Advertisement
ZoriaRPG

ZScript: Flying Fortress Alpha 0.7

Jul 1st, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.33 KB | None | 0 0
  1. import "std.zh"
  2.  
  3. int fortress_virtual_map_IDs[255];
  4.  
  5. global script init{
  6.     void run(){
  7.  
  8.         //Map 106.
  9.         fortress_virtual_map_IDs[0] = virtual_map_overworld_desert;
  10.         //Set style attributes for fortress 0.
  11.         SetFortressInitialAttributes(0, DEFAULT_FORTRESS_X, DEFAULT_FORTRESS_Y, DEFAULT_FORTRESS_DMAP, DEFAULT_FORTRESS_SCREEN,
  12.         DEFAULT_FORTRESS_DIR, DEFAULT_FORTRESS_SPEED, DEFAULT_FORTRESS_TIME, DEFAULT_FORTRESS_TILE, DEFAULT_FORTRESS_TILEWIDTH,
  13.         DEFAULT_FORTRESS_TILEHEIGHT, DEFAULT_FORTRESS_SCALE, DEFAULT_FORTRESS_CSET, DEFAULT_FORTRESS_SHADOWTILE, DEFAULT_FORTRESS_TILEWIDTH,
  14.         DEFAULT_FORTRESS_TILEHEIGHT, DEFAULT_FORTRESS_SHADOWSCALE, DEFAULT_FORTRESS_SHADOW_Y_OFS, DEFAULT_FORTRESS_DEST_DMAP, DEFAULT_FORTRESS_DEST_SCREEN,
  15.         virtual_map_overworld_desert);
  16.     }
  17. }
  18.  
  19.  
  20. //Arrays
  21. int _____GRAM[1024]; //GLobal RAM
  22. const int LOOPS_Q = 1023;
  23.  
  24. //Fortresses array
  25. int Fortresses[256]; //tmer, dir, speed, x, y, dmap, screen
  26. //int FortressTimers[20];
  27.  
  28. //Fortress[] Array Indices and Offses
  29. const int FORTRESS_TIMER        = 0;
  30. const int FORTRESS_DIR          = 1;
  31. const int FORTRESS_SPEED        = 2;
  32. const int FORTRESS_X            = 3;
  33. const int FORTRESS_Y            = 4;
  34. const int FORTRESS_DMAP_ID      = 5;
  35. const int FORTRESS_SCREEN_ID        = 6;
  36. const int FORTRESS_TILE         = 7;
  37. const int FORTRESS_CSET         = 8;
  38. const int FORTRES_SCALE         = 9; //Scale it, blast you!
  39. const int FORTRESS_SHADOW_TILE      = 10;
  40. const int FORTRESS_SHADOW_      = 11; //More scaling effects, for perspective.
  41. const int FORTRESS_DEST_DMAP        = 12; //the dmap of the actual dungeon for this fortress
  42. const int FORTRESS_DEST_SCREEN      = 13; //the entrance screen of the actual dungeon for this fortress
  43. const int FORTRESS_TILEWIDTH        = 14;
  44. const int FORTRESS_TILEHEIGHT       = 15;
  45. const int FORTRESS_SHADOW_Y_OFS     = 16;
  46. const int FORTRESS_SHADOW_TILEHEIGHT    = 17;
  47. const int FORTRESS_SHADOW_TILEWIDTH     = 18;
  48. const int FORTRESS_SCALE        = 19;
  49. const int FORTRESS_SHADOW_X     = 20;
  50. const int FORTRESS_SHADOW_Y     = 21;
  51. const int FORTRESS_SHADOW_SCALE     = 22;
  52. const int FORTRESS_VIRTUAL_MAP      = 23;
  53.  
  54. const int FORTRESS_DMAP_OFFSET      = 20;  // Multiply this * Fortress ID, then add element.
  55.  
  56. //! Fortress Constants and Settings
  57.  
  58. //Base Fortress Constants
  59. const int NUM_FORTRESSES        = 9;
  60. const int NUM_WORLD_DMAPS       = 32;
  61. const int FORTRESS_1_TILE       = 100; //Replaced by array value,
  62. //sconst int FORTRESS_SHADOW_TILE       = 101; //Replaced by array value,
  63. const int FORTRESS_SHADOW_Y_OFFSET  = 70;  //Replaced by array value,
  64. const int FORTRESS_DRAW_LAYER       = 6;
  65. const int FORTRESS_SHADOW_DRAW_LAYER    = 6;
  66. //const int FORTRESS_TILEWIDTH  = 1;  Now by array
  67. //const int FORTRESS_TILEHEIGHT     = 1;  Now by array
  68. const int FORTRESS_WIDTH        = 8;  //Sprite dimensions. Unused?
  69. const int FORTRESS_HEIGHT       = 8;  //Unused?
  70. const int FORTRESS_Z_LOCATION       = 100; //must match this Z to enter.
  71. const int FORTRESS_SHADOW_CSET      = 0;
  72.  
  73. //Warps
  74. const int FORTRESS_EXIT_SIDEWARP    = 0; //Default SideWarp ID.,
  75. const int FORTRESS_EXIT_SIDEWARP_TYPE   = 0; //Fadeout warp here?
  76. const int FORTRESS_ENTRANCE_TILEWARP    = 3; //Tile Warp D is reserved for this.
  77. const int FORTRESS_ENTRANCE_TILEWARP_TYPE = 0; //Fadeout?
  78. const int FORTRESS_TILEWARP_COMBO    = 0; //Should be an insta-warp D type.
  79.  
  80. //FFC Values
  81. const int FORTRESS_FFC_SLOT         = 30; //When on-screen, the ffc will use this slot.
  82. const int FORTRESS_FFC_DEFDATA      = 1; //The combo (invisible) used by the ffc
  83.  
  84. //Movment and Turn Timer
  85. const int FORTRESS_MOVE_TMER_MIN    = 120;
  86. const int FORTRESS_MOVE_TMER_MAX    = 400;
  87. const int FORTRESS_MOVE_DIST_MIN    = 6;
  88. const int FORTRESS_MOVE_DIST_MAX    = 14;
  89.  
  90.  
  91.  
  92. const int FORTRESS_TIME_MIN         = 0; //minutes
  93. const int FORTRESS_TIME_MAX         = 3; //minutes
  94. const int FORTRESS_TIME_FRACTIONAL_MIN  = 10; //seconds
  95. const int FORTRESS_TIME_FRACTIONAL_MAX  = 59; //seconds
  96.    
  97.  
  98. //Link Misc[]
  99. const int LINK_FLAGS    = 15; //Link->Misc, 17 bits
  100.  
  101. //Temporary constants for each bit.
  102. const int LINKF_00  = 00000000000000001b;
  103. const int LINKF_01  = 00000000000000010b;
  104. const int LINKF_02  = 00000000000000100b;
  105. const int LINKF_03  = 00000000000001000b;
  106. const int LINKF_04  = 00000000000010000b;
  107. const int LINKF_05  = 00000000000100000b;
  108. const int LINKF_06  = 00000000001000000b;
  109. const int LINKF_07  = 00000000010000000b;
  110. const int LINKF_08  = 00000000100000000b;
  111. const int LINKF_09  = 00000001000000000b;
  112. const int LINKF_10  = 00000010000000000b;
  113. const int LINKF_11  = 00000100000000000b;
  114. const int LINKF_12  = 00001000000000000b;
  115. const int LINKF_13  = 00010000000000000b;
  116. const int LINKF_14  = 00100000000000000b;
  117. const int LINKF_LEAVING_FORTRESS    = 01000000000000000b;
  118. const int LINKF_FORTRESS_Z  = 10000000000000000b;
  119.  
  120. const int LINK_MISC_CURFORTRESS = 14;  //Current Fortress ID. Stored for use when shifting to or from a fortress.
  121.  
  122.  
  123. //Fortress FFC Settings
  124.  
  125. const int DEFAULT_FORTRESS_TILE = 65303;
  126. const int DEFAULT_FORTRESS_X = 30;
  127. const int DEFAULT_FORTRESS_Y = 20;
  128. const int DEFAULT_FORTRESS_DMAP = 0;
  129. const int DEFAULT_FORTRESS_SCREEN = 0x14;
  130. const int DEFAULT_FORTRESS_DIR = 0;
  131. const float DEFAULT_FORTRESS_SPEED = 0.002;
  132. const float DEFAULT_FORTRESS_TIME = 0.50;
  133. const int DEFAULT_FORTRESS_TILEWIDTH = 1;
  134. const int DEFAULT_FORTRESS_TILEHEIGHT = 1;
  135. const int DEFAULT_FORTRESS_SCALE = 30;
  136. const int DEFAULT_FORTRESS_CSET = 0;
  137. const int DEFAULT_FORTRESS_SHADOWTILE = 65304;
  138. const int DEFAULT_FORTRESS_SHADOW_TILEWIDTH = 1;
  139. const int DEFAULT_FORTRESS_SHADOW_TILEHEIGHT = 1;
  140. const int DEFAULT_FORTRESS_SHADOW_SCALE = 1;
  141. const int DEFAULT_FORTRESS_SHADOWSCALE = 18;
  142. const int DEFAULT_FORTRESS_SHADOW_Y_OFS = 30;
  143. const int DEFAULT_FORTRESS_DEST_DMAP = 1;
  144. const int DEFAULT_FORTRESS_DEST_SCREEN = 0x71;
  145.  
  146. /// VIRTUAL MAPS AND DMAPS ///
  147. //! Let's hardcode some DMAPS! Z
  148.  
  149. const int FF_DMAP_SCREEN_VALID = 0;
  150. const int FF_DMAP_SCREEN_INVALID = -1;
  151. const int FF_DMAP_SCREEN_BOUNDARY = 1; //1 or higher is a screen boundary.
  152.  
  153. //A virtual DMap. 0s are empty space, 1s are screens, 2s are boundaries.
  154. //Should each edge and corner be a unique value
  155.  
  156.  
  157. //-1 empty space
  158. //0 has sceens on each side
  159.  
  160. //1 cannot turn up
  161. //2 cannot turn down
  162. //4 cannot turn right
  163. //8 cannot turn up
  164.  
  165.  
  166.  
  167.  
  168. //DMap and Screen Boundaries
  169. const int NOT_VALID_SCREEN = -1;
  170. const int CANNOT_TURN_UP = 1;
  171. const int CANNOT_TURN_DOWN = 2;
  172. const int CANNOT_TURN_RIGHT = 4;
  173. const int CANNOT_TURN_LEFT = 8;
  174.  
  175. //Virtual Map Wrap Entry Point Offsets
  176. const int VM_WRAP_UP = 128;
  177. const int VM_WRAP_DOWN = 256;
  178. const int VM_WRAP_LEFT = 384;
  179. const int VM_WRAP_RIGHT = 512;
  180.  
  181.  
  182. //map 106, dmap  getcurdmap
  183. int virtual_map_overworld_desert[]={
  184.    
  185.     // Illegal Turns
  186.     9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
  187.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  188.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  189.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  190.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  191.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  192.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  193.     10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,
  194.    
  195.     //Wraps
  196.     //! These wrap from the screen at [index] to the specified screen for each given direction.
  197.     //! Needed for non-16x8 DMaps
  198.    
  199.     //!! We can handle WORLD WRAPPING in the same manner, by storing an U/D/L/R grid for each DMap as
  200.     //!! four arrays.
  201.    
  202.     //Wrap Screen Up
  203.    
  204.     0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
  205.     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  206.     0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  207.     0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  208.     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  209.     0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  210.     0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  211.     0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  212.    
  213.     //Wrap screen down
  214.    
  215.     0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  216.     0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  217.     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  218.     0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  219.     0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  220.     0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  221.     0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
  222.     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  223.    
  224.     //Wrap Screen left
  225.    
  226.     0x0F,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
  227.     0x1F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,
  228.     0x2F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,
  229.     0x3F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,
  230.     0x4F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,
  231.     0x5F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,
  232.     0x6F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,
  233.     0x7F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,
  234.    
  235.     //Wrap screen right
  236.    
  237.     0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x00,
  238.     0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x10,
  239.     0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x20,
  240.     0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x30,
  241.     0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x40,
  242.     0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x50,
  243.     0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x60,
  244.     0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x70,
  245.  
  246.     0,0,0,0};
  247.    
  248. //This array should hold the overworld layout for crossing dmap boundaries.
  249. int virtual_dmaps[]={
  250.    
  251.     //The world layout
  252.    
  253.     //DMap IDs as they actually connect
  254.     000, 001, 002, 003, 004, 005, 006, 007,
  255.     008, 009, 010, 011, 012, 013, 014, 015,
  256.     016, 017, 018, 019, 020, 021, 022, 023,
  257.     024, 025, 026, 027, 028, 029, 030, 031,
  258.    
  259.     //Wrap Up
  260.     024, 025, 026, 027, 028, 029, 030, 031,
  261.     000, 001, 002, 003, 004, 005, 006, 007,
  262.     008, 009, 010, 011, 012, 013, 014, 015,
  263.     016, 017, 018, 019, 020, 021, 022, 023,
  264.    
  265.    
  266.     //Wrap Down
  267.     008, 009, 010, 011, 012, 013, 014, 015,
  268.     016, 017, 018, 019, 020, 021, 022, 023,
  269.     024, 025, 026, 027, 028, 029, 030, 031,
  270.     000, 001, 002, 003, 004, 005, 006, 007,
  271.    
  272.     //Wrap Left
  273.     007, 000, 001, 002, 003, 004, 005, 006,  
  274.     015, 008, 009, 010, 011, 012, 013, 014,
  275.     023, 016, 017, 018, 019, 020, 021, 022,
  276.     031, 024, 025, 026, 027, 028, 029, 030,
  277.    
  278.     //Wrap Right
  279.     001, 002, 003, 004, 005, 006, 007, 000,
  280.     009, 010, 011, 012, 013, 014, 015, 008,
  281.     017, 018, 019, 020, 021, 022, 023, 016,
  282.     025, 026, 027, 028, 029, 030, 031, 024,
  283.    
  284.     0,0,0,0};
  285.    
  286.  
  287. //! Accessors for Fortresses[]
  288. //Getters
  289. int FortressX(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X]<<0); } //Truncated
  290. int FortressY(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y]<<0); } //Truncated
  291. int FortressDir(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR]; }
  292. int FortressSpeed(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED]; }
  293. int FortressDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID]; }
  294. int FortressScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID]; }
  295. int FortressTimer(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
  296. int FortressTile(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE]; }
  297. int FortressCSet(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET]; }
  298. int FortresScale(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE]; }
  299. int FortressShadowTile(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE]; }
  300. int FortresaShadowScale(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE]; }
  301. int FortressDestDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_DMAP]; }
  302. int FortressDestScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_SCREEN]; }
  303. int FortressTileHeight(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEHEIGHT]; }
  304. int FortressTileWidth(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEWIDTH];; }
  305. int FortressShadowYOffset(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y_OFS]; }
  306. int FortressShadowTileWidth(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEWIDTH]; }
  307. int FortressShadowTileHeight(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEHEIGHT]; }
  308. int FortressVirtualMap(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_VIRTUAL_MAP];; }
  309.  
  310. //Setters
  311. void FortressX(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X] = VBound(v,0,255); }
  312. void FortressY(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  313. void FortressDir(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR] = VBound(v,0,7); }
  314. void FortressSpeed(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED] = Abs(v); }
  315. void FortressDMap(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID] = v; }
  316. void FortressScreen(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID] = VBound(v,0,255); }
  317. void FortressTimer(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = Abs(v); }
  318. //void FortressY(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  319. void FortressTile(int fort_id, int tile){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE] = tile; }
  320. void FortressCSet(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET] = v; }
  321. void FortressScale(int fort_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE] = scale; }
  322. void FortressShadowTile(int fort_id, int tile) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE] = tile; }
  323. void FortressShadowScale(int fort_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE] = scale; }
  324. void FortressDestScreen(int fort_id, int s){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_SCREEN] = s; }
  325. void FortressDestDMap(int fort_id, int s){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_DMAP] = s; }
  326. void FortressTileHeight(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEHEIGHT] = VBound(v,1,4); }
  327. void FortressTileWidth(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEWIDTH] = VBound(v,1,4); }
  328. void FortressShadowYOffset(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y_OFS] =  v; }
  329. void FortressShadowTileWidth(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEWIDTH] = VBound(v,1,4); }
  330. void FortressShadowTileHeight(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEHEIGHT] = VBound(v,1,4); }
  331. void FortressVirtualMap(int fort_id, int virtual_map_ptr) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_VIRTUAL_MAP] = virtual_map_ptr; }
  332.  
  333. int FortressShadowY(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y]; }
  334. void FortressShadowY(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y] = v; }
  335.    
  336. //int FortressTimer(int id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
  337. //void FortressTimer(int id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = v; }
  338.  
  339. int FortressScale(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE]; }
  340.    
  341. int FortressShadowScale(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE]; }
  342.  
  343.  
  344. //Returns the logical dmap onto which we wrap.
  345.     //!Does NOT give the screen on that DMap.
  346.     //!We need a second function for /that/
  347. int GetWrapDMap(int virtual_map, int dmap, int dir, int dmap_max){
  348.     int pos;
  349.     for ( pos = 0; pos < dmap_max; pos++ ) {
  350.         if ( virtual_map[pos] == dmap ) {
  351.             if ( dir == DIR_UP ) return ( virtual_map[ ( NUM_WORLD_DMAPS ) + pos] );
  352.             if ( dir == DIR_DOWN ) return ( virtual_map[ ( NUM_WORLD_DMAPS*2 ) + pos] );
  353.             if ( dir == DIR_LEFT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*3 ) + pos] );
  354.             if ( dir == DIR_RIGHT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*4 ) + pos] );
  355.             return 1; //invalid directiom
  356.         }
  357.     }
  358.     return -1; //no match
  359. }
  360.  
  361.  
  362.  
  363.  
  364. //!Link Flag Functions
  365. void SetLinkFlag(int flag, bool state){
  366.     if(state) Link->Misc[LINK_FLAGS] |= flag;
  367.     else Link->Misc[LINK_FLAGS] &= ~flag;
  368. }
  369.  
  370. bool GetLinkFlag(int flag){
  371.     return (Link->Misc[LINK_FLAGS]&flag) != 0;
  372. }
  373.  
  374. //Determines or sets of Link can enter the fortress because he has a sufficient fake Z, by whatever mechanism gives him that fake Z value.
  375. bool LinkFortressZ(){ return (Link->Misc[LINK_FLAGS]&LINKF_FORTRESS_Z) != 0; }
  376. void LinkFortressZ(bool z){ if (z) Link->Misc[LINK_FLAGS] |= LINKF_FORTRESS_Z; else Link->Misc[LINK_FLAGS] &= ~LINKF_FORTRESS_Z; }
  377.  
  378. //Call globally to adust Link's X and Y when leaving the fortress.
  379. void LeavingFortress(){
  380.     //Set Link invisible and fix his coordinates,
  381.     if ( GetLinkFlag(LINKF_LEAVING_FORTRESS) && Game->GetCurScreen() == FortressScreen(Link->Misc[LINK_MISC_CURFORTRESS])
  382.         && Game->GetCurDMap() == FortressDMap(Link->Misc[LINK_MISC_CURFORTRESS]) ) {
  383.             Link->Invisible = true;
  384.             Link->X = FortressX(Link->Misc[LINK_MISC_CURFORTRESS]);
  385.             Link->Y = FortressShadowY(Link->Misc[LINK_MISC_CURFORTRESS]);
  386.             SetLinkFlag(LINKF_LEAVING_FORTRESS,false);         
  387.     }
  388.     else Link->Invisible = false;
  389. }
  390.  
  391.  
  392. //!! Fortress Functions
  393.  
  394.  
  395. //Call in Init, per fortress ID to set the attributes of each fortress.
  396. void SetFortressInitialAttributes
  397. (   int id, int x, int y, int dmap, int screen, int dir, float speed, float time, int tile,
  398.     int tilewidth, int tileheight, int scale, int cset, int shadowtile, int shadow_tilewidth,
  399.     int shadow_tileheight, int shadowscale, int shadow_y_offset,
  400.     int dest_dmap, int dest_screen, int virtual_map_ptr
  401. ){
  402.     FortressX(id, x); FortressY(id,y);
  403.     if ( dir == -1 ) FortressDir(id, Rand(0,3)); else FortressDir(dir);
  404.     if ( speed == -1 ) FortressTimer(id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX));
  405.         else FortressTimer(id, time);
  406.     FortressDMap(id, dmap);
  407.     FortressScreen(id, screen);
  408.     FortressTile(id, tile); FortressTileWidth(id, tilewidth); FortressTileHeight(id, tileheight);
  409.     FortressScale(id, scale);
  410.     FortressShadowTile(id, shadowtile); FortressShadowScale(id, shadowscale); FortressShadowYOffset(id, shadow_y_offset);
  411.     FortressShadowTileWidth(id, shadow_tilewidth); FortressShadowTileHeight(id, shadow_tileheight);
  412.     FortressCSet(id, cset);
  413.     FortressDestDMap(id, dest_dmap); FortressDestScreen(id, dest_screen);
  414.     FortressVirtualMap(id, virtual_map_ptr);
  415.    
  416. }
  417.    
  418.  
  419. //Main fortress function. Call once per fortress, pointing to its id and the virtual map that it uses.
  420. void DoFortress(int fortress_id) { //, int virtual_map){
  421.     int virtual_map = fortress_virtual_map_IDs[fortress_id]; //get the virtual map ID.
  422.     DoFortressTimers(fortress_id);
  423.     MoveFortress(fortress_id, virtual_map); //Moves the fortress every frame, and chanhges its direction fi it cannot move.
  424.     //UpdateFortressScreen(fortress_id); //If the fortress moves off-screen, wrap it to the next one.
  425.     DrawFortress(fortress_id);
  426. }
  427.  
  428. //Draws the fortress. Called by DoFortress()
  429. void DrawFortress(int fortress_id){
  430.     //if it is on this dmap
  431.     if ( FortressDMap(fortress_id) == Game->GetCurDMap() ) {
  432.         //...and this screen
  433.         if ( FortressScreen(fortress_id) == Game->GetCurScreen() ) {
  434.             //Draw it
  435.             Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id),
  436.             FortressTileWidth(fortress_id), FortressTileHeight(fortress_id), FortressCSet(fortress_id), FortressScale(fortress_id), FortressScale(fortress_id),
  437.             0, 0, 0, 0, true, OP_OPAQUE);
  438.             //Draw its shadow.
  439.            
  440.             Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressShadowTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id)+FORTRESS_SHADOW_Y_OFFSET,
  441.             FortressShadowTileWidth(fortress_id), FortressShadowTileHeight(fortress_id), FORTRESS_SHADOW_CSET, FortressShadowScale(fortress_id), FortressShadowScale(fortress_id),
  442.             0, 0, 0, 0, true, OP_OPAQUE);
  443.         }
  444.         DoFortressFFC(fortress_id); //Run the ffc that handles warping Link.
  445.     }
  446. } //!!z Now uses accessors and the array for almost every attribute.
  447.  
  448. //Determines if the fortress, moving where it wishes, is legal.
  449. bool FortressCanMove(int fortress_id, int virtual_map){
  450.     int dir = FortressDir(fortress_id);
  451.     int scr = FortressScreen(fortress_id);
  452.     //If the fortress is on a screen edge, check if that is a dmap edge, too.
  453.     if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id) )){
  454.         if ( dir == DIR_LEFT ) {
  455.             if ( virtual_map[scr] >= 8 ) return false;
  456.             return true;
  457.         }
  458.         if ( dir == DIR_RIGHT ){
  459.             if ( virtual_map[scr] >= 4 &&  virtual_map[scr] <= 6 ) return false;
  460.             return true;
  461.         }
  462.         if ( dir == DIR_DOWN ) {
  463.             if ( virtual_map[scr] == 10 || virtual_map[scr] == 2 || virtual_map[scr] == 6 ) return false;
  464.             return true;
  465.         }
  466.         if ( dir == DIR_UP ) {
  467.             if ( virtual_map[scr] == 9 || virtual_map[scr] == 1 || virtual_map[scr] == 5 ) return false;
  468.             return true;
  469.         }
  470.     }
  471.     return true; //The fortress is not on a screen edge, so it can move freely.
  472. }
  473.  
  474. //Moves the fortress based on its speed, and changes its direction if it cannot move.
  475. void MoveFortress(int fortress_id, int virtual_map){
  476.     if ( FortressCanMove(fortress_id, virtual_map) ) {
  477.         if ( FortressDir(fortress_id) == DIR_LEFT ) {
  478.             //If it is on the edge of a screen
  479.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id))) {
  480.                 //Move it one screen to the left and reset its X
  481.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_LEFT) );
  482.                 FortressX(fortress_id,255);
  483.             }
  484.             //Move left
  485.             else FortressX(fortress_id, FortressX(fortress_id)-FortressSpeed(fortress_id));
  486.         }
  487.         if ( FortressDir(fortress_id) == DIR_RIGHT ) {
  488.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id))) {
  489.                 //Move it one screen to the right and reset its X
  490.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_RIGHT));
  491.                 FortressX(fortress_id,0);
  492.             }
  493.             //Move right
  494.             else FortressX(fortress_id, FortressX(fortress_id)+FortressSpeed(fortress_id));
  495.         }
  496.         if ( FortressDir(fortress_id) == DIR_UP ) {
  497.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id))) {
  498.                 //Move it one screen up and reset its Y
  499.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_UP));
  500.                 FortressY(fortress_id,175);  
  501.             }
  502.             //Move up
  503.             FortressY(fortress_id, FortressY(fortress_id)-FortressSpeed(fortress_id));
  504.         }
  505.         if ( FortressDir(fortress_id) == DIR_DOWN ) {
  506.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id))) {
  507.                 //Move it one screen down and reset its Y
  508.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_DOWN));
  509.                 FortressY(fortress_id,0);
  510.             }
  511.             //Move down
  512.             FortressY(fortress_id, FortressY(fortress_id)+FortressSpeed(fortress_id));
  513.         }
  514.     }
  515.     else {
  516.         //Change the direction.
  517.         FortressDir( fortress_id, FindLegalTurn(fortress_id, virtual_map) );
  518.     }
  519. }
  520.  
  521. //Handles turn timers.
  522. void DoFortressTimers(int fortress_id){
  523.     if ( FortressTimer(fortress_id) <= 0 ) {
  524.         TurnFortress(fortress_id);
  525.     }
  526.     else {
  527.         FortressTimer(fortress_id, FortressTimer(fortress_id)-1); //Reduce the timer.
  528.     }
  529. }
  530.  
  531. //Returns if the fortress is on the edge of a screen based on its direction.
  532. bool FortressAtScreenEdge(int fortress_id, int dir){
  533.     if ( dir == DIR_LEFT && FortressX(fortress_id) <= 0+FORTRESS_WIDTH ) return true;
  534.     if ( dir == DIR_RIGHT && FortressX(fortress_id) >= 256 ) return true;
  535.     if ( dir == DIR_UP && FortressY(fortress_id)+FORTRESS_HEIGHT < 0 ) return true;
  536.     if ( dir == DIR_DOWN && FortressY(fortress_id) >= 176 ) return true;
  537.     return false;
  538. }
  539. //Turns the fortress if its timer expires.
  540. bool TurnFortress(int fortress_id) {
  541.     //Choose a direction other than the present diretion.
  542.     int dir;
  543.     do { //Pick a random direction that differs from this direction.
  544.         dir = Rand(0,7);
  545.     } while ( dir != FortressDir(fortress_id) );
  546.     FortressDir(fortress_id, dir); //Change the direction.
  547.     //Reset the turn timer to a randomised value. .
  548.     FortressTimer(fortress_id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX) );
  549. }
  550.    
  551.  
  552. //Set the turn timer.
  553. int FortressTime(int time_min, int time_max, int frac_time, int frac_max){
  554.     int t = Rand(time_min,time_max); int tt = (Rand(frac_time, frac_max) / 60);
  555.     return (t+tt)*60;
  556. }
  557.  
  558.  
  559.  
  560. //Called from the global if the fortress is on-screen, via DrawFortress()
  561. void DoFortressFFC(int fortress_id){
  562.     ffc f = Screen->LoadFFC(FORTRESS_FFC_SLOT);
  563.     int ff[]="FortressFFC";
  564.     int fff = Game->GetFFCScript(ff);
  565.     if ( f->Script != fff ) {
  566.         f->Data = FORTRESS_FFC_DEFDATA;
  567.         f->InitD[0] = FortressDestDMap(fortress_id);
  568.         f->InitD[1] = FortressDestScreen(fortress_id);
  569.         f->Script = fff;
  570.     }
  571. }
  572.  
  573.  
  574. //Returns the correct screen for wrapping x.y coordinates off a given screen for a virtual map.
  575. int GetWrapScreen(int virtual_map, int screen, int dir){
  576.     if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UP]; }
  577.     if ( dir == DIR_DOWN ) { return virtual_map[screen+VM_WRAP_DOWN]; }
  578.     if ( dir == DIR_LEFT ) { return virtual_map[screen+VM_WRAP_LEFT]; }
  579.     if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UP]; }
  580.     return -1; //Invalid direction.
  581. }
  582.  
  583. //Determines a random, legal directions, based on values on a vritual map.
  584. int FindLegalTurn(int virtual_map, int screen){
  585.     if ( virtual_map[screen] == 1 ) {  //cannot turn up
  586.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_DOWN) );
  587.     }
  588.     if ( virtual_map[screen] == 2 ) { //cannot tuen down
  589.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_UP) );
  590.     }
  591.     if ( virtual_map[screen] == 4 ) { //cannot turn right
  592.         return ( Choose(DIR_LEFT, DIR_DOWN, DIR_UP) );
  593.     }
  594.     if ( virtual_map[screen] == 5 ) { //cannot turn up or right
  595.         return ( Choose(DIR_DOWN, DIR_LEFT) );
  596.     }
  597.     if ( virtual_map[screen] == 6 ) { //cannot turn down or right
  598.         return ( Choose(DIR_UP, DIR_LEFT) );
  599.     }
  600.     if ( virtual_map[screen] == 8 ) { //cannot turn left
  601.         return ( Choose(DIR_RIGHT, DIR_DOWN, DIR_UP) );
  602.     }
  603.     if ( virtual_map[screen] == 9 ) { //cannot turn left or up
  604.         return ( Choose(DIR_RIGHT, DIR_DOWN) );
  605.     }
  606.     if ( virtual_map[screen] == 10 ) { //cannot turn left or down
  607.         return ( Choose(DIR_RIGHT, DIR_UP) );
  608.     }
  609.     return Rand(0,3); //Otherwise, return a random direction.
  610. }
  611.  
  612.  
  613.  
  614.  
  615. //! FFC Scripts
  616. ffc script FortressExit{
  617.     void run(int fortress_id){
  618.         while(true){
  619.             if ( Collision(this) ) {
  620.                 SetLinkFlag(LINKF_LEAVING_FORTRESS,true); //mark Link Leaving fortress
  621.                
  622.                 Screen->SetSideWarp(FORTRESS_EXIT_SIDEWARP, FortressScreen(fortress_id), FortressDMap(fortress_id), FORTRESS_EXIT_SIDEWARP_TYPE);
  623.             }
  624.             Waitframe();
  625.         }
  626.     }
  627. }
  628.  
  629. ffc script FortressFFC{
  630.     void run(int fortress_id, int warp_to_dmap, int warp_to_screen){
  631.         while(true){
  632.             if ( FortressScreen(fortress_id) != Game->GetCurScreen() ) Quit(); //If the fortress moves off-screen, quit.
  633.             if ( LinkFortressZ() && Collision(this) ) { //If collision with this and Link has the fake Z needed...
  634.                 //Set the tilewarp and change this ffc's data to a warp type.
  635.                 Screen->SetTileWarp(FORTRESS_ENTRANCE_TILEWARP, warp_to_screen, warp_to_dmap, FORTRESS_ENTRANCE_TILEWARP_TYPE);
  636.                 this->Data = FORTRESS_TILEWARP_COMBO;
  637.             }
  638.             Waitframe();
  639.         }
  640.     }
  641. }
  642.  
  643. int Q(){ return  _____GRAM[LOOPS_Q]; }
  644. void Q(int v){  _____GRAM[LOOPS_Q] = v; }
  645.  
  646. //Test Global Active Script
  647. global script test_fortress{
  648.     void run(){
  649.         while(true){
  650.             for ( _____GRAM[LOOPS_Q] = 0; _____GRAM[LOOPS_Q]  < 9; _____GRAM[LOOPS_Q]++ ) {
  651.                 DoFortress(Q());
  652.             }
  653.             Waitdraw();
  654.             Waitframe();
  655.         }
  656.     }
  657. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement