<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Procedural Generation &#8211; Tom Francis Regrets This Already</title>
	<atom:link href="https://www.pentadact.com/tag/procedural-generation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.pentadact.com</link>
	<description>We&#039;re back on a default theme because comments broke on my custom one and I don&#039;t have the energy to figure out why</description>
	<lastBuildDate>Mon, 02 Oct 2023 20:26:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Generating Locks And Keys In Heat Signature&#8217;s Ships</title>
		<link>https://www.pentadact.com/2015-11-28-generating-locks-and-keys-in-heat-signatures-ships/</link>
					<comments>https://www.pentadact.com/2015-11-28-generating-locks-and-keys-in-heat-signatures-ships/#comments</comments>
		
		<dc:creator><![CDATA[Pentadact]]></dc:creator>
		<pubDate>Sat, 28 Nov 2015 00:33:47 +0000</pubDate>
				<category><![CDATA[Game development]]></category>
		<category><![CDATA[Heat Signature]]></category>
		<category><![CDATA[Procedural Generation]]></category>
		<guid isPermaLink="false">http://www.pentadact.com/?p=8354</guid>

					<description><![CDATA[My summary of where we are after the last ship-generation post would be: The Drunk Snake is probably the best algorithm so far, for generating the amount of branching and length of critical path we want while looking fairly pleasing. But! There&#8217;s a lot of room for improvement. But! Improvement is getting harder: we don&#8217;t [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>My summary of where we are after <a href="https://www.pentadact.com/2015-11-26-laying-out-heat-signatures-ships-snakey-vs-branchy/">the last ship-generation post</a> would be:</p>
<ul>
<li>The Drunk Snake is probably the best algorithm so far, for generating the amount of branching and length of critical path we want while looking fairly pleasing.</li>
<li>But! There&#8217;s a lot of room for improvement.</li>
<li>But! Improvement is getting harder: we don&#8217;t have a huge amount of control with these types of algorithms, so we can&#8217;t fine-tune things precisely without a big rewrite.</li>
<li>And! We don&#8217;t know enough about our requirements to get really fussy yet &#8211; maybe some things that seem bad now will be good when we have certain security devices or guard patrols in.</li>
</ul>
<p><span id="more-8354"></span></p>
<p>In other words, it&#8217;s not worth getting tunnel vision and tinkering with layout algorithms until we start fleshing out the systems and elements they&#8217;re meant to support.</p>
<p>The most basic one of these is locked doors and keys. The keys and even the doors are partly placeholders: some will literally be keycards and locked doors, but instead of some keycards we might put a terminal that can override things of that security level, and instead of some doors we might put a security camera that needs to be turned off.</p>
<p>I&#8217;ve had some version of that system in there since the first post, but it was literally dumping they keys in front of the doors. I wanted them placed in dead ends off the beaten track, so I can put security measures on them.</p>
<p>This turns out to be harder than it sounds. I want an early sector to branch off in three directions &#8211; two are dead ends with keycards behind various obstacles, and the third is the locked door either could open. I don&#8217;t want <em>exactly</em> that every time, obviously, but that kind of thing.</p>
<p>But because we generate as we go, at the time we place the next sector along, we don&#8217;t know whether there&#8217;ll be other branches coming from the last one, or if this is the only path. It could be like this sector, whose phallic shape allows for two keycards to be placed in easy reach:</p>
<p><a href="https://www.pentadact.com/wp-content/Two-keys-and-a-door.png"><img fetchpriority="high" decoding="async" src="https://www.pentadact.com/wp-content/Two-keys-and-a-door.png" alt="Two keys and a door" width="395" height="255" class="aligncenter size-full wp-image-8356" srcset="https://www.pentadact.com/wp-content/Two-keys-and-a-door.png 395w, https://www.pentadact.com/wp-content/Two-keys-and-a-door-178x115.png 178w" sizes="(max-width: 395px) 100vw, 395px" /></a></p>
<p>Or this one, which did not branch at all before the door that leads to the rest of the ship.</p>
<p><a href="https://www.pentadact.com/wp-content/No-keys-no-branches.png"><img decoding="async" src="https://www.pentadact.com/wp-content/No-keys-no-branches.png" alt="No keys, no branches" width="531" height="428" class="aligncenter size-full wp-image-8355" srcset="https://www.pentadact.com/wp-content/No-keys-no-branches.png 531w, https://www.pentadact.com/wp-content/No-keys-no-branches-178x143.png 178w, https://www.pentadact.com/wp-content/No-keys-no-branches-500x403.png 500w" sizes="(max-width: 531px) 100vw, 531px" /></a></p>
<p>The Drunk Snake places all the sectors that form the longest path first, and only afterwards does it look for room to make branching paths. The Branching Algorithm is not much better: it&#8217;ll let the first sector branch first, but after that it&#8217;s effectively random.</p>
<p>Long story short, it gets very tricky if you want to place keys and locks at the same time you place the sectors. It was pretty clear that &#8216;Security&#8217; needed to be added in a second pass, after the basic geometry of the ship has been generated.</p>
<p>In case I haven&#8217;t made it clear yet, keys and doors work on Security Levels: a Security 3 Key can open Security 3 doors as well as Security 2 and 1. And they&#8217;re reusable. If you had one Security 9 key, you could open every door on the ship with it.</p>
<p>I&#8217;ll spare you my false start at this and skip to the algorithm that worked. What we&#8217;re doing kind of involves pathfinding &#8211; to ensure there&#8217;s a route to Key 2 that doesn&#8217;t go through any Lock 2 doors. But it would be complicated to integrate it with Game Maker&#8217;s pathfinding systems or to write my own, so I basically do it by making lots of lists.</p>
<p>We place the first sector as normal. But when we join a second sector onto it, we tell that sector to remember that &#8216;Sector 1&#8217; is one of the ones you have to go through to get here. When we join something onto Sector 2, it copies Sector 2&#8217;s list of sectors-you-have-to-go-through, and adds Sector 2 to it. So every sector has a list of every other sector you need to go through to get to it.</p>
<p>Once the whole ship is generated, we go through the sectors and make a list of all the ones that are dead ends.</p>
<p>Then, until we run out of dead ends, we:</p>
<ul>
<li>Find the nearest two dead ends &#8211; the ones with the fewest &#8216;sectors you have to go through&#8217;.</li>
<li>Remove them from the list.</li>
<li>Put a keycard of security level S in each.</li>
<li>Tell every sector that leads to either of those dead ends: your security level is fixed now.</li>
<li>For all sectors whose security level is not fixed yet, upgrade them to security level S.</li>
<li>Increase S.</li>
<li>Do it all again.</li>
</ul>
<p>Lastly, we go through every door in the ship and tell it: your security level is equal to the highest of the two sectors you&#8217;re between. So if you join a Sec 1 to a Sec 2, you are a Sec 2 door.</p>
<p>This works! Look!</p>
<div class="VideoWrapper"><iframe width="1280" height="720" src="https://www.youtube-nocookie.com/embed/sPcn8LWKT5o?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe></div>
<p>Next I should either try adding hazards &#8211; like security cameras or specially placed guards &#8211; or I should put all the functional modules back in and check it still works: thrusters, cockpit, etc.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.pentadact.com/2015-11-28-generating-locks-and-keys-in-heat-signatures-ships/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>Laying Out Heat Signature&#8217;s Ships: Snakey Vs Branchy</title>
		<link>https://www.pentadact.com/2015-11-26-laying-out-heat-signatures-ships-snakey-vs-branchy/</link>
					<comments>https://www.pentadact.com/2015-11-26-laying-out-heat-signatures-ships-snakey-vs-branchy/#comments</comments>
		
		<dc:creator><![CDATA[Pentadact]]></dc:creator>
		<pubDate>Thu, 26 Nov 2015 00:29:47 +0000</pubDate>
				<category><![CDATA[Game development]]></category>
		<category><![CDATA[Heat Signature]]></category>
		<category><![CDATA[Procedural Generation]]></category>
		<guid isPermaLink="false">http://www.pentadact.com/?p=8323</guid>

					<description><![CDATA[Last time I covered how I taught Heat Signature to build ships out of sectors, join those sectors together, lock some of those doors, then place keycards in the right places to ensure they&#8217;re all openable. I&#8217;d got the algorithm generating layouts like this, which is great: But as I said at the end of [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Last time I covered <a href="https://www.pentadact.com/2015-11-14-teaching-heat-signatures-ship-generator-to-think-in-sectors/">how I taught Heat Signature to build ships out of sectors</a>, join those sectors together, lock some of those doors, then place keycards in the right places to ensure they&#8217;re all openable. I&#8217;d got the algorithm generating layouts like this, which is great:<span id="more-8323"></span></p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey.png" alt="Runner 2015-11-13 18-50-07-72 with security doors, snakey" width="1133" height="654" class="aligncenter size-full wp-image-8312" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey.png 1133w, https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey-178x103.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey-500x289.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey-1024x591.png 1024w" sizes="auto, (max-width: 1133px) 100vw, 1133px" /></a></p>
<p>But as I said at the end of the post, there might be a problem with this layout. Here&#8217;s the route you&#8217;d have to take to get from the airlock to the front of the ship:</p>
<p><a href="https://www.pentadact.com/wp-content/Snakey-Route.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Snakey-Route.png" alt="Snakey Route" width="840" height="704" class="aligncenter size-full wp-image-8324" srcset="https://www.pentadact.com/wp-content/Snakey-Route.png 840w, https://www.pentadact.com/wp-content/Snakey-Route-178x149.png 178w, https://www.pentadact.com/wp-content/Snakey-Route-500x419.png 500w" sizes="auto, (max-width: 840px) 100vw, 840px" /></a></p>
<h5>The Snaking Algorithm</h5>
<p>That long, snakey, back-and-forth route is common to a lot of ships this code generates, and it comes from the order in which it places the sectors. It starts with one at the airlock, then tries to surround it with new sectors. But! I also wanted each of those sectors to be surrounded too, so as soon as it creates the first one, it tries to surround that. And as soon as it places the first surrounding sector, it tries to surround that one too.</p>
<p>If you keep trying to surround the last sector you placed, what you&#8217;re really doing is placing sectors one after the other in a line. And since we connect each sector we place to the last one we put down, we end up making one long route that weaves back and forth across the ship.</p>
<p>There are a few possible problems with this:</p>
<ul>
<li>It&#8217;s obviously inefficient for the crew of the ship, though that&#8217;s not necessarily a major problem.</li>
<li>A bigger concern is that the player might feel they&#8217;re being messed around, that the layout is contrived to take up their time.</li>
<li>And the biggest one is that this long, linear path doesn&#8217;t lead to much branching &#8211; a few little twiglets sprout off here and there, but usually only one at a time. That doesn&#8217;t give me a lot of places to put keycards: ideally, before every locked door, I want to place two different key-type things that let the player open it, and put different types of hazards or obstacles in front of them. That way, the player has a choice of challenges.</li>
</ul>
<p>I call this the <strong>Snaking Algorithm</strong>, because it tends to create one long and winding snakey path. Since my biggest concern was the lack of branching, I tried to come up with a new one that would focus on that.</p>
<h5>The Branching Algorithm</h5>
<p>The snaking, as I say, comes from trying to surround each sector as soon as it&#8217;s created. So I took that part out, and just let the algorithm finish surrounding that first sector.</p>
<p>That gives you lots of branching, but obviously doesn&#8217;t fill the whole ship. At some point, it&#8217;s got to decide which of the remaining sectors to try to surround next. So I defaulted to what I always default to: random.</p>
<p>It goes through all sectors that haven&#8217;t been surrounded yet, picks one at random, and surrounds it. Since we make doorways between sectors at the time we join them on, this gives the early sectors it picks lots of branches. But then as the ship fills up, it has less and less room to place new sectors around the one it&#8217;s picked, and so those later sectors have fewer branches. But where those are on the ship is pretty random.</p>
<p>Once every sector has had its turn being surrounded, we&#8217;re done.</p>
<p><a href="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-3.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-3.png" alt="Branching Ship Sectors 3" width="1253" height="742" class="aligncenter size-full wp-image-8327" srcset="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-3.png 1253w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-3-178x105.png 178w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-3-500x296.png 500w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-3-1024x606.png 1024w" sizes="auto, (max-width: 1253px) 100vw, 1253px" /></a></p>
<p>Nice!</p>
<p><a href="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-2.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-2.png" alt="Branching Ship Sectors 2" width="848" height="574" class="aligncenter size-full wp-image-8328" srcset="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-2.png 848w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-2-178x120.png 178w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-2-500x338.png 500w" sizes="auto, (max-width: 848px) 100vw, 848px" /></a></p>
<p>Cool!</p>
<p><a href="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-1.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-1.png" alt="Branching Ship Sectors 1" width="574" height="624" class="aligncenter size-full wp-image-8329" srcset="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-1.png 574w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-1-178x194.png 178w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-1-500x544.png 500w" sizes="auto, (max-width: 574px) 100vw, 574px" /></a></p>
<p>Well! You can see pretty clearly here that the sector the player&#8217;s ship is docked with, in the bottom right, was surrounded by other sectors &#8211; and joined to all of them &#8211; before anything else.</p>
<p><a href="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-4.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-4.png" alt="Branching Ship Sectors 4" width="858" height="465" class="aligncenter size-full wp-image-8326" srcset="https://www.pentadact.com/wp-content/Branching-Ship-Sectors-4.png 858w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-4-178x96.png 178w, https://www.pentadact.com/wp-content/Branching-Ship-Sectors-4-500x271.png 500w" sizes="auto, (max-width: 858px) 100vw, 858px" /></a></p>
<p>And now I&#8217;m starting to see the problem.</p>
<h5>The Problem</h5>
<p>On anything but a tiny ship, branching a lot early on ends up leading to multiple long paths.</p>
<p><a href="https://www.pentadact.com/wp-content/Branching-Routes.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Branching-Routes.png" alt="Branching Routes" width="858" height="465" class="aligncenter size-full wp-image-8331" srcset="https://www.pentadact.com/wp-content/Branching-Routes.png 858w, https://www.pentadact.com/wp-content/Branching-Routes-178x96.png 178w, https://www.pentadact.com/wp-content/Branching-Routes-500x271.png 500w" sizes="auto, (max-width: 858px) 100vw, 858px" /></a></p>
<p>This clashes a bit with our policy of &#8220;place multiple keys protected by varied hazards before placing a locked door&#8221;. What kind of keys and doors do we place along these multiple parallel paths? Either:</p>
<p><strong>1.</strong> We have multiple parallel tracks of level 1 key > level 1 door > level 2 key > etc.<br />
<strong>2.</strong> Or we have only one track like that, and all the others start with higher sec doors &#8211; level 6 or so &#8211; ones you don&#8217;t get the key for until you reach the end of the first path.</p>
<p>Neither option appeals much. The first feels redundant, messy, and an inefficient use of space &#8211; we&#8217;d need very big ships to ensure one path is long enough to be interesting, and big ships are daunting and expensive performance-wise. The second involves a lot of backtracking, and makes the critical path &#8211; Where You Have To Go &#8211; almost impossible to read without meticulous examination. I tried to design a set of keys and doors for a big Branching ship by hand, and it was laborious even to draw:</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-door-sec-level-mockup-colour-coded.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-door-sec-level-mockup-colour-coded.png" alt="Heat Signature door sec level mockup colour coded" width="787" height="668" class="aligncenter size-full wp-image-8332" srcset="https://www.pentadact.com/wp-content/Heat-Signature-door-sec-level-mockup-colour-coded.png 787w, https://www.pentadact.com/wp-content/Heat-Signature-door-sec-level-mockup-colour-coded-178x151.png 178w, https://www.pentadact.com/wp-content/Heat-Signature-door-sec-level-mockup-colour-coded-500x424.png 500w" sizes="auto, (max-width: 787px) 100vw, 787px" /></a></p>
<p>The more ways the Branching Algorithm clashed with my plans for keys and locks, the more I thought &#8220;Boy, that Snaking Algorithm really wasn&#8217;t far off.&#8221;</p>
<h5>Tweaking The Snake</h5>
<p>So the Snake&#8217;s problems were a) an almost dickish determination to take you on the longest possible route to your objective, and b) not enough branching to place multiple keys before a locked door. But maybe these are fixable. Like everything at this early stage, I wrote every step of this code in whatever way was easy, simple and short, so there are loads of biases and cheats in it.</p>
<p>I looked for the easiest one to mess with, and it&#8217;s this: when surrounding a sector, it always tries placing them above and below, then switches to looking down both sides. To be more &#8216;true random&#8217;, it should find all the adjacent modules and then pick a random one to start a sector from. But even that seemed too much like hard work to me, so first I wanted to test if this ordering stuff even made much of a difference. There is one <em>super</em> easy way to do that: switch those two bits of code round. Try placing sectors along the sides, <em>then</em> try above and below. I give you <strong>The Sidewinder</strong>:</p>
<p><a href="https://www.pentadact.com/wp-content/Sidewinder-layout.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Sidewinder-layout.png" alt="Sidewinder layout" width="1072" height="545" class="aligncenter size-full wp-image-8335" srcset="https://www.pentadact.com/wp-content/Sidewinder-layout.png 1072w, https://www.pentadact.com/wp-content/Sidewinder-layout-178x90.png 178w, https://www.pentadact.com/wp-content/Sidewinder-layout-500x254.png 500w, https://www.pentadact.com/wp-content/Sidewinder-layout-1024x521.png 1024w" sizes="auto, (max-width: 1072px) 100vw, 1072px" /></a></p>
<p>It&#8217;s snakey, but it&#8217;s trying to snake lengthwise.</p>
<p><a href="https://www.pentadact.com/wp-content/Sidewinder-path.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Sidewinder-path.png" alt="Sidewinder path" width="1072" height="545" class="aligncenter size-full wp-image-8336" srcset="https://www.pentadact.com/wp-content/Sidewinder-path.png 1072w, https://www.pentadact.com/wp-content/Sidewinder-path-178x90.png 178w, https://www.pentadact.com/wp-content/Sidewinder-path-500x254.png 500w, https://www.pentadact.com/wp-content/Sidewinder-path-1024x521.png 1024w" sizes="auto, (max-width: 1072px) 100vw, 1072px" /></a></p>
<p>And right away this answers lots of questions. Firstly: yep, this makes a huge difference. This ship is nuts. And secondly: look! Branching! Enough? Too much? Dunno! But it&#8217;s worth taking the next step.</p>
<p>I&#8217;m still too lazy to do true random selection of adjacent modules, so I came up with another super easy trick: instead of always doing vertical first, or always doing horizontal first, it flips a coin. And because this one piece of code is run again for every module, the coin flip will mean some snake horizontally and others vertically. I give you: <strong>The Drunk Snake Algorithm</strong>.</p>
<p><a href="https://www.pentadact.com/wp-content/Small-Drunk-Snake.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Small-Drunk-Snake.png" alt="Small Drunk Snake" width="1440" height="900" class="aligncenter size-full wp-image-8340" srcset="https://www.pentadact.com/wp-content/Small-Drunk-Snake.png 1440w, https://www.pentadact.com/wp-content/Small-Drunk-Snake-178x111.png 178w, https://www.pentadact.com/wp-content/Small-Drunk-Snake-500x313.png 500w, https://www.pentadact.com/wp-content/Small-Drunk-Snake-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>That&#8217;s lovely, but small ships almost always are with sector systems, I&#8217;m finding.</p>
<p><a href="https://www.pentadact.com/wp-content/Large-Drunk-Snake.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Large-Drunk-Snake.png" alt="Large Drunk Snake" width="1440" height="900" class="aligncenter size-full wp-image-8339" srcset="https://www.pentadact.com/wp-content/Large-Drunk-Snake.png 1440w, https://www.pentadact.com/wp-content/Large-Drunk-Snake-178x111.png 178w, https://www.pentadact.com/wp-content/Large-Drunk-Snake-500x313.png 500w, https://www.pentadact.com/wp-content/Large-Drunk-Snake-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>This huge one is a bit ugly, but just because it picked a lot of 3&#215;1 rooms all next to each other &#8211; I may bias it against that. But pathwise, it&#8217;s surprisingly good &#8211; the critical path is not dickishly circuitous, and there&#8217;s a good amount of branching along the way. There&#8217;s a huge amount of path <em>after</em> the objective, but I don&#8217;t know yet if that&#8217;s bad. </p>
<p><a href="https://www.pentadact.com/wp-content/Large-Drunk-Snake-Paths.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Large-Drunk-Snake-Paths.png" alt="Large Drunk Snake Paths" width="1440" height="900" class="aligncenter size-full wp-image-8338" srcset="https://www.pentadact.com/wp-content/Large-Drunk-Snake-Paths.png 1440w, https://www.pentadact.com/wp-content/Large-Drunk-Snake-Paths-178x111.png 178w, https://www.pentadact.com/wp-content/Large-Drunk-Snake-Paths-500x313.png 500w, https://www.pentadact.com/wp-content/Large-Drunk-Snake-Paths-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>My next step involved giving every sector a &#8216;distance&#8217; value: how many sectors do you have to go through to get to this one? So the airlock sector is 0, any attached to it are 1, and so on. They usually go up to about 8, on a medium ship. Then I boarded one and saw the number <em>23</em>. I thought it was a bug at first, but then I traced the route, and no, the Drunk Snake is just a dick sometimes:</p>
<p><a href="https://www.pentadact.com/wp-content/Dickish-Drunk-Snake.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Dickish-Drunk-Snake.png" alt="Dickish Drunk Snake" width="835" height="665" class="aligncenter size-full wp-image-8337" srcset="https://www.pentadact.com/wp-content/Dickish-Drunk-Snake.png 835w, https://www.pentadact.com/wp-content/Dickish-Drunk-Snake-178x142.png 178w, https://www.pentadact.com/wp-content/Dickish-Drunk-Snake-500x398.png 500w" sizes="auto, (max-width: 835px) 100vw, 835px" /></a></p>
<p>I actually love that layout. And it gave me an idea: these distance values could also be used to spot good places for a shortcut. So if this sector is at distance 14, but it&#8217;s right next to one that has distance 3, maybe we just make a door. Maybe it&#8217;s locked. Maybe it has a hazard on it. Dunno! That&#8217;s what I&#8217;m gonna play with next.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.pentadact.com/2015-11-26-laying-out-heat-signatures-ships-snakey-vs-branchy/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>Teaching Heat Signature&#8217;s Ship Generator To Think In Sectors</title>
		<link>https://www.pentadact.com/2015-11-14-teaching-heat-signatures-ship-generator-to-think-in-sectors/</link>
					<comments>https://www.pentadact.com/2015-11-14-teaching-heat-signatures-ship-generator-to-think-in-sectors/#comments</comments>
		
		<dc:creator><![CDATA[Pentadact]]></dc:creator>
		<pubDate>Sat, 14 Nov 2015 21:40:19 +0000</pubDate>
				<category><![CDATA[Game development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Heat Signature]]></category>
		<category><![CDATA[Procedural Generation]]></category>
		<guid isPermaLink="false">http://www.pentadact.com/?p=8300</guid>

					<description><![CDATA[I haven&#8217;t talked about the way I randomly generate spaceships in Heat Signature since this post &#8211; before it even had actual art. That&#8217;s partly because I&#8217;ve barely touched it since then. I showed the game to developer friends and the press in LA and SF a few weeks ago, and got lots of great [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I haven&#8217;t talked about the way I randomly generate spaceships in Heat Signature since <a href="https://www.pentadact.com/2014-07-19-improving-heat-signatures-randomly-generated-ships-inside-and-out/">this post</a> &#8211; before it even had actual art. That&#8217;s partly because I&#8217;ve barely touched it since then. I showed the game to developer friends and the press in LA and SF a few weeks ago, and got lots of great input and ideas, but the main thing I came away thinking was: the on-board game needs to be more interesting. And I think better ship interiors are the foundation of that.<span id="more-8300"></span></p>
<p>So that&#8217;s why I was <a href="https://www.pentadact.com/2015-11-08-what-works-and-why-multiple-routes-in-deus-ex/">replaying the Deus Ex games</a> recently. My conclusions from that combined with two other ideas I&#8217;d been having about how to improve ship generation, namely:</p>
<p><strong>1.</strong> Getting from the airlock to your objective should involve a series of Gates and Keys. For each locked Gate you encounter, there&#8217;s a corresponding Key somewhere in the area you can access, and fighting/hacking/sneaking your way to that is how you progress.</p>
<p><strong>2.</strong> Whenever I sketch out what a cool ship interior might look like, I draw it as a series of little bubbles of space, about 3-6 modules each. One might be a long room, another might be a row of rooms, another might just be corridors that connect the rest. I call them Sectors. It feels like these lead to natural/pleasing/readable ship layouts &#8211; can I teach the game to build them this way?</p>
<p><a href="https://www.pentadact.com/wp-content/Ship-made-of-sectors-sketh.jpg"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Ship-made-of-sectors-sketh.jpg" alt="Ship made of sectors - sketh" width="2307" height="2165" class="aligncenter size-full wp-image-8302" srcset="https://www.pentadact.com/wp-content/Ship-made-of-sectors-sketh.jpg 2307w, https://www.pentadact.com/wp-content/Ship-made-of-sectors-sketh-178x167.jpg 178w, https://www.pentadact.com/wp-content/Ship-made-of-sectors-sketh-500x469.jpg 500w, https://www.pentadact.com/wp-content/Ship-made-of-sectors-sketh-1024x961.jpg 1024w" sizes="auto, (max-width: 2307px) 100vw, 2307px" /></a></p>
<p>And the relevant conclusions from my Deus Ex replay are:</p>
<p><strong>3.</strong> The player needs multiple routes to their objective.</p>
<p><strong>4.</strong> Those routes must be blocked by different obstacles, which require different methods to get past.</p>
<p>There&#8217;s some <a href="https://www.pentadact.com/2015-11-08-what-works-and-why-multiple-routes-in-deus-ex/">other stuff</a>, but that&#8217;s what&#8217;s relevant to ship layout.</p>
<p>The first two are more instinct than rigorous logic: I feel like 1 will make the ships feel more like &#8216;levels&#8217;, and I think that&#8217;s more positive than it sounds: right now they feel like random, empty mazes &#8211; to use an even less liked term, they don&#8217;t feel like &#8216;content&#8217;. And they need to &#8211; if each ship isn&#8217;t a fun little challenge, the game has nothing at its core.</p>
<p>And 2 is my best guess at how to combat the corresponding visual &#8216;blah&#8217; factor: they <em>look</em> like random mazes, and I want them to look more designed.</p>
<h5>Teaching the computer to think in Sectors</h5>
<p>Checking all these boxes is a massively complicated challenge both technically and creatively, so I tried to start as simple as possible. Let&#8217;s just have one type of Sector for now: a 3&#215;1 room. Can you build a ship out of these?</p>
<p>The two neat features of my current ship generation algorithm are:</p>
<p><strong>a)</strong> The interior layout always fills the whole ship<br />
<strong>b)</strong> You can always get from every module to every other module</p>
<p>a) would be tricky with only 3&#215;1 sectors, but should be doable with sectors in general &#8211; we just let one of the Sector types be a 1&#215;1 module and then any gaps are fillable.</p>
<p>b) sounds tricky, but actually I&#8217;m already fulfilling it in the sketches I draw, and the way I draw them is the key to teaching the computer to do it. I start by drawing one Sector, then draw another adjacent to it, then new ones adjacent to those, and so on. If I created a doorway from the existing sector to the new one I&#8217;m drawing each time, every sector would have a route back to the start, and therefore every sector has a route to every other.</p>
<p>So after tinkering for a bit, I got the algorithm to do this:</p>
<p><a href="https://www.pentadact.com/wp-content/First-Sector.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/First-Sector.png" alt="First Sector" width="1440" height="900" class="aligncenter size-full wp-image-8304" srcset="https://www.pentadact.com/wp-content/First-Sector.png 1440w, https://www.pentadact.com/wp-content/First-Sector-178x111.png 178w, https://www.pentadact.com/wp-content/First-Sector-500x313.png 500w, https://www.pentadact.com/wp-content/First-Sector-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>And then this:</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-10-18-36-05-72-first-ship-made-of-sectors.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-10-18-36-05-72-first-ship-made-of-sectors.png" alt="Runner 2015-11-10 18-36-05-72 first ship made of sectors" width="1440" height="900" class="aligncenter size-full wp-image-8303" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-10-18-36-05-72-first-ship-made-of-sectors.png 1440w, https://www.pentadact.com/wp-content/Runner-2015-11-10-18-36-05-72-first-ship-made-of-sectors-178x111.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-10-18-36-05-72-first-ship-made-of-sectors-500x313.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-10-18-36-05-72-first-ship-made-of-sectors-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>Great! They&#8217;re not connected yet, and they all tend to point in the same direction, but this is promising. The little 1&#215;1 rooms are spaces where it couldn&#8217;t fit a 3&#215;1 sector, in the order that they were laid. It&#8217;s definitely possible to do a better job of it than that, but that&#8217;s irrelevant &#8211; those little pockets look nice, I want them. If they were all clustered in one corner it&#8217;d look bad, but randomly dotted around like that is great.</p>
<p>So next, remove that direction bias. It&#8217;s happening because the code tries to place the sector lengthwise, and then if it doesn&#8217;t fit, goes through each possible rotation in turn. Since it always tries them in the same order, you end up with a lot of lengthwise ones. I tweaked it to try the rotations in a random order, producing this:</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-11-15-02-41-12-fixred-bias.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-11-15-02-41-12-fixred-bias.png" alt="Runner 2015-11-11 15-02-41-12 fixred bias" width="1440" height="798" class="aligncenter size-full wp-image-8308" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-11-15-02-41-12-fixred-bias.png 1440w, https://www.pentadact.com/wp-content/Runner-2015-11-11-15-02-41-12-fixred-bias-178x99.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-11-15-02-41-12-fixred-bias-500x277.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-11-15-02-41-12-fixred-bias-1024x567.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>Lovely!</p>
<p>Now we need to connect them. As I say, it seems like you could just do this each time you place one: connect it to the old one. It&#8217;s a little trickier than it sounds to find the co-ords of the two modules in question (we need to know which modules to link, not just which sectors), but I got something logical working:</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-11-16-48-59-17-conneced-sectors.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-11-16-48-59-17-conneced-sectors.png" alt="Runner 2015-11-11 16-48-59-17 conneced sectors" width="1440" height="900" class="aligncenter size-full wp-image-8309" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-11-16-48-59-17-conneced-sectors.png 1440w, https://www.pentadact.com/wp-content/Runner-2015-11-11-16-48-59-17-conneced-sectors-178x111.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-11-16-48-59-17-conneced-sectors-500x313.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-11-16-48-59-17-conneced-sectors-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>I actually don&#8217;t know <em>why</em> this works so well. My connect-as-you-go concept assumes that every module is part of some sector, but at this stage those 1&#215;1 bits aren&#8217;t part of any sector &#8211; they&#8217;re just leftovers. I don&#8217;t quite have a good enough handle on my own code to tell you how it knows to link those up too, but it does.</p>
<p>So now I need to do some messy replumbing: right now we&#8217;re working with a single fixed sector size, but obviously I want a variety of sectors. After some deliberating, I decided to make each Sector type an object &#8211; a sort of invisible template the ship can refer to when creating itself. The template for each sector could store what its dimensions are, and what kinds of modules it contains.</p>
<p>Making those is easy, but having the algorithm read them in, rotate them to try 8 different orientations, then actually place them is all rather fiddly. For now I&#8217;ve settled on a slightly rigid system, where a Sector can either be a &#8216;Big Room&#8217; or &#8216;Corridors&#8217; or &#8216;Small Rooms&#8217;, but it can&#8217;t specify an arrangement of multiple elements &#8211; like one small room surrounded by corridors, for example. Supporting that would add a lot of complexity, so I decided to leave it until I&#8217;m really sure I need it.</p>
<p>So, with the new Sector templates in &#8211; just 3&#215;1 and 1&#215;1 for now &#8211; how does it look?</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-12-17-05-11-01-not-filled-and-not-connected.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-12-17-05-11-01-not-filled-and-not-connected.png" alt="Runner 2015-11-12 17-05-11-01 not filled and not connected" width="1440" height="688" class="aligncenter size-full wp-image-8307" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-12-17-05-11-01-not-filled-and-not-connected.png 1440w, https://www.pentadact.com/wp-content/Runner-2015-11-12-17-05-11-01-not-filled-and-not-connected-178x85.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-12-17-05-11-01-not-filled-and-not-connected-500x239.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-12-17-05-11-01-not-filled-and-not-connected-1024x489.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>Oh, it&#8217;s broken. Parts of this layout are OK, but it fails both our conditions: doesn&#8217;t fill the ship, and the bits it does fill aren&#8217;t all connected to each other. Doesn&#8217;t make sense as a ship.</p>
<p>This, and a similar glitch, took me about a day to solve. I kept thinking there was some flaw in the way I&#8217;d implemented &#8216;connect as you go&#8217; that could lead to a Sector being created but not connected to the previous one. As it turned out, the reason I couldn&#8217;t find a flaw in this code is that it was exactly right. I just had two very stupid, unrelated mistakes that both caused very similar symptoms, and kept looking like one thing.</p>
<p>a) I&#8217;d created a 3&#215;1 &#8216;Corridor&#8217; sector, but forgot to tell each module of it to link to the next &#8211; it wasn&#8217;t internally connected. The connections to other sectors were fine.</p>
<p>b) I&#8217;d set the dimension values of the 1&#215;1 Sector to 1&#215;3. This is incorrect. Maths tells us that 1 = 1 and not 3, so that 3 should be 1, so that it reads &#8216;1&#215;1&#8217;, because one is not three, in fact it is less. Stop me if I&#8217;m going too fast.</p>
<p>Fixed these, and blam:</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-13-16-04-18-10-big-ship-with-fixed-connections.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-13-16-04-18-10-big-ship-with-fixed-connections.png" alt="Runner 2015-11-13 16-04-18-10 big ship with fixed connections" width="1289" height="867" class="aligncenter size-full wp-image-8311" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-13-16-04-18-10-big-ship-with-fixed-connections.png 1289w, https://www.pentadact.com/wp-content/Runner-2015-11-13-16-04-18-10-big-ship-with-fixed-connections-178x120.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-13-16-04-18-10-big-ship-with-fixed-connections-500x336.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-13-16-04-18-10-big-ship-with-fixed-connections-1024x689.png 1024w" sizes="auto, (max-width: 1289px) 100vw, 1289px" /></a></p>
<p>Blam is the sound of a ship being generated with a connected and spanning interior graph:</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-13-16-05-26-09-small-ship-with-fixed-connections.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-13-16-05-26-09-small-ship-with-fixed-connections.png" alt="Runner 2015-11-13 16-05-26-09 small ship with fixed connections" width="1440" height="900" class="aligncenter size-full wp-image-8313" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-13-16-05-26-09-small-ship-with-fixed-connections.png 1440w, https://www.pentadact.com/wp-content/Runner-2015-11-13-16-05-26-09-small-ship-with-fixed-connections-178x111.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-13-16-05-26-09-small-ship-with-fixed-connections-500x313.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-13-16-05-26-09-small-ship-with-fixed-connections-1024x640.png 1024w" sizes="auto, (max-width: 1440px) 100vw, 1440px" /></a></p>
<p>This is looking great to me, especially on smaller ships. So, on to Gates and Keys!</p>
<h5>On, indeed, to Gates and Keys</h5>
<p>Again I wanted to start as simple as possible. Some ships will play host to a particular mission with a specific objective, but for any that don&#8217;t, we should default to treating the ship&#8217;s cockpit as the &#8216;objective&#8217; &#8211; it&#8217;s the thing they&#8217;d most want to protect.</p>
<p>Because we generate as we go, we don&#8217;t actually know how far along your path to the objective we are when we place a Sector. But we can fudge it: if the next sector is physically closer to the objective&#8217;s location, then we increase the security level of the door we&#8217;re placing between them. And to ensure you can open it, we put a keycard of the same level somewhere in the previous sector. Again, for now, I went ultra-basic: it dumps it right in front of the door.</p>
<p><a href="https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey.png" alt="Runner 2015-11-13 18-50-07-72 with security doors, snakey" width="1133" height="654" class="aligncenter size-full wp-image-8312" srcset="https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey.png 1133w, https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey-178x103.png 178w, https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey-500x289.png 500w, https://www.pentadact.com/wp-content/Runner-2015-11-13-18-50-07-72-with-security-doors-snakey-1024x591.png 1024w" sizes="auto, (max-width: 1133px) 100vw, 1133px" /></a></p>
<p>This works! You can&#8217;t see them well, but those black square outlines in some modules are where keycards are placed, and some are placed less gracefully in corridors and stuff. The level it generates is always completable, though obviously not challenging yet.</p>
<p>So we need to move those keycards to more secluded locations, so that we can put obstacles between the player and them: enemies, security, etc. But before I put a lot of work into ensuring that can happen, I wanted to look into a possible worry with the kind of layout this is generating. And since this has taken a while to write up already, I&#8217;ll save that for the next post!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.pentadact.com/2015-11-14-teaching-heat-signatures-ship-generator-to-think-in-sectors/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Improving Heat Signature&#8217;s Randomly Generated Ships, Inside And Out</title>
		<link>https://www.pentadact.com/2014-07-19-improving-heat-signatures-randomly-generated-ships-inside-and-out/</link>
					<comments>https://www.pentadact.com/2014-07-19-improving-heat-signatures-randomly-generated-ships-inside-and-out/#comments</comments>
		
		<dc:creator><![CDATA[Pentadact]]></dc:creator>
		<pubDate>Sat, 19 Jul 2014 12:23:55 +0000</pubDate>
				<category><![CDATA[Feature]]></category>
		<category><![CDATA[Game development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Heat Signature]]></category>
		<category><![CDATA[Procedural Generation]]></category>
		<guid isPermaLink="false">http://www.pentadact.com/?p=7264</guid>

					<description><![CDATA[I started making Heat Signature mainly to figure out if the mechanics would be as fun as they seemed in my head, so I built all its systems in the cheapest, fastest, simplest possible way. That worked &#8211; it&#8217;s now got to the point where I&#8217;m laughing out loud at something ridiculous happening most times [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I started making Heat Signature mainly to figure out if the mechanics would be as fun as they seemed in my head, so I built all its systems in the cheapest, fastest, simplest possible way. That worked &#8211; it&#8217;s now got to the point where I&#8217;m laughing out loud at something ridiculous happening most times I play.</p>
<p>But the slapdash way I built it has the following problems:<span id="more-7264"></span></p>
<ul>
<li>All collision checks, including guards checking whether they can see the player, are being done on a per-pixel basis. That means the game slows down a lot if there are many guards.</li>
<li>Pathfinding is done ahead of time, meaning <a href="https://www.pentadact.com/2014-02-22-thinking-about-pathfinding-in-heat-signatures-randomised-modularly-destructible-spaceships/">each ship calculates all possible routes within it every time its floorplan changes</a>. For very large ships, that causes slowdown when a missile takes a chunk out of it.</li>
<li>When things on a ship move or are created, they don&#8217;t have a good way of making sure they end up fixed in the right position on the ship, leading to lots of very tricky to diagnose bugs where airlocks appear in the wrong place and won&#8217;t let you inside.</li>
</ul>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Airlock-Problemns.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Airlock-Problemns.png" alt="Heat Signature Airlock Problemns" width="494" height="222" class="aligncenter size-full wp-image-7281" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Airlock-Problemns.png 494w, https://www.pentadact.com/wp-content/Heat-Signature-Airlock-Problemns-178x79.png 178w" sizes="auto, (max-width: 494px) 100vw, 494px" /></a></p>
<h5>The Rewrite</h5>
<p>All of these systems need a total rewrite, and I know how to make each one massively faster and more reliable now that I&#8217;ve had some experience with how they&#8217;ll be used. I&#8217;ve been working with the bad code for so long that I&#8217;m actually really excited to rip this awful shit out and make it all clean, fast and efficient.</p>
<div align="center">
<blockquote class="twitter-tweet" lang="en">
<p>A good way to get motivated about the boring task of redoing code is to just keep working with the bad code until you want to die.</p>
<p>&mdash; Heat Signature (@HeatSig) <a href="https://twitter.com/HeatSig/statuses/488300355730804737">July 13, 2014</a></p></blockquote>
<p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p></div>
<p>But I&#8217;m also aware that this means it will look like exactly the same game until I finish all three rewrites, which might be a while. So while I&#8217;m at it, I&#8217;m making some of the more superficial tweaks I&#8217;ve been planning, just to make the game feel fresh on the outside too. And the first of these are tweaks to the way ships randomly generate their interior floorplans.</p>
<h5>The Old Floor Plan Generator</h5>
<p><a href="https://www.pentadact.com/2014-02-07-randomly-generating-simple-spaceships-in-heat-signature/">I talked about how I built that system</a> at the time, and it&#8217;s really simple:</p>
<ol>
<li>All modules in a row have doors leading to each other</li>
<li>If there&#8217;s a row behind this one, one module in this row has a door leading to it</li>
<li>If a module has exactly two doors and they&#8217;re in a straight line, it&#8217;s a corridor. Otherwise, it&#8217;s a room.</li>
</ol>
<p>That generates interiors that look like this:</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Corridors.jpg"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Corridors.jpg" alt="Heat Signature Corridors" width="633" height="434" class="aligncenter size-full wp-image-6842" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Corridors.jpg 633w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-178x122.jpg 178w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-500x342.jpg 500w" sizes="auto, (max-width: 633px) 100vw, 633px" /></a></p>
<p>I was pretty pleased with this! From only three rules, it makes sure every module is used, every corridor leads to a room, and there&#8217;s a path from every module to every other, but it&#8217;s usually not trivial. Despite being simple, the pattern didn&#8217;t seem to be obvious &#8211; to me or others. I posted a shot on Twitter and asked people to figure out the rules &#8211; no-one got them right.</p>
<p>Its main shortcomings were:</p>
<ul>
<li>There are a lot of rooms, as opposed to corridors. Rooms obfuscate connections: it&#8217;s harder to see at a glance which ones are connected and which are blocked, which can make the layout visually boring even when it&#8217;s mechanically interesting.</li>
<li>It&#8217;s usually not mechanically interesting either. The fact that there&#8217;s only one logical route between any two rooms will probably be too boring and restrictive once we have more of the on-board game elements in, like sealed doors and hacking.</li>
</ul>
<h5>The New Floor Plan Generator</h5>
<p>So I made a few tweaks, and the new system generates stuff like this:</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Tweaked1.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Tweaked1.png" alt="Heat Signature Floorplan Tweaked" width="802" height="635" class="aligncenter size-full wp-image-7271" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Tweaked1.png 802w, https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Tweaked1-178x140.png 178w, https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Tweaked1-500x395.png 500w" sizes="auto, (max-width: 802px) 100vw, 802px" /></a></p>
<p>How much you get out of this image might depend on how much you care about corridors, but I am fascinated by it. It&#8217;s so much more intricate, organic and complex than the rules I added seemed &#8211; I look at it and think &#8220;Wait, I didn&#8217;t tell you how to do that!&#8221; But evidently I did. Again, I think it has good Rule Stealth: the rules are right there on display, but I don&#8217;t think you&#8217;d guess what they were, right? If you want to try, do so before clicking this:</p>
<p><a href="#" onclick="toggle_visibility('Rules');return false;">Click to show the new rules</a></p>
<div id="Rules" style="display: none; margin-left:30px;">
<ol>
<li>As before, if there&#8217;s a row behind this one, one module is selected to have a door leading back to it.</li>
<li>But now, every other module has a chance to have a back-door too.</li>
<li>As we&#8217;re building this row, if we&#8217;re placing a back-door and one already exists, there&#8217;s a chance we <em>won&#8217;t</em> connect this room to what we&#8217;ve already built of this row.</li>
<li>If a module has only one door, or it contains a ship system, it&#8217;s a room. Otherwise, it&#8217;s a corridor.</li>
<li>I halved the corridor sprite so we can have corners, T-junctions and crossroads as well as the straight corridors and rooms from before, while still building everything from only two sprites.</li>
</ol>
</div>
<h5>The Interesting Bit</h5>
<p>The bits that surprise me are bits like this:</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1.png" alt="Heat Signature Floorplan Isolated Room" width="290" height="302" class="aligncenter size-full wp-image-7277" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1.png 290w, https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1-178x185.png 178w" sizes="auto, (max-width: 290px) 100vw, 290px" /></a></p>
<p>How did it know to build a corridor branching off from a lengthwise passageway to lead to this out-of-the-way room?! My algorithm builds the ship one lateral row at a time, and each one has no idea what was in the last one. This makes it look like whoever built the ship planned ahead to make sure there was a corridor leading to this otherwise isolated room.</p>
<h5>The Explanation</h5>
<p>I get it, of course: three modules in a row all decided to make a door to the previous row, which meant all of them could block themselves off from each other laterally. And in the row it made afterwards, the middle module failed the chance to create a door leading back, so the room behind it was left with only one connection. And being a dead end, it became a room rather than a corridor.</p>
<p>The fact that it&#8217;s reachable is not luck, it&#8217;s a result of some logic I intentionally put into rule 3: we&#8217;re only allowed to block ourselves off from the rest of the row if we know the rest of the row also has a back-door. That way we can still get to them by going back one row.</p>
<p>But what if there&#8217;s a lateral block there too? Well, they&#8217;ll only create one if they, too, have doors on either side of the block leading backwards. What about the row behind that? Same rule, all the way to the very back row of the ship, which will never create a lateral block because it&#8217;ll never have two back-doors &#8211; it won&#8217;t have any.</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1.png" alt="Heat Signature Floorplan Isolated Room" width="290" height="302" class="aligncenter size-full wp-image-7277" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1.png 290w, https://www.pentadact.com/wp-content/Heat-Signature-Floorplan-Isolated-Room1-178x185.png 178w" sizes="auto, (max-width: 290px) 100vw, 290px" /></a></p>
<h5>Imaginary Intentions</h5>
<p>But it&#8217;s so interesting how much intentionality I can read in to the result of these rules. It looks so much like they isolated this room for a reason, and built that corner corridor to lead to it. And that adds meaning and character to whatever we put there.</p>
<p>Once the room types are in, that might end up being a cargo hold with a locked door and valuable loot in it. Clearly, it&#8217;s isolated by these thick sturdy walls for security reasons.</p>
<p>But random is random, so it could just as easily end up being living quarters. Now the isolation looks like privacy: maybe they don&#8217;t want to be kept up by ship noises. Or it could be a bathroom, and they don&#8217;t want sound to travel for other reasons.</p>
<p>That&#8217;s why this new system fascinates me. It seems to create intentionality out of algorithms, and the more stuff I put into the game for it to combine with, the more unexpected combinations will come out.</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Floorplans-2.png"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Floorplans-2.png" alt="Heat Signature Floorplans 2" width="902" height="584" class="aligncenter size-full wp-image-7283" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Floorplans-2.png 902w, https://www.pentadact.com/wp-content/Heat-Signature-Floorplans-2-178x115.png 178w, https://www.pentadact.com/wp-content/Heat-Signature-Floorplans-2-500x323.png 500w" sizes="auto, (max-width: 902px) 100vw, 902px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.pentadact.com/2014-07-19-improving-heat-signatures-randomly-generated-ships-inside-and-out/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
		<item>
		<title>Randomly Generating Simple Spaceships In Heat Signature</title>
		<link>https://www.pentadact.com/2014-02-07-randomly-generating-simple-spaceships-in-heat-signature/</link>
					<comments>https://www.pentadact.com/2014-02-07-randomly-generating-simple-spaceships-in-heat-signature/#comments</comments>
		
		<dc:creator><![CDATA[Pentadact]]></dc:creator>
		<pubDate>Fri, 07 Feb 2014 23:31:25 +0000</pubDate>
				<category><![CDATA[Game development]]></category>
		<category><![CDATA[Heat Signature]]></category>
		<category><![CDATA[Procedural Generation]]></category>
		<guid isPermaLink="false">http://www.pentadact.com/?p=6835</guid>

					<description><![CDATA[The way Heat Signature randomly generates its ships at the moment is very basic &#8211; I&#8217;m new to random generation, and I don&#8217;t polish or improve things until all the other systems are in. Its process for the ship&#8217;s shapes is probably obvious from the video: Pick a random &#8216;length&#8217; in ship modules That many [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The way Heat Signature randomly generates its ships at the moment is very basic &#8211; I&#8217;m new to random generation, and I don&#8217;t polish or improve things until all the other systems are in.</p>
<p>Its process for the ship&#8217;s shapes is probably obvious from the video:<span id="more-6835"></span></p>
<ul>
<li>Pick a random &#8216;length&#8217; in ship modules</li>
<li>That many times:</li>
</ul>
<ul style="margin-left:30px;">
<li>Pick a random &#8216;width&#8217; for this row</li>
<li>Generate that many modules</li>
<li>Center them along the ship&#8217;s middle</li>
</ul>
<p>So they&#8217;re all symmetrical, and contain no gaps, holes or curves &#8211; conventional. You still get some interesting oddities &#8211; like the rare very wide ship that&#8217;s only one module long &#8211; but the pattern is pretty obvious.</p>
<p>For the layout of the internal rooms and corridors, I tried the same approach: just the simplest thing I could think of that would always work. But I think it&#8217;s harder to see the pattern in the results. Even knowing the rules, I still find layouts that surprise me.</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Corridors.jpg"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Corridors.jpg" alt="Heat Signature Corridors" width="633" height="434" class="aligncenter size-full wp-image-6842" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Corridors.jpg 633w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-178x122.jpg 178w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-500x342.jpg 500w" sizes="auto, (max-width: 633px) 100vw, 633px" /></a></p>
<p>Curious about this, I asked from <a href="https://twitter.com/HeatSigGame">the game&#8217;s Twitter account</a> if anyone could guess what the rules were from the video. I got lots of good suggestions, and one or two got an individual rule right, but none that I saw got the whole process. Here&#8217;s what it does:</p>
<ul>
<li>When building a row, always add a doorway to the next module in the row.</li>
<li>Pick a random module position in this row that&#8217;s not empty in the next row, and make a doorway between the two.</li>
<li>If a module connects exactly two modules in a straight line, it&#8217;s a corridor. Otherwise, it&#8217;s a room.</li>
</ul>
<p>This ensures every room is connected to every other room, so it&#8217;s never impossible to get somewhere, but also makes it unlikely that the route will be direct. It makes a lot of wildly unrealistic corridor layouts, but I was surprised at how varied they felt.</p>
<p><a href="https://www.pentadact.com/wp-content/Heat-Signature-Corridors-2.jpg"><img loading="lazy" decoding="async" src="https://www.pentadact.com/wp-content/Heat-Signature-Corridors-2.jpg" alt="Heat Signature Corridors 2" width="1158" height="694" class="aligncenter size-full wp-image-6841" srcset="https://www.pentadact.com/wp-content/Heat-Signature-Corridors-2.jpg 1158w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-2-178x106.jpg 178w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-2-500x299.jpg 500w, https://www.pentadact.com/wp-content/Heat-Signature-Corridors-2-1024x613.jpg 1024w" sizes="auto, (max-width: 1158px) 100vw, 1158px" /></a></p>
<p>I didn&#8217;t plan it this way, but it&#8217;s also quite similar to a Spelunky level laid down flat: a Spelunky level is a series of floors made up of chunks, and a randomly selected chunk will lead down to the next floor. It doesn&#8217;t guarantee every chunk is connected to every other, though, only the &#8216;leading down&#8217; chunks.</p>
<p>I&#8217;ll change this a fair bit as I go &#8211; once guards are harder to get past, and there&#8217;s more incentive for stealth, I&#8217;ll open up multiple routes between rooms to give you more options.</p>
<p>I&#8217;ll also make the ship generation itself more varied, possibly by faction. At the very least I want &#8216;junk&#8217; type ships that are cobbled together from old wrecks and not at all symmetrical. It&#8217;d also be interesting to have a type that are rotationally symmetric, or have a width-wise axis of symmetry instead. And I can vary module width and length independently, which&#8217;ll change the whole shape, look and feel both inside and out.</p>
<p>But it&#8217;s not worth tinkering with that stuff yet &#8211; after IndieCade, my next job will be to put ship systems in, so that rooms relate to ship capabilities and you can sabotage them. Once ship functions are tied to their layouts, there may be implications for ship generation I haven&#8217;t seen coming. More importantly, it&#8217;ll be a lot more fun to mess around with.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.pentadact.com/2014-02-07-randomly-generating-simple-spaceships-in-heat-signature/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>
