Beispiel #1
0
        private void CreateAndMoveToOffset()
        {
            if (NewAutoPilot.InGravity())
            {
                if (NewAutoPilot.Targeting.Target.CurrentAltitude() > NewAutoPilot.OffsetPlanetMinTargetAltitude)
                {
                    //Logger.MsgDebug("Target Is High", DebugTypeEnum.General);
                    NewAutoPilot.SetRandomOffset(VectorHelper.RandomDistance(NewAutoPilot.OffsetPlanetMinTargetAltitude, NewAutoPilot.OffsetPlanetMaxTargetAltitude), 0, NewAutoPilot.Targeting.Target.GetEntity());
                }
                else
                {
                    //Logger.MsgDebug("Target Is Low", DebugTypeEnum.General);
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity());
                }
            }
            else
            {
                //Logger.MsgDebug("Target Is Space", DebugTypeEnum.General);
                NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity());
            }

            LastOffsetCalculation = MyAPIGateway.Session.GameDateTime;
            NewAutoPilot.ActivateAutoPilot(AutoPilotType.RivalAI, NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward, RemoteControl.GetPosition(), true, true, true);
        }
Beispiel #2
0
        public override void MainBehavior()
        {
            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                Mode = BehaviorMode.Retreat;
                NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), false, true, true);
            }

            //Init
            if (Mode == BehaviorMode.Init)
            {
                if (!NewAutoPilot.Targeting.HasTarget())
                {
                    Mode = BehaviorMode.WaitingForTarget;
                }
                else
                {
                    Mode = BehaviorMode.WaitAtWaypoint;
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
            }

            //Waiting For Target
            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (NewAutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!NewAutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                var timeSpan = MyAPIGateway.Session.GameDateTime - this.HorseflyWaypointAbandonTime;
                //Logger.MsgDebug("Distance To Waypoint: " + NewAutoPilot.DistanceToCurrentWaypoint.ToString(), DebugTypeEnum.General);

                if (ArrivedAtWaypoint())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.None, NewAutoPilotMode.None, Vector3D.Zero);
                }
                else if (timeSpan.TotalSeconds >= this.HorseflyWaypointAbandonTimeTrigger)
                {
                    Logger.MsgDebug("Horsefly Timeout, Getting New Offset", DebugTypeEnum.General);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                }
                else if (NewAutoPilot.IsWaypointThroughVelocityCollision())
                {
                    Logger.MsgDebug("Horsefly Velocity Through Collision, Getting New Offset", DebugTypeEnum.General);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                }
            }

            //WaitAtWaypoint
            if (Mode == BehaviorMode.WaitAtWaypoint)
            {
                var timeSpan = MyAPIGateway.Session.GameDateTime - this.HorseflyWaypointWaitTime;

                if (timeSpan.TotalSeconds >= this.HorseflyWaypointWaitTimeTrigger)
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    NewAutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Beispiel #3
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), false, false, true);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!NewAutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (NewAutoPilot.CurrentMode != NewAutoPilotMode.None)
                {
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.None, NewAutoPilotMode.None, Vector3D.Zero);
                }

                if (NewAutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!NewAutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                NewAutoPilot.ActivateAutoPilot(AutoPilotType.None, NewAutoPilotMode.None, Vector3D.Zero);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                bool inRange = false;

                if (!NewAutoPilot.InGravity() && NewAutoPilot.DistanceToInitialWaypoint < this.FighterEngageDistanceSpace)
                {
                    inRange = true;
                }

                if (NewAutoPilot.InGravity() && NewAutoPilot.DistanceToInitialWaypoint < this.FighterEngageDistancePlanet)
                {
                    inRange = true;
                }

                if (inRange)
                {
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.RivalAI, NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.Strafe, Vector3D.Zero, true, false, false);
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    BehaviorTriggerA = true;
                }
            }

            //Engage
            if (Mode == BehaviorMode.EngageTarget)
            {
                bool outRange = false;

                if (!NewAutoPilot.InGravity() && NewAutoPilot.DistanceToInitialWaypoint > this.FighterDisengageDistanceSpace)
                {
                    outRange = true;
                }

                if (NewAutoPilot.InGravity() && NewAutoPilot.DistanceToInitialWaypoint > this.FighterDisengageDistancePlanet)
                {
                    outRange = true;
                }

                if (outRange)
                {
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    BehaviorTriggerB = true;
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    NewAutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Beispiel #4
0
        public override void MainBehavior()
        {
            bool skipEngageCheck = false;


            //Init
            if (Mode == BehaviorMode.Init)
            {
                if (!NewAutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    CreateAndMoveToOffset();
                    skipEngageCheck = true;
                }
            }

            //Waiting For Target
            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (NewAutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    CreateAndMoveToOffset();
                    skipEngageCheck = true;
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!NewAutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
            }

            //Approach Target
            if (Mode == BehaviorMode.ApproachTarget && !skipEngageCheck)
            {
                double distance = NewAutoPilot.InGravity() ? this.StrikeBeginPlanetAttackRunDistance : this.StrikeBeginSpaceAttackRunDistance;

                if (NewAutoPilot.DistanceToCurrentWaypoint <= distance && !NewAutoPilot.IsAvoidingCollision())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.RivalAI, NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward, RemoteControl.GetPosition(), true, false, StrikeEngageUseSafePlanetPathing);
                    skipEngageCheck = true;
                }

                if (skipEngageCheck == false)
                {
                    var timeSpan = MyAPIGateway.Session.GameDateTime - LastOffsetCalculation;

                    if (timeSpan.TotalSeconds >= StrikeOffsetRecalculationTime)
                    {
                        skipEngageCheck = true;
                        CreateAndMoveToOffset();
                    }

                    if (TargetIsHigh && NewAutoPilot.Targeting.Target.CurrentAltitude() < NewAutoPilot.OffsetPlanetMinTargetAltitude)
                    {
                        TargetIsHigh = false;
                        CreateAndMoveToOffset();
                    }
                    else if (!TargetIsHigh && NewAutoPilot.Targeting.Target.CurrentAltitude() > NewAutoPilot.OffsetPlanetMinTargetAltitude)
                    {
                        TargetIsHigh = true;
                        CreateAndMoveToOffset();
                    }
                }
            }

            //Engage Target
            if (Mode == BehaviorMode.EngageTarget && !skipEngageCheck)
            {
                Logger.MsgDebug("Strike: " + StrikeBreakawayDistance.ToString() + " - " + NewAutoPilot.DistanceToInitialWaypoint, DebugTypeEnum.General);
                if (NewAutoPilot.DistanceToInitialWaypoint <= StrikeBreakawayDistance || (NewAutoPilot.UseVelocityCollisionEvasion && NewAutoPilot.Collision.VelocityResult.CollisionImminent()))
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    CreateAndMoveToOffset();
                }
            }
        }