Exemple #1
0
        public Resource(ResourceType type, Point location, int size)
            : base(new Rectangle(location.X * Rts.map.TileSize, location.Y * Rts.map.TileSize, size * Rts.map.TileSize, size * Rts.map.TileSize))
        {
            ID = idCounter++;
            ResourceArray[ID] = this;

            Type = type;
            Texture = type.NormalTexture;
            Amount = type.AmountOfResources;
            Size = size;
            Radius = (size * Rts.map.TileSize) / 2f;

            X = location.X;
            Y = location.Y;

            setOccupiedPathNodes();

            Resources.Add(this);
        }
Exemple #2
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));*/
        }
Exemple #3
0
 static ResourceType()
 {
     Roks = new ResourceType();
     Roks.Name = "Roks";
     Roks.NormalTexture = Game1.Game.Content.Load<Texture2D>("WC2Gold");
     Roks.DepletedTexture = Game1.Game.Content.Load<Texture2D>("WC2Gold");
     Roks.CargoTexture = Game1.Game.Content.Load<Texture2D>("rock");
     Roks.AmountOfResources = 2500;
     Roks.Size = 3;
 }
Exemple #4
0
        Resource findNearestResource(ResourceType resourceType)
        {
            Resource nearestResource = null;
            float nearest = int.MaxValue;

            foreach (Resource resource in Resource.Resources)
            {
                if (resource.Type != resourceType || resource == null || resource.Depleted)
                    continue;

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

            return nearestResource;
        }