public static unsafe RadarMapBlock?GetRadarMapBlock(int map, int blockX, int blockY) { IndexMap indexMap = GetIndex(map, blockX, blockY); if (indexMap.MapAddress == 0) { return(null); } MapBlock *mp = (MapBlock *)indexMap.MapAddress; MapCells *cells = (MapCells *)&mp->Cells; RadarMapBlock mb = new RadarMapBlock { Cells = new RadarMapcells[8, 8] }; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { ref MapCells cell = ref cells[y * 8 + x]; ref RadarMapcells outcell = ref mb.Cells[x, y]; outcell.Graphic = cell.TileID; outcell.Z = cell.Z; outcell.IsLand = true; }
public MapCells GetFirstMapCells() { // t:MapCells doesn't works (tested in project folder window) // should we call every scriptableobject that has 'MapCells' inside its name. string filter = "t:ScriptableObject MapCell"; string[] mapCellsGUID = AssetDatabase.FindAssets(filter); if (mapCellsGUID.Length == 0) { Debug.LogErrorFormat("Map Cells : No MapCells found in project. To be founded, the MapCell you want to edit must have 'MapCell' in its name."); return(null); } string firstMapCellGUID = mapCellsGUID[0]; string firstCellPath = AssetDatabase.GUIDToAssetPath(firstMapCellGUID); MapCells mapCells = AssetDatabase.LoadAssetAtPath <MapCells>(firstCellPath); if (mapCellsGUID.Length > 1) { Debug.LogWarningFormat("Map Cells : " + "There is more than one MapCells. We are editing " + mapCells.name + "."); } return(mapCells); }
private void GetMesh(MapCells cell, ref MeshData cellMesh) { ContourMesh contourMesh = new ContourMesh(cell.map, squareSize, drawContours, drawSimple, uniqueVertcies, cell.xOffset, cell.zOffset); cellMesh = contourMesh.GetMeshData(); methodQueue.Enqueue(() => MeshDataCounter()); }
private void CreateBrush() { if (_currentCellBrush != null) { Debug.LogWarningFormat("Map Cells : Can't create brush because it already exists."); return; } MapCells mapCells = GetFirstMapCells(); _currentCellBrush = new CellBrush(mapCells, CellType.Walkable); }
// Konstruktor public clsMap(int CellCountX, int CellCountY) { this.CellCountX = CellCountX; this.CellCountY = CellCountY; // Liste mit den einzelnen Feldern erstellen for (int x = 0; x < CellCountX; x++) { for (int y = 0; y < CellCountY; y++) { clsMapCell MapCell = new Map.clsMapCell(this, x, y); MapCells.Add(MapCell); } } }
private unsafe void Load() { int size = FileManager.Map.MapsDefaultSize[World.MapIndex, 0] * FileManager.Map.MapsDefaultSize[World.MapIndex, 1]; ushort[] buffer = new ushort[size]; int maxBlock = size - 1; for (int bx = 0; bx < FileManager.Map.MapBlocksSize[World.MapIndex, 0]; bx++) { int mapX = bx << 3; for (int by = 0; by < FileManager.Map.MapBlocksSize[World.MapIndex, 1]; by++) { IndexMap indexMap = World.Map.GetIndex(bx, by); if (indexMap.MapAddress == 0) { continue; } int mapY = by << 3; MapBlock info = new MapBlock(); MapCells *infoCells = (MapCells *)&info.Cells; MapBlock *mapBlock = (MapBlock *)indexMap.MapAddress; MapCells *cells = (MapCells *)&mapBlock->Cells; int pos = 0; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { ref MapCells cell = ref cells[pos]; ref MapCells infoCell = ref infoCells[pos]; infoCell.TileID = cell.TileID; infoCell.Z = cell.Z; pos++; } } StaticsBlock *sb = (StaticsBlock *)indexMap.StaticAddress; if (sb != null) { int count = (int)indexMap.StaticCount; for (int c = 0; c < count; c++) { ref readonly StaticsBlock staticBlock = ref sb[c];
public void ProcessCells(GridCell[,] cells) { MapCells[] holdMapCells = new MapCells[cells.GetLength(1)]; for (int y = 0; y < cells.GetLength(1); y++) { holdMapCells[y] = new MapCells(cells.GetLength(0)); for (int x = 0; x < cells.GetLength(0); x++) { holdMapCells[y].height[x] = cells[x, y].height; holdMapCells[y].color[x] = cells[x, y].color; holdMapCells[y].template[x] = cells[x, y].cellTemplate; } } mapCells = holdMapCells; }
public void FormatMapCells() { MapCells[] holdCells = new MapCells[height]; int xDiff = height < mapCells.Length ? mapCells.Length : height; int lowerY = height > mapCells.Length ? mapCells.Length : height; int lowerX; for (int y = 0; y < lowerY; y++) { lowerX = width > mapCells[y].height.Length ? mapCells[y].height.Length : width; holdCells[y] = new MapCells(width); for (int x = 0; x < width; x++) { holdCells[y].height[x] = mapCells[y].height[x]; holdCells[y].color[x] = mapCells[y].color[x]; } xDiff = mapCells[y].height.Length; } int yDiff = mapCells.Length; for (int y = 0; y < height - yDiff; y++) { holdCells[y + yDiff] = new MapCells(width); for (int x = 0; x < width; x++) { holdCells[y + yDiff].height[x] = 0; holdCells[y + yDiff].color[x] = Color.black; } } for (int y = 0; y < yDiff; y++) { for (int x = 0; x < width - xDiff; x++) { holdCells[y].height[x + xDiff] = 0; holdCells[y].color[x + xDiff] = Color.black; } } mapCells = holdCells; }
public static unsafe RadarMapBlock?GetRadarMapBlock(int map, int blockX, int blockY) { IndexMap indexMap = GetIndex(map, blockX, blockY); if (indexMap == null || indexMap.MapAddress == 0) { return(null); } MapBlock block = Marshal.PtrToStructure <MapBlock>((IntPtr)indexMap.MapAddress); RadarMapBlock mb = new RadarMapBlock(); mb.Cells = new RadarMapcells[8, 8]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { ref MapCells cell = ref block.Cells[y * 8 + x]; ref RadarMapcells outcell = ref mb.Cells[x, y]; outcell.Graphic = cell.TileID; outcell.Z = cell.Z; outcell.IsLand = true; }
public void StartThreads() { int cellCount = 0, cellX, cellZ; for (int a = 0; a < divX; a++) { for (int b = 0; b < divZ; b++) { meshCells[cellCount] = new MeshData(); cells[cellCount] = new MapCells(); cells[cellCount].map = new bool[cellWidth, cellHeight]; cellX = (a * cellWidth); cellZ = (b * cellHeight); cells[cellCount].xOffset = cellX / 2; cells[cellCount].zOffset = cellZ / 2; for (int c = cellX; c < cellWidth + cellX; c++) { for (int d = cellZ; d < cellHeight + cellZ; d++) { cells[cellCount].map[c - cellX, d - cellZ] = map[c, d]; } } cellCount++; } } for (int n = 0; n < threadCount; n++) { int x = n; var thread = new Thread(() => GetMesh(cells[x], ref meshCells[x])); thread.Start(); } }
private unsafe void Load() { int size = IO.Resources.Map.MapsDefaultSize[World.MapIndex][0] * IO.Resources.Map.MapsDefaultSize[World.MapIndex][1]; ushort[] buffer = new ushort[size]; int maxBlock = size - 1; for (int bx = 0; bx < IO.Resources.Map.MapBlocksSize[World.MapIndex][0]; bx++) { int mapX = bx * 8; for (int by = 0; by < IO.Resources.Map.MapBlocksSize[World.MapIndex][1]; by++) { IndexMap indexMap = World.Map.GetIndex(bx, by); if (indexMap.MapAddress == 0) { continue; } int mapY = by * 8; MapBlock info = new MapBlock(); MapCells *infoCells = (MapCells *)&info.Cells; MapBlock *mapBlock = (MapBlock *)indexMap.MapAddress; MapCells *cells = (MapCells *)&mapBlock->Cells; int pos = 0; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { ref MapCells cell = ref cells[pos]; ref MapCells infoCell = ref infoCells[pos]; infoCell.TileID = cell.TileID; infoCell.Z = cell.Z; pos++; } } StaticsBlock *sb = (StaticsBlock *)indexMap.StaticAddress; if (sb != null) { int count = (int)indexMap.StaticCount; for (int c = 0; c < count; c++) { StaticsBlock staticBlock = sb[c]; if (staticBlock.Color > 0 && staticBlock.Color != 0xFFFF && !View.IsNoDrawable(staticBlock.Color)) { pos = staticBlock.Y * 8 + staticBlock.X; ref MapCells cell = ref infoCells[pos]; if (cell.Z <= staticBlock.Z) { cell.TileID = (ushort)(staticBlock.Color + 0x4000); cell.Z = staticBlock.Z; } } } }
public MapRow() { this.cells = new MapCells(); }
public Problem(string[] mapStringLines) { this.MapCells = new List <List <MapCell> >(); this.CartCoords = new List <Coordinates>(); int rowNum = 0; foreach (var line in mapStringLines) { var mapLine = new List <MapCell>(); int colNum = 0; foreach (var segment in line) { switch (segment) { case '|': mapLine.Add(new MapCell(TrackShape.Vertical, null)); break; case '-': mapLine.Add(new MapCell(TrackShape.Horizontal, null)); break; case '/': mapLine.Add(new MapCell(TrackShape.UpRightLeftDown, null)); break; case '\\': mapLine.Add(new MapCell(TrackShape.UpLeftRightDown, null)); break; case '+': mapLine.Add(new MapCell(TrackShape.Intersection, null)); break; case '<': mapLine.Add(new MapCell(TrackShape.Horizontal, new Cart(Direction.Left, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case '>': mapLine.Add(new MapCell(TrackShape.Horizontal, new Cart(Direction.Right, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case '^': mapLine.Add(new MapCell(TrackShape.Vertical, new Cart(Direction.Up, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case 'v': mapLine.Add(new MapCell(TrackShape.Vertical, new Cart(Direction.Down, 0))); CartCoords.Add(new Coordinates(colNum, rowNum)); break; case ' ': mapLine.Add(new MapCell(TrackShape.Empty, null)); break; } colNum++; } rowNum++; MapCells.Add(mapLine); } }
private unsafe void CreateMiniMapTexture(bool force = false) { if (_gumpTexture == null || _gumpTexture.IsDisposed) { return; } ushort lastX = World.Player.X; ushort lastY = World.Player.Y; if (_x != lastX || _y != lastY) { _x = lastX; _y = lastY; } else if (!force) { return; } int blockOffsetX = Width >> 2; int blockOffsetY = Height >> 2; int gumpCenterX = Width >> 1; //int gumpCenterY = Height >> 1; //0xFF080808 - pixel32 //0x8421 - pixel16 int minBlockX = ((lastX - blockOffsetX) >> 3) - 1; int minBlockY = ((lastY - blockOffsetY) >> 3) - 1; int maxBlockX = ((lastX + blockOffsetX) >> 3) + 1; int maxBlockY = ((lastY + blockOffsetY) >> 3) + 1; if (minBlockX < 0) { minBlockX = 0; } if (minBlockY < 0) { minBlockY = 0; } int maxBlockIndex = World.Map.BlocksCount; int mapBlockHeight = MapLoader.Instance.MapBlocksSize[World.MapIndex, 1]; int index = _useLargeMap ? 1 : 0; _blankGumpsPixels[index].CopyTo(_blankGumpsPixels[index + 2], 0); uint[] data = _blankGumpsPixels[index + 2]; Point *table = stackalloc Point[2]; table[0].X = 0; table[0].Y = 0; table[1].X = 0; table[1].Y = 1; for (int i = minBlockX; i <= maxBlockX; i++) { int blockIndexOffset = i * mapBlockHeight; for (int j = minBlockY; j <= maxBlockY; j++) { int blockIndex = blockIndexOffset + j; if (blockIndex >= maxBlockIndex) { break; } ref IndexMap indexMap = ref World.Map.GetIndex(i, j); if (indexMap.MapAddress == 0) { break; } MapBlock * mp = (MapBlock *)indexMap.MapAddress; MapCells * cells = (MapCells *)&mp->Cells; StaticsBlock *sb = (StaticsBlock *)indexMap.StaticAddress; uint staticCount = indexMap.StaticCount; Chunk block = World.Map.GetChunk(blockIndex); int realBlockX = i << 3; int realBlockY = j << 3; for (int x = 0; x < 8; x++) { int px = realBlockX + x - lastX + gumpCenterX; for (int y = 0; y < 8; y++) { ref MapCells cell = ref cells[(y << 3) + x]; int color = cell.TileID; bool isLand = true; int z = cell.Z; for (int c = 0; c < staticCount; ++c) { ref StaticsBlock stblock = ref sb[c]; if (stblock.X == x && stblock.Y == y && stblock.Color > 0 && stblock.Color != 0xFFFF && GameObject.CanBeDrawn(stblock.Color)) { if (stblock.Z >= z) { color = stblock.Hue > 0 ? (ushort)(stblock.Hue + 0x4000) : stblock.Color; isLand = stblock.Hue > 0; z = stblock.Z; } } } if (block != null) { GameObject obj = block.Tiles[x, y]; while (obj?.TNext != null) { obj = obj.TNext; } for (; obj != null; obj = obj.TPrevious) { if (obj is Multi) { if (obj.Hue == 0) { color = obj.Graphic; isLand = false; } else { color = obj.Hue + 0x4000; } break; } } } if (!isLand) { color += 0x4000; } int tableSize = 2; if (isLand && color > 0x4000) { color = HuesLoader.Instance.GetColor16(16384, (ushort)(color - 0x4000)); //28672 is an arbitrary position in hues.mul, is the 14 position in the range } else { color = HuesLoader.Instance.GetRadarColorData(color); } int py = realBlockY + y - lastY; int gx = px - py; int gy = px + py; CreatePixels ( data, 0x8000 | color, gx, gy, Width, Height, table, tableSize ); } }
/// <summary> /// Initializes the control. /// </summary> protected override void Initialize() { Random rand = new Random(); spriteBatch = new SpriteBatch(base.GraphicsDevice); selectedMapCells = new MapCells(); camera = new Camera(Vector2.Zero, new Vector2(this.Width, this.Height), new Vector2(1f, 1f)); this.MouseClick +=new MouseEventHandler(MapViewer_MouseClick); Application.Idle += delegate { Invalidate(); }; }
public MapCell GetCell(System.Drawing.Point p, bool outMap = false, int width = 0, int height = 0) { var searchRect = new System.Drawing.Rectangle(p.X, p.Y, width, height); return(MapCells.FirstOrDefault(cell => cell != null && cell.IsInRectange(searchRect) && PointInPoly(p, cell.RectanglePoints))); }
private void ClearSelection() { this.selectedMapCells = new MapCells(); }
public void Initialise() { if (IsInitialised) { return; } // Get Tile Attributes from named map if we have no sheet string json = ""; if (SpriteSheetName != Name) { MapController mapController = GameObject.FindGameObjectWithTag("Globals").GetComponent <MapController>(); if (!mapController.LoadedMaps.ContainsKey(SpriteSheetName)) { mapController.LoadMap(SpriteSheetName); } TileAttributes = mapController.LoadedMaps[SpriteSheetName].TileAttributes; } else { json = "{'Items': " + MetaDataJson + "}"; MetaDataInfo metaData = JsonConvert.DeserializeObject <MetaDataInfo>(json); for (int i = 0; i < metaData.Items.Count; i++) { TileMetaData m = new TileMetaData(); foreach (MetaDataItem meta in metaData.Items[i].Data) { switch (meta.Type) { case "Solid": m.IsSolid = meta.Value == "True"; break; case "Friction": m.Friction = meta.Value; break; case "Damage": m.Damage = Convert.ToInt32(meta.Value == "" ? "0" : meta.Value); break; case "Ladder": m.IsLadder = meta.Value == "True"; break; } } TileAttributes.Add(m); } } json = "{'Layers':" + LayersJson + "}"; MapCellInfo mapCellInfo = JsonConvert.DeserializeObject <MapCellInfo>(json); Layers = new List <MapCells>(); LayerNames = new List <string>(); for (int i = 0; i < mapCellInfo.Layers.Count; i++) { MapCells layer = new MapCells(MapWidth, MapHeight); for (int y = 0; y < MapHeight; y++) { for (int x = 0; x < MapWidth; x++) { int c = y * MapWidth + x; layer.Cells[x, y] = mapCellInfo.Layers[i].Cells[c].TileID; layer.Actions[x, y] = mapCellInfo.Layers[i].Cells[c].Action; } } LayerNames.Add(mapCellInfo.Layers[i].Layer); Layers.Add(layer); } CreatePathFindingArray("Collisions"); // Create NPCs json = "{'NPC' :" + NPCJson + "}"; NPCData npcData = JsonConvert.DeserializeObject <NPCData>(json); foreach (NPCInfo npcInfo in npcData.NPC) { NPC npc = NPCController.CreateNPC(npcInfo.Name, npcInfo.ModelName, npcInfo.X, MapHeight - npcInfo.Y - 1, this); npc.CanMoveToPOI = npcInfo.POI == "True"; npc.CanWander = npcInfo.Wander == "True"; npc.InteractFunction = npcInfo.IntFunc; npc.InteractParams = npcInfo.IntParam; npc.maxSpeed = npcInfo.Speed; npc.VisibilityFunction = npcInfo.VisFunc; npc.VisibilityParams = npcInfo.VisParam; AddNPC(npc); } IsInitialised = true; }