MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / giveInterruptChanceToUnit

Method giveInterruptChanceToUnit

game/state/battle/battle.cpp:2394–2425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2392}
2393
2394void 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)

Callers 2

onReachGoalMethod · 0.80
handleCollisionMethod · 0.80

Calls 11

getAITypeMethod · 0.80
endMethod · 0.80
getReactionValueMethod · 0.80
emptyMethod · 0.80
pushEventMethod · 0.80
getTULimitMethod · 0.80
thinkMethod · 0.45
isEmptyMethod · 0.45
clearMethod · 0.45
getNameMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected