Implemented GoToJail

actorid
scrawl 11 years ago
parent 3896c88403
commit a2ba0dde31

@ -458,6 +458,8 @@ namespace MWBase
/// Moves all stolen items from \a ptr to the closest evidence chest.
virtual void confiscateStolenItems(const MWWorld::Ptr& ptr) = 0;
virtual void goToJail () = 0;
};
}

@ -766,12 +766,7 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr();
world->teleportToClosestMarker(player, "prisonmarker");
player.getClass().getNpcStats(player).setBounty(0);
world->confiscateStolenItems(player);
// TODO: pass time, change skills, show messagebox
// iDaysinPrisonMod
world->goToJail();
}
};

@ -216,7 +216,7 @@ namespace MWWorld
mSky (true), mCells (mStore, mEsm),
mActivationDistanceOverride (mActivationDistanceOverride),
mFallback(fallbackMap), mPlayIntro(0), mTeleportEnabled(true), mLevitationEnabled(false),
mFacedDistance(FLT_MAX), mGodMode(false)
mFacedDistance(FLT_MAX), mGodMode(false), mGoToJail(false)
{
mPhysics = new PhysicsSystem(renderer);
mPhysEngine = mPhysics->getEngine();
@ -259,6 +259,9 @@ namespace MWWorld
void World::startNewGame()
{
mGoToJail = false;
mLevitationEnabled = true;
mTeleportEnabled = true;
mWorldScene->changeToVoid();
mStore.clearDynamic();
@ -1272,6 +1275,9 @@ namespace MWWorld
mRendering->playVideo(mFallback.getFallbackString("Movies_New_Game"), true);
}
if (mGoToJail && !paused)
goToJail();
updateWeather(duration);
mWorldScene->update (duration, paused);
@ -2491,4 +2497,75 @@ namespace MWWorld
}
}
}
void World::goToJail()
{
if (!mGoToJail)
{
// Save for next update, since the player should be able to read the dialog text first
mGoToJail = true;
return;
}
else
{
mGoToJail = false;
MWWorld::Ptr player = getPlayerPtr();
teleportToClosestMarker(player, "prisonmarker");
int bounty = player.getClass().getNpcStats(player).getBounty();
player.getClass().getNpcStats(player).setBounty(0);
confiscateStolenItems(player);
int iDaysinPrisonMod = getStore().get<ESM::GameSetting>().find("iDaysinPrisonMod")->getInt();
int days = std::max(1, bounty / iDaysinPrisonMod);
advanceTime(days * 24);
std::set<int> skills;
for (int day=0; day<days; ++day)
{
int skill = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * ESM::Skill::Length;
skills.insert(skill);
MWMechanics::SkillValue& value = player.getClass().getNpcStats(player).getSkill(skill);
if (skill == ESM::Skill::Security || skill == ESM::Skill::Sneak)
value.setBase(std::min(100, value.getBase()+1));
else
value.setBase(value.getBase()-1);
}
const Store<ESM::GameSetting>& gmst = getStore().get<ESM::GameSetting>();
std::string message;
if (days == 1)
message = gmst.find("sNotifyMessage42")->getString();
else
message = gmst.find("sNotifyMessage43")->getString();
std::stringstream dayStr;
dayStr << days;
if (message.find("%d") != std::string::npos)
message.replace(message.find("%d"), 2, dayStr.str());
for (std::set<int>::iterator it = skills.begin(); it != skills.end(); ++it)
{
std::string skillName = gmst.find(ESM::Skill::sSkillNameIds[*it])->getString();
std::stringstream skillValue;
skillValue << player.getClass().getNpcStats(player).getSkill(*it).getBase();
std::string skillMsg = gmst.find("sNotifyMessage44")->getString();
if (*it == ESM::Skill::Sneak || *it == ESM::Skill::Security)
skillMsg = gmst.find("sNotifyMessage39")->getString();
if (skillMsg.find("%s") != std::string::npos)
skillMsg.replace(skillMsg.find("%s"), 2, skillName);
if (skillMsg.find("%d") != std::string::npos)
skillMsg.replace(skillMsg.find("%d"), 2, skillValue.str());
message += "\n" + skillMsg;
}
std::vector<std::string> buttons;
buttons.push_back("#{sOk}");
MWBase::Environment::get().getWindowManager()->messageBox(message, buttons);
}
}
}

@ -151,6 +151,7 @@ namespace MWWorld
bool mTeleportEnabled;
bool mLevitationEnabled;
bool mGoToJail;
/// Called when \a object is moved to an inactive cell
void objectLeftActiveCell (MWWorld::Ptr object, MWWorld::Ptr movedPtr);
@ -543,6 +544,8 @@ namespace MWWorld
/// Moves all stolen items from \a ptr to the closest evidence chest.
virtual void confiscateStolenItems(const MWWorld::Ptr& ptr);
virtual void goToJail ();
};
}

Loading…
Cancel
Save