comparison hockey.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
comparison
equal deleted inserted replaced
2:fba0b6e6cdc7 3:5a977ccbc7a9
1 /* $Id: hockey.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
2
3 #ifdef HOCKEY
4 /* code for hockey lines [BDyess] 9/14/94 */
5
6 #include <stdio.h>
7 #include "Wlib.h"
8 #include "defs.h"
9 #include "struct.h"
10 #include "data.h"
11 #include "proto.h"
12 #include "gameconf.h"
13 #include "packets.h"
14
15 void dump_hockey_points();
16 /*void init_puck(); /* getship.c */
17
18 struct player *puck;
19
20 /* check to see if on a hockey server and do initialization [BDyess] */
21 void hockeyInit() {
22 int i,j;
23 struct planet *l, *last;
24 int rightmost = 0;
25 int leftmost = blk_gwidth;
26 int nplan = paradise ? nplanets : 40; /* shouldn't be Paradise... */
27 int middle = blk_gwidth / 2;
28 int top = 0;
29 int bottom = blk_gwidth;
30 int line = 0;
31 struct point { int x,y; } boxpoints[4];
32 /* top-topleft, top-bottomright, bottom-topright,
33 bottom-bottomright, {x,y} for each [BDyess] */
34 W_Color topcolor,bottomcolor;
35
36 topcolor = bottomcolor = W_Grey;
37
38 /* we're playing hockey if a player named "Puck" exists in the 'g'
39 slot, is independant, is in a scout, and has the login name
40 'Robot'. [BDyess] */
41 puck = &players['g'-'a'+10];
42 if(!hockey) {
43 if(0 == strcmp(puck->p_name,"Puck") &&
44 0 == strcmp(puck->p_login,"Robot") &&
45 puck->p_teami < 0 &&
46 SCOUT == puck->p_ship->s_type) {
47
48 printf("Hi Puck!\n");
49 hockey = 1;
50 /*init_puck();*/
51 }
52 }
53 if(!hockey) /* not a hockey server, nothing more to do */
54 return;
55
56 if(puck->p_ship->s_type != PUCK) {
57 puck->p_ship = getship(PUCK);
58 redrawPlayer[puck->p_no];
59 }
60 if(tacticalHockeyLines) {
61 last = &planets[nplan];
62 /* guess where the lines are supposed to go based on planet
63 location. Always draws straight lines, ie. if the border
64 bows out, tough - the furthest out planet will have a vertical
65 line through it. [BDyess] */
66
67 /* first the left and rightmost lines [BDyess] */
68 for(l = &planets[0];l < last;l++) {
69 if(l->pl_x < leftmost) {
70 leftmost = l->pl_x;
71 }
72 if(l->pl_x > rightmost) {
73 rightmost = l->pl_x;
74 }
75 }
76 hlines[line].vertical = 1;
77 hlines[line].pos = leftmost;
78 hlines[line].end1 = 0;
79 hlines[line].end2 = blk_gwidth;
80 hlines[line].color = W_Grey;
81 line++;
82 hlines[line].vertical = 1;
83 hlines[line].pos = rightmost;
84 hlines[line].end1 = 0;
85 hlines[line].end2 = blk_gwidth;
86 hlines[line].color = W_Grey;
87 line++;
88 /* now guess the middle planet. Pick the planet closest to the
89 middle of the screen. [BDyess] */
90 hlines[line].pos = 0;
91 for(l = &planets[0];l < last;l++) {
92 if(ABS(l->pl_y - middle) < ABS(hlines[line].pos - middle))
93 hlines[line].pos = l->pl_y;
94 }
95 middle = hlines[line].pos;
96 hlines[line].end1 = leftmost;
97 hlines[line].end2 = rightmost;
98 hlines[line].vertical = 0;
99 hlines[line].color = W_Red;
100 line++;
101 /* now find the upper and lower middle lines by picking the planets
102 closest to the center yet still above/below the middle and inside
103 the left and rightmost [BDyess] */
104 for(l = &planets[0];l < last;l++) {
105 if(NOBODY == l->pl_owner) continue;
106 if(l->pl_y > top && l->pl_y < middle &&
107 l->pl_x < rightmost && l->pl_x > leftmost) {
108 top = l->pl_y;
109 topcolor = planetColor(l);
110 }
111 if(l->pl_y < bottom && l->pl_y > middle &&
112 l->pl_x < rightmost && l->pl_x > leftmost) {
113 bottom = l->pl_y;
114 bottomcolor = planetColor(l);
115 }
116 }
117 hlines[line].pos = top;
118 hlines[line].end1 = leftmost;
119 hlines[line].end2 = rightmost;
120 hlines[line].vertical = 0;
121 hlines[line].color = teamColorHockeyLines ? topcolor : W_Cyan;
122 line++;
123 hlines[line].pos = bottom;
124 hlines[line].end1 = leftmost;
125 hlines[line].end2 = rightmost;
126 hlines[line].vertical = 0;
127 hlines[line].color = teamColorHockeyLines ? bottomcolor : W_Cyan;
128 line++;
129 /* last, try to find the goal box. Search for the planets that
130 are inside the left and right, above/below the upper/lower middle,
131 and are not neutral. Of those planets, take the top left and
132 bottom right points [BDyess] */
133 /* toplefts */
134 boxpoints[0].x = boxpoints[0].y = boxpoints[2].x = boxpoints[2].y =
135 blk_gwidth;
136 /* bottomrights */
137 boxpoints[1].x = boxpoints[1].y = boxpoints[3].x = boxpoints[3].y = 0;
138 for(l = &planets[0];l < last;l++) {
139 /* don't want nobody's planets */
140 if(l->pl_owner == NOBODY) continue;
141 /* check for out-of-bounds */
142 if((l->pl_y >= top && l->pl_y <= bottom) ||
143 l->pl_x >= rightmost || l->pl_x <= leftmost) continue;
144 /* top or bottom? */
145 if(l->pl_y < middle) i = 0; /* top */
146 else i = 2; /* bottom */
147 if(l->pl_x <= boxpoints[i].x &&
148 l->pl_y <= boxpoints[i].y) { /* new topleft */
149 boxpoints[i].x = l->pl_x;
150 boxpoints[i].y = l->pl_y;
151 }
152 if(l->pl_x >= boxpoints[i+1].x &&
153 l->pl_y >= boxpoints[i+1].y) { /* new bottomright */
154 boxpoints[i+1].x = l->pl_x;
155 boxpoints[i+1].y = l->pl_y;
156 }
157 }
158 if(! teamColorHockeyLines) {
159 topcolor = bottomcolor = W_Grey;
160 }
161 hlines[line].vertical = 0;
162 hlines[line].pos = boxpoints[0].y;
163 hlines[line].end1 = boxpoints[0].x;
164 hlines[line].end2 = boxpoints[1].x;
165 hlines[line].color = topcolor;
166 line++;
167 hlines[line].vertical = 1;
168 hlines[line].pos = boxpoints[0].x;
169 hlines[line].end1 = boxpoints[0].y;
170 hlines[line].end2 = boxpoints[1].y;
171 hlines[line].color = topcolor;
172 line++;
173 hlines[line].vertical = 0;
174 hlines[line].pos = boxpoints[1].y;
175 hlines[line].end1 = boxpoints[0].x;
176 hlines[line].end2 = boxpoints[1].x;
177 hlines[line].color = W_Red;
178 line++;
179 hlines[line].vertical = 1;
180 hlines[line].pos = boxpoints[1].x;
181 hlines[line].end1 = boxpoints[0].y;
182 hlines[line].end2 = boxpoints[1].y;
183 hlines[line].color = topcolor;
184 line++;
185
186 hlines[line].vertical = 0;
187 hlines[line].pos = boxpoints[2].y;
188 hlines[line].end1 = boxpoints[2].x;
189 hlines[line].end2 = boxpoints[3].x;
190 hlines[line].color = W_Red;
191 line++;
192 hlines[line].vertical = 1;
193 hlines[line].pos = boxpoints[2].x;
194 hlines[line].end1 = boxpoints[2].y;
195 hlines[line].end2 = boxpoints[3].y;
196 hlines[line].color = bottomcolor;
197 line++;
198 hlines[line].vertical = 0;
199 hlines[line].pos = boxpoints[3].y;
200 hlines[line].end1 = boxpoints[2].x;
201 hlines[line].end2 = boxpoints[3].x;
202 hlines[line].color = bottomcolor;
203 line++;
204 hlines[line].vertical = 1;
205 hlines[line].pos = boxpoints[3].x;
206 hlines[line].end1 = boxpoints[2].y;
207 hlines[line].end2 = boxpoints[3].y;
208 hlines[line].color = bottomcolor;
209 line++;
210 }
211 }
212
213 /* draw the tactical hockey lines [BDyess] */
214 void tactical_hockey() {
215 int i;
216 struct hockeyLine *l = &hlines[0];
217 int dx,dx1,dx2,dy,dy1,dy2;
218 int view = SCALE * WINSIDE / 2;
219 static int old_tacticalHockeyLines, old_galacticHockeyLines,
220 old_cleanHockeyGalactic, old_teamColorHockeyLines;
221
222 if(!hockey)
223 return;
224
225 if(puck->p_ship->s_type != PUCK) {
226 puck->p_ship = getship(PUCK);
227 redrawPlayer[puck->p_no];
228 }
229 if(tacticalHockeyLines != old_tacticalHockeyLines) {
230 redrawall = 1;
231 old_tacticalHockeyLines = tacticalHockeyLines;
232 }
233 if(galacticHockeyLines != old_galacticHockeyLines) {
234 redrawall = 1;
235 old_galacticHockeyLines = galacticHockeyLines;
236 }
237 if(cleanHockeyGalactic != old_cleanHockeyGalactic) {
238 redrawall = 1;
239 old_cleanHockeyGalactic = cleanHockeyGalactic;
240 }
241 if(teamColorHockeyLines != old_teamColorHockeyLines) {
242 old_teamColorHockeyLines = teamColorHockeyLines;
243 hockeyInit();
244 }
245 /* draw whatever hockey lines are visible [BDyess] */
246 if(hockey && tacticalHockeyLines) { /* if it should be drawn */
247 for(i = 0, l = &hlines[0]; i < NUM_HOCKEY_LINES; i++, l++) {
248 if(l->vertical) {
249 dx = l->pos - me->p_x;
250 dy1 = l->end1 - me->p_y;
251 dy2 = l->end2 - me->p_y;
252 /* is it in view? [BDyess] */
253 if(ABS(dx) <= view &&
254 (ABS(dy1) <= view || ABS(dy2) <= view ||
255 (l->end1 <= me->p_y && l->end2 >= me->p_y))) {
256 dx = dx / SCALE + WINSIDE / 2;
257 dy1 = dy1 / SCALE + WINSIDE / 2;
258 dy2 = dy2 / SCALE + WINSIDE / 2;
259 W_CacheLine(w, dx, dy1, dx, dy2, l->color);
260 clearline[0][clearlcount] = dx;
261 clearline[1][clearlcount] = dy1;
262 clearline[2][clearlcount] = dx;
263 clearline[3][clearlcount] = dy2;
264 clearlcount++;
265 }
266 } else { /* horizontal */
267 dy = l->pos - me->p_y;
268 dx1 = l->end1 - me->p_x;
269 dx2 = l->end2 - me->p_x;
270 /* is it in view? [BDyess] */
271 if(ABS(dy) <= view &&
272 (ABS(dx1) <= view || ABS(dx2) <= view ||
273 (l->end1 <= me->p_x && l->end2 >= me->p_x))) {
274 dy = dy / SCALE + WINSIDE / 2;
275 dx1 = dx1 / SCALE + WINSIDE / 2;
276 dx2 = dx2 / SCALE + WINSIDE / 2;
277 W_CacheLine(w, dx1, dy, dx2, dy, l->color);
278 clearline[0][clearlcount] = dx1;
279 clearline[1][clearlcount] = dy;
280 clearline[2][clearlcount] = dx2;
281 clearline[3][clearlcount] = dy;
282 clearlcount++;
283 }
284 }
285 }
286 }
287 }
288
289 /* draw the tactical hockey lines [BDyess] */
290 void galactic_hockey() {
291 int i;
292 struct hockeyLine *l;
293 int dx,dx1,dx2,dy,dy1,dy2;
294 int gwidth, offsetx, offsety;
295
296 if(hockey && galacticHockeyLines) { /* if it should be drawn */
297 if(blk_zoom) {
298 gwidth = blk_gwidth / 2;
299 offsetx = zoom_offset(me->p_x);
300 offsety = zoom_offset(me->p_y);
301 /* keep last offset? */
302 } else {
303 gwidth = blk_gwidth;
304 offsetx = offsety = 0;
305 }
306 for(i = 0, l = &hlines[0]; i < NUM_HOCKEY_LINES; i++, l++) {
307 if(l->vertical) {
308 dx = (l->pos - offsetx) * WINSIDE / gwidth;
309 dy1 = (l->end1 - offsety) * WINSIDE / gwidth;
310 dy2 = (l->end2 - offsety) * WINSIDE / gwidth;
311 W_MakeLine(mapw, dx, dy1, dx, dy2, l->color);
312 } else {
313 dy = (l->pos - offsety) * WINSIDE / gwidth;
314 dx1 = (l->end1 - offsetx) * WINSIDE / gwidth;
315 dx2 = (l->end2 - offsetx) * WINSIDE / gwidth;
316 W_MakeLine(mapw, dx1, dy, dx2, dy, l->color);
317 }
318 }
319 }
320 }
321
322 void dump_hockey_points() {
323 int i;
324 struct hockeyLine *l;
325
326 printf("Hockey points dump:\n");
327 for (i = 0, l = &hlines[0]; i < NUM_HOCKEY_LINES; i++, l++) {
328 if(l->vertical) {
329 printf("%d: %d,%d %d,%d\n",i,l->pos,l->end1,l->pos,l->end2);
330 } else {
331 printf("%d: %d,%d %d,%d\n",i,l->end1,l->pos,l->end2,l->pos);
332 }
333 }
334 }
335 #endif /*HOCKEY*/