Beispiel #1
0
 public void Init()
 {
     queueEnded   = true;
     AmbushList   = new TroopList();
     CurrentQueue = new Queue <Troop>();
     troopQueue   = new Queue <Troop>();
 }
 public override int GetCreditWithPosition(Troop source, out Point? position)
 {
     //position = 0;
     position = new Point(0, 0);
     TroopList hostileTroopsInView = source.GetHostileTroopsInView();
     TroopList list2 = new TroopList();
     foreach (Troop troop in hostileTroopsInView)
     {
         if ((troop.IsInArchitecture || !troop.DaysToReachPosition(source.Position, 1)) || (troop.Army.Kind.Type == MilitaryType.水军))
         {
             list2.Add(troop);
         }
     }
     foreach (Troop troop in list2)
     {
         hostileTroopsInView.Remove(troop);
     }
     if (hostileTroopsInView.Count == 0)
     {
         return 0;
     }
     List<Point> orientations = new List<Point>();
     int num = 0;
     foreach (Troop troop in hostileTroopsInView)
     {
         orientations.Add(troop.Position);
         num += troop.FightingForce;
     }
     int num2 = 0;
     int fightingForce = source.FightingForce;
     int num4 = source.TroopIntelligence + source.ChanceIncrementOfStratagem;
     if (num4 > 100)
     {
         num4 = 100;
     }
     num2 = (((GameObject.Square(num4) / 60) * num) / fightingForce) / 100;
     if (num2 > 0)
     {
         GameArea area = new GameArea();
         foreach (Point point in source.GetStratagemArea(source.Position).Area)
         {
             if (!source.Scenario.PositionIsOnFire(point) && (source.Scenario.IsPositionEmpty(point) && source.Scenario.IsFireVaild(point, false, MilitaryType.步兵)))
             {
                 area.Area.Add(point);
             }
         }
         if (area.Count > 0)
         {
             position = source.Scenario.GetClosestPosition(area, orientations);
         }
         else
         {
             num2 = 0;
         }
     }
     return num2;
 }
Beispiel #3
0
 public void LoadTroopsFromString(TroopList troops, string dataString)
 {
     char[]   separator = new char[] { ' ', '\n', '\r', '\t' };
     string[] strArray  = dataString.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     this.Troops.Clear();
     foreach (string str in strArray)
     {
         Troop gameObject = troops.GetGameObject(int.Parse(str)) as Troop;
         if (gameObject != null)
         {
             this.AddTroop(gameObject);
         }
     }
 }
        public MainGameScreen(MainGame game)
            : base(game)
        {
            this.Player = new WindowsMediaPlayerClass();
            this.Textures = new GameTextures();
            this.mainMapLayer = new MainMapLayer();
            this.architectureLayer = new ArchitectureLayer();
            this.mapVeilLayer = new MapVeilLayer();
            this.troopLayer = new TroopLayer();
            this.selectingLayer = new SelectingLayer();
            this.tileAnimationLayer = new TileAnimationLayer();
            this.routewayLayer = new RoutewayLayer();
            this.Plugins = new GamePlugin();
            this.SelectorTroops = new TroopList();
            this.scrollSpeedScale = 1f;
            this.scrollSpeedScaleDefault = 1f;
            this.scrollSpeedScaleSpeedy = 1.7f;
            this.oldScrollWheelValue = 0;
            this.EnableLaterMouseLeftDownEvent = true;
            this.EnableLaterMouseLeftUpEvent = true;
            this.EnableLaterMouseRightDownEvent = true;
            this.EnableLaterMouseRightUpEvent = true;
            this.EnableLaterMouseMoveEvent = true;
            this.EnableLaterMouseScrollEvent = true;
            this.frameRate = 0;
            this.frameCounter = 0;
            this.elapsedTime = TimeSpan.Zero;
            this.UpdateCount = 0;
            this.thisGame = game;
            this.screenManager = new ScreenManager(this);
            base.Scenario = new GameScenario(this);
            this.LoadCommonData();
            base.Game.Window.ClientSizeChanged += new EventHandler(this.Window_ClientSizeChanged);
            base.Game.Activated += new EventHandler(this.Game_Activated);
            base.Game.Deactivated += new EventHandler(this.Game_Deactivated);
            base.Scenario.OnAfterLoadScenario += new GameScenario.AfterLoadScenario(this.Scenario_OnAfterLoadScenario);
            base.Scenario.OnNewFactionAppear += new GameScenario.NewFactionAppear(this.Scenario_OnNewFactionAppear);
            base.Scenario.Date.OnDayStarting += new GameDate.DayStartingEvent(this.Date_OnDayStarting);
            base.Scenario.Date.OnDayPassed += new GameDate.DayPassedEvent(this.Date_OnDayPassed);
            base.Scenario.Date.OnMonthPassed += new GameDate.MonthPassedEvent(this.Date_OnMonthPassed);
            base.Scenario.Date.OnSeasonChange += new GameDate.SeasonChangeEvent(this.Date_OnSeasonChange);
            base.Scenario.Date.OnYearStarting += new GameDate.YearStartingEvent(this.Date_OnYearStarting);
            base.Scenario.Date.OnYearPassed += new GameDate.YearPassedEvent(this.Date_OnYearPassed);
            //this.Player.add_PlayStateChange(new _WMPOCXEvents_PlayStateChangeEventHandler(this.Player_PlayStateChange));
            this.Player.PlayStateChange+=(new _WMPOCXEvents_PlayStateChangeEventHandler(this.Player_PlayStateChange));
            //this.ShowyoucelanInFrame(UndoneWorkKind.Frame, FrameKind.Architecture, FrameFunction.Jump, false, true, false, false, base.Scenario.CurrentPlayer.Architectures, null, "跳转", "");


        }
Beispiel #5
0
        internal int GetLegionHostileTroopFightingForceInView()
        {
            TroopList list = new TroopList();
            int       num  = 0;

            foreach (Troop troop in this.Troops)
            {
                foreach (Troop troop2 in troop.GetHostileTroopsInView())
                {
                    if (!list.HasGameObject(troop2))
                    {
                        list.Add(troop2);
                        num += troop2.FightingForce;
                    }
                }
            }
            return(num);
        }
Beispiel #6
0
 internal int GetLegionHostileTroopFightingForceInView()
 {
     TroopList list = new TroopList();
     int num = 0;
     foreach (Troop troop in this.Troops)
     {
         foreach (Troop troop2 in troop.GetHostileTroopsInView())
         {
             if (!list.HasGameObject(troop2))
             {
                 list.Add(troop2);
                 num += troop2.FightingForce;
             }
         }
     }
     return num;
 }
Beispiel #7
0
 public TroopList GetAllOtherTroopsInView()
 {
     TroopList list = new TroopList();
     foreach (Point point in this.ViewArea.Area)
     {
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if ((troopByPosition != null) && (troopByPosition != this))
         {
             list.Add(troopByPosition);
         }
     }
     return list;
 }
 public TroopList GetFriendlyTroopsInView()
 {
     GameArea longViewArea = this.LongViewArea;
     TroopList list = new TroopList();
     foreach (Point point in longViewArea.Area)
     {
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if ((troopByPosition != null) && troopByPosition.IsFriendly(this.BelongedFaction))
         {
             list.Add(troopByPosition);
         }
     }
     return list;
 }
        public void ResetFaction(Faction faction)
        {
            Faction oldFaction = this.BelongedFaction;
            this.ResetAuto();
            this.PlanFacilityKind = null;
            this.PlanFacilityKindID = -1;
            if ((faction != null) && base.Scenario.IsPlayer(faction))
            {
                this.AutoHiring = true;
                this.AutoRewarding = true;

            }
            if (this.BelongedFaction != null && this.BelongedFaction != faction)
            {
                this.ClearFundPacks();
                this.ClearRouteways();
                this.ReleaseAllCaptive();
                this.PurifyFactionInfluences();
                if (this.BelongedSection != null)
                {
                    this.BelongedSection.RemoveArchitecture(this);
                }
                this.DefensiveLegion = null;
                if (this == this.BelongedFaction.Capital)
                {
                    Person leader = this.BelongedFaction.Leader;
                    while (this.Persons.Count > 0)
                    {
                        Person person2 = this.Persons[0] as Person;
                        person2.Status = PersonStatus.NoFaction;
                        person2.LocationArchitecture = this;
                    }
                    //this.Persons.Clear();
                    while (this.MovingPersons.Count > 0)
                    {
                        Person person2 = this.MovingPersons[0] as Person;
                        person2.OutsideTask = OutsideTaskKind.无;
                        person2.TaskDays = 0;
                        person2.Status = PersonStatus.NoFaction;

                        person2.LocationArchitecture = this;
                        person2.TargetArchitecture = null;

                    }

                    //if ((leader.LocationTroop == null) || leader.IsCaptive)
                    {
                        TroopList list = new TroopList();
                        foreach (Troop troop in this.BelongedFaction.Troops)
                        {
                            list.Add(troop);
                        }
                        foreach (Troop troop in list)
                        {
                            troop.FactionDestroy();
                        }
                        if (faction != null)
                        {
                            faction.CheckLeaderDeath(leader);
                        }
                        this.BelongedFaction.Destroy();

                    }
                    this.BelongedFaction.Capital = null;
                }
                else
                {
                    while (this.Persons.Count > 0)
                    {
                        if ((this.Persons[0] as Person).LocationArchitecture != null)
                        {
                            (this.Persons[0] as Person).MoveToArchitecture(this.BelongedFaction.Capital);
                        }
                    }
                    while (this.MovingPersons.Count > 0)
                    {
                        if ((this.MovingPersons[0] as Person).LocationArchitecture != null)
                        {
                            (this.MovingPersons[0] as Person).MoveToArchitecture(this.BelongedFaction.Capital);
                        }
                    }
                }
                if (this.BelongedFaction != null)
                {
                    this.BelongedFaction.RemoveArchitectureMilitaries(this);
                    this.BelongedFaction.RemoveArchitectureKnownData(this);
                    this.BelongedFaction.RemoveArchitecture(this);
                }
                if (faction != null)
                {
                    faction.AddArchitecture(this);
                    this.ApplyFactionInfluences();
                    faction.AddArchitectureMilitaries(this);
                }
                else
                {
                    this.BelongedFaction = null;
                }
            }
            else if (faction != null)
            {
                faction.AddArchitecture(this);
                this.ApplyFactionInfluences();
                faction.AddArchitectureMilitaries(this);
            }

            if (faction != null)
            {
                //this.jianzhuqizi.qizidezi.Text = faction.ToString().Substring(0, 1);
            }

            foreach (Architecture architecture in base.Scenario.Architectures)
            {
                architecture.RefreshViewArea();
            }
            foreach (Troop troop in base.Scenario.Troops)
            {
                troop.RefreshViewArchitectureRelatedArea();
            }
            foreach (LinkNode i in this.AIAllLinkNodes.Values)
            {
                i.A.CheckIsFrontLine();
            }
            this.CheckIsFrontLine();
            ExtensionInterface.call("ArchitectureResetFaction", new Object[] { this.Scenario, this, oldFaction });
        }
 private void DefensiveCampaign()
 {
     if ((this.HasPerson() && this.HasCampaignableMilitary()) && (this.GetAllAvailableArea(false).Count != 0))
     {
         TroopList hostileTroopsInView = this.GetHostileTroopsInView();
         if (hostileTroopsInView.Count > 0)
         {
             List<Point> orientations = new List<Point>();
             foreach (Troop troop in hostileTroopsInView)
             {
                 orientations.Add(troop.Position);
             }
             TroopList friendlyTroopsInView = this.GetFriendlyTroopsInView();
             int num = 0;
             int militaryCount = this.MilitaryCount;
             while ((num < militaryCount) && (this.TotalFriendlyForce < (this.TotalHostileForce * 5)))
             {
                 Troop troop2;
                 num++;
                 int num3 = (this.TotalHostileForce * 5) - this.TotalFriendlyForce;
                 TroopList list4 = new TroopList();
                 bool isBesideWater = this.IsBesideWater;
             //Label_033D:
                 foreach (Military military in this.Militaries.GetRandomList())
                 {
                     if ((isBesideWater || (military.Kind.Type != MilitaryType.水军)) && (((((this.Endurance < 30) || military.Kind.AirOffence) || (military.Scales >= 2)) && (military.Morale > 0x2d)) && ((this.Endurance < 30) || (military.InjuryQuantity < military.Kind.MinScale))))
                     {
                         PersonList list5;
                         if ((military.FollowedLeader != null) && this.Persons.HasGameObject(military.FollowedLeader))
                         {
                             list5 = new PersonList();
                             list5.Add(military.FollowedLeader);
                             military.FollowedLeader.Selected = true;
                             troop2 = Troop.CreateSimulateTroop(list5, military, this.Position);
                             list4.Add(troop2);
                         }
                         else
                         {
                             if ((((military.Leader != null) && (military.LeaderExperience >= 200)) && (((military.Leader.Strength >= 80) || (military.Leader.Command >= 80)) || military.Leader.HasLeaderValidCombatTitle)) && this.Persons.HasGameObject(military.Leader))
                             {
                                 list5 = new PersonList();
                                 list5.Add(military.Leader);
                                 military.Leader.Selected = true;
                                 troop2 = Troop.CreateSimulateTroop(list5, military, this.Position);
                                 list4.Add(troop2);
                                 //goto Label_033D;
                                 continue;
                             }
                             foreach (Person person in this.Persons)
                             {
                                 if (!person.Selected)
                                 {
                                     list5 = new PersonList();
                                     list5.Add(person);
                                     troop2 = Troop.CreateSimulateTroop(list5, military, this.Position);
                                     list4.Add(troop2);
                                 }
                             }
                         }
                     }
                 }
                 if (list4.Count <= 0)
                 {
                     break;
                 }
                 list4.IsNumber = true;
                 list4.PropertyName = "FightingForce";
                 list4.ReSort();
                 foreach (Troop troop in list4.GetList())
                 {
                     if (((troop.FightingForce < 0x2710) && (troop.FightingForce < (num3 / 0x19))) && (troop.Army.Scales < 10))
                     {
                         return;
                     }
                     Point? nullable = this.GetCampaignPosition(troop, orientations, troop.Army.Scales > 0);
                     if (!nullable.HasValue)
                     {
                         return;
                     }
                     if (troop.Army.Kind.AirOffence && (troop.Army.Scales < 2))
                     {
                         Architecture architectureByPositionNoCheck = base.Scenario.GetArchitectureByPositionNoCheck(nullable.Value);
                         if ((architectureByPositionNoCheck == null) || (architectureByPositionNoCheck.Endurance == 0))
                         {
                             continue;
                         }
                     }
                     Person leader = troop.Persons[0] as Person;
                     this.AddPersonToTroop(troop);
                     troop2 = this.CreateTroop(troop.Persons, leader, troop.Army, -1, nullable.Value);
                     troop2.WillArchitecture = this;
                     if (this.DefensiveLegion == null)
                     {
                         this.CreateDefensiveLegion();
                     }
                     this.DefensiveLegion.AddTroop(troop2);
                     this.PostCreateTroop(troop2, false);
                     this.TotalFriendlyForce += troop2.FightingForce;
                     break;
                 }
                 if (!(this.HasCampaignableMilitary() && this.HasPerson()))
                 {
                     break;
                 }
             }
         }
     }
 }
        private Troop BuildTroopForTransfer(Military military, Architecture destination, LinkKind linkkind)
        {
            if (linkkind == LinkKind.None)
            {
                return null;
            }
            if (!this.isArmyNavigableTo(linkkind, military))
            {
                return null;
            }
            if (this.Persons.Count == 0) return null;
            TroopList list = new TroopList();
            this.Persons.ClearSelected();
            if ((military.Scales > 5) && (military.Morale >= 80) && (military.Combativity >= 80) && (military.InjuryQuantity < military.Kind.MinScale) && !military.IsFewScaleNeedRetreat)
            {
                PersonList list2;
                Military military2 = military;
                if ((military2.FollowedLeader != null) && this.Persons.HasGameObject(military2.FollowedLeader) && military2.FollowedLeader.WaitForFeiZi == null && military2.FollowedLeader.LocationTroop == null)
                {
                    list2 = new PersonList();
                    list2.Add(military2.FollowedLeader);
                    military2.FollowedLeader.Selected = true;
                    Point? nullable = this.GetRandomStartingPosition(military2);
                    if (!nullable.HasValue)
                    {
                        return null;
                    }

                    Troop troop = this.CreateTroop(list2, military2.FollowedLeader, military2, -1, nullable.Value);
                    troop.WillArchitecture = destination;
                    Legion legion = this.BelongedFaction.GetLegion(destination);
                    if (legion == null)
                    {
                        legion = this.CreateOffensiveLegion(destination);
                    }
                    legion.AddTroop(troop);
                    return troop;
                }
                if ((((military2.Leader != null) && (military2.LeaderExperience >= 10)) && (((military2.Leader.Strength >= 80) || (military2.Leader.Command >= 80)) || military2.Leader.HasLeaderValidTitle))
                    && this.Persons.HasGameObject(military2.Leader) && military2.Leader.WaitForFeiZi == null && military2.Leader.LocationTroop == null)
                {
                    list2 = new PersonList();
                    list2.Add(military2.Leader);
                    military2.Leader.Selected = true;
                    Point? nullable = this.GetRandomStartingPosition(military2);
                    if (!nullable.HasValue)
                    {
                        return null;
                    }
                    Troop troop = this.CreateTroop(list2, military2.Leader, military2, -1, nullable.Value);
                    troop.WillArchitecture = destination;
                    Legion legion = this.BelongedFaction.GetLegion(destination);
                    if (legion == null)
                    {
                        legion = this.CreateOffensiveLegion(destination);
                    }
                    legion.AddTroop(troop);
                    return troop;
                }
                GameObjectList sortedList = this.Persons.GetList() as GameObjectList;
                sortedList.PropertyName = "FightingForce";
                sortedList.IsNumber = true;
                sortedList.SmallToBig = true;
                sortedList.ReSort();
                foreach (Person person in sortedList)
                {
                    if (!person.Selected && person.WaitForFeiZi == null && person.LocationTroop == null)
                    {
                        list2 = new PersonList();
                        list2.Add(person);
                        person.Selected = true;
                        Point? nullable = this.GetRandomStartingPosition(military2);
                        if (!nullable.HasValue)
                        {
                            break;
                        }
                        Troop troop = this.CreateTroop(list2, person, military2, -1, nullable.Value);
                        troop.WillArchitecture = destination;
                        Legion legion = this.BelongedFaction.GetLegion(destination);
                        if (legion == null)
                        {
                            legion = this.CreateOffensiveLegion(destination);
                        }
                        legion.AddTroop(troop);
                        return troop;
                    }
                }
            }
            return null;
        }
