Hello, I'm trying 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
How to force the AI to repair its ships?
Moderators: Slitherine Core, The Lordz
Re: How to force the AI to repair its ships?
what I can't do is tell the AI to repair its ships, and for me this is off vital importance, in fact I would go as far a say its a game breaker!
What I can see from looking at the Lua script, is that the AI repairs, any unit that it considers in the frontline. The problem is Naval units don't come under this heading, according to the script, they are regional units. I think I need to create a new FUNCTION that instructs the AI to repair its ships.
Below is the Economic data script that the game uses to allocate a repair value to units. The key part of the whole script is the first part the FUNCTION in brackets it only applies to units, that it considers in the front. function AIPlayer:repairUnits(front) and naval units don't come under this heading so they don't get repaired, which is a serious flaw.
Anyone from Slitherine,Matrix or Lords games studio,please answer me, how do you write a script that tell the AI to repair its ships, I need an answer, someone must know how to do it.
What I can see from looking at the Lua script, is that the AI repairs, any unit that it considers in the frontline. The problem is Naval units don't come under this heading, according to the script, they are regional units. I think I need to create a new FUNCTION that instructs the AI to repair its ships.
Below is the Economic data script that the game uses to allocate a repair value to units. The key part of the whole script is the first part the FUNCTION in brackets it only applies to units, that it considers in the front. function AIPlayer:repairUnits(front) and naval units don't come under this heading so they don't get repaired, which is a serious flaw.
Anyone from Slitherine,Matrix or Lords games studio,please answer me, how do you write a script that tell the AI to repair its ships, I need an answer, someone must know how to do it.
Code: Select all
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
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
function AIPlayer:findAllVulnerableCities(alliance)
local units = {}
for faction in self.sai.enemyAlliance.factions do
for unit in faction.units do
if unit.alive and unit.hex ~= nil and unit.type == Unit.LAND and unit.state ~= Unit.STATE_EMBARKED then
table.insert(units,unit)
end
end
end
Re: How to force the AI to repair its ships?
I'm sorry but only the developer can help you.
Re: How to force the AI to repair its ships?
front is a function? where is its code?function AIPlayer:repairUnits(front)
or if its units variable where is how its set?
which values it can have? true/false? so maybe u could just use trick to use always true, replace front with value which will place it in repairing queue
Re: How to force the AI to repair its ships?
I've posted a possible workaround in Mods&Scenarios.