Changeset - r12411:4ac6b3dd713f
[Not reviewed]
master
0 8 0
rubidium - 15 years ago 2009-07-16 23:02:39
rubidium@openttd.org
(svn r16855) -Codechange: remove unused 'conversion' stuff from the waypoint struct and make it more similar to Station.
8 files changed with 53 insertions and 51 deletions:
0 comments (0 inline, 0 general)
src/saveload/afterload.cpp
Show inline comments
 
@@ -403,77 +403,68 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	/* in version 2.1 of the savegame, town owner was unified. */
 
	if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
 

	
 
	/* from version 4.1 of the savegame, exclusive rights are stored at towns */
 
	if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
 

	
 
	/* from version 4.2 of the savegame, currencies are in a different order */
 
	if (CheckSavegameVersionOldStyle(4, 2)) UpdateCurrencies();
 

	
 
	/* In old version there seems to be a problem that water is owned by
 
	 * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
 
	 * (4.3) version, so I just check when versions are older, and then
 
	 * walk through the whole map.. */
 
	if (CheckSavegameVersionOldStyle(4, 3)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
 
				SetTileOwner(t, OWNER_WATER);
 
			}
 
		}
 
	}
 

	
 
	/* Update all waypoints */
 
	if (CheckSavegameVersion(12)) FixOldWaypoints();
 

	
 
	if (CheckSavegameVersion(84)) {
 
		FOR_ALL_COMPANIES(c) {
 
			c->name = CopyFromOldName(c->name_1);
 
			if (c->name != NULL) c->name_1 = STR_SV_UNNAMED;
 
			c->president_name = CopyFromOldName(c->president_name_1);
 
			if (c->president_name != NULL) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
 
		}
 

	
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			st->name = CopyFromOldName(st->string_id);
 
			/* generating new name would be too much work for little effect, use the station name fallback */
 
			if (st->name != NULL) st->string_id = STR_SV_STNAME_FALLBACK;
 
		}
 

	
 
		Town *t;
 
		FOR_ALL_TOWNS(t) {
 
			t->name = CopyFromOldName(t->townnametype);
 
			if (t->name != NULL) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
 
		}
 

	
 
		Waypoint *wp;
 
		FOR_ALL_WAYPOINTS(wp) {
 
			wp->name = CopyFromOldName(wp->string_id);
 
			wp->string_id = STR_NULL;
 
		}
 
	}
 

	
 
	/* From this point the old names array is cleared. */
 
	ResetOldNames();
 

	
 
	if (CheckSavegameVersion(106)) {
 
		/* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			if (st->airport_tile == 0) st->airport_tile = INVALID_TILE;
 
			if (st->dock_tile    == 0) st->dock_tile    = INVALID_TILE;
 
			if (st->train_tile   == 0) st->train_tile   = INVALID_TILE;
 
		}
 

	
 
		/* the same applies to Company::location_of_HQ */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
			if (c->location_of_HQ == 0 || (CheckSavegameVersion(4) && c->location_of_HQ == 0xFFFF)) {
 
				c->location_of_HQ = INVALID_TILE;
 
			}
 
		}
 
	}
 

	
 
	/* convert road side to my format. */
src/saveload/saveload.cpp
Show inline comments
 
@@ -20,49 +20,49 @@
 
#include "../thread.h"
 
#include "../town.h"
 
#include "../network/network.h"
 
#include "../variables.h"
 
#include "../window_func.h"
 
#include "../strings_func.h"
 
#include "../gfx_func.h"
 
#include "../core/alloc_func.hpp"
 
#include "../core/endian_func.hpp"
 
#include "../vehicle_base.h"
 
#include "../company_func.h"
 
#include "../date_func.h"
 
#include "../autoreplace_base.h"
 
#include "../roadstop_base.h"
 
#include "../statusbar_gui.h"
 
#include "../fileio_func.h"
 
#include "../gamelog.h"
 
#include "../string_func.h"
 
#include "../engine_base.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "saveload_internal.h"
 

	
 
extern const uint16 SAVEGAME_VERSION = 121;
 
extern const uint16 SAVEGAME_VERSION = 122;
 

	
 
SavegameType _savegame_type; ///< type of savegame we are loading
 

	
 
uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
char _savegame_format[8]; ///< how to compress savegames
 

	
 
typedef void WriterProc(size_t len);
 
typedef size_t ReaderProc();
 

	
 
/** What are we currently doing? */
 
enum SaveLoadAction {
 
	SLA_LOAD, ///< loading
 
	SLA_SAVE, ///< saving
 
	SLA_PTRS, ///< fixing pointers
 
};
 

	
 
enum NeedLength {
 
	NL_NONE = 0,       ///< not working in NeedLength mode
 
	NL_WANTLENGTH = 1, ///< writing length and data
 
	NL_CALCLENGTH = 2, ///< need to calculate the length
 
};
 

	
src/saveload/saveload_internal.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file saveload_internal.h Declaration of functions used in more save/load files */
 

	
 
#ifndef SAVELOAD_INTERNAL_H
 
#define SAVELOAD_INTERNAL_H
 

	
 
#include "../strings_type.h"
 
#include "../company_manager_face.h"
 
#include "../order_base.h"
 
#include "../engine_type.h"
 
#include "saveload.h"
 

	
 
void InitializeOldNames();
 
StringID RemapOldStringID(StringID s);
 
char *CopyFromOldName(StringID id);
 
void ResetOldNames();
 

	
 
void FixOldWaypoints();
 

	
 
void AfterLoadWaypoints();
 
void AfterLoadVehicles(bool part_of_load);
 
void AfterLoadStations();
 
void AfterLoadLabelMaps();
 
void UpdateHousesAndTowns();
 

	
 
void UpdateOldAircraft();
 

	
 
void SaveViewportBeforeSaveGame();
 
void ResetViewportAfterLoadGame();
 

	
 
void ConvertOldMultiheadToNew();
 
void ConnectMultiheadedTrains();
 

	
 
Engine *GetTempDataEngine(EngineID index);
 
void CopyTempEngineData();
 

	
 
extern int32 _saved_scrollpos_x;
 
extern int32 _saved_scrollpos_y;
 

	
 
extern SavegameType _savegame_type;
 
extern uint32 _ttdp_version;
 

	
 
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face);
src/saveload/waypoint_sl.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file waypoint_sl.cpp Code handling saving and loading of waypoints */
 

	
 
#include "../stdafx.h"
 
#include "../waypoint.h"
 
#include "../newgrf_station.h"
 
#include "../town.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "saveload.h"
 
#include "saveload_internal.h"
 

	
 
/**
 
 * Update waypoint graphics id against saved GRFID/localidx.
 
 * This is to ensure the chosen graphics are correct if GRF files are changed.
 
 */
 
