示例#1
0
        // find upper left corner of sprites
        public Vector2Int32 GetAnchor(int x, int y)
        {
            Tile         tile     = Tiles[x, y];
            TileProperty tileprop = TileProperties[tile.Type];
            var          size     = tileprop.FrameSize[0];

            if (tileprop.IsFramed && (size.X > 1 || size.Y > 1 || tileprop.FrameSize.Length > 1))
            {
                if (tile.U == 0 && tile.V == 0)
                {
                    new Vector2Int32(x, y);
                }

                var sprite = World.Sprites2.FirstOrDefault(s => s.Tile == tile.Type);
                var style  = sprite?.GetStyleFromUV(tile.GetUV());

                var sizeTiles = style?.Value?.SizeTiles ?? sprite?.SizeTiles?.FirstOrDefault() ?? tileprop.FrameSize.FirstOrDefault();


                int xShift = tile.U % ((tileprop.TextureGrid.X + 2) * sizeTiles.X) / (tileprop.TextureGrid.X + 2);
                int yShift = tile.V % ((tileprop.TextureGrid.Y + 2) * sizeTiles.Y) / (tileprop.TextureGrid.Y + 2);
                return(new Vector2Int32(x - xShift, y - yShift));
            }
            else
            {
                return(new Vector2Int32(x, y));
            }
        }
示例#2
0
        private void CalculateScores()
        {
            for (int index = 0; index < MyGame.Players.Count; index++)
            {
                foreach (Tile tile in MyGame.Players[index].Streets)
                {
                    TileProperty tileProp     = tile as TileProperty;
                    TileRailRoad tileRailroad = tile as TileRailRoad;
                    TileCompany  tileComp     = tile as TileCompany;

                    if (tileProp != null)
                    {
                        if (tileProp.TotalUpgrades > 0)
                        {
                            for (int downgrade = 0; downgrade < tileProp.TotalUpgrades; downgrade++)
                            {
                                tileProp.Downgrade();
                            }
                            tileProp.Downgrade();
                        }
                    }
                    else if (tileRailroad != null)
                    {
                        tileRailroad.Downgrade();
                    }
                    else if (tileComp != null)
                    {
                        tileComp.Downgrade();
                    }
                }
                PlayerMoneys[index] = MyGame.Players[index].Money;
            }
        }
示例#3
0
        public bool GetClosestAdj(Vector2Int fromPosition)
        {
            float        distance        = float.MaxValue;
            TileProperty closestNeigbour = null;

            for (int i = 0; i < 8; i++)
            {
                TileProperty tileProperty = Loki.map[this.position + DirectionUtils.neighbours[i]];
                if (tileProperty != null && !tileProperty.blockPath)
                {
                    float d = Utils.Distance(fromPosition, this.position);
                    if (d < distance)
                    {
                        distance        = d;
                        closestNeigbour = tileProperty;
                    }
                }
            }

            if (closestNeigbour != null)
            {
                this.closestAdj = closestNeigbour.position;
                return(true);
            }
            return(false);
        }
示例#4
0
 public Tile( Rectangle rect )
 {
     property = TileProperty.TILE_EMPTY;
     pheromones = Program.TILE_MIN_PHEROMONES;
     color = Color.FromArgb( pheromones, Program.TILE_EMPTY_COLOR );
     this.rect = rect;
 }
示例#5
0
        public void SetTileProperty(int id, TileProperty prop)
        {
            WallTileProperty.Remove(id);
            ObstacleTileProperty.Remove(id);
            FloorTileProperty.Remove(id);
            DeadlyTileProperty.Remove(id);

            switch (prop)
            {
            case TileProperty.Wall:
                WallTileProperty.Add(id);
                break;

            case TileProperty.Obstacle:
                ObstacleTileProperty.Add(id);
                break;

            case TileProperty.Floor:
                FloorTileProperty.Add(id);
                break;

            case TileProperty.Deadly:
                DeadlyTileProperty.Add(id);
                break;

            case TileProperty.Null:
                FloorTileProperty.Add(id);
                break;
            }
        }
示例#6
0
 public bool TileHasProperty(TileProperty property)
 {
     if (tile != null && tile.HasTileProperty(property))
     {
         return true;
     }
     return false;
 }
示例#7
0
 /// <summary>
 /// Adds given tileproperty to the dictionary
 /// </summary>
 /// <param name="tileProperty"></param>
 public void AddTileProperty(TileProperty tileProperty)
 {
     if (TilePropertyDictionary.ContainsKey(tileProperty.TextureId))
     {
         return;
     }
     TilePropertyDictionary.Add(tileProperty.TextureId, tileProperty);
 }
示例#8
0
 public Tile(TileState state, TileType type, TileProperty property, TileLogic logic, GridController grid)
 {
     this.state    = state;
     this.type     = type;
     this.property = property;
     this.logic    = logic;
     this.grid     = grid;
 }
示例#9
0
        public static PathResult GetPath(Vector2Int startPosition, Vector2Int endPosition)
        {
            TileProperty start   = Loki.map[startPosition];
            TileProperty end     = Loki.map[endPosition];
            bool         success = false;

            Vector2Int[] path = new Vector2Int[0];
            start.parent = start;

            if (!start.blockPath && !end.blockPath)
            {
                SimplePriorityQueue <TileProperty> openSet   = new SimplePriorityQueue <TileProperty>();
                HashSet <TileProperty>             closedSet = new HashSet <TileProperty>();

                openSet.Enqueue(start, start.fCost);
                while (openSet.Count > 0)
                {
                    TileProperty current = openSet.Dequeue();
                    if (current == end)
                    {
                        success = true;
                        break;
                    }
                    closedSet.Add(current);
                    for (int i = 0; i < 8; i++)
                    {
                        TileProperty neighbour = Loki.map[current.position + DirectionUtils.neighbours[i]];
                        if (neighbour == null || neighbour.blockPath || closedSet.Contains(neighbour))
                        {
                            continue;
                        }
                        float neighbourCost = current.gCost + Utils.Distance(current.position, neighbour.position) + neighbour.pathCost;
                        if (neighbourCost > neighbour.gCost || !openSet.Contains(neighbour))
                        {
                            neighbour.gCost  = neighbourCost;
                            neighbour.hCost  = Utils.Distance(neighbour.position, end.position);
                            neighbour.parent = current;

                            if (!openSet.Contains(neighbour))
                            {
                                openSet.Enqueue(neighbour, neighbour.fCost);
                            }
                            else
                            {
                                openSet.UpdatePriority(neighbour, neighbour.fCost);
                            }
                        }
                    }
                }
            }

            if (success)
            {
                path    = PathFinder.CalcPath(start, end);
                success = path.Length > 0;
            }
            return(new PathResult(path, success));
        }
示例#10
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        serializedObject.Update();
        TileAppearance ta = (TileAppearance)tileAppearance.intValue;
        TileProperty tp = (TileProperty)tileProperties.intValue;
        
        if (oldTileApprearance != ta || oldTileProperties != tp)
        {
            MonoBehaviour[] targetComponents = GetMonoBehaviours(serializedObject.targetObjects);

            if ((tp & TileProperty.Landmine) == TileProperty.Landmine && ta != TileAppearance.Normal)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.invalidMat);
            }
            else if ((tp & TileProperty.Traversable) == TileProperty.Traversable &&
                      ta == TileAppearance.Obstacle)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.invalidMat);
            }
            else if ((tp & TileProperty.Traversable) != TileProperty.Traversable &&
                     (tp & TileProperty.Finish) == TileProperty.Finish)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.invalidMat);
            }
            else if ((tp & TileProperty.Landmine) == TileProperty.Landmine)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.landmineMat);
            }
            else if ((tp & TileProperty.Start) == TileProperty.Start)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.startMat);
            }
            else if ((tp & TileProperty.Finish) == TileProperty.Finish)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.finishMat);
            }
            else if (ta == TileAppearance.Obstacle)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.obstacleMat);
            }
            else if ((tp & TileProperty.Traversable) == TileProperty.Traversable)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.normalTraversableMat);
            }
            else if ((tp & TileProperty.Traversable) != TileProperty.Traversable && ta == TileAppearance.Normal)
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.normalNontraversableMat);
            }
            else
            {
                ChangeMaterialForAllObjects(targetComponents, tileMaterials.defaultMat);
            }
        }
        oldTileProperties = tp;
    }
