Quellcode durchsuchen

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)
Xilmi vor 1 Jahr
Ursprung
Commit
a79f76f32b
1 geänderte Dateien mit 9 neuen und 4 gelöschten Zeilen
  1. 9 4
      AI/Nullkiller/Engine/Nullkiller.cpp

+ 9 - 4
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<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;