Skip to content

Commit

Permalink
fix(mechanics): Set the default jump fuel of an outfit properly (endl…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGoodIdea authored Nov 6, 2024
1 parent ff23e69 commit c11fd90
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
6 changes: 6 additions & 0 deletions data/_ui/tooltips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.`

Expand Down
22 changes: 21 additions & 1 deletion source/Outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pair<Body, int>> &thisFlares, const pair<Body, int> &it, int count)
{
auto oit = find_if(thisFlares.begin(), thisFlares.end(),
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 4 additions & 10 deletions source/ShipJumpNavigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ this program. If not, see <https://www.gnu.org/licenses/>.

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.
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions source/ShipJumpNavigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c11fd90

Please sign in to comment.