mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- added smarts to the AI so it takes note of very active battle locations and scouts there.
This commit is contained in:
parent
de1f7c53d9
commit
1a49588a45
@ -735,7 +735,18 @@ void Ai::sendScoutPatrol(){
|
|||||||
&& random.randRange(0, 2) == 1;
|
&& random.randRange(0, 2) == 1;
|
||||||
bool megaResourceAttack=(aiInterface->getControlType() == ctCpuMega || aiInterface->getControlType() == ctNetworkCpuMega)
|
bool megaResourceAttack=(aiInterface->getControlType() == ctCpuMega || aiInterface->getControlType() == ctNetworkCpuMega)
|
||||||
&& random.randRange(0, 1) == 1;
|
&& random.randRange(0, 1) == 1;
|
||||||
if( megaResourceAttack || ultraResourceAttack) {
|
|
||||||
|
std::vector<Vec2i> warningEnemyList = aiInterface->getEnemyWarningPositionList();
|
||||||
|
if(warningEnemyList.empty() == false) {
|
||||||
|
for(int i = warningEnemyList.size() - 1; i <= 0; --i) {
|
||||||
|
Vec2i &checkPos = warningEnemyList[i];
|
||||||
|
pos = checkPos;
|
||||||
|
possibleTargetFound = true;
|
||||||
|
aiInterface->removeEnemyWarningPositionFromList(checkPos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( megaResourceAttack || ultraResourceAttack) {
|
||||||
Map *map= aiInterface->getMap();
|
Map *map= aiInterface->getMap();
|
||||||
|
|
||||||
const TechTree *tt= aiInterface->getTechTree();
|
const TechTree *tt= aiInterface->getTechTree();
|
||||||
|
@ -832,9 +832,23 @@ bool AiInterface::isFreeCells(const Vec2i &pos, int size, Field field){
|
|||||||
return world->getMap()->isFreeCells(pos, size, field);
|
return world->getMap()->isFreeCells(pos, size, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AiInterface::removeEnemyWarningPositionFromList(Vec2i &checkPos) {
|
||||||
|
for(int i = enemyWarningPositionList.size() - 1; i <= 0; --i) {
|
||||||
|
Vec2i &pos = enemyWarningPositionList[i];
|
||||||
|
|
||||||
|
if(checkPos == pos) {
|
||||||
|
enemyWarningPositionList.erase(enemyWarningPositionList.begin()+i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Unit *AiInterface::getFirstOnSightEnemyUnit(Vec2i &pos, Field &field, int radius) {
|
const Unit *AiInterface::getFirstOnSightEnemyUnit(Vec2i &pos, Field &field, int radius) {
|
||||||
Map *map= world->getMap();
|
Map *map= world->getMap();
|
||||||
|
|
||||||
|
const int CHECK_RADIUS = 12;
|
||||||
|
const int WARNING_ENEMY_COUNT = 6;
|
||||||
|
|
||||||
for(int i = 0; i < world->getFactionCount(); ++i) {
|
for(int i = 0; i < world->getFactionCount(); ++i) {
|
||||||
for(int j = 0; j < world->getFaction(i)->getUnitCount(); ++j) {
|
for(int j = 0; j < world->getFaction(i)->getUnitCount(); ++j) {
|
||||||
Unit * unit= world->getFaction(i)->getUnit(j);
|
Unit * unit= world->getFaction(i)->getUnit(j);
|
||||||
@ -850,6 +864,37 @@ const Unit *AiInterface::getFirstOnSightEnemyUnit(Vec2i &pos, Field &field, int
|
|||||||
if(pos.dist(getHomeLocation()) < radius) {
|
if(pos.dist(getHomeLocation()) < radius) {
|
||||||
printLog(2, "Being attacked at pos "+intToStr(pos.x)+","+intToStr(pos.y)+"\n");
|
printLog(2, "Being attacked at pos "+intToStr(pos.x)+","+intToStr(pos.y)+"\n");
|
||||||
|
|
||||||
|
// Now check if there are more than x enemies in sight and if
|
||||||
|
// so make note of the position
|
||||||
|
int foundEnemies = 0;
|
||||||
|
std::map<int,bool> foundEnemyList;
|
||||||
|
for(int aiX = pos.x-CHECK_RADIUS; aiX < pos.x + CHECK_RADIUS; ++aiX) {
|
||||||
|
for(int aiY = pos.y-CHECK_RADIUS; aiY < pos.y + CHECK_RADIUS; ++aiY) {
|
||||||
|
Vec2i checkPos(aiX,aiY);
|
||||||
|
if(map->isInside(checkPos) && map->isInsideSurface(map->toSurfCoords(checkPos))) {
|
||||||
|
Cell *cAI = map->getCell(checkPos);
|
||||||
|
SurfaceCell *scAI = map->getSurfaceCell(Map::toSurfCoords(checkPos));
|
||||||
|
if(scAI != NULL && cAI != NULL && cAI->getUnit(field) != NULL && sc->isVisible(teamIndex)) {
|
||||||
|
const Unit *checkUnit = cAI->getUnit(field);
|
||||||
|
if(foundEnemyList.find(checkUnit->getId()) == foundEnemyList.end()) {
|
||||||
|
bool cannotSeeUnitAI = (checkUnit->getType()->hasCellMap() == true &&
|
||||||
|
checkUnit->getType()->getAllowEmptyCellMap() == true &&
|
||||||
|
checkUnit->getType()->hasEmptyCellMap() == true);
|
||||||
|
if(cannotSeeUnitAI == false && isAlly(checkUnit) == false
|
||||||
|
&& checkUnit->isAlive() == true) {
|
||||||
|
foundEnemies++;
|
||||||
|
foundEnemyList[checkUnit->getId()] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(foundEnemies >= WARNING_ENEMY_COUNT) {
|
||||||
|
if(std::find(enemyWarningPositionList.begin(),enemyWarningPositionList.end(),pos) == enemyWarningPositionList.end()) {
|
||||||
|
enemyWarningPositionList.push_back(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ private:
|
|||||||
Mutex *aiMutex;
|
Mutex *aiMutex;
|
||||||
|
|
||||||
AiInterfaceThread *workerThread;
|
AiInterfaceThread *workerThread;
|
||||||
|
std::vector<Vec2i> enemyWarningPositionList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AiInterface(Game &game, int factionIndex, int teamIndex, int useStartLocation=-1);
|
AiInterface(Game &game, int factionIndex, int teamIndex, int useStartLocation=-1);
|
||||||
@ -88,6 +89,9 @@ public:
|
|||||||
//main
|
//main
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
std::vector<Vec2i> getEnemyWarningPositionList() const { return enemyWarningPositionList; }
|
||||||
|
void removeEnemyWarningPositionFromList(Vec2i &checkPos);
|
||||||
|
|
||||||
inline Mutex * getMutex() {return aiMutex;}
|
inline Mutex * getMutex() {return aiMutex;}
|
||||||
|
|
||||||
void signalWorkerThread(int frameIndex);
|
void signalWorkerThread(int frameIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user