Moved ActivePlayer out of Controller and into LocalPlayerController.
This commit is contained in:
@@ -31,9 +31,8 @@
|
||||
|
||||
bool AIBaseController::m_ai_debug = false;
|
||||
|
||||
AIBaseController::AIBaseController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: Controller(kart, player)
|
||||
AIBaseController::AIBaseController(AbstractKart *kart)
|
||||
: Controller(kart)
|
||||
{
|
||||
m_kart = kart;
|
||||
m_kart_length = m_kart->getKartLength();
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#define HEADER_AI_BASE_CONTROLLER_HPP
|
||||
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
class AIProperties;
|
||||
class Track;
|
||||
@@ -69,8 +68,7 @@ protected:
|
||||
bool isStuck() const { return m_stuck; }
|
||||
|
||||
public:
|
||||
AIBaseController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player=NULL);
|
||||
AIBaseController(AbstractKart *kart);
|
||||
virtual ~AIBaseController() {};
|
||||
virtual void reset();
|
||||
virtual bool disableSlipstreamBonus() const;
|
||||
|
||||
@@ -82,9 +82,8 @@ in all AIs, e.g.:
|
||||
in [-1,1].
|
||||
|
||||
*/
|
||||
AIBaseLapController::AIBaseLapController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: AIBaseController(kart, player)
|
||||
AIBaseLapController::AIBaseLapController(AbstractKart *kart)
|
||||
: AIBaseController(kart)
|
||||
{
|
||||
|
||||
if (race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES &&
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#define HEADER_AI_BASE_LAP_CONTROLLER_HPP
|
||||
|
||||
#include "karts/controller/ai_base_controller.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
class AIProperties;
|
||||
class LinearWorld;
|
||||
@@ -68,8 +67,7 @@ protected:
|
||||
virtual void raceFinished() {};
|
||||
|
||||
public:
|
||||
AIBaseLapController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player=NULL);
|
||||
AIBaseLapController(AbstractKart *kart);
|
||||
virtual ~AIBaseLapController() {};
|
||||
virtual void reset();
|
||||
virtual void crashed(const AbstractKart *k) {};
|
||||
|
||||
@@ -49,9 +49,8 @@ using namespace std;
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
BattleAI::BattleAI(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: AIBaseController(kart, player)
|
||||
BattleAI::BattleAI(AbstractKart *kart)
|
||||
: AIBaseController(kart)
|
||||
{
|
||||
|
||||
reset();
|
||||
|
||||
@@ -137,8 +137,7 @@ protected:
|
||||
#endif
|
||||
|
||||
public:
|
||||
BattleAI(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player=NULL);
|
||||
BattleAI(AbstractKart *kart);
|
||||
~BattleAI();
|
||||
virtual void update (float delta);
|
||||
virtual void reset ();
|
||||
|
||||
@@ -28,25 +28,9 @@
|
||||
/** Constructor, saves the kart pointer and a pointer to the KartControl
|
||||
* of the kart.
|
||||
*/
|
||||
Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player)
|
||||
Controller::Controller(AbstractKart *kart)
|
||||
{
|
||||
m_controls = &(kart->getControls());
|
||||
m_kart = kart;
|
||||
m_player = player;
|
||||
if(player)
|
||||
player->setKart(kart);
|
||||
setControllerName("Controller");
|
||||
} // Controller
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns true if the player of this controller can collect achievements.
|
||||
* At the moment only the current player can collect them.
|
||||
* TODO: check this, possible all local players should be able to
|
||||
* collect achievements - synching to online account will happen
|
||||
* next time the account gets online.
|
||||
*/
|
||||
bool Controller::canGetAchievements() const
|
||||
{
|
||||
return m_player && m_player->getConstProfile()
|
||||
== PlayerManager::getCurrentPlayer();
|
||||
} // canGetAchievements
|
||||
|
||||
@@ -42,9 +42,6 @@ class Material;
|
||||
class Controller
|
||||
{
|
||||
private:
|
||||
/** If this belongs to a player, it stores the active player data
|
||||
* structure. Otherwise it is 0. */
|
||||
StateManager::ActivePlayer *m_player;
|
||||
|
||||
protected:
|
||||
/** Pointer to the kart that is controlled by this controller. */
|
||||
@@ -58,10 +55,8 @@ protected:
|
||||
std::string m_controller_name;
|
||||
|
||||
public:
|
||||
Controller (AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player=NULL);
|
||||
Controller (AbstractKart *kart);
|
||||
virtual ~Controller () {};
|
||||
virtual bool canGetAchievements () const;
|
||||
virtual void reset () = 0;
|
||||
virtual void update (float dt) = 0;
|
||||
virtual void handleZipper (bool play_sound) = 0;
|
||||
@@ -86,14 +81,6 @@ public:
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Returns the name of this controller. */
|
||||
const std::string &getControllerName() const { return m_controller_name; }
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Returns the active player for this controller (NULL
|
||||
* if this controller does not belong to a player. */
|
||||
StateManager::ActivePlayer *getPlayer () {return m_player;}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Returns the player object (or NULL if it's a computer controller). */
|
||||
const StateManager::ActivePlayer *getPlayer () const { return m_player; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Default: ignore actions. Only PlayerController get them. */
|
||||
virtual void action(PlayerAction action, int value) = 0;
|
||||
@@ -110,6 +97,15 @@ public:
|
||||
/** Get a pointer on the kart controls. */
|
||||
virtual KartControl* getControls() { return m_controls; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Only local players can get achievements. */
|
||||
virtual bool canGetAchievements () const { return false; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** This should only be called for End- and LocalPlayer-Controller. */
|
||||
virtual core::stringw getName() const
|
||||
{
|
||||
assert(false);
|
||||
return core::stringw("");
|
||||
} // getName
|
||||
}; // Controller
|
||||
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
EndController::EndController(AbstractKart *kart,
|
||||
Controller *prev_controller)
|
||||
: AIBaseLapController(kart, NULL)
|
||||
: AIBaseLapController(kart)
|
||||
{
|
||||
m_previous_controller = prev_controller;
|
||||
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES &&
|
||||
|
||||
@@ -109,6 +109,10 @@ public:
|
||||
{
|
||||
return m_previous_controller->isLocalPlayerController();
|
||||
} // isLocalPlayerController
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the previous controller (which has the right
|
||||
* player name associated). */
|
||||
core::stringw getName() const { return m_previous_controller->getName(); }
|
||||
|
||||
}; // EndKart
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "karts/controller/local_player_controller.hpp"
|
||||
|
||||
#include "audio/sfx_base.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
@@ -52,8 +53,12 @@
|
||||
*/
|
||||
LocalPlayerController::LocalPlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: PlayerController(kart, player)
|
||||
: PlayerController(kart)
|
||||
{
|
||||
m_player = player;
|
||||
if(player)
|
||||
player->setKart(kart);
|
||||
|
||||
// Keep a pointer to the camera to remove the need to search for
|
||||
// the right camera once per frame later.
|
||||
m_camera = Camera::createCamera(kart);
|
||||
@@ -309,3 +314,15 @@ void LocalPlayerController::collectedItem(const Item &item, int add_info,
|
||||
}
|
||||
}
|
||||
} // collectedItem
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns true if the player of this controller can collect achievements.
|
||||
* At the moment only the current player can collect them.
|
||||
* TODO: check this, possible all local players should be able to
|
||||
* collect achievements - synching to online account will happen
|
||||
* next time the account gets online.
|
||||
*/
|
||||
bool LocalPlayerController::canGetAchievements() const
|
||||
{
|
||||
return m_player->getConstProfile() == PlayerManager::getCurrentPlayer();
|
||||
} // canGetAchievements
|
||||
|
||||
@@ -37,6 +37,9 @@ class LocalPlayerController : public PlayerController
|
||||
{
|
||||
private:
|
||||
|
||||
/** Stores the active player data structure. */
|
||||
StateManager::ActivePlayer *m_player;
|
||||
|
||||
bool m_sound_schedule;
|
||||
|
||||
/** The camera attached to the kart for this controller. The camera
|
||||
@@ -64,10 +67,16 @@ public:
|
||||
virtual void reset () OVERRIDE;
|
||||
virtual void finishedRace (float time) OVERRIDE;
|
||||
virtual void resetInputState () OVERRIDE;
|
||||
virtual bool canGetAchievements() const OVERRIDE;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool isPlayerController() const OVERRIDE {return true;}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool isLocalPlayerController() const OVERRIDE {return true;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the player profile. */
|
||||
core::stringw getName() const { return m_player->getProfile()->getName(); }
|
||||
|
||||
|
||||
}; // LocalPlayerController
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@ class Player;
|
||||
class NetworkPlayerController : public PlayerController
|
||||
{
|
||||
public:
|
||||
NetworkPlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: PlayerController(kart, player)
|
||||
NetworkPlayerController(AbstractKart *kart) : PlayerController(kart)
|
||||
{
|
||||
Log::info("NetworkPlayerController",
|
||||
"New network player controller.");
|
||||
|
||||
@@ -38,11 +38,9 @@
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
PlayerController::PlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: Controller(kart, player)
|
||||
PlayerController::PlayerController(AbstractKart *kart)
|
||||
: Controller(kart)
|
||||
{
|
||||
assert(player != NULL);
|
||||
m_penalty_time = 0.0f;
|
||||
} // PlayerController
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ protected:
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
PlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *_player);
|
||||
PlayerController(AbstractKart *kart);
|
||||
virtual ~PlayerController ();
|
||||
virtual void update (float) OVERRIDE;
|
||||
virtual void action (PlayerAction action, int value) OVERRIDE;
|
||||
|
||||
@@ -315,8 +315,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
||||
m_num_players ++;
|
||||
break;
|
||||
case RaceManager::KT_NETWORK_PLAYER:
|
||||
controller = new NetworkPlayerController(new_kart,
|
||||
StateManager::get()->getActivePlayer(local_player_id));
|
||||
controller = new NetworkPlayerController(new_kart);
|
||||
m_num_players++;
|
||||
break;
|
||||
case RaceManager::KT_AI:
|
||||
@@ -1085,15 +1084,11 @@ void World::updateHighscores(int* best_highscore_rank)
|
||||
|
||||
Highscores* highscores = getHighscores();
|
||||
|
||||
LocalPlayerController *controller =
|
||||
(LocalPlayerController*)(k->getController());
|
||||
|
||||
int highscore_rank = 0;
|
||||
// The player is a local player, so it is sure that getPlayer() exists.
|
||||
if (controller->getPlayer()->getProfile() != NULL) // if we have the player profile here
|
||||
highscore_rank = highscores->addData(k->getIdent(),
|
||||
controller->getPlayer()->getProfile()->getName(),
|
||||
k->getFinishTime());
|
||||
// The player is a local player, so there is a name:
|
||||
highscore_rank = highscores->addData(k->getIdent(),
|
||||
k->getController()->getName(),
|
||||
k->getFinishTime() );
|
||||
|
||||
if (highscore_rank > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user