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


            if (option.index == NO_RESPONSE)
            {
                msgs.Add(new ReasonMsg("Neutral Option", 0));
            }

            if (option.index == AGENT_TO_KNIGHT)
            {
                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.knight);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
            }
            if (option.index == AGENT_TO_BASIC)
            {
                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.basic);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
            }

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

            //Option 1 is "Kill suspect"
            //Multiply values based on this, as they should be symmetric for most parts
            double parityMult = 1;

            if (option.index == 0)
            {
                parityMult = -1;
            }

            RelObj rel    = voter.getRelation(option.person);
            double apathy = (1 - voter.shadow);

            /*
             * This is actually already covered by liking, but caps out at 100. This adds another bonus, purely from suspicion
             */
            double proKill = rel.suspicion * apathy * voter.map.param.utility_killSuspectFromSuspicion * parityMult;

            msgs.Add(new ReasonMsg("Suspicion towards " + option.person.getFullName(), proKill));
            u += proKill;

            //double reluctance = -voter.map.param.utility_killSuspectRelucatance* parityMult * reluctanceModifier;
            //msgs.Add(new ReasonMsg("Base reluctance to kill noble", reluctance));
            //u += reluctance;

            double liking = -rel.getLiking() * parityMult;

            msgs.Add(new ReasonMsg("Opinion of " + option.person.getFullName(), liking));
            u += liking;

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

            if (option.group == null)
            {
                //Null case is "remain independent"
                localU = -voter.map.param.utility_vassaliseReluctance;
                msgs.Add(new ReasonMsg("Inherent reluctance", localU));
                u += localU;

                return(u);
            }

            localU = voter.map.param.utility_vassaliseReluctance;
            msgs.Add(new ReasonMsg("Inherent reluctance", localU));
            u += localU;

            Society socTarget = (Society)option.group;

            foreach (KillOrder order in socTarget.killOrders)
            {
                if (order.person == voter)
                {
                    localU = -1000;
                    msgs.Add(new ReasonMsg("Kill order against " + voter.getFullName(), localU));
                    u += localU;
                }
            }

            double awarenessU = society.map.param.utility_lightAllianceMult * voter.awareness;

            msgs.Add(new ReasonMsg("Awareness", awarenessU));
            u += awarenessU;


            double militaryU = option.group.currentMilitary - voter.society.currentMilitary;

            militaryU *= society.map.param.utility_lightAllianceMilMult * voter.awareness;
            msgs.Add(new ReasonMsg("Their military might", militaryU));
            u += militaryU;

            double totalSuspicion = 0;

            foreach (Person p in socTarget.people)
            {
                RelObj rel = voter.getRelation(p);
                totalSuspicion += rel.suspicion;
            }

            double susU = -totalSuspicion;

            susU *= society.map.param.utility_lightAlliancSusMult;
            msgs.Add(new ReasonMsg("Suspicion of their nobles", susU));
            u += susU;

            return(u);
        }
