Beispiel #1
0
        public Vehicle GetSquadCentralUnit()
        {
            if (!Units.Any())
            {
                return(null);
            }

            if (Units.Count == 1)
            {
                return(Units[0]);
            }

            var dispersionPerUnit = SquaredDispersionList;

            //get the ID of less distant.
            var  minSquaredDistance = Double.MaxValue;
            long centerUnitId       = 0;

            foreach (var pair in dispersionPerUnit)
            {
                if (pair.Value > 0.01 && pair.Value < minSquaredDistance)
                {
                    minSquaredDistance = pair.Value;
                    centerUnitId       = pair.Key;
                }
            }

            //return position of less distant unit
            var centerUnit = Units.First(u => u.Id.Equals(centerUnitId));

            return(centerUnit);
        }
Beispiel #2
0
        public void UpdateState(Universe universe)
        {
            Units = universe.MyUnits.Where(u => u.Groups.Contains(Id)).ToList();
            var firstUpdate = false;

            if (!IsCreated)
            {
                IsCreated = Units.Any();
                if (IsCreated)
                {
                    firstUpdate = true;
                }
            }

            if (ScalingTimeDelay > 0 && !IsWaitingForScaling)
            {
                --ScalingTimeDelay;
            }

            IsEmpty = !Units.Any();

            if (IsCreated)
            {
                CalculateProperties();
            }

            if (firstUpdate)
            {
                StartDispersionSquared = DispersionSquared;
                ScalingTimeDelay       = 0;
                IsWaitingForScaling    = false;
            }
        }
Beispiel #3
0
 public bool OfType(VehicleType type)
 {
     if (!Units.Any())
     {
         return(false);
     }
     return(Units.FirstOrDefault().Type == type);
     //var totalCount = Units.Count;
     //var requestedCount = Units.Count(u => u.Type == type);
     //var othersCount = totalCount - requestedCount;
     //
     //return requestedCount > othersCount;
 }
Beispiel #4
0
        public double GetUnitsSquaredDispersionValue()
        {
            if (!Units.Any())
            {
                return(Double.MaxValue);
            }
            var    dispersionPerUnit = SquaredDispersionList;
            double dispersionSum     = 0;

            foreach (var dispersion in dispersionPerUnit)
            {
                dispersionSum += dispersion.Value;
            }
            return(dispersionSum / Units.Count);
        }
Beispiel #5
0
 public OrderInvalidReason CanBeAttacked(AttackMethod AttackMethod)
 {
     if (AttackMethod == AttackMethod.OVERRUN)
     {
         if (Units.Any(i => i.Configuration.IsEmplaceable()))
         {
             return(OrderInvalidReason.TARGET_IMMUNE);
         }
         if (!GetBaseRules().IsClear ||
             GetEdgeRules().Any(i => !i?.IsClear ?? false) ||
             GetPathOverlayRules().Any(i => !i?.IsClear ?? false))
         {
             return(OrderInvalidReason.OVERRUN_TERRAIN);
         }
     }
     return(OrderInvalidReason.NONE);
 }
Beispiel #6
0
        public void UpdateParents()
        {
            if (Units != null && Units.Any())
            {
                Units.ForEach(u => {
                    u.Parent = this;
                    u.UpdateParents();
                });
            }

            if (Sensors != null && Sensors.Any())
            {
                Sensors.ForEach(s => s.Parent = this);
            }

            if (Commands != null && Commands.Any())
            {
                Commands.ForEach(c => c.Parent = this);
            }
        }
