| 1 |
// |
| 2 |
// Copyright(C) 1993-1996 Id Software, Inc. |
| 3 |
// Copyright(C) 1993-2008 Raven Software |
| 4 |
// Copyright(C) 2005-2014 Simon Howard |
| 5 |
// |
| 6 |
// This program is free software; you can redistribute it and/or |
| 7 |
// modify it under the terms of the GNU General Public License |
| 8 |
// as published by the Free Software Foundation; either version 2 |
| 9 |
// of the License, or (at your option) any later version. |
| 10 |
// |
| 11 |
// This program is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
// |
| 16 |
|
| 17 |
#include "doomdef.h" |
| 18 |
#include "doomstat.h" |
| 19 |
#include "m_random.h" |
| 20 |
#include "s_sound.h" |
| 21 |
#include "sounds.h" |
| 22 |
#include "r_defs.h" |
| 23 |
#include "r_state.h" |
| 24 |
#include "sc_man.h" |
| 25 |
#include "lprintf.h" |
| 26 |
#include "w_wad.h" |
| 27 |
#include "p_setup.h" |
| 28 |
|
| 29 |
#include "dsda/map_format.h" |
| 30 |
#include "dsda/mapinfo.h" |
| 31 |
|
| 32 |
#include "p_anim.h" |
| 33 |
|
| 34 |
#define ANIM_SCRIPT_NAME "ANIMDEFS" |
| 35 |
#define MAX_FRAME_DEFS 96 |
| 36 |
#define ANIM_FLAT 0 |
| 37 |
#define ANIM_TEXTURE 1 |
| 38 |
#define SCI_FLAT "flat" |
| 39 |
#define SCI_TEXTURE "texture" |
| 40 |
#define SCI_PIC "pic" |
| 41 |
#define SCI_TICS "tics" |
| 42 |
#define SCI_RAND "rand" |
| 43 |
|
| 44 |
#define LIGHTNING_SPECIAL 198 |
| 45 |
#define LIGHTNING_SPECIAL2 199 |
| 46 |
#define SKYCHANGE_SPECIAL 200 |
| 47 |
|
| 48 |
typedef struct |
| 49 |
{ |
| 50 |
int index; |
| 51 |
int tics; |
| 52 |
} frameDef_t; |
| 53 |
|
| 54 |
static void P_LightningFlash(void); |
| 55 |
|
| 56 |
extern fixed_t Sky1ColumnOffset; |
| 57 |
extern fixed_t Sky2ColumnOffset; |
| 58 |
extern dboolean DoubleSky; |
| 59 |
extern short numlinespecials; |
| 60 |
extern line_t *linespeciallist[]; |
| 61 |
|
| 62 |
fixed_t Sky1ScrollDelta; |
| 63 |
fixed_t Sky2ScrollDelta; |
| 64 |
|
| 65 |
animDef_t AnimDefs[MAX_ANIM_DEFS]; |
| 66 |
static frameDef_t FrameDefs[MAX_FRAME_DEFS]; |
| 67 |
static int AnimDefCount; |
| 68 |
static dboolean LevelHasLightning; |
| 69 |
int NextLightningFlash; |
| 70 |
int LightningFlash; |
| 71 |
static int *LightningLightLevels; |
| 72 |
|
| 73 |
void P_AnimateCompatibleSurfaces(void) |
| 74 |
{ |
| 75 |
// nothing in doom |
| 76 |
} |
| 77 |
|
| 78 |
void P_AnimateHereticSurfaces(void) |
| 79 |
{ |
| 80 |
int i; |
| 81 |
line_t *line; |
| 82 |
|
| 83 |
// Update scrolling texture offsets |
| 84 |
for (i = 0; i < numlinespecials; i++) |
| 85 |
{ |
| 86 |
line = linespeciallist[i]; |
| 87 |
switch (line->special) |
| 88 |
{ |
| 89 |
case 48: // Effect_Scroll_Left |
| 90 |
sides[line->sidenum[0]].textureoffset += FRACUNIT; |
| 91 |
break; |
| 92 |
case 99: // Effect_Scroll_Right |
| 93 |
sides[line->sidenum[0]].textureoffset -= FRACUNIT; |
| 94 |
break; |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
void P_AnimateZDoomSurfaces(void) |
| 100 |
{ |
| 101 |
// MAP_FORMAT_TODO: P_AnimateZDoomSurfaces |
| 102 |
// The linespeciallist stuff isn't relevant (using doom scrollers) |
| 103 |
// AnimDef stuff will come later |
| 104 |
// Skies / lightning as well |
| 105 |
} |
| 106 |
|
| 107 |
void P_AnimateHexenSurfaces(void) |
| 108 |
{ |
| 109 |
int i; |
| 110 |
animDef_t *ad; |
| 111 |
line_t *line; |
| 112 |
|
| 113 |
// Animate flats and textures |
| 114 |
for (i = 0; i < AnimDefCount; i++) |
| 115 |
{ |
| 116 |
ad = &AnimDefs[i]; |
| 117 |
ad->tics--; |
| 118 |
if (ad->tics == 0) |
| 119 |
{ |
| 120 |
if (ad->currentFrameDef == ad->endFrameDef) |
| 121 |
{ |
| 122 |
ad->currentFrameDef = ad->startFrameDef; |
| 123 |
} |
| 124 |
else |
| 125 |
{ |
| 126 |
ad->currentFrameDef++; |
| 127 |
} |
| 128 |
ad->tics = FrameDefs[ad->currentFrameDef].tics; |
| 129 |
if (ad->tics > 255) |
| 130 |
{ // Random tics |
| 131 |
ad->tics = (ad->tics >> 16) |
| 132 |
+ P_Random(pr_hexen) % ((ad->tics & 0xff00) >> 8); |
| 133 |
} |
| 134 |
if (ad->type == ANIM_FLAT) |
| 135 |
{ |
| 136 |
flattranslation[ad->index] = |
| 137 |
FrameDefs[ad->currentFrameDef].index; |
| 138 |
} |
| 139 |
else |
| 140 |
{ // Texture |
| 141 |
texturetranslation[ad->index] = |
| 142 |
FrameDefs[ad->currentFrameDef].index; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
// Update scrolling textures |
| 148 |
for (i = 0; i < numlinespecials; i++) |
| 149 |
{ |
| 150 |
line = linespeciallist[i]; |
| 151 |
switch (line->special) |
| 152 |
{ |
| 153 |
case 100: // Scroll_Texture_Left |
| 154 |
sides[line->sidenum[0]].textureoffset += line->special_args[0] << 10; |
| 155 |
break; |
| 156 |
case 101: // Scroll_Texture_Right |
| 157 |
sides[line->sidenum[0]].textureoffset -= line->special_args[0] << 10; |
| 158 |
break; |
| 159 |
case 102: // Scroll_Texture_Up |
| 160 |
sides[line->sidenum[0]].rowoffset += line->special_args[0] << 10; |
| 161 |
break; |
| 162 |
case 103: // Scroll_Texture_Down |
| 163 |
sides[line->sidenum[0]].rowoffset -= line->special_args[0] << 10; |
| 164 |
break; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
// Update sky column offsets |
| 169 |
Sky1ColumnOffset += Sky1ScrollDelta; |
| 170 |
Sky2ColumnOffset += Sky2ScrollDelta; |
| 171 |
|
| 172 |
if (LevelHasLightning) |
| 173 |
{ |
| 174 |
if (!NextLightningFlash || LightningFlash) |
| 175 |
{ |
| 176 |
P_LightningFlash(); |
| 177 |
} |
| 178 |
else |
| 179 |
{ |
| 180 |
NextLightningFlash--; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
void P_AnimateSurfaces(void) |
| 186 |
{ |
| 187 |
map_format.animate_surfaces(); |
| 188 |
} |
| 189 |
|
| 190 |
static void P_LightningFlash(void) |
| 191 |
{ |
| 192 |
int i; |
| 193 |
sector_t *tempSec; |
| 194 |
int *tempLight; |
| 195 |
dboolean foundSec; |
| 196 |
int flashLight; |
| 197 |
|
| 198 |
if (LightningFlash) |
| 199 |
{ |
| 200 |
LightningFlash--; |
| 201 |
if (LightningFlash) |
| 202 |
{ |
| 203 |
tempLight = LightningLightLevels; |
| 204 |
tempSec = sectors; |
| 205 |
for (i = 0; i < numsectors; i++, tempSec++) |
| 206 |
{ |
| 207 |
if (tempSec->ceilingpic == skyflatnum |
| 208 |
|| tempSec->special == LIGHTNING_SPECIAL |
| 209 |
|| tempSec->special == LIGHTNING_SPECIAL2) |
| 210 |
{ |
| 211 |
if (*tempLight < tempSec->lightlevel - 4) |
| 212 |
{ |
| 213 |
tempSec->lightlevel -= 4; |
| 214 |
} |
| 215 |
tempLight++; |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
else |
| 220 |
{ // remove the alternate lightning flash special |
| 221 |
tempLight = LightningLightLevels; |
| 222 |
tempSec = sectors; |
| 223 |
for (i = 0; i < numsectors; i++, tempSec++) |
| 224 |
{ |
| 225 |
if (tempSec->ceilingpic == skyflatnum |
| 226 |
|| tempSec->special == LIGHTNING_SPECIAL |
| 227 |
|| tempSec->special == LIGHTNING_SPECIAL2) |
| 228 |
{ |
| 229 |
tempSec->lightlevel = *tempLight; |
| 230 |
tempLight++; |
| 231 |
} |
| 232 |
} |
| 233 |
Sky1Texture = dsda_Sky1Texture(); |
| 234 |
} |
| 235 |
return; |
| 236 |
} |
| 237 |
LightningFlash = (P_Random(pr_hexen) & 7) + 8; |
| 238 |
flashLight = 200 + (P_Random(pr_hexen) & 31); |
| 239 |
tempSec = sectors; |
| 240 |
tempLight = LightningLightLevels; |
| 241 |
foundSec = false; |
| 242 |
for (i = 0; i < numsectors; i++, tempSec++) |
| 243 |
{ |
| 244 |
if (tempSec->ceilingpic == skyflatnum |
| 245 |
|| tempSec->special == LIGHTNING_SPECIAL |
| 246 |
|| tempSec->special == LIGHTNING_SPECIAL2) |
| 247 |
{ |
| 248 |
*tempLight = tempSec->lightlevel; |
| 249 |
if (tempSec->special == LIGHTNING_SPECIAL) |
| 250 |
{ |
| 251 |
tempSec->lightlevel += 64; |
| 252 |
if (tempSec->lightlevel > flashLight) |
| 253 |
{ |
| 254 |
tempSec->lightlevel = flashLight; |
| 255 |
} |
| 256 |
} |
| 257 |
else if (tempSec->special == LIGHTNING_SPECIAL2) |
| 258 |
{ |
| 259 |
tempSec->lightlevel += 32; |
| 260 |
if (tempSec->lightlevel > flashLight) |
| 261 |
{ |
| 262 |
tempSec->lightlevel = flashLight; |
| 263 |
} |
| 264 |
} |
| 265 |
else |
| 266 |
{ |
| 267 |
tempSec->lightlevel = flashLight; |
| 268 |
} |
| 269 |
if (tempSec->lightlevel < *tempLight) |
| 270 |
{ |
| 271 |
tempSec->lightlevel = *tempLight; |
| 272 |
} |
| 273 |
tempLight++; |
| 274 |
foundSec = true; |
| 275 |
} |
| 276 |
} |
| 277 |
if (foundSec) |
| 278 |
{ |
| 279 |
Sky1Texture = dsda_Sky2Texture(); // set alternate sky |
| 280 |
S_StartVoidSound(hexen_sfx_thunder_crash); |
| 281 |
} |
| 282 |
// Calculate the next lighting flash |
| 283 |
if (!NextLightningFlash) |
| 284 |
{ |
| 285 |
if (P_Random(pr_hexen) < 50) |
| 286 |
{ // Immediate Quick flash |
| 287 |
NextLightningFlash = (P_Random(pr_hexen) & 15) + 16; |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
if (P_Random(pr_hexen) < 128 && !(leveltime & 32)) |
| 292 |
{ |
| 293 |
NextLightningFlash = ((P_Random(pr_hexen) & 7) + 2) * 35; |
| 294 |
} |
| 295 |
else |
| 296 |
{ |
| 297 |
NextLightningFlash = ((P_Random(pr_hexen) & 15) + 5) * 35; |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
void P_ForceLightning(void) |
| 304 |
{ |
| 305 |
NextLightningFlash = 0; |
| 306 |
} |
| 307 |
|
| 308 |
void P_InitLightning(void) |
| 309 |
{ |
| 310 |
int i; |
| 311 |
int secCount; |
| 312 |
|
| 313 |
if (!dsda_MapLightning()) |
| 314 |
{ |
| 315 |
LevelHasLightning = false; |
| 316 |
LightningFlash = 0; |
| 317 |
return; |
| 318 |
} |
| 319 |
LightningFlash = 0; |
| 320 |
secCount = 0; |
| 321 |
for (i = 0; i < numsectors; i++) |
| 322 |
{ |
| 323 |
if (sectors[i].ceilingpic == skyflatnum |
| 324 |
|| sectors[i].special == LIGHTNING_SPECIAL |
| 325 |
|| sectors[i].special == LIGHTNING_SPECIAL2) |
| 326 |
{ |
| 327 |
secCount++; |
| 328 |
} |
| 329 |
} |
| 330 |
if (secCount) |
| 331 |
{ |
| 332 |
LevelHasLightning = true; |
| 333 |
} |
| 334 |
else |
| 335 |
{ |
| 336 |
LevelHasLightning = false; |
| 337 |
return; |
| 338 |
} |
| 339 |
LightningLightLevels = (int *) Z_MallocLevel(secCount * sizeof(int)); |
| 340 |
NextLightningFlash = ((P_Random(pr_hexen) & 15) + 5) * 35; // don't flash at level start |
| 341 |
} |
| 342 |
|
| 343 |
void P_InitFTAnims(void) |
| 344 |
{ |
| 345 |
int base; |
| 346 |
int mod; |
| 347 |
int fd; |
| 348 |
animDef_t *ad; |
| 349 |
dboolean ignore; |
| 350 |
dboolean done; |
| 351 |
|
| 352 |
if (!map_format.animdefs) return; |
| 353 |
|
| 354 |
fd = 0; |
| 355 |
ad = AnimDefs; |
| 356 |
AnimDefCount = 0; |
| 357 |
SC_OpenLump(ANIM_SCRIPT_NAME); |
| 358 |
while (SC_GetString()) |
| 359 |
{ |
| 360 |
if (AnimDefCount == MAX_ANIM_DEFS) |
| 361 |
{ |
| 362 |
I_Error("P_InitFTAnims: too many AnimDefs."); |
| 363 |
} |
| 364 |
if (SC_Compare(SCI_FLAT)) |
| 365 |
{ |
| 366 |
ad->type = ANIM_FLAT; |
| 367 |
} |
| 368 |
else if (SC_Compare(SCI_TEXTURE)) |
| 369 |
{ |
| 370 |
ad->type = ANIM_TEXTURE; |
| 371 |
} |
| 372 |
else |
| 373 |
{ |
| 374 |
SC_ScriptError(NULL); |
| 375 |
} |
| 376 |
SC_MustGetString(); // Name |
| 377 |
ignore = false; |
| 378 |
if (ad->type == ANIM_FLAT) |
| 379 |
{ |
| 380 |
if (!W_LumpNameExists2(sc_String, ns_flats)) |
| 381 |
{ |
| 382 |
ignore = true; |
| 383 |
} |
| 384 |
else |
| 385 |
{ |
| 386 |
ad->index = R_FlatNumForName(sc_String); |
| 387 |
} |
| 388 |
} |
| 389 |
else |
| 390 |
{ // Texture |
| 391 |
if (R_CheckTextureNumForName(sc_String) == -1) |
| 392 |
{ |
| 393 |
ignore = true; |
| 394 |
} |
| 395 |
else |
| 396 |
{ |
| 397 |
ad->index = R_TextureNumForName(sc_String); |
| 398 |
} |
| 399 |
} |
| 400 |
ad->startFrameDef = fd; |
| 401 |
done = false; |
| 402 |
while (done == false) |
| 403 |
{ |
| 404 |
if (SC_GetString()) |
| 405 |
{ |
| 406 |
if (SC_Compare(SCI_PIC)) |
| 407 |
{ |
| 408 |
if (fd == MAX_FRAME_DEFS) |
| 409 |
{ |
| 410 |
I_Error("P_InitFTAnims: too many FrameDefs."); |
| 411 |
} |
| 412 |
SC_MustGetNumber(); |
| 413 |
if (ignore == false) |
| 414 |
{ |
| 415 |
FrameDefs[fd].index = ad->index + sc_Number - 1; |
| 416 |
} |
| 417 |
SC_MustGetString(); |
| 418 |
if (SC_Compare(SCI_TICS)) |
| 419 |
{ |
| 420 |
SC_MustGetNumber(); |
| 421 |
if (ignore == false) |
| 422 |
{ |
| 423 |
FrameDefs[fd].tics = sc_Number; |
| 424 |
fd++; |
| 425 |
} |
| 426 |
} |
| 427 |
else if (SC_Compare(SCI_RAND)) |
| 428 |
{ |
| 429 |
SC_MustGetNumber(); |
| 430 |
base = sc_Number; |
| 431 |
SC_MustGetNumber(); |
| 432 |
if (ignore == false) |
| 433 |
{ |
| 434 |
mod = sc_Number - base + 1; |
| 435 |
FrameDefs[fd].tics = (base << 16) + (mod << 8); |
| 436 |
fd++; |
| 437 |
} |
| 438 |
} |
| 439 |
else |
| 440 |
{ |
| 441 |
SC_ScriptError(NULL); |
| 442 |
} |
| 443 |
} |
| 444 |
else |
| 445 |
{ |
| 446 |
SC_UnGet(); |
| 447 |
done = true; |
| 448 |
} |
| 449 |
} |
| 450 |
else |
| 451 |
{ |
| 452 |
done = true; |
| 453 |
} |
| 454 |
} |
| 455 |
if ((ignore == false) && (fd - ad->startFrameDef < 2)) |
| 456 |
{ |
| 457 |
I_Error("P_InitFTAnims: AnimDef has framecount < 2."); |
| 458 |
} |
| 459 |
if (ignore == false) |
| 460 |
{ |
| 461 |
ad->endFrameDef = fd - 1; |
| 462 |
ad->currentFrameDef = ad->endFrameDef; |
| 463 |
ad->tics = 1; // Force 1st game tic to animate |
| 464 |
AnimDefCount++; |
| 465 |
ad++; |
| 466 |
} |
| 467 |
} |
| 468 |
SC_Close(); |
| 469 |
} |