1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:49:56 +00:00
openmw-tes3mp/apps/openmw/mwgui/jailscreen.cpp
dteviot 3f28634d1f consolidate random number logic
Note, I suspect Rng::rollClosedProbability() is not needed.  The only difference between it and rollProbability() is that one time in 37k (on Windows), it will give an output of 1.0.
On some versions of Linux, the value of 1.0 will occur about 1 time in 4 billion.
2015-03-15 14:07:47 +13:00

131 lines
4.4 KiB
C++

#include <MyGUI_ScrollBar.h>
#include <openengine/misc/rng.hpp>
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/store.hpp"
#include "../mwworld/class.hpp"
#include "jailscreen.hpp"
namespace MWGui
{
JailScreen::JailScreen()
: WindowBase("openmw_jail_screen.layout"),
mTimeAdvancer(0.01f),
mDays(1),
mFadeTimeRemaining(0)
{
getWidget(mProgressBar, "ProgressBar");
setVisible(false);
mTimeAdvancer.eventProgressChanged += MyGUI::newDelegate(this, &JailScreen::onJailProgressChanged);
mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &JailScreen::onJailFinished);
center();
}
void JailScreen::goToJail(int days)
{
mDays = days;
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
mFadeTimeRemaining = 0.5;
setVisible(false);
mProgressBar->setScrollRange(100+1);
mProgressBar->setScrollPosition(0);
mProgressBar->setTrackSize(0);
}
void JailScreen::onFrame(float dt)
{
mTimeAdvancer.onFrame(dt);
if (mFadeTimeRemaining <= 0)
return;
mFadeTimeRemaining -= dt;
if (mFadeTimeRemaining <= 0)
{
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker");
setVisible(true);
mTimeAdvancer.run(100);
}
}
void JailScreen::onJailProgressChanged(int cur, int /*total*/)
{
mProgressBar->setScrollPosition(0);
mProgressBar->setTrackSize(static_cast<int>(cur / (float)(mProgressBar->getScrollRange()) * mProgressBar->getLineSize()));
}
void JailScreen::onJailFinished()
{
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Jail);
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWBase::Environment::get().getWorld()->advanceTime(mDays * 24);
for (int i=0; i<mDays*24; ++i)
MWBase::Environment::get().getMechanicsManager()->rest(true);
std::set<int> skills;
for (int day=0; day<mDays; ++day)
{
int skill = OEngine::Misc::Rng::rollDice(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 MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
std::string message;
if (mDays == 1)
message = gmst.find("sNotifyMessage42")->getString();
else
message = gmst.find("sNotifyMessage43")->getString();
std::stringstream dayStr;
dayStr << mDays;
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()->interactiveMessageBox(message, buttons);
}
}