diff options
author | David Athay <ko2fan@gmail.com> | 2008-10-22 13:30:46 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-10-22 13:30:46 +0000 |
commit | dbc83dae37dff1338e1ee6358a0a8d10103278b0 (patch) | |
tree | 4ec1afd5c64c12dff53d9a5ad6b73e7d8689e0af | |
parent | f598952da95395759d6725bfa5778a66695f1d73 (diff) | |
download | manaserv-dbc83dae37dff1338e1ee6358a0a8d10103278b0.tar.gz manaserv-dbc83dae37dff1338e1ee6358a0a8d10103278b0.tar.bz2 manaserv-dbc83dae37dff1338e1ee6358a0a8d10103278b0.tar.xz manaserv-dbc83dae37dff1338e1ee6358a0a8d10103278b0.zip |
Added enabling and disabling NPCs.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/game-server/npc.cpp | 13 | ||||
-rw-r--r-- | src/game-server/npc.hpp | 6 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 34 |
4 files changed, 50 insertions, 5 deletions
@@ -3,6 +3,8 @@ * src/scripting/lua.cpp, src/game-server/mapcomposite.cpp, src/game-server/main-game.cpp: Fixed NPC id's starting from 0. Changed time between reconnection attempts. + * src/scripting/lua.cpp, src/game-server/npc.hpp, + src/game-server/npc.cpp: Added enabling and disabling NPCs. 2008-10-21 Roderic Morris <roderic@ccs.neu.edu> diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp index fd462c50..ce344a52 100644 --- a/src/game-server/npc.cpp +++ b/src/game-server/npc.cpp @@ -25,14 +25,19 @@ #include "scripting/script.hpp" NPC::NPC(const std::string &name, int id, Script *s): - Being(OBJECT_NPC, 65535), mScript(s), mID(id) + Being(OBJECT_NPC, 65535), mScript(s), mID(id), mEnabled(true) { setName(name); } +void NPC::enable(bool enabled) +{ + mEnabled = enabled; +} + void NPC::update() { - if (!mScript) return; + if (!mScript || !mEnabled) return; mScript->prepare("npc_update"); mScript->push(this); mScript->execute(); @@ -40,7 +45,7 @@ void NPC::update() void NPC::prompt(Character *ch, bool restart) { - if (!mScript) return; + if (!mScript || !mEnabled) return; mScript->prepare(restart ? "npc_start" : "npc_next"); mScript->push(this); mScript->push(ch); @@ -49,7 +54,7 @@ void NPC::prompt(Character *ch, bool restart) void NPC::select(Character *ch, int v) { - if (!mScript) return; + if (!mScript || !mEnabled) return; mScript->prepare("npc_choose"); mScript->push(this); mScript->push(ch); diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp index c4d8b384..cfcfa54a 100644 --- a/src/game-server/npc.hpp +++ b/src/game-server/npc.hpp @@ -39,6 +39,11 @@ class NPC : public Being void update(); /** + * Enables the NPC + */ + void enable(bool enabled); + + /** * Prompts NPC. */ void prompt(Character *, bool restart); @@ -71,6 +76,7 @@ class NPC : public Being private: Script *mScript; /**< Script describing NPC behavior. */ unsigned short mID; /**< ID of the NPC. */ + bool mEnabled; /**< Whether NPC is enabled */ }; #endif diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 09ac134e..846a43a1 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -217,6 +217,37 @@ static int LuaNpc_Create(lua_State *s) } /** + * Enable a NPC if it has previously disabled + */ +static int LuaNPC_Enable(lua_State *s) +{ + NPC *p = getNPC(s, 1); + if (p) + { + p->enable(true); + bool b = GameState::insert(p); + assert(b); (void)b; + } + + return 0; +} + +/** + * Disable a NPC + */ +static int LuaNPC_Disable(lua_State *s) +{ + NPC *p = getNPC(s, 1); + if (p) + { + p->enable(false); + GameState::remove(p); + } + + return 0; +} + +/** * Callback for warping a player to another place. * tmw.chr_warp(character, nil/int map, int x, int y) */ @@ -468,7 +499,6 @@ static int LuaBeing_Damage(lua_State *s) return 0; } - /** * Function for getting the x-coordinate of the position of a being */ @@ -781,6 +811,8 @@ LuaScript::LuaScript(): { "npc_message", &LuaNpc_Message }, { "npc_choice", &LuaNpc_Choice }, { "npc_trade", &LuaNpc_Trade }, + { "npc_enable", &LuaNPC_Enable }, + { "npc_disable", &LuaNPC_Disable }, { "chr_warp", &LuaChr_Warp }, { "chr_inv_change", &LuaChr_InvChange }, { "chr_inv_count", &LuaChr_InvCount }, |