Beispiel #12
0
        public void ApplyEventEffects(Troop self)
        {
            if (((self != null) && !self.Destroyed) && (!this.Happened || this.Repeatable))
            {
                Troop troopByPositionNoCheck;
                this.Happened = true;
                TroopList list = new TroopList();
                if (this.SelfEffects.Count > 0)
                {
                    list.Add(self);
                    foreach (GameObjects.TroopDetail.EventEffect.EventEffect effect in this.SelfEffects)
                    {
                        effect.ApplyEffect(self.Leader);
                    }
                }
                foreach (TroopEffectPerson person in this.EffectPersons)
                {
                    person.Effect.ApplyEffect(person.EffectPerson);
                    if ((person.EffectPerson.LocationTroop != null) && (list.GetGameObject(person.EffectPerson.LocationTroop.ID) == null))
                    {
                        list.Add(person.EffectPerson.LocationTroop);
                    }
                }
                List <TroopEffectArea> list2 = new List <TroopEffectArea>();
                List <TroopEffectArea> list3 = new List <TroopEffectArea>();
                List <TroopEffectArea> list4 = new List <TroopEffectArea>();
                foreach (TroopEffectArea area in this.EffectAreas)
                {
                    switch (area.Kind)
                    {
                    case EffectAreaKind.视野敌军:
                        list2.Add(area);
                        break;

                    case EffectAreaKind.视野友军:
                        list2.Add(area);
                        break;

                    case EffectAreaKind.八格敌军:
                        list3.Add(area);
                        break;

                    case EffectAreaKind.八格友军:
                        list3.Add(area);
                        break;

                    case EffectAreaKind.攻击范围敌军:
                        list4.Add(area);
                        break;

                    case EffectAreaKind.攻击范围友军:
                        list4.Add(area);
                        break;
                    }
                }
                foreach (TroopEffectArea area in list2)
                {
                    foreach (Point point in self.BaseViewArea.Area)
                    {
                        if (self.BelongedFaction.IsPositionKnown(point))
                        {
                            troopByPositionNoCheck = Session.Current.Scenario.GetTroopByPositionNoCheck(point);
                            if (troopByPositionNoCheck != null)
                            {
                                switch (area.Kind)
                                {
                                case EffectAreaKind.视野敌军:
                                    if (!self.IsFriendly(troopByPositionNoCheck.BelongedFaction))
                                    {
                                        area.Effect.ApplyEffect(troopByPositionNoCheck.Leader);
                                    }
                                    break;

                                case EffectAreaKind.视野友军:
                                    if (self.IsFriendly(troopByPositionNoCheck.BelongedFaction))
                                    {
                                        area.Effect.ApplyEffect(troopByPositionNoCheck.Leader);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                foreach (TroopEffectArea area in list3)
                {
                    foreach (Point point in GameArea.GetArea(self.Position, 1, true).Area)
                    {
                        if (self.BelongedFaction.IsPositionKnown(point))
                        {
                            troopByPositionNoCheck = Session.Current.Scenario.GetTroopByPositionNoCheck(point);
                            if (troopByPositionNoCheck != null)
                            {
                                switch (area.Kind)
                                {
                                case EffectAreaKind.八格敌军:
                                    if (!self.IsFriendly(troopByPositionNoCheck.BelongedFaction))
                                    {
                                        area.Effect.ApplyEffect(troopByPositionNoCheck.Leader);
                                    }
                                    break;

                                case EffectAreaKind.八格友军:
                                    if (self.IsFriendly(troopByPositionNoCheck.BelongedFaction))
                                    {
                                        area.Effect.ApplyEffect(troopByPositionNoCheck.Leader);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                foreach (TroopEffectArea area in list4)
                {
                    //Label_0539:
                    foreach (Point point in self.OffenceArea.Area)
                    {
                        if (!self.BelongedFaction.IsPositionKnown(point))
                        {
                            continue;
                        }
                        troopByPositionNoCheck = Session.Current.Scenario.GetTroopByPositionNoCheck(point);
                        if (troopByPositionNoCheck != null)
                        {
                            switch (area.Kind)
                            {
                            case EffectAreaKind.攻击范围敌军:
                                if (!self.IsFriendly(troopByPositionNoCheck.BelongedFaction))
                                {
                                    area.Effect.ApplyEffect(troopByPositionNoCheck.Leader);
                                }
                                break;

                            case EffectAreaKind.攻击范围友军:
                                if (self.IsFriendly(troopByPositionNoCheck.BelongedFaction))
                                {
                                    area.Effect.ApplyEffect(troopByPositionNoCheck.Leader);
                                }
                                break;
                            }
                        }
                    }
                }
                foreach (Troop troop in list)
                {
                    Troop.CheckTroopRout(troop);
                }
            }
        }
        public void ResetFaction(Faction faction)
        {
            this.ResetAuto();
            if ((faction != null) && base.Scenario.IsPlayer(faction))
            {
                this.AutoHiring = true;
                this.AutoRewarding = true;

            }
            if (this.BelongedFaction != null)
            {

                this.ClearFundPacks();
                this.ClearRouteways();
                this.ReleaseAllCaptive();
                this.BelongedSection.RemoveArchitecture(this);
                this.DefensiveLegion = null;
                if (this == this.BelongedFaction.Capital)
                {
                    Person leader = this.BelongedFaction.Leader;
                    foreach (Person person2 in this.Persons)
                    {
                        this.BelongedFaction.RemovePerson(person2);
                        this.AddNoFactionPerson(person2);
                    }
                    this.Persons.Clear();
                    foreach (Person person2 in this.MovingPersons)
                    {
                        person2.OutsideTask = OutsideTaskKind.无;
                        person2.TaskDays = 0;
                        if (person2.BelongedFaction != null)
                        {
                            person2.BelongedFaction.RemovePerson(person2);
                        }
                    }
                    this.MovingPersons.Clear();
                    if ((leader.LocationTroop == null) || leader.IsCaptive)
                    {
                        TroopList list = new TroopList();
                        foreach (Troop troop in this.BelongedFaction.Troops)
                        {
                            list.Add(troop);
                        }
                        foreach (Troop troop in list)
                        {
                            troop.FactionDestroy();
                        }
                        this.BelongedFaction.Destroy();
                        if (faction != null)
                        {
                            faction.CheckLeaderDeath(leader);
                        }
                    }
                    this.BelongedFaction.Capital = null;
                }
                else
                {
                    PersonList list2 = new PersonList();
                    foreach (Person person2 in this.Persons)
                    {
                        person2.MoveToArchitecture(this.BelongedFaction.Capital);
                        list2.Add(person2);
                    }
                    foreach (Person person2 in list2)
                    {
                        this.RemovePerson(person2);
                    }
                    foreach (Person person2 in this.MovingPersons)
                    {
                        person2.MoveToArchitecture(this.BelongedFaction.Capital);
                    }
                    this.MovingPersons.Clear();
                }
                if (this.BelongedFaction != null)
                {
                    this.BelongedFaction.RemoveArchitectureMilitaries(this);
                    this.BelongedFaction.RemoveArchitectureKnownData(this);
                    this.BelongedFaction.RemoveArchitecture(this);
                }
                if (faction != null)
                {
                    faction.AddArchitecture(this);
                    faction.AddArchitectureMilitaries(this);
                    faction.AddArchitecturePersons(this);
                }
                else
                {
                    this.BelongedFaction = null;
                }
            }
            else if (faction != null)
            {
                faction.AddArchitecture(this);
                faction.AddArchitectureMilitaries(this);
            }

            if (faction != null)
            {
                this.jianzhuqizi.qizidezi.Text = faction.ToString().Substring(0, 1);
            }

            foreach (Architecture architecture in base.Scenario.Architectures)
            {
                architecture.RefreshViewArea();
            }
            foreach (Troop troop in base.Scenario.Troops)
            {
                troop.RefreshViewArchitectureRelatedArea();
            }
        }
Beispiel #14
0
 public void BeRouted()
 {
     if (this.BelongedFaction == null)
     {
         this.Destroy(true, true);
         if (this.StartingArchitecture != null && this.StartingArchitecture.RobberTroop == this)  //盗贼队
         {
             this.StartingArchitecture.RobberTroop = null;
             this.StartingArchitecture.RobberTroopID = -1;
         }
         if (this.OrientationTroop != null)
         {
             this.OrientationTroop.OperationDone = !this.OrientationTroop.CanAttackAfterRout;
         }
     }
     else
     {
         if (this.IsTransport && this.WillArchitecture != null)
         {
             this.WillArchitecture.SuspendTroopTransfer = 0;
         }
         bool flag = false;
         if ((this.BelongedFaction.Leader == this.Leader) && (this.BelongedFaction.ArchitectureCount == 0))
         {
             //flag = true;
         }
         Faction f = this.BelongedFaction;
         this.Destroy(true, true);
         foreach (Person p in this.persons)
         {
             foreach (Person q in this.persons)
             {
                 if (p == q) continue;
                 p.AdjustRelation(q, -0.5f / (this.persons.Count - 1), -3);
             }
         }
         foreach (Person person in this.persons)
         {
             Point from = this.Position;
             if ((this.StartingArchitecture == null) || (f != this.StartingArchitecture.BelongedFaction))
             {
                 if (f.Capital != null)
                 {
                     this.StartingArchitecture = f.Capital;
                 }
             }
             if (this.StartingArchitecture != null)
             {
                 person.LocationArchitecture = this.StartingArchitecture;
                 person.MoveToArchitecture(this.StartingArchitecture, from);
             }
             person.LocationTroop = null;
         }
         this.persons.Clear();
         if (flag)
         {
             TroopList list = new TroopList();
             foreach (Troop troop in this.BelongedFaction.Troops)
             {
                 if (troop != this)
                 {
                     list.Add(troop);
                 }
             }
             foreach (Troop troop in list)
             {
                 troop.FactionDestroy();
             }
             this.BelongedFaction.Destroy();
         }
         if ((this.OrientationTroop != null) && !this.ProhibitAllAction)
         {
             this.OrientationTroop.OperationDone = !this.OrientationTroop.CanAttackAfterRout && !this.OrientationTroop.StuntCanAttackAfterRout;
             if (!(this.OrientationTroop.OperationDone || this.OrientationTroop.QueueEnded))
             {
                 this.OrientationTroop.AttackedTroopList.Clear();
             }
         }
     }
     ExtensionInterface.call("BeRouted", new Object[] { this.Scenario, this });
 }
Beispiel #15
0
 private TroopList GetAllOffenceAreaTroops(Point position)
 {
     TroopList list = new TroopList();
     foreach (Point point in this.GetOffenceArea(position).Area)
     {
         if ((this.BelongedFaction == null) || this.BelongedFaction.IsPositionKnown(point))
         {
             Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
             if (troopByPosition != null)
             {
                 list.Add(troopByPosition);
             }
         }
     }
     return list;
 }
Beispiel #16
0
 public void DayEvent()
 {
     if (this.BelongedFaction != null)
     {
         this.ViewingWillArchitecture = this.IsViewingWillArchitecture();
         this.ContactingWillArchitecture = this.IsContactingWillArchitecture();
         this.OffencingWillArchitecture = this.IsOffencingWillArchitecture();
         this.ContactHostileTroopCount = this.GetContactHostileTroops().Count;
         this.ContactFriendlyTroopCount = this.GetContactFriendlyTroops().Count;
         this.SetFriendlyTroopsInView();
         this.SetHostileTroopsInView();
     }
     if (this.StartingArchitecture != null)
     {
     }
     if ((this.IncrementPerDayOfCombativity + this.CombativityIncrementPerDayByViewArea) > 0)
     {
         this.IncreaseCombativity(this.IncrementPerDayOfCombativity + this.CombativityIncrementPerDayByViewArea);
     }
     if ((this.DecrementPerDayOfCombativity + this.CombativityDecrementPerDayByViewArea) > 0)
     {
         this.DecreaseCombativity(this.DecrementPerDayOfCombativity + this.CombativityDecrementPerDayByViewArea);
     }
     if ((this.InjuryRecoveryPerDayRate > 0f) && (this.InjuryQuantity > 0))
     {
         int number = this.Army.Recovery(this.InjuryRecoveryPerDayRate);
         if (number > 0)
         {
             this.RefreshOffence();
             this.RefreshDefence();
             this.IncrementNumberList.AddNumber(number, CombatNumberKind.人数, this.Position);
             this.ShowNumber = true;
         }
     }
     if (this.ChaosDayLeft > 0)
     {
         this.ChaosDayLeft--;
         if ((this.ChaosDayLeft == 0) || this.StuntRecoverFromChaos)
         {
             this.SetRecoverFromChaos();
         }
     }
     if (base.Scenario.FireTable.HasPosition(this.Position))
     {
         this.SetOnFire(Parameters.FireDamageScale * base.Scenario.GetTerrainDetailByPositionNoCheck(this.Position).FireDamageRate);
     }
     if (this.CutRoutewayDays > 0)
     {
         this.CutRoutewayDays--;
         if (this.CutRoutewayDays == 0)
         {
             this.CutPositionRouteway();
         }
         else if (this.CheckPositionRouteway())
         {
             this.Controllable = false;
             this.Operated = true;
         }
         else
         {
             this.CutRoutewayDays = 0;
             if (this.OnEndCutRouteway != null)
             {
                 this.OnEndCutRouteway(this, false);
             }
         }
     }
     if (this.Food >= this.FoodCostPerDay)
     {
         this.Food -= this.FoodCostPerDay;
         this.RefillFoodByArchitecture();
         this.RefillFoodByRouteway();
     }
     else
     {
         this.RefillFoodByArchitecture();
         this.RefillFoodByRouteway();
         if (this.Food < this.FoodCostPerDay)
         {
             this.Food = 0;
             if (this.RecentlyFighting > 0)
             {
                 this.DecreaseCombativity(10);
                 this.DecreaseMorale((int) (10f * this.MoraleChangeRateOnOutOfFood));
             }
             else
             {
                 this.DecreaseCombativity(5);
                 this.DecreaseMorale(5);
             }
             CheckTroopRout(this);
         }
         else
         {
             this.Food -= this.FoodCostPerDay;
         }
     }
     if (this.BelongedFaction != null)
     {
         foreach (TroopEvent event2 in base.Scenario.TroopEvents.GetRandomList())
         {
             if (event2.CheckTroop(this))
             {
                 event2.ApplyEventDialogs(this);
                 TroopList list = null;
                 if (base.Scenario.TroopEventsToApply.TryGetValue(event2, out list))
                 {
                     list.Add(this);
                 }
                 else
                 {
                     list = new TroopList();
                     list.Add(this);
                     base.Scenario.TroopEventsToApply.Add(event2, list);
                 }
             }
         }
     }
     if ((this.CurrentStunt != null) && (this.StuntDayLeft > 0))
     {
         this.StuntDayLeft--;
         if (this.StuntDayLeft == 0)
         {
             this.CurrentStunt.Purify(this);
             this.CurrentStunt = null;
             this.RefreshAllData();
         }
     }
     this.ResetDayInfluence();
 }
Beispiel #17
0
 public void BeRouted()
 {
     if (this.BelongedFaction == null)
     {
         this.Destroy();
         base.Scenario.Militaries.Remove(this.Army);
         base.Scenario.Troops.RemoveTroop(this);
         if ((this.StartingArchitecture != null) && (this.StartingArchitecture.RobberTroop == this))
         {
             this.StartingArchitecture.RobberTroop = null;
         }
         if (this.OrientationTroop != null)
         {
             this.OrientationTroop.OperationDone = !this.OrientationTroop.CanAttackAfterRout;
         }
     }
     else
     {
         bool flag = false;
         if ((this.BelongedFaction.Leader == this.Leader) && (this.BelongedFaction.ArchitectureCount == 0))
         {
             flag = true;
         }
         foreach (Person person in this.Persons)
         {
             if ((this.StartingArchitecture == null) || (this.BelongedFaction != this.StartingArchitecture.BelongedFaction))
             {
                 if (this.BelongedFaction.Capital != null)
                 {
                     this.StartingArchitecture = this.BelongedFaction.Capital;
                 }
                 else
                 {
                     this.BelongedFaction.RemovePerson(person);
                 }
             }
             if (this.StartingArchitecture != null)
             {
                 person.MoveToArchitecture(this.StartingArchitecture);
             }
             else if (base.Scenario.Architectures.Count > 0)
             {
                 person.MoveToArchitecture(base.Scenario.Architectures[0] as Architecture);
             }
             person.LocationTroop = null;
         }
         this.Destroy();
         this.BelongedLegion.RemoveTroop(this);
         if (this.Army.ShelledMilitary == null)
         {
             this.BelongedFaction.RemoveMilitary(this.Army);
         }
         else
         {
             this.BelongedFaction.RemoveMilitary(this.Army.ShelledMilitary);
             base.Scenario.Militaries.Remove(this.Army.ShelledMilitary);
         }
         base.Scenario.Militaries.Remove(this.Army);
         if (flag)
         {
             TroopList list = new TroopList();
             foreach (Troop troop in this.BelongedFaction.Troops)
             {
                 if (troop != this)
                 {
                     list.Add(troop);
                 }
             }
             foreach (Troop troop in list)
             {
                 troop.FactionDestroy();
             }
             this.BelongedFaction.Destroy();
         }
         else
         {
             this.BelongedFaction.RemoveTroop(this);
         }
         base.Scenario.Troops.RemoveTroop(this);
         if ((this.OrientationTroop != null) && !this.ProhibitAllAction)
         {
             this.OrientationTroop.OperationDone = !this.OrientationTroop.CanAttackAfterRout && !this.OrientationTroop.StuntCanAttackAfterRout;
             if (!(this.OrientationTroop.OperationDone || this.OrientationTroop.QueueEnded))
             {
                 this.OrientationTroop.AttackedTroopList.Clear();
             }
         }
     }
 }
Beispiel #18
0
        public void DayEvent()
        {
            if (!GameObject.Chance(this.chanceTirednessStopIncrease))
            {
                this.Army.Tiredness += GlobalVariables.TirednessIncrease;
            }
            foreach (Person p in this.Persons)
            {
                if (!GameObject.Chance(p.chanceTirednessStopIncrease) && !GameObject.Chance(this.chanceTirednessStopIncrease))
                {
                    p.Tiredness += GlobalVariables.TirednessIncrease;
                }
            }

            if (this.BelongedFaction != null)
            {
                this.ViewingWillArchitecture = this.IsViewingWillArchitecture();
                this.ContactingWillArchitecture = this.IsContactingWillArchitecture();
                this.OffencingWillArchitecture = this.IsOffencingWillArchitecture();
                this.ContactHostileTroopCount = this.GetContactHostileTroops().Count;
                this.ContactFriendlyTroopCount = this.GetContactFriendlyTroops().Count;
                this.SetFriendlyTroopsInView();
                this.SetHostileTroopsInView();
            }
            if (this.StartingArchitecture != null)
            {
            }
            if ((this.IncrementPerDayOfCombativity + this.CombativityIncrementPerDayByViewArea) > 0)
            {
                this.IncreaseCombativity(this.IncrementPerDayOfCombativity + this.CombativityIncrementPerDayByViewArea);
            }
            if ((this.DecrementPerDayOfCombativity + this.CombativityDecrementPerDayByViewArea) > 0)
            {
                this.DecreaseCombativity(this.DecrementPerDayOfCombativity + this.CombativityDecrementPerDayByViewArea);
            }
            if ((this.InjuryRecoveryPerDayRate > 0f) && (this.InjuryQuantity > 0))
            {
                int number = this.Army.Recovery(this.InjuryRecoveryPerDayRate);
                if (number > 0)
                {
                    this.RefreshOffence();
                    this.RefreshDefence();
                    this.IncrementNumberList.AddNumber(number, CombatNumberKind.人数, this.Position);
                    this.ShowNumber = true;
                }
            }
            if (this.ChaosDayLeft > 0)
            {
                this.ChaosDayLeft--;
                if ((this.ChaosDayLeft == 0) || this.StuntRecoverFromChaos)
                {
                    this.SetRecoverFromChaos();
                }
            }
            if (base.Scenario.FireTable.HasPosition(this.Position))
            {
                this.SetOnFire(Parameters.FireDamageScale * base.Scenario.GetTerrainDetailByPositionNoCheck(this.Position).FireDamageRate);
            }
            if (this.CutRoutewayDays > 0)
            {
                this.CutRoutewayDays--;
                if (this.CutRoutewayDays == 0)
                {
                    this.CutPositionRouteway();
                }
                else if (this.CheckPositionRouteway())
                {
                    this.Controllable = false;
                    this.Operated = true;
                }
                else
                {
                    this.CutRoutewayDays = 0;
                    if (this.OnEndCutRouteway != null)
                    {
                        this.OnEndCutRouteway(this, false);
                    }
                }
            }
            if (this.Food >= this.FoodCostPerDay)
            {
                this.Food -= this.FoodCostPerDay;
                this.RefillFood();

            }
            else
            {
                this.RefillFood();

                if (this.Food < this.FoodCostPerDay)
                {
                    this.Food = 0;
                    if (this.RecentlyFighting > 0)
                    {
                        this.DecreaseCombativity(10);
                        this.DecreaseMorale((int)(10f * this.MoraleChangeRateOnOutOfFood));
                    }
                    else
                    {
                        this.DecreaseCombativity(5);
                        this.DecreaseMorale(5);
                    }
                    CheckTroopRout(this);
                }
                else
                {
                    this.Food -= this.FoodCostPerDay;
                }
            }
            if (this.BelongedFaction != null)
            {
                foreach (TroopEvent event2 in base.Scenario.TroopEvents.GetList())
                {
                    if (event2.CheckTroop(this))
                    {
                        TroopList list = null;
                        if (base.Scenario.TroopEventsToApply.TryGetValue(event2, out list))
                        {
                            list.Add(this);
                        }
                        else
                        {
                            list = new TroopList();
                            list.Add(this);
                            base.Scenario.TroopEventsToApply.Add(event2, list);
                        }
                        event2.ApplyEventDialogs(this);
                    }
                }
            }
            if ((this.CurrentStunt != null) && (this.StuntDayLeft > 0))
            {
                this.StuntDayLeft--;
                if (this.StuntDayLeft == 0)
                {
                    this.CurrentStunt.Purify(this);
                    this.CurrentStunt = null;
                    this.RefreshAllData();
                }
            }

            if (base.Scenario.IsPlayer(this.BelongedFaction) && this.TargetTroop == null && this.TargetArchitecture == null
                && this.Position.Equals(this.Destination)
                && this.Status == TroopStatus.一般 && this.WillArchitecture == this.StartingArchitecture
                && !this.HasHostileTroopInView() && !this.HasHostileArchitectureInView()
                && this.mingling != "移动" && this.mingling != "待命")
            {
                this.minglingweizhi = this.Destination = base.Scenario.GetClosestPoint(this.StartingArchitecture.ArchitectureArea, this.Position);
                this.mingling = "入城";
                this.TargetArchitecture = this.StartingArchitecture;
            }

            this.ResetDayInfluence();
        }
 private TroopList AISelectPersonIntoTroop(Architecture from, Military military)
 {
     TroopList result = new TroopList();
     if ((military.FollowedLeader != null) && from.Persons.HasGameObject(military.FollowedLeader) && military.FollowedLeader.LocationTroop == null)
     {
         result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(military.FollowedLeader, from.Persons, true), military, from.Position));
     }
     else if ((((military.Leader != null) && (military.LeaderExperience >= 10)) && (((military.Leader.Strength >= 80) || (military.Leader.Command >= 80)) || military.Leader.HasLeaderValidCombatTitle))
         && from.Persons.HasGameObject(military.Leader) && military.Leader.LocationTroop == null)
     {
         result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(military.Leader, from.Persons, true), military, from.Position));
     }
     else
     {
         foreach (Person person in from.Persons)
         {
             if (!person.Selected)
             {
                 if ((this.BelongedFaction.AvailableMilitaryKinds.GetMilitaryKindList().GameObjects.Contains(military.Kind) && !military.Kind.Unique) ||
                     person.FightingForce >= Parameters.AIUniqueTroopFightingForceThreshold || this.Endurance < 30)
                 {
                     result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(person, from.Persons, false), military, from.Position));
                 }
             }
         }
     }
     return result;
 }
Beispiel #20
0
 private TroopList GetAreaAttackTroops(Point centre, int radius, bool oblique)
 {
     GameArea area = GameArea.GetViewArea(centre, radius, oblique, base.Scenario, null);
     TroopList list = new TroopList();
     foreach (Point point in area.Area)
     {
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if (troopByPosition != null)
         {
             list.Add(troopByPosition);
         }
     }
     return list;
 }
        public void CurrentQueueTroopMove()
        {
            
            if (this.CurrentTroop != null)
            {

                this.TroopMoveThread(this.CurrentTroop);
                /*Thread thread;
                
                thread = new Thread(new ThreadStart(this.CurrentTroop.Move));
                thread.Start();
                thread.Join();*/
                
                if (this.CurrentTroop.StepNotFinished || (this.CurrentTroop.MovabilityLeft <= 0))
                {
                    if (!this.CurrentTroop.OperationDone)
                    {
                        this.troopQueue.Enqueue(this.CurrentTroop);
                    }
                    this.CurrentTroop = null;
                }
            }
            else if (!this.CheckAmbushList())
            {
                Queue<Troop> queue = new Queue<Troop>();
                if ((this.CurrentQueue.Count == 0) && (this.troopQueue.Count > 0))
                {
                    this.CurrentQueue.Enqueue(this.troopQueue.Dequeue());
                }
                while (this.CurrentQueue.Count > 0)
                {
                    Troop item = this.CurrentQueue.Dequeue();
                    if (!item.Destroyed)
                    {
                        if (item.mingling == "待命")
                        {
                            item.OperationDone = true;
                            break;
                        }

                        if (item.Destroyed || 
                            (item.Status != TroopStatus.一般 && item.Status != TroopStatus.伪报 && item.Status != TroopStatus.挑衅))
                        {
                            item.MovabilityLeft = -1;
                            item.OperationDone = true;
                        }

                        if (item.Scenario.IsPlayer(item.BelongedFaction))
                        {
                            if (!(item.HasToDoCombatAction || !item.ToDoCombatAction()))
                            {
                                item.HasToDoCombatAction = true;
                                this.CurrentQueue.Enqueue(item);
                                break;
                            }
                            if (item.HasToDoCombatAction)
                            {
                                item.HasToDoCombatAction = false;
                                item.DoCombatAction();
                                this.CurrentQueue.Enqueue(item);
                                break;
                            }
                            if (this.troopQueue.Count > 0)
                            {
                                this.CurrentQueue.Enqueue(this.troopQueue.Dequeue());
                            }

                            if (item.MovabilityLeft > 0)
                            {
                                this.TroopChangeRealDestination(item);
                                this.TroopMoveThread(item);
                            }
                        }
                        else
                        {
                            if (item.MovabilityLeft > 0)
                            {
                                this.TroopChangeRealDestination(item);
                                this.TroopMoveThread(item);
                            }

                            if (item.MovabilityLeft <= 0)
                            {
                                if (!item.HasToDoCombatAction && item.ToDoCombatAction())
                                {
                                    item.HasToDoCombatAction = true;
                                    this.CurrentQueue.Enqueue(item);
                                    break;
                                }
                                if (item.HasToDoCombatAction)
                                {
                                    item.HasToDoCombatAction = false;
                                    item.DoCombatAction();
                                    this.CurrentQueue.Enqueue(item);
                                    break;
                                }
                            }
                        }

                        if (item.Destroyed ||
                            (item.Status != TroopStatus.一般 && item.Status != TroopStatus.伪报 && item.Status != TroopStatus.挑衅))
                        {
                            item.MovabilityLeft = -1;
                            item.OperationDone = true;
                        }
                       
                        if ((!item.OperationDone && item.OffenceOnlyBeforeMove) && (item.Position != item.PreviousPosition))
                        {
                            item.OperationDone = true;
                        }
                        if ((!item.StepNotFinished || item.chongshemubiaoweizhibiaoji) && item.MovabilityLeft >= 0)
                        {
                            this.CurrentTroop = item;
                            break;
                        }
                        if (!this.queueEnded)
                        {
                            if (item.MovabilityLeft > 0)
                            {
                                item.WaitOnce = true;
                                queue.Enqueue(item);
                            }
                            else if (!(item.OperationDone || item.QueueEnded))
                            {
                                queue.Enqueue(item);
                            }
                        }
                    }
                }
                while (queue.Count > 0)
                {
                    this.troopQueue.Enqueue(queue.Dequeue());
                }
                if (!this.queueEnded && this.TotallyEmpty)
                {
                    this.queueEnded = true;
                    TroopList list = new TroopList();
                    foreach (Troop troop2 in base.GameObjects)
                    {
                        if (troop2.QueueEnded)
                        {
                            list.Add(troop2);
                        }
                    }
                    foreach (Troop troop2 in list.GetRandomList())
                    {
                        this.troopQueue.Enqueue(troop2);
                    }
                }
            }
        }
Beispiel #22
0
 public TroopList GetAreaStratagemTroops(Troop troop, bool friendly)
 {
     TroopList list = new TroopList();
     foreach (Troop troop2 in this.GetAreaCastTroops(troop.Position, this.AreaStratagemRadius, false))
     {
         if ((!friendly || this.IsFriendly(troop2.BelongedFaction)) && (friendly || ((troop2 != this) && !this.IsFriendly(troop2.BelongedFaction))))
         {
             list.Add(troop2);
         }
     }
     return list;
 }
Beispiel #23
0
 private TroopList GetAreaStratagemTroops(Point centre, int radius, bool oblique)
 {
     GameArea area = GameArea.GetViewArea(centre, radius, oblique, base.Scenario, null);
     TroopList list = new TroopList();
     foreach (Point point in area.Area)
     {
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if ((troopByPosition != null) && (this.CurrentStratagem.IsValid(troopByPosition) && (this.CurrentStratagem.Friendly || !this.IsFriendly(troopByPosition.BelongedFaction))))
         {
             list.Add(troopByPosition);
         }
     }
     return list;
 }
Beispiel #24
0
 private TroopList GetAttackPossibleTroops(bool last)
 {
     TroopList list = new TroopList();
     foreach (Point point in this.OffenceArea.Area)
     {
         if (((this.BelongedFaction == null) && this.ViewArea.HasPoint(point)) || ((this.BelongedFaction != null) && this.BelongedFaction.IsPositionKnown(point)))
         {
             Troop troopByPositionNoCheck = base.Scenario.GetTroopByPositionNoCheck(point);
             if ((troopByPositionNoCheck != null) && (troopByPositionNoCheck != this))
             {
                 if (((this.AttackedTroopList.HasGameObject(troopByPositionNoCheck) || this.IsFriendly(troopByPositionNoCheck.BelongedFaction)) || (troopByPositionNoCheck.Status == TroopStatus.埋伏)) || !(this.AirOffence || !troopByPositionNoCheck.IsInArchitecture))
                 {
                     continue;
                 }
                 if (this.IfAttackTroop(troopByPositionNoCheck, last))
                 {
                     list.Add(troopByPositionNoCheck);
                 }
             }
         }
     }
     return list;
 }
 private Troop BuildOffensiveTroop(Architecture destination, LinkKind linkkind, bool offensive)
 {
     Troop troop;
     if (linkkind == LinkKind.None)
     {
         return null;
     }
     TroopList list = new TroopList();
     this.Persons.ClearSelected();
     //Label_0309:
     foreach (Military military in this.Militaries.GetRandomList())
     {
         if (military.Scales < military.RetreatScale * 1.5) continue;
         if (military.IsTransport) continue; //never deal with transports in this function
         switch (linkkind)
         {
             case LinkKind.Land:
                 {
                     if (military.Kind.Type != MilitaryType.水军)
                     {
                         break;
                     }
                     continue;
                 }
             case LinkKind.Water:
                 {
                     //if ((military.Kind.Type == MilitaryType.水军) || (this.ValueWater && (!offensive || ((military.Quantity >= 0x1f40) && (GameObject.Random(military.Kind.Merit) <= 0)))))
                     if (GlobalVariables.LandArmyCanGoDownWater)
                     {
                         if (!offensive || (military.KindID != 28 && !military.IsTransport))
                         {
                             break;
                         }
                     }
                     else
                     {
                         if (military.Kind.Type == MilitaryType.水军)
                         {
                             break;
                         }
                     }
                     continue;
                 }
         }
         if ((((military.Scales > 5) && (military.Morale >= 80)) && (military.Combativity >= 80)) && (military.InjuryQuantity < military.Kind.MinScale)
             && (!offensive ||
             (military.Merit > 0)
             )) //do not use transport teams to attack
         {
             TroopList candidates = this.AISelectPersonIntoTroop(this, military);
             foreach (Troop t in candidates)
             {
                 list.Add(t);
             }
         }
     }
     if (list.Count > 0)
     {
         list.IsNumber = true;
         list.PropertyName = "SimulatingFightingForce";
         list.ReSort();
         foreach (Troop troop2 in list.GetList())
         {
             bool personAlreadyOut = false;
             foreach (Person p in troop2.Candidates)
             {
                 if (p.LocationTroop != null)
                 {
                     personAlreadyOut = true;
                     break;
                 }
             }
             bool militaryOut = true;
             foreach (Military m in this.Militaries)
             {
                 if (troop2.Army == m)
                 {
                     militaryOut = false;
                     break;
                 }
             }
             if (personAlreadyOut) continue;
             if (militaryOut) continue;
             if (troop2.FightingForce < 10000 && offensive)
             {
                 break;
             }
             Point? nullable = this.GetRandomStartingPosition(troop2);
             if (!nullable.HasValue)
             {
                 break;
             }
             Person leader = troop2.Candidates[0] as Person;
             PersonList candidates = this.SelectSubOfficersToTroop(troop2);
             troop = this.CreateTroop(candidates, leader, troop2.Army, -1, nullable.Value);
             troop.WillArchitecture = destination;
             Legion legion = this.BelongedFaction.GetLegion(destination);
             if (legion == null)
             {
                 legion = this.CreateOffensiveLegion(destination);
             }
             legion.AddTroop(troop);
             this.PostCreateTroop(troop, false);
         }
     }
     foreach (Troop t in list)
     {
         t.Destroy(true, false);
     }
     return null;
 }
Beispiel #26
0
 private TroopList GetCastPossibleTroops(bool last)
 {
     TroopList list = new TroopList();
     foreach (Point point in this.StratagemArea.Area)
     {
         if (((this.BelongedFaction == null) && this.ViewArea.HasPoint(point)) || ((this.BelongedFaction != null) && this.BelongedFaction.IsPositionKnown(point)))
         {
             Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
             if (((troopByPosition == null) || (troopByPosition.Action != TroopAction.Stop)) || (troopByPosition.Status == TroopStatus.埋伏))
             {
                 continue;
             }
             if (this.CurrentStratagem.Friendly)
             {
                 if (!this.IsFriendly(troopByPosition.BelongedFaction) || !this.CurrentStratagem.IsValid(troopByPosition))
                 {
                     continue;
                 }
                 if (this.IfCastTroop(troopByPosition, last))
                 {
                     list.Add(troopByPosition);
                 }
             }
             else
             {
                 if (this.IsFriendly(troopByPosition.BelongedFaction) || !this.CurrentStratagem.IsValid(troopByPosition))
                 {
                     continue;
                 }
                 if (this.IfCastTroop(troopByPosition, last))
                 {
                     list.Add(troopByPosition);
                 }
             }
         }
     }
     return list;
 }
        private void DefensiveCampaign()
        {
            DateTime beforeStart = DateTime.UtcNow;

            List<Point> orientations = new List<Point>();
            TroopList hostileTroopsInView = this.GetHostileTroopsInView();
            foreach (Troop troop in hostileTroopsInView)
            {
                orientations.Add(troop.Position);
            }

            if ((this.HasPerson() && this.HasCampaignableMilitary()) && (this.GetAllAvailableArea(false).Count != 0))
            {
                if (hostileTroopsInView.Count > 0)
                {
                    TroopList friendlyTroopsInView = this.GetFriendlyTroopsInView();
                    int troopSent = 0;
                    int militaryCount = this.MilitaryCount;

                    Troop troop2;
                    TroopList list4 = new TroopList();
                    bool isBesideWater = this.IsBesideWater;

                    foreach (Military military in this.Militaries.GetRandomList())
                    {
                        if (military.IsFewScaleNeedRetreat && this.Endurance >= 30) continue;
                        if ((isBesideWater || (military.Kind.Type != MilitaryType.水军)) && (((((this.Endurance < 30) || military.Kind.AirOffence) || (military.Scales >= 2)) && (military.Morale > 0x2d)) && ((this.Endurance < 30) || (military.InjuryQuantity < military.Kind.MinScale))))
                        {
                            TroopList candidates = this.AISelectPersonIntoTroop(this, military);
                            foreach (Troop t in candidates)
                            {
                                list4.Add(t);
                                if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime))
                                {
                                    break;
                                }
                            }
                        }
                        if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime))
                        {
                            break;
                        }
                    }

                    if (list4.Count > 0)
                    {
                        list4.IsNumber = true;
                        list4.PropertyName = "FightingForce";
                        list4.ReSort();
                        foreach (Troop troop in list4.GetList())
                        {
                            if (troop.FightingForce < 10000 && troop.FightingForce < (this.TotalHostileForce * 5 - this.TotalFriendlyForce) / 25)
                            {
                                break;
                            }
                            if (troop.Army.Scales < 5 && this.Endurance > 30)
                            {
                                continue;
                            }

                            bool personAlreadyOut = false;
                            foreach (Person p in troop.Candidates)
                            {
                                if (p.LocationTroop != null)
                                {
                                    personAlreadyOut = true;
                                    break;
                                }
                            }
                            if (personAlreadyOut) continue;
                            bool militaryOut = true;
                            foreach (Military m in this.Militaries)
                            {
                                if (troop.Army == m)
                                {
                                    militaryOut = false;
                                    break;
                                }
                            }
                            if (militaryOut) continue;

                            Point? nullable = this.GetCampaignPosition(troop, orientations, troop.Army.Scales > 0);
                            if (!nullable.HasValue)
                            {
                                break;
                            }

                            Person leader = troop.Candidates[0] as Person;
                            PersonList candidates = this.SelectSubOfficersToTroop(troop);
                            troop2 = this.CreateTroop(candidates, leader, troop.Army, -1, nullable.Value);
                            troop2.WillArchitecture = this;
                            if (this.DefensiveLegion == null)
                            {
                                this.CreateDefensiveLegion();
                            }
                            this.DefensiveLegion.AddTroop(troop2);
                            this.PostCreateTroop(troop2, false);
                            this.TotalFriendlyForce += troop2.FightingForce;
                            troopSent++;
                        }

                        foreach (Troop t in list4)
                        {
                            t.Destroy(true, false);
                        }
                    }
                }
            }

            //not enough defensive troop, call for reinforcements!!
            float rate = (float)Math.Max(1, (200 - this.Endurance) * 0.005 + 1);
            if (this.TotalFriendlyForce < this.TotalHostileForce * rate)
            {
                foreach (LinkNode i in this.AIAllLinkNodes.Values)
                {
                    if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime))
                    {
                        return;
                    }
                    if (i.Level > 1) break;
                    if (i.A.actuallyUnreachableArch.Contains(this))
                    {
                        continue;
                    }
                    if (this.BelongedFaction == i.A.BelongedFaction && i.A.HasPerson()
                        && i.A.BelongedSection.AIDetail.AutoRun)
                    {

                        int reserve;
                        if (this.Population > 0)
                        {
                            reserve = (int)(i.A.getArmyReserveForOffensive(null) * Math.Pow(i.A.Population / (double)this.Population, 0.15));
                        }
                        else
                        {
                            reserve = int.MaxValue;
                        }

                        TroopList supportList = new TroopList();
                        Troop troop2;

                        foreach (Military military in i.A.Militaries.GetRandomList())
                        {
                            if (military.IsFewScaleNeedRetreat) continue;
                            if (military.IsTransport) continue;
                            if (this.isArmyNavigableTo(i, military) && (military.Morale > 90) && (military.InjuryQuantity < military.Kind.MinScale))
                            {
                                TroopList candidates = this.AISelectPersonIntoTroop(this, military);
                                foreach (Troop t in candidates)
                                {
                                    supportList.Add(t);
                                    if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime))
                                    {
                                        break;
                                    }
                                }
                            }
                            if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime))
                            {
                                break;
                            }
                        }

                        if (supportList.Count > 0)
                        {
                            supportList.IsNumber = true;
                            supportList.PropertyName = "FightingForce";
                            supportList.ReSort();
                            foreach (Troop troop in supportList.GetList())
                            {
                                if ((troop.FightingForce < 10000) && (troop.Army.Scales < 10))
                                {
                                    break;
                                }

                                bool personAlreadyOut = false;
                                foreach (Person p in troop.Candidates)
                                {
                                    if (p.LocationTroop != null)
                                    {
                                        personAlreadyOut = true;
                                        break;
                                    }
                                }
                                if (personAlreadyOut) continue;
                                bool militaryOut = true;
                                foreach (Military m in i.A.Militaries)
                                {
                                    if (troop.Army == m)
                                    {
                                        militaryOut = false;
                                        break;
                                    }
                                }
                                if (militaryOut) continue;

                                Point? nullable = i.A.GetCampaignPosition(troop, orientations, troop.Army.Scales > 0);
                                if (!nullable.HasValue)
                                {
                                    continue;
                                }
                                Person leader = troop.Candidates[0] as Person;
                                PersonList candidates = i.A.SelectSubOfficersToTroop(troop);
                                troop2 = i.A.CreateTroop(candidates, leader, troop.Army, -1, nullable.Value);
                                troop2.WillArchitecture = this;
                                if (this.DefensiveLegion == null)
                                {
                                    this.CreateDefensiveLegion();
                                }
                                this.DefensiveLegion.AddTroop(troop2);
                                i.A.PostCreateTroop(troop2, false);
                                this.TotalFriendlyForce += troop2.FightingForce;
                            }
                            foreach (Troop t in supportList)
                            {
                                t.Destroy(true, false);
                            }

                        }
                    }

                }
            }
        }
