示例#1
0
        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;
            }


            addMessage(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;
                        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);
        }
        public virtual void takeLocationFromOther(SocialGroup def, Location taken)
        {
            this.temporaryThreat += map.param.threat_takeLocation;

            addHistory("#GRN_We have taken " + taken.getName() + " from " + def.getName());
            def.addHistory("#RED_We have lost " + taken.getName() + " to " + this.getName());
        }
 public string getTitle()
 {
     if (group == null)
     {
         if (form == formTypes.HOSTILE_NATION)
         {
             return("Hostile Nation");
         }
         if (form == formTypes.ENSHADOWED_NOBLES)
         {
             return("Enshadowed Nobles");
         }
         if (form == formTypes.AGENTS)
         {
             return("Dark Agents");
         }
         if (form == formTypes.PLAGUE)
         {
             return("Plague");
         }
         return("UNKNOWN");
     }
     else
     {
         return(group.getName());
     }
 }
        public void declareWar(SocialGroup att, SocialGroup def)
        {
            World.log(att.getName() + " declares war on " + def.getName());
            int  priority = MsgEvent.LEVEL_ORANGE;
            bool good     = false;

            if (att.hasEnthralled())
            {
                good = true; priority = MsgEvent.LEVEL_GREEN;
            }
            if (def.hasEnthralled())
            {
                priority = MsgEvent.LEVEL_RED;
            }
            turnMessages.Add(new MsgEvent(att.getName() + " launches an offensive against " + def.getName(), priority, good));

            att.getRel(def).state = DipRel.dipState.war;
            att.getRel(def).war   = new War(this, att, def);
        }
 public override string ToString()
 {
     return("Vassalise under " + target.getName());
 }
 public override string getShort()
 {
     return("Travelling to " + target.getName());
 }
示例#7
0
        public override string getLargeDesc()
        {
            string reply = "Vote to declare war on " + target.getName() + ".";

            return(reply);
        }
