AI chooses the closest deposit to build an extractor

This commit is contained in:
devZoGok
2024-02-11 15:44:45 +02:00
parent 2932c2b923
commit 781f1649b0
2 changed files with 8 additions and 6 deletions
+7 -6
View File
@@ -55,14 +55,15 @@ function Player:buildExtractor()
self:selectUnits({engineer})
deposits = self:getResourceDeposits()
depPos = nil
if #deposits == 0 then return false end
if #deposits > 0 then
depPos = deposits[1]:getPos()
end
depPos = deposits[1]:getPos()
spawnPoint = self:getSpawnPoint()
if depPos == nil then
return false
for i = 1, #deposits do
if deposits[i]:getPos():getDistanceFrom(spawnPoint) < depPos:getDistanceFrom(spawnPoint) then
depPos = deposits[i]:getPos()
end
end
extractor = GameObjectFactory.createUnit(self, UnitId.EXTRACTOR, depPos, Quaternion:new(1, 0, 0, 0), 0)
+1
View File
@@ -111,6 +111,7 @@ namespace battleship{
"y", &Vector3::y,
"z", &Vector3::z,
"norm", &Vector3::norm,
"getDistanceFrom", &Vector3::getDistanceFrom,
"add", [](Vector3 v1, Vector3 v2){return v1 + v2;},
"subtr", [](Vector3 v1, Vector3 v2){return v1 - v2;},
"mult", [](Vector3 v1, float s){return v1 * s;},