1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

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)
This commit is contained in:
Xilmi 2024-08-15 18:15:29 +02:00
parent 6193e6224f
commit a79f76f32b

View File

@ -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<float>(available[i]) / required[i];
@ -625,6 +628,8 @@ bool Nullkiller::handleTrading()
float ratio = available[i];
if (required[i] > 0)
ratio = static_cast<float>(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;