Esempio n. 4
0
        public override double computeUtility(Person voter, VoteOption option, List <ReasonMsg> msgs)
        {
            double u   = option.getBaseUtility(voter);
            RelObj rel = voter.getRelation(option.person);

            double liking = -rel.getLiking() * World.staticMap.param.utility_dismissFromCourt;

            msgs.Add(new ReasonMsg("Opinion of " + option.person.getFullName(), liking));
            u += liking;

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

            Person p             = option.person;
            double existingValue = 0;

            if (p.title_land != null)
            {
                existingValue = p.title_land.settlement.getPrestige();
            }

            double newValue = title.settlement.getPrestige();

            double benefitToPerson = newValue - existingValue;

            //We know how much they would be advantaged. We now need to know how much we like them to determine
            //if this is a good thing or not

            double localU = benefitToPerson * voter.getRelation(p).getLiking() * voter.map.param.utility_landedTitleMult;

            msgs.Add(new ReasonMsg("Benefit to " + p.getFullName(), localU));
            u += localU;

            if (title.heldBy == null)
            {
                localU = voter.map.param.utility_landedTitleAssignBaseline;
                msgs.Add(new ReasonMsg("Need to assign the title", localU));
                u += localU;
            }

            //We need to know if someone's going to lose out here
            //(Note this is irrelevant if they're the person who's being voted on)
            if (title.heldBy != null && title.heldBy != p)
            {
                double damageToOther = title.settlement.getPrestige();
                localU = -damageToOther *voter.getRelation(title.heldBy).getLiking() * voter.map.param.utility_landedTitleMult;

                msgs.Add(new ReasonMsg("Harm to " + title.heldBy.getFullName(), localU));
                u += localU;
            }


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


            double localU = 0;

            foreach (ThreatItem threat in voter.threatEvaluations)
            {
                if (threat.group == option.group)
                {
                    localU = threat.threat;
                    msgs.Add(new ReasonMsg("Perceived Threat", localU));
                    u += localU;
                    break;
                }
            }


            //If we already have a military target
            if (society.defensiveTarget != null)
            {
                localU = 0;

                //Add current target threat
                foreach (ThreatItem threat in voter.threatEvaluations)
                {
                    if (threat.group == society.defensiveTarget)
                    {
                        localU -= threat.threat;
                        msgs.Add(new ReasonMsg("Threat of current target (" + society.defensiveTarget.getName() + ")", localU));
                        u += localU;
                        break;
                    }
                }
            }


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

            //Option 1 is "Kill suspect"
            //Multiply values based on this, as they should be symmetric for most parts

            RelObj rel    = voter.getRelation(target.person);
            double apathy = (1 - voter.shadow);

            if (option.index == 0)
            {
                double liking = rel.getLiking();
                msgs.Add(new ReasonMsg("Opinion of " + target.getName(), liking));
                u += liking;
            }
            else if (option.index == 1)
            {
                /*
                 * This is actually already covered by liking, but caps out at 100. This adds another bonus, purely from suspicion
                 */
                double proKill = rel.suspicion * apathy * voter.map.param.utility_exileSuspectFromSuspicion;
                msgs.Add(new ReasonMsg("Suspicion towards " + target.getName(), proKill));
                u += proKill;

                double liking = -rel.getLiking();
                msgs.Add(new ReasonMsg("Opinion of " + target.getName(), liking));
                u += liking;

                double reluctance = -voter.map.param.utility_killSuspectRelucatance;
                msgs.Add(new ReasonMsg("Base reluctance to exile agent", reluctance));
                u += reluctance;
            }



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

            Person p = option.person;


            double benefitU = voter.getRelation(p).getLiking() * voter.map.param.utility_singleUseCure;

            msgs.Add(new ReasonMsg("Benefit to " + p.getFullName(), benefitU));
            u += benefitU;

            bool hasDisease = false;

            foreach (Property pr in voter.getLocation().properties)
            {
                if (pr.proto.isDisease)
                {
                    hasDisease = true;
                    break;
                }
            }
            if (hasDisease && p != voter)
            {
                //We're considering giving this cure to another

                //This option doesn't help me. If I'm corrupt, I'll naturally be angry at not being given help
                double localU = voter.getSelfInterest() * voter.threat_plague.threat * World.staticMap.param.utility_selfInterestFromThreat * 1.5;
                if (localU != 0)
                {
                    msgs.Add(new ReasonMsg("Does not help me personally", localU));
                    u += localU;
                }
            }

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

            double desire  = voter.awareness * voter.map.worldPanic;
            double counter = 0;

            counter = voter.shadow;
            if (voter.state == Person.personState.broken)
            {
                counter = 1;
            }
            if (voter.state == Person.personState.enthralled)
            {
                counter = 1;
            }
            if (voter.state == Person.personState.enthralledAgent)
            {
                counter = 1;
            }

            double localU = 0;

            //Begin
            if (option.index == 0)
            {
                localU = desire * voter.map.param.utility_lightbringerRitual;
                msgs.Add(new ReasonMsg("Awareness and World Panic", localU));
                u += localU;

                localU = -1 * counter * voter.map.param.utility_lightbringerRitual;
                if (counter > 1)
                {
                    msgs.Add(new ReasonMsg("Enshadowment of own soul", localU));
                    u += localU;
                }

                localU = voter.map.param.utility_lightbringerRitualReluctance;
                msgs.Add(new ReasonMsg("Cost of Ritual", localU));
                u += localU;
            }
            else //No ritual
            {
                localU = -1 * desire * voter.map.param.utility_lightbringerRitual;
                msgs.Add(new ReasonMsg("Awareness and World Panic", localU));
                u += localU;

                localU = counter * voter.map.param.utility_lightbringerRitual;
                if (counter > 1)
                {
                    msgs.Add(new ReasonMsg("Enshadowment of own soul", localU));
                    u += localU;
                }

                localU = -1 * voter.map.param.utility_lightbringerRitualReluctance;
                msgs.Add(new ReasonMsg("Cost of Ritual", localU));
                u += localU;
            }

            return(u);
        }
