예제 #1
0
            public override void DoOnDirectMasterMsg(MyIGCMessage msg)
            {
                p.Echo("Getting msg from master");
                if (msg.Tag == ShipFormationMaster.TAG_FORMATION)
                {
                    GPS center = new GPS(msg.Data.ToString());
                    p.Echo("Getting formation msg from master : ");

                    IMyRemoteControl r = GetRemote();

                    r.ClearWaypoints();

                    int    nbWP     = 18;
                    double angleTmp = 0;
                    double angleDeg = 360 / nbWP;
                    for (int i = 0; i < nbWP; ++i)
                    {
                        GPS            wp   = center.ComputeCoordinate(ShipFormationMaster.DISTANCE, DegreeToRadian(angleTmp));
                        MyWaypointInfo dest = new MyWaypointInfo("WP_" + i, wp.x, wp.y, wp.z);
                        r.AddWaypoint(dest);
                        angleTmp += angleDeg;
                    }

                    GetLight().SetValue("Color", new Color(0, 255, 0));

                    r.FlightMode = FlightMode.Circle;
                    r.SetCollisionAvoidance(false);
                    r.SetAutoPilotEnabled(true);
                }
            }
예제 #2
0
        void EnableRC(List <MyWaypointInfo> inList, out List <MyWaypointInfo> outList)
        {
            rc.ClearWaypoints();
            List <MyWaypointInfo> tempList = new List <MyWaypointInfo>();

            foreach (MyWaypointInfo point in inList)
            {
                tempList.Add(point);
            }

            outList = tempList;

            rc.SetDockingMode(true);
            rc.SetCollisionAvoidance(true);
            rc.SetAutoPilotEnabled(true);
            rc.FlightMode = FlightMode.OneWay;
        }
예제 #3
0
 public void Climb()
 {
     Echo("Target Grav: " + TargetGravity.ToString() + "m/s");
     Echo("Accel Force (m/s): " + Accel.ToString() + "m/s");
     Echo("Accel Time: " + AccelTime.ToString() + "s");
     Echo("Stop Distance: " + stopDistance.ToString() + "m");
     if (Elev >= (TargetAltitude - stopDistance))
     {
         CCOff.ApplyAction("TriggerNow");
         CruiseCon = false;
         RController.DampenersOverride = true;
         RControllers.SetAutoPilotEnabled(true);
         RControllers.SetCollisionAvoidance(false);
         RControllers.SetDockingMode(true);
         Main("Seperate");
     }
 }
