Skip to content

Commit

Permalink
allow resting up to a specific percent of hp/mp
Browse files Browse the repository at this point in the history
this way, for instance, pressing 5 can restore 70% of hp instead of
always waiting until completely full
  • Loading branch information
doy committed Apr 1, 2015
1 parent 395b7c9 commit f038802
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions crawl-ref/docs/options_guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,11 @@ rest_wait_both = false
when both HP and MP are fully restored, not when either one of
them is restored.

rest_wait_percent = 100
When resting, if your HP or MP is below this percentage of being full,
it will stop resting when this percent of maximum HP or MP is refilled.
Resting after this point will still rest up to 100%.

auto_exclude += <monster name>, <monster name>, ...
(List option)
Whenever you encounter a sleeping or stationary monster during
Expand Down
9 changes: 5 additions & 4 deletions crawl-ref/source/delay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1313,9 +1313,10 @@ static bool _should_stop_activity(const delay_queue_item &item,

if (ai == AI_FULL_HP || ai == AI_FULL_MP)
{
int max_hp = (Options.rest_wait_percent * you.hp_max) / 100;
int max_mp = (Options.rest_wait_percent * you.max_magic_points) / 100;
if (Options.rest_wait_both && curr == DELAY_REST
&& (you.magic_points < you.max_magic_points
|| you.hp < you.hp_max))
&& (you.magic_points < max_mp || you.hp < max_hp))
{
return false;
}
Expand Down Expand Up @@ -1612,9 +1613,9 @@ bool interrupt_activity(activity_interrupt_type ai,
// First try to stop the current delay.
const delay_queue_item &item = you.delay_queue.front();

if (ai == AI_FULL_HP)
if (ai == AI_FULL_HP && !you.running.notified_hp_full++)
mpr("HP restored.");
else if (ai == AI_FULL_MP)
else if (ai == AI_FULL_MP && !you.running.notified_mp_full++)
mpr("Magic restored.");

if (_should_stop_activity(item, ai, at))
Expand Down
2 changes: 2 additions & 0 deletions crawl-ref/source/externs.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ class runrest
int runmode;
int mp;
int hp;
bool notified_mp_full;
bool notified_hp_full;
coord_def pos;
int travel_speed;

Expand Down
2 changes: 2 additions & 0 deletions crawl-ref/source/initfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ void game_options::reset_options()
item_glyph_cache.clear();

rest_wait_both = false;
rest_wait_percent = 100;

// Map each category to itself. The user can override in init.txt
kill_map[KC_YOU] = KC_YOU;
Expand Down Expand Up @@ -3651,6 +3652,7 @@ void game_options::read_option_line(const string &str, bool runscript)
}
}
else BOOL_OPTION(rest_wait_both);
else INT_OPTION(rest_wait_percent, 0, 100);
else BOOL_OPTION(cloud_status);
else if (key == "dump_message_count")
{
Expand Down
2 changes: 2 additions & 0 deletions crawl-ref/source/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ struct game_options

bool rest_wait_both; // Stop resting only when both HP and MP are
// fully restored.
int rest_wait_percent; // Stop resting after restoring this
// fraction of HP or MP

lang_t language; // Translation to use.
const char* lang_name; // Database name of the language.
Expand Down
12 changes: 10 additions & 2 deletions crawl-ref/source/player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3955,6 +3955,11 @@ bool enough_zp(int minimum, bool suppress_msg)
return true;
}

static bool should_stop_resting(int cur, int max)
{
return cur == max || cur == (max * Options.rest_wait_percent) / 100;
}

void inc_mp(int mp_gain, bool silent)
{
ASSERT(!crawl_state.game_is_arena());
Expand All @@ -3976,8 +3981,11 @@ void inc_mp(int mp_gain, bool silent)

if (!silent)
{
if (wasnt_max && you.magic_points == you.max_magic_points)
if (wasnt_max
&& should_stop_resting(you.magic_points, you.max_magic_points))
{
interrupt_activity(AI_FULL_MP);
}
you.redraw_magic_points = true;
}
}
Expand All @@ -3999,7 +4007,7 @@ void inc_hp(int hp_gain)
if (you.hp > you.hp_max)
you.hp = you.hp_max;

if (wasnt_max && you.hp == you.hp_max)
if (wasnt_max && should_stop_resting(you.hp, you.hp_max))
interrupt_activity(AI_FULL_HP);

you.redraw_hit_points = true;
Expand Down
4 changes: 4 additions & 0 deletions crawl-ref/source/travel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,8 @@ void runrest::initialise(int dir, int mode)
// Note HP and MP for reference.
hp = you.hp;
mp = you.magic_points;
notified_hp_full = false;
notified_mp_full = false;
init_travel_speed();

if (dir == RDIR_REST)
Expand Down Expand Up @@ -4202,6 +4204,8 @@ void runrest::clear()
runmode = RMODE_NOT_RUNNING;
pos.reset();
mp = hp = travel_speed = 0;
notified_hp_full = false;
notified_mp_full = false;

_reset_zigzag_info();
}
Expand Down

0 comments on commit f038802

Please sign in to comment.