コード例 #1
0
        private void HandleEnemyUnitMove(bool visible)
        {
            _log.Debug($"HandleEnemyUnitMove() set new coords from:{NextEnemyUnitToMove.Coordinates} movement={NextEnemyUnitToMove.Movement} [unit:{NextEnemyUnitToMove.UnitNumber}]");

            if (NextEnemyUnitMoveCoords != null)
            {
                if (_units.IsUnitWithinAttackRange(NextEnemyUnitToMove, _alliedEnemyMatrix))
                {
                    NextEnemyUnitToMove.ClearPath();
                    NextEnemyUnitToMove.Movement = 0;
                    NextEnemyUnitToMove.Flash    = null;
                    //_units.PlayerCheckForPossibleAttack(NextEnemyUnitToMove, _alliedEnemyMatrix);
                    //FindEnemyUnitToAttackFrom();
                }
                else if (IsCellBlocked(NextEnemyUnitToMove, NextEnemyUnitMoveCoords.Col, NextEnemyUnitMoveCoords.Row))
                {
                    NextEnemyUnitToMove.ClearPath();
                    NextEnemyUnitToMove.Movement = 0;
                }
                else
                {
                    NextEnemyUnitToMove.Col = NextEnemyUnitMoveCoords.Col;
                    NextEnemyUnitToMove.Row = NextEnemyUnitMoveCoords.Row;

                    NextEnemyUnitToMove.Movement -= _map[NextEnemyUnitToMove.Col, NextEnemyUnitToMove.Row].GroundUnitTerrainModifier;
                    NextEnemyUnitMoveCoords       = NextEnemyUnitToMove.GetNextWaypoint(NextEnemyUnitToMove.Col, NextEnemyUnitToMove.Row);

                    WakeAdjacentAlliedUnits();

                    _log.Debug($"HandleEnemyUnitMove() to:{NextEnemyUnitToMove.Coordinates} movement = {NextEnemyUnitToMove.Movement} [unit:{NextEnemyUnitToMove.UnitNumber}]");
                }

                _totalUnitsMovedOrAttacked++;
            }

            if (NextEnemyUnitToMove.IsAtDestination)
            {
                _log.Debug("HandleEnemyUnitMove() unit is at destination");
                _units.PlayerCheckForPossibleAttack(NextEnemyUnitToMove, _alliedEnemyMatrix);
                NextEnemyUnitToMove.Command = UNITCOMMAND.Destination;
                NextEnemyUnitToMove.Sleep   = true;               //TODO: if allied unit comes in range, then wake and attack
                EnemyUnitQueue.Dequeue();
                NextEnemyUnitToMove = null;
            }
            else
            {
                NextEnemyUnitToMove.Flash = new UnitFlash(2, 0.2f, new Color(100, 200, 100));
            }
        }
コード例 #2
0
        public void HandleEnemy(GameTime gameTime, bool visible)
        {
            if (_units.CurrentTurn == NATIONALITY.Germany)
            {
                //TODO: need to detect when units are blocked or all idle.

                if (NextEnemyUnitToMove == null)
                {
                    NextEnemyUnitToMove = FindEnemyUnitToMove();
                }

                if (NextEnemyUnitToMove != null)
                {
                    switch (NextEnemyUnitToMove.EnemyUnitMode)
                    {
                    case 0:
                        if (_units.IsUnitWithinAttackRange(NextEnemyUnitToMove, _alliedEnemyMatrix))
                        {
                            NextEnemyUnitToMove.ClearPath();
                            NextEnemyUnitToMove.Movement = 0;
                            NextEnemyUnitToMove.Flash    = null;
                            FindEnemyUnitToAttackFrom();
                            NextEnemyUnitToMove.EnemyUnitMode = 1;
                            NextEnemyUnitToMove.Flash         = new UnitFlash(2, 0.2f, new Color(200, 100, 100));
                        }
                        else
                        {
                            NextEnemyUnitToMove.EnemyUnitMode = 3;
                        }
                        break;

                    case 1:
                        if (!IsUnitFlashing(visible))
                        {
                            NextEnemyUnitToMove.EnemyUnitMode = 2;
                        }
                        break;

                    case 2:
                        if (HandleEnemyAttackingAllied(visible))
                        {
                            NextEnemyUnitToMove.EnemyUnitMode = 5;
                        }
                        break;

                    case 3:
                        NextEnemyUnitToMove.Flash         = new UnitFlash(2, 0.2f, new Color(100, 200, 100));
                        NextEnemyUnitToMove.EnemyUnitMode = 4;
                        break;

                    case 4:
                        if (NextEnemyUnitToMove.Movement < 0.1)
                        {
                            if (_units.IsUnitWithinAttackRange(NextEnemyUnitToMove, _alliedEnemyMatrix))
                            {
                                NextEnemyUnitToMove.ClearPath();
                                NextEnemyUnitToMove.Movement = 0;
                                NextEnemyUnitToMove.Flash    = null;
                                FindEnemyUnitToAttackFrom();
                                NextEnemyUnitToMove.EnemyUnitMode = 1;
                                NextEnemyUnitToMove.Flash         = new UnitFlash(2, 0.2f, new Color(200, 100, 100));
                                return;
                            }

                            NextEnemyUnitToMove.EnemyUnitMode = 5;
                            return;
                        }

                        if (!IsUnitFlashing(visible))
                        {
                            HandleEnemyUnitMove(visible);
                        }
                        break;

                    case 5:
                        EnemyUnitQueue.Dequeue();
                        NextEnemyUnitToMove = null;
                        break;
                    }
                }

                // forallunits((Movement == 0 && UnitHasAttackedThisTurn) || Sleep || SkipTurn)
                if (_units.IsTurnComplete(NATIONALITY.Germany) || EnemyUnitQueue.Count == 0)
                {
                    //_log.Debug("HandleEnemy() turn complete");

                    _units.SetTurn(NATIONALITY.USA);
                    EnemyUnitAttacking    = null;
                    AlliedUnitUnderAttack = null;
                    NextEnemyUnitToMove   = null;
                }
            }
        }