Esempio n. 1
0
        void UseResourcesFromFaction(string faction, int usedResources)
        {
            foreach (Building building in manager.GetBuildingsByFaction(faction))
            {
                if (building is ResourceBuilding && !building.IsDestroyed)
                {
                    ResourceBuilding resourceBuilding = (ResourceBuilding)building;

                    //this buildings has not resources left, let's skip it
                    if (resourceBuilding.resourcesGenerated <= 0)
                    {
                        continue;
                    }

                    //determine how many resources can be used from this buildings
                    int resourcesToUse = Math.Min(usedResources, resourceBuilding.resourcesGenerated);

                    //subtract resources from total used by faction
                    usedResources -= resourcesToUse;
                    //subtract resources from actual building
                    resourceBuilding.resourcesGenerated -= resourcesToUse;

                    //if we've subtracted all the resources use by this faction
                    if (usedResources <= 0)
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 2
0
        public void InitializeBuildings()
        {
            buildings = new Building[numberOfBuildings];

            for (int i = 0; i < buildings.Length; i++)
            {
                int x            = GameEngine.random.Next(0, mapSize);
                int y            = GameEngine.random.Next(0, mapSize);
                int factionIndex = GameEngine.random.Next(0, 2);
                int buildingType = GameEngine.random.Next(0, 2);

                while (map[x, y] != null)
                {
                    x = GameEngine.random.Next(0, mapSize);
                    y = GameEngine.random.Next(0, mapSize);
                }

                if (buildingType == 0)
                {
                    buildings[i] = new ResourceBuilding(x, y, factions[factionIndex]);
                }
                else
                {
                    buildings[i] = new FactoryBuilding(x, y, factions[factionIndex]);  //not many changes needed in this section
                }

                map[x, y] = buildings[i].Faction[0] + "/" + buildings[i].Symbol;
            }
        }
Esempio n. 3
0
        ///
        ///
        ///
        ///
        public void UpdateBuildings()
        {
            foreach (Building building in map.Buildings)
            {
                if (building.IsDestroyed) //if unit is dead, it will be discarded
                {
                    continue;
                }

                if (building is FactoryBuilding)
                {
                    FactoryBuilding factoryBuilding = (FactoryBuilding)building; //if building is a factory, it gets assigned

                    if (round % factoryBuilding.ProductionSpeed == 0)            //if the round can be divided by the factory production speed, it creates a unit
                    {
                        Unit newUnit = factoryBuilding.CreateUnit();
                        map.AddUnit(newUnit);
                    }
                }
                else if (building is ResourceBuilding)                              //resource building
                {
                    ResourceBuilding resourceBuilding = (ResourceBuilding)building; //casting it
                    resourceBuilding.IncreaseResourceAmount();
                }
            }
        }
Esempio n. 4
0
 void AddToResourcePoolByFaction(string faction)
 { //gets all buildings by faction, if is rss and not destroyed, add 1
     foreach (Building building in manager.GetBuildingsByFaction(faction))
     {
         if (building is ResourceBuilding && !building.IsDestroyed)
         {
             ResourceBuilding resourceBuilding = (ResourceBuilding)building;
             resourceBuilding.ResourcePoolRemaining += 1;
         }
     }
 }
Esempio n. 5
0
        //calculate how much resources a faction has at it's disposal
        int GetResourcesTotalByFaction(string faction)
        {
            int totalResources = 0;

            foreach (Building building in manager.GetBuildingsByFaction(faction))
            {
                //we are interested in resource buildings that have not been destroyed
                if (building is ResourceBuilding && !building.IsDestroyed)
                {
                    ResourceBuilding resourceBuilding = (ResourceBuilding)building;
                    totalResources += resourceBuilding.resourcesGenerated;
                }
            }
            return(totalResources);
        }
Esempio n. 6
0
        void UpdateBuildings()
        {
            foreach (string faction in factions)
            {
                //new resources are only considered at the beginning of the next round
                int resources     = GetResourcesTotalByFaction(faction);
                int usedResources = 0;

                foreach (Building building in manager.GetBuildingsByFaction(faction))
                {
                    //ignore destroyed buildings
                    if (building.IsDestroyed)
                    {
                        building.CheckHide();
                        continue;
                    }

                    if (building is FactoryBuilding)
                    {
                        FactoryBuilding factoryBuilding = (FactoryBuilding)building;

                        if (factoryBuilding.CanProduce(round) && factoryBuilding.SpawnCost <= resources)
                        {
                            resources     -= factoryBuilding.SpawnCost;
                            usedResources += factoryBuilding.SpawnCost;

                            Unit newUnit = factoryBuilding.CreateUnit(round);
                            manager.AddUnit(newUnit);
                        }
                    }
                    else if (building is ResourceBuilding)
                    {
                        ResourceBuilding resourceBuilding = (ResourceBuilding)building;
                        resourceBuilding.IncreaseResourceAmount();
                    }
                }

                //remove used resources from faction's available resource buildings
                UseResourcesFromFaction(faction, usedResources);
            }
        }
Esempio n. 7
0
        private void AddBuildings(int numBuildings, string faction)
        {
            for (int i = 0; i < numBuildings; i++)
            {
                int x            = random.Next(0, map.width);
                int y            = random.Next(0, map.height);
                int buildingType = random.Next(0, 2);

                Building building;
                if (buildingType == 0)
                {
                    building = new FactoryBuilding(x, y, faction, map.height);
                }
                else
                {
                    building = new ResourceBuilding(x, y, faction);
                }

                manager.AddBuilding(building);
            }
        }