136 lines
3.2 KiB
Lua
136 lines
3.2 KiB
Lua
-- @name Koptilnya Engine
|
|
-- @author Koptilnya1337
|
|
-- @server
|
|
--
|
|
-- @include ./engine.txt
|
|
--
|
|
-- @include ./clutch.txt
|
|
--
|
|
-- @include ./gearboxes/manual.txt
|
|
-- @include ./gearboxes/cvt.txt
|
|
-- @include ./gearboxes/auto.txt
|
|
--
|
|
-- @include ./differential.txt
|
|
--
|
|
-- @include ./configs/audi_tt.txt
|
|
-- @include ../libs/watcher.txt
|
|
require('./engine.txt')
|
|
--
|
|
require('./clutch.txt')
|
|
--
|
|
require('./gearboxes/manual.txt')
|
|
require('./gearboxes/cvt.txt')
|
|
require('./gearboxes/auto.txt')
|
|
--
|
|
require('./differential.txt')
|
|
--
|
|
require('./configs/audi_tt.txt')
|
|
require('../libs/watcher.txt')
|
|
|
|
ECU = class('ECU')
|
|
|
|
function ECU:initialize(options)
|
|
options = options or {}
|
|
|
|
self:adjustPorts()
|
|
|
|
self.engine = options.Engine
|
|
self.clutch = options.Clutch
|
|
self.gearbox = options.Gearbox
|
|
self.differentials = options.Differentials
|
|
self.input = wire.ports.Input or nil
|
|
|
|
hook.add('tick', 'ecu_update', function()
|
|
self:update()
|
|
end)
|
|
|
|
self.shifterWatcher = watcher(function()
|
|
return self.input.Shifter.Value
|
|
end, function(val)
|
|
if self.gearbox == nil or val == 0 then
|
|
return
|
|
end
|
|
|
|
self.gearbox:shift(val)
|
|
end)
|
|
end
|
|
|
|
function ECU:adjustPorts()
|
|
wire.adjustPorts({
|
|
Input = 'table',
|
|
FL = 'entity',
|
|
FR = 'entity',
|
|
RL = 'entity',
|
|
RR = 'entity'
|
|
}, {
|
|
RPM = 'number',
|
|
Torque = 'number',
|
|
ClutchTorque = 'number',
|
|
ClutchPress = 'number',
|
|
AvgRPM = 'number',
|
|
GearboxTorque = 'number',
|
|
GearboxRPM = 'number',
|
|
GearboxRatio = 'number',
|
|
Gear = 'number',
|
|
ClutchSlip = 'number'
|
|
})
|
|
end
|
|
|
|
function ECU:update()
|
|
wire.ports.RPM = self.engine.rpm
|
|
wire.ports.Torque = self.engine.torque
|
|
wire.ports.ClutchPress = self.clutch.press
|
|
wire.ports.ClutchTorque = self.clutch.torque
|
|
wire.ports.ClutchSlip = self.clutch.slip
|
|
wire.ports.GearboxTorque = self.gearbox.torque
|
|
wire.ports.GearboxRPM = self.gearbox.rpm
|
|
wire.ports.AvgRPM = self.differentials[1].avgRPM
|
|
wire.ports.Gear = self.gearbox.gear
|
|
wire.ports.GearboxRatio = self.gearbox.ratio
|
|
|
|
self.input = wire.ports.Input
|
|
|
|
if self.input.Throttle then
|
|
self.engine:setThrottle(self.input.Throttle.Value)
|
|
end
|
|
|
|
if self.input.Clutch then
|
|
self.clutch:setPress(self.input.Clutch.Value)
|
|
end
|
|
|
|
self.engine:update()
|
|
self.clutch:update()
|
|
self.gearbox:update()
|
|
|
|
self.shifterWatcher()
|
|
|
|
for _, diff in ipairs(self.differentials) do
|
|
diff:update()
|
|
end
|
|
end
|
|
|
|
local clutch = Clutch:new(config.Clutch)
|
|
|
|
local engine = Engine:new(config.Engine)
|
|
engine:linkClutch(clutch)
|
|
|
|
local gearbox = ManualGearbox:new(config.Gearbox)
|
|
gearbox:linkClutch(clutch)
|
|
|
|
local frontDifferential = Differential:new(config.FrontDiff)
|
|
frontDifferential:linkWheels(wire.ports.FL, wire.ports.FR)
|
|
frontDifferential:linkGearbox(gearbox)
|
|
|
|
local rearDifferential = Differential:new(config.RearDiff)
|
|
rearDifferential:linkWheels(wire.ports.RL, wire.ports.RR)
|
|
rearDifferential:linkGearbox(gearbox)
|
|
|
|
local differentials = {frontDifferential, rearDifferential}
|
|
|
|
local ecu = ECU:new({
|
|
Engine = engine,
|
|
Clutch = clutch,
|
|
Differentials = differentials,
|
|
Gearbox = gearbox
|
|
})
|