Ejemplo n.º 1
0
        public static Actor?GetMostUnderutilizedDrillrig(Player owner, WPos origin)
        {
            // We will ignore any oil sneaking actors.
            var tankers = owner.World.ActorsWithTrait <Tanker>()
                          .Where(pair => pair.Actor.Owner == owner && pair.Trait.PreferedDrillrig != null)
                          .Select(pair => pair.Trait)
                          .ToArray();

            var powerstations = owner.World.ActorsWithTrait <PowerStation>()
                                .Where(pair => pair.Actor.Owner == owner && !pair.Trait.IsTraitDisabled)
                                .Select(pair => pair.Actor)
                                .ToArray();

            return(owner.World.ActorsWithTrait <Drillrig>()
                   .Where(pair => pair.Actor.Owner == owner && OilUtils.IsUsable(pair.Actor, pair.Trait))
                   .Select(pair => pair.Actor)
                   .OrderBy(
                       drillrig =>
            {
                // Assume a default distance of 1 when we have no PowerStation nearby.
                var distance = 1;

                // We ignore the fact that Tankers could have assigned a different PowerStation.
                if (powerstations.Any())
                {
                    distance = Math.Max(distance, powerstations.Min(powerStation => (powerStation.CenterPosition - drillrig.CenterPosition).Length));
                }

                // Using a large factor to avoid using a float.
                return 1024 * 1024 * tankers.Count(pair2 => drillrig.Equals(pair2.PreferedDrillrig)) / distance;
            }
                       )
                   .ThenBy(drillrig => (drillrig.CenterPosition - origin).Length)
                   .FirstOrDefault());
        }
Ejemplo n.º 2
0
 public static Actor?GetNearestPowerStation(Player owner, WPos origin)
 {
     return(owner.World.ActorsWithTrait <PowerStation>()
            .Where(pair => pair.Actor.Owner == owner && OilUtils.IsUsable(pair.Actor, pair.Trait))
            .OrderBy(pair => (pair.Actor.CenterPosition - origin).Length)
            .Select(pair => pair.Actor)
            .FirstOrDefault());
 }