コード例 #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();
    }
コード例 #2
0
    public void SetLocalPollution(PollutionMap map)
    {
        localPollution.CopyAssign(map);
        localPollutionEvent.Invoke(null, map);

        OutPut();
    }
コード例 #3
0
    public PollutionMap PlusEquals(PollutionMap rhs)
    {
        var result = this + rhs;

        CopyAssign(result);
        return(this);
    }
コード例 #4
0
    private bool CheckNode(GameObject targetGameObject)
    {
        bool hasFoundData = false;

        Node node = targetGameObject.GetComponentInChildren <Node>();

        if (node != null)
        {
            PollutionMap map = node.GetPollutionMap();

            float total = map.GetTotalPollution();

            if (total < 0)
            {
                hasFoundData = true;

                SetPieChart(nodeContent.pieChart, Util.MultiplyMap(map, -1));
            }
            else if (total > 0)
            {
                hasFoundData = true;

                SetPieChart(nodeContent.pieChart, map);
            }

            imageToShow     = false;
            imageIsDisaster = false;
        }

        return(hasFoundData);
    }
コード例 #5
0
 public PollutionMap CopyAssign(PollutionMap rhs)
 {
     Clear();
     foreach (var pair in rhs)
     {
         Add(pair.Key, pair.Value);
     }
     return(this);
 }
コード例 #6
0
    public static PollutionMap MultiplyMap(PollutionMap map, float coefficient)
    {
        var result = new PollutionMap(map);

        foreach (var key in result.Keys.ToArray())
        {
            result[key] *= coefficient;
        }
        return(result);
    }
コード例 #7
0
    public static PollutionMap DivideMap(PollutionMap map, float denominator)
    {
        var result = new PollutionMap(map);

        foreach (var key in result.Keys.ToArray())
        {
            result[key] /= denominator;
        }
        return(result);
    }
コード例 #8
0
    public static float SumMap(PollutionMap map)
    {
        float sum = 0;

        foreach (var pair in map)
        {
            sum += pair.Value;
        }
        return(sum);
    }
コード例 #9
0
    private bool CheckPolluter(GameObject targetGameObject)
    {
        bool hasFoundData = false;

        Polluter polluter = targetGameObject.GetComponentInChildren <Polluter>();

        if (polluter != null)
        {
            hasFoundData = true;
            PolluterAttrib attrib = polluter.GetAttrib();

            polluterContent.textTitle.text = attrib.title;

            polluterContent.textDetails.text = "Price: " + attrib.economicAttrib.price + " Income: " + attrib.economicAttrib.profitPerTurn + "\nRemoval cost: " + attrib.economicAttrib.removalCost;

            VulnerabilityAttrib vulnerabilityAttrib = attrib.vulnerabilityAttrib;
            if (vulnerabilityAttrib.vulnerabilities != null)
            {
                string vulnerabilityString = "Vulnerable to ";
                foreach (VulnerabilityAttrib.Vulnerability v in vulnerabilityAttrib.vulnerabilities)
                {
                    vulnerabilityString += v.disasterName + ":" + v.factor + " ";
                }
                polluterContent.textVulnerabilities.text = vulnerabilityString;
            }
            else
            {
                polluterContent.textVulnerabilities.text = "";
            }

            PollutionMap map = new PollutionMap(attrib.pollutionAttrib.emissions);

            if (polluter is Filter)
            {
                map = Util.MultiplyMap(map, (-1));
            }

            VisualAttrib visualAttrib = attrib.visualAttrib;
            if (visualAttrib.imageName != "")
            {
                worldWindow.imageLoader.LoadImage(visualAttrib.imageName);
                imageToShow = true;
            }
            else
            {
                imageToShow = false;
            }

            imageIsDisaster = !polluter.IsAlive();

            SetPieChart(polluterContent.pieChart, map);
        }

        return(hasFoundData);
    }
コード例 #10
0
    private bool CheckGraphicPolluter(PurchasableIcon purchasableIcon)
    {
        bool hasFoundData = false;

        PolluterAttrib attrib = purchasableIcon.GetPolluterAttributes();

        if (attrib != null)
        {
            hasFoundData = true;

            polluterContent.textTitle.text = attrib.title;

            polluterContent.textDetails.text = "Price: " + attrib.economicAttrib.price + " Income: " + attrib.economicAttrib.profitPerTurn + "\nRemoval cost: " + attrib.economicAttrib.removalCost;

            VulnerabilityAttrib vulnerabilityAttrib = attrib.vulnerabilityAttrib;
            if (vulnerabilityAttrib.vulnerabilities != null)
            {
                string vulnerabilityString = ""; //"Vulnerable to ";
                foreach (VulnerabilityAttrib.Vulnerability v in vulnerabilityAttrib.vulnerabilities)
                {
                    vulnerabilityString += v.disasterName + ": " + v.factor + " ";
                }
                polluterContent.textVulnerabilities.text = vulnerabilityString;
            }
            else
            {
                polluterContent.textVulnerabilities.text = "";
            }


            PollutionMap map = new PollutionMap(attrib.pollutionAttrib.emissions);

            if (purchasableIcon.GetPolluterIcon().GetPolluter().GetEntityType() == EntityType.FILTER)
            {
                map = Util.MultiplyMap(map, (-1));
            }

            VisualAttrib visualAttrib = attrib.visualAttrib;
            if (visualAttrib.imageName != "")
            {
                worldWindow.imageLoader.LoadImage(visualAttrib.imageName);
                imageToShow = true;
            }
            else
            {
                imageToShow = false;
            }

            imageIsDisaster = false;

            SetPieChart(polluterContent.pieChart, map);
        }

        return(hasFoundData);
    }
