示例#1
0
        void updateBuildQueue(GameTime gameTime)
        {
            BuildQueueItem currentItem = BuildQueue[0];

            /*BuildUnitButtonType unitButtonType = BuildQueue[0].Type as BuildUnitButtonType;
             * if (unitButtonType != null)
             * {
             *  if (Player.Players[Team].CurrentSupply + unitButtonType.UnitType.SupplyCost > Player.Players[Team].MaxSupply)
             *  {
             *  }
             *  else
             *      currentItem.UpdateTime(gameTime);
             * }
             * else*/
            if (!currentItem.Started)
            {
                BuildUnitButtonType unitButtonType = currentItem.Type as BuildUnitButtonType;
                if (unitButtonType != null)
                {
                    if (Player.Players[Team].CurrentSupply + unitButtonType.UnitType.SupplyCost <= Player.Players[Team].MaxSupply)
                    {
                        Player.Players[Team].CurrentSupply += unitButtonType.UnitType.SupplyCost;
                        BuildQueue[0].Started = true;
                    }
                }
                else
                {
                    BuildQueue[0].Started = true;
                }
            }

            currentItem.UpdateTime(gameTime);

            if (currentItem.Done)
            {
                completeBuildQueueItem(BuildQueue[0]);
                BuildQueue.RemoveAt(0);

                if (BuildQueue.Count > 0)
                {
                    BuildUnitButtonType unitButtonType = BuildQueue[0].Type as BuildUnitButtonType;
                    if (unitButtonType != null)
                    {
                        if (Player.Players[Team].CurrentSupply + unitButtonType.UnitType.SupplyCost <= Player.Players[Team].MaxSupply)
                        {
                            Player.Players[Team].CurrentSupply += unitButtonType.UnitType.SupplyCost;
                            BuildQueue[0].Started = true;
                        }
                    }
                    else
                    {
                        BuildQueue[0].Started = true;
                    }
                }
            }
        }
示例#2
0
        void completeBuildQueueItem(BuildQueueItem item)
        {
            BuildUnitButtonType buttonType = item.Type as BuildUnitButtonType;

            if (buttonType != null)
            {
                Unit unit;
                if (buttonType.UnitType == UnitType.MeleeNublet)
                {
                    unit = new MeleeNublet(new Vector2(), Team, item.ID);
                }
                else if (buttonType.UnitType == UnitType.RangedNublet)
                {
                    unit = new RangedNublet(new Vector2(), Team, item.ID);
                }
                else
                {
                    unit = new WorkerNublet(new Vector2(), Team, item.ID);
                }

                float angle = 0;

                Vector2 spawnLocation;
                if (rallyPoints.Count > 0)
                {
                    angle = (float)Math.Atan2(rallyPoints[0].Point.Y - CenterPoint.Y, rallyPoints[0].Point.X - CenterPoint.X);
                    angle = Util.ConvertToPositiveRadians(angle);

                    /*if (angle < MathHelper.TwoPi / 4)
                     *  spawnLocation = new Vector2(Rectangle.X + Rectangle.Width - map.TileSize, Rectangle.Y + Rectangle.Height - map.TileSize / 2);
                     * else if (angle < MathHelper.TwoPi / 2)
                     *  spawnLocation = new Vector2(Rectangle.X + map.TileSize, Rectangle.Y + Rectangle.Height - map.TileSize / 2);
                     * else if (angle < MathHelper.TwoPi * .75f)
                     *  spawnLocation = new Vector2(Rectangle.X + map.TileSize, Rectangle.Y + map.TileSize / 2);
                     * else
                     *  spawnLocation = new Vector2(Rectangle.X + Rectangle.Width - map.TileSize, Rectangle.Y + map.TileSize / 2);*/

                    PathNode closestPathNode = null;
                    float    closest         = float.MaxValue;

                    foreach (PathNode pathNode in exitPathNodes)
                    {
                        float distance = Vector2.Distance(pathNode.Tile.CenterPoint, RallyPoints[0].Point);
                        if (distance < closest)
                        {
                            closestPathNode = pathNode;
                            closest         = distance;
                        }
                    }

                    if (closestPathNode != null)
                    {
                        spawnLocation = closestPathNode.Tile.CenterPoint;
                    }
                    else if (exitPathNodes.Count > 0)
                    {
                        spawnLocation = exitPathNodes[0].Tile.CenterPoint;
                    }
                    else
                    {
                        spawnLocation = new Vector2(Rectangle.X + Rts.map.TileSize, Rectangle.Y + Rectangle.Height - Rts.map.TileSize / 2);
                    }
                }
                else
                {
                    spawnLocation = new Vector2(Rectangle.X + Rts.map.TileSize, Rectangle.Y + Rectangle.Height - Rts.map.TileSize / 2);
                }

                unit.CenterPoint = new Vector2(spawnLocation.X, spawnLocation.Y);
                unit.Rotation    = angle;
                unit.InitializeCurrentPathNode();

                if (rallyPoints.Count == 0)
                {
                    unit.CheckForWallHit();
                    unit.CheckForPush();
                }
                else
                {
                    MoveCommand command = null;

                    if (rallyPoints[0].Resource != null && unit is WorkerNublet)
                    {
                        command = new HarvestCommand(unit, rallyPoints[0].Resource);
                    }
                    else
                    {
                        command = new MoveCommand(unit, RallyPoints[0].Point);
                    }

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

                    for (int i = 1; i < RallyPoints.Count; i++)
                    {
                        if (rallyPoints[i].Resource != null && unit is WorkerNublet)
                        {
                            unit.QueueCommand(new HarvestCommand(unit, rallyPoints[i].Resource));
                        }
                        else
                        {
                            unit.QueueCommand(new MoveCommand(unit, RallyPoints[i].Point));
                        }
                    }

                    unit.CheckForWallHit();
                }
            }
        }
