Example #1
0
 public MilitaryKind findSuccessorCreatable(MilitaryKindList allMilitaryKinds, Architecture recruiter)
 {
     foreach (MilitaryKind i in allMilitaryKinds)
     {
         i.findSuccessor_visited = false;
     }
     return(findSuccessorRecruitable_r(allMilitaryKinds, recruiter, this));
 }
Example #2
0
        private MilitaryKind findSuccessorRecruitable_r(MilitaryKindList allMilitaryKinds, Architecture recruiter, MilitaryKind prev)
        {
            if (prev.successor.GetMilitaryKindList().Count == 0)
            {
                return(prev);
            }
            prev.findSuccessor_visited = true;
            MilitaryKindList toVisit = new MilitaryKindList();

            foreach (MilitaryKind i in prev.successor.GetMilitaryKindList())
            {
                if (!i.findSuccessor_visited && recruiter.GetNewMilitaryKindList().GameObjects.Contains(i) && allMilitaryKinds.GetList().GameObjects.Contains(i))
                {
                    toVisit.Add(i);
                }
            }
            if (toVisit.Count == 0)
            {
                return(prev);
            }
            return(findSuccessorRecruitable_r(allMilitaryKinds, recruiter, toVisit[GameObject.Random(toVisit.Count)] as MilitaryKind));
        }
 private MilitaryKind findSuccessorRecruitable_r(MilitaryKindList allMilitaryKinds, Architecture recruiter, MilitaryKind prev)
 {
     if (prev.successor.GetMilitaryKindList().Count == 0)
     {
         return prev;
     }
     prev.findSuccessor_visited = true;
     MilitaryKindList toVisit = new MilitaryKindList();
     foreach (MilitaryKind i in prev.successor.GetMilitaryKindList())
     {
         if (!i.findSuccessor_visited && recruiter.GetNewMilitaryKindList().GameObjects.Contains(i) && allMilitaryKinds.GetList().GameObjects.Contains(i))
         {
             toVisit.Add(i);
         }
     }
     if (toVisit.Count == 0)
     {
         return prev;
     }
     return findSuccessorRecruitable_r(allMilitaryKinds, recruiter, toVisit[GameObject.Random(toVisit.Count)] as MilitaryKind);
 }
 public MilitaryKind findSuccessorCreatable(MilitaryKindList allMilitaryKinds, Architecture recruiter)
 {
     foreach (MilitaryKind i in allMilitaryKinds)
     {
         i.findSuccessor_visited = false;
     }
     return findSuccessorRecruitable_r(allMilitaryKinds, recruiter, this);
 }
 private void AIRecruitment(bool water, bool siege)
 {
     if (this.Population > 0)
     {
         MilitaryKind current;
         Dictionary<int, MilitaryKind>.ValueCollection.Enumerator enumerator;
         MilitaryKindList list = new MilitaryKindList();
         MilitaryKindList allMilitaries = new MilitaryKindList();
         using (enumerator = this.BelongedFaction.AvailableMilitaryKinds.MilitaryKinds.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current;
                 if (current.IsTransport) continue;
                 if (current.Type == MilitaryType.水军 && this.AIWaterLinks.Count == 0) continue;
                 if (current.Type != MilitaryType.水军 && this.AILandLinks.Count == 0) continue;
                 if (((water && current.Type == MilitaryType.水军) || (!water && current.Type != MilitaryType.水军))
                     && ((siege && current.Type == MilitaryType.器械) || (!siege && current.Type != MilitaryType.器械))
                     && current.CreateAvail(this))
                 {
                     list.Add(current);
                 }
                 if (current.CreateAvail(this))
                 {
                     allMilitaries.Add(current);
                 }
                 /*if ((((this.ValueWater == (current.Type == MilitaryType.水军)) || (!water && GameObject.Chance(20))) && current.CreateAvail(this)) && (current.ID != 29))
                 {
                     list.Add(current);
                 }*/
             }
         }
         using (enumerator = this.PrivateMilitaryKinds.MilitaryKinds.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current;
                 if (current.IsTransport) continue;
                 if (current.Type == MilitaryType.水军 && this.AIWaterLinks.Count == 0) continue;
                 if (current.Type != MilitaryType.水军 && this.AILandLinks.Count == 0) continue;
                 if (((water && current.Type == MilitaryType.水军) || (!water && current.Type != MilitaryType.水军))
                     && ((siege && current.Type == MilitaryType.器械) || (!siege && current.Type != MilitaryType.器械))
                     && current.CreateAvail(this))
                 {
                     list.Add(current);
                 }
                 if (current.CreateAvail(this))
                 {
                     allMilitaries.Add(current);
                 }
             }
         }
         if (list.Count > 0)
         {
             current = list[GameObject.Random(list.Count)] as MilitaryKind;
             this.CreateMilitary(current.findSuccessorCreatable(list, this));
         }
         else if (allMilitaries.Count > 0)
         {
             current = allMilitaries[GameObject.Random(allMilitaries.Count)] as MilitaryKind;
             this.CreateMilitary(current.findSuccessorCreatable(allMilitaries, this));
         }
         /*if (GameObject.Chance(90))
         {
             list.PropertyName = "Merit";
             list.IsNumber = true;
             list.ReSort();
             int maxValue = list.Count / 2;
             if (list.Count > 1)
             {
                 for (int i = maxValue; i < list.Count; i++)
                 {
                     if ((list[i] as MilitaryKind).Merit == (list[i - 1] as MilitaryKind).Merit)
                     {
                         maxValue++;
                     }
                 }
             }
             current = list[GameObject.Random(maxValue)] as MilitaryKind;
             if ((!this.ValueWater || (current.Type == MilitaryType.水军)) || GameObject.Chance(20))
             {
                 this.CreateMilitary(current);
             }
         }
         else
         {
             current = list[GameObject.Random(list.Count)] as MilitaryKind;
             if ((!this.ValueWater || (current.Type == MilitaryType.水军)) || GameObject.Chance(20))
             {
                 this.CreateMilitary(current);
             }
         }*/
     }
 }
 private void AIRecruitment(bool water)
 {
     if (this.Population > 0)
     {
         MilitaryKind current;
         Dictionary<int, MilitaryKind>.ValueCollection.Enumerator enumerator;
         MilitaryKindList list = new MilitaryKindList();
         using (enumerator = this.BelongedFaction.AvailableMilitaryKinds.MilitaryKinds.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current;
                 if (((this.ValueWater == (current.Type == MilitaryType.水军)) || (!water && GameObject.Chance(20))) && current.CreateAvail(this))
                 {
                     if (current.ID!=29)
                         list.Add(current);
                 }
             }
         }
         using (enumerator = this.PrivateMilitaryKinds.MilitaryKinds.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current;
                 if (((this.ValueWater == (current.Type == MilitaryType.水军)) || (!water && GameObject.Chance(20))) && current.CreateAvail(this))
                 {
                     if (current.ID != 29)
                         list.Add(current);
                 }
             }
         }
         if (list.Count > 0)
         {
             if (GameObject.Chance(90))
             {
                 list.PropertyName = "Merit";
                 list.IsNumber = true;
                 list.ReSort();
                 current = list[GameObject.Random(list.Count / 2)] as MilitaryKind;
                 if ((!this.ValueWater || (current.Type == MilitaryType.水军)) || GameObject.Chance(20))
                 {
                     this.CreateMilitary(current);
                 }
             }
             else
             {
                 current = list[GameObject.Random(list.Count)] as MilitaryKind;
                 if ((!this.ValueWater || (current.Type == MilitaryType.水军)) || GameObject.Chance(20))
                 {
                     this.CreateMilitary(current);
                 }
             }
         }
     }
 }
 //what to recruit
 //90% chance => recruit one of the best 50% troop (by merit value in military kind)
 //10% chance => recruit any type of troop
 //naval has only 80% of being actually recruited if the arch can recruit naval (hmm... strange)
 private void AIRecruitment(bool water)
 {
     if (this.Population > 0)
     {
         MilitaryKind current;
         Dictionary<int, MilitaryKind>.ValueCollection.Enumerator enumerator;
         MilitaryKindList list = new MilitaryKindList();
         using (enumerator = this.BelongedFaction.AvailableMilitaryKinds.MilitaryKinds.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current;
                 if (((this.ValueWater == (current.Type == MilitaryType.水军)) || (!water && GameObject.Chance(20))) && current.CreateAvail(this))
                 {
                     if (current.ID!=29)
                         list.Add(current);
                 }
             }
         }
         using (enumerator = this.PrivateMilitaryKinds.MilitaryKinds.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current;
                 if (((this.ValueWater == (current.Type == MilitaryType.水军)) || (!water && GameObject.Chance(20))) && current.CreateAvail(this))
                 {
                     if (current.ID != 29)
                         list.Add(current);
                 }
             }
         }
         if (list.Count > 0)
         {
             if (GameObject.Chance(90))
             {
                 list.PropertyName = "Merit";
                 list.IsNumber = true;
                 list.ReSort();
                 //the problem: what if those merit values are all the same?
                 //this results in AI tends to create qibian other than bubian
                 int idCap = list.Count / 2;
                 if (list.Count > 1)
                 {
                     for (int i = idCap; i < list.Count; i++)
                     {
                         if ((list[i] as MilitaryKind).Merit == (list[i - 1] as MilitaryKind).Merit)
                         {
                             idCap++;
                         }
                     }
                 }
                 //current = list[GameObject.Random(list.Count / 2)] as MilitaryKind;
                 current = list[GameObject.Random(idCap)] as MilitaryKind;
                 if ((!this.ValueWater || (current.Type == MilitaryType.水军)) || GameObject.Chance(20))
                 {
                     this.CreateMilitary(current);
                 }
             }
             else
             {
                 current = list[GameObject.Random(list.Count)] as MilitaryKind;
                 if ((!this.ValueWater || (current.Type == MilitaryType.水军)) || GameObject.Chance(20))
                 {
                     this.CreateMilitary(current);
                 }
             }
         }
     }
 }