Started to use ItemState instead of Item in the attachment and

powerup callbacks on item collection.
This commit is contained in:
hiker 2018-05-27 00:42:21 +10:00
parent 89ded35c21
commit 079b5abe2a
4 changed files with 13 additions and 12 deletions

View File

@ -317,7 +317,7 @@ void Attachment::rewind(BareNetworkString *buffer)
* server, the new item is based on the current world time. * server, the new item is based on the current world time.
* \param item The item that was collected. * \param item The item that was collected.
*/ */
void Attachment::hitBanana(Item *item) void Attachment::hitBanana(ItemState *item_state)
{ {
// Don't keep on getting achievements due to rewind! // Don't keep on getting achievements due to rewind!
if (m_kart->getController()->canGetAchievements() && if (m_kart->getController()->canGetAchievements() &&
@ -369,9 +369,9 @@ void Attachment::hitBanana(Item *item)
// same banana again once the explosion animation is finished, giving // same banana again once the explosion animation is finished, giving
// the kart the same penalty twice. // the kart the same penalty twice.
int ticks = int ticks =
std::max(item->getTicksTillReturn(), std::max(item_state->getTicksTillReturn(),
stk_config->time2Ticks(kp->getExplosionDuration() + 2.0f)); stk_config->time2Ticks(kp->getExplosionDuration() + 2.0f));
item->setTicksTillReturn(ticks); item_state->setTicksTillReturn(ticks);
break; break;
} }
case ATTACH_ANVIL: case ATTACH_ANVIL:

View File

@ -30,7 +30,7 @@ using namespace irr;
class AbstractKart; class AbstractKart;
class BareNetworkString; class BareNetworkString;
class Item; class ItemState;
class SFXBase; class SFXBase;
/** This objects is permanently available in a kart and stores information /** This objects is permanently available in a kart and stores information
@ -115,7 +115,7 @@ public:
Attachment(AbstractKart* kart); Attachment(AbstractKart* kart);
~Attachment(); ~Attachment();
void clear (); void clear ();
void hitBanana(Item *item); void hitBanana(ItemState *item);
void update(int ticks); void update(int ticks);
void handleCollisionWithKart(AbstractKart *other); void handleCollisionWithKart(AbstractKart *other);
void set (AttachmentType type, int ticks, void set (AttachmentType type, int ticks,

11
src/items/powerup.cpp Normal file → Executable file
View File

@ -445,11 +445,11 @@ void Powerup::use()
* or on a client, in which case the item and additional info is used * or on a client, in which case the item and additional info is used
* to make sure server and clients are synched correctly. * to make sure server and clients are synched correctly.
* \param n * \param n
* \param item The item (bonux box) that was hit. This is necessary * \param item_state The item_state (bonux box) that was hit. This is
* for servers so that the clients can be informed which item * necessary for servers so that the clients can be informed which
* was collected. * item was collected.
*/ */
void Powerup::hitBonusBox(const Item &item) void Powerup::hitBonusBox(const ItemState &item_state)
{ {
// Position can be -1 in case of a battle mode (which doesn't have // Position can be -1 in case of a battle mode (which doesn't have
// positions), but this case is properly handled in getRandomPowerup. // positions), but this case is properly handled in getRandomPowerup.
@ -474,9 +474,10 @@ void Powerup::hitBonusBox(const Item &item)
// non-random selection (e.g. by displaying which item is collecte // non-random selection (e.g. by displaying which item is collecte
// where), since it's only around 83 ms - but it is bit more // where), since it's only around 83 ms - but it is bit more
// relaxed when client prediction should be a frame or so earlier. // relaxed when client prediction should be a frame or so earlier.
int random_number = item.getItemId() + world->getTimeTicks() / 10; int random_number = item_state.getItemId() + world->getTimeTicks() / 10;
new_powerup = new_powerup =
powerup_manager->getRandomPowerup(position, &n, random_number); powerup_manager->getRandomPowerup(position, &n, random_number);
new_powerup = PowerupManager::POWERUP_BUBBLEGUM;
if (new_powerup != PowerupManager::POWERUP_RUBBERBALL || if (new_powerup != PowerupManager::POWERUP_RUBBERBALL ||
(world->getTicksSinceStart() - powerup_manager->getBallCollectTicks()) (world->getTicksSinceStart() - powerup_manager->getBallCollectTicks())
> RubberBall::getTicksBetweenRubberBalls()) > RubberBall::getTicksBetweenRubberBalls())

4
src/items/powerup.hpp Normal file → Executable file
View File

@ -27,7 +27,7 @@
class AbstractKart; class AbstractKart;
class BareNetworkString; class BareNetworkString;
class Item; class ItemState;
class SFXBase; class SFXBase;
/** /**
@ -59,7 +59,7 @@ public:
Material* getIcon () const; Material* getIcon () const;
void adjustSound (); void adjustSound ();
void use (); void use ();
void hitBonusBox (const Item &item); void hitBonusBox (const ItemState &item);
void saveState(BareNetworkString *buffer) const; void saveState(BareNetworkString *buffer) const;
void rewindTo(BareNetworkString *buffer); void rewindTo(BareNetworkString *buffer);