예제 #4
0
        string doInit()
        {
            // initialization of each module goes here:

            // when all initialization is done, set init to true.

            Echo(gtsAllBlocks.Count.ToString() + " Blocks");

            Echo("Init:" + currentInit);
            if (currentInit == 0)
            {
                //        StatusLog("clear", textLongStatus, true); // only MAIN module should clear long status on init.
                StatusLog(DateTime.Now.ToString() + " " + OurName + ":" + moduleName + ":INIT", textLongStatus, true);

                /*
                 * add commands to set modes
                 * if(!modeCommands.ContainsKey("launchprep")) modeCommands.Add("launchprep", MODE_LAUNCHPREP);
                 */
                sInitResults += gridsInit();
                initLogging();
                initTimers();
                sInitResults += SerializeInit();

                Deserialize(); // get info from savefile to avoid blind-rewrite of (our) defaults
            }
            else if (currentInit == 1)
            {
                Deserialize();// get info from savefile to avoid blind-rewrite of (our) defaults

//                sInitResults += BlockInit();
                sInitResults += DefaultOrientationBlockInit();
                initCargoCheck();
                initPower();
                sInitResults += thrustersInit(shipOrientationBlock);
                sInitResults += gyrosetup();
//                if (gtsAllBlocks.Count < 300) currentInit = 2; // go ahead and do next step.
                if (shipOrientationBlock is IMyRemoteControl)
                {
                    Vector3D         playerPosition;
                    bool             bGotPlayer = ((IMyRemoteControl)shipOrientationBlock).GetNearestPlayer(out playerPosition);
                    IMyRemoteControl myR        = (IMyRemoteControl)shipOrientationBlock;
                    myR.SetCollisionAvoidance(false);
                    myR.SetDockingMode(false);
                    myR.Direction  = Base6Directions.Direction.Forward;
                    myR.FlightMode = FlightMode.OneWay;
                    myR.ClearWaypoints();
                    myR.AddWaypoint(playerPosition, "Name");
                }
            }
            if (currentInit == 2)
            {
                sInitResults += wheelsInit(shipOrientationBlock);
                sInitResults += rotorsNavInit();

                sInitResults += connectorsInit();
                sInitResults += tanksInit();
                sInitResults += drillInit();
//                if (gtsAllBlocks.Count < 100) currentInit = 3; // go ahead and do next step.
            }
            if (currentInit == 3)
            {
                sInitResults += camerasensorsInit(shipOrientationBlock);
                sInitResults += ejectorsInit();

                sInitResults += antennaInit();
                sInitResults += gasgenInit();

                autoConfig();
                bWantFast = false;

                if (bGotAntennaName)
                {
                    sBanner = "*" + OurName + ":" + moduleName + " V" + sVersion + " ";
                }

                if (sBanner.Length > 34)
                {
                    sBanner = OurName + ":" + moduleName + "\nV" + sVersion + " ";
                }
                if (shipOrientationBlock is IMyShipController)
                {
                    MyShipMass myMass;
                    myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();

                    gridBaseMass = myMass.BaseMass;
                }

                sInitResults += modeOnInit(); // handle mode initializing from load/recompile..

                init = true;                  // we are done
            }

            currentInit++;
            if (init)
            {
                currentInit = 0;
            }

            Log(sInitResults);

            return(sInitResults);
        }
        public void Main(string argument, UpdateType updateSource)
        {
            string[] argInfo = argument.Split(new string[] { "," }, StringSplitOptions.None);
            if (argument == "RUN")
            {
                //Check if can scan, and scan if can.
                if (cam.CanScan(rayCastDistance))
                {
                    detectedInfo = cam.Raycast(rayCastDistance);
                }
                else
                {
                    Echo("Can't scan yet!");
                }

                Echo("INITIATING");

                coordinate = Vector3D.Zero; //initating to zero value.

                Boolean found = false;
                if (detectedInfo.HitPosition != null)
                {
                    coordinate = detectedInfo.HitPosition.Value;
                    found      = true;
                }

                if (found)
                {
                    Vector3D currentCoords = rc.GetPosition();

                    //creating unit vector
                    double denominator = Math.Sqrt(Math.Pow(coordinate.X - currentCoords.X, 2)
                                                   + Math.Pow(coordinate.Y - currentCoords.Y, 2)
                                                   + Math.Pow(coordinate.Z - currentCoords.Z, 2));
                    double xMultiplier = (coordinate.X - currentCoords.X) / denominator;
                    double yMultiplier = (coordinate.Y - currentCoords.Y) / denominator;
                    double zMultiplier = (coordinate.Z - currentCoords.Z) / denominator;

                    //manipulating target coordinate with unit vector
                    coordinate.X -= finalDistFromTarget * xMultiplier;
                    coordinate.Y -= finalDistFromTarget * yMultiplier;
                    coordinate.Z -= finalDistFromTarget * zMultiplier;

                    //Setting up backward thrusters list
                    backwardThrusters = new List <IMyThrust>();

                    //Obtaining each thruster pointing backward
                    foreach (IMyThrust thruster in thrusters)
                    {
                        if (Base6Directions.GetFlippedDirection(rc.Orientation.Forward) == Base6Directions.GetFlippedDirection(thruster.Orientation.Forward))
                        {
                            backwardThrusters.Add(thruster);
                        }
                    }

                    //Obtaining max backward acceleration
                    MyShipMass myShipMass = rc.CalculateShipMass();
                    backwardsAcceleration = CalculateAcceleration(myShipMass.TotalMass, backwardThrusters);

                    //autopilot settings
                    rc.ClearWaypoints();
                    rc.AddWaypoint(coordinate, "AUTO DYNAMIC BRAKING SCRIPT COORDINATE");
                    rc.SetAutoPilotEnabled(true);
                    rc.SetCollisionAvoidance(false);
                    rc.SetDockingMode(false); //CHANGE??? or dont?
                    rc.FlightMode = FlightMode.OneWay;
                    rc.Direction  = Base6Directions.Direction.Forward;
                    blindMode     = false;
                }
            }
            else if (argInfo[0] == "blind".ToLower())
            {
                int     dist   = 0;
                Boolean passed = Int32.TryParse(argInfo[1], out dist);

                if (passed)
                {
                    Vector3D dir = rc.WorldMatrix.Forward;
                    coordinate    = rc.GetPosition();
                    coordinate.X += dir.X * dist;
                    coordinate.Y += dir.Y * dist;
                    coordinate.Z += dir.Z * dist;

                    Vector3D currentCoords = rc.GetPosition();

                    //Setting up backward thrusters list
                    backwardThrusters = new List <IMyThrust>();

                    //Obtaining each thruster pointing backward
                    foreach (IMyThrust thruster in thrusters)
                    {
                        if (Base6Directions.GetFlippedDirection(rc.Orientation.Forward) == Base6Directions.GetFlippedDirection(thruster.Orientation.Forward))
                        {
                            backwardThrusters.Add(thruster);
                        }
                    }

                    //Obtaining max backward acceleration
                    MyShipMass myShipMass = rc.CalculateShipMass();
                    backwardsAcceleration = CalculateAcceleration(myShipMass.TotalMass, backwardThrusters);

                    //autopilot settings
                    rc.ClearWaypoints();
                    rc.AddWaypoint(coordinate, "CAPTXAN'S SCRIPT COORDINATE");
                    rc.SetAutoPilotEnabled(true);
                    rc.SetCollisionAvoidance(false);
                    rc.SetDockingMode(false); //CHANGE??? or dont?
                    rc.FlightMode = FlightMode.OneWay;
                    rc.Direction  = Base6Directions.Direction.Forward;
                    blindMode     = true;
                    blindCounter  = 0;
                }
                else
                {
                    Echo("2nd parameter is not a number!");
                }
            }
            else
            {
                //User Feedback
                if (!cam.CanScan(rayCastDistance))
                {
                    float percentage = ((cam.TimeUntilScan(rayCastDistance) / 1000) / (rayCastDistance / 2000));
                    percentage = (1 - percentage) * 100;
                    Echo("Raycast is recharging " + percentage + "%");
                    if (!cam.EnableRaycast)
                    {
                        cam.EnableRaycast = true;
                    }
                }
                else
                {
                    Echo("Ready to Scan");
                    cam.EnableRaycast = false;
                }

                //Travelling CHANGE HERE FOR ENABLE / DISABLE AUTOPILOT
                if (rc.IsAutoPilotEnabled)
                {
                    travelling = true;
                    double currentDistanceFromTarget = Vector3D.Distance(coordinate, rc.GetPosition());
                    Echo("Travelling, ETA: " + (int)(currentDistanceFromTarget / rc.GetShipSpeed()) + "s");

                    //Calculating stopping distance to determine if thrusters need to be enabled.
                    Echo("Current Speed: " + (int)rc.GetShipSpeed() + "m/s");
                    Echo("Ship Speed Limit: " + rc.SpeedLimit + "m/s");
                    if (rc.GetShipSpeed() > rc.SpeedLimit - 1) //If ship at max speed
                    {
                        Vector3D currentTrajectory = Vector3D.Normalize(rc.GetPosition() - prevPosition);
                        prevPosition = rc.GetPosition();
                        Vector3D calculatedTrajectory = Vector3D.Normalize(rc.GetPosition() - coordinate);

                        double accuracyAmount;
                        if (currentDistanceFromTarget > 15000)
                        {
                            accuracyAmount = .99999;
                        }
                        else if (currentDistanceFromTarget > 5000)
                        {
                            accuracyAmount = .9999;
                        }
                        else
                        {
                            accuracyAmount = .999;
                        }

                        if (currentDistanceFromTarget * .90 > (Math.Pow(rc.GetShipSpeed(), 2) / (2 * backwardsAcceleration)) &&
                            Math.Abs(currentTrajectory.Dot(calculatedTrajectory)) > accuracyAmount)
                        {
                            foreach (IMyThrust thruster in thrusters)
                            {
                                thruster.ApplyAction("OnOff_Off");
                            }
                        }
                        else //Curr < stopp
                        {
                            foreach (IMyThrust thruster in thrusters)
                            {
                                thruster.ApplyAction("OnOff_On");
                            }
                        }
                    }

                    Echo("Blind Mode: " + blindMode);

                    if (blindMode)
                    {
                        Echo("Blind Counter: " + blindCounter);
                        Echo("Coll Avoid: " + rc.);
                        if (cam.CanScan(((Math.Pow(rc.GetShipSpeed(), 2) / (2 * backwardsAcceleration)) * 2)))
                        {
                            detectedInfo = cam.Raycast((Math.Pow(maxSpeed, 2) / (2 * backwardsAcceleration)) * 2);
                            if (detectedInfo.HitPosition != null)
                            {
                                rc.SpeedLimit = 3;
                                rc.SetCollisionAvoidance(true);
                                blindCounter = 0;
                            }
                            else
                            {
                                if (blindCounter > 500)
                                {
                                    rc.SpeedLimit = maxSpeed;
                                    rc.SetCollisionAvoidance(false);
                                    blindCounter = 0;
                                }
                                else
                                {
                                    blindCounter++;
                                }
                            }
                        }
                    }
                }
                else if (travelling)
                {
                    foreach (IMyThrust thruster in thrusters)
                    {
                        thruster.ApplyAction("OnOff_On");
                    }
                    travelling = false;
                    blindMode  = false;
                }
            }
            //Additional Arugment Commands
            if (argument == "ABORT")
            {
                rc.SetAutoPilotEnabled(false);
                rc.DampenersOverride = true;
            }
        }