Esempio n. 10
0
        public override double computeUtility(Person p, VoteOption option, List <ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(p);


            if (option.index == NO_RESPONSE)
            {
                msgs.Add(new ReasonMsg("Neutral Option", 0));
            }

            if (option.index == AGENT_TO_MEDIC)
            {
                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.medic);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
            }
            if (option.index == AGENT_TO_BASIC)
            {
                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.basic);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
            }
            if (option.index == QUARANTINE)
            {
                //First part is your personal utility. How much am I, personally, affected?
                double localU      = p.threat_plague.threat;
                bool   amNeighbour = false;
                bool   hasDisease  = false;
                foreach (Property p2 in p.getLocation().properties)
                {
                    if (p2.proto.isDisease)
                    {
                        hasDisease = true; break;
                    }
                }
                if (hasDisease)
                {
                    //This option doesn't help me. It's already here. If I'm corrupt, I'll naturally be angry at not being given help
                    localU = p.getSelfInterest() * p.threat_plague.threat * World.staticMap.param.utility_selfInterestFromThreat;
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Does not help me personally", localU));
                        u += localU;
                    }
                }
                else
                {
                    //I do not have the disease. Best to vote to keep it that way.
                    foreach (Location l2 in p.getLocation().getNeighbours())
                    {
                        foreach (Property p2 in l2.properties)
                        {
                            if (p2.proto.isDisease)
                            {
                                amNeighbour = true; break;
                            }
                        }
                    }
                    if (amNeighbour)
                    {
                        localU *= 1.5;
                    }
                    else
                    {
                        localU *= 0.66;
                    }
                    localU *= p.getSelfInterest() * -1 * World.staticMap.param.utility_selfInterestFromThreat; //Note this param is negative as it is petulance
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Desire to keep self safe from disease", localU));
                        u += localU;
                    }
                }

                //Second part is the benefit to the nation
                int    nNeighbours = 0;
                double nSocLocs    = 0;
                foreach (Location l2 in p.map.locations)
                {
                    if (l2.soc == p.society)
                    {
                        nSocLocs += 1;
                    }
                    else
                    {
                        continue;
                    }

                    hasDisease = false;
                    foreach (Property p2 in l2.properties)
                    {
                        if (p2.proto.isDisease)
                        {
                            hasDisease = true; break;
                        }
                    }
                    if (hasDisease)
                    {
                        foreach (Location l3 in l2.getNeighbours())
                        {
                            if (l3.soc != p.society)
                            {
                                continue;
                            }
                            bool l3HasDisease = false;
                            foreach (Property p2 in l3.properties)
                            {
                                if (p2.proto.isDisease)
                                {
                                    l3HasDisease = true; break;
                                }
                            }
                            if (!l3HasDisease)
                            {
                                //Location 3 doesn not have the disease, but l2 does. Therefore it is a spread vector
                                //Since we're taking a risk for each link, we can double-count L3s.
                                nNeighbours += 1;
                            }
                        }
                    }
                }
                localU = nNeighbours;
                if (nSocLocs > 0)
                {
                    localU /= nSocLocs;
                }                                        //Normalise for society size
                localU *= p.threat_plague.threat;
                localU *= p.map.param.utility_plagueResponseMultPerRiskItem;
                localU *= Math.Max(0, Math.Min(1, 1 - p.getSelfInterest()));//Clamp that between [0,1]
                if (localU != 0)
                {
                    msgs.Add(new ReasonMsg("Benefit to nation: Number of locations at risk", localU));
                    u += localU;
                }
            }
            if (option.index == TREATMENT)
            {
                //First part is your personal utility. How much am I, personally, affected?
                double localU     = p.threat_plague.threat;
                bool   hasDisease = false;
                foreach (Property p2 in p.getLocation().properties)
                {
                    if (p2.proto.isDisease)
                    {
                        hasDisease = true; break;
                    }
                }
                if (hasDisease)
                {
                    //I have the disease. Gotta invest in that sweet cure
                    localU *= p.getSelfInterest() * -1 * World.staticMap.param.utility_selfInterestFromThreat;//Note this param is negative as it is petulance
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Desire to save self from disease", localU));
                        u += localU;
                    }
                }
                else
                {
                    //This option doesn't help me. It's already here. If I'm corrupt, I'll naturally be angry at not being given help
                    localU = p.getSelfInterest() * p.threat_plague.threat * World.staticMap.param.utility_selfInterestFromThreat;
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Does not help me personally", localU));
                        u += localU;
                    }
                }

                //Second part is the benefit to the nation
                int    nDiseased = 0;
                double nSocLocs  = 0;
                foreach (Location l2 in p.map.locations)
                {
                    if (l2.soc == p.society)
                    {
                        nSocLocs += 1;
                    }
                    else
                    {
                        continue;
                    }

                    foreach (Property p2 in l2.properties)
                    {
                        if (p2.proto.isDisease)
                        {
                            nDiseased += 1; break;
                        }
                    }
                }
                localU = nDiseased;
                if (nSocLocs > 0)
                {
                    localU /= nSocLocs;
                }                                        //Normalise for society size
                localU *= p.threat_plague.threat;
                localU *= p.map.param.utility_plagueResponseMultPerRiskItem;
                localU *= Math.Max(0, Math.Min(1, 1 - p.getSelfInterest()));//Clamp that between [0,1]
                if (localU != 0)
                {
                    msgs.Add(new ReasonMsg("Benefit to nation: Number of locations infected", localU));
                    u += localU;
                }
            }

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

            double concernLevel = p.threat_agents.threat;                   //curr 0 to 200

            concernLevel += (100 * p.awareness) + (100 * p.map.worldPanic); //0 to 400
            concernLevel /= 4;
            concernLevel  = Math.Min(concernLevel, (p.map.worldPanic * 100) + 20);

            concernLevel *= (1 - p.shadow);
            if (p.state == Person.personState.enthralled || p.state == Person.personState.broken)
            {
                concernLevel = 0;
            }

            //Define the range at which this manner of response is appropriate
            double responseLevelMin = 0;
            double responseLevelMax = 0;

            if (option.index == DEFEND_PROVINCE)
            {
                responseLevelMin = 10;
                responseLevelMax = 40;

                int evidenceFound = 0;
                foreach (Evidence ev in foundEvidence)
                {
                    if (ev.locationFound.province.index == option.province)
                    {
                        evidenceFound += 1;
                    }
                }

                double localU = World.staticMap.param.utility_defendEvidenceProvince * evidenceFound * (1 - p.shadow);
                msgs.Add(new ReasonMsg("Amount of evidence found in " + society.map.provinces[option.province].name + " province", localU));
                u += localU;

                localU = 0;
                foreach (Person person in society.people)
                {
                    if (person.getLocation() != null && person.getLocation().province.index == option.province)
                    {
                        localU += p.getRelation(person.index).getLiking() * World.staticMap.param.utility_agentDefendProvinceLikingMult;
                    }
                }
                string add = "";
                msgs.Add(new ReasonMsg("Liking for nobles in province" + add, localU));
                u += localU;

                if (p.getLocation().province.index != option.province)
                {
                    localU = p.getSelfInterest() * p.threat_agents.threat * World.staticMap.param.utility_selfInterestFromThreat;
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Does not help me personally", localU));
                        u += localU;
                    }
                }
                else
                {
                    localU = -1 * p.getSelfInterest() * p.threat_agents.threat * World.staticMap.param.utility_selfInterestFromThreat;
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Helps me personally", localU));
                        u += localU;
                    }
                }
            }
            if (option.index == NATIONWIDE_SECURITY)
            {
                responseLevelMin = 10;
                responseLevelMax = 40;

                double localU = World.staticMap.param.utility_evidenceResonseBaseline * (concernLevel / 100);
                msgs.Add(new ReasonMsg("Base Desirability", localU));
                u += localU;

                localU = p.getSelfInterest() * p.threat_agents.threat * World.staticMap.param.utility_selfInterestFromThreat / 2;
                if (localU != 0)
                {
                    msgs.Add(new ReasonMsg("Doesn't maximise my provinces' defences", localU));
                    u += localU;
                }
            }
            if (option.index == NO_RESPONSE)
            {
                responseLevelMin = 0;
                responseLevelMax = 10;

                if (p.getGreatestThreat() != null && p.getGreatestThreat() != p.threat_agents)
                {
                    double localU = World.staticMap.param.utility_greatestThreatDelta * 0.5;
                    msgs.Add(new ReasonMsg("Not our greatest threat", localU));
                    u += localU;
                }
                else
                {
                    double localU = -World.staticMap.param.utility_greatestThreatDelta;
                    msgs.Add(new ReasonMsg("Dark Agents are our greatest threat", localU));
                    u += localU;
                }
            }

            if (option.index == EXPELL_ALL_FOREIGN_AGENTS)
            {
                responseLevelMin = 75;
                responseLevelMax = 100;

                double n = 0;
                foreach (Unit unit in society.map.units)
                {
                    if (unit.society == society)
                    {
                        continue;
                    }
                    if (society.enemies.Contains(unit) == false)
                    {
                        n += 1;
                    }
                }
                if (n > 0)
                {
                    msgs.Add(new ReasonMsg("So many potential enemies!", concernLevel));
                    u += concernLevel;
                }
            }
            if (option.index == LOCKDOWN_PROVINCE)
            {
                responseLevelMin = 40;
                responseLevelMax = 100;

                int evidenceFound = 0;
                foreach (Evidence ev in foundEvidence)
                {
                    if (ev.locationFound.province.index == option.province)
                    {
                        evidenceFound += 1;
                    }
                }

                double localU = World.staticMap.param.utility_defendEvidenceProvince * evidenceFound * (1 - p.shadow);
                msgs.Add(new ReasonMsg("Amount of evidence found in " + society.map.provinces[option.province].name + " province", localU));
                u += localU;

                localU = 0;
                foreach (Person person in society.people)
                {
                    if (person.getLocation() != null && person.getLocation().province.index == option.province)
                    {
                        localU += p.getRelation(person.index).getLiking() * World.staticMap.param.utility_agentDefendProvinceLikingMult;
                    }
                }
                string add = "" + (int)(localU);
                msgs.Add(new ReasonMsg("Liking for nobles in province" + add, localU));
                u += localU;

                if (p.getLocation().province.index != option.province)
                {
                    localU = p.getSelfInterest() * p.threat_agents.threat * World.staticMap.param.utility_selfInterestFromThreat;
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Does not help me personally", localU));
                        u += localU;
                    }
                }
                else
                {
                    localU = -1 * p.getSelfInterest() * p.threat_agents.threat * World.staticMap.param.utility_selfInterestFromThreat;
                    if (localU != 0)
                    {
                        msgs.Add(new ReasonMsg("Helps me personally", localU));
                        u += localU;
                    }
                }
            }
            if (option.index == AGENT_TO_INVESTIGATOR)
            {
                responseLevelMin = 0;
                responseLevelMax = 100;
                Unit_Investigator inv = (Unit_Investigator)option.unit;

                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.investigator);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
                bool hasSuspicions = false;
                foreach (RelObj rel in inv.person.relations.Values)
                {
                    if (inv.location.map.persons[rel.them] == null)
                    {
                        continue;
                    }
                    if (rel.suspicion > 0 && inv.location.map.persons[rel.them].unit != null && inv.location.map.units.Contains(inv.location.map.persons[rel.them].unit))
                    {
                        hasSuspicions = true;
                    }
                }
                if (hasSuspicions)
                {
                    localU = 12;
                    msgs.Add(new ReasonMsg("Has a suspect", localU));
                    u += localU;
                }
            }
            if (option.index == AGENT_TO_BASIC)
            {
                responseLevelMin = 0;
                responseLevelMax = 100;

                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.basic);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
            }

            if (concernLevel > responseLevelMax)
            {
                double delta = responseLevelMax - concernLevel;
                delta *= society.map.param.utility_extremeismScaling;
                double localU = delta;
                msgs.Add(new ReasonMsg("Too weak response for current concern level (" + (int)(concernLevel) + "%)", localU));
                u += localU;
            }
            if (concernLevel < responseLevelMin)
            {
                double delta = concernLevel - responseLevelMin;
                delta *= society.map.param.utility_extremeismScaling;
                double localU = delta;
                msgs.Add(new ReasonMsg("Too extreme for current concern level (" + (int)(concernLevel) + "%)", localU));
                u += localU;
            }
            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);
        }
