-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathlua.cpp
More file actions
14748 lines (11597 loc) · 417 KB
/
Copy pathlua.cpp
File metadata and controls
14748 lines (11597 loc) · 417 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 "ai/ai.h"
#include "ai/aigoals.h"
#include "asteroid/asteroid.h"
#include "camera/camera.h"
#include "cfile/cfilesystem.h"
#include "cmdline/cmdline.h"
#include "cutscene/movie.h"
#include "debris/debris.h"
#include "freespace.h"
#include "gamesequence/gamesequence.h"
#include "globalincs/linklist.h"
#include "graphics/2d.h"
#include "graphics/font.h"
#include "graphics/generic.h"
#include "graphics/opengl/gropenglpostprocessing.h"
#include "headtracking/headtracking.h"
#include "hud/hudbrackets.h"
#include "hud/hudconfig.h"
#include "hud/hudescort.h"
#include "hud/hudets.h"
#include "hud/hudgauges.h"
#include "hud/hudshield.h"
#include "iff_defs/iff_defs.h"
#include "io/joy.h"
#include "io/key.h"
#include "io/mouse.h"
#include "io/timer.h"
#include "jumpnode/jumpnode.h"
#include "lighting/lighting.h"
#include "menuui/credits.h"
#include "mission/missioncampaign.h"
#include "mission/missiongoals.h"
#include "mission/missionload.h"
#include "mission/missionlog.h"
#include "mission/missionmessage.h"
#include "mission/missiontraining.h"
#include "missionui/missionbrief.h"
#include "model/model.h"
#include "network/multi.h"
#include "network/multimsgs.h"
#include "object/objectshield.h"
#include "object/waypoint.h"
#include "scripting/lua.h"
#include "parse/parselo.h"
#include "scripting/scripting.h"
#include "particle/particle.h"
#include "playerman/player.h"
#include "render/3d.h"
#include "render/3dinternal.h"
#include "scripting/ade_api.h"
#include "ship/ship.h"
#include "ship/shipfx.h"
#include "ship/shiphit.h"
#include "sound/audiostr.h"
#include "sound/ds.h"
#include "weapon/beam.h"
#include "weapon/weapon.h"
#define BMPMAN_INTERNAL
#include "bmpman/bm_internal.h"
#include "scripting/api/bitops.h"
#include "scripting/api/enums.h"
#include "scripting/api/vecmath.h"
#include "scripting/api/event.h"
#include "scripting/api/file.h"
#include "scripting/api/font.h"
#include "scripting/api/gameevent.h"
#include "scripting/api/gamestate.h"
#include "scripting/api/hudgauge.h"
#include "scripting/api/eye.h"
using namespace scripting;
using namespace scripting::api;
int ade_set_object_with_breed(lua_State *L, int obj_idx);
//**********Handles
/*ade_obj<int> l_Camera("camera", "Camera handle");
ade_obj<int> l_Cmission("cmission", "Campaign mission handle"); //WMC - We can get away with a pointer right now, but if it ever goes dynamic, it'd be a prob
ade_obj<enum_h> l_Enum("enumeration", "Enumeration object");
ade_obj<int> l_Event("event", "Mission event handle");
ade_obj<int> l_Font("font", "font handle");
ade_obj<matrix_h> l_Matrix("orientation", "Orientation matrix object");
ade_obj<int> l_Model("model", "3D Model (POF) handle");
ade_obj<object_h> l_Object("object", "Object handle");
ade_obj<physics_info_h> l_Physics("physics", "Physics handle");
ade_obj<int> l_Player("player", "Player handle");
ade_obj<object_h> l_Shields("shields", "Shields handle");
ade_obj<object_h> l_Ship("ship", "Ship handle", &l_Object);
ade_obj<int> l_Shipclass("shipclass", "Ship class handle");
ade_obj<object_h> l_ShipTextures("shiptextures", "Ship textures handle");
ade_obj<int> l_Shiptype("shiptype", "Ship type handle");
ade_obj<int> l_Species("species", "Species handle");
ade_obj<ship_subsys_h> l_Subsystem("subsystem", "Ship subsystem handle");
ade_obj<int> l_Team("team", "Team handle");
ade_obj<int> l_Texture("texture", "Texture handle");
ade_obj<int> l_Wing("wing", "Wing handle");
ade_obj<vec3d> l_Vector("vector", "Vector object");
ade_obj<object_h> l_Weapon("weapon", "Weapon handle", &l_Object);
ade_obj<ship_bank_h> l_WeaponBank("weaponbank", "Ship/subystem weapons bank handle");
ade_obj<ship_banktype_h> l_WeaponBankType("weaponbanktype", "Ship/subsystem weapons bank type handle");
ade_obj<int> l_Weaponclass("weaponclass", "Weapon class handle");
*/
//###########################################################
//########################<IMPORTANT>########################
//###########################################################
//If you are a coder who wants to add libraries, functions,
//or objects to Lua, then you want to be below this point.
//###########################################################
//########################</IMPORTANT>#######################
//###########################################################
flag_def_list plr_commands[] = {
{ "TARGET_NEXT", TARGET_NEXT, 0 },
{ "TARGET_PREV", TARGET_PREV, 0 },
{ "TARGET_NEXT_CLOSEST_HOSTILE", TARGET_NEXT_CLOSEST_HOSTILE, 0 },
{ "TARGET_PREV_CLOSEST_HOSTILE", TARGET_PREV_CLOSEST_HOSTILE, 0 },
{ "TOGGLE_AUTO_TARGETING", TOGGLE_AUTO_TARGETING, 0 },
{ "TARGET_NEXT_CLOSEST_FRIENDLY", TARGET_NEXT_CLOSEST_FRIENDLY, 0 },
{ "TARGET_PREV_CLOSEST_FRIENDLY", TARGET_PREV_CLOSEST_FRIENDLY, 0 },
{ "TARGET_SHIP_IN_RETICLE", TARGET_SHIP_IN_RETICLE, 0 },
{ "TARGET_CLOSEST_SHIP_ATTACKING_TARGET", TARGET_CLOSEST_SHIP_ATTACKING_TARGET, 0 },
{ "TARGET_LAST_TRANMISSION_SENDER", TARGET_LAST_TRANMISSION_SENDER, 0 },
{ "STOP_TARGETING_SHIP", STOP_TARGETING_SHIP, 0 },
{ "TARGET_SUBOBJECT_IN_RETICLE", TARGET_SUBOBJECT_IN_RETICLE, 0 },
{ "TARGET_NEXT_SUBOBJECT", TARGET_NEXT_SUBOBJECT, 0 },
{ "TARGET_PREV_SUBOBJECT", TARGET_PREV_SUBOBJECT, 0 },
{ "STOP_TARGETING_SUBSYSTEM", STOP_TARGETING_SUBSYSTEM, 0 },
{ "MATCH_TARGET_SPEED", MATCH_TARGET_SPEED, 0 },
{ "TOGGLE_AUTO_MATCH_TARGET_SPEED", TOGGLE_AUTO_MATCH_TARGET_SPEED, 0 },
{ "FIRE_PRIMARY", FIRE_PRIMARY, 0 },
{ "FIRE_SECONDARY", FIRE_SECONDARY, 0 },
{ "CYCLE_NEXT_PRIMARY", CYCLE_NEXT_PRIMARY, 0 },
{ "CYCLE_PREV_PRIMARY", CYCLE_PREV_PRIMARY, 0 },
{ "CYCLE_SECONDARY", CYCLE_SECONDARY, 0 },
{ "CYCLE_NUM_MISSLES", CYCLE_NUM_MISSLES, 0 },
{ "LAUNCH_COUNTERMEASURE", LAUNCH_COUNTERMEASURE, 0 },
{ "FORWARD_THRUST", FORWARD_THRUST, 0 },
{ "REVERSE_THRUST", REVERSE_THRUST, 0 },
{ "BANK_LEFT", BANK_LEFT, 0 },
{ "BANK_RIGHT", BANK_RIGHT, 0 },
{ "PITCH_FORWARD", PITCH_FORWARD, 0 },
{ "PITCH_BACK", PITCH_BACK, 0 },
{ "YAW_LEFT", YAW_LEFT, 0 },
{ "YAW_RIGHT", YAW_RIGHT, 0 },
{ "ZERO_THROTTLE", ZERO_THROTTLE, 1 },
{ "MAX_THROTTLE", MAX_THROTTLE, 1 },
{ "ONE_THIRD_THROTTLE", ONE_THIRD_THROTTLE, 1 },
{ "TWO_THIRDS_THROTTLE", TWO_THIRDS_THROTTLE, 1 },
{ "PLUS_5_PERCENT_THROTTLE", PLUS_5_PERCENT_THROTTLE, 1 },
{ "MINUS_5_PERCENT_THROTTLE", MINUS_5_PERCENT_THROTTLE, 1 },
{ "ATTACK_MESSAGE", ATTACK_MESSAGE, 1 },
{ "DISARM_MESSAGE", DISARM_MESSAGE, 1 },
{ "DISABLE_MESSAGE", DISABLE_MESSAGE, 1 },
{ "ATTACK_SUBSYSTEM_MESSAGE", ATTACK_SUBSYSTEM_MESSAGE, 1 },
{ "CAPTURE_MESSAGE", CAPTURE_MESSAGE, 1 },
{ "ENGAGE_MESSAGE", ENGAGE_MESSAGE, 1 },
{ "FORM_MESSAGE", FORM_MESSAGE, 1 },
{ "IGNORE_MESSAGE", IGNORE_MESSAGE, 1 },
{ "PROTECT_MESSAGE", PROTECT_MESSAGE, 1 },
{ "COVER_MESSAGE", COVER_MESSAGE, 1 },
{ "WARP_MESSAGE", WARP_MESSAGE, 1 },
{ "REARM_MESSAGE", REARM_MESSAGE, 1 },
{ "TARGET_CLOSEST_SHIP_ATTACKING_SELF", TARGET_CLOSEST_SHIP_ATTACKING_SELF, 1 },
{ "VIEW_CHASE", VIEW_CHASE, 1 },
{ "VIEW_EXTERNAL", VIEW_EXTERNAL, 1 },
{ "VIEW_EXTERNAL_TOGGLE_CAMERA_LOCK", VIEW_EXTERNAL_TOGGLE_CAMERA_LOCK, 1 },
{ "VIEW_SLEW", VIEW_SLEW, 1 },
{ "VIEW_OTHER_SHIP", VIEW_OTHER_SHIP, 1 },
{ "VIEW_DIST_INCREASE", VIEW_DIST_INCREASE, 1 },
{ "VIEW_DIST_DECREASE", VIEW_DIST_DECREASE, 1 },
{ "VIEW_CENTER", VIEW_CENTER, 1 },
{ "PADLOCK_UP", PADLOCK_UP, 1 },
{ "PADLOCK_DOWN", PADLOCK_DOWN, 1 },
{ "PADLOCK_LEFT", PADLOCK_LEFT, 1 },
{ "PADLOCK_RIGHT", PADLOCK_RIGHT, 1 },
{ "RADAR_RANGE_CYCLE", RADAR_RANGE_CYCLE, 1 },
{ "SQUADMSG_MENU", SQUADMSG_MENU, 2 },
{ "SHOW_GOALS", SHOW_GOALS, 2 },
{ "END_MISSION", END_MISSION, 2 },
{ "TARGET_TARGETS_TARGET", TARGET_TARGETS_TARGET, 2 },
{ "AFTERBURNER", AFTERBURNER, 2 },
{ "INCREASE_WEAPON", INCREASE_WEAPON, 2 },
{ "DECREASE_WEAPON", DECREASE_WEAPON, 2 },
{ "INCREASE_SHIELD", INCREASE_SHIELD, 2 },
{ "DECREASE_SHIELD", DECREASE_SHIELD, 2 },
{ "INCREASE_ENGINE", INCREASE_ENGINE, 2 },
{ "DECREASE_ENGINE", DECREASE_ENGINE, 2 },
{ "ETS_EQUALIZE", ETS_EQUALIZE, 2 },
{ "SHIELD_EQUALIZE", SHIELD_EQUALIZE, 2 },
{ "SHIELD_XFER_TOP", SHIELD_XFER_TOP, 2 },
{ "SHIELD_XFER_BOTTOM", SHIELD_XFER_BOTTOM, 2 },
{ "SHIELD_XFER_LEFT", SHIELD_XFER_LEFT, 2 },
{ "SHIELD_XFER_RIGHT", SHIELD_XFER_RIGHT, 2 },
{ "XFER_SHIELD", XFER_SHIELD, 2 },
{ "XFER_LASER", XFER_LASER, 2 },
{ "GLIDE_WHEN_PRESSED", GLIDE_WHEN_PRESSED, 2 },
{ "BANK_WHEN_PRESSED", BANK_WHEN_PRESSED, 2 },
{ "SHOW_NAVMAP", SHOW_NAVMAP, 2 },
{ "ADD_REMOVE_ESCORT", ADD_REMOVE_ESCORT, 2 },
{ "ESCORT_CLEAR", ESCORT_CLEAR, 2 },
{ "TARGET_NEXT_ESCORT_SHIP", TARGET_NEXT_ESCORT_SHIP, 2 },
{ "TARGET_CLOSEST_REPAIR_SHIP", TARGET_CLOSEST_REPAIR_SHIP, 2 },
{ "TARGET_NEXT_UNINSPECTED_CARGO", TARGET_NEXT_UNINSPECTED_CARGO, 2 },
{ "TARGET_PREV_UNINSPECTED_CARGO", TARGET_PREV_UNINSPECTED_CARGO, 2 },
{ "TARGET_NEWEST_SHIP", TARGET_NEWEST_SHIP, 2 },
{ "TARGET_NEXT_LIVE_TURRET", TARGET_NEXT_LIVE_TURRET, 2 },
{ "TARGET_PREV_LIVE_TURRET", TARGET_PREV_LIVE_TURRET, 2 },
{ "TARGET_NEXT_BOMB", TARGET_NEXT_BOMB, 2 },
{ "TARGET_PREV_BOMB", TARGET_PREV_BOMB, 3 },
{ "MULTI_MESSAGE_ALL", MULTI_MESSAGE_ALL, 3 },
{ "MULTI_MESSAGE_FRIENDLY", MULTI_MESSAGE_FRIENDLY, 3 },
{ "MULTI_MESSAGE_HOSTILE", MULTI_MESSAGE_HOSTILE, 3 },
{ "MULTI_MESSAGE_TARGET", MULTI_MESSAGE_TARGET, 3 },
{ "MULTI_OBSERVER_ZOOM_TO", MULTI_OBSERVER_ZOOM_TO, 3 },
{ "TIME_SPEED_UP", TIME_SPEED_UP, 3 },
{ "TIME_SLOW_DOWN", TIME_SLOW_DOWN, 3 },
{ "TOGGLE_HUD_CONTRAST", TOGGLE_HUD_CONTRAST, 3 },
{ "MULTI_TOGGLE_NETINFO", MULTI_TOGGLE_NETINFO, 3 },
{ "MULTI_SELF_DESTRUCT", MULTI_SELF_DESTRUCT, 3 },
{ "TOGGLE_HUD", TOGGLE_HUD, 3 },
{ "RIGHT_SLIDE_THRUST", RIGHT_SLIDE_THRUST, 3 },
{ "LEFT_SLIDE_THRUST", LEFT_SLIDE_THRUST, 3 },
{ "UP_SLIDE_THRUST", UP_SLIDE_THRUST, 3 },
{ "DOWN_SLIDE_THRUST", DOWN_SLIDE_THRUST, 3 },
{ "HUD_TARGETBOX_TOGGLE_WIREFRAME", HUD_TARGETBOX_TOGGLE_WIREFRAME, 3 },
{ "VIEW_TOPDOWN", VIEW_TOPDOWN, 3 },
{ "VIEW_TRACK_TARGET", VIEW_TRACK_TARGET, 3 },
{ "AUTO_PILOT_TOGGLE", AUTO_PILOT_TOGGLE, 3 },
{ "NAV_CYCLE", NAV_CYCLE, 3 },
{ "TOGGLE_GLIDING", TOGGLE_GLIDING, 3 },
{ "TOGGLE_AUTO_SHIELD_EQUALIZE", TOGGLE_AUTO_SHIELD_EQUALIZE, 3 },
};
int num_plr_commands = sizeof(plr_commands)/sizeof(flag_def_list);
//**********HANDLE: model
class model_h
{
protected:
int mid;
polymodel *model;
public:
polymodel *Get(){
if(!this->IsValid())
return NULL;
return model;
}
int GetID(){
if(!this->IsValid())
return -1;
return mid;
}
bool IsValid(){
return (model != NULL && mid > -1 && model_get(mid) == model);
}
model_h(int n_modelnum) {
mid = n_modelnum;
if(mid > 0)
model = model_get(mid);
else
model = NULL;
}
model_h(polymodel *n_model) {
model = n_model;
if(n_model != NULL)
mid = n_model->id;
else
mid = -1;
}
model_h(){
mid=-1;
model = NULL;
}
};
class modeltextures_h : public model_h
{
public:
modeltextures_h(polymodel *pm) : model_h(pm){}
modeltextures_h() : model_h(){}
};
ade_obj<model_h> l_Model("model", "3D Model (POF) handle");
ade_obj<modeltextures_h> l_ModelTextures("modeltextures_h", "Array of materials");
class eyepoints_h : public model_h
{
public:
eyepoints_h(polymodel *pm) : model_h(pm){}
eyepoints_h() : model_h(){}
};
ade_obj<eyepoints_h> l_Eyepoints("eyepoints", "Array of model eye points");
// Thrusters:
class thrusters_h : public model_h
{
public:
thrusters_h(polymodel *pm) : model_h(pm){}
thrusters_h() : model_h(){}
};
ade_obj<thrusters_h> l_Thrusters("thrusters", "The thrusters of a model");
// Thrusterbank:
struct thrusterbank_h
{
thruster_bank *bank;
thrusterbank_h()
{
bank = NULL;
}
thrusterbank_h(thruster_bank* ba)
{
bank = ba;
}
thruster_bank *Get()
{
if (!isValid())
return NULL;
return bank;
}
bool isValid()
{
return bank != NULL;
}
};
ade_obj<thrusterbank_h> l_Thrusterbank("thrusterbank", "A model thrusterbank");
// Glowpoint:
struct glowpoint_h
{
glow_point *point;
glowpoint_h()
{
}
glowpoint_h(glow_point* np)
{
point = np;
}
glow_point* Get()
{
if (!isValid())
return NULL;
return point;
}
bool isValid()
{
return point != NULL;
}
};
ade_obj<glowpoint_h> l_Glowpoint("glowpoint", "A model glowpoint");
// Glowbanks:
class dockingbays_h : public model_h
{
public:
dockingbays_h(polymodel *pm) : model_h(pm){}
dockingbays_h() : model_h(){}
};
ade_obj<dockingbays_h> l_Dockingbays("dockingbays", "The docking bays of a model");
ADE_VIRTVAR(Textures, l_Model, "modeltextures_h", "Model textures", "modeltextures_h", "Model textures, or an invalid modeltextures handle if the model handle is invalid")
{
model_h *mdl = NULL;
modeltextures_h *oth = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_ModelTextures.GetPtr(&oth)))
return ade_set_error(L, "o", l_ModelTextures.Set(modeltextures_h()));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_ModelTextures.Set(modeltextures_h()));
if(ADE_SETTING_VAR && oth && oth->IsValid()) {
//WMC TODO: Copy code
LuaError(L, "Attempt to use Incomplete Feature: Modeltextures copy");
}
return ade_set_args(L, "o", l_ModelTextures.Set(modeltextures_h(pm)));
}
ADE_VIRTVAR(Thrusters, l_Model, "thrusters", "Model thrusters", "thrusters", "Thrusters of the model or invalid handle")
{
model_h *mdl = NULL;
thrusters_h *oth = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_Thrusters.GetPtr(&oth)))
return ade_set_error(L, "o", l_Thrusters.Set(thrusters_h()));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_Thrusters.Set(thrusters_h()));
if(ADE_SETTING_VAR && oth && oth->IsValid()) {
LuaError(L, "Attempt to use Incomplete Feature: Thrusters copy");
}
return ade_set_args(L, "o", l_Thrusters.Set(thrusters_h(pm)));
}
ADE_VIRTVAR(Eyepoints, l_Model, "eyepoints", "Model eyepoints", "eyepoints", "Array of eyepoints or invalid handle on error")
{
model_h *mdl = NULL;
eyepoints_h *eph = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_Eyepoints.GetPtr(&eph)))
return ade_set_error(L, "o", l_Eyepoints.Set(eyepoints_h()));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_Eyepoints.Set(eyepoints_h()));
if(ADE_SETTING_VAR && eph && eph->IsValid()) {
LuaError(L, "Attempt to use Incomplete Feature: Eyepoints copy");
}
return ade_set_args(L, "o", l_Eyepoints.Set(eyepoints_h(pm)));
}
ADE_VIRTVAR(Dockingbays, l_Model, "dockingbays", "Docking bays handle of model", "dockingbays", "Array of docking bays on this model, or invalid handle on error")
{
model_h *mdl = NULL;
dockingbays_h *dbh = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_Dockingbays.GetPtr(&dbh)))
return ade_set_error(L, "o", l_Dockingbays.Set(dockingbays_h()));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_Dockingbays.Set(dockingbays_h()));
if(ADE_SETTING_VAR && dbh && dbh->IsValid()) {
LuaError(L, "Attempt to use Incomplete Feature: Docking bays copy");
}
return ade_set_args(L, "o", l_Dockingbays.Set(dockingbays_h(pm)));
}
extern void model_calc_bound_box( vec3d *box, vec3d *big_mn, vec3d *big_mx);
ADE_VIRTVAR(BoundingBoxMax, l_Model, "vector", "Model bounding box maximum", "vector", "Model bounding box, or an empty vector if the handle is invalid")
{
model_h *mdl = NULL;
vec3d *v = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_Vector.GetPtr(&v)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(ADE_SETTING_VAR && v != NULL) {
pm->maxs = *v;
//Recalculate this, so it stays valid
model_calc_bound_box(pm->bounding_box, &pm->mins, &pm->maxs);
}
return ade_set_args(L, "o", l_Vector.Set(pm->maxs));
}
ADE_VIRTVAR(BoundingBoxMin, l_Model, "vector", "Model bounding box minimum", "vector", "Model bounding box, or an empty vector if the handle is invalid")
{
model_h *mdl = NULL;
vec3d *v = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_Vector.GetPtr(&v)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(ADE_SETTING_VAR && v != NULL) {
pm->mins = *v;
//Recalculate this, so it stays valid
model_calc_bound_box(pm->bounding_box, &pm->mins, &pm->maxs);
}
return ade_set_args(L, "o", l_Vector.Set(pm->mins));
}
ADE_VIRTVAR(Filename, l_Model, "string", "Model filename", "string", "Model filename, or an empty string if the handle is invalid")
{
model_h *mdl = NULL;
char *s = NULL;
if(!ade_get_args(L, "o|s", l_Model.GetPtr(&mdl), &s))
return ade_set_error(L, "s", "");
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR) {
strncpy(pm->filename, s, sizeof(pm->filename) - sizeof(char));
}
return ade_set_args(L, "s", pm->filename);
}
ADE_VIRTVAR(Mass, l_Model, "number", "Model mass", "number", "Model mass, or 0 if the model handle is invalid")
{
model_h *mdl = NULL;
float nm = 0.0f;
if(!ade_get_args(L, "o|f", l_Model.GetPtr(&mdl), &nm))
return ade_set_error(L, "f", 0.0f);
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR) {
pm->mass = nm;
}
return ade_set_args(L, "f", pm->mass);
}
ADE_VIRTVAR(MomentOfInertia, l_Model, "orientation", "Model moment of inertia", "orientation", "Moment of Inertia matrix or identity matrix if invalid" )
{
model_h *mdl = NULL;
matrix_h *mh = NULL;
if(!ade_get_args(L, "o|o", l_Model.GetPtr(&mdl), l_Matrix.GetPtr(&mh)))
return ade_set_error(L, "o", l_Matrix.Set(matrix_h()));
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "o", l_Matrix.Set(matrix_h()));
if(ADE_SETTING_VAR && mh != NULL) {
matrix *mtx = mh->GetMatrix();
memcpy(&pm->moment_of_inertia, mtx, sizeof(*mtx));
}
return ade_set_args(L, "o", l_Matrix.Set(matrix_h(&pm->moment_of_inertia)));
}
ADE_VIRTVAR(Radius, l_Model, "number", "Model radius (Used for collision & culling detection)", "number", "Model Radius or 0 if invalid")
{
model_h *mdl = NULL;
float nr = 0.0f;
if(!ade_get_args(L, "o|f", l_Model.GetPtr(&mdl), &nr))
return ade_set_error(L, "f", 0.0f);
polymodel *pm = mdl->Get();
if(pm == NULL)
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR) {
pm->rad = nr;
}
return ade_set_args(L, "f", pm->rad);
}
ADE_FUNC(isValid, l_Model, NULL, "True if valid, false or nil if not", "boolean", "Detects whether handle is valid")
{
model_h *mdl;
if(!ade_get_args(L, "o", l_Model.GetPtr(&mdl)))
return ADE_RETURN_NIL;
return mdl->IsValid();
}
//**********HANDLE: eyepoints
ADE_FUNC(__len, l_Eyepoints, NULL, "Gets the number of eyepoints on this model", "number", "Number of eyepoints on this model or 0 on error")
{
eyepoints_h *eph = NULL;
if (!ade_get_args(L, "o", l_Eyepoints.GetPtr(&eph)))
{
return ade_set_error(L, "i", 0);
}
if (!eph->IsValid())
{
return ade_set_error(L, "i", 0);
}
polymodel *pm = eph->Get();
if (pm == NULL)
{
return ade_set_error(L, "i", 0);
}
return ade_set_args(L, "i", pm->n_view_positions);
}
ADE_INDEXER(l_Eyepoints, "eyepoint", "Gets en eyepoint handle", "eyepoint", "eye handle or invalid handle on error")
{
eyepoints_h *eph = NULL;
int index = -1;
eye_h *eh = NULL;
if (!ade_get_args(L, "oi|o", l_Eyepoints.GetPtr(&eph), &index, l_Eyepoint.GetPtr(&eh)))
{
return ade_set_error(L, "o", l_Eyepoint.Set(eye_h()));
}
if (!eph->IsValid())
{
return ade_set_error(L, "o", l_Eyepoint.Set(eye_h()));
}
polymodel *pm = eph->Get();
if (pm == NULL)
{
return ade_set_error(L, "o", l_Eyepoint.Set(eye_h()));
}
index--; // Lua -> FS2
if (index < 0 || index >= pm->n_view_positions)
{
return ade_set_error(L, "o", l_Eyepoint.Set(eye_h()));
}
if (ADE_SETTING_VAR && eh && eh->IsValid())
{
LuaError(L, "Attempted to use incomplete feature: Eyepoint copy");
}
return ade_set_args(L, "o", l_Eyepoint.Set(eye_h(eph->GetID(), index)));
}
ADE_FUNC(isValid, l_Eyepoints, NULL, "Detects whether handle is valid or not", "boolean", "true if valid false otherwise")
{
eyepoints_h *eph;
if(!ade_get_args(L, "o", l_Eyepoints.GetPtr(&eph)))
return ADE_RETURN_FALSE;
return ade_set_args(L, "b", eph->IsValid());
}
//**********HANDLE: thrusters
ADE_FUNC(__len, l_Thrusters, NULL, "Number of thruster banks on the model", "number", "Number of thrusterbanks")
{
thrusters_h *trh;
if(!ade_get_args(L, "o", l_Thrusters.GetPtr(&trh)))
return ade_set_error(L, "i", -1);
if(!trh->IsValid())
return ade_set_error(L, "i", -1);
polymodel *pm = trh->Get();
if(pm == NULL)
return ade_set_error(L, "i", -1);
return ade_set_args(L, "i", pm->n_thrusters);
}
ADE_INDEXER(l_Thrusters, "number Index", "Array of all thrusterbanks on this thruster", "thrusterbank", "Handle to the thrusterbank or invalid handle if index is invalid")
{
thrusters_h *trh = NULL;
char *s = NULL;
thrusterbank_h newThr;
if (!ade_get_args(L, "os|o", l_Thrusters.GetPtr(&trh), &s, l_Thrusterbank.Get(&newThr)))
return ade_set_error(L, "o", l_Thrusterbank.Set(thrusterbank_h()));
polymodel *pm = trh->Get();
if (!trh->IsValid() || s == NULL || pm == NULL)
return ade_set_error(L, "o", l_Thrusterbank.Set(thrusterbank_h()));
//Determine index
int idx = atoi(s) - 1; //Lua->FS2
if (idx < 0 || idx >= pm->n_thrusters)
return ade_set_error(L, "o", l_Thrusterbank.Set(thrusterbank_h()));
thruster_bank* bank = &pm->thrusters[idx];
if (ADE_SETTING_VAR && trh != NULL)
{
if (newThr.isValid())
{
pm->thrusters[idx] = *(newThr.Get());
}
}
return ade_set_args(L, "o", l_Thrusterbank.Set(bank));
}
ADE_FUNC(isValid, l_Thrusters, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
thrusters_h *trh;
if(!ade_get_args(L, "o", l_Thrusters.GetPtr(&trh)))
return ADE_RETURN_NIL;
return ade_set_args(L, "b", trh->IsValid());
}
//**********HANDLE: thrusterbank
ADE_FUNC(__len, l_Thrusterbank, NULL, "Number of thrusters on this thrusterbank", "number", "Number of thrusters on this bank or 0 if handle is invalid")
{
thrusterbank_h *tbh = NULL;
if(!ade_get_args(L, "o", l_Thrusterbank.GetPtr(&tbh)))
return ade_set_error(L, "i", -1);
if(!tbh->isValid())
return ade_set_error(L, "i", -1);
thruster_bank* bank = tbh->Get();
return ade_set_args(L, "i", bank->num_points);
}
ADE_INDEXER(l_Thrusterbank, "number Index", "Array of glowpoint", "glowpoint", "Glowpoint, or invalid glowpoint handle on failure")
{
thrusterbank_h *tbh = NULL;
char *s = NULL;
glowpoint_h *glh = NULL;
if (!ade_get_args(L, "os|o", l_Thrusterbank.GetPtr(&tbh), &s, l_Glowpoint.GetPtr(&glh)))
return ade_set_error(L, "o", l_Glowpoint.Set(glowpoint_h()));
if (!tbh->isValid() || s==NULL)
return ade_set_error(L, "o", l_Glowpoint.Set(glowpoint_h()));
thruster_bank* bank = tbh->Get();
//Determine index
int idx = atoi(s) - 1; //Lua->FS2
if (idx < 0 || idx >= bank->num_points)
return ade_set_error(L, "o", l_Glowpoint.Set(glowpoint_h()));
glow_point* glp = &bank->points[idx];
if (ADE_SETTING_VAR && glh != NULL)
{
if (glh->isValid())
{
bank->points[idx] = *(glh->Get());
}
}
return ade_set_args(L, "o", l_Glowpoint.Set(glp));
}
ADE_FUNC(isValid, l_Thrusterbank, NULL, "Detectes if this handle is valid", "boolean", "true if this handle is valid, false otherwise")
{
thrusterbank_h* trh;
if(!ade_get_args(L, "o", l_Thrusterbank.GetPtr(&trh)))
return ADE_RETURN_FALSE;
if (!trh->isValid())
return ADE_RETURN_FALSE;
return ade_set_args(L, "b", trh->isValid());
}
//**********HANDLE: glowpoint
ADE_VIRTVAR(Position, l_Glowpoint, NULL, "The (local) vector to the position of the glowpoint", "vector", "The local vector to the glowpoint or nil invalid")
{
glowpoint_h *glh = NULL;
vec3d newVec;
if(!ade_get_args(L, "o|o", l_Glowpoint.GetPtr(&glh), l_Vector.Get(&newVec)))
return ADE_RETURN_NIL;
if (!glh->isValid())
return ADE_RETURN_NIL;
vec3d vec = glh->point->pnt;
if (ADE_SETTING_VAR)
{
glh->point->pnt = newVec;
}
return ade_set_args(L, "o", l_Vector.Set(vec));
}
ADE_VIRTVAR(Radius, l_Glowpoint, NULL, "The radius of the glowpoint", "number", "The radius of the glowpoint or -1 of invalid")
{
glowpoint_h* glh = NULL;
float newVal;
if(!ade_get_args(L, "o|f", l_Glowpoint.GetPtr(&glh), &newVal))
return ade_set_error(L, "f", -1.0f);
if (!glh->isValid())
return ade_set_error(L, "f", -1.0f);
float radius = glh->point->radius;
if (ADE_SETTING_VAR)
{
glh->point->radius = newVal;
}
return ade_set_args(L, "f", radius);
}
ADE_FUNC(isValid, l_Glowpoint, NULL, "Returns wether this handle is valid or not", "boolean", "True if handle is valid, false otherwise")
{
glowpoint_h glh = NULL;
if(!ade_get_args(L, "o", l_Glowpoint.Get(&glh)))
return ADE_RETURN_FALSE;
return ade_set_args(L, "b", glh.isValid());
}
class dockingbay_h : public model_h
{
private:
int dock_id;
public:
dockingbay_h(polymodel *pm, int dock_idx) : model_h(pm), dock_id(dock_idx) {}
dockingbay_h() : model_h(), dock_id(-1){}
bool IsValid()
{
if (!model_h::IsValid())
{
return false;
}
else
{
return dock_id >= 0 && dock_id < this->Get()->n_docks;
}
}
dock_bay* getDockingBay()
{
if (!this->IsValid())
{
return NULL;
}
return &this->Get()->docking_bays[dock_id];
}
};
ade_obj<dockingbay_h> l_Dockingbay("dockingbay", "Handle to a model docking bay");
//**********HANDLE: dockingbays
ADE_INDEXER(l_Dockingbays, "dockingbay", "Gets a dockingbay handle from this model. If a string is given then a dockingbay with that name is searched.", "dockingbay", "Handle or invalid handle on error")
{
dockingbays_h *dbhp = NULL;
int index = -1;
dockingbay_h *newVal = NULL;
if (lua_isnumber(L, 2))
{
if (!ade_get_args(L, "oi|o", l_Dockingbays.GetPtr(&dbhp), &index, l_Dockingbay.GetPtr(&newVal)))
return ade_set_error(L, "o", l_Dockingbay.Set(dockingbay_h()));
if (!dbhp->IsValid())
return ade_set_error(L, "o", l_Dockingbay.Set(dockingbay_h()));
index--; // Lua --> C/C++
}
else
{
char* name = NULL;
if (!ade_get_args(L, "os|o", l_Dockingbays.GetPtr(&dbhp), &name, l_Dockingbay.GetPtr(&newVal)))
{
return ade_set_error(L, "o", l_Dockingbay.Set(dockingbay_h()));
}
if (!dbhp->IsValid() && name != NULL)
return ade_set_error(L, "o", l_Dockingbay.Set(dockingbay_h()));
index = model_find_dock_name_index(dbhp->GetID(), name);
}
polymodel *pm = dbhp->Get();
if (index < 0 || index >= pm->n_docks)
{
return ade_set_error(L, "o", l_Dockingbay.Set(dockingbay_h()));
}
return ade_set_args(L, "o", l_Dockingbay.Set(dockingbay_h(pm, index)));
}
ADE_FUNC(__len, l_Dockingbays, NULL, "Retrieves the number of dockingbays on this model", "number", "number of docking bays or 0 on error")
{
dockingbays_h *dbhp = NULL;
if (!ade_get_args(L, "o", l_Dockingbays.GetPtr(&dbhp)))
return ade_set_error(L, "i", 0);
if (!dbhp->IsValid())
return ade_set_error(L, "i", 0);
return ade_set_args(L, "i", dbhp->Get()->n_docks);
}
//**********HANDLE: dockingbay
ADE_FUNC(__len, l_Dockingbay, NULL, "Gets the number of docking points in this bay", "number", "The number of docking points or 0 on error")
{
dockingbay_h* dbh = NULL;
if (!ade_get_args(L, "o", l_Dockingbay.GetPtr(&dbh)))
{
return ade_set_error(L, "i", 0);
}
if (dbh == NULL || !dbh->IsValid())
{
return ade_set_error(L, "i", 0);
}
return ade_set_args(L, "i", dbh->getDockingBay()->num_slots);
}
ADE_FUNC(getName, l_Dockingbay, NULL, "Gets the name of this docking bay", "string", "The name or an empty string on error")
{
dockingbay_h* dbh = NULL;
if (!ade_get_args(L, "o", l_Dockingbay.GetPtr(&dbh)))
{
return ade_set_error(L, "s", "");
}
if (dbh == NULL || !dbh->IsValid())
{
return ade_set_error(L, "s", "");
}
dock_bay* dbp = dbh->getDockingBay();
return ade_set_args(L, "s", dbp->name);
}
ADE_FUNC(getPoint, l_Dockingbay, "number index", "Gets the location of a docking point in this bay", "vector", "The local location or null vector on error")
{
dockingbay_h* dbh = NULL;
int index = -1;
if (!ade_get_args(L, "oi", l_Dockingbay.GetPtr(&dbh), &index))
{
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
}
index--; // Lua --> C/C++
if (dbh == NULL || !dbh->IsValid())
{
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
}
dock_bay* dbp = dbh->getDockingBay();
if (index < 0 || index > dbp->num_slots)
{
LuaError(L, "Invalid dock bay index %d!", (index + 1));
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
}
return ade_set_args(L, "o", l_Vector.Set(dbp->pnt[index]));
}
ADE_FUNC(getNormal, l_Dockingbay, "number index", "Gets the normal of a docking point in this bay", "vector", "The normal vector or null vector on error")
{
dockingbay_h* dbh = NULL;
int index = -1;
if (!ade_get_args(L, "oi", l_Dockingbay.GetPtr(&dbh), &index))
{
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
}
index--; // Lua --> C/C++
if (dbh == NULL || !dbh->IsValid())
{
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
}