# HG changeset patch # User bjarni # Date 1173219118 0 # Node ID d08d813ecd42d24baec0351a49d59946c19fbf47 # Parent ffdb1169edce47a2cf252cc0b4a11c525275e62b (svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question This should help ensuring that the build command and the list are consistent in what aircraft are buildable diff -r ffdb1169edce -r d08d813ecd42 src/aircraft.h --- a/src/aircraft.h Tue Mar 06 22:01:59 2007 +0000 +++ b/src/aircraft.h Tue Mar 06 22:11:58 2007 +0000 @@ -42,6 +42,20 @@ return IsAircraftInHangar(v) && v->vehstatus & VS_STOPPED; } +/** Checks if an aircraft is buildable at the tile in question + * @param engine The engine to test + * @param tile The tile where the hangar is + * @return true if the aircraft can be build + */ +static inline bool IsAircraftBuildableAtStation(EngineID engine, TileIndex tile) +{ + const Station *st = GetStationByTile(tile); + const AirportFTAClass *apc = st->Airport(); + const AircraftVehicleInfo *avi = AircraftVehInfo(engine); + + return apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS); +} + uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo*); void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2); diff -r ffdb1169edce -r d08d813ecd42 src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp Tue Mar 06 22:01:59 2007 +0000 +++ b/src/aircraft_cmd.cpp Tue Mar 06 22:11:58 2007 +0000 @@ -227,7 +227,6 @@ } } - /** Build an aircraft. * @param tile tile of depot where aircraft is built * @param flags for command @@ -250,11 +249,7 @@ SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); /* Prevent building aircraft types at places which can't handle them */ - const Station* st = GetStationByTile(tile); - const AirportFTAClass* apc = st->Airport(); - if (!(apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS))) { - return CMD_ERROR; - } + if (!IsAircraftBuildableAtStation(p1, tile)) return CMD_ERROR; /* Allocate 2 or 3 vehicle structs, depending on type * vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */ @@ -367,6 +362,9 @@ * layout for #th position of depot. Since layout must start with a listing * of all depots, it is simple */ for (uint i = 0;; i++) { + const Station *st = GetStationByTile(tile); + const AirportFTAClass *apc = st->Airport(); + assert(i != apc->nof_depots); if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) { assert(apc->layout[i].heading == HANGAR); diff -r ffdb1169edce -r d08d813ecd42 src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp Tue Mar 06 22:01:59 2007 +0000 +++ b/src/build_vehicle_gui.cpp Tue Mar 06 22:11:58 2007 +0000 @@ -694,26 +694,11 @@ * when planes become obsolete and are removed */ sel_id = INVALID_ENGINE; for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) { - if (IsEngineBuildable(eid, VEH_Aircraft, _local_player)) { - const AircraftVehicleInfo *avi = AircraftVehInfo(eid); - switch (bv->filter.flags & ~AirportFTAClass::SHORT_STRIP) { // we don't care about the length of the runway here - case AirportFTAClass::HELICOPTERS: - if (avi->subtype != AIR_HELI) continue; - break; + if (!IsEngineBuildable(eid, VEH_Aircraft, _local_player)) continue; + if (w->window_number != 0 && !IsAircraftBuildableAtStation(eid, w->window_number)) continue; - case AirportFTAClass::AIRPLANES: - if (!(avi->subtype & AIR_CTOL)) continue; - break; - - case AirportFTAClass::ALL: break; - default: - NOT_REACHED(); - } - - EngList_Add(&bv->eng_list, eid); - - if (eid == bv->sel_engine) sel_id = eid; - } + EngList_Add(&bv->eng_list, eid); + if (eid == bv->sel_engine) sel_id = eid; } bv->sel_engine = sel_id;