local function ReturnZero(aiPlayer, pbg, productionGroupID)
    return 0.0
end

local function VillagerScore2000(aiPlayer, pbg, productionGroupID)
    return 4000.0
end

local function MilitaryScore2000(aiPlayer, pbg, productionGroupID)
    return 2000.0
end

local function LandmarkMilitaryScore2500(aiPlayer, pbg, productionGroupID)
    return 2500.0
end

function GetDesiredTCCount(aiPlayer)
    return 0
end

function TwoTCDesire(aiPlayer, pbg)
    return 0.0
end

function ThreeTCDesire(aiPlayer, pbg)
    return 0.0
end

function ScoringFunctions_Gatherer(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, VillagerScore2000),
        AIProductionScoring_HasProductionQueue(aiPlayer),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_MultipleProduced(aiPlayer, 5.0),
        AIProductionScoring_PopulationPercentage(aiPlayer, 3.0, 2.0, true, true),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {["villager"] = 0.10, ["worker"] = 0.10}, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["economy"] = 2.0 }),
    }
    return result
end

function ScoringFunctions_Infantry(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, MilitaryScore2000),
        AIProductionScoring_CounterScore(aiPlayer, 1.0),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {
            ["cavalry"] = 0.15,
            ["knight"] = 0.15,
            ["horseman"] = 0.15,
            ["lancer"] = 0.15,
        }, true),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {["infantry"] = 0.10, ["military"] = 0.05}, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["combat"] = 2.0, ["offense"] = 2.0 }),
        AIProductionScoring_MultipleProduced(aiPlayer, 0.5),
        AIProductionScoring_TimeToAcquire(aiPlayer, 120.0, true, false, true),
    }
    return result
end

function ScoringFunctions_RangedInfantry(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, MilitaryScore2000),
        AIProductionScoring_CounterScore(aiPlayer, 1.0),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {
            ["infantry"] = 0.15,
            ["spearman"] = 0.15,
            ["manatarms"] = 0.15,
            ["pikeman"] = 0.15,
        }, true),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {["archer"] = 0.10, ["ranged"] = 0.10, ["military"] = 0.05}, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["combat"] = 2.0, ["offense"] = 2.0 }),
        AIProductionScoring_MultipleProduced(aiPlayer, 0.5),
        AIProductionScoring_TimeToAcquire(aiPlayer, 120.0, true, false, true),
    }
    return result
end

function ScoringFunctions_Cavalry(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, MilitaryScore2000),
        AIProductionScoring_CounterScore(aiPlayer, 1.0),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {
            ["archer"] = 0.15,
            ["crossbowman"] = 0.15,
            ["handcannon"] = 0.15,
            ["ranged"] = 0.15,
        }, true),
        AIProductionScoring_PresenceOfEnemyTypes(aiPlayer, {["cavalry"] = 0.10, ["military"] = 0.05}, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["combat"] = 2.0, ["offense"] = 2.0 }),
        AIProductionScoring_MultipleProduced(aiPlayer, 0.5),
        AIProductionScoring_TimeToAcquire(aiPlayer, 120.0, true, false, true),
    }
    return result
end

function ScoringFunctions_LandmarkOffensive(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, LandmarkMilitaryScore2500),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["age_up"] = 2.0, ["offense"] = 2.0, ["combat"] = 2.0 }),
    }
    return result
end

function ScoringFunctions_LandmarkStandard(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, LandmarkMilitaryScore2500),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["age_up"] = 2.0, ["offense"] = 2.0, ["combat"] = 2.0 }),
    }
    return result
end

function ScoringFunctions_LandmarkDarkAgeA(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, LandmarkMilitaryScore2500),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["age_up"] = 2.0, ["offense"] = 2.0 }),
        AIProductionScoring_RandomIntScore(aiPlayer),
    }
    return result
end

function ScoringFunctions_LandmarkDarkAgeB(aiPlayer)
    local result = {
        AIProductionScoring_LuaScoringFunction(aiPlayer, LandmarkMilitaryScore2500),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["age_up"] = 2.0, ["offense"] = 2.0 }),
        AIProductionScoring_InverseRandomIntScore(aiPlayer),
    }
    return result
end

