protected override void CreateStates() { CreateState(cSeekTarget, actor => new SimpleMoveOrder( actor, actor.GameController.SnapToGround(targetObj.transform.position)), actor => GoToState(cReservationWait, actor), null); CreateState(cReservationWait, actor => { resourceReservation = reservoir.NewReservation(actor.gameObject, 1); return(new WaitForReservationOrder(actor, resourceReservation)); }, actor => GoToState(cGetResource, actor), null); CreateState(cGetResource, actor => new ExtractFromReservoirOrder(actor, resourceReservation), actor => { resourceReservation = null; GoToState(cStoreContents, actor); }, null); CreateState(cStoreContents, actor => new StoreCarriedResourceOrder(actor), actor => GoToState(cSeekTarget, actor), null); }
public ResourceReservation MakeReservation(StorageNode reserver, Resource resource) { ResourceReservation newReservation = new ResourceReservation(Take(resource), this); reservations.Add(newReservation); return(newReservation); }
public FreightContract(Employee contractCreator, Company issuingCompany, ResourceReservation reservedResource, JobBoard board) { issuer = issuingCompany; creator = contractCreator; reservation = reservedResource; base.jobBoard = board; }
/// <summary> /// Removes the resources for the given reservation from this warehouse and sets the reservation to released /// </summary> /// <param name="res"></param> public void WithdrawReservation(ResourceReservation res) { if (!res.Ready) { throw new Exception("Reservation is not ready"); } if (res.source != gameObject) { throw new Exception("Attempting to withdraw reservation for another warehouse!"); } if (res.Released) { throw new Exception("Reservation already filled!"); } foreach (ResourceProfile rp in resourceContents) { if (rp.ResourceKind == res.resourceKind && rp.Amount >= res.amount) { rp.Amount -= res.amount; res.Released = true; resourceReservations.Remove(res); SendMessage("OnResourceWithdrawn", SendMessageOptions.DontRequireReceiver); return; } } //Debug.Log(res); throw new InvalidOperationException("Unable to withdraw reservation"); }
public void FixedUpdate() { if (!employmentData.HasContract()) { state = ShipState.Idle; } else if (employmentData.HasContract() && state == ShipState.Idle) { FreightContract c = (FreightContract)employmentData.contract; state = ShipState.Pickup; destination = c.reservation.location.gameObject; } if (state == ShipState.Pickup) { if (_atDestination) { _atDestination = false; _rb.velocity = Vector2.zero; FreightContract c = (FreightContract)employmentData.contract; c.reservation.Resolve(cargoHold); ResourceReservation newReservation = cargoHold.MakeReservation(c.reservation.location, c.reservation.resource); c.reservation = newReservation; destination = c.creator.GetComponent <IndustryNode>().connectedStorageNode.gameObject; state = ShipState.Dropoff; } else { Arrive(destination); } } else if (state == ShipState.Dropoff) { if (_atDestination) { _atDestination = false; destination = null; _rb.velocity = Vector2.zero; FreightContract f = (FreightContract)employmentData.contract; f.reservation.Resolve(f.creator.GetComponent <IndustryNode>().connectedStorageNode); employmentData.contract.MarkAsComplete(); state = ShipState.Idle; } else { Arrive(destination); } } }
public bool SetNewReservation(ResourceReservation reservation) { if (Reservation != null) { return(false); } else { Reservation = reservation; return(true); } }
/// <summary> /// Attempts to reserve the resource contents of this warehouse, returning a boolean indicating whether the operation was successful /// </summary> /// <param name="reserver">Gameobject to which this reservation should be attached</param> /// <param name="resourceKind">Resource type tag</param> /// <param name="amount">Amount to reserve</param> /// <returns>true on success, false on failure</returns> public bool ReserveContents(GameObject reserver, ResourceKind resourceKind, double amount) { double avail = GetAvailableContents(resourceKind); if (avail < amount) { return(false); } ResourceReservation r = reserver.AddComponent <ResourceReservation>(); r.amount = amount; r.resourceKind = resourceKind; r.Ready = true; r.source = gameObject; resourceReservations.Add(r); return(true); }
public SystemTaskBase GetTask(LoadBalanceWorkload workload, ResourceReservationContext context) { lock (this.requestQueueLock) { this.BlockedTaskCount = 0; if (this.requests.Count == 0) { return(null); } for (int i = 0; i < this.requests.Count; i++) { IRequest request = this.requests[i]; if (request.IsBlocked) { this.BlockedTaskCount++; } else if (request.ShouldCancel(this.settings.IdleRunDelay)) { request.Abort(); DatabaseRequestLog.Write(request); this.requests.RemoveAt(i); i--; } else { ResourceKey obj2; ResourceReservation reservation = context.GetReservation(workload, request.Resources, out obj2); if (reservation != null) { this.requests.RemoveAt(i); return(new LoadBalanceTask(workload, reservation, request)); } if (ProcessorResourceKey.Local.Equals(obj2)) { this.BlockedTaskCount = this.requests.Count; break; } this.BlockedTaskCount++; } } } return(null); }
/// <summary> /// Attempts to reserve the resource contents of this warehouse, returning a boolean indicating whether the operation was successful /// </summary> /// <param name="reserver">Gameobject to which this reservation should be attached</param> /// <param name="resourceKind">Resource type tag</param> /// <param name="amount">Amount to reserve</param> /// <returns>true on success, false on failure</returns> public bool ReserveContents(GameObject reserver, ResourceKind resourceKind, double amount) { double avail = GetAvailableContents(resourceKind); if (avail < amount) { return(false); } ResourceReservation r = reserver.AddComponent <ResourceReservation>(); r.amount = amount; r.resourceKind = resourceKind; r.Ready = true; r.source = this.gameObject; //Debug.Log(r.resourceTag + " " + r.amount); //Debug.Log("Res count: " + resourceReservations.Count); resourceReservations.Add(r); //Debug.Log("Res count: "+resourceReservations.Count); return(true); }
public override BT_Result Tick(BT_AgentMemory am) { ResourceReservation reservationToCheck = am.Character.Reservation; if (reservationToCheck == null) { return(BT_Result.SUCCESS); } if ((reservationToCheck.SourceStorage != null && am.Character.IsTileMarkedAsInaccessible( reservationToCheck.SourceStorage.GetAccessTile(reservationToCheck.UseSourceStorageSecondAccessTile))) || (am.Character.IsTileMarkedAsInaccessible( reservationToCheck.TargetStorage.GetAccessTile(reservationToCheck.UseTargetStorageSecondAccessTile)))) { return(BT_Result.FAILURE); } else { return(BT_Result.SUCCESS); } }
/// <summary> /// Withdraws the given reservation from this reservoir /// </summary> /// <param name="res"></param> /// <exception cref="System.ArgumentException">Thrown when an invalid reservation is passed</exception> /// <returns>True on success, false if the reservation is not fulfillable</returns> public bool WithdrawReservation(ResourceReservation res) { if (res.source != this.gameObject) { Debug.Log(res); throw new ArgumentException("Reservation not for this Reservoir"); } if (res.Released || res.Cancelled) { Debug.Log(res); throw new ArgumentException("Invalid reservation!"); } if (amount >= res.amount) { amount -= res.amount; res.Released = true; reservations.Remove(res); if (!String.IsNullOrEmpty(harvestStat)) { IGameStat stat = statManager.Stat(harvestStat); if (stat != null) { stat.Add(res.amount); } else { Debug.Log("Unable to resolve stat " + harvestStat); } } return(true); } else { return(false); } }
private void CreateFreightContract(Resource resource) { Star star = gameObject.GetComponentInParent <Star>(); // Check if the resource is available in this system if (!star.HasResourceAmount(resource)) { return; } // Make a reservation ResourceReservation reservation = MakeReservation(resource, star); // Add the resource type to the list of requested types. // The resource will be removed from the _requiredResources list later in Update() _requestedResourceTypes.Add(resource.type); FreightContract newContract = new FreightContract(employmentData, employmentData.employer, reservation, star.jobBoard); employmentData.employer.ConsiderIssuingContract(newContract); Debug.Log("Posting contract"); }
public void CancelReservation(ResourceReservation reservation) { Put(reservation.resource); reservations.Remove(reservation); }
public override BT_Result Tick(BT_AgentMemory am) { BT_FindTransportJobNodeData data = am.GetObject(ID) as BT_FindTransportJobNodeData; if (data == null) { return(BT_Result.FAILURE); } World world = GameManager.Instance.World; if (data.PotentialReservation == null) { ResourceReservation newReservation = null; newReservation = world.GetReservationForFillingInput(am.Character); if (newReservation == null) { newReservation = world.GetReservationForEmptying(am.Character); } if (newReservation != null) { data.PotentialReservation = newReservation; data.TargetStorageChecked = false; data.SourceStorageChecked = false; } else { am.SetTimer(ID, timeoutAfterFailure); return(BT_Result.FAILURE); } return(BT_Result.RUNNING); } if (data.TargetStorageChecked == false) { BT_Result result = TickChild(findTargetStorageNode, am); if (result == BT_Result.SUCCESS) { data.TargetStorageChecked = true; return(BT_Result.RUNNING); } else if (result == BT_Result.RUNNING) { return(BT_Result.RUNNING); } else { am.SetTimer(ID, timeoutAfterFailure); return(BT_Result.FAILURE); } } else { BT_Result result = TickChild(findSourceStorageNode, am); if (result == BT_Result.SUCCESS) { data.SourceStorageChecked = true; if (am.Character.SetNewReservation(data.PotentialReservation)) { am.SetObject(ID, null); return(BT_Result.SUCCESS); } else { data.PotentialReservation.SourceStorage.RemoveResourceReservation(am.Character); data.PotentialReservation.TargetStorage.RemoveFreeSpaceReservation(am.Character); am.SetTimer(ID, timeoutAfterFailure); return(BT_Result.FAILURE); } } else if (result == BT_Result.RUNNING) { return(BT_Result.RUNNING); } else { am.SetTimer(ID, timeoutAfterFailure); return(BT_Result.FAILURE); } } }
public MrsSystemTask(Job job, Action callback, SystemWorkloadBase systemWorkload, ResourceReservation reservation, bool ignoreTaskSuccessfulExecutionTime = false) : base(systemWorkload) { this.Job = job; base.ResourceReservation = reservation; this.Callback = callback; this.IgnoreTaskSuccessfulExecutionTime = ignoreTaskSuccessfulExecutionTime; }
public LoadBalanceTask(SystemWorkloadBase workload, ResourceReservation reservation, IRequest request) : base(workload, reservation) { this.request = request; }
// Token: 0x06000427 RID: 1063 RVA: 0x00014EB9 File Offset: 0x000130B9 internal TimeBasedAssistantTask(SystemWorkloadBase workload, TimeBasedDatabaseDriver driver, ResourceReservation reservation) : base(workload, reservation) { this.driver = driver; }
public NewIntersightResourceReservation() { ApiInstance = new ResourceApi(Config); ModelObject = new ResourceReservation(); MethodName = "CreateResourceReservationWithHttpInfo"; }
public ExtractFromReservoirOrder(ActorController a, ResourceReservation res) : base() { a.GetComponent <NeolithicObject>().statusString = "Extracting resource"; reservation = res; }
private MrsSystemTask GetTask(SystemWorkloadBase systemWorkload, ResourceReservationContext context) { MrsTracer.ActivityID = this.traceActivityID; base.CheckDisposed(); MrsSystemTask result; using (SettingsContextBase.ActivateContext(this as ISettingsContextProvider)) { lock (this.jobLock) { if (this.IsFinished) { MrsTracer.Service.Debug("Job({0}) is finished.", new object[] { base.GetType().Name }); this.state = JobState.Finished; this.jobDoneEvent.Set(); result = null; } else { WorkItem workItem = null; bool flag2 = true; foreach (WorkItem workItem2 in this.workItemQueue.GetCandidateWorkItems()) { if (workItem2.ScheduledRunTime <= ExDateTime.UtcNow || CommonUtils.ServiceIsStopping) { flag2 = false; if (this.GetWorkloadType(workItem2.WorkloadType) == systemWorkload.WorkloadType) { workItem = workItem2; break; } } } if (workItem == null) { if (flag2) { this.state = JobState.Waiting; } result = null; } else { this.RevertToPreviousUnthrottledState(); IEnumerable <ResourceKey> enumerable = this.ResourceDependencies; if (enumerable == null) { enumerable = Array <ResourceKey> .Empty; } ResourceKey resource = null; ResourceReservation reservation = this.GetReservation(workItem, systemWorkload, context, enumerable, out resource); if (reservation != null) { if (reservation.DelayFactor > 0.0) { this.MoveToThrottledState(resource, true); } this.TraceWorkItem(workItem); this.workItemQueue.Remove(workItem); result = new MrsSystemTask(this, workItem.Callback, systemWorkload, reservation, workItem is JobCheck); } else { this.MoveToThrottledState(resource, false); result = null; } } } } } return(result); }
protected override SystemTaskBase GetTask(ResourceReservationContext context) { List <Guid> list = null; Guid guid = this.lastProcessedDriverGuid; lock (this.instanceLock) { TimeBasedAssistantTask timeBasedAssistantTask = null; List <TimeBasedAssistantTask> list2 = new List <TimeBasedAssistantTask>(); foreach (SystemTaskBase systemTaskBase in this.tasksWaitingExecution) { TimeBasedAssistantTask timeBasedAssistantTask2 = (TimeBasedAssistantTask)systemTaskBase; IEnumerable <ResourceKey> resourceDependencies = timeBasedAssistantTask2.ResourceDependencies; if (resourceDependencies != null) { ResourceReservation reservation = context.GetReservation(this, resourceDependencies); if (reservation != null) { timeBasedAssistantTask2.ResourceReservation = reservation; timeBasedAssistantTask = timeBasedAssistantTask2; break; } } else { list2.Add(timeBasedAssistantTask2); } } foreach (TimeBasedAssistantTask value in list2) { this.tasksWaitingExecution.Remove(value); } if (timeBasedAssistantTask != null) { this.tasksWaitingExecution.Remove(timeBasedAssistantTask); return(timeBasedAssistantTask); } } TimeBasedDatabaseDriver nextDriver; ResourceReservation reservation2; for (;;) { nextDriver = this.Controller.GetNextDriver(guid); if (nextDriver == null) { break; } guid = nextDriver.DatabaseInfo.Guid; if (list != null && list.Contains(guid)) { goto Block_4; } if (!nextDriver.HasTask()) { ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "Skipping database '{0}' for assistant '{1}'. There is no task to execute.", guid, this.Controller.TimeBasedAssistantType.Name); } else { IEnumerable <ResourceKey> resourceDependencies2 = nextDriver.ResourceDependencies; if (resourceDependencies2 != null) { reservation2 = context.GetReservation(this, resourceDependencies2); if (reservation2 != null) { goto IL_1E1; } ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "Skipping database '{0}' for assistant '{1}'. Dependent resources are not currently available for this assistant.", guid, this.Controller.TimeBasedAssistantType.Name); } else { ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "The driver for database {0} assistant {1} did not return any resource dependencies. This is possible only when the driver is not started. Skipping tasks from this driver.", guid, this.Controller.TimeBasedAssistantType.Name); } } if (list == null) { list = new List <Guid>(); } list.Add(guid); } ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <LocalizedString>((long)this.GetHashCode(), "There are no drivers available for the assistant controller '{0}' at this time. No task available for execution.", this.Controller.TimeBasedAssistantType.Name); return(null); Block_4: ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <LocalizedString>((long)this.GetHashCode(), "Could not find any tasks to execute for the assistant controller '{0}'. No task available for execution.", this.Controller.TimeBasedAssistantType.Name); return(null); IL_1E1: ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "A task is available for execution on database {0} for assistant {1}. Submitting the task to RUBS for execution", guid, this.Controller.TimeBasedAssistantType.Name); this.lastProcessedDriverGuid = guid; return(new TimeBasedAssistantTask(this, nextDriver, reservation2)); }
public void TransferReservedResources(ResourceReservation reservation, StorageNode destinationNode) { reservations.Remove(reservation); destinationNode.Put(reservation.resource); }