public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl) { if (KCT_GUI.PrimarilyDisabled) { return; } if (!(allowedToUpgrade || KCT_GameStates.settings.InstantKSCUpgrades)) { KCT_UpgradingBuilding upgrading = new KCT_UpgradingBuilding(facility, lvl, lvl - 1, facility.id.Split('/').Last()); if (!upgrading.AlreadyInProgress()) { upgrading.Downgrade(); double cost = facility.GetUpgradeCost(); upgrading.SetBP(cost); upgrading.cost = cost; KCT_GameStates.ActiveKSC.KSCTech.Add(upgrading); ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " upgrade requested to lvl " + lvl + " for " + cost + " funds, resulting in a BP of " + upgrading.BP); } else if (lvl != upgrading.currentLevel) { // KCT_UpgradingBuilding listBuilding = upgrading.KSC.KSCTech.Find(b => b.id == upgrading.id); listBuilding.Downgrade(); KCT_Utilities.AddFunds(listBuilding.cost, TransactionReasons.None); ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " tried to upgrade to lvl " + lvl + " but already in list!"); } } else { KCTDebug.Log("Facility " + facility.id + " upgraded to lvl " + lvl); allowedToUpgrade = false; foreach (KCT_KSC ksc in KCT_GameStates.KSCs) { ksc.RecalculateBuildRates(); ksc.RecalculateUpgradedBuildRates(); } foreach (KCT_TechItem tech in KCT_GameStates.TechList) { tech.UpdateBuildRate(); } } /* if (lvl <= lastLvl) * { * lastLvl = -1; * return; * } * facility.SetLevel(lvl - 1); * lastLvl = lvl; * double cost = facility.GetUpgradeCost(); * double BP = Math.Sqrt(cost) * 2000 * KCT_GameStates.timeSettings.OverallMultiplier;*/ // KCTDebug.Log(facility.GetNormLevel()); }
internal void handleUpgrade() { int oldLevel = getMember <int>("level"); KCTDebug.Log($"Upgrading from level {oldLevel}"); string facilityID = GetFacilityID(); KCT_UpgradingBuilding upgrading = new KCT_UpgradingBuilding(facilityID, oldLevel + 1, oldLevel, facilityID.Split('/').Last()); upgrading.isLaunchpad = facilityID.ToLower().Contains("launchpad"); if (upgrading.isLaunchpad) { upgrading.launchpadID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID; if (upgrading.launchpadID > 0) { upgrading.commonName += KCT_GameStates.ActiveKSC.ActiveLPInstance.name; } } if (!upgrading.AlreadyInProgress()) { float cost = getMember <float>("upgradeCost"); if (Funding.CanAfford(cost)) { Funding.Instance.AddFunds(-cost, TransactionReasons.Structures); KCT_GameStates.ActiveKSC.KSCTech.Add(upgrading); upgrading.SetBP(cost); upgrading.cost = cost; ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log($"Facility {facilityID} upgrade requested to lvl {oldLevel + 1} for {cost} funds, resulting in a BP of {upgrading.BP}"); } else { KCTDebug.Log("Couldn't afford to upgrade."); ScreenMessages.PostScreenMessage("Not enough funds to upgrade facility!", 4.0f, ScreenMessageStyle.UPPER_CENTER); } } else if (oldLevel + 1 != upgrading.currentLevel) { ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log($"Facility {facilityID} tried to upgrade to lvl {oldLevel+1} but already in list!"); } _menu.Dismiss(KSCFacilityContextMenu.DismissAction.None); }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); this.KSCName = node.GetValue("KSCName"); ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.SPHWarehouse.Add(blv); } /* tmp = node.GetNode("TechList"); foreach (ConfigNode techNode in tmp.GetNodes("Tech")) { KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem(); ConfigNode.LoadObjectFromConfig(techStorageItem, techNode); KCT_TechItem techItem = techStorageItem.ToTechItem(); techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode")); this.TechList.Add(techItem); }*/ tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); ConfigNode.LoadObjectFromConfig(tempUP, upBuild); KSCTech.Add(tempUP); } } return this; }
public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl) { if (KCT_GUI.PrimarilyDisabled) { bool isLaunchpad = facility.id.ToLower().Contains("launchpad"); if (!isLaunchpad) { return; } //is a launch pad KCT_GameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl); } if (!(allowedToUpgrade || !KCT_PresetManager.Instance.ActivePreset.generalSettings.KSCUpgradeTimes)) { KCT_UpgradingBuilding upgrading = new KCT_UpgradingBuilding(facility, lvl, lvl - 1, facility.id.Split('/').Last()); upgrading.isLaunchpad = facility.id.ToLower().Contains("launchpad"); if (upgrading.isLaunchpad) { upgrading.launchpadID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID; if (upgrading.launchpadID > 0) { upgrading.commonName += KCT_GameStates.ActiveKSC.ActiveLPInstance.name;//" " + (upgrading.launchpadID+1); } } if (!upgrading.AlreadyInProgress()) { KCT_GameStates.ActiveKSC.KSCTech.Add(upgrading); upgrading.Downgrade(); double cost = facility.GetUpgradeCost(); upgrading.SetBP(cost); upgrading.cost = cost; ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " upgrade requested to lvl " + lvl + " for " + cost + " funds, resulting in a BP of " + upgrading.BP); } else if (lvl != upgrading.currentLevel) { // KCT_UpgradingBuilding listBuilding = upgrading.KSC.KSCTech.Find(b => b.id == upgrading.id); if (upgrading.isLaunchpad) { listBuilding = upgrading.KSC.KSCTech.Find(b => b.isLaunchpad && b.launchpadID == upgrading.launchpadID); } listBuilding.Downgrade(); KCT_Utilities.AddFunds(listBuilding.cost, TransactionReasons.None); ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " tried to upgrade to lvl " + lvl + " but already in list!"); } } else { KCTDebug.Log("Facility " + facility.id + " upgraded to lvl " + lvl); if (facility.id.ToLower().Contains("launchpad")) { if (!allowedToUpgrade) { KCT_GameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl); //also repairs the launchpad } else { KCT_GameStates.ActiveKSC.ActiveLPInstance.level = lvl; } } allowedToUpgrade = false; foreach (KCT_KSC ksc in KCT_GameStates.KSCs) { ksc.RecalculateBuildRates(); ksc.RecalculateUpgradedBuildRates(); } foreach (KCT_TechItem tech in KCT_GameStates.TechList) { tech.UpdateBuildRate(KCT_GameStates.TechList.IndexOf(tech)); } } /* if (lvl <= lastLvl) * { * lastLvl = -1; * return; * } * facility.SetLevel(lvl - 1); * lastLvl = lvl; * double cost = facility.GetUpgradeCost(); * double BP = Math.Sqrt(cost) * 2000 * KCT_GameStates.timeSettings.OverallMultiplier;*/ // KCTDebug.Log(facility.GetNormLevel()); }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); VABRates.Clear(); SPHRates.Clear(); this.KSCName = node.GetValue("KSCName"); if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID)) { this.ActiveLaunchPadID = 0; } ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHWarehouse.Add(blv); } /* tmp = node.GetNode("TechList"); * foreach (ConfigNode techNode in tmp.GetNodes("Tech")) * { * KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem(); * ConfigNode.LoadObjectFromConfig(techStorageItem, techNode); * KCT_TechItem techItem = techStorageItem.ToTechItem(); * techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode")); * this.TechList.Add(techItem); * }*/ tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); ConfigNode.LoadObjectFromConfig(tempUP, upBuild); KSCTech.Add(tempUP); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad")) { KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0"); ConfigNode.LoadObjectFromConfig(tempLP, LP); tempLP.DestructionNode = LP.GetNode("DestructionState"); LaunchPads.Add(tempLP); } } if (node.HasNode("VABRateCache")) { foreach (string rate in node.GetNode("VABRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { VABRates.Add(r); } } } if (node.HasNode("SPHRateCache")) { foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { SPHRates.Add(r); } } } return(this); }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); this.KSCName = node.GetValue("KSCName"); ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); this.SPHWarehouse.Add(blv); } /* tmp = node.GetNode("TechList"); * foreach (ConfigNode techNode in tmp.GetNodes("Tech")) * { * KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem(); * ConfigNode.LoadObjectFromConfig(techStorageItem, techNode); * KCT_TechItem techItem = techStorageItem.ToTechItem(); * techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode")); * this.TechList.Add(techItem); * }*/ tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); ConfigNode.LoadObjectFromConfig(tempUP, upBuild); KSCTech.Add(tempUP); } } return(this); }
internal void processUpgrade() { int oldLevel = getMember <int>("level"); KCTDebug.Log($"Upgrading from level {oldLevel}"); string facilityID = GetFacilityID(); string gate = GetTechGate(facilityID, oldLevel + 1); Debug.Log("[KCTT] Gate for " + facilityID + "? " + gate); if (!string.IsNullOrEmpty(gate)) { if (ResearchAndDevelopment.GetTechnologyState(gate) != RDTech.State.Available) { PopupDialog.SpawnPopupDialog(new MultiOptionDialog("kctUpgradePadConfirm", "Can't upgrade this facility. Requires " + KerbalConstructionTimeData.techNameToTitle[gate] + ".", "Lack Tech to Upgrade", HighLogic.UISkin, new DialogGUIButton("Ok", stub)), false, HighLogic.UISkin); return; } } KCT_UpgradingBuilding upgrading = new KCT_UpgradingBuilding(facilityID, oldLevel + 1, oldLevel, facilityID.Split('/').Last()); upgrading.isLaunchpad = facilityID.ToLower().Contains("launchpad"); if (upgrading.isLaunchpad) { upgrading.launchpadID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID; if (upgrading.launchpadID > 0) { upgrading.commonName += KCT_GameStates.ActiveKSC.ActiveLPInstance.name; } } if (!upgrading.AlreadyInProgress()) { float cost = getMember <float>("upgradeCost"); if (Funding.CanAfford(cost)) { Funding.Instance.AddFunds(-cost, TransactionReasons.Structures); KCT_GameStates.ActiveKSC.KSCTech.Add(upgrading); upgrading.SetBP(cost); upgrading.cost = cost; ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log($"Facility {facilityID} upgrade requested to lvl {oldLevel + 1} for {cost} funds, resulting in a BP of {upgrading.BP}"); } else { KCTDebug.Log("Couldn't afford to upgrade."); ScreenMessages.PostScreenMessage("Not enough funds to upgrade facility!", 4.0f, ScreenMessageStyle.UPPER_CENTER); } } else if (oldLevel + 1 != upgrading.currentLevel) { ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log($"Facility {facilityID} tried to upgrade to lvl {oldLevel + 1} but already in list!"); } }
public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl) { if (KCT_GUI.PrimarilyDisabled) { bool isLaunchpad = facility.id.ToLower().Contains("launchpad"); if (!isLaunchpad) return; //is a launch pad KCT_GameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl); } if (!(allowedToUpgrade || !KCT_PresetManager.Instance.ActivePreset.generalSettings.KSCUpgradeTimes)) { KCT_UpgradingBuilding upgrading = new KCT_UpgradingBuilding(facility, lvl, lvl - 1, facility.id.Split('/').Last()); upgrading.isLaunchpad = facility.id.ToLower().Contains("launchpad"); if (upgrading.isLaunchpad) { upgrading.launchpadID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID; if (upgrading.launchpadID > 0) upgrading.commonName += KCT_GameStates.ActiveKSC.ActiveLPInstance.name;//" " + (upgrading.launchpadID+1); } if (!upgrading.AlreadyInProgress()) { KCT_GameStates.ActiveKSC.KSCTech.Add(upgrading); upgrading.Downgrade(); double cost = facility.GetUpgradeCost(); upgrading.SetBP(cost); upgrading.cost = cost; ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " upgrade requested to lvl " + lvl + " for " + cost + " funds, resulting in a BP of " + upgrading.BP); } else if (lvl != upgrading.currentLevel) { // KCT_UpgradingBuilding listBuilding = upgrading.KSC.KSCTech.Find(b => b.id == upgrading.id); if (upgrading.isLaunchpad) listBuilding = upgrading.KSC.KSCTech.Find(b => b.isLaunchpad && b.launchpadID == upgrading.launchpadID); listBuilding.Downgrade(); KCT_Utilities.AddFunds(listBuilding.cost, TransactionReasons.None); ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " tried to upgrade to lvl " + lvl + " but already in list!"); } } else { KCTDebug.Log("Facility " + facility.id + " upgraded to lvl " + lvl); if (facility.id.ToLower().Contains("launchpad")) { if (!allowedToUpgrade) KCT_GameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl); //also repairs the launchpad else KCT_GameStates.ActiveKSC.ActiveLPInstance.level = lvl; } allowedToUpgrade = false; foreach (KCT_KSC ksc in KCT_GameStates.KSCs) { ksc.RecalculateBuildRates(); ksc.RecalculateUpgradedBuildRates(); } foreach (KCT_TechItem tech in KCT_GameStates.TechList) { tech.UpdateBuildRate(KCT_GameStates.TechList.IndexOf(tech)); } } /* if (lvl <= lastLvl) { lastLvl = -1; return; } facility.SetLevel(lvl - 1); lastLvl = lvl; double cost = facility.GetUpgradeCost(); double BP = Math.Sqrt(cost) * 2000 * KCT_GameStates.timeSettings.OverallMultiplier;*/ // KCTDebug.Log(facility.GetNormLevel()); }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); VABPlans.Clear(); SPHPlans.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); AirlaunchPrep.Clear(); VABRates.Clear(); SPHRates.Clear(); this.KSCName = node.GetValue("KSCName"); if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID)) { this.ActiveLaunchPadID = 0; } ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHWarehouse.Add(blv); } if (node.TryGetNode("VABPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; if (this.VABPlans.ContainsKey(blv.shipName)) { this.VABPlans.Remove(blv.shipName); } this.VABPlans.Add(blv.shipName, blv); } } } if (node.TryGetNode("SPHPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; if (this.SPHPlans.ContainsKey(blv.shipName)) { this.SPHPlans.Remove(blv.shipName); } this.SPHPlans.Add(blv.shipName, blv); } } } tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.TryGetNode("Airlaunch_Prep", ref tmp)) { foreach (ConfigNode APCN in tmp.GetNodes("Airlaunch_Prep_Item")) { KCT_AirlaunchPrep temp = new KCT_AirlaunchPrep(); ConfigNode.LoadObjectFromConfig(temp, APCN); AirlaunchPrep.Add(temp); } } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); tempUP.Load(upBuild); KSCTech.Add(tempUP); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad")) { KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0"); ConfigNode.LoadObjectFromConfig(tempLP, LP); tempLP.DestructionNode = LP.GetNode("DestructionState"); LaunchPads.Add(tempLP); } } if (node.HasNode("VABRateCache")) { foreach (string rate in node.GetNode("VABRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { VABRates.Add(r); } } } if (node.HasNode("SPHRateCache")) { foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { SPHRates.Add(r); } } } return(this); }
public static void DrawBuildListWindow(int windowID) { if (buildListWindowPosition.xMax > Screen.width) buildListWindowPosition.x = Screen.width - buildListWindowPosition.width; //if (Input.touchCount == 0) MouseOnRolloutButton = false; //GUI.skin = HighLogic.UISkin; GUIStyle redText = new GUIStyle(GUI.skin.label); redText.normal.textColor = Color.red; GUIStyle yellowText = new GUIStyle(GUI.skin.label); yellowText.normal.textColor = Color.yellow; GUIStyle greenText = new GUIStyle(GUI.skin.label); greenText.normal.textColor = Color.green; GUIStyle normalButton = new GUIStyle(GUI.skin.button); GUIStyle yellowButton = new GUIStyle(GUI.skin.button); yellowButton.normal.textColor = Color.yellow; yellowButton.hover.textColor = Color.yellow; yellowButton.active.textColor = Color.yellow; GUIStyle redButton = new GUIStyle(GUI.skin.button); redButton.normal.textColor = Color.red; redButton.hover.textColor = Color.red; redButton.active.textColor = Color.red; GUIStyle greenButton = new GUIStyle(GUI.skin.button); greenButton.normal.textColor = Color.green; greenButton.hover.textColor = Color.green; greenButton.active.textColor = Color.green; int width1 = 120; int width2 = 100; int butW = 20; GUILayout.BeginVertical(); //GUILayout.Label("Current KSC: " + KCT_GameStates.ActiveKSC.KSCName); //List next vessel to finish GUILayout.BeginHorizontal(); GUILayout.Label("Next:", windowSkin.label); IKCTBuildItem buildItem = KCT_Utilities.NextThingToFinish(); if (buildItem != null) { //KCT_BuildListVessel ship = (KCT_BuildListVessel)buildItem; string txt = buildItem.GetItemName(), locTxt = "VAB"; if (buildItem.GetListType() == KCT_BuildListVessel.ListType.Reconditioning) { KCT_Recon_Rollout reconRoll = buildItem as KCT_Recon_Rollout; if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Reconditioning) { txt = "Reconditioning"; locTxt = reconRoll.launchPadID; } else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout) { KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID); txt = associated.shipName + " Rollout"; locTxt = reconRoll.launchPadID; } else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback) { KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID); txt = associated.shipName + " Rollback"; locTxt = reconRoll.launchPadID; } else { locTxt = "VAB"; } } else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.VAB) { locTxt = "VAB"; } else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.SPH) { locTxt = "SPH"; } else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.TechNode) { locTxt = "Tech"; } else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.KSC) { locTxt = "KSC"; } GUILayout.Label(txt); GUILayout.Label(locTxt, windowSkin.label); GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(buildItem.GetTimeLeft())); if (!HighLogic.LoadedSceneIsEditor && TimeWarp.CurrentRateIndex == 0 && GUILayout.Button("Warp to" + System.Environment.NewLine + "Complete")) { KCT_GameStates.targetedItem = buildItem; KCT_GameStates.canWarp = true; KCT_Utilities.RampUpWarp(); KCT_GameStates.warpInitiated = true; /* if (buildItem.GetBuildRate() > 0) { TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + buildItem.GetTimeLeft(), KCT_GameStates.settings.MaxTimeWarp, 1); }*/ } else if (!HighLogic.LoadedSceneIsEditor && TimeWarp.CurrentRateIndex > 0 && GUILayout.Button("Stop" + System.Environment.NewLine + "Warp")) { KCT_GameStates.canWarp = false; TimeWarp.SetRate(0, true); KCT_GameStates.lastWarpRate = 0; } if (KCT_GameStates.settings.AutoKACAlarms && KACWrapper.APIReady && buildItem.GetTimeLeft() > 30) //don't check if less than 30 seconds to completion. Might fix errors people are seeing { double UT = Planetarium.GetUniversalTime(); if (!KCT_Utilities.ApproximatelyEqual(KCT_GameStates.KACAlarmUT - UT, buildItem.GetTimeLeft())) { KCTDebug.Log("KAC Alarm being created!"); KCT_GameStates.KACAlarmUT = (buildItem.GetTimeLeft() + UT); KACWrapper.KACAPI.KACAlarm alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => a.ID == KCT_GameStates.KACAlarmId); if (alarm == null) { alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => (a.Name.StartsWith("KCT: "))); } if (alarm != null) { KCTDebug.Log("Removing existing alarm"); KACWrapper.KAC.DeleteAlarm(alarm.ID); } txt = "KCT: "; if (buildItem.GetListType() == KCT_BuildListVessel.ListType.Reconditioning) { KCT_Recon_Rollout reconRoll = buildItem as KCT_Recon_Rollout; if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Reconditioning) { txt += reconRoll.launchPadID + " Reconditioning"; } else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout) { KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID); txt += associated.shipName + " rollout at " + reconRoll.launchPadID; } else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback) { KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID); txt += associated.shipName + " rollback at " + reconRoll.launchPadID; } else { txt += buildItem.GetItemName() + " Complete"; } } else txt += buildItem.GetItemName() + " Complete"; KCT_GameStates.KACAlarmId = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, txt, KCT_GameStates.KACAlarmUT); KCTDebug.Log("Alarm created with ID: " + KCT_GameStates.KACAlarmId); } } } else { GUILayout.Label("No Active Projects"); } GUILayout.EndHorizontal(); //Buttons for VAB/SPH lists // List<string> buttonList = new List<string> { "VAB", "SPH", "KSC" }; //if (KCT_Utilities.CurrentGameHasScience() && !KCT_GameStates.settings.InstantTechUnlock) buttonList.Add("Tech"); GUILayout.BeginHorizontal(); //if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { buttonList.Add("Upgrades"); buttonList.Add("Settings"); } // int lastSelected = listWindow; // listWindow = GUILayout.Toolbar(listWindow, buttonList.ToArray()); bool VABSelectedNew = GUILayout.Toggle(VABSelected, "VAB", GUI.skin.button); bool SPHSelectedNew = GUILayout.Toggle(SPHSelected, "SPH", GUI.skin.button); bool TechSelectedNew = false; if (KCT_Utilities.CurrentGameHasScience()) TechSelectedNew = GUILayout.Toggle(TechSelected, "Tech", GUI.skin.button); if (VABSelectedNew != VABSelected) SelectList("VAB"); else if (SPHSelectedNew != SPHSelected) SelectList("SPH"); else if (TechSelectedNew != TechSelected) SelectList("Tech"); if (HighLogic.LoadedScene == GameScenes.SPACECENTER && GUILayout.Button("Upgrades")) { showUpgradeWindow = true; showBuildList = false; showBLPlus = false; } if (HighLogic.LoadedScene == GameScenes.SPACECENTER && GUILayout.Button("Settings")) { showBuildList = false; showBLPlus = false; ShowSettings(); } GUILayout.EndHorizontal(); /* if (GUI.changed) { buildListWindowPosition.height = 1; showBLPlus = false; if (lastSelected == listWindow) { listWindow = -1; } }*/ //Content of lists if (listWindow == 0) //VAB Build List { List<KCT_BuildListVessel> buildList = KCT_GameStates.ActiveKSC.VABList; GUILayout.BeginHorizontal(); // GUILayout.Space((butW + 4) * 3); GUILayout.Label("Name:"); GUILayout.Label("Progress:", GUILayout.Width(width1 / 2)); GUILayout.Label("Time Left:", GUILayout.Width(width2)); //GUILayout.Label("BP:", GUILayout.Width(width1 / 2 + 10)); GUILayout.EndHorizontal(); //if (KCT_Utilities.ReconditioningActive(null)) foreach (KCT_Recon_Rollout reconditioning in KCT_GameStates.ActiveKSC.Recon_Rollout.FindAll(r => r.RRType == KCT_Recon_Rollout.RolloutReconType.Reconditioning)) { GUILayout.BeginHorizontal(); IKCTBuildItem item = reconditioning.AsBuildItem(); if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width((butW + 4) * 3))) { KCT_GameStates.targetedItem = item; KCT_GameStates.canWarp = true; KCT_Utilities.RampUpWarp(item); KCT_GameStates.warpInitiated = true; /*if (item.GetBuildRate() > 0) { TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + item.GetTimeLeft(), KCT_GameStates.settings.MaxTimeWarp, 1); }*/ } GUILayout.Label("Reconditioning: "+reconditioning.launchPadID); GUILayout.Label(reconditioning.ProgressPercent().ToString() + "%", GUILayout.Width(width1 / 2)); GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(item.GetTimeLeft()), GUILayout.Width(width2)); //GUILayout.Label(Math.Round(KCT_GameStates.ActiveKSC.GetReconditioning().BP, 2).ToString(), GUILayout.Width(width1 / 2 + 10)); //GUILayout.Space((butW + 4) * 3); GUILayout.EndHorizontal(); } scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250)); { if (buildList.Count == 0) { GUILayout.Label("No vessels under construction! Go to the VAB to build more."); } for (int i = 0; i < buildList.Count; i++) { KCT_BuildListVessel b = buildList[i]; if (!b.allPartsValid) continue; GUILayout.BeginHorizontal(); //GUILayout.Label(b.shipName, GUILayout.Width(width1)); if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("*", GUILayout.Width(butW))) { if (IDSelected == b.id) showBLPlus = !showBLPlus; else showBLPlus = true; IDSelected = b.id; } else if (HighLogic.LoadedSceneIsEditor) { //GUILayout.Space(butW); if (GUILayout.Button("X", GUILayout.Width(butW))) { InputLockManager.SetControlLock(ControlTypes.EDITOR_SOFT_LOCK, "KCTPopupLock"); IDSelected = b.id; DialogGUIBase[] options = new DialogGUIBase[2]; options[0] = new DialogGUIButton("Yes", ScrapVessel); options[1] = new DialogGUIButton("No", DummyVoid); MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap this vessel?", "Scrap Vessel", null, options: options); PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin); } } if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW))) { buildList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { buildList.Insert(0, b); } else { buildList.Insert(i - 1, b); } } else if (i == 0) { // GUILayout.Space(butW + 4); } if (i < buildList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW))) { buildList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { buildList.Add(b); } else { buildList.Insert(i + 1, b); } } else if (i >= buildList.Count - 1) { // GUILayout.Space(butW + 4); } GUILayout.Label(b.shipName); GUILayout.Label(Math.Round(b.ProgressPercent(), 2).ToString() + "%", GUILayout.Width(width1 / 2)); if (b.buildRate > 0) GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(b.timeLeft), GUILayout.Width(width2)); else GUILayout.Label("Est: " + MagiCore.Utilities.GetColonFormattedTime((b.buildPoints - b.progress) / KCT_Utilities.GetBuildRate(0, KCT_BuildListVessel.ListType.VAB, null)), GUILayout.Width(width2)); // GUILayout.Label(Math.Round(b.buildPoints, 2).ToString(), GUILayout.Width(width1 / 2 + 10)); GUILayout.EndHorizontal(); } //ADD Storage here! buildList = KCT_GameStates.ActiveKSC.VABWarehouse; GUILayout.Label("__________________________________________________"); GUILayout.Label("VAB Storage"); if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR && GUILayout.Button("Recover Active Vessel")) { if (!KCT_Utilities.RecoverActiveVesselToStorage(KCT_BuildListVessel.ListType.VAB)) { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Error!", "There was an error while recovering the ship. Sometimes reloading the scene and trying again works. Sometimes a vessel just can't be recovered this way and you must use the stock recover system.", "OK", false, HighLogic.UISkin); } } if (buildList.Count == 0) { GUILayout.Label("No vessels in storage!\nThey will be stored here when they are complete."); } //KCT_Recon_Rollout rollback = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollback); bool rolloutEnabled = KCT_PresetManager.Instance.ActivePreset.generalSettings.ReconditioningTimes && KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit > 0; for (int i = 0; i < buildList.Count; i++) { KCT_BuildListVessel b = buildList[i]; if (!b.allPartsValid) continue; string launchSite = b.launchSite; if (launchSite == "LaunchPad") { if (b.launchSiteID >= 0) launchSite = KCT_GameStates.ActiveKSC.LaunchPads[b.launchSiteID].name; else launchSite = KCT_GameStates.ActiveKSC.ActiveLPInstance.name; } KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollout, launchSite); KCT_Recon_Rollout rollback = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback); KCT_Recon_Rollout recovery = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Recovery); GUIStyle textColor = new GUIStyle(GUI.skin.label); GUIStyle buttonColor = new GUIStyle(GUI.skin.button); VesselPadStatus padStatus = VesselPadStatus.InStorage; if (rollback != null) padStatus = VesselPadStatus.RollingBack; if (recovery != null) padStatus = VesselPadStatus.Recovering; string status = "In Storage"; if (rollout != null && rollout.associatedID == b.id.ToString()) { padStatus = VesselPadStatus.RollingOut; status = "Rolling Out to "+launchSite; textColor = yellowText; if (rollout.AsBuildItem().IsComplete()) { padStatus = VesselPadStatus.RolledOut; status = "At "+launchSite; textColor = greenText; } } else if (rollback != null) { status = "Rolling Back from "+launchSite; textColor = yellowText; } else if (recovery != null) { status = "Recovering"; textColor = redText; } GUILayout.BeginHorizontal(); if (!HighLogic.LoadedSceneIsEditor && (padStatus == VesselPadStatus.InStorage || padStatus == VesselPadStatus.RolledOut)) { if (GUILayout.Button("*", GUILayout.Width(butW))) { if (IDSelected == b.id) showBLPlus = !showBLPlus; else showBLPlus = true; IDSelected = b.id; } } else GUILayout.Space(butW + 4); GUILayout.Label(b.shipName, textColor); GUILayout.Label(status+" ", textColor, GUILayout.ExpandWidth(false)); bool siteHasActiveRolloutOrRollback = rollout != null || KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollback, launchSite) != null; if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && !siteHasActiveRolloutOrRollback) //rollout if the pad isn't busy { GUIStyle btnColor = greenButton; if (KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed) btnColor = redButton; else if (KCT_GameStates.ActiveKSC.GetReconditioning(KCT_GameStates.ActiveKSC.ActiveLPInstance.name) != null) btnColor = yellowButton; KCT_Recon_Rollout tmpRollout = new KCT_Recon_Rollout(b, KCT_Recon_Rollout.RolloutReconType.Rollout, b.id.ToString(), launchSite); string rolloutText = (i == MouseOnRolloutButton ? MagiCore.Utilities.GetColonFormattedTime(tmpRollout.AsBuildItem().GetTimeLeft()) : "Rollout"); if (GUILayout.Button(rolloutText, btnColor, GUILayout.ExpandWidth(false))) { List<string> facilityChecks = b.MeetsFacilityRequirements(); if (facilityChecks.Count == 0) { if (!KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed) { b.launchSiteID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID; if (rollout != null) { rollout.SwapRolloutType(); } // tmpRollout.launchPadID = KCT_GameStates.ActiveKSC.ActiveLPInstance.name; KCT_GameStates.ActiveKSC.Recon_Rollout.Add(tmpRollout); } else { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "You must repair the launchpad before you can launch a vessel from it!", "Acknowledged", false, HighLogic.UISkin); } } else { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "Warning! This vessel did not pass the editor checks! Until you upgrade the VAB and/or Launchpad it cannot be launched. Listed below are the failed checks:\n" + String.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin); } } if (Event.current.type == EventType.Repaint) if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) MouseOnRolloutButton = i; else if (i == MouseOnRolloutButton) MouseOnRolloutButton = -1; } else if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && rollout != null && b.id.ToString() == rollout.associatedID && !rollout.AsBuildItem().IsComplete() && rollback == null && GUILayout.Button(MagiCore.Utilities.GetColonFormattedTime(rollout.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false))) //swap rollout to rollback { rollout.SwapRolloutType(); } else if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && rollback != null && !rollback.AsBuildItem().IsComplete()) { if (rollout == null) { if (GUILayout.Button(MagiCore.Utilities.GetColonFormattedTime(rollback.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false))) //switch rollback back to rollout rollback.SwapRolloutType(); } else { GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(rollback.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false)); } } else if (HighLogic.LoadedScene != GameScenes.TRACKSTATION && recovery == null && (!rolloutEnabled || (rollout != null && b.id.ToString() == rollout.associatedID && rollout.AsBuildItem().IsComplete()))) { KCT_LaunchPad pad = KCT_GameStates.ActiveKSC.LaunchPads.Find(lp => lp.name == launchSite); bool operational = pad!=null ? !pad.destroyed : !KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed; GUIStyle btnColor = greenButton; string launchTxt = "Launch"; if (!operational) { launchTxt = "Repairs Required"; btnColor = redButton; } else if (KCT_Utilities.ReconditioningActive(null, launchSite)) { launchTxt = "Reconditioning"; btnColor = yellowButton; } if (rolloutEnabled && GameSettings.MODIFIER_KEY.GetKey() && GUILayout.Button("Roll Back", GUILayout.ExpandWidth(false))) { rollout.SwapRolloutType(); } else if (!GameSettings.MODIFIER_KEY.GetKey() && GUILayout.Button(launchTxt, btnColor, GUILayout.ExpandWidth(false))) { if (b.launchSiteID >= 0) { KCT_GameStates.ActiveKSC.SwitchLaunchPad(b.launchSiteID); } b.launchSiteID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID; List<string> facilityChecks = b.MeetsFacilityRequirements(); if (facilityChecks.Count == 0) { // bool operational = !KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed;// && KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.VAB);//new PreFlightTests.FacilityOperational("LaunchPad", "building").Test(); if (!operational) { //ScreenMessages.PostScreenMessage("You must repair the launchpad prior to launch!", 4.0f, ScreenMessageStyle.UPPER_CENTER); PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "You must repair the launchpad before you can launch a vessel from it!", "Acknowledged", false, HighLogic.UISkin); } else if (KCT_Utilities.ReconditioningActive(null, launchSite)) { //can't launch now ScreenMessage message = new ScreenMessage("[KCT] Cannot launch while LaunchPad is being reconditioned. It will be finished in " + MagiCore.Utilities.GetFormattedTime(((IKCTBuildItem)KCT_GameStates.ActiveKSC.GetReconditioning(launchSite)).GetTimeLeft()), 4.0f, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(message); } else { /*if (rollout != null) KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);*/ KCT_GameStates.launchedVessel = b; if (ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, b.launchSite).Count == 0)// ShipConstruction.CheckLaunchSiteClear(HighLogic.CurrentGame.flightState, "LaunchPad", false)) { showBLPlus = false; // buildList.RemoveAt(i); if (!IsCrewable(b.ExtractedParts)) b.Launch(); else { showBuildList = false; if (KCT_Events.instance.KCTButtonStock != null) { KCT_Events.instance.KCTButtonStock.SetFalse(); } centralWindowPosition.height = 1; KCT_GameStates.launchedCrew.Clear(); parts = KCT_GameStates.launchedVessel.ExtractedParts; pseudoParts = KCT_GameStates.launchedVessel.GetPseudoParts(); KCT_GameStates.launchedCrew = new List<CrewedPart>(); foreach (PseudoPart pp in pseudoParts) KCT_GameStates.launchedCrew.Add(new CrewedPart(pp.uid, new List<ProtoCrewMember>())); CrewFirstAvailable(); showShipRoster = true; } } else { showBuildList = false; showClearLaunch = true; } } } else { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "Warning! This vessel did not pass the editor checks! Until you upgrade the VAB and/or Launchpad it cannot be launched. Listed below are the failed checks:\n" + String.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin); } } } else if (!HighLogic.LoadedSceneIsEditor && recovery != null) { GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(recovery.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false)); } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); int lpCount = KCT_GameStates.ActiveKSC.LaunchPadCount; if (lpCount > 1 && GUILayout.Button("<<", GUILayout.ExpandWidth(false))) { //Simple fix for mod function being "weird" in the negative direction //http://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain KCT_GameStates.ActiveKSC.SwitchLaunchPad(((KCT_GameStates.ActiveKSC.ActiveLaunchPadID - 1) % lpCount + lpCount) % lpCount); } GUILayout.FlexibleSpace(); GUILayout.Label("Current: " + KCT_GameStates.ActiveKSC.ActiveLPInstance.name+" ("+(KCT_GameStates.ActiveKSC.ActiveLPInstance.level+1)+")"); if (costOfNewLP == -13) costOfNewLP = KCT_MathParsing.GetStandardFormulaValue("NewLaunchPadCost", new Dictionary<string, string> { { "N", KCT_GameStates.ActiveKSC.LaunchPads.Count.ToString() } }); // if (KCT_Utilities.KSCSwitcherInstalled) //todo // costOfNewLP = -1; //disable purchasing additional launchpads when playing with KSC Switcher (until upgrades are properly per KSC) if (GUILayout.Button("Rename", GUILayout.ExpandWidth(false))) { renamingLaunchPad = true; newName = KCT_GameStates.ActiveKSC.ActiveLPInstance.name; showRename = true; showBuildList = false; showBLPlus = false; } if (costOfNewLP >= 0 && GUILayout.Button("New", GUILayout.ExpandWidth(false))) { //open dialog to unlock new costOfNewLP = KCT_MathParsing.GetStandardFormulaValue("NewLaunchPadCost", new Dictionary<string, string> { { "N", KCT_GameStates.ActiveKSC.LaunchPads.Count.ToString() } }); DialogGUIBase[] options = new DialogGUIBase[2]; options[0] = new DialogGUIButton("Yes", () => { if (!KCT_Utilities.CurrentGameIsCareer()) { KCTDebug.Log("Building new launchpad!"); KCT_GameStates.ActiveKSC.LaunchPads.Add(new KCT_LaunchPad("LaunchPad " + (KCT_GameStates.ActiveKSC.LaunchPads.Count + 1), 2)); } else if (Funding.CanAfford((float)costOfNewLP)) { KCTDebug.Log("Building new launchpad!"); //take the funds KCT_Utilities.SpendFunds(costOfNewLP, TransactionReasons.StructureConstruction); //create new launchpad at level -1 KCT_GameStates.ActiveKSC.LaunchPads.Add(new KCT_LaunchPad("LaunchPad " + (KCT_GameStates.ActiveKSC.LaunchPads.Count + 1), -1)); //create new upgradeable KCT_UpgradingBuilding newPad = new KCT_UpgradingBuilding();//(null, 0, -1, "LaunchPad"); newPad.id = "SpaceCenter/LaunchPad"; newPad.isLaunchpad = true; newPad.launchpadID = KCT_GameStates.ActiveKSC.LaunchPads.Count-1; newPad.upgradeLevel = 0; newPad.currentLevel = -1; newPad.cost = costOfNewLP; newPad.SetBP(costOfNewLP); newPad.commonName = "LaunchPad " + (KCT_GameStates.ActiveKSC.LaunchPads.Count); KCT_GameStates.ActiveKSC.KSCTech.Add(newPad); } costOfNewLP = -13; }); options[1] = new DialogGUIButton("No", DummyVoid); MultiOptionDialog diag = new MultiOptionDialog("It will cost " + Math.Round(costOfNewLP, 2).ToString("N") + " funds to build a new launchpad. Would you like to build it?", "Build LaunchPad", null, 300, options); PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin); } GUILayout.FlexibleSpace(); if (lpCount > 1 && GUILayout.Button(">>", GUILayout.ExpandWidth(false))) { KCT_GameStates.ActiveKSC.SwitchLaunchPad((KCT_GameStates.ActiveKSC.ActiveLaunchPadID + 1) % KCT_GameStates.ActiveKSC.LaunchPadCount); } GUILayout.EndHorizontal(); } else if (listWindow == 1) //SPH Build List { List<KCT_BuildListVessel> buildList = KCT_GameStates.ActiveKSC.SPHList; GUILayout.BeginHorizontal(); // GUILayout.Space((butW + 4) * 3); GUILayout.Label("Name:"); GUILayout.Label("Progress:", GUILayout.Width(width1 / 2)); GUILayout.Label("Time Left:", GUILayout.Width(width2)); //GUILayout.Label("BP:", GUILayout.Width(width1 / 2 + 10)); GUILayout.EndHorizontal(); scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250)); { if (buildList.Count == 0) { GUILayout.Label("No vessels under construction! Go to the SPH to build more."); } for (int i = 0; i < buildList.Count; i++) { KCT_BuildListVessel b = buildList[i]; if (!b.allPartsValid) continue; GUILayout.BeginHorizontal(); if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("*", GUILayout.Width(butW))) { if (IDSelected == b.id) showBLPlus = !showBLPlus; else showBLPlus = true; IDSelected = b.id; } else if (HighLogic.LoadedSceneIsEditor) { //GUILayout.Space(butW); if (GUILayout.Button("X", GUILayout.Width(butW))) { InputLockManager.SetControlLock(ControlTypes.EDITOR_SOFT_LOCK, "KCTPopupLock"); IDSelected = b.id; DialogGUIBase[] options = new DialogGUIBase[2]; options[0] = new DialogGUIButton("Yes", ScrapVessel); options[1] = new DialogGUIButton("No", DummyVoid); MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap " + b.shipName + "?", "Scrap Vessel", null, 300, options); PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin); } } if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW))) { buildList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { buildList.Insert(0, b); } else { buildList.Insert(i - 1, b); } } else if (i == 0) { // GUILayout.Space(butW + 4); } if (i < buildList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW))) { buildList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { buildList.Add(b); } else { buildList.Insert(i + 1, b); } } else if (i >= buildList.Count - 1) { // GUILayout.Space(butW + 4); } GUILayout.Label(b.shipName); GUILayout.Label(Math.Round(b.ProgressPercent(), 2).ToString() + "%", GUILayout.Width(width1 / 2)); if (b.buildRate > 0) GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(b.timeLeft), GUILayout.Width(width2)); else GUILayout.Label("Est: " + MagiCore.Utilities.GetColonFormattedTime((b.buildPoints - b.progress) / KCT_Utilities.GetBuildRate(0, KCT_BuildListVessel.ListType.SPH, null)), GUILayout.Width(width2)); //GUILayout.Label(Math.Round(b.buildPoints, 2).ToString(), GUILayout.Width(width1 / 2 + 10)); GUILayout.EndHorizontal(); } buildList = KCT_GameStates.ActiveKSC.SPHWarehouse; GUILayout.Label("__________________________________________________"); GUILayout.Label("SPH Storage"); if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR && GUILayout.Button("Recover Active Vessel")) { if (!KCT_Utilities.RecoverActiveVesselToStorage(KCT_BuildListVessel.ListType.SPH)) { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Error!", "There was an error while recovering the ship. Sometimes reloading the scene and trying again works. Sometimes a vessel just can't be recovered this way and you must use the stock recover system.", "OK", false, HighLogic.UISkin); } } for (int i = 0; i < buildList.Count; i++) { KCT_BuildListVessel b = buildList[i]; if (!b.allPartsValid) continue; string status = ""; KCT_Recon_Rollout recovery = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Recovery); if (recovery != null) status = "Recovering"; GUILayout.BeginHorizontal(); if (!HighLogic.LoadedSceneIsEditor && status == "") { if (GUILayout.Button("*", GUILayout.Width(butW))) { if (IDSelected == b.id) showBLPlus = !showBLPlus; else showBLPlus = true; IDSelected = b.id; } } else GUILayout.Space(butW + 4); GUILayout.Label(b.shipName); GUILayout.Label(status + " ", GUILayout.ExpandWidth(false)); //ScenarioDestructibles.protoDestructibles["KSCRunway"]. if (HighLogic.LoadedScene != GameScenes.TRACKSTATION && recovery == null && GUILayout.Button("Launch", GUILayout.ExpandWidth(false))) { List<string> facilityChecks = b.MeetsFacilityRequirements(); if (facilityChecks.Count == 0) { bool operational = KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.SPH);//new PreFlightTests.FacilityOperational("Runway", "building").Test(); if (!operational) { ScreenMessages.PostScreenMessage("You must repair the runway prior to launch!", 4.0f, ScreenMessageStyle.UPPER_CENTER); } else { showBLPlus = false; KCT_GameStates.launchedVessel = b; if (ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, "Runway").Count == 0) { if (!IsCrewable(b.ExtractedParts)) b.Launch(); else { showBuildList = false; if (KCT_Events.instance.KCTButtonStock != null) { KCT_Events.instance.KCTButtonStock.SetFalse(); } centralWindowPosition.height = 1; KCT_GameStates.launchedCrew.Clear(); parts = KCT_GameStates.launchedVessel.ExtractedParts; pseudoParts = KCT_GameStates.launchedVessel.GetPseudoParts(); KCT_GameStates.launchedCrew = new List<CrewedPart>(); foreach (PseudoPart pp in pseudoParts) KCT_GameStates.launchedCrew.Add(new CrewedPart(pp.uid, new List<ProtoCrewMember>())); CrewFirstAvailable(); showShipRoster = true; } } else { showBuildList = false; showClearLaunch = true; } } } else { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "Warning! This vessel did not pass the editor checks! Until you upgrade the SPH and/or Runway it cannot be launched. Listed below are the failed checks:\n" + String.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin); } } else if (recovery != null) { GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(recovery.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false)); } GUILayout.EndHorizontal(); } if (buildList.Count == 0) { GUILayout.Label("No vessels in storage!\nThey will be stored here when they are complete."); } } GUILayout.EndScrollView(); } else if (listWindow == 2) //Tech nodes { List<KCT_UpgradingBuilding> KSCList = KCT_GameStates.ActiveKSC.KSCTech; List<KCT_TechItem> techList = KCT_GameStates.TechList; //GUILayout.Label("Tech Node Research"); GUILayout.BeginHorizontal(); GUILayout.Label("Name:"); GUILayout.Label("Progress:", GUILayout.Width(width1/2)); GUILayout.Label("Time Left:", GUILayout.Width(width1)); GUILayout.Space(70); GUILayout.EndHorizontal(); scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250)); if (KCT_Utilities.CurrentGameIsCareer()) { if (KSCList.Count == 0) GUILayout.Label("No KSC upgrade projects are currently underway."); foreach (KCT_UpgradingBuilding KCTTech in KSCList) { GUILayout.BeginHorizontal(); /* int i = KSCList.IndexOf(KCTTech); if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW))) { KSCList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { KSCList.Insert(0, KCTTech); } else { KSCList.Insert(i - 1, KCTTech); } } if (i < KSCList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW))) { KSCList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { KSCList.Add(KCTTech); } else { KSCList.Insert(i + 1, KCTTech); } } */ GUILayout.Label(KCTTech.AsIKCTBuildItem().GetItemName()); GUILayout.Label(Math.Round(100 * KCTTech.progress / KCTTech.BP, 2) + " %", GUILayout.Width(width1 / 2)); GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(KCTTech.AsIKCTBuildItem().GetTimeLeft()), GUILayout.Width(width1)); if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width(70))) { KCT_GameStates.targetedItem = KCTTech; KCT_GameStates.canWarp = true; KCT_Utilities.RampUpWarp(KCTTech); KCT_GameStates.warpInitiated = true; /*if (KCTTech.AsIKCTBuildItem().GetBuildRate() > 0) { TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + KCTTech.AsIKCTBuildItem().GetTimeLeft(), KCT_GameStates.settings.MaxTimeWarp, 1); }*/ } else if (HighLogic.LoadedSceneIsEditor) GUILayout.Space(70); GUILayout.EndHorizontal(); } } if (techList.Count == 0) GUILayout.Label("No tech nodes are being researched!\nBegin research by unlocking tech in the R&D building."); bool forceRecheck = false; int cancelID = -1; for (int i = 0; i < techList.Count; i++) { KCT_TechItem t = techList[i]; GUILayout.BeginHorizontal(); if (GUILayout.Button("X", GUILayout.Width(butW))) { forceRecheck = true; cancelID = i; DialogGUIBase[] options = new DialogGUIBase[2]; options[0] = new DialogGUIButton("Yes", () => { CancelTechNode(cancelID); }); options[1] = new DialogGUIButton("No", DummyVoid); MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to stop researching "+t.techName+"?", "Cancel Node?", null, 300, options); PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin); /*if (CancelTechNode(i)) { i--; GUILayout.EndHorizontal(); continue; }*/ } if (i > 0 && t.BuildRate != techList[0].BuildRate) { if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW))) { techList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { techList.Insert(0, t); } else { techList.Insert(i - 1, t); } forceRecheck = true; } } if ((i == 0 && t.BuildRate != techList[techList.Count - 1].BuildRate) || t.BuildRate != techList[techList.Count - 1].BuildRate) { if (i < techList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW))) { techList.RemoveAt(i); if (GameSettings.MODIFIER_KEY.GetKey()) { techList.Add(t); } else { techList.Insert(i + 1, t); } forceRecheck = true; } } if (forceRecheck) { forceRecheck = false; for (int j=0; j<techList.Count; j++) techList[j].UpdateBuildRate(j); } GUILayout.Label(t.techName); GUILayout.Label(Math.Round(100 * t.progress / t.scienceCost, 2) + " %", GUILayout.Width(width1/2)); if (t.BuildRate > 0) GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(t.TimeLeft), GUILayout.Width(width1)); else GUILayout.Label("Est: " + MagiCore.Utilities.GetColonFormattedTime(t.EstimatedTimeLeft), GUILayout.Width(width1)); if (t.BuildRate > 0) { if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp", GUILayout.Width(45))) { KCT_GameStates.targetedItem = t; KCT_GameStates.canWarp = true; KCT_Utilities.RampUpWarp(t); KCT_GameStates.warpInitiated = true; } else if (HighLogic.LoadedSceneIsEditor) GUILayout.Space(45); } else GUILayout.Space(45); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } if (KCT_UpdateChecker.UpdateFound) { GUILayout.BeginHorizontal(); GUILayout.Label("Current Version: " + KCT_UpdateChecker.CurrentVersion); GUILayout.Label("Latest: " + KCT_UpdateChecker.WebVersion); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); // if (ToolbarManager.ToolbarAvailable && ToolbarManager.Instance != null && KCT_GameStates.settings.PreferBlizzyToolbar) if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2)) GUI.DragWindow(); }
public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl) { if (KCT_GUI.PrimarilyDisabled) return; if (!(allowedToUpgrade || KCT_GameStates.settings.InstantKSCUpgrades)) { KCT_UpgradingBuilding upgrading = new KCT_UpgradingBuilding(facility, lvl, lvl - 1, facility.id.Split('/').Last()); if (!upgrading.AlreadyInProgress()) { upgrading.Downgrade(); double cost = facility.GetUpgradeCost(); upgrading.SetBP(cost); upgrading.cost = cost; KCT_GameStates.ActiveKSC.KSCTech.Add(upgrading); ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " upgrade requested to lvl " + lvl + " for " + cost + " funds, resulting in a BP of " + upgrading.BP); } else if (lvl != upgrading.currentLevel) { // KCT_UpgradingBuilding listBuilding = upgrading.KSC.KSCTech.Find(b => b.id == upgrading.id); listBuilding.Downgrade(); KCT_Utilities.AddFunds(listBuilding.cost, TransactionReasons.None); ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER); KCTDebug.Log("Facility " + facility.id + " tried to upgrade to lvl " + lvl + " but already in list!"); } } else { KCTDebug.Log("Facility " + facility.id + " upgraded to lvl " + lvl); allowedToUpgrade = false; foreach (KCT_KSC ksc in KCT_GameStates.KSCs) { ksc.RecalculateBuildRates(); ksc.RecalculateUpgradedBuildRates(); } foreach (KCT_TechItem tech in KCT_GameStates.TechList) { tech.UpdateBuildRate(); } } /* if (lvl <= lastLvl) { lastLvl = -1; return; } facility.SetLevel(lvl - 1); lastLvl = lvl; double cost = facility.GetUpgradeCost(); double BP = Math.Sqrt(cost) * 2000 * KCT_GameStates.timeSettings.OverallMultiplier;*/ // KCTDebug.Log(facility.GetNormLevel()); }