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

Function CmdBuildAircraft

src/aircraft_cmd.cpp:269–394  ·  view source on GitHub ↗

* Build an aircraft. * @param flags type of operation. * @param tile tile of the depot where aircraft is built. * @param e the engine to build. * @param[out] ret the vehicle that has been built. * @return the cost of this operation or an error. */

Source from the content-addressed store, hash-verified

267 * @return the cost of this operation or an error.
268 */
269CommandCost CmdBuildAircraft(DoCommandFlags flags, TileIndex tile, const Engine *e, Vehicle **ret)
270{
271 const AircraftVehicleInfo *avi = &e->VehInfo<AircraftVehicleInfo>();
272 const Station *st = Station::GetByTile(tile);
273
274 /* Prevent building aircraft types at places which can't handle them */
275 if (!CanVehicleUseStation(e->index, st)) return CMD_ERROR;
276
277 /* Make sure all aircraft end up in the first tile of the hangar. */
278 tile = st->airport.GetHangarTile(st->airport.GetHangarNum(tile));
279
280 if (flags.Test(DoCommandFlag::Execute)) {
281 Aircraft *v = new Aircraft(); // aircraft
282 Aircraft *u = new Aircraft(); // shadow
283 *ret = v;
284
285 v->direction = DIR_SE;
286
287 v->owner = u->owner = _current_company;
288
289 v->tile = tile;
290
291 uint x = TileX(tile) * TILE_SIZE + 5;
292 uint y = TileY(tile) * TILE_SIZE + 3;
293
294 v->x_pos = u->x_pos = x;
295 v->y_pos = u->y_pos = y;
296
297 u->z_pos = GetSlopePixelZ(x, y);
298 v->z_pos = u->z_pos + 1;
299
300 v->vehstatus = {VehState::Hidden, VehState::Stopped, VehState::DefaultPalette};
301 u->vehstatus = {VehState::Hidden, VehState::Unclickable, VehState::Shadow};
302
303 v->spritenum = avi->image_index;
304
305 v->cargo_cap = avi->passenger_capacity;
306 v->refit_cap = 0;
307 u->refit_cap = 0;
308
309 v->cargo_type = e->GetDefaultCargoType();
310 assert(IsValidCargoType(v->cargo_type));
311
312 CargoType mail = GetCargoTypeByLabel(CT_MAIL);
313 if (IsValidCargoType(mail)) {
314 u->cargo_type = mail;
315 u->cargo_cap = avi->mail_capacity;
316 }
317
318 v->name.clear();
319 v->last_station_visited = StationID::Invalid();
320 v->last_loading_station = StationID::Invalid();
321
322 v->acceleration = avi->acceleration;
323 v->engine_type = e->index;
324 u->engine_type = e->index;
325
326 v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER);

Callers 1

CmdBuildVehicleFunction · 0.85

Calls 15

CanVehicleUseStationFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
GetSlopePixelZFunction · 0.85
IsValidCargoTypeFunction · 0.85
GetCargoTypeByLabelFunction · 0.85
InvalidFunction · 0.85
GetVehiclePosOnBuildFunction · 0.85
GetStationIndexFunction · 0.85
UpdateAircraftCacheFunction · 0.85
CommandCostClass · 0.85
GetHangarTileMethod · 0.80

Tested by

no test coverage detected