private void LoadStrafeData(MySpaceStrafeData strafeData)
        {
            m_width  = strafeData.Width;
            m_height = strafeData.Height;
            m_depth  = strafeData.Depth;

            Debug.Assert(m_width >= 0 && m_height >= 0 && m_depth >= 0);

            m_avoidCollisions          = strafeData.AvoidCollisions;
            m_speedLimit               = strafeData.SpeedLimit;
            m_rotateToTarget           = strafeData.RotateToPlayer;
            PlayerYAxisOffset          = strafeData.PlayerYAxisOffset;
            WaypointThresholdDistance  = strafeData.WaypointThresholdDistance;
            m_waypointDelayMs          = strafeData.WaypointDelayMsMin;
            m_waypointDelayMsRange     = strafeData.WaypointDelayMsMax - strafeData.WaypointDelayMsMin;
            m_waypointMaxTime          = strafeData.WaypointMaxTime;
            m_lostTimeMs               = strafeData.LostTimeMs;
            m_playerTargetDistance     = strafeData.PlayerTargetDistance;
            m_maxManeuverDistanceSq    = strafeData.MaxManeuverDistance * strafeData.MaxManeuverDistance;
            m_minStrafeDistanceSq      = strafeData.MinStrafeDistance * strafeData.MinStrafeDistance;
            m_kamikazeBehavior         = strafeData.UseKamikazeBehavior;
            m_canBeDisabled            = strafeData.CanBeDisabled;
            m_staticWeaponryUsageSq    = strafeData.StaticWeaponryUsage * strafeData.StaticWeaponryUsage;
            m_useStaticWeaponry        = strafeData.UseStaticWeaponry;
            m_kamikazeBehaviorDistance = strafeData.KamikazeBehaviorDistance;
            m_alternativeBehavior      = strafeData.AlternativeBehavior;
            m_useTools         = strafeData.UseTools;
            m_toolsUsageSq     = strafeData.ToolsUsage * strafeData.ToolsUsage;
            m_rotationLimitSq  = Math.Max(m_toolsUsageSq, Math.Max(m_staticWeaponryUsageSq, m_maxManeuverDistanceSq));
            m_useHoverMechanic = strafeData.UsePlanetHover;
            m_hoverMin         = strafeData.PlanetHoverMin;
            m_hoverMax         = strafeData.PlanetHoverMax;
        }
 public static void SavePreset(string key, MySpaceStrafeData preset)
 {
     if (presets.ContainsKey(key))
         presets.Add(key, preset);
     else
         presets[key] = preset;
 }
 public static void SavePreset(string key, MySpaceStrafeData preset)
 {
     if (presets.ContainsKey(key))
     {
         presets.Add(key, preset);
     }
     else
     {
         presets[key] = preset;
     }
 }
        public MyDroneStrafeBehaviour(MyRemoteControl remoteControl, MySpaceStrafeData strafeData, bool activate, List<MyUserControllableGun> weapons, List<MyFunctionalBlock> tools, Vector3D firstWaypoint)
        {
            m_remoteControl = remoteControl;
            ReturnPosition = m_remoteControl.PositionComp.GetPosition();

            LoadStrafeData(strafeData);

            m_weapons = weapons;
            m_tools = tools;
            MyPlayer player = m_remoteControl.GetNearestPlayer();
            m_target = player != null ? player.Character as MyEntity : null;
            m_lastTargetUpdate = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_lastWeaponUpdate = m_lastTargetUpdate;
            m_waypointReachedTimeMs = m_lastTargetUpdate;
            m_firstWaypoint = firstWaypoint;

            NeedUpdate = activate;
        }
        public MyDroneStrafeBehaviour(MyRemoteControl remoteControl, MySpaceStrafeData strafeData, bool activate, List <MyUserControllableGun> weapons, List <MyFunctionalBlock> tools, Vector3D firstWaypoint)
        {
            m_remoteControl = remoteControl;
            ReturnPosition  = m_remoteControl.PositionComp.GetPosition();

            LoadStrafeData(strafeData);

            m_weapons = weapons;
            m_tools   = tools;
            MyPlayer player = m_remoteControl.GetNearestPlayer();

            m_target                = player != null ? player.Character as MyEntity : null;
            m_lastTargetUpdate      = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_lastWeaponUpdate      = m_lastTargetUpdate;
            m_waypointReachedTimeMs = m_lastTargetUpdate;
            m_firstWaypoint         = firstWaypoint;

            NeedUpdate = activate;
        }
        public MyDroneStrafeBehaviour(MyRemoteControl remoteControl, string presetName, bool activate, List <MyEntity> waypoints, List <DroneTarget> targets, int playerPriority, TargetPrioritization prioritizationStyle, float maxPlayerDistance, bool cycleWaypoints)
        {
            m_remoteControl  = remoteControl;
            m_returnPosition = m_remoteControl.PositionComp.GetPosition();

            MySpaceStrafeData strafeData = MySpaceStrafeDataStatic.LoadPreset(presetName);

            m_currentPreset = presetName;
            LoadStrafeData(strafeData);

            m_lastTargetUpdate      = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_lastWeaponUpdate      = m_lastTargetUpdate;
            m_waypointReachedTimeMs = m_lastTargetUpdate;
            m_forcedWaypoints       = waypoints != null ? waypoints : new List <MyEntity>();
            m_targetsList           = targets != null ? targets : new List <DroneTarget>();
            PlayerPriority          = playerPriority;
            m_prioritizationStyle   = prioritizationStyle;
            MaxPlayerDistance       = maxPlayerDistance;
            m_cycleWaypoints        = cycleWaypoints;

            NeedUpdate = activate;
        }
        public void Load(MyObjectBuilder_AutomaticBehaviour objectBuilder, MyRemoteControl remoteControl)
        {
            MyObjectBuilder_DroneStrafeBehaviour builder = objectBuilder as MyObjectBuilder_DroneStrafeBehaviour;

            if (builder != null)
            {
                m_remoteControl = remoteControl;

                MySpaceStrafeData strafeData = MySpaceStrafeDataStatic.LoadPreset(builder.CurrentPreset);
                m_currentPreset = builder.CurrentPreset;
                LoadStrafeData(strafeData);

                m_lastTargetUpdate      = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                m_lastWeaponUpdate      = m_lastTargetUpdate;
                m_waypointReachedTimeMs = m_lastTargetUpdate;

                m_forcedWaypoints   = new List <MyEntity>();
                m_loadWaypointList  = builder.WaypointList;
                m_targetsList       = new List <DroneTarget>();
                m_loadTargetList    = builder.TargetList;
                m_currentTarget     = null;
                m_loadCurrentTarget = builder.CurrentTarget;

                m_returnPosition              = builder.ReturnPosition;
                PlayerPriority                = builder.PlayerPriority;
                m_prioritizationStyle         = builder.PrioritizationStyle;
                MaxPlayerDistance             = builder.MaxPlayerDistance;
                m_cycleWaypoints              = builder.CycleWaypoints;
                m_alternativebehaviorSwitched = builder.AlternativebehaviorSwitched;
                CollisionAvoidance            = builder.CollisionAvoidance;
                m_canSkipWaypoint             = builder.CanSkipWaypoint;

                NeedUpdate     = builder.NeedUpdate;
                IsActive       = builder.IsActive;
                m_loadEntities = true;
            }
        }
        //checks if it has usable weapons and use them if necessary or ram player if weapons are unusable
        private void WeaponsUpdate(float distSq)
        {
            bool suicide = m_canBeDisabled;

            m_shooting = false;
            bool hasNonStationaryWeapons = false;

            if (m_weapons != null && m_weapons.Count > 0)
            {
                foreach (var weapon in m_weapons)
                {
                    if (!weapon.Enabled && weapon.IsFunctional)
                    {
                        suicide = false;
                        if (!weapon.IsStationary())
                        {
                            hasNonStationaryWeapons = true;
                        }
                        continue;
                    }

                    MyGunStatusEnum status;
                    if (weapon.CanOperate() && weapon.CanShoot(out status) && status == MyGunStatusEnum.OK)
                    {
                        suicide = false;
                        if (m_useStaticWeaponry && weapon.IsStationary())
                        {
                            if (m_remoteControl.TargettingAimDelta <= 0.05f && distSq < m_staticWeaponryUsageSq && distSq >= 0 && m_canRotateToTarget)
                            {
                                weapon.SetShooting(true);
                                m_shooting = true;
                            }
                            else
                            {
                                weapon.SetShooting(false);
                            }
                        }
                        if (!weapon.IsStationary())
                        {
                            hasNonStationaryWeapons = true;
                        }
                    }
                }
            }
            if (m_tools != null && m_tools.Count > 0)
            {
                foreach (var tool in m_tools)
                {
                    if (tool.IsFunctional)
                    {
                        suicide = false;
                        if (m_useTools)
                        {
                            if (distSq < m_toolsUsageSq && distSq >= 0 && m_canRotateToTarget)
                            {
                                tool.Enabled = true;
                            }
                            else
                            {
                                tool.Enabled = false;
                            }
                        }
                    }
                }
            }
            m_operational = !suicide;
            if (suicide)
            {
                m_rotateToTarget = true;
                m_weapons.Clear();
                m_tools.Clear();
                if (m_remoteControl.HasWaypoints())
                {
                    m_remoteControl.ClearWaypoints();
                }
                NeedUpdate = true;
                m_forcedWaypoints.Clear();
            }
            if (!hasNonStationaryWeapons && !m_alternativebehaviorSwitched)
            {
                m_rotateToTarget = true;
                if (m_alternativeBehavior.Length > 0)
                {
                    MySpaceStrafeData strafeData = MySpaceStrafeDataStatic.LoadPreset(m_alternativeBehavior);
                    LoadStrafeData(strafeData);
                    m_currentPreset = m_alternativeBehavior;
                }
                m_alternativebehaviorSwitched = true;
            }
        }
        private void LoadStrafeData(MySpaceStrafeData strafeData)
        {
            m_width = strafeData.Width;
            m_height = strafeData.Height;
            m_depth = strafeData.Depth;

            Debug.Assert(m_width >= 0 && m_height >= 0 && m_depth >= 0);

            m_avoidCollisions = strafeData.AvoidCollisions;
            m_speedLimit = strafeData.SpeedLimit;
            RotateToPlayer = strafeData.RotateToPlayer;
            PlayerYAxisOffset = strafeData.PlayerYAxisOffset;
            WaypointThresholdDistance = strafeData.WaypointThresholdDistance;
            m_waypointDelayMs = strafeData.WaypointDelayMsMin;
            m_waypointDelayMsRange = strafeData.WaypointDelayMsMax - strafeData.WaypointDelayMsMin;
            m_waypointMaxTime = strafeData.WaypointMaxTime;
            m_lostTimeMs = strafeData.LostTimeMs;
            m_playerTargetDistance = strafeData.PlayerTargetDistance;
            m_maxManeuverDistanceSq = strafeData.MaxManeuverDistance * strafeData.MaxManeuverDistance;
            m_minStrafeDistanceSq = strafeData.MinStrafeDistance * strafeData.MinStrafeDistance;
            m_kamikazeBehavior = strafeData.UseKamikazeBehavior;
            m_staticWeaponryUsageSq = strafeData.StaticWeaponryUsage * strafeData.StaticWeaponryUsage;
            m_useStaticWeaponry = strafeData.UseStaticWeaponry;
            m_kamikazeBehaviorDistance = strafeData.KamikazeBehaviorDistance;
            m_alternativeBehavior = strafeData.AlternativeBehavior;
            m_useTools = strafeData.UseTools;
            m_toolsUsageSq = strafeData.ToolsUsage * strafeData.ToolsUsage;
        }
Beispiel #10
0
 public static void SavePreset(string key, MySpaceStrafeData preset)
 {
     presets[key] = preset;
 }