comparison src/tourny.c @ 8:0836fb919dfa

First entry of Paradise Server 2.9 patch 10 Beta
author darius
date Sat, 06 Dec 1997 04:37:05 +0000
parents
children
comparison
equal deleted inserted replaced
7:814de70c9f67 8:0836fb919dfa
1 /*--------------------------------------------------------------------------
2 NETREK II -- Paradise
3
4 Permission to use, copy, modify, and distribute this software and its
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
6 purpose and without fee is hereby granted, provided that this copyright
7 notice appear in all copies. No representations are made about the
8 suitability of this software for any purpose. This software is provided
9 "as is" without express or implied warranty.
10
11 Xtrek Copyright 1986 Chris Guthrie
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
13 Scott Silvey
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
15 Kurt Olsen
16 Brandon Gillespie
17 --------------------------------------------------------------------------*/
18
19 #include "config.h"
20 #ifdef LEAGUE_SUPPORT
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "defs.h"
25 #include "struct.h"
26 #include "shmem.h"
27 #include "data.h"
28
29 #define TLOGNAME "/tmp/tourney.log"
30 #define MAXTIME 120
31
32 FILE *tlog = NULL;
33 /* int tournymode = 0; */
34
35 #define TOURNEYMODE (status2->league > 2)
36
37 void endtourn();
38 void starttourn();
39
40
41 #ifndef IRIX
42 extern int fprintf();
43 #endif
44 extern int fclose();
45 extern void pmessage();
46 extern void explode_everyone();
47 extern void endgame_effects();
48
49 void
50 opentlog()
51 {
52 tlog = fopen(TLOGNAME, "a");
53 if (tlog == NULL)
54 fprintf(stderr, "Could not open the tournament logfile");
55 else
56 {
57 #ifdef SYSV
58 setvbuf(tlog, NULL, _IOLBF, BUFSIZ);
59 #else
60 setlinebuf(tlog);
61 #endif
62 fprintf(tlog, "\n\n\n\nOPENING TOURNAMENT LOG\n\n");
63 }
64 }
65
66 /*
67 * Return a string identifying the player and his ship. Uses a ring of
68 * buffers so that it can be used multiple times in a printf
69 */
70 char *
71 id_player(p)
72 struct player *p;
73 {
74 static char bufs[16][80];
75 static int ring = 0;
76 int count;
77
78 ring++;
79 count = sizeof(bufs) / sizeof(*bufs);
80 if (ring >= count)
81 ring = 0;
82
83 sprintf(bufs[ring], "%s <%s> %c%c", twoletters(p),
84 p->p_name, p->p_ship.s_desig1, p->p_ship.s_desig2);
85
86 return bufs[ring];
87 }
88
89 /*
90 * Return a string identifying the player and his ship. Uses a ring of
91 * buffers so that it can be used multiple times in a printf
92 */
93 char *
94 id_planet(p)
95 struct planet *p;
96 {
97 static char bufs[16][80];
98 static int ring = 0;
99 int count;
100
101 ring++;
102 count = sizeof(bufs) / sizeof(*bufs);
103 if (ring >= count)
104 ring = 0;
105
106 sprintf(bufs[ring], "#%d [%s] %s", p->pl_no, p->pl_name,
107 teams[p->pl_owner].shortname);
108
109 return bufs[ring];
110 }
111
112
113 /*
114 * List of player related actions
115 *
116 */
117
118 enum player_status_e status_cache[MAXPLAYER];
119 enum ship_types_e ship_cache[MAXPLAYER];
120
121 void
122 tlog_refit(pl)
123 struct player *pl;
124 {
125 if (!TOURNEYMODE)
126 return;
127 if (!tlog)
128 return;
129
130 /* we have to print the OLD ship type he was flying */
131 fprintf(tlog, "%ld\trefit %s <%s> %c%c %dt\n", status->clock,
132 twoletters(pl), pl->p_name,
133 shipvals[ship_cache[pl->p_no]].s_desig1,
134 shipvals[ship_cache[pl->p_no]].s_desig2,
135 pl->p_updates);
136
137 ship_cache[pl->p_no] = pl->p_ship.s_type;
138 }
139
140 /*
141 * player was killed by player. call before erasing armies
142 */
143 void
144 tlog_plkill(victim, killer1, killer2)
145 struct player *victim;
146 struct player *killer1;
147 struct player *killer2;
148 {
149 if (!TOURNEYMODE)
150 return;
151 if (!tlog)
152 return;
153
154 fprintf(tlog, "%ld\tkill %s+%da,%dt,%.2fk by %s&%s\n",
155 status->clock,
156 id_player(victim), victim->p_armies, victim->p_updates,
157 victim->p_kills,
158 killer1 ? id_player(killer1) : "_", killer2 ? id_player(killer2) : "_");
159
160 status_cache[victim->p_no] = victim->p_status;
161 }
162
163 /*
164 * player changed status from ALIVE to something else without telling us.
165 * call before erasing armies
166 */
167 void
168 tlog_plquit(victim)
169 struct player *victim;
170 {
171 if (!TOURNEYMODE)
172 return;
173 if (!tlog)
174 return;
175
176 fprintf(tlog, "%ld\tquit %s+%da,%dt,%.2fk\n",
177 status->clock,
178 id_player(victim), victim->p_armies, victim->p_updates,
179 victim->p_kills);
180
181 status_cache[victim->p_no] = victim->p_status;
182 }
183
184 /*
185 * player was killed by planet. call before erasing armies
186 */
187 void
188 tlog_plankill(victim, killer1, killer2)
189 struct player *victim;
190 struct planet *killer1;
191 struct player *killer2;
192 {
193 if (!TOURNEYMODE)
194 return;
195 if (!tlog)
196 return;
197
198 fprintf(tlog, "%ld\tkill %s+%da by %s&%s\n",
199 status->clock, id_player(victim), victim->p_armies,
200 id_planet(killer1), killer2 ? id_player(killer2) : "_");
201 status_cache[victim->p_no] = victim->p_status;
202 }
203
204 /*
205 * planet was destroyed call before changing owner to IND
206 */
207 void
208 tlog_plandest(pl, killer)
209 struct planet *pl;
210 struct player *killer;
211 {
212 if (!TOURNEYMODE)
213 return;
214 if (!tlog)
215 return;
216
217 fprintf(tlog, "%ld\tpl_destroy %s by %s\n", status->clock, id_planet(pl),
218 id_player(killer));
219 }
220
221 /*
222 * planet was taken call after changing owner
223 */
224 void
225 tlog_plantake(pl, killer)
226 struct planet *pl;
227 struct player *killer;
228 {
229 if (!TOURNEYMODE)
230 return;
231 if (!tlog)
232 return;
233
234 fprintf(tlog, "%ld\tpl_take %s by %s\n", status->clock, id_planet(pl),
235 id_player(killer));
236 }
237
238 /*
239 * planet was abandoned call before changing owner
240 */
241 void
242 tlog_planaban(pl, killer)
243 struct planet *pl;
244 struct player *killer;
245 {
246 if (!TOURNEYMODE)
247 return;
248 if (!tlog)
249 return;
250
251 fprintf(tlog, "%ld\tpl_aban %s by %s\n", status->clock, id_planet(pl),
252 id_player(killer));
253 }
254
255 void
256 tlog_jsassist(js)
257 struct player *js;
258 {
259 if (!TOURNEYMODE)
260 return;
261 if (!tlog)
262 return;
263
264 fprintf(tlog, "%ld\tjsassist %s\n", status->clock, id_player(js));
265 }
266
267 /* call before transferring the army */
268 void
269 tlog_beamup(pl, carrier)
270 struct planet *pl;
271 struct player *carrier;
272 {
273 if (!TOURNEYMODE)
274 return;
275 if (!tlog)
276 return;
277
278 fprintf(tlog, "%ld\tbeamup %s from %s@%da\n", status->clock,
279 id_player(carrier), id_planet(pl), pl->pl_armies);
280 }
281
282 /* call after transferring the army */
283 void
284 tlog_beamdown(pl, carrier)
285 struct planet *pl;
286 struct player *carrier;
287 {
288 if (!TOURNEYMODE)
289 return;
290 if (!tlog)
291 return;
292
293 fprintf(tlog, "%ld\tbeamdown %s to %s@%da\n", status->clock,
294 id_player(carrier), id_planet(pl), pl->pl_armies);
295 }
296
297 /* call before transferring the army */
298 void
299 tlog_Bbeamup(base, carrier)
300 struct player *base;
301 struct player *carrier;
302 {
303 if (!TOURNEYMODE)
304 return;
305 if (!tlog)
306 return;
307
308 fprintf(tlog, "%ld\txfer %s from %s\n", status->clock, id_player(carrier),
309 id_player(base));
310 }
311
312 /* call after transferring the army */
313 void
314 tlog_Bbeamdown(base, carrier)
315 struct player *base;
316 struct player *carrier;
317 {
318 if (!TOURNEYMODE)
319 return;
320 if (!tlog)
321 return;
322
323 fprintf(tlog, "%ld\txfer %s to %s\n", status->clock, id_player(carrier),
324 id_player(base));
325 }
326
327 /* call after destroying armies */
328 void
329 tlog_bomb(pl, killer, narmies)
330 struct planet *pl;
331 struct player *killer;
332 int narmies;
333 {
334 if (!TOURNEYMODE)
335 return;
336 if (!tlog)
337 return;
338
339 if (!narmies)
340 return;
341
342 fprintf(tlog, "%ld\tbomb %s by %s (%da)\n", status->clock,
343 id_planet(pl), id_player(killer), narmies);
344 }
345
346 void
347 tlog_bres(pl, killer, resource)
348 struct planet *pl;
349 struct player *killer;
350 char *resource;
351 {
352 if (!TOURNEYMODE)
353 return;
354 if (!tlog)
355 return;
356
357 fprintf(tlog, "%ld\tresbomb %s (%s) by %s\n", status->clock,
358 id_planet(pl), resource, id_player(killer));
359 }
360
361
362 /*
363 * non-player action stuff
364 *
365 */
366
367 /* call before popping */
368 void
369 tlog_pop(pl, narmies)
370 struct planet *pl;
371 int narmies;
372 {
373 if (!TOURNEYMODE)
374 return;
375 if (!tlog)
376 return;
377
378 fprintf(tlog, "%ld\tpoparmies %s %+da\n", status->clock,
379 id_planet(pl), narmies);
380 }
381
382 void
383 tlog_res(pl, resource)
384 struct planet *pl;
385 char *resource;
386 {
387 if (!TOURNEYMODE)
388 return;
389 if (!tlog)
390 return;
391
392 fprintf(tlog, "%ld\tresgrow %s (%s)\n", status->clock,
393 id_planet(pl), resource);
394 }
395
396 /* call before changing owner */
397 void
398 tlog_revolt(pl)
399 struct planet *pl;
400 {
401 if (!TOURNEYMODE)
402 return;
403 if (!tlog)
404 return;
405
406 fprintf(tlog, "%ld\trevolt %s\n", status->clock, id_planet(pl));
407 }
408
409 void
410 scan_for_unexpected_tourny_events()
411 {
412 int i;
413 for (i = 0; i < MAXPLAYER; i++)
414 {
415 struct player *p = &players[i];
416 if (status_cache[i] != PALIVE)
417 {
418 status_cache[i] = p->p_status;
419 ship_cache[i] = -1;
420 continue;
421 }
422
423 if (p->p_status != PALIVE)
424 {
425 tlog_plquit(p, 0, 0);
426 status_cache[i] = p->p_status;
427 }
428 else if (ship_cache[i] < 0)
429 {
430 ship_cache[i] = p->p_ship.s_type;
431 }
432 else if (ship_cache[i] != p->p_ship.s_type)
433 {
434 tlog_refit(p);
435 }
436 }
437 }
438
439 /*
440 * end of T log procs
441 *
442 */
443
444
445 void
446 closetlog()
447 {
448 if (tlog != NULL)
449 {
450 fprintf(tlog, "\n\nCLOSING TOURNAMENT LOG\n\n\n\n");
451 fclose(tlog);
452 }
453 tlog = NULL;
454 }
455
456
457 void
458 tlog_all()
459 {
460 int i;
461 struct planet *pl;
462
463 if (!tlog)
464 return;
465
466 fprintf(tlog, "The time is: %ld ----------------\n", status->clock);
467 for (i = 0, pl = &planets[i]; i < NUMPLANETS; i++, pl++)
468 fprintf(tlog, "Planet: %s %x %s -- armies %d\n", pl->pl_name,
469 pl->pl_flags, teams[pl->pl_owner].shortname, pl->pl_armies);
470 }
471
472 void
473 tlog_conquerline(line)
474 char *line;
475 {
476 if (!tlog)
477 return;
478
479 fprintf(tlog, "C:\t%s\n", line);
480 }
481
482
483
484
485
486 void
487 udtourny()
488 {
489 int trem;
490 char buf[120];
491 if (!status2->league)
492 return;
493
494 /* server is configured for league play */
495
496 if (status2->league == 1)
497 return; /* we're still prepping */
498
499 trem = --status2->leagueticksleft;
500
501
502 switch (status2->league)
503 {
504 case 2: /* the 1-minute pre tourney warm up. */
505 if (trem == SECONDS(5))
506 pmessage("5 seconds to tournament start", -1, MALL, UMPIRE);
507 else if (trem == SECONDS(2))
508 pmessage("Hold on to your hats. Everybody dies!", -1, MALL, UMPIRE);
509 else if (trem <= 0)
510 {
511 starttourn();
512 }
513 break;
514
515 case 3: /* full-on T-mode */
516
517 buf[0] = 0;
518 if (trem % MINUTES(20) == 0 ||
519 (trem < MINUTES(20) && 0 == trem % MINUTES(5)) ||
520 (trem < MINUTES(5) && 0 == trem % MINUTES(1)))
521 {
522 sprintf(buf, "There are %d minutes remaining in regulation play",
523 trem / MINUTES(1));
524 }
525 else if (trem < MINUTES(1) && 0 == trem % SECONDS(10))
526 {
527 sprintf(buf, "There are %d seconds remaining in regulation play",
528 trem / SECONDS(1));
529 }
530 if (buf[0])
531 pmessage(buf, -1, MALL, UMPIRE);
532 if (trem <= 0)
533 /* maybe go into overtime */
534 endtourn();
535 break;
536 case 4:
537 /* overtime, not implemented */
538 break;
539 }
540 }
541
542
543
544 void
545 starttourn()
546 {
547 int i, j;
548 struct planet *pl;
549 char s[80];
550
551 opentlog();
552 for (i = 0, pl = &planets[i]; i < NUMPLANETS; i++, pl++)
553 {
554 for (j = 0; j < MAXTEAM + 1; j++)
555 {
556 pl->pl_tinfo[j].timestamp = 0;
557 /* doesn't work? */
558 pl->pl_hinfo = (PL_TYPE(*pl) == PLSTAR) ? ALLTEAM : pl->pl_owner;
559 }
560 }
561 status->clock = 0;
562
563 explode_everyone(KTOURNSTART, 0);
564
565 tlog_all();
566
567
568 status2->league++;
569 status2->leagueticksleft = MINUTES(configvals->regulation_minutes);
570
571 /* version team names configured time date */
572 pmessage(" ", 0, MALL, UMPIRE);
573 sprintf(s, "Timer started -- %d minutes remaining",
574 status2->leagueticksleft / MINUTES(1));
575 pmessage(s, 0, MALL, UMPIRE);
576 pmessage(" ", 0, MALL, UMPIRE);
577 }
578
579
580 void
581 endtourn()
582 {
583 pmessage(" ", 0, MALL, UMPIRE);
584 pmessage("Time is done", 0, MALL, UMPIRE);
585 pmessage(" ", 0, MALL, UMPIRE);
586
587 /* print damage assesments */
588 endgame_effects(1 << status2->home.index, 1 << status2->away.index, -1);
589
590 scan_for_unexpected_tourny_events();
591
592 tlog_all();
593
594 closetlog();
595
596 /* conquer */
597
598 status2->league = 1;
599
600 /* we should shut the game off here (status->gameup=0) */
601 }
602 #endif