Ejemplo n.º 1
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var operand = (VMGotoRelativePositionOperand)args;

            var obj = context.StackObject;
            var avatar = (VMAvatar)context.Caller;

            if (obj.Position == LotTilePos.OUT_OF_WORLD) return VMPrimitiveExitCode.GOTO_FALSE;

            var slot = new SLOTItem { Type = 3, Standing = 1 };

            if (operand.Location != VMGotoRelativeLocation.OnTopOf) { //default slot is on top of
                slot.MinProximity = 16;
                slot.MaxProximity = 24;
                if (operand.Location == VMGotoRelativeLocation.AnywhereNear) slot.Rsflags |= (SLOTFlags)255;
                else slot.Rsflags |= (SLOTFlags)(1 << (((int)operand.Location) % 8));
            }

            if (operand.Direction == VMGotoRelativeDirection.AnyDirection) slot.Facing = SLOTFacing.FaceAnywhere; //TODO: verify. not sure where this came from?
            else slot.Facing = (SLOTFacing)operand.Direction;

            var pathFinder = context.Thread.PushNewRoutingFrame(context, !operand.NoFailureTrees);
            var success = pathFinder.InitRoutes(slot, context.StackObject);

            return VMPrimitiveExitCode.CONTINUE;
        }
Ejemplo n.º 2
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var operand = (VMSnapOperand)args;
            var avatar = context.Caller; //todo, can sometimes be an object?? see roaches object tile movement, snaps to its own routing slot
            var obj = context.StackObject;

            SLOTItem slot = null;

            switch (operand.Mode)
            {
                case VMSnapSlotScope.StackVariable:
                    slot = VMMemory.GetSlot(context, VMSlotScope.StackVariable, operand.Index);
                    break;
                case VMSnapSlotScope.BeContained:
                    return (context.StackObject.PlaceInSlot(context.Caller, 0, true, context.VM.Context)) ? VMPrimitiveExitCode.GOTO_TRUE:VMPrimitiveExitCode.GOTO_FALSE;
                case VMSnapSlotScope.InFront:
                    slot = new SLOTItem { Type = 3, Standing = 1, MinProximity = 16, Rsflags = SLOTFlags.NORTH };
                    break;
                case VMSnapSlotScope.Literal:
                    slot = VMMemory.GetSlot(context, VMSlotScope.Literal, operand.Index);
                    break;
                case VMSnapSlotScope.Global:
                    slot = VMMemory.GetSlot(context, VMSlotScope.Global, operand.Index);
                    break;
            }

            if (operand.Mode != VMSnapSlotScope.BeContained)
            {
                var parser = new VMSlotParser(slot);
                var locations = parser.FindAvaliableLocations(obj, context.VM.Context, avatar);
                if (slot.SnapTargetSlot > -1)
                {
                    if (!context.StackObject.PlaceInSlot(context.Caller, slot.SnapTargetSlot, true, context.VM.Context)) return VMPrimitiveExitCode.GOTO_FALSE;
                    if (locations.Count > 0) avatar.RadianDirection = ((slot.Rsflags & SLOTFlags.SnapToDirection) > 0) ? locations[0].RadianDirection: avatar.RadianDirection;
                }
                else
                {
                    if (locations.Count > 0)
                    {
                        if (!SetPosition(avatar, locations[0].Position,
                            ((slot.Rsflags & SLOTFlags.SnapToDirection) > 0) ? locations[0].RadianDirection : avatar.RadianDirection,
                            context.VM.Context))
                            return VMPrimitiveExitCode.GOTO_FALSE;
                    }
                    else
                    {
                        avatar.SetValue(VMStackObjectVariable.PrimitiveResultID, (parser.Blocker == null) ? (short)0 : parser.Blocker.ObjectID);
                        return VMPrimitiveExitCode.GOTO_FALSE;
                    }
                }
            }
            return VMPrimitiveExitCode.GOTO_TRUE;
        }
