public void FindClosestBusinesses(Person Searcher
     , ref List<Company> CurrentClosest, ref double MaxDistance, int NumCompanies)
 {
     if (isLeafNode)
     {
         for (int i = 0; i < Constituents.Length; i++)
         {
             if (Searcher.DistanceTo(Constituents[i]) <= MaxDistance)
             {
                 if (CurrentClosest.Count == 0)
                 {
                     CurrentClosest.Add(Constituents[i]);
                 }
                 else
                 {
                     for (int j = CurrentClosest.Count - 1; j >= 0; j--)
                     {
                         if (Constituents[i].DistanceRegister > CurrentClosest[j].DistanceRegister)
                         {
                             CurrentClosest.Insert(j + 1, Constituents[i]);
                         }
                     }
                 }
             }
         }
         if (CurrentClosest.Count > NumCompanies)
         {
             CurrentClosest.RemoveRange(NumCompanies, CurrentClosest.Count - NumCompanies);
             MaxDistance = CurrentClosest[CurrentClosest.Count - 1].DistanceRegister;
         }
     }
     else
     {
         if (Searcher.Location[SplitDimensionIndex] > SplitPosition)
         {
             GreaterNode.FindClosestBusinesses(Searcher
                 , ref CurrentClosest, ref MaxDistance, NumCompanies);
             if (Searcher.Location[SplitDimensionIndex] - MaxDistance < SplitPosition)
             {
                 LessEqualNode.FindClosestBusinesses(Searcher
                     , ref CurrentClosest, ref MaxDistance, NumCompanies);
             }
         }
         else
         {
             LessEqualNode.FindClosestBusinesses(Searcher
                 , ref CurrentClosest, ref MaxDistance, NumCompanies);
             if (Searcher.Location[SplitDimensionIndex] + MaxDistance > SplitPosition)
             {
                 GreaterNode.FindClosestBusinesses(Searcher
                     , ref CurrentClosest, ref MaxDistance, NumCompanies);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void QueryForEmployment(Person Candidate)
 {
     double Chance = 0.1;
     if (Candidate.SkillLevel > CapitalLevel)
     {
         Chance *= 1.0 + 0.1 * (Candidate.SkillLevel - CapitalLevel);
     }
     else
     {
         Chance -= 0.5 * (CapitalLevel - Candidate.SkillLevel);
     }
     if (Candidate.Productivity > 1)
     {
         Chance += 0.05 * Math.Log(Candidate.Productivity);
     }
     if (MyGame.random.NextDouble() > 1.0 - Chance)
     {
         Candidate.Employer = this;
         Employees.Add(Candidate);
         RedefineProduction();
     }
 }