OpenTTD

Tasklist

FS#3332 - Town generated on a hill having too many roads

Attached to Project: OpenTTD
Opened by SirkoZ (SirkoZ) - Saturday, 28 November 2009, 10:40 GMT
Last edited by Remko Bijker (Rubidium) - Sunday, 06 December 2009, 16:14 GMT
Type Bug
Category Core
Status Closed
Assigned To No-one
Operating System Windows
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Revision: r18309.

When generating a map with the good ol' original terrain generator and using better_roads town layout this (as shown in the below screen-shot) happens.
If the mechanism for generation would only be set to not build roads next to each other but with one to three squares apart, that would be just lovely.
The same thing also sometimes happens during the progress of the game where better_roads leads to road next to road on the hills.
There was an interesting function in the trunk back in the day (rel. 0.6.3) - I don't know if it is still present but it could perhaps be used to
prevent the town mechanism to build roads too near each other. Here's that function:

/**
* Check if a neighboring tile has a road
*
* @param tile curent tile
* @param dir target direction
* @param dist_multi distance multiplier
* @return true if one of the neighboring tiles at the
* given distance is a road tile else false
*/
static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi)
{
/* Lookup table for the used diff values */
const TileIndexDiff tid_lt[3] = {
TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)),
TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)),
TileOffsByDiagDir(ReverseDiagDir(dir)),
};

/* We add 1 to the distance because we want to get 1 for
* the min distance multiplier and not 0.
* Therefore we start at 4. The 4 is used because
* there are 4 tiles per distance step to check. */
dist_multi = (dist_multi + 1) * 4;
for (uint pos = 4; pos < dist_multi; pos++) {
TileIndexDiff cur = 0;
/* For each even value of pos add the right TileIndexDiff
* for each uneven value the left TileIndexDiff
* for each with 2nd bit set (2,3,6,7,..) add the reversed TileIndexDiff */
cur += tid_lt[(pos & 1) ? 0 : 1];
if (pos & 2) cur += tid_lt[2];

cur = (uint)(pos / 4) * cur; // Multiply for the fitting distance
if (GetBuiltRoadBits(TILE_ADD(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true;
}
return false;
}
This task depends upon

Closed by  Remko Bijker (Rubidium)
Sunday, 06 December 2009, 16:14 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r18415 (I hope)
Comment by Remko Bijker (Rubidium) - Sunday, 06 December 2009, 14:18 GMT
Can you add the savegame so we can actually reproduce OpenTTD doing that and thus fix the issue; I've generated a dozen maps with the original map generator and haven't seen any case of that.

Loading...