Esempio n. 13
0
        public override double computeUtility(Person voter, VoteOption option, List <ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(voter);

            //Option 0 is "Don't declare war"
            //Multiply values based on this, as they should be symmetric for most parts
            double parityMult = 1;

            if (option.index == 0)
            {
                parityMult = -1;
            }

            double ourStrength   = society.currentMilitary;
            double theirStrength = target.currentMilitary;

            if (ourStrength + theirStrength == 0)
            {
                ourStrength += 0.001;
            }
            double localU = 0;

            if (ourStrength < 1)
            {
                localU = -1000 * parityMult;
                msgs.Add(new ReasonMsg("We are too weak", localU));
                u += localU;
                return(u);
            }

            //1 if we're 100% of the balance, -1 if they are
            double relativeStrength = (ourStrength - theirStrength) / (ourStrength + theirStrength + 1);

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

            msgs.Add(new ReasonMsg("Relative strength of current militaries", relMilU));
            u += relMilU;

            /*
             * 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;
             * }
             */

            localU = voter.politics_militarism * parityMult * 50;
            msgs.Add(new ReasonMsg("Militarism of " + voter.getFullName(), localU));
            u += localU;


            foreach (ThreatItem threat in voter.threatEvaluations)
            {
                if (threat.group == option.group)
                {
                    localU = threat.threat;
                    msgs.Add(new ReasonMsg("Perceived Threat", localU));
                    u += localU;
                    break;
                }
            }

            /*
             * 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);
        }
        public override double computeUtility(Person voter, VoteOption option, List <ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(voter);

            Person p = option.person;

            double newValue = title.getPrestige();

            double benefitToPerson = newValue;

            //We know how much they would be advantaged. We now need to know how much we like them to determine
            //if this is a good thing or not

            double benefitU = benefitToPerson * voter.getRelation(p).getLiking() * voter.map.param.utility_unlandedTitleMult;

            //Check if you should avoid voting for yourself
            bool wouldBeOutvoted = false;

            if (p == voter)
            {
                foreach (Person p2 in voter.society.people)
                {
                    if (p2.prestige > p.prestige * 1.5)
                    {
                        wouldBeOutvoted = true;
                    }
                }
            }
            if (wouldBeOutvoted)
            {
                benefitU *= voter.map.param.utility_wouldBeOutvotedMult;
                msgs.Add(new ReasonMsg("Benefit to (reduced by fears of being outvoted) " + p.getFullName(), benefitU));
                u += benefitU;
            }
            else
            {
                msgs.Add(new ReasonMsg("Benefit to " + p.getFullName(), benefitU));
                u += benefitU;
            }

            //We need to know if someone's going to lose out here
            //(Note this is irrelevant if they're the person who's being voted on)
            if (title.heldBy != null && title.heldBy != p)
            {
                double damageToOther = title.getPrestige();
                double localU        = -damageToOther *voter.getRelation(title.heldBy).getLiking() * voter.map.param.utility_unlandedTitleMult;

                if (wouldBeOutvoted)
                {
                    localU *= voter.map.param.utility_wouldBeOutvotedMult;
                }
                msgs.Add(new ReasonMsg("Harm to " + title.heldBy.getFullName(), localU));
                u += localU;
            }

            //Existing prestige of person being voted on
            double prestigeU = p.prestige * society.map.param.utility_prestigeMultForTitle;

            msgs.Add(new ReasonMsg("Prestige of " + p.getFullName(), prestigeU));
            u += prestigeU;

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


            double ourStrength   = society.currentMilitary;
            double theirStrength = option.group.currentMilitary;
            double localU        = 0;


            //1 if we're 100% of the balance, -1 if they are
            double relativeStrength = (ourStrength - theirStrength) / (ourStrength + theirStrength);

            //Don't just always attack the weakest, it causes blobbing. Check military to avoid suicide charges, but attack should be modulated by threat
            //As such, this modifier only applies when its negative (aversion to attacking stronger targets)
            localU = society.map.param.utility_militaryTargetRelStrengthOffensive * relativeStrength;
            if (localU < 0)
            {
                msgs.Add(new ReasonMsg("Relative Strength of Current Militaries", localU));
                u += localU;
            }


            foreach (ThreatItem threat in voter.threatEvaluations)
            {
                if (threat.group == option.group)
                {
                    localU = threat.threat;
                    msgs.Add(new ReasonMsg("Perceived Threat", localU));
                    u += localU;
                    break;
                }
            }


            //If we already have a military target
            if (society.offensiveTarget != null)
            {
                theirStrength = society.offensiveTarget.currentMilitary;
                localU        = 0;

                //1 if we're 100% of the balance, -1 if they are
                relativeStrength = (ourStrength - theirStrength) / (ourStrength + theirStrength);
                if (relativeStrength > 0)
                {
                    relativeStrength = 0;
                }

                //Add current target threat
                foreach (ThreatItem threat in voter.threatEvaluations)
                {
                    if (threat.group == society.offensiveTarget)
                    {
                        localU -= threat.threat;
                        break;
                    }
                }

                localU -= society.map.param.utility_militaryTargetRelStrengthOffensive * relativeStrength;
                msgs.Add(new ReasonMsg("Desirability of current target (" + society.offensiveTarget.getName() + ")", localU));
                u += localU;
            }


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

            //Option 0 is "Don't vassalise"
            //Multiply values based on this, as they should be symmetric for most parts
            double parityMult = 1;

            if (option.index == 0)
            {
                parityMult = -1;
            }


            double localU = 0;

            localU = voter.map.param.utility_vassaliseReluctance * parityMult;
            msgs.Add(new ReasonMsg("Inherent reluctance", localU));
            u += localU;

            Society socTarget = (Society)target;

            foreach (KillOrder order in socTarget.killOrders)
            {
                if (order.person == voter)
                {
                    localU = -1000 * parityMult;
                    msgs.Add(new ReasonMsg("Kill order against " + voter.getFullName(), localU));
                    u += localU;
                }
            }

            if (voter.society.defensiveTarget == null)
            {
                return(u);
            }

            double threatV = 0;

            foreach (ThreatItem threat in voter.threatEvaluations)
            {
                if (threat.group == voter.society.defensiveTarget)
                {
                    threatV = threat.threat;
                    break;
                }
            }

            /*
             * double ourStrength = society.currentMilitary;
             * double theirStrength = society.defensiveTarget.currentMilitary;
             * if (ourStrength + theirStrength == 0) { ourStrength += 0.001; }
             * //-1 if we're 100% of the balance, +1 if they are
             * double relativeStrength = (theirStrength - ourStrength) / (ourStrength + theirStrength);
             *
             * double relMilU = society.map.param.utility_vassaliseMilMult*relativeStrength * parityMult;
             * msgs.Add(new ReasonMsg("Military strength vs defensive target", relMilU));
             * u += relMilU;
             */

            double relThreatU = society.map.param.utility_vassaliseThreatMult * threatV * parityMult;

            msgs.Add(new ReasonMsg("Threat from defensive target", relThreatU));
            u += relThreatU;


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


            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;

            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;
            }
            double offUtility            = 0;
            double offUtilityStr         = 0;
            double offUtilityPersonality = 0;

            if (voter.society.offensiveTarget != null)
            {
                //Negative if the offensive target is stronger
                offUtilityStr         += (ourStr - offStr) / (ourStr + offStr) * voter.map.param.utility_militaryTargetRelStrengthOffensive;
                offUtilityPersonality += voter.politics_militarism * voter.map.param.utility_militarism;
                offUtility            += offUtilityStr;
                offUtility            += offUtilityPersonality;
            }
            double introUtility          = 0;
            double 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

            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 && society.posture != Society.militaryPosture.defensive)
            {
                u += defUtility;
                msgs.Add(new ReasonMsg("Our relative strength against defensive target", defUtility));
            }
            if (option.index == 1 && society.posture != Society.militaryPosture.offensive)
            {
                u += offUtility;
                msgs.Add(new ReasonMsg("Our relative strength against offensive target", offUtilityStr));
                msgs.Add(new ReasonMsg("Militarism personality", offUtilityPersonality));
            }
            if (option.index == 2 && society.posture != Society.militaryPosture.introverted)
            {
                u += introUtility;
                msgs.Add(new ReasonMsg("Instability internally", introUtilityStability));
                msgs.Add(new ReasonMsg("Suspicion of nobles' darkness", introFromInnerThreat));
            }


            return(u);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public override double computeUtility(Person p, VoteOption option, List <ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(p);

            double concernLevel = p.threat_enshadowedNobles.threat;         //curr 0 to 200

            concernLevel += (100 * p.awareness) + (100 * p.map.worldPanic); //0 to 400
            concernLevel /= 4;
            concernLevel  = Math.Min(concernLevel, (p.map.worldPanic * 100) + 20);

            concernLevel *= (1 - p.shadow);
            if (p.state == Person.personState.enthralled || p.state == Person.personState.broken)
            {
                concernLevel = 0;
            }

            //Define the range at which this manner of response is appropriate
            double responseLevelMin = 0;
            double responseLevelMax = 0;

            if (option.index == NO_RESPONSE)
            {
                responseLevelMin = 0;
                responseLevelMax = 10;

                if (p.getGreatestThreat() != null && p.getGreatestThreat() != p.threat_enshadowedNobles)
                {
                    double localU = World.staticMap.param.utility_greatestThreatDelta * 0.5;
                    msgs.Add(new ReasonMsg("Not our greatest threat", localU));
                    u += localU;
                }
                else
                {
                    double localU = -World.staticMap.param.utility_greatestThreatDelta;
                    msgs.Add(new ReasonMsg("Enshadowed nobles are our greatest threat", localU));
                    u += localU;
                }
            }

            if (option.index == WITCH_HUNT)
            {
                responseLevelMin = 80;
                responseLevelMax = 100;

                double localU = -World.staticMap.param.utility_killSuspectRelucatance;
                msgs.Add(new ReasonMsg("Base Reluctance to Execute Noble", localU));
                u += localU;


                bool isWarlike   = false;
                bool isHonorable = false;
                bool isPacifist  = false;
                foreach (Trait t in p.traits)
                {
                    if (t is Trait_Political_Warlike)
                    {
                        isWarlike = true; break;
                    }
                    if (t is Trait_Political_Honorable)
                    {
                        isHonorable = true; break;
                    }
                    if (t is Trait_Political_Pacifist)
                    {
                        isPacifist = true; break;
                    }
                }
                if (isHonorable)
                {
                    localU = p.map.param.utility_honorableHatesWitchHunt;
                    msgs.Add(new ReasonMsg("Honorable Politician opposes executions without trials", localU));
                    u += localU;
                }
                if (isWarlike)
                {
                    localU = p.map.param.utility_warlikeLikesWitchHunt;
                    msgs.Add(new ReasonMsg("Warlike Politician supports violence", localU));
                    u += localU;
                }
                if (isPacifist)
                {
                    localU = -p.map.param.utility_warlikeLikesWitchHunt;
                    msgs.Add(new ReasonMsg("Pacifist Politician supports violence", localU));
                    u += localU;
                }

                double maxSuspicion = 0;
                foreach (Person p2 in p.society.people)
                {
                    maxSuspicion = Math.Max(maxSuspicion, p.getRelation(p2.index).suspicion);
                }
                localU = maxSuspicion;
                if (localU != 0)
                {
                    msgs.Add(new ReasonMsg("Suspicion towards other nobles", localU));
                    u += localU;
                }
            }

            if (option.index == AGENT_TO_INQUISITOR)
            {
                responseLevelMin = 0;
                responseLevelMax = 100;
                Unit_Investigator inv = (Unit_Investigator)option.unit;

                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.inquisitor);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;

                bool isCorrupt = false;
                foreach (Trait t in p.traits)
                {
                    if (t is Trait_Political_Corrupt)
                    {
                        isCorrupt = true; break;
                    }
                }
                if (isCorrupt)
                {
                    localU = p.map.param.utility_corruptHatesInquisitor;
                    msgs.Add(new ReasonMsg("Inquisitor may expose my political corruption", localU));
                    u += localU;
                }
            }
            if (option.index == AGENT_TO_BASIC)
            {
                responseLevelMin = 0;
                responseLevelMax = 100;

                double localU = Unit_Investigator.getSwitchUtility(p, (Unit_Investigator)option.unit, Unit_Investigator.unitState.basic);
                localU *= p.map.param.utility_swapAgentRolesMult;
                msgs.Add(new ReasonMsg("Balance of agent skills vs balance of threats", localU));
                u += localU;
            }

            if (concernLevel > responseLevelMax)
            {
                double delta = responseLevelMax - concernLevel;
                delta *= society.map.param.utility_extremeismScaling;
                double localU = delta;
                msgs.Add(new ReasonMsg("Too weak response for current concern level (" + (int)(concernLevel) + "%)", localU));
                u += localU;
            }
            if (concernLevel < responseLevelMin)
            {
                double delta = concernLevel - responseLevelMin;
                delta *= society.map.param.utility_extremeismScaling;
                double localU = delta;
                msgs.Add(new ReasonMsg("Too extreme for current concern level (" + (int)(concernLevel) + "%)", localU));
                u += localU;
            }
            return(u);
        }
        public override double computeUtility(Person voter, VoteOption option,List<ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(voter);


            double ourStrength = society.currentMilitary;
            double theirStrength = option.group.currentMilitary;
            double localU = 0;


            //1 if we're 100% of the balance, -1 if they are
            double relativeStrength = (ourStrength - theirStrength) / (ourStrength + theirStrength);

            //Don't just always attack the weakest, it causes blobbing. Check military to avoid suicide charges, but attack should be modulated by threat
            //As such, this modifier only applies when its negative (aversion to attacking stronger targets)
            localU = society.map.param.utility_militaryTargetRelStrengthOffensive*relativeStrength;
            if (localU < 0)
            {
                msgs.Add(new ReasonMsg("Relative Strength of Current Militaries", localU));
                u += localU;
            }

            //We want to expand into territory we already partially own
            bool hasMyTerritory = false;
            foreach (Location loc in option.group.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;
            }

            bool hasOurTerritory = false;
            foreach (Location loc in option.group.lastTurnLocs)
            {
                foreach (Location l2 in society.lastTurnLocs)
                {
                    if (loc.province == l2.province)
                    {
                        hasOurTerritory = true;
                    }
                }
            }

            //We want to own more land. Invade weak neighbours
            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; }
            if (shouldExpand && option.group is Society && option.group.currentMilitary*1.5 < this.society.currentMilitary && option.group.getNeighbours().Contains(this.society))
            {
                //Society soc = (Society)option.group;
                //if (this.society.getCapital() != null && soc.getCapital() != null)
                //{
                //    if (soc.getCapital().hex.getHabilitability() > 0.5)
                //    {
                        localU = society.map.param.utility_militaryTargetExpansion;
                        msgs.Add(new ReasonMsg("Expand our holdings", localU));
                        u += localU;
                //    }
                //}
            }


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


            //If we already have a military target
            if (society.offensiveTarget != null)
            {
                theirStrength = society.offensiveTarget.currentMilitary;
                localU = 0;

                //1 if we're 100% of the balance, -1 if they are
                relativeStrength = (ourStrength - theirStrength) / (ourStrength + theirStrength);
                if (relativeStrength > 0) { relativeStrength = 0; }

                //Add current target threat
                foreach (ThreatItem threat in voter.threatEvaluations)
                {
                    if (threat.group == society.offensiveTarget)
                    {
                        localU -= threat.threat;
                        break;
                    }
                }


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

                localU -= society.map.param.utility_militaryTargetRelStrengthOffensive * relativeStrength;
                msgs.Add(new ReasonMsg("Desirability of current target (" + society.offensiveTarget.getName() + ")", localU));
                u += localU;
            }


            return u;
        }
