-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqarea.c
executable file
·321 lines (275 loc) · 6.77 KB
/
qarea.c
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
qarea.c
880924 ACH convert to Atari ST & Acylon
880925 ACH add bonus for Quixes captured, 250 points each.
891216 ACH Tidied up code for Sozobon C and general release of source
*/
#include "defs.h"
#include <stdlib.h>
#define LINE_BORDER 'L'
#define BORDER_SOLID 'B'
int min;
int max;
int min_min;
short near_border(a, b)
int a;
int b;
{
return ((a - b == 1 || b - a == 1) ||
(a == bord_max && b == bord_min) ||
(b == bord_max && a == bord_min));
} /* near_border */
static int
bound_pos(int x1, int y1)
{
int i;
struct coord *b;
if (board[x1][y1] == BORDER || board[x1][y1] == BORDER_SOLID) {
for (i = bord_min, b = boundary + i; i <= bord_max; i++, b++)
if (b->x == x1 && b->y == y1)
return i;
} else {
for (i = line_max + 1, b = boundary + i; i >= line_min; i--, b--)
if (b->x == x1 && b->y == y1)
return i;
} /* if */
print("\nError in bound_pos()\n");
exit(0);
}
short line_near(i, j, at_border)
int i;
int j;
short at_border;
{
char c0;
char c1;
char border;
c0 = board[i][j];
c1 = board[i][j+1];
border = (at_border ? BORDER : BORDER_SOLID);
if ((c0 == LINE_BORDER || c0 == border) &&
(c1 == LINE_BORDER || c1 == border) ){
int f0;
int f1;
f0 = bound_pos(i, j);
f1 = bound_pos(i, j+1);
if (c0 == LINE_BORDER) {
if (c1 == LINE_BORDER)
return f0 - f1 == 1 || f1 - f0 == 1 ||
((f0 == line_max + 1 || f0 == line_min) &&
(f1 == line_max + 1 || f1 == line_min));
else if (boundary[max].x == i && boundary[max].y == j)
return near_border(max, f1);
else if (boundary[min].x == i && boundary[min].y == j)
return near_border(min, f1);
else
return FALSE;
} else if (c1 == LINE_BORDER) {
if (boundary[max].x == i && boundary[max].y == j + 1)
return near_border(max, f0);
else if (boundary[min].x == i && boundary[min].y == j + 1)
return near_border(min, f0);
else
return FALSE;
} else {
return near_border(f0, f1);
} /* if */
} /* if */
return FALSE;
} /* line_near */
int
find(int x1, int y1)
{
int i;
struct coord *b;
for (i = bord_min, b = boundary + i; i <= bord_max; i++, b++)
if (b->x == x1 && b->y == y1)
return i;
print("\nError in find()\n");
exit(0);
} /* find */
static int
scan_screen(int draw, int border)
{
int i;
int j;
short in;
int area;
int quix_in;
int quix_out;
area = -2;
quix_in = 0;
quix_out = 0;
lastx = 0;
for (j = 1; j <= ymax; j++) {
in = FALSE;
for (i = 1; i <= xmax; i++) {
int surface;
surface = board[i][j];
if (surface != SOLID && surface != NOTHING &&
j < ymax && line_near(i, j, border))
in = !in;
if (draw) {
switch (surface) {
case NOTHING:
case QUIX:
if (in) {
area++;
mvaddch(i, j, SOLID);
} /* if */
break;
case BORDER:
if (border)
mvaddch(i, j, SOLID);
break;
case BORDER_SOLID:
if (border)
board[i][j] = BORDER;
else
mvaddch(i, j, SOLID);
break;
case LINE_BORDER:
area++;
mvaddch(i, j, BORDER);
} /* switch */
} else {
switch (surface) {
case NOTHING:
if (in) area++;
break;
case LINE_BORDER:
area++;
break;
case QUIX:
if (in) {
area++;
quix_in++;
} else
quix_out++;
} /* switch */
} /* if */
} /* for */
} /* for */
if (!draw) {
if (quix_in == 0)
return 0;
else if (quix_out == 0)
return maxarea;
else if (quix_in - quix_out > 3)
return maxarea;
else if (quix_out - quix_in > 3)
return 0;
} else {
score += (area/2) * quixnum;
add_life();
move(46, 0);
putint(score, 1);
qputch('0');
} /* if */
return area;
}
void
fill_area(void)
{
unsigned tpercent; /* for percent calculation */
int i;
int j;
struct quixtype *q;
min = find(boundary[line_max+1].x, boundary[line_max+1].y);
max = find(player.x, player.y);
boundary[line_min].x = player.x;
boundary[line_min].y = player.y;
if (max < min) {
i = max;
max = min;
min = i;
} /* if */
for (i = 0; i < sparxnum; i++) {
sparx[i].x = boundary[sparx[i].pos].x;
sparx[i].y = boundary[sparx[i].pos].y;
board[sparx[i].x][sparx[i].y] = BORDER;
} /* for */
for (i = min + 1; i < max; i++)
board[boundary[i].x][boundary[i].y] = BORDER_SOLID;
for (i = line_min; i <= line_max+1; i++)
board[boundary[i].x][boundary[i].y] = LINE_BORDER;
for (i = 0; i < BOUNDARY_LEN; i++) {
temp[i].x = boundary[i].x;
temp[i].y = boundary[i].y;
} /* for */
min_min = temp[line_max+1].x == temp[max].x &&
temp[line_max+1].y == temp[max].y;
if (scan_screen(FALSE, FALSE) > area_left / 2) {
area_left -= scan_screen(TRUE, TRUE);
for (j = min, i = bord_min; j <= max; i++, j++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
if (min_min) {
for (j = line_max; j > line_min; j--, i++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
} else {
for (j = line_min + 1; j <= line_max; j++, i++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
} /* if */
} else {
area_left -= scan_screen(TRUE, FALSE);
for (i = j = bord_min; j <= min; i++, j++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
if (!min_min) {
for (j = line_max; j > line_min; j--, i++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
} else {
for (j = line_min + 1; j <= line_max; j++, i++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
} /* if */
for (j = max; j <= bord_max; j++, i++) {
boundary[i].x = temp[j].x;
boundary[i].y = temp[j].y;
} /* for */
} /* if */
bord_max = i - 1;
player.pos = find(player.x, player.y);
for (i = 0; i < sparxnum; i++) {
if (board[sparx[i].x][sparx[i].y] != BORDER) {
if (sparx[i].dir == 1) {
sparx[i].pos = (player.pos == bord_max) ?
bord_min : player.pos +1;
} else {
sparx[i].pos = (player.pos == bord_min) ?
bord_max : player.pos -1;
} /* if */
} else {
sparx[i].pos = find(sparx[i].x, sparx[i].y);
} /* if */
} /* for */
/*
* DON'T alter the way "percent" is calculated or the intermeadiate
* results in the calculation will OVERFLOW without you knowing it
* and weird results will occur!!
*/
tpercent = (((maxarea/10)-(area_left/10))*100)/(maxarea/10);
percent = tpercent;
if (percent < 75) {
move(34, 0);
putint(percent, 1);
qputch('%');
} /* if */
/* Check for captures. */
for( i = quixnum, q = quix; i; --i, ++q ){
if( !q->cought && board[q->x][q->y] == SOLID ){
++QuixCaptured;
q->cought = TRUE;
} /* if */
} /* for */
} /* fill_area */