Ejemplo n.º 1
0
        public override double computeUtility(Person voter, VoteOption option, List <ReasonMsg> msgs)
        {
            double     u = option.getBaseUtility(voter);
            ThreatItem greatestThreat = voter.getGreatestThreat();


            double ourStr = 1 + (voter.society.currentMilitary + (voter.society.maxMilitary / 2));
            double offStr = 1;
            double defStr = 1;

            if (voter.society.offensiveTarget != null)
            {
                offStr = voter.society.offensiveTarget.currentMilitary + (voter.society.offensiveTarget.maxMilitary / 2);
            }
            if (voter.society.defensiveTarget != null)
            {
                defStr = voter.society.defensiveTarget.currentMilitary + (voter.society.defensiveTarget.maxMilitary / 2);
            }

            double defUtility        = 0;
            double defGreatestThreat = 0;

            if (voter.society.defensiveTarget != null)
            {
                //Negative if we are stronger than the one we fear
                defUtility += (defStr - ourStr) / (ourStr + defStr) * voter.map.param.utility_militaryTargetRelStrengthDefensive;

                if (defUtility < -50)
                {
                    defUtility = -50;
                }

                if (greatestThreat != null)
                {
                    if (greatestThreat.group != null && greatestThreat.group.currentMilitary > voter.society.currentMilitary)
                    {
                        defGreatestThreat = World.staticMap.param.utility_greatestThreatDelta;
                        defUtility       += defGreatestThreat;
                        if (option.index == 0)
                        {
                            msgs.Add(new ReasonMsg("Our greatest threat (" + greatestThreat.group.getName() + ") is stronger than us, we must defend", defGreatestThreat));
                        }
                    }
                }
            }
            double offUtility            = 0;
            double offUtilityStr         = 0;
            double offUtilityPersonality = 0;
            double offUtilityTerritory   = 0;
            double offUtilityInstab      = 0;
            double offGreatestThreat     = 0;

            if (voter.society.offensiveTarget != null)
            {
                //Negative if the offensive target is stronger
                offUtilityStr += (ourStr - offStr) / (ourStr + offStr) * voter.map.param.utility_militaryTargetRelStrengthOffensive;
                if (voter.society.offensiveTarget is Society)
                {
                    offUtilityStr = Math.Min(offUtilityStr, voter.map.param.utility_militaryTargetRelStrengthOffensive);//Capped to prevent insanity snowballing
                }
                offUtilityPersonality += voter.getMilitarism() * voter.map.param.utility_militarism;

                //We want to expand into territory we already partially own
                bool hasOurTerritory = false;
                foreach (Location loc in voter.society.offensiveTarget.lastTurnLocs)
                {
                    if (loc.province == voter.getLocation().province)
                    {
                        hasOurTerritory = true;
                        break;
                    }
                }
                if (hasOurTerritory)
                {
                    offUtilityTerritory += society.map.param.utility_militaryTargetCompleteProvince * society.data_societalStability;
                }

                if (offUtilityStr > 0 && society.offensiveTarget is Society)
                {
                    //Counters expansion desire. Value always negative or zero
                    //u = off*stability
                    //u = off + (off*(stability-1))  (Because we are removing 1 from stability mult)
                    //If stab == 0 it's off - off
                    //If stab < 0 it's less than off
                    offUtilityInstab = offUtilityInstab * (society.data_societalStability - 1);
                }

                if (greatestThreat != null)
                {
                    if (greatestThreat.group != null && greatestThreat.group.currentMilitary < voter.society.currentMilitary)
                    {
                        offGreatestThreat += World.staticMap.param.utility_greatestThreatDelta;
                        if (option.index == 1)
                        {
                            msgs.Add(new ReasonMsg("Our greatest threat (" + greatestThreat.group.getName() + ") is weaker than us, we must attack", offGreatestThreat));
                        }
                    }
                }
                offUtility += offGreatestThreat;
                offUtility += offUtilityStr;
                offUtility += offUtilityPersonality;
                offUtility += offUtilityTerritory;
                offUtility += offUtilityInstab;
            }
            double introUtility          = 0;
            double introUtilityStability = 0;

            if (society.data_societalStability < 0.66)
            {
                introUtilityStability = -(society.data_societalStability - 1);  //0 if stability is 1, increasing to 1 if civil war is imminent, to 2 if every single person is a traitor
            }
            double introGreatestThreat = 0;

            if (greatestThreat != null)
            {
                if (greatestThreat.form == ThreatItem.formTypes.AGENTS || greatestThreat.form == ThreatItem.formTypes.ENSHADOWED_NOBLES)
                {
                    introGreatestThreat = World.staticMap.param.utility_greatestThreatDelta;
                    introUtility       += introGreatestThreat;
                    if (option.index == 2)
                    {
                        msgs.Add(new ReasonMsg("Our greatest threat (" + greatestThreat.getTitle() + ") requires internal security", introGreatestThreat));
                    }
                }
            }
            introUtilityStability *= voter.map.param.utility_introversionFromInstability;
            double introFromInnerThreat = voter.threat_enshadowedNobles.threat * voter.map.param.utility_introversionFromSuspicion;

            introUtility += introUtilityStability;
            introUtility += introFromInnerThreat;
            introUtility += 10;

            //Option 0 is DEFENSIVE
            //Option 1 is OFFENSIVE
            //Option 2 is INTROSPECTIVE
            if (voter.society.posture == Society.militaryPosture.defensive && option.index != 0)
            {
                u -= defUtility;
                msgs.Add(new ReasonMsg("Switching away from defensive", -defUtility));
            }
            if (voter.society.posture == Society.militaryPosture.offensive && option.index != 1)
            {
                u -= offUtility;
                msgs.Add(new ReasonMsg("Switching away from offensive", -offUtility));
            }
            if (voter.society.posture == Society.militaryPosture.introverted && option.index != 2)
            {
                u -= introUtility;
                msgs.Add(new ReasonMsg("Switching away from introversion", -introUtility));
            }

            if (option.index == 0)
            {
                if (society.posture != Society.militaryPosture.defensive)
                {
                    u += defUtility;
                    msgs.Add(new ReasonMsg("Our relative strength against defensive target", defUtility));
                    if (voter.society.isDarkEmpire)
                    {
                        int value = (int)(-100 * voter.shadow);
                        u += value;
                        msgs.Add(new ReasonMsg("We must expand the Dark Empire", value));
                    }
                }
                else
                {
                    u += defUtility;
                    msgs.Add(new ReasonMsg("Our relative strength against defensive target", defUtility));
                    if (voter.society.isDarkEmpire)
                    {
                        int value = (int)(-100 * voter.shadow);
                        u += value;
                        msgs.Add(new ReasonMsg("We must expand the Dark Empire", value));
                    }
                    msgs.Add(new ReasonMsg("No need to change: It is our current stance", -u));
                    u = 0;
                }
            }
            if (option.index == 1)
            {
                if (society.posture != Society.militaryPosture.offensive)
                {
                    u += offUtility;
                    msgs.Add(new ReasonMsg("Our relative strength against offensive target", offUtilityStr));
                    msgs.Add(new ReasonMsg("Risk of instability from expansion", offUtilityInstab));
                    msgs.Add(new ReasonMsg("Militarism personality", offUtilityPersonality));
                    msgs.Add(new ReasonMsg("Desire for territory", offUtilityTerritory));
                    if (voter.society.isDarkEmpire)
                    {
                        int value = (int)(100 * voter.shadow);
                        u += value;
                        msgs.Add(new ReasonMsg("We must expand the Dark Empire", value));
                    }
                }
                else
                {
                    u += offUtility;
                    msgs.Add(new ReasonMsg("Our relative strength against offensive target", offUtilityStr));
                    msgs.Add(new ReasonMsg("Risk of instability from expansion", offUtilityInstab));
                    msgs.Add(new ReasonMsg("Militarism personality", offUtilityPersonality));
                    msgs.Add(new ReasonMsg("Desire for territory", offUtilityTerritory));
                    if (voter.society.isDarkEmpire)
                    {
                        int value = (int)(100 * voter.shadow);
                        u += value;
                        msgs.Add(new ReasonMsg("We must expand the Dark Empire", value));
                    }
                    msgs.Add(new ReasonMsg("No need to change: It is our current stance", -u));
                    u = 0;
                }
            }
            if (option.index == 2)
            {
                msgs.Add(new ReasonMsg("Default position", 10));
                if (society.posture != Society.militaryPosture.introverted)
                {
                    u += introUtility;
                    msgs.Add(new ReasonMsg("Instability internally", introUtilityStability));
                    msgs.Add(new ReasonMsg("Suspicion of nobles' darkness", introFromInnerThreat));
                    if (voter.society.isDarkEmpire)
                    {
                        int value = (int)(-100 * voter.shadow);
                        u += value;
                        msgs.Add(new ReasonMsg("We must expand the Dark Empire", value));
                    }
                }
                else
                {
                    u += introUtility;
                    msgs.Add(new ReasonMsg("Instability internally", introUtilityStability));
                    msgs.Add(new ReasonMsg("Suspicion of nobles' darkness", introFromInnerThreat));
                    if (voter.society.isDarkEmpire)
                    {
                        int value = (int)(-100 * voter.shadow);
                        u += value;
                        msgs.Add(new ReasonMsg("We must expand the Dark Empire", value));
                    }
                    msgs.Add(new ReasonMsg("No need to change: It is our current stance", -u));
                    u = 0;
                }
            }


            return(u);
        }
        public override double computeUtility(Person voter, VoteOption option, List <ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(voter);

            //double parityMult = 1;
            //if (option.index == 0) { parityMult = -1; }
            //return 100 * parityMult;

            //Option 0 is "Don't declare war"

            //1 if we're 100% of the balance, -1 if they are

            double ourStrength   = society.currentMilitary + (society.maxMilitary * 0.5);
            double theirStrength = target.currentMilitary + (target.maxMilitary * 0.5);

            if (ourStrength + theirStrength == 0)
            {
                ourStrength += 0.001;
            }
            double relativeStrength = (ourStrength - theirStrength) / (ourStrength + theirStrength + 1);
            double localU           = 0;

            double relMilU = society.map.param.utility_militaryTargetRelStrengthOffensive * relativeStrength;

            bool shouldExpand = true;
            int  nDukes       = 0;

            foreach (Title t in society.titles)
            {
                if (t is Title_ProvinceRuler)
                {
                    nDukes += 1;
                }
            }
            if (nDukes >= society.map.param.society_maxDukes)
            {
                shouldExpand = false;
            }

            bool hasOurTerritory = false;

            foreach (Location loc in target.lastTurnLocs)
            {
                foreach (Location l2 in society.lastTurnLocs)
                {
                    if (loc.province == l2.province)
                    {
                        hasOurTerritory = true;
                    }
                }
            }

            //Peace
            if (option.index == 0)
            {
                if (ourStrength < 1)
                {
                    localU = 1000;
                    msgs.Add(new ReasonMsg("We are too weak", localU));
                    u += localU;
                    return(u);
                }

                if (ourStrength * 2 < theirStrength)
                {
                    localU = 1000;
                    msgs.Add(new ReasonMsg("We stand no chance", localU));
                    u += localU;
                    return(u);
                }

                if (relMilU < 0)
                {
                    msgs.Add(new ReasonMsg("Relative strength of current militaries", -relMilU));
                    u += relMilU;
                }

                bool tinyComplete = target.lastTurnLocs.Count <= 3 && hasOurTerritory;//You can take over tiny nations to complete your provinces
                if (!tinyComplete && society.isDarkEmpire == false && shouldExpand == false && target is Society)
                {
                    localU = society.map.param.utility_militaryOverexpansionHalt;
                    msgs.Add(new ReasonMsg("We have as much as we can control", localU));
                    u += localU;
                }

                localU = voter.getMilitarism() * -100;
                msgs.Add(new ReasonMsg("Militarism of " + voter.getFullName(), localU));
                u += localU;
            }
            else //Pro-war
            {
                //We want to expand into territory we already partially own
                bool hasMyTerritory = false;
                foreach (Location loc in target.lastTurnLocs)
                {
                    if (loc.province == voter.getLocation().province)
                    {
                        hasMyTerritory = true;
                        break;
                    }
                }
                if (hasMyTerritory)
                {
                    localU = society.map.param.utility_militaryTargetCompleteProvince;
                    msgs.Add(new ReasonMsg("Has territory from my province", localU));
                    u += localU;
                }

                //We want to own more land. Invade weak neighbours
                if (shouldExpand && target is Society && target.currentMilitary * 1.5 < this.society.currentMilitary && target.getNeighbours().Contains(this.society))
                {
                    //Society soc = (Society)target;
                    //if (this.society.getCapital() != null && soc.getCapital() != null)
                    //{
                    //    if (soc.getCapital().hex.getHabilitability() > 0.5)
                    //    {
                    localU = society.map.param.utility_militaryTargetExpansion * Math.Max(0, voter.getMilitarism());
                    msgs.Add(new ReasonMsg("Expand our holdings", localU));
                    u += localU;
                    //    }
                    //}
                }

                localU = voter.getMilitarism() * 100;
                msgs.Add(new ReasonMsg("Militarism of " + voter.getFullName(), localU));
                u += localU;

                foreach (ThreatItem threat in voter.threatEvaluations)
                {
                    if (threat.group == target)
                    {
                        localU = threat.threat * society.map.param.utility_fromThreat;
                        msgs.Add(new ReasonMsg("Perceived Threat", localU));
                        u += localU;
                        break;
                    }
                }
            }



            /*
             * if (relMilU > 0 && target is Society)
             * {
             *  //0 if stability is full, getting more negative as stability decreases
             *  double stabilityU = (this.society.data_societalStability-1);
             *  stabilityU = relMilU * stabilityU;//More negative the worse stability is, reaches the complement of relMilU when civil war is imminent
             *  msgs.Add(new ReasonMsg("Our societal stability concerns", stabilityU));
             *  u += stabilityU;
             * }
             */



            /*
             * if (this.society.defensiveTarget != null && this.society.defensiveTarget != this.society.offensiveTarget)
             * {
             *
             *  theirStrength = society.defensiveTarget.currentMilitary;
             *  //0 if we're 100% of the balance, -1 if they are
             *  relativeStrength = (((ourStrength - theirStrength) / (ourStrength + theirStrength))-1)/2;
             *
             *  localU = society.map.param.utility_militaryTargetRelStrength * relativeStrength * parityMult;
             *  msgs.Add(new ReasonMsg("Defensive Target's Capabilities (risk of sneak attack)", localU));
             *  u += localU;
             * }
             */

            return(u);
        }