Beispiel #28
0
 public TroopList GetContactHostileTroops()
 {
     TroopList list = new TroopList();
     foreach (Point point in GameArea.GetArea(this.Position, 1, true).Area)
     {
         if ((point != this.Position) && this.BelongedFaction.IsPositionKnown(point))
         {
             Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
             if (!((troopByPosition == null) || this.IsFriendly(troopByPosition.BelongedFaction)))
             {
                 list.Add(troopByPosition);
             }
         }
     }
     return list;
 }
 public TroopList GetHostileTroopsInView()
 {
     GameArea viewArea = this.ViewArea;
     if ((this.RecentlyAttacked > 0) || (this.ArmyScale > this.LargeArmyScale))
     {
         viewArea = this.LongViewArea;
     }
     TroopList list = new TroopList();
     foreach (Point point in viewArea.Area)
     {
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if ((troopByPosition != null) && (!troopByPosition.IsFriendly(this.BelongedFaction) && (troopByPosition.Status != TroopStatus.埋伏)))
         {
             int days = 1;
             if ((((this.BelongedFaction != null) && (troopByPosition.BelongedFaction != null)) && (this.RecentlyAttacked <= 0)) && (base.Scenario.GetDiplomaticRelation(this.BelongedFaction.ID, troopByPosition.BelongedFaction.ID) >= 0))
             {
                 days = 0;
             }
             if (troopByPosition.DaysToReachPosition(base.Scenario.GetClosestPoint(this.ArchitectureArea, troopByPosition.Position), days))
             {
                 list.Add(troopByPosition);
             }
         }
     }
     return list;
 }
