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

5287 lines
124 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
Copyright (C) 2017-2019 - Nuke.YKT
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.
This file is a combination of code from the following sources:
- EDuke 2 by Matt Saettler
- JFDuke by Jonathon Fowler (jf@jonof.id.au),
- DukeGDX and RedneckGDX by Alexander Makarov-[M210] (m210-2007@mail.ru)
- Redneck Rampage reconstructed source by Nuke.YKT
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "global.h"
#include "names.h"
2020-06-23 19:12:15 +00:00
#include "stats.h"
2020-07-06 11:26:26 +00:00
#include "constants.h"
2020-10-17 07:14:31 +00:00
#include "dukeactor.h"
BEGIN_DUKE_NS
double adjustfall(DDukeActor* actor, double c);
2020-05-14 07:07:07 +00:00
2020-06-30 15:30:48 +00:00
2020-07-06 11:26:26 +00:00
//---------------------------------------------------------------------------
//
// this was once a macro
//
//---------------------------------------------------------------------------
void RANDOMSCRAP(DDukeActor* origin)
2020-07-06 11:26:26 +00:00
{
2022-09-11 21:05:42 +00:00
int r1 = krand(), r2 = krand(), r3 = krand(), r4 = krand();
DVector3 offset;
offset.X = krandf(16) - 8;
offset.Y = krandf(16) - 8;
offset.Z = krandf(16) - 8;
2022-10-07 16:51:29 +00:00
double v = isRR() ? 0.125 : 0.375;
auto a = randomAngle();
auto vel = krandf(4) + 4;
auto zvel = -krandf(8) - 2;
2022-10-07 16:51:29 +00:00
CreateActor(origin->sector(), origin->spr.pos + offset, TILE_SCRAP6 + (r4 & 15), -8, DVector2(v, v), a, vel, zvel, origin, 5);
2020-07-06 11:26:26 +00:00
}
2020-06-30 15:30:48 +00:00
//---------------------------------------------------------------------------
//
// wrapper to ensure that if a sound actor is killed, the sound is stopped as well.
//
//---------------------------------------------------------------------------
void deletesprite(DDukeActor *const actor)
2020-06-30 15:30:48 +00:00
{
if (actor->spr.picnum == MUSICANDSFX && actor->temp_data[0] == 1)
S_StopSound(actor->spr.lotag, actor);
actor->Destroy();
2020-06-30 15:30:48 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-02-07 10:04:19 +00:00
void addammo(int weapon, player_struct* player, int amount)
{
2020-10-21 16:42:47 +00:00
player->ammo_amount[weapon] += amount;
if (player->ammo_amount[weapon] > gs.max_ammo_amount[weapon])
player->ammo_amount[weapon] = gs.max_ammo_amount[weapon];
2020-05-05 13:25:59 +00:00
}
2020-05-05 20:07:54 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-02-07 10:04:19 +00:00
void checkavailinven(player_struct* player)
2020-05-05 20:07:54 +00:00
{
2020-10-21 16:42:47 +00:00
if (player->firstaid_amount > 0)
player->inven_icon = ICON_FIRSTAID;
else if (player->steroids_amount > 0)
player->inven_icon = ICON_STEROIDS;
else if (player->holoduke_amount > 0)
player->inven_icon = ICON_HOLODUKE;
else if (player->jetpack_amount > 0)
player->inven_icon = ICON_JETPACK;
else if (player->heat_amount > 0)
player->inven_icon = ICON_HEATS;
else if (player->scuba_amount > 0)
player->inven_icon = ICON_SCUBA;
else if (player->boot_amount > 0)
player->inven_icon = ICON_BOOTS;
else player->inven_icon = ICON_NONE;
2020-05-05 20:07:54 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-02-07 10:04:19 +00:00
void checkavailweapon(player_struct* player)
2020-05-05 20:07:54 +00:00
{
int i, snum;
2020-05-05 20:07:54 +00:00
int weap;
2020-10-21 16:42:47 +00:00
if (player->wantweaponfire >= 0)
2020-05-05 20:07:54 +00:00
{
2020-10-21 16:42:47 +00:00
weap = player->wantweaponfire;
player->wantweaponfire = -1;
2020-05-05 20:07:54 +00:00
2020-10-21 16:42:47 +00:00
if (weap == player->curr_weapon) return;
else if (player->gotweapon[weap] && player->ammo_amount[weap] > 0)
2020-05-05 20:07:54 +00:00
{
2020-10-21 16:42:47 +00:00
fi.addweapon(player, weap);
2020-05-05 20:07:54 +00:00
return;
}
}
2020-10-21 16:42:47 +00:00
weap = player->curr_weapon;
if (player->gotweapon[weap] && player->ammo_amount[weap] > 0)
2020-05-05 20:07:54 +00:00
return;
2020-10-21 16:42:47 +00:00
snum = player->GetPlayerNum();
2020-05-05 20:07:54 +00:00
int max = MAX_WEAPON;
for (i = 0; i <= max; i++)
2020-05-05 20:07:54 +00:00
{
weap = ud.wchoice[snum][i];
if ((g_gameType & GAMEFLAG_SHAREWARE) && weap > 6) continue;
if (weap == 0) weap = max;
else weap--;
2020-10-21 16:42:47 +00:00
if (weap == MIN_WEAPON || (player->gotweapon[weap] && player->ammo_amount[weap] > 0))
2020-05-05 20:07:54 +00:00
break;
}
if (i == MAX_WEAPON) weap = MIN_WEAPON;
2020-05-05 20:07:54 +00:00
// Found the weapon
2020-10-21 16:42:47 +00:00
player->last_weapon = player->curr_weapon;
player->random_club_frame = 0;
player->curr_weapon = weap;
if (isWW2GI())
2020-05-05 20:07:54 +00:00
{
2021-08-30 06:07:40 +00:00
SetGameVarID(g_iWeaponVarID, player->curr_weapon, player->GetActor(), snum); // snum is player index!
2020-10-21 16:42:47 +00:00
if (player->curr_weapon >= 0)
2020-05-05 20:07:54 +00:00
{
SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(player->curr_weapon, snum), player->GetActor(), snum);
2020-05-05 20:07:54 +00:00
}
else
{
2020-10-21 16:42:47 +00:00
SetGameVarID(g_iWorksLikeVarID, -1, player->GetActor(), snum);
2020-05-05 20:07:54 +00:00
}
OnEvent(EVENT_CHANGEWEAPON, snum, player->GetActor(), -1);
2020-05-05 20:07:54 +00:00
}
2020-10-21 16:42:47 +00:00
player->okickback_pic = player->kickback_pic = 0;
if (player->holster_weapon == 1)
2020-05-05 20:07:54 +00:00
{
2020-10-21 16:42:47 +00:00
player->holster_weapon = 0;
player->weapon_pos = 10;
2020-05-05 20:07:54 +00:00
}
2020-10-21 16:42:47 +00:00
else player->weapon_pos = -1;
2020-05-05 20:07:54 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void clearcamera(player_struct* ps)
{
2020-11-02 23:20:51 +00:00
ps->newOwner = nullptr;
ps->restorexyz();
ps->angle.restore();
2022-02-05 12:32:34 +00:00
updatesector(ps->pos, &ps->cursector);
2020-10-21 17:38:53 +00:00
DukeStatIterator it(STAT_ACTOR);
while (auto k = it.Next())
{
2022-01-21 00:04:08 +00:00
if (actorflag(k, SFLAG2_CAMERA))
k->spr.yint = 0;
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 17:38:53 +00:00
int ssp(DDukeActor* const actor, unsigned int cliptype) //The set sprite function
{
Collision c;
2022-09-03 16:41:25 +00:00
return movesprite_ex(actor, DVector3(actor->spr.angle.ToVector() * actor->vel.X, actor->vel.Z), cliptype, c) == kHitNone;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void insertspriteq(DDukeActor* const actor)
{
if (spriteqamount > 0)
{
if (spriteq[spriteqloc] != nullptr)
{
// todo: Make list size a CVAR.
deletesprite(spriteq[spriteqloc]);
}
spriteq[spriteqloc] = actor;
spriteqloc = (spriteqloc + 1) % spriteqamount;
}
else actor->spr.SetScale(0, 0);
}
//---------------------------------------------------------------------------
//
// consolidation of several nearly identical functions
//
//---------------------------------------------------------------------------
void lotsofstuff(DDukeActor* actor, int n, int spawntype)
{
for (int i = n; i > 0; i--)
{
DAngle r1 = randomAngle();
2022-02-12 11:37:27 +00:00
double r2 = zrand(47);
2022-10-07 16:51:29 +00:00
auto j = CreateActor(actor->sector(), actor->spr.pos.plusZ(-r2), spawntype, -32, DVector2(0.125, 0.125), r1, 0., 0., actor, 5);
if (j) j->spr.cstat = randomFlip();
}
}
//---------------------------------------------------------------------------
//
2022-09-11 16:41:52 +00:00
// movesector - used by sector effectors
//
//---------------------------------------------------------------------------
void movesector(DDukeActor* const actor, int msindex, DAngle rotation)
{
//T1,T2 and T3 are used for all the sector moving stuff!!!
actor->spr.pos.X += actor->vel.X * actor->spr.angle.Cos();
actor->spr.pos.Y += actor->vel.X * actor->spr.angle.Sin();
for(auto& wal : wallsofsector(actor->sector()))
{
auto t = rotatepoint({ 0, 0 }, mspos[msindex], rotation);
dragpoint(&wal, actor->spr.pos.XY() + t);
msindex++;
}
}
2020-05-06 19:11:36 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movecyclers(void)
{
2021-05-11 22:48:41 +00:00
for (int q = numcyclers - 1; q >= 0; q--)
2020-05-06 19:11:36 +00:00
{
Cycler* c = &cyclers[q];
auto sect = c->sector;
2020-05-06 19:11:36 +00:00
int shade = c->shade2;
int j = shade + int(BobVal(c->lotag) * 16);
int cshade = c->shade1;
2020-05-06 19:11:36 +00:00
if (j < cshade) j = cshade;
else if (j > shade) j = shade;
2020-05-06 19:11:36 +00:00
c->lotag += sect->extra;
if (c->state)
2020-05-06 19:11:36 +00:00
{
for (auto& wal : wallsofsector(sect))
{
if (wal.hitag != 1)
2020-05-06 19:11:36 +00:00
{
wal.shade = j;
2020-05-06 19:11:36 +00:00
if ((wal.cstat & CSTAT_WALL_BOTTOM_SWAP) && wal.twoSided())
wal.nextWall()->shade = j;
2020-05-06 19:11:36 +00:00
}
}
sect->floorshade = sect->ceilingshade = j;
2020-05-06 19:11:36 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movedummyplayers(void)
{
int p;
2020-05-06 19:11:36 +00:00
DukeStatIterator iti(STAT_DUMMYPLAYER);
while (auto act = iti.Next())
2020-05-06 19:11:36 +00:00
{
if (!act->GetOwner()) continue;
p = act->GetOwner()->PlayerIndex();
2020-05-06 19:11:36 +00:00
if ((!isRR() && ps[p].on_crane != nullptr) || !ps[p].insector() || ps[p].cursector->lotag != 1 || ps->GetActor()->spr.extra <= 0)
2020-05-06 19:11:36 +00:00
{
2020-10-25 06:21:33 +00:00
ps[p].dummyplayersprite = nullptr;
deletesprite(act);
2020-05-06 19:11:36 +00:00
continue;
}
else
{
if (ps[p].on_ground && ps[p].on_warping_sector == 1 && ps[p].cursector->lotag == 1)
2020-05-06 19:11:36 +00:00
{
act->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2022-08-20 16:56:13 +00:00
act->spr.pos.Z = act->sector()->ceilingz + 27;
act->spr.angle = ps[p].angle.ang;
2020-10-24 08:13:21 +00:00
if (act->temp_data[0] == 8)
act->temp_data[0] = 0;
else act->temp_data[0]++;
2020-05-06 19:11:36 +00:00
}
else
{
2022-08-20 16:56:13 +00:00
if (act->sector()->lotag != 2) act->spr.pos.Z = act->sector()->floorz;
act->spr.cstat = CSTAT_SPRITE_INVISIBLE;
2020-05-06 19:11:36 +00:00
}
}
2022-02-05 12:32:34 +00:00
act->spr.pos.X += (ps[p].pos.X - ps[p].opos.X);
act->spr.pos.Y += (ps[p].pos.Y - ps[p].opos.Y);
2022-02-06 20:11:08 +00:00
SetActor(act, act->spr.pos);
2020-05-06 19:11:36 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void moveplayers(void)
2020-05-06 19:11:36 +00:00
{
double other;
2020-05-06 19:11:36 +00:00
DukeStatIterator iti(STAT_PLAYER);
while (auto act = iti.Next())
2020-05-06 19:11:36 +00:00
{
int pn = act->PlayerIndex();
auto p = &ps[pn];
if (act->GetOwner())
2020-05-06 19:11:36 +00:00
{
2020-11-02 23:20:51 +00:00
if (p->newOwner != nullptr) //Looking thru the camera
2020-05-06 19:11:36 +00:00
{
2022-02-06 19:02:58 +00:00
act->spr.pos = p->opos.plusZ(gs.playerheight);
act->backupz();
2022-08-28 22:02:17 +00:00
act->spr.angle = p->angle.oang;
2022-02-06 20:11:08 +00:00
SetActor(act, act->spr.pos);
2020-05-06 19:11:36 +00:00
}
else
{
if (ud.multimode > 1)
otherp = findotherplayer(pn, &other);
2020-05-06 19:11:36 +00:00
else
{
otherp = pn;
other = 0;
2020-05-06 19:11:36 +00:00
}
execute(act, pn, other);
2020-05-06 19:11:36 +00:00
if (ud.multimode > 1)
{
auto psp = ps[otherp].GetActor();
if (psp->spr.extra > 0)
2020-05-06 19:11:36 +00:00
{
if (act->spr.ScaleY() > 0.5 && psp->spr.ScaleY() < 0.5)
2020-05-06 19:11:36 +00:00
{
if (other < 1400/16. && p->knee_incs == 0)
2020-05-06 19:11:36 +00:00
{
p->knee_incs = 1;
p->weapon_pos = -1;
p->actorsqu = ps[otherp].GetActor();
2020-05-06 19:11:36 +00:00
}
}
}
}
2020-05-06 19:11:36 +00:00
if (ud.god)
{
act->spr.extra = gs.max_player_health;
act->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2020-05-06 19:11:36 +00:00
if (!isWW2GI() && !isRR())
p->jetpack_amount = 1599;
}
if (p->actorsqu != nullptr)
{
p->angle.addadjustment(deltaangle(p->angle.ang, (p->actorsqu->spr.pos - p->pos).Angle()) * 0.25);
}
if (act->spr.extra > 0)
2020-05-06 19:11:36 +00:00
{
// currently alive...
act->SetHitOwner(act);
2020-05-06 19:11:36 +00:00
if (ud.god == 0)
if (fi.ceilingspace(act->sector()) || fi.floorspace(act->sector()))
2020-05-06 19:11:36 +00:00
quickkill(p);
}
else
{
2022-02-05 12:32:34 +00:00
p->pos = act->spr.pos.plusZ(-28);
2020-11-02 23:20:51 +00:00
p->newOwner = nullptr;
if (p->wackedbyactor != nullptr && p->wackedbyactor->spr.statnum < MAXSTATUS)
{
p->angle.addadjustment(deltaangle(p->angle.ang, (p->wackedbyactor->spr.pos - p->pos).Angle()) * 0.5);
}
2020-05-06 19:11:36 +00:00
}
2022-08-28 22:02:17 +00:00
act->spr.angle = p->angle.ang;
2020-05-06 19:11:36 +00:00
}
}
else
{
if (p->holoduke_on == nullptr)
2020-05-06 19:11:36 +00:00
{
deletesprite(act);
2020-05-06 19:11:36 +00:00
continue;
}
act->spr.cstat = 0;
2020-05-06 19:11:36 +00:00
if (act->spr.ScaleX() < 0.65625)
2020-05-06 19:11:36 +00:00
{
act->spr.AddScaleX(0.0625);
act->spr.cstat |= CSTAT_SPRITE_TRANSLUCENT;
2020-05-06 19:11:36 +00:00
}
else act->spr.SetScaleX(0.65625);
if (act->spr.ScaleY() < 0.5625)
act->spr.AddScaleY(4);
2020-05-06 19:11:36 +00:00
else
{
act->spr.SetScaleY(0.5625);
if (act->sector()->lotag != ST_2_UNDERWATER)
makeitfall(act);
if (act->vel.Z == 0 && act->sector()->lotag == ST_1_ABOVE_WATER)
act->spr.pos.Z += 32;
2020-05-06 19:11:36 +00:00
}
if (act->spr.extra < 8)
2020-05-06 19:11:36 +00:00
{
2022-09-03 08:05:20 +00:00
act->vel.X = 8;
2022-08-28 22:02:17 +00:00
act->spr.angle = p->angle.ang;
act->spr.extra++;
ssp(act, CLIPMASK0);
2020-05-06 19:11:36 +00:00
}
else
{
act->spr.angle = DAngle360 - minAngle - p->angle.ang;
2022-02-06 20:11:08 +00:00
SetActor(act, act->spr.pos);
2020-05-06 19:11:36 +00:00
}
}
if (act->insector())
{
if (act->sector()->ceilingstat & CSTAT_SECTOR_SKY)
act->spr.shade += (act->sector()->ceilingshade - act->spr.shade) >> 1;
else
act->spr.shade += (act->sector()->floorshade - act->spr.shade) >> 1;
}
2020-05-06 19:11:36 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movefx(void)
{
int p;
DukeStatIterator iti(STAT_FX);
while (auto act = iti.Next())
{
switch (act->spr.picnum)
{
case RESPAWN:
if (act->spr.extra == 66)
{
auto j = spawn(act, act->spr.hitag);
if (isRRRA() && j)
{
respawn_rrra(act, j);
}
else
{
deletesprite(act);
}
}
else if (act->spr.extra > (66 - 13))
act->spr.extra++;
break;
case MUSICANDSFX:
{
2022-09-15 16:15:41 +00:00
double maxdist = act->spr.hitag * maptoworld;
if (act->temp_data[1] != (int)SoundEnabled())
{
act->temp_data[1] = SoundEnabled();
act->temp_data[0] = 0;
}
if (act->spr.lotag >= 1000 && act->spr.lotag < 2000)
{
double dist = (ps[screenpeek].GetActor()->spr.pos.XY() - act->spr.pos.XY()).Length();
if (dist < maxdist && act->temp_data[0] == 0)
{
FX_SetReverb(act->spr.lotag - 1100);
act->temp_data[0] = 1;
}
if (dist >= maxdist && act->temp_data[0] == 1)
{
FX_SetReverb(0);
FX_SetReverbDelay(0);
act->temp_data[0] = 0;
}
}
2022-08-20 18:11:01 +00:00
else if (act->spr.lotag < 999 && (unsigned)act->sector()->lotag < ST_9_SLIDING_ST_DOOR && snd_ambience && act->sector()->floorz != act->sector()->ceilingz)
{
int flags = S_GetUserFlags(act->spr.lotag);
if (flags & SF_MSFX)
{
double distance = (ps[screenpeek].GetActor()->spr.pos - act->spr.pos).Length();
if (distance < maxdist && act->temp_data[0] == 0)
{
// Start playing an ambience sound.
S_PlayActorSound(act->spr.lotag, act, CHAN_AUTO, CHANF_LOOP);
act->temp_data[0] = 1; // AMBIENT_SFX_PLAYING
}
else if (distance >= maxdist && act->temp_data[0] == 1)
{
// Stop playing ambience sound because we're out of its range.
S_StopSound(act->spr.lotag, act);
}
}
if ((flags & (SF_GLOBAL | SF_DTAG)) == SF_GLOBAL)
{
if (act->temp_data[4] > 0) act->temp_data[4]--;
else for (p = connecthead; p >= 0; p = connectpoint2[p])
if (p == myconnectindex && ps[p].cursector == act->sector())
{
S_PlaySound(act->spr.lotag + (unsigned)global_random % (act->spr.hitag + 1));
act->temp_data[4] = 26 * 40 + (global_random % (26 * 40));
}
}
}
break;
}
}
}
}
//---------------------------------------------------------------------------
//
// split out of movestandables
//
//---------------------------------------------------------------------------
2020-10-24 08:37:20 +00:00
void movecrane(DDukeActor *actor, int crane)
{
2022-02-05 12:32:34 +00:00
const double CRANE_STEP = 16.;
auto sectp = actor->sector();
double xx;
auto& cpt = cranes[actor->temp_data[4]];
//actor->temp_data[0] = state
//actor->temp_data[1] = checking sector number
if(actor->vel.X != 0) getglobalz(actor);
if (actor->temp_data[0] == 0) //Waiting to check the sector
{
DukeSectIterator it(actor->temp_sect);
2020-10-24 08:37:20 +00:00
while (auto a2 = it.Next())
{
switch (a2->spr.statnum)
{
case STAT_ACTOR:
case STAT_ZOMBIEACTOR:
case STAT_STANDABLE:
case STAT_PLAYER:
actor->spr.angle = (cpt.pole - actor->spr.pos.XY()).Angle();
2022-02-07 10:00:15 +00:00
SetActor(a2, DVector3( cpt.pole.X, cpt.pole.Y, a2->spr.pos.Z ));
actor->temp_data[0]++;
return;
}
}
}
else if (actor->temp_data[0] == 1)
{
2022-09-14 17:29:29 +00:00
if (actor->vel.X < 11.5)
{
actor->spr.picnum = crane + 1;
2022-09-03 08:05:20 +00:00
actor->vel.X += 0.5;
}
//IFMOVING; // JBF 20040825: see my rant above about this
2020-10-24 08:37:20 +00:00
ssp(actor, CLIPMASK0);
if (actor->sector() == actor->temp_sect)
actor->temp_data[0]++;
}
else if (actor->temp_data[0] == 2 || actor->temp_data[0] == 7)
{
actor->spr.pos.Z += 6;
if (actor->temp_data[0] == 2)
{
2022-02-06 20:11:08 +00:00
if ((sectp->floorz - actor->spr.pos.Z) < 64)
if (actor->spr.picnum > crane) actor->spr.picnum--;
2022-02-06 20:11:08 +00:00
if ((sectp->floorz - actor->spr.pos.Z) < 20)
actor->temp_data[0]++;
}
if (actor->temp_data[0] == 7)
{
2022-02-06 20:11:08 +00:00
if ((sectp->floorz - actor->spr.pos.Z) < 64)
{
if (actor->spr.picnum > crane) actor->spr.picnum--;
else
{
2020-10-24 08:37:20 +00:00
if (actor->IsActiveCrane())
{
int p = findplayer(actor, &xx);
2020-10-24 08:37:20 +00:00
S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].GetActor());
if (ps[p].on_crane == actor)
2020-10-17 08:44:00 +00:00
ps[p].on_crane = nullptr;
}
actor->temp_data[0]++;
actor->SetActiveCrane(false);
}
}
}
}
else if (actor->temp_data[0] == 3)
{
actor->spr.picnum++;
if (actor->spr.picnum == (crane + 2))
{
int p = checkcursectnums(actor->temp_sect);
if (p >= 0 && ps[p].on_ground)
{
2020-10-24 08:37:20 +00:00
actor->SetActiveCrane(true);
ps[p].on_crane = actor;
S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].GetActor());
ps[p].angle.settarget(actor->spr.angle + DAngle180);
}
else
{
DukeSectIterator it(actor->temp_sect);
2020-10-24 08:37:20 +00:00
while (auto a2 = it.Next())
{
switch (a2->spr.statnum)
{
case 1:
case 6:
2020-10-24 08:37:20 +00:00
actor->SetOwner(a2);
break;
}
}
}
actor->temp_data[0]++;//Grabbed the sprite
actor->temp_data[2] = 0;
return;
}
}
else if (actor->temp_data[0] == 4) //Delay before going up
{
actor->temp_data[2]++;
if (actor->temp_data[2] > 10)
actor->temp_data[0]++;
}
else if (actor->temp_data[0] == 5 || actor->temp_data[0] == 8)
{
if (actor->temp_data[0] == 8 && actor->spr.picnum < (crane + 2))
2022-02-06 20:11:08 +00:00
if ((sectp->floorz - actor->spr.pos.Z) > 32)
actor->spr.picnum++;
2022-02-07 10:00:15 +00:00
if (actor->spr.pos.Z < cpt.pos.Z)
{
actor->temp_data[0]++;
2022-09-03 08:02:25 +00:00
actor->vel.X = 0;
}
else
2022-02-06 20:11:08 +00:00
actor->spr.pos.Z -= 6;
}
else if (actor->temp_data[0] == 6)
{
2022-09-14 17:29:29 +00:00
if (actor->vel.X < 12)
2022-09-03 08:05:20 +00:00
actor->vel.X += 0.5;
actor->spr.angle = (cpt.pos.XY() - actor->spr.pos.XY()).Angle();
2020-10-24 08:37:20 +00:00
ssp(actor, CLIPMASK0);
2022-02-07 10:00:15 +00:00
if (((actor->spr.pos.X - cpt.pos.X) * (actor->spr.pos.X - cpt.pos.X) + (actor->spr.pos.Y - cpt.pos.Y) * (actor->spr.pos.Y - cpt.pos.Y)) < (8 * 8))
actor->temp_data[0]++;
}
else if (actor->temp_data[0] == 9)
actor->temp_data[0] = 0;
if (cpt.poleactor)
SetActor(cpt.poleactor, actor->spr.pos.plusZ(-34));
2020-10-24 08:37:20 +00:00
auto Owner = actor->GetOwner();
if (Owner != nullptr || actor->IsActiveCrane())
{
int p = findplayer(actor, &xx);
int j = fi.ifhitbyweapon(actor);
if (j >= 0)
{
2020-10-24 08:37:20 +00:00
if (actor->IsActiveCrane())
if (ps[p].on_crane == actor)
2020-10-17 08:44:00 +00:00
ps[p].on_crane = nullptr;
2020-10-24 08:37:20 +00:00
actor->SetActiveCrane(false);
actor->spr.picnum = crane;
return;
}
if (Owner != nullptr)
{
2022-02-06 20:11:08 +00:00
SetActor(Owner, actor->spr.pos);
2022-02-03 21:06:09 +00:00
Owner->opos = actor->spr.pos;
2022-09-03 08:02:25 +00:00
actor->vel.Z = 0;
}
2020-10-24 08:37:20 +00:00
else if (actor->IsActiveCrane())
{
auto ang = ps[p].angle.ang;
ps[p].backupxyz();
2022-08-29 20:59:44 +00:00
ps[p].pos.XY() = actor->spr.pos.XY() - CRANE_STEP * ang.ToVector();
2022-02-05 12:32:34 +00:00
ps[p].pos.Z = actor->spr.pos.Z + 2;
SetActor(ps[p].GetActor(), ps[p].pos);
ps[p].setCursector(ps[p].GetActor()->sector());
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movefountain(DDukeActor *actor, int fountain)
{
if (actor->temp_data[0] > 0)
{
if (actor->temp_data[0] < 20)
{
actor->temp_data[0]++;
actor->spr.picnum++;
if (actor->spr.picnum == fountain + 3)
actor->spr.picnum = fountain + 1;
}
else
{
double x;
findplayer(actor, &x);
if (x > 32)
{
actor->temp_data[0] = 0;
actor->spr.picnum = fountain;
}
else actor->temp_data[0] = 1;
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-01-26 23:41:33 +00:00
void moveflammable(DDukeActor* actor, int pool)
{
double scale;
2020-10-24 20:18:05 +00:00
if (actor->temp_data[0] == 1)
{
2020-10-24 20:18:05 +00:00
actor->temp_data[1]++;
if ((actor->temp_data[1] & 3) > 0) return;
if (actorflag(actor, SFLAG_FLAMMABLEPOOLEFFECT) && actor->temp_data[1] == 32)
{
actor->spr.cstat = 0;
auto spawned = spawn(actor, pool);
2022-01-26 23:41:33 +00:00
if (spawned)
{
spawned->spr.pal = 2;
spawned->spr.shade = 127;
}
}
else
{
if (actor->spr.shade < 64) actor->spr.shade++;
else
{
deletesprite(actor);
return;
}
}
scale = actor->spr.ScaleX() - (krand() & 7) * REPEAT_SCALE;
if (scale < 0.15625)
{
deletesprite(actor);
return;
}
actor->spr.SetScaleX(scale);
scale = actor->spr.ScaleY() - (krand() & 7) * REPEAT_SCALE;
if (scale < 0.0625)
{
deletesprite(actor);
return;
}
actor->spr.SetScaleY(scale);
}
2022-01-26 23:41:33 +00:00
if (actorflag(actor, SFLAG_FALLINGFLAMMABLE))
{
makeitfall(actor);
actor->ceilingz = actor->sector()->ceilingz;
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void detonate(DDukeActor *actor, int explosion)
{
earthquaketime = 16;
DukeStatIterator itj(STAT_EFFECTOR);
while (auto effector = itj.Next())
{
if (actor->spr.hitag == effector->spr.hitag)
{
if (effector->spr.lotag == SE_13_EXPLOSIVE)
{
if (effector->temp_data[2] == 0)
effector->temp_data[2] = 1;
}
else if (effector->spr.lotag == SE_8_UP_OPEN_DOOR_LIGHTS)
effector->temp_data[4] = 1;
else if (effector->spr.lotag == SE_18_INCREMENTAL_SECTOR_RISE_FALL)
{
if (effector->temp_data[0] == 0)
effector->temp_data[0] = 1;
}
else if (effector->spr.lotag == SE_21_DROP_FLOOR)
effector->temp_data[0] = 1;
}
}
actor->spr.pos.Z -= 32;
if ((actor->temp_data[3] == 1 && actor->spr.ScaleX() != 0) || actor->spr.lotag == -99)
{
int x = actor->spr.extra;
spawn(actor, explosion);
fi.hitradius(actor, gs.seenineblastradius, x >> 2, x - (x >> 1), x - (x >> 2), x);
S_PlayActorSound(PIPEBOMB_EXPLODE, actor);
}
if (actor->spr.ScaleX() != 0)
for (int x = 0; x < 8; x++) RANDOMSCRAP(actor);
deletesprite(actor);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movemasterswitch(DDukeActor *actor)
{
if (actor->spr.yint == 1)
{
actor->spr.hitag--;
if (actor->spr.hitag <= 0)
{
operatesectors(actor->sector(), actor);
DukeSectIterator it(actor->sector());
while (auto effector = it.Next())
{
if (effector->spr.statnum == STAT_EFFECTOR)
{
switch (effector->spr.lotag)
{
case SE_2_EARTHQUAKE:
case SE_21_DROP_FLOOR:
case SE_31_FLOOR_RISE_FALL:
case SE_32_CEILING_RISE_FALL:
case SE_36_PROJ_SHOOTER:
effector->temp_data[0] = 1;
break;
case SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT:
effector->temp_data[4] = 1;
break;
}
}
else if (effector->spr.statnum == STAT_STANDABLE)
{
2022-01-20 07:31:08 +00:00
if (actorflag(effector, SFLAG2_BRIGHTEXPLODE)) // _SEENINE_ and _OOZFILTER_
{
effector->spr.shade = -31;
}
}
}
// we cannot delete this because it may be used as a sound source.
// This originally depended on undefined behavior as the deleted sprite was still used for the sound
// with no checking if it got reused in the mean time.
actor->spr.picnum = 0; // give it a picnum without any behavior attached, just in case
actor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
actor->spr.cstat2 |= CSTAT2_SPRITE_NOFIND;
ChangeActorStat(actor, STAT_REMOVED);
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:17:25 +00:00
void movetrash(DDukeActor *actor)
{
2022-09-11 20:57:56 +00:00
if (actor->vel.X == 0) actor->vel.X = 1 / 16.;
2020-10-21 20:17:25 +00:00
if (ssp(actor, CLIPMASK0))
{
2020-10-21 20:17:25 +00:00
makeitfall(actor);
2022-09-11 17:28:45 +00:00
if (krand() & 1) actor->vel.Z -= 1;
2022-09-11 20:57:56 +00:00
if (abs(actor->vel.X) < 3)
actor->vel.X += (krand() & 3) / 16.;
}
2020-10-21 20:17:25 +00:00
else deletesprite(actor);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:17:25 +00:00
void movewaterdrip(DDukeActor *actor, int drip)
{
if (actor->temp_data[1])
{
actor->temp_data[1]--;
if (actor->temp_data[1] == 0)
actor->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE;
}
else
{
2020-10-21 20:17:25 +00:00
makeitfall(actor);
ssp(actor, CLIPMASK0);
2022-09-11 17:28:45 +00:00
if(actor->vel.X > 0) actor->vel.X -= 1/8.;
if (actor->vel.Z == 0)
{
actor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
if (actor->spr.pal != 2 && (isRR() || actor->spr.hitag == 0))
2020-10-21 20:17:25 +00:00
S_PlayActorSound(SOMETHING_DRIPPING, actor);
2020-10-21 20:17:25 +00:00
auto Owner = actor->GetOwner();
if (!Owner || Owner->spr.picnum != drip)
{
2020-10-21 20:17:25 +00:00
deletesprite(actor);
}
else
{
actor->spr.pos.Z = actor->temp_pos.Z;
actor->backupz();
actor->temp_data[1] = 48 + (krand() & 31);
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:17:25 +00:00
void movedoorshock(DDukeActor* actor)
{
auto sectp = actor->sector();
2022-10-05 22:08:51 +00:00
double j = abs(sectp->ceilingz - sectp->floorz) / 128.;
actor->spr.SetScale(0.25, 0.0625 + j);
2022-08-20 16:56:13 +00:00
actor->spr.pos.Z = sectp->floorz;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movetouchplate(DDukeActor* actor, int plate)
{
auto sectp = actor->sector();
int p;
if (actor->temp_data[1] == 1 && actor->spr.hitag >= 0) //Move the sector floor
{
2022-09-11 21:16:06 +00:00
double X = sectp->floorz;
double add = sectp->extra * zmaptoworld;
if (actor->temp_data[3] == 1)
{
2022-09-11 21:16:06 +00:00
if (X >= actor->temp_pos.Z)
{
2022-09-11 21:16:06 +00:00
sectp->setfloorz(X);
actor->temp_data[1] = 0;
}
else
{
2022-09-11 21:16:06 +00:00
sectp->addfloorz(add);
p = checkcursectnums(actor->sector());
2022-09-11 21:16:06 +00:00
if (p >= 0) ps[p].pos.Z += add;
}
}
else
{
2022-09-11 21:16:06 +00:00
if (X <= actor->spr.pos.Z)
{
2022-02-06 20:11:08 +00:00
sectp->setfloorz(actor->spr.pos.Z);
actor->temp_data[1] = 0;
}
else
{
2022-09-11 21:16:06 +00:00
sectp->floorz -= add;
p = checkcursectnums(actor->sector());
if (p >= 0)
2022-09-11 21:16:06 +00:00
ps[p].pos.Z -= add;
}
}
return;
}
if (actor->temp_data[5] == 1) return;
p = checkcursectnums(actor->sector());
2022-09-11 21:16:06 +00:00
if (p >= 0 && (ps[p].on_ground || actor->spr.intangle == 512))
{
if (actor->temp_data[0] == 0 && !check_activator_motion(actor->spr.lotag))
{
actor->temp_data[0] = 1;
actor->temp_data[1] = 1;
actor->temp_data[3] = !actor->temp_data[3];
operatemasterswitches(actor->spr.lotag);
operateactivators(actor->spr.lotag, p);
if (actor->spr.hitag > 0)
{
actor->spr.hitag--;
if (actor->spr.hitag == 0) actor->temp_data[5] = 1;
}
}
}
else actor->temp_data[0] = 0;
if (actor->temp_data[1] == 1)
{
DukeStatIterator it(STAT_STANDABLE);
while (auto act2 = it.Next())
{
if (act2 != actor && act2->spr.picnum == plate && act2->spr.lotag == actor->spr.lotag)
{
act2->temp_data[1] = 1;
act2->temp_data[3] = actor->temp_data[3];
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void moveooz(DDukeActor* actor, int seenine, int seeninedead, int ooz, int explosion)
{
int j;
if (actor->spr.shade != -32 && actor->spr.shade != -33)
{
if (actor->spr.ScaleX() != 0)
j = (fi.ifhitbyweapon(actor) >= 0);
else
j = 0;
if (j || actor->spr.shade == -31)
{
if (j) actor->spr.lotag = 0;
actor->temp_data[3] = 1;
DukeStatIterator it(STAT_STANDABLE);
while (auto act2 = it.Next())
{
2022-01-20 07:31:08 +00:00
if (actor->spr.hitag == act2->spr.hitag && actorflag(act2, SFLAG2_BRIGHTEXPLODE))
act2->spr.shade = -32;
}
}
}
else
{
if (actor->spr.shade == -32)
{
if (actor->spr.lotag > 0)
{
actor->spr.lotag -= 3;
if (actor->spr.lotag <= 0) actor->spr.lotag = -99;
}
else
actor->spr.shade = -33;
}
else
{
if (actor->spr.ScaleX() > 0)
{
actor->temp_data[2]++;
if (actor->temp_data[2] == 3)
{
if (actor->spr.picnum == ooz)
{
actor->temp_data[2] = 0;
detonate(actor, explosion);
return;
}
if (actor->spr.picnum != (seeninedead + 1))
{
actor->temp_data[2] = 0;
if (actor->spr.picnum == seeninedead) actor->spr.picnum++;
else if (actor->spr.picnum == seenine)
actor->spr.picnum = seeninedead;
}
else
{
detonate(actor, explosion);
return;
}
}
return;
}
detonate(actor, explosion);
return;
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movecanwithsomething(DDukeActor* actor)
{
makeitfall(actor);
int j = fi.ifhitbyweapon(actor);
if (j >= 0)
{
S_PlayActorSound(VENT_BUST, actor);
for (j = 0; j < 10; j++)
RANDOMSCRAP(actor);
if (actor->spr.lotag) spawn(actor, actor->spr.lotag);
deletesprite(actor);
}
}
2020-05-07 12:38:01 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:29:35 +00:00
void bounce(DDukeActor* actor)
2020-05-07 12:38:01 +00:00
{
2022-09-14 17:02:29 +00:00
DVector3 vect(actor->spr.angle.ToVector() * actor->vel.X, actor->vel.Z);
2020-05-07 12:38:01 +00:00
auto sectp = actor->sector();
2020-05-07 12:38:01 +00:00
DAngle daang = sectp->firstWall()->delta().Angle();
2020-05-07 12:38:01 +00:00
2022-09-14 17:02:29 +00:00
double k;
2022-02-03 23:45:24 +00:00
if (actor->spr.pos.Z < (actor->floorz + actor->ceilingz) * 0.5)
2022-09-14 17:02:29 +00:00
k = sectp->ceilingheinum / 16.;
2020-05-07 12:38:01 +00:00
else
2022-09-14 17:02:29 +00:00
k = sectp->floorheinum / 16.;
2020-05-07 12:38:01 +00:00
2022-09-14 17:02:29 +00:00
DVector3 davec(daang.Sin() * k, -daang.Cos() * k, 16);
2020-05-07 12:38:01 +00:00
2022-09-14 17:02:29 +00:00
double dot = vect.dot(davec);
double l = davec.LengthSquared();
const double scale = 1; // still need to figure out.
if ((abs(dot) * scale) < l)
2020-05-07 12:38:01 +00:00
{
2022-09-14 17:02:29 +00:00
k = k * l / 8.; // Guessed by '<< (17-14)'
vect -= davec * k;
2020-05-07 12:38:01 +00:00
}
2022-09-14 17:02:29 +00:00
actor->vel.Z = vect.Z;
actor->vel.X = vect.XY().Length();
actor->spr.angle = vect.Angle();
2020-05-07 12:38:01 +00:00
}
//---------------------------------------------------------------------------
//
// taken out of moveweapon
2020-05-07 12:38:01 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 20:29:35 +00:00
void movetongue(DDukeActor *actor, int tongue, int jaw)
2020-05-07 12:38:01 +00:00
{
actor->temp_data[0] = int(BobVal(actor->temp_data[1]) * 32);
2020-10-21 20:29:35 +00:00
actor->temp_data[1] += 32;
if (actor->temp_data[1] > 2047)
2020-05-07 12:38:01 +00:00
{
2020-10-21 20:29:35 +00:00
deletesprite(actor);
2020-05-07 12:38:01 +00:00
return;
}
2020-10-21 20:29:35 +00:00
auto Owner = actor->GetOwner();
if (!Owner) return;
if (Owner->spr.statnum == MAXSTATUS)
2020-10-21 20:29:35 +00:00
if (badguy(Owner) == 0)
2020-05-07 12:38:01 +00:00
{
2020-10-21 20:29:35 +00:00
deletesprite(actor);
2020-05-07 12:38:01 +00:00
return;
}
actor->spr.angle = Owner->spr.angle;
2022-02-06 21:45:47 +00:00
actor->spr.pos = Owner->spr.pos.plusZ(Owner->isPlayer() ? -34 : 0);
2020-10-21 20:29:35 +00:00
for (int k = 0; k < actor->temp_data[0]; k++)
2020-05-07 12:38:01 +00:00
{
auto pos = actor->spr.pos + actor->spr.angle.ToVector() * 2 * k;
pos.Z += k * Sgn(actor->vel.Z) * abs(actor->vel.Z / 12);
2022-10-07 16:51:29 +00:00
auto q = CreateActor(actor->sector(), pos, tongue, -40 + (k << 1), DVector2(0.125, 0.125), nullAngle, 0., 0., actor, 5);
2020-10-21 20:29:35 +00:00
if (q)
{
q->spr.cstat = CSTAT_SPRITE_YCENTER;
q->spr.pal = 8;
}
2020-05-07 12:38:01 +00:00
}
2020-10-21 20:29:35 +00:00
int k = actor->temp_data[0]; // do not depend on the above loop counter.
auto pos = actor->spr.pos + actor->spr.angle.ToVector() * 2 * k;
pos.Z += k * Sgn(actor->vel.Z) * abs(actor->vel.Z / 12);
2022-10-07 16:51:29 +00:00
auto spawned = CreateActor(actor->sector(), pos, jaw, -40, DVector2(0.5, 0.5), nullAngle, 0., 0., actor, 5);
2020-10-21 20:29:35 +00:00
if (spawned)
{
spawned->spr.cstat = CSTAT_SPRITE_YCENTER;
2020-10-21 20:29:35 +00:00
if (actor->temp_data[1] > 512 && actor->temp_data[1] < (1024))
spawned->spr.picnum = jaw + 1;
2020-10-21 20:29:35 +00:00
}
2020-05-07 12:38:01 +00:00
}
2020-05-08 22:34:48 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void rpgexplode(DDukeActor *actor, int hit, const DVector3 &pos, int EXPLOSION2, int EXPLOSION2BOT, int newextra, int playsound)
{
2020-10-21 20:29:35 +00:00
auto explosion = spawn(actor, EXPLOSION2);
if (!explosion) return;
explosion->spr.pos = pos;
if (actor->spr.ScaleX() < 0.15625)
{
2022-10-05 22:08:51 +00:00
explosion->spr.SetScale(0.09375, 0.09375);
}
else if (hit == kHitSector)
{
if (actor->vel.Z > 0 && EXPLOSION2BOT >= 0)
2020-10-21 20:29:35 +00:00
spawn(actor, EXPLOSION2BOT);
else
{
explosion->spr.cstat |= CSTAT_SPRITE_YFLIP;
explosion->spr.pos.Z += 48;
}
}
if (newextra > 0) actor->spr.extra = newextra;
2020-10-21 20:29:35 +00:00
S_PlayActorSound(playsound, actor);
if (actor->spr.ScaleX() >= 0.15625)
{
int x = actor->spr.extra;
fi.hitradius(actor, gs.rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x);
}
else
{
int x = actor->spr.extra + (global_random & 3);
fi.hitradius(actor, (gs.rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x);
}
}
//---------------------------------------------------------------------------
//
2020-05-08 22:34:48 +00:00
//
//
//---------------------------------------------------------------------------
2020-10-21 20:34:45 +00:00
bool respawnmarker(DDukeActor *actor, int yellow, int green)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
actor->temp_data[0]++;
if (actor->temp_data[0] > gs.respawnitemtime)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
deletesprite(actor);
2020-05-08 22:34:48 +00:00
return false;
}
if (actor->temp_data[0] >= (gs.respawnitemtime >> 1) && actor->temp_data[0] < ((gs.respawnitemtime >> 1) + (gs.respawnitemtime >> 2)))
actor->spr.picnum = yellow;
else if (actor->temp_data[0] > ((gs.respawnitemtime >> 1) + (gs.respawnitemtime >> 2)))
actor->spr.picnum = green;
2020-10-21 20:34:45 +00:00
makeitfall(actor);
2020-05-08 22:34:48 +00:00
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:34:45 +00:00
bool rat(DDukeActor* actor, bool makesound)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
makeitfall(actor);
if (ssp(actor, CLIPMASK0))
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
if (makesound && (krand() & 255) == 0) S_PlayActorSound(RATTY, actor);
2022-09-15 16:12:09 +00:00
actor->spr.angle += mapangle((krand() & 31) - 15 + BobVal(actor->temp_data[0] << 8) * 8);
2020-05-08 22:34:48 +00:00
}
else
{
2020-10-21 20:34:45 +00:00
actor->temp_data[0]++;
if (actor->temp_data[0] > 1)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
deletesprite(actor);
2020-05-08 22:34:48 +00:00
return false;
}
2022-09-14 17:29:29 +00:00
else actor->spr.angle = randomAngle();
2020-05-08 22:34:48 +00:00
}
2022-09-14 17:29:29 +00:00
if (actor->vel.X < 8)
2022-09-11 17:28:45 +00:00
actor->vel.X += 1/8.;
2022-09-14 17:29:29 +00:00
actor->spr.angle += mapangle((krand() & 3) - 6);
2020-05-08 22:34:48 +00:00
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-05-06 19:11:36 +00:00
2020-10-21 20:34:45 +00:00
bool queball(DDukeActor *actor, int pocket, int queball, int stripeball)
2020-05-08 22:34:48 +00:00
{
if(actor->vel.X != 0)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
DukeStatIterator it(STAT_DEFAULT);
while (auto aa = it.Next())
2020-05-08 22:34:48 +00:00
{
double dist = (aa->spr.pos.XY() - actor->spr.pos.XY()).Length();
if (aa->spr.picnum == pocket && dist < 3.25)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:34:45 +00:00
deletesprite(actor);
2020-05-08 22:34:48 +00:00
return false;
}
}
Collision coll;
auto sect = actor->sector();
2022-08-30 19:07:40 +00:00
auto pos = actor->spr.pos;
2022-09-14 17:10:21 +00:00
auto move = actor->spr.angle.ToVector() * actor->vel.X * 0.5;
int j = clipmove(pos, &sect, move, 1.5, 4., 4., CLIPMASK1, coll);
2022-08-30 19:07:40 +00:00
actor->spr.pos = pos;;
actor->setsector(sect);
2020-05-08 22:34:48 +00:00
if (j == kHitWall)
2020-05-08 22:34:48 +00:00
{
auto ang = coll.hitWall->delta().Angle();
2022-09-14 17:10:21 +00:00
actor->spr.angle = ang * 2 - actor->spr.angle;
}
else if (j == kHitSprite)
2020-10-24 04:33:31 +00:00
{
fi.checkhitsprite(actor, coll.actor());
2020-10-24 04:33:31 +00:00
}
2022-09-11 17:28:45 +00:00
actor->vel.X -= 1/16.;
if(actor->vel.X < 0) actor->vel.X = 0;
if (actor->spr.picnum == stripeball)
2020-05-08 22:34:48 +00:00
{
actor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
actor->spr.cstat |= (CSTAT_SPRITE_XFLIP | CSTAT_SPRITE_YFLIP) & ESpriteFlags::FromInt(int(actor->vel.X / 16.)); // special hack edition...
2020-05-08 22:34:48 +00:00
}
}
else
{
2022-09-14 17:10:21 +00:00
double x;
int p = findplayer(actor, &x);
2020-05-08 22:34:48 +00:00
2022-09-14 17:10:21 +00:00
if (x < 99.75)
2020-05-08 22:34:48 +00:00
{
// if(actor->spr.pal == 12)
2020-05-08 22:34:48 +00:00
{
auto delta = absangle(ps[p].angle.ang, (actor->spr.pos.XY() - ps[p].pos.XY()).Angle());
2022-09-14 17:10:21 +00:00
if (delta < DAngle22_5 / 2 && PlayerInput(p, SB_OPEN))
2020-05-08 22:34:48 +00:00
if (ps[p].toggle_key_flag == 1)
{
2020-10-21 20:34:45 +00:00
DukeStatIterator it(STAT_ACTOR);
DDukeActor *act2;
while ((act2 = it.Next()))
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
if (act2->spr.picnum == queball || act2->spr.picnum == stripeball)
2020-05-08 22:34:48 +00:00
{
delta = absangle(ps[p].angle.ang, (act2->spr.pos.XY() - ps[p].pos.XY()).Angle());
2022-09-14 17:10:21 +00:00
if (delta < DAngle22_5 / 2)
2020-05-08 22:34:48 +00:00
{
2022-09-14 17:10:21 +00:00
double l;
2020-10-23 15:44:45 +00:00
findplayer(act2, &l);
2020-05-08 22:34:48 +00:00
if (x > l) break;
}
}
}
2020-10-21 20:34:45 +00:00
if (act2 == nullptr)
2020-05-08 22:34:48 +00:00
{
if (actor->spr.pal == 12)
2022-09-13 17:55:54 +00:00
actor->vel.X = 10.25;
else actor->vel.Z = 8.75;
2022-09-14 17:10:21 +00:00
actor->spr.angle = ps[p].angle.ang;
2020-05-08 22:34:48 +00:00
ps[p].toggle_key_flag = 2;
}
}
}
}
2022-09-14 17:10:21 +00:00
if (x < 32 && actor->sector() == ps[p].cursector)
2020-05-08 22:34:48 +00:00
{
actor->spr.angle = (actor->spr.pos.XY() - ps[p].pos.XY()).Angle();
2022-09-03 08:05:20 +00:00
actor->vel.X = 3;
2020-05-08 22:34:48 +00:00
}
}
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:59:56 +00:00
void forcesphere(DDukeActor* actor, int forcesphere)
2020-05-08 22:34:48 +00:00
{
auto sectp = actor->sector();
if (actor->spr.yint == 0)
2020-05-08 22:34:48 +00:00
{
actor->spr.yint = 1;
2020-05-08 22:34:48 +00:00
2022-09-14 17:43:25 +00:00
for (DAngle l = DAngle90; l < DAngle270; l += DAngle22_5)
for (DAngle j = nullAngle; j < DAngle360; j += DAngle22_5)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:59:56 +00:00
auto k = spawn(actor, forcesphere);
if (k)
{
k->spr.cstat = CSTAT_SPRITE_BLOCK_ALL | CSTAT_SPRITE_YCENTER;
k->clipdist = 16;
2022-09-14 17:43:25 +00:00
k->spr.angle = j;
k->vel.Z = l.Sin() * 2;
k->vel.X = l.Cos() * 2;
k->SetOwner(actor);
}
2020-05-08 22:34:48 +00:00
}
}
if (actor->temp_data[3] > 0)
2020-05-08 22:34:48 +00:00
{
if (actor->vel.Z < 24)
2022-09-11 17:28:45 +00:00
actor->vel.Z += 0.75;
actor->spr.pos.Z += actor->vel.Z;
2022-02-06 20:11:08 +00:00
if (actor->spr.pos.Z > sectp->floorz)
actor->spr.pos.Z = sectp->floorz;
actor->temp_data[3]--;
if (actor->temp_data[3] == 0)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:59:56 +00:00
deletesprite(actor);
2020-05-08 22:34:48 +00:00
return;
}
else if (actor->temp_data[2] > 10)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:59:56 +00:00
DukeStatIterator it(STAT_MISC);
while (auto aa = it.Next())
2020-05-08 22:34:48 +00:00
{
if (aa->GetOwner() == actor && aa->spr.picnum == forcesphere)
2020-10-21 20:59:56 +00:00
aa->temp_data[1] = 1 + (krand() & 63);
2020-05-08 22:34:48 +00:00
}
actor->temp_data[3] = 64;
2020-05-08 22:34:48 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 20:59:56 +00:00
void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int painsnd, int roamsnd, int shift, int (*getspawn)(DDukeActor* i))
2020-05-08 22:34:48 +00:00
{
auto sectp = actor->sector();
2022-09-14 21:30:10 +00:00
DAngle a;
2020-05-08 22:34:48 +00:00
2020-10-21 20:59:56 +00:00
getglobalz(actor);
2020-05-08 22:34:48 +00:00
if (sectp->ceilingstat & CSTAT_SECTOR_SKY)
actor->spr.shade += (sectp->ceilingshade - actor->spr.shade) >> 1;
else actor->spr.shade += (sectp->floorshade - actor->spr.shade) >> 1;
2020-05-08 22:34:48 +00:00
2022-02-06 20:11:08 +00:00
if (actor->spr.pos.Z < sectp->ceilingz + 32)
actor->spr.pos.Z = sectp->ceilingz + 32;
2020-05-08 22:34:48 +00:00
if (ud.multimode < 2)
{
if (actor_tog == 1)
{
actor->spr.cstat = CSTAT_SPRITE_INVISIBLE;
2020-05-08 22:34:48 +00:00
return;
}
else if (actor_tog == 2) actor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2020-05-08 22:34:48 +00:00
}
2020-10-21 20:59:56 +00:00
if (fi.ifhitbyweapon(actor) >= 0)
2020-05-08 22:34:48 +00:00
{
if (actor->spr.extra < 0 && actor->temp_data[0] != -1)
2020-05-08 22:34:48 +00:00
{
actor->temp_data[0] = -1;
actor->spr.extra = 0;
2020-05-08 22:34:48 +00:00
}
2020-10-21 20:59:56 +00:00
if (painsnd >= 0) S_PlayActorSound(painsnd, actor);
RANDOMSCRAP(actor);
2020-05-08 22:34:48 +00:00
}
if (actor->temp_data[0] == -1)
2020-05-08 22:34:48 +00:00
{
actor->spr.pos.Z += 4;
actor->temp_data[2]++;
if ((actor->temp_data[2] & 3) == 0) spawn(actor, explosion);
2020-10-21 20:59:56 +00:00
getglobalz(actor);
2022-09-14 21:30:10 +00:00
actor->spr.angle += DAngle22_5 * 0.75;
2022-09-03 08:05:20 +00:00
actor->vel.X = 8;
2020-10-21 20:59:56 +00:00
int j = ssp(actor, CLIPMASK0);
2022-02-03 23:45:24 +00:00
if (j != 1 || actor->spr.pos.Z > actor->floorz)
2020-05-08 22:34:48 +00:00
{
for (int l = 0; l < 16; l++)
2020-10-21 20:59:56 +00:00
RANDOMSCRAP(actor);
S_PlayActorSound(LASERTRIP_EXPLODE, actor);
int sp = getspawn(actor);
if (sp >= 0) spawn(actor, sp);
2020-05-08 22:34:48 +00:00
ps[myconnectindex].actors_killed++;
2020-10-21 20:59:56 +00:00
deletesprite(actor);
2020-05-08 22:34:48 +00:00
}
return;
}
else
{
2022-02-03 23:45:24 +00:00
if (actor->spr.pos.Z > actor->floorz - 48)
actor->spr.pos.Z = actor->floorz - 48;
2020-05-08 22:34:48 +00:00
}
double xx;
int p = findplayer(actor, &xx);
2020-10-21 20:59:56 +00:00
auto Owner = actor->GetOwner();
2020-05-08 22:34:48 +00:00
// 3 = findplayerz, 4 = shoot
if (actor->temp_data[0] >= 4)
2020-05-08 22:34:48 +00:00
{
actor->temp_data[2]++;
if ((actor->temp_data[2] & 15) == 0)
2020-05-08 22:34:48 +00:00
{
2022-09-14 21:30:10 +00:00
a = actor->spr.angle;
actor->spr.angle = actor->temp_angle;
2020-10-21 20:59:56 +00:00
if (attacksnd >= 0) S_PlayActorSound(attacksnd, actor);
fi.shoot(actor, firelaser);
2022-09-14 21:30:10 +00:00
actor->spr.angle = a;
2020-05-08 22:34:48 +00:00
}
if (actor->temp_data[2] > (26 * 3) || !cansee(actor->spr.pos.plusZ(-16), actor->sector(), ps[p].pos, ps[p].cursector))
2020-05-08 22:34:48 +00:00
{
actor->temp_data[0] = 0;
actor->temp_data[2] = 0;
2020-05-08 22:34:48 +00:00
}
2022-09-14 21:30:10 +00:00
else actor->temp_angle +=
deltaangle(actor->temp_angle, (ps[p].pos.XY() - actor->spr.pos.XY()).Angle()) / 3;
2020-05-08 22:34:48 +00:00
}
else if (actor->temp_data[0] == 2 || actor->temp_data[0] == 3)
2020-05-08 22:34:48 +00:00
{
2022-09-03 08:05:20 +00:00
if(actor->vel.X > 0) actor->vel.X -= 1;
2022-09-03 08:02:25 +00:00
else actor->vel.X = 0;
2020-05-08 22:34:48 +00:00
if (actor->temp_data[0] == 2)
2020-05-08 22:34:48 +00:00
{
double l = ps[p].pos.Z - actor->spr.pos.Z;
if (fabs(l) < 48) actor->temp_data[0] = 3;
else actor->spr.pos.Z += (Sgn(ps[p].pos.Z - actor->spr.pos.Z) * shift); // The shift here differs between Duke and RR.
2020-05-08 22:34:48 +00:00
}
else
{
actor->temp_data[2]++;
if (actor->temp_data[2] > (26 * 3) || !cansee(actor->spr.pos.plusZ(-16), actor->sector(), ps[p].pos, ps[p].cursector))
2020-05-08 22:34:48 +00:00
{
actor->temp_data[0] = 1;
actor->temp_data[2] = 0;
2020-05-08 22:34:48 +00:00
}
else if ((actor->temp_data[2] & 15) == 0 && attacksnd >= 0)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:59:56 +00:00
S_PlayActorSound(attacksnd, actor);
fi.shoot(actor, firelaser);
2020-05-08 22:34:48 +00:00
}
}
actor->spr.angle += deltaangle(actor->spr.angle, (ps[p].pos.XY() - actor->spr.pos.XY()).Angle()) * 0.25;
2020-05-08 22:34:48 +00:00
}
if (actor->temp_data[0] != 2 && actor->temp_data[0] != 3 && Owner)
2020-05-08 22:34:48 +00:00
{
double dist = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Length();
if (dist <= 96)
2020-05-08 22:34:48 +00:00
{
2022-09-14 21:30:10 +00:00
a = actor->spr.angle;
2022-09-03 08:04:16 +00:00
actor->vel.X *= 0.5;
2020-05-08 22:34:48 +00:00
}
else a = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Angle();
2020-05-08 22:34:48 +00:00
if (actor->temp_data[0] == 1 || actor->temp_data[0] == 4) // Found a locator and going with it
2020-05-08 22:34:48 +00:00
{
dist = (Owner->spr.pos - actor->spr.pos).Length();
2020-05-08 22:34:48 +00:00
if (dist <= 96) { if (actor->temp_data[0] == 1) actor->temp_data[0] = 0; else actor->temp_data[0] = 5; }
2020-05-08 22:34:48 +00:00
else
{
// Control speed here
if (dist > 96) { if (actor->vel.X < 16) actor->vel.X += 2.; }
2020-05-08 22:34:48 +00:00
else
{
2022-09-03 08:05:20 +00:00
if(actor->vel.X > 0) actor->vel.X -= 1;
2022-09-03 08:02:25 +00:00
else actor->vel.X = 0;
2020-05-08 22:34:48 +00:00
}
}
if (actor->temp_data[0] < 2) actor->temp_data[2]++;
2020-05-08 22:34:48 +00:00
if (xx < 384 && actor->temp_data[0] < 2 && actor->temp_data[2] > (26 * 4))
2020-05-08 22:34:48 +00:00
{
actor->temp_data[0] = 2 + (krand() & 2);
actor->temp_data[2] = 0;
2022-09-14 21:30:10 +00:00
actor->temp_angle = actor->spr.angle;
2020-05-08 22:34:48 +00:00
}
}
if (actor->temp_data[0] == 0 || actor->temp_data[0] == 5)
2020-05-08 22:34:48 +00:00
{
if (actor->temp_data[0] == 0)
actor->temp_data[0] = 1;
else actor->temp_data[0] = 4;
auto NewOwner = LocateTheLocator(actor->spr.hitag, nullptr);
2020-10-21 20:59:56 +00:00
if (!NewOwner)
2020-05-08 22:34:48 +00:00
{
actor->spr.hitag = actor->temp_data[5];
NewOwner = LocateTheLocator(actor->spr.hitag, nullptr);
2020-10-21 20:59:56 +00:00
if (!NewOwner)
2020-05-08 22:34:48 +00:00
{
2020-10-21 20:59:56 +00:00
deletesprite(actor);
2020-05-08 22:34:48 +00:00
return;
}
}
else actor->spr.hitag++;
2020-11-01 06:56:49 +00:00
actor->SetOwner(NewOwner);
2020-05-08 22:34:48 +00:00
}
2022-09-14 21:30:10 +00:00
auto ang = deltaangle(actor->spr.angle, a);
actor->spr.angle += ang * 0.125;
2020-05-08 22:34:48 +00:00
if (actor->spr.pos.Z < Owner->spr.pos.Z - 2)
actor->spr.pos.Z += 2;
else if (actor->spr.pos.Z > Owner->spr.pos.Z + 2)
actor->spr.pos -= 2;
else actor->spr.pos.Z = Owner->spr.pos.Z;
2020-05-08 22:34:48 +00:00
}
2020-10-21 21:39:12 +00:00
if (roamsnd >= 0 && S_CheckActorSoundPlaying(actor, roamsnd) < 1)
2020-10-21 20:59:56 +00:00
S_PlayActorSound(roamsnd, actor);
2020-05-08 22:34:48 +00:00
2020-10-21 20:59:56 +00:00
ssp(actor, CLIPMASK0);
2020-05-08 22:34:48 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 21:04:14 +00:00
void ooz(DDukeActor *actor)
2020-05-08 22:34:48 +00:00
{
2020-10-21 21:04:14 +00:00
getglobalz(actor);
2020-05-08 22:34:48 +00:00
2022-10-05 22:08:51 +00:00
double y = min((actor->floorz - actor->ceilingz) / 128, 4.);
double x = clamp(0.390625 - y * 0.5, 0.125, 0.75);
2020-05-08 22:34:48 +00:00
2022-10-05 22:08:51 +00:00
actor->spr.SetScale(x, y);
2022-02-03 23:45:24 +00:00
actor->spr.pos.Z = actor->floorz;
2020-05-08 22:34:48 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void reactor(DDukeActor* const actor, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BURNT, int REACTORSPARK, int REACTOR2SPARK)
2020-05-08 22:34:48 +00:00
{
auto sectp = actor->sector();
2020-05-08 22:34:48 +00:00
if (actor->temp_data[4] == 1)
2020-05-08 22:34:48 +00:00
{
DukeSectIterator it(actor->sector());
2021-12-21 18:09:05 +00:00
while (auto a2 = it.Next())
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
if (a2->spr.picnum == SECTOREFFECTOR)
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
if (a2->spr.lotag == 1)
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
a2->spr.lotag = -1;
a2->spr.hitag = -1;
2020-05-08 22:34:48 +00:00
}
}
2021-12-21 18:09:05 +00:00
else if (a2->spr.picnum == REACTOR)
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
a2->spr.picnum = REACTORBURNT;
2020-05-08 22:34:48 +00:00
}
2021-12-21 18:09:05 +00:00
else if (a2->spr.picnum == REACTOR2)
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
a2->spr.picnum = REACTOR2BURNT;
2020-05-08 22:34:48 +00:00
}
2021-12-21 18:09:05 +00:00
else if (a2->spr.picnum == REACTORSPARK || a2->spr.picnum == REACTOR2SPARK)
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
a2->spr.cstat = CSTAT_SPRITE_INVISIBLE;
2020-05-08 22:34:48 +00:00
}
2020-10-21 21:04:14 +00:00
}
return;
2020-05-08 22:34:48 +00:00
}
if (actor->temp_data[1] >= 20)
2020-05-08 22:34:48 +00:00
{
actor->temp_data[4] = 1;
2020-05-08 22:34:48 +00:00
return;
}
double xx;
int p = findplayer(actor, &xx);
2020-05-08 22:34:48 +00:00
actor->temp_data[2]++;
if (actor->temp_data[2] == 4) actor->temp_data[2] = 0;
2020-05-08 22:34:48 +00:00
if (xx < 256)
2020-05-08 22:34:48 +00:00
{
if ((krand() & 255) < 16)
{
if (!S_CheckSoundPlaying(DUKE_LONGTERM_PAIN))
2020-10-21 21:04:14 +00:00
S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor());
2020-05-08 22:34:48 +00:00
2020-10-21 21:04:14 +00:00
S_PlayActorSound(SHORT_CIRCUIT, actor);
2020-05-08 22:34:48 +00:00
ps[p].GetActor()->spr.extra--;
2020-05-08 22:34:48 +00:00
SetPlayerPal(&ps[p], PalEntry(32, 32, 0, 0));
}
actor->temp_data[0] += 128;
if (actor->temp_data[3] == 0)
actor->temp_data[3] = 1;
2020-05-08 22:34:48 +00:00
}
else actor->temp_data[3] = 0;
2020-05-08 22:34:48 +00:00
if (actor->temp_data[1])
2020-05-08 22:34:48 +00:00
{
actor->temp_data[1]++;
2020-05-08 22:34:48 +00:00
2022-08-22 18:08:45 +00:00
actor->temp_data[4] = FloatToFixed<8>(actor->spr.pos.Z);
actor->spr.pos.Z = sectp->floorz - zrand(sectp->floorz - sectp->ceilingz);
2020-05-08 22:34:48 +00:00
switch (actor->temp_data[1])
2020-05-08 22:34:48 +00:00
{
case 3:
{
2020-05-08 22:34:48 +00:00
//Turn on all of those flashing sectoreffector.
2020-10-21 21:04:14 +00:00
fi.hitradius(actor, 4096,
gs.impact_damage << 2,
gs.impact_damage << 2,
gs.impact_damage << 2,
gs.impact_damage << 2);
2020-10-21 21:04:14 +00:00
DukeStatIterator it(STAT_STANDABLE);
2021-12-21 18:09:05 +00:00
while (auto a2 = it.Next())
2020-05-08 22:34:48 +00:00
{
2021-12-21 18:09:05 +00:00
if (a2->spr.picnum == MASTERSWITCH)
if (a2->spr.hitag == actor->spr.hitag)
if (a2->spr.yint == 0)
a2->spr.yint = 1;
2020-05-08 22:34:48 +00:00
}
break;
}
2020-05-08 22:34:48 +00:00
case 4:
case 7:
case 10:
case 15:
{
DukeSectIterator it(actor->sector());
2020-10-21 21:04:14 +00:00
while (auto a2 = it.Next())
2020-05-08 22:34:48 +00:00
{
2020-10-21 21:04:14 +00:00
if (a2 != actor)
2020-05-08 22:34:48 +00:00
{
2020-10-21 21:04:14 +00:00
deletesprite(a2);
break;
2020-05-08 22:34:48 +00:00
}
}
break;
}
}
for (int x = 0; x < 16; x++)
2020-10-21 21:04:14 +00:00
RANDOMSCRAP(actor);
2020-05-08 22:34:48 +00:00
2022-08-22 18:08:45 +00:00
actor->spr.pos.Z = FixedToFloat<8>(actor->temp_data[4]);
actor->temp_data[4] = 0;
2020-05-08 22:34:48 +00:00
}
else
{
2020-10-21 21:04:14 +00:00
int j = fi.ifhitbyweapon(actor);
2020-05-08 22:34:48 +00:00
if (j >= 0)
{
for (int x = 0; x < 32; x++)
2020-10-21 21:04:14 +00:00
RANDOMSCRAP(actor);
if (actor->spr.extra < 0)
actor->temp_data[1] = 1;
2020-05-08 22:34:48 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 21:04:14 +00:00
void camera(DDukeActor *actor)
2020-05-08 22:34:48 +00:00
{
if (actor->temp_data[0] == 0)
2020-05-08 22:34:48 +00:00
{
actor->temp_data[1] += 8;
if (gs.camerashitable)
2020-05-08 22:34:48 +00:00
{
if (fi.ifhitbyweapon(actor) >= 0)
2020-05-08 22:34:48 +00:00
{
actor->temp_data[0] = 1; // static
actor->spr.cstat = CSTAT_SPRITE_INVISIBLE;
2020-05-08 22:34:48 +00:00
for (int x = 0; x < 5; x++)
2020-10-21 21:04:14 +00:00
RANDOMSCRAP(actor);
2020-05-08 22:34:48 +00:00
return;
}
}
if (actor->spr.hitag > 0)
2020-05-08 22:34:48 +00:00
{
auto const angle = mapangle(8);
if (actor->temp_data[1] < actor->spr.hitag)
actor->spr.angle += angle;
else if (actor->temp_data[1] < (actor->spr.hitag * 3))
actor->spr.angle -= angle;
else if (actor->temp_data[1] < (actor->spr.hitag << 2))
actor->spr.angle += angle;
else
{
actor->spr.angle += angle;
actor->temp_data[1] = 0;
}
2020-05-08 22:34:48 +00:00
}
}
}
2020-05-09 18:27:06 +00:00
//---------------------------------------------------------------------------
//
// taken out of moveexplosion
//
//---------------------------------------------------------------------------
void forcesphereexplode(DDukeActor *actor)
2020-05-09 18:27:06 +00:00
{
double size = actor->spr.ScaleX();
if (actor->temp_data[1] > 0)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[1]--;
if (actor->temp_data[1] == 0)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return;
}
}
auto Owner = actor->GetOwner();
if (!Owner) return;
if (Owner->temp_data[1] == 0)
2020-05-09 18:27:06 +00:00
{
if (actor->temp_data[0] < 64)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[0]++;
size += 0.046875;
2020-05-09 18:27:06 +00:00
}
}
else
if (actor->temp_data[0] > 64)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[0]--;
size -= 0.046875;
2020-05-09 18:27:06 +00:00
}
2022-02-06 20:11:08 +00:00
actor->spr.pos = Owner->spr.pos;;
actor->spr.angle += mapangle(Owner->temp_data[0]);
2020-05-09 18:27:06 +00:00
size = clamp(size, REPEAT_SCALE, 1.);
2020-05-09 18:27:06 +00:00
actor->spr.SetScale(size, size);
actor->spr.shade = int8_t((size * 32) - 48);
2020-05-09 18:27:06 +00:00
for (int j = actor->temp_data[0]; j > 0; j--)
ssp(actor, CLIPMASK0);
2020-05-09 18:27:06 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void watersplash2(DDukeActor* actor)
2020-05-09 18:27:06 +00:00
{
2021-11-20 23:33:17 +00:00
auto sectp = actor->sector();
actor->temp_data[0]++;
if (actor->temp_data[0] == 1)
2020-05-09 18:27:06 +00:00
{
if (sectp->lotag != 1 && sectp->lotag != 2)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return;
}
if (!S_CheckSoundPlaying(ITEM_SPLASH))
S_PlayActorSound(ITEM_SPLASH, actor);
2020-05-09 18:27:06 +00:00
}
if (actor->temp_data[0] == 3)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[0] = 0;
actor->temp_data[1]++;
2020-05-09 18:27:06 +00:00
}
if (actor->temp_data[1] == 5)
deletesprite(actor);
2020-05-09 18:27:06 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void frameeffect1(DDukeActor *actor)
2020-05-09 18:27:06 +00:00
{
auto Owner = actor->GetOwner();
if (Owner)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[0]++;
2020-05-09 18:27:06 +00:00
if (actor->temp_data[0] > 7)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return;
}
else if (actor->temp_data[0] > 4) actor->spr.cstat |= CSTAT_SPRITE_TRANS_FLIP | CSTAT_SPRITE_TRANSLUCENT;
else if (actor->temp_data[0] > 2) actor->spr.cstat |= CSTAT_SPRITE_TRANSLUCENT;
actor->spr.xoffset = Owner->spr.xoffset;
actor->spr.yoffset = Owner->spr.yoffset;
2020-05-09 18:27:06 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool money(DDukeActor* actor, int BLOODPOOL)
2020-05-09 18:27:06 +00:00
{
auto sectp = actor->sector();
2020-05-09 18:27:06 +00:00
actor->vel.X = krandf(0.5) + BobVal(actor->temp_data[0]) * 2;
actor->temp_data[0] += (krand() & 63);
if ((actor->temp_data[0] & 2047) > 512 && (actor->temp_data[0] & 2047) < 1596)
2020-05-09 18:27:06 +00:00
{
if (sectp->lotag == 2)
2020-05-09 18:27:06 +00:00
{
if (actor->vel.Z < 0.25)
actor->vel.Z += gs.gravity / 32. + krandf(1/32.);
2020-05-09 18:27:06 +00:00
}
else
if (actor->vel.Z < 0.5625)
actor->vel.Z += gs.gravity / 32. + krandf(1 / 32.);
2020-05-09 18:27:06 +00:00
}
ssp(actor, CLIPMASK0);
2020-05-09 18:27:06 +00:00
if ((krand() & 3) == 0)
2022-02-06 20:11:08 +00:00
SetActor(actor, actor->spr.pos);
2020-05-09 18:27:06 +00:00
if (!actor->insector())
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
double l = getflorzofslopeptr(actor->sector(), actor->spr.pos);
2020-05-09 18:27:06 +00:00
if (actor->spr.pos.Z > l)
2020-05-09 18:27:06 +00:00
{
actor->spr.pos.Z = l;
2020-05-09 18:27:06 +00:00
insertspriteq(actor);
actor->spr.picnum++;
2020-05-09 18:27:06 +00:00
DukeStatIterator it(STAT_MISC);
while (auto aa = it.Next())
2020-05-09 18:27:06 +00:00
{
if (aa->spr.picnum == BLOODPOOL)
{
double dist = (aa->spr.pos.XY() - actor->spr.pos.XY()).Length();
if (dist < 348/16.)
2020-05-09 18:27:06 +00:00
{
actor->spr.pal = 2;
2020-05-09 18:27:06 +00:00
break;
}
}
2020-05-09 18:27:06 +00:00
}
}
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool jibs(DDukeActor *actor, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, bool zcheck1, bool zcheck2)
2020-05-09 18:27:06 +00:00
{
auto sectp = actor->sector();
2020-05-09 18:27:06 +00:00
2022-09-11 17:28:45 +00:00
if(actor->vel.X > 0) actor->vel.X -= 1/16.;
2022-09-03 08:02:25 +00:00
else actor->vel.X = 0;
2020-05-09 18:27:06 +00:00
if (timeout)
{
if (actor->temp_data[5] < 30 * 10)
actor->temp_data[5]++;
2020-05-09 18:27:06 +00:00
else
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
}
if (actor->vel.Z > 4 && actor->vel.Z < 5)
2020-05-09 18:27:06 +00:00
{
2022-02-06 20:11:08 +00:00
SetActor(actor, actor->spr.pos);
sectp = actor->sector();
2020-05-09 18:27:06 +00:00
}
2022-02-06 20:11:08 +00:00
if (callsetsprite) SetActor(actor, actor->spr.pos);
2020-05-09 18:27:06 +00:00
// this was after the slope calls, but we should avoid calling that for invalid sectors.
if (!actor->insector())
{
deletesprite(actor);
return false;
}
double fz = getflorzofslopeptr(sectp, actor->spr.pos);
double cz = getceilzofslopeptr(sectp, actor->spr.pos);
if (cz == fz)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
if (actor->spr.pos.Z < fz - 2)
2020-05-09 18:27:06 +00:00
{
if (actor->temp_data[1] < 2) actor->temp_data[1]++;
else if (sectp->lotag != 2)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[1] = 0;
2020-05-09 18:27:06 +00:00
if (zcheck1)
{
if (actor->temp_data[0] > 6) actor->temp_data[0] = 0;
else actor->temp_data[0]++;
2020-05-09 18:27:06 +00:00
}
else
{
if (actor->temp_data[0] > 2)
actor->temp_data[0] = 0;
else actor->temp_data[0]++;
2020-05-09 18:27:06 +00:00
}
}
if (actor->vel.Z < 24)
2020-05-09 18:27:06 +00:00
{
if (sectp->lotag == 2)
2020-05-09 18:27:06 +00:00
{
if (actor->vel.Z < 4)
2022-09-11 17:28:45 +00:00
actor->vel.Z += 3 / 16.;
2022-09-03 08:04:16 +00:00
else actor->vel.Z = 4;
2020-05-09 18:27:06 +00:00
}
else actor->vel.Z += ( gs.gravity - 50/256.);
2020-05-09 18:27:06 +00:00
}
actor->spr.pos += actor->spr.angle.ToVector() * actor->vel.X;
actor->spr.pos.Z += actor->vel.Z;
2020-05-09 18:27:06 +00:00
2022-02-06 21:45:47 +00:00
if (floorcheck && actor->spr.pos.Z >= actor->sector()->floorz)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
}
else
{
if (zcheck2)
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
if (actor->temp_data[2] == 0)
2020-05-09 18:27:06 +00:00
{
if (!actor->insector())
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
if ((actor->sector()->floorstat & CSTAT_SECTOR_SLOPE))
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
actor->temp_data[2]++;
2020-05-09 18:27:06 +00:00
}
double ll = getflorzofslopeptr(actor->sector(), actor->spr.pos);
2020-05-09 18:27:06 +00:00
2022-08-20 16:56:13 +00:00
actor->spr.pos.Z = ll - 2;
2022-09-03 08:02:25 +00:00
actor->vel.X = 0;
2020-05-09 18:27:06 +00:00
if (actor->spr.picnum == JIBS6)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[1]++;
if ((actor->temp_data[1] & 3) == 0 && actor->temp_data[0] < 7)
actor->temp_data[0]++;
if (actor->temp_data[1] > 20)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
}
else { actor->spr.picnum = JIBS6; actor->temp_data[0] = 0; actor->temp_data[1] = 0; }
2020-05-09 18:27:06 +00:00
}
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-01-26 23:41:33 +00:00
bool bloodpool(DDukeActor* actor, bool puke)
2020-05-09 18:27:06 +00:00
{
auto sectp = actor->sector();
2020-05-09 18:27:06 +00:00
if (actor->temp_data[0] == 0)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[0] = 1;
2021-12-18 12:23:08 +00:00
if (sectp->floorstat & CSTAT_SECTOR_SLOPE)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return false;
}
else insertspriteq(actor);
2020-05-09 18:27:06 +00:00
}
makeitfall(actor);
2020-05-09 18:27:06 +00:00
double xx;
int p = findplayer(actor, &xx);
2020-05-09 18:27:06 +00:00
2022-02-03 23:45:24 +00:00
actor->spr.pos.Z = actor->floorz - FOURSLEIGHT_F;
2020-05-09 18:27:06 +00:00
if (actor->temp_data[2] < 32)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[2]++;
2022-01-26 23:41:33 +00:00
if (attackerflag(actor, SFLAG_FLAMMABLEPOOLEFFECT))
2020-05-09 18:27:06 +00:00
{
2022-10-05 22:46:20 +00:00
if (actor->spr.ScaleX() < 1 && actor->spr.ScaleY() < 1)
2020-05-09 18:27:06 +00:00
{
actor->spr.AddScaleX((krand() & 3) * REPEAT_SCALE);
actor->spr.AddScaleY((krand() & 3) * REPEAT_SCALE);
2020-05-09 18:27:06 +00:00
}
}
else
{
2022-10-05 22:46:20 +00:00
if (actor->spr.ScaleX() < 0.5 && actor->spr.ScaleY() < 0.5)
2020-05-09 18:27:06 +00:00
{
actor->spr.AddScaleX((krand() & 3) * REPEAT_SCALE);
actor->spr.AddScaleY((krand() & 3) * REPEAT_SCALE);
2020-05-09 18:27:06 +00:00
}
}
}
if (xx < 844 / 16. && actor->spr.ScaleX() > 0.09375 && actor->spr.ScaleY() > 0.09375)
2020-05-09 18:27:06 +00:00
{
if (actor->spr.pal == 0 && (krand() & 255) < 16 && !puke)
2020-05-09 18:27:06 +00:00
{
if (ps[p].boot_amount > 0)
ps[p].boot_amount--;
else
{
if (!S_CheckSoundPlaying(DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor());
ps[p].GetActor()->spr.extra--;
2020-05-09 18:27:06 +00:00
SetPlayerPal(&ps[p], PalEntry(32, 16, 0, 0));
}
}
if (actor->temp_data[1] == 1) return false;
actor->temp_data[1] = 1;
2020-05-09 18:27:06 +00:00
2022-01-26 23:41:33 +00:00
if (attackerflag(actor, SFLAG_FLAMMABLEPOOLEFFECT))
2020-05-09 18:27:06 +00:00
ps[p].footprintcount = 10;
else ps[p].footprintcount = 3;
ps[p].footprintpal = actor->spr.pal;
ps[p].footprintshade = actor->spr.shade;
2020-05-09 18:27:06 +00:00
if (actor->temp_data[2] == 32)
2020-05-09 18:27:06 +00:00
{
actor->spr.AddScaleX(-6);
actor->spr.AddScaleY(-6);
2020-05-09 18:27:06 +00:00
}
}
else actor->temp_data[1] = 0;
2020-05-09 18:27:06 +00:00
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void shell(DDukeActor* actor, bool morecheck)
2020-05-09 18:27:06 +00:00
{
auto sectp = actor->sector();
2020-05-09 18:27:06 +00:00
ssp(actor, CLIPMASK0);
2020-05-09 18:27:06 +00:00
if (!actor->insector() || morecheck)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return;
}
if (sectp->lotag == 2)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[1]++;
if (actor->temp_data[1] > 8)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[1] = 0;
actor->temp_data[0]++;
actor->temp_data[0] &= 3;
2020-05-09 18:27:06 +00:00
}
if (actor->vel.Z < 0.5) actor-> vel.Z += (gs.gravity / 13); // 8
2022-09-11 17:28:45 +00:00
else actor->vel.Z -= 0.25;
if (actor->vel.X > 0)
actor->vel.X -= 0.25;
2022-09-03 08:02:25 +00:00
else actor->vel.X = 0;
2020-05-09 18:27:06 +00:00
}
else
{
actor->temp_data[1]++;
if (actor->temp_data[1] > 3)
2020-05-09 18:27:06 +00:00
{
actor->temp_data[1] = 0;
actor->temp_data[0]++;
actor->temp_data[0] &= 3;
2020-05-09 18:27:06 +00:00
}
if (actor->vel.Z < 2) actor->vel.Z += (gs.gravity / 3); // 52;
if(actor->vel.X > 0)
2022-09-11 17:28:45 +00:00
actor->vel.X -= 1/16.;
2020-05-09 18:27:06 +00:00
else
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void glasspieces(DDukeActor* actor)
2020-05-09 18:27:06 +00:00
{
auto sectp = actor->sector();
2020-05-09 18:27:06 +00:00
makeitfall(actor);
2020-05-09 18:27:06 +00:00
2022-09-11 17:28:45 +00:00
if (actor->vel.Z > 16) actor->vel.Z = 16;
if (!actor->insector())
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return;
}
2022-02-03 23:45:24 +00:00
if (actor->spr.pos.Z == actor->floorz - FOURSLEIGHT_F && actor->temp_data[0] < 3)
2020-05-09 18:27:06 +00:00
{
actor->vel.Z = -(3 - actor->temp_data[0]) - krandf(2);
if (sectp->lotag == 2)
2022-09-03 08:04:16 +00:00
actor->vel.Z *= 0.5;
2022-10-07 16:37:21 +00:00
actor->spr.MultScale(0.5);
2020-05-09 18:27:06 +00:00
if (rnd(96))
2022-02-06 21:45:47 +00:00
SetActor(actor, actor->spr.pos);
actor->temp_data[0]++;//Number of bounces
2020-05-09 18:27:06 +00:00
}
else if (actor->temp_data[0] == 3)
2020-05-09 18:27:06 +00:00
{
deletesprite(actor);
2020-05-09 18:27:06 +00:00
return;
}
if(actor->vel.X > 0)
2020-05-09 18:27:06 +00:00
{
2022-09-11 17:28:45 +00:00
actor->vel.X -= 1/8.;
2021-12-18 11:28:48 +00:00
static const ESpriteFlags flips[] = { 0, CSTAT_SPRITE_XFLIP, CSTAT_SPRITE_YFLIP, CSTAT_SPRITE_XFLIP | CSTAT_SPRITE_YFLIP };
actor->spr.cstat = flips[int(actor->vel.X * 16) & 3];
2020-05-09 18:27:06 +00:00
}
2022-09-03 08:02:25 +00:00
else actor->vel.X = 0;
2020-05-09 18:27:06 +00:00
ssp(actor, CLIPMASK0);
2020-05-09 18:27:06 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void scrap(DDukeActor* actor, int SCRAP1, int SCRAP6)
2020-05-09 18:27:06 +00:00
{
auto sectp = actor->sector();
2020-05-09 18:27:06 +00:00
if(actor->vel.X > 0)
2022-09-11 17:28:45 +00:00
actor->vel.X -= 1/16.;
2022-09-03 08:02:25 +00:00
else actor->vel.X = 0;
2020-05-09 18:27:06 +00:00
if (actor->vel.Z > 4 && actor->vel.Z < 5)
2020-05-09 18:27:06 +00:00
{
2022-02-06 21:45:47 +00:00
SetActor(actor, actor->spr.pos);
sectp = actor->sector();
2020-05-09 18:27:06 +00:00
}
if (actor->spr.pos.Z < sectp->floorz - 2)
2020-05-09 18:27:06 +00:00
{
if (actor->temp_data[1] < 1) actor->temp_data[1]++;
2020-05-09 18:27:06 +00:00
else
{
actor->temp_data[1] = 0;
2020-05-09 18:27:06 +00:00
if (actor->spr.picnum < SCRAP6 + 8)
2020-05-09 18:27:06 +00:00
{
if (actor->temp_data[0] > 6)
actor->temp_data[0] = 0;
else actor->temp_data[0]++;
2020-05-09 18:27:06 +00:00
}
else
{
if (actor->temp_data[0] > 2)
actor->temp_data[0] = 0;
else actor->temp_data[0]++;
2020-05-09 18:27:06 +00:00
}
}
if (actor->vel.Z < 16) actor->vel.Z += (gs.gravity - 50 / 256.);
actor->spr.pos += actor->spr.angle.ToVector() * actor->vel.X;
actor->spr.pos.Z += actor->vel.Z;
2020-05-09 18:27:06 +00:00
}
else
{
if (actor->spr.picnum == SCRAP1 && actor->spr.yint > 0)
2020-05-09 18:27:06 +00:00
{
auto spawned = spawn(actor, actor->spr.yint);
if (spawned)
{
2022-08-22 16:34:01 +00:00
SetActor(spawned, actor->spr.pos);
getglobalz(spawned);
spawned->spr.hitag = spawned->spr.lotag = 0;
}
2020-05-09 18:27:06 +00:00
}
deletesprite(actor);
2020-05-09 18:27:06 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void gutsdir(DDukeActor* actor, int gtype, int n, int p)
{
2022-10-07 16:51:29 +00:00
double scale;
2022-10-05 22:46:20 +00:00
if (badguy(actor) && actor->spr.ScaleX() < 0.25)
2022-10-07 16:51:29 +00:00
scale = 0.125;
else scale = 0.5;
2022-08-23 20:46:54 +00:00
double gutz = actor->spr.pos.Z - 8;
double floorz = getflorzofslopeptr(actor->sector(), actor->spr.pos);
2022-08-23 20:46:54 +00:00
if (gutz > floorz - 8)
gutz = floorz - 8;
gutz += gs.actorinfo[actor->spr.picnum].gutsoffset;
for (int j = 0; j < n; j++)
{
auto a = randomAngle();
auto vel = krandf(8) + 16;
auto zvel = -krandf(8) - 2;
// TRANSITIONAL: owned by a player???
2022-10-07 16:51:29 +00:00
CreateActor(actor->sector(), DVector3(actor->spr.pos.XY(), gutz), gtype, -32, DVector2(scale, scale), a, vel, zvel, ps[p].GetActor(), 5);
}
}
2020-05-10 07:08:02 +00:00
//---------------------------------------------------------------------------
//
2022-09-11 16:01:27 +00:00
// Rotating sector
//
// temp_data[1]: mspos index
// temp_angle: current angle
// temp_data[3]: checkz / acceleration, depending on mode.
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2022-01-19 09:48:18 +00:00
void handle_se00(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
sectortype *sect = actor->sector();
2020-05-10 07:08:02 +00:00
2022-09-11 16:01:27 +00:00
double zchange = 0;
2020-05-10 07:08:02 +00:00
2020-10-21 21:39:12 +00:00
auto Owner = actor->GetOwner();
2020-05-10 07:08:02 +00:00
if (!Owner || Owner->spr.lotag == -1)
2020-05-10 07:08:02 +00:00
{
2020-10-21 21:39:12 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
2022-09-11 16:01:27 +00:00
DAngle ang_amount = mapangle(sect->extra >> 3);
double direction = 0;
2020-05-10 07:08:02 +00:00
2020-10-31 21:55:41 +00:00
if (sect->lotag == 30)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:01:27 +00:00
ang_amount *= 0.25;
2020-05-10 07:08:02 +00:00
if (actor->spr.extra == 1)
2020-05-10 07:08:02 +00:00
{
if (actor->tempval < 256)
2020-05-10 07:08:02 +00:00
{
actor->tempval += 4;
if (actor->tempval >= 256)
callsound(actor->sector(), actor, true);
if (actor->spr.clipdist) direction = 1; // notreallyclipdist
2022-09-11 16:01:27 +00:00
else direction = -1;
2020-05-10 07:08:02 +00:00
}
else actor->tempval = 256;
2020-05-10 07:08:02 +00:00
2022-02-06 21:45:47 +00:00
if (sect->floorz > actor->spr.pos.Z) //z's are touching
2020-05-10 07:08:02 +00:00
{
2022-02-07 08:05:36 +00:00
sect->addfloorz(-2);
2022-09-11 16:01:27 +00:00
zchange = 2;
2022-02-06 21:45:47 +00:00
if (sect->floorz < actor->spr.pos.Z)
sect->setfloorz(actor->spr.pos.Z);
2020-05-10 07:08:02 +00:00
}
2022-02-06 21:45:47 +00:00
else if (sect->floorz < actor->spr.pos.Z) //z's are touching
2020-05-10 07:08:02 +00:00
{
2022-02-07 08:05:36 +00:00
sect->addfloorz(2);
2022-09-11 16:01:27 +00:00
zchange = 2;
2022-02-06 21:45:47 +00:00
if (sect->floorz > actor->spr.pos.Z)
sect->setfloorz(actor->spr.pos.Z);
2020-05-10 07:08:02 +00:00
}
}
else if (actor->spr.extra == 3)
2020-05-10 07:08:02 +00:00
{
if (actor->tempval > 0)
2020-05-10 07:08:02 +00:00
{
actor->tempval -= 4;
if (actor->tempval <= 0)
callsound(actor->sector(), actor, true);
if (actor->spr.clipdist) direction = -1; // notreallyclipdist
2022-09-11 16:01:27 +00:00
else direction = 1;
2020-05-10 07:08:02 +00:00
}
else actor->tempval = 0;
2020-05-10 07:08:02 +00:00
double checkz = actor->temp_pos.Z;
2022-02-07 08:05:36 +00:00
if (sect->floorz > checkz) //z's are touching
2020-05-10 07:08:02 +00:00
{
2022-02-07 08:05:36 +00:00
sect->addfloorz(-2);
2022-09-11 16:01:27 +00:00
zchange = -2;
2022-02-07 08:05:36 +00:00
if (sect->floorz < checkz)
sect->setfloorz(checkz);
2020-05-10 07:08:02 +00:00
}
2022-02-07 08:05:36 +00:00
else if (sect->floorz < checkz) //z's are touching
2020-05-10 07:08:02 +00:00
{
2022-02-07 08:05:36 +00:00
sect->addfloorz(2);
2022-09-11 16:01:27 +00:00
zchange = 2;
2022-02-07 08:05:36 +00:00
if (sect->floorz > checkz)
sect->setfloorz(checkz);
2020-05-10 07:08:02 +00:00
}
}
2022-09-11 16:01:27 +00:00
actor->spr.angle += ang_amount * direction;
actor->temp_angle += ang_amount * direction;
2020-05-10 07:08:02 +00:00
}
else
{
2020-10-21 21:39:12 +00:00
if (Owner->temp_data[0] == 0) return;
if (Owner->temp_data[0] == 2)
2020-05-10 07:08:02 +00:00
{
2020-10-21 21:39:12 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
2022-09-11 16:01:27 +00:00
if (Owner->spr.angle.Normalized360() > DAngle180)
direction = -1;
else direction = 1;
if (actor->temp_pos.Y == 0)
actor->temp_pos.Y = (actor->spr.pos.XY() - Owner->spr.pos.XY()).Length();
actor->vel.X = actor->temp_pos.Y;
2022-08-29 17:27:52 +00:00
actor->spr.pos.XY() = Owner->spr.pos.XY();
2022-09-11 16:01:27 +00:00
actor->spr.angle += ang_amount * direction;
actor->temp_angle += ang_amount * direction;
2020-05-10 07:08:02 +00:00
}
2022-09-11 16:01:27 +00:00
if (direction && (sect->floorstat & CSTAT_SECTOR_ALIGN))
2020-05-10 07:08:02 +00:00
{
int p;
for (p = connecthead; p >= 0; p = connectpoint2[p])
{
if (ps[p].cursector == actor->sector() && ps[p].on_ground == 1)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:01:27 +00:00
ps[p].angle.addadjustment(ang_amount * direction);
2020-05-10 07:08:02 +00:00
2022-09-11 16:01:27 +00:00
ps[p].pos.Z += zchange;
2020-05-10 07:08:02 +00:00
2022-09-11 16:01:27 +00:00
auto result = rotatepoint(Owner->spr.pos, ps[p].pos.XY(), ang_amount * direction);
2020-05-10 07:08:02 +00:00
2022-02-05 12:58:12 +00:00
ps[p].bobpos += (result - ps[p].pos.XY());
2020-05-10 07:08:02 +00:00
2022-02-05 12:49:36 +00:00
ps[p].pos.X = result.X;
ps[p].pos.Y = result.Y;
2020-05-10 07:08:02 +00:00
2020-10-21 21:39:12 +00:00
auto psp = ps[p].GetActor();
if (psp->spr.extra <= 0)
2020-05-10 07:08:02 +00:00
{
2022-02-05 12:49:36 +00:00
psp->spr.pos.X = result.X;
psp->spr.pos.Y = result.Y;
2020-05-10 07:08:02 +00:00
}
}
}
DukeSectIterator itp(actor->sector());
2021-12-21 18:09:05 +00:00
while (auto act2 = itp.Next())
2020-05-10 07:08:02 +00:00
{
if (act2->spr.statnum != STAT_EFFECTOR && act2->spr.statnum != STAT_PROJECTILE && !actorflag(act2, SFLAG2_NOROTATEWITHSECTOR))
2022-01-19 09:48:18 +00:00
{
if (act2->isPlayer() && act2->GetOwner())
2020-05-10 07:08:02 +00:00
{
2022-01-19 09:48:18 +00:00
continue;
}
2020-05-10 07:08:02 +00:00
2022-09-11 16:01:27 +00:00
act2->spr.angle += ang_amount * direction;
2022-08-16 21:27:44 +00:00
act2->norm_ang();
2020-05-10 07:08:02 +00:00
2022-09-11 16:01:27 +00:00
act2->spr.pos.Z += zchange;
2022-09-11 16:41:52 +00:00
auto pos = rotatepoint(Owner->spr.pos, act2->spr.pos.XY(), ang_amount * direction);
act2->spr.pos.X = pos.X;
act2->spr.pos.Y = pos.Y;
2022-01-19 09:48:18 +00:00
}
2022-09-11 16:01:27 +00:00
}
2020-05-10 07:08:02 +00:00
}
2022-09-11 16:01:27 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 21:39:12 +00:00
void handle_se01(DDukeActor *actor)
2020-05-10 07:08:02 +00:00
{
int sh = actor->spr.hitag;
2020-10-21 21:39:12 +00:00
if (actor->GetOwner() == nullptr) //Init
2020-05-10 07:08:02 +00:00
{
2020-10-21 21:39:12 +00:00
actor->SetOwner(actor);
2020-05-10 07:08:02 +00:00
2020-10-21 21:39:12 +00:00
DukeStatIterator it(STAT_EFFECTOR);
while (auto ac = it.Next())
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
if (ac->spr.lotag == SE_19_EXPLOSION_LOWERS_CEILING && ac->spr.hitag == sh)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
break;
}
}
}
}
//---------------------------------------------------------------------------
//
2022-09-11 16:41:52 +00:00
// Subway car
2020-05-10 07:08:02 +00:00
//
2022-09-11 16:41:52 +00:00
// temp_data[1]: mspos index
// temp_angle: rotation angle
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int st = actor->spr.lotag;
2020-05-10 07:08:02 +00:00
2020-11-01 06:56:49 +00:00
if (actor->GetOwner() == nullptr)
2020-05-10 07:08:02 +00:00
{
auto NewOwner = LocateTheLocator(actor->temp_data[3], &sector[actor->temp_data[0]]);
2020-11-01 06:56:49 +00:00
if (NewOwner == nullptr)
{
I_Error("Could not find any locators for SE# 6 and 14 with a hitag of %d.", actor->temp_data[3]);
2020-11-01 06:56:49 +00:00
}
actor->SetOwner(NewOwner);
2020-05-10 07:08:02 +00:00
}
2020-11-01 06:56:49 +00:00
auto Owner = actor->GetOwner();
double dist = (Owner->spr.pos.XY() - actor->spr.pos.XY()).LengthSquared();
2020-05-10 07:08:02 +00:00
if (dist < 64*64)
2020-05-10 07:08:02 +00:00
{
if (st == 6)
if (Owner->spr.hitag & 1)
actor->temp_data[4] = sc->extra; //Slow it down
actor->temp_data[3]++;
auto NewOwner = LocateTheLocator(actor->temp_data[3], &sector[actor->temp_data[0]]);
2020-11-01 06:56:49 +00:00
if (NewOwner == nullptr)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[3] = 0;
NewOwner = LocateTheLocator(0, &sector[actor->temp_data[0]]);
2020-05-10 07:08:02 +00:00
}
2020-11-01 06:56:49 +00:00
if (NewOwner) actor->SetOwner(NewOwner);
2020-05-10 07:08:02 +00:00
}
2020-11-01 06:56:49 +00:00
Owner = actor->GetOwner();
if(actor->vel.X != 0)
2020-05-10 07:08:02 +00:00
{
auto curangle = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Angle();
2022-09-11 16:41:52 +00:00
auto diffangle = deltaangle(actor->spr.angle, curangle) * 0.125;
2020-05-10 07:08:02 +00:00
2022-09-11 16:41:52 +00:00
actor->temp_angle += diffangle;
actor->spr.angle += diffangle;
2020-05-10 07:08:02 +00:00
bool statstate = (!checkstat || ((sc->floorstat & CSTAT_SECTOR_SKY) == 0 && (sc->ceilingstat & CSTAT_SECTOR_SKY) == 0));
2022-09-11 16:41:52 +00:00
if (actor->vel.X == sc->extra * maptoworld)
2020-05-10 07:08:02 +00:00
{
if (statstate)
{
if (!S_CheckSoundPlaying(actor->tempsound))
S_PlayActorSound(actor->tempsound, actor);
2020-05-10 07:08:02 +00:00
}
if ((!checkstat || !statstate) && (ud.monsters_off == 0 && sc->floorpal == 0 && (sc->floorstat & CSTAT_SECTOR_SKY) && rnd(8)))
2020-05-10 07:08:02 +00:00
{
2022-09-13 21:44:21 +00:00
double dist2;
int p = findplayer(actor, &dist2);
if (dist2 < 1280)//20480)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
auto saved_angle = actor->spr.angle;
actor->spr.angle = (actor->spr.pos.XY() - ps[p].pos.XY()).Angle();
fi.shoot(actor, RPG);
2022-09-11 16:41:52 +00:00
actor->spr.angle = saved_angle;
2020-05-10 07:08:02 +00:00
}
}
}
2022-09-11 16:41:52 +00:00
if (actor->vel.X <= 4 && statstate)
S_StopSound(actor->tempsound, actor);
2020-05-10 07:08:02 +00:00
if ((sc->floorz - sc->ceilingz) < 108)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
if (ud.clipping == 0 && actor->vel.X >= 12)
2020-05-10 07:08:02 +00:00
for (int p = connecthead; p >= 0; p = connectpoint2[p])
2020-11-01 07:00:03 +00:00
{
auto psp = ps[p].GetActor();
if (psp->spr.extra > 0)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
auto sect = ps[p].cursector;
updatesector(ps[p].pos, &sect);
if ((sect == nullptr && ud.clipping == 0) || (sect == actor->sector() && ps[p].cursector != actor->sector()))
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:50:04 +00:00
ps[p].pos.XY() = actor->spr.pos.XY();
ps[p].setCursector(actor->sector());
2020-05-10 07:08:02 +00:00
SetActor(ps[p].GetActor(), actor->spr.pos);
2020-05-10 07:08:02 +00:00
quickkill(&ps[p]);
}
}
2020-11-01 07:00:03 +00:00
}
2020-05-10 07:08:02 +00:00
}
2022-09-11 16:41:52 +00:00
auto vec = actor->spr.angle.ToVector() * actor->vel.X;
2020-05-10 07:08:02 +00:00
for (int p = connecthead; p >= 0; p = connectpoint2[p])
2020-11-01 07:00:03 +00:00
{
auto psp = ps[p].GetActor();
if (ps[p].insector() && ps[p].cursector->lotag != 2)
2020-05-10 07:08:02 +00:00
{
if (po[p].os == actor->sector())
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
po[p].opos += vec;
2020-05-10 07:08:02 +00:00
}
if (actor->sector() == psp->sector())
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
auto result = rotatepoint(actor->spr.pos.XY(), ps[p].pos.XY(), diffangle);
2020-05-10 07:08:02 +00:00
2022-09-11 16:41:52 +00:00
ps[p].pos.XY() = result + vec;
2020-05-10 07:08:02 +00:00
2022-09-11 16:41:52 +00:00
ps[p].bobpos += vec;
2020-05-10 07:08:02 +00:00
2022-09-11 16:41:52 +00:00
ps[p].angle.addadjustment(diffangle);
2020-05-10 07:08:02 +00:00
if (numplayers > 1)
{
ps[p].backupxy();
2020-05-10 07:08:02 +00:00
}
if (psp->spr.extra <= 0)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
psp->spr.pos.XY() = ps[p].pos.XY();
2020-05-10 07:08:02 +00:00
}
}
}
2020-11-01 07:00:03 +00:00
}
DukeSectIterator it(actor->sector());
2020-11-01 07:00:03 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
2022-01-07 15:36:02 +00:00
if (a2->spr.statnum != STAT_PLAYER && a2->sector()->lotag != 2 &&
(a2->spr.picnum != SECTOREFFECTOR || a2->spr.lotag == SE_49_POINT_LIGHT || a2->spr.lotag == SE_50_SPOT_LIGHT) &&
a2->spr.picnum != LOCATORS)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
a2->spr.pos.XY() = rotatepoint(actor->spr.pos.XY(), a2->spr.pos.XY(), diffangle) + vec;
a2->spr.angle += diffangle;
2020-05-10 07:08:02 +00:00
if (numplayers > 1)
{
a2->backupvec2();
2020-05-10 07:08:02 +00:00
}
}
}
2022-09-11 16:41:52 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
// I have no idea why this is here, but the SE's sector must never, *EVER* change, or the map will corrupt.
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
if ((sc->floorz - sc->ceilingz) < 108)
2020-05-10 07:08:02 +00:00
{
2022-09-11 16:41:52 +00:00
if (ud.clipping == 0 && actor->vel.X >= 12)
2020-05-10 07:08:02 +00:00
for (int p = connecthead; p >= 0; p = connectpoint2[p])
2020-11-01 07:00:03 +00:00
{
if (ps[p].GetActor()->spr.extra > 0)
2020-05-10 07:08:02 +00:00
{
auto k = ps[p].cursector;
updatesector(ps[p].pos, &k);
if ((k == nullptr && ud.clipping == 0) || (k == actor->sector() && ps[p].cursector != actor->sector()))
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:50:04 +00:00
ps[p].pos.XY() = actor->spr.pos.XY();
ps[p].backupxy();
ps[p].setCursector(actor->sector());
2020-05-10 07:08:02 +00:00
2022-08-22 16:34:01 +00:00
SetActor(ps[p].GetActor(), actor->spr.pos);
2020-05-10 07:08:02 +00:00
quickkill(&ps[p]);
}
}
2020-11-01 07:00:03 +00:00
}
2020-05-10 07:08:02 +00:00
auto actOwner = actor->GetOwner();
if (actOwner)
2020-05-10 07:08:02 +00:00
{
DukeSectIterator itr(actOwner->sector());
2020-11-01 07:00:43 +00:00
while (auto a2 = itr.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->spr.statnum == 1 && badguy(a2) && a2->spr.picnum != SECTOREFFECTOR && a2->spr.picnum != LOCATORS)
2020-05-10 07:08:02 +00:00
{
auto k = a2->sector();
2022-09-11 16:41:52 +00:00
updatesector(a2->spr.pos, &k);
if (a2->spr.extra >= 0 && k == actor->sector())
2020-11-01 07:00:43 +00:00
{
gutsdir(a2, JIBS6, 72, myconnectindex);
2020-11-01 07:00:43 +00:00
S_PlayActorSound(SQUISHED, actor);
deletesprite(a2);
}
2020-05-10 07:08:02 +00:00
}
}
}
}
}
}
//---------------------------------------------------------------------------
//
2022-09-11 18:31:40 +00:00
// Two way train
2020-05-10 07:08:02 +00:00
//
2022-09-11 18:31:40 +00:00
// temp_data[1]: mspos index
// temp_angle: rotation angle
// temp_data[3]: locator tag
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:00:43 +00:00
void handle_se30(DDukeActor *actor, int JIBS6)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
2020-10-21 22:00:43 +00:00
auto Owner = actor->GetOwner();
if (Owner == nullptr)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[3] = !actor->temp_data[3];
Owner = LocateTheLocator(actor->temp_data[3], &sector[actor->temp_data[0]]);
2020-10-21 22:00:43 +00:00
actor->SetOwner(Owner);
2020-05-10 07:08:02 +00:00
}
else
{
2022-09-11 18:31:40 +00:00
auto dist = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Length();
if (actor->temp_data[4] == 1) // Starting to go
2020-05-10 07:08:02 +00:00
{
2022-09-11 18:31:40 +00:00
if (dist < (128 - 8))
actor->temp_data[4] = 2;
2020-05-10 07:08:02 +00:00
else
{
2022-09-11 18:31:40 +00:00
if (actor->vel.X == 0)
operateactivators(actor->spr.hitag + (!actor->temp_data[3]), -1);
2022-09-11 18:31:40 +00:00
if (actor->vel.X < 16)
2022-09-03 08:05:20 +00:00
actor->vel.X += 1;
2020-05-10 07:08:02 +00:00
}
}
if (actor->temp_data[4] == 2)
2020-05-10 07:08:02 +00:00
{
2022-09-11 18:31:40 +00:00
if (dist <= 8)
2022-09-03 08:02:25 +00:00
actor->vel.X = 0;
2020-05-10 07:08:02 +00:00
if(actor->vel.X > 0)
2022-09-03 08:05:20 +00:00
actor->vel.X -= 1;
2020-05-10 07:08:02 +00:00
else
{
2022-09-03 08:02:25 +00:00
actor->vel.X = 0;
operateactivators(actor->spr.hitag + (short)actor->temp_data[3], -1);
2020-10-21 22:00:43 +00:00
actor->SetOwner(nullptr);
2022-09-09 16:37:55 +00:00
actor->spr.angle += DAngle180;
actor->temp_data[4] = 0;
fi.operateforcefields(actor, actor->spr.hitag);
2020-05-10 07:08:02 +00:00
}
}
}
if(actor->vel.X != 0)
2020-05-10 07:08:02 +00:00
{
2022-09-11 18:31:40 +00:00
auto vect = actor->spr.angle.ToVector() * actor->vel.X;
2020-05-10 07:08:02 +00:00
if ((sc->floorz - sc->ceilingz) < 108)
2020-05-10 07:08:02 +00:00
if (ud.clipping == 0)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
2020-10-21 22:00:43 +00:00
{
auto psp = ps[p].GetActor();
if (psp->spr.extra > 0)
2020-05-10 07:08:02 +00:00
{
auto k = ps[p].cursector;
updatesector(ps[p].pos, &k);
if ((k == nullptr && ud.clipping == 0) || (k == actor->sector() && ps[p].cursector != actor->sector()))
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:50:04 +00:00
ps[p].pos.XY() = actor->spr.pos.XY();
ps[p].setCursector(actor->sector());
2020-05-10 07:08:02 +00:00
2022-08-22 16:34:01 +00:00
SetActor(ps[p].GetActor(), actor->spr.pos);
2020-05-10 07:08:02 +00:00
quickkill(&ps[p]);
}
}
2020-10-21 22:00:43 +00:00
}
2020-05-10 07:08:02 +00:00
for (int p = connecthead; p >= 0; p = connectpoint2[p])
{
2020-10-21 22:00:43 +00:00
auto psp = ps[p].GetActor();
if (psp->sector() == actor->sector())
2020-05-10 07:08:02 +00:00
{
2022-09-11 18:31:40 +00:00
ps[p].pos += vect;
2020-05-10 07:08:02 +00:00
if (numplayers > 1)
{
ps[p].backupxy();
2020-05-10 07:08:02 +00:00
}
2022-09-11 18:31:40 +00:00
ps[p].bobpos += vect;
2020-05-10 07:08:02 +00:00
}
if (po[p].os == actor->sector())
2020-05-10 07:08:02 +00:00
{
2022-09-11 18:31:40 +00:00
po[p].opos += vect;
2020-05-10 07:08:02 +00:00
}
}
DukeSectIterator its(actor->sector());
2020-10-21 22:00:43 +00:00
while (auto a2 = its.Next())
2020-05-10 07:08:02 +00:00
{
2021-12-21 18:09:05 +00:00
if (a2->spr.picnum != SECTOREFFECTOR && a2->spr.picnum != LOCATORS)
2020-05-10 07:08:02 +00:00
{
2022-09-11 18:31:40 +00:00
a2->spr.pos += vect;
2020-05-10 07:08:02 +00:00
if (numplayers > 1)
{
a2->backupvec2();
2020-05-10 07:08:02 +00:00
}
}
}
2022-09-11 18:31:40 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
if ((sc->floorz - sc->ceilingz) < 108)
2020-05-10 07:08:02 +00:00
{
if (ud.clipping == 0)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].GetActor()->spr.extra > 0)
2020-05-10 07:08:02 +00:00
{
auto k = ps[p].cursector;
updatesector(ps[p].pos, &k);
if ((k == nullptr && ud.clipping == 0) || (k == actor->sector() && ps[p].cursector != actor->sector()))
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:50:04 +00:00
ps[p].pos.XY() = actor->spr.pos.XY();
ps[p].backupxy();
2020-05-10 07:08:02 +00:00
ps[p].setCursector(actor->sector());
2020-05-10 07:08:02 +00:00
2022-08-22 16:34:01 +00:00
SetActor(ps[p].GetActor(), actor->spr.pos);
2020-05-10 07:08:02 +00:00
quickkill(&ps[p]);
}
}
2020-10-21 22:00:43 +00:00
if (Owner)
2020-05-10 07:08:02 +00:00
{
DukeSectIterator it(Owner->sector());
2020-10-21 22:00:43 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->spr.statnum == STAT_ACTOR && badguy(a2) && a2->spr.picnum != SECTOREFFECTOR && a2->spr.picnum != LOCATORS)
2020-05-10 07:08:02 +00:00
{
// if(a2->spr.sector != actor->spr.sector)
2020-05-10 07:08:02 +00:00
{
auto k = a2->sector();
2022-09-11 18:31:40 +00:00
updatesector(a2->spr.pos, &k);
if (a2->spr.extra >= 0 && k == actor->sector())
2020-10-21 22:00:43 +00:00
{
gutsdir(a2, JIBS6, 24, myconnectindex);
2020-10-21 22:00:43 +00:00
S_PlayActorSound(SQUISHED, a2);
deletesprite(a2);
2020-05-10 07:08:02 +00:00
}
}
}
}
}
}
2020-10-21 22:00:43 +00:00
}
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
2022-09-11 19:11:00 +00:00
// Earthquake
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
void handle_se02(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int sh = actor->spr.hitag;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[4] > 0 && actor->temp_data[0] == 0)
2020-05-10 07:08:02 +00:00
{
if (actor->temp_data[4] < sh)
actor->temp_data[4]++;
else actor->temp_data[0] = 1;
2020-05-10 07:08:02 +00:00
}
if (actor->temp_data[0] > 0)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
2022-09-11 19:11:00 +00:00
actor->vel.X = 3 / 16.;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] > 96)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[0] = -1; //Stop the quake
actor->temp_data[4] = -1;
2020-10-21 22:10:43 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
else
{
if ((actor->temp_data[0] & 31) == 8)
2020-05-10 07:08:02 +00:00
{
earthquaketime = 48;
2020-10-21 22:10:43 +00:00
S_PlayActorSound(EARTHQUAKE, ps[screenpeek].GetActor());
2020-05-10 07:08:02 +00:00
}
if (abs(sc->floorheinum - actor->temp_data[5]) < 8)
sc->setfloorslope(actor->temp_data[5]);
else sc->setfloorslope(sc->getfloorslope() + (Sgn(actor->temp_data[5] - sc->getfloorslope()) << 4));
2020-05-10 07:08:02 +00:00
}
2022-09-11 19:11:00 +00:00
auto vect = actor->spr.angle.ToVector() * actor->vel.X;
2020-05-10 07:08:02 +00:00
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].cursector == actor->sector() && ps[p].on_ground)
2020-05-10 07:08:02 +00:00
{
2022-09-11 19:11:00 +00:00
ps[p].pos += vect;
ps[p].bobpos += vect;
2020-05-10 07:08:02 +00:00
}
DukeSectIterator it(actor->sector());
2020-10-21 22:10:43 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
2021-12-21 18:09:05 +00:00
if (a2->spr.picnum != SECTOREFFECTOR)
2020-05-10 07:08:02 +00:00
{
2022-09-11 19:11:00 +00:00
a2->spr.pos += vect;
2022-08-22 16:34:01 +00:00
SetActor(a2, a2->spr.pos);
2020-05-10 07:08:02 +00:00
}
}
2022-09-11 19:11:00 +00:00
movesector(actor, actor->temp_data[1], nullAngle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
}
}
//---------------------------------------------------------------------------
//
2022-09-11 19:43:49 +00:00
// lights off
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:10:43 +00:00
void handle_se03(DDukeActor *actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int sh = actor->spr.hitag;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[4] == 0) return;
double xx;
findplayer(actor, &xx);
2020-10-21 22:10:43 +00:00
int palvals = actor->palvals;
2020-05-10 07:08:02 +00:00
if ((global_random / (sh + 1) & 31) < 4 && !actor->temp_data[2])
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:10:43 +00:00
sc->ceilingpal = palvals >> 8;
sc->floorpal = palvals & 0xff;
actor->temp_data[0] = actor->spr.shade + (global_random & 15);
2020-05-10 07:08:02 +00:00
}
else
{
sc->ceilingpal = actor->spr.pal;
sc->floorpal = actor->spr.pal;
actor->temp_data[0] = actor->temp_data[3];
2020-05-10 07:08:02 +00:00
}
sc->ceilingshade = actor->temp_data[0];
sc->floorshade = actor->temp_data[0];
2020-05-10 07:08:02 +00:00
for(auto& wal : wallsofsector(sc))
2020-05-10 07:08:02 +00:00
{
if (wal.hitag != 1)
2020-05-10 07:08:02 +00:00
{
wal.shade = actor->temp_data[0];
if ((wal.cstat & CSTAT_WALL_BOTTOM_SWAP) && wal.twoSided())
2020-05-10 07:08:02 +00:00
{
wal.nextWall()->shade = wal.shade;
2020-05-10 07:08:02 +00:00
}
}
}
}
//---------------------------------------------------------------------------
//
2022-09-11 19:43:49 +00:00
// lights
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:10:43 +00:00
void handle_se04(DDukeActor *actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int sh = actor->spr.hitag;
2020-05-10 07:08:02 +00:00
int j;
int palvals = actor->palvals;
2020-10-21 22:10:43 +00:00
2020-05-10 07:08:02 +00:00
if ((global_random / (sh + 1) & 31) < 4)
{
actor->temp_data[1] = actor->spr.shade + (global_random & 15);//Got really bright
actor->temp_data[0] = actor->spr.shade + (global_random & 15);
2020-10-21 22:10:43 +00:00
sc->ceilingpal = palvals >> 8;
sc->floorpal = palvals & 0xff;
2020-05-10 07:08:02 +00:00
j = 1;
}
else
{
actor->temp_data[1] = actor->temp_data[2];
actor->temp_data[0] = actor->temp_data[3];
2020-05-10 07:08:02 +00:00
sc->ceilingpal = actor->spr.pal;
sc->floorpal = actor->spr.pal;
2020-05-10 07:08:02 +00:00
j = 0;
}
sc->floorshade = actor->temp_data[1];
sc->ceilingshade = actor->temp_data[1];
2020-05-10 07:08:02 +00:00
for (auto& wal : wallsofsector(sc))
2020-05-10 07:08:02 +00:00
{
if (j) wal.pal = (palvals & 0xff);
else wal.pal = actor->spr.pal;
2020-05-10 07:08:02 +00:00
if (wal.hitag != 1)
2020-05-10 07:08:02 +00:00
{
wal.shade = actor->temp_data[0];
if ((wal.cstat & CSTAT_WALL_BOTTOM_SWAP) && wal.twoSided())
wal.nextWall()->shade = wal.shade;
2020-05-10 07:08:02 +00:00
}
}
DukeSectIterator it(actor->sector());
2020-10-21 22:10:43 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
2021-12-21 18:09:05 +00:00
if (a2->spr.cstat & CSTAT_SPRITE_ALIGNMENT_WALL)
2020-05-10 07:08:02 +00:00
{
if (sc->ceilingstat & CSTAT_SECTOR_SKY)
2021-12-21 18:09:05 +00:00
a2->spr.shade = sc->ceilingshade;
else a2->spr.shade = sc->floorshade;
2020-05-10 07:08:02 +00:00
}
}
if (actor->temp_data[4])
2020-10-21 22:10:43 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
2022-09-11 19:43:49 +00:00
// boss
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:14:54 +00:00
void handle_se05(DDukeActor* actor, int FIRELASER)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2022-09-11 19:43:49 +00:00
int j;
2020-05-10 07:08:02 +00:00
2022-09-11 19:43:49 +00:00
double x;
int p = findplayer(actor, &x);
if (x < 512)
2020-05-10 07:08:02 +00:00
{
2022-08-20 19:14:00 +00:00
auto ang = actor->spr.angle;
actor->spr.angle = (actor->spr.pos.XY() - ps[p].pos).Angle();
fi.shoot(actor, FIRELASER);
2022-08-20 19:14:00 +00:00
actor->spr.angle = ang;
2020-05-10 07:08:02 +00:00
}
2020-10-21 22:14:54 +00:00
auto Owner = actor->GetOwner();
if (Owner == nullptr) //Start search
2020-05-10 07:08:02 +00:00
{
actor->temp_data[4] = 0;
2022-09-11 19:43:49 +00:00
double maxdist = 0x7fffffff;
2020-05-10 07:08:02 +00:00
while (1) //Find the shortest dist
{
auto NewOwner = LocateTheLocator(actor->temp_data[4], nullptr);
2020-10-21 22:14:54 +00:00
if (NewOwner == nullptr) break;
2020-05-10 07:08:02 +00:00
2022-09-11 19:43:49 +00:00
double dist = (ps[p].GetActor()->spr.pos.XY() - NewOwner->spr.pos.XY()).LengthSquared();
2020-05-10 07:08:02 +00:00
2022-09-11 19:43:49 +00:00
if (maxdist > dist)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:14:54 +00:00
Owner = NewOwner;
2022-09-11 19:43:49 +00:00
maxdist = dist;
2020-05-10 07:08:02 +00:00
}
actor->temp_data[4]++;
2020-05-10 07:08:02 +00:00
}
2020-10-21 22:14:54 +00:00
actor->SetOwner(Owner);
if (!Owner) return; // Undefined case - was not checked.
2022-09-11 19:43:49 +00:00
actor->vel.Z = (Sgn(Owner->spr.pos.Z - actor->spr.pos.Z) / 16);
2020-05-10 07:08:02 +00:00
}
2022-09-11 19:43:49 +00:00
if ((Owner->spr.pos.XY() - actor->spr.pos.XY()).LengthSquared() < 64 * 64)
2020-05-10 07:08:02 +00:00
{
2022-08-20 19:14:00 +00:00
// Huh?
//auto ta = actor->spr.angle;
//actor->spr.angle = (ps[p].pos.XY() - actor->spr.pos.XY()).Angle();
2022-08-20 19:14:00 +00:00
//actor->spr.angle = ta;
2020-10-21 22:14:54 +00:00
actor->SetOwner(nullptr);
2020-05-10 07:08:02 +00:00
return;
}
2022-09-11 19:43:49 +00:00
else actor->vel.X = 16;
2020-05-10 07:08:02 +00:00
auto ang = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Angle();
2022-09-11 19:43:49 +00:00
auto angdiff = deltaangle(actor->spr.angle, ang) / 8;
actor->spr.angle += angdiff;
2020-05-10 07:08:02 +00:00
if (rnd(32))
{
2022-09-11 19:43:49 +00:00
actor->temp_angle += angdiff;
2020-05-10 07:08:02 +00:00
sc->ceilingshade = 127;
}
else
{
2022-09-11 19:43:49 +00:00
actor->temp_angle +=
deltaangle(actor->temp_angle + DAngle90, (ps[p].pos.XY() - actor->spr.pos.XY()).Angle()) * 0.25;
2020-05-10 07:08:02 +00:00
sc->ceilingshade = 0;
}
2020-10-21 22:14:54 +00:00
j = fi.ifhitbyweapon(actor);
2020-05-10 07:08:02 +00:00
if (j >= 0)
{
actor->temp_data[3]++;
if (actor->temp_data[3] == 5)
2020-05-10 07:08:02 +00:00
{
2022-09-11 17:28:45 +00:00
actor->vel.Z += 4;
2020-05-10 07:08:02 +00:00
FTA(7, &ps[myconnectindex]);
}
}
actor->spr.pos.Z += actor->vel.Z;
2022-09-04 20:51:39 +00:00
sc->setceilingz(actor->vel.Z);
sector[actor->temp_data[0]].setceilingz(actor->vel.Z);
2022-09-11 19:43:49 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:14:54 +00:00
void handle_se08(DDukeActor *actor, bool checkhitag1)
2020-05-10 07:08:02 +00:00
{
// work only if its moving
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int st = actor->spr.lotag;
int sh = actor->spr.hitag;
2020-05-10 07:08:02 +00:00
2022-09-11 19:46:47 +00:00
int change, goal = -1;
2020-05-10 07:08:02 +00:00
2020-10-21 22:14:54 +00:00
if (actor->temp_data[4])
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:14:54 +00:00
actor->temp_data[4]++;
if (actor->temp_data[4] > 8)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:14:54 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
2022-09-11 19:46:47 +00:00
goal = 1;
2020-05-10 07:08:02 +00:00
}
2022-09-12 17:47:07 +00:00
else goal = getanimationindex(anim_ceilingz, actor->sector());
2020-05-10 07:08:02 +00:00
2022-09-11 19:46:47 +00:00
if (goal >= 0)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:14:54 +00:00
if ((sc->lotag & 0x8000) || actor->temp_data[4])
2022-09-11 19:46:47 +00:00
change = -actor->temp_data[3];
2020-05-10 07:08:02 +00:00
else
2022-09-11 19:46:47 +00:00
change = actor->temp_data[3];
2020-05-10 07:08:02 +00:00
2022-09-11 19:46:47 +00:00
if (st == 9) change = -change;
2020-05-10 07:08:02 +00:00
2020-10-21 22:14:54 +00:00
DukeStatIterator it(STAT_EFFECTOR);
while (auto ac = it.Next())
2020-05-10 07:08:02 +00:00
{
if (((ac->spr.lotag) == st) && (ac->spr.hitag) == sh)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sect = ac->sector();
2022-09-11 19:46:47 +00:00
int minshade = ac->spr.shade;
2020-05-10 07:08:02 +00:00
for (auto& wal : wallsofsector(sect))
2020-05-10 07:08:02 +00:00
{
if (wal.hitag != 1)
2020-05-10 07:08:02 +00:00
{
2022-09-11 19:46:47 +00:00
wal.shade += change;
2020-05-10 07:08:02 +00:00
2022-09-11 19:46:47 +00:00
if (wal.shade < minshade)
wal.shade = minshade;
else if (wal.shade > ac->temp_data[2])
wal.shade = ac->temp_data[2];
2020-05-10 07:08:02 +00:00
if (wal.twoSided())
if (wal.nextWall()->hitag != 1)
wal.nextWall()->shade = wal.shade;
2020-05-10 07:08:02 +00:00
}
}
2022-09-11 19:46:47 +00:00
sect->floorshade += change;
sect->ceilingshade += change;
2020-05-10 07:08:02 +00:00
2022-09-11 19:46:47 +00:00
if (sect->floorshade < minshade)
sect->floorshade = minshade;
2020-10-21 22:14:54 +00:00
else if (sect->floorshade > ac->temp_data[0])
sect->floorshade = ac->temp_data[0];
2020-05-10 07:08:02 +00:00
2022-09-11 19:46:47 +00:00
if (sect->ceilingshade < minshade)
sect->ceilingshade = minshade;
2020-10-21 22:14:54 +00:00
else if (sect->ceilingshade > ac->temp_data[1])
sect->ceilingshade = ac->temp_data[1];
2020-05-10 07:08:02 +00:00
if (checkhitag1 && sect->hitag == 1)
2020-10-21 22:14:54 +00:00
sect->ceilingshade = ac->temp_data[1];
2020-05-10 07:08:02 +00:00
}
}
}
}
//---------------------------------------------------------------------------
//
2022-09-11 20:06:20 +00:00
// door auto close
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:14:54 +00:00
void handle_se10(DDukeActor* actor, const int* specialtags)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int sh = actor->spr.hitag;
2020-05-10 07:08:02 +00:00
if ((sc->lotag & 0xff) == 27 || (sc->floorz > sc->ceilingz && (sc->lotag & 0xff) != 23) || sc->lotag == 32791 - 65536)
2020-05-10 07:08:02 +00:00
{
int j = 1;
if ((sc->lotag & 0xff) != 27)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (sc->lotag != 30 && sc->lotag != 31 && sc->lotag != 0)
if (actor->sector() == ps[p].GetActor()->sector())
2020-05-10 07:08:02 +00:00
j = 0;
if (j == 1)
{
if (actor->temp_data[0] > sh)
2020-05-10 07:08:02 +00:00
{
if (specialtags) for (int i = 0; specialtags[i]; i++)
{
2022-09-12 17:47:07 +00:00
if (actor->sector()->lotag == specialtags[i] && getanimationindex(anim_ceilingz, actor->sector()) >= 0)
2020-05-10 07:08:02 +00:00
{
return;
}
}
fi.activatebysector(actor->sector(), actor);
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
}
else actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
}
}
else actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
2022-09-11 20:06:20 +00:00
// swinging door
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:20:47 +00:00
void handle_se11(DDukeActor *actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
if (actor->temp_data[5] > 0)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[5]--;
2020-05-10 07:08:02 +00:00
return;
}
if (actor->temp_data[4])
2020-05-10 07:08:02 +00:00
{
for(auto& wal : wallsofsector(sc))
2020-05-10 07:08:02 +00:00
{
DukeStatIterator it(STAT_ACTOR);
2020-10-21 22:20:47 +00:00
while (auto ac = it.Next())
2020-05-10 07:08:02 +00:00
{
if (ac->spr.extra > 0 && badguy(ac) && IsCloseToWall(ac->spr.pos.XY(), &wal, 16) == EClose::InFront)
2020-05-10 07:08:02 +00:00
return;
}
}
int k = (actor->spr.yint >> 3) * actor->temp_data[3];
2022-09-11 20:06:20 +00:00
actor->temp_angle += mapangle(k);
actor->temp_data[4] += k;
2022-09-11 20:06:20 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
for(auto& wal : wallsofsector(sc))
{
DukeStatIterator it(STAT_PLAYER);
2020-10-21 22:20:47 +00:00
while (auto ac = it.Next())
2020-05-10 07:08:02 +00:00
{
if (ac->GetOwner() && IsCloseToWall(ac->spr.pos.XY(), &wal, 9) == EClose::InFront)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[5] = 8; // Delay
2022-09-11 20:06:20 +00:00
actor->temp_angle -= mapangle(k);
actor->temp_data[4] -= k;
2022-09-11 20:06:20 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
return;
}
}
}
if (actor->temp_data[4] <= -511 || actor->temp_data[4] >= 512)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[4] = 0;
2022-09-11 20:06:20 +00:00
actor->temp_angle = mapangle(actor->temp_angle.Buildang() & 0xffffff00); // Gross hack! What is this supposed to do?
movesector(actor, actor->temp_data[1], actor->temp_angle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:20:47 +00:00
void handle_se12(DDukeActor *actor, int planeonly)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
if (actor->temp_data[0] == 3 || actor->temp_data[3] == 1) //Lights going off
2020-05-10 07:08:02 +00:00
{
sc->floorpal = 0;
sc->ceilingpal = 0;
for (auto& wal : wallsofsector(sc))
{
if (wal.hitag != 1)
2020-05-10 07:08:02 +00:00
{
wal.shade = actor->temp_data[1];
wal.pal = 0;
2020-05-10 07:08:02 +00:00
}
}
sc->floorshade = actor->temp_data[1];
sc->ceilingshade = actor->temp_data[2];
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
2021-11-20 23:33:17 +00:00
DukeSectIterator it(sc);
2020-10-21 22:20:47 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->spr.cstat & CSTAT_SPRITE_ALIGNMENT_WALL)
2020-05-10 07:08:02 +00:00
{
if (sc->ceilingstat & CSTAT_SECTOR_SKY)
a2->spr.shade = sc->ceilingshade;
else a2->spr.shade = sc->floorshade;
2020-05-10 07:08:02 +00:00
}
}
if (actor->temp_data[3] == 1)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:20:47 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
if (actor->temp_data[0] == 1) //Lights flickering on
2020-05-10 07:08:02 +00:00
{
// planeonly 1 is RRRA SE47, planeonly 2 is SE48
int compshade = planeonly == 2 ? sc->ceilingshade : sc->floorshade;
if (compshade > actor->spr.shade)
2020-05-10 07:08:02 +00:00
{
if (planeonly != 2) sc->floorpal = actor->spr.pal;
if (planeonly != 1) sc->ceilingpal = actor->spr.pal;
2020-05-10 07:08:02 +00:00
if (planeonly != 2) sc->floorshade -= 2;
if (planeonly != 1) sc->ceilingshade -= 2;
for (auto& wal : wallsofsector(sc))
{
if (wal.hitag != 1)
2020-05-10 07:08:02 +00:00
{
wal.pal = actor->spr.pal;
wal.shade -= 2;
2020-05-10 07:08:02 +00:00
}
}
2020-05-10 07:08:02 +00:00
}
else actor->temp_data[0] = 2;
2020-05-10 07:08:02 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 22:20:47 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->spr.cstat & CSTAT_SPRITE_ALIGNMENT_WALL)
2020-05-10 07:08:02 +00:00
{
if (sc->ceilingstat & CSTAT_SECTOR_SKY)
a2->spr.shade = sc->ceilingshade;
else a2->spr.shade = sc->floorshade;
2020-05-10 07:08:02 +00:00
}
}
}
}
//---------------------------------------------------------------------------
//
2022-09-11 20:28:05 +00:00
// explosive
2020-05-10 07:08:02 +00:00
//
//---------------------------------------------------------------------------
2020-10-21 22:20:47 +00:00
void handle_se13(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
if (actor->temp_data[2])
2020-05-10 07:08:02 +00:00
{
2022-09-11 20:28:05 +00:00
double amt = ((actor->spr.yint << 5) | 1) * zmaptoworld;
2020-05-10 07:08:02 +00:00
2022-09-11 20:28:05 +00:00
if (actor->spr.intangle == 512)
2020-05-10 07:08:02 +00:00
{
if (actor->spriteextra)
2020-05-10 07:08:02 +00:00
{
2022-09-11 20:28:05 +00:00
if (abs(actor->temp_pos.Y - sc->ceilingz) >= amt)
sc->addceilingz(Sgn(actor->temp_pos.Y - sc->ceilingz) * amt);
else sc->setceilingz(actor->temp_pos.Y);
2020-05-10 07:08:02 +00:00
}
else
{
2022-09-11 20:28:05 +00:00
if (abs(actor->temp_pos.Z - sc->floorz) >= amt)
sc->addfloorz(Sgn(actor->temp_pos.Z - sc->floorz) * amt);
else sc->setfloorz(actor->temp_pos.Z);
2020-05-10 07:08:02 +00:00
}
}
else
{
2022-09-11 20:28:05 +00:00
if (abs(actor->temp_pos.Z - sc->floorz) >= amt)
sc->addfloorz(Sgn(actor->temp_pos.Z - sc->floorz) * amt);
else sc->setfloorz(actor->temp_pos.Z);
if (abs(actor->temp_pos.Y - sc->ceilingz) >= amt)
sc->addceilingz(Sgn(actor->temp_pos.Y - sc->ceilingz) * amt);
sc->setceilingz(actor->temp_pos.Y);
2020-05-10 07:08:02 +00:00
}
if (actor->temp_data[3] == 1)
2020-05-10 07:08:02 +00:00
{
//Change the shades
actor->temp_data[3]++;
2021-12-18 12:23:08 +00:00
sc->ceilingstat ^= CSTAT_SECTOR_SKY;
2020-05-10 07:08:02 +00:00
if (actor->spr.intangle == 512)
2020-05-10 07:08:02 +00:00
{
for (auto& wal : wallsofsector(sc))
wal.shade = actor->spr.shade;
2020-05-10 07:08:02 +00:00
sc->floorshade = actor->spr.shade;
2020-05-10 07:08:02 +00:00
2021-11-17 23:08:52 +00:00
if (ps[0].one_parallax_sectnum != nullptr)
2020-05-10 07:08:02 +00:00
{
2021-11-17 23:08:52 +00:00
sc->ceilingpicnum = ps[0].one_parallax_sectnum->ceilingpicnum;
sc->ceilingshade = ps[0].one_parallax_sectnum->ceilingshade;
2020-05-10 07:08:02 +00:00
}
}
}
actor->temp_data[2]++;
if (actor->temp_data[2] > 256)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:20:47 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
2022-09-11 20:28:05 +00:00
if (actor->temp_data[2] == 4 && actor->spr.angle != DAngle90)
2020-10-21 22:20:47 +00:00
for (int x = 0; x < 7; x++) RANDOMSCRAP(actor);
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:25:11 +00:00
void handle_se15(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
if (actor->temp_data[4])
2020-05-10 07:08:02 +00:00
{
2022-09-03 08:05:20 +00:00
actor->vel.X = 1;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[4] == 1) //Opening
2020-05-10 07:08:02 +00:00
{
if (actor->temp_data[3] >= (actor->spr.yint >> 3))
2020-05-10 07:08:02 +00:00
{
actor->temp_data[4] = 0; //Turn off the sliders
callsound(actor->sector(), actor);
2020-05-10 07:08:02 +00:00
return;
}
actor->temp_data[3]++;
2020-05-10 07:08:02 +00:00
}
else if (actor->temp_data[4] == 2)
2020-05-10 07:08:02 +00:00
{
if (actor->temp_data[3] < 1)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[4] = 0;
callsound(actor->sector(), actor);
2020-05-10 07:08:02 +00:00
return;
}
actor->temp_data[3]--;
2020-05-10 07:08:02 +00:00
}
movesector(actor, actor->temp_data[1], nullAngle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:25:11 +00:00
void handle_se16(DDukeActor* actor, int REACTOR, int REACTOR2)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
2022-09-14 19:08:27 +00:00
actor->temp_angle += DAngle22_5 / 4;
if (sc->floorz < sc->ceilingz) actor->spr.shade = 0;
2020-05-10 07:08:02 +00:00
2022-09-14 19:08:27 +00:00
else if (sc->ceilingz < actor->temp_pos.Z)
2020-05-10 07:08:02 +00:00
{
//The following code check to see if
//there is any other sprites in the sector.
//If there isn't, then kill this sectoreffector
//itself.....
DukeSectIterator it(actor->sector());
2020-10-21 22:25:11 +00:00
DDukeActor* a2;
while ((a2 = it.Next()))
2020-05-10 07:08:02 +00:00
{
if (a2->spr.picnum == REACTOR || a2->spr.picnum == REACTOR2)
2020-05-10 07:08:02 +00:00
return;
}
2020-10-21 22:25:11 +00:00
if (a2 == nullptr)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:25:11 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
else actor->spr.shade = 1;
2020-05-10 07:08:02 +00:00
}
if (actor->spr.shade) sc->addceilingz(4);
else sc->addceilingz(-2);
2020-05-10 07:08:02 +00:00
2022-09-14 19:08:27 +00:00
movesector(actor, actor->temp_data[1], actor->temp_angle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:25:11 +00:00
void handle_se17(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int sh = actor->spr.hitag;
2022-09-14 19:04:07 +00:00
double refheight = actor->spr.yint * zmaptoworld;
2020-05-10 07:08:02 +00:00
2022-09-14 19:04:07 +00:00
double q = actor->temp_data[0] * refheight * 4;
2020-05-10 07:08:02 +00:00
sc->addceilingz(q);
sc->addfloorz(q);
2020-05-10 07:08:02 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 22:25:11 +00:00
while (auto act1 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (act1->spr.statnum == STAT_PLAYER && act1->GetOwner())
2020-05-10 07:08:02 +00:00
{
int p = act1->spr.yint;
2022-02-05 12:32:34 +00:00
ps[p].pos.Z += q;
ps[p].truefz += q;
ps[p].truecz += q;
2020-05-10 07:08:02 +00:00
}
if (act1->spr.statnum != STAT_EFFECTOR)
2020-05-10 07:08:02 +00:00
{
act1->spr.pos.Z += q;
2020-05-10 07:08:02 +00:00
}
act1->floorz = sc->floorz;
act1->ceilingz = sc->ceilingz;
2020-05-10 07:08:02 +00:00
}
if (actor->temp_data[0]) //If in motion
2020-05-10 07:08:02 +00:00
{
2022-09-14 19:04:07 +00:00
if (abs(sc->floorz - actor->temp_pos.X) <= refheight)
2020-05-10 07:08:02 +00:00
{
2020-10-23 15:46:46 +00:00
activatewarpelevators(actor, 0);
2020-05-10 07:08:02 +00:00
return;
}
if (actor->temp_data[0] == -1)
2020-05-10 07:08:02 +00:00
{
2022-09-14 19:04:07 +00:00
if (sc->floorz > actor->temp_pos.Y)
2020-05-10 07:08:02 +00:00
return;
}
2022-09-14 19:04:07 +00:00
else if (sc->ceilingz < actor->temp_pos.Z) return;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[1] == 0) return;
actor->temp_data[1] = 0;
2020-05-10 07:08:02 +00:00
2020-10-21 22:25:11 +00:00
DDukeActor* act2;
DukeStatIterator itr(STAT_EFFECTOR);
while ((act2 = itr.Next()))
2020-05-10 07:08:02 +00:00
{
if (actor != act2 && (act2->spr.lotag) == 17)
if ((sc->hitag - actor->temp_data[0]) == (act2->sector()->hitag) && sh == (act2->spr.hitag))
2020-05-10 07:08:02 +00:00
break;
}
2020-10-21 22:25:11 +00:00
if (act2 == nullptr) return;
2020-05-10 07:08:02 +00:00
DukeSectIterator its(actor->sector());
2020-10-21 22:25:11 +00:00
while (auto act3 = its.Next())
2020-05-10 07:08:02 +00:00
{
2021-12-21 18:09:05 +00:00
if (act3->spr.statnum == STAT_PLAYER && act3->GetOwner())
2020-05-10 07:08:02 +00:00
{
int p = act3->PlayerIndex();
2020-05-10 07:08:02 +00:00
ps[p].opos -= ps[p].pos;
ps[p].pos.XY() += act2->spr.pos.XY() - actor->spr.pos.XY();
ps[p].pos.Z += act2->sector()->floorz - sc->floorz;
ps[p].opos += ps[p].pos;
if (q > 0) ps[p].backupz();
2020-05-10 07:08:02 +00:00
act3->floorz = act2->sector()->floorz;
act3->ceilingz = act2->sector()->ceilingz;
2020-05-10 07:08:02 +00:00
ps[p].setbobpos();
2020-05-10 07:08:02 +00:00
ps[p].truefz = act3->floorz;
ps[p].truecz = act3->ceilingz;
2020-05-10 07:08:02 +00:00
ps[p].bobcounter = 0;
ChangeActorSect(act3, act2->sector());
ps[p].setCursector(act2->sector());
2020-05-10 07:08:02 +00:00
}
2021-12-21 18:09:05 +00:00
else if (act3->spr.statnum != STAT_EFFECTOR)
2020-05-10 07:08:02 +00:00
{
act3->opos -= act3->spr.pos;
act3->spr.pos.XY() += act2->spr.pos.XY() - actor->spr.pos.XY();
act3->spr.pos.Z += act2->sector()->floorz - sc->floorz;
act3->opos += act3->spr.pos;
2020-05-10 07:08:02 +00:00
if (q > 0) act3->backupz();
2020-05-10 07:08:02 +00:00
ChangeActorSect(act3, act2->sector());
2022-08-22 16:34:01 +00:00
SetActor(act3, act3->spr.pos);
2020-05-10 07:08:02 +00:00
act3->floorz = act2->sector()->floorz;
act3->ceilingz = act2->sector()->ceilingz;
2020-05-10 07:08:02 +00:00
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:30:22 +00:00
void handle_se18(DDukeActor *actor, bool morecheck)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
double extra = sc->extra * zmaptoworld;
double goal = FixedToFloat<8>(actor->temp_data[1]);
if (actor->temp_data[0])
2020-05-10 07:08:02 +00:00
{
if (actor->spr.pal)
2020-05-10 07:08:02 +00:00
{
if (actor->spr.intangle == 512)
2020-05-10 07:08:02 +00:00
{
sc->addceilingz(-extra);
if (sc->ceilingz <= goal)
2020-05-10 07:08:02 +00:00
{
sc->setceilingz(goal);
2020-10-21 22:30:22 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
else
{
sc->addfloorz(extra);
2020-05-10 07:08:02 +00:00
if (morecheck)
{
DukeSectIterator it(actor->sector());
2020-10-21 22:30:22 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->isPlayer() && a2->GetOwner())
{
2022-02-05 12:32:34 +00:00
if (ps[a2->PlayerIndex()].on_ground == 1) ps[a2->PlayerIndex()].pos.Z += extra;
}
if (a2->vel.Z == 0 && a2->spr.statnum != STAT_EFFECTOR && a2->spr.statnum != STAT_PROJECTILE)
2020-05-10 07:08:02 +00:00
{
a2->spr.pos.Z += extra;
a2->floorz = sc->floorz;
2020-05-10 07:08:02 +00:00
}
}
}
if (sc->floorz >= goal)
2020-05-10 07:08:02 +00:00
{
sc->setfloorz(goal);
2020-10-21 22:30:22 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
}
else
{
if (actor->spr.intangle == 512)
2020-05-10 07:08:02 +00:00
{
sc->addceilingz(extra);
if (sc->ceilingz >= actor->spr.pos.Z)
2020-05-10 07:08:02 +00:00
{
2022-02-07 07:59:20 +00:00
sc->setceilingz(actor->spr.pos.Z);
2020-10-21 22:30:22 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
else
{
sc->addfloorz(-extra);
2020-05-10 07:08:02 +00:00
if (morecheck)
{
DukeSectIterator it(actor->sector());
2020-10-21 22:30:22 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->isPlayer() && a2->GetOwner())
{
2022-02-05 12:32:34 +00:00
if (ps[a2->PlayerIndex()].on_ground == 1) ps[a2->PlayerIndex()].pos.Z -= extra;
}
if (a2->vel.Z == 0 && a2->spr.statnum != STAT_EFFECTOR && a2->spr.statnum != STAT_PROJECTILE)
2020-05-10 07:08:02 +00:00
{
a2->spr.pos.Z -= extra;
a2->floorz = sc->floorz;
2020-05-10 07:08:02 +00:00
}
}
}
if (sc->floorz <= actor->spr.pos.Z)
2020-05-10 07:08:02 +00:00
{
2022-02-07 07:59:20 +00:00
sc->setfloorz(actor->spr.pos.Z);
2020-10-21 22:30:22 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
}
actor->temp_data[2]++;
if (actor->temp_data[2] >= actor->spr.hitag)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[2] = 0;
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
DDukeActor* ifhitsectors(sectortype* sect)
{
DukeStatIterator it(STAT_MISC);
while (auto a1 = it.Next())
{
2022-01-07 15:36:02 +00:00
if (actorflag(a1, SFLAG_TRIGGER_IFHITSECTOR) && sect == a1->sector())
return a1;
}
return nullptr;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:30:22 +00:00
void handle_se19(DDukeActor *actor, int BIGFORCE)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
int sh = actor->spr.hitag;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0])
2020-05-10 07:08:02 +00:00
{
if (actor->temp_data[0] == 1)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[0]++;
2021-11-15 21:59:51 +00:00
for (auto& wal : wallsofsector(sc))
{
if (wal.overpicnum == BIGFORCE)
2020-05-10 07:08:02 +00:00
{
2021-12-18 14:16:31 +00:00
wal.cstat &= (CSTAT_WALL_TRANSLUCENT | CSTAT_WALL_1WAY | CSTAT_WALL_XFLIP | CSTAT_WALL_ALIGN_BOTTOM | CSTAT_WALL_BOTTOM_SWAP);
2021-11-15 21:59:51 +00:00
wal.overpicnum = 0;
auto nextwal = wal.nextWall();
if (nextwal != nullptr)
2020-05-10 07:08:02 +00:00
{
2021-11-15 21:59:51 +00:00
nextwal->overpicnum = 0;
2021-12-18 14:16:31 +00:00
nextwal->cstat &= (CSTAT_WALL_TRANSLUCENT | CSTAT_WALL_1WAY | CSTAT_WALL_XFLIP | CSTAT_WALL_ALIGN_BOTTOM | CSTAT_WALL_BOTTOM_SWAP);
2020-05-10 07:08:02 +00:00
}
}
2021-11-15 21:59:51 +00:00
}
2020-05-10 07:08:02 +00:00
}
if (sc->ceilingz < sc->floorz)
sc->addceilingz(actor->spr.yint * zmaptoworld);
2020-05-10 07:08:02 +00:00
else
{
sc->setceilingz(sc->floorz);
2020-05-10 07:08:02 +00:00
2020-10-21 22:30:22 +00:00
DukeStatIterator it(STAT_EFFECTOR);
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:30:22 +00:00
auto a2Owner = a2->GetOwner();
if (a2->spr.lotag == 0 && a2->spr.hitag == sh && a2Owner)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sectp = a2Owner->sector();
a2->sector()->floorpal = a2->sector()->ceilingpal = sectp->floorpal;
a2->sector()->floorshade = a2->sector()->ceilingshade = sectp->floorshade;
2020-10-21 22:30:22 +00:00
a2Owner->temp_data[0] = 2;
2020-05-10 07:08:02 +00:00
}
}
2020-10-21 22:30:22 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
}
else //Not hit yet
{
auto hitter = ifhitsectors(actor->sector());
2020-10-21 22:30:22 +00:00
if (hitter)
2020-05-10 07:08:02 +00:00
{
FTA(8, &ps[myconnectindex]);
2020-10-21 22:30:22 +00:00
DukeStatIterator it(STAT_EFFECTOR);
while (auto ac = it.Next())
2020-05-10 07:08:02 +00:00
{
int x = ac->spr.lotag & 0x7fff;
2020-05-10 07:08:02 +00:00
switch (x)
{
case 0:
if (ac->spr.hitag == sh && ac->GetOwner())
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sectp = ac->sector();
sectp->floorshade = sectp->ceilingshade = ac->GetOwner()->spr.shade;
sectp->floorpal = sectp->ceilingpal = ac->GetOwner()->spr.pal;
2020-05-10 07:08:02 +00:00
}
break;
case 1:
case 12:
//case 18:
case 19:
if (sh == ac->spr.hitag)
2020-10-21 22:30:22 +00:00
if (ac->temp_data[0] == 0)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:30:22 +00:00
ac->temp_data[0] = 1; //Shut them all on
ac->SetOwner(actor);
2020-05-10 07:08:02 +00:00
}
break;
}
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:35:30 +00:00
void handle_se20(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] == 0) return;
2020-05-10 07:08:02 +00:00
2022-09-11 22:56:23 +00:00
//if(actor->vel.X != 0) //Moving
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:56:23 +00:00
auto vec = actor->spr.angle.ToVector() * (actor->temp_data[0] == 1 ? 0.5 : -0.5);
2020-05-10 07:08:02 +00:00
2022-09-11 22:56:23 +00:00
actor->temp_data[3] += actor->temp_data[0] == 1? 8 :- 8;
2020-05-10 07:08:02 +00:00
2022-09-11 22:56:23 +00:00
actor->spr.pos += vec;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[3] <= 0 || (actor->temp_data[3] >> 6) >= (actor->spr.yint >> 6))
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:56:23 +00:00
actor->spr.pos -= vec;
actor->temp_data[0] = 0;
callsound(actor->sector(), actor);
2020-05-10 07:08:02 +00:00
return;
}
DukeSectIterator it(actor->sector());
2020-10-21 22:35:30 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->spr.statnum != STAT_EFFECTOR && a2->vel.Z == 0)
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:56:23 +00:00
actor->spr.pos += vec;
2021-12-18 12:23:08 +00:00
if (a2->sector()->floorstat & CSTAT_SECTOR_SLOPE)
if (a2->spr.statnum == 2)
2020-10-21 22:35:30 +00:00
makeitfall(a2);
2020-05-10 07:08:02 +00:00
}
}
auto& wal = actor->temp_walls;
2022-09-11 22:56:23 +00:00
dragpoint(wal[0], wal[0]->pos + vec);
dragpoint(wal[1], wal[1]->pos + vec);
2020-05-10 07:08:02 +00:00
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].cursector == actor->sector() && ps[p].on_ground)
2020-05-10 07:08:02 +00:00
{
2022-09-11 22:56:23 +00:00
ps[p].pos += vec;
ps[p].backupxy();
2020-05-10 07:08:02 +00:00
2022-02-05 12:32:34 +00:00
SetActor(ps[p].GetActor(), ps[p].pos.plusZ(gs.playerheight));
2020-05-10 07:08:02 +00:00
}
2022-09-11 22:56:23 +00:00
sc->addfloorxpan(-vec.X * 2);
sc->addfloorypan(-vec.Y * 2);
2020-05-10 07:08:02 +00:00
2022-09-11 22:56:23 +00:00
sc->addceilingxpan(-vec.X * 2);
sc->addceilingypan(-vec.Y * 2);
2020-05-10 07:08:02 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:35:30 +00:00
void handle_se21(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2022-09-11 21:35:31 +00:00
double lp;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] == 0) return;
2020-05-10 07:08:02 +00:00
2022-09-11 21:35:31 +00:00
if (actor->spr.intangle == 1536)
lp = sc->ceilingz;
2020-05-10 07:08:02 +00:00
else
2022-09-11 21:35:31 +00:00
lp = sc->floorz;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] == 1) //Decide if the sector should go up or down
2020-05-10 07:08:02 +00:00
{
2022-09-11 21:35:31 +00:00
actor->vel.Z = (Sgn(actor->spr.pos.Z - lp) * (actor->spr.yint << 4) * zmaptoworld);
actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
}
if (sc->extra == 0)
{
lp += actor->vel.Z;
2020-05-10 07:08:02 +00:00
if (abs(lp - actor->spr.pos.Z) < 4)
2020-05-10 07:08:02 +00:00
{
lp = actor->spr.pos.Z;
2020-10-21 22:35:30 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
}
if (actor->spr.intangle == 1536)
sc->setceilingz(lp);
else
sc->setfloorz(lp);
2020-05-10 07:08:02 +00:00
}
else sc->extra--;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:35:30 +00:00
void handle_se22(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
if (actor->temp_data[1])
2020-05-10 07:08:02 +00:00
{
2022-09-12 17:47:07 +00:00
if (getanimationindex(anim_ceilingz, &sector[actor->temp_data[0]]) >= 0)
sc->addceilingz(sc->extra * 9 * zmaptoworld);
else actor->temp_data[1] = 0;
2020-05-10 07:08:02 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:35:30 +00:00
void handle_se26(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
double zvel = actor->vel.Z;
2020-05-10 07:08:02 +00:00
2022-09-03 08:05:20 +00:00
actor->vel.X = 2;
DVector2 vect = 2 * actor->spr.angle.ToVector(); // was: (32 * b sin) >> 14
2020-05-10 07:08:02 +00:00
actor->spr.shade++;
if (actor->spr.shade > 7)
2020-05-10 07:08:02 +00:00
{
2022-08-29 21:13:54 +00:00
actor->spr.pos.XY() = actor->temp_pos.XY();
sc->addfloorz(-((zvel * actor->spr.shade) - zvel));
actor->spr.shade = 0;
2020-05-10 07:08:02 +00:00
}
else
sc->addfloorz(zvel);
2020-05-10 07:08:02 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 22:35:30 +00:00
while (auto a2 = it.Next())
2020-05-10 07:08:02 +00:00
{
if (a2->spr.statnum != 3 && a2->spr.statnum != 10)
2020-05-10 07:08:02 +00:00
{
a2->spr.pos = DVector3(vect, zvel);
2022-08-22 16:34:01 +00:00
SetActor(a2, a2->spr.pos);
2020-05-10 07:08:02 +00:00
}
}
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].GetActor()->sector() == actor->sector() && ps[p].on_ground)
2020-05-10 07:08:02 +00:00
{
ps[p].fric.X += vect.X;
ps[p].fric.Y += vect.Y;
ps[p].pos.Z += zvel;
2020-05-10 07:08:02 +00:00
}
movesector(actor, actor->temp_data[1], nullAngle);
2022-02-06 21:45:47 +00:00
//SetActor(actor, actor->spr.pos);
2020-05-10 07:08:02 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:40:57 +00:00
void handle_se27(DDukeActor* actor)
2020-05-10 07:08:02 +00:00
{
int sh = actor->spr.hitag;
int p;
double xx;
2020-05-10 07:08:02 +00:00
if (ud.recstat == 0) return;
2022-09-14 21:30:10 +00:00
actor->temp_angle = actor->spr.angle;
2020-05-10 07:08:02 +00:00
p = findplayer(actor, &xx);
if (ps[p].GetActor()->spr.extra > 0 && myconnectindex == screenpeek)
2020-05-10 07:08:02 +00:00
{
if (actor->temp_data[0] < 0)
2020-05-10 07:08:02 +00:00
{
2020-11-02 22:53:55 +00:00
ud.cameraactor = actor;
actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
}
2020-11-02 23:20:51 +00:00
else if (ud.recstat == 2 && ps[p].newOwner == nullptr)
2020-05-10 07:08:02 +00:00
{
if (cansee(actor->spr.pos, actor->sector(), ps[p].pos, ps[p].cursector))
2020-05-10 07:08:02 +00:00
{
if (xx < sh * maptoworld)
2020-05-10 07:08:02 +00:00
{
2020-11-02 22:53:55 +00:00
ud.cameraactor = actor;
actor->temp_data[0] = 999;
actor->spr.angle += deltaangle(actor->spr.angle, (ps[p].pos.XY() - actor->spr.pos.XY()).Angle()) * 0.125;
actor->spr.yint = 100 + int((actor->spr.pos.Z - ps[p].pos.Z) * (256. / 257.));
2020-05-10 07:08:02 +00:00
}
else if (actor->temp_data[0] == 999)
2020-05-10 07:08:02 +00:00
{
2020-11-02 22:53:55 +00:00
if (ud.cameraactor == actor)
actor->temp_data[0] = 0;
else actor->temp_data[0] = -10;
2020-11-02 22:53:55 +00:00
ud.cameraactor = actor;
2020-05-10 07:08:02 +00:00
}
}
else
{
actor->spr.angle = (ps[p].pos.XY() - actor->spr.pos.XY()).Angle();
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] == 999)
2020-05-10 07:08:02 +00:00
{
2020-11-02 22:53:55 +00:00
if (ud.cameraactor == actor)
actor->temp_data[0] = 0;
else actor->temp_data[0] = -20;
2020-11-02 22:53:55 +00:00
ud.cameraactor = actor;
2020-05-10 07:08:02 +00:00
}
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-12 19:59:34 +00:00
void handle_se24(DDukeActor *actor, bool scroll, double mult)
2020-10-21 22:50:01 +00:00
{
if (actor->temp_data[4]) return;
2020-10-21 22:50:01 +00:00
2022-09-12 19:59:34 +00:00
auto vec = actor->spr.angle.ToVector() * actor->spr.yint / 256.;
2020-10-21 22:50:01 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 22:50:01 +00:00
while (auto a2 = it.Next())
{
if (a2->vel.Z >= 0)
2020-10-21 22:50:01 +00:00
{
2021-12-21 18:09:05 +00:00
switch (a2->spr.statnum)
2020-10-21 22:50:01 +00:00
{
2022-01-18 22:00:58 +00:00
case STAT_MISC:
case STAT_STANDABLE:
case STAT_ACTOR:
case STAT_DEFAULT:
if (actorflag(a2, SFLAG_SE24_REMOVE))
2020-10-21 22:50:01 +00:00
{
a2->spr.SetScale(0, 0);
2020-10-21 22:50:01 +00:00
continue;
}
if (actorflag(a2, SFLAG_SE24_NOCARRY) ||
2020-10-21 22:50:01 +00:00
wallswitchcheck(a2))
continue;
2020-10-21 22:50:01 +00:00
2022-02-03 23:45:24 +00:00
if (a2->spr.pos.Z > a2->floorz - 16)
2020-10-21 22:50:01 +00:00
{
2022-09-12 19:59:34 +00:00
a2->spr.pos += vec * mult;
2020-10-21 22:50:01 +00:00
2022-08-22 16:34:01 +00:00
SetActor(a2, a2->spr.pos);
2020-10-21 22:50:01 +00:00
if (a2->sector()->floorstat & CSTAT_SECTOR_SLOPE)
if (a2->spr.statnum == STAT_ZOMBIEACTOR)
makeitfall(a2);
2020-10-21 22:50:01 +00:00
}
break;
}
}
}
for (auto p = connecthead; p >= 0; p = connectpoint2[p])
{
if (ps[p].cursector == actor->sector() && ps[p].on_ground)
2020-10-21 22:50:01 +00:00
{
if (abs(ps[p].pos.Z - ps[p].truefz) < gs.playerheight + 9)
2020-10-21 22:50:01 +00:00
{
2022-09-12 19:59:34 +00:00
ps[p].fric += vec * (1. / 4.);
2020-10-21 22:50:01 +00:00
}
}
}
if (scroll) actor->sector()->addfloorxpan(actor->spr.yint / 128.f);
2020-10-21 22:50:01 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-12 21:35:48 +00:00
void handle_se25(DDukeActor* actor, int snd1, int snd2)
2020-10-21 22:59:42 +00:00
{
2021-11-20 23:33:17 +00:00
auto sec = actor->sector();
2022-09-12 21:35:48 +00:00
auto add = actor->spr.yint * zmaptoworld;
2020-10-21 22:59:42 +00:00
2022-08-20 18:11:01 +00:00
if (sec->floorz <= sec->ceilingz)
actor->spr.shade = 0;
2022-09-12 21:35:48 +00:00
else if (sec->ceilingz <= actor->temp_pos.Z)
actor->spr.shade = 1;
2020-10-21 22:59:42 +00:00
if (actor->spr.shade)
2020-10-21 22:59:42 +00:00
{
2022-09-12 21:35:48 +00:00
sec->addceilingz(add);
2022-08-20 18:11:01 +00:00
if (sec->ceilingz > sec->floorz)
2020-10-21 22:59:42 +00:00
{
sec->setceilingz(sec->floorz);
2020-10-21 22:59:42 +00:00
if (pistonsound && snd1 >= 0)
S_PlayActorSound(snd1, actor);
}
}
else
{
2022-09-12 21:35:48 +00:00
sec->addceilingz(-add);
if (sec->ceilingz < actor->temp_pos.Z)
2020-10-21 22:59:42 +00:00
{
2022-09-12 21:35:48 +00:00
sec->setceilingz(actor->temp_pos.Z);
2020-10-21 22:59:42 +00:00
if (pistonsound && snd2 >= 0)
S_PlayActorSound(snd2, actor);
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:40:57 +00:00
void handle_se32(DDukeActor *actor)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] == 1)
2020-05-10 07:08:02 +00:00
{
// Choose dir
double targetval = actor->spr.yint * zmaptoworld;
if (actor->temp_data[2] == 1) // Retract
2020-05-10 07:08:02 +00:00
{
2022-09-12 19:52:47 +00:00
if (actor->spr.intangle != 1536)
2020-05-10 07:08:02 +00:00
{
if (abs(sc->ceilingz - actor->spr.pos.Z) < targetval * 2)
2020-05-10 07:08:02 +00:00
{
2022-02-07 07:59:20 +00:00
sc->setceilingz(actor->spr.pos.Z);
callsound(actor->sector(), actor);
actor->temp_data[2] = 0;
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
}
else sc->addceilingz(Sgn(actor->spr.pos.Z - sc->ceilingz) * targetval);
2020-05-10 07:08:02 +00:00
}
else
{
2022-09-12 19:52:47 +00:00
if (abs(sc->ceilingz - actor->temp_pos.Z) < targetval * 2)
2020-05-10 07:08:02 +00:00
{
2022-09-12 19:52:47 +00:00
sc->setceilingz(actor->temp_pos.Z);
callsound(actor->sector(), actor);
actor->temp_data[2] = 0;
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
}
2022-09-12 19:52:47 +00:00
else sc->addceilingz(Sgn(actor->temp_pos.Z - sc->ceilingz) * targetval);
2020-05-10 07:08:02 +00:00
}
return;
}
if ((actor->spr.intangle & 2047) == 1536)
2020-05-10 07:08:02 +00:00
{
if (abs(sc->ceilingz - actor->spr.pos.Z) < targetval * 2)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[0] = 0;
actor->temp_data[2] = !actor->temp_data[2];
callsound(actor->sector(), actor);
2022-02-07 07:59:20 +00:00
sc->setceilingz(actor->spr.pos.Z);
2020-05-10 07:08:02 +00:00
}
else sc->addceilingz(Sgn(actor->spr.pos.Z - sc->ceilingz) * targetval);
2020-05-10 07:08:02 +00:00
}
else
{
2022-09-12 19:52:47 +00:00
if (abs(sc->ceilingz - actor->temp_pos.Z) < targetval * 2)
2020-05-10 07:08:02 +00:00
{
actor->temp_data[0] = 0;
actor->temp_data[2] = !actor->temp_data[2];
callsound(actor->sector(), actor);
2020-05-10 07:08:02 +00:00
}
2022-09-12 19:52:47 +00:00
else sc->addceilingz(-Sgn(actor->spr.pos.Z - actor->temp_pos.Z) * targetval);
2020-05-10 07:08:02 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:40:57 +00:00
void handle_se35(DDukeActor *actor, int SMALLSMOKE, int EXPLOSION2)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
if (sc->ceilingz > actor->spr.pos.Z)
2020-05-10 07:08:02 +00:00
for (int j = 0; j < 8; j++)
{
2022-09-11 21:31:20 +00:00
actor->spr.angle = randomAngle(90);
2020-10-21 22:40:57 +00:00
auto spawned = spawn(actor, SMALLSMOKE);
if (spawned)
{
spawned->vel.X = 6 + krandf(8);
ssp(spawned, CLIPMASK0);
2022-08-22 16:34:01 +00:00
SetActor(spawned, spawned->spr.pos);
if (rnd(16))
spawn(actor, EXPLOSION2);
}
2020-05-10 07:08:02 +00:00
}
double targetval = actor->spr.yint * zmaptoworld;
switch (actor->temp_data[0])
2020-05-10 07:08:02 +00:00
{
case 0:
sc->addceilingz(targetval);
2022-08-20 18:11:01 +00:00
if (sc->ceilingz > sc->floorz)
sc->setfloorz(sc->ceilingz);
2022-08-20 18:11:01 +00:00
if (sc->ceilingz > actor->spr.pos.Z + 32)
actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
break;
case 1:
sc->addceilingz(-targetval * 4);
if (sc->ceilingz < actor->temp_pos.Y)
2020-05-10 07:08:02 +00:00
{
sc->setceilingz(actor->temp_pos.Y);
actor->temp_data[0] = 0;
2020-05-10 07:08:02 +00:00
}
break;
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:40:57 +00:00
void handle_se128(DDukeActor *actor)
2020-05-10 07:08:02 +00:00
{
auto wal = actor->temp_walls[0];
if (!wal) return; // E4L1 contains an uninitialized SE128 which would crash without this.
2020-05-10 07:08:02 +00:00
//if (wal->cstat | 32) // this has always been bugged, the condition can never be false.
2020-05-10 07:08:02 +00:00
{
2021-12-18 14:16:31 +00:00
wal->cstat &= ~CSTAT_WALL_1WAY;
wal->cstat |= CSTAT_WALL_MASKED;
if (wal->twoSided())
2020-05-10 07:08:02 +00:00
{
2021-12-18 14:16:31 +00:00
wal->nextWall()->cstat &= ~CSTAT_WALL_1WAY;
wal->nextWall()->cstat |= CSTAT_WALL_MASKED;
2020-05-10 07:08:02 +00:00
}
}
2021-10-08 17:21:29 +00:00
// else return;
2020-05-10 07:08:02 +00:00
wal->overpicnum++;
auto nextwal = wal->nextWall();
if (nextwal)
nextwal->overpicnum++;
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] < actor->temp_data[1]) actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
else
{
2021-12-18 14:16:31 +00:00
wal->cstat &= (CSTAT_WALL_TRANSLUCENT | CSTAT_WALL_1WAY | CSTAT_WALL_XFLIP | CSTAT_WALL_ALIGN_BOTTOM | CSTAT_WALL_BOTTOM_SWAP);
if (nextwal)
2021-12-18 14:16:31 +00:00
nextwal->cstat &= (CSTAT_WALL_TRANSLUCENT | CSTAT_WALL_1WAY | CSTAT_WALL_XFLIP | CSTAT_WALL_ALIGN_BOTTOM | CSTAT_WALL_BOTTOM_SWAP);
2020-10-21 22:40:57 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 22:40:57 +00:00
void handle_se130(DDukeActor *actor, int countmax, int EXPLOSION2)
2020-05-10 07:08:02 +00:00
{
2021-11-20 23:33:17 +00:00
auto sc = actor->sector();
2020-05-10 07:08:02 +00:00
if (actor->temp_data[0] > countmax)
2020-05-10 07:08:02 +00:00
{
2020-10-21 22:40:57 +00:00
deletesprite(actor);
2020-05-10 07:08:02 +00:00
return;
}
else actor->temp_data[0]++;
2020-05-10 07:08:02 +00:00
double x = sc->floorz - sc->ceilingz;
2020-05-10 07:08:02 +00:00
if (rnd(64))
{
2020-10-21 22:40:57 +00:00
auto k = spawn(actor, EXPLOSION2);
if (k)
{
2022-10-05 22:08:51 +00:00
double s = 0.03125 + (krand() & 7) * REPEAT_SCALE;
k->spr.SetScale(s, s);
k->spr.pos.Z = sc->floorz + krandf(x);
k->spr.angle += DAngle45 - randomAngle(90);
2022-09-13 17:55:54 +00:00
k->vel.X = krandf(8);
ssp(k, CLIPMASK0);
}
2020-05-10 07:08:02 +00:00
}
}
2020-05-13 22:04:14 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void handle_se29(DDukeActor* actor)
{
auto sc = actor->sector();
actor->spr.hitag += 64;
double val = actor->spr.yint * BobVal(actor->spr.hitag) / 64.;
sc->setfloorz(actor->spr.pos.Z + val);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-05-13 22:04:14 +00:00
2020-10-21 23:04:13 +00:00
void handle_se31(DDukeActor* actor, bool choosedir)
{
2021-11-20 23:33:17 +00:00
auto sec = actor->sector();
2020-10-21 23:04:13 +00:00
if (actor->temp_data[0] == 1)
2020-10-21 23:04:13 +00:00
{
// Choose dir
if (choosedir && actor->temp_data[3] > 0)
2020-10-21 23:04:13 +00:00
{
actor->temp_data[3]--;
2020-10-21 23:04:13 +00:00
return;
}
if (actor->temp_data[2] == 1) // Retract
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
if (actor->spr.intangle != 1536)
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
if (abs(sec->floorz- actor->spr.pos.Z) < actor->temp_pos.Z)
2020-10-21 23:04:13 +00:00
{
2022-02-07 07:59:20 +00:00
sec->setfloorz(actor->spr.pos.Z);
actor->temp_data[2] = 0;
actor->temp_data[0] = 0;
if (choosedir) actor->temp_data[3] = actor->spr.hitag;
callsound(actor->sector(), actor);
2020-10-21 23:04:13 +00:00
}
else
{
2022-09-09 17:30:18 +00:00
double l = Sgn(actor->spr.pos.Z - sec->floorz) * actor->temp_pos.Z;
sec->addfloorz(l);
2020-10-21 23:04:13 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 23:04:13 +00:00
while (auto a2 = it.Next())
{
if (a2->isPlayer() && a2->GetOwner())
2020-10-21 23:04:13 +00:00
if (ps[a2->PlayerIndex()].on_ground == 1)
2022-09-09 17:30:18 +00:00
ps[a2->PlayerIndex()].pos.Z +=l;
if (a2->vel.Z == 0 && a2->spr.statnum != STAT_EFFECTOR && (!choosedir || a2->spr.statnum != STAT_PROJECTILE))
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
a2->spr.pos.Z += l;
a2->floorz = sec->floorz;
2020-10-21 23:04:13 +00:00
}
}
}
}
else
{
2022-09-09 17:30:18 +00:00
if (abs(sec->floorz - actor->temp_pos.Y) < actor->temp_pos.Z)
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
sec->floorz = actor->temp_pos.Y;
callsound(actor->sector(), actor);
actor->temp_data[2] = 0;
actor->temp_data[0] = 0;
if (choosedir) actor->temp_data[3] = actor->spr.hitag;
2020-10-21 23:04:13 +00:00
}
else
{
2022-09-09 17:30:18 +00:00
double l = Sgn(actor->temp_pos.Y - sec->floorz) * actor->temp_pos.Z;
sec->addfloorz(l);
2020-10-21 23:04:13 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 23:04:13 +00:00
while (auto a2 = it.Next())
{
if (a2->isPlayer() && a2->GetOwner())
2020-10-21 23:04:13 +00:00
if (ps[a2->PlayerIndex()].on_ground == 1)
2022-09-09 17:30:18 +00:00
ps[a2->PlayerIndex()].pos.Z += l;
if (a2->vel.Z == 0 && a2->spr.statnum != STAT_EFFECTOR && (!choosedir || a2->spr.statnum != STAT_PROJECTILE))
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
a2->spr.pos.Z += l;
a2->floorz = sec->floorz;
2020-10-21 23:04:13 +00:00
}
}
}
}
return;
}
2022-09-09 17:30:18 +00:00
if ((actor->spr.intangle & 2047) == 1536)
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
if (abs(actor->spr.pos.Z - sec->floorz) < actor->temp_pos.Z)
2020-10-21 23:04:13 +00:00
{
callsound(actor->sector(), actor);
actor->temp_data[0] = 0;
actor->temp_data[2] = 1;
if (choosedir) actor->temp_data[3] = actor->spr.hitag;
2020-10-21 23:04:13 +00:00
}
else
{
2022-09-09 17:30:18 +00:00
double l = Sgn(actor->spr.pos.Z - sec->floorz) * actor->temp_pos.Z;
sec->addfloorz(l);
2020-10-21 23:04:13 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 23:04:13 +00:00
while (auto a2 = it.Next())
{
if (a2->isPlayer() && a2->GetOwner())
2020-10-21 23:04:13 +00:00
if (ps[a2->PlayerIndex()].on_ground == 1)
2022-09-09 17:30:18 +00:00
ps[a2->PlayerIndex()].pos.Z += l;
if (a2->vel.Z == 0 && a2->spr.statnum != STAT_EFFECTOR && (!choosedir || a2->spr.statnum != STAT_PROJECTILE))
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
a2->spr.pos.Z += l;
a2->floorz = sec->floorz;
2020-10-21 23:04:13 +00:00
}
}
}
}
else
{
2022-09-09 17:30:18 +00:00
if (abs(sec->floorz - actor->temp_pos.Y) < actor->temp_pos.Z)
2020-10-21 23:04:13 +00:00
{
actor->temp_data[0] = 0;
callsound(actor->sector(), actor);
actor->temp_data[2] = 1;
actor->temp_data[3] = actor->spr.hitag;
2020-10-21 23:04:13 +00:00
}
else
{
2022-09-09 17:30:18 +00:00
double l = Sgn(actor->spr.pos.Z - actor->temp_pos.Y) * actor->temp_pos.Z;
sec->addfloorz(-l);
2020-10-21 23:04:13 +00:00
DukeSectIterator it(actor->sector());
2020-10-21 23:04:13 +00:00
while (auto a2 = it.Next())
{
if (a2->isPlayer() && a2->GetOwner())
2020-10-21 23:04:13 +00:00
if (ps[a2->PlayerIndex()].on_ground == 1)
2022-09-09 17:30:18 +00:00
ps[a2->PlayerIndex()].pos.Z -= l;
if (a2->vel.Z == 0 && a2->spr.statnum != STAT_EFFECTOR && (!choosedir || a2->spr.statnum != STAT_PROJECTILE))
2020-10-21 23:04:13 +00:00
{
2022-09-09 17:30:18 +00:00
a2->spr.pos.Z -= l;
a2->floorz = sec->floorz;
2020-10-21 23:04:13 +00:00
}
}
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 23:10:56 +00:00
void getglobalz(DDukeActor* actor)
2020-05-13 22:04:14 +00:00
{
double zr;
2020-10-21 23:10:56 +00:00
Collision hz, lz;
2020-05-13 22:04:14 +00:00
if( actor->spr.statnum == STAT_PLAYER || actor->spr.statnum == STAT_STANDABLE || actor->spr.statnum == STAT_ZOMBIEACTOR || actor->spr.statnum == STAT_ACTOR || actor->spr.statnum == STAT_PROJECTILE)
2020-05-13 22:04:14 +00:00
{
if(actor->spr.statnum == STAT_PROJECTILE)
zr = 0.25;
else zr = 7.9375;
2020-05-13 22:04:14 +00:00
auto cc = actor->spr.cstat2;
actor->spr.cstat2 |= CSTAT2_SPRITE_NOFIND; // don't clip against self. getzrange cannot detect this because it only receives a coordinate.
getzrange(actor->spr.pos.plusZ(-1), actor->sector(), &actor->ceilingz, hz, &actor->floorz, lz, zr, CLIPMASK0);
actor->spr.cstat2 = cc;
2020-05-13 22:04:14 +00:00
actor->spr.cstat2 &= ~CSTAT2_SPRITE_NOSHADOW;
if( lz.type == kHitSprite && (lz.actor()->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == 0 )
2020-05-13 22:04:14 +00:00
{
if( badguy(lz.actor()) && lz.actor()->spr.pal != 1)
2020-05-13 22:04:14 +00:00
{
if( actor->spr.statnum != STAT_PROJECTILE)
2020-05-13 22:04:14 +00:00
{
actor->spr.cstat2 |= CSTAT2_SPRITE_NOSHADOW; // No shadows on actors
2022-09-03 08:05:20 +00:00
actor->vel.X = -16;
2020-10-21 23:10:56 +00:00
ssp(actor, CLIPMASK0);
2020-05-13 22:04:14 +00:00
}
}
else if(lz.actor()->isPlayer() && badguy(actor) )
2020-05-13 22:04:14 +00:00
{
actor->spr.cstat2 |= CSTAT2_SPRITE_NOSHADOW; // No shadows on actors
2022-09-03 08:05:20 +00:00
actor->vel.X = -16;
2020-10-21 23:10:56 +00:00
ssp(actor, CLIPMASK0);
2020-05-13 22:04:14 +00:00
}
else if(actor->spr.statnum == STAT_PROJECTILE && lz.actor()->isPlayer() && actor->GetOwner() == actor)
2020-05-13 22:04:14 +00:00
{
actor->ceilingz = actor->sector()->ceilingz;
actor->floorz = actor->sector()->floorz;
2020-05-13 22:04:14 +00:00
}
}
}
else
{
actor->ceilingz = actor->sector()->ceilingz;
actor->floorz = actor->sector()->floorz;
2020-05-13 22:04:14 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-10-21 23:11:38 +00:00
void makeitfall(DDukeActor* actor)
2020-05-13 22:04:14 +00:00
{
double grav;
2020-05-13 22:04:14 +00:00
if( fi.floorspace(actor->sector()) )
grav = 0;
2020-05-13 22:04:14 +00:00
else
{
if( fi.ceilingspace(actor->sector()) || actor->sector()->lotag == ST_2_UNDERWATER)
grav = gs.gravity/6;
else grav = gs.gravity;
2020-05-13 22:04:14 +00:00
}
2020-05-13 22:04:14 +00:00
if (isRRRA())
{
grav = adjustfall(actor, grav); // this accesses sprite indices and cannot be in shared code. Should be done better. (todo: turn into actor flags)
2020-05-13 22:04:14 +00:00
}
if ((actor->spr.statnum == STAT_ACTOR || actor->spr.statnum == STAT_PLAYER || actor->spr.statnum == STAT_ZOMBIEACTOR || actor->spr.statnum == STAT_STANDABLE))
2020-10-21 23:11:38 +00:00
{
Collision coll;
getzrange(actor->spr.pos.plusZ(-1), actor->sector(), &actor->ceilingz, coll, &actor->floorz, coll, 7.9375, CLIPMASK0);
2020-10-21 23:11:38 +00:00
}
2020-05-13 22:04:14 +00:00
else
{
actor->ceilingz = actor->sector()->ceilingz;
actor->floorz = actor->sector()->floorz;
2020-05-13 22:04:14 +00:00
}
2022-02-03 23:45:24 +00:00
if( actor->spr.pos.Z < actor->floorz - FOURSLEIGHT_F)
2020-05-13 22:04:14 +00:00
{
if( actor->sector()->lotag == 2 && actor->vel.Z > 3122/256.)
2022-09-11 17:28:45 +00:00
actor->vel.Z = 3144 / 256.;
if (actor->vel.Z < 24)
actor->vel.Z += grav;
2022-09-11 17:28:45 +00:00
else actor->vel.Z = 24;
actor->spr.pos.Z += actor->vel.Z;
2020-05-13 22:04:14 +00:00
}
2022-02-03 23:45:24 +00:00
if (actor->spr.pos.Z >= actor->floorz - FOURSLEIGHT_F)
2020-05-13 22:04:14 +00:00
{
2022-02-03 23:45:24 +00:00
actor->spr.pos.Z = actor->floorz - FOURSLEIGHT_F;
2022-09-03 08:02:25 +00:00
actor->vel.Z = 0;
2020-05-13 22:04:14 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int dodge(DDukeActor* actor)
2020-05-13 22:04:14 +00:00
{
2022-09-12 20:06:43 +00:00
auto oldpos = actor->spr.pos.XY();
2020-05-13 22:04:14 +00:00
DukeStatIterator it(STAT_PROJECTILE);
while (auto ac = it.Next())
2020-05-13 22:04:14 +00:00
{
if (ac->GetOwner() == ac || ac->sector() != actor->sector())
2020-05-13 22:04:14 +00:00
continue;
2022-09-12 20:06:43 +00:00
auto delta = ac->spr.pos.XY() - oldpos;
auto bvect = ac->spr.angle.ToVector() * 1024;
2020-05-13 22:04:14 +00:00
2022-09-12 20:06:43 +00:00
if (actor->spr.angle.ToVector().dot(delta) >= 0)
{
if (bvect.dot(delta) < 0)
2020-05-13 22:04:14 +00:00
{
2022-09-12 20:06:43 +00:00
double d = bvect.X * delta.Y - bvect.Y * delta.X;
if (abs(d) < 256 * 64)
2020-05-13 22:04:14 +00:00
{
2022-09-12 20:06:43 +00:00
actor->spr.angle -= DAngle90 + randomAngle(180);
2020-05-13 22:04:14 +00:00
return 1;
}
}
2022-09-12 20:06:43 +00:00
}
2020-05-13 22:04:14 +00:00
}
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
DAngle furthestangle(DDukeActor *actor, int angs)
2020-05-13 22:04:14 +00:00
{
2022-09-12 20:40:55 +00:00
double d, greatestd;
DAngle furthest_angle = DAngle360;
HitInfo hit{};
2020-05-13 22:04:14 +00:00
greatestd = -(1 << 30);
2022-09-12 20:40:55 +00:00
DAngle angincs = DAngle360 / angs;
2020-05-13 22:04:14 +00:00
if (!actor->isPlayer())
if ((actor->temp_data[0] & 63) > 2) return(actor->spr.angle + DAngle180);
2020-05-13 22:04:14 +00:00
2022-09-12 20:40:55 +00:00
for (DAngle j = actor->spr.angle; j < DAngle360 + actor->spr.angle; j += angincs)
2020-05-13 22:04:14 +00:00
{
2022-09-12 20:40:55 +00:00
hitscan(actor->spr.pos.plusZ(-8), actor->sector(), DVector3(j.ToVector() * 1024, 0), hit, CLIPMASK1);
2020-05-13 22:04:14 +00:00
d = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum();
2020-05-13 22:04:14 +00:00
if (d > greatestd)
{
greatestd = d;
furthest_angle = j;
}
}
2022-09-12 20:40:55 +00:00
return furthest_angle.Normalized360();
2020-05-13 22:04:14 +00:00
}
//---------------------------------------------------------------------------
//
// return value was changed to what its only caller really expects
2020-05-13 22:04:14 +00:00
//
//---------------------------------------------------------------------------
int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, DVector2& pos)
2020-05-13 22:04:14 +00:00
{
DAngle angincs;
HitInfo hit{};
2020-05-13 22:04:14 +00:00
if ((actor->temp_data[0] & 63)) return -1;
2020-05-13 22:04:14 +00:00
if (ud.multimode < 2 && ud.player_skill < 3)
angincs = DAngle180;
else angincs = DAngle360 / (1 + (krand() & 1));
2020-05-13 22:04:14 +00:00
for (auto j = tosee->spr.angle; j < tosee->spr.angle + DAngle360; j += (angincs - randomAngle(90)))
2020-05-13 22:04:14 +00:00
{
hitscan(tosee->spr.pos.plusZ(-16), tosee->sector(), DVector3(j.ToVector() * 1024, 64 - krandf(128)), hit, CLIPMASK1);
2020-05-13 22:04:14 +00:00
double d = (hit.hitpos.XY() - tosee->spr.pos.XY()).Sum();
double da = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum();
2020-05-13 22:04:14 +00:00
if (d < da && hit.hitSector)
if (cansee(hit.hitpos, hit.hitSector, actor->spr.pos.plusZ(-16), actor->sector()))
2020-05-13 22:04:14 +00:00
{
pos = hit.hitpos.XY();
return 1;
2020-05-13 22:04:14 +00:00
}
}
return 0;
2020-05-13 22:04:14 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-01 09:45:09 +00:00
void alterang(int ang, DDukeActor* actor, int playernum)
2020-05-13 22:04:14 +00:00
{
DAngle goalang, aang, angdif;
int j;
2020-05-13 22:04:14 +00:00
int ticselapsed;
auto moveptr = &ScriptCode[actor->temp_data[1]];
2020-05-13 22:04:14 +00:00
ticselapsed = (actor->temp_data[0]) & 31;
2020-05-13 22:04:14 +00:00
aang = actor->spr.angle;
2020-05-13 22:04:14 +00:00
2022-09-11 20:57:56 +00:00
actor->vel.X += (moveptr[0] / 16 - actor->vel.X) / 5;
if (actor->vel.Z < (648 / 256.))
{
actor->vel.Z += (moveptr[1] / 16 - actor->vel.Z) / 5;
}
2020-05-13 22:04:14 +00:00
2020-10-22 14:40:48 +00:00
if (isRRRA() && (ang & windang))
2022-09-11 20:57:56 +00:00
actor->spr.angle = WindDir;
2020-10-22 14:40:48 +00:00
else if (ang & seekplayer)
2020-05-13 22:04:14 +00:00
{
DDukeActor* holoduke = !isRR()? ps[playernum].holoduke_on.Get() : nullptr;
2020-05-13 22:04:14 +00:00
2020-11-02 21:26:32 +00:00
// NOTE: looks like 'Owner' is set to target sprite ID...
2020-05-13 22:04:14 +00:00
2022-02-06 21:45:47 +00:00
if (holoduke && cansee(holoduke->spr.pos, holoduke->sector(), actor->spr.pos, actor->sector()))
2020-10-22 14:40:48 +00:00
actor->SetOwner(holoduke);
2020-11-01 09:45:09 +00:00
else actor->SetOwner(ps[playernum].GetActor());
2020-05-13 22:04:14 +00:00
2020-10-22 14:40:48 +00:00
auto Owner = actor->GetOwner();
if (Owner->isPlayer())
goalang = (actor->ovel - actor->spr.pos.XY()).Angle();
2020-05-13 22:04:14 +00:00
else
goalang = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Angle();
2020-05-13 22:04:14 +00:00
if (actor->vel.X != 0 && actor->spr.picnum != TILE_DRONE)
2020-05-13 22:04:14 +00:00
{
angdif = absangle(aang, goalang);
2020-05-13 22:04:14 +00:00
if (ticselapsed < 2)
{
if (angdif < DAngle45)
2020-05-13 22:04:14 +00:00
{
DAngle add = DAngle22_5 * ((krand() & 256)? 1 : -1);
actor->spr.angle += add;
2022-09-13 22:05:32 +00:00
if (hits(actor) < 51.25)
actor->spr.angle -= add;
2020-05-13 22:04:14 +00:00
}
}
else if (ticselapsed > 18 && ticselapsed < 26) // choose
{
if (angdif < DAngle90) actor->spr.angle = goalang;
else actor->spr.angle += angdif * 0.25;
2020-05-13 22:04:14 +00:00
}
}
else actor->spr.angle = goalang;
2020-05-13 22:04:14 +00:00
}
if (ticselapsed < 1)
{
j = 2;
2020-10-22 14:40:48 +00:00
if (ang & furthestdir)
2020-05-13 22:04:14 +00:00
{
2020-10-22 14:40:48 +00:00
goalang = furthestangle(actor, j);
actor->spr.angle = goalang;
2020-11-01 09:45:09 +00:00
actor->SetOwner(ps[playernum].GetActor());
2020-05-13 22:04:14 +00:00
}
2020-10-22 14:40:48 +00:00
if (ang & fleeenemy)
2020-05-13 22:04:14 +00:00
{
2020-10-22 14:40:48 +00:00
goalang = furthestangle(actor, j);
actor->spr.angle = goalang;
2020-05-13 22:04:14 +00:00
}
}
}
2020-05-14 07:07:07 +00:00
//---------------------------------------------------------------------------
//
// the indirections here are to keep this core function free of game references
//
//---------------------------------------------------------------------------
2020-11-01 09:49:50 +00:00
void fall_common(DDukeActor *actor, int playernum, int JIBS6, int DRONE, int BLOODPOOL, int SHOTSPARK1, int squished, int thud, int(*fallspecial)(DDukeActor*, int))
2020-05-14 07:07:07 +00:00
{
actor->spr.xoffset = 0;
actor->spr.yoffset = 0;
2020-05-14 07:07:07 +00:00
// if(!gotz)
{
double grav;
2020-05-14 07:07:07 +00:00
2020-11-01 09:49:50 +00:00
int sphit = fallspecial? fallspecial(actor, playernum) : 0;
if (fi.floorspace(actor->sector()))
grav = 0;
2020-05-14 07:07:07 +00:00
else
{
if (fi.ceilingspace(actor->sector()) || actor->sector()->lotag == 2)
grav = gs.gravity / 6;
else grav = gs.gravity;
2020-05-14 07:07:07 +00:00
}
if (actor->cgg <= 0 || (actor->sector()->floorstat & CSTAT_SECTOR_SLOPE))
2020-05-14 07:07:07 +00:00
{
getglobalz(actor);
actor->cgg = 6;
2020-05-14 07:07:07 +00:00
}
else actor->cgg--;
2020-05-14 07:07:07 +00:00
2022-02-03 23:45:24 +00:00
if (actor->spr.pos.Z < actor->floorz - FOURSLEIGHT_F)
2020-05-14 07:07:07 +00:00
{
actor->vel.Z += grav;
actor->spr.pos.Z += actor->vel.Z;
2020-05-14 07:07:07 +00:00
2022-09-11 17:28:45 +00:00
if (actor->vel.Z > 24) actor->vel.Z = 24;
2020-05-14 07:07:07 +00:00
}
else
{
2022-02-03 23:55:12 +00:00
actor->spr.pos.Z = actor->floorz - FOURSLEIGHT_F;
2020-05-14 07:07:07 +00:00
if (badguy(actor) || (actor->isPlayer() && actor->GetOwner()))
2020-05-14 07:07:07 +00:00
{
if (actor->vel.Z > (3084/256.) && actor->spr.extra <= 1)
2020-05-14 07:07:07 +00:00
{
if (actor->spr.pal != 1 && actor->spr.picnum != DRONE)
2020-05-14 07:07:07 +00:00
{
if (actor->isPlayer() && actor->spr.extra > 0)
2020-05-14 07:07:07 +00:00
goto SKIPJIBS;
if (sphit)
{
2020-10-22 17:21:21 +00:00
fi.guts(actor, JIBS6, 5, playernum);
S_PlayActorSound(squished, actor);
2020-05-14 07:07:07 +00:00
}
else
{
2020-10-22 17:21:21 +00:00
fi.guts(actor, JIBS6, 15, playernum);
S_PlayActorSound(squished, actor);
spawn(actor, BLOODPOOL);
2020-05-14 07:07:07 +00:00
}
}
SKIPJIBS:
actor->attackertype = SHOTSPARK1;
actor->hitextra = 1;
2022-09-03 08:02:25 +00:00
actor->vel.Z = 0;
2020-05-14 07:07:07 +00:00
}
else if (actor->vel.Z > 8 && actor->sector()->lotag != 1)
2020-05-14 07:07:07 +00:00
{
auto sect = actor->sector();
pushmove(actor->spr.pos, &sect, 8., 4., 4., CLIPMASK0);
if (sect != actor->sector() && sect != nullptr)
ChangeActorSect(actor, sect);
2020-05-14 07:07:07 +00:00
S_PlayActorSound(thud, actor);
2020-05-14 07:07:07 +00:00
}
}
if (actor->sector()->lotag == 1)
2022-09-12 16:38:51 +00:00
actor->spr.pos.Z += gs.actorinfo[actor->spr.picnum].falladjustz;
2022-09-03 08:02:25 +00:00
else actor->vel.Z = 0;
2020-05-14 07:07:07 +00:00
}
}
}
2020-05-13 22:04:14 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
DDukeActor *LocateTheLocator(int n, sectortype* sect)
2020-06-23 19:12:15 +00:00
{
2020-11-01 06:56:49 +00:00
DukeStatIterator it(STAT_LOCATOR);
while (auto ac = it.Next())
2020-06-23 19:12:15 +00:00
{
if ((sect == nullptr || sect == ac->sector()) && n == ac->spr.lotag)
2020-11-01 06:56:49 +00:00
return ac;
2020-06-23 19:12:15 +00:00
}
2020-11-01 06:56:49 +00:00
return nullptr;
2020-06-23 19:12:15 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void recordoldspritepos()
{
for (int statNum = 0; statNum < MAXSTATUS; statNum++)
{
DukeStatIterator it(statNum);
while (auto ac = it.Next())
{
ac->backuploc();
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void movefta(void)
{
double xx;
int canseeme, p;
sectortype* psect, * ssect;
auto check_fta_sounds = [](DDukeActor* act)
{
if (isRR()) check_fta_sounds_r(act);
else check_fta_sounds_d(act);
};
DukeStatIterator it(STAT_ZOMBIEACTOR);
while (auto act = it.Next())
{
p = findplayer(act, &xx);
canseeme = 0;
ssect = psect = act->sector();
if (ps[p].GetActor()->spr.extra > 0)
{
if (xx < 30000 / 16.)
{
act->timetosleep++;
if (act->timetosleep >= int(xx / 16.))
{
if (badguy(act))
{
auto xyrand = []() -> double { return (64 - (krand() & 127)) * maptoworld; };
double px = ps[p].opos.X - xyrand();
double py = ps[p].opos.Y - xyrand();
2022-02-06 19:02:58 +00:00
updatesector(DVector3(px, py, 0), &psect);
if (psect == nullptr)
{
continue;
}
double sx = act->spr.pos.X - xyrand();
double sy = act->spr.pos.Y - xyrand();
2022-02-06 19:02:58 +00:00
// The second updatesector call here used px and py again and was redundant as coded.
// SFLAG_MOVEFTA_CHECKSEE is set for all actors in Duke.
if (act->spr.pal == 33 || actorflag(act, SFLAG_MOVEFTA_CHECKSEE) ||
2022-01-07 15:36:02 +00:00
(actorflag(act, SFLAG_MOVEFTA_CHECKSEEWITHPAL8) && act->spr.pal == 8) ||
(act->spr.angle.Cos() * (px - sx) + act->spr.angle.Sin() * (py - sy) >= 0))
{
2022-02-12 11:37:27 +00:00
double r1 = zrand(32);
double r2 = zrand(52);
canseeme = cansee({ sx, sy, act->spr.pos.Z - r2 }, act->sector(), { px, py, ps[p].opos.Z - r1 }, ps[p].cursector);
}
}
else
{
int r1 = krand();
int r2 = krand();
2022-02-06 19:02:58 +00:00
canseeme = cansee(act->spr.pos.plusZ(-(r2 & 31)), act->sector(), ps[p].opos.plusZ(-(r1 & 31)), ps[p].cursector);
}
if (canseeme)
{
2022-01-07 15:36:02 +00:00
if (actorflag(act, SFLAG_MOVEFTA_MAKESTANDABLE))
{
if (act->sector()->ceilingstat & CSTAT_SECTOR_SKY)
act->spr.shade = act->sector()->ceilingshade;
else act->spr.shade = act->sector()->floorshade;
act->timetosleep = 0;
ChangeActorStat(act, STAT_STANDABLE);
}
else
{
act->timetosleep = 0;
check_fta_sounds(act);
ChangeActorStat(act, STAT_ACTOR);
}
}
else act->timetosleep = 0;
}
}
if (badguy(act))
{
if (act->sector()->ceilingstat & CSTAT_SECTOR_SKY)
act->spr.shade = act->sector()->ceilingshade;
else act->spr.shade = act->sector()->floorshade;
// wakeup is an RR feature, this flag will later allow it to use in Duke, too.
2022-01-07 15:36:02 +00:00
if (actorflag(act, SFLAG_MOVEFTA_WAKEUPCHECK))
{
if (wakeup(act, p))
{
act->timetosleep = 0;
check_fta_sounds(act);
ChangeActorStat(act, STAT_ACTOR);
}
}
}
}
}
}
2020-06-23 19:12:15 +00:00
END_DUKE_NS