Old revision #pv8ckd8ru | 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 | @@ -348,6 +353,9 @@ | 50 | @@ -324,6 +330,8 @@ |
51 | */ | ||
52 | static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags) | ||
53 | { | ||
54 | + CommandCost cost(EXPENSES_CONSTRUCTION); // dependable variable needed to adjust cost for this command. | ||
55 | + | ||
56 | if (GetTileOwner(tile) != OWNER_NONE) { | ||
57 | CommandCost ret = CheckTileOwnership(tile); | ||
58 | if (ret.Failed()) return ret; | ||
59 | @@ -337,6 +345,9 @@ | ||
60 | if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta); | ||
61 | if (ret.Failed()) return ret; | ||
62 | |||
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 | + | ||
66 | if (flags & DC_EXEC) { | ||
67 | /* Remove middle part from company infrastructure count. */ | ||
68 | Company *c = Company::GetIfValid(GetTileOwner(tile)); | ||
69 | @@ -348,6 +359,9 @@ | ||
46 | if (GetWaterClass(tile) == WATER_CLASS_RIVER) { | 70 | if (GetWaterClass(tile) == WATER_CLASS_RIVER) { |
47 | MakeRiver(tile, Random()); | 71 | MakeRiver(tile, Random()); |
48 | } else { | 72 | } else { |
49 | + if (c != NULL) { | 49 | + if (c != NULL) { // make sure it's not a leftover or neutral lock. |
50 | + c->infrastructure.water--; | 50 | + c->infrastructure.water--; // extra count. |
51 | + } | 75 | + } |
52 | DoClearSquare(tile); | 76 | DoClearSquare(tile); |
53 | } | 77 | } |
54 | MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); | 78 | MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); |
55 | @@ -1276,8 +1284,14 @@ | 79 | @@ -357,7 +371,9 @@ |
80 | MarkCanalsAndRiversAroundDirty(tile + delta); | ||
81 | } | ||
82 | |||
83 | - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]); | ||
84 | + cost.AddCost(_price[PR_CLEAR_LOCK]); // add the base cost of clearing a lock | ||
85 | + return cost; // final cost for this command | ||
86 | + | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | @@ -1275,9 +1291,15 @@ | ||
91 | bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE; | ||
56 | 92 | ||
57 | /* 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. */ |
58 | 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. |
59 | + if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) { | 95 | + if (is_lock_middle) { |
60 | + Company::Get(old_owner)->infrastructure.water--; | 96 | + 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--; // extra count. | ||
61 | + } | 98 | + } |
62 | if (new_owner != INVALID_OWNER) { | 99 | 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. | 100 | - 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) { | 101 | + if (is_lock_middle) { |
65 | + Company::Get(new_owner)->infrastructure.water++; | 102 | + 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++; // extra count. | ||
66 | + } | 104 | + } |
67 | /* 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, |
68 | * otherwise we clear ship depots and canal water below. */ | 106 | * otherwise we clear ship depots and canal water below. */ |