Changeset - r15837:0edeb7d262a5
[Not reviewed]
master
0 2 0
yexo - 14 years ago 2010-08-17 21:50:58
yexo@openttd.org
(svn r20529) -Codechange: simplify UpdateAirplanesOnNewStation by removing code for situations that don't happen
2 files changed with 6 insertions and 40 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1955,40 +1955,16 @@ Station *GetTargetAirportIfValid(const A
 
 * @param st Station been updated
 
 */
 
void UpdateAirplanesOnNewStation(const Station *st)
 
{
 
	/* only 1 station is updated per function call, so it is enough to get entry_point once */
 
	const AirportFTAClass *ap = st->airport.GetFTA();
 
	Direction rotation = st->airport.tile == INVALID_TILE ? DIR_N : st->airport.rotation;
 

	
 
	Aircraft *v;
 
	FOR_ALL_AIRCRAFT(v) {
 
		if (v->IsNormalAircraft()) {
 
			if (v->targetairport == st->index) { // if heading to this airport
 
				/* update position of airplane. If plane is not flying, landing, or taking off
 
				 * you cannot delete airport, so it doesn't matter */
 
				if (v->state >= FLYING) { // circle around
 
					Direction rotation = st->airport.tile == INVALID_TILE ? DIR_N : st->airport.rotation;
 
					v->pos = v->previous_pos = AircraftGetEntryPoint(v, ap, rotation);
 
					v->state = FLYING;
 
					UpdateAircraftCache(v);
 
					/* landing plane needs to be reset to flying height (only if in pause mode upgrade,
 
					 * in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */
 
					GetNewVehiclePosResult gp = GetNewVehiclePos(v);
 
					/* set new position x,y,z */
 
					SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
 
				} else {
 
					assert(v->state == ENDTAKEOFF || v->state == HELITAKEOFF);
 
					byte takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF;
 
					/* search in airportdata for that heading
 
					 * easiest to do, since this doesn't happen a lot */
 
					for (uint cnt = 0; cnt < ap->nofelements; cnt++) {
 
						if (ap->layout[cnt].heading == takeofftype) {
 
							v->pos = ap->layout[cnt].position;
 
							UpdateAircraftCache(v);
 
							break;
 
						}
 
					}
 
				}
 
			}
 
		}
 
		if (!v->IsNormalAircraft() || v->targetairport != st->index) continue;
 
		assert(v->state == FLYING);
 
		v->pos = v->previous_pos = AircraftGetEntryPoint(v, ap, rotation);
 
		UpdateAircraftCache(v);
 
	}
 
}
src/station_cmd.cpp
Show inline comments
 
@@ -2103,13 +2103,12 @@ void UpdateAirportsNoise()
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool airport_upgrade = true;
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 
	byte airport_type = GB(p1, 0, 8);
 
	byte layout = GB(p1, 8, 8);
 
@@ -2185,14 +2184,12 @@ CommandCost CmdBuildAirport(TileIndex ti
 
		if (ret.Failed()) return ret;
 

	
 
		if (st->airport.tile != INVALID_TILE) {
 
			return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
 
		}
 
	} else {
 
		airport_upgrade = false;
 

	
 
		/* allocate and initialize new station */
 
		if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
		if (flags & DC_EXEC) {
 
			st = new Station(tile);
 

	
 
@@ -2236,20 +2233,13 @@ CommandCost CmdBuildAirport(TileIndex ti
 
		it = as->table[layout];
 
		do {
 
			TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
 
			AirportTileAnimationTrigger(st, cur_tile, AAT_BUILT);
 
		} while ((++it)->ti.x != -0x80);
 

	
 
		/* if airport was demolished while planes were en-route to it, the
 
		 * positions can no longer be the same (v->u.air.pos), since different
 
		 * airports have different indexes. So update all planes en-route to this
 
		 * airport. Only update if
 
		 * 1. airport is upgraded
 
		 * 2. airport is added to existing station (unfortunately unavoideable)
 
		 */
 
		if (airport_upgrade) UpdateAirplanesOnNewStation(st);
 
		UpdateAirplanesOnNewStation(st);
 

	
 
		st->UpdateVirtCoord();
 
		UpdateStationAcceptance(st, false);
 
		st->RecomputeIndustriesNear();
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
0 comments (0 inline, 0 general)