Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison gameconf.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: gameconf.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */ | |
2 | |
3 #include <stdio.h> | |
4 #include <string.h> | |
5 #include <sys/types.h> | |
6 #include <netinet/in.h> | |
7 #include <time.h> | |
8 #ifndef hpux | |
9 #include <sys/time.h> | |
10 #endif | |
11 #ifdef __STDC__ | |
12 #include <stdlib.h> | |
13 #endif | |
14 | |
15 #include "gameconf.h" | |
16 #include "defaultlogos.h" | |
17 #include "data.h" | |
18 #include "gppackets.h" | |
19 | |
20 int number_of_teams; | |
21 | |
22 struct teaminfo_s *teaminfo = 0; | |
23 | |
24 void | |
25 load_default_teams() | |
26 { | |
27 number_of_teams = 4; | |
28 | |
29 /* independent is teaminfo[-1], allteam is teaminfo[4] */ | |
30 teaminfo = 1 + (struct teaminfo_s *) malloc(sizeof(*teaminfo) * (number_of_teams + 2)); | |
31 | |
32 strcpy(teaminfo[-1].name, "Independant"); | |
33 teaminfo[-1].letter = 'I'; | |
34 strcpy(teaminfo[-1].shortname, "IND"); | |
35 | |
36 strcpy(teaminfo[0].name, "Federation"); | |
37 teaminfo[0].letter = 'F'; | |
38 strcpy(teaminfo[0].shortname, "FED"); | |
39 | |
40 | |
41 strcpy(teaminfo[1].name, "Romulan"); | |
42 teaminfo[1].letter = 'R'; | |
43 strcpy(teaminfo[1].shortname, "ROM"); | |
44 | |
45 | |
46 strcpy(teaminfo[2].name, "Klingon"); | |
47 teaminfo[2].letter = 'K'; | |
48 strcpy(teaminfo[2].shortname, "KLI"); | |
49 | |
50 | |
51 strcpy(teaminfo[3].name, "Orion"); | |
52 teaminfo[3].letter = 'O'; | |
53 strcpy(teaminfo[3].shortname, "ORI"); | |
54 | |
55 strcpy(teaminfo[4].name, "None"); | |
56 teaminfo[4].letter = '-'; | |
57 strcpy(teaminfo[4].shortname, "NON"); | |
58 } | |
59 | |
60 void | |
61 load_default_teamlogos() | |
62 { | |
63 if (number_of_teams < 1) | |
64 return; | |
65 teaminfo[0].shield_logo = W_StoreBitmap(fedshield_width, fedshield_height, | |
66 fedshield_bits, teamWin[0]); | |
67 if (number_of_teams < 2) | |
68 return; | |
69 teaminfo[1].shield_logo = W_StoreBitmap(romshield_width, romshield_height, | |
70 romshield_bits, teamWin[1]); | |
71 if (number_of_teams < 3) | |
72 return; | |
73 teaminfo[2].shield_logo = W_StoreBitmap(klishield_width, klishield_height, | |
74 klishield_bits, teamWin[2]); | |
75 if (number_of_teams < 4) | |
76 return; | |
77 teaminfo[3].shield_logo = W_StoreBitmap(orishield_width, orishield_height, | |
78 orishield_bits, teamWin[3]); | |
79 } | |
80 | |
81 void | |
82 load_generic_teams() | |
83 { | |
84 /* | |
85 reserved letters: A G T | |
86 */ | |
87 int i; | |
88 | |
89 /* independent is teaminfo[-1] */ | |
90 teaminfo = 1 + (struct teaminfo_s *) malloc(sizeof(*teaminfo) * (number_of_teams + 1)); | |
91 | |
92 strcpy(teaminfo[-1].name, "Independant"); | |
93 teaminfo[-1].letter = 'I'; | |
94 strcpy(teaminfo[-1].shortname, "IND"); | |
95 | |
96 load_default_teamlogos(); /* loads the first 4 team logos */ | |
97 | |
98 for (i = 0; i < number_of_teams; i++) { | |
99 sprintf(teaminfo[i].name, "Team #%d", i); | |
100 teaminfo[i].letter = 'J' + i; /* I, J through P */ | |
101 sprintf(teaminfo[i].shortname, "T%02d", i); | |
102 | |
103 #if 0 | |
104 /* we should draw something nifty here */ | |
105 if (i >= 4) /* the first 4 have been loaded already. */ | |
106 teaminfo[i].shield_logo = W_StoreBitmap(1, 1, &i, teamWin[i]); | |
107 /* XXX uh-oh if more than 4 teams */ | |
108 | |
109 /* exactly. If there are more than 4 teams the above will SEGV because | |
110 of the &i (which should be a char * bitmap array). | |
111 */ | |
112 #endif | |
113 | |
114 } | |
115 } | |
116 | |
117 void | |
118 initialize_thingies() | |
119 { | |
120 int i; | |
121 int n = (npthingies * nplayers + ngthingies); | |
122 thingies = (struct thingy *) malloc(sizeof(*thingies) * n); | |
123 for (i = 0; i < n; i++) { | |
124 thingies[i].t_shape = SHP_BLANK; | |
125 thingies[i].t_no = i; | |
126 thingies[i].t_owner = (i >= npthingies * nplayers) ? -1 : (i / npthingies); | |
127 } | |
128 } | |
129 | |
130 void | |
131 initialize_players() | |
132 { | |
133 int i; | |
134 | |
135 players = (struct player *) malloc(sizeof(*players) * nplayers); | |
136 | |
137 bzero(players, sizeof(struct player) * nplayers); | |
138 | |
139 for (i = 0; i < nplayers; i++) { | |
140 players[i].p_status = PFREE; | |
141 players[i].p_cloakphase = 0; | |
142 players[i].p_no = i; | |
143 players[i].p_ntorp = 0; | |
144 players[i].p_ndrone = 0;/* TSH */ | |
145 players[i].p_explode = 1; | |
146 players[i].p_stats.st_tticks = 1; | |
147 players[i].p_ship = shiptypes->ship; | |
148 } | |
149 } | |
150 | |
151 void | |
152 initialize_torps() | |
153 { | |
154 int i; | |
155 | |
156 torps = (struct torp *) malloc(sizeof(*torps) * nplayers * ntorps); | |
157 | |
158 for (i = 0; i < nplayers * ntorps; i++) { | |
159 torps[i].t_status = TFREE; | |
160 torps[i].t_no = i; | |
161 torps[i].t_owner = (i / ntorps); | |
162 } | |
163 } | |
164 | |
165 void | |
166 initialize_plasmas() | |
167 { | |
168 int i; | |
169 | |
170 plasmatorps = (struct plasmatorp *) malloc(sizeof(*plasmatorps) * nplayers * nplasmas); | |
171 | |
172 for (i = 0; i < nplayers * nplasmas; i++) { | |
173 plasmatorps[i].pt_status = PTFREE; | |
174 plasmatorps[i].pt_no = i; | |
175 plasmatorps[i].pt_owner = (i / nplasmas); | |
176 } | |
177 } | |
178 | |
179 void | |
180 initialize_phasers() | |
181 { | |
182 int i; | |
183 | |
184 phasers = (struct phaser *) malloc(sizeof(*phasers) * nplayers * nphasers); | |
185 | |
186 for (i = 0; i < nplayers * nphasers; i++) { | |
187 phasers[i].ph_status = PHFREE; | |
188 phasers[i].ph_fuse = 0; | |
189 } | |
190 } | |
191 | |
192 void | |
193 initialize_planets() | |
194 { | |
195 int i; | |
196 | |
197 planets = (struct planet *) malloc(sizeof(*planets) * nplanets); | |
198 | |
199 for (i = 0; i < nplanets; i++) { | |
200 struct planet *curr = &planets[i]; | |
201 curr->pl_no = i; | |
202 curr->pl_flags = 0; | |
203 curr->pl_owner = 0; | |
204 curr->pl_x = curr->pl_y = -10000; | |
205 sprintf(curr->pl_name, "planet%d", i); | |
206 curr->pl_namelen = strlen(curr->pl_name); | |
207 curr->pl_armies = 0; | |
208 curr->pl_info = 0; | |
209 curr->pl_deadtime = 0; | |
210 curr->pl_couptime = 0; | |
211 curr->pl_timestamp = 0; | |
212 | |
213 /* initialize planet redraw for moving planets */ | |
214 pl_update[i].plu_update = -1; | |
215 } | |
216 } | |
217 | |
218 void | |
219 init_ranks() | |
220 { | |
221 ranks2 = (struct rank2 *) malloc(sizeof(*ranks2) * nranks2); | |
222 ranks2[0].genocides = 0; | |
223 ranks2[0].di = 0; | |
224 ranks2[0].battle = 0.0; | |
225 ranks2[0].strategy = 0.0; | |
226 ranks2[0].specship = 0.0; | |
227 ranks2[0].name = strdup("Recruit"); | |
228 | |
229 ranks2[1].genocides = 1; | |
230 ranks2[1].di = 10; | |
231 ranks2[1].battle = 0.30; | |
232 ranks2[1].strategy = 0.3; | |
233 ranks2[1].specship = 0.0; | |
234 ranks2[1].name = strdup("Specialist"); | |
235 | |
236 ranks2[2].genocides = 2; | |
237 ranks2[2].di = 25; | |
238 ranks2[2].battle = 0.40; | |
239 ranks2[2].strategy = 0.6; | |
240 ranks2[2].specship = 0.0; | |
241 ranks2[2].name = strdup("Cadet"); | |
242 | |
243 ranks2[3].genocides = 3; | |
244 ranks2[3].di = 45; | |
245 ranks2[3].battle = 0.50; | |
246 ranks2[3].strategy = 0.9; | |
247 ranks2[3].specship = 0.0; | |
248 ranks2[3].name = strdup("Midshipman"); | |
249 | |
250 ranks2[4].genocides = 4; | |
251 ranks2[4].di = 70; | |
252 ranks2[4].battle = 0.70; | |
253 ranks2[4].strategy = 1.2; | |
254 ranks2[4].specship = 0.0; | |
255 ranks2[4].name = strdup("Ensn. J.G."); | |
256 | |
257 ranks2[5].genocides = 5; | |
258 ranks2[5].di = 100; | |
259 ranks2[5].battle = 0.90; | |
260 ranks2[5].strategy = 1.5; | |
261 ranks2[5].specship = 0.0; | |
262 ranks2[5].name = strdup("Ensign"); | |
263 | |
264 ranks2[6].genocides = 6; | |
265 ranks2[6].di = 140; | |
266 ranks2[6].battle = 1.10; | |
267 ranks2[6].strategy = 2.0; | |
268 ranks2[6].specship = 0.0; | |
269 ranks2[6].name = strdup("Lt. J.G."); | |
270 | |
271 ranks2[7].genocides = 8; | |
272 ranks2[7].di = 190; | |
273 ranks2[7].battle = 1.30; | |
274 ranks2[7].strategy = 2.5; | |
275 ranks2[7].specship = 0.0; | |
276 ranks2[7].name = strdup("Lieutenant"); | |
277 | |
278 ranks2[8].genocides = 10; | |
279 ranks2[8].di = 250; | |
280 ranks2[8].battle = 1.50; | |
281 ranks2[8].strategy = 3.0; | |
282 ranks2[8].specship = 0.5; | |
283 ranks2[8].name = strdup("Lt. Cmdr."); | |
284 | |
285 ranks2[9].genocides = 15; | |
286 ranks2[9].di = 300; | |
287 ranks2[9].battle = 1.80; | |
288 ranks2[9].strategy = 3.5; | |
289 ranks2[9].specship = 0.7; | |
290 ranks2[9].name = strdup("Commander"); | |
291 | |
292 ranks2[10].genocides = 18; | |
293 ranks2[10].di = 350; | |
294 ranks2[10].battle = 2.00; | |
295 ranks2[10].strategy = 4.0; | |
296 ranks2[10].specship = 1.0; | |
297 ranks2[10].name = strdup("Captain"); | |
298 | |
299 ranks2[11].genocides = 25; | |
300 ranks2[11].di = 400; | |
301 ranks2[11].battle = 2.10; | |
302 ranks2[11].strategy = 4.3; | |
303 ranks2[11].specship = 2.5; | |
304 ranks2[11].name = strdup("Fleet Capt."); | |
305 | |
306 ranks2[12].genocides = 50; | |
307 ranks2[12].di = 500; | |
308 ranks2[12].battle = 2.15; | |
309 ranks2[12].strategy = 4.8; | |
310 ranks2[12].specship = 3.0; | |
311 ranks2[12].name = strdup("Commodore"); | |
312 | |
313 ranks2[13].genocides = 75; | |
314 ranks2[13].di = 700; | |
315 ranks2[13].battle = 2.20; | |
316 ranks2[13].strategy = 5.3; | |
317 ranks2[13].specship = 3.3; | |
318 ranks2[13].name = strdup("Moff"); | |
319 | |
320 ranks2[14].genocides = 100; | |
321 ranks2[14].di = 900; | |
322 ranks2[14].battle = 2.25; | |
323 ranks2[14].strategy = 5.7; | |
324 ranks2[14].specship = 3.6; | |
325 ranks2[14].name = strdup("Grand Moff"); | |
326 | |
327 ranks2[15].genocides = 300; | |
328 ranks2[15].di = 1200; | |
329 ranks2[15].battle = 2.30; | |
330 ranks2[15].strategy = 6.0; | |
331 ranks2[15].specship = 3.8; | |
332 ranks2[15].name = strdup("Rear Adml."); | |
333 | |
334 ranks2[16].genocides = 700; | |
335 ranks2[16].di = 1700; | |
336 ranks2[16].battle = 2.35; | |
337 ranks2[16].strategy = 6.1; | |
338 ranks2[16].specship = 4.0; | |
339 ranks2[16].name = strdup("Admiral"); | |
340 | |
341 ranks2[17].genocides = 1000; | |
342 ranks2[17].di = 2500; | |
343 ranks2[17].battle = 2.40; | |
344 ranks2[17].strategy = 6.2; | |
345 ranks2[17].specship = 4.2; | |
346 ranks2[17].name = strdup("Grand Adml."); | |
347 } | |
348 | |
349 void | |
350 init_royal() | |
351 { | |
352 royal = (struct royalty *) malloc(sizeof(*royal) * nroyals); | |
353 | |
354 royal[0].name = strdup("none"); | |
355 royal[1].name = strdup("Wesley"); | |
356 royal[2].name = strdup("Centurion"); | |
357 royal[3].name = strdup("Praetor"); | |
358 royal[4].name = strdup("Emperor"); | |
359 #if 0 | |
360 royal[5].name = strdup("Wizard"); | |
361 royal[6].name = strdup("Duke"); | |
362 royal[7].name = strdup("Count"); | |
363 royal[8].name = strdup("Baron"); | |
364 royal[9].name = strdup("Knight"); | |
365 royal[10].name = strdup("Dread"); | |
366 royal[11].name = strdup("Lord of Destruction"); | |
367 royal[12].name = strdup("BlitzMeister"); | |
368 royal[13].name = strdup("Hitler"); | |
369 royal[14].name = strdup("Terminator"); | |
370 royal[15].name = strdup("Kamikaze"); | |
371 royal[16].name = strdup("Speed Kamikaze"); | |
372 royal[17].name = strdup("Carpet Bomber"); | |
373 royal[18].name = strdup("NukeMeister"); | |
374 royal[19].name = strdup("Terrorist"); | |
375 royal[20].name = strdup("Democrat"); | |
376 royal[21].name = strdup("Executioner"); | |
377 royal[22].name = strdup("DooshMeister"); | |
378 royal[23].name = strdup("Diplomat"); | |
379 royal[24].name = strdup("speed Diplomat"); | |
380 royal[25].name = strdup("Addict"); | |
381 #endif /* 0 */ | |
382 } | |
383 | |
384 void | |
385 reinit_ranks() | |
386 { | |
387 int i; | |
388 ranks2 = (struct rank2 *) malloc(sizeof(*ranks2) * nranks2); | |
389 | |
390 for (i = 0; i < nranks2; i++) { | |
391 ranks2[i].name = strdup("blank"); | |
392 } | |
393 } | |
394 | |
395 void | |
396 reinit_royal() | |
397 { | |
398 int i; | |
399 royal = (struct royalty *) malloc(sizeof(*royal) * nroyals); | |
400 | |
401 for (i = 0; i < nroyals; i++) { | |
402 royal[i].name = strdup("blank"); | |
403 } | |
404 } | |
405 | |
406 | |
407 void | |
408 resize_players() | |
409 { | |
410 int me_no; | |
411 | |
412 if (me) | |
413 me_no = me->p_no; | |
414 players = (struct player *) realloc(players, sizeof(*players) * nplayers); | |
415 if (me) { | |
416 me = &players[me_no]; | |
417 myship = me->p_ship; | |
418 } | |
419 } | |
420 | |
421 void | |
422 free_teams() | |
423 { | |
424 int i; | |
425 for (i = 0; i < number_of_teams; i++) { | |
426 W_FreeBitmap(teaminfo[i].shield_logo); | |
427 } | |
428 /* we offsetted by 1 to make room for IND */ | |
429 free(teaminfo - 1); | |
430 teaminfo = 0; | |
431 } | |
432 | |
433 void | |
434 free_torps() | |
435 { | |
436 free(torps); | |
437 torps = 0; | |
438 } | |
439 | |
440 void | |
441 free_phasers() | |
442 { | |
443 free(phasers); | |
444 phasers = 0; | |
445 } | |
446 | |
447 void | |
448 free_plasmas() | |
449 { | |
450 free(plasmatorps); | |
451 plasmatorps = 0; | |
452 } | |
453 | |
454 void | |
455 free_thingies() | |
456 { | |
457 free(thingies); | |
458 thingies = 0; | |
459 } | |
460 | |
461 void | |
462 free_ranks() | |
463 { | |
464 int i; | |
465 for (i = 0; i < nranks2; i++) | |
466 if (ranks2[i].name) | |
467 free(ranks2[i].name); | |
468 free(ranks2); | |
469 ranks2 = 0; | |
470 } | |
471 | |
472 void | |
473 free_royal() | |
474 { | |
475 int i; | |
476 for (i = 0; i < nroyals; i++) | |
477 if (royal[i].name) | |
478 free(royal[i].name); | |
479 | |
480 free(royal); | |
481 royal = 0; | |
482 } | |
483 | |
484 /* | |
485 */ | |
486 | |
487 void | |
488 build_default_configuration() | |
489 { | |
490 load_default_teams(); | |
491 /* can't load logos until we have some windows */ | |
492 | |
493 init_shiptypes(); | |
494 initialize_players(); | |
495 initialize_torps(); | |
496 initialize_thingies(); | |
497 initialize_plasmas(); | |
498 initialize_planets(); | |
499 initialize_phasers(); | |
500 | |
501 | |
502 init_ranks(); | |
503 init_royal(); | |
504 } | |
505 | |
506 /* | |
507 */ | |
508 | |
509 | |
510 int | |
511 compute_gameparam_size(buf) | |
512 char *buf; | |
513 { | |
514 struct gameparam_spacket *pkt = (struct gameparam_spacket *) buf; | |
515 | |
516 if (*buf != SP_GPARAM) | |
517 return -1; | |
518 | |
519 switch (pkt->subtype) { | |
520 case 0: | |
521 return sizeof(struct gp_sizes_spacket); | |
522 case 1: | |
523 return sizeof(struct gp_team_spacket); | |
524 case 2: | |
525 return sizeof(struct gp_teamlogo_spacket); | |
526 case 3: | |
527 return sizeof(struct gp_shipshape_spacket); | |
528 case 4: | |
529 return sizeof(struct gp_shipbitmap_spacket); | |
530 case 5: | |
531 return sizeof(struct gp_rank_spacket); | |
532 case 6: | |
533 return sizeof(struct gp_royal_spacket); | |
534 case 7: | |
535 return sizeof(struct gp_teamplanet_spacket); | |
536 default: | |
537 return -1; | |
538 } | |
539 } | |
540 | |
541 void | |
542 handleGPsizes(pkt) | |
543 struct gp_sizes_spacket *pkt; | |
544 { | |
545 free_ranks(); | |
546 free_royal(); | |
547 | |
548 free_teams(); | |
549 free_torps(); | |
550 free_phasers(); | |
551 free_plasmas(); | |
552 free_thingies(); | |
553 | |
554 free_shipshapes(); | |
555 | |
556 nplayers = pkt->nplayers; | |
557 number_of_teams = pkt->nteams; | |
558 /* shiptypes */ | |
559 nranks2 = pkt->nranks; | |
560 nroyals = pkt->nroyal; | |
561 nphasers = pkt->nphasers; | |
562 ntorps = pkt->ntorps; | |
563 nplasmas = pkt->nplasmas; | |
564 npthingies = pkt->nthingies; | |
565 ngthingies = pkt->gthingies; | |
566 | |
567 /* gwidth */ | |
568 /* flags */ | |
569 | |
570 load_generic_teams(); | |
571 | |
572 reinit_ranks(); | |
573 reinit_royal(); | |
574 | |
575 resize_players(); | |
576 initialize_torps(); | |
577 initialize_phasers(); | |
578 initialize_plasmas(); | |
579 initialize_thingies(); | |
580 | |
581 slurp_ship_bitmaps(); | |
582 } | |
583 | |
584 void | |
585 handleGPteam(pkt) | |
586 struct gp_team_spacket *pkt; | |
587 { | |
588 struct teaminfo_s *currteam; | |
589 | |
590 if ((int) pkt->index >= number_of_teams) { | |
591 fprintf(stderr, "Team #%d %s is out of range (0..%d)\n", pkt->index, | |
592 pkt->teamname, number_of_teams); | |
593 return; | |
594 } | |
595 currteam = &teaminfo[pkt->index]; | |
596 | |
597 currteam->letter = pkt->letter; | |
598 | |
599 strncpy(currteam->shortname, pkt->shortname, 3); | |
600 currteam->shortname[3] = 0; | |
601 | |
602 strncpy(currteam->name, pkt->teamname, sizeof(currteam->name) - 1); | |
603 currteam->name[sizeof(currteam->name) - 1] = 0;; | |
604 } | |
605 | |
606 void | |
607 handleGPteamlogo(pkt) | |
608 struct gp_teamlogo_spacket *pkt; | |
609 { | |
610 static char buf[13 * 99]; /* 99x99 */ | |
611 static int curr_height = 0; | |
612 static int lwidth, lheight; | |
613 static int teamindex; | |
614 int pwidth; | |
615 | |
616 if ((unsigned) pkt->teamindex >= number_of_teams) { | |
617 fprintf(stderr, "Team #%d is out of range (0..%d)\n", pkt->teamindex, | |
618 number_of_teams); | |
619 return; | |
620 } | |
621 if (pkt->y != curr_height) { | |
622 fprintf(stderr, "Bad gp_teamlogo packet sequence y(%d) != curr_height(%d)\n", | |
623 pkt->y, curr_height); | |
624 curr_height = 0; | |
625 return; | |
626 } | |
627 if (curr_height) { | |
628 if (lwidth != pkt->logowidth || lheight != pkt->logoheight || | |
629 teamindex != pkt->teamindex) { | |
630 fprintf(stderr, "gp_teamlogo packet sequence error, %d!=%d || %d!=%d || %d!=%d\n", | |
631 lwidth, pkt->logowidth, lheight, pkt->logoheight, | |
632 teamindex, pkt->teamindex); | |
633 curr_height = 0; | |
634 return; | |
635 } | |
636 } else { | |
637 teamindex = pkt->teamindex; | |
638 lwidth = pkt->logowidth; | |
639 lheight = pkt->logoheight; | |
640 if (lwidth > 99 || lheight > 99) { | |
641 fprintf(stderr, "logo too big (%dx%d), rejecting\n", lwidth, lheight); | |
642 curr_height = 0; | |
643 return; | |
644 } | |
645 } | |
646 pwidth = (lwidth - 1) / 8 + 1; | |
647 memcpy(buf + pwidth * curr_height, pkt->data, pwidth * pkt->thisheight); | |
648 curr_height += pkt->thisheight; | |
649 | |
650 if (curr_height >= lheight) { | |
651 W_FreeBitmap(teaminfo[teamindex].shield_logo); | |
652 teaminfo[teamindex].shield_logo = W_StoreBitmap(lwidth, lheight, buf, | |
653 teamWin[teamindex]); | |
654 curr_height = 0; | |
655 } | |
656 } | |
657 | |
658 void | |
659 handleGPshipshape(pkt) | |
660 struct gp_shipshape_spacket *pkt; | |
661 { | |
662 if (pkt->race < -1 || pkt->race >= number_of_teams) { | |
663 fprintf(stderr, "race #%d out of range (-1..%d)\n", pkt->race, | |
664 number_of_teams - 1); | |
665 return; | |
666 } | |
667 if ( /* pkt->shipno<0 || */ (int) pkt->shipno >= nshiptypes) { | |
668 fprintf(stderr, "ship class #%d out of range (0..%d)\n", pkt->shipno, | |
669 nshiptypes - 1); | |
670 return; | |
671 } | |
672 replace_shipshape(pkt->race, pkt->shipno, pkt->nviews, | |
673 pkt->width, pkt->height); | |
674 } | |
675 | |
676 void | |
677 handleGPshipbitmap(pkt) | |
678 struct gp_shipbitmap_spacket *pkt; | |
679 { | |
680 if (pkt->race < -1 || pkt->race >= number_of_teams) { | |
681 fprintf(stderr, "race #%d out of range (-1..%d)\n", pkt->race, | |
682 number_of_teams - 1); | |
683 return; | |
684 } | |
685 if ( /* pkt->shipno<0 || */ (int) pkt->shipno >= nshiptypes) { | |
686 fprintf(stderr, "ship class #%d out of range (0..%d)\n", pkt->shipno, | |
687 nshiptypes - 1); | |
688 return; | |
689 } | |
690 replace_ship_bitmap(pkt->race, pkt->shipno, pkt->thisview, pkt->bitmapdata); | |
691 } | |
692 | |
693 void | |
694 handleGPrank(pkt) | |
695 struct gp_rank_spacket *pkt; | |
696 { | |
697 struct rank2 *curr; | |
698 if (pkt->rankn >= nranks2) { | |
699 fprintf(stderr, "rank #%d %s out of range (0..%d)\n", pkt->rankn, | |
700 pkt->name, nranks2 - 1); | |
701 return; | |
702 } | |
703 curr = &ranks2[pkt->rankn]; | |
704 free(curr->name); | |
705 | |
706 curr->genocides = htonl(pkt->genocides); | |
707 curr->di = htonl(pkt->milliDI) / 1000.0; | |
708 curr->battle = htonl(pkt->millibattle) / 1000.0; | |
709 curr->strategy = htonl(pkt->millistrat) / 1000.0; | |
710 curr->specship = htonl(pkt->millispec) / 1000.0; | |
711 curr->name = strdup(pkt->name); | |
712 } | |
713 | |
714 void | |
715 handleGProyal(pkt) | |
716 struct gp_royal_spacket *pkt; | |
717 { | |
718 if ((int) pkt->rankn >= nroyals) { | |
719 fprintf(stderr, "Royalty #%d %s out of range (0..%d)\n", pkt->rankn, | |
720 pkt->name, nroyals - 1); | |
721 return; | |
722 } | |
723 free(royal[pkt->rankn].name); | |
724 royal[pkt->rankn].name = strdup(pkt->name); | |
725 } | |
726 | |
727 static unsigned char mplanet_bits[] = { | |
728 0xe0, 0x03, 0x18, 0x0c, 0x04, 0x10, 0x02, 0x20, 0x02, 0x20, 0x01, 0x40, | |
729 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x02, 0x20, 0x02, 0x20, | |
730 0x04, 0x10, 0x18, 0x0c, 0xe0, 0x03, 0x00, 0x00}; | |
731 static unsigned char planet_bits[] = { | |
732 0x00, 0xf8, 0x03, 0x00, 0x00, 0x07, 0x1c, 0x00, 0xc0, 0x00, 0x60, 0x00, | |
733 0x20, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, | |
734 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x08, | |
735 0x02, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x10, | |
736 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, | |
737 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, | |
738 0x02, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x08, | |
739 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x02, | |
740 0x10, 0x00, 0x00, 0x01, 0x20, 0x00, 0x80, 0x00, 0xc0, 0x00, 0x60, 0x00, | |
741 0x00, 0x07, 0x1c, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}; | |
742 | |
743 void | |
744 handleGPteamplanet(pkt) | |
745 struct gp_teamplanet_spacket *pkt; | |
746 { | |
747 { | |
748 #define TACTICALSIZE sizeof(pkt->tactical) | |
749 unsigned char tactical[TACTICALSIZE]; | |
750 int i; | |
751 int race = pkt->teamn; | |
752 | |
753 if (race < -1 || race >= number_of_teams) { | |
754 fprintf(stderr, "race #%d out of range (-1..%d)\n", race, | |
755 number_of_teams - 1); | |
756 return; | |
757 } | |
758 for (i = 0; i < TACTICALSIZE; i++) { | |
759 tactical[i] = (pkt->tactical[i] & pkt->tacticalM[i]) | | |
760 (planet_bits[i] & ~pkt->tacticalM[i]); | |
761 } | |
762 | |
763 W_FreeBitmap(bplanets[race + 1]); | |
764 bplanets[race + 1] = W_StoreBitmap(30, 30, tactical, w); | |
765 | |
766 #undef TACTICALSIZE | |
767 } | |
768 | |
769 { | |
770 #define GALACTICSIZE sizeof(pkt->galactic) | |
771 unsigned char galactic[GALACTICSIZE]; | |
772 int i; | |
773 int race = pkt->teamn; | |
774 | |
775 if (race < -1 || race >= number_of_teams) { | |
776 fprintf(stderr, "race #%d out of range (-1..%d)\n", race, | |
777 number_of_teams - 1); | |
778 return; | |
779 } | |
780 for (i = 0; i < GALACTICSIZE; i++) { | |
781 galactic[i] = (pkt->galactic[i] & pkt->galacticM[i]) | | |
782 (mplanet_bits[i] & ~pkt->galacticM[i]); | |
783 } | |
784 | |
785 W_FreeBitmap(mbplanets[race + 1]); | |
786 mbplanets[race + 1] = W_StoreBitmap(16, 16, galactic, mapw); | |
787 | |
788 #undef GALACTICSIZE | |
789 } | |
790 } | |
791 | |
792 void | |
793 handleGameparams(pkt) | |
794 struct gameparam_spacket *pkt; | |
795 { | |
796 switch (pkt->subtype) { | |
797 case 0: | |
798 handleGPsizes((struct gp_sizes_spacket *) pkt); | |
799 break; | |
800 case 1: | |
801 handleGPteam((struct gp_team_spacket *) pkt); | |
802 break; | |
803 case 2: | |
804 handleGPteamlogo((struct gp_teamlogo_spacket *) pkt); | |
805 break; | |
806 case 3: | |
807 handleGPshipshape((struct gp_shipshape_spacket *) pkt); | |
808 break; | |
809 case 4: | |
810 handleGPshipbitmap((struct gp_shipbitmap_spacket *) pkt); | |
811 break; | |
812 case 5: | |
813 handleGPrank((struct gp_rank_spacket *) pkt); | |
814 break; | |
815 case 6: | |
816 handleGProyal((struct gp_royal_spacket *) pkt); | |
817 break; | |
818 case 7: | |
819 handleGPteamplanet((struct gp_teamplanet_spacket *) pkt); | |
820 break; | |
821 default: | |
822 fprintf(stderr, "Gameparams packet subtype %d not yet implemented\n", | |
823 pkt->subtype); | |
824 } | |
825 } |