Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.17 KB | None | 0 0
  1.     bool MechanicsManager::commitCrime(const MWWorld::Ptr &ptr, const MWWorld::Ptr &victim, OffenseType type, int arg)
  2.     {
  3.         // NOTE: int arg can be from itemTaken() so DON'T modify it, since it is
  4.         //  passed to reportCrime later on in this function.
  5.  
  6.         // NPC's can't commit crimes
  7.         if (ptr.getRefData().getHandle() != "player" || victim.isEmpty())
  8.             return false;
  9.  
  10.         // Get game settings store
  11.         const MWWorld::Store<ESM::GameSetting>& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
  12.  
  13.         // What amount of fight and alarm did this crime generate?
  14.         int fight, alarm;
  15.         if (type == OT_Trespassing || type == OT_SleepingInOwnedBed)
  16.         {
  17.             fight = store.find("iFightTrespass")->getFloat();
  18.             alarm = store.find("iAlarmTresspass")->getInt();
  19.  
  20.         }
  21.         else if (type == OT_Pickpocket)
  22.         {
  23.             fight = store.find("iFightPickpocket")->getInt();
  24.             alarm = store.find("iAlarmPickPocket")->getInt();
  25.         }
  26.         else if (type == OT_Assault)
  27.         {
  28.             fight = store.find("iFightAttack")->getInt();
  29.             alarm = store.find("iAlarmAttack")->getInt();
  30.         }
  31.         else if (type == OT_Murder)
  32.         {
  33.             fight = store.find("iFightKilling")->getInt();
  34.             alarm = store.find("iAlarmKilling")->getInt();
  35.         }
  36.         else if (type == OT_Theft)
  37.         {
  38.             fight = store.find("fFightStealing")->getFloat();
  39.             alarm = store.find("iAlarmStealing")->getInt();
  40.         }
  41.  
  42.         // Innocent until proven guilty
  43.         bool reported = false;
  44.  
  45.         // Find all the NPC's close enough, ie. within fAlarmRadius
  46.         std::vector<MWWorld::Ptr> neighbors;
  47.         mActors.getObjectsInRange(Ogre::Vector3(ptr.getRefData().getPosition().pos), store.find("fAlarmRadius")->getInt(), neighbors);
  48.         for (std::vector<MWWorld::Ptr>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
  49.         {
  50.             // Not the offender
  51.             if (*it == ptr)
  52.                 continue;
  53.  
  54.             CreatureStats& creatureStats = MWWorld::Class::get(*it).getCreatureStats(*it);
  55.  
  56.             // Did the witness see the crime?
  57.             if (MWBase::Environment::get().getWorld()->getLOS(ptr, *it) && awarenessCheck(ptr, *it))
  58.             {
  59.  
  60.                 // Will the witness report?
  61.                 if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
  62.                 {
  63.                     // If crime is seen say appropriate message
  64.                     if (type == OT_Theft)
  65.                         MWBase::Environment::get().getDialogueManager()->say(*it, "Thief");
  66.  
  67.                     creatureStats.setAlarmed(true);
  68.                     reported = true;
  69.                 }
  70.  
  71.                 // Will the witness fight?
  72.                 if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
  73.                 {
  74.                     creatureStats.getAiSequence().stack(AiCombat(MWBase::Environment::get().getWorld()->getPlayerPtr()));
  75.                     creatureStats.setHostile(true);
  76.                     creatureStats.getAiSequence().execute(*it,0);
  77.                 }
  78.             }
  79.             // If the witness didn't see the crime, did the victim tell them?
  80.             else if (victim.getClass().getCreatureStats(victim).getAiSetting(CreatureStats::AI_Alarm).getModified() >= alarm)
  81.             {
  82.                 // Does the witness get alarmed?
  83.                 if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
  84.                 {
  85.                     creatureStats.setAlarmed(true);
  86.                     reported = true;
  87.                 }
  88.  
  89.                 // Will the witness fight?
  90.                 if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
  91.                 {
  92.                     creatureStats.getAiSequence().stack(AiCombat(MWBase::Environment::get().getWorld()->getPlayerPtr()));
  93.                     creatureStats.setHostile(true);
  94.                     creatureStats.getAiSequence().execute(*it,0);
  95.                 }
  96.             }
  97.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement