45static JSBool
StationGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
46static JSBool
StationSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
82 JSCLASS_NO_OPTIONAL_MEMBERS
177 if (outEntity == NULL)
return NO;
180 result = OOJSEntityGetEntity(context, stationObj, &entity);
181 if (!result)
return NO;
183 if (![entity isKindOfClass:[
StationEntity class]])
return NO;
198 if (outEntity == NULL)
return NO;
201 result = OOJSEntityGetEntity(context, shipObj, &entity);
202 if (!result)
return NO;
204 if (![entity isKindOfClass:[
ShipEntity class]])
return NO;
213@implementation StationEntity (OOJavaScriptExtensions)
215- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
232 if (!JSID_IS_INT(propID))
return YES;
239 if (entity ==
nil) { *value = JSVAL_VOID;
return YES; }
241 switch (JSID_TO_INT(propID))
256 *value = INT_TO_JSVAL([entity alertLevel]);
272 return JS_NewNumberValue(context, [entity flightRoll], value);
283 *value = INT_TO_JSVAL([entity countOfDockedContractors]);
287 *value = INT_TO_JSVAL([entity countOfDockedPolice]);
291 *value = INT_TO_JSVAL([entity countOfDockedDefenders]);
295 *value = INT_TO_JSVAL((int32_t)[entity equivalentTechLevel]);
299 return JS_NewNumberValue(context, [entity equipmentPriceFactor], value);
311 if (![entity hasShipyard])
341static JSBool
StationSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
343 if (!JSID_IS_INT(propID))
return YES;
351 NSString *sValue =
nil;
354 if (entity ==
nil)
return YES;
356 switch (JSID_TO_INT(propID))
359 if (JS_ValueToBoolean(context, *value, &bValue))
367 if (JS_ValueToInt32(context, *value, &iValue))
385 if (JS_ValueToBoolean(context, *value, &bValue))
393 if (JS_ValueToNumber(context, *value, &fValue))
400 else if (fValue >
M_PI) fValue =
M_PI;
407 if (JS_ValueToBoolean(context, *value, &bValue))
415 if (JS_ValueToBoolean(context, *value, &bValue))
423 if (JS_ValueToBoolean(context, *value, &bValue))
431 if (JS_ValueToBoolean(context, *value, &bValue))
476 if (!JSVAL_IS_OBJECT(
OOJS_ARGV[0]))
return NO;
532 if (
EXPECT_NOT([gameController isGamePaused]))
541 if (
EXPECT(![player isDocked]))
547 [UNIVERSE setViewDirection:VIEW_FORWARD];
548 [player
enterDock:stationForDockingPlayer];
564 if ([station alertCondition] < 3)
581 if ([station alertCondition] > 1)
595 NSString *shipRole =
nil;
598 JSBool abortAllDockings = NO;
609 if (argc > 1) JS_ValueToBoolean(context,
OOJS_ARGV[1], &abortAllDockings);
744 NSArray *launched =
nil;
766 if (argc < 2 || JSVAL_IS_NULL(
OOJS_ARGV[1]))
773 jsval value = JSVAL_NULL;
774 jsval callback = JSVAL_NULL;
775 JSObject *callbackThis = NULL;
776 JSObject *params = NULL;
778 NSString *title =
nil;
779 NSString *summary =
nil;
780 NSString *category =
nil;
782 if (!JS_ValueToObject(context,
OOJS_ARGV[1], ¶ms))
789 if (JS_GetProperty(context, params,
"title", &value) == JS_FALSE || JSVAL_IS_VOID(value))
791 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, it must have a 'title' property.");
795 if (title ==
nil || [title length] == 0)
797 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, 'title' property must be a non-empty string.");
802 if (JS_GetProperty(context, params,
"category", &value) == JS_FALSE || JSVAL_IS_VOID(value))
804 category = [NSString stringWithString:DESC(@"interfaces-category-uncategorised")];
809 if (category ==
nil || [category length] == 0) {
810 category = [NSString stringWithString:DESC(@"interfaces-category-uncategorised")];
815 if (JS_GetProperty(context, params,
"summary", &value) == JS_FALSE || JSVAL_IS_VOID(value))
817 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, it must have a 'summary' property.");
821 if (summary ==
nil || [summary length] == 0)
823 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, 'summary' property must be a non-empty string.");
828 if (JS_GetProperty(context, params,
"callback", &callback) == JS_FALSE || JSVAL_IS_VOID(callback))
830 OOJSReportBadArguments(context,
@"Station",
@"setInterface",
MIN(argc, 1U),
OOJS_ARGV, NULL,
@"key [, definition]; if definition is set, it must have a 'callback' property.");
846 if (JS_GetProperty(context, params,
"cbThis", &value) == JS_TRUE && !JSVAL_IS_VOID(value))
848 JS_ValueToObject(context, value, &callbackThis);
855 [definition release];
884 BOOL gotPrice = JS_ValueToInt32(context,
OOJS_ARGV[1], &price);
893 if (station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_MARKET)
895 [PLAYER setGuiToMarketScreen];
925 BOOL gotQuantity = JS_ValueToInt32(context,
OOJS_ARGV[1], &quantity);
926 if (
EXPECT_NOT(!gotQuantity || quantity < 0 || (
OOCargoQuantity)quantity > [[station localMarket] capacityForGood:commodity]))
934 if (station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_MARKET)
936 [PLAYER setGuiToMarketScreen];
949 JSObject *params = NULL;
953 if (argc != 1 || (!JSVAL_IS_NULL(
OOJS_ARGV[0]) && !JS_ValueToObject(context,
OOJS_ARGV[0], ¶ms)))
960 if (![station hasShipyard]) {
970 NSMutableDictionary *result = [NSMutableDictionary dictionary];
973 if (!shipyardDefinition)
983 [result setObject:[shipyardDefinition oo_stringForKey:@"short_description"] forKey:KEY_SHORT_DESCRIPTION];
990 NSString *shipKey = [shipyardDefinition oo_stringForKey:SHIPYARD_KEY_SHIPDATA_KEY defaultValue:nil];
992 NSMutableDictionary *shipInfo = [NSMutableDictionary dictionaryWithDictionary:[registry
shipInfoForKey:shipKey]];
1000 if ([[shipInfo oo_stringForKey:
@"roles"] rangeOfString:
@"player"].location == NSNotFound)
1011 [result setObject:shipKey forKey:SHIPYARD_KEY_SHIPDATA_KEY];
1015 int superRand1 = ship_seed.
a * 0x10000 + ship_seed.
c * 0x100 + ship_seed.
e;
1016 uint32_t superRand2 = ship_seed.
b * 0x10000 + ship_seed.
d * 0x100 + ship_seed.
f;
1018 NSString *shipID = [NSString stringWithFormat:@"%06x-%06x", superRand1, superRand2];
1019 [result setObject:shipID forKey:SHIPYARD_KEY_ID];
1025 [result setObject:[NSNumber numberWithUnsignedLongLong:price] forKey:SHIPYARD_KEY_PRICE];
1029 OOCreditsQuantity price = [shipyardDefinition oo_unsignedIntForKey:SHIPYARD_KEY_PRICE];
1032 [result setObject:[NSNumber numberWithUnsignedLongLong:price] forKey:SHIPYARD_KEY_PRICE];
1044 [result setObject:0 forKey:SHIPYARD_KEY_PERSONALITY];
1048 [result setObject:[NSNumber numberWithUnsignedLongLong:[shipyardDefinition oo_unsignedIntForKey:SHIPYARD_KEY_PERSONALITY]] forKey:SHIPYARD_KEY_PERSONALITY];
1051 NSArray *extras = [shipyardDefinition oo_arrayForKey:KEY_EQUIPMENT_EXTRAS];
1055 extras = [NSArray arrayWithArray:[[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
1057 if ([extras
count] > 0) {
1059 NSString* fwdWeaponString = [[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_FORWARD_WEAPON];
1060 NSString* aftWeaponString = [[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_AFT_WEAPON];
1067 NSString *equipmentKey =
nil;
1068 for (i = 0; i < [extras count]; i++) {
1069 equipmentKey = [extras oo_stringAtIndex:i];
1070 if ([equipmentKey hasPrefix:
@"EQ_WEAPON"])
1074 if (availableFacings &
WEAPON_FACING_FORWARD && [new_weapon weaponThreatAssessment] > [fwdWeapon weaponThreatAssessment])
1077 fwdWeaponString = equipmentKey;
1078 fwdWeapon = new_weapon;
1079 [shipInfo setObject:fwdWeaponString forKey:KEY_EQUIPMENT_FORWARD_WEAPON];
1084 if (availableFacings &
WEAPON_FACING_AFT && (
isWeaponNone(aftWeapon) || [new_weapon weaponThreatAssessment] > [aftWeapon weaponThreatAssessment]))
1086 aftWeaponString = equipmentKey;
1087 aftWeapon = new_weapon;
1088 [shipInfo setObject:aftWeaponString forKey:KEY_EQUIPMENT_AFT_WEAPON];
1095 [result setObject:extras forKey:KEY_EQUIPMENT_EXTRAS];
1097 [result setObject:shipInfo forKey:SHIPYARD_KEY_SHIP];
1099 [shipyard addObject:result];
1102 if(station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_SHIPYARD)
1104 [PLAYER setGuiToShipyardScreen:0];
1121 if (![station hasShipyard]) {
1129 int32 shipIndex = -1;
1130 BOOL gotIndex = YES;
1131 gotIndex = JS_ValueToInt32(context,
OOJS_ARGV[0], &shipIndex);
1133 if (argc != 1 || (!JSVAL_IS_NULL(
OOJS_ARGV[0]) && !gotIndex) || shipIndex < 0 || (shipIndex + 1) > [shipyard
count])
1139 [shipyard removeObjectAtIndex:shipIndex];
1142 if(station == [
PLAYER dockedStation] && [
PLAYER guiScreen] == GUI_SCREEN_SHIPYARD)
1144 [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)
@ kStation_equivalentTechLevel
@ kStation_allowsAutoDocking
@ kStation_equipmentPriceFactor
@ kStation_alertCondition
@ kStation_allowsFastDocking
@ kStation_dockedDefenders
@ kStation_requiresDockingClearance
@ kStation_dockedContractors
@ kStation_suppressArrivalReports
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
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
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)