From 02c6ea475ff8a10b666c514867d16772b48ac7d1 Mon Sep 17 00:00:00 2001 From: Moon Horse Date: Wed, 19 Jan 2022 23:07:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=B2=D0=BE=D0=BB=D1=8C=D1=82=D0=BC=D0=B5=D1=82=D1=80=D1=8B?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=BF=D1=80=D1=8F=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BD=D0=B0=2010=20=D0=BF=D1=80=D0=BE=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5.=20=D0=98=D0=BC=D0=B8=D1=82=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D0=B0=D0=B4=D0=BA=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=BF=D1=80=D1=8F=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=9F=D0=9F=20=D0=91=D0=9F=D0=A1=D0=9D=20=D0=B8=20=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=82=D0=B5=D0=BF=D0=BB=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/entities/gmod_subway_81-714_mvm/init.lua | 43 +++++++++++++++++- lua/entities/gmod_subway_81-717_mvm/init.lua | 44 ++++++++++++++++++- .../systems/sys_81_714_electric.lua | 2 +- .../systems/sys_81_717_electric.lua | 2 +- lua/metrostroi/systems/sys_bpsn.lua | 5 +-- 5 files changed, 89 insertions(+), 7 deletions(-) diff --git a/lua/entities/gmod_subway_81-714_mvm/init.lua b/lua/entities/gmod_subway_81-714_mvm/init.lua index 36e492d..db2c10b 100644 --- a/lua/entities/gmod_subway_81-714_mvm/init.lua +++ b/lua/entities/gmod_subway_81-714_mvm/init.lua @@ -355,7 +355,48 @@ function ENT:Think() end self:SetPackedRatio("TLPressure", Pneumatic.TrainLinePressure/16.0) self:SetPackedRatio("BCPressure", Pneumatic.BrakeCylinderPressure/6.0) - self:SetPackedRatio("BatteryVoltage",Panel["V1"]*self.Battery.Voltage/150.0) + +----------------------------------*****************************-------------------------------- + --10th wire voltage readout imitation depending on the BPSNs and EKK state, not on the wagon battery switch state + local hvcounter = 0 + local hvcar = nil + local vdrop = 1.125*(#self.WagonList) + for k,v in ipairs(self.WagonList) do + if v.PowerSupply.X2_2 > 0 and v.A24.Value > 0 then + hvcounter = hvcounter + 1 + hvcar = hvcar or v + vdrop = vdrop - 1.125 + else + vdrop = vdrop - ((v.A56.Value == 0 and 0.4 or (v.VB.Value == 0 and 0.4 or 0)) + (v.LK4.Value == 0 and 0.725 or 0)) + end + end + local PCV_o = hvcounter > 0 and math.Clamp(76+(hvcar.Electric.Aux750V - 600)*8/375, 76, 84) - vdrop or self.WagonList[1].Battery.Voltage + --imitating converter overload protection only when control circuits are energized and at least one PC on the train is off; pretty useless btw (but fun) + local pcloadratio = #self.WagonList/(hvcounter > 0 and hvcounter or 0.5) + --local _a = 25*(#self.WagonList - #self.WagonList/(#self.WagonList-1)) + local _A = 25*(6 - 6/(5.01)) --assuming one PC on 6 cars can work for 25 secs while the cars' CCs are energized + if pcloadratio > 1 and pcloadratio <= #self.WagonList and self.LK4.Value > 0 and self.PowerSupply.X2_2 > 0 and not self.pcrlxtimer then + self.pcprotimer = self.pcprotimer or CurTime() + --if CurTime() - self.pcprotimer > _a/(pcloadratio + _a/25 - #self.WagonList) + self._pcdiff then --hyperbolic function of PC operating time depending on load coeff + if CurTime() - self.pcprotimer > _A/(pcloadratio - 6/5.01) then + --self.RZP:TriggerInput("Close",1) + self.pcrlxtimer = CurTime() + end + else + if self.pcrlxtimer then + if CurTime() - self.pcrlxtimer < 30 then --30 seconds relaxation time before PC overload protecion can be reset + self.RZP:TriggerInput("Close",1) + else + self.pcrlxtimer = nil + end + else + self.pcprotimer = nil + end + end + self.PowerSupply:TriggerInput("3x2",self.pcrlxtimer and 1 or 0) --BPSN overheat protection in case of RZP button is being pressed constantly +----------------------------------*****************************-------------------------------- + + self:SetPackedRatio("BatteryVoltage",Panel["V1"]*PCV_o/150.0) self:SetPackedRatio("BatteryCurrent",Panel["V1"]*math.Clamp((self.Battery.Voltage-75)*0.01,-0.01,1)) self:SetPackedRatio("EnginesCurrent", 0.5 + 0.5*(self.Electric.I24/500.0)) diff --git a/lua/entities/gmod_subway_81-717_mvm/init.lua b/lua/entities/gmod_subway_81-717_mvm/init.lua index 879c474..6943ca8 100644 --- a/lua/entities/gmod_subway_81-717_mvm/init.lua +++ b/lua/entities/gmod_subway_81-717_mvm/init.lua @@ -668,8 +668,50 @@ function ENT:Think() self:SetPackedRatio("EnginesVoltage", self.Electric.Aux750V/1000.0) self:SetPackedRatio("EnginesCurrent2", 0.5 + 0.5*(self.Electric.I13/500.0)) self:SetPackedRatio("EnginesCurrent", 0.5 + 0.5*(self.Electric.I24/500.0)) - self:SetPackedRatio("BatteryVoltage",Panel["V1"]*self.Battery.Voltage/150.0) +----------------------------------*****************************-------------------------------- + --10th wire voltage readout imitation depending on the BPSNs and EKK state, not on the wagon battery switch state + -- PC — power converter; CC — control circuits + local hvcounter = 0 + local hvcar = nil + local vdrop = 1.125*(#self.WagonList) + for k,v in ipairs(self.WagonList) do + if v.PowerSupply.X2_2 > 0 and v.A24.Value > 0 then + hvcounter = hvcounter + 1 + hvcar = hvcar or v + vdrop = vdrop - 1.125 + else + vdrop = vdrop - ((v.A56.Value == 0 and 0.4 or (v.VB.Value == 0 and 0.4 or 0)) + (v.LK4.Value == 0 and 0.725 or 0)) + end + end + local PCV_o = hvcounter > 0 and math.Clamp(76+(hvcar.Electric.Aux750V - 600)*8/375, 76, 84) - vdrop or self.WagonList[1].Battery.Voltage + --imitating converter overload protection only when control circuits are energized and at least one PC on the train is off; pretty useless btw (but fun) + local pcloadratio = #self.WagonList/(hvcounter > 0 and hvcounter or 0.5) + --local _a = 25*(#self.WagonList - #self.WagonList/(#self.WagonList-0.99)) --0.99 instead of 1 is for zero division protection + local _A = 25*(6 - 6/(5.01)) --assuming one PC on 6 cars can work for 25 secs while the cars' CCs are energized + if pcloadratio > 1 and pcloadratio <= #self.WagonList and self.LK4.Value > 0 and self.PowerSupply.X2_2 > 0 and not self.pcrlxtimer then + self.pcprotimer = self.pcprotimer or CurTime() + --if CurTime() - self.pcprotimer > _a/(pcloadratio + _a/25 - #self.WagonList) + self._pcdiff then --hyperbolic function of PC operating time depending on load coeff + if CurTime() - self.pcprotimer > _A/(pcloadratio - 6/5.01) then + self.pcrlxtimer = CurTime() + end + else + if self.pcrlxtimer then + if CurTime() - self.pcrlxtimer < 30 then --30 seconds relaxation time before PC overload protecion can be reset + self.RZP:TriggerInput("Close",1) + else + self.pcrlxtimer = nil + end + else + self.pcprotimer = nil + end + end + self.PowerSupply:TriggerInput("3x2",self.pcrlxtimer and 1 or 0) --BPSN overheat protection in case of RZP button is being pressed constantly + --print("self.WagonNumber = "..self.WagonNumber) +----------------------------------*****************************-------------------------------- + + self:SetPackedRatio("BatteryVoltage",Panel["V1"]*PCV_o/150.0) + self:SetPackedBool("Compressor",Pneumatic.Compressor > 0) self:SetPackedBool("Buzzer",Panel.Ring >= 1) self:SetPackedBool("BuzzerBZOS",Panel.Ring>0 and Panel.Ring<1) diff --git a/lua/metrostroi/systems/sys_81_714_electric.lua b/lua/metrostroi/systems/sys_81_714_electric.lua index 6723fc7..841c4b9 100644 --- a/lua/metrostroi/systems/sys_81_714_electric.lua +++ b/lua/metrostroi/systems/sys_81_714_electric.lua @@ -66,7 +66,7 @@ function TRAIN_SYSTEM:SolveAllInternalCircuits(Train,dT,firstIter) local isDot2 = self.Type == 5 local Panel = Train.Panel - Panel.V1 = BO + Panel.V1 = T[10] --ÐŸÐ¾ÐµÐ·Ð´Ð½Ð°Ñ Ñ‡Ð°Ñть S["33D"] = T[10]*Train.A54.Value*Train.A84.Value diff --git a/lua/metrostroi/systems/sys_81_717_electric.lua b/lua/metrostroi/systems/sys_81_717_electric.lua index a73d956..4e02f99 100644 --- a/lua/metrostroi/systems/sys_81_717_electric.lua +++ b/lua/metrostroi/systems/sys_81_717_electric.lua @@ -70,7 +70,7 @@ function TRAIN_SYSTEM:SolveAllInternalCircuits(Train,dT,firstIter) local KV = Train.KV local KRU = Train.KRU local Panel = Train.Panel - Panel.V1 = BO + Panel.V1 = T[10] local RC1 = Train.RC1.Value local ARS = Train.ALS_ARS local RC2,AVI,AVO diff --git a/lua/metrostroi/systems/sys_bpsn.lua b/lua/metrostroi/systems/sys_bpsn.lua index a3227be..4e1ec41 100644 --- a/lua/metrostroi/systems/sys_bpsn.lua +++ b/lua/metrostroi/systems/sys_bpsn.lua @@ -9,7 +9,7 @@ Metrostroi.DefineSystem("BPSN") function TRAIN_SYSTEM:Initialize() self.X2 = { [2] = 0, - [3] = 0, + [3] = 0, --overheat protection simulation [4] = 0, [5] = 0, -- Out only [6] = 0, @@ -42,7 +42,7 @@ end function TRAIN_SYSTEM:Think() local Train = self.Train -- Get high-voltage input - self.X2_1 = Train.KPP.Value * (1-Train.RZP.Value) -- P4 + self.X2_1 = Train.KPP.Value * (1-Train.RZP.Value) * (1-self.X2[3]) -- P4 -- Get battery input local XT3_1 = self.X2[5]*self.X2_1 if Train.Electric.Aux750V*self.X2_1 > 975 then @@ -50,7 +50,6 @@ function TRAIN_SYSTEM:Think() self.X2_1 = 0 XT3_1 = 0 end - -- Check if enable signal is present self.Active = XT3_1>0 and 1 or 0 self.X2_2 = Train.Electric.Aux750V*self.Active