Esempio n. 1
0
        public SimulationEvent MoveDoneReceived(SimulationEvent e, SimulationModelInfo model, SimulationEvent theTick)
        { 
            //Should receieve a MoveDone event, and create a new move event and send
            //it to the Queue Manager with time ticks + 1.

            SimulationEvent ee = SimulationEventFactory.BuildEvent(ref model, "MoveObject");

            ee.eventType = "MoveObject";

            DataValue myDV = new IntegerValue();
            myDV = e["ObjectID"];
            ee["ObjectID"] = myDV;

            myDV = new LocationValue();
            ((LocationValue)(myDV)).X = 150;
            ((LocationValue)(myDV)).Y = 150;
            ((LocationValue)(myDV)).Z = 50;
            ee["DestinationLocation"] = myDV;

            myDV = new DoubleValue();
            ((DoubleValue)(myDV)).value = .5;
            ee["Throttle"] = myDV;

            myDV = new IntegerValue();
            ((IntegerValue)(myDV)).value = 
                ((IntegerValue)theTick.parameters["Time"]).value + 1000;
            ee["Time"] = myDV;

            return ee;



        }
Esempio n. 2
0
        public void AddEvent(int? time, SimulationEvent theEvent)
        {
            if (EventQueue.ContainsKey(time))
            { //Another entry with this key exists, add onto list (done below)
            }
            else 
            {//No entries exist with this key, create new list, stick it into Queue
                List<SimulationEvent> tempList = new List<SimulationEvent>();
                EventQueue[time] = tempList;
            }

            EventQueue[time].Add(theEvent);
        }
Esempio n. 3
0
        //public WaypointRoute GenerateRoute(LocationValue currentLocation, LocationValue destination, List<WaypointRoute> routes)
        //{
        //    WaypointRoute result = null;

        //    LocationGraph graph = LocationGraph.GenerateRouteGraph("start",currentLocation, "end",destination, routes);

        //    result = graph.GenerateWaypointRoute("start","end");
        //    return result;
        //}

        internal void ViewProInitializeObject(SimulationEvent ev)
        {
            String    id = ((StringValue)ev["ObjectID"]).value;
            SimObject ob;

            if (AllObjects.ContainsKey(id))
            {
                ob = AllObjects[id];
            }
            else
            {
                ob = new SimObject(id);
            }
            ob.Owner    = ((StringValue)ev["OwnerID"]).value;
            ob.Location = ((LocationValue)ev["Location"]);
            ob.IconName = ((StringValue)ev["IconName"]).value;

            ob.IsWeapon = ((BooleanValue)ev["IsWeapon"]).value;
            if (ob.Owner == m_decisionMakerID)
            {
                m_myObjects[ob.ID] = ob;
            }
            else
            {
                if (m_myObjects.ContainsKey(id))
                {
                    m_myObjects.Remove(id);
                }
            }


            m_allObjects[ob.ID] = ob;

            if (PlayerAgent != null)
            {
                PlayerAgent.ViewProInitializeObject(ev);
            }
        }
Esempio n. 4
0
        public void AuthenticationRequest(SimulationEvent e)
        {
            Authenticator.LoadUserFile();
            string terminalID = ((StringValue)e["TerminalID"]).value;

            if (currentlyLoggedInUsers == maxNumberOfUsers)
            {
                SendAuthenticationResponse(terminalID, "The server has reached its limit for number of users attached to the DDD.", false);
                return;
            }

            string username = ((StringValue)e["Username"]).value;
            string password = ((StringValue)e["Password"]).value;

            if (Authenticator.Authenticate(username, password))
            {
                SendAuthenticationResponse(terminalID, "Authentication successful!", true);
            }
            else
            {
                SendAuthenticationResponse(terminalID, "Invalid username and/or password", false);
            }
        }
Esempio n. 5
0
 private void loadEventsButton_Click(object sender, EventArgs e)
 {
     if (ofd2.ShowDialog() == DialogResult.OK)
     {
         StreamReader    re    = File.OpenText(ofd2.FileName);
         string          input = null;
         SimulationEvent ev    = null;
         eventsListBox.Items.Clear();
         while ((input = re.ReadLine()) != null)
         {
             ev = SimulationEventFactory.XMLDeserialize(input);
             if (SimulationEventFactory.ValidateEvent(ref simModel, ev))
             {
                 eventsListBox.Items.Add(new EventListBoxItem(ev));
             }
             else
             {
                 MessageBox.Show("event file contains invalid event: \"" + input + "\"");
             }
         }
         re.Close();
     }
 }
Esempio n. 6
0
        public void AttackSucceeded(SimulationEvent ev)
        {
            String attacker = ((StringValue)ev["ObjectID"]).value;
            String target   = ((StringValue)ev["TargetID"]).value;
            String newState = ((StringValue)ev["NewState"]).value;

            if (m_attackInProcess)
            {
                if (target == m_targetID)
                {
                    ResetAttack();
                    if (m_returnAfter)
                    {
                        m_engagementState = EngagementState.Returning;
                        m_dddServer.SendMoveObjectRequest(m_thisID, m_originalLocation, 1);
                    }
                    else
                    {
                        m_done = true;
                    }
                }
            }
        }
