コード例 #1
0
        public void Init()
        {
            _game = new TestGame();
            StaticDataManager.LoadData("Pulsar4x", _game.Game);  // TODO: Figure out correct directory
            _entityManager = _game.Game.GlobalManager;



            // Initialize gas dictionary - haven't found a good way to look up gases without doing this
            _gasDictionary = new Dictionary <string, AtmosphericGasSD>();

            foreach (WeightedValue <AtmosphericGasSD> atmos in _game.Game.StaticData.AtmosphericGases)
            {
                _gasDictionary.Add(atmos.Value.ChemicalSymbol, atmos.Value);
            }


            _planetsList = new List <Entity>();
            _planetsList.Add(_game.Earth);

            _speciesList = new List <Entity>();
            _speciesList.Add(_game.HumanSpecies);
            //_speciesList.Add(_game.GreyAlienSpecies);

            // Set up colonies
            // @todo: add more colonies, especially ones with multiple species in one colony


            ComponentTemplateSD infrastructureSD       = _game.Game.StaticData.ComponentTemplates[new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb")];
            ComponentDesigner   infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>());

            EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesigner.CreateDesign(_game.HumanFaction));

            ReCalcProcessor.ReCalcAbilities(_game.EarthColony);
        }
コード例 #2
0
        public void OnConstructionComplete(Entity industryEntity, CargoStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo)
        {
            var colonyConstruction = industryEntity.GetDataBlob <IndustryAbilityDB>();

            batchJob.NumberCompleted++;
            batchJob.ResourcesRequired = designInfo.ResourceCosts;

            batchJob.ProductionPointsLeft = designInfo.IndustryPointCosts;


            if (batchJob.InstallOn != null)
            {
                ComponentInstance specificComponent = new ComponentInstance((ComponentDesign)designInfo);
                if (batchJob.InstallOn == industryEntity || StorageSpaceProcessor.HasEntity(storage, batchJob.InstallOn.GetDataBlob <CargoAbleTypeDB>()))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddCargo(storage, (ComponentDesign)designInfo, 1);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.ProductionLines[productionLine].Jobs.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.ProductionLines[productionLine].Jobs.Add(batchJob);
                }
            }
        }
コード例 #3
0
        private void testPlanetAndSpecies(Entity planet, Entity species)
        {
            long[] basePop = new long[] { 0, 5, 10, 100, 999, 1000, 10000, 100000, 10000000 };
            long[] infrastructureAmounts = new long[] { 0, 1, 5, 100 };
            Dictionary <Entity, long> newPop, returnedPop;

            int i, j, k;

            Guid infGUID = new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb");
            ComponentTemplateSD infrastructureSD = _game.Game.StaticData.ComponentTemplates[infGUID];


            ComponentDesigner infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>());
            ComponentDesign   infrastructureDesign   = infrastructureDesigner.CreateDesign(_game.HumanFaction);

            Dictionary <Entity, long> pop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;


            // Single iteration growth test
            for (i = 0; i < infrastructureAmounts.Length; i++)
            {
                // Create a new colony with this planet and species, add infrastructure item to it
                _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet);

                // Add the correct number of infrastructure to the colony
                for (k = 0; k < infrastructureAmounts[i]; k++)
                {
                    EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign);
                }
                ReCalcProcessor.ReCalcAbilities(_game.EarthColony);


                for (j = 0; j < basePop.Length; j++)
                {
                    // set up population and infrastructure for each test
                    newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;

                    foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray())
                    {
                        newPop[kvp.Key] = basePop[j];
                    }

                    //var infrastuctures = _game.EarthColony.GetDataBlob<ComponentInstancesDB>().SpecificInstances[infrastructureEntity].Where(inf => inf.DesignEntity.HasDataBlob<LifeSupportAbilityDB>());

                    returnedPop = calcGrowthIteration(_game.EarthColony, newPop);
                    PopulationProcessor.GrowPopulation(_game.EarthColony);

                    foreach (KeyValuePair <Entity, long> kvp in pop.ToArray())
                    {
                        Assert.AreEqual(returnedPop[kvp.Key], pop[kvp.Key]);
                    }
                }
            }


            // Multiple iteration growth test
            for (i = 0; i < infrastructureAmounts.Length; i++)
            {
                // Create a new colony with this planet and species, add infrastructure item to it
                _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet);

                // Add the correct number of infrastructure to the colony
                for (k = 0; k < infrastructureAmounts[i]; k++)
                {
                    EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign);
                }
                ReCalcProcessor.ReCalcAbilities(_game.EarthColony);

                for (j = 0; j < basePop.Length; j++)
                {
                    // set up population and infrastructure for each test
                    newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;

                    foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray())
                    {
                        newPop[kvp.Key] = basePop[j];
                    }

                    for (k = 0; k < 10; k++)
                    {
                        newPop = calcGrowthIteration(_game.EarthColony, newPop);
                        PopulationProcessor.GrowPopulation(_game.EarthColony);
                    }

                    foreach (KeyValuePair <Entity, long> kvp in pop.ToArray())
                    {
                        Assert.AreEqual(newPop[kvp.Key], pop[kvp.Key]);
                    }
                }
            }
        }