summaryrefslogtreecommitdiffstats
path: root/src/game-server/spawnarea.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2007-06-30 15:01:50 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2007-06-30 15:01:50 +0000
commitd7e84be1d3dc935f47cefc0f600ced74f37e46fb (patch)
treef535b6b4130994a9162c48f8c556b0dd5ddc9a5f /src/game-server/spawnarea.cpp
parentfd392c16c0a1236ca4ea124b5ebbd309df1c5064 (diff)
downloadmanaserv-d7e84be1d3dc935f47cefc0f600ced74f37e46fb.tar.gz
manaserv-d7e84be1d3dc935f47cefc0f600ced74f37e46fb.tar.xz
manaserv-d7e84be1d3dc935f47cefc0f600ced74f37e46fb.zip
Implemented basic monster AI and fixed a stability problem caused by the spawn areas.
Diffstat (limited to 'src/game-server/spawnarea.cpp')
-rw-r--r--src/game-server/spawnarea.cpp45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp
index 9d7687f..780e3e6 100644
--- a/src/game-server/spawnarea.cpp
+++ b/src/game-server/spawnarea.cpp
@@ -23,6 +23,7 @@
#include "spawnarea.hpp"
+#include "game-server/mapcomposite.hpp"
#include "game-server/monster.hpp"
#include "game-server/state.hpp"
@@ -53,22 +54,40 @@ SpawnArea::update()
if (mNextSpawn == 0)
{
- Being *being = new Monster();
- being->addDeathListener(this);
+ //find a free spawn location. Give up after 10 tries
+ int c = 10;
+ Point position;
+ do
+ {
+ position = Point(mZone.x + rand() % mZone.w,
+ mZone.y + rand() % mZone.h);
+ c--;
+ } while (! mMap->getMap()->getWalk(position.x / 32, position.y / 32)
+ && c);
- // some bogus stats for testing
- being->setSpeed(150);
- being->setSize(8);
- being->setAttribute(BASE_ATTR_VITALITY, 10);
- being->fillHitpoints();
+ if (c >= 0)
+ {
+ Being *being = new Monster();
+ being->addDeathListener(this);
- being->setMapId(1);
- being->setPosition(Point(mZone.x + rand() % mZone.w,
- mZone.y + rand() % mZone.h));
- DelayedEvent e = { EVENT_INSERT };
- gameState->enqueueEvent(being, e);
+ // some bogus stats for testing
+ being->setSpeed(150);
+ being->setSize(8);
+ being->setAttribute(BASE_ATTR_VITALITY, 10);
+ being->fillHitpoints();
- mNumBeings++;
+ being->setMapId(1);
+ being->setPosition(position);
+ DelayedEvent e = { EVENT_INSERT };
+ gameState->enqueueEvent(being, e);
+
+ mNumBeings++;
+ }
+ else {
+ //TODO: This log message should have more information when
+ // more flexibility is added to the spawn area
+ LOG_WARN("Unable to find a free spawn location for monster");
+ }
}
}