Advertisement
ZoriaRPG

ZScript: Flying Fortress Alpha 0.6

May 20th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 33.53 KB | None | 0 0
  1. //! We need a GetScreenDown and GetScreenUp function pair to go with the virtual maps.
  2.  
  3. //Arrays
  4. int _____GRAM[1024]; //GLobal RAM
  5. const int LOOPS_Q = 1023;
  6.  
  7. //Fortresses array
  8. int Fortresses[256]; //tmer, dir, speed, x, y, dmap, screen
  9.  
  10.  
  11. //Fortress[] Array Indices and Offses
  12. const int FORTRESS_TIMER        = 0;
  13. const int FORTRESS_DIR          = 1;
  14. const int FORTRESS_SPEED        = 2;
  15. const int FORTRESS_X            = 3;
  16. const int FORTRESS_Y            = 4;
  17. const int FORTRESS_DMAP_ID      = 5;
  18. const int FORTRESS_SCREEN_ID        = 6;
  19. const int FORTRESS_TILE         = 7;
  20. const int FORTRESS_CSET         = 8;
  21. const int FORTRES_SCALE         = 9; //Scale it, blast you!
  22. const int FORTRESS_SHADOW_TILE      = 10;
  23. const int FORTRESS_SHADOW_      = 11; //More scaling effects, for perspective.
  24. const int FORTRESS_DEST_DMAP        = 12; //the dmap of the actual dungeon for this fortress
  25. const int FORTRESS_DEST_SCREEN      = 13; //the entrance screen of the actual dungeon for this fortress
  26. const int FORTRESS_TILEWIDTH        = 14;
  27. const int FORTRESS_TILEHEIGHT       = 15;
  28. const int FORTRESS_SHADOW_Y_OFS     = 16;
  29. const int FORTRESS_SHADOW_TILEHEIGHT    = 17;
  30. const int FORTRESS_SHADOW_TILEWIDTH     = 18;
  31. const int FORTRESS_VIRTUAL_MAP      = 19;
  32.  
  33. const int FORTRESS_DMAP_OFFSET      = 20;  // Multiply this * Fortress ID, then add element.
  34.  
  35. //! Fortress Constants and Settings
  36.  
  37. //Base Fortress Constants
  38. const int NUM_FORTRESSES        = 9;
  39. const int NUM_WORLD_DMAPS       = 32;
  40. const int FORTRESS_1_TILE       = 100; //Replaced by array value,
  41. const int FORTRESS_SHADOW_TILE      = 101; //Replaced by array value,
  42. const int FORTRESS_SHADOW_Y_OFFSET  = 70;  //Replaced by array value,
  43. const int FORTRESS_DRAW_LAYER       = 6;
  44. const int FORTRESS_SHADOW_DRAW_LAYER    = 6;
  45. //const int FORTRESS_TILEWIDTH  = 1;  Now by array
  46. //const int FORTRESS_TILEHEIGHT     = 1;  Now by array
  47. const int FORTRESS_WIDTH        = 8;  //Sprite dimensions. Unused?
  48. const int FORTRESS_HEIGHT       = 8;  //Unused?
  49. const int FORTRESS_Z_LOCATION       = 100; //must match this Z to enter.
  50. const int FORTRESS_SHADOW_CSET      = 0;
  51.  
  52. //Warps
  53. const int FORTRESS_EXIT_SIDEWARP    = 0; //Default SideWarp ID.,
  54. const int FORTRESS_EXIT_SIDEWARP_TYPE   = 0; //Fadeout warp here?
  55. const int FORTRESS_ENTRANCE_TILEWARP    = 3; //Tile Warp D is reserved for this.
  56. const int FORTRESS_ENTRANCE_TILEWARP_TYPE = 0; //Fadeout?
  57. const int FORTRESS_TILEWARP_COMBO    = 0; //Should be an insta-warp D type.
  58.  
  59. //FFC Values
  60. const int FORTRESS_FFC_SLOT         = 30; //When on-screen, the ffc will use this slot.
  61. const int FORTRESS_FFC_DEFDATA      = 1; //The combo (invisible) used by the ffc
  62.  
  63. //Movment and Turn Timer
  64. const int FORTRESS_MOVE_TMER_MIN    = 120;
  65. const int FORTRESS_MOVE_TMER_MAX    = 400;
  66. const int FORTRESS_MOVE_DIST_MIN    = 6;
  67. const int FORTRESS_MOVE_DIST_MAX    = 14;
  68.  
  69.  
  70.  
  71. const int FORTRESS_TIME_MIN         = 0; //minutes
  72. const int FORTRESS_TIME_MAX         = 3; //minutes
  73. const int FORTRESS_TIME_FRACTIONAL_MIN  = 10; //seconds
  74. const int FORTRESS_TIME_FRACTIONAL_MAX  = 59; //seconds
  75.    
  76.  
  77. //Link Misc[]
  78. const int LINK_FLAGS    = 15; //Link->Misc, 17 bits
  79.  
  80. //Temporary constants for each bit.
  81. const int LINKF_00  = 00000000000000001;
  82. const int LINKF_01  = 00000000000000010;
  83. const int LINKF_02  = 00000000000000100;
  84. const int LINKF_03  = 00000000000001000;
  85. const int LINKF_04  = 00000000000010000;
  86. const int LINKF_05  = 00000000000100000;
  87. const int LINKF_06  = 00000000001000000;
  88. const int LINKF_07  = 00000000010000000;
  89. const int LINKF_08  = 00000000100000000;
  90. const int LINKF_09  = 00000001000000000;
  91. const int LINKF_10  = 00000010000000000;
  92. const int LINKF_11  = 00000100000000000;
  93. const int LINKF_12  = 00001000000000000;
  94. const int LINKF_13  = 00010000000000000;
  95. const int LINKF_14  = 00100000000000000;
  96. const int LINKF_LEAVING_FORTRESS    = 01000000000000000;
  97. const int LINKF_FORTRESS_Z  = 10000000000000000;
  98.  
  99. const int LINK_MISC_CURFORTRESS = 14;  //Current Fortress ID. Stored for use when shifting to or from a fortress.
  100.  
  101.  
  102. //! Accessors for Fortresses[]
  103. //Getters
  104. int FortressX(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X]<<0); } //Truncated
  105. int FortressY(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y]<<0); } //Truncated
  106. int FortressDir(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR]; }
  107. int FortressSpeed(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED]; }
  108. int FortressDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID]; }
  109. int FortressScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID]; }
  110. int FortressTimer(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
  111. int FortressTile(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE]; }
  112. int FortressCSet(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET]; }
  113. int FortresScale(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE]; }
  114. int FortressShadowTile(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE]; }
  115. int FortresaShadowScale(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE]; }
  116. int FortressDestDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_DMAP]; }
  117. int FortressDestScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_SCREEN]; }
  118. int FortressTileHeight(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEHEIGHT]; }
  119. int FortressTileWidth(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEWIDTH];; }
  120. int FortressShadowYOffset(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y_OFS]; }
  121. int FortressShadowTileWidth(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEWIDTH]; }
  122. int FortressShadowTileHeight(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEHEIGHT]; }
  123. int FortressVirtualMap(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_VIRTUAL_MAP];; }
  124.  
  125. //Setters
  126. void FortressX(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X] = VBound(v,0,255); }
  127. void FortressY(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  128. void FortressDir(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR] = VBound(v,0,7); }
  129. void FortressSpeed(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED] = Abs(v); }
  130. void FortressDMap(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID] = v; }
  131. void FortressScreen(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID] = VBound(v,0,255); }
  132. void FortressTimer(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = Abs(v); }
  133. void FortressY(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  134. void FortressTile(int fort_id, int tile){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE] = tile; }
  135. void FortressCSet(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET] = v; }
  136. void FortressScale(int fort_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE] = scale; }
  137. void FortressShadowTile(int fort_id, int tile) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE] = tile; }
  138. void FortressShadowScale(int fort_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE] = scale; }
  139. void FortressDestScreen(int fort_id, int s){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_SCREEN] = s; }
  140. void FortressDestDMap(int fort_id, int s){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_DMAP] = s; }
  141. void FortressTileHeight(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEHEIGHT] = VBound(v,1,4); }
  142. void FortressTileWidth(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEWIDTH] = VBound(v,1,4); }
  143. void FortressShadowYOffset(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y_OFS] =  v; }
  144. void FortressShadowTileWidth(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEWIDTH] = VBound(v,1,4); }
  145. void FortressShadowTileHeight(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEHEIGHT] = VBound(v,1,4); }
  146. void FortressVirtualMap(int fort_id, int virtual_map_ptr) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_VIRTUAL_MAP] = virtual_map_ptr; }
  147.  
  148.  
  149. //!Link Flag Functions
  150. void SetLinkFlag(int flag, bool state){
  151.     if(state) Link->Misc[LINK_FLAGS] |= flag;
  152.     else Link->Misc[LINK_FLAGS] &= ~flag;
  153. }
  154.  
  155. bool GetLinkFlag(int flag){
  156.     return (Link->Misc[LINK_FLAGS]&flag) != 0;
  157. }
  158.  
  159. //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.
  160. bool LinkFortressZ(){ return (Link->Misc[LINK_FLAGS]&LINKF_FORTRESS_Z) != 0; }
  161. void LinkFortressZ(bool z){ if (z) Link->Misc[LINK_FLAGS] |= LINKF_FORTRESS_Z; else Link->Misc[LINK_FLAGS] &= ~LINKF_FORTRESS_Z; }
  162.  
  163. //Call globally to adust Link's X and Y when leaving the fortress.
  164. void LeavingFortress(){
  165.     //Set Link invisible and fix his coordinates,
  166.     if ( GetLinkFlag(LINK_LEAVING_FORTRESS) && Game->GetCurScreen() == FortressScreen(Link->Misc[LINK_MISC_CURFORTRESS])
  167.         && Game->GetCurDMap() == FortressDMap(Link->Misc[LINK_MISC_CURFORTRESS]) ) {
  168.             Link->Invisible = true;
  169.             Link->X = FortressX(Link->Misc[LINK_MISC_CURFORTRESS]);
  170.             Link->Y = FortressShadowY(Link->Misc[LINK_MISC_CURFORTRESS]));
  171.             SetLinkFLag(LINK_LEAVING_FORTRESS,false);          
  172.     }
  173.     else Link->Invisible = false;
  174. }
  175.  
  176.  
  177. //!! Fortress Functions
  178.  
  179.  
  180. //Call in Init, per fortress ID to set the attributes of each fortress.
  181. void SetFortressInitialAttributes
  182. (   int id, int x, int y, int dmap, int screen, int dir, float speed, float time, int tile,
  183.     int tilewidth, int tileheight, int scale, int cset, int shadowtile, int shadow_tilewidth,
  184.     int shadow_tileheight, int shadowscale, int shadow_y_offset,
  185.     int dest_dmap, int dest_screen, int virtual_map_ptr
  186. ){
  187.     FortressX(id, x); FortressY(id,y);
  188.     if ( dir == -1 ) FortressDir(id, Rand(0,3); else FortressDir(dir);
  189.     if ( speed == -1 ) FortresssTimer(id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX));
  190.         else FortresssTimer(id, time);
  191.     FortressDMap(id, dmap);
  192.     FortressScreen(id, screen);
  193.     FortressTile(id, tile); FortressTileWidth(id, tilewidth); FortressTileHeight(id, tileheight);
  194.     FortressScale(id, scale);
  195.     FortressShadowTile(id, shadowtile); FortressShadowScale(id, shadowscale); FortressShadowYOffset(id, shadow_y_offset);
  196.     FortressShadowTileWidth(id, shadow_tilewidth); FortressShadowTileHeight(id, shadow_tileheight);
  197.     FortressCSet(id, cset);
  198.     FortressDestDMap(id, dest_dmap); FortressDestScreen(id, dest_screen);
  199.     FortressVirtualMap(id, virtual_map_ptr);
  200.    
  201. }
  202.    
  203.  
  204.  
  205. //Main fortress function. Call once per fortress, pointing to its id and the virtual map that it uses.
  206. void DoFortress(int fortress_id, int virtual_map){
  207.     DoFortressTmers(fortress_id);
  208.     MoveFortress(fortress_id, virtual_map); //Moves the fortress every frame, and chanhges its direction fi it cannot move.
  209.     //UpdateFortressScreen(fortress_id); //If the fortress moves off-screen, wrap it to the next one.
  210.     DrawFortress(fortress_id);
  211. }
  212.  
  213. //Draws the fortress. Called by DoFortress()
  214. void DrawFortress(int fortress_id, int tile){
  215.     //if it is on this dmap
  216.     if ( FortressDMap(fortress_id) == Game->GetCurDMap() ) {
  217.         //...and this screen
  218.         if ( FortressScreen(fortress_id) == Game->GetCurScreen() ) {
  219.             //Draw it
  220.             Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id),
  221.             FortressTileWidth(fortress_id), FortressTileHeight(fortress_id), FortressCSet(fortress_id), FortressScale(fortress_id), FortressScale(fortress_id),
  222.             0, 0, 0, 0, true, OP_OPAQUE);
  223.             //Draw its shadow.
  224.            
  225.             Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressShadowTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id)+FORTRESS_SHADOW_Y_OFFSET,
  226.             FortressShadowTileWidth(fortress_id), FortressShadowTileHeight(fortress_id), FORTRESS_SHADOW_CSET, FortresShadowScale(fortress_id), FortresShadowScale(fortress_id),
  227.             0, 0, 0, 0, true, OP_OPAQUE);
  228.         }
  229.         DoFortressFFC(fortress_id); //Run the ffc that handles warping Link.
  230.     }
  231. } //!!z Now uses accessors and the array for almost every attribute.
  232.  
  233. //Determines if the fortress, moving where it wishes, is legal.
  234. bool FortressCanMove(int fortress_id, int virtual_map, int screen){
  235.     int dir = FortressDir(fortress_id);
  236.     int scr = FortressScreen(fortress_id);
  237.     //If the fortress is on a screen edge, check if that is a dmap edge, too.
  238.     if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id) ){
  239.         if ( dir == DIR_LEFT ) {
  240.             if ( virtual_map[scr] >= 8 ) return false;
  241.             return true;
  242.         }
  243.         if ( dir == DIR_RIGHT ){
  244.             if ( virtual_map[scr] >= 4 &&  virtual_map[scr] <= 6 ) return false;
  245.             return true;
  246.         }
  247.         if ( dir == DIR_DOWN ) {
  248.             if ( virtual_map[scr] == 10 || virtual_map[scr] == 2 || virtual_map[scr] == 6 ) return false;
  249.             return true;
  250.         }
  251.         if ( dir == DIR_UP ) {
  252.             if ( virtual_map[scr] == 9 || virtual_map[scr] == 1 || virtual_map[scr] == 5 ) return false;
  253.             return true;
  254.         }
  255.     }
  256.     return true; //The fortress is not on a screen edge, so it can move freely.
  257. }
  258.  
  259. //Moves the fortress based on its speed, and changes its direction if it cannot move.
  260. void MoveFortress(int fortress_id, int virtual_map){
  261.     if ( FortressCanMove(fortress_id) ) {
  262.         if ( FortressDir(fortress_id) == DIR_LEFT ) {
  263.             //If it is on the edge of a screen
  264.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  265.                 //Move it one screen to the left and reset its X
  266.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_LEFT) );
  267.                 FortressX(fortress_id,255);
  268.             }
  269.             //Move left
  270.             else FortressX(fortress_id, FortressX(fortress_id)-FortressSpeed(fortress_id));
  271.         }
  272.         if ( FortressDir(fortress_id) == DIR_RIGHT ) {
  273.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  274.                 //Move it one screen to the right and reset its X
  275.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_RIGHT));
  276.                 FortressX(fortress_id,0);
  277.             }
  278.             //Move right
  279.             else FortressX(fortress_id, FortressX(fortress_id)+FortressSpeed(fortress_id));
  280.         }
  281.         if ( FortressDir(fortress_id) == DIR_UP ) {
  282.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  283.                 //Move it one screen up and reset its Y
  284.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_UO));
  285.                 FortressY(fortress_id,175);  
  286.             }
  287.             //Move up
  288.             FortressY(fortress_id, FortressY(fortress_id)-FortressSpeed(fortress_id));
  289.         }
  290.         if ( FortressDir(fortress_id) == DIR_DOWN ) {
  291.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  292.                 //Move it one screen down and reset its Y
  293.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_DOWN));
  294.                 FortressY(fortress_id,0);
  295.             }
  296.             //Move down
  297.             FortressY(fortress_id, FortressY(fortress_id)+FortressSpeed(fortress_id));
  298.         }
  299.     }
  300.     else {
  301.         //Change the direction.
  302.         FortressDir( fortress_id, FindLegalTurn(fortress_id, virtual_map) );
  303.     }
  304. }
  305.  
  306. //Handles turn timers.
  307. void DoFortressTmers(int fortress_id){
  308.     if FortressTimer(fortress_id) <= 0 ) {
  309.         TurnFortress(fortress_id);
  310.     }
  311.     else {
  312.         FortressTime(fortress_id, FortressTime(fortress_id)-1); //Reduce the timer.
  313.     }
  314. }
  315.  
  316. //Returns if the fortress is on the edge of a screen based on its direction.
  317. bool FortressAtScreenEdge(int fortress_id, int dir){
  318.     if ( dir == DIR_LEFT && FottressX(fortress_id) <= 0+FORTRESS_WIDTH ) return true;
  319.     if ( dir == DIR_RIGHT && FortressX(fortress_id) >= 256 ) return true;
  320.     if ( dir == DIR_UP && FortressY(fortress_id)+FORTRESS_HEIGHT < 0 ) return true;
  321.     if ( dir == DIR_DOWN && FortrwessY(fortress_id) >= 176 ) return true;
  322.     return false;
  323. }
  324. //Turns the fortress if its timer expires.
  325. bool TurnFortress(int fortress_id) { {
  326.     //Choose a direction other than the present diretion.
  327.     int dir;
  328.     do { //Pick a random direction that differs from this direction.
  329.         dir = Rand(0,7);
  330.     } while ( dir != FortressDir(fortress_id);
  331.     FortressDir(fortress_id, dir); //Change the direction.
  332.     //Reset the turn timer to a randomised value. .
  333.     FortressTimer(fortress_id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX) );
  334. }
  335.    
  336.  
  337. //Set the turn timer.
  338. int FortressTime(int time_min, time_max, int frac_time, int frac_max){
  339.     int t = Rand(time_min,time_max); int tt = (Rand(frac_time, frac_max) / 60);
  340.     Return (t+tt)*60;
  341. }
  342.  
  343. //Called from the global if the fortress is on-screen, via DrawFortress()
  344. void DoFortressFFC(int fortress_id){
  345.     ffc f = Screen->LoadFFC(FORTRESS_FFC_SLOT);
  346.     int ff[]="FortressFFC";
  347.     int fff = Game->GetFFCScript(ff);
  348.     if ( f->Script != fff ) {
  349.         f->Data = FORTRESS_FFC_DEFDATA;
  350.         f->InitD[0] = FortressDestDMap(fortress_id);
  351.         f->InitD[1] = FortressDestScreen(fortress_id);
  352.         f->Script = fff;
  353.     }
  354. }
  355.  
  356.  
  357. //Returns the correct screen for wrapping x.y coordinates off a given screen for a virtual map.
  358. int GetWrapScreen(int virtual_map, int screen, int dir){
  359.     if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UP]; }
  360.     if ( dir == DIR_DOWN ) { return virtual_map[screen+VM_WRAP_DOWN]; }
  361.     if ( dir == DIR_LEFT ) { return virtual_map[screen+VM_WRAP_LEFT]; }
  362.     if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UO]; }
  363.     return -1; //Invalid direction.
  364. }
  365.  
  366. //Determines a random, legal directions, based on values on a vritual map.
  367. int FindLegalTurn(int virtual_map, int screen){
  368.     if ( virtual_map[screen] == 1 ) {  //cannot turn up
  369.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_DOWN) );
  370.     }
  371.     if ( virtual_map[screen] == 2 ) { //cannot tuen down
  372.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_UP) );
  373.     }
  374.     if ( virtual_map[screen] == 4 ) { //cannot turn right
  375.         return ( Choose(DIR_LEFT, DIR_DOWN, DIR_UP) );
  376.     }
  377.     if ( virtual_map[screen] == 5 ) { //cannot turn up or right
  378.         return ( Choose(DIR_DOWN, DIR_LEFT) );
  379.     }
  380.     if ( virtual_map[screen] == 6 ) { //cannot turn down or right
  381.         return ( Choose(DIR_UP, DIR_LEFT) );
  382.     }
  383.     if ( virtual_map[screen] == 8 ) { //cannot turn left
  384.         return ( Choose(DIR_RIGHT, DIR_DOWN, DIR_UP) );
  385.     }
  386.     if ( virtual_map[screen] == 9 ) { //cannot turn left or up
  387.         return ( Choose(DIR_RIGHT, DIR_DOWN) );
  388.     }
  389.     if ( virtual_map[screen] == 10 ) { //cannot turn left or down
  390.         return ( Choose(DIR_RIGHT, DIR_UP) );
  391.     }
  392.     return Rand(0,3); //Otherwise, return a random direction.
  393. }
  394.  
  395.  
  396. /// VIRTUAL MAPS AND DMAPS ///
  397. //! Let's hardcode some DMAPS! Z
  398.  
  399. const int FF_DMAP_SCREEN_VALID = 0;
  400. const int FF_DMAP_SCREEN_INVALID = -1;
  401. const int FF_DMAP_SCREEN_BOUNDARY = 1; //1 or higher is a screen boundary.
  402.  
  403. //A virtual DMap. 0s are empty space, 1s are screens, 2s are boundaries.
  404. //Should each edge and corner be a unique value
  405.  
  406. /*
  407. -1 empty space
  408. 0 has sceens on each side
  409.  
  410. 1 cannot turn up
  411. 2 cannot turn down
  412. 4 cannot turn right
  413. 8 cannot turn up
  414.  
  415.  
  416. */
  417.  
  418. //DMap and Screen Boundaries
  419. const int NOT_VALID_SCREEN = -1;
  420. const int CANNOT_TURN_UP = 1;
  421. const int CANNOT_TURN_DOWN = 2;
  422. const int CANNOT_TURN_RIGHT = 4;
  423. const int CANNOT_TURN_LEFT = 8;
  424.  
  425. //Virtual Map Wrap Entry Point Offsets
  426. const int VM_WRAP_UP = 128;
  427. const int VM_WRAP_DOWN = 256;
  428. const int VM_WRAP_LEFT = 384;
  429. const int VM_WRAP_RIGHT = 512;
  430.  
  431. //A virtual map with the edges marked.
  432. int virtual_map_1[]={
  433.    
  434.     // Illegal Turns
  435.     9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
  436.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  437.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  438.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  439.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  440.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  441.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  442.     10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,
  443.    
  444.     //Wraps
  445.     //! These wrap from the screen at [index] to the specified screen for each given direction.
  446.     //! Needed for non-16x8 DMaps
  447.    
  448.     //!! We can handle WORLD WRAPPING in the same manner, by storing an U/D/L/R grid for each DMap as
  449.     //!! four arrays.
  450.    
  451.     //Wrap Screen Up
  452.    
  453.     0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
  454.     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  455.     0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  456.     0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  457.     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  458.     0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  459.     0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  460.     0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  461.    
  462.     //Wrap screen down
  463.    
  464.     0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  465.     0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  466.     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  467.     0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  468.     0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  469.     0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  470.     0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
  471.     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  472.    
  473.     //Wrap Screen left
  474.    
  475.     0x0F,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
  476.     0x1F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,
  477.     0x2F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,
  478.     0x3F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,
  479.     0x4F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,
  480.     0x5F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,
  481.     0x6F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,
  482.     0x7F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,
  483.    
  484.     //Wrap screen right
  485.    
  486.     0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x00,
  487.     0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x10,
  488.     0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x20,
  489.     0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x30,
  490.     0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x40,
  491.     0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x50,
  492.     0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x60,
  493.     0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x70,
  494.  
  495.     0,0,0,0};
  496.    
  497. int virtual_dmaps[]={
  498.    
  499.     //The world layout
  500.    
  501.     //DMap IDs as they actually connect
  502.     000, 001, 002, 003m 004, 005, 006, 007,
  503.     008, 009, 010, 011, 012, 013, 014, 015,
  504.     016, 017, 018, 019, 020. 021, 022, 023,
  505.     024, 025, 026, 027, 028, 029, 030, 031,
  506.    
  507.     //Wrap Up
  508.     024, 025, 026, 027, 028, 029, 030, 031,
  509.     000, 001, 002, 003m 004, 005, 006, 007,
  510.     008, 009, 010, 011, 012, 013, 014, 015,
  511.     016, 017, 018, 019, 020. 021, 022, 023,
  512.    
  513.    
  514.     //Wrap Down
  515.     008, 009, 010, 011, 012, 013, 014, 015,
  516.     016, 017, 018, 019, 020. 021, 022, 023,
  517.     024, 025, 026, 027, 028, 029, 030, 031,
  518.     000, 001, 002, 003m 004, 005, 006, 007,
  519.    
  520.     //Wrap Left
  521.     007, 000, 001, 002, 003m 004, 005, 006,  
  522.     015, 008, 009, 010, 011, 012, 013, 014,
  523.     023, 016, 017, 018, 019, 020. 021, 022,
  524.     031, 024, 025, 026, 027, 028, 029, 030,
  525.    
  526.     //Wrap Right
  527.     001, 002, 003m 004, 005, 006, 007, 000,
  528.     009, 010, 011, 012, 013, 014, 015, 008,
  529.     017, 018, 019, 020. 021, 022, 023, 016,
  530.     025, 026, 027, 028, 029, 030, 031, 024,
  531.    
  532.     0,0,0,0};
  533.    
  534.  
  535.    
  536.    
  537.    
  538.    
  539. //Returns the logical dmap onto which we wrap.
  540.     //!Does NOT give the screen on that DMap.
  541.     //!We need a second function for /that/
  542. int GetWrapDMap(int virtual_map, int dmap, int dir, int dmap_max){
  543.     int pos;
  544.     for ( pos = 0; pos < dmap_max, pos++ ) {
  545.         if ( virtual_map[pos] == dmap ) {
  546.             if ( dir == DIR_UP ) return ( virtual_map[ ( NUM_WORLD_DMAPS ) + pos];
  547.             if ( dir == DIR_DOWN ) return ( virtual_map[ ( NUM_WORLD_DMAPS*2 ) + pos];
  548.             if ( dir == DIR_LEFT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*3 ) + pos];
  549.             if ( dir == DIR_RIGHT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*4 ) + pos];
  550.             return 1; //invalid directiom
  551.         }
  552.     }
  553.     return -1; //no match
  554. }
  555.    
  556.  
  557. int virtual_map_0[]={
  558.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  559.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  560.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  561.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  562.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  563.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  564.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  565.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
  566.    
  567.  
  568.    
  569.  
  570. //! FFC Scripts
  571. ffc script FortressExit{
  572.     void run(int fortress_id){
  573.         while(true){
  574.             if ( Collision(this) ) {
  575.                 SetLinkFlag(LINKF_LEAVING_FORTRESS,true); //mark Link Leaving fortress
  576.                
  577.                 Screen->SetSideWarp(FORTRESS_EXIT_SIDEWARP, FortressScreen(fortress_id), FortressDMapfortress_id), FORTRESS_EXIT_SIDEWARP_TYPE);
  578.             }
  579.             Waitframe();
  580.         }
  581.     }
  582. }
  583.  
  584. ffc script FortressFFC{
  585.     void run(int warp_to_dmap, int warp_to_screen){
  586.         while(true){
  587.             if ( FortressScreen(fortress_id) != Game->GetCurScreen() ) Quit(); //If the fortress moves off-screen, quit.
  588.             if ( LinkFortressZ() && Collision(this) ) { //If collision with this and Link has the fake Z needed...
  589.                 //Set the tilewarp and change this ffc's data to a warp type.
  590.                 Screen->SetTileWarp(FORTRESS_ENTRANCE_TILEWARP, warp_to_screen, warp_to_dmap, FORTRESS_ENTRANCE_TILEWARP_TYPE);
  591.                 this->Data = FORTRESS_TILEWARP_COMBO;
  592.             }
  593.             Waitframe();
  594.         }
  595.     }
  596. }
  597.  
  598.  
  599. //Test Global Active Script
  600. global script test_fortress{
  601.     void run(){
  602.         while(true){
  603.             for ( _____GRAM[LOOPS_Q] = 0; _____GRAM[LOOPS_Q]  < 9; _____GRAM[LOOPS_Q]++ ) {
  604.                 DoFortress(q);
  605.             }
  606.             Waitdraw();
  607.             Waitframe();
  608.         }
  609.     }
  610. }
  611.  
  612. const int DEFAULT_FORTRESS_TILE = 0;
  613. const int DEFAULT_FORTRESS_X = 30;
  614. const int DEFAULT_FORTRESS_Y = 20;
  615. const int DEFAULT_FORTRESS_DMAP = 0;
  616. const int DEFAULT_FORTRESS_SCREEN = 0x14;
  617. const int DEFAULT_FORTRESS_DIR = 0;
  618. const float DEFAULT_FORTRESS_SPEED = 0.002;
  619. const float DEFAULT_FORTRESS_TIME = 0.50;
  620. const int DEFAULT_FORTRESS_TILE = 10100;
  621. const int DEFAULT_FORTRESS_TILEWIDTH = 1;
  622. const int DEFAULT_FORTRESS_TILEHEIGHT = 1;
  623. const int DEFAULT_FORTRESS_SCALE = 30;
  624. const int DEFAULT_FORTRESS_CSET = 0;
  625. const int DEFAULT_FORTRESS_SHADOWTILE = 10100;
  626. const int DEFAULT_FORTRESS_TILEWIDTH = 1;
  627. const int DEFAULT_FORTRESS_TILEHEIGHT = 1;
  628. const int DEFAULT_FORTRESS_SHADOWSCALE = 18;
  629. const int DEFAULT_FORTRESS_SHADOW_Y_OFS = 30;
  630. const int DEFAULT_FORTRESS_DEST_DMAP = 1;
  631. const int DEFAULT_FORTRESS_DEST_SCREEN = 0x71;
  632.  
  633.  
  634. //Example Init script
  635. global script init{
  636.     void run(){
  637.         SetFortressInitialAttributes(0, DEFAULT_FORTRESS_X, DEFAULT_FORTRESS_Y, DEFAULT_FORTRESS_DMAP, DEFAULT_FORTRESS_SCREEN,
  638.         DEFAULT_FORTRESS_DIR, DEFAULT_FORTRESS_SPEED, DEFAULT_FORTRESS_TIME, DEFAULT_FORTRESS_TILE, DEFAULT_FORTRESS_TILEWIDTH,
  639.         DEFAULT_FORTRESS_TILEHEIGHT, DEFAULT_FORTRESS_SCALE, DEFAULT_FORTRESS_CSET, DEFAULT_FORTRESS_SHADOWTILE, DEFAULT_FORTRESS_TILEWIDTH,
  640.         DEFAULT_FORTRESS_TILEHEIGHT, DEFAULT_FORTRESS_SHADOWSCALE, DEFAULT_FORTRESS_SHADOW_Y_OFS, DEFAULT_FORTRESS_DEST_DMAP, DEFAULT_FORTRESS_DEST_SCREEN,
  641.         virtual_map_1);
  642.     }
  643. }
  644.  
  645.  
  646.  
  647.  
  648.  
  649. //! For world-wrapping, in a future version
  650.  
  651. int virtual_map[114]; //nine dmaps screen, x, y, left_bound, rightbound, topbound, bottombound* dmaps];
  652. const int DMAP1 = 0;
  653. const int DMAP_COLS = 12;
  654. //start ( dmap, start screen, screen_left, screen_right, screen_up, screen_down, dma_left, dmap_right, dmap_down, dmap_up, x, y ) * dmap count
  655. int virtualmap_dmap-connections[numdmaps];
  656.  
  657. //Call in init script to set up all the boundaries, dest screens, and so forth.
  658. void SetMapBound(int ptr, int type, int screen, bool wrapdmap, int wrapto){
  659.     //Set the screen that is the left most, and the screen on the right of the dmap to wrap into.
  660.     //If we are wrapping to another dmap, we need to know it.
  661.     if ( type == BOUND_LEFT ) {
  662.        
  663.         //We need to automatically set up wraps to dmaps using GetWrapDMap()
  664.        
  665.         ptr[FLF_MAP_BOUND_LEFT = screen; //the screen at which we start the wrap
  666.         ptr[FLF_MAP_BOUND_LEFT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  667.         if ( wrapdmap ) ptr[FLF_MAP_BOUND_LEFT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_LEFT); //the dmap on which we end the wrap.
  668.         ptr[FLF_X] = 255; //We wrapped left from x=0, so we wrap to x = 255.
  669.     }
  670.     if ( type == BOUND_RIGHT ) {
  671.         ptr[FLF_MAP_BOUND_RIGHT = screen; //the screen at which we start the wrap
  672.         ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  673.         if ( wrapdmap ) ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_RIGHT);  //the dmap on which we end the wrap.
  674.         ptr[FLF_X] = 0; //We wrapped left from x=255, so we wrap to x = 0.
  675.     }
  676.     if ( type == BOUND_UP ) {
  677.         ptr[FLF_MAP_BOUND_UP = screen; //the screen at which we start the wrap
  678.         ptr[FLF_MAP_BOUND_UP_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  679.         if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_UP_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_UP); //the dmap on which we end the wrap.
  680.         ptr[FLF_Y] = 175; //We wrapped left from y=0, so we wrap to Y = 175.
  681.     }
  682.     if ( type == BOUND_DOWN ) {
  683.         ptr[FLF_MAP_BOUND_DOWN = screen; //the screen at which we start the wrap
  684.         ptr[FLF_MAP_BOUND_DOWN_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  685.         if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_DOWN_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_DOWN);  //the dmap on which we end the wrap.
  686.         ptr[FLF_Y] = 0; //We wrapped left from y=175, so we wrap to Y = 0.
  687.     }
  688. }
  689.  
  690. /*
  691. int WrapDMap(int dmap){
  692.     int dmap = Game->GetCurDMap();
  693.    
  694.     //checck ths table to see if we are on the edge of a dmap and wrappinf to another one,
  695.     //if so, return its value
  696.     //otherwise, return the current dmap.
  697.    
  698.     int dmap1[128]={
  699.         0,0,0,0,0,0
  700. }
  701. */
  702. const int DMAP_COLS = 4; //Actual columns
  703. const int DMAP_ROWS = 4; //Actual rows
  704. int GetWrapDMap(int source, int dir){
  705.     int virtual_dmaps[ (4_dirs +1 )* NumDMaps] {
  706.        
  707.        
  708.         //Layout of the world by DMap IDs.
  709.        
  710.         0000
  711.         0000
  712.         0000
  713.         0000,
  714.        
  715.         //Left position from each
  716.        
  717.         3012
  718.         7456
  719.         11, 8910,
  720.         15, 12, 13, 14,
  721.        
  722.         //Right position from each
  723.        
  724.         1230
  725.         5674
  726.         910, 11, 8
  727.         13, 14, 15, 12,
  728.        
  729.         //Down position from each
  730.        
  731.         4567
  732.         8910, 11,
  733.         12, 13, 14, 15,
  734.         0123,
  735.        
  736.         //Up position from each
  737.        
  738.         12, 13, 14, 15,
  739.         0123
  740.         8910, 11,
  741.         78910,
  742.     }
  743.    
  744.     if ( dir == DIR_LEFT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*1)];
  745.     if ( dir == DIR_RIGHT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*2)];
  746.     if ( dir == DIR_DOWN ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*3)];
  747.     if ( dir == DIR_UP ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*4)];
  748.     return -1;//Error
  749. }
  750.  
  751.  
  752.  
  753.  
  754. //If our DMap is square, this part is easier.
  755. int virtual_maps[]={    0,  0x1F,    0,     0x1F,
  756.             0,  0x1F,    0,     0x1F,
  757.             0,  0x1F,    0,     0x1F,
  758.             0,  0x1F,    0,     0x1F,
  759.             0,  0x1F,    0,     0x1F,
  760.             0,  0x1F,    0,     0x1F,
  761.             0,  0x1F,    0,     0x1F,
  762.             0,  0x1F,    0,     0x1F,
  763.             0,  0x1F,    0,     0x1F,
  764.  
  765. }; //Topleft, Topright, BottomLeft, BottomRight Screen IDs
  766.  
  767.  
  768.  
  769.  
  770. //! Deprecated --------------------------------------------------------------------------------------------------------
  771.  
  772. bool TurnFortress(int fortress_id) {
  773.     if ( ( FortressAtScreenEdge(fortres_id), FortressDir(fortress_id) ) || FortressTimer(fortress_id) <= 0 ) {
  774.         //Choose a direction other than the present diretion.
  775.         int dir;
  776.         do { //Pick a random direction that differs from this direction.
  777.             dir = Rand(0,7);
  778.         } while ( dir != FortressDir(fortress_id);
  779.         FortressDir(fortress_id, dir); //Change the direction.
  780.     }
  781. }
  782.  
  783. int MoveForetressSpeed()
  784.  
  785.  
  786. //Edge of Boundary Screen
  787. bool FortressAtDMapEdge(int virtual_map){
  788.    
  789.    
  790.    
  791. }
  792.  
  793. void SetFortressTimers(int ptr){
  794.     nt sz = SzeOfArray(ptr);
  795.     for ( int q = 0; q < sz; q += NUM_FORTRESSES )  ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX);
  796. }
  797. void DoFortressTmers(int ptr){
  798.     int sz = SizeOfArray(ptr);
  799.     for ( int q = 0; q < sz; q += NUM_FORTRESSES ) {
  800.         if ( ptr[q] <= 0 ) { MoveFortress(q); ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX); }
  801.         else ptr[q]--;
  802.     }
  803. }
  804.  
  805. int MoveFortressDir(int ptr) {
  806.     int dirs[4] = {UP, DOWN, LEFT, RIGHT};
  807.     int dir = dirs[Rand(0,4)]; //What about angles?
  808.     //
  809. }
  810.  
  811.  
  812. //I forgot what this was supposed to do, ans I may as well start fresh after I resolve DMap boundaries.
  813. void MoveFortress(int ptr){
  814.     int distx = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
  815.     int disty = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
  816.     bool neg = RandB();
  817.     if ( neg )
  818.     //Avoid jiter somehow?
  819. }
  820.    
  821. void MoveFortress(int id)}
  822.  
  823. const int FLF_MAP_
  824.  
  825. //! THis function is Not finished
  826. //Boundary Screen?
  827. bool FortressAtDMapBoundary(int fortress_id, int virtual_map, int offset){
  828.    
  829.     //Map out the screens of this DMap.
  830.     int map[4];
  831.     for ( int q = 0; q < 3; q++ ) {
  832.         map[q] = virtual_map[(offset*4)+q];
  833.     }
  834.    
  835.     int edges[4];
  836.    
  837.     if ( FortressScreen(fortress_id) % map[0] == 0 ) edges[0] = 1; //on left side of dmap. //Will this work of the DMap has an offset???
  838.    
  839.     //Decide which screens are dmap boundaries.
  840.    
  841.     //If the fortress is on one of these screens, return true.
  842. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement