From b1a535b21ffdcdda7b38498fb2e2075bb21da9c5 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 21 Sep 2018 20:06:47 +0800 Subject: [PATCH] Save ticks till return for eating banana with bomb --- src/items/item_event_info.cpp | 12 ++++++++---- src/items/item_event_info.hpp | 21 ++++++++++++++++----- src/items/network_item_manager.cpp | 10 ++++++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/items/item_event_info.cpp b/src/items/item_event_info.cpp index f9d97ea49..6acb38d5b 100644 --- a/src/items/item_event_info.cpp +++ b/src/items/item_event_info.cpp @@ -31,6 +31,7 @@ */ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count) { + m_ticks_till_return = 0; m_type = (EventType)buffer->getUInt8(); m_ticks = buffer->getTime(); m_kart_id = buffer->getInt8(); @@ -41,7 +42,11 @@ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count) m_xyz = buffer->getVec3(); *count -= 12; } - + else if (m_type == IEI_COLLECT) + { + m_ticks_till_return = buffer->getUInt16(); + *count -= 2; + } } // ItemEventInfo(BareNetworkString, int *count) //----------------------------------------------------------------------------- @@ -55,7 +60,6 @@ void ItemEventInfo::saveState(BareNetworkString *buffer) .addUInt16(m_index); if(m_type == IEI_NEW) buffer->add(m_xyz); + else if (m_type == IEI_COLLECT) + buffer->addUInt16(m_ticks_till_return); } // saveState - - - \ No newline at end of file diff --git a/src/items/item_event_info.hpp b/src/items/item_event_info.hpp index 35499baf2..ddb246922 100644 --- a/src/items/item_event_info.hpp +++ b/src/items/item_event_info.hpp @@ -51,13 +51,20 @@ private: /** In case of new items the position of the new item. */ 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: /** Constructor for collecting an existing item. * \param ticks Time of the event. * \param item_id The index of the item that was collected. - * \param kart_id the kart that collected the item. */ - ItemEventInfo(int ticks, int index, int kart_id) - : m_ticks(ticks), m_index(index), m_kart_id(kart_id) + * \param kart_id the kart that collected the item. + * \param ttr Ticks till return after being collected. */ + + 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; } // ItemEventInfo(collected existing item) @@ -69,14 +76,15 @@ public: */ ItemEventInfo(int ticks, ItemState::ItemType type, int index, 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; } // ItemEventInfo(new item) // -------------------------------------------------------------------- /** 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; } // ItemEventInfo(switch) @@ -116,6 +124,9 @@ public: return m_xyz; } // 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 * can be created during a race. */ ItemState::ItemType getNewItemType() const diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index 76eb030ba..b77cce037 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -99,13 +99,14 @@ void NetworkItemManager::collectedItem(ItemState *item, AbstractKart *kart) { if(NetworkConfig::get()->isServer()) { + ItemManager::collectedItem(item, kart); // The server saves the collected item as item event info m_item_events.lock(); m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(), item->getItemId(), - kart->getWorldKartId() ); + kart->getWorldKartId(), + item->getTicksTillReturn()); m_item_events.unlock(); - ItemManager::collectedItem(item, kart); } else { @@ -319,6 +320,11 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count) int old_time = world->getTicksSinceStart(); // Save time we rewind to world->setTicksForRewind(iei.getTicks()); // Set time of event 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 if (m_confirmed_state[index]->isUsedUp())