コード例 #1
0
            public bool SensorIsActive(IMySensorBlock s1, ref bool bAsteroidFound, ref bool bLargeFound, ref bool bSmallFound)
            {
                //           bool bAnyFound = false;
                bAsteroidFound = false;
                bLargeFound    = false;
                bSmallFound    = false;
                if (s1 == null)
                {
                    _program.ErrorLog("SensorIsActive: Null sensor");
                }

                if (s1 != null && s1.IsActive && s1.Enabled && !s1.LastDetectedEntity.IsEmpty())
                {
                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s1.DetectedEntities(lmyDEI);
                    for (int j1 = 0; j1 < lmyDEI.Count; j1++)
                    {
                        if (lmyDEI[j1].Type == MyDetectedEntityType.Asteroid)
                        {
                            //                        Echo(s1.CustomName + "SIA: Asteroid");
                            bAsteroidFound = true;
                        }
                        else if (lmyDEI[j1].Type == MyDetectedEntityType.LargeGrid)
                        {
                            bLargeFound = true;
                        }
                        else if (lmyDEI[j1].Type == MyDetectedEntityType.SmallGrid)
                        {
                            bSmallFound = true;
                        }
                    }
                }
                //            else Echo(s1.CustomName + " SIA() Inactive");
                return(bAsteroidFound || bLargeFound || bSmallFound);// bAnyFound;
            }
        public override void UpdateBeforeSimulation100()
        {
            Init();

            IMySensorBlock sensorBlock = Entity as IMySensorBlock;

            if (Target != null && sensorBlock.IsActive && TeleporterNetwork.ContainsKey(Target))
            {
                PrintDebugMessage($"'{sensorBlock.DisplayNameText}' is an active teleporter to '{Target}'.");
                List <MyDetectedEntityInfo> detectedEntityInfos = new List <MyDetectedEntityInfo>();
                sensorBlock.DetectedEntities(detectedEntityInfos);
                List <IMyPlayer> players = new List <IMyPlayer>();

                foreach (MyDetectedEntityInfo entityInfo in detectedEntityInfos)
                {
                    if (entityInfo.Type == MyDetectedEntityType.CharacterHuman)
                    {
                        MyAPIGateway.Players.GetPlayers(players, p => p.Character.EntityId == entityInfo.EntityId);
                        IMyPlayer player = players[0];

                        PrintDebugMessage($"'{sensorBlock.DisplayNameText}' detected '{player.DisplayName}' and will teleport it to '{TeleporterNetwork[Target].Name}'.");
                        Teleport(player.Character, TeleporterNetwork[Target]);
                    }
                }
            }
        }
コード例 #3
0
        bool SensorActive(IMySensorBlock s1, ref bool bAsteroidFound, ref bool bLargeFound, ref bool bSmallFound)
        {
            //           bool bAnyFound = false;
            bAsteroidFound = false;
            bLargeFound    = false;
            bSmallFound    = false;

            if (s1 != null && s1.IsActive && s1.Enabled && !s1.LastDetectedEntity.IsEmpty())
            {
                List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                s1.DetectedEntities(lmyDEI);
                for (int j1 = 0; j1 < lmyDEI.Count; j1++)
                {
                    if (lmyDEI[j1].Type == MyDetectedEntityType.Asteroid)
                    {
                        bAsteroidFound = true;
                    }
                    else if (lmyDEI[j1].Type == MyDetectedEntityType.LargeGrid)
                    {
                        bLargeFound = true;
                    }
                    else if (lmyDEI[j1].Type == MyDetectedEntityType.SmallGrid)
                    {
                        bSmallFound = true;
                    }
                }
            }
            return(bAsteroidFound || bLargeFound || bSmallFound);// bAnyFound;
        }
コード例 #4
0
            // No normal way to get, workaround!
            public MyDetectedEntityInfo?GetCharacterInShipControllers()
            {
                if (cockpitsEmpty(cockpits))
                {
                    sensor.DetectedEntities(entities);
                }
                else if (!cockpitsEmpty(cockpits))
                {
                    List <MyDetectedEntityInfo> temp = new List <MyDetectedEntityInfo>();

                    sensor.DetectedEntities(temp);

                    MyDetectedEntityInfo?lost = GetLostPlayerEntity(entities, temp);

                    filled = true;
                    return(lost);
                }

                return(null);
            }
コード例 #5
0
        //Scans for targets
        private bool Scan()
        {
            EchoToLCD("Scanning for targets");
            if (_sensorBlock.IsActive)             //If sensor picks up any targets
            {
                List <MyDetectedEntityInfo> targetList = new List <MyDetectedEntityInfo>();
                _sensorBlock.DetectedEntities(targetList);
                EchoToLCD("Targets found by Sensor: " + targetList.Count.ToString());

                double detectedGridDist = -1;
                double distHolder;
                MyDetectedEntityInfo gridHolder = new MyDetectedEntityInfo();
                bool foundOne = false;

                //Finds the closest target
                for (int i = 0; i < targetList.Count; i += 1)
                {
                    if (ValidTarget(targetList[i]))
                    {
                        distHolder = Vector3D.DistanceSquared(targetList[i].Position, Me.GetPosition());
                        if (detectedGridDist < 0 || distHolder < detectedGridDist)
                        {
                            detectedGridDist = distHolder;
                            gridHolder       = targetList[i];
                            foundOne         = true;
                        }
                    }
                }

                //if target found then set target grid
                if (foundOne)
                {
                    EchoToLCD("Target Locked");
                    targetGrid = gridHolder;
                    return(true);
                }
                else
                {
                    EchoToLCD("No valid targets found.");
                }
            }
            else
            {
                EchoToLCD("Sensor block disabled");
            }

            return(false);
        }
コード例 #6
0
 public void Main()
 {
     detected_entities.Clear();
     sensor.DetectedEntities(detected_entities);
     foreach(MyDetectedEntityInfo entity in detected_entities)
     {
         if (entity.Type == player_type)
         {
             p = entity.Position - azimuth_rotor.GetPosition();
             break;
         }
     }
     block_p = convert_to_block_vector(azimuth_rotor, p);
     azimuth_atan2 = (float)Math.Atan2(-block_p.X, block_p.Z);
     azimuth_rotor.TargetVelocityRad = get_azimuth(azimuth_rotor.Angle, azimuth_atan2) * azimuth_mult;
 }
コード例 #7
0
        private void printDetectedObjects(IMySensorBlock sens, IMyTextPanel lcd)
        {
            var det = new List <MyDetectedEntityInfo>();

            sens.DetectedEntities(det);

            lcd.WritePublicText("Detected " + det.Count + " entities.\n", false);

            foreach (var d in det)
            {
                lcd.WritePublicText("ID: " + d.EntityId + "\n", true);
                lcd.WritePublicText("Name: " + d.Name + "\n", true);
                lcd.WritePublicText("Type: " + d.Type + "\n", true);
                lcd.WritePublicText("Time(ms): " + d.TimeStamp + "\n", true);
                lcd.WritePublicText("Pos: " + d.Position + "\n", true);
                lcd.WritePublicText("Relation: " + d.Relationship + "\n", true);
            }
        }
コード例 #8
0
ファイル: turret.cs プロジェクト: Vsevalot/SpaceEngineers
 public void Main()
 {
     test_panel.WriteText("");
     detected_entities.Clear();
     sensor.DetectedEntities(detected_entities);
     foreach (MyDetectedEntityInfo entity in detected_entities)
     {
         if (entity.Type == player_type)
         {
             if (entity.Velocity == new Vector3D(0.0))
             {
                 test_panel.WriteText($"I see: {entity.Type} at {entity.Name}\n", true);
                 turret.SetTarget(entity.Position);
             }
             break;
         }
     }
 }
コード例 #9
0
            public void Main()
            {
                if (sensor == null)
                {
                    return;
                }

                detected.Clear();
                sensor.DetectedEntities(detected);

                foreach (var entity in detected)
                {
                    if ((entity.Relationship & (MyRelationsBetweenPlayerAndBlock.Enemies | MyRelationsBetweenPlayerAndBlock.Neutral | MyRelationsBetweenPlayerAndBlock.NoOwnership)) != 0)
                    {
                        Detonate();
                    }
                }
            }
コード例 #10
0
            private void UpdatePayload()
            {
                if (Vector3D.DistanceSquared(_target, _gyros[0].GetPosition()) < _DetonateDistanceSq)
                {
                    Detonate();
                    return;
                }

                if (_sensor != null)
                {
                    _sensor.DetectedEntities(_detectedEntities);
                    foreach (var entity in _detectedEntities)
                    {
                        if (entity.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies ||
                            entity.Relationship == MyRelationsBetweenPlayerAndBlock.Neutral)
                        {
                            Detonate();
                        }
                    }
                }
            }
コード例 #11
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (sensor != null)
            {
                Echo("updateSource: " + updateSource);
                Echo("IsActive: " + sensor.IsActive);

                entityList.Clear();
                sensor.DetectedEntities(entityList);

                stringBuilder.Clear();
                foreach (var item in entityList)
                {
                    Echo("" + item.Type + ": " + item.Name);
                    stringBuilder.Append(gpsToString(item.Name, item.Position)).Append("\n");
                }
                pbLCD.WriteText(stringBuilder.ToString());
            }
            else
            {
                Echo("run ERROR");
            }
        }
