Skip to content

Commit

Permalink
Show immunity when targetting an MR-resistible spell (#9391).
Browse files Browse the repository at this point in the history
Pain on a zombie, for example, will show "not susceptible" rather than an
irrelevant percentage.

As mentioned in comments, this is implemented with an ultra-wrong hack, but
the alternative seems to be massive code duplication. This relates back to
fundamental issues with the place of monster_info in the codebase, which
are beyond the scope of this commit.
  • Loading branch information
wheals committed Dec 28, 2015
1 parent b8a2fe6 commit 244f4fb
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 20 deletions.
3 changes: 2 additions & 1 deletion crawl-ref/source/ability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,8 @@ static spret_type _do_ability(const ability_def& abil, bool fail)
direction_chooser_args args;
args.mode = TARG_HOSTILE;
args.get_desc_func = bind(desc_success_chance, placeholders::_1,
zap_ench_power(ZAP_BANISHMENT, pow), false);
zap_ench_power(ZAP_BANISHMENT, pow), false,
nullptr);
if (!spell_direction(spd, beam, &args))
return SPRET_ABORT;

Expand Down
14 changes: 7 additions & 7 deletions crawl-ref/source/beam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4115,7 +4115,7 @@ void bolt::update_hurt_or_helped(monster* mon)
{
if (nasty_to(mon))
foe_info.hurt++;
else if (nice_to(mon))
else if (nice_to(monster_info(mon)))
{
foe_info.helped++;
// Accidentally helped a foe.
Expand All @@ -4137,7 +4137,7 @@ void bolt::update_hurt_or_helped(monster* mon)
if (!is_tracer && mon->mid == source_id)
xom_is_stimulated(100);
}
else if (nice_to(mon))
else if (nice_to(monster_info(mon)))
friend_info.helped++;
}
}
Expand Down Expand Up @@ -6285,7 +6285,7 @@ bool bolt::nasty_to(const monster* mon) const
return false;

// Positive effects.
if (nice_to(mon))
if (nice_to(monster_info(mon)))
return false;

// Co-aligned inner flame is fine.
Expand Down Expand Up @@ -6328,14 +6328,14 @@ bool bolt::nasty_to(const monster* mon) const
// Return true if the bolt is considered nice by mon.
// This is not the inverse of nasty_to(): the bolt needs to be
// actively positive.
bool bolt::nice_to(const monster* mon) const
bool bolt::nice_to(const monster_info& mi) const
{
// Polymorphing a (very) ugly thing will mutate it into a different
// (very) ugly thing.
if (flavour == BEAM_POLYMORPH)
{
return mon->type == MONS_UGLY_THING
|| mon->type == MONS_VERY_UGLY_THING;
return mi.type == MONS_UGLY_THING
|| mi.type == MONS_VERY_UGLY_THING;
}

if (flavour == BEAM_HASTE
Expand All @@ -6348,7 +6348,7 @@ bool bolt::nice_to(const monster* mon) const
return true;
}

if (flavour == BEAM_GHOSTLY_FLAME && mon->holiness() & MH_UNDEAD)
if (flavour == BEAM_GHOSTLY_FLAME && mi.holi & MH_UNDEAD)
return true;

return false;
Expand Down
2 changes: 1 addition & 1 deletion crawl-ref/source/beam.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct bolt
bool god_cares() const; // Will the god be unforgiving about this beam?
bool is_harmless(const monster* mon) const;
bool nasty_to(const monster* mon) const;
bool nice_to(const monster* mon) const;
bool nice_to(const monster_info& mi) const;
bool has_saving_throw() const;

void draw(const coord_def& p);
Expand Down
2 changes: 1 addition & 1 deletion crawl-ref/source/directn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,7 @@ static bool _find_mlist(const coord_def& where, int idx, bool need_path,
static bool _want_target_monster(const monster *mon, targ_mode_type mode,
targetter* hitfunc)
{
if (hitfunc && !hitfunc->affects_monster(*mon))
if (hitfunc && !hitfunc->affects_monster(monster_info(mon)))
return false;
switch (mode)
{
Expand Down
3 changes: 2 additions & 1 deletion crawl-ref/source/evoke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ void zap_wand(int slot)
SPFLAG_MR_CHECK))
{
args.get_desc_func = bind(desc_success_chance, placeholders::_1,
zap_ench_power(type_zapped, power), true);
zap_ench_power(type_zapped, power), true,
hitfunc);
}
direction(zap_wand, args);

Expand Down
7 changes: 5 additions & 2 deletions crawl-ref/source/spl-cast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,15 @@ int hex_success_chance(const int mr, int powc, int scale, bool round_up)
}

