raze/source/games/duke/src/sectors_d.cpp

377 lines
9.6 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
2020-05-13 14:19:39 +00:00
Copyright (C) 2020 - Christoph Oelckers
This file is part of Enhanced Duke Nukem 3D version 1.5 - Atomic Edition
Duke Nukem 3D is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Original Source: 1996 - Todd Replogle
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
EDuke enhancements integrated: 04/13/2003 - Matt Saettler
Note: EDuke source was in transition. Changes are in-progress in the
source as it is released.
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "global.h"
2020-06-24 19:21:02 +00:00
#include "sounds.h"
2020-07-07 15:56:20 +00:00
#include "mapinfo.h"
#include "dukeactor.h"
#include "secrets.h"
// PRIMITIVE
BEGIN_DUKE_NS
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool checkaccessswitch_d(int snum, int switchpal, DDukeActor* act, walltype* wwal)
{
if (getPlayer(snum)->access_incs == 0)
{
if (switchpal == 0)
{
if ((getPlayer(snum)->got_access & 1))
getPlayer(snum)->access_incs = 1;
else FTA(70, getPlayer(snum));
}
else if (switchpal == 21)
{
if (getPlayer(snum)->got_access & 2)
getPlayer(snum)->access_incs = 1;
else FTA(71, getPlayer(snum));
}
else if (switchpal == 23)
{
if (getPlayer(snum)->got_access & 4)
getPlayer(snum)->access_incs = 1;
else FTA(72, getPlayer(snum));
}
if (getPlayer(snum)->access_incs == 1)
{
if (!act)
getPlayer(snum)->access_wall = wwal;
else
getPlayer(snum)->access_spritenum = act;
}
return 1;
}
return 0;
}
2020-05-10 18:59:38 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-11-18 17:51:19 +00:00
void activatebysector_d(sectortype* sect, DDukeActor* activator)
2020-05-10 18:59:38 +00:00
{
int didit = 0;
2020-11-02 18:28:59 +00:00
DukeSectIterator it(sect);
while (auto act = it.Next())
{
2022-11-20 11:43:24 +00:00
if (isactivator(act))
{
2022-11-19 14:40:35 +00:00
operateactivators(act->spr.lotag, nullptr);
didit = 1;
// return;
}
}
if (didit == 0)
2020-11-02 18:28:59 +00:00
operatesectors(sect, activator);
2020-05-10 18:59:38 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void checkplayerhurt_d(DukePlayer* p, const Collision& coll)
2020-05-10 18:59:38 +00:00
{
if (coll.type == kHitSprite)
{
2022-11-15 09:17:23 +00:00
CallOnHurt(coll.actor(), p);
return;
}
if (coll.type != kHitWall) return;
auto wal = coll.hitWall;
if (p->hurt_delay > 0) p->hurt_delay--;
else if (wal->cstat & (CSTAT_WALL_BLOCK | CSTAT_WALL_ALIGN_BOTTOM | CSTAT_WALL_MASKED | CSTAT_WALL_BLOCK_HITSCAN))
{
int tf = tileflags(wal->overtexture);
if (tf & TFLAG_ANIMFORCEFIELD)
{
p->GetActor()->spr.extra -= 5;
p->hurt_delay = 16;
SetPlayerPal(p, PalEntry(32, 32, 0, 0));
p->vel.XY() = -p->GetActor()->spr.Angles.Yaw.ToVector() * 16;
S_PlayActorSound(DUKE_LONGTERM_PAIN, p->GetActor());
checkhitwall(p->GetActor(), wal, p->GetActor()->getPosWithOffsetZ() + p->GetActor()->spr.Angles.Yaw.ToVector() * 2);
}
else if (tf & TFLAG_FORCEFIELD)
{
p->hurt_delay = 26;
checkhitwall(p->GetActor(), wal, p->GetActor()->getPosWithOffsetZ() + p->GetActor()->spr.Angles.Yaw.ToVector() * 2);
}
}
2020-05-10 18:59:38 +00:00
}
//---------------------------------------------------------------------------
//
// taken out of checksectors to eliminate some gotos.
//
//---------------------------------------------------------------------------
void clearcameras(DukePlayer* p)
{
p->GetActor()->restorepos();
2022-01-21 00:04:08 +00:00
p->newOwner = nullptr;
updatesector(p->GetActor()->getPosWithOffsetZ(), &p->cursector);
2022-01-21 00:04:08 +00:00
DukeStatIterator it(STAT_ACTOR);
while (auto act = it.Next())
{
if ((act->flags2 & SFLAG2_CAMERA)) act->spr.yint = 0;
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void checksectors_d(int snum)
{
2022-09-13 22:11:16 +00:00
int i = -1;
DukePlayer* p;
2021-11-17 23:04:36 +00:00
walltype* hitscanwall;
2021-11-26 17:59:28 +00:00
HitInfo near;
p = getPlayer(snum);
auto pact = p->GetActor();
if (!p->insector()) return;
switch (p->cursector->lotag)
{
case 32767:
p->cursector->lotag = 0;
FTA(9, p);
2023-10-01 08:07:23 +00:00
Level.addSecret(snum);
SECRET_Trigger(sectindex(p->cursector));
return;
case -1:
p->cursector->lotag = 0;
2020-07-07 15:56:20 +00:00
setnextmap(false);
return;
case -2:
p->cursector->lotag = 0;
p->timebeforeexit = 26 * 8;
p->customexitsound = p->cursector->hitag;
return;
default:
if (p->cursector->lotag >= 10000 && p->cursector->lotag < 16383)
{
if (snum == screenpeek || ud.coop == 1)
S_PlayActorSound(p->cursector->lotag - 10000, pact);
p->cursector->lotag = 0;
}
break;
}
//After this point the the player effects the map with space
if (chatmodeon || p->GetActor()->spr.extra <= 0) return;
if (ud.cashman && PlayerInput(snum, SB_OPEN))
lotsofstuff(p->GetActor(), 2, DukeMailClass);
2020-11-02 23:20:51 +00:00
if (p->newOwner != nullptr)
{
if (abs(PlayerInputSideVel(snum)) > 0.75 || abs(PlayerInputForwardVel(snum)) > 0.75)
{
clearcameras(p);
return;
}
else if (PlayerInput(snum, SB_ESCAPE))
{
2022-01-21 00:04:08 +00:00
clearcameras(p);
return;
}
}
if (!(PlayerInput(snum, SB_OPEN)))
p->toggle_key_flag = 0;
else if (!p->toggle_key_flag)
{
2021-11-26 17:59:28 +00:00
near.hitActor = nullptr;
p->toggle_key_flag = 1;
2021-11-17 23:04:36 +00:00
hitscanwall = nullptr;
2022-09-13 22:20:58 +00:00
double dist = hitawall(p, &hitscanwall);
2021-11-17 23:04:36 +00:00
if (hitscanwall != nullptr)
2021-11-17 22:40:10 +00:00
{
if (dist < 80 && hitscanwall->overtexture == mirrortex)
2021-11-17 23:04:36 +00:00
if (hitscanwall->lotag > 0 && S_CheckSoundPlaying(hitscanwall->lotag) == 0 && snum == screenpeek)
2021-11-17 22:40:10 +00:00
{
2021-11-17 23:04:36 +00:00
S_PlayActorSound(hitscanwall->lotag, pact);
2021-11-17 22:40:10 +00:00
return;
}
if (hitscanwall != nullptr && (hitscanwall->cstat & CSTAT_WALL_MASKED))
2021-11-17 23:04:36 +00:00
if (hitscanwall->lotag)
2021-11-17 22:40:10 +00:00
return;
}
2020-11-02 23:20:51 +00:00
if (p->newOwner != nullptr)
neartag(p->GetActor()->getPrevPosWithOffsetZ(), p->GetActor()->sector(), p->GetActor()->PrevAngles.Yaw, near, 80., NT_Lotag);
else
{
neartag(p->GetActor()->getPosWithOffsetZ(), p->GetActor()->sector(), p->GetActor()->PrevAngles.Yaw, near, 80., NT_Lotag);
2021-11-26 17:59:28 +00:00
if (near.actor() == nullptr && near.hitWall == nullptr && near.hitSector == nullptr)
neartag(p->GetActor()->getPosWithOffsetZ().plusZ(8), p->GetActor()->sector(), p->GetActor()->PrevAngles.Yaw, near, 80., NT_Lotag);
2021-11-26 17:59:28 +00:00
if (near.actor() == nullptr && near.hitWall == nullptr && near.hitSector == nullptr)
neartag(p->GetActor()->getPosWithOffsetZ().plusZ(16), p->GetActor()->sector(), p->GetActor()->PrevAngles.Yaw, near, 80., NT_Lotag);
2021-11-26 17:59:28 +00:00
if (near.actor() == nullptr && near.hitWall == nullptr && near.hitSector == nullptr)
{
neartag(p->GetActor()->getPosWithOffsetZ().plusZ(16), p->GetActor()->sector(), p->GetActor()->PrevAngles.Yaw, near, 80., NT_Lotag | NT_Hitag);
2021-11-26 17:59:28 +00:00
if (near.actor() != nullptr)
{
if (near.actor()->flags2 & SFLAG2_TRIGGERRESPAWN)
return;
}
2021-11-26 17:59:28 +00:00
near.clearObj();
}
}
2021-11-26 17:59:28 +00:00
if (p->newOwner == nullptr && near.actor() == nullptr && near.hitWall == nullptr && near.hitSector == nullptr)
2021-11-20 23:33:17 +00:00
if (isanunderoperator(p->GetActor()->sector()->lotag))
near.hitSector = p->GetActor()->sector();
2021-11-26 17:59:28 +00:00
if (near.hitSector && (near.hitSector->lotag & 16384))
return;
2021-11-26 17:59:28 +00:00
if (near.actor() == nullptr && near.hitWall == nullptr)
if (p->cursector->lotag == ST_2_UNDERWATER)
{
DDukeActor* hit;
2022-09-13 22:30:08 +00:00
dist = hitasprite(p->GetActor(), &hit);
2021-11-26 17:59:28 +00:00
if (hit) near.hitActor = hit;
2022-09-13 22:11:16 +00:00
if (dist > 80) near.hitActor = nullptr;
}
2021-11-26 17:59:28 +00:00
auto const neartagsprite = near.actor();
2020-10-27 06:00:39 +00:00
if (neartagsprite != nullptr)
{
if (checkhitswitch(snum, nullptr, neartagsprite)) return;
if (CallOnUse(neartagsprite, p))
return;
2022-01-21 00:04:08 +00:00
}
if (!PlayerInput(snum, SB_OPEN)) return;
2022-01-21 00:04:08 +00:00
else if (p->newOwner != nullptr)
{
2022-01-21 00:04:08 +00:00
clearcameras(p);
return;
2022-01-21 00:04:08 +00:00
}
2021-11-26 17:59:28 +00:00
if (near.hitWall == nullptr && near.hitSector == nullptr && near.actor() == nullptr)
2022-09-13 22:05:32 +00:00
if (hits(p->GetActor()) < 32)
{
if ((krand() & 255) < 16)
S_PlayActorSound(DUKE_SEARCH2, pact);
else S_PlayActorSound(DUKE_SEARCH, pact);
return;
}
2021-11-26 17:59:28 +00:00
if (near.hitWall)
{
if (near.hitWall->lotag > 0 && isadoorwall(near.hitWall->walltexture))
{
2021-11-26 17:59:28 +00:00
if (hitscanwall == near.hitWall || hitscanwall == nullptr)
checkhitswitch(snum, near.hitWall, nullptr);
return;
}
2020-11-02 23:20:51 +00:00
else if (p->newOwner != nullptr)
{
2022-01-21 00:04:08 +00:00
clearcameras(p);
return;
}
}
2021-11-26 17:59:28 +00:00
if (near.hitSector && (near.hitSector->lotag & 16384) == 0 && isanearoperator(near.hitSector->lotag))
{
2021-11-26 17:59:28 +00:00
DukeSectIterator it(near.hitSector);
2020-11-02 18:41:06 +00:00
while (auto act = it.Next())
{
2022-11-20 11:43:24 +00:00
if (isactivator(act) || ismasterswitch(act))
return;
}
2021-11-26 17:59:28 +00:00
operatesectors(near.hitSector, p->GetActor());
}
2021-11-20 23:33:17 +00:00
else if ((p->GetActor()->sector()->lotag & 16384) == 0)
{
2021-11-20 23:33:17 +00:00
if (isanunderoperator(p->GetActor()->sector()->lotag))
{
DukeSectIterator it(p->GetActor()->sector());
2020-11-02 18:41:06 +00:00
while (auto act = it.Next())
{
2022-11-20 11:43:24 +00:00
if (isactivator(act) || ismasterswitch(act)) return;
}
operatesectors(p->GetActor()->sector(), p->GetActor());
}
else checkhitswitch(snum, near.hitWall, nullptr);
}
}
}
END_DUKE_NS