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 scooping rework #5609

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/modules/FuelScoop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ local lc = Lang.GetResource("core")
-- These callbacks are triggered from C++ or Lua and are responsible for
-- providing UI feedback about the scooping process.

Event.Register("onShipScoopFuel", function(ship, body)
Event.Register("onShipScoopFuel", function(ship, body, amount)
---@type CargoManager
local cargoMgr = ship:GetComponent('CargoManager')

cargoMgr:AddCommodity(Commodities.hydrogen, 1)
cargoMgr:AddCommodity(Commodities.hydrogen, amount)

if ship == Game.player then
Game.AddCommsLogLine(lc.FUEL_SCOOP_ACTIVE_N_TONNES_H_COLLECTED:gsub('%%quantity',
Expand Down
21 changes: 17 additions & 4 deletions src/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,10 +1256,23 @@ void Ship::StaticUpdate(const float timeStep)
const vector3d vdir = GetVelocity().Normalized();
const vector3d pdir = -GetOrient().VectorZ();
const double dot = vdir.Dot(pdir);
if ((m_stats.free_capacity) && (dot > 0.90) && (speed > 100.0) && (density > 0.3)) {
const double rate = speed * density * 0.00000333 * double(m_stats.fuel_scoop_cap);
if (Pi::rng.Double() < rate) {
LuaEvent::Queue("onShipScoopFuel", this, p);
const double speed_times_density = speed * density;
/*
* speed = m/s, density = g/cm^3 -> T/m^3, pressure = Pa -> N/m^2 -> kg/(m*s^2)
* m T kg m*kg^2 kg^2
* - * --- * ----- = 1000 ------- = 1000 -------
* s m^3 m*s^2 m^4*s^3 m^3*s^3
*
* fuel_scoop_cap = area, m^2. rate = kg^2/(m*s^3) = (Pa*kg)/s^2
*/
const double hydrogen_density = 0.0002;
if ((m_stats.free_capacity) && (dot > 0.90) && speed_times_density > (100.0 * 0.3)) {
const double rate = speed_times_density * hydrogen_density * double(m_stats.fuel_scoop_cap);
m_hydrogenScoopedAccumulator += rate * timeStep;
if (m_hydrogenScoopedAccumulator > 1) {
const double scoopedTons = floor(m_hydrogenScoopedAccumulator);
LuaEvent::Queue("onShipScoopFuel", this, p, scoopedTons);
m_hydrogenScoopedAccumulator -= scoopedTons;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class Ship : public DynamicBody {

std::string m_shipName;

double m_hydrogenScoopedAccumulator = 0;

public:
// FIXME: these methods are deprecated; all calls should use the propulsion object directly.
void ClearAngThrusterState() { m_propulsion->ClearAngThrusterState(); }
Expand Down
Loading