예제 #6
0
        public void Main(string argument, UpdateType updateType)
        {
            Vector3D homebase         = new Vector3D(coord[0], coord[1], coord[2]);
            Vector3D homebasevelocity = new Vector3D(velocityout[0], velocityout[1], velocityout[2]);
            MatrixD  m = brain.WorldMatrix;
            Matrix   test;



            switch (argument.ToLower())
            {
            case "auto":
                brain.SetAutoPilotEnabled(true);
                brain.SetCollisionAvoidance(true);
                brain.DampenersOverride = true;
                Echo("Auto Pilot Enabled.");
                break;

            case "stop":
                brain.SetAutoPilotEnabled(false);
                brain.SetCollisionAvoidance(false);
                brain.DampenersOverride = false;
                Echo("Auto Pilot Disabled.");
                break;
            }



            info.WritePublicText("");
            info.WritePublicText(brain.CalculateShipMass().TotalMass.ToString() + " : Mass \n", true);

            //calculate manhattan distance
            int dist = (int)Math.Ceiling(Math.Abs(homebase.X - brain.GetPosition().X) + Math.Abs(homebase.Y - brain.GetPosition().Y) + Math.Abs(homebase.Z - brain.GetPosition().Z));

            info.WritePublicText(dist.ToString() + " :Distance \n", true);
            //debugging to an lcd screen - used as a visual aid
            info.WritePublicText(m.Forward.X.ToString(), true);

            //found out how to use and turn gyro
            //if (dist < 20 && m.Forward.X < 0.1)
            //{
            //    gyro.SetValueFloat("Yaw", 2);
            //    gyro.GetActionWithName("Override").Apply(gyro);
            //}

            //check for new homebase coords
            if (listeners[0].HasPendingMessage)
            {
                packet = listeners[0].AcceptMessage();
                string messagetext = packet.Data.ToString();
                sentcord = messagetext;
            }

            //check for new homebase velocity
            if (listeners[1].HasPendingMessage)
            {
                packet = listeners[1].AcceptMessage();
                string messagetext1 = packet.Data.ToString();
                sentvelocity = messagetext1;
            }
            string[] coords = sentcord.Split(' ');
            if (coords[0] != "")
            {
                coord[0] = double.Parse(coords[0].Remove(0, 2));
                coord[1] = double.Parse(coords[1].Remove(0, 2));
                coord[2] = double.Parse(coords[2].Remove(0, 2));
            }

            string[] velocity = sentvelocity.Split(' ');
            if (velocity[0] != "")
            {
                velocityout[0] = double.Parse(velocity[0].Remove(0, 2));
                velocityout[1] = double.Parse(velocity[1].Remove(0, 2));
                velocityout[2] = double.Parse(velocity[2].Remove(0, 2));
            }
            GetPredictedTargetPosition(homebase, homebasevelocity);

            //add new thrusters to list
            for (int i = 0; i < term.Count; i++)
            {
                onGridThrust.Add((IMyThrust)term[i]);
            }
        }
