-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathshipclass.cpp
More file actions
1590 lines (1271 loc) · 46.1 KB
/
shipclass.cpp
File metadata and controls
1590 lines (1271 loc) · 46.1 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
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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
//
#include "freespace.h" //For frametime
#include "shipclass.h"
#include "model.h"
#include "cockpit_display.h"
#include "species.h"
#include "shiptype.h"
#include "team_colors.h"
#include "vecmath.h"
#include "ship/ship.h"
#include "playerman/player.h"
#include "weapon/weapon.h"
#include "mission/missioncampaign.h"
#include "missionui/missionweaponchoice.h"
#include "graphics/matrix.h"
#include "missionui/missionscreencommon.h"
#include "scripting/api/objs/weaponclass.h"
#include "scripting/lua/LuaTable.h"
#include "model/modelrender.h"
#include "utils/string_utils.h"
namespace scripting {
namespace api {
//**********HANDLE: default primary
ADE_OBJ(l_Default_Primary, int, "default_primary", "weapon index");
ADE_INDEXER(l_Default_Primary,
"number idx",
"Array of ship default primaries for each bank. Returns the Weapon Class or "
"nil if the bank is invalid for the ship class.",
"weaponclass",
"The weapon index")
{
int current;
int idx = -1;
if (!ade_get_args(L, "oi", l_Default_Primary.Get(¤t), &idx))
return ADE_RETURN_NIL;
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
ship_info* sip = &Ship_info[current];
if (idx < 1 || idx > sip->num_primary_banks) {
return ADE_RETURN_NIL;
};
idx--; // Convert to Lua's 1 based index system
return ade_set_args(L, "o", l_Weaponclass.Set(sip->primary_bank_weapons[idx]));
}
ADE_FUNC(__len,
l_Default_Primary,
nullptr,
"The number of primary banks with defaults",
"number",
"The number of primary banks.")
{
int current;
ade_get_args(L, "o", l_Default_Primary.Get(¤t));
ship_info* sip = &Ship_info[current];
return ade_set_args(L, "i", sip->num_primary_banks);
}
//**********HANDLE: default secondary
ADE_OBJ(l_Default_Secondary, int, "default_secondary", "weapon index");
ADE_INDEXER(l_Default_Secondary,
"number idx",
"Array of ship default secondaries for each bank. Returns the Weapon Class or "
"nil if the bank is invalid for the ship class.",
"weaponclass",
"The weapon index")
{
int current;
int idx = -1;
if (!ade_get_args(L, "oi", l_Default_Secondary.Get(¤t), &idx))
return ADE_RETURN_NIL;
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
ship_info* sip = &Ship_info[current];
if (idx < 1 || idx > sip->num_secondary_banks) {
return ADE_RETURN_NIL;
};
idx--; // Convert to Lua's 1 based index system
return ade_set_args(L, "o", l_Weaponclass.Set(sip->secondary_bank_weapons[idx]));
}
ADE_FUNC(__len,
l_Default_Secondary,
nullptr,
"The number of secondary banks with defaults",
"number",
"The number of secondary banks.")
{
int current;
ade_get_args(L, "o", l_Default_Secondary.Get(¤t));
ship_info* sip = &Ship_info[current];
return ade_set_args(L, "i", sip->num_secondary_banks);
}
//**********HANDLE: Shipclass
ADE_OBJ(l_Shipclass, int, "shipclass", "Ship class handle");
ADE_FUNC(__tostring, l_Shipclass, NULL, "Ship class name", "string", "Ship class name, or an empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
return ade_set_args(L, "s", Ship_info[idx].name);
}
ADE_FUNC(__eq, l_Shipclass, "shipclass, shipclass", "Checks if the two classes are equal", "boolean", "true if equal, false otherwise")
{
int idx1,idx2;
if(!ade_get_args(L, "oo", l_Shipclass.Get(&idx1), l_Shipclass.Get(&idx2)))
return ade_set_error(L, "b", false);
if(idx1 < 0 || idx1 >= ship_info_size())
return ade_set_error(L, "b", false);
if(idx2 < 0 || idx2 >= ship_info_size())
return ade_set_error(L, "b", false);
return ade_set_args(L, "b", idx1 == idx2);
}
ADE_VIRTVAR(Name, l_Shipclass, "string", "Ship class name", "string", "Ship class name, or an empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR && s != NULL) {
auto len = sizeof(Ship_info[idx].name);
strncpy(Ship_info[idx].name, s, len);
Ship_info[idx].name[len - 1] = 0;
}
return ade_set_args(L, "s", Ship_info[idx].name);
}
ADE_VIRTVAR(ShortName, l_Shipclass, "string", "Ship class short name", "string", "Ship short name, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR && s != NULL) {
auto len = sizeof(Ship_info[idx].short_name);
strncpy(Ship_info[idx].short_name, s, len);
Ship_info[idx].short_name[len - 1] = 0;
}
return ade_set_args(L, "s", Ship_info[idx].short_name);
}
static int handle_ship_class_optional_string(lua_State *L, std::unique_ptr<char[]> ship_info::*optional_string_field)
{
int idx;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if (!SCP_vector_inbounds(Ship_info, idx))
return ade_set_error(L, "s", "");
auto sip = &Ship_info[idx];
if(ADE_SETTING_VAR) {
sip->*optional_string_field = util::unique_copy(s, true);
}
return ade_set_args(L, "s", coalesce((sip->*optional_string_field).get(), ""));
}
ADE_VIRTVAR(TypeString, l_Shipclass, "string", "Ship class type string", "string", "Type string, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::type_str);
}
ADE_VIRTVAR(ManeuverabilityString, l_Shipclass, "string", "Ship class maneuverability string", "string", "Maneuverability string, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::maneuverability_str);
}
ADE_VIRTVAR(ArmorString, l_Shipclass, "string", "Ship class armor string", "string", "Armor string, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::armor_str);
}
ADE_VIRTVAR(ManufacturerString, l_Shipclass, "string", "Ship class manufacturer", "string", "Manufacturer, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::manufacturer_str);
}
ADE_VIRTVAR(LengthString, l_Shipclass, "string", "Ship class length", "string", "Length, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::ship_length);
}
ADE_VIRTVAR(GunMountsString, l_Shipclass, "string", "Ship class gun mounts", "string", "Gun mounts, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::gun_mounts);
}
ADE_VIRTVAR(MissileBanksString, l_Shipclass, "string", "Ship class missile banks", "string", "Missile banks, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::missile_banks);
}
ADE_VIRTVAR(VelocityString, l_Shipclass, "string", "Ship class velocity", "string", "velocity, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
ship_info *sip = &Ship_info[idx];
if (ADE_SETTING_VAR) {
LuaError(L, "Setting Velocity is not supported");
}
char str[100];
sprintf(str, XSTR("%d m/s", 743), fl2i((float)sip->max_vel.xyz.z * Hud_speed_multiplier));
return ade_set_args(L, "s", str);
}
ADE_VIRTVAR(Description, l_Shipclass, "string", "Ship class description", "string", "Description, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::desc);
}
ADE_VIRTVAR(SelectIconFilename, l_Shipclass, "string", "Ship class select icon filename", "string", "Filename, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR) {
LuaError(L, "Setting Select Icon is not supported");
}
return ade_set_args(L, "s", Ship_info[idx].icon_filename);
}
ADE_VIRTVAR(SelectAnimFilename, l_Shipclass, "string", "Ship class select animation filename", "string", "Filename, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR) {
LuaError(L, "Setting Select Anim is not supported");
}
return ade_set_args(L, "s", Ship_info[idx].anim_filename);
}
ADE_VIRTVAR(SelectOverheadFilename, l_Shipclass, "string", "Ship class select overhead filename", "string", "Filename, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &s))
return ade_set_error(L, "s", "");
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR) {
LuaError(L, "Setting Select Overhead Image is not supported");
}
return ade_set_args(L, "s", Ship_info[idx].overhead_filename);
}
ADE_VIRTVAR(TechDescription, l_Shipclass, "string", "Ship class tech description", "string", "Tech description, or empty string if handle is invalid")
{
return handle_ship_class_optional_string(L, &ship_info::tech_desc);
}
ADE_VIRTVAR(numPrimaryBanks,
l_Shipclass,
nullptr,
"Number of primary banks on this ship class",
"number",
"number of banks or nil is ship handle is invalid")
{
int idx;
if (!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ADE_RETURN_NIL;
if (idx < 0 || idx >= ship_info_size())
return ADE_RETURN_NIL;
ship_info* sip = &Ship_info[idx];
if (ADE_SETTING_VAR) {
LuaError(L, "Setting number of banks is not supported");
}
return ade_set_args(L, "i", sip->num_primary_banks);
}
ADE_FUNC(getPrimaryBankCapacity,
l_Shipclass,
"number index",
"Returns the capacity of the specified primary bank",
"number",
"The bank capacity or nil if the index is invalid")
{
int shipIdx;
int idx;
if (!ade_get_args(L, "oi", l_Shipclass.Get(&shipIdx), &idx))
return ADE_RETURN_NIL;
ship_info* sip = &Ship_info[shipIdx];
if (idx < 1 || idx > sip->num_primary_banks) {
return ADE_RETURN_NIL;
};
idx--; // Convert from Lua's 1 based index system
return ade_set_args(L, "i", sip->primary_bank_ammo_capacity[idx]);
}
ADE_VIRTVAR(numSecondaryBanks,
l_Shipclass,
nullptr,
"Number of secondary banks on this ship class",
"number",
"number of banks or nil is ship handle is invalid")
{
int idx;
if (!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ADE_RETURN_NIL;
if (idx < 0 || idx >= ship_info_size())
return ADE_RETURN_NIL;
ship_info* sip = &Ship_info[idx];
if (ADE_SETTING_VAR) {
LuaError(L, "Setting number of banks is not supported");
}
return ade_set_args(L, "i", sip->num_secondary_banks);
}
ADE_FUNC(getSecondaryBankCapacity,
l_Shipclass,
"number index",
"Returns the capacity of the specified secondary bank",
"number",
"The bank capacity or nil if the index is invalid")
{
int shipIdx;
int idx;
if (!ade_get_args(L, "oi", l_Shipclass.Get(&shipIdx), &idx))
return ADE_RETURN_NIL;
ship_info* sip = &Ship_info[shipIdx];
if (idx < 1 || idx > sip->num_secondary_banks) {
return ADE_RETURN_NIL;
};
idx--; // Convert from Lua's 1 based index system
return ade_set_args(L, "i", sip->secondary_bank_ammo_capacity[idx]);
}
ADE_VIRTVAR(defaultPrimaries,
l_Shipclass,
"number",
"Array of default primary weapons",
"default_primary",
"The weapons array or nil if handle is invalid")
{
int idx;
if (!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ADE_RETURN_NIL;
if (idx < 0 || idx >= ship_info_size())
return ADE_RETURN_NIL;
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "o", l_Default_Primary.Set(idx));
}
ADE_VIRTVAR(defaultSecondaries,
l_Shipclass,
"number",
"Array of default secondary weapons",
"default_secondary",
"The weapons array or nil if handle is invalid")
{
int idx;
if (!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ADE_RETURN_NIL;
if (idx < 0 || idx >= ship_info_size())
return ADE_RETURN_NIL;
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "o", l_Default_Secondary.Set(idx));
}
ADE_FUNC(isWeaponAllowedOnShip,
l_Shipclass,
"number index, [number bank]",
"Gets whether or not a weapon is allowed on a ship class. "
"Optionally check a specific bank. Banks are 1 to a maximum of 7 where the first banks are Primaries and rest are "
"Secondaries. "
"Exact numbering depends on the ship class being checked. Note also that this will consider dogfight weapons only "
"if "
"a dogfight mission has been loaded. Index is index into Weapon Classes.",
"boolean",
"True if allowed, false if not.")
{
int idx;
int wepidx;
int bank = 0;
if (!ade_get_args(L, "oi|i", l_Shipclass.Get(&idx), &wepidx, &bank))
return ade_set_error(L, "b", false);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "b", false);
wepidx--; // Convert from Lua
if (wepidx < 0 || wepidx >= weapon_info_size())
return ade_set_error(L, "b", false);
if (bank != 0) {
if (bank < 0 || bank > (Ship_info[idx].num_primary_banks + Ship_info[idx].num_secondary_banks))
return ade_set_error(L, "b", false);
};
bank--; // Convert from Lua
bool retv = false;
if ((bank >= 0) && (eval_weapon_flag_for_game_type(Ship_info[idx].restricted_loadout_flag[bank]))) {
if (eval_weapon_flag_for_game_type(Ship_info[idx].allowed_bank_restricted_weapons[bank][wepidx]))
retv = true;
} else if (eval_weapon_flag_for_game_type(Ship_info[idx].allowed_weapons[wepidx])) {
retv = true;
}
return ade_set_args(L, "b", retv);
}
ADE_VIRTVAR(AfterburnerFuelMax, l_Shipclass, "number", "Afterburner fuel capacity", "number", "Afterburner capacity, or 0 if handle is invalid")
{
int idx;
float fuel = -1.0f;
if(!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &fuel))
return ade_set_error(L, "f", 0.0f);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR && fuel >= 0.0f)
Ship_info[idx].afterburner_fuel_capacity = fuel;
return ade_set_args(L, "f", Ship_info[idx].afterburner_fuel_capacity);
}
ADE_VIRTVAR(ScanTime, l_Shipclass, nullptr, "Ship scan time", "number", "Time required to scan, or 0 if handle is invalid. This property is read-only")
{
int idx;
if (!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ade_set_error(L, "i", 0);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "i", 0);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting ScanTime is not supported");
}
return ade_set_args(L, "i", Ship_info[idx].scan_time);
}
ADE_VIRTVAR(CountermeasureClass, l_Shipclass, "weaponclass", "The default countermeasure class assigned to this ship class", "weaponclass", "Countermeasure hardpoint weapon class, or invalid weaponclass handle if no countermeasure class or ship handle is invalid")
{
int idx;
if (!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ade_set_error(L, "o", l_Weaponclass.Set(-1));
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "o", l_Weaponclass.Set(-1));
ship_info* sip = &Ship_info[idx];
if(ADE_SETTING_VAR) {
LuaError(L, "Setting CountermeasureClass is not supported");
}
if (sip->cmeasure_type > -1) {
return ade_set_args(L, "o", l_Weaponclass.Set(sip->cmeasure_type));
} else {
return ade_set_error(L, "o", l_Weaponclass.Set(-1));
}
}
ADE_VIRTVAR(CountermeasuresMax, l_Shipclass, "number", "Maximum number of countermeasures the ship can carry", "number", "Countermeasure capacity, or 0 if handle is invalid")
{
int idx;
int i = -1;
if(!ade_get_args(L, "o|i", l_Shipclass.Get(&idx), &i))
return ade_set_error(L, "i", 0);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "i", 0);
if(ADE_SETTING_VAR && i > -1) {
Ship_info[idx].cmeasure_max = i;
}
return ade_set_args(L, "i", Ship_info[idx].cmeasure_max);
}
ADE_VIRTVAR(Model, l_Shipclass, "model", "Model", "model", "Ship class model, or invalid model handle if shipclass handle is invalid")
{
int ship_info_idx=-1;
model_h *mdl = NULL;
if(!ade_get_args(L, "o|o", l_Shipclass.Get(&ship_info_idx), l_Model.GetPtr(&mdl)))
return ade_set_error(L, "o", l_Model.Set(model_h(-1)));
if(ship_info_idx < 0 || ship_info_idx >= ship_info_size())
return ade_set_error(L, "o", l_Model.Set(model_h(-1)));
ship_info *sip = &Ship_info[ship_info_idx];
int mid = (mdl ? mdl->GetID() : -1);
if(ADE_SETTING_VAR && mid > -1) {
sip->model_num = mid;
}
return ade_set_args(L, "o", l_Model.Set(model_h(sip->model_num)));
}
ADE_VIRTVAR(CockpitModel, l_Shipclass, "model", "Model used for first-person cockpit", "model", "Cockpit model")
{
int ship_info_idx=-1;
model_h *mdl = NULL;
if(!ade_get_args(L, "o|o", l_Shipclass.Get(&ship_info_idx), l_Model.GetPtr(&mdl)))
return ade_set_error(L, "o", l_Model.Set(model_h()));
if(ship_info_idx < 0 || ship_info_idx >= ship_info_size())
return ade_set_error(L, "o", l_Model.Set(model_h()));
ship_info *sip = &Ship_info[ship_info_idx];
int mid = (mdl ? mdl->GetID() : -1);
if(ADE_SETTING_VAR) {
sip->cockpit_model_num = mid;
}
return ade_set_args(L, "o", l_Model.Set(model_h(sip->cockpit_model_num)));
}
ADE_VIRTVAR(CockpitDisplays, l_Shipclass, "cockpitdisplays", "Gets the cockpit display information array of this ship class", "cockpitdisplays", "Array handle containing the information or invalid handle on error")
{
int ship_info_idx=-1;
cockpit_displays_info_h *cdih = NULL;
if(!ade_get_args(L, "o|o", l_Shipclass.Get(&ship_info_idx), l_CockpitDisplayInfos.GetPtr(&cdih)))
return ade_set_error(L, "o", l_CockpitDisplayInfos.Set(cockpit_displays_info_h()));
if(ship_info_idx < 0 || ship_info_idx >= ship_info_size())
return ade_set_error(L, "o", l_CockpitDisplayInfos.Set(cockpit_displays_info_h()));
if(ADE_SETTING_VAR) {
LuaError(L, "Attempted to use incomplete feature: Cockpit display information copy");
}
return ade_set_args(L, "o", l_CockpitDisplayInfos.Set(cockpit_displays_info_h(ship_info_idx)));
}
ADE_VIRTVAR(HitpointsMax, l_Shipclass, "number", "Ship class hitpoints", "number", "Hitpoints, or 0 if handle is invalid")
{
int idx;
float f = -1.0f;
if(!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR && f >= 0.0f) {
Ship_info[idx].max_hull_strength = f;
}
return ade_set_args(L, "f", Ship_info[idx].max_hull_strength);
}
ADE_VIRTVAR(ShieldHitpointsMax, l_Shipclass, nullptr, "Ship class shield hitpoints", "number", "Shield hitpoints, or 0 if handle is invalid")
{
int idx;
if(!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ade_set_error(L, "f", 0.0f);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR) {
LuaError(L, "Setting Shield Max Hitpoints is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].max_shield_strength);
}
ADE_VIRTVAR(Species, l_Shipclass, "species", "Ship class species", "species", "Ship class species, or invalid species handle if shipclass handle is invalid")
{
int idx;
int sidx = -1;
if(!ade_get_args(L, "o|o", l_Shipclass.Get(&idx), l_Species.Get(&sidx)))
return ade_set_error(L, "o", l_Species.Set(-1));
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "o", l_Species.Set(-1));
if(ADE_SETTING_VAR && sidx > -1 && sidx < (int)Species_info.size()) {
Ship_info[idx].species = sidx;
}
return ade_set_args(L, "o", l_Species.Set(Ship_info[idx].species));
}
ADE_VIRTVAR(Type, l_Shipclass, "shiptype", "Ship class type", "shiptype", "Ship type, or invalid handle if shipclass handle is invalid")
{
int idx;
int sidx = -1;
if(!ade_get_args(L, "o|o", l_Shipclass.Get(&idx), l_Shiptype.Get(&sidx)))
return ade_set_error(L, "o", l_Shiptype.Set(-1));
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "o", l_Shiptype.Set(-1));
if(ADE_SETTING_VAR && sidx > -1 && sidx < (int)Ship_types.size()) {
Ship_info[idx].class_type = sidx;
}
return ade_set_args(L, "o", l_Shiptype.Set(Ship_info[idx].class_type));
}
ADE_VIRTVAR(AltName, l_Shipclass, "string", "Alternate name for ship class", "string", "Alternate string or empty string if handle is invalid")
{
const char* newName = nullptr;
int idx;
if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &newName))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR && newName != NULL) {
if (strlen(newName) >= NAME_LENGTH)
{
LuaError(L, "Cannot set alternate name value to '%s' because it is too long, maximum length is %d!", newName, NAME_LENGTH - 1);
return ade_set_error(L, "s", "");
}
strcpy_s(Ship_info[idx].display_name, newName);
}
return ade_set_args(L, "s", Ship_info[idx].display_name);
}
ADE_VIRTVAR(VelocityMax, l_Shipclass, "vector", "Ship's lateral and forward speeds", "vector", "Maximum velocity, or null vector if handle is invalid")
{
int idx;
vec3d* vec = NULL;
if (!ade_get_args(L, "o|o", l_Shipclass.Get(&idx), l_Vector.GetPtr(&vec)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if (ADE_SETTING_VAR) {
LuaError(L, "Setting VelocityMax is not supported");
}
return ade_set_args(L, "o", l_Vector.Set(Ship_info[idx].max_vel));
}
ADE_VIRTVAR(VelocityDamping, l_Shipclass, "number", "Damping, the natural period (1 / omega) of the dampening effects on top of the acceleration model. ", "number", "Damping, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting VelocityDamping is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].damp);
}
ADE_VIRTVAR(RearVelocityMax, l_Shipclass, "number", "The maximum rear velocity of the ship", "number", "Speed, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting RearVelocityMax is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].max_rear_vel);
}
ADE_VIRTVAR(ForwardAccelerationTime, l_Shipclass, "number", "Forward acceleration time", "number", "Forward acceleration time, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting ForwardAccelerationTime is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].forward_accel);
}
ADE_VIRTVAR(ForwardDecelerationTime, l_Shipclass, "number", "Forward deceleration time", "number", "Forward deceleration time, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting ForwardDecelerationTime is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].forward_decel);
}
ADE_VIRTVAR(RotationTime, l_Shipclass, "vector", "Maximum rotation time on each axis", "vector", "Full rotation time for each axis, or null vector if handle is invalid")
{
int idx;
vec3d* vec = NULL;
if (!ade_get_args(L, "o|o", l_Shipclass.Get(&idx), l_Vector.GetPtr(&vec)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if (ADE_SETTING_VAR) {
LuaError(L, "Setting RotationTime is not supported");
}
return ade_set_args(L, "o", l_Vector.Set(Ship_info[idx].rotation_time));
}
ADE_VIRTVAR(RotationalVelocityDamping, l_Shipclass, "number", "Rotational damping, ie derivative of rotational speed", "number", "Rotational damping, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting RotationalVelocityDamping is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].rotdamp);
}
ADE_VIRTVAR(AfterburnerAccelerationTime, l_Shipclass, "number", "Afterburner acceleration time", "number", "Afterburner acceleration time, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting AfterburnerAccelerationTime is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].afterburner_forward_accel);
}
ADE_VIRTVAR(AfterburnerVelocityMax, l_Shipclass, "vector", "Afterburner max velocity", "vector", "Afterburner max velocity, or null vector if handle is invalid")
{
int idx;
vec3d* vec = NULL;
if (!ade_get_args(L, "o|o", l_Shipclass.Get(&idx), l_Vector.GetPtr(&vec)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if (ADE_SETTING_VAR) {
LuaError(L, "Setting AfterburnerVelocityMax is not supported");
}
return ade_set_args(L, "o", l_Vector.Set(Ship_info[idx].afterburner_max_vel));
}
ADE_VIRTVAR(AfterburnerRearVelocityMax, l_Shipclass, "number", "Afterburner maximum rear velocity", "number", "Rear velocity, or 0 if handle is invalid")
{
int idx;
float f = 0.0f;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &f))
return ade_set_error(L, "f", 0.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if (ADE_SETTING_VAR) {
LuaError(L, "Setting AfterburnerRearVelocityMax is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].afterburner_max_reverse_vel);
}
ADE_VIRTVAR(Score, l_Shipclass, "string", "The score of this ship class", "number", "The score or -1 on invalid ship class")
{
int idx;
int new_score;
if(!ade_get_args(L, "o|i", l_Shipclass.Get(&idx), &new_score))
return ade_set_error(L, "i", -1);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "i", -1);
if(ADE_SETTING_VAR) {
Ship_info[idx].score = new_score;
}
return ade_set_args(L, "i", Ship_info[idx].score);
}
ADE_VIRTVAR(InTechDatabase, l_Shipclass, "boolean", "Gets or sets whether this ship class is visible in the tech room", "boolean", "True or false")
{
int idx;
bool new_value;
if (!ade_get_args(L, "o|b", l_Shipclass.Get(&idx), &new_value))
return ade_set_error(L, "b", false);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "b", false);
auto flag = (Player && (Player->flags & PLAYER_FLAGS_IS_MULTI))
? Ship::Info_Flags::In_tech_database_m
: Ship::Info_Flags::In_tech_database;
if (ADE_SETTING_VAR) {
Ship_info[idx].flags.set(flag, new_value);
}
return ade_set_args(L, "b", Ship_info[idx].flags[flag]);
}
ADE_VIRTVAR(AllowedInCampaign, l_Shipclass, "boolean", "Gets or sets whether this ship class is allowed in loadouts in campaign mode", "boolean", "True or false")
{
int idx;
bool new_value;
if (!ade_get_args(L, "o|b", l_Shipclass.Get(&idx), &new_value))
return ade_set_error(L, "b", false);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "b", false);
if (ADE_SETTING_VAR) {
Campaign.ships_allowed[idx] = new_value;
}
return Campaign.ships_allowed[idx] ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
}
ADE_VIRTVAR(PowerOutput, l_Shipclass, "number", "Gets or sets a ship class' power output", "number", "The ship class' current power output")
{
int idx;
float new_power;
if (!ade_get_args(L, "o|f", l_Shipclass.Get(&idx), &new_power))
return ade_set_error(L, "f", -1.0f);
if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", -1.0f);
if (ADE_SETTING_VAR) {
Ship_info[idx].power_output = new_power;
}
return ade_set_args(L, "f", Ship_info[idx].power_output);
}
ADE_VIRTVAR(ScanningTimeMultiplier, l_Shipclass, nullptr, "Time multiplier for scans performed by this ship class", "number", "Scanning time multiplier, or 0 if handle is invalid")
{
int idx;
if(!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ade_set_error(L, "f", 0.0f);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR) {
LuaError(L, "Setting ScanningTimeMultiplier is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].scanning_time_multiplier);
}
ADE_VIRTVAR(ScanningRangeMultiplier, l_Shipclass, nullptr, "Range multiplier for scans performed by this ship class", "number", "Scanning range multiplier, or 0 if handle is invalid")
{
int idx;
if(!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ade_set_error(L, "f", 0.0f);
if(idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR) {
LuaError(L, "Setting ScanningRangeMultiplier is not supported");
}
return ade_set_args(L, "f", Ship_info[idx].scanning_range_multiplier);
}
ADE_VIRTVAR(CustomData, l_Shipclass, nullptr, "Gets the custom data table for this ship class", "table", "The ship class's custom data table")
{
int idx;
if(!ade_get_args(L, "o", l_Shipclass.Get(&idx)))
return ADE_RETURN_NIL;
if(idx < 0 || idx >= ship_info_size())
return ADE_RETURN_NIL;
auto table = luacpp::LuaTable::create(L);
ship_info *sip = &Ship_info[idx];