Esempio n. 7
0
        private void ProcessRegion(SimulationEvent ev)
        {
            String id = ((StringValue)ev["ID"]).value;
            AttributeCollectionValue atts = ((AttributeCollectionValue)ev["Attributes"]);
            PolygonValue             pv   = atts.attributes["Polygon"] as PolygonValue;

            if (atts.attributes.ContainsKey("CurrentAbsolutePolygon"))
            {
                pv = atts["CurrentAbsolutePolygon"] as PolygonValue;
            }
            if (id.StartsWith("SeaLane-"))
            {
                if (!_seaLanes.ContainsKey(id))
                {
                    _seaLanes.Add(id, pv);
                }
                else
                {
                    _seaLanes[id] = pv;
                }
            }
            else if (id.StartsWith("Entry-"))
            {
                if (!_entryPoints.ContainsKey(id))
                {
                    _entryPoints.Add(id, pv);
                }
                else
                {
                    _entryPoints[id] = pv;
                }
            }
            else if (id.StartsWith("AO-"))
            {
                //AO's handled differently now
            }
        }
Esempio n. 8
0
        public void ProcessEvent(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies();
            switch (e.eventType)
            {
            case "NewObject":
                NewObject(e);
                break;

            case "RevealObject":
                RevealObject(e);
                break;

            case "MoveObject":
                MoveObject(e);
                break;

            case "StateChange":
                StateChange(e);
                break;

            case "TimeTick":
                TimeTick(e);
                break;

            case "ExternalApp_SimStop":
                ResetSimulation();
                break;

            case "ForceUpdateObjectAttribute":
                ForceUpdateObjectAttribute(e);
                break;

            default:
                break;
            }
        }
Esempio n. 9
0
        public void ProcessEvent(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies();
            switch (e.eventType)
            {
            case "TimeTick":
                TimeTick(e);
                break;

            case "NewObject":
                NewObject(e);
                break;

            case "RevealObject":
                RevealObject(e);
                break;

            //case "HandshakeInitializeGUIDone":
            //    HandshakeInitializeGUIDone(e);
            //    break;
            case "ExternalApp_SimStop":
                ResetSimulation();
                break;

            case "PlayerControl":
                PlayerControl(e);
                break;

            case "ForceUpdateObjectAttribute":
                ForceUpdateObjectAttribute(e);
                break;

            default:
                break;
            }
        }
Esempio n. 10
0
        private void LoadEvents(string fileName)
        {
            StreamReader    re    = File.OpenText(fileName);
            string          input = null;
            SimulationEvent ev    = null;

            events.Clear();

            input = re.ReadLine(); // thriow away the line with the version number


            while ((input = re.ReadLine()) != null)
            {
                try
                {
                    ev = SimulationEventFactory.XMLDeserialize(input);
                    if (SimulationEventFactory.ValidateEvent(ref simModel, ev))
                    {
                        if (simModel.eventModel.events[ev.eventType].shouldReplay)
                        {
                            events.Add(ev);
                        }
                    }
                    else
                    {
                        throw new Exception("error reading: " + input);
                    }
                }
                catch (Exception e)
                {
                    ErrorLog.Write(String.Format("NONFATAL Deserialize Error in LogPlayer.Player: {0}", input));
                    ErrorLog.Write(e.ToString());
                }
            }
            re.Close();
        }
Esempio n. 11
0
        /// <summary>
        /// This event is broadcast out to each client.  That client will attempt to put the object in motion, but will only
        /// succeed if the object already exists in its playfield.
        /// </summary>
        /// <param name="objectID"></param>
        /// <param name="ownerID"></param>
        /// <param name="location"></param>
        /// <param name="desLocation"></param>
        /// <param name="maxSpeed"></param>
        /// <param name="throttle"></param>
        /// <param name="time"></param>
        /// <param name="iconName"></param>
        /// <param name="isWeapon"></param>
        private void SendViewProMotionUpdate(string objectID, string ownerID, LocationValue location, LocationValue desLocation, double maxSpeed, double throttle, string iconName, bool isWeapon, double activeRegionSpeedMultiplier)
        {
            SimulationEvent vpmu = null;

            vpmu = SimulationEventFactory.BuildEvent(ref simModel, "ViewProMotionUpdate");

            vpmu["ObjectID"]            = DataValueFactory.BuildString(objectID);
            vpmu["OwnerID"]             = DataValueFactory.BuildString(ownerID);
            vpmu["Location"]            = location;
            vpmu["DestinationLocation"] = desLocation;
            //Console.WriteLine(String.Format("VPMU: ID:{0} dX:{1} dY:{2}", objectID, desLocation.X, desLocation.Y));
            //if (objectID == "Fighter01_Troop_2")
            //{
            //    Console.Out.Write(String.Format("\n{0} is moving at {1}*{2}\n", objectID, maxSpeed, activeRegionSpeedMultiplier));
            //}
            vpmu["MaximumSpeed"] = DataValueFactory.BuildDouble(maxSpeed * activeRegionSpeedMultiplier);
            vpmu["Throttle"]     = DataValueFactory.BuildDouble(throttle);
            vpmu["Time"]         = DataValueFactory.BuildInteger(currentTick);
            vpmu["IconName"]     = DataValueFactory.BuildString(iconName);
            //add label color to the mix
            try
            {
                vpmu["LabelColor"] = DataValueFactory.BuildInteger(dmColorMapping[ownerID]);
            }
            catch (Exception ex)
            {
                vpmu["LabelColor"] = DataValueFactory.BuildInteger(-984833);
            }
            vpmu["IsWeapon"] = DataValueFactory.BuildBoolean(isWeapon);
            distClient.PutEvent(vpmu);
            if (!movingObjects.Contains(objectID) &&
                !DataValueFactory.CompareDataValues(location, desLocation))
            {
                movingObjects.Add(objectID);
            }
        }
