home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume18 / xmpb / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-07-11  |  53.1 KB

  1. Path: uunet!news.tek.com!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v18i001:  xmpb - multiplayer space combat for X, Part01/08
  5. Date: 26 Jun 1993 00:31:52 GMT
  6. Organization: Tektronix, Inc, Redmond, OR, USA
  7. Lines: 2358
  8. Approved: billr@saab.CNA.TEK.COM
  9. Message-ID: <20g5do$6sk@ying.cna.tek.com>
  10. NNTP-Posting-Host: saab.cna.tek.com
  11. Xref: uunet comp.sources.games:1791
  12.  
  13. Submitted-by: ddp@deakin.edu.au (Damien De Paoli)
  14. Posting-number: Volume 18, Issue 1
  15. Archive-name: xmpb/Part01
  16. Environment: X11, Xlib
  17.  
  18. [[From the author...]]
  19. [     XMPB is a multi player space combat game for X-terms. It works best
  20. on multiple black and white workstations.  My next aim is to get it to
  21. run quickly on colour workstations  (when I get access to a colour station)
  22. If you have only seen version 0.85 then there are many changes, including
  23.  
  24.     save files
  25.     a shop
  26.     non playing characters
  27.     more weapons
  28.     speed increase.
  29.  
  30.  
  31. If you have seen version 1.0, then the main change is in the Imakefile
  32. xmpb can now be run without having to install the whole program.  Also
  33. time limits have been added to games.
  34.  
  35. Well here it is, and good luck,
  36. Damien ]
  37.  
  38.  
  39. #! /bin/sh
  40. # This is a shell archive.  Remove anything before this line, then unpack
  41. # it by saving it into a file and typing "sh file".  To overwrite existing
  42. # files, type "sh file -c".  You can also feed this as standard input via
  43. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  44. # will see the following message at the end:
  45. #        "End of archive 1 (of 8)."
  46. # Contents:  README MANIFEST bitmaps bitmaps/debris.3 parse.y pcomp.c
  47. # Wrapped by billr@saab on Fri Jun 25 16:30:13 1993
  48. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  49. if test -f 'README' -a "${1}" != "-c" ; then 
  50.   echo shar: Will not clobber existing file \"'README'\"
  51. else
  52. echo shar: Extracting \"'README'\" \(2088 characters\)
  53. sed "s/^X//" >'README' <<'END_OF_FILE'
  54. XWHAT IS XMPB?
  55. X
  56. XXMPB is a multi player space combat game for X-terms. It works best
  57. Xon multiple workstations rather than using X-terms on the same computer.
  58. X
  59. X
  60. X--->>> YOU MUST DO THIS, OR IT WILL NOT COMPILE.
  61. X
  62. XFirst you need to cd into the bitmaps directory, then:
  63. X    
  64. X    uudecode title.bmp.Z.uu
  65. X    uncompress title.bmp.Z
  66. X    rm title.bmp.Z.uu
  67. X
  68. X
  69. XCOMPILING
  70. X
  71. XIf you have Imake then you should be able to just type
  72. X
  73. X    xmkmf
  74. X    make depend
  75. X    make
  76. X
  77. XHopefully this will create a copy of xmpb, npcc, clear_lock, describe
  78. Xand retire in your current directory.  This should mean that you can
  79. Xrun it, but the npc's are not installed.  If you are low on disk spave
  80. Xand want to run it from your current directory, then you can type make
  81. Xnpcs and they will be placed into NPCDIR.  Now it wil run fully, 
  82. Xwithout being installed.
  83. X
  84. XIf you don't have Imake, then I have included a standard Makefile, 
  85. XMakefile.std.  I haven't tested this, so I don't know if it will
  86. Xwork or not, but give it a go!
  87. X
  88. X
  89. XINSTALLING
  90. X
  91. XTo install the npcs, and all the binaries...
  92. X
  93. Xtype make install
  94. X
  95. XNow being pessimistic, you will probably get errors.  The most
  96. Xobvious one, is due to mkdirhier not being set correctly and the
  97. Xsubdirectories BLASTDIR, SAVEDIR, NPCDIR, BITMAPDIR and BINDIR.
  98. Xhave not been created.  You can simply create these directories 
  99. Xby hand.  e.g. for my system:
  100. X
  101. X    mkdir /home/ddp/blast    (this is what my BLASTDIR is set to)
  102. X    mkdir /home/ddp/blast/save    (this is what my SAVEDIR is set to)
  103. X
  104. Xe.t.c.
  105. X
  106. XOnce this works, all you need to run this fully, is the blast dir and
  107. Xits contents.  All the stuff from the shar files can be deleted.  If 
  108. Xyou want to keep the sources, and modify them for yourself please do,
  109. Xbut send the changes to me as well, and I will try to add them into 
  110. Xthe official version.
  111. X
  112. X
  113. XBUGS
  114. X
  115. X    What are they???
  116. X    Seriously, if you get any, mail them to me ddp@deakin.edu.au, and
  117. X    I'll look into it.
  118. X
  119. X
  120. XTODO
  121. X
  122. X    The obvious one is to get this to run fast on a colour machine.  At
  123. Xthe moment this is difficult as I don't have access to one, but soon we
  124. Xwill and then I shall fix it up.
  125. X
  126. X
  127. XGood Luck,
  128. XDamien
  129. END_OF_FILE
  130. if test 2088 -ne `wc -c <'README'`; then
  131.     echo shar: \"'README'\" unpacked with wrong size!
  132. fi
  133. # end of 'README'
  134. fi
  135. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  136.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  137. else
  138. echo shar: Extracting \"'MANIFEST'\" \(3338 characters\)
  139. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  140. X   File Name        Archive #    Description
  141. X-----------------------------------------------------------
  142. X Imakefile                  6    
  143. X MANIFEST                   1    This shipping list
  144. X Makefile.std               5    
  145. X README                     1    
  146. X add_host.c                 3    
  147. X average.npc                6    
  148. X basic.npc                  6    
  149. X beam.npc                   7    
  150. X bitmaps                    1    
  151. X bitmaps/atom               8    
  152. X bitmaps/bigrock            7    
  153. X bitmaps/bomb               3    
  154. X bitmaps/cloud.1            8    
  155. X bitmaps/cloud.2            7    
  156. X bitmaps/cloud.3            8    
  157. X bitmaps/cloud.4            8    
  158. X bitmaps/cloud.5            8    
  159. X bitmaps/cloud.6            8    
  160. X bitmaps/debris.1           7    
  161. X bitmaps/debris.2           7    
  162. X bitmaps/debris.3           1    
  163. X bitmaps/dunno              8    
  164. X bitmaps/dunno2             8    
  165. X bitmaps/hvypulse           8    
  166. X bitmaps/jam100             8    
  167. X bitmaps/jam25              8    
  168. X bitmaps/jam50              8    
  169. X bitmaps/jam75              8    
  170. X bitmaps/magneto            8    
  171. X bitmaps/massdrive          8    
  172. X bitmaps/medrock            7    
  173. X bitmaps/mine               8    
  174. X bitmaps/pulse              8    
  175. X bitmaps/rail               8    
  176. X bitmaps/saturn1            8    
  177. X bitmaps/seeker             8    
  178. X bitmaps/ship.0             6    
  179. X bitmaps/shortdeaddude      7    
  180. X bitmaps/smallrock          8    
  181. X bitmaps/star1              8    
  182. X bitmaps/star2              8    
  183. X bitmaps/stipple            8    
  184. X bitmaps/title.bmp.Z.uu     4    
  185. X bits.c                     6    
  186. X bits.h                     8    
  187. X calc_angle.c               7    
  188. X calc_shields.c             7    
  189. X clear_lock.c               8    
  190. X clear_lock.man             7    
  191. X collide.c                  7    
  192. X cos.c                      8    
  193. X costab.c                   7    
  194. X damage_ship.c              6    
  195. X describe.c                 7    
  196. X describe.man               7    
  197. X disp_ship.c                6    
  198. X do_stars.c                 7    
  199. X error.c                    8    
  200. X handle_ev.c                4    
  201. X harry.npc                  7    
  202. X input.c                    2    
  203. X john.npc                   7    
  204. X junk.c                     5    
  205. X lex.l                      6    
  206. X ml.npc                     6    
  207. X ml2.npc                    7    
  208. X mnemonics.h                8    
  209. X nasty.npc                  6    
  210. X npcc.man                   5    
  211. X operators.h                7    
  212. X parse.y                    1    
  213. X pcomp.c                    1    
  214. X pcomp.h                    7    
  215. X player.h                   5    
  216. X polygon.c                  6    
  217. X rad1.npc                   6    
  218. X rad2.npc                   7    
  219. X rad3.npc                   7    
  220. X radar.c                    4    
  221. X read_ship.c                7    
  222. X retire.c                   7    
  223. X retire.man                 7    
  224. X save.c                     8    
  225. X save.h                     7    
  226. X save_load.c                7    
  227. X shop.contents              4    
  228. X shop.icon                  7    
  229. X shop.man                   6    
  230. X shop_stubs.c               2    
  231. X shop_ui.c                  5    
  232. X shop_ui.h                  7    
  233. X sin.c                      7    
  234. X sintab.c                   7    
  235. X stats.c                    5    
  236. X test.c                     4    
  237. X thrust.c                   7    
  238. X ud_win.c                   7    
  239. X update_ships.c             3    
  240. X update_win.c               3    
  241. X util.c                     5    
  242. X weapon.c                   3    
  243. X weapon.h                   7    
  244. X xmpb.man                   2    
  245. X xoutput.c                  5    
  246. END_OF_FILE
  247. if test 3338 -ne `wc -c <'MANIFEST'`; then
  248.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  249. fi
  250. # end of 'MANIFEST'
  251. fi
  252. if test ! -d 'bitmaps' ; then
  253.     echo shar: Creating directory \"'bitmaps'\"
  254.     mkdir 'bitmaps'
  255. fi
  256. if test -f 'bitmaps/debris.3' -a "${1}" != "-c" ; then 
  257.   echo shar: Will not clobber existing file \"'bitmaps/debris.3'\"
  258. else
  259. echo shar: Extracting \"'bitmaps/debris.3'\" \(437 characters\)
  260. sed "s/^X//" >'bitmaps/debris.3' <<'END_OF_FILE'
  261. X#define debris_width 19
  262. X#define debris_height 19
  263. Xstatic char debris_bits[] = {
  264. X   0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x78, 0x02, 0x80, 0x07, 0x01,
  265. X   0x78, 0x00, 0x01, 0x07, 0x80, 0x00, 0x01, 0x40, 0x00, 0x01, 0x20, 0x00,
  266. X   0x02, 0x20, 0x00, 0x02, 0x10, 0x00, 0x02, 0x08, 0x00, 0x02, 0x04, 0x00,
  267. X   0x02, 0x04, 0x00, 0x02, 0x02, 0x00, 0x04, 0x01, 0x00, 0x84, 0x00, 0x00,
  268. X   0x84, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00};
  269. END_OF_FILE
  270. if test 437 -ne `wc -c <'bitmaps/debris.3'`; then
  271.     echo shar: \"'bitmaps/debris.3'\" unpacked with wrong size!
  272. fi
  273. # end of 'bitmaps/debris.3'
  274. fi
  275. if test -f 'parse.y' -a "${1}" != "-c" ; then 
  276.   echo shar: Will not clobber existing file \"'parse.y'\"
  277. else
  278. echo shar: Extracting \"'parse.y'\" \(25960 characters\)
  279. sed "s/^X//" >'parse.y' <<'END_OF_FILE'
  280. X%{
  281. X#include <stdio.h>
  282. X#include "player.h"
  283. X#include "weapon.h"
  284. X#include "mnemonics.h"
  285. X
  286. X#define YYSTYPE int
  287. X#define LOCAL 1
  288. X#define GLOBAL 2
  289. X
  290. X#define ANY 0
  291. X#define PROCFLAG 1
  292. X#define STATEFLAG 2
  293. X
  294. Xint euid;
  295. Xextern char id[];
  296. Xint errline = 1;
  297. Xint lasterr = 0;
  298. Xint errors =0;
  299. Xextern FILE *yyin,*yyout;
  300. XFILE *dfp;
  301. Xextern char yytext[];
  302. X
  303. Xint does_have_weap[NO_WEAPONS];
  304. Xint i,j;
  305. Xint curr_type;
  306. Xint no_vars=0;
  307. Xint max_vars = 0;
  308. Xint no_globals = 0;
  309. Xint no_locals = 0;
  310. Xchar vars[100][MAX_SYMB_LEN+1];
  311. Xint varmem[100];
  312. Xint no_states=0;
  313. Xchar states[100][MAX_SYMB_LEN+1];
  314. Xint proc[100];
  315. Xint sp[100];
  316. Xchar buf[100];
  317. Xint regused[NO_REGS];
  318. Xchar curr_state[MAX_SYMB_LEN+1];
  319. X
  320. Xint bps[1000];
  321. Xint bpsp = 0;
  322. X
  323. Xstruct ins mem[5000];
  324. X
  325. Xint pointer = 0;
  326. X
  327. Xint bp_no=0;
  328. Xint bpl[100];
  329. Xint bpp[100];
  330. Xint bp_type[100];
  331. Xchar bpn[100][MAX_SYMB_LEN+1];
  332. X
  333. Xstruct header head;
  334. X
  335. Xint ppp;
  336. X
  337. X%}
  338. X
  339. X%token HEADER NAME SHIPNAME ENGINEL NONE SHORT PULSE LLASER RAIL BOMB SEEK
  340. X%token HLASER HPULSE ATOM MAGNETO BDEATH PROC
  341. X%token WEAPONS ID VAR STATE LBRACE RBRACE ARROW SET RETURN B1 B2 B3
  342. X%token INTEGER EQIV NOTEQ GT LT GTE LTE RP LP AND OR START LONG TCL
  343. X%token EQUALS LSHIELD RSHIELD BSHIELD REPAIRL SOLARL CLOAKL DARROW
  344. X%token SEMICOLON BALANCE RADARCHANGE RADARMODE SELECTE CLOAKT
  345. X%token PLUS MINUS MASS MINE MOD IF END WHILE ELSE ANGLEDIFF COMMA
  346. X%token TIMES DIV ENERGYMAX LSHIELDMAX RSHIELDMAX BSHIELDMAX NOT
  347. X%token TURNLEFT TURNRIGHT XPOS YPOS XVEL YVEL ANGLE TURNTO
  348. X%token SPEED  ENEMYSPEED ENEMYANGLE TARGETSTATE SOLARSTATE 
  349. X%token JAMSTATE SHORTSTATE LONGSTATE ENGINESTATE REPAIRSTATE CURRWEAP ENEMYDIST
  350. X%token NUMENEMIES ENERGY GRAB REPAIRTOGGLE QUIT TARGET REPAIRSELITEM
  351. X%token ENEMYAVAIL DIRECTION ANGLETO DISTTO ENEMYXPOS ENEMYYPOS ENEMYXVEL ENEMYYVEL
  352. X%token REPAIRITEM IDLEL VELATANG ENTRY EXIT CURRWEAPSTATE ENEMYDIRECTION WAITFRAME
  353. X
  354. X%%
  355. Xprogram     : HEADER name shipname ship VAR variables rules start_rule
  356. X            {
  357. X                int i;
  358. X
  359. X                for(i=0;i<bp_no;i++)
  360. X                {
  361. X                    int sp;
  362. X
  363. X                    sp = finds(bpn[i],ANY);
  364. X                    if(sp == -1)
  365. X                    {
  366. X                        sprintf(buf,"No routine %s: referenced in line %d",bpn[i],bpl[i]);
  367. X                        yyerror(buf);
  368. X                    }
  369. X                    else
  370. X                    {
  371. X                        mem[bpp[i]].o2 = sp;
  372. X                    }
  373. X                }
  374. X                head.no_vars = max_vars;
  375. X                head.no_ins = pointer;
  376. X                head.num_played=0;
  377. X                head.kills = 0;
  378. X                head.cash_earned=0;
  379. X                fwrite(&head,sizeof(struct header),1,yyout);
  380. X
  381. X                /*
  382. X                **
  383. X                */
  384. X                fwrite(mem,sizeof(struct ins),pointer,yyout);
  385. X            if(dfp)
  386. X            {
  387. X                j = 0;
  388. X                for(i=0;i<pointer;i++)
  389. X                {
  390. X                    if(i==sp[j])
  391. X                    {
  392. X                        fprintf(dfp,"%s:%d\n",states[j],sp[j]);
  393. X                        j++;
  394. X                    }
  395. X                    switch (mem[i].ins)
  396. X                    {
  397. X                        case EQR:
  398. X                        case XORR:
  399. X                        case LTR:
  400. X                        case LTER:
  401. X                        case GTR:
  402. X                        case GTER:
  403. X                        case ANDR:    
  404. X                        case ORR:
  405. X                        case ADDR:
  406. X                        case SUBR:
  407. X                        case MODR:
  408. X                        case MULR:
  409. X                        case DIVR:
  410. X                            fprintf(dfp,"%d %s r%d <- r%d r%d\n",i,ins_name[mem[i].ins],mem[i].o1,mem[i].o2,mem[i].o3);
  411. X                            break;
  412. X                        case RET:
  413. X                            fprintf(dfp,"%d %s\n",i,ins_name[mem[i].ins]);
  414. X                            break;
  415. X                        case LODM:
  416. X                        case STOM:
  417. X                        case INPR:
  418. X                        case LODI:
  419. X                        case OUPR:
  420. X                        case JMPC:
  421. X                        case JSRC:
  422. X                            fprintf(dfp,"%d %s r%d %d\n",i,ins_name[mem[i].ins],mem[i].o1,mem[i].o2);
  423. X                            break;
  424. X                        case JMPI:
  425. X                        case JSRI:
  426. X                        case PUSHM:
  427. X                        case POPM:
  428. X                            fprintf(dfp,"%d %s %d\n",i,ins_name[mem[i].ins],mem[i].o2);
  429. X                            break;
  430. X                        case MOVR:
  431. X                            fprintf(dfp,"%d %s r%d r%d\n",i,ins_name[mem[i].ins],mem[i].o1,mem[i].o2);
  432. X                            break;
  433. X                        case PUSHR:
  434. X                        case NOTR:
  435. X                        case POPR:
  436. X                            fprintf(dfp,"%d %s r%d\n",i,ins_name[mem[i].ins],mem[i].o1);
  437. X                            break;
  438. X            
  439. X                        default:
  440. X                            fprintf(stderr,"%d Debug error\n",i);
  441. X                    }
  442. X                }
  443. X            }
  444. X            fwrite(&no_states,sizeof(int),1,yyout);
  445. X            for(i=0;i<no_states;i++)
  446. X            {
  447. X                fwrite((states[i]),1,MAX_SYMB_LEN,yyout);
  448. X                fwrite(&(sp[i]),sizeof(int),1,yyout);
  449. X            }        
  450. X            }
  451. X            ;
  452. Xname        : NAME EQUALS ID {strncpy(head.Name,id,MAX_SYMB_LEN);}
  453. X            ;
  454. Xshipname    : SHIPNAME EQUALS ID {strncpy(head.Ship,id,MAX_SYMB_LEN);}
  455. X            ;
  456. Xship        : max items weapons
  457. X
  458. Xitems        : solar items
  459. X            | short items
  460. X            | engine items
  461. X            | repair items
  462. X            | long items
  463. X            | cloak items
  464. X            | tc items
  465. X            |
  466. X            ;
  467. Xengine      : ENGINEL assign {head.qual[ENGINE] = $2;}
  468. X            ;
  469. Xassign      : EQUALS INTEGER {$$ = $2;};
  470. X            | EQUALS NONE    {$$ = -1;};
  471. X            ;
  472. X
  473. Xshort       : SHORT assign {head.qual[SHORTRR] = $2;}
  474. X            ;
  475. Xtc          : TCL assign    {head.qual[TC] = $2;}
  476. X            ;
  477. Xlong        : LONG assign  {head.qual[LONGRR] = $2;}
  478. X            ;
  479. Xmax         : me max
  480. X            | mls max
  481. X            | mrs max
  482. X            | mbs max
  483. X            |
  484. X            ;
  485. Xme          : ENERGYMAX EQUALS INTEGER {head.energy_max = $3;}
  486. X            ;
  487. Xmls         : LSHIELDMAX EQUALS INTEGER {head.ls_max = $3;}
  488. X            ;
  489. Xmrs         : RSHIELDMAX EQUALS INTEGER {head.rs_max = $3;}
  490. X            ;
  491. Xmbs         : BSHIELDMAX EQUALS INTEGER {head.bs_max = $3;}
  492. X            ;
  493. Xsolar       : SOLARL assign {head.qual[SOLAR] = $2;}
  494. X            ;
  495. Xcloak       : CLOAKL assign  {head.qual[CLOAK] = $2;}
  496. X            ;
  497. Xrepair      : REPAIRL assign  {head.qual[REPAIR] = $2;}
  498. X            ;
  499. X
  500. Xweapons     : WEAPONS w_list 
  501. X            ;
  502. X
  503. Xw_list      : w_name
  504. X                {
  505. X                    if(head.does_have_weap[$1])
  506. X                    {
  507. X                        sprintf(buf,"Already has %s",weap_names[$1]);
  508. X                        yywarn(buf);
  509. X                    }
  510. X                    head.does_have_weap[$1] = 1;
  511. X                }     w_list
  512. X            |
  513. X            ;
  514. Xw_name      : PULSE {$$ = WEAP_PULSE;};
  515. X            | BOMB { $$ = WEAP_BOMB;};
  516. X            | SEEK { $$ = WEAP_SEEK;};
  517. X            | LLASER { $$ = WEAP_LIGHT_LASER;};
  518. X            | RAIL  { $$ = WEAP_RAIL;};
  519. X            | MASS  { $$ = WEAP_MASS;};
  520. X            | MINE  { $$ = WEAP_MINE;};
  521. X            | HLASER { $$ = WEAP_HEAVY_LASER;};
  522. X            | ATOM { $$ = WEAP_SPRAY;};
  523. X            | HPULSE { $$ = WEAP_HVYPULSE;};
  524. X            | MAGNETO { $$ = WEAP_MAGNET;};
  525. X            | BDEATH { $$ = WEAP_BLACK;};
  526. X            ;
  527. Xitem_name   :   SOLARL { $$ = SOLAR;}
  528. X            |   SHORT  { $$ = SHORTRR;}
  529. X            |   LONG { $$ = LONGRR;}
  530. X            |   ENGINEL  { $$ = ENGINE;}
  531. X            |   TCL { $$ = TC;}
  532. X            |   CLOAKL { $$ = CLOAK;}
  533. X            |   REPAIRL { $$ = REPAIR;}
  534. X            ;
  535. Xvariables   : variable variables
  536. X            | END
  537. X            ;
  538. X
  539. Xvariable    : ID  
  540. X                {
  541. X                    if(addvar(id,GLOBAL) == -1)
  542. X                    {
  543. X                        sprintf(buf,"redeclaration of %s",id);
  544. X                        yywarn(buf);
  545. X                    }
  546. X                };
  547. X            ;
  548. X
  549. Xlocvariables: locvar locvariables
  550. X            | 
  551. X            ;
  552. X
  553. Xlocvar        : ID
  554. X                {
  555. X                        if(addvar(id,LOCAL) == -1)
  556. X                        {
  557. X                            sprintf(buf,"redeclaration of %s",id);
  558. X                            yywarn(buf);
  559. X                        }
  560. X                      };
  561. X            ;
  562. Xlocals        :
  563. X            | VAR locvariables END
  564. X            ;
  565. X
  566. Xrules       : rule rules
  567. X            |
  568. X            ;
  569. X
  570. Xrule        : STATE ID {
  571. X                                    curr_type = STATEFLAG;
  572. X
  573. X                                    strncpy(curr_state,id,MAX_SYMB_LEN);
  574. X                                    curr_state[MAX_SYMB_LEN] = 0;
  575. X                                    if(addstate(id,pointer,STATEFLAG)==-1)
  576. X                                    {
  577. X                                        sprintf(buf,"%s redefined",id);
  578. X                                        yyerror(buf);
  579. X                                    }
  580. X                                        } LBRACE locals entry { ppp = pointer;} statements {ins(JMPI,0,ppp,0); kill_locals(); } RBRACE 
  581. X            | PROC ID {
  582. X                                    curr_type = PROCFLAG;
  583. X
  584. X                                    strncpy(curr_state,id,MAX_SYMB_LEN);
  585. X                                    curr_state[MAX_SYMB_LEN] = 0;
  586. X                                    if(addstate(id,pointer,PROCFLAG)==-1)
  587. X                                    {
  588. X                                        sprintf(buf,"%s redefined",id);
  589. X                                        yyerror(buf);
  590. X                                    }
  591. X                                        } LBRACE locals statements RBRACE {ins(RET,0,0,0); kill_locals();
  592. X                                }
  593. X            ;
  594. X            ;
  595. X
  596. Xentry        : ENTRY LBRACE statements RBRACE
  597. X            |
  598. X            ;
  599. Xstatements  : statements statement
  600. X            |
  601. X            ;
  602. Xifstart        : IF LP expr RP
  603. X                {
  604. X                    ins(NOTR,$3,0,0);
  605. X                    pushbp(pointer);
  606. X                    ins(JMPC,$3,0,0);
  607. X                    regused[$3] = 0;
  608. X                }
  609. X            statement
  610. X                {
  611. X                    {
  612. X                    int i;
  613. X                    
  614. X                    i = popbp();
  615. X                    mem[i].o2 = pointer;
  616. X                    pushbp(i);
  617. X                    }
  618. X                }
  619. X            ;
  620. Xifend        : { popbp();}
  621. X            | ELSE 
  622. X                {
  623. X                    mem[popbp()].o2++;
  624. X                    pushbp(pointer);
  625. X                    ins(JMPI,0,0,0);
  626. X                }
  627. X            statement
  628. X                {
  629. X                    mem[popbp()].o2 = pointer;
  630. X                }
  631. X            ;
  632. X
  633. Xstatement   : error SEMICOLON {yyerrok;}
  634. X            | WAITFRAME {ins(WAIT,0,0,0);}
  635. X            | fcall SEMICOLON {for(i=0;i<NO_REGS;i++) regused[i] = 0;}
  636. X            | expr SEMICOLON
  637. X            | LBRACE statements RBRACE
  638. X            | SEMICOLON
  639. X            | ifstart ifend
  640. X/*
  641. X**    While statement
  642. X*/
  643. X        |     WHILE LP 
  644. X                {
  645. X                    pushbp(pointer);
  646. X                }
  647. X            expr 
  648. X                {
  649. X                    ins(NOTR,$4,0,0);
  650. X                    pushbp(pointer);
  651. X                    ins(JMPC,$4,0,0);
  652. X                    regused[$4] = 0;
  653. X                }
  654. X            RP statement
  655. X                {
  656. X                    mem[popbp()].o2 = pointer+1; /*Note that 1 is the size of next*/
  657. X                    ins(JMPI,0,popbp(),0);
  658. X                }
  659. X        |     ARROW ID
  660. X                {
  661. X                    int sp;
  662. X
  663. X                    if(curr_type == PROCFLAG)
  664. X                        yyerror("May not change states inside procedures");
  665. X                    sp = finds(id,STATEFLAG);
  666. X                    if(sp == -1)
  667. X                    {
  668. X                        bpp[bp_no] = pointer;
  669. X                        strncpy(bpn[bp_no],id,MAX_SYMB_LEN);
  670. X                        bpn[bp_no][MAX_SYMB_LEN] = 0;
  671. X                        bpl[bp_no] = errline;
  672. X                        bp_no++;
  673. X                        ins(JMPI,0,0,0);
  674. X                    }
  675. X                    else
  676. X                    {
  677. X                        ins(JMPI,0,sp,0);
  678. X                    }
  679. X                } SEMICOLON
  680. X        |     expr ARROW ID 
  681. X                {
  682. X                    int sp;
  683. X
  684. X                    if(curr_type == PROCFLAG)
  685. X                        yyerror("May not change states inside procedures");
  686. X                    sp = finds(id,STATEFLAG);
  687. X                    if(sp == -1)
  688. X                    {
  689. X                        bpp[bp_no] = pointer;
  690. X                        strncpy(bpn[bp_no],id,MAX_SYMB_LEN);
  691. X                        bpn[bp_no][MAX_SYMB_LEN] = 0;
  692. X                        bpl[bp_no] = errline;
  693. X                        bp_no++;
  694. X                        ins(JMPC,$1,0,0);
  695. X                    }
  696. X                    else
  697. X                    {
  698. X                        ins(JMPC,$1,sp,0);
  699. X                    }
  700. X                    regused[$1] = 0;
  701. X                } SEMICOLON
  702. X            | SET outport EQUALS expr SEMICOLON 
  703. X                {
  704. X                    ins(OUPR,$4,$2,0);
  705. X                    regused[$4] = 0;
  706. X                }
  707. X            | RETURN SEMICOLON {
  708. X                    if(curr_type != PROCFLAG)
  709. X                        yyerror("Return can only be in procedures");
  710. X                    else ins(RET,0,0,0);}
  711. X            | RETURN expr SEMICOLON { 
  712. X                    if(curr_type != PROCFLAG)
  713. X                        yyerror("Return can only be in procedures");
  714. X                    else
  715. X                    {
  716. X                                        if($2 == 0)
  717. X                                        {
  718. X                                            regused[0] = 0;
  719. X                                        }
  720. X                                        else
  721. X                                        {
  722. X                                            ins(MOVR,0,$2,0);
  723. X                                            regused[0] =0;    
  724. X                                            regused[$2] =0;    
  725. X                                        }
  726. X                                        ins(RET,0,0,0);
  727. X                                    }
  728. X                    }
  729. X            ;
  730. Xoutport     : B1  {$$ = BUTTON1PORT;}
  731. X            | B2  {$$ = BUTTON2PORT;}
  732. X            | B3  {$$ = BUTTON3PORT;}
  733. X            | BALANCE {$$ = BALANCEPORT;}
  734. X            | RADARCHANGE {$$=RADARPORT;}
  735. X            | CLOAKT {$$=CLOAKPORT;}
  736. X            | SELECTE {$$=SELECTEPORT;}
  737. X            | TURNLEFT {$$=TURNLEFTPORT;}
  738. X            | TURNRIGHT {$$=TURNRIGHTPORT;}
  739. X            | TURNTO { $$ = TURNTOPORT;}
  740. X            | TARGET {$$ = TARGETPORT;}
  741. X            | QUIT {$$ = QUITPORT;}
  742. X            | REPAIRTOGGLE {$$=REPAIRTOGGLEPORT;}
  743. X            | REPAIRSELITEM {$$=REPAIRSELITEMPORT;}
  744. X            | GRAB {$$ = GRABPORT;}
  745. X            ;
  746. X
  747. Xinformation : inport {
  748. X                        int r;
  749. X                        r = getreg();
  750. X                        ins(INPR,r,$1,0);
  751. X                        $$ = r;
  752. X                    }
  753. X            | var  {
  754. X                    int r;
  755. X                    r = getreg();
  756. X                    ins(LODM,r,$1,0);
  757. X                    $$ = r;
  758. X                   }
  759. X            | item_name {
  760. X                    int r;
  761. X                    r = getreg();
  762. X                    ins(LODI,r, $1,0);
  763. X                    $$ = r;
  764. X                    }
  765. X            | IDLEL {
  766. X                    int r;
  767. X                    r = getreg();
  768. X                    ins(LODI,r,IDLE,0);
  769. X                    $$ = r;
  770. X                    }
  771. X            | w_name {
  772. X                    int r;
  773. X                    r = getreg();
  774. X                    ins(LODI,r, $1,0);
  775. X                    $$ = r;
  776. X                    }
  777. X            | INTEGER {
  778. X                    int r;
  779. X                    r = getreg();
  780. X                    ins(LODI,r,yylval,0);
  781. X                    $$ = r;
  782. X                   }
  783. X            | fcall
  784. X            ;
  785. X
  786. Xfcall: ID LP RP        {
  787. X                        int ru[NO_REGS];
  788. X                        extern char id[];
  789. X                        int r;
  790. X                        int i;
  791. X                        int sp;
  792. X
  793. X                        for(i=0;i<NO_REGS;i++)
  794. X                        {
  795. X                            ru[i] = regused[i];
  796. X                            if(ru[i])
  797. X                            {
  798. X                                ins(PUSHR,i,0,0);
  799. X                            }
  800. X                        }
  801. X                        sp = finds(id,PROCFLAG);
  802. X                        if(sp == -1)
  803. X                        {
  804. X                            bpp[bp_no] = pointer;
  805. X                            if(regused[0])
  806. X                                bpp[bp_no]++;
  807. X                            strncpy(bpn[bp_no],id,MAX_SYMB_LEN);
  808. X                            bpn[bp_no][MAX_SYMB_LEN] = 0;
  809. X                               bpl[bp_no] = errline;
  810. X                            bp_type[bp_no] = PROCFLAG;
  811. X                            bp_no++;
  812. X                            sp = 0;
  813. X                        }
  814. X
  815. X                        if(regused[0])
  816. X                        {
  817. X                            r = getreg();
  818. X                            ins(JSRI,0,sp,0);
  819. X                            ins(MOVR,r,0,0);
  820. X                        }    
  821. X                        else
  822. X                        {
  823. X                            r = 0;
  824. X                            regused[0] = 1;
  825. X                            ins(JSRI,0,sp,0);
  826. X                        }
  827. X                        for(i=NO_REGS-1;i>=0;i--)
  828. X                            if(ru[i])
  829. X                                ins(POPR,i,0,0);
  830. X
  831. X                        $$ = r;
  832. X                }
  833. X            ;
  834. Xinport      : LSHIELD {
  835. X                        $$ = SHIELD1PORT;
  836. X                        }
  837. X            | RSHIELD {
  838. X                        $$ = SHIELD2PORT;
  839. X                        }
  840. X            | BSHIELD {
  841. X                        $$ = SHIELD3PORT;
  842. X                        }
  843. X            | RADARMODE { $$ = RADARMODEPORT;
  844. X                        }
  845. X            | XPOS  { $$ = XPOSPORT;
  846. X                    }
  847. X            | YPOS  { $$ = YPOSPORT;
  848. X                    }
  849. X            | XVEL  { $$ = XVELPORT;
  850. X                    }
  851. X            | YVEL  { $$ = YVELPORT;
  852. X                    }
  853. X            | ANGLE  { $$ = ANGLEPORT;
  854. X                    }
  855. X            | ENERGY { $$ = ENERGYPORT;}
  856. X            | NUMENEMIES { $$ = NUMENEMIESPORT;}
  857. X            | ENEMYDIST {$$ = ENEMYDISTPORT;}
  858. X            | CURRWEAP {$$ = CURRWEAPPORT;}
  859. X            | REPAIRSTATE {$$ = REPAIRSTATEPORT;}
  860. X            | ENGINESTATE {$$ = ENGINESTATEPORT;}
  861. X            | LONGSTATE {$$ = LONGSTATEPORT;}
  862. X            | SHORTSTATE {$$ = SHORTSTATEPORT;}
  863. X            | JAMSTATE {$$ = JAMSTATEPORT;}
  864. X            | SOLARSTATE {$$ = SOLARSTATEPORT;}
  865. X            | TARGETSTATE {$$ = TARGETSTATEPORT;}
  866. X            | ENEMYANGLE {$$ = ENEMYANGLEPORT;}
  867. X            | ENEMYDIRECTION { $$ = ENEMYDIRECTIONPORT;}
  868. X            | ENEMYSPEED { $$ = ENEMYSPEEDPORT;}
  869. X            | SPEED { $$ = SPEEDPORT;}
  870. X            | ENEMYAVAIL { $$ = ENEMYAVAILPORT;}
  871. X            | DIRECTION { $$ = DIRECTIONPORT;}
  872. X            | ANGLETO LP expr {ins(PUSHR,$3,0,0); regused[$3] = 0;} COMMA expr { ins(PUSHR,$6,0,0); regused[$6] = 0;} RP {$$ = ANGLETOPORT;}
  873. X            | DISTTO LP expr {ins(PUSHR,$3,0,0); regused[$3] = 0;} COMMA expr { ins(PUSHR,$6,0,0); regused[$6] = 0;} RP {$$ = DISTTOPORT;}
  874. X            | ENEMYXPOS { $$ = ENEMYXPOSPORT;}
  875. X            | ENEMYYPOS { $$ = ENEMYYPOSPORT;}
  876. X            | ENEMYXVEL { $$ = ENEMYXVELPORT;}
  877. X            | ENEMYYVEL { $$ = ENEMYYVELPORT;}
  878. X            | REPAIRITEM { $$ = REPAIRITEMPORT;}
  879. X            | VELATANG LP expr {ins(PUSHR,$3,0,0); regused[$3]=0;} RP { $$ = VELATANGPORT;}
  880. X            | CURRWEAPSTATE {$$ = CURRWEAPSTATEPORT;}
  881. X            ;
  882. Xvar         : ID {
  883. X                    extern char id[];
  884. X                    int v;
  885. X                    v = lookup(id);
  886. X                    if(v == -1)
  887. X                    {
  888. X                        sprintf(buf,"%s undefined",id);
  889. X                        yyerror(buf);
  890. X                    }
  891. X                    $$ = varmem[v];
  892. X                    }
  893. X            ;
  894. X
  895. Xstart_rule  : START ID {
  896. X                    int sp;
  897. X
  898. X                    sp = finds(id,STATEFLAG);
  899. X                    if(sp == -1)
  900. X                    {
  901. X                        yyerror("Start state does not exist");
  902. X                    }
  903. X                    else
  904. X                    {
  905. X                        head.start = sp;
  906. X                    }
  907. X                    }
  908. X            ;
  909. X
  910. Xexpr:    logical_or_expr
  911. X                |    var EQUALS expr { 
  912. X                            ins(STOM,$3,$1,0);
  913. X                            regused[$3] = 0;
  914. X                            $$ = $3;
  915. X                                    }
  916. X                ;
  917. Xlogical_or_expr        :    logical_and_expr
  918. X                    |     logical_or_expr OR logical_and_expr
  919. X                        {
  920. X                            int r;
  921. X                            r = getreg();
  922. X                            ins(ORR,r,$1,$3);
  923. X                            regused[$1] = 0;
  924. X                            regused[$3] = 0;
  925. X                            $$ = r;
  926. X                        }
  927. X                    ;
  928. Xlogical_and_expr    :    inclusive_or_expr
  929. X                    |    logical_and_expr AND inclusive_or_expr
  930. X                        {
  931. X                            int r;
  932. X                            r = getreg();
  933. X                            ins(ANDR,r,$1,$3);
  934. X                            regused[$1] = 0;
  935. X                            regused[$3] = 0;
  936. X                            $$ = r;
  937. X                        }
  938. X                    ;
  939. Xinclusive_or_expr:    exclusive_or_expr
  940. X                |    inclusive_or_expr '|' exclusive_or_expr
  941. X                        {
  942. X                            int r;
  943. X                            r = getreg();
  944. X                            ins(ORR,r,$1,$3);
  945. X                            regused[$1] = 0;
  946. X                            regused[$3] = 0;
  947. X                            $$ = r;
  948. X                        }
  949. X                ;
  950. Xexclusive_or_expr:    and_expr
  951. X                |    exclusive_or_expr '^' and_expr
  952. X                        {
  953. X                            int r;
  954. X                            r = getreg();
  955. X                            ins(XORR,r,$1,$3);
  956. X                            regused[$1] = 0;
  957. X                            regused[$3] = 0;
  958. X                            $$ = r;
  959. X                        }
  960. X                ;
  961. Xand_expr        :    equality_expr
  962. X                |    and_expr '&' equality_expr
  963. X                        {
  964. X                            int r;
  965. X                            r = getreg();
  966. X                            ins(ANDR,r,$1,$3);
  967. X                            regused[$1] = 0;
  968. X                            regused[$3] = 0;
  969. X                            $$ = r;
  970. X                        }
  971. X                ;
  972. Xequality_expr    :    relational_expr
  973. X                |    equality_expr EQIV    relational_expr
  974. X                        {
  975. X                            int r;
  976. X                            r = getreg();
  977. X                            ins(EQR,r,$1,$3);
  978. X                            regused[$1] = 0;
  979. X                            regused[$3] = 0;
  980. X                            $$ = r;
  981. X                        }
  982. X                |    equality_expr NOTEQ relational_expr
  983. X                        {
  984. X                            int r;
  985. X                            r = getreg();
  986. X                            ins(EQR,r,$1,$3);
  987. X                            ins(NOTR,r,0,0);
  988. X                            regused[$1] = 0;
  989. X                            regused[$3] = 0;
  990. X                            $$ = r;
  991. X                        }
  992. X                ;
  993. Xrelational_expr    :    additive_expr
  994. X                |    relational_expr LT additive_expr
  995. X                        {
  996. X                            int r;
  997. X                            r = getreg();
  998. X                            ins(LTR,r,$1,$3);
  999. X                            regused[$1] = 0;
  1000. X                            regused[$3] = 0;
  1001. X                            $$ = r;
  1002. X                        }
  1003. X                |     relational_expr GT additive_expr
  1004. X                        {
  1005. X                            int r;
  1006. X                            r = getreg();
  1007. X                            ins(GTR,r,$1,$3);
  1008. X                            regused[$1] = 0;
  1009. X                            regused[$3] = 0;
  1010. X                            $$ = r;
  1011. X                        }
  1012. X                |     relational_expr LTE additive_expr
  1013. X                        {
  1014. X                            int r;
  1015. X                            r = getreg();
  1016. X                            ins(LTER,r,$1,$3);
  1017. X                            regused[$1] = 0;
  1018. X                            regused[$3] = 0;
  1019. X                            $$ = r;
  1020. X                        }
  1021. X                |     relational_expr GTE additive_expr
  1022. X                        {
  1023. X                            int r;
  1024. X                            r = getreg();
  1025. X                            ins(GTER,r,$1,$3);
  1026. X                            regused[$1] = 0;
  1027. X                            regused[$3] = 0;
  1028. X                            $$ = r;
  1029. X                        }
  1030. X                ;
  1031. Xadditive_expr    :    multiplicative_expr
  1032. X                |    additive_expr PLUS multiplicative_expr
  1033. X                        {
  1034. X                            int r;
  1035. X                            r = getreg();
  1036. X                            ins(ADDR,r,$1,$3);
  1037. X                            regused[$1] = 0;
  1038. X                            regused[$3] = 0;
  1039. X                            $$ = r;
  1040. X                        }
  1041. X                |    additive_expr MINUS multiplicative_expr
  1042. X                        {
  1043. X                            int r;
  1044. X                            r = getreg();
  1045. X                            ins(SUBR,r,$1,$3);
  1046. X                            regused[$1] = 0;
  1047. X                            regused[$3] = 0;
  1048. X                            $$ = r;
  1049. X                        }
  1050. X                ;
  1051. Xmultiplicative_expr:    unary_expr
  1052. X                    | multiplicative_expr TIMES unary_expr
  1053. X                        {
  1054. X                            int r;
  1055. X                            r = getreg();
  1056. X                            ins(MULR,r,$1,$3);
  1057. X                            regused[$1] = 0;
  1058. X                            regused[$3] = 0;
  1059. X                            $$ = r;
  1060. X                        }
  1061. X                    | multiplicative_expr DIV unary_expr
  1062. X                        {
  1063. X                            int r;
  1064. X                            r = getreg();
  1065. X                            ins(DIVR,r,$1,$3);
  1066. X                            regused[$1] = 0;
  1067. X                            regused[$3] = 0;
  1068. X                            $$ = r;
  1069. X                        }
  1070. X                    | multiplicative_expr MOD unary_expr
  1071. X                        {
  1072. X                            int r;
  1073. X                            r = getreg();
  1074. X                            ins(MODR,r,$1,$3);
  1075. X                            regused[$1] = 0;
  1076. X                            regused[$3] = 0;
  1077. X                            $$ = r;
  1078. X                        }
  1079. X                    ;
  1080. Xunary_expr    :    primary_expr
  1081. X            |    NOT primary_expr
  1082. X                        {
  1083. X                            int r;
  1084. X                            ins(NOTR,$2,0,0);
  1085. X                            regused[$2] = 0;
  1086. X                            $$ = $2;
  1087. X                        }
  1088. X            |    MINUS primary_expr
  1089. X                        {
  1090. X                            int r;
  1091. X                            r = getreg();
  1092. X                            ins(SUBR,r,0,$2);
  1093. X                            regused[$2] = 0;
  1094. X                            $$ = r;
  1095. X                        }
  1096. X            ;
  1097. Xprimary_expr    :    information {$$ = $1;}
  1098. X                |    LP expr RP {$$ = $2;}
  1099. X                ;
  1100. X
  1101. X%%
  1102. Xchar fn[40] = "stdin";
  1103. Xchar in[40],out[40];
  1104. Xint deb=0;
  1105. Xchar deg[40];
  1106. X
  1107. Xparse(f,d)
  1108. Xchar *f;
  1109. Xint d;
  1110. X{
  1111. X
  1112. X    int i;
  1113. X    FILE *hall_fp;
  1114. X
  1115. X
  1116. X
  1117. X    errors = 0;
  1118. X    errline = 1;
  1119. X    no_vars = 0;
  1120. X    no_globals = 0;
  1121. X    max_vars = 0;
  1122. X    no_locals = 0;
  1123. X    pointer = 0;
  1124. X    no_states = 0;
  1125. X    bpsp = 0;
  1126. X    bp_no = 0;
  1127. X    for(i=0;i<NUM_ITEMS;i++)
  1128. X    {
  1129. X        head.qual[i] = -1;
  1130. X    }
  1131. X    for(i=0;i<NO_WEAPONS;i++)
  1132. X        head.does_have_weap[i] = 0;
  1133. X    for(i=0;i<NO_REGS;i++)
  1134. X        regused[i] =0;
  1135. X    if(rindex(f,'.') && !strcmp(".npc",rindex(f,'.')))
  1136. X    {
  1137. X        *((char *)rindex(f,'.')) = '\0';
  1138. X    }
  1139. X    strcpy(in,f);
  1140. X
  1141. X    strcpy(out,NPCDIR);
  1142. X
  1143. X    if(rindex(f,'/'))
  1144. X    {
  1145. X        strcat(out,rindex(f,'/'));
  1146. X    }
  1147. X    else
  1148. X        strcat(out,f);
  1149. X
  1150. X    strcat(in,".npc");
  1151. X    yyin = fopen(in,"r");
  1152. X    if(!yyin)
  1153. X    {
  1154. X        perror("Can't open source file");
  1155. X        return 1;
  1156. X    }
  1157. X    strcat(out,".no");
  1158. X
  1159. X    seteuid(euid);
  1160. X    hall_fp=fopen(out,"rb");
  1161. X    if(hall_fp)
  1162. X    {
  1163. X        hall_of_fame(hall_fp);
  1164. X        seteuid(euid);
  1165. X    }
  1166. X    yyout = fopen(out,"wb");
  1167. X    seteuid(getuid());
  1168. X    if(!yyout)
  1169. X    {
  1170. X        perror("Can't open output file");
  1171. X        fclose(yyin);
  1172. X        return 1;
  1173. X    }
  1174. X    if(d)
  1175. X    {
  1176. X        strcpy(deg,f);
  1177. X        strcat(deg,".deb");
  1178. X        dfp = fopen(deg,"w");
  1179. X        if(!dfp)
  1180. X        {
  1181. X            perror("Can't open debug file");
  1182. X            fclose(yyout);
  1183. X            fclose(yyin);
  1184. X            return 1;
  1185. X        }
  1186. X    }
  1187. X    strcpy(fn,in);
  1188. X    fprintf(stderr,"***%s***\n",in);
  1189. X    yyparse();    
  1190. X    fclose(yyin);
  1191. X    fclose(yyout);
  1192. X    if(d)
  1193. X    {
  1194. X        fclose(dfp);
  1195. X        dfp = NULL;
  1196. X    }
  1197. X    if(errors)
  1198. X        unlink(out);
  1199. X}
  1200. X
  1201. Xmain(argc,argv)
  1202. Xint argc;
  1203. Xchar *argv[];
  1204. X{
  1205. X    extern int yydebug;
  1206. X    int i;
  1207. X    int d = 0;
  1208. X
  1209. X    euid = geteuid();
  1210. X    seteuid(getuid());
  1211. X    yyin = stdin;
  1212. X    yyout = stdout;
  1213. X
  1214. X    yydebug = 1;
  1215. X    if(argc < 2)
  1216. X    {
  1217. X        yyparse();
  1218. X        return 0;
  1219. X    }
  1220. X    for(i=1;i<argc;i++)
  1221. X    {
  1222. X        if(argv[i][0] == '-' && argv[i][1] == 'd')
  1223. X            d = 1;
  1224. X        else
  1225. X            parse(argv[i],d);
  1226. X    }
  1227. X    return 0;
  1228. X}
  1229. X
  1230. Xvoid yyerror(str)
  1231. Xchar *str;
  1232. X{
  1233. X    fprintf(stderr,"%s - Error in line %d: %s\n",fn,errline,str);
  1234. X    errors = 1;
  1235. X}
  1236. Xvoid yywarn(str)
  1237. Xchar *str;
  1238. X{
  1239. X    fprintf(stderr,"%s - Warning in line %d: %s\n",fn,errline,str);
  1240. X}
  1241. X
  1242. Xvoid emit(s)
  1243. Xchar *s;
  1244. X{
  1245. X    fprintf(yyout,"%s",s);
  1246. X}
  1247. X
  1248. Xaddvar(v,mode)
  1249. Xchar *v;
  1250. Xint mode;
  1251. X{
  1252. X    int i;
  1253. X
  1254. X    if(mode == GLOBAL)
  1255. X    {
  1256. X        for(i=0;i<no_vars;i++)
  1257. X        {
  1258. X            if(!strncmp(vars[i],v,MAX_SYMB_LEN))
  1259. X            return -1;
  1260. X        }
  1261. X    }
  1262. X    strncpy(vars[no_vars],v,MAX_SYMB_LEN);
  1263. X    vars[no_vars][MAX_SYMB_LEN] = 0;
  1264. X    varmem[no_vars++] = max_vars++;
  1265. X    /*if(no_vars > max_vars)
  1266. X        max_vars++;
  1267. X*/
  1268. X    if(mode == GLOBAL)
  1269. X        no_globals++;
  1270. X    else
  1271. X        no_locals++;
  1272. X/*
  1273. Xfprintf(stderr, "added %s in mode %d\n", v, mode);
  1274. Xfprintf(stderr, "no_vars=%d\nmax_vars=%d\nglobs=%d\nlocs=%d\n", no_vars, max_vars, no_globals, no_locals);
  1275. X{ int i;
  1276. X    for(i=0; i < no_vars; i++)
  1277. X        printf("var[%d]=%s mem = %d\n", i, vars[i],varmem[i]);
  1278. X}
  1279. X*/
  1280. X    return 1;
  1281. X}
  1282. X
  1283. Xkill_locals()
  1284. X{
  1285. X    no_vars = no_globals;
  1286. X    no_locals=0;
  1287. X}
  1288. X
  1289. Xlookup(v)
  1290. Xchar *v;
  1291. X{
  1292. X    int i;
  1293. X
  1294. X    for(i=no_vars-1;i>=0;i--)
  1295. X    {
  1296. X        if(!strncmp(vars[i],v,MAX_SYMB_LEN))
  1297. X        return i;
  1298. X    }
  1299. X    return -1;
  1300. X}
  1301. X
  1302. Xgetreg()
  1303. X{
  1304. X    int i=0;
  1305. X    while(regused[i] && i < NO_REGS) i++;
  1306. X    if(i == NO_REGS)
  1307. X    {
  1308. X        yyerror("Out of registers");
  1309. X        return -1;
  1310. X    }
  1311. X    regused[i] = 1;
  1312. X    return i;
  1313. X}
  1314. X
  1315. Xins(i,o1,o2,o3)
  1316. Xint i,o1,o2,o3;
  1317. X{
  1318. X    if(i == NOTR && mem[pointer-1].ins == NOTR && mem[pointer-1].o1 == o1)
  1319. X    {
  1320. X        pointer--;
  1321. X        return;
  1322. X    }
  1323. X
  1324. X    mem[pointer].ins = i;
  1325. X    mem[pointer].o1 = o1;
  1326. X    mem[pointer].o2 = o2;
  1327. X    mem[pointer].o3 = o3;
  1328. X    sprintf(buf,"%d\t%s %d,%d,%d\n",pointer,ins_name[i],o1,o2,o3);
  1329. X    pointer++;
  1330. X}
  1331. X
  1332. Xaddstate(s,p,pors)
  1333. Xchar *s;
  1334. Xint p;
  1335. Xint pors;
  1336. X{
  1337. X    int i;
  1338. X
  1339. X    for(i=0;i<no_states;i++)
  1340. X    {
  1341. X        if(!strncmp(states[i],s,MAX_SYMB_LEN))
  1342. X        return -1;
  1343. X    }
  1344. X    proc[no_states] = pors;
  1345. X    sp[no_states] = p;
  1346. X    strncpy(states[no_states],s,MAX_SYMB_LEN);
  1347. X    states[no_states++][MAX_SYMB_LEN] = 0;
  1348. X    return 1;
  1349. X}
  1350. Xfinds(s,pors)
  1351. Xchar *s;
  1352. Xint pors;
  1353. X{
  1354. X    int i;
  1355. X    for(i=0;i<no_states;i++)
  1356. X    {
  1357. X        if(!strncmp(states[i],s,MAX_SYMB_LEN) && (pors == proc[i] || pors == ANY))
  1358. X        {
  1359. X        return sp[i];
  1360. X        }
  1361. X    }
  1362. X    return -1;
  1363. X}
  1364. X
  1365. Xpushbp(i)
  1366. Xint i;
  1367. X{
  1368. X    bps[bpsp++] = i;
  1369. X}
  1370. X
  1371. Xpopbp()
  1372. X{
  1373. X    return(bps[--bpsp]);
  1374. X}
  1375. X
  1376. Xhall_of_fame(npc_fp)
  1377. XFILE *npc_fp;
  1378. X{
  1379. X    char buf[160], buf2[160];
  1380. X    struct header h, head;
  1381. X    int dude_written,same;
  1382. X    FILE *fp, *fp2;
  1383. X    
  1384. X
  1385. X    buf[0]=buf2[0]=0;
  1386. X    fread(&h, sizeof(struct header), 1, npc_fp);
  1387. X    fclose(npc_fp);
  1388. X    strcpy(buf, SAVEDIR);
  1389. X    strcat(buf, "hall.of.fame.npc");
  1390. X    strcpy(buf2, buf);
  1391. X    strcat(buf2, "2");
  1392. Xseteuid(euid);
  1393. X    fp=fopen(buf,"rb");
  1394. Xseteuid(getuid());
  1395. X    if(!fp)
  1396. X    {
  1397. Xseteuid(euid);
  1398. X        fp=fopen(buf,"wb");
  1399. Xseteuid(getuid());
  1400. X        if(!fp)
  1401. X        {
  1402. X                perror("Cannot create npc hall of fame\n");
  1403. X                exit(0);
  1404. X        }
  1405. X        fwrite(&h, sizeof(struct header), 1, fp);
  1406. X        fclose(fp);
  1407. X        return;
  1408. X    }
  1409. X
  1410. X    dude_written=0;
  1411. X
  1412. Xseteuid(euid);
  1413. X    fp2=fopen(buf2, "wb");
  1414. Xseteuid(getuid());
  1415. Xif(!fp2)
  1416. X{
  1417. X    perror("Can't open temp hall of fame file");
  1418. X    exit(1);
  1419. X}
  1420. X    while(fread(&head, sizeof(struct header), 1, fp))
  1421. X    {
  1422. X        same = 0;
  1423. X        if(!strcmp(h.Name, head.Name))
  1424. X        {
  1425. X            if(!dude_written && (h.kills > head.kills || 
  1426. X                (h.kills == head.kills && h.cash_earned > head.cash_earned)))
  1427. X                fwrite(&h, sizeof(struct header), 1, fp2);
  1428. X            else
  1429. X                if(!dude_written) fwrite(&head, sizeof(struct header), 1, fp2);
  1430. X            dude_written = 1;
  1431. X            same = 1;
  1432. X        }
  1433. X        else
  1434. X        {
  1435. X            if(!dude_written && (h.kills > head.kills || 
  1436. X                (h.kills == head.kills && h.cash_earned > head.cash_earned)))
  1437. X            {
  1438. X                fwrite(&h, sizeof(struct header), 1, fp2);
  1439. X                dude_written = 1;
  1440. X            }
  1441. X        }
  1442. X        if(!same) 
  1443. X            fwrite(&head, sizeof(struct header), 1, fp2);
  1444. X    }
  1445. X    if(!dude_written)
  1446. X            fwrite(&h, sizeof(struct header), 1, fp2);     
  1447. X    fclose(fp);
  1448. X    fclose(fp2);
  1449. X    unlink(buf);
  1450. X    rename(buf2, buf);
  1451. X}
  1452. END_OF_FILE
  1453. if test 25960 -ne `wc -c <'parse.y'`; then
  1454.     echo shar: \"'parse.y'\" unpacked with wrong size!
  1455. fi
  1456. # end of 'parse.y'
  1457. fi
  1458. if test -f 'pcomp.c' -a "${1}" != "-c" ; then 
  1459.   echo shar: Will not clobber existing file \"'pcomp.c'\"
  1460. else
  1461. echo shar: Extracting \"'pcomp.c'\" \(16260 characters\)
  1462. sed "s/^X//" >'pcomp.c' <<'END_OF_FILE'
  1463. X/* pcomp.c - *** routines for the psuedo computer */
  1464. Xstatic char sccs_id[] = "@(#)pcomp.c 1.1 93/01/26 XMPB";
  1465. X
  1466. X#include <math.h>    
  1467. X#include "player.h"
  1468. X#include "mnemonics.h"
  1469. X
  1470. Xextern int euid;
  1471. Xextern winptr first_win;
  1472. Xextern int mycostab[];
  1473. Xextern int num_npcs_windows;
  1474. Xextern int num_npcs_alive;
  1475. Xextern int num_alive;
  1476. X
  1477. XFILE *tfp = stdout;
  1478. X
  1479. Xstruct comp *create_comp(ds,cs,start)
  1480. Xint ds,cs,start;
  1481. X{
  1482. X    struct comp *c;
  1483. X
  1484. X    c = (struct comp *)malloc(sizeof(struct comp));
  1485. X    if(!c) 
  1486. X        return NULL;
  1487. X
  1488. X    c->data = (int *)malloc(ds*sizeof(int));
  1489. X    if(!c->data)
  1490. X    {
  1491. X        free(c);
  1492. X        return NULL;
  1493. X    }
  1494. X    c->text = (struct ins *)malloc(cs*sizeof(struct ins));
  1495. X    if(!c->text)
  1496. X    {
  1497. X        free(c->data);
  1498. X        free(c);
  1499. X        return NULL;
  1500. X    }
  1501. X    c->sp =0;
  1502. X    c->pc = start;
  1503. X    return c;
  1504. X}
  1505. X
  1506. X#define R1    c->regs[ci->o1]
  1507. X#define R2    c->regs[ci->o2]
  1508. X#define R3    c->regs[ci->o3]
  1509. X
  1510. Xexecute_ins(w,c)
  1511. Xwinptr w;
  1512. Xstruct comp *c;
  1513. X{
  1514. X    int r = 1;
  1515. X    struct ins *ci;
  1516. X
  1517. X    if(w->comp->turnto != 0 && w->comp->turnto != -500)
  1518. X    {
  1519. X/*
  1520. Xprintf("Turning to %d\n",w->comp->turnto);
  1521. X*/
  1522. X        if(w->comp->turnto > 0)
  1523. X        {
  1524. X            start_turn_right(w);
  1525. X        }
  1526. X        else
  1527. X        {
  1528. X            start_turn_left(w);
  1529. X        }    
  1530. X
  1531. X        if(w->angle_v > 15 || w->angle_v < -15)
  1532. X            stop_turn_left(w);
  1533. X
  1534. X            w->comp->turnto = w->comp->turnabs - w->angle;
  1535. X            if(w->comp->turnto > 180)
  1536. X            {
  1537. X                w->comp->turnto -= 360;
  1538. X            }
  1539. X            if(w->comp->turnto < -180)
  1540. X            {
  1541. X                w->comp->turnto += 360;
  1542. X            }
  1543. X/*
  1544. X        w->comp->turnto -= w->angle - w->comp->turnabs;
  1545. X        w->comp->turnabs = w->angle;
  1546. X*/
  1547. X    }
  1548. X    else if(w->comp->turnto != -500)
  1549. X    {
  1550. X        w->comp->turnto = -500;
  1551. X        stop_turn_left(w);
  1552. X    }
  1553. X#ifdef TRACE
  1554. Xprintf("%s\n", w->Name);
  1555. Xprintf("%d\n",c->pc);
  1556. X#endif
  1557. X    ci = &(c->text[c->pc++]);
  1558. X
  1559. X
  1560. X    switch(ci->ins)
  1561. X    {
  1562. X        case ANDR:
  1563. X            R1 = R2 & R3;
  1564. X            break;
  1565. X        case LODI:
  1566. X            R1 = ci->o2;
  1567. X            break;
  1568. X        case LODM:
  1569. X            R1 = c->data[ci->o2];
  1570. X            break;
  1571. X        case STOM:
  1572. X            c->data[ci->o2] = R1;
  1573. X            break;
  1574. X        case XORR:
  1575. X            R1 = R2 ^ R3;
  1576. X            break;
  1577. X        case LTER:
  1578. X            R1 = R2 <= R3;
  1579. X            break;
  1580. X        case ORR:
  1581. X            R1 = R2 | R3;
  1582. X            break;
  1583. X        case JMPI:
  1584. X            c->pc = ci->o2;
  1585. X            break;
  1586. X        case EQR:
  1587. X            R1 = R2 == R3;
  1588. X            break;
  1589. X        case LTR:
  1590. X            R1 = R2 < R3;
  1591. X            break;
  1592. X        case GTR:
  1593. X            R1 = R2 > R3;
  1594. X            break;
  1595. X        case GTER:
  1596. X            R1 = R2 >= R3;
  1597. X            break;
  1598. X        case NOTR:
  1599. X            R1 = !R1;
  1600. X            break;
  1601. X        case JMPC:
  1602. X            if(R1)
  1603. X            {
  1604. X                c->pc = ci->o2;
  1605. X            }
  1606. X            break;
  1607. X        case JSRC:
  1608. X            if(R1)
  1609. X            {
  1610. X                c->stack[c->sp++] = c->pc;
  1611. X                c->pc = ci->o2;
  1612. X            }
  1613. X            break;
  1614. X        case JSRI:
  1615. X            c->stack[c->sp++] = c->pc;
  1616. X            c->pc = ci->o2;
  1617. X            break;
  1618. X        case RET:
  1619. X            c->pc = c->stack[--c->sp];
  1620. X            break;
  1621. X        case RETC:
  1622. X            if(R1)
  1623. X                c->pc = c->stack[--c->sp];
  1624. X            break;
  1625. X        case MOVR:
  1626. X            R1 = R2;
  1627. X            break;
  1628. X        case ADDR:
  1629. X            R1 = R2 + R3;
  1630. X            break;
  1631. X        case SUBR:
  1632. X            R1 = R2 - R3;
  1633. X            break;
  1634. X        case MULR:
  1635. X            R1 = R2 * R3;
  1636. X            break;
  1637. X        case DIVR:
  1638. X            if(R3 == 0)
  1639. X                R1 = 0;
  1640. X            else
  1641. X            R1 = R2 / R3;
  1642. X            break;
  1643. X        case INPR:
  1644. X            R1 = input_port(w,ci->o2);
  1645. X            break;
  1646. X        case OUPR:
  1647. X            output_port(w,ci->o2,R1);
  1648. X            break;
  1649. X        case MODR:
  1650. X            if(R3 == 0)
  1651. X                R1 = 0;
  1652. X            else
  1653. X            R1 = R2 % R3;
  1654. X#ifdef TRACE
  1655. Xprintf("the mod of %d with %d is %d\n", R1, R2, R3);
  1656. X#endif
  1657. X            break;
  1658. X        case PUSHR:
  1659. X            c->stack[c->sp++] = R1;
  1660. X            break;
  1661. X        case WAIT:
  1662. X            r = 0;
  1663. X            break;
  1664. X        case POPR:
  1665. X            if(c->sp == 0)
  1666. X            {
  1667. X                printf("%s Stack Underflow instruction %d\n",w->Name,c->pc);
  1668. X                xmpb_error("");
  1669. X            }
  1670. X             R1 = c->stack[--c->sp];
  1671. X            break;
  1672. X        case PUSHM:
  1673. X            c->stack[c->sp++] = c->data[ci->o2];
  1674. X            break;
  1675. X        case POPM:
  1676. X            if(c->sp == 0)
  1677. X            {
  1678. X                printf("%s Stack Underflow instruction %d\n",w->Name,c->pc);
  1679. X                xmpb_error("");
  1680. X            }
  1681. X             c->data[ci->o2] = c->stack[--c->sp];
  1682. X            break;
  1683. X        default:
  1684. X            fprintf(stderr,"\n%s instruction %d opcode %d - Illegal Instruction sp = %d\n",w->Name,w->comp->pc,ci->ins,c->sp);
  1685. X            xmpb_error("\n\nExecution Halted\n");
  1686. X            break;
  1687. X    }
  1688. X#ifdef TRACE
  1689. X{ int i;
  1690. X
  1691. X    switch(ci->ins)
  1692. X    {
  1693. X        case EQR:
  1694. X        case XORR:
  1695. X        case LTR:
  1696. X        case LTER:
  1697. X        case GTR:
  1698. X        case GTER:
  1699. X        case ANDR:
  1700. X        case ORR:
  1701. X        case ADDR:
  1702. X        case SUBR:
  1703. X        case MODR:
  1704. X        case MULR:
  1705. X        case DIVR:
  1706. X            fprintf(tfp,"%d %s r%d <- r%d r%d\n",i,ins_name[ci->ins],ci->o1,ci->o2,ci->o3);
  1707. X            break;
  1708. X        case WAIT:
  1709. X        case RET:
  1710. X            fprintf(tfp,"%d %s\n",i,ins_name[ci->ins]);
  1711. X            break;
  1712. X        case LODM:
  1713. X        case STOM:
  1714. X        case INPR:
  1715. X        case LODI:
  1716. X        case OUPR:
  1717. X        case JMPC:
  1718. X        case JSRC:
  1719. X            fprintf(tfp,"%d %s r%d %d\n",i,ins_name[ci->ins],ci->o1,ci->o2);
  1720. X            break;
  1721. X        case JMPI:
  1722. X        case JSRI:
  1723. X        case PUSHM:
  1724. X        case POPM:
  1725. X            fprintf(tfp,"%d %s %d\n",i,ins_name[ci->ins],ci->o2);
  1726. X            break;
  1727. X        case PUSHR:
  1728. X        case NOTR:
  1729. X        case POPR:
  1730. X            fprintf(tfp,"%d %s r%d\n",i,ins_name[ci->ins],ci->o1);
  1731. X            break;
  1732. X
  1733. X        default:
  1734. X            fprintf(stderr,"%d Trace error\n",i);
  1735. X    }
  1736. X    for(i=0; i < NO_REGS; i++)
  1737. X        printf("r[%d]=%d  ", i, w->comp->regs[i]);
  1738. X    printf("\n-------\n");
  1739. X}
  1740. X#endif
  1741. X
  1742. X    return r;
  1743. X}
  1744. X
  1745. Xint input_port(w,i)
  1746. Xwinptr w;
  1747. Xint i;
  1748. X{
  1749. X    int v;
  1750. X    switch(i)
  1751. X    {
  1752. X        case SHIELD1PORT:
  1753. X            v = w->ls_curr;
  1754. X            break;
  1755. X        case SHIELD2PORT:
  1756. X            v = w->rs_curr;
  1757. X            break;
  1758. X        case SHIELD3PORT:
  1759. X            v = w->bs_curr;
  1760. X            break;
  1761. X         case RADARMODEPORT:
  1762. X            v = 2 - w->short_range_radar;
  1763. X            break;
  1764. X        case XPOSPORT:
  1765. X            v = w->sx;
  1766. X            break;
  1767. X        case YPOSPORT:
  1768. X            v = w->sy;
  1769. X            break;
  1770. X        case XVELPORT:
  1771. X            v = w->xv/32768;
  1772. X            break;
  1773. X        case YVELPORT:
  1774. X            v = w->yv/32768;
  1775. X            break;
  1776. X        case ANGLEPORT:
  1777. X            v = w->angle;
  1778. X            break;
  1779. X        case TARGETSTATEPORT:
  1780. X            v = w->state[TC];
  1781. X            break;
  1782. X        case SOLARSTATEPORT:
  1783. X            v = w->state[SOLAR];
  1784. X            break;
  1785. X        case JAMSTATEPORT:
  1786. X            v = w->state[CLOAK];
  1787. X            break;
  1788. X        case SHORTSTATEPORT:
  1789. X            v = w->state[SHORTRR];
  1790. X            break;
  1791. X        case LONGSTATEPORT:
  1792. X            v = w->state[LONGRR];
  1793. X            break;
  1794. X        case ENGINESTATEPORT:
  1795. X            v = w->state[ENGINE];
  1796. X            break;
  1797. X        case REPAIRSTATEPORT:
  1798. X            v = w->state[REPAIR];
  1799. X            break;
  1800. X        case CURRWEAPPORT:
  1801. X            v = w->curr_weap;
  1802. X            break;
  1803. X        case ENERGYPORT:
  1804. X            v = w->energy_curr;
  1805. X            break;
  1806. X        case ENEMYSPEEDPORT:
  1807. X            if(w->comp->curr_enemy == -1 || !w->comp->ce || !cansee(w,w->comp->ce)) 
  1808. X            {
  1809. X                v = 0;
  1810. X            }
  1811. X            else
  1812. X                v = (int)(sqrt((double)(w->comp->ce->xv/32768*w->comp->ce->xv/32768)+(double)(w->comp->ce->yv/32768*w->comp->ce->yv/32768)));
  1813. X            break;
  1814. X        case SPEEDPORT:
  1815. X            v = (int)(sqrt((double)(w->xv/32768*w->xv/32768)+(double)(w->yv/32768*w->yv/32768)));
  1816. X            break;
  1817. X        case NUMENEMIESPORT:
  1818. X        {
  1819. X            winptr t;
  1820. X            int i,j,k,l,d;
  1821. X            int relx,rely;
  1822. X
  1823. X            t = first_win;
  1824. X            i = 0;
  1825. X            l = 0;
  1826. X            while(t)
  1827. X            {
  1828. X                if(t == w)
  1829. X                    goto argh;
  1830. X                {
  1831. X                    relx = w->sx - t->sx;
  1832. X                    rely = w->sy - t->sy;
  1833. X            
  1834. X                    d = (relx*relx+rely*rely);
  1835. X            
  1836. X                    if(!cansee(w,t))
  1837. X                    {
  1838. X                        goto argh;
  1839. X                    }
  1840. X
  1841. X                    j = 0;
  1842. X                    while((w->comp->close[j] < d) && (j < i))
  1843. X                        j++;
  1844. X                    for(k=i;k>j;k--)
  1845. X                    {
  1846. X                        w->comp->close[k] = w->comp->close[k-1];
  1847. X                        w->comp->closest[k] = w->comp->closest[k-1];
  1848. X                        w->comp->cptr[k] = w->comp->cptr[k-1];
  1849. X                    }
  1850. X                    w->comp->closest[j] = l;
  1851. X                    w->comp->close[j] = d;
  1852. X                    w->comp->cptr[j] = t;
  1853. X                    i++;
  1854. X                }
  1855. Xargh:
  1856. X                l++;
  1857. X                t = t->next;
  1858. X            }
  1859. X#ifdef TRACE
  1860. X    for(j=0;j<MAXHOST;j++)
  1861. X    {
  1862. X        printf("%d ",w->comp->closest[j]);
  1863. X    }
  1864. X    printf("\n");
  1865. X#endif
  1866. X            w->comp->no_seen = i;
  1867. X            v = i;
  1868. X            break;
  1869. X        }
  1870. X        case ENEMYAVAILPORT:
  1871. X        {
  1872. X            if(w->comp->curr_enemy == -1 || !w->comp->ce) v = 0;
  1873. X            else
  1874. X                v = cansee(w,w->comp->ce);
  1875. X            break;
  1876. X        }
  1877. X        case ENEMYDISTPORT:
  1878. X        {
  1879. X            int relx,rely;
  1880. X
  1881. X            if(w->comp->curr_enemy == -1 || !w->comp->ce || !cansee(w,w->comp->ce)) 
  1882. X            {
  1883. X                v = 0;
  1884. X            }
  1885. X            else
  1886. X            {
  1887. X                if(jamming(w,w->comp->ce))
  1888. X                {
  1889. X                    relx = w->sx - (rand()%(WORLDW*2)-WORLDW);
  1890. X                    rely = w->sy - (rand()%(WORLDH*2)-WORLDH);
  1891. X                }
  1892. X                else
  1893. X                {
  1894. X                    relx = w->sx - w->comp->ce->sx;
  1895. X                    rely = w->sy - w->comp->ce->sy;
  1896. X                }
  1897. X                v = (int)sqrt((double)(relx*relx+rely*rely));
  1898. X            }
  1899. X            break;
  1900. X        }
  1901. X        case ENEMYANGLEPORT:
  1902. X            
  1903. X            if(w->comp->curr_enemy == -1 ||!w->comp->ce ||  !cansee(w,w->comp->ce)) 
  1904. X            {
  1905. X                v = -1;
  1906. X            }
  1907. X            else
  1908. X            if(w->comp->ce->sx == w->sx && w->comp->ce->sy == w->sy) 
  1909. X                v = 0;
  1910. X            else
  1911. X            {
  1912. X                int x,y;
  1913. X                if(jamming(w,w->comp->ce))
  1914. X                {
  1915. X                    x = (rand()%(WORLDW*2)-WORLDW);
  1916. X                    y = (rand()%(WORLDH*2)-WORLDH);
  1917. X                }    
  1918. X                else
  1919. X                {
  1920. X                    x = w->comp->ce->sx;
  1921. X                    y = w->comp->ce->sy;
  1922. X                }
  1923. X                v = (int)(180.0+180.0*atan2(-(double)(x-w->sx),-(double)(y-w->sy))/M_PI);
  1924. X            }
  1925. X            break;
  1926. X        case DIRECTIONPORT:
  1927. X            if(w->xv/32768 == 0)
  1928. X            {
  1929. X                if(w->yv > 0)
  1930. X                    v = 0;
  1931. X                else
  1932. X                    v = 180;
  1933. X            }
  1934. X            else if(w->yv/32768 == 0)
  1935. X            {
  1936. X                if(w->xv > 0)
  1937. X                    v = 90;
  1938. X                else
  1939. X                    v = 270;
  1940. X            }
  1941. X            else
  1942. X            v = (int)(180+180.0*atan2(-(double)(w->xv/32768),-(double)(w->yv/32768))/M_PI);
  1943. X            break;
  1944. X        case ANGLETOPORT:
  1945. X        {
  1946. X            int *x,*y;
  1947. X    
  1948. X            x = &(w->comp->stack[w->comp->sp-2]);
  1949. X            y = &(w->comp->stack[w->comp->sp-1]);
  1950. X
  1951. X            v = (int)(180+180.0*atan2((double)(w->sx- *x),(double)(w->sy- *y))/M_PI);
  1952. X            w->comp->sp-=2;
  1953. X            break;
  1954. X        }
  1955. X        case DISTTOPORT:
  1956. X        {
  1957. X            int relx,rely;
  1958. X            int *x,*y;
  1959. X    
  1960. X            x = &(w->comp->stack[w->comp->sp-2]);
  1961. X            y = &(w->comp->stack[w->comp->sp-1]);
  1962. X
  1963. X            relx = w->sx - *x;
  1964. X            rely = w->sy - *y;
  1965. X
  1966. X            v = (int)sqrt((double)(relx*relx+rely*rely));
  1967. X
  1968. X            w->comp->sp-=2;
  1969. X            break;
  1970. X        }
  1971. X        case ENEMYDIRECTIONPORT: 
  1972. X            if(!w->comp->ce) break;
  1973. X            if(w->comp->ce->xv/32768 == 0)
  1974. X            {
  1975. X                if(w->comp->ce->yv > 0)
  1976. X                    v = 0;
  1977. X                else
  1978. X                    v = 180;
  1979. X            }
  1980. X            else if(w->comp->ce->yv/32768 == 0)
  1981. X            {
  1982. X                if(w->comp->ce->xv > 0)
  1983. X                    v = 90;
  1984. X                else
  1985. X                    v = 270;
  1986. X            }
  1987. X            else
  1988. X            v = (int)(180+180.0*atan2(-(double)(w->comp->ce->xv/32768),-(double)(w->comp->ce->yv/32768))/M_PI)
  1989. X;
  1990. X            break;
  1991. X        case ENEMYXVELPORT:
  1992. X            if(w->comp->curr_enemy == -1 ||!w->comp->ce ||  !cansee(w,w->comp->ce)) 
  1993. X            {
  1994. X                v = -1;
  1995. X            }
  1996. X            else
  1997. X                v = w->comp->ce->xv/32768;
  1998. X            break;
  1999. X        case ENEMYYVELPORT:
  2000. X            if(w->comp->curr_enemy == -1 ||!w->comp->ce ||  !cansee(w,w->comp->ce)) 
  2001. X            {
  2002. X                v = -1;
  2003. X            }
  2004. X            else
  2005. X                v = w->comp->ce->yv/32768;
  2006. X            break;
  2007. X        case ENEMYXPOSPORT:
  2008. X            if(w->comp->curr_enemy == -1 ||!w->comp->ce ||  !cansee(w,w->comp->ce)) 
  2009. X            {
  2010. X                v = -1;
  2011. X            }
  2012. X            else
  2013. X                v = w->comp->ce->sx;
  2014. X            break;
  2015. X        case ENEMYYPOSPORT:
  2016. X            if(w->comp->curr_enemy == -1 ||!w->comp->ce ||  !cansee(w,w->comp->ce)) 
  2017. X            {
  2018. X                v = -1;
  2019. X            }
  2020. X            else
  2021. X                v = w->comp->ce->sy;
  2022. X            break;
  2023. X        case REPAIRITEMPORT:
  2024. X                v = w->rep_which;
  2025. X            break;
  2026. X        case VELATANGPORT:
  2027. X        {
  2028. X            int dir, speed, *ang;
  2029. X                
  2030. X            if(w->xv/32768 == 0)
  2031. X            {
  2032. X                if(w->yv > 0)
  2033. X                    dir = 0;
  2034. X                else
  2035. X                    dir = 180;
  2036. X            }
  2037. X            else if(w->yv/32768 == 0)
  2038. X            {
  2039. X                if(w->xv > 0)
  2040. X                    dir = 90;
  2041. X                else
  2042. X                    dir = 270;
  2043. X            }
  2044. X            else
  2045. X            dir = (int)(180+180.0*atan2(-(double)(w->xv/32768),-(double)(w->yv/32768))/M_PI)
  2046. X;
  2047. X            speed = (int)(sqrt((double)(w->xv/32768*w->xv/32768)+(double)(w->yv/32768*w->yv/32768)));
  2048. X            ang= &(w->comp->stack[w->comp->sp-1]);
  2049. X            if(dir >= *ang)
  2050. X                v = speed * (mycostab[(dir - *ang)%360])/32768;
  2051. X            else 
  2052. X                v = speed * (mycostab[(*ang - dir)%360])/32768;
  2053. X        }
  2054. X            w->comp->sp-=1;
  2055. X            break;
  2056. X        case CURRWEAPSTATEPORT:
  2057. X            if(w->load_status[w->curr_weap]==-1)
  2058. X                v = 0;
  2059. X            else
  2060. X                v = 1;
  2061. X            break;
  2062. X        default:
  2063. X            fprintf(stderr,"%s ----\n",w->Name);
  2064. X            xmpb_error("Illegal Input port");
  2065. X            break;
  2066. X    }
  2067. X#ifdef TRACE
  2068. Xprintf("inport %d %d\n",i,v);
  2069. X#endif
  2070. X    return v;
  2071. X}    
  2072. X
  2073. Xoutput_port(w,o,v)
  2074. Xwinptr w;
  2075. Xint o,v;
  2076. X{
  2077. X#ifdef TRACE
  2078. Xprintf("ouport %d -> %d\n",v,o);
  2079. X#endif
  2080. X    switch(o)
  2081. X    {
  2082. X        case BUTTON1PORT:
  2083. X            w->b1 = v;
  2084. X            w->cloaking = 0;
  2085. X            break;
  2086. X        case BUTTON2PORT:
  2087. X            w->b2 = v;
  2088. X            break;
  2089. X        case BUTTON3PORT:
  2090. X            w->b3 = v;
  2091. X            break;
  2092. X        case RADARPORT:
  2093. X            w->short_range_radar = 1 - w->short_range_radar;
  2094. X            break;
  2095. X        case BALANCEPORT:
  2096. X            balance_shields(w);
  2097. X            break;
  2098. X        case TURNLEFTPORT:
  2099. X            if(v)
  2100. X                start_turn_left(w);
  2101. X            else
  2102. X                stop_turn_left(w);
  2103. X            break;
  2104. X        case TURNRIGHTPORT:
  2105. X            if(v)
  2106. X                start_turn_right(w);
  2107. X            else
  2108. X                stop_turn_right(w);
  2109. X            break;
  2110. X        case TURNTOPORT:
  2111. X/*
  2112. Xprintf("Set turn port\n");
  2113. X*/
  2114. X            w->comp->turnto = v - w->angle;
  2115. X            if(w->comp->turnto > 180)
  2116. X            {
  2117. X                w->comp->turnto -= 360;
  2118. X            }
  2119. X            if(w->comp->turnto < -180)
  2120. X            {
  2121. X                w->comp->turnto += 360;
  2122. X            }
  2123. X/*
  2124. X            w->comp->turnabs = w->angle;
  2125. X*/
  2126. X            w->comp->turnabs = v;
  2127. X            break;
  2128. X        case REPAIRTOGGLEPORT:
  2129. X            change_repair(w);
  2130. X            break;
  2131. X        case REPAIRSELITEMPORT:
  2132. X            if(w->state[v] < 100)
  2133. X                w->rep_which=v;
  2134. X            break;
  2135. X        case TARGETPORT:
  2136. X            if(w->state[TC]==-1 ||  !w->comp->ce) break;
  2137. X              if(((w->comp->ce->cloaking) && (w->comp->ce->state[CLOAK]>=rand()%100+1))
  2138. X                || (w->comp->ce->exploding))
  2139. X            {
  2140. X                w->targeting = NULL;
  2141. X            }
  2142. X            else
  2143. X            {
  2144. X                w->targeting=w->comp->ce;
  2145. X            }
  2146. X            break;
  2147. X        case GRABPORT:
  2148. X            grab_energy(w);
  2149. X            break;
  2150. X        case SHIELDREGENPORT:
  2151. X            w->shield_regen=!w->shield_regen;
  2152. X            break;
  2153. X        case CLOAKPORT:
  2154. X            w->cloaking = v;
  2155. X            break;
  2156. X        case SELECTEPORT:
  2157. X            if(v > (w->comp->no_seen -1))
  2158. X            {
  2159. X                break;
  2160. X            }
  2161. X            w->comp->curr_enemy = w->comp->closest[v];
  2162. X            w->comp->ce = w->comp->cptr[v];
  2163. X            break;
  2164. X        case QUITPORT:
  2165. X        {
  2166. X            int add;
  2167. X            winptr r;
  2168. X
  2169. X            num_alive--;
  2170. X            num_npcs_alive--;
  2171. X            add=w->earned/3;
  2172. X            if(num_npcs_alive)
  2173. X            {
  2174. X                add /= num_npcs_alive;
  2175. X                r = first_win;
  2176. X                while(r)
  2177. X                {
  2178. X                    if(!r->exploding && r->npc && r!=w)
  2179. X                        r->earned += add;
  2180. X                    r=r->next;
  2181. X                }
  2182. X            }
  2183. X            w->earned = w->earned*2/3;
  2184. X            
  2185. X            if(w->npcwin)
  2186. X            {
  2187. X                close_host(w);
  2188. X                num_npcs_windows--;
  2189. X                w->npcwin=0;
  2190. X            }
  2191. X            w->exploding=1;
  2192. X            untarget(w);
  2193. X        }
  2194. X            break;
  2195. X        default:
  2196. X            xmpb_error("Unknown Output port");
  2197. X            break;
  2198. X    }
  2199. X}
  2200. X
  2201. Xload_npc(w,name)
  2202. Xwinptr w;
  2203. Xchar *name;
  2204. X{
  2205. X    int i,start,no_vars,no_ins;
  2206. X    FILE *fp;
  2207. X    char fn[100];
  2208. X    struct header h;
  2209. X
  2210. X    parse_shop_contents();
  2211. X    strcpy(fn, NPCDIR);
  2212. X    strcat(fn,name);
  2213. X    strcat(fn,".no");
  2214. X
  2215. Xseteuid(euid);
  2216. X    fp = fopen(fn,"rb");
  2217. Xseteuid(getuid());
  2218. X    if(!fp) return 0;
  2219. X
  2220. X    fread(&h, sizeof(struct header), 1, fp);
  2221. X
  2222. X    strcpy(w->Name, h.Name);    
  2223. X    strcpy(w->Ship, h.Ship);    
  2224. X    w->energy_max=h.energy_max;
  2225. X    w->ls_max=h.ls_max;
  2226. X    w->rs_max=h.rs_max;
  2227. X    w->bs_max=h.bs_max;
  2228. X    w->kills=h.kills;
  2229. X    w->last_kills = h.kills;
  2230. X        
  2231. X    for(i=0;i<NUM_ITEMS;i++)
  2232. X    {
  2233. X        if(h.qual[i] == -1)
  2234. X        {
  2235. X            w->state[i] = -1;
  2236. X            w->quality[i] = 2;
  2237. X        }
  2238. X        else
  2239. X        {
  2240. X            w->quality[i] = h.qual[i];
  2241. X            w->state[i] = 100;
  2242. X        }
  2243. X    }
  2244. X
  2245. X    for(i=0;i<NO_WEAPONS;i++)
  2246. X    {
  2247. X        w->does_have_weap[i]=h.does_have_weap[i];
  2248. X        w->weap_on_status[i] = 1;
  2249. X    }
  2250. X    w->comp = create_comp(h.no_vars,h.no_ins,h.start);
  2251. X    fread(w->comp->text,sizeof(struct ins),h.no_ins,fp);
  2252. X    fread(&(w->comp->no_states),sizeof(int),1,fp);
  2253. X    for(i=0;i<w->comp->no_states;i++)
  2254. X    {
  2255. X        fread(w->comp->states[i],1,MAX_SYMB_LEN,fp);
  2256. X        fread(&(w->comp->stp[i]),sizeof(int),1,fp);
  2257. X    }
  2258. X    fclose(fp);
  2259. X    w->energy_curr = w->energy_max;;
  2260. X    w->ls_curr = w->ls_max;
  2261. X    w->rs_curr = w->rs_max;
  2262. X    w->bs_curr = w->bs_max;
  2263. X    w->shield_cnt = 3;
  2264. X    w->curr_weap = 0;    
  2265. X    w->comp->curr_enemy = -1;
  2266. X    w->comp->no_seen = 0;
  2267. X    w->comp->ce = NULL;
  2268. X    strcpy(w->comp->fname,name);
  2269. X    
  2270. X    {
  2271. X        int first;
  2272. X        int cw = 0;
  2273. X
  2274. X        w->curr_weap=WEAP_PULSE;
  2275. X        first=1;
  2276. X        while(!w->does_have_weap[w->curr_weap])
  2277. X        {
  2278. X            w->curr_weap++;
  2279. X            w->curr_weap %= NO_WEAPONS;
  2280. X            if(cw == w->curr_weap && !first)
  2281. X            {
  2282. X            w->curr_weap++;
  2283. X                cw = -1;
  2284. X                break;
  2285. X            }
  2286. X            first=0;
  2287. X        }
  2288. X        if(cw == -1) w->curr_weap = -1;
  2289. X    }
  2290. X
  2291. X    w->credits=h.cash_earned;
  2292. X    if(h.cash_earned>0)
  2293. X        w->ship_value=h.cash_earned/(1+h.num_played)+350000;
  2294. X    else
  2295. X        w->ship_value=350000;
  2296. X
  2297. X    return 1;
  2298. X}
  2299. X
  2300. X
  2301. Xcansee(w,t)
  2302. Xwinptr w,t;
  2303. X{
  2304. X    /*
  2305. X    ** can w see t?
  2306. X    */
  2307. X
  2308. X
  2309. X    if(t->exploding) return 0;
  2310. X    if(t->quitting) return 0;
  2311. X    if(t->sx < w->sx+PLAYW/2 && t->sx > w->sx-PLAYW/2 && t->sy < w->sy+PLAYH/2 && t->sy > w->sy-PLAYH/2)
  2312. X        return 1;
  2313. X    if(w->short_range_radar)
  2314. X    {
  2315. X        if(w->state[SHORTRR] < (rand()%100))
  2316. X            return 0;
  2317. X        if(!(t->sx < w->sx+WORLDW/4 && t->sx > w->sx-WORLDW/4 && t->sy < w->sy+WORLDH/4 && t->sy > w->sy-WORLDH/4))
  2318. X            return 0;
  2319. X        return 1;
  2320. X    }
  2321. X    else
  2322. X    {
  2323. X        if(w->state[LONGRR] < (rand()%100))
  2324. X            return 0;
  2325. X        return 1;
  2326. X    }
  2327. X}
  2328. X    
  2329. X
  2330. X    
  2331. Xjamming(w,t)
  2332. Xwinptr w,t;
  2333. X{
  2334. X    int c,r,chance;
  2335. X
  2336. X    if(t->cloaking)
  2337. X    {
  2338. X        c = (t->quality[CLOAK]-1)*t->state[CLOAK];
  2339. X        r = w->quality[SHORTRR]*w->state[SHORTRR];    
  2340. X        if(c+r!=0)
  2341. X            chance=(r-c)*100/(c+r) + 50;
  2342. X        if(chance < (rand()%100+1))
  2343. X            return 1;
  2344. X    }
  2345. X    return 0;
  2346. X}
  2347. X
  2348. END_OF_FILE
  2349. if test 16260 -ne `wc -c <'pcomp.c'`; then
  2350.     echo shar: \"'pcomp.c'\" unpacked with wrong size!
  2351. fi
  2352. # end of 'pcomp.c'
  2353. fi
  2354. echo shar: End of archive 1 \(of 8\).
  2355. cp /dev/null ark1isdone
  2356. MISSING=""
  2357. for I in 1 2 3 4 5 6 7 8 ; do
  2358.     if test ! -f ark${I}isdone ; then
  2359.     MISSING="${MISSING} ${I}"
  2360.     fi
  2361. done
  2362. if test "${MISSING}" = "" ; then
  2363.     echo You have unpacked all 8 archives.
  2364.     rm -f ark[1-9]isdone
  2365. else
  2366.     echo You still need to unpack the following archives:
  2367.     echo "        " ${MISSING}
  2368. fi
  2369. ##  End of shell archive.
  2370. exit 0
  2371.