Skip to content

Commit

Permalink
Daily Progress on Construction/Research
Browse files Browse the repository at this point in the history
  • Loading branch information
severedsolo committed Jan 26, 2020
1 parent 326e3d9 commit 5068908
Show file tree
Hide file tree
Showing 22 changed files with 227 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .idea/.idea.Bureaucracy/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

172 changes: 104 additions & 68 deletions .idea/.idea.Bureaucracy/.idea/workspace.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Bureaucracy/Budget/BudgetEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using System;
using System.Linq;
using UnityEngine;

namespace Bureaucracy
Expand All @@ -14,6 +15,7 @@ public BudgetEvent(double budgetTime, BudgetManager manager, bool newKacAlarm)
Name = "Next Budget";
ParentManager = manager;
if(newKacAlarm) Utilities.Instance.NewKacAlarm("Next Budget", CompletionTime);
StopTimewarpOnCompletion = true;
AddTimer();
}

Expand Down Expand Up @@ -42,6 +44,11 @@ public override void OnEventCompleted()
InternalListeners.OnBudgetAwarded.Fire(funding, facilityDebt);
Costs.Instance.ResetLaunchCosts();
repDecay.ApplyRepDecay(Bureaucracy.Instance.settings.RepDecayPercent);
for (int i = 0; i < Bureaucracy.Instance.registeredManagers.Count; i++)
{
Manager m = Bureaucracy.Instance.registeredManagers.ElementAt(i);
m.ThisMonthsBudget = Utilities.Instance.GetNetBudget(m.Name);
}
InformParent();
}

Expand Down
7 changes: 7 additions & 0 deletions Bureaucracy/Bureaucracy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ public class Bureaucracy : MonoBehaviour
public SettingsClass settings;
public static Bureaucracy Instance;
public List<Manager> registeredManagers = new List<Manager>();
public bool existingSave;
public ManagerProgressEvent progressEvent;
public double lastProgressUpdate = 0;

private void Awake()
{
//Mod starts here.
settings = new SettingsClass();
RegisterBureaucracyManagers();
Instance = this;
lastProgressUpdate = Planetarium.GetUniversalTime();
Debug.Log("[Bureaucracy]: Awake");
}

Expand Down Expand Up @@ -96,6 +100,8 @@ public void OnLoad(ConfigNode node)
CrewManager.Instance.OnLoad(node);
RandomEventLoader.Instance.OnLoad(node);
UiController.Instance.OnLoad(node);
node.TryGetValue("existingSave", ref existingSave);
if(progressEvent == null) progressEvent = new ManagerProgressEvent();
Debug.Log("[Bureaucracy]: OnLoad Complete");
}

Expand All @@ -110,6 +116,7 @@ public void OnSave(ConfigNode node)
CrewManager.Instance.OnSave(node);
RandomEventLoader.Instance.OnSave(node);
UiController.Instance.OnSave(node);
node.SetValue("existingSave", existingSave, true);
Debug.Log("[Bureaucracy]: OnSave Complete");
}

Expand Down
2 changes: 1 addition & 1 deletion Bureaucracy/Bureaucracy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
<Compile Include="BureaucracyEvent.cs" />
<Compile Include="KACWrapper.cs" />
<Compile Include="Manager.cs" />
<Compile Include="ManagerProgressEvent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RandomEvents\CurrencyEvent.cs" />
<Compile Include="RandomEvents\ExplosionEvent.cs" />
<Compile Include="RandomEvents\FireEvent.cs" />
<Compile Include="RandomEvents\QAEvent.cs" />
<Compile Include="RandomEvents\RandomEventBase.cs" />
Expand Down
1 change: 1 addition & 0 deletions Bureaucracy/BureaucracyEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class BureaucracyEvent
protected Manager ParentManager;
// ReSharper disable once NotAccessedField.Global
protected string Name = "Uninitialised Event";
public bool StopTimewarpOnCompletion = false;

protected void AddTimer()
{
Expand Down
5 changes: 3 additions & 2 deletions Bureaucracy/Facilities/BureaucracyFacility.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using UnityEngine;
using Upgradeables;

Expand All @@ -16,7 +17,7 @@ public class BureaucracyFacility
public bool IsPriority;
public int LaunchesThisMonth;

public int Level => level;
[UsedImplicitly] public int Level => level;

public bool IsClosed => isClosed;

Expand Down Expand Up @@ -216,7 +217,7 @@ public bool CanBeDestroyed()
return level > 2;
}

