Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool MechanicsManager::commitCrime(const MWWorld::Ptr &ptr, const MWWorld::Ptr &victim, OffenseType type, int arg)
- {
- // NOTE: int arg can be from itemTaken() so DON'T modify it, since it is
- // passed to reportCrime later on in this function.
- // NPC's can't commit crimes
- if (ptr.getRefData().getHandle() != "player" || victim.isEmpty())
- return false;
- // Get game settings store
- const MWWorld::Store<ESM::GameSetting>& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
- // What amount of fight and alarm did this crime generate?
- int fight, alarm;
- if (type == OT_Trespassing || type == OT_SleepingInOwnedBed)
- {
- fight = store.find("iFightTrespass")->getFloat();
- alarm = store.find("iAlarmTresspass")->getInt();
- }
- else if (type == OT_Pickpocket)
- {
- fight = store.find("iFightPickpocket")->getInt();
- alarm = store.find("iAlarmPickPocket")->getInt();
- }
- else if (type == OT_Assault)
- {
- fight = store.find("iFightAttack")->getInt();
- alarm = store.find("iAlarmAttack")->getInt();
- }
- else if (type == OT_Murder)
- {
- fight = store.find("iFightKilling")->getInt();
- alarm = store.find("iAlarmKilling")->getInt();
- }
- else if (type == OT_Theft)
- {
- fight = store.find("fFightStealing")->getFloat();
- alarm = store.find("iAlarmStealing")->getInt();
- }
- // Innocent until proven guilty
- bool reported = false;
- // Find all the NPC's close enough, ie. within fAlarmRadius
- std::vector<MWWorld::Ptr> neighbors;
- mActors.getObjectsInRange(Ogre::Vector3(ptr.getRefData().getPosition().pos), store.find("fAlarmRadius")->getInt(), neighbors);
- for (std::vector<MWWorld::Ptr>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
- {
- // Not the offender
- if (*it == ptr)
- continue;
- CreatureStats& creatureStats = MWWorld::Class::get(*it).getCreatureStats(*it);
- // Did the witness see the crime?
- if (MWBase::Environment::get().getWorld()->getLOS(ptr, *it) && awarenessCheck(ptr, *it))
- {
- // Will the witness report?
- if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
- {
- // If crime is seen say appropriate message
- if (type == OT_Theft)
- MWBase::Environment::get().getDialogueManager()->say(*it, "Thief");
- creatureStats.setAlarmed(true);
- reported = true;
- }
- // Will the witness fight?
- if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
- {
- creatureStats.getAiSequence().stack(AiCombat(MWBase::Environment::get().getWorld()->getPlayerPtr()));
- creatureStats.setHostile(true);
- creatureStats.getAiSequence().execute(*it,0);
- }
- }
- // If the witness didn't see the crime, did the victim tell them?
- else if (victim.getClass().getCreatureStats(victim).getAiSetting(CreatureStats::AI_Alarm).getModified() >= alarm)
- {
- // Does the witness get alarmed?
- if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
- {
- creatureStats.setAlarmed(true);
- reported = true;
- }
- // Will the witness fight?
- if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
- {
- creatureStats.getAiSequence().stack(AiCombat(MWBase::Environment::get().getWorld()->getPlayerPtr()));
- creatureStats.setHostile(true);
- creatureStats.getAiSequence().execute(*it,0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement