src/aircraft_cmd.cpp
changeset 6563 d08d813ecd42
parent 6519 367d6f96e23f
child 6573 7624f942237f
equal deleted inserted replaced
6562:ffdb1169edce 6563:d08d813ecd42
   225 		default:
   225 		default:
   226 			return (avi->passenger_capacity + avi->mail_capacity) / 4;
   226 			return (avi->passenger_capacity + avi->mail_capacity) / 4;
   227 	}
   227 	}
   228 }
   228 }
   229 
   229 
   230 
       
   231 /** Build an aircraft.
   230 /** Build an aircraft.
   232  * @param tile tile of depot where aircraft is built
   231  * @param tile tile of depot where aircraft is built
   233  * @param flags for command
   232  * @param flags for command
   234  * @param p1 aircraft type being built (engine)
   233  * @param p1 aircraft type being built (engine)
   235  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   234  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   248 	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
   247 	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
   249 
   248 
   250 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
   249 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
   251 
   250 
   252 	/* Prevent building aircraft types at places which can't handle them */
   251 	/* Prevent building aircraft types at places which can't handle them */
   253 	const Station* st = GetStationByTile(tile);
   252 	if (!IsAircraftBuildableAtStation(p1, tile)) return CMD_ERROR;
   254 	const AirportFTAClass* apc = st->Airport();
       
   255 	if (!(apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS))) {
       
   256 		return CMD_ERROR;
       
   257 	}
       
   258 
   253 
   259 	/* Allocate 2 or 3 vehicle structs, depending on type
   254 	/* Allocate 2 or 3 vehicle structs, depending on type
   260 	 * vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */
   255 	 * vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */
   261 	Vehicle *vl[3];
   256 	Vehicle *vl[3];
   262 	if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
   257 	if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
   365 		/* When we click on hangar we know the tile it is on. By that we know
   360 		/* When we click on hangar we know the tile it is on. By that we know
   366 		 * its position in the array of depots the airport has.....we can search
   361 		 * its position in the array of depots the airport has.....we can search
   367 		 * layout for #th position of depot. Since layout must start with a listing
   362 		 * layout for #th position of depot. Since layout must start with a listing
   368 		 * of all depots, it is simple */
   363 		 * of all depots, it is simple */
   369 		for (uint i = 0;; i++) {
   364 		for (uint i = 0;; i++) {
       
   365 			const Station *st = GetStationByTile(tile);
       
   366 			const AirportFTAClass *apc = st->Airport();
       
   367 
   370 			assert(i != apc->nof_depots);
   368 			assert(i != apc->nof_depots);
   371 			if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
   369 			if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
   372 				assert(apc->layout[i].heading == HANGAR);
   370 				assert(apc->layout[i].heading == HANGAR);
   373 				v->u.air.pos = apc->layout[i].position;
   371 				v->u.air.pos = apc->layout[i].position;
   374 				break;
   372 				break;