Beispiel #1
0
        // returns true if a special command is being used
        protected override bool DoSpecialCommands(UnitCommand command, GameTime gameTime)
        {
            BuildStructureCommand buildStructureCommand = command as BuildStructureCommand;

            if (buildStructureCommand != null)
            {
                moveToBuildLocation(buildStructureCommand, gameTime);
                return(true);
            }

            HarvestCommand harvestCommand = command as HarvestCommand;

            if (harvestCommand != null)
            {
                moveToHarvestLocation(harvestCommand, gameTime);
                return(true);
            }

            ReturnCargoCommand returnCargoCommand = command as ReturnCargoCommand;

            if (returnCargoCommand != null)
            {
                moveToReturnCargo(returnCargoCommand, gameTime);
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        void refreshTargetTownHall(ReturnCargoCommand command, GameTime gameTime)
        {
            timeSinceLastRefresh += (int)(gameTime.ElapsedGameTime.TotalMilliseconds * Rts.GameSpeed);
            if (timeSinceLastRefresh >= refreshTargetTownHallDelay)
            {
                timeSinceLastRefresh = 0;

                TownHall townHall = FindNearestTownHall();

                if (townHall == null)
                {
                    NextCommand();
                    return;
                }

                if (townHall != command.TargetStructure && Rts.pathFinder.Tools.IsStructureInLineOfSight(this, townHall))
                {
                    //command.TargetStructure = townHall;
                    //PathFinder.AddHighPriorityPathFindRequest(this, command, CurrentPathNode, 1, false);

                    Commands.Insert(1, new ReturnCargoCommand(this, townHall, command.Source));
                    NextCommand();
                    //InsertCommand(new ReturnCargoCommand(townHall, command.Source, 1));
                }
            }
        }
Beispiel #3
0
        //public Object WayPointsLock = new Object();

        public PathFindRequest(MoveCommand command, PathNode startNode, int priority, bool queued, bool avoidUnits)
        {
            Command    = command;
            StartNode  = startNode;
            AvoidUnits = avoidUnits;
            Priority   = priority;
            Queued     = queued;
            AttackCommand attackCommand = command as AttackCommand;

            if (attackCommand != null)
            {
                Target = attackCommand.Target;
            }
            HarvestCommand harvestCommand = command as HarvestCommand;

            if (harvestCommand != null)
            {
                Target = harvestCommand.TargetResource;
            }
            ReturnCargoCommand returnCargoCommand = command as ReturnCargoCommand;

            if (returnCargoCommand != null)
            {
                Target = returnCargoCommand.TargetStructure;
            }
        }
Beispiel #4
0
        void returnCargo(ReturnCargoCommand command)
        {
            if (CargoType == ResourceType.MineResource)
            {
                Player.Players[Team].Roks += CargoAmount;
                Player.Players[Team].Stats.RoksCounter += CargoAmount;
            }

            //if (Commands.Count > 1)
            //{
            NextCommand();

            if (Commands.Count == 0)
            {
                HarvestCommand harvestCommand = null;

                if (command.Source != null && !command.Source.Depleted)
                {
                    harvestCommand = new HarvestCommand(this, command.Source);
                }
                else
                {
                    Resource nearestResource = findNearestResource(CargoType);
                    if (nearestResource != null && !nearestResource.Depleted)
                    {
                        harvestCommand = new HarvestCommand(this, nearestResource);
                    }
                }

                if (harvestCommand != null)
                {
                    GiveCommand(harvestCommand);
                    Rts.pathFinder.AddPathFindRequest(harvestCommand, false, false, false);
                }
            }

            CargoAmount = 0;
            CargoType   = null;

            //}

            /*else if (command.Source == null || command.Source.Depleted)
             * {
             *  Resource nearestResource = findNearestResource(CargoType);
             *  if (nearestResource != null)
             *      GiveCommand(new HarvestCommand(nearestResource, 1));
             *  else
             *      NextCommand();
             * }
             * else
             *  GiveCommand(new HarvestCommand(command.Source, 1));*/
        }
Beispiel #5
0
 public ScheduledReturnCargoCommand(float scheduledTime, ReturnCargoCommand command)
     : base(scheduledTime, command, false)
 {
     ReturnCargoCommand = command;
 }
Beispiel #6
0
        void moveToReturnCargo(ReturnCargoCommand command, GameTime gameTime)
        {
            checkForSmoothPath(command, gameTime);

            refreshTargetTownHall(command, gameTime);

            clearPushStatus();
            clearHitWallStatus();

            Vector2 wayPoint = command.WayPoints[0];

            //float moveX = Util.ScaleWithGameTime(speed.X, gameTime);
            //float moveY = Util.ScaleWithGameTime(speed.Y, gameTime);
            Speed = MathHelper.Min(Speed + acceleration, MaxSpeed);
            float moveX = Util.ScaleWithGameTime(Speed, gameTime);
            float moveY = moveX;

            if (command.WayPoints.Count > 1)
            {
                if (Contains(wayPoint))
                {
                    lastWayPoint = wayPoint;
                    command.NextWayPoint(this, Rts.pathFinder);
                    return;
                }
            }

            /*else
             * {
             *  Vector2 difference = wayPoint - centerPoint;
             *  if (Math.Abs(difference.X) < moveX && Math.Abs(difference.Y) < moveY)
             *  {
             *      this.CenterPoint = wayPoint;
             *      HasMoved = true;
             *
             *      lastWayPoint = wayPoint;
             *
             *      return;
             *  }
             * }*/

            float angle = (float)Math.Atan2(wayPoint.Y - CenterPoint.Y, wayPoint.X - CenterPoint.X);

            moveX *= (float)Math.Cos(angle);
            moveY *= (float)Math.Sin(angle);

            lastMove.X       = moveX;
            lastMove.Y       = moveY;
            PrecisePosition += lastMove;
            HasMoved         = true;

            if (command.TargetStructure == null || command.TargetStructure.IsDead)
            {
                command.TargetStructure = FindNearestTownHall();
            }

            if (command.TargetStructure == null)
            {
                NextCommand();
            }

            //if (Vector2.Distance(CenterPoint, targetStructure.CenterPoint) <= Radius + targetStructure.Radius)
            if (checkForWallHit(command))
            {
                returnCargo(command);
            }

            //checkForWallHit(command);

            if (!turnTowards(wayPoint, 120 / Radius, gameTime))
            {
                Speed = MathHelper.Max(Speed - Util.ScaleWithGameTime(acceleration, gameTime), 0);
            }
        }
Beispiel #7
0
 public ScheduledReturnCargoCommand(float scheduledTime, ReturnCargoCommand command)
     : base(scheduledTime, command, false)
 {
     ReturnCargoCommand = command;
 }
Beispiel #8
0
        void returnCargo(ReturnCargoCommand command)
        {
            if (CargoType == ResourceType.Roks)
            {
                Player.Players[Team].Roks += CargoAmount;
                Player.Players[Team].Stats.RoksCounter += CargoAmount;
            }

            //if (Commands.Count > 1)
            //{
            NextCommand();

            if (Commands.Count == 0)
            {
                HarvestCommand harvestCommand = null;

                if (command.Source != null && !command.Source.Depleted)
                    harvestCommand = new HarvestCommand(this, command.Source);
                else
                {
                    Resource nearestResource = findNearestResource(CargoType);
                    if (nearestResource != null && !nearestResource.Depleted)
                        harvestCommand = new HarvestCommand(this, nearestResource);
                }

                if (harvestCommand != null)
                {
                    GiveCommand(harvestCommand);
                    Rts.pathFinder.AddPathFindRequest(harvestCommand, false, false, false);
                }
            }

            CargoAmount = 0;
            CargoType = null;

            //}
            /*else if (command.Source == null || command.Source.Depleted)
            {
                Resource nearestResource = findNearestResource(CargoType);
                if (nearestResource != null)
                    GiveCommand(new HarvestCommand(nearestResource, 1));
                else
                    NextCommand();
            }
            else
                GiveCommand(new HarvestCommand(command.Source, 1));*/
        }
Beispiel #9
0
        void refreshTargetTownHall(ReturnCargoCommand command, GameTime gameTime)
        {
            timeSinceLastRefresh += (int)(gameTime.ElapsedGameTime.TotalMilliseconds * Rts.GameSpeed);
            if (timeSinceLastRefresh >= refreshTargetTownHallDelay)
            {
                timeSinceLastRefresh = 0;

                TownHall townHall = FindNearestTownHall();

                if (townHall == null)
                {
                    NextCommand();
                    return;
                }

                if (townHall != command.TargetStructure && Rts.pathFinder.Tools.IsStructureInLineOfSight(this, townHall))
                {
                    //command.TargetStructure = townHall;
                    //PathFinder.AddHighPriorityPathFindRequest(this, command, CurrentPathNode, 1, false);

                    Commands.Insert(1, new ReturnCargoCommand(this, townHall, command.Source));
                    NextCommand();
                    //InsertCommand(new ReturnCargoCommand(townHall, command.Source, 1));
                }
            }
        }
Beispiel #10
0
        void moveToReturnCargo(ReturnCargoCommand command, GameTime gameTime)
        {
            checkForSmoothPath(command, gameTime);

            refreshTargetTownHall(command, gameTime);

            clearPushStatus();
            clearHitWallStatus();

            Vector2 wayPoint = command.WayPoints[0];

            //float moveX = Util.ScaleWithGameTime(speed.X, gameTime);
            //float moveY = Util.ScaleWithGameTime(speed.Y, gameTime);
            Speed = MathHelper.Min(Speed + acceleration, MaxSpeed);
            float moveX = Util.ScaleWithGameTime(Speed, gameTime);
            float moveY = moveX;

            if (command.WayPoints.Count > 1)
            {
                if (Contains(wayPoint))
                {
                    lastWayPoint = wayPoint;
                    command.NextWayPoint(this, Rts.pathFinder);
                    return;
                }
            }
            /*else
            {
                Vector2 difference = wayPoint - centerPoint;
                if (Math.Abs(difference.X) < moveX && Math.Abs(difference.Y) < moveY)
                {
                    this.CenterPoint = wayPoint;
                    HasMoved = true;

                    lastWayPoint = wayPoint;

                    return;
                }
            }*/

            float angle = (float)Math.Atan2(wayPoint.Y - CenterPoint.Y, wayPoint.X - CenterPoint.X);
            moveX *= (float)Math.Cos(angle);
            moveY *= (float)Math.Sin(angle);

            lastMove.X = moveX;
            lastMove.Y = moveY;
            PrecisePosition += lastMove;
            HasMoved = true;

            if (command.TargetStructure == null || command.TargetStructure.IsDead)
                command.TargetStructure = FindNearestTownHall();

            if (command.TargetStructure == null)
                NextCommand();

            //if (Vector2.Distance(CenterPoint, targetStructure.CenterPoint) <= Radius + targetStructure.Radius)
            if (checkForWallHit(command))
                returnCargo(command);

            //checkForWallHit(command);

            if (!turnTowards(wayPoint, 120 / Radius, gameTime))
            {
                Speed = MathHelper.Max(Speed - Util.ScaleWithGameTime(acceleration, gameTime), 0);
            }
        }