Ejemplo n.º 1
0
        //type 2 will be function callback.

        public void Run(VMEntity cbOwner)
        {
            if (type == 1)
            {
                BHAV       bhav;
                GameObject CodeOwner = null;
                ushort     ActionID;
                TTABFlags  ActionFlags;
                var        global = Interaction < 0;
                Interaction &= 0x7FFF;
                string ActionName = "";
                if (IsTree)
                {
                    ActionFlags = TTABFlags.Leapfrog;
                    ActionID    = (ushort)Interaction;
                }
                else
                {
                    var tt     = global ? vm.Context.GlobalTreeTable : Target.TreeTable;
                    var ttas   = global ? vm.Context.GlobalTTAs : Target.TreeTableStrings;
                    var Action = tt.InteractionByIndex[(byte)Interaction];
                    ActionID    = Action.ActionFunction;
                    ActionFlags = Action.Flags;
                    ActionName  = ttas.GetString((int)Action.TTAIndex);
                }

                bhav = Target.GetBHAVWithOwner(ActionID, vm.Context).bhav;
                if (bhav == null)
                {
                    return;               //???
                }
                if (IsTree)
                {
                    ActionName = bhav.ChunkLabel;
                }

                CodeOwner = Target.Object;
                var routine = vm.Assemble(bhav);
                var args    = new short[4];
                if (SetParam)
                {
                    args[0] = cbOwner.ObjectID;
                }

                Caller.Thread.EnqueueAction(
                    new FSO.SimAntics.Engine.VMQueuedAction
                {
                    Callee            = Target,
                    CodeOwner         = CodeOwner,
                    ActionRoutine     = routine,
                    Name              = ActionName,
                    StackObject       = this.StackObject,
                    Args              = args,
                    InteractionNumber = Interaction,
                    Priority          = (short)VMQueuePriority.Maximum, //not sure if this is meant to be the case!
                    Flags             = ActionFlags
                }
                    );
            }
        }
Ejemplo n.º 2
0
        private void PieButtonClick(UIElement button)
        {
            int index = m_PieButtons.IndexOf((UIButton)button);

            if (index == -1)
            {
                return;              //bail! this isn't meant to happen!
            }
            var action = m_CurrentItem.Children.ElementAt(index);

            HITVM.Get().PlaySoundEvent(UISounds.PieMenuSelect);

            if (action.Category)
            {
                m_CurrentItem = action;
                RenderMenu();
            }
            else
            {
                if (m_Obj == m_Parent.GotoObject)
                {
                    m_Parent.vm.SendCommand(new VMNetGotoCmd
                    {
                        Interaction = action.ID,
                        ActorUID    = m_Caller.PersistID,
                        x           = m_Obj.Position.x,
                        y           = m_Obj.Position.y,
                        level       = m_Obj.Position.Level
                    });
                }
                else
                {
                    if (Debug.IDEHook.IDE != null && ShiftDown)
                    {
                        if (m_Obj.TreeTable.InteractionByIndex.ContainsKey((uint)action.ID))
                        {
                            var    act      = m_Obj.TreeTable.InteractionByIndex[(uint)action.ID];
                            ushort ActionID = act.ActionFunction;

                            var function = m_Obj.GetBHAVWithOwner(ActionID, m_Parent.vm.Context);

                            Debug.IDEHook.IDE.IDEOpenBHAV(
                                function.bhav,
                                m_Obj.Object
                                );
                        }
                    }
                    else
                    {
                        m_Parent.vm.SendCommand(new VMNetInteractionCmd
                        {
                            Interaction = action.ID,
                            ActorUID    = m_Caller.PersistID,
                            CalleeID    = m_Obj.ObjectID,
                            Param0      = action.Param0,
                            Global      = action.Global
                        });
                    }
                }
                HITVM.Get().PlaySoundEvent(UISounds.QueueAdd);
                m_Parent.ClosePie();
            }
        }
Ejemplo n.º 3
0
        private bool PushEntryPoint(int entryPoint, VMEntity ent)
        {
            if (ent.EntryPoints[entryPoint].ActionFunction != 0)
            {
                bool Execute;
                if (ent.EntryPoints[entryPoint].ConditionFunction != 0) //check if we can definitely execute this...
                {
                    var Behavior = ent.GetBHAVWithOwner(ent.EntryPoints[entryPoint].ConditionFunction, VM.Context);
                    Execute = (VMThread.EvaluateCheck(VM.Context, Caller, new VMQueuedAction()
                    {
                        Callee = ent,
                        CodeOwner = Behavior.owner,
                        StackObject = ent,
                        Routine = VM.Assemble(Behavior.bhav),
                    }) == VMPrimitiveExitCode.RETURN_TRUE);

                }
                else
                {
                    Execute = true;
                }

                if (Execute)
                {
                    //push it onto our stack, except now the object owns our soul! when we are returned to we can evaluate the result and determine if the action failed.
                    var Behavior = ent.GetBHAVWithOwner(ent.EntryPoints[entryPoint].ActionFunction, VM.Context);
                    var routine = VM.Assemble(Behavior.bhav);
                    var childFrame = new VMStackFrame
                    {
                        Routine = routine,
                        Caller = Caller,
                        Callee = ent,
                        CodeOwner = Behavior.owner,
                        StackObject = ent
                    };
                    childFrame.Args = new short[routine.Arguments];
                    Thread.Push(childFrame);
                    return true;
                }
                else
                {
                    return false; //could not execute portal function. todo: re-evaluate room route
                }
            }
            else
            {
                return false;
            }
        }