public static CellData FromRaw(Stream s, Map map, int cellId) { var cell = new CellData(cellId); cell.Floor = s.ReadByte() * 10; if (cell.Floor == -1280) { return(cell); } if (map.Version >= 9) { var tmpbytesv9 = s.ReadShort(); cell.Mov = (tmpbytesv9 & 1) == 0; cell.NonWalkableDuringFight = (tmpbytesv9 & 2) != 0; cell.NonWalkableDuringRp = (tmpbytesv9 & 4) != 0; cell.Los = (tmpbytesv9 & 8) == 0; cell.Blue = (tmpbytesv9 & 16) != 0; cell.Red = (tmpbytesv9 & 32) != 0; cell.Visible = (tmpbytesv9 & 64) != 0; cell.FarmCell = (tmpbytesv9 & 128) != 0; if (map.Version >= 10) { cell.HavenbagCell = (tmpbytesv9 & 256) != 0; cell.TopArrow = (tmpbytesv9 & 512) != 0; cell.BottomArrow = (tmpbytesv9 & 1024) != 0; cell.RightArrow = (tmpbytesv9 & 2048) != 0; cell.LeftArrow = (tmpbytesv9 & 4096) != 0; } else { cell.TopArrow = (tmpbytesv9 & 256) != 0; cell.BottomArrow = (tmpbytesv9 & 512) != 0; cell.RightArrow = (tmpbytesv9 & 1024) != 0; cell.LeftArrow = (tmpbytesv9 & 2048) != 0; } if (cell.TopArrow) { map.TopArrowCells.Add(cell.Id); } if (cell.BottomArrow) { map.BottomArrowCells.Add(cell.Id); } if (cell.RightArrow) { map.RightArrowCells.Add(cell.Id); } if (cell.LeftArrow) { map.LeftArrowCells.Add(cell.Id); } } else { var losmov = s.ReadByte(); cell.Los = (losmov & 2) >> 1 == 1; cell.Mov = (losmov & 1) == 1; cell.Visible = (losmov & 64) >> 6 == 1; cell.FarmCell = (losmov & 32) >> 5 == 1; cell.Blue = (losmov & 16) >> 4 == 1; cell.Red = (losmov & 8) >> 3 == 1; cell.NonWalkableDuringRp = (losmov & 128) >> 7 == 1; cell.NonWalkableDuringFight = (losmov & 4) >> 2 == 1; } cell.Speed = s.ReadByte(); cell.MapChangeData = s.ReadByte(); if (map.Version > 5) { cell.MoveZone = s.ReadByte(); } if (map.Version > 10 && (cell.HasLinkedZoneRP || cell.HasLinkedZoneFight)) { cell.LinkedZone = s.ReadByte(); } if (map.Version > 7 && map.Version < 9) { var tmpBits = s.ReadByte(); cell.Arrow = 15 & tmpBits; if ((cell.Arrow & 1) != 0) { map.TopArrowCells.Add(cell.Id); } if ((cell.Arrow & 2) != 0) { map.BottomArrowCells.Add(cell.Id); } if ((cell.Arrow & 4) != 0) { map.RightArrowCells.Add(cell.Id); } if ((cell.Arrow & 8) != 0) { map.LeftArrowCells.Add(cell.Id); } } return(cell); }
private static void readMapData(Stream s, Map map) { map.RelativeId = s.ReadUInt(); map.Type = s.ReadByte(); map.SubAreaId = s.ReadInt(); map.Neighbours.Top = s.ReadUInt(); map.Neighbours.Bottom = s.ReadUInt(); map.Neighbours.Left = s.ReadUInt(); map.Neighbours.Right = s.ReadUInt(); map.ShadowBonusOnEntities = s.ReadUInt(); if (map.Version >= 9) { var readColor = s.ReadUInt(); map.BackgroundColor.Alpha = (byte)((readColor & 0b11111111_00000000_00000000_00000000) >> 32); map.BackgroundColor.Red = (byte)((readColor & 0b00000000_11111111_00000000_00000000) >> 16); map.BackgroundColor.Green = (byte)((readColor & 0b00000000_00000000_11111111_00000000) >> 8); map.BackgroundColor.Blue = (byte)((readColor & 0b00000000_00000000_00000000_11111111) >> 0); readColor = s.ReadUInt(); map.GridColor.Alpha = (byte)((readColor & 0b11111111_00000000_00000000_00000000) >> 32); map.GridColor.Red = (byte)((readColor & 0b00000000_11111111_00000000_00000000) >> 16); map.GridColor.Green = (byte)((readColor & 0b00000000_00000000_11111111_00000000) >> 8); map.GridColor.Blue = (byte)((readColor & 0b00000000_00000000_00000000_11111111) >> 0); } else if (map.Version >= 3) { map.BackgroundColor.Red = (byte)s.ReadByte(); map.BackgroundColor.Green = (byte)s.ReadByte(); map.BackgroundColor.Blue = (byte)s.ReadByte(); } if (map.Version >= 4) { map.ZoomScale = s.ReadUShort() / 100f; map.ZoomOffsetX = s.ReadShort(); map.ZoomOffsetY = s.ReadShort(); if (map.ZoomScale < 1) { map.ZoomScale = 1; map.ZoomOffsetX = 0; map.ZoomOffsetY = 0; } } if (map.Version > 10) { map.TacticalModeTemplateId = s.ReadInt(); } map.UseLowPassFilter = s.ReadByte() == 1; map.UseReverb = s.ReadByte() == 1; if (map.UseReverb) { map.PresetId = s.ReadInt(); } else { map.PresetId = -1; } var backgroundCount = s.ReadByte(); for (int i = 0; i < backgroundCount; i++) { map.BackgroundFixtures.Add(Fixture.FromRaw(s)); } var foregroundCount = s.ReadByte(); for (int i = 0; i < foregroundCount; i++) { map.ForegroundFixtures.Add(Fixture.FromRaw(s)); } s.ReadInt(); // ??? map.GroundCRC = s.ReadInt(); var layerCount = s.ReadByte(); for (int i = 0; i < layerCount; i++) { map.Layers.Add(Layer.FromRaw(s, map.Version)); } var cellCount = AtouinConstants.MapCellsCount; for (int i = 0; i < cellCount; i++) { map.Cells.Add(CellData.FromRaw(s, map, i)); } s.Close(); }