Ejemplo n.º 1
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.º 2
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);
        }