Add arena ai to test live join
This commit is contained in:
parent
7c34818c04
commit
c16727302a
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<ThreeStrikesBattle*>(World::getWorld());
|
||||
m_world = dynamic_cast<WorldWithRank*>(World::getWorld());
|
||||
m_tsb_world = dynamic_cast<ThreeStrikesBattle*>(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);
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -141,7 +141,7 @@ void SpareTireAI::crashed(const AbstractKart *k)
|
||||
if (dynamic_cast<const SpareTireAI*>(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();
|
||||
|
@ -454,8 +454,13 @@ std::shared_ptr<AbstractKart> 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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user