Esempio n. 1
0
    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();
    }
Esempio n. 2
0
    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);
    }
Esempio n. 3
0
    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);
    }