diff options
author | rubidium <rubidium@openttd.org> | 2010-09-16 16:31:57 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-09-16 16:31:57 +0000 |
commit | af18c30f30d550b98f7fe3dc89c8977a2aeb7f51 (patch) | |
tree | 9c154aa95356c740d333b8f92ee34259272cc914 | |
parent | b01c63cd23b3c60de3b48478b5287cdaeffed974 (diff) | |
download | openttd-af18c30f30d550b98f7fe3dc89c8977a2aeb7f51.tar.xz |
(svn r20816) -Codechange [FS#3835]: make waypoint default names work like depots, stations and vehicles (Krille)
-rw-r--r-- | src/depot_base.h | 2 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 13 | ||||
-rw-r--r-- | src/town.h | 8 | ||||
-rw-r--r-- | src/waypoint_base.h | 2 | ||||
-rw-r--r-- | src/waypoint_cmd.cpp | 8 |
5 files changed, 20 insertions, 13 deletions
diff --git a/src/depot_base.h b/src/depot_base.h index 4bc4af67c..04957c8cb 100644 --- a/src/depot_base.h +++ b/src/depot_base.h @@ -23,7 +23,7 @@ struct Depot : DepotPool::PoolItem<&_depot_pool> { char *name; TileIndex xy; - uint16 town_cn; ///< The Nth depot for this town (consecutive number) + uint16 town_cn; ///< The N-1th depot for this town (consecutive number) Date build_date; ///< Date of construction Depot(TileIndex xy = INVALID_TILE) : xy(xy) {} diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 61183f30c..348cbb6c6 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2295,6 +2295,19 @@ bool AfterLoadGame() SetWaterClass(t, WATER_CLASS_INVALID); } } + + /* Waypoints with custom name may have a non-unique town_cn, + * renumber those. First set all affected waypoints to the + * highest possible number to get them numbered in the + * order they have in the pool. */ + Waypoint *wp; + FOR_ALL_WAYPOINTS(wp) { + if (wp->name != NULL) wp->town_cn = UINT16_MAX; + } + + FOR_ALL_WAYPOINTS(wp) { + if (wp->name != NULL) MakeDefaultName(wp); + } } /* Road stops is 'only' updating some caches */ diff --git a/src/town.h b/src/town.h index 6e3533d8d..d2f0ba143 100644 --- a/src/town.h +++ b/src/town.h @@ -240,8 +240,8 @@ extern TownID _new_town_id; template <class T> void MakeDefaultName(T *obj) { - /* We only want to set names if it hasn't been set before. */ - assert(obj->name == NULL); + /* We only want to set names if it hasn't been set before, or when we're calling from afterload. */ + assert(obj->name == NULL || obj->town_cn == UINT16_MAX); obj->town = ClosestTownFromTile(obj->xy, UINT_MAX); @@ -266,8 +266,8 @@ void MakeDefaultName(T *obj) /* check only valid waypoints... */ if (lobj != NULL && obj != lobj) { - /* only objects with 'generic' name within the same city and with the same type*/ - if (lobj->name == NULL && lobj->town == obj->town && lobj->IsOfType(obj)) { + /* only objects within the same city and with the same type */ + if (lobj->town == obj->town && lobj->IsOfType(obj)) { /* if lobj->town_cn < next, uint will overflow to '+inf' */ uint i = (uint)lobj->town_cn - next; diff --git a/src/waypoint_base.h b/src/waypoint_base.h index 7dc7a5753..6b8d59579 100644 --- a/src/waypoint_base.h +++ b/src/waypoint_base.h @@ -15,7 +15,7 @@ #include "base_station_base.h" struct Waypoint : SpecializedStation<Waypoint, true> { - uint16 town_cn; ///< The Nth waypoint for this town (consecutive number) + uint16 town_cn; ///< The N-1th waypoint for this town (consecutive number) Waypoint(TileIndex tile = INVALID_TILE) : SpecializedStation<Waypoint, true>(tile) { } ~Waypoint(); diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 724f193af..c7095673a 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -406,13 +406,7 @@ CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, ui if (flags & DC_EXEC) { free(wp->name); - - if (reset) { - wp->name = NULL; - MakeDefaultName(wp); - } else { - wp->name = strdup(text); - } + wp->name = reset ? NULL : strdup(text); wp->UpdateVirtCoord(); } |