diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-02-11 23:42:48 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-02-11 23:42:48 +0000 |
commit | f03e1cb4ce24e92fa3756d7b9aa9131853783810 (patch) | |
tree | 183c683de37783e42575f990d509b65cee0a44ab | |
parent | 504b008e264a3213d9802e52b984196ff348f814 (diff) | |
download | manaserv-f03e1cb4ce24e92fa3756d7b9aa9131853783810.tar.gz manaserv-f03e1cb4ce24e92fa3756d7b9aa9131853783810.tar.bz2 manaserv-f03e1cb4ce24e92fa3756d7b9aa9131853783810.tar.xz manaserv-f03e1cb4ce24e92fa3756d7b9aa9131853783810.zip |
Implemented getting size and speed from monster.xml
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 24 | ||||
-rw-r--r-- | src/game-server/monster.hpp | 40 | ||||
-rw-r--r-- | src/game-server/monstermanager.cpp | 20 |
4 files changed, 54 insertions, 36 deletions
@@ -1,3 +1,9 @@ +2008-02-12 Philipp Sehmisch <tmw@crushnet.org> + + * src/gameserver/monster.cpp, src/game-server/monster.hpp, + src/game-server/monstermanager.cpp: Monster speed and size is now read + from monsters.xml. + 2008-02-07 Philipp Sehmisch <tmw@crushnet.org> * src/game-server/monster.cpp, src/game-server/monster.hpp, diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 4cad2311..772942d5 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -72,14 +72,15 @@ Monster::Monster(MonsterClass *specy): setAttribute(i, specy->getAttribute(i)); } + setSpeed(specy->getSpeed()); + setSize(specy->getSize()); + // Some bogus stats for testing. // TODO: Get all this stuff from the monster database. mAttackPreDelay = 10; mAttackAftDelay = 10; mAttackRange = 32; mAttackAngle = 10; - setSpeed(300); - setSize(8); // Set positions relative to target from which the monster can attack mAttackPositions.push_back(AttackPosition(+32, 0, DIRECTION_LEFT)); @@ -226,16 +227,19 @@ void Monster::update() else { // We have no target - let's wander around - mCountDown--; - if (mCountDown <= 0) + if (getPosition() == getDestination()) { - unsigned range = mSpecy->getStrollRange(); - if (range) + mCountDown--; + if (mCountDown <= 0) { - Point randomPos(rand() % (range * 2) - range + getPosition().x, - rand() % (range * 2) - range + getPosition().y); - setDestination(randomPos); - mCountDown = 10 + rand() % 10; + unsigned range = mSpecy->getStrollRange(); + if (range) + { + Point randomPos(rand() % (range * 2) - range + getPosition().x, + rand() % (range * 2) - range + getPosition().y); + setDestination(randomPos); + mCountDown = 10 + rand() % 10; + } } } } diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp index 3b96c619..e93051b4 100644 --- a/src/game-server/monster.hpp +++ b/src/game-server/monster.hpp @@ -52,6 +52,8 @@ class MonsterClass MonsterClass(int id): mID(id), mAttributes(BASE_ATTR_NB, 0), + mSpeed(1), + mSize(16), mExp(-1), mAggressive(false), mTrackRange(1), @@ -82,35 +84,23 @@ class MonsterClass int getAttribute(size_t attribute) const { return mAttributes.at(attribute); } - /** - * Sets exp reward for killing the monster - */ - void setExp(int exp) - { mExp = exp; } - - /** - * Gets exp reward for killing the monster - */ - int getExp() const - { return mExp; } - - void setAggressive(bool aggressive) - { mAggressive = aggressive; } + void setSpeed(int speed) { mSpeed = speed; } /**< sets inverted movement speed*/ + int getSpeed() const { return mSpeed; } /**< gets inverted movement speed*/ - bool isAggressive() const - { return mAggressive; } + void setSize(int size) { mSize = size; } /**< sets hit circle radius*/ + int getSize() const { return mSize; } /**< gets hit circle radius*/ - void setTrackRange(int range) - { mTrackRange = range; } + void setExp(int exp) { mExp = exp; } /**< sets experience reward*/ + int getExp() const { return mExp; } /**< gets experience reward*/ - unsigned getTrackRange() const - { return mTrackRange; } + void setAggressive(bool aggressive) { mAggressive = aggressive; } /**< sets if the monster attacks without being attacked first*/ + bool isAggressive() const { return mAggressive; } /**< gets if the monster attacks without being attacked first*/ - void setStrollRange(int range) - { mStrollRange = range; } + void setTrackRange(int range){ mTrackRange = range; } /**< sets range in tiles in which the monster searches for enemies*/ + unsigned getTrackRange() const { return mTrackRange; } /**< gets range in tiles in which the monster searches for enemies*/ - unsigned getStrollRange() const - { return mStrollRange; } + void setStrollRange(int range) { mStrollRange = range; } /**< sets range in tiles in which the monster moves around when idled*/ + unsigned getStrollRange() const { return mStrollRange; } /**< gets range in tiles in which the monster moves around when idled*/ /** * Randomly selects a monster drop (may return NULL). @@ -121,6 +111,8 @@ class MonsterClass unsigned short mID; /**< ID of the monster class. */ MonsterDrops mDrops; /**< Items the monster drops when dying. */ std::vector<int> mAttributes; /**< Base attributes of the monster*/ + int mSpeed; /** (inverted) Movement speed of the monster */ + int mSize; /** Collision circle radius of the monster */ int mExp; /**< Exp reward for killing the monster */ bool mAggressive; /**< Does the monster attack without being provoked? */ unsigned mTrackRange; /**< Distance the monster tracks enemies in */ diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index c4bddfa3..ca823310 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -140,8 +140,8 @@ void MonsterManager::reload() XML::getProperty(subnode, "physical-defence", -1)); monster->setAttribute(BASE_ATTR_MAG_RES, XML::getProperty(subnode, "magical-defence", -1)); - // TODO: speed - // TODO: size + monster->setSize(XML::getProperty(subnode, "size", 0)); + int speed = (XML::getProperty(subnode, "speed", 0)); //check for completeness bool attributesComplete = true; @@ -153,8 +153,24 @@ void MonsterManager::reload() monster->setAttribute(i, 0); } } + if (monster->getSize() == 0) + { + monster->setSize(16); + attributesComplete = false; + } + if (speed == 0) + { + speed = 1; + attributesComplete = false; + } + if (!attributesComplete) LOG_WARN(monsterReferenceFile <<": Attributes incomplete for monster #"<<id); + + //for usability reasons we set the speed in the monsters.xml as tiles per second + //instead of miliseconds per tile. + monster->setSpeed(1000/speed); + } else if (xmlStrEqual(subnode->name, BAD_CAST "exp")) { |