Exemple #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;
                    }
                }
            }
        }
Exemple #2
0
        public void RemoveFromBuildQueue(int index)
        {
            if (BuildQueue.Count <= index || index < 0)
            {
                return;
            }

            BuildUnitButtonType unitButtonType = BuildQueue[0].Type as BuildUnitButtonType;

            if (unitButtonType != null)
            {
                if (index == 0)
                {
                    if (BuildQueue[0].Started)
                    {
                        Player.Players[Team].CurrentSupply -= unitButtonType.UnitType.SupplyCost;
                    }

                    if (BuildQueue.Count > 1)
                    {
                        unitButtonType = BuildQueue[1].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[1].Started = true;
                            }
                        }
                        //Player.Players[Team].CurrentSupply += unitButtonType.UnitType.SupplyCost;
                    }
                }

                Player.Players[Team].Roks += unitButtonType.UnitType.RoksCost;
            }
            else if (BuildQueue.Count > 1)
            {
                BuildQueue[1].Started = true;
            }

            // if it was a unit, set its ID to null in the player unit array
            if (BuildQueue[index].Type is BuildUnitButtonType)
            {
                Player.Players[Team].AddUnitIDToSetNull(BuildQueue[index].ID, Rts.GameClock);
                if (Team == Player.Me.Team)
                {
                    ((Rts)Game1.Game.CurrentGameState).TransmitUnitCancelConfirmation(BuildQueue[BuildQueue.Count - 1].ID);
                }
            }

            BuildQueue.RemoveAt(index);
        }
Exemple #3
0
        public void AddToBuildQueue(ProductionButtonType buttonType, short id)
        {
            BuildQueue.Add(new BuildQueueItem(buttonType, id, buttonType.BuildTime));

            if (BuildQueue.Count == 1)
            {
                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;
                    }
                }
            }
        }
Exemple #4
0
        void giveStructureCommand(BuildUnitButtonType buttonType)
        {
            // error if not enough roks
            if (buttonType.UnitType.RoksCost > Player.Me.Roks)
            {
                playErrorSound();
                return;
            }

            // find selected structure with smallest queue
            // also counts scheduled commands
            Structure structureWithSmallestQueue = null;
            int smallest = int.MaxValue;
            foreach (RtsObject o in SelectedUnits)
            {
                Structure s = o as Structure;

                if (s.Team != Player.Me.Team)
                    return;

                if (s != null && s.Type == SelectedUnits.ActiveType && !s.UnderConstruction)
                {
                    int queueCount = s.BuildQueue.Count + Player.Me.CountScheduledStructureCommands(s);
                    if (queueCount < smallest)
                    {
                        structureWithSmallestQueue = s;
                        smallest = queueCount;
                    }
                }
            }

            // find structure with highest percent done (and smallest queue)
            float highestPercentDone = 0;
            foreach (RtsObject o in SelectedUnits)
            {
                Structure s = o as Structure;

                if (s != null)
                {
                    if (s != null && s.Type == SelectedUnits.ActiveType && !s.UnderConstruction)
                    {
                        if (smallest > 0 && s.BuildQueue.Count == smallest)
                        {
                            if (s.BuildQueue[0].PercentDone > highestPercentDone)
                            {
                                structureWithSmallestQueue = s;
                                highestPercentDone = s.BuildQueue[0].PercentDone;
                            }
                        }
                    }
                }
            }

            // give command to the structure
            if (structureWithSmallestQueue != null)
            {
                //if (structureWithSmallestQueue.AddToBuildQueue(buttonType))
                if (structureWithSmallestQueue.CanAddToBuildQueue(buttonType))
                {
                    //float scheduledTime = gameClock + connection.AverageRoundtripTime;
                    short unitID = Player.Me.UnitIDCounter++;

                    Player.Me.ScheduledActions.Add(new ScheduledStructureCommand(currentScheduleTime, structureWithSmallestQueue, buttonType, unitID));
                    Player.Me.Roks -= buttonType.UnitType.RoksCost;

                    NetOutgoingMessage msg = netPeer.CreateMessage();

                    msg.Write(MessageID.STRUCTURE_COMMAND);
                    msg.Write(currentScheduleTime);
                    msg.Write(structureWithSmallestQueue.Team);
                    msg.Write(structureWithSmallestQueue.ID);
                    msg.Write(buttonType.ID);
                    msg.Write(unitID);

                    netPeer.SendMessage(msg, connection, NetDeliveryMethod.ReliableOrdered);

                    //Player.Me.Roks -= buttonType.UnitType.RoksCost;
                }
            }
        }
Exemple #5
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();
                }
            }
        }