As requested, here is the more refined script and I don't intend to update it here further.
Code:
function addAiSiegeEqiupment(settlement)
for i = 0, settlement.siegesNum-1 do
local siege=settlement:getSiege(i);
local army = siege.besieger;
if army then
if army.faction.isPlayerControlled == 1 then return end;
local numinfantry = numInfantryUnits(army);
print('Found sieging ai army - adding equipment. Num infantry: ', numinfantry);
-- track how many things we've added so additional rams still spawn
numinfantry = addRams(army, numinfantry);
numinfantry = addTowers(settlement, army, numinfantry);
addLadders(settlement, army, numinfantry);
end
end
end
-- rams are unique in that we want buffer troops for the extra rams to spawn.
function addRams(army, numinfantry)
if not numinfantry then return 0 end
--print('Added rams to a comp army')
if numinfantry > 7 then
army.rams = 3;
return numinfantry - 3
end
army.rams = 2;
return numinfantry - 2
end
function addTowers(settlement, army, numinfantry)
if not numinfantry then return 0 end
-- siege towers only make sense for level 3 and higher
if settlement.level > 2
and army.towers < (settlement.level + 3) then
local maxtowers = math.min(numinfantry, math.random(settlement.level + 3))
local oldTowers = army.towers
army.towers = math.max(army.towers, maxtowers) -- never reduce the number of towers
--print('Added towers to a comp army. Old towers '..oldTowers..' New towers '..army.towers)
return numinfantry - army.towers
end
return numinfantry
end
function addLadders(settlement, army, numinfantry)
if not numinfantry then return 0 end
-- ladders only make sense between level 1 and 5, bring a lot
if settlement.level >= 1
and settlement.level < 5
and army.ladders < numinfantry then
local newnumladders = math.min(numinfantry, 6)
--print('Added ladders to a comp army, total = '..newnumladders)
army.ladders = newnumladders
end
end
Works great. I've lost a normal siege or two even with adequate garrisons. If nothing else they're much more interesting in the average case.
Some might thing this is a tad too much, if so they can modify numInfantry directly or subtract more in the AddRams stage so that less ladders/towers are produced.