Tile* Item::getTile() { Cylinder* cylinder = getTopParent(); //get root cylinder if (cylinder->getParent()) { cylinder = cylinder->getParent(); } return dynamic_cast<Tile*>(cylinder); }
void Container::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t) { Cylinder* topParent = getTopParent(); if (topParent->getCreature()) { topParent->postRemoveNotification(thing, newParent, index, LINK_TOPPARENT); } else if (topParent == this) { //let the tile class notify surrounding players if (topParent->getParent()) { topParent->getParent()->postRemoveNotification(thing, newParent, index, LINK_NEAR); } } else { topParent->postRemoveNotification(thing, newParent, index, LINK_PARENT); } }
Tile* Thing::getTile() { Cylinder* cylinder = getTopParent(); #ifdef __DEBUG_MOVESYS__ if(!cylinder) { std::clog << "[Failure - Thing::getTile] NULL tile" << std::endl; return &(Tile::nullTile); } #endif if(cylinder->getParent()) cylinder = cylinder->getParent(); return dynamic_cast<Tile*>(cylinder); }
void Container::postRemoveNotification(Creature* actor, Thing* thing, const Cylinder* newParent, int32_t index, bool isCompleteRemoval, CylinderLink_t/* link = LINK_OWNER*/) { Cylinder* topParent = getTopParent(); if(!topParent->getCreature()) { if(topParent == this) { //let the tile class notify surrounding players if(topParent->getParent()) topParent->getParent()->postRemoveNotification(actor, thing, newParent, index, isCompleteRemoval, LINK_NEAR); } else topParent->postRemoveNotification(actor, thing, newParent, index, isCompleteRemoval, LINK_PARENT); } else topParent->postRemoveNotification(actor, thing, newParent, index, isCompleteRemoval, LINK_TOPPARENT); }
Cylinder* Item::getTopParent() { Cylinder* aux = getParent(); Cylinder* prevaux = dynamic_cast<Cylinder*>(this); if (!aux) { return prevaux; } while (aux->getParent() != NULL) { prevaux = aux; aux = aux->getParent(); } if (dynamic_cast<Cylinder*>(prevaux)) { return prevaux; } return aux; }
Cylinder* Thing::getTopParent() { //tile Cylinder* aux = getParent(); if(!aux) return dynamic_cast<Cylinder*>(this); Cylinder* prev = dynamic_cast<Cylinder*>(this); while(aux->getParent()) { prev = aux; aux = aux->getParent(); } if(dynamic_cast<Cylinder*>(prev)) return prev; return aux; }
Player* Item::getHoldingPlayer() { for(Cylinder* p = getParent(); p; p = p->getParent()) { if(p->getCreature()) return p->getCreature()->getPlayer(); } return NULL; }
Cylinder* Thing::getTopParent() { //tile if(getParent() == NULL) return dynamic_cast<Cylinder*>(this); Cylinder* aux = getParent(); Cylinder* prevaux = dynamic_cast<Cylinder*>(this); while(aux->getParent() != NULL){ prevaux = aux; aux = aux->getParent(); } if(dynamic_cast<Cylinder*>(prevaux)){ return prevaux; } return aux; }
Player* Item::getHoldingPlayer() { Cylinder* p = getParent(); while(p){ if(p->getCreature()) // Must be a player, creatures are not cylinders return p->getCreature()->getPlayer(); p = p->getParent(); } return NULL; }
Player* Item::getHoldingPlayer() { Cylinder* p = getParent(); while (p) { if (p->getCreature()) { return p->getCreature()->getPlayer(); } p = p->getParent(); } return NULL; }