MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / evaluateAIMode

Method evaluateAIMode

src/Battlescape/AlienBAIState.cpp:1154–1390  ·  view source on GitHub ↗

* Selects an AI mode based on a number of factors, some RNG and the results of the rest of the determinations. */

Source from the content-addressed store, hash-verified

1152 * Selects an AI mode based on a number of factors, some RNG and the results of the rest of the determinations.
1153 */
1154void AlienBAIState::evaluateAIMode()
1155{
1156 if (_unit->getCharging() && _attackAction->type != BA_RETHINK)
1157 {
1158 _AIMode = AI_COMBAT;
1159 return;
1160 }
1161 // don't try to run away as often if we're a melee type, and really don't try to run away if we have a viable melee target, or we still have 50% or more TUs remaining.
1162 int escapeOdds = 15;
1163 if (_melee)
1164 {
1165 escapeOdds = 12;
1166 }
1167 if (_unit->getTimeUnits() > _unit->getStats()->tu / 2 || _unit->getCharging())
1168 {
1169 escapeOdds = 5;
1170 }
1171 int ambushOdds = 12;
1172 int combatOdds = 20;
1173 // we're less likely to patrol if we see enemies.
1174 int patrolOdds = _visibleEnemies ? 15 : 30;
1175
1176 // the enemy sees us, we should take retreat into consideration, and forget about patrolling for now.
1177 if (_spottingEnemies)
1178 {
1179 patrolOdds = 0;
1180 if (_escapeTUs == 0)
1181 {
1182 setupEscape();
1183 }
1184 }
1185
1186 // melee/blaster units shouldn't consider ambush
1187 if (!_rifle || _ambushTUs == 0)
1188 {
1189 ambushOdds = 0;
1190 if (_melee)
1191 {
1192 combatOdds *= 1.3;
1193 }
1194 }
1195
1196 // if we KNOW there are enemies around...
1197 if (_knownEnemies)
1198 {
1199 if (_knownEnemies == 1)
1200 {
1201 combatOdds *= 1.2;
1202 }
1203
1204 if (_escapeTUs == 0)
1205 {
1206 if (selectClosestKnownEnemy())
1207 {
1208 setupEscape();
1209 }
1210 else
1211 {

Callers

nothing calls this directly

Calls 10

generateFunction · 0.85
getChargingMethod · 0.80
getTimeUnitsMethod · 0.80
getHealthMethod · 0.80
getMissionTypeMethod · 0.80
isCheatingMethod · 0.80
getStatsMethod · 0.45
getAggressionMethod · 0.45
getTileMethod · 0.45
getUnitMethod · 0.45

Tested by

no test coverage detected