示例#1
0
        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));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Gets the score that describes the suitability of the resource to fulfill this resource request.
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <returns>The score</returns>
        public double GetScore(IResource resource)
        {
            // If it's the right type of material, it's perfect. Otherwise, throw it back.
            MaterialResourceItem item = resource as MaterialResourceItem;

            if (item != null && item.MaterialType.Equals(m_materialType))
            {
                if (QuantityDesired < 0 /* augmenting */ || (resource.Available + resource.PermissibleOverbook) >= QuantityDesired)
                {
                    return(double.MaxValue);
                }
            }
            return(double.MinValue);
        }
示例#3
0
        }         // end ContainsGuid

        /// <summary>
        /// Performs an XOR on mri's MT and Specs to give a unique key into the contents.
        /// </summary>
        /// <param name="mri">The MRI to search</param>
        /// <returns>Guid defining the unqueness of the mri</returns>
        public static Guid ContentsXOR(MaterialResourceItem mri)
        {
            return(ContentsXOR(mri.MaterialType.Guid, mri.MaterialSpecificationGuids));
        }