Use ItemState instead of Item as paramter for kart's collectedItem.

This commit is contained in:
hiker
2018-05-28 00:20:37 +10:00
parent d0e95d0d63
commit 755cd8095b
13 changed files with 29 additions and 23 deletions

View File

@@ -40,6 +40,7 @@ class btKart;
class btQuaternion;
class Controller;
class Item;
class ItemState;
class KartGFX;
class KartModel;
class KartProperties;
@@ -340,7 +341,7 @@ public:
/** Called when an item is collected. It will either adjust the collected
* energy, or update the attachment or powerup for this kart.
* \param item The item that was hit. */
virtual void collectedItem(Item *item) = 0;
virtual void collectedItem(ItemState *item_state) = 0;
// ------------------------------------------------------------------------
/** Returns the current position of this kart in the race. */
virtual int getPosition() const = 0;

View File

@@ -93,7 +93,7 @@ public:
virtual void crashed(const AbstractKart *k) OVERRIDE {};
virtual void handleZipper(bool play_sound) OVERRIDE {};
virtual void finishedRace(float time) OVERRIDE {};
virtual void collectedItem(const Item &item,
virtual void collectedItem(const ItemState &item,
float previous_energy=0) OVERRIDE {};
virtual void setPosition(int p) OVERRIDE {};
virtual bool isPlayerController() const OVERRIDE { return false; }

View File

@@ -34,7 +34,7 @@ class BareNetworkString;
class AbstractKart;
class BareNetworString;
class Item;
class ItemState;
class KartControl;
class Material;
@@ -63,7 +63,7 @@ public:
virtual void reset () = 0;
virtual void update (int ticks) = 0;
virtual void handleZipper (bool play_sound) = 0;
virtual void collectedItem (const Item &item,
virtual void collectedItem (const ItemState &item,
float previous_energy=0) = 0;
virtual void crashed (const AbstractKart *k) = 0;
virtual void crashed (const Material *m) = 0;

View File

@@ -53,7 +53,7 @@ public:
virtual void crashed(const AbstractKart *k) OVERRIDE {}
virtual void handleZipper(bool play_sound) OVERRIDE {}
virtual void finishedRace(float time) OVERRIDE {}
virtual void collectedItem(const Item &item,
virtual void collectedItem(const ItemState &item,
float previous_energy=0) OVERRIDE {}
virtual void setPosition(int p) OVERRIDE {}
virtual bool isPlayerController() const OVERRIDE { return false; }

View File

@@ -331,7 +331,8 @@ void LocalPlayerController::handleZipper(bool play_sound)
* \param item Item that was collected.
* \param old_energy The previous energy value
*/
void LocalPlayerController::collectedItem(const Item &item , float old_energy)
void LocalPlayerController::collectedItem(const ItemState &item_state,
float old_energy)
{
if (old_energy < m_kart->getKartProperties()->getNitroMax() &&
m_kart->getEnergy() == m_kart->getKartProperties()->getNitroMax())
@@ -346,7 +347,7 @@ void LocalPlayerController::collectedItem(const Item &item , float old_energy)
}
else
{
switch(item.getType())
switch(item_state.getType())
{
case Item::ITEM_BANANA:
m_kart->playSound(m_ugh_sound);

View File

@@ -64,7 +64,7 @@ public:
bool action (PlayerAction action, int value,
bool dry_run=false) OVERRIDE;
virtual void handleZipper (bool play_sound) OVERRIDE;
void collectedItem (const Item &item,
void collectedItem (const ItemState &item,
float previous_energy=0) OVERRIDE;
virtual void setPosition (int p) OVERRIDE;
virtual void reset () OVERRIDE;

View File

@@ -55,7 +55,7 @@ public:
virtual void saveState(BareNetworkString *buffer) const OVERRIDE;
virtual void rewindTo(BareNetworkString *buffer) OVERRIDE;
// ------------------------------------------------------------------------
virtual void collectedItem(const Item &item,
virtual void collectedItem(const ItemState &item,
float previous_energy=0 ) OVERRIDE { };
// ------------------------------------------------------------------------
virtual bool isPlayerController() const OVERRIDE { return true; }

View File

@@ -50,6 +50,7 @@
#include <line3d.h>
class Item;
class LinearWorld;
class Track;

View File

@@ -51,6 +51,8 @@
#include <line3d.h>
class Item;
#ifdef AI_DEBUG
class ShowCurve;

16
src/karts/kart.cpp Executable file → Normal file
View File

@@ -1037,17 +1037,17 @@ void Kart::setRaceResult()
//-----------------------------------------------------------------------------
/** Called when an item is collected. It will either adjust the collected
* energy, or update the attachment or powerup for this kart.
* \param item The item that was hit.
* \param item_state The item that was hit.
*/
void Kart::collectedItem(Item *item)
void Kart::collectedItem(ItemState *item_state)
{
float old_energy = m_collected_energy;
const Item::ItemType type = item->getType();
const Item::ItemType type = item_state->getType();
switch (type)
{
case Item::ITEM_BANANA:
m_attachment->hitBanana(item);
m_attachment->hitBanana(item_state);
break;
case Item::ITEM_NITRO_SMALL:
m_collected_energy += m_kart_properties->getNitroSmallContainer();
@@ -1057,13 +1057,13 @@ void Kart::collectedItem(Item *item)
break;
case Item::ITEM_BONUS_BOX :
{
m_powerup->hitBonusBox(*item);
m_powerup->hitBonusBox(*item_state);
break;
}
case Item::ITEM_BUBBLEGUM:
m_has_caught_nolok_bubblegum =
(item->getPreviousOwner()&&
item->getPreviousOwner()->getIdent() == "nolok");
(item_state->getPreviousOwner()&&
item_state->getPreviousOwner()->getIdent() == "nolok");
// slow down
m_bubblegum_ticks =
@@ -1085,7 +1085,7 @@ void Kart::collectedItem(Item *item)
if ( m_collected_energy > m_kart_properties->getNitroMax())
m_collected_energy = m_kart_properties->getNitroMax();
m_controller->collectedItem(*item, old_energy);
m_controller->collectedItem(*item_state, old_energy);
} // collectedItem

View File

@@ -41,6 +41,7 @@ class btUprightConstraint;
class Controller;
class HitEffect;
class Item;
class ItemState;
class KartGFX;
class KartRewinder;
class MaxSpeed;
@@ -288,7 +289,7 @@ public:
virtual int getSpeedIncreaseTicksLeft(unsigned int category) const;
virtual void setBoostAI (bool boosted);
virtual bool getBoostAI () const;
virtual void collectedItem(Item *item) OVERRIDE;
virtual void collectedItem(ItemState *item) OVERRIDE;
virtual float getStartupBoost() const;
virtual const Material *getMaterial() const;

View File

@@ -100,12 +100,12 @@ void KartWithStats::setKartAnimation(AbstractKartAnimation *ka)
// ----------------------------------------------------------------------------
/** Called when an item is collected. It will increment private variables that
* represent counters for each type of item hit.
* \param item The item that was hit.
* \param item_state The item that was hit.
*/
void KartWithStats::collectedItem(Item *item)
void KartWithStats::collectedItem(ItemState *item_state)
{
Kart::collectedItem(item);
const Item::ItemType type = item->getType();
Kart::collectedItem(item_state);
const Item::ItemType type = item_state->getType();
switch (type)
{

View File

@@ -78,7 +78,7 @@ public:
PerPlayerDifficulty difficulty);
virtual void update(int ticks) OVERRIDE;
virtual void reset() OVERRIDE;
virtual void collectedItem(Item *item) OVERRIDE;
virtual void collectedItem(ItemState *item_state) OVERRIDE;
virtual void setKartAnimation(AbstractKartAnimation *ka) OVERRIDE;
/** Returns the top speed of this kart. */