Changeset - r18558:0017880a5972
[Not reviewed]
master
0 6 0
michi_cc - 12 years ago 2011-12-03 23:40:23
michi_cc@openttd.org
(svn r23413) -Add: Company infrastructure counts for canals.
6 files changed with 116 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/economy_type.h
Show inline comments
 
@@ -202,11 +202,13 @@ static const int MAX_PRICE_MODIFIER = 16
 
static const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1;
 

	
 
/** Multiplier for how many regular track bits a tunnel/bridge counts. */
 
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4;
 
/** Multiplier for how many regular track bits a level crossing counts. */
 
static const uint LEVELCROSSING_TRACKBIT_FACTOR = 2;
 
/** Multiplier for how many regular tiles a lock counts. */
 
static const uint LOCK_DEPOT_TILE_FACTOR = 2;
 

	
 
struct CargoPayment;
 
typedef uint32 CargoPaymentID;
 

	
 
#endif /* ECONOMY_TYPE_H */
src/object_cmd.cpp
Show inline comments
 
@@ -100,12 +100,17 @@ void BuildObject(ObjectType type, TileIn
 
	}
 

	
 
	assert(o->town != NULL);
 

	
 
	TILE_AREA_LOOP(t, ta) {
 
		WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID);
 
		/* Update company infrastructure counts for objects build on canals owned by nobody. */
 
		if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, OWNER_WATER))) {
 
			Company::Get(owner)->infrastructure.water++;
 
			DirtyCompanyInfrastructureWindows(owner);
 
		}
 
		MakeObject(t, type, owner, o->index, wc, Random());
 
		MarkTileDirtyByTile(t);
 
	}
 

	
 
	Object::IncTypeCount(type);
 
	if (spec->flags & OBJECT_FLAG_ANIMATION) TriggerObjectAnimation(o, OAT_BUILT, spec);
src/saveload/company_sl.cpp
Show inline comments
 
@@ -148,17 +148,38 @@ void AfterLoadCompanyStats()
 
							c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
							if (c != NULL) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
 
						}
 
						break;
 
					}
 

	
 
					case STATION_DOCK:
 
					case STATION_BUOY:
 
						if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
 
							if (c != NULL) c->infrastructure.water++;
 
						}
 
						break;
 

	
 
					default:
 
						break;
 
				}
 
				break;
 

	
 
			case MP_WATER:
 
				if (IsShipDepot(tile) || IsLock(tile)) {
 
					c = Company::GetIfValid(GetTileOwner(tile));
 
					if (c != NULL) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
 
				}
 
				/* FALL THROUGH */
 

	
 
			case MP_OBJECT:
 
				if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
 
					c = Company::GetIfValid(GetTileOwner(tile));
 
					if (c != NULL) c->infrastructure.water++;
 
				}
 
				break;
 

	
 
			case MP_TUNNELBRIDGE: {
 
				/* Only count the tunnel/bridge if we're on the northern end tile. */
 
				TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
 
				if (tile < other_end) {
 
					/* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
 
					 * the higher structural maintenance needs, and don't forget the end tiles. */
 
@@ -177,12 +198,17 @@ void AfterLoadCompanyStats()
 
								c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
								if (c != NULL) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
 
							}
 
							break;
 
						}
 

	
 
						case TRANSPORT_WATER:
 
							c = Company::GetIfValid(GetTileOwner(tile));
 
							if (c != NULL) c->infrastructure.water += len;
 
							break;
 

	
 
						default:
 
							break;
 
					}
 
				}
 
				break;
 
			}
src/station_cmd.cpp
Show inline comments
 
@@ -2479,12 +2479,19 @@ CommandCost CmdBuildDock(TileIndex tile,
 
		st->AddFacility(FACIL_DOCK, tile);
 

	
 
		st->rect.BeforeAddRect(
 
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
 
				_dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
 

	
 
		/* If the water part of the dock is on a canal, update infrastructure counts.
 
		 * This is needed as we've unconditionally cleared that tile before. */
 
		if (wc == WATER_CLASS_CANAL) {
 
			Company::Get(st->owner)->infrastructure.water++;
 
			DirtyCompanyInfrastructureWindows(st->owner);
 
		}
 

	
 
		MakeDock(tile, st->owner, st->index, direction, wc);
 

	
 
		st->UpdateVirtCoord();
 
		UpdateStationAcceptance(st, false);
 
		st->RecomputeIndustriesNear();
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -453,12 +453,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
				}
 
				MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir,                 roadtypes);
 
				MakeRoadBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), roadtypes);
 
				break;
 

	
 
			case TRANSPORT_WATER:
 
				if (!IsBridgeTile(tile_start) && c != NULL) c->infrastructure.water += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
				MakeAqueductBridgeRamp(tile_start, owner, dir);
 
				MakeAqueductBridgeRamp(tile_end,   owner, ReverseDiagDir(dir));
 
				break;
 

	
 
			default:
 
				NOT_REACHED();
 