コード例 #12
0
        public void Main(string arg)
        {
            if ((DateTime.Now - last_greetings) < greetings_interval)
            {
                debug_panel.WriteText($"Last greetings: {DateTime.Now - last_greetings} {((DateTime.Now - last_greetings) < greetings_interval)}");
                return;
            }
            else
            {
                can_greet = true;
            }

            if (can_greet)
            {
                if (!player_is_inside)
                {
                    detected_entities.Clear();
                    sensor.DetectedEntities(detected_entities);
                    foreach (MyDetectedEntityInfo entity in detected_entities)
                    {
                        if (entity.Type == player_type)
                        {
                            player_entity    = entity;
                            player_is_inside = true;
                            sensor.Enabled   = false;
                            ticks_passed     = 0;
                            break;
                        }
                    }
                }
                else
                {
                    if (ticks_passed < 100)
                    {
                        greet_panel.WriteText($"{central_n}{authorization_spaces}\\    Authorization    \\");
                    }
                    else if (ticks_passed < 200)
                    {
                        greet_panel.WriteText($"{central_n}{authorization_spaces}|    Authorization.   |");
                    }
                    else if (ticks_passed < 300)
                    {
                        greet_panel.WriteText($"{central_n}{authorization_spaces}/   Authorization..  /");
                    }
                    else if (ticks_passed < 400)
                    {
                        greet_panel.WriteText($"{central_n}{authorization_spaces}\\   Authorization... \\");
                    }
                    else if (ticks_passed < 500)
                    {
                        greet_panel.WriteText($"{central_n}{authorization_spaces}|   Authorization... |");
                    }
                    else if (ticks_passed < 600)
                    {
                        greet_panel.WriteText($"{central_n}{authorization_spaces}/   Authorization... /");
                    }
                    else if (ticks_passed < 1200)
                    {
                        if (player_entity.Name == greeted_player_name)
                        {
                            if (!greeting_started)
                            {
                                greet_panel.WriteText($"{central_n}            Welcome back, commander");
                                jukebox.ApplyAction("OnOff_On");
                                greeting_started = true;
                            }
                        }
                    }
                    else
                    {
                        jukebox.ApplyAction("OnOff_Off");
                        sensor.Enabled   = true;
                        player_is_inside = false;
                        can_greet        = false;
                        greeting_started = false;
                        last_greetings   = DateTime.Now;
                        return;
                    }
                    ticks_passed = ticks_passed + 100;
                }
            }
        }
コード例 #13
0
        void doModeFindOre()
        {
            List <IMySensorBlock> aSensors = null;
            IMySensorBlock        sb;
            IMySensorBlock        sb2;

            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":FindOre", textPanelReport);
            Echo("current_state=" + current_state.ToString());
            double maxThrust = calculateMaxThrust(thrustForwardList);

            Echo("maxThrust=" + maxThrust.ToString("N0"));

            MyShipMass myMass;

            myMass = ((IMyShipController)gpsCenter).CalculateShipMass();
            double effectiveMass = myMass.PhysicalMass;

            Echo("effectiveMass=" + effectiveMass.ToString("N0"));

            double maxDeltaV = (maxThrust) / effectiveMass;

            Echo("maxDeltaV=" + maxDeltaV.ToString("0.00"));

            Echo("Cargo=" + cargopcent.ToString() + "%");

            Echo("velocity=" + velocityShip.ToString("0.00"));
            Echo("miningElapsedMs=" + miningElapsedMs.ToString("0.00"));

            /*
             * Echo("#Sensors=" + sensorsList.Count);
             * Echo("width=" + shipDim.WidthInMeters().ToString("0.0"));
             * Echo("height=" + shipDim.HeightInMeters().ToString("0.0"));
             * Echo("length=" + shipDim.LengthInMeters().ToString("0.0"));
             */
            IMyTextPanel txtPanel = getTextBlock("Sensor Report");

            StatusLog("clear", txtPanel);

            // TODO: Check  maxDeltaV.  If <0.25, then we can't move..
            // so turn around at 0.50 or less.. (and still use cargopcent?)
            if (bValidAsteroid)
            {
                debugGPSOutput("Pre-Valid Ast", vTargetAsteroid);
            }
            //            if(vExpectedExit.AbsMax()>.5)
            {
                Vector3D vT = gpsCenter.GetPosition() + vExpectedExit * 150;
                debugGPSOutput("ExpectedExit", vT);
            }
            switch (current_state)
            {
            case 0:
                current_state = 10;
                bWantFast     = true;
                if (sensorsList.Count < 2)
                {
                    StatusLog(OurName + ":" + moduleName + " Find Ore: Not Enough Sensors!", textLongStatus, true);
                    setMode(MODE_ATTENTION);
                }
                sensorsList[0].DetectAsteroids = true;
                sensorsList[1].DetectAsteroids = true;

                bValidAsteroid = false;
                bValidExit     = false;

                ResetMotion();
//                    turnDrillsOff();
                turnEjectorsOff();
                break;

            case 10:
                //sb = sensorsList[0];
                sleepAllSensors();
                setSensorShip(sensorsList[0], 2, 2, 2, 2, 2, 2);
                //                    setSensorShip(sensorsList[1], 50, 50, 50, 50, 50, 0);
                miningElapsedMs = 0;
                current_state   = 11;
                break;

            case 11:
            {
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < 1)
                {
                    return;
                }

                aSensors = activeSensors();
                bool bFoundAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);

                    strbMining.Clear();
                    strbMining.Append("Sensor Position:" + s.GetPosition().ToString());
                    strbMining.AppendLine();


                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        strbMining.Append("Name: " + lmyDEI[j].Name);
                        strbMining.AppendLine();
                        strbMining.Append("Type: " + lmyDEI[j].Type);
                        strbMining.AppendLine();
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            StatusLog("Found Asteroid!", txtPanel);
                            bFoundAsteroid         = true;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                            bValidAsteroid         = true;
                            vTargetAsteroid        = lmyDEI[j].Position;
                        }
                    }
                    StatusLog(strbMining.ToString(), txtPanel);
                }
                if (bFoundAsteroid)
                {
                    current_state = 20;                         // inside
                }
                else
                {
                    current_state = 100;
                }
            }
            break;

            case 20:
            {
                // started find ore while 'inside' asteroid.
                // point towards exit
                vExpectedExit = gpsCenter.GetPosition() - currentAst.Position;
                vExpectedExit.Normalize();
                bValidExit    = true;
                current_state = 31;
            }
            break;

            case 31:
                sb  = sensorsList[0];
                sb2 = sensorsList[1];
                sleepAllSensors();
                setSensorShip(sb, 0, 0, 0, 0, 45, 0);
                setSensorShip(sb2, 5, 5, 5, 5, 0, 15);
                current_state   = 32;
                miningElapsedMs = 0;
                break;

            case 32:
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < 1)
                {
                    return;                          // delay for sensor settling
                }
                current_state = 35;
                break;

            case 35:
            {
                aSensors = activeSensors();
                //                        bValidAsteroid = false;
                bool bLocalAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            bLocalAsteroid = true;
                            if (!bValidAsteroid)
                            {
                                Echo("Found New Asteroid!");
                                bValidAsteroid  = true;
                                vTargetAsteroid = lmyDEI[j].Position;
                            }
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                        }
                        // need to detect other ships and avoid
                    }
                }
                if (!bLocalAsteroid)
                {         // we have exited the asteroid.
                    ResetMotion();
//                            turnDrillsOff();
                    if (cargopcent > cargopctlowwater || maxDeltaV < (fTargetMiningmps / 2))
                    {
                        // we need to dump our contents
                        turnEjectorsOn();
                    }
                    current_state = 300;
                    bWantFast     = true;
                }
                else
                {         // we are inside asteroid
                    turnEjectorsOn();
                    GyroMain("forward", vExpectedExit, gpsCenter);
                    //                            blockApplyAction(ejectorList, "OnOff_On");
                    if (maxDeltaV < (fTargetMiningmps / 2) || cargopcent > cargopcthighwater && !bWaitingCargo)       //
                    {
                        ResetMotion();
//                                turnDrillsOff();
                        turnEjectorsOn();
                        bWaitingCargo = true;
                    }
                    if (bWaitingCargo)
                    {         // continue to wait
                        // need to check how much stone we have.. if zero(ish), then we're full.. go exit.
                        doCargoOreCheck();
                        if (currentStoneAmount() < 15)
                        {
                            // we are full and not much stone ore in us...
                            ResetMotion();
//                                    turnDrillsOff();
                            turnEjectorsOff();
                            setMode(MODE_EXITINGASTEROID);
                            doTriggerMain();
                        }
                        // TODO: Needs time-out
                        Echo("Cargo above low water: Waiting");
                        if (maxDeltaV > (fTargetMiningmps / 2) && cargopcent < cargopctlowwater)
                        {
                            bWaitingCargo = false;         // can now move.
                        }
                    }
                    else
                    {
//                                GyroMain("forward", vExpectedExit, gpsCenter);
                        turnDrillsOn();
                        mineMoveForward(fTargetMiningmps, fAbortmps);
                        bWantFast = true;
                    }
                }
            }
            break;

            case 100:
                turnDrillsOff();
                sleepAllSensors();
                sb = sensorsList[0];
                setSensorShip(sb, 0, 0, 0, 0, 50, 0);
                current_state   = 101;
                miningElapsedMs = 0;
                break;

            case 101:
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < 1)
                {
                    return;                          // delay for sensor settling
                }
                current_state++;
                break;

            case 102:
            {
                aSensors       = activeSensors();
                bValidAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);

                    StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);
                    strbMining.Clear();
                    strbMining.Append("Sensor Position:" + s.GetPosition().ToString());
                    strbMining.AppendLine();
                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        strbMining.Append("Name: " + lmyDEI[j].Name);
                        strbMining.AppendLine();
                        strbMining.Append("Type: " + lmyDEI[j].Type);
                        strbMining.AppendLine();
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            StatusLog("Found Asteroid!", txtPanel);
                            bValidAsteroid         = true;
                            vTargetAsteroid        = lmyDEI[j].Position;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                        }
                    }
                    StatusLog(strbMining.ToString(), txtPanel);
                    //				else current_state = 100;
                }
                //                        if (!bValidAsteroid)
                {
                    // not in sensor range. start checking cameras
                    double scandist = 500;

                    /*
                     *                          if (bValidAsteroid)
                     *                          {
                     *                              scandist = (gpsCenter.GetPosition() - vTargetAsteroid).Length();
                     *                          }
                     */
                    if (doCameraScan(cameraForwardList, scandist))
                    {         // we scanned
                        if (!lastDetectedInfo.IsEmpty())
                        {     // we hit something
                            if (lastDetectedInfo.Type == MyDetectedEntityType.Asteroid)
                            {
                                addDetectedEntity(lastDetectedInfo);
                                vTargetAsteroid = (Vector3D)lastDetectedInfo.HitPosition;
                                bValidAsteroid  = true;
                                vExpectedExit   = vTargetAsteroid - gpsCenter.GetPosition();
                                vExpectedExit.Normalize();
                                bValidExit = true;
                            }
                        }
                        else
                        {
                            // no asteroid detected.  Check surroundings for one.
                            current_state = 110;
                            bValidExit    = false;
                        }
                    }
                }
                if (bValidExit)
                {
                    current_state = 120;                     //found asteroid ahead
                }
            }
            break;

            case 110:
            {
                sleepAllSensors();
                setSensorShip(sensorsList[0], 50, 50, 50, 50, 50, 50);
                miningElapsedMs = 0;
                current_state   = 111;
            }
            break;

            case 111:
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < 1)
                {
                    return;                          // delay for sensor settling
                }
                current_state++;
                break;

            case 112:
            {
                aSensors = activeSensors();
                //                        bValidAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);

                    StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);
                    strbMining.Clear();
                    strbMining.Append("Sensor Position:" + s.GetPosition().ToString());
                    strbMining.AppendLine();
                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        strbMining.Append("Name: " + lmyDEI[j].Name);
                        strbMining.AppendLine();
                        strbMining.Append("Type: " + lmyDEI[j].Type);
                        strbMining.AppendLine();
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            StatusLog("Found Asteroid!", txtPanel);
                            bValidAsteroid         = true;
                            vTargetAsteroid        = lmyDEI[j].Position;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                        }
                    }
                    StatusLog(strbMining.ToString(), txtPanel);
                    //				else current_state = 100;
                }
                if (bValidAsteroid)
                {
                    bWantFast = true;
                    if (GyroMain("forward", vTargetAsteroid - gpsCenter.GetPosition(), gpsCenter))
                    {
                        // we are aimed
                        current_state = 100;
                    }
                }
            }
            break;

            case 120:
            {         // approach
                if (!bValidAsteroid)
                {
                    current_state = 10;
                    return;
                }
                bWantFast = true;
                // we should have asteroid in front.
                bool bAimed = true;

                Echo(bValidExit.ToString() + " " + Vector3DToString(vExpectedExit));
                bAimed = GyroMain("forward", vExpectedExit, gpsCenter);
                if (bAimed)
                {
                    if (doCameraScan(cameraForwardList, 500))
                    {
                        if (!lastDetectedInfo.IsEmpty())
                        {
                            // we have a target
                            //                                   if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                            {
                                Vector3D vTarget  = (Vector3D)lastDetectedInfo.HitPosition;
                                double   distance = (vTarget - lastCamera.GetPosition()).Length();
                                Echo("Distance=" + distance.ToString());
                                if (distance < 15)
                                {
                                    vLastContact = gpsCenter.GetPosition();
                                    if (!bValidInitialContact)
                                    {
                                        vInitialContact      = vLastContact;
                                        bValidInitialContact = true;
                                    }
                                    current_state = 31;
                                    ResetMotion();
                                }
                                else
                                {
                                    mineMoveForward(fApproachMps, fApproachAbortMps);
                                }
                            }
                            //                                      bValidExit = true;
                            //                                        vExpectedExit = vTarget - gpsCenter.GetPosition();
                        }
                        else
                        {
                            /*
                             * // we scanned, but didn't hit anything.  it's likely a donut
                             * double distance = (vTargetAsteroid - gpsCenter.GetPosition()).Length();
                             * Echo("Distance=" + distance.ToString());
                             * mineMoveForward(fTargetMiningmps,fAbortmps);
                             * if (distance < 5)
                             * {
                             *  vExpectedExit = vTargetAsteroid - gpsCenter.GetPosition();
                             *  current_state = 31;
                             *  ResetMotion();
                             * }
                             */
                            setMode(MODE_ATTENTION);
                        }
                    }
                    // ELSE no scan available.. just wait
                    else
                    {
                        Echo("No Camera SCAN!");
                    }
                }
                else
                {
                    Echo("Aiming");
                }
                // BUG: Gets stuck in state if nothing hit.. (ie, donut)
            }
            break;

            case 300:
            {
                // we have exitted the asteroid.  Prepare for another run or to go dock
                Echo("Exitted!");
                ResetMotion();
                sleepAllSensors();

                if (maxDeltaV < (fTargetMiningmps / 2) || cargopcent > cargopctlowwater)
                {
                    setMode(MODE_DOCKING);
                }
                else
                {
                    vLastExit = gpsCenter.GetPosition();
                    //                           dist = (vLastExit - vInitialExit).Length();
                    if (!bValidInitialExit)
                    {
                        vInitialExit      = vLastExit;
                        bValidInitialExit = true;
                    }
                    setMode(MODE_SEARCHORIENT);
                    // prepare for another run.
                }
                break;
            }
            }
        }
