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.
* \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!
if (m_kart->getController()->canGetAchievements() &&
@ -369,9 +369,9 @@ void Attachment::hitBanana(Item *item)
// same banana again once the explosion animation is finished, giving
// the kart the same penalty twice.
int ticks =
std::max(item->getTicksTillReturn(),
std::max(item_state->getTicksTillReturn(),
stk_config->time2Ticks(kp->getExplosionDuration() + 2.0f));
item->setTicksTillReturn(ticks);
item_state->setTicksTillReturn(ticks);
break;
}
case ATTACH_ANVIL:

View File

@ -30,7 +30,7 @@ using namespace irr;
class AbstractKart;
class BareNetworkString;
class Item;
class ItemState;
class SFXBase;
/** This objects is permanently available in a kart and stores information
@ -115,7 +115,7 @@ public:
Attachment(AbstractKart* kart);
~Attachment();
void clear ();
void hitBanana(Item *item);
void hitBanana(ItemState *item);
void update(int ticks);
void handleCollisionWithKart(AbstractKart *other);
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
* to make sure server and clients are synched correctly.
* \param n
* \param item The item (bonux box) that was hit. This is necessary
* for servers so that the clients can be informed which item
* was collected.
* \param item_state The item_state (bonux box) that was hit. This is
* necessary for servers so that the clients can be informed which
* 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
// 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
// where), since it's only around 83 ms - but it is bit more
// 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 =
powerup_manager->getRandomPowerup(position, &n, random_number);
new_powerup = PowerupManager::POWERUP_BUBBLEGUM;
if (new_powerup != PowerupManager::POWERUP_RUBBERBALL ||
(world->getTicksSinceStart() - powerup_manager->getBallCollectTicks())
> RubberBall::getTicksBetweenRubberBalls())

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

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