Changeset - r13298:ddbc752190f3
[Not reviewed]
master
0 3 0
rubidium - 15 years ago 2009-10-20 12:31:11
rubidium@openttd.org
(svn r17817) -Codechange: MakeWater actually made sea tiles, so rename it to MakeSea and unduplicate the code to make sea, rivers and canals.
3 files changed with 42 insertions and 29 deletions:
0 comments (0 inline, 0 general)
src/saveload/afterload.cpp
Show inline comments
 
@@ -917,25 +917,25 @@ bool AfterLoadGame()
 
								town,
 
								GetTileOwner(t), OWNER_NONE
 
							);
 
						}
 
					} else {
 
						if (GB(_m[t].m5, 3, 2) == 0) {
 
							MakeClear(t, CLEAR_GRASS, 3);
 
						} else {
 
							if (GetTileSlope(t, NULL) != SLOPE_FLAT) {
 
								MakeShore(t);
 
							} else {
 
								if (GetTileOwner(t) == OWNER_WATER) {
 
									MakeWater(t);
 
									MakeSea(t);
 
								} else {
 
									MakeCanal(t, GetTileOwner(t), Random());
 
								}
 
							}
 
						}
 
					}
 
					SetBridgeMiddle(t, axis);
 
				} else { // ramp
 
					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
 
					uint north_south = GB(_m[t].m5, 5, 1);
 
					DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
 
					TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
 
@@ -1475,25 +1475,25 @@ bool AfterLoadGame()
 
			}
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(86)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			/* Move river flag and update canals to use water class */
 
			if (IsTileType(t, MP_WATER)) {
 
				if (GetWaterClass(t) != WATER_CLASS_RIVER) {
 
					if (IsWater(t)) {
 
						Owner o = GetTileOwner(t);
 
						if (o == OWNER_WATER) {
 
							MakeWater(t);
 
							MakeSea(t);
 
						} else {
 
							MakeCanal(t, o, Random());
 
						}
 
					} else if (IsShipDepot(t)) {
 
						Owner o = (Owner)_m[t].m4; // Original water owner
 
						SetWaterClass(t, o == OWNER_WATER ? WATER_CLASS_SEA : WATER_CLASS_CANAL);
 
					}
 
				}
 
			}
 
		}
 

	
 
		/* Update locks, depots, docks and buoys to have a water class based
src/water_cmd.cpp
Show inline comments
 
@@ -156,25 +156,25 @@ void MakeWaterKeepingClass(TileIndex til
 
{
 
	assert(IsTileType(tile, MP_WATER) || (IsTileType(tile, MP_STATION) && (IsBuoy(tile) || IsDock(tile) || IsOilRig(tile))) || IsTileType(tile, MP_INDUSTRY));
 

	
 
	WaterClass wc = GetWaterClass(tile);
 

	
 
	/* Autoslope might turn an originally canal or river tile into land */
 
	uint z;
 
	if (GetTileSlope(tile, &z) != SLOPE_FLAT) wc = WATER_CLASS_INVALID;
 

	
 
	if (wc == WATER_CLASS_SEA && z > 0) wc = WATER_CLASS_CANAL;
 

	
 
	switch (wc) {
 
		case WATER_CLASS_SEA:   MakeWater(tile);              break;
 
		case WATER_CLASS_SEA:   MakeSea(tile);                break;
 
		case WATER_CLASS_CANAL: MakeCanal(tile, o, Random()); break;
 
		case WATER_CLASS_RIVER: MakeRiver(tile, Random());    break;
 
		default:                DoClearSquare(tile);          break;
 
	}
 
}
 

	
 
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!IsShipDepot(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	TileIndex tile2 = GetOtherShipDepotTile(tile);
 
@@ -328,25 +328,25 @@ CommandCost CmdBuildCanal(TileIndex tile
 
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
		}
 

	
 
		/* can't make water of water! */
 
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue;
 

	
 
		ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (CmdFailed(ret)) return ret;
 
		cost.AddCost(ret);
 

	
 
		if (flags & DC_EXEC) {
 
			if (TileHeight(tile) == 0 && p2 == 1) {
 
				MakeWater(tile);
 
				MakeSea(tile);
 
			} else if (p2 == 2) {
 
				MakeRiver(tile, Random());
 
			} else {
 
				MakeCanal(tile, _current_company, Random());
 
			}
 
			MarkTileDirtyByTile(tile);
 
			MarkCanalsAndRiversAroundDirty(tile);
 
		}
 

	
 
		cost.AddCost(_price.clear_water);
 
	}
 

	
 