Esempio n. 12
0
        private void ClockStart()
        {
            switch (clockState)
            {
            case ClockState.STOPPED:
                clockState          = ClockState.RUNNING;
                startButton.Text    = "Pause";
                clockTimer.Interval = updateFrequency;
                clockTimer.Start();
                SimulationEvent tick = SimulationEventFactory.BuildEvent(ref simModel, "TimeTick");
                ((IntegerValue)tick["Time"]).value = simulationTime;
                netClient.PutEvent(tick);

                manualCheckBox.Enabled = false;

                break;

            case ClockState.RUNNING:
                clockState       = ClockState.STOPPED;
                startButton.Text = "Start";
                clockTimer.Stop();
                break;
            }
        }
Esempio n. 13
0
        private void ClassificationChanged(SimulationEvent e)
        {
            String objectID = ((StringValue)e["ObjectID"]).value;

            if (objectProxies.Count == 0)
            {
                return; //another weird edge case
            }
            SimulationObjectProxy proxy = objectProxies[objectID];

            proxy["IdentifyTime"].SetDataValue(DataValueFactory.BuildInteger(time));
            proxy["IdentifiedBy"].SetDataValue(DataValueFactory.BuildString(((StringValue)e["UserID"]).value));
            proxy["ClassifiedBy"].SetDataValue(DataValueFactory.BuildString(((StringValue)e["UserID"]).value));

            String classification = ((StringValue)e["ClassificationName"]).value;

            proxy["UserClassifiedIFF"].SetDataValue(DataValueFactory.BuildString(classification));

            if (!classifications.ContainsKey(objectID))
            {
                classifications.Add(objectID, "");
            }
            classifications[objectID] = classification;
        }
Esempio n. 14
0
        public void ReceiveDecisionMakerEvent(SimulationEvent dmEvent)
        {
            string        dmID       = ((StringValue)dmEvent["ID"]).value;
            string        dmRole     = ((StringValue)((AttributeCollectionValue)dmEvent["Attributes"])["RoleName"]).value;
            string        team       = ((StringValue)((AttributeCollectionValue)dmEvent["Attributes"])["TeamMember"]).value;
            int           dmColor    = ((IntegerValue)((AttributeCollectionValue)dmEvent["Attributes"])["Color"]).value;
            string        dmBriefing = ((StringValue)((AttributeCollectionValue)dmEvent["Attributes"])["Briefing"]).value;
            Boolean       isObserver = ((BooleanValue)((AttributeCollectionValue)dmEvent["Attributes"])["IsObserver"]).value;
            DecisionMaker dm         = new DecisionMaker(dmID, null); //STUB; need teams info

            dm.role     = dmRole;
            dm.color    = dmColor;
            dm.briefing = dmBriefing;
            dm.isHuman  = !((BooleanValue)((AttributeCollectionValue)dmEvent["Attributes"])["ComputerControlled"]).value;
            if (!allDMs.ContainsKey(dmID))
            {
                allDMs.Add(dmID, dm);
            }
            dm.isObserver = isObserver;
            //SimulationEvent player = SimulationEventFactory.BuildEvent(ref simModelInfo, "PlayerControl");
            //((StringValue)player["DecisionMakerID"]).value = dmID;
            //((StringValue)player["ControlledBy"]).value = "COMPUTER";
            //server.PutEvent(player);
        }
Esempio n. 15
0
        private void ProcessObject(SimulationEvent ev)
        {
            String id                              = ((StringValue)ev["ID"]).value;
            String objectType                      = ((StringValue)((AttributeCollectionValue)ev["Attributes"])["ClassName"]).value;
            AttributeCollectionValue atts          = ev["Attributes"] as AttributeCollectionValue;
            SeamateObject            seamateObject = null;

            if (_unrevealedObjects.ContainsKey(id))
            {
            }
            else
            {
                _unrevealedObjects.Add(id, new SeamateObject(id));
                Console.WriteLine("Added to UnrevealedObjects: " + id);
            }
            _unrevealedObjects[id].SetAttributes(atts);
            if (atts.attributes.ContainsKey("OwnerID"))
            {
                EstablishOwnership(id, ((StringValue)atts.attributes["OwnerID"]).value);
            }
            if (ev.parameters.ContainsKey("StateTable") && !_speciesPossibleStates.ContainsKey(objectType))
            {
                _speciesPossibleStates.Add(objectType, new Dictionary <string, AttributeCollectionValue>());
                StateTableValue          stv             = (StateTableValue)ev["StateTable"];
                AttributeCollectionValue stateAttributes = null;
                foreach (String stateName in stv.states.Keys)
                {
                    stateAttributes = (AttributeCollectionValue)stv[stateName];
                    _speciesPossibleStates[objectType].Add(stateName, new AttributeCollectionValue());
                    foreach (String att in stateAttributes.attributes.Keys)
                    {
                        _speciesPossibleStates[objectType][stateName].attributes.Add(att, DataValueFactory.BuildFromDataValue(stateAttributes[att]));
                    }
                }
            }
        }
Esempio n. 16
0
        public void DisconnectTerminal(SimulationEvent e)
        {
            string termID = ((StringValue)e["TerminalID"]).value;
            string dmID   = "";

            if (termToDMMap.ContainsKey(termID))
            {
                dmID = termToDMMap[termID]; //.ToUpper()];
            }


            if (dmToTerminalMap.ContainsKey(dmID))
            {
                termID = dmToTerminalMap[dmID];
                dmToTerminalMap.Remove(dmID);
                termToDMMap.Remove(termID);
            }
            if (dmsIsReady.ContainsKey(dmID))
            {
                dmsIsReady.Remove(dmID);
            }
            if (allDMs.ContainsKey(dmID))
            {
                allDMs[dmID].availability = DecisionMaker.Availability.AVAILABLE;
            }

            SimulationEvent player = SimulationEventFactory.BuildEvent(ref simModelInfo, "PlayerControl");

            ((StringValue)player["DecisionMakerID"]).value = dmID;
            ((StringValue)player["ControlledBy"]).value    = "COMPUTER";
            server.PutEvent(player);

            player = SimulationEventFactory.BuildEvent(ref simModelInfo, "DisconnectDecisionMaker");
            ((StringValue)player["DecisionMakerID"]).value = dmID;
            server.PutEvent(player);
        }
