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 18 extern int *TerrainTypes; 19 20 // 21 // scrolling line specials 22 // 23 24 #define MAXLINEANIMS 64*256 25 extern short numlinespecials; 26 extern line_t *linespeciallist[MAXLINEANIMS]; 27 28 // Define values for map objects 29 #define MO_TELEPORTMAN 14 30 31 // at game start 32 void P_InitTerrainTypes(void); 33 void P_InitLava(void); 34 35 // at map load 36 void P_SpawnSpecials(void); 37 38 // every tic 39 void P_UpdateSpecials(void); 40 41 // when needed 42 boolean P_ExecuteLineSpecial(int special, byte * args, line_t * line, 43 int side, mobj_t * mo); 44 boolean P_ActivateLine(line_t * ld, mobj_t * mo, int side, 45 int activationType); 46 //boolean P_UseSpecialLine ( mobj_t *thing, line_t *line); 47 //void P_ShootSpecialLine ( mobj_t *thing, line_t *line); 48 //void P_CrossSpecialLine (int linenum, int side, mobj_t *thing); 49 50 void P_PlayerInSpecialSector(player_t * player); 51 void P_PlayerOnSpecialFlat(player_t * player, int floorType); 52 53 //int twoSided(int sector,int line); 54 //sector_t *getSector(int currentSector,int line,int side); 55 //side_t *getSide(int currentSector,int line, int side); 56 fixed_t P_FindLowestFloorSurrounding(sector_t * sec); 57 fixed_t P_FindHighestFloorSurrounding(sector_t * sec); 58 fixed_t P_FindNextHighestFloor(sector_t * sec, int currentheight); 59 fixed_t P_FindLowestCeilingSurrounding(sector_t * sec); 60 fixed_t P_FindHighestCeilingSurrounding(sector_t * sec); 61 //int P_FindSectorFromLineTag(line_t *line,int start); 62 int P_FindSectorFromTag(int tag, int start); 63 //int P_FindMinSurroundingLight(sector_t *sector,int max); 64 sector_t *getNextSector(line_t * line, sector_t * sec); 65 line_t *P_FindLine(int lineTag, int *searchPosition); 66 67 // 68 // SPECIAL 69 // 70 //int EV_DoDonut(line_t *line); 71 72 //------------------------------- 73 // P_anim.c 74 //------------------------------- 75 76 void P_AnimateSurfaces(void); 77 void P_InitFTAnims(void); 78 void P_InitLightning(void); 79 void P_ForceLightning(void); 80 81 /* 82 =============================================================================== 83 84 P_LIGHTS 85 86 =============================================================================== 87 */ 88 89 typedef enum 90 { 91 LITE_RAISEBYVALUE, 92 LITE_LOWERBYVALUE, 93 LITE_CHANGETOVALUE, 94 LITE_FADE, 95 LITE_GLOW, 96 LITE_FLICKER, 97 LITE_STROBE 98 } lighttype_t; 99 100 typedef struct 101 { 102 thinker_t thinker; 103 sector_t *sector; 104 lighttype_t type; 105 int value1; 106 int value2; 107 int tics1; 108 int tics2; 109 int count; 110 } light_t; 111 112 typedef struct 113 { 114 thinker_t thinker; 115 sector_t *sector; 116 int index; 117 int base; 118 } phase_t; 119 120 #define LIGHT_SEQUENCE_START 2 121 #define LIGHT_SEQUENCE 3 122 #define LIGHT_SEQUENCE_ALT 4 123 124 void T_Phase(phase_t * phase); 125 void T_Light(light_t * light); 126 void P_SpawnPhasedLight(sector_t * sector, int base, int index); 127 void P_SpawnLightSequence(sector_t * sector, int indexStep); 128 boolean EV_SpawnLight(line_t * line, byte * arg, lighttype_t type); 129 130 #if 0 131 typedef struct 132 { 133 thinker_t thinker; 134 sector_t *sector; 135 int count; 136 int maxlight; 137 int minlight; 138 int maxtime; 139 int mintime; 140 } lightflash_t; 141 142 typedef struct 143 { 144 thinker_t thinker; 145 sector_t *sector; 146 int count; 147 int minlight; 148 int maxlight; 149 int darktime; 150 int brighttime; 151 } strobe_t; 152 153 typedef struct 154 { 155 thinker_t thinker; 156 sector_t *sector; 157 int minlight; 158 int maxlight; 159 int direction; 160 } glow_t; 161 162 typedef struct 163 { 164 thinker_t thinker; 165 sector_t *sector; 166 int index; 167 int base; 168 } phase_t; 169 170 #define GLOWSPEED 8 171 #define STROBEBRIGHT 5 172 #define FASTDARK 15 173 #define SLOWDARK 35 174 175 #define LIGHT_SEQUENCE_START 2 176 #define LIGHT_SEQUENCE 3 177 #define LIGHT_SEQUENCE_ALT 4 178 179 void T_LightFlash(lightflash_t * flash); 180 void P_SpawnLightFlash(sector_t * sector); 181 void T_StrobeFlash(strobe_t * flash); 182 void P_SpawnStrobeFlash(sector_t * sector, int fastOrSlow, int inSync); 183 void EV_StartLightStrobing(line_t * line); 184 void EV_TurnTagLightsOff(line_t * line); 185 void EV_LightTurnOn(line_t * line, int bright); 186 void T_Glow(glow_t * g); 187 void P_SpawnGlowingLight(sector_t * sector); 188 void T_Phase(phase_t * phase); 189 void P_SpawnPhasedLight(sector_t * sector, int base, int index); 190 void P_SpawnLightSequence(sector_t * sector, int indexStep); 191 #endif 192 193 /* 194 =============================================================================== 195 196 P_SWITCH 197 198 =============================================================================== 199 */ 200 typedef struct 201 { 202 char name1[9]; 203 char name2[9]; 204 int soundID; 205 } switchlist_t; 206 207 typedef enum 208 { 209 SWTCH_TOP, 210 SWTCH_MIDDLE, 211 SWTCH_BOTTOM 212 } bwhere_e; 213 214 typedef struct 215 { 216 line_t *line; 217 bwhere_e where; 218 int btexture; 219 int btimer; 220 mobj_t *soundorg; 221 } button_t; 222 223 #define MAXSWITCHES 50 // max # of wall switches in a level 224 #define MAXBUTTONS 16 // 4 players, 4 buttons each at once, max. 225 #define BUTTONTIME 35 // 1 second 226 227 extern button_t buttonlist[MAXBUTTONS]; 228 229 void P_ChangeSwitchTexture(line_t * line, int useAgain); 230 void P_InitSwitchList(void); 231 232 /* 233 =============================================================================== 234 235 P_PLATS 236 237 =============================================================================== 238 */ 239 240 typedef enum 241 { 242 PLAT_UP, 243 PLAT_DOWN, 244 PLAT_WAITING, 245 // PLAT_IN_STASIS 246 } plat_e; 247 248 typedef enum 249 { 250 PLAT_PERPETUALRAISE, 251 PLAT_DOWNWAITUPSTAY, 252 PLAT_DOWNBYVALUEWAITUPSTAY, 253 PLAT_UPWAITDOWNSTAY, 254 PLAT_UPBYVALUEWAITDOWNSTAY, 255 //PLAT_RAISEANDCHANGE, 256 //PLAT_RAISETONEARESTANDCHANGE 257 } plattype_e; 258 259 typedef struct 260 { 261 thinker_t thinker; 262 sector_t *sector; 263 fixed_t speed; 264 fixed_t low; 265 fixed_t high; 266 int wait; 267 int count; 268 plat_e status; 269 plat_e oldstatus; 270 int crush; 271 int tag; 272 plattype_e type; 273 } plat_t; 274 275 #define PLATWAIT 3 276 #define PLATSPEED FRACUNIT 277 #define MAXPLATS 30*256 278 279 extern plat_t *activeplats[MAXPLATS]; 280 281 void T_PlatRaise(plat_t * plat); 282 int EV_DoPlat(line_t * line, byte * args, plattype_e type, int amount); 283 void P_AddActivePlat(plat_t * plat); 284 void P_RemoveActivePlat(plat_t * plat); 285 void EV_StopPlat(line_t * line, byte * args); 286 287 /* 288 =============================================================================== 289 290 P_DOORS 291 292 =============================================================================== 293 */ 294 typedef enum 295 { 296 DREV_NORMAL, 297 DREV_CLOSE30THENOPEN, 298 DREV_CLOSE, 299 DREV_OPEN, 300 DREV_RAISEIN5MINS, 301 } vldoor_e; 302 303 typedef struct 304 { 305 thinker_t thinker; 306 sector_t *sector; 307 vldoor_e type; 308 fixed_t topheight; 309 fixed_t speed; 310 int direction; // 1 = up, 0 = waiting at top, -1 = down 311 int topwait; // tics to wait at the top (keep in case a door going down is reset) 312 int topcountdown; // when it reaches 0, start going down 313 } vldoor_t; 314 315 #define VDOORSPEED FRACUNIT*2 316 #define VDOORWAIT 150 317 318 boolean EV_VerticalDoor(line_t * line, mobj_t * thing); 319 int EV_DoDoor(line_t * line, byte * args, vldoor_e type); 320 void T_VerticalDoor(vldoor_t * door); 321 //void P_SpawnDoorCloseIn30(sector_t *sec); 322 //void P_SpawnDoorRaiseIn5Mins(sector_t *sec, int secnum); 323 324 /* 325 =============================================================================== 326 327 P_CEILNG 328 329 =============================================================================== 330 */ 331 typedef enum 332 { 333 CLEV_LOWERTOFLOOR, 334 CLEV_RAISETOHIGHEST, 335 CLEV_LOWERANDCRUSH, 336 CLEV_CRUSHANDRAISE, 337 CLEV_LOWERBYVALUE, 338 CLEV_RAISEBYVALUE, 339 CLEV_CRUSHRAISEANDSTAY, 340 CLEV_MOVETOVALUETIMES8 341 } ceiling_e; 342 343 typedef struct 344 { 345 thinker_t thinker; 346 sector_t *sector; 347 ceiling_e type; 348 fixed_t bottomheight, topheight; 349 fixed_t speed; 350 int crush; 351 int direction; // 1 = up, 0 = waiting, -1 = down 352 int tag; // ID 353 int olddirection; 354 } ceiling_t; 355 356 #define CEILSPEED FRACUNIT 357 #define CEILWAIT 150 358 #define MAXCEILINGS 30 359 360 extern ceiling_t *activeceilings[MAXCEILINGS]; 361 362 int EV_DoCeiling(line_t * line, byte * args, ceiling_e type); 363 void T_MoveCeiling(ceiling_t * ceiling); 364 void P_AddActiveCeiling(ceiling_t * c); 365 void P_RemoveActiveCeiling(ceiling_t * c); 366 int EV_CeilingCrushStop(line_t * line, byte * args); 367 368 /* 369 =============================================================================== 370 371 P_FLOOR 372 373 =============================================================================== 374 */ 375 typedef enum 376 { 377 FLEV_LOWERFLOOR, // lower floor to highest surrounding floor 378 FLEV_LOWERFLOORTOLOWEST, // lower floor to lowest surrounding floor 379 FLEV_LOWERFLOORBYVALUE, 380 FLEV_RAISEFLOOR, // raise floor to lowest surrounding CEILING 381 FLEV_RAISEFLOORTONEAREST, // raise floor to next highest surrounding floor 382 FLEV_RAISEFLOORBYVALUE, 383 FLEV_RAISEFLOORCRUSH, 384 FLEV_RAISEBUILDSTEP, // One step of a staircase 385 FLEV_RAISEBYVALUETIMES8, 386 FLEV_LOWERBYVALUETIMES8, 387 FLEV_LOWERTIMES8INSTANT, 388 FLEV_RAISETIMES8INSTANT, 389 FLEV_MOVETOVALUETIMES8 390 } floor_e; 391 392 typedef struct 393 { 394 thinker_t thinker; 395 sector_t *sector; 396 floor_e type; 397 int crush; 398 int direction; 399 int newspecial; 400 short texture; 401 fixed_t floordestheight; 402 fixed_t speed; 403 int delayCount; 404 int delayTotal; 405 fixed_t stairsDelayHeight; 406 fixed_t stairsDelayHeightDelta; 407 fixed_t resetHeight; 408 short resetDelay; 409 short resetDelayCount; 410 byte textureChange; 411 } floormove_t; 412 413 typedef struct 414 { 415 thinker_t thinker; 416 sector_t *sector; 417 int ceilingSpeed; 418 int floorSpeed; 419 int floordest; 420 int ceilingdest; 421 int direction; 422 int crush; 423 } pillar_t; 424 425 typedef struct 426 { 427 thinker_t thinker; 428 sector_t *sector; 429 fixed_t originalHeight; 430 fixed_t accumulator; 431 fixed_t accDelta; 432 fixed_t targetScale; 433 fixed_t scale; 434 fixed_t scaleDelta; 435 int ticker; 436 int state; 437 } floorWaggle_t; 438 439 #define FLOORSPEED FRACUNIT 440 441 typedef enum 442 { 443 RES_OK, 444 RES_CRUSHED, 445 RES_PASTDEST 446 } result_e; 447 448 typedef enum 449 { 450 STAIRS_NORMAL, 451 STAIRS_SYNC, 452 STAIRS_PHASED 453 } stairs_e; 454 455 result_e T_MovePlane(sector_t * sector, fixed_t speed, 456 fixed_t dest, int crush, int floorOrCeiling, 457 int direction); 458 459 int EV_BuildStairs(line_t * line, byte * args, int direction, stairs_e type); 460 int EV_DoFloor(line_t * line, byte * args, floor_e floortype); 461 void T_MoveFloor(floormove_t * floor); 462 void T_BuildPillar(pillar_t * pillar); 463 void T_FloorWaggle(floorWaggle_t * waggle); 464 int EV_BuildPillar(line_t * line, byte * args, boolean crush); 465 int EV_OpenPillar(line_t * line, byte * args); 466 int EV_DoFloorAndCeiling(line_t * line, byte * args, boolean raise); 467 int EV_FloorCrushStop(line_t * line, byte * args); 468 boolean EV_StartFloorWaggle(int tag, int height, int speed, int offset, 469 int timer); 470 471 //-------------------------------------------------------------------------- 472 // 473 // p_telept 474 // 475 //-------------------------------------------------------------------------- 476 477 boolean P_Teleport(mobj_t * thing, fixed_t x, fixed_t y, angle_t angle, 478 boolean useFog); 479 boolean EV_Teleport(int tid, mobj_t * thing, boolean fog); 480 481 //-------------------------------------------------------------------------- 482 // 483 // p_acs 484 // 485 //-------------------------------------------------------------------------- 486 487 #define MAX_ACS_SCRIPT_VARS 10 488 #define MAX_ACS_MAP_VARS 32 489 #define MAX_ACS_WORLD_VARS 64 490 #define ACS_STACK_DEPTH 32 491 #define MAX_ACS_STORE 20 492 493 typedef enum 494 { 495 ASTE_INACTIVE, 496 ASTE_RUNNING, 497 ASTE_SUSPENDED, 498 ASTE_WAITINGFORTAG, 499 ASTE_WAITINGFORPOLY, 500 ASTE_WAITINGFORSCRIPT, 501 ASTE_TERMINATING 502 } aste_t; 503 504 typedef struct acs_s acs_t; 505 typedef struct acsInfo_s acsInfo_t; 506 507 struct acsInfo_s 508 { 509 int number; 510 int offset; 511 int argCount; 512 aste_t state; 513 int waitValue; 514 }; 515 516 struct acs_s 517 { 518 thinker_t thinker; 519 mobj_t *activator; 520 line_t *line; 521 int side; 522 int number; 523 int infoIndex; 524 int delayCount; 525 int stack[ACS_STACK_DEPTH]; 526 int stackPtr; 527 int vars[MAX_ACS_SCRIPT_VARS]; 528 int ip; 529 }; 530 531 typedef struct 532 { 533 int map; // Target map 534 int script; // Script number on target map 535 byte args[4]; // Padded to 4 for alignment 536 } acsstore_t; 537 538 void P_LoadACScripts(int lump); 539 boolean P_StartACS(int number, int map, byte * args, mobj_t * activator, 540 line_t * line, int side); 541 boolean P_StartLockedACS(line_t * line, byte * args, mobj_t * mo, int side); 542 boolean P_TerminateACS(int number, int map); 543 boolean P_SuspendACS(int number, int map); 544 void T_InterpretACS(acs_t * script); 545 void P_TagFinished(int tag); 546 void P_PolyobjFinished(int po); 547 void P_ACSInitNewGame(void); 548 void P_CheckACSStore(void); 549 void CheckACSPresent(int number); 550 551 extern int ACScriptCount; 552 extern byte *ActionCodeBase; 553 extern acsInfo_t *ACSInfo; 554 extern int MapVars[MAX_ACS_MAP_VARS]; 555 extern int WorldVars[MAX_ACS_WORLD_VARS]; 556 extern acsstore_t ACSStore[MAX_ACS_STORE + 1]; // +1 for termination marker 557 558 //-------------------------------------------------------------------------- 559 // 560 // p_things 561 // 562 //-------------------------------------------------------------------------- 563 564 extern mobjtype_t TranslateThingType[]; 565 566 boolean EV_ThingProjectile(byte * args, boolean gravity); 567 boolean EV_ThingSpawn(byte * args, boolean fog); 568 boolean EV_ThingActivate(int tid); 569 boolean EV_ThingDeactivate(int tid); 570 boolean EV_ThingRemove(int tid); 571 boolean EV_ThingDestroy(int tid); 572