home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / software / Mappy / mappyal / mappyal.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-02-01  |  48.0 KB  |  1,623 lines

  1. /* Mappy playback library functions and variables
  2.  * (C)2001 Robin Burrows - rburrows@bigfoot.com
  3.  * This version (R11C) released May 2002 - for Mappy FMP maps
  4.  * Please read the readmeal.txt file and look at the examples
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <allegro.h>
  10.  
  11. #ifdef __cplusplus
  12. #error "Hey, stop compiling mappyal.c as C++!, see MappyAL readme.txt"
  13. #endif
  14.  
  15. /* Comment out next line to disable index0 to truecolour pink conversion */
  16. #define RB8BITTOPINK
  17.  
  18.  
  19. #define MER_NONE 0        /* All the horrible things that can go wrong */
  20. #define MER_OUTOFMEM 1
  21. #define MER_MAPLOADERROR 2
  22. #define MER_NOOPEN 3
  23. #define MER_NOSCREEN 4
  24. #define MER_NOACCELERATION 5
  25. #define MER_CVBFAILED 6
  26. #define MER_MAPTOONEW 7
  27.  
  28. #define AN_END -1            /* Animation types, AN_END = end of anims */
  29. #define AN_NONE 0            /* No anim defined */
  30. #define AN_LOOPF 1        /* Loops from start to end, then jumps to start etc */
  31. #define AN_LOOPR 2        /* As above, but from end to start */
  32. #define AN_ONCE 3            /* Only plays once */
  33. #define AN_ONCEH 4        /* Only plays once, but holds end frame */
  34. #define AN_PPFF 5            /* Ping Pong start-end-start-end-start etc */
  35. #define AN_PPRR 6            /* Ping Pong end-start-end-start-end etc */
  36. #define AN_PPRF 7            /* Used internally by playback */
  37. #define AN_PPFR 8            /* Used internally by playback */
  38. #define AN_ONCES 9        /* Used internally by playback */
  39.  
  40. typedef struct {                /* Structure for data blocks */
  41. long int bgoff, fgoff;            /* offsets from start of graphic blocks */
  42. long int fgoff2, fgoff3;         /* more overlay blocks */
  43. unsigned long int user1, user2;    /* user long data */
  44. unsigned short int user3, user4;    /* user short data */
  45. unsigned char user5, user6, user7;    /* user byte data */
  46. unsigned char tl : 1;                /* bits for collision detection */
  47. unsigned char tr : 1;
  48. unsigned char bl : 1;
  49. unsigned char br : 1;
  50. unsigned char trigger : 1;            /* bit to trigger an event */
  51. unsigned char unused1 : 1;
  52. unsigned char unused2 : 1;
  53. unsigned char unused3 : 1;
  54. } BLKSTR;
  55.  
  56. typedef struct {        /* Animation control structure */
  57. signed char antype;    /* Type of anim, AN_? */
  58. signed char andelay;    /* Frames to go before next frame */
  59. signed char ancount;    /* Counter, decs each frame, till 0, then resets to andelay */
  60. signed char anuser;    /* User info */
  61. long int ancuroff;    /* Points to current offset in list */
  62. long int anstartoff;    /* Points to start of blkstr offsets list, AFTER ref. blkstr offset */
  63. long int anendoff;    /* Points to end of blkstr offsets list */
  64. } ANISTR;
  65.  
  66.  
  67. /* All global variables used by Mappy playback are here */
  68. int maperror, mapgfxinbitmaps;        /* Set to a MER_ error if something wrong happens */
  69. short int mapwidth, mapheight, mapblockwidth, mapblockheight, mapdepth;
  70. short int mapblockstrsize, mapnumblockstr, mapnumblockgfx;
  71. PACKFILE * mapfilept;
  72. short int * mappt = NULL;
  73. short int ** maparraypt = NULL;
  74. char * mapcmappt = NULL;
  75. char * mapblockgfxpt = NULL;
  76. char * mapblockstrpt = NULL;
  77. ANISTR * mapanimstrpt = NULL;
  78. int * mapanimseqpt = NULL;
  79. ANISTR * mapanimstrendpt;
  80. RGB mapcmap6bit[256];
  81. short int * mapmappt[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
  82. short int ** mapmaparraypt[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
  83. BITMAP ** abmTiles = NULL;
  84. /* NEW for Release 6 */
  85. int mapaltdepth;
  86. int maptype, mapislsb, mapclickmask;
  87. int mapblockgapx, mapblockgapy, mapblockstaggerx, mapblockstaggery;
  88. int mapblocksinvidmem, mapblocksinsysmem;
  89. char mapnovctext[80];
  90. /* End of Mappy globals */
  91.  
  92. int MapGenerateYLookup (void)
  93. {
  94. int i, j;
  95.  
  96.     for (i=0;i<8;i++) {
  97.         if (mapmaparraypt[i]!=NULL) { free (mapmaparraypt[i]); mapmaparraypt[i] = NULL; }
  98.         if (mapmappt[i]!=NULL) {
  99.             mapmaparraypt[i] = malloc (mapheight*sizeof(short int *));
  100.             if (mapmaparraypt[i] == NULL) return -1;
  101.             for (j=0;j<mapheight;j++) mapmaparraypt[i][j] = (mapmappt[i]+(j*mapwidth));
  102.             if (mapmappt[i] == mappt) maparraypt = mapmaparraypt[i];
  103.         }
  104.     }
  105.     return 0;
  106. }
  107.  
  108. static int MEClickmask (int x, int y, int xory)
  109. {
  110.     if (abmTiles == NULL) return 0;
  111.  
  112.     x %= mapblockgapx; y %= mapblockgapy;
  113.  
  114.     if (x >= mapblockwidth && xory == 0) return 0;
  115.     if (x >= mapblockwidth && xory == 1) {
  116.         if (y < mapblockstaggery) return -1;
  117.         else return 1;
  118.     }
  119.     if (y >= mapblockheight && xory == 1) return 1;
  120.     if (y >= mapblockheight && xory == 0) {
  121.         if (x < mapblockstaggerx) return -1;
  122.         else return 0;
  123.     }
  124.  
  125.     switch (mapdepth) {
  126.         case 8:
  127.             if (getpixel (abmTiles[mapclickmask], x, y) == 0) {
  128.                 if (x < (mapblockwidth/2) && xory == 0) return -1;
  129.                 if (x >= (mapblockwidth/2) && xory == 0) return 0;
  130.                 if (y < (mapblockheight/2) && xory == 1) return -1;
  131.                 if (y >= (mapblockheight/2) && xory == 1) return 1;
  132.             }
  133.             return 0;
  134.         default:
  135.             if (getpixel (abmTiles[mapclickmask], x, y) == makecol (255,0,255)) {
  136.                 if (x < (mapblockwidth/2) && xory == 0) return -1;
  137.                 if (x >= (mapblockwidth/2) && xory == 0) return 0;
  138.                 if (y < (mapblockheight/2) && xory == 1) return -1;
  139.                 if (y >= (mapblockheight/2) && xory == 1) return 1;
  140.             }
  141.             return 0;
  142.     }
  143.     return 0;
  144. }
  145.  
  146. int MapGetXOffset (int xpix, int ypix)
  147. {
  148. int xb;
  149.  
  150.     if (mapblockstaggerx || mapblockstaggery) {
  151.         xpix += (mapblockstaggerx);
  152.         ypix += (mapblockstaggery);
  153.     }
  154.     xb = xpix/mapblockgapx;
  155.  
  156.     if ((mapblockstaggerx || mapblockstaggery) && mapclickmask) xb += MEClickmask (xpix, ypix, 0);
  157.  
  158.     if (xb < 0) xb = 0;
  159.     if (xb >= mapwidth) xb = mapwidth-1;
  160.     return xb;
  161. }
  162.  
  163. int MapGetYOffset (int xpix, int ypix)
  164. {
  165. int yb;
  166.  
  167.     if (mapblockstaggerx || mapblockstaggery) {
  168.         xpix += (mapblockstaggerx);
  169.         ypix += (mapblockstaggery);
  170.     }
  171.     yb = ypix/mapblockgapy;
  172.  
  173.     if ((mapblockstaggerx || mapblockstaggery) && mapclickmask) {
  174.         yb *= 2;
  175.         yb += MEClickmask (xpix, ypix, 1);
  176.     }
  177.  
  178.     if (yb < 0) yb = 0;
  179.     if (yb >= mapheight) yb = mapheight-1;
  180.     return yb;
  181. }
  182.  
  183. BLKSTR * MapGetBlockInPixels (int x, int y)
  184. {
  185. int xp, yp;
  186. short int * mymappt;
  187. ANISTR * myanpt;
  188.  
  189.     if (x < 0 || y < 0 || x >= (mapwidth*mapblockwidth) || y >= (mapheight*mapblockheight)) return NULL;
  190.  
  191.     xp = x; yp = y;
  192.     x = MapGetXOffset (xp, yp);
  193.     y = MapGetYOffset (xp, yp);
  194.  
  195.     if (maparraypt!= NULL) {
  196.         mymappt = maparraypt[y]+x;
  197.     } else {
  198.         mymappt = mappt;
  199.         mymappt += x;
  200.         mymappt += y*mapwidth;
  201.     }
  202.     if (*mymappt>=0) return ((BLKSTR*) mapblockstrpt) + *mymappt;
  203.     else { myanpt = mapanimstrendpt + *mymappt;
  204.         return ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  205. }
  206.  
  207. BLKSTR * MapGetBlock (int x, int y)
  208. {
  209. short int * mymappt;
  210. ANISTR * myanpt;
  211.  
  212.     if (maparraypt!= NULL) {
  213.         mymappt = maparraypt[y]+x;
  214.     } else {
  215.         mymappt = mappt;
  216.         mymappt += x;
  217.         mymappt += y*mapwidth;
  218.     }
  219.     if (*mymappt>=0) return ((BLKSTR*) mapblockstrpt) + *mymappt;
  220.     else { myanpt = mapanimstrendpt + *mymappt;
  221.         return ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  222. }
  223.  
  224. void MapSetBlockInPixels (int x, int y, int strvalue)
  225. {
  226. int xp, yp;
  227. short int * mymappt;
  228.  
  229.     if (x < 0 || y < 0 || x >= (mapwidth*mapblockwidth) || y >= (mapheight*mapblockheight)) return;
  230.     xp = x; yp = y;
  231.     x = MapGetXOffset (xp, yp);
  232.     y = MapGetYOffset (xp, yp);
  233.  
  234.     if (maparraypt!= NULL) {
  235.         mymappt = maparraypt[y]+x;
  236.     } else {
  237.         mymappt = mappt;
  238.         mymappt += x;
  239.         mymappt += y*mapwidth;
  240.     }
  241.     *mymappt = strvalue;
  242. }
  243.  
  244. void MapSetBlock (int x, int y, int strvalue)
  245. {
  246. short int * mymappt;
  247.  
  248.     if (maparraypt!= NULL) {
  249.         mymappt = maparraypt[y]+x;
  250.     } else {
  251.         mymappt = mappt;
  252.         mymappt += x;
  253.         mymappt += y*mapwidth;
  254.     }
  255.     *mymappt = strvalue;
  256. }
  257.  
  258. int MapChangeLayer (int newlyr)
  259. {
  260.     if (newlyr<0 || newlyr>7 || mapmappt[newlyr] == NULL) return -1;
  261.     mappt = mapmappt[newlyr]; maparraypt = mapmaparraypt[newlyr];
  262.     return newlyr;
  263. }
  264.  
  265. int MapGetBlockID (int blid, int usernum)
  266. {
  267. int i;
  268. BLKSTR * myblkpt;
  269.  
  270.     myblkpt = (BLKSTR *) mapblockstrpt;
  271.     if (myblkpt == NULL) return -1;
  272.  
  273.     for (i=0;i<mapnumblockstr;i++) {
  274.         switch (usernum) {
  275.             case 1:
  276.                 if (myblkpt[i].user1 == blid) return i;
  277.                 break;
  278.             case 2:
  279.                 if (myblkpt[i].user2 == blid) return i;
  280.                 break;
  281.             case 3:
  282.                 if (myblkpt[i].user3 == blid) return i;
  283.                 break;
  284.             case 4:
  285.                 if (myblkpt[i].user4 == blid) return i;
  286.                 break;
  287.             case 5:
  288.                 if (myblkpt[i].user5 == blid) return i;
  289.                 break;
  290.             case 6:
  291.                 if (myblkpt[i].user6 == blid) return i;
  292.                 break;
  293.             case 7:
  294.                 if (myblkpt[i].user7 == blid) return i;
  295.                 break;
  296.         }
  297.     }
  298.  
  299.     return -1;
  300. }
  301.  
  302. int MapDecodeMAR (unsigned char * mrpt, int marlyr)
  303. {
  304. int i, j;
  305. short int * mymarpt;
  306.  
  307.     if (marlyr < 0 || marlyr > 7) return -1;
  308.  
  309.     if (mapmappt[marlyr] == NULL)
  310.         mapmappt[marlyr] = malloc (mapwidth*mapheight*sizeof(short int));
  311.  
  312.     memcpy (mapmappt[marlyr], mrpt, (mapwidth*mapheight*sizeof(short int)));
  313.  
  314.     mymarpt = mapmappt[marlyr];
  315.     j = 0; for (i=0;i<(mapwidth*mapheight);i++) { if (mymarpt[i]&0xF) j = 1; }
  316.     if (j == 0) {
  317.         for (i=0;i<(mapwidth*mapheight);i++) {
  318.             if (mymarpt[i] >= 0) mymarpt[i] /= 32;
  319.             else mymarpt[i] /= 16;
  320.         }
  321.     }
  322.  
  323.     return 0;
  324. }
  325.  
  326. int MapLoadMAR (char * mname, int marlyr)
  327. {
  328. int i, j;
  329. short int * mymarpt;
  330. PACKFILE * marfpt;
  331.  
  332.     if (marlyr < 0 || marlyr > 7) return -1;
  333.  
  334.     marfpt = pack_fopen (mname, "rp");
  335.     if (marfpt==NULL) { marfpt = pack_fopen (mname, "r");
  336.         if (marfpt==NULL) { return -1; } }
  337.  
  338.     if (mapmappt[marlyr] == NULL)
  339.         mapmappt[marlyr] = malloc (mapwidth*mapheight*sizeof(short int));
  340.  
  341.     if (pack_fread (mapmappt[marlyr], (mapwidth*mapheight*sizeof(short int)), marfpt) !=
  342.         (mapwidth*mapheight*sizeof(short int))) { pack_fclose (marfpt); return -1; }
  343.  
  344.     pack_fclose (marfpt);
  345.  
  346.     mymarpt = mapmappt[marlyr];
  347.     j = 0; for (i=0;i<(mapwidth*mapheight);i++) { if (mymarpt[i]&0xF) j = 1; }
  348.     if (j == 0) {
  349.         for (i=0;i<(mapwidth*mapheight);i++) {
  350.             if (mymarpt[i] >= 0) mymarpt[i] /= 32;
  351.             else mymarpt[i] /= 16;
  352.         }
  353.     }
  354.  
  355.     return 0;
  356. }
  357.  
  358. void MapInitAnims (void)
  359. {
  360. ANISTR * myanpt;
  361.     if (mapanimstrpt==NULL) return;
  362.     myanpt = (ANISTR *) mapanimstrendpt; myanpt--;
  363.     while (myanpt->antype!=-1)
  364.     {
  365.         if (myanpt->antype==AN_PPFR) myanpt->antype = AN_PPFF;
  366.         if (myanpt->antype==AN_PPRF) myanpt->antype = AN_PPRR;
  367.         if (myanpt->antype==AN_ONCES) myanpt->antype = AN_ONCE;
  368.         if ((myanpt->antype==AN_LOOPR) || (myanpt->antype==AN_PPRR))
  369.         {
  370.         myanpt->ancuroff = myanpt->anstartoff;
  371.         if ((myanpt->anstartoff)!=(myanpt->anendoff)) myanpt->ancuroff=(myanpt->anendoff)-1;
  372.         } else {
  373.         myanpt->ancuroff = myanpt->anstartoff;
  374.         }
  375.         myanpt->ancount = myanpt->andelay;
  376.         myanpt--;
  377.     }
  378. }
  379.  
  380. void MapUpdateAnims (void)
  381. {
  382. ANISTR * myanpt;
  383.  
  384.     if (mapanimstrpt==NULL) return;
  385.     myanpt = (ANISTR *) mapanimstrendpt; myanpt--;
  386.     while (myanpt->antype!=-1)
  387.     {
  388.         if (myanpt->antype!=AN_NONE) { myanpt->ancount--; if (myanpt->ancount<0) {
  389.         myanpt->ancount = myanpt->andelay;
  390.         if (myanpt->antype==AN_LOOPF)
  391.         {
  392.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
  393.             if (myanpt->ancuroff==myanpt->anendoff) myanpt->ancuroff = myanpt->anstartoff;
  394.         } }
  395.         if (myanpt->antype==AN_LOOPR)
  396.         {
  397.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff--;
  398.             if (myanpt->ancuroff==((myanpt->anstartoff)-1))
  399.                 myanpt->ancuroff = (myanpt->anendoff)-1;
  400.         } }
  401.         if (myanpt->antype==AN_ONCE)
  402.         {
  403.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
  404.             if (myanpt->ancuroff==myanpt->anendoff) { myanpt->antype = AN_ONCES;
  405.                 myanpt->ancuroff = myanpt->anstartoff; }
  406.         } }
  407.         if (myanpt->antype==AN_ONCEH)
  408.         {
  409.             if (myanpt->anstartoff!=myanpt->anendoff) {
  410.             if (myanpt->ancuroff!=((myanpt->anendoff)-1)) myanpt->ancuroff++;
  411.         } }
  412.         if (myanpt->antype==AN_PPFF)
  413.         {
  414.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
  415.             if (myanpt->ancuroff==myanpt->anendoff) { myanpt->ancuroff -= 2;
  416.             myanpt->antype = AN_PPFR;
  417.             if (myanpt->ancuroff<myanpt->anstartoff) myanpt->ancuroff++; }
  418.         } } else {
  419.         if (myanpt->antype==AN_PPFR)
  420.         {
  421.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff--;
  422.             if (myanpt->ancuroff==((myanpt->anstartoff)-1)) { myanpt->ancuroff += 2;
  423.             myanpt->antype = AN_PPFF;
  424.             if (myanpt->ancuroff>myanpt->anendoff) myanpt->ancuroff --; }
  425.         } } }
  426.         if (myanpt->antype==AN_PPRR)
  427.         {
  428.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff--;
  429.             if (myanpt->ancuroff==((myanpt->anstartoff)-1)) { myanpt->ancuroff += 2;
  430.             myanpt->antype = AN_PPRF;
  431.             if (myanpt->ancuroff>myanpt->anendoff) myanpt->ancuroff--; }
  432.         } } else {
  433.         if (myanpt->antype==AN_PPRF)
  434.         {
  435.             if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
  436.             if (myanpt->ancuroff==myanpt->anendoff) { myanpt->ancuroff -= 2;
  437.             myanpt->antype = AN_PPRR;
  438.             if (myanpt->ancuroff<myanpt->anstartoff) myanpt->ancuroff++; }
  439.         } } }
  440.     } } myanpt--; }
  441. }
  442.  
  443. void Mapconv8to6pal (unsigned char * palpt)
  444. {
  445. int i;
  446.     for (i=0;i<256;i++)
  447.     {
  448.         mapcmap6bit[i].r=(*(palpt)>>2);
  449.         mapcmap6bit[i].g=(*(palpt+1)>>2);
  450.         mapcmap6bit[i].b=(*(palpt+2)>>2);
  451.         palpt+=3;
  452.     }
  453. }
  454.  
  455. void MapFreeMem (void)
  456. {
  457. int i;
  458.     for (i=0;i<8;i++) { if (mapmappt[i]!=NULL) { free (mapmappt[i]); mapmappt[i] = NULL; } }
  459.     mappt = NULL;
  460.     for (i=0;i<8;i++) { if (mapmaparraypt[i]!=NULL) { free (mapmaparraypt[i]); mapmaparraypt[i] = NULL; } }
  461.     maparraypt = NULL;
  462.     if (mapcmappt!=NULL) { free (mapcmappt); mapcmappt = NULL; }
  463.     if (mapblockgfxpt!=NULL) { free (mapblockgfxpt); mapblockgfxpt = NULL; }
  464.     if (mapblockstrpt!=NULL) { free (mapblockstrpt); mapblockstrpt = NULL; }
  465.     if (mapanimseqpt!=NULL) { free (mapanimseqpt); mapanimseqpt = NULL; }
  466.     if (mapanimstrpt!=NULL) { free (mapanimstrpt); mapanimstrpt = NULL; }
  467.     if (abmTiles != NULL) {
  468.         i = 0; while (abmTiles[i]!=NULL) { destroy_bitmap (abmTiles[i]); i++; }
  469.         free (abmTiles); abmTiles = NULL;
  470.     }
  471.     mapnovctext[0] = 0;
  472.     mapblocksinvidmem = 0; mapblocksinsysmem = 0;
  473. }
  474.  
  475. void MapSetPal8 (void)
  476. {
  477.     if (screen!=NULL) { if ((bitmap_color_depth (screen)==8) && mapdepth == 8) set_palette (mapcmap6bit); }
  478. }
  479.  
  480. void MapCorrectColours (void)
  481. {
  482. /* Remember, Intel stores shorts and longs the wrong way round!
  483.  * ie. 0x12345678 will be 0x78563412
  484.  */
  485.     return;
  486. }
  487.  
  488. void MapRestore (void)
  489. {
  490. int i, j, k;
  491. unsigned char * newgfxpt;
  492.  
  493.     if (mapgfxinbitmaps!=1 || abmTiles == NULL) return;
  494.     i = 0; newgfxpt = mapblockgfxpt; while (abmTiles[i]!=NULL) {
  495.         acquire_bitmap (abmTiles[i]);
  496.         for (k=0;k<mapblockheight;k++) {
  497.         for (j=0;j<mapblockwidth;j++) {
  498.         switch (mapdepth) {
  499.             case 8:
  500.                 putpixel (abmTiles[i], j, k, *((unsigned char *) newgfxpt));
  501.                 newgfxpt++;
  502.                 break;
  503.             case 15:
  504.             case 16:
  505.                 putpixel (abmTiles[i], j, k, *((unsigned short int *) newgfxpt));
  506.                 newgfxpt+=2;
  507.                 break;
  508.             case 24:
  509.                 putpixel (abmTiles[i], j, k, makecol (newgfxpt[0], newgfxpt[1], newgfxpt[2]));
  510.                 newgfxpt+=3;
  511.                 break;
  512.             case 32:
  513.                 putpixel (abmTiles[i], j, k, makecol (newgfxpt[1], newgfxpt[2], newgfxpt[3]));
  514.                 newgfxpt+=4;
  515.                 break;
  516.         } } }
  517.         release_bitmap (abmTiles[i]);
  518.         i++;
  519.     }
  520. }
  521.  
  522. int MapRelocate2 (void)
  523. {
  524. int i, j, k;
  525. BLKSTR * myblkstrpt;
  526. //ANISTR * myanpt;
  527. unsigned char * newgfxpt, * novcarray;
  528. char ascnum[80];
  529. //long int * myanblkpt;
  530.  
  531.     i = mapnumblockstr;
  532.     myblkstrpt = (BLKSTR *) mapblockstrpt;
  533.  
  534.     novcarray = malloc (mapnumblockgfx);
  535.     memset (novcarray, 0, mapnumblockgfx);
  536.     i = 0; while (mapnovctext[i] != 0) {
  537.         j = 0; while (mapnovctext[i] >= '0' && mapnovctext[i] <= '9') {
  538.             ascnum[j] = mapnovctext[i];
  539.             i++; j++;
  540.         }
  541.         ascnum[j] = 0;
  542.         k = atoi(ascnum);
  543.         if (k < 0 || k >= mapnumblockgfx) break;
  544.         if (mapnovctext[i] == '-') {
  545.             i++;
  546.             j = 0; while (mapnovctext[i] >= '0' && mapnovctext[i] <= '9') {
  547.                 ascnum[j] = mapnovctext[i];
  548.                 i++; j++;
  549.             }
  550.             ascnum[j] = 0;
  551.             j = atoi(ascnum);
  552.             if (j < k || j >= mapnumblockgfx) break;
  553.             while (k <= j) {
  554.                 novcarray[k] = 1; k++;
  555.             }
  556.         } else {
  557.             novcarray[k] = 1;
  558.         }
  559.         if (mapnovctext[i] == ',') i++;
  560.     }
  561.  
  562.     if (abmTiles == NULL) abmTiles = malloc ((sizeof (BITMAP *))*(mapnumblockgfx+2));
  563.     abmTiles[0] = NULL;
  564.     i = 0; newgfxpt = mapblockgfxpt; while (i<mapnumblockgfx) {
  565.         abmTiles[i+1] = NULL;
  566.         if (mapgfxinbitmaps==1 && novcarray[i]==0) {
  567.             abmTiles[i] = create_video_bitmap (mapblockwidth, mapblockheight);
  568.             if (abmTiles[i] != NULL) {
  569.                     mapblocksinvidmem++;
  570.                     acquire_bitmap (abmTiles[i]);
  571.             } else {
  572.                 abmTiles[i] = create_bitmap (mapblockwidth, mapblockheight);
  573.                 if (abmTiles[i] == NULL) { MapFreeMem (); maperror = MER_CVBFAILED ; return -1; }
  574.                     mapblocksinsysmem++;
  575.             }
  576.             set_clip (abmTiles[i], 0, 0, 0, 0);
  577.         } else {
  578.             abmTiles[i] = create_bitmap (mapblockwidth, mapblockheight);
  579.             if (abmTiles[i] == NULL) { MapFreeMem (); maperror = MER_CVBFAILED ; return -1; }
  580.             mapblocksinsysmem++;
  581.             set_clip (abmTiles[i], 0, 0, 0, 0);
  582.         }
  583.         for (k=0;k<mapblockheight;k++) {
  584.         for (j=0;j<mapblockwidth;j++) {
  585.         switch (mapdepth) {
  586.             case 8:
  587.                 putpixel (abmTiles[i], j, k, *((unsigned char *) newgfxpt));
  588.                 newgfxpt++;
  589.                 break;
  590.             case 15:
  591.             case 16:
  592.                 putpixel (abmTiles[i], j, k, *((unsigned short int *) newgfxpt));
  593.                 newgfxpt+=2;
  594.                 break;
  595.             case 24:
  596.                 putpixel (abmTiles[i], j, k, makecol (newgfxpt[0], newgfxpt[1], newgfxpt[2]));
  597.                 newgfxpt+=3;
  598.                 break;
  599.             case 32:
  600.                 putpixel (abmTiles[i], j, k, makecol (newgfxpt[1], newgfxpt[2], newgfxpt[3]));
  601.                 newgfxpt+=4;
  602.                 break;
  603.         } } }
  604.         if (is_video_bitmap(abmTiles[i])) release_bitmap (abmTiles[i]);
  605.         i++;
  606.     }
  607.     i = mapnumblockstr; while (i) {
  608.         ((BITMAP *) myblkstrpt->bgoff) = abmTiles[myblkstrpt->bgoff];
  609.         if (myblkstrpt->fgoff!=0)
  610.             ((BITMAP *) myblkstrpt->fgoff) = abmTiles[myblkstrpt->fgoff];
  611.         if (myblkstrpt->fgoff2!=0)
  612.             ((BITMAP *) myblkstrpt->fgoff2) = abmTiles[myblkstrpt->fgoff2];
  613.         if (myblkstrpt->fgoff3!=0)
  614.             ((BITMAP *) myblkstrpt->fgoff3) = abmTiles[myblkstrpt->fgoff3];
  615.         myblkstrpt++; i--;
  616.     }
  617.  
  618.     free (novcarray);
  619.     return 0;
  620. }
  621.  
  622. int MapRelocate (void)
  623. {
  624. int i, j, cdepth, pixcol, ccr, ccg, ccb;
  625. //BLKSTR * myblkstrpt;
  626. unsigned char * oldgfxpt;
  627. unsigned char * mycmappt;
  628. unsigned char * newgfxpt;
  629. unsigned char * newgfx2pt;
  630.  
  631.     if (screen == NULL) { MapFreeMem (); maperror = MER_NOSCREEN; return -1; }
  632.     if (!gfx_capabilities&GFX_HW_VRAM_BLIT && mapgfxinbitmaps==1)
  633.         { MapFreeMem (); maperror = MER_NOACCELERATION; return -1; }
  634.         cdepth = bitmap_color_depth (screen);
  635.         oldgfxpt = (unsigned char *) mapblockgfxpt;
  636.         newgfxpt = (unsigned char *)
  637.             malloc (mapblockwidth*mapblockheight*((mapdepth+1)/8)*mapnumblockgfx*((cdepth+1)/8));
  638.         if (newgfxpt==NULL) { MapFreeMem (); maperror = MER_OUTOFMEM; return -1; }
  639.         newgfx2pt = newgfxpt;
  640.         mycmappt = (unsigned char *) mapcmappt; pixcol = 0;
  641.         for (i=0;i<(mapblockwidth*mapblockheight*mapnumblockgfx);i++)
  642.         {
  643.             switch (mapdepth) {
  644.             case 8:
  645.                 if (cdepth==8) pixcol = (int) *oldgfxpt; else {
  646.                 j = (*oldgfxpt)*3;
  647.                 pixcol = makecol (mycmappt[j], mycmappt[j+1], mycmappt[j+2]);
  648. #ifdef RB8BITTOPINK
  649.                 if (j == 0 && cdepth!=8) pixcol = makecol (255, 0, 255); }
  650. #endif
  651.                 oldgfxpt++;
  652.                 break;
  653.             case 15:
  654.                 ccr = ((((int) *oldgfxpt)&0x7C)<<1);
  655.                 ccg = ((((((int) *oldgfxpt)&0x3)<<3)|(((int) *(oldgfxpt+1))>>5))<<3);
  656.                 ccb = (((int) *(oldgfxpt+1)&0x1F)<<3);
  657.                 ccr |= ((ccr>>5)&0x07);
  658.                 ccg |= ((ccg>>5)&0x07);
  659.                 ccb |= ((ccb>>5)&0x07);
  660.                 pixcol = makecol (ccr, ccg, ccb);
  661.                 if (cdepth==8) { if (ccr == 0xFF && ccg == 0 && ccb == 0xFF) pixcol = 0; }
  662.                 oldgfxpt += 2;
  663.                 break;
  664.             case 16:
  665.                 ccr = (((int) *oldgfxpt)&0xF8);
  666.                 ccg = ((((((int) *oldgfxpt)&0x7)<<3)|(((int) *(oldgfxpt+1))>>5))<<2);
  667.                 ccb = (((int) *(oldgfxpt+1)&0x1F)<<3);
  668.                 ccr |= ((ccr>>5)&0x07);
  669.                 ccg |= ((ccg>>6)&0x03);
  670.                 ccb |= ((ccb>>5)&0x07);
  671.                 pixcol = makecol (ccr, ccg, ccb);
  672.                 if (cdepth==8) { if (ccr == 0xFF && ccg == 0 && ccb == 0xFF) pixcol = 0; }
  673.                 oldgfxpt += 2;
  674.                 break;
  675.             case 24:
  676.                 pixcol = makecol (*oldgfxpt, *(oldgfxpt+1), *(oldgfxpt+2));
  677.                 if (cdepth==8) { if (*oldgfxpt == 0xFF && *(oldgfxpt+1) == 0 &&
  678.                     *(oldgfxpt+2) == 0xFF) pixcol = 0; }
  679.                 oldgfxpt += 3;
  680.                 break;
  681.             case 32:
  682.                 pixcol = makecol (*(oldgfxpt+1), *(oldgfxpt+2), *(oldgfxpt+3));
  683.                 if (cdepth==8) { if (*(oldgfxpt+1) == 0xFF && *(oldgfxpt+2) == 0 &&
  684.                     *(oldgfxpt+3) == 0xFF) pixcol = 0; }
  685.                 oldgfxpt += 4;
  686.                 break;
  687.             }
  688.             switch (cdepth) {
  689.             case 8:
  690.                 *newgfxpt = (unsigned char) pixcol;
  691.                 newgfxpt++;
  692.                 break;
  693.             case 15:
  694.             case 16:
  695.                 *((unsigned short int *) newgfxpt) = (unsigned short int) pixcol;
  696.                 newgfxpt+=2;
  697.                 break;
  698.             case 24:
  699.                 *newgfxpt = (unsigned char) (pixcol>>16)&0xFF;
  700.                 *(newgfxpt+1) = (unsigned char) (pixcol>>8)&0xFF;
  701.                 *(newgfxpt+2) = (unsigned char) pixcol&0xFF;
  702.                 newgfxpt+=3;
  703.                 break;
  704.             case 32:
  705.                 *newgfxpt = 0;
  706.                 *(newgfxpt+1) = (unsigned char) (pixcol>>16)&0xFF;
  707.                 *(newgfxpt+2) = (unsigned char) (pixcol>>8)&0xFF;
  708.                 *(newgfxpt+3) = (unsigned char) pixcol&0xFF;
  709.                 newgfxpt+=4;
  710.                 break;
  711.             }
  712.         }
  713.         free (mapblockgfxpt); mapblockgfxpt = (char *) newgfx2pt;
  714.  
  715.     mapdepth = cdepth;
  716.  
  717.     return MapRelocate2 ();
  718. }
  719.  
  720. static int MapGetchksz (unsigned char * locpt)
  721. {
  722.     return ((((int) (locpt[0]))<<24)|(((int) (locpt[1]))<<16)|
  723.         (((int) (locpt[2]))<<8)|((int) (locpt[3])));
  724. }
  725.  
  726. static int MapGetshort (unsigned char * locpt)
  727. {
  728. int rval;
  729.  
  730.     if (mapislsb)
  731.     rval = ((((int) (locpt[1]))<<8)|((int) (locpt[0])));
  732.     else
  733.     rval = ((((int) (locpt[0]))<<8)|((int) (locpt[1])));
  734.     if (rval & 0x8000) rval -= 0x10000;
  735.     return rval;
  736. }
  737.  
  738. static int MapGetlong (unsigned char * locpt)
  739. {
  740.     if (mapislsb)
  741.     return ((((int) (locpt[3]))<<24)|(((int) (locpt[2]))<<16)|
  742.         (((int) (locpt[1]))<<8)|((int) (locpt[0])));
  743.     else
  744.     return ((((int) (locpt[0]))<<24)|(((int) (locpt[1]))<<16)|
  745.         (((int) (locpt[2]))<<8)|((int) (locpt[3])));
  746. }
  747.  
  748. int MapDecodeMPHD (unsigned char * mdatpt)
  749. {
  750.     mdatpt += 8;
  751.     if (mdatpt[0] > 1) { maperror = MER_MAPTOONEW; return -1; }
  752.     if (mdatpt[2] == 1) mapislsb = 1; else mapislsb = 0;
  753.  
  754.     maptype = (int) mdatpt[3];
  755.     if (maptype > 3) { maperror = MER_MAPTOONEW; return -1; }
  756.     mapwidth = (short) MapGetshort (mdatpt+4);
  757.     mapheight = (short) MapGetshort (mdatpt+6);
  758.     mapblockwidth = (short) MapGetshort (mdatpt+12);
  759.     mapblockheight = (short) MapGetshort (mdatpt+14);
  760.     mapdepth = (short) MapGetshort (mdatpt+16);
  761.     mapaltdepth = mapdepth;
  762.     mapblockstrsize = (short) MapGetshort (mdatpt+18);
  763.     mapnumblockstr = (short) MapGetshort (mdatpt+20);
  764.     mapnumblockgfx = (short) MapGetshort (mdatpt+22);
  765.  
  766.     if (MapGetchksz (mdatpt-4) > 28) {
  767.         mapblockgapx = (int) MapGetshort (mdatpt+28);
  768.         mapblockgapy = (int) MapGetshort (mdatpt+30);
  769.         mapblockstaggerx = (int) MapGetshort (mdatpt+32);
  770.         mapblockstaggery = (int) MapGetshort (mdatpt+34);
  771.     } else {
  772.         mapblockgapx = (int) mapblockwidth;
  773.         mapblockgapy = (int) mapblockheight;
  774.         mapblockstaggerx = 0;
  775.         mapblockstaggery = 0;
  776.     }
  777.     if (MapGetchksz (mdatpt-4) > 36) mapclickmask = (short) MapGetshort (mdatpt+36);
  778.     else mapclickmask = 0;
  779.  
  780.     return 0;
  781. }
  782.  
  783. /*
  784. int DecodeEDHD (unsigned char * mdatpt)
  785. {
  786. int i, j;
  787. short int * mybrshpt;
  788. char * mynamept;
  789. short int * mybrsh2pt;
  790.  
  791.     mdatpt += 8;
  792.     xmapoffset = (short) MapGetshort (mdatpt);
  793.     ymapoffset = (short) MapGetshort (mdatpt+2);
  794.     fgcolour = (int) MapGetlong (mdatpt+4);
  795.     bgcolour = (int) MapGetlong (mdatpt+8);
  796.     swidth = (short) MapGetshort (mdatpt+12);
  797.     sheight = (short) MapGetshort (mdatpt+14);
  798.     strtstr = (short) MapGetshort (mdatpt+16);
  799.     strtblk = (short) MapGetshort (mdatpt+18);
  800.     curstr = (short) MapGetshort (mdatpt+20);
  801.     curanim = (short) MapGetshort (mdatpt+22); curanim = -1;
  802.     animspd = (short) MapGetshort (mdatpt+24);
  803.     span = (short) MapGetshort (mdatpt+26);
  804.     numbrushes = (short) MapGetshort (mdatpt+28);
  805.     if (clickmask == 0) {
  806.         clickmask = (int) MapGetshort (mdatpt+30);
  807.         if (clickmask<0 || clickmask >= numblockgfx) clickmask = 0;
  808.     }
  809.  
  810.     if (numbrushes>0)
  811.     {
  812.     mybrshpt =(short int *) (mdatpt+32);
  813.         for (i=0;i<8;i++)
  814.         {
  815.             j = *mybrshpt; j *= *(mybrshpt+1); j *= 2; j += 4;
  816.             brshpt[i] = malloc (j); j /= 2; mybrsh2pt = brshpt[i];
  817.             *mybrsh2pt = *mybrshpt;
  818.             mybrsh2pt++; mybrshpt++;
  819.             *mybrsh2pt = *mybrshpt;
  820.             mybrsh2pt++; mybrshpt++;
  821.             j -= 2;
  822.             if (maptype == 0) {
  823.                 while (j) {
  824.                     j--;
  825.                     *mybrsh2pt = *mybrshpt;
  826.                     if (*mybrsh2pt >= 0) *mybrsh2pt /= BLOCKSTRSIZE;
  827.                     mybrsh2pt++; mybrshpt++;
  828.                 }
  829.             } else {
  830.                 while (j) {
  831.                     j--;
  832.                     *mybrsh2pt = *mybrshpt;
  833.                     if (*mybrsh2pt < 0) *mybrsh2pt *= sizeof(ANISTR);
  834.                     mybrsh2pt++; mybrshpt++;
  835.                 }
  836.             }
  837.             numbrushes--; if (!numbrushes) i=8;
  838.         }
  839.     mynamept = (char *) mybrshpt;
  840.     if ((MapGetchksz (mdatpt-4)) > (mynamept-((char *) mdatpt))) {
  841.         for (i=0;i<8;i++) {
  842.             if (brshpt[i] != NULL) {
  843.                 strcpy (brshname[i], mynamept);
  844.                 mynamept += strlen (mynamept);
  845.                 mynamept++;
  846.             }
  847.         }
  848.     }
  849.     }
  850.  
  851.     return 0;
  852. }
  853.  
  854. int DecodeATHR (unsigned char * mdatpt)
  855. {
  856. int i, j;
  857.  
  858.     mdatpt += 8;
  859.     i = 0; while (i < MapGetchksz (mdatpt-4))
  860.     {
  861.         authorname[i]=mdatpt[i];
  862.         if (mdatpt[i]==0) break;
  863.         i++;
  864.     }
  865.     i++; j = 0;
  866.     while (i < MapGetchksz (mdatpt-4))
  867.     {
  868.         authorinfo1[j]=mdatpt[i];
  869.         if (mdatpt[i]==0) break;
  870.         i++; j++;
  871.     }
  872.     i++; j = 0;
  873.     while (i < MapGetchksz (mdatpt-4))
  874.     {
  875.         authorinfo2[j]=mdatpt[i];
  876.         if (mdatpt[i]==0) break;
  877.         i++; j++;
  878.     }
  879.     i++; j = 0;
  880.     while (i < MapGetchksz (mdatpt-4))
  881.     {
  882.         authorinfo3[j]=mdatpt[i];
  883.         if (mdatpt[i]==0) break;
  884.         i++; j++;
  885.     }
  886.     return 0;
  887. }
  888. */
  889.  
  890. int MapDecodeCMAP (unsigned char * mdatpt)
  891. {
  892.     mdatpt += 8;
  893.     mapcmappt = (unsigned char *) malloc (MapGetchksz (mdatpt-4));
  894.     if (mapcmappt==NULL) { maperror = MER_OUTOFMEM; return -1; }
  895.     memcpy (mapcmappt, mdatpt, MapGetchksz (mdatpt-4));
  896.     Mapconv8to6pal (mapcmappt);
  897.     return 0;
  898. }
  899.  
  900. int MapDecodeBKDT (unsigned char * mdatpt)
  901. {
  902. int i, j;
  903. BLKSTR * myblkpt;
  904.  
  905.     mdatpt += 8;
  906.     mapblockstrpt = malloc (mapnumblockstr*sizeof(BLKSTR));
  907.     if (mapblockstrpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
  908.  
  909.     myblkpt = (BLKSTR *) mapblockstrpt;
  910.     j = MapGetchksz (mdatpt-4);
  911.     i = 0; while (i < (mapnumblockstr*mapblockstrsize)) {
  912.         myblkpt->bgoff = (int) MapGetlong (mdatpt+i);
  913.         myblkpt->fgoff = (int) MapGetlong (mdatpt+i+4);
  914.         myblkpt->fgoff2 = (int) MapGetlong (mdatpt+i+8);
  915.         myblkpt->fgoff3 = (int) MapGetlong (mdatpt+i+12);
  916.         if (maptype == 0) {
  917.             myblkpt->bgoff /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
  918.             myblkpt->fgoff /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
  919.             myblkpt->fgoff2 /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
  920.             myblkpt->fgoff3 /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
  921.         }
  922.         myblkpt->user1 = (unsigned int) MapGetlong (mdatpt+i+16);
  923.         myblkpt->user2 = (unsigned int) MapGetlong (mdatpt+i+20);
  924.         myblkpt->user3 = (unsigned short int) MapGetshort (mdatpt+i+24);
  925.         myblkpt->user4 = (unsigned short int) MapGetshort (mdatpt+i+26);
  926.         myblkpt->user5 = mdatpt[i+28];
  927.         myblkpt->user6 = mdatpt[i+29];
  928.         myblkpt->user7 = mdatpt[i+30];
  929.         if (mdatpt[i+31]&0x80) myblkpt->unused3 = 1; else myblkpt->unused3 = 0;
  930.         if (mdatpt[i+31]&0x40) myblkpt->unused2 = 1; else myblkpt->unused2 = 0;
  931.         if (mdatpt[i+31]&0x20) myblkpt->unused1 = 1; else myblkpt->unused1 = 0;
  932.         if (mdatpt[i+31]&0x10) myblkpt->trigger = 1; else myblkpt->trigger = 0;
  933.         if (mdatpt[i+31]&0x08) myblkpt->br = 1; else myblkpt->br = 0;
  934.         if (mdatpt[i+31]&0x04) myblkpt->bl = 1; else myblkpt->bl = 0;
  935.         if (mdatpt[i+31]&0x02) myblkpt->tr = 1; else myblkpt->tr = 0;
  936.         if (mdatpt[i+31]&0x01) myblkpt->tl = 1; else myblkpt->tl = 0;
  937.         i += mapblockstrsize;
  938.         myblkpt++;
  939.     }
  940.     return 0;
  941. }
  942.  
  943. int MapDecodeANDT (unsigned char * mdatpt)
  944. {
  945. int numani, i, ancksz;
  946. unsigned char * mdatendpt;
  947.  
  948.     mdatpt += 8;
  949.     ancksz = MapGetchksz(mdatpt-4);
  950.     mdatendpt = mdatpt+ancksz;
  951.  
  952.     numani = 0; while (1) {
  953.         mdatendpt -= 16;
  954.         numani++;
  955.         if (*mdatendpt == 255) break;
  956.     }
  957.  
  958.     mapanimseqpt = malloc (((mdatendpt-mdatpt)/4)*sizeof(int));
  959.     if (mapanimseqpt == NULL) { maperror = MER_OUTOFMEM; return -1; }
  960.     i = 0; while (mdatpt != mdatendpt) {
  961.         mapanimseqpt[i] = MapGetlong (mdatpt);
  962.         if (maptype == 0) mapanimseqpt[i] /= mapblockstrsize;
  963.         mdatpt += 4; i++;
  964.     }
  965.  
  966.     mapanimstrpt = malloc (numani*sizeof(ANISTR));
  967.     if (mapanimstrpt == NULL) { maperror = MER_OUTOFMEM; return -1; }
  968.     mapanimstrendpt = mapanimstrpt;
  969.     mapanimstrendpt += numani;
  970.  
  971.     i = 0; while (i<numani) {
  972.         mapanimstrpt[i].antype = mdatendpt[0];
  973.         mapanimstrpt[i].andelay = mdatendpt[1];
  974.         mapanimstrpt[i].ancount = mdatendpt[2];
  975.         mapanimstrpt[i].anuser = mdatendpt[3];
  976.         if (maptype == 0) {
  977.             mapanimstrpt[i].ancuroff = (int) ((MapGetlong (mdatendpt+4)+ancksz)/4);
  978.             mapanimstrpt[i].anstartoff = (int) ((MapGetlong (mdatendpt+8)+ancksz)/4);
  979.             mapanimstrpt[i].anendoff = (int) ((MapGetlong (mdatendpt+12)+ancksz)/4);
  980.         } else {
  981.             mapanimstrpt[i].ancuroff = (int) MapGetlong (mdatendpt+4);
  982.             mapanimstrpt[i].anstartoff = (int) MapGetlong (mdatendpt+8);
  983.             mapanimstrpt[i].anendoff = (int) MapGetlong (mdatendpt+12);
  984.         }
  985.         mdatendpt += 16; i++;
  986.     }
  987.  
  988.     MapInitAnims ();
  989.     return 0;
  990. }
  991.  
  992. int MapDecodeAGFX (unsigned char * mdatpt)
  993. {
  994.     if (bitmap_color_depth (screen) > 8) return 0;
  995.     if (mapblockgfxpt != NULL) free (mapblockgfxpt);
  996.     mapblockgfxpt = malloc (MapGetchksz (mdatpt+4));
  997.     if (mapblockgfxpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
  998.     memcpy (mapblockgfxpt, mdatpt+8, MapGetchksz(mdatpt+4));
  999.     mapaltdepth = 8;
  1000.     return 0;
  1001. }
  1002.  
  1003. int MapDecodeBGFX (unsigned char * mdatpt)
  1004. {
  1005.     if (mapblockgfxpt != NULL) return 0;
  1006.     mapblockgfxpt = malloc (MapGetchksz (mdatpt+4));
  1007.     if (mapblockgfxpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
  1008.     memcpy (mapblockgfxpt, mdatpt+8, MapGetchksz(mdatpt+4));
  1009.     return 0;
  1010. }
  1011.  
  1012. int MapDecodeNOVC (unsigned char * mdatpt)
  1013. {
  1014.     memset (mapnovctext, 0, 70);
  1015.     if (MapGetchksz (mdatpt+4) < 70) strcpy (mapnovctext, mdatpt+8);
  1016.     return 0;
  1017. }
  1018.  
  1019. int MapDecodeLayer (unsigned char * mdatpt, int lnum)
  1020. {
  1021. int i, j, k, l;
  1022. short int * mymappt, * mymap2pt;
  1023.  
  1024.     mapmappt[lnum] = malloc (mapwidth*mapheight*sizeof(short int));
  1025.     if (mapmappt[lnum] == NULL) { maperror = MER_OUTOFMEM; return -1; }
  1026.  
  1027.     mdatpt += 8;
  1028.     mymappt = mapmappt[lnum];
  1029.     if (maptype == 0) {
  1030.     for (j=0;j<mapheight;j++) {
  1031.         for (i=0;i<mapwidth;i++) {
  1032.             *mymappt = (short int) MapGetshort (mdatpt);
  1033.             if (*mymappt >= 0) { *mymappt /= mapblockstrsize; }
  1034.             else { *mymappt /= 16; }
  1035.             mdatpt+=2; mymappt++;
  1036.         }
  1037.     }
  1038.     } else {
  1039.     if (maptype == 1) {
  1040.     for (j=0;j<mapheight;j++) {
  1041.         for (i=0;i<mapwidth;i++) {
  1042.             *mymappt = (short int) MapGetshort (mdatpt);
  1043.             mdatpt+=2; mymappt++;
  1044.         }
  1045.     }
  1046.     } else {
  1047.     if (maptype == 2) {
  1048.     for (j=0;j<mapheight;j++) {
  1049.         for (i=0;i<mapwidth;) {
  1050.             k = (int) MapGetshort (mdatpt);
  1051.             mdatpt += 2;
  1052.             if (k > 0) {
  1053.                 while (k) {
  1054.                     *mymappt = (short int) MapGetshort (mdatpt);
  1055.                     mymappt++; mdatpt += 2;
  1056.                     i++; k--;
  1057.                 }
  1058.             } else {
  1059.             if (k < 0) {
  1060.                 l = (int) MapGetshort (mdatpt); mdatpt += 2;
  1061.                 while (k) {
  1062.                     *mymappt = (short int) l;
  1063.                     mymappt++;
  1064.                     i++; k++;
  1065.                 }
  1066.             } else {
  1067.             } }
  1068.         }
  1069.     }
  1070.     } else {
  1071.     if (maptype == 3) {
  1072.     for (j=0;j<mapheight;j++) {
  1073.         for (i=0;i<mapwidth;) {
  1074.             k = (int) MapGetshort (mdatpt);
  1075.             mdatpt += 2;
  1076.             if (k > 0) {
  1077.                 while (k) {
  1078.                     *mymappt = (short int) MapGetshort (mdatpt);
  1079.                     mymappt++; mdatpt += 2;
  1080.                     i++; k--;
  1081.                 }
  1082.             } else {
  1083.             if (k < 0) {
  1084.                 mymap2pt = mymappt + (int) MapGetshort (mdatpt); mdatpt += 2;
  1085.                 while (k) {
  1086.                     *mymappt = *mymap2pt;
  1087.                     mymappt++; mymap2pt++;
  1088.                     i++; k++;
  1089.                 }
  1090.             } else {
  1091.             } }
  1092.         }
  1093.     }
  1094.     } } } }
  1095.  
  1096.     if (lnum == 0) { mappt = mapmappt[lnum]; }
  1097.     return 0;
  1098. }
  1099.  
  1100. int MapDecodeNULL (unsigned char * mdatpt)
  1101. {
  1102.     return 0;
  1103. }
  1104.  
  1105. int MapRealDecode (PACKFILE * mfpt, unsigned char * mmpt, long int mpfilesize)
  1106. {
  1107. int chkdn;
  1108. unsigned char * fmappospt;
  1109. char mphdr[8];
  1110.  
  1111.     MapFreeMem ();
  1112.     mpfilesize -= 12;
  1113.  
  1114.     while (mpfilesize > 0) {
  1115.  
  1116.         if (mfpt != NULL) {
  1117.             if (pack_fread (mphdr, 8, mfpt) != 8) {
  1118.                 maperror = MER_MAPLOADERROR;
  1119.                 MapFreeMem ();
  1120.                 return -1;
  1121.             }
  1122.             fmappospt = malloc (MapGetchksz(mphdr+4)+8);
  1123.             if (fmappospt == NULL) {
  1124.                 maperror = MER_OUTOFMEM;
  1125.                 MapFreeMem ();
  1126.                 return -1;
  1127.             }
  1128.             memcpy (fmappospt, mphdr, 8);
  1129.             if (pack_fread (fmappospt+8, MapGetchksz(mphdr+4), mfpt) != MapGetchksz(mphdr+4)) {
  1130.                 maperror = MER_MAPLOADERROR;
  1131.                 MapFreeMem ();
  1132.                 return -1;
  1133.             }
  1134.         } else {
  1135.             fmappospt = mmpt;
  1136.             mmpt += MapGetchksz(mmpt+4);
  1137.             mmpt += 8;
  1138.         }
  1139.  
  1140.         chkdn = 0;
  1141.         if (!strncmp (fmappospt, "MPHD", 4)) { chkdn = 1; MapDecodeMPHD (fmappospt); }
  1142. /*        if (!strncmp (fmappospt, "ATHR", 4)) { chkdn = 1; MapDecodeATHR (fmappospt); }
  1143.         if (!strncmp (fmappospt, "EDHD", 4)) { chkdn = 1; MapDecodeEDHD (fmappospt); }
  1144. */
  1145.         if (!strncmp (fmappospt, "CMAP", 4)) { chkdn = 1; MapDecodeCMAP (fmappospt); }
  1146.         if (!strncmp (fmappospt, "BKDT", 4)) { chkdn = 1; MapDecodeBKDT (fmappospt); }
  1147.         if (!strncmp (fmappospt, "ANDT", 4)) { chkdn = 1; MapDecodeANDT (fmappospt); }
  1148.         if (!strncmp (fmappospt, "AGFX", 4)) { chkdn = 1; MapDecodeAGFX (fmappospt); }
  1149.         if (!strncmp (fmappospt, "BGFX", 4)) { chkdn = 1; MapDecodeBGFX (fmappospt); }
  1150.         if (!strncmp (fmappospt, "NOVC", 4)) { chkdn = 1; MapDecodeNOVC (fmappospt); }
  1151.         if (!strncmp (fmappospt, "BODY", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 0); }
  1152.         if (!strncmp (fmappospt, "LYR1", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 1); }
  1153.         if (!strncmp (fmappospt, "LYR2", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 2); }
  1154.         if (!strncmp (fmappospt, "LYR3", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 3); }
  1155.         if (!strncmp (fmappospt, "LYR4", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 4); }
  1156.         if (!strncmp (fmappospt, "LYR5", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 5); }
  1157.         if (!strncmp (fmappospt, "LYR6", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 6); }
  1158.         if (!strncmp (fmappospt, "LYR7", 4)) { chkdn = 1; MapDecodeLayer (fmappospt, 7); }
  1159.         if (!chkdn) MapDecodeNULL (fmappospt);
  1160.  
  1161.         mpfilesize -= 8;
  1162.         mpfilesize -= MapGetchksz (fmappospt+4);
  1163.         if (mfpt != NULL) free (fmappospt);
  1164.  
  1165.         if (maperror != MER_NONE) { MapFreeMem (); return -1; }
  1166.     }
  1167.  
  1168.     mapdepth = mapaltdepth;
  1169.     return MapRelocate ();
  1170. }
  1171.  
  1172. int MapRealLoad (char * mname)
  1173. {
  1174. int mretval;
  1175. char idtag[4];
  1176. unsigned char tempc;
  1177. int mapfilesize = 0;
  1178.  
  1179.     maperror = MER_NONE;
  1180.     mapfilept = pack_fopen (mname, "rp");
  1181.     if (mapfilept==NULL) { mapfilept = pack_fopen (mname, "r");
  1182.         if (mapfilept==NULL) { maperror = MER_NOOPEN; return -1; } }
  1183.  
  1184.     maperror = MER_MAPLOADERROR;
  1185.     if (pack_fread (&idtag[0], 1, mapfilept) == 1) {
  1186.     if (pack_fread (&idtag[1], 1, mapfilept) == 1) {
  1187.     if (pack_fread (&idtag[2], 1, mapfilept) == 1) {
  1188.     if (pack_fread (&idtag[3], 1, mapfilept) == 1) {
  1189.     if (pack_fread (&tempc, 1, mapfilept) == 1) {
  1190.     mapfilesize = (((int) tempc)<<24);
  1191.     if (pack_fread (&tempc, 1, mapfilept) == 1) {
  1192.     mapfilesize |= (((int) tempc)<<16);
  1193.     if (pack_fread (&tempc, 1, mapfilept) == 1) {
  1194.     mapfilesize |= (((int) tempc)<<8);
  1195.     if (pack_fread (&tempc, 1, mapfilept) == 1) {
  1196.     mapfilesize |= (((int) tempc));
  1197.     mapfilesize += 8;
  1198.     if (!strncmp (idtag, "FORM", 4)) {
  1199.     if (pack_fread (&idtag[0], 1, mapfilept) == 1) {
  1200.     if (pack_fread (&idtag[1], 1, mapfilept) == 1) {
  1201.     if (pack_fread (&idtag[2], 1, mapfilept) == 1) {
  1202.     if (pack_fread (&idtag[3], 1, mapfilept) == 1) {
  1203.     if (!strncmp (idtag, "FMAP", 4)) maperror = MER_NONE;
  1204.     } } } } }
  1205.     } } } } } } } }
  1206.  
  1207.     if (maperror != MER_NONE) { pack_fclose (mapfilept); return -1; }
  1208.  
  1209.     mretval = MapRealDecode (mapfilept, NULL, mapfilesize);
  1210.     pack_fclose (mapfilept);
  1211.  
  1212.     return mretval;
  1213. }
  1214.  
  1215. int MapLoad (char * mapname)
  1216. {
  1217.     mapgfxinbitmaps = 2;
  1218.     return MapRealLoad (mapname);
  1219. }
  1220.  
  1221. int MapLoadVRAM (char * mapname)
  1222. {
  1223.     mapgfxinbitmaps = 1;
  1224.     return MapRealLoad (mapname);
  1225. }
  1226.  
  1227. int MapLoadABM (char * mapname)
  1228. {
  1229.     mapgfxinbitmaps = 2;
  1230.     return MapRealLoad (mapname);
  1231. }
  1232.  
  1233. int MapPreRealDecode (unsigned char * mapmempt)
  1234. {
  1235. long int maplength;
  1236.  
  1237.     MapFreeMem ();
  1238.     maperror = 0;
  1239.  
  1240.     if (*mapmempt!='F') maperror = MER_MAPLOADERROR;
  1241.     if (*(mapmempt+1)!='O') maperror = MER_MAPLOADERROR;
  1242.     if (*(mapmempt+2)!='R') maperror = MER_MAPLOADERROR;
  1243.     if (*(mapmempt+3)!='M') maperror = MER_MAPLOADERROR;
  1244.     mapmempt += 4;
  1245.     maplength = (MapGetchksz (mapmempt))+8;
  1246.  
  1247.     if (maperror) return -1;
  1248.     mapmempt += 4;
  1249.  
  1250.     if (*mapmempt!='F') maperror = MER_MAPLOADERROR;
  1251.     if (*(mapmempt+1)!='M') maperror = MER_MAPLOADERROR;
  1252.     if (*(mapmempt+2)!='A') maperror = MER_MAPLOADERROR;
  1253.     if (*(mapmempt+3)!='P') maperror = MER_MAPLOADERROR;
  1254.     mapmempt+=4;
  1255.  
  1256.     if (maperror) return -1;
  1257.     return MapRealDecode (NULL, mapmempt, maplength);
  1258. }
  1259.  
  1260. int MapDecode (unsigned char * mapmempt)
  1261. {
  1262.     mapgfxinbitmaps = 2;
  1263.     return MapPreRealDecode (mapmempt);
  1264. }
  1265.  
  1266. int MapDecodeVRAM (unsigned char * mapmempt)
  1267. {
  1268.     mapgfxinbitmaps = 1;
  1269.     return MapPreRealDecode (mapmempt);
  1270. }
  1271.  
  1272. int MapDecodeABM (unsigned char * mapmempt)
  1273. {
  1274.     mapgfxinbitmaps = 2;
  1275.     return MapPreRealDecode (mapmempt);
  1276. }
  1277.  
  1278. BITMAP * MapMakeParallaxBitmap (BITMAP * sourcebm, int style)
  1279. {
  1280. BITMAP * newbm;
  1281.  
  1282.     if (mappt == NULL) return NULL;
  1283.     if (style < 0 || style > 1) return NULL;
  1284.  
  1285.     if (style) newbm = create_video_bitmap (sourcebm->w+mapblockwidth, sourcebm->h+mapblockheight);
  1286.     else newbm = create_bitmap (sourcebm->w+mapblockwidth, sourcebm->h+mapblockheight);
  1287.  
  1288.     if (newbm == NULL) return NULL;
  1289.     blit (sourcebm, newbm, 0, 0, 0, 0, sourcebm->w, sourcebm->h);
  1290.     blit (sourcebm, newbm, 0, 0, 0, sourcebm->h, sourcebm->w, mapblockheight);
  1291.     blit (newbm, newbm, 0, 0, sourcebm->w, 0, mapblockwidth, sourcebm->h+mapblockheight);
  1292.     return newbm;
  1293. }
  1294.  
  1295. void MapDrawParallax (BITMAP * mapdestpt, BITMAP * parbm, int mapxo, int mapyo, int mapx, int mapy,
  1296.     int mapw, int maph)
  1297. /* mapdestpt = standard allegro bitmap, MEMORY or VIDEO bitmap.
  1298.  * parbm = standard allegro bitmap. MEMORY or VIDEO bitmap.
  1299.  * mapxo = offset, in pixels, from the left edge of the map.
  1300.  * mapyo = offset, in pixels, from the top edge of the map.
  1301.  * mapx  = offset, in pixels, from the left edge of the BITMAP.
  1302.  * mapy  = offset, in pixels, from the top edge of the BITMAP.
  1303.  * mapw  = width, in pixels, of drawn area.
  1304.  * maph  = height, in pixels, of drawn area.
  1305.  */
  1306. {
  1307. int mycl, mycr, myct, mycb;
  1308. int i, i2, j;
  1309. int paraxo, paraxo2, parayo;
  1310. short int * mymappt, * mymappt2;
  1311. BLKSTR * blkdatapt;
  1312. ANISTR * myanpt;
  1313.  
  1314.     if (mapblockstaggerx || mapblockstaggery) return;
  1315.     mycl = mapdestpt->cl;
  1316.     mycr = mapdestpt->cr;
  1317.     myct = mapdestpt->ct;
  1318.     mycb = mapdestpt->cb;
  1319.     set_clip (mapdestpt, mapx, mapy, mapx+mapw-1, mapy+maph-1);
  1320.  
  1321.     mymappt = (short int *) mappt;
  1322.     mymappt += (mapxo/mapblockwidth)+((mapyo/mapblockheight)*mapwidth);
  1323.  
  1324.     paraxo = ((mapxo-(mapxo%mapblockwidth))%(parbm->w-mapblockwidth))-((mapxo/2)%(parbm->w-mapblockwidth));
  1325.     parayo = ((mapyo-(mapyo%mapblockheight))%(parbm->h-mapblockheight))-((mapyo/2)%(parbm->h-mapblockheight));
  1326.     while (paraxo < 0) paraxo += (parbm->w-mapblockwidth);
  1327.     while (parayo < 0) parayo += (parbm->h-mapblockheight);
  1328.  
  1329.     i = mapx-(mapxo%mapblockwidth);
  1330.     j = mapy-(mapyo%mapblockheight);
  1331.  
  1332.     i2 = i; paraxo2 = paraxo; mymappt2 = mymappt;
  1333.     while (j < (mapy+maph)) {
  1334.         while (i < (mapx+mapw)) {
  1335.             if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1336.             else { myanpt = mapanimstrendpt + *mymappt;
  1337.                 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1338.             if (blkdatapt->trigger)
  1339.                 blit (parbm, mapdestpt, paraxo, parayo, i, j, mapblockwidth, mapblockheight);
  1340.             paraxo += mapblockwidth;
  1341.             if (paraxo >= (parbm->w-mapblockwidth)) paraxo -= (parbm->w-mapblockwidth);
  1342.             i += mapblockwidth; mymappt++;
  1343.         }
  1344.         parayo += mapblockheight;
  1345.         if (parayo >= (parbm->h-mapblockheight)) parayo -= (parbm->h-mapblockheight);
  1346.         i = i2; paraxo = paraxo2; mymappt2 += mapwidth; mymappt = mymappt2;
  1347.         j += mapblockheight;
  1348.     }
  1349.     set_clip (mapdestpt, mycl, myct, mycr+1, mycb+1);
  1350. }
  1351.  
  1352. void MapDrawBG (BITMAP * mapdestpt, int mapxo, int mapyo, int mapx, int mapy,
  1353.     int mapw, int maph)
  1354. {
  1355. int i, j, mycl, mycr, myct, mycb, mapvclip, maphclip;
  1356. int mbgx, mbgy;
  1357. short int *mymappt;
  1358. short int *mymap2pt;
  1359. BLKSTR *blkdatapt;
  1360. ANISTR *myanpt;
  1361.  
  1362.     if (!mapgfxinbitmaps) {
  1363.         return;
  1364.     } else {
  1365.         mycl = mapdestpt->cl;
  1366.         mycr = mapdestpt->cr;
  1367.         myct = mapdestpt->ct;
  1368.         mycb = mapdestpt->cb;
  1369.         set_clip (mapdestpt, mapx, mapy, mapx+mapw-1, mapy+maph-1);
  1370.         mapxo -= mapblockstaggerx;
  1371.         mapyo -= mapblockstaggery;
  1372.         mymappt = (short int *) mappt;
  1373.         if (mapblockstaggerx || mapblockstaggery) {
  1374.             mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth*2);
  1375.             mbgx = mapblockgapx;
  1376.             mbgy = mapblockgapy;
  1377.         } else {
  1378.             mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth);
  1379.             mbgx = 0;
  1380.             mbgy = 0;
  1381.         }
  1382.         mapvclip = mapyo%mapblockgapy;
  1383.         maphclip = mapxo%mapblockgapx;
  1384.  
  1385.         mymap2pt = mymappt;
  1386.         for (j=((mapy-mapvclip)-mbgy);j<((mapy+maph));j+=mapblockgapy) {
  1387.         for (i=((mapx-maphclip)-mbgx);i<((mapx+mapw));i+=mapblockgapx) {
  1388.             if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1389.             else { myanpt = mapanimstrendpt + *mymappt;
  1390.                 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1391.             if (mapblockstaggerx || mapblockstaggery) {
  1392.             if (abmTiles[0] != (BITMAP *) blkdatapt->bgoff)
  1393.                 masked_blit ((BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
  1394.             } else {
  1395.                 blit ((BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
  1396.             }
  1397.             mymappt++;
  1398.         }
  1399.         if (mapblockstaggerx || mapblockstaggery) {
  1400.             mymap2pt += mapwidth;
  1401.             mymappt = mymap2pt;
  1402.             for (i=(((mapx-maphclip)-mbgx)+mapblockstaggerx);i<((mapx+mapw));i+=mapblockgapx) {
  1403.                 if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1404.                 else { myanpt = mapanimstrendpt + *mymappt;
  1405.                     blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1406.                 if (abmTiles[0] != (BITMAP *) blkdatapt->bgoff)
  1407.                     masked_blit ((BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j+mapblockstaggery, mapblockwidth, mapblockheight);
  1408.                 mymappt++;
  1409.             }
  1410.         }
  1411.         mymap2pt += mapwidth;
  1412.         mymappt = mymap2pt;
  1413.         }
  1414.  
  1415.         set_clip (mapdestpt, mycl, myct, mycr+1, mycb+1);
  1416.     }
  1417. }
  1418.  
  1419. void MapDrawBGT (BITMAP * mapdestpt, int mapxo, int mapyo, int mapx, int mapy,
  1420.     int mapw, int maph)
  1421. {
  1422. int i, j, mycl, mycr, myct, mycb, mapvclip, maphclip;
  1423. short int *mymappt;
  1424. short int *mymap2pt;
  1425. BLKSTR *blkdatapt;
  1426. ANISTR *myanpt;
  1427.  
  1428.     if (mapblockstaggerx || mapblockstaggery) {
  1429.         MapDrawBG (mapdestpt, mapxo, mapyo, mapx, mapy, mapw, maph);
  1430.         return;
  1431.     }
  1432.     if (!mapgfxinbitmaps) {
  1433.         return;
  1434.     } else {
  1435.         mycl = mapdestpt->cl;
  1436.         mycr = mapdestpt->cr;
  1437.         myct = mapdestpt->ct;
  1438.         mycb = mapdestpt->cb;
  1439.         set_clip (mapdestpt, mapx, mapy, mapx+mapw-1, mapy+maph-1);
  1440.         mymappt = (short int *) mappt;
  1441.         mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth);
  1442.         mapvclip = mapyo%mapblockgapy;
  1443.         maphclip = mapxo%mapblockgapx;
  1444.  
  1445.         mymap2pt = mymappt;
  1446.         for (j=(mapy-mapvclip);j<((mapy+maph));j+=mapblockgapy) {
  1447.         for (i=(mapx-maphclip);i<((mapx+mapw));i+=mapblockgapx) {
  1448.             if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1449.             else { myanpt = mapanimstrendpt + *mymappt;
  1450.                 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1451.             if (blkdatapt->trigger) {
  1452.             if (abmTiles[0] != (BITMAP *) blkdatapt->bgoff)
  1453.                 masked_blit ((BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
  1454.             } else {
  1455.                 blit ((BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
  1456.             }
  1457.             mymappt++;
  1458.         }
  1459.         mymap2pt += mapwidth;
  1460.         mymappt = mymap2pt;
  1461.         }
  1462.  
  1463.         set_clip (mapdestpt, mycl, myct, mycr+1, mycb+1);
  1464.     }
  1465. }
  1466.  
  1467. void MapDrawFG (BITMAP * mapdestpt, int mapxo, int mapyo, int mapx, int mapy,
  1468.     int mapw, int maph, int mapfg)
  1469. {
  1470. int i, j, mycl, mycr, myct, mycb, mapvclip, maphclip;
  1471. int mbgx, mbgy;
  1472. short int *mymappt;
  1473. short int *mymap2pt;
  1474. BLKSTR *blkdatapt;
  1475. ANISTR *myanpt;
  1476. BITMAP *mapgfxpt;
  1477.  
  1478.     if (!mapgfxinbitmaps) {
  1479.         return;
  1480.     } else {
  1481.         mycl = mapdestpt->cl;
  1482.         mycr = mapdestpt->cr;
  1483.         myct = mapdestpt->ct;
  1484.         mycb = mapdestpt->cb;
  1485.         set_clip (mapdestpt, mapx, mapy, mapx+mapw-1, mapy+maph-1);
  1486.         mapxo -= mapblockstaggerx;
  1487.         mapyo -= mapblockstaggery;
  1488.         mymappt = (short int *) mappt;
  1489.         if (mapblockstaggerx || mapblockstaggery) {
  1490.             mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth*2);
  1491.             mbgx = mapblockgapx;
  1492.             mbgy = mapblockgapy;
  1493.         } else {
  1494.             mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth);
  1495.             mbgx = 0;
  1496.             mbgy = 0;
  1497.         }
  1498.         mapvclip = mapyo%mapblockgapy;
  1499.         maphclip = mapxo%mapblockgapx;
  1500.  
  1501.         mymap2pt = mymappt;
  1502.         for (j=((mapy-mapvclip)-mbgy);j<((mapy+maph));j+=mapblockgapy) {
  1503.         for (i=((mapx-maphclip)-mbgx);i<((mapx+mapw));i+=mapblockgapx) {
  1504.             if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1505.             else { myanpt = mapanimstrendpt + *mymappt;
  1506.                 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1507.             if (!mapfg) mapgfxpt = (BITMAP *) blkdatapt->fgoff;
  1508.             else if (mapfg == 1) mapgfxpt = (BITMAP *) blkdatapt->fgoff2;
  1509.             else mapgfxpt = (BITMAP *) blkdatapt->fgoff3;
  1510.             if (((int)mapgfxpt) != 0)
  1511.                 masked_blit (mapgfxpt, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
  1512.             mymappt++;
  1513.         }
  1514.         if (mapblockstaggerx || mapblockstaggery) {
  1515.         mymap2pt += mapwidth;
  1516.         mymappt = mymap2pt;
  1517.         for (i=(((mapx-maphclip)-mbgx)+mapblockstaggerx);i<((mapx+mapw));i+=mapblockgapx) {
  1518.             if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1519.             else { myanpt = mapanimstrendpt + *mymappt;
  1520.                 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1521.             if (!mapfg) mapgfxpt = (BITMAP *) blkdatapt->fgoff;
  1522.             else if (mapfg == 1) mapgfxpt = (BITMAP *) blkdatapt->fgoff2;
  1523.             else mapgfxpt = (BITMAP *) blkdatapt->fgoff3;
  1524.             if (((int)mapgfxpt) != 0)
  1525.                 masked_blit (mapgfxpt, mapdestpt, 0, 0, i, j+mapblockstaggery, mapblockwidth, mapblockheight);
  1526.             mymappt++;
  1527.         }
  1528.         }
  1529.         mymap2pt += mapwidth;
  1530.         mymappt = mymap2pt;
  1531.         }
  1532.  
  1533.         set_clip (mapdestpt, mycl, myct, mycr+1, mycb+1);
  1534.     }
  1535. }
  1536.  
  1537. void MapDrawRow (BITMAP * mapdestpt, int mapxo, int mapyo, int mapx, int mapy,
  1538.     int mapw, int maph, int maprw, void (*cellcall) (int cx, int cy, int dx, int dy))
  1539. {
  1540. int i, j, mycl, mycr, myct, mycb, mapvclip, maphclip;
  1541. int mbgx, mbgy, bfield, bysub;
  1542. int cx, cy;
  1543. short int *mymappt;
  1544. short int *mymap2pt;
  1545. BLKSTR *blkdatapt;
  1546. ANISTR *myanpt;
  1547. BITMAP *mapgfxpt;
  1548.  
  1549.     if (((mapyo/mapblockgapy)+maprw) >= mapheight) return;
  1550.     if (mapblockstaggerx || mapblockstaggery) {
  1551.         mapxo -= mapblockstaggerx;
  1552.         mapyo -= mapblockstaggery;
  1553.         if ((((mapyo/mapblockgapy)*2)+maprw) >= (mapheight-1)) return;
  1554.     }
  1555.     if (!mapgfxinbitmaps) {
  1556.         return;
  1557.     } else {
  1558.         mycl = mapdestpt->cl;
  1559.         mycr = mapdestpt->cr;
  1560.         myct = mapdestpt->ct;
  1561.         mycb = mapdestpt->cb;
  1562.         set_clip (mapdestpt, mapx, mapy, mapx+mapw-1, mapy+maph-1);
  1563.         mymappt = (short int *) mappt;
  1564.         mapvclip = mapyo%mapblockgapy;
  1565.         maphclip = mapxo%mapblockgapx;
  1566.         j = (mapy-mapvclip); i = 0;
  1567.         if (mapblockstaggerx || mapblockstaggery) {
  1568.             cx = mapxo/mapblockgapx;
  1569.             cy = (((mapyo/mapblockgapy)*2)+maprw);
  1570.             mymappt += (cx)+(cy*mapwidth);
  1571.             mbgx = mapblockgapx;
  1572.             mbgy = mapblockgapy;
  1573.             j -= mbgy;
  1574.             j += ((maprw/2)*mapblockgapy);
  1575.             if (maprw&1) { j += mapblockstaggery; i = mapblockstaggerx; }
  1576.         } else {
  1577.             cx = mapxo/mapblockgapx;
  1578.             cy = ((mapyo/mapblockgapy)+maprw);
  1579.             mymappt += (cx)+(cy*mapwidth);
  1580.             mbgx = 0;
  1581.             mbgy = 0;
  1582.             j += (maprw*mapblockgapy);
  1583.         }
  1584.  
  1585.         mymap2pt = mymappt;
  1586.         for (i+=((mapx-maphclip)-mbgx);i<((mapx+mapw));i+=mapblockgapx) {
  1587.             if (cellcall != NULL) cellcall (cx, cy, i, j);
  1588.             if (*mymappt>=0) blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
  1589.             else { myanpt = mapanimstrendpt + *mymappt;
  1590.                 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
  1591.             bfield = 1; bysub = 0;
  1592.             do {
  1593.             if (!bfield) blkdatapt++;
  1594.             for (;bfield<4;bfield++) {
  1595.             switch (bfield) {
  1596.                 case 0: mapgfxpt = (BITMAP *) blkdatapt->bgoff; break;
  1597.                 case 1: mapgfxpt = (BITMAP *) blkdatapt->fgoff; break;
  1598.                 case 2: mapgfxpt = (BITMAP *) blkdatapt->fgoff2; break;
  1599.                 default:
  1600.                 case 3: mapgfxpt = (BITMAP *) blkdatapt->fgoff3; break;
  1601.             }
  1602.             if (((int)mapgfxpt) != 0) {
  1603.                 if (blkdatapt->unused2 && !blkdatapt->unused3) {
  1604.                     masked_blit (mapgfxpt, mapdestpt, 0, 0, i, j-bysub, mapblockwidth/2, mapblockheight);
  1605.                 } else {
  1606.                     if (!blkdatapt->unused2 && blkdatapt->unused3) {
  1607.                         masked_blit (mapgfxpt, mapdestpt, mapblockwidth/2, 0, i, j-bysub, mapblockwidth/2, mapblockheight);
  1608.                     } else {
  1609.                         masked_blit (mapgfxpt, mapdestpt, 0, 0, i, j-bysub, mapblockwidth, mapblockheight);
  1610.                     }
  1611.                 }
  1612.             }
  1613.             bysub += mapblockheight;
  1614.             }
  1615.             bfield = 0;
  1616.             } while (blkdatapt->unused1);
  1617.             mymappt++; cx++;
  1618.         }
  1619.  
  1620.         set_clip (mapdestpt, mycl, myct, mycr+1, mycb+1);
  1621.     }
  1622. }
  1623.