Skip to content

Commit

Permalink
ais battery recharges
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-Cpu committed Jan 7, 2025
1 parent 07d6c7f commit f3441f9
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Content.Server/Silicons/StationAi/StationAiSystem.Power.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@ private void UpdatePower(float frameTime)
while (query.MoveNext(out var uid, out var aiPower, out var core, out var battery))
{
if (aiPower.IsPowered)
{
if (!TryComp<ApcPowerReceiverComponent>(uid, out var power))
continue;

if (_battery.IsFull(uid, battery))
continue;

var inputCharge = power.Load > power.PowerReceived ? power.PowerReceived : power.Load;
var newCharge = battery.CurrentCharge + inputCharge * frameTime;
_battery.SetCharge(uid, newCharge, battery);
}
else
{
if (!_battery.TryUseCharge(uid, aiPower.Wattage * frameTime, battery))
{
aiPower.IsPowered = false;
TurnOff(uid, core);
_battery.SetCharge(uid, 0f, battery);
}
}
}
Expand Down Expand Up @@ -69,10 +82,8 @@ private void UpdateState(EntityUid uid, StationAiRequirePowerComponent component
{
TurnOn(uid, core);
}
else
{
TurnOff(uid, core);
}

// dont run turn off now as it will instantly kill the ai
}

private void TurnOff(EntityUid uid, StationAiCoreComponent core)
Expand Down

0 comments on commit f3441f9

Please sign in to comment.