Fix dropping big nitro with switch on
This commit is contained in:
parent
90daf4ce87
commit
a13af6bfc8
@ -182,6 +182,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||
}
|
||||
m_node = lodnode;
|
||||
setType(type);
|
||||
handleNewMesh(getType());
|
||||
|
||||
#ifdef DEBUG
|
||||
std::string debug_name("item: ");
|
||||
@ -253,39 +254,6 @@ void Item::initItem(ItemType type, const Vec3 &xyz)
|
||||
|
||||
} // initItem
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the type of the item (and also derived attributes lile m_rotate
|
||||
* \param type Type of the item.
|
||||
*/
|
||||
void Item::setType(ItemType type)
|
||||
{
|
||||
ItemState::setType(type);
|
||||
} // setType
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Changes this item to be a new type for a certain amount of time.
|
||||
* \param type New type of this item.
|
||||
* \param mesh Mesh to use to display this item.
|
||||
*/
|
||||
void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
|
||||
{
|
||||
ItemState::switchTo(type, mesh, lowmesh);
|
||||
} // switchTo
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Switch backs to the original item. Returns true if the item wa snot
|
||||
* actually switched (e.g. trigger, or bubblegum dropped during switch
|
||||
* time). The return value is not actually used, but necessary in order
|
||||
* to overwrite ItemState::switchBack()
|
||||
*/
|
||||
bool Item::switchBack()
|
||||
{
|
||||
if (ItemState::switchBack())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
} // switchBack
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Item::setMesh(scene::IMesh* mesh, scene::IMesh* lowres_mesh)
|
||||
{
|
||||
@ -344,12 +312,13 @@ void Item::reset()
|
||||
m_node->setScale(core::vector3df(1,1,1));
|
||||
m_node->setVisible(true);
|
||||
}
|
||||
handleNewMesh(getType());
|
||||
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Item::handleNewMesh(ItemType type)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
if (m_node == NULL)
|
||||
return;
|
||||
setMesh(ItemManager::get()->getItemModel(type),
|
||||
@ -363,6 +332,8 @@ void Item::handleNewMesh(ItemType type)
|
||||
Vec3 hpr;
|
||||
hpr.setHPR(m_original_rotation);
|
||||
m_node->setRotation(hpr.toIrrHPR());
|
||||
m_rotation_angle = 0.0f;
|
||||
#endif
|
||||
} // handleNewMesh
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -418,20 +389,3 @@ void Item::updateGraphics(float dt)
|
||||
} // if item is available
|
||||
m_was_available_previously = isAvailable();
|
||||
} // updateGraphics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Is called when the item is hit by a kart. It sets the flag that the item
|
||||
* has been collected, and the time to return to the parameter.
|
||||
* \param kart The kart that collected the item.
|
||||
*/
|
||||
void Item::collected(const AbstractKart *kart)
|
||||
{
|
||||
ItemState::collected(kart);
|
||||
|
||||
if (m_listener != NULL)
|
||||
{
|
||||
m_listener->onTriggerItemApproached();
|
||||
}
|
||||
|
||||
} // isCollected
|
||||
|
||||
|
@ -219,11 +219,8 @@ public:
|
||||
/** Switches an item to be of a different type. Used for the switch
|
||||
* powerup.
|
||||
* \param type New type for this item.
|
||||
* \param mesh Ignored.
|
||||
* \param lowmesh Ignored.
|
||||
*/
|
||||
virtual void switchTo(ItemType type, scene::IMesh *mesh,
|
||||
scene::IMesh *lowmesh)
|
||||
virtual void switchTo(ItemType type)
|
||||
{
|
||||
// triggers and easter eggs should not be switched
|
||||
if (m_type == ITEM_TRIGGER || m_type == ITEM_EASTER_EGG) return;
|
||||
@ -356,7 +353,6 @@ private:
|
||||
* would not be collected. Used by the AI to avoid items. */
|
||||
Vec3 *m_avoidance_points[2];
|
||||
|
||||
void setType(ItemType type) OVERRIDE;
|
||||
void initItem(ItemType type, const Vec3 &xyz);
|
||||
void setMesh(scene::IMesh* mesh, scene::IMesh* lowres_mesh);
|
||||
void handleNewMesh(ItemType type);
|
||||
@ -370,12 +366,31 @@ public:
|
||||
TriggerItemListener* trigger);
|
||||
virtual ~Item ();
|
||||
virtual void updateGraphics(float dt) OVERRIDE;
|
||||
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
||||
virtual void reset() OVERRIDE;
|
||||
virtual void switchTo(ItemType type, scene::IMesh *mesh,
|
||||
scene::IMesh *lowmesh) OVERRIDE;
|
||||
virtual bool switchBack() OVERRIDE;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
/** Is called when the item is hit by a kart. It sets the flag that the
|
||||
* item has been collected, and the time to return to the parameter.
|
||||
* \param kart The kart that collected the item.
|
||||
*/
|
||||
virtual void collected(const AbstractKart *kart) OVERRIDE
|
||||
{
|
||||
ItemState::collected(kart);
|
||||
if (m_listener != NULL)
|
||||
m_listener->onTriggerItemApproached();
|
||||
} // isCollected
|
||||
//-------------------------------------------------------------------------
|
||||
/** Switch backs to the original item. Returns true if the item was not
|
||||
* actually switched (e.g. trigger, or bubblegum dropped during switch
|
||||
* time). The return value is not actually used, but necessary in order
|
||||
* to overwrite ItemState::switchBack()
|
||||
*/
|
||||
virtual bool switchBack() OVERRIDE
|
||||
{
|
||||
if (ItemState::switchBack())
|
||||
return true;
|
||||
return false;
|
||||
} // 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
|
||||
|
@ -53,6 +53,7 @@ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count)
|
||||
} // is not switch
|
||||
else // switch
|
||||
{
|
||||
m_index = -1;
|
||||
m_kart_id = -1;
|
||||
}
|
||||
} // ItemEventInfo(BareNetworkString, int *count)
|
||||
|
@ -307,8 +307,7 @@ Item* ItemManager::dropNewItem(ItemState::ItemType type,
|
||||
if(m_switch_ticks>=0)
|
||||
{
|
||||
ItemState::ItemType new_type = m_switch_to[item->getType()];
|
||||
item->switchTo(new_type, m_item_mesh[(int)new_type],
|
||||
m_item_lowres_mesh[(int)new_type]);
|
||||
item->switchTo(new_type);
|
||||
}
|
||||
return item;
|
||||
} // dropNewItem
|
||||
@ -338,8 +337,7 @@ Item* ItemManager::placeItem(ItemState::ItemType type, const Vec3& xyz,
|
||||
if (m_switch_ticks >= 0)
|
||||
{
|
||||
ItemState::ItemType new_type = m_switch_to[item->getType()];
|
||||
item->switchTo(new_type, m_item_mesh[(int)new_type],
|
||||
m_item_lowres_mesh[(int)new_type]);
|
||||
item->switchTo(new_type);
|
||||
}
|
||||
return item;
|
||||
} // placeItem
|
||||
@ -575,8 +573,7 @@ void ItemManager::switchItemsInternal(std::vector<ItemState*> &all_items)
|
||||
if (new_type == (*i)->getType())
|
||||
continue;
|
||||
if(m_switch_ticks<0)
|
||||
(*i)->switchTo(new_type, m_item_mesh[(int)new_type],
|
||||
m_item_lowres_mesh[(int)new_type]);
|
||||
(*i)->switchTo(new_type);
|
||||
else
|
||||
(*i)->switchBack();
|
||||
} // for all_items
|
||||
|
@ -45,15 +45,9 @@ class ItemManager : public NoCopy
|
||||
{
|
||||
// Some static data and functions to initialise it:
|
||||
private:
|
||||
/** Stores all item models. */
|
||||
static std::vector<scene::IMesh *> m_item_mesh;
|
||||
|
||||
/** Stores the glow color for all items. */
|
||||
static std::vector<video::SColorf> m_glow_color;
|
||||
|
||||
/** Stores all low-resolution item models. */
|
||||
static std::vector<scene::IMesh *> m_item_lowres_mesh;
|
||||
|
||||
/** Disable item collection (for debugging purposes). */
|
||||
static bool m_disable_item_collection;
|
||||
|
||||
@ -61,6 +55,13 @@ private:
|
||||
protected:
|
||||
/** The instance of ItemManager while a race is on. */
|
||||
static std::shared_ptr<ItemManager> m_item_manager;
|
||||
|
||||
/** Stores all item models. */
|
||||
static std::vector<scene::IMesh *> m_item_mesh;
|
||||
|
||||
/** Stores all low-resolution item models. */
|
||||
static std::vector<scene::IMesh *> m_item_lowres_mesh;
|
||||
|
||||
public:
|
||||
static void loadDefaultItemMeshes();
|
||||
static void removeTextures();
|
||||
@ -105,15 +106,16 @@ protected:
|
||||
/** The vector of all items of the current track. */
|
||||
typedef std::vector<ItemState*> AllItemTypes;
|
||||
AllItemTypes m_all_items;
|
||||
|
||||
/** What item this item is switched to. */
|
||||
std::vector<ItemState::ItemType> m_switch_to;
|
||||
|
||||
private:
|
||||
/** Stores which items are on which quad. m_items_in_quads[#quads]
|
||||
* contains all items that are not on a quad. Note that this
|
||||
* field is undefined if no Graph exist, e.g. arena without navmesh. */
|
||||
std::vector< AllItemTypes > *m_items_in_quads;
|
||||
|
||||
/** What item this item is switched to. */
|
||||
std::vector<ItemState::ItemType> m_switch_to;
|
||||
|
||||
protected:
|
||||
/** Remaining time that items should remain switched. If the
|
||||
* value is <0, it indicates that the items are not switched atm. */
|
||||
|
@ -371,7 +371,8 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
iei.getIndex(),
|
||||
iei.getTicks(), iei.isItemCollection(), iei.isNewItem(),
|
||||
iei.getTicksTillReturn(),
|
||||
iei.getIndex() < (int)m_confirmed_state.size() ? m_confirmed_state[iei.getIndex()] : NULL);
|
||||
iei.getIndex() < (int)m_confirmed_state.size() && iei.getIndex() != -1 ?
|
||||
m_confirmed_state[iei.getIndex()] : NULL);
|
||||
// 1.2) If the event needs to be applied, forward
|
||||
// the time to the time of this event:
|
||||
// ----------------------------------------------
|
||||
@ -409,6 +410,11 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
ItemState *is = new ItemState(iei.getNewItemType(), kart,
|
||||
iei.getIndex() );
|
||||
is->initItem(iei.getNewItemType(), iei.getXYZ());
|
||||
if (m_switch_ticks >= 0)
|
||||
{
|
||||
ItemState::ItemType new_type = m_switch_to[is->getType()];
|
||||
is->switchTo(new_type);
|
||||
}
|
||||
|
||||
// A new confirmed item must either be inserted at the end of all
|
||||
// items, or in an existing unused entry.
|
||||
@ -478,8 +484,6 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
? m_confirmed_state[i] : NULL;
|
||||
if (is && item)
|
||||
{
|
||||
// TODO: Check that the item has the right model, otherwise it
|
||||
// might be an incorrectly predicted item.
|
||||
*(ItemState*)item = *is;
|
||||
}
|
||||
else if (is && !item)
|
||||
|
Loading…
x
Reference in New Issue
Block a user