summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-03-17 21:56:00 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2012-03-17 23:40:12 +0100
commita6c3eed2b9a91e9768ec6ce137879cac13703dea (patch)
treeb85bd802a6169dfd2e99f99d3150004d7e90e6a0 /src
parentf98ba725442348584810c089111501a07ac59905 (diff)
downloadmanaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.tar.gz
manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.tar.bz2
manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.tar.xz
manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.zip
Added map update function, moved schedules there to keep map context
Reviewed-by: bjorn.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/mapcomposite.cpp30
-rw-r--r--src/game-server/mapcomposite.h4
-rw-r--r--src/game-server/state.cpp30
-rw-r--r--src/scripting/lua.cpp17
4 files changed, 50 insertions, 31 deletions
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 6b2b74f9..7d377d18 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -457,6 +457,7 @@ MapZone& MapContent::getZone(const Point &pos) const
*****************************************************************************/
Script::Ref MapComposite::mInitializeCallback;
+Script::Ref MapComposite::mUpdateCallback;
MapComposite::MapComposite(int id, const std::string &name):
mMap(NULL),
@@ -607,6 +608,35 @@ void MapComposite::remove(Thing *ptr)
void MapComposite::update()
{
+ // Update object status
+ const std::vector< Thing * > &things = getEverything();
+ for (std::vector< Thing * >::const_iterator it = things.begin(),
+ it_end = things.end(); it != it_end; ++it)
+ {
+ (*it)->update();
+ }
+
+ if (mUpdateCallback.isValid())
+ {
+ Script *s = ScriptManager::currentState();
+ s->setMap(this);
+ s->prepare(mUpdateCallback);
+ s->push(mID);
+ s->execute();
+ }
+
+ // Perform actions
+ for (BeingIterator it(getWholeMapIterator()); it; ++it)
+ {
+ (*it)->perform();
+ }
+
+ // Move objects around and update zones.
+ for (BeingIterator it(getWholeMapIterator()); it; ++it)
+ {
+ (*it)->move();
+ }
+
for (int i = 0; i < mContent->mapHeight * mContent->mapWidth; ++i)
{
mContent->zones[i].destinations.clear();
diff --git a/src/game-server/mapcomposite.h b/src/game-server/mapcomposite.h
index 15310a97..96939a9c 100644
--- a/src/game-server/mapcomposite.h
+++ b/src/game-server/mapcomposite.h
@@ -356,6 +356,9 @@ class MapComposite
static void setInitializeCallback(Script *script)
{ script->assignCallback(mInitializeCallback); }
+ static void setUpdateCallback(Script *script)
+ { script->assignCallback(mUpdateCallback); }
+
private:
MapComposite(const MapComposite &);
@@ -374,6 +377,7 @@ class MapComposite
std::map<const std::string, Script::Ref> mWorldVariableCallbacks;
static Script::Ref mInitializeCallback;
+ static Script::Ref mUpdateCallback;
};
#endif
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index 34ede681..0e7bea25 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -70,34 +70,6 @@ static DelayedEvents delayedEvents;
*/
static std::map< std::string, std::string > mScriptVariables;
-
-/**
- * Updates object states on the map.
- */
-static void updateMap(MapComposite *map)
-{
- // Update object status
- const std::vector< Thing * > &things = map->getEverything();
- for (std::vector< Thing * >::const_iterator it = things.begin(),
- it_end = things.end(); it != it_end; ++it)
- {
- (*it)->update();
- }
-
- // Perform actions
- for (BeingIterator it(map->getWholeMapIterator()); it; ++it)
- {
- (*it)->perform();
- }
-
- // Move objects around and update zones.
- for (BeingIterator it(map->getWholeMapIterator()); it; ++it)
- {
- (*it)->move();
- }
- map->update();
-}
-
/**
* Sets message fields describing character look.
*/
@@ -456,7 +428,7 @@ void GameState::update(int worldTime)
if (!map->isActive())
continue;
- updateMap(map);
+ map->update();
for (CharacterIterator p(map->getWholeMapIterator()); p; ++p)
{
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index c5ab16ff..136350da 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -168,6 +168,13 @@ static int on_worldvar_changed(lua_State *s)
return 0;
}
+static int on_mapupdate(lua_State *s)
+{
+ luaL_checktype(s, 1, LUA_TFUNCTION);
+ MapComposite::setUpdateCallback(getScript(s));
+ return 0;
+}
+
static int get_item_class(lua_State *s)
{
LuaItemClass::push(s, checkItemClass(s, 1));
@@ -1921,8 +1928,13 @@ static int test_tableget(lua_State *s)
*/
static int get_map_id(lua_State *s)
{
- MapComposite *m = checkCurrentMap(s);
- lua_pushinteger(s, m->getID());
+ Script *script = getScript(s);
+
+ if (MapComposite *mapComposite = script->getMap())
+ lua_pushinteger(s, mapComposite->getID());
+ else
+ lua_pushnil(s);
+
return 1;
}
@@ -2232,6 +2244,7 @@ LuaScript::LuaScript():
{ "on_get_special_recharge_cost", &on_get_special_recharge_cost },
{ "on_mapvar_changed", &on_mapvar_changed },
{ "on_worldvar_changed", &on_worldvar_changed },
+ { "on_mapupdate", &on_mapupdate },
{ "get_item_class", &get_item_class },
{ "get_monster_class", &get_monster_class },
{ "get_status_effect", &get_status_effect },