Skip to content

Commit

Permalink
Merge pull request #3 from AlexSkylark/master
Browse files Browse the repository at this point in the history
fixes and new budget report window
  • Loading branch information
R-T-B authored Dec 1, 2024
2 parents 620ec19 + 894bbfc commit 2a0aad4
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 264 deletions.
19 changes: 19 additions & 0 deletions Bureaucracy/Budget/BudgetEvent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

using System;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Bureaucracy
Expand Down Expand Up @@ -57,11 +58,29 @@ public override void OnEventCompleted()
InternalListeners.OnBudgetAwarded.Fire(funding, facilityDebt);
Costs.Instance.ResetLaunchCosts();
repDecay.ApplyRepDecay(Bureaucracy.Instance.settings.RepDecayPercent);


//stringbuilder for budget report
if (!Utilities.Instance.IsBootstrapBudgetCycle)
{
StringBuilder reportBuilder = new StringBuilder();
for (int i = 0; i < Bureaucracy.Instance.registeredManagers.Count; i++)
{
Manager m = Bureaucracy.Instance.registeredManagers.ElementAt(i);
m.ThisMonthsBudget = Utilities.Instance.GetNetBudget(m.Name);

// build cycle report for the manager
var r = m.GetReport();
reportBuilder.AppendLine(r.ReportTitle.ToUpper().Replace("REPORT", "DETAILS"));
reportBuilder.AppendLine("==================================");
reportBuilder.AppendLine(r.ReportBody());
reportBuilder.AppendLine(String.Empty);
}

// show budget cycle window
UiController.Instance.BudgetCycleReportWindow(reportBuilder.ToString());
}

InformParent();
}

Expand Down
4 changes: 3 additions & 1 deletion Bureaucracy/Budget/BudgetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BudgetManager()
Debug.Log("[Bureaucracy]: Budget Manager is ready");
}

protected override Report GetReport()
public override Report GetReport()
{
return new BudgetReport();
}
Expand Down Expand Up @@ -49,6 +49,7 @@ public void OnLoad(ConfigNode cn)
if (managerNode != null)
{
bool.TryParse(managerNode.GetValue("IsBootstrapBudgetCycle"), out Utilities.Instance.IsBootstrapBudgetCycle);
double.TryParse(managerNode.GetValue("InitialFunds"), out Utilities.Instance.InitialFunds);
float.TryParse(managerNode.GetValue("FundingAllocation"), out FundingAllocation);
double.TryParse(managerNode.GetValue("nextBudget"), out nextBudgetTime);
CreateNewBudget(nextBudgetTime);
Expand Down Expand Up @@ -89,6 +90,7 @@ public void OnSave(ConfigNode cn)
Debug.Log("[Bureaucracy]: Budget Manager: OnSave");
ConfigNode managerNode = new ConfigNode("BUDGET_MANAGER");
managerNode.SetValue("IsBootstrapBudgetCycle", Utilities.Instance.IsBootstrapBudgetCycle, true);
managerNode.SetValue("InitialFunds", Utilities.Instance.InitialFunds, true);
managerNode.SetValue("FundingAllocation", FundingAllocation, true);
if (NextBudget != null) managerNode.SetValue("nextBudget", NextBudget.CompletionTime, true);
cn.AddNode(managerNode);
Expand Down
22 changes: 11 additions & 11 deletions Bureaucracy/Budget/BudgetReport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace Bureaucracy
{
Expand All @@ -12,22 +12,22 @@ public BudgetReport()
public override string ReportBody()
{
ReportBuilder.Clear();
ReportBuilder.AppendLine("Gross Budget: " + Utilities.Instance.GetGrossBudget());
ReportBuilder.AppendLine("Staff Wages: " + Costs.Instance.GetWageCosts());
ReportBuilder.AppendLine("Facility Maintenance Costs: " + Costs.Instance.GetFacilityMaintenanceCosts());
ReportBuilder.AppendLine("Launch Costs: " + Costs.Instance.GetLaunchCosts());
ReportBuilder.AppendLine("Total Maintenance Costs: " + Costs.Instance.GetTotalMaintenanceCosts());
ReportBuilder.AppendLine("Mission Bonuses: " + CrewManager.Instance.LastBonus);
ReportBuilder.AppendLine("Construction Department: " + FacilityManager.Instance.GetAllocatedFunding());
ReportBuilder.AppendLine("Research Department: " + ResearchManager.Instance.GetAllocatedFunding());
ReportBuilder.AppendLine($"Gross Budget: {Utilities.Instance.FundsSymbol}{Utilities.Instance.GetGrossBudget()}");
ReportBuilder.AppendLine($"Staff Wages: {Utilities.Instance.FundsSymbol}{Costs.Instance.GetWageCosts()}");
ReportBuilder.AppendLine($"Facility Maintenance Costs: {Utilities.Instance.FundsSymbol}{Costs.Instance.GetFacilityMaintenanceCosts()}");
ReportBuilder.AppendLine($"Launch Costs: {Utilities.Instance.FundsSymbol}{Costs.Instance.GetLaunchCosts()}");
ReportBuilder.AppendLine($"Total Maintenance Costs: {Utilities.Instance.FundsSymbol}{Costs.Instance.GetTotalMaintenanceCosts()}");
ReportBuilder.AppendLine($"Mission Bonuses: {Utilities.Instance.FundsSymbol}{CrewManager.Instance.LastBonus}");
ReportBuilder.AppendLine($"Construction Department: {Utilities.Instance.FundsSymbol}{FacilityManager.Instance.GetAllocatedFunding()}");
ReportBuilder.AppendLine($"Research Department: {Utilities.Instance.FundsSymbol}{ResearchManager.Instance.GetAllocatedFunding()}");
double netBudget = Utilities.Instance.GetNetBudget("Budget");
ReportBuilder.AppendLine("Net Budget: " + Math.Max(0, netBudget));
ReportBuilder.AppendLine($"Net Budget: {Utilities.Instance.FundsSymbol}{Math.Max(0, netBudget)}");
if (netBudget > 0 && netBudget < Funding.Instance.Funds) ReportBuilder.AppendLine("We can't justify extending your funding");
// ReSharper disable once InvertIf
if (netBudget < 0)
{
ReportBuilder.AppendLine("The budget didn't fully cover your space programs costs.");
ReportBuilder.Append("A penalty of " + Math.Round(netBudget, 0) + " will be applied");
ReportBuilder.Append($"A penalty of {Utilities.Instance.FundsSymbol}{Math.Round(netBudget, 0)} will be applied");
}
return ReportBuilder.ToString();
}
Expand Down
3 changes: 3 additions & 0 deletions Bureaucracy/Budget/Costs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public double GetLaunchCosts()

public double GetWageCosts()
{
// if it's the initial cycle, return 0 (kerbal just been hired!)
if (Utilities.Instance.IsBootstrapBudgetCycle) return 0;

List<CrewMember> crew = CrewManager.Instance.Kerbals.Values.ToList();
double wage = 0;
for (int i = 0; i < crew.Count; i++)
Expand Down
Loading

0 comments on commit 2a0aad4

Please sign in to comment.