function ScoringFunctions_LandmarkDefensive(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_LandmarkEcon(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_LandmarkEconTrader(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_LandmarkSiege(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_LandmarkGreatWall(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_MilitaryProductionBuilding(aiPlayer)
    local result = {
        AIProductionScoring_PlannedPlacementScore(aiPlayer, -1.0),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["combat"] = 2.0, ["offense"] = 2.0 }),
        AIProductionScoring_ProductionQueueContention(aiPlayer, 4, 12),
        AIProductionScoring_NotProducedRecently(aiPlayer, 8.0),
        AIProductionScoring_UnderCountLimit(aiPlayer, 8, -1, false),
    }
    return result
end

function ScoringFunctions_House(aiPlayer)
    return { AIProductionScoring_PopCapGenerator(aiPlayer) }
end

function ScoringFunctions_DropOffs(aiPlayer)
    local normalScoring = AIProductionScoring_MultiplyListScoringFunction(aiPlayer, {
        AIProductionScoring_ScarcityAndDeficiencyScore(aiPlayer),
        AIProductionScoring_NotProducedRecently(aiPlayer, 50.0),
        AIProductionScoring_PlannedPlacementScoreValid(aiPlayer),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["economy"] = 2.0 }),
    })
    
    local failsafe = AIProductionScoring_MultiplyListScoringFunction(aiPlayer, {
        AIProductionScoring_NotProducedRecently(aiPlayer, 180.0),
        AIProductionScoring_AmountOfResourceNeeded(aiPlayer, 25.0),
        AIProductionScoring_LowResourceIncome(aiPlayer, 4.0),
        AIProductionScoring_IsProductionBlockedByThisResource(aiPlayer),
    })
    
    return { AIProductionScoring_MaxScoringFunction(aiPlayer, {normalScoring, failsafe}) }
end

function ScoringFunctions_ResourceGenerator(aiPlayer)
    local normalScoring = AIProductionScoring_MultiplyListScoringFunction(aiPlayer, {
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["economy"] = 2.0 }),
        AIProductionScoring_ScarcityAndDeficiencyScore(aiPlayer),
        AIProductionScoring_MinimumGameTime(aiPlayer, 6*60),
    })
    
    return { normalScoring }
end

function ScoringFunction_Mills(aiPlayer)
    local earlyScoring = AIProductionScoring_MultiplyListScoringFunction(aiPlayer, {
        AIProductionScoring_MaximumGameTime(aiPlayer, 6*60),
        AIProductionScoring_PlannedPlacementScore(aiPlayer, 0.48),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["economy"] = 2.0 }),
        AIProductionScoring_NotProducedRecently(aiPlayer, 40.0),
    })
    
    local lateScoring = AIProductionScoring_MultiplyListScoringFunction(aiPlayer, {
        AIProductionScoring_MinimumGameTime(aiPlayer, 6*60),
        AIProductionScoring_NotProducedRecently(aiPlayer, 60.0),
        AIProductionScoring_PlannedPlacementScoreValid(aiPlayer),
    })
    
    return { AIProductionScoring_MaxScoringFunction(aiPlayer, {earlyScoring, lateScoring}) }
end

function ScoringFunctions_Scouting(aiPlayer)
    local result = {
        AIProductionScoring_UnderCountLimit(aiPlayer, 2, -1, true),
        AIProductionScoring_MaxPopCapPercentage(aiPlayer, 0.02, true),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["economy"] = 1.0 }),
    }
    return result
end

function ScoringFunctions_PlayerUnitCombatUpgrade(aiPlayer)
    local result = {
        AIProductionScoring_OnlyProduceOneAtATime(aiPlayer),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["combat"] = 2.0, ["upgrade"] = 1.0 }),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
    }
    return result
end

function ScoringFunctions_PlayerUnitTierUpgrade(aiPlayer)
    local result = {
        AIProductionScoring_OnlyProduceOneAtATime(aiPlayer),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["combat"] = 2.0 }),
        AIProductionScoring_TierUpgrade(aiPlayer, 0.05),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
    }
    return result
end

function ScoringFunctions_PlayerEconGatheringUpgrade(aiPlayer)
    local result = {
        AIProductionScoring_OnlyProduceOneAtATime(aiPlayer),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["upgrade"] = 1.0, ["economy"] = 2.0 }),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
        AIProductionScoring_PlayerGatheringUpgrade(aiPlayer, 10.0, 10.0),
    }
    return result
end

function ScoringFunctions_PlayerEconWheelbarrowUpgrade(aiPlayer)
    local result = {
        AIProductionScoring_OnlyProduceOneAtATime(aiPlayer),
        AIProductionScoring_StrategicIntention(aiPlayer, { ["upgrade"] = 1.0, ["economy"] = 2.0 }),
        AIProductionScoring_TimeToAcquire(aiPlayer, 300.0, true, false, true),
    }
    return result
end

function ScoringFunctions_Siege(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_CombatSiege(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_SiegeTower(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Dock(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_FishingBoat(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_TradeBoat(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_TransportBoat(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_NavalMilitary(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_WarShip(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Fireship(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Keeps(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Outposts(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_WallAndGate(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_WallTower(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Trader(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Monk(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function ScoringFunctions_Wonder(aiPlayer)
    return { AIProductionScoring_LuaScoringFunction(aiPlayer, ReturnZero) }
end

function InitZombieWarmonger()
    local player = Game_GetLocalPlayer()
    if not player then return end
    
    if Game_AIControlLocalPlayer then Game_AIControlLocalPlayer() end
    if AI_Enable then AI_Enable(player, true) end
    if AI_SetDifficulty then AI_SetDifficulty(player, 6) end
    
    if UI_CreateEventCue then
        UI_CreateEventCue("Ai- Activated Enjoy :)", "", "", "", "", ECV_Queue, 4.0)
    end
end

if Rule_AddOneShot then
    Rule_AddOneShot(InitZombieWarmonger, 1.0)
else
    InitZombieWarmonger()
end