Ejemplo n.º 3
0
        public static void SerializeInto(SLOTItem item, BinaryWriter writer)
        {
            writer.Write(item.Type);
            writer.Write(item.Offset.X);
            writer.Write(item.Offset.Y);
            writer.Write(item.Offset.Z);

            writer.Write(item.Standing);
            writer.Write(item.Sitting);
            writer.Write(item.Ground);
            writer.Write((int)item.Rsflags);
            writer.Write(item.SnapTargetSlot);
            writer.Write(item.MinProximity);
            writer.Write(item.MaxProximity);
            writer.Write(item.OptimalProximity);
            writer.Write(item.Gradient);
            writer.Write((int)item.Facing);
            writer.Write(item.Resolution);
            writer.Write(item.Height);
        }
Ejemplo n.º 4
0
        public static SLOTItem Deserialize(BinaryReader reader)
        {
            var result = new SLOTItem();
            result.Type = reader.ReadUInt16();
            result.Offset = new Vector3();
            result.Offset.X = reader.ReadSingle();
            result.Offset.Y = reader.ReadSingle();
            result.Offset.Z = reader.ReadSingle();

            result.Standing = reader.ReadInt32();
            result.Sitting = reader.ReadInt32();
            result.Ground = reader.ReadInt32();
            result.Rsflags = (SLOTFlags)reader.ReadInt32();
            result.SnapTargetSlot = reader.ReadInt32();
            result.MinProximity = reader.ReadInt32();
            result.MaxProximity = reader.ReadInt32();
            result.OptimalProximity = reader.ReadInt32();
            result.Gradient = reader.ReadSingle();
            result.Facing = (SLOTFacing)reader.ReadInt32();
            result.Resolution = reader.ReadInt32();
            result.Height = reader.ReadInt32();
            return result;
        }
Ejemplo n.º 5
0
        public override void Read(IffFile iff,System.IO.Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream,ByteOrder.LITTLE_ENDIAN)){
                var zero    = io.ReadUInt32();
                var version = io.ReadUInt32();
                Version = version;
                var slotMagic = io.ReadBytes(4);
                var numSlots  = io.ReadUInt32();

                /** The span for version 4 is 34.
                 * The span for version 6 is 54.
                 * The span for version 7 is 58.
                 * The span for version 8 is 62.
                 * The span for version 9 is 66.
                 * The span for version 10 is 70.  **/
                for (var i = 0; i < numSlots; i++)
                {
                    var item = new SLOTItem();
                    item.Type   = io.ReadUInt16();
                    item.Offset = new Vector3(
                        io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                        );

                    var standing       = io.ReadInt32();
                    var sitting        = io.ReadInt32();
                    var ground         = io.ReadInt32();
                    var rsflags        = io.ReadInt32();
                    var snaptargetslot = io.ReadInt32();

                    //bonuses (0 means never)
                    item.Standing = standing; //score bonus for standing destinations
                    item.Sitting  = sitting;  //score bonus for sitting destinations
                    item.Ground   = ground;   //score bonus for sitting on ground

                    item.Rsflags        = (SLOTFlags)rsflags;
                    item.SnapTargetSlot = snaptargetslot;

                    if (version >= 6)
                    {
                        var minproximity     = io.ReadInt32();
                        var maxproximity     = io.ReadInt32();
                        var optimalproximity = io.ReadInt32();
                        var i9  = io.ReadInt32();
                        var i10 = io.ReadInt32();

                        item.MinProximity     = minproximity;
                        item.MaxProximity     = maxproximity;
                        item.OptimalProximity = optimalproximity;
                        item.MaxSize          = i9;
                        item.I10 = i10;
                    }

                    if (version <= 9)
                    {
                        item.MinProximity     *= 16;
                        item.MaxProximity     *= 16;
                        item.OptimalProximity *= 16;
                    }

                    if (version >= 7)
                    {
                        item.Gradient = io.ReadFloat();
                    }

                    if (version >= 8)
                    {
                        item.Height = io.ReadInt32();
                    }

                    if (item.Height == 0)
                    {
                        item.Height = 5;                   //use offset height, nonstandard.
                    }
                    if (version >= 9)
                    {
                        item.Facing = (SLOTFacing)io.ReadInt32();
                    }

                    if (version >= 10)
                    {
                        item.Resolution = io.ReadInt32();
                    }

                    if (!Slots.ContainsKey(item.Type))
                    {
                        Slots.Add(item.Type,new List <SLOTItem>());
                    }
                    Slots[item.Type].Add(item);
                    Chronological.Add(item);
                }
            }
        }