コード例 #14
0
        void doModeExitingAsteroid()
        {
            List <IMySensorBlock> aSensors = null;
            IMySensorBlock        sb;

            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":Exiting!", textPanelReport);
            Echo("current_state=" + current_state.ToString());
            MyShipMass myMass;

            myMass = ((IMyShipController)gpsCenter).CalculateShipMass();
            double effectiveMass = myMass.PhysicalMass;

            double maxThrust = calculateMaxThrust(thrustForwardList);

            Echo("effectiveMass=" + effectiveMass.ToString("N0"));
            Echo("maxThrust=" + maxThrust.ToString("N0"));

            double maxDeltaV = (maxThrust) / effectiveMass;

            Echo("maxDeltaV=" + maxDeltaV.ToString("0.00"));
            Echo("Cargo=" + cargopcent.ToString() + "%");

            Echo("velocity=" + velocityShip.ToString("0.00"));
            Echo("#Sensors=" + sensorsList.Count);
            Echo("width=" + shipDim.WidthInMeters().ToString("0.0"));
            Echo("height=" + shipDim.HeightInMeters().ToString("0.0"));
            Echo("length=" + shipDim.LengthInMeters().ToString("0.0"));

            IMyTextPanel txtPanel = getTextBlock("Sensor Report");

            StatusLog("clear", txtPanel);

            /*
             * 0 - Master Init
             * 10 - Init sensors, turn drills on
             * 11 - await sensor set
             * 20 - turn around until aimed ->30
             * 30 - move forward (out) until exit asteroid
             *
             * 40 when out, call for pickup
             *
             */

            switch (current_state)
            {
            case 0:     //0 - Master Init
                if (sensorsList.Count < 2)
                {
                    StatusLog(OurName + ":" + moduleName + " Find Ore: Not Enough Sensors!", textLongStatus, true);
                    setMode(MODE_ATTENTION);
                }
                ResetMotion();
//                    turnDrillsOff();
                turnEjectorsOn();
                current_state = 10;
                break;

            case 10:    //10 - Init sensors, turn drills on
                sleepAllSensors();
                setSensorShip(sensorsList[0], 2, 2, 2, 2, 15, 15);
                //                    setSensorShip(sensorsList[1], 50, 50, 50, 50, 50, 0);
                miningElapsedMs = 0;
                current_state   = 11;
                break;

            case 11:    //11 - await sensor set
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < 1)
                {
                    return;
                }
                current_state = 20;
                break;

            case 20:     //20 - turn around until aimed ->30
            {
                bWantFast = true;
                turnDrillsOn();

                // we want to turn on our horizontal axis as that should be the 'wide' one.


                bool   bAimed   = false;
                double yawangle = -999;
                Echo("vTarget=" + Vector3DToString(vLastContact));
                yawangle = CalculateYaw(vLastContact, gpsCenter);
                Echo("yawangle=" + yawangle.ToString());
                double aYawAngle = Math.Abs(yawangle);
                bAimed = aYawAngle < .05;
                float maxYPR = GyroControl.MaxYPR;
                if (aYawAngle > 1.0)
                {
                    maxYPR = maxYPR / 2;
                }
                DoRotate(yawangle, "Yaw", maxYPR);

                /*
                 * //minAngleRad = 0.1f;
                 * bAimed=GyroMain("backward", vExpectedExit, gpsCenter);
                 *
                 * // minAngleRad = 0.01f;
                 * // GyroMain("backward", vExpectedExit, gpsCenter);
                 */
                if (bAimed)
                {
                    mineMoveForward(fTargetMiningmps, fAbortmps);
                }

                bool bLocalAsteroid = false;
                aSensors = activeSensors();
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);

                    strbMining.Clear();
                    strbMining.Append("Sensor Position:" + s.GetPosition().ToString());
                    strbMining.AppendLine();

                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        strbMining.Append("Name: " + lmyDEI[j].Name);
                        strbMining.AppendLine();
                        strbMining.Append("Type: " + lmyDEI[j].Type);
                        strbMining.AppendLine();
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            StatusLog("Found Asteroid!", txtPanel);
                            bLocalAsteroid = true;
                        }
                    }
                    StatusLog(strbMining.ToString(), txtPanel);
                }
                if (!bLocalAsteroid)
                {
                    ResetMotion();
//                            turnDrillsOff();
                    sleepAllSensors();
                    current_state = 40;
                }
            }
            break;

            case 30:    //30 - move forward (out) until exit asteroid

                break;

            case 40:    //40 when out, call for pickup
            {
                turnDrillsOff();
                // we should probably give hint to docking as to WHY we want to dock..
                setMode(MODE_DOCKING);
            }
            break;
            }
        }
