summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-02-26 16:22:58 +0100
committerGitHub <noreply@github.com>2021-02-26 16:22:58 +0100
commit9a3dbf3122f63f65ce95b2201c4dfe98c6003bc9 (patch)
treed36dc3b8c466d4ece47022cc5a911ef0a80a7421
parentd4583fa64c067c00d3a7592642b3c269d02a8bef (diff)
downloadopenttd-9a3dbf3122f63f65ce95b2201c4dfe98c6003bc9.tar.xz
Fix 02e770ff: allow estimating CloneVehicle if short on money (#8748)
CheckCompanyHasMoney() was also executed when not using DC_EXEC, resulting in an error about shortage of money instead of the estimation. This mostly is a problem for AI players, as they will have no way to know how much it would have cost.
-rw-r--r--src/script/api/ai_changelog.hpp3
-rw-r--r--src/vehicle_cmd.cpp10
2 files changed, 7 insertions, 6 deletions
diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp
index 5d5d5c26f..a0d9097d9 100644
--- a/src/script/api/ai_changelog.hpp
+++ b/src/script/api/ai_changelog.hpp
@@ -21,6 +21,9 @@
* \li AICargo::GetName
* \li AIPriorityQueue
*
+ * Other changes:
+ * \li AIVehicle::CloneVehicle now correctly returns estimate when short on cash
+ *
* \b 1.10.0
*
* API additions:
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 32706837f..9da6b89ce 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -987,16 +987,14 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
/* Now clone the vehicle's name, if it has one. */
if (!v_front->name.empty()) CloneVehicleName(v_front, w_front);
- }
- /* Since we can't estimate the cost of cloning a vehicle accurately we must
- * check whether the company has enough money manually. */
- if (!CheckCompanyHasMoney(total_cost)) {
- if (flags & DC_EXEC) {
+ /* Since we can't estimate the cost of cloning a vehicle accurately we must
+ * check whether the company has enough money manually. */
+ if (!CheckCompanyHasMoney(total_cost)) {
/* The vehicle has already been bought, so now it must be sold again. */
DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
+ return total_cost;
}
- return total_cost;
}
return total_cost;