private List<DestructibleBuilding> Destructibles()
private IEnumerable<DestructibleBuilding> Destructibles()
{
foreach (KeyValuePair<string, ScenarioDestructibles.ProtoDestructible> kvp in ScenarioDestructibles.protoDestructibles)
{
Expand Down
18 changes: 12 additions & 6 deletions Bureaucracy/Facilities/FacilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class FacilityManager : Manager
public readonly List<BureaucracyFacility> Facilities = new List<BureaucracyFacility>();
public static FacilityManager Instance;
[UsedImplicitly] private PopupDialog warningDialog;
public float FireChance = 0.0f;
public float FireChance;
public float CostMultiplier = 1.0f;

public FacilityManager()
{
InternalListeners.OnBudgetAboutToFire.Add(RunFacilityBudget);
InternalListeners.OnBudgetAboutToFire.Add(OnBudgetAboutToFire);
SpaceCenterFacility[] spaceCentreFacilities = (SpaceCenterFacility[]) Enum.GetValues(typeof(SpaceCenterFacility));
for (int i = 0; i < spaceCentreFacilities.Length; i++)
{
Expand All @@ -30,9 +30,14 @@ public FacilityManager()
Debug.Log("[Bureaucracy]: Facility Manager Ready");
}

private void OnBudgetAboutToFire()
{
ReopenAllFacilities();
}

public override void UnregisterEvents()
{
InternalListeners.OnBudgetAboutToFire.Remove(RunFacilityBudget);
InternalListeners.OnBudgetAboutToFire.Remove(OnBudgetAboutToFire);
}

public override double GetAllocatedFunding()
Expand All @@ -45,10 +50,9 @@ protected override Report GetReport()
return new FacilityReport();
}

private void RunFacilityBudget()
public override void ProgressTask()
{
ReopenAllFacilities();
double facilityBudget = Utilities.Instance.GetNetBudget(Name);
double facilityBudget = Utilities.Instance.ConvertMonthlyBudgetToDaily(ThisMonthsBudget) * ProgressTime();
//Find the priority build first
for (int i = 0; i < Facilities.Count; i++)
{
Expand Down Expand Up @@ -77,6 +81,7 @@ public void OnLoad(ConfigNode cn)
ConfigNode managerNode = cn.GetNode("FACILITY_MANAGER");
if (managerNode == null) return;
int.TryParse(managerNode.GetValue("FundingAllocation"), out int funding);
double.TryParse(managerNode.GetValue("thisMonth"), out ThisMonthsBudget);
FundingAllocation = funding;
float.TryParse(managerNode.GetValue("CostMultiplier"), out CostMultiplier);
float.TryParse(managerNode.GetValue("FireChance"), out FireChance);
Expand All @@ -100,6 +105,7 @@ public void OnSave(ConfigNode cn)
managerNode.SetValue("FundingAllocation", FundingAllocation, true);
managerNode.SetValue("CostMultiplier", CostMultiplier, true);
managerNode.SetValue("FireChance", FireChance, true);
managerNode.SetValue("thisMonth", ThisMonthsBudget, true);
for (int i = 0; i < Facilities.Count; i++)
{
BureaucracyFacility bf = Facilities.ElementAt(i);
Expand Down
5 changes: 3 additions & 2 deletions Bureaucracy/Facilities/FacilityUpgradeEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using JetBrains.Annotations;
using UnityEngine;
using Upgradeables;

Expand All @@ -14,7 +14,7 @@ public class FacilityUpgradeEvent : BureaucracyEvent
private int levelRequested = 1;
private float originalCost;
private readonly BureaucracyFacility parentFacility;
private PopupDialog kctWarning;
[UsedImplicitly] private PopupDialog kctWarning;
public bool UpgradeHeld;

public FacilityUpgradeEvent(string id, BureaucracyFacility passingFacility)
Expand Down Expand Up @@ -43,6 +43,7 @@ public float ProgressUpgrade(double funding)
if (remainingFunding > 0)
{
OnEventCompleted();
ScreenMessages.PostScreenMessage(parentFacility.Name + ": Upgrade Complete");
return (float)remainingFunding;
}
remainingInvestment -= (float)funding;
Expand Down
1 change: 1 addition & 0 deletions Bureaucracy/GameEvents/ExternalListeners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void AllocateCrewBonuses(ProtoCrewMember crewMember)

private void OnScienceReceived(float science, ScienceSubject subject, ProtoVessel protoVessel, bool reverseEngineered)
{
if (!SettingsClass.Instance.HandleScience) return;
ResearchManager.Instance.NewScienceReceived(science, subject);
}

Expand Down
11 changes: 11 additions & 0 deletions Bureaucracy/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ public class Manager
//obviously you change these in the constructor.
public string Name = "Blank Manager";
public float FundingAllocation = 0.3f;
public double ThisMonthsBudget = 0;

protected double ProgressTime()
{
//How long since the last update?
double timeElapsed = Planetarium.GetUniversalTime() - Bureaucracy.Instance.lastProgressUpdate;
//convert that into days
timeElapsed /= FlightGlobals.GetHomeBody().solarDayLength;
return timeElapsed;
}
public void MakeReport()
{
Report r = GetReport();
Expand All @@ -20,6 +29,8 @@ public void MakeReport()

public virtual void UnregisterEvents() { Debug.Log("[Bureaucracy]: No Events to Unregister for "+Name); }

public virtual void ProgressTask() { }


[UsedImplicitly]
public virtual double GetAllocatedFunding() { return 0; }
Expand Down
24 changes: 24 additions & 0 deletions Bureaucracy/ManagerProgressEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Linq;

namespace Bureaucracy
{
public class ManagerProgressEvent : BureaucracyEvent
{
public ManagerProgressEvent()
{
CompletionTime = Planetarium.GetUniversalTime() + FlightGlobals.GetHomeBody().solarDayLength;
AddTimer();
}

public override void OnEventCompleted()
{
for (int i = 0; i < Bureaucracy.Instance.registeredManagers.Count; i++)
{
Manager m = Bureaucracy.Instance.registeredManagers.ElementAt(i);
m.ProgressTask();
}
Bureaucracy.Instance.progressEvent = new ManagerProgressEvent();
Bureaucracy.Instance.lastProgressUpdate = Planetarium.GetUniversalTime();
}
}
}
21 changes: 0 additions & 21 deletions Bureaucracy/RandomEvents/ExplosionEvent.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Bureaucracy/RandomEvents/FireEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class FireEvent : RandomEventBase
public FireEvent()
{
facilityToBurn = FacilityManager.Instance.Facilities.ElementAt(Utilities.Instance.Randomise.Next(0, FacilityManager.Instance.Facilities.Count));
title = "Fire!";
body = "Recent cutbacks have resulted in poor safety protocols at " + facilityToBurn.Name + ". As a result, a small fire has gotten out of control";
acceptString = "Oh dear. (" + facilityToBurn.Name + " is destroyed)";
Title = "Fire!";
Body = "Recent cutbacks have resulted in poor safety protocols at " + facilityToBurn.Name + ". As a result, a small fire has gotten out of control";
AcceptString = "Oh dear. (" + facilityToBurn.Name + " is destroyed)";
CanBeDeclined = false;
}
public override bool EventCanFire()
Expand Down
40 changes: 20 additions & 20 deletions Bureaucracy/RandomEvents/RandomEventBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public abstract class RandomEventBase
{
[UsedImplicitly] private PopupDialog eventDialog;
public string Name;
protected string title;
protected string body;
protected string acceptString;
protected string DeclineString;
protected string Title;
protected string Body;
protected string AcceptString;
private string declineString;
protected bool CanBeDeclined;
protected float EventEffect;
protected string KerbalName;
Expand All @@ -23,10 +23,10 @@ public abstract class RandomEventBase
protected void LoadConfig(ConfigNode cn)
{
if(!cn.TryGetValue("Name", ref Name)) throw new ArgumentException("Event is missing a Name!");
if(!cn.TryGetValue("Title", ref title)) throw new ArgumentException(Name+" has no title!");
if(!cn.TryGetValue("Body", ref body)) throw new ArgumentException(Name+" has no body!");
if(!cn.TryGetValue("AcceptButtonText", ref acceptString)) throw new ArgumentException(Name + " missing AcceptButtonText");
if(cn.TryGetValue("canBeDeclined", ref CanBeDeclined) && !cn.TryGetValue("DeclineButtonText", ref DeclineString)) throw new ArgumentException(Name + "Can be declined but DeclineButtonText not set");
if(!cn.TryGetValue("Title", ref Title)) throw new ArgumentException(Name+" has no title!");
if(!cn.TryGetValue("Body", ref Body)) throw new ArgumentException(Name+" has no body!");
if(!cn.TryGetValue("AcceptButtonText", ref AcceptString)) throw new ArgumentException(Name + " missing AcceptButtonText");
if(cn.TryGetValue("canBeDeclined", ref CanBeDeclined) && !cn.TryGetValue("DeclineButtonText", ref declineString)) throw new ArgumentException(Name + "Can be declined but DeclineButtonText not set");
if(!cn.TryGetValue("Effect", ref EventEffect)) throw new ArgumentException(Name+" has no Effect defined in cfg");
ReplaceStrings();
}
Expand All @@ -37,14 +37,14 @@ private void ReplaceStrings()
KerbalName = Utilities.Instance.GetARandomKerbal();
Name = Name.Replace("<kerbal>", KerbalName);
Name = Name.Replace("<body>", bodyName);
title = title.Replace("<kerbal>", KerbalName);
title = title.Replace("<body>", bodyName);
body = body.Replace("<kerbal>", KerbalName);
body = body.Replace("<body>", bodyName);
acceptString = acceptString.Replace("<kerbal>", KerbalName);
acceptString = acceptString.Replace("<body>", bodyName);
if (DeclineString != null) DeclineString = DeclineString.Replace("<kerbal>", KerbalName);
if (DeclineString != null) DeclineString = DeclineString.Replace("<body>", bodyName);
Title = Title.Replace("<kerbal>", KerbalName);
Title = Title.Replace("<body>", bodyName);
Body = Body.Replace("<kerbal>", KerbalName);
Body = Body.Replace("<body>", bodyName);
AcceptString = AcceptString.Replace("<kerbal>", KerbalName);
AcceptString = AcceptString.Replace("<body>", bodyName);
if (declineString != null) declineString = declineString.Replace("<kerbal>", KerbalName);
if (declineString != null) declineString = declineString.Replace("<body>", bodyName);
}

protected abstract void OnEventAccepted();
Expand All @@ -56,12 +56,12 @@ public void OnEventFire()
List<DialogGUIBase> dialogElements = new List<DialogGUIBase>();
List<DialogGUIBase> innerElements = new List<DialogGUIBase>();
innerElements.Add(new DialogGUISpace(10));
innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel(body)));
innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel(Body)));
DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray());
dialogElements.Add(new DialogGUIScrollList(-Vector2.one, false, false, vertical));
dialogElements.Add(new DialogGUIButton(acceptString, OnEventAccepted));
if(CanBeDeclined) dialogElements.Add(new DialogGUIButton(DeclineString, OnEventDeclined));
eventDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("EventDialog", "", title, UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 300, 200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
dialogElements.Add(new DialogGUIButton(AcceptString, OnEventAccepted));
if(CanBeDeclined) dialogElements.Add(new DialogGUIButton(declineString, OnEventDeclined));
eventDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("EventDialog", "", Title, UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 300, 200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
}

private DialogGUIBase[] PaddedLabel(string stringToPad)
Expand Down
6 changes: 3 additions & 3 deletions Bureaucracy/RandomEvents/WageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Bureaucracy
{
public class WageEvent : RandomEventBase
{
private CrewMember crewMember;
private readonly CrewMember crewMember;

public WageEvent(ConfigNode eventNode)
{
CrewMember c = FindCrew();
if (c == null) return;
crewMember = c;
LoadConfig(eventNode);
body = body.Replace("<crew>", c.Name);
acceptString = acceptString.Replace("<crew>", c.Name);
Body = Body.Replace("<crew>", c.Name);
AcceptString = AcceptString.Replace("<crew>", c.Name);
}

private CrewMember FindCrew()
Expand Down
Loading

0 comments on commit 5068908

Please sign in to comment.