コード例 #15
0
        void doModeSearchShift()
        {
            List <IMySensorBlock> aSensors = null;

            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":SearchShift", textPanelReport);
            Echo("Search Shift: current_state=" + current_state.ToString());
            double maxThrust = calculateMaxThrust(thrustForwardList);

            Echo("maxThrust=" + maxThrust.ToString("N0"));

            MyShipMass myMass;

            myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();
            double effectiveMass = myMass.PhysicalMass;

            Echo("effectiveMass=" + effectiveMass.ToString("N0"));

            double maxDeltaV = (maxThrust) / effectiveMass;

            Echo("maxDeltaV=" + maxDeltaV.ToString("0.00"));

            Echo("Cargo=" + cargopcent.ToString() + "%");

            Echo("velocity=" + velocityShip.ToString("0.00"));
            Echo("shiftElapsedMs=" + shiftElapsedMs.ToString("0.00"));

            bool bLocalFoundAsteroid = false;

            IMySensorBlock sb;
            IMySensorBlock sb2;

            if (sensorsList.Count < 2)
            {
                StatusLog(OurName + ":" + moduleName + " Search Shift: Not Enough Sensors!", textLongStatus, true);
                setMode(MODE_ATTENTION);
                return;
            }

            sb  = sensorsList[0];
            sb2 = sensorsList[1];
            switch (current_state)
            {
            case 0:
                ResetMotion();
                sleepAllSensors();
                sb2.DetectAsteroids = true;
                sb.DetectAsteroids  = true;
                setSensorShip(sb, 0, 0, 0, 0, 45, 0);
                current_state  = 10;
                shiftElapsedMs = 0;
                break;

            case 10:
                Echo("Check for front");
                shiftElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (shiftElapsedMs < 1)
                {
                    return;                        // delay for sensors
                }
                if (velocityShip > 0.2f)
                {
                    return;
                }
                Echo("Checking");
                aSensors            = activeSensors();
                bLocalFoundAsteroid = false;
                Echo(aSensors.Count + ": Sensors active");
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    if (AsteroidProcessLDEI(lmyDEI))
                    {
                        Echo("Found Asteroid");
                        bLocalFoundAsteroid = true;
                    }
                    else
                    {
                        Echo("Did NOT find asteroid");
                    }
                }
                if (bLocalFoundAsteroid)
                {
                    current_state = 20;
                }
                else
                {
                    current_state = 100;
                }
                break;

            case 20:
                setMode(MODE_FINDORE);
                break;

            case 100:
                // asteroid not in sensor range
                // check 'down' for asteroid.
                setSensorShip(sb, 0, 0, 0, 0, 45, 0);
                setSensorShip(sb2, 0, 0, 0, 45, 45, 0);
                current_state  = 110;
                shiftElapsedMs = 0;
                break;

            case 110:
            {
                // search 'down'
                shiftElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (shiftElapsedMs < 1)
                {
                    return;
                }
                if (velocityShip > 0.2f)
                {
                    return;
                }

                bool bDownAsteroid    = false;
                bool bForwardAsteroid = false;
                bool bLarge           = false;
                bool bSmall           = false;
                SensorActive(sb2, ref bDownAsteroid, ref bLarge, ref bSmall);
                SensorActive(sb, ref bForwardAsteroid, ref bLarge, ref bSmall);
                if (bDownAsteroid || bForwardAsteroid)
                {
                    current_state = 120;
                }
                else
                {
                    current_state = 130;
                }
                break;
            }

            case 120:
            {
                // we found asteroid 'below'.  Move down

                // check 'down' for asteroid.
                //                       setSensorShip(sb, 0, 0, 0, 0, 45, 0);
                // don't need to change sensors
                current_state = 122;
//                        shiftElapsedMs = 0;
                break;
            }

            case 122:
            {
                Echo("Move Down");
//                        if (shiftElapsedMs < 1) return;
//                        if (velocityShip > 0.2f) return;
                // move down until sensor sees asteroid
                bool bDownAsteroid    = false;
                bool bForwardAsteroid = false;
                bool bLarge           = false;
                bool bSmall           = false;
                SensorActive(sb2, ref bDownAsteroid, ref bLarge, ref bSmall);
                SensorActive(sb, ref bForwardAsteroid, ref bLarge, ref bSmall);
                Echo(bForwardAsteroid + ":" + bDownAsteroid);
                if (bForwardAsteroid)
                {
                    Echo("Forward");
                    ResetMotion();
                    // we have it right in front of us.
                    setMode(MODE_FINDORE);
//                            current_state = 120;
                }
                else if (bDownAsteroid)
                {
                    Echo("Down");
                    if (velocityShip < 0.5)
                    {
                        powerUpThrusters(thrustDownList, 100f);
                    }
                    else if (velocityShip > fTargetMiningMps)
                    {
                        powerDownThrusters();
                    }
                    else
                    {
                        powerUpThrusters(thrustDownList, 1f);
                    }
                }
                else
                {
                    Echo("Neither");
                    // we ran out of asteroid.
                    ResetMotion();
                    current_state = 130;
                }

                break;
            }

            case 130:
            {
                // No asteroid 'below'.
                // need to shift (left) (old state 2)
                Echo("Shift Left");
                break;
            }
            }
        }
コード例 #16
0
        void doModeMine()
        {
            List <IMySensorBlock> aSensors = null;
            IMySensorBlock        sb;

            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":Mine!", textPanelReport);
            Echo("current_state=" + current_state.ToString());
            MyShipMass myMass;

            myMass = ((IMyShipController)gpsCenter).CalculateShipMass();
            double effectiveMass = myMass.PhysicalMass;

            double maxThrust = calculateMaxThrust(thrustForwardList);

            Echo("effectiveMass=" + effectiveMass.ToString("N0"));
            Echo("maxThrust=" + maxThrust.ToString("N0"));

            double maxDeltaV = (maxThrust) / effectiveMass;

            Echo("maxDeltaV=" + maxDeltaV.ToString("0.00"));
            Echo("Cargo=" + cargopcent.ToString() + "%");

            Echo("velocity=" + velocityShip.ToString("0.00"));
            Echo("#Sensors=" + sensorsList.Count);
            Echo("width=" + shipDim.WidthInMeters().ToString("0.0"));
            Echo("height=" + shipDim.HeightInMeters().ToString("0.0"));
            Echo("length=" + shipDim.LengthInMeters().ToString("0.0"));

            IMyTextPanel txtPanel = getTextBlock("Sensor Report");

            StatusLog("clear", txtPanel);

            // TODO: Check  maxDeltaV.  If <0.25, then we can't move..
            // so turn around at 0.50 or less.. (and still use cargopcent?)

            switch (current_state)
            {
            case 0:
                current_state = 10;
                bWantFast     = true;
                if (sensorsList.Count < 2)
                {
                    StatusLog(OurName + ":" + moduleName + " Find Ore: Not Enough Sensors!", textLongStatus, true);
                    setMode(MODE_ATTENTION);
                }
                ResetMotion();
                break;

            case 10:
                //sb = sensorsList[0];
                sleepAllSensors();
                setSensorShip(sensorsList[0], 2, 2, 2, 2, 2, 0);
                //                    setSensorShip(sensorsList[1], 50, 50, 50, 50, 50, 0);
                current_state = 11;
                break;

            case 11:
            {
                aSensors = activeSensors();
                bool bFoundAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);

                    strb.Clear();
                    strb.Append("Sensor Position:" + s.GetPosition().ToString());
                    strb.AppendLine();


                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        strb.Append("Name: " + lmyDEI[j].Name);
                        strb.AppendLine();
                        strb.Append("Type: " + lmyDEI[j].Type);
                        strb.AppendLine();
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            StatusLog("Found Asteroid!", txtPanel);
                            bFoundAsteroid         = true;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                            bValidAsteroid         = true;
                            vTargetAsteroid        = lmyDEI[j].Position;
                        }
                    }
                    StatusLog(strb.ToString(), txtPanel);
                }
                if (bFoundAsteroid)
                {
                    current_state = 20;                         // inside
                }
                // should search using cameras..
                // TODO:
                else
                {
                    current_state = 100;
                }
            }
            break;

            case 20:
                // started find ore while 'inside' asteroid.
                // point towards exit
                vExpectedExit = gpsCenter.GetPosition() - currentAst.Position;
                current_state = 31;
                break;

            case 31:
                sb = sensorsList[0];
                sleepAllSensors();
                setSensorShip(sb, 0, 0, 0, 0, 25, 4);
                current_state = 35;
                break;

            case 35:
            {
                aSensors       = activeSensors();
                bValidAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            Echo("Found Asteroid!");
                            bValidAsteroid         = true;
                            vTargetAsteroid        = lmyDEI[j].Position;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                        }
                        // need to detect other ships and avoid
                    }
                }
                if (!bValidAsteroid)
                {         // we have exited the asteroid.
                    ResetMotion();
                    if (cargopcent > cargopctlowwater || maxDeltaV < fTargetMiningmps)
                    {
                        // we need to dump our contents
                    }

                    current_state = 10;
                    bWantFast     = true;
                }
                else
                {         // we are inside asteroid
                    turnEjectorsOn();
//                            blockApplyAction(ejectorList, "OnOff_On");
                    if (cargopcent > cargopcthighwater && !bWaitingCargo)         //maxDeltaV<fTargetMiningmps ||
                    {
                        // need to check how much stone we have.. if zero, then we're full.. go exit.
                        // TODO:
                        ResetMotion();
                        turnDrillsOff();
//                                blockApplyAction(drillList, "OnOff_Off");
                        bWaitingCargo = true;
                    }
                    if (bWaitingCargo && cargopcent > cargopctlowwater)
                    {         // continue to wait
                              // TODO: Needs time-out
                        Echo("Cargo above highwater: Waiting");
                        // should check for stone amount...
                    }
                    else
                    {
                        bWaitingCargo = false;
                        GyroMain("forward", vExpectedExit, gpsCenter);
                        turnDrillsOn();
//                                blockApplyAction(drillList, "OnOff_On");
                        mineMoveForward();
                        bWantFast = true;
                    }
                }
            }
            break;

            case 100:
                turnDrillsOff();
