From 558ad55bb0d86690c8bdd76dbafedf79fc777083 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Sun, 13 Dec 2015 23:20:07 +0100 Subject: [PATCH] fix a potential bug when requesting supplies for queued AI things caused by re-arranging the queue --- src/ai/ai_resource.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ai/ai_resource.cpp b/src/ai/ai_resource.cpp index 883a7a45b..dc30c0602 100644 --- a/src/ai/ai_resource.cpp +++ b/src/ai/ai_resource.cpp @@ -862,6 +862,7 @@ static void AiCheckingWork() for (int i = 0; i < sz; ++i) { AiBuildQueue &queue = AiPlayer->UnitTypeBuilt[AiPlayer->UnitTypeBuilt.size() - sz + i]; CUnitType &type = *queue.Type; + bool new_supply = false; // FIXME: must check if requirements are fulfilled. // Buildings can be destroyed. @@ -869,7 +870,7 @@ static void AiCheckingWork() // Check if we have enough food. if (type.Stats[AiPlayer->Player->Index].Variables[DEMAND_INDEX].Value && !AiCheckSupply(*AiPlayer, type)) { AiPlayer->NeedSupply = true; - AiRequestSupply(); + new_supply = true; } // Check limits, AI should be broken if reached. if (queue.Want > queue.Made && AiPlayer->Player->CheckLimits(type) < 0) { @@ -897,6 +898,10 @@ static void AiCheckingWork() } } } + if (new_supply) { + // trigger this last, because it may re-arrange the queue and invalidate our queue item + AiRequestSupply(); + } } }