Exemplo n.º 1
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var        operand = (VMCreateObjectInstanceOperand)args;
            LotTilePos tpos    = new LotTilePos(LotTilePos.OUT_OF_WORLD);
            Direction  dir;

            switch (operand.Position)
            {
            case VMCreateObjectPosition.UnderneathMe:
            case VMCreateObjectPosition.OnTopOfMe:
                tpos = new LotTilePos(context.Caller.Position);
                dir  = Direction.NORTH;
                break;

            case VMCreateObjectPosition.BelowObjectInLocal:
                tpos = new LotTilePos(context.VM.GetObjectById((short)context.Locals[operand.LocalToUse]).Position);
                dir  = Direction.NORTH;
                break;

            case VMCreateObjectPosition.BelowObjectInStackParam0:
                tpos = new LotTilePos(context.VM.GetObjectById((short)context.Args[0]).Position);
                dir  = Direction.NORTH;
                break;

            case VMCreateObjectPosition.OutOfWorld:
                dir = Direction.NORTH;
                break;

            case VMCreateObjectPosition.InSlot0OfStackObject:
            case VMCreateObjectPosition.InMyHand:
                dir = Direction.NORTH;
                //this object should start in slot 0 of the stack object!
                //we have to create it first tho so hold your horses
                break;

            case VMCreateObjectPosition.InFrontOfStackObject:
            case VMCreateObjectPosition.InFrontOfMe:
                var objp = (operand.Position == VMCreateObjectPosition.InFrontOfStackObject)?context.StackObject:context.Caller;
                tpos = new LotTilePos(objp.Position);
                switch (objp.Direction)
                {
                case FSO.LotView.Model.Direction.SOUTH:
                    tpos.y += 16;
                    break;

                case FSO.LotView.Model.Direction.WEST:
                    tpos.x -= 16;
                    break;

                case FSO.LotView.Model.Direction.EAST:
                    tpos.x += 16;
                    break;

                case FSO.LotView.Model.Direction.NORTH:
                    tpos.y -= 16;
                    break;
                }
                dir = objp.Direction;
                break;

            case VMCreateObjectPosition.NextToMeInDirectionOfLocal:
                tpos = new LotTilePos(context.Caller.Position);
                var udir = context.Locals[operand.LocalToUse];
                dir = Direction.NORTH;
                switch (udir)
                {
                case 0:
                    dir     = Direction.NORTH;
                    tpos.y -= 16;
                    break;

                case 2:
                    dir     = Direction.EAST;
                    tpos.x += 16;
                    break;

                case 4:
                    dir     = Direction.SOUTH;
                    tpos.y += 16;
                    break;

                case 6:
                    dir     = Direction.WEST;
                    tpos.x -= 16;
                    break;
                }
                break;

            default:
                throw new VMSimanticsException("Where do I put this??", context);
            }

            var mobj = context.VM.Context.CreateObjectInstance(operand.GUID, tpos, dir,
                                                               (operand.PassObjectIds && context.StackObject != null) ? (context.StackObject.ObjectID) : (short)0,
                                                               (operand.PassTemp0) ? (context.Thread.TempRegisters[0]) : (operand.PassObjectIds ? context.Caller.ObjectID : (short)0), false);

            if (mobj == null)
            {
                return(VMPrimitiveExitCode.GOTO_FALSE);
            }
            var obj = mobj.Objects[0];

            if (operand.Position == VMCreateObjectPosition.InSlot0OfStackObject)
            {
                context.StackObject.PlaceInSlot(obj, 0, true, context.VM.Context);
            }
            else if (operand.Position == VMCreateObjectPosition.InMyHand)
            {
                context.Caller.PlaceInSlot(obj, 0, true, context.VM.Context);
            }
            else if (operand.Position != VMCreateObjectPosition.OutOfWorld && obj.Position == LotTilePos.OUT_OF_WORLD)
            {
                obj.Delete(true, context.VM.Context);
                return(VMPrimitiveExitCode.GOTO_FALSE);
            }
            if ((operand.Flags & (1 << 6)) > 0)
            {
                var interaction = operand.InteractionCallback;
                if (interaction == 254)
                {
                    var temp = context.Thread.Queue[0].InteractionNumber;
                    if (temp == -1)
                    {
                        throw new VMSimanticsException("Set callback as 'this interaction' when queue item has no interaction number!", context);
                    }
                    interaction = (byte)temp;
                }
                var callback = new VMActionCallback(context.VM, interaction, context.Callee, context.StackObject, context.Caller, true);
                callback.Run(obj);
            }
            else
            {
                context.StackObject = obj;
            }

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
Exemplo n.º 2
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var        operand = (VMCreateObjectInstanceOperand)args;
            LotTilePos tpos    = new LotTilePos(LotTilePos.OUT_OF_WORLD);
            Direction  dir     = Direction.NORTH; //FaceStackObjDir? not used afaik

            switch (operand.Position)
            {
            case VMCreateObjectPosition.UnderneathMe:
            case VMCreateObjectPosition.OnTopOfMe:
                tpos = new LotTilePos(context.Caller.Position);
                dir  = Direction.NORTH;
                break;

            case VMCreateObjectPosition.BelowObjectInLocal:
                tpos = new LotTilePos(context.VM.GetObjectById((short)context.Locals[operand.LocalToUse]).Position);
                dir  = Direction.NORTH;
                break;

            case VMCreateObjectPosition.BelowObjectInStackParam0:
                tpos = new LotTilePos(context.VM.GetObjectById((short)context.Args[0]).Position);
                dir  = Direction.NORTH;
                break;

            case VMCreateObjectPosition.OutOfWorld:
                dir = Direction.NORTH;
                break;

            case VMCreateObjectPosition.InSlot0OfStackObject:
            case VMCreateObjectPosition.InMyHand:
                dir = Direction.NORTH;
                //this object should start in slot 0 of the stack object!
                //we have to create it first tho so hold your horses
                break;

            case VMCreateObjectPosition.InFrontOfStackObject:
            case VMCreateObjectPosition.InFrontOfMe:
                var objp = (operand.Position == VMCreateObjectPosition.InFrontOfStackObject)?context.StackObject:context.Caller;
                tpos = new LotTilePos(objp.Position);
                switch (objp.Direction)
                {
                case FSO.LotView.Model.Direction.SOUTH:
                    tpos.y += 16;
                    break;

                case FSO.LotView.Model.Direction.WEST:
                    tpos.x -= 16;
                    break;

                case FSO.LotView.Model.Direction.EAST:
                    tpos.x += 16;
                    break;

                case FSO.LotView.Model.Direction.NORTH:
                    tpos.y -= 16;
                    break;
                }
                dir = objp.Direction;
                break;

            case VMCreateObjectPosition.NextToMeInDirectionOfLocal:
                tpos = new LotTilePos(context.Caller.Position);
                var udir = context.Locals[operand.LocalToUse];
                dir = Direction.NORTH;
                switch (udir)
                {
                case 0:
                    dir     = Direction.NORTH;
                    tpos.y -= 16;
                    break;

                case 2:
                    dir     = Direction.EAST;
                    tpos.x += 16;
                    break;

                case 4:
                    dir     = Direction.SOUTH;
                    tpos.y += 16;
                    break;

                case 6:
                    dir     = Direction.WEST;
                    tpos.x -= 16;
                    break;
                }
                break;

            default:
                throw new VMSimanticsException("Where do I put this??", context);
            }
            var       guid  = operand.GUID;
            Neighbour neigh = null;

            if (operand.UseNeighbor && context.VM.TS1)
            {
                neigh = Content.Content.Get().Neighborhood.GetNeighborByID(context.StackObjectID);
                if (neigh == null)
                {
                    return(VMPrimitiveExitCode.GOTO_FALSE);
                }
                guid = neigh.GUID;
            }

            var mobj = context.VM.Context.CreateObjectInstance(guid, tpos, dir,
                                                               (operand.PassObjectIds && context.StackObject != null) ? (context.StackObject.ObjectID) : (short)0,
                                                               (operand.PassTemp0) ? (context.Thread.TempRegisters[0]) : (operand.PassObjectIds ? context.Caller.ObjectID : (short)0), false);

            if (mobj == null)
            {
                return(VMPrimitiveExitCode.GOTO_FALSE);
            }
            var obj = mobj.BaseObject;

            if (operand.Position == VMCreateObjectPosition.InSlot0OfStackObject)
            {
                context.StackObject.PlaceInSlot(obj, 0, true, context.VM.Context);
            }
            else if (operand.Position == VMCreateObjectPosition.InMyHand)
            {
                context.Caller.PlaceInSlot(obj, 0, true, context.VM.Context);
            }
            else if (operand.Position == VMCreateObjectPosition.UnderneathMe && obj.Position == LotTilePos.OUT_OF_WORLD)
            {
                foreach (var iobj in mobj.Objects)
                {
                    iobj.IgnoreIntersection = context.Caller.MultitileGroup;
                }
                mobj.ChangePosition(context.Caller.Position, dir, context.VM.Context, Model.VMPlaceRequestFlags.Default);
                foreach (var iobj in mobj.Objects)
                {
                    iobj.IgnoreIntersection = null;
                }
            }

            if (operand.Position != VMCreateObjectPosition.OutOfWorld && obj.Position == LotTilePos.OUT_OF_WORLD && obj.Container == null)
            {
                obj.Delete(true, context.VM.Context);
                return(VMPrimitiveExitCode.GOTO_FALSE);
            }
            if (operand.ReturnImmediately)
            {
                short interaction = operand.InteractionCallback;
                if (interaction == 254 && context.ActionTree)
                {
                    var temp = context.Thread.Queue[0].InteractionNumber;
                    if (temp == -1)
                    {
                        throw new VMSimanticsException("Set callback as 'this interaction' when queue item has no interaction number!", context);
                    }
                    interaction = (short)temp;
                    if (temp < 0)
                    {
                        interaction |= unchecked ((short)0x8000);          //cascade global flag
                    }
                }
                else if (interaction == 252 || interaction == 253)
                {
                    interaction = context.Thread.TempRegisters[0];
                }
                //target is existing stack object. (where we get the interaction/tree from)
                var callback = new VMActionCallback(context.VM, interaction, context.StackObject, context.StackObject,
                                                    context.Caller, true, (operand.InteractionCallback == 252));
                callback.Run(obj);
            }
            else
            {
                context.StackObject = obj;
            }

            if (operand.PersistInDB)
            {
                var vm = context.VM;
                if (vm.GlobalLink != null)
                {
                    vm.GlobalLink.RegisterNewObject(vm, obj, (short objID, uint pid) =>
                    {
                        vm.SendCommand(new VMNetUpdatePersistStateCmd()
                        {
                            ObjectID  = objID,
                            PersistID = pid
                        });
                    });
                }
            }
            if (operand.UseNeighbor)
            {
                ((VMAvatar)(obj)).InheritNeighbor(neigh);
            }

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
        public override VMPrimitiveExitCode Execute(VMStackFrame context)
        {
            var operand = context.GetCurrentOperand<VMCreateObjectInstanceOperand>();
            short x = 0;
            short y = 0;
            sbyte level = 0;
            Direction dir;

            switch (operand.Position)
            {
                case VMCreateObjectPosition.UnderneathMe:
                case VMCreateObjectPosition.OnTopOfMe:
                    var pos = context.Caller.Position;
                    x = (short)pos.X;
                    y = (short)pos.Y;
                    level = 0; //for now..
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.BelowObjectInLocal:
                    var pos2 = context.VM.GetObjectById((short)context.Locals[operand.LocalToUse]).Position;
                    x = (short)pos2.X;
                    y = (short)pos2.Y;
                    level = 0; //for now..
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.OutOfWorld:
                    x = 0; //need a system for out of world objects.
                    y = 0;
                    level = 0; //for now..
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.InSlot0OfStackObject:
                case VMCreateObjectPosition.InMyHand:
                    x = 0; //need a system for out of world objects.
                    y = 0;
                    level = 0; //for no..
                    dir = Direction.NORTH;
                    //this object should start in slot 0 of the stack object!
                    //we have to create it first tho so hold your horses
                    break;
                case VMCreateObjectPosition.InFrontOfStackObject:
                case VMCreateObjectPosition.InFrontOfMe:
                    var objp = (operand.Position == VMCreateObjectPosition.InFrontOfStackObject)?context.StackObject:context.Caller;
                    var location = objp.Position;
                    switch (objp.Direction)
                    {
                        case tso.world.model.Direction.SOUTH:
                            location += new Vector3(0.0f, 1.0f, 0.0f);
                            break;
                        case tso.world.model.Direction.WEST:
                            location += new Vector3(-1.0f, 0.0f, 0.0f);
                            break;
                        case tso.world.model.Direction.EAST:
                            location += new Vector3(1.0f, 0.0f, 0.0f);
                            break;
                        case tso.world.model.Direction.NORTH:
                            location += new Vector3(0.0f, -1.0f, 0.0f);
                            break;
                    }
                    x = (short)Math.Floor(location.X);
                    y = (short)Math.Floor(location.Y);
                    level = 0;
                    dir = objp.Direction;
                    break;
                default:
                    throw new VMSimanticsException("Where do I put this??", context);
            }

            var obj = context.VM.Context.CreateObjectInstance(operand.GUID, x, y, level, dir);

            if (operand.PassObjectIds)
            {
                obj.MainStackOBJ = context.StackObject.ObjectID;
                obj.MainParam = context.Caller.ObjectID;
            }
            if (operand.PassTemp0) obj.MainParam = context.Thread.TempRegisters[0];

            obj.Init(context.VM.Context);

            if (operand.Position == VMCreateObjectPosition.InSlot0OfStackObject) context.StackObject.PlaceInSlot(obj, 0);
            else if (operand.Position == VMCreateObjectPosition.InMyHand) context.Caller.PlaceInSlot(obj, 0);

            if ((operand.Flags & (1 << 6)) > 0)
            {
                var interaction = operand.InteractionCallback;
                if (interaction == 254)
                {
                    var temp = context.Caller.Thread.Queue[0].InteractionNumber;
                    if (temp == -1) throw new VMSimanticsException("Set callback as 'this interaction' when queue item has no interaction number!", context);
                    interaction = (byte)temp;
                }
                var callback = new VMActionCallback(context.VM, interaction, context.Callee, context.StackObject, context.Caller, true);
                callback.Run(obj);
            }
            else context.StackObject = obj;

            return VMPrimitiveExitCode.GOTO_TRUE;
        }
