diff --git a/.idea/.idea.Bureaucracy/.idea/contentModel.xml b/.idea/.idea.Bureaucracy/.idea/contentModel.xml index 79b44b0..04470d4 100644 --- a/.idea/.idea.Bureaucracy/.idea/contentModel.xml +++ b/.idea/.idea.Bureaucracy/.idea/contentModel.xml @@ -43,10 +43,12 @@ + + diff --git a/.idea/.idea.Bureaucracy/.idea/workspace.xml b/.idea/.idea.Bureaucracy/.idea/workspace.xml index 1e5ceed..de2eb50 100644 --- a/.idea/.idea.Bureaucracy/.idea/workspace.xml +++ b/.idea/.idea.Bureaucracy/.idea/workspace.xml @@ -2,7 +2,18 @@ + + + + + + + + + + + + + + @@ -27,6 +41,7 @@ + @@ -39,6 +54,7 @@ + @@ -73,7 +89,6 @@ @@ -239,6 +255,8 @@ + + @@ -282,90 +300,91 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - + + @@ -1578,21 +1597,24 @@ + + + + - - - - + + + diff --git a/Bureaucracy/Budget/Costs.cs b/Bureaucracy/Budget/Costs.cs index e8f40b2..8f0f43a 100644 --- a/Bureaucracy/Budget/Costs.cs +++ b/Bureaucracy/Budget/Costs.cs @@ -80,7 +80,7 @@ public double GetFacilityMaintenanceCosts() { BureaucracyFacility bf = FacilityManager.Instance.Facilities.ElementAt(i); if(bf.IsClosed) continue; - d += bf.MaintenanceCost*Bureaucracy.Instance.qaModifier; + d += bf.MaintenanceCost*FacilityManager.Instance.CostMultiplier; } return d; } diff --git a/Bureaucracy/Bureaucracy.cs b/Bureaucracy/Bureaucracy.cs index cff4c9d..168a5bf 100644 --- a/Bureaucracy/Bureaucracy.cs +++ b/Bureaucracy/Bureaucracy.cs @@ -24,7 +24,6 @@ public class Bureaucracy : MonoBehaviour { public SettingsClass settings; public static Bureaucracy Instance; - public float qaModifier = 1.0f; public List registeredManagers = new List(); private void Awake() @@ -90,7 +89,6 @@ public void OnLoad(ConfigNode node) { //ScenarioModule OnLoad event redirects here, each class handles it's own saving/loading (for better encapsulation). Debug.Log("[Bureaucracy]: OnLoad"); - if(float.TryParse(node.GetValue("QAModifier"), out float f))qaModifier = f; SettingsClass.Instance.InGameLoad(); BudgetManager.Instance.OnLoad(node); FacilityManager.Instance.OnLoad(node); @@ -105,7 +103,6 @@ public void OnSave(ConfigNode node) { //ScenarioModule OnLoad event redirects here, each class handles it's own saving/loading (for better encapsulation). Debug.Log("[Bureaucracy]: OnSave"); - node.SetValue("QAModifier", qaModifier, true); SettingsClass.Instance.InGameSave(); BudgetManager.Instance.OnSave(node); FacilityManager.Instance.OnSave(node); diff --git a/Bureaucracy/Bureaucracy.csproj b/Bureaucracy/Bureaucracy.csproj index 46a780a..6eba5fe 100644 --- a/Bureaucracy/Bureaucracy.csproj +++ b/Bureaucracy/Bureaucracy.csproj @@ -91,10 +91,12 @@ + + diff --git a/Bureaucracy/Crew/CrewMember.cs b/Bureaucracy/Crew/CrewMember.cs index 4a9d387..8a76cef 100644 --- a/Bureaucracy/Crew/CrewMember.cs +++ b/Bureaucracy/Crew/CrewMember.cs @@ -11,6 +11,7 @@ public class CrewMember public readonly int MaxStrikes; public readonly List UnhappinessEvents = new List(); public bool Unhappy; + public float WageModifier = 1.0f; public string Name { get; private set; } @@ -21,7 +22,7 @@ public double Wage float experienceLevel = crewRef.experienceLevel; // ReSharper disable once CompareOfFloatsByEqualityOperator if (experienceLevel == 0) experienceLevel = 0.5f; - return experienceLevel * SettingsClass.Instance.KerbalBaseWage; + return experienceLevel * SettingsClass.Instance.KerbalBaseWage*WageModifier; } } diff --git a/Bureaucracy/Facilities/BureaucracyFacility.cs b/Bureaucracy/Facilities/BureaucracyFacility.cs index a0db938..c1af24f 100644 --- a/Bureaucracy/Facilities/BureaucracyFacility.cs +++ b/Bureaucracy/Facilities/BureaucracyFacility.cs @@ -8,7 +8,7 @@ namespace Bureaucracy { public class BureaucracyFacility { - private int level = 1; + private int level; private readonly int upkeepCost; private bool recentlyUpgraded; public FacilityUpgradeEvent Upgrade; @@ -16,6 +16,8 @@ public class BureaucracyFacility public bool IsPriority; public int LaunchesThisMonth; + public int Level => level; + public bool IsClosed => isClosed; private bool CanBeClosed { get; set; } @@ -45,11 +47,11 @@ public BureaucracyFacility(SpaceCenterFacility spf) { Name = SetName(spf); upkeepCost = SetCosts(); - level = GetUpgradeableLevel(); + level = GetFacilityLevel(); Debug.Log("[Bureaucracy]: Setup Facility " + Name); } - private int GetUpgradeableLevel() + private int GetFacilityLevel() { foreach (KeyValuePair config in ScenarioUpgradeableFacilities.protoUpgradeables) { @@ -192,19 +194,38 @@ public void OnUpgradeCompleted() public bool IsDestroyed() { - foreach (KeyValuePair kvp in ScenarioDestructibles.protoDestructibles) + foreach (DestructibleBuilding building in Destructibles()) { - if (!kvp.Key.Contains(Name)) continue; - List buildingsToDestroy = kvp.Value.dBuildingRefs; - foreach (DestructibleBuilding building in buildingsToDestroy) - { - if (building.IsDestroyed) return true; - } + if (building.IsDestroyed) return true; } return false; } + public void DestroyBuilding() + { + if (!CanBeDestroyed()) return; + foreach (DestructibleBuilding building in Destructibles()) + { + building.Demolish(); + } + } + + public bool CanBeDestroyed() + { + return level > 2; + } + + private List Destructibles() + { + foreach (KeyValuePair kvp in ScenarioDestructibles.protoDestructibles) + { + if (!kvp.Key.Contains(Name)) continue; + return kvp.Value.dBuildingRefs; + } + return null; + } + public void CancelUpgrade() { Upgrade = null; diff --git a/Bureaucracy/Facilities/FacilityManager.cs b/Bureaucracy/Facilities/FacilityManager.cs index b2c5792..cbb7b2f 100644 --- a/Bureaucracy/Facilities/FacilityManager.cs +++ b/Bureaucracy/Facilities/FacilityManager.cs @@ -12,6 +12,8 @@ public class FacilityManager : Manager public readonly List Facilities = new List(); public static FacilityManager Instance; [UsedImplicitly] private PopupDialog warningDialog; + public float FireChance = 0.0f; + public float CostMultiplier = 1.0f; public FacilityManager() { @@ -76,6 +78,9 @@ public void OnLoad(ConfigNode cn) if (managerNode == null) return; int.TryParse(managerNode.GetValue("FundingAllocation"), out int funding); FundingAllocation = funding; + float.TryParse(managerNode.GetValue("CostMultiplier"), out CostMultiplier); + float.TryParse(managerNode.GetValue("FireChance"), out FireChance); + if (CostMultiplier < 1.0f) CostMultiplier = 1.0f; ConfigNode[] facilityNodes = managerNode.GetNodes("FACILITY"); for (int i = 0; i < Facilities.Count; i++) { @@ -93,6 +98,8 @@ public void OnSave(ConfigNode cn) Debug.Log("[Bureaucracy]: FacilityManager OnSave"); ConfigNode managerNode = new ConfigNode("FACILITY_MANAGER"); managerNode.SetValue("FundingAllocation", FundingAllocation, true); + managerNode.SetValue("CostMultiplier", CostMultiplier, true); + managerNode.SetValue("FireChance", FireChance, true); for (int i = 0; i < Facilities.Count; i++) { BureaucracyFacility bf = Facilities.ElementAt(i); diff --git a/Bureaucracy/GameEvents/ExternalListeners.cs b/Bureaucracy/GameEvents/ExternalListeners.cs index f9d8a94..fc21e95 100644 --- a/Bureaucracy/GameEvents/ExternalListeners.cs +++ b/Bureaucracy/GameEvents/ExternalListeners.cs @@ -102,10 +102,6 @@ private void OnContractOffered(Contract contract) private void AddLaunch(ShipConstruct ship) { - if (Utilities.Instance.Randomise.NextDouble() > Bureaucracy.Instance.qaModifier) - { - ExplosionEvent unused = new ExplosionEvent(); - } Costs.Instance.AddLaunch(ship); string editor = ship.shipFacility == EditorFacility.VAB ? "VehicleAssemblyBuilding" : "SpaceplaneHangar"; BureaucracyFacility bf = FacilityManager.Instance.GetFacilityByName(editor); diff --git a/Bureaucracy/RandomEvents/FireEvent.cs b/Bureaucracy/RandomEvents/FireEvent.cs new file mode 100644 index 0000000..fcc21bf --- /dev/null +++ b/Bureaucracy/RandomEvents/FireEvent.cs @@ -0,0 +1,32 @@ +using System.Linq; + +namespace Bureaucracy +{ + public class FireEvent : RandomEventBase + { + private readonly BureaucracyFacility facilityToBurn; + 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)"; + CanBeDeclined = false; + } + public override bool EventCanFire() + { + if (Utilities.Instance.Randomise.NextDouble() > FacilityManager.Instance.FireChance) return false; + return facilityToBurn.CanBeDestroyed(); + } + + protected override void OnEventAccepted() + { + facilityToBurn.DestroyBuilding(); + } + + protected override void OnEventDeclined() + { + + } + } +} \ No newline at end of file diff --git a/Bureaucracy/RandomEvents/QAEvent.cs b/Bureaucracy/RandomEvents/QAEvent.cs index 592d133..cdc34b5 100644 --- a/Bureaucracy/RandomEvents/QAEvent.cs +++ b/Bureaucracy/RandomEvents/QAEvent.cs @@ -5,24 +5,22 @@ public class QaEvent : RandomEventBase public QaEvent(ConfigNode eventNode) { LoadConfig(eventNode); - CanBeDeclined = true; - DeclineString = "No thanks"; } public override bool EventCanFire() { - if (Bureaucracy.Instance.qaModifier < 0.8f && EventEffect < 0) return false; - if (Bureaucracy.Instance.qaModifier >= 1.0f && EventEffect > 0) return false; + if (EventEffect < 0.0f && FacilityManager.Instance.FireChance <= 0.0f) return false; return true; } protected override void OnEventAccepted() { - Bureaucracy.Instance.qaModifier += EventEffect; + FacilityManager.Instance.CostMultiplier += EventEffect; } protected override void OnEventDeclined() { + FacilityManager.Instance.FireChance += EventEffect; } } } \ No newline at end of file diff --git a/Bureaucracy/RandomEvents/RandomEventBase.cs b/Bureaucracy/RandomEvents/RandomEventBase.cs index 64b7905..8bf78ff 100644 --- a/Bureaucracy/RandomEvents/RandomEventBase.cs +++ b/Bureaucracy/RandomEvents/RandomEventBase.cs @@ -9,9 +9,9 @@ public abstract class RandomEventBase { [UsedImplicitly] private PopupDialog eventDialog; public string Name; - private string title; - private string body; - private string acceptString; + protected string title; + protected string body; + protected string acceptString; protected string DeclineString; protected bool CanBeDeclined; protected float EventEffect; diff --git a/Bureaucracy/RandomEvents/RandomEventLoader.cs b/Bureaucracy/RandomEvents/RandomEventLoader.cs index d912475..27e32cc 100644 --- a/Bureaucracy/RandomEvents/RandomEventLoader.cs +++ b/Bureaucracy/RandomEvents/RandomEventLoader.cs @@ -34,6 +34,7 @@ private void RollEvent() private void LoadEvents() { ConfigNode[] eventCache = GameDatabase.Instance.GetConfigNodes("BUREAUCRACY_EVENT"); + loadedEvents.Add(new FireEvent()); for (int i = 0; i < eventCache.Length; i++) { ConfigNode eventNode = eventCache.ElementAt(i); @@ -54,6 +55,10 @@ private void LoadEvents() re = new QaEvent(eventNode); loadedEvents.Add(re); break; + case "Wage": + re = new WageEvent(eventNode); + loadedEvents.Add(re); + break; default: throw new ArgumentException("[Bureaucracy]: Event "+eventNode.GetValue("Name")+" is not a valid type!"); } diff --git a/Bureaucracy/RandomEvents/WageEvent.cs b/Bureaucracy/RandomEvents/WageEvent.cs new file mode 100644 index 0000000..964998e --- /dev/null +++ b/Bureaucracy/RandomEvents/WageEvent.cs @@ -0,0 +1,44 @@ +using System.Linq; + +namespace Bureaucracy +{ + public class WageEvent : RandomEventBase + { + private CrewMember crewMember; + + public WageEvent(ConfigNode eventNode) + { + CrewMember c = FindCrew(); + if (c == null) return; + crewMember = c; + LoadConfig(eventNode); + body = body.Replace("", c.Name); + acceptString = acceptString.Replace("", c.Name); + } + + private CrewMember FindCrew() + { + if (CrewManager.Instance.Kerbals.Count == 0) return null; + int i = Utilities.Instance.Randomise.Next(0, CrewManager.Instance.Kerbals.Count); + CrewMember c = CrewManager.Instance.Kerbals.ElementAt(i).Value; + return c; + } + + public override bool EventCanFire() + { + if (crewMember.CrewReference().rosterStatus != ProtoCrewMember.RosterStatus.Available) return false; + if (crewMember.WageModifier <= 1.0f && EventEffect < 0.0f) return false; + return true; + } + + protected override void OnEventAccepted() + { + crewMember.WageModifier += EventEffect; + } + + protected override void OnEventDeclined() + { + + } + } +} \ No newline at end of file diff --git a/Bureaucracy/UI/UIController.cs b/Bureaucracy/UI/UIController.cs index 12ba652..1e1e3fb 100644 --- a/Bureaucracy/UI/UIController.cs +++ b/Bureaucracy/UI/UIController.cs @@ -231,7 +231,11 @@ private PopupDialog DrawFacilityUi() if (upgradeCount == 0) innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("No Facility Upgrades in progress", false))); DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray()); dialogElements.Add(new DialogGUIScrollList(new Vector2(300, 300), false, false, vertical)); - dialogElements.Add(new DialogGUILabel("Processing: $"+investmentNeeded)); + DialogGUIBase[] horizontal = new DialogGUIBase[3]; + horizontal[0] = new DialogGUILabel("Total Investment Needed: $"+investmentNeeded); + horizontal[1] = new DialogGUILabel("|"); + horizontal[2] = new DialogGUILabel("Chance of Fire: "+Math.Round(FacilityManager.Instance.FireChance*100, 0)+"%"); + dialogElements.Add(new DialogGUIHorizontalLayout(horizontal)); dialogElements.Add(GetBoxes("facility")); return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("FacilitiesDialog", "", "Bureaucracy: Facilities", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 320, 350), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")); }