diff options
author | Enne Walker <ennewalker@users.sourceforge.net> | 2009-10-31 10:59:52 -0400 |
---|---|---|
committer | Enne Walker <ennewalker@users.sourceforge.net> | 2009-10-31 11:09:28 -0400 |
commit | 95746496df9bc09763421a35bb5c3cbc1ff4ad54 (patch) | |
tree | 941adb4b2e042d6f63a2c467d96e431464cbc145 /crawl-ref/source/l_you.cc | |
parent | 3877db329ce13f8d527b2954c3f9d5857a2b6b35 (diff) | |
download | crawl-ref-95746496df9bc09763421a35bb5c3cbc1ff4ad54.tar.gz crawl-ref-95746496df9bc09763421a35bb5c3cbc1ff4ad54.zip |
Adding you.in_branch(string) as a lua function.
This also removes you.where_are_you() so as not to require lua scripts to
know the value of C++ enums. This change also fixes stricmp incorrectly
falling through to strcmp on non-MSVC platforms.
Diffstat (limited to 'crawl-ref/source/l_you.cc')
-rw-r--r-- | crawl-ref/source/l_you.cc | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/crawl-ref/source/l_you.cc b/crawl-ref/source/l_you.cc index aa58e0e5f8..a316cc768d 100644 --- a/crawl-ref/source/l_you.cc +++ b/crawl-ref/source/l_you.cc @@ -4,6 +4,7 @@ #include "l_libs.h" #include "abl-show.h" +#include "branch.h" #include "chardump.h" #include "coord.h" #include "delay.h" @@ -275,7 +276,39 @@ static int _you_gold(lua_State *ls) LUAWRAP(_you_die,ouch(INSTANT_DEATH, NON_MONSTER, KILLED_BY_SOMETHING)) -LUARET1(you_where_are_you, number, you.where_are_you) +LUAFN(you_in_branch) +{ + const char* name = luaL_checkstring(ls, 1); + + int br = NUM_BRANCHES; + + for (int i = 0; i < NUM_BRANCHES; i++) + { + if (stricmp(name, branches[i].shortname) == 0 + || stricmp(name, branches[i].longname) == 0 + || stricmp(name, branches[i].abbrevname) == 0) + { + if (br != NUM_BRANCHES) + { + std::string err = make_stringf( + "'%s' matches both branch '%s' and '%s'", + name, branches[br].abbrevname, + branches[i].abbrevname); + return (luaL_argerror(ls, 1, err.c_str())); + } + br = i; + } + } + + if (br == NUM_BRANCHES) + { + std::string err = make_stringf("'%s' matches no branches.", name); + return (luaL_argerror(ls, 1, err.c_str())); + } + + bool in_branch = (br == you.where_are_you); + PLUARET(boolean, in_branch); +} static const struct luaL_reg you_dlib[] = { @@ -291,7 +324,7 @@ static const struct luaL_reg you_dlib[] = { "gold", _you_gold }, { "uniques", _you_uniques }, { "die", _you_die }, -{ "where_are_you", you_where_are_you }, +{ "in_branch", you_in_branch }, { NULL, NULL } }; |