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

Method enterBattle

game/state/battle/battle.cpp:2476–2533  ·  view source on GitHub ↗

To be called when battle must be started, after the player has assigned agents to squads

Source from the content-addressed store, hash-verified

2474
2475// To be called when battle must be started, after the player has assigned agents to squads
2476void Battle::enterBattle(GameState &state)
2477{
2478 if (!state.current_battle)
2479 {
2480 LogError("Battle::enterBattle called with no battle!");
2481 return;
2482 }
2483
2484 auto &b = state.current_battle;
2485 b->hotseat = b->hotseat && b->mode == Battle::Mode::TurnBased;
2486
2487 state.current_battle->initialUnitSpawn(state);
2488
2489 state.current_battle->initBattle(state, true);
2490
2491 if (b->mission_type == MissionType::BaseDefense)
2492 {
2493 for (size_t i = 0; i < b->visibleTiles[b->locationOwner].size(); i++)
2494 {
2495 b->visibleTiles[b->locationOwner][i] = true;
2496 }
2497 for (size_t i = 0; i < b->visibleBlocks[b->locationOwner].size(); i++)
2498 {
2499 b->visibleBlocks[b->locationOwner][i] = true;
2500 }
2501 }
2502
2503 for (auto &u : state.current_battle->units)
2504 {
2505 u.second->updateCheckBeginFalling(state);
2506 }
2507
2508 // Find first player unit
2509 sp<BattleUnit> firstPlayerUnit = nullptr;
2510 for (auto &f : state.current_battle->forces[state.getPlayer()].squads)
2511 {
2512 if (f.getNumUnits() > 0)
2513 {
2514 firstPlayerUnit = f.units.front();
2515 break;
2516 }
2517 }
2518 if (!firstPlayerUnit)
2519 {
2520 LogError("WTF, no player units found?");
2521 state.current_battle->battleViewScreenCenter = state.current_battle->map->size / 2;
2522 state.current_battle->battleViewZLevel = state.current_battle->map->size.z / 2 + 1;
2523 }
2524 else
2525 {
2526 state.current_battle->battleViewScreenCenter = firstPlayerUnit->position;
2527 state.current_battle->battleViewZLevel = (int)ceilf(firstPlayerUnit->position.z);
2528 }
2529 state.current_battle->battleViewGroupMove = true;
2530
2531 // Remember time
2532 state.updateBeforeBattle();
2533}

Callers

nothing calls this directly

Calls 7

initialUnitSpawnMethod · 0.80
initBattleMethod · 0.80
getPlayerMethod · 0.80
getNumUnitsMethod · 0.80
updateBeforeBattleMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected