summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--road_cmd.c19
-rw-r--r--town_cmd.c36
2 files changed, 22 insertions, 33 deletions
diff --git a/road_cmd.c b/road_cmd.c
index b195bc63d..4655b45f2 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -107,7 +107,7 @@ static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road)
if (_patches.extra_dynamite)
return true;
- t = ClosestTownFromTile(tile, (uint)-1);
+ t = GetTown(_map2[tile]);
SetDParam(0, t->index);
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
return false;
@@ -149,7 +149,10 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
FindLandscapeHeight(&ti, x, y);
tile = ti.tile;
- t = ClosestTownFromTile(tile, (uint)-1); // needed for town rating penalty
+ if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
+ t = GetTown(_map2[tile]); // needed for town rating penalty
+ else
+ t = NULL;
// allow deleting road under bridge
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
@@ -964,12 +967,18 @@ static void TileLoop_Road(uint tile)
return;
if (((_map3_hi[tile] & 0x70) >> 4) < 6) {
- t = ClosestTownFromTile(tile, (uint)-1);
+ if(_map_owner[tile] == OWNER_TOWN)
+ t = GetTown(_map2[tile]);
+ else
+ t = ClosestTownFromTile(tile, (uint)-1);
+
grp = 0;
if (t != NULL) {
- // If in the scenario editor, set the owner to a town.
- if (_game_mode == GM_EDITOR) {
+ /* In SE, set the owner to OWNER_TOWN */
+ if (_game_mode == GM_EDITOR && _map_owner[tile] != OWNER_TOWN) {
_map_owner[tile] = OWNER_TOWN;
+ /* XXX - This line is not perfect, any suggestions? */
+ _map2[tile] = ClosestTownFromTile(tile, (uint)-1)->index;
}
grp = GetTownRadiusGroup(t, tile);
diff --git a/town_cmd.c b/town_cmd.c
index da505332b..39a68b527 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -254,8 +254,7 @@ static void MakeSingleHouseBigger(uint tile)
_map3_lo[tile] = _map3_lo[tile] + 0x40;
if ( (_map3_lo[tile] & 0xC0) == 0xC0) {
- Town *t = ClosestTownFromTile(tile, (uint)-1);
- ChangePopulation(t, _housetype_population[_map3_hi[tile]]);
+ ChangePopulation(GetTown(_map2[tile]), _housetype_population[_map3_hi[tile]]);
}
MarkTileDirtyByTile(tile);
}
@@ -288,7 +287,7 @@ static void TileLoop_Town(uint tile)
_map5[tile] = (_map5[tile] & 0x40)|0x80;
}
- t = ClosestTownFromTile(tile, (uint)-1);
+ t = GetTown(_map2[tile]);
r = Random();
@@ -345,7 +344,7 @@ static int32 ClearTile_Town(uint tile, byte flags)
rating = _housetype_remove_ratingmod[house];
_cleared_town_rating += rating;
- _cleared_town = t = ClosestTownFromTile(tile, (uint)-1);
+ _cleared_town = t = GetTown(_map2[tile]);
if (_current_player < MAX_PLAYERS) {
if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
@@ -552,7 +551,6 @@ static void LevelTownLand(uint tile)
static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
{
- Town *t2;
uint16 r;
int a,b,rcmd;
uint tmptile;
@@ -568,12 +566,6 @@ static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
// to say that this is the last iteration.
_grow_town_result = 0;
- // Then check if the tile we are at belongs to the town,
- // if not, bail out.
- t2 = ClosestTownFromTile(tile, (uint)-1);
- if (t2 != t1)
- return;
-
// Remove hills etc
LevelTownLand(tile);
@@ -636,13 +628,6 @@ static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
if (IS_WATER_TILE(tmptile))
return;
- // If the new tile belongs to another town,
- // then stop the search altogether.
- if (ClosestTownFromTile(tmptile, (uint)-1) != t1) {
- _grow_town_result = 0;
- return;
- }
-
// Build a house at the edge. 60% chance or
// always ok if no road allowed.
if (!IsRoadAllowedHere(tmptile, i) || CHANCE16(6,10)) {
@@ -743,6 +728,10 @@ static int GrowTownAtRoad(Town *t, uint tile)
do block = Random() & 3; while (!HASBIT(mask,block));
tile += ToTileIndexDiff(_roadblock_tileadd[block]);
+ /* Don't allow building over roads of other cities */
+ if (IsTileType(tile, MP_STREET) && _map_owner[tile] == OWNER_TOWN && GetTown(_map2[tile]) != t)
+ _grow_town_result = -1;
+
// Max number of times is checked.
} while (--_grow_town_result >= 0);
@@ -1077,7 +1066,6 @@ void GenerateTowns(void)
}
static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
- Town *t2 = ClosestTownFromTile(tile, (uint)-1);
int b;
uint slope;
@@ -1086,9 +1074,6 @@ static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
0x3,0xC,0x6,0x9,
};
- if (t2 != t1)
- return false;
-
slope = GetTileSlope(tile, NULL);
if (slope & 0x10)
return false;
@@ -1122,7 +1107,6 @@ int GetTownRadiusGroup(Town *t, uint tile)
static bool CheckFree2x2Area(Town *t1, uint tile)
{
- Town *t;
int i;
static const TileIndexDiffC _tile_add[] = {
@@ -1135,10 +1119,6 @@ static bool CheckFree2x2Area(Town *t1, uint tile)
for(i=0; i!=4; i++) {
tile += ToTileIndexDiff(_tile_add[i]);
- t = ClosestTownFromTile(tile, (uint)-1);
- if (t1 != t)
- return false;
-
if (GetTileSlope(tile, NULL))
return false;
@@ -1446,7 +1426,7 @@ void DeleteTown(Town *t)
for (tile = 0; tile < MapSize(); ++tile) {
switch (GetTileType(tile)) {
case MP_HOUSE:
- if (ClosestTownFromTile(tile, (uint)-1) == t)
+ if (GetTown(_map2[tile]) == t)
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
break;