Changeset - r14847:17c348b2df58
[Not reviewed]
master
0 3 0
yexo - 15 years ago 2010-03-18 18:38:32
yexo@openttd.org
(svn r19453) -Codechange: split getting the initial aircraft position to a new function
3 files changed with 26 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -315,20 +315,7 @@ CommandCost CmdBuildAircraft(TileIndex t
 

	
 
		_new_vehicle_id = v->index;
 

	
 
		/* 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 = Station::GetByTile(tile);
 
			const AirportFTAClass *apc = st->Airport();
 

	
 
			if (st->GetHangarTile(i) == tile) {
 
				assert(apc->layout[i].heading == HANGAR);
 
				v->pos = apc->layout[i].position;
 
				break;
 
			}
 
		}
 
		v->pos = GetVehiclePosOnBuild(tile);
 

	
 
		v->state = HANGAR;
 
		v->previous_pos = v->pos;
src/airport.cpp
Show inline comments
 
@@ -18,6 +18,7 @@
 
#include "date_func.h"
 
#include "settings_type.h"
 
#include "newgrf_airport.h"
 
#include "station_base.h"
 
#include "table/strings.h"
 
#include "table/airporttile_ids.h"
 

	
 
@@ -381,3 +382,25 @@ const AirportFTAClass *GetAirport(const 
 
	if (airport_type == AT_DUMMY) return &_airportfta_dummy;
 
	return AirportSpec::Get(airport_type)->fsm;
 
}
 

	
 
/**
 
 * Get the vehicle position when an aircraft is build at the given tile
 
 * @param hangar_tile The tile on which the vehicle is build
 
 * @return The position (index in airport node array) where the aircraft ends up
 
 */
 
byte GetVehiclePosOnBuild(TileIndex hangar_tile)
 
{
 
	const Station *st = Station::GetByTile(hangar_tile);
 
	const AirportFTAClass *apc = st->Airport();
 
	/* 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++) {
 
		if (st->GetHangarTile(i) == hangar_tile) {
 
			assert(apc->layout[i].heading == HANGAR);
 
			return apc->layout[i].position;
 
		}
 
	}
 
	NOT_REACHED();
 
}
src/airport.h
Show inline comments
 
@@ -13,6 +13,7 @@
 
#define AIRPORT_H
 

	
 
#include "direction_type.h"
 
#include "tile_type.h"
 

	
 
/** Some airport-related constants */
 
enum {
 
@@ -186,5 +187,6 @@ struct AirportFTA {
 
};
 

	
 
const AirportFTAClass *GetAirport(const byte airport_type);
 
byte GetVehiclePosOnBuild(TileIndex hangar_tile);
 

	
 
#endif /* AIRPORT_H */
0 comments (0 inline, 0 general)