From f03e1cb4ce24e92fa3756d7b9aa9131853783810 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Mon, 11 Feb 2008 23:42:48 +0000 Subject: Implemented getting size and speed from monster.xml --- src/game-server/monster.cpp | 24 +++++++++++++---------- src/game-server/monster.hpp | 40 +++++++++++++++----------------------- src/game-server/monstermanager.cpp | 20 +++++++++++++++++-- 3 files changed, 48 insertions(+), 36 deletions(-) (limited to 'src/game-server') 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 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 #"<setSpeed(1000/speed); + } else if (xmlStrEqual(subnode->name, BAD_CAST "exp")) { -- cgit v1.2.3-60-g2f50