@@ -853,12 +854,14 @@ static CommandCost DoClearBridge(TileInd
 
				if (c != NULL) {
 
					/* A full diagonal road tile has two road bits. */
 
					c->infrastructure.road[rt] -= len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 
			}
 
		} else { // Aqueduct
 
			if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
		}
 
		DirtyCompanyInfrastructureWindows(owner);
 

	
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
		for (TileIndex c = tile + delta; c != endtile; c += delta) {
 
@@ -1571,12 +1574,15 @@ static void ChangeTileOwner_TunnelBridge
 
	 * No need to dirty windows here, we'll redraw the whole screen anyway. */
 
	TransportType tt = GetTunnelBridgeTransportType(tile);
 
	Company *old = Company::Get(old_owner);
 
	if (tt == TRANSPORT_RAIL) {
 
		old->infrastructure.rail[GetRailType(tile)] -= num_pieces;
 
		if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.rail[GetRailType(tile)] += num_pieces;
 
	} else if (tt == TRANSPORT_WATER) {
 
		old->infrastructure.water -= num_pieces;
 
		if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.water += num_pieces;
 
	}
 

	
 
	if (new_owner != INVALID_OWNER) {
 
		SetTileOwner(tile, new_owner);
 
	} else {
 
		if (tt == TRANSPORT_RAIL) {
src/water_cmd.cpp
Show inline comments
 
@@ -32,12 +32,14 @@
 
#include "tunnelbridge_map.h"
 
#include "station_base.h"
 
#include "ai/ai.hpp"
 
#include "core/random_func.hpp"
 
#include "core/backup_type.hpp"
 
#include "date_func.h"
 
#include "company_base.h"
 
#include "company_gui.h"
 

	
 
#include "table/strings.h"
 

	
 
/**
 
 * Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
 
 */
 
@@ -131,12 +133,19 @@ CommandCost CmdBuildShipDepot(TileIndex 
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *depot = new Depot(tile);
 
		depot->build_date = _date;
 

	
 
		if (wc1 == WATER_CLASS_CANAL || wc2 == WATER_CLASS_CANAL) {
 
			/* Update infrastructure counts after the unconditional clear earlier. */
 
			Company::Get(_current_company)->infrastructure.water += wc1 == WATER_CLASS_CANAL && wc2 == WATER_CLASS_CANAL ? 2 : 1;
 
		}
 
		Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR;
 
		DirtyCompanyInfrastructureWindows(_current_company);
 

	
 
		MakeShipDepot(tile,  _current_company, depot->index, DEPOT_PART_NORTH, axis, wc1);
 
		MakeShipDepot(tile2, _current_company, depot->index, DEPOT_PART_SOUTH, axis, wc2);
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile2);
 
		MakeDefaultName(depot);
 
	}
 
@@ -147,15 +156,34 @@ CommandCost CmdBuildShipDepot(TileIndex 
 
void MakeWaterKeepingClass(TileIndex tile, Owner o)
 
{
 
	WaterClass wc = GetWaterClass(tile);
 

	
 
	/* Autoslope might turn an originally canal or river tile into land */
 
	int z;
 
	if (GetTileSlope(tile, &z) != SLOPE_FLAT) wc = WATER_CLASS_INVALID;
 
	if (GetTileSlope(tile, &z) != SLOPE_FLAT) {
 
		if (wc == WATER_CLASS_CANAL) {
 
			/* If we clear the canal, we have to remove it from the infrastructure count as well. */
 
			Company *c = Company::GetIfValid(o);
 
			if (c != NULL) {
 
				c->infrastructure.water--;
 
				DirtyCompanyInfrastructureWindows(c->index);
 
			}
 
		}
 
		wc = WATER_CLASS_INVALID;
 
	}
 

	
 
	if (wc == WATER_CLASS_SEA && z > 0) wc = WATER_CLASS_CANAL;
 
	if (wc == WATER_CLASS_SEA && z > 0) {
 
		/* Update company infrastructure count. */
 
		Company *c = Company::GetIfValid(o);
 
		if (c != NULL) {
 
			c->infrastructure.water++;
 
			DirtyCompanyInfrastructureWindows(c->index);
 
		}
 

	
 
		wc = WATER_CLASS_CANAL;
 
	}
 

	
 
	/* Zero map array and terminate animation */
 
	DoClearSquare(tile);
 

	
 
	/* Maybe change to water */
 
	switch (wc) {
 
@@ -184,12 +212,18 @@ static CommandCost RemoveShipDepot(TileI
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		delete Depot::GetByTile(tile);
 

	
 
		Company *c = Company::GetIfValid(GetTileOwner(tile));
 
		if (c != NULL) {
 
			c->infrastructure.water -= 2 * LOCK_DEPOT_TILE_FACTOR;
 
			DirtyCompanyInfrastructureWindows(c->index);
 
		}
 

	
 
		MakeWaterKeepingClass(tile,  GetTileOwner(tile));
 
		MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]);
 
}
 
@@ -246,12 +280,22 @@ static CommandCost DoBuildLock(TileIndex
 
	    (MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) ||
 
	    (MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) {
 
		return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Update company infrastructure counts. */
 
		Company *c = Company::Get(_current_company);
 
		/* Counts for the water. */
 
		c->infrastructure.water++;
 
		if (!IsWaterTile(tile - delta)) c->infrastructure.water++;
 
		if (!IsWaterTile(tile + delta)) c->infrastructure.water++;
 
		/* Count for the lock itself. */
 
		c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles.
 
		DirtyCompanyInfrastructureWindows(_current_company);
 

	
 
		MakeLock(tile, _current_company, dir, wc_lower, wc_upper);
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile - delta);
 
		MarkTileDirtyByTile(tile + delta);
 
		MarkCanalsAndRiversAroundDirty(tile - delta);
 
		MarkCanalsAndRiversAroundDirty(tile + delta);
 
@@ -280,12 +324,19 @@ static CommandCost RemoveLock(TileIndex 
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Remove middle part from company infrastructure count. */
 
		Company *c = Company::GetIfValid(GetTileOwner(tile));
 
		if (c != NULL) {
 
			c->infrastructure.water -= 1 + 3 * LOCK_DEPOT_TILE_FACTOR; // Middle tile + three parts of the lock.
 
			DirtyCompanyInfrastructureWindows(c->index);
 
		}
 

	
 
		DoClearSquare(tile);
 
		MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta));
 
		MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta));
 
		MarkCanalsAndRiversAroundDirty(tile - delta);
 
		MarkCanalsAndRiversAroundDirty(tile + delta);
 
	}
 