Beispiel #30
0
 public TroopList GetHostileTroopsInView()
 {
     TroopList list = new TroopList();
     foreach (Point point in this.ViewArea.Area)
     {
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if (!((troopByPosition == null) || this.IsFriendly(troopByPosition.BelongedFaction)))
         {
             list.Add(troopByPosition);
         }
     }
     return list;
 }
 private TroopList AISelectPersonIntoTroop(Architecture from, Military military)
 {
     TroopList result = new TroopList();
     if (military.FollowedLeader != null && from.Persons.HasGameObject(military.FollowedLeader) && military.FollowedLeader.LocationTroop == null)
     {
         result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(military.FollowedLeader, from.Persons, true), military, from.Position));
     }
     else if (military.Leader != null && military.LeaderExperience >= 10 && (military.Leader.Strength >= 80 || military.Leader.Command >= 80 || military.Leader.HasLeaderValidTitle)
         && from.Persons.HasGameObject(military.Leader) && military.Leader.LocationTroop == null)
     {
         result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(military.Leader, from.Persons, true), military, from.Position));
     }
     else
     {
         GameObjectList pl = from.Persons.GetList();
         pl.PropertyName = "FightingForce";
         pl.IsNumber = true;
         pl.SmallToBig = false;
         pl.ReSort();
         foreach (Person person in pl)
         {
             if (!person.Selected)
             {
                 if (person.HasMilitaryKindTitle(military.Kind))
                 {
                     result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(person, from.Persons, false), military, from.Position));
                 }
                 else if (person.HasMilitaryTypeTitle(military.Kind.Type))
                 {
                     result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(person, from.Persons, false), military, from.Position));
                 }
                 else if ((this.BelongedFaction.AvailableMilitaryKinds.GetMilitaryKindList().GameObjects.Contains(military.Kind) && military.Kind.RecruitLimit > 10) ||
                     person.FightingForce >= Parameters.AIUniqueTroopFightingForceThreshold || this.Endurance < 30)
                 {
                     result.Add(Troop.CreateSimulateTroop(this.AISelectPersonIntoTroop_inner(person, from.Persons, false), military, from.Position));
                 }
             }
         }
     }
     return result;
 }
