-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloader.lua
85 lines (71 loc) · 3.77 KB
/
loader.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
-- loader
--
-- loader script for the mod
--
-- Copyright (c) Wopster, 2019
local directory = g_currentModDirectory
local modName = g_currentModName
g_shuttleDriveDirectionModDirectory = directory
g_shuttleDriveDirectionModName = modName
local function installSpecializations(vehicleTypeManager, specializationManager, modDirectory, modName)
g_specializationManager:addSpecialization("shuttleDriveDirection", "ShuttleDriveDirection", Utils.getFilename("ShuttleDriveDirection.lua", modDirectory), nil)
for typeName, typeEntry in pairs(vehicleTypeManager:getVehicleTypes()) do
if SpecializationUtil.hasSpecialization(Drivable, typeEntry.specializations)
and not SpecializationUtil.hasSpecialization(ShuttleDriveDirection, typeEntry.specializations) then
vehicleTypeManager:addSpecialization(typeName, modName .. ".shuttleDriveDirection")
end
end
end
local function validateVehicleTypes(vehicleTypeManager)
installSpecializations(g_vehicleTypeManager, g_specializationManager, directory, modName)
end
local function inj_actionEventAccelerate(vehicle, superFunc, actionName, inputValue, ...)
if not vehicle:isHoldingBrake() then
local spec = vehicle.spec_drivable
local axisAccelerate = MathUtil.clamp(inputValue, 0, 1) * vehicle:getShuttleDriveDirection()
spec.lastInputValues.axisAccelerate = axisAccelerate
if vehicle.getHasGuidanceSystem ~= nil and vehicle:getHasGuidanceSystem() then
local guidanceSpec = vehicle.spec_globalPositioningSystem
if guidanceSpec.guidanceSteeringIsActive then
guidanceSpec.axisAccelerate = axisAccelerate
end
end
end
end
local function inj_actionEventBrake(vehicle, superFunc, actionName, inputValue, ...)
vehicle:setIsHoldingBrake(inputValue ~= 0)
if vehicle:isHoldingBrake() and vehicle.lastSpeedReal > 0.0003 then
-- Only brake when driving faster than 0.7km/h
local spec = vehicle.spec_drivable
local shuttleDirection = vehicle:getShuttleDriveDirection()
local signAxis = MathUtil.sign(spec.axisForward)
if shuttleDirection == signAxis or not signAxis ~= 0 then
local axisBrake = MathUtil.clamp(inputValue, 0, 1) * shuttleDirection
spec.lastInputValues.axisBrake = axisBrake
end
if vehicle.getHasGuidanceSystem ~= nil and vehicle:getHasGuidanceSystem() then
local guidanceSpec = vehicle.spec_globalPositioningSystem
if guidanceSpec.guidanceSteeringIsActive then
local guidanceSignAxis = MathUtil.sign(guidanceSpec.axisForward)
if shuttleDirection == guidanceSignAxis or not guidanceSignAxis ~= 0 then
guidanceSpec.axisBrake = MathUtil.clamp(inputValue, 0, 1) * shuttleDirection
end
end
end
end
end
local function updateWheelsPhysics(vehicle, superFunc, dt, currentSpeed, acceleration, doHandbrake, stopAndGoBraking)
local spec = vehicle.spec_drivable
if not vehicle:getIsAIActive() and spec.cruiseControl.state ~= Drivable.CRUISECONTROL_STATE_OFF then
acceleration = acceleration * vehicle:getShuttleDriveDirection()
end
superFunc(vehicle, dt, currentSpeed, acceleration, doHandbrake, stopAndGoBraking)
end
local function init()
VehicleTypeManager.validateVehicleTypes = Utils.prependedFunction(VehicleTypeManager.validateVehicleTypes, validateVehicleTypes)
WheelsUtil.updateWheelsPhysics = Utils.overwrittenFunction(WheelsUtil.updateWheelsPhysics, updateWheelsPhysics)
Drivable.actionEventAccelerate = Utils.overwrittenFunction(Drivable.actionEventAccelerate, inj_actionEventAccelerate)
Drivable.actionEventBrake = Utils.overwrittenFunction(Drivable.actionEventBrake, inj_actionEventBrake)
end
init()