Beispiel #7
0
        public int TakeDamage(Hit hit, PRNG dice = null)
        {
            int damage = hit.NominalDamage;

            if (Population.Any() && Units.Any())
            {
                // for now, have a 50% chance to hit population first and a 50% chance to hit units first
                // TODO - base the chance to hit population vs. units on relative HP or something?
                var coin = RandomHelper.Next(2, dice);
                int leftover;
                if (coin == 0)
                {
                    leftover = TakePopulationDamage(hit, damage, dice);
                }
                else
                {
                    leftover = TakeUnitDamage(hit, damage, dice);
                }
                if (coin == 0)
                {
                    return(TakeUnitDamage(hit, leftover, dice));
                }
                else
                {
                    return(TakePopulationDamage(hit, damage, dice));
                }
            }
            else if (Population.Any())
            {
                return(TakePopulationDamage(hit, damage, dice));
            }
            else if (Units.Any())
            {
                return(TakeUnitDamage(hit, damage, dice));
            }
            else
            {
                return(damage);                // nothing to damage
            }
        }
Beispiel #8
0
 protected override bool IsFirstSymbolUnit(char symbol)
 {
     return(Units.Any(unit => unit.IsFirstSymbol(symbol)));
 }
Beispiel #9
0
 public virtual bool HasProcessableCandidates()
 {
     return(Units.Any());
 }
Beispiel #10
0
 public int TotalDebuffCount(SNOPower power)
 {
     return(Units.Any() ? TargetUtil.DebuffCount(new List <SNOPower> {
         power
     }, Units) : 0);
 }