//                    blockApplyAction(drillList, "OnOff_Off");
                sb = sensorsList[0];
                setSensorShip(sb, 0, 0, 0, 0, 50, 0);
                current_state = 101;
                break;

            case 101:
            {
                aSensors       = activeSensors();
                bValidAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);

                    StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);
                    strb.Clear();
                    strb.Append("Sensor Position:" + s.GetPosition().ToString());
                    strb.AppendLine();
                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        strb.Append("Name: " + lmyDEI[j].Name);
                        strb.AppendLine();
                        strb.Append("Type: " + lmyDEI[j].Type);
                        strb.AppendLine();
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            StatusLog("Found Asteroid!", txtPanel);
                            bValidAsteroid         = true;
                            vTargetAsteroid        = lmyDEI[j].Position;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                        }
                    }
                    StatusLog(strb.ToString(), txtPanel);
                    //				else current_state = 100;
                }
                //                        if (!bValidAsteroid)
                {
                    // not in sensor range. start checking cameras
                    if (doCameraScan(cameraForwardList, 5000))
                    {         // we scanned
                        if (!lastDetectedInfo.IsEmpty())
                        {     // we hit something
                            if (lastDetectedInfo.Type == MyDetectedEntityType.Asteroid)
                            {
                                addDetectedEntity(lastDetectedInfo);
                                vTargetAsteroid = (Vector3D)lastDetectedInfo.HitPosition;
                                bValidAsteroid  = true;
                                vExpectedExit   = vTargetAsteroid - gpsCenter.GetPosition();
                            }
                        }
                    }
                }
                if (bValidAsteroid)
                {
                    current_state = 120;                         //found asteroid ahead
                }
            }
            break;

            case 120:
            {
                bWantFast = true;
                // we should have asteroid in front.
                bool     bAimed = false;
                Vector3D vVec   = vTargetAsteroid - gpsCenter.GetPosition();

                bAimed = GyroMain("forward", vVec, gpsCenter);
                if (bAimed)
                {
                    if (doCameraScan(cameraForwardList, 5000))
                    {
                        if (!lastDetectedInfo.IsEmpty())
                        {
                            // we have a target
                            Vector3D vTarget  = (Vector3D)lastDetectedInfo.HitPosition;
                            double   distance = (vTarget - gpsCenter.GetPosition()).Length();
                            Echo("Distance=" + distance.ToString());
                            mineMoveForward();
                            if (distance < 5)
                            {
                                current_state = 31;
                                ResetMotion();
                            }
                        }
                        else
                        {
                            // we scanned, but didn't hit anything.  it's likely a donut
                            double distance = (vTargetAsteroid - gpsCenter.GetPosition()).Length();
                            Echo("Distance=" + distance.ToString());
                            mineMoveForward();
                            if (distance < 5)
                            {
                                current_state = 31;
                                ResetMotion();
                            }
                        }
                    }
                    else
                    {
                        Echo("No Camera SCAN!");
                    }
                }
                else
                {
                    Echo("Aiming");
                }
                // BUG: Gets stuck in state if nothing hit.. (ie, donut)

                // ELSE no scan available.. just wait
            }
            break;
            }
        }
コード例 #17
0
        void doModeFindOre()
        {
            List <IMySensorBlock> aSensors = null;
            IMySensorBlock        sb;
            IMySensorBlock        sb2;

            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":FindOre", textPanelReport);
            Echo("FIND ORE:current_state=" + current_state.ToString());
            double maxThrust = calculateMaxThrust(thrustForwardList);
//            Echo("maxThrust=" + maxThrust.ToString("N0"));

            MyShipMass myMass;

            myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();
            double effectiveMass = myMass.PhysicalMass;
//            Echo("effectiveMass=" + effectiveMass.ToString("N0"));

            double maxDeltaV = (maxThrust) / effectiveMass;

//            Echo("maxDeltaV=" + maxDeltaV.ToString("0.00"));

//            Echo("Cargo=" + cargopcent.ToString() + "%");

//            Echo("velocity=" + velocityShip.ToString("0.00"));
//            Echo("miningElapsedMs=" + miningElapsedMs.ToString("0.00"));

            //           IMyTextPanel txtPanel = getTextBlock("Sensor Report");
            //           StatusLog("clear", txtPanel);

            if (bValidAsteroid)
            {
                debugGPSOutput("Pre-Valid Ast", vTargetAsteroid);
            }
