diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-12-02 16:34:51 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-12-02 16:36:14 +0100 |
commit | e903323165daa65a5d646f0c061de9d60177b88a (patch) | |
tree | b52d4794dfac358bcdfa895d68cfffc68e141dc4 | |
parent | 472560d73f947309000c50e9c562a8ab7bb13d25 (diff) | |
download | crawl-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.
-rw-r--r-- | crawl-ref/source/effects.cc | 28 | ||||
-rw-r--r-- | crawl-ref/source/effects.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/main.cc | 22 | ||||
-rw-r--r-- | crawl-ref/source/player.cc | 1 | ||||
-rw-r--r-- | crawl-ref/source/player.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/tags.cc | 4 | ||||
-rw-r--r-- | crawl-ref/source/tags.h | 3 |
7 files changed, 30 insertions, 32 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; diff --git a/crawl-ref/source/effects.h b/crawl-ref/source/effects.h index 0b71717f3c..c430e17be2 100644 --- a/crawl-ref/source/effects.h +++ b/crawl-ref/source/effects.h @@ -95,6 +95,6 @@ bool forget_inventory(bool quiet = false); bool vitrify_area(int radius); void update_corpses(double elapsedTime); void update_level(double elapsedTime); -void handle_time(long time_delta); +void handle_time(); #endif diff --git a/crawl-ref/source/main.cc b/crawl-ref/source/main.cc index 805cd2b9a3..e37d27f76b 100644 --- a/crawl-ref/source/main.cc +++ b/crawl-ref/source/main.cc @@ -2870,27 +2870,7 @@ void world_reacts() you.elapsed_time += you.time_taken; - if (you.synch_time <= you.time_taken) - { - handle_time(200 + (you.time_taken - you.synch_time)); - you.synch_time = 200; - _check_banished(); - } - else - { - const long old_synch_time = you.synch_time; - you.synch_time -= you.time_taken; - - // Call spawn_random_monsters() more often than the rest of - // handle_time() so the spawning rates work out correctly. - if (old_synch_time >= 150 && you.synch_time < 150 - || old_synch_time >= 100 && you.synch_time < 100 - || old_synch_time >= 50 && you.synch_time < 50) - { - spawn_random_monsters(); - } - } - + handle_time(); manage_clouds(); if (you.duration[DUR_FIRE_SHIELD] > 0) diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index a83fffad66..ab351092fe 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -5350,7 +5350,6 @@ void player::init() elapsed_time = 0; rotting = 0; unrand_reacts = 0; - synch_time = 0; magic_contamination = 0; diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h index 9b2960a644..8acd5577fb 100644 --- a/crawl-ref/source/player.h +++ b/crawl-ref/source/player.h @@ -58,8 +58,6 @@ public: double elapsed_time; // total amount of elapsed time in the game // This is NOT a fraction; double is merely used as a portable long long here - unsigned char synch_time; // amount to wait before calling handle_time() - int disease; char max_level; diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 5b04041c53..79af67c505 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -965,7 +965,6 @@ static void tag_construct_you(writer &th) marshallString(th, you.level_type_ext); marshallByte(th, you.entry_cause); marshallByte(th, you.entry_cause_god); - marshallByte(th, you.synch_time); marshallLong(th, you.disease); marshallByte(th, you.species); @@ -1389,7 +1388,8 @@ static void tag_read_you(reader &th, char minorVersion) you.entry_cause = static_cast<entry_cause_type>( unmarshallByte(th) ); you.entry_cause_god = static_cast<god_type>( unmarshallByte(th) ); - you.synch_time = unmarshallByte(th); + if (minorVersion < TAG_MINOR_SYNCH_TIME) + unmarshallByte(th); if (minorVersion >= TAG_MINOR_DISEASE) you.disease = unmarshallLong(th); else diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h index 1583d68bf2..e3ec18f659 100644 --- a/crawl-ref/source/tags.h +++ b/crawl-ref/source/tags.h @@ -50,7 +50,8 @@ enum tag_minor_version TAG_MINOR_DISEASE = 1, // you.disease changed to an integer TAG_MINOR_MAPCELL_NOCOLOUR = 2, // map_cell::colour removed TAG_MINOR_SHOWTYPE_EXTENDED = 3, // map_cell::object stores more data - TAG_MINOR_VERSION = 3 // Current version. (Keep equal to max.) + TAG_MINOR_SYNCH_TIME = 4, // player::synch_time removed + TAG_MINOR_VERSION = 4 // Current version. (Keep equal to max.) }; struct enum_info |