示例#11
0
 public InputHandler(GridHandler gridHandler, CameraHandler cameraHandler, TileHandler tileHandler, ModeHandler modeHandler, Canvas canvas, Information information, TileProperty tileProperty)
 {
     _gridHandler   = gridHandler;
     _cameraHandler = cameraHandler;
     _tileHandler   = tileHandler;
     _modeHandler   = modeHandler;
     _canvas        = canvas;
     _information   = information;
     _tileProperty  = tileProperty;
 }
示例#12
0
    void OnEnable()
    {
        var tileMaterialsGUID = AssetDatabase.FindAssets("EditorTileMaterials")[0];
        var tileMaterialsPath = AssetDatabase.GUIDToAssetPath(tileMaterialsGUID);
        tileMaterials = AssetDatabase.LoadAssetAtPath<DebugTileMaterials>(tileMaterialsPath);

        tileAppearance = serializedObject.FindProperty("appearance");
        oldTileApprearance = (TileAppearance)tileAppearance.intValue;
        tileProperties = serializedObject.FindProperty("properties");
        oldTileProperties = (TileProperty)tileProperties.intValue;
    }
示例#13
0
 public bool Dig()
 {
         if ((properties & TileProperty.Hole) == TileProperty.Hole ||
             (properties & TileProperty.Crater) == TileProperty.Crater)
         {
             return false;
         }
         appearance = TileAppearance.Hole;
         properties = properties | TileProperty.Hole;
         ChangeModel();
         heatmapUpdateTimer.Restart();
         return true;
 }
示例#14
0
        public static Vector2Int[] CalcPath(TileProperty start, TileProperty end)
        {
            List <Vector2Int> path    = new List <Vector2Int>();
            TileProperty      current = end;

            while (current != start)
            {
                path.Add(current.position);
                current = current.parent;
            }
            Vector2Int[] result = path.ToArray();
            System.Array.Reverse(result);
            return(result);
        }
示例#15
0
 public bool Detonate()
 {
     if ((properties & TileProperty.Landmine) == TileProperty.Landmine)
     {
         appearance = TileAppearance.Crater;
         properties = properties ^ TileProperty.Landmine;
         properties = properties | TileProperty.Crater;
         ChangeModel();
         Camera.main.GetComponent<ShakeScript>().Shake();
         GameObject.Instantiate(GameObject.FindGameObjectWithTag("Game Manager").GetComponent<TilePrefabHelpScript>().explosionPrefab, transform.position, Quaternion.LookRotation(Vector3.up));
         heatmapUpdateTimer.Restart();
         return true;
     }
     return false;
 }
示例#16
0
 public Tile(Vector2 position, Texture2D texture, Rectangle sourceRectangle, TileProperty property)
 {
     this.position        = position;
     this.texture         = texture;
     this.sourceRectangle = sourceRectangle;
     this.property        = property;
     if (property == TileProperty.PLATFORM_CENTER || property == TileProperty.PLATFORM_LEFT || property == TileProperty.PLATFORM_RIGHT)
     {
         boundingRectangle = new Rectangle((int)position.X, (int)position.Y, sourceRectangle.Width, 25);
     }
     else
     {
         boundingRectangle = new Rectangle((int)position.X, (int)position.Y, sourceRectangle.Width, sourceRectangle.Height);
     }
 }
示例#17
0
        // find upper left corner of sprites
        public Vector2Int32 GetAnchor(int x, int y)
        {
            Tile         tile     = Tiles[x, y];
            TileProperty tileprop = TileProperties[tile.Type];

            if (tileprop.IsFramed && (tileprop.FrameSize.X > 1 || tileprop.FrameSize.Y > 1))
            {
                int xShift = tile.U % ((tileprop.TextureGrid.X + 2) * tileprop.FrameSize.X) / (tileprop.TextureGrid.X + 2);
                int yShift = tile.V % ((tileprop.TextureGrid.Y + 2) * tileprop.FrameSize.Y) / (tileprop.TextureGrid.Y + 2);
                return(new Vector2Int32(x - xShift, y - yShift));
            }
            else
            {
                return(new Vector2Int32(x, y));
            }
        }
示例#18
0
        /// <summary>
        /// Updates the data from the UI to the selected tile
        /// </summary>
        private void UpdateTileProperty()
        {
            Tile selectedTile = _tileHandler.GetTile(_gridHandler.SelectedTilePoint);

            if (selectedTile == null)
            {
                return;
            }

            TileProperty tileProp = _tileHandler.GetTileProperty(selectedTile.TextureId);

            if (tileProp == null)
            {
                return;
            }

            tileProp.CopyData(TileProperty);
        }
