Skip to content

Commit

Permalink
sim: remove redundant KillUnit() parameter
Browse files Browse the repository at this point in the history
Previously, `KillUnit()` (and its variants) exposed an optional
`showDeathSequence` parameters that defaulted to `true`, and if set to
`false` then no death script was run.

In this commit, we remove the parameter as it is entirely redundant:

- The 3rd mandatory parameter `reclaimed` is used for exactly the same
  purpose: if `reclaimed` is `true`, then no death script is run.
- The default value of `showDeathSequence` is `true` and none of the
  callers actually set it to `false`, except 1, but this one also sets
  `reclaimed` to `true`... thereby overriding `showDeathSequence`.
  • Loading branch information
nbusseneau committed Aug 21, 2023
1 parent ccc1fe7 commit ee146a7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ void CUnit::FinishedBuilding(bool postInit)
}


void CUnit::KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence)
void CUnit::KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed)
{
if (IsCrashing() && !beingBuilt)
return;

ForcedKillUnit(attacker, selfDestruct, reclaimed, showDeathSequence);
ForcedKillUnit(attacker, selfDestruct, reclaimed);
}

void CUnit::ForcedKillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence)
void CUnit::ForcedKillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed)
{
if (isDead)
return;
Expand All @@ -477,7 +477,7 @@ void CUnit::ForcedKillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, b
envResHandler.DelGenerator(this);

blockHeightChanges = false;
deathScriptFinished = (!showDeathSequence || reclaimed || beingBuilt);
deathScriptFinished = (reclaimed || beingBuilt);

if (deathScriptFinished)
return;
Expand Down
4 changes: 2 additions & 2 deletions rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class CUnit : public CSolidObject

public:
void KilledScriptFinished(int wreckLevel) { deathScriptFinished = true; delayedWreckLevel = wreckLevel; }
void ForcedKillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence = true);
virtual void KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence = true);
void ForcedKillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed);
virtual void KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed);
virtual void IncomingMissile(CMissileProjectile* missile);

void TempHoldFire(int cmdID);
Expand Down
4 changes: 2 additions & 2 deletions rts/Sim/Units/UnitHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ bool CUnitHandler::QueueDeleteUnit(CUnit* unit)
// there are many ways to fiddle with "deathScriptFinished", so a unit may
// arrive here not having been properly killed while isDead is still false
// make sure we always call Killed; no-op if isDead was already set to true
unit->ForcedKillUnit(nullptr, false, true, true);
unit->ForcedKillUnit(nullptr, false, true);
unitsToBeRemoved.push_back(unit);
return true;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ void CUnitHandler::UpdateUnitMoveTypes()
// this unit is not coming back, kill it now without any death
// sequence (s.t. deathScriptFinished becomes true immediately)
if (!unit->pos.IsInBounds() && (unit->speed.w > MAX_UNIT_SPEED))
unit->ForcedKillUnit(nullptr, false, true, false);
unit->ForcedKillUnit(nullptr, false, true);

unit->SanityCheck();
assert(activeUnits[activeUpdateUnit] == unit);
Expand Down
4 changes: 2 additions & 2 deletions rts/Sim/Units/UnitTypes/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ CFactory::CFactory()
, lastBuildUpdateFrame(-1)
{ }

void CFactory::KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence)
void CFactory::KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed)
{
if (curBuild != nullptr) {
curBuild->KillUnit(nullptr, false, true);
curBuild = nullptr;
}

CUnit::KillUnit(attacker, selfDestruct, reclaimed, showDeathSequence);
CUnit::KillUnit(attacker, selfDestruct, reclaimed);
}

void CFactory::PreInit(const UnitLoadParams& params)
Expand Down
2 changes: 1 addition & 1 deletion rts/Sim/Units/UnitTypes/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CFactory : public CBuilding
/// supply the build piece to speed up
float3 CalcBuildPos(int buildPiece = -1);

void KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence = true);
void KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed);
void PreInit(const UnitLoadParams& params);
bool ChangeTeam(int newTeam, ChangeType type);

Expand Down

0 comments on commit ee146a7

Please sign in to comment.