forked from mirror/openmw-tes3mp
implemented passing of time
This commit is contained in:
parent
083b11c740
commit
d27c548710
4 changed files with 71 additions and 4 deletions
|
@ -51,6 +51,9 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
||||||
// global scripts
|
// global scripts
|
||||||
mEnvironment.mGlobalScripts->run (mEnvironment);
|
mEnvironment.mGlobalScripts->run (mEnvironment);
|
||||||
|
|
||||||
|
// passing of time (30 times as fast as RL time)
|
||||||
|
mEnvironment.mWorld->advanceTime ((mEnvironment.mFrameDuration*30)/3600);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,17 +133,31 @@ namespace MWScript
|
||||||
|
|
||||||
void InterpreterContext::setGlobalShort (const std::string& name, int value)
|
void InterpreterContext::setGlobalShort (const std::string& name, int value)
|
||||||
{
|
{
|
||||||
|
if (name=="gamehour")
|
||||||
|
mEnvironment.mWorld->setHour (value);
|
||||||
|
else if (name=="day")
|
||||||
|
mEnvironment.mWorld->setDay (value);
|
||||||
|
else
|
||||||
mEnvironment.mWorld->getGlobalVariable (name).mShort = value;
|
mEnvironment.mWorld->getGlobalVariable (name).mShort = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::setGlobalLong (const std::string& name, int value)
|
void InterpreterContext::setGlobalLong (const std::string& name, int value)
|
||||||
{
|
{
|
||||||
// a global long is internally a float.
|
if (name=="gamehour")
|
||||||
|
mEnvironment.mWorld->setHour (value);
|
||||||
|
else if (name=="day")
|
||||||
|
mEnvironment.mWorld->setDay (value);
|
||||||
|
else
|
||||||
mEnvironment.mWorld->getGlobalVariable (name).mLong = value;
|
mEnvironment.mWorld->getGlobalVariable (name).mLong = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::setGlobalFloat (const std::string& name, float value)
|
void InterpreterContext::setGlobalFloat (const std::string& name, float value)
|
||||||
{
|
{
|
||||||
|
if (name=="gamehour")
|
||||||
|
mEnvironment.mWorld->setHour (value);
|
||||||
|
else if (name=="day")
|
||||||
|
mEnvironment.mWorld->setDay (value);
|
||||||
|
else
|
||||||
mEnvironment.mWorld->getGlobalVariable (name).mFloat = value;
|
mEnvironment.mWorld->getGlobalVariable (name).mFloat = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "components/bsa/bsa_archive.hpp"
|
#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 enable (Ptr reference);
|
||||||
|
|
||||||
void disable (Ptr reference);
|
void disable (Ptr reference);
|
||||||
|
|
||||||
|
void advanceTime (double hours);
|
||||||
|
|
||||||
|
void setHour (double hour);
|
||||||
|
|
||||||
|
void setDay (int day);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue