From 7d317e6fc0e6847a95d0c59888400f135af66cd7 Mon Sep 17 00:00:00 2001 From: haranp Date: Wed, 21 Jan 2009 11:04:32 +0000 Subject: Remove a few more unnecessary casts. Don't cheat on constness in _mons_has_path_to_player. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8651 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/externs.h | 2 +- crawl-ref/source/misc.cc | 6 ++---- crawl-ref/source/mon-util.cc | 6 ++---- crawl-ref/source/monplace.cc | 4 ++-- crawl-ref/source/monplace.h | 4 ++-- crawl-ref/source/monstuff.cc | 2 +- crawl-ref/source/spl-cast.cc | 4 ++-- 7 files changed, 12 insertions(+), 16 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 42d6024864..6b3eb875e2 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1257,7 +1257,7 @@ public: coord_def target; coord_def patrol_point; - montravel_target_type travel_target; + mutable montravel_target_type travel_target; std::vector travel_path; FixedVector inv; monster_spells spells; diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index e6c4b3d427..70f14eb31b 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -2553,8 +2553,6 @@ bool go_berserk(bool intentional) // assumed that this is the case. static bool _mons_has_path_to_player(const monsters *mon) { - int m = monster_index(mon); - // Don't consider sleeping monsters safe, in case the player would // rather retreat and try another path for maximum stabbing chances. if (mons_is_sleeping(mon)) @@ -2575,11 +2573,11 @@ static bool _mons_has_path_to_player(const monsters *mon) if (range > 0) mp.set_range(range); - if (mp.init_pathfind(&menv[m], you.pos(), true, false, true)) + if (mp.init_pathfind(mon, you.pos(), true, false, true)) return (true); // Now we know the monster cannot possibly reach the player. - menv[m].travel_target = MTRAV_KNOWN_UNREACHABLE; + mon->travel_target = MTRAV_KNOWN_UNREACHABLE; return (false); } diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index b2288a2549..c916a4c5fb 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -3389,7 +3389,7 @@ bool monster_senior(const monsters *m1, const monsters *m2) monsters::monsters() : type(-1), hit_points(0), max_hit_points(0), hit_dice(0), ac(0), ev(0), speed(0), speed_increment(0), - target(0,0), patrol_point(0, 0), travel_target(MTRAV_NONE), + target(), patrol_point(), travel_target(MTRAV_NONE), inv(NON_ITEM), spells(), attitude(ATT_HOSTILE), behaviour(BEH_WANDER), foe(MHITYOU), enchantments(), flags(0L), experience(0), number(0), colour(BLACK), foe_memory(0), shield_blocks(0), god(GOD_NO_GOD), ghost(), @@ -7543,9 +7543,7 @@ bool monsters::can_see(const actor *targ) const if (targ->atype() == ACT_PLAYER) return mons_near(this); - const monsters* mon = dynamic_cast(targ); - - return mon_see_grid(mon->pos()); + return mon_see_grid(targ->pos()); } bool monsters::can_mutate() const diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index 81cc98817b..aee447406d 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -2716,8 +2716,8 @@ coord_def monster_pathfind::next_pos(const coord_def &c) const // The main method in the monster_pathfind class. // Returns true if a path was found, else false. -bool monster_pathfind::init_pathfind(monsters *mon, coord_def dest, bool diag, - bool msg, bool pass_unmapped) +bool monster_pathfind::init_pathfind(const monsters *mon, coord_def dest, + bool diag, bool msg, bool pass_unmapped) { mons = mon; diff --git a/crawl-ref/source/monplace.h b/crawl-ref/source/monplace.h index b92ae4bd60..093c714576 100644 --- a/crawl-ref/source/monplace.h +++ b/crawl-ref/source/monplace.h @@ -343,7 +343,7 @@ public: // public methods void set_range(int r); coord_def next_pos(const coord_def &p) const; - bool init_pathfind(monsters *mon, coord_def dest, + bool init_pathfind(const monsters *mon, coord_def dest, bool diag = true, bool msg = false, bool pass_unmapped = false); bool init_pathfind(coord_def src, coord_def dest, @@ -366,7 +366,7 @@ protected: // The monster trying to find a path. - monsters *mons; + const monsters *mons; // Our destination, and the current position we're looking at. coord_def start, target, pos; diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 68bdeb1ddb..2f8e567d5c 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -1567,7 +1567,7 @@ int monster_die(monsters *monster, killer_type killer, in_transit = true; monster->destroy_inventory(); // Make monster stop patrolling and/or travelling. - monster->patrol_point = coord_def(0, 0); + monster->patrol_point.reset(); monster->travel_path.clear(); monster->travel_target = MTRAV_NONE; break; diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 1ef96a73d8..5a9ab56145 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -2335,7 +2335,7 @@ void MiscastEffect::init() if (target->atype() == ACT_MONSTER) { mon_target = dynamic_cast(target); - target_known = you.can_see(mon_target); + target_known = you.can_see(target); } else target_known = true; @@ -2346,7 +2346,7 @@ void MiscastEffect::init() if (target->atype() == ACT_MONSTER) { mon_source = dynamic_cast(target); - kill_source = monster_index(mon_source); + kill_source = target->mindex(); } else kill_source = NON_MONSTER; -- cgit v1.2.3-54-g00ecf