示例#1
0
 public void Update(DDDServerConnection serverConnection, DMView dmView)
 {
     if (DateTime.Now >= m_endTime)
     {
         m_done = true;
     }
 }
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {
            m_dmView = dmView;
            //Console.Out.WriteLine(String.Format("MoveWithAvoidanceBehavior.Start(){0}",m_thisID));
            LogWriter.Write(m_dmView.DecisionMakerID + "_" + m_thisID, dmView.SimTime, String.Format("MoveWithAvoidanceBehavior.Start,{0},{1}", m_destLocation.ToXML(), m_throttle));
            m_wasBlocked = false;
            
            
            SimObject me = dmView.AllObjects[m_thisID];
            //SimObject dest = dmView.AllObjects[m_destID];

            LocationValue myLocation = me.Location;
            //LocationValue destLocation = dest.Location;


            if (BehaviorHelper.LocationIsEqual(myLocation, m_destLocation))
            {
                m_done = true;
                return;
            }

            if (!IsBlocked2())
            {
                m_wasBlocked = false;
                serverConnection.SendMoveObjectRequest(m_thisID, me.Owner, m_destLocation, m_throttle);
            }
            else
            {
                m_wasBlocked = true;
            }

        }
示例#3
0
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            SimObject me = dmView.AllObjects[m_thisID];
            SimActiveRegion zone = dmView.ActiveRegions[m_zoneID];

            LocationValue otherLocation = null;
            Polygon2D azPoly = new Polygon2D();
            foreach (PolygonValue.PolygonPoint p in zone.Shape.points)
            {
                azPoly.AddVertex(new Vec2D(p.X, p.Y));
            }
            bool clear = true;

            foreach (String id in dmView.AllObjects.Keys)
            {
                if (id == m_thisID)
                {
                    continue;
                }
                otherLocation = dmView.AllObjects[id].Location;
                if (Polygon2D.IsPointInside(azPoly, new Vec2D(otherLocation)))
                {
                    clear = false;
                    break;
                }

            }

            if (clear)
            {
                m_done = true;
            }
        }
示例#4
0
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            SimObject me = dmView.AllObjects[m_thisID];
            SimObject dest = dmView.AllObjects[m_destID];

            LocationValue clearLoc = dest.Location;
            LocationValue otherLocation = null;

            bool clear = true;

            foreach (String id in dmView.AllObjects.Keys)
            {
                if (id == m_destID || id == m_thisID)
                {
                    continue;
                }
                otherLocation = dmView.AllObjects[id].Location;
                if (ObjectMath.IsWithinRange(100, clearLoc, otherLocation))
                {
                    clear = false;
                    break;
                }
            }

            if (clear)
            {
                m_done = true;
            }
        }
示例#5
0
        public void Update(DDDServerConnection serverConnection,DMView dmView)
        {
            if (m_behaviorQueue.Count >= 1)
            {
                //Console.Out.WriteLine(String.Format("ObjectControlAgent.Update() {0}",simObject.ID));
                if (m_currentBehavior != m_behaviorQueue[0])
                {
                    
                    m_currentBehavior = m_behaviorQueue[0];
                    //Console.Out.WriteLine(String.Format("ObjectControlAgent.Update() starting {0} for {1}",m_currentBehavior.GetName(), simObject.ID));
                    m_currentBehavior.Start(serverConnection,dmView);
                }
                m_currentBehavior.Update(serverConnection, dmView);
                if (m_currentBehavior.IsDone(serverConnection, dmView))
                {
                    //Console.Out.WriteLine(String.Format("ObjectControlAgent.Update(){0} is done for {1}", m_currentBehavior.GetName(), simObject.ID));
                    m_behaviorQueue.Remove(m_currentBehavior);
                    m_currentBehavior = null;
                }

            }
            else
            {
                m_currentBehavior = null;
            }



        }
