예제 #1
0
        public VMGameObject(GameObject def, ObjectComponent worldUI)
            : base(def)
        {
            this.WorldUI = worldUI;

            /*var mainFunction = def.Master.MainFuncID;
            if (mainFunction > 0)
            {
                var bhav = def.Iff.BHAVs.First(x => x.ID == mainFunction);
                int y = 22;
            }*/
        }
 public int GetDirection(ObjectComponent obj)
 {
     switch (obj.Direction)
     {
         case tso.world.model.Direction.WEST:
             return 6;
         case tso.world.model.Direction.SOUTH:
             return 4;
         case tso.world.model.Direction.EAST:
             return 2;
         case tso.world.model.Direction.NORTH:
             return 0;
         default:
             return 0;
     }
 }
        public VMGameObject CreateObject(XmlHouseDataObject obj)
        {
            var objDefinition = Content.Get().WorldObjects.Get(obj.GUIDInt);
            if (objDefinition == null){
                return null;
            }

            var worldObject = new ObjectComponent(objDefinition);
            worldObject.Direction = obj.Direction;

            var vmObject = new VMGameObject(objDefinition, worldObject);

            VM.AddEntity(vmObject);
            Blueprint.ChangeObjectLocation(worldObject, (short)obj.X, (short)obj.Y, (sbyte)obj.Level);
            return vmObject;
        }
예제 #4
0
 public void RemoveObject(ObjectComponent comp)
 {
     Objects.Remove(comp);
 }
예제 #5
0
 public void AddObject(ObjectComponent comp)
 {
     Objects.Add(comp);
 }
예제 #6
0
 public void RemoveObject(ObjectComponent component)
 {
     if (component.TileX != -2)
     {
         var currentOffset = GetOffset(component.TileX, component.TileY);
         var currentList = Objects[currentOffset];
         if (currentList != null)
         {
             currentList.RemoveObject(component);
         }
     }
     if (All.Contains(component))
     {
         All.Remove(component);
     }
     Damage.Add(new BlueprintDamage(BlueprintDamageType.OBJECT_MOVE, component.TileX, component.TileY, component.Level) { Component = component });
     OccupiedTilesDirty = true;
 }
예제 #7
0
        public void ChangeObjectLocation(ObjectComponent component, short tileX, short tileY, sbyte level)
        {
            /** It has never been placed before if tileX == -2 **/
            if (component.TileX != -2){
                var currentOffset = GetOffset(tileX, tileY);
                var currentList = Objects[currentOffset];
                if (currentList != null){
                    currentList.RemoveObject(component);
                }
            }

            var newOffset = GetOffset(tileX, tileY);
            var newList = Objects[newOffset];
            if (newList == null){
                newList = Objects[newOffset] = new BlueprintObjectList();
            }
            newList.AddObject(component);
            component.blueprint = this;
            component.TileX = tileX;
            component.TileY = tileY;
            component.Level = level;
            component.Position = new Microsoft.Xna.Framework.Vector3(tileX, tileY, 0);

            if (!All.Contains(component))
            {
                All.Add(component);
            }
            Damage.Add(new BlueprintDamage(BlueprintDamageType.OBJECT_MOVE, tileX, tileY, level) { Component = component });
            OccupiedTilesDirty = true;
        }
예제 #8
0
        public void ChangeObjectLocation(ObjectComponent component, LotTilePos pos)
        {
            short tileX = (pos.x < 0) ? (short)0 : pos.TileX;
            short tileY = (pos.y < 0) ? (short)0 : pos.TileY;
            sbyte level = pos.Level;
            /** It has never been placed before if tileX == -2 **/

            if (component.TileX != -2){
                var currentOffset = GetOffset(component.TileX, component.TileY);
                var currentList = Objects[currentOffset];
                if (currentList != null){
                    currentList.RemoveObject(component);
                }
            }

            if (tileX != -2)
            {
                var newOffset = GetOffset(tileX, tileY);
                var newList = Objects[newOffset];
                if (newList == null)
                {
                    newList = Objects[newOffset] = new BlueprintObjectList();
                }
                newList.AddObject(component);
                if (!All.Contains(component))
                {
                    All.Add(component);
                }
            }
            else if (All.Contains(component))
            {
                All.Remove(component);
            }

            Damage.Add(new BlueprintDamage(BlueprintDamageType.OBJECT_MOVE, tileX, tileY, level) { Component = component });
            OccupiedTilesDirty = true;

            component.blueprint = this;
            component.TileX = tileX;
            component.TileY = tileY;
            component.Level = level;
            component.Position = new Microsoft.Xna.Framework.Vector3(pos.x / 16.0f, pos.y / 16.0f, (level - 1) * 3.0f);
        }
