Add arena ai to test live join

This commit is contained in:
Benau 2019-01-04 22:07:15 +08:00
parent 7c34818c04
commit c16727302a
8 changed files with 25 additions and 14 deletions

View File

@ -76,7 +76,6 @@ protected:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void determineTurnRadius(const Vec3 &end, Vec3 *center, void determineTurnRadius(const Vec3 &end, Vec3 *center,
float *radius) const; float *radius) const;
virtual void update(int ticks) OVERRIDE;
virtual void setSteering (float angle, float dt); virtual void setSteering (float angle, float dt);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Return true if AI can skid now. */ /** Return true if AI can skid now. */
@ -108,6 +107,8 @@ public:
virtual void saveState(BareNetworkString *buffer) const OVERRIDE; virtual void saveState(BareNetworkString *buffer) const OVERRIDE;
virtual void rewindTo(BareNetworkString *buffer) OVERRIDE; virtual void rewindTo(BareNetworkString *buffer) OVERRIDE;
void setNetworkAI(bool val) { m_enabled_network_ai = val; } void setNetworkAI(bool val) { m_enabled_network_ai = val; }
// ------------------------------------------------------------------------
virtual void update(int ticks) OVERRIDE;
}; // AIBaseController }; // AIBaseController

View File

@ -37,7 +37,6 @@ ArenaAI::ArenaAI(AbstractKart *kart)
m_debug_sphere = NULL; m_debug_sphere = NULL;
m_debug_sphere_next = NULL; m_debug_sphere_next = NULL;
m_graph = ArenaGraph::get(); m_graph = ArenaGraph::get();
assert(m_graph != NULL);
} // ArenaAI } // ArenaAI
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -78,6 +77,9 @@ void ArenaAI::reset()
*/ */
void ArenaAI::update(int ticks) void ArenaAI::update(int ticks)
{ {
if (!m_graph)
return;
// This is used to enable firing an item backwards. // This is used to enable firing an item backwards.
m_controls->setLookBack(false); m_controls->setLookBack(false);
m_controls->setNitro(false); m_controls->setNitro(false);

View File

@ -47,7 +47,8 @@ BattleAI::BattleAI(AbstractKart *kart)
m_debug_sphere_next = irr_driver->addSphere(1.0f, col_debug_next); m_debug_sphere_next = irr_driver->addSphere(1.0f, col_debug_next);
m_debug_sphere_next->setVisible(true); m_debug_sphere_next->setVisible(true);
#endif #endif
m_world = dynamic_cast<ThreeStrikesBattle*>(World::getWorld()); m_world = dynamic_cast<WorldWithRank*>(World::getWorld());
m_tsb_world = dynamic_cast<ThreeStrikesBattle*>(World::getWorld());
m_track = Track::getCurrentTrack(); m_track = Track::getCurrentTrack();
// Don't call our own setControllerName, since this will add a // 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() void BattleAI::findTarget()
{ {
bool find_sta = false; bool find_sta = false;
if (m_world->spareTireKartsSpawned()) if (m_tsb_world && m_tsb_world->spareTireKartsSpawned())
{ {
switch (m_cur_difficulty) switch (m_cur_difficulty)
{ {
case RaceManager::DIFFICULTY_EASY: case RaceManager::DIFFICULTY_EASY:
case RaceManager::DIFFICULTY_MEDIUM: case RaceManager::DIFFICULTY_MEDIUM:
{ {
find_sta = m_world->getKartLife(m_kart->getWorldKartId()) == 1; find_sta = m_tsb_world->getKartLife(m_kart->getWorldKartId()) == 1;
break; break;
} }
case RaceManager::DIFFICULTY_HARD: case RaceManager::DIFFICULTY_HARD:
case RaceManager::DIFFICULTY_BEST: case RaceManager::DIFFICULTY_BEST:
{ {
find_sta = m_world->getKartLife(m_kart->getWorldKartId()) != 3; find_sta = m_tsb_world->getKartLife(m_kart->getWorldKartId()) != 3;
break; break;
} }
default: assert(false); default: assert(false);

View File

@ -24,6 +24,7 @@
#include "karts/controller/arena_ai.hpp" #include "karts/controller/arena_ai.hpp"
class ThreeStrikesBattle; class ThreeStrikesBattle;
class WorldWithRank;
/** The actual battle AI. /** The actual battle AI.
* \ingroup controller * \ingroup controller
@ -32,7 +33,8 @@ class BattleAI : public ArenaAI
{ {
protected: protected:
/** Keep a pointer to world. */ /** Keep a pointer to world. */
ThreeStrikesBattle *m_world; WorldWithRank *m_world;
ThreeStrikesBattle* m_tsb_world;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void findClosestKart(bool consider_difficulty, virtual void findClosestKart(bool consider_difficulty,

View File

@ -31,7 +31,7 @@ const int UPDATE_FREQUENCY = 30;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
NetworkAIController::NetworkAIController(AbstractKart *kart, NetworkAIController::NetworkAIController(AbstractKart *kart,
int local_player_id, int local_player_id,
SkiddingAI* ai) AIBaseController* ai)
: PlayerController(kart) : PlayerController(kart)
{ {
m_ai_controller = ai; m_ai_controller = ai;

View File

@ -22,18 +22,18 @@
#include "karts/controller/player_controller.hpp" #include "karts/controller/player_controller.hpp"
class AbstractKart; class AbstractKart;
class SkiddingAI; class AIBaseController;
class NetworkAIController : public PlayerController class NetworkAIController : public PlayerController
{ {
private: private:
int m_prev_update_ticks; int m_prev_update_ticks;
SkiddingAI* m_ai_controller; AIBaseController* m_ai_controller;
KartControl* m_ai_controls; KartControl* m_ai_controls;
void convertAIToPlayerActions(); void convertAIToPlayerActions();
public: public:
NetworkAIController(AbstractKart *kart, int local_player_id, NetworkAIController(AbstractKart *kart, int local_player_id,
SkiddingAI* ai); AIBaseController* ai);
virtual ~NetworkAIController(); virtual ~NetworkAIController();
virtual void update(int ticks) OVERRIDE; virtual void update(int ticks) OVERRIDE;
virtual void reset() OVERRIDE; virtual void reset() OVERRIDE;

View File

@ -141,7 +141,7 @@ void SpareTireAI::crashed(const AbstractKart *k)
if (dynamic_cast<const SpareTireAI*>(k->getController()) != NULL) return; if (dynamic_cast<const SpareTireAI*>(k->getController()) != NULL) return;
// Tell players that they can have at most 3 lives // 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 World::getWorld()->getRaceGUI()->addMessage
(_("You can have at most 3 lives!"), k, 2.0f); (_("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 // Otherwise add one life for that kart
else else
{ {
m_world->addKartLife(k->getWorldKartId()); m_tsb_world->addKartLife(k->getWorldKartId());
World::getWorld()->getRaceGUI()->addMessage(_("+1 life."), k, 2.0f); World::getWorld()->getRaceGUI()->addMessage(_("+1 life."), k, 2.0f);
} }
unspawn(); unspawn();

View File

@ -454,8 +454,13 @@ std::shared_ptr<AbstractKart> World::createKart
{ {
if (NetworkConfig::get()->isNetworkAITester()) 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(), controller = new NetworkAIController(new_kart.get(),
local_player_id, new SkiddingAI(new_kart.get())); local_player_id, ai);
} }
else else
{ {