JS: replaced Player.legalStatus with Ship.bounty. Tweaks.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1121 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-08-02 20:46:46 +00:00
parent 6fe5f8347f
commit ef9a6751d3
9 changed files with 51 additions and 51 deletions

View File

@ -329,7 +329,7 @@ typedef enum
unsigned max_missiles; // no. of missile pylons unsigned max_missiles; // no. of missile pylons
ShipEntity *missile_entity[SHIPENTITY_MAX_MISSILES]; // holds the actual missile entities or equivalents ShipEntity *missile_entity[SHIPENTITY_MAX_MISSILES]; // holds the actual missile entities or equivalents
int legalStatus; int legalStatus;
int market_rnd; int market_rnd;
unsigned ship_kills; unsigned ship_kills;

View File

@ -3235,7 +3235,6 @@ double scoopSoundPlayTime = 0.0;
//has_escape_pod = NO; //has_escape_pod = NO;
// reset legal status // reset legal status
legalStatus = 0;
bounty = 0; bounty = 0;
// reset trumbles // reset trumbles
@ -3302,7 +3301,7 @@ double scoopSoundPlayTime = 0.0;
int i; int i;
for (i = 1; i < (n_cargo - rotates); i++) for (i = 1; i < (n_cargo - rotates); i++)
{ {
pod = (ShipEntity*)[cargo objectAtIndex:i]; pod = [cargo objectAtIndex:i];
if ([pod commodityType] == current_contents) if ([pod commodityType] == current_contents)
{ {
[pod retain]; [pod retain];
@ -3312,7 +3311,12 @@ double scoopSoundPlayTime = 0.0;
rotates++; rotates++;
} }
} }
}
- (void) setBounty:(OOCreditsQuantity) amount
{
legalStatus = amount;
} }

View File

@ -37,9 +37,6 @@ MA 02110-1301, USA.
- (double) creditBalance; - (double) creditBalance;
- (void) setCreditBalance:(double)value; - (void) setCreditBalance:(double)value;
- (int) legalStatus;
- (void) setLegalStatusValue:(int)value; // NOTE: setLegalStatus: is a legacy script method and takes a string.
- (float)fuelLeakRate; - (float)fuelLeakRate;
- (void)setFuelLeakRate:(float)value; - (void)setFuelLeakRate:(float)value;

View File

