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
This commit is contained in:
hikerstk 2011-08-25 22:02:29 +00:00
parent d9cd6cec9b
commit f3355f2484
10 changed files with 138 additions and 129 deletions

View File

@ -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.

View File

@ -24,6 +24,7 @@ namespace irr
{
namespace scene { class IMesh; }
}
#include <irrString.h>
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

View File

@ -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

View File

@ -27,6 +27,7 @@ namespace irr
{
namespace scene { class IMesh; }
}
#include <irrString.h>
#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); }
// ------------------------------------------------------------------------

View File

@ -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;

View File

@ -27,9 +27,9 @@ namespace irr
{
namespace scene { class IMesh; }
}
#include <irrString.h>
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

View File

@ -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();

View File

@ -23,6 +23,9 @@
#ifndef HEADER_MISSILE_HPP
#define HEADER_MISSILE_HPP
#include <irrString.h>
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);
// ------------------------------------------------------------------------

View File

@ -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.

View File

@ -20,6 +20,8 @@
#ifndef HEADER_RUBBER_BALL_HPP
#define HEADER_RUBBER_BALL_HPP
#include <irrString.h>
#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. */