diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/game-server/spawnarea.cpp | 41 | ||||
-rw-r--r-- | src/game-server/spawnarea.hpp | 1 |
3 files changed, 29 insertions, 15 deletions
@@ -17,6 +17,8 @@ src/game-server/deathlistener.hpp: Added a DeathListener interface, which the SpawnArea now uses to get notified about dying beings, so that it knows when to spawn more. + * src/game-server/spawnarea.cpp, src/game-server/spawnarea.hpp: Took + into account spawn rate. 2007-03-30 Bjørn Lindeijer <bjorn@lindeijer.nl> diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp index 9d7a4eb2..bded9cc0 100644 --- a/src/game-server/spawnarea.cpp +++ b/src/game-server/spawnarea.cpp @@ -29,7 +29,6 @@ #include "utils/logger.h" /* - * TODO: Take into account spawn rate. * TODO: Allow specifying being type and use it. */ @@ -39,7 +38,8 @@ SpawnArea::SpawnArea(int mapId, const Rectangle &zone): mMaxBeings(10), mBeingType(1), mSpawnRate(10), - mNumBeings(0) + mNumBeings(0), + mNextSpawn(0) { setMapId(mapId); } @@ -47,23 +47,34 @@ SpawnArea::SpawnArea(int mapId, const Rectangle &zone): void SpawnArea::update() { - while (mNumBeings < mMaxBeings) + if (mNextSpawn > 0) { - Being *being = new Monster(); - being->addDeathListener(this); + mNextSpawn--; - // some bogus stats for testing - being->setSpeed(150); - being->setSize(8); - being->setAttribute(BASE_ATTR_VITALITY, 10); - being->fillHitpoints(); + if (mNextSpawn == 0) + { + Being *being = new Monster(); + being->addDeathListener(this); - being->setMapId(1); - being->setPosition(Point(mZone.x + rand() % mZone.w, - mZone.y + rand() % mZone.h)); - gameState->insert(being); + // 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(Point(mZone.x + rand() % mZone.w, + mZone.y + rand() % mZone.h)); + gameState->insert(being); + + mNumBeings++; + } + } + + if (mNextSpawn == 0 && mNumBeings < mMaxBeings && mSpawnRate > 0) + { + // Predictable respawn intervals (can be randomized later) + mNextSpawn = (10 * 60) / mSpawnRate; } } diff --git a/src/game-server/spawnarea.hpp b/src/game-server/spawnarea.hpp index fb293b53..1debb1b3 100644 --- a/src/game-server/spawnarea.hpp +++ b/src/game-server/spawnarea.hpp @@ -51,6 +51,7 @@ class SpawnArea : public Thing, public DeathListener int mBeingType; /**< Type of being that spawns in this area. */ int mSpawnRate; /**< Number of beings spawning per minute. */ int mNumBeings; /**< Current population of this area. */ + int mNextSpawn; /**< The time until next being spawn. */ }; #endif |