Old revision #pogzmtclz | New revision #phckb7exn | ||
---|---|---|---|
2 | =================================================================== | 2 | =================================================================== |
3 | --- src/saveload/company_sl.cpp (revision 27153) | 3 | --- src/saveload/company_sl.cpp (revision 27153) |
4 | +++ src/saveload/company_sl.cpp (working copy) | 4 | +++ src/saveload/company_sl.cpp (working copy) |
5 | @@ -179,8 +179,1 | 5 | @@ -179,8 +179,11 @@ |
6 | if (IsShipDepot(tile)) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR; | 6 | if (IsShipDepot(tile)) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR; |
7 | if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) { | 7 | if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) { |
8 | /* The middle tile specifies the owner of the lock. */ | 8 | /* The middle tile specifies the owner of the lock. */ |
9 | - c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // the middle tile specifies the owner of the | 9 | - c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // the middle tile specifies the owner of the |
10 | - break; // do not count the middle tile as canal | 10 | - break; // do not count the middle tile as canal |
11 | + c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; | 11 | + c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; |
12 | + | ||
12 | + /* Only count the middle tile as canal if the tile is not river. */ | 13 | + /* Only count the middle tile as canal if the tile is not river. */ |
13 | + if (GetWaterClass(tile) != WATER_CLASS_RIVER) { | 13 | + if (GetWaterClass(tile) != WATER_CLASS_RIVER) c->infrastructure.water++; |
14 | + c->infrastructure.water++; | ||
15 | + } | ||
16 | + break; | 15 | + break; |
17 | } | 16 | } |
18 | } | 17 | } | … | … |
28 | - ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 27 | - ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
29 | - if (ret.Failed()) return ret; | 28 | - if (ret.Failed()) return ret; |
30 | - cost.AddCost(ret); | 29 | - cost.AddCost(ret); |
31 | + | 31 | + |
32 | + /* Add the cost of building a canal when the middle tile isn't a river. */ | ||
33 | + if (!IsWaterTile(tile)) { | 31 | + if (!IsWaterTile(tile)) { |
34 | + ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 32 | + ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
35 | + if (ret.Failed()) return ret; | 33 | + if (ret.Failed()) return ret; |
36 | + cost.AddCost(ret); | 34 | + cost.AddCost(ret); |
37 | + cost.AddCost(_price[PR_BUILD_CANAL]); // extra cost. | 35 | + /* Add an extra cost only if not building on a river. */ |
36 | + cost.AddCost(_price[PR_BUILD_CANAL]); | ||
38 | + } | 37 | + } |
39 | 38 | ||
40 | /* lower tile */ | 39 | /* lower tile */ | … | … |
43 | if (c != NULL) { | 42 | if (c != NULL) { |
44 | /* Counts for the water. */ | 43 | /* Counts for the water. */ |
45 | if (!IsWaterTile(tile - delta)) c->infrastructure.water++; | 44 | if (!IsWaterTile(tile - delta)) c->infrastructure.water++; |
46 | + if (!IsWaterTile(tile)) c->infrastructure.water++; | 46 | + if (!IsWaterTile(tile)) c->infrastructure.water++; |
47 | if (!IsWaterTile(tile + delta)) c->infrastructure.water++; | 46 | if (!IsWaterTile(tile + delta)) c->infrastructure.water++; |
48 | /* Count for the lock itself. */ | 47 | /* Count for the lock itself. */ |
49 | c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles. | 48 | c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles. | … | … |
51 | */ | 50 | */ |
52 | static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags) | 51 | static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags) |
53 | { | 52 | { |
54 | + CommandCost cost(EXPENSES_CONSTRUCTION); | 54 | + CommandCost cost(EXPENSES_CONSTRUCTION); |
55 | + | 54 | + |
56 | if (GetTileOwner(tile) != OWNER_NONE) { | 55 | if (GetTileOwner(tile) != OWNER_NONE) { |
57 | CommandCost ret = CheckTileOwnership(tile); | 56 | CommandCost ret = CheckTileOwnership(tile); | … | … |
60 | if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta); | 59 | if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta); |
61 | if (ret.Failed()) return ret; | 60 | if (ret.Failed()) return ret; |
62 | 61 | ||
63 | + /* Add | 63 | + /* Add an extra cost only if it was not built on a river. */ |
64 | + if (GetWaterClass(tile) != WATER_CLASS_RIVER) cost.AddCost(_price[PR_CLEAR_CANAL]); | 64 | + if (GetWaterClass(tile) != WATER_CLASS_RIVER) cost.AddCost(_price[PR_CLEAR_CANAL]); |
65 | + | 64 | + |
66 | if (flags & DC_EXEC) { | 65 | if (flags & DC_EXEC) { |
67 | /* Remove middle part from company infrastructure count. */ | 66 | /* Remove middle part from company infrastructure count. */ |
68 | Company *c = Company::GetIfValid(GetTileOwner(tile)); | 67 | Company *c = Company::GetIfValid(GetTileOwner(tile)); |
69 | @@ -348,6 +359, | 69 | @@ -348,6 +359,7 @@ |
70 | if (GetWaterClass(tile) == WATER_CLASS_RIVER) { | 69 | if (GetWaterClass(tile) == WATER_CLASS_RIVER) { |
71 | MakeRiver(tile, Random()); | 70 | MakeRiver(tile, Random()); |
72 | } else { | 71 | } else { |
73 | + if (c != NULL) { // make sure it's not a leftover or neutral lock. | 73 | + if (c != NULL) c->infrastructure.water--; // Make sure it's not a leftover or neutral lock. |
74 | + c->infrastructure.water--; // extra count. | ||
75 | + } | ||
76 | DoClearSquare(tile); | 73 | DoClearSquare(tile); |
77 | } | 74 | } |
78 | MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); | 75 | MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); |
79 | @@ -357,7 +3 | 79 | @@ -357,7 +369,9 @@ |
80 | MarkCanalsAndRiversAroundDirty(tile + delta); | 77 | MarkCanalsAndRiversAroundDirty(tile + delta); |
81 | } | 78 | } |
82 | 79 | ||
83 | - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]); | 80 | - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]); |
84 | + cost.AddCost(_price[PR_CLEAR_LOCK]); | 84 | + cost.AddCost(_price[PR_CLEAR_LOCK]); |
85 | + return cost; | 85 | + return cost; |
86 | + | 83 | + |
87 | } | 84 | } |
88 | 85 | ||
89 | /** | 86 | /** |
90 | @@ -1275,9 +12 | 90 | @@ -1275,9 +1289,15 @@ |
91 | bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE; | 88 | bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE; |
92 | 89 | ||
93 | /* No need to dirty company windows here, we'll redraw the whole screen anyway. */ | 90 | /* No need to dirty company windows here, we'll redraw the whole screen anyway. */ |
94 | - if (is_lock_middle) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. | 91 | - if (is_lock_middle) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. |
95 | + if (is_lock_middle) { | 92 | + if (is_lock_middle) { |
96 | + Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. | 93 | + Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. |
97 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(old_owner)->infrastructure.water--; | 97 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(old_owner)->infrastructure.water--; |
98 | + } | 95 | + } |
99 | if (new_owner != INVALID_OWNER) { | 96 | if (new_owner != INVALID_OWNER) { |
100 | - if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. | 97 | - if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. |
101 | + if (is_lock_middle) { | 98 | + if (is_lock_middle) { |
102 | + Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. | 99 | + Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. |
103 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(new_owner)->infrastructure.water++; | 103 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(new_owner)->infrastructure.water++; |
104 | + } | 101 | + } |
105 | /* Only subtract from the old owner here if the new owner is valid, | 102 | /* Only subtract from the old owner here if the new owner is valid, |
106 | * otherwise we clear ship depots and canal water below. */ | 103 | * otherwise we clear ship depots and canal water below. */ |