MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MapAircraftMovementState

Function MapAircraftMovementState

src/newgrf_engine.cpp:133–228  ·  view source on GitHub ↗

* Map OTTD aircraft movement states to TTDPatch style movement states * (VarAction 2 Variable 0xE2) */

Source from the content-addressed store, hash-verified

131 * (VarAction 2 Variable 0xE2)
132 */
133static uint8_t MapAircraftMovementState(const Aircraft *v)
134{
135 const Station *st = GetTargetAirportIfValid(v);
136 if (st == nullptr) return AMS_TTDP_FLIGHT_TO_TOWER;
137
138 const AirportFTAClass *afc = st->airport.GetFTA();
139 AirportMovingDataFlags amdflag = afc->MovingData(v->pos)->flags;
140
141 switch (v->state) {
142 case HANGAR:
143 /* The international airport is a special case as helicopters can land in
144 * front of the hangar. Helicopters also change their air.state to
145 * AirportMovingDataFlag::HeliLower some time before actually descending. */
146
147 /* This condition only occurs for helicopters, during descent,
148 * to a landing by the hangar of an international airport. */
149 if (amdflag.Test(AirportMovingDataFlag::HeliLower)) return AMS_TTDP_HELI_LAND_AIRPORT;
150
151 /* This condition only occurs for helicopters, before starting descent,
152 * to a landing by the hangar of an international airport. */
153 if (amdflag.Test(AirportMovingDataFlag::SlowTurn)) return AMS_TTDP_FLIGHT_TO_TOWER;
154
155 /* The final two conditions apply to helicopters or aircraft.
156 * Has reached hangar? */
157 if (amdflag.Test(AirportMovingDataFlag::ExactPosition)) return AMS_TTDP_HANGAR;
158
159 /* Still moving towards hangar. */
160 return AMS_TTDP_TO_HANGAR;
161
162 case TERM1:
163 if (amdflag.Test(AirportMovingDataFlag::ExactPosition)) return AMS_TTDP_TO_PAD1;
164 return AMS_TTDP_TO_JUNCTION;
165
166 case TERM2:
167 if (amdflag.Test(AirportMovingDataFlag::ExactPosition)) return AMS_TTDP_TO_PAD2;
168 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
169
170 case TERM3:
171 case TERM4:
172 case TERM5:
173 case TERM6:
174 case TERM7:
175 case TERM8:
176 /* TTDPatch only has 3 terminals, so treat these states the same */
177 if (amdflag.Test(AirportMovingDataFlag::ExactPosition)) return AMS_TTDP_TO_PAD3;
178 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
179
180 case HELIPAD1:
181 case HELIPAD2:
182 case HELIPAD3:
183 /* Will only occur for helicopters.*/
184 if (amdflag.Test(AirportMovingDataFlag::HeliLower)) return AMS_TTDP_HELI_LAND_AIRPORT; // Descending.
185 if (amdflag.Test(AirportMovingDataFlag::SlowTurn)) return AMS_TTDP_FLIGHT_TO_TOWER; // Still hasn't started descent.
186 return AMS_TTDP_TO_JUNCTION; // On the ground.
187
188 case TAKEOFF: // Moving to takeoff position.
189 return AMS_TTDP_TO_OUTWAY;
190

Callers 1

VehicleGetVariableFunction · 0.85

Calls 4

GetTargetAirportIfValidFunction · 0.85
GetFTAMethod · 0.80
MovingDataMethod · 0.80
TestMethod · 0.80

Tested by

no test coverage detected