diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-21 19:44:11 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-03-25 20:32:37 +0100 |
commit | 4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64 (patch) | |
tree | 1b77436b4623c8c1fc4419758e623753899fd818 /src/scripting/lua.cpp | |
parent | 7aeb3b4a6c34a8f679719c207e51394d7e48828b (diff) | |
download | manaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.tar.gz manaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.tar.bz2 manaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.tar.xz manaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.zip |
Changed NPC to an NpcComponent added to a Being
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 705ee4c9..d4438990 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -280,25 +280,35 @@ static int npc_create(lua_State *s) MapComposite *m = checkCurrentMap(s); - NPC *q = new NPC(name, id); - q->setGender(getGender(gender)); - q->setMap(m); - q->setPosition(Point(x, y)); + NpcComponent *npcComponent = new NpcComponent(id); + + Being *npc = new Being(OBJECT_NPC); + npc->addComponent(npcComponent); + // some health so it doesn't spawn dead + npc->setAttribute(ATTR_MAX_HP, 100); + npc->setAttribute(ATTR_HP, 100); + npc->setName(name); + npc->setGender(getGender(gender)); + + npc->setWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_MONSTER | + Map::BLOCKMASK_CHARACTER); + npc->setMap(m); + npc->setPosition(Point(x, y)); if (lua_isfunction(s, 6)) { lua_pushvalue(s, 6); - q->setTalkCallback(luaL_ref(s, LUA_REGISTRYINDEX)); + npcComponent->setTalkCallback(luaL_ref(s, LUA_REGISTRYINDEX)); } if (lua_isfunction(s, 7)) { lua_pushvalue(s, 7); - q->setUpdateCallback(luaL_ref(s, LUA_REGISTRYINDEX)); + npcComponent->setUpdateCallback(luaL_ref(s, LUA_REGISTRYINDEX)); } - GameState::enqueueInsert(q); - lua_pushlightuserdata(s, q); + GameState::enqueueInsert(npc); + lua_pushlightuserdata(s, npc); return 1; } @@ -309,9 +319,9 @@ static int npc_create(lua_State *s) */ static int npc_enable(lua_State *s) { - NPC *p = checkNPC(s, 1); - p->setEnabled(true); - GameState::enqueueInsert(p); + Being *npc = checkNpc(s, 1); + npc->getComponent<NpcComponent>()->setEnabled(true); + GameState::enqueueInsert(npc); return 0; } @@ -322,9 +332,9 @@ static int npc_enable(lua_State *s) */ static int npc_disable(lua_State *s) { - NPC *p = checkNPC(s, 1); - p->setEnabled(false); - GameState::remove(p); + Being *npc = checkNpc(s, 1); + npc->getComponent<NpcComponent>()->setEnabled(false); + GameState::remove(npc); return 0; } @@ -489,14 +499,14 @@ static int item_drop(lua_State *s) */ static int npc_message(lua_State *s) { - NPC *p = checkNPC(s, 1); + Being *npc = checkNpc(s, 1); Character *q = checkCharacter(s, 2); const char *m = luaL_checkstring(s, 3); Script::Thread *thread = checkCurrentThread(s); MessageOut msg(GPMSG_NPC_MESSAGE); - msg.writeInt16(p->getPublicID()); + msg.writeInt16(npc->getPublicID()); msg.writeString(m); gameHandler->sendTo(q, msg); @@ -522,13 +532,13 @@ static int npc_message(lua_State *s) */ static int npc_choice(lua_State *s) { - NPC *p = checkNPC(s, 1); + Being *npc = checkNpc(s, 1); Character *q = checkCharacter(s, 2); Script::Thread *thread = checkCurrentThread(s); MessageOut msg(GPMSG_NPC_CHOICE); - msg.writeInt16(p->getPublicID()); + msg.writeInt16(npc->getPublicID()); for (int i = 3, i_end = lua_gettop(s); i <= i_end; ++i) { if (lua_isstring(s, i)) @@ -578,7 +588,7 @@ static int npc_choice(lua_State *s) */ static int npc_ask_integer(lua_State *s) { - NPC *p = checkNPC(s, 1); + Being *npc = checkNpc(s, 1); Character *q = checkCharacter(s, 2); int min = luaL_checkint(s, 3); int max = luaL_checkint(s, 4); @@ -587,7 +597,7 @@ static int npc_ask_integer(lua_State *s) Script::Thread *thread = checkCurrentThread(s); MessageOut msg(GPMSG_NPC_NUMBER); - msg.writeInt16(p->getPublicID()); + msg.writeInt16(npc->getPublicID()); msg.writeInt32(min); msg.writeInt32(max); msg.writeInt32(defaultValue); @@ -608,13 +618,13 @@ static int npc_ask_integer(lua_State *s) */ static int npc_ask_string(lua_State *s) { - NPC *p = checkNPC(s, 1); + Being *npc = checkNpc(s, 1); Character *q = checkCharacter(s, 2); Script::Thread *thread = checkCurrentThread(s); MessageOut msg(GPMSG_NPC_STRING); - msg.writeInt16(p->getPublicID()); + msg.writeInt16(npc->getPublicID()); gameHandler->sendTo(q, msg); thread->mState = Script::ThreadExpectingString; @@ -628,11 +638,11 @@ static int npc_ask_string(lua_State *s) */ static int npc_post(lua_State *s) { - NPC *p = checkNPC(s, 1); + Being *npc = checkNpc(s, 1); Character *q = checkCharacter(s, 2); MessageOut msg(GPMSG_NPC_POST); - msg.writeInt16(p->getPublicID()); + msg.writeInt16(npc->getPublicID()); gameHandler->sendTo(q, msg); return 0; @@ -755,7 +765,7 @@ static int announce(lua_State *s) */ static int npc_trade(lua_State *s) { - NPC *p = checkNPC(s, 1); + Being *npc = checkNpc(s, 1); Character *q = checkCharacter(s, 2); if (!lua_isboolean(s, 3)) { @@ -778,7 +788,7 @@ static int npc_trade(lua_State *s) return 1; } - if (t->start(p)) + if (t->start(npc)) { lua_pushinteger(s, 0); return 1; @@ -856,7 +866,7 @@ static int npc_trade(lua_State *s) lua_pushinteger(s, 1); return 1; } - if (t->start(p)) + if (t->start(npc)) { lua_pushinteger(s, 0); return 1; |