//            if (miningAsteroidID > 0)
            Echo("Our Asteroid=" + miningAsteroidID.ToString());

            //            if(vExpectedExit.AbsMax()>.5)
            {
//                Vector3D vT = shipOrientationBlock.GetPosition() + vExpectedExit * 150;
//                debugGPSOutput("ExpectedExit", vT);
            }
            switch (current_state)
            {
            case 0:
                if (fMiningMinThrust < fTargetMiningMps * 1.1f)
                {
                    fMiningMinThrust = fTargetMiningMps * 1.1f;
                }
                bValidAsteroid = false;     /// really?  shouuldn't we be keepint this?
                bValidExit     = false;
                bWaitingCargo  = false;

                ResetMotion();
                //                    turnDrillsOff();
                turnEjectorsOff();

                current_state = 10;
                bWantFast     = true;

                if (!HasDrills())
                {
                    current_state = 400;
                    return;
                }

                if (sensorsList.Count < 2)
                {
                    StatusLog(OurName + ":" + moduleName + " Find Ore: Not Enough Sensors!", textLongStatus, true);
                    setMode(MODE_ATTENTION);
                }
                sensorsList[0].DetectAsteroids = true;
                sensorsList[1].DetectAsteroids = true;

                if (miningAsteroidID > 0)     // return to a known asteroid
                {
                    bValidAsteroid        = true;
                    vTargetAsteroid       = AsteroidGetPosition(miningAsteroidID);
                    vExpectedAsteroidExit = vTargetAsteroid - shipOrientationBlock.GetPosition();
                    vExpectedAsteroidExit.Normalize();

                    current_state = 120;
                }

                break;

            case 10:
                //sb = sensorsList[0];
                sleepAllSensors();
                setSensorShip(sensorsList[0], 2, 2, 2, 2, 2, 2);
                //                    setSensorShip(sensorsList[1], 50, 50, 50, 50, 50, 0);
                miningElapsedMs = 0;
                current_state   = 11;
                break;

            case 11:
            {
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < dSensorSettleWaitMS)
                {
                    return;
                }

                aSensors = activeSensors();
                bool bFoundAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
//                            StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    if (AsteroidProcessLDEI(lmyDEI))
                    {
                        bFoundAsteroid = true;
                    }

/*
 *                          StatusLog("#DetectedEntities=" + lmyDEI.Count, txtPanel);
 *
 *                          strbMining.Clear();
 *                          strbMining.Append("Sensor Position:" + s.GetPosition().ToString());
 *                          strbMining.AppendLine();
 *
 *
 *                          for (int j = 0; j < lmyDEI.Count; j++)
 *                          {
 *
 *                              strbMining.Append("Name: " + lmyDEI[j].Name);
 *                              strbMining.AppendLine();
 *                              strbMining.Append("Type: " + lmyDEI[j].Type);
 *                              strbMining.AppendLine();
 *                              if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
 *                              {
 *                                  addDetectedEntity(lmyDEI[j]);
 *                                  StatusLog("Found Asteroid!", txtPanel);
 *                                  bFoundAsteroid = true;
 *                                  currentAst.EntityId = lmyDEI[j].EntityId;
 *                                  currentAst.BoundingBox = lmyDEI[j].BoundingBox;
 *                                  bValidAsteroid = true;
 *                                  vTargetAsteroid = lmyDEI[j].Position;
 *                              }
 *                          }
 *                          StatusLog(strbMining.ToString(), txtPanel);
 */
                }
                if (bFoundAsteroid)
                {
                    current_state = 100;
                }
                else
                {
                    // no asteroid in sensor range.  Try cameras
                    current_state = 400;
                }
            }
            break;

            case 20:
            {
                // started find ore while 'inside' asteroid.
                // point towards exit

                /*
                 * vExpectedExit = shipOrientationBlock.GetPosition() - currentAst.Position;
                 * vExpectedExit.Normalize();
                 * bValidExit = true;
                 */
                current_state = 31;
            }
            break;

            case 31:
                sb  = sensorsList[0];
                sb2 = sensorsList[1];
                sleepAllSensors();
                setSensorShip(sb, 0, 0, 0, 0, 45, 0);
                setSensorShip(sb2, 5, 5, 5, 5, 0, 15);
                current_state   = 32;
                miningElapsedMs = 0;
                break;

            case 32:
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < dSensorSettleWaitMS)
                {
                    return;                                            // delay for sensor settling
                }
                current_state = 35;
                break;

            case 35:
            {         // active mining
                      // TODO: check just the front sensor and we are 'exiting' if no asteroid active.
                      //
                sb  = sensorsList[0];
                sb2 = sensorsList[1];
                bool bLocalAsteroid     = false;
                bool bForwardAsteroid   = false;
                bool bSourroundAsteroid = false;
                bool bLarge             = false;
                bool bSmall             = false;
                SensorActive(sb, ref bForwardAsteroid, ref bLarge, ref bSmall);
                SensorActive(sb2, ref bSourroundAsteroid, ref bLarge, ref bSmall);

                aSensors = activeSensors();
                Echo(aSensors.Count + " Active Sensors");
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    if (AsteroidProcessLDEI(lmyDEI))
                    {
                        bLocalAsteroid = true;
                    }
                }
                if (!bLocalAsteroid)
                {         // we have exited the asteroid.
                    Echo("No Local Asteroid found");
                    ResetMotion();
                    if (cargopcent > cargopctlowwater || maxDeltaV < (fMiningMinThrust))
                    {
                        // we need to dump our contents
                        turnEjectorsOn();
                    }
                    current_state = 300;
                    bWantFast     = true;
                }
                else if (bSourroundAsteroid)
                {         // we are inside asteroid
                    turnEjectorsOn();
                    //                            blockApplyAction(ejectorList, "OnOff_On");
                    if (maxDeltaV < fMiningMinThrust || cargopcent > cargopcthighwater && !bWaitingCargo)         //
                    {
                        ResetMotion();
                        turnEjectorsOn();
                        bWaitingCargo = true;
                    }
                    if (bWaitingCargo)
                    {         // continue to wait
                        ResetMotion();
                        // need to check how much stone we have.. if zero(ish), then we're full.. go exit.
                        OreDoCargoCheck();
                        if (currentStoneAmount() < 15)
                        {
                            // we are full and not much stone ore in us...
                            ResetMotion();
                            turnEjectorsOff();
                            setMode(MODE_EXITINGASTEROID);
                        }
                        // TODO: Needs time-out
                        Echo("Cargo above low water: Waiting");
                        if (maxDeltaV > fMiningMinThrust && cargopcent < cargopctlowwater)
                        {
                            bWaitingCargo = false;         // can now move.
                        }
                    }
                    else
                    {
                        GyroMain("forward", vExpectedAsteroidExit, shipOrientationBlock);
                        //                                GyroMain("forward", vExpectedExit, shipOrientationBlock);
                        turnDrillsOn();
                        mineMoveForward(fTargetMiningMps, fMiningAbortMps);
                        //                                bWantFast = true;
                        bWantMedium = true;
                    }
                }
                else
                {
                    // we have nothing in front, but are still close
                    turnDrillsOff();
                    mineMoveForward(fAsteroidApproachMps, fAsteroidApproachAbortMps);
                    bWantMedium = true;
                }
            }
            break;

            case 100:
                turnDrillsOff();
                sleepAllSensors();
                sb = sensorsList[0];
                setSensorShip(sb, 0, 0, 0, 0, 50, 0);
                current_state   = 101;
                miningElapsedMs = 0;
                break;

            case 101:
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < dSensorSettleWaitMS)
                {
                    return;                                            // delay for sensor settling
                }
                current_state++;
                break;

            case 102:
            {
                aSensors       = activeSensors();
                bValidAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
//                            StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    AsteroidProcessLDEI(lmyDEI);
                }
                //                        if (!bValidAsteroid)
                {
                    // not in sensor range. start checking cameras
                    double scandist = 500;

                    /*
                     *                          if (bValidAsteroid)
                     *                          {
                     *                              scandist = (shipOrientationBlock.GetPosition() - vTargetAsteroid).Length();
                     *                          }
                     */
                    if (doCameraScan(cameraForwardList, scandist))
                    {         // we scanned
                        if (!lastDetectedInfo.IsEmpty())
                        {     // we hit something
                            if (lastDetectedInfo.Type == MyDetectedEntityType.Asteroid)
                            {
                                MinerProcessScan(lastDetectedInfo);

                                /*
                                 * addDetectedEntity(lastDetectedInfo);
                                 * vTargetAsteroid = (Vector3D)lastDetectedInfo.HitPosition;
                                 * bValidAsteroid = true;
                                 * vExpectedExit = vTargetAsteroid - shipOrientationBlock.GetPosition();
                                 * vExpectedExit.Normalize();
                                 * bValidExit = true;
                                 */
                            }
                        }
                        else
                        {
                            // no asteroid detected.  Check surroundings for one.
                            current_state = 110;
                            bValidExit    = false;
                        }
                    }
                }
                if (bValidExit)
                {
                    current_state = 120;                     //found asteroid ahead
                }
            }
            break;

            case 110:
            {         // asteroid NOT in front. big sensor search for asteroids in area
                sleepAllSensors();
                setSensorShip(sensorsList[0], 50, 50, 50, 50, 50, 50);
                miningElapsedMs = 0;
                current_state   = 111;
            }
            break;

            case 111:
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < dSensorSettleWaitMS)
                {
                    return;                                            // delay for sensor settling
                }
                current_state++;
                break;

            case 112:
            {         // asteroid not in front. Check sensors
                aSensors = activeSensors();
                //                        bValidAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
//                            StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    AsteroidProcessLDEI(lmyDEI);
                }
                if (bValidAsteroid)
                {
                    bWantFast = true;
                    if (GyroMain("forward", vTargetAsteroid - shipOrientationBlock.GetPosition(), shipOrientationBlock))
                    {
                        // we are aimed
                        current_state = 100;
                    }
                }
            }
            break;

            case 120:
                sleepAllSensors();
                setSensorShip(sensorsList[0], 5, 5, 5, 5, 25, 0);
                //                    setSensorShip(sensorsList[1], 50, 50, 50, 50, 50, 0);
                miningElapsedMs = 0;
                current_state   = 121;

                break;

            case 121:
            {         // approach
                if (!bValidAsteroid)
                {
                    current_state = 10;
                    return;
                }
                bWantFast = true;

                // we should have asteroid in front.
                bool bAimed = true;

                Echo(bValidExit.ToString() + " " + Vector3DToString(vExpectedAsteroidExit));
                bAimed = GyroMain("forward", vExpectedAsteroidExit, shipOrientationBlock);

                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < dSensorSettleWaitMS)
                {
                    return;
                }

                if (bAimed)
                {
                    double scandist;
                    double distanceSQ = 0;
                    if (bValidAsteroid)
                    {
                        distanceSQ = (vTargetAsteroid - shipOrientationBlock.GetPosition()).LengthSquared();
                        scandist   = distanceSQ;
                        Echo("distanceSQ=" + distanceSQ.ToString("0.00"));

                        // TODO: we need to keep the radius/BB of the target asteroid..
                        //                                if (lastDetectedInfo.BoundingBox.Contains(vTargetLocation) != ContainmentType.Disjoint)
                        if (distanceSQ > 512 * 512)
                        {
                            current_state = 130;
                            bWantFast     = true;
                            return;
                        }
                    }
                    else
                    {
                        scandist = 500;          // unknown scan distance
                    }
                    bWantFast   = false;
                    bWantMedium = true;
                    if (doCameraScan(cameraForwardList, scandist))
                    {
                        if (!lastDetectedInfo.IsEmpty())
                        {
                            // we have a target
                            //                                   if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                            {
                                Vector3D vTarget  = (Vector3D)lastDetectedInfo.HitPosition;
                                double   distance = (vTarget - lastCamera.GetPosition()).Length();
                                Echo("Distance=" + distance.ToString());
                                if (distance < 15)
                                {
                                    vLastAsteroidContact = shipOrientationBlock.GetPosition();
                                    if (!bValidInitialAsteroidContact)
                                    {
                                        vInitialAsteroidContact      = vLastAsteroidContact;
                                        bValidInitialAsteroidContact = true;
                                    }
                                    current_state = 31;
                                    ResetMotion();
                                }
                                else if (distance > 100)
                                {
                                    vInitialAsteroidContact = (Vector3D)lastDetectedInfo.HitPosition;
                                    current_state           = 130;// do faster travel
                                }
                                else
                                {
                                    mineMoveForward(fAsteroidApproachMps, fAsteroidApproachAbortMps);
                                }
                            }
                            //                                      bValidExit = true;
                            //                                        vExpectedExit = vTarget - shipOrientationBlock.GetPosition();
                        }
                        else
                        {
                            /*
                             * // we scanned, but didn't hit anything.  it's likely a donut
                             * double distance = (vTargetAsteroid - shipOrientationBlock.GetPosition()).Length();
                             * Echo("Distance=" + distance.ToString());
                             * mineMoveForward(fTargetMiningmps,fAbortmps);
                             * if (distance < 5)
                             * {
                             *  vExpectedExit = vTargetAsteroid - shipOrientationBlock.GetPosition();
                             *  current_state = 31;
                             *  ResetMotion();
                             * }
                             */
                            //                                    setMode(MODE_ATTENTION);
                            // or we made a whole there..
                        }
                    }
                    // ELSE no scan available.. just wait
                    else
                    {
                        Echo("No Camera SCAN!");
                    }

                    // check sensors for one in front of us
                    aSensors = activeSensors();
                    bool bFoundAsteroid = false;
                    for (int i = 0; i < aSensors.Count; i++)
                    {
                        IMySensorBlock s = aSensors[i] as IMySensorBlock;
//                                StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
//                                Echo(aSensors[i].CustomName + " ACTIVE!");

                        List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                        s.DetectedEntities(lmyDEI);
                        if (AsteroidProcessLDEI(lmyDEI))
                        {
                            bFoundAsteroid = true;
                        }
                    }
                    if (bFoundAsteroid)
                    {
                        current_state = 31;
                    }
                }
                else
                {
                    Echo("Aiming");
                }
                // BUG: Gets stuck in state if nothing hit.. (ie, donut)
            }
            break;

            case 130:
            {         // far travel to asteroid. use doTravelMovement
                Echo("Far travel to asteroid");

                doTravelMovement(vTargetAsteroid, 45, 135, 140, true);
                break;
            }

            case 135:
            {        // we have 'arrived' from far travel
                // wait for motion to slow
                if (velocityShip < fAsteroidApproachMps)
                {
                    current_state = 120;
                }
                ResetMotion();
                break;
            }

            case 140:
            {
                ResetTravelMovement();
                ResetMotion();
                calcCollisionAvoid(vInitialAsteroidContact);
                current_state = 150;
                break;
            }

            case 150:
            {
                doTravelMovement(vAvoid, 5.0f, 130, 160);
                break;
            }

            case 160:
            {
                ResetTravelMovement();
                ResetMotion();
                setMode(MODE_ATTENTION);
                break;
            }

            case 300:
            {
                // we have exitted the asteroid.  Prepare for another run or to go dock
                Echo("Exitted!");
                ResetMotion();
                sleepAllSensors();

                if (maxDeltaV < fMiningMinThrust || cargopcent > cargopctlowwater)
                {
                    setMode(MODE_DOCKING);
                }
                else
                {
                    vLastAsteroidExit = shipOrientationBlock.GetPosition();
                    //                           dist = (vLastExit - vInitialExit).Length();
                    if (!bValidInitialAsteroidExit)
                    {
                        vInitialAsteroidExit      = vLastAsteroidExit;
                        bValidInitialAsteroidExit = true;
                    }
                    setMode(MODE_SEARCHORIENT);
                    // prepare for another run.
                }
                break;
            }

            case 400:
            {         // init camera scan for asteroids
                ResetMotion();
                turnEjectorsOn();
                sleepAllSensors();
                miningElapsedMs = 0;

                // initialize cameras
                miningfrontScanner  = new QuadrantCameraScanner(this, cameraForwardList, 5000);
                miningbackScanner   = new QuadrantCameraScanner(this, cameraBackwardList, 5000);
                miningleftScanner   = new QuadrantCameraScanner(this, cameraLeftList, 5000);
                miningrightScanner  = new QuadrantCameraScanner(this, cameraRightList, 5000);
                miningtopScanner    = new QuadrantCameraScanner(this, cameraUpList, 5000);
                miningbottomScanner = new QuadrantCameraScanner(this, cameraDownList, 5000);

                current_state = 410;
                break;
            }

            case 410:
            {
                StatusLog("Long Range Scan", textPanelReport);
                if (miningfrontScanner == null)         // in case we reload/compile in this state..
                {
                    current_state = 400;
                }
                bWantMedium      = true;
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                // use for timeout...

                // do camera scans

                if (miningfrontScanner.DoScans())
                {
                    AsteroidProcessLDEI(miningfrontScanner.myLDEI);
                }
                if (miningbackScanner.DoScans())
                {
                    AsteroidProcessLDEI(miningbackScanner.myLDEI);
                }
                if (miningleftScanner.DoScans())
                {
                    AsteroidProcessLDEI(miningleftScanner.myLDEI);
                }
                if (miningrightScanner.DoScans())
                {
                    AsteroidProcessLDEI(miningrightScanner.myLDEI);
                }
                if (miningtopScanner.DoScans())
                {
                    AsteroidProcessLDEI(miningtopScanner.myLDEI);
                }
                if (miningbottomScanner.DoScans())
                {
                    AsteroidProcessLDEI(miningbottomScanner.myLDEI);
                }

                // take the first one found.
                // TODO: do all search and then choose 'best' (closest?)
                // TODO: Aim at the hit position and not 'CENTER' for more randomized start on asteroid
                // TODO: once we find asteroid(s) choose how to find ore intelligently and not just randomly

                /*
                 * if (bValidAsteroid)
                 *  current_state = 120;
                 */
                string s = "";
                s += "Front: ";
                if (miningfrontScanner.DoneScanning())
                {
                    s += "DONE!";
                }
                else
                {
                    s += miningfrontScanner.SCAN_DISTANCE.ToString("0") + " meters";
                }
                s += " " + miningfrontScanner.myLDEI.Count + " asteroids";
                s += "\n";

                s += "Back: ";
                if (miningbackScanner.DoneScanning())
                {
                    s += "DONE!";
                }
                else
                {
                    s += miningbackScanner.SCAN_DISTANCE.ToString("0") + " meters";
                }
                s += " " + miningbackScanner.myLDEI.Count + " asteroids";
                s += "\n";

                s += "Left: ";
                if (miningleftScanner.DoneScanning())
                {
                    s += "DONE!";
                }
                else
                {
                    s += miningleftScanner.SCAN_DISTANCE.ToString("0") + " meters";
                }
                s += " " + miningleftScanner.myLDEI.Count + " asteroids";
                s += "\n";

                s += "Right: ";
                if (miningrightScanner.DoneScanning())
                {
                    s += "DONE!";
                }
                else
                {
                    s += miningrightScanner.SCAN_DISTANCE.ToString("0") + " meters";
                }
                s += " " + miningrightScanner.myLDEI.Count + " asteroids";
                s += "\n";

                s += "Top: ";
                if (miningtopScanner.DoneScanning())
                {
                    s += "DONE!";
                }
                else
                {
                    s += miningtopScanner.SCAN_DISTANCE.ToString("0") + " meters";
                }
                s += " " + miningtopScanner.myLDEI.Count + " asteroids";
                s += "\n";

                s += "Bottom: ";
                if (miningbottomScanner.DoneScanning())
                {
                    s += "DONE!";
                }
                else
                {
                    s += miningbottomScanner.SCAN_DISTANCE.ToString("0") + " meters";
                }
                s += " " + miningbottomScanner.myLDEI.Count + " asteroids";
                s += "\n";

                if (AsteroidFindNearest() < 0)
                {
                    s += "No Known Asteroid";
                }
                else
                {
                    s += "FOUND at least one asteroid!";
                }

                StatusLog(s, textPanelReport);
                Echo(s);


                if (
                    miningfrontScanner.DoneScanning() &&
                    miningbackScanner.DoneScanning() &&
                    miningleftScanner.DoneScanning() &&
                    miningrightScanner.DoneScanning() &&
                    miningtopScanner.DoneScanning() &&
                    miningbottomScanner.DoneScanning()
                    )
                {
                    //                            long asteroidID = -1;
                    if (HasDrills())
                    {
                        miningAsteroidID = AsteroidFindNearest();
                        if (miningAsteroidID < 0)
                        {
                            // all scans have run and didn't find asteroid..
                            setMode(MODE_ATTENTION);
                        }
                        else
                        {
                            bValidAsteroid        = true;
                            vTargetAsteroid       = AsteroidGetPosition(miningAsteroidID);
                            vExpectedAsteroidExit = vTargetAsteroid - shipOrientationBlock.GetPosition();
                            vExpectedAsteroidExit.Normalize();

                            current_state = 120;
                        }
                    }
                    else
                    {         // if no drills, we are done.
                        setMode(MODE_IDLE);
                    }
                }
                break;
            }

            case 425:
            {
                // aim at asteroid location
                if (!bValidExit)
                {
                    setMode(MODE_ATTENTION);
                }
                {
                    bWantFast = true;
                    if (GyroMain("forward", vExpectedAsteroidExit - shipOrientationBlock.GetPosition(), shipOrientationBlock))
                    {
                        // we are aimed
                        current_state = 120;
                    }
                }
                break;
            }
            }
        }
