コード例 #1
0
ファイル: Workshop.cs プロジェクト: valeIT/ProjectPorcupine
        public override IEnumerable <string> GetDescription()
        {
            if (PossibleProductions.Count > 1)
            {
                StringBuilder sb        = new StringBuilder();
                string        prodChain = CurrentProductionChainName.ToString();
                sb.AppendLine(!string.IsNullOrEmpty(prodChain) ? string.Format("Production: {0}", prodChain) : "No selected production");
                float curProcessingTime = CurrentProcessingTime.ToFloat();
                if (!ParentFurniture.HasCustomProgressReport && curProcessingTime > 0f)
                {
                    float perc = 0f;
                    float maxProcessingTime = MaxProcessingTime.ToFloat();
                    if (maxProcessingTime != 0f)
                    {
                        perc = curProcessingTime * 100f / maxProcessingTime;
                        if (perc > 100f)
                        {
                            perc = 100f;
                        }
                    }

                    sb.AppendLine(string.Format("Progress: {0:0}%", perc));
                }

                int numHaulingJobs = InputHaulingJobsCount.ToInt();
                if (numHaulingJobs > 0)
                {
                    sb.AppendLine(string.Format("Hauling jobs: {0}", numHaulingJobs));
                }

                yield return(sb.ToString());
            }
            else
            {
                yield return(null);
            }
        }
コード例 #2
0
ファイル: Workshop.cs プロジェクト: valeIT/ProjectPorcupine
        private void HaulingJobForInputs(ProductionChain prodChain)
        {
            int  numHaulingJobs = 0;
            bool isProcessing   = InputProcessed.ToInt() > 0;

            //// for all inputs in production chain
            foreach (Item reqInputItem in prodChain.Input)
            {
                if (isProcessing && !reqInputItem.HasHopper)
                {
                    continue;
                }

                //// if there is no hauling job for input object type, create one
                Job    furnJob;
                string requiredType       = reqInputItem.ObjectType;
                bool   existingHaulingJob = ParentFurniture.Jobs.HasJobWithPredicate(x => x.RequestedItems.ContainsKey(requiredType), out furnJob);

                if (existingHaulingJob)
                {
                    numHaulingJobs++;
                }
                else
                {
                    Tile inTile = World.Current.GetTileAt(
                        ParentFurniture.Tile.X + reqInputItem.SlotPosX,
                        ParentFurniture.Tile.Y + reqInputItem.SlotPosY,
                        ParentFurniture.Tile.Z);

                    // create job for desired input resource
                    string desiredInv    = reqInputItem.ObjectType;
                    int    desiredAmount = reqInputItem.Amount;

                    if (reqInputItem.HasHopper)
                    {
                        desiredAmount = PrototypeManager.Inventory.Get(desiredInv).MaxStackSize;
                    }

                    if (inTile.Inventory != null && inTile.Inventory.Type == reqInputItem.ObjectType &&
                        inTile.Inventory.StackSize <= desiredAmount)
                    {
                        desiredAmount = desiredAmount - inTile.Inventory.StackSize;
                    }

                    if (desiredAmount > 0)
                    {
                        Job job = new Job(
                            inTile,
                            null,           // beware: passed jobObjectType is expected Furniture only !!
                            null,
                            0.4f,
                            new RequestedItem[] { new RequestedItem(desiredInv, desiredAmount, desiredAmount) },
                            Job.JobPriority.High,
                            "hauling",
                            false,
                            false,
                            false);

                        job.Description  = string.Format("Hauling '{0}' to '{1}'", desiredInv, ParentFurniture.GetName());
                        job.OnJobWorked += PlaceInventoryToWorkshopInput;
                        ParentFurniture.Jobs.Add(job);
                        numHaulingJobs++;
                    }
                }
            }

            InputHaulingJobsCount.SetValue(numHaulingJobs);
        }