47static JSBool
PlayerGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
48static JSBool
PlayerSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
80 JSCLASS_NO_OPTIONAL_MEMBERS
202 if (!JSID_IS_INT(propID))
return YES;
209 switch (JSID_TO_INT(propID))
216 *value = INT_TO_JSVAL([player score]);
220 return JS_NewNumberValue(context, [player creditBalance], value);
231 *value = INT_TO_JSVAL([player alertCondition]);
255 return JS_NewNumberValue(context, [player escapePodRescueTime], value);
258 return JS_NewNumberValue(context, [player trumbleCount], value);
263 return JS_NewNumberValue(context, (
int)(((
float)[player contractReputation])/10.0), value);
266 return JS_NewNumberValue(context, (
int)(((
float)[player passengerReputation])/10.0), value);
269 return JS_NewNumberValue(context, (
int)(((
float)[player parcelReputation])/10.0), value);
273 return JS_NewNumberValue(context, ((
float)[player contractReputation])/10.0, value);
276 return JS_NewNumberValue(context, ((
float)[player passengerReputation])/10.0, value);
279 return JS_NewNumberValue(context, ((
float)[player parcelReputation])/10.0, value);
287 *value = INT_TO_JSVAL([player legalStatus]);
306static JSBool
PlayerSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
308 if (!JSID_IS_INT(propID))
return YES;
317 switch (JSID_TO_INT(propID))
329 if (JS_ValueToInt32(context, *value, &iValue))
331 iValue =
MAX(iValue, 0);
338 if (JS_ValueToNumber(context, *value, &fValue))
346 if (JS_ValueToInt32(context, *value, &iValue))
348 if (iValue < 0) iValue = 0;
355 if (JS_ValueToNumber(context, *value, &fValue))
381 NSString *message =
nil;
386 if (argc > 1) gotTime = JS_ValueToNumber(context,
OOJS_ARGV[1], &time);
387 if (message ==
nil || !gotTime)
393 [UNIVERSE addCommsMessage:message forCount:time];
394 [PLAYER doScriptEvent:OOJSID("commsMessageReceived") withArgument:message andArgument:nil];
406 NSString *message =
nil;
411 if (argc > 1) gotTime = JS_ValueToNumber(context,
OOJS_ARGV[1], &time);
412 if (message ==
nil || !gotTime)
418 [UNIVERSE addMessage:message forCount:time];
430 NSString *scenario =
nil;
450 [OOPlayerForScripting() increaseContractReputation:1];
462 [OOPlayerForScripting() decreaseContractReputation:1];
474 [OOPlayerForScripting() increaseParcelReputation:1];
486 [OOPlayerForScripting() decreaseParcelReputation:1];
498 [OOPlayerForScripting() increasePassengerReputation:1];
510 [OOPlayerForScripting() decreasePassengerReputation:1];
521 NSString *report =
nil;
542 NSString *audioMessage =
nil;
546 if (audioMessage ==
nil)
564 NSString *shipKey =
nil;
576 if (
EXPECT_NOT(!([player status] == STATUS_DOCKED)))
578 OOJSReportError(context,
@"Player.replaceShip() only works while the player is docked.");
585 JS_ValueToInt32(context,
OOJS_ARGV[1],&personality);
612 OOJSReportError(context,
@"Player.setEscapePodDestination() only works while the escape pod is in flight.");
624 if (destValue ==
nil)
629 else if ([destValue isKindOfClass:[
ShipEntity class]] && [destValue isStation])
634 else if ([destValue isKindOfClass:[NSString
class]])
636 if ([destValue isEqualToString:
@"NEARBY_SYSTEM"])
647 NSMutableArray *sDests = [UNIVERSE nearbyDestinationsWithinRange:rescueRange];
648 NSUInteger i = 0, nDests = [sDests count];
650 if (nDests > 0)
for (i = --nDests; i > 0; i--)
652 if ([[sDests oo_dictionaryAtIndex:i] oo_boolForKey:
@"nova"])
654 [sDests removeObjectAtIndex:i];
659 nDests = [sDests count];
663 NSDictionary *dest = [sDests objectAtIndex:i];
666 double dist = [dest oo_doubleForKey:@"distance"];
667 [player
addToAdjustTime:(.2 + dist * dist) * 3600.0 + 5400.0 * (ranrot_rand() & 127)];
678 if (JS_ValueToBoolean(context,
OOJS_ARGV[0], &bValue) && bValue == NO)
701 NSString *role =
nil;
714 if (JS_ValueToECMAUint32(context,
OOJS_ARGV[1],&index))
730 if ([
UNIVERSE isSpeaking]) [UNIVERSE stopSpeaking];
NSString * DockingClearanceStatusToString(OODockingClearanceStatus dockingClearanceStatus) PURE_FUNC
#define OOJS_NATIVE_ENTER(cx)
OOINLINE BOOL OOIsPlayerStale(void)
JSClass * JSPlayerClass(void)
static JSBool PlayerSetEscapePodDestination(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerIncreasePassengerReputation(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerIncreaseParcelReputation(JSContext *context, uintN argc, jsval *vp)
void InitOOJSPlayer(JSContext *context, JSObject *global)
static JSBool PlayerDecreaseParcelReputation(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool PlayerEndScenario(JSContext *context, uintN argc, jsval *vp)
@ kPlayer_passengerReputationPrecise
@ kPlayer_parcelReputation
@ kPlayer_alertMassLocked
@ kPlayer_contractReputation
@ kPlayer_dockingClearanceStatus
@ kPlayer_passengerReputation
@ kPlayer_alertTemperature
@ kPlayer_escapePodRescueTime
@ kPlayer_contractReputationPrecise
@ kPlayer_parcelReputationPrecise
static JSBool PlayerStopAudioMessage(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerIncreaseContractReputation(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerDecreasePassengerReputation(JSContext *context, uintN argc, jsval *vp)
JSObject * JSPlayerObject(void)
static JSBool PlayerReplaceShip(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerAudioMessage(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerCommsMessage(JSContext *context, uintN argc, jsval *vp)
PlayerEntity * OOPlayerForScripting(void)
static JSBool PlayerAddMessageToArrivalReport(JSContext *context, uintN argc, jsval *vp)
static JSClass sPlayerClass
static JSBool PlayerDecreaseContractReputation(JSContext *context, uintN argc, jsval *vp)
static JSBool PlayerSetPlayerRole(JSContext *context, uintN argc, jsval *vp)
JSObject * JSPlayerPrototype(void)
static JSObject * sPlayerPrototype
static JSObject * sPlayerObject
static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool PlayerConsoleMessage(JSContext *context, uintN argc, jsval *vp)
static JSPropertySpec sPlayerProperties[]
static JSFunctionSpec sPlayerMethods[]
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
#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)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
void OOJSReportError(JSContext *context, NSString *format,...)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
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
NSString * OODisplayRatingStringFromKillCount(unsigned kills)
NSString * OODisplayStringFromLegalStatus(int legalStatus)
#define ENTITY_PERSONALITY_MAX
void addRoleToPlayer:(NSString *role)
void setBounty:withReason:(OOCreditsQuantity amount, [withReason] OOLegalStatusReason reason)
NSString * commanderName()
void setScore:(unsigned value)
BOOL replaceShipWithNamedShip:(NSString *shipName)
void setCreditBalance:(double value)
NSMutableArray * roleWeights
void addToAdjustTime:(double seconds)
void setDockTarget:(ShipEntity *entity)
void addMessageToReport:(NSString *report)
void setScriptTarget:(ShipEntity *ship)
void setEscapePodRescueTime:(double seconds)
void addRoleToPlayer:inSlot:(NSString *role,[inSlot] NSUInteger slot)
void setCommanderName:(NSString *value)
void setTargetSystemID:(OOSystemID sid)
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)