trying to let mega CPUs fight smarter

This commit is contained in:
titiger 2019-06-22 00:54:29 +02:00
parent aec1e6d416
commit b3e0e1b462
1 changed files with 66 additions and 26 deletions

View File

@ -2982,6 +2982,9 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
//attack enemies that can attack first //attack enemies that can attack first
float distToUnit= -1; float distToUnit= -1;
Unit* enemySeen= NULL; Unit* enemySeen= NULL;
std::vector<Unit*> fightingEnemiesInRange;
std::vector<Unit*> damagedFightingEnemiesInRange;
Unit* myFightingEnemyInRange= NULL;
float distToStandingUnit= -1; float distToStandingUnit= -1;
Unit* attackingEnemySeen= NULL; Unit* attackingEnemySeen= NULL;
@ -3018,35 +3021,72 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
// Select closest attacking unit // Select closest attacking unit
if (distToUnit < 0 || currentDist < distToUnit) { if (distToUnit < 0 || currentDist < distToUnit) {
distToUnit = currentDist; distToUnit = currentDist;
*rangedPtr = enemies[i]; *rangedPtr = enemy;
enemySeen = enemies[i]; enemySeen = enemy;
result = true; result = true;
} }
if(isUltra || isMega) { if (distToStandingUnit < 0
|| currentDist < distToStandingUnit) {
if(distToStandingUnit < 0 || currentDist< distToStandingUnit) { if (enemy->getCurrSkill() != NULL
if(enemies[i]->getCurrSkill()!=NULL && enemies[i]->getCurrSkill()->getClass()==scAttack) { && enemy->getCurrSkill()->getClass()
== scAttack) {
distToStandingUnit = currentDist; distToStandingUnit = currentDist;
attackingEnemySeen=enemies[i]; attackingEnemySeen = enemy;
}
} }
} }
if (enemy->getCurrSkill() != NULL
&& enemy->getCurrSkill()->getClass() == scAttack) {
if(enemy->getId()==unit->getLastAttackedUnitId())
myFightingEnemyInRange=enemy;
AttackSkillType* ast =
(AttackSkillType*) (enemy->getCurrSkill());
int enemyAttackRange = ast->getTotalAttackRange(unit->getTotalUpgrade());
if (enemyAttackRange > 1) {
fightingEnemiesInRange.push_back(enemy);
if( unit->getHpRatio()<0.9){
damagedFightingEnemiesInRange.push_back(enemy);
} }
} }
} }
if(evalMode == false && (isUltra || isMega)) { }
}
}
if (evalMode == false) {
if ((isUltra)) {
unit->getRandom()->addLastCaller(randomInfoData); unit->getRandom()->addLastCaller(randomInfoData);
bool doit = unit->getRandom()->randRange(0, 2, extractFileFromDirectoryPath(__FILE__) + intToStr(__LINE__)) != 2;
if( attackingEnemySeen != NULL && unit->getRandom()->randRange(0,2,extractFileFromDirectoryPath(__FILE__) + intToStr(__LINE__)) != 2 ) { if (attackingEnemySeen != NULL && doit) {
//if( attackingEnemySeen != NULL) { //if( attackingEnemySeen != NULL) {
*rangedPtr = attackingEnemySeen; *rangedPtr = attackingEnemySeen;
enemySeen = attackingEnemySeen; enemySeen = attackingEnemySeen;
//printf("Da hat er wen gefunden:%s\n",enemySeen->getType()->getName(false).c_str()); //printf("Da hat er wen gefunden:%s\n",enemySeen->getType()->getName(false).c_str());
} }
} else if (isMega) {
if (myFightingEnemyInRange != NULL) {
//printf("Choosed my good old friend\n");
*rangedPtr = myFightingEnemyInRange;
enemySeen = myFightingEnemyInRange;
} else {
unit->getRandom()->addLastCaller(randomInfoData);
bool doit = unit->getRandom()->randRange(0, 3, extractFileFromDirectoryPath(__FILE__) + intToStr(__LINE__)) == 1;
//printf("fightingEnemiesInRange.size()=%d\n",fightingEnemiesInRange.size());
if (fightingEnemiesInRange.size() > 0 && doit) {
//printf("Choosing new one\n");
int myChoice = unit->getRandom()->randRange(1, fightingEnemiesInRange.size(),
extractFileFromDirectoryPath(__FILE__) + intToStr(__LINE__));
//printf("myChoice=%d\n", myChoice);
Unit* choosenOne = fightingEnemiesInRange[myChoice - 1];
//printf("choosenOne=%s team=%d\n", choosenOne->getType()->getName().c_str(), choosenOne->getFactionIndex());
*rangedPtr = choosenOne;
enemySeen = choosenOne;
} }
}
}
}
if(result == true) { if(result == true) {