diff --git a/changelogcustom.txt b/changelogcustom.txt index 72a2ffc..1459636 100644 --- a/changelogcustom.txt +++ b/changelogcustom.txt @@ -417,19 +417,16 @@ check the feedback of them --Fixed Tool Duping Class --Fixed Gearboxes Act Issue --Fixed DupeFixer Tool --- -##I've being really busy this time, not -everything are tested yet, but it should -be stated as working. I am still looking -for someone to become the dev of this mod.## --- -##I don't play gmod since years and I am -still updating it, I am wondering if this -is the last update I do on it.## --- -##Thank You everyone for enjoying this mod -from 2012 to now. This hard lua scriting -time allowed me to script java, c#, c++ -and almost any others script in about no time, -I am now a Game Developper, and I can say, -it's only because of this mod !## \ No newline at end of file + +*r134 +-V1.3.4 +--Added TRUE Manual Gearboxes +--Added Compatility Manual with Original +--Added Engines Running Output +--Added Display for engine maker name +--Cleaned Engines CalcRPM Function +--Cleaned Rev Limiter Function +--Cleaned Engine Maker Data Vars +--Cleaned Engine Maker Inputs +--Removed Gearbox RPM Outputs +--Faster Engine Stall \ No newline at end of file diff --git a/lua/acf/shared/customs/manual-gearbox.lua b/lua/acf/shared/customs/manual-gearbox.lua index c5e3205..98f66e5 100644 --- a/lua/acf/shared/customs/manual-gearbox.lua +++ b/lua/acf/shared/customs/manual-gearbox.lua @@ -1,4 +1,4 @@ -/* + -- Manual Gearboxes -- Weight @@ -33,9 +33,9 @@ local StWB = 0.75 --straight weight bonus mulitplier local StTB = 1.25 --straight torque bonus multiplier -- Shift Time -local ShiftS = 0.25 -local ShiftM = 0.35 -local ShiftL = 0.5 +local ShiftS = 0.15 +local ShiftM = 0.22 +local ShiftL = 0.3 -- 4 Speed -- Inline @@ -541,7 +541,7 @@ ACF_DefineGearboxManual( "6Gear-T-LM", { -- Transaxial Dual Clutch -ACF_DefineGearboxManual( "6Gear-T-SM", { +ACF_DefineGearboxManual( "6Gear-T-SMD", { name = "6-Speed Manual, Transaxial, Small, Dual Clutch", desc = "A small, and light 6 speed manual gearbox, with a somewhat limited max torque rating", model = "models/engines/transaxial_s.mdl", @@ -563,7 +563,7 @@ ACF_DefineGearboxManual( "6Gear-T-SM", { } } ) -ACF_DefineGearboxManual( "6Gear-T-MM", { +ACF_DefineGearboxManual( "6Gear-T-MMD", { name = "6-Speed Manual, Transaxial, Medium, Dual Clutch", desc = "A medium sized, 6 speed manual gearbox", model = "models/engines/transaxial_m.mdl", @@ -585,7 +585,7 @@ ACF_DefineGearboxManual( "6Gear-T-MM", { } } ) -ACF_DefineGearboxManual( "6Gear-T-LM", { +ACF_DefineGearboxManual( "6Gear-T-LMD", { name = "6-Speed Manual, Transaxial, Large, Dual Clutch", desc = "A large, heavy and sturdy 6 speed manual gearbox", model = "models/engines/transaxial_l.mdl", @@ -1034,4 +1034,3 @@ ACF_DefineGearboxManual( "8Gear-ST-LM", { [ -1 ] = 0.5 } } ) -*/ \ No newline at end of file diff --git a/lua/autorun/acf_globals_custom.lua b/lua/autorun/acf_globals_custom.lua index 211cdca..42c0a79 100644 --- a/lua/autorun/acf_globals_custom.lua +++ b/lua/autorun/acf_globals_custom.lua @@ -2,7 +2,7 @@ -- Set vars -------------------------------------- ACFCUSTOM = {} -ACFCUSTOM.Version = 133 +ACFCUSTOM.Version = 134 ACFCUSTOM.CurrentVersion = 0 ACFCUSTOM.EngineMakerVersion = 6.1 ACFC = {} diff --git a/lua/entities/acf_engine_custom.lua b/lua/entities/acf_engine_custom.lua index bd7e90e..3fbc2b5 100644 --- a/lua/entities/acf_engine_custom.lua +++ b/lua/entities/acf_engine_custom.lua @@ -101,7 +101,7 @@ function ENT:Initialize() self.Throttle = 0 self.Active = false self.IsMaster = true - self.GearLink = {} -- a "Link" has these components: Ent, Rope, RopeLen, ReqTq + self.GearLink = {} -- a "Link" has these components: Ent, Rope, RopeLen, ReqTq, ReqTq2 self.FuelLink = {} self.LastCheck = 0 @@ -112,18 +112,25 @@ function ENT:Initialize() self.CanUpdate = true self.RequiresFuel = false + self.Fuelusing = 0 + -- Rev Limiter Vars self.CutMode = 0 self.CutRpm = 0 - self.Fuelusing = 0 self.DisableCut = 0 + self.DisableCutFinal = 0 + -- Table Vars self.ExtraLink = {} self.RadiatorLink = {} + -- Extra Vars self.PeakTorqueExtra = 0 self.RPMExtra = 0 self.ExtraUsing = 0 self.PeakTorqueHealth = 0 + -- Manual Gearbox Vars + self.ManualGearbox = false + self.GearboxCurrentGear = 0 - self.Outputs = WireLib.CreateSpecialOutputs( self, { "RPM", "Torque", "Power", "Fuel Use", "Entity", "Mass", "Physical Mass" }, { "NORMAL","NORMAL","NORMAL", "NORMAL", "ENTITY", "NORMAL", "NORMAL" } ) + self.Outputs = WireLib.CreateSpecialOutputs( self, { "RPM", "Torque", "Power", "Fuel Use", "Entity", "Mass", "Physical Mass", "Running" }, { "NORMAL","NORMAL","NORMAL", "NORMAL", "ENTITY", "NORMAL", "NORMAL", "NORMAL" } ) Wire_TriggerOutput( self, "Entity", self ) self.WireDebugName = "ACF Engine" @@ -445,6 +452,7 @@ function ENT:TriggerInput( iname, value ) self.RPM[1] = self.IdleRPM self.Active = true self.Active2 = true + Wire_TriggerOutput( self, "Running", 1 ) self.Sound = CreateSound(self, self.SoundPath) self.Sound:PlayEx(0.5,100) self:ACFInit() @@ -465,6 +473,7 @@ function ENT:TriggerInput( iname, value ) Wire_TriggerOutput( self, "Torque", 0 ) Wire_TriggerOutput( self, "Power", 0 ) Wire_TriggerOutput( self, "Fuel Use", 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end elseif (value <= 0 and self.Active) then self.Active = false @@ -472,6 +481,7 @@ function ENT:TriggerInput( iname, value ) Wire_TriggerOutput( self, "Torque", 0 ) Wire_TriggerOutput( self, "Power", 0 ) Wire_TriggerOutput( self, "Fuel Use", 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end elseif (iname == "TqAdd") then @@ -612,7 +622,11 @@ function ENT:Think() end self:SetRadsInfos() - self:SetManualInfos() + + --Set Manual Gearbox Infos (Stall Engine) + if (self.ManualGearbox) then + self:SetManualInfos() + end self.LastThink = Time self:NextThink( Time ) @@ -745,94 +759,126 @@ function ENT:CalcRPM() self.TorqueMult = math.Clamp(((1 - self.TorqueScale) / (0.5)) * ((self.ACF.Health/self.ACF.MaxHealth) - 1) + 1, self.TorqueScale, 1) self.PeakTorque = (self.PeakTorqueAdd+self.PeakTorqueExtra-self.PeakTorqueHealth) * self.TorqueMult - -- Calculate the current torque from flywheel RPM - self.Torque = boost * self.Throttle * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM, (self.LimitRPM - self.FlyRPM) / (self.LimitRPM - self.PeakMaxRPM), 1 ), 0 ) - local Drag local TorqueDiff - if self.Active then - if( self.CutMode == 0 ) then - self.Torque = boost * self.Throttle * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) - if self.iselec == true then - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / self.FlywheelOverride) * (1 - self.Throttle) / self.Inertia - else - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / (self.PeakMaxRPM+self.RPMExtra)) * ( 1 - self.Throttle) / self.Inertia - end - elseif( self.CutMode == 1 ) then - self.Torque = boost * 0 * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) - if self.iselec == true then - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / self.FlywheelOverride) * (1 - 0) / self.Inertia - else - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / (self.PeakMaxRPM+self.RPMExtra)) * ( 1 - 0) / self.Inertia - end - end - -- Let's accelerate the flywheel based on that torque + + --Custom Drag Value for Engines Types + local DragType = self.PeakMaxRPM+self.RPMExtra + if self.iselec == true then + DragType = self.FlywheelOverride + end + + if (self.Active and self.CutMode == 0) then + --Set Torque & Drag + self.Torque = boost * self.Throttle * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) + Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / DragType) * (1 - self.Throttle) / self.Inertia + --Set FlyRPM & TorqueDiff self.FlyRPM = math.max( self.FlyRPM + self.Torque / self.Inertia - Drag, 1 ) - -- This is the presently avaliable torque from the engine TorqueDiff = math.max( self.FlyRPM - self.IdleRPM, 0 ) * self.Inertia - else - self.Torque = boost * 0 * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) - if self.iselec == true then - Drag = self.PeakTorque * (math.max( self.FlyRPM - 0, 0) / self.FlywheelOverride) * (1 - 0) / self.Inertia - else - Drag = self.PeakTorque * (math.max( self.FlyRPM - 0, 0) / (self.PeakMaxRPM+self.RPMExtra)) * ( 1 - 0) / self.Inertia + --Reset TorqueDiff for Manual Gearbox + if (self.ManualGearbox) then + TorqueDiff = math.max( self.FlyRPM + (self.IdleRPM/4), 0 ) * self.Inertia end - -- Let's accelerate the flywheel based on that torque + else + --Set Torque & Drag + self.Torque = 0 + Drag = 10 * (math.max( self.FlyRPM, 0) / DragType) * 1 / (0.001*(3.1416)^2) + --Set RPM & TorqueDiff self.FlyRPM = math.max( self.FlyRPM + self.Torque / self.Inertia - Drag, 1 ) - -- This is the presently avaliable torque from the engine TorqueDiff = 0 end -- The gearboxes don't think on their own, it's the engine that calls them, to ensure consistent execution order local Boxes = table.Count( self.GearLink ) local TotalReqTq = 0 + local TotalReqTq2 = 0 --Used for Manual Gearbox (Aka Engine Back-Force) + -- Get the requirements for torque for the gearboxes (Max clutch rating minus any wheels currently spinning faster than the Flywheel) for Key, Link in pairs( self.GearLink ) do if not Link.Ent.Legal then continue end - + -- Set accelerating engine gearbox Back-Force Link.ReqTq = Link.Ent:Calc( self.FlyRPM, self.Inertia ) TotalReqTq = TotalReqTq + Link.ReqTq + if self.ManualGearbox then + -- Set deccelerating engine gearbox Back-Force (Manual Gearbox) + Link.ReqTq2 = Link.Ent:Calc2( self.FlyRPM, self.Inertia ) + TotalReqTq2 = TotalReqTq2 + Link.ReqTq2 + end end -- Split the torque fairly between the gearboxes who need it for Key, Link in pairs( self.GearLink ) do if not Link.Ent.Legal then continue end - -- Set TRUE Manual Gearbox Torque - if (IsValid(Link.isManual) && Link.isManual) then - TorqueDiff = math.max( self.FlyRPM, 0 ) * self.Inertia - end -- Calculate the ratio of total requested torque versus what's avaliable local AvailRatio = math.min( TorqueDiff / TotalReqTq / Boxes, 1 ) - -- Set the Torque + self.GearboxCurrentGear = Link.Ent.Gear + -- Reset AvailRatio (Manual Gearbox) + if (self.ManualGearbox and self.Throttle == 0 and self.GearboxCurrentGear != 0 and self.FlyRPM > self.IdleRPM) then + AvailRatio = 0 + end + -- Set the Torque On Gearboxes Link.Ent:Act( Link.ReqTq * AvailRatio * self.MassRatio, DeltaTime, self.MassRatio ) end + -- Remove RPM with Gearbox Velocity (Engine Back Force) self.FlyRPM = self.FlyRPM - math.min( TorqueDiff, TotalReqTq ) / self.Inertia - if( self.DisableCut == 0 ) then + -- Add RPM (Manual Gearbox)(Engine Back Force) + if (self.ManualGearbox and self.Active) then + if self.Throttle == 0 and self.GearboxCurrentGear != 0 then + --Remove Rev Limiter while decompressing + self.DisableCutFinal = 1 + + self.FlyRPM = self.FlyRPM + (TotalReqTq2 / self.Inertia) + else + --Enable Rev Limiter + self.DisableCutFinal = self.DisableCut + end + else + --Enable Rev Limiter + self.DisableCutFinal = self.DisableCut + end + + if( self.DisableCutFinal == 0 ) then + -- Cut the Engine (Rev Limiter) if( self.FlyRPM >= self.CutRpm and self.CutMode == 0 ) then self.CutMode = 1 if self.Sound then self.Sound:Stop() end self.Sound = nil - local MakeSound = math.random(1,3) + local MakeSound = math.random(1,4) if MakeSound <= 1 and self.Sound2 and self.Sound2:IsPlaying() then self.Sound2:Stop() end if MakeSound <= 1 then self.Sound2 = CreateSound(self, "ambient/explosions/explode_4.wav") self.Sound2:PlayEx(0.7,100) end end + -- Enable back Engine (Rev Limiter) if( self.FlyRPM <= self.CutRpm - self.CutValue and self.CutMode == 1 ) then self.CutMode = 0 self.Sound = CreateSound(self, self.SoundPath) self.Sound:PlayEx(0.5,100) end - elseif( self.DisableCut == 1 ) then + elseif( self.DisableCutFinal == 1 ) then + -- Fix Sound Bug once its cutted + if( self.CutMode == 1 ) then + self.Sound = CreateSound(self, self.SoundPath) + self.Sound:PlayEx(0.5,100) + end + -- No Rev Limiting self.CutMode = 0 end - if( self.FlyRPM <= 50 and self.Active == false ) then + + --Update Gui + /*if self.FuelusingGUI != self.Fuelusing or self.FlyRPMGUI != self.FlyRPM then + self:UpdateOverlayText() + end*/ + + -- Kill the Engine Off under 100 RPM + if( self.FlyRPM <= 100 and self.Active == false ) then self.Active2 = false + Wire_TriggerOutput( self, "Running", 0 ) self.FlyRPM = 0 if self.Sound then self.Sound:Stop() @@ -853,6 +899,7 @@ function ENT:CalcRPM() end end end + --Update radiator values for Key, Radiator in pairs(self.RadiatorLink) do if IsValid( Radiator ) then @@ -971,12 +1018,18 @@ function ENT:Link( Target ) Ent = Target, Rope = Rope, RopeLen = ( OutPos - InPos ):Length(), - ReqTq = 0 + ReqTq = 0, + ReqTq2 = 0 --used for manual gearbox, engine back-force torque } table.insert( self.GearLink, Link ) table.insert( Target.Master, self ) + //Perform Manual Gearbox Checkup + if Target.isManual then + self.ManualGearbox = true + end + return true, "Link successful!" end @@ -1011,6 +1064,9 @@ function ENT:Unlink( Target ) table.remove( self.GearLink,Key ) + -- Make Sure Manual Gearbox are disabled + self.ManualGearbox = false + return true, "Unlink successful!" end @@ -1184,24 +1240,21 @@ function ENT:SetRadsInfos() if Blowed then self.Active = false self:TriggerInput( "Active" , 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end end --SET Manual Gearbox Functions (Kill Engine) function ENT:SetManualInfos() local Staled = false - --Get Gearbox, and if its manual, stall engine under half idle rpm - for Key, Link in pairs( self.GearLink ) do - if (IsValid( Link ) && IsValid(Link.isManual) && Link.isManual) then - if (self.FlyRPM < (self.idlerpm / 2)) then - Staled = true - end - end + if (self.FlyRPM < (self.IdleRPM / 2)) then + Staled = true end if Staled then self.Active = false self:TriggerInput( "Active" , 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end end diff --git a/lua/entities/acf_engine_maker.lua b/lua/entities/acf_engine_maker.lua index 69375f2..0115581 100644 --- a/lua/entities/acf_engine_maker.lua +++ b/lua/entities/acf_engine_maker.lua @@ -187,18 +187,25 @@ function ENT:Initialize() self.CanUpdate = true self.RequiresFuel = false + self.Fuelusing = 0 + -- Rev Limiter Vars self.CutMode = 0 self.CutRpm = 0 - self.Fuelusing = 0 self.DisableCut = 0 + self.DisableCutFinal = 0 + -- Table Vars self.ExtraLink = {} self.RadiatorLink = {} + -- Extra Vars self.PeakTorqueExtra = 0 self.RPMExtra = 0 self.ExtraUsing = 0 self.PeakTorqueHealth = 0 + -- Manual Gearbox Vars + self.ManualGearbox = false + self.GearboxCurrentGear = 0 - self.Outputs = WireLib.CreateSpecialOutputs( self, { "RPM", "Torque", "Power", "Fuel Use", "Entity", "Mass", "Physical Mass" }, { "NORMAL","NORMAL","NORMAL", "NORMAL", "ENTITY", "NORMAL", "NORMAL" } ) + self.Outputs = WireLib.CreateSpecialOutputs( self, { "RPM", "Torque", "Power", "Fuel Use", "Entity", "Mass", "Physical Mass", "Running" }, { "NORMAL","NORMAL","NORMAL", "NORMAL", "ENTITY", "NORMAL", "NORMAL", "NORMAL" } ) Wire_TriggerOutput( self, "Entity", self ) self.WireDebugName = "ACF Engine Maker" @@ -250,53 +257,38 @@ function MakeACF_EngineMaker(Owner, Pos, Angle, Id, Data1, Data2, Data3, Data4, Engine.ModTable[14] = Data14 Engine.ModTable[15] = Data15 - Engine.Mod1 = Data1 - Engine.Mod2 = Data2 - Engine.Mod3 = Data3 - Engine.Mod4 = Data4 - Engine.Mod5 = Data5 - Engine.Mod6 = Data6 - Engine.Mod7 = Data7 - Engine.Mod8 = Data8 - Engine.Mod9 = Data9 - Engine.Mod10 = Data10 - Engine.Mod11 = Data11 - Engine.Mod12 = Data12 - Engine.Mod13 = Data13 - Engine.Mod14 = Data14 - Engine.Mod15 = Data15 --Set Strings Values - if tostring(Engine.Mod1) != nil then Engine.EngineName = tostring(Engine.Mod1) else Engine.EngineName = "No Name" end - if tostring(Engine.Mod2) != nil then Engine.SoundPath = tostring(Engine.Mod2) else Engine.SoundPath = "" end - if string.find(tostring(Engine.Mod3),".mdl") then Engine.Model = tostring(Engine.Mod3) else Engine.Model = "models/engines/inline4s.mdl" end - if tostring(Engine.Mod4) != nil then Engine.FuelType = tostring(Engine.Mod4) else Engine.FuelType = "Petrol" end - if tostring(Engine.Mod5) != nil then Engine.EngineType = tostring(Engine.Mod5) else Engine.EngineType = "GenericPetrol" end + if tostring(Data1) != nil then Engine.EngineName = tostring(Data1) else Engine.EngineName = "No Name" end + if tostring(Data2) != nil then Engine.SoundPath = tostring(Data2) else Engine.SoundPath = "" end + if string.find(tostring(Data3),".mdl") then Engine.Model = tostring(Data3) else Engine.Model = "models/engines/inline4s.mdl" end + if tostring(Data4) != nil then Engine.FuelType = tostring(Data4) else Engine.FuelType = "Petrol" end + if tostring(Data5) != nil then Engine.EngineType = tostring(Data5) else Engine.EngineType = "GenericPetrol" end --Set Torque - if(tonumber(Engine.Mod6) >= 1) then Engine.PeakTorque = tonumber(Engine.Mod6) + if(tonumber(Data6) >= 1) then Engine.PeakTorque = tonumber(Data6) elseif(tonumber(Data6) < 1 or tonumber(Data6) == nil) then Engine.PeakTorque = 1 end --Set Idle - if(tonumber(Engine.Mod7) >= 1) then Engine.IdleRPM = tonumber(Engine.Mod7) - elseif(tonumber(Engine.Mod7) < 1 or tonumber(Engine.Mod7) == nil) then Engine.IdleRPM = 1 end + if(tonumber(Data7) >= 1) then Engine.IdleRPM = tonumber(Data7) + elseif(tonumber(Data7) < 1 or tonumber(Data7) == nil) then Engine.IdleRPM = 1 end --Set PeakMin - if(tonumber(Engine.Mod8) >= 1) then Engine.PeakMinRPM = tonumber(Engine.Mod8) - elseif(tonumber(Engine.Mod8) < 1 or tonumber(Engine.Mod8) == nil) then Engine.PeakMinRPM = 1 end + if(tonumber(Data8) >= 1) then Engine.PeakMinRPM = tonumber(Data8) + elseif(tonumber(Data8) < 1 or tonumber(Data8) == nil) then Engine.PeakMinRPM = 1 end --Set PeakMax - if(Engine.Mod9 <= Engine.Mod10 and tonumber(Engine.Mod9) >= 1 ) then Engine.PeakMaxRPM = tonumber(Engine.Mod9) - elseif(Engine.Mod9 > Engine.Mod10 ) then Engine.PeakMaxRPM = tonumber(Engine.Mod10) - elseif(tonumber(Engine.Mod9) < 1 or tonumber(Engine.Mod9) == nil) then Engine.PeakMaxRPM = 1 end + if(Data9 <= Data10 and tonumber(Data9) >= 1 ) then Engine.PeakMaxRPM = tonumber(Data9) + elseif(Data9 > Data10 ) then Engine.PeakMaxRPM = tonumber(Data10) + elseif(tonumber(Data9) < 1 or tonumber(Data9) == nil) then Engine.PeakMaxRPM = 1 end --Set Limit - if(tonumber(Engine.Mod10) >= 100) then Engine.LimitRPM = tonumber(Engine.Mod10) - elseif(tonumber(Engine.Mod10) < 100 or tonumber(Engine.Mod10) == nil) then Engine.LimitRPM = 100 end + if(tonumber(Data10) >= 100) then Engine.LimitRPM = tonumber(Data10) + elseif(tonumber(Data10) < 100 or tonumber(Data10) == nil) then Engine.LimitRPM = 100 end --Set Flywheel - if(tonumber(Engine.Mod11) >= 0.001) then Engine.FlywheelMassValue = tonumber(Engine.Mod11) - elseif(tonumber(Engine.Mod11) < 0.001 or tonumber(Engine.Mod11) == nil) then Engine.FlywheelMassValue = 0.001 end + if(tonumber(Data11) >= 0.001) then Engine.FlywheelMassValue = tonumber(Data11) + elseif(tonumber(Data11) < 0.001 or tonumber(Data11) == nil) then Engine.FlywheelMassValue = 0.001 end --Set Weight - if(tonumber(Engine.Mod12) >= 1) then Engine.Weight = tonumber(Engine.Mod12) - elseif(tonumber(Engine.Mod12) < 1 or tonumber(Engine.Mod12) == nil ) then Engine.Weight = 1 end + if(tonumber(Data12) >= 1) then Engine.Weight = tonumber(Data12) + elseif(tonumber(Data12) < 1 or tonumber(Data12) == nil ) then Engine.Weight = 1 end --Set Electric/turbine stuff - if tobool(Engine.Mod13) != nil then Engine.iselec = tobool(Engine.Mod13) else Engine.iselec = false end - if tobool(Engine.Mod14) != nil then Engine.IsTrans = tobool(Engine.Mod14) else Engine.IsTrans = false end - if tonumber(Engine.Mod15) != nil then Engine.FlywheelOverride = tonumber(Engine.Mod15) else Engine.FlywheelOverride = 1200 end + if tobool(Data13) != nil then Engine.iselec = tobool(Data13) else Engine.iselec = false end + if tobool(Data14) != nil then Engine.IsTrans = tobool(Data14) else Engine.IsTrans = false end + if tonumber(Data15) != nil then Engine.FlywheelOverride = tonumber(Data15) else Engine.FlywheelOverride = 1200 end --Set Original Values Engine.PeakTorqueHeld = Engine.PeakTorque Engine.CutValue = Engine.LimitRPM / 20 @@ -311,13 +303,12 @@ function MakeACF_EngineMaker(Owner, Pos, Angle, Id, Data1, Data2, Data3, Data4, if Engine.CustomLimit > 0 then if Engine.EngineType == "Turbine" or Engine.EngineType == "Electric" then --Create inputs for Electric&Turbine table.insert(Inputs, "TqAdd") - table.insert(Inputs, "LimitRpmAdd") + table.insert(Inputs, "RpmAdd") table.insert(Inputs, "FlywheelMass") table.insert(Inputs, "Override") else --Create inputs others engines table.insert(Inputs, "TqAdd") - table.insert(Inputs, "MaxRpmAdd") - table.insert(Inputs, "LimitRpmAdd") + table.insert(Inputs, "RpmAdd") table.insert(Inputs, "FlywheelMass") table.insert(Inputs, "Idle") table.insert(Inputs, "Disable Cutoff") @@ -429,53 +420,38 @@ function ENT:Update( ArgsTable ) --That table is the player data, as sorted in t self.ModTable[13] = ArgsTable[17] self.ModTable[14] = ArgsTable[18] self.ModTable[15] = ArgsTable[19] - self.Mod1 = ArgsTable[5] - self.Mod2 = ArgsTable[6] - self.Mod3 = ArgsTable[7] - self.Mod4 = ArgsTable[8] - self.Mod5 = ArgsTable[9] - self.Mod6 = ArgsTable[10] - self.Mod7 = ArgsTable[11] - self.Mod8 = ArgsTable[12] - self.Mod9 = ArgsTable[13] - self.Mod10 = ArgsTable[14] - self.Mod11 = ArgsTable[15] - self.Mod12 = ArgsTable[16] - self.Mod13 = ArgsTable[17] - self.Mod14 = ArgsTable[18] - self.Mod15 = ArgsTable[19] --Set String Values - if tostring(self.Mod1) != nil then self.EngineName = tostring(self.Mod1) else self.EngineName = "No Name" end - if tostring(self.Mod2) != nil then self.SoundPath = tostring(self.Mod2) else self.SoundPath = "" end - if string.find(tostring(self.Mod3),".mdl") then self.Model = tostring(self.Mod3) else self.Model = "models/engines/v8s.mdl" end - if tostring(self.Mod4) != nil then self.FuelType = tostring(self.Mod4) else self.FuelType = "Petrol" end - if tostring(self.Mod5) != nil then self.EngineType = tostring(self.Mod5) else self.EngineType = "GenericPetrol" end + if tostring(ArgsTable[5]) != nil then self.EngineName = tostring(ArgsTable[5]) else self.EngineName = "No Name" end + if tostring(ArgsTable[6]) != nil then self.SoundPath = tostring(ArgsTable[6]) else self.SoundPath = "" end + if string.find(tostring(ArgsTable[7]),".mdl") then self.Model = tostring(ArgsTable[7]) else self.Model = "models/engines/v8s.mdl" end + if tostring(ArgsTable[8]) != nil then self.FuelType = tostring(ArgsTable[8]) else self.FuelType = "Petrol" end + if tostring(ArgsTable[9]) != nil then self.EngineType = tostring(ArgsTable[9]) else self.EngineType = "GenericPetrol" end --Set Torque - if(tonumber(self.Mod6) >= 1) then self.PeakTorque = tonumber(self.Mod6) - elseif(tonumber(self.Mod6) < 1 or tonumber(self.Mod6) == nil) then self.PeakTorque = 1 end + if(tonumber(ArgsTable[10]) >= 1) then self.PeakTorque = tonumber(ArgsTable[10]) + elseif(tonumber(ArgsTable[10]) < 1 or tonumber(ArgsTable[10]) == nil) then self.PeakTorque = 1 end --Set Idle - if(tonumber(self.Mod7) >= 1) then self.IdleRPM = tonumber(self.Mod7) - elseif(tonumber(self.Mod7) < 1 or tonumber(self.Mod7) == nil) then self.IdleRPM = 1 end + if(tonumber(ArgsTable[11]) >= 1) then self.IdleRPM = tonumber(ArgsTable[11]) + elseif(tonumber(ArgsTable[11]) < 1 or tonumber(ArgsTable[11]) == nil) then self.IdleRPM = 1 end --Set PeakMin - if(tonumber(self.Mod8) >= 1) then self.PeakMinRPM = tonumber(self.Mod8) - elseif(tonumber(self.Mod8) < 1 or tonumber(self.Mod8) == nil) then self.PeakMinRPM = 1 end + if(tonumber(ArgsTable[12]) >= 1) then self.PeakMinRPM = tonumber(ArgsTable[12]) + elseif(tonumber(ArgsTable[12]) < 1 or tonumber(ArgsTable[12]) == nil) then self.PeakMinRPM = 1 end --Set PeakMax - if(self.Mod9 <= self.Mod10 and tonumber(self.Mod9) >= 1 ) then self.PeakMaxRPM = tonumber(self.Mod9) - elseif(self.Mod9 > self.Mod10 ) then self.PeakMaxRPM = tonumber(self.Mod10) - elseif(tonumber(self.Mod9) < 1 or tonumber(self.Mod9) == nil) then self.PeakMaxRPM = 1 end + if(ArgsTable[13] <= ArgsTable[14] and tonumber(ArgsTable[13]) >= 1 ) then self.PeakMaxRPM = tonumber(ArgsTable[13]) + elseif(ArgsTable[13] > ArgsTable[14] ) then self.PeakMaxRPM = tonumber(ArgsTable[14]) + elseif(tonumber(ArgsTable[13]) < 1 or tonumber(ArgsTable[13]) == nil) then self.PeakMaxRPM = 1 end --Set Limit - if(tonumber(self.Mod10) >= 100) then self.LimitRPM = tonumber(self.Mod10) - elseif(tonumber(self.Mod10) < 100 or tonumber(self.Mod10) == nil) then self.LimitRPM = 100 end + if(tonumber(ArgsTable[14]) >= 100) then self.LimitRPM = tonumber(ArgsTable[14]) + elseif(tonumber(ArgsTable[14]) < 100 or tonumber(ArgsTable[14]) == nil) then self.LimitRPM = 100 end --Set Flywheel - if(tonumber(self.Mod11) >= 0.001) then self.FlywheelMassValue = tonumber(self.Mod11) - elseif(tonumber(self.Mod11) < 0.001 or tonumber(self.Mod11) == nil) then self.FlywheelMassValue = 0.001 end + if(tonumber(ArgsTable[15]) >= 0.001) then self.FlywheelMassValue = tonumber(ArgsTable[15]) + elseif(tonumber(ArgsTable[15]) < 0.001 or tonumber(ArgsTable[15]) == nil) then self.FlywheelMassValue = 0.001 end --Set Weight - if(tonumber(self.Mod12) >= 1) then self.Weight = tonumber(self.Mod12) - elseif(tonumber(self.Mod12) < 1 or tonumber(self.Mod12) == nil) then self.Weight = 1 end + if(tonumber(ArgsTable[16]) >= 1) then self.Weight = tonumber(ArgsTable[16]) + elseif(tonumber(ArgsTable[16]) < 1 or tonumber(ArgsTable[16]) == nil) then self.Weight = 1 end --Set Electric/Turbine Stuff - if tobool(self.Mod13) != nil then self.iselec = tobool(self.Mod13) else self.iselec = false end - if tobool(self.Mod14) != nil then self.IsTrans = tobool(self.Mod14) else self.IsTrans = false end - if tonumber(self.Mod15) != nil then self.FlywheelOverride = tonumber(self.Mod15) else self.FlywheelOverride = 1200 end + if tobool(ArgsTable[17]) != nil then self.iselec = tobool(ArgsTable[17]) else self.iselec = false end + if tobool(ArgsTable[18]) != nil then self.IsTrans = tobool(ArgsTable[18]) else self.IsTrans = false end + if tonumber(ArgsTable[19]) != nil then self.FlywheelOverride = tonumber(ArgsTable[19]) else self.FlywheelOverride = 1200 end --Set Original Values self.PeakTorqueHeld = self.PeakTorque self.CutValue = self.LimitRPM / 20 @@ -490,13 +466,12 @@ function ENT:Update( ArgsTable ) --That table is the player data, as sorted in t if self.CustomLimit > 0 then if self.EngineType == "Turbine" or self.EngineType == "Electric" then --Create inputs for Electric&Turbine table.insert(Inputs, "TqAdd") - table.insert(Inputs, "LimitRpmAdd") + table.insert(Inputs, "RpmAdd") table.insert(Inputs, "FlywheelMass") table.insert(Inputs, "Override") else --Create inputs others engines table.insert(Inputs, "TqAdd") - table.insert(Inputs, "MaxRpmAdd") - table.insert(Inputs, "LimitRpmAdd") + table.insert(Inputs, "RpmAdd") table.insert(Inputs, "FlywheelMass") table.insert(Inputs, "Idle") table.insert(Inputs, "Disable Cutoff") @@ -576,7 +551,8 @@ function ENT:UpdateOverlayText() //self.FuelusingGUI = self.Fuelusing //self.FlyRPMGUI = self.FlyRPM - local text = "Power: " .. math.Round(self.PowerGUI) .. " kW / " .. math.Round(self.PowerGUI * 1.34) .. " hp\n" + local text = "" .. self.EngineName.."\n" + text = text .. "Power: " .. math.Round(self.PowerGUI) .. " kW / " .. math.Round(self.PowerGUI * 1.34) .. " hp\n" text = text .. "Torque: " .. math.Round(self.TorqueGUI) .. " Nm / " .. math.Round(self.TorqueGUI * 0.73) .. " ft-lb\n" text = text .. "Powerband: " .. pbmin .. " - " .. pbmax .. " RPM\n" if self.EngineType == "Turbine" or self.EngineType == "Electric" then @@ -636,6 +612,7 @@ function ENT:TriggerInput( iname, value ) self.RPM[1] = self.IdleRPM self.Active = true self.Active2 = true + Wire_TriggerOutput( self, "Running", 1 ) self.Sound = CreateSound(self, self.SoundPath) self.Sound:PlayEx(0.5,100) self:ACFInit() @@ -656,6 +633,7 @@ function ENT:TriggerInput( iname, value ) Wire_TriggerOutput( self, "Torque", 0 ) Wire_TriggerOutput( self, "Power", 0 ) Wire_TriggerOutput( self, "Fuel Use", 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end elseif (value <= 0 and self.Active) then self.Active = false @@ -663,6 +641,7 @@ function ENT:TriggerInput( iname, value ) Wire_TriggerOutput( self, "Torque", 0 ) Wire_TriggerOutput( self, "Power", 0 ) Wire_TriggerOutput( self, "Fuel Use", 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end elseif (iname == "TqAdd") then @@ -803,7 +782,11 @@ function ENT:Think() end self:SetRadsInfos() - self:SetManualInfos() + + --Set Manual Gearbox Infos (Stall Engine) + if (self.ManualGearbox) then + self:SetManualInfos() + end self.LastThink = Time self:NextThink( Time ) @@ -936,113 +919,122 @@ function ENT:CalcRPM() self.TorqueMult = math.Clamp(((1 - self.TorqueScale) / (0.5)) * ((self.ACF.Health/self.ACF.MaxHealth) - 1) + 1, self.TorqueScale, 1) self.PeakTorque = (self.PeakTorqueAdd+self.PeakTorqueExtra-self.PeakTorqueHealth) * self.TorqueMult - -- Calculate the current torque from flywheel RPM - self.Torque = boost * self.Throttle * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM, (self.LimitRPM - self.FlyRPM) / (self.LimitRPM - self.PeakMaxRPM), 1 ), 0 ) - - self.Inertia = self.FlywheelMassValue*(3.1416)^2 - local Drag local TorqueDiff - if self.Active then - if( self.CutMode == 0 ) then - self.Torque = boost * self.Throttle * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) - - if self.iselec == true then - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / self.FlywheelOverride) * (1 - self.Throttle) / self.Inertia - else - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / (self.PeakMaxRPM+self.RPMExtra)) * ( 1 - self.Throttle) / self.Inertia - end - - elseif( self.CutMode == 1 ) then - self.Torque = boost * 0 * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) - - if self.iselec == true then - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / self.FlywheelOverride) * (1 - 0) / self.Inertia - else - Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / (self.PeakMaxRPM+self.RPMExtra)) * ( 1 - 0) / self.Inertia - end - - end - -- Let's accelerate the flywheel based on that torque - self.FlyRPM = math.max( self.FlyRPM + self.Torque / self.Inertia - Drag, 1 ) - -- This is the presently avaliable torque from the engine - TorqueDiff = math.max( self.FlyRPM - self.IdleRPM, 0 ) * self.Inertia - else - self.Torque = boost * 0 * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) - if self.iselec == true then - Drag = self.PeakTorque * (math.max( self.FlyRPM - 0, 0) / self.FlywheelOverride) * (1 - 0) / self.Inertia - else - Drag = self.PeakTorque * (math.max( self.FlyRPM - 0, 0) / (self.PeakMaxRPM+self.RPMExtra)) * ( 1 - 0) / self.Inertia - end - -- Let's accelerate the flywheel based on that torque + --Custom Drag Value for Engines Types + local DragType = self.PeakMaxRPM+self.RPMExtra + if self.iselec == true then + DragType = self.FlywheelOverride + end + + if (self.Active and self.CutMode == 0) then + --Set Torque & Drag + self.Torque = boost * self.Throttle * math.max( self.PeakTorque * math.min( self.FlyRPM / self.PeakMinRPM , ((self.LimitRPM+self.RPMExtra) - self.FlyRPM) / ((self.LimitRPM+self.RPMExtra) - (self.PeakMaxRPM+self.RPMExtra)), 1 ), 0 ) + Drag = self.PeakTorque * (math.max( self.FlyRPM - self.IdleRPM, 0) / DragType) * (1 - self.Throttle) / self.Inertia + --Set FlyRPM & TorqueDiff + self.FlyRPM = math.max( self.FlyRPM + self.Torque / self.Inertia - Drag, 1 ) + TorqueDiff = math.max( self.FlyRPM - self.IdleRPM, 0 ) * self.Inertia + --Reset TorqueDiff for Manual Gearbox + if (self.ManualGearbox) then + TorqueDiff = math.max( self.FlyRPM + (self.IdleRPM/4), 0 ) * self.Inertia + end + else + --Set Torque & Drag + self.Torque = 0 + Drag = 10 * (math.max( self.FlyRPM, 0) / DragType) * 1 / (0.001*(3.1416)^2) + --Set RPM & TorqueDiff self.FlyRPM = math.max( self.FlyRPM + self.Torque / self.Inertia - Drag, 1 ) - -- This is the presently avaliable torque from the engine TorqueDiff = 0 end -- The gearboxes don't think on their own, it's the engine that calls them, to ensure consistent execution order local Boxes = table.Count( self.GearLink ) local TotalReqTq = 0 + local TotalReqTq2 = 0 --Used for Manual Gearbox (Aka Engine Back-Force) + -- Get the requirements for torque for the gearboxes (Max clutch rating minus any wheels currently spinning faster than the Flywheel) for Key, Link in pairs( self.GearLink ) do if not Link.Ent.Legal then continue end - + -- Set accelerating engine gearbox Back-Force Link.ReqTq = Link.Ent:Calc( self.FlyRPM, self.Inertia ) TotalReqTq = TotalReqTq + Link.ReqTq + if self.ManualGearbox then + -- Set deccelerating engine gearbox Back-Force (Manual Gearbox) + Link.ReqTq2 = Link.Ent:Calc2( self.FlyRPM, self.Inertia ) + TotalReqTq2 = TotalReqTq2 + Link.ReqTq2 + end end -- Split the torque fairly between the gearboxes who need it for Key, Link in pairs( self.GearLink ) do if not Link.Ent.Legal then continue end - -- Set TRUE Manual Gearbox Torque - if (IsValid(Link.isManual) && Link.isManual) then - TorqueDiff = math.max( self.FlyRPM, 0 ) * self.Inertia - end -- Calculate the ratio of total requested torque versus what's avaliable local AvailRatio = math.min( TorqueDiff / TotalReqTq / Boxes, 1 ) - -- Set the Torque + self.GearboxCurrentGear = Link.Ent.Gear + -- Reset AvailRatio (Manual Gearbox) + if (self.ManualGearbox and self.Throttle == 0 and self.GearboxCurrentGear != 0 and self.FlyRPM > self.IdleRPM) then + AvailRatio = 0 + end + -- Set the Torque On Gearboxes Link.Ent:Act( Link.ReqTq * AvailRatio * self.MassRatio, DeltaTime, self.MassRatio ) end + -- Remove RPM with Gearbox Velocity (Engine Back Force) self.FlyRPM = self.FlyRPM - math.min( TorqueDiff, TotalReqTq ) / self.Inertia - if( self.DisableCut == 0 ) then + -- Add RPM (Manual Gearbox)(Engine Back Force) + if (self.ManualGearbox and self.Active) then + if self.Throttle == 0 and self.GearboxCurrentGear != 0 then + --Remove Rev Limiter while decompressing + self.DisableCutFinal = 1 + + self.FlyRPM = self.FlyRPM + (TotalReqTq2 / self.Inertia) + else + --Enable Rev Limiter + self.DisableCutFinal = self.DisableCut + end + else + --Enable Rev Limiter + self.DisableCutFinal = self.DisableCut + end + + if( self.DisableCutFinal == 0 ) then + -- Cut the Engine (Rev Limiter) if( self.FlyRPM >= self.CutRpm and self.CutMode == 0 ) then self.CutMode = 1 if self.Sound then self.Sound:Stop() end self.Sound = nil - local MakeSound = math.random(1,3) + local MakeSound = math.random(1,4) if MakeSound <= 1 and self.Sound2 and self.Sound2:IsPlaying() then self.Sound2:Stop() end if MakeSound <= 1 then self.Sound2 = CreateSound(self, "ambient/explosions/explode_4.wav") self.Sound2:PlayEx(0.7,100) end end + -- Enable back Engine (Rev Limiter) if( self.FlyRPM <= self.CutRpm - self.CutValue and self.CutMode == 1 ) then self.CutMode = 0 self.Sound = CreateSound(self, self.SoundPath) self.Sound:PlayEx(0.5,100) end - elseif( self.DisableCut == 1 ) then - self.CutMode = 0 - end - if( self.FlyRPM <= 50 and self.Active == false ) then - self.Active2 = false - self.FlyRPM = 0 - if self.Sound then - self.Sound:Stop() + elseif( self.DisableCutFinal == 1 ) then + -- Fix Sound Bug once its cutted + if( self.CutMode == 1 ) then + self.Sound = CreateSound(self, self.SoundPath) + self.Sound:PlayEx(0.5,100) end - self.Sound = nil - self:UpdateOverlayText() + -- No Rev Limiting + self.CutMode = 0 end --Update Gui /*if self.FuelusingGUI != self.Fuelusing or self.FlyRPMGUI != self.FlyRPM then self:UpdateOverlayText() end*/ + --Update extras values for Key, Extra in pairs(self.ExtraLink) do if IsValid(Extra) then @@ -1056,6 +1048,7 @@ function ENT:CalcRPM() end end end + --Update radiator values for Key, Radiator in pairs(self.RadiatorLink) do if IsValid( Radiator ) then @@ -1174,7 +1167,8 @@ function ENT:Link( Target ) Ent = Target, Rope = Rope, RopeLen = ( OutPos - InPos ):Length(), - ReqTq = 0 + ReqTq = 0, + ReqTq2 = 0 --used for manual gearbox, engine back-force torque } table.insert( self.GearLink, Link ) @@ -1214,6 +1208,9 @@ function ENT:Unlink( Target ) table.remove( self.GearLink,Key ) + -- Make Sure Manual Gearbox are disabled + self.ManualGearbox = false + return true, "Unlink successful!" end @@ -1393,18 +1390,14 @@ end function ENT:SetManualInfos() local Staled = false - --Get Gearbox, and if its manual, stall engine under half idle rpm - for Key, Link in pairs( self.GearLink ) do - if (IsValid( Link ) && IsValid(Link.isManual) && Link.isManual) then - if (self.FlyRPM < (self.idlerpm / 2)) then - Staled = true - end - end + if (self.FlyRPM < (self.IdleRPM / 2)) then + Staled = true end if Staled then self.Active = false self:TriggerInput( "Active" , 0 ) + Wire_TriggerOutput( self, "Running", 0 ) end end diff --git a/lua/entities/acf_gearbox_air.lua b/lua/entities/acf_gearbox_air.lua index 69bdf7d..f105793 100644 --- a/lua/entities/acf_gearbox_air.lua +++ b/lua/entities/acf_gearbox_air.lua @@ -76,7 +76,7 @@ function ENT:Initialize() self.Legal = true self.Inputs = Wire_CreateInputs( self, {"Clutch", "Brake"} ) - self.Outputs = WireLib.CreateSpecialOutputs( self, { "Entity" , "Gearbox RPM" }, { "ENTITY" , "NORMAL" } ) + self.Outputs = WireLib.CreateSpecialOutputs( self, { "Entity" }, { "ENTITY" , "NORMAL" } ) Wire_TriggerOutput( self, "Entity", self ) end @@ -323,12 +323,6 @@ function ENT:Calc( InputRPM, InputInertia, GetRatio ) if self.GearRatio ~= 0 and ( ( InputRPM > 0 and RPM < InputRPM ) or ( InputRPM < 0 and RPM > InputRPM ) ) then Link.ReqTq = math.min( Clutch, ( InputRPM - RPM ) * InputInertia ) end - --Calling RPM Ouputs Value's - if Clutch == 0 then - Wire_TriggerOutput(self, "Gearbox RPM", 0) - elseif Clutch > 0 then - Wire_TriggerOutput(self, "Gearbox RPM", RPM) - end self.PropellerRpm = RPM self:UpdateOverlayText() diff --git a/lua/entities/acf_gearbox_auto.lua b/lua/entities/acf_gearbox_auto.lua index 313deb8..222296d 100644 --- a/lua/entities/acf_gearbox_auto.lua +++ b/lua/entities/acf_gearbox_auto.lua @@ -326,7 +326,7 @@ function MakeACF_GearboxAuto(Owner, Pos, Angle, Id, Data1, Data2, Data3, Data4, table.insert(Inputs, "Brake") end - local Outputs = { "Ratio", "Entity", "Current Gear", "Gearbox RPM" } + local Outputs = { "Ratio", "Entity", "Current Gear" } local OutputTypes = { "NORMAL", "ENTITY", "NORMAL", "NORMAL" } GearboxAuto.Inputs = Wire_CreateInputs( GearboxAuto, Inputs ) @@ -686,12 +686,6 @@ function ENT:Calc( InputRPM, InputInertia ) if self.GearRatio ~= 0 and ( ( InputRPM > 0 and RPM < InputRPM ) or ( InputRPM < 0 and RPM > InputRPM ) ) then Link.ReqTq = math.min( Clutch, ( InputRPM - RPM ) * InputInertia ) end - --Calling RPM Ouputs Value's - if Clutch == 0 then - Wire_TriggerOutput(self, "Gearbox RPM", 0) - elseif Clutch > 0 then - Wire_TriggerOutput(self, "Gearbox RPM", RPM) - end end self.TotalReqTq = self.TotalReqTq + math.abs( Link.ReqTq ) end diff --git a/lua/entities/acf_gearbox_cvt.lua b/lua/entities/acf_gearbox_cvt.lua index 2c71b28..4124706 100644 --- a/lua/entities/acf_gearbox_cvt.lua +++ b/lua/entities/acf_gearbox_cvt.lua @@ -299,7 +299,7 @@ function MakeACF_GearboxCVT(Owner, Pos, Angle, Id, Data1, Data2, Data3, Data4, D end GearboxCVT.Inputs = Wire_CreateInputs( GearboxCVT.Entity, Inputs ) - GearboxCVT.Outputs = WireLib.CreateSpecialOutputs( GearboxCVT.Entity, { "Ratio", "Entity" , "Current Gear", "Gearbox RPM" }, { "NORMAL" , "ENTITY" , "NORMAL" , "NORMAL" } ) + GearboxCVT.Outputs = WireLib.CreateSpecialOutputs( GearboxCVT.Entity, { "Ratio", "Entity" , "Current Gear" }, { "NORMAL" , "ENTITY" , "NORMAL" , "NORMAL" } ) Wire_TriggerOutput(GearboxCVT.Entity, "Entity", GearboxCVT.Entity) GearboxCVT.LClutch = GearboxCVT.MaxTorque @@ -673,12 +673,6 @@ function ENT:Calc( InputRPM, InputInertia ) if self.GearRatio ~= 0 and ( ( InputRPM > 0 and RPM < InputRPM ) or ( InputRPM < 0 and RPM > InputRPM ) ) then Link.ReqTq = math.min( Clutch, ( InputRPM - RPM ) * InputInertia ) end - --Calling RPM Ouputs Value's - if Clutch == 0 then - Wire_TriggerOutput(self, "Gearbox RPM", 0) - elseif Clutch > 0 then - Wire_TriggerOutput(self, "Gearbox RPM", RPM) - end end self.TotalReqTq = self.TotalReqTq + math.abs( Link.ReqTq ) end diff --git a/lua/entities/acf_gearbox_manual.lua b/lua/entities/acf_gearbox_manual.lua index 1acc479..8ad9585 100644 --- a/lua/entities/acf_gearbox_manual.lua +++ b/lua/entities/acf_gearbox_manual.lua @@ -110,22 +110,15 @@ function ENT:Initialize() self.LegalThink = 0 - self.RPM = {} - self.CurRPM = 0 - //self.CVT = false self.DoubleDiff = false self.InGear = false self.CanUpdate = true self.LastActive = 0 self.Legal = true + //Manual Gearbox Vars self.isManual = true - - //self.OnReverse = 0 - //self.Usable = 1 - //self.AllowChange = 0 - //self.ClutchMode = 0 - //self.ClutchModeUse = 0 + self.TotalReqTq2 = 0 end @@ -188,7 +181,7 @@ function MakeACF_GearboxManual(Owner, Pos, Angle, Id, Data1, Data2, Data3, Data4 end local Outputs = { "Ratio", "Entity", "Current Gear" } - local OutputTypes = { "NORMAL", "ENTITY", "NORMAL" } + local OutputTypes = { "NORMAL", "ENTITY", "NORMAL", "NORMAL" } GearboxManual.Inputs = Wire_CreateInputs( GearboxManual, Inputs ) GearboxManual.Outputs = WireLib.CreateSpecialOutputs( GearboxManual, Outputs, OutputTypes ) @@ -264,8 +257,8 @@ function ENT:Update( ArgsTable ) table.insert(Inputs, "Brake") end - local Outputs = { "Ratio", "Entity", "Current Gear" } - local OutputTypes = { "NORMAL", "ENTITY", "NORMAL" } + local Outputs = { "Ratio", "Entity", "Current Gear", "Gearbox RPM" } + local OutputTypes = { "NORMAL", "ENTITY", "NORMAL", "NORMAL" } self.Inputs = Wire_CreateInputs( self, Inputs ) self.Outputs = WireLib.CreateSpecialOutputs( self, Outputs, OutputTypes ) @@ -458,6 +451,14 @@ function ENT:CheckEnts() end +function ENT:GetGear( ) + return self.Gear +end + +function ENT:GetClutching( ) + return self.Clutching +end + function ENT:Calc( InputRPM, InputInertia ) if self.LastActive == CurTime() then @@ -466,6 +467,10 @@ function ENT:Calc( InputRPM, InputInertia ) if self.ChangeFinished < CurTime() then self.InGear = true + else + -- disable power while changing gear + self.TotalReqTq = 0 + return self.TotalReqTq end self:CheckEnts() @@ -504,10 +509,10 @@ function ENT:Calc( InputRPM, InputInertia ) Sign = 0 end if Link.Side == 0 then - local DTq = math.Clamp( ( self.SteerRate * ( ( InputRPM * ( math.abs( self.SteerRate ) + 1 ) ) - (RPM * Sign) ) ) * InputInertia, -self.MaxTorque, self.MaxTorque ) + local DTq = math.Clamp( ( self.SteerRate * ( ( InputRPM * ( math.abs( self.SteerRate ) + 1 ) ) - (RPM * Sign) ) ) * InputInertia, -self.MaxTorque, self.MaxTorque ) Link.ReqTq = ( NTq + DTq ) elseif Link.Side == 1 then - local DTq = math.Clamp( ( self.SteerRate * ( ( InputRPM * ( math.abs( self.SteerRate ) + 1 ) ) + (RPM * Sign) ) ) * InputInertia, -self.MaxTorque, self.MaxTorque ) + local DTq = math.Clamp( ( self.SteerRate * ( ( InputRPM * ( math.abs( self.SteerRate ) + 1 ) ) + (RPM * Sign) ) ) * InputInertia, -self.MaxTorque, self.MaxTorque ) Link.ReqTq = ( NTq - DTq ) end end @@ -523,6 +528,225 @@ function ENT:Calc( InputRPM, InputInertia ) return math.min( self.TotalReqTq, self.MaxTorque ) end +function ENT:Calc2( InputRPM, InputInertia ) + if self.LastActive == CurTime() then + return self.TotalReqTq2 + end + + local BoxPhys = self:GetPhysicsObject() + local SelfWorld = self:LocalToWorld( BoxPhys:GetAngleVelocity() ) - self:GetPos() + + self.TotalReqTq2 = 0 + + for Key, Link in pairs( self.WheelLink ) do + if not IsValid( Link.Ent ) then + table.remove( self.WheelLink, Key ) + continue end + + local Clutch = 0 + if Link.Side == 0 then + Clutch = self.LClutch + elseif Link.Side == 1 then + Clutch = self.RClutch + end + + Link.ReqTq2 = 0 + if Link.Ent.IsGeartrain then + if not Link.Ent.Legal then continue end + + -- ONLY if Calc2() is added on the linked gearbox ## NOT ADDED ON ANY GEARBOXES --> OVERRIDE MODE INSTEAD FOR COMPATIBILITY WITH ORIGINAL ACF + /*if IsValid(Link.Ent.TotalReqTq2) then + Link.ReqTq2 = math.min( Clutch, math.abs( Link.Ent:Calc2( InputRPM * self.GearRatio, Inertia ) * self.GearRatio ) ) + end*/ + + //#### MORE THAN 4GEARBOXES ARE ALMOST IMPOSSIBLE, IT WOULD BE STUPID TO HAVE SOMETHING LIKE THIS : MANUAL-->CLUTCH-->TRANSFER-->TRANSFER-->DIFF + + -- Link up to 4x external gearboxes, and override the manual function to read the final wheel RPM + for Key2, Link2 in pairs( Link.Ent.WheelLink ) do + if Link2.Ent.IsGeartrain then + for Key3, Link3 in pairs( Link2.Ent.WheelLink ) do + if Link3.Ent.IsGeartrain then + for Key4, Link4 in pairs( Link3.Ent.WheelLink ) do + if Link4.Ent.IsGeartrain then + for Key5, Link5 in pairs( Link4.Ent.WheelLink ) do + if !Link5.Ent.IsGeartrain then + if !Link4.Ent.DoubleDiff then + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, false, Link, Link2, Link3, Link4, Link5) + else + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, true, Link, Link2, Link3, Link4, Link5) + end + end + end + else + if !Link3.Ent.DoubleDiff then + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, false, Link, Link2, Link3, Link4) + else + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, true, Link, Link2, Link3, Link4) + end + end + end + else + if !Link2.Ent.DoubleDiff then + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, false, Link, Link2, Link3) + else + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, true, Link, Link2, Link3) + end + end + end + else + if !Link.Ent.DoubleDiff then + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, false, Link, Link2) + else + Link.ReqTq2 = self:RPMCheckup(InputRPM, InputInertia, true, Link, Link2) + end + end + end + elseif self.DoubleDiff then + local RPM = self:CalcWheel( Link, SelfWorld ) + if self.GearRatio ~= 0 and ( ( InputRPM > 0 and RPM < InputRPM ) or ( InputRPM < 0 and RPM > InputRPM ) ) then + local NTq = math.min( Clutch, ( RPM - InputRPM) * InputInertia) + -- Set Sign + if( self.SteerRate ~= 0 ) then Sign = self.SteerRate / math.abs( self.SteerRate ) else Sign = 0 end + -- Set Link Sides + if Link.Side == 0 then + local DTq = math.Clamp( ( self.SteerRate * ( (RPM * Sign) - ( InputRPM * ( math.abs( self.SteerRate ) + 1 ) ) ) ) * InputInertia, -self.MaxTorque, self.MaxTorque ) + elseif Link.Side == 1 then + local DTq = math.Clamp( ( self.SteerRate * ( (RPM * Sign) + ( InputRPM * ( math.abs( self.SteerRate ) + 1 ) ) ) ) * InputInertia, -self.MaxTorque, self.MaxTorque ) + end + Link.ReqTq2 = ( NTq + DTq ) + end + else + local RPM = self:CalcWheel( Link, SelfWorld ) + if self.GearRatio ~= 0 and ( ( InputRPM > 0 and RPM > InputRPM ) or ( InputRPM < 0 and RPM < InputRPM ) ) then + Link.ReqTq2 = math.min( Clutch, ( RPM - InputRPM ) * InputInertia ) + end + end + self.TotalReqTq2 = self.TotalReqTq2 + math.abs( Link.ReqTq2 ) + end + return self.TotalReqTq2 +end + +-- THIS IS AN 'OVERRIDE' FUNCTION FOR GEARBOX WITHOUT MANUAL MODE, IT RUN HERE INSTEAD OF COPYING IT IN ANY GEARBOXES FILES +function ENT:RPMCheckup (InputRPM, InputInertia, DoubleDiff, Link1, Link2, Link3, Link4, Link5) + /*if LinkNumer == 2 then + elseif LinkNumer == 3 then + elseif LinkNumer == 4 then + end*/ + -- Perform RPM Checkup on the next Gearbox + -- Set Links Number (link up to 4x gearboxes) + local LinkNumer = 2 + if (IsValid(Link3)) then LinkNumer = 3 end + if (IsValid(Link4)) then LinkNumer = 4 end + if (IsValid(Link5)) then LinkNumer = 5 end + + -- Set EngineRPM + local InputRPM2 = InputRPM * self.GearRatio + if LinkNumer > 2 then + if LinkNumer == 3 then InputRPM2 = (InputRPM * self.GearRatio) * Link1.Ent.GearRatio end + if LinkNumer == 4 then InputRPM2 = ((InputRPM * self.GearRatio) * Link1.Ent.GearRatio) * Link2.Ent.GearRatio end + if LinkNumer == 5 then InputRPM2 = (((InputRPM * self.GearRatio) * Link1.Ent.GearRatio) * Link2.Ent.GearRatio) * Link3.Ent.GearRatio end + end + + -- Set Inertia + local Inertia = InputInertia / self.GearRatio + if LinkNumer > 2 then + if LinkNumer == 3 then Inertia = (InputInertia / self.GearRatio) / Link1.Ent.GearRatio end + if LinkNumer == 4 then Inertia = ((InputInertia / self.GearRatio) / Link1.Ent.GearRatio) / Link2.Ent.GearRatio end + if LinkNumer == 5 then Inertia = (((InputInertia / self.GearRatio) / Link1.Ent.GearRatio) / Link2.Ent.GearRatio) / Link3.Ent.GearRatio end + end + + -- Set Pos, World, Phys Vars + local BoxPhys + local SelfWorld + if LinkNumer == 2 then + BoxPhys = Link1.Ent:GetPhysicsObject() + SelfWorld = Link1.Ent:LocalToWorld( BoxPhys:GetAngleVelocity() ) - Link1.Ent:GetPos() + elseif LinkNumer == 3 then + BoxPhys = Link2.Ent:GetPhysicsObject() + SelfWorld = Link2.Ent:LocalToWorld( BoxPhys:GetAngleVelocity() ) - Link2.Ent:GetPos() + elseif LinkNumer == 4 then + BoxPhys = Link3.Ent:GetPhysicsObject() + SelfWorld = Link3.Ent:LocalToWorld( BoxPhys:GetAngleVelocity() ) - Link3.Ent:GetPos() + elseif LinkNumer == 5 then + BoxPhys = Link4.Ent:GetPhysicsObject() + SelfWorld = Link4.Ent:LocalToWorld( BoxPhys:GetAngleVelocity() ) - Link4.Ent:GetPos() + end + + -- Get RPM + local RPM = 0 + if LinkNumer == 2 then RPM = Link1.Ent:CalcWheel(Link2, SelfWorld) + elseif LinkNumer == 3 then RPM = Link2.Ent:CalcWheel(Link3, SelfWorld) + elseif LinkNumer == 4 then RPM = Link3.Ent:CalcWheel(Link4, SelfWorld) + elseif LinkNumer == 5 then RPM = Link4.Ent:CalcWheel(Link5, SelfWorld) + end + + -- Set Clutch + local Clutch = 0 + if LinkNumer == 2 then + if Link2.Side == 0 then Clutch = Link1.Ent.LClutch + elseif Link2.Side == 1 then Clutch = Link1.Ent.RClutch end + elseif LinkNumer == 3 then + if Link3.Side == 0 then Clutch = Link2.Ent.LClutch + elseif Link3.Side == 1 then Clutch = Link2.Ent.RClutch end + elseif LinkNumer == 4 then + if Link4.Side == 0 then Clutch = Link3.Ent.LClutch + elseif Link4.Side == 1 then Clutch = Link3.Ent.RClutch end + elseif LinkNumer == 5 then + if Link5.Side == 0 then Clutch = Link4.Ent.LClutch + elseif Link5.Side == 1 then Clutch = Link4.Ent.RClutch end + end + + -- Set RPM Torque to send + if ((LinkNumer==2 and Link1.Ent.GearRatio~=0) or (LinkNumer==3 and Link2.Ent.GearRatio~=0) or (LinkNumer==4 and Link3.Ent.GearRatio~=0) or (LinkNumer==5 and Link4.Ent.GearRatio~=0))then + if ((InputRPM2 > 0 and RPM > InputRPM2) or (InputRPM2 < 0 and RPM < InputRPM2)) then + if DoubleDiff then + -- DoubleDiff + local NTq = math.min( Clutch, ( RPM - InputRPM2) * Inertia) + -- Set Sign + if LinkNumer == 2 then if( Link1.Ent.SteerRate ~= 0 ) then Sign = Link1.Ent.SteerRate / math.abs( Link1.Ent.SteerRate ) else Sign = 0 end end + if LinkNumer == 3 then if( Link2.Ent.SteerRate ~= 0 ) then Sign = Link2.Ent.SteerRate / math.abs( Link2.Ent.SteerRate ) else Sign = 0 end end + if LinkNumer == 4 then if( Link3.Ent.SteerRate ~= 0 ) then Sign = Link3.Ent.SteerRate / math.abs( Link3.Ent.SteerRate ) else Sign = 0 end end + if LinkNumer == 5 then if( Link4.Ent.SteerRate ~= 0 ) then Sign = Link4.Ent.SteerRate / math.abs( Link4.Ent.SteerRate ) else Sign = 0 end end + + -- Set Link Sides + if LinkNumer == 2 then + if Link2.Side == 0 then + local DTq = math.Clamp((Link1.Ent.SteerRate*((RPM*Sign)-(InputRPM2*(math.abs(Link1.Ent.SteerRate)+1))))*Inertia, -Link1.Ent.MaxTorque, Link1.Ent.MaxTorque) + elseif Link2.Side == 1 then + local DTq = math.Clamp((Link1.Ent.SteerRate*((RPM*Sign)+(InputRPM2*(math.abs(Link1.Ent.SteerRate)+1))))*Inertia, -Link1.Ent.MaxTorque, Link1.Ent.MaxTorque) + end + elseif LinkNumer == 3 then + if Link3.Side == 0 then + local DTq = math.Clamp((Link2.Ent.SteerRate*((RPM*Sign)-(InputRPM2*(math.abs(Link2.Ent.SteerRate)+1))))*Inertia, -Link2.Ent.MaxTorque, Link2.Ent.MaxTorque) + elseif Link3.Side == 1 then + local DTq = math.Clamp((Link2.Ent.SteerRate*((RPM*Sign)+(InputRPM2*(math.abs(Link2.Ent.SteerRate)+1))))*Inertia, -Link2.Ent.MaxTorque, Link2.Ent.MaxTorque) + end + elseif LinkNumer == 4 then + if Link4.Side == 0 then + local DTq = math.Clamp((Link3.Ent.SteerRate*((RPM*Sign)-(InputRPM2*(math.abs(Link3.Ent.SteerRate)+1))))*Inertia, -Link3.Ent.MaxTorque, Link3.Ent.MaxTorque) + elseif Link4.Side == 1 then + local DTq = math.Clamp((Link3.Ent.SteerRate*((RPM*Sign)+(InputRPM2*(math.abs(Link3.Ent.SteerRate)+1))))*Inertia, -Link3.Ent.MaxTorque, Link3.Ent.MaxTorque) + end + elseif LinkNumer == 5 then + if Link5.Side == 0 then + local DTq = math.Clamp((Link4.Ent.SteerRate*((RPM*Sign)-(InputRPM2*(math.abs(Link4.Ent.SteerRate)+1))))*Inertia, -Link4.Ent.MaxTorque, Link4.Ent.MaxTorque) + elseif Link5.Side == 1 then + local DTq = math.Clamp((Link4.Ent.SteerRate*((RPM*Sign)+(InputRPM2*(math.abs(Link4.Ent.SteerRate)+1))))*Inertia, -Link4.Ent.MaxTorque, Link4.Ent.MaxTorque) + end + end + return (NTq + DTq) + else + -- Normal + return math.min( Clutch, ( RPM - InputRPM2 ) * Inertia ) + end + else + return 0 + end + else + return 0 + end +end + function ENT:CalcWheel( Link, SelfWorld ) local Wheel = Link.Ent @@ -662,6 +886,7 @@ function ENT:Link( Target ) RopeLen = ( OutPosWorld - InPosWorld ):Length(), Output = OutPos, ReqTq = 0, + ReqTq2 = 0, Vel = 0 } table.insert( self.WheelLink, Link ) diff --git a/lua/entities/gmod_wire_expression2/core/custom/acfcustomfunctions.lua b/lua/entities/gmod_wire_expression2/core/custom/acfcustomfunctions.lua index 2b1b236..6113e59 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/acfcustomfunctions.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/acfcustomfunctions.lua @@ -9,7 +9,7 @@ end local function isGearbox(ent) if not validPhysics(ent) then return false end - if (ent:GetClass() == "acf_gearbox_cvt" or ent:GetClass() == "acf_gearbox_auto") then return true else return false end + if (ent:GetClass() == "acf_gearbox_cvt" or ent:GetClass() == "acf_gearbox_auto" or ent:GetClass() == "acf_gearbox_manual") then return true else return false end end local function isChips(ent) @@ -74,6 +74,7 @@ local linkTables = acf_gearbox_air = {WheelLink = true, Master = false}, acf_gearbox_cvt = {WheelLink = true, Master = false}, acf_gearbox_auto = {WheelLink = true, Master = false}, + acf_gearbox_manual = {WheelLink = true, Master = false}, acf_chips = {Master = false}, acf_nos = {Master = false} } @@ -97,6 +98,7 @@ local function searchForGearboxLinks(ent) local boxes = ents.FindByClass("acf_gearbox") local boxes3 = ents.FindByClass("acf_gearbox_cvt") local boxes4 = ents.FindByClass("acf_gearbox_auto") + local boxes5 = ents.FindByClass("acf_gearbox_manual") local ret = {} @@ -133,6 +135,17 @@ local function searchForGearboxLinks(ent) end end + for _, box5 in pairs(boxes5) do + if IsValid(box5) then + for _, link in pairs(box5.WheelLink) do + if link.Ent == ent then + ret[#ret+1] = box5 + break + end + end + end + end + return ret end @@ -176,7 +189,7 @@ end e2function number entity:acfCustomLinkTo(entity target, number notify) if not (isLinkableACFEnt(this)) and (isOwner(self, this) and isOwner(self, target)) then if notify > 0 then - ACF_SendNotify(self.player, 0, "Must be called on a gun, engine, or gearbox you own.") + ACFCUSTOM_SendNotify(self.player, 0, "Must be called on a gun, engine, or gearbox you own.") end return 0 end @@ -192,7 +205,7 @@ end e2function number entity:acfCustomUnlinkFrom(entity target, number notify) if not (isLinkableACFEnt(this)) and (isOwner(self, this) and isOwner(self, target)) then if notify > 0 then - ACF_SendNotify(self.player, 0, "Must be called on a gun, engine, or gearbox you own.") + ACFCUSTOM_SendNotify(self.player, 0, "Must be called on a gun, engine, or gearbox you own.") end return 0 end