Ejemplo n.º 6
0
        public VMSlotParser(SLOTItem slot)
        {
            Slot = slot;
            Flags = slot.Rsflags;

            MinProximity = slot.MinProximity;
            MaxProximity = slot.MaxProximity;
            DesiredProximity = slot.OptimalProximity;

            if (MaxProximity == 0) { MaxProximity = MinProximity; }
            if (DesiredProximity == 0) { DesiredProximity = MinProximity; }
        }
Ejemplo n.º 7
0
        public override void Read(IffFile iff, System.IO.Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN)){
                var zero = io.ReadUInt32();
                var version = io.ReadUInt32();
                var slotMagic = io.ReadBytes(4);
                var numSlots = io.ReadUInt32();

                Slots = new Dictionary<ushort, List<SLOTItem>>();

                /** The span for version 4 is 34.
                 * The span for version 6 is 54.
                 * The span for version 7 is 58.
                 * The span for version 8 is 62.
                 * The span for version 9 is 66.
                 * The span for version 10 is 70.  **/
                for (var i = 0; i < numSlots; i++){
                    io.Mark();

                    var item = new SLOTItem();
                    item.Type = io.ReadUInt16();
                    item.Offset = new Vector3(
                        io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                    );

                    var standing = io.ReadInt32();
                    var sitting = io.ReadInt32();
                    var ground = io.ReadInt32();
                    var rsflags = io.ReadInt32();
                    var snaptargetslot = io.ReadInt32();
                    var minproximity = io.ReadInt32();

                    //bonuses (0 means never)
                    item.Standing = standing; //score bonus for standing destinations
                    item.Sitting = sitting; //score bonus for sitting destinations
                    item.Ground = ground; //score bonus for sitting on ground

                    item.Rsflags = (SLOTFlags)rsflags;
                    item.SnapTargetSlot = snaptargetslot;
                    item.MinProximity = minproximity;

                    if (version >= 6)
                    {
                        var maxproximity = io.ReadInt32();
                        var optimalproximity = io.ReadInt32();
                        var i9 = io.ReadInt32();
                        var i10 = io.ReadInt32();

                        item.MaxProximity = maxproximity;
                        item.OptimalProximity = optimalproximity;
                    }

                    if (version <= 9) {
                        item.MinProximity *= 16;
                        item.MaxProximity *= 16;
                        item.OptimalProximity *= 16;
                    }

                    if (version >= 7) item.Gradient = io.ReadFloat();

                    if (version >= 8) item.Height = io.ReadInt32();

                    //the below cases are just here for breakpoint purposes
                    //TODO: find use cases?
                    if (item.Height == 9) item.Height = 9;

                    if (item.Height == 0) item.Height = 5; //use offset height, nonstandard.

                    if (version >= 9) item.Facing = (SLOTFacing)io.ReadInt32();

                    if (version >= 10) item.Resolution = io.ReadInt32();

                    if (!Slots.ContainsKey(item.Type)) Slots.Add(item.Type, new List<SLOTItem>());
                    Slots[item.Type].Add(item);
                }
            }
        }
