Added new isLocalPlayerKart() function to controller, which is used

to detect when sfx and graphical effects should be shown. The isPlayerKart
funtion is used to detect a (local or remote) player, e.g. for rubber-banding
the AI, or finding the Xth player kart.
This commit is contained in:
hiker
2015-12-10 17:35:31 +11:00
parent 1969ee0b1f
commit e0b3de17f6
22 changed files with 67 additions and 62 deletions

View File

@@ -34,11 +34,11 @@ class HitEffect: public NoCopy
private:
/** True if this effect affected a player kart. Used to play certain SFX
* less loud if only an AI is hit. */
bool m_player_kart_hit;
bool m_local_player_kart_hit;
public:
/** Constructor for a hit effect. */
HitEffect() {m_player_kart_hit = false; }
HitEffect() {m_local_player_kart_hit = false; }
virtual ~HitEffect() {}
/** Updates a hit effect. Called once per frame.
* \param dt Time step size.
@@ -49,10 +49,10 @@ public:
/** Sets that this SFX affects a player kart, which can be used to
* make certain sfx louder/less loud. Default is that the affect
* does not affect a player kart. */
virtual void setPlayerKartHit() { m_player_kart_hit = true; }
virtual void setLocalPlayerKartHit() { m_local_player_kart_hit = true; }
// ------------------------------------------------------------------------
/** Returns if this effect affects a player kart. */
bool getPlayerKartHit() const { return m_player_kart_hit; }
bool getLocalPlayerKartHit() const { return m_local_player_kart_hit; }
}; // HitEffect
#endif

View File

@@ -49,11 +49,11 @@ HitSFX::~HitSFX()
* played louder than for a non-player kart if split screen is used).
* If this sfx is for a player kart in split screen, make it louder again.
*/
void HitSFX::setPlayerKartHit()
void HitSFX::setLocalPlayerKartHit()
{
if(race_manager->getNumLocalPlayers())
m_sfx->setVolume(1.0f);
} // setPlayerKartHit
} // setLocalPlayerKartHit
//-----------------------------------------------------------------------------
/** Updates the hit sfx, called one per time step. If this function returns

View File

@@ -20,6 +20,7 @@
#define HEADER_HIT_SFX_HPP
#include "graphics/hit_effect.hpp"
#include "utils/cpp2011.hpp"
class SFXBase;
@@ -36,7 +37,7 @@ public:
HitSFX(const Vec3& coord, const char* explosion_sound);
~HitSFX();
virtual bool updateAndDelete(float dt);
virtual void setPlayerKartHit();
virtual void setLocalPlayerKartHit() OVERRIDE;
}; // HitSFX

View File

@@ -441,7 +441,7 @@ void SlipStream::update(float dt)
m_kart->getPlayerDifficulty()->getSlipstreamMinSpeed())
{
if(UserConfigParams::m_slipstream_debug &&
m_kart->getController()->isPlayerController())
m_kart->getController()->isLocalPlayerController())
m_target_kart->getSlipstream()
->setDebugColor(video::SColor(255, 0, 0, 0));
@@ -459,7 +459,7 @@ void SlipStream::update(float dt)
if(delta.length2_2d() > l*l)
{
if(UserConfigParams::m_slipstream_debug &&
m_kart->getController()->isPlayerController())
m_kart->getController()->isLocalPlayerController())
m_target_kart->getSlipstream()
->setDebugColor(video::SColor(255, 0, 0, 128));
continue;
@@ -472,7 +472,7 @@ void SlipStream::update(float dt)
break;
}
if(UserConfigParams::m_slipstream_debug &&
m_kart->getController()->isPlayerController())
m_kart->getController()->isLocalPlayerController())
m_target_kart->getSlipstream()
->setDebugColor(video::SColor(255, 0, 0, 255));
} // for i < num_karts
@@ -480,7 +480,7 @@ void SlipStream::update(float dt)
if(!is_sstreaming)
{
if(UserConfigParams::m_slipstream_debug &&
m_kart->getController()->isPlayerController())
m_kart->getController()->isLocalPlayerController())
m_target_kart->getSlipstream()
->setDebugColor(video::SColor(255, 255, 0, 0));
@@ -506,7 +506,7 @@ void SlipStream::update(float dt)
} // if !is_sstreaming
if(UserConfigParams::m_slipstream_debug &&
m_kart->getController()->isPlayerController())
m_kart->getController()->isLocalPlayerController())
m_target_kart->getSlipstream()->setDebugColor(video::SColor(255, 0, 255, 0));
// Accumulate slipstream credits now
m_slipstream_time = m_slipstream_mode==SS_NONE ? dt

View File

@@ -255,8 +255,8 @@ void Attachment::hitBanana(Item *item, int new_attachment)
{
add_a_new_item = false;
HitEffect *he = new Explosion(m_kart->getXYZ(), "explosion", "explosion_bomb.xml");
if(m_kart->getController()->isPlayerController())
he->setPlayerKartHit();
if(m_kart->getController()->isLocalPlayerController())
he->setLocalPlayerKartHit();
projectile_manager->addHitEffect(he);
ExplosionAnimation::create(m_kart);
clear();
@@ -454,8 +454,8 @@ void Attachment::update(float dt)
if(m_time_left<=0.0)
{
HitEffect *he = new Explosion(m_kart->getXYZ(), "explosion", "explosion_bomb.xml");
if(m_kart->getController()->isPlayerController())
he->setPlayerKartHit();
if(m_kart->getController()->isLocalPlayerController())
he->setLocalPlayerKartHit();
projectile_manager->addHitEffect(he);
ExplosionAnimation::create(m_kart);

View File

@@ -165,7 +165,7 @@ bool Plunger::hit(AbstractKart *kart, PhysicalObject *obj)
if(kart)
{
kart->blockViewWithPlunger();
if (kart->getController()->isPlayerController())
if (kart->getController()->isLocalPlayerController())
SFXManager::get()->quickSound("plunger");
}

View File

@@ -154,7 +154,7 @@ void Powerup::adjustSound()
{
// player karts played at full volume; AI karts much dimmer
if (m_owner->getController()->isPlayerController())
if (m_owner->getController()->isLocalPlayerController())
{
m_sound_use->setVolume( 1.0f );
}
@@ -308,7 +308,7 @@ void Powerup::use()
// or the kart "throwing" the anvil? Ideally it should be both.
// Meanwhile, don't play it near AI karts since they obviously
// don't hear anything
if(kart->getController()->isPlayerController())
if(kart->getController()->isLocalPlayerController())
m_sound_use->setPosition(kart->getXYZ());
else
m_sound_use->setPosition(m_owner->getXYZ());
@@ -341,7 +341,7 @@ void Powerup::use()
->set(Attachment::ATTACH_PARACHUTE,
stk_config->m_parachute_time_other);
if(kart->getController()->isPlayerController())
if(kart->getController()->isLocalPlayerController())
player_kart = kart;
}
}
@@ -350,7 +350,7 @@ void Powerup::use()
// or the kart "throwing" the anvil? Ideally it should be both.
// Meanwhile, don't play it near AI karts since they obviously
// don't hear anything
if(m_owner->getController()->isPlayerController())
if(m_owner->getController()->isLocalPlayerController())
m_sound_use->setPosition(m_owner->getXYZ());
else if(player_kart)
m_sound_use->setPosition(player_kart->getXYZ());

View File

@@ -309,8 +309,8 @@ void Swatter::squashThingsAround()
{ // make bomb explode
kart->getAttachment()->update(10000);
HitEffect *he = new Explosion(m_kart->getXYZ(), "explosion", "explosion.xml");
if(m_kart->getController()->isPlayerController())
he->setPlayerKartHit();
if(m_kart->getController()->isLocalPlayerController())
he->setLocalPlayerKartHit();
projectile_manager->addHitEffect(he);
ExplosionAnimation::create(kart);
} // if kart has bomb attached

View File

@@ -110,8 +110,8 @@ public:
virtual void collectedItem(const Item &item, int add_info=-1,
float previous_energy=0) {};
virtual void setPosition(int p) {};
virtual bool isNetworkController() const { return false; }
virtual bool isPlayerController() const { return false; }
virtual bool isLocalPlayerController() const { return false; }
virtual void action(PlayerAction action, int value) {};
virtual void skidBonusTriggered() {};
virtual bool disableSlipstreamBonus() const;

View File

@@ -69,8 +69,14 @@ public:
virtual void crashed (const AbstractKart *k) = 0;
virtual void crashed (const Material *m) = 0;
virtual void setPosition (int p) = 0;
/** This function checks if this is a local player. A local player will get
* special graphical effects enabled, has a camera, and sound effects will
* be played with normal volume. */
virtual bool isLocalPlayerController () const = 0;
/** This function checks if this player is not an AI, i.e. it is either a
* a local or a remote/networked player. This is tested e.g. by the AI for
* rubber-banding. */
virtual bool isPlayerController () const = 0;
virtual bool isNetworkController() const = 0;
virtual bool disableSlipstreamBonus() const = 0;
// ---------------------------------------------------------------------------
/** Sets the controller name for this controller. */

