-- Core components -- -- @include ./engine.txt -- @include ./clutch.txt -- @include ./differential.txt -- @include ./novojiloff_diff.txt -- -- Helpers & stuff -- @include ./factories/gearbox.txt -- @include /koptilnya/libs/table.txt -- @include /koptilnya/libs/constants.txt require('./engine.txt') require('./clutch.txt') --require('./differential.txt') require('./novojiloff_diff.txt') require('./factories/gearbox.txt') require('/koptilnya/libs/table.txt') require('/koptilnya/libs/constants.txt') Vehicle = class('Vehicle') function Vehicle:initialize(config) -- should probably validate config here if config == nil then throw('Vehicle config not provided') end self.clutch = Clutch:new(config.Clutch) self.engine = Engine:new(config.Engine, self.clutch) local axleOrder = 0 self.axles = table.map(config.Axles, function(config) axleOrder = axleOrder + 1 return Differential:new(config, axleOrder) end) self.gearbox = GearboxFactory.create(config.Gearbox, self.clutch, self.axles) -- self.systems = table.map(config.Systems, function(config) -- return SystemsFactory.create(config) -- end)s self.components = {self.clutch, self.gearbox} self.components = table.add(self.components, self.axles) self.components = table.add(self.components, {self.gearbox, self.clutch, self.engine}) -- self.components = table.add(self.components, self.systems) local inputs = { Base = "entity" } local outputs = {} for _, comp in ipairs(self.components) do inputs = table.merge(inputs, comp:getInputs()) outputs = table.merge(outputs, comp:getOutputs()) end wire.adjustPorts(inputs, outputs) hook.add('tick', 'vehicle_update', function() local base = wire.ports.Base for _, comp in pairs(self.components) do comp:update() comp:updateOutputs() end if isValid(base) and (self.clutch:getPress() == 1 or self.gearbox.ratio == 0) then local tiltForce = self.engine.torque * (-1 + self.engine.masterThrottle * 2) base:applyForceOffset(base:getUp() * tiltForce, base:getMassCenter() + base:getRight() * UNITS_PER_METER) base:applyForceOffset(-base:getUp() * tiltForce, base:getMassCenter() - base:getRight() * UNITS_PER_METER) end end) end