public static ResourceQuantity operator *(int quantity, Resource resource) { var q = new ResourceQuantity(); q.Add(resource, quantity); return(q); }
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); }
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); }
/// <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); }
public ResourceQuantity(ResourceQuantity q) { if (q != null) { foreach (var x in q) { Add(x); } } }
/// <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); }
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); }
public int CompareTo(ResourceQuantity other) { return(this.Sum(kvp => kvp.Value).CompareTo(other.Sum(kvp => kvp.Value))); }
public ResourceProgress(ResourceQuantity value, ResourceQuantity maximum, ResourceQuantity incrementalProgress) { Value = value; Maximum = maximum; IncrementalProgress = incrementalProgress; }