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
 
@@ -421,15 +421,12 @@ bool AfterLoadGame()
 
			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;
 
@@ -444,18 +441,12 @@ bool AfterLoadGame()
 

	
 
		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)) {
src/saveload/saveload.cpp
Show inline comments
 
@@ -38,13 +38,13 @@
 
#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!
src/saveload/saveload_internal.h
Show inline comments
 
@@ -13,14 +13,12 @@
 

	
 
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();
 

	
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -7,12 +7,13 @@
 
#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()
 
@@ -31,45 +32,31 @@ void AfterLoadWaypoints()
 
				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()
 
{
 
@@ -83,14 +70,41 @@ static void Save_WAYP()
 

	
 
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
 
@@ -858,13 +858,13 @@ static char *FormatString(char *buff, co
 
				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;
src/waypoint.cpp
Show inline comments
 
@@ -54,13 +54,13 @@ Station *ComposeWaypointStation(TileInde
 
	/* 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;
 
}
 

	
 
/**
src/waypoint.h
Show inline comments
 
@@ -17,15 +17,14 @@
 
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
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -42,13 +42,13 @@ void Waypoint::UpdateVirtCoord()
 
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).
 
@@ -61,13 +61,13 @@ static void MakeDefaultWaypointName(Wayp
 
	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) {
 
@@ -161,13 +161,13 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
	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
 
@@ -203,13 +203,13 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
			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);
0 comments (0 inline, 0 general)