private void ChooseTarget(MechAiStateMachine stateMachine, Battle battle)
        {
            Team enemyTeam = battle.GetOtherTeam(stateMachine.Owner.Team);

            List <Mech> possibleTargets = new List <Mech>();

            foreach (Mech mech in enemyTeam.Mechs)
            {
                if (mech.IsAlive)
                {
                    possibleTargets.Add(mech);
                }
            }

            if (possibleTargets.Count == 0)
            {
                stateMachine.CurrentMainEnemy = null;
                stateMachine.FollowingPath    = false;
            }
            else
            {
                int enemyNumber = stateMachine.Rng.Next(0, possibleTargets.Count);
                stateMachine.CurrentMainEnemy = possibleTargets[enemyNumber];

                stateMachine.DesiredDistance = stateMachine.Owner.MainGun.Range * 0.75f;
            }
        }
        private void ChooseTarget(MechAiStateMachine stateMachine, Battle battle)
        {
            Team enemyTeam = battle.GetOtherTeam(stateMachine.Owner.Team);

            List <Mech> possibleTargets = new List <Mech>();

            foreach (Mech mech in enemyTeam.Mechs)
            {
                if (mech.IsAlive)
                {
                    possibleTargets.Add(mech);
                }
            }

            if (possibleTargets.Count == 0)
            {
                currentTarget = null;
                stateMachine.FollowingPath = false;
            }
            else
            {
                int lowestHp = int.MaxValue;
                foreach (Mech target in possibleTargets)
                {
                    if (target.CurrHp < lowestHp)
                    {
                        currentTarget = target;
                        lowestHp      = target.CurrHp;
                    }
                }
            }
        }
예제 #3
0
 public void EnterState(MechAiStateMachine stateMachine, Battle battle)
 {
     if (stateMachine.CurrentMainEnemy != null)
     {
         Pathfind(stateMachine, battle);
     }
 }
예제 #4
0
        private void PlanLongTermMovement(MechAiStateMachine stateMachine, GameTime gameTime, Battle battle)
        {
            if (stateMachine.CurrentMainEnemy != null && !stateMachine.EnemyAtDesiredDistance( ))
            {
                if (stateMachine.Path.Count == 0 || (stepsSincePathfinder > 100 && stateMachine.Rng.NextDouble() > 0.5)) // This randomization helps make the mechs pathfind on diffrent cycles
                {
                    Pathfind(stateMachine, battle);
                }

                stepsSincePathfinder++;
            }
        }
예제 #5
0
 public Mech(Mech source, int id)
 {
     name        = source.name;
     this.mechId = id;
     mainGun     = source.MainGun;
     maxSpeed    = source.MaxSpeed;
     currHp      = source.currHp;
     maxHp       = source.maxHp;
     mechType    = source.mechType;
     mechColor   = source.mechColor;
     size        = source.size;
     brain       = new MechAiStateMachine(source.brain);
 }
예제 #6
0
 private void PlanNextMove(MechAiStateMachine stateMachine, Battle battle)
 {
     if (stateMachine.FollowingPath && stateMachine.Path.Count > stateMachine.NodeOnPath)
     {
         if (stateMachine.EnemyAtDesiredDistance())
         {
             stateMachine.CurrentMovementTarget = stateMachine.Owner.Position;
         }
         else
         {
             stateMachine.CurrentMovementTarget = stateMachine.Path[stateMachine.NodeOnPath];
         }
     }
 }
예제 #7
0
 private void UpdatePath(MechAiStateMachine stateMachine, Battle battle)
 {
     if (stateMachine.FollowingPath)
     {
         float closeEnough = Math.Max(stateMachine.Owner.Size.X, stateMachine.Owner.Size.Y) * 1.5f;
         if ((stateMachine.CurrentMovementTarget - stateMachine.Owner.Position).LengthSquared() < closeEnough * closeEnough)
         {
             stateMachine.NodeOnPath++;
             if (stateMachine.NodeOnPath >= stateMachine.Path.Count)
             {
                 stateMachine.FollowingPath = false;
                 return;
             }
         }
     }
 }
        public void Update(MechAiStateMachine stateMachine, GameTime gameTime, Battle battle)
        {
            if (battle.CurrentBattleState == BattleState.Unfinished)
            {
                if (stateMachine.CurrentMainEnemy == null || !stateMachine.CurrentMainEnemy.IsAlive)
                {
                    ChooseTarget(stateMachine, battle);
                }

                float gunRangeSq = stateMachine.Owner.MainGun.Range * stateMachine.Owner.MainGun.Range;

                if (stateMachine.DistanceToMainEnemySq() < gunRangeSq)
                {
                    stateMachine.Owner.FacePoint(stateMachine.CurrentMainEnemy.Position);
                    stateMachine.Owner.Shoot((int)gameTime.TotalGameTime.TotalMilliseconds);
                }
            }
        }
예제 #9
0
        private void Init(string name, int mechId, MechType mechType, int maxHp, int maxSpeed, Color color)
        {
            this.name     = name;
            this.mechType = mechType;
            this.mechId   = mechId;
            this.maxHp    = maxHp;
            this.currHp   = maxHp;
            this.maxSpeed = maxSpeed;

            Position     = Vector2.Zero;
            facing       = Vector2.UnitX;
            smoothFacing = new VectorSmoother(20);
            smoothFacing.SetSmoothVector(facing);

            size = GameSettings.GetMechSize(mechType);

            this.brain = new MechAiStateMachine(this, new BasicMoveBehavior(), new BasicAttackBehavior());

            mechColor = color;
            mainGun   = Gun.DefaultGun;
        }
예제 #10
0
        private void Pathfind(MechAiStateMachine stateMachine, Battle battle)
        {
            List <Vector2> path = Pathfinder.FindPath(stateMachine.Owner, battle.Map, stateMachine.CurrentMainEnemy.Position);

            if (path.Count > 0)
            {
                TrimPath(path);
            }

            for (int index = 0; index < path.Count; index++)
            {
                path[index] *= GameSettings.TileSize;
            }

            if (path.Count > 0)
            {
                stateMachine.FollowingPath = true;
            }

            stateMachine.Path       = path;
            stateMachine.NodeOnPath = 0;
            stepsSincePathfinder    = 0;
        }
 public void ExitState(MechAiStateMachine stateMachine, Battle battle)
 {
     // Nothing to do
 }
 public void EnterState(MechAiStateMachine stateMachine, Battle battle)
 {
     ChooseTarget(stateMachine, battle);
 }
예제 #13
0
 public void Update(MechAiStateMachine stateMachine, Microsoft.Xna.Framework.GameTime gameTime, Screens.Battle battle)
 {
     // Do nothing
 }
예제 #14
0
 public void ExitState(MechAiStateMachine stateMachine, Screens.Battle battle)
 {
 }
예제 #15
0
 public void Update(MechAiStateMachine stateMachine, GameTime gameTime, Battle battle)
 {
     PlanLongTermMovement(stateMachine, gameTime, battle);
     UpdatePath(stateMachine, battle);
     PlanNextMove(stateMachine, battle);
 }
예제 #16
0
 public void ExitState(MechAiStateMachine stateMachine, Battle battle)
 {
     stateMachine.FollowingPath = false;
     stateMachine.Path          = new List <Vector2>( );
 }