| 2458 | } |
| 2459 | |
| 2460 | void BattleUnit::updateIdling(GameState &state) |
| 2461 | { |
| 2462 | bool realTime = state.current_battle->mode == Battle::Mode::RealTime; |
| 2463 | |
| 2464 | if (missions.empty() && isConscious()) |
| 2465 | { |
| 2466 | // Sanity checks |
| 2467 | if (goalFacing != facing) |
| 2468 | { |
| 2469 | LogError("Unit %s (%s) turning without a mission, wtf?", id, agent->type->id); |
| 2470 | } |
| 2471 | if (target_body_state != current_body_state) |
| 2472 | { |
| 2473 | LogError("Unit %s (%s) changing body state without a mission, wtf?", id, |
| 2474 | agent->type->id); |
| 2475 | } |
| 2476 | |
| 2477 | // Reach goal before everything else |
| 2478 | if (!atGoal) |
| 2479 | { |
| 2480 | // The only way unit can suddenly become not at goal when idling is if either |
| 2481 | // map part died under him, or dirt fell from above on him |
| 2482 | // Either way, moving to goal is not the correct way to solve this |
| 2483 | startFalling(state); |
| 2484 | } |
| 2485 | else if (realTime || (state.current_battle->interruptQueue.empty() && |
| 2486 | (owner == state.current_battle->currentActiveOrganisation || |
| 2487 | state.current_battle->interruptUnits.find({&state, id}) != |
| 2488 | state.current_battle->interruptUnits.end()))) |
| 2489 | { |
| 2490 | // Kneel if not kneeling and should kneel |
| 2491 | if (kneeling_mode == KneelingMode::Kneeling && |
| 2492 | current_body_state != BodyState::Kneeling && canKneel() && |
| 2493 | canAfford(state, getBodyStateChangeCost(target_body_state, BodyState::Kneeling), |
| 2494 | true)) |
| 2495 | { |
| 2496 | setMission(state, BattleUnitMission::changeStance(*this, BodyState::Kneeling)); |
| 2497 | } |
| 2498 | // Go prone if not prone and should stay prone |
| 2499 | else if (movement_mode == MovementMode::Prone && |
| 2500 | current_body_state != BodyState::Prone && |
| 2501 | kneeling_mode != KneelingMode::Kneeling && canProne(position, facing) && |
| 2502 | canAfford(state, getBodyStateChangeCost(target_body_state, BodyState::Prone))) |
| 2503 | { |
| 2504 | setMission(state, BattleUnitMission::changeStance(*this, BodyState::Prone)); |
| 2505 | } |
| 2506 | // Stand up if not standing up and should stand up |
| 2507 | else if ((movement_mode == MovementMode::Walking || |
| 2508 | movement_mode == MovementMode::Running) && |
| 2509 | kneeling_mode != KneelingMode::Kneeling && |
| 2510 | current_body_state != BodyState::Standing && |
| 2511 | current_body_state != BodyState::Flying) |
| 2512 | { |
| 2513 | if (agent->isBodyStateAllowed(BodyState::Standing)) |
| 2514 | { |
| 2515 | if (canAfford(state, |
| 2516 | getBodyStateChangeCost(target_body_state, BodyState::Standing))) |
| 2517 | { |
nothing calls this directly
no test coverage detected