summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-05-05 10:31:57 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-05-11 23:31:16 +0200
commita4fa031fb36683667f17d4824293ff27ddca7a7a (patch)
tree24bb27f71efbafc1eca88a834df250e102d00c6e
parentf81fae399d1c3a527744c20e4bc49fb487dbb0cf (diff)
downloadmanaserv-a4fa031fb36683667f17d4824293ff27ddca7a7a.tar.gz
manaserv-a4fa031fb36683667f17d4824293ff27ddca7a7a.tar.xz
manaserv-a4fa031fb36683667f17d4824293ff27ddca7a7a.zip
Removed the hardcoded monster AI
-rw-r--r--example/monsters.xml28
-rw-r--r--src/game-server/monster.cpp76
-rw-r--r--src/game-server/monster.h100
-rw-r--r--src/game-server/monstermanager.cpp27
4 files changed, 1 insertions, 230 deletions
diff --git a/example/monsters.xml b/example/monsters.xml
index f577c69..0a4e779 100644
--- a/example/monsters.xml
+++ b/example/monsters.xml
@@ -23,7 +23,6 @@ attributes <TAG>: Tells all the monsters attribute. These attribute, as for ite
(A tile is the smallest square map unit: by default, a tile is 32 pixel long.)
mutation[integer]: The mutation indicates the amplitude in percent where attributes get modified with.
For instance, with a mutation of 50, each attribute can be altered to become 100% to 149% of what they are.
-vulnerability<TAG>: Tells the monster specific vulnerability to an element.
element[string]: Tells to which element the weakness is. ('fire', 'earth', 'ice', 'metal' are some examples.)
factor[float]: Tells the defense against an element is reduced in percent. (A value of 0.7 indicates that the defense is lowered by 30%).
exp<TAG>: Tells how much experience point a monster is giving upon victory.
@@ -52,17 +51,8 @@ exp<TAG>: Tells how much experience point a monster is giving up
magical-defence="0"
mutation="50"
/>
- <vulnerability element="fire" factor="10"/>
- <vulnerability element="earth" factor="0.7"/>
<exp>10</exp>
<!-- average stroll- and track range-->
- <behavior
- aggressive="false"
- cowardly="false"
- track-range="5"
- stroll-range="32"
- attack-distance="32"
- />
</monster>
<monster id="2" name="Scorpion">
@@ -121,15 +111,6 @@ exp<TAG>: Tells how much experience point a monster is giving up
magical-defence="0"
gender="female"
/>
- <!-- also quite lazy when unprovoked but much more territorial
- than the normal one-->
- <behavior
- aggressive="true"
- cowardly="false"
- track-range="6"
- stroll-range="32"
- attack-distance="64"
- />
</monster>
<monster id="4" name="Green Slime">
@@ -153,15 +134,6 @@ exp<TAG>: Tells how much experience point a monster is giving up
physical-defence="0"
magical-defence="0"
/>
- <!-- Is fulfilling some unknown purpose that requires it to move around
- a lot and leaves no time for pursing attackers -->
- <behavior
- aggressive="false"
- cowardly="false"
- track-range="4"
- stroll-range="24"
- />
</monster>
-
</monsters>
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 45a99d8..1c4f39b 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -35,17 +35,8 @@
#include <cmath>
-double MonsterClass::getVulnerability(Element element) const
-{
- Vulnerabilities::const_iterator it = mVulnerabilities.find(element);
- if (it == mVulnerabilities.end())
- return 1.0f;
- return it->second;
-}
-
MonsterComponent::MonsterComponent(Entity &entity, MonsterClass *specy):
- mSpecy(specy),
- mOwner(nullptr)
+ mSpecy(specy)
{
LOG_DEBUG("Monster spawned! (id: " << mSpecy->getId() << ").");
@@ -96,16 +87,8 @@ MonsterComponent::MonsterComponent(Entity &entity, MonsterClass *specy):
beingComponent->signal_died.connect(sigc::mem_fun(this,
&MonsterComponent::monsterDied));
}
-
-MonsterComponent::~MonsterComponent()
-{
-}
-
void MonsterComponent::update(Entity &entity)
{
- if (mKillStealProtectedTimeout.justFinished())
- mOwner = nullptr;
-
auto *beingComponent = entity.getComponent<BeingComponent>();
// If dead, remove it
@@ -124,65 +107,8 @@ void MonsterComponent::update(Entity &entity)
script->push(&entity);
script->execute(entity.getMap());
}
-
- const Point &position =
- entity.getComponent<ActorComponent>()->getPosition();
-
- // We have no target - let's wander around
- if (mStrollTimeout.expired() &&
- position == beingComponent->getDestination())
- {
- if (mKillStealProtectedTimeout.expired())
- {
- unsigned range = mSpecy->getStrollRange();
- if (range)
- {
- Point randomPos(rand() % (range * 2 + 1) - range + position.x,
- rand() % (range * 2 + 1) - range + position.y);
- // Don't allow negative destinations, to avoid rounding
- // problems when divided by tile size
- if (randomPos.x >= 0 && randomPos.y >= 0)
- beingComponent->setDestination(entity, randomPos);
- }
- mStrollTimeout.set(10 + rand() % 10);
- }
- }
}
-int MonsterComponent::calculatePositionPriority(Entity &entity,
- Point position,
- int targetPriority)
-{
- Point thisPos = entity.getComponent<ActorComponent>()->getPosition();
-
- unsigned range = mSpecy->getTrackRange();
-
- Map *map = entity.getMap()->getMap();
- int tileWidth = map->getTileWidth();
- int tileHeight = map->getTileHeight();
-
- // Check if we already are on this position
- if (thisPos.x / tileWidth == position.x / tileWidth &&
- thisPos.y / tileHeight == position.y / tileHeight)
- {
- return targetPriority *= range;
- }
-
- Path path;
- path = map->findPath(thisPos.x / tileWidth, thisPos.y / tileHeight,
- position.x / tileWidth, position.y / tileHeight,
- entity.getComponent<ActorComponent>()->getWalkMask(),
- range);
-
- if (path.empty() || path.size() >= range)
- {
- return 0;
- }
- else
- {
- return targetPriority * (range - path.size());
- }
-}
void MonsterComponent::monsterDied(Entity *monster)
{
mDecayTimeout.set(DECAY_TIME);
diff --git a/src/game-server/monster.h b/src/game-server/monster.h
index 9854a7a..434e170 100644
--- a/src/game-server/monster.h
+++ b/src/game-server/monster.h
@@ -68,11 +68,7 @@ class MonsterClass
mSpeed(1),
mSize(16),
mExp(-1),
- mAggressive(false),
- mTrackRange(1),
- mStrollRange(0),
mMutation(0),
- mAttackDistance(0),
mOptimalLevel(0)
{}
@@ -146,61 +142,21 @@ class MonsterClass
/** Sets maximum skill level after which exp reward is reduced. */
int getOptimalLevel() const { return mOptimalLevel; }
- /** Sets if the monster attacks without being attacked first. */
- void setAggressive(bool aggressive) { mAggressive = aggressive; }
-
- /** Returns if the monster attacks without being attacked first. */
- bool isAggressive() const { return mAggressive; }
-
- /** Sets range in tiles in which the monster searches for enemies. */
- void setTrackRange(unsigned range){ mTrackRange = range; }
-
- /**
- * Returns range in tiles in which the monster searches for enemies.
- */
- unsigned getTrackRange() const { return mTrackRange; }
-
- /** Sets range in pixels in which the monster moves around when idle. */
- void setStrollRange(unsigned range) { mStrollRange = range; }
-
- /**
- * Returns range in pixels in which the monster moves around when idle.
- */
- unsigned getStrollRange() const { return mStrollRange; }
-
/** Sets mutation factor in percent. */
void setMutation(unsigned factor) { mMutation = factor; }
/** Returns mutation factor in percent. */
unsigned getMutation() const { return mMutation; }
- /** Sets preferred combat distance in pixels. */
- void setAttackDistance(unsigned distance)
- { mAttackDistance = distance; }
-
- /** Returns preferred combat distance in pixels. */
- unsigned getAttackDistance() const { return mAttackDistance; }
-
- void setVulnerability(Element element, double factor)
- { mVulnerabilities[element] = factor; }
-
- double getVulnerability(Element element) const;
-
void addAbility(AbilityManager::AbilityInfo *info);
const std::set<AbilityManager::AbilityInfo *> &getAbilities() const;
void setUpdateCallback(Script *script)
{ script->assignCallback(mUpdateCallback); }
- void setDamageCallback(Script *script)
- { script->assignCallback(mDamageCallback); }
-
Script::Ref getUpdateCallback() const
{ return mUpdateCallback; }
- Script::Ref getDamageCallback() const
- { return mDamageCallback; }
-
private:
unsigned short mId;
std::string mName;
@@ -213,24 +169,14 @@ class MonsterClass
int mSize;
int mExp;
- bool mAggressive;
- int mTrackRange;
- int mStrollRange;
int mMutation;
- int mAttackDistance;
int mOptimalLevel;
- Vulnerabilities mVulnerabilities;
/**
* A reference to the script function that is called each update.
*/
Script::Ref mUpdateCallback;
- /**
- * A reference to the script that is called when a mob takes damage.
- */
- Script::Ref mDamageCallback;
-
friend class MonsterManager;
friend class MonsterComponent;
};
@@ -243,11 +189,7 @@ class MonsterComponent : public Component
public:
static const ComponentType type = CT_Monster;
- /** Time in game ticks until ownership of a monster can change. */
- static const int KILLSTEAL_PROTECTION_TIME = 100;
-
MonsterComponent(Entity &entity, MonsterClass *);
- ~MonsterComponent();
/**
* Returns monster specy.
@@ -265,53 +207,11 @@ class MonsterComponent : public Component
*/
void monsterDied(Entity *monster);
- /**
- * Alters hate for the monster
- */
- void changeAnger(Entity *target, int amount);
-
- std::map<Entity *, int> getAngerList() const;
-
- /**
- * Removes a being from the anger list.
- */
- void forgetTarget(Entity *entity);
-
private:
static const int DECAY_TIME = 50;
- int calculatePositionPriority(Entity &entity,
- Point position,
- int targetPriority);
-
MonsterClass *mSpecy;
- /** Aggression towards other beings. */
- struct AggressionInfo {
- AggressionInfo()
- : anger(0)
- {}
-
- int anger;
- sigc::connection removedConnection;
- sigc::connection diedConnection;
- };
-
- /**
- * Character who currently owns this monster (killsteal protection).
- */
- Entity *mOwner;
-
- /**
- * List of characters who are entitled to receive exp (killsteal
- * protection).
- */
- std::set<Entity *> mLegalExpReceivers;
-
- /** Time until monster strolls to new location */
- Timeout mStrollTimeout;
- /** Kill steal protection time */
- Timeout mKillStealProtectedTimeout;
/** Time until dead monster is removed */
Timeout mDecayTimeout;
};
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index 19e196e..9a907e7 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -107,7 +107,6 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
MonsterDrops drops;
bool attributesSet = false;
- bool behaviorSet = false;
for_each_xml_child_node(subnode, node)
{
@@ -266,26 +265,6 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
monster->setExp(atoi((const char*)exp));
monster->setOptimalLevel(XML::getProperty(subnode, "level", 0));
}
- else if (xmlStrEqual(subnode->name, BAD_CAST "behavior"))
- {
- behaviorSet = true;
- if (XML::getBoolProperty(subnode, "aggressive", false))
- monster->setAggressive(true);
-
- monster->setTrackRange(
- XML::getProperty(subnode, "track-range", 1));
- monster->setStrollRange(
- XML::getProperty(subnode, "stroll-range", 0));
- monster->setAttackDistance(
- XML::getProperty(subnode, "attack-distance", 0));
- }
- else if (xmlStrEqual(subnode->name, BAD_CAST "vulnerability"))
- {
- Element element = elementFromString(
- XML::getProperty(subnode, "element", std::string()));
- double factor = XML::getFloatProperty(subnode, "factor", 1.0);
- monster->setVulnerability(element, factor);
- }
}
monster->setDrops(drops);
@@ -295,12 +274,6 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
<< ": No attributes defined for monster Id:" << id
<< " (" << name << ")");
}
- if (!behaviorSet)
- {
- LOG_WARN(filename
- << ": No behavior defined for monster Id:" << id
- << " (" << name << ")");
- }
if (monster->getExp() == -1)
{
LOG_WARN(filename