From 9be4808b6d5af4d95457e5f95bde5742a35f54be Mon Sep 17 00:00:00 2001
From: 6d486f49 <76097bcc@gmail.com>
Date: Tue, 19 May 2026 17:06:06 -0400
Subject: [PATCH] Some stub build plan calculator code
---
.../Components/Pages/BuildingCalculator.razor | 116 ++++++
AOW4/Data/BuildingCalculator.cs | 360 ++++++++++++++++++
AOW4/Data/SectionData.cs | 7 +-
3 files changed, 482 insertions(+), 1 deletion(-)
create mode 100644 AOW4/Components/Pages/BuildingCalculator.razor
create mode 100644 AOW4/Data/BuildingCalculator.cs
diff --git a/AOW4/Components/Pages/BuildingCalculator.razor b/AOW4/Components/Pages/BuildingCalculator.razor
new file mode 100644
index 0000000..0e8536e
--- /dev/null
+++ b/AOW4/Components/Pages/BuildingCalculator.razor
@@ -0,0 +1,116 @@
+@page "/building-calculator"
+@using System.Text.Json
+@using AOW4.Data
+
+
+
Building Plan Calculator
+
Simulates resource income each turn and tracks build completion times for ordered buildings.
+
+
+ Build Order
+
+
+
+ | Turn Requested |
+ Building |
+ Finish Turn |
+ Industry Remaining |
+
+
+
+ @foreach (var entry in Result.BuildOrder)
+ {
+
+ | @entry.RequestedTurn |
+ @entry.Name |
+ @(entry.BuiltFinishTurn == 0 ? "Starting" : entry.BuiltFinishTurn.ToString()) |
+ @entry.IndustryCostRemaining |
+
+ }
+
+
+
+
+
+ Gold Over Time
+
+
+
+ | Turn |
+ Stored Gold |
+ Income |
+ Upkeep |
+
+
+
+ @foreach (var snapshot in Result.ResourceHistory)
+ {
+
+ | @snapshot.Turn |
+ @snapshot.Stored.Gold |
+ @snapshot.TotalIncome.Gold |
+ @snapshot.TotalUpkeep.Gold |
+
+ }
+
+
+
+
+
+
+
+@code {
+ private BuildPlanResult Result = new();
+ private string Json = string.Empty;
+
+ protected override void OnInitialized()
+ {
+ Result = BuildingPlanCalculator.CreateSampleBuildPlan(60);
+ Json = JsonSerializer.Serialize(Result, new JsonSerializerOptions
+ {
+ WriteIndented = true
+ });
+ }
+}
+
+
diff --git a/AOW4/Data/BuildingCalculator.cs b/AOW4/Data/BuildingCalculator.cs
new file mode 100644
index 0000000..03eebe3
--- /dev/null
+++ b/AOW4/Data/BuildingCalculator.cs
@@ -0,0 +1,360 @@
+using System.Text.Json.Serialization;
+
+namespace AOW4.Data;
+
+public sealed class ResourceAmounts
+{
+ public int Draft { get; set; }
+ public int Food { get; set; }
+ public int Knowledge { get; set; }
+ public int Industry { get; set; }
+ public int Magic { get; set; }
+ public int Gold { get; set; }
+ public int Imperial { get; set; }
+ public int Stability { get; set; }
+
+ [JsonIgnore]
+ public bool IsZero => Draft == 0 && Food == 0 && Knowledge == 0 && Industry == 0 && Magic == 0 && Gold == 0 && Imperial == 0 && Stability == 0;
+
+ public void Add(ResourceAmounts other)
+ {
+ Draft += other.Draft;
+ Food += other.Food;
+ Knowledge += other.Knowledge;
+ Industry += other.Industry;
+ Magic += other.Magic;
+ Gold += other.Gold;
+ Imperial += other.Imperial;
+ Stability += other.Stability;
+ }
+
+ public void Subtract(ResourceAmounts other)
+ {
+ Draft -= other.Draft;
+ Food -= other.Food;
+ Knowledge -= other.Knowledge;
+ Industry -= other.Industry;
+ Magic -= other.Magic;
+ Gold -= other.Gold;
+ Imperial -= other.Imperial;
+ Stability -= other.Stability;
+ }
+
+ public static ResourceAmounts operator +(ResourceAmounts a, ResourceAmounts b)
+ => new ResourceAmounts
+ {
+ Draft = a.Draft + b.Draft,
+ Food = a.Food + b.Food,
+ Knowledge = a.Knowledge + b.Knowledge,
+ Industry = a.Industry + b.Industry,
+ Magic = a.Magic + b.Magic,
+ Gold = a.Gold + b.Gold,
+ Imperial = a.Imperial + b.Imperial,
+ Stability = a.Stability + b.Stability
+ };
+
+ public static ResourceAmounts operator -(ResourceAmounts a, ResourceAmounts b)
+ => new ResourceAmounts
+ {
+ Draft = a.Draft - b.Draft,
+ Food = a.Food - b.Food,
+ Knowledge = a.Knowledge - b.Knowledge,
+ Industry = a.Industry - b.Industry,
+ Magic = a.Magic - b.Magic,
+ Gold = a.Gold - b.Gold,
+ Imperial = a.Imperial - b.Imperial,
+ Stability = a.Stability - b.Stability
+ };
+}
+
+public sealed class BuildingDefinition
+{
+ public string Id { get; set; } = string.Empty;
+ public string Name { get; set; } = string.Empty;
+ public string? Description { get; set; }
+ public string? Image { get; set; }
+ public string SourceId { get; set; } = "General";
+ public List