예제 #1
0
 public static void AddJob(IndustryAbilityDB industryDB, Guid plineID, IndustryJob job)
 {
     lock (industryDB.ProductionLines[plineID])
     {
         var pline = industryDB.ProductionLines[plineID];
         pline.Jobs.Add(job);
     }
 }
예제 #2
0
        public static IndustryOrder2 CreateNewJobOrder(
            Guid factionGuid, Entity thisEntity, Guid productionLineID,
            IndustryJob jobItem
            )
        {
            IndustryOrder2 order = new IndustryOrder2(factionGuid, thisEntity);

            order._job             = jobItem;
            order.OrderType        = OrderTypeEnum.NewJob;
            order.ItemID           = jobItem.ItemGuid;
            order.productionLineID = productionLineID;
            return(order);
        }
예제 #3
0
        internal override void ActionCommand(DateTime atDateTime)
        {
            if (!IsRunning)
            {
                var portDB = _entityCommanding.GetDataBlob <IndustryAbilityDB>();

                foreach (var job in portDB.ProductionLines[_launchSlot].Jobs)
                {
                    if (job.ItemGuid == _jobID)
                    {
                        _yardJob = job;
                        ShipDesign design = (ShipDesign)_factionEntity.GetDataBlob <FactionInfoDB>().IndustryDesigns[job.ItemGuid];
                        if (_entityCommanding.HasDataBlob <ColonyInfoDB>())
                        {
                            var planet = _entityCommanding.GetDataBlob <ColonyInfoDB>().PlanetEntity;

                            FuelCost       = OrbitMath.FuelCostToLowOrbit(planet, design.MassPerUnit);
                            targetPosition = new Vector3(0, OrbitMath.LowOrbitRadius(planet), 0);
                            IsRunning      = true;
                        }
                        else
                        {
                            FuelCost = OrbitMath.TsiolkovskyFuelCost(design.MassPerUnit, 275, 1);
                            //targetOrbit = (OrbitDB)_entityCommanding.GetDataBlob<OrbitDB>().Clone();
                            targetPosition = _entityCommanding.GetDataBlob <PositionDB>().RelativePosition_m;
                            IsRunning      = true;
                        }
                    }
                }
            }
            else //IsRunning
            {
                //_entityCommanding.GetDataBlob<CargoStorageDB>().StoredCargoTypes
                ShipDesign design = (ShipDesign)_factionEntity.GetDataBlob <FactionInfoDB>().IndustryDesigns[_yardJob.ItemGuid];
                ShipFactory.CreateShip(design, _factionEntity, targetPosition, orbitalParent, (StarSystem)orbitalParent.Manager);
                _hasLaunched = true;
            }
        }
예제 #4
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);
                        }
                    }
                }
            }
        }
예제 #5
0
        public static void AddJob(Entity industryEntity, Guid plineID, IndustryJob job)
        {
            var industryDB = industryEntity.GetDataBlob <IndustryAbilityDB>();

            AddJob(industryDB, plineID, job);
        }