summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/player-stats.cc
diff options
context:
space:
mode:
authorelliptic <hyperelliptical@gmail.com>2013-11-03 19:51:50 -0500
committerelliptic <hyperelliptical@gmail.com>2013-11-03 20:53:26 -0500
commit0e91adf89620bbf7698e45f9df593a3f37649675 (patch)
tree848a7c72d59dbb5b2dec2e574621b499db5b9588 /crawl-ref/source/player-stats.cc
parent612243dca4b10f4a8e1169912de79b197ff1fe74 (diff)
downloadcrawl-ref-0e91adf89620bbf7698e45f9df593a3f37649675.tar.gz
crawl-ref-0e91adf89620bbf7698e45f9df593a3f37649675.zip
Let choose_stat_gain work by returning a string.
It used to be that to use this lua hook to automatically choose a stat at level-up, the function choose_stat_gain had to call crawl.sendkeys('s') or some such. This still works, but now the function can return a string instead and the first character will be used.
Diffstat (limited to 'crawl-ref/source/player-stats.cc')
-rw-r--r--crawl-ref/source/player-stats.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/crawl-ref/source/player-stats.cc b/crawl-ref/source/player-stats.cc
index a33992bf19..a8292c56c2 100644
--- a/crawl-ref/source/player-stats.cc
+++ b/crawl-ref/source/player-stats.cc
@@ -104,17 +104,29 @@ bool attribute_increase()
mpr("Increase (S)trength, (I)ntelligence, or (D)exterity? ", MSGCH_PROMPT);
#endif
mouse_control mc(MOUSE_MODE_PROMPT);
- // Calling a user-defined lua function here to let players reply to the
- // prompt automatically.
- clua.callfn("choose_stat_gain", 0, 0);
+ bool tried_lua = false;
+ int keyin;
while (true)
{
+ // Calling a user-defined lua function here to let players reply to
+ // the prompt automatically. Either returning a string or using
+ // crawl.sendkeys will work.
+ if (!tried_lua && clua.callfn("choose_stat_gain", 0, 1))
+ {
+ string result;
+ clua.fnreturns(">s", &result);
+ keyin = result[0];
+ }
+ else
+ {
#ifdef TOUCH_UI
- const int keyin = pop->pop();
+ keyin = pop->pop();
#else
- const int keyin = getchm();
+ keyin = getchm();
#endif
+ }
+ tried_lua = true;
switch (keyin)
{