{"id":815,"date":"2014-07-12T22:35:04","date_gmt":"2014-07-12T14:35:04","guid":{"rendered":"http:\/\/www.gridsagegames.com\/blog\/?p=815"},"modified":"2017-01-11T09:21:10","modified_gmt":"2017-01-11T01:21:10","slug":"dungeon-prefabs","status":"publish","type":"post","link":"https:\/\/www.gridsagegames.com\/blog\/2014\/07\/dungeon-prefabs\/","title":{"rendered":"Dungeon Prefabs"},"content":{"rendered":"<p>Procedurally generated maps are great, but even with variety factored into an algorithm it naturally won&#8217;t produce anything outside its parameters. This is good in that it keeps the style consistent, but individual areas sacrifice character as a result.<\/p>\n<p>Hand-crafted map pieces can restore some of that character where you really need it, be that interspersed with generated content to mix things up, or at key plot areas where a specific environment is necessary. Prefabs integrated with the rest of the map will really stand out, and be more memorable for it.<\/p>\n<div id=\"attachment_816\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_skull.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-816\" class=\"size-full wp-image-816 \" title=\"Dungeon Prefabs: Skull\" alt=\"prefab_skull\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_skull.png\" width=\"400\" height=\"400\" \/><\/a><p id=\"caption-attachment-816\" class=\"wp-caption-text\">Just a silly example, but writing a separate algorithm to procedurally generate skulls would be overkill.<\/p><\/div>\n<p>Prefabs are a way to deviate from what may otherwise be a repetitive experience (even if that repetition is masked behind layer upon layer of random content). They also give players a &#8220;common ground&#8221; from which to discuss specific parts of a game. The more a roguelike is completely random and unpredictable, the more discussion is limited to &#8220;general survival tips.&#8221; Static areas open up a whole different category of discussion--&#8220;what can we do <em>here<\/em>&#8221; rather than &#8220;what can we do <em>when<\/em> XYZ.&#8221;<\/p>\n<p>And it&#8217;s not only strategy--a whole new category of stories emerges from static areas, since readers who&#8217;ve played the game will have a much clearer idea of <em>where<\/em> the story takes place, having explored that same area themselves.<\/p>\n<h2>Creation<\/h1>\n<p>I chose to draw prefabs in <a title=\"Options, Revisited\" href=\"http:\/\/www.gridsagegames.com\/rexpaint\" target=\"_blank\">REXPaint<\/a>, assigning different palette colors for each cell type and painting them on the first layer.<\/p>\n<div id=\"attachment_819\" style=\"width: 334px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_skull_REXPaint.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-819\" class=\"wp-image-819 \" title=\"Dungeon Prefabs: Skull (in REXPaint)\" alt=\"prefab_skull_REXPaint\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_skull_REXPaint.png\" width=\"324\" height=\"263\" \/><\/a><p id=\"caption-attachment-819\" class=\"wp-caption-text\">Initial tests used the same palette as the algorithm development program.<\/p><\/div>\n<p>Other layers in the image store additional information, because prefabs are obviously about more than just the layout.<\/p>\n<div id=\"attachment_843\" style=\"width: 332px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_REXPaint.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-843\" class=\"size-full wp-image-843 \" title=\"Dungeon Prefabs: Rigged Skull (in REXPaint)\" alt=\"cogmind_prefab_skull_REXPaint\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_REXPaint.png\" width=\"322\" height=\"370\" \/><\/a><p id=\"caption-attachment-843\" class=\"wp-caption-text\">I changed the palette to give it the black background similar to what would be seen in game, to simplify the design process.<\/p><\/div>\n<p>Above is a fully &#8220;rigged&#8221; prefab with some test content. Layer 2 (above layer 1) contains map linking\/integration information (that yellow &#8216;2&#8217;, which I&#8217;ll talk about later). Layer 3 is where unique machines\/props are drawn (those gray lines and boxes). Layer 4 contains references indicating static object locations (the green letters\/numbers).<\/p>\n<p>Any prefab that includes specific objects (most), needs an accompanying text file that describes the objects placed in layer 4.<\/p>\n<div id=\"attachment_845\" style=\"width: 721px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_script.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-845\" class=\"size-full wp-image-845 \" title=\"Dungeon Prefabs: Skull Script Example\" alt=\"cogmind_prefab_skull_script\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_script.png\" width=\"711\" height=\"235\" \/><\/a><p id=\"caption-attachment-845\" class=\"wp-caption-text\">Test data\/script for the skull prefab, containing a random assortment of objects.\u00a0 Ideally this information could be entered\/viewed\/manipulated directly in the prefab editor, but in the case of Cogmind prefabs and their objects are fairly simple so I&#8217;ve opted to use a text file instead.<\/p><\/div>\n<p>Objects can be listed in any order, and use any letter or number as a reference. More features, including the potential for randomized objects, will be implemented when necessary--this is just what the game currently needs to get things working on a basic level.<\/p>\n<p>And here it is loaded in game connected to an actual map:<\/p>\n<div id=\"attachment_846\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_ingame.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-846\" class=\"size-full wp-image-846 \" title=\"Dungeon Prefabs: Skull (in game)\" alt=\"cogmind_prefab_skull_ingame\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_ingame.png\" width=\"290\" height=\"351\" \/><\/a><p id=\"caption-attachment-846\" class=\"wp-caption-text\">Entering the skull test in game. (The map generator dropped an extra robot and item into it because the area wasn&#8217;t set as off limits to random spawning.)<\/p><\/div>\n<h2>Integration<\/h1>\n<p>The main issue with prefabs is how to connect them to the rest of the map. Letting the map generator do whatever it wants could make a mess of the prefab and defeat the purpose, so dark gray cells surrounding the skull keep the map generator from encroaching on it. Instead we control the connection from the prefab end.<\/p>\n<p>First, based on instructions from a map definition text file the algorithm reads in .xp files (produced by REXPaint), parses them for their contents, then places those cells on the map (at a random position if indicated) before any other generation begins. The yellow cell on the skull example indicates that when corridor-building begins, a 2-wide tunneler will start digging south (the nearest edge) from there, and will eventually connect with the rest of the map.<\/p>\n<p><div id=\"attachment_847\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_placement.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-847\" class=\"size-full wp-image-847 \" title=\"Dungeon Prefabs: Skull (placement)\" alt=\"cogmind_prefab_skull_placement\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/07\/cogmind_prefab_skull_placement.png\" width=\"584\" height=\"80\" \/><\/a><p id=\"caption-attachment-847\" class=\"wp-caption-text\">The section of the map definition file that places a prefab, where the &#8220;type&#8221; is the file name containing the image. Maps also support other general [FEATURE]s besides prefabs, most useful for designating areas that are off limits to the generator.<\/p><\/div>Because the features are placed before any tunneling and random generation begins, they also support randomized placement so that, for example, you won&#8217;t always find the same point of interest in the same area of a map.<\/p>\n<p><em>Update 3\/16\/2016: I&#8217;ve since written <a title=\"Generating and Populating Caves\" href=\"http:\/\/www.gridsagegames.com\/blog\/2016\/03\/generating-populating-caves\/\">Generating and Populating Caves<\/a>, demonstrating how prefabs are integrated with cave maps as part of the post-generation process.<\/em><\/p>\n<p><em>Update 1\/11\/2017: And the newer <a title=\"Map Prefabs, in Depth\" href=\"http:\/\/www.gridsagegames.com\/blog\/2017\/01\/map-prefabs-in-depth\/\">Map Prefabs, in Depth<\/a> covers prefab integration in room-and-corridor style maps, as well as the elements that go into constructing an individual prefab itself. <\/em><\/p>\n<h2>Uses<\/h1>\n<p>Carving skulls and other fun shapes from the map isn&#8217;t entirely what I meant by &#8220;character.&#8221; Prefabs are ideal for more functional layouts that fit specific needs of a game, like special NPC and plot-related areas.<\/p>\n<p>I don&#8217;t want to rely on &#8220;finding&#8221; the right place in a map for a certain encounter to occur. I&#8217;ll just build it.<\/p>\n<div id=\"attachment_820\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_base.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-820\" class=\"size-full wp-image-820 \" title=\"Dungeon Prefabs: Hall\" alt=\"prefab_base\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_base.png\" width=\"500\" height=\"370\" \/><\/a><p id=\"caption-attachment-820\" class=\"wp-caption-text\">You meet a potential ally in the main hall and if he doesn&#8217;t like what you have to say his minions hanging out in side rooms ambush you, otherwise he lets you check out the secret weapon stash in the back. (Or: You use a terrain scanner to find that you can just blast\/drill a hole into the back room from another part of the map and take whatever you like ;)<\/p><\/div>\n<p>More or less the same method is used to add hand-crafted content to caves, although direct links are used instead of a tunneling algorithm so they don&#8217;t get out of control and take over the caves.<\/p>\n<div id=\"attachment_822\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_cavebase.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-822\" class=\"size-full wp-image-822 \" title=\"Dungeon Prefabs: Cave Base\" alt=\"prefab_cavebase\" src=\"https:\/\/www.gridsagegames.com\/blog\/gsg-content\/uploads\/2014\/06\/prefab_cavebase.png\" width=\"400\" height=\"600\" \/><\/a><p id=\"caption-attachment-822\" class=\"wp-caption-text\">Hm, we could walk in the front door&#8230; or not.<\/p><\/div>\n<p><em>This is the fifth in a five-part series on procedural maps:<\/em><\/p>\n<ul>\n<li><em>Part 1: <a title=\"Procedural Map Generation\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/06\/procedural-map-generation\/\">Procedural Map Generation<\/a><\/em><\/li>\n<li><em>Part 2: <a title=\"Mapgen: Tunneling Algorithm\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/06\/mapgen-tunneling-algorithm\/\">Tunneling Algorithm<\/a><em><\/em><\/em><\/li>\n<li><em>Part 3: <a title=\"Mapgen: Cellular Automata\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/06\/mapgen-cellular-automata\/\"><em>Cellular Automata<\/em><\/a><\/em><\/li>\n<li><em>Part 4: <a title=\"Dungeon Metrics\" href=\"http:\/\/www.gridsagegames.com\/blog\/2014\/07\/dungeon-metrics\/\"><em>Dungeon Metrics<\/em><\/a><\/em><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Procedurally generated maps are great, but even with variety factored into an algorithm it naturally won&#8217;t produce anything outside its parameters. This is good in that it keeps the style consistent, but individual areas sacrifice character as a result. Hand-crafted map pieces can restore some of that character where you really need it, be that [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":819,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,92],"tags":[4,76,82,84],"class_list":["post-815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-design","category-dev-series-procedural-maps","tag-cogmind","tag-map-generation","tag-prefabs","tag-rexpaint"],"_links":{"self":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts\/815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/comments?post=815"}],"version-history":[{"count":15,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions"}],"predecessor-version":[{"id":2433,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions\/2433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/media\/819"}],"wp:attachment":[{"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/media?parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/categories?post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gridsagegames.com\/blog\/wp-json\/wp\/v2\/tags?post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}