예제 #7
0
        string doInit()
        {
            // initialization of each module goes here:

            // when all initialization is done, set init to true.
//            Echo(gtsAllBlocks.Count.ToString() + " Blocks");
            if (bStartupError)
            {
                Echo("(RE)INIT:" + sStartupError);
            }

            do
            {
//                Echo("Init:" + currentInit);
                echoInstructions("Init:" + currentInit + " ");
                if (bStartupError)
                {
                    Echo("ERROR: Need (RE)INIT:" + sStartupError);
                    Echo(sStartupError);
                }

                switch (currentInit)
                {
                case 0:
                    sStartupError = "";
                    if (bStartupError)
                    {
                        gridsInit();                    // check the entire grid again
                    }
                    bStartupError = false;
                    StatusLog(DateTime.Now.ToString() + " " + OurName + ":" + moduleName + ":INIT", textLongStatus, true);
                    break;

                case 1:
                    /*
                     * add commands to set modes
                     * if(!modeCommands.ContainsKey("launchprep")) modeCommands.Add("launchprep", MODE_LAUNCHPREP);
                     */
                    if (!modeCommands.ContainsKey("doscans"))
                    {
                        modeCommands.Add("doscans", MODE_DOSCAN);
                    }
                    break;

                case 2:
                    sInitResults += gridsInit();
                    break;

                case 3:
                    initLogging();
                    break;

                case 4:
                    initTimers();
                    break;

                case 5:
                    sInitResults += SerializeInit();
                    Deserialize();     // get info from savefile to avoid blind-rewrite of (our) defaults
                    break;

                case 6:
                    sInitResults += DefaultOrientationBlockInit();
                    break;

                case 7:
                    initCargoCheck();
                    break;

                case 8:
                    initPower();
                    break;

                case 9:
                    sInitResults += thrustersInit(shipOrientationBlock);
                    break;

                case 10:
                    sInitResults += gyrosetup();
                    break;

                case 11:
                    if (shipOrientationBlock is IMyRemoteControl)
                    {
                        Vector3D         playerPosition;
                        bool             bGotPlayer = ((IMyRemoteControl)shipOrientationBlock).GetNearestPlayer(out playerPosition);
                        IMyRemoteControl myR        = (IMyRemoteControl)shipOrientationBlock;
                        myR.SetCollisionAvoidance(false);
                        myR.SetDockingMode(false);
                        myR.Direction  = Base6Directions.Direction.Forward;
                        myR.FlightMode = FlightMode.OneWay;
                        myR.ClearWaypoints();

                        /*
                         * if (bGotPlayer)
                         * {
                         *  // we are a pirate faction.  chase the player.
                         *  myR.AddWaypoint(playerPosition, "Name");
                         *  myR.SetAutoPilotEnabled(true);
                         *  setMode(MODE_ATTACK);
                         * }
                         */
                    }
                    break;

                case 12:
                    sInitResults += wheelsInit(shipOrientationBlock);
                    break;

                case 13:
                    sInitResults += rotorsNavInit();
                    break;

                case 14:
                    sInitResults += connectorsInit();
                    break;

                case 15:
                    sInitResults += tanksInit();
                    break;

                case 16:
                    sInitResults += drillInit();
                    break;

                case 17:
//                        sInitResults += camerasensorsInit(shipOrientationBlock);
                    break;

                case 18:
                    sInitResults += ejectorsInit();
                    break;

                case 19:
                    sInitResults += antennaInit();
                    break;

                case 20:
                    sInitResults += gasgenInit();
                    break;

                case 21:
                    autoConfig();
                    break;

                case 22:
//                        bWantFast = false;

                    if (bGotAntennaName)
                    {
                        sBanner = "*" + OurName + ":" + moduleName + " V" + sVersion + " ";
                    }

                    if (sBanner.Length > 34)
                    {
                        sBanner = OurName + ":" + moduleName + "\nV" + sVersion + " ";
                    }
                    if (shipOrientationBlock is IMyShipController)
                    {
                        MyShipMass myMass;
                        myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();

                        gridBaseMass = myMass.BaseMass;
                    }

                    sInitResults += modeOnInit();     // handle mode initializing from load/recompile..
                    break;

                case 23:
                {
                    // do startup error check
                    init = true;         // we are done
                                         //                       sStartupError = "";
                                         //                        bStartupError = false;
                    if (shipOrientationBlock == null)
                    {
                        shipOrientationBlock = Me;
                        sStartupError       += "\nUsing " + Me.CustomName + " as orientation";

                        //bStartupError = true;
                        sStartupError += "\nNo Ship Controller";
                        dGravity       = -1.0;
                    }
                    else
                    {
                        if (shipOrientationBlock is IMyShipController)
                        {
                            velocityShip = ((IMyShipController)shipOrientationBlock).GetShipSpeed();

                            Vector3D vNG     = ((IMyShipController)shipOrientationBlock).GetNaturalGravity();
                            double   dLength = vNG.Length();
                            dGravity = dLength / 9.81;
                        }
                        else
                        {
                            dGravity = -1.0;
                        }
                    }
                    Echo("Grid Mass=" + gridBaseMass.ToString());
                    if (gridBaseMass > 0)
                    {         // Only require propulsion if not a station
                        if (dGravity == 0)
                        {
                            if (ionThrustCount < 1 && hydroThrustCount < 1)
                            {
                                sStartupError += "\nIn Space, but no valid thrusters";
                            }
                        }
                        if (ionThrustCount < 1 && hydroThrustCount < 1 && atmoThrustCount < 1)
                        {
                            // no thrusters
                            if (wheelSledList.Count < 1)
                            {
                                // no sled wheels && no thrusters
                                if (rotorNavRightList.Count < 1)
                                {
                                    if (wheelRightList.Count < 1)
                                    {
                                        //TODO: Detect station and it's OK to not go anywhere..

                                        bStartupError  = true;
                                        sStartupError += "\nNo Propulsion Method Found";
                                        sStartupError += "\nNo Thrusters.\nNo NAV Rotors\nNo Sled Wheels\nNo Wheels";
                                    }
                                }
                            }
                            else
                            {
                                // sled wheels, but not thrusters...
                                bStartupError  = true;
                                sStartupError += "\nNo Valid Propulsion Method Found";
                                sStartupError += "\nSled wheels, but No Thrusters.\nNo NAV Rotors";
                                if (gyros.Count < 1)
                                {
                                    bStartupError = true;
                                    sStartupError = "\nSled wheels, but no Gyros";
                                }
                            }
                        }
                        else
                        {
                            // we DO have thrusters
                            if (gyros.Count < 1)
                            {
                                // thrusters, but no gyros
                                bStartupError  = true;
                                sStartupError += "\nNo Gyros Found";
                            }
                            // check for sled wheels?
                            if (shipOrientationBlock is IMyShipController)
                            {
                                // can check gravity..
                            }
                        }
                        // check for [WCCS] timer, but no Wico Craft Save.. and vice-versa
                        if (TimerTriggerFind(sSubModuleTimer))
                        {
                            // there is a submodule timer trigger
                            if (SaveFile == null)
                            {         // no save text panel
                                bStartupError  = true;
                                sStartupError += "\nSubmodule timer, but no text\n panel named:" + SAVE_FILE_NAME;
                            }
                        }
                        else
                        {
                            if (bSupportSubModules)
                            {
                                bStartupError  = true;
                                sStartupError += "\nSubmodules Enabled, but no\n timer containing:" + sSubModuleTimer;
                                if (SaveFile == null)
                                {         // no save text panel
                                    bStartupError  = true;
                                    sStartupError += "\n No text\n panel containing:" + SAVE_FILE_NAME;
                                }
                            }
                        }
                    }
                    if (!bStartupError)
                    {
                        init = true;
                    }
                    else
                    {
                        currentInit = -1;         // start init all over again
                    }
                    break;
                }
                }
                currentInit++;
                //               echoInstructions("EInit:" + currentInit + " | ");
                //               Echo("%=" + (float)Runtime.CurrentInstructionCount / (float)Runtime.MaxInstructionCount);
            }while (!init && (((float)Runtime.CurrentInstructionCount / (float)Runtime.MaxInstructionCount) < 0.2f));
            if (init)
            {
                currentInit = 0;
            }
            if (bStartupError)
            {
                Echo("ERROR: Need (RE)INIT:" + sStartupError);
            }

            Echo(sStartupError);

            Log(sInitResults);

            return(sInitResults);
        }
