From 0ba89633c7f4db4c76cb34e7c30734633e1e009a Mon Sep 17 00:00:00 2001 From: Giles Williams Date: Fri, 30 Jun 2006 09:18:09 +0000 Subject: [PATCH] some changes to behaviour git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@628 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/ShipEntity.h | 7 +++++ src/Core/ShipEntity.m | 60 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Core/ShipEntity.h b/src/Core/ShipEntity.h index 5be0dd39..8545a838 100644 --- a/src/Core/ShipEntity.h +++ b/src/Core/ShipEntity.h @@ -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; // // //////////////// diff --git a/src/Core/ShipEntity.m b/src/Core/ShipEntity.m index e6c0711e..160543b8 100644 --- a/src/Core/ShipEntity.m +++ b/src/Core/ShipEntity.m @@ -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];