home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / structinit.c < prev    next >
C/C++ Source or Header  |  2009-05-18  |  9KB  |  449 lines

  1. #include <exec/types.h>
  2. #include <h/rot.h>
  3. #include <h/extern.h>
  4.  
  5. initboxes()
  6. {
  7. LONG x;
  8. for (x=0;x<control.boxnum;x++) b[x].length = 0;
  9. }
  10.  
  11. inittokenexplosions()
  12. {
  13. LONG x;
  14. for (x=0;x<control.explosionnum;x++) e[x].flag = FALSE;
  15. }
  16.  
  17.  
  18. initbattleshipfighter(n)
  19. LONG n;
  20. {
  21. LONG x,num=-1;
  22.  
  23. for (x=0;x<control.ftrnum;x++)
  24.     if (f[x].flight == FALSE)
  25.         {
  26.         num = x;
  27.         break;
  28.         }
  29.  
  30. if (num!=-1)
  31.     {
  32.     f[num].x = bs[n].x + id[bs[n].image+bs[n].pos].wi/2;
  33.     f[num].y = bs[n].y + id[bs[n].image+bs[n].pos].he/2;
  34.     f[num].ax = Random(60.0)-30;
  35.     f[num].ay = Random(48.0)-24;
  36.     f[num].vmax = 3;
  37.     f[num].pos = Random(31.0);
  38.     f[num].flight = TRUE;
  39.  
  40.     if ((Random(100.0) > 50) && (control.playernum > 1)) f[num].aim   = 1;
  41.     else                                           f[num].aim   = 0;
  42.     }
  43. }
  44.  
  45.  
  46. initfighters()
  47. {
  48. LONG xx,yy,x;
  49.  
  50. for (x=0;x<control.ftrnum;x++)
  51.     {
  52.     xx = gi.x1 + Random((DOUBLE)gi.dx);
  53.     yy = gi.y1 + Random((DOUBLE)gi.dy);
  54.  
  55.     f[x].x = xx;
  56.     f[x].y = yy;
  57.     f[x].ax = Random(60.0)-30;
  58.     f[x].ay = Random(48.0)-24;
  59.     f[x].vmax = 3;
  60.     f[x].pos = Random(31.0);
  61.     f[x].flight = TRUE;
  62.  
  63.     if ((Random(100.0) > 50) && (control.playernum > 1)) f[x].aim   = 1;
  64.     else                                           f[x].aim   = 0;
  65.     }
  66. }
  67.  
  68.  
  69. initsaucer()
  70. {
  71. LONG random;
  72.  
  73. random = Random(100.0);
  74. if (random > 30)
  75.     {
  76.     saucer.type = 0;
  77.     saucer.image = il.saucer;
  78.     }
  79. else
  80.     {
  81.     saucer.type = 1;
  82.     saucer.image = il.asaucer;
  83.     }
  84.  
  85. random = Random(100.0);
  86. if (random > 50)
  87.     {
  88.     saucer.x     = gi.x1;
  89.     saucer.y     = gi.y1+Random((DOUBLE)gi.dy);
  90.     saucer.vx    = 4;
  91.     }
  92. else
  93.     {
  94.     saucer.x     = gi.x2;
  95.     saucer.y     = gi.y1+Random((DOUBLE)gi.dy);
  96.     saucer.vx    = -4;
  97.     }
  98.  
  99. saucer.delay = Random(50.0);
  100. saucer.vy    = 0;
  101. saucer.flag  = TRUE;
  102. saucer.rot = 0;
  103. saucer.fnum = 10;
  104. saucer.haltfire = FALSE;
  105. }
  106.  
  107. initBattleship(n)
  108. LONG n;
  109. {
  110. LONG x;
  111.  
  112. bs[n].x     = 300;
  113. bs[n].y     = 200;
  114. bs[n].pos   = 8;
  115.  
  116. bs[n].fx     = gi.x1 + Random(500.0) + 50;
  117. bs[n].fy     = gi.y1 + Random(240.0) + 30;
  118.  
  119. bs[n].vx    = 0;
  120. bs[n].vy    = 0;
  121. bs[n].shield=1000;
  122. bs[n].vmax =  1;
  123.  
  124. bs[n].man  =  3;
  125. bs[n].turn  =  0;
  126.  
  127. bs[n].fnum = 20;
  128. bs[n].fvmax=  10;
  129. bs[n].fdam =  10;
  130. bs[n].ftype=   0;
  131.  
  132. bs[n].pnum = 20;
  133. bs[n].pvmax=  10;
  134. bs[n].pdam =  30;
  135. bs[n].prange = 35;
  136. bs[n].pdelay = 300;
  137. bs[n].pman   = 4;
  138.  
  139. bs[n].dnum = 2;
  140.  
  141. bs[n].image = il.battleship;
  142. bs[n].flight = TRUE;
  143.  
  144. bs[n].lbox = TRUE;
  145. bs[n].rbox = TRUE;
  146. bs[n].line = TRUE;
  147.  
  148. for (x=0;x<bs[n].dnum;x++)
  149.     bs[n].fdelay[x] = -1;
  150. }
  151.  
  152.  
  153. initPlayer(n)
  154. LONG n;
  155. {
  156. LONG x;
  157.  
  158. ship[n].x     = gi.wi/2-10+20*n;
  159. ship[n].y     = gi.he/2-20;
  160. ship[n].modx  = 0;
  161. ship[n].mody  = 0;
  162. ship[n].pos   = 0;
  163. ship[n].vx    = 0;
  164. ship[n].vy    = 0;
  165. ship[n].shield=control.shield[n];
  166. ship[n].vmax =  6;
  167. ship[n].man  =  0;
  168.  
  169. ship[n].fnum = 20;
  170. ship[n].fvmax=  12;
  171. ship[n].fdam =  20;
  172. ship[n].flen =  10;
  173. ship[n].ftype=   0;
  174.  
  175. ship[n].pnum = 20;
  176. ship[n].pvmax=  10;
  177. ship[n].pdam =  30;
  178. ship[n].prange = 35;
  179. ship[n].pdelay = 300;
  180. ship[n].pman   = 4;
  181.  
  182. ship[n].blast = 0;
  183. ship[n].aim   = 1;
  184. ship[n].pilot = HUMAN;
  185. ship[n].pointvalue= 1000;
  186.  
  187. if (n == 0) ship[n].image  =  il.player;
  188. else          ship[n].image  =  il.player2;
  189.  
  190. ship[n].shIno  =  il.shield; /* shield image number */
  191.  
  192. for (x=0;x<control.thrustlength;x++) 
  193.     {
  194.     ship[n].exhlx[x]=0;
  195.     ship[n].exhly[x]=0;
  196.     ship[n].exhrx[x]=0;
  197.     ship[n].exhry[x]=0;
  198.     ship[n].exhd[x]=-1;
  199.     }
  200.  
  201. ship[n].shieldstat = NULL;
  202. }
  203.  
  204. initAsteroids()
  205. {
  206. LONG x;
  207. LONG vx,vy;
  208.  
  209. for(x=0;x<256;x++) a[x].flag = FALSE;
  210.  
  211. for (x=0;x<control.asteroidnum/4;x++)
  212.     {
  213.     a[x].flag = TRUE;
  214.     a[x].size = 0;
  215.     }
  216.  
  217. for (x=0;x<control.asteroidnum/4;x++)
  218.     {
  219.     a[x].x = 2*gi.x1 + Random((DOUBLE)gi.dx);
  220.     a[x].y = gi.y1   + Random((DOUBLE)gi.dy);
  221.     if (Random(100.0) > 50)     a[x].dir = 1;
  222.     else                    a[x].dir = -1;
  223.  
  224.     vx = vy = 0;
  225.     while ((vx == 0) && (vy == 0))
  226.         {
  227.         vx= Random(4.0)-2;
  228.         vy= Random(4.0)-2;
  229.         }
  230.     a[x].vx = vx;
  231.     a[x].vy = vy;
  232.     }
  233. }
  234.  
  235.  
  236. initfirestructures(num)
  237. LONG num;
  238. {
  239. LONG x;
  240.  
  241. for (x=0;x<40;x++)
  242.     ship[num].shotI[x].flight = FALSE;
  243.  
  244. for (x=0;x<40;x++)
  245.     ship[num].photI[x].flight = FALSE;
  246. }
  247.  
  248. initenemy(x)
  249. LONG x;
  250. {
  251. ship[x].x = gi.x1+Random((DOUBLE)gi.dx);
  252. ship[x].y = gi.y1+Random((DOUBLE)gi.dy);
  253. ship[x].pos   = Random(31.0);
  254. ship[x].vx    = 0;
  255. ship[x].vy    = 0;
  256. ship[x].blast = 0;
  257. ship[x].pilot = COMPUTER;
  258. ship[x].shieldstat = NULL;
  259. ship[x].fdelay=   0;
  260. ship[x].pdelay =  0;
  261.  
  262. if ((Random(100.0) > 50) && (control.playernum > 1)) ship[x].aim   = 1;
  263. else
  264. ship[x].aim   = 0;
  265. }
  266.  
  267. setenemy(x,type)
  268. LONG x,type;
  269. {
  270.  
  271. initenemy(x);
  272.  
  273. if (type == 1) /* light cruiser */
  274.     {
  275.     ship[x].vmax =   3;
  276.     ship[x].man  =   1;
  277.     ship[x].fnum =   3;
  278.     ship[x].fvmax=   8;
  279.     ship[x].fdam =  20;
  280.     ship[x].flen =   5;
  281.     ship[x].ftype=   0;
  282.     ship[x].frate=   8;
  283.     ship[x].pnum =   1;
  284.     ship[x].pvmax=   8;
  285.     ship[x].pdam =  30;
  286.     ship[x].prange =  150;
  287.     ship[x].pdelay =  400;
  288.     ship[x].pman   =  5;
  289.     ship[x].pimage =  il.photon+1;
  290.     ship[x].image  =  il.elight;
  291.     ship[x].shIno  =  il.shield;
  292.     ship[x].shield=100;
  293.     ship[x].pointvalue= 1000;
  294.     }
  295. else
  296. if (type == 2) /* heavy cruiser */
  297.     {
  298.     ship[x].vmax =   4; /* maximum velocity */
  299.     ship[x].man  =   3; /* maneuverability */
  300.     ship[x].fnum =   5; /* fire number */
  301.     ship[x].fvmax=   8; /* fire velocity */
  302.     ship[x].fdam =  20; /* fire damage */
  303.     ship[x].flen =   8; /* fire length */
  304.     ship[x].ftype=   2; /* fire type   0=fwd  1=360  2=360+side */
  305.     ship[x].frate=   4;
  306.     ship[x].pnum =   2; /* seeking number */
  307.     ship[x].pvmax=   8; /* seeking velocity */
  308.     ship[x].pdam =  30; /* seeking damage */
  309.     ship[x].prange =  150; /* seeking range */
  310.     ship[x].pdelay =  400; /* seeking delay */
  311.     ship[x].pman   =  5; /* seeking maneuverabilty */
  312.     ship[x].pimage =  il.photon+1;
  313.     ship[x].image  =  il.eheavy; /* ship image number */
  314.     ship[x].shIno  =  il.shield; /* shield image number */
  315.     ship[x].shield=200;
  316.     ship[x].pointvalue= 2000;
  317.     }
  318. else
  319. if (type == 3)        /* x-cruiser */
  320.     {
  321.     ship[x].vmax =   5;
  322.     ship[x].man  =   1;
  323.     ship[x].fnum =  10;
  324.     ship[x].fvmax=   8;
  325.     ship[x].fdam =  20;
  326.     ship[x].flen =   8;
  327.     ship[x].ftype=   0;
  328.     ship[x].frate=   4;
  329.     ship[x].pnum =   3;
  330.     ship[x].pvmax=  12;
  331.     ship[x].pdam =  30;
  332.     ship[x].prange = 30;
  333.     ship[x].prate =  32;
  334.     ship[x].pman   =  4;
  335.     ship[x].pimage =  il.photon+1;
  336.     ship[x].image  =  il.xcruiser;
  337.     ship[x].shIno  =  il.shield;
  338.     ship[x].shield =150;
  339.     ship[x].pointvalue= 3500;
  340.     }
  341. else
  342. if (type == 4)        /* MINELAYER */
  343.     {
  344.     ship[x].vmax =   3; /* maximum velocity */
  345.     ship[x].man  =   2; /* maneuverability */
  346.     ship[x].fnum =   1; /* fire number */
  347.     ship[x].fvmax=   8; /* fire velocity */
  348.     ship[x].fdam =  10; /* fire damage */
  349.     ship[x].flen =   8; /* fire length */
  350.     ship[x].ftype=   0; /* fire type   0=fwd  1=360 */
  351.     ship[x].pnum =   10; /* seeking number */
  352.     ship[x].pimage =  il.photon+1;
  353.     ship[x].image  =  il.minelayer; /* ship image number */
  354.     ship[x].shIno  =  il.shield; /* shield image number */
  355.     ship[x].shield = 50;
  356.     ship[x].pointvalue= 500;
  357.     }
  358. else
  359. if (type == 5)        /* dreadnought */
  360.     {
  361.     ship[x].vmax =   5; /* maximum velocity */
  362.     ship[x].man  =   3; /* maneuverability */
  363.     ship[x].fnum =   0; /* fire number */
  364.     ship[x].fvmax=   8; /* fire velocity */
  365.     ship[x].fdam =  20; /* fire damage */
  366.     ship[x].flen =   8; /* fire length */
  367.     ship[x].ftype=   0; /* fire type   0=fwd  1=360 */
  368.     ship[x].frate=   10;
  369.     ship[x].pnum =   14;
  370.     ship[x].pvmax=  10;
  371.     ship[x].pdam =  30;
  372.     ship[x].prange =  30; /* seeking range */
  373.     ship[x].pdelay =  400; /* seeking delay */
  374.     ship[x].pman   =  4; /* seeking maneuverabilty */
  375.     ship[x].pimage =  il.expander;
  376.     ship[x].image  =  il.dreadnought; /* ship image number */
  377.     ship[x].shIno  =  il.dreadshield; /* shield image number */
  378.     ship[x].shield =250;
  379.     ship[x].pointvalue= 4000;
  380.     }
  381. else
  382. if (type == 6)        /* m-cruiser */
  383.     {
  384.     ship[x].vmax =   4; /* maximum velocity */
  385.     ship[x].man  =   2; /* maneuverability */
  386.     ship[x].fnum =   4; /* fire number */
  387.     ship[x].fvmax=   8; /* fire velocity */
  388.     ship[x].fdam =  20; /* fire damage */
  389.     ship[x].flen =   8; /* fire length */
  390.     ship[x].ftype=   0; /* fire type   0=fwd  1=360 */
  391.     ship[x].frate=   3;
  392.     ship[x].pnum =   2; /* seeking number */
  393.     ship[x].pvmax=  10; /* seeking velocity */
  394.     ship[x].pdam =  30; /* seeking damage */
  395.     ship[x].prange =  150; /* seeking range */
  396.     ship[x].pdelay =  400; /* seeking delay */
  397.     ship[x].pman   =  4; /* seeking maneuverabilty */
  398.     ship[x].pimage =  il.photon+1;
  399.     ship[x].image  =  il.magnetic; /* ship image number */
  400.     ship[x].shIno  =  il.shield; /* shield image number */
  401.     ship[x].shield =100;
  402.     ship[x].pointvalue= 2000;
  403.     }
  404.  
  405.  
  406. }
  407.  
  408. addenemy()
  409. {
  410. LONG x,xx,num=-1;
  411. LONG r1,r2,type;
  412.  
  413.  
  414. for(x=0;x<control.maxenemynum;x++)
  415.     {
  416.     xx = control.playernum+x;
  417.     if ((ship[xx].pilot == DESTROYED) && (ship[xx].wait == 0))
  418.         {
  419.         num = xx;
  420.         break;
  421.         }
  422.     }
  423.  
  424. if (num != -1)
  425.     {
  426.     makesound(7,3);
  427.  
  428.     r1 = Random(100.0);
  429.     r2 = Random(100.0);
  430.  
  431.     if (r1 < 100-4*control.level)
  432.         {
  433.         if (r2 < 40-control.level) type = 1; /* light cruiser */
  434.         else
  435.         if (r2 < 80-control.level) type = 4; /* minelayer */
  436.         else                      type = 2; /* heavy cruiser */
  437.         }
  438.     else
  439.         {
  440.         if (r2 < 40) type = 3; /* x-cruiser */
  441.         else
  442.         if (r2 < 70) type = 5; /* dreadnought */
  443.         else           type = 6; /* m-cruiser */
  444.         }
  445.     control.enemynum++;
  446.     setenemy(num,type);
  447.     }
  448. }
  449.