예제 #8
0
        string doInit()
        {
            //             Echo("InitA:" + currentInit + ":"+Runtime.CurrentInstructionCount+ "/"+Runtime.MaxInstructionCount);
            // initialization of each module goes here:

            // when all initialization is done, set init to true.

            if (bStartupError)
            {
                Echo("(RE)INIT:" + sStartupError);
            }
            Log("Init:" + currentInit.ToString());
//            Echo(gtsAllBlocks.Count.ToString() + " Blocks");

            /*
             * double progress = currentInit * 100 / 3; // 3=Number of expected INIT phases.
             * string sProgress = progressBar(progress);
             * StatusLog(moduleName + sProgress, textPanelReport);
             */
            if (shipOrientationBlock != null)
            {
                //               anchorPosition = shipOrientationBlock;
                //               currentPosition = anchorPosition.GetPosition();
            }
            //            Echo("InitB:" + currentInit + ":"+Runtime.CurrentInstructionCount+ "/"+Runtime.MaxInstructionCount);

            do
            {
                //                Echo("Init:" + currentInit);
                echoInstructions("Init:" + currentInit + " ");
                switch (currentInit)
                {
                case 0:
                    sStartupError = "";
                    if (bStartupError)
                    {
                        gridsInit();                    // check the entire grid again
                    }
                    bStartupError = false;
                    StatusLog(DateTime.Now.ToString() + " " + OurName + ":" + moduleName + ":INIT", textLongStatus, true);
                    break;

                case 2:
                    sInitResults += gridsInit();
                    break;

                case 3:
                    initLogging();
                    break;

                case 4:
                    initTimers();
                    break;

                case 5:
                    sInitResults += SerializeInit();
                    Deserialize();     // get info from savefile to avoid blind-rewrite of (our) defaults
                    break;

                case 6:
                    sInitResults += DefaultOrientationBlockInit();
                    break;

                case 7:
                    initCargoCheck();
                    break;

                case 8:
                    initPower();
                    break;

                case 9:
                    sInitResults += thrustersInit(shipOrientationBlock);
                    break;

                case 10:
                    sInitResults += gyrosetup();
                    GyroControl.UpdateGyroList(gyros);
                    break;

                case 11:
                    if (shipOrientationBlock is IMyRemoteControl)
                    {
                        Vector3D         playerPosition;
                        bool             bGotPlayer = ((IMyRemoteControl)shipOrientationBlock).GetNearestPlayer(out playerPosition);
                        IMyRemoteControl myR        = (IMyRemoteControl)shipOrientationBlock;
                        myR.SetCollisionAvoidance(false);
                        myR.SetDockingMode(false);
                        myR.Direction  = Base6Directions.Direction.Forward;
                        myR.FlightMode = FlightMode.OneWay;
                        myR.ClearWaypoints();

                        /*
                         * if (bGotPlayer)
                         * {
                         *  // we are a pirate faction.  chase the player.
                         *  myR.AddWaypoint(playerPosition, "Name");
                         *  myR.SetAutoPilotEnabled(true);
                         *  setMode(MODE_ATTACK);
                         * }
                         */
                    }
                    break;

                case 12:
                    sInitResults += wheelsInit(shipOrientationBlock);
                    break;

                case 13:
                    sInitResults += rotorsNavInit();
                    break;

                case 14:
                    sInitResults += connectorsInit();
                    break;

                case 15:
                    sInitResults += tanksInit();
                    break;

                case 16:
                    sInitResults += drillInit();
                    sInitResults += controllersInit();
                    break;

                case 17:
                    sInitResults += SensorInit(shipOrientationBlock);
                    break;

                case 18:
                    sInitResults += ejectorsInit();
                    break;

                case 19:
                    sInitResults += antennaInit();
                    break;

                case 20:
                    sInitResults += gasgenInit();
                    sInitResults += camerasensorsInit(shipOrientationBlock);
                    sInitResults += airventInit();
                    break;

                case 21:
                    autoConfig();
                    break;

                case 22:
                    //                        bWantFast = false;

                    if (bGotAntennaName)
                    {
                        sBanner = "*" + OurName + ":" + moduleName + " V" + sVersion + " ";
                    }

                    if (sBanner.Length > 34)
                    {
                        sBanner = OurName + ":" + moduleName + "\nV" + sVersion + " ";
                    }
                    if (shipOrientationBlock is IMyShipController)
                    {
                        MyShipMass myMass;
                        myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();

                        gridBaseMass = myMass.BaseMass;
                    }

                    sInitResults += modeOnInit();     // handle mode initializing from load/recompile..
                    break;

                case 23:
                    // do startup error check
                    init          = true; // we are done
                    sStartupError = "";
                    bStartupError = false;
                    if (shipOrientationBlock == null)
                    {
                        bStartupError  = true;
                        sStartupError += "\nNo Ship Controller";
                    }
                    if (ionThrustCount < 1 && hydroThrustCount < 1 && atmoThrustCount < 1)
                    {
                        // no thrusters
                        if (wheelSledList.Count < 1)
                        {
                            // no sled wheels && no thrusters
                            if (rotorNavRightList.Count < 1)
                            {
                                bStartupError  = true;
                                sStartupError += "\nNo Propulsion Method Found";
                                sStartupError += "\nNo Thrusters.\nNo NAV Rotors\nNo Sled Wheels";
                            }
                        }
                        else
                        {
                            // sled wheels, but not thrusters...
                            bStartupError  = true;
                            sStartupError += "\nNo Valid Propulsion Method Found";
                            sStartupError += "\nSled wheels, but No Thrusters.\nNo NAV Rotors";
                        }
                    }
                    else
                    {
                        // we DO have thrusters
                        if (gyros.Count < 1)
                        {
                            // thrusters, but no gyros
                            bStartupError  = true;
                            sStartupError += "\nNo Gyros Found";
                        }
                        // check for sled wheels?
                        if (shipOrientationBlock is IMyShipController)
                        {
                            // can check gravity..
                        }
                    }
                    // check for [WCCS] timer, but no Wico Craft Save.. and vice-versa
                    if (TimerTriggerFind(sSubModuleTimer))
                    {
                        // there is a submodule timer trigger
                        if (SaveFile == null)
                        {     // no save text panel
                            bStartupError  = true;
                            sStartupError += "\nSubmodule timer, but no text\n panel named:" + SAVE_FILE_NAME;
                        }
                    }
                    else
                    {
                        if (bSupportSubModules)
                        {
                            bStartupError  = true;
                            sStartupError += "\nSubmodules Enabled, but no\n timer containing:" + sSubModuleTimer;
                            if (SaveFile == null)
                            {     // no save text panel
                                bStartupError  = true;
                                sStartupError += "\n No text\n panel containing:" + SAVE_FILE_NAME;
                            }
                        }
                    }
                    if (!bStartupError)
                    {
                        init = true;
                    }
                    else
                    {
                        currentInit = -1;     // start init all over again
                    }
                    break;
                }
                currentInit++;
                //               echoInstructions("EInit:" + currentInit + " | ");
                //               Echo("%=" + (float)Runtime.CurrentInstructionCount / (float)Runtime.MaxInstructionCount);
            }while (!init && (((float)Runtime.CurrentInstructionCount / (float)Runtime.MaxInstructionCount) < 0.2f));

/*
 *          if (currentInit == 0)
 *          {
 * //            Echo("Init0:" + currentInit + ":"+Runtime.CurrentInstructionCount+ "/"+Runtime.MaxInstructionCount);
 *              //        StatusLog("clear", textLongStatus, true); // only MAIN module should clear long status on init.
 *              StatusLog(DateTime.Now.ToString() + " " + OurName + ":" + moduleName + ":INIT", textLongStatus, true);
 *
 *              sInitResults += gridsInit();
 *              initLogging();
 *              initTimers();
 *              sInitResults += SerializeInit();
 *
 *              Deserialize(); // get info from savefile to avoid blind-rewrite of (our) defaults
 *          }
 *          else if (currentInit == 1)
 *          {
 *              Deserialize();// get info from savefile to avoid blind-rewrite of (our) defaults
 *
 *              sInitResults += DefaultOrientationBlockInit();
 *              initCargoCheck();
 *              initPower();
 *              sInitResults += thrustersInit(shipOrientationBlock);
 *              sInitResults += gyrosetup();
 *              GyroControl.UpdateGyroList(gyros);
 *              if (gtsAllBlocks.Count < 300) currentInit = 2; // go ahead and do next step.
 *          }
 *          if (currentInit == 2)
 *          {
 *              sInitResults += wheelsInit(shipOrientationBlock);
 *              sInitResults += rotorsNavInit();
 *              sInitResults += wheelsInit(shipOrientationBlock);
 *              sInitResults += sensorInit(true);
 *
 *              if (gtsAllBlocks.Count < 100) currentInit = 3; // go ahead and do next step.
 *          }
 *          if (currentInit == 3)
 *          {
 *             sInitResults += connectorsInit();
 *              sInitResults += tanksInit();
 *              sInitResults += drillInit();
 *              sInitResults += controllersInit();
 *              if (gtsAllBlocks.Count < 100) currentInit = 4; // go ahead and do next step.
 *          }
 *          if (currentInit == 4)
 *          {
 *              sInitResults += ejectorsInit();
 *              sInitResults += antennaInit();
 *              sInitResults += gasgenInit();
 *              sInitResults += camerasensorsInit(shipOrientationBlock);
 *              sInitResults += airventInit();
 *
 *              //        Serialize();
 *
 *              autoConfig();
 *              bWantFast = false;
 *
 *              if (bGotAntennaName)
 *                 sBanner = "*" + OurName + ":" + moduleName + " V" + sVersion + " ";
 *
 *              if(sBanner.Length>34)
 *              {
 *                  sBanner = OurName + ":" + moduleName + "\nV" + sVersion + " ";
 *              }
 *
 *              if (shipOrientationBlock is IMyShipController)
 *              {
 *                  MyShipMass myMass;
 *                  myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();
 *
 *                  gridBaseMass = myMass.BaseMass;
 *              }////
 *              initShipDim(shipOrientationBlock);
 *
 *              sInitResults += modeOnInit(); // handle mode initializing from load/recompile..
 *
 *              if(currentInit==5)
 *              {
 *                  sStartupError = "";
 *                  bStartupError = false;
 *                  if (shipOrientationBlock == null)
 *                  {
 *                      bStartupError = true;
 *                      sStartupError += "\nNo Ship Controller";
 *                  }
 *                  if (ionThrustCount < 1 && hydroThrustCount < 1 && atmoThrustCount < 1)
 *                  {
 *                      // no thrusters
 *                      if (wheelSledList.Count < 1)
 *                      {
 *                          // no sled wheels && no thrusters
 *                          if (rotorNavRightList.Count < 1)
 *                          {
 *                              bStartupError = true;
 *                              sStartupError += "\nNo Propulsion Method Found";
 *                              sStartupError += "\nNo Thrusters.\nNo NAV Rotors\nNo Sled Wheels";
 *
 *                          }
 *                      }
 *                      else
 *                      {
 *                          // sled wheels, but not thrusters...
 *                          bStartupError = true;
 *                          sStartupError += "\nNo Valid Propulsion Method Found";
 *                          sStartupError += "\nSled wheels, but No Thrusters.\nNo NAV Rotors";
 *                      }
 *                  }
 *                  else
 *                  {
 *                      // we DO have thrusters
 *                      if (gyros.Count < 1)
 *                      {
 *                          // thrusters, but no gyros
 *                          bStartupError = true;
 *                          sStartupError += "\nNo Gyros Found";
 *                      }
 *                      // check for sled wheels?
 *                      if (shipOrientationBlock is IMyShipController)
 *                      {
 *                          // can check gravity..
 *                      }
 *                  }
 *                  // check for [WCCS] timer, but no Wico Craft Save.. and vice-versa
 *                  if (TimerTriggerFind(sSubModuleTimer))
 *                  {
 *                      // there is a submodule timer trigger
 *                      if (SaveFile == null)
 *                      { // no save text panel
 *
 *                          bStartupError = true;
 *                          sStartupError += "\nSubmodule timer, but no text\n panel named:" + SAVE_FILE_NAME;
 *
 *                      }
 *                  }
 *                  else
 *                  {
 *                      if (bSubModules)
 *                      {
 *                          bStartupError = true;
 *                          sStartupError += "\nSubmodules Enabled, but no\n timer containing:" + sSubModuleTimer;
 *                          if (SaveFile == null)
 *                          { // no save text panel
 *
 *                              bStartupError = true;
 *                              sStartupError += "\n No text\n panel containing:" + SAVE_FILE_NAME;
 *
 *                          }
 *
 *                      }
 *                  }
 *
 *              }
 *              init = true; // we are done
 *          }
 *
 *          currentInit++;
 */
            if (init)
            {
                currentInit = 0;
            }

            Log(sInitResults);

            return(sInitResults);
        }
