diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-05-19 15:07:45 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-05-19 15:07:45 +0000 |
commit | 502d5c892c92b4a71eceae1d275032100d42dd23 (patch) | |
tree | 81f29c3ce0bda3d2a4221a485c9695d4e56eb568 /src/scripting/lua.cpp | |
parent | 4b4b6d0865f5f04f73e04926fb9e6b610f0a71a7 (diff) | |
download | manaserv-502d5c892c92b4a71eceae1d275032100d42dd23.tar.gz manaserv-502d5c892c92b4a71eceae1d275032100d42dd23.tar.bz2 manaserv-502d5c892c92b4a71eceae1d275032100d42dd23.tar.xz manaserv-502d5c892c92b4a71eceae1d275032100d42dd23.zip |
Implemented NPC names. Implemented the theoretical possibility to have named monsters along the way. Note that the syntax of the LUA functions for creating NPCs has changed.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index a8663f75..9f160bca 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -68,6 +68,8 @@ class LuaScript: public Script void push(int); + void push(const std::string &); + void push(Thing *); int execute(); @@ -180,11 +182,11 @@ static int LuaNpc_Choice(lua_State *s) /** * Callback for creating a NPC on the current map with the current script. - * tmw.npc_create(int id, int x, int y): npc + * tmw.npc_create(string name, int id, int x, int y): npc */ static int LuaNpc_Create(lua_State *s) { - if (!lua_isnumber(s, 1) || !lua_isnumber(s, 2) || !lua_isnumber(s, 3)) + if (!lua_isstring(s, 1), !lua_isnumber(s, 2) || !lua_isnumber(s, 3) || !lua_isnumber(s, 4)) { raiseScriptError(s, "npc_create called with incorrect parameters."); return 0; @@ -192,7 +194,7 @@ static int LuaNpc_Create(lua_State *s) lua_pushlightuserdata(s, (void *)®istryKey); lua_gettable(s, LUA_REGISTRYINDEX); Script *t = static_cast<Script *>(lua_touserdata(s, -1)); - NPC *q = new NPC(lua_tointeger(s, 1), t); + NPC *q = new NPC(lua_tostring(s, 1), lua_tointeger(s, 2), t); MapComposite *m = t->getMap(); if (!m) { @@ -200,7 +202,7 @@ static int LuaNpc_Create(lua_State *s) return 0; } q->setMap(m); - q->setPosition(Point(lua_tointeger(s, 2), lua_tointeger(s, 3))); + q->setPosition(Point(lua_tointeger(s, 3), lua_tointeger(s, 4))); bool b = GameState::insert(q); /* Do not try to deal with a failure there. There are some serious issues if an insertion failed on an almost empty map. */ @@ -711,6 +713,14 @@ void LuaScript::push(int v) ++nbArgs; } +void LuaScript::push(std::string const &v) +{ + assert(nbArgs >= 0); + lua_pushstring(mState, v.c_str()); + ++nbArgs; +} + + void LuaScript::push(Thing *v) { assert(nbArgs >= 0); |