Esempio n. 17
0
        public ScenarioReader()
        {
            Queue<SimulationEvent> q = new Queue<SimulationEvent>();

            QueueManager EventQueue = QueueManager.UniqueInstance();

            SimulationEvent dequeued;

            //simulates reading in from the XML file
            q.Enqueue(populateQueue());
            q.Enqueue(populateQueue2());
            q.Enqueue(populateQueue3());
            q.Enqueue(populateQueue4());
            //Only would dequeue if events are not conditional.
            //After done reading from XML file, send time queue to queue manager
            while (q.Count > 0)
            {
                dequeued = new SimulationEvent();
                dequeued = q.Dequeue();
                EventQueue.AddEvent(((IntegerValue)dequeued.parameters["Time"]).value, dequeued);
            }      
        }
Esempio n. 18
0
        private void EventLoop()
        {
            try
            {
                List <SimulationEvent> events = null;
                DateTime nowTimer             = new DateTime();
                DateTime tickTimer            = DateTime.Now;
                DateTime startTime            = new DateTime();
                int      eventCounter         = 0;

                long start;
                long end;
                Dictionary <string, long> simTimes = new Dictionary <string, long>();

                foreach (SimulatorExecutionInfo sei in simModelInfo.simulationExecutionModel.simulators)
                {
                    simTimes[sei.simulatorName] = 0;
                }

                while (true)
                {
                    nowTimer = DateTime.Now;
                    lock (simCoreLock)
                    {
                        switch (state)
                        {
                        case SimCoreState.UNINITIALIZED:
                            throw new Exception("SimCore: shouldn't be in event loop if uninitialized");

                        case SimCoreState.RUNNING:
                            //distributor.StopIncoming();
                            events       = distClient.GetEvents();
                            eventCounter = events.Count;

                            foreach (SimulationEvent e in events)
                            {
                                switch (e.eventType)
                                {
                                case "TimeTick":
                                    lock (simTimeLock)
                                    {
                                        simulationTime = (int)((IntegerValue)e["Time"]).value;

                                        if (ServerOptions.UsePerformanceLog)
                                        {
                                            StringBuilder b = new StringBuilder();
                                            b.AppendFormat("SimCore Metric: SimTime: {0}; Processing Time: {1}.", simulationTime / 1000, DateTime.Now - tickTimer);
                                            PerformanceLog.Write(b.ToString());
                                        }
                                        tickTimer = DateTime.Now;
                                        if (simulationTime == 1000)
                                        {
                                            startTime = DateTime.Now;
                                        }
                                    }
                                    break;

                                case "ExternalApp_SimStop":
                                    //Console.Out.WriteLine("SimCore Metric: Exiting SimCore loop.  Total run time: {0}; Total ticks: {1}.", DateTime.Now - startTime, (simulationTime / 1000) - 1);//-1 because it is starting at time 1
                                    isReady = false;
                                    break;

                                //case "PauseScenario":
                                //    if (simulators.ContainsKey("ViewPro"))
                                //    {
                                //        ((ViewProSim)simulators["ViewPro"]).PauseScenario();
                                //    }
                                //    break;
                                //case "ResumeScenario":
                                //    if (simulators.ContainsKey("ViewPro"))
                                //    {
                                //        ((ViewProSim)simulators["ViewPro"]).ResumeScenario();
                                //    }
                                //    break;
                                case "ResetSimulation":
                                    lock (simTimeLock)
                                    {
                                        simulationTime = 0;
                                        isReady        = false;
                                    }
                                    break;

                                default:
                                    break;
                                }

                                //foreach (SimulatorExecutionInfo sei in simModelInfo.simulationExecutionModel.simulators)
                                foreach (KeyValuePair <String, ISimulator> sim in simulators)
                                {
                                    start = DateTime.Now.Ticks;
                                    //simulators[sei.simulatorName].ProcessEvent(e);
                                    sim.Value.ProcessEvent(e);
                                    end = DateTime.Now.Ticks;

                                    //simTimes[sei.simulatorName] += (end - start);
                                    simTimes[sim.Key] += (end - start);
                                }

                                if (e.eventType == "StartupComplete")
                                {
                                    SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModelInfo, "SimCoreReady");
                                    isReady = true;
                                    distClient.PutEvent(ev);
                                    if (ServerOptions.UsePerformanceLog)
                                    {
                                        foreach (SimulatorExecutionInfo sei in simModelInfo.simulationExecutionModel.simulators)
                                        {
                                            if (!simTimes.ContainsKey(sei.simulatorName))
                                            {
                                                continue;
                                            }
                                            StringBuilder b = new StringBuilder();
                                            b.AppendFormat("SimCore Metric: Initialization time in: {0} was {1} seconds.", sei.simulatorName, simTimes[sei.simulatorName] / 10000000.0);
                                            PerformanceLog.Write(b.ToString());
                                            simTimes[sei.simulatorName] = 0;
                                        }
                                    }
                                }
                            }
                            if (eventCounter > 0)
                            {
                                //Console.Out.WriteLine("SimCore Metric: Events Processed: {0}; processing time: {1}.", eventCounter, DateTime.Now - nowTimer);
                                //distributor.ResumeIncoming();
                            }
                            break;

                        case SimCoreState.STOPPING:

                            long total = 0;
                            if (ServerOptions.UsePerformanceLog)
                            {
                                foreach (SimulatorExecutionInfo sei in simModelInfo.simulationExecutionModel.simulators)
                                {
                                    if (!simTimes.ContainsKey(sei.simulatorName))
                                    {
                                        continue;
                                    }
                                    total += simTimes[sei.simulatorName];
                                }
                                foreach (SimulatorExecutionInfo sei in simModelInfo.simulationExecutionModel.simulators)
                                {
                                    if (!simTimes.ContainsKey(sei.simulatorName))
                                    {
                                        continue;
                                    }
                                    StringBuilder b = new StringBuilder();
                                    b.AppendFormat("SimCore Metric: Total time in: {0} was {1} seconds which is {2}% of total simulator time.", sei.simulatorName, simTimes[sei.simulatorName] / 10000000.0, (((double)simTimes[sei.simulatorName]) / total) * 100.0);
                                    PerformanceLog.Write(b.ToString());
                                }
                            }
                            state = SimCoreState.UNINITIALIZED;
                            return;
                        }
                    }
                    Thread.Sleep(updateFrequency / 10);
                }
            }
            catch (ThreadAbortException) { }
            catch (Exception exc)
            {
                MessageBox.Show("An error '" + exc.Message + "' has occurred in the Simulation Server.\nPlease email the C:\\DDDErrorLog.txt file to Aptima customer support with a description of what you were doing at the time of the error.");
                ErrorLog.Write(exc.ToString() + "\n");
                throw new Exception();
            }
        }
Esempio n. 19
0
 private void ForceUpdateObjectAttribute(SimulationEvent e)
 {
     return;
 }
Esempio n. 20
0
 public EventListBoxItem(SimulationEvent se)
 {
     simEvent = se;
 }
Esempio n. 21
0
 public void ViewProActiveRegionUpdate(SimulationEvent ev)
 {
 }
Esempio n. 22
0
        //----------------------------------------------------------------------------------------
        // ProcessIRV | Parameters : Entity
        //----------------------------------------------------------------------------------------
        public void ProcessIRV(Entity activeEntity)
        {
            //assign the entity a rep
            activeEntity.SalesRep = TheSalesRepManager.AssignFreeSalesRep(activeEntity.EntityCallType);

            //set the entitys start wait time
            activeEntity.StartWaitTime = SimulationTime;

            //Check to see if the active entity actually recived a rep if so...
            if (activeEntity.SalesRep != null)
            {
                //... set the end wait time for the entity
                activeEntity.EndWaitTime = SimulationTime;

                //set the rep assigned to the entity to be not availble
                activeEntity.SalesRep.Avaliable = false;

               //Calculate the processing interval based on calls type
                double processingTime = CalculateProcessingTime(activeEntity.EntityCallType);
                //create the new complete serve event passing in the calculated processing time and the active entity as well as the event type
                SimulationEvent newCompleteServiceEvent = new SimulationEvent(activeEntity, eEventType.ProcessingComplete, processingTime);
                //add the event to the calandar
                MainCalandar.AddEvent(newCompleteServiceEvent);
            }
            else//or else...
            {
                //add the entity to the queue
                theQueueManager.AddEntity(activeEntity);
            }//End outer if
        }
Esempio n. 23
0
 //----------------------------------------------------------------------------------------
 // Initalize Method | Parameters : N/A
 //----------------------------------------------------------------------------------------
 public void Initialize()
 {
     //create first entity
     Entity lastEntity = new Entity(0);
     //create first event passsin in the first entity
     SimulationEvent lastEvent = new SimulationEvent(lastEntity, eEventType.EndSimulation, 10800);
     //create last entity
     Entity firstEntity = new Entity(callArrives);
     //create last event passsin in the last entity
     SimulationEvent firstEvent = new SimulationEvent(firstEntity, eEventType.CallArrive, 0);
     //add the first event to the calandar
     MainCalandar.AddEvent(firstEvent);
     //add the last event to the calandar
     MainCalandar.AddEvent(lastEvent);
 }
Esempio n. 24
0
        private static SimulationEvent populateQueue4()
        {
            SimulationEvent ee = new SimulationEvent();
            Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>();

            ee.eventType = "MoveObject";

            DataValue myDV = new IntegerValue();
            ((IntegerValue)(myDV)).value = 1;
            ee.parameters.Add("ObjectID", myDV);

            myDV = new LocationValue();
            ((LocationValue)(myDV)).X = 100;
            ((LocationValue)(myDV)).Y = 100;
            ((LocationValue)(myDV)).Z = 100;
            ee.parameters.Add("DestinationLocation", myDV);

            myDV = new DoubleValue();
            ((DoubleValue)(myDV)).value = .5;
            ee.parameters.Add("Throttle", myDV);

            myDV = new IntegerValue();
            ((IntegerValue)(myDV)).value = 10000;
            ee.parameters.Add("Time", myDV);

            return ee;

        }
Esempio n. 25
0
 public void ViewProMotionUpdate(SimulationEvent ev)
 {
 }
Esempio n. 26
0
 private void TimeTick(SimulationEvent e)
 {
     time = ((IntegerValue)e["Time"]).value;
 }
Esempio n. 27
0
 public void ViewProStopObjectUpdate(SimulationEvent ev)
 {
 }
