-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_pmps.lua
More file actions
436 lines (411 loc) · 16.3 KB
/
setup_pmps.lua
File metadata and controls
436 lines (411 loc) · 16.3 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
-- Powered mass point setup module (name subject to change)
-- This module reads vehicle type definitions from JSON files: a type is composed of a powered mass point set, and a set of global tag properties
-- TODO: Export the object functions, they will come in handy.
-- Also, add a way to read and validate Type definitions from files, and add exception handling for invalid Type definitions at "import_types()"
local module = {}
local system_utilities = require("./system_utilities")
local dkjson = require("./lib/dkjson/dkjson")
function module.import_types()
-- Reads all the Type JSON files from the designated types directory
local types = {}
local types_root_path = system_utilities.generate_path("./types")
local type_list
if not system_utilities.is_valid_path(types_root_path) then
print("error: invalid JSON types directory (missing or inaccessible \"types\" folder)")
return
end
type_list = system_utilities.get_json_files_in_dir(types_root_path)
for _, v in pairs(type_list) do
local path = system_utilities.generate_path(types_root_path, "/", v, ".json")
local file = io.open(path)
local content
local object
if not file then
print("error: failed to import type file \""..path.."\"")
else
content = file:read("*a")
file:close()
-- TODO: call "decode_type" instead of dkjson's decode
object = dkjson.decode(content)
-- "v" is the type and file name without the JSON extension, so the Type object is stored at key [Type name]
types[v] = object
end
end
return types
end
function module.export_standard_types()
local standard_types = module.get_standard_types()
for _, v in pairs(standard_types) do
local json = module.encode_type(v)
local name = v.name
local path = system_utilities.generate_path("./types/", name, ".json")
local file = io.open(path, "w")
if not file then
print("error: failed to export type file \""..path.."\"")
else
file:write(json)
file:close()
end
end
end
function module.decode_type(type_json_string)
-- Takes a string for argument, just a type definition JSON string straight from a JSON file
local type = dkjson.decode(type_json_string)
-- TODO: here, check that the JSON matches a Type definition, and check that each PoweredMassPoint table matches a PoweredMassPoint definition
return type
end
function module.encode_type(type)
-- "type" is the object table to be encoded in a string in JSON notation
-- indent adds line breaks and indentations so the output JSON is human-readable, easily editable, and not a bunch of gibberish
-- keyorder is self-explanatory. This order is based on the tag-structure, though some keys are arbitrarily defined to account for nested table ordering
local json = dkjson.encode(type, {
indent = true,
keyorder = {
-- Type
"name",
"properties",
"pmps",
-- Powered Mass Point (arbitrary)
"flags",
-- Properties
"radius",
"moment_scale",
"mass",
"density",
"gravity_scale",
"ground_friction",
"ground_depth",
"ground_damp_fraction",
"ground_normal_k1",
"ground_normal_k0",
"water_friction",
"water_depth",
"water_density",
"air_friction",
-- Powered Mass Point
"water_lift",
"air_lift",
"thrust",
"antigrav",
"antigrav_strength",
"antigrav_offset",
"antigrav_height",
"antigrav_damp_fraction",
"antigrav_normal_k1",
"antigrav_normal_k0"
}
})
return json
end
function module.get_standard_types()
return {
-- TODO: make all of these part of the "module" table, and update their references, and remove their "exporter" functions
HumanTankType(),
HumanJeepType(),
HumanBoatType(),
HumanPlaneType(),
AlienScoutType(),
AlienFighterType(),
TurretType()
}
end
function module.Type()
return Type()
end
function module.Properties()
return Properties()
end
function module.PoweredMassPoint()
return PoweredMassPoint()
end
function Type()
local type = {}
type.name = ""
type.properties = Properties()
type.pmps = {}
return type
end
function Properties()
local properties = {}
properties.radius = 0
properties.moment_scale = 0
properties.mass = 0
-- * center_of_mass is geometry dependent
properties.density = 0
properties.gravity_scale = 0
properties.ground_friction = 0
properties.ground_depth = 0
properties.ground_damp_fraction = 0
properties.ground_normal_k1 = 0
properties.ground_normal_k0 = 0
properties.water_friction = 0
properties.water_depth = 0
properties.water_density = 0
properties.air_friction = 0
-- * xx_moment is geometry dependent
-- * yy_moment is geometry dependent
-- * zz_moment is geometry dependent
return properties
end
function PoweredMassPoint()
local pmp = {}
pmp.name = ""
pmp.flags = {}
pmp.flags.ground_friction = 0
pmp.flags.water_friction = 0
pmp.flags.air_friction = 0
pmp.flags.water_lift = 0
pmp.flags.air_lift = 0
pmp.flags.thrust = 0
pmp.flags.antigrav = 0
pmp.antigrav_strength = 0
pmp.antigrav_offset = 0
pmp.antigrav_height = 0
pmp.antigrav_damp_fraction = 0
pmp.antigrav_normal_k1 = 0
pmp.antigrav_normal_k0 = 0
return pmp
end
-- SCORPION
function HumanTankType()
local human_tank = Type()
human_tank.name = "human tank"
human_tank.properties.radius = -1
human_tank.properties.moment_scale = 1
human_tank.properties.mass = 20000
human_tank.properties.density = 8
human_tank.properties.gravity_scale = 1
human_tank.properties.ground_friction = 0.2
human_tank.properties.ground_depth = 0.25
human_tank.properties.ground_damp_fraction = 0.05
human_tank.properties.ground_normal_k1 = 0.707107
human_tank.properties.ground_normal_k0 = 0.5
human_tank.properties.water_friction = 0.05
human_tank.properties.water_depth = 0.25
human_tank.properties.water_density = 1
human_tank.properties.air_friction = 0.001
human_tank.pmps[0] = PoweredMassPoint()
human_tank.pmps[1] = PoweredMassPoint()
local front = human_tank.pmps[0]
local back = human_tank.pmps[1]
front.name = "left"
front.flags.ground_friction = 1
back.name = "right"
back.flags.ground_friction = 1
return human_tank
end
-- WARTHOG / ROCKET WARTHOG
function HumanJeepType()
local human_jeep = Type()
human_jeep.name = "human jeep"
human_jeep.properties.radius = -1
human_jeep.properties.moment_scale = 1
human_jeep.properties.mass = 5000
human_jeep.properties.density = 5
human_jeep.properties.gravity_scale = 1
human_jeep.properties.ground_friction = 0.23
human_jeep.properties.ground_depth = 0.15
human_jeep.properties.ground_damp_fraction = 0.05
human_jeep.properties.ground_normal_k1 = 0.707107
human_jeep.properties.ground_normal_k0 = 0.5
human_jeep.properties.water_friction = 0.05
human_jeep.properties.water_depth = 0.25
human_jeep.properties.water_density = 1
human_jeep.properties.air_friction = 0.005
human_jeep.pmps[0] = PoweredMassPoint()
human_jeep.pmps[1] = PoweredMassPoint()
local front = human_jeep.pmps[0]
local back = human_jeep.pmps[1]
front.name = "front"
front.flags.ground_friction = 1
back.name = "back"
back.flags.ground_friction = 1
return human_jeep
end
-- I still don't know the behavior difference between these PMPs, I just know they are set up like this, otherwise -THEY JUST DON'T WORK- at all
-- Maybe controls are inverted in the 'back' hydrofoil, like the 'back' wheels of the warthog are
-- DOOZY
function HumanBoatType()
local human_boat = Type()
human_boat.name = "human boat"
human_boat.properties.radius = -1
human_boat.properties.moment_scale = 1
human_boat.properties.mass = 2500
human_boat.properties.density = 0.5
human_boat.properties.gravity_scale = 1
human_boat.properties.ground_friction = 0.2
human_boat.properties.ground_depth = 0.2
human_boat.properties.ground_damp_fraction = 0.05
human_boat.properties.ground_normal_k1 = 0.707107
human_boat.properties.ground_normal_k0 = 0.5
human_boat.properties.water_friction = 0.05
human_boat.properties.water_depth = 0.2
human_boat.properties.water_density = 1
human_boat.properties.air_friction = 0.001
human_boat.pmps[0] = PoweredMassPoint()
human_boat.pmps[1] = PoweredMassPoint()
human_boat.pmps[2] = PoweredMassPoint()
local hydrofoil_plus_propellor = human_boat.pmps[0]
local hydrofoil_front = human_boat.pmps[1]
local hydrofoil_back = human_boat.pmps[2]
hydrofoil_plus_propellor.name = "hydrofoil + propellor"
hydrofoil_plus_propellor.flags.water_friction = 1
hydrofoil_plus_propellor.flags.water_lift = 1
hydrofoil_front.name = "hydrofoil (front)"
hydrofoil_front.flags.water_lift = 1
hydrofoil_back.name = "hydrofoil (back)"
hydrofoil_back.flags.water_lift = 1
return human_boat
end
-- Human plane maneuverability is controlled through friction types and parallel/perpendicular scales in MPs, PMPs are ignored by this vehicle type
-- PELICAN / COVENANT DROPSHIP (BOTH USE THE SAME VALUES AND MASS POINTS; NONE)
function HumanPlaneType()
local human_plane = Type()
human_plane.name = "human plane"
human_plane.properties.radius = 4
human_plane.properties.moment_scale = 0.3
human_plane.properties.mass = 10000
human_plane.properties.density = 4
human_plane.properties.gravity_scale = 1
human_plane.properties.ground_friction = 0.2
human_plane.properties.ground_depth = 0.2
human_plane.properties.ground_damp_fraction = 0.05
human_plane.properties.ground_normal_k1 = 0.707107
human_plane.properties.ground_normal_k0 = 0.5
human_plane.properties.water_friction = 0.05
human_plane.properties.water_depth = 0.25
human_plane.properties.water_density = 1
human_plane.properties.air_friction = 0.02
return human_plane
end
-- TODO: This type... I don't know what I will do with it; it can have up to the 32 PMP limit count, but I haven't experimented that much with what each PMP after index 7 does
-- Maybe just limit this type to 2 PMPs, just in case the developer wants to create a front/back 'leaning' vehicle when in the air
-- * this matches the PMP pattern of all vanilla hovering vehicles: two PMPs, one for frontal "strong" antigravity, and one for the sides or the back "weak" antigravity
-- * unlike ground and water vehicles' PMPs, these PMPs operate exactly the same regardless of their index/position in the tag
-- * this allows having multiple antigravity intensities: one for each PMP
-- There are 3 possible "hover" vehicles: ghost, wraith and banshee. Each one has unique values, though they do not differ much. This template is based off the ghost
-- ... And... I still don't know what "antigrav offset" does. Tried tweaking it on the ghost, using values from -5000 to 5000 and no difference
-- GHOST
function AlienScoutType()
local alien_scout = Type()
alien_scout.name = "alien scout"
alien_scout.properties.radius = -1
alien_scout.properties.moment_scale = 1
alien_scout.properties.mass = 2000
alien_scout.properties.density = 3
alien_scout.properties.gravity_scale = 1
alien_scout.properties.ground_friction = 0.2
alien_scout.properties.ground_depth = 0.15
alien_scout.properties.ground_damp_fraction = 0.05
alien_scout.properties.ground_normal_k1 = 0.707107
alien_scout.properties.ground_normal_k0 = 0.5
alien_scout.properties.water_friction = 0.05
alien_scout.properties.water_depth = 0.25
alien_scout.properties.water_density = 1
alien_scout.properties.air_friction = 0.0025
alien_scout.pmps[0] = PoweredMassPoint()
alien_scout.pmps[1] = PoweredMassPoint()
local primary_antigravity = alien_scout.pmps[0]
local secondary_antigravity = alien_scout.pmps[1]
primary_antigravity.name = "primary antigravity"
secondary_antigravity.name = "secondary antigravity"
primary_antigravity.flags.antigrav = 1
primary_antigravity.antigrav_strength = 1.5
primary_antigravity.antigrav_height = 0.75
primary_antigravity.antigrav_damp_fraction = 0.02
primary_antigravity.antigrav_normal_k0 = 0.5
primary_antigravity.antigrav_normal_k1 = 0.258819
secondary_antigravity.flags.antigrav = 1
secondary_antigravity.antigrav_strength = 1.5
secondary_antigravity.antigrav_height = 0.75
secondary_antigravity.antigrav_damp_fraction = 0.02
secondary_antigravity.antigrav_normal_k0 = 0.5
secondary_antigravity.antigrav_normal_k1 = 0.258819
return alien_scout
end
-- TODO: This type... Maybe create a command line argument for primary and secondary antigravity PMPs, exclusive for 'alien scout' and 'alien fighter' types (check if antigravity affects 'human plane' types, because it doesn't affect land vehicle types)
-- Too much hassle, I will literally copy the PMP values and definitions, and let the user customize those values as necessary in the physics tag
-- Reduce the number of "antigravity PMPs" to two, and have command line options to customize their strength and other parameters, I guess... Both in the ghost, banshee, and wraith
-- In this type, there must be only 2 PMPs: they only affect antigravity
-- BANSHEE
function AlienFighterType()
local alien_fighter = Type()
alien_fighter.name = "alien fighter"
alien_fighter.properties.radius = -1
alien_fighter.properties.moment_scale = 1
alien_fighter.properties.mass = 4000
alien_fighter.properties.density = 4
alien_fighter.properties.gravity_scale = 1
alien_fighter.properties.ground_friction = 0.2
alien_fighter.properties.ground_depth = 0.15
alien_fighter.properties.ground_damp_fraction = 0.05
alien_fighter.properties.ground_normal_k1 = 0.707107
alien_fighter.properties.ground_normal_k0 = 0.5
alien_fighter.properties.water_friction = 0.05
alien_fighter.properties.water_depth = 0.25
alien_fighter.properties.water_density = 1
alien_fighter.properties.air_friction = 0.005
alien_fighter.pmps[0] = PoweredMassPoint()
alien_fighter.pmps[1] = PoweredMassPoint()
local primary_antigravity = alien_fighter.pmps[0]
local secondary_antigravity = alien_fighter.pmps[1]
primary_antigravity.name = "primary antigravity"
secondary_antigravity.name = "secondary antigravity"
primary_antigravity.flags.antigrav = 1
primary_antigravity.antigrav_strength = 1
primary_antigravity.antigrav_height = 0.75
primary_antigravity.antigrav_damp_fraction = 0.01
primary_antigravity.antigrav_normal_k0 = 0.1
primary_antigravity.antigrav_normal_k1 = 0
secondary_antigravity.flags.antigrav = 1
secondary_antigravity.antigrav_strength = 1
secondary_antigravity.antigrav_height = 0.25
secondary_antigravity.antigrav_damp_fraction = 0.01
secondary_antigravity.antigrav_normal_k0 = 0.1
secondary_antigravity.antigrav_normal_k1 = 0
return alien_fighter
end
-- TODO: I may create a "sharp alien hover" vehicle now that I confirmed how antigrav damp fraction, and antigrav normal k1 and k0 work: the same as ground variables do
-- * normal k1 (static friction) is cos(x) where x = max angle of slope (at which the vehicle cannot start moving)
-- * normal k0 (dynamic friction)is cos(x) where x = max angle of slope (at which the vehicle cannot keep moving, even when having speed inertia, once static friction has been broken)
-- * hence, if k1 > k0, the vehicle cannot move at all, because it cannot break static friction first [is it? k0 angles are greater than k1's]
-- This vehicle is kind of a mystery. I haven't tested it, but I suppose it is hard-coded to be impossible to drive. Unless... (it is assigned proper animations, and given a proper physics tag, maybe?)
-- But for the time being, I'm just pasting it here for compatibility purposes: to make a "fixed" turret, just abstain from assigning a physics tag to it in the vehicle tag
-- (SINGLE-PLAYER DEFAULT COVENANT GUN) TURRET
function TurretType()
local turret = Type()
turret.name = "turret"
turret.properties.radius = -1
turret.properties.moment_scale = 1
turret.properties.mass = 2000
turret.properties.density = 6
turret.properties.gravity_scale = 1
turret.properties.ground_friction = 0.2
turret.properties.ground_depth = 0.15
turret.properties.ground_damp_fraction = 0.05
turret.properties.ground_normal_k1 = 0.707107
turret.properties.ground_normal_k0 = 0.5
turret.properties.water_friction = 0.05
turret.properties.water_depth = 0.25
turret.properties.water_density = 1
turret.properties.air_friction = 0.001
turret.pmps[0] = PoweredMassPoint()
turret.pmps[1] = PoweredMassPoint()
local front = turret.pmps[0]
local back = turret.pmps[1]
front.name = "front"
front.flags.ground_friction = 1
back.name = "back"
back.flags.ground_friction = 1
return turret
end
--[[
human tank
human jeep
human boat
human plane
alien scout
alien fighter
turret
--]]
return module