Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuel Computer + Some Reusable Fuel Code #6031

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions data/lang/equipment-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,15 @@
"description": "",
"message": "Shows profitable commodities to trade between selected and current system"
},

"FUEL_COMPUTER": {
"description": "Ship equipment computing fuel transfer to hyperdrive if available.",
"message": "Fuel Computer"
},
"FUEL_COMPUTER_DESCRIPTION": {
"description": "",
"message": "Tired of transferring fuel from cargo to your drive? Now have it automatically balanced on arrival to a system."
},
"UNOCCUPIED_CABIN": {
"description": "",
"message": "Extra Passenger Cabin"
Expand Down
59 changes: 59 additions & 0 deletions data/lang/module-fuel/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"FUEL": {
"description": "",
"message": "FUEL"
},
"EMERGENCY_RESERVE": {
"description": "",
"message": "Emergency Reserve"
},
"MAIN_TANK": {
"description": "",
"message": "Main Tank"
},
"CARGO_BAY": {
"description": "",
"message": "Cargo Bay"
},
"DRIVE_TANK": {
"description": "",
"message": "Drive Tank"
},
"OPERATIONAL_SETTINGS": {
"description": "",
"message": "Operational Settings"
},
"FUEL_COMPUTER": {
"description": "",
"message": "Fuel Computer"
},
"INITIATING_TRANSFER": {
"description": "",
"message": "Initiating Automated Fuel Transfer"
},
"JUMP_RANGE": {
"description": "",
"message": "Jump Range"
},
"MAX_RANGE": {
"description": "",
"message": "Max Range"
},
"UNRESERVED_RANGE": {
"description": "",
"message": "Unreserved Range"
},
"TOPPING_UP": {
"description": "",
"message": "Topping up your tank with %dT of H"
},
"NO_DRIVE_FUEL": {
"description": "",
"message": "No Fuel Available To Refuel Hyperdrive. Check Your Reserves!"
},
"NO_DRIVE_MIL_FUEL": {
"description": "",
"message": "No Military Fuel Available To Refuel Hyperdrive. Check Your Reserves!"
}

}
13 changes: 12 additions & 1 deletion data/libs/EquipType.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ function HyperdriveType:GetMaximumRange(ship)
return (self.fuel_resv_size * E)^fuel_use_exp_inv
end

-- Function: GetCustomRange
--
-- Returns the range of the hyperdrive under their current lading state of the ship. acounting for a custom extra fuel usage
---@param ship Ship
---@param extraMass number - of tons of fuel in cargo for alocation for calculation
function HyperdriveType:GetCustomRange(ship, extraMass)
-- Account for the extra mass needed to reach full fuel state
local E = self:GetEfficiencyTerm(ship, extraMass)
return ((self.fuel_resv_size+extraMass) * E)^fuel_use_exp_inv
end

-- Function: GetFuelUse
--
-- Returns the fuel consumed by the drive in attempting a jump of the specified distance.
Expand Down Expand Up @@ -447,7 +458,7 @@ end
--
-- Return the maximum fuel capacity of the drive, in tons.
function HyperdriveType:GetMaxFuel()
return self.fuel_resv_size
return self.fuel_resv_size -- is this a cpp value???
end

-- Function: CheckJump
Expand Down
8 changes: 8 additions & 0 deletions data/modules/Equipment/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Equipment.Register("misc.trade_computer", EquipType.New {
icon_name="equip_trade_computer"
})

Equipment.Register("misc.fuel_computer", EquipType.New {
l10n_key="FUEL_COMPUTER",
price=450, purchasable=true, tech_level=6,
slot={ type="computer", size=1 },
mass=0.3, volume=0.5, capabilities={ fuel_computer=1 },
icon_name="equip_fuel_computer"
})

--===============================================
-- Sensors
--===============================================
Expand Down
64 changes: 64 additions & 0 deletions data/modules/FuelComputer/FuelComputer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@



-- Copyright © 2008-2025 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local Event = require 'Event'
local Game = require 'Game'
local Engine = require 'Engine'
local Timer = require 'Timer'
local Serializer = require 'Serializer'
local Comms = require 'Comms'

local fuel = require 'pigui.libs.fuel-transfer'

-- store which station sent them out
local policeDispatched = false

local loaded_data


local onGameStart = function ()
if (loaded_data) then
fuel.setComputerReserve(loaded_data.mainReserve, loaded_data.cargoReserve)
end
loaded_data = nil
end


local serialize = function ()
local data = fuel.getComputerReserve()
return data
end


local unserialize = function (data)
loaded_data = data
end



local onEnterSystem = function (player)
if not player:IsPlayer() then return end -- only works for player

if (loaded_data) then
fuel.setComputerReserve(loaded_data.mainReserve, loaded_data.cargoReserve)
end

loaded_data = nil

if(fuel.hasFuelComputerCapability()) then
fuel.computerTransfer()
end
end




Event.Register("onGameStart", onGameStart)
Event.Register("onEnterSystem", onEnterSystem)
Event.Register("", onEnterSystem)


Serializer:Register("FuelComputer", serialize, unserialize)
Loading