Beispiel #11
0
        protected static bool DoParseMutliple(string text, out TimeSpan[] timeSpans, TimeSpanParserOptions options = null, int max = int.MaxValue)
        {
            if (options == null)
            {
                options = new TimeSpanParserOptions(); //TODO: default options object
            }
            Units[] badDefaults = new Units[] { Units.Error, Units.ErrorTooManyUnits, Units.ErrorAmbiguous };
            if (badDefaults.Any(bad => options.UncolonedDefault == bad) || badDefaults.Any(bad => options.ColonedDefault == bad))
            {
                throw new ArgumentException("Bad default selection.");
            }

            //TODO (or not: overly limited: requires groups of 3 numbers or fails): https://social.msdn.microsoft.com/Forums/en-US/431d51f9-8003-4c72-ba1f-e830c6ad75ba/regex-to-match-all-number-formats-used-around-the-world?forum=regexp

            text = text.Normalize(NormalizationForm.FormKC); // fixing any fullwidth characters
            text = text.Replace('_', ' ');

            var numberFormatInfo = (options.FormatProvider == null)
                ? CultureInfo.CurrentCulture.NumberFormat
                : NumberFormatInfo.GetInstance(options.FormatProvider);

            string decimalSeparator = numberFormatInfo.NumberDecimalSeparator;
            bool   allowThousands   = ((options.NumberStyles & NumberStyles.AllowThousands) > 0);
            string groupSeparator   = allowThousands ?
                                      Regex.Escape(numberFormatInfo.NumberGroupSeparator) : string.Empty;
            string plusMinus = numberFormatInfo.PositiveSign + numberFormatInfo.NegativeSign; // TODO?

            if (options.AllowDotSeparatedDayHours && decimalSeparator != ".")
            {
                decimalSeparator += ".";                                                                                                                  // always also need a dot for day.hour separation (unless that's off)
            }
            string zeroRegexStr = @"([+-]?:)?(([-+]?[0" + groupSeparator + "]*[" + Regex.Escape(decimalSeparator) + @"}]?[0]+(?:[eE][-+]?[0-9]+)?)\:?)+"; // 0:00:00 0e100 0.00:00:00:0.000:0e20:00
            string numberRegexStr;

            //TODO: +- at start or end depending on culture
            if (allowThousands)
            {
                numberRegexStr = @"([+-]?:)?(([-+]?([0-9]+([" + groupSeparator + "]?)(?=[0-9]))*[" + Regex.Escape(decimalSeparator) + @"}]?[0-9]+(?:[eE][-+]?[0-9]+)?)\:?)+";
            }
            else
            {
                numberRegexStr = @"([+-]?:)?(([-+]?[0-9]*[" + Regex.Escape(decimalSeparator) + @"}]?[0-9]+(?:[eE][-+]?[0-9]+)?)\:?)+";
            }

            // regex notes:
            // - floating point numbers separated by (or ending with) with colon.
            // - matches a number: 30
            // - also matches floating point number: +3e-10
            // - also allows colons: 10:20:21.70
            // - or crazy combo: 10.2e+2:20:21.70 (note: the dot is sometimes a day separator)
            // - regex101.com for testing

            // weird things:
            // - supports mixed formats like "22:11h 10s" (=22:11:10)

            // may change:
            // - starting colon will be ignored, ":30" treated as "30"
            // - but not after: 3: (treated as "3")
            // - in future, starting-colon numbers may get their own option


            var numberRegex = new Regex(numberRegexStr); // TODO: re-use regex + RegexOptions.Compiled
            var zeroRegex   = new Regex(zeroRegexStr);

            List <ParserToken> tokens = new List <ParserToken>();

            var matches = numberRegex.Matches(text);

            for (int i = 0; i < matches.Count; i++)   //  foreach (Match match in matches) {
            {
                Match match = matches[i];

                int numberEnd      = match.Index + match.Length;
                int nextMatchIndex = (i + 1 < matches.Count ? matches[i + 1].Index : text.Length);
                int suffixLength   = nextMatchIndex - numberEnd;

                //Console.WriteLine($"text:{text}. match[{i}]: suffixLength:{suffixLength}");

                string number  = match.Value;
                string suffix  = text.Substring(numberEnd, suffixLength);
                bool   coloned = number.Contains(':');

                //Console.WriteLine($"part[{i}]: num:'{number}', suffix:'{suffix}', colon:{coloned}");

                Units suffixUnits = ParseSuffix(suffix);

                //TODO: ignore initial colon (now) if requested

                if (coloned)
                {
                    var parts = number.Split(':');
                    if (parts.Length <= 1)
                    {
                        timeSpans = null; //  timeSpans = builder.FinalSpans(); // foundTimeSpans.ToArray();
                        return(false);    // something went wrong. should never happen
                    }

                    var token = new ColonedToken();
                    token.options   = options;
                    token.GivenUnit = suffixUnits;

                    //TODO: maybe don't do this if parsing a localization that doesn't use a dot separator for days.months ?
                    if (parts != null && parts.Length >= 1 && parts[0].Contains('.'))
                    {
                        token.firstColumnContainsDot = true;                                         //Note: specifically '.' and NOT the regional decimal separator
                        token.firstColumnRightHalf   = ParseNumber(parts[0].Split('.')[1], options); //TODO: error checking
                    }

                    if (string.IsNullOrWhiteSpace(parts[0]))
                    {
                        // TODO
                        token.startsWithColon = true;
                        parts[0] = null;
                    }
                    else if (parts != null && parts.Length >= 1 && parts[0] != null && parts[0].Trim() == "-")
                    {
                        //don't attempt to parse
                        parts[0] = null;
                        token.negativeColoned = true;
                        token.startsWithColon = true;
                    }
                    else if (parts != null && parts.Length >= 1 && parts[0] != null && parts[0].Trim() == "+")     //TODO tidy
                    {
                        parts[0] = null;
                        token.startsWithColon = true;
                    }

                    token.colonedColumns = parts.Select(p => ParseNumber(p, options)).ToArray();
                    tokens.Add(token);

                    //Console.WriteLine($"token: {token}");
                }
                else
                {
                    //decimal parsedNumber;
                    //bool numberSuccess = decimal.TryParse(number, options.NumberStyles, options.FormatProvider, out parsedNumber);

                    var token = new OneUnitToken();
                    token.options        = options;
                    token.GivenUnit      = suffixUnits;
                    token.uncolonedValue = ParseNumber(number, options);

                    tokens.Add(token);

                    //Console.WriteLine($"token= {token}");
                }
            }

            List <TimeSpan?> timespans   = new List <TimeSpan?>();
            ParserToken      last        = null;
            bool             willSucceed = true;

            foreach (ParserToken token in tokens)
            {
                if (token.IsUnitlessFailure() || token.IsOtherFailure())
                {
                    //Console.WriteLine($"wont succeed..." + (!options.FailOnUnitlessNumber ? "or actually it might" : ""));
                    //throw new ArgumentException("failed to parse because of a unitless number.");
                    willSucceed = false;
                    if (last != null)
                    {
                        timespans.Add(last.ToTimeSpan());
                    }
                    last = null;
                    continue;
                }

                if (last != null)
                {
                    bool success = last.TryMerge(token, out ParserToken newToken);
                    if (!success)
                    {
                        throw new ArgumentException("Failed to parse. Probably because of a unitless number.");
                    }

                    if (newToken == null)
                    {
                        timespans.Add(last.ToTimeSpan());
                        last = token;
                    }
                    else
                    {
                        last = newToken;
                    }
                }
                else
                {
                    last = token;
                }
            }
            if (last != null)
            {
                timespans.Add(last.ToTimeSpan());
            }

            timeSpans = timespans.Where(t => t.HasValue).Select(t => t.Value).ToArray(); // just the nonnull for now
            return(!options.FailOnUnitlessNumber || willSucceed);
        }
