Home | History | Annotate | Line # | Download | only in warp
play.c revision 1.1
      1 /* $Header: /tank/opengrok/rsync2/NetBSD/src/games/warp/play.c,v 1.1 2020/11/09 23:37:05 kamil Exp $ */
      2 
      3 /* $Log: play.c,v $
      4 /* Revision 1.1  2020/11/09 23:37:05  kamil
      5 /* Add Warp Kit, Version 7.0 by Larry Wall
      6 /*
      7 /* Warp is a real-time space war game that doesn't get boring very quickly.
      8 /* Read warp.doc and the manual page for more information.
      9 /*
     10 /* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD
     11 /* world via NetBSD. Its remnants were still mentioned in games/Makefile.
     12 /*
     13 /* Larry Wall, the original author and the copyright holder, generously
     14 /* donated the game and copyright to The NetBSD Foundation, Inc.
     15 /*
     16 /* Import the game sources as-is from 4.3BSD-Reno, with the cession
     17 /* of the copyright and license to BSD-2-clause NetBSD-style.
     18 /*
     19 /* Signed-off-by: Larry Wall <larry (at) wall.org>
     20 /* Signed-off-by: Kamil Rytarowski <kamil (at) netbsd.org>
     21 /*
     22  * Revision 7.0.1.1  86/10/16  10:52:39  lwall
     23  * Added Damage.  Fixed random bugs.
     24  *
     25  * Revision 7.0  86/10/08  15:13:09  lwall
     26  * Split into separate files.  Added amoebas and pirates.
     27  *
     28  */
     29 
     30 #include "EXTERN.h"
     31 #include "warp.h"
     32 #include "bang.h"
     33 #include "score.h"
     34 #include "object.h"
     35 #include "move.h"
     36 #include "term.h"
     37 #include "them.h"
     38 #include "us.h"
     39 #include "util.h"
     40 #include "weapon.h"
     41 #include "INTERN.h"
     42 #include "play.h"
     43 
     44 void
     45 play_init()
     46 {
     47     ;
     48 }
     49 
     50 void
     51 play()
     52 {
     53     bool done = FALSE;
     54     Reg1 OBJECT *curobj;
     55     Reg2 OBJECT *to;
     56     Reg3 int i;
     57     Reg4 int x;
     58     Reg5 int y;
     59 
     60     display_status();
     61 #ifdef TIOCOUTQ
     62     while (output_pending() > charsperhalfsec)
     63 	sleep(1);			 /* allow buffers to empty */
     64 #endif
     65     sleep(3);
     66     do {
     67 	timer++;
     68 	nxtbang = 0;
     69 	banging = FALSE;
     70 	display_status();
     71 #ifdef TIOCOUTQ
     72 	while (output_pending() > charsperhalfsec)
     73 	    sleep(1);
     74 #endif
     75 	if (lowspeed)
     76 	    roundsleep(2);
     77 	else
     78 	    roundsleep(1);
     79 	if (ent) {
     80 	    evely = ent->vely;
     81 	    evelx = ent->velx;
     82 	    if (cloaking && ent->energy >= 250 && !damflag[NOCLOAKING]) {
     83 		if (!rand_mod(300)) {
     84 		    damage++;
     85 		    damflag[NOCLOAKING] = rand_mod(smarts+1)+2;
     86 		}
     87 		ent->energy -= ent->energy/40;
     88 	    }
     89 	    else
     90 		cloaking = FALSE;
     91 	    cloaked = cloaking;
     92 	}
     93 	if (base) {
     94 	    bvely = base->vely;
     95 	    bvelx = base->velx;
     96 	}
     97 	get_commands(&done);
     98 	if (done)
     99 	    break;
    100 	their_smarts();
    101 	apolloflag = 0;
    102 	if (ent) {
    103 	    if (numapollos) {
    104 		if (numstars) {
    105 		    if (realapollo) {
    106 			if (lookfor(realapollo->posy,realapollo->posx,
    107 			    Enterprise)) {
    108 			    apolloflag = 1;
    109 			}
    110 		    }
    111 		    else if (lookfor(root.next->posy,root.next->posx,
    112 			Enterprise)) {
    113 			apolloflag = 1;
    114 			realapollo = root.next;
    115 			mvaddch(realapollo->posy+1,realapollo->posx*2,
    116 			    'A');
    117 			realapollo->image = 'A';
    118 			realapollo->mass = 6000;
    119 			inumapollos = 1;
    120 			numenemies++;
    121 			inumenemies++;
    122 			possiblescore += 5000;
    123 		    }
    124 		    if (apolloflag) {
    125 			if (blast[realapollo->posy][realapollo->posx] <= 32000)
    126 			    evely = evelx = 0;
    127 			realapollo->energy = 32000;
    128 		    }
    129 		}
    130 		else
    131 		    numapollos = 0;
    132 	    }
    133 	    ent->vely = evely;
    134 	    ent->velx = evelx;
    135 	}
    136 	if (base) {
    137 	    if (numapollos) {
    138 		if (numstars) {
    139 		    if (realapollo) {
    140 			if (lookfor(realapollo->posy,realapollo->posx,
    141 			    Base)) {
    142 			    apolloflag |= 2;
    143 			}
    144 		    }
    145 		    else if (lookfor(root.next->posy,root.next->posx,
    146 			Base)) {
    147 			apolloflag |= 2;
    148 			realapollo = root.next;
    149 			mvaddch(realapollo->posy+1,realapollo->posx*2,
    150 			    'A');
    151 			realapollo->image = 'A';
    152 			realapollo->mass = 6000;
    153 			inumapollos = 1;
    154 			numenemies++;
    155 			inumenemies++;
    156 			possiblescore += 5000;
    157 		    }
    158 		    if (apolloflag & 2) {
    159 			if (blast[realapollo->posy][realapollo->posx] <= 32000)
    160 			    bvely = bvelx = 0;
    161 			realapollo->energy = 32000;
    162 		    }
    163 		}
    164 		else
    165 		    numapollos = 0;
    166 	    }
    167 	    base->vely = bvely;
    168 	    base->velx = bvelx;
    169 	}
    170 	if (aretorps) {
    171 	    aretorps = 0;
    172 	    for (i=0;i<2;i++) for (y=0;y<3;y++) for (x=0;x<3;x++) {
    173 		if (curobj = isatorp[i][y][x]) {
    174 		    to = occupant[(curobj->posy+curobj->vely+YSIZE00)%YSIZE]
    175 				 [(curobj->posx+curobj->velx+XSIZE00)%XSIZE];
    176 		    if (to && !to->vely && !to->velx) {
    177 			unmake_object(curobj);
    178 			if (i)
    179 			    btorp++;
    180 			else
    181 			    etorp++;
    182 		    }
    183 		    isatorp[i][y][x]=0;
    184 		}
    185 	    }
    186 	}
    187 	move_universe();
    188 	if (finish) {
    189 	    finish--;
    190 	    if (!finish && (!(numenemies || numos) || (!ent && !base))) {
    191 		done = TRUE;
    192 		timer -= 5;
    193 	    }
    194 	}
    195 	else if (!banging && (!(numenemies || numos) || (!ent && !base)))
    196 	    finish = 5;
    197     } while (!done);
    198 }
    199