summaryrefslogtreecommitdiffstats
path: root/warp/play.c
blob: 1397f7b9ded5672d3100f8d99f2f28d2ebc0077b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* $Header: /cvsroot/src/games/warp/play.c,v 1.1 2020/11/09 23:37:05 kamil Exp $ */

/* $Log: play.c,v $
/* Revision 1.1  2020/11/09 23:37:05  kamil
/* Add Warp Kit, Version 7.0 by Larry Wall
/*
/* Warp is a real-time space war game that doesn't get boring very quickly.
/* Read warp.doc and the manual page for more information.
/*
/* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD
/* world via NetBSD. Its remnants were still mentioned in games/Makefile.
/*
/* Larry Wall, the original author and the copyright holder, generously
/* donated the game and copyright to The NetBSD Foundation, Inc.
/*
/* Import the game sources as-is from 4.3BSD-Reno, with the cession
/* of the copyright and license to BSD-2-clause NetBSD-style.
/*
/* Signed-off-by: Larry Wall <larry@wall.org>
/* Signed-off-by: Kamil Rytarowski <kamil@netbsd.org>
/*
 * Revision 7.0.1.1  86/10/16  10:52:39  lwall
 * Added Damage.  Fixed random bugs.
 * 
 * Revision 7.0  86/10/08  15:13:09  lwall
 * Split into separate files.  Added amoebas and pirates.
 * 
 */

#include "EXTERN.h"
#include "warp.h"
#include "bang.h"
#include "score.h"
#include "object.h"
#include "move.h"
#include "term.h"
#include "them.h"
#include "us.h"
#include "util.h"
#include "weapon.h"
#include "INTERN.h"
#include "play.h"

void
play_init()
{
    ;
}

void
play()
{
    bool done = FALSE;
    Reg1 OBJECT *curobj;
    Reg2 OBJECT *to;
    Reg3 int i;
    Reg4 int x;
    Reg5 int y;

    display_status();
#ifdef TIOCOUTQ
    while (output_pending() > charsperhalfsec)
	sleep(1);			 /* allow buffers to empty */
#endif
    sleep(3);
    do {
	timer++;
	nxtbang = 0;
	banging = FALSE;
	display_status();
#ifdef TIOCOUTQ
	while (output_pending() > charsperhalfsec)
	    sleep(1);
#endif
	if (lowspeed)
	    roundsleep(2);
	else
	    roundsleep(1);
	if (ent) {
	    evely = ent->vely;
	    evelx = ent->velx;
	    if (cloaking && ent->energy >= 250 && !damflag[NOCLOAKING]) {
		if (!rand_mod(300)) {
		    damage++;
		    damflag[NOCLOAKING] = rand_mod(smarts+1)+2;
		}
		ent->energy -= ent->energy/40;
	    }
	    else
		cloaking = FALSE;
	    cloaked = cloaking;
	}
	if (base) {
	    bvely = base->vely;
	    bvelx = base->velx;
	}
	get_commands(&done);
	if (done)
	    break;
	their_smarts();
	apolloflag = 0;
	if (ent) {
	    if (numapollos) {
		if (numstars) {
		    if (realapollo) {
			if (lookfor(realapollo->posy,realapollo->posx,
			    Enterprise)) {
			    apolloflag = 1;
			}
		    }
		    else if (lookfor(root.next->posy,root.next->posx,
			Enterprise)) {
			apolloflag = 1;
			realapollo = root.next;
			mvaddch(realapollo->posy+1,realapollo->posx*2,
			    'A');
			realapollo->image = 'A';
			realapollo->mass = 6000;
			inumapollos = 1;
			numenemies++;
			inumenemies++;
			possiblescore += 5000;
		    }
		    if (apolloflag) {
			if (blast[realapollo->posy][realapollo->posx] <= 32000)
			    evely = evelx = 0;
			realapollo->energy = 32000;
		    }
		}
		else
		    numapollos = 0;
	    }
	    ent->vely = evely;
	    ent->velx = evelx;
	}
	if (base) {
	    if (numapollos) {
		if (numstars) {
		    if (realapollo) {
			if (lookfor(realapollo->posy,realapollo->posx,
			    Base)) {
			    apolloflag |= 2;
			}
		    }
		    else if (lookfor(root.next->posy,root.next->posx,
			Base)) {
			apolloflag |= 2;
			realapollo = root.next;
			mvaddch(realapollo->posy+1,realapollo->posx*2,
			    'A');
			realapollo->image = 'A';
			realapollo->mass = 6000;
			inumapollos = 1;
			numenemies++;
			inumenemies++;
			possiblescore += 5000;
		    }
		    if (apolloflag & 2) {
			if (blast[realapollo->posy][realapollo->posx] <= 32000)
			    bvely = bvelx = 0;
			realapollo->energy = 32000;
		    }
		}
		else
		    numapollos = 0;
	    }
	    base->vely = bvely;
	    base->velx = bvelx;
	}
	if (aretorps) {
	    aretorps = 0;
	    for (i=0;i<2;i++) for (y=0;y<3;y++) for (x=0;x<3;x++) {
		if (curobj = isatorp[i][y][x]) {
		    to = occupant[(curobj->posy+curobj->vely+YSIZE00)%YSIZE]
				 [(curobj->posx+curobj->velx+XSIZE00)%XSIZE];
		    if (to && !to->vely && !to->velx) {
			unmake_object(curobj);
			if (i)
			    btorp++;
			else
			    etorp++;
		    }
		    isatorp[i][y][x]=0;
		}
	    }
	}
	move_universe();
	if (finish) {
	    finish--;
	    if (!finish && (!(numenemies || numos) || (!ent && !base))) {
		done = TRUE;
		timer -= 5;
	    }
	}
	else if (!banging && (!(numenemies || numos) || (!ent && !base)))
	    finish = 5;
    } while (!done);
}