示例#3
0
        void completeBuildQueueItem(BuildQueueItem item)
        {
            BuildUnitButtonType buttonType = item.Type as BuildUnitButtonType;
            if (buttonType != null)
            {
                Unit unit;
                if (buttonType.UnitType == UnitType.MeleeNublet)
                    unit = new MeleeNublet(new Vector2(), Team, item.ID);
                else if (buttonType.UnitType == UnitType.RangedNublet)
                    unit = new RangedNublet(new Vector2(), Team, item.ID);
                else
                    unit = new WorkerNublet(new Vector2(), Team, item.ID);

                float angle = 0;

                Vector2 spawnLocation;
                if (rallyPoints.Count > 0)
                {
                    angle = (float)Math.Atan2(rallyPoints[0].Point.Y - CenterPoint.Y, rallyPoints[0].Point.X - CenterPoint.X);
                    angle = Util.ConvertToPositiveRadians(angle);

                    /*if (angle < MathHelper.TwoPi / 4)
                        spawnLocation = new Vector2(Rectangle.X + Rectangle.Width - map.TileSize, Rectangle.Y + Rectangle.Height - map.TileSize / 2);
                    else if (angle < MathHelper.TwoPi / 2)
                        spawnLocation = new Vector2(Rectangle.X + map.TileSize, Rectangle.Y + Rectangle.Height - map.TileSize / 2);
                    else if (angle < MathHelper.TwoPi * .75f)
                        spawnLocation = new Vector2(Rectangle.X + map.TileSize, Rectangle.Y + map.TileSize / 2);
                    else
                        spawnLocation = new Vector2(Rectangle.X + Rectangle.Width - map.TileSize, Rectangle.Y + map.TileSize / 2);*/

                    PathNode closestPathNode = null;
                    float closest = float.MaxValue;

                    foreach (PathNode pathNode in exitPathNodes)
                    {
                        float distance = Vector2.Distance(pathNode.Tile.CenterPoint, RallyPoints[0].Point);
                        if (distance < closest)
                        {
                            closestPathNode = pathNode;
                            closest = distance;
                        }
                    }

                    if (closestPathNode != null)
                        spawnLocation = closestPathNode.Tile.CenterPoint;
                    else if (exitPathNodes.Count > 0)
                        spawnLocation = exitPathNodes[0].Tile.CenterPoint;
                    else
                        spawnLocation = new Vector2(Rectangle.X + Rts.map.TileSize, Rectangle.Y + Rectangle.Height - Rts.map.TileSize / 2);
                }
                else
                {
                    spawnLocation = new Vector2(Rectangle.X + Rts.map.TileSize, Rectangle.Y + Rectangle.Height - Rts.map.TileSize / 2);
                }

                unit.CenterPoint = new Vector2(spawnLocation.X, spawnLocation.Y);
                unit.Rotation = angle;
                unit.InitializeCurrentPathNode();

                if (rallyPoints.Count == 0)
                {
                    unit.CheckForWallHit();
                    unit.CheckForPush();
                }
                else
                {
                    MoveCommand command = null;

                    if (rallyPoints[0].Resource != null && unit is WorkerNublet)
                        command = new HarvestCommand(unit, rallyPoints[0].Resource);
                    else
                        command = new MoveCommand(unit, RallyPoints[0].Point);

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

                    for (int i = 1; i < RallyPoints.Count; i++)
                    {
                        if (rallyPoints[i].Resource != null && unit is WorkerNublet)
                            unit.QueueCommand(new HarvestCommand(unit, rallyPoints[i].Resource));
                        else
                            unit.QueueCommand(new MoveCommand(unit, RallyPoints[i].Point));
                    }

                    unit.CheckForWallHit();
                }
            }
        }