public Person getSuperiorIfAny()
 {
     foreach (Title t in titles)
     {
         if (t is Title_ProvinceRuler)
         {
             return(this.society.getSovreign());
         }
     }
     //Am not a duke
     foreach (Title t in society.titles)
     {
         if (t is Title_Sovreign)
         {
             return(null);
         }
         if (t is Title_ProvinceRuler)
         {
             if (((Title_ProvinceRuler)t).province == this.getLocation().province)
             {
                 return(t.heldBy);
             }
         }
     }
     //Am neither duke nor sovreign, nor do I live in a duke's province
     return(society.getSovreign());
 }
 public Person getSuperiorInSociety(Society society)
 {
     if (society.getCapital() != null && society.getCapital().province == this.province)
     {
         return(society.getSovreign());
     }
     foreach (Title t in society.titles)
     {
         if (t is Title_ProvinceRuler)
         {
             Title_ProvinceRuler t2 = (Title_ProvinceRuler)t;
             if (t2.province == this.province)
             {
                 return(t2.heldBy);
             }
         }
     }
     return(null);
 }
        public static void refreshHierarchy(Person nfocus)
        {
            clear();

            Person ss = activeSociety.getSovreign();

            //if (ss == null)
            //    return;

            focus = (state == viewState.HIERARCHY && nfocus != null) ? nfocus : ss;

            var tree = new Dictionary <GraphicalSlot, List <GraphicalSlot> >();

            foreach (Person p in activeSociety.people)
            {
                GraphicalSlot ds = null;
                if (p == ss || p.title_land == null)
                {
                    continue;
                }

                Person sp = p.getDirectSuperiorIfAny();
                if (sp != null)
                {
                    if (sp == ss)
                    {
                        if (!p.getIsProvinceRuler())
                        {
                            ds = loadedPlaceholders[p.getLocation().province];
                        }
                    }
                    else
                    {
                        ds = sp.outer;
                    }
                }
                else
                {
                    ds = loadedPlaceholders[p.getLocation().province];
                }

                if (ds == null)
                {
                    continue;
                }

                if (!tree.ContainsKey(ds))
                {
                    tree.Add(ds, new List <GraphicalSlot>());
                }

                tree[ds].Add(p.outer);
            }

            ss.outer.gameObject.SetActive(true);
            focus.outer.targetPosition = Vector3.zero;

            int n = tree.Count, i = 0;

            foreach (var pair in tree)
            {
                GraphicalSlot ds = pair.Key;

                float radius = 2.0f * zoom;
                float angle  = 6.28f / n * i;

                float x = Mathf.Cos(angle) * radius;
                float y = Mathf.Sin(angle) * radius;


                ds.gameObject.SetActive(true);
                ds.connection = ss.outer;

                ds.targetPosition     = new Vector3(x, y, 0.0f);
                ds.targetStartColor   = ds.targetEndColor = ds.neutralColor;
                ds.targetStartColor.a = ds.targetEndColor.a = 0.5f;

                float n2 = pair.Value.Count, j = 0;
                foreach (GraphicalSlot ds2 in pair.Value)
                {
                    float radius2 = 1.5f;
                    float spread  = (n2 > 4) ? 3.5f : 2.5f;
                    float angle2  = (angle - spread / 2) + spread / n2 * (j + 0.5f);

                    float x2 = Mathf.Cos(angle2) * radius2 + x;
                    float y2 = Mathf.Sin(angle2) * radius2 + y;

                    ds2.gameObject.SetActive(true);
                    ds2.gameObject.transform.localScale = originalScale * 0.75f;
                    ds2.connection = ds;

                    ds2.targetPosition     = new Vector3(x2, y2, 0.0f);
                    ds2.targetStartColor   = ds2.targetEndColor = ds2.neutralColor;
                    ds2.targetStartColor.a = ds2.targetEndColor.a = 0.25f;

                    j += 1;
                }

                i += 1;
            }

            state = viewState.HIERARCHY;
            resetHidden();
            refreshOffset();
        }
