Added JS Ship properties cargoSpaceUsed, availableCargoSpace, passengerCount and passengerCapacity; renamed maxCargo to cargoCapacity (and added compatibility getter in prefix script).

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1693 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2008-07-15 14:50:25 +00:00
parent 51748cae1c
commit d5fad77a34
4 changed files with 41 additions and 37 deletions

View File

@ -116,7 +116,7 @@ this.defineCompatibilityWriteOnly = function (constructorName, oldName, funcName
{
let getter = function ()
{
special.jsWarning(constructorName + "." + oldName + " is deprecated and read-only.");
special.jsWarning(constructorName + "." + oldName + " is deprecated and write-only.");
return undefined;
}
let setter = function (value)
@ -154,3 +154,7 @@ system.setSunNova = function(delay)
special.jsWarning("system.setSunNova() is deprecated, use system.sun.goNova() instead.");
if (this.sun) this.sun.goNova(delay);
}
// To be removed after 1.73
this.defineCompatibilityGetter("Ship", "maxCargo", "cargoCapacity");

View File

@ -68,9 +68,6 @@ OOINLINE void quaternion_set_rotate_about_axis(Quaternion *quat, Vector axis, GL
/* Inner product of two quaternions */
OOINLINE GLfloat quaternion_dot_product(Quaternion q1, Quaternion q2) CONST_FUNC;
/* Create a rotation matrix from a quaternion. */
void quaternion_into_gl_matrix(Quaternion quat, GLfloat *glmat) NONNULL_FUNC;
/* Create basis vectors from a quaternion. */
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC;
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC;

View File

@ -58,34 +58,6 @@ void quaternion_set_random(Quaternion *quat)
}
void quaternion_into_gl_matrix(Quaternion quat, GLfloat *glmat)
{
GLfloat w, wz, wy, wx;
GLfloat x, xz, xy, xx;
GLfloat y, yz, yy;
GLfloat z, zz;
Quaternion q = quat;
quaternion_normalize(&q);
w = q.w;
z = q.z;
y = q.y;
x = q.x;
xx = 2.0f * x; yy = 2.0f * y; zz = 2.0f * z;
wx = w * xx; wy = w * yy; wz = w * zz;
xx = x * xx; xy = x * yy; xz = x * zz;
yy = y * yy; yz = y * zz;
zz = z * zz;
glmat[ 0] = 1.0f - yy - zz; glmat[ 4] = xy + wz; glmat[ 8] = xz - wy; glmat[12] = 0.0f;
glmat[ 1] = xy - wz; glmat[ 5] = 1.0f - xx - zz; glmat[ 9] = yz + wx; glmat[13] = 0.0f;
glmat[ 2] = xz + wy; glmat[ 6] = yz - wx; glmat[10] = 1.0f - xx - yy; glmat[14] = 0.0f;
glmat[ 3] = 0.0f; glmat[ 7] = 0.0f; glmat[11] = 0.0f; glmat[15] = 1.0f;
}
Vector vector_forward_from_quaternion(Quaternion quat)
{
GLfloat w, wy, wx;

View File

@ -113,7 +113,9 @@ enum
kShip_scannerRange, // scanner range, double, read-only
kShip_reportAIMessages, // report AI messages, boolean, read/write
kShip_withinStationAegis, // within main station aegis, boolean, read/write
kShip_maxCargo, // maximum cargo, integer, read-only
kShip_cargoCapacity, // free cargo space, integer, read-only
kShip_cargoSpaceUsed, // cargo on board, integer, read-only
kShip_availableCargoSpace, // maximum cargo, integer, read-only
kShip_speed, // current flight speed, double, read-only
kShip_desiredSpeed, // AI desired flight speed, double, read/write
kShip_maxSpeed, // maximum flight speed, double, read-only
@ -125,7 +127,10 @@ enum
kShip_isTrader, // is trader, boolean, read-only
kShip_isPirateVictim, // is pirate victim, boolean, read-only
kShip_scriptInfo, // arbitrary data for scripts, dictionary, read-only
kShip_trackCloseContacts // generate close contact events, boolean, read/write
kShip_trackCloseContacts, // generate close contact events, boolean, read/write
kShip_passengerCount, // number of passengers on ship, integer, read-only
kShip_passengerCapacity // amount of passenger space on ship, integer, read-only
};
@ -153,7 +158,10 @@ static JSPropertySpec sShipProperties[] =
{ "isPolice", kShip_isPolice, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "isThargoid", kShip_isThargoid, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "isTrader", kShip_isTrader, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "maxCargo", kShip_maxCargo, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
// "cargo" reserved for array of cargo pods or similar.
{ "cargoSpaceUsed", kShip_cargoSpaceUsed, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "cargoCapacity", kShip_cargoCapacity, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "availableCargoSpace", kShip_availableCargoSpace, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "maxSpeed", kShip_maxSpeed, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "potentialCollider", kShip_potentialCollider, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "primaryRole", kShip_primaryRole, JSPROP_PERMANENT | JSPROP_ENUMERATE },
@ -173,6 +181,9 @@ static JSPropertySpec sShipProperties[] =
{ "weaponRange", kShip_weaponRange, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "withinStationAegis", kShip_withinStationAegis, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "trackCloseContacts", kShip_trackCloseContacts, JSPROP_PERMANENT | JSPROP_ENUMERATE },
// "passengers" reserved for array of characters or similar.
{ "passengerCount", kShip_passengerCount, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "passengerCapacity", kShip_passengerCapacity, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ 0 }
};
@ -375,12 +386,22 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
*outValue = BOOLToJSVal([entity withinStationAegis]);
OK = YES;
break;
case kShip_maxCargo:
case kShip_cargoCapacity:
*outValue = INT_TO_JSVAL([entity maxCargo]);
OK = YES;
break;
case kShip_cargoSpaceUsed:
*outValue = INT_TO_JSVAL([entity maxCargo] - [entity availableCargoSpace]);
OK = YES;
break;
case kShip_availableCargoSpace:
*outValue = INT_TO_JSVAL([entity availableCargoSpace]);
OK = YES;
break;
case kShip_speed:
OK = JS_NewDoubleValue(context, [entity flightSpeed], outValue);
break;
@ -437,6 +458,16 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
*outValue = BOOLToJSVal([entity trackCloseContacts]);
OK = YES;
break;
case kShip_passengerCount:
*outValue = INT_TO_JSVAL([entity passengerCount]);
OK = YES;
break;
case kShip_passengerCapacity:
*outValue = INT_TO_JSVAL([entity passengerCapacity]);
OK = YES;
break;
default:
OOReportJSBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));