public bool ArrivedAtWaypoint() { if (NewAutoPilot.InGravity() && NewAutoPilot.MyAltitude < NewAutoPilot.IdealPlanetAltitude) { if (NewAutoPilot.DistanceToWaypointAtMyAltitude == -1 || NewAutoPilot.DistanceToOffsetAtMyAltitude == -1) { return(false); } if (NewAutoPilot.DistanceToWaypointAtMyAltitude < NewAutoPilot.WaypointTolerance && NewAutoPilot.DistanceToOffsetAtMyAltitude < NewAutoPilot.WaypointTolerance) { Logger.MsgDebug("Offset Compensation", DebugTypeEnum.General); return(true); } return(false); } if (NewAutoPilot.DistanceToCurrentWaypoint < NewAutoPilot.WaypointTolerance) { return(true); } /* * if (NewAutoPilot.IsAvoidingCollision() && !_previouslyAvoidingCollision) { * * _previouslyAvoidingCollision = true; * return false; * * } * * if (_previouslyAvoidingCollision && !NewAutoPilot.IsAvoidingCollision()) { * * _previouslyAvoidingCollision = false; * return true; * * * } */ return(false); }
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); }
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()); } } }
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(); } } }
private bool UseEngageCollisionEvasion() { return(NewAutoPilot.InGravity() ? this.StrikeEngageUseCollisionEvasionPlanet : this.StrikeEngageUseCollisionEvasionSpace); }