| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Plats (i.e. elevator platforms) code, raising/lowering. |
| 31 |
* |
| 32 |
*-----------------------------------------------------------------------------*/ |
| 33 |
|
| 34 |
#include "doomstat.h" |
| 35 |
#include "m_random.h" |
| 36 |
#include "r_main.h" |
| 37 |
#include "p_spec.h" |
| 38 |
#include "p_tick.h" |
| 39 |
#include "s_sound.h" |
| 40 |
#include "sounds.h" |
| 41 |
#include "lprintf.h" |
| 42 |
#include "e6y.h"//e6y |
| 43 |
|
| 44 |
#include "dsda/id_list.h" |
| 45 |
#include "dsda/map_format.h" |
| 46 |
|
| 47 |
#include "hexen/p_acs.h" |
| 48 |
#include "hexen/sn_sonix.h" |
| 49 |
|
| 50 |
platlist_t *activeplats; // killough 2/14/98: made global again |
| 51 |
|
| 52 |
// |
| 53 |
// T_PlatRaise() |
| 54 |
// |
| 55 |
// Action routine to move a plat up and down |
| 56 |
// |
| 57 |
// Passed a plat structure containing all pertinent information about the move |
| 58 |
// No return |
| 59 |
// |
| 60 |
// jff 02/08/98 all cases with labels beginning with gen added to support |
| 61 |
// generalized line type behaviors. |
| 62 |
|
| 63 |
void T_CompatiblePlatRaise(plat_t * plat) |
| 64 |
{ |
| 65 |
result_e res; |
| 66 |
|
| 67 |
// handle plat moving, up, down, waiting, or in stasis, |
| 68 |
switch(plat->status) |
| 69 |
{ |
| 70 |
case up: // plat moving up |
| 71 |
res = T_MoveFloorPlane(plat->sector, plat->speed, plat->high, plat->crush, 1, false); |
| 72 |
|
| 73 |
if (heretic && !(leveltime & 31)) |
| 74 |
{ |
| 75 |
S_LoopSectorSound(plat->sector, g_sfx_stnmov_plats, 32); |
| 76 |
} |
| 77 |
|
| 78 |
// if a pure raise type, make the plat moving sound |
| 79 |
if (plat->type == raiseAndChange |
| 80 |
|| plat->type == raiseToNearestAndChange) |
| 81 |
{ |
| 82 |
if (!(leveltime&7)) |
| 83 |
S_LoopSectorSound(plat->sector, g_sfx_stnmov_plats, 8); |
| 84 |
} |
| 85 |
|
| 86 |
// if encountered an obstacle, and not a crush type, reverse direction |
| 87 |
if (res == crushed && plat->crush == NO_CRUSH) |
| 88 |
{ |
| 89 |
plat->count = plat->wait; |
| 90 |
plat->status = down; |
| 91 |
S_StartSectorSound(plat->sector, g_sfx_pstart); |
| 92 |
|
| 93 |
if (demo_compatibility && |
| 94 |
(plat->type == raiseToNearestAndChange || |
| 95 |
plat->type == raiseAndChange)) |
| 96 |
{ |
| 97 |
// For these types vanilla did not initialize plat->low in EV_DoPlat, |
| 98 |
// so they may descend to any depth, or not at all. |
| 99 |
// See https://sourceforge.net/p/prboom-plus/bugs/211/ . |
| 100 |
lprintf(LO_WARN, "T_PlatRaise: raise-and-change type has reversed " |
| 101 |
"direction in compatibility mode - may lead to desync\n" |
| 102 |
" gametic: %d sector: %d complevel: %d\n", |
| 103 |
gametic, plat->sector->iSectorID, compatibility_level); |
| 104 |
} |
| 105 |
} |
| 106 |
else // else handle reaching end of up stroke |
| 107 |
{ |
| 108 |
if (res == pastdest) // end of stroke |
| 109 |
{ |
| 110 |
// if not an instant toggle type, wait, make plat stop sound |
| 111 |
if (plat->type!=toggleUpDn) |
| 112 |
{ |
| 113 |
plat->count = plat->wait; |
| 114 |
plat->status = waiting; |
| 115 |
S_StartSectorSound(plat->sector, g_sfx_pstop); |
| 116 |
} |
| 117 |
else // else go into stasis awaiting next toggle activation |
| 118 |
{ |
| 119 |
plat->oldstatus = plat->status;//jff 3/14/98 after action wait |
| 120 |
plat->status = in_stasis; //for reactivation of toggle |
| 121 |
} |
| 122 |
|
| 123 |
// lift types and pure raise types are done at end of up stroke |
| 124 |
// only the perpetual type waits then goes back up |
| 125 |
switch(plat->type) |
| 126 |
{ |
| 127 |
case blazeDWUS: |
| 128 |
case downWaitUpStay: |
| 129 |
case raiseAndChange: |
| 130 |
case raiseToNearestAndChange: |
| 131 |
case genLift: |
| 132 |
if (heretic && plat->type == raiseToNearestAndChange) break; |
| 133 |
P_RemoveActivePlat(plat); // killough |
| 134 |
default: |
| 135 |
break; |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
break; |
| 140 |
|
| 141 |
case down: // plat moving down |
| 142 |
res = T_MoveFloorPlane(plat->sector, plat->speed, plat->low, NO_CRUSH, -1, false); |
| 143 |
|
| 144 |
// handle reaching end of down stroke |
| 145 |
if (res == pastdest) |
| 146 |
{ |
| 147 |
// if not an instant toggle, start waiting, make plat stop sound |
| 148 |
if (plat->type!=toggleUpDn) //jff 3/14/98 toggle up down |
| 149 |
{ // is silent, instant, no waiting |
| 150 |
plat->count = plat->wait; |
| 151 |
plat->status = waiting; |
| 152 |
S_StartSectorSound(plat->sector, g_sfx_pstop); |
| 153 |
} |
| 154 |
else // instant toggles go into stasis awaiting next activation |
| 155 |
{ |
| 156 |
plat->oldstatus = plat->status;//jff 3/14/98 after action wait |
| 157 |
plat->status = in_stasis; //for reactivation of toggle |
| 158 |
} |
| 159 |
|
| 160 |
//jff 1/26/98 remove the plat if it bounced so it can be tried again |
| 161 |
//only affects plats that raise and bounce |
| 162 |
//killough 1/31/98: relax compatibility to demo_compatibility |
| 163 |
|
| 164 |
// remove the plat if its a pure raise type |
| 165 |
if (!comp[comp_floors]) |
| 166 |
{ |
| 167 |
switch(plat->type) |
| 168 |
{ |
| 169 |
case raiseAndChange: |
| 170 |
case raiseToNearestAndChange: |
| 171 |
P_RemoveActivePlat(plat); |
| 172 |
default: |
| 173 |
break; |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
else if (heretic && !(leveltime & 31)) |
| 178 |
{ |
| 179 |
S_LoopSectorSound(plat->sector, g_sfx_stnmov_plats, 32); |
| 180 |
} |
| 181 |
break; |
| 182 |
|
| 183 |
case waiting: // plat is waiting |
| 184 |
if (!--plat->count) // downcount and check for delay elapsed |
| 185 |
{ |
| 186 |
if (plat->sector->floorheight == plat->low) |
| 187 |
plat->status = up; // if at bottom, start up |
| 188 |
else |
| 189 |
plat->status = down; // if at top, start down |
| 190 |
|
| 191 |
// make plat start sound |
| 192 |
S_StartSectorSound(plat->sector, g_sfx_pstart); |
| 193 |
} |
| 194 |
break; //jff 1/27/98 don't pickup code added later to in_stasis |
| 195 |
|
| 196 |
case in_stasis: // do nothing if in stasis |
| 197 |
break; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
void T_ZDoomPlatRaise(plat_t * plat) |
| 202 |
{ |
| 203 |
result_e res; |
| 204 |
|
| 205 |
switch (plat->status) |
| 206 |
{ |
| 207 |
case up: |
| 208 |
res = T_MoveFloorPlane(plat->sector, plat->speed, plat->high, plat->crush, 1, false); |
| 209 |
|
| 210 |
// if a pure raise type, make the plat moving sound |
| 211 |
if (plat->type == platUpByValueStay |
| 212 |
|| plat->type == platRaiseAndStay |
| 213 |
|| plat->type == platRaiseAndStayLockout) |
| 214 |
{ |
| 215 |
if (!(leveltime & 7)) |
| 216 |
S_LoopSectorSound(plat->sector, g_sfx_stnmov_plats, 8); |
| 217 |
} |
| 218 |
|
| 219 |
if (res == crushed && plat->crush == NO_CRUSH) |
| 220 |
{ |
| 221 |
plat->count = plat->wait; |
| 222 |
plat->status = down; |
| 223 |
S_StartSectorSound(plat->sector, g_sfx_pstart); |
| 224 |
} |
| 225 |
else if (res == pastdest) |
| 226 |
{ |
| 227 |
if (plat->type != platToggle) |
| 228 |
{ |
| 229 |
plat->count = plat->wait; |
| 230 |
plat->status = waiting; |
| 231 |
S_StartSectorSound(plat->sector, g_sfx_pstop); |
| 232 |
|
| 233 |
switch (plat->type) |
| 234 |
{ |
| 235 |
case platRaiseAndStayLockout: |
| 236 |
case platRaiseAndStay: |
| 237 |
case platDownByValue: |
| 238 |
case platDownWaitUpStay: |
| 239 |
case platDownWaitUpStayStone: |
| 240 |
case platUpByValueStay: |
| 241 |
case platDownToNearestFloor: |
| 242 |
case platDownToLowestCeiling: |
| 243 |
P_RemoveActivePlat(plat); |
| 244 |
break; |
| 245 |
default: |
| 246 |
break; |
| 247 |
} |
| 248 |
} |
| 249 |
else |
| 250 |
{ |
| 251 |
plat->oldstatus = plat->status; |
| 252 |
plat->status = in_stasis; |
| 253 |
} |
| 254 |
} |
| 255 |
break; |
| 256 |
case down: |
| 257 |
res = T_MoveFloorPlane(plat->sector, plat->speed, plat->low, NO_CRUSH, -1, false); |
| 258 |
|
| 259 |
if (res == pastdest) |
| 260 |
{ |
| 261 |
if (plat->type != platToggle) |
| 262 |
{ |
| 263 |
plat->count = plat->wait; |
| 264 |
plat->status = waiting; |
| 265 |
S_StartSectorSound(plat->sector, g_sfx_pstop); |
| 266 |
|
| 267 |
switch (plat->type) |
| 268 |
{ |
| 269 |
case platUpWaitDownStay: |
| 270 |
case platUpNearestWaitDownStay: |
| 271 |
case platUpByValue: |
| 272 |
P_RemoveActivePlat(plat); |
| 273 |
break; |
| 274 |
default: |
| 275 |
break; |
| 276 |
} |
| 277 |
} |
| 278 |
else |
| 279 |
{ |
| 280 |
plat->oldstatus = plat->status; |
| 281 |
plat->status = in_stasis; |
| 282 |
} |
| 283 |
} |
| 284 |
else if (res == crushed && plat->crush == NO_CRUSH && plat->type != platToggle) |
| 285 |
{ |
| 286 |
plat->count = plat->wait; |
| 287 |
plat->status = up; |
| 288 |
S_StartSectorSound(plat->sector, g_sfx_pstart); |
| 289 |
} |
| 290 |
|
| 291 |
// jff 1/26/98 remove the plat if it bounced so it can be tried again |
| 292 |
// only affects plats that raise and bounce |
| 293 |
// remove the plat if it's a pure raise type |
| 294 |
switch (plat->type) |
| 295 |
{ |
| 296 |
case platUpByValueStay: |
| 297 |
case platRaiseAndStay: |
| 298 |
case platRaiseAndStayLockout: |
| 299 |
P_RemoveActivePlat(plat); |
| 300 |
break; |
| 301 |
default: |
| 302 |
break; |
| 303 |
} |
| 304 |
|
| 305 |
break; |
| 306 |
case waiting: |
| 307 |
if (!plat->count || !--plat->count) |
| 308 |
{ |
| 309 |
if (plat->sector->floorheight == plat->low) |
| 310 |
plat->status = up; |
| 311 |
else |
| 312 |
plat->status = down; |
| 313 |
|
| 314 |
if (plat->type != platToggle) |
| 315 |
S_StartSectorSound(plat->sector, g_sfx_pstart); |
| 316 |
} |
| 317 |
break; |
| 318 |
case in_stasis: |
| 319 |
break; |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
void T_PlatRaise(plat_t * plat) |
| 324 |
{ |
| 325 |
map_format.t_plat_raise(plat); |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
// |
| 330 |
// EV_DoPlat |
| 331 |
// |
| 332 |
// Handle Plat linedef types |
| 333 |
// |
| 334 |
// Passed the linedef that activated the plat, the type of plat action, |
| 335 |
// and for some plat types, an amount to raise |
| 336 |
// Returns true if a thinker is started, or restarted from stasis |
| 337 |
// |
| 338 |
|
| 339 |
int EV_DoZDoomPlat(int tag, line_t *line, plattype_e type, fixed_t height, |
| 340 |
fixed_t speed, int delay, fixed_t lip, int change) |
| 341 |
{ |
| 342 |
plat_t *plat; |
| 343 |
const int *id_p; |
| 344 |
int rtn = 0; |
| 345 |
sector_t *sec; |
| 346 |
|
| 347 |
height *= FRACUNIT; |
| 348 |
lip *= FRACUNIT; |
| 349 |
|
| 350 |
if (tag) |
| 351 |
{ |
| 352 |
// Activate all <type> plats that are in_stasis |
| 353 |
switch (type) |
| 354 |
{ |
| 355 |
case platToggle: |
| 356 |
rtn = 1; |
| 357 |
case platPerpetualRaise: |
| 358 |
P_ActivateInStasis(tag); |
| 359 |
break; |
| 360 |
default: |
| 361 |
break; |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
FIND_SECTORS2(id_p, tag, line) |
| 366 |
{ |
| 367 |
sec = §ors[*id_p]; |
| 368 |
|
| 369 |
if (P_FloorActive(sec)) |
| 370 |
continue; |
| 371 |
|
| 372 |
rtn = 1; |
| 373 |
|
| 374 |
plat = Z_MallocLevel(sizeof(*plat)); |
| 375 |
memset(plat, 0, sizeof(*plat)); |
| 376 |
P_AddThinker(&plat->thinker); |
| 377 |
|
| 378 |
plat->sector = sec; |
| 379 |
sec->floordata = plat; |
| 380 |
plat->thinker.function = T_PlatRaise; |
| 381 |
plat->type = type; |
| 382 |
plat->crush = NO_CRUSH; |
| 383 |
plat->tag = tag; |
| 384 |
plat->speed = speed; |
| 385 |
plat->wait = delay; |
| 386 |
plat->low = sec->floorheight; |
| 387 |
plat->high = sec->floorheight; |
| 388 |
|
| 389 |
if (change) |
| 390 |
{ |
| 391 |
if (line) |
| 392 |
sec->floorpic = sides[line->sidenum[0]].sector->floorpic; |
| 393 |
if (change == 1) |
| 394 |
P_ResetSectorSpecial(sec); |
| 395 |
} |
| 396 |
|
| 397 |
switch (type) |
| 398 |
{ |
| 399 |
case platRaiseAndStay: |
| 400 |
case platRaiseAndStayLockout: |
| 401 |
plat->high = P_FindNextHighestFloor(sec, sec->floorheight); |
| 402 |
plat->status = up; |
| 403 |
P_ResetSectorSpecial(sec); |
| 404 |
S_StartSectorSound(sec, g_sfx_stnmov_plats); |
| 405 |
break; |
| 406 |
case platUpByValue: |
| 407 |
case platUpByValueStay: |
| 408 |
plat->high = sec->floorheight + height; |
| 409 |
plat->status = up; |
| 410 |
S_StartSectorSound(sec, g_sfx_stnmov_plats); |
| 411 |
break; |
| 412 |
case platDownByValue: |
| 413 |
plat->low = sec->floorheight - height; |
| 414 |
plat->status = down; |
| 415 |
S_StartSectorSound(sec, g_sfx_stnmov_plats); |
| 416 |
break; |
| 417 |
case platDownWaitUpStay: |
| 418 |
case platDownWaitUpStayStone: |
| 419 |
plat->low = P_FindLowestFloorSurrounding(sec) + lip; |
| 420 |
if (plat->low > sec->floorheight) |
| 421 |
plat->low = sec->floorheight; |
| 422 |
plat->status = down; |
| 423 |
S_StartSectorSound(sec, type == platDownWaitUpStay ? g_sfx_pstart : g_sfx_stnmov_plats); |
| 424 |
break; |
| 425 |
case platUpNearestWaitDownStay: |
| 426 |
plat->high = P_FindNextHighestFloor(sec, sec->floorheight); |
| 427 |
plat->status = up; |
| 428 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 429 |
break; |
| 430 |
case platUpWaitDownStay: |
| 431 |
plat->high = P_FindHighestFloorSurrounding(sec); |
| 432 |
if (plat->high < sec->floorheight) |
| 433 |
plat->high = sec->floorheight; |
| 434 |
plat->status = up; |
| 435 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 436 |
break; |
| 437 |
case platPerpetualRaise: |
| 438 |
plat->low = P_FindLowestFloorSurrounding(sec) + lip; |
| 439 |
if (plat->low > sec->floorheight) |
| 440 |
plat->low = sec->floorheight; |
| 441 |
plat->high = P_FindHighestFloorSurrounding(sec); |
| 442 |
if (plat->high < sec->floorheight) |
| 443 |
plat->high = sec->floorheight; |
| 444 |
plat->status = (P_Random(pr_plats) & 1) ? up : down; |
| 445 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 446 |
break; |
| 447 |
case platToggle: |
| 448 |
plat->crush = DOOM_CRUSH; |
| 449 |
plat->low = sec->ceilingheight; |
| 450 |
plat->status = down; |
| 451 |
break; |
| 452 |
case platDownToNearestFloor: |
| 453 |
plat->low = P_FindNextLowestFloor(sec, sec->floorheight) + lip; |
| 454 |
plat->status = down; |
| 455 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 456 |
break; |
| 457 |
case platDownToLowestCeiling: |
| 458 |
plat->low = P_FindLowestCeilingSurrounding(sec); |
| 459 |
if (plat->low > sec->floorheight) |
| 460 |
plat->low = sec->floorheight; |
| 461 |
plat->status = down; |
| 462 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 463 |
break; |
| 464 |
default: |
| 465 |
break; |
| 466 |
} |
| 467 |
|
| 468 |
P_AddActivePlat(plat); |
| 469 |
} |
| 470 |
|
| 471 |
return rtn; |
| 472 |
} |
| 473 |
|
| 474 |
int EV_DoPlat |
| 475 |
( line_t* line, |
| 476 |
plattype_e type, |
| 477 |
int amount ) |
| 478 |
{ |
| 479 |
plat_t* plat; |
| 480 |
const int *id_p; |
| 481 |
int rtn; |
| 482 |
sector_t* sec; |
| 483 |
|
| 484 |
rtn = 0; |
| 485 |
|
| 486 |
// Activate all <type> plats that are in_stasis |
| 487 |
switch(type) |
| 488 |
{ |
| 489 |
case perpetualRaise: |
| 490 |
P_ActivateInStasis(line->tag); |
| 491 |
break; |
| 492 |
|
| 493 |
case toggleUpDn: |
| 494 |
P_ActivateInStasis(line->tag); |
| 495 |
rtn=1; |
| 496 |
break; |
| 497 |
|
| 498 |
default: |
| 499 |
break; |
| 500 |
} |
| 501 |
|
| 502 |
// act on all sectors tagged the same as the activating linedef |
| 503 |
FIND_SECTORS(id_p, line->tag) |
| 504 |
{ |
| 505 |
sec = §ors[*id_p]; |
| 506 |
|
| 507 |
// don't start a second floor function if already moving |
| 508 |
if (P_FloorActive(sec)) //jff 2/23/98 multiple thinkers |
| 509 |
continue; |
| 510 |
|
| 511 |
// Create a thinker |
| 512 |
rtn = 1; |
| 513 |
plat = Z_MallocLevel( sizeof(*plat)); |
| 514 |
memset(plat, 0, sizeof(*plat)); |
| 515 |
P_AddThinker(&plat->thinker); |
| 516 |
|
| 517 |
plat->type = type; |
| 518 |
plat->sector = sec; |
| 519 |
plat->sector->floordata = plat; //jff 2/23/98 multiple thinkers |
| 520 |
plat->thinker.function = T_PlatRaise; |
| 521 |
plat->crush = NO_CRUSH; |
| 522 |
plat->tag = line->tag; |
| 523 |
|
| 524 |
//jff 1/26/98 Avoid raise plat bouncing a head off a ceiling and then |
| 525 |
//going down forever -- default low to plat height when triggered |
| 526 |
plat->low = sec->floorheight; // heretic_note: not in heretic |
| 527 |
|
| 528 |
// set up plat according to type |
| 529 |
switch(type) |
| 530 |
{ |
| 531 |
case raiseToNearestAndChange: |
| 532 |
plat->speed = PLATSPEED/2; |
| 533 |
sec->floorpic = sides[line->sidenum[0]].sector->floorpic; |
| 534 |
plat->high = P_FindNextHighestFloor(sec,sec->floorheight); |
| 535 |
plat->wait = 0; |
| 536 |
plat->status = up; |
| 537 |
P_ResetSectorSpecial(sec); |
| 538 |
|
| 539 |
S_StartSectorSound(sec, g_sfx_stnmov_plats); |
| 540 |
break; |
| 541 |
|
| 542 |
case raiseAndChange: |
| 543 |
plat->speed = PLATSPEED/2; |
| 544 |
sec->floorpic = sides[line->sidenum[0]].sector->floorpic; |
| 545 |
plat->high = sec->floorheight + amount*FRACUNIT; |
| 546 |
plat->wait = 0; |
| 547 |
plat->status = up; |
| 548 |
|
| 549 |
S_StartSectorSound(sec, g_sfx_stnmov_plats); |
| 550 |
break; |
| 551 |
|
| 552 |
case downWaitUpStay: |
| 553 |
plat->speed = PLATSPEED * 4; |
| 554 |
plat->low = P_FindLowestFloorSurrounding(sec); |
| 555 |
|
| 556 |
if (plat->low > sec->floorheight) |
| 557 |
plat->low = sec->floorheight; |
| 558 |
|
| 559 |
plat->high = sec->floorheight; |
| 560 |
plat->wait = 35*PLATWAIT; |
| 561 |
plat->status = down; |
| 562 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 563 |
break; |
| 564 |
|
| 565 |
case blazeDWUS: |
| 566 |
plat->speed = PLATSPEED * 8; |
| 567 |
plat->low = P_FindLowestFloorSurrounding(sec); |
| 568 |
|
| 569 |
if (plat->low > sec->floorheight) |
| 570 |
plat->low = sec->floorheight; |
| 571 |
|
| 572 |
plat->high = sec->floorheight; |
| 573 |
plat->wait = 35*PLATWAIT; |
| 574 |
plat->status = down; |
| 575 |
S_StartSectorSound(sec, sfx_pstart); |
| 576 |
break; |
| 577 |
|
| 578 |
case perpetualRaise: |
| 579 |
plat->speed = PLATSPEED; |
| 580 |
plat->low = P_FindLowestFloorSurrounding(sec); |
| 581 |
|
| 582 |
if (plat->low > sec->floorheight) |
| 583 |
plat->low = sec->floorheight; |
| 584 |
|
| 585 |
plat->high = P_FindHighestFloorSurrounding(sec); |
| 586 |
|
| 587 |
if (plat->high < sec->floorheight) |
| 588 |
plat->high = sec->floorheight; |
| 589 |
|
| 590 |
plat->wait = 35*PLATWAIT; |
| 591 |
plat->status = P_Random(pr_plats)&1; |
| 592 |
|
| 593 |
S_StartSectorSound(sec, g_sfx_pstart); |
| 594 |
break; |
| 595 |
|
| 596 |
case toggleUpDn: //jff 3/14/98 add new type to support instant toggle |
| 597 |
plat->speed = PLATSPEED; //not used |
| 598 |
plat->wait = 35*PLATWAIT; //not used |
| 599 |
plat->crush = DOOM_CRUSH; //jff 3/14/98 crush anything in the way |
| 600 |
|
| 601 |
// set up toggling between ceiling, floor inclusive |
| 602 |
plat->low = sec->ceilingheight; |
| 603 |
plat->high = sec->floorheight; |
| 604 |
plat->status = down; |
| 605 |
break; |
| 606 |
|
| 607 |
default: |
| 608 |
break; |
| 609 |
} |
| 610 |
P_AddActivePlat(plat); // add plat to list of active plats |
| 611 |
} |
| 612 |
return rtn; |
| 613 |
} |
| 614 |
|
| 615 |
// The following were all rewritten by Lee Killough |
| 616 |
// to use the new structure which places no limits |
| 617 |
// on active plats. It also avoids spending as much |
| 618 |
// time searching for active plats. Previously a |
| 619 |
// fixed-size array was used, with NULL indicating |
| 620 |
// empty entries, while now a doubly-linked list |
| 621 |
// is used. |
| 622 |
|
| 623 |
// |
| 624 |
// P_ActivateInStasis() |
| 625 |
// |
| 626 |
// Activate a plat that has been put in stasis |
| 627 |
// (stopped perpetual floor, instant floor/ceil toggle) |
| 628 |
// |
| 629 |
// Passed the tag of the plat that should be reactivated |
| 630 |
// Returns nothing |
| 631 |
// |
| 632 |
void P_ActivateInStasis(int tag) |
| 633 |
{ |
| 634 |
platlist_t *pl; |
| 635 |
for (pl=activeplats; pl; pl=pl->next) // search the active plats |
| 636 |
{ |
| 637 |
plat_t *plat = pl->plat; // for one in stasis with right tag |
| 638 |
if (plat->tag == tag && plat->status == in_stasis) |
| 639 |
{ |
| 640 |
if (plat->type==toggleUpDn) //jff 3/14/98 reactivate toggle type |
| 641 |
plat->status = plat->oldstatus==up? down : up; |
| 642 |
else |
| 643 |
plat->status = plat->oldstatus; |
| 644 |
plat->thinker.function = T_PlatRaise; |
| 645 |
} |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
// |
| 650 |
// EV_StopPlat() |
| 651 |
// |
| 652 |
// Handler for "stop perpetual floor" linedef type |
| 653 |
// |
| 654 |
// Passed the linedef that stopped the plat |
| 655 |
// Returns true if a plat was put in stasis |
| 656 |
// |
| 657 |
// jff 2/12/98 added int return value, fixed return |
| 658 |
// |
| 659 |
|
| 660 |
void EV_StopZDoomPlat(int tag, dboolean remove) |
| 661 |
{ |
| 662 |
platlist_t *pl; |
| 663 |
|
| 664 |
for (pl = activeplats; pl; pl = pl->next) |
| 665 |
{ |
| 666 |
plat_t *plat = pl->plat; |
| 667 |
if (plat->status != in_stasis && plat->tag == tag) |
| 668 |
{ |
| 669 |
if (!remove) |
| 670 |
{ |
| 671 |
plat->oldstatus = plat->status; |
| 672 |
plat->status = in_stasis; |
| 673 |
} |
| 674 |
else |
| 675 |
{ |
| 676 |
P_RemoveActivePlat(plat); |
| 677 |
} |
| 678 |
} |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
int EV_StopPlat(line_t* line) |
| 683 |
{ |
| 684 |
platlist_t *pl; |
| 685 |
for (pl=activeplats; pl; pl=pl->next) // search the active plats |
| 686 |
{ |
| 687 |
plat_t *plat = pl->plat; // for one with the tag not in stasis |
| 688 |
if (plat->status != in_stasis && plat->tag == line->tag) |
| 689 |
{ |
| 690 |
plat->oldstatus = plat->status; // put it in stasis |
| 691 |
plat->status = in_stasis; |
| 692 |
plat->thinker.function = NULL; |
| 693 |
} |
| 694 |
} |
| 695 |
return 1; |
| 696 |
} |
| 697 |
|
| 698 |
// |
| 699 |
// P_AddActivePlat() |
| 700 |
// |
| 701 |
// Add a plat to the head of the active plat list |
| 702 |
// |
| 703 |
// Passed a pointer to the plat to add |
| 704 |
// Returns nothing |
| 705 |
// |
| 706 |
void P_AddActivePlat(plat_t* plat) |
| 707 |
{ |
| 708 |
platlist_t *list = Z_Malloc(sizeof *list); |
| 709 |
list->plat = plat; |
| 710 |
plat->list = list; |
| 711 |
if ((list->next = activeplats)) |
| 712 |
list->next->prev = &list->next; |
| 713 |
list->prev = &activeplats; |
| 714 |
activeplats = list; |
| 715 |
} |
| 716 |
|
| 717 |
// |
| 718 |
// P_RemoveActivePlat() |
| 719 |
// |
| 720 |
// Remove a plat from the active plat list |
| 721 |
// |
| 722 |
// Passed a pointer to the plat to remove |
| 723 |
// Returns nothing |
| 724 |
// |
| 725 |
void P_RemoveActivePlat(plat_t* plat) |
| 726 |
{ |
| 727 |
platlist_t *list = plat->list; |
| 728 |
plat->sector->floordata = NULL; //jff 2/23/98 multiple thinkers |
| 729 |
P_TagFinished(plat->sector->tag); |
| 730 |
P_RemoveThinker(&plat->thinker); |
| 731 |
if ((*list->prev = list->next)) |
| 732 |
list->next->prev = list->prev; |
| 733 |
Z_Free(list); |
| 734 |
} |
| 735 |
|
| 736 |
// |
| 737 |
// P_RemoveAllActivePlats() |
| 738 |
// |
| 739 |
// Remove all plats from the active plat list |
| 740 |
// |
| 741 |
// Passed nothing, returns nothing |
| 742 |
// |
| 743 |
void P_RemoveAllActivePlats(void) |
| 744 |
{ |
| 745 |
while (activeplats) |
| 746 |
{ |
| 747 |
platlist_t *next = activeplats->next; |
| 748 |
Z_Free(activeplats); |
| 749 |
activeplats = next; |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
// hexen |
| 754 |
|
| 755 |
void T_HexenPlatRaise(plat_t * plat) |
| 756 |
{ |
| 757 |
result_e res; |
| 758 |
|
| 759 |
switch (plat->status) |
| 760 |
{ |
| 761 |
case up: |
| 762 |
res = T_MoveFloorPlane(plat->sector, plat->speed, plat->high, plat->crush, 1, true); |
| 763 |
if (res == crushed && plat->crush == NO_CRUSH) |
| 764 |
{ |
| 765 |
plat->count = plat->wait; |
| 766 |
plat->status = down; |
| 767 |
SN_StartSequence((mobj_t *) & plat->sector->soundorg, |
| 768 |
SEQ_PLATFORM + plat->sector->seqType); |
| 769 |
} |
| 770 |
else if (res == pastdest) |
| 771 |
{ |
| 772 |
plat->count = plat->wait; |
| 773 |
plat->status = waiting; |
| 774 |
SN_StopSequence((mobj_t *) & plat->sector->soundorg); |
| 775 |
switch (plat->type) |
| 776 |
{ |
| 777 |
case PLAT_DOWNWAITUPSTAY: |
| 778 |
case PLAT_DOWNBYVALUEWAITUPSTAY: |
| 779 |
P_RemoveActivePlat(plat); |
| 780 |
break; |
| 781 |
default: |
| 782 |
break; |
| 783 |
} |
| 784 |
} |
| 785 |
break; |
| 786 |
case down: |
| 787 |
res = T_MoveFloorPlane(plat->sector, plat->speed, plat->low, NO_CRUSH, -1, true); |
| 788 |
if (res == pastdest) |
| 789 |
{ |
| 790 |
plat->count = plat->wait; |
| 791 |
plat->status = waiting; |
| 792 |
switch (plat->type) |
| 793 |
{ |
| 794 |
case PLAT_UPWAITDOWNSTAY: |
| 795 |
case PLAT_UPBYVALUEWAITDOWNSTAY: |
| 796 |
P_RemoveActivePlat(plat); |
| 797 |
break; |
| 798 |
default: |
| 799 |
break; |
| 800 |
} |
| 801 |
SN_StopSequence((mobj_t *) & plat->sector->soundorg); |
| 802 |
} |
| 803 |
break; |
| 804 |
case waiting: |
| 805 |
if (!--plat->count) |
| 806 |
{ |
| 807 |
if (plat->sector->floorheight == plat->low) |
| 808 |
plat->status = up; |
| 809 |
else |
| 810 |
plat->status = down; |
| 811 |
SN_StartSequence((mobj_t *) & plat->sector->soundorg, |
| 812 |
SEQ_PLATFORM + plat->sector->seqType); |
| 813 |
} |
| 814 |
default: |
| 815 |
break; |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
int EV_DoHexenPlat(line_t * line, byte * args, plattype_e type, int amount) |
| 820 |
{ |
| 821 |
plat_t *plat; |
| 822 |
const int *id_p; |
| 823 |
int rtn; |
| 824 |
sector_t *sec; |
| 825 |
|
| 826 |
rtn = 0; |
| 827 |
|
| 828 |
FIND_SECTORS(id_p, args[0]) |
| 829 |
{ |
| 830 |
sec = §ors[*id_p]; |
| 831 |
if (sec->floordata || sec->ceilingdata) |
| 832 |
continue; |
| 833 |
|
| 834 |
// |
| 835 |
// Find lowest & highest floors around sector |
| 836 |
// |
| 837 |
rtn = 1; |
| 838 |
plat = Z_MallocLevel(sizeof(*plat)); |
| 839 |
memset(plat, 0, sizeof(*plat)); |
| 840 |
P_AddThinker(&plat->thinker); |
| 841 |
|
| 842 |
plat->type = type; |
| 843 |
plat->sector = sec; |
| 844 |
plat->sector->floordata = plat; |
| 845 |
plat->thinker.function = T_PlatRaise; |
| 846 |
plat->crush = NO_CRUSH; |
| 847 |
plat->tag = args[0]; |
| 848 |
plat->speed = args[1] * (FRACUNIT / 8); |
| 849 |
switch (type) |
| 850 |
{ |
| 851 |
case PLAT_DOWNWAITUPSTAY: |
| 852 |
plat->low = P_FindLowestFloorSurrounding(sec) + 8 * FRACUNIT; |
| 853 |
if (plat->low > sec->floorheight) |
| 854 |
plat->low = sec->floorheight; |
| 855 |
plat->high = sec->floorheight; |
| 856 |
plat->wait = args[2]; |
| 857 |
plat->status = down; |
| 858 |
break; |
| 859 |
case PLAT_DOWNBYVALUEWAITUPSTAY: |
| 860 |
plat->low = sec->floorheight - args[3] * 8 * FRACUNIT; |
| 861 |
if (plat->low > sec->floorheight) |
| 862 |
plat->low = sec->floorheight; |
| 863 |
plat->high = sec->floorheight; |
| 864 |
plat->wait = args[2]; |
| 865 |
plat->status = down; |
| 866 |
break; |
| 867 |
case PLAT_UPWAITDOWNSTAY: |
| 868 |
plat->high = P_FindHighestFloorSurrounding(sec); |
| 869 |
if (plat->high < sec->floorheight) |
| 870 |
plat->high = sec->floorheight; |
| 871 |
plat->low = sec->floorheight; |
| 872 |
plat->wait = args[2]; |
| 873 |
plat->status = up; |
| 874 |
break; |
| 875 |
case PLAT_UPBYVALUEWAITDOWNSTAY: |
| 876 |
plat->high = sec->floorheight + args[3] * 8 * FRACUNIT; |
| 877 |
if (plat->high < sec->floorheight) |
| 878 |
plat->high = sec->floorheight; |
| 879 |
plat->low = sec->floorheight; |
| 880 |
plat->wait = args[2]; |
| 881 |
plat->status = up; |
| 882 |
break; |
| 883 |
case PLAT_PERPETUALRAISE: |
| 884 |
plat->low = P_FindLowestFloorSurrounding(sec) + 8 * FRACUNIT; |
| 885 |
if (plat->low > sec->floorheight) |
| 886 |
plat->low = sec->floorheight; |
| 887 |
plat->high = P_FindHighestFloorSurrounding(sec); |
| 888 |
if (plat->high < sec->floorheight) |
| 889 |
plat->high = sec->floorheight; |
| 890 |
plat->wait = args[2]; |
| 891 |
plat->status = P_Random(pr_hexen) & 1; |
| 892 |
break; |
| 893 |
default: |
| 894 |
break; |
| 895 |
} |
| 896 |
P_AddActivePlat(plat); |
| 897 |
SN_StartSequence((mobj_t *) & sec->soundorg, |
| 898 |
SEQ_PLATFORM + sec->seqType); |
| 899 |
} |
| 900 |
return rtn; |
| 901 |
} |
| 902 |
|
| 903 |
// hexen_note: why set the tags? not sure if this is correct |
| 904 |
void Hexen_EV_StopPlat(line_t * line, byte * args) |
| 905 |
{ |
| 906 |
platlist_t *pl; |
| 907 |
for (pl = activeplats; pl; pl = pl->next) |
| 908 |
{ |
| 909 |
pl->plat->tag = args[0]; |
| 910 |
|
| 911 |
if (pl->plat->tag != 0) |
| 912 |
{ |
| 913 |
P_RemoveActivePlat(pl->plat); |
| 914 |
return; |
| 915 |
} |
| 916 |
} |
| 917 |
} |