(svn r11276) -Codechange: be more consistent with naming of some accessors.

-Fix: make sure canals are never owned by water. Based on a patch by boekabart.
This commit is contained in:
rubidium 2007-10-16 19:48:58 +00:00
parent 4f512a70c3
commit ba7c595d84
8 changed files with 52 additions and 17 deletions

View File

@ -1236,11 +1236,11 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable
/* As soon as the tile is not water, bail out.
* But that does not mean the search is over. You have
* to make sure every tile of the industry will be only water*/
if (!IsClearWaterTile(cur_tile)) return false;
if (!IsWaterTile(cur_tile)) return false;
} else {
Slope tileh;
if (IsClearWaterTile(cur_tile)) return false;
if (IsWaterTile(cur_tile)) return false;
tileh = GetTileSlope(cur_tile, NULL);

View File

@ -1626,7 +1626,7 @@ bool AfterLoadGame()
if (GB(_m[t].m5, 3, 2) == 0) {
MakeClear(t, CLEAR_GRASS, 3);
} else {
MakeCanal(t, GetTileOwner(t));
MakeCanal(t, (GetTileOwner(t) == OWNER_WATER) ? OWNER_NONE : GetTileOwner(t));
}
}
SetBridgeMiddle(t, axis);
@ -2160,6 +2160,19 @@ bool AfterLoadGame()
FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
}
/* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
Replace the owner for those by OWNER_NONE. */
if (CheckSavegameVersion(82)) {
for (TileIndex t = 0; t < map_size; t++) {
if (IsTileType(t, MP_WATER) &&
GetWaterTileType(t) == WATER_TILE_CLEAR &&
GetTileOwner(t) == OWNER_WATER &&
TileHeight(t) != 0) {
SetTileOwner(t, OWNER_NONE);
}
}
}
/* Recalculate */
Group *g;
FOR_ALL_GROUPS(g) {

View File

@ -1769,7 +1769,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
/* allocate and initialize new station */
@ -2088,7 +2088,7 @@ static void DrawTile_Station(TileInfo *ti)
DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
}
if (IsBuoyTile(ti->tile) && (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER))) DrawCanalWater(ti->tile);
if (IsCanalBuoyTile(ti->tile)) DrawCanalWater(ti->tile);
const DrawTileSeqStruct *dtss;
foreach_draw_tile_seq(dtss, t->seq) {

View File

@ -154,6 +154,15 @@ static inline bool IsBuoyTile(TileIndex t)
return IsTileType(t, MP_STATION) && IsBuoy(t);
}
static inline bool IsCanalBuoyTile(TileIndex t)
{
return IsBuoyTile(t) && !IsTileOwner(t, OWNER_WATER);
}
static inline bool IsSeaBuoyTile(TileIndex t)
{
return IsBuoyTile(t) && IsTileOwner(t, OWNER_WATER);
}
static inline bool IsHangarTile(TileIndex t)
{

View File

@ -933,7 +933,7 @@ static bool GrowTownWithBridge(const Town *t, TileIndex tile, RoadBits rcmd)
return false;
}
bridge_tile = TILE_MASK(bridge_tile + TileOffsByDiagDir(bridge_dir));
} while (IsClearWaterTile(bridge_tile));
} while (IsWaterTile(bridge_tile));
/* no water tiles in between? */
if (bridge_length == 1) return false;
@ -1072,7 +1072,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
TileIndex house_tile = TileAddByDiagDir(tile, target_dir); // position of a possible house
/* Don't walk into water. */
if (IsClearWaterTile(house_tile)) return;
if (IsWaterTile(house_tile)) return;
switch (_patches.town_layout) {
default: NOT_REACHED();
@ -1121,7 +1121,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
}
/* Return if a water tile */
if (IsClearWaterTile(tile)) return;
if (IsWaterTile(tile)) return;
/* Make the roads look nicer */
rcmd = CleanUpRoadBits(tile, rcmd);

View File

@ -243,7 +243,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p
/* retrieve landscape height and ensure it's on land */
tile_start = TileXY(x, y);
tile_end = TileXY(sx, sy);
if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) {
if (IsWaterTile(tile_start) || IsWaterTile(tile_end)) {
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
}

View File

@ -72,7 +72,7 @@ CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
if (!IsWaterTile(tile) || !IsWaterTile(tile2))
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
@ -458,7 +458,7 @@ static void DrawTile_Water(TileInfo *ti)
switch (GetWaterTileType(ti->tile)) {
case WATER_TILE_CLEAR:
DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
if (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER)) DrawCanalWater(ti->tile);
if (IsCanal(ti->tile)) DrawCanalWater(ti->tile);
DrawBridgeMiddle(ti);
break;
@ -518,7 +518,7 @@ static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
{
switch (GetWaterTileType(tile)) {
case WATER_TILE_CLEAR:
if (TilePixelHeight(tile) == 0 || IsTileOwner(tile, OWNER_WATER)) {
if (!IsCanal(tile)) {
td->str = STR_3804_WATER;
} else {
td->str = STR_LANDINFO_CANAL;
@ -725,8 +725,10 @@ void TileLoop_Water(TileIndex tile)
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}}
};
/* Ensure sea-level canals and buoys on canal borders do not flood */
if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && !IsTileOwner(tile, OWNER_WATER)) return;
/* Ensure buoys on canal borders do not flood */
if (IsCanalBuoyTile(tile)) return;
/* Ensure only sea and coast floods, not canals or rivers */
if (IsTileType(tile, MP_WATER) && !(IsSea(tile) || IsCoast(tile))) return;
/* floods in all four diagonal directions with the exception of the edges */
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
@ -815,7 +817,7 @@ static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
static CommandCost TerraformTile_Water(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
{
/* Canals can't be terraformed */
if (IsClearWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
}

View File

@ -27,6 +27,8 @@ enum LockPart {
static inline WaterTileType GetWaterTileType(TileIndex t)
{
assert(IsTileType(t, MP_WATER));
if (_m[t].m5 == 0) return WATER_TILE_CLEAR;
if (_m[t].m5 == 1) return WATER_TILE_COAST;
if (IS_INT_INSIDE(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK;
@ -35,11 +37,19 @@ static inline WaterTileType GetWaterTileType(TileIndex t)
return WATER_TILE_DEPOT;
}
/** IsWater return true if any type of clear water like ocean, river, canal */
static inline bool IsWater(TileIndex t)
{
return GetWaterTileType(t) == WATER_TILE_CLEAR;
}
static inline bool IsSea(TileIndex t)
{
if (GetWaterTileType(t) != WATER_TILE_CLEAR) return false;
if (!IsTileOwner(t, OWNER_WATER)) return false; // 'Human' built water = canal, not sea
return true;
}
static inline bool IsCoast(TileIndex t)
{
return GetWaterTileType(t) == WATER_TILE_COAST;
@ -50,9 +60,9 @@ static inline bool IsCanal(TileIndex t)
return GetWaterTileType(t) == WATER_TILE_CLEAR && GetTileOwner(t) != OWNER_WATER;
}
static inline bool IsClearWaterTile(TileIndex t)
static inline bool IsWaterTile(TileIndex t)
{
return IsTileType(t, MP_WATER) && IsWater(t) && GetTileSlope(t, NULL) == SLOPE_FLAT;
return IsTileType(t, MP_WATER) && IsWater(t);
}
static inline TileIndex GetOtherShipDepotTile(TileIndex t)
@ -109,6 +119,7 @@ static inline void MakeShore(TileIndex t)
static inline void MakeCanal(TileIndex t, Owner o)
{
assert(o != OWNER_WATER);
SetTileType(t, MP_WATER);
SetTileOwner(t, o);
_m[t].m2 = 0;