42static JSBool
StationGetProperty(JSContext* context, JSObject*
this, jsid propID, jsval* value);
43static JSBool
StationSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value);
78 JSCLASS_NO_OPTIONAL_MEMBERS
165 if (outEntity == NULL)
169 result = OOJSEntityGetEntity(context, stationObj, &entity);
189 if (outEntity == NULL)
193 result = OOJSEntityGetEntity(context, shipObj, &entity);
197 if (![entity isKindOfClass:[
ShipEntity class]])
206@implementation StationEntity (OOJavaScriptExtensions)
208- (void)getJSClass:(JSClass**)outClass andPrototype:(JSObject**)outPrototype
223 if (!JSID_IS_INT(propID))
237 switch (JSID_TO_INT(propID)) {
251 *value = INT_TO_JSVAL([entity alertLevel]);
266 return JS_NewNumberValue(context, [entity flightRoll], value);
277 *value = INT_TO_JSVAL([entity countOfDockedContractors]);
281 *value = INT_TO_JSVAL([entity countOfDockedPolice]);
285 *value = INT_TO_JSVAL([entity countOfDockedDefenders]);
289 *value = INT_TO_JSVAL((int32_t)[entity equivalentTechLevel]);
293 return JS_NewNumberValue(context, [entity equipmentPriceFactor], value);
304 if (![entity hasShipyard]) {
308 if ([entity localShipyard] ==
nil)
330static JSBool
StationSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value)
332 if (!JSID_IS_INT(propID))
341 NSString* sValue =
nil;
348 switch (JSID_TO_INT(propID)) {
350 if (JS_ValueToBoolean(context, *value, &bValue)) {
357 if (JS_ValueToInt32(context, *value, &iValue)) {
372 if (JS_ValueToBoolean(context, *value, &bValue)) {
379 if (JS_ValueToNumber(context, *value, &fValue)) {
386 else if (fValue >
M_PI)
394 if (JS_ValueToBoolean(context, *value, &bValue)) {
401 if (JS_ValueToBoolean(context, *value, &bValue)) {
408 if (JS_ValueToBoolean(context, *value, &bValue)) {
415 if (JS_ValueToBoolean(context, *value, &bValue)) {
510 if (
EXPECT_NOT([gameController isGamePaused])) {
518 if (
EXPECT(![player isDocked])) {
523 [UNIVERSE setViewDirection:VIEW_FORWARD];
524 [player
enterDock:stationForDockingPlayer];
540 if ([station alertCondition] < 3) {
557 if ([station alertCondition] > 1) {
570 NSString* shipRole =
nil;
573 JSBool abortAllDockings = NO;
586 JS_ValueToBoolean(context,
OOJS_ARGV[1], &abortAllDockings);
590 if (abortAllDockings)
722 NSArray* launched =
nil;
744 if (argc < 2 || JSVAL_IS_NULL(
OOJS_ARGV[1])) {
749 jsval value = JSVAL_NULL;
750 jsval callback = JSVAL_NULL;
751 JSObject* callbackThis = NULL;
752 JSObject* params = NULL;
754 NSString* title =
nil;
755 NSString* summary =
nil;
756 NSString* category =
nil;
758 if (!JS_ValueToObject(context,
OOJS_ARGV[1], ¶ms)) {
764 if (JS_GetProperty(context, params,
"title", &value) == JS_FALSE || JSVAL_IS_VOID(value)) {
765 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, it must have a 'title' property.");
769 if (title ==
nil || [title length] == 0) {
770 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, 'title' property must be a non-empty string.");
775 if (JS_GetProperty(context, params,
"category", &value) == JS_FALSE || JSVAL_IS_VOID(value)) {
776 category = [NSString stringWithString:DESC(@"interfaces-category-uncategorised")];
779 if (category ==
nil || [category length] == 0) {
780 category = [NSString stringWithString:DESC(@"interfaces-category-uncategorised")];
785 if (JS_GetProperty(context, params,
"summary", &value) == JS_FALSE || JSVAL_IS_VOID(value)) {
786 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, it must have a 'summary' property.");
790 if (summary ==
nil || [summary length] == 0) {
791 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, 'summary' property must be a non-empty string.");
796 if (JS_GetProperty(context, params,
"callback", &callback) == JS_FALSE || JSVAL_IS_VOID(callback)) {
797 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, it must have a 'callback' property.");
812 if (JS_GetProperty(context, params,
"cbThis", &value) == JS_TRUE && !JSVAL_IS_VOID(value)) {
813 JS_ValueToObject(context, value, &callbackThis);
820 [definition release];
847 BOOL gotPrice = JS_ValueToInt32(context,
OOJS_ARGV[1], &price);
855 if (station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_MARKET) {
856 [PLAYER setGuiToMarketScreen];
884 BOOL gotQuantity = JS_ValueToInt32(context,
OOJS_ARGV[1], &quantity);
885 if (
EXPECT_NOT(!gotQuantity || quantity < 0 || (
OOCargoQuantity)quantity > [[station localMarket] capacityForGood:commodity])) {
892 if (station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_MARKET) {
893 [PLAYER setGuiToMarketScreen];
905 JSObject* params = NULL;
910 if (argc != 1 || (!JSVAL_IS_NULL(
OOJS_ARGV[0]) && !JS_ValueToObject(context,
OOJS_ARGV[0], ¶ms))) {
916 if (![station hasShipyard]) {
921 if (![station localShipyard])
928 NSMutableDictionary* result = [NSMutableDictionary dictionary];
931 if (!shipyardDefinition) {
939 [result setObject:[shipyardDefinition oo_stringForKey:@"short_description"] forKey:KEY_SHORT_DESCRIPTION];
945 NSString* shipKey = [shipyardDefinition oo_stringForKey:SHIPYARD_KEY_SHIPDATA_KEY defaultValue:nil];
947 NSMutableDictionary* shipInfo = [NSMutableDictionary dictionaryWithDictionary:[registry
shipInfoForKey:shipKey]];
954 if ([[shipInfo oo_stringForKey:
@"roles"] rangeOfString:
@"player"].location == NSNotFound) {
963 [result setObject:shipKey forKey:SHIPYARD_KEY_SHIPDATA_KEY];
967 int superRand1 = ship_seed.
a * 0x10000 + ship_seed.
c * 0x100 + ship_seed.
e;
968 uint32_t superRand2 = ship_seed.
b * 0x10000 + ship_seed.
d * 0x100 + ship_seed.
f;
970 NSString* shipID = [NSString stringWithFormat:@"%06x-%06x", superRand1, superRand2];
971 [result setObject:shipID forKey:SHIPYARD_KEY_ID];
976 [result setObject:[NSNumber numberWithUnsignedLongLong:price] forKey:SHIPYARD_KEY_PRICE];
978 OOCreditsQuantity price = [shipyardDefinition oo_unsignedIntForKey:SHIPYARD_KEY_PRICE];
980 [result setObject:[NSNumber numberWithUnsignedLongLong:price] forKey:SHIPYARD_KEY_PRICE];
989 [result setObject:[NSNumber numberWithUnsignedInt:0] forKey:SHIPYARD_KEY_PERSONALITY];
991 [result setObject:[NSNumber numberWithUnsignedLongLong:[shipyardDefinition oo_unsignedIntForKey:SHIPYARD_KEY_PERSONALITY]] forKey:SHIPYARD_KEY_PERSONALITY];
994 NSArray* extras = [shipyardDefinition oo_arrayForKey:KEY_EQUIPMENT_EXTRAS];
997 extras = [NSArray arrayWithArray:[[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
999 if ([extras
count] > 0) {
1001 NSString* fwdWeaponString = [[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_FORWARD_WEAPON];
1002 NSString* aftWeaponString = [[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_AFT_WEAPON];
1009 NSString* equipmentKey =
nil;
1010 for (i = 0; i < [extras count]; i++) {
1011 equipmentKey = [extras oo_stringAtIndex:i];
1012 if ([equipmentKey hasPrefix:
@"EQ_WEAPON"]) {
1015 if (availableFacings &
WEAPON_FACING_FORWARD && [new_weapon weaponThreatAssessment] > [fwdWeapon weaponThreatAssessment]) {
1017 fwdWeaponString = equipmentKey;
1018 fwdWeapon = new_weapon;
1019 [shipInfo setObject:fwdWeaponString forKey:KEY_EQUIPMENT_FORWARD_WEAPON];
1022 if (availableFacings &
WEAPON_FACING_AFT && (
isWeaponNone(aftWeapon) || [new_weapon weaponThreatAssessment] > [aftWeapon weaponThreatAssessment])) {
1023 aftWeaponString = equipmentKey;
1024 aftWeapon = new_weapon;
1025 [shipInfo setObject:aftWeaponString forKey:KEY_EQUIPMENT_AFT_WEAPON];
1032 [result setObject:extras forKey:KEY_EQUIPMENT_EXTRAS];
1034 [result setObject:shipInfo forKey:SHIPYARD_KEY_SHIP];
1036 [shipyard addObject:result];
1039 if (station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_SHIPYARD) {
1040 [PLAYER setGuiToShipyardScreen:0];
1057 if (![station hasShipyard]) {
1062 if (![station localShipyard])
1066 int32 shipIndex = -1;
1067 BOOL gotIndex = YES;
1068 gotIndex = JS_ValueToInt32(context,
OOJS_ARGV[0], &shipIndex);
1070 if (argc != 1 || (!JSVAL_IS_NULL(
OOJS_ARGV[0]) && !gotIndex) || shipIndex < 0 || (shipIndex + 1) > [shipyard
count]) {
1075 [shipyard removeObjectAtIndex:shipIndex];
1078 if (station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_SHIPYARD) {
1079 [PLAYER setGuiToShipyardScreen:0];
#define OOJS_PROFILE_EXIT
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_PROFILE_ENTER
PlayerEntity * OOPlayerForScripting(void)
JSObject * JSShipPrototype(void)
JSClass * JSShipClass(void)
static JSBool StationIncreaseAlertLevel(JSContext *context, uintN argc, jsval *vp)
static JSBool StationLaunchPolice(JSContext *context, uintN argc, jsval *vp)
static JSBool StationSetMarketQuantity(JSContext *context, uintN argc, jsval *vp)
static JSBool StationDecreaseAlertLevel(JSContext *context, uintN argc, jsval *vp)
static JSClass sStationClass
static JSBool StationLaunchShuttle(JSContext *context, uintN argc, jsval *vp)
static JSBool StationLaunchMiner(JSContext *context, uintN argc, jsval *vp)
static JSBool StationLaunchShipWithRole(JSContext *context, uintN argc, jsval *vp)
static JSBool StationRemoveShipFromShipyard(JSContext *context, uintN argc, jsval *vp)
static BOOL JSStationGetStationEntity(JSContext *context, JSObject *stationObj, StationEntity **outEntity)
static JSBool StationLaunchDefenseShip(JSContext *context, uintN argc, jsval *vp)
static BOOL JSStationGetShipEntity(JSContext *context, JSObject *shipObj, ShipEntity **outEntity)
static JSBool StationSetInterface(JSContext *context, uintN argc, jsval *vp)
static JSBool StationGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
void InitOOJSStation(JSContext *context, JSObject *global)
static JSBool StationSetMarketPrice(JSContext *context, uintN argc, jsval *vp)
static JSBool StationAbortDockingForShip(JSContext *context, uintN argc, jsval *vp)
static JSBool StationLaunchPirateShip(JSContext *context, uintN argc, jsval *vp)
static JSBool StationAddShipToShipyard(JSContext *context, uintN argc, jsval *vp)
static JSBool StationCanDockShip(JSContext *context, uintN argc, jsval *vp)
static JSBool StationDockPlayer(JSContext *context, uintN argc, jsval *vp)
static JSObject * sStationPrototype
@ kStation_equivalentTechLevel
@ kStation_allowsAutoDocking
@ kStation_equipmentPriceFactor
@ kStation_alertCondition
@ kStation_allowsFastDocking
@ kStation_dockedDefenders
@ kStation_requiresDockingClearance
@ kStation_dockedContractors
@ kStation_suppressArrivalReports
static JSPropertySpec sStationProperties[]
static JSFunctionSpec sStationMethods[]
static JSBool StationLaunchScavenger(JSContext *context, uintN argc, jsval *vp)
static JSBool StationLaunchEscort(JSContext *context, uintN argc, jsval *vp)
static JSBool StationSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool StationAbortAllDockings(JSContext *context, uintN argc, jsval *vp)
static JSBool StationLaunchPatrol(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READWRITE_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
void OOJSReportWarningForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
#define OOJS_RETURN_BOOL(v)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
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
uint8_t OOWeaponFacingSet
NSString * OOCommodityType
uint64_t OOCreditsQuantity
#define VALID_WEAPON_FACINGS
OOEquipmentType * OOWeaponType
BOOL isWeaponNone(OOWeaponType weapon)
OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string) PURE_FUNC
#define KEY_SHORT_DESCRIPTION
#define SHIPYARD_KEY_PRICE
#define SHIPYARD_KEY_PERSONALITY
#define SHIPYARD_KEY_SHIPDATA_KEY
NSString * oo_jsClassName()
void setGamePaused:(BOOL value)
void setCallback:(jsval callback)
void setSummary:(NSString *summary)
void setCategory:(NSString *category)
void setTitle:(NSString *title)
void setCallbackThis:(JSObject *callbackthis)
NSDictionary * shipyardInfoForKey:(NSString *key)
OOShipRegistry * sharedRegistry()
NSDictionary * shipInfoForKey:(NSString *key)
void setDockingClearanceStatus:(OODockingClearanceStatus newValue)
void enterDock:(StationEntity *station)
void setRawRoll:(double amount)
void setQuantity:forCommodity:(OOCargoQuantity quantity,[forCommodity] OOCommodityType commodity)
ShipEntity * launchMiner()
ShipEntity * launchScavenger()
void setHasNPCTraffic:(BOOL flag)
void setAllowsFastDocking:(BOOL newValue)
ShipEntity * launchIndependentShip:(NSString *role)
ShipEntity * launchDefenseShip()
ShipEntity * launchPirateShip()
void setAlertLevel:signallingScript:(OOStationAlertLevel level,[signallingScript] BOOL signallingScript)
ShipEntity * launchShuttle()
NSMutableArray * localShipyard
ShipEntity * launchPatrol()
void setSuppressArrivalReports:(BOOL newValue)
void increaseAlertLevel()
void setRequiresDockingClearance:(BOOL newValue)
void setAllowsAutoDocking:(BOOL newValue)
NSDictionary * localMarketForScripting()
void setInterfaceDefinition:forKey:(OOJSInterfaceDefinition *definition,[forKey] NSString *key)
void decreaseAlertLevel()
void setHasBreakPattern:(BOOL newValue)
BOOL fitsInDock:andLogNoFit:(ShipEntity *ship,[andLogNoFit] BOOL logNoFit)
ShipEntity * launchEscort()
void setPrice:forCommodity:(OOCreditsQuantity price,[forCommodity] OOCommodityType commodity)
void setAllegiance:(NSString *newAllegiance)
void abortDockingForShip:(ShipEntity *ship)