@@ -374,12 +425,16 @@ CommandCost CmdBuildCanal(TileIndex tile
 
						break;
 
					}
 
					/* FALL THROUGH */
 

	
 
				default:
 
					MakeCanal(tile, _current_company, Random());
 
					if (Company::IsValidID(_current_company)) {
 
						Company::Get(_current_company)->infrastructure.water++;
 
						DirtyCompanyInfrastructureWindows(_current_company);
 
					}
 
					break;
 
			}
 
			MarkTileDirtyByTile(tile);
 
			MarkCanalsAndRiversAroundDirty(tile);
 
		}
 

	
 
@@ -407,18 +462,23 @@ static CommandCost ClearTile_Water(TileI
 
			}
 

	
 
			/* Make sure no vehicle is on the tile */
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			if (ret.Failed()) return ret;
 

	
 
			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE) {
 
			Owner owner = GetTileOwner(tile);
 
			if (owner != OWNER_WATER && owner != OWNER_NONE) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				if (IsCanal(tile) && Company::IsValidID(owner)) {
 
					Company::Get(owner)->infrastructure.water--;
 
					DirtyCompanyInfrastructureWindows(owner);
 
				}
 
				DoClearSquare(tile);
 
				MarkCanalsAndRiversAroundDirty(tile);
 
			}
 

	
 
			return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
 
		}
 
@@ -1188,23 +1248,29 @@ static bool ClickTile_Water(TileIndex ti
 
}
 

	
 
static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	if (!IsTileOwner(tile, old_owner)) return;
 

	
 
	/* No need to dirty company windows here, we'll redraw the whole screen anyway. */
 
	if (IsCanal(tile)) Company::Get(old_owner)->infrastructure.water--;
 
	if (new_owner != INVALID_OWNER) {
 
		if (IsCanal(tile)) Company::Get(new_owner)->infrastructure.water++;
 
		SetTileOwner(tile, new_owner);
 
		return;
 
	}
 

	
 
	/* Remove depot */
 
	if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 

	
 
	/* Set owner of canals and locks ... and also canal under dock there was before.
 
	 * Check if the new owner after removing depot isn't OWNER_WATER. */
 
	if (IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
 
	if (IsTileOwner(tile, old_owner)) {
 
		if (IsCanal(tile)) Company::Get(old_owner)->infrastructure.water--;
 
		SetTileOwner(tile, OWNER_NONE);
 
	}
 
}
 

	
 
static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
 
{
 
	return VETSB_CONTINUE;
 
}
0 comments (0 inline, 0 general)