diff --git a/src/karts/controller/default_ai_controller.cpp b/src/karts/controller/default_ai_controller.cpp index 6f9e91ae4..a3365dd0e 100644 --- a/src/karts/controller/default_ai_controller.cpp +++ b/src/karts/controller/default_ai_controller.cpp @@ -46,8 +46,7 @@ #include "tracks/track.hpp" #include "utils/constants.hpp" -DefaultAIController::DefaultAIController(Kart *kart, unsigned int kart_id) - : AIBaseController(kart) +DefaultAIController::DefaultAIController(Kart *kart) : AIBaseController(kart) { m_next_node_index.reserve(m_quad_graph->getNumNodes()); m_successor_index.reserve(m_quad_graph->getNumNodes()); @@ -89,23 +88,6 @@ DefaultAIController::DefaultAIController(Kart *kart, unsigned int kart_id) // Reset must be called after m_quad_graph etc. is set up reset(); - float variation = m_kart->getKartProperties()->getAISteeringVariation(); - unsigned int num_ai_karts = race_manager->getNumberOfKarts() - - race_manager->getNumPlayers(); - if(num_ai_karts==1) - { - m_steering_variation = 0; - } - else - { - m_steering_variation = 2*kart_id /(num_ai_karts-1) - 1.0f; - } - - // The steering varition gets further adjusted by AI level - - // higher level AI will have less variation --> more potential - // slipstreaming. - m_steering_variation *= m_kart->getKartProperties()->getAISteeringVariation(); - switch( race_manager->getDifficulty()) { case RaceManager::RD_EASY: @@ -145,7 +127,6 @@ DefaultAIController::DefaultAIController(Kart *kart, unsigned int kart_id) m_min_steps = 2; m_nitro_level = NITRO_ALL; m_handle_bomb = true; - m_steering_variation *= 0.5f; setSkiddingFraction(2.0f); break; } @@ -517,9 +498,6 @@ void DefaultAIController::handleItems( const float DELTA, const int STEPS ) break; case PowerupManager::POWERUP_BUBBLEGUM: - // Avoid dropping all bubble gums one after another - if( m_time_since_last_shot >3.0f) break; - // Either use the bubble gum after 10 seconds, or if the next kart // behind is 'close' but not too close (too close likely means that the // kart is not behind but more to the side of this kart and so won't @@ -527,17 +505,15 @@ void DefaultAIController::handleItems( const float DELTA, const int STEPS ) // kart as well? I.e. only drop if the kart behind is faster? Otoh // this approach helps preventing an overtaken kart to overtake us // again. - // Don't drop bubble gums too quickly, wait at least three seconds m_controls->m_fire = (m_distance_behind < 15.0f && - m_distance_behind > 3.0f ); + m_distance_behind > 3.0f ) || + m_time_since_last_shot>10.0f; break; // All the thrown/fired items might be improved by considering the angle // towards m_kart_ahead. And some of them can fire backwards, too - which // isn't yet supported for AI karts. case PowerupManager::POWERUP_CAKE: { - // Leave some time between shots - if(m_time_since_last_shot<3.0f) break; // Since cakes can be fired all around, just use a sane distance // with a bit of extra for backwards, as enemy will go towards cake bool fire_backwards = (m_kart_behind && m_kart_ahead && @@ -546,17 +522,14 @@ void DefaultAIController::handleItems( const float DELTA, const int STEPS ) float distance = fire_backwards ? m_distance_behind : m_distance_ahead; m_controls->m_fire = (fire_backwards && distance < 25.0f) || - (!fire_backwards && distance < 20.0f); + (!fire_backwards && distance < 20.0f) || + m_time_since_last_shot > 10.0f; if(m_controls->m_fire) m_controls->m_look_back = fire_backwards; break; } case PowerupManager::POWERUP_BOWLING: { - // Leave more time between bowling balls, since they are - // slower, so it should take longer to hit something which - // can result in changing our target. - if(m_time_since_last_shot < 5.0f) break; // Bowling balls slower, so only fire on closer karts - but when // firing backwards, the kart can be further away, since the ball // acts a bit like a mine (and the kart is racing towards it, too) @@ -565,19 +538,15 @@ void DefaultAIController::handleItems( const float DELTA, const int STEPS ) !m_kart_ahead; float distance = fire_backwards ? m_distance_behind : m_distance_ahead; - m_controls->m_fire = ( (fire_backwards && distance < 30.0f) || - (!fire_backwards && distance <10.0f) ) && - m_time_since_last_shot > 3.0f; + m_controls->m_fire = (fire_backwards && distance < 30.0f) || + (!fire_backwards && distance <10.0f) || + m_time_since_last_shot > 10.0f; if(m_controls->m_fire) m_controls->m_look_back = fire_backwards; break; } case PowerupManager::POWERUP_PLUNGER: { - // Leave more time after a plunger, since it will take some - // time before a plunger effect becomes obvious. - if(m_time_since_last_shot < 5.0f) break; - // Plungers can be fired backwards and are faster, // so allow more distance for shooting. bool fire_backwards = (m_kart_behind && m_kart_ahead && @@ -592,9 +561,6 @@ void DefaultAIController::handleItems( const float DELTA, const int STEPS ) break; } case PowerupManager::POWERUP_ANVIL: - // Wait one second more than a previous anvil ... just in case - if(m_time_since_last_shot < stk_config->m_anvil_time+1.0f) break; - if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER) { m_controls->m_fire = m_world->getTime()<1.0f && @@ -923,8 +889,7 @@ void DefaultAIController::findNonCrashingPoint(Vec3 *result) target_sector = m_next_node_index[sector]; //direction is a vector from our kart to the sectors we are testing - direction = m_quad_graph->getSideOfCenter(target_sector, - m_steering_variation); + direction = m_quad_graph->getQuad(target_sector).getCenter() - m_kart->getXYZ(); float len=direction.length_2d(); @@ -951,8 +916,7 @@ void DefaultAIController::findNonCrashingPoint(Vec3 *result) if ( distance + m_kart_width * 0.5f > m_quad_graph->getNode(sector).getPathWidth() ) { - *result=m_quad_graph->getSideOfCenter(sector, - m_steering_variation); + *result = m_quad_graph->getQuad(sector).getCenter(); return; } } diff --git a/src/karts/controller/default_ai_controller.hpp b/src/karts/controller/default_ai_controller.hpp index 45df9def7..85fbc8d2c 100644 --- a/src/karts/controller/default_ai_controller.hpp +++ b/src/karts/controller/default_ai_controller.hpp @@ -109,10 +109,6 @@ private: float m_curve_target_speed; float m_curve_angle; - /** Indicates how much to the left/right of the center driveline point - * the AI should aim at in order to avoid AIs creating trains. */ - float m_steering_variation; - /** The current node the kart is on. This can be different from the value * in LinearWorld, since it takes the chosen path of the AI into account * (e.g. the closest point in LinearWorld might be on a branch not @@ -162,7 +158,7 @@ protected: virtual unsigned int getNextSector(unsigned int index); public: - DefaultAIController(Kart *kart, unsigned kart_id); + DefaultAIController(Kart *kart); ~DefaultAIController(); virtual void update (float delta) ; virtual void reset (); diff --git a/src/karts/controller/new_ai_controller.cpp b/src/karts/controller/new_ai_controller.cpp index 9a7a47058..ba0bcc2bb 100644 --- a/src/karts/controller/new_ai_controller.cpp +++ b/src/karts/controller/new_ai_controller.cpp @@ -46,8 +46,7 @@ #include "tracks/track.hpp" #include "utils/constants.hpp" -NewAIController::NewAIController(Kart *kart, unsigned int kart_id) - : AIBaseController(kart) +NewAIController::NewAIController(Kart *kart) : AIBaseController(kart) { m_next_node_index.reserve(m_quad_graph->getNumNodes()); m_successor_index.reserve(m_quad_graph->getNumNodes()); diff --git a/src/karts/controller/new_ai_controller.hpp b/src/karts/controller/new_ai_controller.hpp index f07b67f21..181763de7 100644 --- a/src/karts/controller/new_ai_controller.hpp +++ b/src/karts/controller/new_ai_controller.hpp @@ -161,7 +161,7 @@ protected: virtual unsigned int getNextSector(unsigned int index); public: - NewAIController(Kart *kart, unsigned int kart_id); + NewAIController(Kart *kart); virtual ~NewAIController(); virtual void update (float delta) ; virtual void reset (); diff --git a/src/modes/profile_world.cpp b/src/modes/profile_world.cpp index 9ba5e8b36..7477b15d6 100644 --- a/src/modes/profile_world.cpp +++ b/src/modes/profile_world.cpp @@ -92,7 +92,7 @@ Kart *ProfileWorld::createKart(const std::string &kart_ident, int index, race_manager->getNumberOfKarts()-1); Kart *new_kart = new Kart(prof_kart_id, index+1, init_pos); - Controller *controller = loadAIController(new_kart, index); + Controller *controller = loadAIController(new_kart); new_kart->setController(controller); // Create a camera for the last kart (since this way more of the diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 8521bf76f..0e4c34e3d 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -171,14 +171,14 @@ void World::init() * this player globally (i.e. including network players). * \param init_pos The start transform (xyz and hpr). */ -Kart *World::createKart(const std::string &kart_ident, int kart_id, +Kart *World::createKart(const std::string &kart_ident, int index, int local_player_id, int global_player_id, const btTransform &init_pos) { - int position = kart_id+1; + int position = index+1; Kart *new_kart = new Kart(kart_ident, position, init_pos); Controller *controller = NULL; - switch(race_manager->getKartType(kart_id)) + switch(race_manager->getKartType(index)) { case RaceManager::KT_PLAYER: controller = new PlayerController(new_kart, @@ -193,7 +193,7 @@ Kart *World::createKart(const std::string &kart_ident, int kart_id, //m_num_players++; //break; case RaceManager::KT_AI: - controller = loadAIController(new_kart, kart_id); + controller = loadAIController(new_kart); break; case RaceManager::KT_GHOST: break; @@ -208,7 +208,7 @@ Kart *World::createKart(const std::string &kart_ident, int kart_id, /** Creates an AI controller for the kart. * \param kart The kart to be controlled by an AI. */ -Controller* World::loadAIController(Kart *kart, unsigned int kart_id) +Controller* World::loadAIController(Kart *kart) { Controller *controller; // const int NUM_ROBOTS = 1; @@ -222,14 +222,14 @@ Controller* World::loadAIController(Kart *kart, unsigned int kart_id) switch(turn) { case 0: - controller = new DefaultAIController(kart, kart_id); + controller = new DefaultAIController(kart); break; case 1: - controller = new NewAIController(kart, kart_id); + controller = new NewAIController(kart); break; default: std::cerr << "Warning: Unknown robot, using default." << std::endl; - controller = new DefaultAIController(kart, kart_id); + controller = new DefaultAIController(kart); break; } diff --git a/src/modes/world.hpp b/src/modes/world.hpp index a13e2a091..09f8aacd3 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -112,9 +112,9 @@ protected: void resetAllKarts (); void removeKart (int kart_number, bool notifyOfElimination=true); Controller* - loadAIController (Kart *kart, unsigned int kart_id); + loadAIController (Kart *kart); - virtual Kart *createKart(const std::string &kart_ident, int kart_id, + virtual Kart *createKart(const std::string &kart_ident, int index, int local_player_id, int global_player_id, const btTransform &init_pos); /** Pointer to the track. The track is managed by world. */ diff --git a/src/tracks/graph_node.cpp b/src/tracks/graph_node.cpp index dfcb0ff36..906731547 100644 --- a/src/tracks/graph_node.cpp +++ b/src/tracks/graph_node.cpp @@ -56,8 +56,6 @@ GraphNode::GraphNode(unsigned int index) upper.getX(), upper.getZ() ); // Only this 2d point is needed later m_lower_center = core::vector2df(lower.getX(), lower.getZ()); - - m_center_to_right = (quad[1]+quad[2])*0.5f-quad.getCenter(); } // GraphNode // ---------------------------------------------------------------------------- @@ -131,13 +129,3 @@ float GraphNode::getDistance2FromPoint(const Vec3 &xyz) core::vector2df closest = m_line.getClosestPoint(xyz2d); return (closest-xyz2d).getLengthSQ(); } // getDistance2FromPoint - -// ---------------------------------------------------------------------------- -/** Returns a point to the right (f>0) or left (f<0) of the center - * of a node. |f| <=1, with f=0 returning exactly the center point, - * and f=+-1 returning the point on the right/left edge of the node. - */ -Vec3 GraphNode::getSideOfCenter(float f) const -{ - return m_all_quads->getCenterOfQuad(m_index)+f*m_center_to_right; -} // getSideOfCenter diff --git a/src/tracks/graph_node.hpp b/src/tracks/graph_node.hpp index 7fc4c8119..f6c9a7e95 100644 --- a/src/tracks/graph_node.hpp +++ b/src/tracks/graph_node.hpp @@ -71,10 +71,6 @@ class GraphNode * saves computation, and it is only needed to determine the distance * from the center of the drivelines anyway. */ core::line2df m_line; - - /** A vector from the center of the quad to the center of the right - * side. This is used in getSideOfCenter. */ - Vec3 m_center_to_right; public: /** Keep a shared pointer so that some asserts and tests can be * done without adding additional parameters. */ @@ -87,7 +83,6 @@ public: void addSuccessor (unsigned int to); void getDistances(const Vec3 &xyz, Vec3 *result); float getDistance2FromPoint(const Vec3 &xyz); - Vec3 getSideOfCenter(float f) const; /** Returns the i-th successor. */ unsigned int getSuccessor(unsigned int i) const @@ -116,7 +111,6 @@ public: // ------------------------------------------------------------------- /** Returns the width of the part for this quad. */ float getPathWidth() const { return m_width; } - // ------------------------------------------------------------------- /** Returns the center point of the lower edge of this graph node. */ const core::vector2df& getLowerCenter() const {return m_lower_center;} diff --git a/src/tracks/quad_graph.hpp b/src/tracks/quad_graph.hpp index b6230e531..fdfcfa945 100644 --- a/src/tracks/quad_graph.hpp +++ b/src/tracks/quad_graph.hpp @@ -117,12 +117,6 @@ public: /** Returns the length of the main driveline. */ float getLapLength() const {return m_lap_length; } // ---------------------------------------------------------------------- - /** Returns a point to the right (f>0) or left (f<0) of the center - * of a node. |f| <=1, with f=0 returning exactly the center point, - * and f=+-1 returning the point on the right/left edge of the node. - */ - Vec3 getSideOfCenter(unsigned int j, float f) const - { return m_all_nodes[j]->getSideOfCenter(f); } }; // QuadGraph #endif