This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 526
/
courseplay.lua
279 lines (250 loc) · 8.29 KB
/
courseplay.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
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
--
-- Courseplay
--
-- @authors: Thomas Gärtner / Satissis / Pops64 / Pvajko
-- @version: 5.00 beta
-- @website: http://courseplay.github.io/courseplay/
-- @date: 2016
-- @history: http://courseplay.github.io/courseplay/en/changelog/index.html
--
-- Copyright (C) 2014 Courseplay Dev Team
--
-- add steady courseplay identifier to global environment
local globalEnvironment = getfenv (0);
globalEnvironment["g_courseplay"] = globalEnvironment[g_currentModName];
---@class courseplay
courseplay = {};
courseplay.path = g_currentModDirectory;
if courseplay.path:sub(-1) ~= '/' then
courseplay.path = courseplay.path .. '/';
end;
courseplay.modName = g_currentModName;
--- CoursePlay Input Context name for locking keys and mouse to the hud
courseplay.INPUT_CONTEXT_NAME = "COURSEPLAY_HUD";
-- place sub-classes here in order to get an overview of the contents of the courseplay object and allow for sub-class functions
courseplay.utils = {};
---@class courseplay.courses
courseplay.courses = {};
courseplay.settings = {};
courseplay.hud = {};
courseplay.buttons = {};
---@class courseplay.fields
courseplay.fields = {};
courseplay.generation = {};
courseplay.lights = {};
courseplay.clock = 0;
local function initialize()
local fileList = {
'CpObject',
'DevHelper',
'CpManager',
'base',
'button',
'BunkersiloManager',
'courseplay_event',
'course_management',
'courseeditor',
'CourseEditorEvent',
'clicktoswitch',
'debug',
'distance',
'fields',
'fruit',
'helpers',
'hud',
'input',
'recording',
'reverse',
'settings',
'GlobalSettings',
'ValidModeSetupHandler',
'signs',
'specialTools',
'start_stop',
'toolManager',
'triggers',
'turn',
'TrafficCollision',
'ProximitySensor',
'vehicles',
'AIDriverUtil',
'PurePursuitController',
'Waypoint',
'StateModule',
'TriggerHandler',
'TriggerSensor',
'BaleToCollect',
'AIDriver',
'CombineUnloadAIDriver',
'OverloaderAIDriver',
'CombineUnloadManager',
'GrainTransportAIDriver',
'FieldworkAIDriver',
'FillableFieldworkAIDriver',
'FieldSupplyAIDriver',
'PlowAIDriver',
'UnloadableFieldworkAIDriver',
'BaleLoaderAIDriver',
'BaleCollectorAIDriver',
'BalerAIDriver',
'BaleWrapperAIDriver',
'CombineAIDriver',
'BunkerSiloAIDriver',
'CompactingAIDriver',
'ShieldAIDriver',
'ShovelAIDriver',
'TriggerShovelAIDriver',
'BunkerSiloLoaderAIDriver',
'MixerWagonAIDriver',
'Conflict',
'AITurn',
'VehicleConfigurations',
'ActionEventsLoader',
'GlobalInfoTextHandler',
'course-generator/geo',
'course-generator/Island',
'course-generator/courseGenerator',
'course-generator/cp',
'course-generator/Genetic',
'course-generator/track',
'course-generator/center',
'course-generator/headland',
'course-generator/Vector',
'course-generator/State3D',
'course-generator/BinaryHeap',
'course-generator/Dubins',
'course-generator/HybridAStar',
'course-generator/ReedsShepp',
'course-generator/ReedsSheppSolver',
'course-generator/PathfinderUtil',
'course-generator/CourseGeneratorSettings',
'gui/CpGuiUtil',
'gui/CourseGeneratorScreen',
'gui/CoursePlot',
'gui/inputCourseNameDialogue',
'gui/AdvancedSettingsScreen',
'gui/GlobalSettingsPage',
'gui/VehicleSettingsPage',
'Events/SettingEvent',
'Events/StartStopEvent',
'Events/UnloaderEvents',
'Events/SiloSelectedFillTypeEvent',
'Events/StartStopWorkEvent',
'Events/AssignedCombinesEvents',
'Events/CourseEvent',
'Events/InfoTextEvent',
'Events/CommandEvents',
'Events/CustomFieldEvent',
'Generic/LinkedList'
};
local numFiles, numFilesLoaded = #(fileList) + 2, 2; -- + 2 as 'register.lua', 'courseplay.lua' have already been loaded
for _,file in ipairs(fileList) do
local filePath = courseplay.path .. file .. '.lua';
assert(fileExists(filePath), '\tCOURSEPLAY ERROR: could not load file ' .. filePath);
source(filePath);
--print('\t### Courseplay: ' .. filePath .. ' has been loaded');
numFilesLoaded = numFilesLoaded + 1;
end;
print(('### Courseplay: initialized %d/%d files (v%s)'):format(numFilesLoaded, numFiles, courseplay.version));
end;
local function setVersionData()
local modItem = g_modManager:getModByName(courseplay.modName)
if modItem and modItem.version then
courseplay.version = modItem.version
courseplay.versionDisplayStr = string.format("v%s",courseplay.version)
else
courseplay.version = ' [no version specified]'
courseplay.versionDisplayStr = 'no\nversion'
end
end
local function setGlobalData()
courseplay.MODE_GRAIN_TRANSPORT = 1;
courseplay.MODE_COMBI = 2;
courseplay.MODE_OVERLOADER = 3;
courseplay.MODE_SEED_FERTILIZE = 4;
courseplay.MODE_TRANSPORT = 5;
courseplay.MODE_FIELDWORK = 6;
courseplay.MODE_BALE_COLLECTOR = 7;
courseplay.MODE_FIELD_SUPPLY = 8;
courseplay.MODE_SHOVEL_FILL_AND_EMPTY = 9;
courseplay.MODE_BUNKERSILO_COMPACTER = 10;
courseplay.NUM_MODES = 10;
courseplay.MODE_DEFAULT = courseplay.MODE_TRANSPORT
------------------------------------------------------------
courseplay.SHOW_COVERS = true
courseplay.OPEN_COVERS = false
courseplay.CLOSE_COVERS = true
courseplay.RIDGEMARKER_NONE = 0
courseplay.RIDGEMARKER_LEFT = 1
courseplay.RIDGEMARKER_RIGHT = 2
-- "start at _ point" options
StartingPointSetting.START_AT_NEAREST_POINT = 1;
StartingPointSetting.START_AT_FIRST_POINT = 2;
StartingPointSetting.START_AT_CURRENT_POINT = 3;
StartingPointSetting.START_AT_NEXT_POINT = 4;
-- lights options
-- this should have a Setting Class like WarningLightsModeSetting
courseplay.lights.HEADLIGHT_OFF = 0;
courseplay.lights.HEADLIGHT_STREET = 1;
courseplay.lights.HEADLIGHT_FULL = 7;
-- number separators
local langNumData = {
br = { '.', ',' },
cs = { ',', '.' },
cz = { ' ', ',' },
de = { "'", ',' },
en = { ',', '.' },
es = { '.', ',' },
fr = { ' ', ',' },
it = { '.', ',' },
jp = { ',', '.' },
pl = { ' ', ',' },
pt = { '.', ',' },
ru = { ' ', ',' }
};
courseplay.numberSeparator = '\'';
courseplay.numberDecimalSeparator = '.';
if g_languageShort and langNumData[g_languageShort] then
courseplay.numberSeparator = langNumData[g_languageShort][1];
courseplay.numberDecimalSeparator = langNumData[g_languageShort][2];
end;
--UTF8
courseplay.allowedCharacters = courseplay:getAllowedCharacters();
courseplay.utf8normalization = courseplay:getUtf8normalization();
courseplay.multiplayerSyncTable = {
[1]={name='self.cp.canDrive',dataFormat='Bool'},
[2]={name='self.cp.drivingDirReverse',dataFormat='Bool'},
[3]={name='self.cp.isDriving',dataFormat='Bool'},
[4]={name='self.cp.hud.openWithMouse',dataFormat='Bool'},
[5]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --??
[6]={name='self.cp.hud.currentPage',dataFormat='Int'},
[7]={name='self.cp.waypointIndex',dataFormat='Int'},
[8]={name='self.cp.isRecording',dataFormat='Bool'},
[9]={name='self.cp.recordingIsPaused',dataFormat='Bool'},
}
---@type SettingsContainer
courseplay.globalSettings = SettingsContainer.createGlobalSettings()
---@type SettingsContainer
courseplay.globalCourseGeneratorSettings = SettingsContainer.createGlobalCourseGeneratorSettings()
---@type SettingsContainer
courseplay.globalPathfinderSettings = SettingsContainer.createGlobalPathfinderSettings()
end;
--------------------------------------------------------------
setVersionData();
initialize();
courseplay.inputBindings.updateInputButtonData();
setGlobalData();
local function displayDevWaring()
local maxLength = 91;
local s = {
('%-' .. maxLength .. 's'):format('You are using a development version of Courseplay, which may and will contain errors, bugs,');
('%-' .. maxLength .. 's'):format('mistakes and unfinished code. Chances are your computer will explode when using it. Twice.');
('%-' .. maxLength .. 's'):format('If you have no idea what "beta", "alpha", or "developer" means and entails, remove this');
('%-' .. maxLength .. 's'):format('version of Courseplay immediately. The Courseplay team will not take any responsibility for');
('%-' .. maxLength .. 's'):format('crop destroyed, savegames deleted or baby pandas killed.');
};
print(' ' .. ('*'):rep((maxLength - 5) * 0.5) .. ' WARNING ' .. ('*'):rep((maxLength - 5) * 0.5) .. '\n * ' .. table.concat(s, ' *\n * ') .. ' *\n ' .. ('*'):rep(maxLength + 4));
end
displayDevWaring()
--load(), update(), updateTick(), draw() are located in base.lua
--mouseEvent(), keyEvent() are located in input.lua