From 22e5db9d1ec1a8119185f3806387519195497b1c Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Mon, 3 Sep 2007 13:41:30 +0000 Subject: Implementing patch 1772497 (improvement to runrest.lua by zelgadis). Also added notes for getting penance, and small fix (patch 1786893 by dolorous). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2047 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/misc.cc | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'crawl-ref/source/misc.cc') diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index ed29826c53..d4212f73aa 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -40,6 +40,7 @@ #include "branch.h" #include "chardump.h" #include "cloud.h" +#include "clua.h" #include "delay.h" #include "dgnevent.h" #include "fight.h" @@ -2447,7 +2448,32 @@ std::string cloud_name(cloud_type type) } } -bool i_feel_safe(bool announce) +bool mons_is_safe(const struct monsters *mon, bool want_move) +{ + bool is_safe = mons_friendly(mon) || + (Options.safe_zero_exp && + mons_class_flag( mon->type, M_NO_EXP_GAIN )); + +#ifdef CLUA_BINDINGS + bool moving = ((!you.delay_queue.empty() && + is_run_delay(you.delay_queue.front().type) && + you.delay_queue.front().type != DELAY_REST) || + you.running < RMODE_NOT_RUNNING || want_move); + + int dist = grid_distance(you.x_pos, you.y_pos, + mon->x, mon->y); + bool result = is_safe; + + if (clua.callfn("ch_mon_is_safe", "Mbbd>b", + mon, is_safe, moving, dist, + &result)) + is_safe = result; +#endif + + return is_safe; +} + +bool i_feel_safe(bool announce, bool want_move) { /* This is probably unnecessary, but I'm not sure that you're always at least 9 away from a wall */ @@ -2486,12 +2512,10 @@ bool i_feel_safe(bool announce) if ( targ_monst != NON_MONSTER ) { const monsters *mon = &menv[targ_monst]; - if ( !mons_friendly(mon) && - player_monster_visible(mon) && + if ( player_monster_visible(mon) && !mons_is_submerged(mon) && !mons_is_mimic(mon->type) && - (!Options.safe_zero_exp || - !mons_class_flag( mon->type, M_NO_EXP_GAIN ))) + !mons_is_safe(mon, want_move)) { if (announce) mons.push_back(mon); -- cgit v1.2.3-54-g00ecf