public override void turnTick(Unit unit)
        {
            if (unit.location.settlement != null)
            {
                unit.task = null;
                return;
            }

            dur += 1;
            if (dur >= unit.location.map.param.unit_establishNewSettlementTime || (!unit.location.map.burnInComplete))
            {
                unit.task = null;

                Location loc      = unit.location;
                int      c        = 0;
                Society  receiver = null;
                foreach (Location l2 in loc.getNeighbours())
                {
                    if (l2.soc != null && l2.soc is Society)
                    {
                        c += 1;
                        if (Eleven.random.Next(c) == 0)
                        {
                            receiver = (Society)l2.soc;
                        }
                    }
                }
                if (receiver == null)
                {
                    //foreach (SocialGroup sg in loc.map.socialGroups)
                    //{
                    //    if (sg is Society)
                    //    {
                    //        c += 1;
                    //        if (Eleven.random.Next(c) == 0)
                    //        {
                    //            receiver = (Society)sg;
                    //        }
                    //    }
                    //}
                    //Start a fully new colony.
                    //Maybe in time this could have a cool name, like "Merchant republic" and be a free port city or something
                    receiver = new Society(unit.location.map, loc);
                    receiver.setName(loc.shortName);
                    loc.soc = receiver;
                    unit.location.map.socialGroups.Add(receiver);
                }

                if (receiver != null)
                {
                    if (loc.isMajor)
                    {
                        loc.settlement = new Set_City(loc);
                    }
                    else
                    {
                        int      q       = 0;
                        double[] weights = new double[] { 2, 1, 2 };
                        double   roll    = 0;
                        for (int i = 0; i < weights.Length; i++)
                        {
                            roll += weights[i];
                        }
                        roll *= Eleven.random.NextDouble();
                        for (int i = 0; i < weights.Length; i++)
                        {
                            roll -= weights[i]; if (roll <= 0)
                            {
                                q = i; break;
                            }
                        }

                        if (q == 0)
                        {
                            loc.settlement = new Set_Abbey(loc);
                        }
                        else if (q == 1)
                        {
                            loc.settlement = new Set_University(loc);
                        }
                        else
                        {
                            loc.settlement = new Set_Fort(loc);
                        }
                    }

                    loc.soc = receiver;
                    SettlementHuman set = (SettlementHuman)loc.settlement;
                    set.population = 1;//Start at the start
                    loc.map.addMessage(loc.soc.getName() + " expands, add new settlement: " + loc.getName(), MsgEvent.LEVEL_RED, false, loc.hex);
                }
            }
        }
        public void triggerCivilWar(List <Person> rebelsTotal)
        {
            World.log(this.getName() + " falls into civil war as " + rebelsTotal.Count + " out of " + people.Count + " nobles declare rebellion against " + getSovreign().getFullName());

            int  level     = MsgEvent.LEVEL_ORANGE;
            bool goodThing = true;

            if (this.hasEnthralled())
            {
                goodThing = false;
                level     = MsgEvent.LEVEL_RED;
            }
            map.addMessage(this.getName() + " falls into civil war! Provinces declare war on the sovreign's loyal forces.",
                           level, goodThing);

            List <Province>       seenProvinces    = new List <Province>();
            List <List <Person> > rebelsByProvince = new List <List <Person> >();
            List <Person>         unmappedRebels   = new List <Person>();

            foreach (Person p in rebelsTotal)
            {
                if (p.title_land == null)
                {
                    unmappedRebels.Add(p); continue;
                }
                if (seenProvinces.Contains(p.title_land.settlement.location.province))
                {
                    int ind = seenProvinces.IndexOf(p.title_land.settlement.location.province);
                    rebelsByProvince[ind].Add(p);
                }
                else
                {
                    seenProvinces.Add(p.title_land.settlement.location.province);
                    rebelsByProvince.Add(new List <Person>());
                    rebelsByProvince[rebelsByProvince.Count - 1].Add(p);
                }
            }

            if (rebelsByProvince.Count == 0)
            {
                World.log("No rebels had any territory. Rebellion called off");
                return;
            }

            rebelsByProvince[0].AddRange(unmappedRebels);

            World.log("Rebellion has " + seenProvinces.Count + " provinces");

            for (int k = 0; k < seenProvinces.Count; k++)
            {
                List <Person> rebels    = rebelsByProvince[k];
                Society       rebellion = new Society(map);
                map.socialGroups.Add(rebellion);
                rebellion.setName(seenProvinces[k].name + " rebellion");
                rebellion.isRebellion = true;
                if (Eleven.random.Next(2) == 0)
                {
                    rebellion.posture = militaryPosture.defensive;
                }
                foreach (Person p in rebels)
                {
                    if (p.title_land != null)
                    {
                        p.title_land.settlement.location.soc = rebellion;
                    }
                    this.people.Remove(p);
                    rebellion.people.Add(p);
                    p.society = rebellion;
                }

                double proportionalStrength = 0;
                rebellion.computeMilitaryCap();
                this.computeMilitaryCap();

                if (this.maxMilitary > 0 || rebellion.maxMilitary > 0)
                {
                    proportionalStrength      = this.maxMilitary / (this.maxMilitary + rebellion.maxMilitary);
                    rebellion.currentMilitary = this.currentMilitary * (1 - proportionalStrength);
                    this.currentMilitary      = this.currentMilitary * proportionalStrength;
                }

                if (getSovreign() != null)
                {
                    KillOrder killSovreign = new KillOrder(getSovreign(), "Rebellion against tyranny");
                    rebellion.killOrders.Add(killSovreign);
                }

                foreach (Person p in rebels)
                {
                    KillOrder killRebel = new KillOrder(p, "Rebelled against sovreign");
                    this.killOrders.Add(killRebel);
                }
                this.map.declareWar(rebellion, this);
            }
        }
