src/town_cmd.cpp
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
--- a/src/town_cmd.cpp	Tue Jun 17 10:32:49 2008 +0000
+++ b/src/town_cmd.cpp	Tue Jun 17 13:22:13 2008 +0000
@@ -1642,13 +1642,14 @@
  * @param random_bits required for newgrf houses
  * @pre house can be built here
  */
-static inline void ClearMakeHouseTile(TileIndex tile, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
+static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
 {
 	CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
 
 	assert(CmdSucceeded(cc));
 
-	MakeHouseTile(tile, tid, counter, stage, type, random_bits);
+	IncreaseBuildingCount(t, type);
+	MakeHouseTile(tile, t->index, counter, stage, type, random_bits);
 	if (GetHouseSpecs(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile);
 
 	MarkTileDirtyByTile(tile);
@@ -1665,14 +1666,14 @@
  * @param random_bits required for newgrf houses
  * @pre house can be built here
  */
-static void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
+static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits)
 {
 	BuildingFlags size = GetHouseSpecs(type)->building_flags;
 
-	ClearMakeHouseTile(t, tid, counter, stage, type, random_bits);
-	if (size & BUILDING_2_TILES_Y)   ClearMakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type, random_bits);
-	if (size & BUILDING_2_TILES_X)   ClearMakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type, random_bits);
-	if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type, random_bits);
+	ClearMakeHouseTile(t, town, counter, stage, type, random_bits);
+	if (size & BUILDING_2_TILES_Y)   ClearMakeHouseTile(t + TileDiffXY(0, 1), town, counter, stage, ++type, random_bits);
+	if (size & BUILDING_2_TILES_X)   ClearMakeHouseTile(t + TileDiffXY(1, 0), town, counter, stage, ++type, random_bits);
+	if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), town, counter, stage, ++type, random_bits);
 }
 
 
@@ -1929,11 +1930,6 @@
 			}
 
 			if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue;
-
-			if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
-				uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile);
-				if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) == 0) continue;
-			}
 		}
 
 		if (_cur_year < hs->min_year || _cur_year > hs->max_year) continue;
@@ -1947,7 +1943,7 @@
 			SetBit(oneof, TOWN_HAS_STADIUM);
 		}
 
-		if (HASBITS(t->flags12 , oneof)) continue;
+		if (HASBITS(t->flags12, oneof)) continue;
 
 		/* Make sure there is no slope? */
 		bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
@@ -1963,9 +1959,13 @@
 			/* 1x1 house checks are already done */
 		}
 
+		if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
+			uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile);
+			if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) == 0) continue;
+		}
+
 		/* build the house */
 		t->num_houses++;
-		IncreaseBuildingCount(t, house);
 
 		/* Special houses that there can be only one of. */
 		t->flags12 |= oneof;
@@ -1986,7 +1986,7 @@
 			}
 		}
 
-		MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, Random());
+		MakeTownHouse(tile, t, construction_counter, construction_stage, house, Random());
 
 		return true;
 	}
@@ -1995,9 +1995,10 @@
 }
 
 
-static void DoClearTownHouseHelper(TileIndex tile)
+static void DoClearTownHouseHelper(TileIndex tile, Town *t, HouseID house)
 {
 	assert(IsTileType(tile, MP_HOUSE));
+	DecreaseBuildingCount(t, house);
 	DoClearSquare(tile);
 	DeleteAnimatedTile(tile);
 }
@@ -2046,7 +2047,6 @@
 	}
 
 	t->num_houses--;
-	DecreaseBuildingCount(t, house);
 
 	/* Clear flags for houses that only may exist once/town. */
 	if (hs->building_flags & BUILDING_IS_CHURCH) {
@@ -2057,10 +2057,10 @@
 
 	/* Do the actual clearing of tiles */
 	uint eflags = hs->building_flags;
-	DoClearTownHouseHelper(tile);
-	if (eflags & BUILDING_2_TILES_X)   DoClearTownHouseHelper(tile + TileDiffXY(1, 0));
-	if (eflags & BUILDING_2_TILES_Y)   DoClearTownHouseHelper(tile + TileDiffXY(0, 1));
-	if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1));
+	DoClearTownHouseHelper(tile, t, house);
+	if (eflags & BUILDING_2_TILES_Y)   DoClearTownHouseHelper(tile + TileDiffXY(0, 1), t, ++house);
+	if (eflags & BUILDING_2_TILES_X)   DoClearTownHouseHelper(tile + TileDiffXY(1, 0), t, ++house);
+	if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1), t, ++house);
 }
 
 static bool IsUniqueTownName(const char *name)