Skip to content

Commit

Permalink
Fix laser bounce tick
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrc6 committed Jun 3, 2024
1 parent 3eefa68 commit ec4f377
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void CCharacter::FireWeapon(bool EarlyFire)
else
LaserReach = TuningList()[m_TuneZone].m_LaserReach;

new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_SHOTGUN);
new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_SHOTGUN, EarlyFire);
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE, TeamMask()); // NOLINT(clang-analyzer-unix.Malloc)
}
break;
Expand Down Expand Up @@ -592,7 +592,7 @@ void CCharacter::FireWeapon(bool EarlyFire)
else
LaserReach = TuningList()[m_TuneZone].m_LaserReach;

new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_LASER);
new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_LASER, EarlyFire);
GameServer()->CreateSound(m_Pos, SOUND_LASER_FIRE, TeamMask()); // NOLINT(clang-analyzer-unix.Malloc)
}
break;
Expand Down Expand Up @@ -686,6 +686,7 @@ void CCharacter::OnPredictedInput(CNetObj_PlayerInput *pNewInput)

// copy new input
mem_copy(&m_Input, pNewInput, sizeof(m_Input));
m_NumInputs++;

// it is not allowed to aim in the center
if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0)
Expand Down Expand Up @@ -722,7 +723,6 @@ void CCharacter::WeaponTick()
{
mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput));
mem_copy(&m_LatestInput, &m_Input, sizeof(m_LatestInput));
m_NumInputs++;

// it is not allowed to aim in the center
if(m_LatestInput.m_TargetX == 0 && m_LatestInput.m_TargetY == 0)
Expand Down
8 changes: 5 additions & 3 deletions src/game/server/entities/laser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <game/server/gamecontext.h>
#include <game/server/gamemodes/DDRace.h>

CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type) :
CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type, bool EarlyTick) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
{
m_Pos = Pos;
Expand All @@ -32,7 +32,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
m_BelongsToPracticeTeam = pOwnerChar && pOwnerChar->Teams()->IsPractice(pOwnerChar->Team());

GameWorld()->InsertEntity(this);
DoBounce();
DoBounce(EarlyTick);
}

bool CLaser::HitCharacter(vec2 From, vec2 To)
Expand Down Expand Up @@ -97,9 +97,11 @@ bool CLaser::HitCharacter(vec2 From, vec2 To)
return true;
}

void CLaser::DoBounce()
void CLaser::DoBounce(bool EarlyTick)
{
m_EvalTick = Server()->Tick();
if(EarlyTick)
m_EvalTick--;

if(m_Energy < 0)
{
Expand Down
11 changes: 9 additions & 2 deletions src/game/server/entities/laser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
class CLaser : public CEntity
{
public:
CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type);
CLaser(
CGameWorld *pGameWorld,
vec2 Pos,
vec2 Direction,
float StartEnergy,
int Owner,
int Type,
bool EarlyTick = false);

virtual void Reset() override;
virtual void Tick() override;
Expand All @@ -20,7 +27,7 @@ class CLaser : public CEntity

protected:
bool HitCharacter(vec2 From, vec2 To);
void DoBounce();
void DoBounce(bool EarlyTick = false);

private:
vec2 m_From;
Expand Down

0 comments on commit ec4f377

Please sign in to comment.