Beispiel #1
0
        private void UpdateCPE(String dmId, double ffCpe, double ttCpe, int time)
        {
            if (!_dmCPEs.ContainsKey(dmId))
            {
                _dmCPEs.Add(dmId, new CPEPair(dmId, ffCpe, ttCpe, time));
            }
            else
            {
                _dmCPEs[dmId].FF_CPE          = ffCpe;
                _dmCPEs[dmId].TT_CPE          = ttCpe;
                _dmCPEs[dmId].LastTimeUpdated = time;
            }
            _lastCPEUpdateTime = time;
            AppendToInfoBox(tbInfoBox, String.Format("{0} CPEs updated to: FindFix={1}, TrackTarget={2}\r\n", dmId, ffCpe, ttCpe));
            //if they have a queued item waiting, send it now!

            if (_timelineEvents.Count() > 0 && !_hasFinishedPreTest)
            {
                _readyToSendItems = true; //next time tick, will check for next scheduled item
                return;                   //only adaptively choose if there are no more scheduled items remaining.
            }
            _hasFinishedPreTest = true;
            //Do stuff!
            List <int> usedItemIds    = new List <int>();
            CellRange  nextItemRange  = _itemSelector.GetNextItem(ffCpe, ttCpe);
            T_Item     nextItem       = SelectNextItemByRange(nextItemRange, dmId);
            int        failedAttempts = 0;

            while (nextItem == null && _items.Count > usedItemIds.Count)//0)
            {
                failedAttempts++;
                usedItemIds.Add(nextItemRange.CellNumber);
                //get a similar cell range and try again
                nextItemRange = _itemSelector.GetNextItem(ffCpe, ttCpe, usedItemIds, failedAttempts);
                nextItem      = SelectNextItemByRange(nextItemRange, dmId);
            }
            if (nextItem == null)
            {
                Console.WriteLine("Serious issues where we can't find a good fit");
                nextItem = _items[Math.Min(_items.Count, 5).ToString()];
            }
            //Thread.Sleep(1000); //TEMP
            ScheduledItem si = new ScheduledItem();

            si.DM_ID = dmId;
            si.ID    = nextItem.ID;
            si.Time  = time;
            _timelineEvents.Add(si);
            _readyToSendItems = true;
            //SendItem(nextItem, dmId, time);
            AppendToInfoBox(tbInfoBox, String.Format("{3}: Next Item ({4}) selected for {0}: FindFixDifficulty={1}, TrackTargetDifficulty={2}\r\n", dmId, nextItem.Parameters.FF_Difficulty, nextItem.Parameters.TT_Difficulty, time, nextItem.ID));
        }
Beispiel #2
0
        public T_Item DeepCopy()
        {
            T_Item    newItem;
            Exception ex;
            bool      result = T_Item.Deserialize(this.Serialize(), out newItem, out ex);

            if (!result || ex != null)
            {
                return(null);
            }

            return(newItem);
        }
