From 2ed7628fb900f14b03cbf2843d0e0d4f301d7484 Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Mon, 10 Sep 2007 09:19:19 +0000 Subject: Spawn rate and limit are now read from map files and really fixed size of spawn area. --- src/game-server/mapreader.cpp | 12 +++++++++++- src/game-server/spawnarea.cpp | 25 ++++++++++++++++++------- src/game-server/spawnarea.hpp | 3 ++- 3 files changed, 31 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index 0033264c..9c062cb5 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -240,6 +240,8 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp else if (objType == "SPAWN") { int monsterId = -1; + int maxBeings = 10; // Default value + int spawnRate = 10; // Default value for_each_xml_child_node(propertiesNode, objectNode) { @@ -256,6 +258,14 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp { monsterId = atoi((const char *)propertyNode->xmlChildrenNode->content); } + else if (XML::getProperty(propertyNode, "name", std::string()) == "MAX_BEINGS") + { + maxBeings = atoi((const char *)propertyNode->xmlChildrenNode->content); + } + else if (XML::getProperty(propertyNode, "name", std::string()) == "SPAWN_RATE") + { + spawnRate = atoi((const char *)propertyNode->xmlChildrenNode->content); + } } } } @@ -263,7 +273,7 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp MonsterClass *monster = MonsterManager::getMonster(monsterId); if (monster != NULL) { - things.push_back(new SpawnArea(composite, monster, rect)); + things.push_back(new SpawnArea(composite, monster, rect, maxBeings, spawnRate)); } else { diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp index 5cc1f39f..fc6e40cd 100644 --- a/src/game-server/spawnarea.cpp +++ b/src/game-server/spawnarea.cpp @@ -39,13 +39,13 @@ struct SpawnAreaEventDispatch: EventDispatch static SpawnAreaEventDispatch spawnAreaEventDispatch; -SpawnArea::SpawnArea(MapComposite *map, MonsterClass *specy, const Rectangle &zone): +SpawnArea::SpawnArea(MapComposite *map, MonsterClass *specy, const Rectangle &zone, int maxBeings, int spawnRate): Thing(OBJECT_OTHER, map), mSpecy(specy), mSpawnedListener(&spawnAreaEventDispatch), mZone(zone), - mMaxBeings(10), - mSpawnRate(10), + mMaxBeings(maxBeings), + mSpawnRate(spawnRate), mNumBeings(0), mNextSpawn(0) { @@ -65,12 +65,23 @@ SpawnArea::update() Point position; MapComposite *map = getMap(); Map *realMap = map->getMap(); - int width = mZone.w == 0 ? realMap->getWidth() : mZone.w; - int height = mZone.h == 0 ? realMap->getHeight() : mZone.h; + int x = mZone.x; + int y = mZone.y; + int width = mZone.w; + int height = mZone.h; + + // Reset the spawn area to the whole map in case of dimensionless zone + if (width == 0 || height == 0) + { + x = 0; + y = 0; + width = realMap->getWidth() * 32; + height = realMap->getHeight() * 32; + } + do { - position = Point(mZone.x + rand() % width, - mZone.y + rand() % height); + position = Point(x + rand() % width, y + rand() % height); c--; } while (!realMap->getWalk(position.x / 32, position.y / 32) && c); diff --git a/src/game-server/spawnarea.hpp b/src/game-server/spawnarea.hpp index a565890d..7d596841 100644 --- a/src/game-server/spawnarea.hpp +++ b/src/game-server/spawnarea.hpp @@ -38,7 +38,8 @@ class MonsterClass; class SpawnArea : public Thing { public: - SpawnArea(MapComposite *, MonsterClass *, Rectangle const &zone); + SpawnArea(MapComposite *, MonsterClass *, Rectangle const &zone, + int maxBeings, int spawnRate); void update(); -- cgit v1.2.3-70-g09d2