diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-03-13 16:18:38 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-03-13 16:25:18 +0100 |
commit | 53cf65f40c64a0d2ea8757390179127222faa258 (patch) | |
tree | a82479f3e77df3021d2105dda604b8e5eb2a90c4 /src | |
parent | 0075aa38fbde5c3df773cca320bcba615296624c (diff) | |
download | manaserv-53cf65f40c64a0d2ea8757390179127222faa258.tar.gz manaserv-53cf65f40c64a0d2ea8757390179127222faa258.tar.bz2 manaserv-53cf65f40c64a0d2ea8757390179127222faa258.tar.xz manaserv-53cf65f40c64a0d2ea8757390179127222faa258.zip |
Added script bind to set walkmask for beings
TODO: Inform client about this change.
Reviewed-by: bjorn.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/actor.h | 12 | ||||
-rw-r--r-- | src/game-server/character.cpp | 3 | ||||
-rw-r--r-- | src/game-server/character.h | 7 | ||||
-rw-r--r-- | src/game-server/map.h | 6 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 3 | ||||
-rw-r--r-- | src/game-server/monster.h | 9 | ||||
-rw-r--r-- | src/game-server/npc.cpp | 3 | ||||
-rw-r--r-- | src/game-server/npc.h | 6 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 42 |
9 files changed, 63 insertions, 28 deletions
diff --git a/src/game-server/actor.h b/src/game-server/actor.h index abc1e1d0..758424aa 100644 --- a/src/game-server/actor.h +++ b/src/game-server/actor.h @@ -52,7 +52,8 @@ class Actor : public Thing mMoveTime(0), mUpdateFlags(0), mPublicID(65535), - mSize(0) + mSize(0), + mWalkMask(0) {} ~Actor(); @@ -114,11 +115,14 @@ class Actor : public Thing bool isPublicIdValid() const { return (mPublicID > 0 && mPublicID != 65535); } + void setWalkMask(unsigned char mask) + { mWalkMask = mask; } + /** * Gets the way the actor blocks pathfinding for other actors. */ - virtual unsigned char getWalkMask() const - { return 0x00; } //can walk through everything + unsigned char getWalkMask() const + { return mWalkMask; } /** * Overridden in order to update the walkmap. @@ -143,6 +147,8 @@ class Actor : public Thing Point mPos; /**< Coordinates. */ unsigned char mSize; /**< Radius of bounding circle. */ + + unsigned char mWalkMask; }; #endif // ACTOR_H diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index ccd629e8..031cf87c 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -34,6 +34,7 @@ #include "game-server/item.h" #include "game-server/itemmanager.h" #include "game-server/gamehandler.h" +#include "game-server/map.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" #include "game-server/skillmanager.h" @@ -97,6 +98,8 @@ Character::Character(MessageIn &msg): it1_end = attr.end(); it1 != it1_end; ++it1) mAttributes.insert(std::make_pair(it1->first, Attribute(*it1->second))); + setWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_MONSTER); + // Get character data. mDatabaseID = msg.readInt32(); setName(msg.readString()); diff --git a/src/game-server/character.h b/src/game-server/character.h index 1f82a101..f54d4ec4 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -372,13 +372,6 @@ class Character : public Being Script::Thread *getNpcThread() const { return mNpcThread; } - - /** - * Gets the way the actor is blocked by other things on the map - */ - virtual unsigned char getWalkMask() const - { return 0x82; } // blocked by walls and monsters ( bin 1000 0010) - /** Makes it impossible to chat for a while */ void mute(int seconds) { setTimerHard(T_C_MUTE, seconds * 10); } diff --git a/src/game-server/map.h b/src/game-server/map.h index 28faed7f..9f058fbf 100644 --- a/src/game-server/map.h +++ b/src/game-server/map.h @@ -72,7 +72,7 @@ class MapObject { } void addProperty(const std::string &key, const std::string &value) - { + { if (mProperties.contains(key)) LOG_WARN("Duplicate property " << key << " of object " << mName); @@ -178,7 +178,7 @@ class Map void setProperty(const std::string &key, const std::string &val) { mProperties[key] = val; } - /** + /** * Adds an object. */ void addObject(MapObject *object) @@ -198,7 +198,6 @@ class Map unsigned char walkmask, int maxCost = 20) const; - private: /** * Blockmasks for different entities */ @@ -206,6 +205,7 @@ class Map static const unsigned char BLOCKMASK_CHARACTER = 0x01;// = bin 0000 0001 static const unsigned char BLOCKMASK_MONSTER = 0x02; // = bin 0000 0010 + private: // map properties int mWidth, mHeight; int mTileWidth, mTileHeight; diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 1e68892d..0bee4c9a 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -26,6 +26,7 @@ #include "game-server/character.h" #include "game-server/collisiondetection.h" #include "game-server/item.h" +#include "game-server/map.h" #include "game-server/mapcomposite.h" #include "game-server/state.h" #include "scripting/scriptmanager.h" @@ -55,6 +56,8 @@ Monster::Monster(MonsterClass *specy): { LOG_DEBUG("Monster spawned! (id: " << mSpecy->getId() << ")."); + setWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER); + /* * Initialise the attribute structures. */ diff --git a/src/game-server/monster.h b/src/game-server/monster.h index 5ccabfa9..0ece89ab 100644 --- a/src/game-server/monster.h +++ b/src/game-server/monster.h @@ -323,15 +323,6 @@ class Monster : public Being void forgetTarget(Thing *being); /** - * Returns the way the actor is blocked by other things on the map. - */ - virtual unsigned char getWalkMask() const - { - // blocked walls, other monsters and players ( bin 1000 0011) - return 0x83; - } - - /** * Called when an attribute modifier is changed. * Recalculate the base value of an attribute and update derived * attributes if it has changed. diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp index 5583c3d5..82cd6a51 100644 --- a/src/game-server/npc.cpp +++ b/src/game-server/npc.cpp @@ -20,6 +20,7 @@ #include "game-server/character.h" #include "game-server/gamehandler.h" +#include "game-server/map.h" #include "game-server/npc.h" #include "net/messageout.h" #include "scripting/script.h" @@ -30,6 +31,8 @@ NPC::NPC(const std::string &name, int id): mID(id), mEnabled(true) { + setWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_MONSTER | + Map::BLOCKMASK_CHARACTER); setName(name); } diff --git a/src/game-server/npc.h b/src/game-server/npc.h index f62f72c7..49dd4bfa 100644 --- a/src/game-server/npc.h +++ b/src/game-server/npc.h @@ -82,12 +82,6 @@ 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 diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 1b762f34..05d1aec8 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -38,6 +38,7 @@ extern "C" { #include "game-server/inventory.h" #include "game-server/item.h" #include "game-server/itemmanager.h" +#include "game-server/map.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" #include "game-server/monster.h" @@ -1159,6 +1160,45 @@ static int being_set_direction(lua_State *s) return 0; } +/* + * being_set_walkmask(Being*, string mask) + * Sets the walkmask of a being + */ +static int being_set_walkmask(lua_State *s) +{ + Being *being = checkBeing(s, 1); + const char *stringMask = luaL_checkstring(s, 2); + unsigned char mask = 0x00; + if (strchr(stringMask, 'w')) + mask |= Map::BLOCKMASK_WALL; + else if (strchr(stringMask, 'c')) + mask |= Map::BLOCKMASK_CHARACTER; + else if (strchr(stringMask, 'm')) + mask |= Map::BLOCKMASK_MONSTER; + being->setWalkMask(mask); + return 0; +} + +/** + * being_get_walkmask(Being*): string + * Returns the walkmask of a being + */ +static int being_get_walkmask(lua_State *s) +{ + Being *being = checkBeing(s, 1); + const unsigned char mask = being->getWalkMask(); + luaL_Buffer buffer; + luaL_buffinit(s, &buffer); + if (mask & Map::BLOCKMASK_WALL) + luaL_addstring(&buffer, "w"); + if (mask & Map::BLOCKMASK_CHARACTER) + luaL_addstring(&buffer, "c"); + if (mask & Map::BLOCKMASK_MONSTER) + luaL_addstring(&buffer, "m"); + luaL_pushresult(&buffer); + return 1; +} + /** * posX(Being*): int xcoord * Function for getting the x-coordinate of the position of a being. @@ -2212,6 +2252,8 @@ LuaScript::LuaScript(): { "being_set_base_attribute", &being_set_base_attribute }, { "being_get_modified_attribute", &being_get_modified_attribute }, { "being_get_base_attribute", &being_get_base_attribute }, + { "being_set_walkmask", &being_set_walkmask }, + { "being_get_walkmask", &being_get_walkmask }, { "posX", &posX }, { "posY", &posY }, { "trigger_create", &trigger_create }, |