Пример #1
0
        public void SetPreviousUnit(UnitCalculation previous, int frame)
        {
            if (FrameLastSeen == frame)
            {
                return;
            }

            TargetPriorityCalculation = previous.TargetPriorityCalculation;
            PreviousUnit = previous.Unit;
            var vector = new Vector2(Unit.Pos.X - PreviousUnit.Pos.X, Unit.Pos.Y - PreviousUnit.Pos.Y);

            Position = new Vector2(Unit.Pos.X + vector.X, Unit.Pos.Y + vector.Y);

            Vector          = vector / (FrameLastSeen - frame);
            AverageVector   = Vector;
            Velocity        = Vector.LengthSquared();
            AverageVelocity = Velocity;

            //PreviousUnits = previous.PreviousUnits;
            //PreviousUnits[frame] = Unit;

            //var oneSecondAgo = frame - (int)oneSecondInFrames;
            //if (PreviousUnits.Count() > 50)
            //{
            //    PreviousUnits.Remove(PreviousUnits.Keys.First());
            //}

            //Unit oneSecondOldUnit;
            //if (PreviousUnits.TryGetValue(oneSecondAgo, out oneSecondOldUnit))
            //{
            //    vector = new Vector2(Unit.Pos.X - oneSecondOldUnit.Pos.X, Unit.Pos.Y - oneSecondOldUnit.Pos.Y);
            //    AverageVector = vector / (oneSecondAgo - frame);
            //    AverageVelocity = AverageVector.LengthSquared();
            //}
        }
Пример #2
0
 bool ShouldTargetDetection(UnitCalculation unitCalculation)
 {
     if (unitCalculation.NearbyAllies.Any(e => SharkyUnitData.CloakableAttackers.Contains((UnitTypes)e.Unit.UnitType)))
     {
         if (unitCalculation.NearbyEnemies.Any(e => SharkyUnitData.DetectionTypes.Contains((UnitTypes)e.Unit.UnitType) || SharkyUnitData.AbilityDetectionTypes.Contains((UnitTypes)e.Unit.UnitType)))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
        public TargetPriorityCalculation CalculateTargetPriority(UnitCalculation unitCalculation, int frame)
        {
            var allies  = unitCalculation.NearbyAllies.Where(e => e.UnitClassifications.Contains(UnitClassification.DefensiveStructure) || e.UnitClassifications.Contains(UnitClassification.ArmyUnit));
            var enemies = unitCalculation.NearbyEnemies.Where(e => e.UnitClassifications.Contains(UnitClassification.DefensiveStructure) || e.UnitClassifications.Contains(UnitClassification.ArmyUnit));

            var calculation = CalculateTargetPriority(allies, enemies);

            if (ShouldTargetDetection(unitCalculation))
            {
                calculation.TargetPriority = TargetPriority.KillDetection;
                return(calculation);
            }

            calculation.FrameCalculated = frame;
            return(calculation);
        }
Пример #4
0
 public bool CanDamage(UnitCalculation attacker, UnitCalculation victim)
 {
     if (attacker.Damage == 0)
     {
         return(false);
     }
     if (attacker.DamageAir && (victim.Unit.IsFlying || victim.Unit.UnitType == (uint)UnitTypes.PROTOSS_COLOSSUS || victim.Unit.BuffIds.Contains((uint)Buffs.GRAVITONBEAM)))
     {
         return(true);
     }
     if (attacker.DamageGround && !victim.Unit.IsFlying)
     {
         return(true);
     }
     return(false);
 }
Пример #5
0
        public UnitCommander(UnitCalculation unitCalculation)
        {
            UnitCalculation = unitCalculation;

            BestTarget = null;
            Claimed    = false;

            LastAbility        = Abilities.INVALID;
            LastTargetLocation = null;
            LastTargetTag      = 0;
            AbilityOrderTimes  = new Dictionary <Abilities, int>();
            LoadTimes          = new Dictionary <ulong, int>();
            RetreatPathFrame   = 0;
            RetreatPath        = new List <Vector2>();
            RetreatPathIndex   = 0;

            LastOrderFrame = 0;
        }