(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
authortruelight
Fri, 04 Feb 2005 13:56:51 +0000
changeset 1280 b6925875de49
parent 1279 4f83fbde72de
child 1281 1573d0e4e7a1
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
with _map2-data if possible (Celestar / TrueLight)
road_cmd.c
town_cmd.c
--- a/road_cmd.c	Fri Feb 04 13:23:29 2005 +0000
+++ b/road_cmd.c	Fri Feb 04 13:56:51 2005 +0000
@@ -107,7 +107,7 @@
 		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 @@
 
 	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 @@
 		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);
--- a/town_cmd.c	Fri Feb 04 13:23:29 2005 +0000
+++ b/town_cmd.c	Fri Feb 04 13:56:51 2005 +0000
@@ -254,8 +254,7 @@
 	_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 @@
 		_map5[tile] = (_map5[tile] & 0x40)|0x80;
 	}
 
-	t = ClosestTownFromTile(tile, (uint)-1);
+	t = GetTown(_map2[tile]);
 
 	r = Random();
 
@@ -345,7 +344,7 @@
 
 	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 GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
 {
-	Town *t2;
 	uint16 r;
 	int a,b,rcmd;
 	uint tmptile;
@@ -568,12 +566,6 @@
 		// 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 @@
 		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 @@
 		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 @@
 }
 
 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 @@
 		0x3,0xC,0x6,0x9,
 	};
 
-	if (t2 != t1)
-		return false;
-
 	slope = GetTileSlope(tile, NULL);
 	if (slope & 0x10)
 		return false;
@@ -1122,7 +1107,6 @@
 
 static bool CheckFree2x2Area(Town *t1, uint tile)
 {
-	Town *t;
 	int i;
 
 	static const TileIndexDiffC _tile_add[] = {
@@ -1135,10 +1119,6 @@
 	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 @@
 	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;