Esempio n. 28
0
        //----------------------------------------------------------------------------------------
        // Process Complete Service Method | Parameter : Entity
        //----------------------------------------------------------------------------------------
        public void ProcessCompleteService(Entity activeEntity)
        {
            //Set the active entitys end time to the simulations current time
            activeEntity.EndSystemTime = SimulationTime;

            //update the stats for the entity passing in the active entity
            stats.UpdateEntityStats(activeEntity);

            //store the rep type of the current rep in a variable
            eCallType theCallTypeofRep = activeEntity.SalesRep.RepType;

            //check the length of the queue of the call type that the active entitys rep is
            int lengthOfQueueRepIsIn = theQueueManager.QueueLength(theCallTypeofRep);

            //if the queue length for that call type of the rep is null then...
            if (lengthOfQueueRepIsIn == 0)
            {
                //... make the rep avalible
                activeEntity.SalesRep.Avaliable = true;
            }
            else//or else...
            {
                //... get the next entity from thequeue that correspons to the rep type of the rep that was assigned to active entity
                Entity nextEntity = theQueueManager.GetNextEntity(theCallTypeofRep);
                //pass the rep from the active entity to the next entity
                nextEntity.SalesRep = activeEntity.SalesRep;
                //set the simulation end time for the next entity
                nextEntity.EndWaitTime = SimulationTime;

                //calculate how long it will take the next entity to comple the service call
                double processingTime = CalculateProcessingTime(nextEntity.EntityCallType);

                //create and add the new complete service event to the clandar passing the next entity, the processing complete event and the processing time
                SimulationEvent newCompleteServiceEvent = new SimulationEvent(nextEntity, eEventType.ProcessingComplete, processingTime);
                MainCalandar.AddEvent(newCompleteServiceEvent);

            }//End if
        }
Esempio n. 29
0
 public void AttackSucceeded(SimulationEvent ev)
 {
     m_done = true;
 }
Esempio n. 30
0
        private void RevealObject(SimulationEvent e)
        {
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];
            string id = ((StringValue)e["ObjectID"]).value;

            SimulationObjectProxy prox = null;

            prox = GetObjectProxy(id);
            if (prox == null)
            {
                return;
            }

            //Set State info?
            //AD: This is kind of a quick fix.  Gabe would have a better idea on a more permanent
            //solution.
            DataValue stv = new DataValue();

            stv = prox["StateTable"].GetDataValue();
            Dictionary <string, DataValue> tempDict = ((StateTableValue)stv).states;

            tempDict = ((AttributeCollectionValue)tempDict[((StringValue)atts["State"]).value]).attributes;

            foreach (KeyValuePair <String, DataValue> kvp in tempDict)
            {
                if (!atts.attributes.ContainsKey(kvp.Key))
                {//if att exists in atts, it should NOT overwrite reveal attributes.
                    atts.attributes.Add(kvp.Key, kvp.Value);
                }
            }
            ////AD
            foreach (string attname in atts.attributes.Keys)
            {
                if (attname == "ID")
                {
                    continue;
                }
                if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                {
                    prox[attname].SetDataValue(atts[attname]);
                    if (attname == "Sensors")
                    {
                        double           maxSensor = -1.0;
                        SensorArrayValue sav       = atts[attname] as SensorArrayValue;
                        foreach (SensorValue sv in sav.sensors)
                        {
                            maxSensor = Math.Max(maxSensor, sv.maxRange);
                        }
                        if (maxSensor >= 0)
                        {
                            ObjectDistances.UpdateObjectSensorRange(id, maxSensor);
                        }
                    }
                }
            }
            Dictionary <string, DataValue> x = new Dictionary <string, DataValue>();

            EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue();

            foreach (string attName in em.attIsEngram.Keys)
            {
                if (em.attIsEngram[attName])
                {
                    if (StateDB.engrams.ContainsKey(attName))
                    {
                        x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue);
                    }
                }
            }

            prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x));
        }
Esempio n. 31
0
        //----------------------------------------------------------------------------------------
        // Process Call Arrive | Parameters : Entity
        //----------------------------------------------------------------------------------------
        public void ProcessCallArrive(Entity activeEntity)
        {
            //if the max that can be on hold hasn't been reached.....
            if (theQueueManager.TotalQueueLength() < GlobalParameters.MAX_ON_HOLD)//
            {
                //...Update its start time to the current simulation time
                activeEntity.StartSystemTime = SimulationTime;
                //...calc wait at switch time
                double waitIRVInterval = (theDice.diceRoll() * GlobalParameters.IVR_DELAY)*GlobalParameters.SEC_IN_MIN;
                double completIRVTime = SimulationTime + waitIRVInterval;

                //...Create the new event taking in the entity and Add the new event to the calandar
                SimulationEvent newCompleteSwitcheEvent = new SimulationEvent(activeEntity, eEventType.SwitchComplete, completIRVTime);
                MainCalandar.AddEvent(newCompleteSwitcheEvent);
            }
            else// if the max that can be on hold has been reashed or surpassed then...
            {
                //...increment the hangup count
                stats.HangUps++;
            }//End If

            callArrives++;
            //Compute next arrival of and entity
            Entity nextEntity = new Entity(callArrives);
            double nextArivalInterval = (theDice.diceRoll() * GlobalParameters.CALL_ARRIVAL_RATE) * GlobalParameters.SEC_IN_MIN;
            double nextArrivalTime = SimulationTime + nextArivalInterval;

            //Add event to callander for next arrival
            SimulationEvent newArrivalEvent = new SimulationEvent(nextEntity, eEventType.CallArrive,nextArrivalTime);
            MainCalandar.AddEvent(newArrivalEvent);
        }
Esempio n. 32
0
        private void StateChange(SimulationEvent e)
        {
            string id = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy prox = null; // objectProxies[id];

            prox = GetObjectProxy(id);
            if (prox == null)
            {
                return;
            }

            string newState = ((StringValue)e["NewState"]).value;

            DataValue dv = prox["StateTable"].GetDataValue();

            if (((StateTableValue)dv).states.ContainsKey(newState))
            {
                DataValue dv2 = ((StateTableValue)dv).states[newState];
                //AD: Added state to attributes
                DataValue temp = new StringValue();
                ((StringValue)temp).value = newState;
                ((AttributeCollectionValue)dv2).attributes["State"] = temp;
                //AD
                foreach (string attname in ((AttributeCollectionValue)dv2).attributes.Keys)
                {
                    if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                    {
                        prox[attname].SetDataValue(((AttributeCollectionValue)dv2).attributes[attname]);
                        if (attname == "Sensors")
                        {
                            double           maxSensor = -1.0;
                            SensorArrayValue sav       = ((AttributeCollectionValue)dv2).attributes[attname] as SensorArrayValue;
                            foreach (SensorValue sv in sav.sensors)
                            {
                                maxSensor = Math.Max(maxSensor, sv.maxRange);
                            }
                            if (maxSensor >= 0)
                            {
                                ObjectDistances.UpdateObjectSensorRange(id, maxSensor);
                            }
                        }
                    }
                }
            }
            CustomAttributesValue cav = prox["CustomAttributes"].GetDataValue() as CustomAttributesValue;

            Dictionary <string, DataValue> x = new Dictionary <string, DataValue>();

            if (cav != null)
            {
                x = cav.attributes;
            }

            EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue();

            foreach (string attName in em.attIsEngram.Keys)
            {
                if (em.attIsEngram[attName])
                {
                    if (StateDB.engrams.ContainsKey(attName))
                    {
                        x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue);
                    }
                }
            }

            prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x));
        }
Esempio n. 33
0
 //--------------------------------------------------------------------------------------------
 // Add Event | Parameters : SimulationEvent
 //---------------------------------------------------------------------------------------------
 public void AddEvent(SimulationEvent theEvent)
 {
     // add the event to the events list then sort to get the events in order as they are added
     EventList.Add(theEvent);
     SortEvents();
 }
Esempio n. 34
0
        public override void UpdateFromSimulation(int numberOfUpdates, Simulator sim, SimulationEvent eventType)
        {
            base.UpdateFromSimulation(numberOfUpdates, sim, eventType);
            if (eventType == SimulationEvent.TICK)
            {
                int varID = sim.GetComponentPinCurrentVarId(ID, 1);
                if (varID != -1)
                {
                    double LEDCurrent = sim.GetValueOfVar(varID, 0);

                    if (LEDCurrent > 0)
                    {
                        SetBrightness(Math.Min(LEDCurrent / 0.01, 1.0));
                    }
                    else
                    {
                        SetBrightness(0);
                    }
                }
                else
                {
                    SetBrightness(0);
                }
            }
            else if (eventType == SimulationEvent.STOPPED)
            {
                SetBrightness(0);
            }
        }
Esempio n. 35
0
 private void TimeTick(SimulationEvent e)
 {
     blackboard.simTime = ((IntegerValue)e["Time"]).value;
 }
Esempio n. 36
0
 public void ViewProInitializeObject(SimulationEvent ev)
 {
 }
