summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-29 14:50:38 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-29 14:50:38 +0000
commit543be3c674fc50c6a375b77e1e9e5296a76bbef2 (patch)
tree49ac3bc9a6fe024346f7b1fcc07dd95f19e725d1
parentc029d0d79ef9776675002f94cd1f2d541e5435b2 (diff)
downloadcrawl-ref-543be3c674fc50c6a375b77e1e9e5296a76bbef2.tar.gz
crawl-ref-543be3c674fc50c6a375b77e1e9e5296a76bbef2.zip
Trunk->0.4 r6718: Don't lose level-up stat and hp gain if Crawl receives SIGHUP at the level-up prompt.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6719 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/acr.cc6
-rw-r--r--crawl-ref/source/player.cc44
2 files changed, 34 insertions, 16 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 849f754946..02ce386d18 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -277,6 +277,12 @@ int main( int argc, char *argv[] )
else
learned_something_new(TUT_LOAD_SAVED_GAME);
+ // Catch up on any experience levels we did not assign last time. This
+ // can happen if Crawl sees SIGHUP while it is waiting for the player
+ // to dismiss a level-up prompt.
+ _prep_input();
+ level_change();
+
while (true)
_input();
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 781ea5e7fb..04c37b846b 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -2945,46 +2945,59 @@ void level_change(bool skip_attribute_increase)
int hp_adjust = 0;
int mp_adjust = 0;
- you.experience_level++;
+ // [ds] Make sure we increment you.experience_level and apply
+ // any stat/hp increases only after we've cleared all prompts
+ // for this experience level. If we do part of the work before
+ // the prompt, and a player on telnet gets disconnected, the
+ // SIGHUP will save Crawl in the in-between state and rob the
+ // player of their level-up perks.
- if (you.experience_level <= you.max_level)
+ const int new_exp = you.experience_level + 1;
+
+ if (new_exp <= you.max_level)
{
mprf(MSGCH_INTRINSIC_GAIN,
- "Welcome back to level %d!", you.experience_level );
+ "Welcome back to level %d!", new_exp );
if (!skip_more)
more();
+ // No more prompts for this XL past this point.
+
+ you.experience_level = new_exp;
// Gain back the hp and mp we lose in lose_level(). -- bwr
- inc_hp( 4, true );
- inc_mp( 1, true );
+ inc_hp(4, true);
+ inc_mp(1, true);
}
else // Character has gained a new level
{
- if (you.experience_level == 27)
- mprf(MSGCH_INTRINSIC_GAIN, "You have reached level 27, the final one!");
+ if (new_exp == 27)
+ mprf(MSGCH_INTRINSIC_GAIN,
+ "You have reached level 27, the final one!");
else
- {
mprf(MSGCH_INTRINSIC_GAIN, "You have reached level %d!",
- you.experience_level);
- }
+ new_exp);
+
if (!skip_more)
more();
+ if (!(new_exp % 3) && !skip_attribute_increase)
+ _attribute_increase();
+
+ // No more prompts for this XL past this point.
+
int brek = 0;
- if (you.experience_level > 21)
+ if (new_exp > 21)
brek = (coinflip() ? 3 : 2);
- else if (you.experience_level > 12)
+ else if (new_exp > 12)
brek = 3 + random2(3); // up from 2 + rand(3) -- bwr
else
brek = 4 + random2(4); // up from 3 + rand(4) -- bwr
+ you.experience_level = new_exp;
inc_hp( brek, true );
inc_mp( 1, true );
- if (!(you.experience_level % 3) && !skip_attribute_increase)
- _attribute_increase();
-
switch (you.species)
{
case SP_HUMAN:
@@ -3527,7 +3540,6 @@ void level_change(bool skip_attribute_increase)
xom_is_stimulated(16);
learned_something_new(TUT_NEW_LEVEL);
-
}
redraw_skill( you.your_name, player_title() );