Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private void TimeTick(int time)
        {
            //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);
            if (itemsToProcess == null)
            {
                return;
            }
            foreach (ScheduledItem i in itemsToProcess)
            {
                //i.DM_ID;
                if (_items.ContainsKey(i.ID))
                {
                    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(_items[i.ID].DeepCopy());
                    T_Item        item = _items[i.ID].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)
                    {
                        List <DDDAdapter.SeamateObject> itemsTriedInThreatGenerator = new List <DDDAdapter.SeamateObject>();
                        while (true)
                        {
                            //Threat generator -- generates or chooses ONE pirate or friendly vessel in DM domain
                            //So either creates a RevealEvent or chooses existing vessel, always makes MoveEvent
                            //Location of this vessel is determined here.
                            ThreatGenerator thrg = new ThreatGenerator(_ddd);
                            itemsTriedInThreatGenerator = thrg.GenerateWithTriedItems(item, i.DM_ID, itemsTriedInThreatGenerator);

                            //Make extra merchants, ensuring at least one if "imminent" threat.  Choose locations for them all. (or choose them by location if reusing)
                            GroupingGenerator gg = new GroupingGenerator(_ddd);
                            gg.Generate(item, i.DM_ID);

                            // For each vessel, picks course/destination, IFF, and speed based on ambiguity table, grouping, and crossing constraints.
                            AmbiguityGenerator ag = new AmbiguityGenerator(_ddd);
                            bool worked           = ag.SpecialGenerate(item, i.DM_ID);
                            if (worked)
                            {
                                break;
                            }
                            else
                            {
                                item.Action = new object[0];
                            }
                        }

                        //Intercept course plotted if necessary, now we know all the other vessels and their positions and courses.
                        ThreatTypeGenerator ttg = new ThreatTypeGenerator(_ddd);
                        ttg.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);
                        }
                    }
                    AppendToInfoBox(tbInfoBox, infoText);
                }
            }
        }
Ejemplo n.º 3
0
 public static bool LoadFromFile(string fileName, out T_Item obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
0
 public static bool Deserialize(string xml, out T_Item obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
Ejemplo n.º 6
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;
     }
 }