(svn r19799) -Change: give depots an unique name in the same manner buoys and waypoints are named

pull/155/head
rubidium 14 years ago
parent 92648be718
commit 7f43b93eae

@ -19,8 +19,11 @@ typedef Pool<Depot, DepotID, 64, 64000> DepotPool;
extern DepotPool _depot_pool; extern DepotPool _depot_pool;
struct Depot : DepotPool::PoolItem<&_depot_pool> { struct Depot : DepotPool::PoolItem<&_depot_pool> {
Town *town;
const char *name;
TileIndex xy; TileIndex xy;
TownID town_index; uint16 town_cn; ///< The Nth depot for this town (consecutive number)
Depot(TileIndex xy = INVALID_TILE) : xy(xy) {} Depot(TileIndex xy = INVALID_TILE) : xy(xy) {}
~Depot(); ~Depot();
@ -29,6 +32,17 @@ struct Depot : DepotPool::PoolItem<&_depot_pool> {
{ {
return Depot::Get(GetDepotIndex(tile)); return Depot::Get(GetDepotIndex(tile));
} }
/**
* Is the "type" of depot the same as the given depot,
* i.e. are both a rail, road or ship depots?
* @param d The depot to compare to.
* @return true iff their types are equal.
*/
FORCEINLINE bool IsOfType(const Depot *d) const
{
return GetTileType(d->xy) == GetTileType(this->xy);
}
}; };
#define FOR_ALL_DEPOTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Depot, depot_index, var, start) #define FOR_ALL_DEPOTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Depot, depot_index, var, start)

@ -4060,8 +4060,11 @@ STR_FORMAT_WAYPOINT_NAME :{TOWN} Waypoint
STR_FORMAT_WAYPOINT_NAME_SERIAL :{TOWN} Waypoint #{COMMA} STR_FORMAT_WAYPOINT_NAME_SERIAL :{TOWN} Waypoint #{COMMA}
STR_FORMAT_DEPOT_NAME_TRAIN :{TOWN} Train Depot STR_FORMAT_DEPOT_NAME_TRAIN :{TOWN} Train Depot
STR_FORMAT_DEPOT_NAME_TRAIN_SERIAL :{TOWN} Train Depot #{COMMA}
STR_FORMAT_DEPOT_NAME_ROAD_VEHICLE :{TOWN} Road Vehicle Depot STR_FORMAT_DEPOT_NAME_ROAD_VEHICLE :{TOWN} Road Vehicle Depot
STR_FORMAT_DEPOT_NAME_ROAD_VEHICLE_SERIAL :{TOWN} Road Vehicle Depot #{COMMA}
STR_FORMAT_DEPOT_NAME_SHIP :{TOWN} Ship Depot STR_FORMAT_DEPOT_NAME_SHIP :{TOWN} Ship Depot
STR_FORMAT_DEPOT_NAME_SHIP_SERIAL :{TOWN} Ship Depot #{COMMA}
STR_FORMAT_DEPOT_NAME_AIRCRAFT :{STATION} Hangar STR_FORMAT_DEPOT_NAME_AIRCRAFT :{STATION} Hangar
STR_UNKNOWN_STATION :unknown station STR_UNKNOWN_STATION :unknown station

@ -867,10 +867,10 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Depot *d = new Depot(tile); Depot *d = new Depot(tile);
d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
MakeRailDepot(tile, _current_company, d->index, dir, railtype); MakeRailDepot(tile, _current_company, d->index, dir, railtype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MakeDefaultName(d);
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company); AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir)); YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));

@ -909,10 +909,10 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Depot *dep = new Depot(tile); Depot *dep = new Depot(tile);
dep->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
MakeRoadDepot(tile, _current_company, dep->index, dir, rt); MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MakeDefaultName(dep);
} }
cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]); cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
return cost; return cost;

@ -2106,6 +2106,14 @@ bool AfterLoadGame()
/* Reset tropic zone for VOID tiles, they shall not have any. */ /* Reset tropic zone for VOID tiles, they shall not have any. */
if (IsTileType(t, MP_VOID)) SetTropicZone(t, TROPICZONE_NORMAL); if (IsTileType(t, MP_VOID)) SetTropicZone(t, TROPICZONE_NORMAL);
} }
/* We need to properly number/name the depots.
* The first step is making sure none of the depots uses the
* 'default' names, after that we can assign the names. */
Depot *d;
FOR_ALL_DEPOTS(d) d->town_cn = UINT16_MAX;
FOR_ALL_DEPOTS(d) MakeDefaultName(d);
} }
/* Road stops is 'only' updating some caches */ /* Road stops is 'only' updating some caches */

@ -11,14 +11,20 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "../depot_base.h" #include "../depot_base.h"
#include "../town.h"
#include "saveload.h" #include "saveload.h"
static TownID _town_index;
static const SaveLoad _depot_desc[] = { static const SaveLoad _depot_desc[] = {
SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION), SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_VAR(Depot, town_index, SLE_UINT16), SLEG_CONDVAR(_town_index, SLE_UINT16, 0, 140),
SLE_END() SLE_CONDREF(Depot, town, REF_TOWN, 141, SL_MAX_VERSION),
SLE_CONDVAR(Depot, town_cn, SLE_UINT16, 141, SL_MAX_VERSION),
SLE_CONDSTR(Depot, name, SLE_STR, 0, 141, SL_MAX_VERSION),
SLE_END()
}; };
static void Save_DEPT() static void Save_DEPT()
@ -38,9 +44,22 @@ static void Load_DEPT()
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
Depot *depot = new (index) Depot(); Depot *depot = new (index) Depot();
SlObject(depot, _depot_desc); SlObject(depot, _depot_desc);
/* Set the town 'pointer' so we can restore it later. */
if (CheckSavegameVersion(141)) depot->town = (Town *)_town_index;
}
}
static void Ptrs_DEPT()
{
Depot *depot;
FOR_ALL_DEPOTS(depot) {
SlObject(depot, _depot_desc);
if (CheckSavegameVersion(141)) depot->town = Town::Get((size_t)depot->town);
} }
} }
extern const ChunkHandler _depot_chunk_handlers[] = { extern const ChunkHandler _depot_chunk_handlers[] = {
{ 'DEPT', Save_DEPT, Load_DEPT, NULL, CH_ARRAY | CH_LAST}, { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, CH_ARRAY | CH_LAST},
}; };

@ -662,7 +662,7 @@ static bool LoadOldDepot(LoadgameState *ls, int num)
if (!LoadChunk(ls, d, depot_chunk)) return false; if (!LoadChunk(ls, d, depot_chunk)) return false;
if (d->xy != 0) { if (d->xy != 0) {
d->town_index = RemapTownIndex(_old_town_index); d->town = Town::Get(RemapTownIndex(_old_town_index));
} else { } else {
delete d; delete d;
} }

@ -46,7 +46,7 @@
#include "saveload_internal.h" #include "saveload_internal.h"
extern const uint16 SAVEGAME_VERSION = 140; extern const uint16 SAVEGAME_VERSION = 141;
SavegameType _savegame_type; ///< type of savegame we are loading SavegameType _savegame_type; ///< type of savegame we are loading

@ -947,8 +947,14 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
case SCC_DEPOT_NAME: { // {DEPOT} case SCC_DEPOT_NAME: { // {DEPOT}
VehicleType vt = (VehicleType)GetInt32(&argv); VehicleType vt = (VehicleType)GetInt32(&argv);
int64 temp[1] = { vt == VEH_AIRCRAFT ? GetInt32(&argv) : Depot::Get(GetInt32(&argv))->town_index }; if (vt == VEH_AIRCRAFT) {
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_TRAIN + vt, temp, last); int64 temp[] = { GetInt32(&argv) };
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_AIRCRAFT + vt, temp, last);
} else {
const Depot *d = Depot::Get(GetInt32(&argv));
int64 temp[] = { d->town->index, d->town_cn + 1 };
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * vt + (d->town_cn == 0 ? 0 : 1), temp, last);
}
break; break;
} }

@ -489,7 +489,7 @@ public:
/* Depots refer to towns. */ /* Depots refer to towns. */
const Depot *d; const Depot *d;
FOR_ALL_DEPOTS(d) { FOR_ALL_DEPOTS(d) {
if (d->town_index == this->town->index) return false; if (d->town == this->town) return false;
} }
/* Check all tiles for town ownership. */ /* Check all tiles for town ownership. */

@ -130,12 +130,12 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Depot *depot = new Depot(tile); Depot *depot = new Depot(tile);
depot->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
MakeShipDepot(tile, _current_company, depot->index, DEPOT_NORTH, axis, wc1); MakeShipDepot(tile, _current_company, depot->index, DEPOT_NORTH, axis, wc1);
MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2); MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(tile2); MarkTileDirtyByTile(tile2);
MakeDefaultName(depot);
} }
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]); return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);

Loading…
Cancel
Save