Replaced many uses of getPlayer with Controller::canGetAchievements.

Removed some unused variables.
This commit is contained in:
hiker 2016-01-15 08:02:36 +11:00
parent 45399fc43f
commit d3a7c75a62
14 changed files with 52 additions and 39 deletions

View File

@ -225,10 +225,7 @@ void Attachment::clear()
*/
void Attachment::hitBanana(Item *item, int new_attachment)
{
const KartProperties *kp = m_kart->getKartProperties();
const StateManager::ActivePlayer *const ap = m_kart->getController()
->getPlayer();
if(ap && ap->getConstProfile()==PlayerManager::getCurrentPlayer())
if(m_kart->getController()->canGetAchievements())
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_BANANA,
"banana",1 );
//Bubble gum shield effect:
@ -250,6 +247,7 @@ void Attachment::hitBanana(Item *item, int new_attachment)
return;
}
const KartProperties *kp = m_kart->getKartProperties();
switch(getType()) // If there already is an attachment, make it worse :)
{
case ATTACH_BOMB:

View File

@ -174,9 +174,8 @@ void Powerup::use()
const KartProperties *kp = m_owner->getKartProperties();
// The player gets an achievement point for using a powerup
StateManager::ActivePlayer * player = m_owner->getController()->getPlayer();
if (m_type != PowerupManager::POWERUP_NOTHING &&
player != NULL && player->getConstProfile() == PlayerManager::getCurrentPlayer())
if (m_type != PowerupManager::POWERUP_NOTHING &&
m_owner->getController()->canGetAchievements() )
{
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_POWERUP_LOVER, "poweruplover");
}

View File

@ -290,13 +290,11 @@ void Swatter::squashThingsAround()
m_closest_kart->setSquash(kp->getSwatterSquashDuration(),
kp->getSwatterSquashSlowdown());
//Handle achievement if the swatter is used by the current player
const StateManager::ActivePlayer *const ap = m_kart->getController()
->getPlayer();
if (ap && ap->getConstProfile() == PlayerManager::getCurrentPlayer())
// Handle achievement if the swatter is used by the current player
if (m_kart->getController()->canGetAchievements())
{
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_MOSQUITO,
"swatter", 1);
"swatter", 1);
}
if (m_closest_kart->getAttachment()->getType()==Attachment::ATTACH_BOMB)

View File

@ -22,6 +22,7 @@
#include "karts/controller/controller.hpp"
#include "config/player_manager.hpp"
#include "karts/abstract_kart.hpp"
/** Constructor, saves the kart pointer and a pointer to the KartControl
@ -38,3 +39,14 @@ Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player)
} // 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

View File

@ -61,6 +61,7 @@ public:
Controller (AbstractKart *kart,
StateManager::ActivePlayer *player=NULL);
virtual ~Controller () {};
virtual bool canGetAchievements () const;
virtual void reset () = 0;
virtual void update (float dt) = 0;
virtual void handleZipper (bool play_sound) = 0;
@ -93,7 +94,6 @@ public:
// ---------------------------------------------------------------------------
/** 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;

View File

@ -50,9 +50,9 @@
#include "utils/constants.hpp"
#include "utils/log.hpp"
EndController::EndController(AbstractKart *kart, StateManager::ActivePlayer *player,
EndController::EndController(AbstractKart *kart,
Controller *prev_controller)
: AIBaseLapController(kart, player)
: AIBaseLapController(kart, NULL)
{
m_previous_controller = prev_controller;
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES &&

View File

@ -82,17 +82,33 @@ private:
int calcSteps();
public:
EndController(AbstractKart *kart,
StateManager::ActivePlayer* player,
Controller *prev_controller);
~EndController();
virtual void update (float delta) ;
virtual void reset ();
virtual void action (PlayerAction action, int value);
virtual void newLap (int lap);
// ------------------------------------------------------------------------
virtual bool canGetAchievements() const
{
return m_previous_controller->canGetAchievements();
} // canGetAchievements
// ------------------------------------------------------------------------
/** Returns if the original controller of the kart was a player
* controller. This way e.g. highscores can still be assigned
* to the right player. */
virtual bool isPlayerController () const {return getPlayer()!=NULL;}
virtual void action (PlayerAction action, int value);
virtual void newLap (int lap);
virtual bool isPlayerController () const
{
return m_previous_controller->isPlayerController();
} // isPlayerController
// ------------------------------------------------------------------------
/** Returns if the original controller of the kart was a local player
* controller. This way e.g. highscores can still be assigned
* to the right player. */
virtual bool isLocalPlayerController () const
{
return m_previous_controller->isLocalPlayerController();
} // isLocalPlayerController
}; // EndKart

