示例#1
0
        bool buildStructure(BuildStructureCommand command)
        {
            bool allowBuild = Rts.pathFinder.Tools.CanStructureBePlaced(command.StructureLocation, command.StructureType.Size, this, command.StructureType.CutCorners);

            if (allowBuild)
            {
                //if (command.StructureType == StructureType.Barracks)
                //    new Barracks(command.StructureLocation, this, Team);

                Structure structure;

                if (command.StructureType == StructureType.TownHall)
                {
                    structure = new TownHall(command.StructureLocation, this, Team);
                }
                else
                {
                    structure = new Structure(command.StructureType, command.StructureLocation, this, Team);
                }

                CenterPoint = structure.CenterPoint;
                //IgnoringCollision = true;
                Targetable = false;
                Busy       = true;
                Building   = true;
                Unit.RemoveUnit(this);
            }

            return(allowBuild);
        }
示例#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));
                }
            }
        }
示例#3
0
        public bool CheckForEntrance(WorkerNublet worker)
        {
            if (worker.CargoAmount == CARGO_PER_TRIP && worker.CargoType == Type)
            {
                TownHall townHall = findNearestTownHall(worker);
                if (townHall != null)
                {
                    worker.InsertCommand(new ReturnCargoCommand(worker, townHall, this));
                }
                else
                {
                    worker.NextCommand();
                }
                return(false);
            }

            if (Amount - (workersInside.Count * CARGO_PER_TRIP) <= 0)
            {
                return(false);
            }

            if (timeSinceLastEntrance >= ALLOW_ENTRANCE_DELAY)
            {
                timeSinceLastEntrance = 0;

                letWorkerEnter(worker);

                return(true);
            }

            return(false);
        }
示例#4
0
        public TownHall FindNearestTownHall()
        {
            TownHall nearestTownHall = null;
            float    nearest         = int.MaxValue;

            foreach (TownHall townHall in TownHall.TownHalls)
            {
                if (townHall.Team != Team)
                {
                    continue;
                }

                float distance = Vector2.DistanceSquared(CenterPoint, townHall.CenterPoint);
                if (distance < nearest)
                {
                    nearestTownHall = townHall;
                    nearest         = distance;
                }
            }

            return(nearestTownHall);
        }
示例#5
0
        TownHall findNearestTownHall(Unit unit)
        {
            TownHall nearestTownHall = null;
            float    nearest         = int.MaxValue;

            foreach (TownHall townHall in TownHall.TownHalls)
            {
                if (townHall.Team != unit.Team || townHall.UnderConstruction)
                {
                    continue;
                }

                float distance = Vector2.DistanceSquared(CenterPoint, townHall.CenterPoint);
                if (distance < nearest)
                {
                    nearestTownHall = townHall;
                    nearest         = distance;
                }
            }

            return(nearestTownHall);
        }
示例#6
0
        public void ReturnCargoToNearestTownHall(Resource source)
        {
            if (CargoAmount == 0)
            {
                return;
            }

            TownHall nearestTownHall = FindNearestTownHall();

            if (nearestTownHall != null)
            {
                //if (Commands.Count == 0 || !(Commands[0] is HarvestCommand))
                //{
                //    Resource nearestResource = findNearestResource(CargoType);
                //    if (nearestResource != null)
                //        InsertCommand(new HarvestCommand(nearestResource, 1));
                //}

                stop();

                InsertCommand(new ReturnCargoCommand(this, nearestTownHall, source));
            }
        }
示例#7
0
        void releaseWorker(WorkerNublet worker)
        {
            worker.CargoType = Type;

            int oldAmount = Amount;

            Amount            -= CARGO_PER_TRIP;
            worker.CargoAmount = oldAmount - Amount;

            // only decrement amount if worker is on my team,
            // else rely on status updates for amount
            //if (worker.Team != Player.Me.Team)
            //Amount = oldAmount;

            //int newAmount = (int)(MathHelper.Max(Amount - CARGO_PER_TRIP, 0));
            //worker.CargoAmount = Amount - newAmount;
            //Amount = newAmount;

            workersInside.Remove(worker);

            TownHall townHall = findNearestTownHall(worker);

            float angle;

            if (townHall == null)
            {
                angle = 0;
            }
            else
            {
                angle = (float)Math.Atan2(townHall.Rectangle.Y - CenterPoint.Y, townHall.Rectangle.X - CenterPoint.X);
            }

            PathNode closestPathNode = null;

            if (townHall != null)
            {
                float closest = float.MaxValue;

                foreach (PathNode pathNode in exitPathNodes)
                {
                    float distance = Vector2.Distance(pathNode.Tile.CenterPoint, townHall.CenterPoint);
                    if (distance < closest)
                    {
                        closestPathNode = pathNode;
                        closest         = distance;
                    }
                }
            }

            if (closestPathNode != null)
            {
                worker.CenterPoint = closestPathNode.Tile.CenterPoint;
            }
            else if (exitPathNodes.Count > 0)
            {
                worker.CenterPoint = exitPathNodes[0].Tile.CenterPoint;
            }
            else
            {
                worker.CenterPoint = centerPoint;
            }

            //worker.CenterPoint = centerPoint + new Vector2((Radius + worker.Radius) * (float)Math.Cos(angle), (Radius + worker.Radius) * (float)Math.Sin(angle));
            worker.Rotation = angle;

            worker.FinishHarvesting();

            if (townHall != null && worker.Commands.Count <= 0)
            {
                //worker.GiveCommand(new ReturnCargoCommand(townHall, 1));
                //worker.QueueCommand(new HarvestCommand(this, 1));
                worker.ReturnCargoToNearestTownHall(this);
            }

            checkForStatusUpdate(Rts.netPeer, Rts.connection, worker.Team);
        }
示例#8
0
        bool buildStructure(BuildStructureCommand command)
        {
            bool allowBuild = Rts.pathFinder.Tools.CanStructureBePlaced(command.StructureLocation, command.StructureType.Size, this, command.StructureType.CutCorners);

            if (allowBuild)
            {
                //if (command.StructureType == StructureType.Barracks)
                //    new Barracks(command.StructureLocation, this, Team);

                Structure structure;

                if (command.StructureType == StructureType.TownHall)
                    structure = new TownHall(command.StructureLocation, this, Team);
                else
                    structure = new Structure(command.StructureType, command.StructureLocation, this, Team);

                CenterPoint = structure.CenterPoint;
                //IgnoringCollision = true;
                Targetable = false;
                Busy = true;
                Building = true;
                Unit.RemoveUnit(this);
            }

            return allowBuild;
        }