More ship properties
This commit is contained in:
commit
d196f8f45b
@ -835,6 +835,11 @@ typedef enum
|
||||
- (Vector) viewpointPosition;
|
||||
- (Vector) breakPatternPosition;
|
||||
- (Vector) viewpointOffset;
|
||||
- (Vector) viewpointOffsetAft;
|
||||
- (Vector) viewpointOffsetForward;
|
||||
- (Vector) viewpointOffsetPort;
|
||||
- (Vector) viewpointOffsetStarboard;
|
||||
|
||||
|
||||
- (NSDictionary *) missionOverlayDescriptor;
|
||||
- (NSDictionary *) missionOverlayDescriptorOrDefault;
|
||||
|
@ -3101,6 +3101,27 @@ static GLfloat sBaseMass = 0.0;
|
||||
}
|
||||
|
||||
|
||||
- (Vector) viewpointOffsetAft
|
||||
{
|
||||
return aftViewOffset;
|
||||
}
|
||||
|
||||
- (Vector) viewpointOffsetForward
|
||||
{
|
||||
return forwardViewOffset;
|
||||
}
|
||||
|
||||
- (Vector) viewpointOffsetPort
|
||||
{
|
||||
return portViewOffset;
|
||||
}
|
||||
|
||||
- (Vector) viewpointOffsetStarboard
|
||||
{
|
||||
return starboardViewOffset;
|
||||
}
|
||||
|
||||
|
||||
/* TODO post 1.78: profiling suggests this gets called often enough
|
||||
* that it's worth caching the result per-frame - CIM */
|
||||
- (Vector) viewpointPosition
|
||||
|
@ -59,6 +59,7 @@ SOFTWARE.
|
||||
|
||||
@interface OOShipRegistry (OOConveniences)
|
||||
|
||||
- (NSArray *) shipKeys;
|
||||
- (NSArray *) shipKeysWithRole:(NSString *)role;
|
||||
- (NSString *) randomShipKeyForRole:(NSString *)role;
|
||||
|
||||
|
@ -240,6 +240,11 @@ static NSString * const kVisualEffectDataCacheKey = @"visual effect data";
|
||||
|
||||
@implementation OOShipRegistry (OOConveniences)
|
||||
|
||||
- (NSArray *) shipKeys
|
||||
{
|
||||
return [_shipData allKeys];
|
||||
}
|
||||
|
||||
- (NSArray *) shipKeysWithRole:(NSString *)role
|
||||
{
|
||||
return [[self probabilitySetForRole:role] allObjects];
|
||||
|
@ -128,6 +128,10 @@ enum
|
||||
kPlayerShip_specialCargo, // special cargo, string, read-only
|
||||
kPlayerShip_targetSystem, // target system id, int, read-write
|
||||
kPlayerShip_viewDirection, // view direction identifier, string, read-only
|
||||
kPlayerShip_viewPositionAft, // view position offset, vector, read-only
|
||||
kPlayerShip_viewPositionForward, // view position offset, vector, read-only
|
||||
kPlayerShip_viewPositionPort, // view position offset, vector, read-only
|
||||
kPlayerShip_viewPositionStarboard, // view position offset, vector, read-only
|
||||
kPlayerShip_weaponsOnline, // weapons online status, boolean, read-only
|
||||
kPlayerShip_yaw, // yaw (overrules Ship)
|
||||
};
|
||||
@ -170,6 +174,10 @@ static JSPropertySpec sPlayerShipProperties[] =
|
||||
{ "specialCargo", kPlayerShip_specialCargo, OOJS_PROP_READONLY_CB },
|
||||
{ "targetSystem", kPlayerShip_targetSystem, OOJS_PROP_READWRITE_CB },
|
||||
{ "viewDirection", kPlayerShip_viewDirection, OOJS_PROP_READONLY_CB },
|
||||
{ "viewPositionAft", kPlayerShip_viewPositionAft, OOJS_PROP_READONLY_CB },
|
||||
{ "viewPositionForward", kPlayerShip_viewPositionForward, OOJS_PROP_READONLY_CB },
|
||||
{ "viewPositionPort", kPlayerShip_viewPositionPort, OOJS_PROP_READONLY_CB },
|
||||
{ "viewPositionStarboard", kPlayerShip_viewPositionStarboard, OOJS_PROP_READONLY_CB },
|
||||
{ "weaponsOnline", kPlayerShip_weaponsOnline, OOJS_PROP_READONLY_CB },
|
||||
{ "yaw", kPlayerShip_yaw, OOJS_PROP_READONLY_CB },
|
||||
{ 0 }
|
||||
@ -387,6 +395,18 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
*value = OOJSValueFromViewID(context, [UNIVERSE viewDirection]);
|
||||
return YES;
|
||||
|
||||
case kPlayerShip_viewPositionAft:
|
||||
return VectorToJSValue(context, [player viewpointOffsetAft], value);
|
||||
|
||||
case kPlayerShip_viewPositionForward:
|
||||
return VectorToJSValue(context, [player viewpointOffsetForward], value);
|
||||
|
||||
case kPlayerShip_viewPositionPort:
|
||||
return VectorToJSValue(context, [player viewpointOffsetPort], value);
|
||||
|
||||
case kPlayerShip_viewPositionStarboard:
|
||||
return VectorToJSValue(context, [player viewpointOffsetStarboard], value);
|
||||
|
||||
case kPlayerShip_currentWeapon:
|
||||
result = [player weaponTypeForFacing:[player currentWeaponFacing]];
|
||||
break;
|
||||
|
@ -92,12 +92,11 @@ static JSBool ShipBecomeCascadeExplosion(JSContext *context, uintN argc, jsval *
|
||||
static JSBool ShipBroadcastCascadeImminent(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipOfferToEscort(JSContext *context, uintN argc, jsval *vp);
|
||||
|
||||
|
||||
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp);
|
||||
|
||||
static BOOL RemoveOrExplodeShip(JSContext *context, uintN argc, jsval *vp, BOOL explode);
|
||||
static JSBool ShipSetMaterialsInternal(JSContext *context, uintN argc, jsval *vp, ShipEntity *thisEnt, BOOL fromShaders);
|
||||
|
||||
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipStaticKeys(JSContext *context, uintN argc, jsval *vp);
|
||||
|
||||
|
||||
static JSClass sShipClass =
|
||||
@ -150,6 +149,7 @@ enum
|
||||
kShip_equipment, // the ship's equipment, array of EquipmentInfo, read only
|
||||
kShip_escortGroup, // group, ShipGroup, read-only
|
||||
kShip_escorts, // deployed escorts, array of Ship, read-only
|
||||
kShip_extraCargo, // cargo space increase granted by large cargo bay, int, read-only
|
||||
kShip_forwardWeapon, // the ship's forward weapon, equipmentType, read/write
|
||||
kShip_fuel, // fuel, float, read/write
|
||||
kShip_fuelChargeRate, // fuel scoop rate & charge multiplier, float, read-only
|
||||
@ -271,6 +271,7 @@ static JSPropertySpec sShipProperties[] =
|
||||
{ "equipment", kShip_equipment, OOJS_PROP_READONLY_CB },
|
||||
{ "escorts", kShip_escorts, OOJS_PROP_READONLY_CB },
|
||||
{ "escortGroup", kShip_escortGroup, OOJS_PROP_READONLY_CB },
|
||||
{ "extraCargo", kShip_extraCargo, OOJS_PROP_READONLY_CB },
|
||||
{ "forwardWeapon", kShip_forwardWeapon, OOJS_PROP_READWRITE_CB },
|
||||
{ "fuel", kShip_fuel, OOJS_PROP_READWRITE_CB },
|
||||
{ "fuelChargeRate", kShip_fuelChargeRate, OOJS_PROP_READONLY_CB },
|
||||
@ -358,7 +359,6 @@ static JSPropertySpec sShipProperties[] =
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
||||
static JSFunctionSpec sShipMethods[] =
|
||||
{
|
||||
// JS name Function min args
|
||||
@ -410,6 +410,7 @@ static JSFunctionSpec sShipMethods[] =
|
||||
static JSFunctionSpec sShipStaticMethods[] =
|
||||
{
|
||||
// JS name Function min args
|
||||
{ "keys", ShipStaticKeys, 0 },
|
||||
{ "keysForRole", ShipStaticKeysForRole, 1 },
|
||||
{ 0 }
|
||||
};
|
||||
@ -642,6 +643,10 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
case kShip_cargoSpaceAvailable:
|
||||
*value = INT_TO_JSVAL([entity availableCargoSpace]);
|
||||
return YES;
|
||||
|
||||
case kShip_extraCargo:
|
||||
*value = INT_TO_JSVAL([entity extraCargo]);
|
||||
return YES;
|
||||
|
||||
case kShip_commodity:
|
||||
if ([entity commodityAmount] > 0)
|
||||
@ -2502,27 +2507,6 @@ static JSBool ShipUpdateEscortFormation(JSContext *context, uintN argc, jsval *v
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
||||
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context);
|
||||
OOShipRegistry *registry = [OOShipRegistry sharedRegistry];
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
NSString *role = OOStringFromJSValue(context, OOJS_ARGV[0]);
|
||||
NSArray *keys = [registry shipKeysWithRole:role];
|
||||
OOJS_RETURN_OBJECT(keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
OOJSReportBadArguments(context, @"Ship", @"shipKeysForRole", MIN(argc, 1U), OOJS_ARGV, nil, @"ship role");
|
||||
return NO;
|
||||
}
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static BOOL RemoveOrExplodeShip(JSContext *context, uintN argc, jsval *vp, BOOL explode)
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
@ -2675,3 +2659,37 @@ static JSBool ShipOfferToEscort(JSContext *context, uintN argc, jsval *vp)
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
||||
|
||||
/** Static methods */
|
||||
|
||||
static JSBool ShipStaticKeys(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context);
|
||||
OOShipRegistry *registry = [OOShipRegistry sharedRegistry];
|
||||
|
||||
NSArray *keys = [registry shipKeys];
|
||||
OOJS_RETURN_OBJECT(keys);
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context);
|
||||
OOShipRegistry *registry = [OOShipRegistry sharedRegistry];
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
NSString *role = OOStringFromJSValue(context, OOJS_ARGV[0]);
|
||||
NSArray *keys = [registry shipKeysWithRole:role];
|
||||
OOJS_RETURN_OBJECT(keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
OOJSReportBadArguments(context, @"Ship", @"shipKeysForRole", MIN(argc, 1U), OOJS_ARGV, nil, @"ship role");
|
||||
return NO;
|
||||
}
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user