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

992 lines
24 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
2020-06-28 07:03:31 +00:00
Copyright (C) 2020 - Christoph Oelckers
This file is part of Enhanced Duke Nukem 3D version 1.5 - Atomic Edition
Duke Nukem 3D is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Original Source: 1996 - Todd Replogle
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
EDuke enhancements integrated: 04/13/2003 - Matt Saettler
Note: EDuke source was in transition. Changes are in-progress in the
source as it is released.
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "global.h"
2020-07-07 15:56:20 +00:00
#include "mapinfo.h"
#include "dukeactor.h"
#include "vm.h"
BEGIN_DUKE_NS
2020-07-15 16:10:31 +00:00
//---------------------------------------------------------------------------
//
// callback for playercolor CVAR
//
//---------------------------------------------------------------------------
int playercolor2lookup(int color)
2020-07-15 16:10:31 +00:00
{
static int8_t player_pals[] = { 0, 9, 10, 11, 12, 13, 14, 15, 16, 21, 23, };
if (color >= 0 && color < 10) return player_pals[color];
return 0;
}
void PlayerColorChanged(void)
{
if (ud.recstat != 0)
return;
auto& pp = ps[myconnectindex];
2020-07-15 16:10:31 +00:00
if (ud.multimode > 1)
{
//Net_SendClientInfo();
}
else
{
pp.palookup = ud.user_pals[myconnectindex] = playercolor2lookup(playercolor);
2020-07-15 16:10:31 +00:00
}
if (pp.GetActor()->isPlayer() && pp.GetActor()->spr.pal != 1)
pp.GetActor()->spr.pal = ud.user_pals[myconnectindex];
2020-07-15 16:10:31 +00:00
}
//---------------------------------------------------------------------------
//
// why is this such a mess?
//
//---------------------------------------------------------------------------
2022-02-07 10:04:19 +00:00
int setpal(player_struct* p)
{
int palette;
if (p->DrugMode) palette = DRUGPAL;
else if (p->heat_on) palette = SLIMEPAL;
2021-11-21 07:45:07 +00:00
else if (!p->insector()) palette = BASEPAL; // don't crash if out of range.
else if (tileflags(p->cursector->ceilingpicnum) & TFLAG_SLIME) palette = SLIMEPAL;
else if (p->cursector->lotag == ST_2_UNDERWATER) palette = WATERPAL;
else palette = BASEPAL;
return palette;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-02-07 10:04:19 +00:00
void quickkill(player_struct* p)
{
SetPlayerPal(p, PalEntry(48, 48, 48, 48));
auto pa = p->GetActor();
pa->spr.extra = 0;
pa->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
if (ud.god == 0) spawnguts(pa, PClass::FindActor("DukeJibs6"), 8);
return;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void forceplayerangle(int snum)
{
player_struct* p = &ps[snum];
const auto ang = (DAngle22_5 - randomAngle(45)) / 2.;
p->Angles.addPitch(DAngle::fromDeg(-26.566));
p->sync.actions |= SB_CENTERVIEW;
p->Angles.ViewAngles.Yaw = ang;
p->Angles.ViewAngles.Roll = -ang;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-13 21:07:08 +00:00
void tracers(const DVector3& start, const DVector3& dest, int n)
{
2021-11-18 18:04:00 +00:00
sectortype* sect = nullptr;
2022-09-13 21:07:08 +00:00
auto direction = dest - start;
2022-09-13 21:07:08 +00:00
if (direction.XY().Sum() < 192.75)
return;
2022-09-13 21:07:08 +00:00
auto pos = start;
auto add = direction / (n + 1);
for (int i = n; i > 0; i--)
{
2022-09-13 21:07:08 +00:00
pos += add;
updatesector(pos, &sect);
2021-11-18 18:04:00 +00:00
if (sect)
{
2021-11-18 18:04:00 +00:00
if (sect->lotag == 2)
2022-10-07 16:57:09 +00:00
{
DVector2 scale(0.0625 + (krand() & 3) * REPEAT_SCALE, 0.0625 + (krand() & 3) * REPEAT_SCALE);
CreateActor(sect, pos, TILE_WATERBUBBLE, -32, scale, randomAngle(), 0., 0., ps[0].GetActor(), 5);
}
else
2022-10-07 16:57:09 +00:00
CreateActor(sect, pos, TILE_SMALLSMOKE, -32, DVector2(0.21875, 0.21875), nullAngle, 0., 0., ps[0].GetActor(), 5);
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-13 22:05:32 +00:00
double hits(DDukeActor* actor)
{
2022-09-13 22:08:56 +00:00
double zoff;
HitInfo hit{};
2022-09-13 22:08:56 +00:00
if (actor->isPlayer()) zoff = gs.playerheight;
else zoff = 0;
2022-09-13 22:08:56 +00:00
auto pos = actor->spr.pos;
hitscan(pos.plusZ(-zoff), actor->sector(), DVector3(actor->spr.Angles.Yaw.ToVector() * 1024, 0), hit, CLIPMASK1);
2022-09-13 22:08:56 +00:00
return (hit.hitpos.XY() - actor->spr.pos.XY()).Length();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-13 22:11:16 +00:00
double hitasprite(DDukeActor* actor, DDukeActor** hitsp)
{
2022-09-13 22:15:45 +00:00
double zoff;
HitInfo hit{};
if (badguy(actor))
2022-09-13 22:15:45 +00:00
zoff = 42;
else if (actor->isPlayer()) zoff = gs.playerheight;
else zoff = 0;
2022-09-13 22:15:45 +00:00
auto pos = actor->spr.pos;
hitscan(pos.plusZ(-zoff), actor->sector(), DVector3(actor->spr.Angles.Yaw.ToVector() * 1024, 0), hit, CLIPMASK1);
if (hitsp) *hitsp = hit.actor();
if (hit.hitWall != nullptr && (hit.hitWall->cstat & CSTAT_WALL_MASKED) && badguy(actor))
2022-09-13 22:11:16 +00:00
return INT_MAX;
2022-09-13 22:15:45 +00:00
return (hit.hitpos.XY() - actor->spr.pos.XY()).Length();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-13 22:20:58 +00:00
double hitawall(player_struct* p, walltype** hitw)
{
HitInfo hit{};
hitscan(p->GetActor()->getPosWithOffsetZ(), p->cursector, DVector3(p->GetActor()->spr.Angles.Yaw.ToVector() * 1024, 0), hit, CLIPMASK0);
if (hitw) *hitw = hit.hitWall;
return (hit.hitpos.XY() - p->GetActor()->spr.pos.XY()).Length();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-14 16:08:23 +00:00
DDukeActor* aim(DDukeActor* actor, int abase)
{
2022-09-14 16:08:23 +00:00
DAngle aang = DAngle90 * (AUTO_AIM_ANGLE / 512.);
bool gotshrinker, gotfreezer;
static const int aimstats[] = { STAT_PLAYER, STAT_DUMMYPLAYER, STAT_ACTOR, STAT_ZOMBIEACTOR };
DAngle a = actor->spr.Angles.Yaw;
// Autoaim from DukeGDX.
if (actor->isPlayer())
{
2022-09-01 14:42:23 +00:00
auto* plr = &ps[actor->PlayerIndex()];
int autoaim = Autoaim(actor->PlayerIndex());
2020-11-29 08:00:00 +00:00
if (!autoaim)
{
// Some fudging to avoid aim randomization when autoaim is off.
// This is a reimplementation of how it was solved in RedNukem.
if (plr->curr_weapon == PISTOL_WEAPON && !isWW2GI())
{
double vel = 1024, zvel = 0;
setFreeAimVelocity(vel, zvel, plr->Angles.getPitchWithView(), 16.);
HitInfo hit{};
hitscan(plr->GetActor()->getPosWithOffsetZ().plusZ(4), actor->sector(), DVector3(actor->spr.Angles.Yaw.ToVector() * vel, zvel), hit, CLIPMASK1);
if (hit.actor() != nullptr)
{
if (isIn(hit.actor()->spr.statnum, { STAT_PLAYER, STAT_DUMMYPLAYER, STAT_ACTOR, STAT_ZOMBIEACTOR }))
return hit.actor();
}
}
// The chickens in RRRA are homing and must always autoaim.
if (!isRRRA() || plr->curr_weapon != CHICKEN_WEAPON)
return nullptr;
}
2020-11-29 08:00:00 +00:00
else if (autoaim == 2)
{
int weap;
if (!isWW2GI())
{
weap = plr->curr_weapon;
}
else
{
2022-09-01 14:42:23 +00:00
weap = aplWeaponWorksLike(plr->curr_weapon, actor->PlayerIndex());
}
// The chickens in RRRA are homing and must always autoaim.
if (!isRRRA() || plr->curr_weapon != CHICKEN_WEAPON)
{
if (weap > CHAINGUN_WEAPON || weap == KNEE_WEAPON)
{
return nullptr;
}
}
}
}
DDukeActor* aimed = nullptr;
2022-09-01 14:42:23 +00:00
// if(actor->isPlayer() && ps[actor->PlayerIndex()].aim_mode) return -1;
if (isRR())
{
gotshrinker = false;
gotfreezer = false;
}
else if (isWW2GI())
{
2022-09-01 14:42:23 +00:00
gotshrinker = actor->isPlayer() && aplWeaponWorksLike(ps[actor->PlayerIndex()].curr_weapon, actor->PlayerIndex()) == SHRINKER_WEAPON;
gotfreezer = actor->isPlayer() && aplWeaponWorksLike(ps[actor->PlayerIndex()].curr_weapon, actor->PlayerIndex()) == FREEZE_WEAPON;
}
else
{
2022-09-01 14:42:23 +00:00
gotshrinker = actor->isPlayer() && ps[actor->PlayerIndex()].curr_weapon == SHRINKER_WEAPON;
gotfreezer = actor->isPlayer() && ps[actor->PlayerIndex()].curr_weapon == FREEZE_WEAPON;
}
2022-09-14 16:08:23 +00:00
double smax = 0x7fffffff;
2022-09-14 16:08:23 +00:00
auto dv1 = (a - aang).ToVector();
auto dv2 = (a + aang).ToVector();
auto dv3 = a.ToVector();
2022-09-14 16:08:23 +00:00
for (int k = 0; k < 4; k++)
{
if (aimed)
break;
DukeStatIterator it(aimstats[k]);
while (auto act = it.Next())
{
if (act->spr.scale.X > 0 && act->spr.extra >= 0 && (act->spr.cstat & (CSTAT_SPRITE_BLOCK_ALL | CSTAT_SPRITE_INVISIBLE)) == CSTAT_SPRITE_BLOCK_ALL)
2021-12-21 19:22:34 +00:00
if (badguy(act) || k < 2)
{
if (badguy(act) || act->isPlayer())
{
if (act->isPlayer() &&
(isRR() && ud.ffire == 0) &&
ud.coop == 1 &&
actor->isPlayer() &&
2021-12-21 19:22:34 +00:00
actor != act)
continue;
if (gotshrinker && act->spr.scale.X < 0.46875 && !actorflag(act, SFLAG_SHRINKAUTOAIM)) continue;
2021-12-21 19:22:34 +00:00
if (gotfreezer && act->spr.pal == 1) continue;
}
2022-09-14 16:08:23 +00:00
DVector2 vv = act->spr.pos.XY() - actor->spr.pos.XY();
2022-09-14 16:08:23 +00:00
if ((dv1.Y * vv.X) <= (dv1.X * vv.Y))
if ((dv2.Y * vv.X) >= (dv2.X * vv.Y))
{
2022-09-14 16:08:23 +00:00
double sdist = dv3.dot(vv);
if (sdist > 32 && sdist < smax)
{
2022-09-14 16:08:23 +00:00
int check;
if (actor->isPlayer())
2022-09-14 16:08:23 +00:00
{
double checkval = (act->spr.pos.Z - actor->spr.pos.Z) * 1.25 / sdist;
double horiz = ps[actor->PlayerIndex()].Angles.getPitchWithView().Tan();
check = abs(checkval - horiz) < 0.78125;
2022-09-14 16:08:23 +00:00
}
else check = 1;
2022-09-14 16:08:23 +00:00
int cans = cansee(act->spr.pos.plusZ(-32 + gs.actorinfo[act->spr.picnum].aimoffset), act->sector(), actor->spr.pos.plusZ(-32), actor->sector());
2022-09-14 16:08:23 +00:00
if (check && cans)
{
smax = sdist;
aimed = act;
}
}
}
}
}
}
return aimed;
}
2020-05-17 21:44:53 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void dokneeattack(int snum)
2020-05-17 21:44:53 +00:00
{
auto p = &ps[snum];
if (p->knee_incs > 0)
{
p->oknee_incs = p->knee_incs;
2020-05-17 21:44:53 +00:00
p->knee_incs++;
p->Angles.addPitch(deltaangle(p->GetActor()->spr.Angles.Pitch, (p->GetActor()->getPosWithOffsetZ() - p->actorsqu->spr.pos).Pitch() * 1.1875));
p->sync.actions |= SB_CENTERVIEW;
2020-05-17 21:44:53 +00:00
if (p->knee_incs > 15)
{
p->oknee_incs = p->knee_incs = 0;
2020-05-17 21:44:53 +00:00
p->holster_weapon = 0;
if (p->weapon_pos < 0)
p->weapon_pos = -p->weapon_pos;
if (p->actorsqu != nullptr && (p->GetActor()->spr.pos - p->actorsqu->spr.pos).Length() < 1400/16.)
2020-05-17 21:44:53 +00:00
{
spawnguts(p->actorsqu, PClass::FindActor("DukeJibs6"), 7);
spawn(p->actorsqu, TILE_BLOODPOOL);
S_PlayActorSound(SQUISHED, p->actorsqu);
if (actorflag(p->actorsqu, SFLAG2_TRIGGERRESPAWN))
2020-05-17 21:44:53 +00:00
{
if (p->actorsqu->spr.yint)
operaterespawns(p->actorsqu->spr.yint);
2020-05-17 21:44:53 +00:00
}
if (p->actorsqu->isPlayer())
2020-05-17 21:44:53 +00:00
{
2022-09-01 14:42:23 +00:00
quickkill(&ps[p->actorsqu->PlayerIndex()]);
ps[p->actorsqu->PlayerIndex()].frag_ps = snum;
2020-05-17 21:44:53 +00:00
}
else if (badguy(p->actorsqu))
2020-05-17 21:44:53 +00:00
{
p->actorsqu->Destroy();
2020-05-17 21:44:53 +00:00
p->actors_killed++;
}
else p->actorsqu->Destroy();
2020-05-17 21:44:53 +00:00
}
p->actorsqu = nullptr;
2020-05-17 21:44:53 +00:00
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int makepainsounds(int snum, int type)
{
auto p = &ps[snum];
auto actor = p->GetActor();
2020-05-17 21:44:53 +00:00
int k = 0;
switch (type)
{
case 0:
if (rnd(32))
{
if (p->boot_amount > 0)
k = 1;
else
{
if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
2020-05-17 21:44:53 +00:00
SetPlayerPal(p, PalEntry(32, 64, 64, 64));
2021-12-21 19:22:34 +00:00
actor->spr.extra -= 1 + (krand() & 3);
if (!S_CheckActorSoundPlaying(actor, SHORT_CIRCUIT))
S_PlayActorSound(SHORT_CIRCUIT, actor);
2020-05-17 21:44:53 +00:00
}
}
break;
case 1:
if (rnd(16))
{
if (p->boot_amount > 0)
k = 1;
else
{
if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
2020-05-17 21:44:53 +00:00
SetPlayerPal(p, PalEntry(32, 0, 8, 0));
2021-12-21 19:22:34 +00:00
actor->spr.extra -= 1 + (krand() & 3);
2020-05-17 21:44:53 +00:00
}
}
break;
case 2:
if (rnd(32))
{
if (p->boot_amount > 0)
k = 1;
else
{
if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
2020-05-17 21:44:53 +00:00
SetPlayerPal(p, PalEntry(32, 8, 0, 0));
2021-12-21 19:22:34 +00:00
actor->spr.extra -= 1 + (krand() & 3);
2020-05-17 21:44:53 +00:00
}
}
break;
case 3:
if ((krand() & 3) == 1)
if (p->on_ground)
{
if (p->OnMotorcycle)
2021-12-21 19:22:34 +00:00
actor->spr.extra -= 2;
2020-05-17 21:44:53 +00:00
else
2021-12-21 19:22:34 +00:00
actor->spr.extra -= 4;
S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
2020-05-17 21:44:53 +00:00
}
break;
}
return k;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void footprints(int snum)
{
auto p = &ps[snum];
auto actor = p->GetActor();
2020-05-17 21:44:53 +00:00
if (p->footprintcount > 0 && p->on_ground)
if (p->insector() && (p->cursector->floorstat & CSTAT_SECTOR_SLOPE) != 2)
2020-05-17 21:44:53 +00:00
{
int j = -1;
DukeSectIterator it(actor->sector());
while (auto act = it.Next())
{
if (act->IsKindOf(NAME_DukeFootprints))
if (abs(act->spr.pos.X - p->GetActor()->spr.pos.X) < 24)
if (abs(act->spr.pos.Y - p->GetActor()->spr.pos.Y) < 24)
{
j = 1;
2020-05-17 21:44:53 +00:00
break;
}
}
2020-05-17 21:44:53 +00:00
if (j < 0)
{
p->footprintcount--;
if (p->cursector->lotag == 0 && p->cursector->hitag == 0)
2020-05-17 21:44:53 +00:00
{
DDukeActor* fprint = spawn(actor, PClass::FindActor(NAME_DukeFootprints));
if (fprint)
{
fprint->spr.Angles.Yaw = p->actor->spr.Angles.Yaw;
fprint->spr.pal = p->footprintpal;
fprint->spr.shade = (int8_t)p->footprintshade;
}
2020-05-17 21:44:53 +00:00
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-09-14 19:25:27 +00:00
void playerisdead(int snum, int psectlotag, double floorz, double ceilingz)
2020-05-17 21:44:53 +00:00
{
auto p = &ps[snum];
auto actor = p->GetActor();
2020-05-17 21:44:53 +00:00
if (p->dead_flag == 0)
{
2021-12-21 19:22:34 +00:00
if (actor->spr.pal != 1)
2020-05-17 21:44:53 +00:00
{
SetPlayerPal(p, PalEntry(63, 63, 0, 0));
2022-02-05 12:40:30 +00:00
actor->spr.pos.Z -= 16;
2020-05-17 21:44:53 +00:00
}
#if 0
if (ud.recstat == 1 && ud.multimode < 2)
closedemowrite();
#endif
2021-12-21 19:22:34 +00:00
if (actor->spr.pal != 1)
2020-05-17 21:44:53 +00:00
p->dead_flag = (512 - ((krand() & 1) << 10) + (krand() & 255) - 512) & 2047;
p->jetpack_on = 0;
p->holoduke_on = nullptr;
2020-05-17 21:44:53 +00:00
if (!isRR())S_StopSound(DUKE_JETPACK_IDLE, actor);
S_StopSound(-1, actor, CHAN_VOICE);
2020-05-17 21:44:53 +00:00
2021-12-21 19:22:34 +00:00
if (actor->spr.pal != 1 && (actor->spr.cstat & CSTAT_SPRITE_INVISIBLE) == 0) actor->spr.cstat = 0;
2020-05-17 21:44:53 +00:00
2021-12-21 19:22:34 +00:00
if (ud.multimode > 1 && (actor->spr.pal != 1 || (actor->spr.cstat & CSTAT_SPRITE_INVISIBLE)))
2020-05-17 21:44:53 +00:00
{
if (p->frag_ps != snum)
{
ps[p->frag_ps].frag++;
ps[p->frag_ps].frags[snum]++;
2020-05-17 21:44:53 +00:00
2020-11-29 08:00:00 +00:00
auto pname = PlayerName(p->frag_ps);
2020-05-17 21:44:53 +00:00
if (snum == screenpeek)
{
Printf(PRINT_NOTIFY, "Killed by %s", pname);
2020-05-17 21:44:53 +00:00
}
else
{
Printf(PRINT_NOTIFY, "Killed %s", pname);
2020-05-17 21:44:53 +00:00
}
}
else p->fraggedself++;
2020-05-17 21:44:53 +00:00
p->frag_ps = snum;
}
}
if (psectlotag == ST_2_UNDERWATER)
{
if (p->on_warping_sector == 0)
{
if (abs(p->GetActor()->getOffsetZ() - floorz) > (gs.playerheight * 0.5))
p->GetActor()->spr.pos.Z += 348/ 256.;
2020-05-17 21:44:53 +00:00
}
else
{
actor->spr.pos.Z -= 2;
2022-09-11 17:28:45 +00:00
actor->vel.Z = -348 / 256.;
2020-05-17 21:44:53 +00:00
}
Collision coll;
clipmove(p->GetActor()->spr.pos.XY(), p->GetActor()->getOffsetZ(), &p->cursector, DVector2( 0, 0), 10.25, 4., 4., CLIPMASK0, coll);
2020-05-17 21:44:53 +00:00
}
actor->backuploc();
2020-05-17 21:44:53 +00:00
p->Angles.ViewAngles.Pitch = p->GetActor()->spr.Angles.Pitch = nullAngle;
2020-05-17 21:44:53 +00:00
updatesector(p->GetActor()->getPosWithOffsetZ(), &p->cursector);
2020-05-17 21:44:53 +00:00
pushmove(p->GetActor()->spr.pos.XY(), p->GetActor()->getOffsetZ(), &p->cursector, 8, 4, 20, CLIPMASK0);
2022-09-14 19:25:27 +00:00
if (floorz > ceilingz + 16 && actor->spr.pal != 1)
p->Angles.ViewAngles.Roll = DAngle::fromBuild(-(p->dead_flag + ((floorz + p->GetActor()->getOffsetZ()) * 2)));
2020-05-17 21:44:53 +00:00
p->on_warping_sector = 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int endoflevel(int snum)
{
auto p = &ps[snum];
// the fist puching the end-of-level thing...
p->ofist_incs = p->fist_incs;
2020-05-17 21:44:53 +00:00
p->fist_incs++;
if (p->fist_incs == 28)
{
#if 0
if (ud.recstat == 1) closedemowrite();
#endif
S_PlaySound(PIPEBOMB_EXPLODE);
2020-05-17 21:44:53 +00:00
SetPlayerPal(p, PalEntry(48, 64, 64, 64));
}
if (p->fist_incs > 42)
{
2020-07-07 15:56:20 +00:00
setnextmap(!!p->buttonpalette);
2020-05-17 21:44:53 +00:00
return 1;
}
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-05-18 22:26:07 +00:00
int timedexit(int snum)
2020-05-17 21:44:53 +00:00
{
auto p = &ps[snum];
p->timebeforeexit--;
if (p->timebeforeexit == 26 * 5)
{
FX_StopAllSounds();
if (p->customexitsound >= 0)
{
S_PlaySound(p->customexitsound);
2020-05-17 21:44:53 +00:00
FTA(102, p);
}
}
else if (p->timebeforeexit == 1)
{
2020-07-07 15:56:20 +00:00
setnextmap(false);
2020-05-18 22:26:07 +00:00
return true;
2020-05-17 21:44:53 +00:00
}
2020-05-18 22:26:07 +00:00
return false;
2020-05-17 21:44:53 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-05-17 21:44:53 +00:00
void playerCrouch(int snum)
{
auto p = &ps[snum];
// crouching
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_CROUCH, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0)
2020-05-17 21:44:53 +00:00
{
p->GetActor()->spr.pos.Z += 8 + 3;
p->crack_time = CRACK_TIME;
2020-05-17 21:44:53 +00:00
}
}
2022-09-14 20:04:41 +00:00
void playerJump(int snum, double floorz, double ceilingz)
2020-05-17 21:44:53 +00:00
{
auto p = &ps[snum];
if (p->jumping_toggle == 0 && p->jumping_counter == 0)
{
2022-09-14 20:04:41 +00:00
if ((floorz - ceilingz) > 56)
2020-05-17 21:44:53 +00:00
{
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_JUMP, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0)
2020-05-17 21:44:53 +00:00
{
p->jumping_counter = 1;
p->jumping_toggle = 1;
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void player_struct::apply_seasick()
{
2021-10-08 17:21:29 +00:00
if (isRRRA() && SeaSick && (dead_flag == 0 || (dead_flag && resurrected)))
{
2020-11-29 08:00:00 +00:00
if (SeaSick < 250)
{
2020-11-29 08:00:00 +00:00
if (SeaSick >= 180)
Angles.ViewAngles.Roll -= DAngle::fromDeg(24 * BAngToDegree);
else if (SeaSick >= 130)
Angles.ViewAngles.Roll += DAngle::fromDeg(24 * BAngToDegree);
else if (SeaSick >= 70)
Angles.ViewAngles.Roll -= DAngle::fromDeg(24 * BAngToDegree);
else if (SeaSick >= 20)
Angles.ViewAngles.Roll += DAngle::fromDeg(24 * BAngToDegree);
}
2020-11-29 08:00:00 +00:00
if (SeaSick < 250)
Angles.ViewAngles.Yaw = DAngle::fromDeg(((krand() & 255) - 128) * BAngToDegree);
}
2020-05-17 21:44:53 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-29 08:00:00 +00:00
void player_struct::backuppos(bool noclipping)
{
if (!noclipping)
{
GetActor()->backupvec2();
}
else
{
GetActor()->restorevec2();
}
GetActor()->backupz();
bobpos = GetActor()->spr.pos.XY();
2020-11-29 08:00:00 +00:00
opyoff = pyoff;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-29 08:00:00 +00:00
void player_struct::backupweapon()
{
2020-11-29 08:00:00 +00:00
oweapon_sway = weapon_sway;
oweapon_pos = weapon_pos;
okickback_pic = kickback_pic;
orandom_club_frame = random_club_frame;
ohard_landing = hard_landing;
ofistsign = fistsign;
otipincs = tipincs;
oknee_incs = knee_incs;
oaccess_incs = access_incs;
ofist_incs = fist_incs;
oloogcnt = loogcnt;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-29 08:00:00 +00:00
void player_struct::checkhardlanding()
{
2020-11-29 08:00:00 +00:00
if (hard_landing > 0)
{
Angles.addPitch(maphoriz(hard_landing << 4));
2020-11-29 08:00:00 +00:00
hard_landing--;
}
}
2022-09-15 16:41:01 +00:00
void player_struct::playerweaponsway(double xvel)
2020-08-05 10:04:14 +00:00
{
if (cl_weaponsway)
{
2022-09-15 16:41:01 +00:00
if (xvel < 2 || on_ground == 0 || bobcounter == 1024)
2020-08-05 10:04:14 +00:00
{
2020-11-29 08:00:00 +00:00
if ((weapon_sway & 2047) > (1024 + 96))
weapon_sway -= 96;
else if ((weapon_sway & 2047) < (1024 - 96))
weapon_sway += 96;
else oweapon_sway = weapon_sway = 1024;
2020-08-05 10:04:14 +00:00
}
else
{
2020-11-29 08:00:00 +00:00
weapon_sway = bobcounter;
2020-08-05 10:04:14 +00:00
2020-11-29 08:00:00 +00:00
if ((bobcounter - oweapon_sway) > 256)
2020-08-05 10:04:14 +00:00
{
2020-11-29 08:00:00 +00:00
oweapon_sway = weapon_sway;
2020-08-05 10:04:14 +00:00
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void checklook(int snum, ESyncBits actions)
2020-05-17 21:44:53 +00:00
{
auto p = &ps[snum];
if ((actions & SB_LOOK_LEFT) && !p->OnMotorcycle)
2020-05-17 21:44:53 +00:00
{
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_LOOKLEFT, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0)
{
actions &= ~SB_LOOK_LEFT;
}
}
if ((actions & SB_LOOK_RIGHT) && !p->OnMotorcycle)
{
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_LOOKRIGHT, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0)
{
actions &= ~SB_LOOK_RIGHT;
}
2020-05-17 21:44:53 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void playerCenterView(int snum)
{
auto p = &ps[snum];
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_RETURNTOCENTER, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0)
{
p->sync.actions |= SB_CENTERVIEW;
}
else
{
p->sync.actions &= ~SB_CENTERVIEW;
}
}
2020-08-28 22:57:07 +00:00
void playerLookUp(int snum, ESyncBits actions)
{
auto p = &ps[snum];
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_LOOKUP, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0)
{
p->sync.actions |= SB_CENTERVIEW;
}
else
{
p->sync.actions &= ~SB_LOOK_UP;
}
}
2020-08-28 22:57:07 +00:00
void playerLookDown(int snum, ESyncBits actions)
{
auto p = &ps[snum];
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_LOOKDOWN, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0)
{
p->sync.actions |= SB_CENTERVIEW;
}
else
{
p->sync.actions &= ~SB_LOOK_DOWN;
}
}
2020-08-28 22:57:07 +00:00
void playerAimUp(int snum, ESyncBits actions)
{
auto p = &ps[snum];
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_AIMUP, snum, p->GetActor(), -1);
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0)
{
p->sync.actions &= ~SB_AIM_UP;
}
}
2020-08-28 22:57:07 +00:00
void playerAimDown(int snum, ESyncBits actions)
{
auto p = &ps[snum];
SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum);
OnEvent(EVENT_AIMDOWN, snum, p->GetActor(), -1); // due to a typo in WW2GI's CON files this is the same as EVENT_AIMUP.
if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0)
{
p->sync.actions &= ~SB_AIM_DOWN;
}
}
//---------------------------------------------------------------------------
//
// split out so that the weapon check can be done right.
//
//---------------------------------------------------------------------------
bool movementBlocked(player_struct *p)
{
auto blockingweapon = [=]()
{
if (isRR()) return false;
if (isWW2GI()) return aplWeaponWorksLike(p->curr_weapon, p->GetPlayerNum()) == TRIPBOMB_WEAPON;
else return p->curr_weapon == TRIPBOMB_WEAPON;
};
auto weapondelay = [=]()
{
if (isWW2GI()) return aplWeaponFireDelay(p->curr_weapon, p->GetPlayerNum());
else return 4;
};
return (p->fist_incs ||
p->transporter_hold > 2 ||
p->hard_landing ||
p->access_incs > 0 ||
p->knee_incs > 0 ||
(blockingweapon() && p->kickback_pic > 1 && p->kickback_pic < weapondelay()));
}
2020-05-19 19:21:55 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int haskey(sectortype* sectp, int snum)
2020-05-19 19:21:55 +00:00
{
auto p = &ps[snum];
if (!sectp)
return 0;
if (!sectp->keyinfo)
2020-05-19 19:21:55 +00:00
return 1;
if (sectp->keyinfo > 6)
2020-05-19 19:21:55 +00:00
return 1;
int wk = sectp->keyinfo;
2020-05-19 19:21:55 +00:00
if (wk > 3)
wk -= 3;
if (p->keys[wk] == 1)
{
sectp->keyinfo = 0;
2020-05-19 19:21:55 +00:00
return 1;
}
return 0;
}
END_DUKE_NS