Description:
Add trespassing policy.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r359:e0b0d93962c3 -

@@ -0,0 +1,21
1 using Encompass;
2 using System;
3 using System.ComponentModel.DataAnnotations;
4 // using System.ComponentModel;
5
6 namespace isometricparkfna.Components {
7
8 public enum EnforcementLevel {
9 Unspecified,
10 // [Display(Name = "No Enforcement")]
11 NoEnforcement,
12 // [Display(Name = "Rangers, warnings")]
13 EnforcedWithWarnings,
14 // [Display(Name = "Rangers, citations")]
15 EnforcedWithFines
16 }
17
18 public struct TrespassingPolicyComponent : IComponent {
19 public EnforcementLevel tresspassingPolicy;
20 }
21 }
@@ -0,0 +1,56
1 using System;
2
3 using Encompass;
4
5 using isometricparkfna.Messages;
6 using isometricparkfna.Components;
7
8 namespace isometricparkfna.Engines
9 {
10
11 [Receives(typeof(SetTrespassingPolicyMessage))]
12 [Reads(typeof(TrespassingPolicyComponent))]
13 [Writes(typeof(TrespassingPolicyComponent),
14 typeof(BudgetLineComponent))]
15 public class PolicyEngine : Engine
16 {
17
18 public PolicyEngine()
19 {
20 }
21
22
23 public override void Update(double dt)
24 {
25 foreach (ref readonly var message
26 in ReadMessages<SetTrespassingPolicyMessage>())
27 {
28 foreach (ref readonly var entity
29 in ReadEntities<TrespassingPolicyComponent>())
30 {
31
32 SetComponent<TrespassingPolicyComponent>(entity,
33 new TrespassingPolicyComponent {tresspassingPolicy
34 = message.newEnforcementLevel });
35
36 var newCost =message.newEnforcementLevel switch {
37 EnforcementLevel.NoEnforcement => 0,
38 EnforcementLevel.EnforcedWithWarnings => 100,
39 EnforcementLevel.EnforcedWithFines => 100,
40
41
42 };
43
44
45 SetComponent<BudgetLineComponent>(entity,
46 new BudgetLineComponent {category = "Enforcement",
47 amount = newCost
48 });
49
50 }
51 }
52
53 }
54
55 }
56 }
@@ -0,0 +1,9
1 using Encompass;
2 using isometricparkfna.Components;
3
4 namespace isometricparkfna.Messages {
5
6 public struct SetTrespassingPolicyMessage : IMessage {
7 public EnforcementLevel newEnforcementLevel;
8 }
9 }
1 NO CONTENT: modified file, binary diff hidden
@@ -18,9 +18,11
18 18 typeof(GameStateMessage),
19 19 typeof(GameStateMessage),
20 20 typeof(SetResolutionMessage),
21 typeof(SetFontMessage))]
21 typeof(SetFontMessage),
22 typeof(SetTrespassingPolicyMessage))]
22 23 [Reads(typeof(VisibilityComponent),
23 typeof(WindowTypeComponent)
24 typeof(WindowTypeComponent),
25 typeof(TrespassingPolicyComponent)
24 26 //, typeof(SelectedComponent)
25 27 )]
26 28 // [Writes(typeof(SelectedComponent))]
@@ -35,6 +37,7
35 37 public List<GameStateMessage> gameStateMessages;
36 38 public List<SetResolutionMessage> resolutionMessages;
37 39 public List<SetFontMessage> fontMessages;
40 public List<SetTrespassingPolicyMessage> trespassingPolicyMessages;
38 41
39 42 bool showBudget {get;}
40 43 bool showForest {get;}
@@ -60,6 +63,7
60 63 this.gameStateMessages = new List<GameStateMessage>();
61 64 this.resolutionMessages = new List<SetResolutionMessage>();
62 65 this.fontMessages = new List<SetFontMessage>();
66 this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>();
63 67 this.windowStatuses = new Dictionary<Window, bool>();
64 68
65 69
@@ -124,6 +128,11
124 128 message.fontSize);
125 129 }
126 130
131 foreach (var message in this.trespassingPolicyMessages)
132 {
133 SendMessage(message);
134 }
135
127 136
128 137
129 138 foreach(var entity in ReadEntities<WindowTypeComponent>())
@@ -142,6 +151,7
142 151 this.gameStateMessages.Clear();
143 152 this.resolutionMessages.Clear();
144 153 this.fontMessages.Clear();
154 this.trespassingPolicyMessages.Clear();
145 155 }
146 156 }
147 } No newline at end of file
157 }
@@ -64,29 +64,31
64 64 }
65 65
66 66 decimal new_contract_amount = 0M;
67 decimal new_enforcement_amount = 0M;
68 // decimal new_upkeep_amount = 0M;
67 69
68 70 foreach (ref readonly var entity in ReadEntities<BudgetLineComponent>())
69 71 {
70 72 ref readonly var budgetComponent = ref GetComponent<BudgetLineComponent>(entity);
71 var status = GetComponent<ContractStatusComponent>(entity).status;
72 73
73 74 // SetComponent(entity, new BudgetComponent{currentBudget = this.simulation.latestBudget,
74 75 // priorBudget = this.simulation.previousBudget});
75 76 switch (budgetComponent.category)
76 77 {
77 78 case "Contracts":
78
79 var status = GetComponent<ContractStatusComponent>(entity).status;
79 80 if (status == ContractStatus.Accepted)
80 81 {
81 82 new_contract_amount += budgetComponent.amount;
82 83 }
83 84 break;
85 case "Enforcement":
86 new_enforcement_amount += budgetComponent.amount;
87 break;
84 88 }
85 89
86 90 }
87 91
88
89
90 92 if (this.ticksToSend > 0)
91 93 {
92 94
@@ -139,6 +141,7
139 141 this.ticksToSend = 0;
140 142
141 143 simulation.contracts = new_contract_amount;
144 simulation.enforcement = new_enforcement_amount;
142 145
143 146 }
144 147
@@ -266,6 +266,7
266 266
267 267 WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar));
268 268 WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar));
269 WorldBuilder.AddEngine(new PolicyEngine());
269 270
270 271 WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.batch, this.monoFont), 1);
271 272 WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine, this.gdm) , 2);
@@ -300,6 +301,14
300 301
301 302 WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false});
302 303
304 var policyEntity = WorldBuilder.CreateEntity();
305 WorldBuilder.SetComponent(policyEntity,
306 new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement});
307 WorldBuilder.SetComponent(policyEntity,
308 new BudgetLineComponent { });
309
310
311
303 312
304 313 var area = WorldBuilder.CreateEntity();
305 314 var size = 5;
@@ -26,6 +26,8
26 26 public decimal upkeep;
27 27 public decimal tree_planting;
28 28 public decimal tree_clearing;
29 public decimal miscellaneous;
30 public decimal enforcement;
29 31
30 32
31 33 public decimal final_money;
@@ -87,6 +89,7
87 89 public SimulationBridgeEngine BridgeEngine { get; private set; }
88 90 // public SimulationBridgeEngine bridgeEngine {get;}
89 91 public decimal contracts;
92 public decimal enforcement;
90 93
91 94 public Budget latestBudget
92 95 {
@@ -296,6 +299,7
296 299 trees = this.map.tree_count,
297 300 subsidy = 1000,
298 301 contracts = this.contracts,
302 enforcement = this.enforcement,
299 303 upkeep = (int)(this.map.tree_count * 1.5),
300 304 tree_planting = this.tree_planting * Simulation.TREE_PLANT_COST,
301 305 tree_clearing = this.tree_clearing * Simulation.TREE_CLEAR_COST
@@ -314,7 +318,7
314 318 {
315 319
316 320 this.money = budget.money
317 - (budget.upkeep + budget.tree_planting + budget.tree_clearing)
321 - (budget.upkeep + budget.tree_planting + budget.tree_clearing + budget.enforcement)
318 322 + (budget.subsidy + budget.contracts);
319 323
320 324
@@ -109,6 +109,7
109 109 batch.DrawString(font, String.Format("Upkeep.................${0:}....${1:}", this.budget.upkeep, this.previous_budget.upkeep), new Vector2(x, bar_height * 10 + y), Color.Black);
110 110 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);
111 111 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);
112 batch.DrawString(font, String.Format("Enforcement............${0:}....${1:}", this.budget.enforcement, this.previous_budget.enforcement), new Vector2(x, bar_height * 13 + y), Color.Black);
112 113
113 114 Color cashflow_color = Color.Black;
114 115 if (this.budget.cashflow < 0) {
@@ -119,8 +120,8
119 120 final_color = Color.Red;
120 121 }
121 122
122 batch.DrawString(font, String.Format("Cashflow.............${0:}....${1:}", this.budget.cashflow, this.previous_budget.cashflow), new Vector2(x, bar_height * 14 + y), cashflow_color);
123 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);
123 batch.DrawString(font, String.Format("Cashflow.............${0:}....${1:}", this.budget.cashflow, this.previous_budget.cashflow), new Vector2(x, bar_height * 15 + y), cashflow_color);
124 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);
124 125
125 126
126 127 FilledRectangle.drawFilledRectangle(batch, new Rectangle(50, 50, 50, 50), new Color (0, 0,0, 0), 0.99f);
@@ -1,8 +1,10
1 using System;
2 using Num = System.Numerics;
3
1 4 using ImGuiNET;
2 5
3 using Num = System.Numerics;
4
5 6 using isometricparkfna.Messages;
7 using isometricparkfna.Components;
6 8 using isometricparkfna.Engines;
7 9
8 10 namespace isometricparkfna.UI
@@ -11,6 +13,10
11 13 public static class ForestWindow
12 14 {
13 15 public static bool hadFocus = false;
16
17 private static bool enforceTresspassing1 = false;
18 private static string enforceTresspassing2 = "None";
19
14 20 public static void Render(bool show, ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine)
15 21 {
16 22 bool newShow = show;
@@ -43,6 +49,53
43 49 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));
44 50 sim.tree_clearing = new_tree_clearing;
45 51
52 ImGui.Checkbox("Enforce Trespassing.", ref enforceTresspassing1);
53
54 ImGui.Text("Enforce tresspassing?");
55 ImGui.SameLine();
56
57 if (ImGui.BeginCombo("##tresspassing2", enforceTresspassing2))
58 {
59
60 // if ( ImGui.Selectable("None"))
61 // {
62 // enforceTresspassing2 = "None";
63 // }
64 // if (ImGui.Selectable("Rangers, warnings"))
65 // {
66 // enforceTresspassing2 = "Rangers, warnings";
67 // }
68 // if (ImGui.Selectable("Rangers, citations"))
69 // {
70 // enforceTresspassing2 = "Rangers, citations";
71 // }
72
73 foreach (EnforcementLevel option in EnforcementLevel.GetValues(typeof(EnforcementLevel)))
74 {
75
76 if (ImGui.Selectable(option.ToString()))
77 {
78 enforceTresspassing2 = option.ToString();
79 }
80 }
81
82 ImGui.EndCombo();
83 }
84 ImGui.SameLine();
85 ImGui.TextDisabled("(?)");
86 if (ImGui.IsItemHovered())
87 {
88 var rect = ImGui.GetItemRectMax();
89 ImGui.SetNextWindowPos(rect + new Num.Vector2(15, 0));
90 ImGui.BeginTooltip();
91 ImGui.Text("Enforcing tresspassing lowers upkeep, but costs money.\n\nRacial minorities may also be targeted unfairly.");
92 ImGui.EndTooltip();
93 }
94
95
96
97 ImGui.Separator();
98
46 99 ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees ));
47 100 ImGui.Text(string.Format("Percent Healthy Trees: {0:F2}", sim.healthy_percent));
48 101 ImGui.Text(string.Format("Average Age of Trees: {0:F2}", sim.average_tree_age));
@@ -51,9 +104,11
51 104 if (ImGui.Button("Okay"))
52 105 {
53 106 show = false;
107 Logging.Spy(new {newEnforcementLevel = (EnforcementLevel)Enum.Parse(typeof(EnforcementLevel), enforceTresspassing2)});
108 engine.trespassingPolicyMessages.Add(new SetTrespassingPolicyMessage{newEnforcementLevel = (EnforcementLevel)Enum.Parse(typeof(EnforcementLevel), enforceTresspassing2)});
54 109 }
55 110
56 ImGui.End();
111 ImGui.End();
57 112 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
58 113 StyleSets.defaultSet.pop();
59 114 ImGui.PopFont();
You need to be logged in to leave comments. Login now