private void HandleRequest(MaterialResourceRequest mrr, IResourceManager secondary) { MaterialResourceItem mri = (MaterialResourceItem)m_resources[mrr.MaterialType]; if (mri == null) { return; } if (mrr.QuantityDesired > 0) // Depletion - do we have enough supply? { if (mrr.QuantityDesired > (mri.Available + mri.PermissibleOverbook)) { TransferIn(mrr, secondary, (mrr.QuantityDesired - mri.Available)); } } else // Augmentation - do we have room? { double howMuchRoom = (mri.Capacity + mri.PermissibleOverbook) - mri.Available; if (howMuchRoom + mrr.QuantityDesired < 0) { TransferOut(mrr, secondary, (-mrr.QuantityDesired - howMuchRoom)); } } }
private void TransferOut(MaterialResourceRequest mrr, IResourceManager secondary, double quantity) { //_Debug.WriteLine("Gotta transfer " + quantity + " kg out."); IResourceRequest newMrr = new MaterialResourceRequest(mrr.MaterialType, quantity, MaterialResourceRequest.Direction.Deplete); if (secondary.Acquire(newMrr, false)) { //_Debug.WriteLine("Successfully transferred."); } }
private void m_myResourceManager_ResourceRequested(IResourceRequest irr, IResource resource) { MaterialResourceRequest resourceRequest = irr as MaterialResourceRequest; if (resourceRequest != null) { MaterialResourceRequest mrr = resourceRequest; //_Debug.WriteLine("I am taking care of a request for " + mrr.QuantityDesired + " kg of " + mrr.MaterialType.Name); IResourceManager rm = (IResourceManager)m_conduits[mrr.MaterialType]; if (rm != null) { //_Debug.WriteLine("There is a conduit specified for " + mrr.MaterialType.Name + ", and it is " + rm); HandleRequest(mrr, rm); } else { //_Debug.WriteLine("There is no conduit specified for " + mrr.MaterialType.Name); } } else { //_Debug.WriteLine("I am skipping handling of a request for " + irr.QuantityDesired + " units of something."); } }