- added to the faction resource cache pool for even better AI discovery of resources

This commit is contained in:
Mark Vejvoda 2010-10-21 20:31:09 +00:00
parent ae367fb252
commit 07fe6a2196
3 changed files with 20 additions and 0 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -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){