| 1087 | } |
| 1088 | |
| 1089 | void ActorMovementController::doSetAnchorState(Maybe<EntityAnchorState> anchorState) { |
| 1090 | EntityAnchorConstPtr entityAnchor; |
| 1091 | if (anchorState) { |
| 1092 | auto anchorableEntity = as<AnchorableEntity>(world()->entity(anchorState->entityId)); |
| 1093 | if (!anchorableEntity) |
| 1094 | throw ActorMovementControllerException::format("No such anchorable entity id {} in ActorMovementController::setAnchorState", anchorState->entityId); |
| 1095 | entityAnchor = anchorableEntity->anchor(anchorState->positionIndex); |
| 1096 | if (!entityAnchor) |
| 1097 | throw ActorMovementControllerException::format("Anchor position {} is disabled ActorMovementController::setAnchorState", anchorState->positionIndex); |
| 1098 | } |
| 1099 | |
| 1100 | if (!entityAnchor && m_entityAnchor && m_entityAnchor->exitBottomPosition) { |
| 1101 | auto boundBox = MovementController::localBoundBox(); |
| 1102 | Vec2F bottomMid = {boundBox.center()[0], boundBox.yMin()}; |
| 1103 | setPosition(*m_entityAnchor->exitBottomPosition - bottomMid); |
| 1104 | } |
| 1105 | |
| 1106 | m_anchorState.set(anchorState); |
| 1107 | m_entityAnchor = std::move(entityAnchor); |
| 1108 | |
| 1109 | if (m_entityAnchor) |
| 1110 | setPosition(m_entityAnchor->position); |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | PathController::PathController(World* world) |