void Hero::takeAll() { ObjectWeakPtrs objects; if (Simulator::get().listObjectsAt( getX(), getY(), getZ(), &objects)) { ItemSharedPtrs items; std::for_each( objects.begin(), objects.end(), [&items](const ObjectWeakPtr& o) { ObjectSharedPtr object = o.lock(); if (object->getObjectType() & OBJECT_TYPE_CHARACTER) { Character* target = (Character*)object.get(); if (target->getHp() == 0) { items.reserve(items.size() + target->getItems().size()); items.insert(items.end(), target->getItems().begin(), target->getItems().end()); target->removeAllItems(); } } else if (object->getObjectType() & OBJECT_TYPE_CHEST) { Chest* target = (Chest*)object.get(); items.reserve(items.size() + target->getItems().size()); items.insert(items.end(), target->getItems().begin(), target->getItems().end()); target->removeAllItems(); } }); if (!items.empty()) { WindowSharedPtr w(new Window()); w->setHorizontalAlign(Window::HorizontalAlign::CENTER); w->setVerticalAlign(Window::VerticalAlign::BOTTOM); w->setTitle("Added To Inventory"); w->setMaxWidth(50); bool first = true; for_each(items.begin(), items.end(), [w, &first] (const ItemSharedPtr& item) { if (!first) { w->printEndLine(); } first = false; w->print(Colors::WHITE(), item->getName()); }); WindowManager::get().popup(w, 5); addItems(items); } } }
bool Group::isEquivalent( ObjectSharedPtr const& object, bool ignoreNames, bool deepCompare ) const { if ( object.get() == this ) { return( true ); } bool equi = std::dynamic_pointer_cast<Group>(object) && Node::isEquivalent( object, ignoreNames, deepCompare ); if ( equi ) { GroupSharedPtr const& g = std::static_pointer_cast<Group>(object); equi = ( m_children.size() == g->m_children.size() ) && ( m_clipPlanes.size() == g->m_clipPlanes.size() ); if ( deepCompare ) { for ( ChildrenContainer::const_iterator lhsit = m_children.begin() ; equi && lhsit != m_children.end() ; ++lhsit ) { bool found = false; for ( ChildrenContainer::const_iterator rhsit = g->m_children.begin() ; !found && rhsit != g->m_children.end() ; ++rhsit ) { found = (*lhsit)->isEquivalent( *rhsit, ignoreNames, true ); } equi = found; } for ( ClipPlaneContainer::const_iterator lhsit = m_clipPlanes.begin() ; equi && lhsit != m_clipPlanes.end() ; ++lhsit ) { bool found = false; for ( ClipPlaneContainer::const_iterator rhsit = g->m_clipPlanes.begin() ; !found && rhsit != g->m_clipPlanes.end() ; ++rhsit ) { found = (*lhsit)->isEquivalent( *rhsit, ignoreNames, true ); } equi = found; } } else { for ( ChildrenContainer::const_iterator lhsit = m_children.begin() ; equi && lhsit != m_children.end() ; ++lhsit ) { bool found = false; for ( ChildrenContainer::const_iterator rhsit = g->m_children.begin() ; !found && rhsit != g->m_children.end() ; ++rhsit ) { found = ( *lhsit == *rhsit ); } equi = found; } for ( ClipPlaneContainer::const_iterator lhsit = m_clipPlanes.begin() ; equi && lhsit != m_clipPlanes.end() ; ++lhsit ) { bool found = false; for ( ClipPlaneContainer::const_iterator rhsit = g->m_clipPlanes.begin() ; !found && rhsit != g->m_clipPlanes.end() ; ++rhsit ) { found = ( *lhsit == *rhsit ); } equi = found; } } } return( equi ); }
bool Billboard::isEquivalent( ObjectSharedPtr const& object, bool ignoreNames, bool deepCompare ) const { if ( object.get() == this ) { return( true ); } bool equi = std::dynamic_pointer_cast<Billboard>(object) && Group::isEquivalent( object, ignoreNames, deepCompare ); if ( equi ) { BillboardSharedPtr const& b = std::static_pointer_cast<Billboard>(object); equi = ( m_alignment == b->m_alignment ) && ( ( m_alignment != Alignment::AXIS ) || ( m_rotationAxis == b->m_rotationAxis ) ); } return( equi ); }
void Weapon::use(Direction dir) { if (getOwner() && getOwner()->getObjectType() & Object::OBJECT_TYPE_CHARACTER) { Character* owner = (Character*)getOwner(); m_dir = dir; show(); float dx, dy; getDeltas(dx, dy); ObjectWeakPtrs objects; if (Simulator::get().listObjectsAt( owner->getX() + dx, owner->getY() + dy, owner->getZ(), &objects)) { std::for_each( objects.begin(), objects.end(), [this, owner](const ObjectWeakPtr& o) { ObjectSharedPtr object = o.lock(); if (object->getObjectType() & Object::OBJECT_TYPE_CHARACTER) { int damage = Math::ceilRandom(m_damage); Character* target = (Character*)object.get(); Math::clamp(damage, 0, target->getHp()); target->onReceiveHit(owner, damage); owner->onGiveHit(target, damage); } }); } } }
bool VertexAttributeSet::isEquivalent( ObjectSharedPtr const& object, bool ignoreNames, bool deepCompare ) const { if ( object.get() == this ) { return( true ); } bool equi = std::dynamic_pointer_cast<VertexAttributeSet>(object) && Object::isEquivalent( object, ignoreNames, deepCompare ); if ( equi ) { VertexAttributeSetSharedPtr vas = std::static_pointer_cast<VertexAttributeSet>(object); equi = ( m_vattribs.size() == vas->m_vattribs.size() ); for ( AttributeContainer::const_iterator thisit = m_vattribs.begin(), thatit = vas->m_vattribs.begin() ; equi && ( thisit != m_vattribs.end() ) && ( thatit != vas->m_vattribs.end() ) ; ++thisit, ++thatit ) { equi = (thisit->first == thatit->first) && (thisit->second.getVertexDataBytes() == thatit->second.getVertexDataBytes()) && (thisit->second.getVertexDataCount() == thatit->second.getVertexDataCount()) && (thisit->second.getVertexDataOffsetInBytes() == thatit->second.getVertexDataOffsetInBytes()) && (thisit->second.getVertexDataSize() == thatit->second.getVertexDataSize()) && (thisit->second.getVertexDataStrideInBytes() == thatit->second.getVertexDataStrideInBytes()) && (thisit->second.getVertexDataType() == thatit->second.getVertexDataType()); } if ( equi ) { for ( AttributeContainer::const_iterator thisit = m_vattribs.begin(), thatit = vas->m_vattribs.begin() ; equi && thisit != m_vattribs.end() && thatit != vas->m_vattribs.end() ; ++thisit, ++thatit ) { equi = (thisit->second.getBuffer() == thatit->second.getBuffer()) || (deepCompare && thisit->second.getBuffer()->isEquivalent(thatit->second.getBuffer(), ignoreNames, deepCompare)); } } } return( equi ); }