summaryrefslogtreecommitdiff
path: root/scripts/gear.lua
blob: bcf036103407bb7d1e741d2f5694e8eaee710b43 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
-- SLIMax Mgr Lua Script v3.2.1
-- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved.
-- gear event
-- last change by Zappadoc - 2013-09

function Ignition(gear, isFanatec)
	-- ========================================================================================
	-- IGNITION
	-- patch led function damage for ignition
	-- check if sim is rFactor2
	if GetContextInfo("simulation") == "rFactor2.exe" then
		if GetCarInfo("rpm") == 0 and GetCarInfo("rawspeed") == 0 then
			if GetCarInfo("ignition") == 0 then
				-- engine has been stopped
				-- engine has been stopped
				-- do nothing


			elseif GetCarInfo("ignition") == 1 then
				-- ignition ON after engine stop
				-- engine has been stopped, ignition ON

				SetDigitsAllowed(false)
				if isFanatec == true then
					SetFanatecDigits("   ")
				else
					SetLeftDigits  ("      ")
					SetRightDigits ("      ")
				end

				SetGearDigit("_")

				-- init led
				toggleAllLed(0)

				-- blink damage led
				if mOLDIgnitionticks == nil or GetTicks() > mOLDIgnitionticks then
					 mOLDIgnitionticks  = GetTicks() + 1000
					 initLedTable(mRPMLedTable, 1)

					SetWarnLed(GetLedIndex("damage"), 1)

				else
					initLedTable(mRPMLedTable, 0)
					SetWarnLed(GetLedIndex("damage"), 0)
				end
				SetRPMLed("mRPMLedTable")
				SLISendReport()
				return 1

			elseif GetCarInfo("ignition") == 2 and GetCarInfo("rpm") == 0 and GetCarInfo("rawspeed") == 0 then
				-- ignition ON and starter ON
				-- engine has been stopped, ignition ON + Starter ON

				SetGearDigit("-")
				SetDigitsAllowed(true)
				-- stop blinking
				initLedTable(mRPMLedTable, 1)
				SetWarnLed(GetLedIndex("damage"), 1)
				SetRPMLed("mRPMLedTable")
				SLISendReport()
				return 1
			end
		end
	end
	return 2
end

-- SIM RACE Deluxe, SIM RACE F1, SLI-M, SLI-PRO Gear Event
function gearEvent(gear)
	-- get the rpm limit already computed by my OSP method
	-- using OSP Factor parameter
	-- value used in OSP, Shiftlights, car setup,... and can be overwritten
	gOSPLimit = 0
	gOSPLimit = GetContextInfo("osplimitrpm")
	if gOSPLimit == nil then gOSPLimit = 0 end

	-- get the red zone already computed by my SLIMax Mgr II
	-- value used in Shiftlights and can be overwritten
	gRedZone = 0
	gRedZone = GetCarInfo("redzone")
	if gRedZone == nil then gRedZone = 18000 end

	-- call custom script
	local result = custom_gearEvent(gear)
	if result <= 1 then return result end

	-- call global custom script
	result = global_custom_gearEvent(gear)
	if result <= 1 then return result end

	-- ignition
	if Ignition(gear, false) <= 1 then return 1 end

	local g = gear
	if oldGear == nil then oldGear = -1 end

	-- get neutral
	local n = GetContextInfo("neutral")
	-- get reverse char and convert to string
	local r = string.char(GetContextInfo("reverse"))
	-- get state of custom Optimal Shift Point (OSP) records
	local ospcustom_on = GetContextInfo("ospcustom")

	-- optimize display, call if changed
	if oldGear ~= g then
		-- backup gear state
		oldGear = g
		-- set neutral, reverse or current gear
		if g == 0 then
			-- if neutral and using custom OSP record then add a dot to gear digit
			if ospcustom_on  then n = n + 128 end
			SetGearDigit(string.char(n))
		elseif g < 0 then
			SetGearDigit(r)
		else
			-- if gear = 'E' give the hand to SLIMax Manager
			if g == 69 then
				return 0
			end
			SetGearDigit(string.char(g))
		end
	end

	return 1
end


-- Fanatec Gear Event
function gearFanatecEvent(gear)
	-- get the rpm limit already computed by my OSP method
	-- using OSP Factor parameter
	-- value used in OSP, Shiftlights, car setup,... and can be overwritten
	gOSPLimit = 0
	gOSPLimit = GetContextInfo("osplimitrpm")
	if gOSPLimit == nil then gOSPLimit = 0 end

	-- get the red zone already computed by my SLIMax Mgr
	-- value used in Shiftlights and can be overwritten
	gRedZone = 0
	gRedZone = GetCarInfo("redzone")
	if gRedZone == nil then gRedZone = 18000 end

	-- call custom script
	local result = custom_gearFanatecEvent(gear)
	if result <= 1 then return result end

	-- call global custom script
	result = global_custom_gearFanatecEvent(gear)
	if result <= 1 then return result end

	-- ignition
	if Ignition(gear, true) <= 1 then return 1 end

	local g = gear
	if oldGear == nil then oldGear = -1 end

	if oldGear ~= g then
		local rumbbleGear = GetContextInfo("gearshock")
		local rumbbleGearDelay = GetContextInfo("gearshockdelay")

		-- gear schock effect restricted to 1 to 7
		if rumbbleGear and g > 0 then
			if g < oldGear then
				SetFanatecWheelMotor(0, 100, rumbbleGearDelay)
			elseif g > oldGear then
				SetFanatecWheelMotor(1, 100, rumbbleGearDelay)
			end
		end

		-- backup gear state
		oldGear = g
	end

	return 2
end