|
|
1.1 root 1: #ifndef lint
2: static char *sccsid = "@(#)driver3.c 1.3 83/05/20";
3: #endif
4: #include "externs.h"
5:
6: extern int dtab[];
7:
8: moveall() /* move all comp ships */
9: {
10: register int n, k, l, m, ma, closest;
11: int weakest[5];
12: int ta, af, jj;
13: char command[10], clast[20][10];
14: int row[20], col[20], dir[20], r1, r2, c1, c2, d1, d2;
15: struct File *ptr;
16:
17: for (n=0; n < scene[game].vessels; n++){
18: ptr = scene[game].ship[n].file;
19: if (!ptr -> captain[0] && scene[game].ship[n].shipdir){
20:
21: if (!ptr -> struck && windspeed && !grappled(n) && !fouled(n) && specs[scene[game].ship[n].shipnum].crew3){
22: ta = maxturns(n);
23: jj = 0100000;
24: af = ta & jj;
25: jj = 077777;
26: ta = ta & jj;
27: ma = maxmove(n, pos[n].dir, 0);
28: closest = closestenemy(n, 0, 0);
29: if (closest == 30000)
30: command[0] = '\0';
31: else
32: closeon(n, closest, command, ta, ma, af);
33: }
34: else
35: command[0] = '\0';
36: strcpy(ptr -> last, command);
37: }
38: }
39: for (n=0; n < scene[game].vessels; n++){
40: strcpy(clast[n], scene[game].ship[n].file -> last);
41: if (fouled(n) || grappled(n))
42: clast[n][0] = '\0';
43: row[n] = pos[n].row;
44: col[n] = pos[n].col;
45: dir[n] = pos[n].dir;
46: score(clast[n],n, 0, 1, 0);
47: }
48: for (k=0; stillmoving(clast, k); k++){
49: for (n=0; n < scene[game].vessels; n++){
50: if (dir[n])
51: step(clast[n][k], n, row, col, dir);
52: if (!clast[n][k])
53: clast[n][k+1] = '\0';
54: }
55: for (n=0; n < scene[game].vessels; n++){
56: if ((d1 = pos[n].dir) && !isolated(n)){
57: r1 = pos[n].row;
58: c1 = pos[n].col;
59: pos[n].dir = dir[n];
60: pos[n].row = row[n];
61: pos[n].col = col[n];
62: for (l=0; l < scene[game].vessels; l++){
63: if (d2 = pos[l].dir && l != n){
64: r2 = pos[l].row;
65: c2 = pos[l].col;
66: pos[l].dir = dir[l];
67: pos[l].row = row[l];
68: pos[l].col = col[l];
69: if ((foul(n,l) || grapple(n,l)) && push(n,l) && range(n,l) > 1){
70: Write(l,0,6,pos[n].row-1);
71: if (pos[n].dir == 1 || pos[n].dir == 5)
72: Write(l,0,8,pos[n].col-1);
73: else
74: Write(l,0,8,pos[n].col);
75: Write(l,0,10,pos[n].dir);
76: }
77: if (!range(n,l) && !foul(n,l) && push(n,l)){
78: makesignal("collision with %s (%c%c)", l, n);
79: if (die() < 4){
80: makesignal("fouled with %s (%c%c)", l, n);
81: for (m=0;scene[game].ship[n].file -> fouls[m].turnfoul && m < 10; m++);
82: if (m < 10){
83: Write(FILES + n, 0, 84 + m*4, turn);
84: Write(FILES + n, 0, 84 + m*4 + 2, l);
85: }
86: for (m=0;scene[game].ship[l].file -> fouls[m].turnfoul && m < 10; m++);
87: if (m < 10){
88: Write(FILES + l, 0, 84 + m*4, turn);
89: Write(FILES + l, 0, 84 + m*4 + 2, n);
90: }
91: }
92: clast[n][k+1] = '\0';
93: pos[n].row = r2;
94: pos[n].col = c2;
95: pos[n].dir = d2;
96: score(clast[n],n,n,1,0);
97: Write(l,0,6,pos[n].row-1);
98: if (pos[n].dir == 1 || pos[n].dir == 5)
99: Write(l,0,8,pos[n].col-1);
100: else
101: Write(l,0,8,pos[n].col);
102: Write(l,0,10,pos[n].dir);
103: Write(FILES + l, 0, 82, 0);
104: Write(FILES + n, 0, 82, 0);
105: }
106: else {
107: pos[l].row = r2;
108: pos[l].col = c2;
109: pos[l].dir = d2;
110: }
111: }
112: }
113: pos[n].row = r1;
114: pos[n].col = c1;
115: pos[n].dir = d1;
116: }
117: }
118: }
119: for(n=0; n < scene[game].vessels; n++)
120: scene[game].ship[n].file -> last[0] = NULL;
121: }
122:
123: stillmoving(last, k)
124: register char last[20][10];
125: register int k;
126: {
127: register int n;
128:
129: for (n=0; n < scene[game].vessels; n++)
130: if (last[n][k]) return(1);
131: return(0);
132: }
133:
134: isolated(ship)
135: register int ship;
136: {
137: register int n;
138:
139: for (n=0; n < scene[game].vessels; n++)
140: if (ship != n && range(ship, n) <= 10)
141: return(0);
142: return(1);
143: }
144:
145: push(from, to)
146: register int from, to;
147: {
148: int bow1r, bow1c, bow2r, bow2c, stern1r, stern1c, stern2r, stern2c;
149: register int bs, sb;
150:
151: stern1r = bow1r = pos[from].row;
152: stern1c = bow1c = pos[from].col;
153: stern2r = bow2r = pos[to].row;
154: stern2c = bow2c = pos[to].col;
155: drdc(&stern2r, &stern2c, pos[to].dir);
156: bs = bow1r - stern2r + bow1c - stern2c;
157: sb = stern1r - bow2r + stern1c - bow2c;
158: if (!bs)
159: return(1);
160: drdc(&stern1r, &stern1c, pos[from].dir);
161: if(!sb)
162: return(0);
163: if ((sb = specs[scene[game].ship[to].shipnum].class) > (bs = specs[scene[game].ship[from].shipnum].class))
164: return(1);
165: if (sb < bs)
166: return(0);
167: return(from < to);
168: }
169:
170: step(com, shipnum, row, col, dir)
171: int shipnum, row[20], col[20], dir[20];
172: char com;
173: {
174: int dr = 0, dc = 0;
175: register int dist;
176:
177: switch(com){
178:
179: case 'r':
180: if (++dir[shipnum] == 9)
181: dir[shipnum] = 1;
182: break;
183: case 'l':
184: if (!--dir[shipnum])
185: dir[shipnum] = 8;
186: break;
187: case '0':
188: case '1':
189: case '2':
190: case '3':
191: case '4':
192: case '5':
193: case '6':
194: case '7':
195: drdc(&dr, &dc, dir[shipnum]);
196: if (!(dir[shipnum] % 2))
197: dist = dtab[com - '0'];
198: else
199: dist = com - '0';
200: row[shipnum] -= dr * dist;
201: col[shipnum] -= dc * dist;
202: dr = dc = 0;
203: break;
204: case 'b':
205: break;
206: case 'd':
207: drdc(&dr, &dc, winddir);
208: dist = 1 - ((specs[scene[game].ship[shipnum].shipnum].class < 3 || fouled(shipnum) || grappled(shipnum)) && turn % 2);
209: row[shipnum] -= dr * dist;
210: col[shipnum] -= dc * dist;
211: break;
212: }
213: }
214:
215: send(from, to, sections, offset)
216: int from, to, sections, offset;
217: {
218: int n;
219: struct BP *ptr;
220:
221: ptr = offset == 200 ? scene[game].ship[from].file -> OBP : scene[game].ship[from].file -> DBP;
222: for (n=0; n<3 && ptr[n].turnsent; n++);
223: if (n < 3 && sections){
224: Write(FILES + from, 0, 30 + (offset > 200)*18 + 6*n, turn);
225: Write(FILES + from, 0, 30 + (offset > 200)*18 + 6*n + 2, to);
226: Write(FILES + from, 0, 30 + (offset > 200)*18 + 6*n + 4, sections);
227: if (offset == 200)
228: makesignal("boarding the %s (%c%c)", to, from);
229: else
230: makesignal("repelling boarders", 0, from);
231: }
232: }
233:
234: toughmelee(shipnum, toship, defense, count)
235: int shipnum, toship, defense, count;
236: {
237: int n, OBP = 0, DBP = 0, obp = 0, dbp = 0;
238: int qual;
239: struct BP *ptr1;
240: struct shipspecs *ptr;
241:
242: ptr = &specs[scene[game].ship[shipnum].shipnum];
243: ptr1 = defense ? scene[game].ship[shipnum].file -> DBP : scene[game].ship[shipnum].file -> OBP ;
244: qual = ptr -> qual;
245: for (n=0; n < 3; n++){
246: if (ptr1[n].turnsent && (toship == ptr1[n].toship || defense)){
247: obp += ptr1[n].mensent / 100 ? ptr -> crew1 * qual : 0;
248: obp += (ptr1[n].mensent % 100)/10 ? ptr -> crew2 * qual : 0;
249: obp += ptr1[n].mensent % 10 ? ptr -> crew3 * qual : 0;
250: }
251: }
252: if (count || defense)
253: return(obp);
254: OBP = toughmelee(toship, shipnum, 0, count + 1);
255: dbp = toughmelee(shipnum, toship, 1, count + 1);
256: DBP = toughmelee(toship, shipnum, 1, count + 1);
257: if (OBP > obp + 10 || OBP + DBP >= obp + dbp + 10)
258: return(1);
259: else
260: return(0);
261: }
262:
263: reload()
264: {
265: register int n;
266:
267: for (n=0; n < scene[game].vessels; n++)
268: loadwith[n] = 0;
269: }
270:
271: checksails()
272: {
273: register int n, rig, full;
274: struct shipspecs *ptr;
275: int close;
276:
277: for (n=0; n < scene[game].vessels; n++){
278: ptr = &specs[scene[game].ship[n].shipnum];
279: rig = ptr -> rig1;
280: if (windspeed == 6 || (windspeed == 5 && ptr -> class > 4))
281: rig = 0;
282: if (!scene[game].ship[n].file -> captain[0]){
283: if (rig && ptr -> crew3) {
284: close = closestenemy(n,0,0);
285: if (close != 30000) {
286: if (range(n, close) > 9)
287: full = 1;
288: else
289: full = 0;
290: } else
291: full = 0;
292: } else
293: full = 0;
294: if ((scene[game].ship[n].file -> FS != 0) != full)
295: Write(FILES + n, 0, 230, full);
296: }
297: }
298: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.