summaryrefslogtreecommitdiffstats
path: root/src/scripting
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-21 19:44:11 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-03-25 20:32:37 +0100
commit4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64 (patch)
tree1b77436b4623c8c1fc4419758e623753899fd818 /src/scripting
parent7aeb3b4a6c34a8f679719c207e51394d7e48828b (diff)
downloadmanaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.tar.gz
manaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.tar.xz
manaserv-4e9e0ac87b4dc16f19ac4f930d52c4cc0a2c6f64.zip
Changed NPC to an NpcComponent added to a Being
Diffstat (limited to 'src/scripting')
-rw-r--r--src/scripting/lua.cpp64
-rw-r--r--src/scripting/luautil.cpp8
-rw-r--r--src/scripting/luautil.h5
3 files changed, 43 insertions, 34 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 705ee4c..d443899 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;
diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp
index 6210eda..24e9edf 100644
--- a/src/scripting/luautil.cpp
+++ b/src/scripting/luautil.cpp
@@ -188,14 +188,14 @@ MonsterClass *getMonsterClass(lua_State *s, int p)
return monsterClass;
}
-NPC *getNPC(lua_State *s, int p)
+Being *getNpc(lua_State *s, int p)
{
if (!lua_islightuserdata(s, p))
return 0;
Entity *t = static_cast<Entity *>(lua_touserdata(s, p));
if (t->getType() != OBJECT_NPC)
return 0;
- return static_cast<NPC *>(t);
+ return static_cast<Being*>(t);
}
@@ -234,9 +234,9 @@ MonsterClass *checkMonsterClass(lua_State *s, int p)
return monsterClass;
}
-NPC *checkNPC(lua_State *s, int p)
+Being *checkNpc(lua_State *s, int p)
{
- NPC *npc = getNPC(s, p);
+ Being *npc = getNpc(s, p);
luaL_argcheck(s, npc, p, "npc expected");
return npc;
}
diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h
index 8e380d4..dd63c0f 100644
--- a/src/scripting/luautil.h
+++ b/src/scripting/luautil.h
@@ -45,7 +45,6 @@ class MapComposite;
class MapObject;
class Monster;
class MonsterClass;
-class NPC;
class StatusEffect;
void raiseWarning(lua_State *s, const char *format, ...);
@@ -172,14 +171,14 @@ Character * getCharacter(lua_State *s, int p);
ItemClass * getItemClass(lua_State *s, int p);
Monster * getMonster(lua_State *s, int p);
MonsterClass * getMonsterClass(lua_State *s, int p);
-NPC * getNPC(lua_State *s, int p);
+Being * getNpc(lua_State *s, int p);
Being * checkBeing(lua_State *s, int p);
Character * checkCharacter(lua_State *s, int p);
ItemClass * checkItemClass(lua_State *s, int p);
Monster * checkMonster(lua_State *s, int p);
MonsterClass * checkMonsterClass(lua_State *s, int p);
-NPC * checkNPC(lua_State *s, int p);
+Being * checkNpc(lua_State *s, int p);
int checkSkill(lua_State *s, int p);
int checkSpecial(lua_State *s, int p);