From b869552cade5f1b977c29322acfeb06f9a4f34d9 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 22 Oct 2010 04:48:24 +0000 Subject: [PATCH] - a little bit of fine tuning the new unit harvesting logic, now units are more intelligent about how they harvest (both AI and Human players) --- source/glest_game/world/map.cpp | 28 +----------------------- source/glest_game/world/unit_updater.cpp | 6 +++-- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 88a93742..17d0e530 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -273,38 +273,12 @@ bool Map::isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resour // Look for another unit that is currently harvesting the same resource // type right now - /* This should not be needed due to the check below - * - for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) { - Unit *peerUnit = unit->getFaction()->getUnit(i); - if( peerUnit != NULL && peerUnit->getId() != unit->getId() && - peerUnit->getType()->getSize() <= unit->getType()->getSize()) { - if( peerUnit->getCurrSkill() != NULL && - peerUnit->getCurrSkill()->getClass() == scHarvest && - peerUnit->getLoadType() == rt && - peerUnit->getCurrCommand() != NULL) { - - if(unit->getPos().dist(peerUnit->getCurrCommand()->getPos()) <= 40) { - if( i == 0 || - (unit->getPos().dist(peerUnit->getCurrCommand()->getPos()) < unit->getPos().dist(resourcePos))) { - resourcePos = peerUnit->getCurrCommand()->getPos(); - } - if(unit->getPos().dist(peerUnit->getCurrCommand()->getPos()) <= 5) { - return true; - } - } - } - } - } - */ - - // Check the faction cache for a known position where we can harvest // this resource type Vec2i result = unit->getFaction()->getClosestResourceTypeTargetFromCache(unit, rt); if(result.x >= 0) { resourcePos = result; - if(unit->getPos().dist(resourcePos) <= 5) { + if(unit->getPos().dist(resourcePos) <= size) { return true; } } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 71e835c1..b84b1021 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -657,11 +657,13 @@ void UnitUpdater::updateHarvest(Unit *unit) { throw runtime_error("detected unsupported pathfinder type!"); } - if(wasStuck == true && unit->isAlive() == true) { + // If the unit is blocked or Even worse 'stuck' then try to + // find the same resource type elsewhere, but close by + if((wasStuck == true || tsValue == tsBlocked) && unit->isAlive() == true) { switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: { - bool isNearResource = map->isResourceNear(unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit); + bool isNearResource = map->isResourceNear(unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit,true); if(isNearResource == true) { if((unit->getPos().dist(command->getPos()) < harvestDistance || unit->getPos().dist(targetPos) < harvestDistance) && isNearResource == true) { canHarvestDestPos = true;