summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Plugin.h1
-rw-r--r--source/PluginLua.cpp12
-rw-r--r--source/PluginLua.h1
-rw-r--r--source/PluginManager.cpp21
-rw-r--r--source/PluginManager.h2
-rw-r--r--source/World.cpp3
6 files changed, 40 insertions, 0 deletions
diff --git a/source/Plugin.h b/source/Plugin.h
index d7d91eafc..2595b9470 100644
--- a/source/Plugin.h
+++ b/source/Plugin.h
@@ -94,6 +94,7 @@ public:
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) = 0;
virtual bool OnWeatherChanged (cWorld & a_World) = 0;
virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) = 0;
+ virtual bool OnWorldTick (cWorld & a_World, float a_Dt) = 0;
/** Handles the command split into a_Split, issued by player a_Player.
Command permissions have already been checked.
diff --git a/source/PluginLua.cpp b/source/PluginLua.cpp
index 62911a31c..5ceae29f9 100644
--- a/source/PluginLua.cpp
+++ b/source/PluginLua.cpp
@@ -734,6 +734,17 @@ bool cPlugin_NewLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather
+bool cPlugin_NewLua::OnWorldTick(cWorld & a_World, float a_Dt)
+{
+ cCSLock Lock(m_CriticalSection);
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_WORLD_TICK), &a_World, a_Dt);
+ return false;
+}
+
+
+
+
+
bool cPlugin_NewLua::HandleCommand(const AStringVector & a_Split, cPlayer * a_Player)
{
ASSERT(!a_Split.empty());
@@ -908,6 +919,7 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
case cPluginManager::HOOK_UPDATING_SIGN: return "OnUpdatingSign";
case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged";
case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging";
+ case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick";
default: return NULL;
} // switch (a_Hook)
}
diff --git a/source/PluginLua.h b/source/PluginLua.h
index dfeacf800..14bfda9e8 100644
--- a/source/PluginLua.h
+++ b/source/PluginLua.h
@@ -90,6 +90,7 @@ public:
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override;
virtual bool OnWeatherChanged (cWorld & a_World) override;
virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) override;
+ virtual bool OnWorldTick (cWorld & a_World, float a_Dt) override;
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer * a_Player) override;
diff --git a/source/PluginManager.cpp b/source/PluginManager.cpp
index de1963f91..104f58aaa 100644
--- a/source/PluginManager.cpp
+++ b/source/PluginManager.cpp
@@ -1180,6 +1180,27 @@ bool cPluginManager::CallHookWeatherChanging(cWorld & a_World, eWeather & a_NewW
+bool cPluginManager::CallHookWorldTick(cWorld & a_World, float a_Dt)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_WORLD_TICK);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnWorldTick(a_World, a_Dt))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions)
{
ASSERT(a_Player != NULL);
diff --git a/source/PluginManager.h b/source/PluginManager.h
index b90f90156..290737461 100644
--- a/source/PluginManager.h
+++ b/source/PluginManager.h
@@ -106,6 +106,7 @@ public: // tolua_export
HOOK_UPDATING_SIGN,
HOOK_WEATHER_CHANGED,
HOOK_WEATHER_CHANGING,
+ HOOK_WORLD_TICK,
// Note that if a hook type is added, it may need processing in cPlugin::CanAddHook() descendants,
// and it definitely needs adding in cPlugin_NewLua::GetHookFnName() !
@@ -184,6 +185,7 @@ public: // tolua_export
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
bool CallHookWeatherChanged (cWorld & a_World);
bool CallHookWeatherChanging (cWorld & a_World, eWeather & a_NewWeather);
+ bool CallHookWorldTick (cWorld & a_World, float a_Dt);
bool DisablePlugin(const AString & a_PluginName); // tolua_export
bool LoadPlugin (const AString & a_PluginName); // tolua_export
diff --git a/source/World.cpp b/source/World.cpp
index 70dbb5284..2485a1154 100644
--- a/source/World.cpp
+++ b/source/World.cpp
@@ -576,6 +576,9 @@ void cWorld::Stop(void)
void cWorld::Tick(float a_Dt)
{
+ // Call the plugins
+ cPluginManager::Get()->CallHookWorldTick(*this, a_Dt);
+
// We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
m_WorldAgeSecs += (double)a_Dt / 1000.0;
m_TimeOfDaySecs += (double)a_Dt / 1000.0;