| 5156 | } |
| 5157 | |
| 5158 | void BattleUnit::setBodyState(GameState &state, BodyState bodyState) |
| 5159 | { |
| 5160 | if (!agent->isBodyStateAllowed(bodyState)) |
| 5161 | { |
| 5162 | LogError("SetBodyState called on %s (%s) (%s) with bodyState %d", id, agent->name, |
| 5163 | agent->type->id, (int)bodyState); |
| 5164 | return; |
| 5165 | } |
| 5166 | bool roseUp = current_body_state == BodyState::Downed; |
| 5167 | current_body_state = bodyState; |
| 5168 | target_body_state = bodyState; |
| 5169 | body_animation_ticks_remaining = 0; |
| 5170 | body_animation_ticks_total = 1; |
| 5171 | // Update things that require tileObject (or stuff loaded after battle::init) |
| 5172 | if (tileObject) |
| 5173 | { |
| 5174 | // Ensure we have frames in this state |
| 5175 | auto animationPack = agent->getAnimationPack(); |
| 5176 | if (animationPack->getFrameCountBody(displayedItem, current_body_state, target_body_state, |
| 5177 | current_hand_state, current_movement_state, |
| 5178 | facing) == 0) |
| 5179 | { |
| 5180 | // No animation for target state -> Try without movement |
| 5181 | if (current_movement_state != MovementState::None && |
| 5182 | animationPack->getFrameCountBody(displayedItem, current_body_state, |
| 5183 | target_body_state, current_hand_state, |
| 5184 | MovementState::None, facing) != 0) |
| 5185 | { |
| 5186 | setMovementState(MovementState::None); |
| 5187 | } |
| 5188 | // No animation for target state -> Try without aiming |
| 5189 | else if (current_hand_state != HandState::AtEase && |
| 5190 | animationPack->getFrameCountBody(displayedItem, current_body_state, |
| 5191 | target_body_state, HandState::AtEase, |
| 5192 | current_movement_state, facing) != 0) |
| 5193 | { |
| 5194 | setHandState(HandState::AtEase); |
| 5195 | } |
| 5196 | // We know for sure this body state is allowed, |
| 5197 | // and we know for sure allowed body state has frames w/o aiming and moving |
| 5198 | else |
| 5199 | { |
| 5200 | setMovementState(MovementState::None); |
| 5201 | setHandState(HandState::AtEase); |
| 5202 | } |
| 5203 | } |
| 5204 | // Updates bounds etc. |
| 5205 | setPosition(state, position); |
| 5206 | // Update vision since our head position may have changed |
| 5207 | refreshUnitVision(state); |
| 5208 | // If rose up - update vision for units that see this |
| 5209 | if (roseUp) |
| 5210 | { |
| 5211 | refreshUnitVisibilityAndVision(state); |
| 5212 | } |
| 5213 | } |
| 5214 | } |
| 5215 |
no test coverage detected