コード例 #18
0
        public void Main(string argument, UpdateType updateSource)
        {
            mySensor.DetectedEntities(detectedEntityInfos);

            text.WritePublicText("");
            foreach (var item in detectedEntityInfos)
            {
                WriteText(item.Name + ":" + item.Position.ToString() + "\n");
            }

            if (detectedEntityInfos.Count == 0 || Me.CustomData == StaticCmd)
            {
                NowTargetEntityInfoID = 0;
                Settledlist           = new List <long>();
                getTarget             = false;
                var vector = mySensor.GetPosition() + (mySensor.WorldMatrix.Forward * 500);
                mySensor.CustomData = vector.X + "," + vector.Y + "," + vector.Z;
            }
            else
            {
                if (Me.CustomData == ChageCmd)
                {
                    Me.CustomData = "";

                    foreach (var item in detectedEntityInfos)
                    {
                        if (!Settledlist.Contains(item.EntityId))
                        {
                            NowTargetEntityInfoID = item.EntityId;

                            Settledlist.Add(item.EntityId);
                            mySensor.CustomData = item.Position.X + "," + item.Position.Y + "," + item.Position.Z;
                            return;
                        }
                    }

                    NowTargetEntityInfoID = new long();
                    Settledlist           = new List <long>();
                    getTarget             = false;
                    var vector = mySensor.GetPosition() + (mySensor.WorldMatrix.Forward * 500);
                    mySensor.CustomData = vector.X + "," + vector.Y + "," + vector.Z;
                    return;
                }

                foreach (var item in detectedEntityInfos)
                {
                    if (item.EntityId == NowTargetEntityInfoID)
                    {
                        mySensor.CustomData = item.Position.X + "," + item.Position.Y + "," + item.Position.Z;
                        return;
                    }
                }

                NowTargetEntityInfoID = new long();
                Settledlist           = new List <long>();
                getTarget             = false;
                var vectorDi = mySensor.GetPosition() + (mySensor.WorldMatrix.Forward * 500);
                mySensor.CustomData = vectorDi.X + "," + vectorDi.Y + "," + vectorDi.Z;
                return;
            }
        }
