src/water_cmd.cpp
changeset 8414 488721240c47
parent 8413 c7f3384330a3
child 8430 ecbc9ff4271d
equal deleted inserted replaced
8413:c7f3384330a3 8414:488721240c47
    92 	bool has_water = false;
    92 	bool has_water = false;
    93 	bool has_canal = false;
    93 	bool has_canal = false;
    94 
    94 
    95 	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
    95 	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
    96 		TileIndex neighbour = TileAddByDiagDir(t, dir);
    96 		TileIndex neighbour = TileAddByDiagDir(t, dir);
    97 		if (IsTileType(neighbour, MP_WATER)) {
    97 		switch (GetTileType(neighbour)) {
    98 			has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
    98 			case MP_WATER:
    99 			has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
    99 				has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
       
   100 				has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
       
   101 				break;
       
   102 
       
   103 			case MP_RAILWAY:
       
   104 				/* Shore or flooded halftile */
       
   105 				has_water |= (GetRailGroundType(neighbour) == RAIL_GROUND_WATER);
       
   106 				break;
       
   107 
       
   108 			default: break;
   100 		}
   109 		}
   101 	}
   110 	}
   102 	if (has_canal || !has_water) {
   111 	if (has_canal || !has_water) {
   103 		MakeCanal(t, o, Random());
   112 		MakeCanal(t, o, Random());
   104 	} else {
   113 	} else {
   412 	switch (GetTileType(tile)) {
   421 	switch (GetTileType(tile)) {
   413 		case MP_WATER:
   422 		case MP_WATER:
   414 			if (!IsCoast(tile)) return true;
   423 			if (!IsCoast(tile)) return true;
   415 			return IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL));
   424 			return IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL));
   416 
   425 
   417 		case MP_RAILWAY:  return GetRailGroundType(tile) == RAIL_GROUND_WATER;
   426 		case MP_RAILWAY:
       
   427 			if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
       
   428 				assert(IsPlainRailTile(tile));
       
   429 				return IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL));
       
   430 			}
       
   431 			return false;
       
   432 
   418 		case MP_STATION:  return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile);
   433 		case MP_STATION:  return IsOilRig(tile) || IsDock(tile) || IsBuoy(tile);
   419 		case MP_INDUSTRY: return (GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0;
   434 		case MP_INDUSTRY: return (GetIndustrySpec(GetIndustryType(tile))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0;
   420 		default:          return false;
   435 		default:          return false;
   421 	}
   436 	}
   422 }
   437 }
   779  * @return Behaviour of the tile
   794  * @return Behaviour of the tile
   780  */
   795  */
   781 static FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
   796 static FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
   782 {
   797 {
   783 	/* FLOOD_ACTIVE:  'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, rail with flooded halftile
   798 	/* FLOOD_ACTIVE:  'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, rail with flooded halftile
   784 	 * FLOOD_DRYUP:   coast with more than one corner raised
   799 	 * FLOOD_DRYUP:   coast with more than one corner raised, coast with rail-track
   785 	 * FLOOD_PASSIVE: oilrig, dock, water-industries
   800 	 * FLOOD_PASSIVE: oilrig, dock, water-industries
   786 	 * FLOOD_NONE:    canals, rivers, everything else
   801 	 * FLOOD_NONE:    canals, rivers, everything else
   787 	 */
   802 	 */
   788 	switch (GetTileType(tile)) {
   803 	switch (GetTileType(tile)) {
   789 		case MP_WATER:
   804 		case MP_WATER:
   793 			} else {
   808 			} else {
   794 				return ((IsSea(tile) || (IsShipDepot(tile) && (GetShipDepotWaterOwner(tile) == OWNER_WATER))) ? FLOOD_ACTIVE : FLOOD_NONE);
   809 				return ((IsSea(tile) || (IsShipDepot(tile) && (GetShipDepotWaterOwner(tile) == OWNER_WATER))) ? FLOOD_ACTIVE : FLOOD_NONE);
   795 			}
   810 			}
   796 
   811 
   797 		case MP_RAILWAY:
   812 		case MP_RAILWAY:
   798 			return ((GetRailGroundType(tile) == RAIL_GROUND_WATER) ? FLOOD_ACTIVE : FLOOD_NONE);
   813 			if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
       
   814 				return (IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL)) ? FLOOD_ACTIVE : FLOOD_DRYUP);
       
   815 			}
       
   816 			return FLOOD_NONE;
   799 
   817 
   800 		case MP_STATION:
   818 		case MP_STATION:
   801 			if (IsSeaBuoyTile(tile)) return FLOOD_ACTIVE;
   819 			if (IsSeaBuoyTile(tile)) return FLOOD_ACTIVE;
   802 			if (IsOilRig(tile) || IsDock(tile)) return FLOOD_PASSIVE;
   820 			if (IsOilRig(tile) || IsDock(tile)) return FLOOD_PASSIVE;
   803 			return FLOOD_NONE;
   821 			return FLOOD_NONE;
   876 /**
   894 /**
   877  * Drys a tile up.
   895  * Drys a tile up.
   878  */
   896  */
   879 static void DoDryUp(TileIndex tile)
   897 static void DoDryUp(TileIndex tile)
   880 {
   898 {
   881 	assert(IsTileType(tile, MP_WATER) && IsCoast(tile));
       
   882 	_current_player = OWNER_WATER;
   899 	_current_player = OWNER_WATER;
   883 
   900 
   884 	if (CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
   901 	switch (GetTileType(tile)) {
   885 		MakeClear(tile, CLEAR_GRASS, 3);
   902 		case MP_RAILWAY:
   886 		MarkTileDirtyByTile(tile);
   903 			assert(IsPlainRailTile(tile));
       
   904 			assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
       
   905 
       
   906 			RailGroundType new_ground;
       
   907 			switch (GetTrackBits(tile)) {
       
   908 				case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
       
   909 				case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
       
   910 				case TRACK_BIT_LEFT:  new_ground = RAIL_GROUND_FENCE_VERT1;  break;
       
   911 				case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2;  break;
       
   912 				default: NOT_REACHED();
       
   913 			}
       
   914 			SetRailGroundType(tile, new_ground);
       
   915 			MarkTileDirtyByTile(tile);
       
   916 			break;
       
   917 
       
   918 		case MP_WATER:
       
   919 			assert(IsCoast(tile));
       
   920 
       
   921 			if (CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
       
   922 				MakeClear(tile, CLEAR_GRASS, 3);
       
   923 				MarkTileDirtyByTile(tile);
       
   924 			}
       
   925 			break;
       
   926 
       
   927 		default: NOT_REACHED();
   887 	}
   928 	}
   888 
   929 
   889 	_current_player = OWNER_NONE;
   930 	_current_player = OWNER_NONE;
   890 }
   931 }
   891 
   932