Esempio n. 37
0
        private void AttackSucceeded(SimulationEvent e)
        {
            if (objectProxies.Count == 0)
            {
                return; //another weird edge case
            }
            try
            {
                String objectID             = ((StringValue)e["ObjectID"]).value;
                SimulationObjectProxy proxy = objectProxies[objectID];

                String targetID = ((StringValue)e["TargetID"]).value;
                SimulationObjectProxy targetProxy = objectProxies[targetID];

                String transitionState = ((StringValue)e["NewState"]).value;

                // It's a sea vessel if it's not a BAMS or Firescout
                String targetClassName = ((StringValue)targetProxy["ClassName"].GetDataValue()).value;
                if (targetClassName != "BAMS" && targetClassName != "Firescout" && transitionState == "Dead")
                {
                    targetProxy["DestroyedTime"].SetDataValue(DataValueFactory.BuildInteger(time));
                    targetProxy["DestroyedBy"].SetDataValue(DataValueFactory.BuildString(objectID));

                    //AD: TODO Send view pro attribute event for these objects.
                    SimulationEvent          ev  = SimulationEventFactory.BuildEvent(ref simModel, "ViewProAttributeUpdate");
                    AttributeCollectionValue acv = new AttributeCollectionValue();
                    //                  acv.attributes.Add("DestroyedTime", DataValueFactory.BuildDetectedValue(DataValueFactory.BuildInteger(time), 100));
//                    acv.attributes.Add("DestroyedBy", DataValueFactory.BuildDetectedValue(DataValueFactory.BuildString(objectID), 100));
                    acv.attributes.Add("DestroyedTime", DataValueFactory.BuildInteger(time));
                    acv.attributes.Add("DestroyedBy", DataValueFactory.BuildString(objectID));


                    ((StringValue)ev["TargetPlayer"]).value = "BAMS DM";
                    ((StringValue)ev["ObjectID"]).value     = ((StringValue)targetProxy["ID"].GetDataValue()).value;
                    ((StringValue)ev["OwnerID"]).value      = ((StringValue)targetProxy["OwnerID"].GetDataValue()).value;
                    ((IntegerValue)ev["Time"]).value        = time * 1000;
                    ev["Attributes"] = acv;

                    distClient.PutEvent(ev);

                    ((StringValue)ev["TargetPlayer"]).value = "Firescout DM";
                    distClient.PutEvent(ev);
                    ((StringValue)ev["TargetPlayer"]).value = "Individual DM";
                    distClient.PutEvent(ev);
                }

                String targetOwnerID   = ((StringValue)targetProxy["OwnerID"].GetDataValue()).value;
                String attackerOwnerID = ((StringValue)proxy["OwnerID"].GetDataValue()).value;


                if (transitionState == "Dead")
                {
                    //Clear the intent of any other vessel mentioned in target's intent (pursued or pursuee).
                    String targetIntent = ((StringValue)targetProxy["Intent"].GetDataValue()).value;
                    if (targetIntent != "")
                    {
                        String[] intentArray = targetIntent.Split(":".ToCharArray());
                        if (intentArray.Length > 1)
                        {
                            SimulationObjectProxy vesselProxyToClear = objectProxies[intentArray[1]];
                            vesselProxyToClear["Intent"].SetDataValue(DataValueFactory.BuildString(""));
                        }
                    }

                    //IF friendly, increment counter
                    if (!targetOwnerID.ToLower().Contains("pirate"))
                    {
                        IncrementFriendliesLost(1);
                        String attackClassName = ((StringValue)proxy["ClassName"].GetDataValue()).value;
                        if (attackClassName == "BAMS" || attackClassName == "Firescout")
                        {
                            //IF friendly, and attacker was BAMS/FS
                            IncrementFriendliesDestroyedByPlayers(1);
                        }
                    }
                    else
                    {
                        //if hostile increment counter
                        IncrementHostileTargetsDestroyed(1);
                    }
                }
                //if (targetClassName == "BAMS" || targetClassName == "Firescout")
                //{
                //    //if bams/firescout, increment counter
                //    IncrementHitsTakenByAssets(1);
                //}

                if (!attackerOwnerID.Contains("BAMS") && !attackerOwnerID.Contains("Firescout") && !attackerOwnerID.Contains("Individual"))
                {
                    return; //the following section is only for YOUR attacks, so return if its not BAMS or FS
                }
                String attackClass          = ((StringValue)proxy["ClassName"].GetDataValue()).value;
                String targetClassification = "";
                try
                {
                    targetClassification = classifications[targetID];
                }
                catch (Exception exc)
                { }
                if (targetClassification != "Hostile" && (targetClassName != "BAMS" || targetClassName != "Firescout"))
                {
                    //if asset was not classified as hostile, violated ROE
                    IncrementRulesOfEngagementViolations(1);
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 38
0
 public void ViewProAttributeUpdate(SimulationEvent ev)
 {
 }
Esempio n. 39
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record

            string id   = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary <string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);

            if (prox == null)
            {
                return;
            }
            if (!objectProxies.ContainsKey(id))
            {
                objectProxies.Add(id, prox);
            }
            else
            {
                objectProxies[id] = prox;
            }

            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];

            string id2 = ((StringValue)e["ID"]).value;
            SimulationObjectProxy proxi = objectProxies[id2];

            if (proxi.GetKeys().Contains("StateTable"))
            {
                proxi["StateTable"].SetDataValue(e["StateTable"]);
            }


            if (objectProxies.ContainsKey(id2))
            {
                // initialize any object values I own.

                foreach (string attname in atts.attributes.Keys)
                {
                    if (proxi.GetKeys().Contains(attname) && proxi[attname].IsOwner())
                    {
                        proxi[attname].SetDataValue(atts[attname]);
                        if (attname == "Sensors")
                        {
                            double           maxSensor = -1.0;
                            SensorArrayValue sav       = atts[attname] as SensorArrayValue;
                            foreach (SensorValue sv in sav.sensors)
                            {
                                maxSensor = Math.Max(maxSensor, sv.maxRange);
                            }
                            if (maxSensor >= 0)
                            {
                                ObjectDistances.UpdateObjectSensorRange(id2, maxSensor);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 40
0
        private static SimulationEvent populateQueue3()
        {
            SimulationEvent ee = new SimulationEvent();
            Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>();

            ee.eventType = "NewObject";
            DataValue myDV = new StringValue();
            ((StringValue)(myDV)).value = "PhysicalObject";
            ee.parameters.Add("ObjectType", myDV);


            // START OF ATTRIBUTE DEFINITIONS //
            myDV = new IntegerValue();
            ((IntegerValue)(myDV)).value = 1;
            myAtt.Add("ID", myDV);

            myDV = new StringValue();
            ((StringValue)(myDV)).value = "Second Object";
            myAtt.Add("ObjectName", myDV);

            myDV = new StringValue();
            ((StringValue)(myDV)).value = "flying";
            myAtt.Add("ObjectState", myDV);

            myDV = new StringValue();
            ((StringValue)(myDV)).value = "NoClassesYet";
            myAtt.Add("ClassName", myDV);

            myDV = new LocationValue();
            ((LocationValue)(myDV)).X = 100;
            ((LocationValue)(myDV)).Y = 100;
            ((LocationValue)(myDV)).Z = 0;
            myAtt.Add("Location", myDV);

            myDV = new VelocityValue();
            ((VelocityValue)(myDV)).VX = 0;
            ((VelocityValue)(myDV)).VY = 0;
            ((VelocityValue)(myDV)).VZ = 0;
            myAtt.Add("Velocity", myDV);

            myDV = new DoubleValue();
            ((DoubleValue)(myDV)).value = 1;
            myAtt.Add("MaximumSpeed", myDV);

            myDV = new DoubleValue();
            ((DoubleValue)(myDV)).value = 0.0;
            myAtt.Add("Throttle", myDV);

            myDV = new LocationValue();
            ((LocationValue)(myDV)).X = 0;
            ((LocationValue)(myDV)).Y = 0;
            ((LocationValue)(myDV)).Z = 0;
            myAtt.Add("DestinationLocation", myDV);

            // END OF ATTRIBUTE DEFINITIONS //

            myDV = new AttributeCollectionValue();
            ((AttributeCollectionValue)(myDV)).attributes = myAtt;
            ee.parameters.Add("Attributes", myDV);

            myDV = new IntegerValue();
            ((IntegerValue)(myDV)).value = 5000;
            ee.parameters.Add("Time", myDV);

            return ee;

        }