raze/source/games/exhumed/src/gun.cpp

1168 lines
35 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 sirlemonhead, Nuke.YKT
This file is part of PCExhumed.
PCExhumed is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "aistuff.h"
#include "engine.h"
#include "player.h"
#include "exhumed.h"
#include "view.h"
#include "status.h"
#include "sound.h"
#include "input.h"
#include <string.h>
#include <assert.h>
#include "v_2ddrawer.h"
#include "sequence.h"
BEGIN_PS_NS
Weapon WeaponInfo[] = {
{ kSeqSword, { 0, 1, 3, 7, -1, 2, 4, 5, 6, 8, 9, 10 }, 0, 0, 0, true },
{ kSeqPistol, { 0, 3, 2, 4, -1, 1, 0, 0, 0, 0, 0, 0 }, 1, 0, 1, false },
{ kSeqM60, { 0, 5, 6, 16, -1, 21, 0, 0, 0, 0, 0, 0 }, 2, 0, 1, false },
{ kSeqFlamer, { 0, 2, 5, 5, 6, 1, 0, 0, 0, 0, 0, 0 }, 3, 4, 1, false },
{ kSeqGrenade, { 0, 2, 3, 4, -1, 1, 0, 0, 0, 0, 0, 0 }, 4, 0, 1, true },
{ kSeqCobra, { 0, 1, 2, 2, -1, 4, 0, 0, 0, 0, 0, 0 }, 5, 0, 1, true },
{ kSeqRavolt, { 0, 1, 2, 3, -1, 4, 0, 0, 0, 0, 0, 0 }, 6, 0, 1, true },
{ kSeqRothands,{ 0, 1, 2, -1, -1, -1, 0, 0, 0, 0, 0, 0 }, 7, 0, 0, true },
{ kSeqDead, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 1, 0, false },
{ kSeqDeadEx, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 1, 0, false },
{ kSeqDeadBrn, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 1, 0, false }
};
int16_t nTemperature[kMaxPlayers];
static const uint8_t nMinAmmo[] = { 0, 24, 51, 50, 1, 0, 0 };
int isRed = 0;
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-30 00:07:14 +00:00
void SerializeGun(FSerializer& arc)
{
if (arc.BeginObject("gun"))
{
arc.Array("temperature", nTemperature, kMaxPlayers)
("isred", isRed)
.EndObject();
2020-11-30 00:07:14 +00:00
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void RestoreMinAmmo(int nPlayer)
{
2019-11-16 12:28:07 +00:00
for (int i = 0; i < kMaxWeapons; i++)
{
if (i == kWeaponGrenade) {
continue;
}
if ((1 << i) & PlayerList[nPlayer].nPlayerWeapons)
2019-11-16 12:28:07 +00:00
{
if (nMinAmmo[i] > PlayerList[nPlayer].nAmmo[i]) {
PlayerList[nPlayer].nAmmo[i] = nMinAmmo[i];
}
}
}
CheckClip(nPlayer);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void FillWeapons(int nPlayer)
{
PlayerList[nPlayer].nPlayerWeapons = 0xFFFF; // turn on all bits
2019-11-16 12:28:07 +00:00
for (int i = 0; i < kMaxWeapons; i++)
{
if (WeaponInfo[i].d) {
PlayerList[nPlayer].nAmmo[i] = 300;
2019-11-16 12:28:07 +00:00
}
}
2019-11-16 12:28:07 +00:00
CheckClip(nPlayer);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void ResetPlayerWeapons(int nPlayer)
{
2019-11-16 12:28:07 +00:00
for (int i = 0; i < kMaxWeapons; i++)
{
PlayerList[nPlayer].nAmmo[i] = 0;
}
2019-11-16 12:28:07 +00:00
PlayerList[nPlayer].nCurrentWeapon = 0;
PlayerList[nPlayer].nState = 0;
PlayerList[nPlayer].nSeqSize2 = 0;
2021-10-21 17:44:53 +00:00
PlayerList[nPlayer].pPlayerGrenade = nullptr;
PlayerList[nPlayer].nPlayerWeapons = 0x1; // turn on bit 1 only
}
void InitWeapons()
{
2021-10-21 17:44:53 +00:00
for (auto& p : PlayerList) p.pPlayerGrenade = nullptr;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-11-21 18:24:46 +00:00
void SetNewWeapon(int nPlayer, int nWeapon)
{
2019-11-16 12:28:07 +00:00
if (nWeapon == kWeaponMummified)
{
PlayerList[nPlayer].nLastWeapon = PlayerList[nPlayer].nCurrentWeapon;
PlayerList[nPlayer].bIsFiring = false;
PlayerList[nPlayer].nState = 5;
SetPlayerMummified(nPlayer, true);
2019-11-16 12:28:07 +00:00
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
}
else
{
if (nWeapon < 0)
{
PlayerList[nPlayer].nPlayerOldWeapon = PlayerList[nPlayer].nCurrentWeapon;
2019-11-16 12:28:07 +00:00
}
else if (nWeapon != kWeaponGrenade || PlayerList[nPlayer].nAmmo[kWeaponGrenade] > 0)
{
int nCurrentWeapon = PlayerList[nPlayer].nCurrentWeapon;
2019-11-16 12:28:07 +00:00
if (nCurrentWeapon != kWeaponMummified)
{
if (PlayerList[nPlayer].bIsFiring || nWeapon == nCurrentWeapon) {
return;
}
}
else
{
PlayerList[nPlayer].nCurrentWeapon = nWeapon;
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
}
}
else {
return;
}
}
PlayerList[nPlayer].nNextWeapon = nWeapon;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-11-21 18:24:46 +00:00
void SetNewWeaponImmediate(int nPlayer, int nWeapon)
{
2019-11-16 12:28:07 +00:00
SetNewWeapon(nPlayer, nWeapon);
2019-11-16 12:28:07 +00:00
PlayerList[nPlayer].nCurrentWeapon = nWeapon;
PlayerList[nPlayer].nNextWeapon = -1;
PlayerList[nPlayer].nSeqSize2 = 0;
PlayerList[nPlayer].nState = 0;
}
2021-11-21 18:24:46 +00:00
void SetNewWeaponIfBetter(int nPlayer, int nWeapon)
{
2019-11-16 12:28:07 +00:00
if (nWeapon > PlayerList[nPlayer].nCurrentWeapon) {
SetNewWeapon(nPlayer, nWeapon);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void SelectNewWeapon(int nPlayer)
{
2019-11-16 12:28:07 +00:00
int nWeapon = kWeaponRing; // start at the highest weapon number
uint16_t di = PlayerList[nPlayer].nPlayerWeapons;
2019-11-16 12:28:07 +00:00
uint16_t dx = 0x40; // bit 7 turned on
2019-11-16 12:28:07 +00:00
while (dx)
{
if (di & dx)
{
// we have this weapon
if (!WeaponInfo[nWeapon].d || PlayerList[nPlayer].nAmmo[WeaponInfo[nWeapon].nAmmoType])
break;
}
2019-11-16 12:28:07 +00:00
nWeapon--;
dx >>= 1;
}
2019-11-16 12:28:07 +00:00
if (nWeapon < 0)
nWeapon = kWeaponSword;
PlayerList[nPlayer].bIsFiring = false;
2019-11-16 12:28:07 +00:00
SetNewWeapon(nPlayer, nWeapon);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void StopFiringWeapon(int nPlayer)
{
PlayerList[nPlayer].bIsFiring = false;
}
void FireWeapon(int nPlayer)
{
2019-11-16 12:28:07 +00:00
if (!PlayerList[nPlayer].bIsFiring) {
PlayerList[nPlayer].bIsFiring = true;
2019-11-16 12:28:07 +00:00
}
}
void SetWeaponStatus(int nPlayer)
{
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
uint8_t WeaponCanFire(int nPlayer)
{
2021-11-21 18:24:46 +00:00
int nWeapon = PlayerList[nPlayer].nCurrentWeapon;
2021-11-22 23:20:15 +00:00
auto pSector =PlayerList[nPlayer].pPlayerViewSect;
2021-11-22 23:20:15 +00:00
if (!(pSector->Flag & kSectUnderwater) || WeaponInfo[nWeapon].bFireUnderwater)
2019-11-16 12:28:07 +00:00
{
2021-11-21 18:24:46 +00:00
int nAmmoType = WeaponInfo[nWeapon].nAmmoType;
2019-11-16 12:28:07 +00:00
if (WeaponInfo[nWeapon].d <= PlayerList[nPlayer].nAmmo[nAmmoType]) {
return true;
2019-11-16 12:28:07 +00:00
}
}
return false;
}
// UNUSED
void ResetSwordSeqs()
{
2019-11-16 12:28:07 +00:00
WeaponInfo[kWeaponSword].b[2] = 3;
WeaponInfo[kWeaponSword].b[3] = 7;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
Collision CheckCloseRange(int nPlayer, DVector3& pos, sectortype* *ppSector)
{
auto pActor = PlayerList[nPlayer].pActor;
HitInfo hit{};
hitscan(pos, *ppSector, DVector3(pActor->spr.angle.ToVector() * 1024, 0 ), hit, CLIPMASK1);
const double ecx = 56.84; // bsin(150, -3)
double sqrtNum = (hit.hitpos.XY() - pos.XY()).LengthSquared();
2021-11-26 13:26:03 +00:00
Collision c;
c.setNone();
if (sqrtNum >= ecx * ecx)
2021-10-21 22:08:40 +00:00
return c;
pos = hit.hitpos;
2021-11-25 23:25:28 +00:00
*ppSector = hit.hitSector;
2021-11-25 23:25:28 +00:00
if (hit.actor()) {
c.setSprite(hit.actor());
2019-11-16 12:28:07 +00:00
}
2021-11-25 23:25:28 +00:00
if (hit.hitWall) {
c.setWall(wallnum(hit.hitWall));
2019-11-16 12:28:07 +00:00
}
2021-10-21 22:08:40 +00:00
return c;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void CheckClip(int nPlayer)
{
if (PlayerList[nPlayer].nPlayerClip <= 0)
2019-11-16 12:28:07 +00:00
{
PlayerList[nPlayer].nPlayerClip = PlayerList[nPlayer].nAmmo[kWeaponM60];
2019-11-16 12:28:07 +00:00
if (PlayerList[nPlayer].nPlayerClip > 100) {
PlayerList[nPlayer].nPlayerClip = 100;
2019-11-16 12:28:07 +00:00
}
}
// Reset pistol's clip amount.
PlayerList[nPlayer].nPistolClip = PlayerList[nPlayer].nAmmo[kWeaponPistol] % 6;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void MoveWeapons(int nPlayer)
{
2019-11-16 12:28:07 +00:00
static int dword_96E22 = 0;
2021-11-22 23:20:15 +00:00
int nSectFlag = PlayerList[nPlayer].pPlayerViewSect->Flag;
2019-11-16 12:28:07 +00:00
if ((nSectFlag & kSectUnderwater) && (totalmoves & 1)) {
return;
}
nPilotLightFrame++;
if (nPilotLightFrame >= nPilotLightCount)
nPilotLightFrame = 0;
if (!PlayerList[nPlayer].bIsFiring || (nSectFlag & kSectUnderwater))
nTemperature[nPlayer] = 0;
auto pPlayerActor = PlayerList[nPlayer].pActor;
int nWeapon = PlayerList[nPlayer].nCurrentWeapon;
2019-11-16 12:28:07 +00:00
if (nWeapon < -1)
{
if (PlayerList[nPlayer].nNextWeapon != -1)
2019-11-16 12:28:07 +00:00
{
PlayerList[nPlayer].nCurrentWeapon = PlayerList[nPlayer].nNextWeapon;
PlayerList[nPlayer].nState = 0;
PlayerList[nPlayer].nSeqSize2 = 0;
PlayerList[nPlayer].nNextWeapon = -1;
2019-11-16 12:28:07 +00:00
}
return;
}
// loc_26ACC
int eax = PlayerList[nPlayer].nState;
int nSeq = WeaponInfo[nWeapon].nSeq;
2019-11-16 12:28:07 +00:00
int var_3C = WeaponInfo[nWeapon].b[eax] + SeqOffsets[nSeq];
2019-11-16 12:28:07 +00:00
int var_1C = (PlayerList[nPlayer].nDouble > 0) + 1;
2019-11-16 12:28:07 +00:00
frames = var_1C - 1;
for (frames = var_1C; frames > 0; frames--)
{
seq_MoveSequence(pPlayerActor, var_3C, PlayerList[nPlayer].nSeqSize2);
2019-11-16 12:28:07 +00:00
PlayerList[nPlayer].nSeqSize2++;
2019-11-16 12:28:07 +00:00
dword_96E22++;
if (dword_96E22 >= 15) {
dword_96E22 = 0;
}
if (PlayerList[nPlayer].nSeqSize2 >= SeqSize[var_3C])
2019-11-16 12:28:07 +00:00
{
if (PlayerList[nPlayer].nNextWeapon == -1)
2019-11-16 12:28:07 +00:00
{
switch (PlayerList[nPlayer].nState)
2019-11-16 12:28:07 +00:00
{
default:
break;
case 0:
{
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
SetWeaponStatus(nPlayer);
break;
}
case 1:
{
if (PlayerList[nPlayer].bIsFiring)
{
if (!WeaponCanFire(nPlayer))
{
if (!dword_96E22) {
D3PlayFX(StaticSound[4], PlayerList[nPlayer].pActor);
2019-11-16 12:28:07 +00:00
}
}
else
{
if (nWeapon == kWeaponRing)
{
2021-10-19 13:06:46 +00:00
if (Ra[nPlayer].pTarget == nullptr)
2019-11-16 12:28:07 +00:00
break;
Ra[nPlayer].nAction = 0;
Ra[nPlayer].nFrame = 0;
Ra[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
}
PlayerList[nPlayer].nState = 2;
2019-11-16 12:28:07 +00:00
if (nWeapon == 0)
break;
if (nWeapon == kWeaponGrenade)
{
BuildGrenade(nPlayer);
AddAmmo(nPlayer, 4, -1);
}
else if (nWeapon == kWeaponMummified)
2019-11-16 12:28:07 +00:00
{
ShootStaff(nPlayer);
}
}
}
break;
}
case 2:
case 6:
case 7:
case 8:
{
if (nWeapon == kWeaponPistol && PlayerList[nPlayer].nPistolClip <= 0)
2019-11-16 12:28:07 +00:00
{
PlayerList[nPlayer].nState = 3;
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
PlayerList[nPlayer].nPistolClip = min<int>(6, PlayerList[nPlayer].nAmmo[kWeaponPistol]);
2019-11-16 12:28:07 +00:00
break;
}
else if (nWeapon == kWeaponGrenade)
{
if (!PlayerList[nPlayer].bIsFiring)
{
PlayerList[nPlayer].nState = 3;
2019-11-16 12:28:07 +00:00
break;
}
else
{
PlayerList[nPlayer].nSeqSize2 = SeqSize[var_3C] - 1;
2019-11-16 12:28:07 +00:00
continue;
}
}
else if (nWeapon == kWeaponMummified)
{
PlayerList[nPlayer].nState = 0;
PlayerList[nPlayer].nCurrentWeapon = PlayerList[nPlayer].nLastWeapon;
2019-11-16 12:28:07 +00:00
nWeapon = PlayerList[nPlayer].nCurrentWeapon;
SetPlayerMummified(nPlayer, false);
2019-11-16 12:28:07 +00:00
break;
}
else
{
// loc_26D88:
if (PlayerList[nPlayer].bIsFiring && WeaponCanFire(nPlayer))
{
if (nWeapon != kWeaponM60 && nWeapon != kWeaponPistol) {
PlayerList[nPlayer].nState = 3;
2019-11-16 12:28:07 +00:00
}
}
else
{
if (WeaponInfo[nWeapon].b[4] == -1)
{
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
}
else
{
if (nWeapon == kWeaponFlamer && (nSectFlag & kSectUnderwater))
{
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
}
else
{
PlayerList[nPlayer].nState = 4;
2019-11-16 12:28:07 +00:00
}
}
}
break;
}
}
case 3:
case 9:
case 10:
case 11:
{
if (nWeapon == kWeaponMummified)
{
PlayerList[nPlayer].nCurrentWeapon = PlayerList[nPlayer].nLastWeapon;
2019-11-16 12:28:07 +00:00
nWeapon = PlayerList[nPlayer].nCurrentWeapon;
PlayerList[nPlayer].nState = 0;
2019-11-16 12:28:07 +00:00
break;
}
else if (nWeapon == kWeaponRing)
{
if (!WeaponInfo[nWeapon].d || PlayerList[nPlayer].nAmmo[WeaponInfo[nWeapon].nAmmoType])
{
if (!PlayerList[nPlayer].bIsFiring) {
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
}
else {
break;
}
}
else
{
SelectNewWeapon(nPlayer);
}
Ra[nPlayer].nState = 0;
2019-11-16 12:28:07 +00:00
break;
}
else if (nWeapon == kWeaponM60)
{
CheckClip(nPlayer);
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
break;
}
else if (nWeapon == kWeaponGrenade)
{
if (!WeaponInfo[nWeapon].d || PlayerList[nPlayer].nAmmo[WeaponInfo[nWeapon].nAmmoType])
{
PlayerList[nPlayer].nState = 0;
2019-11-16 12:28:07 +00:00
break;
}
else
{
SelectNewWeapon(nPlayer);
PlayerList[nPlayer].nState = 5;
PlayerList[nPlayer].nSeqSize2 = SeqSize[WeaponInfo[kWeaponGrenade].b[0] + SeqOffsets[nSeq]] - 1; // CHECKME
2019-11-16 12:28:07 +00:00
goto loc_flag; // FIXME
}
}
else
{
if (PlayerList[nPlayer].bIsFiring && WeaponCanFire(nPlayer)) {
PlayerList[nPlayer].nState = 2;
2019-11-16 12:28:07 +00:00
break;
}
if (WeaponInfo[nWeapon].b[4] == -1)
{
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
break;
}
if (nWeapon == kWeaponFlamer && (nSectFlag & kSectUnderwater))
{
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
}
else
{
PlayerList[nPlayer].nState = 4;
2019-11-16 12:28:07 +00:00
}
}
break;
}
case 4:
{
PlayerList[nPlayer].nState = 1;
2019-11-16 12:28:07 +00:00
break;
}
case 5:
{
PlayerList[nPlayer].nCurrentWeapon = PlayerList[nPlayer].nNextWeapon;
2019-11-16 12:28:07 +00:00
nWeapon = PlayerList[nPlayer].nCurrentWeapon;
PlayerList[nPlayer].nState = 0;
PlayerList[nPlayer].nNextWeapon = -1;
2019-11-16 12:28:07 +00:00
SetWeaponStatus(nPlayer);
break;
}
}
// loc_26FC5
var_3C = SeqOffsets[WeaponInfo[nWeapon].nSeq] + WeaponInfo[nWeapon].b[PlayerList[nPlayer].nState];
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
}
else
{
if (PlayerList[nPlayer].nState == 5)
2019-11-16 12:28:07 +00:00
{
PlayerList[nPlayer].nCurrentWeapon = PlayerList[nPlayer].nNextWeapon;
2019-11-16 12:28:07 +00:00
nWeapon = PlayerList[nPlayer].nCurrentWeapon;
PlayerList[nPlayer].nNextWeapon = -1;
PlayerList[nPlayer].nState = 0;
2019-11-16 12:28:07 +00:00
}
else
{
PlayerList[nPlayer].nState = 5;
2019-11-16 12:28:07 +00:00
}
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
continue;
}
} // end of if (PlayerList[nPlayer].field_34 >= SeqSize[var_3C])
loc_flag:
2019-11-16 12:28:07 +00:00
// loc_27001
int nFrameFlag = seq_GetFrameFlag(var_3C, PlayerList[nPlayer].nSeqSize2);
2019-11-16 12:28:07 +00:00
if (((!(nSectFlag & kSectUnderwater)) || nWeapon == kWeaponRing) && (nFrameFlag & 4))
{
BuildFlash(nPlayer, 512);
2019-11-16 12:28:07 +00:00
AddFlash(
pPlayerActor->sector(),
2022-08-20 14:19:07 +00:00
pPlayerActor->spr.pos,
2019-11-16 12:28:07 +00:00
0);
}
if (nFrameFlag & 0x80)
{
int nAction = PlayerList[nPlayer].nAction;
int var_38 = 1;
if (nAction < 10 || nAction > 12) {
var_38 = 0;
}
if (nPlayer == nLocalPlayer) {
obobangle = bobangle = 512;
}
if (nWeapon == kWeaponFlamer && (!(nSectFlag & kSectUnderwater)))
{
nTemperature[nPlayer]++;
if (nTemperature[nPlayer] > 50)
{
nTemperature[nPlayer] = 0;
PlayerList[nPlayer].nState = 4;
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
}
}
2021-11-21 18:24:46 +00:00
int nAmmoType = WeaponInfo[nWeapon].nAmmoType;
DAngle nAngle = pPlayerActor->spr.angle;
auto thePos = pPlayerActor->spr.pos;
2019-11-16 12:28:07 +00:00
2022-09-09 16:32:42 +00:00
int ebp = nAngle.Cos() * (1 << 14) * (pPlayerActor->native_clipdist() << 3);
int ebx = nAngle.Sin() * (1 << 14) * (pPlayerActor->native_clipdist() << 3);
2019-11-16 12:28:07 +00:00
if (WeaponInfo[nWeapon].c)
{
int ecx;
int theVal = (totalmoves + 101) & (WeaponInfo[nWeapon].c - 1);
if (theVal & 1)
ecx = -theVal;
else
ecx = theVal;
2022-09-10 19:16:25 +00:00
DAngle angle = (nAngle + DAngle90).Normalized360();
ebp += angle.Cos() * (1 << 3) * ecx;
ebx += angle.Sin() * (1 << 3) * ecx;
2019-11-16 12:28:07 +00:00
}
double nHeight = GetActorHeight(pPlayerActor) * -0.5;
2019-11-16 12:28:07 +00:00
if (nAction < 6)
{
2022-09-10 19:16:25 +00:00
nHeight -= 7;
2019-11-16 12:28:07 +00:00
}
else
{
if (!var_38)
{
2022-09-10 19:16:25 +00:00
nHeight += 4;
2019-11-16 12:28:07 +00:00
}
else {
2022-09-10 19:16:25 +00:00
nHeight -= 10;
2019-11-16 12:28:07 +00:00
}
}
auto pSectorB = pPlayerActor->sector();
2019-11-16 12:28:07 +00:00
switch (nWeapon)
{
// loc_27266:
case kWeaponSword:
{
2022-09-10 19:16:25 +00:00
nHeight -= PlayerList[nLocalPlayer].horizon.horiz.asbuildf() * 0.25;
2019-11-16 12:28:07 +00:00
2022-09-10 19:16:25 +00:00
thePos.Z += nHeight;
2019-11-16 12:28:07 +00:00
int var_28;
if (PlayerList[nPlayer].nState == 2) {
2019-11-16 12:28:07 +00:00
var_28 = 6;
}
else {
var_28 = 9;
}
auto cRange = CheckCloseRange(nPlayer, thePos, &pSectorB);
2019-11-16 12:28:07 +00:00
2021-10-21 22:08:40 +00:00
if (cRange.type != kHitNone)
2019-11-16 12:28:07 +00:00
{
int nDamage = BulletInfo[kWeaponSword].nDamage;
2019-11-16 12:28:07 +00:00
if (PlayerList[nPlayer].nDouble) {
2019-11-16 12:28:07 +00:00
nDamage *= 2;
}
2021-10-21 22:08:40 +00:00
//if (cRange.type != kHitNone)
2019-11-16 12:28:07 +00:00
{
2021-10-21 22:08:40 +00:00
if (cRange.type == kHitWall)
2019-11-16 12:28:07 +00:00
{
// loc_2730E:
var_28 += 2;
}
2021-10-21 22:08:40 +00:00
else if (cRange.type == kHitSprite)
2019-11-16 12:28:07 +00:00
{
2021-11-26 13:26:03 +00:00
auto pActor2 = cRange.actor();
2019-11-16 12:28:07 +00:00
if (pActor2->spr.cstat & (CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_ONE_SIDE))
2019-11-16 12:28:07 +00:00
{
var_28 += 2;
}
else if (pActor2->spr.statnum > 90 && pActor2->spr.statnum <= 199)
2019-11-16 12:28:07 +00:00
{
2021-10-21 07:46:24 +00:00
runlist_DamageEnemy(pActor2, pPlayerActor, nDamage);
2019-11-16 12:28:07 +00:00
if (pActor2->spr.statnum < 102) {
2019-11-16 12:28:07 +00:00
var_28++;
}
else if (pActor2->spr.statnum == 102)
2019-11-16 12:28:07 +00:00
{
// loc_27370:
BuildAnim(nullptr, 12, 0, thePos, pSectorB, 30, 0);
2019-11-16 12:28:07 +00:00
}
else if (pActor2->spr.statnum == kStatExplodeTrigger) {
2019-11-16 12:28:07 +00:00
var_28 += 2;
}
else {
var_28++;
}
}
else
{
// loc_27370:
BuildAnim(nullptr, 12, 0, thePos, pSectorB, 30, 0);
2019-11-16 12:28:07 +00:00
}
}
}
}
// loc_27399:
PlayerList[nPlayer].nState = var_28;
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
break;
}
case kWeaponFlamer:
{
if (nSectFlag & kSectUnderwater)
{
DoBubbles(nPlayer);
PlayerList[nPlayer].nState = 1;
PlayerList[nPlayer].nSeqSize2 = 0;
2021-10-21 07:46:24 +00:00
StopActorSound(pPlayerActor);
2019-11-16 12:28:07 +00:00
break;
}
else
{
if (var_38) {
2022-09-10 19:16:25 +00:00
nHeight += 3;
2019-11-16 12:28:07 +00:00
}
else {
2022-09-10 19:16:25 +00:00
nHeight -= 10;
2019-11-16 12:28:07 +00:00
}
// fall through to case 1 (kWeaponPistol)
2021-10-21 07:46:24 +00:00
[[fallthrough]];
2019-11-16 12:28:07 +00:00
}
}
case kWeaponM60:
{
if (nWeapon == kWeaponM60) { // hack(?) to do fallthrough from kWeapon3 into kWeaponPistol without doing the nQuake[] change
2022-09-07 07:58:41 +00:00
nQuake[nPlayer] = 0.5;
2019-11-16 12:28:07 +00:00
}
// fall through
[[fallthrough]];
2019-11-16 12:28:07 +00:00
}
case kWeaponPistol:
{
2022-09-10 19:16:25 +00:00
double h = PlayerList[nLocalPlayer].horizon.horiz.asbuildf() / 64.;
2021-05-16 17:20:36 +00:00
nHeight -= h;
2019-11-16 12:28:07 +00:00
2021-10-21 20:18:29 +00:00
DExhumedActor* target = nullptr;
if (sPlayerInput[nPlayer].pTarget != nullptr && Autoaim(nPlayer))
2019-11-16 12:28:07 +00:00
{
2021-12-07 17:53:02 +00:00
DExhumedActor* t = sPlayerInput[nPlayer].pTarget;
2021-10-21 20:18:29 +00:00
// only autoaim if target is in front of the player.
assert(t->sector());
DAngle angletotarget = VecToAngle(t->spr.pos - pPlayerActor->spr.pos);
DAngle anglediff = absangle(pPlayerActor->spr.angle, angletotarget);
if (anglediff < DAngle90)
2021-05-16 17:20:36 +00:00
{
2021-10-21 20:18:29 +00:00
target = t;
h = 0;
2021-05-16 17:20:36 +00:00
}
2019-11-16 12:28:07 +00:00
}
2022-09-10 19:16:25 +00:00
BuildBullet(pPlayerActor, nAmmoType, nHeight, nAngle, target, var_1C, int(h * zworldtoint));
2019-11-16 12:28:07 +00:00
break;
}
case kWeaponGrenade:
{
2022-09-10 20:39:40 +00:00
ThrowGrenade(nPlayer, nHeight - 10, FixedToInt(PlayerList[nLocalPlayer].horizon.horiz.asq16()));
2019-11-16 12:28:07 +00:00
break;
}
case kWeaponStaff:
{
2022-09-10 20:16:37 +00:00
BuildSnake(nPlayer, nHeight);
2022-09-07 07:58:41 +00:00
nQuake[nPlayer] = 2.;
2019-11-16 12:28:07 +00:00
PlayerList[nPlayer].nThrust -= pPlayerActor->spr.angle.ToVector() * 2;
2019-11-16 12:28:07 +00:00
break;
}
case kWeaponRing:
break;
case kWeaponMummified:
{
int nDamage = BulletInfo[kWeaponMummified].nDamage;
if (PlayerList[nPlayer].nDouble) {
2019-11-16 12:28:07 +00:00
nDamage *= 2;
}
2021-10-21 07:46:24 +00:00
runlist_RadialDamageEnemy(pPlayerActor, nDamage, BulletInfo[kWeaponMummified].nRadius);
2019-11-16 12:28:07 +00:00
break;
}
}
// end of switch, loc_2753E:
if (nWeapon < kWeaponMummified)
{
if (nWeapon != kWeaponGrenade)
2021-01-19 08:44:16 +00:00
{
if (WeaponInfo[nWeapon].d) {
AddAmmo(nPlayer, nAmmoType, -1);
2019-11-16 12:28:07 +00:00
}
if (nWeapon == kWeaponM60) {
PlayerList[nPlayer].nPlayerClip--;
2019-11-16 12:28:07 +00:00
}
else if (nWeapon == kWeaponPistol) {
PlayerList[nPlayer].nPistolClip--;
2019-11-16 12:28:07 +00:00
}
}
if (!WeaponInfo[nWeapon].d || PlayerList[nPlayer].nAmmo[WeaponInfo[nWeapon].nAmmoType])
{
if (nWeapon == kWeaponM60 && PlayerList[nPlayer].nPlayerClip <= 0)
2019-11-16 12:28:07 +00:00
{
PlayerList[nPlayer].nState = 3;
PlayerList[nPlayer].nSeqSize2 = 0;
2019-11-16 12:28:07 +00:00
// goto loc_27609:
}
}
else if (nWeapon != kWeaponGrenade)
{
SelectNewWeapon(nPlayer);
// go to loc_27609:
}
}
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DrawWeapons(double interpfrac)
{
2019-11-16 12:28:07 +00:00
if (bCamera) {
return;
}
int nWeapon = PlayerList[nLocalPlayer].nCurrentWeapon;
2019-11-16 12:28:07 +00:00
if (nWeapon < -1) {
return;
}
int var_34 = PlayerList[nLocalPlayer].nState;
int var_30 = SeqOffsets[WeaponInfo[nWeapon].nSeq];
int var_28 = var_30 + WeaponInfo[nWeapon].b[var_34];
2021-11-22 23:41:21 +00:00
int8_t nShade = initsectp->ceilingshade;
int nDouble = PlayerList[nLocalPlayer].nDouble;
2019-11-16 12:28:07 +00:00
int nPal = kPalNormal;
2019-11-16 12:28:07 +00:00
if (nDouble)
{
2020-11-30 00:07:14 +00:00
if (isRed) {
nPal = kPalRedBrite;
2019-11-16 12:28:07 +00:00
}
2020-11-30 00:07:14 +00:00
isRed = isRed == 0;
2019-11-16 12:28:07 +00:00
}
nPal = RemapPLU(nPal);
double xOffset = 0, yOffset = 0;
bool screenalign = false;
if (cl_weaponsway)
2019-11-16 12:28:07 +00:00
{
double nBobAngle, nVal;
if (cl_hudinterpolation)
{
nBobAngle = interpolatedvalue<double>(obobangle, bobangle, interpfrac) * BAngToDegree;
nVal = interpolatedvalue<double>(PlayerList[nLocalPlayer].ototalvel, PlayerList[nLocalPlayer].totalvel, interpfrac);
}
else
{
nBobAngle = bobangle;
nVal = PlayerList[nLocalPlayer].totalvel;
}
yOffset = nVal * fabs(g_sindeg(nBobAngle)) * (1. / 16.);
if (var_34 == 1)
{
xOffset = nVal * g_cosdeg(nBobAngle) * (1. / 8.);
}
2019-11-16 12:28:07 +00:00
}
else
{
obobangle = bobangle = 512;
}
2019-11-16 12:28:07 +00:00
if (nWeapon == 3 && var_34 == 1) {
seq_DrawPilotLightSeq(xOffset, yOffset);
}
else if (nWeapon == 8 || nWeapon == 9)
{
screenalign = true;
}
2019-11-16 12:28:07 +00:00
if (nWeapon < 0) {
nShade = PlayerList[nLocalPlayer].pActor->spr.shade;
2019-11-16 12:28:07 +00:00
}
double const look_anghalf = PlayerList[nLocalPlayer].angle.look_anghalf(interpfrac);
double const looking_arc = PlayerList[nLocalPlayer].angle.looking_arc(interpfrac);
xOffset -= look_anghalf;
yOffset += looking_arc;
seq_DrawGunSequence(var_28, PlayerList[nLocalPlayer].nSeqSize2, xOffset, yOffset, nShade, nPal, screenalign);
2019-11-16 12:28:07 +00:00
if (nWeapon != kWeaponM60)
return;
2019-11-16 12:28:07 +00:00
switch (var_34)
{
default:
return;
2019-11-16 12:28:07 +00:00
case 0:
{
int nClip = PlayerList[nLocalPlayer].nPlayerClip;
2019-11-16 12:28:07 +00:00
if (nClip <= 0)
return;
2019-11-16 12:28:07 +00:00
int nSeqOffset;
2019-11-16 12:28:07 +00:00
if (nClip <= 3)
{
nSeqOffset = var_30 + 1;
}
else if (nClip <= 6)
{
nSeqOffset = var_30 + 2;
}
else if (nClip <= 25)
{
nSeqOffset = var_30 + 3;
}
else //if (nClip > 25)
2019-11-16 12:28:07 +00:00
{
nSeqOffset = var_30 + 4;
}
seq_DrawGunSequence(nSeqOffset, PlayerList[nLocalPlayer].nSeqSize2, xOffset, yOffset, nShade, nPal);
2019-11-16 12:28:07 +00:00
return;
}
case 1:
{
int nClip = PlayerList[nLocalPlayer].nPlayerClip;
2019-11-16 12:28:07 +00:00
int edx = (nClip % 3) * 4;
2019-11-16 12:28:07 +00:00
if (nClip <= 0) {
return;
}
seq_DrawGunSequence(var_30 + 8, edx, xOffset, yOffset, nShade, nPal);
if (nClip <= 3) {
return;
}
seq_DrawGunSequence(var_30 + 9, edx, xOffset, yOffset, nShade, nPal);
if (nClip <= 6) {
return;
}
seq_DrawGunSequence(var_30 + 10, edx, xOffset, yOffset, nShade, nPal);
if (nClip <= 25) {
return;
}
seq_DrawGunSequence(var_30 + 11, edx, xOffset, yOffset, nShade, nPal);
return;
}
case 2:
{
int nClip = PlayerList[nLocalPlayer].nPlayerClip;
2019-11-16 12:28:07 +00:00
int dx = PlayerList[nLocalPlayer].nSeqSize2;
2019-11-16 12:28:07 +00:00
if (nClip <= 0) {
return;
}
seq_DrawGunSequence(var_30 + 8, dx, xOffset, yOffset, nShade, nPal);
if (nClip <= 3) {
return;
}
seq_DrawGunSequence(var_30 + 9, dx, xOffset, yOffset, nShade, nPal);
if (nClip <= 6) {
return;
}
seq_DrawGunSequence(var_30 + 10, dx, xOffset, yOffset, nShade, nPal);
if (nClip <= 25) {
return;
}
seq_DrawGunSequence(var_30 + 11, dx, xOffset, yOffset, nShade, nPal);
return;
}
case 3:
case 4:
return;
case 5:
{
int nClip = PlayerList[nLocalPlayer].nPlayerClip;
2019-11-16 12:28:07 +00:00
int ax = PlayerList[nLocalPlayer].nSeqSize2;
2019-11-16 12:28:07 +00:00
if (nClip <= 0) {
return;
}
int nSeqOffset;
if (nClip <= 3)
{
nSeqOffset = var_30 + 20;
}
else if (nClip <= 6)
{
nSeqOffset = var_30 + 19;
}
else if (nClip <= 25)
{
nSeqOffset = var_30 + 18;
}
else
{
nSeqOffset = var_30 + 17;
}
2019-11-16 12:28:07 +00:00
seq_DrawGunSequence(nSeqOffset, ax, xOffset, yOffset, nShade, nPal);
return;
}
}
}
END_PS_NS