mirror of https://github.com/OpenTTD/OpenTTD
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
with _map2-data if possible (Celestar / TrueLight)release/0.4.5
parent
42f98c7eec
commit
7241f42e9d
19
road_cmd.c
19
road_cmd.c
|
@ -107,7 +107,7 @@ static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road)
|
||||||
if (_patches.extra_dynamite)
|
if (_patches.extra_dynamite)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
t = ClosestTownFromTile(tile, (uint)-1);
|
t = GetTown(_map2[tile]);
|
||||||
SetDParam(0, t->index);
|
SetDParam(0, t->index);
|
||||||
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
|
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
|
||||||
return false;
|
return false;
|
||||||
|
@ -149,7 +149,10 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
FindLandscapeHeight(&ti, x, y);
|
FindLandscapeHeight(&ti, x, y);
|
||||||
tile = ti.tile;
|
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
|
// allow deleting road under bridge
|
||||||
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
|
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
|
||||||
|
@ -964,12 +967,18 @@ static void TileLoop_Road(uint tile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (((_map3_hi[tile] & 0x70) >> 4) < 6) {
|
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;
|
grp = 0;
|
||||||
if (t != NULL) {
|
if (t != NULL) {
|
||||||
// If in the scenario editor, set the owner to a town.
|
/* In SE, set the owner to OWNER_TOWN */
|
||||||
if (_game_mode == GM_EDITOR) {
|
if (_game_mode == GM_EDITOR && _map_owner[tile] != OWNER_TOWN) {
|
||||||
_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);
|
grp = GetTownRadiusGroup(t, tile);
|
||||||
|
|
36
town_cmd.c
36
town_cmd.c
|
@ -254,8 +254,7 @@ static void MakeSingleHouseBigger(uint tile)
|
||||||
_map3_lo[tile] = _map3_lo[tile] + 0x40;
|
_map3_lo[tile] = _map3_lo[tile] + 0x40;
|
||||||
|
|
||||||
if ( (_map3_lo[tile] & 0xC0) == 0xC0) {
|
if ( (_map3_lo[tile] & 0xC0) == 0xC0) {
|
||||||
Town *t = ClosestTownFromTile(tile, (uint)-1);
|
ChangePopulation(GetTown(_map2[tile]), _housetype_population[_map3_hi[tile]]);
|
||||||
ChangePopulation(t, _housetype_population[_map3_hi[tile]]);
|
|
||||||
}
|
}
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
|
@ -288,7 +287,7 @@ static void TileLoop_Town(uint tile)
|
||||||
_map5[tile] = (_map5[tile] & 0x40)|0x80;
|
_map5[tile] = (_map5[tile] & 0x40)|0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = ClosestTownFromTile(tile, (uint)-1);
|
t = GetTown(_map2[tile]);
|
||||||
|
|
||||||
r = Random();
|
r = Random();
|
||||||
|
|
||||||
|
@ -345,7 +344,7 @@ static int32 ClearTile_Town(uint tile, byte flags)
|
||||||
|
|
||||||
rating = _housetype_remove_ratingmod[house];
|
rating = _housetype_remove_ratingmod[house];
|
||||||
_cleared_town_rating += rating;
|
_cleared_town_rating += rating;
|
||||||
_cleared_town = t = ClosestTownFromTile(tile, (uint)-1);
|
_cleared_town = t = GetTown(_map2[tile]);
|
||||||
|
|
||||||
if (_current_player < MAX_PLAYERS) {
|
if (_current_player < MAX_PLAYERS) {
|
||||||
if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
|
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)
|
static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
|
||||||
{
|
{
|
||||||
Town *t2;
|
|
||||||
uint16 r;
|
uint16 r;
|
||||||
int a,b,rcmd;
|
int a,b,rcmd;
|
||||||
uint tmptile;
|
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.
|
// to say that this is the last iteration.
|
||||||
_grow_town_result = 0;
|
_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
|
// Remove hills etc
|
||||||
LevelTownLand(tile);
|
LevelTownLand(tile);
|
||||||
|
|
||||||
|
@ -636,13 +628,6 @@ static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
|
||||||
if (IS_WATER_TILE(tmptile))
|
if (IS_WATER_TILE(tmptile))
|
||||||
return;
|
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
|
// Build a house at the edge. 60% chance or
|
||||||
// always ok if no road allowed.
|
// always ok if no road allowed.
|
||||||
if (!IsRoadAllowedHere(tmptile, i) || CHANCE16(6,10)) {
|
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));
|
do block = Random() & 3; while (!HASBIT(mask,block));
|
||||||
tile += ToTileIndexDiff(_roadblock_tileadd[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.
|
// Max number of times is checked.
|
||||||
} while (--_grow_town_result >= 0);
|
} while (--_grow_town_result >= 0);
|
||||||
|
|
||||||
|
@ -1077,7 +1066,6 @@ void GenerateTowns(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
|
static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
|
||||||
Town *t2 = ClosestTownFromTile(tile, (uint)-1);
|
|
||||||
int b;
|
int b;
|
||||||
uint slope;
|
uint slope;
|
||||||
|
|
||||||
|
@ -1086,9 +1074,6 @@ static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
|
||||||
0x3,0xC,0x6,0x9,
|
0x3,0xC,0x6,0x9,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (t2 != t1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
slope = GetTileSlope(tile, NULL);
|
slope = GetTileSlope(tile, NULL);
|
||||||
if (slope & 0x10)
|
if (slope & 0x10)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1122,7 +1107,6 @@ int GetTownRadiusGroup(Town *t, uint tile)
|
||||||
|
|
||||||
static bool CheckFree2x2Area(Town *t1, uint tile)
|
static bool CheckFree2x2Area(Town *t1, uint tile)
|
||||||
{
|
{
|
||||||
Town *t;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
static const TileIndexDiffC _tile_add[] = {
|
static const TileIndexDiffC _tile_add[] = {
|
||||||
|
@ -1135,10 +1119,6 @@ static bool CheckFree2x2Area(Town *t1, uint tile)
|
||||||
for(i=0; i!=4; i++) {
|
for(i=0; i!=4; i++) {
|
||||||
tile += ToTileIndexDiff(_tile_add[i]);
|
tile += ToTileIndexDiff(_tile_add[i]);
|
||||||
|
|
||||||
t = ClosestTownFromTile(tile, (uint)-1);
|
|
||||||
if (t1 != t)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (GetTileSlope(tile, NULL))
|
if (GetTileSlope(tile, NULL))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1446,7 +1426,7 @@ void DeleteTown(Town *t)
|
||||||
for (tile = 0; tile < MapSize(); ++tile) {
|
for (tile = 0; tile < MapSize(); ++tile) {
|
||||||
switch (GetTileType(tile)) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_HOUSE:
|
case MP_HOUSE:
|
||||||
if (ClosestTownFromTile(tile, (uint)-1) == t)
|
if (GetTown(_map2[tile]) == t)
|
||||||
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue