Oolite
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 "HeadUpDisplay.h"
28#import "OOJSEntity.h"
29#import "OOJSPlayer.h"
30#import "OOJSQuaternion.h"
31#import "OOJSShip.h"
32#import "OOJSVector.h"
39#import "PlayerEntitySound.h"
40#import "StationEntity.h"
41
42#import "OOConstToJSString.h"
43#import "OOConstToString.h"
44#import "OOEquipmentType.h"
46#import "OOJSEquipmentInfo.h"
47
48static JSObject* sPlayerShipPrototype;
49static JSObject* sPlayerShipObject;
50
51static JSBool PlayerShipGetProperty(JSContext* context, JSObject* this, jsid propID, jsval* value);
52static JSBool PlayerShipSetProperty(JSContext* context, JSObject* this, jsid propID, JSBool strict, jsval* value);
53
54static JSBool PlayerShipLaunch(JSContext* context, uintN argc, jsval* vp);
55static JSBool PlayerShipRemoveAllCargo(JSContext* context, uintN argc, jsval* vp);
56static JSBool PlayerShipUseSpecialCargo(JSContext* context, uintN argc, jsval* vp);
57static JSBool PlayerShipEngageAutopilotToStation(JSContext* context, uintN argc, jsval* vp);
58static JSBool PlayerShipDisengageAutopilot(JSContext* context, uintN argc, jsval* vp);
59static JSBool PlayerShipRequestDockingClearance(JSContext* context, uintN argc, jsval* vp);
60static JSBool PlayerShipCancelDockingRequest(JSContext* context, uintN argc, jsval* vp);
61static JSBool PlayerShipAwardEquipmentToCurrentPylon(JSContext* context, uintN argc, jsval* vp);
62static JSBool PlayerShipAddPassenger(JSContext* context, uintN argc, jsval* vp);
63static JSBool PlayerShipRemovePassenger(JSContext* context, uintN argc, jsval* vp);
64static JSBool PlayerShipAddParcel(JSContext* context, uintN argc, jsval* vp);
65static JSBool PlayerShipRemoveParcel(JSContext* context, uintN argc, jsval* vp);
66static JSBool PlayerShipAwardContract(JSContext* context, uintN argc, jsval* vp);
67static JSBool PlayerShipRemoveContract(JSContext* context, uintN argc, jsval* vp);
68static JSBool PlayerShipSetCustomView(JSContext* context, uintN argc, jsval* vp);
69static JSBool PlayerShipSetPrimedEquipment(JSContext* context, uintN argc, jsval* vp);
70static JSBool PlayerShipResetCustomView(JSContext* context, uintN argc, jsval* vp);
71static JSBool PlayerShipResetScannerZoom(JSContext* context, uintN argc, jsval* vp);
72static JSBool PlayerShipTakeInternalDamage(JSContext* context, uintN argc, jsval* vp);
73static JSBool PlayerShipBeginHyperspaceCountdown(JSContext* context, uintN argc, jsval* vp);
74static JSBool PlayerShipCancelHyperspaceCountdown(JSContext* context, uintN argc, jsval* vp);
75static JSBool PlayerShipBeginGalacticHyperspaceCountdown(JSContext* context, uintN argc, jsval* vp);
76static JSBool PlayerShipSetMultiFunctionDisplay(JSContext* context, uintN argc, jsval* vp);
77static JSBool PlayerShipSetMultiFunctionText(JSContext* context, uintN argc, jsval* vp);
78static JSBool PlayerShipHideHUDSelector(JSContext* context, uintN argc, jsval* vp);
79static JSBool PlayerShipShowHUDSelector(JSContext* context, uintN argc, jsval* vp);
80static JSBool PlayerShipSetCustomHUDDial(JSContext* context, uintN argc, jsval* vp);
81
82static BOOL ValidateContracts(JSContext* context, uintN argc, jsval* vp, BOOL isCargo, OOSystemID* start, OOSystemID* destination, double* eta, double* fee, double* premium, NSString* functionName, unsigned* risk);
83
84static JSClass sPlayerShipClass = {
85 "PlayerShip",
86 JSCLASS_HAS_PRIVATE,
87
88 JS_PropertyStub, // addProperty
89 JS_PropertyStub, // delProperty
90 PlayerShipGetProperty, // getProperty
91 PlayerShipSetProperty, // setProperty
92 JS_EnumerateStub, // enumerate
93 JS_ResolveStub, // resolve
94 JS_ConvertStub, // convert
95 OOJSObjectWrapperFinalize, // finalize
96 JSCLASS_NO_OPTIONAL_MEMBERS
97};
98
99enum {
100 // Property IDs
101 kPlayerShip_activeMissile, // index in 'missiles' array of current active missile
102 kPlayerShip_aftShield, // aft shield charge level, nonnegative float, read/write
103 kPlayerShip_aftShieldRechargeRate, // aft shield recharge rate, positive float, read-only
104 kPlayerShip_chartHightlightMode, // what type of information is being shown on the chart
105 kPlayerShip_compassMode, // compass mode, string, read/write
106 kPlayerShip_compassTarget, // object targeted by the compass, entity, read/write
107 kPlayerShip_compassType, // basic / advanced, string, read/write
108 kPlayerShip_currentWeapon, // shortcut property to _aftWeapon, etc. overrides kShip generic version
109 kPlayerShip_crosshairs, // custom plist file defining crosshairs
110 kPlayerShip_cursorCoordinates, // cursor coordinates (unscaled), Vector3D, read only
111 kPlayerShip_cursorCoordinatesInLY, // cursor coordinates (in LY), Vector3D, read only
112 kPlayerShip_docked, // docked, boolean, read-only
113 kPlayerShip_dockedStation, // docked station, entity, read-only
114 kPlayerShip_fastEquipmentA, // fast equipment A, string, read/write
115 kPlayerShip_fastEquipmentB, // fast equipment B, string, read/write
116 kPlayerShip_forwardShield, // forward shield charge level, nonnegative float, read/write
117 kPlayerShip_forwardShieldRechargeRate, // forward shield recharge rate, positive float, read-only
118 kPlayerShip_fuelLeakRate, // fuel leak rate, float, read/write
119 kPlayerShip_galacticHyperspaceBehaviour, // can be standard, all systems reachable or fixed coordinates, integer, read-only
120 kPlayerShip_galacticHyperspaceFixedCoords, // used when fixed coords behaviour is selected, Vector3D, read/write
121 kPlayerShip_galacticHyperspaceFixedCoordsInLY, // used when fixed coords behaviour is selected, Vector3D, read/write
122 kPlayerShip_galaxyCoordinates, // galaxy coordinates (unscaled), Vector3D, read only
123 kPlayerShip_galaxyCoordinatesInLY, // galaxy coordinates (in LY), Vector3D, read only
124 kPlayerShip_hud, // hud name identifier, string, read/write
125 kPlayerShip_hudAllowsBigGui, // hud big gui, string, read only
126 kPlayerShip_hudHidden, // hud visibility, boolean, read/write
127 kPlayerShip_injectorsEngaged, // injectors in use, boolean, read-only
128 kPlayerShip_massLockable, // mass-lockability of player ship, read/write
129 kPlayerShip_maxAftShield, // maximum aft shield charge level, positive float, read-only
130 kPlayerShip_maxForwardShield, // maximum forward shield charge level, positive float, read-only
131 kPlayerShip_messageGuiTextColor, // message gui standard text color, array, read/write
132 kPlayerShip_messageGuiTextCommsColor, // message gui incoming comms text color, array, read/write
133 kPlayerShip_multiFunctionDisplays, // mfd count, positive int, read-only
134 kPlayerShip_multiFunctionDisplayList, // active mfd list, array, read-only
135 kPlayerShip_missilesOnline, // bool (false for ident mode, true for missile mode)
136 kPlayerShip_pitch, // pitch (overrules Ship)
137 kPlayerShip_price, // idealised trade-in value decicredits, positive int, read-only
138 kPlayerShip_primedEquipment, // currently primed equipment, string, read/write
139 kPlayerShip_renovationCost, // int read-only current renovation cost
140 kPlayerShip_reticleColorTarget, // Reticle color for normal targets, array, read/write
141 kPlayerShip_reticleColorTargetSensitive, // Reticle color for targets picked up when sensitive mode is on, array, read/write
142 kPlayerShip_reticleColorWormhole, // REticle color for wormholes, array, read/write
143 kPlayerShip_renovationMultiplier, // float read-only multiplier for renovation costs
144 kPlayerShip_reticleTargetSensitive, // target box changes color when primary target in crosshairs, boolean, read/write
145 kPlayerShip_roll, // roll (overrules Ship)
147 kPlayerShip_scannerMinimalistic, // essentially scanner without gridlines
148 kPlayerShip_scannerNonLinear, // non linear scanner setting, boolean, read/write
149 kPlayerShip_scannerUltraZoom, // scanner zoom in powers of 2, boolean, read/write
151 kPlayerShip_serviceLevel, // servicing level, positive int 75-100, read-only
152 kPlayerShip_specialCargo, // special cargo, string, read-only
153 kPlayerShip_targetSystem, // target system id, int, read-write
154 kPlayerShip_nextSystem, // next hop system id, read-only
155 kPlayerShip_infoSystem, // info (F7 screen) system id, int, read-write
156 kPlayerShip_previousSystem, // previous system id, read-only
157 kPlayerShip_torusEngaged, // torus in use, boolean, read-only
158 kPlayerShip_viewDirection, // view direction identifier, string, read-only
159 kPlayerShip_viewPositionAft, // view position offset, vector, read-only
160 kPlayerShip_viewPositionForward, // view position offset, vector, read-only
161 kPlayerShip_viewPositionPort, // view position offset, vector, read-only
162 kPlayerShip_viewPositionStarboard, // view position offset, vector, read-only
163 kPlayerShip_weaponsOnline, // weapons online status, boolean, read-only
164 kPlayerShip_yaw, // yaw (overrules Ship)
165};
166
167static JSPropertySpec sPlayerShipProperties[] = {
168 // JS name ID flags
171 { "aftShieldRechargeRate", kPlayerShip_aftShieldRechargeRate, OOJS_PROP_READWRITE_CB },
179 { "cursorCoordinatesInLY", kPlayerShip_cursorCoordinatesInLY, OOJS_PROP_READONLY_CB },
185 { "forwardShieldRechargeRate", kPlayerShip_forwardShieldRechargeRate, OOJS_PROP_READWRITE_CB },
187 { "galacticHyperspaceBehaviour", kPlayerShip_galacticHyperspaceBehaviour, OOJS_PROP_READWRITE_CB },
188 { "galacticHyperspaceFixedCoords", kPlayerShip_galacticHyperspaceFixedCoords, OOJS_PROP_READWRITE_CB },
189 { "galacticHyperspaceFixedCoordsInLY", kPlayerShip_galacticHyperspaceFixedCoordsInLY, OOJS_PROP_READWRITE_CB },
191 { "galaxyCoordinatesInLY", kPlayerShip_galaxyCoordinatesInLY, OOJS_PROP_READONLY_CB },
197 // manifest defined in OOJSManifest.m
201 { "messageGuiTextCommsColor", kPlayerShip_messageGuiTextCommsColor, OOJS_PROP_READWRITE_CB },
203 { "multiFunctionDisplays", kPlayerShip_multiFunctionDisplays, OOJS_PROP_READONLY_CB },
204 { "multiFunctionDisplayList", kPlayerShip_multiFunctionDisplayList, OOJS_PROP_READONLY_CB },
210 { "reticleColorTargetSensitive", kPlayerShip_reticleColorTargetSensitive, OOJS_PROP_READWRITE_CB },
211 { "reticleColorWormhole", kPlayerShip_reticleColorWormhole, OOJS_PROP_READWRITE_CB },
212 { "renovationMultiplier", kPlayerShip_renovationMultiplier, OOJS_PROP_READONLY_CB },
213 { "reticleTargetSensitive", kPlayerShip_reticleTargetSensitive, OOJS_PROP_READWRITE_CB },
229 { "viewPositionForward", kPlayerShip_viewPositionForward, OOJS_PROP_READONLY_CB },
231 { "viewPositionStarboard", kPlayerShip_viewPositionStarboard, OOJS_PROP_READONLY_CB },
234 { 0 }
235};
236
237static JSFunctionSpec sPlayerShipMethods[] = {
238 // JS name Function min args
239 { "addParcel", PlayerShipAddParcel, 0 },
240 { "addPassenger", PlayerShipAddPassenger, 0 },
241 { "awardContract", PlayerShipAwardContract, 0 },
242 { "awardEquipmentToCurrentPylon", PlayerShipAwardEquipmentToCurrentPylon, 1 },
243 { "beginHyperspaceCountdown", PlayerShipBeginHyperspaceCountdown, 0 },
244 { "cancelDockingRequest", PlayerShipCancelDockingRequest, 1 },
245 { "cancelHyperspaceCountdown", PlayerShipCancelHyperspaceCountdown, 0 },
246 { "beginGalacticHyperspaceCountdown", PlayerShipBeginGalacticHyperspaceCountdown, 1 },
247 { "disengageAutopilot", PlayerShipDisengageAutopilot, 0 },
248 { "engageAutopilotToStation", PlayerShipEngageAutopilotToStation, 1 },
249 { "hideHUDSelector", PlayerShipHideHUDSelector, 1 },
250 { "launch", PlayerShipLaunch, 0 },
251 { "removeAllCargo", PlayerShipRemoveAllCargo, 0 },
252 { "removeContract", PlayerShipRemoveContract, 2 },
253 { "removeParcel", PlayerShipRemoveParcel, 1 },
254 { "removePassenger", PlayerShipRemovePassenger, 1 },
255 { "requestDockingClearance", PlayerShipRequestDockingClearance, 1 },
256 { "resetCustomView", PlayerShipResetCustomView, 0 },
257 { "resetScannerZoom", PlayerShipResetScannerZoom, 0 },
258 { "setCustomView", PlayerShipSetCustomView, 2 },
259 { "setCustomHUDDial", PlayerShipSetCustomHUDDial, 2 },
260 { "setMultiFunctionDisplay", PlayerShipSetMultiFunctionDisplay, 1 },
261 { "setMultiFunctionText", PlayerShipSetMultiFunctionText, 1 },
262 { "setPrimedEquipment", PlayerShipSetPrimedEquipment, 1 },
263 { "showHUDSelector", PlayerShipShowHUDSelector, 1 },
264 { "takeInternalDamage", PlayerShipTakeInternalDamage, 0 },
265 { "useSpecialCargo", PlayerShipUseSpecialCargo, 1 },
266 { 0 }
267};
268
269void InitOOJSPlayerShip(JSContext* context, JSObject* global)
270{
274
275 PlayerEntity* player = [PlayerEntity sharedPlayer]; // NOTE: at time of writing, this creates the player entity. Don't use PLAYER here.
276
277 // Create ship object as a property of the player object.
279 JS_SetPrivate(context, sPlayerShipObject, OOConsumeReference([player weakRetain]));
280 [player setJSSelf:sPlayerShipObject context:context];
281 // Analyzer: object leaked. [Expected, object is retained by JS object.]
282}
283
284JSClass* JSPlayerShipClass(void)
285{
286 return &sPlayerShipClass;
287}
288
290{
292}
293
294JSObject* JSPlayerShipObject(void)
295{
296 return sPlayerShipObject;
297}
298
299@implementation PlayerEntity (OOJavaScriptExtensions)
300
301- (NSString*)oo_jsClassName
302{
303 return @"PlayerShip";
304}
305
306- (void)setJSSelf:(JSObject*)val context:(JSContext*)context
307{
308 _jsSelf = val;
309 OOJSAddGCObjectRoot(context, &_jsSelf, "Player jsSelf");
310
311 [[NSNotificationCenter defaultCenter] addObserver:self
312 selector:@selector(javaScriptEngineWillReset:)
313 name:kOOJavaScriptEngineWillResetNotification
315}
316
317- (void)javaScriptEngineWillReset:(NSNotification*)notification
318{
319 [[NSNotificationCenter defaultCenter] removeObserver:self
320 name:kOOJavaScriptEngineWillResetNotification
322
323 if (_jsSelf != NULL) {
324
325 JSContext* context = OOJSAcquireContext();
326 JS_RemoveObjectRoot(context, &_jsSelf);
327 _jsSelf = NULL;
328 OOJSRelinquishContext(context);
329 }
330}
331
332@end
333
334static JSBool PlayerShipGetProperty(JSContext* context, JSObject* this, jsid propID, jsval* value)
335{
336 if (!JSID_IS_INT(propID))
337 return YES;
338
339 OOJS_NATIVE_ENTER(context)
340
342 *value = JSVAL_VOID;
343 return YES;
344 }
345
346 id result = nil;
348
349 switch (JSID_TO_INT(propID)) {
351 return JS_NewNumberValue(context, [player activeMissile], value);
352
354 return JS_NewNumberValue(context, [player fuelLeakRate], value);
355
357 *value = OOJSValueFromBOOL([player isDocked]);
358 return YES;
359
361 result = [player dockedStation];
362 break;
363
365 result = [player specialCargo];
366 break;
367
369 result = [[[player hud] reticleColorForIndex:OO_RETICLE_COLOR_TARGET] normalizedArray];
370 break;
371
373 result = [[[player hud] reticleColorForIndex:OO_RETICLE_COLOR_TARGET_SENSITIVE] normalizedArray];
374 break;
375
377 result = [[[player hud] reticleColorForIndex:OO_RETICLE_COLOR_WORMHOLE] normalizedArray];
378 break;
379
381 *value = OOJSValueFromBOOL([[player hud] reticleTargetSensitive]);
382 return YES;
383
385 *value = OOJSValueFromGalacticHyperspaceBehaviour(context, [player galacticHyperspaceBehaviour]);
386 return YES;
387
389 return NSPointToVectorJSValue(context, [player galacticHyperspaceFixedCoords], value);
390
392 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([player galacticHyperspaceFixedCoords]), value);
393
395 result = [player fastEquipmentA];
396 break;
397
399 result = [player fastEquipmentB];
400 break;
401
403 result = [player currentPrimedEquipment];
404 break;
405
407 return JS_NewNumberValue(context, [player forwardShieldLevel], value);
408
410 return JS_NewNumberValue(context, [player aftShieldLevel], value);
411
413 return JS_NewNumberValue(context, [player maxForwardShieldLevel], value);
414
416 return JS_NewNumberValue(context, [player maxAftShieldLevel], value);
417
419 // No distinction made internally
420 return JS_NewNumberValue(context, [player forwardShieldRechargeRate], value);
421
423 // No distinction made internally
424 return JS_NewNumberValue(context, [player aftShieldRechargeRate], value);
425
427 return JS_NewNumberValue(context, [[player hud] mfdCount], value);
428
430 result = [player multiFunctionDisplayList];
431 break;
432
434 *value = OOJSValueFromBOOL(![player dialIdentEngaged]);
435 return YES;
436
438 result = OOStringFromLongRangeChartMode([player longRangeChartMode]);
439 break;
440
442 return NSPointToVectorJSValue(context, [player galaxy_coordinates], value);
443
445 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([player galaxy_coordinates]), value);
446
448 return NSPointToVectorJSValue(context, [player cursor_coordinates], value);
449
451 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([player cursor_coordinates]), value);
452
454 *value = INT_TO_JSVAL([player targetSystemID]);
455 return YES;
456
458 *value = INT_TO_JSVAL([player nextHopTargetSystemID]);
459 return YES;
460
462 *value = INT_TO_JSVAL([player infoSystemID]);
463 return YES;
464
466 *value = INT_TO_JSVAL([player previousSystemID]);
467 return YES;
468
470 OORouteType route = [player ANAMode];
471 switch (route) {
473 result = @"OPTIMIZED_BY_TIME";
474 break;
476 result = @"OPTIMIZED_BY_JUMPS";
477 break;
479 result = @"OPTIMIZED_BY_NONE";
480 break;
481 }
482 break;
483 }
484
486 *value = OOJSValueFromBOOL([[player hud] minimalisticScanner]);
487 return YES;
488
490 *value = OOJSValueFromBOOL([[player hud] nonlinearScanner]);
491 return YES;
492
494 *value = OOJSValueFromBOOL([[player hud] scannerUltraZoom]);
495 return YES;
496
498 *value = OOJSValueFromBOOL([player scoopOverride]);
499 return YES;
500
502 *value = OOJSValueFromBOOL([player injectorsEngaged]);
503 return YES;
504
506 *value = OOJSValueFromBOOL([player massLockable]);
507 return YES;
508
510 *value = OOJSValueFromBOOL([player hyperspeedEngaged]);
511 return YES;
512
514 result = [player compassTarget];
515 break;
516
518 result = [OOStringFromCompassMode([player compassMode]) isEqualToString:@"COMPASS_MODE_BASIC"] ? @"OO_COMPASSTYPE_BASIC" : @"OO_COMPASSTYPE_ADVANCED";
519 break;
520
522 *value = OOJSValueFromCompassMode(context, [player compassMode]);
523 return YES;
524
525 case kPlayerShip_hud:
526 result = [[player hud] hudName];
527 break;
528
530 result = [[player hud] crosshairDefinition];
531 break;
532
534 *value = OOJSValueFromBOOL([[player hud] allowBigGui]);
535 return YES;
536
538 *value = OOJSValueFromBOOL([[player hud] isHidden]);
539 return YES;
540
542 *value = OOJSValueFromBOOL([player weaponsOnline]);
543 return YES;
544
546 *value = OOJSValueFromViewID(context, [UNIVERSE viewDirection]);
547 return YES;
548
550 return VectorToJSValue(context, [player viewpointOffsetAft], value);
551
553 return VectorToJSValue(context, [player viewpointOffsetForward], value);
554
556 return VectorToJSValue(context, [player viewpointOffsetPort], value);
557
559 return VectorToJSValue(context, [player viewpointOffsetStarboard], value);
560
562 result = [player weaponTypeForFacing:[player currentWeaponFacing] strict:NO];
563 break;
564
566 return JS_NewNumberValue(context, [UNIVERSE tradeInValueForCommanderDictionary:[player commanderDataDictionary]], value);
567
569 return JS_NewNumberValue(context, [player tradeInFactor], value);
570
572 return JS_NewNumberValue(context, [player renovationCosts], value);
573
575 return JS_NewNumberValue(context, [player renovationFactor], value);
576
577 // make roll, pitch, yaw reported to JS use same +/- convention as
578 // for NPC ships
580 return JS_NewNumberValue(context, -[player flightPitch], value);
581
582 case kPlayerShip_roll:
583 return JS_NewNumberValue(context, -[player flightRoll], value);
584
585 case kPlayerShip_yaw:
586 return JS_NewNumberValue(context, -[player flightYaw], value);
587
589 result = [[[UNIVERSE messageGUI] textColor] normalizedArray];
590 break;
591
593 result = [[[UNIVERSE messageGUI] textCommsColor] normalizedArray];
594 break;
595
596 default:
598 }
599
600 *value = OOJSValueFromNativeObject(context, result);
601 return YES;
602
604}
605
606static JSBool PlayerShipSetProperty(JSContext* context, JSObject* this, jsid propID, JSBool strict, jsval* value)
607{
608 if (!JSID_IS_INT(propID))
609 return YES;
610
611 OOJS_NATIVE_ENTER(context)
612
614 return YES;
615
617 jsdouble fValue;
618 JSBool bValue;
619 int32 iValue;
620 NSString* sValue = nil;
622 Vector vValue;
623 OOColor* colorForScript = nil;
624 Entity* eValue = nil;
625
626 switch (JSID_TO_INT(propID)) {
628 if (JS_ValueToNumber(context, *value, &fValue)) {
629 [player setFuelLeakRate:fValue];
630 return YES;
631 }
632 break;
633
635 if (JS_ValueToBoolean(context, *value, &bValue)) {
636 [player setMassLockable:bValue];
637 return YES;
638 }
639 break;
640
642 if (JS_ValueToBoolean(context, *value, &bValue)) {
643 [[player hud] setReticleTargetSensitive:bValue];
644 return YES;
645 }
646 break;
647
649 sValue = OOStringFromJSValue(context, *value);
650 if (sValue != nil) {
652 if (chartMode > OOLRC_MODE_UNKNOWN) {
653 [player setLongRangeChartMode:chartMode];
654 [player doScriptEvent:OOJSID("chartHighlightModeChanged") withArgument:OOStringFromLongRangeChartMode([player longRangeChartMode])];
655 return YES;
656 } else {
657 OOJSReportError(context, @"Unknown chart hightlight mode specified - must be either OOLRC_MODE_SUNCOLOR, OOLRC_MODE_ECONOMY, OOLRC_MODE_GOVERNMENT or OOLRC_MODE_TECHLEVEL.");
658 }
659 }
660 return NO; // not reachable if successfully set
661 break;
662
664 sValue = OOStringFromJSValue(context, *value);
665 if (sValue != nil) {
667 [player setCompassMode:mode];
668 [player validateCompassTarget];
669 return YES;
670 }
671 break;
672
674 sValue = OOStringFromJSValue(context, *value);
675 if (sValue != nil) {
676 if ([sValue isEqualToString:@"OO_COMPASSTYPE_BASIC"]) {
677 [player setCompassMode:COMPASS_MODE_BASIC];
678 } else if ([sValue isEqualToString:@"OO_COMPASSTYPE_ADVANCED"]) {
679 if (![player hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"]) {
680 OOJSReportWarning(context, @"Advanced Compass type requested and set but player ship does not carry the EQ_ADVANCED_COMPASS equipment or has it damaged.");
681 }
682 [player setCompassMode:COMPASS_MODE_PLANET];
683 } else {
684 OOJSReportError(context, @"Unknown compass type specified - must be either OO_COMPASSTYPE_BASIC or OO_COMPASSTYPE_ADVANCED.");
685 return NO;
686 }
687 return YES;
688 }
689 break;
690
692 // can't change compass target in basic mode
693 if (![player hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"]) {
694 OOJSReportError(context, @"Compass target cannot be set with a basic compass.");
695 return NO;
696 }
697 // make sure we have a valid entity
698 if (!JSVAL_IS_NULL(*value) && JSValueToEntity(context, *value, &eValue)) {
699 Entity* current = [player compassTarget];
700 [player setNextCompassMode];
701 [player validateCompassTarget];
702 // cycle the targets until we either get back to the start (entity not found) or we find the one we're looking for
703 while ([player compassTarget] != current && [player compassTarget] != eValue) {
704 [player setNextCompassMode];
705 [player validateCompassTarget];
706 }
707 return [player compassTarget] != current;
708 } else {
709 OOJSReportError(context, @"Invalid compass target entity provided.");
710 return NO;
711 }
712 break;
713
715 ghBehaviour = OOGalacticHyperspaceBehaviourFromJSValue(context, *value);
716 if (ghBehaviour != GALACTIC_HYPERSPACE_BEHAVIOUR_UNKNOWN) {
717 [player setGalacticHyperspaceBehaviour:ghBehaviour];
718 return YES;
719 }
720 break;
721
723 if (JSValueToVector(context, *value, &vValue)) {
724 NSPoint coords = { vValue.x, vValue.y };
725 [player setGalacticHyperspaceFixedCoords:coords];
726 return YES;
727 }
728 break;
729
731 if (JSValueToVector(context, *value, &vValue)) {
732 NSPoint coords = OOInternalCoordinatesFromGalactic(vValue);
733 [player setGalacticHyperspaceFixedCoords:coords];
734 return YES;
735 }
736 break;
737
739 sValue = OOStringFromJSValue(context, *value);
740 if (sValue != nil) {
741 [player setFastEquipmentA:sValue];
742 return YES;
743 }
744 break;
745
747 sValue = OOStringFromJSValue(context, *value);
748 if (sValue != nil) {
749 [player setFastEquipmentB:sValue];
750 return YES;
751 }
752 break;
753
755 sValue = OOStringFromJSValue(context, *value);
756 if (sValue != nil) {
757 return [player setPrimedEquipment:sValue showMessage:NO];
758 }
759 break;
760
762 if (JS_ValueToNumber(context, *value, &fValue)) {
763 if (!isnan(fValue)) // guard against undefined
764 {
765 [player decrease_flight_pitch:[player flightPitch] + fValue];
766 }
767 return YES;
768 }
769 break;
770
771 case kPlayerShip_roll:
772 if (JS_ValueToNumber(context, *value, &fValue)) {
773 if (!isnan(fValue)) // guard against undefined
774 {
775 [player decrease_flight_roll:[player flightRoll] + fValue];
776 }
777 return YES;
778 }
779 break;
780
781 case kPlayerShip_yaw:
782 if (JS_ValueToNumber(context, *value, &fValue)) {
783 if (!isnan(fValue)) // guard against undefined
784 {
785 [player decrease_flight_yaw:[player flightYaw] + fValue];
786 }
787 return YES;
788 }
789 break;
790
792 if (JS_ValueToNumber(context, *value, &fValue)) {
793 [player setForwardShieldLevel:fValue];
794 return YES;
795 }
796 break;
797
799 if (JS_ValueToNumber(context, *value, &fValue)) {
800 [player setAftShieldLevel:fValue];
801 return YES;
802 }
803 break;
804
806 if (JS_ValueToNumber(context, *value, &fValue)) {
807 [player setMaxForwardShieldLevel:fValue];
808 return YES;
809 }
810 break;
811
813 if (JS_ValueToNumber(context, *value, &fValue)) {
814 [player setMaxAftShieldLevel:fValue];
815 return YES;
816 }
817 break;
818
820 if (JS_ValueToNumber(context, *value, &fValue)) {
821 [player setForwardShieldRechargeRate:fValue];
822 return YES;
823 }
824 break;
825
827 if (JS_ValueToNumber(context, *value, &fValue)) {
828 [player setAftShieldRechargeRate:fValue];
829 return YES;
830 }
831 break;
832
834 if (JS_ValueToBoolean(context, *value, &bValue)) {
835 [[player hud] setMinimalisticScanner:bValue];
836 return YES;
837 }
838 break;
839
841 if (JS_ValueToBoolean(context, *value, &bValue)) {
842 [[player hud] setNonlinearScanner:bValue];
843 return YES;
844 }
845 break;
846
848 if (JS_ValueToBoolean(context, *value, &bValue)) {
849 [[player hud] setScannerUltraZoom:bValue];
850 return YES;
851 }
852 break;
853
855 if (JS_ValueToBoolean(context, *value, &bValue)) {
856 [player setScoopOverride:bValue];
857 return YES;
858 }
859 break;
860
861 case kPlayerShip_hud:
862 sValue = OOStringFromJSValue(context, *value);
863 if (sValue != nil) {
864 [player switchHudTo:sValue]; // EMMSTRAN: logged error should be a JS warning.
865 return YES;
866 } else {
867 [player resetHud];
868 return YES;
869 }
870 break;
871
873 sValue = OOStringFromJSValue(context, *value);
874 if (sValue == nil) {
875 // reset HUD back to its plist settings
876 NSString* hud = [[[player hud] hudName] retain];
877 [player switchHudTo:hud];
878 [hud release];
879 return YES;
880 } else {
881 if (![[player hud] setCrosshairDefinition:sValue]) {
882 OOJSReportWarning(context, @"Crosshair definition file %@ not found or invalid", sValue);
883 }
884 return YES;
885 }
886 break;
887
889 if (JS_ValueToBoolean(context, *value, &bValue)) {
890 [[player hud] setHidden:bValue];
891 return YES;
892 }
893 break;
894
896 if (JS_ValueToNumber(context, *value, &fValue)) {
897 int newLevel = (int)fValue;
898 [player adjustTradeInFactorBy:(newLevel - [player tradeInFactor])];
899 return YES;
900 }
901
903 BOOL exists = NO;
904 sValue = JSValueToEquipmentKeyRelaxed(context, *value, &exists);
905 if (!exists || sValue == nil) {
906 sValue = @"EQ_WEAPON_NONE";
907 }
908 [player setWeaponMount:[player currentWeaponFacing] toWeapon:sValue inContext:@"scripted"];
909 return YES;
910 }
911
913 /* This first check is essential: if removed, it would be
914 * possible to make jumps of arbitrary length - CIM */
915 if ([player status] != STATUS_ENTERING_WITCHSPACE) {
916 /* These checks though similar are less important. The
917 * consequences of allowing jump destination to be set in
918 * flight are not as severe and do not allow the 7LY limit to
919 * be broken. Nevertheless, it is not allowed. - CIM */
920 // (except when compiled in debugging mode)
921#ifndef OO_DUMP_PLANETINFO
922 if (EXPECT_NOT([player status] != STATUS_DOCKED && [player status] != STATUS_LAUNCHING)) {
923 OOJSReportError(context, @"player.ship.targetSystem is read-only unless called when docked.");
924 return NO;
925 }
926#endif
927
928 if (JS_ValueToInt32(context, *value, &iValue)) {
929 if (iValue >= 0 && iValue < OO_SYSTEMS_PER_GALAXY) {
930 [player setTargetSystemID:iValue];
931 return YES;
932 } else {
933 return NO;
934 }
935 }
936 } else {
937 OOJSReportError(context, @"player.ship.targetSystem is read-only unless called when docked.");
938 return NO;
939 }
940
942 if (JS_ValueToInt32(context, *value, &iValue)) {
943 if (iValue >= 0 && iValue < OO_SYSTEMS_PER_GALAXY) {
944 [player setInfoSystemID:iValue moveChart:YES];
945 return YES;
946 } else {
947 return NO;
948 }
949 }
950 break;
951
953 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
954 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
955 [[UNIVERSE messageGUI] setTextColor:colorForScript];
956 return YES;
957 }
958 break;
959
961 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
962 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
963 [[UNIVERSE messageGUI] setTextCommsColor:colorForScript];
964 return YES;
965 }
966 break;
967
969 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
970 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
971 return [[player hud] setReticleColorForIndex:OO_RETICLE_COLOR_TARGET toColor:colorForScript];
972 }
973 break;
974
976 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
977 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
978 return [[player hud] setReticleColorForIndex:OO_RETICLE_COLOR_TARGET_SENSITIVE toColor:colorForScript];
979 }
980 break;
981
983 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
984 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
985 return [[player hud] setReticleColorForIndex:OO_RETICLE_COLOR_WORMHOLE toColor:colorForScript];
986 }
987 break;
988
989 default:
991 return NO;
992 }
993
994 OOJSReportBadPropertyValue(context, this, propID, sPlayerShipProperties, *value);
995 return NO;
996
998}
999
1000// *** Methods ***
1001
1002// launch()
1003static JSBool PlayerShipLaunch(JSContext* context, uintN argc, jsval* vp)
1004{
1005 OOJS_NATIVE_ENTER(context)
1006
1009
1012
1014}
1015
1016// removeAllCargo()
1017static JSBool PlayerShipRemoveAllCargo(JSContext* context, uintN argc, jsval* vp)
1018{
1019 OOJS_NATIVE_ENTER(context)
1020
1023
1025
1026 if ([player isDocked]) {
1027 [player removeAllCargo];
1029 } else {
1030 OOJSReportError(context, @"PlayerShip.removeAllCargo only works when docked.");
1031 return NO;
1032 }
1033
1035}
1036
1037// useSpecialCargo(name : String)
1038static JSBool PlayerShipUseSpecialCargo(JSContext* context, uintN argc, jsval* vp)
1039{
1040 OOJS_NATIVE_ENTER(context)
1041
1044
1046 NSString* name = nil;
1047
1048 if (argc > 0)
1049 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1050 if (EXPECT_NOT(name == nil)) {
1051 OOJSReportBadArguments(context, @"PlayerShip", @"useSpecialCargo", MIN(argc, 1U), OOJS_ARGV, nil, @"string (special cargo description)");
1052 return NO;
1053 }
1054
1055 [player useSpecialCargo:OOStringFromJSValue(context, OOJS_ARGV[0])];
1057
1059}
1060
1061// engageAutopilotToStation(stationForDocking : Station) : Boolean
1062static JSBool PlayerShipEngageAutopilotToStation(JSContext* context, uintN argc, jsval* vp)
1063{
1064 OOJS_NATIVE_ENTER(context)
1065
1068
1070 StationEntity* stationForDocking = nil;
1071
1072 if (argc > 0)
1073 stationForDocking = OOJSNativeObjectOfClassFromJSValue(context, OOJS_ARGV[0], [StationEntity class]);
1074 if (stationForDocking == nil) {
1075 OOJSReportBadArguments(context, @"PlayerShip", @"engageAutopilot", MIN(argc, 1U), OOJS_ARGV, nil, @"station");
1076 return NO;
1077 }
1078
1079 OOJS_RETURN_BOOL([player engageAutopilotToStation:stationForDocking]);
1080
1082}
1083
1084// disengageAutopilot()
1085static JSBool PlayerShipDisengageAutopilot(JSContext* context, uintN argc, jsval* vp)
1086{
1087 OOJS_NATIVE_ENTER(context)
1088
1091
1094
1096}
1097
1098static JSBool PlayerShipRequestDockingClearance(JSContext* context, uintN argc, jsval* vp)
1099{
1100 OOJS_NATIVE_ENTER(context)
1101
1104
1106 StationEntity* stationForDocking = nil;
1107
1108 if (argc > 0)
1109 stationForDocking = OOJSNativeObjectOfClassFromJSValue(context, OOJS_ARGV[0], [StationEntity class]);
1110 if (stationForDocking == nil) {
1111 OOJSReportBadArguments(context, @"PlayerShip", @"requestDockingClearance", MIN(argc, 1U), OOJS_ARGV, nil, @"station");
1112 return NO;
1113 }
1114
1115 [player requestDockingClearance:stationForDocking];
1117
1119}
1120
1121static JSBool PlayerShipCancelDockingRequest(JSContext* context, uintN argc, jsval* vp)
1122{
1123 OOJS_NATIVE_ENTER(context)
1124
1127
1129 StationEntity* stationForDocking = nil;
1130
1131 if (argc > 0)
1132 stationForDocking = OOJSNativeObjectOfClassFromJSValue(context, OOJS_ARGV[0], [StationEntity class]);
1133 if (stationForDocking == nil) {
1134 OOJSReportBadArguments(context, @"PlayerShip", @"cancelDockingRequest", MIN(argc, 1U), OOJS_ARGV, nil, @"station");
1135 return NO;
1136 }
1137
1138 [player cancelDockingRequest:stationForDocking];
1140
1142}
1143
1144// awardEquipmentToCurrentPylon(externalTank: equipmentInfoExpression) : Boolean
1145static JSBool PlayerShipAwardEquipmentToCurrentPylon(JSContext* context, uintN argc, jsval* vp)
1146{
1147 OOJS_NATIVE_ENTER(context)
1148
1151
1153 NSString* key = nil;
1154 OOEquipmentType* eqType = nil;
1155
1156 if (argc > 0)
1157 key = JSValueToEquipmentKey(context, OOJS_ARGV[0]);
1158 if (key != nil)
1160 if (EXPECT_NOT(![eqType isMissileOrMine])) {
1161 OOJSReportBadArguments(context, @"PlayerShip", @"awardEquipmentToCurrentPylon", MIN(argc, 1U), OOJS_ARGV, nil, @"equipment type (external store)");
1162 return NO;
1163 }
1164
1165 OOJS_RETURN_BOOL([player assignToActivePylon:key]);
1166
1168}
1169
1170// addPassenger(name: string, start: int, destination: int, ETA: double, fee: double) : Boolean
1171static JSBool PlayerShipAddPassenger(JSContext* context, uintN argc, jsval* vp)
1172{
1173 OOJS_NATIVE_ENTER(context)
1174
1176 NSString* name = nil;
1177 OOSystemID start = 0, destination = 0;
1178 jsdouble eta = 0.0, fee = 0.0, advance = 0.0;
1179 unsigned risk = 0;
1180
1181 if (argc < 5) {
1182 OOJSReportBadArguments(context, @"PlayerShip", @"addPassenger", argc, OOJS_ARGV, nil, @"name, start, destination, ETA, fee");
1183 return NO;
1184 }
1185
1186 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1187 if (EXPECT_NOT(name == nil)) {
1188 OOJSReportBadArguments(context, @"PlayerShip", @"addPassenger", 1, &OOJS_ARGV[0], nil, @"string");
1189 return NO;
1190 }
1191
1192 if (!ValidateContracts(context, argc, vp, NO, &start, &destination, &eta, &fee, &advance, @"addPassenger", &risk))
1193 return NO; // always go through validate contracts (passenger)
1194
1195 // Ensure there's space.
1196 if ([player passengerCount] >= [player passengerCapacity])
1197 OOJS_RETURN_BOOL(NO);
1198
1199 BOOL OK = [player addPassenger:name start:start destination:destination eta:eta fee:fee advance:advance risk:risk];
1200 OOJS_RETURN_BOOL(OK);
1201
1203}
1204
1205// removePassenger(name :string)
1206static JSBool PlayerShipRemovePassenger(JSContext* context, uintN argc, jsval* vp)
1207{
1208 OOJS_NATIVE_ENTER(context)
1209
1211 NSString* name = nil;
1212 BOOL OK = YES;
1213
1214 if (argc > 0)
1215 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1216 if (EXPECT_NOT(name == nil)) {
1217 OOJSReportBadArguments(context, @"PlayerShip", @"removePassenger", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
1218 return NO;
1219 }
1220
1221 OK = [player passengerCount] > 0 && [name length] > 0;
1222 if (OK)
1223 OK = [player removePassenger:name];
1224
1225 OOJS_RETURN_BOOL(OK);
1226
1228}
1229
1230// addParcel(description: string, start: int, destination: int, ETA: double, fee: double) : Boolean
1231static JSBool PlayerShipAddParcel(JSContext* context, uintN argc, jsval* vp)
1232{
1233 OOJS_NATIVE_ENTER(context)
1234
1236 NSString* name = nil;
1237 OOSystemID start = 0, destination = 0;
1238 jsdouble eta = 0.0, fee = 0.0, premium = 0.0;
1239 unsigned risk = 0;
1240
1241 if (argc < 5) {
1242 OOJSReportBadArguments(context, @"PlayerShip", @"addParcel", argc, OOJS_ARGV, nil, @"name, start, destination, ETA, fee");
1243 return NO;
1244 }
1245
1246 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1247 if (EXPECT_NOT(name == nil)) {
1248 OOJSReportBadArguments(context, @"PlayerShip", @"addParcel", 1, &OOJS_ARGV[0], nil, @"string");
1249 return NO;
1250 }
1251
1252 if (!ValidateContracts(context, argc, vp, NO, &start, &destination, &eta, &fee, &premium, @"addParcel", &risk))
1253 return NO; // always go through validate contracts (passenger/parcel mode)
1254
1255 // Ensure there's space.
1256
1257 BOOL OK = [player addParcel:name start:start destination:destination eta:eta fee:fee premium:premium risk:risk];
1258 OOJS_RETURN_BOOL(OK);
1259
1261}
1262
1263// removeParcel(description :string)
1264static JSBool PlayerShipRemoveParcel(JSContext* context, uintN argc, jsval* vp)
1265{
1266 OOJS_NATIVE_ENTER(context)
1267
1269 NSString* name = nil;
1270 BOOL OK = YES;
1271
1272 if (argc > 0)
1273 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1274 if (EXPECT_NOT(name == nil)) {
1275 OOJSReportBadArguments(context, @"PlayerShip", @"removeParcel", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
1276 return NO;
1277 }
1278
1279 OK = [player parcelCount] > 0 && [name length] > 0;
1280 if (OK)
1281 OK = [player removeParcel:name];
1282
1283 OOJS_RETURN_BOOL(OK);
1284
1286}
1287
1288// awardContract(quantity: int, commodity: string, start: int, destination: int, eta: double, fee: double) : Boolean
1289static JSBool PlayerShipAwardContract(JSContext* context, uintN argc, jsval* vp)
1290{
1291 OOJS_NATIVE_ENTER(context)
1292
1294 NSString* key = nil;
1295 int32 qty = 0;
1296 OOSystemID start = 0, destination = 0;
1297 jsdouble eta = 0.0, fee = 0.0, premium = 0.0;
1298
1299 if (argc < 6) {
1300 OOJSReportBadArguments(context, @"PlayerShip", @"awardContract", argc, OOJS_ARGV, nil, @"quantity, commodity, start, destination, ETA, fee");
1301 return NO;
1302 }
1303
1304 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &qty)) {
1305 OOJSReportBadArguments(context, @"PlayerShip", @"awardContract", 1, &OOJS_ARGV[0], nil, @"positive integer (cargo quantity)");
1306 return NO;
1307 }
1308
1309 key = OOStringFromJSValue(context, OOJS_ARGV[1]);
1310 if (EXPECT_NOT(key == nil)) {
1311 OOJSReportBadArguments(context, @"PlayerShip", @"awardContract", 1, &OOJS_ARGV[1], nil, @"string (commodity identifier)");
1312 return NO;
1313 }
1314
1315 if (!ValidateContracts(context, argc, vp, YES, &start, &destination, &eta, &fee, &premium, @"awardContract", NULL))
1316 return NO; // always go through validate contracts (cargo)
1317
1318 BOOL OK = [player awardContract:qty commodity:key start:start destination:destination eta:eta fee:fee premium:premium];
1319 OOJS_RETURN_BOOL(OK);
1320
1322}
1323
1324// removeContract(commodity: string, destination: int)
1325static JSBool PlayerShipRemoveContract(JSContext* context, uintN argc, jsval* vp)
1326{
1327 OOJS_NATIVE_ENTER(context)
1328
1330 NSString* key = nil;
1331 int32 dest = 0;
1332
1333 if (argc < 2) {
1334 OOJSReportBadArguments(context, @"PlayerShip", @"removeContract", argc, OOJS_ARGV, nil, @"commodity, destination");
1335 return NO;
1336 }
1337
1338 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1339
1340 if (EXPECT_NOT(key == nil)) {
1341 OOJSReportBadArguments(context, @"PlayerShip", @"removeContract", 1, &OOJS_ARGV[0], nil, @"string (commodity identifier)");
1342 return NO;
1343 }
1344
1345 if (!JS_ValueToInt32(context, OOJS_ARGV[1], &dest) || dest < 0 || dest > 255) {
1346 OOJSReportBadArguments(context, @"PlayerShip", @"removeContract", 1, &OOJS_ARGV[1], nil, @"system ID");
1347 return NO;
1348 }
1349
1350 BOOL OK = [player removeContract:key destination:(unsigned)dest];
1351 OOJS_RETURN_BOOL(OK);
1352
1354}
1355
1356// setCustomView(position:vector, orientation:quaternion [, weapon:string])
1357static JSBool PlayerShipSetCustomView(JSContext* context, uintN argc, jsval* vp)
1358{
1359 OOJS_NATIVE_ENTER(context)
1360
1362
1363 if (argc < 2) {
1364 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomView", argc, OOJS_ARGV, nil, @"position, orientiation, [weapon]");
1365 return NO;
1366 }
1367
1368 // must be in custom view
1369 if ([UNIVERSE viewDirection] != VIEW_CUSTOM) {
1370 OOJSReportError(context, @"PlayerShip.setCustomView only works when custom view is active.");
1371 return NO;
1372 }
1373
1374 NSMutableDictionary* viewData = [NSMutableDictionary dictionaryWithCapacity:3];
1375
1376 Vector position = kZeroVector;
1377 BOOL gotpos = JSValueToVector(context, OOJS_ARGV[0], &position);
1378 if (!gotpos) {
1379 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomView", argc, OOJS_ARGV, nil, @"position, orientiation, [weapon]");
1380 return NO;
1381 }
1382 NSString* positionstr = [[NSString alloc] initWithFormat:@"%f %f %f", position.x, position.y, position.z];
1383
1384 Quaternion orientation = kIdentityQuaternion;
1385 BOOL gotquat = JSValueToQuaternion(context, OOJS_ARGV[1], &orientation);
1386 if (!gotquat) {
1387 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomView", argc, OOJS_ARGV, nil, @"position, orientiation, [weapon]");
1388 return NO;
1389 }
1390 NSString* orientationstr = [[NSString alloc] initWithFormat:@"%f %f %f %f", orientation.w, orientation.x, orientation.y, orientation.z];
1391
1392 [viewData setObject:positionstr forKey:@"view_position"];
1393 [viewData setObject:orientationstr forKey:@"view_orientation"];
1394
1395 if (argc > 2) {
1396 NSString* facing = OOStringFromJSValue(context, OOJS_ARGV[2]);
1397 [viewData setObject:facing forKey:@"weapon_facing"];
1398 }
1399
1400 [player setCustomViewDataFromDictionary:viewData withScaling:NO];
1401 [player noteSwitchToView:VIEW_CUSTOM fromView:VIEW_CUSTOM];
1402
1403 [positionstr release];
1404 [orientationstr release];
1405
1406 OOJS_RETURN_BOOL(YES);
1408}
1409
1410// resetCustomView()
1411static JSBool PlayerShipResetCustomView(JSContext* context, uintN argc, jsval* vp)
1412{
1413 OOJS_NATIVE_ENTER(context)
1414
1416
1417 // must be in custom view
1418 if ([UNIVERSE viewDirection] != VIEW_CUSTOM) {
1419 OOJSReportError(context, @"PlayerShip.setCustomView only works when custom view is active.");
1420 return NO;
1421 }
1422
1423 [player resetCustomView];
1424 [player noteSwitchToView:VIEW_CUSTOM fromView:VIEW_CUSTOM];
1425
1426 OOJS_RETURN_BOOL(YES);
1428}
1429
1430// resetScannerZoom()
1431static JSBool PlayerShipResetScannerZoom(JSContext* context, uintN argc, jsval* vp)
1432{
1433 OOJS_NATIVE_ENTER(context)
1434
1436
1437 [player resetScannerZoom];
1438
1441}
1442
1443// takeInternalDamage()
1444static JSBool PlayerShipTakeInternalDamage(JSContext* context, uintN argc, jsval* vp)
1445{
1446 OOJS_NATIVE_ENTER(context)
1447
1449
1450 BOOL took = [player takeInternalDamage];
1451
1452 OOJS_RETURN_BOOL(took);
1454}
1455
1456// beginHyperspaceCountdown([int: spin_time])
1457static JSBool PlayerShipBeginHyperspaceCountdown(JSContext* context, uintN argc, jsval* vp)
1458{
1459 OOJS_NATIVE_ENTER(context)
1460
1462 int32 spin_time;
1463 int32 witchspaceSpinUpTime = 0;
1464 BOOL begun = NO;
1465 if (argc < 1) {
1466 witchspaceSpinUpTime = 0;
1467#ifdef OO_DUMP_PLANETINFO
1468 // quick intersystem jumps for debugging
1469 witchspaceSpinUpTime = 1;
1470#endif
1471 } else {
1472 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &spin_time) || spin_time < 5 || spin_time > 60) {
1473 OOJSReportBadArguments(context, @"PlayerShip", @"beginHyperspaceCountdown", 1, &OOJS_ARGV[0], nil, @"between 5 and 60 seconds");
1474 return NO;
1475 }
1476 if (spin_time < 5) {
1477 witchspaceSpinUpTime = 5;
1478 } else {
1479 witchspaceSpinUpTime = spin_time;
1480 }
1481 }
1482 if ([player hasHyperspaceMotor] && [player status] == STATUS_IN_FLIGHT && [player witchJumpChecklist:false]) {
1483 [player beginWitchspaceCountdown:witchspaceSpinUpTime];
1484 begun = YES;
1485 }
1486 OOJS_RETURN_BOOL(begun);
1488}
1489
1490// cancelHyperspaceCountdown()
1491static JSBool PlayerShipCancelHyperspaceCountdown(JSContext* context, uintN argc, jsval* vp)
1492{
1493 OOJS_NATIVE_ENTER(context)
1494
1496
1497 BOOL cancelled = NO;
1498 if ([player hasHyperspaceMotor] && [player status] == STATUS_WITCHSPACE_COUNTDOWN) {
1500 [player setJumpType:false];
1501 cancelled = YES;
1502 }
1503
1504 OOJS_RETURN_BOOL(cancelled);
1506}
1507
1508static JSBool PlayerShipBeginGalacticHyperspaceCountdown(JSContext* context, uintN argc, jsval* vp)
1509{
1510 OOJS_NATIVE_ENTER(context)
1511
1513 int32 spin_time;
1514 int32 witchspaceSpinUpTime = 5;
1515 BOOL begun = NO;
1516 if (argc == 1) {
1517
1518 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &spin_time) || spin_time < 5 || spin_time > 60) {
1519 OOJSReportBadArguments(context, @"PlayerShip", @"beginGalacticHyperspaceCountdown", 1, &OOJS_ARGV[0], nil, @"between 5 and 60 seconds");
1520 return NO;
1521 }
1522 if (spin_time < 5) {
1523 witchspaceSpinUpTime = 5;
1524 } else {
1525 witchspaceSpinUpTime = spin_time;
1526 }
1527 }
1528 if ([player hasEquipmentItemProviding:@"EQ_GAL_DRIVE"] && [player status] == STATUS_IN_FLIGHT && [player witchJumpChecklist:true]) {
1529 [player setJumpType:YES];
1530 [player setWitchspaceCountdown:witchspaceSpinUpTime];
1531 [player setStatus:STATUS_WITCHSPACE_COUNTDOWN];
1532 [player playGalacticHyperspace];
1533 // say it!
1534 [UNIVERSE addMessage:[NSString stringWithFormat:DESC(@"witch-galactic-in-f-seconds"), witchspaceSpinUpTime] forCount:1.0];
1535 begun = YES;
1536 }
1537 OOJS_RETURN_BOOL(begun);
1539}
1540
1541// setMultiFunctionDisplay(index,key)
1542static JSBool PlayerShipSetMultiFunctionDisplay(JSContext* context, uintN argc, jsval* vp)
1543{
1544 OOJS_NATIVE_ENTER(context)
1545
1546 NSString* key = nil;
1547 uint32 index = 0;
1549 BOOL OK = YES;
1550
1551 if (argc > 0) {
1552 if (!JS_ValueToECMAUint32(context, OOJS_ARGV[0], &index)) {
1553 OOJSReportBadArguments(context, @"PlayerShip", @"setMultiFunctionDisplay", MIN(argc, 1U), OOJS_ARGV, nil, @"number (index) [, string (key)]");
1554 return NO;
1555 }
1556 }
1557
1558 if (argc > 1) {
1559 key = OOStringFromJSValue(context, OOJS_ARGV[1]);
1560 }
1561
1562 OK = [player setMultiFunctionDisplay:index toKey:key];
1563
1564 OOJS_RETURN_BOOL(OK);
1565
1567}
1568
1569// setMultiFunctionText(key,value)
1570static JSBool PlayerShipSetMultiFunctionText(JSContext* context, uintN argc, jsval* vp)
1571{
1572 OOJS_NATIVE_ENTER(context)
1573
1574 NSString* key = nil;
1575 NSString* value = nil;
1577 JSBool reflow = NO;
1578
1579 if (argc > 0) {
1580 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1581 }
1582 if (key == nil) {
1583 OOJSReportBadArguments(context, @"PlayerShip", @"setMultiFunctionText", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key) [, string (text)]");
1584 return NO;
1585 }
1586 if (argc > 1) {
1587 value = OOStringFromJSValue(context, OOJS_ARGV[1]);
1588 }
1589 if (argc > 2 && EXPECT_NOT(!JS_ValueToBoolean(context, OOJS_ARGV[2], &reflow))) {
1590 OOJSReportBadArguments(context, @"setMultiFunctionText", @"reflow", argc, OOJS_ARGV, nil, @"boolean");
1591 return NO;
1592 }
1593
1594 if (!reflow) {
1595 [player setMultiFunctionText:value forKey:key];
1596 } else {
1597 GuiDisplayGen* gui = [UNIVERSE gui];
1598 NSString* formatted = [gui reflowTextForMFD:value];
1599 [player setMultiFunctionText:formatted forKey:key];
1600 }
1601
1603
1605}
1606
1607// setPrimedEquipment(key, [noMessage])
1608static JSBool PlayerShipSetPrimedEquipment(JSContext* context, uintN argc, jsval* vp)
1609{
1610 OOJS_NATIVE_ENTER(context)
1611
1612 NSString* key = nil;
1614 JSBool showMsg = YES;
1615
1616 if (argc > 0) {
1617 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1618 }
1619 if (key == nil) {
1620 OOJSReportBadArguments(context, @"PlayerShip", @"setPrimedEquipment", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key)");
1621 return NO;
1622 }
1623 if (argc > 1 && EXPECT_NOT(!JS_ValueToBoolean(context, OOJS_ARGV[1], &showMsg))) {
1624 OOJSReportBadArguments(context, @"PlayerShip", @"setPrimedEquipment", MIN(argc, 2U), OOJS_ARGV, nil, @"boolean");
1625 return NO;
1626 }
1627
1628 OOJS_RETURN_BOOL([player setPrimedEquipment:key showMessage:showMsg]);
1629
1631}
1632
1633// setCustomHUDDial(key,value)
1634static JSBool PlayerShipSetCustomHUDDial(JSContext* context, uintN argc, jsval* vp)
1635{
1636 OOJS_NATIVE_ENTER(context)
1637
1638 NSString* key = nil;
1639 id value = nil;
1641
1642 if (argc > 0) {
1643 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1644 }
1645 if (key == nil) {
1646 OOJSReportBadArguments(context, @"PlayerShip", @"setCustomHUDDial", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key), value]");
1647 return NO;
1648 }
1649 if (argc > 1) {
1650 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[1]);
1651 } else {
1652 value = @"";
1653 }
1654
1655 [player setDialCustom:value forKey:key];
1656
1658
1660}
1661
1662static JSBool PlayerShipHideHUDSelector(JSContext* context, uintN argc, jsval* vp)
1663{
1664 OOJS_NATIVE_ENTER(context)
1665
1666 NSString* key = nil;
1668
1669 if (argc > 0) {
1670 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1671 }
1672 if (key == nil) {
1673 OOJSReportBadArguments(context, @"PlayerShip", @"hideHUDSelector", MIN(argc, 1U), OOJS_ARGV, nil, @"string (selector)");
1674 return NO;
1675 }
1676 [[player hud] setHiddenSelector:key hidden:YES];
1677
1679
1681}
1682
1683static JSBool PlayerShipShowHUDSelector(JSContext* context, uintN argc, jsval* vp)
1684{
1685 OOJS_NATIVE_ENTER(context)
1686
1687 NSString* key = nil;
1689
1690 if (argc > 0) {
1691 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
1692 }
1693 if (key == nil) {
1694 OOJSReportBadArguments(context, @"PlayerShip", @"hideHUDSelector", MIN(argc, 1U), OOJS_ARGV, nil, @"string (selector)");
1695 return NO;
1696 }
1697 [[player hud] setHiddenSelector:key hidden:NO];
1698
1700
1702}
1703
1704static BOOL ValidateContracts(JSContext* context, uintN argc, jsval* vp, BOOL isCargo, OOSystemID* start, OOSystemID* destination, double* eta, double* fee, double* premium, NSString* functionName, unsigned* risk)
1705{
1707
1708 NSCParameterAssert(context != NULL && vp != NULL && start != NULL && destination != NULL && eta != NULL && fee != NULL);
1709
1710 unsigned uValue, offset = isCargo ? 2 : 1;
1711 jsdouble fValue;
1712 int32 iValue;
1713
1714 if (!JS_ValueToInt32(context, OOJS_ARGV[offset + 0], &iValue) || iValue < 0 || iValue > kOOMaximumSystemID) {
1715 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 0], nil, @"system ID");
1716 return NO;
1717 }
1718 *start = iValue;
1719
1720 if (!JS_ValueToInt32(context, OOJS_ARGV[offset + 1], &iValue) || iValue < 0 || iValue > kOOMaximumSystemID) {
1721 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 1], nil, @"system ID");
1722 return NO;
1723 }
1724 *destination = iValue;
1725
1726 if (!JS_ValueToNumber(context, OOJS_ARGV[offset + 2], &fValue) || !isfinite(fValue) || fValue <= [PLAYER clockTime]) {
1727 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 2], nil, @"number (future time)");
1728 return NO;
1729 }
1730 *eta = fValue;
1731
1732 if (!JS_ValueToNumber(context, OOJS_ARGV[offset + 3], &fValue) || !isfinite(fValue) || fValue < 0.0) {
1733 OOJSReportBadArguments(context, @"PlayerShip", functionName, 1, &OOJS_ARGV[offset + 3], nil, @"number (credits quantity)");
1734 return NO;
1735 }
1736 *fee = fValue;
1737
1738 if (argc > offset + 4 && JS_ValueToNumber(context, OOJS_ARGV[offset + 4], &fValue) && isfinite(fValue) && fValue >= 0.0) {
1739 *premium = fValue;
1740 }
1741
1742 if (!isCargo) {
1743 if (argc > offset + 5 && JS_ValueToECMAUint32(context, OOJS_ARGV[offset + 5], &uValue) && isfinite((double)uValue)) {
1744 *risk = uValue;
1745 }
1746 }
1747
1748 return YES;
1749
1751}
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)
id OOConsumeReference(id OO_NS_CONSUMED value)
#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:63
BOOL JSValueToEntity(JSContext *context, jsval value, Entity **outEntity)
Definition OOJSEntity.m:133
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)
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)
@ 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
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:170
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:175
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
JSObject * JSShipPrototype(void)
Definition OOJSShip.m:587
JSClass * JSShipClass(void)
Definition OOJSShip.m:582
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:341
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:328
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:264
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:91
return nil
const Quaternion kIdentityQuaternion
#define OO_SYSTEMS_PER_GALAXY
OOLongRangeChartMode
Definition OOTypes.h:45
@ kOOMaximumSystemID
Definition OOTypes.h:187
OORouteType
Definition OOTypes.h:31
@ OPTIMIZED_BY_NONE
Definition OOTypes.h:32
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:33
@ OPTIMIZED_BY_TIME
Definition OOTypes.h:34
int16_t OOSystemID
Definition OOTypes.h:183
OOCompassMode
Definition OOTypes.h:129
const Vector kZeroVector
Definition OOVector.m:27
NSPoint OOInternalCoordinatesFromGalactic(Vector galacticCoordinates)
Vector OOGalacticCoordinatesFromInternal(NSPoint internalCoordinates)
OOGalacticHyperspaceBehaviour
#define PLAYER
#define UNIVERSE
Definition Universe.h:827
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:135
NSArray * normalizedArray()
Definition OOColor.m:465
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)
OOLongRangeChartMode longRangeChartMode
NSUInteger passengerCount()
void setGalacticHyperspaceFixedCoords:(NSPoint point)
StationEntity * dockedStation()
NSString * specialCargo
void useSpecialCargo:(NSString *descriptionString)
BOOL switchHudTo:(NSString *hudFileName)
void setJSSelf:context:(JSObject *val,[context] JSContext *context)
void setFastEquipmentA:(NSString *eqKey)
OORouteType ANAMode()
void setFastEquipmentB:(NSString *eqKey)
void beginWitchspaceCountdown:(int spin_time)
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 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)
BOOL takeInternalDamage()
NSUInteger parcelCount()
void setDialCustom:forKey:(id value,[forKey] NSString *key)
NSString * fastEquipmentA()
NSString * currentPrimedEquipment()
NSArray * multiFunctionDisplayList()
void setFuelLeakRate:(float value)
void setJumpType:(BOOL isGalacticJump)
HeadUpDisplay * hud
void setLongRangeChartMode:(OOLongRangeChartMode mode)
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)
void setCompassMode:(OOCompassMode value)
BOOL setPrimedEquipment:showMessage:(NSString *eqKey,[showMessage] BOOL showMsg)
void setScoopOverride:(BOOL newValue)
NSString * fastEquipmentB()
void disengageAutopilot()
void validateCompassTarget()
void setGalacticHyperspaceBehaviour:(OOGalacticHyperspaceBehaviour galacticHyperspaceBehaviour)
BOOL removePassenger:(NSString *Name)
void setWitchspaceCountdown:(int spin_time)
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)
BOOL removeContract:destination:(NSString *commodity,[destination] unsigned destination)
void setCustomViewDataFromDictionary:withScaling:(NSDictionary *viewDict,[withScaling] BOOL withScaling)
void requestDockingClearance:(StationEntity *stationForDocking)
void noteSwitchToView:fromView:(OOViewID toView,[fromView] OOViewID fromView)
void adjustTradeInFactorBy:(int value)
OOCompassMode compassMode
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
void setStatus:(OOEntityStatus stat)
void decrease_flight_yaw:(double delta)
GLfloat flightPitch
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)
void decrease_flight_pitch:(double delta)
GLfloat flightRoll
GLfloat flightYaw
voidpf uLong offset
Definition ioapi.h:132
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
const char int mode
Definition ioapi.h:125
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33