public void Operate(PollutionMap input) { pollutionMap.Clear(); var pollutionAttrib = GetAttrib().pollutionAttrib; foreach (var emission in pollutionAttrib.emissions) { var pollutantName = emission.pollutantName; float emissionAmount = emission.emissionPerTurn; if (emission.emissionPerTurn < 0) { if (input.ContainsKey(pollutantName)) { float existingPollution = input[pollutantName]; emissionAmount = (emissionAmount + existingPollution) > 0 ? emissionAmount : -existingPollution; } else { emissionAmount = 0; } } pollutionMap.Add(pollutantName, emissionAmount); } pollutionMapChangeEvent.Invoke(); }
public static PollutionMap operator +(PollutionMap lhs, PollutionMap rhs) { var result = new PollutionMap(lhs); foreach (var pair in rhs) { if (!result.ContainsKey(pair.Key)) { result.Add(pair.Key, pair.Value); } else { result[pair.Key] += pair.Value; } } return(result); }
private PollutionMap SumOwnedPolluterPollutionMapIf(System.Predicate <float> pred) { var result = new PollutionMap { }; foreach (var polluter in polluters) { foreach (var pair in polluter.GetPollutionMap()) { if (!result.ContainsKey(pair.Key)) { result.Add(pair.Key, 0); } if (pred(pair.Value)) { result[pair.Key] += pair.Value; } } } return(result); }