示例#19
0
        /// <summary>
        /// Loads tileproperties from a json array into the tilehandlers array
        /// </summary>
        /// <param name="mapProperties"></param>
        private void LoadTilePropertiesFromJSON(JArray mapProperties)
        {
            if (mapProperties == null)
            {
                return;
            }

            foreach (var jsonProperty in mapProperties)
            {
                TileProperty tileProperty = new TileProperty((int)jsonProperty["Id"]);
                tileProperty.SpeedMultiplier = (float)jsonProperty["SpeedMultiplier"];
                tileProperty.Damage          = (float)jsonProperty["Damage"];
                tileProperty.DamageInterval  = (float)jsonProperty["DamageInterval"];
                tileProperty.Walkable        = (bool)jsonProperty["Walkable"];
                tileProperty.Water           = (bool)jsonProperty["Water"];
                tileProperty.GroupId         = (jsonProperty["GroupId"] != null) ? (int)jsonProperty["GroupId"] : -1;
                tileProperty.GroupPosition   = (jsonProperty["GroupPosition"] != null) ? (int)jsonProperty["GroupPosition"] : 5;

                _tileHandler.AddTileProperty(tileProperty);
            }
        }
        private static void LoadObjectDbXml(string file)
        {
            var xmlSettings = XElement.Load(file);

            // Load Colors
            foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                string    name  = (string)xElement.Attribute("Name");
                XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color"));
                GlobalColors.Add(name, color);
            }

            foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = new TileProperty();

                // Read XML attributes
                curTile.Color        = ColorFromString((string)xElement.Attribute("Color"));
                curTile.Name         = (string)xElement.Attribute("Name");
                curTile.Id           = (int?)xElement.Attribute("Id") ?? 0;
                curTile.IsFramed     = (bool?)xElement.Attribute("Framed") ?? false;
                curTile.IsSolid      = (bool?)xElement.Attribute("Solid") ?? false;
                curTile.IsSolidTop   = (bool?)xElement.Attribute("SolidTop") ?? false;
                curTile.IsLight      = (bool?)xElement.Attribute("Light") ?? false;
                curTile.FrameSize    = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1);
                curTile.Placement    = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement"));
                curTile.TextureGrid  = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16);
                curTile.IsGrass      = "Grass".Equals((string)xElement.Attribute("Special"));    /* Heathtech */
                curTile.IsPlatform   = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */
                curTile.IsCactus     = "Cactus".Equals((string)xElement.Attribute("Special"));   /* Heathtech */
                curTile.IsStone      = (bool?)xElement.Attribute("Stone") ?? false;              /* Heathtech */
                curTile.CanBlend     = (bool?)xElement.Attribute("Blends") ?? false;             /* Heathtech */
                curTile.MergeWith    = (int?)xElement.Attribute("MergeWith") ?? null;            /* Heathtech */
                curTile.HasFrameName = curTile.IsFramed && ((bool?)xElement.Attribute("UseFrameName") ?? false);
                string frameNamePostfix = (string)xElement.Attribute("FrameNamePostfix") ?? null;

                foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame"))
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = (string)elementFrame.Attribute("Name");
                    curFrame.Variety = (string)elementFrame.Attribute("Variety");
                    curFrame.UV      = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0);
                    curFrame.Anchor  = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor"));
                    var frameSize = StringToVector2Short((string)elementFrame.Attribute("FrameSize"), curTile.FrameSize.X, curTile.FrameSize.Y);

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    string spriteName = null;
                    if (curFrame.Name == curTile.Name)
                    {
                        if (!string.IsNullOrWhiteSpace(curFrame.Variety))
                        {
                            spriteName += curFrame.Variety;
                        }
                    }
                    else
                    {
                        spriteName += curFrame.Name;
                        if (!string.IsNullOrWhiteSpace(curFrame.Variety))
                        {
                            spriteName += " - " + curFrame.Variety;
                        }
                    }
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = spriteName,
                        Origin           = curFrame.UV,
                        Size             = frameSize,
                        Tile             = (ushort)curTile.Id,     /* SBlogic */
                        TileName         = curTile.Name
                    });
                    if (curTile.HasFrameName)
                    {
                        string frameName = curFrame.Name;
                        if (frameNamePostfix != null)
                        {
                            frameName += " (" + frameNamePostfix + ")";
                        }
                        if (curFrame.Variety != null)
                        {
                            frameName += ", " + curFrame.Variety;
                        }

                        //  TODO:  There must be a more efficient way than to store each frame...
                        for (int x = 0, mx = curTile.FrameSize.X; x < mx; x++)
                        {
                            for (int y = 0, my = curTile.FrameSize.Y; y < my; y++)
                            {
                                string frameNameKey = GetFrameNameKey(curTile.Id, (short)(curFrame.UV.X + (x * 18)), (short)(curFrame.UV.Y + (y * 18)));
                                if (!FrameNames.ContainsKey(frameNameKey))
                                {
                                    FrameNames.Add(frameNameKey, frameName);
                                }
                                else
                                {
                                    System.Diagnostics.Debug.WriteLine(curFrame.Name + " collided with " + frameNameKey);
                                }
                            }
                        }
                    }
                }
                if (curTile.Frames.Count == 0 && curTile.IsFramed)
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = curTile.Name;
                    curFrame.Variety = string.Empty;
                    curFrame.UV      = new Vector2Short(0, 0);
                    //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor"));

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = null,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize,
                        Tile             = (ushort)curTile.Id,
                        TileName         = curTile.Name
                    });
                }
                TileProperties.Add(curTile);
                if (!curTile.IsFramed)
                {
                    TileBricks.Add(curTile);
                }
            }
            for (int i = TileProperties.Count; i < 255; i++)
            {
                TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true));
            }

            foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = new WallProperty();
                curWall.Color = ColorFromString((string)xElement.Attribute("Color"));
                curWall.Name  = (string)xElement.Attribute("Name");
                curWall.Id    = (int?)xElement.Attribute("Id") ?? -1;
                WallProperties.Add(curWall);
            }

            foreach (var xElement in xmlSettings.Elements("Items").Elements("Item"))
            {
                var curItem = new ItemProperty();
                curItem.Id    = (int?)xElement.Attribute("Id") ?? -1;
                curItem.Name  = (string)xElement.Attribute("Name");
                curItem.Scale = (float?)xElement.Attribute("Scale") ?? 1f;
                ItemProperties.Add(curItem);
                _itemLookup.Add(curItem.Id, curItem);
                int tally = (int?)xElement.Attribute("Tally") ?? 0;
                if (tally > 0)
                {
                    _tallynames.Add(tally, curItem.Name);
                }
                int head = (int?)xElement.Attribute("Head") ?? -1;
                if (head >= 0)
                {
                    _armorHeadNames.Add(head, curItem.Name);
                }
                int body = (int?)xElement.Attribute("Body") ?? -1;
                if (body >= 0)
                {
                    _armorBodyNames.Add(body, curItem.Name);
                }
                int legs = (int?)xElement.Attribute("Legs") ?? -1;
                if (legs >= 0)
                {
                    _armorLegsNames.Add(legs, curItem.Name);
                }
                bool rack = (bool?)xElement.Attribute("Rack") ?? false;
                if (rack)
                {
                    _rackable.Add(curItem.Id, curItem.Name);
                }
            }

            foreach (var xElement in xmlSettings.Elements("Paints").Elements("Paint"))
            {
                var curPaint = new PaintProperty();
                curPaint.Id    = (int?)xElement.Attribute("Id") ?? -1;
                curPaint.Name  = (string)xElement.Attribute("Name");
                curPaint.Color = ColorFromString((string)xElement.Attribute("Color"));
                PaintProperties.Add(curPaint);
            }

            int chestId = 0;

            foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                string tileName = (string)tileElement.Attribute("Name");
                if (tileName == "Chest" || tileName == "Dresser")
                {
                    ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 21);
                    foreach (var xElement in tileElement.Elements("Frames").Elements("Frame"))
                    {
                        var curItem = new ChestProperty();
                        curItem.Name = (string)xElement.Attribute("Name");
                        string variety = (string)xElement.Attribute("Variety");
                        if (variety != null)
                        {
                            if (tileName == "Dresser")
                            {
                                curItem.Name = variety + " " + "Dresser";
                            }
                            else
                            {
                                curItem.Name = curItem.Name + " " + variety;
                            }
                        }
                        curItem.ChestId  = chestId++;
                        curItem.UV       = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0);
                        curItem.TileType = type;
                        ChestProperties.Add(curItem);
                    }
                }
            }

            int signId = 0;

            foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                string tileName = (string)tileElement.Attribute("Name");
                if (tileName == "Sign" || tileName == "Grave Marker" || tileName == "Announcement Box")
                {
                    ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 55);
                    foreach (var xElement in tileElement.Elements("Frames").Elements("Frame"))
                    {
                        var    curItem = new SignProperty();
                        string variety = (string)xElement.Attribute("Variety");
                        if (variety != null)
                        {
                            if (tileName == "Sign")
                            {
                                curItem.Name = "Sign " + variety;
                            }
                            else
                            {
                                curItem.Name = variety;
                            }
                        }
                        curItem.SignId   = signId++;
                        curItem.UV       = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0);
                        curItem.TileType = type;
                        SignProperties.Add(curItem);
                    }
                }
            }

            foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                NpcIds.Add(name, id);
                NpcNames.Add(id, name);
                int frames = (int?)xElement.Attribute("Frames") ?? 16;
                NpcFrames.Add(id, frames);
            }

            foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                ItemPrefix.Add((byte)id, name);
            }

            foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut"))
            {
                var key  = InLineEnumTryParse <Key>((string)xElement.Attribute("Key"));
                var tool = (string)xElement.Attribute("Tool");
                ShortcutKeys.Add(key, tool);
            }

            XElement appSettings   = xmlSettings.Element("App");
            int      appWidth      = (int?)appSettings.Attribute("Width") ?? 800;
            int      appHeight     = (int?)appSettings.Attribute("Height") ?? 600;
            int      clipboardSize = (int)XNA.MathHelper.Clamp((int?)appSettings.Attribute("ClipboardRenderSize") ?? 512, 64, 4096);

            _appSize = new Vector2(appWidth, appHeight);
            ClipboardBuffer.ClipboardRenderSize = clipboardSize;

            ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools"));

            AltC        = (string)xmlSettings.Element("AltC");
            SteamUserId = (int?)xmlSettings.Element("SteamUserId") ?? null;
        }
        public static Tile ReadTileDataFromStreamV1(BinaryReader b, uint version)
        {
            var tile = new Tile();

            tile.IsActive = b.ReadBoolean();

            TileProperty tileProperty = null;

            if (tile.IsActive)
            {
                tile.Type    = b.ReadByte();
                tileProperty = TileProperties[tile.Type];


                if (tile.Type == (int)TileType.IceByRod)
                {
                    tile.IsActive = false;
                }

                if (version < 72 &&
                    (tile.Type == 35 || tile.Type == 36 || tile.Type == 170 || tile.Type == 171 || tile.Type == 172))
                {
                    tile.U = b.ReadInt16();
                    tile.V = b.ReadInt16();
                }
                else if (!tileProperty.IsFramed)
                {
                    tile.U = -1;
                    tile.V = -1;
                }
                else if (version < 28 && tile.Type == (int)(TileType.Torch))
                {
                    // torches didn't have extra in older versions.
                    tile.U = 0;
                    tile.V = 0;
                }
                else if (version < 40 && tile.Type == (int)TileType.Platform)
                {
                    tile.U = 0;
                    tile.V = 0;
                }
                else
                {
                    tile.U = b.ReadInt16();
                    tile.V = b.ReadInt16();

                    if (tile.Type == (int)TileType.Timer)
                    {
                        tile.V = 0;
                    }
                }


                if (version >= 48 && b.ReadBoolean())
                {
                    tile.TileColor = b.ReadByte();
                }
            }

            //skip obsolete hasLight
            if (version <= 25)
            {
                b.ReadBoolean();
            }

            if (b.ReadBoolean())
            {
                tile.Wall = b.ReadByte();
                if (version >= 48 && b.ReadBoolean())
                {
                    tile.WallColor = b.ReadByte();
                }
            }

            if (b.ReadBoolean())
            {
                tile.LiquidType   = LiquidType.Water;
                tile.LiquidAmount = b.ReadByte();
                if (b.ReadBoolean())
                {
                    tile.LiquidType = LiquidType.Lava;
                }
                if (version >= 51)
                {
                    if (b.ReadBoolean())
                    {
                        tile.LiquidType = LiquidType.Honey;
                    }
                }
            }

            if (version >= 33)
            {
                tile.WireRed = b.ReadBoolean();
            }
            if (version >= 43)
            {
                tile.WireGreen = b.ReadBoolean();
                tile.WireBlue  = b.ReadBoolean();
            }

            if (version >= 41)
            {
                bool isHalfBrick = b.ReadBoolean();

                if (tileProperty == null || !tileProperty.IsSolid)
                {
                    isHalfBrick = false;
                }

                if (version >= 49)
                {
                    tile.BrickStyle = (BrickStyle)b.ReadByte();

                    if (tileProperty == null || !tileProperty.IsSolid)
                    {
                        tile.BrickStyle = 0;
                    }
                }
            }
            if (version >= 42)
            {
                tile.Actuator = b.ReadBoolean();
                tile.InActive = b.ReadBoolean();
            }
            return(tile);
        }