Beispiel #32
0
 public TroopList GetSurroundAttackingTroop(Troop troop)
 {
     TroopList list = new TroopList();
     foreach (Point point in GameArea.GetArea(troop.Position, 1, true).Area)
     {
         if (point == troop.Position)
         {
             continue;
         }
         Troop troopByPosition = base.Scenario.GetTroopByPosition(point);
         if ((troopByPosition != null) && ((troopByPosition == this) || ((this.IsFriendly(troopByPosition.BelongedFaction) && troopByPosition.SurroundAvail()) && troopByPosition.CanAttack(troop))))
         {
             list.Add(troopByPosition);
         }
     }
     return list;
 }
Beispiel #33
0
 public void LoadTroopsFromString(TroopList troops, string dataString)
 {
     char[] separator = new char[] { ' ', '\n', '\r', '\t' };
     string[] strArray = dataString.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     this.Troops.Clear();
     foreach (string str in strArray)
     {
         Troop gameObject = troops.GetGameObject(int.Parse(str)) as Troop;
         if (gameObject != null)
         {
             this.AddTroop(gameObject);
         }
     }
 }
Beispiel #34
0
 private TroopList GetTroopsBetween(Point from, Point to)
 {
     TroopList list = new TroopList();
     int num = to.X - from.X;
     int num2 = to.Y - from.Y;
     if ((Math.Abs(num) > 1) || (Math.Abs(num2) > 1))
     {
         int num3;
         Troop troopByPosition;
         if (num == 0)
         {
             if (num2 > 0)
             {
                 for (num3 = 1; num3 < num2; num3++)
                 {
                     troopByPosition = base.Scenario.GetTroopByPosition(new Point(from.X, from.Y + num3));
                     if (troopByPosition != null)
                     {
                         list.Add(troopByPosition);
                     }
                 }
                 return list;
             }
             num3 = -1;
             while (num3 > num2)
             {
                 troopByPosition = base.Scenario.GetTroopByPosition(new Point(from.X, from.Y + num3));
                 if (troopByPosition != null)
                 {
                     list.Add(troopByPosition);
                 }
                 num3--;
             }
             return list;
         }
         if (num > 0)
         {
             for (num3 = 1; num3 < num; num3++)
             {
                 troopByPosition = base.Scenario.GetTroopByPosition(new Point(from.X + num3, from.Y + ((int) Math.Round((double) ((num3 * num2) / ((double) num))))));
                 if (troopByPosition != null)
                 {
                     list.Add(troopByPosition);
                 }
             }
             return list;
         }
         for (num3 = -1; num3 > num; num3--)
         {
             troopByPosition = base.Scenario.GetTroopByPosition(new Point(from.X + num3, from.Y + ((int) Math.Round((double) ((num3 * num2) / ((double) num))))));
             if (troopByPosition != null)
             {
                 list.Add(troopByPosition);
             }
         }
     }
     return list;
 }
