function FinalizeCityState(numMinorCivs)
-- tab for playerID
local ynaemSelection = {}
for playerID = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 1 do
local player = Players[playerID]
local minorCivID = player:GetMinorCivType()
-- Does this civ exist ?
if minorCivID ~= -1 then
-- keep only TSL ?
if (not MinorCivHasTSL(minorCivID) and PreGame.GetMapOption(MINOR_PLACEMENT) == MINOR_TSL_ONLY) then
YnaemRemoveCiv (playerID)
-- was marked for removing ?
elseif string.find(modUserData.GetValue("ToRemove"), "minor"..minorCivID.."tr") then
YnaemRemoveCiv (playerID)
print ("kill marked civ : " .. minorCivID)
else
table.insert(ynaemSelection, playerID)
end
end
end
print ("Actual Number of City States = " .. #ynaemSelection )
if #ynaemSelection > numMinorCivs then
print ("Ok, exterminating a few settlers discretly..." )
-- remove excedent
-- but first shuffle selection
-- so we can't be accused of deliberate ethnic cleaning
for i = #ynaemSelection, 2, -1 do
local r = math.random(i)
ynaemSelection[i], ynaemSelection[r] = ynaemSelection[r], ynaemSelection[i]
end
-- keep only the requested number
for i = numMinorCivs + 1 , #ynaemSelection do
YnaemRemoveCiv (ynaemSelection[i])
end
end
end