コード例 #11
0
    public PollutionMap GetPollutionMapSum(PollutionMapType type)
    {
        PollutionMap sum = new PollutionMap {
        };

        foreach (var pair in playerStates)
        {
            sum += pair.Value.GetAccumulatedPollutionMap(type);
        }
        return(sum);
    }
コード例 #12
0
    private PollutionMap SumSeaEntrancePollution()
    {
        var result = new PollutionMap {
        };

        foreach (var seaEntrance in seaEntrances)
        {
            result += seaEntrance.GetPollutionMap();
        }
        return(result);
    }
コード例 #13
0
    public static PollutionMap SumMap(Dictionary <Flow, PollutionMap> map)
    {
        var sum = new PollutionMap {
        };

        foreach (var pair in map)
        {
            sum += pair.Value;
        }
        return(sum);
    }
コード例 #14
0
    public void Input(Flow flow, PollutionMap map)
    {
        if (!inFlowPollutions.ContainsKey(flow))
        {
            inFlowPollutions.Add(flow, new PollutionMap {
            });
        }

        inFlowPollutions[flow].CopyAssign(map);
        inputEvent.Invoke(flow, map);

        OutPut();
    }
コード例 #15
0
    private void UpdateCurrentPieChart()
    {
        PollutionMap map = worldStateManager.GetPlayerState(player.id).GetTurnPollutionMap(showingOrder[currentTypeShown].pollutionMapType);

        if (showingOrder[currentTypeShown].pollutionMapType == PollutionMapType.FILTERED)
        {
            map = Util.MultiplyMap(map, (-1));
        }

        pollutionPie.SetPollutionMap(map);

        pollutionPie.Draw();
    }
コード例 #16
0
    void LerpColor(PollutionMap map)
    {
        float sum  = Util.SumMap(map);
        float time = sum / maxPollution;

        time = time > 1 ? 1 : time;
        float[] rgba = new float[4];
        for (int i = 0; i != 4; ++i)
        {
            rgba[i] = curves[i].Evaluate(time);
        }
        var color = new Color(rgba[0], rgba[1], rgba[2], rgba[3]);

        lineRenderer.startColor = color;
        lineRenderer.endColor   = color;
    }
コード例 #17
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);
    }
コード例 #18
0
    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);
    }
コード例 #19
0
    private void UpdatePieChart()
    {
        PollutionMap map1   = player1Stat.playerState.GetTurnPollutionMap(typeOrder[currentTypeIndex].mapType);
        float        value1 = map1.GetTotalPollution();

        PollutionMap map2   = player2Stat.playerState.GetTurnPollutionMap(typeOrder[currentTypeIndex].mapType);
        float        value2 = map2.GetTotalPollution();

        if (typeOrder[currentTypeIndex].mapType == PollutionMapType.FILTERED)
        {
            value1 *= -1;
            value2 *= -1;
        }

        pieChart.SetPlayersValue(value1, value2);
        pieChart.SetTitle(typeOrder[currentTypeIndex].title);

        pieChart.Draw();
    }
コード例 #20
0
    public void SetBaseEmission(PollutionAttrib attrib)
    {
        var baseEmission           = new PollutionMap(attrib.emissions);
        var baseEmissionComps      = GetComponentsInChildren <BaseEmission>();
        var validBaseEmissionComps = new List <BaseEmission>();

        foreach (var comp in baseEmissionComps)
        {
            if (comp.gameObject.activeInHierarchy)
            {
                validBaseEmissionComps.Add(comp);
            }
        }
        var divided = Util.DivideMap(baseEmission, baseEmissionComps.Length);

        foreach (var comp in validBaseEmissionComps)
        {
            comp.SetLocalPollution(divided);
        }
    }
コード例 #21
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);
    }
コード例 #22
0
    private bool CheckBalticSea(GameObject targetGameObject)
    {
        bool hasFoundData = false;

        Node node = targetGameObject.GetComponentInChildren <Node>();

        if (node != null)
        {
            if (node.CompareTag(balticTag))
            {
                hasFoundData = true;

                PollutionMap map = node.GetPollutionMap();

                SetPieChart(balticContent.pieChart, map);
            }

            imageToShow     = false;
            imageIsDisaster = false;
        }

        return(hasFoundData);
    }
コード例 #23
0
 public void SetPollutionMap(PollutionMap map)
 {
     pollutionMap = map;
 }
コード例 #24
0
 public PollutionMap(PollutionMap other) : base(other)
 {
 }
コード例 #25
0
 protected void SetPollutionMap(PollutionMap map)
 {
     pollutionMap = map;
     pollutionMapChangeEvent.Invoke();
 }
コード例 #26
0
 public void SetPollutionMap(PollutionMap map)
 {
     pollutionMap = map;
     pollutionMap.Keys.ToString();
 }
コード例 #27
0
 private void SetPieChart(PieChartController pieChart, PollutionMap map)
 {
     pieChart.Clear();
     pieChart.SetPollutionMap(map);
     pieChart.Draw();
 }