public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            if (m_done)
            {
                return;
            }
            //SimObject me = dmView.AllObjects[m_thisID];
            //LocationValue myLocation = me.Location;
            SimObject     track         = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;

            m_absoluteLoiterPattern = m_relativeLoiterPattern.ToAbsolute(trackLocation);


            if (ShouldTrack(serverConnection, dmView))
            {
                serverConnection.SendMoveObjectRequest(m_thisID, trackLocation, 1);

                m_trackTarget = true;
            }
            else
            {
                if (m_trackTarget)
                {
                    StartLoiter(serverConnection, dmView);
                    m_trackTarget = false;
                }
                ContinueLoiter(serverConnection, dmView);
            }
        }
 public TrackTargetBehavior(String thisID, String targetID, WaypointSequence relativeLoiterPattern)
 {
     m_thisID   = thisID;
     m_targetID = targetID;
     m_relativeLoiterPattern = relativeLoiterPattern;
     m_absoluteLoiterPattern = null;
     m_destWaypoint          = null;
     m_trackTarget           = false;
 }
Exemple #3
0
        //public LoiterBehavior(String thisID, String destID, WaypointSequence loiterPattern)
        //{
        //    m_thisID = thisID;
        //    m_destID = destID;
        //    m_destX = 0;
        //    m_destY = 0;
        //    m_loiterPattern = loiterPattern;
        //}

        public LoiterBehavior(String thisID, LocationValue refLoc, WaypointSequence relativeLoiterPattern)
        {
            m_thisID = thisID;
            //m_destID = String.Empty;
            m_referenceLocation     = refLoc;
            m_relativeLoiterPattern = relativeLoiterPattern;
            m_absoluteLoiterPattern = relativeLoiterPattern.ToAbsolute(refLoc);
            m_destWaypoint          = null;
        }
        void StartLoiter(DDDServerConnection serverConnection, DMView dmView)
        {
            SimObject     me            = dmView.AllObjects[m_thisID];
            LocationValue myLocation    = me.Location;
            SimObject     track         = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;

            m_absoluteLoiterPattern = m_relativeLoiterPattern.ToAbsolute(trackLocation);
            m_destWaypoint          = m_absoluteLoiterPattern.GetWaypointClosestTo(myLocation);
            m_relativeLoiterPattern.NextWaypointIndex    = m_absoluteLoiterPattern.NextWaypointIndex;
            m_relativeLoiterPattern.CurrentWaypointIndex = m_absoluteLoiterPattern.CurrentWaypointIndex;
            serverConnection.SendMoveObjectRequest(m_thisID, m_destWaypoint.Location, 1);
        }
 public EngageTargetBehavior(String thisID, String targetID, WaypointSequence relativeLoiterPattern, Boolean returnAfter)
 {
     m_engagementState       = EngagementState.Tracking;
     m_thisID                = thisID;
     m_targetID              = targetID;
     m_relativeLoiterPattern = relativeLoiterPattern;
     m_absoluteLoiterPattern = null;
     m_destWaypoint          = null;
     m_attackEndTime         = 0;
     m_attackInProcess       = false;
     m_attackIsWeapon        = false;
     m_originalLocation      = null;
     m_returnAfter           = returnAfter;
 }
Exemple #6
0
        public WaypointSequence ToAbsolute(LocationValue referenceLoc)
        {
            WaypointSequence abs = new WaypointSequence();
            Waypoint         newWP;

            foreach (Waypoint wp in this)
            {
                newWP = new Waypoint(wp);

                newWP.Location.X = referenceLoc.X + wp.Location.X;
                newWP.Location.Y = referenceLoc.Y + wp.Location.Y;
                newWP.Location.Z = referenceLoc.Z + wp.Location.Z;

                abs.Add(newWP);
            }
            abs.m_nextIndex = this.m_nextIndex;
            return(abs);
        }
Exemple #7
0
        public WaypointSequence ToRelative(LocationValue referenceLoc)
        {
            WaypointSequence rel = new WaypointSequence();

            Waypoint newWP;

            foreach (Waypoint wp in this)
            {
                newWP = new Waypoint(wp);

                newWP.Location.X = wp.Location.X - referenceLoc.X;
                newWP.Location.Y = wp.Location.Y - referenceLoc.Y;
                newWP.Location.Z = wp.Location.Z - referenceLoc.Z;

                rel.Add(newWP);
            }
            rel.m_nextIndex = this.m_nextIndex;
            return(rel);
        }
        bool ShouldTrack(DDDServerConnection serverConnection, DMView dmView)
        {
            SimObject     me            = dmView.AllObjects[m_thisID];
            LocationValue myLocation    = me.Location;
            SimObject     track         = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;

            WaypointSequence absoluteLoiterPattern = m_relativeLoiterPattern.ToAbsolute(trackLocation);
            Waypoint         destWaypoint          = absoluteLoiterPattern.GetWaypointClosestTo(myLocation);

            Double myDis   = BehaviorHelper.Distance(myLocation, trackLocation);
            Double destDis = BehaviorHelper.Distance(destWaypoint.Location, trackLocation);

            if (myDis > (destDis * 2))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            if (m_done)
            {
                return;
            }
            SimObject     me            = dmView.AllObjects[m_thisID];
            LocationValue myLocation    = me.Location;
            SimObject     track         = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;

            m_absoluteLoiterPattern = m_relativeLoiterPattern.ToAbsolute(trackLocation);


            switch (m_engagementState)
            {
            case EngagementState.Tracking:
                if (ShouldTrack(serverConnection, dmView))
                {
                    serverConnection.SendMoveObjectRequest(m_thisID, trackLocation, 1);
                }
                else
                {
                    m_engagementState = EngagementState.Attacking;
                    StartLoiter(serverConnection, dmView);
                }
                break;

            case EngagementState.Attacking:
                ContinueLoiter(serverConnection, dmView);
                if (!m_attackInProcess)     // start the attack
                {
                    // start with weapons
                    if (me.DockedWeapons.Count > 0)
                    {
                        m_attackWeaponID = me.DockedWeapons[0];
                        serverConnection.SendWeaponLaunchRequest(m_thisID, m_attackWeaponID, m_targetID);
                        m_attackEndTime   = dmView.SimTime + 12000;   // give a two minute time window to start, AttackUpdate will modify this
                        m_attackInProcess = true;
                        m_attackIsWeapon  = true;
                    }
                    else     // use native capabilities
                    {
                        // figure out capability/vulnerability match up
                        String cap = DetermineCapability(me.CapabilityList, track.VulnerabilityList);
                        if (cap != String.Empty)
                        {
                            serverConnection.SendAttackObjectRequest(m_thisID, m_targetID, cap);
                            m_attackInProcess = true;
                            m_attackIsWeapon  = false;
                            m_attackEndTime   = dmView.SimTime + 12000;
                        }
                        else     //  I don't have the right capabilities, finish up
                        {
                            ResetAttack();
                            if (m_returnAfter)
                            {
                                m_engagementState = EngagementState.Returning;
                                m_dddServer.SendMoveObjectRequest(m_thisID, m_originalLocation, 1);
                            }
                            else
                            {
                                m_done = true;
                            }
                        }
                    }
                }
                else     // check to see if the attack was succesful
                {
                    // if we are still in attack mode 2 seconds after attack was supposed to end
                    // start another attack
                    if (dmView.SimTime > m_attackEndTime + 2000)
                    {
                        ResetAttack();
                    }
                }
                break;

            case EngagementState.Returning:
                if (BehaviorHelper.Distance(myLocation, m_originalLocation) < 1)
                {
                    m_done = true;
                }
                break;
            }
        }