# HG changeset patch # User Alys Brooks # Date 2021-07-16 09:22:10 # Node ID e0b0d93962c3fea0a9cacf0e1ea7c75b5263b547 # Parent 0ea73c9411dfcd2694ebf588f30ef2cda47cd99f Add trespassing policy. diff --git a/SpriteFontPlus/src/obj/Debug/net45/SpriteFontPlus.FNA.assets.cache b/SpriteFontPlus/src/obj/Debug/net45/SpriteFontPlus.FNA.assets.cache index 6ca2105711c886143efa663a1cbeac7dd3b3a1ec..fa7a5be7ee40b2fb967e125c2ae0eb0e66d3bbde GIT binary patch literal 136 zc$^FHc6a1rU|?7w@?U#WeDz(1z7w}L8ugU?oXpsDd9L@1zs`wz33dB5TNnrfMj)2f h&&bbB)lbZ+EY{b{D@{)=(Jx3$&Q45EE!M}U7XZJ-96SI3 diff --git a/isometric-park-fna/Components/TrespassingPolicyComponent.cs b/isometric-park-fna/Components/TrespassingPolicyComponent.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/TrespassingPolicyComponent.cs @@ -0,0 +1,21 @@ +using Encompass; +using System; +using System.ComponentModel.DataAnnotations; +// using System.ComponentModel; + +namespace isometricparkfna.Components { + + public enum EnforcementLevel { + Unspecified, + // [Display(Name = "No Enforcement")] + NoEnforcement, + // [Display(Name = "Rangers, warnings")] + EnforcedWithWarnings, + // [Display(Name = "Rangers, citations")] + EnforcedWithFines + } + + public struct TrespassingPolicyComponent : IComponent { + public EnforcementLevel tresspassingPolicy; + } +} diff --git a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs --- a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs +++ b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs @@ -18,9 +18,11 @@ typeof(GameStateMessage), typeof(GameStateMessage), typeof(SetResolutionMessage), - typeof(SetFontMessage))] + typeof(SetFontMessage), + typeof(SetTrespassingPolicyMessage))] [Reads(typeof(VisibilityComponent), - typeof(WindowTypeComponent) + typeof(WindowTypeComponent), + typeof(TrespassingPolicyComponent) //, typeof(SelectedComponent) )] // [Writes(typeof(SelectedComponent))] @@ -35,6 +37,7 @@ public List gameStateMessages; public List resolutionMessages; public List fontMessages; + public List trespassingPolicyMessages; bool showBudget {get;} bool showForest {get;} @@ -60,6 +63,7 @@ this.gameStateMessages = new List(); this.resolutionMessages = new List(); this.fontMessages = new List(); + this.trespassingPolicyMessages = new List(); this.windowStatuses = new Dictionary(); @@ -124,6 +128,11 @@ message.fontSize); } + foreach (var message in this.trespassingPolicyMessages) + { + SendMessage(message); + } + foreach(var entity in ReadEntities()) @@ -142,6 +151,7 @@ this.gameStateMessages.Clear(); this.resolutionMessages.Clear(); this.fontMessages.Clear(); + this.trespassingPolicyMessages.Clear(); } } -} \ No newline at end of file +} diff --git a/isometric-park-fna/Engines/PolicyEngine.cs b/isometric-park-fna/Engines/PolicyEngine.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Engines/PolicyEngine.cs @@ -0,0 +1,56 @@ +using System; + +using Encompass; + +using isometricparkfna.Messages; +using isometricparkfna.Components; + +namespace isometricparkfna.Engines +{ + + [Receives(typeof(SetTrespassingPolicyMessage))] + [Reads(typeof(TrespassingPolicyComponent))] + [Writes(typeof(TrespassingPolicyComponent), + typeof(BudgetLineComponent))] + public class PolicyEngine : Engine + { + + public PolicyEngine() + { + } + + + public override void Update(double dt) + { + foreach (ref readonly var message + in ReadMessages()) + { + foreach (ref readonly var entity + in ReadEntities()) + { + + SetComponent(entity, + new TrespassingPolicyComponent {tresspassingPolicy + = message.newEnforcementLevel }); + + var newCost =message.newEnforcementLevel switch { + EnforcementLevel.NoEnforcement => 0, + EnforcementLevel.EnforcedWithWarnings => 100, + EnforcementLevel.EnforcedWithFines => 100, + + + }; + + + SetComponent(entity, + new BudgetLineComponent {category = "Enforcement", + amount = newCost + }); + + } + } + + } + + } +} diff --git a/isometric-park-fna/Engines/SimulationBridgeEngine.cs b/isometric-park-fna/Engines/SimulationBridgeEngine.cs --- a/isometric-park-fna/Engines/SimulationBridgeEngine.cs +++ b/isometric-park-fna/Engines/SimulationBridgeEngine.cs @@ -64,29 +64,31 @@ } decimal new_contract_amount = 0M; + decimal new_enforcement_amount = 0M; + // decimal new_upkeep_amount = 0M; foreach (ref readonly var entity in ReadEntities()) { ref readonly var budgetComponent = ref GetComponent(entity); - var status = GetComponent(entity).status; // SetComponent(entity, new BudgetComponent{currentBudget = this.simulation.latestBudget, // priorBudget = this.simulation.previousBudget}); switch (budgetComponent.category) { case "Contracts": - + var status = GetComponent(entity).status; if (status == ContractStatus.Accepted) { new_contract_amount += budgetComponent.amount; } break; + case "Enforcement": + new_enforcement_amount += budgetComponent.amount; + break; } } - - if (this.ticksToSend > 0) { @@ -139,6 +141,7 @@ this.ticksToSend = 0; simulation.contracts = new_contract_amount; + simulation.enforcement = new_enforcement_amount; } diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -266,6 +266,7 @@ WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar)); WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar)); + WorldBuilder.AddEngine(new PolicyEngine()); WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.batch, this.monoFont), 1); WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine, this.gdm) , 2); @@ -300,6 +301,14 @@ WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); + var policyEntity = WorldBuilder.CreateEntity(); + WorldBuilder.SetComponent(policyEntity, + new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement}); + WorldBuilder.SetComponent(policyEntity, + new BudgetLineComponent { }); + + + var area = WorldBuilder.CreateEntity(); var size = 5; diff --git a/isometric-park-fna/Messages/SetTrespassingPolicyMessage.cs b/isometric-park-fna/Messages/SetTrespassingPolicyMessage.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Messages/SetTrespassingPolicyMessage.cs @@ -0,0 +1,9 @@ +using Encompass; +using isometricparkfna.Components; + +namespace isometricparkfna.Messages { + + public struct SetTrespassingPolicyMessage : IMessage { + public EnforcementLevel newEnforcementLevel; + } +} diff --git a/isometric-park-fna/Simulation.cs b/isometric-park-fna/Simulation.cs --- a/isometric-park-fna/Simulation.cs +++ b/isometric-park-fna/Simulation.cs @@ -26,6 +26,8 @@ public decimal upkeep; public decimal tree_planting; public decimal tree_clearing; + public decimal miscellaneous; + public decimal enforcement; public decimal final_money; @@ -87,6 +89,7 @@ public SimulationBridgeEngine BridgeEngine { get; private set; } // public SimulationBridgeEngine bridgeEngine {get;} public decimal contracts; + public decimal enforcement; public Budget latestBudget { @@ -296,6 +299,7 @@ trees = this.map.tree_count, subsidy = 1000, contracts = this.contracts, + enforcement = this.enforcement, upkeep = (int)(this.map.tree_count * 1.5), tree_planting = this.tree_planting * Simulation.TREE_PLANT_COST, tree_clearing = this.tree_clearing * Simulation.TREE_CLEAR_COST @@ -314,7 +318,7 @@ { this.money = budget.money - - (budget.upkeep + budget.tree_planting + budget.tree_clearing) + - (budget.upkeep + budget.tree_planting + budget.tree_clearing + budget.enforcement) + (budget.subsidy + budget.contracts); diff --git a/isometric-park-fna/UI/BudgetWindow.cs b/isometric-park-fna/UI/BudgetWindow.cs --- a/isometric-park-fna/UI/BudgetWindow.cs +++ b/isometric-park-fna/UI/BudgetWindow.cs @@ -109,6 +109,7 @@ batch.DrawString(font, String.Format("Upkeep.................${0:}....${1:}", this.budget.upkeep, this.previous_budget.upkeep), new Vector2(x, bar_height * 10 + y), Color.Black); batch.DrawString(font, String.Format("Tree Planting..........${0:}....${1:}", this.budget.tree_planting, this.previous_budget.tree_planting), new Vector2(x, bar_height * 11 + y), Color.Black); batch.DrawString(font, String.Format("Tree Clearing..........${0:}....${1:}", this.budget.tree_clearing, this.previous_budget.tree_clearing), new Vector2(x, bar_height * 12 + y), Color.Black); + batch.DrawString(font, String.Format("Enforcement............${0:}....${1:}", this.budget.enforcement, this.previous_budget.enforcement), new Vector2(x, bar_height * 13 + y), Color.Black); Color cashflow_color = Color.Black; if (this.budget.cashflow < 0) { @@ -119,8 +120,8 @@ final_color = Color.Red; } - batch.DrawString(font, String.Format("Cashflow.............${0:}....${1:}", this.budget.cashflow, this.previous_budget.cashflow), new Vector2(x, bar_height * 14 + y), cashflow_color); - batch.DrawString(font, String.Format("Ending Funds.........${0:}....${1:}", this.budget.final_money, this.previous_budget.final_money), new Vector2(x, bar_height * 15 + y), final_color); + batch.DrawString(font, String.Format("Cashflow.............${0:}....${1:}", this.budget.cashflow, this.previous_budget.cashflow), new Vector2(x, bar_height * 15 + y), cashflow_color); + batch.DrawString(font, String.Format("Ending Funds.........${0:}....${1:}", this.budget.final_money, this.previous_budget.final_money), new Vector2(x, bar_height * 16 + y), final_color); FilledRectangle.drawFilledRectangle(batch, new Rectangle(50, 50, 50, 50), new Color (0, 0,0, 0), 0.99f); diff --git a/isometric-park-fna/UI/ForestWindow.cs b/isometric-park-fna/UI/ForestWindow.cs --- a/isometric-park-fna/UI/ForestWindow.cs +++ b/isometric-park-fna/UI/ForestWindow.cs @@ -1,8 +1,10 @@ +using System; +using Num = System.Numerics; + using ImGuiNET; -using Num = System.Numerics; - using isometricparkfna.Messages; +using isometricparkfna.Components; using isometricparkfna.Engines; namespace isometricparkfna.UI @@ -11,6 +13,10 @@ public static class ForestWindow { public static bool hadFocus = false; + + private static bool enforceTresspassing1 = false; + private static string enforceTresspassing2 = "None"; + public static void Render(bool show, ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine) { bool newShow = show; @@ -43,6 +49,53 @@ ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, Simulation.MAX_TREES_TO_CLEAR, string.Format("%d (${0})", new_tree_clearing*Simulation.TREE_CLEAR_COST)); sim.tree_clearing = new_tree_clearing; + ImGui.Checkbox("Enforce Trespassing.", ref enforceTresspassing1); + + ImGui.Text("Enforce tresspassing?"); + ImGui.SameLine(); + + if (ImGui.BeginCombo("##tresspassing2", enforceTresspassing2)) + { + + // if ( ImGui.Selectable("None")) + // { + // enforceTresspassing2 = "None"; + // } + // if (ImGui.Selectable("Rangers, warnings")) + // { + // enforceTresspassing2 = "Rangers, warnings"; + // } + // if (ImGui.Selectable("Rangers, citations")) + // { + // enforceTresspassing2 = "Rangers, citations"; + // } + + foreach (EnforcementLevel option in EnforcementLevel.GetValues(typeof(EnforcementLevel))) + { + + if (ImGui.Selectable(option.ToString())) + { + enforceTresspassing2 = option.ToString(); + } + } + + ImGui.EndCombo(); + } + ImGui.SameLine(); + ImGui.TextDisabled("(?)"); + if (ImGui.IsItemHovered()) + { + var rect = ImGui.GetItemRectMax(); + ImGui.SetNextWindowPos(rect + new Num.Vector2(15, 0)); + ImGui.BeginTooltip(); + ImGui.Text("Enforcing tresspassing lowers upkeep, but costs money.\n\nRacial minorities may also be targeted unfairly."); + ImGui.EndTooltip(); + } + + + + ImGui.Separator(); + ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees )); ImGui.Text(string.Format("Percent Healthy Trees: {0:F2}", sim.healthy_percent)); ImGui.Text(string.Format("Average Age of Trees: {0:F2}", sim.average_tree_age)); @@ -51,9 +104,11 @@ if (ImGui.Button("Okay")) { show = false; + Logging.Spy(new {newEnforcementLevel = (EnforcementLevel)Enum.Parse(typeof(EnforcementLevel), enforceTresspassing2)}); + engine.trespassingPolicyMessages.Add(new SetTrespassingPolicyMessage{newEnforcementLevel = (EnforcementLevel)Enum.Parse(typeof(EnforcementLevel), enforceTresspassing2)}); } - ImGui.End(); + ImGui.End(); ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; StyleSets.defaultSet.pop(); ImGui.PopFont();