some changes to behaviour

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@628 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Giles Williams 2006-06-30 09:18:09 +00:00
parent 2aa9a99f9b
commit 0ba89633c7
2 changed files with 66 additions and 1 deletions

View File

@ -356,6 +356,11 @@ Your fair use and other rights are in no way affected by the above.
ShipEntity* scanned_ships[MAX_SCAN_NUMBER];
GLfloat distance2_scanned_ships[MAX_SCAN_NUMBER];
int n_scanned_ships;
// advanced navigation
Vector navpoints[32];
int next_navpoint_index;
int number_of_navpoints;
// DEBUGGING
int debug_flag;
@ -429,6 +434,8 @@ Your fair use and other rights are in no way affected by the above.
// //
- (void) behaviour_track_as_turret:(double) delta_t;
// //
- (void) behaviour_fly_thru_navpoints:(double) delta_t;
// //
- (void) behaviour_experimental:(double) delta_t;
// //
////////////////

View File

@ -2818,7 +2818,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
if (distance < last_distance) // improvement
{
frustration -= delta_t;
frustration -= 0.25 * delta_t;
if (frustration < 0.0)
frustration = 0.0;
}
@ -2903,6 +2903,64 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
}
// //
- (void) behaviour_fly_thru_navpoints:(double) delta_t
{
int navpoint_plus_index = (next_navpoint_index + 1) % number_of_navpoints;
Vector d1 = navpoints[ next_navpoint_index]; // head for this one
Vector d2 = navpoints[ navpoint_plus_index]; // but be facing this one
Vector rel = vector_between(d1, position);
Vector ref = vector_between(d2, d1);
ref = unit_vector(&ref);
GLfloat r1 = dot_product( rel, ref);
GLfloat distance = sqrtf(magnitude2(rel));
if (distance < desired_range)
{
// desired range achieved
[shipAI reactToMessage:@"NAVPOINT_REACHED"];
if (navpoint_plus_index == 0)
[shipAI reactToMessage:@"ENDPOINT_REACHED"];
next_navpoint_index = navpoint_plus_index; // loop as required
}
else
{
double last_success_factor = success_factor;
double last_distance = last_success_factor;
success_factor = distance;
// set destination spline point from r1 and ref
destination = make_vector( d1.x + r1 * ref.x, d1.y + r1 * ref.y, d1.z + r1 * ref.z);
// do the actual piloting!!
[self trackDestination:delta_t: NO];
// keep speed as is
if (distance < last_distance) // improvement
{
frustration -= delta_t;
if (frustration < 0.0)
frustration = 0.0;
}
else
{
frustration += delta_t;
if (frustration > 15.0) // 15s of frustration
{
[shipAI reactToMessage:@"FRUSTRATED"];
frustration -= 15.0; //repeat after another 15s of frustration
}
}
}
// if ((proximity_alert != NO_TARGET)&&(proximity_alert != primaryTarget))
// [self avoidCollision];
[self applyRoll:delta_t*flight_roll andClimb:delta_t*flight_pitch];
[self applyThrust:delta_t];
}
// //
- (void) behaviour_experimental:(double) delta_t
{
double aim = [self ballTrackTarget:delta_t];