summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-02-15 17:01:48 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-02-15 17:01:48 +0000
commita5f8b4aaccf99929024188fb2253f1fa2b6b3f44 (patch)
tree5b9f5df4951f2217c6367cdbd0e723dc97674d21
parentcf4b68bb3c2e5d1955d41fff7284a7d56a484b3f (diff)
downloadcrawl-ref-a5f8b4aaccf99929024188fb2253f1fa2b6b3f44.tar.gz
crawl-ref-a5f8b4aaccf99929024188fb2253f1fa2b6b3f44.zip
Lots more cleanups.
Remove the sound-strength #defines because they're not used anymore (except for SL_SPLASH, which has been replaced by its value.) Change some #defines to const variables. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9087 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/chardump.cc5
-rw-r--r--crawl-ref/source/defines.h79
-rw-r--r--crawl-ref/source/it_use3.cc9
-rw-r--r--crawl-ref/source/item_use.cc143
-rw-r--r--crawl-ref/source/itemprop.cc2
-rw-r--r--crawl-ref/source/mon-util.cc2
-rw-r--r--crawl-ref/source/monplace.cc27
-rw-r--r--crawl-ref/source/monstuff.cc81
-rw-r--r--crawl-ref/source/mstuff2.cc44
-rw-r--r--crawl-ref/source/player.cc2
-rw-r--r--crawl-ref/source/religion.cc5
-rw-r--r--crawl-ref/source/skills.cc9
-rw-r--r--crawl-ref/source/spells3.cc2
-rw-r--r--crawl-ref/source/spells4.cc39
-rw-r--r--crawl-ref/source/terrain.cc4
15 files changed, 197 insertions, 256 deletions
diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc
index 579069cd04..20f0e392e3 100644
--- a/crawl-ref/source/chardump.cc
+++ b/crawl-ref/source/chardump.cc
@@ -1051,9 +1051,8 @@ static std::string _sdump_kills_place_info(PlaceInfo place_info,
f = TO_PERCENT(place_info.mon_kill_exp_avail,
you.global_info.mon_kill_exp_avail);
- g = (float) MAXIMUM(place_info.mon_kill_exp,
- place_info.mon_kill_exp_avail) /
- (float) place_info.levels_seen;
+ g = std::max<float>(place_info.mon_kill_exp, place_info.mon_kill_exp_avail)
+ / place_info.levels_seen;
out =
make_stringf("%14s | %5.1f | %5.1f | %5.1f | %5.1f | %5.1f |"
diff --git a/crawl-ref/source/defines.h b/crawl-ref/source/defines.h
index 8b1d09cb80..198603d682 100644
--- a/crawl-ref/source/defines.h
+++ b/crawl-ref/source/defines.h
@@ -37,10 +37,10 @@
#define ENDOFPACK 52
// minimum value for strength required on armour and weapons
-#define STR_REQ_THRESHOLD 10
+const int STR_REQ_THRESHOLD = 10;
// Max ghosts on a level.
-#define MAX_GHOSTS 10
+const int MAX_GHOSTS = 10;
// max size of monter array {dlb}:
#define MAX_MONSTERS 350
@@ -72,7 +72,7 @@
// max y-bound for level generation {dlb}
#define GYM 70
-#define INFINITE_DISTANCE 30000
+const int INFINITE_DISTANCE = 30000;
// this is the size of the border around the playing area (see in_bounds())
#define BOUNDARY_BORDER 1
@@ -112,7 +112,7 @@ const int LABYRINTH_BORDER = 4;
#define ENV_SHOW_OFFSET (LOS_RADIUS + 1)
#define ENV_SHOW_DIAMETER (ENV_SHOW_OFFSET * 2 + 1)
-#define VIEW_BASE_WIDTH 33
+#define VIEW_BASE_WIDTH 33 // FIXME: never used
#define VIEW_MIN_WIDTH 17
#define VIEW_MIN_HEIGHT 17
#define MSG_MIN_HEIGHT 7
@@ -127,81 +127,46 @@ const int LABYRINTH_BORDER = 4;
#define MAX_RANDOM_SHOPS 5
// Can be passed to monster_die to indicate that a friendly did the killing.
-#define ANON_FRIENDLY_MONSTER -1999
+const int ANON_FRIENDLY_MONSTER = -1999;
// This value is used to make test_hit checks always succeed
#define AUTOMATIC_HIT 1500
// Yes, I know we have 32-bit ints now.
-#define DEBUG_COOKIE 32767
+const int DEBUG_COOKIE = 32767;
-#define MAX_SKILL_LEVEL 27
+const int MAX_SKILL_LEVEL = 27;
-#define MIN_HIT_MISS_PERCENTAGE 5
+const int MIN_HIT_MISS_PERCENTAGE = 5;
// grids that monsters can see
-#define MONSTER_LOS_RANGE 8
+const int MONSTER_LOS_RANGE = 8;
// Maximum charge level for rods
-#define MAX_ROD_CHARGE 17
-#define ROD_CHARGE_MULT 100
+const int MAX_ROD_CHARGE = 17;
+const int ROD_CHARGE_MULT = 100;
-// Should never exceed 255 - durations are saved as single bytes.
-#define GOURMAND_MAX 200
-#define GOURMAND_NUTRITION_BASE 10
+const int GOURMAND_MAX = 200;
+const int GOURMAND_NUTRITION_BASE = 10;
-#define CHUNK_BASE_NUTRITION 1000
+const int CHUNK_BASE_NUTRITION = 1000;
// The maximum number of abilities any god can have
#define MAX_GOD_ABILITIES 5
// This value is used to mark immune levels of MR
-#define MAG_IMMUNE 5000
+const int MAG_IMMUNE = 5000;
// This is the damage amount used to signal insta-death
-#define INSTANT_DEATH -9999
-
-// grids that monsters can see
-#define MONSTER_LOS_RANGE 8
-
-// most items allowed in a shop
-#define MAX_SHOP_ITEMS 16
-
-// sound level standards
-// mininum is the base, we add mult * radius to it:
-#define SL_EXPLODE_MIN 10
-#define SL_EXPLODE_MULT 10
-
-// #define SL_BOW 3
-#define SL_TRAP_CLICK 3
-#define SL_HISS 6
-#define SL_BUZZ 6
-#define SL_GROWL 8
-#define SL_MOAN 8
-#define SL_SPLASH 8
-#define SL_CREAK 8
-#define SL_CROAK 8
-#define SL_BARK 10
-#define SL_YELL 10
-#define SL_TRAP_JAM 12
-#define SL_SHRIEK 12
-#define SL_ROAR 15
-#define SL_DIG 15
-#define SL_NOISY_WEAPON 20
-#define SL_HORN 25
-#define SL_NOISE_SCROLL 30
-#define SL_THUNDER 30
-#define SL_PROJECTED_NOISE 30
-#define SL_EARTHQUAKE 30
-#define SL_TRAP_ZOT 30
+const int INSTANT_DEATH = -9999;
// Maximum enchantment on weapons/armour/secondary armours
// This is the same as for ammunition.
-#define MAX_WPN_ENCHANT 9
+const int MAX_WPN_ENCHANT = 9;
// Note: use armour_max_enchant(item) to get the correct limit for item
-#define MAX_ARM_ENCHANT 8
-#define MAX_SEC_ENCHANT 2
+const int MAX_ARM_ENCHANT = 8;
+const int MAX_SEC_ENCHANT = 2;
// some shortcuts:
#define menv env.mons
@@ -282,9 +247,6 @@ const int LABYRINTH_BORDER = 4;
#define PCOLOUR(desc) ((desc) % PDC_NCOLOURS)
#define PQUAL(desc) ((desc) / PDC_NCOLOURS)
-#define MINIMUM( xxx, yyy ) (((xxx) < (yyy)) ? (xxx) : (yyy))
-#define MAXIMUM( xxx, yyy ) (((xxx) > (yyy)) ? (xxx) : (yyy))
-
// Convert capital letters into mystic numbers representing
// CTRL sequences. This is a macro because a lot of the type
// it wants to be used in case labels.
@@ -293,9 +255,6 @@ const int LABYRINTH_BORDER = 4;
#define ARRAYSZ(x) (sizeof(x) / sizeof(x[0]))
#define RANDOM_ELEMENT(x) (x[random2(ARRAYSZ(x))])
-#define MIN(x, y) MINIMUM(x, y)
-#define MAX(x,y) (((x) > (y)) ? (x) : (y))
-
const char * const MONSTER_NUMBER = "monster-number";
// Synthetic keys:
diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc
index 21e50531bc..1a1c7b03da 100644
--- a/crawl-ref/source/it_use3.cc
+++ b/crawl-ref/source/it_use3.cc
@@ -295,14 +295,17 @@ static bool _reaching_weapon_attack(const item_def& wpn)
// If we're attacking more than a space away...
if (x_distance > 1 || y_distance > 1)
{
- const int x_middle = MAX(beam.target.x, you.pos().x) - (x_distance / 2);
- const int y_middle = MAX(beam.target.y, you.pos().y) - (y_distance / 2);
+ const int x_middle = std::max(beam.target.x, you.pos().x)
+ - (x_distance / 2);
+ const int y_middle = std::max(beam.target.y, you.pos().y)
+ - (y_distance / 2);
+ const coord_def middle(x_middle, y_middle);
bool success = false;
// If either the x or the y is the same, we should check for
// a monster:
if ((beam.target.x == you.pos().x || beam.target.y == you.pos().y)
- && mgrd[x_middle][y_middle] != NON_MONSTER)
+ && monster_at(middle))
{
const int skill = weapon_skill( wpn.base_type, wpn.sub_type );
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 828be5b480..8e3e804e98 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -3452,10 +3452,13 @@ static bool _swap_rings(int ring_slot)
bool puton_item(int item_slot, bool prompt_finger)
{
+ item_def& item = you.inv[item_slot];
+
if (item_slot == you.equip[EQ_LEFT_RING]
|| item_slot == you.equip[EQ_RIGHT_RING]
|| item_slot == you.equip[EQ_AMULET])
{
+ // "Putting on" an equipped item means taking it off.
return (!remove_ring(item_slot));
}
@@ -3465,87 +3468,88 @@ bool puton_item(int item_slot, bool prompt_finger)
return (false);
}
- if (you.inv[item_slot].base_type != OBJ_JEWELLERY)
+ if (item.base_type != OBJ_JEWELLERY)
{
mpr("You can only put on jewellery.");
return (false);
}
- const bool is_amulet = jewellery_is_amulet( you.inv[item_slot] );
+ const bool lring = (you.slot_item(EQ_LEFT_RING) != NULL);
+ const bool rring = (you.slot_item(EQ_RIGHT_RING) != NULL);
+ const bool is_amulet = jewellery_is_amulet(item);
- if (!is_amulet) // ie it's a ring
+ if (!is_amulet) // i.e. it's a ring
{
- if (you.equip[EQ_GLOVES] != -1
- && item_cursed( you.inv[you.equip[EQ_GLOVES]] ))
+ const item_def* gloves = you.slot_item(EQ_GLOVES);
+ if (gloves && item_cursed(*gloves))
{
mpr("You can't take your gloves off to put on a ring!");
return (false);
}
- if (you.equip[EQ_LEFT_RING] != -1
- && you.equip[EQ_RIGHT_RING] != -1)
- {
+ if (lring && rring)
return _swap_rings(item_slot);
- }
}
- else if (you.equip[EQ_AMULET] != -1)
+ else if (item_def* amulet = you.slot_item(EQ_AMULET))
{
- if (!check_warning_inscriptions(you.inv[you.equip[EQ_AMULET]],
- OPER_REMOVE)
- || !remove_ring( you.equip[EQ_AMULET], true ))
+ // Remove the previous one.
+ if (!check_warning_inscriptions(*amulet, OPER_REMOVE)
+ || !remove_ring(you.equip[EQ_AMULET], true))
{
return (false);
}
- // Put on the new amulet.
- if (!safe_to_remove_or_wear(you.inv[item_slot], false))
+ // Check that the new amulet won't kill us.
+ if (!safe_to_remove_or_wear(item, false))
return (false);
+ // Put on the new amulet.
start_delay(DELAY_JEWELLERY_ON, 1, item_slot);
// Assume it's going to succeed.
return (true);
}
- // Put on the amulet.
- if (!safe_to_remove_or_wear(you.inv[item_slot], false))
+ // Check that it won't kill us.
+ if (!safe_to_remove_or_wear(item, false))
return (false);
- // First ring goes on left hand if we're choosing automatically.
- int hand_used = 0;
-
- if (you.equip[EQ_LEFT_RING] != -1)
- hand_used = 1;
-
- if (you.equip[EQ_RIGHT_RING] != -1)
- hand_used = 0;
+ equipment_type hand_used;
if (is_amulet)
- hand_used = 2;
- else if (prompt_finger
- && you.equip[EQ_LEFT_RING] == -1
- && you.equip[EQ_RIGHT_RING] == -1)
{
- mpr("Put on which hand (l or r)?", MSGCH_PROMPT);
-
- int keyin = get_ch();
+ hand_used = EQ_AMULET;
+ }
+ else
+ {
+ // First ring goes on left hand if we're choosing automatically.
+ hand_used = EQ_LEFT_RING;
- if (keyin == 'l')
- hand_used = 0;
- else if (keyin == 'r')
- hand_used = 1;
- else if (keyin == ESCAPE)
- return (false);
- else
+ if (lring && !rring)
+ hand_used = EQ_RIGHT_RING;
+ else if (rring && !lring)
+ hand_used = EQ_LEFT_RING;
+ else if (prompt_finger) // both free; both busy has been handled
{
- mpr("You don't have such a hand!");
- return (false);
+ mpr("Put on which hand (l or r)?", MSGCH_PROMPT);
+ int keyin = get_ch();
+ switch (keyin)
+ {
+ case 'l': hand_used = EQ_LEFT_RING; break;
+ case 'r': hand_used = EQ_RIGHT_RING; break;
+ case ESCAPE: return (false);
+ default:
+ mpr("You don't have such a hand!");
+ return (false);
+ }
}
}
- you.equip[ EQ_LEFT_RING + hand_used ] = item_slot;
+ // Actually equip the item.
+ you.equip[hand_used] = item_slot;
- jewellery_wear_effects( you.inv[item_slot] );
+ // And calculate the effects.
+ jewellery_wear_effects(item);
// Putting on jewellery is as fast as wielding weapons.
you.time_taken /= 2;
@@ -4042,12 +4046,10 @@ void drink(int slot)
if (slot == -1)
{
- if (grd(you.pos()) >= DNGN_FOUNTAIN_BLUE
- && grd(you.pos()) <= DNGN_FOUNTAIN_BLOOD)
- {
+ const dungeon_feature_type feat = grd(you.pos());
+ if (feat >= DNGN_FOUNTAIN_BLUE && feat <= DNGN_FOUNTAIN_BLOOD)
if (_drink_fountain())
return;
- }
}
if (inv_count() == 0)
@@ -4181,29 +4183,30 @@ bool _drink_fountain()
mpr("You drink the sparkling water.");
- const potion_type effects[] =
- { POT_WATER, POT_DECAY,
- POT_MUTATION, POT_HEALING, POT_HEAL_WOUNDS, POT_SPEED, POT_MIGHT,
- POT_DEGENERATION,
- POT_LEVITATION, POT_POISON, POT_SLOWING,
- POT_PARALYSIS, POT_CONFUSION, POT_INVISIBILITY,
- POT_MAGIC, POT_RESTORE_ABILITIES, POT_RESISTANCE,
- POT_STRONG_POISON, POT_BERSERK_RAGE,
- POT_GAIN_STRENGTH, POT_GAIN_INTELLIGENCE, POT_GAIN_DEXTERITY };
-
- const int weights[] = { 467, 48,
- 40, 40, 40, 40, 40,
- 32,
- 27, 27, 27,
- 27, 27, 27,
- 20, 20, 20,
- 20, 20,
- 4, 4, 4 };
-
- COMPILE_CHECK(ARRAYSZ(weights) == ARRAYSZ(effects), c1);
- fountain_effect =
- effects[choose_random_weighted(weights,
- weights + ARRAYSZ(weights))];
+ fountain_effect = static_cast<potion_type>(
+ random_choose_weighted(467, POT_WATER,
+ 48, POT_DECAY,
+ 40, POT_MUTATION,
+ 40, POT_HEALING,
+ 40, POT_HEAL_WOUNDS,
+ 40, POT_SPEED,
+ 40, POT_MIGHT,
+ 32, POT_DEGENERATION,
+ 27, POT_LEVITATION,
+ 27, POT_POISON,
+ 27, POT_SLOWING,
+ 27, POT_PARALYSIS,
+ 27, POT_CONFUSION,
+ 27, POT_INVISIBILITY,
+ 20, POT_MAGIC,
+ 20, POT_RESTORE_ABILITIES,
+ 20, POT_RESISTANCE,
+ 20, POT_STRONG_POISON,
+ 20, POT_BERSERK_RAGE,
+ 4, POT_GAIN_STRENGTH,
+ 4, POT_GAIN_INTELLIGENCE,
+ 4, POT_GAIN_DEXTERITY,
+ 0));
}
if (fountain_effect != POT_WATER && fountain_effect != POT_BLOOD)
diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc
index 40263e2f3b..e5107c9f1a 100644
--- a/crawl-ref/source/itemprop.cc
+++ b/crawl-ref/source/itemprop.cc
@@ -2592,7 +2592,7 @@ int item_mass( const item_def &item )
// Truncate to the nearest 5 and reduce the item mass:
unit_mass -= ((reduc / 5) * 5);
- unit_mass = MAXIMUM( unit_mass, 5 );
+ unit_mass = std::max(unit_mass, 5);
}
break;
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index ec1a0b88dd..2c1fac0b54 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -6189,7 +6189,7 @@ bool monsters::find_place_to_live(bool near_player)
if ((near_player && find_place_near_player())
|| find_home_anywhere())
{
- mgrd(pos()) = monster_index(this);
+ mgrd(pos()) = mindex();
return (true);
}
diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc
index c6866b3a7b..90f8738603 100644
--- a/crawl-ref/source/monplace.cc
+++ b/crawl-ref/source/monplace.cc
@@ -523,7 +523,7 @@ static monster_type _resolve_monster_type(monster_type mon_type,
{
pos = random_in_bounds();
- if (mgrd(pos) != NON_MONSTER || pos == you.pos())
+ if (actor_at(pos))
continue;
// Is the grid verboten?
@@ -695,7 +695,7 @@ static bool _valid_monster_location(const mgen_data &mg,
return (false);
// Occupied?
- if (mgrd(mg_pos) != NON_MONSTER || mg_pos == you.pos())
+ if (actor_at(mg_pos))
return (false);
// Is the monster happy where we want to put it?
@@ -733,7 +733,7 @@ int place_monster(mgen_data mg, bool force_pos)
int id = -1;
// (1) Early out (summoned to occupied grid).
- if (mg.use_position() && mgrd(mg.pos) != NON_MONSTER)
+ if (mg.use_position() && monster_at(mg.pos))
return (-1);
mg.cls = _resolve_monster_type(mg.cls, mg.proximity, mg.base_type,
@@ -848,6 +848,14 @@ int place_monster(mgen_data mg, bool force_pos)
proxOK = false;
break;
}
+
+ // You can't be shoved if you're caught in a net.
+ if (you.caught())
+ {
+ proxOK = false;
+ break;
+ }
+
shoved = true;
coord_def mpos = mg.pos;
mg.pos = you.pos();
@@ -983,7 +991,7 @@ static int _place_monster_aux(const mgen_data &mg,
// If the space is occupied, try some neighbouring square instead.
if (first_band_member && in_bounds(mg.pos)
&& (mg.behaviour == BEH_FRIENDLY || !is_sanctuary(mg.pos))
- && mgrd(mg.pos) == NON_MONSTER && mg.pos != you.pos()
+ && actor_at(mg.pos) == NULL
&& (force_pos || monster_habitable_grid(montype, grd(mg.pos))))
{
fpos = mg.pos;
@@ -2294,8 +2302,7 @@ public:
good_square(dc);
return (false);
}
- if (mgrd(dc) == NON_MONSTER && dc != you.pos()
- && one_chance_in(++nfound))
+ if (actor_at(dc) == NULL && one_chance_in(++nfound))
{
greedy_dist = traveled_distance;
greedy_place = dc;
@@ -2447,8 +2454,7 @@ int create_monster(mgen_data mg, bool fail_msg)
if (!mg.force_place()
|| !in_bounds(mg.pos)
- || mgrd(mg.pos) != NON_MONSTER
- || mg.pos == you.pos()
+ || actor_at(mg.pos)
|| !mons_class_can_pass(montype, grd(mg.pos)))
{
mg.pos = find_newmons_square(montype, mg.pos);
@@ -2516,10 +2522,7 @@ bool empty_surrounds(const coord_def& where, dungeon_feature_type spc_wanted,
{
bool success = false;
- if ( *ri == you.pos() )
- continue;
-
- if (mgrd(*ri) != NON_MONSTER)
+ if (actor_at(*ri))
continue;
// Players won't summon out of LOS, or past transparent walls.
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index 8d05bfda26..17253a1ca0 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -1764,15 +1764,9 @@ static bool _jelly_divide(monsters *parent)
// First, find a suitable spot for the child {dlb}:
for (adjacent_iterator ai(parent->pos()); ai; ++ai)
- {
- if (mgrd(*ai) == NON_MONSTER
- && parent->can_pass_through(*ai)
- && (*ai != you.pos()))
- {
+ if (actor_at(*ai) == NULL && parent->can_pass_through(*ai))
if ( one_chance_in(++num_spots) )
child_spot = *ai;
- }
- }
if ( num_spots == 0 )
return (false);
@@ -2257,8 +2251,7 @@ bool random_near_space(const coord_def& origin, coord_def& target,
if (!in_bounds(target)
|| restrict_LOS && !see_grid(target)
|| grd(target) < DNGN_SHALLOW_WATER
- || mgrd(target) != NON_MONSTER
- || target == you.pos()
+ || actor_at(target)
|| !allow_adjacent && distance(origin, target) <= 2
|| forbid_sanctuary && is_sanctuary(target))
{
@@ -2789,7 +2782,7 @@ static bool _choose_random_patrol_target_grid(monsters *mon)
// (and if we're not, we couldn't move anyway), and this avoids
// monsters trying to move onto a grid occupied by a plant or
// sleeping monster.
- if (mgrd(*ri) != NON_MONSTER)
+ if (monster_at(*ri))
continue;
if (patrol_seen)
@@ -2896,15 +2889,14 @@ static void _mark_neighbours_target_unreachable(monsters *mon)
if (*ri == mon->pos())
continue;
- if (mgrd(*ri) == NON_MONSTER)
- continue;
-
// Don't alert monsters out of sight (e.g. on the other side of
// a wall).
if (!mon->mon_see_grid(*ri))
continue;
- monsters* const m = &menv[mgrd(*ri)];
+ monsters* const m = monster_at(*ri);
+ if (m == NULL)
+ continue;
// Don't restrict smarter monsters as they might find a path
// a dumber monster wouldn't.
@@ -4285,17 +4277,15 @@ static bool _mons_check_set_foe(monsters *mon, const coord_def& p,
return (true);
}
- if (mgrd(p) != NON_MONSTER)
+ if (monsters *foe = monster_at(p))
{
- monsters *foe = &menv[mgrd(p)];
-
if (foe != mon
&& mon_can_see_monster(mon, foe)
&& (friendly || !is_sanctuary(p))
&& (mons_friendly(foe) != friendly
|| (neutral && !mons_neutral(foe))))
{
- mon->foe = mgrd(p);
+ mon->foe = foe->mindex();
return (true);
}
}
@@ -4366,9 +4356,8 @@ monsters *choose_random_monster_on_level(int weight,
for ( ; ri; ++ri )
{
- if (mgrd(*ri) != NON_MONSTER)
+ if (monsters *mon = monster_at(*ri))
{
- monsters *mon = &menv[mgrd(*ri)];
if (suitable(mon))
{
// FIXME: if the intent is to favour monsters
@@ -4500,21 +4489,22 @@ static bool _allied_monster_at(monsters *mon, coord_def a, coord_def b,
if (!in_bounds(pos[i]))
continue;
- if (mgrd(pos[i]) == NON_MONSTER)
+ const monsters *ally = monster_at(pos[i]);
+ if (ally == NULL)
continue;
- if (mons_is_stationary(&menv[mgrd(pos[i])]))
+ if (mons_is_stationary(ally))
continue;
// Hostile monsters of normal intelligence only move aside for
// monsters of the same type.
if (mons_intel(mon) <= I_NORMAL && !mons_wont_attack_real(mon)
- && mons_genus(mon->type) != mons_genus((&menv[mgrd(pos[i])])->type))
+ && mons_genus(mon->type) != mons_genus(ally->type))
{
continue;
}
- if (mons_aligned(monster_index(mon), mgrd(pos[i])))
+ if (mons_aligned(mon->mindex(), ally->mindex()))
return (true);
}
@@ -4535,22 +4525,25 @@ static bool _ranged_allied_monster_in_dir(monsters *mon, coord_def p)
if (!in_bounds(pos))
break;
- if (mgrd(pos) == NON_MONSTER)
+ const monsters* ally = monster_at(pos);
+ if (ally == NULL)
continue;
- if (mons_aligned(monster_index(mon), mgrd(pos)))
+ if (mons_aligned(mon->mindex(), ally->mindex()))
{
// Hostile monsters of normal intelligence only move aside for
// monsters of the same type.
if (mons_intel(mon) <= I_NORMAL && !mons_wont_attack(mon)
- && mons_genus(mon->type) != mons_genus((&menv[mgrd(pos)])->type))
+ && mons_genus(mon->type) != mons_genus(ally->type))
{
return (false);
}
- monsters *m = &menv[mgrd(pos)];
- if (mons_has_ranged_attack(m) || mons_has_ranged_spell(m, true))
+ if (mons_has_ranged_attack(ally)
+ || mons_has_ranged_spell(ally, true))
+ {
return (true);
+ }
}
break;
}
@@ -5215,10 +5208,9 @@ static bool _siren_movement_effect(const monsters *monster)
else
{
bool swapping = false;
- monsters *mon = NULL;
- if (mgrd(newpos) != NON_MONSTER)
+ monsters *mon = monster_at(newpos);
+ if (mon)
{
- mon = &menv[mgrd(newpos)];
if (mons_wont_attack(mon)
&& !mons_is_stationary(mon)
&& !mons_cannot_act(mon)
@@ -6671,11 +6663,10 @@ static bool _handle_throw(monsters *monster, bolt & beem)
// Throwing a net at a target that is already caught would be
// completely useless, so bail out.
+ const actor *act = actor_at(beem.target);
if (missile->base_type == OBJ_MISSILES
&& missile->sub_type == MI_THROWING_NET
- && ( beem.target == you.pos() && you.caught()
- || mgrd(beem.target) != NON_MONSTER
- && mons_is_caught(&menv[mgrd(beem.target)])))
+ && act && act->caught())
{
return (false);
}
@@ -7978,11 +7969,8 @@ static bool _mon_can_move_to_pos(const monsters *monster,
}
// Inside a sanctuary don't attack anything!
- if (is_sanctuary(monster->pos())
- && (targ == you.pos() || mgrd(targ) != NON_MONSTER))
- {
+ if (is_sanctuary(monster->pos()) && actor_at(targ))
return (false);
- }
const dungeon_feature_type target_grid = grd(targ);
const habitat_type habitat = mons_primary_habitat(monster);
@@ -8071,7 +8059,7 @@ static bool _mon_can_move_to_pos(const monsters *monster,
// Smacking another monster is good, if the monsters
// are aligned differently.
- if (mgrd(targ) != NON_MONSTER)
+ if (monsters *targmonster = monster_at(targ))
{
if (just_check)
{
@@ -8081,12 +8069,8 @@ static bool _mon_can_move_to_pos(const monsters *monster,
return (false); // blocks square
}
- const int thismonster = monster->mindex(),
- targmonster = mgrd(targ);
-
- if (!invalid_monster_index(targmonster)
- && mons_aligned(thismonster, targmonster)
- && !_mons_can_displace(monster, &menv[targmonster]))
+ if (mons_aligned(monster->mindex(), targmonster->mindex())
+ && !_mons_can_displace(monster, targmonster))
{
return (false);
}
@@ -8870,10 +8854,7 @@ bool shift_monster(monsters *mon, coord_def p)
if (grd(*ai) != DNGN_FLOOR)
continue;
- if (mgrd(*ai) != NON_MONSTER)
- continue;
-
- if (*ai == you.pos())
+ if (actor_at(*ai))
continue;
if (one_chance_in(++count))
diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc
index 13ba57fea6..bd39ab7f14 100644
--- a/crawl-ref/source/mstuff2.cc
+++ b/crawl-ref/source/mstuff2.cc
@@ -778,14 +778,9 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
}
else if (in_bounds(pbolt.target) && see_grid(pbolt.target))
{
- int midx = mgrd(pbolt.target);
- if (midx != NON_MONSTER)
- {
- monsters* mtarg = &menv[midx];
-
+ if (monsters* mtarg = monster_at(pbolt.target))
if (you.can_see(mtarg))
target = mtarg->name(DESC_NOCAP_THE);
- }
}
// Monster might be aiming past the real target, or maybe some fuzz has
@@ -807,13 +802,12 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
break;
}
- const int midx = mgrd(*ai);
-
- if (midx != NON_MONSTER && you.can_see(&menv[midx]))
+ const monsters *m = monster_at(*ai);
+ if (m && you.can_see(m))
{
targ_prep = "next to";
if (one_chance_in(count++))
- target = menv[midx].name(DESC_NOCAP_THE);
+ target = m->name(DESC_NOCAP_THE);
}
}
}
@@ -829,7 +823,7 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
if (pos == monster->pos())
continue;
- const int midx = mgrd(pos);
+ const monsters *m = monster_at(pos);
if (pos == you.pos())
{
// Be egotistical and assume that the monster is aiming at
@@ -852,11 +846,10 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
mons_targ_aligned = true;
}
}
- else if (visible_path && midx != NON_MONSTER
- && you.can_see(&menv[midx]))
+ else if (visible_path && m && you.can_see(m))
{
- bool is_aligned = mons_aligned(midx, monster->mindex());
- std::string name = menv[midx].name(DESC_NOCAP_THE);
+ bool is_aligned = mons_aligned(m->mindex(), monster->mindex());
+ std::string name = m->name(DESC_NOCAP_THE);
if (target == "nothing")
{
@@ -888,12 +881,12 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
break;
}
- const int midx2 = mgrd(*ai);
- if (midx2 != NON_MONSTER && you.can_see(&menv[midx2]))
+ const monsters *m2 = monster_at(*ai);
+ if (m2 && you.can_see(m2))
{
targ_prep = "past";
if (one_chance_in(count++))
- target = menv[midx2].name(DESC_NOCAP_THE);
+ target = m2->name(DESC_NOCAP_THE);
}
}
}
@@ -1089,7 +1082,7 @@ bool monster_random_space(const monsters *monster, coord_def& target,
target = random_in_bounds();
// Don't land on top of another monster.
- if (mgrd(target) != NON_MONSTER || target == you.pos())
+ if (actor_at(target))
continue;
if (is_sanctuary(target) && forbid_sanctuary)
@@ -2148,11 +2141,10 @@ static int _monster_abjure_square(const coord_def &pos,
int pow, int actual,
int wont_attack)
{
- const int mindex = mgrd(pos);
- if (mindex == NON_MONSTER)
+ monsters *target = monster_at(pos);
+ if (target == NULL)
return (0);
- monsters *target = &menv[mindex];
if (!target->alive()
|| ((bool)wont_attack == mons_wont_attack_real(target)))
{
@@ -2519,7 +2511,8 @@ bool mons_clonable(const monsters* mon, bool needs_adjacent)
{
const coord_def p = mon->pos() + Compass[i];
- if (in_bounds(p) && p != you.pos() && mgrd(p) == NON_MONSTER
+ if (in_bounds(p)
+ && !actor_at(p)
&& monster_habitable_grid(mon, grd(p)))
{
square_found = true;
@@ -2568,7 +2561,8 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious,
{
const coord_def p = orig->pos() + Compass[i];
- if (in_bounds(p) && p != you.pos() && mgrd(p) == NON_MONSTER
+ if (in_bounds(p)
+ && !actor_at(p)
&& monster_habitable_grid(orig, grd(p)))
{
if (one_chance_in(++squares))
@@ -2580,7 +2574,7 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious,
return (NON_MONSTER);
}
- ASSERT(mgrd(pos) == NON_MONSTER && you.pos() != pos);
+ ASSERT( !actor_at(pos) );
monsters &mon(menv[midx]);
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 146b32d571..08efe21cb4 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -286,7 +286,7 @@ bool move_player_to_grid( const coord_def& p, bool stepped, bool allow_shift,
else if (new_grid == DNGN_SHALLOW_WATER && !player_likes_water())
{
if (!stepped)
- noisy(SL_SPLASH, you.pos(), "Splash!");
+ noisy(8, you.pos(), "Splash!");
you.time_taken *= 13 + random2(8);
you.time_taken /= 10;
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 8987d02123..a907542e8b 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -11,6 +11,7 @@ REVISION("$Rev$");
#include "religion.h"
+#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
@@ -904,7 +905,7 @@ static void _inc_penance(god_type god, int val)
}
you.penance[god] += val;
- you.penance[god] = MIN(MAX_PENANCE, you.penance[god]);
+ you.penance[god] = std::min<unsigned char>(MAX_PENANCE, you.penance[god]);
if (god == GOD_BEOGH && _need_water_walking() && !beogh_water_walk())
fall_into_a_pool( you.pos(), true, grd(you.pos()) );
@@ -3318,7 +3319,7 @@ void gain_piety(int pgn)
int old_piety = you.piety;
you.piety += pgn;
- you.piety = MIN(MAX_PIETY, you.piety);
+ you.piety = std::min<int>(MAX_PIETY, you.piety);
for (int i = 0; i < MAX_GOD_ABILITIES; ++i)
{
diff --git a/crawl-ref/source/skills.cc b/crawl-ref/source/skills.cc
index c53e91106d..674cb0551d 100644
--- a/crawl-ref/source/skills.cc
+++ b/crawl-ref/source/skills.cc
@@ -11,6 +11,7 @@ REVISION("$Rev$");
#include "skills.h"
+#include <algorithm>
#include <string.h>
#include <stdlib.h>
@@ -285,7 +286,7 @@ static int _exercise2(int exsk)
return (0);
}
- int spending_limit = MIN(MAX_SPENDING_LIMIT, you.exp_available);
+ int spending_limit = std::min(MAX_SPENDING_LIMIT, you.exp_available);
// Handle fractional learning.
if (skill_change > spending_limit)
@@ -330,20 +331,20 @@ static int _exercise2(int exsk)
if ((exsk >= SK_FIGHTING && exsk <= SK_STAVES) || exsk == SK_ARMOUR)
{
// These skills are easier for the strong.
- skill_inc *= MAX(5, you.strength);
+ skill_inc *= std::max<int>(5, you.strength);
skill_inc /= 10;
}
else if (exsk >= SK_SLINGS && exsk <= SK_UNARMED_COMBAT)
{
// These skills are easier for the dexterous.
// Note: Armour is handled above.
- skill_inc *= MAX(5, you.dex);
+ skill_inc *= std::max<int>(5, you.dex);
skill_inc /= 10;
}
else if (exsk >= SK_SPELLCASTING && exsk <= SK_POISON_MAGIC)
{
// These skills are easier for the smart.
- skill_inc *= MAX(5, you.intel);
+ skill_inc *= std::max<int>(5, you.intel);
skill_inc /= 10;
}
}
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index 145d90aa63..9d63b3ca96 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -1104,7 +1104,7 @@ bool cast_twisted_resurrection(int pow, god_type god)
(colour == RED) ? 1000
: 2500);
- menv[monster].hit_dice = MIN(30, menv[monster].hit_dice);
+ menv[monster].hit_dice = std::min(30, menv[monster].hit_dice);
// XXX: No convenient way to get the hit dice size right now.
menv[monster].hit_points = hit_points(menv[monster].hit_dice, 2, 5);
diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc
index 5d18ebabb0..a0222a7fc1 100644
--- a/crawl-ref/source/spells4.cc
+++ b/crawl-ref/source/spells4.cc
@@ -102,15 +102,15 @@ static bool _player_hurt_monster(int monster, int damage)
static int _shatter_monsters(coord_def where, int pow, int, actor *)
{
dice_def dam_dice( 0, 5 + pow / 3 ); // number of dice set below
- const int monster = mgrd(where);
+ monsters *monster = monster_at(where);
- if (monster == NON_MONSTER)
+ if (monster == NULL)
return (0);
// Removed a lot of silly monsters down here... people, just because
// it says ice, rock, or iron in the name doesn't mean it's actually
// made out of the substance. -- bwr
- switch (menv[monster].type)
+ switch (monster->type)
{
case MONS_ICE_BEAST: // 3/2 damage
case MONS_SIMULACRUM_SMALL:
@@ -175,17 +175,17 @@ static int _shatter_monsters(coord_def where, int pow, int, actor *)
break;
default: // normal damage
- if (mons_flies( &menv[monster] ))
+ if (mons_flies(monster))
dam_dice.num = 1;
else
dam_dice.num = 3;
break;
}
- int damage = dam_dice.roll() - random2( menv[monster].ac );
+ int damage = dam_dice.roll() - random2(monster->ac);
if (damage > 0)
- _player_hurt_monster( monster, damage );
+ _player_hurt_monster(*monster, damage);
else
damage = 0;
@@ -587,7 +587,7 @@ static int _ignite_poison_monsters(coord_def where, int pow, int, actor *)
dam_dice.num, dam_dice.size, damage );
#endif
- if (!_player_hurt_monster(mon->mindex(), damage))
+ if (!_player_hurt_monster(*mon, damage))
{
// Monster survived, remove any poison.
mon->del_ench(ENCH_POISON);
@@ -1662,14 +1662,11 @@ bool cast_fragmentation(int pow, const dist& spd)
beam.damage = dice_def(0, 5 + pow / 10);
const dungeon_feature_type grid = grd(spd.target);
- const int midx = mgrd(spd.target);
- if (midx != NON_MONSTER)
+ if (monsters *mon = monster_at(spd.target))
{
- monsters *mon = &menv[midx];
-
// Save the monster's name in case it isn't available later.
- std::string name_cap_the = mon->name(DESC_CAP_THE);
+ const std::string name_cap_the = mon->name(DESC_CAP_THE);
switch (mon->type)
{
@@ -1681,7 +1678,7 @@ bool cast_fragmentation(int pow, const dist& spd)
// fizzle (since we don't actually explode wood golems). -- bwr
explode = false;
beam.damage.num = 2;
- _player_hurt_monster(midx, beam.damage.roll());
+ _player_hurt_monster(*mon, beam.damage.roll());
break;
case MONS_IRON_GOLEM:
@@ -1690,7 +1687,7 @@ bool cast_fragmentation(int pow, const dist& spd)
beam.name = "blast of metal fragments";
beam.colour = CYAN;
beam.damage.num = 4;
- if (_player_hurt_monster(midx, beam.damage.roll()))
+ if (_player_hurt_monster(*mon, beam.damage.roll()))
beam.damage.num += 2;
break;
@@ -1703,7 +1700,7 @@ bool cast_fragmentation(int pow, const dist& spd)
beam.name = "blast of rock fragments";
beam.colour = BROWN;
beam.damage.num = 3;
- if (_player_hurt_monster(midx, beam.damage.roll()))
+ if (_player_hurt_monster(*mon, beam.damage.roll()))
beam.damage.num++;
break;
@@ -1729,7 +1726,7 @@ bool cast_fragmentation(int pow, const dist& spd)
if (pow >= 50 && one_chance_in(10))
statue_damage = mon->hit_points;
- if (_player_hurt_monster(midx, statue_damage))
+ if (_player_hurt_monster(*mon, statue_damage))
beam.damage.num += 2;
}
break;
@@ -1740,7 +1737,7 @@ bool cast_fragmentation(int pow, const dist& spd)
beam.name = "blast of crystal shards";
beam.colour = WHITE;
beam.damage.num = 4;
- if (_player_hurt_monster(midx, beam.damage.roll()))
+ if (_player_hurt_monster(*mon, beam.damage.roll()))
beam.damage.num += 2;
break;
@@ -1752,7 +1749,7 @@ bool cast_fragmentation(int pow, const dist& spd)
beam.colour = WHITE;
beam.damage.num = 2;
beam.flavour = BEAM_ICE;
- if (_player_hurt_monster(midx, beam.damage.roll()))
+ if (_player_hurt_monster(*mon, beam.damage.roll()))
beam.damage.num++;
break;
}
@@ -1774,7 +1771,7 @@ bool cast_fragmentation(int pow, const dist& spd)
else
{
beam.damage.num = 2;
- if (_player_hurt_monster(midx, beam.damage.roll()))
+ if (_player_hurt_monster(*mon, beam.damage.roll()))
beam.damage.num += 2;
}
goto all_done; // i.e., no "Foo Explodes!"
@@ -1792,7 +1789,7 @@ bool cast_fragmentation(int pow, const dist& spd)
beam.name = "blast of petrified fragments";
beam.colour = mons_class_colour(mon->type);
beam.damage.num = petrifying ? 2 : 3;
- if (_player_hurt_monster(midx, beam.damage.roll()))
+ if (_player_hurt_monster(*mon, beam.damage.roll()))
beam.damage.num++;
break;
}
@@ -1803,7 +1800,7 @@ bool cast_fragmentation(int pow, const dist& spd)
// Yes, this spell does lousy damage if the monster
// isn't susceptible. -- bwr
- _player_hurt_monster(midx, roll_dice(1, 5 + pow / 25));
+ _player_hurt_monster(*mon, roll_dice(1, 5 + pow / 25));
goto do_terrain;
}
diff --git a/crawl-ref/source/terrain.cc b/crawl-ref/source/terrain.cc
index a893869834..88fa5905b2 100644
--- a/crawl-ref/source/terrain.cc
+++ b/crawl-ref/source/terrain.cc
@@ -323,8 +323,8 @@ void get_door_description(int door_size, const char** adjective, const char** no
"huge " , "gate",
};
- const unsigned int idx = MIN( (unsigned int) door_size*2,
- ARRAYSZ(descriptions) - 2 );
+ const unsigned int idx = std::min(static_cast<unsigned int>(door_size*2),
+ ARRAYSZ(descriptions) - 2);
*adjective = descriptions[idx];
*noun = descriptions[idx+1];
}