Beispiel #35
0
        public void CurrentQueueTroopMove()
        {
            if (this.CurrentTroop != null)
            {
                this.TroopMoveThread(this.CurrentTroop);

                /*Thread thread;
                *
                *  thread = new Thread(new ThreadStart(this.CurrentTroop.Move));
                *  thread.Start();
                *  thread.Join();*/

                if (this.CurrentTroop.StepNotFinished || (this.CurrentTroop.MovabilityLeft <= 0))
                {
                    if (!this.CurrentTroop.OperationDone)
                    {
                        this.troopQueue.Enqueue(this.CurrentTroop);
                    }
                    this.CurrentTroop = null;
                }
            }
            else if (!this.CheckAmbushList())
            {
                Queue <Troop> queue = new Queue <Troop>();
                if ((this.CurrentQueue.Count == 0) && (this.troopQueue.Count > 0))
                {
                    this.CurrentQueue.Enqueue(this.troopQueue.Dequeue());
                }
                while (this.CurrentQueue.Count > 0)
                {
                    Troop item = this.CurrentQueue.Dequeue();
                    if (!item.Destroyed)
                    {
                        if (item.mingling == "待命")
                        {
                            item.OperationDone = true;
                            break;
                        }

                        if (item.Destroyed ||
                            (item.Status != TroopStatus.一般 && item.Status != TroopStatus.伪报 && item.Status != TroopStatus.挑衅))
                        {
                            item.MovabilityLeft = -1;
                            item.OperationDone  = true;
                        }

                        if (Session.Current.Scenario.IsPlayer(item.BelongedFaction))
                        {
                            if (!(item.HasToDoCombatAction || !item.ToDoCombatAction()))
                            {
                                item.HasToDoCombatAction = true;
                                this.CurrentQueue.Enqueue(item);
                                break;
                            }
                            if (item.HasToDoCombatAction)
                            {
                                item.HasToDoCombatAction = false;
                                item.DoCombatAction();
                                this.CurrentQueue.Enqueue(item);
                                break;
                            }
                            if (this.troopQueue.Count > 0)
                            {
                                this.CurrentQueue.Enqueue(this.troopQueue.Dequeue());
                            }

                            if (item.MovabilityLeft > 0)
                            {
                                this.TroopChangeRealDestination(item);
                                this.TroopMoveThread(item);
                            }
                        }
                        else
                        {
                            if (!item.Destroyed)
                            {
                                if (item.MovabilityLeft > 0)
                                {
                                    this.TroopChangeRealDestination(item);
                                    this.TroopMoveThread(item);
                                }

                                if (item.MovabilityLeft <= 0)
                                {
                                    if (!item.HasToDoCombatAction && item.ToDoCombatAction())
                                    {
                                        item.HasToDoCombatAction = true;
                                        this.CurrentQueue.Enqueue(item);
                                        break;
                                    }
                                    if (item.HasToDoCombatAction)
                                    {
                                        item.HasToDoCombatAction = false;
                                        item.DoCombatAction();
                                        this.CurrentQueue.Enqueue(item);
                                        break;
                                    }
                                }
                            }
                        }

                        if (item.Destroyed ||
                            (item.Status != TroopStatus.一般 && item.Status != TroopStatus.伪报 && item.Status != TroopStatus.挑衅))
                        {
                            item.MovabilityLeft = -1;
                            item.OperationDone  = true;
                        }

                        if ((!item.OperationDone && item.OffenceOnlyBeforeMove) && (item.Position != item.PreviousPosition))
                        {
                            item.OperationDone = true;
                        }
                        if ((!item.StepNotFinished || item.chongshemubiaoweizhibiaoji) && item.MovabilityLeft >= 0)
                        {
                            this.CurrentTroop = item;
                            break;
                        }
                        if (!this.queueEnded)
                        {
                            if (item.MovabilityLeft > 0)
                            {
                                item.WaitOnce = true;
                                queue.Enqueue(item);
                            }
                            else if (!(item.OperationDone || item.QueueEnded))
                            {
                                queue.Enqueue(item);
                            }
                        }
                    }
                }
                while (queue.Count > 0)
                {
                    this.troopQueue.Enqueue(queue.Dequeue());
                }
                if (!this.queueEnded && this.TotallyEmpty)
                {
                    this.queueEnded = true;
                    TroopList list = new TroopList();
                    foreach (Troop troop2 in base.GameObjects)
                    {
                        if (troop2.QueueEnded)
                        {
                            list.Add(troop2);
                        }
                    }
                    foreach (Troop troop2 in list.GetRandomList())
                    {
                        this.troopQueue.Enqueue(troop2);
                    }
                }
            }
        }
Beispiel #36
0
 public void Init()
 {
     Troops = new TroopList();
 }