boost::shared_ptr<MWWorld::Action> Container::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { const std::string lockedSound = "LockedChest"; const std::string trapActivationSound = "Disarm Trap Fail"; if (ptr.getCellRef().lockLevel>0) { // TODO check for key std::cout << "Locked container" << std::endl; boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction); action->setSound(lockedSound); return action; } else { if(ptr.getCellRef().trap.empty()) { boost::shared_ptr<MWWorld::Action> action (new MWWorld::ActionOpen(ptr)); action->setSound ("chest open"); return action; } else { // Trap activation goes here std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl; boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction); action->setSound(trapActivationSound); ptr.getCellRef().trap = ""; return action; } } }
void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const { if(lockLevel != 0) ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, if positive else ptr.getCellRef().setLockLevel(ESM::UnbreakableLock); // If zero, set to max lock level }
void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float duration, const ESM::Position& pos) { zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1])); MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor); if (mObstacleCheck.check(actor, duration)) { // first check if we're walking into a door MWWorld::Ptr door = getNearbyDoor(actor); if (door != MWWorld::Ptr()) // NOTE: checks interior cells only { if (!door.getCellRef().getTeleport() && door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 && door.getClass().getDoorState(door) == 0) { MWBase::Environment::get().getWorld()->activateDoor(door, 1); } } else // probably walking into another NPC { mObstacleCheck.takeEvasiveAction(movement); } } else { //Not stuck, so reset things movement.mPosition[1] = 1; //Just run forward } }
MWGui::ToolTipInfo Container::getToolTipInfo (const MWWorld::Ptr& ptr) const { MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>(); MWGui::ToolTipInfo info; info.caption = ref->mBase->mName; std::string text; if (ptr.getCellRef().getLockLevel() > 0) text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel()); else if (ptr.getCellRef().getLockLevel() < 0) text += "\n#{sUnlocked}"; if (ptr.getCellRef().getTrap() != "") text += "\n#{sTrapped}"; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.text = text; return info; }
void Container::lock (const MWWorld::Ptr& ptr, int lockLevel) const { if(lockLevel!=0) ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, in positive else ptr.getCellRef().setLockLevel(abs(ptr.getCellRef().getLockLevel())); //No locklevel given, just flip the original one }
MWGui::ToolTipInfo Clothing::getToolTipInfo (const MWWorld::Ptr& ptr) const { MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>(); MWGui::ToolTipInfo info; info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->mBase->mIcon; std::string text; text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight); text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.enchant = ref->mBase->mEnchant; if (!info.enchant.empty()) info.remainingEnchantCharge = ptr.getCellRef().getEnchantmentCharge(); info.text = text; return info; }
MWGui::ToolTipInfo Repair::getToolTipInfo (const MWWorld::Ptr& ptr) const { MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); MWGui::ToolTipInfo info; info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->mBase->mIcon; std::string text; int remainingUses = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mUses; text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses); text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality); text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight); text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.text = text; return info; }
void Actors::insertBegin(const MWWorld::Ptr &ptr) { Ogre::SceneNode* cellnode; CellSceneNodeMap::const_iterator celliter = mCellSceneNodes.find(ptr.getCell()); if(celliter != mCellSceneNodes.end()) cellnode = celliter->second; else { //Create the scenenode and put it in the map cellnode = mRootNode->createChildSceneNode(); mCellSceneNodes[ptr.getCell()] = cellnode; } Ogre::SceneNode* insert = cellnode->createChildSceneNode(); const float *f = ptr.getRefData().getPosition().pos; insert->setPosition(f[0], f[1], f[2]); insert->setScale(ptr.getCellRef().mScale, ptr.getCellRef().mScale, ptr.getCellRef().mScale); // Convert MW rotation to a quaternion: f = ptr.getCellRef().mPos.rot; // Rotate around X axis Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X); // Rotate around Y axis Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y); // Rotate around Z axis Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z); // Rotates first around z, then y, then x insert->setOrientation(xr*yr*zr); ptr.getRefData().setBaseNode(insert); }
void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float duration, const ESM::Position& pos) { zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1])); MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor); // check if stuck due to obstacles if (!mObstacleCheck.check(actor, duration)) return; // first check if obstacle is a door MWWorld::Ptr door = getNearbyDoor(actor); // NOTE: checks interior cells only if (door != MWWorld::Ptr()) { // note: AiWander currently does not open doors if (getTypeId() != TypeIdWander && !door.getCellRef().getTeleport() && door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 && door.getClass().getDoorState(door) == 0) { MWBase::Environment::get().getWorld()->activateDoor(door, 1); } } else // any other obstacle (NPC, crate, etc.) { mObstacleCheck.takeEvasiveAction(movement); } }
float Light::getRemainingUsageTime (const MWWorld::Ptr& ptr) const { MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>(); if (ptr.getCellRef().getCharge() == -1) return static_cast<float>(ref->mBase->mData.mTime); else return ptr.getCellRef().getChargeFloat(); }
void Recharge::onItemClicked(MyGUI::Widget *sender) { MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>(); if (!gem.getRefData().getCount()) return; MWWorld::Ptr item = *sender->getUserData<MWWorld::Ptr>(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); float luckTerm = 0.1f * stats.getAttribute(ESM::Attribute::Luck).getModified(); if (luckTerm < 1|| luckTerm > 10) luckTerm = 1; float intelligenceTerm = 0.2f * stats.getAttribute(ESM::Attribute::Intelligence).getModified(); if (intelligenceTerm > 20) intelligenceTerm = 20; if (intelligenceTerm < 1) intelligenceTerm = 1; float x = (npcStats.getSkill(ESM::Skill::Enchant).getModified() + intelligenceTerm + luckTerm) * stats.getFatigueTerm(); int roll = OEngine::Misc::Rng::roll0to99(); if (roll < x) { std::string soul = gem.getCellRef().getSoul(); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul); float restored = creature->mData.mSoul * (roll / x); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find( item.getClass().getEnchantment(item)); item.getCellRef().setEnchantmentCharge( std::min(item.getCellRef().getEnchantmentCharge() + restored, static_cast<float>(enchantment->mData.mCharge))); player.getClass().getContainerStore(player).restack(item); player.getClass().skillUsageSucceeded (player, ESM::Skill::Enchant, 0); } gem.getContainerStore()->remove(gem, 1, player); if (gem.getRefData().getCount() == 0) { std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sNotifyMessage51")->getString(); message = boost::str(boost::format(message) % gem.getClass().getName(gem)); MWBase::Environment::get().getWindowManager()->messageBox(message); // special case: readd Azura's Star if (Misc::StringUtils::ciEqual(gem.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura")) player.getClass().getContainerStore(player).add("Misc_SoulGem_Azura", 1, player); } updateView(); }
boost::shared_ptr<MWWorld::Action> Door::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref = ptr.get<ESM::Door>(); const std::string &openSound = ref->base->openSound; //const std::string &closeSound = ref->base->closeSound; const std::string lockedSound = "LockedDoor"; const std::string trapActivationSound = "Disarm Trap Fail"; if (ptr.getCellRef().lockLevel>0) { // TODO check for key // TODO report failure to player (message, sound?). Look up behaviour of original MW. std::cout << "Locked!" << std::endl; MWBase::Environment::get().getSoundManager()->playSound3D (ptr, lockedSound, 1.0, 1.0); return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction); } if(!ptr.getCellRef().trap.empty()) { // Trap activation std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl; MWBase::Environment::get().getSoundManager()->playSound3D(ptr, trapActivationSound, 1.0, 1.0); ptr.getCellRef().trap = ""; return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction); } if (ref->ref.teleport) { // teleport door if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor) { // the player is using the door // The reason this is not 3D is that it would get interrupted when you teleport MWBase::Environment::get().getSoundManager()->playSound(openSound, 1.0, 1.0); return boost::shared_ptr<MWWorld::Action> ( new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest)); } else { // another NPC or a creature is using the door // TODO return action for teleporting other NPC/creature return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction); } } else { // animated door // TODO return action for rotating the door // This is a little pointless, but helps with testing MWBase::Environment::get().getSoundManager()->playSound3D (ptr, openSound, 1.0, 1.0); return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction); } }
int Weapon::getValue (const MWWorld::Ptr& ptr) const { MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>(); if (ptr.getCellRef().mCharge == -1) return ref->mBase->mData.mValue; else return ref->mBase->mData.mValue * (static_cast<float>(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr)); }
bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr) { if (ptr.mRef == nullptr) return false; // Players always have 0 as their refNumIndex and mpNum if (ptr.getCellRef().getRefNum().mIndex != 0 || ptr.getCellRef().getMpNum() != 0) return false; return (getPlayer(ptr) != 0); }
void Recharge::onItemClicked(MyGUI::Widget *sender) { MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>(); if (!gem.getRefData().getCount()) return; MWWorld::Ptr item = *sender->getUserData<MWWorld::Ptr>(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); float luckTerm = 0.1 * stats.getAttribute(ESM::Attribute::Luck).getModified(); if (luckTerm < 1|| luckTerm > 10) luckTerm = 1; float intelligenceTerm = 0.2 * stats.getAttribute(ESM::Attribute::Intelligence).getModified(); if (intelligenceTerm > 20) intelligenceTerm = 20; if (intelligenceTerm < 1) intelligenceTerm = 1; float x = (npcStats.getSkill(ESM::Skill::Enchant).getModified() + intelligenceTerm + luckTerm) * stats.getFatigueTerm(); int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] if (roll < x) { std::string soul = gem.getCellRef().mSoul; const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul); float restored = creature->mData.mSoul * (roll / x); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find( item.getClass().getEnchantment(item)); item.getCellRef().mEnchantmentCharge = std::min(item.getCellRef().mEnchantmentCharge + restored, static_cast<float>(enchantment->mData.mCharge)); player.getClass().skillUsageSucceeded (player, ESM::Skill::Enchant, 0); } gem.getContainerStore()->remove(gem, 1, player); if (gem.getRefData().getCount() == 0) { std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sNotifyMessage51")->getString(); message = boost::str(boost::format(message) % gem.getClass().getName(gem)); MWBase::Environment::get().getWindowManager()->messageBox(message); } updateView(); }
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const { // TODO handle exterior cells (when ref and ref2 are located in different cells) const MWWorld::Ptr ref2 = getReference (id, false); const MWWorld::Ptr ref = mEnvironment.mWorld->getPtr (name, true); double diff[3]; for (int i=0; i<3; ++i) diff[i] = ref.getCellRef().pos.pos[i] - ref2.getCellRef().pos.pos[i]; return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]); }
int Miscellaneous::getValue (const MWWorld::Ptr& ptr) const { MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>(); int value = (ptr.getCellRef().mGoldValue == 1) ? ref->mBase->mData.mValue : ptr.getCellRef().mGoldValue; if (ptr.getCellRef().mSoul != "") { const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(ref->mRef.mSoul); value *= creature->mData.mSoul; } return value; }
void InventoryWindow::cycle(bool next) { ItemModel::ModelIndex selected = -1; // not using mSortFilterModel as we only need sorting, not filtering SortFilterItemModel model(new InventoryItemModel(MWMechanics::getPlayer())); model.setSortByType(false); model.update(); if (model.getItemCount() == 0) return; for (ItemModel::ModelIndex i=0; i<int(model.getItemCount()); ++i) { MWWorld::Ptr item = model.getItem(i).mBase; if (model.getItem(i).mType & ItemStack::Type_Equipped && isRightHandWeapon(item)) selected = i; } int incr = next ? 1 : -1; bool found = false; std::string lastId; if (selected != -1) lastId = model.getItem(selected).mBase.getCellRef().getRefId(); ItemModel::ModelIndex cycled = selected; for (unsigned int i=0; i<model.getItemCount(); ++i) { cycled += incr; cycled = (cycled + model.getItemCount()) % model.getItemCount(); MWWorld::Ptr item = model.getItem(cycled).mBase; // skip different stacks of the same item, or we will get stuck as stacking/unstacking them may change their relative ordering if (Misc::StringUtils::ciEqual(lastId, item.getCellRef().getRefId())) continue; lastId = item.getCellRef().getRefId(); if (item.getClass().getTypeName() == typeid(ESM::Weapon).name() && isRightHandWeapon(item)) { found = true; break; } } if (!found) return; useItem(model.getItem(cycled).mBase); }
void InventoryItemModel::update() { MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor); mItems.clear(); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { MWWorld::Ptr item = *it; // NOTE: Don't show WerewolfRobe objects in the inventory, or allow them to be taken. // Vanilla likely uses a hack like this since there's no other way to prevent it from // being shown or taken. if(item.getCellRef().getRefId() == "werewolfrobe") continue; ItemStack newItem (item, this, item.getRefData().getCount()); if (mActor.getClass().hasInventoryStore(mActor)) { MWWorld::InventoryStore& store = mActor.getClass().getInventoryStore(mActor); for (int slot=0; slot<MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ContainerStoreIterator equipped = store.getSlot(slot); if (equipped == store.end()) continue; if (*equipped == newItem.mBase) newItem.mType = ItemStack::Type_Equipped; } } mItems.push_back(newItem); } }
void Container::lock (const MWWorld::Ptr& ptr, int lockLevel) const { if (lockLevel<0) lockLevel = 0; ptr.getCellRef().lockLevel = lockLevel; }
void MerchantRepair::onRepairButtonClick(MyGUI::Widget *sender) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); int price = MyGUI::utility::parseInt(sender->getUserString("Price")); if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId)) return; // repair MWWorld::Ptr item = *sender->getUserData<MWWorld::Ptr>(); item.getCellRef().setCharge(item.getClass().getItemMaxHealth(item)); player.getClass().getContainerStore(player).restack(item); MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1); player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price, player); // add gold to NPC trading gold pool MWMechanics::CreatureStats& actorStats = mActor.getClass().getCreatureStats(mActor); actorStats.setGoldPool(actorStats.getGoldPool() + price); startRepair(mActor); }
boost::shared_ptr<MWWorld::Action> Miscellaneous::use (const MWWorld::Ptr& ptr) const { if (ptr.getCellRef().getSoul().empty()) return boost::shared_ptr<MWWorld::Action>(new MWWorld::NullAction()); else return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionSoulgem(ptr)); }
std::pair<int, std::string> Armor::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const { MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc); if (ptr.getCellRef().getCharge() == 0) return std::make_pair(0, "#{sInventoryMessage1}"); // slots that this item can be equipped in std::pair<std::vector<int>, bool> slots_ = ptr.getClass().getEquipmentSlots(ptr); if (slots_.first.empty()) return std::make_pair(0, ""); if (npc.getClass().isNpc()) { std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace; // Beast races cannot equip shoes / boots, or full helms (head part vs hair part) const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace); if(race->mData.mFlags & ESM::Race::Beast) { std::vector<ESM::PartReference> parts = ptr.get<ESM::Armor>()->mBase->mParts.mParts; for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) { if((*itr).mPart == ESM::PRT_Head) return std::make_pair(0, "#{sNotifyMessage13}"); if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) return std::make_pair(0, "#{sNotifyMessage14}"); } } } for (std::vector<int>::const_iterator slot=slots_.first.begin(); slot!=slots_.first.end(); ++slot) { // If equipping a shield, check if there's a twohanded weapon conflicting with it if(*slot == MWWorld::InventoryStore::Slot_CarriedLeft) { MWWorld::ContainerStoreIterator weapon = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); if(weapon == invStore.end()) return std::make_pair(1,""); if(weapon->getTypeName() == typeid(ESM::Weapon).name() && (weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand || weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose || weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide || weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::SpearTwoWide || weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand || weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow || weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)) { return std::make_pair(3,""); } return std::make_pair(1,""); } } return std::make_pair(1,""); }
int MWMechanics::Alchemy::addIngredient (const MWWorld::Ptr& ingredient) { // find a free slot int slot = -1; for (int i=0; i<static_cast<int> (mIngredients.size()); ++i) if (mIngredients[i].isEmpty()) { slot = i; break; } if (slot==-1) return -1; for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter) if (!iter->isEmpty() && Misc::StringUtils::ciEqual(ingredient.getCellRef().getRefId(), iter->getCellRef().getRefId())) return -1; mIngredients[slot] = ingredient; updateEffects(); return slot; }
void Objects::insertBegin(const MWWorld::Ptr& ptr) { osg::ref_ptr<osg::Group> cellnode; CellMap::iterator found = mCellSceneNodes.find(ptr.getCell()); if (found == mCellSceneNodes.end()) { cellnode = new osg::Group; mRootNode->addChild(cellnode); mCellSceneNodes[ptr.getCell()] = cellnode; } else cellnode = found->second; osg::ref_ptr<SceneUtil::PositionAttitudeTransform> insert (new SceneUtil::PositionAttitudeTransform); cellnode->addChild(insert); insert->getOrCreateUserDataContainer()->addUserObject(new PtrHolder(ptr)); const float *f = ptr.getRefData().getPosition().pos; insert->setPosition(osg::Vec3(f[0], f[1], f[2])); const float scale = ptr.getCellRef().getScale(); osg::Vec3f scaleVec(scale, scale, scale); ptr.getClass().adjustScale(ptr, scaleVec, true); insert->setScale(scaleVec); ptr.getRefData().setBaseNode(insert); }
void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const { if (lockLevel<0) lockLevel = 0; ptr.getCellRef().mLockLevel = lockLevel; }
void TradeItemModel::update() { mSourceModel->update(); int services = 0; if (!mMerchant.isEmpty()) services = mMerchant.getClass().getServices(mMerchant); mItems.clear(); // add regular items for (size_t i=0; i<mSourceModel->getItemCount(); ++i) { ItemStack item = mSourceModel->getItem(i); if(!mMerchant.isEmpty()) { MWWorld::Ptr base = item.mBase; if(Misc::StringUtils::ciEqual(base.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) continue; if(!base.getClass().canSell(base, services)) continue; // Bound items may not be bought if (item.mFlags & ItemStack::Flag_Bound) continue; // don't show equipped items if(mMerchant.getClass().hasInventoryStore(mMerchant)) { MWWorld::InventoryStore& store = mMerchant.getClass().getInventoryStore(mMerchant); if (store.isEquipped(base)) continue; } } // don't show items that we borrowed to someone else std::vector<ItemStack>::iterator it = mBorrowedFromUs.begin(); for (; it != mBorrowedFromUs.end(); ++it) { if (it->mBase == item.mBase) { if (item.mCount < it->mCount) throw std::runtime_error("Lent more items than present"); item.mCount -= it->mCount; } } if (item.mCount > 0) mItems.push_back(item); } // add items borrowed to us std::vector<ItemStack>::iterator it = mBorrowedToUs.begin(); for (; it != mBorrowedToUs.end(); ++it) { ItemStack item = *it; item.mType = ItemStack::Type_Barter; mItems.push_back(item); } }
void WindowManager::setSelectedEnchantItem(const MWWorld::Ptr& item) { const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>() .find(MWWorld::Class::get(item).getEnchantment(item)); int chargePercent = item.getCellRef().mEnchantmentCharge / static_cast<float>(ench->mData.mCharge) * 100; mHud->setSelectedEnchantItem(item, chargePercent); mSpellWindow->setTitle(MWWorld::Class::get(item).getName(item)); }
// Set the position on a sound based on a Ptr. static void setPos(SoundPtr &snd, const MWWorld::Ptr ref) { // Get sound position from the reference const float *pos = ref.getCellRef().pos.pos; // Move the sound, converting from MW coordinates to Ogre // coordinates. snd->setPos(pos[0], pos[2], -pos[1]); }
void Door::setDoorState (const MWWorld::Ptr &ptr, int state) const { if (ptr.getCellRef().getTeleport()) throw std::runtime_error("load doors can't be moved"); ensureCustomData(ptr); DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData(); customData.mDoorState = state; }