Пример #1
0
 public short GetElemPriority(VMQueuedAction elem, int i)
 {
     return((elem == QueueOwner.Thread.ActiveAction) ?
            (QueueOwner as VMAvatar)?.GetPersonData(SimAntics.Model.VMPersonDataVariable.Priority) ?? elem.Priority
                 : elem.Priority);
 }
Пример #2
0
        public bool ExecuteEntryPoint(int entry,VMContext context,bool runImmediately,VMEntity stackOBJ,short[] args)
        {
            if (entry == 11)
            {
                //user placement, hack to do auto floor removal/placement for stairs
                if (Object.OBJ.LevelOffset > 0 && Position != LotTilePos.OUT_OF_WORLD)
                {
                    var floor      = context.Architecture.GetFloor(Position.TileX,Position.TileY,Position.Level);
                    var placeFlags = (VMPlacementFlags)ObjectData[(int)VMStackObjectVariable.PlacementFlags];
                    if ((placeFlags & VMPlacementFlags.InAir) > 0)
                    {
                        context.Architecture.SetFloor(Position.TileX,Position.TileY,Position.Level,new FloorTile(),true);
                    }
                    if ((placeFlags & VMPlacementFlags.OnFloor) > 0 && (floor.Pattern == 0))
                    {
                        context.Architecture.SetFloor(Position.TileX,Position.TileY,Position.Level,new FloorTile {
                            Pattern = 1
                        },true);
                    }
                }
            }

            bool result = false;

            if (EntryPoints[entry].ActionFunction > 255)
            {
                VMSandboxRestoreState SandboxState = null;
                if (GhostImage && runImmediately)
                {
                    SandboxState = context.VM.Sandbox();
                    for (int i = 0; i < MultitileGroup.Objects.Count; i++)
                    {
                        var obj = MultitileGroup.Objects[i];
                        context.VM.AddEntity(obj);
                    }
                }

                BHAV       bhav;
                GameObject CodeOwner;
                ushort     ActionID = EntryPoints[entry].ActionFunction;
                if (ActionID < 4096)
                { //global
                    bhav = context.Globals.Resource.Get <BHAV>(ActionID);
                }
                else if (ActionID < 8192)
                { //local
                    bhav = Object.Resource.Get <BHAV>(ActionID);
                }
                else
                { //semi-global
                    bhav = SemiGlobal.Get <BHAV>(ActionID);
                }

                CodeOwner = Object;

                if (bhav != null)
                {
                    var routine = context.VM.Assemble(bhav);
                    var action  = new VMQueuedAction
                    {
                        Callee    = this,
                        CodeOwner = CodeOwner,
                        /** Main function **/
                        StackObject = stackOBJ,
                        Routine     = routine,
                        Args        = args
                    };

                    if (runImmediately)
                    {
                        var checkResult = VMThread.EvaluateCheck(context,this,action);
                        result = (checkResult == VMPrimitiveExitCode.RETURN_TRUE);
                    }
                    else
                    {
                        this.Thread.EnqueueAction(action);
                    }
                }

                if (GhostImage && runImmediately)
                {
                    //restore state
                    context.VM.SandboxRestore(SandboxState);
                }
                return(result);
            }
            else
            {
                return(false);
            }
        }