- 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)
This commit is contained in:
parent
cf5164d5ce
commit
b869552cad
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue