File diff r3314:95a9020945e1 → r3315:71e0b8841575
station_cmd.c
Show inline comments
 
@@ -4,12 +4,13 @@
 
  */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "functions.h"
 
#include "station_map.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "map.h"
 
#include "tile.h"
 
#include "station.h"
 
#include "gfx.h"
 
@@ -107,13 +108,13 @@ RoadStop* GetPrimaryRoadStop(const Stati
 

	
 
	return NULL;
 
}
 

	
 
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
 
{
 
	const Station* st = GetStation(_m[tile].m2);
 
	const Station* st = GetStationByTile(tile);
 
	RoadStop* rs;
 

	
 
	for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) {
 
		assert(rs->next != NULL);
 
	}
 

	
 
@@ -181,13 +182,13 @@ static uint FindCatchmentRadius(const St
 

	
 
static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
 
{
 
	// check around to see if there's any stations there
 
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
		if (IsTileType(tile_cur, MP_STATION)) {
 
			StationID t = _m[tile_cur].m2;
 
			StationID t = GetStationIndex(tile_cur);
 
			{
 
				Station *st = GetStation(t);
 
				// you cannot take control of an oilrig!!
 
				if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK))
 
					continue;
 
			}
 
@@ -229,13 +230,13 @@ static bool CheckStationSpreadOut(Statio
 
	uint y1 = TileY(tile);
 
	uint x2 = x1 + w - 1;
 
	uint y2 = y1 + h - 1;
 
	uint t;
 

	
 
	for (i = 0; i != MapSize(); i++) {
 
		if (IsTileType(i, MP_STATION) && _m[i].m2 == station_index) {
 
		if (IsTileType(i, MP_STATION) && GetStationIndex(i) == station_index) {
 
			t = TileX(i);
 
			if (t < x1) x1 = t;
 
			if (t > x2) x2 = t;
 

	
 
			t = TileY(i);
 
			if (t < y1) y1 = t;
 
@@ -794,13 +795,13 @@ int32 CheckFlatLandBelow(TileIndex tile,
 
		// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build
 
		// on exactly that station.
 
		if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
 
			if (_m[tile_cur].m5 >= 8) {
 
				return ClearTile_Station(tile_cur, DC_AUTO); // get error message
 
			} else {
 
				StationID st = _m[tile_cur].m2;
 
				StationID st = GetStationIndex(tile_cur);
 
				if (*station == INVALID_STATION) {
 
					*station = st;
 
				} else if (*station != st) {
 
					return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING);
 
				}
 
			}
 
@@ -1066,13 +1067,13 @@ int32 CmdBuildRailroadStation(int x, int
 

	
 
	return cost;
 
}
 

	
 
static bool TileBelongsToRailStation(const Station *st, TileIndex tile)
 
{
 
	return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8;
 
	return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st->index && _m[tile].m5 < 8;
 
}
 

	
 
static void MakeRailwayStationAreaSmaller(Station *st)
 
{
 
	uint w = st->trainst_w;
 
	uint h = st->trainst_h;
 
@@ -1141,13 +1142,13 @@ int32 CmdRemoveFromRailroadStation(int x
 
	Station *st;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	// make sure the specified tile belongs to the current player, and that it is a railroad station.
 
	if (!IsTileType(tile, MP_STATION) || _m[tile].m5 >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
 
	st = GetStation(_m[tile].m2);
 
	st = GetStationByTile(tile);
 
	if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR;
 

	
 
	// if we reached here, it means we can actually delete it. do that.
 
	if (flags & DC_EXEC) {
 
		Track track = HASBIT(_m[tile].m5, 0) ? TRACK_Y : TRACK_X;
 
		DoClearSquare(tile);
 
@@ -1249,13 +1250,14 @@ static int32 RemoveRailroadStation(Stati
 

	
 
	return cost;
 
}
 

	
 
int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
 
{
 
	const Station *st = GetStation(_m[tile].m2);
 
	const Station* st = GetStationByTile(tile);
 

	
 
	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	// tile is not a railroad station?
 
	if (_m[tile].m5 >= 8) return CMD_ERROR;
 

	
 
	if (GetRailType(tile) == totype) return CMD_ERROR;
 
@@ -1968,13 +1970,13 @@ static void DrawTile_Station(TileInfo *t
 
		// look for customization
 
		const StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _m[ti->tile].m4);
 

	
 
		//debug("Cust-o-mized %p", statspec);
 

	
 
		if (statspec != NULL) {
 
			const Station* st = GetStation(_m[ti->tile].m2);
 
			const Station* st = GetStationByTile(ti->tile);
 

	
 
			relocation = GetCustomStationRelocation(statspec, st, 0);
 
			//debug("Relocation %d", relocation);
 
			t = &statspec->renderdata[ti->map5];
 
		}
 
	}
 
@@ -2048,13 +2050,13 @@ static void GetAcceptedCargo_Station(Til
 
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
 
{
 
	byte m5;
 
	StringID str;
 

	
 
	td->owner = GetTileOwner(tile);
 
	td->build_date = GetStation(_m[tile].m2)->build_date;
 
	td->build_date = GetStationByTile(tile)->build_date;
 

	
 
	m5 = _m[tile].m5;
 
	(str=STR_305E_RAILROAD_STATION, m5 < 8) ||
 
	(str=STR_305F_AIRCRAFT_HANGAR, m5==32 || m5==45) || // hangars
 
	(str=STR_3060_AIRPORT, m5 < 0x43 || (m5 >= 83 && m5 <= 114)) ||
 
	(str=STR_3061_TRUCK_LOADING_AREA, m5 < 0x47) ||
 
@@ -2163,26 +2165,26 @@ static void ClickTile_Station(TileIndex 
 
{
 
  // 0x20 - hangar large airport (32)
 
  // 0x41 - hangar small airport (65)
 
	if (_m[tile].m5 == 32 || _m[tile].m5 == 65) {
 
		ShowAircraftDepotWindow(tile);
 
	} else {
 
		ShowStationViewWindow(_m[tile].m2);
 
		ShowStationViewWindow(GetStationIndex(tile));
 
	}
 
}
 

	
 
static const byte _enter_station_speedtable[12] = {
 
	215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0
 
};
 

	
 
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
 
{
 
	if (v->type == VEH_Train) {
 
		if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) &&
 
				!IsCompatibleTrainStationTile(tile + TileOffsByDir(DirToDiagDir(v->direction)), tile)) {
 
			StationID station_id = _m[tile].m2;
 
			StationID station_id = GetStationIndex(tile);
 

	
 
			if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
 
					(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
 
				if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) &&
 
						v->current_order.type != OT_LEAVESTATION &&
 
						v->last_station_visited != station_id) {
 
@@ -2560,13 +2562,13 @@ uint MoveGoodsToStation(TileIndex tile, 
 
	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
 
		Station* st;
 

	
 
		cur_tile = TILE_MASK(cur_tile);
 
		if (!IsTileType(cur_tile, MP_STATION)) continue;
 

	
 
		st = GetStation(_m[cur_tile].m2);
 
		st = GetStationByTile(cur_tile);
 

	
 
		for (i = 0; i != lengthof(around); i++) {
 
			if (around[i] == NULL) {
 
				if (!IsBuoy(st) &&
 
						(st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights
 
						st->goods[type].rating != 0 &&
 
@@ -2718,13 +2720,13 @@ void BuildOilRig(TileIndex tile)
 
	UpdateStationVirtCoordDirty(st);
 
	UpdateStationAcceptance(st, false);
 
}
 

	
 
void DeleteOilRig(TileIndex tile)
 
{
 
	Station *st = GetStation(_m[tile].m2);
 
	Station* st = GetStationByTile(tile);
 

	
 
	DoClearSquare(tile);
 

	
 
	st->dock_tile = 0;
 
	st->airport_tile = 0;
 
	st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
 
@@ -2735,13 +2737,14 @@ void DeleteOilRig(TileIndex tile)
 

	
 
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player)
 
{
 
	if (!IsTileOwner(tile, old_player)) return;
 

	
 
	if (new_player != OWNER_SPECTATOR) {
 
		Station *st = GetStation(_m[tile].m2);
 
		Station* st = GetStationByTile(tile);
 

	
 
		SetTileOwner(tile, new_player);
 
		st->owner = new_player;
 
		_global_station_sort_dirty = true; // transfer ownership of station to another player
 
		InvalidateWindowClasses(WC_STATION_LIST);
 
	} else {
 
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
@@ -2761,13 +2764,13 @@ static int32 ClearTile_Station(TileIndex
 
		if (m5 == 0x52) return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
 
		if (m5 != 0x4B && m5 < 0x53) return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
 
		SetDParam(0, STR_4807_OIL_RIG);
 
		return_cmd_error(STR_4800_IN_THE_WAY);
 
	}
 

	
 
	st = GetStation(_m[tile].m2);
 
	st = GetStationByTile(tile);
 

	
 
	if (m5 < 8) return RemoveRailroadStation(st, tile, flags);
 
	// original airports < 67, new airports between 83 - 114
 
	if (m5 < 0x43 || (m5 >= 83 && m5 <= 114)) return RemoveAirport(st, flags);
 
	if (m5 < 0x4B) return RemoveRoadStop(st, flags, tile);
 
	if (m5 == 0x52) return RemoveBuoy(st, flags);