예제 #9
0
        public VMMultitileGroup CreateObjectInstance(UInt32 GUID, LotTilePos pos, Direction direction, short MainStackOBJ, short MainParam)
        {
            VMMultitileGroup group = new VMMultitileGroup();
            var objDefinition = TSO.Content.Content.Get().WorldObjects.Get(GUID);
            if (objDefinition == null)
            {
                return null;
            }

            var master = objDefinition.OBJ.MasterID;
            if (master != 0)
            {
                group.MultiTile = true;
                var objd = objDefinition.Resource.List<OBJD>();

                for (int i = 0; i < objd.Count; i++)
                {
                    if (objd[i].MasterID == master && objd[i].SubIndex != -1) //if sub-part of this object, make it!
                    {
                        var subObjDefinition = TSO.Content.Content.Get().WorldObjects.Get(objd[i].GUID);
                        if (subObjDefinition != null)
                        {
                            var worldObject = new ObjectComponent(subObjDefinition);
                            var vmObject = new VMGameObject(subObjDefinition, worldObject);
                            vmObject.MasterDefinition = objDefinition.OBJ;
                            vmObject.UseTreeTableOf(objDefinition);

                            vmObject.MainParam = MainParam;
                            vmObject.MainStackOBJ = MainStackOBJ;
                            group.Objects.Add(vmObject);

                            vmObject.MultitileGroup = group;
                            VM.AddEntity(vmObject);

                        }
                    }
                }

                group.Init(this);
                VMPlacementError couldPlace = group.ChangePosition(pos, direction, this);
                if (couldPlace != VMPlacementError.Success);
                return group;
            }
            else
            {
                if (objDefinition.OBJ.ObjectType == OBJDType.Person) //person
                {
                    var vmObject = new VMAvatar(objDefinition);
                    vmObject.MultitileGroup = group;
                    group.Objects.Add(vmObject);
                    VM.AddEntity(vmObject);

                    Blueprint.AddAvatar((AvatarComponent)vmObject.WorldUI);

                    vmObject.MainParam = MainParam;
                    vmObject.MainStackOBJ = MainStackOBJ;

                    group.Init(this);
                    vmObject.SetPosition(pos, direction, this);

                    return group;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var vmObject = new VMGameObject(objDefinition, worldObject);

                    vmObject.MultitileGroup = group;
                    group.Objects.Add(vmObject);

                    VM.AddEntity(vmObject);

                    vmObject.MainParam = MainParam;
                    vmObject.MainStackOBJ = MainStackOBJ;

                    group.Init(this);
                    vmObject.SetPosition(pos, direction, this);

                    return group;
                }
            }
        }
예제 #10
0
 void vm_OnDialog(TSO.Simantics.model.VMDialogInfo info)
 {
     var alert = UIScreen.ShowAlert(new UIAlertOptions { Title = info.Title, Message = info.Message, Width = 325+(int)(info.Message.Length/3.5f), Alignment = TextAlignment.Left, TextSize = 12 }, true);
     var entity = info.Icon;
     if (entity is VMGameObject)
     {
         var objects = entity.MultitileGroup.Objects;
         ObjectComponent[] objComps = new ObjectComponent[objects.Count];
         for (int i = 0; i < objects.Count; i++)
         {
             objComps[i] = (ObjectComponent)objects[i].WorldUI;
         }
         var thumb = World.GetObjectThumb(objComps, entity.MultitileGroup.GetBasePositions(), GameFacade.GraphicsDevice);
         alert.SetIcon(thumb, 110, 110);
     }
 }
예제 #11
0
        /// <summary>
        /// Gets an object group's thumbnail provided an array of objects.
        /// </summary>
        /// <param name="objects">The object components to draw.</param>
        /// <param name="gd">GraphicsDevice instance.</param>
        /// <param name="state">WorldState instance.</param>
        /// <returns>Object's ID if the object was found at the given position.</returns>
        public Texture2D GetObjectThumb(ObjectComponent[] objects, Vector3[] positions, GraphicsDevice gd, WorldState state)
        {
            var oldZoom = state.Zoom;
            var oldRotation = state.Rotation;
            /** Center average position **/
            Vector3 average = new Vector3();
            for (int i = 0; i < positions.Length; i++)
            {
                average += positions[i];
            }
            average /= positions.Length;

            state.SilentZoom = WorldZoom.Near;
            state.SilentRotation = WorldRotation.BottomRight;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw = true;
            var pxOffset = new Vector2(442, 275) - state.WorldSpace.GetScreenFromTile(average);

            var _2d = state._2D;
            Promise<Texture2D> bufferTexture = null;
            state._2D.OBJIDMode = false;
            Rectangle bounds = new Rectangle();
            using (var buffer = state._2D.WithBuffer(BUFFER_THUMB, ref bufferTexture))
            {
                while (buffer.NextPass())
                {
                    for (int i=0; i<objects.Length; i++)
                    {
                        var obj = objects[i];
                        var tilePosition = positions[i];

                        //we need to trick the object into believing it is in a set world state.
                        var oldObjRot = obj.Direction;

                        obj.Direction = Direction.NORTH;
                        state.SilentZoom = WorldZoom.Near;
                        state.SilentRotation = WorldRotation.BottomRight;
                        obj.OnRotationChanged(state);
                        obj.OnZoomChanged(state);

                        _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition) + pxOffset);
                        _2d.OffsetTile(tilePosition);
                        _2d.SetObjID(obj.ObjectID);
                        obj.Draw(gd, state);

                        //return everything to normal
                        obj.Direction = oldObjRot;
                        state.SilentZoom = oldZoom;
                        state.SilentRotation = oldRotation;
                        obj.OnRotationChanged(state);
                        obj.OnZoomChanged(state);
                    }
                    bounds = _2d.GetSpriteListBounds();
                }
            }
            bounds.X = Math.Max(0, Math.Min(1023, bounds.X));
            bounds.Y = Math.Max(0, Math.Min(1023, bounds.Y));
            if (bounds.Width + bounds.X > 1024) bounds.Width = 1024 - bounds.X;
            if (bounds.Height + bounds.Y > 1024) bounds.Height = 1024 - bounds.Y;

            //return things to normal
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw = false;

            var tex = bufferTexture.Get();
            return TextureUtils.Clip(gd, tex, bounds);
        }
예제 #12
0
 /// <summary>
 /// Gets an object group's thumbnail provided an array of objects.
 /// </summary>
 /// <param name="objects">The object components to draw.</param>
 /// <param name="gd">GraphicsDevice instance.</param>
 /// <param name="state">WorldState instance.</param>
 /// <returns>Object's ID if the object was found at the given position.</returns>
 public Texture2D GetObjectThumb(ObjectComponent[] objects, Vector3[] positions, GraphicsDevice gd)
 {
     State._2D.Begin(this.State.Camera);
     return _2DWorld.GetObjectThumb(objects, positions, gd, State);
 }