Beispiel #12
0
 public int TotalDebuffCount(IEnumerable <SNOPower> powers)
 {
     return(Units.Any() ? TargetUtil.DebuffCount(powers, Units) : 0);
 }
Beispiel #13
0
 public bool IsAlive()
 {
     return(Units.Any(u => ((Unit)u).IsAlive));
 }
 public bool HaveUnit(Location location)
 {
     return(Units.Any(u => u.Location.X == location.X && u.Location.Y == location.Y));
 }
Beispiel #15
0
 private bool IsOpen(int x, int y)
 {
     return(Spec.FloorMap[x][y] && !Units.Any((u) => u.X == x && u.Y == y && u.Health > 0));
 }
Beispiel #16
0
 public float DebuffedPercent(IEnumerable <SNOPower> powers)
 {
     return(Units.Any() ? DebuffedCount(powers) / Units.Count : 0);
 }
Beispiel #17
0
 public int DebuffedCount(IEnumerable <SNOPower> powers)
 {
     return(Units.Any() ? TargetUtil.MobsWithDebuff(powers, Units) : 0);
 }
Beispiel #18
0
 private void Initialize()
 {
     if (!Stores.Any())
     {
         Stores.Add(new Store {
             Descr = "Главный склад", IsAccount = true
         });
         Stores.Add(new Store {
             Descr = "Склад 1", IsAccount = true
         });
         Stores.Add(new Store {
             Descr = "Склад 2", IsAccount = false
         });
         SaveChanges();
     }
     if (!Cags.Any())
     {
         Cags.Add(new Cag {
             Descr = "АктивМед"
         });
         Cags.Add(new Cag {
             Descr = "Пакт-М"
         });
     }
     if (!Categories.Any())
     {
         Categories.Add(new GoodCategory {
             Descr = "Лекарства"
         });
         Categories.Add(new GoodCategory {
             Descr = "БАДы"
         });
     }
     if (!Units.Any())
     {
         Units.Add(new Unit {
             Descr = "Штука", Scale = 1.0, ShortDescr = "шт"
         });
         Units.Add(new Unit {
             Descr = "Упаковка", Scale = 1.0, ShortDescr = "уп"
         });
     }
     if (!Components.Any())
     {
         Components.Add(new Component {
             Descr = "Нафазолин"
         });
         Components.Add(new Component {
             Descr = "Амбазон"
         });
     }
     if (!Goods.Any())
     {
         Goods.Add(new Good {
             Descr = "Нафтизин"
         });
         Goods.Add(new Good {
             Descr = "Фарингосепт"
         });
     }
 }
Beispiel #19
0
 public bool HasUnit(string name)
 {
     return(Units.Any(unit => unit.IsEqual(name)));
 }