From 819d210acc501e10f20d83cd72176862e8068758 Mon Sep 17 00:00:00 2001 From: tron Date: Wed, 1 Mar 2006 21:00:44 +0000 Subject: (svn r3714) Add functions to turn tiles into water and shore tiles --- landscape.c | 5 ++--- station_cmd.c | 13 +++++-------- water_cmd.c | 28 +++++++++++----------------- water_map.h | 27 +++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 water_map.h diff --git a/landscape.c b/landscape.c index 89ce548b2..3e4a312f9 100644 --- a/landscape.c +++ b/landscape.c @@ -15,6 +15,7 @@ #include "vehicle.h" #include "variables.h" #include "void.h" +#include "water_map.h" extern const TileTypeProcs _tile_type_clear_procs, @@ -450,9 +451,7 @@ void ConvertGroundTilesIntoWaterTiles(void) for (tile = 0; tile < MapSize(); ++tile) { if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) { - SetTileType(tile, MP_WATER); - SetTileOwner(tile, OWNER_WATER); - _m[tile].m5 = 0; + MakeWater(tile); } } } diff --git a/station_cmd.c b/station_cmd.c index 9ff2c3e7a..1ae40771e 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -26,6 +26,7 @@ #include "sprite.h" #include "depot.h" #include "train.h" +#include "water_map.h" enum { /* Max stations: 64000 (64 * 1000) */ @@ -1777,12 +1778,8 @@ static int32 RemoveBuoy(Station *st, uint32 flags) st->facilities &= ~FACIL_DOCK; st->had_vehicle_of_type &= ~HVOT_BUOY; - ModifyTile(tile, - MP_SETTYPE(MP_WATER) | - MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR, - OWNER_WATER, /* map_owner */ - 0 /* map5 */ - ); + MakeWater(tile); + MarkTileDirtyByTile(tile); UpdateStationVirtCoordDirty(st); DeleteStationIfEmpty(st); @@ -1926,8 +1923,8 @@ static int32 RemoveDock(Station *st, uint32 flags) if (flags & DC_EXEC) { DoClearSquare(tile1); - // convert the water tile to water. - ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); + MakeWater(tile2); + MarkTileDirtyByTile(tile2); st->dock_tile = 0; st->facilities &= ~FACIL_DOCK; diff --git a/water_cmd.c b/water_cmd.c index 9ad7cbf65..2df124595 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -16,6 +16,7 @@ #include "depot.h" #include "vehicle_gui.h" #include "train.h" +#include "water_map.h" const SpriteID _water_shore_sprites[15] = { 0, @@ -116,9 +117,10 @@ static int32 RemoveShipDepot(TileIndex tile, uint32 flags) /* Kill the depot */ DoDeleteDepot(tile); - /* Make the tiles water */ - ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); - ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); + MakeWater(tile); + MakeWater(tile2); + MarkTileDirtyByTile(tile); + MarkTileDirtyByTile(tile2); } return _price.remove_ship_depot; @@ -258,7 +260,8 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) // change owner to OWNER_WATER and set land under bridge bit to water ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08); } else { - ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); + MakeWater(tile); + MarkTileDirtyByTile(tile); } // mark the tiles around dirty too MarkTilesAroundDirty(tile); @@ -532,12 +535,8 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs) case MP_TREES: _current_player = OWNER_WATER; if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { - ModifyTile( - target, - MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | - MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, - OWNER_WATER, 1 - ); + MakeShore(target); + MarkTileDirtyByTile(target); } break; @@ -570,13 +569,8 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs) } if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { - ModifyTile( - target, - MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | - MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, - OWNER_WATER, - 0 - ); + MakeWater(target); + MarkTileDirtyByTile(target); } } } diff --git a/water_map.h b/water_map.h new file mode 100644 index 000000000..123e96ae2 --- /dev/null +++ b/water_map.h @@ -0,0 +1,27 @@ +/* $Id$ */ + +#ifndef WATER_MAP_H +#define WATER_MAP_H + +static inline void MakeWater(TileIndex t) +{ + SetTileType(t, MP_WATER); + SetTileOwner(t, OWNER_WATER); + _m[t].m2 = 0; + _m[t].m3 = 0; + _m[t].m4 = 0; + _m[t].m5 = 0; +} + + +static inline void MakeShore(TileIndex t) +{ + SetTileType(t, MP_WATER); + SetTileOwner(t, OWNER_WATER); + _m[t].m2 = 0; + _m[t].m3 = 0; + _m[t].m4 = 0; + _m[t].m5 = 1; +} + +#endif -- cgit v1.2.3-54-g00ecf