// Include success chance in targeter for spells checking monster MR.
vector<string> desc_success_chance(const monster_info& mi, int pow, bool evoked)
vector<string> desc_success_chance(const monster_info& mi, int pow, bool evoked,
targetter* hitfunc)
{
vector<string> descs;
const int mr = mi.res_magic();
if (mr == MAG_IMMUNE)
descs.push_back("magic immune");
else if (hitfunc && !hitfunc->affects_monster(mi))
descs.push_back("not susceptible");
else
{
int success = hex_success_chance(mr,
Expand Down Expand Up @@ -1314,7 +1317,7 @@ spret_type your_spells(spell_type spell, int powc,
const int eff_pow = zap == NUM_ZAPS ? powc
: zap_ench_power(zap, powc);
additional_desc = bind(desc_success_chance, placeholders::_1,
eff_pow, evoked);
eff_pow, evoked, hitfunc.get());
}

string title = "Aiming: <white>";
Expand Down
4 changes: 3 additions & 1 deletion crawl-ref/source/spl-cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ void do_cast_spell_cmd(bool force);

int hex_success_chance(const int mr, int powc, int scale,
bool round_up = false);
vector<string> desc_success_chance(const monster_info& mi, int pow, bool evoked);
class targetter;
vector<string> desc_success_chance(const monster_info& mi, int pow, bool evoked,
targetter* hitfunc);
spret_type your_spells(spell_type spell, int powc = 0, bool allow_fail = true,
bool evoked = false, bool fake_spell = false);

Expand Down
12 changes: 8 additions & 4 deletions crawl-ref/source/target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool targetter::has_additional_sites(coord_def loc)
return false;
}

bool targetter::affects_monster(const monster& mon)
bool targetter::affects_monster(const monster_info& mon)
{
return true; //TODO: false
}
Expand Down Expand Up @@ -226,11 +226,15 @@ aff_type targetter_beam::is_affected(coord_def loc)
AFF_MULTIPLE;
}

bool targetter_beam::affects_monster(const monster& mon)
bool targetter_beam::affects_monster(const monster_info& mon)
{
return !beam.is_harmless(&mon) || beam.nice_to(&mon)
//XXX: this is a disgusting hack that probably leaks information!
// bolt::is_harmless (and transitively, bolt::nasty_to) should
// take monster_infos instead.
const monster* m = monster_at(mon.pos);
return m && (!beam.is_harmless(m) || beam.nice_to(mon))
&& !(beam.has_saving_throw() && beam.flavour != BEAM_VIRULENCE
&& mons_immune_magic(&mon));
&& mon.res_magic() == MAG_IMMUNE);
}

targetter_unravelling::targetter_unravelling(const actor *act, int r, int pow)
Expand Down
4 changes: 2 additions & 2 deletions crawl-ref/source/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class targetter

virtual aff_type is_affected(coord_def loc) = 0;
virtual bool has_additional_sites(coord_def a);
virtual bool affects_monster(const monster& mon);
virtual bool affects_monster(const monster_info& mon);
protected:
bool anyone_there(coord_def loc);
};
Expand All @@ -47,7 +47,7 @@ class targetter_beam : public targetter
bool valid_aim(coord_def a) override;
bool can_affect_outside_range() override;
virtual aff_type is_affected(coord_def loc) override;
virtual bool affects_monster(const monster& mon) override;
virtual bool affects_monster(const monster_info& mon) override;
protected:
vector<coord_def> path_taken; // Path beam took.
void set_explosion_aim(bolt tempbeam);
Expand Down

0 comments on commit 244f4fb

Please sign in to comment.