|
|
|
@ -12,6 +12,9 @@
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
|
|
|
|
|
|
#include "aicombat.hpp"
|
|
|
|
|
#include "aiactivate.hpp"
|
|
|
|
|
|
|
|
|
|
#include <OgreSceneNode.h>
|
|
|
|
|
|
|
|
|
|
#include "spellcasting.hpp"
|
|
|
|
@ -801,42 +804,121 @@ namespace MWMechanics
|
|
|
|
|
|
|
|
|
|
bool MechanicsManager::commitCrime(const MWWorld::Ptr &ptr, const MWWorld::Ptr &victim, OffenseType type, int arg)
|
|
|
|
|
{
|
|
|
|
|
if (ptr.getRefData().getHandle() != "player")
|
|
|
|
|
// NOTE: int arg can be from itemTaken() so DON'T modify it, since it is
|
|
|
|
|
// passed to reportCrime later on in this function.
|
|
|
|
|
|
|
|
|
|
// Only player can commit crime and no victimless crimes
|
|
|
|
|
if (ptr.getRefData().getHandle() != "player" || victim.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool reported=false;
|
|
|
|
|
for (Actors::PtrControllerMap::const_iterator it = mActors.begin(); it != mActors.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it->first != ptr &&
|
|
|
|
|
MWBase::Environment::get().getWorld()->getLOS(ptr, it->first) &&
|
|
|
|
|
awarenessCheck(ptr, it->first))
|
|
|
|
|
const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
|
|
|
|
|
// What amount of alarm did this crime generate?
|
|
|
|
|
int alarm;
|
|
|
|
|
if (type == OT_Trespassing || type == OT_SleepingInOwnedBed)
|
|
|
|
|
alarm = esmStore.get<ESM::GameSetting>().find("iAlarmTresspass")->getInt();
|
|
|
|
|
else if (type == OT_Pickpocket)
|
|
|
|
|
alarm = esmStore.get<ESM::GameSetting>().find("iAlarmPickPocket")->getInt();
|
|
|
|
|
else if (type == OT_Assault)
|
|
|
|
|
alarm = esmStore.get<ESM::GameSetting>().find("iAlarmAttack")->getInt();
|
|
|
|
|
else if (type == OT_Murder)
|
|
|
|
|
alarm = esmStore.get<ESM::GameSetting>().find("iAlarmKilling")->getInt();
|
|
|
|
|
else if (type == OT_Theft)
|
|
|
|
|
alarm = esmStore.get<ESM::GameSetting>().find("iAlarmStealing")->getInt();
|
|
|
|
|
|
|
|
|
|
// Innocent until proven guilty
|
|
|
|
|
bool reported = false;
|
|
|
|
|
|
|
|
|
|
// Find all the NPC's close enough, ie. within fAlarmRadius of the player
|
|
|
|
|
std::vector<MWWorld::Ptr> neighbors;
|
|
|
|
|
mActors.getObjectsInRange(Ogre::Vector3(ptr.getRefData().getPosition().pos),
|
|
|
|
|
esmStore.get<ESM::GameSetting>().find("fAlarmRadius")->getInt(), neighbors);
|
|
|
|
|
|
|
|
|
|
// Did anyone see the crime?
|
|
|
|
|
for (std::vector<MWWorld::Ptr>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (*it == ptr) // Not the player
|
|
|
|
|
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) )
|
|
|
|
|
{
|
|
|
|
|
// NPCs will always curse you when they notice you steal their items, even if they don't report the crime
|
|
|
|
|
if (it->first == victim && type == OT_Theft)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getDialogueManager()->say(victim, "Thief");
|
|
|
|
|
}
|
|
|
|
|
// Say something!
|
|
|
|
|
// TODO: Add more messages
|
|
|
|
|
if (type == OT_Theft)
|
|
|
|
|
MWBase::Environment::get().getDialogueManager()->say(*it, "Thief");
|
|
|
|
|
|
|
|
|
|
// Actor has witnessed a crime. Will he report it?
|
|
|
|
|
// (not sure, is > 0 correct?)
|
|
|
|
|
if (it->first.getClass().getCreatureStats(it->first).getAiSetting(CreatureStats::AI_Alarm).getModified() > 0)
|
|
|
|
|
// Will the witness report the crime?
|
|
|
|
|
if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
|
|
|
|
|
{
|
|
|
|
|
// TODO: stats.setAlarmed(true) on NPCs within earshot
|
|
|
|
|
// fAlarmRadius ?
|
|
|
|
|
reported=true;
|
|
|
|
|
break;
|
|
|
|
|
creatureStats.setAlarmed(true);
|
|
|
|
|
reported = true;
|
|
|
|
|
reportCrime(ptr, victim, type, arg);
|
|
|
|
|
|
|
|
|
|
// Is it a guard? Or will the witness fight?
|
|
|
|
|
if (it->getClass().isClass(*it, "Guard"))
|
|
|
|
|
{
|
|
|
|
|
// TODO: Persue player, concider bounty?
|
|
|
|
|
creatureStats.getAiSequence().stack(AiActivate(ptr.getClass().getId(ptr), 1));
|
|
|
|
|
creatureStats.getAiSequence().execute(*it,0);
|
|
|
|
|
}
|
|
|
|
|
else if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
|
|
|
|
|
{
|
|
|
|
|
creatureStats.getAiSequence().stack(AiCombat(ptr));
|
|
|
|
|
creatureStats.setHostile(true);
|
|
|
|
|
creatureStats.getAiSequence().execute(*it,0);
|
|
|
|
|
}
|
|
|
|
|
else if (type == OT_Assault)
|
|
|
|
|
{
|
|
|
|
|
creatureStats.getAiSequence().stack(AiCombat(ptr));
|
|
|
|
|
creatureStats.setHostile(true);
|
|
|
|
|
creatureStats.getAiSequence().execute(*it,0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tell everyone else
|
|
|
|
|
for (std::vector<MWWorld::Ptr>::iterator it1 = neighbors.begin(); it1 != neighbors.end(); ++it1)
|
|
|
|
|
{
|
|
|
|
|
if (it == it1 || // Don't tell the witness or the player
|
|
|
|
|
ptr == *it1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Is it a guard? Or will the witness fight?
|
|
|
|
|
CreatureStats& creatureStats1 = MWWorld::Class::get(*it1).getCreatureStats(*it1);
|
|
|
|
|
if (it1->getClass().isClass(*it1, "Guard"))
|
|
|
|
|
{
|
|
|
|
|
// TODO: Persue player, concider bounty?
|
|
|
|
|
creatureStats1.getAiSequence().stack(AiActivate(ptr.getClass().getId(ptr), 1));
|
|
|
|
|
creatureStats1.getAiSequence().execute(*it1,0);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (creatureStats1.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
|
|
|
|
|
{
|
|
|
|
|
creatureStats1.getAiSequence().stack(AiCombat(ptr));
|
|
|
|
|
creatureStats1.setHostile(true);
|
|
|
|
|
creatureStats1.getAiSequence().execute(*it1,0);
|
|
|
|
|
}
|
|
|
|
|
else if (type == OT_Assault)
|
|
|
|
|
{
|
|
|
|
|
creatureStats.getAiSequence().stack(AiCombat(ptr));
|
|
|
|
|
creatureStats.setHostile(true);
|
|
|
|
|
creatureStats.getAiSequence().execute(*it,0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break; // Someone saw the crime and everyone has been told
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reported)
|
|
|
|
|
reportCrime(ptr, victim, type, arg);
|
|
|
|
|
return reported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MechanicsManager::reportCrime(const MWWorld::Ptr &ptr, const MWWorld::Ptr &victim, OffenseType type, int arg)
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::Store<ESM::GameSetting>& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
|
|
|
|
|
|
|
|
// Bounty for each type of crime
|
|
|
|
|
if (type == OT_Trespassing || type == OT_SleepingInOwnedBed)
|
|
|
|
|
arg = store.find("iCrimeTresspass")->getInt();
|
|
|
|
@ -849,32 +931,10 @@ namespace MWMechanics
|
|
|
|
|
else if (type == OT_Theft)
|
|
|
|
|
arg *= store.find("fCrimeStealing")->getFloat();
|
|
|
|
|
|
|
|
|
|
// TODO: In some cases (type == Assault), if no NPCs are within earshot, the report will have no effect.
|
|
|
|
|
// however other crime types seem to be always produce a bounty.
|
|
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sCrimeMessage}");
|
|
|
|
|
ptr.getClass().getNpcStats(ptr).setBounty(ptr.getClass().getNpcStats(ptr).getBounty()
|
|
|
|
|
+ arg);
|
|
|
|
|
|
|
|
|
|
if (!victim.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
int fight = 0;
|
|
|
|
|
// Increase in fight rating for each type of crime
|
|
|
|
|
if (type == OT_Trespassing || type == OT_SleepingInOwnedBed)
|
|
|
|
|
fight = store.find("iFightTrespass")->getFloat();
|
|
|
|
|
else if (type == OT_Pickpocket)
|
|
|
|
|
fight = store.find("iFightPickpocket")->getInt();
|
|
|
|
|
else if (type == OT_Assault)
|
|
|
|
|
fight = store.find("iFightAttack")->getInt();
|
|
|
|
|
else if (type == OT_Murder)
|
|
|
|
|
fight = store.find("iFightKilling")->getInt();
|
|
|
|
|
else if (type == OT_Theft)
|
|
|
|
|
fight = store.find("fFightStealing")->getFloat();
|
|
|
|
|
// Not sure if this should be permanent?
|
|
|
|
|
fight = victim.getClass().getCreatureStats(victim).getAiSetting(CreatureStats::AI_Fight).getBase() + fight;
|
|
|
|
|
victim.getClass().getCreatureStats(victim).setAiSetting(CreatureStats::AI_Fight, fight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If committing a crime against a faction member, expell from the faction
|
|
|
|
|
if (!victim.isEmpty() && victim.getClass().isNpc())
|
|
|
|
|
{
|
|
|
|
@ -886,8 +946,6 @@ namespace MWMechanics
|
|
|
|
|
ptr.getClass().getNpcStats(ptr).expell(factionID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: make any guards in the area try to arrest the player
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MechanicsManager::awarenessCheck(const MWWorld::Ptr &ptr, const MWWorld::Ptr &observer)
|
|
|
|
|