From a79f76f32be284ea693d7e7fcca3ca8f13e3939a Mon Sep 17 00:00:00 2001 From: Xilmi Date: Thu, 15 Aug 2024 18:15:29 +0200 Subject: [PATCH] Update Nullkiller.cpp Fix issue with selling/buying the same resources back and forth. But probably leads to not using the market early on. (needs more testing) --- AI/Nullkiller/Engine/Nullkiller.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index 4dbbe36c8..8b3843c90 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -601,7 +601,10 @@ bool Nullkiller::handleTrading() buildAnalyzer->update(); TResources required = buildAnalyzer->getTotalResourcesRequired(); TResources income = buildAnalyzer->getDailyIncome(); - TResources available = getFreeResources(); + TResources available = cb->getResourceAmount(); + + logAi->debug("Available %s", available.toString()); + logAi->debug("Required %s", required.toString()); int mostWanted = -1; int mostExpendable = -1; @@ -610,7 +613,7 @@ bool Nullkiller::handleTrading() for (int i = 0; i < required.size(); ++i) { - if (required[i] == 0) + if (required[i] <= 0) continue; float ratio = static_cast(available[i]) / required[i]; @@ -625,6 +628,8 @@ bool Nullkiller::handleTrading() float ratio = available[i]; if (required[i] > 0) ratio = static_cast(available[i]) / required[i]; + else + ratio = available[i]; bool okToSell = false; @@ -635,7 +640,7 @@ bool Nullkiller::handleTrading() } else { - if (available[i] > required[i]) + if (required[i] <= 0) okToSell = true; } @@ -645,7 +650,7 @@ bool Nullkiller::handleTrading() } } - //logAi->info("mostExpendable: %d mostWanted: %d", mostExpendable, mostWanted); + logAi->debug("mostExpendable: %d mostWanted: %d", mostExpendable, mostWanted); if (mostExpendable == mostWanted || mostWanted == -1 || mostExpendable == -1) return false;