diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index aa81b3cc..d35c398a 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -615,6 +615,23 @@ void Faction::removeResourceTargetFromCache(const Vec2i &pos) { cleanupResourceTypeTargetCache(); } +void Faction::addCloseResourceTargetToCache(const Vec2i &pos) { + const Map *map = world->getMap(); + const int harvestDistance = 5; + for(int j = -harvestDistance; j <= harvestDistance; ++j) { + for(int k = -harvestDistance; k <= harvestDistance; ++k) { + Vec2i newPos = pos + Vec2i(j,k); + if(map->isInside(newPos.x, newPos.y)) { + Resource *r= map->getSurfaceCell(map->toSurfCoords(newPos))->getResource(); + if(r != NULL) { + addResourceTargetToCache(newPos); + } + } + } + } +} + + Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type) { Vec2i result(-1); if(cacheResourceTargetList.size() > 0) { diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index 90646333..dbf15c15 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -158,6 +158,7 @@ public: void addResourceTargetToCache(const Vec2i &pos); void removeResourceTargetFromCache(const Vec2i &pos); + void addCloseResourceTargetToCache(const Vec2i &pos); Vec2i getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type); void cleanupResourceTypeTargetCache(); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index b4c28594..a94cecaf 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -521,6 +521,8 @@ void World::moveUnitCells(Unit *unit){ map.clearUnitCells(unit, unit->getPos()); map.putUnitCells(unit, newPos); } + // Add resources close by to the faction's cache + unit->getFaction()->addCloseResourceTargetToCache(newPos); //water splash if(tileset.getWaterEffects() && unit->getCurrField()==fLand){