示例#22
0
        public static Tile ReadTileDataFromStream(BinaryReader b, uint version)
        {
            Tile tile = new Tile();

            tile.IsActive = b.ReadBoolean();

            TileProperty tileProperty = null;

            if (tile.IsActive)
            {
                tile.Type    = b.ReadByte();
                tileProperty = TileProperties[tile.Type];


                if (tile.Type == 127)
                {
                    tile.IsActive = false;
                }

                if (version < 72 && (tile.Type == 35 || tile.Type == 36 || tile.Type == 170 || tile.Type == 171 || tile.Type == 172))
                {
                    tile.U = b.ReadInt16();
                    tile.V = b.ReadInt16();
                }
                else if (!tileProperty.IsFramed)
                {
                    tile.U = -1;
                    tile.V = -1;
                }
                else if (version < 28 && tile.Type == 4)
                {
                    // torches didn't have extra in older versions.
                    tile.U = 0;
                    tile.V = 0;
                }
                else if (version < 40 && tile.Type == 19)
                {
                    tile.U = 0;
                    tile.V = 0;
                }
                else
                {
                    tile.U = b.ReadInt16();
                    tile.V = b.ReadInt16();

                    if (tile.Type == 144) //timer
                    {
                        tile.V = 0;
                    }
                }


                if (version >= 48 && b.ReadBoolean())
                {
                    tile.Color = b.ReadByte();
                }
            }

            //skip obsolete hasLight
            if (version <= 25)
            {
                b.ReadBoolean();
            }

            if (b.ReadBoolean())
            {
                tile.Wall = b.ReadByte();
                if (version >= 48 && b.ReadBoolean())
                {
                    tile.WallColor = b.ReadByte();
                }
            }

            if (b.ReadBoolean())
            {
                tile.Liquid = b.ReadByte();
                tile.IsLava = b.ReadBoolean();
                if (version >= 51)
                {
                    tile.IsHoney = b.ReadBoolean();
                }
            }

            if (version >= 33)
            {
                tile.HasWire = b.ReadBoolean();
            }
            if (version >= 43)
            {
                tile.HasWire2 = b.ReadBoolean();
                tile.HasWire3 = b.ReadBoolean();
            }

            if (version >= 41)
            {
                tile.HalfBrick = b.ReadBoolean();

                if (tileProperty == null || !tileProperty.IsSolid)
                {
                    tile.HalfBrick = false;
                }

                if (version >= 49)
                {
                    tile.Slope = b.ReadByte();

                    if (tileProperty == null || !tileProperty.IsSolid)
                    {
                        tile.Slope = 0;
                    }
                }
            }
            if (version >= 42)
            {
                tile.Actuator = b.ReadBoolean();
                tile.InActive = b.ReadBoolean();
            }
            return(tile);
        }
        public static ClipboardBuffer Load4(string filename)
        {
            using (var stream = new FileStream(filename, FileMode.Open))
            {
                using (var b = new BinaryReader(stream))
                {
                    string name    = b.ReadString();
                    int    version = b.ReadInt32();

                    int sizeX  = b.ReadInt32();
                    int sizeY  = b.ReadInt32();
                    var buffer = new ClipboardBuffer(new Vector2Int32(sizeX, sizeY));
                    buffer.Name = name;

                    for (int x = 0; x < sizeX; ++x)
                    {
                        for (int y = 0; y < sizeY; y++)
                        {
                            var tile = new Tile();

                            tile.IsActive = b.ReadBoolean();

                            TileProperty tileProperty = null;
                            if (tile.IsActive)
                            {
                                tile.Type    = b.ReadByte();
                                tileProperty = World.TileProperties[tile.Type];

                                if (tile.Type == (int)TileType.IceByRod)
                                {
                                    tile.IsActive = false;
                                }

                                if (tileProperty.IsFramed)
                                {
                                    tile.U = b.ReadInt16();
                                    tile.V = b.ReadInt16();

                                    if (tile.Type == (int)TileType.Timer)
                                    {
                                        tile.V = 0;
                                    }
                                }
                                else
                                {
                                    tile.U = -1;
                                    tile.V = -1;
                                }

                                if (b.ReadBoolean())
                                {
                                    tile.TileColor = b.ReadByte();
                                }
                            }

                            if (b.ReadBoolean())
                            {
                                tile.Wall = b.ReadByte();
                                if (b.ReadBoolean())
                                {
                                    tile.WallColor = b.ReadByte();
                                }
                            }

                            if (b.ReadBoolean())
                            {
                                tile.LiquidType = LiquidType.Water;

                                tile.LiquidAmount = b.ReadByte();
                                bool IsLava = b.ReadBoolean();
                                if (IsLava)
                                {
                                    tile.LiquidType = LiquidType.Lava;
                                }
                                bool IsHoney = b.ReadBoolean();
                                if (IsHoney)
                                {
                                    tile.LiquidType = LiquidType.Honey;
                                }
                            }

                            tile.WireRed   = b.ReadBoolean();
                            tile.WireGreen = b.ReadBoolean();
                            tile.WireBlue  = b.ReadBoolean();

                            bool isHalfBrick = b.ReadBoolean();


                            var brickByte = b.ReadByte();
                            if (tileProperty == null || !tileProperty.IsSolid)
                            {
                                tile.BrickStyle = 0;
                            }
                            else
                            {
                                tile.BrickStyle = (BrickStyle)brickByte;
                            }

                            tile.Actuator = b.ReadBoolean();
                            tile.InActive = b.ReadBoolean();

                            // read complete, start compression
                            buffer.Tiles[x, y] = tile;

                            int rle = b.ReadInt16();
                            if (rle < 0)
                            {
                                throw new ApplicationException("Invalid Tile Data!");
                            }

                            if (rle > 0)
                            {
                                for (int k = y + 1; k < y + rle + 1; k++)
                                {
                                    var tcopy = (Tile)tile.Clone();
                                    buffer.Tiles[x, k] = tcopy;
                                }
                                y = y + rle;
                            }
                        }
                    }
                    for (int i = 0; i < 1000; i++)
                    {
                        if (b.ReadBoolean())
                        {
                            var chest = new Chest(b.ReadInt32(), b.ReadInt32());
                            for (int slot = 0; slot < Chest.MaxItems; slot++)
                            {
                                if (slot < Chest.MaxItems)
                                {
                                    int stackSize = (int)b.ReadInt16();
                                    chest.Items[slot].StackSize = stackSize;

                                    if (chest.Items[slot].StackSize > 0)
                                    {
                                        chest.Items[slot].NetId     = b.ReadInt32();
                                        chest.Items[slot].StackSize = stackSize;
                                        chest.Items[slot].Prefix    = b.ReadByte();
                                    }
                                }
                            }
                            buffer.Chests.Add(chest);
                        }
                    }

                    for (int i = 0; i < 1000; i++)
                    {
                        if (b.ReadBoolean())
                        {
                            Sign sign = new Sign();
                            sign.Text = b.ReadString();
                            sign.X    = b.ReadInt32();
                            sign.Y    = b.ReadInt32();

                            if (buffer.Tiles[sign.X, sign.Y].IsActive && Tile.IsSign(buffer.Tiles[sign.X, sign.Y].Type))
                            {
                                buffer.Signs.Add(sign);
                            }
                        }
                    }

                    string verifyName    = b.ReadString();
                    int    verifyVersion = b.ReadInt32();
                    int    verifyX       = b.ReadInt32();
                    int    verifyY       = b.ReadInt32();
                    if (buffer.Name == verifyName &&
                        version == verifyVersion &&
                        buffer.Size.X == verifyX &&
                        buffer.Size.Y == verifyY)
                    {
                        // valid;
                        return(buffer);
                    }
                    b.Close();
                    return(null);
                }
            }
        }
        private static void LoadObjectDbXml(string file)
        {
            var xmlSettings = XElement.Load(file);

            // Load Colors
            foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                string    name  = (string)xElement.Attribute("Name");
                XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color"));
                GlobalColors.Add(name, color);
            }

            foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = new TileProperty();

                // Read XML attributes
                curTile.Color      = ColorFromString((string)xElement.Attribute("Color"));
                curTile.Name       = (string)xElement.Attribute("Name");
                curTile.Id         = (int?)xElement.Attribute("Id") ?? 0;
                curTile.IsFramed   = (bool?)xElement.Attribute("Framed") ?? false;
                curTile.IsSolid    = (bool?)xElement.Attribute("Solid") ?? false;
                curTile.IsSolidTop = (bool?)xElement.Attribute("SolidTop") ?? false;
                curTile.IsLight    = (bool?)xElement.Attribute("Light") ?? false;
                curTile.IsAnimated = (bool?)xElement.Attribute("IsAnimated") ?? false;
                curTile.FrameSize  = StringToVector2ShortArray((string)xElement.Attribute("Size"), 1, 1);
                // curTile.FrameSize = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1);
                curTile.Placement   = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement"));
                curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16);
                curTile.FrameGap    = StringToVector2Short((string)xElement.Attribute("FrameGap"), 0, 0);
                curTile.IsGrass     = "Grass".Equals((string)xElement.Attribute("Special"));    /* Heathtech */
                curTile.IsPlatform  = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */
                curTile.IsCactus    = "Cactus".Equals((string)xElement.Attribute("Special"));   /* Heathtech */
                curTile.IsStone     = (bool?)xElement.Attribute("Stone") ?? false;              /* Heathtech */
                curTile.CanBlend    = (bool?)xElement.Attribute("Blends") ?? false;             /* Heathtech */
                curTile.MergeWith   = (int?)xElement.Attribute("MergeWith") ?? null;            /* Heathtech */
                string frameNamePostfix = (string)xElement.Attribute("FrameNamePostfix") ?? null;

                foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame"))
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = (string)elementFrame.Attribute("Name");
                    curFrame.Variety = (string)elementFrame.Attribute("Variety");
                    curFrame.UV      = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0);
                    curFrame.Anchor  = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor"));
                    var frameSize = StringToVector2Short((string)elementFrame.Attribute("FrameSize"), curTile.FrameSize[0].X, curTile.FrameSize[0].Y);

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    string spriteName = null;
                    if (curFrame.Name == curTile.Name)
                    {
                        if (!string.IsNullOrWhiteSpace(curFrame.Variety))
                        {
                            spriteName += curFrame.Variety;
                        }
                    }
                    else
                    {
                        spriteName += curFrame.Name;
                        if (!string.IsNullOrWhiteSpace(curFrame.Variety))
                        {
                            spriteName += " - " + curFrame.Variety;
                        }
                    }
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = spriteName,
                        Origin           = curFrame.UV,
                        Size             = frameSize,
                        Tile             = (ushort)curTile.Id, /* SBlogic */
                        TileName         = curTile.Name
                    });
                }
                if (curTile.Frames.Count == 0 && curTile.IsFramed)
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = curTile.Name;
                    curFrame.Variety = string.Empty;
                    curFrame.UV      = new Vector2Short(0, 0);
                    //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor"));

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = null,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize[0],
                        Tile             = (ushort)curTile.Id,
                        TileName         = curTile.Name
                    });
                }
                TileProperties.Add(curTile);
                if (!curTile.IsFramed)
                {
                    TileBricks.Add(curTile);
                }
            }
            for (int i = TileProperties.Count; i < 255; i++)
            {
                TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true));
            }

            foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = new WallProperty();
                curWall.Color = ColorFromString((string)xElement.Attribute("Color"));
                curWall.Name  = (string)xElement.Attribute("Name");
                curWall.Id    = (int?)xElement.Attribute("Id") ?? -1;
                WallProperties.Add(curWall);
            }

            foreach (var xElement in xmlSettings.Elements("Items").Elements("Item"))
            {
                var curItem = new ItemProperty();
                curItem.Id    = (int?)xElement.Attribute("Id") ?? -1;
                curItem.Name  = (string)xElement.Attribute("Name");
                curItem.Scale = (float?)xElement.Attribute("Scale") ?? 1f;

                ItemProperties.Add(curItem);
                _itemLookup.Add(curItem.Id, curItem);
                int tally = (int?)xElement.Attribute("Tally") ?? 0;
                if (tally > 0)
                {
                    _tallynames.Add(tally, curItem.Name);
                }
                int head = (int?)xElement.Attribute("Head") ?? -1;
                if (head >= 0)
                {
                    _armorHeadNames.Add(head, curItem.Name);
                }
                int body = (int?)xElement.Attribute("Body") ?? -1;
                if (body >= 0)
                {
                    _armorBodyNames.Add(body, curItem.Name);
                }
                int legs = (int?)xElement.Attribute("Legs") ?? -1;
                if (legs >= 0)
                {
                    _armorLegsNames.Add(legs, curItem.Name);
                }
                bool rack = (bool?)xElement.Attribute("Rack") ?? false;
                if (rack)
                {
                    _rackable.Add(curItem.Id, curItem.Name);
                }

                bool food = (bool?)xElement.Attribute("IsFood") ?? false;
                if (food)
                {
                    _foodNames.Add(curItem.Id, curItem.Name);
                    curItem.IsFood = true;
                }

                bool acc = (bool?)xElement.Attribute("Accessory") ?? false;
                if (acc)
                {
                    _accessoryNames.Add(curItem.Id, curItem.Name);
                }

                if (curItem.Name.Contains("Dye"))
                {
                    _dyeNames.Add(curItem.Id, curItem.Name);
                }
            }

            foreach (var xElement in xmlSettings.Elements("Paints").Elements("Paint"))
            {
                var curPaint = new PaintProperty();
                curPaint.Id    = (int?)xElement.Attribute("Id") ?? -1;
                curPaint.Name  = (string)xElement.Attribute("Name");
                curPaint.Color = ColorFromString((string)xElement.Attribute("Color"));
                PaintProperties.Add(curPaint);
            }

            int chestId = 0;

            foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                string tileName = (string)tileElement.Attribute("Name");
                int    type     = (int)tileElement.Attribute("Id");
                if (Tile.IsChest(type))
                {
                    foreach (var xElement in tileElement.Elements("Frames").Elements("Frame"))
                    {
                        var curItem = new ChestProperty();
                        curItem.Name = (string)xElement.Attribute("Name");
                        string variety = (string)xElement.Attribute("Variety");
                        if (variety != null)
                        {
                            if (tileName == "Dresser")
                            {
                                curItem.Name = variety + " " + "Dresser";
                            }
                            else
                            {
                                curItem.Name = curItem.Name + " " + variety;
                            }
                        }
                        curItem.ChestId  = chestId++;
                        curItem.UV       = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0);
                        curItem.TileType = (ushort)type;
                        ChestProperties.Add(curItem);
                    }
                }
            }

            int signId = 0;

            foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var    tileId   = (int?)tileElement.Attribute("Id") ?? 0;
                string tileName = (string)tileElement.Attribute("Name");
                if (Tile.IsSign(tileId))
                {
                    ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 55);
                    foreach (var xElement in tileElement.Elements("Frames").Elements("Frame"))
                    {
                        var    curItem = new SignProperty();
                        string variety = (string)xElement.Attribute("Variety");
                        string anchor  = (string)xElement.Attribute("Anchor");
                        curItem.Name     = $"{tileName} {variety} {anchor}";
                        curItem.SignId   = signId++;
                        curItem.UV       = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0);
                        curItem.TileType = type;
                        SignProperties.Add(curItem);
                    }
                }
            }

            foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                NpcIds[name] = id;
                NpcNames[id] = name;
                var frames = StringToVector2Short((string)xElement.Attribute("Size"), 16, 40);
                NpcFrames[id] = frames;
            }

            foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                ItemPrefix.Add((byte)id, name);
            }

            foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut"))
            {
                var key      = InLineEnumTryParse <Key>((string)xElement.Attribute("Key"));
                var modifier = InLineEnumTryParse <ModifierKeys>((string)xElement.Attribute("Modifier"));
                var tool     = (string)xElement.Attribute("Action");
                ShortcutKeys.Add(tool, key, modifier);
            }

            XElement appSettings   = xmlSettings.Element("App");
            int      appWidth      = (int?)appSettings.Attribute("Width") ?? 800;
            int      appHeight     = (int?)appSettings.Attribute("Height") ?? 600;
            int      clipboardSize = (int)XNA.MathHelper.Clamp((int?)appSettings.Attribute("ClipboardRenderSize") ?? 512, 64, 4096);

            _appSize = new Vector2(appWidth, appHeight);
            ClipboardBuffer.ClipboardRenderSize = clipboardSize;

            ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools"));

            AltC        = (string)xmlSettings.Element("AltC");
            SteamUserId = (int?)xmlSettings.Element("SteamUserId") ?? null;
        }
示例#25
0
            /// <summary>
            /// Get image cache or schedule it for later download.
            /// </summary>
            /// <param name="x">tile x in tile-map coordinates</param>
            /// <param name="y"></param>
            /// <param name="zoom"></param>
            /// <param name="mapType"></param>
            /// <returns></returns>
            public Image getImage(int x, int y, int zoom, MapType mapType, bool tryDownloading)
            {
                int w = currentScreenRect.Width;
                int h = currentScreenRect.Height;

                int dx = x - currentScreenRect.X;
                int dy = y - currentScreenRect.Y;

                if (tryDownloading == false)
                {
                    //TileProperty tile = searchInMemoryCache(x, y, zoom, mapType);

                }

                if (dx >= 0 && dx < w && dy >= 0 && dy < h)
                {
                    // get from instant cache (L1)
                    TileProperty tile = imageArray[dx, dy];
                    if (tile == null)
                    {
                        // get from bigCache (L2)
                        tile = searchInMemoryCache(x, y, zoom, mapType);
                        if (tile == null)
                        {
                            tile = new TileProperty(x, y, zoom, mapType);
                        }
                        imageArray[dx, dy] = tile; // download pending (queued)
                    }
                    if (tile.image == null && tile.timeDownloadStarted == DateTime.MinValue)
                    {
                        if (activeDownloads >= activeDownloadsLimit)
                        {
                            // stack up this request
                            TileProperty tileFound = searchOnStackAndPop(x, y, zoom, mapType);
                            if (tileFound == null)
                            {
                                downloadsStack.Add(tile);
                                if (downloadsStack.Count > downloadsStackSizeLimit)
                                {
                                    // remove bottom element
                                    downloadsStack.RemoveAt(0);
                                }

                                Debug.Print("Stack size (+)=" + downloadsStack.Count.ToString());
                            }
                            else
                            {
                                downloadsStack.Add(tileFound); // move this tile to top (priritize it)
                            }
                        }
                        else
                        {
                            // initiate asynchronious image loading
                            scheduleForDownload(tile);
                        }
                    }
                    return tile.image;
                }
                else
                {
                    // this image is outside requested area
                    return null;
                }
            }
示例#26
0
        /// <summary>
        /// Loads the default monopoly board
        /// </summary>
        /// <returns>A linkedlist representation of the board</returns>
        public TileLinkedList LoadDefauldBoard()
        {
            TileLinkedList board = new TileLinkedList();

            City purple = new City();
            City gray   = new City();
            City pink   = new City();
            City orange = new City();
            City red    = new City();
            City yellow = new City();
            City green  = new City();
            City blue   = new City();

            TileProperty medAvenue      = new TileProperty(CurrentGame, "Mediterranean Avenue", new[] { 2, 10, 30, 90, 160, 250 }, 30, 60, 50, purple);
            TileProperty balticAvenue   = new TileProperty(CurrentGame, "Baltic Avenue", new[] { 4, 20, 60, 180, 320, 450 }, 30, 60, 50, purple);
            TileProperty orienAvenue    = new TileProperty(CurrentGame, "Oriental Avenue", new[] { 6, 30, 90, 270, 400, 550 }, 50, 100, 50, gray);
            TileProperty vermAvenue     = new TileProperty(CurrentGame, "Vermont Avenue", new[] { 6, 30, 90, 270, 400, 550 }, 50, 100, 50, gray);
            TileProperty connecAvenue   = new TileProperty(CurrentGame, "Connecticut Avenue", new[] { 8, 40, 100, 300, 450, 600 }, 60, 120, 50, gray);
            TileProperty stCharlesPlace = new TileProperty(CurrentGame, "St. Charles Place", new[] { 10, 50, 150, 450, 625, 750 }, 70, 140, 100, pink);
            TileProperty statesAvenue   = new TileProperty(CurrentGame, "States Avenue", new[] { 10, 50, 150, 450, 625, 750 }, 70, 140, 100, pink);
            TileProperty virginAvenue   = new TileProperty(CurrentGame, "Virginia Avenue", new[] { 12, 60, 180, 500, 700, 900 }, 80, 160, 100, pink);
            TileProperty stJamesPlace   = new TileProperty(CurrentGame, "St. James Place", new[] { 14, 70, 200, 550, 750, 950 }, 90, 180, 100, orange);
            TileProperty tennAvenue     = new TileProperty(CurrentGame, "Tennessee Avenue", new[] { 14, 70, 200, 550, 750, 950 }, 90, 180, 100, orange);
            TileProperty nyAvenue       = new TileProperty(CurrentGame, "New York Avenue", new[] { 16, 80, 220, 600, 800, 1000 }, 100, 200, 100, orange);
            TileProperty kentAvenue     = new TileProperty(CurrentGame, "Kentucky Avenue", new[] { 18, 90, 250, 700, 875, 1050 }, 110, 220, 150, red);
            TileProperty indiAvenue     = new TileProperty(CurrentGame, "Indiana Avenue", new[] { 18, 90, 250, 700, 875, 1050 }, 110, 220, 150, red);
            TileProperty illiAvenue     = new TileProperty(CurrentGame, "Illinois Avenue", new[] { 20, 100, 300, 750, 925, 1100 }, 120, 240, 150, red);
            TileProperty atlAvenue      = new TileProperty(CurrentGame, "Atlantic Avenue", new[] { 22, 110, 330, 800, 975, 1150 }, 130, 260, 150, yellow);
            TileProperty ventnAvenue    = new TileProperty(CurrentGame, "Ventnor Avenue", new[] { 22, 110, 330, 800, 975, 1150 }, 130, 260, 150, yellow);
            TileProperty marvinGardens  = new TileProperty(CurrentGame, "Marvin Gardens", new[] { 24, 120, 360, 850, 1025, 1200 }, 140, 280, 150, yellow);
            TileProperty pacifAvenue    = new TileProperty(CurrentGame, "Pacific Avenue", new[] { 26, 130, 390, 900, 1100, 1275 }, 150, 300, 200, green);
            TileProperty northCaAvnue   = new TileProperty(CurrentGame, "North Carolina Avenue", new[] { 26, 130, 390, 900, 1100, 1275 }, 150, 300, 200, green);
            TileProperty pennsyAvenue   = new TileProperty(CurrentGame, "Pennsylvania Avenue", new[] { 28, 150, 450, 1000, 1200, 1400 }, 160, 320, 200, green);
            TileProperty parkPlace      = new TileProperty(CurrentGame, "Park Place", new[] { 35, 175, 500, 1100, 1300, 1500 }, 175, 350, 200, blue);

            CurrentGame.Boardwalk = new TileProperty(CurrentGame, "Boardwalk", new[] { 50, 200, 600, 1400, 1700, 2000 }, 200, 400, 200, blue);

            purple.Streets.Add(medAvenue);
            purple.Streets.Add(balticAvenue);
            gray.Streets.Add(orienAvenue);
            gray.Streets.Add(vermAvenue);
            gray.Streets.Add(connecAvenue);
            pink.Streets.Add(stCharlesPlace);
            pink.Streets.Add(statesAvenue);
            pink.Streets.Add(virginAvenue);
            orange.Streets.Add(stJamesPlace);
            orange.Streets.Add(tennAvenue);
            orange.Streets.Add(nyAvenue);
            red.Streets.Add(kentAvenue);
            red.Streets.Add(indiAvenue);
            red.Streets.Add(illiAvenue);
            yellow.Streets.Add(atlAvenue);
            yellow.Streets.Add(ventnAvenue);
            yellow.Streets.Add(marvinGardens);
            green.Streets.Add(pacifAvenue);
            green.Streets.Add(northCaAvnue);
            green.Streets.Add(pennsyAvenue);
            blue.Streets.Add(parkPlace);
            blue.Streets.Add(CurrentGame.Boardwalk);

            CurrentGame.JailVisit = new TileJailVisit(CurrentGame, "Jail visit");
            CurrentGame.Jail      = new TileJail(CurrentGame, "Jail");
            CurrentGame.GoToJail  = new TileGoToJail(CurrentGame, "Go to jail");

            CurrentGame.Start = new TileStart(CurrentGame, "Start");
            CurrentGame.Boardwalk.NextTile = CurrentGame.Start;
            CurrentGame.Start.PreviousTile = CurrentGame.Boardwalk;

            board.Add(CurrentGame.Boardwalk);
            board.Add(new TileTaxes(CurrentGame, "Luxury Tax"));
            board.Add(parkPlace);
            board.Add(new TileChance(CurrentGame, "Chance Card"));
            board.Add(new TileRailRoad(CurrentGame, "Short Line", new[] { 25, 50, 100, 200 }, 100, 200));
            board.Add(pennsyAvenue);
            board.Add(new TileCommunity(CurrentGame, "Community Chest"));
            board.Add(northCaAvnue);
            board.Add(pacifAvenue);
            board.Add(CurrentGame.GoToJail);
            board.Add(marvinGardens);
            board.Add(new TileCompany(CurrentGame, "Water Works", 75, 150));
            board.Add(ventnAvenue);
            board.Add(atlAvenue);
            board.Add(new TileRailRoad(CurrentGame, "B&O Railroad", new[] { 25, 50, 100, 200 }, 100, 200));
            board.Add(illiAvenue);
            board.Add(indiAvenue);
            board.Add(new TileChance(CurrentGame, "Chance Card"));
            board.Add(kentAvenue);
            board.Add(new TileFreeParking(CurrentGame, "Free Parking"));
            board.Add(nyAvenue);
            board.Add(tennAvenue);
            board.Add(new TileCommunity(CurrentGame, "Community Chest"));
            board.Add(stJamesPlace);
            board.Add(new TileRailRoad(CurrentGame, "Pennsylvania Railroad", new[] { 25, 50, 100, 200 }, 100, 200));
            board.Add(virginAvenue);
            board.Add(statesAvenue);
            board.Add(new TileCompany(CurrentGame, "Electric Company", 75, 150));
            board.Add(stCharlesPlace);
            board.Add(CurrentGame.JailVisit);
            board.Add(connecAvenue);
            board.Add(vermAvenue);
            board.Add(new TileChance(CurrentGame, "Chance Card"));
            board.Add(orienAvenue);
            board.Add(new TileRailRoad(CurrentGame, "Reading Railroad", new[] { 25, 50, 100, 200 }, 100, 200));
            board.Add(new TileTaxes(CurrentGame, "Income Tax"));
            board.Add(balticAvenue);
            board.Add(new TileCommunity(CurrentGame, "Community Card"));
            board.Add(medAvenue);
            board.Add(CurrentGame.Start);

            return(board);
        }