示例#6
0
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            if (m_done)
            {
                return;
            }
            SimObject me = dmView.AllObjects[m_thisID];
            SimObject dest = dmView.AllObjects[m_destID];

            LocationValue myLocation = me.Location;
            LocationValue destLocation = dest.Location;
            VelocityValue myVelocity = me.Velocity;


            if (ObjectMath.IsWithinRange(0.1, myLocation, destLocation))
            {
                m_done = true;
                return;
            }

            if (myVelocity.VX == 0 && myVelocity.VY == 0 && myVelocity.VZ == 0)
            {
                serverConnection.SendMoveObjectRequest(m_thisID, destLocation, 1);
            }
        }
示例#7
0
 public void Start(DDDServerConnection serverConnection, DMView dmView)
 {
     m_dmView = dmView;
     m_dddServer = serverConnection;
     
     m_done = false;
     m_endTime = DateTime.Now + new TimeSpan(0, 0, 0, 0, m_delayMS);
 }
示例#8
0
 public MainWindow()
 {
     InitializeComponent();
     m_loadedRuns = null;
     m_ddd = null;
     m_currentRun = null;
     m_currentRunFinishTime = 0;
     m_externalCommandProcess = null;
     m_dddProcess = null;
 }
示例#9
0
文件: MainForm.cs 项目: wshanshan/DDD
        public MainForm(String hostname, int port)
        {
            InitializeComponent();
            _hostname = hostname;
            _port = port;

            _connection = new DDDServerConnection();
            

        }
示例#10
0
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {
            m_dmView = dmView;
            m_dddServer = serverConnection;
            

            m_dddServer.SendStateChange(m_thisID, m_newState);
            
            m_done = true;
        }
示例#11
0
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {
            m_dmView = dmView;

            SimObject me = dmView.AllObjects[m_thisID];
            LocationValue myLocation = me.Location;
            m_destWaypoint = m_absoluteLoiterPattern.GetWaypointClosestTo(myLocation);
            serverConnection.SendMoveObjectRequest(m_thisID, m_destWaypoint.Location, 1);

        }
示例#12
0
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {
            m_dmView = dmView;
            m_dddServer = serverConnection;

            SimObject ob = dmView.AllObjects[m_thisID];

            m_dddServer.SendTransferObjectRequest(ob.ID, ob.Owner, m_newOwner, ob.State);
            
            m_done = true;
        }
示例#13
0
        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;

            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();
                        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();
                }
            }   
            
        }
示例#14
0
        public ServerConnectDialog(ref DDDServerConnection serverConnection)
        {
            try
            {
                ServerHostname = System.Net.Dns.GetHostName();
            }
            catch
            {

            }
            InitializeComponent();
            m_serverConnection = serverConnection;
        }
示例#15
0
        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);
        }
示例#16
0
 void ContinueLoiter(DDDServerConnection serverConnection, DMView dmView)
 {
     SimObject me = dmView.AllObjects[m_thisID];
     LocationValue myLocation = me.Location;
     SimObject track = dmView.AllObjects[m_targetID];
     LocationValue trackLocation = track.Location;
     if (BehaviorHelper.LocationIsEqual(myLocation, m_destWaypoint.Location))
     {
         m_destWaypoint = m_absoluteLoiterPattern.GetNextWaypoint();
         m_relativeLoiterPattern.NextWaypointIndex = m_absoluteLoiterPattern.NextWaypointIndex;
         m_relativeLoiterPattern.CurrentWaypointIndex = m_absoluteLoiterPattern.CurrentWaypointIndex;
         serverConnection.SendMoveObjectRequest(m_thisID, m_destWaypoint.Location, 1);
     }
     
 }
示例#17
0
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {
            SimObject me = dmView.AllObjects[m_thisID];
            SimObject dest = dmView.AllObjects[m_destID];

            LocationValue myLocation = me.Location;
            LocationValue destLocation = dest.Location;

            if (ObjectMath.IsWithinRange(0.1, myLocation, destLocation))
            {
                m_done = true;
                return;
            }

            serverConnection.SendMoveObjectRequest(m_thisID, destLocation, 1);


        }
