std::string InterpreterContext::getPCNextRank() const { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); std::string factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); if (factionId.empty()) throw std::runtime_error("getPCNextRank(): NPC is not in a faction"); const std::map<std::string, int>& ranks = player.getClass().getNpcStats (player).getFactionRanks(); std::map<std::string, int>::const_iterator it = ranks.find(Misc::StringUtils::lowerCase(factionId)); int rank = -1; if (it != ranks.end()) rank = it->second; ++rank; // Next rank // if we are already at max rank, there is no next rank if (rank > 9) rank = 9; const MWWorld::ESMStore &store = world->getStore(); const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId); if(rank < 0 || rank > 9) return ""; return faction->mRanks[rank]; }
std::string InterpreterContext::getPCNextRank() const { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); std::string factionId = getReferenceImp().getClass().getNpcStats (getReferenceImp()).getFactionRanks().begin()->first; std::map<std::string, int> ranks = player.getClass().getNpcStats (player).getFactionRanks(); std::map<std::string, int>::const_iterator it = ranks.find(factionId); int rank = -1; if (it != ranks.end()) rank = it->second; ++rank; // Next rank // if we are already at max rank, there is no next rank if (rank > 9) rank = 9; const MWWorld::ESMStore &store = world->getStore(); const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId); if(rank < 0 || rank > 9) return ""; return faction->mRanks[rank]; }
std::string InterpreterContext::getPCRank() const { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); std::string factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); if (factionId.empty()) throw std::runtime_error("getPCRank(): NPC is not in a faction"); const std::map<std::string, int>& ranks = player.getClass().getNpcStats (player).getFactionRanks(); std::map<std::string, int>::const_iterator it = ranks.find(Misc::StringUtils::lowerCase(factionId)); int rank = -1; if (it != ranks.end()) rank = it->second; // If you are not in the faction, PcRank returns the first rank, for whatever reason. // This is used by the dialogue when joining the Thieves Guild in Balmora. if (rank == -1) rank = 0; const MWWorld::ESMStore &store = world->getStore(); const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId); if(rank < 0 || rank > 9) // there are only 10 ranks return ""; return faction->mRanks[rank]; }
std::string InterpreterContext::getNPCRank() const { std::map<std::string, int> ranks = getReferenceImp().getClass().getNpcStats (getReferenceImp()).getFactionRanks(); std::map<std::string, int>::const_iterator it = ranks.begin(); MWBase::World *world = MWBase::Environment::get().getWorld(); const MWWorld::ESMStore &store = world->getStore(); const ESM::Faction *faction = store.get<ESM::Faction>().find(it->first); return faction->mRanks[it->second]; }
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const { // NOTE: id may be empty, indicating an implicit reference MWWorld::Ptr ref2; if (id.empty()) ref2 = getReferenceImp(); else ref2 = MWBase::Environment::get().getWorld()->searchPtr(id, true); // If either actor is in a non-active cell, return a large value (just like vanilla) if (ref2.isEmpty()) return std::numeric_limits<float>().max(); const MWWorld::Ptr ref = MWBase::Environment::get().getWorld()->searchPtr(name, true); if (ref.isEmpty()) return std::numeric_limits<float>().max(); double diff[3]; const float* const pos1 = ref.getRefData().getPosition().pos; const float* const pos2 = ref2.getRefData().getPosition().pos; for (int i=0; i<3; ++i) diff[i] = pos1[i] - pos2[i]; return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]); }
std::string InterpreterContext::getNPCRank() const { const MWWorld::Ptr& ptr = getReferenceImp(); std::string faction = ptr.getClass().getPrimaryFaction(ptr); if (faction.empty()) throw std::runtime_error("getNPCRank(): NPC is not in a faction"); int rank = ptr.getClass().getPrimaryFactionRank(ptr); if (rank < 0 || rank > 9) throw std::runtime_error("getNPCRank(): invalid rank"); MWBase::World *world = MWBase::Environment::get().getWorld(); const MWWorld::ESMStore &store = world->getStore(); const ESM::Faction *fact = store.get<ESM::Faction>().find(faction); return fact->mRanks[rank]; }
Locals& InterpreterContext::getMemberLocals (std::string& id, bool global) { if (global) { return MWBase::Environment::get().getScriptManager()->getGlobalScripts(). getLocals (id); } else { const MWWorld::Ptr ptr = getReferenceImp (id, false); id = ptr.getClass().getScript (ptr); ptr.getRefData().setLocals ( *MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (id)); return ptr.getRefData().getLocals(); } }
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const { // NOTE: id may be empty, indicating an implicit reference MWWorld::Ptr ref2; if (id.empty()) ref2 = getReferenceImp(); else ref2 = MWBase::Environment::get().getWorld()->getPtr(id, false); if (ref2.getContainerStore()) // is the object contained? { MWWorld::Ptr container = MWBase::Environment::get().getWorld()->findContainer(ref2); if (!container.isEmpty()) ref2 = container; else throw std::runtime_error("failed to find container ptr"); } const MWWorld::Ptr ref = MWBase::Environment::get().getWorld()->getPtr(name, false); // If the objects are in different worldspaces, return a large value (just like vanilla) if (ref.getCell()->getCell()->getCellId().mWorldspace != ref2.getCell()->getCell()->getCellId().mWorldspace) return std::numeric_limits<float>::max(); double diff[3]; const float* const pos1 = ref.getRefData().getPosition().pos; const float* const pos2 = ref2.getRefData().getPosition().pos; for (int i=0; i<3; ++i) diff[i] = pos1[i] - pos2[i]; return static_cast<float>(std::sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2])); }
MWWorld::Ptr InterpreterContext::getReference(bool required) { return getReferenceImp ("", true, required); }
void InterpreterContext::disable (const std::string& id) { MWWorld::Ptr ref = getReferenceImp (id, false); MWBase::Environment::get().getWorld()->disable (ref); }
bool InterpreterContext::isDisabled (const std::string& id) const { const MWWorld::Ptr ref = getReferenceImp (id, false); return !ref.getRefData().isEnabled(); }
std::string InterpreterContext::getNPCFaction() const { ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase; const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(npc.mFaction); return faction->mName; }
std::string InterpreterContext::getNPCClass() const { ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase; const ESM::Class* class_ = MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find(npc.mClass); return class_->mName; }
std::string InterpreterContext::getNPCRace() const { ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase; const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npc.mRace); return race->mName; }
std::string InterpreterContext::getNPCName() const { ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase; return npc.mName; }