public void BuildQueue()
        {
            this.queueEnded = false;
            if (this.troopQueue.Count != 0)
            {
                throw new Exception("troopQueue is not empty before building");
            }
            this.AmbushList.Clear();
            GameObjectList randomList = base.GetRandomList();

            if (GlobalVariables.MilitaryKindSpeedValid && (randomList.Count > 1))
            {
                randomList.PropertyName = "Speed";
                randomList.IsNumber     = true;
                randomList.SmallToBig   = false;
                randomList.ReSort();
            }
            foreach (Troop troop in randomList)
            {
                if (troop.ControlAvail())
                {
                    troop.InitializeInQueue();
                    if (troop.Status == TroopStatus.埋伏)
                    {
                        this.AmbushList.Add(troop);
                    }
                    else
                    {
                        this.troopQueue.Enqueue(troop);
                    }
                }
                troop.Operated     = false;
                troop.Controllable = true;
            }
        }
Beispiel #2
0
        public void BuildQueue(bool preUserControlFinished)
        {
            GameObjectList list = base.GetList();

            list.PropertyName = "Power";
            list.IsNumber     = true;
            list.SmallToBig   = true;
            list.ReSort();
            foreach (Faction faction in list)
            {
                this.SetFactionInQueue(faction, preUserControlFinished);
            }
        }
 public void NoFactionMove()
 {
     if (((((this.BelongedFaction == null) && (this.ArrivingDays == 0)) && (this.LocationArchitecture != null)) && !this.IsCaptive) && GameObject.Chance((2 + (int) this.Ambition) + (this.LeaderPossibility ? 10 : 0)))
     {
         if (GameObject.Chance(50 + (this.LeaderPossibility ? 10 : 0)))
         {
             GameObjectList hirableFactionList = this.GetHirableFactionList();
             if (hirableFactionList.Count > 0)
             {
                 GameObjects.Faction faction = hirableFactionList[GameObject.Random(hirableFactionList.Count)] as GameObjects.Faction;
                 if (((faction.Leader != null) && (GetIdealOffset(faction.Leader, this) <= 10)) && ((faction.Capital != null) && (faction.Capital != this.LocationArchitecture)))
                 {
                     this.MoveToArchitecture(faction.Capital);
                     this.LocationArchitecture.RemoveNoFactionPerson(this);
                 }
             }
             else if (this.LeaderPossibility)
             {
                 GameObjectList list2 = new GameObjectList();
                 foreach (Architecture architecture in this.LocationArchitecture.GetClosestArchitectures(40))
                 {
                     if ((architecture.BelongedFaction == null) && (architecture.RecentlyAttacked <= 0))
                     {
                         list2.Add(architecture);
                     }
                 }
                 if (list2.Count > 0)
                 {
                     if (list2.Count > 1)
                     {
                         list2.PropertyName = "UnitPopulation";
                         list2.IsNumber = true;
                         list2.ReSort();
                     }
                     Architecture a = list2[GameObject.Random(list2.Count / 2)] as Architecture;
                     this.MoveToArchitecture(a);
                     this.LocationArchitecture.RemoveNoFactionPerson(this);
                 }
             }
         }
         else
         {
             if (this.LocationArchitecture.ClosestArchitectures == null)
             {
                 this.LocationArchitecture.GetClosestArchitectures();
             }
             if (this.LocationArchitecture.ClosestArchitectures.Count > 0)
             {
                 int maxValue = 20;
                 if (maxValue > this.LocationArchitecture.ClosestArchitectures.Count)
                 {
                     maxValue = this.LocationArchitecture.ClosestArchitectures.Count;
                 }
                 maxValue = GameObject.Random(maxValue);
                 this.MoveToArchitecture(this.LocationArchitecture.ClosestArchitectures[maxValue] as Architecture);
                 this.LocationArchitecture.RemoveNoFactionPerson(this);
             }
         }
     }
 }