示例#27
0
            void addToBigCache(TileProperty tile)
            {
                TileProperty tileFound = searchInMemoryCache(tile.x, tile.y, tile.zoom, tile.mapType);

                if (tileFound == null)
                {
                    memoryCache.Add(tile);

                    while (memoryCache.Count > memoryCacheSizeLimit)
                    {
                        memoryCache.RemoveAt(0);
                    }
                }
                else
                {
                    tileFound.x = tile.x;
                    tileFound.y = tile.y;
                    tileFound.zoom = tile.zoom;
                    tileFound.mapType = tile.mapType;
                    tileFound.image = tile.image;
                    tileFound.timeDownloadStarted = tile.timeDownloadStarted;
                    tileFound.timeDownloadEnded = tile.timeDownloadEnded;
                }
            }
示例#28
0
 public void SwitchToHole()
 {
     tileProperties = tileProperties | TileProperty.Hole;
     // Switch mesh
 }
示例#29
0
            void scheduleForDownload(TileProperty tile)
            {
                Debug.Assert(tile != null);

                // stats
                tile.timeDownloadStarted = DateTime.Now;
                activeDownloads++;
                Debug.Print("Active downloads (+)=" + activeDownloads.ToString());

                BackgroundWorker bgWorker = new BackgroundWorker();
                bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
                bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
                bgWorker.RunWorkerAsync(tile);
            }