@@ -938,25 +938,25 @@ void DoFloodTile(TileIndex target)
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
		}
 
	} else {
 
		/* Flood vehicles */
 
		FloodVehicles(target);
 

	
 
		/* flood flat tile */
 
		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 
			MakeWater(target);
 
			MakeSea(target);
 
			MarkTileDirtyByTile(target);
 
			flooded = true;
 
		}
 
	}
 

	
 
	if (flooded) {
 
		/* Mark surrounding canal tiles dirty too to avoid glitches */
 
		MarkCanalsAndRiversAroundDirty(target);
 

	
 
		/* update signals if needed */
 
		UpdateSignalsInBuffer();
 
	}
 
@@ -1058,25 +1058,25 @@ void ConvertGroundTilesIntoWaterTiles()
 
	TileIndex tile;
 
	uint z;
 
	Slope slope;
 

	
 
	for (tile = 0; tile < MapSize(); ++tile) {
 
		slope = GetTileSlope(tile, &z);
 
		if (IsTileType(tile, MP_CLEAR) && z == 0) {
 
			/* Make both water for tiles at level 0
 
			 * and make shore, as that looks much better
 
			 * during the generation. */
 
			switch (slope) {
 
				case SLOPE_FLAT:
 
					MakeWater(tile);
 
					MakeSea(tile);
 
					break;
 

	
 
				case SLOPE_N:
 
				case SLOPE_E:
 
				case SLOPE_S:
 
				case SLOPE_W:
 
					MakeShore(tile);
 
					break;
 

	
 
				default:
 
					uint check_dirs = _flood_from_dirs[slope & ~SLOPE_STEEP];
 
					uint dir;
src/water_map.h
Show inline comments
 
@@ -139,71 +139,84 @@ static inline DiagDirection GetLockDirec
 
static inline byte GetSection(TileIndex t)
 
{
 
	assert(GetWaterTileType(t) == WATER_TILE_LOCK || GetWaterTileType(t) == WATER_TILE_DEPOT);
 
	return GB(_m[t].m5, 0, 4);
 
}
 

	
 
static inline byte GetWaterTileRandomBits(TileIndex t)
 
{
 
	return _m[t].m4;
 
}
 

	
 

	
 
static inline void MakeWater(TileIndex t)
 
{
 
	SetTileType(t, MP_WATER);
 
	SetTileOwner(t, OWNER_WATER);
 
	_m[t].m2 = 0;
 
	_m[t].m3 = WATER_CLASS_SEA;
 
	_m[t].m4 = 0;
 
	_m[t].m5 = 0;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 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;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
}
 

	
 
static inline void MakeRiver(TileIndex t, uint8 random_bits)
 
/**
 
 * Helper function for making a watery tile.
 
 * @param t The tile to change into water
 
 * @param o The owner of the water
 
 * @param wc The class of water the tile has to be
 
 * @param random_bits Eventual random bits to be set for this tile
 
 */
 
static inline void MakeWater(TileIndex t, Owner o, WaterClass wc, uint8 random_bits)
 
{
 
	SetTileType(t, MP_WATER);
 
	SetTileOwner(t, OWNER_WATER);
 
	SetTileOwner(t, o);
 
	_m[t].m2 = 0;
 
	_m[t].m3 = WATER_CLASS_RIVER;
 
	_m[t].m3 = wc;
 
	_m[t].m4 = random_bits;
 
	_m[t].m5 = 0;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
}
 

	
 
/**
 
 * Make a sea tile.
 
 * @param t The tile to change into sea
 
 */
 
static inline void MakeSea(TileIndex t)
 
{
 
	MakeWater(t, OWNER_WATER, WATER_CLASS_SEA, 0);
 
}
 

	
 
/**
 
 * Make a river tile
 
 * @param t The tile to change into river
 
 * @param random_bits Random bits to be set for this tile
 
 */
 
static inline void MakeRiver(TileIndex t, uint8 random_bits)
 
{
 
	MakeWater(t, OWNER_WATER, WATER_CLASS_RIVER, random_bits);
 
}
 

	
 
/**
 
 * Make a canal tile
 
 * @param t The tile to change into canal
 
 * @param o The owner of the canal
 
 * @param random_bits Random bits to be set for this tile
 
 */
 
static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
 
{
 
	assert(o != OWNER_WATER);
 
	SetTileType(t, MP_WATER);
 
	SetTileOwner(t, o);
 
	_m[t].m2 = 0;
 
	_m[t].m3 = WATER_CLASS_CANAL;
 
	_m[t].m4 = random_bits;
 
	_m[t].m5 = 0;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
	MakeWater(t, o, WATER_CLASS_CANAL, random_bits);
 
}
 

	
 
static inline void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart base, Axis a, WaterClass original_water_class)
 
{
 
	SetTileType(t, MP_WATER);
 
	SetTileOwner(t, o);
 
	_m[t].m2 = did;
 
	_m[t].m3 = original_water_class;
 
	_m[t].m4 = 0;
 
	_m[t].m5 = base + a * 2;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
0 comments (0 inline, 0 general)