Beispiel #4
0
 public void RefreshWithPersonList(GameObjectList personList)
 {
     Point position = this.Position;
     Point destination = this.Destination;
     Point realDestination = this.RealDestination;
     Architecture startingArchitecture = this.StartingArchitecture;
     int iD = base.ID;
     Person leader = this.Leader;
     Stunt currentStunt = this.CurrentStunt;
     int stuntDayLeft = this.StuntDayLeft;
     this.Destroy();
     this.Destroyed = false;
     this.realDestination = realDestination;
     this.destination = destination;
     this.position = position;
     this.StartingArchitecture = startingArchitecture;
     base.ID = iD;
     this.Persons.Clear();
     if (!personList.HasGameObject(leader))
     {
         if (personList.Count > 1)
         {
             personList.PropertyName = "FightingForce";
             personList.IsNumber = true;
             personList.ReSort();
         }
         this.Leader = personList[0] as Person;
     }
     foreach (Person person2 in personList)
     {
         this.AddPerson(person2);
     }
     this.Persons.ApplyInfluences();
     if ((currentStunt != null) && (stuntDayLeft > 0))
     {
         this.CurrentStunt = currentStunt;
         this.StuntDayLeft = stuntDayLeft;
     }
     this.Initialize();
 }
 private void AIFoodTransfer()
 {
     Routeway connectedRouteway;
     int food;
     if (this.IsFoodAbundant || ((!this.HostileLine && (!this.FrontLine || !GameObject.Chance(20))) && !GameObject.Chance(1)))
     {
         if (this.TransferFoodArchitecture != null)
         {
             LinkNode node = null;
             this.AIAllLinkNodes.TryGetValue(this.TransferFoodArchitecture.ID, out node);
             if (node != null)
             {
                 connectedRouteway = this.GetRouteway(node, true);
                 if ((connectedRouteway != null) && (connectedRouteway.LastPoint != null))
                 {
                     if (this.BelongedFaction != this.TransferFoodArchitecture.BelongedFaction)
                     {
                         connectedRouteway.RemoveAfterClose = true;
                         connectedRouteway.Close();
                         this.TransferFoodArchitecture = null;
                     }
                     else
                     {
                         connectedRouteway.DestinationToEnd();
                         if (connectedRouteway.EndArchitecture == this.TransferFoodArchitecture)
                         {
                             food = this.Food - this.EnoughFood;
                             if ((food >= 0x186a0) || (food > this.TransferFoodArchitecture.FoodCostPerDayOfAllMilitaries))
                             {
                                 if (connectedRouteway.IsActive)
                                 {
                                     int abundantFood = this.TransferFoodArchitecture.AbundantFood;
                                     if (food > abundantFood)
                                     {
                                         food = abundantFood;
                                     }
                                     this.DecreaseFood(food);
                                     this.TransferFoodArchitecture.IncreaseFood((int) (food * (1f - (connectedRouteway.LastPoint.ConsumptionRate * this.BelongedFaction.RateOfFoodTransportBetweenArchitectures))));
                                     this.TransferFoodArchitecture = null;
                                 }
                                 else if ((connectedRouteway.LastPoint.BuildFundCost * 2) <= this.Fund)
                                 {
                                     connectedRouteway.Building = true;
                                 }
                             }
                             else
                             {
                                 this.TransferFoodArchitecture = null;
                             }
                         }
                         else
                         {
                             this.TransferFoodArchitecture = null;
                         }
                     }
                 }
                 else
                 {
                     this.TransferFoodArchitecture = null;
                 }
             }
             else
             {
                 this.TransferFoodArchitecture = null;
             }
         }
     }
     else
     {
         GameObjectList list = new GameObjectList();
         foreach (LinkNode node in this.AIAllLinkNodes.Values)
         {
             if (node.Level > 3)
             {
                 break;
             }
             if (node.A.BelongedFaction == this.BelongedFaction)
             {
                 if (node.A.BelongedSection == this.BelongedSection)
                 {
                     list.Add(node.A);
                 }
                 else if (node.A.BelongedSection.AIDetail.AllowFoodTransfer && ((node.A.BelongedSection.OrientationSection == this.BelongedSection) || (node.A.BelongedSection.OrientationSection == null)))
                 {
                     list.Add(node.A);
                 }
             }
         }
         if (list.Count > 1)
         {
             list.PropertyName = "Food";
             list.IsNumber = true;
             list.ReSort();
         }
         foreach (Architecture architecture in list)
         {
             connectedRouteway = architecture.GetConnectedRouteway(this);
             if ((connectedRouteway == null) || (connectedRouteway.LastPoint == null))
             {
                 connectedRouteway = this.GetConnectedRouteway(architecture);
             }
             if ((connectedRouteway != null) && (connectedRouteway.LastPoint != null))
             {
                 food = 0;
                 if (architecture.IsFoodTwiceAbundant && (architecture.RecentlyAttacked <= 0))
                 {
                     food = (architecture.FoodCostPerDayOfAllMilitaries * 80) / 5;
                     if (architecture.BelongedSection.OrientationSection == this.BelongedSection)
                     {
                         food *= 2;
                         if (food > architecture.Food)
                         {
                             food = architecture.Food;
                         }
                     }
                 }
                 else if (architecture.IsFoodAbundant && !architecture.HostileLine)
                 {
                     food = (architecture.FoodCostPerDayOfAllMilitaries * 40) / 5;
                     if (architecture.BelongedSection.OrientationSection == this.BelongedSection)
                     {
                         food *= 2;
                         if (food > architecture.Food)
                         {
                             food = architecture.Food;
                         }
                     }
                 }
                 if (food >= 0x186a0)
                 {
                     architecture.DecreaseFood(food);
                     this.IncreaseFood((int) (food * (1f - (connectedRouteway.LastPoint.ConsumptionRate * this.BelongedFaction.RateOfFoodTransportBetweenArchitectures))));
                 }
                 else
                 {
                     architecture.TransferFoodArchitecture = null;
                 }
             }
             else if (architecture.TransferFoodArchitecture == null)
             {
                 if ((((architecture.RecentlyAttacked == 0) && (!architecture.HostileLine || GameObject.Chance(20))) && (architecture.Food >= ((architecture.EnoughFood + this.EnoughFood) + 0x186a0))) && ((this.TransferFoodArchitectureCount <= GameObject.Random(2)) && (architecture.Food >= 0x61a80)))
                 {
                     architecture.TransferFoodArchitecture = this;
                 }
             }
             else if ((((architecture.BelongedFaction != this.BelongedFaction) || (this.BelongedFaction != architecture.TransferFoodArchitecture.BelongedFaction)) || ((architecture.RecentlyAttacked > 0) || architecture.TransferFoodArchitecture.IsFoodAbundant)) || ((architecture.Food < (architecture.EnoughFood + ((this.EnoughFood * 3) / 2))) && (architecture.Food < 0x61a80)))
             {
                 architecture.TransferFoodArchitecture = null;
             }
         }
     }
 }
 private void AIPersonTransfer()
 {
     int num2;
     if ((this.MilitaryCount == 0) && ((this.IsImportant || (this.AreaCount > 1)) || (this.Population > this.RecruitmentPopulationBoundary)))
     {
         this.AIRecruitment(false);
     }
     if ((((this.BelongedFaction.ArchitectureCount > 1) && (this.PersonCount > this.MilitaryCount)) && (this.RecentlyAttacked > 0)) && ((this.Endurance == 0) || ((this.Endurance < 30) && GameObject.Chance(0x21))))
     {
         int num = this.PersonCount - this.MilitaryCount;
         GameObjectList list = new GameObjectList();
         list = this.Persons.GetList();
         if (list.Count > 1)
         {
             list.IsNumber = true;
             list.SmallToBig = true;
             list.PropertyName = "FightingForce";
             list.ReSort();
         }
         Architecture capital = this.BelongedFaction.Capital;
         if (capital == this)
         {
             ArchitectureList otherArchitectureList = this.GetOtherArchitectureList();
             if (otherArchitectureList.Count > 1)
             {
                 otherArchitectureList.IsNumber = true;
                 otherArchitectureList.PropertyName = "ArmyScaleWeighing";
                 otherArchitectureList.ReSort();
             }
             capital = otherArchitectureList[0] as Architecture;
         }
         num2 = 0;
         while (num2 < num)
         {
             (list[num2] as Person).MoveToArchitecture(capital);
             this.RemovePerson(list[num2] as Person);
             if (GameObject.Chance(20))
             {
                 break;
             }
             num2++;
         }
     }
     else if (((this.PersonCount + this.MovingPersons.Count) < this.MilitaryCount) || (this.PlanArchitecture != null))
     {
         if (this.RecentlyAttacked > 0)
         {
             int num3 = (this.MilitaryCount - this.PersonCount) - this.MovingPersons.Count;
             PersonList list3 = new PersonList();
             foreach (Architecture architecture2 in GameObject.Chance(20) ? this.BelongedFaction.Architectures : this.BelongedSection.Architectures)
             {
                 if ((architecture2 != this) && (((architecture2.BelongedSection.AIDetail != null) && architecture2.BelongedSection.AIDetail.AutoRun) && (((architecture2.RecentlyAttacked <= 0) && ((architecture2.PersonCount + architecture2.MovingPersons.Count) >= architecture2.MilitaryCount)) || (((architecture2.Fund < (100 * this.AreaCount)) && (architecture2.Domination >= (architecture2.DominationCeiling * 0.8))) && (architecture2.Endurance >= (architecture2.EnduranceCeiling * 0.2f))))))
                 {
                     foreach (Person person in architecture2.Persons)
                     {
                         if ((!architecture2.HasFollowedLeaderMilitary(person) && (GameObject.Chance(10) || !architecture2.HasExperiencedLeaderMilitary(person))) && (person.Command >= 40))
                         {
                             list3.Add(person);
                         }
                     }
                 }
             }
             if (list3.Count > 0)
             {
                 if (list3.Count > 1)
                 {
                     list3.IsNumber = true;
                     list3.PropertyName = "FightingForce";
                     list3.ReSort();
                 }
                 for (num2 = 0; (num2 < num3) && (num2 < list3.Count); num2++)
                 {
                     Architecture locationArchitecture = (list3[num2] as Person).LocationArchitecture;
                     (list3[num2] as Person).MoveToArchitecture(this);
                     locationArchitecture.RemovePerson(list3[num2] as Person);
                 }
             }
         }
     }
     else if (this.HasPerson() && GameObject.Chance(10))
     {
         PersonList list4 = new PersonList();
         if (this.Kind.HasPopulation && (this.Population < (0x3e8 * this.AreaCount)))
         {
             if (this.IsCapital && (this.Fund >= this.ChangeCapitalCost))
             {
                 Architecture newCapital = this.BelongedFaction.SelectNewCapital();
                 if (newCapital != this)
                 {
                     this.DecreaseFund(this.ChangeCapitalCost);
                     this.BelongedFaction.ChangeCapital(newCapital);
                 }
             }
             foreach (Person person in this.Persons)
             {
                 if (!this.HasFollowedLeaderMilitary(person) && (GameObject.Chance(10) || !this.HasExperiencedLeaderMilitary(person)))
                 {
                     list4.Add(person);
                 }
             }
         }
         else
         {
             foreach (Person person in this.Persons)
             {
                 if ((person.WorkKind == ArchitectureWorkKind.无) && (!this.HasFollowedLeaderMilitary(person) && (GameObject.Chance(10) || !this.HasExperiencedLeaderMilitary(person))))
                 {
                     list4.Add(person);
                 }
             }
         }
         if (list4.Count > 0)
         {
             ArchitectureList list5 = new ArchitectureList();
             foreach (Architecture architecture2 in (base.Scenario.Date.Day == 1) ? this.BelongedFaction.Architectures : this.BelongedSection.Architectures)
             {
                 if ((architecture2 != this) && ((((architecture2.IsRegionCore || architecture2.IsStateAdmin) || (architecture2.Kind.HasPopulation && (architecture2.Population > this.Population))) || GameObject.Chance(5)) || ((architecture2.Fund >= (100 * this.AreaCount)) && ((((architecture2.PersonCount + architecture2.MovingPersons.Count) < architecture2.MilitaryCount) || (architecture2.Domination < (architecture2.DominationCeiling * 0.8))) || (architecture2.Endurance < (architecture2.EnduranceCeiling * 0.2f))))))
                 {
                     list5.Add(architecture2);
                 }
             }
             if (list5.Count > 0)
             {
                 if (list5.Count > 1)
                 {
                     list5.PropertyName = "ArmyScaleWeighing";
                     list5.IsNumber = true;
                     list5.ReSort();
                 }
                 for (num2 = 0; (num2 < list4.Count) && (num2 < list5.Count); num2++)
                 {
                     (list4[num2] as Person).MoveToArchitecture(list5[num2] as Architecture);
                     this.RemovePerson(list4[num2] as Person);
                 }
             }
         }
     }
 }
 private void BuildSectionByArchitectureList(GameObjectList architecturelist)
 {
     if (architecturelist.Count != 0)
     {
         Section section;
         GameObjectList list;
         if (architecturelist.Count == 1)
         {
             section = new Section();
             section.ID = base.Scenario.Sections.GetFreeGameObjectID();
             section.Scenario = base.Scenario;
             this.AddSection(section);
             base.Scenario.Sections.AddSectionWithEvent(section);
             list = base.Scenario.GameCommonData.AllSectionAIDetails.GetSectionAIDetailsByConditions(SectionOrientationKind.无, true, false, true, true, false);
             if (list.Count > 0)
             {
                 section.AIDetail = list[GameObject.Random(list.Count)] as SectionAIDetail;
             }
             else
             {
                 section.AIDetail = base.Scenario.GameCommonData.AllSectionAIDetails.GetSectionAIDetailList()[0] as SectionAIDetail;
             }
             section.AddArchitecture(architecturelist[0] as Architecture);
         }
         else
         {
             architecturelist.PropertyName = "Population";
             architecturelist.IsNumber = true;
             architecturelist.ReSort();
             int count = 0;
             int num2 = 2 + (this.ArchitectureCount / 8);
             if (architecturelist.Count < ((num2 * 3) / 2))
             {
                 count = architecturelist.Count;
             }
             else
             {
                 count = num2;
             }
             section = new Section();
             section.ID = base.Scenario.Sections.GetFreeGameObjectID();
             section.Scenario = base.Scenario;
             this.AddSection(section);
             base.Scenario.Sections.AddSectionWithEvent(section);
             list = base.Scenario.GameCommonData.AllSectionAIDetails.GetSectionAIDetailsByConditions(SectionOrientationKind.无, true, false, true, true, false);
             if (list.Count > 0)
             {
                 section.AIDetail = list[GameObject.Random(list.Count)] as SectionAIDetail;
             }
             else
             {
                 section.AIDetail = base.Scenario.GameCommonData.AllSectionAIDetails.GetSectionAIDetailList()[0] as SectionAIDetail;
             }
             Architecture architecture = architecturelist[0] as Architecture;
             section.AddArchitecture(architecture);
             if (architecture.ClosestArchitectures == null)
             {
                 architecture.GetClosestArchitectures();
             }
             if (architecture.AIAllLinkNodes.Count == 0)
             {
                 architecture.GenerateAllAILinkNodes(2);
             }
             foreach (LinkNode node in architecture.AIAllLinkNodes.Values)
             {
                 if (node.Level > 2)
                 {
                     break;
                 }
                 if ((node.A.BelongedFaction == this) && architecturelist.HasGameObject(node.A))
                 {
                     section.AddArchitecture(node.A);
                 }
                 if (section.ArchitectureCount >= count)
                 {
                     break;
                 }
             }
             if (count == architecturelist.Count)
             {
                 if (section.ArchitectureCount < count)
                 {
                     foreach (Architecture architecture2 in section.Architectures)
                     {
                         architecturelist.Remove(architecture2);
                     }
                     if (this.SectionCount == 1)
                     {
                         foreach (Architecture architecture2 in architecturelist)
                         {
                             this.FirstSection.AddArchitecture(architecture2);
                         }
                     }
                     else
                     {
                         foreach (Architecture architecture2 in architecturelist)
                         {
                             int num3 = 0x7fffffff;
                             Section section2 = null;
                             foreach (Section section3 in this.Sections)
                             {
                                 int distanceFromSection = architecture2.GetDistanceFromSection(section3);
                                 if (distanceFromSection < num3)
                                 {
                                     num3 = distanceFromSection;
                                     section2 = section3;
                                 }
                             }
                             section2.AddArchitecture(architecture2);
                         }
                     }
                 }
             }
             else
             {
                 foreach (Architecture architecture2 in section.Architectures)
                 {
                     architecturelist.Remove(architecture2);
                 }
                 this.BuildSectionByArchitectureList(architecturelist);
             }
         }
     }
 }