示例#18
0
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            if (m_done)
            {
                return;
            }
            SimObject me = dmView.AllObjects[m_thisID];
            LocationValue myLocation = me.Location;


            if (BehaviorHelper.LocationIsEqual(myLocation, m_destWaypoint.Location))
            {
                m_destWaypoint = m_absoluteLoiterPattern.GetNextWaypoint();
                serverConnection.SendMoveObjectRequest(m_thisID, m_destWaypoint.Location, 1);
            }

        


        }
示例#19
0
        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;
            }
        }
示例#20
0
 public bool IsDone(DDDServerConnection serverConnection, DMView dmView)
 {
     return m_done;
 }
示例#21
0
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {
            m_dmView = dmView;

            SimObject me = dmView.AllObjects[m_thisID];
            LocationValue myLocation = me.Location;
            SimObject track = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;


            m_trackTarget = ShouldTrack(serverConnection,dmView);


            if (m_trackTarget)
            {
                serverConnection.SendMoveObjectRequest(m_thisID, trackLocation, 1);
            }
            else
            {
                StartLoiter(serverConnection,dmView);
            }
            

        }
示例#22
0
 public void Update(DDDServerConnection serverConnection, DMView dmView)
 {
 }
示例#23
0
        public void Start(DDDServerConnection serverConnection, DMView dmView)
        {

        }
示例#24
0
 void StopDDD()
 {
     m_ddd.Disconnect();
     m_ddd = null;
     if (Properties.Settings.Default.RunDDDServer)
     {
         if (m_dddProcess != null)
         {
             m_dddProcess.Kill();
         }
         m_dddProcess = null;
     }
 }
示例#25
0
文件: Form1.cs 项目: wshanshan/DDD
        private bool DisconnectCurrentDDDSession(bool promptUser)
        {
            if (promptUser)
            {
                if (MessageBox.Show("A connection with the DDD currently exists, do you want to terminate this connection?", "Terminate DDD Connection", MessageBoxButtons.YesNo) == DialogResult.No)
                    return false;
            }
            if (_connection == null)
                return true;
            lock (_connection)
            {
                try
                {
                    _connection.Disconnect();
                }
                finally
                {
                    _connection = null;
                }
            }

            return true;
        }
示例#26
0
        void StartDDD()
        {

            if (Properties.Settings.Default.RunDDDServer)
            {
                System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();
                procInfo.FileName = dddExecutablePathTextBox.Text;
                procInfo.WorkingDirectory = Path.GetDirectoryName(dddExecutablePathTextBox.Text);
                procInfo.Arguments = Properties.Settings.Default.DDDPort.ToString();
                procInfo.CreateNoWindow = true;
                procInfo.UseShellExecute = true;
                m_dddProcess = System.Diagnostics.Process.Start(procInfo);

                Thread.Sleep(1000);
            }
            m_ddd = new DDDServerConnection();
            m_ddd.ConnectToServer(Properties.Settings.Default.DDDHostname, Properties.Settings.Default.DDDPort);
            m_ddd.DDDClientPath = Properties.Settings.Default.DDDClientPath;
            if (!m_ddd.ReadSimModel())
            {
                MessageBox.Show(String.Format("Unable to read sim model"));
                return;
            }
            
        }
示例#27
0
        /*** END ***/

        public DDDAdapter()
        {
            _eventsQueue = new OrderedEventsList();
            _dddConnection = new DDDServerConnection();
            _revealedObjects = new Dictionary<string, SeamateObject>();
            _unrevealedObjects = new Dictionary<string, SeamateObject>();
            _scheduledAttacks = new Dictionary<int, List<ScheduledAttack>>();
            _seaLanes = new Dictionary<string, PolygonValue>();
            _entryPoints = new Dictionary<string, PolygonValue>();
            _objectOwnershipMaps = new Dictionary<string, List<string>>();
            _reverseOwnershipMaps = new Dictionary<string, string>();
            _speciesPossibleStates = new Dictionary<string, Dictionary<string, AttributeCollectionValue>>();
        }