예제 #13
0
        public void SetInfo(VMEntity entity, bool bought)
        {
            var obj = entity.Object;
            var def = entity.MasterDefinition;
            if (def == null) def = entity.Object.OBJ;
            CTSS catString = obj.Resource.Get<CTSS>(def.CatalogStringsID);
            if (catString != null)
            {
                DescriptionText.CurrentText = catString.GetString(0) + "\r\n" + catString.GetString(1);
                ObjectNameText.Caption = catString.GetString(0);
            }
            else
            {
                DescriptionText.CurrentText = entity.ToString();
                ObjectNameText.Caption = entity.ToString();
            }
            StringBuilder motivesString = new StringBuilder();
            motivesString.AppendFormat(GameFacade.Strings.GetString("206", "19") + "${0}\r\n", def.Price);
            if (def.RatingHunger != 0) { motivesString.AppendFormat(AdStrings[0], def.RatingHunger); }
            if (def.RatingComfort != 0) { motivesString.AppendFormat(AdStrings[1], def.RatingComfort); }
            if (def.RatingHygiene != 0) { motivesString.AppendFormat(AdStrings[2], def.RatingHygiene); }
            if (def.RatingBladder != 0) { motivesString.AppendFormat(AdStrings[3], def.RatingBladder); }
            if (def.RatingEnergy != 0) { motivesString.AppendFormat(AdStrings[4], def.RatingEnergy); }
            if (def.RatingFun != 0) { motivesString.AppendFormat(AdStrings[5], def.RatingFun); }
            if (def.RatingRoom != 0) { motivesString.AppendFormat(AdStrings[6], def.RatingRoom); }

            var sFlags = def.RatingSkillFlags;
            for (int i = 0; i < 7; i++)
            {
                if ((sFlags & (1 << i)) > 0) motivesString.Append(AdStrings[i+7]);
            }

            MotivesText.CurrentText = motivesString.ToString();
            ObjectOwnerText.Caption = GameFacade.Strings.GetString("206", "24", new string[] { "You" });

            SpecificTabButton.Disabled = !bought;

            if (entity is VMGameObject) {
                var objects = entity.MultitileGroup.Objects;
                ObjectComponent[] objComps = new ObjectComponent[objects.Count];
                for (int i=0; i<objects.Count; i++) {
                    objComps[i] = (ObjectComponent)objects[i].WorldUI;
                }
                var thumb = World.GetObjectThumb(objComps, entity.MultitileGroup.GetBasePositions(), GameFacade.GraphicsDevice);
                if (Thumbnail.Texture != null) Thumbnail.Texture.Dispose();
                Thumbnail.Texture = thumb;
                UpdateImagePosition();
            } else
            {
                if (Thumbnail.Texture != null) Thumbnail.Texture.Dispose();
                Thumbnail.Texture = null;
            }
        }
예제 #14
0
        public VMEntity CreateObjectInstance(UInt32 GUID, short x, short y, sbyte level, Direction direction)
        {
            var objDefinition = TSO.Content.Content.Get().WorldObjects.Get(GUID);
            if (objDefinition == null)
            {
                return null;
            }

            var master = objDefinition.OBJ.MasterID;
            if (master != 0)
            {
                var objd = objDefinition.Resource.List<OBJD>();
                VMMultitileGroup group = new VMMultitileGroup();

                for (int i = 0; i < objd.Count; i++)
                {
                    if (objd[i].MasterID == master && objd[i].SubIndex != -1) //if sub-part of this object, make it!
                    {
                        var subObjDefinition = TSO.Content.Content.Get().WorldObjects.Get(objd[i].GUID);
                        if (subObjDefinition != null)
                        {
                            var worldObject = new ObjectComponent(subObjDefinition);
                            var vmObject = new VMGameObject(subObjDefinition, worldObject);
                            vmObject.MasterDefinition = objDefinition.OBJ;
                            vmObject.UseTreeTableOf(objDefinition);
                            group.Objects.Add(vmObject);

                            VM.AddEntity(vmObject);

                            vmObject.MultitileGroup = group;
                        }
                    }
                }

                group.ChangePosition(x, y, level, direction, this);
                return (VMGameObject)group.Objects[0];
            }
            else
            {
                if (objDefinition.OBJ.ObjectType == OBJDType.Person) //person
                {
                    var vmObject = new VMAvatar(objDefinition);
                    VM.AddEntity(vmObject);

                    //this.InitWorldComponent(vmObject.WorldUI);
                    Blueprint.AddAvatar((AvatarComponent)vmObject.WorldUI);

                    vmObject.SetPosition(x, y, level, direction, this);
                    return vmObject;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var vmObject = new VMGameObject(objDefinition, worldObject);

                    VM.AddEntity(vmObject);

                    vmObject.SetPosition(x, y, level, direction, this);
                    return vmObject;
                }
            }
        }