Beispiel #1
0
        public void RevertTo(StringValue editor)
        {
            if (CanRevvertToEditor())
            {
                EditorFacility fac;
                switch (editor.ToUpper())
                {
                case "VAB":
                    fac = EditorFacility.VAB;
                    break;

                case "SPH":
                    fac = EditorFacility.SPH;
                    break;

                default:
                    fac = EditorFacility.None;
                    break;
                }
                shared.Cpu.GetCurrentOpcode().AbortProgram = true;
                FlightDriver.RevertToPrelaunch(fac);
            }
            else
            {
                throw new KOSCommandInvalidHereException(LineCol.Unknown(), "REVERTTO", "When revert is disabled", "When revert is enabled");
            }
        }
Beispiel #2
0
 public void RevertToLaunch()
 {
     if (CanRevertToLaunch())
     {
         FlightDriver.RevertToLaunch();
     }
     else
     {
         throw new KOSCommandInvalidHereException(LineCol.Unknown(), "REVERTTOLAUNCH", "When revert is disabled", "When revert is enabled");
     }
 }
Beispiel #3
0
 public void RevertToLaunch()
 {
     if (CanRevertToLaunch())
     {
         shared.Cpu.GetCurrentOpcode().AbortProgram = true;
         FlightDriver.RevertToLaunch();
     }
     else
     {
         throw new KOSCommandInvalidHereException(LineCol.Unknown(), "REVERTTOLAUNCH", "When revert is disabled", "When revert is enabled");
     }
 }
Beispiel #4
0
 public void RevertToEditor()
 {
     if (CanRevvertToEditor())
     {
         EditorFacility fac = ShipConstruction.ShipType;
         FlightDriver.RevertToPrelaunch(fac);
     }
     else
     {
         throw new KOSCommandInvalidHereException(LineCol.Unknown(), "REVERTTOEDITOR", "When revert is disabled", "When revert is enabled");
     }
 }
Beispiel #5
0
 public override void Execute(SharedObjects shared)
 {
     AssertArgBottomAndConsume(shared);
     if (Staging.separate_ready && shared.Vessel.isActiveVessel)
     {
         Staging.ActivateNextStage();
     }
     else if (!Staging.separate_ready)
     {
         SafeHouse.Logger.Log("FAIL SILENT: Stage is called before it is ready, Use STAGE:READY to check first if staging rapidly");
     }
     else if (!shared.Vessel.isActiveVessel)
     {
         throw new KOSCommandInvalidHereException(LineCol.Unknown(), "STAGE", "a non-active SHIP, KSP does not support this", "Core is on the active vessel");
     }
 }
Beispiel #6
0
        private void ControlFrom()
        {
            ThrowIfNotCPUVessel();
            var dockingModule = Part.Modules.OfType <ModuleDockingNode>().FirstOrDefault();
            var commandModule = Part.Modules.OfType <ModuleCommand>().FirstOrDefault();

            if (commandModule != null)
            {
                commandModule.MakeReference();
            }
            else if (dockingModule != null)
            {
                dockingModule.MakeReferenceTransform();
            }
            else
            {
                throw new KOSCommandInvalidHereException(LineCol.Unknown(), "CONTROLFROM", "a generic part value", "a docking port or command part");
            }
        }
Beispiel #7
0
        private void ReplaceLabels(List <Opcode> program)
        {
            var labels = new Dictionary <string, int>();

            // get the index of every label
            for (int index = 0; index < program.Count; index++)
            {
                if (program[index].Label != string.Empty)
                {
                    if (labels.ContainsKey(program[index].Label))
                    {
                        if (program[index].Label.EndsWith("-default"))
                        {
                            continue;
                        }
                        // This is one of those "should never happen" errors that if it happens
                        // it means kOS devs screwed up - so dump the partially relabeled program
                        // to the log just to help in diagnosing the bug report that may happen:
                        //
                        Utilities.SafeHouse.Logger.LogError("=====Relabeled Program so far is: =========");
                        Utilities.SafeHouse.Logger.LogError(Utilities.Debug.GetCodeFragment(program));

                        throw new Exceptions.KOSCompileException(LineCol.Unknown(), string.Format(
                                                                     "ProgramBuilder.ReplaceLabels: Cannot add label {0}, label already exists.  Opcode: {1}", program[index].Label, program[index].ToString()));
                    }
                    labels.Add(program[index].Label, index);
                }
            }

            // replace destination labels with the corresponding index
            for (int index = 0; index < program.Count; index++)
            {
                Opcode opcode = program[index];
                if (string.IsNullOrEmpty(opcode.DestinationLabel))
                {
                    continue;
                }

                if (!labels.ContainsKey(opcode.DestinationLabel))
                {
                    Utilities.SafeHouse.Logger.LogError("=====Relabeled Program so far is: =========");
                    Utilities.SafeHouse.Logger.LogError(Utilities.Debug.GetCodeFragment(program));

                    throw new Exceptions.KOSCompileException(LineCol.Unknown(), string.Format(
                                                                 "ProgramBuilder.ReplaceLabels: Cannot find label {0}.  Opcode: {1}", opcode.DestinationLabel, opcode.ToString()));
                }
                int destinationIndex = labels[opcode.DestinationLabel];
                if (opcode is BranchOpcode)
                {
                    ((BranchOpcode)opcode).Distance = destinationIndex - index;
                }
                else if (opcode is OpcodePushRelocateLater)
                {
                    // Replace the OpcodePushRelocateLater with the proper OpcodePush:
                    Opcode newOp;
                    if (opcode is OpcodePushDelegateRelocateLater)
                    {
                        newOp = new OpcodePushDelegate(destinationIndex, ((OpcodePushDelegateRelocateLater)opcode).WithClosure);
                    }
                    else
                    {
                        newOp = new OpcodePush(destinationIndex);
                    }
                    newOp.SourcePath   = opcode.SourcePath;
                    newOp.SourceLine   = opcode.SourceLine;
                    newOp.SourceColumn = opcode.SourceColumn;
                    newOp.Label        = opcode.Label;
                    program[index]     = newOp;
                }
                else if (opcode is OpcodeCall)
                {
                    ((OpcodeCall)opcode).Destination = destinationIndex;
                }
            }

            // complete the entry point address of all the objects
            foreach (var objectFile in objectFiles.Values)
            {
                if (objectFile.EntryPointLabel != string.Empty)
                {
                    objectFile.EntryPointAddress = labels[objectFile.EntryPointLabel];
                }
            }
        }