Skip to content

Commit

Permalink
Clean up EarlyFire entity gametick logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrc6 committed Jun 3, 2024
1 parent ec4f377 commit 8296315
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
36 changes: 16 additions & 20 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,7 @@ void CCharacter::FireWeapon(bool EarlyFire)
else
Lifetime = (int)(Server()->TickSpeed() * TuningList()[m_TuneZone].m_GunLifetime);

int StartTick = Server()->Tick();
if(EarlyFire)
StartTick--;

new CProjectile(
CProjectile *Projectile = new CProjectile(
GameWorld(),
WEAPON_GUN, //Type
m_pPlayer->GetCid(), //Owner
Expand All @@ -528,11 +524,10 @@ void CCharacter::FireWeapon(bool EarlyFire)
false, //Freeze
false, //Explosive
-1, //SoundImpact
MouseTarget, //InitDir
0,
0,
StartTick // StartTick
MouseTarget //InitDir
);
if(EarlyFire)
Projectile->SetStartTick(Server()->Tick() - 1);

GameServer()->CreateSound(m_Pos, SOUND_GUN_FIRE, TeamMask()); // NOLINT(clang-analyzer-unix.Malloc)
}
Expand All @@ -547,7 +542,10 @@ 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, EarlyFire);
CLaser *Laser = new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_SHOTGUN);
if(EarlyFire)
Laser->SetEvalTick(Server()->Tick() - 1);

GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE, TeamMask()); // NOLINT(clang-analyzer-unix.Malloc)
}
break;
Expand All @@ -560,11 +558,7 @@ void CCharacter::FireWeapon(bool EarlyFire)
else
Lifetime = (int)(Server()->TickSpeed() * TuningList()[m_TuneZone].m_GrenadeLifetime);

int StartTick = Server()->Tick();
if(EarlyFire)
StartTick--;

new CProjectile(
CProjectile *Projectile = new CProjectile(
GameWorld(),
WEAPON_GRENADE, //Type
m_pPlayer->GetCid(), //Owner
Expand All @@ -574,11 +568,10 @@ void CCharacter::FireWeapon(bool EarlyFire)
false, //Freeze
true, //Explosive
SOUND_GRENADE_EXPLODE, //SoundImpact
MouseTarget, // MouseTarget
0,
0,
StartTick //StartTick
MouseTarget // MouseTarget
);
if(EarlyFire)
Projectile->SetStartTick(Server()->Tick() - 1);

GameServer()->CreateSound(m_Pos, SOUND_GRENADE_FIRE, TeamMask());
}
Expand All @@ -592,7 +585,10 @@ void CCharacter::FireWeapon(bool EarlyFire)
else
LaserReach = TuningList()[m_TuneZone].m_LaserReach;

new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_LASER, EarlyFire);
CLaser *Laser = new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCid(), WEAPON_LASER);
if(EarlyFire)
Laser->SetEvalTick(Server()->Tick() - 1);

GameServer()->CreateSound(m_Pos, SOUND_LASER_FIRE, TeamMask()); // NOLINT(clang-analyzer-unix.Malloc)
}
break;
Expand Down
9 changes: 7 additions & 2 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, bool EarlyTick) :
CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
{
m_Pos = Pos;
Expand All @@ -32,7 +32,12 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
m_BelongsToPracticeTeam = pOwnerChar && pOwnerChar->Teams()->IsPractice(pOwnerChar->Team());

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

void CLaser::SetEvalTick(int Tick)
{
m_EvalTick = Tick;
}

bool CLaser::HitCharacter(vec2 From, vec2 To)
Expand Down
6 changes: 4 additions & 2 deletions src/game/server/entities/laser.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class CLaser : public CEntity
vec2 Direction,
float StartEnergy,
int Owner,
int Type,
bool EarlyTick = false);
int Type);

virtual void Reset() override;
virtual void Tick() override;
Expand Down Expand Up @@ -49,6 +48,9 @@ class CLaser : public CEntity
bool m_TeleportCancelled;
bool m_IsBlueTeleport;
bool m_BelongsToPracticeTeam;

public:
void SetEvalTick(int Tick);
};

#endif
12 changes: 6 additions & 6 deletions src/game/server/entities/projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ CProjectile::CProjectile(
int SoundImpact,
vec2 InitDir,
int Layer,
int Number,
int StartTick) :
int Number) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_PROJECTILE)
{
m_Type = Type;
Expand All @@ -35,10 +34,6 @@ CProjectile::CProjectile(
//m_Damage = Damage;
m_SoundImpact = SoundImpact;
m_StartTick = Server()->Tick();

if(StartTick >= 0)
m_StartTick = StartTick;

m_Explosive = Explosive;

m_Layer = Layer;
Expand All @@ -54,6 +49,11 @@ CProjectile::CProjectile(
GameWorld()->InsertEntity(this);
}

void CProjectile::SetStartTick(int Tick)
{
m_StartTick = Tick;
}

void CProjectile::Reset()
{
m_MarkedForDestroy = true;
Expand Down
4 changes: 2 additions & 2 deletions src/game/server/entities/projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class CProjectile : public CEntity
int SoundImpact,
vec2 InitDir,
int Layer = 0,
int Number = 0,
int StartTick = -1);
int Number = 0);

vec2 GetPos(float Time);
void FillInfo(CNetObj_Projectile *pProj);
Expand Down Expand Up @@ -51,6 +50,7 @@ class CProjectile : public CEntity
vec2 m_InitDir;

public:
void SetStartTick(int Tick);
void SetBouncing(int Value);
bool FillExtraInfoLegacy(CNetObj_DDRaceProjectile *pProj);
void FillExtraInfo(CNetObj_DDNetProjectile *pProj);
Expand Down

0 comments on commit 8296315

Please sign in to comment.