Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJSPlayer.m File Reference
+ Include dependency graph for OOJSPlayer.m:

Go to the source code of this file.

Enumerations

enum  {
  kPlayer_alertAltitude , kPlayer_alertCondition , kPlayer_alertEnergy , kPlayer_alertHostiles ,
  kPlayer_alertMassLocked , kPlayer_alertTemperature , kPlayer_bounty , kPlayer_contractReputation ,
  kPlayer_contractReputationPrecise , kPlayer_credits , kPlayer_dockingClearanceStatus , kPlayer_escapePodRescueTime ,
  kPlayer_legalStatus , kPlayer_name , kPlayer_parcelReputation , kPlayer_parcelReputationPrecise ,
  kPlayer_passengerReputation , kPlayer_passengerReputationPrecise , kPlayer_rank , kPlayer_roleWeights ,
  kPlayer_score , kPlayer_trumbleCount
}
 

Functions

static JSBool PlayerGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool PlayerSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
 
static JSBool PlayerAddMessageToArrivalReport (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerAudioMessage (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerCommsMessage (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerConsoleMessage (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerEndScenario (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerIncreaseContractReputation (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerDecreaseContractReputation (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerIncreasePassengerReputation (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerDecreasePassengerReputation (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerIncreaseParcelReputation (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerDecreaseParcelReputation (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerReplaceShip (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerSetEscapePodDestination (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerSetPlayerRole (JSContext *context, uintN argc, jsval *vp)
 
static JSBool PlayerStopAudioMessage (JSContext *context, uintN argc, jsval *vp)
 
void InitOOJSPlayer (JSContext *context, JSObject *global)
 
JSClass * JSPlayerClass (void)
 
JSObject * JSPlayerPrototype (void)
 
JSObject * JSPlayerObject (void)
 
PlayerEntityOOPlayerForScripting (void)
 

Variables

static JSObject * sPlayerPrototype
 
static JSObject * sPlayerObject
 
static JSClass sPlayerClass
 
static JSPropertySpec sPlayerProperties []
 
static JSFunctionSpec sPlayerMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kPlayer_alertAltitude 
kPlayer_alertCondition 
kPlayer_alertEnergy 
kPlayer_alertHostiles 
kPlayer_alertMassLocked 
kPlayer_alertTemperature 
kPlayer_bounty 
kPlayer_contractReputation 
kPlayer_contractReputationPrecise 
kPlayer_credits 
kPlayer_dockingClearanceStatus 
kPlayer_escapePodRescueTime 
kPlayer_legalStatus 
kPlayer_name 
kPlayer_parcelReputation 
kPlayer_parcelReputationPrecise 
kPlayer_passengerReputation 
kPlayer_passengerReputationPrecise 
kPlayer_rank 
kPlayer_roleWeights 
kPlayer_score 
kPlayer_trumbleCount 

Definition at line 84 of file OOJSPlayer.m.

85{
86 // Property IDs
87 kPlayer_alertAltitude, // low altitude alert flag, boolean, read-only
88 kPlayer_alertCondition, // alert level, integer, read-only
89 kPlayer_alertEnergy, // low energy alert flag, boolean, read-only
90 kPlayer_alertHostiles, // hostiles present alert flag, boolean, read-only
91 kPlayer_alertMassLocked, // mass lock alert flag, boolean, read-only
92 kPlayer_alertTemperature, // cabin temperature alert flag, boolean, read-only
93 kPlayer_bounty, // bounty, unsigned int, read/write
94 kPlayer_contractReputation, // reputation for cargo contracts, integer, read only
95 kPlayer_contractReputationPrecise, // reputation for cargo contracts, float, read only
96 kPlayer_credits, // credit balance, float, read/write
97 kPlayer_dockingClearanceStatus, // docking clearance status, string, read only
98 kPlayer_escapePodRescueTime, // override for the amount of time an escape pod rescue takes, read/write
99 kPlayer_legalStatus, // legalStatus, string, read-only
100 kPlayer_name, // Player name, string, read/write
101 kPlayer_parcelReputation, // reputation for parcel contracts, integer, read-only
102 kPlayer_parcelReputationPrecise, // reputation for parcel contracts, float, read-only
103 kPlayer_passengerReputation, // reputation for passenger contracts, integer, read-only
104 kPlayer_passengerReputationPrecise, // reputation for passenger contracts, float, read-only
105 kPlayer_rank, // rank, string, read-only
106 kPlayer_roleWeights, // role weights, array, read-only
107 kPlayer_score, // kill count, integer, read/write
108 kPlayer_trumbleCount, // number of trumbles, integer, read-only
109};
@ kPlayer_passengerReputationPrecise
Definition OOJSPlayer.m:104
@ kPlayer_parcelReputation
Definition OOJSPlayer.m:101
@ kPlayer_alertMassLocked
Definition OOJSPlayer.m:91
@ kPlayer_alertHostiles
Definition OOJSPlayer.m:90
@ kPlayer_contractReputation
Definition OOJSPlayer.m:94
@ kPlayer_roleWeights
Definition OOJSPlayer.m:106
@ kPlayer_alertEnergy
Definition OOJSPlayer.m:89
@ kPlayer_dockingClearanceStatus
Definition OOJSPlayer.m:97
@ kPlayer_passengerReputation
Definition OOJSPlayer.m:103
@ kPlayer_rank
Definition OOJSPlayer.m:105
@ kPlayer_bounty
Definition OOJSPlayer.m:93
@ kPlayer_name
Definition OOJSPlayer.m:100
@ kPlayer_score
Definition OOJSPlayer.m:107
@ kPlayer_alertAltitude
Definition OOJSPlayer.m:87
@ kPlayer_alertTemperature
Definition OOJSPlayer.m:92
@ kPlayer_escapePodRescueTime
Definition OOJSPlayer.m:98
@ kPlayer_trumbleCount
Definition OOJSPlayer.m:108
@ kPlayer_contractReputationPrecise
Definition OOJSPlayer.m:95
@ kPlayer_parcelReputationPrecise
Definition OOJSPlayer.m:102
@ kPlayer_credits
Definition OOJSPlayer.m:96
@ kPlayer_alertCondition
Definition OOJSPlayer.m:88
@ kPlayer_legalStatus
Definition OOJSPlayer.m:99

Function Documentation

◆ InitOOJSPlayer()

void InitOOJSPlayer ( JSContext * context,
JSObject * global )

Definition at line 163 of file OOJSPlayer.m.

164{
165 sPlayerPrototype = JS_InitClass(context, global, NULL, &sPlayerClass, OOJSUnconstructableConstruct, 0, sPlayerProperties, sPlayerMethods, NULL, NULL);
167
168 // Create player object as a property of the global object.
169 sPlayerObject = JS_DefineObject(context, global, "player", &sPlayerClass, sPlayerPrototype, OOJS_PROP_READONLY);
170}
static JSClass sPlayerClass
Definition OOJSPlayer.m:67
static JSObject * sPlayerPrototype
Definition OOJSPlayer.m:43
static JSObject * sPlayerObject
Definition OOJSPlayer.m:44
static JSPropertySpec sPlayerProperties[]
Definition OOJSPlayer.m:112
static JSFunctionSpec sPlayerMethods[]
Definition OOJSPlayer.m:141
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References OOJS_PROP_READONLY, OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sPlayerClass, sPlayerMethods, sPlayerObject, sPlayerProperties, and sPlayerPrototype.

+ Here is the call graph for this function:

◆ JSPlayerClass()

JSClass * JSPlayerClass ( void )

Definition at line 173 of file OOJSPlayer.m.

174{
175 return &sPlayerClass;
176}

References sPlayerClass.

◆ JSPlayerObject()

JSObject * JSPlayerObject ( void )

Definition at line 185 of file OOJSPlayer.m.

186{
187 return sPlayerObject;
188}

References sPlayerObject.

Referenced by InitOOJSPlayerShip().

+ Here is the caller graph for this function:

◆ JSPlayerPrototype()

JSObject * JSPlayerPrototype ( void )

Definition at line 179 of file OOJSPlayer.m.

180{
181 return sPlayerPrototype;
182}

References sPlayerPrototype.

◆ OOPlayerForScripting()

PlayerEntity * OOPlayerForScripting ( void )

Definition at line 191 of file OOJSPlayer.m.

192{
193 PlayerEntity *player = PLAYER;
194 [player setScriptTarget:player];
195
196 return player;
197}
#define PLAYER
void setScriptTarget:(ShipEntity *ship)

References PLAYER, and PlayerEntity::setScriptTarget:.

Referenced by ClockGetProperty(), EquipmentInfoGetProperty(), GlobalClearExtraGuiScreenKeys(), GlobalGetProperty(), GlobalKeyBindingDescription(), GlobalSetExtraGuiScreenKeys(), JSClockToString(), ManifestGetProperty(), ManifestSetProperty(), MissionAddMessageText(), MissionGetProperty(), MissionMarkSystem(), MissionRunCallback(), MissionRunScreen(), MissionRunShipLibrary(), MissionSetInstructionsInternal(), MissionSetProperty(), MissionUnmarkSystem(), MissionVariablesDeleteProperty(), MissionVariablesGetProperty(), MissionVariablesSetProperty(), PlayerAddMessageToArrivalReport(), PlayerAudioMessage(), PlayerGetProperty(), PlayerReplaceShip(), PlayerSetEscapePodDestination(), PlayerSetPlayerRole(), PlayerSetProperty(), PlayerShipAddParcel(), PlayerShipAddPassenger(), PlayerShipAwardContract(), PlayerShipAwardEquipmentToCurrentPylon(), PlayerShipBeginGalacticHyperspaceCountdown(), PlayerShipBeginHyperspaceCountdown(), PlayerShipCancelDockingRequest(), PlayerShipCancelHyperspaceCountdown(), PlayerShipEngageAutopilotToStation(), PlayerShipGetProperty(), PlayerShipHideHUDSelector(), PlayerShipRemoveAllCargo(), PlayerShipRemoveContract(), PlayerShipRemoveParcel(), PlayerShipRemovePassenger(), PlayerShipRequestDockingClearance(), PlayerShipResetCustomView(), PlayerShipResetScannerZoom(), PlayerShipSetCustomHUDDial(), PlayerShipSetCustomView(), PlayerShipSetMultiFunctionDisplay(), PlayerShipSetMultiFunctionText(), PlayerShipSetPrimedEquipment(), PlayerShipSetProperty(), PlayerShipShowHUDSelector(), PlayerShipTakeInternalDamage(), PlayerShipUseSpecialCargo(), ShipRunLegacyScriptActions(), StationDockPlayer(), SystemAddMoon(), SystemAddPlanet(), SystemGetProperty(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), SystemLegacyAddShipsWithinRadius(), SystemLegacySpawnShip(), SystemSendAllShipsAway(), SystemSetProperty(), SystemToString(), and WorldScriptsGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PlayerAddMessageToArrivalReport()

static JSBool PlayerAddMessageToArrivalReport ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 517 of file OOJSPlayer.m.

518{
519 OOJS_NATIVE_ENTER(context)
520
521 NSString *report = nil;
523
524 if (argc > 0) report = OOStringFromJSValue(context, OOJS_ARGV[0]);
525 if (report == nil)
526 {
527 OOJSReportBadArguments(context, @"Player", @"addMessageToArrivalReport", MIN(argc, 1U), OOJS_ARGV, nil, @"string (arrival message)");
528 return NO;
529 }
530
531 [player addMessageToReport:report];
533
535}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_RETURN_VOID
#define MIN(A, B)
Definition OOMaths.h:111
return nil
void addMessageToReport:(NSString *report)

References PlayerEntity::addMessageToReport:, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSReportBadArguments(), OOPlayerForScripting(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ PlayerAudioMessage()

static JSBool PlayerAudioMessage ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 538 of file OOJSPlayer.m.

539{
540 OOJS_NATIVE_ENTER(context)
541
542 NSString *audioMessage = nil;
544
545 if (argc > 0) audioMessage = OOStringFromJSValue(context, OOJS_ARGV[0]);
546 if (audioMessage == nil)
547 {
548 OOJSReportBadArguments(context, @"Player", @"audioMessage", argc, OOJS_ARGV, nil, @"audiomessage (string)");
549 return NO;
550 }
551
552 if ([player isSpeechOn] >= OOSPEECHSETTINGS_COMMS) [UNIVERSE startSpeakingString:audioMessage];
554
556}
@ OOSPEECHSETTINGS_COMMS

References nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSReportBadArguments(), OOPlayerForScripting(), OOSPEECHSETTINGS_COMMS, and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ PlayerCommsMessage()

static JSBool PlayerCommsMessage ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 377 of file OOJSPlayer.m.

378{
379 OOJS_NATIVE_ENTER(context)
380
381 NSString *message = nil;
382 double time = 4.5;
383 BOOL gotTime = YES;
384
385 if (argc > 0) message = OOStringFromJSValue(context, OOJS_ARGV[0]);
386 if (argc > 1) gotTime = JS_ValueToNumber(context, OOJS_ARGV[1], &time);
387 if (message == nil || !gotTime)
388 {
389 OOJSReportBadArguments(context, @"Player", @"commsMessage", argc, OOJS_ARGV, nil, @"message and optional duration");
390 return NO;
391 }
392
393 [UNIVERSE addCommsMessage:message forCount:time];
394 [PLAYER doScriptEvent:OOJSID("commsMessageReceived") withArgument:message andArgument:nil];
396
398}

References nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSReportBadArguments(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ PlayerConsoleMessage()

static JSBool PlayerConsoleMessage ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 402 of file OOJSPlayer.m.

403{
404 OOJS_NATIVE_ENTER(context)
405
406 NSString *message = nil;
407 double time = 3.0;
408 BOOL gotTime = YES;
409
410 if (argc > 0) message = OOStringFromJSValue(context, OOJS_ARGV[0]);
411 if (argc > 1) gotTime = JS_ValueToNumber(context, OOJS_ARGV[1], &time);
412 if (message == nil || !gotTime)
413 {
414 OOJSReportBadArguments(context, @"Player", @"consoleMessage", argc, OOJS_ARGV, nil, @"message and optional duration");
415 return NO;
416 }
417
418 [UNIVERSE addMessage:message forCount:time];
420
422}

References nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSReportBadArguments(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ PlayerDecreaseContractReputation()

static JSBool PlayerDecreaseContractReputation ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 458 of file OOJSPlayer.m.

459{
460 OOJS_NATIVE_ENTER(context)
461
462 [OOPlayerForScripting() decreaseContractReputation:1];
464
466}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

◆ PlayerDecreaseParcelReputation()

static JSBool PlayerDecreaseParcelReputation ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 482 of file OOJSPlayer.m.

483{
484 OOJS_NATIVE_ENTER(context)
485
486 [OOPlayerForScripting() decreaseParcelReputation:1];
488
490}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

◆ PlayerDecreasePassengerReputation()

static JSBool PlayerDecreasePassengerReputation ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 506 of file OOJSPlayer.m.

507{
508 OOJS_NATIVE_ENTER(context)
509
510 [OOPlayerForScripting() decreasePassengerReputation:1];
512
514}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

◆ PlayerEndScenario()

static JSBool PlayerEndScenario ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 426 of file OOJSPlayer.m.

427{
428 OOJS_NATIVE_ENTER(context)
429
430 NSString *scenario = nil;
431
432 if (argc > 0) scenario = OOStringFromJSValue(context, OOJS_ARGV[0]);
433 if (scenario == nil)
434 {
435 OOJSReportBadArguments(context, @"Player", @"endScenario", argc, OOJS_ARGV, nil, @"scenario key");
436 return NO;
437 }
438
439 OOJS_RETURN_BOOL([PLAYER endScenario:scenario]);
440
442}
#define OOJS_RETURN_BOOL(v)

References nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOStringFromJSValue(), and PLAYER.

+ Here is the call graph for this function:

◆ PlayerGetProperty()

static JSBool PlayerGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 200 of file OOJSPlayer.m.

201{
202 if (!JSID_IS_INT(propID)) return YES;
203
204 OOJS_NATIVE_ENTER(context)
205
206 id result = nil;
208
209 switch (JSID_TO_INT(propID))
210 {
211 case kPlayer_name:
212 result = [player commanderName];
213 break;
214
215 case kPlayer_score:
216 *value = INT_TO_JSVAL([player score]);
217 return YES;
218
219 case kPlayer_credits:
220 return JS_NewNumberValue(context, [player creditBalance], value);
221
222 case kPlayer_rank:
223 *value = OOJSValueFromNativeObject(context, OODisplayRatingStringFromKillCount([player score]));
224 return YES;
225
227 *value = OOJSValueFromNativeObject(context, OODisplayStringFromLegalStatus([player legalStatus]));
228 return YES;
229
231 *value = INT_TO_JSVAL([player alertCondition]);
232 return YES;
233
235 *value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_TEMP);
236 return YES;
237
239 *value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_MASS_LOCK);
240 return YES;
241
243 *value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_ALT);
244 return YES;
245
247 *value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_ENERGY);
248 return YES;
249
251 *value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_HOSTILES);
252 return YES;
253
255 return JS_NewNumberValue(context, [player escapePodRescueTime], value);
256
258 return JS_NewNumberValue(context, [player trumbleCount], value);
259
260 /* For compatibility with previous versions, these are still on
261 * a -7 to +7 scale */
263 return JS_NewNumberValue(context, (int)(((float)[player contractReputation])/10.0), value);
264
266 return JS_NewNumberValue(context, (int)(((float)[player passengerReputation])/10.0), value);
267
269 return JS_NewNumberValue(context, (int)(((float)[player parcelReputation])/10.0), value);
270
271 /* Full-precision reputations */
273 return JS_NewNumberValue(context, ((float)[player contractReputation])/10.0, value);
274
276 return JS_NewNumberValue(context, ((float)[player passengerReputation])/10.0, value);
277
279 return JS_NewNumberValue(context, ((float)[player parcelReputation])/10.0, value);
280
282 // EMMSTRAN: OOConstToJSString-ify this.
283 *value = OOJSValueFromNativeObject(context, DockingClearanceStatusToString([player getDockingClearanceStatus]));
284 return YES;
285
286 case kPlayer_bounty:
287 *value = INT_TO_JSVAL([player legalStatus]);
288 return YES;
289
291 result = [player roleWeights];
292 break;
293
294 default:
295 OOJSReportBadPropertySelector(context, this, propID, sPlayerProperties);
296 return NO;
297 }
298
299 *value = OOJSValueFromNativeObject(context, result);
300 return YES;
301
303}
NSString * DockingClearanceStatusToString(OODockingClearanceStatus dockingClearanceStatus) PURE_FUNC
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
NSString * OODisplayRatingStringFromKillCount(unsigned kills)
@ ALERT_FLAG_TEMP
@ ALERT_FLAG_ENERGY
@ ALERT_FLAG_HOSTILES
@ ALERT_FLAG_MASS_LOCK
@ ALERT_FLAG_ALT
NSString * OODisplayStringFromLegalStatus(int legalStatus)
NSString * commanderName()
NSMutableArray * roleWeights

References ALERT_FLAG_ALT, ALERT_FLAG_ENERGY, ALERT_FLAG_HOSTILES, ALERT_FLAG_MASS_LOCK, ALERT_FLAG_TEMP, PlayerEntity::commanderName, DockingClearanceStatusToString(), kPlayer_alertAltitude, kPlayer_alertCondition, kPlayer_alertEnergy, kPlayer_alertHostiles, kPlayer_alertMassLocked, kPlayer_alertTemperature, kPlayer_bounty, kPlayer_contractReputation, kPlayer_contractReputationPrecise, kPlayer_credits, kPlayer_dockingClearanceStatus, kPlayer_escapePodRescueTime, kPlayer_legalStatus, kPlayer_name, kPlayer_parcelReputation, kPlayer_parcelReputationPrecise, kPlayer_passengerReputation, kPlayer_passengerReputationPrecise, kPlayer_rank, kPlayer_roleWeights, kPlayer_score, kPlayer_trumbleCount, nil, OODisplayRatingStringFromKillCount(), OODisplayStringFromLegalStatus(), OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), OOPlayerForScripting(), PlayerEntity::roleWeights, and sPlayerProperties.

+ Here is the call graph for this function:

◆ PlayerIncreaseContractReputation()

static JSBool PlayerIncreaseContractReputation ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 446 of file OOJSPlayer.m.

447{
448 OOJS_NATIVE_ENTER(context)
449
450 [OOPlayerForScripting() increaseContractReputation:1];
452
454}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

◆ PlayerIncreaseParcelReputation()

static JSBool PlayerIncreaseParcelReputation ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 470 of file OOJSPlayer.m.

471{
472 OOJS_NATIVE_ENTER(context)
473
474 [OOPlayerForScripting() increaseParcelReputation:1];
476
478}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

◆ PlayerIncreasePassengerReputation()

static JSBool PlayerIncreasePassengerReputation ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 494 of file OOJSPlayer.m.

495{
496 OOJS_NATIVE_ENTER(context)
497
498 [OOPlayerForScripting() increasePassengerReputation:1];
500
502}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

◆ PlayerReplaceShip()

static JSBool PlayerReplaceShip ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 560 of file OOJSPlayer.m.

561{
562 OOJS_NATIVE_ENTER(context)
563
564 NSString *shipKey = nil;
566 BOOL success = NO;
567 int personality = 0;
568
569 if (argc > 0) shipKey = OOStringFromJSValue(context, OOJS_ARGV[0]);
570 if (shipKey == nil)
571 {
572 OOJSReportBadArguments(context, @"Player", @"replaceShip", MIN(argc, 1U), OOJS_ARGV, nil, @"string (shipyard key)");
573 return NO;
574 }
575
576 if (EXPECT_NOT(!([player status] == STATUS_DOCKED)))
577 {
578 OOJSReportError(context, @"Player.replaceShip() only works while the player is docked.");
579 return NO;
580 }
581
582 success = [player replaceShipWithNamedShip:shipKey];
583 if (argc > 1)
584 {
585 JS_ValueToInt32(context,OOJS_ARGV[1],&personality);
586 if (personality >= 0 && (uint16_t)personality < ENTITY_PERSONALITY_MAX)
587 {
588 [player setEntityPersonalityInt:(uint16_t)personality];
589 }
590 }
591
592 if (success)
593 {
594 [player doScriptEvent:OOJSID("playerReplacedShip") withArgument:player];
595 // slightly misnamed world event now - to be deprecated
596 [player doScriptEvent:OOJSID("playerBoughtNewShip") withArgument:player andArgument:[NSNumber numberWithInt:0]];
597 }
598
599 OOJS_RETURN_BOOL(success);
600
602}
#define EXPECT_NOT(x)
void OOJSReportError(JSContext *context, NSString *format,...)
#define ENTITY_PERSONALITY_MAX
Definition ShipEntity.h:110
BOOL replaceShipWithNamedShip:(NSString *shipName)
void setEntityPersonalityInt:(uint16_t value)
void doScriptEvent:withArgument:(jsid message,[withArgument] id argument)
void doScriptEvent:withArgument:andArgument:(jsid message,[withArgument] id argument1,[andArgument] id argument2)

References ShipEntity::doScriptEvent:withArgument:, ShipEntity::doScriptEvent:withArgument:andArgument:, ENTITY_PERSONALITY_MAX, EXPECT_NOT, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOJSReportError(), OOPlayerForScripting(), OOStringFromJSValue(), PlayerEntity::replaceShipWithNamedShip:, and ShipEntity::setEntityPersonalityInt:.

+ Here is the call graph for this function:

◆ PlayerSetEscapePodDestination()

static JSBool PlayerSetEscapePodDestination ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 606 of file OOJSPlayer.m.

607{
608 OOJS_NATIVE_ENTER(context)
609
611 {
612 OOJSReportError(context, @"Player.setEscapePodDestination() only works while the escape pod is in flight.");
613 return NO;
614 }
615
616 BOOL OK = NO;
617 id destValue = nil;
619
620 if (argc == 1)
621 {
622 destValue = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[0]);
623
624 if (destValue == nil)
625 {
626 [player setDockTarget:NULL];
627 OK = YES;
628 }
629 else if ([destValue isKindOfClass:[ShipEntity class]] && [destValue isStation])
630 {
631 [player setDockTarget:destValue];
632 OK = YES;
633 }
634 else if ([destValue isKindOfClass:[NSString class]])
635 {
636 if ([destValue isEqualToString:@"NEARBY_SYSTEM"])
637 {
638 // find the nearest system with a main station, or die in the attempt!
639 [player setDockTarget:NULL];
640
641 double rescueRange = MAX_JUMP_RANGE; // reach at least 1 other system!
642 if ([UNIVERSE inInterstellarSpace])
643 {
644 // Set 3.5 ly as the limit, enough to reach at least 2 systems!
645 rescueRange = MAX_JUMP_RANGE / 2.0;
646 }
647 NSMutableArray *sDests = [UNIVERSE nearbyDestinationsWithinRange:rescueRange];
648 NSUInteger i = 0, nDests = [sDests count];
649
650 if (nDests > 0) for (i = --nDests; i > 0; i--)
651 {
652 if ([[sDests oo_dictionaryAtIndex:i] oo_boolForKey:@"nova"])
653 {
654 [sDests removeObjectAtIndex:i];
655 }
656 }
657
658 // i is back to 0, nDests could have changed...
659 nDests = [sDests count];
660 if (nDests > 0) // we have a system with a main station!
661 {
662 if (nDests > 1) i = ranrot_rand() % nDests; // any nearby system will do.
663 NSDictionary *dest = [sDests objectAtIndex:i];
664
665 // add more time until rescue, with overheads for entering witchspace in case of overlapping systems.
666 double dist = [dest oo_doubleForKey:@"distance"];
667 [player addToAdjustTime:(.2 + dist * dist) * 3600.0 + 5400.0 * (ranrot_rand() & 127)];
668
669 // at the end of the docking sequence we'll check if the target system is the same as the system we're in...
670 [player setTargetSystemID:i];
671 }
672 OK = YES;
673 }
674 }
675 else
676 {
677 JSBool bValue;
678 if (JS_ValueToBoolean(context, OOJS_ARGV[0], &bValue) && bValue == NO)
679 {
680 [player setDockTarget:NULL];
681 OK = YES;
682 }
683 }
684 }
685
686 if (OK == NO)
687 {
688 OOJSReportBadArguments(context, @"Player", @"setEscapePodDestination", argc, OOJS_ARGV, nil, @"a valid station, null, or 'NEARBY_SYSTEM'");
689 }
690 return OK;
691
693}
OOINLINE BOOL OOIsPlayerStale(void)
Definition OOJSEntity.h:65
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
#define MAX_JUMP_RANGE
Definition ShipEntity.h:107
#define UNIVERSE
Definition Universe.h:833
void addToAdjustTime:(double seconds)
void setDockTarget:(ShipEntity *entity)
void setTargetSystemID:(OOSystemID sid)
#define ranrot_rand()

References PlayerEntity::addToAdjustTime:, EXPECT_NOT, MAX_JUMP_RANGE, nil, OOIsPlayerStale(), OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOJSReportError(), OOPlayerForScripting(), ranrot_rand, PlayerEntity::setDockTarget:, PlayerEntity::setTargetSystemID:, and UNIVERSE.

+ Here is the call graph for this function:

◆ PlayerSetPlayerRole()

static JSBool PlayerSetPlayerRole ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 697 of file OOJSPlayer.m.

698{
699 OOJS_NATIVE_ENTER(context)
700
701 NSString *role = nil;
703 uint32 index = 0;
704
705 if (argc > 0) role = OOStringFromJSValue(context, OOJS_ARGV[0]);
706 if (role == nil)
707 {
708 OOJSReportBadArguments(context, @"Player", @"setPlayerRole", MIN(argc, 1U), OOJS_ARGV, nil, @"string (role) [, number (index)]");
709 return NO;
710 }
711
712 if (argc > 1)
713 {
714 if (JS_ValueToECMAUint32(context,OOJS_ARGV[1],&index))
715 {
716 [player addRoleToPlayer:role inSlot:index];
717 return YES;
718 }
719 }
720 [player addRoleToPlayer:role];
721 return YES;
722
724}
void addRoleToPlayer:(NSString *role)
void addRoleToPlayer:inSlot:(NSString *role,[inSlot] NSUInteger slot)

References PlayerEntity::addRoleToPlayer:, PlayerEntity::addRoleToPlayer:inSlot:, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadArguments(), OOPlayerForScripting(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ PlayerSetProperty()

static JSBool PlayerSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 306 of file OOJSPlayer.m.

307{
308 if (!JSID_IS_INT(propID)) return YES;
309
310 OOJS_NATIVE_ENTER(context)
311
313 jsdouble fValue;
314 int32 iValue;
315 NSString *sValue;
316
317 switch (JSID_TO_INT(propID))
318 {
319 case kPlayer_name:
320 sValue = OOStringFromJSValue(context,*value);
321 if (sValue != nil)
322 {
323 [player setCommanderName:sValue];
324 return YES;
325 }
326 break;
327
328 case kPlayer_score:
329 if (JS_ValueToInt32(context, *value, &iValue))
330 {
331 iValue = MAX(iValue, 0);
332 [player setScore:iValue];
333 return YES;
334 }
335 break;
336
337 case kPlayer_credits:
338 if (JS_ValueToNumber(context, *value, &fValue))
339 {
340 [player setCreditBalance:fValue];
341 return YES;
342 }
343 break;
344
345 case kPlayer_bounty:
346 if (JS_ValueToInt32(context, *value, &iValue))
347 {
348 if (iValue < 0) iValue = 0;
349 [player setBounty:iValue withReason:kOOLegalStatusReasonByScript];
350 return YES;
351 }
352 break;
353
355 if (JS_ValueToNumber(context, *value, &fValue))
356 {
357 [player setEscapePodRescueTime:fValue];
358 return YES;
359 }
360 break;
361
362 default:
363 OOJSReportBadPropertySelector(context, this, propID, sPlayerProperties);
364 return NO;
365 }
366
367 OOJSReportBadPropertyValue(context, this, propID, sPlayerProperties, *value);
368 return NO;
369
371}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
#define MAX(A, B)
Definition OOMaths.h:114
void setBounty:withReason:(OOCreditsQuantity amount, [withReason] OOLegalStatusReason reason)
void setScore:(unsigned value)
void setCreditBalance:(double value)
void setEscapePodRescueTime:(double seconds)
void setCommanderName:(NSString *value)

References kPlayer_bounty, kPlayer_credits, kPlayer_escapePodRescueTime, kPlayer_name, kPlayer_score, MAX, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOPlayerForScripting(), OOStringFromJSValue(), PlayerEntity::setBounty:withReason:, PlayerEntity::setCommanderName:, PlayerEntity::setCreditBalance:, PlayerEntity::setEscapePodRescueTime:, PlayerEntity::setScore:, and sPlayerProperties.

+ Here is the call graph for this function:

◆ PlayerStopAudioMessage()

static JSBool PlayerStopAudioMessage ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 727 of file OOJSPlayer.m.

728{
729 OOJS_NATIVE_ENTER(context)
730 if ([UNIVERSE isSpeaking]) [UNIVERSE stopSpeaking];
732
734}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, and UNIVERSE.

Variable Documentation

◆ sPlayerClass

JSClass sPlayerClass
static
Initial value:
=
{
"Player",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSPlayer.m:306
static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSPlayer.m:200
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 67 of file OOJSPlayer.m.

68{
69 "Player",
70 JSCLASS_HAS_PRIVATE,
71
72 JS_PropertyStub, // addProperty
73 JS_PropertyStub, // delProperty
74 PlayerGetProperty, // getProperty
75 PlayerSetProperty, // setProperty
76 JS_EnumerateStub, // enumerate
77 JS_ResolveStub, // resolve
78 JS_ConvertStub, // convert
80 JSCLASS_NO_OPTIONAL_MEMBERS
81};

Referenced by InitOOJSPlayer(), and JSPlayerClass().

◆ sPlayerMethods

JSFunctionSpec sPlayerMethods[]
static
Initial value:
=
{
{ "addMessageToArrivalReport", PlayerAddMessageToArrivalReport, 1 },
{ "audioMessage", PlayerAudioMessage, 1 },
{ "commsMessage", PlayerCommsMessage, 1 },
{ "consoleMessage", PlayerConsoleMessage, 1 },
{ "decreaseContractReputation", PlayerDecreaseContractReputation, 0 },
{ "decreaseParcelReputation", PlayerDecreaseParcelReputation, 0 },
{ "decreasePassengerReputation", PlayerDecreasePassengerReputation, 0 },
{ "endScenario", PlayerEndScenario, 1 },
{ "increaseContractReputation", PlayerIncreaseContractReputation, 0 },
{ "increaseParcelReputation", PlayerIncreaseParcelReputation, 0 },
{ "increasePassengerReputation", PlayerIncreasePassengerReputation, 0 },
{ "replaceShip", PlayerReplaceShip, 1 },
{ "setEscapePodDestination", PlayerSetEscapePodDestination, 1 },
{ "setPlayerRole", PlayerSetPlayerRole, 1 },
{ "stopAudioMessage", PlayerStopAudioMessage, 0 },
{ 0 }
}
static JSBool PlayerSetEscapePodDestination(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:606
static JSBool PlayerIncreasePassengerReputation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:494
static JSBool PlayerIncreaseParcelReputation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:470
static JSBool PlayerDecreaseParcelReputation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:482
static JSBool PlayerEndScenario(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:426
static JSBool PlayerStopAudioMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:727
static JSBool PlayerIncreaseContractReputation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:446
static JSBool PlayerDecreasePassengerReputation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:506
static JSBool PlayerReplaceShip(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:560
static JSBool PlayerAudioMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:538
static JSBool PlayerCommsMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:377
static JSBool PlayerAddMessageToArrivalReport(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:517
static JSBool PlayerDecreaseContractReputation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:458
static JSBool PlayerSetPlayerRole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:697
static JSBool PlayerConsoleMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSPlayer.m:402

Definition at line 141 of file OOJSPlayer.m.

142{
143 // JS name Function min args
144 { "addMessageToArrivalReport", PlayerAddMessageToArrivalReport, 1 },
145 { "audioMessage", PlayerAudioMessage, 1 },
146 { "commsMessage", PlayerCommsMessage, 1 },
147 { "consoleMessage", PlayerConsoleMessage, 1 },
148 { "decreaseContractReputation", PlayerDecreaseContractReputation, 0 },
149 { "decreaseParcelReputation", PlayerDecreaseParcelReputation, 0 },
150 { "decreasePassengerReputation", PlayerDecreasePassengerReputation, 0 },
151 { "endScenario", PlayerEndScenario, 1 },
152 { "increaseContractReputation", PlayerIncreaseContractReputation, 0 },
153 { "increaseParcelReputation", PlayerIncreaseParcelReputation, 0 },
154 { "increasePassengerReputation", PlayerIncreasePassengerReputation, 0 },
155 { "replaceShip", PlayerReplaceShip, 1 },
156 { "setEscapePodDestination", PlayerSetEscapePodDestination, 1 }, // null destination must be set explicitly
157 { "setPlayerRole", PlayerSetPlayerRole, 1 },
158 { "stopAudioMessage", PlayerStopAudioMessage, 0 },
159 { 0 }
160};

Referenced by InitOOJSPlayer().

◆ sPlayerObject

JSObject* sPlayerObject
static

Definition at line 44 of file OOJSPlayer.m.

Referenced by InitOOJSPlayer(), and JSPlayerObject().

◆ sPlayerProperties

JSPropertySpec sPlayerProperties[]
static
Initial value:
=
{
{ "contractReputationPrecise", kPlayer_contractReputationPrecise, OOJS_PROP_READONLY_CB },
{ "dockingClearanceStatus", kPlayer_dockingClearanceStatus, OOJS_PROP_READONLY_CB },
{ "parcelReputationPrecise", kPlayer_parcelReputationPrecise, OOJS_PROP_READONLY_CB },
{ "passengerReputationPrecise", kPlayer_passengerReputationPrecise, OOJS_PROP_READONLY_CB },
{ 0 }
}
#define OOJS_PROP_READWRITE_CB
#define OOJS_PROP_READONLY_CB

Definition at line 112 of file OOJSPlayer.m.

113{
114 // JS name ID flags
115 { "alertAltitude", kPlayer_alertAltitude, OOJS_PROP_READONLY_CB },
116 { "alertCondition", kPlayer_alertCondition, OOJS_PROP_READONLY_CB },
117 { "alertEnergy", kPlayer_alertEnergy, OOJS_PROP_READONLY_CB },
118 { "alertHostiles", kPlayer_alertHostiles, OOJS_PROP_READONLY_CB },
119 { "alertMassLocked", kPlayer_alertMassLocked, OOJS_PROP_READONLY_CB },
120 { "alertTemperature", kPlayer_alertTemperature, OOJS_PROP_READONLY_CB },
122 { "contractReputation", kPlayer_contractReputation, OOJS_PROP_READONLY_CB },
123 { "contractReputationPrecise", kPlayer_contractReputationPrecise, OOJS_PROP_READONLY_CB },
125 { "dockingClearanceStatus", kPlayer_dockingClearanceStatus, OOJS_PROP_READONLY_CB },
126 { "escapePodRescueTime", kPlayer_escapePodRescueTime, OOJS_PROP_READWRITE_CB },
127 { "legalStatus", kPlayer_legalStatus, OOJS_PROP_READONLY_CB },
129 { "parcelReputation", kPlayer_parcelReputation, OOJS_PROP_READONLY_CB },
130 { "parcelReputationPrecise", kPlayer_parcelReputationPrecise, OOJS_PROP_READONLY_CB },
131 { "passengerReputation", kPlayer_passengerReputation, OOJS_PROP_READONLY_CB },
132 { "passengerReputationPrecise", kPlayer_passengerReputationPrecise, OOJS_PROP_READONLY_CB },
134 { "roleWeights", kPlayer_roleWeights, OOJS_PROP_READONLY_CB },
136 { "trumbleCount", kPlayer_trumbleCount, OOJS_PROP_READONLY_CB },
137 { 0 }
138};

Referenced by InitOOJSPlayer(), PlayerGetProperty(), and PlayerSetProperty().

◆ sPlayerPrototype

JSObject* sPlayerPrototype
static

Definition at line 43 of file OOJSPlayer.m.

Referenced by InitOOJSPlayer(), and JSPlayerPrototype().