private bool doAction_AttackEnemy()
            {
                if (!isDroneCombatReady())
                {
                    return(false);
                }
                Vector3D EnemyPos = new Vector3D(0, 0, 0);

                RemoteControl.GetNearestPlayer(out EnemyPos);
                if (EnemyPos.Equals(new Vector3D(0, 0, 0)))
                {
                    return(false);
                }
                if (!isTargetInOperationArea(EnemyPos))
                {
                    return(false);
                }
                setupAndStartDrone(EnemyPos, "Enemy", false);

                return(true);
            }
Beispiel #2
0
        void Main()
        {
            //check if current RC is damaged, look for a replacement
            if (_currentControl == null || !_currentControl.IsFunctional)
            {
                _currentControl = _controllers.FirstOrDefault(c => c.IsFunctional);
            }

            if (_currentControl == null)
            {
                return; //no controls left :(
            }
            //Check Player Distance From Origin
            _currentControl.ClearWaypoints();
            Vector3D currentPos = _currentControl.GetPosition();
            Vector3D closestPlayer;

            _currentControl.GetNearestPlayer(out closestPlayer);

            double playerDistanceOrigin = Vector3D.DistanceSquared(closestPlayer, _origin);
            double playerDistanceDrone  = Vector3D.DistanceSquared(currentPos, closestPlayer);

            if (playerDistanceDrone < BREAKAWAY_DISTANCE * BREAKAWAY_DISTANCE || playerDistanceOrigin < PATROL_RADIUS * PATROL_RADIUS)
            {
                //Chase Player
                _currentControl.AddWaypoint(closestPlayer, "Player");

                //update guns
                if (USE_STATIC_GUNS)
                {
                    if (playerDistanceDrone <= WEAPON_ENGAGE_DIST * WEAPON_ENGAGE_DIST)
                    {
                        Vector3D playerDir = closestPlayer - currentPos;
                        playerDir.Normalize();
                        double dot = Vector3D.Dot(_currentControl.WorldMatrix.Forward, playerDir);
                        //check if player is inside our target cone
                        if (dot > _weaponAngle)
                        {
                            StartShooting();
                            _shooting = true;
                        }
                        else
                        {
                            StopShooting();
                            _shooting = false;
                        }
                    }
                    else if (playerDistanceDrone > WEAPON_DISENGAGE_DIST * WEAPON_DISENGAGE_DIST && _shooting)
                    {
                        StopShooting();
                        _shooting = false;
                    }
                }
            }
            else
            {
                //Go To Origin
                _currentControl.AddWaypoint(_origin, "Origin");
                if (_shooting && USE_STATIC_GUNS)
                {
                    _shooting = false;
                    StopShooting();
                }
            }

            _currentControl.SetAutoPilotEnabled(true);
        }
Beispiel #3
0
        void Main(string args)
        {
            debug("BEGIN");
            if (args.Trim().Length > 0)
            {
                GROUP_TAG = args;
            }

            debug("Groupname: " + GROUP_TAG);

            List <IMyTerminalBlock> Blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(Blocks, (x => x.IsWorking && x.CubeGrid.Equals(Me.CubeGrid)));
            if (Blocks.Count > 0)
            {
                IMyRemoteControl RC = Blocks[0] as IMyRemoteControl;
                debug("Using Remotecontrol: " + RC.CustomName);
                List <IMyBlockGroup> Groups = new List <IMyBlockGroup>();
                GridTerminalSystem.GetBlockGroups(Groups);
                Blocks.Clear();
                for (int i = 0; i < Groups.Count; i++)
                {
                    if (Groups[i].Name.Contains(GROUP_TAG))
                    {
                        for (int j = 0; j < Groups[i].Blocks.Count; j++)
                        {
                            if (
                                ((Groups[i].Blocks[j] is IMyRadioAntenna) || (Groups[i].Blocks[j] is IMyBeacon)) &&
                                Groups[i].Blocks[j].IsFunctional &&
                                Groups[i].Blocks[j].CubeGrid.Equals(Me.CubeGrid)
                                )
                            {
                                Blocks.Add(Groups[i].Blocks[j]);
                            }
                        }
                    }
                }

                Vector3D PlayerPos;
                Vector3D PbPos = RC.GetPosition();
                RC.GetNearestPlayer(out PlayerPos);
                debug("Nearest Player: (" + String.Format("{0:0}", Vector3D.Distance(PlayerPos, PbPos)) + " m)" + PlayerPos.ToString());
                debug("Functional Antennas/Beacons: " + Blocks.Count.ToString());
                for (int i = 0; i < Blocks.Count; i++)
                {
                    IMyTerminalBlock RA = Blocks[i] as IMyTerminalBlock;
                    int    d_pos        = RA.CustomName.IndexOf("DEBUG");
                    string d_name       = RA.CustomName.Trim();
                    if (d_pos > -1)
                    {
                        d_name = RA.CustomName.Substring(0, d_pos).Trim();
                        RA.SetCustomName(d_name);
                    }

                    double radius = 0.0;
                    if (RA is IMyRadioAntenna)
                    {
                        radius = Convert.ToDouble((RA as IMyRadioAntenna).Radius);
                    }
                    else if (RA is IMyBeacon)
                    {
                        radius = Convert.ToDouble((RA as IMyBeacon).Radius);
                    }

                    double cutOffPoint = radius * CUT_OFF_FACTOR;
                    double distance    = Vector3D.Distance(PlayerPos, PbPos);
                    string info        = "% (radius: " + String.Format("{0:0}", radius) + " m; cut-off point: " + String.Format("{0:0}", cutOffPoint) + " m; distance: " + String.Format("{0:0}", distance) + " m)";
                    if (distance < cutOffPoint)
                    {
                        info = "Enable: " + info;
                        //  RA.ApplyAction("OnOff_On");
                    }
                    else
                    {
                        info = "Disable '" + info;
                        //  RA.ApplyAction("OnOff_Off");
                    }
                    Echo(info.Replace("%", RA.CustomName));

                    if (DEBUG)
                    {
                        d_pos  = RA.CustomName.IndexOf("DEBUG");
                        d_name = RA.CustomName.Trim();
                        if (d_pos > -1)
                        {
                            d_name = RA.CustomName.Substring(0, d_pos).Trim();
                        }
                        RA.SetCustomName(d_name + " DEBUG: " + info.Replace("%", ""));
                    }
                }
            }
            else
            {
                debug("Remote Control not found.");
            }
            debug("END");
        }