| 2392 | } |
| 2393 | |
| 2394 | void Battle::giveInterruptChanceToUnit(GameState &state, StateRef<BattleUnit> giver, |
| 2395 | StateRef<BattleUnit> receiver, int reactionValue) |
| 2396 | { |
| 2397 | if (mode != Mode::TurnBased || receiver->owner == currentActiveOrganisation || |
| 2398 | receiver->getAIType() == AIType::None || receiver->getAIType() == AIType::Civilian || |
| 2399 | interruptQueue.find(receiver) != interruptQueue.end()) |
| 2400 | { |
| 2401 | return; |
| 2402 | } |
| 2403 | |
| 2404 | if (receiver->agent->getReactionValue() > reactionValue) |
| 2405 | { |
| 2406 | receiver->focusUnit = giver; |
| 2407 | auto decision = receiver->aiList.think(state, *receiver, true); |
| 2408 | if (decision.isEmpty()) |
| 2409 | { |
| 2410 | receiver->focusUnit.clear(); |
| 2411 | } |
| 2412 | else |
| 2413 | { |
| 2414 | LogWarning("Interrupting AI %s for unit %s decided to %s", decision.ai, receiver->id, |
| 2415 | decision.getName()); |
| 2416 | receiver->aiList.reset(state, *receiver); |
| 2417 | if (interruptQueue.empty()) |
| 2418 | { |
| 2419 | fw().pushEvent(new GameLocationEvent(GameEventType::ZoomView, receiver->position)); |
| 2420 | } |
| 2421 | interruptQueue.emplace(receiver, receiver->agent->getTULimit(reactionValue)); |
| 2422 | receiver->experiencePoints.reactions++; |
| 2423 | } |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | // To be called when battle must be started, before showing battle briefing screen |
| 2428 | // In case battle is in a craft (UFO) |