// Copyright (c) Strange Loop Games. All rights reserved.
// See LICENSE file in the project root for full license information.

namespace Eco.Mods.TechTree
{
    using Eco.Core.Plugins.Interfaces;
    using Eco.Gameplay.Settlements;
    using Eco.Shared.Localization;
    using Eco.Shared.Utils;
    using System.Collections.Generic;
    using Eco.Shared.IoC;
    using Range = Eco.Shared.Math.Range;
    using Eco.Shared;
    using System;
    using Eco.Shared.Items;
    using Eco.Gameplay.Property;

    //Definitions for properties of the settlements system
    public class SettlementDefinitions : IModInit
    {
        //Here we define how culture translates to the influence, defined on each deed, influencing out from the center.
        static float[] influenceMultipliersPerType = new float[] { 1, 5, 8 };
        static float[] maxInfluenceRadiusPerType   = new float[] { 30, 50, 150 };
        static float CultureToInfluence(Settlement settlement, Deed deed, float cultureOfDeed)
        {
            var influence = cultureOfDeed > 0 ? 2.5f * MathF.Sqrt(cultureOfDeed * 10) : 0; //Gives a curve where 10 culture => 25 radius, and 40 culture => 50 radius
            var mult      = influenceMultipliersPerType[(int)settlement.SettlementType];
            var cap       = maxInfluenceRadiusPerType[(int)settlement.SettlementType];
            return Mathf.Min(influence * mult, cap); //Multiply it and cap it.
        }

        public static void Initialize()
        {
            var config = new SettlementConfig
            {
                SettlementTypes                                           = new List<string>  { Localizer.DoStr("Town"), Localizer.DoStr("Country"), Localizer.DoStr("Federation") },

                //Influence and property definitions
                LandClaimsPerCitizenPastFirst                             = new float[]       { 10                     , 10                        , 10                            },
                ClaimStakesPerCitizenPastFirst                            = new float[]       { .5f                    , .5f                       , .5f                           },
                ClosestAllowedNeighborDistance                            = new float[]       { 10                     , 20                        , 50                            },
                HoursToResolvePropertyCrisis                              = new float[]       { 24                     , 24                        , 24                            },
                MinSubSettlementsToFoundSettlement                        = new int[]         { 0                      , 2                         , 2                             },
                MinSubSettlementsToMaintainSettlement                     = new int[]         { 0                      , 2                         , 2                             },
                BasePlotsOnClaimStake                                     = new int[]         { 5                      , 5                         , 5                             },
                BasePlotsOnHomesteadClaimStake                            = 8,
                             
                //Culture -> influence definitions
                CultureToInfluenceRadius                                  = CultureToInfluence,
                MaxNumberOfCulturalProperties                             = new int[]         { 3                      , 10                        , 25                            },

                //Cultural competition definitions
                CultureAdvantagePercentRequiredToAnnexChildSettlement     = new float[] { .25f, .30f, .35f, .40f},
                CultureAdvantageAbsoluteRequiredToAnnexChildSettlement    = new float[] { 10f, 30f, 50f, 100f},
                CultureAdvantagePercentRequiredToAnnexSiblingSettlement   = new float[] { 1.5f, 2f, 2.5f, 3f},
                CultureAdvantageAbsoluteRequiredToAnnexSiblingSettlement  = new float[] { 20, 50, 100, 200},
                WeightCultureByPercentOfNeighboringPlotsChildSettlement   = new Range[] { new Range(.05f, .20f), new Range(.10f, .40f), new Range(.20f, .60f), new Range(.30f, 1) },
                WeightCultureByPercentOfNeighboringPlotsSiblingSettlement = new Range[] { new Range(.05f, .20f), new Range(.10f, .40f), new Range(.20f, .60f), new Range(.30f, 1) },

                //Objects and items
                ClaimStakeItems                                           = new List<Type> { typeof(TownClaimStakeItem), typeof(CountryClaimStakeItem), typeof(FederationClaimStakeItem) },
                ClaimStakeObjects                                         = new List<Type> { typeof(TownClaimStakeItem), typeof(CountryClaimStakeItem), typeof(FederationClaimStakeItem) },

            };

            SharedSettlement.SetSettlementConfig(config);

            SettlementConfig.LeaderNames = new[] { 
                //Town
                new[] { Localizer.DoStr("Mayor") },
                //Country
                new[] { Localizer.DoStr("President"),   
                        Localizer.DoStr("Chief Executive"), 
                        Localizer.DoStr("Czar"), 
                        Localizer.DoStr("Sultan"), 
                        Localizer.DoStr("Prime Minister"), 
                        Localizer.DoStr("Head of State"), 
                        Localizer.DoStr("Premier"), 
                        Localizer.DoStr("Chancellor") },
                //Federation
                new[] { Localizer.DoStr("Secretary-General") } };

            SettlementConfig.DefaultSuffixes = new[] { 
                //Town
                new[] { Localizer.DoStr("ville"),
                        Localizer.DoStr(" Town"),
                        Localizer.DoStr("sdale"),
                        Localizer.DoStr("burg"),
                        Localizer.DoStr("shire"),
                        Localizer.DoStr("berg"),
                        Localizer.DoStr("borough"),
                        Localizer.DoStr("field"),
                        Localizer.DoStr("tropolis"),
                        Localizer.DoStr(" Square"),
                        Localizer.DoStr("rock"),
                        Localizer.DoStr("spire"),
                        Localizer.DoStr("bury"),
                        Localizer.DoStr("borough"),
                        Localizer.DoStr(" Garden"),
                        Localizer.DoStr("glen"),
                        Localizer.DoStr("stead"),
                        Localizer.DoStr("'s Landing"),},
                //Country
                new[] { Localizer.DoStr("land"),},
                //Federation
                new[] { Localizer.DoStr("United Nations"),
                        Localizer.DoStr("League of Nations"),
                        Localizer.DoStr("Federation of Earth"),}};

        }
    }
}