Esempio n. 21
0
        public override double computeUtility(Person p, VoteOption option, List <ReasonMsg> msgs)
        {
            double u = option.getBaseUtility(p);

            double advtangeToMe        = 0;
            double advantageToAllies   = 0;
            double advantageToEnemeies = 0;

            foreach (Person affected in society.people)
            {
                if (affected.title_land != null)
                {
                    double delta = 1;
                    if (affected.title_land.settlement.econTraits().Contains(option.econ_to))
                    {
                        delta *= society.map.param.econ_multFromBuff;
                    }
                    if (affected.title_land.settlement.econTraits().Contains(option.econ_from))
                    {
                        delta /= society.map.param.econ_multFromBuff;
                    }

                    delta = 1 - delta;
                    //Run off the base prestige, so all change is regarded the same, regardless of existing changes
                    if (affected == p)
                    {
                        advtangeToMe = delta * p.getRelation(affected).getLiking() * affected.title_land.settlement.basePrestige * society.map.param.utility_econEffect;
                    }
                    else
                    {
                        if (p.getRelation(affected).getLiking() > 0)
                        {
                            advantageToAllies += delta * p.getRelation(affected).getLiking() * affected.title_land.settlement.basePrestige * society.map.param.utility_econEffectOther;
                        }
                        else
                        {
                            advantageToEnemeies += delta * p.getRelation(affected).getLiking() * affected.title_land.settlement.basePrestige * society.map.param.utility_econEffectOther;
                        }
                    }
                }
            }

            //If we're actually affected by this, don't care more about the wellbeing of others than of yourself
            if (Math.Abs(advtangeToMe) > 1)
            {
                if (Math.Abs(advantageToAllies) > Math.Abs(advtangeToMe) / 4)
                {
                    if (advantageToAllies > 0)
                    {
                        advantageToAllies = Math.Abs(advtangeToMe) / 4;
                    }
                    if (advantageToAllies < 0)
                    {
                        advantageToAllies = -Math.Abs(advtangeToMe) / 4;
                    }
                }
                if (Math.Abs(advantageToEnemeies) > Math.Abs(advtangeToMe) / 3)
                {
                    if (advantageToEnemeies > 0)
                    {
                        advantageToEnemeies = Math.Abs(advtangeToMe) / 3;
                    }
                    if (advantageToEnemeies < 0)
                    {
                        advantageToEnemeies = -Math.Abs(advtangeToMe) / 3;
                    }
                }
            }

            msgs.Add(new ReasonMsg("Advantage to me", advtangeToMe));
            u += advtangeToMe;
            msgs.Add(new ReasonMsg("Advantage to allies", advantageToAllies));
            u += advantageToAllies;
            msgs.Add(new ReasonMsg("Advantage to enemies", advantageToEnemeies));
            u += advantageToEnemeies;

            //World.log("Econ advantages " + advtangeToMe + " " + advantageToAllies + " " + advantageToEnemeies);

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

            Person p             = option.person;
            double existingValue = 0;

            if (p.title_land != null)
            {
                existingValue = p.title_land.settlement.getPrestige();
            }

            double newValue = title.settlement.getPrestige();

            double benefitToPerson = newValue - existingValue;

            //We know how much they would be advantaged. We now need to know how much we like them to determine
            //if this is a good thing or not

            double localU = benefitToPerson * voter.getRelation(p).getLiking() * voter.map.param.utility_landedTitleMult;

            msgs.Add(new ReasonMsg("Benefit to " + p.getFullName(), localU));
            u += localU;

            if (title.heldBy == null)
            {
                localU = voter.map.param.utility_landedTitleAssignBaseline;
                msgs.Add(new ReasonMsg("Need to assign the title", localU));
                u += localU;
            }

            if (option.person != voter.society.getSovreign() && voter != option.person)
            {
                Person wouldBeSuperior = title.settlement.location.getSuperiorInSociety(voter.society);
                Person currentSuperior = option.person.getDirectSuperiorIfAny();
                if (currentSuperior == voter && wouldBeSuperior != voter)
                {
                    //Follower would be leaving
                    double desirabilityAsFollower = 0;
                    foreach (Trait t in option.person.traits)
                    {
                        desirabilityAsFollower += t.desirabilityAsFollower();
                    }
                    if (wouldBeSuperior == voter)
                    {
                        localU = -desirabilityAsFollower;
                        msgs.Add(new ReasonMsg("Desirability as follower", localU));
                        u += localU;
                    }
                }
                else if (currentSuperior != voter && wouldBeSuperior == voter)
                {
                    //Follower would be arriving
                    double desirabilityAsFollower = 0;
                    foreach (Trait t in option.person.traits)
                    {
                        desirabilityAsFollower += t.desirabilityAsFollower();
                    }
                    if (wouldBeSuperior == voter)
                    {
                        localU = desirabilityAsFollower;
                        msgs.Add(new ReasonMsg("Desirability as follower", localU));
                        u += localU;
                    }
                }
            }

            //We need to know if someone's going to lose out here
            //(Note this is irrelevant if they're the person who's being voted on)
            if (title.heldBy != null && title.heldBy != p)
            {
                double damageToOther = title.settlement.getPrestige();
                localU = -damageToOther *voter.getRelation(title.heldBy).getLiking() * voter.map.param.utility_landedTitleMult;

                msgs.Add(new ReasonMsg(title.heldBy.getFullName() + " would lose title", localU));
                u += localU;
            }


            return(u);
        }