<p>This episode is about modeling vehicle designer that can be used to design all kinds of vehicles available in the game. It relates to episode about <a href="https://hackerpublicradio.org/eps.php?id=2818">performing research</a>.</p>
<h2 id="major-parts">Major parts</h2>
<p>Two major parts about vehicle designer are components and chassis.</p>
<p>Components are modular pieces of vehicle that are assembled on chassis. They can, among other things, be things lie star sails, astrolabe navigators or long range sensor. Each component is defined by two values <code>ComponentId</code> and <code>ComponentLevel</code>. If you know these two values, you’ll be able to find out details of the component. <code>ComponentId</code> tells what component it is and <code>ComponentLevel</code> the general knowledge of it. When component is first discovered as a result of research, it’s just a prototype and as a such doesn’t function particularly well. Further research refines it and factories are able to produce higher quality components.</p>
<p>Full definition of component is show below:</p>
<pre><code>data Component = Component
    { componentId :: ComponentId
    , componentLevel :: ComponentLevel
    , componentName :: ComponentName
    , componentDescription :: ComponentDescription
    , componentWeight :: Weight
    , componentSlot :: ComponentSlot
    , componentType :: [ ComponentPower ]
    , componentCost :: RawResources ResourceCost
    , componentChassisType :: ChassisType
    }
    deriving (Show, Read, Eq, Ord)</code></pre>
<p>Two particularly interesting fields are <code>componentSlot</code> and <code>componentType</code>. <code>componentSlot</code> has type of <code>ComponentSlot</code> and defines what kind of slot the component occupies in chassis. As there are limited amount of slots in each chassis, designer needs to make compromises on what components to install. <code>componentType</code> has type of <code>ComponentPower</code>, which defines what component does in general. It could be sensor or provide supplies for the vehicle for example.</p>
<p>Technology requirements are defined by function: <code>componentRequirements :: ComponentId -&gt; Maybe Technology</code>. It defines which technology unlock a given component. Part of the definition is show below. Each and every <code>ComponentId</code> has to be handled.</p>
<pre><code>componentRequirements ShipLongRangeSensors = Just HighSensitivitySensors
componentRequirements ShipBridge = Nothing
componentRequirements VehicleWheeledMotiveSystem = Nothing
componentRequirements VehicleHoverMotiveSystem = Just HoverCrafts
...</code></pre>
<p>Second major part of the designer are chassis. They’re stored in database, as I wanted a bit more flexible system than hardcoding as I did with components. Following piece of configuration is used to define database table and generated data for Haskell code. Most of the fields are probably easy enough to guess. <code>type</code> with type of <code>ChassisType</code> defines if this particular chassis is for example a land vehicle or a space ship. Various slot fields on other hand define amount of particular slots that the chassis offers.</p>
<pre><code>Chassis json
    name ChassisName
    tonnage Weight
    type ChassisType
    technology Technology Maybe
    armourSlots SlotAmount
    innerSlots SlotAmount
    outerSlots SlotAmount
    sensorSlots SlotAmount
    weaponSlots SlotAmount
    engineSlots SlotAmount
    motiveSlots SlotAmount
    sailSlots SlotAmount
    deriving Show Read Eq</code></pre>
<p>Not all chassis are equal and some (probably pretty much every one of them) have some sort of requirements that has to be fulfilled when designing a vehicle. For example, space ships require a bridge for captain and star sails. Bawley, smallest of the working ships has room for two star sails, but requires only one of them to be installed in order to be a valid design. Flyboat on the other hand is smaller ship built for speed and always requires two set of sails.</p>
<p>This data is stored in <code>required_component</code> table and represented as <code>RequiredComponent</code> data. Both are generated from the definition show below:</p>
<pre><code>RequiredComponent json
    chassisId ChassisId
    componentType ComponentType
    level ComponentLevel
    amount ComponentAmount
    deriving Show Read Eq</code></pre>
<h2 id="designing-a-vehicle">Designing a vehicle</h2>
<p>With all that data, we can now design a vehicle. Process is roughly the following:</p>
<ul>
<li>based on completed research, get a list of chassis that are available</li>
<li>select chassis from the list</li>
<li>based on the selected chassis and completed research, get a list of components that are available</li>
<li>select components to install</li>
<li>remember to check that maximum tonnage isn’t exceeded and that there’s enough slots and requirements are met</li>
<li>fill in name</li>
<li>save into database</li>
</ul>
<p>Completed design is saved in two different tables. First one <code>design</code> holds info like name of the design, faction that design belongs to and used chassis. <code>planned_component</code> holds info about which components are planned to be installed and in what quantity.</p>
<pre><code>Design json
    name Text
    ownerId FactionId
    chassisId ChassisId
    deriving Show Read Eq</code></pre>
<p>and</p>
<pre><code>PlannedComponent json
    designId DesignId
    componentId ComponentId
    level ComponentLevel
    amount ComponentAmount
    deriving Show Read Eq</code></pre>
<p>As a little teaser, below is an screenshot of what the vehicle designer currently looks like.</p>
<p><img src="https://hackerpublicradio.org/eps/hpr2858_1.png" alt="Screenshot of vehicle designer showing chassis and components" /></p>
<h2 id="finally">Finally</h2>
<p>Thanks for interest. If you have questions or comments, best way to reach me nowadays is either by email or in fediverse, where I’m <code>Tuula@mastodon.social</code>.</p>
