trap handling.
Changes:
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2831 c06c8d41-db1a-0410-9941-cceddc491573
NW6P7VRKBFBQ2FRDZBXN7APJZPYC4SYCIA3MOOE2KZGX43IXNK2AC
PM65H4V4GNPVIJFUQW57DC3VDB7TRUUNXKVZONQKEFZSK3AXX5GQC
NNG27Y5ZQAZX6UD7F7M4F6KEZBEDFXPEEC3LFUSX4ESKT7K6UJQAC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
T2AYVN57EFJQLFUFLAZDXKDAFDGTDLQIEQWQZNYFWJZBYSTYH4QQC
SJDOBXECX7F3ZPPVR7FPURE53D47PP2TFIF4SB6XPS456PZV3DQAC
AVCMVFA3MKCXHO6H44UK5KJNIHTGQV7UA7GYXM26VI6TXXU5ZN6QC
// returns true for monsters that obviously (to the player) feel
// "thematically at home" in a branch
// currently used for native monsters recognizing traps
static bool is_native_in_branch(const monsters *monster, const branch_type branch)
{
switch (branch)
{
case BRANCH_ELVEN_HALLS:
if (mons_species(monster->type) == MONS_ELF)
return true;
return false;
case BRANCH_ORCISH_MINES:
if (mons_species(monster->type) == MONS_ORC)
return true;
return false;
case BRANCH_SLIME_PITS:
if (mons_species(monster->type) == MONS_JELLY)
return true;
return false;
case BRANCH_SNAKE_PIT:
if (mons_species(monster->type) == MONS_NAGA
|| mons_species(monster->type) == MONS_SNAKE)
{
return true;
}
return false;
case BRANCH_HALL_OF_ZOT:
if (mons_species(monster->type) == MONS_DRACONIAN)
return true;
return false;
case BRANCH_TOMB:
if (mons_species(monster->type) == MONS_MUMMY)
return true;
return false;
case BRANCH_HIVE:
if (monster->type == MONS_KILLER_BEE
|| monster->type == MONS_KILLER_BEE_LARVA)
{
return true;
}
return false;
case BRANCH_HALL_OF_BLADES:
if (monster->type == MONS_DANCING_WEAPON)
return true;
return false;
default:
return false;
}
}
// randomize potential damage
static int estimated_trap_damage(trap_type trap)
{
switch (trap)
{
case TRAP_BLADE:
return (10 + random2(30));
case TRAP_DART:
return (random2(4));
case TRAP_ARROW:
return (random2(7));
case TRAP_SPEAR:
return (random2(10));
case TRAP_BOLT:
return (random2(13));
case TRAP_AXE:
return (random2(15));
default:
return (0);
}
}
// permanent intelligent friendlies will try to avoid traps
// the player knows about (we're assuming s/he warned them about them)
if (grd[trap_x][trap_y] != DNGN_UNDISCOVERED_TRAP
&& trap_category(trap.type) != DNGN_TRAP_MAGICAL // magic doesn't matter
&& intelligent_ally(monster))
// Monsters are not afraid of non-mechanical traps. XXX: If we add
// any non-mechanical traps that can damage monsters, must add
// check here.
const bool mechanical = trap_category(trap.type) == DNGN_TRAP_MECHANICAL;
const bool player_knows_trap = (grd[trap_x][trap_y] != DNGN_UNDISCOVERED_TRAP);
// Smarter trap handling for intelligent monsters
// * monsters native to a branch can be assumed to know the trap
// locations and thus be able to avoid them
// * permanent friendlies can be assumed to have been warned by the
// player about all traps s/he knows about
// * very intelligent monsters can be assumed to have a high T&D skill
// (or have memorized part of the dungeon layout ;) )
if (intel >= I_NORMAL && mechanical
&& (is_native_in_branch(monster, you.where_are_you)
|| monster->attitude == ATT_FRIENDLY
&& player_knows_trap
|| intel >= I_HIGH && one_chance_in(3)))
// Healthy monsters don't mind a little pain. XXX: Smart humanoids
// with low hp should probably not try to go through high-damage
// traps.
if (monster->hit_points >= monster->max_hit_points / 2)
// Healthy monsters don't mind a little pain.
if (mechanical && monster->hit_points >= monster->max_hit_points / 2
&& (intel == I_ANIMAL
|| monster->hit_points > estimated_trap_damage(trap.type)))
{