1 /* This file implements all SHORT_PACKETS functions */
2 /* HW 19.07.93 */
3 #include "config.h"
4
5 #ifdef SHORT_PACKETS
6 #include INC_MACHINE_ENDIAN
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <netdb.h>
10 #include <netinet/in.h>
11
12 #include "Wlib.h"
13 #include "defs.h"
14 #include "struct.h"
15 #include "data.h"
16 #include "packets.h"
17
18 #include "distress.h"
19 #include "dmessage.h"
20 #include "local.h"
21 #include "map.h"
22 #include "playerlist.h"
23 #include "rotate.h"
24 #include "socket.h"
25 #include "spopt.h"
26 #include "stats.h"
27 #include "warning.h"
28
29 #include "short.h"
30
31 /* from here on all SHORT_PACKETS */
32 #include "wtext.h" /* here are all warningdefines */
33
34 /* Here are all warnings that are send with SP_S_WARNING */
35 /* HW 93 */
36
37 /* DaemonMessages */
38 char *daemon_texts[] =
39 {
40 /* Game_Paused() */
41 "Game is paused. CONTINUE to continue.", /* 0 */
42 "Game is no-longer paused!", /* 1 */
43 "Game is paused. Captains CONTINUE to continue.", /* 2 */
44 "Game will continue in 10 seconds", /* 3 */
45 /* send_about_to_start() */
46 "Teams chosen. Game will start in 1 minute.", /* 4 */
47 "----------- Game will start in 1 minute -------------", /* 5 */
48 };
49
50 /* VARITEXTE = warnings with 1 or more arguments argument */
51 char *vari_texts[] =
52 {
53 /* redraw.c */
54 "Engineering: Energizing transporters in %d seconds", /* 0 */
55 "Stand By ... Self Destruct in %d seconds", /* 1 */
56 "Helmsman: Docking manuever completed Captain. All moorings secured at port %d.", /* 2
57 *
58 */
59 /* interface.c from INL server */
60 "Not constructed yet. %d minutes required for completion", /* 3 */
61
62 };
63
64
65
66 char *w_texts[] =
67 {
68 /* socket.c */
69 "Tractor beams haven't been invented yet.", /* 0 */
70 "Weapons's Officer: Cannot tractor while cloaked, sir!", /* 1 */
71 "Weapon's Officer: Vessel is out of range of our tractor beam.", /* 2 */
72
73 /* handleRepressReq */
74 /**************** coup.c ***********************/
75 /* coup() */
76 "You must have one kill to throw a coup", /* 3 */
77 "You must orbit your home planet to throw a coup", /* 4 */
78 "You already own a planet!!!", /* 5 */
79 "You must orbit your home planet to throw a coup", /* 6 */
80 "Too many armies on planet to throw a coup", /* 7 */
81 "Planet not yet ready for a coup", /* 8 */
82 /* getentry.c */
83 /* getentry() */
84 "I cannot allow that. Pick another team", /* 9 */
85 "Please confirm change of teams. Select the new team again.", /* 10
86 *
87 */
88 "That is an illegal ship type. Try again.", /* 11 */
89 "That ship hasn't beed designed yet. Try again.", /* 12 */
90 "Your new starbase is still under construction", /* 13 */
91 "Your team is not capable of defending such an expensive ship!", /* 14
92 *
93 */
94 "Your team's stuggling economy cannot support such an expenditure!", /* 15
95 *
96 */
97 "Your side already has a starbase!", /* 16 */
98 /* plasma.c */
99 /* nplasmatorp(course, type) */
100 "Plasmas haven't been invented yet.", /* 17 */
101 "Weapon's Officer: Captain, this ship is not armed with plasma torpedoes!", /* 18
102 *
103 */
104 "Plasma torpedo launch tube has exceeded the maximum safe temperature!", /* 19
105 *
106 */
107 "Our fire control system limits us to 1 live torpedo at a time captain!", /* 20
108 *
109 */
110 "Our fire control system limits us to 1 live torpedo at a time captain!", /* 21
111 *
112 */
113 "We don't have enough fuel to fire a plasma torpedo!", /* 22 */
114 "We cannot fire while our vessel is undergoing repairs.", /* 23 */
115 "We are unable to fire while in cloak, captain!", /* 24 */
116 /******** torp.c *********/
117 /* ntorp(course, type) */
118 "Torpedo launch tubes have exceeded maximum safe temperature!", /* 25
119 *
120 */
121 "Our computers limit us to having 8 live torpedos at a time captain!", /* 26
122 *
123 */
124 "We don't have enough fuel to fire photon torpedos!", /* 27 */
125 "We cannot fire while our vessel is in repair mode.", /* 28 */
126 "We are unable to fire while in cloak, captain!", /* 29 */
127 "We only have forward mounted cannons.", /* 30 */
128 /* phasers.c */
129 /* phaser(course) */
130 "Weapons Officer: This ship is not armed with phasers, captain!", /* 31
131 *
132 */
133 "Phasers have not recharged", /* 32 */
134 "Not enough fuel for phaser", /* 33 */
135 "Can't fire while repairing", /* 34 */
136 "Weapons overheated", /* 35 */
137 "Cannot fire while cloaked", /* 36 */
138 "Phaser missed!!!", /* 37 */
139 "You destroyed the plasma torpedo!", /* 38 */
140 /* interface.c */
141 /* bomb_planet() */
142 "Must be orbiting to bomb", /* 39 */
143 "Can't bomb your own armies. Have you been reading Catch-22 again?", /* 40
144 *
145 */
146 "Must declare war first (no Pearl Harbor syndrome allowed here).", /* 41
147 *
148 */
149 "Bomb out of T-mode? Please verify your order to bomb.", /* 42 */
150 "Hoser!", /* 43 */
151 /* beam_up() */
152 "Must be orbiting or docked to beam up.", /* 44 */
153 "Those aren't our men.", /* 45 */
154 "Comm Officer: We're not authorized to beam foriegn troops on board!", /* 46
155 *
156 */
157 /* beam_down() */
158 "Must be orbiting or docked to beam down.", /* 47 */
159 "Comm Officer: Starbase refuses permission to beam our troops over.", /* 48
160 *
161 */
162 /* declare_war(mask) */
163 "Pausing ten seconds to re-program battle computers.", /* 49 */
164 /* do_refit(type) */
165 "You must orbit your HOME planet to apply for command reassignment!", /* 50
166 *
167 */
168 "You must orbit your home planet to apply for command reassignment!", /* 51
169 *
170 */
171 "Can only refit to starbase on your home planet.", /* 52 */
172 "You must dock YOUR starbase to apply for command reassignment!", /* 53
173 *
174 */
175 "Must orbit home planet or dock your starbase to apply for command reassignment!", /* 54
176 *
177 */
178 "Central Command refuses to accept a ship in this condition!", /* 55
179 *
180 */
181 "You must beam your armies down before moving to your new ship", /* 56
182 *
183 */
184 "That ship hasn't been designed yet.", /* 57 */
185 "Your side already has a starbase!", /* 58 */
186 "Your team is not capable of defending such an expensive ship", /* 59
187 *
188 */
189 "Your new starbase is still under construction", /* 60 */
190 "Your team's stuggling economy cannot support such an expenditure!", /* 61
191 *
192 */
193 "You are being transported to your new vessel .... ", /* 62 */
194 /* redraw.c */
195 /* auto_features() */
196 "Engineering: Energize. [ SFX: chimes ]", /* 63 */
197 "Wait, you forgot your toothbrush!", /* 64 */
198 "Nothing like turning in a used ship for a new one.", /* 65 */
199 "First officer: Oh no, not you again... we're doomed!", /* 66 */
200 "First officer: Uh, I'd better run diagnostics on the escape pods.", /* 67
201 *
202 */
203 "Shipyard controller: This time, *please* be more careful, okay?", /* 68
204 *
205 */
206 "Weapons officer: Not again! This is absurd...", /* 69 */
207 "Weapons officer: ... the whole ship's computer is down?", /* 70 */
208 "Weapons officer: Just to twiddle a few bits of the ship's memory?", /* 71
209 *
210 */
211 "Weapons officer: Bah! [ bangs fist on inoperative console ]", /* 72
212 *
213 */
214 "First Officer: Easy, big guy... it's just one of those mysterious", /* 73
215 *
216 */
217 "First Officer: laws of the universe, like 'tires on the ether'.", /* 74
218 *
219 */
220 "First Officer: laws of the universe, like 'Klingon bitmaps are ugly'.", /* 75
221 *
222 */
223 "First Officer: laws of the universe, like 'all admirals have scummed'.", /* 76
224 *
225 */
226 "First Officer: laws of the universe, like 'Mucus Pig exists'.", /* 77
227 *
228 */
229 "First Officer: laws of the universe, like 'guests advance 5x faster'.", /* 78
230 *
231 */
232 /* orbit.c */
233 /* orbit() */
234 "Helmsman: Captain, the maximum safe speed for docking or orbiting is warp 2!", /* 79
235 *
236 */
237 "Central Command regulations prohibit you from orbiting foreign planets", /* 80
238 *
239 */
240 "Helmsman: Sensors read no valid targets in range to dock or orbit sir!", /* 81
241 *
242 */
243 /* redraw.c */
244 "No more room on board for armies", /* 82 */
245 "You notice everyone on the bridge is staring at you.", /* 83 */
246 /* startdaemon.c */
247 /* practice_robo() */
248 "Can't send in practice robot with other players in the game.", /* 84
249 *
250 */
251 /* socket.c */
252 /* doRead(asock) */
253 "Self Destruct has been canceled", /* 85 */
254 /* handleMessageReq(packet) */
255 "Be quiet", /* 86 */
256 "You are censured. Message was not sent.", /* 87 */
257 "You are ignoring that player. Message was not sent.", /* 88 */
258 "That player is censured. Message was not sent.", /* 89 */
259 /* handleQuitReq(packet) */
260 "Self destruct initiated", /* 90 */
261 /* handleScan(packet) */
262 "Scanners haven't been invented yet", /* 91 */
263 /* handleUdpReq(packet) */
264 "WARNING: BROKEN mode is enabled", /* 92 */
265 "Server can't do that UDP mode", /* 93 */
266 "Server will send with TCP only", /* 94 */
267 "Server will send with simple UDP", /* 95 */
268 "Request for fat UDP DENIED (set to simple)", /* 96 */
269 "Request for double UDP DENIED (set to simple)", /* 97 */
270 /* forceUpdate() */
271 "Update request DENIED (chill out!)", /* 98 */
272 /* INL redraw.c */
273 "Player lock lost while player dead.", /* 99 */
274 "Can only lock on own team.", /* 100 */
275 "You can only warp to your own team's planets!", /* 101 */
276 "Planet lock lost on change of ownership.", /* 102 */
277 " Weapons officer: Finally! systems are back online!", /* 103 */
278
279 };
280
281 #define NUMWTEXTS (sizeof w_texts / sizeof w_texts[0])
282 #define NUMVARITEXTS ( sizeof vari_texts / sizeof vari_texts[0])
283 #define NUMDAEMONTEXTS ( sizeof daemon_texts / sizeof daemon_texts[0])
284
285 #define statsFile stderr /* use stderr for stats output for now */
286 extern int gather_stats;
287
288 extern void sendShortReq(char);
289 void new_flags(unsigned int data, int which);
290
291 extern unsigned char numofbits[]; /* How many 1 bits in a char */
292 extern int vtisize[]; /* 4 byte Header + torpdata */
293 int Plx[MAXPLAYER], Ply[MAXPLAYER], Pgx[MAXPLAYER], Pgy[MAXPLAYER];
294 unsigned char Pdir[MAXPLAYER];
295 int my_x, my_y; /* for rotation we need to *
296
297 *
298 *
299 * * keep track of our real
300 * * * coordinates */
301
302 /* SP_S_WARNING vari texte */
303 char *s_texte[256]; /* Better with a malloc *
304
305 *
306 * * scheme */
307 char no_memory[] =
308 {"Not enough memory for warning string!"};
309
310 /* For INL Server */
311 char *shiptype[NUM_TYPES] =
312 {"SC", "DD", "CA", "BB", "AS", "SB", "??"};
313 int spwinside = 500; /* WINSIDE from Server */
314
315 #define SPWINSIDE 500 /* To make it safe */
316 LONG spgwidth = GWIDTH;
317
318
sendThreshold(short unsigned int v)319 void sendThreshold(short unsigned int v)
320 {
321 struct threshold_cpacket p;
322
323 p.type = CP_S_THRS;
324 p.thresh = v;
325 sendServerPacket((struct player_spacket *) &p);
326 }
327
handleVTorp(unsigned char * sbuf)328 void handleVTorp(unsigned char *sbuf)
329 {
330 unsigned char *which, *data;
331 unsigned char bitset;
332 struct torp *thetorp;
333 int dx, dy;
334 int shiftvar;
335
336 int i;
337 register int shift = 0; /* How many torps are *
338
339 *
340 * * extracted (for shifting
341 * ) */
342
343 /* now we must find the data ... :-) */
344 if (sbuf[0] == SP_S_8_TORP)
345 { /* MAX packet */
346 bitset = 0xff;
347 which = &sbuf[1];
348 data = &sbuf[2];
349 }
350 else
351 { /* Normal Packet */
352 bitset = sbuf[1];
353 which = &sbuf[2];
354 data = &sbuf[3];
355 }
356
357 #ifdef CORRUPTED_PACKETS
358 /* we probably should do something clever here - jmn */
359 #endif
360
361 weaponUpdate = 1;
362 thetorp = &torps[((unsigned char) *which * 8)];
363 for (shift = 0, i = 0; i < 8;
364 i++, thetorp++, bitset >>= 1)
365 {
366 thetorp->t_updateFuse = MAX(2, TORP_UPDATE_FUSE * server_ups / 5);
367
368 if (bitset & 01)
369 {
370 dx = (*data >> shift);
371 data++;
372 shiftvar = (unsigned char) *data; /* to silence gcc */
373 shiftvar <<= (8 - shift);
374 dx |= (shiftvar & 511);
375 shift++;
376 dy = (*data >> shift);
377 data++;
378 shiftvar = (unsigned char) *data; /* to silence gcc */
379 shiftvar <<= (8 - shift);
380 dy |= (shiftvar & 511);
381 shift++;
382 if (shift == 8)
383 {
384 shift = 0;
385 data++;
386 }
387
388 /* This is necessary because TFREE/TMOVE is now encoded in the * *
389 * bitset */
390 if (thetorp->t_status == TFREE)
391 {
392 thetorp->t_status = TMOVE; /* guess */
393 players[thetorp->t_owner].p_ntorp++;
394 }
395 else if (thetorp->t_owner == me->p_no
396 && thetorp->t_status == TEXPLODE)
397 {
398 thetorp->t_status = TMOVE; /* guess */
399 }
400
401 /* Check if torp is visible */
402 if (dx > SPWINSIDE || dy > SPWINSIDE)
403 {
404 thetorp->t_x = -100000; /* Not visible */
405 thetorp->t_y = -100000;
406 }
407 else
408 { /* visible */
409 /* thetorp->t_x = me->p_x + ((dx - SPWINSIDE / 2) * SCALE); * *
410 * thetorp->t_y = me->p_y + ((dy - SPWINSIDE / 2) * SCALE); */
411 thetorp->t_x = my_x + ((dx - SPWINSIDE / 2) * SCALE);
412 thetorp->t_y = my_y + ((dy - SPWINSIDE / 2) * SCALE);
413
414 #ifdef ROTATERACE
415 if (rotate)
416 {
417 rotate_coord(&thetorp->t_x, &thetorp->t_y, rotate_deg,
418 GWIDTH / 2, GWIDTH / 2);
419 }
420 #endif
421 }
422 } /* if */
423 else
424 { /* We got a TFREE */
425 if (thetorp->t_status && thetorp->t_status != TEXPLODE)
426 {
427 players[thetorp->t_owner].p_ntorp--;
428 thetorp->t_status = TFREE; /* That's no guess */
429 }
430 }
431 } /* for */
432 }
433
handleSelfShort(struct youshort_spacket * packet)434 void handleSelfShort(struct youshort_spacket *packet)
435 {
436 struct player* pl;
437 static int seen = 0;
438
439 pl = &players[(int) packet->pnum];
440
441 if (seen && packet->pnum != me->p_no) become(pl);
442 seen++;
443
444 if (!F_many_self)
445 {
446 me = (ghoststart ? &players[ghost_pno] : pl);
447 myship = &(me->p_ship);
448 mystats = &(me->p_stats);
449 }
450
451 #ifdef PLIST2
452 if (pl->p_hostile != packet->hostile)
453 {
454 pl->p_hostile = packet->hostile;
455 PlistNoteHostile(packet->pnum);
456 }
457 #else
458 pl->p_hostile = packet->hostile;
459 #endif
460
461 pl->p_swar = packet->swar;
462 pl->p_armies = packet->armies;
463 pl->p_flags = ntohl(packet->flags);
464 pl->p_whydead = packet->whydead;
465 pl->p_whodead = packet->whodead;
466 }
467
handleSelfShip(struct youss_spacket * packet)468 void handleSelfShip(struct youss_spacket *packet)
469 {
470 struct player* pl;
471
472 if (F_many_self)
473 {
474 pl = &players[(int) packet->pad1];
475 }
476 else
477 {
478 if (!me)
479 return; /* wait.. */
480 pl = me;
481
482 if (F_self_8flags)
483 me->p_flags = (me->p_flags & 0xffffff00) | (unsigned char) packet->pad1;
484 else if (F_self_8flags2)
485 {
486 unsigned int new_flags = me->p_flags & ~(PFSHIELD | PFREPAIR | PFCLOAK |
487 PFGREEN | PFYELLOW | PFRED |
488 PFTRACT | PFPRESS);
489
490 new_flags |= ((packet->pad1 & PFSHIELD) |
491 (packet->pad1 & PFREPAIR) |
492 ((packet->pad1 & (PFCLOAK << 2)) >> 2) |
493 ((packet->pad1 & (PFGREEN << 7)) >> 7) |
494 ((packet->pad1 & (PFYELLOW << 7)) >> 7) |
495 ((packet->pad1 & (PFRED << 7)) >> 7) |
496 ((packet->pad1 & (PFTRACT << 15)) >> 15) |
497 ((packet->pad1 & (PFPRESS << 15)) >> 15));
498
499 me->p_flags = new_flags;
500 }
501 }
502 pl->p_damage = ntohs(packet->damage);
503 pl->p_shield = ntohs(packet->shield);
504 pl->p_fuel = ntohs(packet->fuel);
505 pl->p_etemp = ntohs(packet->etemp);
506 pl->p_wtemp = ntohs(packet->wtemp);
507 }
508
handleVPlayer(unsigned char * sbuf)509 void handleVPlayer(unsigned char *sbuf)
510 {
511 register int x, y, i, numofplayers, pl_no, save;
512 register struct player *pl;
513
514 numofplayers = (unsigned char) sbuf[1] & 0x3f;
515
516 #ifdef CORRUPTED_PACKETS
517 /* should do something clever here - jmn if(pl_no < 0 || pl_no >= * *
518 * MAXPLAYER){ fprintf(stderr, "handleVPlayer: bad index %d\n", pl_no); * *
519 * return; } */
520 #endif
521
522 if (sbuf[1] & (unsigned char) 128)
523 { /* Short Header + Extended */
524 sbuf += 4;
525 for (i = 0; i < numofplayers; i++)
526 {
527 pl_no = ((unsigned char) *sbuf & 0x1f) + 32;
528 if (pl_no >= MAXPLAYER)
529 continue; /* a little error check */
530 save = (unsigned char) *sbuf;
531 sbuf++;
532 pl = &players[pl_no];
533
534 pl->p_speed = (unsigned char) *sbuf & 15; /* SPEED */
535 PlistNoteSpeed(pl_no);
536
537 if (F_cloak_maxwarp && pl != me)
538 {
539 if (pl->p_speed == 0xf)
540 pl->p_flags |= PFCLOAK;
541 else if (pl->p_flags & PFCLOAK)
542 pl->p_flags &= ~PFCLOAK;
543 }
544
545 Pdir[pl_no] = (unsigned char) *sbuf >> 4; /* DIR */
546 pl->p_dir = (unsigned char) Pdir[pl_no] * 16; /* real DIR */
547 sbuf++;
548 x = (unsigned char) *sbuf++;
549 y = (unsigned char) *sbuf++; /* The lower 8 Bits are * *
550 * saved */
551 /* Now we must preprocess the coordinates */
552 if ((unsigned char) save & 64)
553 x |= 256;
554 if ((unsigned char) save & 128)
555 y |= 256;
556
557 #ifdef WARP_DEAD
558 /* -10000 doesn't work for SP 501 is invisible needs server change
559 * * * [007] */
560 if (F_dead_warp && pl->p_speed == 14 && x == 501 && y == 501 && (pl->p_status != PEXPLODE))
561 {
562 pl->p_status = PEXPLODE;
563 x = pl->p_x;
564 y = pl->p_y;
565 if (pl->p_dir > DEADPACKETS)
566 pl->p_explode = EX_FRAMES;
567 else
568 pl->p_explode = 0;
569
570 redrawPlayer[pl_no] = 1;
571 PlistNoteUpdate(pl_no);
572 }
573 #endif
574
575 /* Now test if it's galactic or local coord */
576 if (save & 32)
577 { /* It's galactic */
578 if (x == 501 || y == 501)
579 {
580 Pgx[pl_no] = -500;
581 Pgy[pl_no] = -500;
582 }
583 else
584 {
585 Pgx[pl_no] = x;
586 Pgy[pl_no] = y;
587 }
588 Plx[pl_no] = -1; /* Not visible */
589 Ply[pl_no] = -1;
590 redrawPlayer[pl->p_no] = 1;
591 pl->p_x = Pgx[pl_no] * GWIDTH / SPWINSIDE;
592 pl->p_y = Pgy[pl_no] * GWIDTH / SPWINSIDE;
593
594 #ifdef ROTATERACE
595 if (rotate)
596 {
597 rotate_coord(&pl->p_x, &pl->p_y,
598 rotate_deg, GWIDTH / 2, GWIDTH / 2);
599 rotate_dir(&pl->p_dir, rotate_deg);
600 }
601 #endif
602 }
603 else
604 { /* Local */
605 Plx[pl_no] = x;
606 Ply[pl_no] = y;
607 redrawPlayer[pl->p_no] = 1;
608 pl->p_x = me->p_x + ((Plx[pl_no] - SPWINSIDE / 2) * SCALE);
609 pl->p_y = me->p_y + ((Ply[pl_no] - SPWINSIDE / 2) * SCALE);
610 Pgx[pl_no] = pl->p_x * SPWINSIDE / GWIDTH;
611 Pgy[pl_no] = pl->p_y * SPWINSIDE / GWIDTH;
612 pl->p_x = my_x + ((x - SPWINSIDE / 2) * SCALE);
613 pl->p_y = my_y + ((y - SPWINSIDE / 2) * SCALE);
614
615 #ifdef ROTATERACE
616 if (rotate)
617 {
618 rotate_coord(&pl->p_x, &pl->p_y,
619 rotate_deg, GWIDTH / 2, GWIDTH / 2);
620 rotate_dir(&pl->p_dir, rotate_deg);
621 }
622 #endif
623 }
624 } /* for */
625 } /* if */
626 else if (sbuf[1] & 64)
627 { /* Short Header */
628 if (shortversion == SHORTVERSION)
629 { /* flags S_P2 */
630 if (sbuf[2] == 2)
631 {
632 int *tmp = (int *) &sbuf[4];
633
634 new_flags(ntohl(*tmp), sbuf[3]);
635 tmp++;
636 new_flags(ntohl(*tmp), 0);
637 sbuf += 8;
638 }
639 else if (sbuf[2] == 1)
640 {
641 int *tmp = (int *) &sbuf[4];
642
643 new_flags(ntohl(*tmp), sbuf[3]);
644 sbuf += 4;
645 }
646 }
647 sbuf += 4;
648 for (i = 0; i < numofplayers; i++)
649 {
650 pl_no = ((unsigned char) *sbuf & 0x1f);
651 if (pl_no >= MAXPLAYER)
652 continue;
653 save = (unsigned char) *sbuf;
654 sbuf++;
655 pl = &players[pl_no];
656
657 pl->p_speed = (unsigned char) *sbuf & 15; /* SPEED */
658 PlistNoteSpeed(pl_no);
659
660 if (F_cloak_maxwarp && pl != me)
661 {
662 if (pl->p_speed == 0xf)
663 pl->p_flags |= PFCLOAK;
664 else if (pl->p_flags & PFCLOAK)
665 pl->p_flags &= ~PFCLOAK;
666 }
667
668 Pdir[pl_no] = (unsigned char) *sbuf >> 4; /* DIR */
669 pl->p_dir = (unsigned char) Pdir[pl_no] * 16; /* real DIR */
670 sbuf++;
671 x = (unsigned char) *sbuf++;
672 y = (unsigned char) *sbuf++; /* The lower 8 Bits are * *
673 * saved */
674 /* Now we must preprocess the coordinates */
675 if ((unsigned char) save & 64)
676 x |= 256;
677 if ((unsigned char) save & 128)
678 y |= 256;
679
680 #ifdef WARP_DEAD
681 /* waiting for server change [007] */
682 if (F_dead_warp && pl->p_speed == 14 && x == 501 && y == 501 && (pl->p_status != PEXPLODE))
683 {
684 pl->p_status = PEXPLODE;
685 x = pl->p_x;
686 y = pl->p_y;
687 if (pl->p_dir > DEADPACKETS)
688 pl->p_explode = EX_FRAMES;
689 else
690 pl->p_explode = 0;
691 redrawPlayer[pl_no] = 1;
692 PlistNoteUpdate(pl_no);
693 }
694 #endif
695
696 /* Now test if it's galactic or local coord */
697 if (save & 32)
698 { /* It's galactic */
699 if (x == 501 || y == 501)
700 {
701 Pgx[pl_no] = -500;
702 Pgy[pl_no] = -500;
703 }
704 else
705 {
706 Pgx[pl_no] = x;
707 Pgy[pl_no] = y;
708 }
709 Plx[pl_no] = -1; /* Not visible */
710 Ply[pl_no] = -1;
711 redrawPlayer[pl->p_no] = 1;
712 pl->p_x = Pgx[pl_no] * GWIDTH / SPWINSIDE;
713 pl->p_y = Pgy[pl_no] * GWIDTH / SPWINSIDE;
714
715 #ifdef ROTATERACE
716 if (rotate)
717 {
718 rotate_coord(&pl->p_x, &pl->p_y,
719 rotate_deg, GWIDTH / 2, GWIDTH / 2);
720 rotate_dir(&pl->p_dir, rotate_deg);
721 }
722 #endif
723 }
724 else
725 { /* Local */
726 Plx[pl_no] = x;
727 Ply[pl_no] = y;
728 redrawPlayer[pl->p_no] = 1;
729 pl->p_x = me->p_x + ((Plx[pl_no] - SPWINSIDE / 2) * SCALE);
730 pl->p_y = me->p_y + ((Ply[pl_no] - SPWINSIDE / 2) * SCALE);
731 Pgx[pl_no] = pl->p_x * SPWINSIDE / GWIDTH;
732 Pgy[pl_no] = pl->p_y * SPWINSIDE / GWIDTH;
733 pl->p_x = my_x + ((x - SPWINSIDE / 2) * SCALE);
734 pl->p_y = my_y + ((y - SPWINSIDE / 2) * SCALE);
735
736 #ifdef ROTATERACE
737 if (rotate)
738 {
739 rotate_coord(&pl->p_x, &pl->p_y,
740 rotate_deg, GWIDTH / 2, GWIDTH / 2);
741 rotate_dir(&pl->p_dir, rotate_deg);
742 }
743 #endif
744 }
745 } /* for */
746 } /* 2. if */
747 else
748 { /* Big Packet */
749 struct player_s_spacket *packet = (struct player_s_spacket *) sbuf;
750
751 pl = &players[me->p_no];
752 pl->p_dir = (unsigned char) packet->dir;
753 Pdir[me->p_no] = (unsigned char) rosette(pl->p_dir);
754
755 pl->p_speed = packet->speed;
756 PlistNoteSpeed(me->p_no);
757
758 if (F_cloak_maxwarp && pl != me)
759 {
760 if (pl->p_speed == 0xf)
761 pl->p_flags |= PFCLOAK;
762 else if (pl->p_flags & PFCLOAK)
763 pl->p_flags &= ~PFCLOAK;
764 }
765 if (shortversion == SHORTVERSION)
766 { /* S_P2 */
767 struct player_s2_spacket *pa2 = (struct player_s2_spacket *) sbuf;
768
769 x = SCALE * (short) ntohs(pa2->x);
770 y = SCALE * (short) ntohs(pa2->y);
771 new_flags(ntohl(pa2->flags), 0);
772 }
773 else
774 { /* OLDSHORTVERSION */
775 x = ntohl(packet->x);
776 y = ntohl(packet->y);
777 }
778
779 #ifdef WARP_DEAD
780 if (F_dead_warp && pl->p_speed == 14 && x == -10000 && y == -10000 && (pl->p_status != PEXPLODE))
781 {
782 pl->p_status = PEXPLODE;
783 x = pl->p_x;
784 y = pl->p_y;
785 if (pl->p_dir > DEADPACKETS)
786 pl->p_explode = EX_FRAMES;
787 else
788 pl->p_explode = 0;
789 redrawPlayer[me->p_no] = 1;
790 PlistNoteUpdate(me->p_no);
791 }
792 #endif
793
794 pl->p_x = my_x = x;
795 pl->p_y = my_y = y;
796 Plx[me->p_no] = TWINSIDE / 2;
797 Ply[me->p_no] = TWINSIDE / 2;
798 Pgx[me->p_no] = pl->p_x * GWINSIDE / GWIDTH;
799 Pgy[me->p_no] = pl->p_y * GWINSIDE / GWIDTH;
800 redrawPlayer[me->p_no] = 1;
801
802 #ifdef ROTATERACE
803 if (rotate)
804 {
805 rotate_coord(&pl->p_x, &pl->p_y,
806 rotate_deg, GWIDTH / 2, GWIDTH / 2);
807 rotate_dir(&pl->p_dir, rotate_deg);
808 }
809 #endif
810
811 if (sbuf[1] == 0)
812 return;
813 sbuf += 12; /* Now the small packets */
814 for (i = 0; i < numofplayers; i++)
815 {
816 pl_no = ((unsigned char) *sbuf & 0x1f);
817 if (pl_no >= MAXPLAYER)
818 continue;
819 save = (unsigned char) *sbuf;
820 sbuf++;
821 pl = &players[pl_no];
822
823 pl->p_speed = (unsigned char) *sbuf & 15; /* SPEED */
824 PlistNoteSpeed(pl_no);
825
826 if (F_cloak_maxwarp && pl != me)
827 {
828 if (pl->p_speed == 0xf)
829 pl->p_flags |= PFCLOAK;
830 else if (pl->p_flags & PFCLOAK)
831 pl->p_flags &= ~PFCLOAK;
832 }
833
834 Pdir[pl_no] = (unsigned char) *sbuf >> 4; /* DIR */
835 pl->p_dir = (unsigned char) Pdir[pl_no] * 16; /* real DIR */
836 sbuf++;
837 x = (unsigned char) *sbuf++;
838 y = (unsigned char) *sbuf++; /* The lower 8 Bits are * *
839 * saved */
840 /* Now we must preprocess the coordinates */
841 if ((unsigned char) save & 64)
842 x |= 256;
843 if ((unsigned char) save & 128)
844 y |= 256;
845
846 #ifdef WARP_DEAD
847 if (F_dead_warp && pl->p_speed == 14 && x == 501 && y == 501 && (pl->p_status != PEXPLODE))
848 {
849 pl->p_status = PEXPLODE;
850 x = pl->p_x;
851 y = pl->p_y;
852 if (pl->p_dir > DEADPACKETS)
853 pl->p_explode = EX_FRAMES;
854 else
855 pl->p_explode = 0;
856 redrawPlayer[me->p_no] = 1;
857 PlistNoteUpdate(me->p_no);
858 }
859 #endif
860
861 /* Now test if it's galactic or local coord */
862 if (save & 32)
863 { /* It's galactic */
864 if (x == 501 || y == 501)
865 {
866 Pgx[pl_no] = -500;
867 Pgy[pl_no] = -500;
868 }
869 else
870 {
871 Pgx[pl_no] = x;
872 Pgy[pl_no] = y;
873 }
874 Plx[pl_no] = -1; /* Not visible */
875 Ply[pl_no] = -1;
876 redrawPlayer[pl->p_no] = 1;
877 pl->p_x = Pgx[pl_no] * GWIDTH / SPWINSIDE;
878 pl->p_y = Pgy[pl_no] * GWIDTH / SPWINSIDE;
879
880 #ifdef ROTATERACE
881 if (rotate)
882 {
883 rotate_coord(&pl->p_x, &pl->p_y,
884 rotate_deg, GWIDTH / 2, GWIDTH / 2);
885 rotate_dir(&pl->p_dir, rotate_deg);
886 }
887 #endif
888 }
889 else
890 { /* Local */
891 Plx[pl_no] = x;
892 Ply[pl_no] = y;
893 redrawPlayer[pl->p_no] = 1;
894 pl->p_x = me->p_x + ((Plx[pl_no] - SPWINSIDE / 2) * SCALE);
895 pl->p_y = me->p_y + ((Ply[pl_no] - SPWINSIDE / 2) * SCALE);
896 Pgx[pl_no] = pl->p_x * SPWINSIDE / GWIDTH;
897 Pgy[pl_no] = pl->p_y * SPWINSIDE / GWIDTH;
898 pl->p_x = my_x + (x - SPWINSIDE / 2) * SCALE;
899 pl->p_y = my_y + (y - SPWINSIDE / 2) * SCALE;
900
901 #ifdef ROTATERACE
902 if (rotate)
903 {
904 rotate_coord(&pl->p_x, &pl->p_y,
905 rotate_deg, GWIDTH / 2, GWIDTH / 2);
906 rotate_dir(&pl->p_dir, rotate_deg);
907 }
908 #endif
909 }
910 } /* for */
911 }
912 }
913
handleSMessage(struct mesg_s_spacket * packet)914 void handleSMessage(struct mesg_s_spacket *packet)
915 {
916 char buf[100];
917 char addrbuf[9];
918
919 if (debug)
920 printf("Length of Message is: %zd total Size %d \n", strlen(&packet->mesg), (int) packet->length);
921 if (packet->m_from >= MAXPLAYER)
922 packet->m_from = 255;
923
924 if (packet->m_from == 255)
925 strcpy(addrbuf, "GOD->");
926 else
927 {
928 sprintf(addrbuf, " %c%c->", teamlet[players[packet->m_from].p_team],
929 shipnos[players[packet->m_from].p_no]);
930 }
931
932 switch (packet->m_flags & (MTEAM | MINDIV | MALL))
933 {
934 case MALL:
935 sprintf(addrbuf + 5, "ALL");
936 break;
937 case MTEAM:
938 sprintf(addrbuf + 5, "%s", teamshort[me->p_team]);
939 break;
940 case MINDIV:
941 /* I know that it's me -> xxx but i copied it straight ... */
942 sprintf(addrbuf + 5, "%c%c ", teamlet[players[packet->m_recpt].p_team],
943 shipnos[packet->m_recpt]);
944 break;
945 default:
946 sprintf(addrbuf + 5, "ALL");
947 break;
948 }
949 sprintf(buf, "%-9s%s", addrbuf, &packet->mesg);
950 dmessage(buf, packet->m_flags, packet->m_from, packet->m_recpt);
951 }
952
handleShortReply(struct shortreply_spacket * packet)953 void handleShortReply(struct shortreply_spacket *packet)
954 {
955 switch (packet->repl)
956 {
957 case SPK_VOFF:
958 /* S_P2 */
959 if (shortversion == SHORTVERSION &&
960 recv_short == 0)
961 { /* retry for S_P 1 */
962 printf("Using Short Packet Version 1.\n");
963 shortversion = OLDSHORTVERSION;
964 sendShortReq(SPK_VON);
965 }
966 else
967 {
968 recv_short = 0;
969 sprefresh(SPK_VFIELD);
970 /*
971 * Get a `=' style update to fix the kills shown on the playerlist
972 * when you first enter the game. It is more than likely that we
973 * were waiting for short packets so that a `-' update could be
974 * used instead.
975 */
976 sendUdpReq(COMM_UPDATE);
977 }
978 break;
979 case SPK_VON:
980 recv_short = 1;
981 sprefresh(SPK_VFIELD);
982 spwinside = ntohs(packet->winside);
983 spgwidth = ntohl(packet->gwidth);
984 /*
985 * Get a `-' style update to fix the kills shown on the playerlist
986 * when you first enter and to fix other loss if short packets
987 * have just been turned back on.
988 */
989 sendShortReq(SPK_SALL);
990 break;
991 case SPK_MOFF:
992 recv_mesg = 0;
993 sprefresh(SPK_MFIELD);
994 W_SetSensitive(reviewWin, 0);
995 break;
996 case SPK_MON:
997 recv_mesg = 1;
998 sprefresh(SPK_MFIELD);
999 W_SetSensitive(reviewWin, 1);
1000 break;
1001 case SPK_M_KILLS:
1002 recv_kmesg = 1;
1003 sprefresh(SPK_KFIELD);
1004 break;
1005 case SPK_M_NOKILLS:
1006 recv_kmesg = 0;
1007 sprefresh(SPK_KFIELD);
1008 break;
1009 case SPK_M_WARN:
1010 recv_warn = 1;
1011 sprefresh(SPK_WFIELD);
1012 break;
1013 case SPK_M_NOWARN:
1014 recv_warn = 0;
1015 sprefresh(SPK_WFIELD);
1016 break;
1017
1018 case SPK_THRESHOLD:
1019 break;
1020 default:
1021 fprintf(stderr, "%s: unknown response packet value short-req: %d\n",
1022 "netrek", packet->repl);
1023 }
1024 }
1025
1026
handleVTorpInfo(unsigned char * sbuf)1027 void handleVTorpInfo(unsigned char *sbuf)
1028 {
1029 unsigned char *bitset, *which, *data, *infobitset, *infodata;
1030 struct torp *thetorp;
1031 int dx, dy;
1032 int shiftvar;
1033 char status, war;
1034 register int i;
1035 register int shift = 0; /* How many torps are *
1036
1037 *
1038 * * extracted (for shifting
1039 * ) */
1040
1041 /* now we must find the data ... :-) */
1042 bitset = &sbuf[1];
1043 which = &sbuf[2];
1044 infobitset = &sbuf[3];
1045 /* Where is the data ? */
1046 data = &sbuf[4];
1047 infodata = &sbuf[vtisize[numofbits[(unsigned char) sbuf[1]]]];
1048
1049 weaponUpdate = 1;
1050 thetorp = &torps[((unsigned char) *which * 8)];
1051
1052 for (shift = 0, i = 0; i < 8;
1053 thetorp++, *bitset >>= 1, *infobitset >>= 1, i++)
1054 {
1055 thetorp->t_updateFuse = MAX(2, TORP_UPDATE_FUSE * server_ups / 5);
1056
1057 if (*bitset & 01)
1058 {
1059 dx = (*data >> shift);
1060 data++;
1061 shiftvar = (unsigned char) *data; /* to silence gcc */
1062 shiftvar <<= (8 - shift);
1063 dx |= (shiftvar & 511);
1064 shift++;
1065 dy = (*data >> shift);
1066 data++;
1067 shiftvar = (unsigned char) *data; /* to silence gcc */
1068 shiftvar <<= (8 - shift);
1069 dy |= (shiftvar & 511);
1070 shift++;
1071 if (shift == 8)
1072 {
1073 shift = 0;
1074 data++;
1075 }
1076 /* Check for torp with no TorpInfo */
1077 if (!(*infobitset & 01))
1078 {
1079 if (thetorp->t_status == TFREE)
1080 {
1081 thetorp->t_status = TMOVE; /* guess */
1082 players[thetorp->t_owner].p_ntorp++;
1083 }
1084 else if (thetorp->t_owner == me->p_no &&
1085 thetorp->t_status == TEXPLODE)
1086 { /* If TFREE got lost */
1087 thetorp->t_status = TMOVE; /* guess */
1088 }
1089 }
1090
1091 /* Check if torp is visible */
1092 if (dx > SPWINSIDE || dy > SPWINSIDE)
1093 {
1094 thetorp->t_x = -100000; /* Not visible */
1095 thetorp->t_y = -100000;
1096 }
1097 else
1098 { /* visible */
1099 /* thetorp->t_x = me->p_x + ((dx - SPWINSIDE / 2) * SCALE); * *
1100 * thetorp->t_y = me->p_y + ((dy - SPWINSIDE / 2) * SCALE); */
1101 thetorp->t_x = my_x + ((dx - SPWINSIDE / 2) *
1102 SCALE);
1103 thetorp->t_y = my_y + ((dy - SPWINSIDE / 2) *
1104 SCALE);
1105
1106 #ifdef ROTATERACE
1107 if (rotate)
1108 {
1109 rotate_coord(&thetorp->t_x, &thetorp->t_y, rotate_deg,
1110 GWIDTH / 2, GWIDTH / 2);
1111 }
1112 #endif
1113 }
1114 } /* if */
1115 else
1116 { /* Got a TFREE ? */
1117 if (!(*infobitset & 01))
1118 { /* No other TorpInfo for * *
1119 * this Torp */
1120 if (thetorp->t_status && thetorp->t_status != TEXPLODE)
1121 {
1122 players[thetorp->t_owner].p_ntorp--;
1123 thetorp->t_status = TFREE; /* That's no guess */
1124 }
1125 }
1126 }
1127 /* Now the TorpInfo */
1128 if (*infobitset & 01)
1129 {
1130 war = (unsigned char) *infodata & 15 /* 0x0f */ ;
1131 status = ((unsigned char) *infodata & 0xf0) >> 4;
1132 infodata++;
1133 if (status == TEXPLODE && thetorp->t_status == TFREE)
1134 {
1135 /* FAT: redundant explosion; don't update p_ntorp */
1136 continue;
1137 }
1138 if (thetorp->t_status == TFREE && status)
1139 {
1140 players[thetorp->t_owner].p_ntorp++;
1141 }
1142 if (thetorp->t_status && status == TFREE)
1143 {
1144 players[thetorp->t_owner].p_ntorp--;
1145 }
1146 thetorp->t_war = war;
1147 if (status != thetorp->t_status)
1148 {
1149 /* FAT: prevent explosion reset */
1150 thetorp->t_status = status;
1151 if (thetorp->t_status == TEXPLODE)
1152 {
1153 thetorp->t_fuse = NUMDETFRAMES * server_ups / 5;
1154 }
1155 }
1156 } /* if */
1157
1158 } /* for */
1159 }
1160
1161
handleVPlanet(unsigned char * sbuf)1162 void handleVPlanet(unsigned char *sbuf)
1163 {
1164 register int i;
1165 register int numofplanets; /* How many Planets are in *
1166
1167 *
1168 *
1169 * * the packet */
1170 struct planet *plan;
1171 struct planet_s_spacket *packet = (struct planet_s_spacket *) &sbuf[2];
1172
1173 #ifdef ATM
1174 /* FAT: prevent excessive redraw */
1175 int redraw = 0;
1176
1177 #endif /* ATM */
1178
1179 numofplanets = (unsigned char) sbuf[1];
1180
1181 if (numofplanets > MAXPLANETS + 1)
1182 return;
1183
1184 for (i = 0; i < numofplanets; i++, packet++)
1185 {
1186 if (packet->pnum >= MAXPLANETS)
1187 continue;
1188
1189 plan = &planets[(unsigned char) packet->pnum];
1190
1191 #ifdef ATM
1192 if (plan->pl_owner != packet->owner)
1193 redraw = 1;
1194 #endif /* ATM */
1195
1196 plan->pl_owner = packet->owner;
1197
1198 #ifdef TSH
1199 if (plan->pl_owner < FED || plan->pl_owner > ORI)
1200 plan->pl_owner = NOBODY;
1201 #endif /* TSH */
1202
1203 #ifdef ATM
1204 if (plan->pl_info != packet->info)
1205 redraw = 1;
1206 #endif /* ATM */
1207
1208 plan->pl_info = packet->info;
1209 /* Redraw the planet because it was updated by server */
1210
1211 #ifdef ATM
1212 if (plan->pl_flags != (int) ntohs(packet->flags))
1213 redraw = 1;
1214 plan->pl_flags = (int) ntohs(packet->flags);
1215 #else
1216 plan->pl_flags = (int) ntohs(packet->flags) | PLREDRAW;
1217 #endif /* ATM */
1218
1219 #ifdef ATM
1220 if (plan->pl_armies != (unsigned char) packet->armies)
1221 {
1222
1223 #ifdef EM
1224 /* don't redraw when armies change unless it crosses the '4' * army
1225 * * * limit. Keeps people from watching for planet 'flicker' * when
1226 * * * players are beaming */
1227 int planetarmies = (unsigned char) packet->armies;
1228
1229 if ((plan->pl_armies < 5 && planetarmies > 4) ||
1230 (plan->pl_armies > 4 && planetarmies < 5))
1231 #endif
1232
1233 redraw = 1;
1234 }
1235 #endif /* ATM */
1236
1237 plan->pl_armies = (unsigned char) packet->armies;
1238
1239 #ifndef RECORDGAME
1240 if (plan->pl_info == 0)
1241 {
1242 plan->pl_owner = NOBODY;
1243 }
1244 #endif
1245
1246 #ifdef ATM
1247 if (redraw)
1248 plan->pl_flags |= PLREDRAW;
1249 #endif /* ATM */
1250
1251 if (gather_stats) {
1252 /*STATS_SP_S_PLANET:\tPNUM\tPL_OWNER\tINFO\tARMIES\tFLAGS*/
1253 fprintf(statsFile, "\nSTATS_SP_S_PLANET:\t");
1254 fprintf(statsFile,
1255 "%d\t%d\t%d\t%d\t%d",
1256 packet->pnum,
1257 packet->owner,
1258 packet->info,
1259 packet->armies,
1260 ntohs(packet->flags));
1261 }
1262
1263 } /* FOR */
1264 }
1265
1266
resetWeaponInfo(void)1267 void resetWeaponInfo(void)
1268 /*
1269 * Give all weapons for all ships the status of not being active.
1270 */
1271 {
1272 register int i;
1273
1274 for (i = 0; i < MAXPLAYER * MAXTORP; i++)
1275 torps[i].t_status = TFREE;
1276
1277 for (i = 0; i < MAXPLAYER * MAXPLASMA; i++)
1278 plasmatorps[i].pt_status = PTFREE;
1279
1280 for (i = 0; i < MAXPLAYER; i++)
1281 {
1282 players[i].p_ntorp = 0;
1283 players[i].p_nplasmatorp = 0;
1284 phasers[i].ph_status = PHFREE;
1285 }
1286 }
1287
1288
sendShortReq(char state)1289 void sendShortReq(char state)
1290 {
1291 struct shortreq_cpacket shortReq;
1292
1293 bzero(&shortReq, sizeof(shortReq));
1294 shortReq.type = CP_S_REQ;
1295 shortReq.req = state;
1296 shortReq.version = shortversion; /* need a var now because 2
1297 * * * S_P versions exist
1298 * S_P2 */
1299 switch (state)
1300 {
1301 case SPK_VON:
1302 warning("Sending short packet request");
1303 break;
1304 case SPK_VOFF:
1305 warning("Sending old packet request");
1306 break;
1307 default:
1308 break;
1309 }
1310 if ((state == SPK_SALL || state == SPK_ALL) && recv_short)
1311 {
1312 /* Let the client do the work, and not the network :-) */
1313
1314 resetWeaponInfo();
1315
1316 if (state == SPK_SALL)
1317 warning("Sent request for small update (weapons+planets+kills)");
1318 else if (state == SPK_ALL)
1319 warning("Sent request for medium update (all except stats)");
1320 else
1321 warning("Sent some unknown request...");
1322 }
1323
1324 sendServerPacket((struct shortreq_cpacket *) &shortReq);
1325 }
1326
1327 char *whydeadmess[] =
1328 {"", "[quit]", "[photon]", "[phaser]", "[planet]", "[explosion]",
1329 "[daemon]", "[winner]", "[ghostbust]", "[genocide]", "[hacker]", "[plasma]",
1330 "[tournend]", "[gameover]", "[gamestart]", "[bad binary]",
1331 "[detted photon]", "[chain explosion]",
1332 "[zapped plasma]", "", "[team det]", "[team explosion]"};
1333
1334
handleSWarning(struct warning_s_spacket * packet)1335 void handleSWarning(struct warning_s_spacket *packet)
1336 {
1337 char buf[80];
1338 register struct player *target;
1339 register int damage;
1340 static int arg3, arg4; /* Here are the arguments *
1341
1342 *
1343 * * for warnings with more
1344 * * * than 2 arguments */
1345 static int karg3, karg4, karg5 = 0;
1346
1347 #ifdef RCM
1348 struct distress dist;
1349 #else
1350 char killmess[20];
1351 #endif
1352
1353 switch (packet->whichmessage)
1354 {
1355 case TEXTE: /* damage used as tmp var */
1356 damage = (unsigned char) packet->argument;
1357 damage |= (unsigned char) packet->argument2 << 8;
1358
1359 #ifdef PHASER_STATS
1360 if (damage == 38) /* Plasma hit */
1361 {
1362 phaserStatTry++;
1363 phaserStatHit++;
1364 }
1365 if (damage == 37) /* Miss */
1366 phaserStatTry++;
1367 if ((damage == 37) && phaserShowStats)
1368 {
1369 /* Mung the message */
1370 char phstatmsg[30];
1371
1372 sprintf(phstatmsg, "%s [%d%%]", w_texts[damage],
1373 phaserStatTry ? (phaserStatHit * 100) / phaserStatTry : 0);
1374 /* Divide by zero sucks */
1375 warning(phstatmsg);
1376 }
1377 else
1378 #endif
1379
1380 if (damage >= 0 && damage < NUMWTEXTS)
1381 warning(w_texts[damage]);
1382 break;
1383 case PHASER_HIT_TEXT:
1384 target = &players[(unsigned char) packet->argument & 0x3f];
1385 damage = (unsigned char) packet->argument2;
1386 if ((unsigned char) packet->argument & 64)
1387 damage |= 256;
1388 if ((unsigned char) packet->argument & 128)
1389 damage |= 512;
1390
1391 #ifdef PHASER_STATS
1392 phaserStatTry++;
1393 phaserStatHit++;
1394 #endif
1395
1396 (void) sprintf(buf, "Phaser burst hit %s for %d points", target->p_name, damage);
1397 warning(buf);
1398 break;
1399 case BOMB_INEFFECTIVE:
1400 sprintf(buf, "Weapons Officer: Bombing is ineffective. Only %d armies are defending.",
1401 (int) packet->argument); /* nifty info feature * *
1402 * 2/14/92 TMC */
1403 warning(buf);
1404 break;
1405 case BOMB_TEXT:
1406 sprintf(buf, "Weapons Officer: Bombarding %s... Sensors read %d armies left.",
1407 planets[(unsigned char) packet->argument].pl_name,
1408 (unsigned char) packet->argument2);
1409 warning(buf);
1410 break;
1411 case BEAMUP_TEXT:
1412 sprintf(buf, "%s: Too few armies to beam up",
1413 planets[(unsigned char) packet->argument].pl_name);
1414 warning(buf);
1415 break;
1416 case BEAMUP2_TEXT:
1417 sprintf(buf, "Beaming up. (%d/%d)", (unsigned char) packet->argument, (unsigned char) packet->argument2);
1418 warning(buf);
1419 break;
1420 case BEAMUPSTARBASE_TEXT:
1421 sprintf(buf, "Starbase %s: Too few armies to beam up",
1422 players[(unsigned char) packet->argument].p_name);
1423 warning(buf);
1424 break;
1425 case BEAMDOWNSTARBASE_TEXT:
1426 sprintf(buf, "No more armies to beam down to Starbase %s.",
1427 players[(unsigned char) packet->argument].p_name);
1428 warning(buf);
1429
1430 break;
1431 case BEAMDOWNPLANET_TEXT:
1432 sprintf(buf, "No more armies to beam down to %s.",
1433 planets[(unsigned char) packet->argument].pl_name);
1434 warning(buf);
1435 break;
1436 case SBREPORT:
1437 sprintf(buf, "Transporter Room: Starbase %s reports all troop bunkers are full!",
1438 players[(unsigned char) packet->argument].p_name);
1439 warning(buf);
1440 break;
1441 case ONEARG_TEXT:
1442 if (packet->argument < NUMVARITEXTS)
1443 {
1444 sprintf(buf, vari_texts[(unsigned char) packet->argument],
1445 (unsigned char) packet->argument2);
1446 warning(buf);
1447 }
1448 break;
1449 case BEAM_D_PLANET_TEXT:
1450 sprintf(buf, "Beaming down. (%d/%d) %s has %d armies left",
1451 arg3,
1452 arg4,
1453 planets[(unsigned char) packet->argument].pl_name,
1454 packet->argument2);
1455 warning(buf);
1456 break;
1457 case ARGUMENTS:
1458 arg3 = (unsigned char) packet->argument;
1459 arg4 = (unsigned char) packet->argument2;
1460 break;
1461 case BEAM_U_TEXT:
1462 sprintf(buf, "Transferring ground units. (%d/%d) Starbase %s has %d armies left",
1463 (unsigned char) arg3, (unsigned char) arg4,
1464 players[(unsigned char) packet->argument].p_name,
1465 (unsigned char) packet->argument2);
1466 warning(buf);
1467 break;
1468 case LOCKPLANET_TEXT:
1469 sprintf(buf, "Locking onto %s", planets[(unsigned char) packet->argument].pl_name);
1470 warning(buf);
1471 break;
1472 case SBRANK_TEXT:
1473 sprintf(buf, "You need a rank of %s or higher to command a starbase!",
1474 ranks[(unsigned char) packet->argument].name);
1475 warning(buf);
1476 break;
1477 case SBDOCKREFUSE_TEXT:
1478 sprintf(buf, "Starbase %s refusing us docking permission captain.",
1479 players[(unsigned char) packet->argument].p_name);
1480 warning(buf);
1481 break;
1482 case SBDOCKDENIED_TEXT:
1483 sprintf(buf, "Starbase %s: Permission to dock denied, all ports currently occupied.",
1484 players[(unsigned char) packet->argument].p_name);
1485 warning(buf);
1486 break;
1487 case SBLOCKSTRANGER:
1488 sprintf(buf, "Locking onto %s (%c%c)",
1489 players[(unsigned char) packet->argument].p_name,
1490 teamlet[players[(unsigned char) packet->argument].p_team],
1491 shipnos[players[(unsigned char) packet->argument].p_no]);
1492 warning(buf);
1493 break;
1494 case SBLOCKMYTEAM:
1495 sprintf(buf, "Locking onto %s (%c%c) (docking is %s)",
1496 players[(unsigned char) packet->argument].p_name,
1497 teamlet[players[(unsigned char) packet->argument].p_team],
1498 shipnos[players[(unsigned char) packet->argument].p_no],
1499 (players[(unsigned char) packet->argument].p_flags & PFDOCKOK) ? "enabled" : "disabled");
1500 warning(buf);
1501 break;
1502 case DMKILL:
1503
1504 #ifdef RCM
1505 case INLDMKILL:
1506 #endif
1507
1508 {
1509 struct mesg_spacket msg;
1510 unsigned char killer, victim, armies;
1511 #ifndef RCM
1512 float kills;
1513 #endif
1514
1515 victim = (unsigned char) packet->argument & 0x3f;
1516 killer = (unsigned char) packet->argument2 & 0x3f;
1517 /* that's only a temp */
1518 damage = (unsigned char) karg3;
1519 damage |= (karg4 & 127) << 8;
1520
1521 #ifndef RCM
1522 kills = damage / 100.0;
1523 if (kills == 0.0)
1524 strcpy(killmess, "NO CREDIT");
1525 else
1526 sprintf(killmess, "%0.2f", kills);
1527 #endif
1528
1529 armies = (((unsigned char) packet->argument >> 6) | ((unsigned char) packet->argument2 & 192) >> 4);
1530 if (karg4 & 128)
1531 armies |= 16;
1532
1533 #ifdef RCM
1534 dist.distype = rcm;
1535 dist.sender = victim;
1536 dist.tclose_j = killer;
1537 dist.arms = armies;
1538 dist.dam = damage / 100;
1539 dist.shld = damage % 100;
1540 dist.wtmp = karg5;
1541 makedistress(&dist, msg.mesg, rcm_msg[1].macro);
1542 msg.m_flags = MALL | MVALID | MKILL;
1543 #else
1544 if (armies == 0)
1545 {
1546 (void) sprintf(msg.mesg, "GOD->ALL %s (%c%c) was kill %s for %s (%c%c)",
1547 players[victim].p_name,
1548 teamlet[players[victim].p_team],
1549 shipnos[victim],
1550 killmess,
1551 players[killer].p_name,
1552 teamlet[players[killer].p_team],
1553 shipnos[killer]);
1554 msg.m_flags = MALL | MVALID | MKILL;
1555 }
1556 else
1557 {
1558 (void) sprintf(msg.mesg, "GOD->ALL %s (%c%c+%d armies) was kill %s for %s (%c%c)",
1559 players[victim].p_name,
1560 teamlet[players[victim].p_team],
1561 shipnos[victim],
1562 armies,
1563 killmess,
1564 players[killer].p_name,
1565 teamlet[players[killer].p_team],
1566 shipnos[killer]);
1567 msg.m_flags = MALL | MVALID | MKILLA;
1568 }
1569 if (why_dead)
1570 {
1571 dist->wtmp = karg5
1572 add_whydead(msg.mesg, karg5);
1573 karg5 = 0;
1574 }
1575 #endif
1576
1577 msg.type = SP_MESSAGE;
1578 msg.mesg[79] = '\0';
1579 msg.m_recpt = 0;
1580 msg.m_from = 255;
1581 handleMessage(&msg);
1582 }
1583 break;
1584 case KILLARGS:
1585 karg3 = (unsigned char) packet->argument;
1586 karg4 = (unsigned char) packet->argument2;
1587 break;
1588 case KILLARGS2:
1589 karg5 = (unsigned char) packet->argument;
1590 break;
1591 case DMKILLP:
1592
1593 #ifdef RCM
1594 case INLDMKILLP:
1595 #endif
1596
1597 {
1598 struct mesg_spacket msg;
1599
1600 #ifdef RCM
1601 dist.distype = rcm;
1602 dist.sender = packet->argument;
1603 dist.tclose_j = packet->argument;
1604 dist.arms = '\0';
1605 dist.dam = '\0';
1606 dist.shld = '\0';
1607 dist.tclose_pl = packet->argument2;
1608 dist.wtmp = karg5;
1609 makedistress(&dist, msg.mesg, rcm_msg[2].macro);
1610 #else
1611 (void) sprintf(msg.mesg, "GOD->ALL %s (%c%c) killed by %s (%c)",
1612 players[packet->argument].p_name,
1613 teamlet[players[packet->argument].p_team],
1614 shipnos[packet->argument],
1615 planets[(unsigned char) packet->argument2].pl_name,
1616 teamlet[planets[(unsigned char) packet->argument2].pl_owner]);
1617 if (why_dead)
1618 {
1619 add_whydead(msg.mesg, karg5);
1620 karg5 = 0;
1621 }
1622 #endif
1623
1624 msg.type = SP_MESSAGE;
1625 msg.mesg[79] = '\0';
1626 msg.m_flags = MALL | MVALID | MKILLP;
1627 msg.m_recpt = 0;
1628 msg.m_from = 255;
1629 handleMessage(&msg);
1630 }
1631 break;
1632 case DMBOMB:
1633 {
1634 struct mesg_spacket msg;
1635
1636 #ifdef RCM
1637 dist.distype = rcm;
1638 dist.sender = packet->argument;
1639 dist.tclose_j = packet->argument;
1640 dist.arms = '\0';
1641 dist.dam = arg3;
1642 dist.shld = '\0';
1643 dist.tclose_pl = packet->argument2;
1644 dist.wtmp = karg5;
1645 makedistress(&dist, msg.mesg, rcm_msg[3].macro);
1646 #else
1647 char buf1[80];
1648 (void) sprintf(buf, "%-3s->%-3s", planets[(unsigned char) packet->argument2].pl_name, teamshort[planets[(unsigned char) packet->argument2].pl_owner]);
1649 (void) sprintf(buf1, "We are being attacked by %s %c%c who is %d%% damaged.",
1650 players[packet->argument].p_name,
1651 teamlet[players[packet->argument].p_team],
1652 shipnos[packet->argument],
1653 arg3);
1654 (void) sprintf(msg.mesg, "%s %s", buf, buf1);
1655 #endif
1656
1657 msg.type = SP_MESSAGE;
1658 msg.mesg[79] = '\0';
1659 msg.m_flags = MTEAM | MBOMB | MVALID;
1660 msg.m_recpt = planets[(unsigned char) packet->argument2].pl_owner;
1661 msg.m_from = 255;
1662 handleMessage(&msg);
1663 }
1664 break;
1665 case DMDEST:
1666 {
1667 struct mesg_spacket msg;
1668
1669 #ifdef RCM
1670 dist.distype = rcm;
1671 dist.sender = packet->argument2;
1672 dist.tclose_j = packet->argument2;
1673 dist.arms = '\0';
1674 dist.dam = '\0';
1675 dist.shld = '\0';
1676 dist.tclose_pl = packet->argument;
1677 dist.wtmp = karg5;
1678 makedistress(&dist, msg.mesg, rcm_msg[4].macro);
1679 #else
1680 char buf1[80];
1681
1682 (void) sprintf(buf, "%s destroyed by %s (%c%c)",
1683 planets[(unsigned char) packet->argument].pl_name,
1684 players[packet->argument2].p_name,
1685 teamlet[players[packet->argument2].p_team],
1686 shipnos[(unsigned char) packet->argument2]);
1687 (void) sprintf(buf1, "%-3s->%-3s",
1688 planets[(unsigned char) packet->argument].pl_name, teamshort[planets[(unsigned char) packet->argument].pl_owner]);
1689 (void) sprintf(msg.mesg, "%s %s", buf1, buf);
1690 #endif
1691
1692 msg.type = SP_MESSAGE;
1693 msg.mesg[79] = '\0';
1694 msg.m_flags = MTEAM | MDEST | MVALID;
1695 msg.m_recpt = planets[(unsigned char) packet->argument].pl_owner;
1696 msg.m_from = 255;
1697 handleMessage(&msg);
1698 }
1699 break;
1700 case DMTAKE:
1701 {
1702 struct mesg_spacket msg;
1703
1704 #ifdef RCM
1705 dist.distype = rcm;
1706 dist.sender = packet->argument2;
1707 dist.tclose_j = packet->argument2;
1708 dist.arms = '\0';
1709 dist.dam = '\0';
1710 dist.shld = '\0';
1711 dist.tclose_pl = packet->argument;
1712 dist.wtmp = karg5;
1713 makedistress(&dist, msg.mesg, rcm_msg[5].macro);
1714 #else
1715 char buf1[80];
1716
1717 (void) sprintf(buf, "%s taken over by %s (%c%c)",
1718 planets[(unsigned char) packet->argument].pl_name,
1719 players[packet->argument2].p_name,
1720 teamlet[players[packet->argument2].p_team],
1721 shipnos[packet->argument2]);
1722 (void) sprintf(buf1, "%-3s->%-3s",
1723 planets[(unsigned char) packet->argument].pl_name, teamshort[players[packet->argument2].p_team]);
1724 (void) sprintf(msg.mesg, "%s %s", buf1, buf);
1725 #endif
1726
1727 msg.type = SP_MESSAGE;
1728 msg.mesg[79] = '\0';
1729 msg.m_flags = MTEAM | MTAKE | MVALID;
1730 msg.m_recpt = players[(unsigned char) packet->argument2].p_team;
1731 msg.m_from = 255;
1732 handleMessage(&msg);
1733 }
1734 break;
1735 case DGHOSTKILL:
1736 {
1737 struct mesg_spacket msg;
1738 unsigned short damage;
1739
1740 damage = (unsigned char) karg3;
1741 damage |= (unsigned char) (karg4 & 0xff) << 8;
1742
1743 #ifdef RCM
1744 dist.distype = rcm;
1745 dist.sender = packet->argument;
1746 dist.tclose_j = packet->argument;
1747 dist.arms = '\0';
1748 dist.dam = damage / 100;
1749 dist.shld = damage % 100;
1750 dist.wtmp = karg5;
1751 makedistress(&dist, msg.mesg, rcm_msg[6].macro);
1752 #else
1753 (void) sprintf(msg.mesg, "GOD->ALL %s (%c%c) was kill %0.2f for the GhostBusters",
1754 players[(unsigned char) packet->argument].p_name, teamlet[players[(unsigned char) packet->argument].p_team],
1755 shipnos[(unsigned char) packet->argument],
1756 (float) damage / 100.0);
1757 #endif
1758
1759 msg.type = SP_MESSAGE;
1760 msg.mesg[79] = '\0';
1761 msg.m_flags = MALL | MVALID;
1762 msg.m_recpt = 0;
1763 msg.m_from = 255;
1764 handleMessage(&msg);
1765 }
1766 break;
1767 /* INL Daemon Mesages */
1768
1769 #ifndef RCM
1770 case INLDMKILLP:
1771 {
1772 struct mesg_spacket msg;
1773
1774 sprintf(buf, "");
1775 if (arg3)
1776 { /* Armies */
1777 sprintf(buf, "+%d", arg3);
1778 }
1779 (void) sprintf(msg.mesg, "GOD->ALL %s(%s) (%c%c%s) killed by %s (%c)",
1780 players[(unsigned char) packet->argument].p_name,
1781 shiptype[players[(unsigned char) packet->argument].p_ship.s_type],
1782 teamlet[players[(unsigned char) packet->argument].p_team],
1783 shipnos[(unsigned char) packet->argument],
1784 buf,
1785 planets[(unsigned char) packet->argument2].pl_name,
1786 teamlet[planets[(unsigned char) packet->argument2].pl_owner]);
1787 if (why_dead)
1788 {
1789 add_whydead(msg.mesg, karg5);
1790 karg5 = 0;
1791 }
1792 msg.type = SP_MESSAGE;
1793 msg.mesg[79] = '\0';
1794 msg.m_flags = MALL | MVALID | MKILLP;
1795 msg.m_recpt = 0;
1796 msg.m_from = 255;
1797 handleMessage(&msg);
1798 }
1799 break;
1800 case INLDMKILL:
1801 {
1802 struct mesg_spacket msg;
1803 int killer, victim, armies;
1804 float kills;
1805
1806 victim = (unsigned char) packet->argument & 0x3f;
1807 killer = (unsigned char) packet->argument2 & 0x3f;
1808 /* that's only a temp */
1809 damage = (unsigned char) karg3;
1810 damage |= (karg4 & 127) << 8;
1811 kills = damage / 100.0;
1812 armies = (((unsigned char) packet->argument >> 6) | ((unsigned char) packet->argument2 & 192) >> 4);
1813 if (karg4 & 128)
1814 armies |= 16;
1815 if (armies == 0)
1816 {
1817 (void) sprintf(msg.mesg, "GOD->ALL %s(%s) (%c%c) was kill %0.2f for %s(%s) (%c%c)",
1818 players[victim].p_name,
1819 shiptype[players[victim].p_ship.s_type],
1820 teamlet[players[victim].p_team],
1821 shipnos[victim],
1822 kills,
1823 players[killer].p_name,
1824 shiptype[players[killer].p_ship.s_type],
1825 teamlet[players[killer].p_team],
1826 shipnos[killer]);
1827 msg.m_flags = MALL | MVALID | MKILL;
1828 }
1829 else
1830 {
1831 (void) sprintf(msg.mesg, "GOD->ALL %s(%s) (%c%c+%d armies) was kill %0.2f for %s(%s) (%c%c)",
1832 players[victim].p_name,
1833 shiptype[players[victim].p_ship.s_type],
1834 teamlet[players[victim].p_team],
1835 shipnos[victim],
1836 armies,
1837 kills,
1838 players[killer].p_name,
1839 shiptype[players[killer].p_ship.s_type],
1840 teamlet[players[killer].p_team],
1841 shipnos[killer]);
1842 msg.m_flags = MALL | MVALID | MKILLA;
1843 }
1844 if (why_dead)
1845 {
1846 add_whydead(msg.mesg, karg5);
1847 karg5 = 0;
1848 }
1849 msg.type = SP_MESSAGE;
1850 msg.mesg[79] = '\0';
1851 msg.m_recpt = 0;
1852 msg.m_from = 255;
1853 handleMessage(&msg);
1854 }
1855 break;
1856 #endif
1857
1858 case INLDRESUME:
1859 {
1860 struct mesg_spacket msg;
1861
1862 sprintf(msg.mesg, " Game will resume in %d seconds", (unsigned char) packet->argument);
1863 msg.m_flags = MALL | MVALID;
1864 msg.type = SP_MESSAGE;
1865 msg.mesg[79] = '\0';
1866 msg.m_recpt = 0;
1867 msg.m_from = 255;
1868 handleMessage(&msg);
1869 }
1870 break;
1871 case INLDTEXTE:
1872 if ((unsigned char) packet->argument < NUMDAEMONTEXTS)
1873 {
1874 struct mesg_spacket msg;
1875
1876 strcpy(msg.mesg, daemon_texts[(unsigned char) packet->argument]);
1877 msg.m_flags = MALL | MVALID;
1878 msg.type = SP_MESSAGE;
1879 msg.mesg[79] = '\0';
1880 msg.m_recpt = 0;
1881 msg.m_from = 255;
1882 handleMessage(&msg);
1883 }
1884 break;
1885 case STEXTE:
1886 warning(s_texte[(unsigned char) packet->argument]);
1887 break;
1888 case SHORT_WARNING:
1889 {
1890 struct warning_spacket *warn = (struct warning_spacket *) packet;
1891
1892 warning(warn->mesg);
1893 }
1894 break;
1895 case STEXTE_STRING:
1896 {
1897 struct warning_spacket *warn = (struct warning_spacket *) packet;
1898
1899 warning(warn->mesg);
1900 s_texte[(unsigned char) warn->pad2] = (char *) malloc(warn->pad3 - 4);
1901 if (s_texte[(unsigned char) warn->pad2] == NULL)
1902 {
1903 s_texte[(unsigned char) warn->pad2] = no_memory;
1904 warning("Could not add warning! (No memory!)");
1905 }
1906 else
1907 strcpy(s_texte[(unsigned char) warn->pad2], warn->mesg);
1908 }
1909 break;
1910 default:
1911 warning("Unknown Short Warning!");
1912 break;
1913 }
1914 }
1915
1916 #define MY_SIZEOF(a) (sizeof(a) / sizeof(*(a)))
1917
1918 void
add_whydead(char * s,int m)1919 add_whydead(char *s, int m) /* 7/22/93 LAB */
1920 {
1921 char b[256];
1922
1923 if (m < MY_SIZEOF(whydeadmess))
1924 {
1925 sprintf(b, "%-50s %s", s, whydeadmess[m]);
1926 b[79] = '\0';
1927 strcpy(s, b);
1928 }
1929 }
1930
1931 /* S_P2 */
1932 void
handleVKills(sbuf)1933 handleVKills(sbuf)
1934 unsigned char *sbuf;
1935 {
1936 register int i, numofkills, pnum;
1937 register unsigned short pkills;
1938 register unsigned char *data = &sbuf[2];
1939
1940 numofkills = (unsigned char) sbuf[1];
1941
1942 for (i = 0; i < numofkills; i++)
1943 {
1944 pkills = (unsigned short) *data++;
1945 pkills |= (unsigned short) ((*data & 0x03) << 8);
1946 pnum = (unsigned char) *data++ >> 2;
1947
1948 #ifdef CORRUPTED_PACKETS
1949 if (pnum < 0 || pnum >= MAXPLAYER)
1950 {
1951 fprintf(stderr, "handleKills: bad index %d\n", pnum);
1952 return;
1953 }
1954 #endif
1955
1956 if (players[pnum].p_kills != ((float) pkills / 100.0))
1957 {
1958 players[pnum].p_kills = pkills / 100.0;
1959 /* FAT: prevent redundant player update */
1960 PlistNoteUpdate(pnum);
1961
1962 #ifdef ARMY_SLIDER
1963 if (me == &players[(int) pnum])
1964 {
1965 calibrate_stats();
1966 redrawStats();
1967 }
1968 #endif /* ARMY_SLIDER */
1969 }
1970
1971 } /* for */
1972
1973 } /* handleVKills */
1974
1975 void
handleVPhaser(sbuf)1976 handleVPhaser(sbuf)
1977 unsigned char *sbuf;
1978 {
1979 struct phaser *phas;
1980 struct phaser_s_spacket *packet = (struct phaser_s_spacket *) &sbuf[0];
1981
1982 /* not nice but.. */
1983 register int pnum, status, target = 0, x = 0, y = 0, dir = 0;
1984
1985 status = packet->status & 0x0f;
1986 pnum = packet->pnum & 0x3f;
1987 weaponUpdate = 1;
1988
1989 switch (status)
1990 {
1991 case PHFREE:
1992 break;
1993 case PHHIT:
1994 target = (unsigned char) packet->target & 0x3f;
1995 break;
1996 case PHMISS:
1997 dir = (unsigned char) packet->target;
1998 break;
1999 case PHHIT2:
2000 x = SCALE * (ntohs(packet->x));
2001 y = SCALE * (ntohs(packet->y));
2002 target = packet->target & 0x3f;
2003 break;
2004 default:
2005 x = SCALE * (ntohs(packet->x));
2006 y = SCALE * (ntohs(packet->y));
2007 target = packet->target & 0x3f;
2008 dir = (unsigned char) packet->dir;
2009 break;
2010 }
2011 phas = &phasers[pnum];
2012 phas->ph_status = status;
2013 phas->ph_dir = dir;
2014 phas->ph_x = x;
2015 phas->ph_y = y;
2016 phas->ph_target = target;
2017 phas->ph_fuse = 0;
2018 #ifdef SOUND
2019 phas->sound_phaser = 1;
2020 #endif
2021 phas->ph_updateFuse = PHASER_UPDATE_FUSE * server_ups / 10;
2022
2023 #ifdef ROTATERACE
2024 if (rotate)
2025 {
2026 rotate_coord(&phas->ph_x, &phas->ph_y, rotate_deg, GWIDTH / 2, GWIDTH / 2);
2027 rotate_dir(&phas->ph_dir, rotate_deg);
2028 }
2029 #endif
2030 }
2031
2032 void
handle_s_Stats(packet)2033 handle_s_Stats(packet)
2034 struct stats_s_spacket *packet;
2035 {
2036 register struct player *pl;
2037
2038 #ifdef CORRUPTED_PACKETS
2039 if (packet->pnum < 0 || packet->pnum >= MAXPLAYER)
2040 {
2041 fprintf(stderr, "handleStats: bad index %d\n", packet->pnum);
2042 return;
2043 }
2044 #endif
2045
2046 pl = &players[(unsigned char) packet->pnum];
2047
2048 pl->p_stats.st_tkills = ntohs(packet->tkills);
2049 pl->p_stats.st_tlosses = ntohs(packet->tlosses);
2050 pl->p_stats.st_kills = ntohs(packet->kills);
2051 pl->p_stats.st_losses = ntohs(packet->losses);
2052 pl->p_stats.st_tticks = ntohl(packet->tticks);
2053 pl->p_stats.st_tplanets = ntohs(packet->tplanets);
2054 pl->p_stats.st_tarmsbomb = ntohl(packet->tarmies);
2055 pl->p_stats.st_sbkills = ntohs(packet->sbkills);
2056 pl->p_stats.st_sblosses = ntohs(packet->sblosses);
2057 pl->p_stats.st_armsbomb = ntohs(packet->armies);
2058 pl->p_stats.st_planets = ntohs(packet->planets);
2059 if ((pl->p_ship.s_type == STARBASE) && (SBhours))
2060 {
2061 pl->p_stats.st_sbticks = ntohl(packet->maxkills);
2062 }
2063 else
2064 {
2065 pl->p_stats.st_maxkills = ntohl(packet->maxkills) / 100.0;
2066 }
2067 pl->p_stats.st_sbmaxkills = ntohl(packet->sbmaxkills) / 100.0;
2068
2069 PlistNoteUpdate((unsigned char) packet->pnum);
2070 }
2071
new_flags(unsigned int data,int which)2072 void new_flags(unsigned int data, int which)
2073 {
2074 register int pnum, status;
2075 register unsigned int new, tmp;
2076 unsigned int oldflags;
2077 struct player *j;
2078
2079 tmp = data;
2080 for (pnum = which * 16; pnum < (which + 1) * 16 && pnum < MAXPLAYER; pnum++)
2081 {
2082 new = tmp & 0x03;
2083 tmp >>= 2;
2084 j = &players[pnum];
2085
2086 oldflags = j->p_flags;
2087 switch (new)
2088 {
2089 case 0: /* PDEAD/PEXPLODE */
2090 status = PEXPLODE;
2091 j->p_flags &= ~PFCLOAK;
2092 break;
2093 case 1: /* PALIVE & PFCLOAK */
2094 status = PALIVE;
2095 j->p_flags |= PFCLOAK;
2096 break;
2097 case 2: /* PALIVE & PFSHIELD */
2098 status = PALIVE;
2099 j->p_flags |= PFSHIELD;
2100 j->p_flags &= ~PFCLOAK;
2101 break;
2102 case 3: /* PALIVE & NO shields */
2103 status = PALIVE;
2104 j->p_flags &= ~(PFSHIELD | PFCLOAK);
2105 break;
2106 default:
2107 break;
2108 }
2109
2110 if (oldflags != j->p_flags)
2111 redrawPlayer[pnum] = 1;
2112
2113 if (j->p_status == status)
2114 continue;
2115
2116 if (status == PEXPLODE)
2117 {
2118 if (j->p_status == PALIVE)
2119 {
2120 j->p_explode = 0;
2121 j->p_status = status;
2122 }
2123 else /* Do nothing */
2124 continue;
2125 }
2126 else
2127 { /* really PALIVE ? */
2128 if (j == me)
2129 {
2130 /* Wait for POUTFIT */
2131 if (j->p_status == POUTFIT || j->p_status == PFREE)
2132 {
2133 if (j->p_status != PFREE)
2134 j->p_kills = 0.;
2135 else
2136 PlistNoteArrive(pnum);
2137
2138 j->p_status = PALIVE;
2139 }
2140 }
2141 else
2142 {
2143 if (j->p_status != PFREE)
2144 j->p_kills = 0.;
2145 else
2146 PlistNoteArrive(pnum);
2147
2148 j->p_status = status;
2149 }
2150 }
2151 redrawPlayer[pnum] = 1;
2152 PlistNoteUpdate(pnum);
2153 } /* for */
2154 }
2155 #endif
2156
2157 /* END SHORT_PACKETS */
2158