Пример #4
0
        private void processEnshadowment()
        {
            evidence += shadow * map.param.person_evidencePerShadow;
            if (evidence > 1)
            {
                evidence = 1;
            }
            if (state != personState.broken && state != personState.enthralled)
            {
                shadow -= map.param.person_shadowDecayPerTurn;
                if (shadow < 0)
                {
                    shadow = 0;
                }
            }
            foreach (Person p in society.people)
            {
                if (p == this)
                {
                    continue;
                }
                if (p.shadow == 0)
                {
                    continue;
                }                               //Can't inherit if they don't have any, skip to save CPU
                if (p.shadow <= shadow)
                {
                    continue;
                }
                if (p.prestige < prestige)
                {
                    continue;
                }

                /*
                 * double basePrestige = 100;
                 * if (society.getSovreign() != null) { basePrestige = society.getSovreign().prestige; }
                 * if (basePrestige < 10) { basePrestige = 10; }
                 * double multFromPrestige = p.prestige / basePrestige;
                 * if (multFromPrestige < 0) { multFromPrestige = 0; }
                 * if (multFromPrestige > 1) { multFromPrestige = 1; }
                 */

                double likingMult = Math.Max(0, this.getRelation(p).getLiking(this, p)) / 100;

                double shadowDelta = p.shadow * likingMult * map.param.person_shadowContagionMult; //You get enshadowed by people you like/trust
                this.shadow = Math.Min(p.shadow, shadow + shadowDelta);                            //Don't exceed your donor's shadow
                if (this.shadow > 1)
                {
                    this.shadow = 1;
                }
            }
            if (society.isDarkEmpire)
            {
                if (society.getSovreign() != null && society.getSovreign().shadow > shadow)
                {
                    shadow += map.param.ability_darkEmpireShadowPerTurn;
                }
                if (shadow > 1)
                {
                    shadow = 1;
                }
            }

            if (state == personState.normal && shadow == 1)
            {
                this.state = personState.broken;
                map.addMessage(new MsgEvent(this.getFullName() + " has been fully enshadowed, their soul can no longer resist the dark", MsgEvent.LEVEL_GREEN, true));
            }
        }
        public override void castInner(Map map, Person person)
        {
            ThreatItem item = person.getGreatestThreat();

            if (item == null)
            {
                return;
            }

            Society soc = person.society;
            Person  sov = soc.getSovreign();

            if (sov == null)
            {
                return;
            }
            int    nAffected = 0;
            double totalV    = 0;
            double sovFear   = 0;

            foreach (ThreatItem ti in sov.threatEvaluations)
            {
                if (item.isSame(ti))
                {
                    sovFear = ti.threat;
                    break;
                }
            }
            foreach (Person p in soc.people)
            {
                double myFear = 0;
                foreach (ThreatItem ti in p.threatEvaluations)
                {
                    if (item.isSame(ti))
                    {
                        myFear = ti.threat;
                        break;
                    }
                }

                double deltaFear = myFear - sovFear;
                if (deltaFear <= 0)
                {
                    continue;
                }

                double deltaLiking = deltaFear * map.param.ability_denounceLeaderLikingMult;
                deltaLiking = Math.Min(deltaLiking, map.param.ability_denounceLeaderMax);

                p.getRelation(sov).addLiking(-deltaLiking, "Doesn't take threat of " + item.getTitle() + " seriously", map.turn);

                nAffected += 1;
                totalV    += deltaFear;
            }

            double avrg = 0;

            if (nAffected > 0)
            {
                avrg = totalV / nAffected;
            }
            map.world.prefabStore.popImgMsg(
                "You rally the people against " + sov.getFullName() + ", denouncing them as unable to defend the people against the threat of " + item.getTitle() + ".\n" +
                nAffected + " nobles agree, with an average liking change of of " + (int)(-avrg),
                map.world.wordStore.lookup("ABILITY_DENOUNCE_LEADER"));
        }
        public void takeLocationFromOther(SocialGroup att, SocialGroup def, Location taken)
        {
            World.log(att.getName() + " takes " + taken.getName() + " from " + def.getName());
            int  priority = MsgEvent.LEVEL_YELLOW;
            bool benefit  = !def.hasEnthralled();

            if (att.hasEnthralled())
            {
                priority = MsgEvent.LEVEL_GREEN;
            }
            else if (def.hasEnthralled())
            {
                priority = MsgEvent.LEVEL_RED;
            }
            else
            {
                priority = MsgEvent.LEVEL_YELLOW;
            }


            turnMessages.Add(new MsgEvent(att.getName() + " takes " + taken.getName() + " from " + def.getName(), priority, benefit));

            if (taken.settlement != null)
            {
                if (taken.settlement.isHuman == false)
                {
                    taken.settlement = null;//Burn it down
                }
                else if (taken.settlement.title != null && taken.settlement.title.heldBy != null)
                {
                    Person lord = taken.settlement.title.heldBy;
                    if (att is Society)
                    {
                        Society socAtt = (Society)att;
                        lord.prestige *= param.combat_prestigeLossFromConquest;
                        if (socAtt.getSovreign() != null)
                        {
                            lord.getRelation(socAtt.getSovreign()).addLiking(param.person_likingFromBeingInvaded, "Their nation invaded mine", turn);
                        }
                        foreach (Title t in lord.titles)
                        {
                            t.heldBy = null;
                        }
                        lord.titles.Clear();


                        movePerson(lord, socAtt);
                    }
                    else
                    {
                        lord.die("Killed by " + att.getName() + " when " + taken.getName() + " fell");
                    }
                }
            }

            taken.soc = att;
            att.takeLocationFromOther(def, taken);

            bool hasRemainingTerritory = false;

            foreach (Location loc in locations)
            {
                if (loc.soc == def)
                {
                    hasRemainingTerritory = true;
                    break;
                }
            }
            if (!hasRemainingTerritory)
            {
                World.log("Last territory taken");
                addMessage(def.getName() + " has lost its last holdings to " + att.getName());

                /*
                 * if (att is Society && def is Society)
                 * {
                 *  Society sAtt = (Society)att;
                 *  Society sDef = (Society)def;
                 *  List<Person> toMove = new List<Person>();
                 *  foreach (Person p in sDef.people)
                 *  {
                 *      if (p.title_land == null)
                 *      {
                 *          toMove.Add(p);
                 *      }
                 *  }
                 *  foreach (Person p in toMove)
                 *  {
                 *      movePerson(p, sAtt);
                 *      addMessage(p.getFullName() + " is now part of the court of " + att.getName(), MsgEvent.LEVEL_GRAY, false);
                 *  }
                 * }
                 */
            }
        }