Expose individual weapon mount temperatures (readonly!) to script for both player and NPC

Move laserHeatLevel from PlayerShip to Ship


git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5047 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Chris Morris 2012-07-04 21:08:38 +00:00
parent db97576119
commit ae014d1496
5 changed files with 109 additions and 3 deletions

View File

@ -386,6 +386,10 @@
"damage",
"weaponRecoveryTime",
"laserHeatLevel",
"laserHeatLevelAft",
"laserHeatLevelForward",
"laserHeatLevelPort",
"laserHeatLevelStarboard",
"hullHeatLevel",
"entityPersonality",
"entityPersonalityInt",

View File

@ -3252,6 +3252,37 @@ static GLfloat sBaseMass = 0.0;
}
- (GLfloat)laserHeatLevelAft
{
GLfloat result = aft_weapon_temp / (GLfloat)PLAYER_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelForward
{
GLfloat result = forward_weapon_temp / (GLfloat)PLAYER_MAX_WEAPON_TEMP;
// no need to check subents here
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelPort
{
GLfloat result = port_weapon_temp / PLAYER_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelStarboard
{
GLfloat result = starboard_weapon_temp / PLAYER_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}
- (GLfloat) dialAltitude
{
if ([self isDocked]) return 0.0f;

View File

@ -875,6 +875,10 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
- (GLfloat)weaponRecoveryTime;
- (GLfloat)laserHeatLevel;
- (GLfloat)laserHeatLevelAft;
- (GLfloat)laserHeatLevelForward;
- (GLfloat)laserHeatLevelPort;
- (GLfloat)laserHeatLevelStarboard;
- (GLfloat)hullHeatLevel;
- (GLfloat)entityPersonality;
- (GLint)entityPersonalityInt;

View File

@ -7865,7 +7865,49 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
- (GLfloat)laserHeatLevel
{
float result = weapon_temp / NPC_MAX_WEAPON_TEMP;
GLfloat result = weapon_temp / NPC_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelAft
{
GLfloat result = aft_weapon_temp / NPC_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelForward
{
GLfloat result = forward_weapon_temp / NPC_MAX_WEAPON_TEMP;
if (forward_weapon_type == WEAPON_NONE)
{ // must check subents
OOWeaponType forward_weapon_real_type = WEAPON_NONE;
NSEnumerator *subEnum = [self shipSubEntityEnumerator];
ShipEntity *se = nil;
while (forward_weapon_real_type == WEAPON_NONE && (se = [subEnum nextObject]))
{
if (se->forward_weapon_type != WEAPON_NONE)
{
forward_weapon_real_type = se->forward_weapon_type;
result = se->forward_weapon_temp / NPC_MAX_WEAPON_TEMP;
}
}
}
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelPort
{
GLfloat result = port_weapon_temp / NPC_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}
- (GLfloat)laserHeatLevelStarboard
{
GLfloat result = starboard_weapon_temp / NPC_MAX_WEAPON_TEMP;
return OOClamp_0_1_f(result);
}

View File

@ -165,6 +165,11 @@ enum
kShip_isThargoid, // is thargoid, boolean, read-only
kShip_isTrader, // is trader, boolean, read-only
kShip_isWeapon, // is missile or mine, boolean, read-only
kShip_laserHeatLevel, // active laser temperature, float, read-only
kShip_laserHeatLevelAft, // aft laser temperature, float, read-only
kShip_laserHeatLevelForward, // fore laser temperature, float, read-only
kShip_laserHeatLevelPort, // port laser temperature, float, read-only
kShip_laserHeatLevelStarboard, // starboard laser temperature, float, read-only
kShip_lightsActive, // flasher/shader light flag, boolean, read/write
kShip_maxSpeed, // maximum flight speed, double, read-only
kShip_maxThrust, // maximum thrust, double, read-only
@ -264,6 +269,11 @@ static JSPropertySpec sShipProperties[] =
{ "isThargoid", kShip_isThargoid, OOJS_PROP_READONLY_CB },
{ "isTrader", kShip_isTrader, OOJS_PROP_READONLY_CB },
{ "isWeapon", kShip_isWeapon, OOJS_PROP_READONLY_CB },
{ "laserHeatLevel", kShip_laserHeatLevel, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelAft", kShip_laserHeatLevelAft, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelForward", kShip_laserHeatLevelForward, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelPort", kShip_laserHeatLevelPort, OOJS_PROP_READONLY_CB },
{ "laserHeatLevelStarboard", kShip_laserHeatLevelStarboard, OOJS_PROP_READONLY_CB },
{ "lightsActive", kShip_lightsActive, OOJS_PROP_READWRITE_CB },
{ "maxSpeed", kShip_maxSpeed, OOJS_PROP_READONLY_CB },
{ "maxThrust", kShip_maxThrust, OOJS_PROP_READONLY_CB },
@ -692,13 +702,28 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
result = [entity weaponTypeForFacing:WEAPON_FACING_AFT];
break;
case kShip_portWeapon: // for future expansion
case kShip_portWeapon:
result = [entity weaponTypeForFacing:WEAPON_FACING_PORT];
break;
case kShip_starboardWeapon: // for future expansion
case kShip_starboardWeapon:
result = [entity weaponTypeForFacing:WEAPON_FACING_STARBOARD];
break;
case kShip_laserHeatLevel:
return JS_NewNumberValue(context, [entity laserHeatLevel], value);
case kShip_laserHeatLevelAft:
return JS_NewNumberValue(context, [entity laserHeatLevelAft], value);
case kShip_laserHeatLevelForward:
return JS_NewNumberValue(context, [entity laserHeatLevelForward], value);
case kShip_laserHeatLevelPort:
return JS_NewNumberValue(context, [entity laserHeatLevelPort], value);
case kShip_laserHeatLevelStarboard:
return JS_NewNumberValue(context, [entity laserHeatLevelStarboard], value);
case kShip_missiles:
result = [entity missilesList];