summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-15 02:39:52 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-15 02:39:52 +0000
commit20cc45b27ecb5264b1e71e99e233b8e4b4aaea50 (patch)
tree37a13fdeac32b60bcccea8362ddf26ca53c2428e /src
parent68c0625ee9a3a01090f0bc93612bf84dd71eaa67 (diff)
downloadmanaserv-20cc45b27ecb5264b1e71e99e233b8e4b4aaea50.tar.gz
manaserv-20cc45b27ecb5264b1e71e99e233b8e4b4aaea50.tar.bz2
manaserv-20cc45b27ecb5264b1e71e99e233b8e4b4aaea50.tar.xz
manaserv-20cc45b27ecb5264b1e71e99e233b8e4b4aaea50.zip
Added pathblocking rules to NPCs, added script bindings to query being positions and created script infrastructure for regularily called script functions. This allows NPCs which wander around automatically.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/npc.hpp14
-rw-r--r--src/scripting/lua.cpp30
2 files changed, 44 insertions, 0 deletions
diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp
index 7c909d25..2d790c4c 100644
--- a/src/game-server/npc.hpp
+++ b/src/game-server/npc.hpp
@@ -54,6 +54,20 @@ class NPC : public Being
int getNPC() const
{ return mID; }
+ /**
+ * Gets the way an NPC is blocked by other things on the map
+ */
+ virtual unsigned char getWalkMask() const
+ { return 0x83; } // blocked like a monster by walls, monsters and characters ( bin 1000 0011)
+
+ protected:
+
+ /**
+ * Gets the way a monster blocks pathfinding for other objects
+ */
+ virtual Map::BlockType getBlockType() const
+ { return Map::BLOCKTYPE_CHARACTER; } //blocks like a player character
+
private:
Script *mScript; /**< Script describing NPC behavior. */
unsigned short mID; /**< ID of the NPC. */
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 7437af83..3d706619 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -400,6 +400,34 @@ static int LuaBeing_Walk(lua_State *s)
}
/**
+ * Function for getting the x-coordinate of the position of a being
+ */
+static int LuaPosX(lua_State *s)
+{
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+
+ int x = getBeing(s, 1)->getPosition().x;
+ lua_pushinteger(s, x);
+
+ return 1;
+}
+
+/**
+ * Function for getting the y-coordinate of the position of a being
+ */
+static int LuaPosY(lua_State *s)
+{
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+
+ int y = getBeing(s, 1)->getPosition().y;
+ lua_pushinteger(s, y);
+
+ return 1;
+}
+
+/**
* Callback for creating a monster on the current map.
* tmw.monster_create(int type, int x, int y)
*/
@@ -524,6 +552,8 @@ LuaScript::LuaScript():
{ "chr_set_quest", &LuaChr_SetQuest },
{ "monster_create", &LuaMonster_Create },
{ "being_walk", &LuaBeing_Walk },
+ { "posX", &LuaPosX },
+ { "posY", &LuaPosY },
{ NULL, NULL }
};
luaL_register(mState, "tmw", callbacks);