Finished manual gearbox
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
Gearbox = class("Gearbox")
|
||||
-- @include ../../libs/table.txt
|
||||
require('../../libs/table.txt')
|
||||
|
||||
Gearbox = class('Gearbox')
|
||||
|
||||
function Gearbox:initialize(options)
|
||||
options = options or {}
|
||||
@@ -7,8 +10,13 @@ function Gearbox:initialize(options)
|
||||
self.finalDrive = options.FinalDrive
|
||||
self.reverse = options.Reverse
|
||||
|
||||
self.rpm = 0
|
||||
self.gear = 0
|
||||
|
||||
self:recalcRatio()
|
||||
|
||||
self.torque = 0
|
||||
|
||||
self._linkedDiffs = {}
|
||||
self._clutch = nil
|
||||
end
|
||||
@@ -18,12 +26,23 @@ function Gearbox:linkDiff(diff)
|
||||
end
|
||||
|
||||
function Gearbox:shift(dir)
|
||||
|
||||
self:setGear(self.gear + dir)
|
||||
end
|
||||
|
||||
function Gearbox:setGear(gear)
|
||||
if gear >= -1 and gear <= #self.ratios then
|
||||
self.gear = gear
|
||||
self:recalcRatio()
|
||||
end
|
||||
end
|
||||
|
||||
function Gearbox: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
|
||||
|
||||
@@ -33,5 +52,15 @@ function Gearbox:linkClutch(clutch)
|
||||
end
|
||||
|
||||
function Gearbox:update()
|
||||
if self._clutch ~= nil then
|
||||
self.torque = self._clutch.torque * self.ratio * self.finalDrive
|
||||
end
|
||||
|
||||
local axlesRPM = table.map(self._linkedDiffs, function(diff)
|
||||
return diff.avgRPM
|
||||
end)
|
||||
|
||||
local maxAxlesRPM = math.max(unpack(axlesRPM))
|
||||
|
||||
self.rpm = maxAxlesRPM * self.finalDrive * self.ratio
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user