From b1b8b2cd0220bf5599ce1c0d57d3921696846620 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Thu, 3 Oct 2024 18:07:58 +0300 Subject: [PATCH] Fix two issues with ftl_energy and damage ftl_energy wouldn't charge Damage switch would fall-through --- engine/src/cmd/energetic.cpp | 6 +++--- engine/src/cmd/unit_generic.cpp | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/engine/src/cmd/energetic.cpp b/engine/src/cmd/energetic.cpp index a08d6b636..a57d766ad 100644 --- a/engine/src/cmd/energetic.cpp +++ b/engine/src/cmd/energetic.cpp @@ -161,6 +161,8 @@ float Energetic::totalShieldEnergyCapacitance() const { // or better yet, write plugable consumption models. //GAHHH reactor in units of 100MJ, shields in units of VSD=5.4MJ to make 1MJ of shield use 1/shieldenergycap MJ void Energetic::ExpendEnergy(const bool player_ship) { + Unit *unit = vega_dynamic_cast_ptr(this); + // TODO: if we run out of fuel or energy, we die from lack of air MaintainShields(); @@ -168,9 +170,7 @@ void Energetic::ExpendEnergy(const bool player_ship) { MaintainECM(); DecreaseWarpEnergyInWarp(); - RechargeWarpCapacitors(player_ship); - - ExpendFuel(); + unit->reactor.Generate(); } void Energetic::ExpendEnergy(float usage) { diff --git a/engine/src/cmd/unit_generic.cpp b/engine/src/cmd/unit_generic.cpp index ad6a3535c..4e08c7f95 100644 --- a/engine/src/cmd/unit_generic.cpp +++ b/engine/src/cmd/unit_generic.cpp @@ -1262,19 +1262,23 @@ void Unit::DamageRandSys(float dam, const Vector &vec, float randnum, float degr return; } if (degrees >= 35 && degrees < 60) { + // This code potentially damages a whole bunch of components. + // We generate a random int (0-19). 0-8 damages something. + // 9-19 doesn't. + // This is really a stopgap code until we refactor this better. std::random_device dev; std::mt19937 rng(dev()); std::uniform_int_distribution dist20(0,19); // distribution in range [1, 6] switch(dist20(rng)) { case 0: fuel.Damage(); break; // Fuel - case 1: energy.Damage(); // Energy - case 2: ftl_energy.Damage(); - case 3: ftl_drive.Damage(); - case 4: jump_drive.Damage(); - case 5: this->afterburnenergy += ((1 - dam) * reactor.Capacity()); - case 6: CargoVolume *= dam; - case 7: UpgradeVolume *= dam; + case 1: energy.Damage(); break; // Energy + case 2: ftl_energy.Damage(); break; + case 3: ftl_drive.Damage(); break; + case 4: jump_drive.Damage(); break; + case 5: this->afterburnenergy += ((1 - dam) * reactor.Capacity()); break; + case 6: CargoVolume *= dam; break; + case 7: UpgradeVolume *= dam; break; case 8: //Do something NASTY to the cargo if (cargo.size() > 0) {