Save ticks till return for eating banana with bomb

This commit is contained in:
Benau 2018-09-21 20:06:47 +08:00
parent aa2d944813
commit b1a535b21f
3 changed files with 32 additions and 11 deletions

View File

@ -31,6 +31,7 @@
*/ */
ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count) ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count)
{ {
m_ticks_till_return = 0;
m_type = (EventType)buffer->getUInt8(); m_type = (EventType)buffer->getUInt8();
m_ticks = buffer->getTime(); m_ticks = buffer->getTime();
m_kart_id = buffer->getInt8(); m_kart_id = buffer->getInt8();
@ -41,7 +42,11 @@ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count)
m_xyz = buffer->getVec3(); m_xyz = buffer->getVec3();
*count -= 12; *count -= 12;
} }
else if (m_type == IEI_COLLECT)
{
m_ticks_till_return = buffer->getUInt16();
*count -= 2;
}
} // ItemEventInfo(BareNetworkString, int *count) } // ItemEventInfo(BareNetworkString, int *count)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -55,7 +60,6 @@ void ItemEventInfo::saveState(BareNetworkString *buffer)
.addUInt16(m_index); .addUInt16(m_index);
if(m_type == IEI_NEW) if(m_type == IEI_NEW)
buffer->add(m_xyz); buffer->add(m_xyz);
else if (m_type == IEI_COLLECT)
buffer->addUInt16(m_ticks_till_return);
} // saveState } // saveState

View File

@ -51,13 +51,20 @@ private:
/** In case of new items the position of the new item. */ /** In case of new items the position of the new item. */
Vec3 m_xyz; Vec3 m_xyz;
/** Ticks for the item to return, atm used by collecting banana
* with bomb to delay the return for banana. */
int16_t m_ticks_till_return;
public: public:
/** Constructor for collecting an existing item. /** Constructor for collecting an existing item.
* \param ticks Time of the event. * \param ticks Time of the event.
* \param item_id The index of the item that was collected. * \param item_id The index of the item that was collected.
* \param kart_id the kart that collected the item. */ * \param kart_id the kart that collected the item.
ItemEventInfo(int ticks, int index, int kart_id) * \param ttr Ticks till return after being collected. */
: m_ticks(ticks), m_index(index), m_kart_id(kart_id)
ItemEventInfo(int ticks, int index, int kart_id, int16_t ttr)
: m_ticks(ticks), m_index(index), m_kart_id(kart_id),
m_ticks_till_return(ttr)
{ {
m_type = IEI_COLLECT; m_type = IEI_COLLECT;
} // ItemEventInfo(collected existing item) } // ItemEventInfo(collected existing item)
@ -69,14 +76,15 @@ public:
*/ */
ItemEventInfo(int ticks, ItemState::ItemType type, int index, ItemEventInfo(int ticks, ItemState::ItemType type, int index,
int kart_id, const Vec3 &xyz) int kart_id, const Vec3 &xyz)
: m_ticks(ticks), m_index(index), m_kart_id(kart_id), m_xyz(xyz) : m_ticks(ticks), m_index(index), m_kart_id(kart_id), m_xyz(xyz),
m_ticks_till_return(0)
{ {
m_type = IEI_NEW; m_type = IEI_NEW;
} // ItemEventInfo(new item) } // ItemEventInfo(new item)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** Constructor for switching items. */ /** Constructor for switching items. */
ItemEventInfo(int ticks) : m_ticks(ticks) ItemEventInfo(int ticks) : m_ticks(ticks), m_ticks_till_return(0)
{ {
m_type = IEI_SWITCH; m_type = IEI_SWITCH;
} // ItemEventInfo(switch) } // ItemEventInfo(switch)
@ -116,6 +124,9 @@ public:
return m_xyz; return m_xyz;
} // getXYZ } // getXYZ
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** Returns the ticks till return, used only by collection events. */
int getTicksTillReturn() const { return m_ticks_till_return; }
// --------------------------------------------------------------------
/** Returns the type of this item. Note at this stage only bubble gums /** Returns the type of this item. Note at this stage only bubble gums
* can be created during a race. */ * can be created during a race. */
ItemState::ItemType getNewItemType() const ItemState::ItemType getNewItemType() const

View File

@ -99,13 +99,14 @@ void NetworkItemManager::collectedItem(ItemState *item, AbstractKart *kart)
{ {
if(NetworkConfig::get()->isServer()) if(NetworkConfig::get()->isServer())
{ {
ItemManager::collectedItem(item, kart);
// The server saves the collected item as item event info // The server saves the collected item as item event info
m_item_events.lock(); m_item_events.lock();
m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(), m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(),
item->getItemId(), item->getItemId(),
kart->getWorldKartId() ); kart->getWorldKartId(),
item->getTicksTillReturn());
m_item_events.unlock(); m_item_events.unlock();
ItemManager::collectedItem(item, kart);
} }
else else
{ {
@ -319,6 +320,11 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
int old_time = world->getTicksSinceStart(); // Save time we rewind to int old_time = world->getTicksSinceStart(); // Save time we rewind to
world->setTicksForRewind(iei.getTicks()); // Set time of event world->setTicksForRewind(iei.getTicks()); // Set time of event
collectedItem(m_confirmed_state[index], kart);// Collect item collectedItem(m_confirmed_state[index], kart);// Collect item
// Reset till ticks return from state (required for eating banana with bomb)
int ttr = iei.getTicksTillReturn();
m_confirmed_state[index]->setTicksTillReturn(ttr);
world->setTicksForRewind(old_time); // Set time to rewind-to world->setTicksForRewind(old_time); // Set time to rewind-to
if (m_confirmed_state[index]->isUsedUp()) if (m_confirmed_state[index]->isUsedUp())