Changeset - r14733:d5287af271c9
[Not reviewed]
master
0 3 0
yexo - 14 years ago 2010-03-06 01:58:55
yexo@openttd.org
(svn r19331) -Fix: when deleting an airport the size from the AirportSpec was used instead of the stored airport size
-Fix (r19319): detecting if a plane was landed at an airport failed
-Fix: reset the airporttile mapping when restarting a game
3 files changed with 4 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/newgrf_airporttiles.h
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file newgrf_airporttiles.h NewGRF handling of airport tiles. */
 

	
 
#ifndef NEWGRF_AIRPORTTILES_H
 
#define NEWGRF_AIRPORTTILES_H
 

	
 
#include "airport.h"
 
#include "station_map.h"
 
#include "newgrf_commons.h"
 
#include "airport.h"
 

	
 
/** Animation triggers for airport tiles */
 
enum AirpAnimationTrigger {
 
	AAT_BUILT,               ///< Triggered when the airport it build (for all tiles at the same time)
 
	AAT_TILELOOP,            ///< Triggered in the periodic tile loop
 
	AAT_STATION_NEW_CARGO,   ///< Triggered when new cargo arrives at the station (for all tiles at the same time)
 
	AAT_STATION_CARGO_TAKEN, ///< Triggered when a cargo type is completely removed from the station (for all tiles at the same time)
 
	AAT_STATION_250_ticks,   ///< Triggered every 250 ticks (for all tiles at the same time)
 
};
 

	
 
/**
 
 * Defines the data structure of each indivudual tile of an airport.
 
 */
 
struct AirportTileSpec {
 
	uint16 animation_info;                ///< Information about the animation (is it looping, how many loops etc)
 
	uint8 animation_speed;                ///< The speed of the animation
 

	
 
	StringID name;                        ///< Tile Subname string, land information on this tile will give you "AirportName (TileSubname)"
 
	uint8 callback_flags;                 ///< Flags telling which grf callback is set
 
	uint8 animation_triggers;             ///< When to start the animation
 
	uint8 animation_special_flags;        ///< Extra flags to influence the animation
 
	bool enabled;                         ///< entity still available (by default true). newgrf can disable it, though
 
	GRFFileProps grf_prop;                ///< properties related the the grf file
 

	
 
	static const AirportTileSpec *Get(StationGfx gfx);
 

	
 
	static void ResetAirportTiles();
 

	
 
private:
 
	static AirportTileSpec tiles[NUM_AIRPORTTILES];
 

	
 
	friend void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts);
 
};
 

	
 
StationGfx GetTranslatedAirportTileID(StationGfx gfx);
 
void AnimateAirportTile(TileIndex tile);
 
void AirportTileAnimationTrigger(Station *st, TileIndex tile, AirpAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
 
bool DrawNewAirportTile(TileInfo *ti, Station *st, StationGfx gfx, const AirportTileSpec *airts);
 

	
 
#endif /* NEWGRF_AIRPORTTILES_H */
src/openttd.cpp
Show inline comments
 
@@ -268,96 +268,97 @@ md_continue_here:;
 
							if (r[2] != ':')
 
								return -2;
 
							md->numleft++;
 
							t = NULL;
 
						} else {
 
							md->argv++;
 
						}
 
					}
 
					md->opt = t;
 
					md->cont = NULL;
 
					return *s;
 
				}
 
				md->opt = NULL;
 
				md->cont = s;
 
				return *s;
 
			}
 
		} else {
 
			/* This is currently not supported. */
 
			return -2;
 
		}
 
	}
 
}
 

	
 
/**
 
 * Extract the resolution from the given string and store
 
 * it in the 'res' parameter.
 
 * @param res variable to store the resolution in.
 
 * @param s   the string to decompose.
 
 */
 
static void ParseResolution(Dimension *res, const char *s)
 
{
 
	const char *t = strchr(s, 'x');
 
	if (t == NULL) {
 
		ShowInfoF("Invalid resolution '%s'", s);
 
		return;
 
	}
 

	
 
	res->width  = max(strtoul(s, NULL, 0), 64UL);
 
	res->height = max(strtoul(t + 1, NULL, 0), 64UL);
 
}
 

	
 
static void InitializeDynamicVariables()
 
{
 
	/* Dynamic stuff needs to be initialized somewhere... */
 
	_engine_mngr.ResetToDefaultMapping();
 
	_house_mngr.ResetMapping();
 
	_industry_mngr.ResetMapping();
 
	_industile_mngr.ResetMapping();
 
	_airporttile_mngr.ResetMapping();
 
}
 

	
 

	
 
/** Unitializes drivers, frees allocated memory, cleans pools, ...
 
 * Generally, prepares the game for shutting down
 
 */
 
static void ShutdownGame()
 
{
 
	IConsoleFree();
 

	
 
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
 

	
 
	DriverFactoryBase::ShutdownDrivers();
 

	
 
	UnInitWindowSystem();
 

	
 
	/* stop the AI */
 
	AI::Uninitialize(false);
 

	
 
	/* Uninitialize airport state machines */
 
	UnInitializeAirports();
 

	
 
	/* Uninitialize variables that are allocated dynamically */
 
	GamelogReset();
 
	_town_pool.CleanPool();
 
	_industry_pool.CleanPool();
 
	_station_pool.CleanPool();
 
	_roadstop_pool.CleanPool();
 
	_vehicle_pool.CleanPool();
 
	_sign_pool.CleanPool();
 
	_order_pool.CleanPool();
 
	_group_pool.CleanPool();
 
	_cargopacket_pool.CleanPool();
 
	_engine_pool.CleanPool();
 
	_company_pool.CleanPool();
 

	
 
	free(_config_file);
 

	
 
	/* Close all and any open filehandles */
 
	FioCloseAll();
 
}
 

	
 
static void LoadIntroGame()
 
{
 
	_game_mode = GM_MENU;
 

	
 
	ResetGRFConfig(false);
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -2184,137 +2184,134 @@ CommandCost CmdBuildAirport(TileIndex ti
 

	
 
		/* Only call the animation trigger after all tiles have been built */
 
		it = as->table[0];
 
		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);
 

	
 
		st->UpdateVirtCoord();
 
		UpdateStationAcceptance(st, false);
 
		st->RecomputeIndustriesNear();
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_PLANES);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
/**
 
 * Remove an airport
 
 * @param tile TileIndex been queried
 
 * @param flags operation to perform
 
 * @return cost or failure of operation
 
 */
 
static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
 
{
 
	Station *st = Station::GetByTile(tile);
 

	
 
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	tile = st->airport.tile;
 

	
 
	const AirportSpec *as = st->GetAirportSpec();
 
	int w = as->size_x;
 
	int h = as->size_y;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	const Aircraft *a;
 
	FOR_ALL_AIRCRAFT(a) {
 
		if (!a->IsNormalAircraft()) continue;
 
		if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
 
	}
 

	
 
	TILE_AREA_LOOP(tile_cur, st->airport) {
 
		if (!st->TileBelongsToAirport(tile_cur)) continue;
 

	
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		CommandCost ret = EnsureNoVehicleOnGround(tile_cur);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 

	
 
		cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
 

	
 
		if (flags & DC_EXEC) {
 
			DeleteAnimatedTile(tile_cur);
 
			DoClearSquare(tile_cur);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		const AirportSpec *as = st->GetAirportSpec();
 
		for (uint i = 0; i < as->nof_depots; ++i) {
 
			DeleteWindowById(
 
				WC_VEHICLE_DEPOT, st->GetHangarTile(i)
 
			);
 
		}
 

	
 
		/* Go get the final noise level, that is base noise minus factor from distance to town center.
 
		 * And as for construction, always remove it, even if the setting is not set, in order to avoid the
 
		 * need of recalculation */
 
		Town *nearest = AirportGetNearestTown(as, tile);
 
		nearest->noise_reached -= GetAirportNoiseLevelForTown(as, nearest->xy, tile);
 

	
 
		st->rect.AfterRemoveRect(st, tile, w, h);
 
		st->rect.AfterRemoveRect(st, tile, st->airport.w, st->airport.h);
 

	
 
		st->airport.Clear();
 
		st->facilities &= ~FACIL_AIRPORT;
 

	
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_PLANES);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
 
		}
 

	
 
		st->UpdateVirtCoord();
 
		st->RecomputeIndustriesNear();
 
		DeleteStationIfEmpty(st);
 
	}
 

	
 
	return cost;
 
}
 

	
 
/**
 
 * Tests whether the company's vehicles have this station in orders
 
 * When company == INVALID_COMPANY, then check all vehicles
 
 * @param station station ID
 
 * @param company company ID, INVALID_COMPANY to disable the check
 
 */
 
bool HasStationInUse(StationID station, CompanyID company)
 
{
 
	const Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (company == INVALID_COMPANY || v->owner == company) {
 
			const Order *order;
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station) {
 
					return true;
 
				}
 
			}
 
		}
 
	}
 
	return false;
 
}
 

	
 
static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
 
	{-1,  0},
 
	{ 0,  0},
 
	{ 0,  0},
 
	{ 0, -1}
 
};
 
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
 
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
0 comments (0 inline, 0 general)