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

Method advanceAlongPath

game/state/battle/battleunitmission.cpp:2083–2386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2081}
2082
2083bool BattleUnitMission::advanceAlongPath(GameState &state, BattleUnit &u, Vec3<float> &dest)
2084{
2085 bool realTime = state.current_battle->mode == Battle::Mode::RealTime;
2086
2087 if (u.isUnconscious() || u.isDead() || currentPlannedPath.empty())
2088 {
2089 return false;
2090 }
2091
2092 // Go to goal if not on goal (can happen if jumped)
2093 auto restingPos = u.tileObject->getOwningTile()->getRestingPosition(u.isLarge());
2094 if (restingPos != u.position)
2095 {
2096 // Cancel jumping state
2097 if (targetBodyState == BodyState::Jumping)
2098 {
2099 targetBodyState = BodyState::Standing;
2100 }
2101 dest = restingPos;
2102 return true;
2103 }
2104
2105 // Reached end of path
2106 if (currentPlannedPath.size() == 1)
2107 {
2108 currentPlannedPath.clear();
2109 return false;
2110 }
2111
2112 // Reset body and facing settings
2113 targetBodyState = u.target_body_state;
2114 targetFacing = u.goalFacing;
2115 requireGoal = true;
2116 freeTurn = false;
2117
2118 // Get target location
2119 auto it = ++currentPlannedPath.begin();
2120 auto pos = *it++;
2121
2122 // See if we can actually go there
2123 auto tFrom = u.tileObject->getOwningTile();
2124 auto &map = tFrom->map;
2125 auto tTo = map.getTile(pos);
2126 float cost = 0;
2127 bool jumped = false;
2128 bool closedDoorInTheWay = false;
2129 if (tFrom->position != pos &&
2130 !BattleUnitTileHelper{map, u}.canEnterTile(tFrom, tTo, !u.canFly(), jumped, cost,
2131 closedDoorInTheWay, true))
2132 {
2133 // Next tile became impassable, pick a new path
2134 currentPlannedPath.clear();
2135 u.addMission(state, BattleUnitMission::snooze(u, 1));
2136 u.addMission(state, Type::RestartNextMission);
2137 return false;
2138 }
2139
2140 // See if we can make a shortcut

Callers

nothing calls this directly

Calls 15

randBoundsInclusiveFunction · 0.85
clampFunction · 0.85
isUnconsciousMethod · 0.80
emptyMethod · 0.80
getRestingPositionMethod · 0.80
getOwningTileMethod · 0.80
isLargeMethod · 0.80
getTileMethod · 0.80
canFlyMethod · 0.80
endMethod · 0.80
canProneMethod · 0.80
getCanStandMethod · 0.80

Tested by

no test coverage detected