summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-22 00:54:58 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-22 00:57:19 +0100
commitbfff42c853f39a7e25c82c9059b7a0af64fd7987 (patch)
treee6b4b500f0b950211922db069a26d0e21ccd5416 /src
parentef785e89cfbc234a9a6a620ab2fac58045259737 (diff)
downloadmanaserv-bfff42c853f39a7e25c82c9059b7a0af64fd7987.tar.gz
manaserv-bfff42c853f39a7e25c82c9059b7a0af64fd7987.tar.bz2
manaserv-bfff42c853f39a7e25c82c9059b7a0af64fd7987.tar.xz
manaserv-bfff42c853f39a7e25c82c9059b7a0af64fd7987.zip
Refuse to spawn dead monsters
The server now warns instead of spawning dead monsters. Since I threw the spawning code around a bit, I hope I didn't break it.
Diffstat (limited to 'src')
-rw-r--r--src/defines.h8
-rw-r--r--src/game-server/being.cpp1
-rw-r--r--src/game-server/map.hpp7
-rw-r--r--src/game-server/monster.hpp2
-rw-r--r--src/game-server/spawnarea.cpp81
5 files changed, 54 insertions, 45 deletions
diff --git a/src/defines.h b/src/defines.h
index 4bad3e9b..7ee92bdd 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -88,15 +88,21 @@ enum
};
/**
- * Enumerated type for communicated messages
+ * Enumerated type for communicated messages:
+ *
* - PAMSG_*: from client to account server
* - APMSG_*: from account server to client
* - PCMSG_*: from client to chat server
* - CPMSG_*: from chat server to client
* - PGMSG_*: from client to game server
* - GPMSG_*: from game server to client
+ *
* Components: B byte, W word, L long, S variable-size string
* C tile-based coordinates (B*3)
+ *
+ * Hosts: P (player's client), A (account server), C (char server),
+ * G (game server)
+ *
* TODO - Document specific error codes for each packet
*/
enum {
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index c07bff71..73aafe6a 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -310,7 +310,6 @@ int Being::getModifiedAttribute(int attr) const
void Being::update()
{
-
int oldHP = getModifiedAttribute(BASE_ATTR_HP);
int newHP = oldHP;
int maxHP = getAttribute(BASE_ATTR_HP);
diff --git a/src/game-server/map.hpp b/src/game-server/map.hpp
index c5fbb0d8..3a9badf9 100644
--- a/src/game-server/map.hpp
+++ b/src/game-server/map.hpp
@@ -108,14 +108,12 @@ class Map
/**
* Sets the size of the map. This will destroy any existing map data.
*/
- void
- setSize(int mWidth, int height);
+ void setSize(int mWidth, int height);
/**
* Get tile reference.
*/
- MetaTile*
- getMetaTile(int x, int y);
+ MetaTile *getMetaTile(int x, int y);
/**
* Marks a tile as occupied
@@ -178,7 +176,6 @@ class Map
// Pathfinding members
int onClosedList, onOpenList;
-
};
#endif
diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp
index a4eb421f..ab60fe0e 100644
--- a/src/game-server/monster.hpp
+++ b/src/game-server/monster.hpp
@@ -289,7 +289,7 @@ class Monster : public Being
/**
* Character who currently owns this monster (killsteal protection).
*/
- Character* mOwner;
+ Character *mOwner;
/**
* Time until someone else can claim this monster (killsteal
diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp
index f5de6f2b..db7a01d6 100644
--- a/src/game-server/spawnarea.cpp
+++ b/src/game-server/spawnarea.cpp
@@ -26,18 +26,23 @@
#include "game-server/state.hpp"
#include "utils/logger.h"
-struct SpawnAreaEventDispatch: EventDispatch
+struct SpawnAreaEventDispatch : EventDispatch
{
SpawnAreaEventDispatch()
{
- typedef EventListenerFactory< SpawnArea, &SpawnArea::mSpawnedListener > Factory;
+ 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, int maxBeings, int spawnRate):
+SpawnArea::SpawnArea(MapComposite *map,
+ MonsterClass *specy,
+ const Rectangle &zone,
+ int maxBeings,
+ int spawnRate):
Thing(OBJECT_OTHER, map),
mSpecy(specy),
mSpawnedListener(&spawnAreaEventDispatch),
@@ -49,46 +54,52 @@ SpawnArea::SpawnArea(MapComposite *map, MonsterClass *specy, const Rectangle &zo
{
}
-void
-SpawnArea::update()
+void SpawnArea::update()
{
if (mNextSpawn > 0)
- {
mNextSpawn--;
- if (mNextSpawn == 0)
+ if (mNextSpawn == 0 && mNumBeings < mMaxBeings && mSpawnRate > 0)
+ {
+ MapComposite *map = getMap();
+ const Map *realMap = map->getMap();
+
+ // Reset the spawn area to the whole map in case of dimensionless zone
+ if (mZone.w == 0 || mZone.h == 0)
{
- // Find a free spawn location. Give up after 10 tries
- int c = 10;
- Point position;
- MapComposite *map = getMap();
- Map *realMap = map->getMap();
- 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;
- }
+ mZone.x = 0;
+ mZone.y = 0;
+ mZone.w = realMap->getWidth() * realMap->getTileWidth();
+ mZone.h = realMap->getHeight() * realMap->getTileHeight();
+ }
+
+ // Find a free spawn location. Give up after 10 tries
+ int c = 10;
+ Point position;
+ const int x = mZone.x;
+ const int y = mZone.y;
+ const int width = mZone.w;
+ const int height = mZone.h;
- Being *being = new Monster(mSpecy);
+ Being *being = new Monster(mSpecy);
- do
- {
+ if (being->getModifiedAttribute(BASE_ATTR_HP) <= 0)
+ {
+ LOG_WARN("Refusing to spawn dead monster " << mSpecy->getType());
+ delete being;
+ being = 0;
+ }
+
+ if (being) {
+ do {
position = Point(x + rand() % width, y + rand() % height);
c--;
- } while (!realMap->getWalk(position.x / 32, position.y / 32, being->getWalkMask()) && c);
+ } while (!realMap->getWalk(position.x / realMap->getTileWidth(),
+ position.y / realMap->getTileHeight(),
+ being->getWalkMask()) && c);
- if (c)
- {
+ if (c) {
being->addListener(&mSpawnedListener);
-
being->setMap(map);
being->setPosition(position);
being->clearDestination();
@@ -96,8 +107,7 @@ SpawnArea::update()
mNumBeings++;
}
- else
- {
+ else {
LOG_WARN("Unable to find a free spawn location for monster "
<< mSpecy->getType() << " on map " << map->getName()
<< " (" << x << ',' << y << ','
@@ -105,10 +115,7 @@ SpawnArea::update()
delete being;
}
}
- }
- if (mNextSpawn == 0 && mNumBeings < mMaxBeings && mSpawnRate > 0)
- {
// Predictable respawn intervals (can be randomized later)
mNextSpawn = (10 * 60) / mSpawnRate;
}