-
Notifications
You must be signed in to change notification settings - Fork 0
/
gearbox.py
293 lines (254 loc) · 7.72 KB
/
gearbox.py
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import pyautogui
from threading import Thread
pyautogui.FAILSAFE = False
keys = ["s", "x", "i"]
try:
with open("controls.txt") as fp:
for i, line in enumerate(fp):
if 1 <= i <= 3:
line = line.split()
keys[i - 1] = line[0]
except:
pass
def get_gear(acceleration, brake, gear, rpm, redline, max_gears, vehicle_model):
if vehicle_model == b"FZ5":
if acceleration < 0.2:
rpm_set = 2000
elif acceleration < 0.4:
rpm_set = 2400
elif acceleration < 0.6:
rpm_set = 2800
elif acceleration < 0.7:
rpm_set = 3200
elif acceleration < 0.8:
rpm_set = 3700
elif acceleration < 0.9:
rpm_set = 4500
elif acceleration < 0.95:
rpm_set = 5000
elif acceleration > 0.94:
rpm_set = 6200
else:
rpm_set = 2000
if brake > 0.95:
rpm_set = rpm_set + 3500
elif brake > 0.8:
rpm_set = rpm_set + 2000
elif brake > 0.5:
rpm_set = rpm_set + 1000
if rpm_set > 6200:
rpm_set = 6200
if rpm < rpm_set - 3000:
gear_to_be = gear - 3
elif rpm < rpm_set - 2000:
gear_to_be = gear - 2
elif rpm < rpm_set - 1000:
gear_to_be = gear - 1
elif rpm > rpm_set + 1600:
gear_to_be = gear + 1
else:
gear_to_be = gear
elif vehicle_model == b'\xb6i\xbd' or vehicle_model == b'K\xd2c' or vehicle_model == b'*\x8f-': # Luxury Sedan and UF pickup
if 0.05 < acceleration < 0.2:
rpm_set = 1800
elif acceleration < 0.4:
rpm_set = 2100
elif acceleration < 0.6:
rpm_set = 2400
elif acceleration < 0.7:
rpm_set = 2800
elif acceleration < 0.8:
rpm_set = 3300
elif acceleration < 0.9:
rpm_set = 3900
elif acceleration < 0.95:
rpm_set = 4400
elif acceleration > 0.94:
rpm_set = 5300
else:
rpm_set = 2000
if brake > 0.95:
rpm_set = rpm_set + 3700
elif brake > 0.8:
rpm_set = rpm_set + 3000
elif brake > 0.5:
rpm_set = rpm_set + 2000
if rpm_set > 5500:
rpm_set = 5500
if rpm < rpm_set - 2700:
gear_to_be = gear - 3
elif rpm < rpm_set - 2000:
gear_to_be = gear - 2
elif rpm < rpm_set - 1000:
gear_to_be = gear - 1
elif rpm > rpm_set + 950:
gear_to_be = gear + 1
else:
gear_to_be = gear
elif vehicle_model == b'\x98a\x10': # Karobus
if 0.05 < acceleration < 0.2:
rpm_set = 1000
elif acceleration < 0.4:
rpm_set = 1300
elif acceleration < 0.6:
rpm_set = 1400
elif acceleration < 0.7:
rpm_set = 1600
elif acceleration < 0.8:
rpm_set = 1800
elif acceleration < 0.9:
rpm_set = 1900
elif acceleration < 0.95:
rpm_set = 2000
elif acceleration > 0.94:
rpm_set = 2150
else:
rpm_set = 2000
if brake > 0.95:
rpm_set = rpm_set + 700
elif brake > 0.8:
rpm_set = rpm_set + 600
elif brake > 0.5:
rpm_set = rpm_set + 400
if rpm_set > 2150:
rpm_set = 2150
if acceleration > 0.1:
if rpm < rpm_set - 800:
gear_to_be = gear - 1
elif rpm > rpm_set + 50:
gear_to_be = gear + 1
else:
gear_to_be = gear
else:
if rpm < rpm_set - 100:
gear_to_be = gear - 1
elif rpm > rpm_set + 50:
gear_to_be = gear + 1
else:
gear_to_be = gear
elif vehicle_model == b'\xac\xb1\xb0': # Faik Topo
if 0.05 < acceleration < 0.2:
rpm_set = 2200
elif acceleration < 0.4:
rpm_set = 2400
elif acceleration < 0.6:
rpm_set = 2600
elif acceleration < 0.7:
rpm_set = 3000
elif acceleration < 0.8:
rpm_set = 3200
elif acceleration < 0.9:
rpm_set = 3600
elif acceleration < 0.95:
rpm_set = 4100
elif acceleration > 0.94:
rpm_set = 4700
else:
rpm_set = 3000
if brake > 0.95:
rpm_set = rpm_set + 3700
elif brake > 0.8:
rpm_set = rpm_set + 3000
elif brake > 0.5:
rpm_set = rpm_set + 2000
if rpm_set > 5100:
rpm_set = 5100
if rpm < rpm_set - 3200:
gear_to_be = gear - 3
elif rpm < rpm_set - 2800:
gear_to_be = gear - 2
elif rpm < rpm_set - 2000:
gear_to_be = gear - 1
elif rpm > rpm_set + 400:
gear_to_be = gear + 1
else:
gear_to_be = gear
elif vehicle_model == b'>\x8c\x88': # Bumer 7
if 0.05 < acceleration < 0.2:
rpm_set = 2200
elif acceleration < 0.4:
rpm_set = 2400
elif acceleration < 0.6:
rpm_set = 2800
elif acceleration < 0.7:
rpm_set = 3200
elif acceleration < 0.8:
rpm_set = 3600
elif acceleration < 0.9:
rpm_set = 4000
elif acceleration < 0.95:
rpm_set = 4500
elif acceleration > 0.94:
rpm_set = 5000
else:
rpm_set = 3000
if brake > 0.95:
rpm_set = rpm_set + 3700
elif brake > 0.8:
rpm_set = rpm_set + 3000
elif brake > 0.5:
rpm_set = rpm_set + 2000
if rpm_set > 5100:
rpm_set = 5100
if rpm < rpm_set - 3200:
gear_to_be = gear - 3
elif rpm < rpm_set - 2800:
gear_to_be = gear - 2
elif rpm < rpm_set - 2000:
gear_to_be = gear - 1
elif rpm > rpm_set + 600:
gear_to_be = gear + 1
else:
gear_to_be = gear
if gear_to_be < 2:
gear_to_be = 2
if gear_to_be > max_gears + 1:
gear_to_be = max_gears + 1
return gear_to_be
def shift_up():
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
pyautogui.keyDown(keys[0])
pyautogui.keyUp(keys[0])
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
def shift_down():
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
pyautogui.keyDown(keys[1])
pyautogui.keyUp(keys[1])
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
def shift_down2():
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
pyautogui.keyDown(keys[1])
pyautogui.keyUp(keys[1])
pyautogui.keyDown(keys[1])
pyautogui.keyUp(keys[1])
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
def shift_down3():
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
pyautogui.keyDown(keys[1])
pyautogui.keyUp(keys[1])
pyautogui.keyDown(keys[1])
pyautogui.keyUp(keys[1])
pyautogui.keyDown(keys[1])
pyautogui.keyUp(keys[1])
pyautogui.keyDown(keys[2])
pyautogui.keyUp(keys[2])
def shift(gear, own_gear, acc, steer):
if own_gear > gear + 2:
thread_shiftd = Thread(target=shift_down3)
thread_shiftd.start()
elif own_gear > gear + 1:
thread_shiftd = Thread(target=shift_down2)
thread_shiftd.start()
elif own_gear > gear:
thread_shiftd = Thread(target=shift_down)
thread_shiftd.start()
elif own_gear < gear and acc > 0 and -800 <= steer <= 800:
thread_shiftd = Thread(target=shift_up)
thread_shiftd.start()