Exemplo n.º 4
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var operand = (VMCreateObjectInstanceOperand)args;
            LotTilePos tpos = new LotTilePos(LotTilePos.OUT_OF_WORLD);
            Direction dir;

            switch (operand.Position)
            {
                case VMCreateObjectPosition.UnderneathMe:
                case VMCreateObjectPosition.OnTopOfMe:
                    tpos = new LotTilePos(context.Caller.Position);
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.BelowObjectInLocal:
                    tpos = new LotTilePos(context.VM.GetObjectById((short)context.Locals[operand.LocalToUse]).Position);
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.BelowObjectInStackParam0:
                    tpos = new LotTilePos(context.VM.GetObjectById((short)context.Args[0]).Position);
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.OutOfWorld:
                    dir = Direction.NORTH;
                    break;
                case VMCreateObjectPosition.InSlot0OfStackObject:
                case VMCreateObjectPosition.InMyHand:
                    dir = Direction.NORTH;
                    //this object should start in slot 0 of the stack object!
                    //we have to create it first tho so hold your horses
                    break;
                case VMCreateObjectPosition.InFrontOfStackObject:
                case VMCreateObjectPosition.InFrontOfMe:
                    var objp = (operand.Position == VMCreateObjectPosition.InFrontOfStackObject)?context.StackObject:context.Caller;
                    tpos = new LotTilePos(objp.Position);
                    switch (objp.Direction)
                    {
                        case FSO.LotView.Model.Direction.SOUTH:
                            tpos.y += 16;
                            break;
                        case FSO.LotView.Model.Direction.WEST:
                            tpos.x -= 16;
                            break;
                        case FSO.LotView.Model.Direction.EAST:
                            tpos.x += 16;
                            break;
                        case FSO.LotView.Model.Direction.NORTH:
                            tpos.y -= 16;
                            break;
                    }
                    dir = objp.Direction;
                    break;
                case VMCreateObjectPosition.NextToMeInDirectionOfLocal:
                    tpos = new LotTilePos(context.Caller.Position);
                    dir = (Direction)context.Locals[operand.LocalToUse];
                    switch (dir)
                    {
                        case FSO.LotView.Model.Direction.SOUTH:
                            tpos.y += 16;
                            break;
                        case FSO.LotView.Model.Direction.WEST:
                            tpos.x -= 16;
                            break;
                        case FSO.LotView.Model.Direction.EAST:
                            tpos.x += 16;
                            break;
                        case FSO.LotView.Model.Direction.NORTH:
                            tpos.y -= 16;
                            break;
                    }
                    break;
                default:
                    throw new VMSimanticsException("Where do I put this??", context);
            }

            var obj = context.VM.Context.CreateObjectInstance(operand.GUID, tpos, dir,
                (operand.PassObjectIds && context.StackObject != null) ? (context.StackObject.ObjectID) : (short)0,
                (operand.PassTemp0) ? (context.Thread.TempRegisters[0]) : (operand.PassObjectIds ? context.Caller.ObjectID : (short)0) , false).Objects[0];

            if (operand.Position == VMCreateObjectPosition.InSlot0OfStackObject) context.StackObject.PlaceInSlot(obj, 0, true, context.VM.Context);
            else if (operand.Position == VMCreateObjectPosition.InMyHand) context.Caller.PlaceInSlot(obj, 0, true, context.VM.Context);

            if ((operand.Flags & (1 << 6)) > 0)
            {
                var interaction = operand.InteractionCallback;
                if (interaction == 254)
                {
                    var temp = context.Caller.Thread.Queue[0].InteractionNumber;
                    if (temp == -1) throw new VMSimanticsException("Set callback as 'this interaction' when queue item has no interaction number!", context);
                    interaction = (byte)temp;
                }
                var callback = new VMActionCallback(context.VM, interaction, context.Callee, context.StackObject, context.Caller, true);
                callback.Run(obj);
            }
            else context.StackObject = obj;

            return VMPrimitiveExitCode.GOTO_TRUE;
        }
