public override void Execute(SharedObjects shared) { var list = new ListValue(); string alarmTypes = PopValueAssert(shared).ToString(); AssertArgBottomAndConsume(shared); if (!KACWrapper.APIReady) { ReturnValue = list; throw new KOSUnavailableAddonException("listAlarms()", "Kerbal Alarm Clock"); } //Get the list of alarms from the KAC Object KACWrapper.KACAPI.KACAlarmList alarms = KACWrapper.KAC.Alarms; foreach (KACWrapper.KACAPI.KACAlarm alarm in alarms) { // if its not my alarm or a general alarm, ignore it if (!string.IsNullOrEmpty(alarm.VesselID) && alarm.VesselID != shared.Vessel.id.ToString()) { continue; } if (alarmTypes.ToUpperInvariant() == "ALL" || alarm.AlarmTime.ToString() == alarmTypes) { list.Add(new KACAlarmWrapper(alarm)); } } ReturnValue = list; }
internal void Update() { if (KACWrapper.InstanceExists) { KACWrapper.KACAPI.KACAlarmList alarms = KACWrapper.KAC.Alarms; int alarmCount = alarms.Count; if (alarmCount > 0) { double UT = Planetarium.GetUniversalTime(); int vesselAlarmCount = 0; string id = vessel.id.ToString(); for (int i = 0; i < alarmCount; ++i) { if (alarms[i].VesselID == id && alarms[i].AlarmTime > UT) { ++vesselAlarmCount; } } if (this.alarms.Length != vesselAlarmCount) { this.alarms = new double[vesselAlarmCount]; alarmIDs = new string[vesselAlarmCount]; } if (vesselAlarmCount > 0) { for (int i = 0; i < alarmCount; ++i) { if (alarms[i].VesselID == id && alarms[i].AlarmTime > UT) { --vesselAlarmCount; alarmIDs[vesselAlarmCount] = alarms[i].ID; this.alarms[vesselAlarmCount] = alarms[i].AlarmTime - UT; } } // Sort the array so the next alarm is in [0]. Array.Sort <double>(this.alarms); } } else if (this.alarms.Length > 0) { this.alarms = new double[0]; alarmIDs = new string[0]; } } }
private ListValue GetAlarms() { var list = new ListValue(); if (!KACWrapper.APIReady) { return(list); } //Get the list of alarms from the KAC Object KACWrapper.KACAPI.KACAlarmList alarms = KACWrapper.KAC.Alarms; foreach (KACWrapper.KACAPI.KACAlarm alarm in alarms) { list.Add(new KACAlarmWrapper(alarm)); } return(list); }
void UpdateAlarm(double mostFutureAlarmTime, bool forward) { if (KACWrapper.APIReady && ELSettings.use_KAC) { if (control.paused) { // It doesn't make sense to have an alarm for an event that will never happen if (control.KACalarmID != "") { try { KACWrapper.KAC.DeleteAlarm(control.KACalarmID); } catch { // Don't crash if there was some problem deleting the alarm } control.KACalarmID = ""; } } else if (mostFutureAlarmTime > 0) { // Find the existing alarm, if it exists // Note that we might have created an alarm, and then the user deleted it! KACWrapper.KACAPI.KACAlarmList alarmList = KACWrapper.KAC.Alarms; KACWrapper.KACAPI.KACAlarm a = null; if ((alarmList != null) && (control.KACalarmID != "")) { //Debug.Log ("Searching for alarm with ID [" + control.KACalarmID + "]"); a = alarmList.FirstOrDefault(z => z.ID == control.KACalarmID); } // set up the strings for the alarm string builderShipName = FlightGlobals.ActiveVessel.vesselName; string newCraftName = control.craftConfig.GetValue("ship"); string alarmMessage = "[EL] build: \"" + newCraftName + "\""; string alarmNotes = "Completion of Extraplanetary Launchpad build of \"" + newCraftName + "\" on \"" + builderShipName + "\""; if (!forward) // teardown messages { alarmMessage = "[EL] teardown: \"" + newCraftName + "\""; alarmNotes = "Teardown of Extraplanetary Launchpad build of \"" + newCraftName + "\" on \"" + builderShipName + "\""; } if (a == null) { // no existing alarm, make a new alarm control.KACalarmID = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, alarmMessage, mostFutureAlarmTime); //Debug.Log ("new alarm ID: [" + control.KACalarmID + "]"); if (control.KACalarmID != "") { a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == control.KACalarmID); if (a != null) { a.AlarmAction = ELSettings.KACAction; a.AlarmMargin = 0; a.VesselID = FlightGlobals.ActiveVessel.id.ToString(); } } } if (a != null) { // Whether we created an alarm or found an existing one, now update it a.AlarmTime = mostFutureAlarmTime; a.Notes = alarmNotes; a.Name = alarmMessage; } } } }
void Update() { if (HighLogic.CurrentGame == null) { return; } if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER) { return; } if (lastUpdate == 99999) { return; } if (emergencyBudgetPercentage < 1) { emergencyBudgetPercentage = 1; } if (emergencyBudgetPercentage > 50) { emergencyBudgetPercentage = 50; } if (researchBudget > 100) { researchBudget = 100; } if (researchBudget < 0) { researchBudget = 0; } double time = (Planetarium.GetUniversalTime()); while (lastUpdate > time) { lastUpdate = lastUpdate - (BudgetSettings.instance.friendlyInterval * dayLength); if (timeDiscrepancyLog) { Debug.Log("[MonthlyBudgets]: Last update was in the future. Using time machine to correct"); timeDiscrepancyLog = false; } } double timeSinceLastUpdate = time - lastUpdate; if (timeSinceLastUpdate >= (BudgetSettings.instance.friendlyInterval * dayLength)) { Budget(timeSinceLastUpdate); } if (KACWrapper.AssemblyExists && BudgetSettings.instance.stopTimewarp) { if (!KACWrapper.APIReady) { return; } KACWrapper.KACAPI.KACAlarmList alarms = KACWrapper.KAC.Alarms; if (alarms.Count == 0) { return; } for (int i = 0; i < alarms.Count; i++) { string s = alarms[i].Name; if (s == "Next Budget") { return; } } KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, "Next Budget", lastUpdate + (BudgetSettings.instance.friendlyInterval * dayLength)); } }