Mega also scouts to random ressource places .Only first tech type ressource is used to navigate now (which is typically gold) more improvement needed regarding this aspect ;pathfinder back to 900

This commit is contained in:
Titus Tscharntke 2011-06-25 18:14:20 +00:00
parent 14b6f195e6
commit 105e639bd8
4 changed files with 90 additions and 10 deletions

View File

@ -424,21 +424,68 @@ Vec2i Ai::getRandomHomePosition(){
// ==================== actions ====================
void Ai::sendScoutPatrol(){
Vec2i pos;
int unit;
Vec2i pos;
int unit;
bool possibleTargetFound= false;
startLoc= (startLoc+1) % aiInterface->getMapMaxPlayers();
pos= aiInterface->getStartLocation(startLoc);
if((aiInterface->getControlType() == ctCpuMega || aiInterface->getControlType() == ctNetworkCpuMega)
&& random.randRange(0, 1) == 1)
{
Map *map= aiInterface->getMap();
if(aiInterface->getFactionIndex()!=startLoc){
if(findAbleUnit(&unit, ccAttack, false)){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
const TechTree *tt= aiInterface->getTechTree();
const ResourceType *rt= tt->getResourceType(0);
int tryCount= 0;
int height= map->getH();
int width= map->getW();
aiInterface->giveCommand(unit, ccAttack, pos);
aiInterface->printLog(2, "Scout patrol sent to: " + intToStr(pos.x)+","+intToStr(pos.y)+"\n");
for(int i= 0; i < tt->getResourceTypeCount(); ++i){
const ResourceType *rt_= tt->getResourceType(i);
const Resource *r= aiInterface->getResource(rt);
if(rt_->getClass() == rcTech){
rt=rt_;
break;
}
}
//printf("looking for resource %s\n",rt->getName().c_str());
while(possibleTargetFound == false){
tryCount++;
if(tryCount == 4){
//printf("no target found\n");
break;
}
pos= Vec2i(random.randRange(2, width - 2), random.randRange(2, height - 2));
if(map->isInside(pos) && map->isInsideSurface(map->toSurfCoords(pos))){
//printf("is inside map\n");
// find first resource in this area
Vec2i resPos;
if(aiInterface->isResourceInRegion(pos, rt, resPos, 20)){
// found a possible target.
pos= resPos;
//printf("lets try the new target\n");
possibleTargetFound= true;
break;
}
}
//else printf("is outside map\n");
}
}
if(possibleTargetFound == false){
startLoc= (startLoc + 1) % aiInterface->getMapMaxPlayers();
pos= aiInterface->getStartLocation(startLoc);
printf("och noe\n");
}
if(aiInterface->getHomeLocation() != pos){
if(findAbleUnit(&unit, ccAttack, false)){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled)
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
aiInterface->giveCommand(unit, ccAttack, pos);
aiInterface->printLog(2, "Scout patrol sent to: " + intToStr(pos.x) + "," + intToStr(pos.y) + "\n");
}
}
}
void Ai::massiveAttack(const Vec2i &pos, Field field, bool ultraAttack){

View File

@ -428,6 +428,38 @@ const TechTree *AiInterface::getTechTree(){
return world->getTechTree();
}
bool AiInterface::isResourceInRegion(const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, int range) const {
const Map *map= world->getMap();
RandomGen random;
int xi=1;
int xj=1;
if(random.randRange(0,1)==1){
xi=-1;
}
if(random.randRange(0,1)==1){
xj=-1;
}
for(int i = -range; i <= range; ++i) {
for(int j = -range; j <= range; ++j) {
int ii=xi*i;
int jj=xj*j;
if(map->isInside(pos.x + ii, pos.y + jj)) {
Resource *r= map->getSurfaceCell(map->toSurfCoords(Vec2i(pos.x + ii, pos.y + jj)))->getResource();
if(r != NULL) {
if(r->getType() == rt) {
resourcePos= pos + Vec2i(ii,jj);
return true;
}
}
}
}
}
return false;
}
//returns if there is a resource next to a unit, in "resourcePos" is stored the relative position of the resource
bool AiInterface::isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, Faction *faction, bool fallbackToPeersHarvestingSameResource) const {
const Map *map= world->getMap();

View File

@ -86,6 +86,7 @@ public:
const FactionType *getMyFactionType();
Faction *getMyFaction();
const TechTree *getTechTree();
bool isResourceInRegion(const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, int range) const;
bool isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, Faction *faction, bool fallbackToPeersHarvestingSameResource) const;
bool getNearestSightedResource(const ResourceType *rt, const Vec2i &pos, Vec2i &resultPos, bool usableResourceTypeOnly);
bool isAlly(const Unit *unit) const;

View File

@ -40,7 +40,7 @@ namespace Glest{ namespace Game{
const int PathFinder::maxFreeSearchRadius = 10;
//const int PathFinder::pathFindNodesMax= 400;
int PathFinder::pathFindNodesAbsoluteMax = 1500;
int PathFinder::pathFindNodesAbsoluteMax = 900;
int PathFinder::pathFindNodesMax = 1500;
const int PathFinder::pathFindRefresh = 10;
const int PathFinder::pathFindBailoutRadius = 20;