summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_instance.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 4d808e055..f109a0926 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -238,8 +238,17 @@ ScriptInfo *AIInstance::FindLibrary(const char *library, int version)
*/
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
{
- Company::Get(_current_company)->ai_instance->DoCommandCallback(result, tile, p1, p2);
- Company::Get(_current_company)->ai_instance->Continue();
+ /*
+ * The company might not exist anymore. Check for this.
+ * The command checks are not useful since this callback
+ * is also called when the command fails, which is does
+ * when the company does not exist anymore.
+ */
+ const Company *c = Company::GetIfValid(_current_company);
+ if (c == NULL || c->ai_instance == NULL) return;
+
+ c->ai_instance->DoCommandCallback(result, tile, p1, p2);
+ c->ai_instance->Continue();
}
CommandCallback *AIInstance::GetDoCommandCallback()