implemented passing of time

pull/7/head
Marc Zinnschlag 15 years ago
parent 083b11c740
commit d27c548710

@ -51,6 +51,9 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
// global scripts
mEnvironment.mGlobalScripts->run (mEnvironment);
// passing of time (30 times as fast as RL time)
mEnvironment.mWorld->advanceTime ((mEnvironment.mFrameDuration*30)/3600);
return true;
}

@ -133,18 +133,32 @@ namespace MWScript
void InterpreterContext::setGlobalShort (const std::string& name, int value)
{
mEnvironment.mWorld->getGlobalVariable (name).mShort = value;
if (name=="gamehour")
mEnvironment.mWorld->setHour (value);
else if (name=="day")
mEnvironment.mWorld->setDay (value);
else
mEnvironment.mWorld->getGlobalVariable (name).mShort = value;
}
void InterpreterContext::setGlobalLong (const std::string& name, int value)
{
// a global long is internally a float.
mEnvironment.mWorld->getGlobalVariable (name).mLong = value;
if (name=="gamehour")
mEnvironment.mWorld->setHour (value);
else if (name=="day")
mEnvironment.mWorld->setDay (value);
else
mEnvironment.mWorld->getGlobalVariable (name).mLong = value;
}
void InterpreterContext::setGlobalFloat (const std::string& name, float value)
{
mEnvironment.mWorld->getGlobalVariable (name).mFloat = value;
if (name=="gamehour")
mEnvironment.mWorld->setHour (value);
else if (name=="day")
mEnvironment.mWorld->setDay (value);
else
mEnvironment.mWorld->getGlobalVariable (name).mFloat = value;
}
bool InterpreterContext::isScriptRunning (const std::string& name) const

@ -1,6 +1,7 @@
#include "world.hpp"
#include <cmath>
#include <iostream>
#include "components/bsa/bsa_archive.hpp"
@ -278,4 +279,47 @@ namespace MWWorld
}
}
}
void World::advanceTime (double hours)
{
hours += mGlobalVariables->getFloat ("gamehour");
setHour (hours);
}
void World::setHour (double hour)
{
if (hour<0)
hour = 0;
int days = hour / 24;
hour = std::fmod (hour, 24);
mGlobalVariables->setFloat ("gamehour", hour);
if (days>0)
{
setDay (days + mGlobalVariables->getInt ("year"));
days += mGlobalVariables->getInt ("dayspassed");
mGlobalVariables->setInt ("dayspassed", days);
}
}
void World::setDay (int day)
{
if (day<0)
day = 0;
int year = day / 365;
day = day % 365;
mGlobalVariables->setInt ("day", day);
if (year>0)
{
year += mGlobalVariables->getInt ("year");
mGlobalVariables->setInt ("year", year);
}
}
}

@ -88,6 +88,12 @@ namespace MWWorld
void enable (Ptr reference);
void disable (Ptr reference);
void advanceTime (double hours);
void setHour (double hour);
void setDay (int day);
};
}

Loading…
Cancel
Save