summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-01-11 18:46:09 +0000
committerrubidium <rubidium@openttd.org>2010-01-11 18:46:09 +0000
commit2b97f38cd176d5638053c87199e6ac175d5ee1e4 (patch)
tree85e4776e0646803f4d69f9c700e1712df215be6a /src/ai
parent48df0d4e06ee05e56793cc6e638d649126032d4e (diff)
downloadopenttd-2b97f38cd176d5638053c87199e6ac175d5ee1e4.tar.xz
(svn r18781) -Codechange: pass the CommandCost to the callback instead of whether it succeeded or not.
-Fix: AIs did update their last cost incorrectly in network games if the cost of the DC_EXEC phase differed from the ~DC_EXEC phase.
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai.hpp2
-rw-r--r--src/ai/ai_core.cpp11
-rw-r--r--src/ai/api/ai_object.hpp2
3 files changed, 7 insertions, 8 deletions
diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp
index a23c411af..04eb7b16d 100644
--- a/src/ai/ai.hpp
+++ b/src/ai/ai.hpp
@@ -20,8 +20,6 @@
typedef std::map<const char *, class AIInfo *, StringCompare> AIInfoList;
-void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2);
-
class AI {
public:
/**
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp
index baf738920..eb93ecff3 100644
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -218,14 +218,15 @@
event->Release();
}
-void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
+void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
{
- AIObject::SetLastCommandRes(success);
+ AIObject::SetLastCommandRes(result.Succeeded());
- if (!success) {
- AIObject::SetLastError(AIError::StringToError(_error_message));
+ if (result.Failed()) {
+ AIObject::SetLastError(AIError::StringToError(result.GetErrorMessage()));
} else {
- AIObject::IncreaseDoCommandCosts(AIObject::GetLastCost());
+ AIObject::IncreaseDoCommandCosts(result.GetCost());
+ AIObject::SetLastCost(result.GetCost());
}
Company::Get(_current_company)->ai_instance->Continue();
diff --git a/src/ai/api/ai_object.hpp b/src/ai/api/ai_object.hpp
index 98343e870..77e9fe885 100644
--- a/src/ai/api/ai_object.hpp
+++ b/src/ai/api/ai_object.hpp
@@ -36,7 +36,7 @@ typedef bool (AIModeProc)();
* command processing, and command-validation checks.
*/
class AIObject : public SimpleCountedObject {
-friend void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2);
+friend void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
friend class AIInstance;
protected:
/**