From a4fa031fb36683667f17d4824293ff27ddca7a7a Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 5 May 2013 10:31:57 +0200 Subject: Removed the hardcoded monster AI --- src/game-server/monster.cpp | 76 +-------------------------------------------- 1 file changed, 1 insertion(+), 75 deletions(-) (limited to 'src/game-server/monster.cpp') 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 -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(); // 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()->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()->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()->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); -- cgit