diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-29 14:17:22 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-29 14:17:22 +0000 |
commit | 26b3e1094d85ef89c90376688000836c8ee43979 (patch) | |
tree | f934d936d7c8319e742e946a6bb5f37ab7289b30 /src/game-server/spawnarea.cpp | |
parent | b82bf7df7053a78d51706a5a017d61f564e4677e (diff) | |
download | manaserv-26b3e1094d85ef89c90376688000836c8ee43979.tar.gz manaserv-26b3e1094d85ef89c90376688000836c8ee43979.tar.bz2 manaserv-26b3e1094d85ef89c90376688000836c8ee43979.tar.xz manaserv-26b3e1094d85ef89c90376688000836c8ee43979.zip |
Replaced event system. Fixed race condition between quest variable recovery and character removal.
Diffstat (limited to 'src/game-server/spawnarea.cpp')
-rw-r--r-- | src/game-server/spawnarea.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp index 0f2ff595..63bdc904 100644 --- a/src/game-server/spawnarea.cpp +++ b/src/game-server/spawnarea.cpp @@ -21,21 +21,28 @@ * $Id$ */ -#include "spawnarea.hpp" +#include "game-server/spawnarea.hpp" #include "game-server/mapcomposite.hpp" #include "game-server/monster.hpp" #include "game-server/state.hpp" - #include "utils/logger.h" -/* - * TODO: Allow specifying being type and use it. - */ +struct SpawnAreaEventDispatch: EventDispatch +{ + SpawnAreaEventDispatch() + { + typedef EventListenerFactory< SpawnArea, &SpawnArea::mSpawnedListener > Factory; + removed = &Factory::create< Thing, &SpawnArea::decrease >::function; + } +}; + +static SpawnAreaEventDispatch spawnAreaEventDispatch; SpawnArea::SpawnArea(MapComposite *map, MonsterClass *specy, const Rectangle &zone): Thing(OBJECT_OTHER, map), mSpecy(specy), + mSpawnedListener(&spawnAreaEventDispatch), mZone(zone), mMaxBeings(10), mSpawnRate(10), @@ -68,7 +75,7 @@ SpawnArea::update() if (c) { Being *being = new Monster(mSpecy); - being->addDeathListener(this); + being->addListener(&mSpawnedListener); being->setMap(map); being->setPosition(position); @@ -94,8 +101,8 @@ SpawnArea::update() } } -void -SpawnArea::died(Being *being) +void SpawnArea::decrease(Thing *t) { - mNumBeings--; + --mNumBeings; + t->removeListener(&mSpawnedListener); } |