コード例 #19
0
        private void FindTargetsList()
        {
            Echo("Sensor Range: " + sensor.MaxRange);
            //Echo("Running");
            sensor.DetectedEntities(entities);

            foreach (MyDetectedEntityInfo entity in entities)
            {
                Target t = new Target(entity, Me.GetPosition());
                targets.Add(t);
            }

            Echo("Entities: " + entities.Count);
            Echo("Screens: " + screens.Count);
            Echo("Used Screens: " + usedScreens.Count);

            targets.Sort((x, y) => x.Distance.CompareTo(y.Distance));

            foreach (IMyTextPanel screen in usedScreens)
            {
                using (var frame = screen.DrawFrame()) {
                    float point = 10;
                    foreach (Target target in targets)
                    {
                        Echo("start");
                        Echo("sensor: " + sensor.ToString());

                        Vector2 pos2       = new Vector2(256, 256);
                        Vector2 size       = new Vector2(512, 512);
                        var     background = MySprite.CreateSprite("SquareSimple", pos2, size);
                        background.Color = Color.Black;
                        frame.Add(background);

                        if (point == 10)
                        {
                            target.Selected = true;
                        }

                        StringBuilder textEnt = new StringBuilder();
                        if (target.Selected)
                        {
                            textEnt.Append("*| ");
                        }
                        else
                        {
                            textEnt.Append(" | ");
                        }
                        textEnt.Append(target.Info.Name + " " + target.Distance.ToString("0.00") + "m");

                        //string textEnt = target.Info.Name + ": " + target.Distance.ToString("0.00");
                        Echo("textent: " + textEnt);
                        Vector2 pos  = new Vector2(10, point);
                        var     text = MySprite.CreateText(textEnt.ToString(), "Monospace", Color.White, 0.8f, TextAlignment.LEFT);

                        if (target.Info.Relationship.Equals(MyRelationsBetweenPlayerAndBlock.Enemies))
                        {
                            text.Color = Color.Red;
                        }

                        text.Position = pos;
                        frame.Add(text);
                        point += 25;
                    }
                }
            }

            targets.Clear();
        }
コード例 #20
0
        void doModeSearchShift()
        {
            bool bLocalFoundAsteroid = false;

            if (sensorsList.Count < 2)
            {
                StatusLog(OurName + ":" + moduleName + " Search Shift: Not Enough Sensors!", textLongStatus, true);
                setMode(MODE_ATTENTION);
                return;
            }
            List <IMySensorBlock> aSensors = null;
            IMySensorBlock        sb;
            IMySensorBlock        sb2;

            sb  = sensorsList[0];
            sb2 = sensorsList[1];
            switch (current_state)
            {
            case 0:
                ResetMotion();
                sleepAllSensors();
                sensorsList[0].DetectAsteroids = true;
                sensorsList[1].DetectAsteroids = true;
                setSensorShip(sb, 0, 0, 0, 0, 45, 0);
                current_state  = 10;
                shiftElapsedMs = 0;
                break;

            case 10:     // delay for sensors
                shiftElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (shiftElapsedMs < 1)
                {
                    return;
                }
                if (velocityShip < 0.2f)
                {
                    return;
                }

                aSensors            = activeSensors();
                bLocalFoundAsteroid = false;
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);

                    for (int j = 0; j < lmyDEI.Count; j++)
                    {
                        if (lmyDEI[j].Type == MyDetectedEntityType.Asteroid)
                        {
                            addDetectedEntity(lmyDEI[j]);
                            bLocalFoundAsteroid    = true;
                            currentAst.EntityId    = lmyDEI[j].EntityId;
                            currentAst.BoundingBox = lmyDEI[j].BoundingBox;
                            if (!bValidAsteroid)
                            {
                                bValidAsteroid  = true;
                                vTargetAsteroid = lmyDEI[j].Position;
                            }
                        }
                    }
                }
                if (bLocalFoundAsteroid)
                {
                    current_state = 20;
                }
                else
                {
                    current_state = 100;
                }
                break;
            }
        }
コード例 #21
0
        void doModeExitingAsteroid()
        {
            List <IMySensorBlock> aSensors = null;

            /*
             * IMySensorBlock sb;
             */

            StatusLog("clear", textPanelReport);
            StatusLog(moduleName + ":Exiting!", textPanelReport);
            Echo("Exiting: current_state=" + current_state.ToString());
            MyShipMass myMass;

            myMass = ((IMyShipController)shipOrientationBlock).CalculateShipMass();
            double effectiveMass = myMass.PhysicalMass;

            double maxThrust = calculateMaxThrust(thrustForwardList);

            Echo("effectiveMass=" + effectiveMass.ToString("N0"));
            Echo("maxThrust=" + maxThrust.ToString("N0"));

            double maxDeltaV = (maxThrust) / effectiveMass;

            Echo("maxDeltaV=" + maxDeltaV.ToString("0.00"));
            Echo("Cargo=" + cargopcent.ToString() + "%");

            Echo("velocity=" + velocityShip.ToString("0.00"));
            Echo("#Sensors=" + sensorsList.Count);
            Echo("width=" + shipDim.WidthInMeters().ToString("0.0"));
            Echo("height=" + shipDim.HeightInMeters().ToString("0.0"));
            Echo("length=" + shipDim.LengthInMeters().ToString("0.0"));

//            IMyTextPanel txtPanel = getTextBlock("Sensor Report");
//            StatusLog("clear", txtPanel);

            /*
             * 0 - Master Init
             * 10 - Init sensors, turn drills on
             * 11 - await sensor set
             * Turn by quarters.  Left, then Left until about 180
             * 20 - turn around until aimed
             * and them move forward until exittedasteroid ->40
             *
             * 40 when out, call for pickup
             *
             */

            switch (current_state)
            {
            case 0:     //0 - Master Init
                current_state = 10;
                ResetMotion();
                //                    turnDrillsOff();
                turnEjectorsOn();
                if (sensorsList.Count < 2)
                {
                    StatusLog(OurName + ":" + moduleName + " Find Ore: Not Enough Sensors!", textLongStatus, true);
                    setMode(MODE_ATTENTION);
                }
                break;

            case 10:    //10 - Init sensors,
                sleepAllSensors();
                setSensorShip(sensorsList[0], 2, 2, 2, 2, 15, 15);
                //                    setSensorShip(sensorsList[1], 50, 50, 50, 50, 50, 0);
                miningElapsedMs = 0;
                current_state   = 11;
                break;

            case 11:    //11 - await sensor set
                miningElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
                if (miningElapsedMs < dSensorSettleWaitMS)
                {
                    return;
                }
                current_state = 20;
                break;

            case 20:     //20 - turn around until aimed ->30
            {
                bWantFast = true;
                turnDrillsOn();

                // we want to turn on our horizontal axis as that should be the 'wide' one.
                bool   bAimed   = false;
                double yawangle = -999;
                Echo("vTarget=" + Vector3DToString(vLastAsteroidContact));
                yawangle = CalculateYaw(vLastAsteroidContact, shipOrientationBlock);
                Echo("yawangle=" + yawangle.ToString());
                double aYawAngle = Math.Abs(yawangle);
                bAimed = aYawAngle < .05;


                // turn slower when >180 since we are in tunnel and drills are cutting a path
                float maxYPR = GyroControl.MaxYPR;
                Echo("maxYPR=" + maxYPR.ToString("0.00"));
                if (aYawAngle > 1.0)
                {
                    maxYPR = maxYPR / 3;
                }

                DoRotate(yawangle, "Yaw", maxYPR, 0.33f);

                /*
                 * //minAngleRad = 0.1f;
                 * bAimed=GyroMain("backward", vExpectedExit, shipOrientationBlock);
                 *
                 * // minAngleRad = 0.01f;
                 * // GyroMain("backward", vExpectedExit, shipOrientationBlock);
                 */
                if (bAimed)
                {
                    current_state = 30;
                    //mineMoveForward(fTargetMiningmps,fAbortmps);
                }
            }
            break;

            case 30:
            {
                bool bAimed = false;
                bAimed = GyroMain("backward", vExpectedAsteroidExit, shipOrientationBlock);
                if (bAimed)
                {
                    bWantMedium = true;
                    mineMoveForward(fTargetMiningMps, fMiningAbortMps);
                }
                else
                {
                    bWantFast = true;
                }

                bool bLocalAsteroid = false;
                aSensors = activeSensors();
                for (int i = 0; i < aSensors.Count; i++)
                {
                    IMySensorBlock s = aSensors[i] as IMySensorBlock;
//                            StatusLog(aSensors[i].CustomName + " ACTIVE!", txtPanel);
                    Echo(aSensors[i].CustomName + " ACTIVE!");

                    List <MyDetectedEntityInfo> lmyDEI = new List <MyDetectedEntityInfo>();
                    s.DetectedEntities(lmyDEI);
                    if (AsteroidProcessLDEI(lmyDEI))
                    {
                        bLocalAsteroid = true;
                    }
                }
                if (!bLocalAsteroid)
                {
                    ResetMotion();
                    //                            turnDrillsOff();
                    sleepAllSensors();
                    current_state = 40;
                }
                break;
            }

            case 40:    //40 when out, call for pickup
            {
                turnDrillsOff();
                // we should probably give hint to docking as to WHY we want to dock..
                setMode(MODE_DOCKING);
            }
            break;

            default:
            {
                Echo("UNKNOWN STATE!");
                break;
            }
            }
        }