Skip to content

Commit

Permalink
fix(mechanics): Check if a weapon consumes a resource before requirin…
Browse files Browse the repository at this point in the history
  • Loading branch information
warp-core authored Feb 8, 2025
1 parent fe55109 commit 90e538d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 9 additions & 7 deletions source/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3565,26 +3565,28 @@ bool Ship::CanFire(const Weapon *weapon) const
return false;
}

if(energy < weapon->FiringEnergy() + weapon->RelativeFiringEnergy() * attributes.Get("energy capacity"))
if(weapon->ConsumesEnergy()
&& energy < weapon->FiringEnergy() + weapon->RelativeFiringEnergy() * attributes.Get("energy capacity"))
return false;
if(fuel < weapon->FiringFuel() + weapon->RelativeFiringFuel() * attributes.Get("fuel capacity"))
if(weapon->ConsumesFuel()
&& fuel < weapon->FiringFuel() + weapon->RelativeFiringFuel() * attributes.Get("fuel capacity"))
return false;
// We do check hull, but we don't check shields. Ships can survive with all shields depleted.
// Ships should not disable themselves, so we check if we stay above minimumHull.
if(hull - MinimumHull() < weapon->FiringHull() + weapon->RelativeFiringHull() * MaxHull())
if(weapon->ConsumesHull() && hull - MinimumHull() < weapon->FiringHull() + weapon->RelativeFiringHull() * MaxHull())
return false;

// If a weapon requires heat to fire, (rather than generating heat), we must
// have enough heat to spare.
if(heat < -(weapon->FiringHeat() + (!weapon->RelativeFiringHeat()
if(weapon->ConsumesHeat() && heat < -(weapon->FiringHeat() + (!weapon->RelativeFiringHeat()
? 0. : weapon->RelativeFiringHeat() * MaximumHeat())))
return false;
// Repeat this for various effects which shouldn't drop below 0.
if(ionization < -weapon->FiringIon())
if(weapon->ConsumesIonization() && ionization < -weapon->FiringIon())
return false;
if(disruption < -weapon->FiringDisruption())
if(weapon->ConsumesDisruption() && disruption < -weapon->FiringDisruption())
return false;
if(slowness < -weapon->FiringSlowing())
if(weapon->ConsumesSlowing() && slowness < -weapon->FiringSlowing())
return false;

return true;
Expand Down
16 changes: 16 additions & 0 deletions source/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class Weapon {
// weapon is not a provocation (even if you push or pull it).
bool DoesDamage() const;

bool ConsumesHull() const;
bool ConsumesFuel() const;
bool ConsumesHeat() const;
bool ConsumesEnergy() const;
bool ConsumesIonization() const;
bool ConsumesDisruption() const;
bool ConsumesSlowing() const;

double Piercing() const;

double Prospecting() const;
Expand Down Expand Up @@ -469,4 +477,12 @@ inline double Weapon::RelativeEnergyDamage() const { return TotalDamage(RELATIVE

inline bool Weapon::DoesDamage() const { if(!calculatedDamage) TotalDamage(0); return doesDamage; }

inline bool Weapon::ConsumesHull() const { return FiringHull() > 0. || RelativeFiringHull() > 0.; }
inline bool Weapon::ConsumesFuel() const { return FiringFuel() > 0. || RelativeFiringFuel() > 0.; }
inline bool Weapon::ConsumesHeat() const { return FiringHeat() < 0. || RelativeFiringHeat() > 0.; }
inline bool Weapon::ConsumesEnergy() const { return FiringEnergy() > 0. || RelativeFiringEnergy() > 0.; }
inline bool Weapon::ConsumesIonization() const { return FiringIon() < 0.; }
inline bool Weapon::ConsumesDisruption() const { return FiringDisruption() < 0.; }
inline bool Weapon::ConsumesSlowing() const { return FiringSlowing() < 0.; }

inline bool Weapon::HasDamageDropoff() const { return hasDamageDropoff; }

0 comments on commit 90e538d

Please sign in to comment.