예제 #9
0
        public void Main(string argument, UpdateType updateSource)
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100 | UpdateFrequency.Update10;
            IMyTextPanel     textPanel     = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(lcdName);
            IMyRemoteControl remoteControl = (IMyRemoteControl)GridTerminalSystem.GetBlockWithName(remoteControllerName);

            // If setupcomplete is false, run Setup method.
            if (!setupcomplete)
            {
                Echo("Running setup.");
                Setup();
            }
            else
            {
                // To create a listener, we use IGC to access the relevant method.
                // We pass the same tag argument we used for our message.
                IGC.RegisterBroadcastListener(broadcastChannel);


                // Create a list for broadcast listeners.
                List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>();

                // The method argument below is the list we wish IGC to populate with all Listeners we've made.
                // Our Listener will be at index 0, since it's the only one we've made so far.
                IGC.GetBroadcastListeners(listeners);

                if (listeners[0].HasPendingMessage)
                {
                    // Let's create a variable for our new message.
                    // Remember, messages have the type MyIGCMessage.
                    MyIGCMessage message = new MyIGCMessage();

                    // Time to get our message from our Listener (at index 0 of our Listener list).
                    // We do this with the following method:
                    message = listeners[0].AcceptMessage();


                    // A message is a struct of 3 variables. To read the actual data,
                    // we access the Data field, convert it to type string (unboxing),
                    // and store it in the variable messagetext.
                    string messagetext = message.Data.ToString();



                    // We can also access the tag that the message was sent with.
                    string messagetag = message.Tag;

                    //Here we store the "address" to the Programmable Block (our friend's) that sent the message.
                    long sender = message.Source;

                    //Do something with the information!
                    Echo("Message received with tag" + messagetag + "\n\r");
                    Echo("from address " + sender.ToString() + ": \n\r");
                    Echo(messagetext);



                    allmessage += $"\n new message \n {messagetext}\n{messagetext.Split(':')[2]}";
                    textPanel.WriteText(allmessage);

                    List <MyWaypointInfo> myWaypoints = new List <MyWaypointInfo>();

                    string gpsname = messagetext.Split(':')[1];
                    double x       = 0;
                    double y       = 0;
                    double z       = 0;
                    try
                    {
                        x = Convert.ToDouble(messagetext.Split(':')[2]);
                        y = Convert.ToDouble(messagetext.Split(':')[3]);
                        z = Convert.ToDouble(messagetext.Split(':')[4]);
                    }
                    catch (Exception e)
                    {
                        Echo(e.Message);
                    }



                    Echo(messagetext.Split('1')[0]);

                    myWaypoints.Add(new MyWaypointInfo(gpsname, x, y, z));

                    remoteControl.ClearWaypoints();

                    remoteControl.AddWaypoint(myWaypoints[0]);

                    remoteControl.SetCollisionAvoidance(true);

                    remoteControl.SetAutoPilotEnabled(true);
                }
            }

            int textlength = textPanel.GetText().Length;

            if (textlength > 100)
            {
                allmessage = "";
            }
        }