View File

@ -868,8 +868,7 @@ void Kart::finishedRace(float time)
{
// Save for music handling in race result gui
setRaceResult();
setController(new EndController(this, m_controller->getPlayer(),
m_controller));
setController(new EndController(this, m_controller));
// Skip animation if this kart is eliminated
if (m_eliminated) return;

View File

@ -416,10 +416,10 @@ void Skidding::update(float dt, bool is_on_ground,
bonus_force, bonus_time,
/*fade-out-time*/ 1.0f);
StateManager::ActivePlayer *c = m_kart->getController()->getPlayer();
if (c && c->getConstProfile() == PlayerManager::getCurrentPlayer())
if (m_kart->getController()->canGetAchievements())
{
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_SKIDDING, "skidding");
PlayerManager::increaseAchievement(
AchievementInfo::ACHIEVE_SKIDDING, "skidding");
}
}
else {

View File

@ -247,9 +247,8 @@ void LinearWorld::newLap(unsigned int kart_index)
AbstractKart *kart = m_karts[kart_index];
// Reset reset-after-lap achievements
StateManager::ActivePlayer *c = kart->getController()->getPlayer();
PlayerProfile *p = PlayerManager::getCurrentPlayer();
if (c && c->getConstProfile() == p)
if (kart->getController()->canGetAchievements())
{
p->getAchievementsStatus()->onLapEnd();
}

View File

@ -500,8 +500,7 @@ void World::terminateRace()
for(unsigned int i = 0; i < kart_amount; i++)
{
// Retrieve the current player
StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer())
if (m_karts[i]->getController()->canGetAchievements())
{
// Check if the player has won
if (m_karts[i]->getPosition() == winner_position && kart_amount > opponents )
@ -525,8 +524,7 @@ void World::terminateRace()
for(unsigned int i = 0; i < kart_amount; i++)
{
// Retrieve the current player
StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer())
if (m_karts[i]->getController()->canGetAchievements())
{
// Check if the player has won
if (m_karts[i]->getPosition() == 1 )
@ -1091,6 +1089,7 @@ void World::updateHighscores(int* best_highscore_rank)
(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(),

View File

@ -307,15 +307,14 @@ void Physics::update(float dt)
// Check for achievements
AbstractKart * kart = World::getWorld()->getKart(f->getOwnerId());
LocalPlayerController *c =
LocalPlayerController *lpc =
dynamic_cast<LocalPlayerController*>(kart->getController());
// Check that it's not a kart hitting itself (this can
// happen at the time a flyable is shot - release too close
// to the kart, and it's the current player. At this stage
// only the current player can get achievements.
if (target_kart != kart && c &&
c->getPlayer()->getConstProfile() == PlayerManager::getCurrentPlayer())
if (target_kart != kart && lpc && lpc->canGetAchievements())
{
// Compare the current value of hits with the 'hit' goal value
// (otherwise it would be compared with the kart id goal value,

View File

@ -476,8 +476,6 @@ void RaceResultGUI::determineTableLayout()
RowInfo *ri = &(m_all_row_infos[position-first_position]);
ri->m_is_player_kart = kart->getController()->isLocalPlayerController();
ri->m_kart_name = translations->fribidize(kart->getName());
ri->m_player = ri->m_is_player_kart
? kart->getController()->getPlayer() : NULL;
video::ITexture *icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
@ -844,8 +842,6 @@ void RaceResultGUI::determineGPLayout()
kart->getKartProperties()->getIconMaterial()->getTexture();
ri->m_kart_name = translations->fribidize(kart->getName());
ri->m_is_player_kart = kart->getController()->isLocalPlayerController();
ri->m_player = ri->m_is_player_kart
? kart->getController()->getPlayer() : NULL;
// In FTL karts do have a time, which is shown even when the kart
// is eliminated

View File

@ -82,8 +82,6 @@ private:
float m_y_pos;
/** True if kart is a player kart. */
bool m_is_player_kart;
/** Only if m_is_player_kart is true */
const StateManager::ActivePlayer* m_player;
/** The radius to use when sorting the entries. Positive values
will rotate downwards, negatives are upwards. */
float m_radius;