Added a generic collectedItem() virtual function to world

instead of a special case of easter eggs only.
This commit is contained in:
hiker
2018-05-04 10:29:44 +10:00
parent 10ce48b86f
commit 3e518968b3
5 changed files with 18 additions and 14 deletions

View File

@@ -118,6 +118,10 @@ private:
* will always reappear after a while. */
int m_used_up_counter;
protected:
// ------------------------------------------------------------------------
void setType(ItemType type) { m_type = type; }
public:
/** Constructor. */
ItemState(ItemType type)
@@ -176,7 +180,7 @@ public:
{
// triggers should not be switched
if (m_type == ITEM_TRIGGER) return true;
// If the item is not switched, do nothing. This can happen if a bubble
// If the item is not switched, do nothing. This can happen if a bubble
// gum is dropped while items are switched - when switching back, this
// bubble gum has no original type.
if (m_original_type == ITEM_NONE)
@@ -213,8 +217,6 @@ public:
/** Returns the type of this item. */
ItemType getType() const { return m_type; }
// ------------------------------------------------------------------------
void setType(ItemType type) { m_type = type; }
// ------------------------------------------------------------------------
/** Sets the index of this item in the item manager list. */
void setItemId(unsigned int n) { m_item_id = n; }
// ------------------------------------------------------------------------

View File

@@ -308,12 +308,8 @@ void ItemManager::collectedItem(Item *item, AbstractKart *kart, int add_info)
return;
}
item->collected(kart, stk_config->time2Ticks(2.0f));
if (item->getType() == ItemState::ITEM_EASTER_EGG)
{
EasterEggHunt *world = dynamic_cast<EasterEggHunt*>(World::getWorld());
assert(world);
world->collectedEasterEgg(kart);
}
// Inform the world - used for Easter egg hunt
World::getWorld()->collectedItem(kart, item);
kart->collectedItem(item, add_info);
} // collectedItem

View File

@@ -148,7 +148,7 @@ const std::string& EasterEggHunt::getIdent() const
/** Called when a kart has collected an egg.
* \param kart The kart that collected an egg.
*/
void EasterEggHunt::collectedEasterEgg(const AbstractKart *kart)
void EasterEggHunt::collectedItem(const AbstractKart *kart, const Item *item)
{
m_eggs_collected[kart->getWorldKartId()]++;
m_eggs_found++;

View File

@@ -21,6 +21,7 @@
#include "modes/linear_world.hpp"
#include "states_screens/race_gui_base.hpp"
#include "utils/cpp2011.hpp"
#include <string>
#include <vector>
@@ -59,10 +60,11 @@ public:
virtual void terminateRace() OVERRIDE;
virtual void update(int ticks) OVERRIDE;
virtual void getKartsDisplayInfo(
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
virtual void collectedItem(const AbstractKart *kart,
const Item *item ) OVERRIDE;
void updateKartRanks();
void collectedEasterEgg(const AbstractKart *kart);
void readData(const std::string &filename);
virtual void checkForWrongDirection(unsigned int i, float dt) OVERRIDE;

View File

@@ -40,6 +40,7 @@
class AbstractKart;
class btRigidBody;
class Controller;
class Item;
class PhysicalObject;
namespace Scripting
@@ -242,8 +243,11 @@ public:
virtual void unpause() OVERRIDE;
virtual void getDefaultCollectibles(int *collectible_type,
int *amount );
virtual void endRaceEarly() { return; }
// ------------------------------------------------------------------------
/** Receives notification if an item is collected. Used for easter eggs. */
virtual void collectedItem(const AbstractKart *kart, const Item *item) {}
// ------------------------------------------------------------------------
virtual void endRaceEarly() { return; }
// ------------------------------------------------------------------------
/** Called to determine whether this race mode uses bonus boxes. */
virtual bool haveBonusBoxes() { return true; }