ZoriaRPG

ZScript: Flying Fortress Alpha 0.5

May 20th, 2017
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //! We need a GetScreenDown and GetScreenUp function pair to go with the virtual maps.
  2.             }
  3.  
  4. int _____GRAM[1024];
  5. const int LOOPS_Q = 1023;
  6.  
  7.  
  8. int Fortresses[27]; //tmer, dir, speed, x, y, dmap, screen
  9.  
  10. const int FORTRESS_TIMER = 0;
  11. const int FORTRESS_DIR = 1;
  12. const int FORTRESS_SPEED = 2;
  13. const int FORTRESS_X = 3;
  14. const int FORTRESS_Y = 4;
  15. const int FORTRESS_DMAP_ID = 5;
  16. const int FORTRESS_SCREEN_ID = 6;
  17. const int FORTRESS_TILE = 7;
  18. const int FORTRESS_CSET = 8;
  19. const int FORTRES_SCALE = 9; //Scale it, blast you!
  20. const int FORTRESS_SHADOW_TILE = 10;
  21. const int FORTRESS_SHADOW_ = 11; //More scaling effects, for perspective.
  22.  
  23. const int FORTRESS_DMAP_OFFSET = 12;  // Multiply this * Fortress ID, then add element.
  24.  
  25. const int NUM_FORTRESSES = 9;
  26.  
  27. const int FORTRESS_MOVE_TMER_MIN = 120;
  28. const int FORTRESS_MOVE_TMER_MAX = 400;
  29.  
  30. const int FORTRESS_MOVE_DIST_MIN = 6;
  31. const int FORTRESS_MOVE_DIST_MAX = 14;
  32.  
  33. //! Let's hardcode some DMAPS! Z
  34.  
  35. const int FF_DMAP_SCREEN_VALID = 0;
  36. const int FF_DMAP_SCREEN_INVALID = -1;
  37. const int FF_DMAP_SCREEN_BOUNDARY = 1; //1 or higher is a screen boundary.
  38.  
  39. //A virtual DMap. 0s are empty space, 1s are screens, 2s are boundaries.
  40. //Should each edge and corner be a unique value
  41.  
  42. /*
  43. -1 empty space
  44. 0 has sceens on each side
  45.  
  46. 1 cannot turn up
  47. 2 cannot turn down
  48. 4 cannot turn right
  49. 8 cannot turn up
  50.  
  51.  
  52. */
  53. const int NOT_VALID_SCREEN = -1;
  54. const int CANNOT_TURN_UP = 1;
  55. const int CANNOT_TURN_DOWN = 2;
  56. const int CANNOT_TURN_RIGHT = 4;
  57. const int CANNOT_TURN_LEFT = 8;
  58.  
  59. const int VM_WRAP_UP = 128;
  60. const int VM_WRAP_DOWN = 256;
  61. const int VM_WRAP_LEFT = 384;
  62. const int VM_WRAP_RIGHT = 512;
  63.  
  64. //A virtual map with the edges marked.
  65. int virtual_map_1[]={
  66.    
  67.     // Illegal Turns
  68.     9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
  69.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  70.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  71.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  72.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  73.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  74.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  75.     10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,
  76.    
  77.     //Wraps
  78.     //! These wrap from the screen at [index] to the specified screen for each given direction.
  79.     //! Needed for non-16x8 DMaps
  80.    
  81.     //!! We can handle WORLD WRAPPING in the same manner, by storing an U/D/L/R grid for each DMap as
  82.     //!! four arrays.
  83.    
  84.     //Wrap Screen Up
  85.    
  86.     0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
  87.     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  88.     0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  89.     0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  90.     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  91.     0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  92.     0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  93.     0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  94.    
  95.     //Wrap screen down
  96.    
  97.     0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  98.     0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  99.     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  100.     0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  101.     0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  102.     0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  103.     0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
  104.     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  105.    
  106.     //Wrap Screen left
  107.    
  108.     0x0F,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
  109.     0x1F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,
  110.     0x2F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,
  111.     0x3F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,
  112.     0x4F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,
  113.     0x5F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,
  114.     0x6F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,
  115.     0x7F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,
  116.    
  117.     //Wrap screen right
  118.    
  119.     0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x00,
  120.     0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x10,
  121.     0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x20,
  122.     0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x30,
  123.     0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x40,
  124.     0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x50,
  125.     0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x60,
  126.     0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x70,
  127.  
  128.     0,0,0,0};
  129.    
  130. int virtual_dmaps[]={
  131.    
  132.     //The world layout
  133.    
  134.     //DMap IDs as they actually connect
  135.     000, 001, 002, 003m 004, 005, 006, 007,
  136.     008, 009, 010, 011, 012, 013, 014, 015,
  137.     016, 017, 018, 019, 020. 021, 022, 023,
  138.     024, 025, 026, 027, 028, 029, 030, 031,
  139.    
  140.     //Wrap Up
  141.     024, 025, 026, 027, 028, 029, 030, 031,
  142.     000, 001, 002, 003m 004, 005, 006, 007,
  143.     008, 009, 010, 011, 012, 013, 014, 015,
  144.     016, 017, 018, 019, 020. 021, 022, 023,
  145.    
  146.    
  147.     //Wrap Down
  148.     008, 009, 010, 011, 012, 013, 014, 015,
  149.     016, 017, 018, 019, 020. 021, 022, 023,
  150.     024, 025, 026, 027, 028, 029, 030, 031,
  151.     000, 001, 002, 003m 004, 005, 006, 007,
  152.    
  153.     //Wrap Left
  154.     007, 000, 001, 002, 003m 004, 005, 006,  
  155.     015, 008, 009, 010, 011, 012, 013, 014,
  156.     023, 016, 017, 018, 019, 020. 021, 022,
  157.     031, 024, 025, 026, 027, 028, 029, 030,
  158.    
  159.     //Wrap Right
  160.     001, 002, 003m 004, 005, 006, 007, 000,
  161.     009, 010, 011, 012, 013, 014, 015, 008,
  162.     017, 018, 019, 020. 021, 022, 023, 016,
  163.     025, 026, 027, 028, 029, 030, 031, 024,
  164.    
  165.     0,0,0,0};
  166.    
  167. const int NUM_WORLD_DMAPS = 32;
  168.    
  169. int GetWrapDMap(int virtual_map, int dmap, int dir, int dmap_max){
  170.     int pos;
  171.     for ( pos = 0; pos < dmap_max, pos++ ) {
  172.         if ( virtual_map[pos] == dmap ) {
  173.             if ( dir == DIR_UP ) return ( virtual_map[ ( NUM_WORLD_DMAPS ) + pos];
  174.             if ( dir == DIR_DOWN ) return ( virtual_map[ ( NUM_WORLD_DMAPS*2 ) + pos];
  175.             if ( dir == DIR_LEFT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*3 ) + pos];
  176.             if ( dir == DIR_RIGHT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*4 ) + pos];
  177.             return 1; //invalid directiom
  178.         }
  179.     }
  180.     return -1; //no match
  181. }
  182.    
  183. //Returns the correct screen for wrapping x.y coordinates off a given screen for a virtual map.
  184. int GetWrapScreen(int virtual_map, int screen, int dir){
  185.     if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UP]; }
  186.     if ( dir == DIR_DOWN ) { return virtual_map[screen+VM_WRAP_DOWN]; }
  187.     if ( dir == DIR_LEFT ) { return virtual_map[screen+VM_WRAP_LEFT]; }
  188.     if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UO]; }
  189.     return -1; //Invalid direction.
  190. }
  191.    
  192. //Determines a random, legal directions, based on values on a vritual map.
  193. int FindLegalTurn(int virtual_map, int screen){
  194.     if ( virtual_map[screen] == 1 ) {  //cannot turn up
  195.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_DOWN) );
  196.     }
  197.     if ( virtual_map[screen] == 2 ) { //cannot tuen down
  198.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_UP) );
  199.     }
  200.     if ( virtual_map[screen] == 4 ) { //cannot turn right
  201.         return ( Choose(DIR_LEFT, DIR_DOWN, DIR_UP) );
  202.     }
  203.     if ( virtual_map[screen] == 5 ) { //cannot turn up or right
  204.         return ( Choose(DIR_DOWN, DIR_LEFT) );
  205.     }
  206.     if ( virtual_map[screen] == 6 ) { //cannot turn down or right
  207.         return ( Choose(DIR_UP, DIR_LEFT) );
  208.     }
  209.     if ( virtual_map[screen] == 8 ) { //cannot turn left
  210.         return ( Choose(DIR_RIGHT, DIR_DOWN, DIR_UP) );
  211.     }
  212.     if ( virtual_map[screen] == 9 ) { //cannot turn left or up
  213.         return ( Choose(DIR_RIGHT, DIR_DOWN) );
  214.     }
  215.     if ( virtual_map[screen] == 10 ) { //cannot turn left or down
  216.         return ( Choose(DIR_RIGHT, DIR_UP) );
  217.     }
  218.     return Rand(0,3); //Otherwise, return a random direction.
  219. }
  220.  
  221.  
  222. const int FORTRESS_1_TILE = 100;
  223. const int FORTRESS_SHADOW_TILE = 101;
  224. const int FORTRESS_SHADOW_Y_OFFSET = 70;
  225. const int FORTRESS_DRAW_LAYER = 6;
  226. const int FORTRESS_SHADOW_DRAW_LAYER = 6;
  227. const int FORTRESS_TILEWIDTH = 1;
  228. const int FORTRESS_TILEHEIGHT = 1;
  229.  
  230. const int FORTRESS_SHADOW_CSET = 0;
  231.  
  232. void DrawFortress(int fortress_id, int tile){
  233.     //if it is on this dmap
  234.     if ( FortressDMap(fortress_id) == Game->GetCurDMap() ) {
  235.         //...and this screen
  236.         if ( FortressScreen(fortress_id) == Game->GetCurScreen() ) {
  237.             //Draw it
  238.             Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id),
  239.             FORTRESS_TILEWIDTH, FORTRESS_TILEHEIGHT, FortressCSet(fortress_id), FortressScale(fortress_id), FortressScale(fortress_id),
  240.             0, 0, 0, 0, true, OP_OPAQUE);
  241.             //Draw its shadow.
  242.            
  243.             Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressShadowTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id)+FORTRESS_SHADOW_Y_OFFSET,
  244.             FORTRESS_TILEWIDTH, FORTRESS_TILEHEIGHT, FORTRESS_SHADOW_CSET, FortresShadowScale(fortress_id), FortresShadowScale(fortress_id),
  245.             0, 0, 0, 0, true, OP_OPAQUE);
  246.         }
  247.     }
  248. }
  249.  
  250. bool FortressCanMove(int fortress_id, int virtual_map, int screen){
  251.     int dir = FortressDir(fortress_id);
  252.     int scr = FortressScreen(fortress_id);
  253.     //If the fortress is on a screen edge, check if that is a dmap edge, too.
  254.     if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id) ){
  255.         if ( dir == DIR_LEFT ) {
  256.             if ( virtual_map[scr] >= 8 ) return false;
  257.             return true;
  258.         }
  259.         if ( dir == DIR_RIGHT ){
  260.             if ( virtual_map[scr] >= 4 &&  virtual_map[scr] <= 6 ) return false;
  261.             return true;
  262.         }
  263.         if ( dir == DIR_DOWN ) {
  264.             if ( virtual_map[scr] == 10 || virtual_map[scr] == 2 || virtual_map[scr] == 6 ) return false;
  265.             return true;
  266.         }
  267.         if ( dir == DIR_UP ) {
  268.             if ( virtual_map[scr] == 9 || virtual_map[scr] == 1 || virtual_map[scr] == 5 ) return false;
  269.             return true;
  270.         }
  271.     }
  272.     return true; //The fortress is not on a screen edge, so it can move freely.
  273. }
  274.  
  275. //Moves the fortress based on its speed, and changes its direction if it cannot move.
  276. void MoveFortress(int fortress_id, int virtual_map){
  277.     if ( FortressCanMove(fortress_id) ) {
  278.         if ( FortressDir(fortress_id) == DIR_LEFT ) {
  279.             //If it is on the edge of a screen
  280.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  281.                 //Move it one screen to the left and reset its X
  282.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_LEFT) );
  283.                 FortressX(fortress_id,255);
  284.             }
  285.             //Move left
  286.             else FortressX(fortress_id, FortressX(fortress_id)-FortressSpeed(fortress_id));
  287.         }
  288.         if ( FortressDir(fortress_id) == DIR_RIGHT ) {
  289.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  290.                 //Move it one screen to the right and reset its X
  291.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_RIGHT));
  292.                 FortressX(fortress_id,0);
  293.             }
  294.             //Move right
  295.             else FortressX(fortress_id, FortressX(fortress_id)+FortressSpeed(fortress_id));
  296.         }
  297.         if ( FortressDir(fortress_id) == DIR_UP ) {
  298.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  299.                 //Move it one screen up and reset its Y
  300.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_UO));
  301.                 FortressY(fortress_id,175);  
  302.             }
  303.             //Move up
  304.             FortressY(fortress_id, FortressY(fortress_id)-FortressSpeed(fortress_id));
  305.         }
  306.         if ( FortressDir(fortress_id) == DIR_DOWN ) {
  307.             if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
  308.                 //Move it one screen down and reset its Y
  309.                 FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_DOWN));
  310.                 FortressY(fortress_id,0);
  311.             }
  312.             //Move down
  313.             FortressY(fortress_id, FortressY(fortress_id)+FortressSpeed(fortress_id));
  314.         }
  315.     }
  316.     else {
  317.         //Change the direction.
  318.         FortressDir( fortress_id, FindLegalTurn(fortress_id, virtual_map) );
  319.     }
  320. }
  321.  
  322. int virtual_map_0[]={
  323.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  324.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  325.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  326.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  327.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  328.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  329.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  330.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
  331.    
  332.  
  333.  
  334. //Main fortress function. Call once per fortress, pointing to its id and the virtual map that it uses.
  335. void DoFortress(int fortress_id, int virtual_map){
  336.     DoFortressTmers(fortress_id);
  337.     MoveFortress(fortress_id, virtual_map); //Moves the fortress every frame, and chanhges its direction fi it cannot move.
  338.     //UpdateFortressScreen(fortress_id); //If the fortress moves off-screen, wrap it to the next one.
  339.     DrawFortress(fortress_id);
  340. }
  341.  
  342.  
  343. global script test_fortress{
  344.     void run(){
  345.         while(true){
  346.             for ( _____GRAM[LOOPS_Q] = 0; _____GRAM[LOOPS_Q]  < 9; _____GRAM[LOOPS_Q]++ ) {
  347.                 DoFortress(q);
  348.             }
  349.             Waitdraw();
  350.             Waitframe();
  351.         }
  352.     }
  353. }
  354.  
  355. void DoFortressTmers(int fortress_id){
  356.     if FortressTimer(fortress_id) <= 0 ) {
  357.         TurnFortress(fortress_id);
  358.     }
  359.     else {
  360.         FortressTime(fortress_id, FortressTIme(fortress_id)-1); //Reduce the timer.
  361.     }
  362. }
  363.  
  364.  
  365. const int FORTRESS_WIDTH = 8;  //Sprite dimensions.
  366. const int FORTRESS_HEIGHT = 8;
  367. const int FORTRESS_Z_LOCATION = 100; //must match this Z to enter.
  368.  
  369. bool FortressAtScreenEdge(int fortress_id, int dir){
  370.     if ( dir == DIR_LEFT && FottressX(fortress_id) <= 0+FORTRESS_WIDTH ) return true;
  371.     if ( dir == DIR_RIGHT && FortressX(fortress_id) >= 256 ) return true;
  372.     if ( dir == DIR_UP && FortressY(fortress_id)+FORTRESS_HEIGHT < 0 ) return true;
  373.     if ( dir == DIR_DOWN && FortrwessY(fortress_id) >= 176 ) return true;
  374.     return false;
  375. }
  376. //Turns the fortress if its timer expires.
  377. bool TurnFortress(int fortress_id) { {
  378.     //Choose a direction other than the present diretion.
  379.     int dir;
  380.     do { //Pick a random direction that differs from this direction.
  381.         dir = Rand(0,7);
  382.     } while ( dir != FortressDir(fortress_id);
  383.     FortressDir(fortress_id, dir); //Change the direction.
  384.     //Reset the turn timer to a randomised value. .
  385.     FortressTimer(fortress_id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX) );
  386. }
  387.    
  388. const int FORTRESS_TIME_MIN = 0; //minutes
  389. const int FORTRESS_TIME_MAX = 3; //minutes
  390. const int FORTRESS_TIME_FRACTIONAL_MIN = 10; //seconds
  391. const int FORTRESS_TIME_FRACTIONAL_MAX = 59; //seconds
  392.    
  393. //Accessors for Fortresses[]
  394. int FortressX(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X]<<0); } //Truncated
  395. int FortressY(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y]<<0); } //Truncated
  396. int FortressDir(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR]; }
  397. int FortressSpeed(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED]; }
  398. int FortressDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID]; }
  399. int FortressScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID]; }
  400. int FortressTimer(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
  401. void FortressX(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X] = VBound(v,0,255); }
  402. void FortressY(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  403. void FortressDir(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR] = VBound(v,0,7); }
  404. void FortressSpeed(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED] = Abs(v); }
  405. void FortressDMap(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID] = v; }
  406. void FortressScreen(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID] = VBound(v,0,255); }
  407. void FortressTimer(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = Abs(v); }
  408. void FortressY(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  409. int FortressY(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y]; }
  410. int FortressTile(int fortress_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE]; }
  411. void FortressTile(int fortress_id, int tile(){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE] = tile; }
  412. int FortressCSet(int fortress_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET]; }
  413. void FortressCSet(int fortress_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET] = v; }
  414. int FortresScale(int fortress_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE]; }
  415. void FortressScale(int fortress_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE] = scale; }
  416. int FortressShadowTile(int fortress_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE]; }
  417. void FortressShadowTile(int fortress_id, int tile) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE] = tile; }
  418. int FortresShadowScale(int fortress_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE]; }
  419. void FortressShadowScale(int fortress_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE] = scale; }
  420.  
  421. //Set the turn timer.
  422. int FortressTime(int time_min, time_max, int frac_time, int frac_max){
  423.     int t = Rand(time_min,time_max); int tt = (Rand(frac_time, frac_max) / 60);
  424.     Return (t+tt)*60;
  425. }
  426.  
  427. //! For world-wrapping, in a future version
  428.  
  429. int virtual_map[114]; //nine dmaps screen, x, y, left_bound, rightbound, topbound, bottombound* dmaps];
  430. const int DMAP1 = 0;
  431. const int DMAP_COLS = 12;
  432. //start ( dmap, start screen, screen_left, screen_right, screen_up, screen_down, dma_left, dmap_right, dmap_down, dmap_up, x, y ) * dmap count
  433. int virtualmap_dmap-connections[numdmaps];
  434.  
  435. //Call in init script to set up all the boundaries, dest screens, and so forth.
  436. void SetMapBound(int ptr, int type, int screen, bool wrapdmap, int wrapto){
  437.     //Set the screen that is the left most, and the screen on the right of the dmap to wrap into.
  438.     //If we are wrapping to another dmap, we need to know it.
  439.     if ( type == BOUND_LEFT ) {
  440.        
  441.         //We need to automatically set up wraps to dmaps using GetWrapDMap()
  442.        
  443.         ptr[FLF_MAP_BOUND_LEFT = screen; //the screen at which we start the wrap
  444.         ptr[FLF_MAP_BOUND_LEFT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  445.         if ( wrapdmap ) ptr[FLF_MAP_BOUND_LEFT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_LEFT); //the dmap on which we end the wrap.
  446.         ptr[FLF_X] = 255; //We wrapped left from x=0, so we wrap to x = 255.
  447.     }
  448.     if ( type == BOUND_RIGHT ) {
  449.         ptr[FLF_MAP_BOUND_RIGHT = screen; //the screen at which we start the wrap
  450.         ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  451.         if ( wrapdmap ) ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_RIGHT);  //the dmap on which we end the wrap.
  452.         ptr[FLF_X] = 0; //We wrapped left from x=255, so we wrap to x = 0.
  453.     }
  454.     if ( type == BOUND_UP ) {
  455.         ptr[FLF_MAP_BOUND_UP = screen; //the screen at which we start the wrap
  456.         ptr[FLF_MAP_BOUND_UP_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  457.         if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_UP_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_UP); //the dmap on which we end the wrap.
  458.         ptr[FLF_Y] = 175; //We wrapped left from y=0, so we wrap to Y = 175.
  459.     }
  460.     if ( type == BOUND_DOWN ) {
  461.         ptr[FLF_MAP_BOUND_DOWN = screen; //the screen at which we start the wrap
  462.         ptr[FLF_MAP_BOUND_DOWN_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  463.         if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_DOWN_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_DOWN);  //the dmap on which we end the wrap.
  464.         ptr[FLF_Y] = 0; //We wrapped left from y=175, so we wrap to Y = 0.
  465.     }
  466. }
  467.  
  468. /*
  469. int WrapDMap(int dmap){
  470.     int dmap = Game->GetCurDMap();
  471.    
  472.     //checck ths table to see if we are on the edge of a dmap and wrappinf to another one,
  473.     //if so, return its value
  474.     //otherwise, return the current dmap.
  475.    
  476.     int dmap1[128]={
  477.         0,0,0,0,0,0
  478. }
  479. */
  480. const int DMAP_COLS = 4; //Actual columns
  481. const int DMAP_ROWS = 4; //Actual rows
  482. int GetWrapDMap(int source, int dir){
  483.     int virtual_dmaps[ (4_dirs +1 )* NumDMaps] {
  484.        
  485.        
  486.         //Layout of the world by DMap IDs.
  487.        
  488.         0000
  489.         0000
  490.         0000
  491.         0000,
  492.        
  493.         //Left position from each
  494.        
  495.         3012
  496.         7456
  497.         11, 8910,
  498.         15, 12, 13, 14,
  499.        
  500.         //Right position from each
  501.        
  502.         1230
  503.         5674
  504.         910, 11, 8
  505.         13, 14, 15, 12,
  506.        
  507.         //Down position from each
  508.        
  509.         4567
  510.         8910, 11,
  511.         12, 13, 14, 15,
  512.         0123,
  513.        
  514.         //Up position from each
  515.        
  516.         12, 13, 14, 15,
  517.         0123
  518.         8910, 11,
  519.         78910,
  520.     }
  521.    
  522.     if ( dir == DIR_LEFT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*1)];
  523.     if ( dir == DIR_RIGHT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*2)];
  524.     if ( dir == DIR_DOWN ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*3)];
  525.     if ( dir == DIR_UP ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*4)];
  526.     return -1;//Error
  527. }
  528.  
  529.  
  530.  
  531.  
  532. //If our DMap is square, this part is easier.
  533. int virtual_maps[]={    0,  0x1F,    0,     0x1F,
  534.             0,  0x1F,    0,     0x1F,
  535.             0,  0x1F,    0,     0x1F,
  536.             0,  0x1F,    0,     0x1F,
  537.             0,  0x1F,    0,     0x1F,
  538.             0,  0x1F,    0,     0x1F,
  539.             0,  0x1F,    0,     0x1F,
  540.             0,  0x1F,    0,     0x1F,
  541.             0,  0x1F,    0,     0x1F,
  542.  
  543. }; //Topleft, Topright, BottomLeft, BottomRight Screen IDs
  544.  
  545.  
  546.  
  547.  
  548. //! Deprecated --------------------------------------------------------------------------------------------------------
  549.  
  550. bool TurnFortress(int fortress_id) {
  551.     if ( ( FortressAtScreenEdge(fortres_id), FortressDir(fortress_id) ) || FortressTimer(fortress_id) <= 0 ) {
  552.         //Choose a direction other than the present diretion.
  553.         int dir;
  554.         do { //Pick a random direction that differs from this direction.
  555.             dir = Rand(0,7);
  556.         } while ( dir != FortressDir(fortress_id);
  557.         FortressDir(fortress_id, dir); //Change the direction.
  558.     }
  559. }
  560.  
  561. int MoveForetressSpeed()
  562.  
  563.  
  564. //Edge of Boundary Screen
  565. bool FortressAtDMapEdge(int virtual_map){
  566.    
  567.    
  568.    
  569. }
  570.  
  571. void SetFortressTimers(int ptr){
  572.     nt sz = SzeOfArray(ptr);
  573.     for ( int q = 0; q < sz; q += NUM_FORTRESSES )  ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX);
  574. }
  575. void DoFortressTmers(int ptr){
  576.     int sz = SizeOfArray(ptr);
  577.     for ( int q = 0; q < sz; q += NUM_FORTRESSES ) {
  578.         if ( ptr[q] <= 0 ) { MoveFortress(q); ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX); }
  579.         else ptr[q]--;
  580.     }
  581. }
  582.  
  583. int MoveFortressDir(int ptr) {
  584.     int dirs[4] = {UP, DOWN, LEFT, RIGHT};
  585.     int dir = dirs[Rand(0,4)]; //What about angles?
  586.     //
  587. }
  588.  
  589.  
  590. //I forgot what this was supposed to do, ans I may as well start fresh after I resolve DMap boundaries.
  591. void MoveFortress(int ptr){
  592.     int distx = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
  593.     int disty = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
  594.     bool neg = RandB();
  595.     if ( neg )
  596.     //Avoid jiter somehow?
  597. }
  598.    
  599. void MoveFortress(int id)}
  600.  
  601. const int FLF_MAP_
  602.  
  603. //! THis function is Not finished
  604. //Boundary Screen?
  605. bool FortressAtDMapBoundary(int fortress_id, int virtual_map, int offset){
  606.    
  607.     //Map out the screens of this DMap.
  608.     int map[4];
  609.     for ( int q = 0; q < 3; q++ ) {
  610.         map[q] = virtual_map[(offset*4)+q];
  611.     }
  612.    
  613.     int edges[4];
  614.    
  615.     if ( FortressScreen(fortress_id) % map[0] == 0 ) edges[0] = 1; //on left side of dmap. //Will this work of the DMap has an offset???
  616.    
  617.     //Decide which screens are dmap boundaries.
  618.    
  619.     //If the fortress is on one of these screens, return true.
  620. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×