mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- added to the faction resource cache pool for even better AI discovery of resources
This commit is contained in:
parent
ae367fb252
commit
07fe6a2196
@ -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) {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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){
|
||||
|
Loading…
x
Reference in New Issue
Block a user