aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2015-10-13 05:17:33 +0100
committerparamat <mat.gregory@virginmedia.com>2015-10-18 16:42:59 +0100
commit3b9f99e0d61957c571ba857301d58ad29fb44527 (patch)
treee42aca267416df268d0e971b73c1db4a7e6358fe /src
parent2364449d7a173086c2681eae267b32e5c1596b00 (diff)
downloadminetest-3b9f99e0d61957c571ba857301d58ad29fb44527.tar.gz
minetest-3b9f99e0d61957c571ba857301d58ad29fb44527.tar.bz2
minetest-3b9f99e0d61957c571ba857301d58ad29fb44527.zip
ABMs: Make catch-up behaviour optional
Default is true for backwards compatibility Update lua_api.txt
Diffstat (limited to 'src')
-rw-r--r--src/environment.cpp16
-rw-r--r--src/environment.h2
-rw-r--r--src/script/cpp_api/s_env.cpp7
-rw-r--r--src/script/lua_api/l_env.h10
4 files changed, 25 insertions, 10 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 88f25536f..0b37212e5 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -577,17 +577,21 @@ public:
i->timer -= trigger_interval;
actual_interval = trigger_interval;
}
- float intervals = actual_interval / trigger_interval;
- if(intervals == 0)
- continue;
float chance = abm->getTriggerChance();
if(chance == 0)
chance = 1;
ActiveABM aabm;
aabm.abm = abm;
- aabm.chance = chance / intervals;
- if(aabm.chance == 0)
- aabm.chance = 1;
+ if(abm->getSimpleCatchUp()) {
+ float intervals = actual_interval / trigger_interval;
+ if(intervals == 0)
+ continue;
+ aabm.chance = chance / intervals;
+ if(aabm.chance == 0)
+ aabm.chance = 1;
+ } else {
+ aabm.chance = chance;
+ }
// Trigger neighbors
std::set<std::string> required_neighbors_s
= abm->getRequiredNeighbors();
diff --git a/src/environment.h b/src/environment.h
index 17d7ff19d..42faf5f6d 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -155,6 +155,8 @@ public:
virtual float getTriggerInterval() = 0;
// Random chance of (1 / return value), 0 is disallowed
virtual u32 getTriggerChance() = 0;
+ // Whether to modify chance to simulate time lost by an unnattended block
+ virtual bool getSimpleCatchUp() = 0;
// This is called usually at interval for 1/chance of the nodes
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp
index 9c733773a..b8717597a 100644
--- a/src/script/cpp_api/s_env.cpp
+++ b/src/script/cpp_api/s_env.cpp
@@ -143,8 +143,11 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
int trigger_chance = 50;
getintfield(L, current_abm, "chance", trigger_chance);
- LuaABM *abm = new LuaABM(L, id, trigger_contents,
- required_neighbors, trigger_interval, trigger_chance);
+ bool simple_catch_up = true;
+ getboolfield(L, current_abm, "catch_up", simple_catch_up);
+
+ LuaABM *abm = new LuaABM(L, id, trigger_contents, required_neighbors,
+ trigger_interval, trigger_chance, simple_catch_up);
env->addActiveBlockModifier(abm);
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h
index 2e9fab777..4f204da81 100644
--- a/src/script/lua_api/l_env.h
+++ b/src/script/lua_api/l_env.h
@@ -184,16 +184,18 @@ private:
std::set<std::string> m_required_neighbors;
float m_trigger_interval;
u32 m_trigger_chance;
+ bool m_simple_catch_up;
public:
LuaABM(lua_State *L, int id,
const std::set<std::string> &trigger_contents,
const std::set<std::string> &required_neighbors,
- float trigger_interval, u32 trigger_chance):
+ float trigger_interval, u32 trigger_chance, bool simple_catch_up):
m_id(id),
m_trigger_contents(trigger_contents),
m_required_neighbors(required_neighbors),
m_trigger_interval(trigger_interval),
- m_trigger_chance(trigger_chance)
+ m_trigger_chance(trigger_chance),
+ m_simple_catch_up(simple_catch_up)
{
}
virtual std::set<std::string> getTriggerContents()
@@ -212,6 +214,10 @@ public:
{
return m_trigger_chance;
}
+ virtual bool getSimpleCatchUp()
+ {
+ return m_simple_catch_up;
+ }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider);
};