1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00

Удален лишний цикл в расчётах потребления электроэнергии

This commit is contained in:
kosmik641
2026-01-23 04:30:29 +03:00
parent 907ad81c81
commit bd632c18b2

View File

@@ -512,31 +512,15 @@ hook.Add("Think", "Metrostroi_ElectricConsumptionThink", function()
for train in pairs(Metrostroi.SpawnedTrains) do for train in pairs(Metrostroi.SpawnedTrains) do
if not train.Electric then continue end if not train.Electric then continue end
local fB = IsValid(train.FrontBogey) and train.FrontBogey
if fB then
if fB.Feeder then
Metrostroi.Currents[fB.Feeder] = Metrostroi.Currents[fB.Feeder] + fB.DropByPeople
else
Metrostroi.Current = Metrostroi.Current + fB.DropByPeople
end
end
local rB = IsValid(train.RearBogey) and train.RearBogey
if rB then
if rB.Feeder then
Metrostroi.Currents[rB.Feeder] = Metrostroi.Currents[rB.Feeder] + rB.DropByPeople
else
Metrostroi.Current = Metrostroi.Current + rB.DropByPeople
end
end
end
for train in pairs(Metrostroi.SpawnedTrains) do
if train.Electric then
if train.Electric.EnergyChange then Metrostroi.TotalRateWatts = Metrostroi.TotalRateWatts + math.max(0, train.Electric.EnergyChange) end if train.Electric.EnergyChange then Metrostroi.TotalRateWatts = Metrostroi.TotalRateWatts + math.max(0, train.Electric.EnergyChange) end
local current = math.max(0, train.Electric.Itotal or 0) - math.max(0, train.Electric.Iexit or 0) local current = math.max(0, train.Electric.Itotal or 0) - math.max(0, train.Electric.Iexit or 0)
local fB = IsValid(train.FrontBogey) and train.FrontBogey local fB = IsValid(train.FrontBogey) and train.FrontBogey
local rB = IsValid(train.RearBogey) and train.RearBogey local rB = IsValid(train.RearBogey) and train.RearBogey
local fBDropByPeople = fb and fB.DropByPeople or 0
local rBDropByPeople = rb and rB.DropByPeople or 0
if fB and (not fB.ContactStates or (not fB.ContactStates[1] and not fB.ContactStates[2])) then fB = nil end -- Don't have contact with TR if fB and (not fB.ContactStates or (not fB.ContactStates[1] and not fB.ContactStates[2])) then fB = nil end -- Don't have contact with TR
if rB and (not rB.ContactStates or (not rB.ContactStates[1] and not rB.ContactStates[2])) then rB = nil end -- Don't have contact with TR if rB and (not rB.ContactStates or (not rB.ContactStates[1] and not rB.ContactStates[2])) then rB = nil end -- Don't have contact with TR
@@ -544,23 +528,30 @@ hook.Add("Think", "Metrostroi_ElectricConsumptionThink", function()
local rBfeeder = rB and rB.Feeder local rBfeeder = rB and rB.Feeder
if fBfeeder then if fBfeeder then
Metrostroi.Currents[fBfeeder] = Metrostroi.Currents[fBfeeder] + fBDropByPeople
if not rBfeeder or fBfeeder == rBfeeder then if not rBfeeder or fBfeeder == rBfeeder then
consumeFromFeeder(current, fBfeeder) -- Feeders are same consumeFromFeeder(current, fBfeeder) -- Feeders are same
else else
consumeFromFeeder(current * 0.5, fBfeeder) -- Feeders are different consumeFromFeeder(current * 0.5, fBfeeder) -- Feeders are different
end end
else
Metrostroi.Current = Metrostroi.Current + fBDropByPeople
end end
if rBfeeder then if rBfeeder then
Metrostroi.Currents[rBfeeder] = Metrostroi.Currents[rBfeeder] + rBDropByPeople
if not fBfeeder then if not fBfeeder then
consumeFromFeeder(current, rBfeeder) -- Feeders are same consumeFromFeeder(current, rBfeeder) -- Feeders are same
elseif fBfeeder ~= rBfeeder then elseif fBfeeder ~= rBfeeder then
consumeFromFeeder(current * 0.5, rBfeeder) -- Feeders are different consumeFromFeeder(current * 0.5, rBfeeder) -- Feeders are different
end end
else
Metrostroi.Current = Metrostroi.Current + rBDropByPeople
end end
if not rBfeeder and not fBfeeder then consumeFromFeeder(current) end if not rBfeeder and not fBfeeder then consumeFromFeeder(current) end
end end
end
-- Ignore invalid values -- Ignore invalid values
if Metrostroi.TotalRateWatts > 1e8 then Metrostroi.TotalRateWatts = 0 end if Metrostroi.TotalRateWatts > 1e8 then Metrostroi.TotalRateWatts = 0 end
if Metrostroi.TotalRateWatts > 0 then if Metrostroi.TotalRateWatts > 0 then