Fixed bubble gum collection in networking (at least the problem
that you would on the client collect the gum you just dropped).
This commit is contained in:
parent
5955166931
commit
9211b26251
@ -37,6 +37,22 @@
|
||||
#include <ISceneManager.h>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Constructor.
|
||||
* \param type Type of the item.
|
||||
* \param owner If not NULL it is the kart that dropped this item; NULL
|
||||
* indicates an item that's part of the track.
|
||||
* \param id Index of this item in the array of all items.
|
||||
*/
|
||||
ItemState::ItemState(ItemType type, const AbstractKart *owner, int id)
|
||||
{
|
||||
setType(type);
|
||||
m_item_id = id;
|
||||
m_previous_owner = owner;
|
||||
if (owner)
|
||||
setDeactivatedTicks(stk_config->time2Ticks(1.5f));
|
||||
} // ItemState(ItemType)
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the disappear counter depending on type. */
|
||||
void ItemState::setDisappearCounter()
|
||||
@ -52,9 +68,23 @@ void ItemState::setDisappearCounter()
|
||||
} // switch
|
||||
} // setDisappearCounter
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** Initialises an item.
|
||||
* \param type Type for this item.
|
||||
*/
|
||||
void ItemState::initItem(ItemType type, const Vec3& xyz)
|
||||
{
|
||||
m_xyz = xyz;
|
||||
m_original_type = ITEM_NONE;
|
||||
m_ticks_till_return = 0;
|
||||
setDisappearCounter();
|
||||
} // initItem
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Update the state of the item, called once per physics frame.
|
||||
* \param ticks Number of ticks to simulate (typically 1).
|
||||
* \param ticks Number of ticks to simulate. While this value is 1 when
|
||||
* called during the normal game loop, during a rewind this value
|
||||
* can be (much) larger than 1.
|
||||
*/
|
||||
void ItemState::update(int ticks)
|
||||
{
|
||||
@ -117,7 +147,7 @@ void ItemState::collected(const AbstractKart *kart)
|
||||
Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||
scene::IMesh* mesh, scene::IMesh* lowres_mesh,
|
||||
const AbstractKart *owner, bool is_predicted)
|
||||
: ItemState(type)
|
||||
: ItemState(type, owner)
|
||||
{
|
||||
assert(type != ITEM_TRIGGER); // use other constructor for that
|
||||
|
||||
@ -163,11 +193,6 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||
hpr.setHPR(m_original_rotation);
|
||||
m_node->setRotation(hpr.toIrrHPR());
|
||||
m_node->grab();
|
||||
if (owner)
|
||||
{
|
||||
m_previous_owner = owner;
|
||||
ItemState::setDeactivatedTicks(stk_config->time2Ticks(1.5f));
|
||||
}
|
||||
} // Item(type, xyz, normal, mesh, lowres_mesh)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -198,7 +223,6 @@ Item::Item(const Vec3& xyz, float distance, TriggerItemListener* trigger)
|
||||
void Item::initItem(ItemType type, const Vec3 &xyz)
|
||||
{
|
||||
ItemState::initItem(type, xyz);
|
||||
m_previous_owner = NULL;
|
||||
m_rotate = (getType()!=ITEM_BUBBLEGUM) &&
|
||||
(getType()!=ITEM_TRIGGER );
|
||||
// Now determine in which quad this item is, and its distance
|
||||
|
@ -122,34 +122,25 @@ private:
|
||||
* and then converting this value to a Vec3. */
|
||||
Vec3 m_xyz;
|
||||
|
||||
protected:
|
||||
/** The 'owner' of the item, i.e. the kart that dropped this item.
|
||||
* Is NULL if the item is part of the track. */
|
||||
* Is NULL if the item is part of the track. */
|
||||
const AbstractKart *m_previous_owner;
|
||||
|
||||
protected:
|
||||
|
||||
friend class ItemManager;
|
||||
friend class NetworkItemManager;
|
||||
// ------------------------------------------------------------------------
|
||||
void setType(ItemType type) { m_type = type; }
|
||||
|
||||
public:
|
||||
/** Constructor.
|
||||
* \param type Type of the item.
|
||||
* \param id Index of this item in the array of all items.
|
||||
* \param kart_id If !=-1 the kart that dropped this item; -1
|
||||
* indicates an item that's part of the track. */
|
||||
ItemState(ItemType type, int id=-1, const AbstractKart *kart=NULL)
|
||||
{
|
||||
setType(type);
|
||||
m_item_id = id;
|
||||
m_previous_owner = kart;
|
||||
} // ItemState(ItemType)
|
||||
|
||||
ItemState(ItemType type, const AbstractKart *owner=NULL, int id = -1);
|
||||
void initItem(ItemType type, const Vec3& xyz);
|
||||
void update(int ticks);
|
||||
void setDisappearCounter();
|
||||
virtual void collected(const AbstractKart *kart);
|
||||
// ------------------------------------------------------------------------
|
||||
virtual ~ItemState() {}
|
||||
void setDisappearCounter();
|
||||
void update(int ticks);
|
||||
virtual void collected(const AbstractKart *kart);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
void reset()
|
||||
@ -165,19 +156,6 @@ public:
|
||||
}
|
||||
} // reset
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** Initialises an item.
|
||||
* \param type Type for this item.
|
||||
*/
|
||||
void initItem(ItemType type, const Vec3& xyz)
|
||||
{
|
||||
m_xyz = xyz;
|
||||
m_original_type = ITEM_NONE;
|
||||
m_deactive_ticks = 0;
|
||||
m_ticks_till_return = 0;
|
||||
setDisappearCounter();
|
||||
} // initItem
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Switches an item to be of a different type. Used for the switch
|
||||
* powerup.
|
||||
@ -333,12 +311,11 @@ public:
|
||||
void updateGraphics(float dt);
|
||||
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
||||
void reset();
|
||||
void switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh);
|
||||
void switchTo(ItemType type, scene::IMesh *mesh,
|
||||
scene::IMesh *lowmesh);
|
||||
void switchBack();
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the Kart is close enough to hit this item, the item is
|
||||
* not deactivated anymore, and it wasn't placed by this kart (this is
|
||||
* e.g. used to avoid that a kart hits a bubble gum it just dropped).
|
||||
@ -348,7 +325,7 @@ public:
|
||||
*/
|
||||
bool hitKart(const Vec3 &xyz, const AbstractKart *kart=NULL) const
|
||||
{
|
||||
if (m_previous_owner == kart && getDeactivatedTicks() > 0)
|
||||
if (getPreviousOwner() == kart && getDeactivatedTicks() > 0)
|
||||
return false;
|
||||
Vec3 lc = quatRotate(m_original_rotation, xyz - getXYZ());
|
||||
// Don't be too strict if the kart is a bit above the item
|
||||
@ -369,7 +346,8 @@ protected:
|
||||
bool hitLine(const core::line3df &line,
|
||||
const AbstractKart *kart=NULL) const
|
||||
{
|
||||
if (m_previous_owner == kart && getDeactivatedTicks() >0) return false;
|
||||
if (getPreviousOwner() == kart && getDeactivatedTicks() > 0)
|
||||
return false;
|
||||
|
||||
Vec3 closest = line.getClosestPoint(getXYZ().toIrrVector());
|
||||
return hitKart(closest, kart);
|
||||
|
@ -102,8 +102,8 @@ void NetworkItemManager::collectedItem(Item *item, AbstractKart *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());
|
||||
item->getItemId(),
|
||||
kart->getWorldKartId() );
|
||||
m_item_events.unlock();
|
||||
ItemManager::collectedItem(item, kart);
|
||||
}
|
||||
@ -315,8 +315,8 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
else if(iei.isNewItem())
|
||||
{
|
||||
AbstractKart *kart = World::getWorld()->getKart(iei.getKartId());
|
||||
ItemState *is = new ItemState(iei.getNewItemType(), iei.getIndex(),
|
||||
kart);
|
||||
ItemState *is = new ItemState(iei.getNewItemType(), kart,
|
||||
iei.getIndex() );
|
||||
is->initItem(iei.getNewItemType(), iei.getXYZ());
|
||||
if (m_confirmed_state.size() <= is->getItemId())
|
||||
{
|
||||
|
@ -560,11 +560,6 @@ void Powerup::hitBonusBox(const ItemState &item_state)
|
||||
|
||||
new_powerup = powerup_manager->getRandomPowerup(position, &n,
|
||||
random_number);
|
||||
// FIXME Disable switch and bubblegum for now in network
|
||||
if (NetworkConfig::get()->isNetworking() &&
|
||||
(new_powerup == PowerupManager::POWERUP_BUBBLEGUM ||
|
||||
new_powerup == PowerupManager::POWERUP_SWITCH))
|
||||
new_powerup = PowerupManager::POWERUP_BOWLING;
|
||||
|
||||
// Always add a new powerup in ITEM_MODE_NEW (or if the kart
|
||||
// doesn't have a powerup atm).
|
||||
|
Loading…
Reference in New Issue
Block a user