diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-02-13 22:24:27 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-02-13 22:24:27 +0000 |
commit | a3e91f58e3aac2c35f70a74187fa2c242e59a647 (patch) | |
tree | 03343668f1dc0c023b3ec256b9f6571056deaf8a /src | |
parent | f1c364583bc647e7697e564bdaefd41e0caf3017 (diff) | |
download | manaserv-a3e91f58e3aac2c35f70a74187fa2c242e59a647.tar.gz manaserv-a3e91f58e3aac2c35f70a74187fa2c242e59a647.tar.bz2 manaserv-a3e91f58e3aac2c35f70a74187fa2c242e59a647.tar.xz manaserv-a3e91f58e3aac2c35f70a74187fa2c242e59a647.zip |
Implemented monster mutation.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/monster.cpp | 10 | ||||
-rw-r--r-- | src/game-server/monster.hpp | 13 | ||||
-rw-r--r-- | src/game-server/monstermanager.cpp | 12 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 772942d5..4eb90483 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -28,6 +28,8 @@ #include "game-server/state.hpp" #include "utils/logger.h" +#include <cmath> + ItemClass *MonsterClass::getRandomDrop() const { int p = rand() / (RAND_MAX / 10000); @@ -67,9 +69,15 @@ Monster::Monster(MonsterClass *specy): LOG_DEBUG("Monster spawned!"); // get basic attributes from monster database + int mutation = specy->getMutation(); for (int i = BASE_ATTR_BEGIN; i < BASE_ATTR_END; i++) { - setAttribute(i, specy->getAttribute(i)); + float attr = (float)specy->getAttribute(i); + if (mutation) + { + attr *= (100 + (rand()%(mutation * 2)) - mutation) / 100.0f; + } + setAttribute(i, (int)std::ceil(attr)); } setSpeed(specy->getSpeed()); diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp index e93051b4..36dbbdc3 100644 --- a/src/game-server/monster.hpp +++ b/src/game-server/monster.hpp @@ -57,7 +57,8 @@ class MonsterClass mExp(-1), mAggressive(false), mTrackRange(1), - mStrollRange(0) + mStrollRange(0), + mMutation(0) {} /** @@ -96,12 +97,15 @@ class MonsterClass 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 setTrackRange(int range){ mTrackRange = range; } /**< sets range in tiles in which the monster searches for enemies*/ + void setTrackRange(unsigned 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*/ - void setStrollRange(int range) { mStrollRange = range; } /**< sets range in tiles in which the monster moves around when idled*/ + void setStrollRange(unsigned 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*/ + void setMutation(unsigned factor) { mMutation = factor; } /**< sets mutation factor in percent*/ + unsigned getMutation() const { return mMutation; } /**< gets mutation factor in percent*/ + /** * Randomly selects a monster drop (may return NULL). */ @@ -114,9 +118,10 @@ class MonsterClass 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? */ + bool mAggressive; /**< Does the monster attack without being provoked? */ unsigned mTrackRange; /**< Distance the monster tracks enemies in */ unsigned mStrollRange; /**< Distance the monster strolls around in when not fighting */ + unsigned mMutation; /**< Mutation factor in percent*/ }; /** diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index b56d263d..693cd53a 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -142,8 +142,18 @@ void MonsterManager::reload() XML::getProperty(subnode, "magical-defence", -1)); monster->setSize(XML::getProperty(subnode, "size", 0)); int speed = (XML::getProperty(subnode, "speed", 0)); + monster->setMutation(XML::getProperty(subnode, "mutation", 0)); + + //checking attributes for completeness and plausibility + + if (monster->getMutation() > 99) + { + LOG_WARN(monsterReferenceFile + <<": Mutation of monster #"<<id + <<" more than 99% - ignored"); + monster->setMutation(0); + } - //check for completeness bool attributesComplete = true; for (int i = BASE_ATTR_BEGIN; i < BASE_ATTR_END; i++) { |