Confiscate stolen items when caught

This commit is contained in:
scrawl 2014-01-11 03:29:41 +01:00
parent 909494ff35
commit bf6d302fba
6 changed files with 66 additions and 3 deletions

View file

@ -451,6 +451,9 @@ namespace MWBase
/// Update the value of some globals according to the world state, which may be used by dialogue entries. /// Update the value of some globals according to the world state, which may be used by dialogue entries.
/// This should be called when initiating a dialogue. /// This should be called when initiating a dialogue.
virtual void updateDialogueGlobals() = 0; virtual void updateDialogueGlobals() = 0;
/// Moves all stolen items from \a ptr to the closest evidence chest.
virtual void confiscateStolenItems(const MWWorld::Ptr& ptr) = 0;
}; };
} }

View file

@ -769,8 +769,8 @@ namespace MWScript
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
world->teleportToClosestMarker(player, "prisonmarker"); world->teleportToClosestMarker(player, "prisonmarker");
player.getClass().getNpcStats(player).setBounty(0); player.getClass().getNpcStats(player).setBounty(0);
world->confiscateStolenItems(player);
// TODO: pass time, change skills, show messagebox // TODO: pass time, change skills, show messagebox
// TODO: move stolen items to closest evidence chest
// iDaysinPrisonMod // iDaysinPrisonMod
} }
}; };
@ -782,8 +782,7 @@ namespace MWScript
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
player.getClass().getNpcStats(player).setBounty(0); player.getClass().getNpcStats(player).setBounty(0);
MWBase::Environment::get().getWorld()->confiscateStolenItems(player);
// TODO: move stolen items to closest evidence chest
} }
}; };

View file

@ -271,3 +271,15 @@ void MWWorld::Cells::getExteriorPtrs(const std::string &name, std::vector<MWWorl
} }
} }
void MWWorld::Cells::getInteriorPtrs(const std::string &name, std::vector<MWWorld::Ptr> &out)
{
for (std::map<std::string, Ptr::CellStore>::iterator iter = mInteriors.begin();
iter!=mInteriors.end(); ++iter)
{
Ptr ptr = getPtrAndCache (name, iter->second);
if (!ptr.isEmpty())
out.push_back(ptr);
}
}

View file

@ -56,6 +56,12 @@ namespace MWWorld
/// @note Due to the current implementation of getPtr this only supports one Ptr per cell. /// @note Due to the current implementation of getPtr this only supports one Ptr per cell.
/// @note name must be lower case /// @note name must be lower case
void getExteriorPtrs (const std::string& name, std::vector<MWWorld::Ptr>& out); void getExteriorPtrs (const std::string& name, std::vector<MWWorld::Ptr>& out);
/// Get all Ptrs referencing \a name in interior cells
/// @note Due to the current implementation of getPtr this only supports one Ptr per cell.
/// @note name must be lower case
void getInteriorPtrs (const std::string& name, std::vector<MWWorld::Ptr>& out);
}; };
} }

View file

@ -2446,4 +2446,44 @@ namespace MWWorld
mGlobalVariables->setInt("crimegoldturnin", turnIn); mGlobalVariables->setInt("crimegoldturnin", turnIn);
mGlobalVariables->setInt("pchasturnin", (turnIn <= playerGold) ? 1 : 0); mGlobalVariables->setInt("pchasturnin", (turnIn <= playerGold) ? 1 : 0);
} }
void World::confiscateStolenItems(const Ptr &ptr)
{
Ogre::Vector3 playerPos;
if (!findInteriorPositionInWorldSpace(ptr.getCell(), playerPos))
playerPos = mPlayer->getLastKnownExteriorPosition();
MWWorld::Ptr closestChest;
float closestDistance = FLT_MAX;
std::vector<MWWorld::Ptr> chests;
mCells.getInteriorPtrs("stolen_goods", chests);
Ogre::Vector3 chestPos;
for (std::vector<MWWorld::Ptr>::iterator it = chests.begin(); it != chests.end(); ++it)
{
if (!findInteriorPositionInWorldSpace(it->getCell(), chestPos))
continue;
float distance = playerPos.squaredDistance(chestPos);
if (distance < closestDistance)
{
closestDistance = distance;
closestChest = *it;
}
}
if (!closestChest.isEmpty())
{
ContainerStore& store = ptr.getClass().getContainerStore(ptr);
for (ContainerStoreIterator it = store.begin(); it != store.end(); ++it)
{
if (!it->getCellRef().mOwner.empty() && it->getCellRef().mOwner != "player")
{
closestChest.getClass().getContainerStore(closestChest).add(*it, it->getRefData().getCount(), closestChest);
store.remove(*it, it->getRefData().getCount(), ptr);
}
}
}
}
} }

View file

@ -536,6 +536,9 @@ namespace MWWorld
/// Update the value of some globals according to the world state, which may be used by dialogue entries. /// Update the value of some globals according to the world state, which may be used by dialogue entries.
/// This should be called when initiating a dialogue. /// This should be called when initiating a dialogue.
virtual void updateDialogueGlobals(); virtual void updateDialogueGlobals();
/// Moves all stolen items from \a ptr to the closest evidence chest.
virtual void confiscateStolenItems(const MWWorld::Ptr& ptr);
}; };
} }