示例#8
0
        public override void castInner(Map map, Unit u)
        {
            Society soc = (Society)u.location.soc;

            SocialGroup enemy = null;

            foreach (SocialGroup sg in map.socialGroups)
            {
                if (sg.getRel(u.location.soc).state == DipRel.dipState.war)
                {
                    bool controlled = false;
                    if (sg is Society)
                    {
                        Society sgSoc = (Society)sg;
                        if (sgSoc.isDarkEmpire)
                        {
                            controlled = true;
                        }
                    }
                    else
                    {
                        controlled = sg.isDark();
                    }
                    if (controlled && sg.currentMilitary > u.location.soc.currentMilitary)
                    {
                        enemy = sg;
                    }
                }
            }
            if (enemy == null)
            {
                map.world.prefabStore.popMsg(soc.getName() + " is not at war with a superior military you control."); return;
            }

            HashSet <Person> targets = new HashSet <Person>();

            foreach (Person p in soc.people)
            {
                targets.Add(p);
            }
            int nSaved = 0;

            foreach (Location loc in map.locations)
            {
                if (loc.soc == soc)
                {
                    foreach (Location l2 in loc.getNeighbours())
                    {
                        if (l2.soc != soc)
                        {
                            if (l2.person() != null)
                            {
                                targets.Add(l2.person());
                            }
                        }
                    }
                    nSaved += 1;
                }
            }
            if (nSaved >= 10)
            {
                AchievementManager.unlockAchievement(SteamManager.achievement_key.SAVIOUR);
            }

            foreach (Person p in targets)
            {
                double boost = 100;
                //Let's not overcomplicate this one
                //foreach (ThreatItem item in p.threatEvaluations)
                //{
                //    if (item.group == enemy)
                //    {
                //        boost = item.threat;
                //    }
                //}
                //if (boost > 150) { boost = 150; }
                //if (boost < 25) { boost = 25; }
                p.getRelation(u.person).addLiking(boost, "Our Saviour!", map.turn, RelObj.STACK_REPLACE, true);
            }

            DipRel rel = soc.getRel(enemy);

            if (rel.war != null)
            {
                rel.war.startTurn = map.turn;
            }
            List <Unit> rems = new List <Unit>();

            foreach (Unit u2 in map.units)
            {
                if (u2.society == enemy && u2.isMilitary)
                {
                    rems.Add(u2);
                }
                else if (u2.society == soc && u2 is Unit_Army)
                {
                    u2.task = null;//Retask, to drop the 'defend the homeland' defensive task and go on the offensive
                }
            }
            foreach (Unit u2 in rems)
            {
                u2.die(map, "Killed by The Saviour");
            }
            soc.posture = Society.militaryPosture.offensive;//Flip to assault mode to ruin the dark forces

            Evidence e2 = new Evidence(map.turn);

            e2.pointsTo = u;
            e2.weight   = u.location.map.param.unit_majorEvidence;
            u.location.evidence.Add(e2);

            u.location.map.world.prefabStore.popImgMsg(u.getName() + " saves " + soc.getName() + " from invasion by " + enemy.getName() + "."
                                                       + "\nNobles within the nation, and those adjacent to it gain liking for " + soc.getName() + ". " + targets.Count + " nobles affected. " + rems.Count + " units killed."
                                                       + soc.getName() + " will now wage this war with renewed vigour, driving back their dark enemy",
                                                       u.location.map.world.wordStore.lookup("ABILITY_SAVIOUR_INVASION"), 7);
        }
        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);
                 *  }
                 * }
                 */
            }
        }
        public void processWars()
        {
            //Every society decides which other to attack, assuming it is over threshold combat strength
            foreach (SocialGroup sg in socialGroups)
            {
                if (sg.lastBattle == turn)
                {
                    continue;
                }                                       //Only one battle permitted per social group (that they initiate, at least)

                if (checkDefensiveAttackHold(sg))
                {
                    continue;
                }                                              //Should you stop attacking, to conserve strength?

                if (sg.currentMilitary < sg.maxMilitary * param.combat_thresholdAttackStrength)
                {
                    continue;
                }                                                                                            //Below min strength

                sg.lastBattle = turn;

                int      c          = 0;
                Location attackFrom = null;
                Location attackTo   = null;
                foreach (Location l in locations)
                {
                    if (l.soc == sg)
                    {
                        foreach (Link link in l.links)
                        {
                            if (link.other(l).soc != null && link.other(l).soc != sg && link.other(l).soc.getRel(sg).state == DipRel.dipState.war)
                            {
                                if (link.other(l).lastTaken == turn)
                                {
                                    continue;
                                }                                                 //Can't retake on this turn
                                c += 1;
                                if (Eleven.random.Next(c) == 0)
                                {
                                    attackFrom = l;
                                    attackTo   = link.other(l);
                                }
                            }
                        }
                    }
                }
                if (attackFrom != null)
                {
                    SocialGroup defender = attackTo.soc;

                    //sg.lastBattle = turn;
                    //defender.lastBattle = turn;

                    World.log(sg.getName() + " attacking into " + attackTo.getName());
                    double myStr    = sg.currentMilitary * Eleven.random.NextDouble();
                    double theirStr = defender.currentMilitary * Eleven.random.NextDouble();
                    if (myStr < 1)
                    {
                        myStr = Math.Min(1, sg.currentMilitary);
                    }
                    if (theirStr < 1)
                    {
                        theirStr = Math.Min(1, defender.currentMilitary);
                    }

                    //Note the defensive fortifications only reduce losses, not increase chance of taking territory
                    double myLosses = theirStr * param.combat_lethality;
                    sg.currentMilitary -= myLosses;
                    if (sg.currentMilitary < 0)
                    {
                        sg.currentMilitary = 0;
                    }
                    double theirLosses = myStr * param.combat_lethality;
                    theirLosses = computeDefensiveBonuses(theirLosses, sg, defender);
                    theirLosses = attackTo.takeMilitaryDamage(theirLosses);
                    defender.currentMilitary -= theirLosses;
                    if (defender.currentMilitary < 0)
                    {
                        defender.currentMilitary = 0;
                    }

                    addMessage(sg.getName() + " attacks " + defender.getName() + ". Inflicts " + (int)(theirLosses) + " dmg, takes " + (int)(myLosses),
                               MsgEvent.LEVEL_YELLOW, false);

                    if (attackTo.settlement != null)
                    {
                        attackTo.settlement.takeAssault(sg, defender, theirLosses);
                    }
                    //Can only take land if there are no defenses in place
                    if (myStr > theirStr * param.combat_takeLandThreshold && (attackTo.getMilitaryDefence() <= 0.01))
                    {
                        takeLocationFromOther(sg, defender, attackTo);
                        attackTo.lastTaken = turn;
                    }

                    if (sg is Society && defender is Society)
                    {
                        Property.addProperty(this, attackTo, "Recent Human Battle");
                    }

                    world.prefabStore.particleCombat(attackFrom.hex, attackTo.hex);
                }
            }

            foreach (SocialGroup group in socialGroups)
            {
                foreach (DipRel rel in group.getAllRelations())
                {
                    if (rel.state == DipRel.dipState.war && rel.war.canTimeOut)
                    {
                        if (turn - rel.war.startTurn > param.war_defaultLength)
                        {
                            declarePeace(rel);
                        }
                    }
                }
            }
        }