@ -60,17 +60,6 @@ MA 02110-1301, USA.
credits = OOClamp_0_max_d(value, (double)ULONG_MAX); credits = OOClamp_0_max_d(value, (double)ULONG_MAX);
} }
- (int) legalStatus
{
return legalStatus;
}
- (void) setLegalStatusValue:(int)value
{
legalStatus = value;
}
- (float)fuelLeakRate - (float)fuelLeakRate
{ {

View File

@ -414,6 +414,7 @@ MA 02110-1301, USA.
- (void) setBounty:(OOCreditsQuantity) amount; - (void) setBounty:(OOCreditsQuantity) amount;
- (OOCreditsQuantity) bounty; - (OOCreditsQuantity) bounty;
- (int) legalStatus; - (int) legalStatus;
- (void) setCommodity:(OOCargoType)co_type andAmount:(OOCargoQuantity)co_amount; - (void) setCommodity:(OOCargoType)co_type andAmount:(OOCargoQuantity)co_amount;

View File

@ -79,9 +79,7 @@ enum
// Property IDs // Property IDs
kEntity_ID, // universalID, int, read-only kEntity_ID, // universalID, int, read-only
kEntity_position, // position in system space, Vector, read-only kEntity_position, // position in system space, Vector, read-only
kEntity_velocity, // velocity, Vector, read-only kEntity_orientation, // orientation, quaternion, read-write
kEntity_speed, // speed, double, read-only (magnitude of velocity)
kEntity_orientation, // orientation, quaternion, read-write (unimplemented)
kEntity_heading, // heading, vector, read-only (like orientation but ignoring twist angle) kEntity_heading, // heading, vector, read-only (like orientation but ignoring twist angle)
kEntity_status, // entity status, string, read-only kEntity_status, // entity status, string, read-only
kEntity_scanClass, // scan class, string, read-only kEntity_scanClass, // scan class, string, read-only
@ -97,8 +95,6 @@ static JSPropertySpec sEntityProperties[] =
// JS name ID flags // JS name ID flags
{ "ID", kEntity_ID, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "ID", kEntity_ID, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "position", kEntity_position, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "position", kEntity_position, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "velocity", kEntity_velocity, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "speed", kEntity_speed, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "orientation", kEntity_orientation, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "orientation", kEntity_orientation, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "heading", kEntity_heading, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "heading", kEntity_heading, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "status", kEntity_status, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "status", kEntity_status, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
@ -279,14 +275,6 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name,
VectorToJSValue(context, [entity position], outValue); VectorToJSValue(context, [entity position], outValue);
break; break;
case kEntity_velocity:
VectorToJSValue(context, [entity velocity], outValue);
break;
case kEntity_speed:
JS_NewDoubleValue(context, magnitude([entity velocity]), outValue);
break;
case kEntity_orientation: case kEntity_orientation:
QuaternionToJSValue(context, [entity orientation], outValue); QuaternionToJSValue(context, [entity orientation], outValue);
break; break;
@ -309,11 +297,8 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name,
case kEntity_owner: case kEntity_owner:
result = [entity owner]; result = [entity owner];
if (result == entity) if (result == entity) result = nil;
{ if (result == nil) *outValue = JSVAL_NULL;
result = nil;
*outValue = JSVAL_NULL;
}
break; break;
case kEntity_energy: case kEntity_energy:

View File

@ -79,7 +79,7 @@ enum
kPlayer_name, // Player name, string, read-only kPlayer_name, // Player name, string, read-only
kPlayer_score, // kill count, integer, read/write kPlayer_score, // kill count, integer, read/write
kPlayer_credits, // credit balance, float, read/write kPlayer_credits, // credit balance, float, read/write
kPlayer_legalStatus, // legal status, integer, read/write kPlayer_legalStatus, // Deprecated synonym for bounty
kPlayer_fuelLeakRate, // fuel leak rate, float, read/write kPlayer_fuelLeakRate, // fuel leak rate, float, read/write
kPlayer_alertCondition, // alert level, integer, read-only kPlayer_alertCondition, // alert level, integer, read-only
kPlayer_docked, // docked, boolean, read-only kPlayer_docked, // docked, boolean, read-only
@ -207,6 +207,7 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsval name,
break; break;
case kPlayer_legalStatus: case kPlayer_legalStatus:
OOReportJavaScriptWarning(context, @"Player.%@ is deprecated, use Player.%@ instead.", @"legalStatus", @"bounty");
*outValue = INT_TO_JSVAL([player legalStatus]); *outValue = INT_TO_JSVAL([player legalStatus]);
break; break;
@ -227,12 +228,12 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsval name,
break; break;
case kPlayer_dockedStationName: case kPlayer_dockedStationName:
OOReportJavaScriptWarning(context, @"Player.dockedStationName is deprecated, use Player.dockedStation.shipDescription instead."); OOReportJavaScriptWarning(context, @"Player.%@ is deprecated, use Player.%@ instead.", @"dockedStationName", @"dockedStation.shipDescription");
result = [player dockedStationName]; result = [player dockedStationName];
break; break;
case kPlayer_dockedAtMainStation: case kPlayer_dockedAtMainStation:
OOReportJavaScriptWarning(context, @"Player.dockedAtMainStation is deprecated, use Player.dockedStation.isMainStation instead."); OOReportJavaScriptWarning(context, @"Player.%@ is deprecated, use Player.%@ instead.", @"dockedAtMainStation", @"dockedStation.isMainStation");
*outValue = BOOLToJSVal([player dockedAtMainStation]); *outValue = BOOLToJSVal([player dockedAtMainStation]);
break; break;
@ -284,9 +285,10 @@ static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsval name,
break; break;
case kPlayer_legalStatus: case kPlayer_legalStatus:
if (JS_ValueToInt32(context, *value, &iValue)) OOReportJavaScriptWarning(context, @"Player.%@ is deprecated, use Player.%@ instead.", @"legalStatus", @"bounty");
if (JS_ValueToInt32(context, *value, &iValue) && 0 < iValue)
{ {
[player setLegalStatusValue:iValue]; [player setBounty:iValue];
} }
break; break;

View File

@ -73,7 +73,8 @@ enum
kShip_roles, // roles, array, read-only kShip_roles, // roles, array, read-only
kShip_AI, // AI state machine name, string, read/write kShip_AI, // AI state machine name, string, read/write
kShip_AIState, // AI state machine state, string, read/write kShip_AIState, // AI state machine state, string, read/write
kShip_fuel // fuel, float, read/write kShip_fuel, // fuel, float, read/write
kShip_bounty // bounty, unsigned int, read/write
}; };
@ -85,6 +86,7 @@ static JSPropertySpec sShipProperties[] =
{ "AI", kShip_AI, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "AI", kShip_AI, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "AIState", kShip_AIState, JSPROP_PERMANENT | JSPROP_ENUMERATE }, { "AIState", kShip_AIState, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "fuel", kShip_fuel, JSPROP_PERMANENT | JSPROP_ENUMERATE }, { "fuel", kShip_fuel, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "bounty", kShip_bounty, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ 0 } { 0 }
}; };
@ -159,10 +161,14 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
case kShip_AIState: case kShip_AIState:
result = [[entity getAI] state]; result = [[entity getAI] state];
break; break;
case kShip_fuel: case kShip_fuel:
JS_NewDoubleValue(context, [entity fuel] * 0.1, outValue); JS_NewDoubleValue(context, [entity fuel] * 0.1, outValue);
break; break;
case kShip_bounty:
*outValue = INT_TO_JSVAL([entity legalStatus]);
break;
default: default:
OOReportJavaScriptBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name)); OOReportJavaScriptBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));
@ -178,25 +184,41 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
{ {
ShipEntity *entity = nil; ShipEntity *entity = nil;
NSString *strVal = nil; NSString *strVal = nil;
BOOL validConversion;
jsdouble fValue; jsdouble fValue;
int32 iValue;
if (!JSVAL_IS_INT(name)) return YES;
if (!JSShipGetShipEntity(context, this, &entity)) return NO;
switch (name) switch (name)
{ {
case kShip_AIState: case kShip_AIState:
strVal = [NSString stringWithJavaScriptValue:*value inContext:context]; if (entity->isPlayer)
if (strVal != nil) [[entity getAI] setState:strVal]; {
OOReportJavaScriptError(context, @"Ship.AIState [setter]: cannot set AI state for player.");
}
else
{
strVal = [NSString stringWithJavaScriptValue:*value inContext:context];
if (strVal != nil) [[entity getAI] setState:strVal];
}
break; break;
case kShip_fuel: case kShip_fuel:
validConversion = JS_ValueToNumber(context, *value, &fValue); if (JS_ValueToNumber(context, *value, &fValue))
if (validConversion)
{ {
fValue = OOClamp_0_max_d(fValue, 7.0); fValue = OOClamp_0_max_d(fValue, 7.0);
[entity setFuel:lround(fValue * 10.0)]; [entity setFuel:lround(fValue * 10.0)];
} }
break; break;
case kShip_bounty:
if (JS_ValueToInt32(context, *value, &iValue) && 0 < iValue)
{
[entity setBounty:iValue];
}
break;
default: default:
OOReportJavaScriptBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name)); OOReportJavaScriptBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));
return NO; return NO;

View File

@ -63,14 +63,14 @@ static JSExtendedClass sStationClass =
enum enum
{ {
// Property IDs // Property IDs
kStation_isMain // Is [UNIVERSE station], boolean, read-only kStation_isMainStation // Is [UNIVERSE station], boolean, read-only
}; };
static JSPropertySpec sStationProperties[] = static JSPropertySpec sStationProperties[] =
{ {
// JS name ID flags // JS name ID flags
{ "isMain", kStation_isMain, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }, { "isMainStation", kStation_isMainStation, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ 0 } { 0 }
}; };
@ -133,7 +133,7 @@ static JSBool StationGetProperty(JSContext *context, JSObject *this, jsval name,
switch (JSVAL_TO_INT(name)) switch (JSVAL_TO_INT(name))
{ {
case kStation_isMain: case kStation_isMainStation:
*outValue = BOOLToJSVal(entity == [UNIVERSE station]); *outValue = BOOLToJSVal(entity == [UNIVERSE station]);
break; break;