aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-01-02 20:26:33 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-01-02 20:26:33 +0200
commit46302813186253a993b9f901fa5f3097961d3229 (patch)
treee06c5cbb895cc2938e0c4e1102c6150fe72df70a
parentcd0019acd28bf7d2b6de44fc366804f0d17c80b2 (diff)
downloadminetest-46302813186253a993b9f901fa5f3097961d3229.tar.gz
minetest-46302813186253a993b9f901fa5f3097961d3229.tar.bz2
minetest-46302813186253a993b9f901fa5f3097961d3229.zip
Fix ABM trigger chance being often way too high
-rw-r--r--src/environment.cpp4
-rw-r--r--src/environment.h3
2 files changed, 5 insertions, 2 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 88f1527fc..53a7fdf9b 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -588,15 +588,17 @@ public:
float trigger_interval = abm->getTriggerInterval();
if(trigger_interval < 0.001)
trigger_interval = 0.001;
+ float actual_interval = dtime_s;
if(use_timers){
i->timer += dtime_s;
if(i->timer < trigger_interval)
continue;
i->timer -= trigger_interval;
+ actual_interval = trigger_interval;
}
ActiveABM aabm;
aabm.abm = abm;
- float intervals = dtime_s / trigger_interval;
+ float intervals = actual_interval / trigger_interval;
float chance = abm->getTriggerChance();
if(chance == 0)
chance = 1;
diff --git a/src/environment.h b/src/environment.h
index 3ebbee910..f8df77f79 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -130,7 +130,8 @@ struct ABMWithState
float timer;
ABMWithState(ActiveBlockModifier *abm_):
- abm(abm_)
+ abm(abm_),
+ timer(0)
{}
};