Exemplo n.º 5
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context)
        {
            var       operand = context.GetCurrentOperand <VMCreateObjectInstanceOperand>();
            short     x       = 0;
            short     y       = 0;
            sbyte     level   = 0;
            Direction dir;

            switch (operand.Position)
            {
            case VMCreateObjectPosition.UnderneathMe:
            case VMCreateObjectPosition.OnTopOfMe:
                var pos = context.Caller.Position;
                x     = (short)pos.X;
                y     = (short)pos.Y;
                level = 0;     //for now..
                dir   = Direction.NORTH;
                break;

            case VMCreateObjectPosition.BelowObjectInLocal:
                var pos2 = context.VM.GetObjectById((short)context.Locals[operand.LocalToUse]).Position;
                x     = (short)pos2.X;
                y     = (short)pos2.Y;
                level = 0;     //for now..
                dir   = Direction.NORTH;
                break;

            case VMCreateObjectPosition.OutOfWorld:
                x     = 0; //need a system for out of world objects.
                y     = 0;
                level = 0; //for now..
                dir   = Direction.NORTH;
                break;

            case VMCreateObjectPosition.InSlot0OfStackObject:
            case VMCreateObjectPosition.InMyHand:
                x     = 0; //need a system for out of world objects.
                y     = 0;
                level = 0; //for no..
                dir   = Direction.NORTH;
                //this object should start in slot 0 of the stack object!
                //we have to create it first tho so hold your horses
                break;

            case VMCreateObjectPosition.InFrontOfStackObject:
            case VMCreateObjectPosition.InFrontOfMe:
                var objp     = (operand.Position == VMCreateObjectPosition.InFrontOfStackObject)?context.StackObject:context.Caller;
                var location = objp.Position;
                switch (objp.Direction)
                {
                case tso.world.model.Direction.SOUTH:
                    location += new Vector3(0.0f, 1.0f, 0.0f);
                    break;

                case tso.world.model.Direction.WEST:
                    location += new Vector3(-1.0f, 0.0f, 0.0f);
                    break;

                case tso.world.model.Direction.EAST:
                    location += new Vector3(1.0f, 0.0f, 0.0f);
                    break;

                case tso.world.model.Direction.NORTH:
                    location += new Vector3(0.0f, -1.0f, 0.0f);
                    break;
                }
                x     = (short)Math.Floor(location.X);
                y     = (short)Math.Floor(location.Y);
                level = 0;
                dir   = objp.Direction;
                break;

            default:
                throw new Exception("Where do I put this??");
            }

            var obj = context.VM.Context.CreateObjectInstance(operand.GUID, x, y, level, dir);

            if (operand.PassObjectIds)
            {
                obj.MainStackOBJ = context.StackObject.ObjectID;
                obj.MainParam    = context.Caller.ObjectID;
            }
            if (operand.PassTemp0)
            {
                obj.MainParam = context.Thread.TempRegisters[0];
            }

            obj.Init(context.VM.Context);

            if (operand.Position == VMCreateObjectPosition.InSlot0OfStackObject)
            {
                context.StackObject.PlaceInSlot(obj, 0);
            }
            else if (operand.Position == VMCreateObjectPosition.InMyHand)
            {
                context.Caller.PlaceInSlot(obj, 0);
            }

            if ((operand.Flags & (1 << 6)) > 0)
            {
                var interaction = operand.InteractionCallback;
                if (interaction == 254)
                {
                    var temp = context.Caller.Thread.Queue[0].InteractionNumber;
                    if (temp == -1)
                    {
                        throw new Exception("Set callback as 'this interaction' when queue item has no interaction number!");
                    }
                    interaction = (byte)temp;
                }
                var callback = new VMActionCallback(context.VM, interaction, context.Callee, context.StackObject, context.Caller, true);
                callback.Run(obj);
            }
            else
            {
                context.StackObject = obj;
            }

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }