Changeset - r6237:48ff143a04eb
[Not reviewed]
master
0 3 0
bjarni - 17 years ago 2007-03-06 22:11:58
bjarni@openttd.org
(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
3 files changed with 22 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/aircraft.h
Show inline comments
 
@@ -39,12 +39,26 @@ static inline bool IsAircraftInHangar(co
 

	
 
static inline bool IsAircraftInHangarStopped(const Vehicle* v)
 
{
 
	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);
 
void CcCloneAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
void HandleAircraftEnterHangar(Vehicle *v);
 
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height);
src/aircraft_cmd.cpp
Show inline comments
 
@@ -224,13 +224,12 @@ uint16 AircraftDefaultCargoCapacity(Carg
 
			return (avi->passenger_capacity + avi->mail_capacity) / 2;
 
		default:
 
			return (avi->passenger_capacity + avi->mail_capacity) / 4;
 
	}
 
}
 

	
 

	
 
/** Build an aircraft.
 
 * @param tile tile of depot where aircraft is built
 
 * @param flags for command
 
 * @param p1 aircraft type being built (engine)
 
 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
 
 * return result of operation.  Could be cost, error
 
@@ -247,17 +246,13 @@ int32 CmdBuildAircraft(TileIndex tile, u
 

	
 
	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
 

	
 
	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] */
 
	Vehicle *vl[3];
 
	if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
 
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
@@ -364,12 +359,15 @@ int32 CmdBuildAircraft(TileIndex tile, u
 

	
 
		/* When we click on hangar we know the tile it is on. By that we know
 
		 * its position in the array of depots the airport has.....we can search
 
		 * 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);
 
				v->u.air.pos = apc->layout[i].position;
 
				break;
 
			}
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -691,32 +691,17 @@ static void GenerateBuildAircraftList(Wi
 
	/* Make list of all available planes.
 
	 * Also check to see if the previously selected plane is still available,
 
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
 
	 * 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;
 
}
 

	
 
/* Generate the list of vehicles */
0 comments (0 inline, 0 general)