Пример #1
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);
                }
            }
        }
Пример #2
0
        public void OnConstructionComplete(Entity industryEntity, VolumeStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo)
        {
            var industryDB = industryEntity.GetDataBlob <IndustryAbilityDB>();
            ProcessedMaterialSD material = (ProcessedMaterialSD)designInfo;

            storage.AddCargoByUnit(material, OutputAmount);
            batchJob.ProductionPointsLeft = material.IndustryPointCosts; //and reset the points left for the next job in the batch.

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                industryDB.ProductionLines[productionLine].Jobs.Remove(batchJob);
                if (batchJob.Auto)
                {
                    industryDB.ProductionLines[productionLine].Jobs.Add(batchJob);
                }
            }
        }
Пример #3
0
        internal static void ConstructStuff(Entity industryEntity)
        {
            CargoStorageDB stockpile = industryEntity.GetDataBlob <CargoStorageDB>();
            Entity         faction;

            industryEntity.Manager.FindEntityByGuid(industryEntity.FactionOwner, out faction);
            var factionInfo = faction.GetDataBlob <FactionInfoDB>();
            var industryDB  = industryEntity.GetDataBlob <IndustryAbilityDB>();

            //var pointRates = industryDB.IndustryTypeRates;
            //int maxPoints = industryDB.ConstructionPoints;


            //List<JobBase> constructionJobs = new List<JobBase>(industryDB.JobBatchList);
            foreach (var kvp in industryDB.ProductionLines.ToArray())
            {
                Guid prodLineID = kvp.Key;
                var  prodLine   = kvp.Value;
                var  industryPointsRemaining = new Dictionary <Guid, int>(prodLine.IndustryTypeRates);
                List <IndustryJob> Joblist   = prodLine.Jobs;
                float productionPercentage   = 1;



                for (int i = 0; i < Joblist.Count; i++)
                {
                    IndustryJob         batchJob   = Joblist[i];
                    IConstrucableDesign designInfo = factionInfo.IndustryDesigns[batchJob.ItemGuid];
                    float pointsToUse = industryPointsRemaining[designInfo.IndustryTypeID] * productionPercentage;
                    //total number of resources requred for a single job in this batch
                    var resourceSum = designInfo.ResourceCosts.Sum(item => item.Value);
                    //how many construction points each resourcepoint is worth.
                    float pointPerResource = (float)designInfo.IndustryPointCosts / resourceSum;

                    while (
                        productionPercentage > 0 &&
                        batchJob.NumberCompleted < batchJob.NumberOrdered &&
                        pointsToUse > 0)
                    {
                        //gather availible resorces for this job.
                        //right now we take all the resources we can, for an individual item in the batch.
                        //even if we're taking more than we can use in this turn, we're using/storing it.
                        IDictionary <Guid, int> resourceCosts = batchJob.ResourcesRequired;
                        //Note: this is editing batchjob.ResourcesRequired variable.
                        ConsumeResources(stockpile, ref resourceCosts);
                        //we calculate the difference between the design resources and the amount of resources we've squirreled away.


                        // this is the total of the resources that we don't have access to for this item.
                        int unusableResourceSum = resourceCosts.Sum(item => item.Value);
                        // this is the total resources that can be used on this item.
                        int useableResourcePoints = resourceSum - unusableResourceSum;

                        pointsToUse = Math.Min(industryPointsRemaining[designInfo.IndustryTypeID], batchJob.ProductionPointsLeft);
                        pointsToUse = Math.Min(pointsToUse, useableResourcePoints * pointPerResource);

                        var remainingPoints = industryPointsRemaining[designInfo.IndustryTypeID] - pointsToUse;


                        if (pointsToUse < 0)
                        {
                            throw new Exception("Can't have negative production");
                        }

                        //construct only enough for the amount of resources we have.
                        batchJob.ProductionPointsLeft -= (int)Math.Floor(pointsToUse);

                        productionPercentage -= remainingPoints * productionPercentage;

                        if (batchJob.ProductionPointsLeft == 0)
                        {
                            designInfo.OnConstructionComplete(industryEntity, stockpile, prodLineID, batchJob, designInfo);
                        }
                    }
                }
            }
        }