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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "build.h"
27 #include "cache1d.h"
28 
29 #include "keys.h"
30 #include "mytypes.h"
31 #include "develop.h"
32 #include "fx_man.h"
33 #include "music.h"
34 #include "scriplib.h"
35 #include "file_lib.h"
36 #include "gamedefs.h"
37 #include "keyboard.h"
38 #include "util_lib.h"
39 
40 #include "control.h"
41 #include "config.h"
42 #include "sounds.h"
43 #include "function.h"
44 
45 #include "game.h"
46 #include "colormap.h"
47 #include "net.h"
48 
49 #include "animlib.h"
50 #include "anim.h"
51 
52 #define MAX_ANMS 10
53 anim_t *anm_ptr[MAX_ANMS];
54 
55 int ANIMnumframes;
56 unsigned char ANIMpal[3*256];
57 unsigned char ANIMnum = 0;
58 short SoundState;
59 
60 char *ANIMname[] =
61 {
62 "sw.anm",
63 "swend.anm",
64 "sumocinm.anm",
65 "zfcin.anm",
66 };
67 
68 #define ANIM_TILE(num) (MAXTILES-11 + (num))
69 
AnimShareIntro(int frame,int numframes)70 VOID AnimShareIntro(int frame, int numframes)
71     {
72     int zero=0;
73 
74     if (frame == numframes-1)
75         ototalclock += 120;
76     else
77     if (frame == 1)
78         {
79         PlaySound(DIGI_NOMESSWITHWANG,&zero,&zero,&zero,v3df_none);
80         ototalclock += 120*3;
81         }
82     else
83         ototalclock += 8;
84 
85     if (frame == 5)
86         {
87         PlaySound(DIGI_INTRO_SLASH,&zero,&zero,&zero,v3df_none);
88         }
89     else
90     if (frame == 15)
91         {
92         PlaySound(DIGI_INTRO_WHIRL,&zero,&zero,&zero,v3df_none);
93         }
94     }
95 
AnimSerp(int frame,int numframes)96 VOID AnimSerp(int frame, int numframes)
97     {
98     int zero=0;
99     ototalclock += 16;
100 
101     if (frame == numframes-1)
102         ototalclock += 1*120;
103 
104     if (frame == 1)
105         {
106         PlaySound(DIGI_SERPTAUNTWANG,&zero,&zero,&zero,v3df_none);
107         }
108     else
109     if (frame == 16)
110         {
111         PlaySound(DIGI_SHAREND_TELEPORT,&zero,&zero,&zero,v3df_none);
112         }
113     else
114     if (frame == 35)
115         {
116         SoundState++;
117         PlaySound(DIGI_WANGTAUNTSERP1,&zero,&zero,&zero,v3df_none);
118         }
119     else
120     if (frame == 51)
121         {
122         SoundState++;
123         PlaySound(DIGI_SHAREND_UGLY1,&zero,&zero,&zero,v3df_none);
124         }
125     else
126     if (frame == 64)
127         {
128         SoundState++;
129         PlaySound(DIGI_SHAREND_UGLY2,&zero,&zero,&zero,v3df_none);
130         }
131     }
132 
AnimSumo(int frame,int numframes)133 VOID AnimSumo(int frame, int numframes)
134     {
135     int zero=0;
136     ototalclock += 10;
137 
138     if (frame == numframes-1)
139         ototalclock += 1*120;
140 
141     if (frame == 1)
142         ototalclock += 30;
143 
144     if (frame == 2)
145         {
146         // hungry
147         PlaySound(DIGI_JG41012,&zero,&zero,&zero,v3df_none);
148         }
149     else
150     if (frame == 30)
151         {
152         PlaySound(DIGI_HOTHEADSWITCH,&zero,&zero,&zero,v3df_none);
153         }
154     else
155     if (frame == 42)
156         {
157         PlaySound(DIGI_HOTHEADSWITCH,&zero,&zero,&zero,v3df_none);
158         }
159     else
160     if (frame == 59)
161         {
162         PlaySound(DIGI_JG41028,&zero,&zero,&zero,v3df_none);
163         }
164     }
165 
AnimZilla(int frame,int numframes)166 VOID AnimZilla(int frame, int numframes)
167     {
168     int zero=0;
169     ototalclock += 16;
170 
171     if (frame == numframes-1)
172         ototalclock += 1*120;
173 
174     if (frame == 1)
175         {
176         PlaySound(DIGI_ZC1,&zero,&zero,&zero,v3df_none);
177         }
178     else
179     if (frame == 5)
180         {
181         PlaySound(DIGI_JG94024,&zero,&zero,&zero,v3df_none);
182         }
183     else
184     if (frame == 14)
185         {
186         PlaySound(DIGI_ZC2,&zero,&zero,&zero,v3df_none);
187         }
188     else
189     if (frame == 30)
190         {
191         PlaySound(DIGI_ZC3,&zero,&zero,&zero,v3df_none);
192         }
193     else
194     if (frame == 32)
195         {
196         PlaySound(DIGI_ZC4,&zero,&zero,&zero,v3df_none);
197         }
198     else
199     if (frame == 37)
200         {
201         PlaySound(DIGI_ZC5,&zero,&zero,&zero,v3df_none);
202         }
203     else
204     if (frame == 63)
205         {
206         PlaySound(DIGI_Z16043,&zero,&zero,&zero,v3df_none);
207         PlaySound(DIGI_ZC6,&zero,&zero,&zero,v3df_none);
208         PlaySound(DIGI_ZC7,&zero,&zero,&zero,v3df_none);
209         }
210     else
211     if (frame == 72)
212         {
213         PlaySound(DIGI_ZC7,&zero,&zero,&zero,v3df_none);
214         }
215     else
216     if (frame == 73)
217         {
218         PlaySound(DIGI_ZC4,&zero,&zero,&zero,v3df_none);
219         }
220     else
221     if (frame == 77)
222         {
223         PlaySound(DIGI_ZC5,&zero,&zero,&zero,v3df_none);
224         }
225     else
226     if (frame == 87)
227         {
228         PlaySound(DIGI_ZC8,&zero,&zero,&zero,v3df_none);
229         }
230     else
231     if (frame == 103)
232         {
233         PlaySound(DIGI_ZC7,&zero,&zero,&zero,v3df_none);
234         }
235     else
236     if (frame == 108)
237         {
238         PlaySound(DIGI_ZC9,&zero,&zero,&zero,v3df_none);
239         }
240     else
241     if (frame == 120)
242         {
243         PlaySound(DIGI_JG94039,&zero,&zero,&zero,v3df_none);
244         }
245     }
246 
LoadAnm(short anim_num)247 unsigned char * LoadAnm(short anim_num)
248     {
249     int handle;
250     int length;
251     unsigned char *animbuf, *palptr;
252     int i,j,k;
253 
254     DSPRINTF(ds,"LoadAnm");
255     MONO_PRINT(ds);
256 
257     // this seperate allows the anim to be precached easily
258 
259     ANIMnum = anim_num;
260 
261     // lock it
262     walock[ANIM_TILE(ANIMnum)] = 219;
263 
264     if (anm_ptr[anim_num] == 0)
265         {
266         handle = kopen4load(ANIMname[ANIMnum], 0);
267         if (handle == -1)
268             return(NULL);
269         length = kfilelength(handle);
270 
271         allocache((void **) &anm_ptr[anim_num], length + sizeof(anim_t), &walock[ANIM_TILE(ANIMnum)]);
272         animbuf = (unsigned char *) ((intptr_t)anm_ptr[anim_num] + sizeof(anim_t));
273 
274         kread(handle, animbuf, length);
275         kclose(handle);
276         }
277     else
278         {
279         animbuf = (unsigned char *) ((intptr_t)anm_ptr[anim_num] + sizeof(anim_t));
280         }
281 
282     return(animbuf);
283     }
284 
285 void
playanm(short anim_num)286 playanm(short anim_num)
287     {
288     unsigned char *animbuf, *palptr;
289     int i, j, k, length = 0, numframes = 0;
290     int32 handle = -1;
291     unsigned char ANIMvesapal[4*256];
292     unsigned char tempbuf[256];
293     unsigned char *palook_bak = palookup[0];
294     UserInput uinfo = { FALSE, FALSE, dir_None };
295 
296     ANIMnum = anim_num;
297 
298     KB_FlushKeyboardQueue();
299     KB_ClearKeysDown();
300 
301     DSPRINTF(ds,"PlayAnm");
302     MONO_PRINT(ds);
303 
304     DSPRINTF(ds,"PlayAnm");
305     MONO_PRINT(ds);
306 
307     animbuf = LoadAnm(anim_num);
308     if (!animbuf)
309         return;
310 
311     DSPRINTF(ds,"PlayAnm - Palette Stuff");
312     MONO_PRINT(ds);
313 
314     for (i = 0; i < 256; i++)
315         tempbuf[i] = i;
316     palookup[0] = tempbuf;
317 
318     ANIM_LoadAnim(animbuf);
319     ANIMnumframes = ANIM_NumFrames();
320     numframes = ANIMnumframes;
321 
322     palptr = ANIM_GetPalette();
323     for (i = 0; i < 768; i++)
324 	ANIMvesapal[i] = palptr[i]>>2;
325 
326     tilesizx[ANIM_TILE(ANIMnum)] = 200;
327     tilesizy[ANIM_TILE(ANIMnum)] = 320;
328 
329 	flushperms();
330     clearallviews(0);
331 
332     setbrightness(gs.Brightness,ANIMvesapal,2);
333     if (ANIMnum == 1)
334         {
335         // draw the first frame
336         waloff[ANIM_TILE(ANIMnum)] = (intptr_t)ANIM_DrawFrame(1);
337 #if USE_POLYMOST && USE_OPENGL
338         invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4);
339 #endif
340         rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1);
341         }
342 
343     SoundState = 0;
344     //ototalclock = totalclock + 120*2;
345     ototalclock = totalclock;
346 
347     for (i = 1; i < numframes; i++)
348         {
349         while (totalclock < ototalclock)
350             {
351 			handleevents();
352             CONTROL_GetUserInput(&uinfo);
353             CONTROL_ClearUserInput(&uinfo);
354             switch (ANIMnum)
355                 {
356                 case ANIM_INTRO:
357                     if (KB_KeyWaiting() || uinfo.button0 || uinfo.button1 || quitevent)
358                         goto ENDOFANIMLOOP;
359                     break;
360                 case ANIM_SERP:
361                     if (KEY_PRESSED(KEYSC_ESC) || uinfo.button1 || quitevent)
362                         goto ENDOFANIMLOOP;
363                     break;
364                 }
365 
366             getpackets();
367             }
368 
369         switch (ANIMnum)
370             {
371             case ANIM_INTRO:
372                 AnimShareIntro(i,numframes);
373                 break;
374             case ANIM_SERP:
375                 AnimSerp(i,numframes);
376                 break;
377             case ANIM_SUMO:
378                 AnimSumo(i,numframes);
379                 break;
380             case ANIM_ZILLA:
381                 AnimZilla(i,numframes);
382                 break;
383             }
384 
385         waloff[ANIM_TILE(ANIMnum)] = (intptr_t)ANIM_DrawFrame(i);
386 #if USE_POLYMOST && USE_OPENGL
387         invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4);
388 #endif
389 
390 		clearallviews(0);
391         rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1);
392         nextpage();
393         }
394 
395     // pause on final frame
396     while (totalclock < ototalclock) {
397 		handleevents();
398         getpackets();
399 	}
400 
401 ENDOFANIMLOOP:
402 
403     clearallviews(0);
404     nextpage();
405     palookup[0] = palook_bak;
406     setbrightness(gs.Brightness, (unsigned char*)palette_data, 2);
407 
408     KB_FlushKeyboardQueue();
409     KB_ClearKeysDown();
410     ANIM_FreeAnim();
411     walock[ANIM_TILE(ANIMnum)] = 1;
412     }
413