forked from pioneerspacesim/pioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LuaSystemBody.cpp
664 lines (621 loc) · 12.9 KB
/
LuaSystemBody.cpp
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
// Copyright © 2008-2018 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "LuaObject.h"
#include "LuaUtils.h"
#include "EnumStrings.h"
#include "Pi.h"
#include "galaxy/Galaxy.h"
#include "galaxy/StarSystem.h"
#include "Game.h"
/*
* Class: SystemBody
*
* Class representing a system body.
*
* <SystemBody> differs from <Body> in that it holds the properties that are
* used to generate the physics <body> that is created when the player enters
* a system. It exists outside of the current space. That is, scripts can use
* a <SystemBody> to discover information about a body that exists in another
* system.
*/
/*
* Attribute: index
*
* The body index of the body in its system
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_sbody_attr_index(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushinteger(l, sbody->GetPath().bodyIndex);
return 1;
}
/*
* Attribute: name
*
* The name of the body
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_sbody_attr_name(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushstring(l, sbody->GetName().c_str());
return 1;
}
/*
* Attribute: type
*
* The type of the body, as a <Constants.BodyType> constant
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_sbody_attr_type(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushstring(l, EnumStrings::GetString("BodyType", sbody->GetType()));
return 1;
}
/*
* Attribute: superType
*
* The supertype of the body, as a <Constants.BodySuperType> constant
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_sbody_attr_super_type(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushstring(l, EnumStrings::GetString("BodySuperType", sbody->GetSuperType()));
return 1;
}
/*
* Attribute: seed
*
* The random seed used to generate this <SystemBody>. This is guaranteed to
* be the same for this body across runs of the same build of the game, and
* should be used to seed a <Rand> object when you want to ensure the same
* random numbers come out each time.
*
* This value is the same is the one available via <Body.seed> once you enter
* this system.
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_sbody_attr_seed(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushinteger(l, sbody->GetSeed());
return 1;
}
/*
* Attribute: parent
*
* The parent of the body, as a <SystemBody>. A body orbits its parent.
*
* Availability:
*
* alpha 14
*
* Status:
*
* stable
*/
static int l_sbody_attr_parent(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
// sbody->parent is 0 as it was cleared by the acquirer. we need to go
// back to the starsystem proper to get what we need.
RefCountedPtr<StarSystem> s = Pi::game->GetGalaxy()->GetStarSystem(sbody->GetPath());
SystemBody *live_sbody = s->GetBodyByPath(sbody->GetPath());
if (!live_sbody->GetParent())
return 0;
LuaObject<SystemBody>::PushToLua(live_sbody->GetParent());
return 1;
}
/*
* Attribute: population
*
* The population of the body, in billions of people.
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_population(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetPopulation());
return 1;
}
/*
* Attribute: radius
*
* The radius of the body, in metres (m).
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_radius(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetRadius());
return 1;
}
/*
* Attribute: mass
*
* The mass of the body, in kilograms (kg).
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_mass(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetMass());
return 1;
}
/*
* Attribute: gravity
*
* The gravity on the surface of the body (m/s).
*
* Availability:
*
* alpha 21
*
* Status:
*
* experimental
*/
static int l_sbody_attr_gravity(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->CalcSurfaceGravity());
return 1;
}
/*
* Attribute: periapsis
*
* The periapsis of the body's orbit, in metres (m).
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_periapsis(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetOrbMin()*AU);
return 1;
}
/*
* Attribute: apoapsis
*
* The apoapsis of the body's orbit, in metres (m).
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_apoapsis(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetOrbMax()*AU);
return 1;
}
/*
* Attribute: orbitPeriod
*
* The orbit of the body, around its parent, in days, as a float
*
* Availability:
*
* 201708
*
* Status:
*
* experimental
*/
static int l_sbody_attr_orbital_period(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetOrbit().Period() / float(60*60*24));
return 1;
}
/*
* Attribute: rotationPeriod
*
* The rotation period of the body, in days
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_rotation_period(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetRotationPeriodInDays());
return 1;
}
/*
* Attribute: semiMajorAxis
*
* The semi-major axis of the orbit, in metres (m).
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_semi_major_axis(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetSemiMajorAxis()*AU);
return 1;
}
/*
* Attribute: eccentricity
*
* The orbital eccentricity of the body
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_eccentricty(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetEccentricity());
return 1;
}
/*
* Attribute: axialTilt
*
* The axial tilt of the body, in radians
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_axial_tilt(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetAxialTilt());
return 1;
}
/*
* Attribute: averageTemp
*
* The average surface temperature of the body, in degrees kelvin
*
* Availability:
*
* alpha 16
*
* Status:
*
* experimental
*/
static int l_sbody_attr_average_temp(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushinteger(l, sbody->GetAverageTemp());
return 1;
}
/*
* Attribute: metallicity
*
* Returns the measure of metallicity of the body
* (crust) 0.0 = light (Al, SiO2, etc), 1.0 = heavy (Fe, heavy metals)
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_metallicity(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetMetallicity());
return 1;
}
/*
* Attribute: volatileGas
*
* Returns the measure of volatile gas present in the atmosphere of the body
* 0.0 = no atmosphere, 1.0 = earth atmosphere density, 4.0+ ~= venus
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_volatileGas(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetVolatileGas());
return 1;
}
/*
* Attribute: atmosOxidizing
*
* Returns the compositional value of any atmospheric gasses in the bodys atmosphere (if any)
* 0.0 = reducing (H2, NH3, etc), 1.0 = oxidising (CO2, O2, etc)
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_atmosOxidizing(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetAtmosOxidizing());
return 1;
}
/*
* Attribute: volatileLiquid
*
* Returns the measure of volatile liquids present on the body
* 0.0 = none, 1.0 = waterworld (earth = 70%)
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_volatileLiquid(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetVolatileLiquid());
return 1;
}
/*
* Attribute: volatileIces
*
* Returns the measure of volatile ices present on the body
* 0.0 = none, 1.0 = total ice cover (earth = 3%)
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_volatileIces(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetVolatileIces());
return 1;
}
/*
* Attribute: volcanicity
*
* Returns the measure of volcanicity of the body
* 0.0 = none, 1.0 = lava planet
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_volcanicity(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetVolcanicity());
return 1;
}
/*
* Attribute: life
*
* Returns the measure of life present on the body
* 0.0 = dead, 1.0 = teeming (~= pandora)
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_life(lua_State *l)
{
SystemBody *sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushnumber(l, sbody->GetLife());
return 1;
}
/*
* Attribute: hasRings
*
* Returns true if the body has a ring or rings of debris or ice in orbit around it
*
* Availability:
*
* January 2018
*
* Status:
*
* experimental
*/
static int l_sbody_attr_has_rings(lua_State *l)
{
SystemBody * sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushboolean(l, sbody->HasRings());
return 1;
}
/*
* Attribute: hasAtmosphere
*
* Returns true if an atmosphere is present, false if not
*
* Availability:
*
* alpha 21
*
* Status:
*
* experimental
*/
static int l_sbody_attr_has_atmosphere(lua_State *l)
{
SystemBody * sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushboolean(l, sbody->HasAtmosphere());
return 1;
}
/*
* Attribute: isScoopable
*
* Returns true if the system body can be scoopable, false if not
*
* Availablility:
*
* alpha 21
*
* Status:
*
* experimental
*/
static int l_sbody_attr_is_scoopable(lua_State *l)
{
SystemBody * sbody = LuaObject<SystemBody>::CheckFromLua(1);
lua_pushboolean(l, sbody->IsScoopable());
return 1;
}
static int l_sbody_attr_path(lua_State *l)
{
SystemBody * sbody = LuaObject<SystemBody>::CheckFromLua(1);
LuaObject<SystemPath>::PushToLua(sbody->GetPath());
return 1;
}
static int l_sbody_attr_astro_description(lua_State *l)
{
SystemBody * sbody = LuaObject<SystemBody>::CheckFromLua(1);
LuaPush(l, sbody->GetAstroDescription());
return 1;
}
template <> const char *LuaObject<SystemBody>::s_type = "SystemBody";
template <> void LuaObject<SystemBody>::RegisterClass()
{
static const luaL_Reg l_attrs[] = {
{ "index", l_sbody_attr_index },
{ "name", l_sbody_attr_name },
{ "type", l_sbody_attr_type },
{ "superType", l_sbody_attr_super_type },
{ "seed", l_sbody_attr_seed },
{ "parent", l_sbody_attr_parent },
{ "population", l_sbody_attr_population },
{ "radius", l_sbody_attr_radius },
{ "mass", l_sbody_attr_mass },
{ "gravity", l_sbody_attr_gravity },
{ "periapsis", l_sbody_attr_periapsis },
{ "apoapsis", l_sbody_attr_apoapsis },
{ "orbitPeriod", l_sbody_attr_orbital_period },
{ "rotationPeriod", l_sbody_attr_rotation_period },
{ "semiMajorAxis", l_sbody_attr_semi_major_axis },
{ "eccentricity", l_sbody_attr_eccentricty },
{ "axialTilt", l_sbody_attr_axial_tilt },
{ "averageTemp", l_sbody_attr_average_temp },
{ "metallicity", l_sbody_attr_metallicity },
{ "volatileGas", l_sbody_attr_volatileGas },
{ "atmosOxidizing", l_sbody_attr_atmosOxidizing },
{ "volatileLiquid", l_sbody_attr_volatileLiquid },
{ "volatileIces", l_sbody_attr_volatileIces },
{ "volcanicity", l_sbody_attr_volcanicity },
{ "life", l_sbody_attr_life },
{ "hasRings", l_sbody_attr_has_rings },
{ "hasAtmosphere", l_sbody_attr_has_atmosphere },
{ "isScoopable", l_sbody_attr_is_scoopable },
{ "astroDescription", l_sbody_attr_astro_description },
{ "path", l_sbody_attr_path },
{ 0, 0 }
};
LuaObjectBase::CreateClass(s_type, 0, 0, l_attrs, 0);
}