Ejemplo n.º 8
0
        public override void Deserialize(BinaryReader reader)
        {
            base.Deserialize(reader);

            var roomN = reader.ReadInt32();
            Rooms = new VMRoomPortal[roomN];
            for (int i=0; i< roomN; i++) Rooms[i] = new VMRoomPortal(reader);

            if (reader.ReadBoolean()) CurrentPortal = new VMRoomPortal(reader);

            var wtLen = reader.ReadInt32();
            if (wtLen > -1)
            {
                WalkTo = new Point[wtLen];
                for (int i = 0; i < wtLen; i++) WalkTo[i] = new Point(reader.ReadInt32(), reader.ReadInt32());
            }

            WalkDirection = reader.ReadDouble();
            TargetDirection = reader.ReadDouble();
            IgnoreRooms = reader.ReadBoolean();

            State = (VMRoutingFrameState)reader.ReadByte();
            PortalTurns = reader.ReadInt32();
            WaitTime = reader.ReadInt32();
            Timeout = reader.ReadInt32();
            Retries = reader.ReadInt32();

            AttemptedChair = reader.ReadBoolean();
            TurnTweak = reader.ReadSingle();
            TurnFrames = reader.ReadInt32();

            MoveTotalFrames = reader.ReadInt32();
            MoveFrames = reader.ReadInt32();
            Velocity = reader.ReadInt32();

            CallFailureTrees = reader.ReadBoolean();

            var igrN = reader.ReadInt32();
            IgnoredRooms = new VMRoomPortal[igrN];
            for (int i = 0; i < igrN; i++) IgnoredRooms[i] = new VMRoomPortal(reader);

            var avaN = reader.ReadInt32();
            AvatarsToConsider = new short[avaN];
            for (int i = 0; i < avaN; i++) AvatarsToConsider[i] = reader.ReadInt16();

            PreviousPosition.Deserialize(reader);
            CurrentWaypoint.Deserialize(reader);

            RoomRouteInvalid = reader.ReadBoolean();

            if (reader.ReadBoolean()) {
                Slot = SLOTItemSerializer.Deserialize(reader);
            }
            Target = reader.ReadInt16();

            var chLen = reader.ReadInt32();
            if (chLen > -1)
            {
                Choices = new VMFindLocationResultMarshal[chLen];
                for (int i = 0; i < chLen; i++)
                {
                    Choices[i] = new VMFindLocationResultMarshal();
                    Choices[i].Deserialize(reader);
                }
            }

            if (reader.ReadBoolean())
            {
                CurRoute = new VMFindLocationResultMarshal();
                CurRoute.Deserialize(reader);
            }
        }
Ejemplo n.º 9
0
        public override void Load(VMStackFrameMarshal input, VMContext context)
        {
            base.Load(input, context);
            var inR = (VMRoutingFrameMarshal)input;

            Rooms = new Stack<VMRoomPortal>();
            for (int i=inR.Rooms.Length-1; i>=0; i--) Rooms.Push(inR.Rooms[i]);
            CurrentPortal = inR.CurrentPortal;

            ParentRoute = GetParentFrame(); //should be able to, since all arrays are generated left to right, including the stacks.

            WalkTo = (inR.WalkTo == null)?null:new LinkedList<Point>(inR.WalkTo);
            WalkDirection = inR.WalkDirection;
            TargetDirection = inR.TargetDirection;
            IgnoreRooms = inR.IgnoreRooms;

            State = inR.State;
            PortalTurns = inR.PortalTurns;
            WaitTime = inR.WaitTime;
            Timeout = inR.Timeout;
            Retries = inR.Retries;

            AttemptedChair = inR.AttemptedChair;
            TurnTweak = inR.TurnTweak;
            TurnFrames = inR.TurnFrames;

            MoveTotalFrames = inR.MoveTotalFrames;
            MoveFrames = inR.MoveFrames;
            Velocity = inR.Velocity;

            CallFailureTrees = inR.CallFailureTrees;

            IgnoredRooms = new HashSet<VMRoomPortal>(inR.IgnoredRooms);
            AvatarsToConsider = new HashSet<VMAvatar>();

            foreach (var avatar in inR.AvatarsToConsider)
                AvatarsToConsider.Add((VMAvatar)context.VM.GetObjectById(avatar));

            PreviousPosition = inR.PreviousPosition;
            CurrentWaypoint = inR.CurrentWaypoint;

            RoomRouteInvalid = inR.RoomRouteInvalid;
            Slot = inR.Slot; //NULLable
            Target = context.VM.GetObjectById(inR.Target); //object id
            if (inR.Choices != null)
            {
                Choices = new List<VMFindLocationResult>();
                foreach (var c in inR.Choices) Choices.Add(new VMFindLocationResult(c, context));
            }
            else Choices = null;
            CurRoute = (inR.CurRoute == null)?null:new VMFindLocationResult(inR.CurRoute, context); //NULLable
        }
Ejemplo n.º 10
0
        public bool InitRoutes(SLOTItem slot, VMEntity target)
        {
            Init();

            Slot = slot;
            Target = target;
            var found = AttemptRoute(null);

            if (found == VMRouteFailCode.Success) return true;
            else HardFail(found, null);
            return false;
        }