summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/effects.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-12-02 16:34:51 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-12-02 16:36:14 +0100
commite903323165daa65a5d646f0c061de9d60177b88a (patch)
treeb52d4794dfac358bcdfa895d68cfffc68e141dc4 /crawl-ref/source/effects.cc
parent472560d73f947309000c50e9c562a8ab7bb13d25 (diff)
downloadcrawl-ref-e903323165daa65a5d646f0c061de9d60177b88a.tar.gz
crawl-ref-e903323165daa65a5d646f0c061de9d60177b88a.zip
Get rid of you.synch_time.
Also, the check for whether to do the corresponding effects has been moved into effects.cc:handle_time.
Diffstat (limited to 'crawl-ref/source/effects.cc')
-rw-r--r--crawl-ref/source/effects.cc28
1 files changed, 24 insertions, 4 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index c8d7f6545a..ce7f664cea 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -3674,16 +3674,36 @@ static void _rot_inventory_food(long time_delta)
}
}
+// Get around C++ dividing integers towards 0.
+static int _div(int num, int denom)
+{
+ div_t res = div(num, denom);
+ return (res.rem >= 0 ? res.quot : res.quot - 1);
+}
+
// Do various time related actions...
-// This function is called about every 20 turns.
-void handle_time(long time_delta)
+void handle_time()
{
+ int base_time = static_cast<int>(fmod(you.elapsed_time, 200));
+ int old_time = base_time - you.time_taken;
+
+ // The checks below assume the function is called at least
+ // once every 50 elapsed time units.
+
+ // Every 5 turns, spawn random monsters.
+ if (_div(base_time, 50) > _div(old_time, 50))
+ spawn_random_monsters();
+
+ // Every 20 turns, a variety of other effects.
+ if (! (_div(base_time, 200) > _div(old_time, 200)))
+ return;
+
+ int time_delta = 200;
+
// Update all of the corpses, food chunks, and potions of blood on
// the floor.
update_corpses(time_delta);
- spawn_random_monsters();
-
if (crawl_state.arena)
return;