Beispiel #3
0
        private void SendItem(T_Item item, String dmId, int time)
        {
            //AppendToInfoBox(tbInfoBox, String.Format("{3}: Next Item ({4}) selected for {0}: FindFixDifficulty={1}, TrackTargetDifficulty={2}\r\n", dmId, nextItem.Parameters.FF_Difficulty, nextItem.Parameters.TT_Difficulty, time, nextItem.ID));
            String infoText = String.Format("{3}: Next Item ({4}) selected for {0}: FindFixDifficulty={1}, TrackTargetDifficulty={2}\r\n", dmId, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty, time, item.ID);
            _ddd.SendItemInfo(dmId, item.ID, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty, time);
            StringBuilder sb = new StringBuilder();
            if (item.Parameters.Crossing)
            {
                sb.AppendFormat("Crossing;");
            }
            else
            {
                sb.AppendFormat("Non-Crossing;");
            }
            if (item.Parameters.Groupings == T_Groupings.Two)
            {
                sb.AppendFormat("Two-Grouping;");
            }
            else
            {
                sb.AppendFormat("One-Grouping;");
            }
            if (item.Parameters.PlayerResources == T_ResourceAvailability.Available)
            {
                sb.AppendFormat("PlayerHasResources;");
            }
            else
            {
                sb.AppendFormat("PlayerHas_NO_Resources;");
            }
            if (item.Parameters.TeammateResources == T_ResourceAvailability.Available)
            {
                sb.AppendFormat("TeammateHasResources;");
            }
            else
            {
                sb.AppendFormat("TeammateHas_NO_Resources;");
            }
            // if (item.Parameters.ThreatTypeSpecified)
            // {
            if (item.Parameters.ThreatType == T_ThreatType.Imminent)
            {
                sb.AppendFormat("Imminent;");
            }
            else
            {
                sb.AppendFormat("Non-imminent;");
            }
            //}
            if (item.Parameters.Threat == T_Threat.Ambiguous)
            {
                sb.AppendFormat("AmbiguousThreat;");
            }
            else if (item.Parameters.Threat == T_Threat.Unambiguous)
            {
                sb.AppendFormat("UnambiguousThreat;");
            }
            else
            {
                sb.AppendFormat("Non-Threat;");
            }

            infoText = String.Format("{0}\t{1}\r\n", infoText, sb.ToString());
            if (item.Action.Count() == 0)
            {

                PirateGenerator pirateGenerator = new PirateGenerator(_ddd);
                pirateGenerator.Generate(item, dmId);

                MerchantGenerator merchantGenerator = new MerchantGenerator(_ddd);
                merchantGenerator.Generate(item, dmId);

                CourseGenerator courseGenerator = new CourseGenerator(_ddd);
                courseGenerator.Generate(item, dmId);

                InterceptGenerator interceptGenerator = new InterceptGenerator(_ddd);
                interceptGenerator.Generate(item, dmId);

            }


            foreach (ActionBase action in item.Action)
            {
                if (action != null && !(action is T_ScriptedItem))
                    _ddd.AddDDDEventToQueue(action.ToDDDEvent(_time, _ddd));

                //ADAMS STUB: Might not work 100%, Lisa please fix if it won't work.
                String stimType = "";
                String objectID = "";
                if (action is T_Reveal)
                {
                    stimType = "Reveal";
                    objectID = ((T_Reveal)action).ID;
                    if (((T_Reveal)action).Location.Item is Aptima.Asim.DDD.CommonComponents.DataTypeTools.LocationValue)
                    {
                        if (((Aptima.Asim.DDD.CommonComponents.DataTypeTools.LocationValue)((T_Reveal)action).Location.Item).exists == false)
                        {
                            Console.WriteLine("Uh oh, null location");
                        }
                    }
                    String IFF = "";
                    if (((T_Reveal)action).StartupParameters.Items.Length > 0)
                    {
                        for (int c = 0; c < ((T_Reveal)action).StartupParameters.Items.Length; c++)
                        {
                            if (((T_Reveal)action).StartupParameters.Items[c] == "ObjectName")
                            {
                                IFF = "Squawking=" + ((T_Reveal)action).StartupParameters.Items[c + 1];
                            }
                            c++; //get past the "value" item, which is the even numbered entry
                        }
                    }
                    infoText = String.Format("{0}\tREVEAL; object_id={1}; Owned_by={2}; Revealed_at={3}\r\n", infoText, objectID, ((T_Reveal)action).Owner, ((T_Reveal)action).Location.ToString());

                }
                else if (action is T_Move)
                {
                    stimType = "Move";
                    objectID = ((T_Move)action).ID;
                    infoText = String.Format("{0}\tMOVE; object_id={1}; Throttle={2:0.00}; Destination={3}\r\n", infoText, objectID, ((T_Move)action).Throttle, ((T_Move)action).Location.ToString());
                }
                else if (action is T_ScriptedItem)
                {

                    //TODO: check to see that the object is not dead -Lisa
                    objectID = ((T_ScriptedItem)action).ID;
                    stimType = ((T_ScriptedItem)action).ActionType;
                }

                if (stimType != "")
                {
                    _ddd.SendStimulusEvent(item.ID, dmId, objectID, stimType, _time, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty);
                }
            }
            AppendToInfoBox(tbInfoBox, infoText);
        }
