1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1997, 2005 - 3D Realms Entertainment
4 
5 This file is part of Shadow Warrior version 1.2
6 
7 Shadow Warrior is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 
22 Original Source: 1997 - Frank Maddin and Jim Norwood
23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24 */
25 //-------------------------------------------------------------------------
26 
27 /****************************************
28 Removed sounds that were causing "Could
29 not load" error messages.
30 ****************************************/
31 
32 #include "build.h"
33 
34 #include "names2.h"
35 #include "game.h"
36 #include "tags.h"
37 #include "common_game.h"
38 #include "break.h"
39 #include "quake.h"
40 #include "pal.h"
41 #include "cache.h"
42 #include "sounds.h"
43 #include "network.h"
44 
45 // Run the game with the -CACHEPRINT option and redirect to a file.
46 // It will save out the tile and sound number every time one caches.
47 //
48 // sw -map $bullet -cacheprint > foofile
49 extern SWBOOL PreCaching;
50 
51 // player weaponry, item usage, etc. Precache every time.
52 short Player_SCTable[] =
53 {
54     1,2,3,4,5,6,7,8,9,10, // weapons
55     11,12,14,16,18,20,
56     22,23,24,25,26,27,28,30,
57     31,32,33,34,35,40,145,291,445,362,269,
58     158,476, // underwater
59     47,359, // cloaking
60     48,50, // dead head
61     196,52,53,54,55, // splash & getting items
62     56,57,58,73,74,410, // bodies hitting ground
63     484,442, // teleport & respawn
64     417,418, // healing
65     238,239,240,241,242,243,244, // bring weapons up
66     181,182,183,184,187,216, // explosions
67     272,273,274,275,486, // nuke associated sounds
68     276,277,278,279,477, // chem bomb
69     280,281,282,283,284,288,289,290,450, // various player sounds
70     295, // armor hit
71     312, // sword clank
72     324,325,209, // unlocking sound
73     395,396,411, // gibs
74     175, // drip
75     435,436,311,221,220,227, // breakage
76     246,247,248,249,250,251,252,253,254,255,256, // common player talk
77     257,258,259,260,261,262,263,264,266,267,438,439,440,441,
78     326, // ancient chinese secret
79     330,331,332,333,334,335,336,337,338,339,340, // player kill talk
80     341,342,343,344,345,346,347,348,
81     376,377,378,379,380,381,382,383,384,385,386,387, // more asst. talking
82     370,443 // repair talk
83 };
84 
85 // Actor specific sound tables. Cache only if the actor appears on the map.
86 // Exceptions would include ghosts, which are spawned by coolies, and
87 // rippers, which are spawned by the serpent boss.
88 short Coolie_SCTable[] =
89 {
90     75,76,77,78,79
91 };
92 
93 short Ghost_SCTable[] =
94 {
95     80,81,82,83,84,85,86,87,213
96 };
97 
98 short Ninja_SCTable[] =
99 {
100     88,89,90,91,92,93,94,412,
101     319, // firing sound
102     430 // death by sword
103 };
104 
105 short Ripper_SCTable[] =
106 {
107     95,96,97,98,99,100,431
108 };
109 
110 short Ripper2_SCTable[] =
111 {
112     313,314,315,316,317,318,431
113 };
114 
115 short Head_SCTable[] =
116 {
117     115,116,117,118 // accursed heads
118 };
119 
120 short Hornet_SCTable[] =
121 {
122     119,120,121,122
123 };
124 
125 short Guardian_SCTable[] =
126 {
127     101,102,103,104,105,106,107
128 };
129 
130 short Serpent_SCTable[] =
131 {
132     123,124,125,126,127,128,129,130,131 // serpent boss
133 };
134 
135 short Sumo_SCTable[] =
136 {
137     320,321,322,323 // sumo boss
138 };
139 
140 short Bunny_SCTable[] =
141 {
142     424,425,426,427,428
143 };
144 
145 short Toilet_SCTable[] =
146 {
147     388,389,390,391,392,393,488,489,490 // anime girl on toilet
148 }; // I suspect some of these are no longer in use
149 
150 short Trash_SCTable[] =
151 {
152     416 // I heard the trash can was an actor, so here is is
153 };
154 
155 short Pachinko_SCTable[] =
156 {
157     419,420,421,422,423
158 };
159 
160 void PreCacheSoundList(short table[], int num);
161 void PreCacheTable(short table[], int num);
162 void PreCacheGhost(void);
163 
164 void
SetupPreCache(void)165 SetupPreCache(void)
166 {
167     if (PreCaching)
168     {
169         precache();
170 
171         PreCacheSoundList(Player_SCTable, SIZ(Player_SCTable));
172 
173         // actors cache ranges are called from SpriteSetup
174         // only caches the actor if its on the level
175 
176         // weapons
177         PreCacheRange(2000, 2227);
178         PreCacheRange(4090, 4093);
179         // Explosions
180         PreCacheRange(3072, 3225);
181         // ninja player character
182         PreCacheRange(1024, 1175);
183         // console
184         PreCacheRange(2380, 2409);
185         PreCacheRange(3600, 3645);
186         PreCacheRange(2434, 2435);
187         // common
188         PreCacheRange(204, 208);
189         // message font
190         PreCacheRange(4608, 4701);
191         // gibs
192         PreCacheRange(1150,1568);
193         PreCacheRange(1685,1690);
194         PreCacheRange(900,944);
195         PreCacheRange(1670,1681);
196         // blood
197         PreCacheRange(1710,1715);
198         PreCacheRange(2410,2425);
199         PreCacheRange(389,389); // blood puddle by itself in art file
200         PreCacheRange(2500,2503);
201         // shrap
202         PreCacheRange(3840,3911);
203         PreCacheRange(3924,3947);
204         PreCacheRange(1397,1398);
205         // water *** animated tiles, can be deleted now ***
206         // PreCacheRange(780,794);
207         // switches
208         PreCacheRange(561,584);
209         PreCacheRange(551,552);
210         PreCacheRange(1846,1847);
211         PreCacheRange(1850,1859);
212         // bullet smoke
213         PreCacheRange(1748,1753);
214         // small blue font
215         PreCacheRange(2930,3023);
216         // gas can
217         PreCacheRange(3038,3042);
218         // lava *** animated tiles, can be deleted now ***
219         // PreCacheRange(175,182);
220         // gas clouds & teleport effect
221         PreCacheRange(3240,3277);
222         // nuke mushroom cloud
223         PreCacheRange(3280,3300);
224         // blood drops
225         PreCacheRange(1718,1721);
226         // smoke
227         PreCacheRange(3948,3968);
228         // footprints
229         PreCacheRange(2490,2492);
230         // player fists
231         PreCacheRange(4070,4077);
232         PreCacheRange(4050,4051);
233         PreCacheRange(4090,4093);
234         // fish actor
235         PreCacheRange(3760,3771);
236         PreCacheRange(3780,3795);
237         // coins
238         PreCacheRange(2531,2533);
239         // respawn markers & console keys
240         PreCacheRange(2440,2467);
241         // light/torch sprites
242         PreCacheRange(537,548);
243         PreCacheRange(521,528);
244         PreCacheRange(512,515);
245         PreCacheRange(396,399);
246         PreCacheRange(443,446);
247         // bubbles
248         PreCacheRange(716,720);
249         // bullet splashes
250         PreCacheRange(772,776);
251     }
252 }
253 
PreCacheRipper(void)254 void PreCacheRipper(void)
255 {
256     PreCacheSoundList(Ripper_SCTable, SIZ(Ripper_SCTable));
257     PreCacheRange(1580, 1644);
258 }
259 
PreCacheRipper2(void)260 void PreCacheRipper2(void)
261 {
262     PreCacheSoundList(Ripper2_SCTable, SIZ(Ripper2_SCTable));
263     PreCacheRange(4320, 4427);
264 }
265 
PreCacheCoolie(void)266 void PreCacheCoolie(void)
267 {
268     PreCacheGhost();
269     PreCacheSoundList(Coolie_SCTable, SIZ(Coolie_SCTable));
270     PreCacheRange(1400, 1440);
271     PreCacheRange(4260, 4276); // coolie explode
272 }
273 
PreCacheGhost(void)274 void PreCacheGhost(void)
275 {
276     PreCacheSoundList(Ghost_SCTable, SIZ(Ghost_SCTable));
277     PreCacheRange(4277, 4312);
278 }
279 
PreCacheSerpent(void)280 void PreCacheSerpent(void)
281 {
282     PreCacheSoundList(Serpent_SCTable, SIZ(Serpent_SCTable));
283     PreCacheRange(960, 1016);
284     PreCacheRange(1300, 1314);
285 }
286 
PreCacheGuardian(void)287 void PreCacheGuardian(void)
288 {
289     PreCacheSoundList(Guardian_SCTable, SIZ(Guardian_SCTable));
290     PreCacheRange(1469,1497);
291 }
292 
PreCacheNinja(void)293 void PreCacheNinja(void)
294 {
295     PreCacheSoundList(Ninja_SCTable, SIZ(Ninja_SCTable));
296     PreCacheRange(4096, 4239);
297 }
298 
PreCacheNinjaGirl(void)299 void PreCacheNinjaGirl(void)
300 {
301     //PreCacheSoundList(NinjaGirl_SCTable, SIZ(NinjaGirl_SCTable));
302     PreCacheRange(5162, 5260);
303 }
304 
PreCacheSumo(void)305 void PreCacheSumo(void)
306 {
307     PreCacheSoundList(Sumo_SCTable, SIZ(Sumo_SCTable));
308     PreCacheRange(4490, 4544);
309 }
310 
PreCacheZilla(void)311 void PreCacheZilla(void)
312 {
313     PreCacheSoundList(Sumo_SCTable, SIZ(Sumo_SCTable));
314     PreCacheRange(4490, 4544);
315 }
316 
PreCacheEel(void)317 void PreCacheEel(void)
318 {
319     PreCacheRange(4430, 4479);
320 }
321 
PreCacheToiletGirl(void)322 void PreCacheToiletGirl(void)
323 {
324     PreCacheSoundList(Toilet_SCTable, SIZ(Toilet_SCTable));
325     PreCacheRange(5023, 5027);
326 }
327 
PreCacheWashGirl(void)328 void PreCacheWashGirl(void)
329 {
330     PreCacheSoundList(Toilet_SCTable, SIZ(Toilet_SCTable));
331     PreCacheRange(5032, 5035);
332 }
333 
PreCacheCarGirl(void)334 void PreCacheCarGirl(void)
335 {
336     PreCacheSoundList(Toilet_SCTable, SIZ(Toilet_SCTable));
337     PreCacheRange(4594,4597);
338 }
339 
PreCacheMechanicGirl(void)340 void PreCacheMechanicGirl(void)
341 {
342     PreCacheSoundList(Toilet_SCTable, SIZ(Toilet_SCTable));
343     PreCacheRange(4590,4593);
344 }
345 
PreCacheSailorGirl(void)346 void PreCacheSailorGirl(void)
347 {
348     PreCacheSoundList(Toilet_SCTable, SIZ(Toilet_SCTable));
349     PreCacheRange(4600,4602);
350 }
351 
PreCachePruneGirl(void)352 void PreCachePruneGirl(void)
353 {
354     PreCacheSoundList(Toilet_SCTable, SIZ(Toilet_SCTable));
355     PreCacheRange(4604,4604);
356 }
357 
PreCacheTrash(void)358 void PreCacheTrash(void)
359 {
360     PreCacheSoundList(Trash_SCTable, SIZ(Trash_SCTable));
361     PreCacheRange(2540, 2546);
362 }
363 
PreCacheBunny(void)364 void PreCacheBunny(void)
365 {
366     PreCacheSoundList(Bunny_SCTable, SIZ(Bunny_SCTable));
367     PreCacheRange(4550, 4584);
368 }
369 
PreCacheSkel(void)370 void PreCacheSkel(void)
371 {
372     PreCacheRange(1320, 1396);
373 }
374 
PreCacheHornet(void)375 void PreCacheHornet(void)
376 {
377     PreCacheSoundList(Hornet_SCTable, SIZ(Hornet_SCTable));
378     PreCacheRange(800, 811);
379 }
380 
PreCacheSkull(void)381 void PreCacheSkull(void)
382 {
383     PreCacheSoundList(Head_SCTable, SIZ(Head_SCTable));
384     PreCacheRange(820, 854);
385 }
386 
PreCacheBetty(void)387 void PreCacheBetty(void)
388 {
389     PreCacheRange(817, 819);
390 }
391 
PreCachePachinko(void)392 void PreCachePachinko(void)
393 {
394     PreCacheRange(618,623);
395     PreCacheRange(618,623);
396     PreCacheRange(4768,4790);
397     PreCacheRange(4792,4814);
398     PreCacheRange(4816,4838);
399     PreCacheRange(4840,4863);
400     PreCacheSoundList(Pachinko_SCTable, SIZ(Pachinko_SCTable));
401 }
402 
PreCacheSoundList(short table[],int num)403 void PreCacheSoundList(short table[], int num)
404 {
405     short j;
406 
407     for (j = 0; j < num; j++)
408     {
409         CacheSound(table[j], CACHE_SOUND_PRECACHE);
410         AnimateCacheCursor();
411     }
412 }
413 
414 void
PreCacheTable(short table[],int num)415 PreCacheTable(short table[], int num)
416 {
417     short j;
418 
419     for (j = 0; j < num; j++)
420     {
421         SET(gotpic[table[j]>>3], 1<<(table[j]&7));
422     }
423 }
424 
425 void
PreCacheRange(short start_pic,short end_pic)426 PreCacheRange(short start_pic, short end_pic)
427 {
428     short j;
429 
430     for (j = start_pic; j <= end_pic; j++)
431     {
432         SET(gotpic[j>>3], 1<<(j&7));
433     }
434 }
435 
PreCacheAmbient(void)436 void PreCacheAmbient(void)
437 {
438     int i,nexti;
439     int num;
440     SPRITEp sp;
441     extern AMB_INFO ambarray[];
442 
443     TRAVERSE_SPRITE_STAT(headspritestat[STAT_AMBIENT], i, nexti)
444     {
445         sp = &sprite[i];
446 
447         num = sp->lotag;
448         num = ambarray[num].diginame;
449 
450         CacheSound(num, CACHE_SOUND_PRECACHE);
451     }
452 }
453 
PreCacheOverride(void)454 void PreCacheOverride(void)
455 {
456     int i,nexti;
457 
458     TRAVERSE_SPRITE_STAT(headspritestat[STAT_CEILING_FLOOR_PIC_OVERRIDE], i, nexti)
459     {
460         ASSERT(SPRITE_TAG2(i) >= 0 && SPRITE_TAG2(i) <= MAXTILES);
461         SET_GOTPIC(SPRITE_TAG2(i));
462     }
463 }
464 
465 
PreCacheSoundSpot(void)466 void PreCacheSoundSpot(void)
467 {
468     int i,nexti;
469     int num;
470     SPRITEp sp;
471 
472     TRAVERSE_SPRITE_STAT(headspritestat[STAT_SOUND_SPOT], i, nexti)
473     {
474         sp = &sprite[i];
475 
476         num = SP_TAG13(sp); // tag4 is copied to tag13
477         if (num > 0 && num < DIGI_MAX)
478             CacheSound(num, CACHE_SOUND_PRECACHE);
479 
480         num = SP_TAG5(sp);
481         if (num > 0 && num < DIGI_MAX)
482             CacheSound(num, CACHE_SOUND_PRECACHE);
483 
484         num = SP_TAG6(sp);
485         if (num > 0 && num < DIGI_MAX)
486             CacheSound(num, CACHE_SOUND_PRECACHE);
487 
488         CacheSound(num, CACHE_SOUND_PRECACHE);
489     }
490 }
491 
492 void
PreCacheActor(void)493 PreCacheActor(void)
494 {
495     int i;
496     short pic;
497 
498     for (i=0; i < MAXSPRITES; i++)
499     {
500         if (sprite[i].statnum >= MAXSTATUS)
501             continue;
502 
503         if (User[i])
504             pic = User[i]->ID;
505         else
506             pic = sprite[i].picnum;
507 
508         switch (pic)
509         {
510         case COOLIE_RUN_R0:
511             PreCacheCoolie();
512             break;
513 
514         case NINJA_RUN_R0:
515         case NINJA_CRAWL_R0:
516             PreCacheNinja();
517             break;
518 
519         case GORO_RUN_R0:
520             PreCacheGuardian();
521             break;
522 
523         case 1441:
524         case COOLG_RUN_R0:
525             PreCacheGhost();
526             break;
527 
528         case EEL_RUN_R0:
529             PreCacheEel();
530             break;
531 
532         case SUMO_RUN_R0:
533             PreCacheZilla();
534             break;
535 
536         case ZILLA_RUN_R0:
537             PreCacheSumo();
538             break;
539 
540         case TOILETGIRL_R0:
541             PreCacheToiletGirl();
542             break;
543 
544         case WASHGIRL_R0:
545             PreCacheWashGirl();
546             break;
547 
548         case CARGIRL_R0:
549             PreCacheCarGirl();
550             break;
551 
552         case MECHANICGIRL_R0:
553             PreCacheMechanicGirl();
554             break;
555 
556         case SAILORGIRL_R0:
557             PreCacheSailorGirl();
558             break;
559 
560         case PRUNEGIRL_R0:
561             PreCachePruneGirl();
562             break;
563 
564         case TRASHCAN:
565             PreCacheTrash();
566             break;
567 
568         case BUNNY_RUN_R0:
569             PreCacheBunny();
570             break;
571 
572         case RIPPER_RUN_R0:
573             PreCacheRipper();
574             break;
575 
576         case RIPPER2_RUN_R0:
577             PreCacheRipper2();
578             break;
579 
580         case SERP_RUN_R0:
581             PreCacheSerpent();
582             break;
583 
584         case LAVA_RUN_R0:
585             break;
586 
587         case SKEL_RUN_R0:
588             PreCacheSkel();
589             break;
590 
591         case HORNET_RUN_R0:
592             PreCacheHornet();
593             break;
594 
595         case SKULL_R0:
596             PreCacheSkull();
597             break;
598 
599         case BETTY_R0:
600             PreCacheBetty();
601             break;
602 
603         case GIRLNINJA_RUN_R0:
604             PreCacheNinjaGirl();
605             break;
606 
607         case 623:   // Pachinko win light
608         case PACHINKO1:
609         case PACHINKO2:
610         case PACHINKO3:
611         case PACHINKO4:
612             PreCachePachinko();
613             break;
614         }
615     }
616 }
617 
618 
DoTheCache(void)619 void DoTheCache(void)
620 {
621     extern char CacheLastLevel[32],LevelName[20];
622     int i, cnt=0;
623 
624     PreCacheAmbient();
625     PreCacheSoundSpot();
626     PreCacheActor();
627     PreCacheOverride();
628 
629     for (i = 0; i < MAXTILES; i++)
630     {
631         if ((TEST(gotpic[i>>3], 1<<(i&7))) && (!waloff[i]))
632         {
633             tileLoad(i);
634             cnt++;
635             if (!(cnt&7))
636             {
637                 AnimateCacheCursor();
638                 handleevents();
639                 getpackets();
640             }
641         }
642     }
643 
644     memset(gotpic,0,sizeof(gotpic));
645     strcpy(CacheLastLevel, LevelName);
646 }
647 
648 void
precache(void)649 precache(void)
650 {
651     int i;
652     short j;
653     SECTORp sectp;
654     WALLp wp;
655     SPRITEp sp;
656 
657     memset(gotpic,0,sizeof(gotpic));
658 
659     for (sectp = sector; sectp < &sector[numsectors]; sectp++)
660     {
661         j = sectp->ceilingpicnum;
662 
663         SET(gotpic[j>>3], 1<<(j&7));
664 
665         if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
666         {
667             for (i = 1; i <= picanm[j].num; i++)
668             {
669                 SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
670             }
671         }
672 
673         j = sectp->floorpicnum;
674 
675         SET(gotpic[j>>3], 1<<(j&7));
676 
677         if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
678         {
679             for (i = 1; i <= picanm[j].num; i++)
680             {
681                 SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
682             }
683         }
684 
685     }
686 
687     for (wp = wall; wp < &wall[numwalls]; wp++)
688     {
689         j = wp->picnum;
690 
691         SET(gotpic[j>>3], 1<<(j&7));
692 
693         if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
694         {
695             for (i = 1; i <= picanm[j].num; i++)
696             {
697                 SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
698             }
699         }
700 
701         if (wp->overpicnum > 0 && wp->overpicnum < MAXTILES)
702         {
703             j = wp->overpicnum;
704             SET(gotpic[j>>3], 1<<(j&7));
705 
706             if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
707             {
708                 for (i = 1; i <= picanm[j].num; i++)
709                 {
710                     SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
711                 }
712             }
713 
714         }
715     }
716 
717     for (sp = sprite; sp < &sprite[MAXSPRITES]; sp++)
718     {
719         if (sp->statnum < MAXSTATUS)
720         {
721             j = sp->picnum;
722 
723             SET(gotpic[j>>3], 1<<(j&7));
724         }
725     }
726 }
727 
728 
729