Advertisement
ZoriaRPG

AutoMap.zs - A Zelda Classic DMap AutoMapping Utility Header

Oct 14th, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.54 KB | None | 0 0
  1. //An attempt at an automapping header.
  2. //v0.2.2
  3. //By: ZoriaRPG
  4.  
  5. int MapFlags[214747]; //Holds map space datum, such as room type, and special icons to draw.
  6. int MapDoorFlags[214747]; //Holds room door pattern.
  7.  
  8. ffc script SetMapFlags{
  9.     void run(int doorUp, int doorDown, int doorLeft, int doorRight, int bossRoom, int specialItem, int miscFlag_1, int miscFlag2){
  10.         int indx = GetCurrentMapIndex();
  11.        
  12.  
  13.  
  14. //int MapData[214747];
  15. //int MapDMaps[214747];
  16. //int MapScreens[214747];
  17.        
  18.         //! Can we condense these into one flagset as an integer|?
  19.         //! |No, we need one door flag, PER DOOR, so that's exceed 18 bits.
  20.        
  21.         //We're using 20 bits thus far. Can we simplify this to use the decimal values as a 32b flag?
  22.        
  23.  
  24. //Integer flags, for the room type and icons. 0 to 2048
  25. const int MAP_FLAG_BLANK    =   000000000000b;
  26. const int MAP_FLAG_ROOM     =   000000000001b;
  27. const int MAP_FLAG_VISITED  =   000000000010b;
  28. const int MAP_FLAG_ITEM     =   000000000100b;
  29. const int MAP_FLAG_CHEST    =   000000001000b;
  30. const int MAP_FLAG_KEY      =   000000010000b;
  31. const int MAP_FLAG_BOSSKEY  =   000000100000b;
  32. const int MAP_FLAG_BOSSCHEST    =   000001000000b;
  33. const int MAP_FLAG_SAVE     =   000010000000b;
  34. const int MAP_FLAG_BOSS     =   000100000000b;
  35. const int MAP_FLAG_MIDBOSS  =   001000000000b;
  36. const int MAP_FLAG_TRIFORCE     =   010000000000b;
  37.  
  38. //Decimal flags, for the door types. 0 to 64
  39. //const int MAP_DOOR_       =
  40. const int MAP_DOOR_UP_NONE      =   000000000000b;
  41. const int MAP_DOOR_UP_BOMB      =   000000000001b;
  42. const int MAP_DOOR_UP_OPEN      =   000000000010b;
  43. const int MAP_DOOR_UP_SHUTTER       =   000000000100b;
  44. const int MAP_DOOR_UP_LOCKED        =   000000001000b;
  45. const int MAP_DOOR_UP_BOSSLOCKED    =   000000010000b;
  46. const int MAP_DOOR_UP_WALKTHROUGH   =   000000100000b;
  47.  
  48. const int MAP_DOOR_DOWN_NONE        =   000000000000b;
  49. const int MAP_DOOR_DOWN_BOMB        =   000000000001b;
  50. const int MAP_DOOR_DOWN_OPEN        =   000000000010b;
  51. const int MAP_DOOR_DOWN_SHUTTER     =   000000000100b;
  52. const int MAP_DOOR_DOWN_LOCKED      =   000000001000b;
  53. const int MAP_DOOR_DOWN_BOSSLOCKED  =   000000010000b;
  54. const int MAP_DOOR_DOWN_WALKTHROUGH =   000000100000b;
  55.  
  56. const int MAP_DOOR_LEFT_NONE        =   000000000000b;
  57. const int MAP_DOOR_LEFT_BOMB        =   000000000001b;
  58. const int MAP_DOOR_LEFT_OPEN        =   000000000010b;
  59. const int MAP_DOOR_LEFT_SHUTTER     =   000000000100b;
  60. const int MAP_DOOR_LEFT_LOCKED      =   000000001000b;
  61. const int MAP_DOOR_LEFT_BOSSLOCKED  =   000000010000b;
  62. const int MAP_DOOR_LEFT_WALKTHROUGH =   000000100000b;
  63.  
  64. const int MAP_DOOR_RIGHT_NONE       =   000000000000b;
  65. const int MAP_DOOR_RIGHT_BOMB       =   000000000001b;
  66. const int MAP_DOOR_RIGHT_OPEN       =   000000000010b;
  67. const int MAP_DOOR_RIGHT_SHUTTER    =   000000000100b;
  68. const int MAP_DOOR_RIGHT_LOCKED     =   000000001000b;
  69. const int MAP_DOOR_RIGHT_BOSSLOCKED =   000000010000b;
  70. const int MAP_DOOR_RIGHT_WALKTHROUGH    =   000000100000b;
  71.  
  72.  
  73. const int MAP_DOOR_UP_NONE      =   0000000000000001b;
  74. const int MAP_DOOR_UP_BOMB      =   0000000000000010b;
  75. const int MAP_DOOR_UP_OPEN      =   0000000000000100b;
  76. const int MAP_DOOR_UP_SHUTTER       =   0000000000001000b;
  77. const int MAP_DOOR_UP_LOCKED        =   0000000000010000b;
  78. const int MAP_DOOR_UP_BOSSLOCKED    =   0000000000100000b;
  79. const int MAP_DOOR_UP_WALKTHROUGH   =   0000000001000000b;
  80.  
  81. const int MAP_DOOR_DOWN_NONE        =   0000000010000000b;
  82. const int MAP_DOOR_DOWN_BOMB        =   0000000100000000b;
  83. const int MAP_DOOR_DOWN_OPEN        =   0000001000000000b;
  84. const int MAP_DOOR_DOWN_SHUTTER     =   0000010000000000b;
  85. const int MAP_DOOR_DOWN_LOCKED      =   0000100000000000b;
  86. const int MAP_DOOR_DOWN_BOSSLOCKED  =   0001000000000000b;
  87. const int MAP_DOOR_DOWN_WALKTHROUGH =   0010000000000000b;
  88.  
  89. const int MAP_DOOR_LEFT_NONE        =   01000000000000000b;
  90. const int MAP_DOOR_LEFT_BOMB        =   10000000000000000b; //Last possible value under 214747.
  91. //! The rest would need to be the decimals.
  92. const int MAP_DOOR_LEFT_OPEN        =   00000000000001b;
  93. const int MAP_DOOR_LEFT_SHUTTER     =   00000000000010b;
  94. const int MAP_DOOR_LEFT_LOCKED      =   00000000000100b;
  95. const int MAP_DOOR_LEFT_BOSSLOCKED  =   00000000001000b;
  96. const int MAP_DOOR_LEFT_WALKTHROUGH =   00000000010000b;
  97. const int MAP_DOOR_RIGHT_NONE       =   00000001000000b;
  98. const int MAP_DOOR_RIGHT_BOMB       =   00000010000000b;
  99. const int MAP_DOOR_RIGHT_OPEN       =   00000100000000b;
  100. const int MAP_DOOR_RIGHT_SHUTTER    =   00001000000000b;
  101. const int MAP_DOOR_RIGHT_LOCKED     =   00010000000000b;
  102. const int MAP_DOOR_RIGHT_BOSSLOCKED =   00100000000000b;
  103. const int MAP_DOOR_RIGHT_WALKTHROUGH    =   01000000000000b; //through 2048 (4096 sum of flags)
  104.  
  105. //! How would this look as a single flagset?!
  106. /*
  107. const int MAP_DOOR_UP_NONE      =   00000000000000000000000000001b;
  108. const int MAP_DOOR_UP_BOMB      =   00000000000000000000000000010b;
  109. const int MAP_DOOR_UP_OPEN      =   00000000000000000000000000100b;
  110. const int MAP_DOOR_UP_SHUTTER       =   00000000000000000000000001000b;
  111. const int MAP_DOOR_UP_LOCKED        =   00000000000000000000000010000b;
  112. const int MAP_DOOR_UP_BOSSLOCKED    =   00000000000000000000000100000b;
  113. const int MAP_DOOR_UP_WALKTHROUGH   =   00000000000000000000001000000b;
  114. const int MAP_DOOR_DOWN_NONE        =   00000000000000000000010000000b;
  115. const int MAP_DOOR_DOWN_BOMB        =   00000000000000000000100000000b;
  116. const int MAP_DOOR_DOWN_OPEN        =   00000000000000000001000000000b;
  117. const int MAP_DOOR_DOWN_SHUTTER     =   00000000000000000010000000000b;
  118. const int MAP_DOOR_DOWN_LOCKED      =   00000000000000000100000000000b;
  119. const int MAP_DOOR_DOWN_BOSSLOCKED  =   00000000000000001000000000000b;
  120. const int MAP_DOOR_DOWN_WALKTHROUGH =   00000000000000010000000000000b;
  121.  
  122. const int MAP_DOOR_LEFT_NONE        =   00000000000001000000000000000b;
  123. const int MAP_DOOR_LEFT_BOMB        =   00000000000010000000000000000b; //Last possible value under 214747.
  124. //! The rest would need to be the decimals.
  125. const int MAP_DOOR_LEFT_OPEN        =   00000000000100000000000000000b;
  126. const int MAP_DOOR_LEFT_SHUTTER     =   00000000001000000000000000000b;
  127. const int MAP_DOOR_LEFT_LOCKED      =   00000000010000000000000000000b;
  128. const int MAP_DOOR_LEFT_BOSSLOCKED  =   00000000100000000000000000000b;
  129. const int MAP_DOOR_LEFT_WALKTHROUGH =   00000001000000000000000000000b;
  130.  
  131. const int MAP_DOOR_RIGHT_NONE       =   00000010000000000000000000000b;
  132. const int MAP_DOOR_RIGHT_BOMB       =   00000100000000000000000000000b;
  133. const int MAP_DOOR_RIGHT_OPEN       =   00001000000000000000000000000b;
  134. const int MAP_DOOR_RIGHT_SHUTTER    =   00010000000000000000000000000b;
  135. const int MAP_DOOR_RIGHT_LOCKED     =   00100000000000000000000000000b;
  136. const int MAP_DOOR_RIGHT_BOSSLOCKED =   01000000000000000000000000000b;
  137. const int MAP_DOOR_RIGHT_WALKTHROUGH    =   10000000000000000000000000000b; //through 2048 (4096 sum of flags)
  138.  
  139. */
  140.  
  141. const int MAP_DOOR_OTHER    =   000001000000b;
  142.        
  143.  
  144. void SetMapFlag(int index, int flag, bool state){
  145.     if ( state ) MapFlags[index] |= flag;
  146.     else MapFlags[index] &= ~flag;
  147. }
  148.  
  149. void GetMapFlag(int index, int flag){
  150.     return ( MapFlags[index]&flag ) != 0;
  151. }
  152.  
  153. //An arbitrary way to find the index for a specific screen and dmap.
  154. //We probably do not want to go tis route, and we'll use dmap sizing to stitch them together, then hardcode
  155. //their attributes so that we know what each index is.
  156. //
  157. //We can set constant floats for each room if desired, but this is certainly the lazy approach.
  158. int GetRoom(int dmap, int screen){
  159.     int scr; int dmp; int q; int w; int index;
  160.     for ( q = 0; q < SizeOfArray(MapDMaps); q++ ) {
  161.         if ( MapDMaps[q] == dmap && MapScreens[q] == screen ) return q;
  162.     }
  163.     return -1;
  164. }
  165.  
  166. //We draw 8x8 tiles for eacdh map space. These may be black (blank), grey (room), or blue (visited room).
  167. //We use the flags for each index to draw the rooms.
  168. const int MAP_TILE_EMPTYSPACE = 1000;
  169. const int MAP_TILE_ROOM = 1001;
  170. const int MAP_TILE_ROOMVISITED = 1002;
  171. const int MAP_ICON_ROOMITEM = 1003; //Overlay = icon
  172. const int MAP_ICON_ROOMSAVE = 1004;
  173. const int MAP_ICON_BOSS = 1005;
  174.  
  175. const int MAP_OVERALL_WIDTH_COLUMNS = 500;
  176. const int MAP_OVERALL_HEIGHT_ROWS = 100;
  177.  
  178. void DrawMapRoomsToBitmap(){
  179.     int q; int w; int x; int y;
  180.     for ( q = 0; q < SizeOfArray(MapFlags); q++ ) {
  181.         //Draw those rows
  182.         if ( q > 0 && q % MAP_OVERALL_WIDTH_COLUMNS == 0 ) { y += MAP_ROOM_Y; x = 0; } //New line
  183.         //Draw the rooms and scale them.
  184.         if ( GetMapFlag(q, MAP_FLAG_BLANK) ) DrawTile(q, MAP_TILE_EMPTYSPACE, MAP_TILE_WIDTH, MAP_TILE_HEIGHT);
  185.         if ( GetMapFlag(q, MAP_FLAG_ROOM) && !GetMapFlag(q, MAP_FLAG_VISITED) ) DrawTile(q, MAP_TILE_ROOM, MAP_TILE_WIDTH, MAP_TILE_HEIGHT);
  186.         if ( GetMapFlag(q, MAP_FLAG_ROOM) && GetMapFlag(q, MAP_FLAG_VISITED) ) DrawTile(q, MAP_TILE_VISITED, MAP_TILE_WIDTH, MAP_TILE_HEIGHT);
  187.         //Draw any room icons
  188.         if ( GetMapFlag(q, MAP_FLAG_BOSS) ) DrawTile(q, MAP_ICON_BOSS, MAP_TILE_WIDTH, MAP_TILE_HEIGHT);
  189.         if ( GetMapFlag(q, MAP_FLAG_ITEM) ) DrawTile(q, MAP_ICON_ROOMITEM, MAP_TILE_WIDTH, MAP_TILE_HEIGHT);
  190.         if ( GetMapFlag(q, MAP_FLAG_SAVE) ) DrawTile(q, MAP_ICON_ROOMSAVE, MAP_TILE_WIDTH, MAP_TILE_HEIGHT);
  191.        
  192.         //Next room
  193.         x += MAP_ROOM_X;
  194.     }
  195. }
  196.    
  197.  
  198. const int MAP_TILE_WIDTH = 8;
  199. const int MAP_ROOM_X = 10;
  200. const int MAP_ROOM_Y = 10;
  201. const int MAP_ROOM_CENTER = 2;
  202.  
  203. //We draw rooms in a pseudo-grid. Each room is a tile, drawn every ROOM_X pixels, in a row.
  204. //Each row is drawn ROOM_Y pixels below the previosu row, to the bitmap.
  205.  
  206. const int MAP_BITMAP = 4;
  207. const int MAP_SLICE_X = 200; //20 rooms.
  208. const int MAP_SLICE_Y = 120; //12 rooms.
  209.  
  210. void FindMapCentre(){} //Find the centre of the map based on the present room.
  211. const int MAP_DRAW_OFFSET_X = 100; //Half the size of the map, from the centre.
  212. const int MAP_DRAW_OFFSET_Y = 60;  //Half the size of the map, from the centre.
  213.  
  214. void MapToScreen(){
  215.     // We draw the map from the bitmap, on layer 7. To accomplish this, we find its centre, and draw the
  216.     // upper-left corner based on the true centre ( FindMapCentre() - OFFSETS), minus the offsets,
  217.     // and set the full width and height to its size (MAP_SLICE).
  218.     Screen->DrawBitmap(MAP_DRAW_LAYER, MAP_BITMAP, (FindMapCentre() - MAP_DRAW_OFFSET_X), (FindMapCentre() - MAP_DRAW_OFFSET_Y), MAP_SLICE_X, MAP_SLICE_Y, true);
  219. }
  220.    
  221. const int MAP_DRAW_LAYER = 7;
  222. const int MAP_DRAW_X = 4; //Upper-left corner of map display.
  223. const int MAP_DRAW_Y = 4;
  224.  
  225. //Dmaps
  226.  
  227. //If we predefine the exact width and height of each dmap, we can stitch them together.
  228. const int DMAP_WIDTH_1 = 16; //16 rooma
  229. const int DMAP_HEIGHT_1 = 8; //8 rooms
  230. const int DMAP_WIDTH_1 = 8; //8 rooma
  231. const int DMAP_HEIGHT_1 = 8; //8 rooms
  232. //...
  233.  
  234. ///...then we define the placement of the dmap in the overall map.
  235. const int FIRST_ROW_DMAP_1 = 0;
  236. const int FIRST_COLUMN_DMAP_1 = 0;
  237. const int LAST_COLUMN_DMAP_1 = 15;
  238. const int LAST_ROW_DMAP_1 = 7;
  239.  
  240. const int FIRST_ROW_DMAP_2 = 0;
  241. const int FIRST_COLUMN_DMAP_2 = 16; //This dmap would be stitched to the exact right of dmap 1
  242. const int LAST_COLUMN_DMAP_1 = 23; //This would be an 8x8 DMAp attached to a 16x8 DMAP.
  243. const int LAST_ROW_DMAP_1 = 7;
  244.  
  245. void DoMap(){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement