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