diff --git a/src/karts/controller/ai_base_controller.hpp b/src/karts/controller/ai_base_controller.hpp index a244c347f..a38401f62 100644 --- a/src/karts/controller/ai_base_controller.hpp +++ b/src/karts/controller/ai_base_controller.hpp @@ -76,7 +76,6 @@ protected: // ------------------------------------------------------------------------ void determineTurnRadius(const Vec3 &end, Vec3 *center, float *radius) const; - virtual void update(int ticks) OVERRIDE; virtual void setSteering (float angle, float dt); // ------------------------------------------------------------------------ /** Return true if AI can skid now. */ @@ -108,6 +107,8 @@ public: virtual void saveState(BareNetworkString *buffer) const OVERRIDE; virtual void rewindTo(BareNetworkString *buffer) OVERRIDE; void setNetworkAI(bool val) { m_enabled_network_ai = val; } + // ------------------------------------------------------------------------ + virtual void update(int ticks) OVERRIDE; }; // AIBaseController diff --git a/src/karts/controller/arena_ai.cpp b/src/karts/controller/arena_ai.cpp index bdfa4dcfd..2bf52406d 100644 --- a/src/karts/controller/arena_ai.cpp +++ b/src/karts/controller/arena_ai.cpp @@ -37,7 +37,6 @@ ArenaAI::ArenaAI(AbstractKart *kart) m_debug_sphere = NULL; m_debug_sphere_next = NULL; m_graph = ArenaGraph::get(); - assert(m_graph != NULL); } // ArenaAI //----------------------------------------------------------------------------- @@ -78,6 +77,9 @@ void ArenaAI::reset() */ void ArenaAI::update(int ticks) { + if (!m_graph) + return; + // This is used to enable firing an item backwards. m_controls->setLookBack(false); m_controls->setNitro(false); diff --git a/src/karts/controller/battle_ai.cpp b/src/karts/controller/battle_ai.cpp index 7f3065712..c4a89c5d8 100644 --- a/src/karts/controller/battle_ai.cpp +++ b/src/karts/controller/battle_ai.cpp @@ -47,7 +47,8 @@ BattleAI::BattleAI(AbstractKart *kart) m_debug_sphere_next = irr_driver->addSphere(1.0f, col_debug_next); m_debug_sphere_next->setVisible(true); #endif - m_world = dynamic_cast(World::getWorld()); + m_world = dynamic_cast(World::getWorld()); + m_tsb_world = dynamic_cast(World::getWorld()); m_track = Track::getCurrentTrack(); // Don't call our own setControllerName, since this will add a @@ -138,20 +139,20 @@ void BattleAI::findClosestKart(bool consider_difficulty, bool find_sta) void BattleAI::findTarget() { bool find_sta = false; - if (m_world->spareTireKartsSpawned()) + if (m_tsb_world && m_tsb_world->spareTireKartsSpawned()) { switch (m_cur_difficulty) { case RaceManager::DIFFICULTY_EASY: case RaceManager::DIFFICULTY_MEDIUM: { - find_sta = m_world->getKartLife(m_kart->getWorldKartId()) == 1; + find_sta = m_tsb_world->getKartLife(m_kart->getWorldKartId()) == 1; break; } case RaceManager::DIFFICULTY_HARD: case RaceManager::DIFFICULTY_BEST: { - find_sta = m_world->getKartLife(m_kart->getWorldKartId()) != 3; + find_sta = m_tsb_world->getKartLife(m_kart->getWorldKartId()) != 3; break; } default: assert(false); diff --git a/src/karts/controller/battle_ai.hpp b/src/karts/controller/battle_ai.hpp index 90ec63463..ad4b13c40 100644 --- a/src/karts/controller/battle_ai.hpp +++ b/src/karts/controller/battle_ai.hpp @@ -24,6 +24,7 @@ #include "karts/controller/arena_ai.hpp" class ThreeStrikesBattle; +class WorldWithRank; /** The actual battle AI. * \ingroup controller @@ -32,7 +33,8 @@ class BattleAI : public ArenaAI { protected: /** Keep a pointer to world. */ - ThreeStrikesBattle *m_world; + WorldWithRank *m_world; + ThreeStrikesBattle* m_tsb_world; // ------------------------------------------------------------------------ virtual void findClosestKart(bool consider_difficulty, diff --git a/src/karts/controller/network_ai_controller.cpp b/src/karts/controller/network_ai_controller.cpp index c23d84e08..d53e2d05e 100644 --- a/src/karts/controller/network_ai_controller.cpp +++ b/src/karts/controller/network_ai_controller.cpp @@ -31,7 +31,7 @@ const int UPDATE_FREQUENCY = 30; // ---------------------------------------------------------------------------- NetworkAIController::NetworkAIController(AbstractKart *kart, int local_player_id, - SkiddingAI* ai) + AIBaseController* ai) : PlayerController(kart) { m_ai_controller = ai; diff --git a/src/karts/controller/network_ai_controller.hpp b/src/karts/controller/network_ai_controller.hpp index 179dd523c..f16c70d74 100644 --- a/src/karts/controller/network_ai_controller.hpp +++ b/src/karts/controller/network_ai_controller.hpp @@ -22,18 +22,18 @@ #include "karts/controller/player_controller.hpp" class AbstractKart; -class SkiddingAI; +class AIBaseController; class NetworkAIController : public PlayerController { private: int m_prev_update_ticks; - SkiddingAI* m_ai_controller; + AIBaseController* m_ai_controller; KartControl* m_ai_controls; void convertAIToPlayerActions(); public: NetworkAIController(AbstractKart *kart, int local_player_id, - SkiddingAI* ai); + AIBaseController* ai); virtual ~NetworkAIController(); virtual void update(int ticks) OVERRIDE; virtual void reset() OVERRIDE; diff --git a/src/karts/controller/spare_tire_ai.cpp b/src/karts/controller/spare_tire_ai.cpp index db05a28ed..9d179c1c4 100644 --- a/src/karts/controller/spare_tire_ai.cpp +++ b/src/karts/controller/spare_tire_ai.cpp @@ -141,7 +141,7 @@ void SpareTireAI::crashed(const AbstractKart *k) if (dynamic_cast(k->getController()) != NULL) return; // Tell players that they can have at most 3 lives - if (m_world->getKartLife(k->getWorldKartId()) == 3) + if (m_tsb_world->getKartLife(k->getWorldKartId()) == 3) { World::getWorld()->getRaceGUI()->addMessage (_("You can have at most 3 lives!"), k, 2.0f); @@ -149,7 +149,7 @@ void SpareTireAI::crashed(const AbstractKart *k) // Otherwise add one life for that kart else { - m_world->addKartLife(k->getWorldKartId()); + m_tsb_world->addKartLife(k->getWorldKartId()); World::getWorld()->getRaceGUI()->addMessage(_("+1 life."), k, 2.0f); } unspawn(); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 508abcc13..aad338574 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -454,8 +454,13 @@ std::shared_ptr World::createKart { if (NetworkConfig::get()->isNetworkAITester()) { + AIBaseController* ai = NULL; + if (race_manager->isBattleMode()) + ai = new BattleAI(new_kart.get()); + else + ai = new SkiddingAI(new_kart.get()); controller = new NetworkAIController(new_kart.get(), - local_player_id, new SkiddingAI(new_kart.get())); + local_player_id, ai); } else {