ZoriaRPG

ZScript: Flying Fortress Alpha 0.1

May 20th, 2017
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int virtual_map[114]; //nine dmaps screen, x, y, left_bound, rightbound, topbound, bottombound* dmaps];
  2. const int DMAP1 = 0;
  3. const int DMAP_COLS = 12;
  4. //start ( dmap, start screen, screen_left, screen_right, screen_up, screen_down, dma_left, dmap_right, dmap_down, dmap_up, x, y ) * dmap count
  5. int virtualmap_dmap-connections[numdmaps];
  6.  
  7. //Call in init script to set up all the boundaries, dest screens, and so forth.
  8. void SetMapBound(int ptr, int type, int screen, bool wrapdmap, int wrapto){
  9.     //Set the screen that is the left most, and the screen on the right of the dmap to wrap into.
  10.     //If we are wrapping to another dmap, we need to know it.
  11.     if ( type == BOUND_LEFT ) {
  12.        
  13.         //We need to automatically set up wraps to dmaps using GetWrapDMap()
  14.        
  15.         ptr[FLF_MAP_BOUND_LEFT = screen; //the screen at which we start the wrap
  16.         ptr[FLF_MAP_BOUND_LEFT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  17.         if ( wrapdmap ) ptr[FLF_MAP_BOUND_LEFT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_LEFT); //the dmap on which we end the wrap.
  18.         ptr[FLF_X] = 255; //We wrapped left from x=0, so we wrap to x = 255.
  19.     }
  20.     if ( type == BOUND_RIGHT ) {
  21.         ptr[FLF_MAP_BOUND_RIGHT = screen; //the screen at which we start the wrap
  22.         ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  23.         if ( wrapdmap ) ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_RIGHT);  //the dmap on which we end the wrap.
  24.         ptr[FLF_X] = 0; //We wrapped left from x=255, so we wrap to x = 0.
  25.     }
  26.     if ( type == BOUND_UP ) {
  27.         ptr[FLF_MAP_BOUND_UP = screen; //the screen at which we start the wrap
  28.         ptr[FLF_MAP_BOUND_UP_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  29.         if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_UP_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_UP); //the dmap on which we end the wrap.
  30.         ptr[FLF_Y] = 175; //We wrapped left from y=0, so we wrap to Y = 175.
  31.     }
  32.     if ( type == BOUND_DOWN ) {
  33.         ptr[FLF_MAP_BOUND_DOWN = screen; //the screen at which we start the wrap
  34.         ptr[FLF_MAP_BOUND_DOWN_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
  35.         if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_DOWN_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_DOWN);  //the dmap on which we end the wrap.
  36.         ptr[FLF_Y] = 0; //We wrapped left from y=175, so we wrap to Y = 0.
  37.     }
  38. }
  39. /*
  40. int WrapDMap(int dmap){
  41.     int dmap = Game->GetCurDMap();
  42.    
  43.     //checck ths table to see if we are on the edge of a dmap and wrappinf to another one,
  44.     //if so, return its value
  45.     //otherwise, return the current dmap.
  46.    
  47.     int dmap1[128]={
  48.         0,0,0,0,0,0
  49. }
  50. */
  51. const int DMAP_COLS = 4; //Actual columns
  52. const int DMAP_ROWS = 4; //Actual rows
  53. int GetWrapDMap(int source, int dir){
  54.     int virtual_dmaps[ (4_dirs +1 )* NumDMaps] {
  55.        
  56.        
  57.         //Layout of the world by DMap IDs.
  58.        
  59.         0000
  60.         0000
  61.         0000
  62.         0000,
  63.        
  64.         //Left position from each
  65.        
  66.         3012
  67.         7456
  68.         11, 8910,
  69.         15, 12, 13, 14,
  70.        
  71.         //Right position from each
  72.        
  73.         1230
  74.         5674
  75.         910, 11, 8
  76.         13, 14, 15, 12,
  77.        
  78.         //Down position from each
  79.        
  80.         4567
  81.         8910, 11,
  82.         12, 13, 14, 15,
  83.         0123,
  84.        
  85.         //Up position from each
  86.        
  87.         12, 13, 14, 15,
  88.         0123
  89.         8910, 11,
  90.         78910,
  91.     }
  92.    
  93.     if ( dir == DIR_LEFT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*1)];
  94.     if ( dir == DIR_RIGHT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*2)];
  95.     if ( dir == DIR_DOWN ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*3)];
  96.     if ( dir == DIR_UP ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*4)];
  97.     return -1;//Error
  98. }
  99.  
  100. int Fortresses[27]; //tmer, dir, speed, x, y, dmap, screen
  101.  
  102. const int FORTRESS_TIMER = 0;
  103. const int FORTRESS_DIR = 1;
  104. const int FORTRESS_SPEED = 2;
  105. const int FORTRESS_X = 3;
  106. const int FORTRESS_Y = 4;
  107. const int FORTRESS_DMAP_ID = 5;
  108. const int FORTRESS_SCREEN_ID = 6;
  109. const int FORTRESS_DMAP_OFFSET = 7; // Multiply this * Fortress ID, then add element.
  110.  
  111. const int NUM_FORTRESSES = 9;
  112.  
  113. const int FORTRESS_MOVE_TMER_MIN = 120;
  114. const int FORTRESS_MOVE_TMER_MAX = 400;
  115.  
  116. const int FORTRESS_MOVE_DIST_MIN = 6;
  117. const int FORTRESS_MOVE_DIST_MAX = 14;
  118.  
  119. void SetFortressTimers(int ptr){
  120.     nt sz = SzeOfArray(ptr);
  121.     for ( int q = 0; q < sz; q += NUM_FORTRESSES )  ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX);
  122. }
  123. void DoFortressTmers(int ptr){
  124.     int sz = SizeOfArray(ptr);
  125.     for ( int q = 0; q < sz; q += NUM_FORTRESSES ) {
  126.         if ( ptr[q] <= 0 ) { MoveFortress(q); ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX); }
  127.         else ptr[q]--;
  128.     }
  129. }
  130.  
  131. int MoveFortressDir(int ptr) {
  132.     int dirs[4] = {UP, DOWN, LEFT, RIGHT};
  133.     int dir = dirs[Rand(0,4)]; //What about angles?
  134.     //
  135. }
  136.  
  137. //If our DMap is square, this part is easier.
  138. int virtual_maps[]={    0,  0x1F,    0,     0x1F,
  139.             0,  0x1F,    0,     0x1F,
  140.             0,  0x1F,    0,     0x1F,
  141.             0,  0x1F,    0,     0x1F,
  142.             0,  0x1F,    0,     0x1F,
  143.             0,  0x1F,    0,     0x1F,
  144.             0,  0x1F,    0,     0x1F,
  145.             0,  0x1F,    0,     0x1F,
  146.             0,  0x1F,    0,     0x1F,
  147.  
  148. }; //Topleft, Topright, BottomLeft, BottomRight Screen IDs
  149.  
  150.  
  151. //! THis function is Not finished
  152. //Boundary Screen?
  153. bool FortressAtDMapBoundary(int fortress_id, int virtual_map, int offset){
  154.    
  155.     //Map out the screens of this DMap.
  156.     int map[4];
  157.     for ( int q = 0; q < 3; q++ ) {
  158.         map[q] = virtual_map[(offset*4)+q];
  159.     }
  160.    
  161.     int edges[4];
  162.    
  163.     if ( FortressScreen(fortress_id) % map[0] == 0 ) edges[0] = 1; //on left side of dmap. //Will this work of the DMap has an offset???
  164.    
  165.     //Decide which screens are dmap boundaries.
  166.    
  167.     //If the fortress is on one of these screens, return true.
  168. }
  169.  
  170.  
  171. //! Let's hardcode some DMAPS! Z
  172.  
  173. const int FF_DMAP_SCREEN_VALID = 0;
  174. const int FF_DMAP_SCREEN_INVALID = -1;
  175. const int FF_DMAP_SCREEN_BOUNDARY = 1; //1 or higher is a screen boundary.
  176.  
  177. //A virtual DMap. 0s are empty space, 1s are screens, 2s are boundaries.
  178. //Should each edge and corner be a unique value
  179.  
  180. /*
  181. -1 empty space
  182. 0 has sceens on each side
  183.  
  184. 1 cannot turn up
  185. 2 cannot turn down
  186. 4 cannot turn right
  187. 8 cannot turn up
  188.  
  189.  
  190. */
  191. const int NOT_VALID_SCREEN = -1;
  192. const int CANNOT_TURN_UP = 1;
  193. const int CANNOT_TURN_DOWN = 2;
  194. const int CANNOT_TURN_RIGHT = 4;
  195. const int CANNOT_TURN_LEFT = 8;
  196.  
  197. //A virtual map with the edges marked.
  198. int virtual_map_1[]={
  199.     9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
  200.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  201.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  202.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  203.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  204.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  205.     8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
  206.     10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6 }
  207.    
  208. //Determines a random, legal directions, based on values on a vritual map.
  209. int FindLegalTurn(int virtual_map, int screen){
  210.     if ( virtual_map[screen] == 1 ) {  //cannot turn up
  211.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_DOWN) );
  212.     }
  213.     if ( virtual_map[screen] == 2 ) { //cannot tuen down
  214.         return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_UP) );
  215.     }
  216.     if ( virtual_map[screen] == 4 ) { //cannot turn right
  217.         return ( Choose(DIR_LEFT, DIR_DOWN, DIR_UP) );
  218.     }
  219.     if ( virtual_map[screen] == 5 ) { //cannot turn up or right
  220.         return ( Choose(DIR_DOWN, DIR_LEFT) );
  221.     }
  222.     if ( virtual_map[screen] == 6 ) { //cannot turn down or right
  223.         return ( Choose(DIR_UP, DIR_LEFT) );
  224.     }
  225.     if ( virtual_map[screen] == 8 ) { //cannot turn left
  226.         return ( Choose(DIR_RIGHT, DIR_DOWN, DIR_UP) );
  227.     }
  228.     if ( virtual_map[screen] == 9 ) { //cannot turn left or up
  229.         return ( Choose(DIR_RIGHT, DIR_DOWN) );
  230.     }
  231.     if ( virtual_map[screen] == 10 ) { //cannot turn left or down
  232.         return ( Choose(DIR_RIGHT, DIR_UP) );
  233.     }
  234.     return Rand(0,3); //Otherwise, return a random direction.
  235. }
  236.  
  237.  
  238. int virtual_map_0[]={
  239.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  240.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  241.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  242.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  243.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  244.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  245.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  246.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
  247.    
  248.  
  249. //Edge of Boundary Screen
  250. bool FortressAtDMapEdge(int virtual_map){
  251.    
  252.    
  253.    
  254. }
  255.  
  256. const int FORTRESS_WIDTH = 8;  //Sprite dimensions.
  257. const int FORTRESS_HEIGHT = 8;
  258. const int FORTRESS_Z_LOCATION = 100; //must match this Z to enter.
  259.  
  260. bool FortressAtScreenEdge(int fortress_id, int dir){
  261.     if ( dir == DIR_LEFT && FottressX(fortress_id) <= 0+FORTRESS_WIDTH ) return true;
  262.     if ( dir == DIR_RIGHT && FortressX(fortress_id) >= 256 ) return true;
  263.     if ( dir == DIR_UP && FortressY(fortress_id)+FORTRESS_HEIGHT < 0 ) return true;
  264.     if ( dir == DIR_DOWN && FortrwessY(fortress_id) >= 176 ) return true;
  265.     return false;
  266. }
  267.  
  268. bool TurnFortress(int fortress_id) {
  269.     if ( ( FortressAtScreenEdge(fortres_id), FortressDir(fortress_id) ) || FortressTimer(fortress_id) <= 0 ) {
  270.         //Choose a direction other than the present diretion.
  271.         int dir;
  272.         do { //Pick a random direction that differs from this direction.
  273.             dir = Rand(0,7);
  274.         } while ( dir != FortressDir(fortress_id);
  275.         FortressDir(fortress_id, dir); //Change the direction.
  276.     }
  277. }
  278.        
  279.    
  280.  
  281. int FortressX(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X]; }
  282. int FortressY(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y]; }
  283.  
  284. int FortressDir(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR]; }
  285. int FortressSpeed(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED]; }
  286. int FortressDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID]; }
  287. int FortressScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID]; }
  288. int FortressTimer(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
  289.  
  290.  
  291. void FortressX(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X] = VBound(v,0,255); }
  292. void FortressY(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
  293.  
  294. void FortressDir(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR] = VBound(v,0,7); }
  295. void FortressSpeed(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED] = Abs(v); }
  296. void FortressDMap(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID] = v; }
  297. void FortressScreen(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID] = VBound(v,0,255); }
  298. void FortressTimer(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = Abs(v); }
  299.  
  300.  
  301. //Set the turn timer.
  302. int FortressTime(int time_min, time_max, int frac_time, int frac_max){
  303.     int t = Rand(time_min,time_max); int tt = (Rand(frac_time, frac_max) / 1000);
  304.     Return (t+tt)*60;
  305. }
  306.  
  307. int MoveForetressSpeed()
  308.  
  309. void MoveFortress(int ptr){
  310.     int distx = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
  311.     int disty = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
  312.     bool neg = RandB();
  313.     if ( neg )
  314.     //Avoid jiter somehow?
  315. }
  316.    
  317. void MoveFortress(int id)}
  318.  
  319. const int FLF_MAP_
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.

×