From c11fd9029e2a59edad169fb7925aaf5e033ee122 Mon Sep 17 00:00:00 2001 From: TomGoodIdea <108272452+TomGoodIdea@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:09:00 +0100 Subject: [PATCH] fix(mechanics): Set the default jump fuel of an outfit properly (#10732) --- data/_ui/tooltips.txt | 6 ++++++ source/Outfit.cpp | 22 +++++++++++++++++++++- source/ShipJumpNavigation.cpp | 14 ++++---------- source/ShipJumpNavigation.h | 6 ------ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/data/_ui/tooltips.txt b/data/_ui/tooltips.txt index 9822d49634ab..1852068953b6 100644 --- a/data/_ui/tooltips.txt +++ b/data/_ui/tooltips.txt @@ -441,6 +441,12 @@ tip "jump speed:" tip "jump fuel:" `Fuel consumed when jumping between systems using this drive.` +tip "hyperdrive fuel" + `Fuel consumed when jumping between systems using this hyperdrive.` + +tip "jump drive fuel" + `Fuel consumed when jumping between systems using this jump drive.` + tip "jump range:" `The maximum distance this drive can jump.` diff --git a/source/Outfit.cpp b/source/Outfit.cpp index 5602c5d1ae9b..6fe5b3025b1e 100644 --- a/source/Outfit.cpp +++ b/source/Outfit.cpp @@ -174,6 +174,10 @@ namespace { {"turn multiplier", -1.} }; + constexpr double DEFAULT_HYPERDRIVE_COST = 100.; + constexpr double DEFAULT_SCRAM_DRIVE_COST = 150.; + constexpr double DEFAULT_JUMP_DRIVE_COST = 200.; + void AddFlareSprites(vector> &thisFlares, const pair &it, int count) { auto oit = find_if(thisFlares.begin(), thisFlares.end(), @@ -328,10 +332,26 @@ void Outfit::Load(const DataNode &node) + pluralName + "\"."); } + // Set the default jump fuel if not defined. + bool isHyperdrive = attributes.Get("hyperdrive"); + bool isScramDrive = attributes.Get("scram drive"); + bool isJumpDrive = attributes.Get("jump drive"); + if((isHyperdrive || isScramDrive) && attributes.Get("hyperdrive fuel") <= 0.) + { + double jumpFuel = attributes.Get("jump fuel"); + attributes["hyperdrive fuel"] = (jumpFuel > 0. ? jumpFuel + : isScramDrive ? DEFAULT_SCRAM_DRIVE_COST : DEFAULT_HYPERDRIVE_COST); + } + if(isJumpDrive && attributes.Get("jump drive fuel") <= 0.) + { + double jumpFuel = attributes.Get("jump fuel"); + attributes["jump drive fuel"] = (jumpFuel > 0. ? jumpFuel : DEFAULT_JUMP_DRIVE_COST); + } + // Only outfits with the jump drive and jump range attributes can // use the jump range, so only keep track of the jump range on // viable outfits. - if(attributes.Get("jump drive") && attributes.Get("jump range")) + if(isJumpDrive && attributes.Get("jump range")) GameData::AddJumpRange(attributes.Get("jump range")); // Legacy support for turrets that don't specify a turn rate: diff --git a/source/ShipJumpNavigation.cpp b/source/ShipJumpNavigation.cpp index 16083fa92526..575dfe10380c 100644 --- a/source/ShipJumpNavigation.cpp +++ b/source/ShipJumpNavigation.cpp @@ -24,10 +24,6 @@ this program. If not, see . using namespace std; -const double ShipJumpNavigation::DEFAULT_HYPERDRIVE_COST = 100.; -const double ShipJumpNavigation::DEFAULT_SCRAM_DRIVE_COST = 150.; -const double ShipJumpNavigation::DEFAULT_JUMP_DRIVE_COST = 200.; - // Calibrate this ship's jump navigation information, caching its jump costs, range, and capabilities. @@ -199,11 +195,9 @@ bool ShipJumpNavigation::HasJumpDrive() const // jump information accordingly. void ShipJumpNavigation::ParseOutfit(const Outfit &outfit) { - auto CalculateFuelCost = [this, &outfit](double defaultFuel) -> double + auto CalculateFuelCost = [this, &outfit](bool isJumpDrive) -> double { - double baseCost = outfit.Get("jump fuel"); - if(baseCost <= 0.) - baseCost = defaultFuel; + double baseCost = outfit.Get(isJumpDrive ? "jump drive fuel" : "hyperdrive fuel"); // Mass cost is the fuel cost per 100 tons of ship mass. The jump base mass of a drive reduces the // ship's effective mass for the jump mass cost calculation. A ship with a mass below the drive's // jump base mass is allowed to have a negative mass cost. @@ -216,7 +210,7 @@ void ShipJumpNavigation::ParseOutfit(const Outfit &outfit) if(outfit.Get("hyperdrive") && (!hasScramDrive || outfit.Get("scram drive"))) { - double cost = CalculateFuelCost(hasScramDrive ? DEFAULT_SCRAM_DRIVE_COST : DEFAULT_HYPERDRIVE_COST); + double cost = CalculateFuelCost(false); if(!hyperdriveCost || cost < hyperdriveCost) hyperdriveCost = cost; } @@ -225,7 +219,7 @@ void ShipJumpNavigation::ParseOutfit(const Outfit &outfit) double distance = outfit.Get("jump range"); if(distance <= 0.) distance = System::DEFAULT_NEIGHBOR_DISTANCE; - double cost = CalculateFuelCost(DEFAULT_JUMP_DRIVE_COST); + double cost = CalculateFuelCost(true); UpdateJumpDriveCosts(distance, cost); } diff --git a/source/ShipJumpNavigation.h b/source/ShipJumpNavigation.h index 38ce87a03d24..c5542dc2546e 100644 --- a/source/ShipJumpNavigation.h +++ b/source/ShipJumpNavigation.h @@ -28,12 +28,6 @@ class System; // A class representing the jump capabilities of a ship. Calculates and caches a ship's // jump methods, costs, and distances. class ShipJumpNavigation { -public: - static const double DEFAULT_HYPERDRIVE_COST; - static const double DEFAULT_SCRAM_DRIVE_COST; - static const double DEFAULT_JUMP_DRIVE_COST; - - public: ShipJumpNavigation() = default;