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 void SetLocalPollution(PollutionMap map) { localPollution.CopyAssign(map); localPollutionEvent.Invoke(null, map); OutPut(); }
public PollutionMap PlusEquals(PollutionMap rhs) { var result = this + rhs; CopyAssign(result); return(this); }
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); }
public PollutionMap CopyAssign(PollutionMap rhs) { Clear(); foreach (var pair in rhs) { Add(pair.Key, pair.Value); } return(this); }
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); }
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); }
public static float SumMap(PollutionMap map) { float sum = 0; foreach (var pair in map) { sum += pair.Value; } return(sum); }
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); }
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); }
public PollutionMap GetPollutionMapSum(PollutionMapType type) { PollutionMap sum = new PollutionMap { }; foreach (var pair in playerStates) { sum += pair.Value.GetAccumulatedPollutionMap(type); } return(sum); }
private PollutionMap SumSeaEntrancePollution() { var result = new PollutionMap { }; foreach (var seaEntrance in seaEntrances) { result += seaEntrance.GetPollutionMap(); } return(result); }
public static PollutionMap SumMap(Dictionary <Flow, PollutionMap> map) { var sum = new PollutionMap { }; foreach (var pair in map) { sum += pair.Value; } return(sum); }
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(); }
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(); }
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; }
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 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(); }
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); } }
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); }
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); }
public void SetPollutionMap(PollutionMap map) { pollutionMap = map; }
public PollutionMap(PollutionMap other) : base(other) { }
protected void SetPollutionMap(PollutionMap map) { pollutionMap = map; pollutionMapChangeEvent.Invoke(); }
public void SetPollutionMap(PollutionMap map) { pollutionMap = map; pollutionMap.Keys.ToString(); }
private void SetPieChart(PieChartController pieChart, PollutionMap map) { pieChart.Clear(); pieChart.SetPollutionMap(map); pieChart.Draw(); }