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