Пример #1
0
        private void OnAdd(AddObjectMessage message)
        {
            var path             = new Path(BaseConstants.EscortAcceleration, new CircularMotion(0, 50, new Angle(0), new Angle(Math.PI / 10), 20, Vector.Zero));
            var selectableObject = new SelectableObject(m_Id.Id, message.Name, path);

            m_SelectableRepo.AddObject(selectableObject);
            m_Renderer.Scene.Add(message.Name, message.Shape);
        }
        private void OnAdd(AddObjectMessage message)
        {
            var path             = new Path(4, new CircularMotion(0, 50, new Angle(0), new Angle(Math.PI / 10), BaseConstants.EscortSpeed, Vector.Zero));
            var selectableObject = new SelectableObject(m_Id.Id, message.Name, path);

            m_Objects.Add(selectableObject);

            m_VesselRepository.Add(new Vessel(selectableObject));
        }
Пример #3
0
 private void OnAdd(AddObjectMessage message)
 {
     Add(message.Name, message.Shape);
 }
Пример #4
0
        /// <summary>
        /// The main interface for communicating between behaviours.  Using polymorphism, we
        /// define a bunch of different messages deriving from BehaviourMessage.  Each behaviour
        /// can then check for particular upcasted messahe types, and either grab some data
        /// from it (set message) or store some data in it (get message).
        /// </summary>
        /// <param name="msg">The message being communicated to the behaviour.</param>
        public override void OnMessage(ref BehaviourMessage msg)
        {
            if (msg is AddObjectMessage)
            {
                AddObjectMessage temp = (AddObjectMessage)msg;

                // The template name is how we will categorize items.
                String newType = temp.mObj_In.pTemplateFileName;

                // Assume that the object was not added to the list.
                Boolean added = false;

                // Index will be needed outside of the loop to figure out where the object
                // was added.
                Int32 index = 0;

                // Loop through ever object in the inventory looking for another object of the
                // same type so that this new object can be grouped in with it.
                for (; index < mObjects.Count; index++)
                {
                    // Objects are grouped by the template that defined them.
                    if (mObjects[index].pTemplateFileName == newType)
                    {
                        // Put the new object at the front of the group. It doesn't need to
                        // be at the front, but it is the quickest/easiest. We may at some point
                        // want it to go at the end of the list, but that won't work in the case
                        // where temp.mDoSelectObj is true.
                        mObjects.Insert(index, temp.mObj_In);

                        // The object has been added so the special handling below can be skipped.
                        added = true;

                        break; // index < mObjects.Count
                    }
                }

                // If the object wasn't added above, it means that there are no other objects of this type
                // yet in the list (including when the list is completely empty). So it needs to be added
                // to the end of the list.
                if (!added)
                {
                    mObjects.Add(temp.mObj_In);
                }

                // If at this point there was no selected object, this new object becomes selected by default.
                if (-1 == mCurrentObject)
                {
                    mCurrentObject = 0;
                }
                else if (true == temp.mDoSelectObj_In)
                {
                    // The message can specifically request that the object added be selected. Since it was inserted
                    // at the front of its group, we just need to update mCurrentObject to be the current index.
                    mCurrentObject = index;
                }
            }
            else if (msg is GetCurrentObjectMessage)
            {
                // Trying to pop with an empty queue is an exception.
                if (0 != mObjects.Count)
                {
                    System.Diagnostics.Debug.Assert(mCurrentObject != -1, "mObjects isn't empty but mCurrentObject is undefined. This should never happen.");

                    // Should never happen.
                    if (-1 == mCurrentObject)
                    {
                        return;
                    }

                    GetCurrentObjectMessage temp = (GetCurrentObjectMessage)msg;

                    // Grab the currently selected object.
                    temp.mObj_Out = mObjects[mCurrentObject];
                    mObjects.RemoveAt(mCurrentObject);

                    // No need to change mCurrentObject as we just removed the object at its index and
                    // so the object that followed it will now become the current object when it inherits
                    // that index in the list.

                    // This can happen when placing the last object in the list while there are still other
                    // types of objects before it.
                    if (mObjects.Count <= mCurrentObject)
                    {
                        mCurrentObject = 0;
                    }

                    // If the list becomes empty set the mCurrentObject back to an undefined so that the
                    // next object added becomes the current object by default.
                    if (0 == mObjects.Count)
                    {
                        mCurrentObject = -1;
                    }
                }
            }
            else if (msg is PeekCurrentObjectMessage)
            {
                if (0 != mObjects.Count)
                {
                    System.Diagnostics.Debug.Assert(mCurrentObject != -1, "mObjects isn't empty but mCurrentObject is undefined. This should never happen.");

                    PeekCurrentObjectMessage temp = (PeekCurrentObjectMessage)msg;

                    if (-1 != mCurrentObject)
                    {
                        temp.mObj_Out = mObjects[mCurrentObject];

                        String type = mObjects[mCurrentObject].pTemplateFileName;

                        // We need to also return the number of objects of this type in the inventory.
                        // Since they are sorted in groups we just loop until we reach an item of
                        // a different type.
                        for (Int32 i = mCurrentObject; i < mObjects.Count; i++)
                        {
                            // If its the same type, increase the count.
                            if (mObjects[i].pTemplateFileName == type)
                            {
                                temp.mCount_Out++;
                            }
                            else
                            {
                                // As soon as we hit another type, stop looking.
                                break;
                            }
                        }
                    }
                }
            }
            else if (msg is SelectNextItemMessage)
            {
                if (0 != mObjects.Count)
                {
                    System.Diagnostics.Debug.Assert(mCurrentObject != -1, "mObjects isn't empty but mCurrentObject is undefined. This should never happen.");

                    if (-1 != mCurrentObject)
                    {
                        String type = mObjects[mCurrentObject].pTemplateFileName;

                        Int32 count = mObjects.Count;

                        // The loop is slightly odd. We loop for the number of object in the list, but
                        // we don't use i to index into the array. Instead we are incrementing mCurrentObject
                        // as we go and using that to iterate. Once we hit an object of another type we stop
                        // looping and mCurrentObject is left pointing at the next object of a different type.
                        for (Int32 i = 0; i < count; i++)
                        {
                            mCurrentObject++;

                            // Loop back to the start.
                            if (mCurrentObject >= count)
                            {
                                mCurrentObject = 0;
                            }

                            // If we hit another type, we are done.
                            if (mObjects[mCurrentObject].pTemplateFileName != type)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }