From f3355f2484b928b6186b0860d1ce7827eec20731 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 25 Aug 2011 22:02:29 +0000 Subject: [PATCH] Refactored the 'hit strings' displayed in the gui. Now each flyable object has to have a 'getHitString' function (instead of the hard coded global functions like getBowlingString etc). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9622 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/items/bowling.cpp | 47 +++++++++++++++- src/items/bowling.hpp | 5 +- src/items/cake.cpp | 21 ++++++++ src/items/cake.hpp | 4 +- src/items/flyable.cpp | 111 +++----------------------------------- src/items/flyable.hpp | 9 ++-- src/items/plunger.cpp | 43 ++++++++------- src/items/plunger.hpp | 4 ++ src/items/rubber_ball.cpp | 18 +++++++ src/items/rubber_ball.hpp | 5 +- 10 files changed, 138 insertions(+), 129 deletions(-) diff --git a/src/items/bowling.cpp b/src/items/bowling.cpp index c81eb468c..f9d2e9303 100644 --- a/src/items/bowling.cpp +++ b/src/items/bowling.cpp @@ -89,7 +89,52 @@ void Bowling::init(const XMLNode &node, scene::IMesh *bowling) node.get("force-to-target", &m_st_force_to_target); } // init -// ----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +/** Picks a random message to be displayed when a kart is hit by a bowling + * ball. This function picks a different message if a kart hit itself. + * \param kart The kart that was hit. + * \returns The string to display. + */ +const core::stringw Bowling::getHitString(const Kart *kart) const +{ + RandomGenerator r; + + if(kart!=m_owner) + { + const int BOWLING_STRINGS_AMOUNT = 3; + switch (r.get(BOWLING_STRINGS_AMOUNT)) + { + //I18N: shown when hit by bowling ball. %1 is the attacker, %0 is + // the victim. + case 0 : return _LTR("%0 will not go bowling with %1 again"); + //I18N: shown when hit by bowling ball. %1 is the attacker, %0 is + // the victim. + case 1 : return _LTR("%1 strikes %0"); + //I18N: shown when hit by bowling ball. %1 is the attacker, %0 is + // the victim. + case 2 : return _LTR("%0 is bowled over by %1"); + default: assert(false); return L""; // avoid compiler warning + } + } + else + { + const int SELFBOWLING_STRINGS_AMOUNT = 3; + switch (r.get(SELFBOWLING_STRINGS_AMOUNT)) + { + //I18N: shown when hit by own bowling ball. %s is the kart. + case 0 : return _LTR("%s is practicing with a blue, big, spheric yo-yo"); + //I18N: shown when hit by own bowling ball. %s is the kart. + case 1 : return _LTR("%s is the world master of the boomerang ball"); + //I18N: shown when hit by own bowling ball. %s is the kart. + case 2 : return _LTR("%s should play (rubber) darts instead of bowling"); + default: assert(false); return L""; // avoid compiler warning + } // switch + } // if kart_hit==owner + + +} // getHitString + +// ---------------------------------------------------------------------------- /** Updates the bowling ball ineach frame. If this function returns true, the * object will be removed by the projectile manager. * \param dt Time step size. diff --git a/src/items/bowling.hpp b/src/items/bowling.hpp index fd2b9c75c..b17ded6d2 100644 --- a/src/items/bowling.hpp +++ b/src/items/bowling.hpp @@ -24,6 +24,7 @@ namespace irr { namespace scene { class IMesh; } } +#include using namespace irr; #include "items/flyable.hpp" @@ -44,7 +45,9 @@ public: Bowling(Kart* kart); static void init(const XMLNode &node, scene::IMesh *bowling); virtual bool updateAndDelete(float dt); - + virtual const core::stringw getHitString(const Kart *kart) const; + + /** Returns the sfx to use when the bowling ball explodes. */ const char* getExplosionSound() const { return "strike"; } }; // Bowling diff --git a/src/items/cake.cpp b/src/items/cake.cpp index a7a671664..9f3212870 100644 --- a/src/items/cake.cpp +++ b/src/items/cake.cpp @@ -133,3 +133,24 @@ void Cake::init(const XMLNode &node, scene::IMesh *cake_model) node.get("max-distance", &m_st_max_distance ); m_st_max_distance_squared = m_st_max_distance*m_st_max_distance; } // init + +// ---------------------------------------------------------------------------- +/** Picks a random message to be displayed when a kart is hit by a cake. + * \param The kart that was hit (ignored here). + * \returns The string to display. + */ +const core::stringw Cake::getHitString(const Kart *kart) const +{ + const int CAKE_STRINGS_AMOUNT = 3; + RandomGenerator r; + switch (r.get(CAKE_STRINGS_AMOUNT)) + { + //I18N: shown when hit by cake. %1 is the attacker, %0 is the victim. + case 0: return _LTR("%0 eats too much of %1's cake"); + //I18N: shown when hit by cake. %1 is the attacker, %0 is the victim. + case 1: return _LTR("%0 is dubious of %1's cooking skills"); + //I18N: shown when hit by cake. %1 is the attacker, %0 is the victim. + case 2: return _LTR("%0 should not play with %1's lunch"); + default: assert(false); return L""; // avoid compiler warning + } +} // getHitString diff --git a/src/items/cake.hpp b/src/items/cake.hpp index 592537dbb..06c51dcf5 100644 --- a/src/items/cake.hpp +++ b/src/items/cake.hpp @@ -27,6 +27,7 @@ namespace irr { namespace scene { class IMesh; } } +#include #include "items/flyable.hpp" @@ -46,8 +47,9 @@ private: Kart* m_target; // which kart is targeted by this // projectile (NULL if none) public: - Cake (Kart *kart); + Cake (Kart *kart); static void init (const XMLNode &node, scene::IMesh *cake_model); + virtual const core::stringw getHitString(const Kart *kart) const; // ------------------------------------------------------------------------ virtual void hitTrack () { hit(NULL); } // ------------------------------------------------------------------------ diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index 3939e87f7..c0c49e820 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -43,67 +43,6 @@ #include "utils/constants.hpp" #include "utils/string_utils.hpp" - -const wchar_t* getCakeString() -{ - const int CAKE_STRINGS_AMOUNT = 3; - - RandomGenerator r; - const int id = r.get(CAKE_STRINGS_AMOUNT); - - switch (id) - { - //I18N: shown when hit by cake. %1 is the attacker, %0 is the victim. - case 0: return _LTR("%0 eats too much of %1's cake"); - //I18N: shown when hit by cake. %1 is the attacker, %0 is the victim. - case 1: return _LTR("%0 is dubious of %1's cooking skills"); - //I18N: shown when hit by cake. %1 is the attacker, %0 is the victim. - case 2: return _LTR("%0 should not play with %1's lunch"); - default: assert(false); return L""; // avoid compiler warning - } -} - - -const wchar_t* getBowlingString() -{ - const int BOWLING_STRINGS_AMOUNT = 3; - - RandomGenerator r; - const int id = r.get(BOWLING_STRINGS_AMOUNT); - - switch (id) - { - //I18N: shown when hit by bowling ball. %1 is the attacker, %0 is the victim. - case 0 : return _LTR("%0 will not go bowling with %1 again"); - //I18N: shown when hit by bowling ball. %1 is the attacker, %0 is the victim. - case 1 : return _LTR("%1 strikes %0"); - //I18N: shown when hit by bowling ball. %1 is the attacker, %0 is the victim. - case 2 : return _LTR("%0 is bowled over by %1"); - default: assert(false); return L""; // avoid compiler warning - } -} - - -const wchar_t* getSelfBowlingString() -{ - const int SELFBOWLING_STRINGS_AMOUNT = 3; - - RandomGenerator r; - const int id = r.get(SELFBOWLING_STRINGS_AMOUNT); - - switch (id) - { - //I18N: shown when hit by own bowling ball. %s is the kart. - case 0 : return _LTR("%s is practicing with a blue, big, spheric yo-yo"); - //I18N: shown when hit by own bowling ball. %s is the kart. - case 1 : return _LTR("%s is the world master of the boomerang ball"); - //I18N: shown when hit by own bowling ball. %s is the kart. - case 2 : return _LTR("%s should play (rubber) darts instead of bowling"); - default: assert(false); return L""; // avoid compiler warning - } -} - - // static variables: float Flyable::m_st_speed [PowerupManager::POWERUP_MAX]; scene::IMesh* Flyable::m_st_model [PowerupManager::POWERUP_MAX]; @@ -492,48 +431,14 @@ void Flyable::hit(Kart *kart_hit, PhysicalObject* object) if (kart_hit != NULL) { RaceGUIBase* gui = World::getWorld()->getRaceGUI(); - irr::core::stringw hit_message; - switch(m_type) - { - case PowerupManager::POWERUP_CAKE: - { - hit_message = - StringUtils::insertValues(getCakeString(), - core::stringw(kart_hit->getName()), - core::stringw(m_owner->getName()) - ).c_str(); - } - break; - case PowerupManager::POWERUP_PLUNGER: - // Handled by plunger.cpp Plunger::hit - break; - case PowerupManager::POWERUP_RUBBERBALL: - break; - case PowerupManager::POWERUP_BOWLING: - { - if (kart_hit == m_owner) - { - hit_message = - StringUtils::insertValues(getSelfBowlingString(), - core::stringw(m_owner->getName()) - ).c_str(); - } - else - { - hit_message = - StringUtils::insertValues(getBowlingString(), - core::stringw(kart_hit->getName()), - core::stringw(m_owner->getName()) - ).c_str(); - } - } - break; - default: - printf("Failed message for %i\n", m_type); - assert(false); - } - gui->addMessage(translations->fribidize(hit_message), NULL, 3.0f, 40, - video::SColor(255, 255, 255, 255), false); + irr::core::stringw hit_message = + StringUtils::insertValues(getHitString(kart_hit), + core::stringw(kart_hit->getName()), + core::stringw(m_owner ->getName()) + ); + if(hit_message.size()>0) + gui->addMessage(translations->fribidize(hit_message), NULL, 3.0f, + 40, video::SColor(255, 255, 255, 255), false); } m_has_hit_something=true; diff --git a/src/items/flyable.hpp b/src/items/flyable.hpp index 01822708e..d32ada461 100644 --- a/src/items/flyable.hpp +++ b/src/items/flyable.hpp @@ -27,9 +27,9 @@ namespace irr { namespace scene { class IMesh; } } +#include using namespace irr; -#include "audio/sfx_manager.hpp" #include "items/powerup_manager.hpp" #include "karts/moveable.hpp" #include "tracks/terrain_info.hpp" @@ -154,11 +154,12 @@ public: virtual ~Flyable (); static void init (const XMLNode &node, scene::IMesh *model, PowerupManager::PowerupType type); - virtual bool updateAndDelete(float); - virtual HitEffect *getHitEffect() const; + virtual bool updateAndDelete(float); + virtual const core::stringw getHitString(const Kart *kart) const = 0; + virtual HitEffect* getHitEffect() const; void updateFromServer(const FlyableInfo &f, float dt); bool isOwnerImmunity(const Kart *kart_hit) const; - virtual void hit (Kart* kart, PhysicalObject* obj=NULL); + virtual void hit(Kart* kart, PhysicalObject* obj=NULL); void explode(Kart* kart, PhysicalObject* obj=NULL); // ------------------------------------------------------------------------ /** If true the up velocity of the flyable will be adjust so that the diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 220f5ba23..914258e36 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -34,23 +34,6 @@ #include "utils/string_utils.hpp" -const wchar_t* getPlungerInFaceString() -{ - const int PLUNGER_IN_FACE_STRINGS_AMOUNT = 2; - - RandomGenerator r; - const int id = r.get(PLUNGER_IN_FACE_STRINGS_AMOUNT); - - switch (id) - { - //I18N: shown when a player receives a plunger in his face - case 0: return _LTR("%0 gets a fancy mask from %1"); - //I18N: shown when a player receives a plunger in his face - case 1: return _LTR("%1 merges %0's face with a plunger"); - default:assert(false); return L""; // avoid compiler warning - } -} - // ----------------------------------------------------------------------------- Plunger::Plunger(Kart *kart) : Flyable(kart, PowerupManager::POWERUP_PLUNGER) @@ -132,6 +115,30 @@ void Plunger::init(const XMLNode &node, scene::IMesh *plunger_model) } // init // ---------------------------------------------------------------------------- +/** Picks a random message to be displayed when a kart is hit by a plunger. + * \param The kart that was hit (ignored here). + * \returns The string to display. + */ +const core::stringw Plunger::getHitString(const Kart *kart) const +{ + const int PLUNGER_IN_FACE_STRINGS_AMOUNT = 2; + RandomGenerator r; + switch (r.get(PLUNGER_IN_FACE_STRINGS_AMOUNT)) + { + //I18N: shown when a player receives a plunger in his face + case 0: return _LTR("%0 gets a fancy mask from %1"); + //I18N: shown when a player receives a plunger in his face + case 1: return _LTR("%1 merges %0's face with a plunger"); + default:assert(false); return L""; // avoid compiler warning + } +} // getHitString + +// ---------------------------------------------------------------------------- +/** Updates the bowling ball ineach frame. If this function returns true, the + * object will be removed by the projectile manager. + * \param dt Time step size. + * \returns True of this object should be removed. + */ bool Plunger::updateAndDelete(float dt) { // In keep-alive mode, just update the rubber band @@ -178,7 +185,7 @@ void Plunger::hit(Kart *kart, PhysicalObject *obj) { kart->blockViewWithPlunger(); - hit_message += StringUtils::insertValues(getPlungerInFaceString(), + hit_message += StringUtils::insertValues(getHitString(kart), core::stringw(kart->getName()), core::stringw(m_owner->getName()) ).c_str(); diff --git a/src/items/plunger.hpp b/src/items/plunger.hpp index 852155fa2..065999008 100644 --- a/src/items/plunger.hpp +++ b/src/items/plunger.hpp @@ -23,6 +23,9 @@ #ifndef HEADER_MISSILE_HPP #define HEADER_MISSILE_HPP +#include +using namespace irr; + #include "items/flyable.hpp" class Kart; @@ -49,6 +52,7 @@ public: static void init(const XMLNode &node, scene::IMesh* missile); virtual bool updateAndDelete(float dt); virtual void hitTrack (); + virtual const core::stringw getHitString(const Kart *kart) const; virtual void hit (Kart *kart, PhysicalObject *obj=NULL); // ------------------------------------------------------------------------ diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index de6101bae..7d9f90ca4 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -213,6 +213,24 @@ void RubberBall::init(const XMLNode &node, scene::IMesh *bowling) Flyable::init(node, bowling, PowerupManager::POWERUP_RUBBERBALL); } // init +// ---------------------------------------------------------------------------- +/** Picks a random message to be displayed when a kart is hit by the + * rubber ball. + * \param The kart that was hit (ignored here). + * \returns The string to display. + */ +const core::stringw RubberBall::getHitString(const Kart *kart) const +{ + const int COUNT = 1; + RandomGenerator r; + switch (r.get(COUNT)) + { + //I18N: shown when a player is hit by a rubber ball. %1 is the + // attacker, %0 is the victim. + case 0: return _LTR("%s is being bounced around."); + default:assert(false); return L""; // avoid compiler warning + } +} // getHitString // ---------------------------------------------------------------------------- /** Updates the rubber ball. diff --git a/src/items/rubber_ball.hpp b/src/items/rubber_ball.hpp index 72908ff39..bfe1c9a84 100644 --- a/src/items/rubber_ball.hpp +++ b/src/items/rubber_ball.hpp @@ -20,6 +20,8 @@ #ifndef HEADER_RUBBER_BALL_HPP #define HEADER_RUBBER_BALL_HPP +#include + #include "items/flyable.hpp" #include "tracks/track_sector.hpp" @@ -126,7 +128,8 @@ public: virtual ~RubberBall(); static void init(const XMLNode &node, scene::IMesh *bowling); virtual bool updateAndDelete(float dt); - virtual void hit (Kart* kart, PhysicalObject* obj=NULL); + virtual void hit(Kart* kart, PhysicalObject* obj=NULL); + virtual const core::stringw getHitString(const Kart *kart) const; // ------------------------------------------------------------------------ /** This object does not create an explosion, all affects on * karts are handled by this hit() function. */