* Runs any code the state needs to keep updating every AI cycle. * @param action (possible) AI action to execute after thinking is done. */
| 140 | * @param action (possible) AI action to execute after thinking is done. |
| 141 | */ |
| 142 | void AlienBAIState::think(BattleAction *action) |
| 143 | { |
| 144 | action->type = BA_RETHINK; |
| 145 | action->actor = _unit; |
| 146 | action->weapon = _unit->getMainHandWeapon(); |
| 147 | _attackAction->diff = (int)(_save->getBattleState()->getGame()->getSavedGame()->getDifficulty()); |
| 148 | _attackAction->actor = _unit; |
| 149 | _attackAction->weapon = action->weapon; |
| 150 | _attackAction->number = action->number; |
| 151 | _escapeAction->number = action->number; |
| 152 | _knownEnemies = countKnownTargets(); |
| 153 | _visibleEnemies = selectNearestTarget(); |
| 154 | _spottingEnemies = getSpottingUnits(_unit->getPosition()); |
| 155 | _melee = false; |
| 156 | _rifle = false; |
| 157 | _blaster = false; |
| 158 | _reachable = _save->getPathfinding()->findReachable(_unit, _unit->getTimeUnits()); |
| 159 | if(_unit->getCharging() && _unit->getCharging()->isOut()) |
| 160 | { |
| 161 | _unit->setCharging(0); |
| 162 | } |
| 163 | |
| 164 | if (_traceAI) |
| 165 | { |
| 166 | Log(LOG_INFO) << "Unit has " << _visibleEnemies << "/" << _knownEnemies << " known enemies visible, " << _spottingEnemies << " of whom are spotting him. "; |
| 167 | std::string AIMode; |
| 168 | switch (_AIMode) |
| 169 | { |
| 170 | case 0: |
| 171 | AIMode = "Patrol"; |
| 172 | break; |
| 173 | case 1: |
| 174 | AIMode = "Ambush"; |
| 175 | break; |
| 176 | case 2: |
| 177 | AIMode = "Combat"; |
| 178 | break; |
| 179 | case 3: |
| 180 | AIMode = "Escape"; |
| 181 | break; |
| 182 | } |
| 183 | Log(LOG_INFO) << "Currently using " << AIMode << " behaviour"; |
| 184 | } |
| 185 | |
| 186 | if (action->weapon) |
| 187 | { |
| 188 | RuleItem *rule = action->weapon->getRules(); |
| 189 | if (rule->getBattleType() == BT_FIREARM) |
| 190 | { |
| 191 | if (!rule->isWaypoint()) |
| 192 | { |
| 193 | _rifle = true; |
| 194 | _reachableWithAttack = _save->getPathfinding()->findReachable(_unit, _unit->getTimeUnits() - _unit->getActionTUs(BA_SNAPSHOT, action->weapon)); |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | _blaster = true; |
| 199 | _reachableWithAttack = _save->getPathfinding()->findReachable(_unit, _unit->getTimeUnits() - _unit->getActionTUs(BA_AIMEDSHOT, action->weapon)); |
nothing calls this directly
no test coverage detected