How to force the AI to repair its ships?

Post bug reports and ask for game support here.

Moderator: MOD_Commander_The_Great_War

Post Reply
User avatar
kirk23
Posts: 3033
Joined: Fri Oct 15, 2010 1:19 pm
Location: Fife Scotland
Contact:

How to force the AI to repair its ships?

Post by kirk23 »

Ok, I'm posting a help request here, in the hope I will be able to solve a problem, that is top priority for me in my games. I need the AI to repair its ship's in the same way it routinely repairs its land forces.

I think that maybe altering the AI Economics Lua data file might fix the issue, but so far all my attempts have failed.

function AIPlayer:repairUnits(front)
if self.sai.stackLogging then self:printLog("function AIPlayer:entered: self:repairUnits()") end
local units = {}
local VU = {}
for _,unit in ipairs(front.friendlyUnits) do
if unit.alive and unit.undeployed ~= true and unit.hex ~= nil and (self:aiCanRepair(unit) or self:aiCanUpgrade(unit)) then
VU[unit.id] = self:getVulnerability(unit,unit.hex) + (100-unit.hp)/100
if unit.hex.construction ~= nil and (self.sai.vulnerableCitiesThisTurn[unit.hex.id] == true or self:isAdjacentToAlliance(self.sai.enemyAlliance,unit.hex)) then
if VU[unit.id] == 0 and unit.hp < 100 then
VU[unit.id] = math.max((100-unit.hp)*1.2-10,0) --math.min((100-unit.hp)*1.2,100)
else
VU[unit.id] = VU[unit.id]*1.2
end
if unit.hp < 30 then
VU[unit.id] = VU[unit.id] + 20
end
if unit.faction.id == 0 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
if unit.faction.id == 1 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
if unit.faction.id == 2 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
if unit.faction.id == 3 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
if unit.faction.id == 4 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
if unit.faction.id == 8 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
if unit.faction.id == 10 and unit.type == Unit.NAVAL then
VU[unit.id] = VU[unit.id] + 10
end
self:printLog("Prioritising unit for repair: "..unit.id.." at "..unit.hex.x..","..unit.hex.y.." because it is in a vulnerable city: "..unit.hex.construction.name)
end
table.insert(units,unit)
end
end
table.sort(units,function(a,b) return VU[a.id] > VU[b.id] end)
for _,unit in ipairs(units) do
if self:aiCanRepair(unit) then
if self.sai.enemyAlliance:IsVisible(unit.hex) then
View:AddEffect(unit.hex, "marker_repair")
end
RepairUnit(unit)
self:printLog("AI repairing: "..unit.hex.x..","..unit.hex.y)
end
end
for _,unit in ipairs(units) do
if self:aiCanUpgrade(unit) then
if UpgradeUnit(unit) then
printLog("AI upgrading unit: "..unit.hex.x..","..unit.hex.y.." "..unit.faction.name)
if self.sai.enemyAlliance:IsVisible(unit.hex) then
View:AddEffect(unit.hex, "marker_upgrade")
end
end
end
end
if self.sai.stackLogging then self:printLog("function AIPlayer:completed: self:repairUnits()") end
end
Make it so!
Post Reply

Return to “Tech Support”