Exemplo n.º 1
0
            // return -1 if x is better target, 1 otherwise
            public int Compare(CombatScoreItem x, CombatScoreItem y)
            {
                var xArmorType = x.Target.CombatObject.Stats.Base.Armor;
                var yArmorType = y.Target.CombatObject.Stats.Base.Armor;

                if (x.Score == y.Score && (xArmorType == ArmorType.Building3 || yArmorType == ArmorType.Building3))
                {
                    if (xArmorType == ArmorType.Building3 && yArmorType == ArmorType.Building3)
                    {
                        var xDistance = tileLocator.RadiusDistance(attacker.Location(),
                                                                   attacker.Size,
                                                                   x.Target.CombatObject.Location(),
                                                                   x.Target.CombatObject.Size);

                        var yDistance = tileLocator.RadiusDistance(attacker.Location(),
                                                                   attacker.Size,
                                                                   y.Target.CombatObject.Location(),
                                                                   y.Target.CombatObject.Size);
                        return(xDistance.CompareTo(yDistance));
                    }
                    return(xArmorType == ArmorType.Building3 ? 1 : -1);
                }

                return(x.Score.CompareTo(y.Score) * -1);
            }
Exemplo n.º 2
0
        private bool HaveNoBuilding(Requirement req, IEnumerable <IStructure> objects, uint x, uint y, byte size)
        {
            foreach (var obj in objects)
            {
                if (req.Type != obj.Type || obj.Lvl > req.MaxLvl || obj.Lvl < req.MinLvl)
                {
                    continue;
                }

                int dist = tileLocator.RadiusDistance(obj.PrimaryPosition, obj.Size, new Position(x, y), size);

                if (dist > req.MaxDist || dist < req.MinDist)
                {
                    continue;
                }

                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        public override bool Validate(IStructure builder, ushort type, uint x, uint y, byte size)
        {
            var effects = builder.Technologies.GetAllEffects(EffectInheritance.Upward).ToArray();

            foreach (var req in Requirements)
            {
                int radius = formula.GetAwayFromRadius(effects, req.MinDist, type);

                // Copy for local closure
                Requirement req1 = req;
                if (builder.City.Any(structure =>
                                     structure.Type == req1.Type &&
                                     structure.Lvl >= req1.MinLvl &&
                                     structure.Lvl <= req1.MaxLvl &&
                                     tileLocator.RadiusDistance(structure.PrimaryPosition, structure.Size, new Position(x, y), size) < radius + 1))
                {
                    return(false);
                }
            }

            return(true);
        }