Army Morale ?
Posted: Sat Nov 10, 2018 7:34 am
My opponent is nearing 1000 over-all Russian casualties (infantry, artillery, aircraft, naval). What can I expect to happen should that -1000 is met or exceeded? Can it be that if his army is in the black MP, to go to yellow MP (including those units on the map)? I'm not sure how to understand this lua file..
function FactionMoraleCalculation(faction)
local maxProduction = 0
for f in game.factions do
for construction in f.constructions do
if construction.type ~= Construction.TYPE_PORT and construction.hex.originalFaction.id == faction.id then
maxProduction = maxProduction + construction.pp
end
end
end
-- +1000 to make it less fluctuating in early turns
local kills = 0
for _, k in pairs(faction.luaData.statsKills) do
kills = kills + k
end
local casualties = 0
for _, c in pairs(faction.luaData.statsCasualties) do
casualties = casualties + c
end
local armyPerformance = (kills + 1000) / (casualties + 1000)
local armyPotentialStrength = math.max(GetUpkeep(faction, true) * armyPerformance, GetIncomePP(faction, true)) * 100 / math.max(1, maxProduction)
-- Never give more than 100 for army strength
armyPotentialStrength = math.min(armyPotentialStrength, 100)
faction.morale = faction.luaData.eventMorale + armyPotentialStrength - gameplay.moraleSurrenderBase
--~ if faction.id == 21 then
--~ print(" ")
--~ print(faction.name .. " maxProduction: " .. faction.luaData.eventMorale .. " armyPotentialStrength: " .. armyPotentialStrength .. " armyPerformance: " .. armyPerformance)
--~ print(faction.name .. " eventMorale: " .. faction.luaData.eventMorale .. " armyPotentialStrength: " .. GetUpkeep(faction, true) * armyPerformance .. " faction.morale: " .. faction.morale .. " GetIncomePP: " .. GetIncomePP(faction))
--~ LogUi(faction.name .. " maxProduction: " .. faction.luaData.eventMorale .. " armyPotentialStrength: " .. armyPotentialStrength .. " armyPerformance: " .. armyPerformance)
print(faction.name .. " Morale: " .. faction.morale)
--~ end
faction.luaData.moraleLevel = GetMoraleLevel(faction.luaData.moraleLevel, faction.morale)
end
function GetMoralePercent(faction)
return math.max(0, math.ceil(faction.morale * 100 / (100 - gameplay.moraleSurrenderBase)))
--return faction.morale + (gameplay.moraleSurrenderBase * faction.morale / (100 - gameplay.moraleSurrenderBase))
end
function CheckForSurrender()
local enemyAlliance = game:GetAllianceById(3 - game.currentAlliance.id)
for faction in enemyAlliance.factions do
if faction.morale <= 0 then
--check if faction still has city
local hasCities = false
for construction in faction.constructions do
hasCities = true
break
end
function FactionMoraleCalculation(faction)
local maxProduction = 0
for f in game.factions do
for construction in f.constructions do
if construction.type ~= Construction.TYPE_PORT and construction.hex.originalFaction.id == faction.id then
maxProduction = maxProduction + construction.pp
end
end
end
-- +1000 to make it less fluctuating in early turns
local kills = 0
for _, k in pairs(faction.luaData.statsKills) do
kills = kills + k
end
local casualties = 0
for _, c in pairs(faction.luaData.statsCasualties) do
casualties = casualties + c
end
local armyPerformance = (kills + 1000) / (casualties + 1000)
local armyPotentialStrength = math.max(GetUpkeep(faction, true) * armyPerformance, GetIncomePP(faction, true)) * 100 / math.max(1, maxProduction)
-- Never give more than 100 for army strength
armyPotentialStrength = math.min(armyPotentialStrength, 100)
faction.morale = faction.luaData.eventMorale + armyPotentialStrength - gameplay.moraleSurrenderBase
--~ if faction.id == 21 then
--~ print(" ")
--~ print(faction.name .. " maxProduction: " .. faction.luaData.eventMorale .. " armyPotentialStrength: " .. armyPotentialStrength .. " armyPerformance: " .. armyPerformance)
--~ print(faction.name .. " eventMorale: " .. faction.luaData.eventMorale .. " armyPotentialStrength: " .. GetUpkeep(faction, true) * armyPerformance .. " faction.morale: " .. faction.morale .. " GetIncomePP: " .. GetIncomePP(faction))
--~ LogUi(faction.name .. " maxProduction: " .. faction.luaData.eventMorale .. " armyPotentialStrength: " .. armyPotentialStrength .. " armyPerformance: " .. armyPerformance)
print(faction.name .. " Morale: " .. faction.morale)
--~ end
faction.luaData.moraleLevel = GetMoraleLevel(faction.luaData.moraleLevel, faction.morale)
end
function GetMoralePercent(faction)
return math.max(0, math.ceil(faction.morale * 100 / (100 - gameplay.moraleSurrenderBase)))
--return faction.morale + (gameplay.moraleSurrenderBase * faction.morale / (100 - gameplay.moraleSurrenderBase))
end
function CheckForSurrender()
local enemyAlliance = game:GetAllianceById(3 - game.currentAlliance.id)
for faction in enemyAlliance.factions do
if faction.morale <= 0 then
--check if faction still has city
local hasCities = false
for construction in faction.constructions do
hasCities = true
break
end