View File

@@ -28,8 +28,8 @@ public:
float previous_energy=0);
virtual void skidBonusTriggered();
virtual void setPosition (int p);
virtual bool isPlayerController() const { return false; }
virtual bool isNetworkController() const { return true; }
virtual bool isPlayerController() const { return true; }
virtual bool isLocalPlayerController() const { return false; }
virtual void reset ();
void resetInputState ();
virtual void finishedRace (float time);

View File

@@ -68,7 +68,7 @@ public:
virtual void skidBonusTriggered();
virtual void setPosition (int p);
virtual bool isPlayerController() const {return true;}
virtual bool isNetworkController() const { return false; }
virtual bool isLocalPlayerController() const {return true;}
virtual void reset ();
void resetInputState ();
virtual void finishedRace (float time);

View File

@@ -737,7 +737,7 @@ void Kart::startEngineSFX()
// player karts twice as loud as AIs toghether
const float players_volume = (np * 2.0f) / (np*2.0f + np);
if (m_controller->isPlayerController())
if (m_controller->isLocalPlayerController())
m_engine_sound->setVolume( players_volume / np );
else
m_engine_sound->setVolume( (1.0f - players_volume) / nai );
@@ -808,7 +808,7 @@ void Kart::finishedRace(float time)
// in modes that support it, start end animation
setController(new EndController(this, m_controller->getPlayer(),
m_controller));
if (m_controller->isPlayerController()) // if player is on this computer
if (m_controller->isLocalPlayerController()) // if player is on this computer
{
PlayerProfile *player = PlayerManager::getCurrentPlayer();
const ChallengeStatus *challenge = player->getCurrentChallengeStatus();
@@ -1475,7 +1475,7 @@ void Kart::handleMaterialSFX(const Material *material)
// multiple listeners. This would make the sounds of all AIs be
// audible at all times. So silence AI karts.
if (s.size()!=0 && (race_manager->getNumPlayers()==1 ||
m_controller->isPlayerController() ) )
m_controller->isLocalPlayerController() ) )
{
m_terrain_sound = SFXManager::get()->createSoundSource(s);
m_terrain_sound->play();
@@ -1557,7 +1557,7 @@ void Kart::handleMaterialGFX()
// has the 'below surface' flag set. Detect if there is a surface
// on top of the kart.
// --------------------------------------------------------------
if (m_controller->isPlayerController() && !hasFinishedRace())
if (m_controller->isLocalPlayerController() && !hasFinishedRace())
{
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
{

View File

@@ -840,7 +840,7 @@ void LinearWorld::updateRacePosition()
*/
void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
{
if (!m_karts[i]->getController()->isPlayerController())
if (!m_karts[i]->getController()->isLocalPlayerController())
return;
float wrongway_counter = m_karts[i]->getWrongwayCounter();

View File

@@ -1079,9 +1079,9 @@ void World::updateHighscores(int* best_highscore_rank, int* best_finish_time,
continue;
}
// Only record times for player karts and only if
// Only record times for local player karts and only if
// they finished the race
if(!m_karts[index[pos]]->getController()->isPlayerController())
if(!m_karts[index[pos]]->getController()->isLocalPlayerController())
continue;
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
@@ -1126,8 +1126,7 @@ AbstractKart *World::getPlayerKart(unsigned int n) const
unsigned int count=-1;
for(unsigned int i=0; i<m_karts.size(); i++)
if(m_karts[i]->getController()->isPlayerController() ||
m_karts[i]->getController()->isNetworkController())
if(m_karts[i]->getController()->isPlayerController())
{
count++;
if(count==n) return m_karts[i];
@@ -1170,7 +1169,7 @@ void World::eliminateKart(int kart_id, bool notify_of_elimination)
} // for i < number of cameras
} // if notify_of_elimination
if(kart->getController()->isPlayerController())
if(kart->getController()->isLocalPlayerController())
{
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
{

View File

@@ -526,11 +526,11 @@ void ClientLobbyRoomProtocol::kartSelectionRefused(Event* event)
* \param event : Event providing the information.
*
* Format of the data :
* Byte 0 1 2 3 N+3
* ------------------------------------------------
* Size | 1 | 1 | 1 | N |
* Data | 1 | race id | N (kart name size) | kart name |
* ------------------------------------------------
* Byte 0 1 2 3 N+3
* --------------------------------------------------
* Size | 1 | 1 | 1 | N |
* Data | 1 | player id | N (kart name size) | kart name |
* --------------------------------------------------
*/
void ClientLobbyRoomProtocol::kartSelectionUpdate(Event* event)
{

View File

@@ -820,8 +820,7 @@ void RaceManager::kartFinishedRace(const AbstractKart *kart, float time)
m_kart_status[id].m_overall_time += time;
m_kart_status[id].m_last_time = time;
m_num_finished_karts ++;
if(kart->getController()->isPlayerController() ||
kart->getController()->isNetworkController())
if(kart->getController()->isPlayerController())
m_num_finished_players++;
} // kartFinishedRace

View File

@@ -382,7 +382,7 @@ void RaceGUI::drawGlobalMiniMap()
// int marker_height = m_marker->getSize().Height;
core::rect<s32> source(core::position2di(0, 0), icon->getSize());
int marker_half_size = (kart->getController()->isPlayerController()
int marker_half_size = (kart->getController()->isLocalPlayerController()
? m_minimap_player_size
: m_minimap_ai_size )>>1;
core::rect<s32> position(m_map_left+(int)(draw_at.getX()-marker_half_size),

View File

@@ -849,13 +849,13 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
// draw icon
video::ITexture *icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
int w =
kart->getController()->isPlayerController() ? ICON_PLAYER_WIDTH
: ICON_WIDTH;
int w = kart->getController()
->isLocalPlayerController() ? ICON_PLAYER_WIDTH
: ICON_WIDTH;
const core::rect<s32> pos(x, y, x+w, y+w);
//to bring to light the player's icon: add a background
if (kart->getController()->isPlayerController())
if (kart->getController()->isLocalPlayerController())
{
video::SColor colors[4];
for (unsigned int i=0;i<4;i++)

View File

@@ -356,7 +356,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
if(kart->isEliminated()) continue; // don't draw eliminated kart
// Make sure to only draw AI kart icons first, then
// only player karts.
if(kart->getController()->isPlayerController()
if(kart->getController()->isLocalPlayerController()
!=(only_draw_player_kart==1)) continue;
kart_xyz= kart->getXYZ();
Vec3 draw_at;
@@ -364,7 +364,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
video::ITexture* icon = kart->getKartProperties()->getMinimapIcon();
core::rect<s32> source(core::position2di(0, 0), icon->getSize());
int marker_half_size = (kart->getController()->isPlayerController()
int marker_half_size = (kart->getController()->isLocalPlayerController()
? m_minimap_player_size
: m_minimap_challenge_size )>>1;
core::rect<s32> position(m_map_left+(int)(draw_at.getX()-marker_half_size),
@@ -373,7 +373,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
lower_y -(int)(draw_at.getY()-marker_half_size));
// Highlight the player icons with some backgorund image.
if (kart->getController()->isPlayerController())
if (kart->getController()->isLocalPlayerController())
{
video::SColor colors[4];
for (unsigned int i=0;i<4;i++)

View File

@@ -458,15 +458,15 @@ void RaceResultGUI::determineTableLayout()
const AbstractKart *kart = rank_world->getKartAtPosition(position);
// Save a pointer to the current row_info entry
RowInfo *ri = &(m_all_row_infos[position-first_position]);
ri->m_is_player_kart = kart->getController()->isPlayerController();
ri->m_kart_name = translations->fribidize(kart->getName());
ri->m_player = ri->m_is_player_kart
? kart->getController()->getPlayer() : NULL;
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 =
video::ITexture *icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
ri->m_kart_icon = icon;
ri->m_kart_icon = icon;
// FTL karts will get a time assigned, they are not shown as eliminated
if (kart->isEliminated() &&
@@ -828,7 +828,7 @@ void RaceResultGUI::determineGPLayout()
ri->m_kart_icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
ri->m_kart_name = translations->fribidize(kart->getName());
ri->m_is_player_kart = kart->getController()->isPlayerController();
ri->m_is_player_kart = kart->getController()->isLocalPlayerController();
ri->m_player = ri->m_is_player_kart
? kart->getController()->getPlayer() : NULL;

View File

@@ -131,7 +131,7 @@ void addAttachment(Attachment::AttachmentType type)
for (unsigned int i = 0; i < world->getNumKarts(); i++)
{
AbstractKart *kart = world->getKart(i);
if (!kart->getController()->isPlayerController())
if (!kart->getController()->isLocalPlayerController())
continue;
if (type == Attachment::ATTACH_ANVIL)
{