├── preview.png ├── .gitattributes ├── bin └── Release │ ├── cave.png │ ├── PNG2WAD.dll │ ├── PNG2WAD.exe │ ├── PNG2WAD.pdb │ ├── bsp-w32.exe │ ├── city_of_hell.png │ ├── wolf_prison.png │ ├── city_of_earth.png │ ├── System.Drawing.Common.dll │ ├── Microsoft.Win32.SystemEvents.dll │ ├── runtimes │ └── win │ │ └── lib │ │ └── net6.0 │ │ ├── System.Drawing.Common.dll │ │ └── Microsoft.Win32.SystemEvents.dll │ ├── PNG2WAD.runtimeconfig.json │ ├── README.txt │ └── Preferences.ini ├── .gitignore ├── src ├── Doom │ ├── ToolsOfDoom.csproj │ ├── Map │ │ ├── ThingOptions.cs │ │ ├── Vertex.cs │ │ ├── LinedefFlags.cs │ │ ├── Thing.cs │ │ ├── Sidedef.cs │ │ ├── Linedef.cs │ │ ├── Sector.cs │ │ └── DoomMap.cs │ └── Wad │ │ ├── WadLump.cs │ │ └── WadFile.cs ├── PNG2WAD.csproj ├── Generator │ ├── ThingsGeneratorFlags.cs │ ├── TileSide.cs │ ├── TileType.cs │ ├── SectorInfo.cs │ ├── ThingsGenerator.cs │ └── MapGenerator.cs ├── Config │ ├── ThemeSector.cs │ ├── ThemeTexture.cs │ ├── ThingCategory.cs │ ├── PreferencesTheme.cs │ └── Preferences.cs ├── PNGToWad.cs ├── Toolbox.cs └── INI │ └── INIFile.cs ├── PNG2WAD.sln ├── README.md └── LICENSE /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/preview.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /bin/Release/cave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/cave.png -------------------------------------------------------------------------------- /bin/Release/PNG2WAD.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/PNG2WAD.dll -------------------------------------------------------------------------------- /bin/Release/PNG2WAD.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/PNG2WAD.exe -------------------------------------------------------------------------------- /bin/Release/PNG2WAD.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/PNG2WAD.pdb -------------------------------------------------------------------------------- /bin/Release/bsp-w32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/bsp-w32.exe -------------------------------------------------------------------------------- /bin/Release/city_of_hell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/city_of_hell.png -------------------------------------------------------------------------------- /bin/Release/wolf_prison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/wolf_prison.png -------------------------------------------------------------------------------- /bin/Release/city_of_earth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/city_of_earth.png -------------------------------------------------------------------------------- /bin/Release/System.Drawing.Common.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/System.Drawing.Common.dll -------------------------------------------------------------------------------- /bin/Release/Microsoft.Win32.SystemEvents.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/Microsoft.Win32.SystemEvents.dll -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rsuser 2 | *.suo 3 | *.user 4 | *.userosscache 5 | *.sln.docstates 6 | *.wad 7 | 8 | .vs/ 9 | [Bb]in/[Dd]ebug/ 10 | [Ss]rc/[Oo]bj/ 11 | -------------------------------------------------------------------------------- /bin/Release/runtimes/win/lib/net6.0/System.Drawing.Common.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/runtimes/win/lib/net6.0/System.Drawing.Common.dll -------------------------------------------------------------------------------- /bin/Release/runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akaAgar/png2wad/HEAD/bin/Release/runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll -------------------------------------------------------------------------------- /bin/Release/PNG2WAD.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "net6.0", 4 | "framework": { 5 | "name": "Microsoft.NETCore.App", 6 | "version": "6.0.0" 7 | }, 8 | "configProperties": { 9 | "System.Reflection.Metadata.MetadataUpdater.IsSupported": false 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Doom/ToolsOfDoom.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | ToolsOfDoom 6 | 7 | 8 | 9 | false 10 | false 11 | ..\..\bin\$(Configuration) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/PNG2WAD.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | PNG2WAD 7 | 8 | 9 | 10 | false 11 | false 12 | ..\bin\$(Configuration) 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /PNG2WAD.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30225.117 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PNG2WAD", "src\PNG2WAD.csproj", "{3CC84FFB-D6BA-4583-A8BF-3B10BA6AE804}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3CC84FFB-D6BA-4583-A8BF-3B10BA6AE804}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3CC84FFB-D6BA-4583-A8BF-3B10BA6AE804}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3CC84FFB-D6BA-4583-A8BF-3B10BA6AE804}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3CC84FFB-D6BA-4583-A8BF-3B10BA6AE804}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {0A199FBF-CC23-4F65-857C-487745F75ED9} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /src/Generator/ThingsGeneratorFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using System; 22 | 23 | namespace PNG2WAD.Generator 24 | { 25 | /// 26 | /// Enumerate flags for thing generation. 27 | /// 28 | [Flags] 29 | public enum ThingsGeneratorFlags 30 | { 31 | /// 32 | /// More things in easy modes (e.g. health pickups) 33 | /// 34 | MoreThingsInEasyMode = 1, 35 | /// 36 | /// More things in hard mode (e.g. monsters) 37 | /// 38 | MoreThingsInHardMode = 2 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Generator/TileSide.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | namespace PNG2WAD.Generator 22 | { 23 | /// 24 | /// Four sides of a tile. Used for linedef generation. 25 | /// 26 | public enum TileSide 27 | { 28 | /// 29 | /// North. 30 | /// 31 | North, 32 | /// 33 | /// East. 34 | /// 35 | East, 36 | /// 37 | /// South. 38 | /// 39 | South, 40 | /// 41 | /// West. 42 | /// 43 | West 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Config/ThemeSector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | namespace PNG2WAD.Config 22 | { 23 | /// 24 | /// Enumerates the various sector types in a theme. 25 | /// 26 | public enum ThemeSector 27 | { 28 | /// 29 | /// Default sector. 30 | /// 31 | Default, 32 | /// 33 | /// Door side. 34 | /// 35 | DoorSide, 36 | /// 37 | /// Entrance. 38 | /// 39 | Entrance, 40 | /// 41 | /// Exit. 42 | /// 43 | Exit, 44 | /// 45 | /// Exterior. 46 | /// 47 | Exterior, 48 | /// 49 | /// Special ceiling. 50 | /// 51 | SpecialCeiling, 52 | /// 53 | /// Special floor. 54 | /// 55 | SpecialFloor 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Doom/Map/ThingOptions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | 22 | using System; 23 | 24 | namespace PNG2WAD.Doom.Map 25 | { 26 | /// 27 | /// Bit flags for a Doom map thing 28 | /// 29 | [Flags] 30 | public enum ThingOptions 31 | { 32 | /// 33 | /// Thing is present in skill levels 1 & 2. 34 | /// 35 | Skill12 = 1, 36 | 37 | /// 38 | /// Thing is present in skill level 3. 39 | /// 40 | Skill3 = 2, 41 | 42 | /// 43 | /// Thing is present in skill levels 4 & 5. 44 | /// 45 | Skill45 = 4, 46 | 47 | /// 48 | /// Monster is deaf. 49 | /// 50 | Deaf = 8, 51 | 52 | /// 53 | /// Thing is only present in multiplayer. 54 | /// 55 | MultiplayerOnly = 16, 56 | 57 | /// 58 | /// Shortcut: this is present in all skill levels. 59 | /// (AllSkills = Skill12 | Skill3 | Skill45) 60 | /// 61 | AllSkills = Skill12 | Skill3 | Skill45 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Generator/TileType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | namespace PNG2WAD.Generator 22 | { 23 | /// 24 | /// Type of tile. 25 | /// 26 | public enum TileType 27 | { 28 | /// 29 | /// Wall. 30 | /// 31 | Wall, 32 | /// 33 | /// Default room. 34 | /// 35 | Room, 36 | /// 37 | /// Exterior room. 38 | /// 39 | RoomExterior, 40 | /// 41 | /// Room with special ceiling. 42 | /// 43 | RoomSpecialCeiling, 44 | /// 45 | /// Room with special floor. 46 | /// 47 | RoomSpecialFloor, 48 | /// 49 | /// Door. 50 | /// 51 | Door, 52 | /// 53 | /// Door side. 54 | /// 55 | DoorSide, 56 | /// 57 | /// Secret passage. 58 | /// 59 | Secret, 60 | /// 61 | /// Entrance. 62 | /// 63 | Entrance, 64 | /// 65 | /// Exit. 66 | /// 67 | Exit 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Doom/Map/Vertex.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Drawing; 24 | 25 | namespace PNG2WAD.Doom.Map 26 | { 27 | /// 28 | /// A Doom map vertex. 29 | /// 30 | public readonly struct Vertex 31 | { 32 | /// 33 | /// X-coordinate of this vertex. 34 | /// 35 | public int X { get; } 36 | 37 | /// 38 | /// Y-coordinate of this vertex. 39 | /// 40 | public int Y { get; } 41 | 42 | /// 43 | /// Constructor. 44 | /// 45 | /// Coordinates of the vertex. 46 | public Vertex(Point pt) 47 | { 48 | X = pt.X; 49 | Y = pt.Y; 50 | } 51 | 52 | /// 53 | /// Gets an array of bytes descripting this vertex to add to the VERTEXES (sic) lump. 54 | /// 55 | /// An array of bytes 56 | public byte[] ToBytes() 57 | { 58 | List bytes = new(); 59 | bytes.AddRange(BitConverter.GetBytes((short)X)); 60 | bytes.AddRange(BitConverter.GetBytes((short)Y)); 61 | return bytes.ToArray(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Config/ThemeTexture.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | namespace PNG2WAD.Config 22 | { 23 | /// 24 | /// Enumerates the textures used by a theme. 25 | /// 26 | public enum ThemeTexture 27 | { 28 | /// 29 | /// Default ceiling. 30 | /// 31 | Ceiling, 32 | /// 33 | /// Special ceiling. 34 | /// 35 | CeilingSpecial, 36 | /// 37 | /// Door. 38 | /// 39 | Door, 40 | /// 41 | /// Door side. 42 | /// 43 | DoorSide, 44 | /// 45 | /// Default floor. 46 | /// 47 | Floor, 48 | /// 49 | /// Floor on the entrance tile. 50 | /// 51 | FloorEntrance, 52 | /// 53 | /// Floor on the exit tile. 54 | /// 55 | FloorExit, 56 | /// 57 | /// Floor in exterior tiles. 58 | /// 59 | FloorExterior, 60 | /// 61 | /// Special floor. 62 | /// 63 | FloorSpecial, 64 | /// 65 | /// Wall. 66 | /// 67 | Wall, 68 | /// 69 | /// Wall for exterior sectors. 70 | /// 71 | WallExterior 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Doom/Map/LinedefFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | 22 | using System; 23 | 24 | namespace PNG2WAD.Doom.Map 25 | { 26 | /// 27 | /// Special flags for a Doom map linedef. 28 | /// 29 | [Flags] 30 | public enum LinedefFlags 31 | { 32 | /// 33 | /// Cannot be crossed. 34 | /// 35 | Impassible = 1, 36 | /// 37 | /// Blocks monsters. 38 | /// 39 | BlocksMonsters = 2, 40 | /// 41 | /// Has two sides. 42 | /// 43 | TwoSided = 4, 44 | /// 45 | /// Draw lower texture from the bottom. 46 | /// 47 | UpperUnpegged = 8, 48 | /// 49 | /// Draw upper texture from the top. 50 | /// 51 | LowerUnpegged = 16, 52 | /// 53 | /// Show as a wall on the automap, used to hide secret passages. 54 | /// 55 | Secret = 32, 56 | /// 57 | /// Sound can only cross one linedef with this flag (not two). 58 | /// 59 | BlocksSound = 64, 60 | /// 61 | /// Does not appear on the automap. 62 | /// 63 | NotOnMap = 128, 64 | /// 65 | /// Drawn on the automap at the beginning of the level. 66 | /// 67 | AlreadyOnMap = 126 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Doom/Wad/WadLump.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of Tools of Doom, a library providing a collection of 4 | classes to load/edit/save Doom maps and wad archives, created by @akaAgar 5 | (https://github.com/akaAgar/tools-of-doom). 6 | 7 | Tools of Doom is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Tools of Doom is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Tools of Doom. If not, see https://www.gnu.org/licenses/ 19 | ========================================================================== 20 | */ 21 | 22 | using System; 23 | using System.Text.RegularExpressions; 24 | 25 | namespace PNG2WAD.Doom.Wad 26 | { 27 | /// 28 | /// A lump in a Doom wad file. 29 | /// 30 | public struct WadLump 31 | { 32 | /// 33 | /// Regex pattern used to remove invalid characters from the lump name. 34 | /// 35 | private const string LUMP_REGEX_PATTERN = "[^A-Z0-9_]"; 36 | 37 | /// 38 | /// Lump name. 39 | /// 40 | public string Name { get; } 41 | 42 | /// 43 | /// Lump content, as an array of bytes. 44 | /// 45 | public byte[] Bytes { get; } 46 | 47 | /// 48 | /// Constructor. 49 | /// 50 | /// The name of the lump. 51 | /// The content of the lump, as an array of bytes. 52 | public WadLump(string name, byte[] bytes) 53 | { 54 | Bytes = bytes ?? Array.Empty(); // Make sure bytes is not null 55 | if (string.IsNullOrEmpty(name)) name = "NULL"; 56 | Name = Regex.Replace(name.ToUpperInvariant(), LUMP_REGEX_PATTERN, ""); 57 | if (Name.Length > WadFile.MAX_LUMP_NAME_LENGTH) 58 | Name = Name[..WadFile.MAX_LUMP_NAME_LENGTH]; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Config/ThingCategory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | namespace PNG2WAD.Config 22 | { 23 | /// 24 | /// A category of thing for the thing generator. 25 | /// 26 | public enum ThingCategory 27 | { 28 | /// 29 | /// Large ammo pickup (box of bullets, box of shells...) 30 | /// 31 | AmmoLarge, 32 | /// 33 | /// Small ammo pickup (clip, shells...) 34 | /// 35 | AmmoSmall, 36 | /// 37 | /// Armor pickup 38 | /// 39 | Armor, 40 | /// 41 | /// Health pickup 42 | /// 43 | Health, 44 | /// 45 | /// Easy monsters 46 | /// 47 | MonstersEasy, 48 | /// 49 | /// Average difficulty monsters 50 | /// 51 | MonstersAverage, 52 | /// 53 | /// Hard monsters 54 | /// 55 | MonstersHard, 56 | /// 57 | /// Very hard monsters 58 | /// 59 | MonstersVeryHard, 60 | /// 61 | /// Power-ups (invisibility, invulnerability...) 62 | /// 63 | PowerUps, 64 | /// 65 | /// Powerful weapons 66 | /// 67 | WeaponsHigh, 68 | /// 69 | /// Weak weapons 70 | /// 71 | WeaponsLow, 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /bin/Release/README.txt: -------------------------------------------------------------------------------- 1 | ================== 2 | PNG2WAD 3 | ================== 4 | 5 | An open source command line tool to turn PNG images into Doom maps. 6 | Created by Ambroise Garel (www.cafedefaune.net) 7 | 8 | Project page: akaagar.itch.io/png2wad 9 | Source code: github.com/akaAgar/png2wad 10 | 11 | -------- 12 | FEATURES 13 | -------- 14 | 15 | - Any bitmap size 16 | - Supports doors, secret passages, special sectors, entrances, exits, variable floor/ceiling heights 17 | - Theme configuration to create maps with various feelings and textures (hell, tech base, sewers...) 18 | - Can generate maps in the Doom 1 (ExMx) or Doom 2 (MAPxx) name format 19 | - Optional things generation to create immediately playable maps filled with monsters and items. Or you can disable the thing generator and populate the map yourself using a map editor such as [DoomBuilder](http://www.doombuilder.com/) 20 | - Includes [Bsp](http://games.moria.org.uk/doom/bsp/) for node generation on Windows. On macOS/Linux you'll have to build nodes manually using a third-party node builder before you can play your maps 21 | 22 | ----- 23 | USAGE 24 | ----- 25 | 26 | Using the command-line 27 | ---------------------- 28 | Syntax is: **PNG2WAD.exe SomeImage.png \[SomeOtherImage.png\] \[YetAnotherImage.png\]...** 29 | 30 | From the GUI 31 | ------------ 32 | Drag and drop one or more PNG files on **PNG2WAD.exe** 33 | 34 | Output 35 | ------ 36 | Output file will always be generated in the directory where PNG2WAD.exe is located and will have a the name of the first PNG file with a wad extension. For instance, if you create a file from SomePlace.png, SomeOtherPlace.png and AThirdPlace.png, the output file will be named SomePlace.wad. 37 | 38 | If Doom 1 format has been selected in Preferences.ini, first map will be named ExM1, then ExM2, etc (Where x is the number of the episode as defined in Preferences.ini). Maps beyond ExM9 will be ignored. 39 | 40 | If Doom 2 format has been selected in Preferences.ini, first map will be named MAP01, then MAP02, MAP03, etc. Maps beyond MAP99 will be ignored. 41 | 42 | Default format is **Doom 2**. 43 | 44 | --------------- 45 | CREATING IMAGES 46 | --------------- 47 | 48 | Run your favorite image edition tool and create a new PNG of any size. Each pixel is a 64x64 tile on the map. 49 | 50 | Theme 51 | ----- 52 | 53 | The upper-left pixel is always a wall. Its color is ignored and used to select the map theme, as defined in the Preferences.ini file. You can add more themes by editing the file. 54 | 55 | Available themes are: 56 | 57 | - Gray (128, 128, 128): cave 58 | - Red (255, 0, 0): hell 59 | - Steel blue (128, 128, 255) : city 60 | - Any other color: tech base (default) 61 | 62 | Image pixels 63 | ------------ 64 | 65 | White (255, 255, 255): Wall 66 | Red (255, 0, 0): Room with special floor (nukage, lava, etc.) as defined in the map theme 67 | Green (0, 128, 0): Room with special ceiling (lamp, etc.) as defined in the map theme 68 | Blue (0, 0, 255): Room with open sky (exterior) 69 | Olive (128, 128, 0): Door 70 | Magenta (255, 0, 255): Secret passage 71 | Yellow (255, 255, 0): Entrance/player start 72 | Lime (0, 255, 0): Exit 73 | Any other color: Room 74 | -------------------------------------------------------------------------------- /src/Doom/Map/Thing.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | namespace PNG2WAD.Doom.Map 25 | { 26 | /// 27 | /// A Doom map thing. 28 | /// 29 | public readonly struct Thing 30 | { 31 | /// 32 | /// X-coordinate of this thing. 33 | /// 34 | public int X { get; } 35 | 36 | /// 37 | /// Y-coordinate of this thing. 38 | /// 39 | public int Y { get; } 40 | 41 | /// 42 | /// Direction this thing is facing (east is 0, north is 90, west is 180, south is 270) 43 | /// 44 | public int Angle { get; } 45 | 46 | /// 47 | /// Type of thing. 48 | /// 49 | public int Type { get; } 50 | 51 | /// 52 | /// Thing options. 53 | /// 54 | public ThingOptions Options { get; } 55 | 56 | /// 57 | /// Constructor. 58 | /// 59 | /// X-coordinate of this thing 60 | /// Y-coordinate of this thing 61 | /// Type of thing 62 | /// Direction this thing is facing (east is 0, north is 90, west is 180, south is 270) 63 | /// Thing options 64 | public Thing(int x, int y, int type, int angle = 0, ThingOptions options = ThingOptions.AllSkills) 65 | { 66 | X = x; 67 | Y = y; 68 | Angle = angle; 69 | Type = type; 70 | Options = options; 71 | } 72 | 73 | /// 74 | /// Gets an array of bytes descripting this thing to add to the THINGS lump. 75 | /// 76 | /// An array of bytes 77 | public byte[] ToBytes() 78 | { 79 | List bytes = new(); 80 | bytes.AddRange(BitConverter.GetBytes((short)X)); 81 | bytes.AddRange(BitConverter.GetBytes((short)Y)); 82 | bytes.AddRange(BitConverter.GetBytes((short)Angle)); 83 | bytes.AddRange(BitConverter.GetBytes((short)Type)); 84 | bytes.AddRange(BitConverter.GetBytes((short)Options)); 85 | return bytes.ToArray(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PNG2WAD 2 | 3 | A C# (.Net/Mono) command-line tool to turn PNG images into Doom maps. 4 | 5 | Not interested in the source code and just want to have fun? You'll find binaries on Itch.io : [akaagar.itch.io/png2wad](https://akaagar.itch.io/png2wad) 6 | 7 | 8 | 9 | ![Preview images](preview.png) 10 | 11 | 12 | ## Features 13 | - Any bitmap size 14 | - Supports doors, secret passages, special sectors, entrances, exits, variable floor/ceiling heights 15 | - Theme configuration to create maps with various feelings and textures (hell, tech base, sewers...) 16 | - Can generate maps in the Doom 1 (ExMx) or Doom 2 (MAPxx) name format 17 | - Optional things generation to create immediately playable maps filled with monsters and items. Or you can disable the thing generator and populate the map yourself using a map editor such as [DoomBuilder](http://www.doombuilder.com/) 18 | - Includes [Bsp](http://games.moria.org.uk/doom/bsp/) for node generation on Windows. On macOS/Linux you'll have to build nodes manually using a third-party node builder before you can play your maps 19 | 20 | 21 | 22 | ## Usage 23 | 24 | ### Using the command-line 25 | Syntax is: **PNG2WAD.exe SomeImage.png \[SomeOtherImage.png\] \[YetAnotherImage.png\]...** 26 | 27 | ### From the GUI 28 | Drag and drop one or more PNG files on **PNG2WAD.exe** 29 | 30 | ### Output 31 | 32 | Output file will always be generated in the directory where PNG2WAD.exe is located and will have a the name of the first PNG file with a wad extension. For instance, if you create a file from SomePlace.png, SomeOtherPlace.png and AThirdPlace.png, the output file will be named SomePlace.wad. 33 | 34 | If Doom 1 format has been selected in Preferences.ini, first map will be named ExM1, then ExM2, etc (Where x is the number of the episode as defined in Preferences.ini). Maps beyond ExM9 will be ignored. 35 | 36 | If Doom 2 format has been selected in Preferences.ini, first map will be named MAP01, then MAP02, MAP03, etc. Maps beyond MAP99 will be ignored. 37 | 38 | Default format is **Doom 2**. 39 | 40 | ## Creating images 41 | 42 | Run your favorite image edition tool and create a new PNG of any size. Each pixel is a 64x64 tile on the map. 43 | 44 | ### Theme 45 | The upper-left pixel is always a wall. Its color is ignored and used to select the map theme, as defined in the Preferences.ini file. You can add more themes by editing the file. 46 | 47 | Available themes are: 48 | 49 | - Gray (128, 128, 128): cave 50 | - Red (255, 0, 0): hell 51 | - Steel blue (128, 128, 255) : city 52 | - Any other color: tech base (default) 53 | 54 | ### Image pixels 55 | | Pixel color | Tile type | 56 | | --------------------- | ------------------------------------------------------------ | 57 | | White (255, 255, 255) | Wall | 58 | | Red (255, 0, 0) | Room with special floor (nukage, lava, etc.) as defined in the map theme | 59 | | Green (0, 128, 0) | Room with special ceiling (lamp, etc.) as defined in the map theme | 60 | | Blue (0, 0, 255) | Room with open sky (exterior) | 61 | | Olive (128, 128, 0) | Door | 62 | | Magenta (255, 0, 255) | Secret passage | 63 | | Yellow (255, 255, 0) | Entrance/player start | 64 | | Lime (0, 255, 0) | Exit | 65 | | Any other color | Room | 66 | 67 | 68 | ## Change history 69 | 70 | **11 July, 2023** 71 | * Updated target framework from .Net Framework 4.5 to .Net 6.0 72 | * Removed dependencies to INIPlusPlus.dll and ToolsOfDoom.dll 73 | -------------------------------------------------------------------------------- /src/Doom/Map/Sidedef.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.Doom.Wad; 22 | using System; 23 | using System.Collections.Generic; 24 | 25 | namespace PNG2WAD.Doom.Map 26 | { 27 | /// 28 | /// A Doom map sidedef. 29 | /// 30 | public readonly struct Sidedef 31 | { 32 | /// 33 | /// Texture X-offset. 34 | /// 35 | public int XOffset { get; } 36 | 37 | /// 38 | /// Texture Y-offset. 39 | /// 40 | public int YOffset { get; } 41 | 42 | /// 43 | /// Upper (above neighboring sector) texture. 44 | /// 45 | public string UpperTexture { get; } 46 | 47 | /// 48 | /// Lower (below neighboring sector) texture. 49 | /// 50 | public string LowerTexture { get; } 51 | 52 | /// 53 | /// Middle (over neighboring sector, or wall) texture. 54 | /// 55 | public string MiddleTexture { get; } 56 | 57 | /// 58 | /// Sector this sidedef faces. 59 | /// 60 | public int Sector { get; } 61 | 62 | /// 63 | /// Constructor. 64 | /// 65 | /// Texture X-offset 66 | /// Texture Y-offset 67 | /// Upper (above neighboring sector) texture 68 | /// Lower (below neighboring sector) texture 69 | /// Middle (over neighboring sector, or wall) texture 70 | /// Sector this sidedef faces 71 | public Sidedef(int xOffset, int yOffset, string upperTexture, string lowerTexture, string middleTexture, int sector) 72 | { 73 | XOffset = xOffset; 74 | YOffset = yOffset; 75 | UpperTexture = upperTexture; 76 | LowerTexture = lowerTexture; 77 | MiddleTexture = middleTexture; 78 | Sector = sector; 79 | } 80 | 81 | /// 82 | /// Gets an array of bytes descripting this sidedef to add to the SIDEDEFS lump. 83 | /// 84 | /// An array of bytes 85 | public byte[] ToBytes() 86 | { 87 | List bytes = new(); 88 | bytes.AddRange(BitConverter.GetBytes((short)XOffset)); 89 | bytes.AddRange(BitConverter.GetBytes((short)YOffset)); 90 | bytes.AddRange(WadFile.GetBytesFromString(UpperTexture)); 91 | bytes.AddRange(WadFile.GetBytesFromString(LowerTexture)); 92 | bytes.AddRange(WadFile.GetBytesFromString(MiddleTexture)); 93 | bytes.AddRange(BitConverter.GetBytes((short)Sector)); 94 | return bytes.ToArray(); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Config/PreferencesTheme.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.INI; 22 | using System; 23 | 24 | namespace PNG2WAD.Config 25 | { 26 | /// 27 | /// Stores information for a theme in the preferences 28 | /// 29 | public readonly struct PreferencesTheme 30 | { 31 | /// 32 | /// Total number of values in the ThemeSector enum. 33 | /// 34 | public static readonly int THEME_SECTORS_COUNT = Enum.GetValues(typeof(ThemeSector)).Length; 35 | 36 | /// 37 | /// Total number of values in the ThemeTexture enum. 38 | /// 39 | public static readonly int THEME_TEXTURES_COUNT = Enum.GetValues(typeof(ThemeTexture)).Length; 40 | 41 | /// 42 | /// Floor/Ceiling heights. Two int32s (floor, ceiling) per ThemeSector. 43 | /// 44 | public int[][] Height { get; } 45 | 46 | /// 47 | /// Light levels. One int32 per ThemeSector. 48 | /// 49 | public int[] LightLevel { get; } 50 | 51 | /// 52 | /// Sector special types. One int32 per ThemeSector. 53 | /// 54 | public int[] SectorSpecial { get; } 55 | 56 | /// 57 | /// Textures. A string array per ThemeTexture. 58 | /// 59 | public string[][] Textures { get; } 60 | 61 | /// 62 | /// Constructor. 63 | /// 64 | /// Ini file to load from 65 | /// Theme section in the ini file 66 | public PreferencesTheme(INIFile ini, string section) 67 | { 68 | int i; 69 | 70 | Height = new int[THEME_SECTORS_COUNT][]; 71 | LightLevel = new int[THEME_SECTORS_COUNT]; 72 | SectorSpecial = new int[THEME_SECTORS_COUNT]; 73 | 74 | for (i = 0; i < THEME_SECTORS_COUNT; i++) 75 | { 76 | Height[i] = ini.GetValueArray(section, $"Height.{(ThemeSector)i}"); 77 | if (Height[i].Length == 0) Height[i] = new int[] { 0, 64 }; 78 | else if (Height[i].Length == 1) Height[i] = new int[] { 0, Height[i][1] }; 79 | Height[i] = new int[] { Math.Min(Height[i][0], Height[i][1]), Math.Max(Height[i][0], Height[i][1]) }; 80 | 81 | LightLevel[i] = ini.GetValue(section, $"LightLevel.{(ThemeSector)i}", -1); 82 | LightLevel[i] = Toolbox.Clamp(LightLevel[i], 0, 255); 83 | 84 | SectorSpecial[i] = ini.GetValue(section, $"SectorSpecial.{(ThemeSector)i}", 0); 85 | SectorSpecial[i] = Math.Max(0, SectorSpecial[i]); 86 | } 87 | 88 | Textures = new string[THEME_TEXTURES_COUNT][]; 89 | for (i = 0; i < THEME_TEXTURES_COUNT; i++) 90 | Textures[i] = ini.GetValueArray(section, $"Textures.{(ThemeTexture)i}"); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Doom/Map/Linedef.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | namespace PNG2WAD.Doom.Map 25 | { 26 | /// 27 | /// A Doom map linedef. 28 | /// 29 | public readonly struct Linedef 30 | { 31 | /// 32 | /// Index of this linedef's first vertex. 33 | /// 34 | public int Vertex1 { get; } 35 | 36 | /// 37 | /// Index of this linedef's second vertex. 38 | /// 39 | public int Vertex2 { get; } 40 | 41 | /// 42 | /// Linedef flags. 43 | /// 44 | public LinedefFlags Flags { get; } 45 | 46 | /// 47 | /// Linedef special type. 48 | /// 49 | public int Type { get; } 50 | 51 | /// 52 | /// Linedef action tag. 53 | /// 54 | public int Tag { get; } 55 | 56 | /// 57 | /// Index of this sidedef's right sidedef. 58 | /// 59 | public int SidedefRight { get; } 60 | 61 | /// 62 | /// Index of this sidedef's left sidedef. 63 | /// 64 | public int SidedefLeft { get; } 65 | 66 | /// 67 | /// Constructor. 68 | /// 69 | /// Index of this linedef's first vertex 70 | /// Index of this linedef's second vertex 71 | /// Linedef flags 72 | /// Linedef special type 73 | /// Linedef action tag 74 | /// Index of this sidedef's right sidedef 75 | /// Index of this sidedef's left sidedef 76 | public Linedef(int vertex1, int vertex2, LinedefFlags flags, int type, int tag, int sidedefLeft, int sidedefRight) 77 | { 78 | Vertex1 = vertex1; 79 | Vertex2 = vertex2; 80 | Flags = flags; 81 | Type = type; 82 | Tag = tag; 83 | SidedefRight = sidedefRight; 84 | SidedefLeft = sidedefLeft; 85 | } 86 | 87 | /// 88 | /// Gets an array of bytes descripting this linedef to add to the LINEDEFS lump. 89 | /// 90 | /// An array of bytes 91 | public byte[] ToBytes() 92 | { 93 | List bytes = new(); 94 | bytes.AddRange(BitConverter.GetBytes((short)Vertex1)); 95 | bytes.AddRange(BitConverter.GetBytes((short)Vertex2)); 96 | bytes.AddRange(BitConverter.GetBytes((short)Flags)); 97 | bytes.AddRange(BitConverter.GetBytes((short)Type)); 98 | bytes.AddRange(BitConverter.GetBytes((short)Tag)); 99 | bytes.AddRange(BitConverter.GetBytes((short)SidedefRight)); 100 | bytes.AddRange(BitConverter.GetBytes((short)SidedefLeft)); 101 | return bytes.ToArray(); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Doom/Map/Sector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.Doom.Wad; 22 | using System; 23 | using System.Collections.Generic; 24 | 25 | namespace PNG2WAD.Doom.Map 26 | { 27 | /// 28 | /// A Doom map sector. 29 | /// 30 | public readonly struct Sector 31 | { 32 | /// 33 | /// Height of this sector's floor. 34 | /// 35 | public int FloorHeight { get; } 36 | 37 | /// 38 | /// Height of this sector's ceiling. 39 | /// 40 | public int CeilingHeight { get; } 41 | 42 | /// 43 | /// Texture drawn on this sector's floor. 44 | /// 45 | public string FloorTexture { get; } 46 | 47 | /// 48 | /// Texture drawn on this sector's ceiling. 49 | /// 50 | public string CeilingTexture { get; } 51 | 52 | /// 53 | /// Light level in this sector (0-255). 54 | /// 55 | public int LightLevel { get; } 56 | 57 | /// 58 | /// Sector special type. 59 | /// 60 | public int Special { get; } 61 | 62 | /// 63 | /// Sector special tag. 64 | /// 65 | public int Tag { get; } 66 | 67 | /// 68 | /// Constructor. 69 | /// 70 | /// 71 | /// 72 | /// 73 | /// 74 | /// 75 | /// 76 | /// 77 | public Sector(int floorHeight, int ceilingHeight, string floorTexture, string ceilingTexture, int lightLevel, int special = 0, int tag = 0) 78 | { 79 | FloorHeight = Math.Max(-32768, Math.Min(32767, floorHeight)); 80 | CeilingHeight = Math.Max(FloorHeight, Math.Min(32767, ceilingHeight)); 81 | FloorTexture = floorTexture; 82 | CeilingTexture = ceilingTexture; 83 | LightLevel = Math.Max(0, Math.Min(255, lightLevel)); 84 | Special = Math.Max(0, Math.Min(32767, special)); 85 | Tag = Math.Max(0, Math.Min(32767, tag)); 86 | } 87 | 88 | /// 89 | /// Gets an array of bytes descripting this sector to add to the SECTORS lump. 90 | /// 91 | /// An array of bytes 92 | public byte[] ToBytes() 93 | { 94 | List bytes = new(); 95 | bytes.AddRange(BitConverter.GetBytes((short)FloorHeight)); 96 | bytes.AddRange(BitConverter.GetBytes((short)CeilingHeight)); 97 | bytes.AddRange(WadFile.GetBytesFromString(FloorTexture)); 98 | bytes.AddRange(WadFile.GetBytesFromString(CeilingTexture)); 99 | bytes.AddRange(BitConverter.GetBytes((short)LightLevel)); 100 | bytes.AddRange(BitConverter.GetBytes((short)Special)); 101 | bytes.AddRange(BitConverter.GetBytes((short)Tag)); 102 | return bytes.ToArray(); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Doom/Map/DoomMap.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | 22 | 23 | using PNG2WAD.Doom.Wad; 24 | using System; 25 | using System.Collections.Generic; 26 | using System.Drawing; 27 | using System.Linq; 28 | 29 | namespace PNG2WAD.Doom.Map 30 | { 31 | /// 32 | /// A Doom map. 33 | /// 34 | public sealed class DoomMap : IDisposable 35 | { 36 | /// 37 | /// Name of the map in the wad file (E1M1, MAP01, etc.) 38 | /// 39 | public string Name { get; } 40 | 41 | /// 42 | /// Map linedefs. 43 | /// 44 | public List Linedefs { get; } = new List(); 45 | 46 | /// 47 | /// Map sectors. 48 | /// 49 | public List Sectors { get; } = new List(); 50 | 51 | /// 52 | /// Map sidedefs. 53 | /// 54 | public List Sidedefs { get; } = new List(); 55 | 56 | /// 57 | /// Map things. 58 | /// 59 | public List Things { get; } = new List(); 60 | 61 | /// 62 | /// Map vertices. 63 | /// 64 | public List Vertices { get; } = new List(); 65 | 66 | /// 67 | /// Constructor. Creates a new, empty map. 68 | /// 69 | /// Name of the map in the wad file (E1M1, MAP01...) 70 | public DoomMap(string name) 71 | { 72 | Name = name; 73 | } 74 | 75 | /// 76 | /// Adds the map lumps to a Doom wad file. 77 | /// 78 | /// The wad file to which the map should be added 79 | public void AddToWad(WadFile wad) 80 | { 81 | wad.AddLump(Name, Array.Empty()); 82 | wad.AddLump("LINEDEFS", Linedefs.SelectMany(x => x.ToBytes()).ToArray()); 83 | wad.AddLump("SECTORS", Sectors.SelectMany(x => x.ToBytes()).ToArray()); 84 | wad.AddLump("SIDEDEFS", Sidedefs.SelectMany(x => x.ToBytes()).ToArray()); 85 | wad.AddLump("THINGS", Things.SelectMany(x => x.ToBytes()).ToArray()); 86 | wad.AddLump("VERTEXES", Vertices.SelectMany(x => x.ToBytes()).ToArray()); 87 | } 88 | 89 | /// 90 | /// Adds a new vertex to the map if no vertex with these coordinates exist, or return the index of the vertex with these coordinates. 91 | /// 92 | /// Coordinates of the vertex 93 | /// Index of the vertex with these coordinates 94 | public int AddVertex(Point coordinates) 95 | { 96 | for (int i = 0; i < Vertices.Count; i++) 97 | if ((Vertices[i].X == coordinates.X) && (Vertices[i].Y == coordinates.Y)) 98 | return i; 99 | 100 | Vertices.Add(new Vertex(coordinates)); 101 | return Vertices.Count - 1; 102 | } 103 | 104 | /// 105 | /// Returns the coordinates the the edges of the map. 106 | /// 107 | /// Minimum X coordinate of any vertex 108 | /// Minimum Y coordinate of any vertex 109 | /// Maximum X coordinate of any vertex 110 | /// Maximum Y coordinate of any vertex 111 | public void GetMapBoundaries(out int minX, out int minY, out int maxX, out int maxY) 112 | { 113 | minX = 0; minY = 0; maxX = 0; maxY = 0; 114 | if (Vertices.Count == 0) return; 115 | 116 | minX = Vertices[0].X; maxX = Vertices[0].X; 117 | minY = Vertices[0].Y; maxY = Vertices[0].Y; 118 | 119 | foreach (Vertex v in Vertices) 120 | { 121 | if (v.X < minX) minX = v.X; 122 | if (v.X > maxX) maxX = v.X; 123 | if (v.Y < minY) minY = v.Y; 124 | if (v.Y > maxY) maxY = v.Y; 125 | } 126 | } 127 | 128 | /// 129 | /// IDisposable implementation. 130 | /// 131 | public void Dispose() { } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/PNGToWad.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.Config; 22 | using PNG2WAD.Generator; 23 | using PNG2WAD.Doom.Map; 24 | using PNG2WAD.Doom.Wad; 25 | using System; 26 | using System.Diagnostics; 27 | using System.Drawing; 28 | using System.IO; 29 | using System.Linq; 30 | 31 | namespace PNG2WAD 32 | { 33 | /// 34 | /// Main program. Parses command-line arguments and creates an instance of the generator. 35 | /// 36 | public sealed class PNGToWad : IDisposable 37 | { 38 | /// 39 | /// Static Main() method. Program entry point. 40 | /// 41 | /// Command line parameters 42 | private static void Main(string[] args) 43 | { 44 | #if DEBUG 45 | if (args.Length == 0) 46 | args = new string[] 47 | { 48 | @"..\Release\wolf_prison.png", 49 | @"..\Release\cave.png", 50 | @"..\Release\city_of_earth.png", 51 | @"..\Release\city_of_hell.png" 52 | }; 53 | #endif 54 | 55 | using PNGToWad db = new(args); 56 | } 57 | 58 | /// 59 | /// Constructor. 60 | /// 61 | /// Command line parameters 62 | public PNGToWad(params string[] args) 63 | { 64 | string[] mapBitmapFiles = (from string file in args where File.Exists(file) && Path.GetExtension(file).ToLowerInvariant() == ".png" select file).ToArray(); 65 | 66 | if (mapBitmapFiles.Length == 0) 67 | { 68 | Console.WriteLine("Missing parameters or no valid PNG file in the parameters."); 69 | Console.WriteLine("Syntax is: PixelsOfDoom.exe SomeImage.png [SomeOtherImage.png] [YetAnotherImage.png]..."); 70 | Console.ReadKey(); 71 | return; 72 | } 73 | 74 | string wadFile = Path.GetFileNameWithoutExtension(mapBitmapFiles[0]) + ".wad"; // Output file is the name of the first file with a WAD extension. 75 | 76 | #if DEBUG 77 | Preferences config = new(@"..\Release\Preferences.ini"); 78 | #else 79 | Preferences config = new("Preferences.ini"); 80 | #endif 81 | MapGenerator generator = new(config); 82 | WadFile wad = new(); 83 | 84 | for (int i = 0; i < mapBitmapFiles.Length; i++) 85 | { 86 | int mapNumber = i + 1; 87 | 88 | if ((config.Doom1Format && (mapNumber > 9)) || (!config.Doom1Format && (mapNumber > 99))) // Too many maps, stop here 89 | break; 90 | 91 | #if !DEBUG 92 | try 93 | { 94 | #endif 95 | string mapName = config.Doom1Format ? $"E{config.Episode:0}M{mapNumber:0}" : $"MAP{mapNumber:00}"; 96 | 97 | using Bitmap bitmap = new(mapBitmapFiles[i]); 98 | using DoomMap map = generator.Generate(mapName, bitmap); 99 | map.AddToWad(wad); 100 | #if !DEBUG 101 | } 102 | catch (Exception ex) 103 | { 104 | Console.WriteLine(ex.Message); 105 | Console.WriteLine(ex.StackTrace); 106 | Console.WriteLine(); 107 | continue; 108 | } 109 | #endif 110 | } 111 | 112 | wad.SaveToFile(wadFile); 113 | wad.Dispose(); 114 | generator.Dispose(); 115 | 116 | if (config.BuildNodes) 117 | { 118 | Process bspProcess; 119 | 120 | switch (Environment.OSVersion.Platform) 121 | { 122 | case PlatformID.Win32NT: 123 | case PlatformID.Win32S: 124 | case PlatformID.Win32Windows: 125 | case PlatformID.WinCE: 126 | Console.WriteLine("Building nodes with bsp-w32.exe..."); 127 | #if DEBUG 128 | bspProcess = Process.Start(@"..\Release\bsp-w32.exe", $"\"{wadFile}\" -o \"{wadFile}\""); 129 | #else 130 | bspProcess = Process.Start("bsp-w32.exe", $"\"{wadFile}\" -o \"{wadFile}\""); 131 | #endif 132 | bspProcess.WaitForExit(); 133 | if (bspProcess.ExitCode != 0) 134 | Console.WriteLine("Failed to build nodes!"); 135 | break; 136 | } 137 | } 138 | } 139 | 140 | /// 141 | /// IDisposable implementation. 142 | /// 143 | public void Dispose() { } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/Config/Preferences.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.INI; 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Drawing; 25 | 26 | namespace PNG2WAD.Config 27 | { 28 | 29 | /// 30 | /// Stores the preferences loaded from Preferences.ini. 31 | /// 32 | public readonly struct Preferences 33 | { 34 | /// 35 | /// Number of things categories. 36 | /// 37 | public static readonly int THINGS_CATEGORY_COUNT = Enum.GetValues(typeof(ThingCategory)).Length; 38 | 39 | /// 40 | /// Color to used for the default theme. 41 | /// 42 | public static readonly int DEFAULT_THEME_COLOR = Color.White.ToArgb(); 43 | 44 | /// 45 | /// Should nodes be built using bsp-w32 once the map(s) are generated? 46 | /// 47 | public bool BuildNodes { get; } 48 | 49 | /// 50 | /// Should map names be generated in the Doom 1 (ExMy) format? 51 | /// 52 | public bool Doom1Format { get; } 53 | 54 | /// 55 | /// What episode do the maps belong to? Only used when Doom1Format is true. 56 | /// 57 | public int Episode { get; } 58 | 59 | /// 60 | /// Should entrances and exits be generated? 61 | /// 62 | public bool GenerateEntranceAndExit { get; } 63 | 64 | /// 65 | /// Should things (monsters, items...) be generated? 66 | /// 67 | public bool GenerateThings { get; } 68 | 69 | /// 70 | /// The map themes. 71 | /// 72 | private readonly Dictionary Themes; 73 | 74 | /// 75 | /// Array of thing types to pick from for each thing category. 76 | /// 77 | public int[][] ThingsTypes { get; } 78 | 79 | /// 80 | /// Min/Max amount of things to spawn for each thing category. 81 | /// 82 | public int[][] ThingsCount { get; } 83 | 84 | /// 85 | /// Constructor. 86 | /// 87 | /// Path to the Preferences.ini file. 88 | public Preferences(string filePath) 89 | { 90 | using INIFile ini = new(filePath); 91 | 92 | // Load common settings 93 | BuildNodes = ini.GetValue("Options", "BuildNodes", false); 94 | Doom1Format = ini.GetValue("Options", "Doom1Format", false); 95 | Episode = Math.Max(1, Math.Min(9, ini.GetValue("Options", "Episode", 1))); 96 | GenerateEntranceAndExit = ini.GetValue("Options", "GenerateEntranceAndExit", true); 97 | GenerateThings = ini.GetValue("Options", "GenerateThings", true); 98 | 99 | // Load things 100 | ThingsTypes = new int[THINGS_CATEGORY_COUNT][]; 101 | ThingsCount = new int[THINGS_CATEGORY_COUNT][]; 102 | for (int i = 0; i < THINGS_CATEGORY_COUNT; i++) 103 | { 104 | ThingsTypes[i] = ini.GetValueArray("Things", $"Types.{(ThingCategory)i}"); 105 | ThingsCount[i] = ini.GetValueArray("Things", $"Count.{(ThingCategory)i}"); 106 | Array.Resize(ref ThingsCount[i], 2); 107 | ThingsCount[i] = new int[] { Math.Min(ThingsCount[i][0], ThingsCount[i][1]), Math.Max(ThingsCount[i][0], ThingsCount[i][1]) }; 108 | } 109 | 110 | // Load themes. Default theme is loaded first so it can't be overriden. 111 | Themes = new Dictionary 112 | { 113 | { DEFAULT_THEME_COLOR, new PreferencesTheme(ini, "Theme.Default") } 114 | }; 115 | 116 | foreach (string theme in ini.GetAllKeysInSection("Themes")) 117 | { 118 | Color? c = Toolbox.GetColorFromString(ini.GetValue("Themes", theme)); 119 | if (!c.HasValue) continue; 120 | if (Themes.ContainsKey(c.Value.ToArgb())) continue; 121 | 122 | Themes.Add(c.Value.ToArgb(), new PreferencesTheme(ini, $"Theme.{theme}")); 123 | } 124 | } 125 | 126 | /// 127 | /// Gets a theme from the RGB color of the top-left pixel of a map PNG. 128 | /// If no theme use this color, returns the default theme. 129 | /// 130 | /// Color of the "theme pixel" 131 | /// A theme 132 | public PreferencesTheme GetTheme(Color color) 133 | { 134 | int colorInt = color.ToArgb(); 135 | return Themes.ContainsKey(colorInt) ? Themes[colorInt] : Themes[DEFAULT_THEME_COLOR]; 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /bin/Release/Preferences.ini: -------------------------------------------------------------------------------- 1 | [Options] 2 | ; Should bsp-w32.exe be used to build nodes after the wad file is generated (Windows only)? 3 | ; If set to false or when running PixelsOfDoom on Linux or macOS, you'll have to build nodes manually using an external node builder 4 | BuildNodes=true 5 | 6 | ; Should the map be names be in the Doom 1 (ExMy) or Doom 2 (MAPxx) format? 7 | ; Be aware that you'll have to change some values in the Things and themes if you want to generate a Doom 1 map, because not all monsters and textures are available in Doom 1 8 | Doom1Format=false 9 | 10 | ; Episode the maps belong to, if Doom 1 format is used 11 | Episode=1 12 | 13 | ; Should entrance and exits be added on the map? 14 | ; If set to false, the maps will not be playable as no player starts will be generated 15 | GenerateEntranceAndExit=true 16 | 17 | ; Should monsters and items be generated 18 | GenerateThings=true 19 | 20 | [Things] 21 | ; Things types the things generator should spawn 22 | Types.AmmoSmall=2008,2007,2047,2010 23 | Types.AmmoLarge=2048,2046,2049,17 24 | Types.Armor=2018,2019 25 | Types.Health=2012,2011 26 | Types.MonstersVeryHard=64,69,3003 27 | Types.MonstersHard=3005,69 28 | Types.MonstersMedium=3002,3006,58,65 29 | Types.MonstersEasy=3004,9,3001 30 | Types.PowerUps=8,2023,2022,2024,2013 31 | Types.WeaponsLow=2002,2005,2001,82 32 | Types.WeaponsHigh=2006,2004,2003 33 | 34 | ; Minimum and maximum number of things to spawn in a map with 1000 walkable tiles (more or less what you could expect to find in an average 64×64 pixels map) 35 | ; A multiplier is applied if the map has more or less walkable tiles. 36 | Count.AmmoLarge=4,8 37 | Count.AmmoSmall=8,12 38 | Count.Armor=2,4 39 | Count.Health=8,10 40 | Count.MonstersAverage=15,25 41 | Count.MonstersEasy=15,25 42 | Count.MonstersHard=5,10 43 | Count.MonstersVeryHard=2,5 44 | Count.PowerUps=0,2 45 | Count.WeaponsHigh=1,3 46 | Count.WeaponsLow=2,4 47 | 48 | ; The color of the upper-left pixel of a PNG is used to set the map theme. 49 | [Themes] 50 | Default=255,255,255 51 | Cave=128,128,128 52 | City=128,128,255 53 | Hell=255,0,0 54 | 55 | ; Default theme, used when the upper-left pixel does not match any theme 56 | [Theme.Default] 57 | ; Floor and ceiling heights 58 | Height.Default=0,64 59 | Height.DoorSide=0,64 60 | Height.Entrance=4,64 61 | Height.Exit=4,64 62 | Height.Exterior=0,128 63 | Height.SpecialCeiling=0,60 64 | Height.SpecialFloor=-4,64 65 | 66 | LightLevel.Default=192 67 | LightLevel.DoorSide=192 68 | LightLevel.Entrance=192 69 | LightLevel.Exit=255 70 | LightLevel.Exterior=255 71 | LightLevel.SpecialCeiling=255 72 | LightLevel.SpecialFloor=192 73 | 74 | ; Sector types can be found here: https://doomwiki.org/wiki/Sector 75 | SectorSpecial.Default=0 76 | SectorSpecial.DoorSide=0 77 | SectorSpecial.Entrance=0 78 | SectorSpecial.Exit=8 79 | SectorSpecial.Exterior=0 80 | SectorSpecial.SpecialCeiling=17 81 | SectorSpecial.SpecialFloor=7 82 | 83 | Textures.Ceiling=CEIL3_1,CEIL3_3,FLAT18,FLAT20,FLAT4,FLAT5_5 84 | Textures.CeilingSpecial=CEIL3_4,FLAT17,FLAT2,FLOOR1_7,GRNLITE1,TLITE6_1,TLITE6_4,TLITE6_5,TLITE6_6 85 | Textures.Door=DOOR1,DOOR3 86 | Textures.DoorSide=LITE5 87 | Textures.Floor=FLAT1_1,FLAT1_2,FLAT5,FLAT5_5,FLOOR0_1,FLOOR0_2,FLOOR1_1,FLOOR3_3,FLOOR4_1,FLOOR5_3,FLOOR5_4 88 | Textures.FloorEntrance=CEIL4_3 89 | Textures.FloorExit=FLAT22 90 | Textures.FloorExterior=FLOOR6_2,FLAT10 91 | Textures.FloorSpecial=NUKAGE1 92 | Textures.Wall=STARTAN2,CEMENT6,GRAY1,ICKWALL1,SLADWALL,BIGBRIK3,BRONZE4,BROVINE2,SPACEW2,SPACEW4,TEKGREN2 93 | Textures.WallExterior= 94 | 95 | [Theme.Cave] 96 | Height.Default=0,64 97 | Height.DoorSide=0,64 98 | Height.Entrance=4,64 99 | Height.Exit=4,64 100 | Height.Exterior=0,128 101 | Height.SpecialCeiling=0,64 102 | Height.SpecialFloor=-4,64 103 | 104 | LightLevel.Default=164 105 | LightLevel.DoorSide=164 106 | LightLevel.Entrance=164 107 | LightLevel.Exit=255 108 | LightLevel.Exterior=192 109 | LightLevel.SpecialCeiling=164 110 | LightLevel.SpecialFloor=192 111 | 112 | SectorSpecial.Default=0 113 | SectorSpecial.DoorSide=0 114 | SectorSpecial.Entrance=0 115 | SectorSpecial.Exit=8 116 | SectorSpecial.Exterior=0 117 | SectorSpecial.SpecialCeiling=0 118 | SectorSpecial.SpecialFloor=0 119 | 120 | Textures.Ceiling=FLAT5_7,FLAT5_8,FLOOR6_2,MFLR8_2 121 | Textures.CeilingSpecial=FLAT5_2 122 | Textures.Door=BIGDOOR5 123 | Textures.DoorSide=METAL,SUPPORT3 124 | Textures.Floor=FLAT10,FLAT5_7,FLAT5_8,FLOOR6_2,MFLR8_2,MFLR8_4 125 | Textures.FloorEntrance=CEIL4_3 126 | Textures.FloorExit=FLAT22 127 | Textures.FloorExterior= 128 | Textures.FloorSpecial=FWATER1 129 | Textures.Wall=ASHWALL2,ROCK1,STONE4,STONE6 130 | Textures.WallExterior= 131 | 132 | [Theme.City] 133 | Height.Default=0,64 134 | Height.DoorSide=0,64 135 | Height.Entrance=4,64 136 | Height.Exit=4,64 137 | Height.Exterior=0,256 138 | Height.SpecialCeiling=0,64 139 | Height.SpecialFloor=-4,64 140 | 141 | LightLevel.Default=192 142 | LightLevel.DoorSide=192 143 | LightLevel.Entrance=192 144 | LightLevel.Exit=255 145 | LightLevel.Exterior=220 146 | LightLevel.SpecialCeiling=255 147 | LightLevel.SpecialFloor=192 148 | 149 | SectorSpecial.Default=0 150 | SectorSpecial.DoorSide=0 151 | SectorSpecial.Entrance=0 152 | SectorSpecial.Exit=8 153 | SectorSpecial.Exterior=0 154 | SectorSpecial.SpecialCeiling=0 155 | SectorSpecial.SpecialFloor=0 156 | 157 | Textures.Ceiling=CEIL3_1,FLAT5_4,FLAT9 158 | Textures.CeilingSpecial=CEIL3_4 159 | Textures.Door=DOOR1,DOOR3 160 | Textures.DoorSide=LITE5 161 | Textures.Floor=FLAT3,FLAT5,FLOOR0_2,FLOOR0_6,FLOOR0_7,FLOOR3_3 162 | Textures.FloorEntrance=CEIL4_3 163 | Textures.FloorExit=FLAT22 164 | Textures.FloorExterior=FLAT1,RROCK03 165 | Textures.FloorSpecial=FLAT14,FLOOR1_1,FLOOR1_6 166 | Textures.Wall=STARTAN2,CEMENT6,GRAY1,ICKWALL1,SLADWALL,BIGBRIK3,BRONZE4,BROVINE2,SPACEW2,SPACEW4,TEKGREN2 167 | Textures.WallExterior=BIGBRIK2,BLAKWAL2,BRICK1,BRICK5,BRICK11 168 | 169 | [Theme.Hell] 170 | Height.Default=0,64 171 | Height.DoorSide=0,64 172 | Height.Entrance=4,64 173 | Height.Exit=4,64 174 | Height.Exterior=0,128 175 | Height.SpecialCeiling=0,64 176 | Height.SpecialFloor=-4,64 177 | 178 | LightLevel.Default=164 179 | LightLevel.DoorSide=164 180 | LightLevel.Entrance=164 181 | LightLevel.Exit=255 182 | LightLevel.Exterior=192 183 | LightLevel.SpecialCeiling=164 184 | LightLevel.SpecialFloor=192 185 | 186 | SectorSpecial.Default=0 187 | SectorSpecial.DoorSide=0 188 | SectorSpecial.Entrance=0 189 | SectorSpecial.Exit=8 190 | SectorSpecial.Exterior=0 191 | SectorSpecial.SpecialCeiling=0 192 | SectorSpecial.SpecialFloor=5 193 | 194 | Textures.Ceiling=CEIL1_1,FLAT5_1,FLAT5_2,FLAT5_3 195 | Textures.CeilingSpecial=FLAT5_6,SFLR6_1,SFLR6_4 196 | Textures.Door=BIGDOOR5 197 | Textures.DoorSide=METAL,SUPPORT3 198 | Textures.Floor=FLAT1_1,FLAT1_2,FLAT5_1,FLAT5_2,FLAT5_3 199 | Textures.FloorEntrance=GATE4 200 | Textures.FloorExit=GATE1,GATE2,GATE3 201 | Textures.FloorExterior=FLAT5_7,FLAT5_8,FLOOR6_1,FLOOR6_2,MFLR8_2,MFLR8_3 202 | Textures.FloorSpecial=LAVA1 203 | Textures.Wall=GSTONE1,GSTVINE1,MARBGRAY,MARBLE2,SKINEDGE,SKSNAKE1 204 | Textures.WallExterior= 205 | -------------------------------------------------------------------------------- /src/Generator/SectorInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.Config; 22 | using System; 23 | 24 | namespace PNG2WAD.Generator 25 | { 26 | /// 27 | /// Information about a sector. Includes all data required by the SECTORS lump in the wad file, but also about the wall textures. 28 | /// 29 | public struct SectorInfo 30 | { 31 | /// 32 | /// Type of sector. 33 | /// 34 | public TileType Type { get; } 35 | 36 | /// 37 | /// Ceiling height. 38 | /// 39 | public int CeilingHeight { get; private set; } 40 | 41 | /// 42 | /// Ceiling texture. 43 | /// 44 | public string CeilingTexture { get; private set; } 45 | 46 | /// 47 | /// Floor height. 48 | /// 49 | public int FloorHeight { get; private set; } 50 | 51 | /// 52 | /// Floor texture. 53 | /// 54 | public string FloorTexture { get; private set; } 55 | 56 | /// 57 | /// Light level. 58 | /// 59 | public int LightLevel { get; private set; } 60 | 61 | /// 62 | /// Special type of linedefs facing this sector. 63 | /// 64 | public int LinedefSpecial { get; private set; } 65 | 66 | /// 67 | /// Special type of this sector. 68 | /// 69 | public int SectorSpecial { get; private set; } 70 | 71 | /// 72 | /// Wall texture. 73 | /// 74 | public string WallTexture { get; private set; } 75 | 76 | /// 77 | /// Upper wall texture. 78 | /// 79 | public string WallTextureUpper { get; private set; } 80 | 81 | /// 82 | /// Lower wall texture. 83 | /// 84 | public string WallTextureLower { get; private set; } 85 | 86 | /// 87 | /// Constructor. 88 | /// 89 | /// Type of sector 90 | /// Map theme 91 | /// Selected "default" textures for this map 92 | public SectorInfo(TileType type, PreferencesTheme theme, string[] themeTextures) 93 | { 94 | Type = type; 95 | 96 | FloorHeight = theme.Height[(int)ThemeSector.Default][0]; 97 | CeilingHeight = theme.Height[(int)ThemeSector.Default][1]; 98 | LinedefSpecial = 0; 99 | SectorSpecial = 0; 100 | 101 | LightLevel = theme.LightLevel[(int)ThemeSector.Default]; 102 | 103 | CeilingTexture = themeTextures[(int)ThemeTexture.Ceiling]; 104 | FloorTexture = themeTextures[(int)ThemeTexture.Floor]; 105 | WallTexture = Toolbox.RandomFromArray(theme.Textures[(int)ThemeTexture.Wall]); 106 | WallTextureUpper = null; 107 | WallTextureLower = null; 108 | 109 | switch (type) 110 | { 111 | case TileType.Door: 112 | CeilingHeight = FloorHeight; 113 | LinedefSpecial = 1; // DR Door Open Wait Close 114 | CeilingTexture = "CRATOP1"; 115 | WallTexture = "DOORTRAK"; 116 | WallTextureUpper = themeTextures[(int)ThemeTexture.Door]; 117 | break; 118 | 119 | case TileType.DoorSide: 120 | WallTexture = themeTextures[(int)ThemeTexture.DoorSide]; 121 | break; 122 | 123 | case TileType.Entrance: 124 | ApplySectorSpecial(theme, ThemeSector.Entrance); 125 | FloorTexture = themeTextures[(int)ThemeTexture.FloorEntrance]; 126 | break; 127 | 128 | case TileType.Exit: 129 | ApplySectorSpecial(theme, ThemeSector.Exit); 130 | LinedefSpecial = 52; // W1 Exit Level 131 | FloorTexture = themeTextures[(int)ThemeTexture.FloorExit]; 132 | break; 133 | 134 | case TileType.RoomExterior: 135 | ApplySectorSpecial(theme, ThemeSector.Exterior); 136 | CeilingTexture = "F_SKY1"; 137 | if (theme.Textures[(int)ThemeTexture.FloorExterior].Length > 0) 138 | FloorTexture = themeTextures[(int)ThemeTexture.FloorExterior]; 139 | if (theme.Textures[(int)ThemeTexture.WallExterior].Length > 0) 140 | WallTexture = Toolbox.RandomFromArray(theme.Textures[(int)ThemeTexture.WallExterior]); 141 | break; 142 | 143 | case TileType.RoomSpecialCeiling: 144 | ApplySectorSpecial(theme, ThemeSector.SpecialCeiling); 145 | CeilingTexture = themeTextures[(int)ThemeTexture.CeilingSpecial]; 146 | break; 147 | 148 | case TileType.RoomSpecialFloor: 149 | ApplySectorSpecial(theme, ThemeSector.SpecialFloor); 150 | FloorTexture = themeTextures[(int)ThemeTexture.FloorSpecial]; 151 | break; 152 | 153 | case TileType.Secret: 154 | CeilingHeight = FloorHeight; 155 | LinedefSpecial = 31; // D1 Door Open Stay 156 | SectorSpecial = 9; // Secret room 157 | WallTexture = "DOORTRAK"; 158 | break; 159 | } 160 | 161 | CeilingHeight = Math.Max(FloorHeight, CeilingHeight); 162 | 163 | WallTextureUpper = WallTextureUpper ?? WallTexture; 164 | WallTextureLower = WallTextureLower ?? WallTexture; 165 | } 166 | 167 | /// 168 | /// Applies parameters read from a ThemeSector. 169 | /// 170 | /// The map theme 171 | /// Type of ThemeSector to copy parameters from 172 | private void ApplySectorSpecial(PreferencesTheme theme, ThemeSector themeSector) 173 | { 174 | CeilingHeight = theme.Height[(int)themeSector][1]; 175 | FloorHeight = theme.Height[(int)themeSector][0]; 176 | LightLevel = theme.LightLevel[(int)themeSector]; 177 | SectorSpecial = theme.SectorSpecial[(int)themeSector]; 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/Toolbox.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Drawing; 24 | 25 | namespace PNG2WAD 26 | { 27 | /// 28 | /// A static "toolbox" class with various class extensions and static methods. 29 | /// 30 | public static class Toolbox 31 | { 32 | /// 33 | /// (Private) Random number generator. 34 | /// 35 | private static readonly Random RNG = new(); 36 | 37 | /// 38 | /// Compares two colors R,G,B values 39 | /// 40 | /// A color 41 | /// Another color 42 | /// True if all R,G,B values are all the same, false otherwise. 43 | public static bool IsSameRGB(this Color color, Color other) 44 | { 45 | return (color.R == other.R) && (color.G == other.G) && (color.B == other.B); 46 | } 47 | 48 | /// 49 | /// Returns the pythagorean distance between two points. 50 | /// 51 | /// A point 52 | /// Another point 53 | /// The distance between the two points 54 | public static float Distance(this Point point, Point other) 55 | { 56 | return (float)Math.Sqrt(Math.Pow(point.X - other.X, 2) + Math.Pow(point.Y - other.Y, 2)); 57 | } 58 | 59 | 60 | /// 61 | /// Adds two points. 62 | /// 63 | /// A point 64 | /// Another point 65 | /// A new with X = point.X + other.X and Y = point.Y + other.Y 66 | public static Point Add(this Point point, Point other) 67 | { 68 | return new Point(point.X + other.X, point.Y + other.Y); 69 | } 70 | 71 | /// 72 | /// Multiplies a point with another point. 73 | /// 74 | /// A point 75 | /// Another point 76 | /// A new with X = point.X * mutiplier.X and Y = point.Y * mutiplier.Y 77 | public static Point Mult(this Point point, Point mutiplier) 78 | { 79 | return new Point(point.X * mutiplier.X, point.Y * mutiplier.Y); 80 | } 81 | 82 | /// 83 | /// Turns a string into a System.Drawing.Color. 84 | /// Can parse strings in HTML (#xxxxxx), RGB (xxx,xxx,xxx) and KnownColor (Red, Blue, etc.) formats. 85 | /// 86 | /// A string 87 | /// The color, or null if parsing failed 88 | public static Color? GetColorFromString(string colorString) 89 | { 90 | int r, g, b; 91 | 92 | try 93 | { 94 | colorString = colorString.Trim(); 95 | 96 | 97 | if (colorString.StartsWith("#")) // HTML format 98 | { 99 | colorString = colorString[1..]; 100 | 101 | if (colorString.Length == 6) 102 | { 103 | r = Convert.ToInt32(colorString[..2], 16); 104 | g = Convert.ToInt32(colorString.Substring(2, 2), 16); 105 | b = Convert.ToInt32(colorString.Substring(4, 2), 16); 106 | 107 | return Color.FromArgb(255, r, g, b); 108 | } 109 | else if (colorString.Length == 3) 110 | { 111 | string xR = colorString[..1]; xR += xR; 112 | string xG = colorString.Substring(1, 1); xG += xG; 113 | string xB = colorString.Substring(2, 1); xB += xB; 114 | 115 | r = Convert.ToInt32(xR, 16); 116 | g = Convert.ToInt32(xG, 16); 117 | b = Convert.ToInt32(xB, 16); 118 | 119 | return Color.FromArgb(255, r, g, b); 120 | } 121 | } 122 | else if (colorString.Contains(',')) // R,G,B format 123 | { 124 | string[] rgbStrings = colorString.Split(','); 125 | 126 | if (rgbStrings.Length >= 3) 127 | { 128 | r = Convert.ToInt32(rgbStrings[0].Trim()); 129 | g = Convert.ToInt32(rgbStrings[1].Trim()); 130 | b = Convert.ToInt32(rgbStrings[2].Trim()); 131 | 132 | return Color.FromArgb(255, r, g, b); 133 | } 134 | } 135 | else if (Enum.TryParse(colorString, true, out KnownColor knownColor)) 136 | return Color.FromKnownColor(knownColor); 137 | } 138 | catch (Exception) 139 | { 140 | return null; 141 | } 142 | 143 | return null; 144 | } 145 | 146 | /// 147 | /// Returns a random integer between 0 (inclusive) and maxValue (exclusive). 148 | /// 149 | /// The maximum possible value, EXCLUSIVE 150 | /// An integer 151 | public static int RandomInt(int maxValue) 152 | { 153 | return RNG.Next(maxValue); 154 | } 155 | 156 | /// 157 | /// Returns a random integer between minValue (inclusive) and maxValue (exclusive). 158 | /// 159 | /// The maximum possible value, INCLUSIVE 160 | /// The maximum possible value, EXCLUSIVE 161 | /// An integer 162 | public static int RandomInt(int minValue, int maxValue) 163 | { 164 | return RNG.Next(minValue, maxValue); 165 | } 166 | 167 | /// 168 | /// Returns a random element from a array. 169 | /// 170 | /// The type of the array 171 | /// The array 172 | /// An element from the array 173 | public static T RandomFromArray(T[] array) 174 | { 175 | if ((array == null) || (array.Length == 0)) return default; 176 | return array[RNG.Next(array.Length)]; 177 | } 178 | 179 | /// 180 | /// Returns a random element from a list. 181 | /// 182 | /// The type of the list 183 | /// The list 184 | /// An element from the list 185 | public static T RandomFromList(List list) 186 | { 187 | if ((list == null) || (list.Count == 0)) return default; 188 | return list[RNG.Next(list.Count)]; 189 | } 190 | 191 | /// 192 | /// Clamps the value between minValue and maxValue. 193 | /// 194 | /// A value 195 | /// Minimum acceptable value 196 | /// Maximum acceptable value 197 | /// The clamped value 198 | public static int Clamp(int value, int minValue, int maxValue) 199 | { 200 | return Math.Max(minValue, Math.Min(maxValue, value)); 201 | } 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/Generator/ThingsGenerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.Config; 22 | using PNG2WAD.Doom.Map; 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Drawing; 26 | using System.Linq; 27 | 28 | namespace PNG2WAD.Generator 29 | { 30 | /// 31 | /// Things generator. Creates player starts, items, monsters and other things. 32 | /// 33 | public sealed class ThingsGenerator : IDisposable 34 | { 35 | /// 36 | /// Default angle is North. 37 | /// 38 | private const int DEFAULT_ANGLE = 90; 39 | 40 | /// 41 | /// Number of deathmatch starts. 42 | /// 43 | private const int DEATHMATCH_STARTS_COUNT = 8; 44 | 45 | /// 46 | /// PNG2WAD Preferences. 47 | /// 48 | private readonly Preferences Preferences; 49 | 50 | /// 51 | /// List of 64x64 where a thing can be spawned. 52 | /// 53 | private readonly List FreeTiles; 54 | 55 | /// 56 | /// Constructor. 57 | /// 58 | /// PNG2WAD preferences 59 | public ThingsGenerator(Preferences preferences) 60 | { 61 | Preferences = preferences; 62 | 63 | FreeTiles = new List(); 64 | } 65 | 66 | /// 67 | /// Create all required things on a map. 68 | /// 69 | /// The Doom map on which to create things 70 | /// Map sub-tiles generated by MapGenerator 71 | public void CreateThings(DoomMap map, TileType[,] subTiles) 72 | { 73 | int i, x, y; 74 | 75 | FreeTiles.Clear(); 76 | for (x = 0; x < subTiles.GetLength(0); x += MapGenerator.SUBTILE_DIVISIONS) 77 | for (y = 0; y < subTiles.GetLength(1); y += MapGenerator.SUBTILE_DIVISIONS) 78 | { 79 | switch (subTiles[x,y]) 80 | { 81 | case TileType.Door: 82 | case TileType.DoorSide: 83 | case TileType.Entrance: 84 | case TileType.Exit: 85 | case TileType.Secret: 86 | case TileType.Wall: 87 | continue; 88 | } 89 | 90 | FreeTiles.Add(new Point(x / MapGenerator.SUBTILE_DIVISIONS, y / MapGenerator.SUBTILE_DIVISIONS)); 91 | } 92 | 93 | 94 | if (Preferences.GenerateEntranceAndExit) 95 | { 96 | AddPlayerStarts(map, subTiles); // Single-player and coop starts (spawned on entrances, or next to each other is none found) 97 | AddThings(map, DEATHMATCH_STARTS_COUNT, 0, 11); // Deathmatch starts (spawned anywhere on the map) 98 | } 99 | 100 | float thingsCountMultiplier = FreeTiles.Count / 1000.0f; // Bigger map = more things 101 | 102 | if (Preferences.GenerateThings) 103 | { 104 | for (i = 0; i < Preferences.THINGS_CATEGORY_COUNT; i++) 105 | AddThings(map, (ThingCategory)i, 106 | (int)(Preferences.ThingsCount[i][0] * thingsCountMultiplier), 107 | (int)(Preferences.ThingsCount[i][1] * thingsCountMultiplier)); 108 | } 109 | } 110 | 111 | /// 112 | /// Adds a random number of things from a certain ThingCategory. 113 | /// 114 | /// The Doom map on which to add things 115 | /// The thing category from which to pick thing types 116 | /// Min number of things to add 117 | /// Max number of things to add 118 | /// Special flags for thing generation 119 | private void AddThings(DoomMap map, ThingCategory thingCategory, int minCount, int maxCount, ThingsGeneratorFlags generationFlags = 0) 120 | { 121 | int count = Toolbox.RandomInt(minCount, maxCount + 1); 122 | AddThings(map, count, generationFlags, Preferences.ThingsTypes[(int)thingCategory]); 123 | } 124 | 125 | /// 126 | /// Add a certain number of things from an array of thing types to a map. 127 | /// 128 | /// The Doom map on which to add things 129 | /// The number of things to add 130 | /// Special flags for thing generation 131 | /// Array of thing types to select from 132 | private void AddThings(DoomMap map, int count, ThingsGeneratorFlags generationFlags, params int[] thingTypes) 133 | { 134 | if ((count < 1) || (thingTypes.Length == 0)) return; 135 | 136 | for (int i = 0; i < count; i++) 137 | { 138 | if (FreeTiles.Count == 0) return; 139 | 140 | ThingOptions options = ThingOptions.AllSkills; 141 | 142 | switch (generationFlags) 143 | { 144 | case ThingsGeneratorFlags.MoreThingsInEasyMode: 145 | if (Toolbox.RandomInt(4) == 0) options = ThingOptions.Skill12 | ThingOptions.Skill3; 146 | else if (Toolbox.RandomInt(3) == 0) options = ThingOptions.Skill12; 147 | break; 148 | case ThingsGeneratorFlags.MoreThingsInHardMode: 149 | if (Toolbox.RandomInt(3) == 0) options = ThingOptions.Skill3 | ThingOptions.Skill45; 150 | else if (Toolbox.RandomInt(2) == 0) options = ThingOptions.Skill45; 151 | break; 152 | } 153 | 154 | int thingType = Toolbox.RandomFromArray(thingTypes); 155 | Point pt = Toolbox.RandomFromList(FreeTiles); 156 | AddThing(map, pt.X, pt.Y, thingType, Toolbox.RandomInt(360), options); 157 | FreeTiles.Remove(pt); 158 | } 159 | } 160 | 161 | /// 162 | /// Adds player starts to the map 163 | /// 164 | /// Doom map to add player starts to 165 | /// Map sub-tiles generated by MapGenerator 166 | private void AddPlayerStarts(DoomMap map, TileType[,] subTiles) 167 | { 168 | int x, y; 169 | List entrances = new(); 170 | 171 | // Spawn a single-player/coop entrance for each of the four players 172 | for (int player = 1; player <= 4; player++) 173 | { 174 | bool foundAnEntrance = false; 175 | 176 | // First try to look for a free "entrance" tile 177 | for (x = 0; x < subTiles.GetLength(0); x+= MapGenerator.SUBTILE_DIVISIONS) 178 | for (y = 0; y < subTiles.GetLength(1); y += MapGenerator.SUBTILE_DIVISIONS) 179 | { 180 | if (!foundAnEntrance && (subTiles[x, y] == TileType.Entrance)) 181 | { 182 | Point entranceTile = new(x / MapGenerator.SUBTILE_DIVISIONS, y / MapGenerator.SUBTILE_DIVISIONS); 183 | if (entrances.Contains(entranceTile)) continue; // Entrance already in use 184 | AddThing(map, x / MapGenerator.SUBTILE_DIVISIONS, y / MapGenerator.SUBTILE_DIVISIONS, player); 185 | entrances.Add(entranceTile); 186 | foundAnEntrance = true; 187 | } 188 | } 189 | 190 | if (foundAnEntrance) continue; 191 | 192 | // No "entrance" tile found for this player, so... 193 | if (FreeTiles.Count > 0) 194 | { 195 | Point tile; 196 | 197 | // ...if no player entrance has been selected yet, spawn the player on a random free tile 198 | if (entrances.Count == 0) 199 | tile = Toolbox.RandomFromList(FreeTiles); 200 | // ...else spawn the player on the nearest free tile from player 1 start 201 | else 202 | tile = (from Point t in FreeTiles select t).OrderBy(t => t.Distance(entrances[0])).First(); 203 | 204 | FreeTiles.Remove(tile); 205 | AddThing(map, tile.X, tile.Y, player); 206 | entrances.Add(tile); 207 | foundAnEntrance = true; 208 | } 209 | 210 | if (foundAnEntrance) continue; 211 | 212 | // No free spot, put the player start in the northwest map corner. 213 | // Should never happen unless the map is entirely made of walls, doors or other unpassable stuff. 214 | // Might be outside a sector but at least the map won't crash with a "no player start found" error. 215 | AddThing(map, player - 1, 0, player); 216 | entrances.Add(new Point(player - 1, 0)); 217 | } 218 | } 219 | 220 | /// 221 | /// Adds a thing to the map. 222 | /// 223 | /// Doom map the thing should be added to 224 | /// X coordinate of the tile on which the thing should be spawned 225 | /// Y coordinate of the tile on which the thing should be spanwed 226 | /// Type of thing 227 | /// Angle the thing should face 228 | /// Thing options 229 | private static void AddThing(DoomMap map, int x, int y, int thingType, int angle = (int)DEFAULT_ANGLE, ThingOptions options = ThingOptions.AllSkills) 230 | { 231 | map.Things.Add( 232 | new Thing( 233 | (int)((x + .5f) * MapGenerator.TILE_SIZE), 234 | (int)((y + .5f) * -MapGenerator.TILE_SIZE), 235 | thingType, angle, options)); 236 | } 237 | 238 | /// 239 | /// IDisposable implementation. 240 | /// 241 | public void Dispose() { } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /src/Doom/Wad/WadFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of Tools of Doom, a library providing a collection of 4 | classes to load/edit/save Doom maps and wad archives, created by @akaAgar 5 | (https://github.com/akaAgar/tools-of-doom). 6 | 7 | Tools of Doom is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Tools of Doom is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Tools of Doom. If not, see https://www.gnu.org/licenses/ 19 | ========================================================================== 20 | */ 21 | 22 | using System; 23 | using System.Collections.Generic; 24 | using System.IO; 25 | using System.Linq; 26 | using System.Text; 27 | 28 | namespace PNG2WAD.Doom.Wad 29 | { 30 | /// 31 | /// A Doom wad archive. 32 | /// 33 | public sealed class WadFile : IDisposable 34 | { 35 | /// 36 | /// Max length of a lump name. 37 | /// 38 | public const int MAX_LUMP_NAME_LENGTH = 8; 39 | 40 | /// 41 | /// Is the wad an IWAD (true) or a PWAD (false)? 42 | /// 43 | public bool IWAD { get; set; } = false; 44 | 45 | /// 46 | /// The number of lumps in the archive. 47 | /// 48 | public int LumpCount { get { return Lumps.Count; } } 49 | 50 | /// 51 | /// A list of all the lumps in the wad archive. 52 | /// 53 | // Cannot be a string/byte[] dictionary because a wad archive can have multiple lumps with the same names (and often does, as each map has its own THINGS, LINEDEFS, etc.) 54 | private readonly List Lumps = new(); 55 | 56 | /// 57 | /// Constructor. Creates an empty wad archive. 58 | /// 59 | public WadFile() { } 60 | 61 | /// 62 | /// Constructor. Loads a wad archive from a file. 63 | /// 64 | /// Path to the wad file 65 | public WadFile(string filePath) 66 | { 67 | if (!File.Exists(filePath)) return; 68 | 69 | byte[] buffer4 = new byte[4]; 70 | byte[] buffer8 = new byte[8]; 71 | 72 | int i; 73 | 74 | using FileStream fs = new(filePath, FileMode.Open); 75 | 76 | fs.Read(buffer4, 0, 4); // Bytes 0-3 (ASCII string): IWAD or PWAD 77 | switch (GetStringFromBytes(buffer4)) 78 | { 79 | case "IWAD": IWAD = true; break; 80 | case "PWAD": IWAD = false; break; 81 | default: return; // Neither an IWAD or a PWAD, invalid format 82 | } 83 | 84 | fs.Read(buffer4, 0, 4); // Bytes 4-7 (int): lump count 85 | int lumpCount = Convert.ToInt32(buffer4); 86 | if (lumpCount <= 0) return; 87 | 88 | fs.Read(buffer4, 0, 4); // Bytes 8-11 (int): directory offset 89 | int directoryOffset = Convert.ToInt32(buffer4); 90 | if (directoryOffset < 12) return; 91 | 92 | for (i = 0; i < lumpCount; i++) 93 | { 94 | fs.Seek(directoryOffset + 16 * i, SeekOrigin.Begin); 95 | 96 | fs.Read(buffer4, 0, 4); 97 | int lumpOffset = Convert.ToInt32(buffer4); 98 | fs.Read(buffer4, 0, 4); 99 | int lumpSize = Convert.ToInt32(buffer4); 100 | fs.Read(buffer4, 0, 8); 101 | string lumpName = GetStringFromBytes(buffer8); 102 | 103 | byte[] lumpbytes = new byte[lumpSize]; 104 | fs.Seek(lumpOffset, SeekOrigin.Begin); 105 | fs.Read(lumpbytes, 0, lumpSize); 106 | Lumps.Add(new WadLump(lumpName, lumpbytes)); 107 | } 108 | } 109 | 110 | /// 111 | /// Remove all lumps. 112 | /// 113 | public void ClearLumps() { Lumps.Clear(); } 114 | 115 | /// 116 | /// 117 | /// 118 | /// 119 | /// 120 | public WadLump? this[string lumpName] 121 | { 122 | get 123 | { 124 | int index = GetFirstIndexByLumpName(lumpName); 125 | if (index == -1) return null; 126 | return Lumps[index]; 127 | } 128 | } 129 | 130 | /// 131 | /// Gets the lump with the provided index, or returns null if index is invalid. 132 | /// 133 | /// Index of the lump 134 | /// A wad lump, or null if index was invalid 135 | public WadLump? this[int index] 136 | { 137 | get 138 | { 139 | if ((index < 0) || (index >= Lumps.Count)) return null; 140 | return Lumps[index]; 141 | } 142 | } 143 | 144 | /// 145 | /// Gets the indices of all lumps with this name. 146 | /// 147 | /// Lump name to search for 148 | /// 149 | public int[] GetIndicesByLumpName(string lumpName) 150 | { 151 | if (string.IsNullOrEmpty(lumpName)) return Array.Empty(); 152 | lumpName = lumpName.ToUpperInvariant(); 153 | 154 | List indices = new(); 155 | 156 | for (int i = 0; i < Lumps.Count; i++) 157 | if (Lumps[i].Name == lumpName) 158 | indices.Add(i); 159 | 160 | return indices.ToArray(); 161 | } 162 | 163 | public int GetFirstIndexByLumpName(string lumpName) 164 | { 165 | int[] indices = GetIndicesByLumpName(lumpName); 166 | return (indices.Length == 0) ? -1 : indices[0]; 167 | } 168 | 169 | /// 170 | /// Removes node(s) with the provided name. 171 | /// 172 | /// Name of the lump(s) to remove 173 | /// If false, only the first node with this name will be removed. If true, all nodes with this name will be removed 174 | /// True if at least one lump was removed, false if no lump with this name was found 175 | public bool RemoveLump(string lumpName, bool removeAll = false) 176 | { 177 | if (removeAll) 178 | { 179 | int lumpIndex = GetFirstIndexByLumpName(lumpName); 180 | if (lumpIndex < 0) return false; 181 | 182 | while (lumpIndex >= 0) 183 | { 184 | Lumps.RemoveAt(lumpIndex); 185 | lumpIndex = GetFirstIndexByLumpName(lumpName); 186 | } 187 | 188 | return true; 189 | } 190 | 191 | return RemoveLump(GetFirstIndexByLumpName(lumpName)); 192 | } 193 | 194 | /// 195 | /// Removes the lump at the provided index. 196 | /// 197 | /// Index of the lump to remove 198 | /// True if the lump was removed succesfully, false if index was invalid 199 | public bool RemoveLump(int index) 200 | { 201 | if ((index < 0) || (index >= Lumps.Count)) return false; 202 | Lumps.RemoveAt(index); 203 | return true; 204 | } 205 | 206 | /// 207 | /// The names of all lumps in the file. 208 | /// 209 | public string[] LumpNames { get { return (from WadLump lump in Lumps select lump.Name).ToArray(); } } 210 | 211 | /// 212 | /// Saves the content of the .wad to a file. 213 | /// 214 | public void SaveToFile(string wadFilePath) 215 | { 216 | // Directory offset is 12 (header length) plus the sum of the length of all lumps 217 | int directoryOffset = 12 + (from WadLump lump in Lumps select lump.Bytes.Length).Sum(); 218 | 219 | // Write the 12-bytes wad file header. 220 | // 4 bytes: an ASCII string which must be either "IWAD" or "PWAD" 221 | // 4 bytes: an integer which is the number of lumps in the wad 222 | // 4 bytes: an integer which is the file offset to the start of the directory 223 | List headerBytes = new(); 224 | headerBytes.AddRange(Encoding.ASCII.GetBytes(IWAD ? "IWAD" : "PWAD")); 225 | headerBytes.AddRange(BitConverter.GetBytes(Lumps.Count)); 226 | headerBytes.AddRange(BitConverter.GetBytes(directoryOffset)); 227 | 228 | // Writes the file directory 229 | List directoryBytes = new(); 230 | int byteOffset = 12; 231 | foreach (WadLump l in Lumps) 232 | { 233 | directoryBytes.AddRange(BitConverter.GetBytes(byteOffset)); 234 | directoryBytes.AddRange(BitConverter.GetBytes(l.Bytes.Length)); 235 | directoryBytes.AddRange(GetBytesFromString(l.Name)); 236 | byteOffset += l.Bytes.Length; 237 | } 238 | 239 | List wadBytes = new(); 240 | wadBytes.AddRange(headerBytes); 241 | foreach (WadLump l in Lumps) wadBytes.AddRange(l.Bytes); 242 | wadBytes.AddRange(directoryBytes); 243 | File.WriteAllBytes(wadFilePath, wadBytes.ToArray()); 244 | } 245 | 246 | /// 247 | /// Convert an ASCII string to an array of bytes. 248 | /// 249 | /// String to convert 250 | /// Fixed length of the returned byte array 251 | /// A byte array 252 | public static byte[] GetBytesFromString(string text, int length = MAX_LUMP_NAME_LENGTH) 253 | { 254 | if (length <= 0) return Array.Empty(); 255 | if (string.IsNullOrEmpty(text)) return new byte[length]; 256 | 257 | byte[] bytes = Encoding.ASCII.GetBytes(text); 258 | Array.Resize(ref bytes, length); 259 | return bytes; 260 | } 261 | 262 | /// 263 | /// Converts an array of bytes into an ASCII string. 264 | /// 265 | /// Array of bytes to convert 266 | /// A ASCII string 267 | public static string GetStringFromBytes(params byte[] asciiBytes) 268 | { 269 | if (asciiBytes == null) return ""; 270 | 271 | return Encoding.ASCII.GetString(asciiBytes).Trim('\0').ToUpperInvariant(); 272 | } 273 | 274 | /// 275 | /// Adds a lump to the wad. 276 | /// 277 | /// The name of the lump. 278 | /// The content of the lump, as a byte array. 279 | public void AddLump(string lumpName, byte[] bytes) 280 | { 281 | Lumps.Add(new WadLump(lumpName, bytes)); 282 | } 283 | 284 | /// 285 | /// IDisposeable implementation. 286 | /// 287 | public void Dispose() { ClearLumps(); } 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /src/INI/INIFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using System; 22 | using System.IO; 23 | using System.Collections.Generic; 24 | using System.Globalization; 25 | using System.Linq; 26 | using System.Text; 27 | using System.Text.RegularExpressions; 28 | 29 | namespace PNG2WAD.INI 30 | { 31 | /// 32 | /// Loads and saves Windows .ini files. 33 | /// 34 | public class INIFile : IDisposable 35 | { 36 | private const StringSplitOptions SPLIT_OPTIONS_REMOVE_EMPTY_AND_TRIM = StringSplitOptions.RemoveEmptyEntries; 37 | 38 | private static readonly Regex KEY_NORMALIZATION_REGEX = new("[^a-z0-9-\\.]"); 39 | 40 | private readonly Dictionary> entries = new(StringComparer.OrdinalIgnoreCase); 41 | 42 | /// 43 | /// Constructor. 44 | /// 45 | public INIFile() 46 | { 47 | entries.Clear(); 48 | } 49 | 50 | public INIFile(string filePath, Encoding encoding = null) 51 | { 52 | LoadFromFile(filePath, encoding); 53 | } 54 | 55 | public void Clear() 56 | { 57 | foreach (string entryKey in entries.Keys) 58 | entries[entryKey].Clear(); 59 | 60 | entries.Clear(); 61 | } 62 | 63 | public string[] GetAllSections() 64 | { 65 | return entries.Keys.OrderBy(x => x).ToArray(); 66 | } 67 | 68 | public void LoadFromFile(string filePath, Encoding encoding = null) 69 | { 70 | Clear(); 71 | if (!File.Exists(filePath)) return; 72 | string dataString = File.ReadAllText(filePath, encoding ?? Encoding.UTF8); 73 | 74 | ParseString(dataString); 75 | } 76 | 77 | public void LoadFromDataString(string dataString) 78 | { 79 | ParseString(dataString); 80 | } 81 | 82 | public string[] GetAllKeysInSection(string sectionKey, bool topLevelOnly = false) 83 | { 84 | if (!entries.ContainsKey(sectionKey)) return Array.Empty(); 85 | 86 | if (topLevelOnly) 87 | return (from string key in entries[sectionKey].Keys select key.Split('.')[0]).Distinct().OrderBy(x => x).ToArray(); 88 | 89 | return entries[sectionKey].Keys.OrderBy(x => x).ToArray(); 90 | } 91 | 92 | public bool SectionExists(string sectionKey) 93 | { 94 | return entries.ContainsKey(sectionKey); 95 | } 96 | 97 | public bool ValueExists(string sectionKey, string keyID) 98 | { 99 | return entries.ContainsKey(sectionKey) && entries[sectionKey].ContainsKey(keyID); 100 | } 101 | 102 | public void RemoveSection(string sectionKey) 103 | { 104 | if (!entries.ContainsKey(sectionKey)) return; 105 | 106 | entries.Remove(sectionKey); 107 | } 108 | 109 | public void RemoveKey(string sectionKey, string keyID) 110 | { 111 | if (!entries.ContainsKey(sectionKey) || !entries[sectionKey].ContainsKey(keyID)) return; 112 | 113 | entries[sectionKey].Remove(keyID); 114 | } 115 | 116 | protected string GetRawValue(string sectionKey, string keyID) 117 | { 118 | sectionKey = NormalizeKey(sectionKey); 119 | keyID = NormalizeKey(keyID); 120 | 121 | if (!ValueExists(sectionKey, keyID)) return null; 122 | 123 | return entries[sectionKey][keyID]; 124 | } 125 | 126 | protected void SetRawValue(string sectionKey, string keyID, string value) 127 | { 128 | sectionKey = NormalizeKey(sectionKey); 129 | keyID = NormalizeKey(keyID); 130 | value ??= ""; 131 | 132 | if (!entries.ContainsKey(sectionKey)) 133 | entries.Add(sectionKey, new Dictionary(StringComparer.OrdinalIgnoreCase)); 134 | 135 | if (!entries[sectionKey].ContainsKey(keyID)) 136 | entries[sectionKey].Add(keyID, value); 137 | else 138 | entries[sectionKey][keyID] = value; 139 | } 140 | 141 | protected string[] GetAllValuesKeys() 142 | { 143 | return ( 144 | from Dictionary section in entries.Values 145 | select section.Keys).SelectMany(i => i).Distinct().OrderBy(x => x).ToArray(); 146 | } 147 | 148 | private void ParseString(string dataString) 149 | { 150 | Clear(); 151 | 152 | string[] lines = dataString.Replace("\r\n", "\n").Split(new char[] { '\n' }, SPLIT_OPTIONS_REMOVE_EMPTY_AND_TRIM); 153 | string currentSection = null; 154 | 155 | foreach (string line in lines) 156 | { 157 | if (line.StartsWith(";")) continue; // Line is a comment 158 | if (line.StartsWith("[") && line.EndsWith("]")) 159 | { 160 | currentSection = line.TrimStart('[').TrimEnd(']').Trim().ToLowerInvariant(); 161 | if (string.IsNullOrEmpty(currentSection)) currentSection = null; 162 | continue; 163 | } 164 | if (!line.Contains('=')) continue; 165 | if (currentSection == null) continue; 166 | 167 | string[] parts = line.Split(new char[] { '=' }, 2, SPLIT_OPTIONS_REMOVE_EMPTY_AND_TRIM); 168 | if (parts.Length < 2) continue; 169 | 170 | string key = parts[0].ToLowerInvariant(); 171 | if (string.IsNullOrEmpty(key)) continue; 172 | 173 | SetRawValue(currentSection, key, parts[1]); 174 | } 175 | } 176 | 177 | public T GetValue(string sectionKey, string keyID, T defaultValue = default) 178 | { 179 | if (!ValueExists(sectionKey, keyID)) return defaultValue; 180 | return ConvertFromString(GetRawValue(sectionKey, keyID)); 181 | } 182 | 183 | public T[] GetValueArray(string sectionKey, string keyID, params T[] defaultValues) 184 | { 185 | if (!ValueExists(sectionKey, keyID)) return defaultValues; 186 | 187 | Type valueType = typeof(T); 188 | 189 | string[] values = GetRawValue(sectionKey, keyID).Split(GetArraySeparator(), SPLIT_OPTIONS_REMOVE_EMPTY_AND_TRIM); 190 | 191 | return (from string value in values select ConvertFromString(value)).ToArray(); 192 | } 193 | 194 | public Dictionary GetValueStringArrayDictionary(string sectionKey, string keyID) 195 | { 196 | Dictionary dict = new(StringComparer.OrdinalIgnoreCase) 197 | { 198 | { "", GetValueArray(sectionKey, keyID) } 199 | }; 200 | 201 | string[] subKeys = 202 | (from subKey in GetAllKeysInSection(sectionKey) 203 | where subKey.ToLowerInvariant().StartsWith($"{keyID.ToLowerInvariant()}.") && 204 | subKey.Length > keyID.Length + 1 205 | select subKey.Split('.')[1].ToLowerInvariant()).ToArray(); 206 | 207 | foreach (string subKey in subKeys) 208 | { 209 | if (dict.ContainsKey(subKey)) continue; 210 | dict.Add(subKey, GetValueArray(sectionKey, $"{keyID}.{subKey}")); 211 | } 212 | 213 | return dict; 214 | } 215 | 216 | public Dictionary GetValueStringDictionary(string sectionKey, string keyID) 217 | { 218 | Dictionary dict = new(StringComparer.OrdinalIgnoreCase) 219 | { 220 | { "", GetValue(sectionKey, keyID) } 221 | }; 222 | 223 | string[] subKeys = 224 | (from subKey in GetAllKeysInSection(sectionKey) 225 | where subKey.ToLowerInvariant().StartsWith($"{keyID.ToLowerInvariant()}.") && 226 | subKey.Length > keyID.Length + 1 227 | select subKey.Split('.')[1].ToLowerInvariant()).ToArray(); 228 | 229 | foreach (string subKey in subKeys) 230 | { 231 | if (dict.ContainsKey(subKey)) continue; 232 | dict.Add(subKey, GetValue(sectionKey, $"{keyID}.{subKey}")); 233 | } 234 | 235 | return dict; 236 | } 237 | 238 | public Dictionary GetValueEnumDictionary(string sectionKey, string keyID) where EnumType : struct 239 | { 240 | Dictionary stringDict = GetValueStringDictionary(sectionKey, keyID); 241 | 242 | Dictionary dict = new(); 243 | foreach (string sKey in stringDict.Keys) 244 | { 245 | if (string.IsNullOrWhiteSpace(sKey)) continue; 246 | bool success = Enum.TryParse(sKey, true, out EnumType eKey); 247 | if (!success) continue; 248 | if (dict.ContainsKey(eKey)) continue; 249 | dict.Add(eKey, stringDict[sKey]); 250 | } 251 | 252 | return dict; 253 | } 254 | 255 | public T[] GetValueArrayEnumIndex(string sectionKey, string keyID) where TIndex : Enum 256 | { 257 | T[] values = new T[Enum.GetValues(typeof(TIndex)).Length]; 258 | 259 | for (int i = 0; i < values.Length; i++) 260 | { 261 | string fullKey = $"{keyID}.{(TIndex)(object)i}"; 262 | 263 | if (!ValueExists(sectionKey, fullKey)) 264 | { 265 | values[i] = default; 266 | continue; 267 | } 268 | 269 | values[i] = GetValue(sectionKey, keyID); 270 | } 271 | 272 | return values; 273 | } 274 | 275 | /// 276 | /// Get an array of comma-separated lower case strings. 277 | /// 278 | /// Section key 279 | /// Value key 280 | /// Should multiple instances of the same string be removed? 281 | /// An array of strings 282 | public string[] GetValueArrayNormalizedStrings(string sectionKey, string keyID, bool distinct = false) 283 | { 284 | string valuesString = GetRawValue(sectionKey, keyID); 285 | if (string.IsNullOrEmpty(valuesString)) return Array.Empty(); 286 | 287 | IEnumerable values = valuesString.Split(',', SPLIT_OPTIONS_REMOVE_EMPTY_AND_TRIM); 288 | 289 | if (!values.Any()) return Array.Empty(); 290 | values = (from string value in values select value.ToLowerInvariant()); 291 | 292 | if (distinct) 293 | values = values.Distinct(); 294 | 295 | return values.ToArray(); 296 | } 297 | 298 | public T[][] GetValueArrayArrayEnumIndex(string sectionKey, string keyID) where TIndex : Enum 299 | { 300 | T[][] values = new T[Enum.GetValues(typeof(TIndex)).Length][]; 301 | 302 | for (int i = 0; i < values.Length; i++) 303 | { 304 | string fullKey = $"{keyID}.{(TIndex)(object)i}"; 305 | 306 | if (!ValueExists(sectionKey, fullKey)) 307 | { 308 | values[i] = default; 309 | continue; 310 | } 311 | 312 | values[i] = GetValueArray(sectionKey, fullKey); 313 | } 314 | 315 | return values; 316 | } 317 | 318 | public List GetValueList(string section, string key, params T[] defaultValues) 319 | { 320 | return new List(GetValueArray(section, key, defaultValues)); 321 | } 322 | 323 | public T GetValueAsFlags(string section, string key) where T : Enum 324 | { 325 | T[] valueArray = GetValueArray(section, key); 326 | int valueFlags = 0; 327 | foreach (T value in valueArray) 328 | valueFlags |= (int)(object)value; 329 | 330 | return (T)(object)valueFlags; 331 | } 332 | 333 | public Dictionary GetValueDictionary(string section, string key, params KeyValuePair[] defaultPairs) where TKey : struct, Enum 334 | { 335 | if (!ValueExists(section, key)) 336 | return new Dictionary(defaultPairs); 337 | 338 | Dictionary dict = new(); 339 | 340 | foreach (TKey dictKey in Enum.GetValues(typeof(TKey))) 341 | dict.Add(dictKey, ConvertFromString(GetRawValue(section, $"{key}.{dictKey}"))); 342 | 343 | return dict; 344 | } 345 | 346 | public void SetValueDictionary(string section, string key, Dictionary value) 347 | { 348 | foreach (TKey dictKey in value.Keys) 349 | SetValue(section, $"{key}.{ConvertToString(dictKey)}", value[dictKey]); 350 | } 351 | 352 | public void SetValueDictionaryArray(string section, string key, Dictionary value) 353 | { 354 | foreach (TKey dictKey in value.Keys) 355 | SetValueArray(section, $"{key}.{ConvertToString(dictKey)}", value[dictKey]); 356 | } 357 | 358 | public void SetValue(string section, string key, T value) 359 | { 360 | SetRawValue(section, key, ConvertToString(value)); 361 | } 362 | 363 | protected virtual T ConvertFromString(string valueString) 364 | { 365 | Type valueType = typeof(T); 366 | 367 | if (valueType.IsEnum) return (T)Enum.Parse(valueType, valueString, true); 368 | if (valueType == typeof(bool)) return (T)(object)Convert.ToBoolean(valueString, NumberFormatInfo.InvariantInfo); 369 | if (valueType == typeof(byte)) return (T)(object)Convert.ToByte(valueString, NumberFormatInfo.InvariantInfo); 370 | if (valueType == typeof(double)) return (T)(object)Convert.ToDouble(valueString, NumberFormatInfo.InvariantInfo); 371 | if (valueType == typeof(float)) return (T)(object)Convert.ToSingle(valueString, NumberFormatInfo.InvariantInfo); 372 | if (valueType == typeof(int)) return (T)(object)Convert.ToInt32(valueString, NumberFormatInfo.InvariantInfo); 373 | if (valueType == typeof(long)) return (T)(object)Convert.ToInt64(valueString, NumberFormatInfo.InvariantInfo); 374 | if (valueType == typeof(sbyte)) return (T)(object)Convert.ToSByte(valueString, NumberFormatInfo.InvariantInfo); 375 | if (valueType == typeof(short)) return (T)(object)Convert.ToInt16(valueString, NumberFormatInfo.InvariantInfo); 376 | if (valueType == typeof(string)) return (T)(object)valueString; 377 | if (valueType == typeof(uint)) return (T)(object)Convert.ToUInt32(valueString, NumberFormatInfo.InvariantInfo); 378 | if (valueType == typeof(ushort)) return (T)(object)Convert.ToUInt16(valueString, NumberFormatInfo.InvariantInfo); 379 | if (valueType == typeof(ulong)) return (T)(object)Convert.ToUInt64(valueString, NumberFormatInfo.InvariantInfo); 380 | 381 | throw new Exception($"Cannot read values of type {valueType.FullName} from INI file."); 382 | } 383 | 384 | protected virtual string ConvertToString(T value) 385 | { 386 | Type valueType = typeof(T); 387 | object objectValue = value; 388 | 389 | if (valueType.IsEnum) return objectValue.ToString(); 390 | if (valueType == typeof(bool)) return ((bool)objectValue).ToString(NumberFormatInfo.InvariantInfo); 391 | if (valueType == typeof(byte)) return ((byte)objectValue).ToString(NumberFormatInfo.InvariantInfo); 392 | if (valueType == typeof(double)) return ((double)objectValue).ToString(NumberFormatInfo.InvariantInfo); 393 | if (valueType == typeof(float)) return ((float)objectValue).ToString(NumberFormatInfo.InvariantInfo); 394 | if (valueType == typeof(int)) return ((int)objectValue).ToString(NumberFormatInfo.InvariantInfo); 395 | if (valueType == typeof(long)) return ((long)objectValue).ToString(NumberFormatInfo.InvariantInfo); 396 | if (valueType == typeof(sbyte)) return ((sbyte)objectValue).ToString(NumberFormatInfo.InvariantInfo); 397 | if (valueType == typeof(short)) return ((short)objectValue).ToString(NumberFormatInfo.InvariantInfo); 398 | if (valueType == typeof(string)) return objectValue.ToString(); // $"\"{value.ToString().Trim('\"')}\""; 399 | if (valueType == typeof(uint)) return ((uint)objectValue).ToString(NumberFormatInfo.InvariantInfo); 400 | if (valueType == typeof(ushort)) return ((ushort)objectValue).ToString(NumberFormatInfo.InvariantInfo); 401 | if (valueType == typeof(ulong)) return ((ulong)objectValue).ToString(NumberFormatInfo.InvariantInfo); 402 | 403 | throw new Exception($"Cannot write values of type {valueType.FullName} to file."); 404 | } 405 | 406 | public Dictionary GetValueDictionaryArray(string section, string key) where TKey : struct, Enum 407 | { 408 | key = key.ToLowerInvariant(); 409 | Dictionary dict = new(); 410 | 411 | foreach (TKey dictKey in Enum.GetValues(typeof(TKey))) 412 | dict.Add(dictKey, GetValueArray(section, $"{key}.{dictKey}")); 413 | 414 | return dict; 415 | } 416 | 417 | public void SetValueArray(string section, string key, params T[] values) 418 | { 419 | string arrayString = string.Join( 420 | GetArraySeparator(), 421 | (from T value in values select ConvertToString(value)).ToArray()); 422 | 423 | SetRawValue(section, key, arrayString); 424 | } 425 | 426 | protected virtual char GetArraySeparator() 427 | { 428 | if (typeof(ElementType) == typeof(string)) 429 | return ';'; 430 | 431 | return ','; 432 | } 433 | 434 | public void SaveToFile(string filePath, Encoding encoding = null) 435 | { 436 | string dataString = ""; 437 | bool firstSection = true; 438 | 439 | foreach (string entryKey in GetAllSections()) 440 | { 441 | if (firstSection) firstSection = false; 442 | else dataString += "\r\n"; 443 | dataString += $"[{entryKey}]\r\n"; 444 | 445 | foreach (string keyID in GetAllKeysInSection(entryKey)) 446 | dataString += $"{keyID}={GetRawValue(entryKey, keyID)}\r\n"; 447 | } 448 | 449 | File.WriteAllText(filePath, dataString, encoding ?? Encoding.UTF8); 450 | } 451 | 452 | private static string NormalizeKey(string key) 453 | { 454 | if (string.IsNullOrEmpty(key)) return "0"; 455 | key = KEY_NORMALIZATION_REGEX.Replace(key.ToLowerInvariant().Replace(" ", "-"), "-").Trim('-'); 456 | while (key.Contains("--")) key = key.Replace("--", "-"); 457 | return key; 458 | } 459 | 460 | public static T CreateFromRawString(string dataString) where T : INIFile, new() 461 | { 462 | T dataFile = new(); 463 | dataFile.ParseString(dataString); 464 | return dataFile; 465 | } 466 | 467 | /// 468 | /// IDisposable implementation. 469 | /// 470 | public void Dispose() 471 | { 472 | Clear(); 473 | GC.SuppressFinalize(this); 474 | } 475 | } 476 | } 477 | -------------------------------------------------------------------------------- /src/Generator/MapGenerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ========================================================================== 3 | This file is part of PNG2WAD, a tool to create Doom maps from PNG files, 4 | created by @akaAgar (https://github.com/akaAgar/png2wad) 5 | 6 | PNG2WAD is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | PNG2WAD is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with PNG2WAD. If not, see https://www.gnu.org/licenses/ 18 | ========================================================================== 19 | */ 20 | 21 | using PNG2WAD.Config; 22 | using PNG2WAD.Doom.Map; 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Drawing; 26 | 27 | namespace PNG2WAD.Generator 28 | { 29 | /// 30 | /// Map generator. Turns a PNG image into a Doom map. 31 | /// 32 | public sealed class MapGenerator : IDisposable 33 | { 34 | /// 35 | /// Size of each tile (one tile = one pixel in the PNG image) in Doom map units. 36 | /// 37 | public const int TILE_SIZE = 64; 38 | 39 | /// 40 | /// Number of subdivisions of each tile. 41 | /// Required to generate doors, as doors are divided into 3 sectors: 3 "doorstep" subtiles, 2 "door" subtiles and then 3 "doorstep" subtiles again. 42 | /// 43 | public const int SUBTILE_DIVISIONS = 8; 44 | 45 | /// 46 | /// The size of each subtile, in Doom map units. 47 | /// 48 | public const int SUBTILE_SIZE = TILE_SIZE / SUBTILE_DIVISIONS; 49 | 50 | /// 51 | /// Multiplier to get the position of a vertex from the map subtiles coordinates. 52 | /// Y axis has to be inverted because of the way Doom maps are made. 53 | /// 54 | private static readonly Point VERTEX_POSITION_MULTIPLIER = new(SUBTILE_SIZE, -SUBTILE_SIZE); 55 | 56 | /// 57 | /// Number of subtiles on the X-axis (equals to "source PNG width × SUBTILE_SIZE) 58 | /// 59 | private int MapSubWidth { get { return SubTiles.GetLength(0); } } 60 | 61 | /// 62 | /// Number of subtiles on the Y-axis (equals to "source PNG height × SUBTILE_SIZE) 63 | /// 64 | private int MapSubHeight { get { return SubTiles.GetLength(1); } } 65 | 66 | /// 67 | /// Map theme to use. 68 | /// 69 | private PreferencesTheme Theme; 70 | 71 | /// 72 | /// Selected texture for each ThemeTexture category. 73 | /// 74 | private string[] ThemeTextures; 75 | 76 | /// 77 | /// Type of each map sub-tile. 78 | /// 79 | private TileType[,] SubTiles; 80 | 81 | /// 82 | /// Sector index of each map sub-tile. 83 | /// 84 | private int[,] Sectors; 85 | 86 | /// 87 | /// List to sector info from which to generate sectors and linedefs. 88 | /// 89 | private List SectorsInfo; 90 | 91 | /// 92 | /// PNG2WAD preferences. 93 | /// 94 | private readonly Preferences Preferences; 95 | 96 | /// 97 | /// Constructor. 98 | /// 99 | /// PNG2WAD preferences 100 | public MapGenerator(Preferences preferences) 101 | { 102 | Preferences = preferences; 103 | } 104 | 105 | /// 106 | /// Generates the map. 107 | /// 108 | /// Map name (MAP01, E1M1, etc) 109 | /// PNG to generate the file from 110 | /// A Doom map 111 | public DoomMap Generate(string name, Bitmap bitmap) 112 | { 113 | if (bitmap == null) return null; 114 | 115 | DoomMap map = new(name); 116 | 117 | CreateTheme(bitmap); 118 | CreateArrays(bitmap); 119 | CreateSectors(map); 120 | CreateLines(map); 121 | 122 | using (ThingsGenerator thingsGenerator = new(Preferences)) 123 | { 124 | thingsGenerator.CreateThings(map, SubTiles); 125 | } 126 | 127 | return map; 128 | } 129 | 130 | /// 131 | /// Selects the proper theme from the PNG's upper-leftmost pixel, and picks random textures. 132 | /// 133 | /// The PNG image 134 | private void CreateTheme(Bitmap bitmap) 135 | { 136 | Theme = Preferences.GetTheme(bitmap.GetPixel(0, 0)); 137 | bitmap.SetPixel(0, 0, Color.White); 138 | ThemeTextures = new string[PreferencesTheme.THEME_TEXTURES_COUNT]; 139 | 140 | for (int i = 0; i < PreferencesTheme.THEME_TEXTURES_COUNT; i++) 141 | ThemeTextures[i] = Toolbox.RandomFromArray(Theme.Textures[i]); 142 | } 143 | 144 | /// 145 | /// Get a tile type from a pixel. 146 | /// 147 | /// A pixel on the PNG image 148 | /// A tile type 149 | private static TileType GetTileTypeFromPixel(Color pixel) 150 | { 151 | if (pixel.IsSameRGB(Color.White)) return TileType.Wall; 152 | 153 | if (pixel.IsSameRGB(Color.FromArgb(0, 0, 255))) return TileType.RoomExterior; 154 | if (pixel.IsSameRGB(Color.FromArgb(0, 128, 0))) return TileType.RoomSpecialCeiling; 155 | if (pixel.IsSameRGB(Color.FromArgb(255, 0, 0))) return TileType.RoomSpecialFloor; 156 | 157 | if (pixel.IsSameRGB(Color.FromArgb(128, 128, 0))) return TileType.Door; 158 | if (pixel.IsSameRGB(Color.Magenta)) return TileType.Secret; 159 | 160 | if (pixel.IsSameRGB(Color.Yellow)) return TileType.Entrance; 161 | if (pixel.IsSameRGB(Color.Lime)) return TileType.Exit; 162 | 163 | return TileType.Room; 164 | } 165 | 166 | /// 167 | /// Creates/clears SectorInfo list and Subtiles and Sectors array before generating a map. 168 | /// 169 | /// The map PNG image 170 | private void CreateArrays(Bitmap bitmap) 171 | { 172 | int x, y, sX, sY; 173 | TileType tileType, subTileType; 174 | 175 | SectorsInfo = new List(); 176 | 177 | SubTiles = new TileType[bitmap.Width * SUBTILE_DIVISIONS, bitmap.Height * SUBTILE_DIVISIONS]; 178 | for (x = 0; x < bitmap.Width; x++) 179 | for (y = 0; y < bitmap.Height; y++) 180 | { 181 | tileType = GetTileTypeFromPixel(bitmap.GetPixel(x, y)); 182 | 183 | if (!Preferences.GenerateEntranceAndExit) // Entrance and exit generation disabled, do not create entrance/exit tiles 184 | { 185 | if ((tileType == TileType.Entrance) || (tileType == TileType.Exit)) 186 | tileType = TileType.Room; 187 | } 188 | 189 | for (sX = 0; sX < SUBTILE_DIVISIONS; sX++) 190 | for (sY = 0; sY < SUBTILE_DIVISIONS; sY++) 191 | { 192 | subTileType = tileType; 193 | 194 | if (tileType == TileType.Door) 195 | { 196 | subTileType = TileType.DoorSide; 197 | 198 | if ((x > 0) && (x < bitmap.Width - 1) && 199 | (GetTileTypeFromPixel(bitmap.GetPixel(x - 1, y)) != TileType.Room) && 200 | (GetTileTypeFromPixel(bitmap.GetPixel(x + 1, y)) != TileType.Room)) 201 | { 202 | if ((sY == 3) || (sY == 4)) 203 | subTileType = TileType.Door; 204 | } 205 | else 206 | { 207 | if ((sX == 3) || (sX == 4)) 208 | subTileType = TileType.Door; 209 | } 210 | } 211 | 212 | SubTiles[x * SUBTILE_DIVISIONS + sX, y * SUBTILE_DIVISIONS + sY] = subTileType; 213 | } 214 | } 215 | 216 | Sectors = new int[bitmap.Width * SUBTILE_DIVISIONS, bitmap.Height * SUBTILE_DIVISIONS]; 217 | for (x = 0; x < bitmap.Width * SUBTILE_DIVISIONS; x++) 218 | for (y = 0; y < bitmap.Height * SUBTILE_DIVISIONS; y++) 219 | Sectors[x, y] = -2; 220 | } 221 | 222 | /// 223 | /// Creates the map linedefs and sidedefs 224 | /// 225 | /// Doom map in which to write linedefs and sidedefs 226 | private void CreateLines(DoomMap map) 227 | { 228 | int x, y; 229 | 230 | bool[,,] linesSet = new bool[MapSubWidth, MapSubHeight, 4]; 231 | 232 | for (x = 0; x < MapSubWidth; x++) 233 | for (y = 0; y < MapSubHeight; y++) 234 | { 235 | int sector = GetSector(x, y); 236 | if (sector < 0) continue; // Tile is a wall, do nothing 237 | 238 | for (int i = 0; i < 4; i++) 239 | { 240 | if (linesSet[x, y, i]) continue; // Line already drawn 241 | 242 | Point neighborDirection = GetTileSideOffset((TileSide)i); 243 | 244 | int neighborSector = GetSector(x + neighborDirection.X, y + neighborDirection.Y); 245 | if (sector == neighborSector) continue; // Same sector on both sides, no need to add a line 246 | 247 | if ((neighborSector >= 0) && ((i == (int)TileSide.South) || (i == (int)TileSide.East))) 248 | continue; // Make sure two-sided lines aren't drawn twice 249 | 250 | bool vertical = (neighborDirection.X != 0); 251 | 252 | int length = AddLine(map, new Point(x, y), (TileSide)i, vertical, sector, neighborSector); 253 | 254 | for (int j = 0; j < length; j++) 255 | { 256 | Point segmentPosition = new Point(x, y).Add(vertical ? new Point(0, j) : new Point(j, 0)); 257 | if (!IsSubPointOnMap(segmentPosition)) continue; 258 | linesSet[segmentPosition.X, segmentPosition.Y, i] = true; 259 | } 260 | } 261 | } 262 | } 263 | 264 | /// 265 | /// Gets the proper offset according to the side of the tile (N, S, E or W) 266 | /// 267 | /// One of the four sides of a tile 268 | /// An offset 269 | private static Point GetTileSideOffset(TileSide side) 270 | { 271 | return side switch 272 | { 273 | TileSide.East => new Point(1, 0), 274 | TileSide.South => new Point(0, 1), 275 | TileSide.West => new Point(-1, 0), 276 | _ => new Point(0, -1),// case WallDirection.North 277 | }; 278 | } 279 | 280 | /// 281 | /// Adds a new linedef (and its sidedef(s)) to the map. 282 | /// 283 | /// The Doom map 284 | /// Line start position 285 | /// Direction to the line's neighbor sector 286 | /// Is the line vertical (on the Y-axis) or horizontal (on the X-axis) 287 | /// Index of the sector this line faces 288 | /// Index of the sector this line is turned against 289 | /// 290 | private int AddLine(DoomMap map, Point position, TileSide neighborDirection, bool vertical, int sector, int neighborSector) 291 | { 292 | bool flipVectors = false; 293 | Point vertexOffset = Point.Empty; 294 | Point neighborOffset = GetTileSideOffset(neighborDirection); 295 | Point neighborPosition; 296 | 297 | bool needsFlipping = SectorsInfo[sector].LinedefSpecial > 0; 298 | 299 | switch (neighborDirection) 300 | { 301 | case TileSide.West: 302 | flipVectors = true; 303 | break; 304 | case TileSide.East: 305 | vertexOffset = new Point(1, 0); 306 | break; 307 | case TileSide.South: 308 | flipVectors = true; 309 | vertexOffset = new Point(0, 1); 310 | break; 311 | } 312 | 313 | int v1 = map.AddVertex(position.Add(vertexOffset).Mult(VERTEX_POSITION_MULTIPLIER)); 314 | int length = 0; 315 | 316 | Point direction = vertical ? new Point(0, 1) : new Point(1, 0); 317 | 318 | do 319 | { 320 | position = position.Add(direction); 321 | neighborPosition = position.Add(neighborOffset); 322 | length++; 323 | 324 | 325 | if ((GetSector(position) != sector) || (GetSector(neighborPosition) != neighborSector)) break; 326 | } while (true); 327 | 328 | int v2 = map.AddVertex(position.Add(vertexOffset).Mult(VERTEX_POSITION_MULTIPLIER)); 329 | 330 | if (flipVectors) { v1 += v2; v2 = v1 - v2; v1 -= v2; } // Quick hack to flip two integers without temporary variable 331 | 332 | if (neighborSector < 0) // neighbor is a wall, create an impassible linedef 333 | { 334 | map.Sidedefs.Add(new Sidedef(0, 0, "-", "-", SectorsInfo[sector].WallTexture, sector)); 335 | map.Linedefs.Add(new Linedef(v1, v2, LinedefFlags.Impassible | LinedefFlags.LowerUnpegged, 0, 0, -1, map.Sidedefs.Count - 1)); 336 | } 337 | else // neighbor is another sector, create a two-sided linedef 338 | { 339 | int lineSpecial = Math.Max(SectorsInfo[sector].LinedefSpecial, SectorsInfo[neighborSector].LinedefSpecial); 340 | 341 | map.Sidedefs.Add(CreateTwoSidedSidedef(neighborSector, SectorsInfo[neighborSector], SectorsInfo[sector])); 342 | map.Sidedefs.Add(CreateTwoSidedSidedef(sector, SectorsInfo[sector], SectorsInfo[neighborSector])); 343 | 344 | if (needsFlipping) 345 | map.Linedefs.Add(new Linedef(v2, v1, LinedefFlags.TwoSided, lineSpecial, 0, map.Sidedefs.Count - 1, map.Sidedefs.Count - 2)); 346 | else 347 | map.Linedefs.Add(new Linedef(v1, v2, LinedefFlags.TwoSided, lineSpecial, 0, map.Sidedefs.Count - 2, map.Sidedefs.Count - 1)); 348 | } 349 | 350 | return length; 351 | } 352 | 353 | /// 354 | /// Creates a sidedef from two SectorInfo 355 | /// 356 | /// Sector this sidedef faces 357 | /// Info about the sector this sidedef faces 358 | /// Info about the sector this sidedef's opposing sector 359 | private static Sidedef CreateTwoSidedSidedef(int sectorID, SectorInfo sector, SectorInfo neighborSector) 360 | { 361 | string lowerTexture, upperTexture; 362 | 363 | if (neighborSector.Type == TileType.Door) 364 | { 365 | upperTexture = (neighborSector.CeilingHeight < sector.CeilingHeight) ? neighborSector.WallTextureUpper : "-"; 366 | lowerTexture = (neighborSector.FloorHeight > sector.FloorHeight) ? neighborSector.WallTextureLower : "-"; 367 | } 368 | else 369 | { 370 | upperTexture = (neighborSector.CeilingHeight < sector.CeilingHeight) ? sector.WallTexture : "-"; 371 | lowerTexture = (neighborSector.FloorHeight > sector.FloorHeight) ? sector.WallTexture : "-"; 372 | } 373 | 374 | return new Sidedef(0, 0, upperTexture, lowerTexture, "-", sectorID); 375 | } 376 | 377 | /// 378 | /// Gets the sector index at a given position. 379 | /// 380 | /// Coordinates of a sub-tile 381 | /// A sector index or -1 if none 382 | private int GetSector(Point position) { return GetSector(position.X, position.Y); } 383 | 384 | /// 385 | /// Gets the sector index at a given position. 386 | /// 387 | /// X coordinate of a sub-tile 388 | /// Y coordinate of a sub-tile 389 | /// A sector index or -1 if none 390 | private int GetSector(int x, int y) 391 | { 392 | if ((x < 0) || (y < 0) || (x >= MapSubWidth) || (y >= MapSubHeight) || (Sectors[x, y] < 0)) 393 | return -1; 394 | 395 | return Sectors[x, y]; 396 | } 397 | 398 | /// 399 | /// Is a sub-tile coordinate on the map? 400 | /// 401 | /// Coordinates of a sub-tile 402 | /// True if sub-tile on the map, false if out of bounds 403 | private bool IsSubPointOnMap(Point position) 404 | { 405 | return !((position.X < 0) || (position.Y < 0) || (position.X >= MapSubWidth) || (position.Y >= MapSubHeight)); 406 | } 407 | 408 | /// 409 | /// Creates the sectors on the Doom map. 410 | /// 411 | /// The Doom map 412 | private void CreateSectors(DoomMap map) 413 | { 414 | int x, y; 415 | 416 | map.Sectors.Clear(); 417 | 418 | for (x = 0; x < MapSubWidth; x++) 419 | for (y = 0; y < MapSubHeight; y++) 420 | { 421 | if (Sectors[x, y] != -2) continue; // Cell was already checked 422 | 423 | if (SubTiles[x, y] == TileType.Wall) 424 | { 425 | Sectors[x, y] = -1; 426 | continue; 427 | } 428 | 429 | Stack pixels = new(); 430 | Point pt = new(x, y); 431 | pixels.Push(pt); 432 | 433 | while (pixels.Count > 0) 434 | { 435 | Point a = pixels.Pop(); 436 | 437 | if (a.X < MapSubWidth && a.X > 0 && a.Y < MapSubHeight && a.Y > 0) 438 | { 439 | if ((Sectors[a.X, a.Y] == -2) && (SubTiles[a.X, a.Y].Equals(SubTiles[x, y]))) 440 | { 441 | Sectors[a.X, a.Y] = SectorsInfo.Count; 442 | pixels.Push(new Point(a.X - 1, a.Y)); 443 | pixels.Push(new Point(a.X + 1, a.Y)); 444 | pixels.Push(new Point(a.X, a.Y - 1)); 445 | pixels.Push(new Point(a.X, a.Y + 1)); 446 | } 447 | } 448 | } 449 | 450 | SectorInfo sectorInfo = new(SubTiles[x, y], Theme, ThemeTextures); 451 | SectorsInfo.Add(sectorInfo); 452 | 453 | map.Sectors.Add( 454 | new Sector( 455 | sectorInfo.FloorHeight, sectorInfo.CeilingHeight, 456 | sectorInfo.FloorTexture, sectorInfo.CeilingTexture, 457 | sectorInfo.LightLevel, sectorInfo.SectorSpecial, 0)); 458 | } 459 | } 460 | 461 | /// 462 | /// IDisposable implementation 463 | /// 464 | public void Dispose() 465 | { 466 | 467 | } 468 | } 469 | } 470 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------