Fix ABM trigger chance being often way too high
authorPerttu Ahola <celeron55@gmail.com>
Mon, 2 Jan 2012 18:26:33 +0000 (20:26 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 2 Jan 2012 18:26:33 +0000 (20:26 +0200)
src/environment.cpp
src/environment.h

index 88f1527fcc4233fe5823f8b61af87a3a0eebe4a7..53a7fdf9befd938a3d947dfd1c0ec3c3f084311d 100644 (file)
@@ -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;
index 3ebbee9108cb9679913dd9d0363ef5748e9e7631..f8df77f79cfa937b612f66dc58ec2d636d951433 100644 (file)
@@ -130,7 +130,8 @@ struct ABMWithState
        float timer;
 
        ABMWithState(ActiveBlockModifier *abm_):
-               abm(abm_)
+               abm(abm_),
+               timer(0)
        {}
 };