Old revision #pv8ckd8ru | 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 | @@ -180,6 +180,9 @@ | 5 | @@ -179,8 +179,11 @@ |
6 | if (IsShipDepot(tile)) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR; | ||
6 | if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) { | 7 | if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) { |
7 | /* The middle tile specifies the owner of the lock. */ | 8 | /* The middle tile specifies the owner of the lock. */ |
8 | 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 |
9 | + if (GetWaterClass(tile) != WATER_CLASS_CANAL) { | 10 | - break; // do not count the middle tile as canal |
10 | + c->infrastructure.water++; | 11 | + c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; |
11 | + } | 12 | + |
12 | break; // do not count the middle tile as canal | 13 | + /* Only count the middle tile as canal if the tile is not river. */ |
14 | + if (GetWaterClass(tile) != WATER_CLASS_RIVER) c->infrastructure.water++; | ||
15 | + break; | ||
13 | } | 16 | } |
14 | } | 17 | } |
18 | } | ||
15 | Index: src/water_cmd.cpp | 19 | Index: src/water_cmd.cpp |
16 | =================================================================== | 20 | =================================================================== |
17 | --- src/water_cmd.cpp (revision 27153) | 21 | --- src/water_cmd.cpp (revision 27153) |
18 | +++ src/water_cmd.cpp (working copy) | 22 | +++ src/water_cmd.cpp (working copy) |
19 | @@ -258, | 19 | @@ -258,9 +258,14 @@ |
20 | 24 | ||
21 | /* middle tile */ | 25 | /* middle tile */ |
22 | WaterClass wc_middle = IsWaterTile(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL; | 26 | WaterClass wc_middle = IsWaterTile(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL; |
23 | - ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 27 | - ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
24 | - if (ret.Failed()) return ret; | 28 | - if (ret.Failed()) return ret; |
25 | - cost.AddCost(ret); | 29 | - cost.AddCost(ret); |
26 | 26 | + | |
27 | + if (!IsWaterTile(tile)) { | 31 | + if (!IsWaterTile(tile)) { |
28 | + ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 32 | + ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
29 | + if (ret.Failed()) return ret; | 33 | + if (ret.Failed()) return ret; |
30 | + cost.AddCost(ret); | 34 | + cost.AddCost(ret); |
35 | + /* Add an extra cost only if not building on a river. */ | ||
31 | + cost.AddCost(_price[PR_BUILD_CANAL]); | 36 | + cost.AddCost(_price[PR_BUILD_CANAL]); |
32 | + } | 37 | + } |
33 | 33 | ||
34 | /* lower tile */ | 39 | /* lower tile */ |
35 | WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL; | 40 | WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL; |
36 | 36 | @@ -298,6 +303,7 @@ | |
37 | @@ -298,6 +302,7 @@ | ||
38 | if (c != NULL) { | 42 | if (c != NULL) { |
39 | /* Counts for the water. */ | 43 | /* Counts for the water. */ |
40 | if (!IsWaterTile(tile - delta)) c->infrastructure.water++; | 44 | if (!IsWaterTile(tile - delta)) c->infrastructure.water++; | … | … |
42 | if (!IsWaterTile(tile + delta)) c->infrastructure.water++; | 46 | if (!IsWaterTile(tile + delta)) c->infrastructure.water++; |
43 | /* Count for the lock itself. */ | 47 | /* Count for the lock itself. */ |
44 | 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. |
45 | @@ -348,6 +353,9 @@ | 49 | @@ -324,6 +330,8 @@ |
50 | */ | ||
51 | static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags) | ||
52 | { | ||
53 | + CommandCost cost(EXPENSES_CONSTRUCTION); | ||
54 | + | ||
55 | if (GetTileOwner(tile) != OWNER_NONE) { | ||
56 | CommandCost ret = CheckTileOwnership(tile); | ||
57 | if (ret.Failed()) return ret; | ||
58 | @@ -337,6 +345,9 @@ | ||
59 | if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta); | ||
60 | if (ret.Failed()) return ret; | ||
61 | |||
62 | + /* Add an extra cost only if it was not built on a river. */ | ||
63 | + if (GetWaterClass(tile) != WATER_CLASS_RIVER) cost.AddCost(_price[PR_CLEAR_CANAL]); | ||
64 | + | ||
65 | if (flags & DC_EXEC) { | ||
66 | /* Remove middle part from company infrastructure count. */ | ||
67 | Company *c = Company::GetIfValid(GetTileOwner(tile)); | ||
68 | @@ -348,6 +359,7 @@ | ||
46 | if (GetWaterClass(tile) == WATER_CLASS_RIVER) { | 69 | if (GetWaterClass(tile) == WATER_CLASS_RIVER) { |
47 | MakeRiver(tile, Random()); | 70 | MakeRiver(tile, Random()); |
48 | } else { | 71 | } else { |
49 | + if (c != NULL) { | 49 | + if (c != NULL) c->infrastructure.water--; // Make sure it's not a leftover or neutral lock. |
50 | + c->infrastructure.water--; | ||
51 | + } | ||
52 | DoClearSquare(tile); | 73 | DoClearSquare(tile); |
53 | } | 74 | } |
54 | MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); | 75 | MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); |
55 | @@ -1276,8 +1284,14 @@ | 76 | @@ -357,7 +369,9 @@ |
77 | MarkCanalsAndRiversAroundDirty(tile + delta); | ||
78 | } | ||
79 | |||
80 | - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]); | ||
81 | + cost.AddCost(_price[PR_CLEAR_LOCK]); | ||
82 | + return cost; | ||
83 | + | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | @@ -1275,9 +1289,15 @@ | ||
88 | bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE; | ||
56 | 89 | ||
57 | /* 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. */ |
58 | 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. |
59 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) { | 92 | + if (is_lock_middle) { |
60 | + Company::Get(old_owner)->infrastructure.water--; | 93 | + Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. |
94 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(old_owner)->infrastructure.water--; | ||
61 | + } | 95 | + } |
62 | if (new_owner != INVALID_OWNER) { | 96 | if (new_owner != INVALID_OWNER) { |
63 | 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. |
64 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) { | 98 | + if (is_lock_middle) { |
65 | + Company::Get(new_owner)->infrastructure.water++; | 99 | + Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts. |
100 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(new_owner)->infrastructure.water++; | ||
66 | + } | 101 | + } |
67 | /* 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, |
68 | * otherwise we clear ship depots and canal water below. */ | 103 | * otherwise we clear ship depots and canal water below. */ |