Combined event handler and emitter in item into one object (since
they are the same anyway).
This commit is contained in:
parent
079b5abe2a
commit
ab3a3e1155
@ -73,7 +73,7 @@ void ItemState::update(int ticks)
|
||||
*/
|
||||
void ItemState::collected(const AbstractKart *kart)
|
||||
{
|
||||
m_event_handler = kart;
|
||||
m_previous_owner = kart;
|
||||
if (m_type == ITEM_EASTER_EGG)
|
||||
{
|
||||
// They will disappear 'forever'
|
||||
@ -190,7 +190,7 @@ void Item::initItem(ItemType type, const Vec3 &xyz)
|
||||
{
|
||||
ItemState::initItem(type);
|
||||
m_xyz = xyz;
|
||||
m_emitter = NULL;
|
||||
m_previous_owner = NULL;
|
||||
m_rotate = (getType()!=ITEM_BUBBLEGUM) &&
|
||||
(getType()!=ITEM_TRIGGER );
|
||||
// Now determine in which quad this item is, and its distance
|
||||
@ -327,10 +327,9 @@ void Item::reset()
|
||||
* affected by its own items.
|
||||
* \param parent Kart that dropped the item.
|
||||
*/
|
||||
void Item::setParent(AbstractKart* parent)
|
||||
void Item::setParent(const AbstractKart* parent)
|
||||
{
|
||||
m_event_handler = parent;
|
||||
m_emitter = parent;
|
||||
m_previous_owner = parent;
|
||||
ItemState::setDeactivatedTicks(stk_config->time2Ticks(1.5f));
|
||||
} // setParent
|
||||
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include <line3d.h>
|
||||
|
||||
class AbstractKart;
|
||||
class Item;
|
||||
class LODNode;
|
||||
|
||||
namespace irr
|
||||
@ -120,9 +119,9 @@ private:
|
||||
int m_used_up_counter;
|
||||
|
||||
protected:
|
||||
/** Optionally set this if this item was laid by a particular kart. in
|
||||
* this case the 'm_deactive_ticks' will also be set - see below. */
|
||||
const AbstractKart *m_event_handler;
|
||||
/** The 'owner' of the item, i.e. the kart that dropped this item.
|
||||
* Is NULL if the item is part of the track. */
|
||||
const AbstractKart *m_previous_owner;
|
||||
|
||||
friend class ItemManager;
|
||||
friend class NetworkItemManager;
|
||||
@ -130,11 +129,16 @@ protected:
|
||||
void setType(ItemType type) { m_type = type; }
|
||||
|
||||
public:
|
||||
/** Constructor. */
|
||||
ItemState(ItemType type, int id=-1)
|
||||
/** 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, AbstractKart *kart=NULL)
|
||||
{
|
||||
m_item_id = id;
|
||||
setType(type);
|
||||
m_item_id = id;
|
||||
m_previous_owner = kart;
|
||||
} // ItemState(ItemType)
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -164,7 +168,7 @@ public:
|
||||
void initItem(ItemType type)
|
||||
{
|
||||
setType(type);
|
||||
m_event_handler = NULL;
|
||||
m_previous_owner = NULL;
|
||||
m_original_type = ITEM_NONE;
|
||||
m_deactive_ticks = 0;
|
||||
m_ticks_till_return = 0;
|
||||
@ -248,6 +252,10 @@ public:
|
||||
/** Sets the number of ticks during which the item is deactivated (i.e.
|
||||
* it was collected). */
|
||||
void setDeactivatedTicks(int ticks) { m_deactive_ticks = ticks; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the kart that dropped this item (or NULL if the item was not
|
||||
* dropped by a kart. */
|
||||
const AbstractKart *getPreviousOwner() const { return m_previous_owner; }
|
||||
}; // class ItemState
|
||||
|
||||
// ============================================================================
|
||||
@ -286,9 +294,6 @@ private:
|
||||
/** Stores if the item was available in the previously rendered frame. */
|
||||
bool m_was_available_previously;
|
||||
|
||||
/** Kart that emitted this item if any */
|
||||
const AbstractKart *m_emitter;
|
||||
|
||||
/** callback used if type == ITEM_TRIGGER */
|
||||
TriggerItemListener* m_listener;
|
||||
|
||||
@ -323,12 +328,12 @@ public:
|
||||
virtual ~Item ();
|
||||
void updateGraphics(float dt);
|
||||
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
||||
void setParent(AbstractKart* parent);
|
||||
void setParent(const AbstractKart* parent);
|
||||
void reset();
|
||||
void switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh);
|
||||
void switchBack();
|
||||
|
||||
const AbstractKart* getEmitter() const { return m_emitter; }
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the Kart is close enough to hit this item, the item is
|
||||
@ -340,7 +345,7 @@ public:
|
||||
*/
|
||||
bool hitKart(const Vec3 &xyz, const AbstractKart *kart=NULL) const
|
||||
{
|
||||
if (m_event_handler == kart && getDeactivatedTicks() > 0)
|
||||
if (m_previous_owner == kart && getDeactivatedTicks() > 0)
|
||||
return false;
|
||||
Vec3 lc = quatRotate(m_original_rotation, xyz - m_xyz);
|
||||
// Don't be too strict if the kart is a bit above the item
|
||||
@ -361,7 +366,7 @@ protected:
|
||||
bool hitLine(const core::line3df &line,
|
||||
const AbstractKart *kart=NULL) const
|
||||
{
|
||||
if(m_event_handler==kart && getDeactivatedTicks() >0) return false;
|
||||
if (m_previous_owner == kart && getDeactivatedTicks() >0) return false;
|
||||
|
||||
Vec3 closest = line.getClosestPoint(m_xyz.toIrrVector());
|
||||
return hitKart(closest, kart);
|
||||
|
@ -259,7 +259,7 @@ unsigned int ItemManager::insertItem(Item *item)
|
||||
* \param xyz Can be used to overwrite the item location (used in networking).
|
||||
*/
|
||||
Item* ItemManager::dropNewItem(ItemState::ItemType type,
|
||||
AbstractKart *kart, const Vec3 *xyz)
|
||||
const AbstractKart *kart, const Vec3 *xyz)
|
||||
{
|
||||
Vec3 hit_point;
|
||||
Vec3 normal;
|
||||
@ -340,8 +340,7 @@ Item* ItemManager::placeItem(ItemState::ItemType type, const Vec3& xyz,
|
||||
Item* ItemManager::placeTrigger(const Vec3& xyz, float distance,
|
||||
TriggerItemListener* listener)
|
||||
{
|
||||
Item* item;
|
||||
item = new Item(xyz, distance, listener);
|
||||
Item* item = new Item(xyz, distance, listener);
|
||||
insertItem(item);
|
||||
|
||||
return item;
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
virtual Item* placeItem (ItemState::ItemType type, const Vec3& xyz,
|
||||
const Vec3 &normal);
|
||||
virtual Item* dropNewItem (ItemState::ItemType type,
|
||||
AbstractKart* parent, const Vec3 *xyz=NULL);
|
||||
const AbstractKart* parent, const Vec3 *xyz=NULL);
|
||||
virtual Item* placeTrigger (const Vec3& xyz, float distance,
|
||||
TriggerItemListener* listener);
|
||||
void update (int ticks);
|
||||
|
@ -130,11 +130,9 @@ void NetworkItemManager::collectedItem(Item *item, AbstractKart *kart)
|
||||
* \param type Type of the item.
|
||||
* \param kart In case of a dropped item used to avoid that a kart
|
||||
* is affected by its own items.
|
||||
* \param xyz Location of the item. If specified will override the
|
||||
* kart position (used in networking only).
|
||||
*/
|
||||
Item* NetworkItemManager::dropNewItem(ItemState::ItemType type,
|
||||
AbstractKart *kart, const Vec3 *xyz)
|
||||
const AbstractKart *kart, const Vec3 *xyz)
|
||||
{
|
||||
Item *item = ItemManager::dropNewItem(type, kart, xyz);
|
||||
if(!item) return NULL;
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
virtual void reset();
|
||||
virtual void setItemConfirmationTime(int host_id, int ticks) OVERRIDE;
|
||||
virtual void collectedItem(Item *item, AbstractKart *kart) OVERRIDE;
|
||||
virtual Item* dropNewItem(ItemState::ItemType type, AbstractKart *kart,
|
||||
virtual Item* dropNewItem(ItemState::ItemType type, const AbstractKart *kart,
|
||||
const Vec3 *xyz=NULL) OVERRIDE;
|
||||
virtual BareNetworkString* saveState() OVERRIDE;
|
||||
virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
|
||||
|
5
src/karts/kart.cpp
Normal file → Executable file
5
src/karts/kart.cpp
Normal file → Executable file
@ -1061,8 +1061,9 @@ void Kart::collectedItem(Item *item)
|
||||
break;
|
||||
}
|
||||
case Item::ITEM_BUBBLEGUM:
|
||||
m_has_caught_nolok_bubblegum = (item->getEmitter() != NULL &&
|
||||
item->getEmitter()->getIdent() == "nolok");
|
||||
m_has_caught_nolok_bubblegum =
|
||||
(item->getPreviousOwner()&&
|
||||
item->getPreviousOwner()->getIdent() == "nolok");
|
||||
|
||||
// slow down
|
||||
m_bubblegum_ticks =
|
||||
|
Loading…
Reference in New Issue
Block a user