Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison shipbitmaps.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: shipbitmaps.c,v 1.1.1.1 1997/12/06 05:41:30 darius Exp $ */ | |
2 | |
3 /* with this file, now the user can define and develop new ship bitmap | |
4 sets ('albums') more easily. | |
5 | |
6 The user need only create a file in the proper directory with the | |
7 proper name with the proper format. The directory is specified by the | |
8 shipBitmapPath resource in the .xtrekrc. Its default is | |
9 /usr/games/lib/netrek. The name of the file is "R%d.C%d" where the | |
10 first integer is the race number and the second is the ship class | |
11 number. | |
12 | |
13 The format of the file is: 3 4-byte integers in network byte order. | |
14 The first is the number of views in the file (this field is currently | |
15 ignored but should have the value 16). The second integer is the | |
16 width and the third is the height. Then follows raw bitmap data. I | |
17 don't know what the format is, but it's basically a binary version of | |
18 the X bitmap file format. Translate those hex numbers to raw bytes | |
19 and you have it. I can tell you that each line is padded to 8 bits. | |
20 | |
21 */ | |
22 | |
23 #include <stdio.h> | |
24 #ifndef AMIGA | |
25 #include <sys/param.h> | |
26 #include <netinet/in.h> | |
27 #endif | |
28 #include <errno.h> | |
29 | |
30 #ifdef m_flags | |
31 /* appears under HPUX */ | |
32 #undef m_flags | |
33 #endif | |
34 | |
35 #include "Wlib.h" | |
36 #include "defs.h" | |
37 #include "struct.h" | |
38 #include "data.h" | |
39 #include "gameconf.h" | |
40 | |
41 #ifdef NOSHIPBITMAPS | |
42 #include "bitmaps_CASB.h" | |
43 #else | |
44 #include "bitmaps_NEW.h" | |
45 #ifdef HOCKEY | |
46 #include "puck.h" | |
47 #endif /*HOCKEY*/ | |
48 #endif | |
49 | |
50 static int | |
51 get_ship_width(team, shipn) | |
52 int team, shipn; | |
53 { | |
54 #ifndef NOSHIPBITMAPS | |
55 if (shipn == ATT && paradise) | |
56 return att_width; | |
57 switch (team) { | |
58 case 0: | |
59 switch (shipn) { | |
60 #ifdef HOCKEY | |
61 case PUCK: | |
62 return puck_width; | |
63 #endif /*HOCKEY*/ | |
64 case SCOUT: | |
65 return fed_scout_width; | |
66 case DESTROYER: | |
67 return fed_destroyer_width; | |
68 case CRUISER: | |
69 return fed_cruiser_width; | |
70 case BATTLESHIP: | |
71 return fed_battleship_width; | |
72 case ASSAULT: | |
73 return fed_assault_width; | |
74 case STARBASE: | |
75 return fed_starbase_width; | |
76 case JUMPSHIP: | |
77 return fed_jumpship_width; | |
78 case FLAGSHIP: | |
79 return fed_galaxy_width; | |
80 case GALAXY: | |
81 return fed_galaxy_width; | |
82 case WARBASE: | |
83 return fed_warbase_width; | |
84 case LIGHTCRUISER: | |
85 return fed_lightcruiser_width; | |
86 case CARRIER: | |
87 return fed_carrier_height; | |
88 case UTILITY: | |
89 return fed_utility_width; | |
90 case PATROL: | |
91 return fed_patrol_width; | |
92 } | |
93 case 1: | |
94 switch (shipn) { | |
95 #ifdef HOCKEY | |
96 case PUCK: | |
97 return puck_width; | |
98 #endif /*HOCKEY*/ | |
99 case SCOUT: | |
100 return rom_scout_width; | |
101 case DESTROYER: | |
102 return rom_destroyer_width; | |
103 case CRUISER: | |
104 return rom_cruiser_width; | |
105 case BATTLESHIP: | |
106 return rom_battleship_width; | |
107 case ASSAULT: | |
108 return rom_assault_width; | |
109 case STARBASE: | |
110 return rom_starbase_width; | |
111 case JUMPSHIP: | |
112 return rom_jumpship_width; | |
113 case FLAGSHIP: | |
114 return rom_galaxy_width; | |
115 case GALAXY: | |
116 return rom_galaxy_width; | |
117 case WARBASE: | |
118 return rom_warbase_width; | |
119 case LIGHTCRUISER: | |
120 return rom_lightcruiser_width; | |
121 case CARRIER: | |
122 return rom_carrier_height; | |
123 case UTILITY: | |
124 return rom_utility_width; | |
125 case PATROL: | |
126 return rom_patrol_width; | |
127 } | |
128 case 2: | |
129 switch (shipn) { | |
130 #ifdef HOCKEY | |
131 case PUCK: | |
132 return puck_width; | |
133 #endif /*HOCKEY*/ | |
134 case SCOUT: | |
135 return kli_scout_width; | |
136 case DESTROYER: | |
137 return kli_destroyer_width; | |
138 case CRUISER: | |
139 return kli_cruiser_width; | |
140 case BATTLESHIP: | |
141 return kli_battleship_width; | |
142 case ASSAULT: | |
143 return kli_assault_width; | |
144 case STARBASE: | |
145 return kli_starbase_width; | |
146 case JUMPSHIP: | |
147 return kli_jumpship_width; | |
148 case FLAGSHIP: | |
149 return kli_galaxy_width; | |
150 case GALAXY: | |
151 return kli_galaxy_width; | |
152 case WARBASE: | |
153 return kli_warbase_width; | |
154 case LIGHTCRUISER: | |
155 return kli_lightcruiser_width; | |
156 case CARRIER: | |
157 return kli_carrier_height; | |
158 case UTILITY: | |
159 return kli_utility_width; | |
160 case PATROL: | |
161 return kli_patrol_width; | |
162 } | |
163 case 3: | |
164 switch (shipn) { | |
165 #ifdef HOCKEY | |
166 case PUCK: | |
167 return puck_width; | |
168 #endif /*HOCKEY*/ | |
169 case SCOUT: | |
170 return ori_scout_width; | |
171 case DESTROYER: | |
172 return ori_destroyer_width; | |
173 case CRUISER: | |
174 return ori_cruiser_width; | |
175 case BATTLESHIP: | |
176 return ori_battleship_width; | |
177 case ASSAULT: | |
178 return ori_assault_width; | |
179 case STARBASE: | |
180 return ori_starbase_width; | |
181 case JUMPSHIP: | |
182 return ori_jumpship_width; | |
183 case FLAGSHIP: | |
184 return ori_galaxy_width; | |
185 case GALAXY: | |
186 return ori_galaxy_width; | |
187 case WARBASE: | |
188 return ori_warbase_width; | |
189 case LIGHTCRUISER: | |
190 return ori_lightcruiser_width; | |
191 case CARRIER: | |
192 return ori_carrier_height; | |
193 case UTILITY: | |
194 return ori_utility_width; | |
195 case PATROL: | |
196 return ori_patrol_width; | |
197 } | |
198 case -1: | |
199 switch (shipn) { | |
200 #ifdef HOCKEY | |
201 case PUCK: | |
202 return puck_width; | |
203 #endif /*HOCKEY*/ | |
204 case SCOUT: | |
205 return ind_scout_width; | |
206 case DESTROYER: | |
207 return ind_destroyer_width; | |
208 case CRUISER: | |
209 return ind_cruiser_width; | |
210 case BATTLESHIP: | |
211 return ind_battleship_width; | |
212 case ASSAULT: | |
213 return ind_assault_width; | |
214 case STARBASE: | |
215 return ind_starbase_width; | |
216 case JUMPSHIP: | |
217 return ind_starbase_width; | |
218 case FLAGSHIP: | |
219 return ind_galaxy_width; | |
220 case GALAXY: | |
221 return ind_galaxy_width; | |
222 case WARBASE: | |
223 return ind_starbase_width; | |
224 case LIGHTCRUISER: | |
225 return ind_lightcruiser_width; | |
226 case CARRIER: | |
227 return ind_carrier_height; | |
228 case UTILITY: | |
229 return ind_utility_width; | |
230 case PATROL: | |
231 return ind_patrol_width; | |
232 } | |
233 } | |
234 #endif /* NOSHIPBITMAPS */ | |
235 return 20; | |
236 } | |
237 | |
238 | |
239 static int | |
240 get_ship_height(team, shipn) | |
241 int team, shipn; | |
242 { | |
243 #ifndef NOSHIPBITMAPS | |
244 if (shipn == ATT && paradise) | |
245 return att_height; | |
246 switch (team) { | |
247 case 0: | |
248 switch (shipn) { | |
249 #ifdef HOCKEY | |
250 case PUCK: | |
251 return puck_height; | |
252 #endif /*HOCKEY*/ | |
253 case SCOUT: | |
254 return fed_scout_height; | |
255 case DESTROYER: | |
256 return fed_destroyer_height; | |
257 case CRUISER: | |
258 return fed_cruiser_height; | |
259 case BATTLESHIP: | |
260 return fed_battleship_height; | |
261 case ASSAULT: | |
262 return fed_assault_height; | |
263 case STARBASE: | |
264 return fed_starbase_height; | |
265 case JUMPSHIP: | |
266 return fed_jumpship_height; | |
267 case FLAGSHIP: | |
268 return fed_galaxy_height; | |
269 case GALAXY: | |
270 return fed_galaxy_height; | |
271 case WARBASE: | |
272 return fed_warbase_height; | |
273 case LIGHTCRUISER: | |
274 return fed_lightcruiser_height; | |
275 case CARRIER: | |
276 return fed_carrier_height; | |
277 case UTILITY: | |
278 return fed_utility_height; | |
279 case PATROL: | |
280 return fed_patrol_height; | |
281 } | |
282 case 1: | |
283 switch (shipn) { | |
284 #ifdef HOCKEY | |
285 case PUCK: | |
286 return puck_height; | |
287 #endif /*HOCKEY*/ | |
288 case SCOUT: | |
289 return rom_scout_height; | |
290 case DESTROYER: | |
291 return rom_destroyer_height; | |
292 case CRUISER: | |
293 return rom_cruiser_height; | |
294 case BATTLESHIP: | |
295 return rom_battleship_height; | |
296 case ASSAULT: | |
297 return rom_assault_height; | |
298 case STARBASE: | |
299 return rom_starbase_height; | |
300 case JUMPSHIP: | |
301 return rom_jumpship_height; | |
302 case FLAGSHIP: | |
303 return rom_galaxy_height; | |
304 case GALAXY: | |
305 return rom_galaxy_height; | |
306 case WARBASE: | |
307 return rom_warbase_height; | |
308 case LIGHTCRUISER: | |
309 return rom_lightcruiser_height; | |
310 case CARRIER: | |
311 return rom_carrier_height; | |
312 case UTILITY: | |
313 return rom_utility_height; | |
314 case PATROL: | |
315 return rom_patrol_height; | |
316 } | |
317 case 2: | |
318 switch (shipn) { | |
319 #ifdef HOCKEY | |
320 case PUCK: | |
321 return puck_height; | |
322 #endif /*HOCKEY*/ | |
323 case SCOUT: | |
324 return kli_scout_height; | |
325 case DESTROYER: | |
326 return kli_destroyer_height; | |
327 case CRUISER: | |
328 return kli_cruiser_height; | |
329 case BATTLESHIP: | |
330 return kli_battleship_height; | |
331 case ASSAULT: | |
332 return kli_assault_height; | |
333 case STARBASE: | |
334 return kli_starbase_height; | |
335 case JUMPSHIP: | |
336 return kli_jumpship_height; | |
337 case FLAGSHIP: | |
338 return kli_galaxy_height; | |
339 case GALAXY: | |
340 return kli_galaxy_height; | |
341 case WARBASE: | |
342 return kli_warbase_height; | |
343 case LIGHTCRUISER: | |
344 return kli_lightcruiser_height; | |
345 case CARRIER: | |
346 return kli_carrier_height; | |
347 case UTILITY: | |
348 return kli_utility_height; | |
349 case PATROL: | |
350 return kli_patrol_height; | |
351 } | |
352 case 3: | |
353 switch (shipn) { | |
354 #ifdef HOCKEY | |
355 case PUCK: | |
356 return puck_height; | |
357 #endif /*HOCKEY*/ | |
358 case SCOUT: | |
359 return ori_scout_height; | |
360 case DESTROYER: | |
361 return ori_destroyer_height; | |
362 case CRUISER: | |
363 return ori_cruiser_height; | |
364 case BATTLESHIP: | |
365 return ori_battleship_height; | |
366 case ASSAULT: | |
367 return ori_assault_height; | |
368 case STARBASE: | |
369 return ori_starbase_height; | |
370 case JUMPSHIP: | |
371 return ori_jumpship_height; | |
372 case FLAGSHIP: | |
373 return ori_galaxy_height; | |
374 case GALAXY: | |
375 return ori_galaxy_height; | |
376 case WARBASE: | |
377 return ori_warbase_height; | |
378 case LIGHTCRUISER: | |
379 return ori_lightcruiser_height; | |
380 case CARRIER: | |
381 return ori_carrier_height; | |
382 case UTILITY: | |
383 return ori_utility_height; | |
384 case PATROL: | |
385 return ori_patrol_height; | |
386 } | |
387 case -1: | |
388 switch (shipn) { | |
389 #ifdef HOCKEY | |
390 case PUCK: | |
391 return puck_height; | |
392 #endif /*HOCKEY*/ | |
393 case SCOUT: | |
394 return ind_scout_height; | |
395 case DESTROYER: | |
396 return ind_destroyer_height; | |
397 case CRUISER: | |
398 return ind_cruiser_height; | |
399 case BATTLESHIP: | |
400 return ind_battleship_height; | |
401 case ASSAULT: | |
402 return ind_assault_height; | |
403 case STARBASE: | |
404 return ind_starbase_height; | |
405 case JUMPSHIP: | |
406 return ind_starbase_height; | |
407 case FLAGSHIP: | |
408 return ind_galaxy_height; | |
409 case GALAXY: | |
410 return ind_galaxy_height; | |
411 case WARBASE: | |
412 return ind_starbase_height; | |
413 case LIGHTCRUISER: | |
414 return ind_lightcruiser_height; | |
415 case CARRIER: | |
416 return ind_carrier_height; | |
417 case UTILITY: | |
418 return ind_utility_height; | |
419 case PATROL: | |
420 return ind_patrol_height; | |
421 } | |
422 } | |
423 #endif /* NOSHIPBITMAPS */ | |
424 return 20; | |
425 } | |
426 | |
427 static int | |
428 get_ship_nviews(shipn) | |
429 int shipn; | |
430 { | |
431 if (shipn == STARBASE || | |
432 shipn == WARBASE || | |
433 shipn == JUMPSHIP | |
434 #ifdef HOCKEY | |
435 || shipn == PUCK | |
436 #endif /*HOCKEY*/ | |
437 ) | |
438 return 1; | |
439 else | |
440 return 16; | |
441 } | |
442 | |
443 static unsigned char * | |
444 get_ship_bits(team, shipn, view) | |
445 int team, shipn; | |
446 int view; | |
447 { | |
448 #ifndef NOSHIPBITMAPS | |
449 if (shipn == ATT && paradise) { | |
450 if (view > 0) | |
451 view = 0; | |
452 return att_bits[view]; | |
453 } | |
454 #endif | |
455 if (view > 16) | |
456 view = 0; | |
457 switch (team) { | |
458 case 0: | |
459 #ifndef NOSHIPBITMAPS | |
460 switch (shipn) { | |
461 #ifdef HOCKEY | |
462 case PUCK: | |
463 return puck_bits; | |
464 #endif /*HOCKEY*/ | |
465 case SCOUT: | |
466 return fed_scout_bits[view]; | |
467 case DESTROYER: | |
468 return fed_destroyer_bits[view]; | |
469 case CRUISER: | |
470 return fed_cruiser_bits[view]; | |
471 case BATTLESHIP: | |
472 return fed_battleship_bits[view]; | |
473 case ASSAULT: | |
474 return fed_assault_bits[view]; | |
475 case STARBASE: | |
476 return fed_starbase_bits; | |
477 case JUMPSHIP: | |
478 return fed_jumpship_bits; | |
479 case FLAGSHIP: | |
480 return fed_galaxy_bits[view]; | |
481 case GALAXY: | |
482 return fed_galaxy_bits[view]; | |
483 case WARBASE: | |
484 return fed_warbase_bits; | |
485 case LIGHTCRUISER: | |
486 return fed_lightcruiser_bits[view]; | |
487 case CARRIER: | |
488 return fed_carrier_bits[view]; | |
489 case UTILITY: | |
490 return fed_utility_bits[view]; | |
491 case PATROL: | |
492 return fed_patrol_bits[view]; | |
493 } | |
494 #else | |
495 if (get_ship_nviews(shipn) == 1) | |
496 return fed_starbase_bits; | |
497 else | |
498 return fed_cruiser_bits[view]; | |
499 #endif | |
500 case 1: | |
501 #ifndef NOSHIPBITMAPS | |
502 switch (shipn) { | |
503 #ifdef HOCKEY | |
504 case PUCK: | |
505 return puck_bits; | |
506 #endif /*HOCKEY*/ | |
507 case SCOUT: | |
508 return rom_scout_bits[view]; | |
509 case DESTROYER: | |
510 return rom_destroyer_bits[view]; | |
511 case CRUISER: | |
512 return rom_cruiser_bits[view]; | |
513 case BATTLESHIP: | |
514 return rom_battleship_bits[view]; | |
515 case ASSAULT: | |
516 return rom_assault_bits[view]; | |
517 case STARBASE: | |
518 return rom_starbase_bits; | |
519 case JUMPSHIP: | |
520 return rom_jumpship_bits; | |
521 case FLAGSHIP: | |
522 return rom_galaxy_bits[view]; | |
523 case GALAXY: | |
524 return rom_galaxy_bits[view]; | |
525 case WARBASE: | |
526 return rom_warbase_bits; | |
527 case LIGHTCRUISER: | |
528 return rom_lightcruiser_bits[view]; | |
529 case CARRIER: | |
530 return rom_carrier_bits[view]; | |
531 case UTILITY: | |
532 return rom_utility_bits[view]; | |
533 case PATROL: | |
534 return rom_patrol_bits[view]; | |
535 } | |
536 #else | |
537 if (get_ship_nviews(shipn) == 1) | |
538 return rom_starbase_bits; | |
539 else | |
540 return rom_cruiser_bits[view]; | |
541 #endif | |
542 case 2: | |
543 #ifndef NOSHIPBITMAPS | |
544 switch (shipn) { | |
545 #ifdef HOCKEY | |
546 case PUCK: | |
547 return puck_bits; | |
548 #endif /*HOCKEY*/ | |
549 case SCOUT: | |
550 return kli_scout_bits[view]; | |
551 case DESTROYER: | |
552 return kli_destroyer_bits[view]; | |
553 case CRUISER: | |
554 return kli_cruiser_bits[view]; | |
555 case BATTLESHIP: | |
556 return kli_battleship_bits[view]; | |
557 case ASSAULT: | |
558 return kli_assault_bits[view]; | |
559 case STARBASE: | |
560 return kli_starbase_bits; | |
561 case JUMPSHIP: | |
562 return kli_jumpship_bits; | |
563 case FLAGSHIP: | |
564 return kli_galaxy_bits[view]; | |
565 case GALAXY: | |
566 return kli_galaxy_bits[view]; | |
567 case WARBASE: | |
568 return kli_warbase_bits; | |
569 case LIGHTCRUISER: | |
570 return kli_lightcruiser_bits[view]; | |
571 case CARRIER: | |
572 return kli_carrier_bits[view]; | |
573 case UTILITY: | |
574 return kli_utility_bits[view]; | |
575 case PATROL: | |
576 return kli_patrol_bits[view]; | |
577 } | |
578 #else | |
579 if (get_ship_nviews(shipn) == 1) | |
580 return kli_starbase_bits; | |
581 else | |
582 return kli_cruiser_bits[view]; | |
583 #endif | |
584 case 3: | |
585 #ifndef NOSHIPBITMAPS | |
586 switch (shipn) { | |
587 #ifdef HOCKEY | |
588 case PUCK: | |
589 return puck_bits; | |
590 #endif /*HOCKEY*/ | |
591 case SCOUT: | |
592 return ori_scout_bits[view]; | |
593 case DESTROYER: | |
594 return ori_destroyer_bits[view]; | |
595 case CRUISER: | |
596 return ori_cruiser_bits[view]; | |
597 case BATTLESHIP: | |
598 return ori_battleship_bits[view]; | |
599 case ASSAULT: | |
600 return ori_assault_bits[view]; | |
601 case STARBASE: | |
602 return ori_starbase_bits; | |
603 case JUMPSHIP: | |
604 return ori_jumpship_bits; | |
605 case FLAGSHIP: | |
606 return ori_galaxy_bits[view]; | |
607 case GALAXY: | |
608 return ori_galaxy_bits[view]; | |
609 case WARBASE: | |
610 return ori_warbase_bits; | |
611 case LIGHTCRUISER: | |
612 return ori_lightcruiser_bits[view]; | |
613 case CARRIER: | |
614 return ori_carrier_bits[view]; | |
615 case UTILITY: | |
616 return ori_utility_bits[view]; | |
617 case PATROL: | |
618 return ori_patrol_bits[view]; | |
619 } | |
620 #else | |
621 if (get_ship_nviews(shipn) == 1) | |
622 return ori_starbase_bits; | |
623 else | |
624 return ori_cruiser_bits[view]; | |
625 #endif | |
626 case -1: | |
627 #ifndef NOSHIPBITMAPS | |
628 switch (shipn) { | |
629 #ifdef HOCKEY | |
630 case PUCK: | |
631 return puck_bits; | |
632 #endif /*HOCKEY*/ | |
633 case SCOUT: | |
634 return ind_scout_bits[view]; | |
635 case DESTROYER: | |
636 return ind_destroyer_bits[view]; | |
637 case CRUISER: | |
638 return ind_cruiser_bits[view]; | |
639 case BATTLESHIP: | |
640 return ind_battleship_bits[view]; | |
641 case ASSAULT: | |
642 return ind_assault_bits[view]; | |
643 case STARBASE: | |
644 return ind_starbase_bits; | |
645 case JUMPSHIP: | |
646 return ind_starbase_bits; | |
647 case FLAGSHIP: | |
648 return ind_galaxy_bits[view]; | |
649 case GALAXY: | |
650 return ind_galaxy_bits[view]; | |
651 case WARBASE: | |
652 return ind_starbase_bits; | |
653 case LIGHTCRUISER: | |
654 return ind_lightcruiser_bits[view]; | |
655 case CARRIER: | |
656 return ind_carrier_bits[view]; | |
657 case UTILITY: | |
658 return ind_utility_bits[view]; | |
659 case PATROL: | |
660 return ind_patrol_bits[view]; | |
661 } | |
662 #else | |
663 if (get_ship_nviews(shipn) == 1) | |
664 return fed_starbase_bits; | |
665 else | |
666 return fed_cruiser_bits[view]; | |
667 #endif | |
668 } | |
669 return fed_cruiser_bits[view]; | |
670 } | |
671 | |
672 | |
673 /* points at the beginning of the fed ship shapes. Independent are | |
674 at negative indices */ | |
675 static struct ship_shape *all_ship_shapes = 0; | |
676 | |
677 struct ship_shape * | |
678 shape_of_ship(team, shipclass) | |
679 int team, shipclass; | |
680 { | |
681 if (team < -1 || team >= number_of_teams || | |
682 shipclass < 0 || shipclass >= nshiptypes) | |
683 return &all_ship_shapes[-nshiptypes]; | |
684 return &all_ship_shapes[team * nshiptypes + shipclass]; | |
685 } | |
686 | |
687 void | |
688 clear_one_ship_shape(shp) | |
689 struct ship_shape *shp; | |
690 { | |
691 int j; | |
692 for (j = 0; j < shp->nviews; j++) { | |
693 W_FreeBitmap(shp->bmap[j]); | |
694 } | |
695 shp->nviews = 0; | |
696 free(shp->bmap); | |
697 shp->bmap = 0; | |
698 W_FreeBitmap(shp->shield); | |
699 shp->shield = 0; | |
700 } | |
701 | |
702 void | |
703 free_shipshapes() | |
704 { | |
705 /* don't forget that IND offset */ | |
706 int race, i; | |
707 if (!all_ship_shapes) /* if nothing there to begin with */ | |
708 return; | |
709 for (race = -1; race < number_of_teams; race++) { | |
710 for (i = 0; i < nshiptypes; i++) { | |
711 clear_one_ship_shape(shape_of_ship(race, i)); | |
712 } | |
713 } | |
714 free(all_ship_shapes - nshiptypes); | |
715 all_ship_shapes = 0; | |
716 } | |
717 | |
718 void | |
719 slurp_ship_bitmaps() | |
720 { | |
721 int i, race, k; | |
722 int width, height, size = 0; | |
723 int nviews; /* NYI */ | |
724 unsigned char *buf = 0, *buf2; | |
725 char *freeme; | |
726 char *mainbitmapdir, *bitmapdir; | |
727 static char path[MAXPATHLEN]; | |
728 | |
729 if (all_ship_shapes == 0) { | |
730 all_ship_shapes = nshiptypes + (struct ship_shape *) | |
731 malloc(sizeof(*all_ship_shapes) * (number_of_teams + 1) * nshiptypes); | |
732 } | |
733 mainbitmapdir = stringDefault("shipBitmapPath", | |
734 #ifndef AMIGA /* worked this way, sort of... was annoying. */ | |
735 "/usr/games/lib/netrek" | |
736 #else | |
737 "netrek:graphics" | |
738 #endif /* AMIGA */ | |
739 ); | |
740 mainbitmapdir = expandFilename(mainbitmapdir); | |
741 | |
742 for (race = -1 /* IND */ ; race < number_of_teams; race++) { | |
743 freeme = NULL; | |
744 /* you can now have a different bitmapDir for each race [BDyess] */ | |
745 sprintf(path, "shipBitmapPath.%d", race); | |
746 if ((bitmapdir = getdefault(path)) == NULL) | |
747 bitmapdir = mainbitmapdir; | |
748 else | |
749 bitmapdir = freeme = expandFilename((char *) strdup(bitmapdir)); | |
750 for (k = 0; k < nshiptypes; k++) { | |
751 struct ship_shape *curr_shape = shape_of_ship(race, k); | |
752 FILE *fp; | |
753 sprintf(path, "%s/R%d.C%d", bitmapdir, race, k); | |
754 | |
755 fp = fopen(path, "r"); | |
756 if (fp == 0) { | |
757 if (errno != ENOENT) { | |
758 fprintf(stderr, "Error accessing ship bitmap file %s:", path); | |
759 perror(""); | |
760 } | |
761 nviews = get_ship_nviews(k, 0); | |
762 width = get_ship_width(race, k, 0); | |
763 height = get_ship_height(race, k, 0); | |
764 } else { | |
765 fread(&nviews, sizeof(nviews), 1, fp); | |
766 nviews = ntohl(nviews); | |
767 fread(&width, sizeof(width), 1, fp); | |
768 width = ntohl(width); | |
769 fread(&height, sizeof(height), 1, fp); | |
770 height = ntohl(height); | |
771 if (nviews > get_ship_nviews(k, 0)) | |
772 nviews = get_ship_nviews(k, 0); | |
773 size = (width + 7) / 8 * height; | |
774 buf = (unsigned char *) malloc(size); | |
775 } | |
776 | |
777 curr_shape->nviews = nviews /* nviews */ ; | |
778 curr_shape->width = width; | |
779 curr_shape->height = height; | |
780 curr_shape->shield = W_MakeShieldBitmap(width, height, w); | |
781 | |
782 curr_shape->bmap = (W_Icon *) malloc(sizeof(*curr_shape->bmap) * | |
783 nviews); | |
784 | |
785 for (i = 0; i < nviews; i++) { | |
786 if (fp) { | |
787 fread(buf, size, 1, fp); | |
788 curr_shape->bmap[i] = | |
789 W_StoreBitmap(width, height, buf, w); | |
790 } else { | |
791 buf2 = get_ship_bits(race, k, i); | |
792 curr_shape->bmap[i] = | |
793 W_StoreBitmap(width, height, buf2, w); | |
794 } | |
795 | |
796 #if 0 | |
797 /* these widths and heights are not necessarily correct */ | |
798 if (fp) | |
799 buf2 = get_ship_bits(race, k, i, blk_altbits); | |
800 else | |
801 buf2 = get_ship_bits(race, k, i, !blk_altbits); | |
802 | |
803 curr_shape->bmap[i + (blk_altbits ? 0 : nviews)] = | |
804 W_StoreBitmap(width, height, buf2, w); | |
805 #endif | |
806 } | |
807 | |
808 if (fp) { | |
809 free(buf); | |
810 fclose(fp); | |
811 } | |
812 } | |
813 if (freeme) | |
814 free(freeme); | |
815 } | |
816 } | |
817 | |
818 void | |
819 replace_shipshape(race, shiptype, nviews, width, height) | |
820 int race, shiptype, nviews, width, height; | |
821 { | |
822 struct ship_shape *shp = shape_of_ship(race, shiptype); | |
823 int i; | |
824 | |
825 clear_one_ship_shape(shp); | |
826 | |
827 shp->nviews = nviews; | |
828 shp->bmap = (W_Icon *) malloc(sizeof(*shp->bmap) * nviews); | |
829 shp->width = width; | |
830 shp->height = height; | |
831 shp->shield = W_MakeShieldBitmap(width, height, w); | |
832 for (i = 0; i < nviews; i++) { | |
833 /* we really should check the files again. */ | |
834 shp->bmap[i] = W_StoreBitmap(get_ship_width(race, shiptype), | |
835 get_ship_height(race, shiptype), | |
836 get_ship_bits(race, shiptype, i, 0), | |
837 w); | |
838 #if 0 | |
839 shp->bmap[i + nviews] = W_StoreBitmap(get_ship_width(race, shiptype), | |
840 get_ship_height(race, shiptype), | |
841 get_ship_bits(race, shiptype, i, 0), | |
842 w); | |
843 #endif | |
844 } | |
845 } | |
846 | |
847 | |
848 void | |
849 replace_ship_bitmap(race, shiptype, view, bits) | |
850 int race, shiptype, view; | |
851 unsigned char *bits; | |
852 { | |
853 struct ship_shape *shp = shape_of_ship(race, shiptype); | |
854 | |
855 if (view >= shp->nviews) { | |
856 fprintf(stderr, "race %d, ship class %d: view %d out of range (0..%d)\n", | |
857 race, shiptype, view, shp->nviews - 1); | |
858 return; | |
859 } | |
860 W_FreeBitmap(shp->bmap[view]); | |
861 /* store the bitmaps into the auxiliary view */ | |
862 shp->bmap[view] = W_StoreBitmap(shp->width, shp->height, bits, w); | |
863 } |