Beispiel #4
0
 public static bool LoadFromFile(string fileName, out T_Item obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Beispiel #5
0
 /// <summary>
 /// Deserializes xml markup from file into an T_Item object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output T_Item object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out T_Item obj, out System.Exception exception)
 {
     exception = null;
     obj = default(T_Item);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Beispiel #6
0
 public static bool Deserialize(string xml, out T_Item obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
Beispiel #7
0
 /// <summary>
 /// Deserializes workflow markup into an T_Item object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output T_Item object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out T_Item obj, out System.Exception exception)
 {
     exception = null;
     obj = default(T_Item);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Beispiel #8
0
        private void TimeTick(int time)
        {
            _time = time;
            if (!_readyToSendItems)
            {
                return;
            }
            try
            {
                //check timeline for a new item to process
                List <T_Item>        items          = new List <T_Item>();
                List <ScheduledItem> itemsToProcess = null;// new List<ScheduledItem>();
                itemsToProcess = _timelineEvents.GetItemsUpTo(time);
                // itemsToProcess[4].DM_ID = "!!";
                if (itemsToProcess == null)
                {
                    return;
                }
                //Thread.Sleep(2000);
                foreach (ScheduledItem i in itemsToProcess)
                {
                    T_Item myItem = null;
                    //i.DM_ID;
                    if (_items.ContainsKey(i.ID))
                    {
                        myItem = _items[i.ID];
                    }
                    else if (_ptItems.ContainsKey(i.ID))
                    {
                        myItem = _ptItems[i.ID];
                    }
                    else
                    {
                        continue;
                    }

                    _ddd.SendItemInfo(i.DM_ID, i.ID, myItem.Parameters.FF_Difficulty, myItem.Parameters.TT_Difficulty, time);
                    String infoText = String.Format("Processing item id={0}; For DM={1}; Current Time={2}\r\n", i.ID, i.DM_ID, i.Time);
                    //AD: TODO: Need to add in specific strings that describe the actions taking place in the item
                    items.Add(myItem.DeepCopy());
                    T_Item        item = myItem.DeepCopy();
                    StringBuilder sb   = new StringBuilder();
                    if (item.Parameters.Crossing)
                    {
                        sb.AppendFormat("Crossing;");
                    }
                    else
                    {
                        sb.AppendFormat("Non-Crossing;");
                    }
                    if (item.Parameters.Groupings == T_Groupings.Two)
                    {
                        sb.AppendFormat("Two-Grouping;");
                    }
                    else
                    {
                        sb.AppendFormat("One-Grouping;");
                    }
                    if (item.Parameters.PlayerResources == T_ResourceAvailability.Available)
                    {
                        sb.AppendFormat("PlayerHasResources;");
                    }
                    else
                    {
                        sb.AppendFormat("PlayerHas_NO_Resources;");
                    }
                    if (item.Parameters.TeammateResources == T_ResourceAvailability.Available)
                    {
                        sb.AppendFormat("TeammateHasResources;");
                    }
                    else
                    {
                        sb.AppendFormat("TeammateHas_NO_Resources;");
                    }
                    // if (item.Parameters.ThreatTypeSpecified)
                    // {
                    if (item.Parameters.ThreatType == T_ThreatType.Imminent)
                    {
                        sb.AppendFormat("Imminent;");
                    }
                    else
                    {
                        sb.AppendFormat("Non-imminent;");
                    }
                    //}
                    if (item.Parameters.Threat == T_Threat.Ambiguous)
                    {
                        sb.AppendFormat("AmbiguousThreat;");
                    }
                    else if (item.Parameters.Threat == T_Threat.Unambiguous)
                    {
                        sb.AppendFormat("UnambiguousThreat;");
                    }
                    else
                    {
                        sb.AppendFormat("Non-Threat;");
                    }

                    infoText = String.Format("{0}\t{1}\r\n", infoText, sb.ToString());
                    if (item.Action.Count() == 0)
                    {
                        PirateGenerator pirateGenerator = new PirateGenerator(_ddd);
                        pirateGenerator.Generate(item, i.DM_ID);

                        MerchantGenerator merchantGenerator = new MerchantGenerator(_ddd);
                        merchantGenerator.Generate(item, i.DM_ID);

                        CourseGenerator courseGenerator = new CourseGenerator(_ddd);
                        courseGenerator.Generate(item, i.DM_ID);

                        InterceptGenerator interceptGenerator = new InterceptGenerator(_ddd);
                        interceptGenerator.Generate(item, i.DM_ID);
                    }


                    foreach (ActionBase action in item.Action)
                    {
                        if (action != null && !(action is T_ScriptedItem))
                        {
                            _ddd.AddDDDEventToQueue(action.ToDDDEvent(time, _ddd));
                        }

                        //ADAMS STUB: Might not work 100%, Lisa please fix if it won't work.
                        String stimType = "";
                        String objectID = "";
                        if (action is T_Reveal)
                        {
                            stimType = "Reveal";
                            objectID = ((T_Reveal)action).ID;
                            if (((T_Reveal)action).Location.Item is Aptima.Asim.DDD.CommonComponents.DataTypeTools.LocationValue)
                            {
                                if (((Aptima.Asim.DDD.CommonComponents.DataTypeTools.LocationValue)((T_Reveal)action).Location.Item).exists == false)
                                {
                                    Console.WriteLine("Uh oh, null location");
                                }
                            }
                            String IFF = "";
                            if (((T_Reveal)action).StartupParameters.Items.Length > 0)
                            {
                                for (int c = 0; c < ((T_Reveal)action).StartupParameters.Items.Length; c++)
                                {
                                    if (((T_Reveal)action).StartupParameters.Items[c] == "ObjectName")
                                    {
                                        IFF = "Squawking=" + ((T_Reveal)action).StartupParameters.Items[c + 1];
                                    }
                                    c++;     //get past the "value" item, which is the even numbered entry
                                }
                            }
                            infoText = String.Format("{0}\tREVEAL; object_id={1}; Owned_by={2}; Revealed_at={3}\r\n", infoText, objectID, ((T_Reveal)action).Owner, ((T_Reveal)action).Location.ToString());
                        }
                        else if (action is T_Move)
                        {
                            stimType = "Move";
                            objectID = ((T_Move)action).ID;
                            infoText = String.Format("{0}\tMOVE; object_id={1}; Throttle={2:0.00}; Destination={3}\r\n", infoText, objectID, ((T_Move)action).Throttle, ((T_Move)action).Location.ToString());
                        }
                        else if (action is T_ScriptedItem)
                        {
                            //TODO: check to see that the object is not dead -Lisa
                            objectID = ((T_ScriptedItem)action).ID;
                            stimType = ((T_ScriptedItem)action).ActionType;
                        }

                        if (stimType != "")
                        {
                            _ddd.SendStimulusEvent(i.ID, i.DM_ID, objectID, stimType, time, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty);
                        }
                    }
                    AppendToInfoBox(tbInfoBox, infoText);
                    _readyToSendItems = false;    //re-set for next time;
                }
            }
            catch (Exception ex)
            {
                ErrorWindow.ShowDialog(ex, this);
            }
        }
Beispiel #9
0
        private void SendItem(T_Item item, String dmId, int time)
        {
            //AppendToInfoBox(tbInfoBox, String.Format("{3}: Next Item ({4}) selected for {0}: FindFixDifficulty={1}, TrackTargetDifficulty={2}\r\n", dmId, nextItem.Parameters.FF_Difficulty, nextItem.Parameters.TT_Difficulty, time, nextItem.ID));
            String infoText = String.Format("{3}: Next Item ({4}) selected for {0}: FindFixDifficulty={1}, TrackTargetDifficulty={2}\r\n", dmId, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty, time, item.ID);

            _ddd.SendItemInfo(dmId, item.ID, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty, time);
            StringBuilder sb = new StringBuilder();

            if (item.Parameters.Crossing)
            {
                sb.AppendFormat("Crossing;");
            }
            else
            {
                sb.AppendFormat("Non-Crossing;");
            }
            if (item.Parameters.Groupings == T_Groupings.Two)
            {
                sb.AppendFormat("Two-Grouping;");
            }
            else
            {
                sb.AppendFormat("One-Grouping;");
            }
            if (item.Parameters.PlayerResources == T_ResourceAvailability.Available)
            {
                sb.AppendFormat("PlayerHasResources;");
            }
            else
            {
                sb.AppendFormat("PlayerHas_NO_Resources;");
            }
            if (item.Parameters.TeammateResources == T_ResourceAvailability.Available)
            {
                sb.AppendFormat("TeammateHasResources;");
            }
            else
            {
                sb.AppendFormat("TeammateHas_NO_Resources;");
            }
            // if (item.Parameters.ThreatTypeSpecified)
            // {
            if (item.Parameters.ThreatType == T_ThreatType.Imminent)
            {
                sb.AppendFormat("Imminent;");
            }
            else
            {
                sb.AppendFormat("Non-imminent;");
            }
            //}
            if (item.Parameters.Threat == T_Threat.Ambiguous)
            {
                sb.AppendFormat("AmbiguousThreat;");
            }
            else if (item.Parameters.Threat == T_Threat.Unambiguous)
            {
                sb.AppendFormat("UnambiguousThreat;");
            }
            else
            {
                sb.AppendFormat("Non-Threat;");
            }

            infoText = String.Format("{0}\t{1}\r\n", infoText, sb.ToString());
            if (item.Action.Count() == 0)
            {
                PirateGenerator pirateGenerator = new PirateGenerator(_ddd);
                pirateGenerator.Generate(item, dmId);

                MerchantGenerator merchantGenerator = new MerchantGenerator(_ddd);
                merchantGenerator.Generate(item, dmId);

                CourseGenerator courseGenerator = new CourseGenerator(_ddd);
                courseGenerator.Generate(item, dmId);

                InterceptGenerator interceptGenerator = new InterceptGenerator(_ddd);
                interceptGenerator.Generate(item, dmId);
            }


            foreach (ActionBase action in item.Action)
            {
                if (action != null && !(action is T_ScriptedItem))
                {
                    _ddd.AddDDDEventToQueue(action.ToDDDEvent(_time, _ddd));
                }

                //ADAMS STUB: Might not work 100%, Lisa please fix if it won't work.
                String stimType = "";
                String objectID = "";
                if (action is T_Reveal)
                {
                    stimType = "Reveal";
                    objectID = ((T_Reveal)action).ID;
                    if (((T_Reveal)action).Location.Item is Aptima.Asim.DDD.CommonComponents.DataTypeTools.LocationValue)
                    {
                        if (((Aptima.Asim.DDD.CommonComponents.DataTypeTools.LocationValue)((T_Reveal)action).Location.Item).exists == false)
                        {
                            Console.WriteLine("Uh oh, null location");
                        }
                    }
                    String IFF = "";
                    if (((T_Reveal)action).StartupParameters.Items.Length > 0)
                    {
                        for (int c = 0; c < ((T_Reveal)action).StartupParameters.Items.Length; c++)
                        {
                            if (((T_Reveal)action).StartupParameters.Items[c] == "ObjectName")
                            {
                                IFF = "Squawking=" + ((T_Reveal)action).StartupParameters.Items[c + 1];
                            }
                            c++; //get past the "value" item, which is the even numbered entry
                        }
                    }
                    infoText = String.Format("{0}\tREVEAL; object_id={1}; Owned_by={2}; Revealed_at={3}\r\n", infoText, objectID, ((T_Reveal)action).Owner, ((T_Reveal)action).Location.ToString());
                }
                else if (action is T_Move)
                {
                    stimType = "Move";
                    objectID = ((T_Move)action).ID;
                    infoText = String.Format("{0}\tMOVE; object_id={1}; Throttle={2:0.00}; Destination={3}\r\n", infoText, objectID, ((T_Move)action).Throttle, ((T_Move)action).Location.ToString());
                }
                else if (action is T_ScriptedItem)
                {
                    //TODO: check to see that the object is not dead -Lisa
                    objectID = ((T_ScriptedItem)action).ID;
                    stimType = ((T_ScriptedItem)action).ActionType;
                }

                if (stimType != "")
                {
                    _ddd.SendStimulusEvent(item.ID, dmId, objectID, stimType, _time, item.Parameters.FF_Difficulty, item.Parameters.TT_Difficulty);
                }
            }
            AppendToInfoBox(tbInfoBox, infoText);
        }