Files
EscapistsReintroduced/docs/evidence/terrain-fuel-pumps-2026-10-30/native-fixture.c
T
2026-10-30 18:56:57 +01:00

111 lines
6.0 KiB
C

#ifdef WORKBENCH
class ERR_FuelPumpProbe
{
static ref array<SCR_BaseSupportStationComponent> Original = {};
static IEntity VehicleEntity;
static SCR_ChimeraCharacter User;
static SCR_FuelSupportStationComponent Pump;
static SCR_RefuelAtSupportStationAction Action;
static SCR_FuelManagerComponent Fuel;
static SCR_FuelManagerComponent PumpFuel;
static int Attempts;
static void Fail(string reason) { Print("ERR SMOKE FAIL: fuel-pump " + reason, LogLevel.ERROR); }
static void Poll()
{
Attempts++;
if (Attempts > 180) { Fail("player or original pump unavailable"); return; }
SCR_PlayerController controller = SCR_PlayerController.Cast(GetGame().GetPlayerController());
if (controller) User = SCR_ChimeraCharacter.Cast(controller.GetControlledEntity());
ERR_GameMode mode = ERR_GameMode.Get();
if (!User || !mode || !mode.Active()) { GetGame().GetCallqueue().CallLater(Poll, 1000, false); return; }
foreach (SCR_BaseSupportStationComponent station : Original)
{
if (!station || !station.GetOwner()) continue;
SCR_FuelSupportStationComponent fuelStation = SCR_FuelSupportStationComponent.Cast(station);
if (!fuelStation || !station.GetOwner().GetPrefabData()) continue;
string prefab = station.GetOwner().GetPrefabData().GetPrefabName();
if (prefab.IndexOf("FuelStation_E_01_tankpistol") < 0) continue;
Pump = fuelStation; break;
}
if (!Pump) { Fail("no existing Everon petrol pump captured"); return; }
PumpFuel = SCR_FuelManagerComponent.Cast(Pump.GetOwner().FindComponent(SCR_FuelManagerComponent));
SCR_SupportStationManagerComponent manager = SCR_SupportStationManagerComponent.GetInstance();
PrintFormat("ERR FUEL PUMP REGISTRY: original=%1 current=%2 pump=%3 position=%4", Original.Count(), manager.ERR_ProbeFuelCount(), Pump.GetOwner().GetPrefabData().GetPrefabName(), Pump.GetPosition());
vector position = ERR_Actors.Ground(Pump.GetPosition() + "3 0 0");
VehicleEntity = ERR_Actors.Spawn("{259EE7B78C51B624}Prefabs/Vehicles/Wheeled/UAZ469/UAZ469.et", position);
if (!VehicleEntity || !PumpFuel) { Fail("fixture UAZ or pump fuel manager unavailable"); return; }
mode.Own(VehicleEntity);
Fuel = SCR_FuelManagerComponent.Cast(VehicleEntity.FindComponent(SCR_FuelManagerComponent));
if (!Fuel) { Fail("UAZ fuel manager missing"); return; }
Fuel.SetTotalFuelPercentage(0.25);
User.SetOrigin(ERR_Actors.Ground(position + "0 0 2"));
DamageManagerComponent damage = DamageManagerComponent.Cast(User.FindComponent(DamageManagerComponent));
if (damage) damage.EnableDamageHandling(false);
GetGame().GetCallqueue().CallLater(Test, 2000, false);
}
static void Test()
{
BaseActionsManagerComponent actions = BaseActionsManagerComponent.Cast(VehicleEntity.FindComponent(BaseActionsManagerComponent));
array<UserActionContext> contexts = {}; if (actions) actions.GetContextList(contexts);
foreach (UserActionContext context : contexts)
{
array<BaseUserAction> entries = {}; context.GetActionsList(entries);
foreach (BaseUserAction entry : entries)
{
SCR_RefuelAtSupportStationAction candidate = SCR_RefuelAtSupportStationAction.Cast(entry);
if (!candidate) continue;
candidate.SetActiveContext(context); candidate.OnActionStart(User);
ESupportStationReasonInvalid reason; int supplies;
bool pumpValid = Pump.IsValid(VehicleEntity, User, candidate, candidate.GetWorldPositionAction(), reason, supplies);
PrintFormat("ERR FUEL PUMP ELIGIBILITY: valid=%1 reason=%2 position=%3", pumpValid, reason, candidate.GetWorldPositionAction());
if (pumpValid) { Action = candidate; break; }
candidate.OnActionCanceled(VehicleEntity, User);
}
if (Action) break;
}
if (!Action) { Fail("existing pump is not eligible for parked UAZ"); return; }
float before = Fuel.GetTotalFuel(); float sourceBefore = PumpFuel.GetTotalFuel();
bool shown = Action.CanBeShownScript(User); bool allowed = Action.CanBePerformedScript(User);
Action.PerformAction(VehicleEntity, User);
float after = Fuel.GetTotalFuel(); float sourceAfter = PumpFuel.GetTotalFuel();
PrintFormat("ERR FUEL PUMP TRANSFER: shown=%1 allowed=%2 targetBefore=%3 targetAfter=%4 sourceBefore=%5 sourceAfter=%6", shown, allowed, before, after, sourceBefore, sourceAfter);
if (EXPECT_MISSING)
{
if (after != before || allowed) { Fail("expected baseline missing registration was not reproduced"); return; }
GetGame().GetCallqueue().CallLater(Control, 1000, false);
return;
}
if (after <= before || Math.AbsFloat((after - before) - (sourceBefore - sourceAfter)) > 0.02) { Fail("native action did not conserve transferred fuel"); return; }
Action.OnActionCanceled(VehicleEntity, User);
Print("ERR SMOKE PASS: fuel-pump existing Everon station refuels UAZ through native action after takeover");
Print("ERR SMOKE COMPLETE: fuel-pump native transfer");
}
static void Control()
{
GetGame().GetCallqueue().Remove(Poll);
SCR_SupportStationManagerComponent.GetInstance().AddSupportStation(Pump);
float before = Fuel.GetTotalFuel(); float sourceBefore = PumpFuel.GetTotalFuel();
Action.PerformAction(VehicleEntity, User);
float after = Fuel.GetTotalFuel();
PrintFormat("ERR FUEL PUMP CONTROL: targetBefore=%1 targetAfter=%2 sourceBefore=%3 sourceAfter=%4", before, after, sourceBefore, PumpFuel.GetTotalFuel());
if (after <= before) { Fail("registering original pump did not restore transfer"); return; }
Action.OnActionCanceled(VehicleEntity, User);
Print("ERR SMOKE PASS: fuel-pump baseline loses registration; registering identical pump restores native transfer");
Print("ERR SMOKE COMPLETE: fuel-pump baseline causal reproduction");
}
}
modded class SCR_SupportStationManagerComponent
{
void ERR_ProbeFuelCapture() { GetArrayOfSupportStationType(ESupportStationType.FUEL, ERR_FuelPumpProbe.Original); }
int ERR_ProbeFuelCount() { array<SCR_BaseSupportStationComponent> stations = {}; return GetArrayOfSupportStationType(ESupportStationType.FUEL, stations); }
}
modded class ArmaReforgerScripted
{
override protected void ERR_CreateTerrainMode()
{
super.ERR_CreateTerrainMode();
GetGame().GetCallqueue().CallLater(ERR_FuelPumpProbe.Poll, 1000, false);
}
}
#endif