From a3e91f58e3aac2c35f70a74187fa2c242e59a647 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Wed, 13 Feb 2008 22:24:27 +0000 Subject: Implemented monster mutation. --- ChangeLog | 2 ++ src/game-server/monster.cpp | 10 +++++++++- src/game-server/monster.hpp | 13 +++++++++---- src/game-server/monstermanager.cpp | 12 +++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e954a788..adc9a7fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * src/game-server/monstermanager.cpp: Movement speed in monsters.xml is now interpreted as pixels per second instead of tiles per second. + * src/game-server/monster.cpp, src/game-server/monster.hpp, + src/game-server/monstermanager.cpp: Implemented monster mutation. 2008-02-12 Philipp Sehmisch 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 + 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 #"<setMutation(0); + } - //check for completeness bool attributesComplete = true; for (int i = BASE_ATTR_BEGIN; i < BASE_ATTR_END; i++) { -- cgit v1.2.3-60-g2f50