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

Method executeAIAction

game/state/battle/battleunit.cpp:4238–4294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4236}
4237
4238void BattleUnit::executeAIAction(GameState &state, AIAction &action)
4239{
4240 if (action.inProgress(*this))
4241 {
4242 return;
4243 }
4244
4245 // Equip item we're going to use
4246 if (action.item)
4247 {
4248 UnitAIHelper::ensureItemInSlot(state, action.item, EquipmentSlotType::RightHand);
4249 if (action.type == AIAction::Type::AttackWeaponUnit ||
4250 action.type == AIAction::Type::AttackWeaponTile)
4251 {
4252 action.item = nullptr;
4253 action.weaponStatus = WeaponStatus::FiringRightHand;
4254 }
4255 }
4256
4257 // Do it
4258 switch (action.type)
4259 {
4260 case AIAction::Type::AttackWeaponTile:
4261 startAttacking(state, action.targetLocation, action.weaponStatus);
4262 break;
4263 case AIAction::Type::AttackWeaponUnit:
4264 startAttacking(state, action.targetUnit, action.weaponStatus);
4265 break;
4266 case AIAction::Type::AttackGrenade:
4267 if (action.item->getCanThrow(*this, action.targetUnit->position))
4268 {
4269 if (setMission(state, BattleUnitMission::throwItem(*this, action.item,
4270 action.targetUnit->position)))
4271 {
4272 action.item->prime(action.item->getPayloadType()->trigger_type !=
4273 TriggerType::Boomeroid,
4274 0, 12.0f);
4275 }
4276 }
4277 break;
4278 case AIAction::Type::AttackPsiMC:
4279 startAttackPsi(state, action.targetUnit, PsiStatus::Control, action.item->type);
4280 break;
4281 case AIAction::Type::AttackPsiStun:
4282 startAttackPsi(state, action.targetUnit, PsiStatus::Stun, action.item->type);
4283 break;
4284 case AIAction::Type::AttackPsiPanic:
4285 startAttackPsi(state, action.targetUnit, PsiStatus::Panic, action.item->type);
4286 break;
4287 case AIAction::Type::AttackBrainsucker:
4288 useBrainsucker(state);
4289 break;
4290 case AIAction::Type::AttackSuicide:
4291 die(state);
4292 break;
4293 }
4294}
4295

Callers 1

Calls 4

inProgressMethod · 0.80
getCanThrowMethod · 0.80
primeMethod · 0.80
getPayloadTypeMethod · 0.80

Tested by

no test coverage detected