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

Method finishBattle

game/state/battle/battle.cpp:2536–2926  ·  view source on GitHub ↗

To be called when battle must be finished and before showing score screen

Source from the content-addressed store, hash-verified

2534
2535// To be called when battle must be finished and before showing score screen
2536void Battle::finishBattle(GameState &state)
2537{
2538 if (!state.current_battle)
2539 {
2540 LogError("Battle::FinishBattle called with no battle!");
2541 return;
2542 }
2543
2544 auto player = state.getPlayer();
2545 auto aliens = state.getAliens();
2546 state.current_battle->unloadResources(state);
2547
2548 // Remove active battle scanners and deactivate medikits and motion scanners
2549 for (auto &u : state.current_battle->units)
2550 {
2551 for (auto &e : u.second->agent->equipment)
2552 {
2553 e->battleScanner.clear();
2554 e->inUse = false;
2555 }
2556 }
2557
2558 // Process MCed units
2559 for (auto &u : state.current_battle->units)
2560 {
2561 if (u.second->owner != u.second->agent->owner)
2562 {
2563 if (u.second->owner == player)
2564 {
2565 // mind control by player = capped alive
2566 u.second->stunDamage = 9001;
2567 }
2568 else
2569 {
2570 // mind control by someone else = MIA
2571 u.second->agent->modified_stats.health = -1;
2572 if (u.second->agent->owner == player)
2573 {
2574 state.current_battle->score.casualtyPenalty -= u.second->agent->type->score;
2575 }
2576 }
2577 u.second->owner = u.second->agent->owner;
2578 }
2579 }
2580
2581 // Loot (temporary storage for items that become loot)
2582 std::list<sp<AEquipment>> loot;
2583
2584 // - Prepare list of surviving aliens
2585 std::list<sp<BattleUnit>> retreatedAliens;
2586 std::list<sp<BattleUnit>> liveAliens;
2587 std::list<sp<BattleUnit>> deadAliens;
2588 for (auto &u : state.current_battle->units)
2589 {
2590 if (u.second->owner != aliens)
2591 {
2592 continue;
2593 }

Callers

nothing calls this directly

Calls 15

getPlayerMethod · 0.80
getAliensMethod · 0.80
unloadAmmoMethod · 0.80
emptyMethod · 0.80
insertMethod · 0.80
processExperienceMethod · 0.80
unloadResourcesMethod · 0.45
clearMethod · 0.45
isDeadMethod · 0.45
canBeUsedMethod · 0.45
removeEquipmentMethod · 0.45
setMissionMethod · 0.45

Tested by

no test coverage detected