示例#30
0
 public void SetProperty( TileProperty property )
 {
     this.property = property;
 }
示例#31
0
 public void SwitchToCrater()
 {
     tileProperties = tileProperties | TileProperty.Crater;
     tileProperties = tileProperties ^ TileProperty.Landmine;
     // Switch mesh
 }
示例#32
0
 public bool HasProperty(TileProperty property)
 {
     return((value & (int)property) > 0);
 }
示例#33
0
        private static void LoadObjectDbXml(string file)
        {
            var xmlSettings = XElement.Load(file);

            // Load Colors
            foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                string    name  = (string)xElement.Attribute("Name");
                XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color"));
                GlobalColors.Add(name, color);
            }

            foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = new TileProperty();

                // Read XML attributes
                curTile.Color       = ColorFromString((string)xElement.Attribute("Color"));
                curTile.Name        = (string)xElement.Attribute("Name");
                curTile.Id          = (int?)xElement.Attribute("Id") ?? 0;
                curTile.IsFramed    = (bool?)xElement.Attribute("Framed") ?? false;
                curTile.IsSolid     = (bool?)xElement.Attribute("Solid") ?? false;
                curTile.IsSolidTop  = (bool?)xElement.Attribute("SolidTop") ?? false;
                curTile.IsLight     = (bool?)xElement.Attribute("Light") ?? false;
                curTile.FrameSize   = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1);
                curTile.Placement   = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement"));
                curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16);
                curTile.IsGrass     = "Grass".Equals((string)xElement.Attribute("Special"));    /* Heathtech */
                curTile.IsPlatform  = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */
                curTile.IsCactus    = "Cactus".Equals((string)xElement.Attribute("Special"));   /* Heathtech */
                curTile.IsStone     = (bool?)xElement.Attribute("Stone") ?? false;              /* Heathtech */
                curTile.CanBlend    = (bool?)xElement.Attribute("Blends") ?? false;             /* Heathtech */
                curTile.MergeWith   = (int?)xElement.Attribute("MergeWith") ?? null;            /* Heathtech */
                foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame"))
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = (string)elementFrame.Attribute("Name");
                    curFrame.Variety = (string)elementFrame.Attribute("Variety");
                    curFrame.UV      = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0);
                    curFrame.Anchor  = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor"));

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = curFrame.Name + ", " + curFrame.Variety,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize,
                        Tile             = (byte)curTile.Id,
                        TileName         = curTile.Name
                    });
                    if (curTile.FrameSize.X == 0 && curTile.FrameSize.Y == 0)
                    {
                        int z = 0;
                    }
                }
                if (curTile.Frames.Count == 0 && curTile.IsFramed)
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = curTile.Name;
                    curFrame.Variety = string.Empty;
                    curFrame.UV      = new Vector2Short(0, 0);
                    //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor"));

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = curFrame.Name + ", " + curFrame.Variety,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize,
                        Tile             = (byte)curTile.Id,
                        TileName         = curTile.Name
                    });
                }
                TileProperties.Add(curTile);
                if (!curTile.IsFramed)
                {
                    TileBricks.Add(curTile);
                }
            }
            for (int i = TileProperties.Count; i < 255; i++)
            {
                TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true));
            }

            foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = new WallProperty();
                curWall.Color   = ColorFromString((string)xElement.Attribute("Color"));
                curWall.Name    = (string)xElement.Attribute("Name");
                curWall.Id      = (int?)xElement.Attribute("Id") ?? -1;
                curWall.IsHouse = (bool?)xElement.Attribute("IsHouse") ?? false;
                WallProperties.Add(curWall);
            }

            foreach (var xElement in xmlSettings.Elements("Items").Elements("Item"))
            {
                var curItem = new ItemProperty();
                curItem.Id   = (int?)xElement.Attribute("Id") ?? -1;
                curItem.Name = (string)xElement.Attribute("Name");
                ItemProperties.Add(curItem);
                _itemLookup.Add(curItem.Id, curItem);
            }

            foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                NpcIds.Add(name, id);
                int frames = (int?)xElement.Attribute("Frames") ?? 16;
                NpcFrames.Add(id, frames);
            }

            foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                ItemPrefix.Add((byte)id, name);
            }

            foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut"))
            {
                var key  = InLineEnumTryParse <Key>((string)xElement.Attribute("Key"));
                var tool = (string)xElement.Attribute("Tool");
                ShortcutKeys.Add(key, tool);
            }

            XElement appSettings = xmlSettings.Element("App");
            int      appWidth    = (int?)appSettings.Attribute("Width") ?? 800;
            int      appHeight   = (int?)appSettings.Attribute("Height") ?? 600;

            _appSize = new Vector2(appWidth, appHeight);

            ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools"));

            AltC = (string)xmlSettings.Element("AltC");
        }
示例#34
0
 /// <summary>
 /// Initialized the models
 /// </summary>
 private void InitModels()
 {
     Information  = new Information();
     MapData      = new MapData();
     TileProperty = new TileProperty(0);
 }
示例#35
0
 public bool HasTileProperty(TileProperty tileProperty)
 {
     return (tileProperties & tileProperty) == tileProperty;
 }
示例#36
0
 set => SetValue(TileProperty, value);