Exemplo n.º 1
0
        public virtual ProximityResult DetectProximity(IEntity other)
        {
            ProximityResult res = new ProximityResult();
            res.Bearing = MatrixPoint.OrientationBetween(this.Centre, other.Centre);
            res.Distance = MatrixPoint.DistanceBetween(this.Centre, other.Centre);
            res.Collision = false;
            res.Entity = other;

            List<Line> myOutline = this.GetPerimeter();
            List<Line> otherOutline = other.GetPerimeter();

            int myCount = myOutline.Count;
            int otherCount = otherOutline.Count;

            for (int i = 0; i < myCount; i++)
            {
                for (int j = 0; j < otherCount; j++)
                {
                    if (myOutline[i].Intersects(otherOutline[j]))
                    {
                        res.Collision = true;
                        return res;
                    }
                }
            }
            return res;
        }
Exemplo n.º 2
0
        private void SeekTarget(ProximityResult prox)
        {
            IMissionTarget target = Mission.GetNextUncompletedTarget();
            Angle relativeOrientation = this.Orientation + prox.Bearing;

            if (Math.Round(relativeOrientation.Radians, 1) != Math.Round(0.0, 1))
            {
                if (relativeOrientation.Radians > Math.PI)
                {
                    nextRotate = 0.05;
                }
                else
                {
                    nextRotate = -0.05;
                }
            }

            if (prox.Distance > 200)
            {
                nextMove = 3;
            }
            else if (prox.Distance > 150)
            {
                nextMove = 3;
            }
            else if (prox.Distance > 30)
            {
                if (tickCount % 5 == 0 && target.Objective == MissionObjective.Attack)
                {
                    new Missile(parent, this.Orientation, this.gunTip.Point1, 1000);
                    target.Complete = target.Target.Expired;
                }
                nextMove = 3;
            }
            else
            {
                switch (target.Objective)
                {
                    case MissionObjective.Visit:
                        target.Complete = true;
                        break;
                    case MissionObjective.Collect:
                        CollectTarget(target.Target);
                        target.Complete = true;
                        break;
                    case MissionObjective.LayMine:
                        target.Complete = true;
                        break;
                    case MissionObjective.Attack:
                        FireMissile();
                        target.Complete = target.Target.Expired;
                        break;
                    default:
                        target.Complete = true;
                        break;
                }
            }
        }
Exemplo n.º 3
0
        private void AvoidTarget(ProximityResult prox)
        {
            // collision avoidance checks
            if (prox.Distance < 100)
            {
                if (prox.GetHeading(this.Orientation) == Heading.Ahead)
                {
                    if ((tickCount % 5 == 0) && (prox.Entity is PlayerVehicle)) // if it's the player, might as well have a pop
                    {
                        FireMissile();
                    }
                    nextRotate = -0.1;
                    nextMove = 0;
                }
                else if (prox.GetHeading(this.Orientation) == Heading.FineAheadLeft)
                {
                    if ((tickCount % 10 == 0) && (prox.Entity is PlayerVehicle)) // if it's the player, might as well have a pop
                    {
                        FireMissile();
                    }

                    nextRotate = -0.3;
                    nextMove = 2;
                }
                else if (prox.GetHeading(this.Orientation) == Heading.FineAheadRight)
                {
                    if ((tickCount % 10 == 0) && (prox.Entity is PlayerVehicle)) // if it's the player, might as well have a pop
                    {
                        FireMissile();
                    }

                    nextRotate = 0.3;
                    nextMove = 2;
                }
                else if (prox.GetHeading(this.Orientation) == Heading.AheadLeft)
                {
                    nextRotate = -0.2;
                    nextMove = 3;
                }
                else if (prox.GetHeading(this.Orientation) == Heading.AheadRight)
                {
                    nextRotate = 0.2;
                    nextMove = 3;
                }
                else if (prox.GetHeading(this.Orientation) == Heading.Right && prox.Distance < 40)
                {
                    nextRotate = 0.08;
                    nextMove = 2;
                }
                else if (prox.GetHeading(this.Orientation) == Heading.Left && prox.Distance < 40)
                {
                    nextRotate = -0.08;
                    nextMove = 2;
                }
                else
                {
                    nextMove = 3;
                }
            }
        }
Exemplo n.º 4
0
 private bool IsAhead(ProximityResult prox)
 {
     Heading relativeHeading = prox.GetHeading(this.Orientation);
     switch (relativeHeading)
     {
         case Heading.Ahead:
         case Heading.AheadLeft:
         case Heading.AheadRight:
         case Heading.FineAheadLeft:
         case Heading.FineAheadRight:
             return true;
         default:
             return false;
     }
 }
Exemplo n.º 5
0
        public override ProximityResult DetectProximity(IEntity other)
        {
            ProximityResult res = base.DetectProximity(other);

            if (!(other is Explosion) && res.Collision)
            {
                // we're dead!
                this.Destroy();
                other.Destroy();
                return res;
            }

            if (Mission == null || Mission.Complete)
            {
                return res;
            }

            IEntity currentTarget = Mission.GetNextUncompletedTarget().Target;

            if (res.Entity != currentTarget)
            {
                if (nearestObject == null)
                {
                    nearestObject = res;
                }
                else if (res.Distance < nearestObject.Distance && IsAhead(res) && !(res.Entity is Missile) && !(res.Entity is WayPoint) && !(res.Entity is Explosion))
                {
                    nearestObject = res;
                }
                else if (res.Entity == nearestObject.Entity && res.Distance > nearestObject.Distance)
                {
                    // we're moving away from it so set it to null
                    nearestObject = null;
                }
            }

            return res;
        }