Changes in AI behaviour when attacking NO_TARGET.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1924 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
cmdrjames 2008-12-27 22:49:14 +00:00
parent 2db3ee11d3
commit c750cd46c8
3 changed files with 43 additions and 32 deletions

View File

@ -252,24 +252,23 @@ FAIL:
[self release]; [self release];
return nil; return nil;
} }
Vector offset, scale; Vector offset;
offset.x = [values floatAtIndex:0]; offset.x = [values floatAtIndex:0];
offset.y = [values floatAtIndex:1]; offset.y = [values floatAtIndex:1];
offset.z = [values floatAtIndex:2]; offset.z = [values floatAtIndex:2];
position = offset;
Vector scale;
scale.x = [values floatAtIndex:3]; scale.x = [values floatAtIndex:3];
scale.y = [values floatAtIndex:4]; scale.y = [values floatAtIndex:4];
scale.z = [values floatAtIndex:5]; scale.z = [values floatAtIndex:5];
status = STATUS_EFFECT;
exhaustScale = scale; exhaustScale = scale;
position = offset; status = STATUS_EFFECT;
particle_type = PARTICLE_EXHAUST; particle_type = PARTICLE_EXHAUST;
[self setOwner:ship]; [self setOwner:ship];
isParticle = YES; isParticle = YES;
} }
@ -771,14 +770,9 @@ FAIL:
rotMatrix = [player drawRotationMatrix]; rotMatrix = [player drawRotationMatrix];
} }
break; break;
default:
case PARTICLE_LASER_BEAM:
case PARTICLE_EXHAUST:
case PARTICLE_ECM_MINE:
case PARTICLE_ENERGY_MINE:
case PARTICLE_BILLBOARD:
case PARTICLE_HYPERRING:
break; break;
} }
switch ([self particleType]) switch ([self particleType])
{ {
@ -1102,7 +1096,7 @@ FAIL:
#define OVERALL_ALPHA 1.0f #define OVERALL_ALPHA 1.0f
#endif #endif
GLfloat ex_emissive[4] = {0.6, 0.8, 1.0, 0.9 * OVERALL_ALPHA}; // pale blue GLfloat ex_emissive[4] = {0.6f, 0.8f, 1.0f, 0.9f * OVERALL_ALPHA}; // pale blue
const GLfloat s1[8] = { 0.0, 0.707, 1.0, 0.707, 0.0, -0.707, -1.0, -0.707}; const GLfloat s1[8] = { 0.0, 0.707, 1.0, 0.707, 0.0, -0.707, -1.0, -0.707};
const GLfloat c1[8] = { 1.0, 0.707, 0.0, -0.707, -1.0, -0.707, 0.0, 0.707}; const GLfloat c1[8] = { 1.0, 0.707, 0.0, -0.707, -1.0, -0.707, 0.0, 0.707};
ShipEntity *ship = [self owner]; ShipEntity *ship = [self owner];
@ -1140,7 +1134,7 @@ FAIL:
if ((int)(ranrot_rand() % 25) < dam - 75) if ((int)(ranrot_rand() % 25) < dam - 75)
flare_factor = 0.0; flare_factor = 0.0;
if (flare_length < 0.1) flare_length = 0.1; if (flare_length < 0.1) { flare_length = 0.1;}
Vector currentPos = ship->position; Vector currentPos = ship->position;
Vector vfwd = vector_forward_from_quaternion(shipQrotation); Vector vfwd = vector_forward_from_quaternion(shipQrotation);
GLfloat spd = 0.5 * [ship flightSpeed]; GLfloat spd = 0.5 * [ship flightSpeed];
@ -1206,9 +1200,9 @@ FAIL:
j1.x *= exhaustScale.y; j1.y *= exhaustScale.y; j1.z *= exhaustScale.y; j1.x *= exhaustScale.y; j1.y *= exhaustScale.y; j1.z *= exhaustScale.y;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
verts[iv++] = f01.position.x + b01.x + s1[i] * i1.x + c1[i] * j1.x; verts[iv++] = f01.position.x + b01.x + s1[i] * i1.x + c1[i] * j1.x;
verts[iv++] = f01.position.y + b01.y + s1[i] * i1.y + c1[i] * j1.y; verts[iv++] = f01.position.y + b01.y + s1[i] * i1.y + c1[i] * j1.y;
verts[iv++] = f01.position.z + b01.z + s1[i] * i1.z + c1[i] * j1.z; verts[iv++] = f01.position.z + b01.z + s1[i] * i1.z + c1[i] * j1.z;
exhaustBaseColors[ci++] = ex_emissive[0]; exhaustBaseColors[ci++] = ex_emissive[0];
exhaustBaseColors[ci++] = ex_emissive[1]; exhaustBaseColors[ci++] = ex_emissive[1];
exhaustBaseColors[ci++] = ex_emissive[2]; exhaustBaseColors[ci++] = ex_emissive[2];
@ -1226,9 +1220,9 @@ FAIL:
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
r1 = randf(); r1 = randf();
verts[iv++] = f03.position.x + b03.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x; verts[iv++] = f03.position.x + b03.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x;
verts[iv++] = f03.position.y + b03.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y; verts[iv++] = f03.position.y + b03.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y;
verts[iv++] = f03.position.z + b03.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z; verts[iv++] = f03.position.z + b03.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z;
exhaustBaseColors[ci++] = ex_emissive[0]; exhaustBaseColors[ci++] = ex_emissive[0];
exhaustBaseColors[ci++] = ex_emissive[1]; exhaustBaseColors[ci++] = ex_emissive[1];
exhaustBaseColors[ci++] = ex_emissive[2]; exhaustBaseColors[ci++] = ex_emissive[2];
@ -1246,9 +1240,9 @@ FAIL:
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
r1 = randf(); r1 = randf();
verts[iv++] = f06.position.x + b06.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x; verts[iv++] = f06.position.x + b06.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x;
verts[iv++] = f06.position.y + b06.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y; verts[iv++] = f06.position.y + b06.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y;
verts[iv++] = f06.position.z + b06.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z; verts[iv++] = f06.position.z + b06.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z;
exhaustBaseColors[ci++] = ex_emissive[0]; exhaustBaseColors[ci++] = ex_emissive[0];
exhaustBaseColors[ci++] = ex_emissive[1]; exhaustBaseColors[ci++] = ex_emissive[1];
exhaustBaseColors[ci++] = ex_emissive[2]; exhaustBaseColors[ci++] = ex_emissive[2];
@ -1266,9 +1260,9 @@ FAIL:
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
r1 = randf(); r1 = randf();
verts[iv++] = f08.position.x + b08.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x; verts[iv++] = f08.position.x + b08.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x;
verts[iv++] = f08.position.y + b08.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y; verts[iv++] = f08.position.y + b08.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y;
verts[iv++] = f08.position.z + b08.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z; verts[iv++] = f08.position.z + b08.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z;
exhaustBaseColors[ci++] = ex_emissive[0]; exhaustBaseColors[ci++] = ex_emissive[0];
exhaustBaseColors[ci++] = ex_emissive[1]; exhaustBaseColors[ci++] = ex_emissive[1];
exhaustBaseColors[ci++] = ex_emissive[2]; exhaustBaseColors[ci++] = ex_emissive[2];
@ -1354,7 +1348,7 @@ FAIL:
Entity *my_owner = [self owner]; Entity *my_owner = [self owner];
if (my_owner) if ([self isSubEntity] && my_owner)
{ {
// this test provides an opportunity to do simple LoD culling // this test provides an opportunity to do simple LoD culling

View File

@ -563,7 +563,9 @@ MA 02110-1301, USA.
- (GLfloat) heatInsulation; - (GLfloat) heatInsulation;
- (void) setHeatInsulation:(GLfloat) value; - (void) setHeatInsulation:(GLfloat) value;
// the percentage of damage taken (100 is destroyed, 0 is fine)
- (int) damage; - (int) damage;
- (void) dealEnergyDamageWithinDesiredRange; - (void) dealEnergyDamageWithinDesiredRange;
- (void) dealMomentumWithinDesiredRange:(double)amount; - (void) dealMomentumWithinDesiredRange:(double)amount;
@ -641,6 +643,8 @@ BOOL class_masslocks(int some_class);
- (double) trackPrimaryTarget:(double) delta_t :(BOOL) retreat; - (double) trackPrimaryTarget:(double) delta_t :(BOOL) retreat;
- (double) missileTrackPrimaryTarget:(double) delta_t; - (double) missileTrackPrimaryTarget:(double) delta_t;
//return 0.0 if there is no primary target
- (double) rangeToPrimaryTarget; - (double) rangeToPrimaryTarget;
- (BOOL) onTarget:(BOOL) fwd_weapon; - (BOOL) onTarget:(BOOL) fwd_weapon;

View File

@ -2233,7 +2233,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{ {
[self avoidCollision]; [self avoidCollision];
} }
if (range > SCANNER_MAX_RANGE) if (range > SCANNER_MAX_RANGE || primaryTarget == NO_TARGET)
{ {
behaviour = BEHAVIOUR_IDLE; behaviour = BEHAVIOUR_IDLE;
frustration = 0.0; frustration = 0.0;
@ -2303,7 +2303,13 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
- (void) behaviour_attack_mining_target:(double) delta_t - (void) behaviour_attack_mining_target:(double) delta_t
{ {
double range = [self rangeToPrimaryTarget]; double range = [self rangeToPrimaryTarget];
if ((range < 650)||(proximity_alert != NO_TARGET)) if (primaryTarget == NO_TARGET || range > SCANNER_MAX_RANGE)
{
[self noteLostTarget];
desired_speed = maxFlightSpeed * 0.375;
return;
}
else if ((range < 650) || (proximity_alert != NO_TARGET))
{ {
if (proximity_alert == NO_TARGET) if (proximity_alert == NO_TARGET)
{ {
@ -2316,9 +2322,10 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
} }
else else
{ {
if (range > SCANNER_MAX_RANGE) [self noteLostTarget]; //we have a target, its within scanner range, and outside 650
desired_speed = maxFlightSpeed * 0.375; desired_speed = maxFlightSpeed * 0.375;
} }
[self trackPrimaryTarget:delta_t:NO]; [self trackPrimaryTarget:delta_t:NO];
[self fireMainWeapon:range]; [self fireMainWeapon:range];
[self applyRoll:delta_t*flightRoll andClimb:delta_t*flightPitch]; [self applyRoll:delta_t*flightRoll andClimb:delta_t*flightPitch];
@ -2332,7 +2339,13 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
float max_available_speed = maxFlightSpeed; float max_available_speed = maxFlightSpeed;
double range = [self rangeToPrimaryTarget]; double range = [self rangeToPrimaryTarget];
if (canBurn) max_available_speed *= [self afterburnerFactor]; if (canBurn) max_available_speed *= [self afterburnerFactor];
if (primaryTarget == NO_TARGET)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
return;
}
if ((range < COMBAT_IN_RANGE_FACTOR * weaponRange)||(proximity_alert != NO_TARGET)) if ((range < COMBAT_IN_RANGE_FACTOR * weaponRange)||(proximity_alert != NO_TARGET))
{ {
if (proximity_alert == NO_TARGET) if (proximity_alert == NO_TARGET)