Пример #3
0
        public void progressToNextAge()
        {
            map.automatic             = false;
            map.world.displayMessages = false;
            map.burnInComplete        = false;
            panicFromCluesDiscovered  = 0;
            panicFromPowerUse         = 0;
            List <Location> monsters = new List <Location>();

            foreach (Location loc in map.locations)
            {
                if (loc.soc != null && loc.soc.isDark() && (loc.soc is Society == false))
                {
                    monsters.Add(loc);
                }
            }
            lightbringerCasters = null;
            lightRitualProgress = 0;
            lightbringerLocations.Clear();
            while (monsters.Count > 3)
            {
                int      q   = Eleven.random.Next(monsters.Count);
                Location loc = monsters[q];
                loc.soc = null;
                if (loc.settlement != null)
                {
                    loc.settlement = null;
                }
                monsters.RemoveAt(q);
            }
            int lastIndexPerson = 0;

            foreach (SocialGroup sg in map.socialGroups)
            {
                if (sg is Society)
                {
                    Society soc = (Society)sg;
                    foreach (Person p in soc.people)
                    {
                        lastIndexPerson = Math.Max(p.index, lastIndexPerson);
                    }
                    soc.isDarkEmpire = false;
                }
            }
            if (enthralled != null)
            {
                enthralled.die("Died as the age changed", false);
            }

            int burnTurns = 300;

            for (int i = 0; i < burnTurns; i++)
            {
                map.turnTick();

                if (i % 25 == 0)
                {
                    bool hasHumanity = false;
                    foreach (Location loc in map.locations)
                    {
                        if (loc.isOcean)
                        {
                            continue;
                        }
                        if (loc.soc is Society && loc.settlement is SettlementHuman)
                        {
                            hasHumanity = true;
                        }
                    }
                    if (!hasHumanity)
                    {
                        foreach (Location loc in map.locations)
                        {
                            if (loc.isOcean)
                            {
                                continue;
                            }
                            if (loc.hex.getHabilitability() > map.param.mapGen_minHabitabilityForHumans && loc.isMajor)
                            {
                                loc.settlement = new Set_City(loc);

                                Society soc = new Society(map, loc);
                                soc.setName(loc.shortName);
                                loc.soc = soc;
                                map.socialGroups.Add(soc);
                            }
                        }
                    }

                    if (map.data_avrgEnshadowment > 0.1)
                    {
                        foreach (SocialGroup sg in map.socialGroups)
                        {
                            if (sg is Society)
                            {
                                Society       soc  = (Society)sg;
                                List <Person> dead = new List <Person>();
                                foreach (Person p in soc.people)
                                {
                                    if (p.state == Person.personState.broken && Eleven.random.Next(2) == 0)
                                    {
                                        dead.Add(p);
                                    }
                                    else if (p.shadow > 0 && Eleven.random.Next(2) == 0)
                                    {
                                        p.shadow = 0;
                                    }
                                }
                                foreach (Person p in dead)
                                {
                                    p.die("Died of old age", false);
                                }
                            }
                        }
                    }
                }
                foreach (SocialGroup sg in map.socialGroups)
                {
                    if (sg is Society)
                    {
                        Society       soc  = (Society)sg;
                        List <Person> dead = new List <Person>();
                        foreach (Person p in soc.people)
                        {
                            if (p.index <= lastIndexPerson)
                            {
                                if (p.index % 100 == i)
                                {
                                    dead.Add(p);
                                }
                            }
                        }
                        foreach (Person p in dead)
                        {
                            p.die("Died of old age", false);
                        }
                    }
                }

                if (i == burnTurns / 2)
                {
                    List <Unit> units = new List <Unit>();
                    units.AddRange(map.units);
                    foreach (Unit u in units)
                    {
                        u.die(map, "Old age");
                    }
                }
            }

            foreach (Person p in map.persons)
            {
                if (p == null)
                {
                    continue;
                }
                for (int i = 0; i < map.persons.Count; i++)
                {
                    if ((map.persons[i] == null || map.persons[i].isDead) && p.relations.ContainsKey(i))
                    {
                        p.relations.Remove(i);
                    }
                }
            }
            map.burnInComplete        = true;
            map.world.displayMessages = true;
            startedComplete();
            endOfGameAchieved   = false;
            map.firstPlayerTurn = map.turn;
        }