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