Beispiel #1
0
 /// <summary>
 /// Constructs a new Virtual Machine instance.
 /// </summary>
 /// <param name="context">The VMContext instance to use.</param>
 public VM(VMContext context, VMNetDriver driver, VMHeadlineRendererProvider headline)
 {
     context.VM = this;
     this.Context = context;
     this.Driver = driver;
     Headline = headline;
     OnBHAVChange += VM_OnBHAVChange;
 }
Beispiel #2
0
        public VMArchitecture(int width, int height, Blueprint blueprint, VMContext context)
        {
            this.Context = context;
            this.Width = width;
            this.Height = height;

            var numTiles = width * height;
            this.WallsAt = new List<int>[Stories];
            this.Walls = new WallTile[Stories][];
            this.VisWalls = new WallTile[Stories][];

            this.Floors = new FloorTile[Stories][];
            this.VisFloors = new FloorTile[Stories][];

            this.ObjectSupport = new bool[Stories][]; //true if there's an object support in the specified position
            this.Supported = new bool[Stories-1][]; //no supported array for bottom floor. true if this tile is supported.
            if (blueprint != null) blueprint.Supported = Supported;

            this.Rooms = new VMRoomMap[Stories];

            for (int i = 0; i < Stories; i++)
            {
                this.WallsAt[i] = new List<int>();
                this.Walls[i] = new WallTile[numTiles];
                this.VisWalls[i] = new WallTile[numTiles];

                this.Floors[i] = new FloorTile[numTiles];
                this.VisFloors[i] = new FloorTile[numTiles];
                this.ObjectSupport[i] = new bool[numTiles];

                if (i<Stories-1) this.Supported[i] = new bool[numTiles];

                this.Rooms[i] = new VMRoomMap();
            }

            this.RoomData = new List<VMRoom>();
            this.WorldUI = blueprint;

            this.Commands = new List<VMArchitectureCommand>();
            this.Commands = new List<VMArchitectureCommand>();

            WallsDirty = true;
            FloorsDirty = true;
            RealMode = true;
            Redraw = true;
        }
        public override void Update(UpdateState state)
        {
            base.Update(state);
            if (TempVM == null && GUID != 0)
            {
                var world = new ExternalWorld(GameFacade.GraphicsDevice);
                world.Initialize(GameFacade.Scenes);
                var context = new VMContext(world);

                TempVM = new VM(context, new VMServerDriver(37565, null), new VMNullHeadlineProvider());
                TempVM.Init();

                var blueprint = new Blueprint(1, 1);
                world.InitBlueprint(blueprint);
                context.Blueprint = blueprint;
                context.Architecture = new VMArchitecture(1, 1, blueprint, TempVM.Context);
            }

            if (GUID != oldGUID)
            {
                SetGUIDLocal(GUID);
                state.SharedData["ExternalDraw"] = true;
            }
        }
Beispiel #4
0
        public override void PrePositionChange(VMContext context)
        {
            Footprint = null;
            if (GhostImage && UseWorld)
            {
                if (WorldUI.Container != null)
                {
                    WorldUI.Container = null;
                    WorldUI.ContainerSlot = 0;
                }
                return;
            }
            if (Container != null)
            {
                Container.ClearSlot(ContainerSlot);
                return;
            }
            if (Position == LotTilePos.OUT_OF_WORLD) return;

            context.UnregisterObjectPos(this);
            base.PrePositionChange(context);
        }
Beispiel #5
0
        public override void PlaceInSlot(VMEntity obj, int slot, bool cleanOld, VMContext context)
        {
            if (cleanOld) obj.PrePositionChange(context);

            if (!obj.GhostImage)
            {
                HandObject = obj;

                CarryAnimationState = new VMAnimationState(FSO.Content.Content.Get().AvatarAnimations.Get("a2o-rarm-carry-loop.anim"), false); //set default carry animation

                obj.Container = this;
                obj.ContainerSlot = (short)slot;
            }
            if (UseWorld)
            {
                obj.WorldUI.Container = this.WorldUI;
                obj.WorldUI.ContainerSlot = slot;
                obj.Position = Position; //TODO: is physical position the same as the slot offset position?
                if (obj.WorldUI is ObjectComponent)
                {
                    var objC = (ObjectComponent)obj.WorldUI;
                    objC.ForceDynamic = true;
                }
            }
        }
Beispiel #6
0
        public VMArchitecture(int width, int height, Blueprint blueprint, VMContext context)
        {
            if (Content.Content.Get().TS1)
            {
                DisableClip  = true;
                TerrainLimit = new Rectangle(1, 1, width - 2, height - 2);
            }
            else
            {
                TerrainLimit = new Rectangle(6, 6, 65, 65);
                TerrainLimit.Inflate(-1, -1);
            }

            this.Context = context;
            this.Width   = width;
            this.Height  = height;

            var numTiles = width * height;

            this.WallsAt  = new List <int> [Stories];
            this.Walls    = new WallTile[Stories][];
            this.VisWalls = new WallTile[Stories][];

            this.Floors    = new FloorTile[Stories][];
            this.VisFloors = new FloorTile[Stories][];

            this.ObjectSupport = new bool[Stories][];     //true if there's an object support in the specified position
            this.Supported     = new bool[Stories - 1][]; //no supported array for bottom floor. true if this tile is supported.
            if (blueprint != null)
            {
                blueprint.Supported = Supported;
            }

            this.Rooms   = new VMRoomMap[Stories];
            this.Terrain = new VMArchitectureTerrain(width, height);

            for (int i = 0; i < Stories; i++)
            {
                this.WallsAt[i]  = new List <int>();
                this.Walls[i]    = new WallTile[numTiles];
                this.VisWalls[i] = new WallTile[numTiles];

                this.Floors[i]        = new FloorTile[numTiles];
                this.VisFloors[i]     = new FloorTile[numTiles];
                this.ObjectSupport[i] = new bool[numTiles];

                if (i < Stories - 1)
                {
                    this.Supported[i] = new bool[numTiles];
                }

                this.Rooms[i] = new VMRoomMap();
            }

            this.RoomData = new List <VMRoom>();
            this.WorldUI  = blueprint;

            this.Commands = new List <VMArchitectureCommand>();
            this.Commands = new List <VMArchitectureCommand>();

            WallsDirty  = true;
            FloorsDirty = true;
            RealMode    = true;
            Redraw      = true;
        }
Beispiel #7
0
        public void Load(VMMarshal input)
        {
            var clientJoin = (Context.Architecture == null);
            var oldWorld = Context.World;
            Context = new VMContext(input.Context, Context);
            Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global");
            Context.VM = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();

            var oldSounds = new List<VMSoundTransfer>();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    obj.Dead = true;
                    if (obj.HeadlineRenderer != null) obj.HeadlineRenderer.Dispose();
                    oldSounds.AddRange(obj.GetActiveSounds());
                }
            }

            Entities = new List<VMEntity>();
            ObjectsById = new Dictionary<short, VMEntity>();
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld) Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var obj = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                    Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    obj.Position = obj.Position;
                    realEnt = obj;
                }
                realEnt.GenerateTreeByName(Context);
                Entities.Add(realEnt);
                Context.SetToNextCache.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;
            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);

                if (realEnt is VMAvatar)
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                else
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
            }

            foreach (var multi in input.MultitileGroups)
            {
                new VMMultitileGroup(multi, Context); //should self register
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null) ent.PositionChange(Context, true); //called recursively for contained objects.
            }

            GlobalState = input.GlobalState;
            PlatformState = input.PlatformState;
            ObjectId = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;
            Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));

            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.WallDirtyState(input.Context.Architecture);

            foreach (var snd in oldSounds)
            {
                //find new owners
                var obj = GetObjectById(snd.SourceID);
                if (obj == null || obj.Object.GUID != snd.SourceGUID) snd.SFX.Sound.RemoveOwner(snd.SourceID);
                else obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object
            }

            if (clientJoin)
            {
                //run clientJoin functions to play object sounds, update some gfx.
                foreach (var obj in Entities)
                {
                    obj.ExecuteEntryPoint(30, Context, true);
                }
            }

            if (OnFullRefresh != null) OnFullRefresh();
        }
