Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
OOJSPlayerShip.m
Go to the documentation of this file.
1/*
2
3OOJSPlayerShip.h
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
26#import "OOJSPlayer.h"
27#import "OOJSEntity.h"
28#import "OOJSShip.h"
29#import "OOJSVector.h"
30#import "OOJSQuaternion.h"
34#import "PlayerEntity.h"
39#import "PlayerEntitySound.h"
40#import "HeadUpDisplay.h"
41#import "StationEntity.h"
42
43#import "OOConstToJSString.h"
44#import "OOConstToString.h"
46#import "OOEquipmentType.h"
47#import "OOJSEquipmentInfo.h"
48
49
50static JSObject *sPlayerShipPrototype;
51static JSObject *sPlayerShipObject;
52
53
54static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
55static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value);
56
57static JSBool PlayerShipLaunch(JSContext *context, uintN argc, jsval *vp);
58static JSBool PlayerShipRemoveAllCargo(JSContext *context, uintN argc, jsval *vp);
59static JSBool PlayerShipUseSpecialCargo(JSContext *context, uintN argc, jsval *vp);
60static JSBool PlayerShipEngageAutopilotToStation(JSContext *context, uintN argc, jsval *vp);
61static JSBool PlayerShipDisengageAutopilot(JSContext *context, uintN argc, jsval *vp);
62static JSBool PlayerShipRequestDockingClearance(JSContext *context, uintN argc, jsval *vp);
63static JSBool PlayerShipCancelDockingRequest(JSContext *context, uintN argc, jsval *vp);
64static JSBool PlayerShipAwardEquipmentToCurrentPylon(JSContext *context, uintN argc, jsval *vp);
65static JSBool PlayerShipAddPassenger(JSContext *context, uintN argc, jsval *vp);
66static JSBool PlayerShipRemovePassenger(JSContext *context, uintN argc, jsval *vp);
67static JSBool PlayerShipAddParcel(JSContext *context, uintN argc, jsval *vp);
68static JSBool PlayerShipRemoveParcel(JSContext *context, uintN argc, jsval *vp);
69static JSBool PlayerShipAwardContract(JSContext *context, uintN argc, jsval *vp);
70static JSBool PlayerShipRemoveContract(JSContext *context, uintN argc, jsval *vp);
71static JSBool PlayerShipSetCustomView(JSContext *context, uintN argc, jsval *vp);
72static JSBool PlayerShipSetPrimedEquipment(JSContext *context, uintN argc, jsval *vp);
73static JSBool PlayerShipResetCustomView(JSContext *context, uintN argc, jsval *vp);
74static JSBool PlayerShipResetScannerZoom(JSContext *context, uintN argc, jsval *vp);
75static JSBool PlayerShipTakeInternalDamage(JSContext *context, uintN argc, jsval *vp);
76static JSBool PlayerShipBeginHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp);
77static JSBool PlayerShipCancelHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp);
78static JSBool PlayerShipBeginGalacticHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp);
79static JSBool PlayerShipSetMultiFunctionDisplay(JSContext *context, uintN argc, jsval *vp);
80static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsval *vp);
81static JSBool PlayerShipHideHUDSelector(JSContext *context, uintN argc, jsval *vp);
82static JSBool PlayerShipShowHUDSelector(JSContext *context, uintN argc, jsval *vp);
83static JSBool PlayerShipSetCustomHUDDial(JSContext *context, uintN argc, jsval *vp);
84
85static BOOL ValidateContracts(JSContext *context, uintN argc, jsval *vp, BOOL isCargo, OOSystemID *start, OOSystemID *destination, double *eta, double *fee, double *premium, NSString *functionName, unsigned *risk);
86
87
88static JSClass sPlayerShipClass =
89{
90 "PlayerShip",
91 JSCLASS_HAS_PRIVATE,
92
93 JS_PropertyStub, // addProperty
94 JS_PropertyStub, // delProperty
95 PlayerShipGetProperty, // getProperty
96 PlayerShipSetProperty, // setProperty
97 JS_EnumerateStub, // enumerate
98 JS_ResolveStub, // resolve
99 JS_ConvertStub, // convert
100 OOJSObjectWrapperFinalize,// finalize
101 JSCLASS_NO_OPTIONAL_MEMBERS
102};
103
104
105enum
106{
107 // Property IDs
108 kPlayerShip_activeMissile, // index in 'missiles' array of current active missile
109 kPlayerShip_aftShield, // aft shield charge level, nonnegative float, read/write
110 kPlayerShip_aftShieldRechargeRate, // aft shield recharge rate, positive float, read-only
111 kPlayerShip_chartHightlightMode, // what type of information is being shown on the chart
112 kPlayerShip_compassMode, // compass mode, string, read/write
113 kPlayerShip_compassTarget, // object targeted by the compass, entity, read/write
114 kPlayerShip_compassType, // basic / advanced, string, read/write
115 kPlayerShip_currentWeapon, // shortcut property to _aftWeapon, etc. overrides kShip generic version
116 kPlayerShip_crosshairs, // custom plist file defining crosshairs
117 kPlayerShip_cursorCoordinates, // cursor coordinates (unscaled), Vector3D, read only
118 kPlayerShip_cursorCoordinatesInLY, // cursor coordinates (in LY), Vector3D, read only
119 kPlayerShip_docked, // docked, boolean, read-only
120 kPlayerShip_dockedStation, // docked station, entity, read-only
121 kPlayerShip_fastEquipmentA, // fast equipment A, string, read/write
122 kPlayerShip_fastEquipmentB, // fast equipment B, string, read/write
123 kPlayerShip_forwardShield, // forward shield charge level, nonnegative float, read/write
124 kPlayerShip_forwardShieldRechargeRate, // forward shield recharge rate, positive float, read-only
125 kPlayerShip_fuelLeakRate, // fuel leak rate, float, read/write
126 kPlayerShip_galacticHyperspaceBehaviour, // can be standard, all systems reachable or fixed coordinates, integer, read-only
127 kPlayerShip_galacticHyperspaceFixedCoords, // used when fixed coords behaviour is selected, Vector3D, read/write
128 kPlayerShip_galacticHyperspaceFixedCoordsInLY, // used when fixed coords behaviour is selected, Vector3D, read/write
129 kPlayerShip_galaxyCoordinates, // galaxy coordinates (unscaled), Vector3D, read only
130 kPlayerShip_galaxyCoordinatesInLY, // galaxy coordinates (in LY), Vector3D, read only
131 kPlayerShip_hud, // hud name identifier, string, read/write
132 kPlayerShip_hudAllowsBigGui, // hud big gui, string, read only
133 kPlayerShip_hudHidden, // hud visibility, boolean, read/write
134 kPlayerShip_injectorsEngaged, // injectors in use, boolean, read-only
135 kPlayerShip_massLockable, // mass-lockability of player ship, read/write
136 kPlayerShip_maxAftShield, // maximum aft shield charge level, positive float, read-only
137 kPlayerShip_maxForwardShield, // maximum forward shield charge level, positive float, read-only
138 kPlayerShip_messageGuiTextColor, // message gui standard text color, array, read/write
139 kPlayerShip_messageGuiTextCommsColor, // message gui incoming comms text color, array, read/write
140 kPlayerShip_multiFunctionDisplays, // mfd count, positive int, read-only
141 kPlayerShip_multiFunctionDisplayList, // active mfd list, array, read-only
142 kPlayerShip_missilesOnline, // bool (false for ident mode, true for missile mode)
143 kPlayerShip_pitch, // pitch (overrules Ship)
144 kPlayerShip_price, // idealised trade-in value decicredits, positive int, read-only
145 kPlayerShip_primedEquipment, // currently primed equipment, string, read/write
146 kPlayerShip_renovationCost, // int read-only current renovation cost
147 kPlayerShip_reticleColorTarget, // Reticle color for normal targets, array, read/write
148 kPlayerShip_reticleColorTargetSensitive, // Reticle color for targets picked up when sensitive mode is on, array, read/write
149 kPlayerShip_reticleColorWormhole, // REticle color for wormholes, array, read/write
150 kPlayerShip_renovationMultiplier, // float read-only multiplier for renovation costs
151 kPlayerShip_reticleTargetSensitive, // target box changes color when primary target in crosshairs, boolean, read/write
152 kPlayerShip_roll, // roll (overrules Ship)
154 kPlayerShip_scannerMinimalistic , // essentially scanner without gridlines
155 kPlayerShip_scannerNonLinear, // non linear scanner setting, boolean, read/write
156 kPlayerShip_scannerUltraZoom, // scanner zoom in powers of 2, boolean, read/write
158 kPlayerShip_serviceLevel, // servicing level, positive int 75-100, read-only
159 kPlayerShip_specialCargo, // special cargo, string, read-only
160 kPlayerShip_targetSystem, // target system id, int, read-write
161 kPlayerShip_nextSystem, // next hop system id, read-only
162 kPlayerShip_infoSystem, // info (F7 screen) system id, int, read-write
163 kPlayerShip_previousSystem, // previous system id, read-only
164 kPlayerShip_torusEngaged, // torus in use, boolean, read-only
165 kPlayerShip_viewDirection, // view direction identifier, string, read-only
166 kPlayerShip_viewPositionAft, // view position offset, vector, read-only
167 kPlayerShip_viewPositionForward, // view position offset, vector, read-only
168 kPlayerShip_viewPositionPort, // view position offset, vector, read-only
169 kPlayerShip_viewPositionStarboard, // view position offset, vector, read-only
170 kPlayerShip_weaponsOnline, // weapons online status, boolean, read-only
171 kPlayerShip_yaw, // yaw (overrules Ship)
172};
173
174
175static JSPropertySpec sPlayerShipProperties[] =
176{
177 // JS name ID flags
180 { "aftShieldRechargeRate", kPlayerShip_aftShieldRechargeRate, OOJS_PROP_READWRITE_CB },
188 { "cursorCoordinatesInLY", kPlayerShip_cursorCoordinatesInLY, OOJS_PROP_READONLY_CB },
194 { "forwardShieldRechargeRate", kPlayerShip_forwardShieldRechargeRate, OOJS_PROP_READWRITE_CB },
196 { "galacticHyperspaceBehaviour", kPlayerShip_galacticHyperspaceBehaviour, OOJS_PROP_READWRITE_CB },
197 { "galacticHyperspaceFixedCoords", kPlayerShip_galacticHyperspaceFixedCoords, OOJS_PROP_READWRITE_CB },
198 { "galacticHyperspaceFixedCoordsInLY", kPlayerShip_galacticHyperspaceFixedCoordsInLY, OOJS_PROP_READWRITE_CB },
200 { "galaxyCoordinatesInLY", kPlayerShip_galaxyCoordinatesInLY, OOJS_PROP_READONLY_CB },
206 // manifest defined in OOJSManifest.m
210 { "messageGuiTextCommsColor", kPlayerShip_messageGuiTextCommsColor, OOJS_PROP_READWRITE_CB },
212 { "multiFunctionDisplays", kPlayerShip_multiFunctionDisplays, OOJS_PROP_READONLY_CB },
213 { "multiFunctionDisplayList", kPlayerShip_multiFunctionDisplayList, OOJS_PROP_READONLY_CB },
219 { "reticleColorTargetSensitive", kPlayerShip_reticleColorTargetSensitive, OOJS_PROP_READWRITE_CB },
220 { "reticleColorWormhole", kPlayerShip_reticleColorWormhole, OOJS_PROP_READWRITE_CB },
221 { "renovationMultiplier", kPlayerShip_renovationMultiplier, OOJS_PROP_READONLY_CB },
222 { "reticleTargetSensitive", kPlayerShip_reticleTargetSensitive, OOJS_PROP_READWRITE_CB },
238 { "viewPositionForward", kPlayerShip_viewPositionForward, OOJS_PROP_READONLY_CB },
240 { "viewPositionStarboard", kPlayerShip_viewPositionStarboard, OOJS_PROP_READONLY_CB },
243 { 0 }
244};
245
246
247static JSFunctionSpec sPlayerShipMethods[] =
248{
249 // JS name Function min args
250 { "addParcel", PlayerShipAddParcel, 0 },
251 { "addPassenger", PlayerShipAddPassenger, 0 },
252 { "awardContract", PlayerShipAwardContract, 0 },
253 { "awardEquipmentToCurrentPylon", PlayerShipAwardEquipmentToCurrentPylon, 1 },
254 { "beginHyperspaceCountdown", PlayerShipBeginHyperspaceCountdown, 0 },
255 { "cancelDockingRequest", PlayerShipCancelDockingRequest, 1 },
256 { "cancelHyperspaceCountdown", PlayerShipCancelHyperspaceCountdown, 0 },
257 { "beginGalacticHyperspaceCountdown", PlayerShipBeginGalacticHyperspaceCountdown, 1 },
258 { "disengageAutopilot", PlayerShipDisengageAutopilot, 0 },
259 { "engageAutopilotToStation", PlayerShipEngageAutopilotToStation, 1 },
260 { "hideHUDSelector", PlayerShipHideHUDSelector, 1 },
261 { "launch", PlayerShipLaunch, 0 },
262 { "removeAllCargo", PlayerShipRemoveAllCargo, 0 },
263 { "removeContract", PlayerShipRemoveContract, 2 },
264 { "removeParcel", PlayerShipRemoveParcel, 1 },
265 { "removePassenger", PlayerShipRemovePassenger, 1 },
266 { "requestDockingClearance", PlayerShipRequestDockingClearance, 1 },
267 { "resetCustomView", PlayerShipResetCustomView, 0 },
268 { "resetScannerZoom", PlayerShipResetScannerZoom, 0 },
269 { "setCustomView", PlayerShipSetCustomView, 2 },
270 { "setCustomHUDDial", PlayerShipSetCustomHUDDial, 2 },
271 { "setMultiFunctionDisplay", PlayerShipSetMultiFunctionDisplay, 1 },
272 { "setMultiFunctionText", PlayerShipSetMultiFunctionText, 1 },
273 { "setPrimedEquipment", PlayerShipSetPrimedEquipment, 1 },
274 { "showHUDSelector", PlayerShipShowHUDSelector, 1 },
275 { "takeInternalDamage", PlayerShipTakeInternalDamage, 0 },
276 { "useSpecialCargo", PlayerShipUseSpecialCargo, 1 },
277 { 0 }
278};
279
280
281void InitOOJSPlayerShip(JSContext *context, JSObject *global)
282{
286
287 PlayerEntity *player = [PlayerEntity sharedPlayer]; // NOTE: at time of writing, this creates the player entity. Don't use PLAYER here.
288
289 // Create ship object as a property of the player object.
291 JS_SetPrivate(context, sPlayerShipObject, OOConsumeReference([player weakRetain]));
292 [player setJSSelf:sPlayerShipObject context:context];
293 // Analyzer: object leaked. [Expected, object is retained by JS object.]
294}
295
296
297JSClass *JSPlayerShipClass(void)
298{
299 return &sPlayerShipClass;
300}
301
302
304{
306}
307
308
309JSObject *JSPlayerShipObject(void)
310{
311 return sPlayerShipObject;
312}
313
314
315@implementation PlayerEntity (OOJavaScriptExtensions)
316
317- (NSString *) oo_jsClassName
318{
319 return @"PlayerShip";
320}
321
322
323- (void) setJSSelf:(JSObject *)val context:(JSContext *)context
324{
325 _jsSelf = val;
326 OOJSAddGCObjectRoot(context, &_jsSelf, "Player jsSelf");
327
328 [[NSNotificationCenter defaultCenter] addObserver:self
329 selector:@selector(javaScriptEngineWillReset:)
330 name:kOOJavaScriptEngineWillResetNotification
332}
333
334
335- (void) javaScriptEngineWillReset:(NSNotification *)notification
336{
337 [[NSNotificationCenter defaultCenter] removeObserver:self
338 name:kOOJavaScriptEngineWillResetNotification
340
341 if (_jsSelf != NULL)
342 {
343
344 JSContext *context = OOJSAcquireContext();
345 JS_RemoveObjectRoot(context, &_jsSelf);
346 _jsSelf = NULL;
347 OOJSRelinquishContext(context);
348 }
349}
350
351@end
352
353
354static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
355{
356 if (!JSID_IS_INT(propID)) return YES;
357
358 OOJS_NATIVE_ENTER(context)
359
360 if (EXPECT_NOT(OOIsPlayerStale() || this == sPlayerShipPrototype)) { *value = JSVAL_VOID; return YES; }
361
362 id result = nil;
364
365 switch (JSID_TO_INT(propID))
366 {
368 return JS_NewNumberValue(context, [player activeMissile], value);
369
371 return JS_NewNumberValue(context, [player fuelLeakRate], value);
372
374 *value = OOJSValueFromBOOL([player isDocked]);
375 return YES;
376
378 result = [player dockedStation];
379 break;
380
382 result = [player specialCargo];
383 break;
384
386 result = [[[player hud] reticleColorForIndex:OO_RETICLE_COLOR_TARGET] normalizedArray];
387 break;
388
390 result = [[[player hud] reticleColorForIndex:OO_RETICLE_COLOR_TARGET_SENSITIVE] normalizedArray];
391 break;
392
394 result = [[[player hud] reticleColorForIndex:OO_RETICLE_COLOR_WORMHOLE] normalizedArray];
395 break;
396
398 *value = OOJSValueFromBOOL([[player hud] reticleTargetSensitive]);
399 return YES;
400
402 *value = OOJSValueFromGalacticHyperspaceBehaviour(context, [player galacticHyperspaceBehaviour]);
403 return YES;
404
406 return NSPointToVectorJSValue(context, [player galacticHyperspaceFixedCoords], value);
407
409 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([player galacticHyperspaceFixedCoords]), value);
410
412 result = [player fastEquipmentA];
413 break;
414
416 result = [player fastEquipmentB];
417 break;
418
420 result = [player currentPrimedEquipment];
421 break;
422
424 return JS_NewNumberValue(context, [player forwardShieldLevel], value);
425
427 return JS_NewNumberValue(context, [player aftShieldLevel], value);
428
430 return JS_NewNumberValue(context, [player maxForwardShieldLevel], value);
431
433 return JS_NewNumberValue(context, [player maxAftShieldLevel], value);
434
436 // No distinction made internally
437 return JS_NewNumberValue(context, [player forwardShieldRechargeRate], value);
438
440 // No distinction made internally
441 return JS_NewNumberValue(context, [player aftShieldRechargeRate], value);
442
444 return JS_NewNumberValue(context, [[player hud] mfdCount], value);
445
447 result = [player multiFunctionDisplayList];
448 break;
449
451 *value = OOJSValueFromBOOL(![player dialIdentEngaged]);
452 return YES;
453
455 result = OOStringFromLongRangeChartMode([player longRangeChartMode]);
456 break;
457
459 return NSPointToVectorJSValue(context, [player galaxy_coordinates], value);
460
462 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([player galaxy_coordinates]), value);
463
465 return NSPointToVectorJSValue(context, [player cursor_coordinates], value);
466
468 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([player cursor_coordinates]), value);
469
471 *value = INT_TO_JSVAL([player targetSystemID]);
472 return YES;
473
475 *value = INT_TO_JSVAL([player nextHopTargetSystemID]);
476 return YES;
477
479 *value = INT_TO_JSVAL([player infoSystemID]);
480 return YES;
481
483 *value = INT_TO_JSVAL([player previousSystemID]);
484 return YES;
485
487 {
488 OORouteType route = [player ANAMode];
489 switch (route)
490 {
492 result = @"OPTIMIZED_BY_TIME";
493 break;
495 result = @"OPTIMIZED_BY_JUMPS";
496 break;
498 result = @"OPTIMIZED_BY_NONE";
499 break;
500 }
501 break;
502 }
503
505 *value = OOJSValueFromBOOL([[player hud] minimalisticScanner]);
506 return YES;
507
509 *value = OOJSValueFromBOOL([[player hud] nonlinearScanner]);
510 return YES;
511
513 *value = OOJSValueFromBOOL([[player hud] scannerUltraZoom]);
514 return YES;
515
517 *value = OOJSValueFromBOOL([player scoopOverride]);
518 return YES;
519
521 *value = OOJSValueFromBOOL([player injectorsEngaged]);
522 return YES;
523
525 *value = OOJSValueFromBOOL([player massLockable]);
526 return YES;
527
529 *value = OOJSValueFromBOOL([player hyperspeedEngaged]);
530 return YES;
531
533 result = [player compassTarget];
534 break;
535
537 result = [OOStringFromCompassMode([player compassMode]) isEqualToString:@"COMPASS_MODE_BASIC"] ?
538 @"OO_COMPASSTYPE_BASIC" : @"OO_COMPASSTYPE_ADVANCED";
539 break;
540
542 *value = OOJSValueFromCompassMode(context, [player compassMode]);
543 return YES;
544
545 case kPlayerShip_hud:
546 result = [[player hud] hudName];
547 break;
548
550 result = [[player hud] crosshairDefinition];
551 break;
552
554 *value = OOJSValueFromBOOL([[player hud] allowBigGui]);
555 return YES;
556
558 *value = OOJSValueFromBOOL([[player hud] isHidden]);
559 return YES;
560
562 *value = OOJSValueFromBOOL([player weaponsOnline]);
563 return YES;
564
566 *value = OOJSValueFromViewID(context, [UNIVERSE viewDirection]);
567 return YES;
568
570 return VectorToJSValue(context, [player viewpointOffsetAft], value);
571
573 return VectorToJSValue(context, [player viewpointOffsetForward], value);
574
576 return VectorToJSValue(context, [player viewpointOffsetPort], value);
577
579 return VectorToJSValue(context, [player viewpointOffsetStarboard], value);
580
582 result = [player weaponTypeForFacing:[player currentWeaponFacing] strict:NO];
583 break;
584
586 return JS_NewNumberValue(context, [UNIVERSE tradeInValueForCommanderDictionary:[player commanderDataDictionary]], value);
587
589 return JS_NewNumberValue(context, [player tradeInFactor], value);
590
592 return JS_NewNumberValue(context, [player renovationCosts], value);
593
595 return JS_NewNumberValue(context, [player renovationFactor], value);
596
597
598 // make roll, pitch, yaw reported to JS use same +/- convention as
599 // for NPC ships
601 return JS_NewNumberValue(context, -[player flightPitch], value);
602
603 case kPlayerShip_roll:
604 return JS_NewNumberValue(context, -[player flightRoll], value);
605
606 case kPlayerShip_yaw:
607 return JS_NewNumberValue(context, -[player flightYaw], value);
608
610 result = [[[UNIVERSE messageGUI] textColor] normalizedArray];
611 break;
612
614 result = [[[UNIVERSE messageGUI] textCommsColor] normalizedArray];
615 break;
616
617 default:
619 }
620
621 *value = OOJSValueFromNativeObject(context, result);
622 return YES;
623
625}
626
627
628static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
629{
630 if (!JSID_IS_INT(propID)) return YES;
631
632 OOJS_NATIVE_ENTER(context)
633
634 if (EXPECT_NOT(OOIsPlayerStale())) return YES;
635
637 jsdouble fValue;
638 JSBool bValue;
639 int32 iValue;
640 NSString *sValue = nil;
642 Vector vValue;
643 OOColor *colorForScript = nil;
644 Entity *eValue = nil;
645
646 switch (JSID_TO_INT(propID))
647 {
649 if (JS_ValueToNumber(context, *value, &fValue))
650 {
651 [player setFuelLeakRate:fValue];
652 return YES;
653 }
654 break;
655
657 if (JS_ValueToBoolean(context, *value, &bValue))
658 {
659 [player setMassLockable:bValue];
660 return YES;
661 }
662 break;
663
665 if (JS_ValueToBoolean(context, *value, &bValue))
666 {
667 [[player hud] setReticleTargetSensitive:bValue];
668 return YES;
669 }
670 break;
671
673 sValue = OOStringFromJSValue(context, *value);
674 if (sValue != nil)
675 {
677 if (chartMode > OOLRC_MODE_UNKNOWN)
678 {
679 [player setLongRangeChartMode:chartMode];
680 [player doScriptEvent:OOJSID("chartHighlightModeChanged") withArgument:OOStringFromLongRangeChartMode([player longRangeChartMode])];
681 return YES;
682 }
683 else
684 {
685 OOJSReportError(context, @"Unknown chart hightlight mode specified - must be either OOLRC_MODE_SUNCOLOR, OOLRC_MODE_ECONOMY, OOLRC_MODE_GOVERNMENT or OOLRC_MODE_TECHLEVEL.");
686 }
687 }
688 return NO; // not reachable if successfully set
689 break;
690
692 sValue = OOStringFromJSValue(context, *value);
693 if(sValue != nil)
694 {
696 [player setCompassMode:mode];
697 [player validateCompassTarget];
698 return YES;
699 }
700 break;
701
703 sValue = OOStringFromJSValue(context, *value);
704 if (sValue != nil)
705 {
706 if ([sValue isEqualToString:@"OO_COMPASSTYPE_BASIC"])
707 {
708 [player setCompassMode:COMPASS_MODE_BASIC];
709 }
710 else if([sValue isEqualToString:@"OO_COMPASSTYPE_ADVANCED"])
711 {
712 if (![player hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"])
713 {
714 OOJSReportWarning(context, @"Advanced Compass type requested and set but player ship does not carry the EQ_ADVANCED_COMPASS equipment or has it damaged.");
715 }
716 [player setCompassMode:COMPASS_MODE_PLANET];
717 }
718 else
719 {
720 OOJSReportError(context, @"Unknown compass type specified - must be either OO_COMPASSTYPE_BASIC or OO_COMPASSTYPE_ADVANCED.");
721 return NO;
722 }
723 return YES;
724 }
725 break;
726
728 // can't change compass target in basic mode
729 if (![player hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"])
730 {
731 OOJSReportError(context, @"Compass target cannot be set with a basic compass.");
732 return NO;
733 }
734 // make sure we have a valid entity
735 if (!JSVAL_IS_NULL(*value) && JSValueToEntity(context, *value, &eValue))
736 {
737 Entity *current = [player compassTarget];
738 [player setNextCompassMode];
739 [player validateCompassTarget];
740 // cycle the targets until we either get back to the start (entity not found) or we find the one we're looking for
741 while ([player compassTarget] != current && [player compassTarget] != eValue)
742 {
743 [player setNextCompassMode];
744 [player validateCompassTarget];
745 }
746 return [player compassTarget] != current;
747 }
748 else
749 {
750 OOJSReportError(context, @"Invalid compass target entity provided.");
751 return NO;
752 }
753 break;
754
756 ghBehaviour = OOGalacticHyperspaceBehaviourFromJSValue(context, *value);
757 if (ghBehaviour != GALACTIC_HYPERSPACE_BEHAVIOUR_UNKNOWN)
758 {
759 [player setGalacticHyperspaceBehaviour:ghBehaviour];
760 return YES;
761 }
762 break;
763
765 if (JSValueToVector(context, *value, &vValue))
766 {
767 NSPoint coords = { vValue.x, vValue.y };
768 [player setGalacticHyperspaceFixedCoords:coords];
769 return YES;
770 }
771 break;
772
774 if (JSValueToVector(context, *value, &vValue))
775 {
776 NSPoint coords = OOInternalCoordinatesFromGalactic(vValue);
777 [player setGalacticHyperspaceFixedCoords:coords];
778 return YES;
779 }
780 break;
781
783 sValue = OOStringFromJSValue(context, *value);
784 if (sValue != nil)
785 {
786 [player setFastEquipmentA:sValue];
787 return YES;
788 }
789 break;
790
792 sValue = OOStringFromJSValue(context, *value);
793 if (sValue != nil)
794 {
795 [player setFastEquipmentB:sValue];
796 return YES;
797 }
798 break;
799
801 sValue = OOStringFromJSValue(context, *value);
802 if (sValue != nil)
803 {
804 return [player setPrimedEquipment:sValue showMessage:NO];
805 }
806 break;
807
809 if (JS_ValueToNumber(context, *value, &fValue))
810 {
811 if (!isnan(fValue)) // guard against undefined
812 {
813 [player decrease_flight_pitch:[player flightPitch] + fValue];
814 }
815 return YES;
816 }
817 break;
818
819 case kPlayerShip_roll:
820 if (JS_ValueToNumber(context, *value, &fValue))
821 {
822 if (!isnan(fValue)) // guard against undefined
823 {
824 [player decrease_flight_roll:[player flightRoll] + fValue];
825 }
826 return YES;
827 }
828 break;
829
830 case kPlayerShip_yaw:
831 if (JS_ValueToNumber(context, *value, &fValue))
832 {
833 if (!isnan(fValue)) // guard against undefined
834 {
835 [player decrease_flight_yaw:[player flightYaw] + fValue];
836 }
837 return YES;
838 }
839 break;
840
842 if (JS_ValueToNumber(context, *value, &fValue))
843 {
844 [player setForwardShieldLevel:fValue];
845 return YES;
846 }
847 break;
848
850 if (JS_ValueToNumber(context, *value, &fValue))
851 {
852 [player setAftShieldLevel:fValue];
853 return YES;
854 }
855 break;
856
858 if (JS_ValueToNumber(context, *value, &fValue))
859 {
860 [player setMaxForwardShieldLevel:fValue];
861 return YES;
862 }
863 break;
864
866 if (JS_ValueToNumber(context, *value, &fValue))
867 {
868 [player setMaxAftShieldLevel:fValue];
869 return YES;
870 }
871 break;
872
874 if (JS_ValueToNumber(context, *value, &fValue))
875 {
876 [player setForwardShieldRechargeRate:fValue];
877 return YES;
878 }
879 break;
880
882 if (JS_ValueToNumber(context, *value, &fValue))
883 {
884 [player setAftShieldRechargeRate:fValue];
885 return YES;
886 }
887 break;
888
890 if (JS_ValueToBoolean(context, *value, &bValue))
891 {
892 [[player hud] setMinimalisticScanner:bValue];
893 return YES;
894 }
895 break;
896
898 if (JS_ValueToBoolean(context, *value, &bValue))
899 {
900 [[player hud] setNonlinearScanner:bValue];
901 return YES;
902 }
903 break;
904
906 if (JS_ValueToBoolean(context, *value, &bValue))
907 {
908 [[player hud] setScannerUltraZoom:bValue];
909 return YES;
910 }
911 break;
912
914 if (JS_ValueToBoolean(context, *value, &bValue))
915 {
916 [player setScoopOverride:bValue];
917 return YES;
918 }
919 break;
920
921 case kPlayerShip_hud:
922 sValue = OOStringFromJSValue(context, *value);
923 if (sValue != nil)
924 {
925 [player switchHudTo:sValue]; // EMMSTRAN: logged error should be a JS warning.
926 return YES;
927 }
928 else
929 {
930 [player resetHud];
931 return YES;
932 }
933 break;
934
936 sValue = OOStringFromJSValue(context, *value);
937 if (sValue == nil)
938 {
939 // reset HUD back to its plist settings
940 NSString *hud = [[[player hud] hudName] retain];
941 [player switchHudTo:hud];
942 [hud release];
943 return YES;
944 }
945 else
946 {
947 if (![[player hud] setCrosshairDefinition:sValue])
948 {
949 OOJSReportWarning(context, @"Crosshair definition file %@ not found or invalid", sValue);
950 }
951 return YES;
952 }
953 break;
954
956 if (JS_ValueToBoolean(context, *value, &bValue))
957 {
958 [[player hud] setHidden:bValue];
959 return YES;
960 }
961 break;
962
964 if (JS_ValueToNumber(context, *value, &fValue))
965 {
966 int newLevel = (int)fValue;
967 [player adjustTradeInFactorBy:(newLevel-[player tradeInFactor])];
968 return YES;
969 }
970
972 {
973 BOOL exists = NO;
974 sValue = JSValueToEquipmentKeyRelaxed(context, *value, &exists);
975 if (!exists || sValue == nil)
976 {
977 sValue = @"EQ_WEAPON_NONE";
978 }
979 [player setWeaponMount:[player currentWeaponFacing] toWeapon:sValue inContext:@"scripted"];
980 return YES;
981 }
982
984 /* This first check is essential: if removed, it would be
985 * possible to make jumps of arbitrary length - CIM */
986 if ([player status] != STATUS_ENTERING_WITCHSPACE)
987 {
988 /* These checks though similar are less important. The
989 * consequences of allowing jump destination to be set in
990 * flight are not as severe and do not allow the 7LY limit to
991 * be broken. Nevertheless, it is not allowed. - CIM */
992 // (except when compiled in debugging mode)
993#ifndef OO_DUMP_PLANETINFO
994 if (EXPECT_NOT([player status] != STATUS_DOCKED && [player status] != STATUS_LAUNCHING))
995 {
996 OOJSReportError(context, @"player.ship.targetSystem is read-only unless called when docked.");
997 return NO;
998 }
999#endif
1000
1001 if (JS_ValueToInt32(context, *value, &iValue))
1002 {
1003 if (iValue >= 0 && iValue < OO_SYSTEMS_PER_GALAXY)
1004 {
1005 [player setTargetSystemID:iValue];
1006 return YES;
1007 }
1008 else
1009 {
1010 return NO;
1011 }
1012 }
1013 }
1014 else
1015 {
1016 OOJSReportError(context, @"player.ship.targetSystem is read-only unless called when docked.");
1017 return NO;
1018 }
1019
1021 if (JS_ValueToInt32(context, *value, &iValue))
1022 {
1023 if (iValue >= 0 && iValue < OO_SYSTEMS_PER_GALAXY)
1024 {
1025 [player setInfoSystemID:iValue moveChart: YES];
1026 return YES;
1027 }
1028 else
1029 {
1030 return NO;
1031 }
1032 }
1033 break;
1034
1036 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
1037 if (colorForScript != nil || JSVAL_IS_NULL(*value))
1038 {
1039 [[UNIVERSE messageGUI] setTextColor:colorForScript];
1040 return YES;
1041 }
1042 break;
1043
1045 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
1046 if (colorForScript != nil || JSVAL_IS_NULL(*value))
1047 {
1048 [[UNIVERSE messageGUI] setTextCommsColor:colorForScript];
1049 return YES;
1050 }
1051 break;
1052
1054 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
1055 if (colorForScript != nil || JSVAL_IS_NULL(*value))
1056 {
1057 return [[player hud] setReticleColorForIndex:OO_RETICLE_COLOR_TARGET toColor:colorForScript];
1058 }
1059 break;
1060
1062 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
1063 if (colorForScript != nil || JSVAL_IS_NULL(*value))
1064 {
1065 return [[player hud] setReticleColorForIndex:OO_RETICLE_COLOR_TARGET_SENSITIVE toColor:colorForScript];
1066 }
1067 break;
1068
1070 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
1071 if (colorForScript != nil || JSVAL_IS_NULL(*value))
1072 {
1073 return [[player hud] setReticleColorForIndex:OO_RETICLE_COLOR_WORMHOLE toColor:colorForScript];
1074 }
1075 break;
1076
1077 default:
1079 return NO;
1080 }
1081
1082 OOJSReportBadPropertyValue(context, this, propID, sPlayerShipProperties, *value);
1083 return NO;
1084
1086}
1087
1088
1089// *** Methods ***
1090
1091// launch()
1092static JSBool PlayerShipLaunch(JSContext *context, uintN argc, jsval *vp)
1093{
1094 OOJS_NATIVE_ENTER(context)
1095
1097
1098 [OOPlayerForScripting() launchFromStation];
1100
1102}
1103
1104
1105// removeAllCargo()
1106static JSBool PlayerShipRemoveAllCargo(JSContext *context, uintN argc, jsval *vp)
1107{
1108 OOJS_NATIVE_ENTER(context)
1109
1111
1113
1114 if ([player isDocked])
1115 {
1116 [player removeAllCargo];
1118 }
1119 else
1120 {
1121 OOJSReportError(context, @"PlayerShip.removeAllCargo only works when docked.");
1122 return NO;
1123 }
1124
1126}
1127
1128
1129// useSpecialCargo(name : String)
1130static JSBool PlayerShipUseSpecialCargo(JSContext *context, uintN argc, jsval *vp)
1131{
1132 OOJS_NATIVE_ENTER(context)
1133
1135
1137 NSString *name = nil;
1138
1139 if (argc > 0) name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1140 if (EXPECT_NOT(name == nil))
1141 {
1142 OOJSReportBadArguments(context, @"PlayerShip", @"useSpecialCargo", MIN(argc, 1U), OOJS_ARGV, nil, @"string (special cargo description)");
1143 return NO;
1144 }
1145
1146 [player useSpecialCargo:OOStringFromJSValue(context, OOJS_ARGV[0])];
1148
1150}
1151
1152
1153// engageAutopilotToStation(stationForDocking : Station) : Boolean
1154static JSBool PlayerShipEngageAutopilotToStation(JSContext *context, uintN argc, jsval *vp)
1155{
1156 OOJS_NATIVE_ENTER(context)
1157
1159
1161 StationEntity *stationForDocking = nil;
1162
1163 if (argc > 0) stationForDocking = OOJSNativeObjectOfClassFromJSValue(context, OOJS_ARGV[0], [StationEntity class]);
1164 if (stationForDocking == nil)
1165 {
1166 OOJSReportBadArguments(context, @"PlayerShip", @"engageAutopilot", MIN(argc, 1U), OOJS_ARGV, nil, @"station");
1167 return NO;
1168 }
1169
1170 OOJS_RETURN_BOOL([player engageAutopilotToStation:stationForDocking]);
1171
1173}
1174
1175
1176// disengageAutopilot()
1177static JSBool PlayerShipDisengageAutopilot(JSContext *context, uintN argc, jsval *vp)
1178{
1179 OOJS_NATIVE_ENTER(context)
1180
1182
1183 [OOPlayerForScripting() disengageAutopilot];
1185
1187}
1188
1189static JSBool PlayerShipRequestDockingClearance(JSContext *context, uintN argc, jsval *vp)
1190{
1191 OOJS_NATIVE_ENTER(context)
1192
1194
1196 StationEntity *stationForDocking = nil;
1197
1198 if (argc > 0) stationForDocking = OOJSNativeObjectOfClassFromJSValue(context, OOJS_ARGV[0], [StationEntity class]);
1199 if (stationForDocking == nil)
1200 {
1201 OOJSReportBadArguments(context, @"PlayerShip", @"requestDockingClearance", MIN(argc, 1U), OOJS_ARGV, nil, @"station");
1202 return NO;
1203 }
1204
1205 [player requestDockingClearance:stationForDocking];
1207
1209}
1210
1211static JSBool PlayerShipCancelDockingRequest(JSContext *context, uintN argc, jsval *vp)
1212{
1213 OOJS_NATIVE_ENTER(context)
1214
1216
1218 StationEntity *stationForDocking = nil;
1219
1220 if (argc > 0) stationForDocking = OOJSNativeObjectOfClassFromJSValue(context, OOJS_ARGV[0], [StationEntity class]);
1221 if (stationForDocking == nil)
1222 {
1223 OOJSReportBadArguments(context, @"PlayerShip", @"cancelDockingRequest", MIN(argc, 1U), OOJS_ARGV, nil, @"station");
1224 return NO;
1225 }
1226
1227 [player cancelDockingRequest:stationForDocking];
1229
1231}
1232
1233// awardEquipmentToCurrentPylon(externalTank: equipmentInfoExpression) : Boolean
1234static JSBool PlayerShipAwardEquipmentToCurrentPylon(JSContext *context, uintN argc, jsval *vp)
1235{
1236 OOJS_NATIVE_ENTER(context)
1237
1239
1241 NSString *key = nil;
1242 OOEquipmentType *eqType = nil;
1243
1244 if (argc > 0) key = JSValueToEquipmentKey(context, OOJS_ARGV[0]);
1245 if (key != nil) eqType = [OOEquipmentType equipmentTypeWithIdentifier:key];
1246 if (EXPECT_NOT(![eqType isMissileOrMine]))
1247 {
1248 OOJSReportBadArguments(context, @"PlayerShip", @"awardEquipmentToCurrentPylon", MIN(argc, 1U), OOJS_ARGV, nil, @"equipment type (external store)");
1249 return NO;
1250 }
1251
1252 OOJS_RETURN_BOOL([player assignToActivePylon:key]);
1253
1255}
1256
1257
1258// addPassenger(name: string, start: int, destination: int, ETA: double, fee: double) : Boolean
1259static JSBool PlayerShipAddPassenger(JSContext *context, uintN argc, jsval *vp)
1260{
1261 OOJS_NATIVE_ENTER(context)
1262
1264 NSString *name = nil;
1265 OOSystemID start = 0, destination = 0;
1266 jsdouble eta = 0.0, fee = 0.0, advance = 0.0;
1267 unsigned risk = 0;
1268
1269 if (argc < 5)
1270 {
1271 OOJSReportBadArguments(context, @"PlayerShip", @"addPassenger", argc, OOJS_ARGV, nil, @"name, start, destination, ETA, fee");
1272 return NO;
1273 }
1274
1275 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1276 if (EXPECT_NOT(name == nil))
1277 {
1278 OOJSReportBadArguments(context, @"PlayerShip", @"addPassenger", 1, &OOJS_ARGV[0], nil, @"string");
1279 return NO;
1280 }
1281
1282 if (!ValidateContracts(context, argc, vp, NO, &start, &destination, &eta, &fee, &advance, @"addPassenger", &risk)) return NO; // always go through validate contracts (passenger)
1283
1284 // Ensure there's space.
1285 if ([player passengerCount] >= [player passengerCapacity]) OOJS_RETURN_BOOL(NO);
1286
1287 BOOL OK = [player addPassenger:name start:start destination:destination eta:eta fee:fee advance:advance risk:risk];
1288 OOJS_RETURN_BOOL(OK);
1289
1291}
1292
1293
1294// removePassenger(name :string)
1295static JSBool PlayerShipRemovePassenger(JSContext *context, uintN argc, jsval *vp)
1296{
1297 OOJS_NATIVE_ENTER(context)
1298
1300 NSString *name = nil;
1301 BOOL OK = YES;
1302
1303 if (argc > 0) name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1304 if (EXPECT_NOT(name == nil))
1305 {
1306 OOJSReportBadArguments(context, @"PlayerShip", @"removePassenger", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
1307 return NO;
1308 }
1309
1310 OK = [player passengerCount] > 0 && [name length] > 0;
1311 if (OK) OK = [player removePassenger:name];
1312
1313 OOJS_RETURN_BOOL(OK);
1314
1316}
1317
1318
1319// addParcel(description: string, start: int, destination: int, ETA: double, fee: double) : Boolean
1320static JSBool PlayerShipAddParcel(JSContext *context, uintN argc, jsval *vp)
1321{
1322 OOJS_NATIVE_ENTER(context)
1323
1325 NSString *name = nil;
1326 OOSystemID start = 0, destination = 0;
1327 jsdouble eta = 0.0, fee = 0.0, premium = 0.0;
1328 unsigned risk = 0;
1329
1330 if (argc < 5)
1331 {
1332 OOJSReportBadArguments(context, @"PlayerShip", @"addParcel", argc, OOJS_ARGV, nil, @"name, start, destination, ETA, fee");
1333 return NO;
1334 }
1335
1336 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1337 if (EXPECT_NOT(name == nil))
1338 {
1339 OOJSReportBadArguments(context, @"PlayerShip", @"addParcel", 1, &OOJS_ARGV[0], nil, @"string");
1340 return NO;
1341 }
1342
1343 if (!ValidateContracts(context, argc, vp, NO, &start, &destination, &eta, &fee, &premium, @"addParcel", &risk)) return NO; // always go through validate contracts (passenger/parcel mode)
1344
1345 // Ensure there's space.
1346
1347 BOOL OK = [player addParcel:name start:start destination:destination eta:eta fee:fee premium:premium risk:risk];
1348 OOJS_RETURN_BOOL(OK);
1349
1351}
1352
1353
1354// removeParcel(description :string)
1355static JSBool PlayerShipRemoveParcel(JSContext *context, uintN argc, jsval *vp)
1356{
1357 OOJS_NATIVE_ENTER(context)
1358
1360 NSString *name = nil;
1361 BOOL OK = YES;
1362
1363 if (argc > 0) name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1364 if (EXPECT_NOT(name == nil))
1365 {
1366 OOJSReportBadArguments(context, @"PlayerShip", @"removeParcel", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
1367 return NO;
1368 }
1369
1370 OK = [player parcelCount] > 0 && [name length] > 0;
1371 if (OK) OK = [player removeParcel:name];
1372
1373 OOJS_RETURN_BOOL(OK);
1374
1376}
1377
1378
1379// awardContract(quantity: int, commodity: string, start: int, destination: int, eta: double, fee: double) : Boolean
1380static JSBool PlayerShipAwardContract(JSContext *context, uintN argc, jsval *vp)
1381{
1382 OOJS_NATIVE_ENTER(context)
1383
1385 NSString *key = nil;
1386 int32 qty = 0;
1387 OOSystemID start = 0, destination = 0;
1388 jsdouble eta = 0.0, fee = 0.0, premium = 0.0;
1389
1390 if (argc < 6)
1391 {
1392 OOJSReportBadArguments(context, @"PlayerShip", @"awardContract", argc, OOJS_ARGV, nil, @"quantity, commodity, start, destination, ETA, fee");
1393 return NO;
1394 }
1395
1396 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &qty))
1397 {
1398 OOJSReportBadArguments(context, @"PlayerShip", @"awardContract", 1, &OOJS_ARGV[0], nil, @"positive integer (cargo quantity)");
1399 return NO;
1400 }
1401
1402 key = OOStringFromJSValue(context, OOJS_ARGV[1]);
1403 if (EXPECT_NOT(key == nil))
1404 {
1405 OOJSReportBadArguments(context, @"PlayerShip", @"awardContract", 1, &OOJS_ARGV[1], nil, @"string (commodity identifier)");
1406 return NO;
1407 }
1408
1409 if (!ValidateContracts(context, argc, vp, YES, &start, &destination, &eta, &fee, &premium, @"awardContract", NULL)) return NO; // always go through validate contracts (cargo)
1410
1411 BOOL OK = [player awardContract:qty commodity:key start:start destination:destination eta:eta fee:fee premium:premium];
1412 OOJS_RETURN_BOOL(OK);
1413
1415}
1416
1417
1418// removeContract(commodity: string, destination: int)
1419static JSBool PlayerShipRemoveContract(JSContext *context, uintN argc, jsval *vp)
1420{
1421 OOJS_NATIVE_ENTER(context)
1422
1424 NSString *key = nil;
1425 int32 dest = 0;
1426
1427 if (argc < 2)
1428 {
1429 OOJSReportBadArguments(context, @"PlayerShip", @"removeContract", argc, OOJS_ARGV, nil, @"commodity, destination");
1430 return NO;
1431 }
1432
1433 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1434
1435 if (EXPECT_NOT(key == nil))
1436 {
1437 OOJSReportBadArguments(context, @"PlayerShip", @"removeContract", 1, &OOJS_ARGV[0], nil, @"string (commodity identifier)");
1438 return NO;
1439 }
1440
1441 if (!JS_ValueToInt32(context, OOJS_ARGV[1], &dest) || dest < 0 || dest > 255)
1442 {
1443 OOJSReportBadArguments(context, @"PlayerShip", @"removeContract", 1, &OOJS_ARGV[1], nil, @"system ID");
1444 return NO;
1445 }
1446
1447 BOOL OK = [player removeContract:key destination:(unsigned)dest];
1448 OOJS_RETURN_BOOL(OK);
1449
1451}
1452
1453
1454// setCustomView(position:vector, orientation:quaternion [, weapon:string])
1455static JSBool PlayerShipSetCustomView(JSContext *context, uintN argc, jsval *vp)
1456{
1457 OOJS_NATIVE_ENTER(context)
1458
1460
1461 if (argc < 2)
1462 {
1463 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomView", argc, OOJS_ARGV, nil, @"position, orientiation, [weapon]");
1464 return NO;
1465 }
1466
1467// must be in custom view
1468 if ([UNIVERSE viewDirection] != VIEW_CUSTOM)
1469 {
1470 OOJSReportError(context, @"PlayerShip.setCustomView only works when custom view is active.");
1471 return NO;
1472 }
1473
1474 NSMutableDictionary *viewData = [NSMutableDictionary dictionaryWithCapacity:3];
1475
1476 Vector position = kZeroVector;
1477 BOOL gotpos = JSValueToVector(context, OOJS_ARGV[0], &position);
1478 if (!gotpos)
1479 {
1480 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomView", argc, OOJS_ARGV, nil, @"position, orientiation, [weapon]");
1481 return NO;
1482 }
1483 NSString *positionstr = [[NSString alloc] initWithFormat:@"%f %f %f",position.x,position.y,position.z];
1484
1485 Quaternion orientation = kIdentityQuaternion;
1486 BOOL gotquat = JSValueToQuaternion(context, OOJS_ARGV[1], &orientation);
1487 if (!gotquat)
1488 {
1489 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomView", argc, OOJS_ARGV, nil, @"position, orientiation, [weapon]");
1490 return NO;
1491 }
1492 NSString *orientationstr = [[NSString alloc] initWithFormat:@"%f %f %f %f",orientation.w,orientation.x,orientation.y,orientation.z];
1493
1494 [viewData setObject:positionstr forKey:@"view_position"];
1495 [viewData setObject:orientationstr forKey:@"view_orientation"];
1496
1497 if (argc > 2)
1498 {
1499 NSString* facing = OOStringFromJSValue(context,OOJS_ARGV[2]);
1500 [viewData setObject:facing forKey:@"weapon_facing"];
1501 }
1502
1503 [player setCustomViewDataFromDictionary:viewData withScaling:NO];
1504 [player noteSwitchToView:VIEW_CUSTOM fromView:VIEW_CUSTOM];
1505
1506 [positionstr release];
1507 [orientationstr release];
1508
1509 OOJS_RETURN_BOOL(YES);
1511}
1512
1513
1514// resetCustomView()
1515static JSBool PlayerShipResetCustomView(JSContext *context, uintN argc, jsval *vp)
1516{
1517 OOJS_NATIVE_ENTER(context)
1518
1520
1521// must be in custom view
1522 if ([UNIVERSE viewDirection] != VIEW_CUSTOM)
1523 {
1524 OOJSReportError(context, @"PlayerShip.setCustomView only works when custom view is active.");
1525 return NO;
1526 }
1527
1528 [player resetCustomView];
1529 [player noteSwitchToView:VIEW_CUSTOM fromView:VIEW_CUSTOM];
1530
1531 OOJS_RETURN_BOOL(YES);
1533}
1534
1535
1536// resetScannerZoom()
1537static JSBool PlayerShipResetScannerZoom(JSContext *context, uintN argc, jsval *vp)
1538{
1539 OOJS_NATIVE_ENTER(context)
1540
1542
1543 [player resetScannerZoom];
1544
1547}
1548
1549
1550// takeInternalDamage()
1551static JSBool PlayerShipTakeInternalDamage(JSContext *context, uintN argc, jsval *vp)
1552{
1553 OOJS_NATIVE_ENTER(context)
1554
1556
1557 BOOL took = [player takeInternalDamage];
1558
1559 OOJS_RETURN_BOOL(took);
1561}
1562
1563
1564// beginHyperspaceCountdown([int: spin_time])
1565static JSBool PlayerShipBeginHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp)
1566{
1567 OOJS_NATIVE_ENTER(context)
1568
1570 int32 spin_time;
1571 int32 witchspaceSpinUpTime = 0;
1572 BOOL begun = NO;
1573 if (argc < 1)
1574 {
1575 witchspaceSpinUpTime = 0;
1576#ifdef OO_DUMP_PLANETINFO
1577 // quick intersystem jumps for debugging
1578 witchspaceSpinUpTime = 1;
1579#endif
1580 }
1581 else
1582 {
1583 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &spin_time) || spin_time < 5 || spin_time > 60)
1584 {
1585 OOJSReportBadArguments(context, @"PlayerShip", @"beginHyperspaceCountdown", 1, &OOJS_ARGV[0], nil, @"between 5 and 60 seconds");
1586 return NO;
1587 }
1588 if (spin_time < 5)
1589 {
1590 witchspaceSpinUpTime = 5;
1591 }
1592 else
1593 {
1594 witchspaceSpinUpTime = spin_time;
1595 }
1596 }
1597 if ([player hasHyperspaceMotor] && [player status] == STATUS_IN_FLIGHT && [player witchJumpChecklist:false])
1598 {
1599 [player beginWitchspaceCountdown:witchspaceSpinUpTime];
1600 begun = YES;
1601 }
1602 OOJS_RETURN_BOOL(begun);
1604}
1605
1606
1607// cancelHyperspaceCountdown()
1608static JSBool PlayerShipCancelHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp)
1609{
1610 OOJS_NATIVE_ENTER(context)
1611
1613
1614 BOOL cancelled = NO;
1615 if ([player hasHyperspaceMotor] && [player status] == STATUS_WITCHSPACE_COUNTDOWN)
1616 {
1618 [player setJumpType:false];
1619 cancelled = YES;
1620 }
1621
1622 OOJS_RETURN_BOOL(cancelled);
1624
1625}
1626
1627
1628static JSBool PlayerShipBeginGalacticHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp)
1629{
1630 OOJS_NATIVE_ENTER(context)
1631
1633 int32 spin_time;
1634 int32 witchspaceSpinUpTime = 5;
1635 BOOL begun = NO;
1636 if (argc == 1)
1637 {
1638
1639 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &spin_time) || spin_time < 5 || spin_time > 60)
1640 {
1641 OOJSReportBadArguments(context, @"PlayerShip", @"beginGalacticHyperspaceCountdown", 1, &OOJS_ARGV[0], nil, @"between 5 and 60 seconds");
1642 return NO;
1643 }
1644 if (spin_time < 5)
1645 {
1646 witchspaceSpinUpTime = 5;
1647 }
1648 else
1649 {
1650 witchspaceSpinUpTime = spin_time;
1651 }
1652 }
1653 if ([player hasEquipmentItemProviding:@"EQ_GAL_DRIVE"] && [player status] == STATUS_IN_FLIGHT && [player witchJumpChecklist:true])
1654 {
1655 [player setJumpType:YES];
1656 [player setWitchspaceCountdown:witchspaceSpinUpTime];
1657 [player setStatus:STATUS_WITCHSPACE_COUNTDOWN];
1658 [player playGalacticHyperspace];
1659 // say it!
1660 [UNIVERSE addMessage:[NSString stringWithFormat:DESC(@"witch-galactic-in-f-seconds"), witchspaceSpinUpTime] forCount:1.0];
1661 begun = YES;
1662 }
1663 OOJS_RETURN_BOOL(begun);
1665}
1666
1667
1668// setMultiFunctionDisplay(index,key)
1669static JSBool PlayerShipSetMultiFunctionDisplay(JSContext *context, uintN argc, jsval *vp)
1670{
1671 OOJS_NATIVE_ENTER(context)
1672
1673 NSString *key = nil;
1674 uint32 index = 0;
1676 BOOL OK = YES;
1677
1678 if (argc > 0)
1679 {
1680 if (!JS_ValueToECMAUint32(context,OOJS_ARGV[0],&index))
1681 {
1682 OOJSReportBadArguments(context, @"PlayerShip", @"setMultiFunctionDisplay", MIN(argc, 1U), OOJS_ARGV, nil, @"number (index) [, string (key)]");
1683 return NO;
1684 }
1685 }
1686
1687 if (argc > 1)
1688 {
1689 key = OOStringFromJSValue(context, OOJS_ARGV[1]);
1690 }
1691
1692 OK = [player setMultiFunctionDisplay:index toKey:key];
1693
1694 OOJS_RETURN_BOOL(OK);
1695
1697}
1698
1699
1700// setMultiFunctionText(key,value)
1701static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsval *vp)
1702{
1703 OOJS_NATIVE_ENTER(context)
1704
1705 NSString *key = nil;
1706 NSString *value = nil;
1708 JSBool reflow = NO;
1709
1710 if (argc > 0)
1711 {
1712 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1713 }
1714 if (key == nil)
1715 {
1716 OOJSReportBadArguments(context, @"PlayerShip", @"setMultiFunctionText", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key) [, string (text)]");
1717 return NO;
1718 }
1719 if (argc > 1)
1720 {
1721 value = OOStringFromJSValue(context, OOJS_ARGV[1]);
1722 }
1723 if (argc > 2 && EXPECT_NOT(!JS_ValueToBoolean(context, OOJS_ARGV[2], &reflow)))
1724 {
1725 OOJSReportBadArguments(context, @"setMultiFunctionText", @"reflow", argc, OOJS_ARGV, nil, @"boolean");
1726 return NO;
1727 }
1728
1729 if (!reflow)
1730 {
1731 [player setMultiFunctionText:value forKey:key];
1732 }
1733 else
1734 {
1735 GuiDisplayGen *gui = [UNIVERSE gui];
1736 NSString *formatted = [gui reflowTextForMFD:value];
1737 [player setMultiFunctionText:formatted forKey:key];
1738 }
1739
1741
1743}
1744
1745// setPrimedEquipment(key, [noMessage])
1746static JSBool PlayerShipSetPrimedEquipment(JSContext *context, uintN argc, jsval *vp)
1747{
1748 OOJS_NATIVE_ENTER(context)
1749
1750 NSString *key = nil;
1752 JSBool showMsg = YES;
1753
1754 if (argc > 0)
1755 {
1756 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1757 }
1758 if (key == nil)
1759 {
1760 OOJSReportBadArguments(context, @"PlayerShip", @"setPrimedEquipment", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key)");
1761 return NO;
1762 }
1763 if (argc > 1 && EXPECT_NOT(!JS_ValueToBoolean(context, OOJS_ARGV[1], &showMsg)))
1764 {
1765 OOJSReportBadArguments(context, @"PlayerShip", @"setPrimedEquipment", MIN(argc, 2U), OOJS_ARGV, nil, @"boolean");
1766 return NO;
1767 }
1768
1769 OOJS_RETURN_BOOL([player setPrimedEquipment:key showMessage:showMsg]);
1770
1772}
1773
1774
1775// setCustomHUDDial(key,value)
1776static JSBool PlayerShipSetCustomHUDDial(JSContext *context, uintN argc, jsval *vp)
1777{
1778 OOJS_NATIVE_ENTER(context)
1779
1780 NSString *key = nil;
1781 id value = nil;
1783
1784 if (argc > 0)
1785 {
1786 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1787 }
1788 if (key == nil)
1789 {
1790 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomHUDDial", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key), value]");
1791 return NO;
1792 }
1793 if (argc > 1)
1794 {
1795 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[1]);
1796 }
1797 else
1798 {
1799 value = @"";
1800 }
1801
1802 [player setDialCustom:value forKey:key];
1803
1804
1806
1808}
1809
1810
1811static JSBool PlayerShipHideHUDSelector(JSContext *context, uintN argc, jsval *vp)
1812{
1813 OOJS_NATIVE_ENTER(context)
1814
1815 NSString *key = nil;
1817
1818 if (argc > 0)
1819 {
1820 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1821 }
1822 if (key == nil)
1823 {
1824 OOJSReportBadArguments(context, @"PlayerShip", @"hideHUDSelector", MIN(argc, 1U), OOJS_ARGV, nil, @"string (selector)");
1825 return NO;
1826 }
1827 [[player hud] setHiddenSelector:key hidden:YES];
1828
1830
1832}
1833
1834
1835static JSBool PlayerShipShowHUDSelector(JSContext *context, uintN argc, jsval *vp)
1836{
1837 OOJS_NATIVE_ENTER(context)
1838
1839 NSString *key = nil;
1841
1842 if (argc > 0)
1843 {
1844 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1845 }
1846 if (key == nil)
1847 {
1848 OOJSReportBadArguments(context, @"PlayerShip", @"hideHUDSelector", MIN(argc, 1U), OOJS_ARGV, nil, @"string (selector)");
1849 return NO;
1850 }
1851 [[player hud] setHiddenSelector:key hidden:NO];
1852
1854
1856}
1857
1858
1859
1860static BOOL ValidateContracts(JSContext *context, uintN argc, jsval *vp, BOOL isCargo, OOSystemID *start, OOSystemID *destination, double *eta, double *fee, double *premium, NSString *functionName, unsigned *risk)
1861{
1863
1864 NSCParameterAssert(context != NULL && vp != NULL && start != NULL && destination != NULL && eta != NULL && fee != NULL);
1865
1866 unsigned uValue, offset = isCargo ? 2 : 1;
1867 jsdouble fValue;
1868 int32 iValue;
1869
1870 if (!JS_ValueToInt32(context, OOJS_ARGV[offset + 0], &iValue) || iValue < 0 || iValue > kOOMaximumSystemID)
1871 {
1872 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 0], nil, @"system ID");
1873 return NO;
1874 }
1875 *start = iValue;
1876
1877 if (!JS_ValueToInt32(context, OOJS_ARGV[offset + 1], &iValue) || iValue < 0 || iValue > kOOMaximumSystemID)
1878 {
1879 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 1], nil, @"system ID");
1880 return NO;
1881 }
1882 *destination = iValue;
1883
1884
1885 if (!JS_ValueToNumber(context, OOJS_ARGV[offset + 2], &fValue) || !isfinite(fValue) || fValue <= [PLAYER clockTime])
1886 {
1887 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 2], nil, @"number (future time)");
1888 return NO;
1889 }
1890 *eta = fValue;
1891
1892 if (!JS_ValueToNumber(context, OOJS_ARGV[offset + 3], &fValue) || !isfinite(fValue) || fValue < 0.0)
1893 {
1894 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 3], nil, @"number (credits quantity)");
1895 return NO;
1896 }
1897 *fee = fValue;
1898
1899 if (argc > offset+4 && JS_ValueToNumber(context, OOJS_ARGV[offset + 4], &fValue) && isfinite(fValue) && fValue >= 0.0)
1900 {
1901 *premium = fValue;
1902 }
1903
1904 if (!isCargo)
1905 {
1906 if (argc > offset+5 && JS_ValueToECMAUint32(context, OOJS_ARGV[offset + 5], &uValue) && isfinite((double)uValue))
1907 {
1908 *risk = uValue;
1909 }
1910 }
1911
1912 return YES;
1913
1915}
id OOConsumeReference(id OO_NS_CONSUMED value)
Definition OOCocoa.m:93
OOINLINE jsval OOJSValueFromGalacticHyperspaceBehaviour(JSContext *context, OOGalacticHyperspaceBehaviour value)
OOINLINE jsval OOJSValueFromViewID(JSContext *context, OOViewID value)
OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSValue(JSContext *context, jsval value)
OOINLINE OOCompassMode OOCompassModeFromJSValue(JSContext *context, jsval value)
OOINLINE jsval OOJSValueFromCompassMode(JSContext *context, OOCompassMode value)
NSString * OOStringFromLongRangeChartMode(OOLongRangeChartMode chartMode)
OOLongRangeChartMode OOLongRangeChartModeFromString(NSString *string)
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_PROFILE_ENTER
OOINLINE BOOL OOIsPlayerStale(void)
Definition OOJSEntity.h:65
BOOL JSValueToEntity(JSContext *context, jsval value, Entity **outEntity)
Definition OOJSEntity.m:146
NSString * JSValueToEquipmentKeyRelaxed(JSContext *context, jsval value, BOOL *outExists)
NSString * JSValueToEquipmentKey(JSContext *context, jsval value)
static JSBool PlayerShipSetPrimedEquipment(JSContext *context, uintN argc, jsval *vp)
static JSFunctionSpec sPlayerShipMethods[]
static JSBool PlayerShipEngageAutopilotToStation(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipAddParcel(JSContext *context, uintN argc, jsval *vp)
static JSClass sPlayerShipClass
static JSBool PlayerShipBeginHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipSetCustomView(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipTakeInternalDamage(JSContext *context, uintN argc, jsval *vp)
static BOOL ValidateContracts(JSContext *context, uintN argc, jsval *vp, BOOL isCargo, OOSystemID *start, OOSystemID *destination, double *eta, double *fee, double *premium, NSString *functionName, unsigned *risk)
static JSObject * sPlayerShipObject
static JSBool PlayerShipResetScannerZoom(JSContext *context, uintN argc, jsval *vp)
static JSObject * sPlayerShipPrototype
static JSBool PlayerShipHideHUDSelector(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipSetCustomHUDDial(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipUseSpecialCargo(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipCancelDockingRequest(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipRemoveContract(JSContext *context, uintN argc, jsval *vp)
@ kPlayerShip_docked
@ kPlayerShip_compassMode
@ kPlayerShip_serviceLevel
@ kPlayerShip_cursorCoordinates
@ kPlayerShip_reticleTargetSensitive
@ kPlayerShip_maxForwardShield
@ kPlayerShip_dockedStation
@ kPlayerShip_targetSystem
@ kPlayerShip_roll
@ kPlayerShip_massLockable
@ kPlayerShip_scannerNonLinear
@ kPlayerShip_hud
@ kPlayerShip_injectorsEngaged
@ kPlayerShip_activeMissile
@ kPlayerShip_galacticHyperspaceBehaviour
@ kPlayerShip_fuelLeakRate
@ kPlayerShip_viewPositionAft
@ kPlayerShip_cursorCoordinatesInLY
@ kPlayerShip_torusEngaged
@ kPlayerShip_reticleColorTargetSensitive
@ kPlayerShip_aftShield
@ kPlayerShip_chartHightlightMode
@ kPlayerShip_yaw
@ kPlayerShip_scoopOverride
@ kPlayerShip_currentWeapon
@ kPlayerShip_missilesOnline
@ kPlayerShip_pitch
@ kPlayerShip_fastEquipmentA
@ kPlayerShip_messageGuiTextCommsColor
@ kPlayerShip_multiFunctionDisplayList
@ kPlayerShip_price
@ kPlayerShip_viewPositionForward
@ kPlayerShip_galaxyCoordinates
@ kPlayerShip_compassType
@ kPlayerShip_compassTarget
@ kPlayerShip_galaxyCoordinatesInLY
@ kPlayerShip_infoSystem
@ kPlayerShip_multiFunctionDisplays
@ kPlayerShip_galacticHyperspaceFixedCoordsInLY
@ kPlayerShip_fastEquipmentB
@ kPlayerShip_nextSystem
@ kPlayerShip_scannerUltraZoom
@ kPlayerShip_viewPositionStarboard
@ kPlayerShip_messageGuiTextColor
@ kPlayerShip_renovationCost
@ kPlayerShip_crosshairs
@ kPlayerShip_scannerMinimalistic
@ kPlayerShip_routeMode
@ kPlayerShip_galacticHyperspaceFixedCoords
@ kPlayerShip_weaponsOnline
@ kPlayerShip_reticleColorTarget
@ kPlayerShip_maxAftShield
@ kPlayerShip_viewPositionPort
@ kPlayerShip_hudAllowsBigGui
@ kPlayerShip_specialCargo
@ kPlayerShip_forwardShieldRechargeRate
@ kPlayerShip_viewDirection
@ kPlayerShip_reticleColorWormhole
@ kPlayerShip_forwardShield
@ kPlayerShip_primedEquipment
@ kPlayerShip_aftShieldRechargeRate
@ kPlayerShip_hudHidden
@ kPlayerShip_renovationMultiplier
@ kPlayerShip_previousSystem
static JSBool PlayerShipRemoveAllCargo(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipAddPassenger(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipResetCustomView(JSContext *context, uintN argc, jsval *vp)
JSObject * JSPlayerShipObject(void)
static JSBool PlayerShipAwardContract(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool PlayerShipRemoveParcel(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipDisengageAutopilot(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipRemovePassenger(JSContext *context, uintN argc, jsval *vp)
void InitOOJSPlayerShip(JSContext *context, JSObject *global)
static JSBool PlayerShipShowHUDSelector(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipRequestDockingClearance(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSPropertySpec sPlayerShipProperties[]
JSObject * JSPlayerShipPrototype(void)
static JSBool PlayerShipBeginGalacticHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipSetMultiFunctionDisplay(JSContext *context, uintN argc, jsval *vp)
JSClass * JSPlayerShipClass(void)
static JSBool PlayerShipLaunch(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipCancelHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerShipAwardEquipmentToCurrentPylon(JSContext *context, uintN argc, jsval *vp)
JSObject * JSPlayerObject(void)
Definition OOJSPlayer.m:185
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
JSObject * JSShipPrototype(void)
Definition OOJSShip.m:601
JSClass * JSShipClass(void)
Definition OOJSShip.m:595
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:259
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:246
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:185
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_PROP_READWRITE_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_BOOL(v)
id OOJSNativeObjectOfClassFromJSValue(JSContext *context, jsval value, Class requiredClass)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
OOINLINE JSContext * OOJSAcquireContext(void)
void OOJSReportError(JSContext *context, NSString *format,...)
#define OOJS_ARGV
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_PROP_READONLY_CB
#define OOJS_RETURN_VOID
#define MIN(A, B)
Definition OOMaths.h:111
return nil
const Quaternion kIdentityQuaternion
#define OO_SYSTEMS_PER_GALAXY
OOLongRangeChartMode
Definition OOTypes.h:50
OORouteType
Definition OOTypes.h:33
@ OPTIMIZED_BY_NONE
Definition OOTypes.h:34
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:35
@ OPTIMIZED_BY_TIME
Definition OOTypes.h:36
int16_t OOSystemID
Definition OOTypes.h:211
OOCompassMode
Definition OOTypes.h:145
@ kOOMaximumSystemID
Definition OOTypes.h:217
const Vector kZeroVector
Definition OOVector.m:28
NSPoint OOInternalCoordinatesFromGalactic(Vector galacticCoordinates)
Vector OOGalacticCoordinatesFromInternal(NSPoint internalCoordinates)
OOGalacticHyperspaceBehaviour
#define PLAYER
#define UNIVERSE
Definition Universe.h:833
OOEntityStatus status()
Definition Entity.m:793
NSString * reflowTextForMFD:(NSString *input)
void setHidden:(BOOL newValue)
void setReticleTargetSensitive:(BOOL newReticleTargetSensitiveValue)
void setNonlinearScanner:(BOOL newValue)
NSString * hudName
void setScannerUltraZoom:(BOOL newValue)
NSString * crosshairDefinition
BOOL setReticleColorForIndex:toColor:(NSUInteger idx,[toColor] OOColor *newColor)
void setHiddenSelector:hidden:(NSString *selectorName,[hidden] BOOL hide)
OOColor * reticleColorForIndex:(NSUInteger idx)
void setMinimalisticScanner:(BOOL newValue)
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127
NSArray * normalizedArray()
Definition OOColor.m:511
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
OOJavaScriptEngine * sharedEngine()
void setNextCompassMode()
void setMaxAftShieldLevel:(float new)
void setForwardShieldLevel:(GLfloat level)
BOOL setMultiFunctionDisplay:toKey:(NSUInteger index,[toKey] NSString *key)
void setMultiFunctionText:forKey:(NSString *text,[forKey] NSString *key)
void setAftShieldRechargeRate:(float new)
OOWeakReference * compassTarget
void setAftShieldLevel:(GLfloat level)
BOOL awardContract:commodity:start:destination:eta:fee:premium:(unsigned qty,[commodity] NSString *commodity,[start] unsigned start,[destination] unsigned destination,[eta] double eta,[fee] double fee,[premium] double premium)
OOLongRangeChartMode longRangeChartMode
NSUInteger passengerCount()
void setGalacticHyperspaceFixedCoords:(NSPoint point)
StationEntity * dockedStation()
NSString * specialCargo
BOOL addPassenger:start:destination:eta:fee:advance:risk:(NSString *Name,[start] unsigned start,[destination] unsigned destination,[eta] double eta,[fee] double fee,[advance] double advance,[risk] unsigned risk)
void useSpecialCargo:(NSString *descriptionString)
BOOL switchHudTo:(NSString *hudFileName)
NSDictionary * commanderDataDictionary()
void setFastEquipmentA:(NSString *eqKey)
OORouteType ANAMode()
void setFastEquipmentB:(NSString *eqKey)
void beginWitchspaceCountdown:(int spin_time)
void setJSSelf:context:(JSObject *val,[context] JSContext *context)
BOOL setWeaponMount:toWeapon:inContext:(OOWeaponFacing facing,[toWeapon] NSString *eqKey,[inContext] NSString *context)
BOOL removeParcel:(NSString *Name)
void setInfoSystemID:moveChart:(OOSystemID sid,[moveChart] BOOL moveChart)
void cancelDockingRequest:(StationEntity *stationForDocking)
BOOL takeInternalDamage()
NSUInteger parcelCount()
void setDialCustom:forKey:(id value,[forKey] NSString *key)
NSString * fastEquipmentA()
void noteSwitchToView:fromView:(OOViewID toView,[fromView] OOViewID fromView)
NSString * currentPrimedEquipment()
NSArray * multiFunctionDisplayList()
void setFuelLeakRate:(float value)
void setJumpType:(BOOL isGalacticJump)
HeadUpDisplay * hud
void setLongRangeChartMode:(OOLongRangeChartMode mode)
void setCompassMode:(OOCompassMode value)
BOOL addParcel:start:destination:eta:fee:premium:risk:(NSString *Name,[start] unsigned start,[destination] unsigned destination,[eta] double eta,[fee] double fee,[premium] double premium,[risk] unsigned risk)
BOOL setPrimedEquipment:showMessage:(NSString *eqKey,[showMessage] BOOL showMsg)
void setScoopOverride:(BOOL newValue)
NSString * fastEquipmentB()
BOOL removeContract:destination:(NSString *commodity,[destination] unsigned destination)
void validateCompassTarget()
void setGalacticHyperspaceBehaviour:(OOGalacticHyperspaceBehaviour galacticHyperspaceBehaviour)
BOOL removePassenger:(NSString *Name)
void setWitchspaceCountdown:(int spin_time)
void setCustomViewDataFromDictionary:withScaling:(NSDictionary *viewDict,[withScaling] BOOL withScaling)
void requestDockingClearance:(StationEntity *stationForDocking)
void adjustTradeInFactorBy:(int value)
OOCompassMode compassMode
BOOL witchJumpChecklist:(BOOL isGalacticJump)
void setForwardShieldRechargeRate:(float new)
void setMassLockable:(BOOL newValue)
OOEquipmentType * weaponTypeForFacing:strict:(OOWeaponFacing facing, [strict] BOOL strict)
PlayerEntity * sharedPlayer()
void setTargetSystemID:(OOSystemID sid)
void setMaxForwardShieldLevel:(float new)
void decrease_flight_roll:(double delta)
OOWeaponFacing currentWeaponFacing
Definition ShipEntity.h:312
void setStatus:(OOEntityStatus stat)
void decrease_flight_yaw:(double delta)
GLfloat flightPitch
Definition ShipEntity.h:370
void doScriptEvent:withArgument:(jsid message,[withArgument] id argument)
void decrease_flight_pitch:(double delta)
GLfloat flightRoll
Definition ShipEntity.h:369
GLfloat flightYaw
Definition ShipEntity.h:371
voidpf uLong offset
Definition ioapi.h:140
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
const char int mode
Definition ioapi.h:133