Set weaponRange to WEAPON_PLASMA_CANNON for ships only armed with plasma turrets. (Not necessarily exactly right, but much better than WEAPON_NONE)

Adjust behaviour a little when attacking a fleeing opponent.


git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4990 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Chris Morris 2012-06-06 17:42:23 +00:00
parent 9f22081e2b
commit 4623cad7d1

View File

@ -3572,12 +3572,22 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
// if forward weapon is actually on a subent // if forward weapon is actually on a subent
if (forward_weapon_real_type == WEAPON_NONE) if (forward_weapon_real_type == WEAPON_NONE)
{ {
BOOL hasTurrets = NO;
NSEnumerator *subEnum = [self shipSubEntityEnumerator]; NSEnumerator *subEnum = [self shipSubEntityEnumerator];
ShipEntity *se = nil; ShipEntity *se = nil;
while (forward_weapon_real_type == WEAPON_NONE && (se = [subEnum nextObject])) while (forward_weapon_real_type == WEAPON_NONE && (se = [subEnum nextObject]))
{ {
forward_weapon_real_type = se->forward_weapon_type; forward_weapon_real_type = se->forward_weapon_type;
forward_weapon_real_temp = se->forward_weapon_temp; forward_weapon_real_temp = se->forward_weapon_temp;
if (se->behaviour == BEHAVIOUR_TRACK_AS_TURRET)
{
hasTurrets = YES;
}
}
if (forward_weapon_real_type == WEAPON_NONE && hasTurrets)
{ // safety for ships only equipped with turrets
forward_weapon_real_type = WEAPON_PLASMA_CANNON;
forward_weapon_real_temp = COMBAT_AI_WEAPON_TEMP_USABLE * 0.9;
} }
} }
@ -3603,10 +3613,18 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
} }
ShipEntity* target = [UNIVERSE entityForUniversalID:primaryTarget]; ShipEntity* target = [UNIVERSE entityForUniversalID:primaryTarget];
double aspect = [self approachAspectToPrimaryTarget];
if (!forward_weapon_ready && !aft_weapon_ready && !port_weapon_ready && !starboard_weapon_ready) if (!forward_weapon_ready && !aft_weapon_ready && !port_weapon_ready && !starboard_weapon_ready)
{ // no usable weapons! Either not fitted or overheated { // no usable weapons! Either not fitted or overheated
// good pilots use behaviour_evasive_action instead
// if unarmed
if (forward_weapon_real_type == WEAPON_NONE && aft_weapon_type == WEAPON_NONE && port_weapon_type == WEAPON_NONE && starboard_weapon_type == WEAPON_NONE)
{
behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
}
else if (aspect > 0)
{
if (accuracy >= COMBAT_AI_IS_SMART && randf() < 0.75) if (accuracy >= COMBAT_AI_IS_SMART && randf() < 0.75)
{ {
behaviour = BEHAVIOUR_EVASIVE_ACTION; behaviour = BEHAVIOUR_EVASIVE_ACTION;
@ -3617,6 +3635,11 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET; behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
} }
} }
else // if target is running away, stay on target
{
behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
}
}
// if our current target isn't targeting us, and we have some idea of how to fight, and our weapons are running hot, and we're fairly nearby // if our current target isn't targeting us, and we have some idea of how to fight, and our weapons are running hot, and we're fairly nearby
else if (weapons_heating && accuracy >= COMBAT_AI_ISNT_AWFUL && [target primaryTargetID] != universalID && range < COMBAT_OUT_RANGE_FACTOR * weaponRange) else if (weapons_heating && accuracy >= COMBAT_AI_ISNT_AWFUL && [target primaryTargetID] != universalID && range < COMBAT_OUT_RANGE_FACTOR * weaponRange)
{ {
@ -3666,7 +3689,6 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
else if (forward_weapon_ready) else if (forward_weapon_ready)
{ {
jink = kZeroVector; // almost all behaviours jink = kZeroVector; // almost all behaviours
double aspect = [self approachAspectToPrimaryTarget];
// TODO: good pilots use behaviour_attack_sniper sometimes // TODO: good pilots use behaviour_attack_sniper sometimes
if (getWeaponRangeFromType(forward_weapon_real_type) > getWeaponRangeFromType(WEAPON_PULSE_LASER) && range > getWeaponRangeFromType(WEAPON_PULSE_LASER)) if (getWeaponRangeFromType(forward_weapon_real_type) > getWeaponRangeFromType(WEAPON_PULSE_LASER) && range > getWeaponRangeFromType(WEAPON_PULSE_LASER))
@ -4283,9 +4305,15 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
[self applyThrust:delta_t]; [self applyThrust:delta_t];
if (weapon_temp > COMBAT_AI_WEAPON_TEMP_USABLE && accuracy >= COMBAT_AI_ISNT_AWFUL) if (weapon_temp > COMBAT_AI_WEAPON_TEMP_USABLE && accuracy >= COMBAT_AI_ISNT_AWFUL)
{
double aspect = [self approachAspectToPrimaryTarget];
if (aspect < 0 || aft_weapon_type != WEAPON_NONE || port_weapon_type != WEAPON_NONE || starboard_weapon_type != WEAPON_NONE)
{ {
behaviour = BEHAVIOUR_ATTACK_TARGET; behaviour = BEHAVIOUR_ATTACK_TARGET;
} }
// don't do this if the target is fleeing and the front laser is
// the only weapon
}
} }
@ -8971,13 +8999,25 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
NSEnumerator *subEnum = [self shipSubEntityEnumerator]; NSEnumerator *subEnum = [self shipSubEntityEnumerator];
ShipEntity *se = nil; ShipEntity *se = nil;
OOWeaponType weapon_type = WEAPON_NONE; OOWeaponType weapon_type = WEAPON_NONE;
BOOL hasTurrets = NO;
while (weapon_type == WEAPON_NONE && (se = [subEnum nextObject])) while (weapon_type == WEAPON_NONE && (se = [subEnum nextObject]))
{ {
weapon_type = se->forward_weapon_type; weapon_type = se->forward_weapon_type;
weapon_temp = se->forward_weapon_temp; weapon_temp = se->forward_weapon_temp;
if (se->behaviour == BEHAVIOUR_TRACK_AS_TURRET)
{
hasTurrets = YES;
} }
}
if (weapon_type == WEAPON_NONE && hasTurrets)
{ // no forward weapon but has turrets, so set up range calculations accordingly
[self setWeaponDataFromType:WEAPON_PLASMA_CANNON];
}
else
{
[self setWeaponDataFromType:weapon_type]; [self setWeaponDataFromType:weapon_type];
} }
}
return result; return result;
} }