MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / airplaneApproachTarget

Method airplaneApproachTarget

src/OpenLoco/src/Vehicles/VehicleHead.cpp:2165–2227  ·  view source on GitHub ↗

0x004A94A9

Source from the content-addressed store, hash-verified

2163
2164 // 0x004A94A9
2165 bool VehicleHead::airplaneApproachTarget(const AirplaneApproachTargetParams& params)
2166 {
2167 auto yaw = spriteYaw;
2168 // Helicopter
2169 if (params.isHeliTakeOffEnd)
2170 {
2171 yaw = params.targetYaw;
2172 }
2173 Vehicle train(*this);
2174 Vehicle1* vehType1 = train.veh1;
2175 Vehicle2* vehType2 = train.veh2;
2176
2177 auto [veh1Loc, veh2Loc] = calculateNextPosition(
2178 yaw, position, vehType1, vehType2->currentSpeed);
2179
2180 Pos3 newLoc(veh2Loc.x, veh2Loc.y, params.targetZ);
2181 vehType1->var_4E = veh1Loc.x;
2182 vehType1->var_50 = veh1Loc.y;
2183 if (params.targetZ != position.z)
2184 {
2185 // Final section of landing / helicopter
2186 if (params.manhattanDistanceToStation <= 28)
2187 {
2188 int16_t zShift = 1;
2189 if (vehType2->currentSpeed >= 50.0_mph)
2190 {
2191 zShift++;
2192 if (vehType2->currentSpeed >= 100.0_mph)
2193 {
2194 zShift++;
2195 }
2196 }
2197
2198 if (params.targetZ < position.z)
2199 {
2200 newLoc.z = std::max<int16_t>(params.targetZ, position.z - zShift);
2201 }
2202 else if (params.targetZ > position.z)
2203 {
2204 newLoc.z = std::min<int16_t>(params.targetZ, position.z + zShift);
2205 }
2206 }
2207 else
2208 {
2209 int32_t zDiff = params.targetZ - position.z;
2210 // We want a SAR instruction so use >>5
2211 int32_t param1 = (zDiff * toSpeed16(vehType2->currentSpeed).getRaw()) >> 5;
2212 int32_t param2 = params.manhattanDistanceToStation - 18;
2213
2214 auto modulo = param1 % param2;
2215 if (modulo < 0)
2216 {
2217 newLoc.z = position.z + param1 / param2 - 1;
2218 }
2219 else
2220 {
2221 newLoc.z = position.z + param1 / param2 + 1;
2222 }

Callers

nothing calls this directly

Calls 3

calculateNextPositionFunction · 0.85
toSpeed16Function · 0.85
getRawMethod · 0.45

Tested by

no test coverage detected