Beispiel #8
0
 public VMContext(VMContextMarshal input, VMContext oldContext)
     : this(oldContext.World, oldContext)
 {
     Load(input);
 }
Beispiel #9
0
        public virtual void SetIndivPosition(LotTilePos pos, Direction direction, VMContext context, VMPlacementResult info)
        {
            Direction = direction;

            //TODO: clean the f**k up out of OUT_OF_WORLD
            if (UseWorld && this is VMGameObject) context.Blueprint.ChangeObjectLocation((ObjectComponent)WorldUI, (pos==LotTilePos.OUT_OF_WORLD)?LotTilePos.FromBigTile(-1,-1,1):pos);
            Position = pos;
            if (info.Object != null) info.Object.PlaceInSlot(this, 0, false, context);
        }
Beispiel #10
0
 public VMArchitecture(VMArchitectureMarshal input, VMContext context, Blueprint blueprint)
     : this(input.Width, input.Height, blueprint, context)
 {
     Load(input);
 }
        public VMContext(LotView.World world, VMContext oldContext)
        {
            //oldContext is passed in case we need to inherit certain things, like the ambient sound player
            this.World          = world;
            this.Clock          = new VMClock();
            this.SetToNextCache = new VMSetToNextCache(this);

            if (oldContext == null)
            {
                this.Ambience = new VMAmbientSound();
            }
            else
            {
                this.Ambience = oldContext.Ambience;
            }

            RandomSeed           = (ulong)((new Random()).NextDouble() * UInt64.MaxValue); //when resuming state, this should be set.
            Clock.TicksPerMinute = 30;                                                     //1 minute per irl second

            AddPrimitive(new VMPrimitiveRegistration(new VMSleep())
            {
                Opcode       = 0,
                Name         = "sleep",
                OperandModel = typeof(VMSleepOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGenericTSOCall())
            {
                Opcode       = 1,
                Name         = "generic_sims_online_call",
                OperandModel = typeof(VMGenericTSOCallOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMExpression())
            {
                Opcode       = 2,
                Name         = "expression",
                OperandModel = typeof(VMExpressionOperand)
            });

            //TODO: Report Metric

            AddPrimitive(new VMPrimitiveRegistration(new VMGrab())
            {
                Opcode       = 4,
                Name         = "grab",
                OperandModel = typeof(VMGrabOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDrop())
            {
                Opcode       = 5,
                Name         = "drop",
                OperandModel = typeof(VMDropOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMChangeSuitOrAccessory())
            {
                Opcode       = 6,
                Name         = "change_suit_or_accessory",
                OperandModel = typeof(VMChangeSuitOrAccessoryOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRefresh())
            {
                Opcode       = 7,
                Name         = "refresh",
                OperandModel = typeof(VMRefreshOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRandomNumber())
            {
                Opcode       = 8,
                Name         = "random_number",
                OperandModel = typeof(VMRandomNumberOperand)
            });

            //TODO: burn

            //Sims 1.0 tutorial

            AddPrimitive(new VMPrimitiveRegistration(new VMGetDistanceTo())
            {
                Opcode       = 11,
                Name         = "get_distance_to",
                OperandModel = typeof(VMGetDistanceToOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGetDirectionTo())
            {
                Opcode       = 12,
                Name         = "get_direction_to",
                OperandModel = typeof(VMGetDirectionToOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMPushInteraction())
            {
                Opcode       = 13,
                Name         = "push_interaction",
                OperandModel = typeof(VMPushInteractionOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMFindBestObjectForFunction())
            {
                Opcode       = 14,
                Name         = "find_best_object_for_function",
                OperandModel = typeof(VMFindBestObjectForFunctionOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMBreakPoint())
            {
                Opcode       = 15,
                Name         = "breakpoint",
                OperandModel = typeof(VMBreakPointOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMFindLocationFor())
            {
                Opcode       = 16,
                Name         = "find_location_for",
                OperandModel = typeof(VMFindLocationForOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMIdleForInput())
            {
                Opcode       = 17,
                Name         = "idle_for_input",
                OperandModel = typeof(VMIdleForInputOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRemoveObjectInstance())
            {
                Opcode       = 18,
                Name         = "remove_object_instance",
                OperandModel = typeof(VMRemoveObjectInstanceOperand)
            });

            //Make new character

            AddPrimitive(new VMPrimitiveRegistration(new VMRunFunctionalTree())
            {
                Opcode       = 20,
                Name         = "run_functional_tree",
                OperandModel = typeof(VMRunFunctionalTreeOperand)
            });

            //Show string: may be used but no functional result.

            AddPrimitive(new VMPrimitiveRegistration(new VMLookTowards())
            {
                Opcode       = 22,
                Name         = "look_towards",
                OperandModel = typeof(VMLookTowardsOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMPlaySound())
            {
                Opcode       = 23,
                Name         = "play_sound",
                OperandModel = typeof(VMPlaySoundOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRelationship())
            {
                Opcode       = 24,
                Name         = "old_relationship",
                OperandModel = typeof(VMOldRelationshipOperand) //same primitive, different operand
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMTransferFunds())
            {
                Opcode       = 25,
                Name         = "transfer_funds",
                OperandModel = typeof(VMTransferFundsOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRelationship())
            {
                Opcode       = 26,
                Name         = "relationship",
                OperandModel = typeof(VMRelationshipOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGotoRelativePosition())
            {
                Opcode       = 27,
                Name         = "goto_relative",
                OperandModel = typeof(VMGotoRelativePositionOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRunTreeByName())
            {
                Opcode       = 28,
                Name         = "run_tree_by_name",
                OperandModel = typeof(VMRunTreeByNameOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSetMotiveChange())
            {
                Opcode       = 29,
                Name         = "set_motive_deltas",
                OperandModel = typeof(VMSetMotiveChangeOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSysLog())
            {
                Opcode       = 30,
                Name         = "syslog",
                OperandModel = typeof(VMSysLogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSetToNext())
            {
                Opcode       = 31,
                Name         = "set_to_next",
                OperandModel = typeof(VMSetToNextOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMTestObjectType())
            {
                Opcode       = 32,
                Name         = "test_object_type",
                OperandModel = typeof(VMTestObjectTypeOperand)
            });

            //TODO: find 5 worst motives

            //TODO: ui effect (used?)

            AddPrimitive(new VMPrimitiveRegistration(new VMSpecialEffect())
            {
                Opcode       = 35,
                Name         = "special_effect",
                OperandModel = typeof(VMSpecialEffectOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDialogPrivateStrings())
            {
                Opcode       = 36,
                Name         = "dialog_private",
                OperandModel = typeof(VMDialogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMTestSimInteractingWith())
            {
                Opcode       = 37,
                Name         = "test_sim_interacting_with",
                OperandModel = typeof(VMTestSimInteractingWithOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDialogGlobalStrings())
            {
                Opcode       = 38,
                Name         = "dialog_global",
                OperandModel = typeof(VMDialogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDialogSemiGlobalStrings())
            {
                Opcode       = 39,
                Name         = "dialog_semiglobal",
                OperandModel = typeof(VMDialogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMOnlineJobsCall())
            {
                Opcode       = 40,
                Name         = "online_jobs_call",
                OperandModel = typeof(VMOnlineJobsCallOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSetBalloonHeadline())
            {
                Opcode       = 41,
                Name         = "set_balloon_headline",
                OperandModel = typeof(VMSetBalloonHeadlineOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMCreateObjectInstance())
            {
                Opcode       = 42,
                Name         = "create_object_instance",
                OperandModel = typeof(VMCreateObjectInstanceOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDropOnto())
            {
                Opcode       = 43,
                Name         = "drop_onto",
                OperandModel = typeof(VMDropOntoOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMAnimateSim())
            {
                Opcode       = 44,
                Name         = "animate",
                OperandModel = typeof(VMAnimateSimOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGotoRoutingSlot())
            {
                Opcode       = 45,
                Name         = "goto_routing_slot",
                OperandModel = typeof(VMGotoRoutingSlotOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSnap()) //not functional right now
            {
                Opcode       = 46,
                Name         = "snap",
                OperandModel = typeof(VMSnapOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMReach())
            {
                Opcode       = 47,
                Name         = "reach",
                OperandModel = typeof(VMReachOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMStopAllSounds())
            {
                Opcode       = 48,
                Name         = "stop_all_sounds",
                OperandModel = typeof(VMStopAllSoundsOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMNotifyOutOfIdle())
            {
                Opcode       = 49,
                Name         = "stackobj_notify_out_of_idle",
                OperandModel = typeof(VMAnimateSimOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMChangeActionString())
            {
                Opcode       = 50,
                Name         = "change_action_string",
                OperandModel = typeof(VMChangeActionStringOperand)
            });

            //lots of unused primitives. see http://simantics.wikidot.com/wiki:primitives

            //TODO: Send Maxis Letter

            AddPrimitive(new VMPrimitiveRegistration(new VMInvokePlugin())
            {
                Opcode       = 62,
                Name         = "invoke_plugin",
                OperandModel = typeof(VMInvokePluginOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGetTerrainInfo())
            {
                Opcode       = 63,
                Name         = "get_terrain_info",
                OperandModel = typeof(VMGetTerrainInfoOperand)
            });

            //UNUSED: Leave Lot and Goto

            AddPrimitive(new VMPrimitiveRegistration(new VMFindBestAction())
            {
                Opcode       = 65,
                Name         = "find_best_action",
                OperandModel = typeof(VMFindBestActionOperand)
            });

            //TODO: Set Dynamic Object Name

            //TODO: Inventory Operations
        }
 public VMContext(VMContextMarshal input, VMContext oldContext) : this(oldContext.World, oldContext)
 {
     Load(input);
 }
Beispiel #13
0
        public void HollowLoad(VMHollowMarshal input)
        {
            var clientJoin = (Context.Architecture == null);
            var oldWorld   = Context.World;

            input.Context.Ambience.ActiveBits = 0;
            Context    = new VMContext(input.Context, Context);
            Context.VM = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();

            Entities    = new List <VMEntity>();
            ObjectsById = new Dictionary <short, VMEntity>();
            var includedEnts = new List <VMHollowGameObjectMarshal>();

            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = Content.GameContent.Get.WorldObjects.Get(ent.GUID);

                var worldObject = Context.MakeObjectComponent(objDefinition);
                var obj         = new VMGameObject(objDefinition, worldObject);
                obj.HollowLoad(ent);
                if (UseWorld)
                {
                    Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                    Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                }
                obj.Position = obj.Position;
                realEnt      = obj;

                includedEnts.Add(ent);
                Entities.Add(realEnt);
                Context.ObjectQueries.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;

            foreach (var realEnt in Entities)
            {
                var ent = includedEnts[i++];
                ((VMGameObject)realEnt).LoadHollowCrossRef(ent, Context);
            }

            foreach (var multi in input.MultitileGroups)
            {
                new VMMultitileGroup(multi, Context); //should self register
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null)
                {
                    ent.PositionChange(Context, true);                        //called recursively for contained objects.
                }
            }

            input.Context.Architecture.WallsDirty  = true;
            input.Context.Architecture.FloorsDirty = true;
            Context.Architecture.WallDirtyState(input.Context.Architecture);
            Context.Architecture.Tick();
        }
Beispiel #14
0
        public void LoadAsync(VMMarshal input)
        {
            FSOVAsyncLoading = true;
            var lastBp = Context.Blueprint; //try keep this alive I suppose

            //var oldWorld = Context.World;
            //TS1 = input.TS1;
            Context    = new VMContext(input.Context, Context);
            Context.VM = this;
            var idMap = input.Context.Architecture.IDMap;

            if (idMap != null)
            {
                idMap.Apply(this);
            }
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.Terrain.RegenerateCenters();

            if (UseWorld)
            {
                Context.Blueprint.Altitude        = Context.Architecture.Terrain.Heights;
                Context.Blueprint.AltitudeCenters = Context.Architecture.Terrain.Centers;
            }

            var oldSounds = new List <VMSoundTransfer>();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    obj.Dead = true;
                    if (obj.HeadlineRenderer != null)
                    {
                        if (UseWorld)
                        {
                            GameThread.InUpdate(() =>
                            {
                                obj.HeadlineRenderer.Dispose();
                            });
                        }
                    }
                    oldSounds.AddRange(obj.GetActiveSounds());
                }
            }

            SoundEntities = new HashSet <VMEntity>();
            Entities      = new List <VMEntity>();
            Scheduler.Reset();
            ObjectsById  = new Dictionary <short, VMEntity>();
            FSOVObjTotal = input.Entities.Length;
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = Content.GameContent.Get.WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = Context.MakeObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                        Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    }
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.FetchTreeByName(Context);
                Entities.Add(realEnt);
                Context.ObjectQueries.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
                FSOVObjLoaded++;
            }

            int i = 0;

            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);
                Scheduler.ScheduleTickIn(realEnt, 1);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                var grp = new VMMultitileGroup(multi, Context); //should self register
                if (UseWorld)
                {
                    var b      = grp.BaseObject;
                    var avgPos = new LotTilePos();
                    foreach (var obj in grp.Objects)
                    {
                        avgPos += obj.Position;
                    }
                    avgPos /= grp.Objects.Count;

                    foreach (var obj in grp.Objects)
                    {
                        var off = obj.Position - avgPos;
                        obj.WorldUI.MTOffset = new Vector3(off.x, off.y, 0);
                        obj.Position         = obj.Position;
                    }
                }
                var persist = grp.BaseObject?.PersistID ?? 0;
                if (persist != 0 && grp.BaseObject is VMGameObject)
                {
                    Context.ObjectQueries.RegisterMultitilePersist(grp, persist);
                }
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null)
                {
                    ent.PositionChange(Context, true);                        //called recursively for contained objects.
                }
            }

            GlobalState = input.GlobalState;
            if (TS1)
            {
                ((VMTS1LotState)input.PlatformState).CurrentFamily = TS1State.CurrentFamily;
            }
            PlatformState = input.PlatformState;
            ObjectId      = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay();

            Context.Architecture.SignalAllDirty();
            Context.DisableRouteInvalidation = true;
            Context.Architecture.Tick();
            Context.DisableRouteInvalidation = false;

            Context.Architecture.WallDirtyState(input.Context.Architecture);

            if (oldSounds.Count > 0)
            {
                GameThread.InUpdate(() =>
                {
                    foreach (var snd in oldSounds)
                    {
                        //find new owners
                        var obj = GetObjectById(snd.SourceID);
                        if (obj == null || obj.Object.GUID != snd.SourceGUID)
                        {
                            snd.SFX.Sound.RemoveOwner(snd.SourceID);
                        }
                        else
                        {
                            SoundEntities.Add(obj);
                            obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object
                        }
                    }
                });
            }

            Context.UpdateTSOBuildableArea();
            Tuning = input.Tuning;
            UpdateTuning();
            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }
Beispiel #15
0
 public override void LoadCrossRef(VMEntityMarshal input, VMContext context)
 {
     base.LoadCrossRef(input, context);
 }
Beispiel #16
0
        public override void PositionChange(VMContext context, bool noEntryPoint)
        {
            for (int i = 0; i < Contained.Length; i++)
            {
                if (Contained[i] != null)
                {
                    context.UnregisterObjectPos(Contained[i]);
                    Contained[i].Position = Position;
                    Contained[i].PositionChange(context, noEntryPoint); //recursive
                }
            }
            if (GhostImage)
            {
                return;
            }

            var room = context.GetObjectRoom(this);

            SetRoom(room);

            context.RegisterObjectPos(this);

            if (Container != null)
            {
                return;
            }
            if (Position == LotTilePos.OUT_OF_WORLD)
            {
                return;
            }

            var arch = context.Architecture;

            if (((VMEntityFlags2)ObjectData[(int)VMStackObjectVariable.FlagField2] & (VMEntityFlags2.ArchitectualWindow | VMEntityFlags2.ArchitectualDoor)) > 0)
            {     //if wall or door, attempt to place style on wall
                if (Object.OBJ.WallStyle > 21 && Object.OBJ.WallStyle < 256)
                { //first thing's first, is the style between 22-255 inclusive? If it is, then the style is stored in the object. Need to load its sprites and change the id for the objd.
                    var id   = Object.OBJ.WallStyleSpriteID;
                    var sprs = new SPR[6];
                    for (int i = 0; i < 6; i++)
                    {
                        sprs[i] = Object.Resource.Get <SPR>((ushort)(id + i));
                        if (sprs[i] != null)
                        {
                            sprs[i].WallStyle = true;
                        }
                    }
                    var style = new WallStyle()
                    {
                        WallsUpFar      = sprs[0],
                        WallsUpMedium   = sprs[1],
                        WallsUpNear     = sprs[2],
                        WallsDownFar    = sprs[3],
                        WallsDownMedium = sprs[4],
                        WallsDownNear   = sprs[5]
                    };
                    Object.OBJ.WallStyle = FSO.Content.Content.Get().WorldWalls.AddDynamicWallStyle(style);
                }

                var placeFlags = (WallPlacementFlags)ObjectData[(int)VMStackObjectVariable.WallPlacementFlags];
                var dir        = DirectionToWallOff(Direction);
                if ((placeFlags & WallPlacementFlags.WallRequiredInFront) > 0)
                {
                    SetWallStyle((dir) % 4, arch, Object.OBJ.WallStyle);
                }
                if ((placeFlags & WallPlacementFlags.WallRequiredOnRight) > 0)
                {
                    SetWallStyle((dir + 1) % 4, arch, Object.OBJ.WallStyle);
                }
                if ((placeFlags & WallPlacementFlags.WallRequiredBehind) > 0)
                {
                    SetWallStyle((dir + 2) % 4, arch, Object.OBJ.WallStyle);
                }
                if ((placeFlags & WallPlacementFlags.WallRequiredOnLeft) > 0)
                {
                    SetWallStyle((dir + 3) % 4, arch, Object.OBJ.WallStyle);
                }
            }
            var exclusive = GetValue(VMStackObjectVariable.ExclusivePlacementFlags);

            SetWallUse(arch, true, ((exclusive & 2) > 0));
            if (GetValue(VMStackObjectVariable.Category) == 8)
            {
                context.Architecture.SetObjectSupported(Position.TileX, Position.TileY, Position.Level, true);
            }

            if (EntryPoints[8].ActionFunction != 0)
            {
                UpdateDynamicMultitile(context);
            }

            base.PositionChange(context, noEntryPoint);
        }
Beispiel #17
0
        public override void PlaceInSlot(VMEntity obj, int slot, bool cleanOld, VMContext context)
        {
            if (cleanOld) obj.PrePositionChange(context);

            if (Contained != null)
            {
                if (slot > -1 && slot < Contained.Length)
                {
                    if (!obj.GhostImage)
                    {
                        Contained[slot] = obj;
                        obj.Container = this;
                        obj.ContainerSlot = (short)slot;
                    }

                    if (UseWorld)
                    {
                        obj.WorldUI.Container = this.WorldUI;
                        obj.WorldUI.ContainerSlot = slot;
                    }
                    obj.Position = Position; //TODO: is physical position the same as the slot offset position?
                }
            }
        }
Beispiel #18
0
        public override void PrePositionChange(VMContext context)
        {
            Footprint = null;
            if (GhostImage && UseWorld)
            {
                if (WorldUI.Container != null)
                {
                    WorldUI.Container = null;
                    WorldUI.ContainerSlot = 0;
                }
                return;
            }
            if (Container != null)
            {
                Container.ClearSlot(ContainerSlot);
                return;
            }
            if (Position == LotTilePos.OUT_OF_WORLD) return;

            var arch = context.Architecture;
            if (((VMEntityFlags2)ObjectData[(int)VMStackObjectVariable.FlagField2] & (VMEntityFlags2.ArchitectualWindow | VMEntityFlags2.ArchitectualDoor)) > 0)
            { //if wall or door, attempt to place style on wall
                var placeFlags = (WallPlacementFlags)ObjectData[(int)VMStackObjectVariable.WallPlacementFlags];
                var dir = DirectionToWallOff(Direction);
                if ((placeFlags & WallPlacementFlags.WallRequiredInFront) > 0) SetWallStyle((dir) % 4, arch, 0);
                if ((placeFlags & WallPlacementFlags.WallRequiredOnRight) > 0) SetWallStyle((dir + 1) % 4, arch, 0);
                if ((placeFlags & WallPlacementFlags.WallRequiredBehind) > 0) SetWallStyle((dir + 2) % 4, arch, 0);
                if ((placeFlags & WallPlacementFlags.WallRequiredOnLeft) > 0) SetWallStyle((dir + 3) % 4, arch, 0);
            }
            SetWallUse(arch, false);
            if (GetValue(VMStackObjectVariable.Category) == 8) context.Architecture.SetObjectSupported(Position.TileX, Position.TileY, Position.Level, false);

            context.UnregisterObjectPos(this);
            base.PrePositionChange(context);
        }
Beispiel #19
0
        public void SetAvatarBodyStrings(STR data, VMContext context)
        {
            if (data == null)
            {
                return;
            }

            var body     = data.GetString(1);
            var randBody = data.GetString(10);

            var gender = data.GetString(12);
            var genVar = (int)VMPersonDataVariable.Gender;

            try
            {
                if (randBody != "")
                {
                    var bodySpl = randBody.Split(';');
                    DefaultSuits.Daywear = Convert.ToUInt64(bodySpl[context.NextRandom((ulong)bodySpl.Length - 1)], 16);
                }
                else if (body != "")
                {
                    DefaultSuits.Daywear = Convert.ToUInt64(body, 16);
                }

                BodyOutfit = DefaultSuits.Daywear;

                var head     = data.GetString(2);
                var randHead = data.GetString(9);

                if (randHead != "")
                {
                    var headSpl = randHead.Split(';');
                    HeadOutfit = Convert.ToUInt64(headSpl[context.NextRandom((ulong)headSpl.Length - 1)], 16);
                }
                else if (head != "")
                {
                    HeadOutfit = Convert.ToUInt64(head, 16);
                }
            }
            catch
            {
                //head or body invalid, resort to default.
                HeadOutfit = SetAvatarRandomOutfit(1);
                BodyOutfit = SetAvatarRandomOutfit(0);
            }


            if (gender.Equals("male", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 0;
            }
            else if (gender.Equals("female", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 1;
            }
            else if (gender.Equals("dogmale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 8;
            }
            else if (gender.Equals("dogfemale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 9;
            }
            else if (gender.Equals("catmale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 16;
            }
            else if (gender.Equals("catfemale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 17;
            }

            var names = data.GetString(11);

            if (names != "")
            {
                var nameSpl = names.Split(';');
                Name = nameSpl[context.NextRandom((ulong)nameSpl.Length)];
            }

            PersonData[(int)VMPersonDataVariable.PersonsAge] = Convert.ToInt16(data.GetString(13));

            var skinTone = data.GetString(14);

            if (skinTone.Equals("lgt", StringComparison.InvariantCultureIgnoreCase))
            {
                SkinTone = AppearanceType.Light;
            }
            else if (skinTone.Equals("med", StringComparison.InvariantCultureIgnoreCase))
            {
                SkinTone = AppearanceType.Medium;
            }
            else if (skinTone.Equals("drk", StringComparison.InvariantCultureIgnoreCase))
            {
                SkinTone = AppearanceType.Dark;
            }
        }
Beispiel #20
0
        public void Load(VMMarshal input)
        {
            var clientJoin = (Context.Architecture == null);
            var oldWorld   = Context.World;

            Context         = new VMContext(input.Context, Context);
            Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global");
            Context.VM      = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();

            var oldSounds = new List <VMSoundTransfer>();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    obj.Dead = true;
                    if (obj.HeadlineRenderer != null)
                    {
                        obj.HeadlineRenderer.Dispose();
                    }
                    oldSounds.AddRange(obj.GetActiveSounds());
                }
            }

            Entities    = new List <VMEntity>();
            ObjectsById = new Dictionary <short, VMEntity>();
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                    Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.GenerateTreeByName(Context);
                Entities.Add(realEnt);
                Context.SetToNextCache.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;

            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                new VMMultitileGroup(multi, Context); //should self register
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null)
                {
                    ent.PositionChange(Context, true);                        //called recursively for contained objects.
                }
            }

            GlobalState   = input.GlobalState;
            PlatformState = input.PlatformState;
            ObjectId      = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));

            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.WallDirtyState(input.Context.Architecture);

            foreach (var snd in oldSounds)
            {
                //find new owners
                var obj = GetObjectById(snd.SourceID);
                if (obj == null || obj.Object.GUID != snd.SourceGUID)
                {
                    snd.SFX.Sound.RemoveOwner(snd.SourceID);
                }
                else
                {
                    obj.SoundThreads.Add(snd.SFX);  // successfully transfer sound to new object
                }
            }

            if (clientJoin)
            {
                //run clientJoin functions to play object sounds, update some gfx.
                foreach (var obj in Entities)
                {
                    obj.ExecuteEntryPoint(30, Context, true);
                }
            }

            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }
Beispiel #21
0
        public VMBHAVOwnerPair GetBHAVWithOwner(ushort ActionID, VMContext context)
        {
            BHAV bhav;
            GameObject CodeOwner;
            if (ActionID < 4096)
            { //global
                bhav = context.Globals.Resource.Get<BHAV>(ActionID);
                //CodeOwner = context.Globals.Resource;
            }
            else if (ActionID < 8192)
            { //local
                bhav = Object.Resource.Get<BHAV>(ActionID);

            }
            else
            { //semi-global
                bhav = SemiGlobal.Resource.Get<BHAV>(ActionID);
                //CodeOwner = SemiGlobal.Resource;
            }

            CodeOwner = Object;

            if (bhav == null) throw new Exception("Invalid BHAV call!");
            return new VMBHAVOwnerPair(bhav, CodeOwner);
        }
Beispiel #22
0
 public virtual VMPlacementResult SetPosition(LotTilePos pos, Direction direction, VMContext context)
 {
     return MultitileGroup.ChangePosition(pos, direction, context);
 }
Beispiel #23
0
        public virtual void Init(VMContext context)
        {
            GenerateTreeByName(context);
            if (!GhostImage) this.Thread = new VMThread(context, this, this.Object.OBJ.StackSize);

            ExecuteEntryPoint(0, context, true); //Init

            if (!GhostImage)
            {
                short[] Args = null;
                VMEntity StackOBJ = null;
                if (MainParam != 0)
                {
                    Args = new short[4];
                    Args[0] = MainParam;
                    MainParam = 0;
                }
                if (MainStackOBJ != 0)
                {
                    StackOBJ = context.VM.GetObjectById(MainStackOBJ);
                    MainStackOBJ = 0;
                }

                ExecuteEntryPoint(1, context, false, StackOBJ, Args); //Main
            }
        }
Beispiel #24
0
        public VMContext(LotView.World world, VMContext oldContext)
        {
            //oldContext is passed in case we need to inherit certain things, like the ambient sound player
            this.World = world;
            this.Clock = new VMClock();
            this.SetToNextCache = new VMSetToNextCache(this);

            if (oldContext == null)
            {
                this.Ambience = new VMAmbientSound();
            } else
            {
                this.Ambience = oldContext.Ambience;
            }

            RandomSeed = (ulong)((new Random()).NextDouble() * UInt64.MaxValue); //when resuming state, this should be set.
            Clock.TicksPerMinute = 30; //1 minute per irl second

            AddPrimitive(new VMPrimitiveRegistration(new VMSleep())
            {
                Opcode = 0,
                Name = "sleep",
                OperandModel = typeof(VMSleepOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGenericTSOCall())
            {
                Opcode = 1,
                Name = "generic_sims_online_call",
                OperandModel = typeof(VMGenericTSOCallOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMExpression())
            {
                Opcode = 2,
                Name = "expression",
                OperandModel = typeof(VMExpressionOperand)
            });

            //TODO: Report Metric

            AddPrimitive(new VMPrimitiveRegistration(new VMGrab())
            {
                Opcode = 4,
                Name = "grab",
                OperandModel = typeof(VMGrabOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDrop())
            {
                Opcode = 5,
                Name = "drop",
                OperandModel = typeof(VMDropOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMChangeSuitOrAccessory())
            {
                Opcode = 6,
                Name = "change_suit_or_accessory",
                OperandModel = typeof(VMChangeSuitOrAccessoryOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRefresh())
            {
                Opcode = 7,
                Name = "refresh",
                OperandModel = typeof(VMRefreshOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRandomNumber())
            {
                Opcode = 8,
                Name = "random_number",
                OperandModel = typeof(VMRandomNumberOperand)
            });

            //TODO: burn

            //Sims 1.0 tutorial

            AddPrimitive(new VMPrimitiveRegistration(new VMGetDistanceTo())
            {
                Opcode = 11,
                Name = "get_distance_to",
                OperandModel = typeof(VMGetDistanceToOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGetDirectionTo())
            {
                Opcode = 12,
                Name = "get_direction_to",
                OperandModel = typeof(VMGetDirectionToOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMPushInteraction())
            {
                Opcode = 13,
                Name = "push_interaction",
                OperandModel = typeof(VMPushInteractionOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMFindBestObjectForFunction())
            {
                Opcode = 14,
                Name = "find_best_object_for_function",
                OperandModel = typeof(VMFindBestObjectForFunctionOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMBreakPoint())
            {
                Opcode = 15,
                Name = "breakpoint",
                OperandModel = typeof(VMBreakPointOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMFindLocationFor())
            {
                Opcode = 16,
                Name = "find_location_for",
                OperandModel = typeof(VMFindLocationForOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMIdleForInput())
            {
                Opcode = 17,
                Name = "idle_for_input",
                OperandModel = typeof(VMIdleForInputOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRemoveObjectInstance())
            {
                Opcode = 18,
                Name = "remove_object_instance",
                OperandModel = typeof(VMRemoveObjectInstanceOperand)
            });

            //Make new character

            AddPrimitive(new VMPrimitiveRegistration(new VMRunFunctionalTree())
            {
                Opcode = 20,
                Name = "run_functional_tree",
                OperandModel = typeof(VMRunFunctionalTreeOperand)
            });

            //Show string: may be used but no functional result.

            AddPrimitive(new VMPrimitiveRegistration(new VMLookTowards())
            {
                Opcode = 22,
                Name = "look_towards",
                OperandModel = typeof(VMLookTowardsOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMPlaySound())
            {
                Opcode = 23,
                Name = "play_sound",
                OperandModel = typeof(VMPlaySoundOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRelationship())
            {
                Opcode = 24,
                Name = "old_relationship",
                OperandModel = typeof(VMOldRelationshipOperand) //same primitive, different operand
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMTransferFunds())
            {
                Opcode = 25,
                Name = "transfer_funds",
                OperandModel = typeof(VMTransferFundsOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRelationship())
            {
                Opcode = 26,
                Name = "relationship",
                OperandModel = typeof(VMRelationshipOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGotoRelativePosition())
            {
                Opcode = 27,
                Name = "goto_relative",
                OperandModel = typeof(VMGotoRelativePositionOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMRunTreeByName())
            {
                Opcode = 28,
                Name = "run_tree_by_name",
                OperandModel = typeof(VMRunTreeByNameOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSetMotiveChange())
            {
                Opcode = 29,
                Name = "set_motive_deltas",
                OperandModel = typeof(VMSetMotiveChangeOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSysLog())
            {
                Opcode = 30,
                Name = "syslog",
                OperandModel = typeof(VMSysLogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSetToNext())
            {
                Opcode = 31,
                Name = "set_to_next",
                OperandModel = typeof(VMSetToNextOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMTestObjectType())
            {
                Opcode = 32,
                Name = "test_object_type",
                OperandModel = typeof(VMTestObjectTypeOperand)
            });

            //TODO: find 5 worst motives

            //TODO: ui effect (used?)

            AddPrimitive(new VMPrimitiveRegistration(new VMSpecialEffect())
            {
                Opcode = 35,
                Name = "special_effect",
                OperandModel = typeof(VMSpecialEffectOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDialogPrivateStrings())
            {
                Opcode = 36,
                Name = "dialog_private",
                OperandModel = typeof(VMDialogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMTestSimInteractingWith())
            {
                Opcode = 37,
                Name = "test_sim_interacting_with",
                OperandModel = typeof(VMTestSimInteractingWithOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDialogGlobalStrings())
            {
                Opcode = 38,
                Name = "dialog_global",
                OperandModel = typeof(VMDialogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDialogSemiGlobalStrings())
            {
                Opcode = 39,
                Name = "dialog_semiglobal",
                OperandModel = typeof(VMDialogOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMOnlineJobsCall())
            {
                Opcode = 40,
                Name = "online_jobs_call",
                OperandModel = typeof(VMOnlineJobsCallOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSetBalloonHeadline())
            {
                Opcode = 41,
                Name = "set_balloon_headline",
                OperandModel = typeof(VMSetBalloonHeadlineOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMCreateObjectInstance())
            {
                Opcode = 42,
                Name = "create_object_instance",
                OperandModel = typeof(VMCreateObjectInstanceOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMDropOnto())
            {
                Opcode = 43,
                Name = "drop_onto",
                OperandModel = typeof(VMDropOntoOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMAnimateSim()) {
                Opcode = 44,
                Name = "animate",
                OperandModel = typeof(VMAnimateSimOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGotoRoutingSlot())
            {
                Opcode = 45,
                Name = "goto_routing_slot",
                OperandModel = typeof(VMGotoRoutingSlotOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMSnap()) //not functional right now
            {
                Opcode = 46,
                Name = "snap",
                OperandModel = typeof(VMSnapOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMReach())
            {
                Opcode = 47,
                Name = "reach",
                OperandModel = typeof(VMReachOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMStopAllSounds())
            {
                Opcode = 48,
                Name = "stop_all_sounds",
                OperandModel = typeof(VMStopAllSoundsOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMNotifyOutOfIdle())
            {
                Opcode = 49,
                Name = "stackobj_notify_out_of_idle",
                OperandModel = typeof(VMAnimateSimOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMChangeActionString())
            {
                Opcode = 50,
                Name = "change_action_string",
                OperandModel = typeof(VMChangeActionStringOperand)
            });

            //lots of unused primitives. see http://simantics.wikidot.com/wiki:primitives

            //TODO: Send Maxis Letter

            AddPrimitive(new VMPrimitiveRegistration(new VMInvokePlugin())
            {
                Opcode = 62,
                Name = "invoke_plugin",
                OperandModel = typeof(VMInvokePluginOperand)
            });

            AddPrimitive(new VMPrimitiveRegistration(new VMGetTerrainInfo())
            {
                Opcode = 63,
                Name = "get_terrain_info",
                OperandModel = typeof(VMGetTerrainInfoOperand)
            });

            //UNUSED: Leave Lot and Goto

            AddPrimitive(new VMPrimitiveRegistration(new VMFindBestAction())
            {
                Opcode = 65,
                Name = "find_best_action",
                OperandModel = typeof(VMFindBestActionOperand)
            });

            //TODO: Set Dynamic Object Name

            //TODO: Inventory Operations
        }
Beispiel #25
0
        public void InitBodyData(VMContext context)
        {
            //init walking strings
            var GlobWalk = context.Globals.Resource.Get<STR>(150);
            for (int i = 0; i < GlobWalk.Length; i++)
            {
                WalkAnimations[i] = GlobWalk.GetString(i);
            }

            var SpecialWalk = Object.Resource.Get<STR>(150);
            if (SpecialWalk != null)
            {
                for (int i = 0; i < SpecialWalk.Length; i++)
                {
                    var str = SpecialWalk.GetString(i);
                    if (str != "") WalkAnimations[i] = str;
                }
            }
        }
Beispiel #26
0
        public virtual void LoadCrossRef(VMEntityMarshal input, VMContext context)
        {
            Contained = new VMEntity[input.Contained.Length];
            int i = 0;
            foreach (var item in input.Contained) Contained[i++] = context.VM.GetObjectById(item);

            Container = context.VM.GetObjectById(input.Container);
            if (UseWorld && Container != null)
            {
                WorldUI.Container = Container.WorldUI;
                WorldUI.ContainerSlot = ContainerSlot;
            }
        }
Beispiel #27
0
 public VMArchitecture(VMArchitectureMarshal input, VMContext context, Blueprint blueprint) : this(input.Width, input.Height, blueprint, context)
 {
     Load(input);
 }
Beispiel #28
0
        public override void Init(VMContext context)
        {
            if (UseWorld) ((AvatarComponent)WorldUI).ObjectID = (ushort)ObjectID;
            base.Init(context);

            Animations = new List<VMAnimationState>();

            SetAvatarBodyStrings(Object.Resource.Get<STR>(Object.OBJ.BodyStringID), context);
            InitBodyData(context);

            SetMotiveData(VMMotive.Comfort, 100);
            SetPersonData(VMPersonDataVariable.NeatPersonality, 1000); //for testing wash hands after toilet
            SetPersonData(VMPersonDataVariable.OnlineJobID, 1); //for testing wash hands after toilet
            SetPersonData(VMPersonDataVariable.IsHousemate, 2);

            SetPersonData(VMPersonDataVariable.CreativitySkill, 1000);
            SetPersonData(VMPersonDataVariable.CookingSkill, 1000);
            SetPersonData(VMPersonDataVariable.CharismaSkill, 1000);
            SetPersonData(VMPersonDataVariable.LogicSkill, 1000);
            SetPersonData(VMPersonDataVariable.BodySkill, 1000);
        }
Beispiel #29
0
 public abstract void PlaceInSlot(VMEntity obj, int slot, bool cleanOld, VMContext context);
Beispiel #30
0
 public virtual void LoadCrossRef(VMAvatarMarshal input, VMContext context)
 {
     base.LoadCrossRef(input, context);
     HandObject = context.VM.GetObjectById(input.HandObject);
     if (HandObject != null && HandObject is VMGameObject) ((ObjectComponent)HandObject.WorldUI).ForceDynamic = true;
     //we need to fix the gender, since InitBodyData resets it.
     var gender = GetPersonData(VMPersonDataVariable.Gender);
     InitBodyData(context);
     SetPersonData(VMPersonDataVariable.Gender, gender);
     BodyOutfit = input.BodyOutfit;
     HeadOutfit = input.HeadOutfit;
 }
Beispiel #31
0
 public virtual void PositionChange(VMContext context, bool noEntryPoint)
 {
     Footprint = GetObstacle(Position, Direction);
     if (!(GhostImage || noEntryPoint)) ExecuteEntryPoint(9, context, true); //Placement
 }
Beispiel #32
0
        public override void PositionChange(VMContext context, bool noEntryPoint)
        {
            if (GhostImage) return;
            if (Container != null) return;
            if (Position == LotTilePos.OUT_OF_WORLD) return;

            context.RegisterObjectPos(this);

            base.PositionChange(context, noEntryPoint);
        }
Beispiel #33
0
        public VMPlacementResult PositionValid(LotTilePos pos, Direction direction, VMContext context)
        {
            if (pos == LotTilePos.OUT_OF_WORLD) return new VMPlacementResult();
            else if (context.IsOutOfBounds(pos)) return new VMPlacementResult { Status = VMPlacementError.LocationOutOfBounds };

            //TODO: speedup with exit early checks
            //TODO: corner checks (wtf uses this)

            var arch = context.Architecture;
            var wall = arch.GetWall(pos.TileX, pos.TileY, pos.Level); //todo: preprocess to check which walls are real solid walls and not fences.

            if (this is VMGameObject) //needs special handling for avatar eventually
            {
                VMPlacementError wallValid = WallChangeValid(wall, direction, true);
                if (wallValid != VMPlacementError.Success) return new VMPlacementResult { Status = wallValid };
            }

            var floor = arch.GetFloor(pos.TileX, pos.TileY, pos.Level);
            VMPlacementError floorValid = FloorChangeValid(floor, pos.Level);
            if (floorValid != VMPlacementError.Success) return new VMPlacementResult { Status = floorValid };

            //we've passed the wall test, now check if we intersect any objects.
            var valid = (this is VMAvatar)? context.GetAvatarPlace(this, pos, direction) : context.GetObjPlace(this, pos, direction);
            return valid;
        }
Beispiel #34
0
        public void SetAvatarBodyStrings(STR data, VMContext context)
        {
            if (data == null) return;

            try
            {
                var body = data.GetString(1);
                var randBody = data.GetString(10);

                if (randBody != "")
                {
                    var bodySpl = randBody.Split(';');
                    DefaultSuits.Daywear = Convert.ToUInt64(bodySpl[context.NextRandom((ulong)bodySpl.Length-1)], 16);
                }
                else if (body != "")
                {
                    DefaultSuits.Daywear = Convert.ToUInt64(body, 16);
                }

                BodyOutfit = DefaultSuits.Daywear;

                var head = data.GetString(2);
                var randHead = data.GetString(9);

                if (randHead != "")
                {
                    var headSpl = randHead.Split(';');
                    HeadOutfit = Convert.ToUInt64(headSpl[context.NextRandom((ulong)headSpl.Length-1)], 16);
                }
                else if (head != "")
                {
                    HeadOutfit = Convert.ToUInt64(head, 16);
                }
            }
            catch
            {
                //head or body invalid, resort to default.
            }

            var gender = data.GetString(12);
            var genVar = (int)VMPersonDataVariable.Gender;

            if (gender.Equals("male", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 0;
            else if (gender.Equals("female", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 1;
            else if (gender.Equals("dogmale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 8;
            else if (gender.Equals("dogfemale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 9;
            else if (gender.Equals("catmale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 16;
            else if (gender.Equals("catfemale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 17;

            var names = data.GetString(11);
            if (names != "")
            {
                var nameSpl = names.Split(';');
                Name = nameSpl[context.NextRandom((ulong)nameSpl.Length)];
            }

            PersonData[(int)VMPersonDataVariable.PersonsAge] = Convert.ToInt16(data.GetString(13));

            var skinTone = data.GetString(14);
            if (skinTone.Equals("lgt", StringComparison.InvariantCultureIgnoreCase)) SkinTone = AppearanceType.Light;
            else if (skinTone.Equals("med", StringComparison.InvariantCultureIgnoreCase)) SkinTone = AppearanceType.Medium;
            else if (skinTone.Equals("drk", StringComparison.InvariantCultureIgnoreCase)) SkinTone = AppearanceType.Dark;
        }
Beispiel #35
0
 public virtual void PrePositionChange(VMContext context)
 {
 }
Beispiel #36
0
        public override void PositionChange(VMContext context, bool noEntryPoint)
        {
            if (GhostImage) return;
            if (Container != null) return;
            if (Position == LotTilePos.OUT_OF_WORLD) return;

            var arch = context.Architecture;
            if (((VMEntityFlags2)ObjectData[(int)VMStackObjectVariable.FlagField2] & (VMEntityFlags2.ArchitectualWindow | VMEntityFlags2.ArchitectualDoor)) > 0)
            { //if wall or door, attempt to place style on wall

                if (Object.OBJ.WallStyle > 21 && Object.OBJ.WallStyle < 256)
                { //first thing's first, is the style between 22-255 inclusive? If it is, then the style is stored in the object. Need to load its sprites and change the id for the objd.
                    var id = Object.OBJ.WallStyleSpriteID;
                    var style = new WallStyle()
                    {
                        WallsUpFar = Object.Resource.Get<SPR>(id),
                        WallsUpMedium = Object.Resource.Get<SPR>((ushort)(id + 1)),
                        WallsUpNear = Object.Resource.Get<SPR>((ushort)(id + 2)),
                        WallsDownFar = Object.Resource.Get<SPR>((ushort)(id + 3)),
                        WallsDownMedium = Object.Resource.Get<SPR>((ushort)(id + 4)),
                        WallsDownNear = Object.Resource.Get<SPR>((ushort)(id + 5))
                    };
                    Object.OBJ.WallStyle = FSO.Content.Content.Get().WorldWalls.AddDynamicWallStyle(style);
                }

                var placeFlags = (WallPlacementFlags)ObjectData[(int)VMStackObjectVariable.WallPlacementFlags];
                var dir = DirectionToWallOff(Direction);
                if ((placeFlags & WallPlacementFlags.WallRequiredInFront) > 0) SetWallStyle((dir) % 4, arch, Object.OBJ.WallStyle);
                if ((placeFlags & WallPlacementFlags.WallRequiredOnRight) > 0) SetWallStyle((dir + 1) % 4, arch, Object.OBJ.WallStyle);
                if ((placeFlags & WallPlacementFlags.WallRequiredBehind) > 0) SetWallStyle((dir + 2) % 4, arch, Object.OBJ.WallStyle);
                if ((placeFlags & WallPlacementFlags.WallRequiredOnLeft) > 0) SetWallStyle((dir + 3) % 4, arch, Object.OBJ.WallStyle);
            }
            SetWallUse(arch, true);
            if (GetValue(VMStackObjectVariable.Category) == 8) context.Architecture.SetObjectSupported(Position.TileX, Position.TileY, Position.Level, true);

            context.RegisterObjectPos(this);

            base.PositionChange(context, noEntryPoint);
        }
Beispiel #37
0
        public void PushUserInteraction(int interaction, VMEntity caller, VMContext context)
        {
            if (!TreeTable.InteractionByIndex.ContainsKey((uint)interaction)) return;
            var Action = TreeTable.InteractionByIndex[(uint)interaction];
            ushort ActionID = Action.ActionFunction;

            var function = GetBHAVWithOwner(ActionID, context);

            VMEntity carriedObj = caller.GetSlot(0);

            var routine = context.VM.Assemble(function.bhav);
            caller.Thread.EnqueueAction(
                new FSO.SimAntics.Engine.VMQueuedAction
                {
                    Callee = this,
                    CodeOwner = function.owner,
                    Routine = routine,
                    Name = TreeTableStrings.GetString((int)Action.TTAIndex),
                    StackObject = this,
                    Args = ((Action.MaskFlags & InteractionMaskFlags.AvailableWhenCarrying) > 0)
                        ? new short[] { (carriedObj == null)?(short)0:carriedObj.ObjectID, 0, 0, 0 }:null,
                    InteractionNumber = interaction,
                    Priority = VMQueuePriority.UserDriven
                }
            );
        }
Beispiel #38
0
        public override void Update(UpdateState state)
        {
            base.Update(state);
            if (TempVM == null && GUID != 0)
            {
                var world = new ExternalWorld(GameFacade.GraphicsDevice);
                world.Initialize(GameFacade.Scenes);
                var context = new VMContext(world);

                TempVM = new VM(context, new VMServerDriver(37565, null), new VMNullHeadlineProvider());
                TempVM.Init();

                var blueprint = new Blueprint(32, 32);
                blueprint.Light = new RoomLighting[]
                {
                    new RoomLighting() { OutsideLight = 100 },
                    new RoomLighting() { OutsideLight = 100 },
                    new RoomLighting() { OutsideLight = 100 },
                };
                blueprint.OutsideColor = Color.White;
                blueprint.GenerateRoomLights();
                blueprint.RoomColors[2].A /= 2;
                world.State._2D.AmbientLight.SetData(blueprint.RoomColors);

                world.InitBlueprint(blueprint);
                context.Blueprint = blueprint;
                context.Architecture = new VMArchitecture(1, 1, blueprint, TempVM.Context);
            }

            if (GUID != oldGUID)
            {
                SetGUIDLocal(GUID, TempVM);
                state.SharedData["ExternalDraw"] = true;
            }

            if (ForceRedraw)
            {
                state.SharedData["ExternalDraw"] = true;
                ForceRedraw = false;
            }

            if (TempVM != null) TempVM.Update();
        }
Beispiel #39
0
 public void RefreshBlueprint(VMContext context)
 {
     if (UseWorld && this is VMGameObject) context.Blueprint.ChangeObjectLocation((ObjectComponent)WorldUI, (_Position == LotTilePos.OUT_OF_WORLD) ? LotTilePos.FromBigTile(-1, -1, 1) : _Position);
 }
Beispiel #40
0
        public virtual void Reset(VMContext context)
        {
            if (this.Thread == null) return;
            this.Thread.Stack.Clear();
            this.Thread.Queue.Clear();

            if (EntryPoints[3].ActionFunction != 0) ExecuteEntryPoint(3, context, true); //Reset
            if (!GhostImage) ExecuteEntryPoint(1, context, false); //Main
        }
Beispiel #41
0
        public void Load(VMMarshal input)
        {
            var oldWorld = Context.World;

            Context         = new VMContext(input.Context, Context);
            Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global");
            Context.VM      = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    if (obj.HeadlineRenderer != null)
                    {
                        obj.HeadlineRenderer.Dispose();
                    }
                }
            }

            Entities    = new List <VMEntity>();
            ObjectsById = new Dictionary <short, VMEntity>();
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                    Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.GenerateTreeByName(Context);
                Entities.Add(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;

            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                new VMMultitileGroup(multi, Context); //should self register
            }

            foreach (var ent in Entities)
            {
                ent.PositionChange(Context, true);
            }

            GlobalState = input.GlobalState;
            ObjectId    = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));

            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.WallDirtyState(input.Context.Architecture);

            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }