Index: src/water_map.h =================================================================== --- src/water_map.h (revision 27177) +++ src/water_map.h (working copy) @@ -346,8 +346,33 @@ return HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t); } +/** + * Comment about getting owner of canal + */ +static inline Owner GetCanalOwner(TileIndex t) +{ + assert(HasTileWaterGround(t)); + if (GetWaterClass(t) != WATER_CLASS_CANAL) { + return GetTileOwner(t); + } else { + Owner co = (Owner)(GB(_me[t].m6, 0, 2) || GB(_me[t].m6, 6, 2)); + /* Canals don't have OWNER_TOWN, and remapping OWNER_NONE + * to OWNER_TOWN makes it use one bit less */ + return co == OWNER_TOWN ? OWNER_NONE : co; + } +} /** + * Comment about setting owner of canal + */ +static inline void SetCanalOwner(TileIndex t, Owner co) +{ + if (co == OWNER_NONE) co = OWNER_TOWN; + SB(_me[t].m6, 0, 2, GB(co, 0, 2)); + SB(_me[t].m6, 6, 2, GB(co, 2, 2)); +} + +/** * Helper function to make a coast tile. * @param t The tile to change into water */ @@ -412,6 +437,7 @@ static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits) { assert(o != OWNER_WATER); + if (o == OWNER_NONE) o = OWNER_TOWN; MakeWater(t, o, WATER_CLASS_CANAL, random_bits); }