* Find a position where we can see our target, and move there. * check the 11x11 grid for a position nearby where we can potentially target him. * @return True if a possible position was found. */
| 1395 | * @return True if a possible position was found. |
| 1396 | */ |
| 1397 | bool AlienBAIState::findFirePoint() |
| 1398 | { |
| 1399 | if (!selectClosestKnownEnemy()) |
| 1400 | return false; |
| 1401 | std::vector<Position> randomTileSearch = _save->getTileSearch(); |
| 1402 | RNG::shuffle(randomTileSearch); |
| 1403 | Position target; |
| 1404 | const int BASE_SYSTEMATIC_SUCCESS = 100; |
| 1405 | const int FAST_PASS_THRESHOLD = 125; |
| 1406 | int bestScore = 0; |
| 1407 | _attackAction->type = BA_RETHINK; |
| 1408 | for (std::vector<Position>::const_iterator i = randomTileSearch.begin(); i != randomTileSearch.end(); ++i) |
| 1409 | { |
| 1410 | Position pos = _unit->getPosition() + *i; |
| 1411 | Tile *tile = _save->getTile(pos); |
| 1412 | if (tile == 0 || |
| 1413 | std::find(_reachableWithAttack.begin(), _reachableWithAttack.end(), _save->getTileIndex(pos)) == _reachableWithAttack.end()) |
| 1414 | continue; |
| 1415 | int score = 0; |
| 1416 | // i should really make a function for this |
| 1417 | Position origin = (pos * Position(16,16,24)) + |
| 1418 | // 4 because -2 is eyes and 2 below that is the rifle (or at least that's my understanding) |
| 1419 | Position(8,8, _unit->getHeight() + _unit->getFloatHeight() - tile->getTerrainLevel() - 4); |
| 1420 | |
| 1421 | if (_save->getTileEngine()->canTargetUnit(&origin, _aggroTarget->getTile(), &target, _unit)) |
| 1422 | { |
| 1423 | _save->getPathfinding()->calculate(_unit, pos); |
| 1424 | // can move here |
| 1425 | if (_save->getPathfinding()->getStartDirection() != -1) |
| 1426 | { |
| 1427 | score = BASE_SYSTEMATIC_SUCCESS - getSpottingUnits(pos) * 10; |
| 1428 | score += _unit->getTimeUnits() - _save->getPathfinding()->getTotalTUCost(); |
| 1429 | if (!_aggroTarget->checkViewSector(pos)) |
| 1430 | { |
| 1431 | score += 10; |
| 1432 | } |
| 1433 | if (score > bestScore) |
| 1434 | { |
| 1435 | bestScore = score; |
| 1436 | _attackAction->target = pos; |
| 1437 | _attackAction->finalFacing = _save->getTileEngine()->getDirectionTo(pos, _aggroTarget->getPosition()); |
| 1438 | if (score > FAST_PASS_THRESHOLD) |
| 1439 | { |
| 1440 | break; |
| 1441 | } |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | if (bestScore > 70) |
| 1448 | { |
| 1449 | _attackAction->type = BA_WALK; |
| 1450 | if (_traceAI) |
| 1451 | { |
| 1452 | Log(LOG_INFO) << "Firepoint found at " << _attackAction->target << ", with a score of: " << bestScore; |
| 1453 | } |
| 1454 | return true; |
nothing calls this directly
no test coverage detected