2 //**************************************************************************
4 //** p_anim.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
13 // HEADER FILES ------------------------------------------------------------
18 // MACROS ------------------------------------------------------------------
20 #define ANIM_SCRIPT_NAME "ANIMDEFS"
21 #define MAX_ANIM_DEFS 20
22 #define MAX_FRAME_DEFS 96
24 #define ANIM_TEXTURE 1
25 #define SCI_FLAT "flat"
26 #define SCI_TEXTURE "texture"
28 #define SCI_TICS "tics"
29 #define SCI_RAND "rand"
31 #define LIGHTNING_SPECIAL 198
32 #define LIGHTNING_SPECIAL2 199
33 #define SKYCHANGE_SPECIAL 200
35 // TYPES -------------------------------------------------------------------
53 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
55 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
57 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
59 static void P_LightningFlash(void);
61 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
63 extern fixed_t Sky1ColumnOffset;
64 extern fixed_t Sky2ColumnOffset;
65 extern int Sky1Texture;
66 extern boolean DoubleSky;
68 // PUBLIC DATA DEFINITIONS -------------------------------------------------
70 fixed_t Sky1ScrollDelta;
71 fixed_t Sky2ScrollDelta;
73 // PRIVATE DATA DEFINITIONS ------------------------------------------------
75 static animDef_t AnimDefs[MAX_ANIM_DEFS];
76 static frameDef_t FrameDefs[MAX_FRAME_DEFS];
77 static int AnimDefCount;
78 static boolean LevelHasLightning;
79 static int NextLightningFlash;
80 static int LightningFlash;
81 static int *LightningLightLevels;
83 // CODE --------------------------------------------------------------------
85 //==========================================================================
89 //==========================================================================
91 void P_AnimateSurfaces(void)
97 // Animate flats and textures
98 for(i = 0; i < AnimDefCount; i++)
104 if(ad->currentFrameDef == ad->endFrameDef)
106 ad->currentFrameDef = ad->startFrameDef;
110 ad->currentFrameDef++;
112 ad->tics = FrameDefs[ad->currentFrameDef].tics;
115 ad->tics = (ad->tics>>16)
116 +P_Random()%((ad->tics&0xff00)>>8);
118 if(ad->type == ANIM_FLAT)
120 flattranslation[ad->index] =
121 FrameDefs[ad->currentFrameDef].index;
125 texturetranslation[ad->index] =
126 FrameDefs[ad->currentFrameDef].index;
131 // Update scrolling textures
132 for(i = 0; i < numlinespecials; i++)
134 line = linespeciallist[i];
135 switch(line->special)
137 case 100: // Scroll_Texture_Left
138 sides[line->sidenum[0]].textureoffset += line->arg1<<10;
140 case 101: // Scroll_Texture_Right
141 sides[line->sidenum[0]].textureoffset -= line->arg1<<10;
143 case 102: // Scroll_Texture_Up
144 sides[line->sidenum[0]].rowoffset += line->arg1<<10;
146 case 103: // Scroll_Texture_Down
147 sides[line->sidenum[0]].rowoffset -= line->arg1<<10;
152 // Update sky column offsets
153 Sky1ColumnOffset += Sky1ScrollDelta;
154 Sky2ColumnOffset += Sky2ScrollDelta;
156 if(LevelHasLightning)
158 if(!NextLightningFlash || LightningFlash)
164 NextLightningFlash--;
169 //==========================================================================
173 //==========================================================================
175 static void P_LightningFlash(void)
188 tempLight = LightningLightLevels;
190 for(i = 0; i < numsectors; i++, tempSec++)
192 if(tempSec->ceilingpic == skyflatnum
193 || tempSec->special == LIGHTNING_SPECIAL
194 || tempSec->special == LIGHTNING_SPECIAL2)
196 if(*tempLight < tempSec->lightlevel-4)
198 tempSec->lightlevel -= 4;
205 { // remove the alternate lightning flash special
206 tempLight = LightningLightLevels;
208 for(i = 0; i < numsectors; i++, tempSec++)
210 if(tempSec->ceilingpic == skyflatnum
211 || tempSec->special == LIGHTNING_SPECIAL
212 || tempSec->special == LIGHTNING_SPECIAL2)
214 tempSec->lightlevel = *tempLight;
218 Sky1Texture = P_GetMapSky1Texture(gamemap);
222 LightningFlash = (P_Random()&7)+8;
223 flashLight = 200+(P_Random()&31);
225 tempLight = LightningLightLevels;
227 for(i = 0; i < numsectors; i++, tempSec++)
229 if(tempSec->ceilingpic == skyflatnum
230 || tempSec->special == LIGHTNING_SPECIAL
231 || tempSec->special == LIGHTNING_SPECIAL2)
233 *tempLight = tempSec->lightlevel;
234 if(tempSec->special == LIGHTNING_SPECIAL)
236 tempSec->lightlevel += 64;
237 if(tempSec->lightlevel > flashLight)
239 tempSec->lightlevel = flashLight;
242 else if(tempSec->special == LIGHTNING_SPECIAL2)
244 tempSec->lightlevel += 32;
245 if(tempSec->lightlevel > flashLight)
247 tempSec->lightlevel = flashLight;
252 tempSec->lightlevel = flashLight;
254 if(tempSec->lightlevel < *tempLight)
256 tempSec->lightlevel = *tempLight;
264 Sky1Texture = P_GetMapSky2Texture(gamemap); // set alternate sky
265 S_StartSound(NULL, SFX_THUNDER_CRASH);
267 // Calculate the next lighting flash
268 if(!NextLightningFlash)
271 { // Immediate Quick flash
272 NextLightningFlash = (P_Random()&15)+16;
276 if(P_Random() < 128 && !(leveltime&32))
278 NextLightningFlash = ((P_Random()&7)+2)*35;
282 NextLightningFlash = ((P_Random()&15)+5)*35;
288 //==========================================================================
292 //==========================================================================
294 void P_ForceLightning(void)
296 NextLightningFlash = 0;
299 //==========================================================================
303 //==========================================================================
305 void P_InitLightning(void)
310 if(!P_GetMapLightning(gamemap))
312 LevelHasLightning = false;
318 for(i = 0; i < numsectors; i++)
320 if(sectors[i].ceilingpic == skyflatnum
321 || sectors[i].special == LIGHTNING_SPECIAL
322 || sectors[i].special == LIGHTNING_SPECIAL2)
329 LevelHasLightning = true;
333 LevelHasLightning = false;
336 LightningLightLevels = (int *)Z_Malloc(secCount*sizeof(int), PU_LEVEL,
338 NextLightningFlash = ((P_Random()&15)+5)*35; // don't flash at level start
341 //==========================================================================
345 // Initialize flat and texture animation lists.
347 //==========================================================================
349 void P_InitFTAnims(void)
361 SC_Open(ANIM_SCRIPT_NAME);
362 while(SC_GetString())
364 if(AnimDefCount == MAX_ANIM_DEFS)
366 I_Error("P_InitFTAnims: too many AnimDefs.");
368 if(SC_Compare(SCI_FLAT))
370 ad->type = ANIM_FLAT;
372 else if(SC_Compare(SCI_TEXTURE))
374 ad->type = ANIM_TEXTURE;
378 SC_ScriptError(NULL);
380 SC_MustGetString(); // Name
382 if(ad->type == ANIM_FLAT)
384 if(W_CheckNumForName(sc_String) == -1)
390 ad->index = R_FlatNumForName(sc_String);
395 if(R_CheckTextureNumForName(sc_String) == -1)
401 ad->index = R_TextureNumForName(sc_String);
404 ad->startFrameDef = fd;
410 if(SC_Compare(SCI_PIC))
412 if(fd == MAX_FRAME_DEFS)
414 I_Error("P_InitFTAnims: too many FrameDefs.");
419 FrameDefs[fd].index = ad->index+sc_Number-1;
422 if(SC_Compare(SCI_TICS))
427 FrameDefs[fd].tics = sc_Number;
431 else if(SC_Compare(SCI_RAND))
438 mod = sc_Number-base+1;
439 FrameDefs[fd].tics = (base<<16)+(mod<<8);
445 SC_ScriptError(NULL);
459 if((ignore == false) && (fd-ad->startFrameDef < 2))
461 I_Error("P_InitFTAnims: AnimDef has framecount < 2.");
465 ad->endFrameDef = fd-1;
466 ad->currentFrameDef = ad->endFrameDef;
467 ad->tics = 1; // Force 1st game tic to animate