home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / sgi / 18206 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  58.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!uoft02.utoledo.edu!ssubram2
  2. From: ssubram2@uoft02.utoledo.edu
  3. Newsgroups: comp.sys.sgi
  4. Subject: Repost of : A 3-d game for SGI's
  5. Message-ID: <1992Dec18.162646.557@uoft02.utoledo.edu>
  6. Date: 18 Dec 92 16:26:46 EST
  7. Organization: University of Toledo, Computer Services
  8. Lines: 2338
  9.  
  10.  
  11.  
  12. Hi !
  13.  
  14. This is a repost of the 3-d game that I had posted sometime back.
  15. There were some changes that had to be made for m/c's running
  16. IRIX 4.0+
  17.  
  18. This version I'm posting is for X based IRIX 4.0+ m/c's.
  19. There are some compiling instructions at the top of file
  20. vr1.c
  21.  
  22. send all comments/flames to :
  23. ssubrama@jupiter.cse.utoledo.edu
  24.  
  25. /Srikanth Subramanian
  26.  
  27. -------------------------------------------------------------------
  28. Game description :
  29. ------------------
  30. You are in a ship with lot of "enemies" around who fire at you and
  31. whom you have to destroy.  (simple, isn't it ? :)
  32. Game gets over if you collide with a wall or ship damage is 100%
  33. or fuel or torpedos runneth out.
  34.  
  35. Types of enemies :
  36. (1) Ordinary : Dull boring enemies who die on the first shot
  37. (2) Tough    : Change color when hit and move faster and make life
  38.                miserable for you.
  39. (3) Cloaked  : these don't show up unless you are holding down the
  40.                cloak detector button.
  41. (4) Cloaked and tough : Really painful enemies.
  42.  
  43. Game controls :
  44.  
  45. ship movement :
  46. --------------
  47. S key : increase forward ship thrust
  48. A key : increase backward ship thrust
  49. Z key : full brakes .. ship halt
  50.  
  51. ship direction :
  52. ---------------
  53. Leftarrow, Rightarrow : Turn ship left, rite
  54. Uparrow, Downarrow    :    Turn ship up, down
  55. Comma, Period         : Turn ship's "UP vector"
  56. PADENTER              : increase ship's rotation step
  57. PAD0                  : decrease ship's rotation step
  58.  
  59. weapons :
  60. --------
  61. Spacebar : Fire torpedo or laser guided missile (according
  62.            to context)
  63. T key    : Target enemy (toggle) which is completely inside 
  64.            the targeting brackets. (enemy changes color to CYAN 
  65.            to show that it has been targeted). Once targeted,
  66.            you can destroy that enemy whenever you want (with space
  67.            bar) and you need not even be looking at him.
  68.  
  69. Misc :
  70. -----
  71. D key : Turn on cloak detector (uses up lots of fuel)
  72. C key : Toggle crosswire (who would want to turn off the crosswire ?)
  73. Esc   : Exit
  74.  
  75. An on-board "flight computer" informs you of most things.
  76.  
  77.  
  78. Playing hints : 
  79. ------------
  80. If you ever halt the ship you are a sitting duck
  81. for the enemy so always keep moving. To kill very fast enemies
  82. you might have to use the laser targeting instrument (T key) and 
  83. then fire ... but laser guided missiles are very few.
  84.  
  85. When you are approaching a wall at moderate speeds, 
  86. you will have to increase the ship's rotation speed and turn in order
  87. to avoid hitting the wall. But a high rotation speed will hinder
  88. your enemy targeting capacity so decrease rotation speed as soon as
  89. you turn away from the wall. (PAD0,PADENTER)
  90.  
  91.  
  92. Program follows :
  93.  
  94. --------------CUT HERE--------------------------------------------
  95. #!/bin/sh
  96. # shar:    Shell Archiver  (v1.22)
  97. #
  98. #    Run the following text with /bin/sh to create:
  99. #      vector.h
  100. #      vr.h
  101. #      vr1.c
  102. #
  103. sed 's/^X//' << 'SHAR_EOF' > vector.h &&
  104. X/*
  105. X::::::::::::::
  106. Xvector.h for VR
  107. X::::::::::::::
  108. X*/
  109. X
  110. X#include <stdio.h>
  111. X#include <math.h>
  112. X#include <gl/gl.h>
  113. X#include <gl/device.h>
  114. X
  115. X#define   NN(x)     (((x) < 0) ?   0  : (x) )
  116. X#define   ABS(x)    (((x) < 0) ? -(x) : (x) ) 
  117. X#define   SQR(x)    ((x)*(x))
  118. X#define   SQRT(x)   ((float)(sqrt((double)(x))))
  119. X#define   COS(x)    ((float)(cos((double)(x))))
  120. X#define   ACOS(x)   ((float)(acos((double)(x))))
  121. X#define   SIN(x)    ((float)(sin((double)(x))))
  122. X#define   POW(x,y)  ((float)(pow((double)(x),(double)(y))))
  123. X#define   ATAN(x)   ((float)(atan((double)(x))))
  124. X#define   TAN(x)    ((float)(tan((double)(x))))
  125. X#define   ZERO(x)   ((ABS(x)<1.0e-10)?1:0)
  126. X
  127. X#define    EPSILON   (1.0e-6)
  128. X
  129. X/* Vector type  --- any point repr. as PV */
  130. Xtypedef struct {
  131. X   float x,y,z   ;
  132. X}  VEC           ;
  133. X
  134. X
  135. X/* Vector type used by GL : */
  136. Xtypedef float  VEC3[3] ; 
  137. X
  138. X
  139. X/* Modulus and Dot Product defs */
  140. X#define mod(a)      SQRT(a.x*a.x + a.y*a.y + a.z*a.z)
  141. X#define dot_p(a,b)  (a.x*b.x + a.y*b.y + a.z*b.z)
  142. X
  143. X/* Cross product :  c = a x b   */
  144. X#define cross_p(a,b,c)       {                   \
  145. X   c.x = (a.y*b.z - b.y*a.z) ;                   \
  146. X   c.y = (b.x*a.z - a.x*b.z) ;                   \
  147. X   c.z = (a.x*b.y - b.x*a.y) ;                   \
  148. X} 
  149. X
  150. X/* Cos(theta) where theta is the angle between vects. a,b */
  151. X#define cos_thet(a,b)  (dot_p(a,b)/(mod(a)*mod(b)))
  152. X
  153. X/* Distance between two position vectors */
  154. X#define   DIST(a,b) SQRT(SQR(a.x-b.x)+SQR(a.y-b.y)+SQR(a.z-b.z))
  155. X
  156. X/* A fast matrix multiplication def for (3x3)(3x1) mult */
  157. X#define mat_mul(a,b,c) { \
  158. X   c[0] = a[0][0]*b[0] + a[0][1]*b[1] + a[0][2]*b[2] ; \
  159. X   c[1] = a[1][0]*b[0] + a[1][1]*b[1] + a[1][2]*b[2] ; \
  160. X   c[2] = a[2][0]*b[0] + a[2][1]*b[1] + a[2][2]*b[2] ; \
  161. X}
  162. X
  163. X
  164. X/* Some simple vec operations */
  165. X
  166. X#define    NORM(vec)                {            \
  167. X           float  md = mod(vec)     ;            \
  168. X           if (md>EPSILON) {                     \
  169. X              vec.x    /= md           ;         \
  170. X              vec.y    /= md           ;         \
  171. X              vec.z    /= md           ;         \
  172. X           }                                     \
  173. X}
  174. X
  175. X#define    REVERSE_VEC(vec)         {            \
  176. X           vec.x = -vec.x           ;            \
  177. X           vec.y = -vec.y           ;            \
  178. X           vec.z = -vec.z           ;            \
  179. X}
  180. X
  181. X
  182. X#define    INIT_VEC(pvdest,xi,yi,zi)  {  \
  183. X           pvdest.x = xi      ;          \
  184. X           pvdest.y = yi      ;          \
  185. X           pvdest.z = zi      ;          \
  186. X}
  187. X           
  188. X   
  189. X#define    COPY_VEC(pvdest,pvsource)  {          \
  190. X           pvdest.x = pvsource.x      ;          \
  191. X           pvdest.y = pvsource.y      ;          \
  192. X           pvdest.z = pvsource.z      ;          \
  193. X}
  194. X
  195. X
  196. X#define    COPY_VEC3(pvdest,pvsource) {          \
  197. X           pvdest[0] = pvsource[0]    ;          \
  198. X           pvdest[1] = pvsource[1]    ;          \
  199. X           pvdest[2] = pvsource[2]    ;          \
  200. X}
  201. X
  202. X
  203. X#define    ADD_VEC(pvdest,pvsource)  {          \
  204. X           pvdest.x += pvsource.x      ;        \
  205. X           pvdest.y += pvsource.y      ;        \
  206. X           pvdest.z += pvsource.z      ;        \
  207. X}
  208. X
  209. X
  210. X#define    SCALE_VEC(pvdest,pvsource,sc)  {     \
  211. X           pvdest.x = sc*pvsource.x      ;      \
  212. X           pvdest.y = sc*pvsource.y      ;      \
  213. X           pvdest.z = sc*pvsource.z      ;      \
  214. X}
  215. X
  216. X
  217. X/* Given two pv's get the vec */
  218. X#define    GET_VEC(pvto,pvfrom,vec)   {      \
  219. X           vec.x  = pvto.x - pvfrom.x ;      \
  220. X           vec.y  = pvto.y - pvfrom.y ;      \
  221. X           vec.z  = pvto.z - pvfrom.z ;      \
  222. X}
  223. X
  224. X#define    VEC3TOVEC(vec,vec3)        {      \
  225. X           vec.x = vec3[0]            ;      \
  226. X           vec.y = vec3[1]            ;      \
  227. X           vec.z = vec3[2]            ;      \
  228. X}
  229. X
  230. X#define    VECTOVEC3(vec3,vec)        {      \
  231. X            vec3[0] = vec.x           ;      \
  232. X            vec3[1] = vec.y           ;      \
  233. X            vec3[2] = vec.z           ;      \
  234. X}
  235. X
  236. X
  237. X/* 
  238. X   REFL_RAY calculates the reflected ray direction at a point given
  239. X   the incident ray direction, the point of incidence and the normal to 
  240. X   the surface at that point. 
  241. X   The reflected ray direction is stored in a var passed as the 
  242. X   last parm to the macro.
  243. X   Note : All input directions and dir output by the macro are
  244. X   taken to be in the outward direction from the point of incidence.
  245. X */
  246. X
  247. X#define    REFL_RAY(indir,sp,un,outdir)   {      \
  248. X           float  ct              ;              \
  249. X           VEC    pn, pi, pr, pin ;              \
  250. X                                                 \
  251. X           pn.x = sp.x + un.x ;                  \
  252. X           pn.y = sp.y + un.y ;                  \
  253. X           pn.z = sp.z + un.z ;                  \
  254. X                                                 \
  255. X           pi.x = sp.x + indir.x ;               \
  256. X           pi.y = sp.y + indir.y ;               \
  257. X           pi.z = sp.z + indir.z ;               \
  258. X                                                 \
  259. X           ct =  cos_thet ( indir, un ) ;        \
  260. X                                                 \
  261. X           pin.x =  sp.x + un.x*ct ;             \
  262. X           pin.y =  sp.y + un.y*ct ;             \
  263. X           pin.z =  sp.z + un.z*ct ;             \
  264. X                                                 \
  265. X           pr.x  =  pin.x + (pin.x-pi.x) ;       \
  266. X           pr.y  =  pin.y + (pin.y-pi.y) ;       \
  267. X           pr.z  =  pin.z + (pin.z-pi.z) ;       \
  268. X                                                 \
  269. X           outdir.x = pr.x - sp.x ;              \
  270. X           outdir.y = pr.y - sp.y ;              \
  271. X           outdir.z = pr.z - sp.z ;              \
  272. X           NORM ( outdir )        ;              \
  273. X}
  274. X
  275. X
  276. X#define    MED_RAY(dir1,dir2,sp,outdir)   {      \
  277. X           VEC    p1, p2, pm ;                   \
  278. X                                                 \
  279. X           COPY_VEC ( p1, sp ) ;                 \
  280. X           COPY_VEC ( p2, sp ) ;                 \
  281. X                                                 \
  282. X           ADD_VEC  ( p1, dir1 ) ;               \
  283. X           ADD_VEC  ( p2, dir2 ) ;               \
  284. X                                                 \
  285. X           pm.x = (p1.x + p2.x)/2 ;              \
  286. X           pm.y = (p1.y + p2.y)/2 ;              \
  287. X           pm.z = (p1.z + p2.z)/2 ;              \
  288. X                                                 \
  289. X           outdir.x = pm.x - sp.x ;              \
  290. X           outdir.y = pm.y - sp.y ;              \
  291. X           outdir.z = pm.z - sp.z ;              \
  292. X           NORM ( outdir )        ;              \
  293. X}
  294. X
  295. X
  296. SHAR_EOF
  297. chmod 0600 vector.h || echo "restore of vector.h fails"
  298. sed 's/^X//' << 'SHAR_EOF' > vr.h &&
  299. X/* VR configuration :
  300. X * The Virtual world setup.
  301. X * Sizes and speeds are in virtual world scale units.
  302. X */
  303. X
  304. X#define ON    1
  305. X#define OFF   0
  306. X
  307. X/* Some color defs : these are dependent on the default
  308. X * color map (can be obtained by a "makemap")
  309. X */
  310. X#define WORLDBGCOLOR BLACK
  311. X#define PANELBGCOLOR 35
  312. X#define PANELTHRCOLOR   138
  313. X#define PANELROTCOLOR   59
  314. X#define PANELFUECOLOR   138
  315. X#define PANELTORCOLOR   138
  316. X#define PANELDAMCOLOR   RED
  317. X
  318. X/* World limits */
  319. X#define CUBEMAX   10000.0
  320. X#define CUBEMIN   (-CUBEMAX)
  321. X#define WORLDDIVS 21
  322. X
  323. X#define SHIPSIZ   500
  324. X
  325. X/* Ship's maximum forward, reverse and step thrust */
  326. X#define MAXTHRUST  500.0
  327. X#define STEPTHRUST 5.0
  328. X
  329. X/* Ship's maximum and minimum rotation speeds 
  330. X * (in 10'ths of degrees ie. GL "Angle" type values) 
  331. X */
  332. X#define MAXROT    450
  333. X#define MINROT    10
  334. X
  335. X/* Initial Fuel */
  336. X#define MAXFUEL 600000.0
  337. X
  338. X/* Phaser torpedos and tracking laser info in ship */
  339. X#define MAXTORP  800
  340. X/* Maximum no. of phaser torpedos firable at any given time */
  341. X#define MAXTORPFIRE   30
  342. X
  343. X#define TORPSPEED 600.0
  344. X#define TORPLEN   1000.0
  345. X#define MAXTRACKERS  5
  346. X
  347. X/* Explosion size */
  348. X#define EXPSIZ    200.0
  349. X
  350. X/* Enemy definitions */
  351. X#define MAXENEM   20
  352. X#define ENEMSIZ   500
  353. X#define ENEMSPEED  100
  354. X#define ENEMMISSPEED  1000.0
  355. X#define TOUGHENEMSPEEDFACT 1.5
  356. X
  357. SHAR_EOF
  358. chmod 0600 vr.h || echo "restore of vr.h fails"
  359. sed 's/^X//' << 'SHAR_EOF' > vr1.c &&
  360. X/* VR : A Reality Game by Cado <12/3/92> */
  361. X
  362. X/*
  363. X * To compile :
  364. X *
  365. X * On NeWS based machines (IRIX 3.3 etc) :
  366. X * cc vr1.c -lgl -lm -o vr1
  367. X *
  368. X * On X based machines (IRIX 4.05 etc) :
  369. X * cc vr1.c -lgl -lm -lX11 -o vr1
  370. X *
  371. X * Note : In NeWS based m/c's keywarp is in /usr/NeWS/bin
  372. X *        and in X based m/c's keywarp is in /usr/sbin
  373. X *        so change the system() calls accordingly.
  374. X */
  375. X
  376. X#include "vector.h"
  377. X#include "vr.h"
  378. X#include <string.h>
  379. X
  380. X#define  X  0
  381. X#define  Y  1
  382. X#define  Z  2
  383. X#define  W  3
  384. X
  385. X/* :) */
  386. X#define fr(v,s,e) for(v=s;v<e;v++) 
  387. X
  388. X/* VR globals */
  389. Xint gov ;
  390. Xchar  gamename[100] ;
  391. Xlong  xorg, yorg, xsiz, ysiz ;
  392. XScreencoord vpst, conslower, consupper ;
  393. Xint   consdispwidth, conslabels[4] ;
  394. Xfloat xmid, ymid ;
  395. Xint   crosswiresiz, crosswiregap ;
  396. Xint   crosswire, cloakdetector ;
  397. X
  398. Xfloat thrust, stepthrust, steprot ;
  399. Xint   xrot, yrot, zrot ;
  400. XVEC   shipmov, shippos[2] ;
  401. XVEC   shipx, shipy, shipz ;
  402. X
  403. Xchar  consolemsg[100] ;
  404. Xint   consolemsgcolor ;
  405. Xint   mainloopcycles = 19 ;
  406. X
  407. Xint   torpleft, ntorp, enemleft, enemymissileshit ;
  408. Xfloat fuelleft, damage ;
  409. X
  410. Xfloat points ;
  411. X
  412. Xshort fovy = 900 ;
  413. Xfloat tanfovyrad ;
  414. X
  415. X/* VR objects */
  416. XObject  vr_world_object ;
  417. X
  418. X/* Torpedo launcher cross-wire */
  419. XObject  crosswire_object ;
  420. X
  421. X/* Individual torpedo information */
  422. Xstruct  {
  423. X   int     fired ;
  424. X   VEC     torpedopos, torpedodir ;
  425. X}  torpinfo[MAXTORPFIRE] ;
  426. X
  427. X
  428. X/* Enemy info */
  429. Xstruct  {
  430. X   int     tough, cloaked ;
  431. X   int     level ;
  432. X   int     destroyed, exploding ;
  433. X   float   speed ;
  434. X   VEC     pos, dir ;
  435. X}  enemyinfo[MAXENEM] ;
  436. X
  437. X
  438. X/* Enemy missile */
  439. Xstruct {
  440. X   float   msiz ;
  441. X   float   distfromship ;
  442. X   int destroyed ;
  443. X   VEC pos, dir ;
  444. X}  enemymissile ;
  445. X
  446. X
  447. X/* Tracker beam */
  448. Xint enemynum, prevstate, trackertoggle, ntrackersleft ;
  449. Xfloat beaminc = 100.0 ;
  450. X
  451. X
  452. Xinit_stat ()
  453. X{
  454. X   gov = FALSE ;
  455. X   thrust = 0 ;
  456. X   stepthrust = STEPTHRUST ;
  457. X   steprot = 10 ;
  458. X   xrot = yrot = 0 ;
  459. X   torpleft = MAXTORP ;
  460. X   ntrackersleft = MAXTRACKERS ;
  461. X   ntorp = 0 ;
  462. X   fuelleft = MAXFUEL ;
  463. X   damage = 0 ;
  464. X   enemleft = MAXENEM ;
  465. X   enemymissileshit = 0 ;
  466. X   enemymissile.destroyed = TRUE ;
  467. X   enemymissile.msiz = ENEMSIZ ;
  468. X
  469. X   crosswire = ON ;
  470. X   cloakdetector = OFF ;
  471. X
  472. X   points = 0 ;
  473. X   shippos[0].x = shippos[1].x = 0 ;
  474. X   shippos[0].y = shippos[1].y = 0 ;
  475. X   shippos[0].z = shippos[1].z = 0 ;
  476. X
  477. X   /* Initially ship is oriented along -ve Z axis */
  478. X   shipx.x = 1.0 ;
  479. X   shipx.y = shipx.z = 0 ;
  480. X   shipy.y = 1.0 ;
  481. X   shipy.x = shipy.z = 0 ;
  482. X   shipz.z = -1.0 ;
  483. X   shipz.x = shipz.y = 0 ;
  484. X}
  485. X
  486. X
  487. X
  488. Xinit_world_view ()
  489. X{
  490. X   color ( PANELBGCOLOR ) ;
  491. X   clear () ;
  492. X   swapbuffers () ;
  493. X   color ( PANELBGCOLOR ) ;
  494. X   clear () ;
  495. X}
  496. X
  497. X
  498. Xinit_gfx ()
  499. X{
  500. X   int i, j, k, cx, cy ;
  501. X   VEC3 v ;
  502. X   float lx, ly, lz, worldinc ;
  503. X   long  vc[2], v1[2], v2[2], v3[2], v4[2] ;
  504. X
  505. X   keepaspect ( 4, 5 ) ;
  506. X   minsize ( 588L, 735L ) ;
  507. X   if ( winopen ( "VR" ) == -1 ) { 
  508. X      printf ( "Error opening window\n" ) ;;
  509. X      exit ( 1 ) ;
  510. X   }
  511. X   doublebuffer () ;
  512. X   gconfig () ;
  513. X   init_world_view () ;
  514. X
  515. X   getorigin ( &xorg, &yorg ) ;
  516. X   getsize ( &xsiz, &ysiz ) ;
  517. X
  518. X   vpst = ysiz*0.2 ;
  519. X   conslower = (vpst-vpst*0.80) ;
  520. X   consupper = (vpst-vpst*0.1) ;
  521. X   consdispwidth = xsiz/15.0 ;
  522. X
  523. X   conslabels[0] = consdispwidth/2.0 - strwidth("Thrust")/2.0  ;
  524. X   conslabels[1] = consdispwidth/2.0 - strwidth("Rotate")/2.0  ;
  525. X   conslabels[2] = consdispwidth/2.0 - strwidth("Fuel")/2.0    ;
  526. X   conslabels[3] = consdispwidth/2.0 - strwidth("Torpedo")/2.0 ;
  527. X
  528. X   xmid = xsiz/2.0 ;
  529. X   ymid = vpst + (ysiz-vpst)/2.0 ;
  530. X   crosswiregap = (crosswiresiz = (ysiz-vpst)/20.0)/5.0 ;
  531. X
  532. X   tanfovyrad = TAN((fovy/10.0)*(M_PI/180.0)*
  533. X                    (crosswiresiz+crosswiregap)/xsiz) ;
  534. X
  535. X   viewport ( (Screencoord) 40, (Screencoord) (xsiz-40), 
  536. X              (Screencoord) vpst+40, (Screencoord) (ysiz-40) ) ;
  537. X   perspective ( fovy, (double)xsiz/(double)(ysiz-vpst), 0.001, 5000000.0 );
  538. X   /* zbuffer ( TRUE ) ;
  539. X   lsetdepth ( 0, 500000 ) ;
  540. X    zclear () ; */
  541. X
  542. X   qdevice ( ESCKEY ) ;
  543. X   qdevice ( LEFTARROWKEY ) ;
  544. X   qdevice ( RIGHTARROWKEY ) ;
  545. X   qdevice ( UPARROWKEY ) ;
  546. X   qdevice ( DOWNARROWKEY ) ;
  547. X   qdevice ( PAD0 ) ;
  548. X   qdevice ( PADENTER ) ;
  549. X   qdevice ( COMMAKEY ) ;
  550. X   qdevice ( PERIODKEY ) ;
  551. X   qdevice ( AKEY ) ;
  552. X   qdevice ( CKEY ) ;
  553. X   qdevice ( DKEY ) ;
  554. X   qdevice ( SKEY ) ;
  555. X   qdevice ( ZKEY ) ;
  556. X   qdevice ( RKEY ) ;
  557. X   qdevice ( PKEY ) ;
  558. X   qdevice ( TKEY ) ;
  559. X   qdevice ( SPACEKEY ) ;
  560. X
  561. X   worldinc = (CUBEMAX-CUBEMIN)/((float)(WORLDDIVS-1)) ;
  562. X
  563. X   vr_world_object = genobj () ;
  564. X   makeobj ( vr_world_object ) ;
  565. X
  566. X   color ( RED ) ;
  567. X   fr ( k, 0, WORLDDIVS ) {
  568. X      bgnline () ;
  569. X      fr ( i, 0, WORLDDIVS ) {
  570. X         v[0] = CUBEMIN + i*worldinc ;
  571. X         v[1] = CUBEMIN ;
  572. X         v[2] = CUBEMIN + k*worldinc ;
  573. X         v3f ( v ) ;
  574. X      }
  575. X      endline () ;
  576. X   }
  577. X   for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  578. X      bgnline () ;
  579. X      for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  580. X         v[0] = CUBEMIN + i*worldinc ;
  581. X         v[1] = CUBEMIN ;
  582. X         v[2] = CUBEMIN + k*worldinc ;
  583. X         v3f ( v ) ;
  584. X      }
  585. X      endline () ;
  586. X   }
  587. X
  588. X   color ( YELLOW ) ;
  589. X   for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  590. X      bgnline () ;
  591. X      for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  592. X         v[0] = CUBEMIN + i*worldinc ;
  593. X         v[1] = CUBEMAX ;
  594. X         v[2] = CUBEMIN + k*worldinc ;
  595. X         v3f ( v ) ;
  596. X      }
  597. X      endline () ;
  598. X   }
  599. X   for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  600. X      bgnline () ;
  601. X      for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  602. X         v[0] = CUBEMIN + i*worldinc ;
  603. X         v[1] = CUBEMAX ;
  604. X         v[2] = CUBEMIN + k*worldinc ;
  605. X         v3f ( v ) ;
  606. X      }
  607. X      endline () ;
  608. X   }
  609. X
  610. X   color ( BLUE ) ;
  611. X   for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  612. X      bgnline () ;
  613. X      for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  614. X         v[0] = CUBEMIN ;
  615. X         v[1] = CUBEMIN + j*worldinc ;
  616. X         v[2] = CUBEMIN + k*worldinc ;
  617. X         v3f ( v ) ;
  618. X      }
  619. X      endline () ;
  620. X   }
  621. X   for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  622. X      bgnline () ;
  623. X      for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  624. X         v[0] = CUBEMIN ;
  625. X         v[1] = CUBEMIN + j*worldinc ;
  626. X         v[2] = CUBEMIN + k*worldinc ;
  627. X         v3f ( v ) ;
  628. X      }
  629. X      endline () ;
  630. X   }
  631. X
  632. X   color ( GREEN ) ;
  633. X   for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  634. X      bgnline () ;
  635. X      for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  636. X         v[0] = CUBEMAX ;
  637. X         v[1] = CUBEMIN + j*worldinc ;
  638. X         v[2] = CUBEMIN + k*worldinc ;
  639. X         v3f ( v ) ;
  640. X      }
  641. X      endline () ;
  642. X   }
  643. X   for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  644. X      bgnline () ;
  645. X      for ( k = 0 ; k < WORLDDIVS ; k++ ) {
  646. X         v[0] = CUBEMAX ;
  647. X         v[1] = CUBEMIN + j*worldinc ;
  648. X         v[2] = CUBEMIN + k*worldinc ;
  649. X         v3f ( v ) ;
  650. X      }
  651. X      endline () ;
  652. X   }
  653. X
  654. X   color ( WHITE ) ;
  655. X   for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  656. X      bgnline () ;
  657. X      for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  658. X         v[0] = CUBEMIN + i*worldinc ;
  659. X         v[1] = CUBEMIN + j*worldinc ;
  660. X         v[2] = CUBEMIN ;
  661. X         v3f ( v ) ;
  662. X      }
  663. X      endline () ;
  664. X   }
  665. X   for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  666. X      bgnline () ;
  667. X      for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  668. X         v[0] = CUBEMIN + i*worldinc ;
  669. X         v[1] = CUBEMIN + j*worldinc ;
  670. X         v[2] = CUBEMIN ;
  671. X         v3f ( v ) ;
  672. X      }
  673. X      endline () ;
  674. X   }
  675. X
  676. X   color ( CYAN ) ;
  677. X   for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  678. X      bgnline () ;
  679. X      for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  680. X         v[0] = CUBEMIN + i*worldinc ;
  681. X         v[1] = CUBEMIN + j*worldinc ;
  682. X         v[2] = CUBEMAX ;
  683. X         v3f ( v ) ;
  684. X      }
  685. X      endline () ;
  686. X   }
  687. X   for ( i = 0 ; i < WORLDDIVS ; i++ ) {
  688. X      bgnline () ;
  689. X      for ( j = 0 ; j < WORLDDIVS ; j++ ) {
  690. X         v[0] = CUBEMIN + i*worldinc ;
  691. X         v[1] = CUBEMIN + j*worldinc ;
  692. X         v[2] = CUBEMAX ;
  693. X         v3f ( v ) ;
  694. X      }
  695. X      endline () ;
  696. X   }
  697. X   closeobj () ;
  698. X
  699. X   crosswire_object = genobj () ;
  700. X   makeobj ( crosswire_object ) ;
  701. X   color ( RED ) ;
  702. X   linewidth ( 3 ) ;
  703. X   vc[0] = cx = xsiz/2.0 ;
  704. X   vc[1] = cy = (ysiz-vpst)/2.0 + vpst ;
  705. X
  706. X   v1[0] = cx - crosswiresiz ;
  707. X   v1[1] = cy ;
  708. X   v2[0] = cx - crosswiregap ;
  709. X   v2[1] = cy ;
  710. X   v3[0] = cx + crosswiregap ;
  711. X   v3[1] = cy ;
  712. X   v4[0] = cx + crosswiresiz ;
  713. X   v4[1] = cy ;
  714. X   bgnline () ;
  715. X      v2i ( v1 ) ;
  716. X      v2i ( v2 ) ;
  717. X   endline () ;
  718. X   bgnline () ;
  719. X      v2i ( v3 ) ;
  720. X      v2i ( v4 ) ;
  721. X   endline () ;
  722. X   v1[0] = cx ;
  723. X   v1[1] = cy - crosswiresiz ;
  724. X   v2[0] = cx ;
  725. X   v2[1] = cy - crosswiregap ;
  726. X   v3[0] = cx ;
  727. X   v3[1] = cy + crosswiregap ;
  728. X   v4[0] = cx ;
  729. X   v4[1] = cy + crosswiresiz ;
  730. X   bgnline () ;
  731. X      v2i ( v1 ) ;
  732. X      v2i ( v2 ) ;
  733. X   endline () ;
  734. X   bgnline () ;
  735. X      v2i ( v3 ) ;
  736. X      v2i ( v4 ) ;
  737. X   endline () ;
  738. X
  739. X   v1[0] = cx - crosswiresiz - crosswiregap ;
  740. X   v1[1] = cy - crosswiresiz - crosswiregap ;
  741. X   v2[0] = cx - crosswiresiz - crosswiregap ;
  742. X   v2[1] = cy + crosswiresiz + crosswiregap ;
  743. X   bgnline () ;
  744. X      v2i ( v1 ) ;
  745. X      v2i ( v2 ) ;
  746. X   endline () ;
  747. X   v1[0] = cx + crosswiresiz + crosswiregap ;
  748. X   v1[1] = cy - crosswiresiz - crosswiregap ;
  749. X   v2[0] = cx + crosswiresiz + crosswiregap ;
  750. X   v2[1] = cy + crosswiresiz + crosswiregap ;
  751. X   bgnline () ;
  752. X      v2i ( v1 ) ;
  753. X      v2i ( v2 ) ;
  754. X   endline () ;
  755. X   v3[0] = cx + crosswiresiz + crosswiregap ;
  756. X   v3[1] = cy - crosswiresiz - crosswiregap ;
  757. X   v4[0] = cx + crosswiresiz - crosswiregap ;
  758. X   v4[1] = cy - crosswiresiz - crosswiregap ;
  759. X   bgnline () ;
  760. X      v2i ( v3 ) ;
  761. X      v2i ( v4 ) ;
  762. X   endline () ;
  763. X   v3[0] = cx + crosswiresiz + crosswiregap ;
  764. X   v3[1] = cy + crosswiresiz + crosswiregap ;
  765. X   v4[0] = cx + crosswiresiz - crosswiregap ;
  766. X   v4[1] = cy + crosswiresiz + crosswiregap ;
  767. X   bgnline () ;
  768. X      v2i ( v3 ) ;
  769. X      v2i ( v4 ) ;
  770. X   endline () ;
  771. X   v3[0] = cx - crosswiresiz - crosswiregap ;
  772. X   v3[1] = cy - crosswiresiz - crosswiregap ;
  773. X   v4[0] = cx - crosswiresiz + crosswiregap ;
  774. X   v4[1] = cy - crosswiresiz - crosswiregap ;
  775. X   bgnline () ;
  776. X      v2i ( v3 ) ;
  777. X      v2i ( v4 ) ;
  778. X   endline () ;
  779. X   v3[0] = cx - crosswiresiz - crosswiregap ;
  780. X   v3[1] = cy + crosswiresiz + crosswiregap ;
  781. X   v4[0] = cx - crosswiresiz + crosswiregap ;
  782. X   v4[1] = cy + crosswiresiz + crosswiregap ;
  783. X   bgnline () ;
  784. X      v2i ( v3 ) ;
  785. X      v2i ( v4 ) ;
  786. X   endline () ;
  787. X   linewidth ( 1 ) ;
  788. X
  789. X   closeobj () ;
  790. X
  791. X   for ( i = 0 ; i < MAXENEM ; i++ ) {
  792. X      enemyinfo[i].destroyed = FALSE ;
  793. X      lx = enemyinfo[i].pos.x = (2*drand48()-1.0)*CUBEMAX ;
  794. X      ly = enemyinfo[i].pos.y = (2*drand48()-1.0)*CUBEMAX ;
  795. X      lz = enemyinfo[i].pos.z = (2*drand48()-1.0)*CUBEMAX ;
  796. X      enemyinfo[i].dir.x = (2*drand48()-1.0) ;
  797. X      enemyinfo[i].dir.y = (2*drand48()-1.0) ;
  798. X      enemyinfo[i].dir.z = (2*drand48()-1.0) ;
  799. X      NORM ( enemyinfo[i].dir ) ;
  800. X
  801. X      /* Tough enemy */
  802. X      enemyinfo[i].tough = ( drand48 () > 0.5 ) ? TRUE : FALSE ;
  803. X
  804. X      /* Cloaked enemy */
  805. X      enemyinfo[i].cloaked = ( drand48 () > 0.9 ) ? TRUE : FALSE ;
  806. X
  807. X      enemyinfo[i].level = WHITE ;
  808. X      if ( drand48 () > 0.9 )
  809. X      /* Stationary enemy */
  810. X         enemyinfo[i].speed = 0.0 ;
  811. X      else
  812. X         enemyinfo[i].speed = ENEMSPEED ;
  813. X
  814. X      if ( enemyinfo[i].cloaked == FALSE )
  815. X         draw_one_enemy ( lx, ly, lz, enemyinfo[i].level ) ;
  816. X   }
  817. X}
  818. X
  819. X
  820. X
  821. Xdraw_window ()
  822. X{
  823. X   color ( WORLDBGCOLOR ) ;
  824. X   clear () ;
  825. X   /* czclear ( BLACK, 500000 ) ; */
  826. X
  827. X   draw_world () ;
  828. X   draw_enemies () ;
  829. X   draw_torpedos () ;
  830. X   if ( crosswire == ON ) draw_crosswire () ;
  831. X}
  832. X
  833. X
  834. X
  835. X
  836. Xdraw_enemies ()
  837. X{
  838. X   int i ;
  839. X
  840. X   for ( i = 0 ; i < MAXENEM ; i++ ) {
  841. X      if ( enemyinfo[i].destroyed == TRUE ) {
  842. X         if ( enemyinfo[i].exploding == TRUE ) {
  843. X            draw_one_exploding_enemy ( enemyinfo[i].pos.x,
  844. X                                        enemyinfo[i].pos.y,
  845. X                                        enemyinfo[i].pos.z, 
  846. X                                        enemyinfo[i].level ) ;
  847. X            enemyinfo[i].exploding = FALSE ;
  848. X         }
  849. X         else
  850. X            continue ;
  851. X      }
  852. X      check_for_enemy_bounce ( i ) ;
  853. X      enemyinfo[i].pos.x += enemyinfo[i].dir.x*enemyinfo[i].speed ;
  854. X      enemyinfo[i].pos.y += enemyinfo[i].dir.y*enemyinfo[i].speed ;
  855. X      enemyinfo[i].pos.z += enemyinfo[i].dir.z*enemyinfo[i].speed ;
  856. X
  857. X      if ( enemyinfo[i].cloaked == FALSE || cloakdetector == ON )
  858. X      draw_one_enemy ( enemyinfo[i].pos.x,
  859. X                       enemyinfo[i].pos.y,
  860. X                       enemyinfo[i].pos.z, enemyinfo[i].level ) ;
  861. X      if ( enemymissile.destroyed == TRUE )
  862. X         launch_enemy_missile ( i ) ;
  863. X   }
  864. X
  865. X   if ( enemymissile.destroyed == FALSE )
  866. X      draw_enemy_missile () ;
  867. X}
  868. X
  869. X
  870. X
  871. Xdraw_one_enemy ( lx, ly, lz, level )
  872. Xfloat lx, ly, lz ;
  873. Xint   level      ;
  874. X{
  875. X   VEC3 v1, v2, v3, v4, v5, v6, v7, v8 ;
  876. X
  877. X   v1[0] = lx ;
  878. X   v1[1] = ly ;
  879. X   v1[2] = lz ;
  880. X   v2[0] = lx + ENEMSIZ ;
  881. X   v2[1] = ly ;
  882. X   v2[2] = lz ;
  883. X   v3[0] = lx + ENEMSIZ ;
  884. X   v3[1] = ly + ENEMSIZ ;
  885. X   v3[2] = lz ;
  886. X   v4[0] = lx ;
  887. X   v4[1] = ly + ENEMSIZ ;
  888. X   v4[2] = lz ;
  889. X   v5[0] = lx ;
  890. X   v5[1] = ly ;
  891. X   v5[2] = lz + ENEMSIZ ;
  892. X   v6[0] = lx + ENEMSIZ ;
  893. X   v6[1] = ly ;
  894. X   v6[2] = lz + ENEMSIZ ;
  895. X   v7[0] = lx + ENEMSIZ ;
  896. X   v7[1] = ly + ENEMSIZ ;
  897. X   v7[2] = lz + ENEMSIZ ;
  898. X   v8[0] = lx ;
  899. X   v8[1] = ly + ENEMSIZ ;
  900. X   v8[2] = lz + ENEMSIZ ;
  901. X   color ( level ) ;
  902. X   bgnpolygon () ;
  903. X   v3f ( v1 ) ;
  904. X   v3f ( v2 ) ;
  905. X   v3f ( v3 ) ;
  906. X   v3f ( v4 ) ;
  907. X   endpolygon () ;
  908. X   bgnpolygon () ;
  909. X   v3f ( v2 ) ;
  910. X   v3f ( v6 ) ;
  911. X   v3f ( v7 ) ;
  912. X   v3f ( v3 ) ;
  913. X   endpolygon () ;
  914. X   bgnpolygon () ;
  915. X   v3f ( v4 ) ;
  916. X   v3f ( v3 ) ;
  917. X   v3f ( v7 ) ;
  918. X   v3f ( v8 ) ;
  919. X   endpolygon () ;
  920. X   bgnpolygon () ;
  921. X   v3f ( v5 ) ;
  922. X   v3f ( v1 ) ;
  923. X   v3f ( v4 ) ;
  924. X   v3f ( v8 ) ;
  925. X   endpolygon () ;
  926. X   bgnpolygon () ;
  927. X   v3f ( v5 ) ;
  928. X   v3f ( v6 ) ;
  929. X   v3f ( v2 ) ;
  930. X   v3f ( v1 ) ;
  931. X   endpolygon () ;
  932. X   bgnpolygon () ;
  933. X   v3f ( v6 ) ;
  934. X   v3f ( v5 ) ;
  935. X   v3f ( v8 ) ;
  936. X   v3f ( v7 ) ;
  937. X   endpolygon () ;
  938. X   color ( RED ) ;
  939. X   bgnline () ;
  940. X   v3f ( v1 ) ;
  941. X   v3f ( v2 ) ;
  942. X   v3f ( v3 ) ;
  943. X   v3f ( v4 ) ;
  944. X   v3f ( v1 ) ;
  945. X   endline () ;
  946. X   bgnline () ;
  947. X   v3f ( v2 ) ;
  948. X   v3f ( v6 ) ;
  949. X   v3f ( v7 ) ;
  950. X   v3f ( v3 ) ;
  951. X   v3f ( v2 ) ;
  952. X   endline () ;
  953. X   bgnline () ;
  954. X   v3f ( v4 ) ;
  955. X   v3f ( v3 ) ;
  956. X   v3f ( v7 ) ;
  957. X   v3f ( v8 ) ;
  958. X   v3f ( v4 ) ;
  959. X   endline () ;
  960. X   bgnline () ;
  961. X   v3f ( v5 ) ;
  962. X   v3f ( v1 ) ;
  963. X   v3f ( v4 ) ;
  964. X   v3f ( v8 ) ;
  965. X   v3f ( v5 ) ;
  966. X   endline () ;
  967. X   bgnline () ;
  968. X   v3f ( v5 ) ;
  969. X   v3f ( v6 ) ;
  970. X   v3f ( v2 ) ;
  971. X   v3f ( v1 ) ;
  972. X   v3f ( v5 ) ;
  973. X   endline () ;
  974. X   bgnline () ;
  975. X   v3f ( v6 ) ;
  976. X   v3f ( v5 ) ;
  977. X   v3f ( v8 ) ;
  978. X   v3f ( v7 ) ;
  979. X   v3f ( v6 ) ;
  980. X   endline () ;
  981. X}
  982. X
  983. X
  984. Xdraw_one_exploding_enemy ( lx, ly, lz, level )
  985. Xfloat lx, ly, lz ;
  986. Xint   level      ;
  987. X{
  988. X   VEC3 v1, v2, v3, v4, v5, v6, v7, v8 ;
  989. X   VEC3 v9, v10, v11, v12 ;
  990. X
  991. X   v1[0] = lx ;
  992. X   v1[1] = ly ;
  993. X   v1[2] = lz ;
  994. X   v2[0] = lx + ENEMSIZ ;
  995. X   v2[1] = ly ;
  996. X   v2[2] = lz ;
  997. X   v3[0] = lx + ENEMSIZ ;
  998. X   v3[1] = ly + ENEMSIZ ;
  999. X   v3[2] = lz ;
  1000. X   v4[0] = lx ;
  1001. X   v4[1] = ly + ENEMSIZ ;
  1002. X   v4[2] = lz ;
  1003. X   v5[0] = lx ;
  1004. X   v5[1] = ly ;
  1005. X   v5[2] = lz + ENEMSIZ ;
  1006. X   v6[0] = lx + ENEMSIZ ;
  1007. X   v6[1] = ly ;
  1008. X   v6[2] = lz + ENEMSIZ ;
  1009. X   v7[0] = lx + ENEMSIZ ;
  1010. X   v7[1] = ly + ENEMSIZ ;
  1011. X   v7[2] = lz + ENEMSIZ ;
  1012. X   v8[0] = lx ;
  1013. X   v8[1] = ly + ENEMSIZ ;
  1014. X   v8[2] = lz + ENEMSIZ ;
  1015. X   v9[0] = lx - ENEMSIZ ;
  1016. X   v9[1] = ly+ENEMSIZ/2.0 ;
  1017. X   v9[2] = lz+ENEMSIZ/2.0 ;
  1018. X   v10[0] = lx+ENEMSIZ/2.0 ;
  1019. X   v10[1] = ly - ENEMSIZ ;
  1020. X   v10[2] = lz+ENEMSIZ/2.0 ;
  1021. X   v11[0] = lx + 2*ENEMSIZ ;
  1022. X   v11[1] = ly+ENEMSIZ/2.0 ;
  1023. X   v11[2] = lz+ENEMSIZ/2.0 ;
  1024. X   v12[0] = lx+ENEMSIZ/2.0 ;
  1025. X   v12[1] = ly + 2*ENEMSIZ ;
  1026. X   v12[2] = lz+ENEMSIZ/2.0 ;
  1027. X   color ( RED ) ;
  1028. X   bgnpolygon () ;
  1029. X   v3f ( v1 ) ;
  1030. X   v3f ( v4 ) ;
  1031. X   v3f ( v9 ) ;
  1032. X   endpolygon () ;
  1033. X   bgnpolygon () ;
  1034. X   v3f ( v9 ) ;
  1035. X   v3f ( v4 ) ;
  1036. X   v3f ( v8 ) ;
  1037. X   endpolygon () ;
  1038. X   bgnpolygon () ;
  1039. X   v3f ( v8 ) ;
  1040. X   v3f ( v5 ) ;
  1041. X   v3f ( v9 ) ;
  1042. X   endpolygon () ;
  1043. X   bgnpolygon () ;
  1044. X   v3f ( v9 ) ;
  1045. X   v3f ( v5 ) ;
  1046. X   v3f ( v1 ) ;
  1047. X   endpolygon () ;
  1048. X   color ( RED ) ;
  1049. X   bgnclosedline () ;
  1050. X   v3f ( v1 ) ;
  1051. X   v3f ( v4 ) ;
  1052. X   v3f ( v9 ) ;
  1053. X   endclosedline () ;
  1054. X   bgnclosedline () ;
  1055. X   v3f ( v9 ) ;
  1056. X   v3f ( v4 ) ;
  1057. X   v3f ( v8 ) ;
  1058. X   endclosedline () ;
  1059. X   bgnclosedline () ;
  1060. X   v3f ( v8 ) ;
  1061. X   v3f ( v5 ) ;
  1062. X   v3f ( v9 ) ;
  1063. X   endclosedline () ;
  1064. X   bgnclosedline () ;
  1065. X   v3f ( v9 ) ;
  1066. X   v3f ( v5 ) ;
  1067. X   v3f ( v1 ) ;
  1068. X   endclosedline () ;
  1069. X   color ( RED ) ;
  1070. X   bgnpolygon () ;
  1071. X   v3f ( v4 ) ;
  1072. X   v3f ( v3 ) ;
  1073. X   v3f ( v12 ) ;
  1074. X   endpolygon () ;
  1075. X   bgnpolygon () ;
  1076. X   v3f ( v12 ) ;
  1077. X   v3f ( v3 ) ;
  1078. X   v3f ( v7 ) ;
  1079. X   endpolygon () ;
  1080. X   bgnpolygon () ;
  1081. X   v3f ( v7 ) ;
  1082. X   v3f ( v8 ) ;
  1083. X   v3f ( v12 ) ;
  1084. X   endpolygon () ;
  1085. X   bgnpolygon () ;
  1086. X   v3f ( v12 ) ;
  1087. X   v3f ( v8 ) ;
  1088. X   v3f ( v4 ) ;
  1089. X   endpolygon () ;
  1090. X   color ( RED ) ;
  1091. X   bgnclosedline () ;
  1092. X   v3f ( v4 ) ;
  1093. X   v3f ( v3 ) ;
  1094. X   v3f ( v12 ) ;
  1095. X   endclosedline () ;
  1096. X   bgnclosedline () ;
  1097. X   v3f ( v12 ) ;
  1098. X   v3f ( v3 ) ;
  1099. X   v3f ( v7 ) ;
  1100. X   endclosedline () ;
  1101. X   bgnclosedline () ;
  1102. X   v3f ( v7 ) ;
  1103. X   v3f ( v8 ) ;
  1104. X   v3f ( v12 ) ;
  1105. X   endclosedline () ;
  1106. X   bgnclosedline () ;
  1107. X   v3f ( v12 ) ;
  1108. X   v3f ( v8 ) ;
  1109. X   v3f ( v4 ) ;
  1110. X   endclosedline () ;
  1111. X   color ( RED ) ;
  1112. X   bgnpolygon () ;
  1113. X   v3f ( v11 ) ;
  1114. X   v3f ( v3 ) ;
  1115. X   v3f ( v2 ) ;
  1116. X   endpolygon () ;
  1117. X   bgnpolygon () ;
  1118. X   v3f ( v2 ) ;
  1119. X   v3f ( v6 ) ;
  1120. X   v3f ( v11 ) ;
  1121. X   endpolygon () ;
  1122. X   bgnpolygon () ;
  1123. X   v3f ( v11 ) ;
  1124. X   v3f ( v6 ) ;
  1125. X   v3f ( v7 ) ;
  1126. X   endpolygon () ;
  1127. X   bgnpolygon () ;
  1128. X   v3f ( v7 ) ;
  1129. X   v3f ( v3 ) ;
  1130. X   v3f ( v11 ) ;
  1131. X   endpolygon () ;
  1132. X   color ( RED ) ;
  1133. X   bgnclosedline () ;
  1134. X   v3f ( v11 ) ;
  1135. X   v3f ( v3 ) ;
  1136. X   v3f ( v2 ) ;
  1137. X   endclosedline () ;
  1138. X   bgnclosedline () ;
  1139. X   v3f ( v2 ) ;
  1140. X   v3f ( v6 ) ;
  1141. X   v3f ( v11 ) ;
  1142. X   endclosedline () ;
  1143. X   bgnclosedline () ;
  1144. X   v3f ( v11 ) ;
  1145. X   v3f ( v6 ) ;
  1146. X   v3f ( v7 ) ;
  1147. X   endclosedline () ;
  1148. X   bgnclosedline () ;
  1149. X   v3f ( v7 ) ;
  1150. X   v3f ( v3 ) ;
  1151. X   v3f ( v11 ) ;
  1152. X   endclosedline () ;
  1153. X   color ( RED ) ;
  1154. X   bgnpolygon () ;
  1155. X   v3f ( v10 ) ;
  1156. X   v3f ( v2 ) ;
  1157. X   v3f ( v1 ) ;
  1158. X   endpolygon () ;
  1159. X   bgnpolygon () ;
  1160. X   v3f ( v1 ) ;
  1161. X   v3f ( v5 ) ;
  1162. X   v3f ( v10 ) ;
  1163. X   endpolygon () ;
  1164. X   bgnpolygon () ;
  1165. X   v3f ( v10 ) ;
  1166. X   v3f ( v5 ) ;
  1167. X   v3f ( v6 ) ;
  1168. X   endpolygon () ;
  1169. X   bgnpolygon () ;
  1170. X   v3f ( v6 ) ;
  1171. X   v3f ( v2 ) ;
  1172. X   v3f ( v10 ) ;
  1173. X   endpolygon () ;
  1174. X   color ( RED ) ;
  1175. X   bgnclosedline () ;
  1176. X   v3f ( v10 ) ;
  1177. X   v3f ( v2 ) ;
  1178. X   v3f ( v1 ) ;
  1179. X   endclosedline () ;
  1180. X   bgnclosedline () ;
  1181. X   v3f ( v1 ) ;
  1182. X   v3f ( v5 ) ;
  1183. X   v3f ( v10 ) ;
  1184. X   endclosedline () ;
  1185. X   bgnclosedline () ;
  1186. X   v3f ( v10 ) ;
  1187. X   v3f ( v5 ) ;
  1188. X   v3f ( v6 ) ;
  1189. X   endclosedline () ;
  1190. X   bgnclosedline () ;
  1191. X   v3f ( v6 ) ;
  1192. X   v3f ( v2 ) ;
  1193. X   v3f ( v10 ) ;
  1194. X   endclosedline () ;
  1195. X}
  1196. X
  1197. X
  1198. Xdraw_enemy_missile ()
  1199. X{
  1200. X   float lx, ly, lz ;
  1201. X   VEC3 v1, v2, v3, v4, v5, v6, v7, v8 ;
  1202. X
  1203. X   v1[0] = enemymissile.pos.x += enemymissile.dir.x*ENEMMISSPEED ;
  1204. X   v1[1] = enemymissile.pos.y += enemymissile.dir.y*ENEMMISSPEED ;
  1205. X   v1[2] = enemymissile.pos.z += enemymissile.dir.z*ENEMMISSPEED ;
  1206. X   v2[0] = v1[0] + enemymissile.dir.x*enemymissile.msiz ;
  1207. X   v2[1] = v1[1] + enemymissile.dir.y*enemymissile.msiz ;
  1208. X   v2[2] = v1[2] + enemymissile.dir.z*enemymissile.msiz ;
  1209. X   color ( MAGENTA ) ;
  1210. X   linewidth ( 5 ) ;
  1211. X   bgnline () ;
  1212. X      v3f ( v1 ) ;
  1213. X      v3f ( v2 ) ;
  1214. X   endline () ;
  1215. X   linewidth ( 1 ) ;
  1216. X   check_for_enemy_missile_collision () ;
  1217. X}
  1218. X
  1219. X
  1220. X
  1221. Xdraw_crosswire ()
  1222. X/* Draw cross-wire at the center of the world viewport */
  1223. X{
  1224. X   pushmatrix () ;
  1225. X   ortho2 ( (Coord)0, (Coord)xsiz, (Coord)vpst, (Coord)ysiz ) ;
  1226. X   callobj ( crosswire_object ) ;
  1227. X   popmatrix () ;
  1228. X}
  1229. X
  1230. X
  1231. Xmove_ship ()
  1232. X{
  1233. X   SCALE_VEC ( shipmov, shipz, thrust ) ;
  1234. X   COPY_VEC ( shippos[0], shippos[1] ) ;
  1235. X   ADD_VEC  ( shippos[1], shipmov ) ;
  1236. X   translate ( -shipmov.x, -shipmov.y, -shipmov.z ) ;
  1237. X   fuelleft -= ABS(thrust) ;
  1238. X}
  1239. X
  1240. X
  1241. Xdraw_world ()
  1242. X{
  1243. X   xrotate () ;
  1244. X   yrotate () ;
  1245. X   zrotate () ;
  1246. X
  1247. X   move_ship () ;
  1248. X   check_for_ship_collision () ;
  1249. X
  1250. X   callobj ( vr_world_object ) ;
  1251. X}
  1252. X
  1253. X
  1254. Xyrotate ()
  1255. X{
  1256. X   Matrix mx ;
  1257. X
  1258. X   if ( yrot != 0 ) {
  1259. X      lib_create_axis_rotate_matrix ( mx, shipy, (float)-yrot/10.0 ) ;
  1260. X      translate ( shippos[1].x, shippos[1].y, shippos[1].z ) ;
  1261. X      multmatrix ( mx ) ;
  1262. X      translate ( -shippos[1].x, -shippos[1].y, -shippos[1].z ) ;
  1263. X      mat_transform ( mx, &shipz ) ;
  1264. X      mat_transform ( mx, &shipx ) ;
  1265. X      yrot = 0 ;
  1266. X      fuelleft -= ABS(yrot) ;
  1267. X   }
  1268. X}
  1269. X
  1270. X
  1271. X
  1272. Xxrotate ()
  1273. X{
  1274. X   Matrix mx ;
  1275. X
  1276. X   if ( xrot != 0 ) {
  1277. X      lib_create_axis_rotate_matrix ( mx, shipx, (float)-xrot/10.0 ) ;
  1278. X      translate ( shippos[1].x, shippos[1].y, shippos[1].z ) ;
  1279. X      multmatrix ( mx ) ;
  1280. X      translate ( -shippos[1].x, -shippos[1].y, -shippos[1].z ) ;
  1281. X      mat_transform ( mx, &shipy ) ;
  1282. X      mat_transform ( mx, &shipz ) ;
  1283. X      xrot = 0 ;
  1284. X      fuelleft -= ABS(xrot) ;
  1285. X   }
  1286. X}
  1287. X
  1288. X
  1289. Xzrotate ()
  1290. X{
  1291. X   Matrix mx ;
  1292. X
  1293. X   if ( zrot != 0 ) {
  1294. X      lib_create_axis_rotate_matrix ( mx, shipz, (float)-zrot/10.0 ) ;
  1295. X      translate ( shippos[1].x, shippos[1].y, shippos[1].z ) ;
  1296. X      multmatrix ( mx ) ;
  1297. X      translate ( -shippos[1].x, -shippos[1].y, -shippos[1].z ) ;
  1298. X      mat_transform ( mx, &shipx ) ;
  1299. X      mat_transform ( mx, &shipy ) ;
  1300. X      zrot = 0 ;
  1301. X      fuelleft -= ABS(zrot) ;
  1302. X   }
  1303. X}
  1304. X
  1305. X
  1306. X
  1307. Xfire_torpedo ()
  1308. X{
  1309. X   int  i ;
  1310. X   VEC3 v1, v2 ;
  1311. X
  1312. X   if ( torpleft == 0 ) return ;
  1313. X
  1314. X   for ( i = 0  ; i < MAXTORPFIRE ; i++ )
  1315. X      if ( torpinfo[i].fired == FALSE ) break ;
  1316. X
  1317. X   torpinfo[i].fired = TRUE ;
  1318. X   COPY_VEC ( torpinfo[i].torpedopos, shippos[1] ) ; 
  1319. X   COPY_VEC ( torpinfo[i].torpedodir, shipz ) ; 
  1320. X
  1321. X   v1[0] = shippos[1].x ;
  1322. X   v1[1] = shippos[1].y ;
  1323. X   v1[2] = shippos[1].z ;
  1324. X   v2[0] = v1[0] + shipz.x*TORPLEN ;
  1325. X   v2[1] = v1[1] + shipz.y*TORPLEN ;
  1326. X   v2[2] = v1[2] + shipz.z*TORPLEN ;
  1327. X
  1328. X   color ( MAGENTA ) ;
  1329. X   linewidth ( 3 ) ;
  1330. X   bgnline () ;
  1331. X      v3f ( v1 ) ;
  1332. X      v3f ( v2 ) ;
  1333. X   endline () ;
  1334. X   linewidth ( 1 ) ;
  1335. X
  1336. X   ntorp++ ;
  1337. X   torpleft-- ;
  1338. X}
  1339. X
  1340. X
  1341. X
  1342. Xlaunch_enemy_missile ( eni )
  1343. X{
  1344. X   enemymissile.destroyed = FALSE ;
  1345. X   COPY_VEC ( enemymissile.pos, enemyinfo[eni].pos ) ;
  1346. X   GET_VEC ( shippos[1], enemyinfo[eni].pos, enemymissile.dir ) ; 
  1347. X   NORM ( enemymissile.dir ) ;
  1348. X   draw_enemy_missile () ;
  1349. X}
  1350. X
  1351. X
  1352. X
  1353. Xdraw_torpedos ()
  1354. X{
  1355. X   int i ;
  1356. X   VEC3 v1, v2 ;
  1357. X
  1358. X   for ( i = 0  ; i < MAXTORPFIRE ; i++ ) {
  1359. X      if ( torpinfo[i].fired == FALSE ) continue ;
  1360. X
  1361. X      v1[0] = torpinfo[i].torpedopos.x += torpinfo[i].torpedodir.x*TORPSPEED ;
  1362. X      v1[1] = torpinfo[i].torpedopos.y += torpinfo[i].torpedodir.y*TORPSPEED ;
  1363. X      v1[2] = torpinfo[i].torpedopos.z += torpinfo[i].torpedodir.z*TORPSPEED ;
  1364. X
  1365. X      v2[0] = v1[0] + torpinfo[i].torpedodir.x*TORPLEN ;
  1366. X      v2[1] = v1[1] + torpinfo[i].torpedodir.y*TORPLEN ;
  1367. X      v2[2] = v1[2] + torpinfo[i].torpedodir.z*TORPLEN ;
  1368. X
  1369. X      check_for_torpedo_collision ( i ) ;
  1370. X
  1371. X      color ( MAGENTA ) ;
  1372. X      linewidth ( 3 ) ;
  1373. X      bgnline () ;
  1374. X         v3f ( v1 ) ;
  1375. X         v3f ( v2 ) ;
  1376. X      endline () ;
  1377. X      linewidth ( 1 ) ;
  1378. X   }
  1379. X}
  1380. X
  1381. X
  1382. Xupdate_console_panels ()
  1383. X{
  1384. X   long v1[3], v2[3], v3[3], v4[3], left, rite, i ;
  1385. X   char buff[100] ;
  1386. X   float divht, idivht, smalldivwidth, largedivwidth, damlower, damupper ;
  1387. X
  1388. X   pushmatrix () ;
  1389. X   pushviewport () ;
  1390. X   viewport ( (Screencoord) 0, (Screencoord) xsiz, (Screencoord) 0, 
  1391. X      (Screencoord) (vpst) ) ;
  1392. X   color ( PANELBGCOLOR ) ;
  1393. X   clear () ;
  1394. X   ortho2 ( (Coord)0, (Coord)xsiz, (Coord)0, (Coord)vpst ) ;
  1395. X
  1396. X   divht = (consupper-conslower)/8.0 ;
  1397. X   smalldivwidth = consdispwidth/8.0 ;
  1398. X   largedivwidth = consdispwidth/4.0 ;
  1399. X
  1400. X   /* Update thrust */
  1401. X   left = 10 ;
  1402. X   rite = left + consdispwidth ;
  1403. X   v1[0] = left-1 ;
  1404. X   v1[1] = conslower-1 ;
  1405. X   v2[0] = rite ;
  1406. X   v2[1] = conslower-1 ;
  1407. X   v3[0] = rite ;
  1408. X   v3[1] = consupper+1 ;
  1409. X   v4[0] = left-1 ;
  1410. X   v4[1] = consupper+1 ;
  1411. X   color ( YELLOW ) ;
  1412. X   bgnclosedline () ;
  1413. X   v2i ( v1 ) ;
  1414. X   v2i ( v2 ) ;
  1415. X   v2i ( v3 ) ;
  1416. X   v2i ( v4 ) ;
  1417. X   endclosedline () ;
  1418. X   if ( thrust < 0.0  )
  1419. X      color ( RED ) ;
  1420. X   else
  1421. X      color ( PANELTHRCOLOR ) ;
  1422. X   v1[0] = left ;
  1423. X   v1[1] = conslower ;
  1424. X   v2[0] = rite ;
  1425. X   v2[1] = conslower ;
  1426. X   v3[0] = rite ;
  1427. X   v3[1] = (ABS(thrust)/MAXTHRUST)*(consupper-conslower) + conslower ;
  1428. X   v4[0] = left ;
  1429. X   v4[1] = v3[1] ;
  1430. X   bgnpolygon () ;
  1431. X   v2i ( v1 ) ;
  1432. X   v2i ( v2 ) ;
  1433. X   v2i ( v3 ) ;
  1434. X   v2i ( v4 ) ;
  1435. X   endpolygon () ;
  1436. X   color ( YELLOW ) ;
  1437. X   for ( i = 1 ; i <= 7 ; i++ ) {
  1438. X      idivht = divht*i+conslower ;
  1439. X      v1[0] = left ;
  1440. X      v1[1] = idivht ;
  1441. X      v2[0] = (i%2 == 1) ? left + smalldivwidth : left + largedivwidth ;
  1442. X      v2[1] = idivht ;
  1443. X      bgnline () ;
  1444. X         v2i ( v1 ) ;
  1445. X         v2i ( v2 ) ;
  1446. X      endline () ;
  1447. X      v1[0] = rite ;
  1448. X      v1[1] = idivht ;
  1449. X      v2[0] = rite - ((i%2 == 1) ? smalldivwidth : largedivwidth) ;
  1450. X      v2[1] = idivht ;
  1451. X      bgnline () ;
  1452. X         v2i ( v1 ) ;
  1453. X         v2i ( v2 ) ;
  1454. X      endline () ;
  1455. X   }
  1456. X   cmov2i ( left+conslabels[0], conslower-15 ) ;
  1457. X   color ( WHITE ) ;
  1458. X   charstr ( "Thrust" ) ;
  1459. X
  1460. X   /* Update Rotation Speed */
  1461. X   left = rite+consdispwidth ;
  1462. X   rite = left+consdispwidth ;
  1463. X   v1[0] = left-1 ;
  1464. X   v1[1] = conslower-1 ;
  1465. X   v2[0] = rite ;
  1466. X   v2[1] = conslower-1 ;
  1467. X   v3[0] = rite ;
  1468. X   v3[1] = consupper+1 ;
  1469. X   v4[0] = left-1 ;
  1470. X   v4[1] = consupper+1 ;
  1471. X   color ( YELLOW ) ;
  1472. X   bgnclosedline () ;
  1473. X   v2i ( v1 ) ;
  1474. X   v2i ( v2 ) ;
  1475. X   v2i ( v3 ) ;
  1476. X   v2i ( v4 ) ;
  1477. X   endclosedline () ;
  1478. X   color ( PANELROTCOLOR ) ;
  1479. X   v1[0] = left ;
  1480. X   v1[1] = conslower ;
  1481. X   v2[0] = rite ;
  1482. X   v2[1] = conslower ;
  1483. X   v3[0] = rite ;
  1484. X   v3[1] = (ABS(steprot)/(float)MAXROT)*(consupper-conslower) + conslower ;
  1485. X   v4[0] = left ;
  1486. X   v4[1] = v3[1] ;
  1487. X   bgnpolygon () ;
  1488. X   v2i ( v1 ) ;
  1489. X   v2i ( v2 ) ;
  1490. X   v2i ( v3 ) ;
  1491. X   v2i ( v4 ) ;
  1492. X   endpolygon () ;
  1493. X   color ( YELLOW ) ;
  1494. X   for ( i = 1 ; i <= 7 ; i++ ) {
  1495. X      idivht = divht*i+conslower ;
  1496. X      v1[0] = left ;
  1497. X      v1[1] = idivht ;
  1498. X      v2[0] = (i%2 == 1) ? left + smalldivwidth : left + largedivwidth ;
  1499. X      v2[1] = idivht ;
  1500. X      bgnline () ;
  1501. X         v2i ( v1 ) ;
  1502. X         v2i ( v2 ) ;
  1503. X      endline () ;
  1504. X      v1[0] = rite ;
  1505. X      v1[1] = idivht ;
  1506. X      v2[0] = rite - ((i%2 == 1) ? smalldivwidth : largedivwidth) ;
  1507. X      v2[1] = idivht ;
  1508. X      bgnline () ;
  1509. X         v2i ( v1 ) ;
  1510. X         v2i ( v2 ) ;
  1511. X      endline () ;
  1512. X   }
  1513. X   cmov2i ( left+conslabels[1], conslower-15 ) ;
  1514. X   color ( WHITE ) ;
  1515. X   charstr ( "Rotate" ) ;
  1516. X
  1517. X   /* Update Fuel */
  1518. X   left = rite+consdispwidth ;
  1519. X   rite = left+consdispwidth ;
  1520. X   v1[0] = left-1 ;
  1521. X   v1[1] = conslower-1 ;
  1522. X   v2[0] = rite ;
  1523. X   v2[1] = conslower-1 ;
  1524. X   v3[0] = rite ;
  1525. X   v3[1] = consupper+1 ;
  1526. X   v4[0] = left-1 ;
  1527. X   v4[1] = consupper+1 ;
  1528. X   color ( YELLOW ) ;
  1529. X   bgnclosedline () ;
  1530. X   v2i ( v1 ) ;
  1531. X   v2i ( v2 ) ;
  1532. X   v2i ( v3 ) ;
  1533. X   v2i ( v4 ) ;
  1534. X   endclosedline () ;
  1535. X   if ( fuelleft <= 0.2*MAXFUEL )
  1536. X      color ( RED ) ;
  1537. X   else
  1538. X      color ( PANELFUECOLOR ) ;
  1539. X   v1[0] = left ;
  1540. X   v1[1] = conslower ;
  1541. X   v2[0] = rite ;
  1542. X   v2[1] = conslower ;
  1543. X   v3[0] = rite ;
  1544. X   v3[1] = (fuelleft/MAXFUEL)*(consupper-conslower) + conslower ;
  1545. X   v4[0] = left ;
  1546. X   v4[1] = v3[1] ;
  1547. X   bgnpolygon () ;
  1548. X   v2i ( v1 ) ;
  1549. X   v2i ( v2 ) ;
  1550. X   v2i ( v3 ) ;
  1551. X   v2i ( v4 ) ;
  1552. X   endpolygon () ;
  1553. X   color ( YELLOW ) ;
  1554. X   for ( i = 1 ; i <= 7 ; i++ ) {
  1555. X      idivht = divht*i+conslower ;
  1556. X      v1[0] = left ;
  1557. X      v1[1] = idivht ;
  1558. X      v2[0] = (i%2 == 1) ? left + smalldivwidth : left + largedivwidth ;
  1559. X      v2[1] = idivht ;
  1560. X      bgnline () ;
  1561. X         v2i ( v1 ) ;
  1562. X         v2i ( v2 ) ;
  1563. X      endline () ;
  1564. X      v1[0] = rite ;
  1565. X      v1[1] = idivht ;
  1566. X      v2[0] = rite - ((i%2 == 1) ? smalldivwidth : largedivwidth) ;
  1567. X      v2[1] = idivht ;
  1568. X      bgnline () ;
  1569. X         v2i ( v1 ) ;
  1570. X         v2i ( v2 ) ;
  1571. X      endline () ;
  1572. X   }
  1573. X   cmov2i ( left+conslabels[2], conslower-15 ) ;
  1574. X   color ( WHITE ) ;
  1575. X   charstr ( "Fuel" ) ;
  1576. X
  1577. X   /* Update No. of torpedos left */
  1578. X   left = rite+consdispwidth ;
  1579. X   rite = left+consdispwidth ;
  1580. X   v1[0] = left-1 ;
  1581. X   v1[1] = conslower-1 ;
  1582. X   v2[0] = rite+1 ;
  1583. X   v2[1] = conslower-1 ;
  1584. X   v3[0] = rite+1 ;
  1585. X   v3[1] = consupper+1 ;
  1586. X   v4[0] = left-1 ;
  1587. X   v4[1] = consupper+1 ;
  1588. X   color ( YELLOW ) ;
  1589. X   bgnclosedline () ;
  1590. X   v2i ( v1 ) ;
  1591. X   v2i ( v2 ) ;
  1592. X   v2i ( v3 ) ;
  1593. X   v2i ( v4 ) ;
  1594. X   endclosedline () ;
  1595. X   if ( torpleft <= 0.2*MAXTORP )
  1596. X      color ( RED ) ;
  1597. X   else
  1598. X      color ( PANELTORCOLOR ) ;
  1599. X   v1[0] = left ;
  1600. X   v1[1] = conslower ;
  1601. X   v2[0] = rite ;
  1602. X   v2[1] = conslower ;
  1603. X   v3[0] = rite ;
  1604. X   v3[1] = ((float)torpleft/(float)MAXTORP)*(consupper-conslower) 
  1605. X           + conslower ;
  1606. X   v4[0] = left ;
  1607. X   v4[1] = v3[1] ;
  1608. X   bgnpolygon () ;
  1609. X   v2i ( v1 ) ;
  1610. X   v2i ( v2 ) ;
  1611. X   v2i ( v3 ) ;
  1612. X   v2i ( v4 ) ;
  1613. X   endpolygon () ;
  1614. X   color ( YELLOW ) ;
  1615. X   for ( i = 1 ; i <= 7 ; i++ ) {
  1616. X      idivht = divht*i+conslower ;
  1617. X      v1[0] = left ;
  1618. X      v1[1] = idivht ;
  1619. X      v2[0] = (i%2 == 1) ? left + smalldivwidth : left + largedivwidth ;
  1620. X      v2[1] = idivht ;
  1621. X      bgnline () ;
  1622. X         v2i ( v1 ) ;
  1623. X         v2i ( v2 ) ;
  1624. X      endline () ;
  1625. X      v1[0] = rite ;
  1626. X      v1[1] = idivht ;
  1627. X      v2[0] = rite - ((i%2 == 1) ? smalldivwidth : largedivwidth) ;
  1628. X      v2[1] = idivht ;
  1629. X      bgnline () ;
  1630. X         v2i ( v1 ) ;
  1631. X         v2i ( v2 ) ;
  1632. X      endline () ;
  1633. X   }
  1634. X   cmov2i ( left+conslabels[3], conslower-15 ) ;
  1635. X   color ( WHITE ) ;
  1636. X   charstr ( "Torpedo" ) ;
  1637. X
  1638. X   /* Update damage report */
  1639. X   left = rite+20 ;
  1640. X   cmov2i ( left, consupper-10 ) ;
  1641. X   color ( WHITE ) ;
  1642. X   charstr ( "Damage" ) ;
  1643. X
  1644. X   damlower = consupper-10 ;
  1645. X   damupper = (consupper-conslower)/10.0 + damlower ;
  1646. X   left = rite+consdispwidth +40;
  1647. X   rite = xsiz-10 ;
  1648. X   v1[0] = left-1 ;
  1649. X   v1[1] = damlower-1 ;
  1650. X   v2[0] = rite+1 ;
  1651. X   v2[1] = damlower-1 ;
  1652. X   v3[0] = rite+1 ;
  1653. X   v3[1] = damupper+1 ;
  1654. X   v4[0] = left-1 ;
  1655. X   v4[1] = damupper+1 ;
  1656. X   color ( YELLOW ) ;
  1657. X   bgnclosedline () ;
  1658. X   v2i ( v1 ) ;
  1659. X   v2i ( v2 ) ;
  1660. X   v2i ( v3 ) ;
  1661. X   v2i ( v4 ) ;
  1662. X   endclosedline () ;
  1663. X   if ( damage > 100.0 ) damage = 100.0 ;
  1664. X   color ( PANELDAMCOLOR ) ;
  1665. X   v1[0] = left ;
  1666. X   v1[1] = damlower ;
  1667. X   v2[0] = (damage/100.0)*(rite-left)+left  ;
  1668. X   v2[1] = damlower ;
  1669. X   v3[0] = v2[0] ;
  1670. X   v3[1] = damupper ;
  1671. X   v4[0] = left ;
  1672. X   v4[1] = v3[1] ;
  1673. X   bgnpolygon () ;
  1674. X   v2i ( v1 ) ;
  1675. X   v2i ( v2 ) ;
  1676. X   v2i ( v3 ) ;
  1677. X   v2i ( v4 ) ;
  1678. X   endpolygon () ;
  1679. X   color ( YELLOW ) ;
  1680. X   for ( i = 1 ; i <= 9 ; i++ ) {
  1681. X      v1[0] = left + (rite-left)/10.0*i ;
  1682. X      v1[1] = damlower ;
  1683. X      v2[0] = v1[0] ;
  1684. X      v2[1] = damupper ;
  1685. X      bgnline () ;
  1686. X         v2i ( v1 ) ;
  1687. X         v2i ( v2 ) ;
  1688. X      endline () ;
  1689. X   }
  1690. X
  1691. X   /* Update console message window */
  1692. X   damlower -= 20 ;
  1693. X   damupper = (consupper-conslower)/10.0 + damlower ;
  1694. X   v1[0] = left-1 ;
  1695. X   v1[1] = damlower-1 ;
  1696. X   v2[0] = rite+1 ;
  1697. X   v2[1] = damlower-1 ;
  1698. X   v3[0] = rite+1 ;
  1699. X   v3[1] = damupper+1 ;
  1700. X   v4[0] = left-1 ;
  1701. X   v4[1] = damupper+1 ;
  1702. X   color ( WORLDBGCOLOR ) ;
  1703. X   bgnpolygon () ;
  1704. X   v2i ( v1 ) ;
  1705. X   v2i ( v2 ) ;
  1706. X   v2i ( v3 ) ;
  1707. X   v2i ( v4 ) ;
  1708. X   endpolygon () ;
  1709. X   cmov2i ( left+1, damlower+1 ) ;
  1710. X   color ( consolemsgcolor ) ;
  1711. X   charstr ( consolemsg ) ;
  1712. X
  1713. X   /* Update No. of enemies left */
  1714. X   color ( YELLOW ) ;
  1715. X   sprintf ( buff, "Enemies Left : %d", enemleft ) ;
  1716. X   cmov2i ( left, (int)((float)(consupper-conslower)/2.0+conslower)-30 ) ;
  1717. X   charstr ( buff ) ;
  1718. X
  1719. X   /* Update missile dist */
  1720. X   sprintf ( buff, "Missile dist : %-9.2f", enemymissile.distfromship ) ;
  1721. X   cmov2i ( left, (int)((float)(consupper-conslower)*3.0/4.0+conslower)-30 ) ;
  1722. X   charstr ( buff ) ;
  1723. X
  1724. X   /* Update Points */
  1725. X   sprintf ( buff, "Points       : %-9.0f", points ) ;
  1726. X   cmov2i ( left, (int)((float)(consupper-conslower)/4.0+conslower)-30 ) ;
  1727. X   charstr ( buff ) ;
  1728. X
  1729. X   /* Print Version */
  1730. X   cmov2i ( left, conslower-25 ) ;
  1731. X   color ( GREEN ) ;
  1732. X   charstr ( "VR v1.0 (c) 1992 - Cado" ) ;
  1733. X
  1734. X   popviewport () ;
  1735. X   popmatrix () ;
  1736. X}
  1737. X
  1738. X
  1739. Xcheck_game ()
  1740. X{
  1741. X   if ( damage >= 100 ) game_over ( "100% Ship damage" ) ;
  1742. X   if ( fuelleft < 0 )  game_over ( "Ran out of fuel" ) ;
  1743. X   if ( torpleft <= 0 ) game_over ( "Ran out of torpedos" ) ;
  1744. X   if ( enemleft == 0 ) {
  1745. X      ringbell () ;
  1746. X      ringbell () ;
  1747. X      ringbell () ;
  1748. X      ringbell () ;
  1749. X      game_over ( "Congrats !!" ) ;
  1750. X   }
  1751. X}
  1752. X
  1753. X
  1754. X
  1755. Xclear_console_message ()
  1756. X{
  1757. X   mainloopcycles++ ;
  1758. X   if ( mainloopcycles%20 == 0 ) {
  1759. X      mainloopcycles = 0 ;
  1760. X      consmsg ( "All Systems Normal", WHITE ) ;
  1761. X   }
  1762. X}
  1763. X
  1764. X
  1765. X
  1766. Xconsmsg ( msg, col )
  1767. Xchar *msg ;
  1768. Xint  col ;
  1769. X{
  1770. X   mainloopcycles = 0 ;
  1771. X   consolemsgcolor = col ;
  1772. X   strcpy ( consolemsg, msg ) ;
  1773. X}
  1774. X
  1775. X
  1776. Xmain ( c, v )
  1777. Xint  c   ;
  1778. Xchar **v ;
  1779. X{
  1780. X   short val ;
  1781. X   char  buff[100] ;
  1782. X   int qt ;
  1783. X
  1784. X   printf ( "\n\n\nVR v1.0 by Cado <12/3/92>\n\n" ) ;
  1785. X   system ( "/usr/sbin/keywarp 10 1" ) ;
  1786. X
  1787. X   /* Seed random no. generator */
  1788. X   srand48 ( time ( 0 ) ) ;
  1789. X
  1790. X   init_stat () ;
  1791. X   init_gfx ();
  1792. X   pushmatrix () ;
  1793. X
  1794. X   /* Main Game Loop */
  1795. X   while ( TRUE ) { 
  1796. X      draw_window () ;
  1797. X      update_console_panels () ;
  1798. X      swapbuffers () ;
  1799. X      check_game () ;
  1800. X      
  1801. X      clear_console_message () ;
  1802. X
  1803. X      if ( cloakdetector == ON ) {
  1804. X         fuelleft -= MAXFUEL*0.005 ;
  1805. X         cloakdetector = OFF ;
  1806. X         consmsg ( "All Systems Normal", WHITE ) ;
  1807. X      }
  1808. X
  1809. X      while ( qtest() ) {
  1810. X         switch ( qread ( &val ) ) {
  1811. X         case SKEY :
  1812. X         /* Increase forward ship thrust */
  1813. X            if ( thrust < MAXTHRUST )
  1814. X               thrust += stepthrust ;
  1815. X            else
  1816. X               consmsg ( "Reached WARP 9", YELLOW ) ;
  1817. X            break ;
  1818. X         case AKEY :
  1819. X         /* Increase backward ship thrust */
  1820. X            if ( thrust > -MAXTHRUST )
  1821. X               thrust -= stepthrust ;
  1822. X            else
  1823. X               consmsg ( "Reached WARP 9", YELLOW ) ;
  1824. X            break ;
  1825. X         case ZKEY :
  1826. X         /* Full brakes -- halt ship */
  1827. X            consmsg ( "Ship Halt", YELLOW ) ;
  1828. X            thrust = 0 ;
  1829. X            break ;
  1830. X
  1831. X         case CKEY :
  1832. X         /* Torpedo firing cross wire toggle */
  1833. X            crosswire = ! crosswire ;
  1834. X            sprintf ( buff, "Torpedo Targeting %s",
  1835. X               (crosswire==ON)? "ON":"OFF" ) ;
  1836. X            consmsg ( buff, YELLOW ) ;
  1837. X            while ( qtest() ) qread ( &val ) ;
  1838. X            break ;
  1839. X
  1840. X         case DKEY :
  1841. X         /* Cloaked enemy detector button */
  1842. X            cloakdetector = ON ;
  1843. X            consmsg ( "Cloak Detector ON", 128 ) ;
  1844. X            break ;
  1845. X
  1846. X         /* Ship rotation keys */
  1847. X         case LEFTARROWKEY : 
  1848. X            yrot = steprot ;
  1849. X            break ;
  1850. X         case RIGHTARROWKEY : 
  1851. X            yrot = -steprot ;
  1852. X            break ;
  1853. X         case UPARROWKEY : 
  1854. X            xrot = steprot ;
  1855. X            break ;
  1856. X         case DOWNARROWKEY : 
  1857. X            xrot = -steprot ;
  1858. X            break ;
  1859. X         case COMMAKEY : 
  1860. X            zrot = -steprot ;
  1861. X            break ;
  1862. X         case PERIODKEY : 
  1863. X            zrot = steprot ;
  1864. X            break ;
  1865. X
  1866. X         /* Ship rotation control keys */
  1867. X         case PADENTER :
  1868. X            if ( steprot < MAXROT )
  1869. X               steprot += 10 ;
  1870. X            break ;
  1871. X         case PAD0 :
  1872. X            if ( steprot > MINROT )
  1873. X               steprot -= 10 ;
  1874. X            break ;
  1875. X
  1876. X         case SPACEKEY :
  1877. X         /* Fire torpedo or laser tracker */
  1878. X            if ( trackertoggle == ON ) {
  1879. X               enemyinfo[enemynum].destroyed = TRUE ;
  1880. X               enemyinfo[enemynum].exploding = TRUE ;
  1881. X               consmsg ( "Laser tracker success", GREEN ) ;
  1882. X               trackertoggle = OFF ;
  1883. X               ntrackersleft-- ;
  1884. X               enemleft-- ;
  1885. X               points += 1000.0 ;
  1886. X            }
  1887. X            else if ( ntorp < MAXTORPFIRE )
  1888. X               fire_torpedo () ;
  1889. X            break ;
  1890. X
  1891. X         case TKEY :
  1892. X         /* Laser tracker targeting instrument */
  1893. X            qreset () ;
  1894. X            if ( trackertoggle == ON ) {
  1895. X               trackertoggle = OFF ;
  1896. X               consmsg ( "Targeting OFF", WHITE ) ;
  1897. X               enemyinfo[enemynum].level = prevstate ;
  1898. X            }
  1899. X            else {
  1900. X               if ( ntrackersleft > 0 ) {
  1901. X                  consmsg ( "Targeting ...", WHITE ) ;
  1902. X                  target_enemy () ;
  1903. X               }
  1904. X               else
  1905. X                  consmsg ( "No tracer lasers left", YELLOW ) ;
  1906. X            }
  1907. X            break ;
  1908. X
  1909. X
  1910. X         case ESCKEY :
  1911. X            exit_game () ;
  1912. X         }
  1913. X      }
  1914. X   }
  1915. X}
  1916. X
  1917. X
  1918. Xpr ( v )
  1919. XVEC v ;
  1920. X{
  1921. X   printf ( "%f %f %f\n", v.x, v.y, v.z ) ;
  1922. X}
  1923. X
  1924. X
  1925. Xmat_transform ( a, v )
  1926. XMatrix a  ;
  1927. XVEC    *v ;
  1928. X{
  1929. X   VEC vn ;
  1930. X
  1931. X   vn.x = a[0][0]*v->x + a[0][1]*v->y + a[0][2]*v->z ;
  1932. X   vn.y = a[1][0]*v->x + a[1][1]*v->y + a[1][2]*v->z ;
  1933. X   vn.z = a[2][0]*v->x + a[2][1]*v->y + a[2][2]*v->z ;
  1934. X   COPY_VEC ( (*v), vn ) ;
  1935. X}
  1936. X
  1937. X
  1938. X
  1939. Xcheck_for_ship_collision ()
  1940. X{
  1941. X   int i ;
  1942. X   VEC tdir, un, refdir, olddir, expsite ;
  1943. X   int chdir ;
  1944. X   Matrix mx  ;
  1945. X   VEC    n   ;
  1946. X   float  ang ;
  1947. X
  1948. X   if ( shippos[1].x <= CUBEMIN ||
  1949. X        shippos[1].y <= CUBEMIN ||
  1950. X        shippos[1].z <= CUBEMIN ||
  1951. X        shippos[1].x >= CUBEMAX ||
  1952. X        shippos[1].y >= CUBEMAX ||
  1953. X        shippos[1].z >= CUBEMAX )
  1954. X      game_over ( "Collided with wall" ) ;
  1955. X
  1956. X   for ( i = 0 ; i < MAXENEM ; i++ ) {
  1957. X      if ( enemyinfo[i].destroyed == FALSE )
  1958. X      if ( DIST ( shippos[1], enemyinfo[i].pos )
  1959. X           < ENEMSIZ ) {
  1960. X         damage += (ABS(thrust)/MAXTHRUST) ;
  1961. X         collided ( "enemy" ) ;
  1962. X         COPY_VEC ( expsite, shippos[1] ) ;
  1963. X         expsite.x += shipz.x*5.0 ;
  1964. X         expsite.y += shipz.y*5.0 ;
  1965. X         expsite.z += shipz.z*5.0 ;
  1966. X         big_explosion ( expsite ) ;
  1967. X      }
  1968. X   }
  1969. X
  1970. X   if ( enemymissile.destroyed == FALSE )
  1971. X   if ( (enemymissile.distfromship = DIST ( shippos[1], enemymissile.pos ))
  1972. X        < SHIPSIZ/2.0 ) {
  1973. X      damage += 10 ;
  1974. X      collided ( "enemy missile" ) ;
  1975. X      COPY_VEC ( expsite, shippos[1] ) ;
  1976. X      expsite.x += shipz.x*5.0 ;
  1977. X      expsite.y += shipz.y*5.0 ;
  1978. X      expsite.z += shipz.z*5.0 ;
  1979. X      big_explosion ( expsite ) ;
  1980. X   }
  1981. X}
  1982. X
  1983. X
  1984. X
  1985. Xcheck_for_torpedo_collision ( torpnum )
  1986. Xint torpnum ;
  1987. X{
  1988. X   int i ;
  1989. X   float dist, pfact ;
  1990. X
  1991. X   if ( torpinfo[torpnum].torpedopos.x <= CUBEMIN || 
  1992. X        torpinfo[torpnum].torpedopos.x >= CUBEMAX ||
  1993. X        torpinfo[torpnum].torpedopos.y <= CUBEMIN || 
  1994. X        torpinfo[torpnum].torpedopos.y >= CUBEMAX ||
  1995. X        torpinfo[torpnum].torpedopos.z <= CUBEMIN || 
  1996. X        torpinfo[torpnum].torpedopos.z >= CUBEMAX ) {
  1997. X      torpinfo[torpnum].fired = FALSE ;
  1998. X      ntorp-- ;
  1999. X      explosion ( torpinfo[torpnum].torpedopos ) ;
  2000. X   }
  2001. X
  2002. X   for ( i = 0 ; i < MAXENEM ; i++ ) {
  2003. X      if ( ( enemyinfo[i].destroyed == FALSE ) && 
  2004. X           (dist = DIST ( torpinfo[torpnum].torpedopos, 
  2005. X                          enemyinfo[i].pos ))
  2006. X           < ENEMSIZ ) {
  2007. X         torpinfo[torpnum].fired = FALSE ;
  2008. X         ntorp-- ;
  2009. X         big_explosion ( torpinfo[torpnum].torpedopos ) ;
  2010. X         pfact = 1.0 ;
  2011. X         dist = DIST ( enemyinfo[i].pos, shippos[1] ) ;
  2012. X
  2013. X         if ( enemyinfo[i].tough == TRUE ) {
  2014. X         /* Tough enemy needs to be shot multiple times */
  2015. X            switch ( enemyinfo[i].level ) {
  2016. X            case BLUE :
  2017. X               pfact = 2.5 ;
  2018. X               enemyinfo[i].destroyed = TRUE ;
  2019. X               enemyinfo[i].exploding = TRUE ;
  2020. X               enemleft-- ;
  2021. X               consmsg ( 
  2022. X                  (enemyinfo[i].cloaked == TRUE) ?
  2023. X                  "Cloaked Enemy destroyed" : "Enemy destroyed", 
  2024. X                  GREEN 
  2025. X               ) ;
  2026. X               break ;
  2027. X            case YELLOW :
  2028. X               pfact = 2.0 ;
  2029. X               if ( drand48() > 0.95 ) {
  2030. X               /* Terrible luck !! */
  2031. X                  consmsg ( "Enemy cloaked", RED ) ;
  2032. X                  enemyinfo[i].cloaked = TRUE ;
  2033. X               }
  2034. X               else {
  2035. X                  enemyinfo[i].level = BLUE ;
  2036. X                  enemyinfo[i].speed *= TOUGHENEMSPEEDFACT ;
  2037. X                  consmsg ( "Enemy hit", GREEN ) ;
  2038. X               }
  2039. X               break ;
  2040. X            case GREEN :
  2041. X               pfact = 1.5 ;
  2042. X               enemyinfo[i].level = YELLOW ;
  2043. X               enemyinfo[i].speed *= TOUGHENEMSPEEDFACT ;
  2044. X               consmsg ( "Enemy hit", GREEN ) ;
  2045. X               break ;
  2046. X            case WHITE :
  2047. X               pfact = 1.0 ;
  2048. X               enemyinfo[i].level = GREEN ;
  2049. X               enemyinfo[i].speed *= TOUGHENEMSPEEDFACT ;
  2050. X               consmsg ( "Enemy hit", GREEN ) ;
  2051. X               break ;
  2052. X            case CYAN :
  2053. X            /* Marked by tracker beam */ 
  2054. X               pfact = 0.0 ;
  2055. X               break ;
  2056. X            }
  2057. X         }
  2058. X         else {
  2059. X            if ( enemyinfo[i].level == CYAN )
  2060. X               pfact = 0.0 ;
  2061. X            else {
  2062. X               enemyinfo[i].destroyed = TRUE ;
  2063. X               enemyinfo[i].exploding = TRUE ;
  2064. X               enemleft-- ;
  2065. X               consmsg ( "Enemy destroyed", GREEN ) ;
  2066. X            }
  2067. X         }
  2068. X         points += pfact*dist ;
  2069. X      }
  2070. X   }
  2071. X
  2072. X   if ( enemymissile.destroyed == FALSE ) 
  2073. X   if ( DIST ( enemymissile.pos, torpinfo[torpnum].torpedopos ) < 
  2074. X               enemymissile.msiz ) {
  2075. X   /* Destroyed an enemy missile */
  2076. X      points += 10000.0 ;
  2077. X      enemymissileshit++ ;
  2078. X      consmsg ( "Missile destroyed", GREEN ) ;
  2079. X      enemymissile.destroyed = TRUE ;
  2080. X      big_explosion ( torpinfo[torpnum].torpedopos ) ;
  2081. X   }
  2082. X}
  2083. X
  2084. X
  2085. X
  2086. Xcheck_for_enemy_bounce ( eni )
  2087. Xint eni ;
  2088. X{
  2089. X   VEC tdir, un, refdir ;
  2090. X   int chdir ;
  2091. X
  2092. X   chdir = FALSE ;
  2093. X
  2094. X   if ( enemyinfo[eni].pos.x <= CUBEMIN ) {
  2095. X      un.x = 1  ;
  2096. X      un.y = 0  ;
  2097. X      un.z = 0  ;
  2098. X      chdir = TRUE ;
  2099. X   }
  2100. X   if ( enemyinfo[eni].pos.x >= CUBEMAX ) {
  2101. X      un.x = -1  ;
  2102. X      un.y = 0  ;
  2103. X      un.z = 0  ;
  2104. X      chdir = TRUE ;
  2105. X   }
  2106. X   if ( enemyinfo[eni].pos.y <= CUBEMIN ) {
  2107. X      un.x = 0  ;
  2108. X      un.y = 1  ;
  2109. X      un.z = 0  ;
  2110. X      chdir = TRUE ;
  2111. X   }
  2112. X   if ( enemyinfo[eni].pos.y >= CUBEMAX ) {
  2113. X      un.x = 0  ;
  2114. X      un.y = -1  ;
  2115. X      un.z = 0  ;
  2116. X      chdir = TRUE ;
  2117. X   }
  2118. X   if ( enemyinfo[eni].pos.z <= CUBEMIN ) {
  2119. X      un.x = 0  ;
  2120. X      un.y = 0  ;
  2121. X      un.z = 1  ;
  2122. X      chdir = TRUE ;
  2123. X   }
  2124. X   if ( enemyinfo[eni].pos.z >= CUBEMAX ) {
  2125. X      un.x = 0  ;
  2126. X      un.y = 0  ;
  2127. X      un.z = -1  ;
  2128. X      chdir = TRUE ;
  2129. X   }
  2130. X
  2131. X   if ( chdir == TRUE ) {
  2132. X      SCALE_VEC ( enemyinfo[eni].dir, enemyinfo[eni].dir, -1.0 ) ;
  2133. X      REFL_RAY ( enemyinfo[eni].dir, enemyinfo[eni].pos, un, refdir ) ;
  2134. X      COPY_VEC ( enemyinfo[eni].dir, refdir ) ;
  2135. X   }
  2136. X}
  2137. X
  2138. X
  2139. Xcheck_for_enemy_missile_collision ()
  2140. X{
  2141. X   if ( enemymissile.pos.x <= CUBEMIN || 
  2142. X        enemymissile.pos.x >= CUBEMAX ||
  2143. X        enemymissile.pos.y <= CUBEMIN || 
  2144. X        enemymissile.pos.y >= CUBEMAX ||
  2145. X        enemymissile.pos.z <= CUBEMIN || 
  2146. X        enemymissile.pos.z >= CUBEMAX ) {
  2147. X      enemymissile.destroyed = TRUE ;
  2148. X      explosion ( enemymissile.pos ) ;
  2149. X   }
  2150. X}
  2151. X
  2152. X
  2153. X
  2154. Xexplosion ( v )
  2155. XVEC v ;
  2156. X{
  2157. X   int i ;
  2158. X   VEC3 v1, vp ;
  2159. X   VEC  r      ;
  2160. X
  2161. X   linewidth ( 2 ) ;
  2162. X   color ( RED ) ;
  2163. X
  2164. X   VECTOVEC3 ( vp, v ) ;
  2165. X   for ( i = 0 ; i < 10 ; i++ ) {
  2166. X   r.x = ( 2*drand48 () - 1 ) ;
  2167. X   r.y = ( 2*drand48 () - 1 ) ;
  2168. X   r.z = ( 2*drand48 () - 1 ) ;
  2169. X   NORM ( r ) ;
  2170. X   v1[0] = v.x+r.x*EXPSIZ ;
  2171. X   v1[1] = v.y+r.y*EXPSIZ ;
  2172. X   v1[2] = v.z+r.z*EXPSIZ ;
  2173. X   bgnline () ;
  2174. X      v3f ( vp ) ;
  2175. X      v3f ( v1 ) ;
  2176. X   endline ;
  2177. X   }
  2178. X   linewidth ( 1 ) ;
  2179. X}
  2180. X
  2181. X
  2182. Xbig_explosion ( v )
  2183. XVEC v ;
  2184. X{
  2185. X   int i ;
  2186. X   VEC3 v1, vp ;
  2187. X   VEC  r      ;
  2188. X
  2189. X   linewidth ( 4 ) ;
  2190. X   color ( RED ) ;
  2191. X
  2192. X   VECTOVEC3 ( vp, v ) ;
  2193. X   for ( i = 0 ; i < 30 ; i++ ) {
  2194. X   r.x = ( 2*drand48 () - 1 ) ;
  2195. X   r.y = ( 2*drand48 () - 1 ) ;
  2196. X   r.z = ( 2*drand48 () - 1 ) ;
  2197. X   NORM ( r ) ;
  2198. X   v1[0] = v.x+r.x*EXPSIZ ;
  2199. X   v1[1] = v.y+r.y*EXPSIZ ;
  2200. X   v1[2] = v.z+r.z*EXPSIZ ;
  2201. X   bgnline () ;
  2202. X      v3f ( vp ) ;
  2203. X      v3f ( v1 ) ;
  2204. X   endline ;
  2205. X   }
  2206. X   linewidth ( 1 ) ;
  2207. X}
  2208. X
  2209. X
  2210. Xcollided ( withwhat )
  2211. Xchar *withwhat ;
  2212. X{
  2213. X   char buff[100] ;
  2214. X   ringbell () ;
  2215. X   sprintf ( buff, "Hit by %s", withwhat ) ;
  2216. X   consmsg ( buff, RED ) ;
  2217. X}
  2218. X
  2219. X
  2220. Xgame_over ( msg )
  2221. Xchar *msg ;
  2222. X{
  2223. X   int   key, i ;
  2224. X   short val    ;
  2225. X
  2226. X   ortho2 ( (Coord)0, (Coord)xsiz, (Coord)vpst, (Coord)ysiz ) ;
  2227. X   cmov2 ( xsiz/2.0-strwidth("Game Over")/2.0, (ysiz-vpst)/3.0+vpst ) ;
  2228. X   color ( WHITE ) ;
  2229. X   charstr ( "Game Over" ) ;
  2230. X   gov = TRUE ;
  2231. X   consmsg ( msg, WHITE  ) ;
  2232. X   update_console_panels () ;
  2233. X   swapbuffers () ;
  2234. X   while ( TRUE )
  2235. X   if ( qtest () ) {
  2236. X      key = qread (&val) ;
  2237. X      if ( key == ESCKEY ) exit_game () ;
  2238. X      else if ( key == RKEY ) break ;
  2239. X   }
  2240. X}
  2241. X
  2242. X
  2243. X
  2244. Xrestart ()
  2245. X/* Restart the game */
  2246. X{
  2247. X   int i ;
  2248. X
  2249. X   init_stat () ;
  2250. X   for ( i = 0 ; i < MAXENEM ; i++ ) {
  2251. X      enemyinfo[i].destroyed = FALSE ;
  2252. X      enemyinfo[i].level     = WHITE ;
  2253. X      enemyinfo[i].level     = WHITE ;
  2254. X      if ( drand48 () > 0.9 )
  2255. X      /* Stationary enemy */
  2256. X         enemyinfo[i].speed = 0.0 ;
  2257. X      else
  2258. X         enemyinfo[i].speed = ENEMSPEED ;
  2259. X   }
  2260. X   popmatrix () ;
  2261. X   pushmatrix () ;
  2262. X   consmsg ( "RESTART", YELLOW ) ;
  2263. X}
  2264. X
  2265. X
  2266. X
  2267. X/*
  2268. X * Create a rotation matrix along the given axis by the given angle 
  2269. X * in degrees.  The axis is a set of direction cosines.
  2270. X * This is originally from Eric Haines' SPD package.
  2271. X */
  2272. Xlib_create_axis_rotate_matrix( mx, vaxis, angle )
  2273. XMatrix    mx ;
  2274. XVEC       vaxis ;
  2275. Xfloat     angle ;
  2276. X{
  2277. X   float cosine, one_minus_cosine, sine ;
  2278. X   int   i, j ;
  2279. X   VEC3  axis ;
  2280. X
  2281. X   angle *= M_PI/180.0 ;
  2282. X   VECTOVEC3 ( axis, vaxis ) ;
  2283. X
  2284. X   for ( j = 0 ; j < 4 ; j++ )
  2285. X   for ( i = 0 ; i < 4 ; i++ )
  2286. X      mx[j][i] = 0 ;
  2287. X
  2288. X   cosine = COS( angle ) ;
  2289. X   sine = SIN ( angle ) ;
  2290. X   one_minus_cosine = 1.0 - cosine ;
  2291. X
  2292. X   mx[0][0] = SQR(axis[X]) + (1.0 - SQR(axis[X])) * cosine ;
  2293. X   mx[0][1] = axis[X] * axis[Y] * one_minus_cosine + axis[Z] * sine ;
  2294. X   mx[0][2] = axis[X] * axis[Z] * one_minus_cosine - axis[Y] * sine ;
  2295. X
  2296. X   mx[1][0] = axis[X] * axis[Y] * one_minus_cosine - axis[Z] * sine ;
  2297. X   mx[1][1] = SQR(axis[Y]) + (1.0 - SQR(axis[Y])) * cosine ;
  2298. X   mx[1][2] = axis[Y] * axis[Z] * one_minus_cosine + axis[X] * sine ;
  2299. X
  2300. X   mx[2][0] = axis[X] * axis[Z] * one_minus_cosine + axis[Y] * sine ;
  2301. X   mx[2][1] = axis[Y] * axis[Z] * one_minus_cosine - axis[X] * sine ;
  2302. X   mx[2][2] = SQR(axis[Z]) + (1.0 - SQR(axis[Z])) * cosine ;
  2303. X
  2304. X   mx[3][3] = 1.0 ;
  2305. X}
  2306. X
  2307. X
  2308. Xexit_game ()
  2309. X{
  2310. X   system ( "/usr/sbin/keywarp 25 1" ) ;
  2311. X   exit ( 0 ) ;
  2312. X}
  2313. X
  2314. X
  2315. X
  2316. Xtarget_enemy ()
  2317. X/* Laser targeting */
  2318. X{
  2319. X   float  beam, dist, bbt, dr1[3], dr2[3] ;
  2320. X   VEC    trackerbeampos, beammov ;
  2321. X   int i ;
  2322. X
  2323. X   COPY_VEC ( trackerbeampos, shippos[1] ) ;
  2324. X   INIT_VEC ( beammov, shipz.x*beaminc, shipz.y*beaminc, shipz.z*beaminc ) ;
  2325. X   for ( beam = 0 ; beam <= (CUBEMAX-CUBEMIN) ; beam += beaminc ) {
  2326. X      ADD_VEC ( trackerbeampos, beammov ) ;
  2327. X      bbt = beam*tanfovyrad ;
  2328. X      for ( i = 0 ; i < MAXENEM ; i++ ) {
  2329. X         if ( enemyinfo[i].destroyed == FALSE ) {
  2330. X            dist = DIST ( trackerbeampos, enemyinfo[i].pos ) ;
  2331. X            if ( dist < bbt ) {
  2332. X               prevstate = enemyinfo[i].level ;
  2333. X               enemyinfo[i].level = CYAN ;
  2334. X               consmsg ( "Laser Locked ON", GREEN ) ;
  2335. X               enemynum = i ;
  2336. X               trackertoggle = ON ;
  2337. X               return ;
  2338. X            }
  2339. X         }
  2340. X      }
  2341. X   }
  2342. X   consmsg ( "Laser NOT Locked ON", YELLOW ) ;
  2343. X}
  2344. X
  2345. SHAR_EOF
  2346. chmod 0600 vr1.c || echo "restore of vr1.c fails"
  2347. exit 0
  2348.