UPDATE
This commit is contained in:
73
koptilnya/engine_remastered/powertrain/gearboxes/manual.txt
Normal file
73
koptilnya/engine_remastered/powertrain/gearboxes/manual.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
--@include /koptilnya/libs/watcher.txt
|
||||
--@include ./base.txt
|
||||
|
||||
local BaseGearbox = require('./base.txt')
|
||||
|
||||
require('/koptilnya/libs/watcher.txt')
|
||||
|
||||
local ManualGearbox = class('ManualGearbox', BaseGearbox)
|
||||
|
||||
function ManualGearbox:initialize(vehicle, name, config)
|
||||
BaseGearbox.initialize(self, vehicle, name, config)
|
||||
|
||||
table.merge(self.wireOutputs, {
|
||||
Gearbox_Gear = 'number'
|
||||
})
|
||||
|
||||
self.ratios = config.Ratios or { 3.6, 2.2, 1.5, 1.2, 1.0, 0.8}
|
||||
self.reverse = config.Reverse or 3.4
|
||||
|
||||
self.gear = 0
|
||||
|
||||
function shiftFunc()
|
||||
local upshift = wire.ports.Upshift or 0
|
||||
local downshift = wire.ports.Downshift or 0
|
||||
|
||||
return upshift - downshift
|
||||
end
|
||||
|
||||
self.shiftWatcher = watcher(shiftFunc, function(val)
|
||||
if val ~= 0 then
|
||||
self:shift(val)
|
||||
end
|
||||
end)
|
||||
|
||||
self:recalcRatio()
|
||||
end
|
||||
|
||||
function ManualGearbox:updateWireOutputs()
|
||||
BaseGearbox.updateWireOutputs(self)
|
||||
|
||||
wire.ports.Gearbox_Gear = self.gear
|
||||
end
|
||||
|
||||
function ManualGearbox:setGear(gear)
|
||||
if gear >= -1 and gear <= #self.ratios then
|
||||
self.gear = gear
|
||||
self:recalcRatio()
|
||||
end
|
||||
end
|
||||
|
||||
function ManualGearbox:recalcRatio()
|
||||
if self.gear == -1 then
|
||||
self.ratio = -self.reverse
|
||||
elseif self.gear == 0 then
|
||||
self.ratio = 0
|
||||
else
|
||||
self.ratio = self.ratios[self.gear]
|
||||
end
|
||||
end
|
||||
|
||||
function ManualGearbox:shift(dir)
|
||||
self:setGear(self.gear + dir)
|
||||
end
|
||||
|
||||
function ManualGearbox:forwardStep(torque, inertia)
|
||||
local result = BaseGearbox.forwardStep(self, torque, inertia)
|
||||
|
||||
self.shiftWatcher()
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return ManualGearbox
|
||||
Reference in New Issue
Block a user