With the help of several factors (such as size, wielded weapon or stats) the game decides whether you should try to destroy the net to come free, or try to slip out of it. The same calculation also influences how long this will take.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2278 c06c8d41-db1a-0410-9941-cceddc491573
UOUDDVHCP2526KI2KRMYS5NDRG5AL3FLPSAHKTVAQOXYVI5XHSVAC
void free_self_from_net(bool damage_net)
// decides whether you will try to tear the net (result <= 0)
// or try to slip out of it (result > 0)
// both damage and escape could be 9 (more likely for damage)
// but are capped at 5 (damage) and 4 (escape)
static int damage_or_escape_net(int hold)
{
// Spriggan: little (+2)
// Halfling, Kobold, Gnome: small (+1)
// Ogre, Troll, Centaur, Naga: large (-1)
// transformations: spider, bat: tiny (+3); ice beast: large (-1)
int escape = SIZE_MEDIUM - you.body_size(PSIZE_BODY);
int damage = -escape;
// your weapon may damage the net, max. bonus of 2
if (you.equip[EQ_WEAPON] != -1)
{
if (can_cut_meat(you.inv[you.equip[EQ_WEAPON]]))
damage++;
int brand = get_weapon_brand( you.inv[you.equip[EQ_WEAPON]] );
if (brand == SPWPN_FLAMING || brand == SPWPN_VORPAL)
damage++;
}
else if (you.attribute[ATTR_TRANSFORMATION] == TRAN_BLADE_HANDS)
damage += 2;
else if (you.mutation[MUT_CLAWS])
damage += random2(you.mutation[MUT_CLAWS]);
// Berserkers get a fighting bonus
if (you.duration[DUR_BERSERKER])
damage += 2;
// damaged nets are easier to slip out of
if (hold < 0)
{
escape += random2(-hold/2) + 1;
damage += random2(-hold/3 + 1); // ... and easier to destroy
}
// check stats
if (you.strength > random2(18))
damage++;
if (you.dex > random2(12))
escape++;
if (player_evasion() > random2(20))
escape++;
// monsters around you add urgency
if (!i_feel_safe())
{
damage++;
escape++;
}
// confusion makes the whole thing somewhat harder
// (less so for trying to escape)
if (you.duration[DUR_CONF])
{
if (escape > 1)
escape--;
else if (damage >= 2)
damage -= 2;
}
// if undecided, choose damaging approach (it's quicker)
if (damage >= escape)
return (-damage); // negate value
return (escape);
}
// calls the above function to decide on how to get free
// note that usually the net will be damaged until trying to slip out
// becomes feasible (for size etc.), so it may take even longer
void free_self_from_net()
if (damage_net)
{
mpr("You struggle against the net.");
int damage = 1;
int do_what = damage_or_escape_net(mitm[net].plus);
#ifdef DEBUG
mprf(MSGCH_DIAGNOSTICS, "net.plus: %d, ATTR_HELD: %d, do_what: %d",
mitm[net].plus, you.attribute[ATTR_HELD], do_what);
#endif
// extra damage for cutting weapons
if (you.equip[EQ_WEAPON] != -1
&& can_cut_meat(you.inv[you.equip[EQ_WEAPON]]))
{
damage++;
}
if (do_what <= 0) // you try to destroy the net
{ // for previously undamaged nets this takes at least 2
// and at most 8 turns
bool can_slice = you.attribute[ATTR_TRANSFORMATION] == TRAN_BLADE_HANDS
|| you.equip[EQ_WEAPON] != -1
&& can_cut_meat(you.inv[you.equip[EQ_WEAPON]]);
int damage = 1;
damage += random2(-do_what);