static void ReportEntry(ActionProgramRun ap, List<HistoryEntry> hl, int pos, string prefix) { if (hl != null && pos >= 0 && pos < hl.Count) // if within range.. (1 based) { try { Variables values = new Variables(); ActionVars.HistoryEventVars(values, hl[pos], prefix); ActionVars.ShipBasicInformation(values, hl[pos].ShipInformation, prefix); ActionVars.SystemVars(values, hl[pos].System, prefix); ap.Add(values); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception reporting entry variables in event " + ex.Message); } ap[prefix + "JID"] = hl[pos].Journalid.ToStringInvariant(); ap[prefix + "Count"] = hl.Count.ToString(System.Globalization.CultureInfo.InvariantCulture); // give a count of matches } else { ap[prefix + "JID"] = "0"; ap[prefix + "Count"] = "0"; } }
static void ReportHistoryEntry(ActionProgramRun ap, HistoryEntry he, string prefix) { try { ConditionVariables values = new ConditionVariables(); ActionVars.HistoryEventVars(values, he, prefix); ActionVars.ShipInformation(values, he.ShipInformation, prefix, true); ActionVars.SystemVars(values, he.System, prefix); ap.Add(values); } catch { } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != Conditions.ConditionFunctions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "ST_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Star"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { ISystem sc = SystemClassDB.GetSystem(cmdname); ap[prefix + "Found"] = sc != null ? "1" : "0"; if (sc != null) { Conditions.ConditionVariables vars = new Conditions.ConditionVariables(); ActionVars.SystemVars(vars, sc, prefix); ap.Add(vars); ActionVars.SystemVarsFurtherInfo(ap, (ap.actioncontroller as ActionController).HistoryList, sc, prefix); } } else { ap.ReportError("Missing starname in Star"); } } else { ap.ReportError(res); } return(true); }
static void ReportEntry(ActionProgramRun ap, List <HistoryEntry> hl, int pos, string prefix) { if (hl != null && pos >= 0 && pos < hl.Count) // if within range.. (1 based) { try { ConditionVariables values = new ConditionVariables(); ActionVars.HistoryEventVars(values, hl[pos], prefix); ActionVars.ShipBasicInformation(values, hl[pos].ShipInformation, prefix); ActionVars.SystemVars(values, hl[pos].System, prefix); ap.Add(values); } catch { } ap[prefix + "Count"] = hl.Count.ToString(System.Globalization.CultureInfo.InvariantCulture); // give a count of matches } else { ap[prefix + "JID"] = "0"; ap[prefix + "Count"] = "0"; } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.Functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "ST_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Star"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { ISystem sc = SystemCache.FindSystem(cmdname); ap[prefix + "Found"] = sc != null ? "1" : "0"; if (sc != null) { BaseUtils.Variables vars = new BaseUtils.Variables(); ActionVars.SystemVars(vars, sc, prefix); ap.Add(vars); ActionVars.SystemVarsFurtherInfo(ap, (ap.ActionController as ActionController).HistoryList, sc, prefix); string options = sp.NextWord(); if (options != null) { if (options.Equals("NEAREST", StringComparison.InvariantCultureIgnoreCase)) { double mindist = sp.NextDouble(0.01); double maxdist = sp.NextDouble(20.0); int number = sp.NextInt(50); bool cube = (sp.NextWord() ?? "Spherical").Equals("Cube", StringComparison.InvariantCultureIgnoreCase); // spherical default for all but cube StarDistanceComputer computer = new StarDistanceComputer(); apr = ap; ret_prefix = prefix; computer.CalculateClosestSystems(sc, (sys, list) => (apr.ActionController as ActionController).DiscoveryForm.BeginInvoke(new Action(() => NewStarListComputed(sys, list))), (mindist > 0) ? (number - 1) : number, // adds an implicit 1 on for centre star mindist, maxdist, !cube); return(false); // go to sleep until value computed } } } } else { ap.ReportError("Missing starname in Star"); } } else { ap.ReportError(res); } return(true); }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "SH_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Ship"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { EliteDangerousCore.ShipInformationList lst = (ap.actioncontroller as ActionController).HistoryList.ShipInformationList; Variables values = new Variables(); if (cmdname.Length > 0) { EliteDangerousCore.ShipInformation si = lst.GetShipByFullInfoMatch(cmdname); if (si != null) { ActionVars.ShipBasicInformation(values, si, prefix); ActionVars.ShipModuleInformation(ap, si, prefix); } values[prefix + "Found"] = (si != null) ? "1" : "0"; } values[prefix + "Ships"] = lst.Ships.Count.ToString(System.Globalization.CultureInfo.InvariantCulture); int ind = 0; foreach (EliteDangerousCore.ShipInformation si in lst.Ships.Values) { string p = prefix + "Ships[" + ind.ToString() + "]_"; ActionVars.ShipBasicInformation(values, si, p); ind++; } ap.Add(values); } else { ap.ReportError("Missing ship name in Ship"); } } else { ap.ReportError(res); } return(true); }
private void DoExecute() // MAIN thread only.. { executing = true; System.Diagnostics.Stopwatch timetaken = new System.Diagnostics.Stopwatch(); timetaken.Start(); while (true) { if (progcurrent != null) { if (progcurrent.GetErrorList != null) // any errors pending, handle { actioncontroller.LogLine("Error at " + progcurrent.Location + ": Line " + progcurrent.GetLastStep().LineNumber + ": " + progcurrent.GetLastStep().Name + Environment.NewLine + progcurrent.GetErrorList); TerminateCurrent(); } else if (progcurrent.IsProgramFinished) // if current program ran out, cancel it { // this catches a LOOP without a statement at the end.. or a DO without a WHILE at the end.. if (progcurrent.ExecLevel > 0 && progcurrent.LevelUp(progcurrent.ExecLevel, null)) // see if we have any pending LOOP (or a DO without a while) and continue.. { continue; // errors or movement causes it to go back.. errors will be picked up above } TerminateCurrent(); } } while (progcurrent == null && progqueue.Count > 0) // if no program,but something in queue { progcurrent = progqueue[0]; progqueue.RemoveAt(0); if (progcurrent.variables != null) // if not null, its because its just been restarted after a call.. reset globals { progcurrent.Add(actioncontroller.Globals); // in case they have been updated... } else { progcurrent.PrepareToRun(new ConditionVariables(progcurrent.inputvariables, actioncontroller.Globals), new ConditionFileHandles(), new Dictionary <string, Forms.ConfigurableForm>(), true); // with new file handles and close at end.. } if (progcurrent.IsProgramFinished) // reject empty programs.. { TerminateCurrent(); continue; // and try again } } if (progcurrent == null) // Still nothing, game over { break; } Action ac = progcurrent.GetNextStep(); // get the step. move PC on. if (ac.LevelUp > 0 && progcurrent.LevelUp(ac.LevelUp, ac)) // level up.. { System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Abort Lv" + progcurrent.ExecLevel + " e " + (progcurrent.IsExecuteOn ? "1" : "0") + " up " + ac.LevelUp + ": " + progcurrent.StepNumber + " " + ac.Name + " " + ac.DisplayedUserData); continue; } System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Exec Lv" + progcurrent.ExecLevel + " e " + (progcurrent.IsExecuteOn ? "1" : "0") + " up " + ac.LevelUp + ": " + progcurrent.StepNumber + " " + ac.Name + " " + ac.DisplayedUserData); if (progcurrent.DoExecute(ac)) // execute is on.. { if (ac.Type == Action.ActionType.Call) // Call needs to pass info back up thru to us, need a different call { ActionCall acall = ac as ActionCall; string prog; ConditionVariables paravars; if (acall.ExecuteCallAction(progcurrent, out prog, out paravars)) // if execute ok { //System.Diagnostics.Debug.WriteLine("Call " + prog + " with " + paravars.ToString()); Tuple <ActionFile, ActionProgram> ap = actionfilelist.FindProgram(prog, progcurrent.actionfile); // find program using this name, prefer this action file first if (ap != null) { Run(true, ap.Item1, ap.Item2, paravars, progcurrent.functions.handles, progcurrent.dialogs, false); // run now with these para vars } else { progcurrent.ReportError("Call cannot find " + prog); } } } else if (ac.Type == Action.ActionType.Return) // Return needs to pass info back up thru to us, need a different call { ActionReturn ar = ac as ActionReturn; string retstr; if (ar.ExecuteActionReturn(progcurrent, out retstr)) { TerminateCurrent(); if (progqueue.Count > 0) // pass return value if program is there.. { progqueue[0]["ReturnValue"] = retstr; } continue; // back to top, next action from returned function. } } else if (!ac.ExecuteAction(progcurrent)) // if execute says, stop, i'm waiting for something { return; // exit, with executing set true. ResumeAfterPause will restart it. } } if (async && timetaken.ElapsedMilliseconds > 100) // no more than 100ms per go to stop the main thread being blocked { System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " *** SUSPEND"); restarttick.Start(); break; } } executing = false; }