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); }
public PollutionMap ComputeFilteredPollution(PollutionMap pollutionMap) { var result = new PollutionMap { }; var pollutionAttrib = GetAttrib().pollutionAttrib; foreach (var emission in pollutionAttrib.emissions) { var pollutantName = emission.pollutantName; if (pollutionMap.ContainsKey(pollutantName)) { float targetPollution = pollutionMap[pollutantName]; float filterAbility = -emission.emissionPerTurn; float filtered = targetPollution > filterAbility ? filterAbility : targetPollution; result[pollutantName] = -filtered; } } 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); }