/
OOJSShip.m
4303 lines (3447 loc) · 121 KB
/
OOJSShip.m
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
/*
OOJSShip.m
Oolite
Copyright (C) 2004-2013 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import "OOJSShip.h"
#import "OOJSEntity.h"
#import "OOJSWormhole.h"
#import "OOJSVector.h"
#import "OOJSQuaternion.h"
#import "OOJSEquipmentInfo.h"
#import "OOJavaScriptEngine.h"
#import "ShipEntity.h"
#import "ShipEntityAI.h"
#import "ShipEntityScriptMethods.h"
#import "StationEntity.h"
#import "WormholeEntity.h"
#import "AI.h"
#import "OOStringParsing.h"
#import "EntityOOJavaScriptExtensions.h"
#import "OORoleSet.h"
#import "OOJSPlayer.h"
#import "PlayerEntity.h"
#import "PlayerEntityScriptMethods.h"
#import "OOShipGroup.h"
#import "OOShipRegistry.h"
#import "OOEquipmentType.h"
#import "ResourceManager.h"
#import "OOCollectionExtractors.h"
#import "OOMesh.h"
#import "OOConstToString.h"
#import "OOEntityFilterPredicate.h"
#import "OOCharacter.h"
static JSObject *sShipPrototype;
static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value);
static JSBool ShipSetScript(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetAI(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSwitchAI(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipExitAI(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipReactToAIMessage(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSendAIMessage(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipDeployEscorts(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipDockEscorts(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipHasRole(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipEjectItem(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipEjectSpecificItem(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSpawn(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipDealEnergyDamage(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipExplode(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRemove(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRunLegacyScriptActions(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipCommsMessage(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipFireECM(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipAbandonShip(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipCanAwardEquipment(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipAwardEquipment(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipAdjustCargo(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRequestHelpFromGroup(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPatrolReportIn(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRemoveEquipment(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRestoreSubEntities(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipHasEquipmentProviding(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipEquipmentStatus(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetEquipmentStatus(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSelectNewMissile(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipFireMissile(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipFindNearestStation(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetBounty(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetCargo(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetMaterials(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetShaders(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipExitSystem(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipUpdateEscortFormation(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipClearDefenseTargets(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipAddDefenseTarget(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRemoveDefenseTarget(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipAddCollisionException(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRemoveCollisionException(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipGetMaterials(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipGetShaders(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipBecomeCascadeExplosion(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipBroadcastCascadeImminent(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipBroadcastDistressMessage(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipOfferToEscort(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipMarkTargetForFines(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipEnterWormhole(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipNotifyGroupOfWormhole(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipThrowSpark(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformAttack(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformCollect(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformEscort(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformFaceDestination(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformFlee(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformFlyToRangeFromDestination(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformHold(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformIdle(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformIntercept(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformLandOnPlanet(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformMining(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformScriptedAI(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformScriptedAttackAI(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformStop(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipPerformTumble(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRequestDockingInstructions(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipRecallDockingInstructions(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipCheckCourseToDestination(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipGetSafeCourseToDestination(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipCheckScanner(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipThreatAssessment(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipDamageAssessment(JSContext *context, uintN argc, jsval *vp);
static double ShipThreatAssessmentWeapon(OOWeaponType wt);
static JSBool ShipSetCargoType(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipSetCrew(JSContext *context, uintN argc, jsval *vp);
static BOOL RemoveOrExplodeShip(JSContext *context, uintN argc, jsval *vp, BOOL explode);
static JSBool ShipSetMaterialsInternal(JSContext *context, uintN argc, jsval *vp, ShipEntity *thisEnt, BOOL fromShaders);
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipStaticKeys(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipStaticRoles(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipStaticRoleIsInCategory(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipStaticShipDataForKey(JSContext *context, uintN argc, jsval *vp);
static JSClass sShipClass =
{
"Ship",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub, // addProperty
JS_PropertyStub, // delProperty
ShipGetProperty, // getProperty
ShipSetProperty, // setProperty
JS_EnumerateStub, // enumerate
JS_ResolveStub, // resolve
JS_ConvertStub, // convert
OOJSObjectWrapperFinalize,// finalize
JSCLASS_NO_OPTIONAL_MEMBERS
};
/* It turns out that the value in SpiderMonkey used to identify these
* enums is an 8-bit signed int:
* developer.mozilla.org/en/docs/SpiderMonkey/JSAPI_Reference/JSPropertySpec
* which puts a limit of 256 properties on the ship object. Moved the
* enum to start at -128, so we can use the full 256 rather than just
* 128 of them. I don't think any of our other classes are getting
* close to the limit yet.
* - CIM 29/9/2013
*/
enum
{
// Property IDs
kShip_accuracy = -128, // the ship's accuracy, float, read/write
kShip_aftWeapon, // the ship's aft weapon, equipmentType, read/write
kShip_AI, // AI state machine name, string, read-only
kShip_AIScript, // AI script, Script, read-only
kShip_AIScriptWakeTime, // next wakeup time, integer, read/write
kShip_AIState, // AI state machine state, string, read/write
kShip_AIFoundTarget, // AI "found target", entity, read/write
kShip_AIPrimaryAggressor, // AI "primary aggressor", entity, read/write
kShip_alertCondition, // number 0-3, read-only, combat alert level
kShip_autoAI, // bool, read-only, auto_ai from shipdata
kShip_autoWeapons, // bool, read-only, auto_weapons from shipdata
kShip_beaconCode, // beacon code, string, read/write
kShip_beaconLabel, // beacon label, string, read/write
kShip_boundingBox, // boundingBox, vector, read-only
kShip_bounty, // bounty, unsigned int, read/write
kShip_cargoList, // cargo on board, array of objects, read-only
kShip_cargoSpaceAvailable, // free cargo space, integer, read-only
kShip_cargoSpaceCapacity, // maximum cargo, integer, read/write
kShip_cargoSpaceUsed, // cargo on board, integer, read-only
kShip_collisionExceptions, // collision exception list, array, read-only
kShip_contracts, // cargo contracts contracts, array - strings & whatnot, read only
kShip_commodity, // commodity of a ship, read only
kShip_commodityAmount, // commodityAmount of a ship, read only
kShip_cloakAutomatic, // should cloack start by itself or by script, read/write
kShip_crew, // crew, list, read only
kShip_cruiseSpeed, // desired cruising speed, number, read only
kShip_currentWeapon, // the ship's active weapon, equipmentType, read/write
kShip_dataKey, // string, read-only, shipdata.plist key
kShip_defenseTargets, // array, read-only, defense targets
kShip_desiredRange, // desired Range, double, read/write
kShip_desiredSpeed, // AI desired flight speed, double, read/write
kShip_destination, // flight destination, Vector, read/write
kShip_destinationSystem, // destination system, number, read/write
kShip_displayName, // name displayed on screen, string, read/write
kShip_dockingInstructions, // name displayed on screen, string, read/write
kShip_energyRechargeRate, // energy recharge rate, float, read-only
kShip_entityPersonality, // per-ship random number, int, read-only
kShip_equipment, // the ship's equipment, array of EquipmentInfo, read only
kShip_escortGroup, // group, ShipGroup, read-only
kShip_escorts, // deployed escorts, array of Ship, read-only
kShip_exhaustEmissiveColor, // exhaust emissive color, array, read/write
kShip_exhausts, // exhausts, array, read-only
kShip_extraCargo, // cargo space increase granted by large cargo bay, int, read-only
kShip_flashers, // flashers, array, read-only
kShip_forwardWeapon, // the ship's forward weapon, equipmentType, read/write
kShip_fuel, // fuel, float, read/write
kShip_fuelChargeRate, // fuel scoop rate & charge multiplier, float, read-only
kShip_group, // group, ShipGroup, read/write
kShip_hasHostileTarget, // has hostile target, boolean, read-only
kShip_hasHyperspaceMotor, // has hyperspace motor, boolean, read-only
kShip_hasSuspendedAI, // AI has suspended states, boolean, read-only
kShip_heading, // forwardVector of a ship, read-only
kShip_heatInsulation, // hull heat insulation, double, read/write
kShip_homeSystem, // home system, number, read/write
kShip_hyperspaceSpinTime, // hyperspace spin time, float, read/write
kShip_injectorBurnRate, // injector burn rate, number, read/write dLY/s
kShip_injectorSpeedFactor, // injector speed factor, number, read/write
kShip_isBeacon, // is beacon, boolean, read-only
kShip_isBoulder, // is a boulder (generates splinters), boolean, read/write
kShip_isCargo, // contains cargo, boolean, read-only
kShip_isCloaked, // cloaked, boolean, read/write (if cloaking device installed)
kShip_isDerelict, // is an abandoned ship, boolean, read-only
kShip_isFrangible, // frangible, boolean, read-only
kShip_isFleeing, // is fleeing, boolean, read-only
kShip_isJamming, // jamming scanners, boolean, read/write (if jammer installed)
kShip_isMinable, // is a sensible target for mining, boolean, read-only
kShip_isMine, // is mine, boolean, read-only
kShip_isMissile, // is missile, boolean, read-only
kShip_isPiloted, // is piloted, boolean, read-only (includes stations)
kShip_isPirate, // is pirate, boolean, read-only
kShip_isPirateVictim, // is pirate victim, boolean, read-only
kShip_isPolice, // is police, boolean, read-only
kShip_isRock, // is a rock (hermits included), boolean, read-only
kShip_isThargoid, // is thargoid, boolean, read-only
kShip_isTurret, // is turret, boolean, read-only
kShip_isTrader, // is trader, boolean, read-only
kShip_isWeapon, // is missile or mine, boolean, read-only
kShip_laserHeatLevel, // active laser temperature, float, read-only
kShip_laserHeatLevelAft, // aft laser temperature, float, read-only
kShip_laserHeatLevelForward, // fore laser temperature, float, read-only
kShip_laserHeatLevelPort, // port laser temperature, float, read-only
kShip_laserHeatLevelStarboard, // starboard laser temperature, float, read-only
kShip_lightsActive, // flasher/shader light flag, boolean, read/write
kShip_markedForFines, // has been marked for fines
kShip_maxEscorts, // maximum escort count, int, read/write
kShip_maxPitch, // maximum flight pitch, double, read-only
kShip_maxSpeed, // maximum flight speed, double, read-only
kShip_maxRoll, // maximum flight roll, double, read-only
kShip_maxYaw, // maximum flight yaw, double, read-only
kShip_maxThrust, // maximum thrust, double, read-only
kShip_missileCapacity, // max missiles capacity, integer, read-only
kShip_missileLoadTime, // missile load time, double, read/write
kShip_missiles, // the ship's missiles / external storage, array of equipmentTypes, read only
kShip_name, // name, string, read-only
kShip_parcelCount, // number of parcels on ship, integer, read-only
kShip_parcels, // parcel contracts, array - strings & whatnot, read only
kShip_passengerCapacity, // amount of passenger space on ship, integer, read-only
kShip_passengerCount, // number of passengers on ship, integer, read-only
kShip_passengers, // passengers contracts, array - strings & whatnot, read only
kShip_pitch, // pitch level, float, read-only
kShip_portWeapon, // the ship's port weapon, equipmentType, read/write
kShip_potentialCollider, // "proximity alert" ship, Entity, read-only
kShip_primaryRole, // Primary role, string, read/write
kShip_reactionTime, // AI reaction time, read/write
kShip_reportAIMessages, // report AI messages, boolean, read/write
kShip_roleWeights, // roles and weights, dictionary, read-only
kShip_roles, // roles, array, read-only
kShip_roll, // roll level, float, read-only
kShip_savedCoordinates, // coordinates in system space for AI use, Vector, read/write
kShip_scanDescription, // STE scan class label, string, read/write
kShip_scannerDisplayColor1, // color of lollipop shown on scanner, array, read/write
kShip_scannerDisplayColor2, // color of lollipop shown on scanner when flashing, array, read/write
kShip_scannerHostileDisplayColor1, // color of lollipop shown on scanner, array, read/write
kShip_scannerHostileDisplayColor2, // color of lollipop shown on scanner when flashing, array, read/write
kShip_scannerRange, // scanner range, double, read-only
kShip_script, // script, Script, read-only
kShip_scriptedMisjump, // next jump will miss if set to true, boolean, read/write
kShip_scriptedMisjumpRange, // 0..1 range of next misjump, float, read/write
kShip_scriptInfo, // arbitrary data for scripts, dictionary, read-only
kShip_shipClassName, // ship type name, string, read/write
kShip_shipUniqueName, // uniqish name, string, read/write
kShip_speed, // current flight speed, double, read-only
kShip_starboardWeapon, // the ship's starboard weapon, equipmentType, read/write
kShip_subEntities, // subentities, array of Ship, read-only
kShip_subEntityCapacity, // max subentities for this ship, int, read-only
kShip_subEntityRotation, // subentity rotation velocity, quaternion, read/write
kShip_sunGlareFilter, // sun glare filter multiplier, float, read/write
kShip_target, // target, Ship, read/write
kShip_temperature, // hull temperature, double, read/write
kShip_thrust, // the ship's thrust, double, read/write
kShip_thrustVector, // thrust-related component of velocity, vector, read-only
kShip_trackCloseContacts, // generate close contact events, boolean, read/write
kShip_vectorForward, // forwardVector of a ship, read-only
kShip_vectorRight, // rightVector of a ship, read-only
kShip_vectorUp, // upVector of a ship, read-only
kShip_velocity, // velocity, vector, read/write
kShip_weaponFacings, // available facings, int, read-only
kShip_weaponPositionAft, // weapon offset, vector, read-only
kShip_weaponPositionForward, // weapon offset, vector, read-only
kShip_weaponPositionPort, // weapon offset, vector, read-only
kShip_weaponPositionStarboard, // weapon offset, vector, read-only
kShip_weaponRange, // weapon range, double, read-only
kShip_withinStationAegis, // within main station aegis, boolean, read/write
kShip_yaw, // yaw level, float, read-only
};
static JSPropertySpec sShipProperties[] =
{
// JS name ID flags
{ "accuracy", kShip_accuracy, OOJS_PROP_READWRITE_CB },
{ "aftWeapon", kShip_aftWeapon, OOJS_PROP_READWRITE_CB },
{ "AI", kShip_AI, OOJS_PROP_READONLY_CB },
{ "AIScript", kShip_AIScript, OOJS_PROP_READONLY_CB },
{ "AIScriptWakeTime", kShip_AIScriptWakeTime, OOJS_PROP_READWRITE_CB },
{ "AIState", kShip_AIState, OOJS_PROP_READWRITE_CB },
{ "AIFoundTarget", kShip_AIFoundTarget, OOJS_PROP_READWRITE_CB },
{ "AIPrimaryAggressor", kShip_AIPrimaryAggressor, OOJS_PROP_READWRITE_CB },
{ "alertCondition", kShip_alertCondition, OOJS_PROP_READONLY_CB },
{ "autoAI", kShip_autoAI, OOJS_PROP_READONLY_CB },
{ "autoWeapons", kShip_autoWeapons, OOJS_PROP_READONLY_CB },
{ "beaconCode", kShip_beaconCode, OOJS_PROP_READWRITE_CB },
{ "beaconLabel", kShip_beaconLabel, OOJS_PROP_READWRITE_CB },
{ "boundingBox", kShip_boundingBox, OOJS_PROP_READONLY_CB },
{ "bounty", kShip_bounty, OOJS_PROP_READWRITE_CB },
{ "cargoList", kShip_cargoList, OOJS_PROP_READONLY_CB },
{ "cargoSpaceUsed", kShip_cargoSpaceUsed, OOJS_PROP_READONLY_CB },
{ "cargoSpaceCapacity", kShip_cargoSpaceCapacity, OOJS_PROP_READWRITE_CB },
{ "cargoSpaceAvailable", kShip_cargoSpaceAvailable, OOJS_PROP_READONLY_CB },
{ "collisionExceptions", kShip_collisionExceptions, OOJS_PROP_READONLY_CB },
{ "commodity", kShip_commodity, OOJS_PROP_READONLY_CB },
{ "commodityAmount", kShip_commodityAmount, OOJS_PROP_READONLY_CB },
// contracts instead of cargo to distinguish them from the manifest
{ "contracts", kShip_contracts, OOJS_PROP_READONLY_CB },
{ "cloakAutomatic", kShip_cloakAutomatic, OOJS_PROP_READWRITE_CB},
{ "crew", kShip_crew, OOJS_PROP_READONLY_CB },
{ "cruiseSpeed", kShip_cruiseSpeed, OOJS_PROP_READONLY_CB },
{ "currentWeapon", kShip_currentWeapon, OOJS_PROP_READWRITE_CB },
{ "dataKey", kShip_dataKey, OOJS_PROP_READONLY_CB },
{ "defenseTargets", kShip_defenseTargets, OOJS_PROP_READONLY_CB },
{ "desiredRange", kShip_desiredRange, OOJS_PROP_READWRITE_CB },
{ "desiredSpeed", kShip_desiredSpeed, OOJS_PROP_READWRITE_CB },
{ "destination", kShip_destination, OOJS_PROP_READWRITE_CB },
{ "destinationSystem", kShip_destinationSystem, OOJS_PROP_READWRITE_CB },
{ "displayName", kShip_displayName, OOJS_PROP_READWRITE_CB },
{ "dockingInstructions", kShip_dockingInstructions, OOJS_PROP_READONLY_CB },
{ "energyRechargeRate", kShip_energyRechargeRate, OOJS_PROP_READWRITE_CB },
{ "entityPersonality", kShip_entityPersonality, OOJS_PROP_READWRITE_CB },
{ "equipment", kShip_equipment, OOJS_PROP_READONLY_CB },
{ "escorts", kShip_escorts, OOJS_PROP_READONLY_CB },
{ "escortGroup", kShip_escortGroup, OOJS_PROP_READONLY_CB },
{ "exhaustEmissiveColor", kShip_exhaustEmissiveColor, OOJS_PROP_READWRITE_CB },
{ "exhausts", kShip_exhausts, OOJS_PROP_READONLY_CB },
{ "extraCargo", kShip_extraCargo, OOJS_PROP_READONLY_CB },
{ "flashers", kShip_flashers, OOJS_PROP_READONLY_CB },
{ "forwardWeapon", kShip_forwardWeapon, OOJS_PROP_READWRITE_CB },
{ "fuel", kShip_fuel, OOJS_PROP_READWRITE_CB },
{ "fuelChargeRate", kShip_fuelChargeRate, OOJS_PROP_READONLY_CB },
{ "group", kShip_group, OOJS_PROP_READWRITE_CB },
{ "hasHostileTarget", kShip_hasHostileTarget, OOJS_PROP_READONLY_CB },
{ "hasHyperspaceMotor", kShip_hasHyperspaceMotor, OOJS_PROP_READONLY_CB },
{ "hasSuspendedAI", kShip_hasSuspendedAI, OOJS_PROP_READONLY_CB },
{ "heatInsulation", kShip_heatInsulation, OOJS_PROP_READWRITE_CB },
{ "heading", kShip_heading, OOJS_PROP_READONLY_CB },
{ "homeSystem", kShip_homeSystem, OOJS_PROP_READWRITE_CB },
{ "hyperspaceSpinTime", kShip_hyperspaceSpinTime, OOJS_PROP_READWRITE_CB },
{ "injectorBurnRate", kShip_injectorBurnRate, OOJS_PROP_READWRITE_CB },
{ "injectorSpeedFactor", kShip_injectorSpeedFactor, OOJS_PROP_READWRITE_CB },
{ "homeSystem", kShip_homeSystem, OOJS_PROP_READWRITE_CB },
{ "isBeacon", kShip_isBeacon, OOJS_PROP_READONLY_CB },
{ "isCloaked", kShip_isCloaked, OOJS_PROP_READWRITE_CB },
{ "isCargo", kShip_isCargo, OOJS_PROP_READONLY_CB },
{ "isDerelict", kShip_isDerelict, OOJS_PROP_READONLY_CB },
{ "isFrangible", kShip_isFrangible, OOJS_PROP_READONLY_CB },
{ "isFleeing", kShip_isFleeing, OOJS_PROP_READONLY_CB },
{ "isJamming", kShip_isJamming, OOJS_PROP_READONLY_CB },
{ "isMinable", kShip_isMinable, OOJS_PROP_READONLY_CB },
{ "isMine", kShip_isMine, OOJS_PROP_READONLY_CB },
{ "isMissile", kShip_isMissile, OOJS_PROP_READONLY_CB },
{ "isPiloted", kShip_isPiloted, OOJS_PROP_READONLY_CB },
{ "isPirate", kShip_isPirate, OOJS_PROP_READONLY_CB },
{ "isPirateVictim", kShip_isPirateVictim, OOJS_PROP_READONLY_CB },
{ "isPolice", kShip_isPolice, OOJS_PROP_READONLY_CB },
{ "isRock", kShip_isRock, OOJS_PROP_READONLY_CB },
{ "isBoulder", kShip_isBoulder, OOJS_PROP_READWRITE_CB },
{ "isThargoid", kShip_isThargoid, OOJS_PROP_READONLY_CB },
{ "isTurret", kShip_isTurret, OOJS_PROP_READONLY_CB },
{ "isTrader", kShip_isTrader, OOJS_PROP_READONLY_CB },
{ "isWeapon", kShip_isWeapon, OOJS_PROP_READONLY_CB },
{ "laserHeatLevel", kShip_laserHeatLevel, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelAft", kShip_laserHeatLevelAft, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelForward", kShip_laserHeatLevelForward, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelPort", kShip_laserHeatLevelPort, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelStarboard", kShip_laserHeatLevelStarboard, OOJS_PROP_READONLY_CB },
{ "lightsActive", kShip_lightsActive, OOJS_PROP_READWRITE_CB },
{ "markedForFines", kShip_markedForFines, OOJS_PROP_READONLY_CB },
{ "maxEscorts", kShip_maxEscorts, OOJS_PROP_READWRITE_CB },
{ "maxPitch", kShip_maxPitch, OOJS_PROP_READWRITE_CB },
{ "maxSpeed", kShip_maxSpeed, OOJS_PROP_READWRITE_CB },
{ "maxRoll", kShip_maxRoll, OOJS_PROP_READWRITE_CB },
{ "maxYaw", kShip_maxYaw, OOJS_PROP_READWRITE_CB },
{ "maxThrust", kShip_maxThrust, OOJS_PROP_READWRITE_CB },
{ "missileCapacity", kShip_missileCapacity, OOJS_PROP_READONLY_CB },
{ "missileLoadTime", kShip_missileLoadTime, OOJS_PROP_READWRITE_CB },
{ "missiles", kShip_missiles, OOJS_PROP_READONLY_CB },
{ "name", kShip_name, OOJS_PROP_READWRITE_CB },
{ "parcelCount", kShip_parcelCount, OOJS_PROP_READONLY_CB },
{ "parcels", kShip_parcels, OOJS_PROP_READONLY_CB },
{ "passengerCount", kShip_passengerCount, OOJS_PROP_READONLY_CB },
{ "passengerCapacity", kShip_passengerCapacity, OOJS_PROP_READONLY_CB },
{ "passengers", kShip_passengers, OOJS_PROP_READONLY_CB },
{ "pitch", kShip_pitch, OOJS_PROP_READONLY_CB },
{ "portWeapon", kShip_portWeapon, OOJS_PROP_READWRITE_CB },
{ "potentialCollider", kShip_potentialCollider, OOJS_PROP_READONLY_CB },
{ "primaryRole", kShip_primaryRole, OOJS_PROP_READWRITE_CB },
{ "reactionTime", kShip_reactionTime, OOJS_PROP_READWRITE_CB },
{ "reportAIMessages", kShip_reportAIMessages, OOJS_PROP_READWRITE_CB },
{ "roleWeights", kShip_roleWeights, OOJS_PROP_READONLY_CB },
{ "roles", kShip_roles, OOJS_PROP_READONLY_CB },
{ "roll", kShip_roll, OOJS_PROP_READONLY_CB },
{ "savedCoordinates", kShip_savedCoordinates, OOJS_PROP_READWRITE_CB },
{ "scanDescription", kShip_scanDescription, OOJS_PROP_READWRITE_CB },
{ "scannerDisplayColor1", kShip_scannerDisplayColor1, OOJS_PROP_READWRITE_CB },
{ "scannerDisplayColor2", kShip_scannerDisplayColor2, OOJS_PROP_READWRITE_CB },
{ "scannerHostileDisplayColor1", kShip_scannerHostileDisplayColor1, OOJS_PROP_READWRITE_CB },
{ "scannerHostileDisplayColor2", kShip_scannerHostileDisplayColor2, OOJS_PROP_READWRITE_CB },
{ "scannerRange", kShip_scannerRange, OOJS_PROP_READONLY_CB },
{ "script", kShip_script, OOJS_PROP_READONLY_CB },
{ "scriptedMisjump", kShip_scriptedMisjump, OOJS_PROP_READWRITE_CB },
{ "scriptedMisjumpRange", kShip_scriptedMisjumpRange, OOJS_PROP_READWRITE_CB },
{ "scriptInfo", kShip_scriptInfo, OOJS_PROP_READONLY_CB },
{ "shipClassName", kShip_shipClassName, OOJS_PROP_READWRITE_CB },
{ "shipUniqueName", kShip_shipUniqueName, OOJS_PROP_READWRITE_CB },
{ "speed", kShip_speed, OOJS_PROP_READONLY_CB },
{ "starboardWeapon", kShip_starboardWeapon, OOJS_PROP_READWRITE_CB },
{ "subEntities", kShip_subEntities, OOJS_PROP_READONLY_CB },
{ "subEntityCapacity", kShip_subEntityCapacity, OOJS_PROP_READONLY_CB },
{ "subEntityRotation", kShip_subEntityRotation, OOJS_PROP_READWRITE_CB },
{ "sunGlareFilter", kShip_sunGlareFilter, OOJS_PROP_READWRITE_CB },
{ "target", kShip_target, OOJS_PROP_READWRITE_CB },
{ "temperature", kShip_temperature, OOJS_PROP_READWRITE_CB },
{ "thrust", kShip_thrust, OOJS_PROP_READWRITE_CB },
{ "thrustVector", kShip_thrustVector, OOJS_PROP_READONLY_CB },
{ "trackCloseContacts", kShip_trackCloseContacts, OOJS_PROP_READWRITE_CB },
{ "vectorForward", kShip_vectorForward, OOJS_PROP_READONLY_CB },
{ "vectorRight", kShip_vectorRight, OOJS_PROP_READONLY_CB },
{ "vectorUp", kShip_vectorUp, OOJS_PROP_READONLY_CB },
{ "velocity", kShip_velocity, OOJS_PROP_READWRITE_CB },
{ "weaponFacings", kShip_weaponFacings, OOJS_PROP_READONLY_CB },
{ "weaponPositionAft", kShip_weaponPositionAft, OOJS_PROP_READONLY_CB },
{ "weaponPositionForward", kShip_weaponPositionForward, OOJS_PROP_READONLY_CB },
{ "weaponPositionPort", kShip_weaponPositionPort, OOJS_PROP_READONLY_CB },
{ "weaponPositionStarboard", kShip_weaponPositionStarboard, OOJS_PROP_READONLY_CB },
{ "weaponRange", kShip_weaponRange, OOJS_PROP_READONLY_CB },
{ "withinStationAegis", kShip_withinStationAegis, OOJS_PROP_READONLY_CB },
{ "yaw", kShip_yaw, OOJS_PROP_READONLY_CB },
{ 0 }
};
static JSFunctionSpec sShipMethods[] =
{
// JS name Function min args
{ "abandonShip", ShipAbandonShip, 0 },
{ "addCollisionException", ShipAddCollisionException, 1 },
{ "addDefenseTarget", ShipAddDefenseTarget, 1 },
{ "adjustCargo", ShipAdjustCargo, 2 },
{ "awardEquipment", ShipAwardEquipment, 1 },
{ "becomeCascadeExplosion", ShipBecomeCascadeExplosion, 0 },
{ "broadcastCascadeImminent", ShipBroadcastCascadeImminent, 0 },
{ "broadcastDistressMessage", ShipBroadcastDistressMessage, 0 },
{ "canAwardEquipment", ShipCanAwardEquipment, 1 },
{ "checkCourseToDestination", ShipCheckCourseToDestination, 0 },
{ "checkScanner", ShipCheckScanner, 0 },
{ "clearDefenseTargets", ShipClearDefenseTargets, 0 },
{ "commsMessage", ShipCommsMessage, 1 },
{ "damageAssessment", ShipDamageAssessment, 0 },
{ "dealEnergyDamage", ShipDealEnergyDamage, 2 },
{ "deployEscorts", ShipDeployEscorts, 0 },
{ "dockEscorts", ShipDockEscorts, 0 },
{ "dumpCargo", ShipDumpCargo, 0 },
{ "ejectItem", ShipEjectItem, 1 },
{ "ejectSpecificItem", ShipEjectSpecificItem, 1 },
{ "enterWormhole", ShipEnterWormhole, 0 },
{ "equipmentStatus", ShipEquipmentStatus, 1 },
{ "exitAI", ShipExitAI, 0 },
{ "exitSystem", ShipExitSystem, 0 },
{ "explode", ShipExplode, 0 },
{ "fireECM", ShipFireECM, 0 },
{ "fireMissile", ShipFireMissile, 0 },
{ "findNearestStation", ShipFindNearestStation, 0 },
{ "getMaterials", ShipGetMaterials, 0 },
{ "getSafeCourseToDestination", ShipGetSafeCourseToDestination, 0 },
{ "getShaders", ShipGetShaders, 0 },
{ "hasEquipmentProviding", ShipHasEquipmentProviding, 1 },
{ "hasRole", ShipHasRole, 1 },
{ "markTargetForFines", ShipMarkTargetForFines, 0 },
{ "notifyGroupOfWormhole", ShipNotifyGroupOfWormhole, 0 },
{ "offerToEscort", ShipOfferToEscort, 1 },
{ "patrolReportIn", ShipPatrolReportIn, 1},
{ "performAttack", ShipPerformAttack, 0 },
{ "performCollect", ShipPerformCollect, 0 },
{ "performEscort", ShipPerformEscort, 0 },
{ "performFaceDestination", ShipPerformFaceDestination, 0 },
{ "performFlee", ShipPerformFlee, 0 },
{ "performFlyToRangeFromDestination", ShipPerformFlyToRangeFromDestination, 0 },
{ "performHold", ShipPerformHold, 0 },
{ "performIdle", ShipPerformIdle, 0 },
{ "performIntercept", ShipPerformIntercept, 0 },
{ "performLandOnPlanet", ShipPerformLandOnPlanet, 0 },
{ "performMining", ShipPerformMining, 0 },
{ "performScriptedAI", ShipPerformScriptedAI, 0 },
{ "performScriptedAttackAI", ShipPerformScriptedAttackAI, 0 },
{ "performStop", ShipPerformStop, 0 },
{ "performTumble", ShipPerformTumble, 0 },
{ "reactToAIMessage", ShipReactToAIMessage, 1 },
{ "remove", ShipRemove, 0 },
{ "removeCollisionException", ShipRemoveCollisionException, 1 },
{ "removeDefenseTarget", ShipRemoveDefenseTarget, 1 },
{ "removeEquipment", ShipRemoveEquipment, 1 },
{ "requestHelpFromGroup", ShipRequestHelpFromGroup, 0},
{ "requestDockingInstructions", ShipRequestDockingInstructions, 0},
{ "recallDockingInstructions", ShipRecallDockingInstructions, 0},
{ "restoreSubEntities", ShipRestoreSubEntities, 0 },
{ "__runLegacyScriptActions", ShipRunLegacyScriptActions, 2 }, // Deliberately not documented
{ "selectNewMissile", ShipSelectNewMissile, 0 },
{ "sendAIMessage", ShipSendAIMessage, 1 },
{ "setAI", ShipSetAI, 1 },
{ "setBounty", ShipSetBounty, 2 },
{ "setCargo", ShipSetCargo, 1 },
{ "setCargoType", ShipSetCargoType, 1 },
{ "setCrew", ShipSetCrew, 1 },
{ "setEquipmentStatus", ShipSetEquipmentStatus, 2 },
{ "setMaterials", ShipSetMaterials, 1 },
{ "setScript", ShipSetScript, 1 },
{ "setShaders", ShipSetShaders, 2 },
{ "spawn", ShipSpawn, 1 },
// spawnOne() is defined in the prefix script.
{ "switchAI", ShipSwitchAI, 1 },
{ "threatAssessment", ShipThreatAssessment, 1 },
{ "throwSpark", ShipThrowSpark, 0 },
{ "updateEscortFormation", ShipUpdateEscortFormation, 0 },
{ 0 }
};
static JSFunctionSpec sShipStaticMethods[] =
{
// JS name Function min args
{ "keys", ShipStaticKeys, 0 },
{ "keysForRole", ShipStaticKeysForRole, 1 },
{ "roleIsInCategory", ShipStaticRoleIsInCategory, 2 },
{ "roles", ShipStaticRoles, 0 },
{ "shipDataForKey", ShipStaticShipDataForKey, 1 },
{ 0 }
};
DEFINE_JS_OBJECT_GETTER(JSShipGetShipEntity, &sShipClass, sShipPrototype, ShipEntity)
void InitOOJSShip(JSContext *context, JSObject *global)
{
sShipPrototype = JS_InitClass(context, global, JSEntityPrototype(), &sShipClass, OOJSUnconstructableConstruct, 0, sShipProperties, sShipMethods, NULL, sShipStaticMethods);
OOJSRegisterObjectConverter(&sShipClass, OOJSBasicPrivateObjectConverter);
OOJSRegisterSubclass(&sShipClass, JSEntityClass());
}
JSClass *JSShipClass(void)
{
return &sShipClass;
}
JSObject *JSShipPrototype(void)
{
return sShipPrototype;
}
static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
{
if (!JSID_IS_INT(propID)) return YES;
OOJS_NATIVE_ENTER(context)
ShipEntity *entity = nil;
id result = nil;
if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
if (OOIsStaleEntity(entity)) { *value = JSVAL_VOID; return YES; }
switch (JSID_TO_INT(propID))
{
case kShip_name:
result = [entity name];
break;
case kShip_displayName:
result = [entity displayName];
break;
case kShip_shipUniqueName:
result = [entity shipUniqueName];
break;
case kShip_shipClassName:
result = [entity shipClassName];
break;
case kShip_scanDescription:
result = [entity scanDescriptionForScripting];
break;
case kShip_roles:
result = [[entity roleSet] sortedRoles];
break;
case kShip_roleWeights:
result = [[entity roleSet] rolesAndProbabilities];
break;
case kShip_primaryRole:
result = [entity primaryRole];
break;
case kShip_AI:
result = [[entity getAI] name];
break;
case kShip_AIState:
result = [[entity getAI] state];
break;
case kShip_AIFoundTarget:
result = [entity foundTarget];
break;
case kShip_AIPrimaryAggressor:
result = [entity primaryAggressor];
break;
case kShip_alertCondition:
return JS_NewNumberValue(context, [entity realAlertCondition], value);
case kShip_autoAI:
*value = OOJSValueFromBOOL([entity hasAutoAI]);
return YES;
case kShip_autoWeapons:
*value = OOJSValueFromBOOL([entity hasAutoWeapons]);
return YES;
case kShip_accuracy:
return JS_NewNumberValue(context, [entity accuracy], value);
case kShip_fuel:
return JS_NewNumberValue(context, [entity fuel] * 0.1, value);
case kShip_fuelChargeRate:
return JS_NewNumberValue(context, [entity fuelChargeRate], value);
case kShip_bounty:
return JS_NewNumberValue(context, [entity bounty], value);
return YES;
case kShip_subEntities:
result = [entity subEntitiesForScript];
break;
case kShip_exhausts:
result = [[entity exhaustEnumerator] allObjects];
break;
case kShip_flashers:
result = [[entity flasherEnumerator] allObjects];
break;
case kShip_subEntityCapacity:
return JS_NewNumberValue(context, [entity maxShipSubEntities], value);
return YES;
case kShip_subEntityRotation:
return QuaternionToJSValue(context, [entity subEntityRotationalVelocity], value);
case kShip_hasSuspendedAI:
*value = OOJSValueFromBOOL([[entity getAI] hasSuspendedStateMachines]);
return YES;
case kShip_target:
result = [entity primaryTarget];
break;
case kShip_defenseTargets:
{
[entity validateDefenseTargets];
result = [NSMutableArray arrayWithCapacity:[entity defenseTargetCount]];
NSEnumerator *defTargets = [entity defenseTargetEnumerator];
Entity *target = nil;
while ((target = [[defTargets nextObject] weakRefUnderlyingObject]))
{
[result addObject:target];
}
break;
}
case kShip_crew:
result = [entity crewForScripting];
break;
case kShip_escorts:
result = [[entity escortGroup] memberArrayExcludingLeader];
break;
case kShip_group:
result = [entity group];
break;
case kShip_escortGroup:
result = [entity escortGroup];
break;
case kShip_temperature:
return JS_NewNumberValue(context, [entity temperature] / SHIP_MAX_CABIN_TEMP, value);
case kShip_heatInsulation:
return JS_NewNumberValue(context, [entity heatInsulation], value);
case kShip_heading:
return VectorToJSValue(context, [entity forwardVector], value);
case kShip_energyRechargeRate:
return JS_NewNumberValue(context, [entity energyRechargeRate], value);
case kShip_entityPersonality:
*value = INT_TO_JSVAL([entity entityPersonalityInt]);
return YES;
case kShip_isBeacon:
*value = OOJSValueFromBOOL([entity isBeacon]);
return YES;
case kShip_beaconCode:
result = [entity beaconCode];
break;
case kShip_beaconLabel:
result = [entity beaconLabel];
break;
case kShip_isFrangible:
*value = OOJSValueFromBOOL([entity isFrangible]);
return YES;
case kShip_isCloaked:
*value = OOJSValueFromBOOL([entity isCloaked]);
return YES;
case kShip_cloakAutomatic:
*value = OOJSValueFromBOOL([entity hasAutoCloak]);
return YES;
case kShip_isJamming:
*value = OOJSValueFromBOOL([entity isJammingScanning]);
return YES;
case kShip_potentialCollider:
result = [entity proximityAlert];
break;
case kShip_hasHostileTarget:
*value = OOJSValueFromBOOL([entity hasHostileTarget]);
return YES;
case kShip_hasHyperspaceMotor:
*value = OOJSValueFromBOOL([entity hasHyperspaceMotor]);
return YES;
case kShip_hyperspaceSpinTime:
return JS_NewNumberValue(context, [entity hyperspaceSpinTime], value);
case kShip_weaponRange:
return JS_NewNumberValue(context, [entity weaponRange], value);
case kShip_weaponFacings:
if ([entity isPlayer])
{
PlayerEntity *pent = (PlayerEntity*)entity;
return JS_NewNumberValue(context, [pent availableFacings], value);
}
return JS_NewNumberValue(context, [entity weaponFacings], value);
case kShip_weaponPositionAft:
result = [entity aftWeaponOffset];
break;
case kShip_weaponPositionForward:
result = [entity forwardWeaponOffset];
break;
// return VectorToJSValue(context, [entity forwardWeaponOffset], value);
case kShip_weaponPositionPort:
result = [entity portWeaponOffset];
break;
case kShip_weaponPositionStarboard:
result = [entity starboardWeaponOffset];
break;
case kShip_scannerRange:
return JS_NewNumberValue(context, [entity scannerRange], value);
case kShip_reactionTime:
return JS_NewNumberValue(context, [entity reactionTime], value);
case kShip_reportAIMessages:
*value = OOJSValueFromBOOL([entity reportAIMessages]);
return YES;
case kShip_withinStationAegis:
*value = OOJSValueFromBOOL([entity withinStationAegis]);
return YES;
case kShip_cargoSpaceCapacity:
*value = INT_TO_JSVAL([entity maxAvailableCargoSpace]);
return YES;
case kShip_cargoSpaceUsed:
*value = INT_TO_JSVAL([entity maxAvailableCargoSpace] - [entity availableCargoSpace]);
return YES;
case kShip_cargoSpaceAvailable:
*value = INT_TO_JSVAL([entity availableCargoSpace]);
return YES;
case kShip_cargoList:
result = [entity cargoListForScripting];
break;
case kShip_extraCargo:
return JS_NewNumberValue(context, [entity extraCargo], value);
return YES;
case kShip_commodity:
if ([entity commodityAmount] > 0)
{
result = [entity commodityType];
}
break;
case kShip_commodityAmount:
*value = INT_TO_JSVAL([entity commodityAmount]);
return YES;
case kShip_collisionExceptions:
result = [entity collisionExceptions];
break;
case kShip_speed:
return JS_NewNumberValue(context, [entity flightSpeed], value);
case kShip_cruiseSpeed:
return JS_NewNumberValue(context, [entity cruiseSpeed], value);
case kShip_dataKey:
result = [entity shipDataKey];
break;
case kShip_desiredRange:
return JS_NewNumberValue(context, [entity desiredRange], value);
case kShip_desiredSpeed:
return JS_NewNumberValue(context, [entity desiredSpeed], value);
case kShip_destination:
return HPVectorToJSValue(context, [entity destination], value);
case kShip_markedForFines:
*value = OOJSValueFromBOOL([entity markedForFines]);
return YES;
case kShip_maxEscorts:
return JS_NewNumberValue(context, [entity maxEscortCount], value);
case kShip_maxPitch:
return JS_NewNumberValue(context, [entity maxFlightPitch], value);
case kShip_maxSpeed:
return JS_NewNumberValue(context, [entity maxFlightSpeed], value);
case kShip_maxRoll:
return JS_NewNumberValue(context, [entity maxFlightRoll], value);
case kShip_maxYaw:
return JS_NewNumberValue(context, [entity maxFlightYaw], value);
case kShip_injectorBurnRate:
return JS_NewNumberValue(context, [entity afterburnerRate], value);
case kShip_injectorSpeedFactor:
return JS_NewNumberValue(context, [entity afterburnerFactor], value);
case kShip_script:
result = [entity shipScript];
break;
case kShip_AIScript:
result = [entity shipAIScript];
break;
case kShip_AIScriptWakeTime:
return JS_NewNumberValue(context, [entity shipAIScriptWakeTime], value);
break;
case kShip_destinationSystem:
return JS_NewNumberValue(context, [entity destinationSystem], value);
break;
case kShip_homeSystem:
return JS_NewNumberValue(context, [entity homeSystem], value);
break;
case kShip_isPirate:
*value = OOJSValueFromBOOL([entity isPirate]);
return YES;
case kShip_isPolice:
*value = OOJSValueFromBOOL([entity isPolice]);
return YES;
case kShip_isThargoid:
*value = OOJSValueFromBOOL([entity isThargoid]);
return YES;
case kShip_isTurret:
*value = OOJSValueFromBOOL([entity isTurret]);
return YES;
case kShip_isTrader:
*value = OOJSValueFromBOOL([entity isTrader]);
return YES;
case kShip_isPirateVictim:
*value = OOJSValueFromBOOL([entity isPirateVictim]);
return YES;
case kShip_isMissile:
*value = OOJSValueFromBOOL([entity isMissile]);
return YES;
case kShip_isMine:
*value = OOJSValueFromBOOL([entity isMine]);
return YES;
case kShip_isWeapon:
*value = OOJSValueFromBOOL([entity isWeapon]);
return YES;
case kShip_isRock:
*value = OOJSValueFromBOOL([entity scanClass] == CLASS_ROCK); // hermits and asteroids!
return YES;
case kShip_isMinable:
*value = OOJSValueFromBOOL([entity isMinable]);
return YES;
case kShip_isBoulder:
*value = OOJSValueFromBOOL([entity isBoulder]);
return YES;
case kShip_isFleeing:
if ([entity isPlayer])
{
*value = OOJSValueFromBOOL([(PlayerEntity*)entity fleeingStatus] >= PLAYER_FLEEING_CARGO);
}
else
{