示例#1
0
        public static ResourceQuantity operator *(int quantity, Resource resource)
        {
            var q = new ResourceQuantity();

            q.Add(resource, quantity);
            return(q);
        }
示例#2
0
        public static ResourceQuantity operator *(ResourceQuantity r, double scalar)
        {
            var result = new ResourceQuantity();

            foreach (var key in r.Keys)
            {
                result.Add(key, (int)Math.Round(r[key] * scalar));
            }
            return(result);
        }
示例#3
0
        public static ResourceQuantity operator -(ResourceQuantity r1, ResourceQuantity r2)
        {
            var result = new ResourceQuantity();

            foreach (var key in r1.Keys.Union(r2.Keys))
            {
                result.Add(key, r1[key] - r2[key]);
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// Computes the maximum of two resource amounts.
        /// Missing values are treated as zeroes!
        /// </summary>
        /// <param name="r1"></param>
        /// <param name="r2"></param>
        /// <returns></returns>
        public static ResourceQuantity Max(ResourceQuantity r1, ResourceQuantity r2)
        {
            var result = new ResourceQuantity();

            foreach (var key in r1.Keys.Union(r2.Keys))
            {
                result.Add(key, Math.Max(r1[key], r2[key]));
            }
            return(result);
        }
示例#5
0
 public ResourceQuantity(ResourceQuantity q)
 {
     if (q != null)
     {
         foreach (var x in q)
         {
             Add(x);
         }
     }
 }
示例#6
0
        /// <summary>
        /// Computes the minimum of two resource amounts.
        /// Missing values are treated as zeroes!
        /// </summary>
        /// <param name="r1"></param>
        /// <param name="r2"></param>
        /// <returns></returns>
        public static ResourceQuantity Min(ResourceQuantity r1, ResourceQuantity r2)
        {
            var result = new ResourceQuantity();

            if (r1 == null || r2 == null)
            {
                return(new ResourceQuantity());
            }
            foreach (var key in r1.Keys.Union(r2.Keys))
            {
                result.Add(key, Math.Min(r1[key], r2[key]));
            }
            return(result);
        }
示例#7
0
        public static ResourceQuantity Parse(string s)
        {
            var q = new ResourceQuantity();

            if (s.Length > 0)
            {
                var resSplit = s.Split(',').Select(sub => sub.Trim());
                foreach (var res in resSplit)
                {
                    var pos     = res.IndexOf(" ");
                    var amount  = res.Substring(0, pos);
                    var resName = res.Substring(pos + 1);
                    q.Add(Resource.Find(resName), int.Parse(amount));
                }
            }
            return(q);
        }
示例#8
0
 public int CompareTo(ResourceQuantity other)
 {
     return(this.Sum(kvp => kvp.Value).CompareTo(other.Sum(kvp => kvp.Value)));
 }
示例#9
0
 public ResourceProgress(ResourceQuantity value, ResourceQuantity maximum, ResourceQuantity incrementalProgress)
 {
     Value               = value;
     Maximum             = maximum;
     IncrementalProgress = incrementalProgress;
 }