示例#28
0
文件: Form1.cs 项目: wshanshan/DDD
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            _dddHostname = textBoxHostname.Text;
            if (Int32.TryParse(textBoxPort.Text, out _dddPort) == false)
            {
                return;
            }
            try
            {
                if (_connection != null)
                {
                    lock (_connection)
                    {
                        if (_connection.IsConnected())
                        {
                            if (!DisconnectCurrentDDDSession(true))
                            {
                                throw new Exception("Unable to disconnect from DDD Server");
                            }
                        }
                    }
                }

                _connection = new DDDServerConnection();
                string remoteSimulationModel = String.Format(@"\\{0}\DDDClient\SimulationModel.xml", _dddHostname);
                
                lock (_connection)
                {
                    bool simModelResult = _connection.ReadSimModel(remoteSimulationModel);

                    if (!simModelResult)
                    {
                        MessageBox.Show(String.Format("Error in DDD Connection: Failed to read the simulation model at '{0}', please try again.", remoteSimulationModel), "DDD Connection Error");

                        //AD: Here we could also ask the user to point to a local copy of the sim model, then re-ReadSimModel.

                        return;
                    }
                    if (!_connection.ConnectToServer(_dddHostname, _dddPort))
                    {
                        throw new Exception("Connection to DDD failed");
                    }

                    //need Login as DM?  no?
                    _connection.RequestPlayers();
                    List<string> decisionMakers = new List<string>();
                    while (decisionMakers.Count == 0)
                    {
                        decisionMakers = _connection.Players;
                        _connection.ProcessEvents();
                    }
                    string selectedDM = decisionMakers[0]; ;
                    _connection.LoginPlayer(selectedDM, "OBSERVER");
                    _connection.GetDMView(selectedDM); //initialize view...
                    //

                    _connection.AddEventCallback("TimeTick", new DDDServerConnection.ProcessSimulationEvent(TimeTick));
                    _connection.AddEventCallback("ExternalApp_SimStart", new DDDServerConnection.ProcessSimulationEvent(ExternalApp_SimStart));
                    _connection.AddEventCallback("ExternalApp_SimStop", new DDDServerConnection.ProcessSimulationEvent(ExternalApp_SimStop));
                    _connection.AddEventCallback("GameSpeed", new DDDServerConnection.ProcessSimulationEvent(GameSpeed));

                }
                try
                {
                    //just in case
                    _dddLoopThread.Abort();
                    _dddLoopThread = null;
                }
                catch (Exception ex)
                { }

                _dddLoopThread = new Thread(new ThreadStart(DDDLoop));
                _dddLoopThread.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error connecting to DDD Server:\r\n" + ex.Message);
                return;
            }

            UpdateDDDConnectionStatus("CONNECTED");
            ((Button)sender).Enabled = false;
            groupBox2.Enabled = true;
            groupBox3.Enabled = true;
        }
示例#29
0
 public bool IsDone(DDDServerConnection serverConnection, DMView dmView)
 {
     //Console.Out.WriteLine(String.Format("MoveWithAvoidanceBehavior.IsDone() {0} {1}", m_thisID,m_done));
     return m_done;
 }
示例#30
0
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            //Console.Out.WriteLine(String.Format("MoveWithAvoidanceBehavior.Update() {0}", m_thisID));
            if (m_done)
            {
                return;
            }
            SimObject me = dmView.AllObjects[m_thisID];
            //SimObject dest = dmView.AllObjects[m_destID];

            LocationValue myLocation = me.Location;
            
            VelocityValue myVelocity = me.Velocity;


            if (ObjectMath.IsWithinRange(0.1, myLocation, m_destLocation))
            {
                m_done = true;
                return;
            }

            if (!IsBlocked2())
            {
                if (m_wasBlocked)
                {
                    m_wasBlocked = false;
                    serverConnection.SendMoveObjectRequest(m_thisID, me.Owner, m_destLocation, m_throttle);
                }
                else if (myVelocity.VX == 0 && myVelocity.VY == 0 && myVelocity.VZ == 0)
                {
                    serverConnection.SendMoveObjectRequest(m_thisID, me.Owner, m_destLocation, m_throttle);
                }
            }
            else
            {
                m_wasBlocked = true;
                serverConnection.SendMoveObjectRequest(m_thisID, me.Owner,myLocation, 0);
            }

            
        }