diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-27 01:47:55 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-27 02:32:58 +0100 |
commit | 4c82c5be80278e2dee3bfc8bb1ca69724365fda5 (patch) | |
tree | 846c39495add6ad718f619a21901037bca595caa | |
parent | 928479a2ce6674d27d6ef03d7a06f81803ccdfae (diff) | |
download | crawl-ref-4c82c5be80278e2dee3bfc8bb1ca69724365fda5.tar.gz crawl-ref-4c82c5be80278e2dee3bfc8bb1ca69724365fda5.zip |
Move autoexclude code from misc.cc to exclude.cc.
-rw-r--r-- | crawl-ref/source/delay.cc | 1 | ||||
-rw-r--r-- | crawl-ref/source/exclude.cc | 77 | ||||
-rw-r--r-- | crawl-ref/source/exclude.h | 9 | ||||
-rw-r--r-- | crawl-ref/source/makefile.obj | 1 | ||||
-rw-r--r-- | crawl-ref/source/misc.cc | 60 | ||||
-rw-r--r-- | crawl-ref/source/misc.h | 3 | ||||
-rw-r--r-- | crawl-ref/source/monstuff.cc | 1 |
7 files changed, 89 insertions, 63 deletions
diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index 8e19ddbeb5..8899683e69 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -18,6 +18,7 @@ #include "delay.h" #include "describe.h" #include "enum.h" +#include "exclude.h" #include "food.h" #include "invent.h" #include "items.h" diff --git a/crawl-ref/source/exclude.cc b/crawl-ref/source/exclude.cc new file mode 100644 index 0000000000..669b7c47e7 --- /dev/null +++ b/crawl-ref/source/exclude.cc @@ -0,0 +1,77 @@ +/* + * File: exclude.cc + * Summary: Code related to travel exclusions. + */ + +#include "AppHdr.h" + +#include "exclude.h" + +#include "mon-util.h" +#include "stuff.h" +#include "travel.h" +#include "tutorial.h" + +// TODO: move other exclusion code here. + +static bool _mon_needs_auto_exclude(const monsters *mon, bool sleepy = false) +{ + if (mons_is_stationary(mon)) + { + if (sleepy) + return (false); + + // Don't give away mimics unless already known. + return (!mons_is_mimic(mon->type) + || testbits(mon->flags, MF_KNOWN_MIMIC)); + } + // Auto exclusion only makes sense if the monster is still asleep. + return (mons_is_sleeping(mon)); +} + +// Check whether a given monster is listed in the auto_exclude option. +bool need_auto_exclude(const monsters *mon, bool sleepy) +{ + // This only works if the name is lowercased. + std::string name = mon->name(DESC_BASENAME); + lowercase(name); + + for (unsigned i = 0; i < Options.auto_exclude.size(); ++i) + if (Options.auto_exclude[i].matches(name) + && _mon_needs_auto_exclude(mon, sleepy) + && mon->attitude == ATT_HOSTILE) + { + return (true); + } + + return (false); +} + +// If the monster is in the auto_exclude list, automatically set an +// exclusion. +void set_auto_exclude(const monsters *mon) +{ + if (need_auto_exclude(mon) && !is_exclude_root(mon->pos())) + { + set_exclude(mon->pos(), LOS_RADIUS, true); +#ifdef USE_TILE + viewwindow(true, false); +#endif + learned_something_new(TUT_AUTO_EXCLUSION, mon->pos()); + } +} + +// Clear auto exclusion if the monster is killed or wakes up with the +// player in sight. If sleepy is true, stationary monsters are ignored. +void remove_auto_exclude(const monsters *mon, bool sleepy) +{ + if (need_auto_exclude(mon, sleepy)) + { + del_exclude(mon->pos()); +#ifdef USE_TILE + viewwindow(true, false); +#endif + } +} + + diff --git a/crawl-ref/source/exclude.h b/crawl-ref/source/exclude.h new file mode 100644 index 0000000000..77b1244a9e --- /dev/null +++ b/crawl-ref/source/exclude.h @@ -0,0 +1,9 @@ +#ifndef EXCLUDE_H +#define EXCLUDE_H + +bool need_auto_exclude(const monsters *mon, bool sleepy = false); +void set_auto_exclude(const monsters *mon); +void remove_auto_exclude(const monsters *mon, bool sleepy = false); + +#endif + diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj index 85dbfd2b56..c12565a64b 100644 --- a/crawl-ref/source/makefile.obj +++ b/crawl-ref/source/makefile.obj @@ -25,6 +25,7 @@ directn.o \ dlua.o \ dungeon.o \ effects.o \ +exclude.o \ fight.o \ files.o \ food.o \ diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 5c65a8e799..03ff51dbb2 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -2741,66 +2741,6 @@ bool mons_is_safe(const monsters *mon, bool want_move, return (is_safe); } -static bool _mon_needs_auto_exclude(const monsters *mon, bool sleepy = false) -{ - if (mons_is_stationary(mon)) - { - if (sleepy) - return (false); - - // Don't give away mimics unless already known. - return (!mons_is_mimic(mon->type) - || testbits(mon->flags, MF_KNOWN_MIMIC)); - } - // Auto exclusion only makes sense if the monster is still asleep. - return (mons_is_sleeping(mon)); -} - -// Check whether a given monster is listed in the auto_exclude option. -bool need_auto_exclude(const monsters *mon, bool sleepy) -{ - // This only works if the name is lowercased. - std::string name = mon->name(DESC_BASENAME); - lowercase(name); - - for (unsigned i = 0; i < Options.auto_exclude.size(); ++i) - if (Options.auto_exclude[i].matches(name) - && _mon_needs_auto_exclude(mon, sleepy) - && mon->attitude == ATT_HOSTILE) - { - return (true); - } - - return (false); -} - -// If the monster is in the auto_exclude list, automatically set an -// exclusion. -void set_auto_exclude(const monsters *mon) -{ - if (need_auto_exclude(mon) && !is_exclude_root(mon->pos())) - { - set_exclude(mon->pos(), true); -#ifdef USE_TILE - viewwindow(true, false); -#endif - learned_something_new(TUT_AUTO_EXCLUSION, mon->pos()); - } -} - -// Clear auto exclusion if the monster is killed or wakes up with the -// player in sight. If sleepy is true, stationary monsters are ignored. -void remove_auto_exclude(const monsters *mon, bool sleepy) -{ - if (need_auto_exclude(mon, sleepy)) - { - del_exclude(mon->pos()); -#ifdef USE_TILE - viewwindow(true, false); -#endif - } -} - // Return all nearby monsters in range (default: LOS) that the player // is able to recognise as being monsters (i.e. no unknown mimics or // submerged creatures.) diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h index c6efd53cd2..737db0f517 100644 --- a/crawl-ref/source/misc.h +++ b/crawl-ref/source/misc.h @@ -69,9 +69,6 @@ std::string weird_sound(); bool mons_is_safe(const monsters *mon, bool want_move = false, bool consider_user_options = true); -bool need_auto_exclude(const monsters *mon, bool sleepy = false); -void set_auto_exclude(const monsters *mon); -void remove_auto_exclude(const monsters *mon, bool sleepy = false); std::vector<monsters*> get_nearby_monsters(bool want_move = false, bool just_check = false, diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 5db6f375b4..b74e0f0a71 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -27,6 +27,7 @@ #include "delay.h" #include "describe.h" #include "dgnevent.h" +#include "exclude.h" #include "fight.h" #include "files.h" #include "ghost.h" |