示例#11
0
        public void declareWar(SocialGroup att, SocialGroup def)
        {
            World.log(att.getName() + " declares war on " + def.getName());
            int  priority = MsgEvent.LEVEL_ORANGE;
            bool good     = false;

            if (att.hasEnthralled())
            {
                good = true; priority = MsgEvent.LEVEL_GREEN;
            }
            if (def.hasEnthralled())
            {
                priority = MsgEvent.LEVEL_RED;
            }
            Location attLoc = null;

            foreach (Location loc in locations)
            {
                if (loc.soc == att)
                {
                    attLoc = loc;
                }
            }
            Hex focusHex = null;

            if (attLoc != null)
            {
                focusHex = attLoc.hex;
            }
            turnMessages.Add(new MsgEvent(att.getName() + " launches an offensive against " + def.getName(), priority, good, focusHex));

            att.getRel(def).state = DipRel.dipState.war;
            att.getRel(def).war   = new War(this, att, def);

            if (def.getRel(att).state != DipRel.dipState.war)
            {
                throw new Exception("Asymmetric war");
            }

            foreach (Location loc in locations)
            {
                if (loc.soc == att || loc.soc == def)
                {
                    if (loc.settlement != null && loc.settlement.embeddedUnit != null)
                    {
                        loc.units.Add(loc.settlement.embeddedUnit);
                        units.Add(loc.settlement.embeddedUnit);
                        loc.settlement.embeddedUnit = null;
                    }
                }
            }

            if (att is Society)
            {
                Society sAtt = (Society)att;
                sAtt.crisisWarLong  = "We are at war, attacking " + def.getName() + ". We can discuss how to deploy our forces.";
                sAtt.crisisWarShort = "Crisis: At War";
                //Get the agents moving early, or they'll stick around doing whatever nonsense they previously were
                foreach (Unit u in units)
                {
                    if (u.society == def &&
                        u is Unit_Investigator &&
                        (((Unit_Investigator)u).state == Unit_Investigator.unitState.basic || ((Unit_Investigator)u).state == Unit_Investigator.unitState.knight) &&
                        (u.task is Task_Disrupted == false))
                    {
                        u.task = new Task_DefendHomeland();
                    }
                }
            }
            att.addHistory("We declared war on " + def.getName());
            if (def is Society)
            {
                Society sDef = (Society)def;
                sDef.crisisWarLong  = att.getName() + " has attacked us, and we are at war. We must respond to this crisis.";
                sDef.crisisWarShort = "Crisis: At War";
                //Get the agents moving early, or they'll stick around doing whatever nonsense they previously were
                foreach (Unit u in units)
                {
                    if (u.society == def &&
                        u is Unit_Investigator &&
                        (((Unit_Investigator)u).state == Unit_Investigator.unitState.basic || ((Unit_Investigator)u).state == Unit_Investigator.unitState.knight) &&
                        (u.task is Task_Disrupted == false))
                    {
                        u.task = new Task_DefendHomeland();
                    }
                }
            }
            def.addHistory(att.getName() + " declared war on us");
        }