public override bool CanFunction() { bool canWork = false; string curSetupChainName = CurrentProductionChainName.ToString(); if (!string.IsNullOrEmpty(curSetupChainName)) { canWork = true; ProductionChain prodChain = GetProductionChainByName(curSetupChainName); //// create possible jobs for factory(hauling input) bool areAllHaulParamReqsFulfilled = true; if (HaulConditions != null) { areAllHaulParamReqsFulfilled = AreParameterConditionsFulfilled(RunConditions.ParamConditions); } if (areAllHaulParamReqsFulfilled) { HaulingJobForInputs(prodChain); canWork = true; } componentRequirements = Requirements.None; } else { componentRequirements = Requirements.Production; } return(canWork); }
public override void FixedFrequencyUpdate(float deltaTime) { // if there is enough input, do the processing and store item to output // - remove items from input // - add param to reflect factory can provide output (has output inside) // - as output will be produced after time, it is possible that output spot can be ocupied meanwhile // - process for specified time // - if output slot is free, provide output (if not, keep output 'inside' factory) if (ParentFurniture.IsBeingDestroyed) { return; } string curSetupChainName = CurrentProductionChainName.ToString(); if (!string.IsNullOrEmpty(curSetupChainName)) { ProductionChain prodChain = GetProductionChainByName(curSetupChainName); // if there is no processing in progress if (IsProcessing.ToInt() == 0) { // check input slots for input inventory List <KeyValuePair <Tile, int> > flaggedForTaking = CheckForInventoryAtInput(prodChain); // if all the input requirements are ok, you can start processing: if (flaggedForTaking.Count == prodChain.Input.Count) { // consume input inventory ConsumeInventories(flaggedForTaking); IsProcessing.SetValue(1); // check if it can be bool // reset processing timer and set max time for processing for this prod. chain CurrentProcessingTime.SetValue(0f); MaxProcessingTime.SetValue(prodChain.ProcessingTime); } } else { // processing is in progress CurrentProcessingTime.ChangeFloatValue(deltaTime); if (CurrentProcessingTime.ToFloat() >= MaxProcessingTime.ToFloat()) { List <TileObjectTypeAmount> outPlacement = CheckForInventoryAtOutput(prodChain); // if output placement was found for all products, place them if (outPlacement.Count == prodChain.Output.Count) { PlaceInventories(outPlacement); //// processing done, can fetch input for another processing IsProcessing.SetValue(0); } } } } }
public override bool CanFunction() { string curSetupChainName = CurrentProductionChainName.ToString(); if (!string.IsNullOrEmpty(curSetupChainName)) { ProductionChain prodChain = GetProductionChainByName(curSetupChainName); //// create possible jobs for factory(hauling input) HaulingJobForInputs(prodChain); } return(true); }
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"); yield return(sb.ToString()); } else { yield return(null); } }
protected override void Initialize() { if (ParamsDefinitions == null) { // don't need definition for all furniture, just use defaults ParamsDefinitions = new WorkShopParameterDefinitions(); } // check if context menu is needed if (PossibleProductions.Count > 1) { componentRequirements = Requirements.Production; WorkshopMenuActions = new List <ComponentContextMenu>(); CurrentProductionChainName.SetValue(null); foreach (ProductionChain chain in PossibleProductions) { string prodChainName = chain.Name; WorkshopMenuActions.Add(new ComponentContextMenu() { Name = prodChainName, Function = ChangeCurrentProductionChain }); } } else { if (PossibleProductions.Count == 1) { CurrentProductionChainName.SetValue(PossibleProductions[0].Name); } else { Debug.ULogWarningChannel(ComponentLogChannel, "Furniture {0} is marked as factory, but has no production chain", ParentFurniture.Name); } } // add dynamic params here CurrentProcessingTime.SetValue(0); MaxProcessingTime.SetValue(0); IsProcessing.SetValue(0); ParentFurniture.Removed += WorkshopRemoved; }
public override bool CanFunction() { bool canWork = false; string curSetupChainName = CurrentProductionChainName.ToString(); if (!string.IsNullOrEmpty(curSetupChainName)) { ProductionChain prodChain = GetProductionChainByName(curSetupChainName); //// create possible jobs for factory(hauling input) HaulingJobForInputs(prodChain); canWork = true; } else { componentRequirements = Requirements.Production; } return(canWork); }
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); } }