void AfterLoadWaypoints()
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		uint i;
 

	
 
		if (wp->spec.grfid == 0) continue;
 

	
 
		for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) {
 
			const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i);
 
			if (statspec != NULL && statspec->grffile->grfid == wp->spec.grfid && statspec->localidx == wp->spec.localidx) {
 
				wp->spec.spec = statspec;
 
				break;
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Fix savegames which stored waypoints in their old format
 
 */
 
void FixOldWaypoints()
 
{
 
	Waypoint *wp;
 

	
 
	/* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */
 
	FOR_ALL_WAYPOINTS(wp) {
 
		wp->town_index = ClosestTownFromTile(wp->xy, UINT_MAX)->index;
 
		wp->town_cn = 0;
 
		if ((wp->string_id & 0xC000) == 0xC000) {
 
			wp->town_cn = (wp->string_id >> 8) & 0x3F;
 
			wp->string_id = STR_NULL;
 
		}
 
	}
 
}
 
static uint16 _waypoint_town_index;
 
static StringID _waypoint_string_id;
 

	
 
static const SaveLoad _waypoint_desc[] = {
 
	SLE_CONDVAR(Waypoint, xy,            SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
 
	SLE_CONDVAR(Waypoint, xy,            SLE_UINT32,                  6, SL_MAX_VERSION),
 
	SLE_CONDVAR(Waypoint, town_index,    SLE_UINT16,                 12, SL_MAX_VERSION),
 
	SLE_CONDVAR(Waypoint, town_cn,       SLE_FILE_U8 | SLE_VAR_U16,  12, 88),
 
	SLE_CONDVAR(Waypoint, town_cn,       SLE_UINT16,                 89, SL_MAX_VERSION),
 
	SLE_CONDVAR(Waypoint, string_id,     SLE_STRINGID,                0, 83),
 
	SLE_CONDSTR(Waypoint, name,          SLE_STR, 0,                 84, SL_MAX_VERSION),
 
	    SLE_VAR(Waypoint, delete_ctr,    SLE_UINT8),
 
	 SLE_CONDVAR(Waypoint, xy,            SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
 
	 SLE_CONDVAR(Waypoint, xy,            SLE_UINT32,                  6, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_waypoint_town_index,    SLE_UINT16,                 12, 121),
 
	 SLE_CONDREF(Waypoint, town,          REF_TOWN,                  122, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Waypoint, town_cn,       SLE_FILE_U8 | SLE_VAR_U16,  12, 88),
 
	 SLE_CONDVAR(Waypoint, town_cn,       SLE_UINT16,                 89, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_waypoint_string_id,     SLE_STRINGID,                0, 83),
 
	 SLE_CONDSTR(Waypoint, name,          SLE_STR, 0,                 84, SL_MAX_VERSION),
 
	     SLE_VAR(Waypoint, delete_ctr,    SLE_UINT8),
 

	
 
	SLE_CONDVAR(Waypoint, build_date,    SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
 
	SLE_CONDVAR(Waypoint, build_date,    SLE_INT32,                  31, SL_MAX_VERSION),
 
	SLE_CONDVAR(Waypoint, spec.localidx, SLE_UINT8,                   3, SL_MAX_VERSION),
 
	SLE_CONDVAR(Waypoint, spec.grfid,    SLE_UINT32,                 17, SL_MAX_VERSION),
 
	SLE_CONDVAR(Waypoint, owner,         SLE_UINT8,                 101, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Waypoint, build_date,    SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
 
	 SLE_CONDVAR(Waypoint, build_date,    SLE_INT32,                  31, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Waypoint, spec.localidx, SLE_UINT8,                   3, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Waypoint, spec.grfid,    SLE_UINT32,                 17, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Waypoint, owner,         SLE_UINT8,                 101, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_WAYP()
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		SlSetArrayIndex(wp->index);
 
		SlObject(wp, _waypoint_desc);
 
	}
 
}
 

	
 
static void Load_WAYP()
 
{
 
	int index;
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		_waypoint_string_id = 0;
 
		_waypoint_town_index = 0;
 

	
 
		Waypoint *wp = new (index) Waypoint();
 
		SlObject(wp, _waypoint_desc);
 

	
 
		if (CheckSavegameVersion(84)) wp->name = (char *)(size_t)_waypoint_string_id;
 
		if (CheckSavegameVersion(122)) wp->town = (Town *)(size_t)_waypoint_town_index;
 
	}
 
}
 

	
 
static void Ptrs_WAYP()
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		SlObject(wp, _waypoint_desc);
 

	
 
		StringID sid = (StringID)(size_t)wp->name;
 
		if (CheckSavegameVersion(12)) {
 
			wp->town_cn = (sid & 0xC000) == 0xC000 ? (sid >> 8) & 0x3F : 0;
 
			wp->town = ClosestTownFromTile(wp->xy, UINT_MAX);
 
		} else if (CheckSavegameVersion(122)) {
 
			/* Only for versions 12 .. 122 */
 
			wp->town = Town::Get((size_t)wp->town);
 
		}
 
		if (CheckSavegameVersion(84)) {
 
			wp->name = CopyFromOldName(sid);
 
		}
 
	}
 
}
 

	
 
extern const ChunkHandler _waypoint_chunk_handlers[] = {
 
	{ 'CHKP', Save_WAYP, Load_WAYP, NULL, CH_ARRAY | CH_LAST},
 
	{ 'CHKP', Save_WAYP, Load_WAYP, Ptrs_WAYP, CH_ARRAY | CH_LAST},
 
};
src/strings.cpp
Show inline comments
 
@@ -840,49 +840,49 @@ static char *FormatString(char *buff, co
 
				buff = FormatNoCommaNumber(buff, GetInt64(&argv), last);
 
				break;
 

	
 
			case SCC_HEX: // {HEX}
 
				buff = FormatHexNumber(buff, GetInt64(&argv), last);
 
				break;
 

	
 
			case SCC_BYTES: // {BYTES}
 
				buff = FormatBytes(buff, GetInt64(&argv), last);
 
				break;
 

	
 
			case SCC_CURRENCY: // {CURRENCY}
 
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
 
				break;
 

	
 
			case SCC_WAYPOINT_NAME: { // {WAYPOINT}
 
				Waypoint *wp = Waypoint::Get(GetInt32(&argv));
 

	
 
				assert(wp != NULL);
 

	
 
				if (wp->name != NULL) {
 
					buff = strecpy(buff, wp->name, last);
 
				} else {
 
					int64 temp[2];
 
					temp[0] = wp->town_index;
 
					temp[0] = wp->town->index;
 
					temp[1] = wp->town_cn + 1;
 
					StringID str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL;
 

	
 
					buff = GetStringWithArgs(buff, str, temp, last);
 
				}
 
				break;
 
			}
 

	
 
			case SCC_STATION_NAME: { // {STATION}
 
				StationID sid = GetInt32(&argv);
 
				const Station *st = Station::GetIfValid(sid);
 

	
 
				if (st == NULL) {
 
					/* The station doesn't exist anymore. The only place where we might
 
					 * be "drawing" an invalid station is in the case of cargo that is
 
					 * in transit. */
 
					buff = GetStringWithArgs(buff, STR_UNKNOWN_STATION, NULL, last);
 
					break;
 
				}
 

	
 
				if (st->name != NULL) {
 
					buff = strecpy(buff, st->name, last);
 
				} else {
 
					StringID str = st->string_id;
src/waypoint.cpp
Show inline comments
 
@@ -36,49 +36,49 @@ void WaypointsDailyLoop()
 
{
 
	Waypoint *wp;
 

	
 
	/* Check if we need to delete a waypoint */
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->delete_ctr != 0 && --wp->delete_ctr == 0) delete wp;
 
	}
 
}
 

	
 
/**
 
 * This hacks together some dummy one-shot Station structure for a waypoint.
 
 * @param tile on which to work
 
 * @return pointer to a Station
 
 */
 
Station *ComposeWaypointStation(TileIndex tile)
 
{
 
	Waypoint *wp = GetWaypointByTile(tile);
 

	
 
	/* instead of 'static Station stat' use byte array to avoid Station's destructor call upon exit. As
 
	 * a side effect, the station is not constructed now. */
 
	static byte stat_raw[sizeof(Station)];
 
	static Station &stat = *(Station*)stat_raw;
 

	
 
	stat.train_tile = stat.xy = wp->xy;
 
	stat.town = Town::Get(wp->town_index);
 
	stat.town = wp->town;
 
	stat.build_date = wp->build_date;
 

	
 
	return &stat;
 
}
 

	
 
/**
 
 * Draw a waypoint
 
 * @param x coordinate
 
 * @param y coordinate
 
 * @param stat_id station id
 
 * @param railtype RailType to use for
 
 */
 
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
 
{
 
	x += 33;
 
	y += 17;
 

	
 
	if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
 
		DrawDefaultWaypointSprite(x, y, railtype);
 
	}
 
}
 

	
 
Waypoint::~Waypoint()
 
{
src/waypoint.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file waypoint.h Base of waypoints. */
 

	
 
#ifndef WAYPOINT_H
 
#define WAYPOINT_H
 

	
 
#include "waypoint_type.h"
 
#include "rail_map.h"
 
#include "command_type.h"
 
#include "station_base.h"
 
#include "town_type.h"
 
#include "viewport_type.h"
 
#include "date_type.h"
 
#include "core/pool_type.hpp"
 

	
 
typedef Pool<Waypoint, WaypointID, 32, 64000> WaypointPool;
 
extern WaypointPool _waypoint_pool;
 

	
 
struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool> {
 
	TileIndex xy;      ///< Tile of waypoint
 

	
 
	TownID town_index; ///< Town associated with the waypoint
 
	Town *town;        ///< Town associated with the waypoint
 
	uint16 town_cn;    ///< The Nth waypoint for this town (consecutive number)
 
	StringID string_id;///< C000-C03F have special meaning in old games
 
	char *name;        ///< Custom name. If not set, town + town_cn is used for naming
 

	
 
	ViewportSign sign; ///< Dimensions of sign (not saved)
 
	Date build_date;   ///< Date of construction
 
	OwnerByte owner;   ///< Whom this waypoint belongs to
 

	
 
	StationSpecList spec; ///< NewGRF specification of the station
 

	
 
	byte delete_ctr;   ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
 

	
 
	Waypoint(TileIndex tile = INVALID_TILE) : xy(tile) { }
 
	~Waypoint();
 

	
 
	void UpdateVirtCoord();
 
};
 

	
 
#define FOR_ALL_WAYPOINTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Waypoint, waypoint_index, var, start)
 
#define FOR_ALL_WAYPOINTS(var) FOR_ALL_WAYPOINTS_FROM(var, 0)
 

	
 

	
 
/**
 
 * Fetch a waypoint by tile
 
 * @param tile Tile of waypoint
 
 * @return Waypoint
src/waypoint_cmd.cpp
Show inline comments
 
@@ -24,68 +24,68 @@
 
#include "train.h"
 

	
 
#include "table/strings.h"
 

	
 
/**
 
 * Update the virtual coords needed to draw the waypoint sign.
 
 */
 
void Waypoint::UpdateVirtCoord()
 
{
 
	Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
 
	SetDParam(0, this->index);
 
	this->sign.UpdatePosition(pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT);
 
}
 

	
 
/**
 
 * Set the default name for a waypoint
 
 * @param wp Waypoint to work on
 
 */
 
static void MakeDefaultWaypointName(Waypoint *wp)
 
{
 
	uint32 used = 0; // bitmap of used waypoint numbers, sliding window with 'next' as base
 
	uint32 next = 0; // first waypoint number in the bitmap
 
	WaypointID idx = 0; // index where we will stop
 

	
 
	wp->town_index = ClosestTownFromTile(wp->xy, UINT_MAX)->index;
 
	wp->town = ClosestTownFromTile(wp->xy, UINT_MAX);
 

	
 
	/* Find first unused waypoint number belonging to this town. This can never fail,
 
	 * as long as there can be at most 65535 waypoints in total.
 
	 *
 
	 * This does 'n * m' search, but with 32bit 'used' bitmap, it needs at most 'n * (1 + ceil(m / 32))'
 
	 * steps (n - number of waypoints in pool, m - number of waypoints near this town).
 
	 * Usually, it needs only 'n' steps.
 
	 *
 
	 * If it wasn't using 'used' and 'idx', it would just search for increasing 'next',
 
	 * but this way it is faster */
 

	
 
	WaypointID cid = 0; // current index, goes to Waypoint::GetPoolSize()-1, then wraps to 0
 
	do {
 
		Waypoint *lwp = Waypoint::Get(cid);
 

	
 
		/* check only valid waypoints... */
 
		if (lwp != NULL && wp != lwp) {
 
			/* only waypoints with 'generic' name within the same city */
 
			if (lwp->name == NULL && lwp->town_index == wp->town_index) {
 
			if (lwp->name == NULL && lwp->town == wp->town) {
 
				/* if lwp->town_cn < next, uint will overflow to '+inf' */
 
				uint i = (uint)lwp->town_cn - next;
 

	
 
				if (i < 32) {
 
					SetBit(used, i); // update bitmap
 
					if (i == 0) {
 
						/* shift bitmap while the lowest bit is '1';
 
						 * increase the base of the bitmap too */
 
						do {
 
							used >>= 1;
 
							next++;
 
						} while (HasBit(used, 0));
 
						/* when we are at 'idx' again at end of the loop and
 
						 * 'next' hasn't changed, then no waypoint had town_cn == next,
 
						 * so we can safely use it */
 
						idx = cid;
 
					}
 
				}
 
			}
 
		}
 

	
 
		cid++;
 
		if (cid == Waypoint::GetPoolSize()) cid = 0; // wrap to zero...
 
	} while (cid != idx);
 
@@ -143,91 +143,91 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
			)) {
 
		return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
 
	}
 

	
 
	Owner owner = GetTileOwner(tile);
 
	if (!CheckOwnership(owner)) return CMD_ERROR;
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	tileh = GetTileSlope(tile, NULL);
 
	if (tileh != SLOPE_FLAT &&
 
			(!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
 
		return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
	}
 

	
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
 
	wp = FindDeletedWaypointCloseTo(tile);
 
	if (wp == NULL && !Waypoint::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (wp == NULL) {
 
			wp = new Waypoint(tile);
 

	
 
			wp->town_index = INVALID_TOWN;
 
			wp->town = NULL;
 
			wp->name = NULL;
 
			wp->town_cn = 0;
 
		} else {
 
			/* Move existing (recently deleted) waypoint to the new location */
 

	
 
			/* First we update the destination for all vehicles that
 
			 * have the old waypoint in their orders. */
 
			Vehicle *v;
 
			FOR_ALL_TRAINS(v) {
 
				if (v->First() == v && v->current_order.IsType(OT_GOTO_WAYPOINT) &&
 
						v->dest_tile == wp->xy) {
 
					v->dest_tile = tile;
 
				}
 
			}
 

	
 
			wp->xy = tile;
 
			InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
		}
 
		wp->owner = owner;
 

	
 
		bool reserved = HasBit(GetTrackReservation(tile), AxisToTrack(axis));
 
		MakeRailWaypoint(tile, owner, axis, GetRailType(tile), wp->index);
 
		SetDepotWaypointReservation(tile, reserved);
 
		MarkTileDirtyByTile(tile);
 

	
 
		const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, p1);
 

	
 
		if (statspec != NULL) {
 
			wp->spec.spec = statspec;
 
			wp->spec.grfid = statspec->grffile->grfid;
 
			wp->spec.localidx = statspec->localidx;
 
		} else {
 
			/* Specified custom graphics do not exist, so use default. */
 
			wp->spec.spec = NULL;
 
			wp->spec.grfid = 0;
 
			wp->spec.localidx = 0;
 
		}
 

	
 
		wp->delete_ctr = 0;
 
		wp->build_date = _date;
 

	
 
		if (wp->town_index == INVALID_TOWN) MakeDefaultWaypointName(wp);
 
		if (wp->town == NULL) MakeDefaultWaypointName(wp);
 

	
 
		wp->UpdateVirtCoord();
 
		YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot);
 
}
 

	
 
/**
 
 * Remove a waypoint
 
 * @param tile from which to remove waypoint
 
 * @param flags type of operation
 
 * @param justremove will indicate if it is removed from rail or if rails are removed too
 
 * @return cost of operation or error
 
 */
 
CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, bool justremove)
 
{
 
	Waypoint *wp;
 

	
 
	/* Make sure it's a waypoint */
 
	if (!IsRailWaypointTile(tile) ||
 
			(!CheckTileOwnership(tile) && _current_company != OWNER_WATER) ||
 
			!EnsureNoVehicleOnGround(tile)) {
 
		return CMD_ERROR;
0 comments (0 inline, 0 general)