Skip to content

HowTo Add a new component feature

se5a edited this page May 5, 2017 · 4 revisions

How it all works

The game grabs the ComponentTemplate data from the json files when starting/loading a game, these define what is displayed to the player on the Component Design screen. The player designs a component in the Component Design screen.
The game takes what the player has defined in the Component Design screen and turns that into a Design Entity.
the player can then research it, at which point it becomes available to build. (the player can also use it in a ship design before research is complete)
The player designs a Ship in the Ship Design screen, the players designed components are all available here.
The player builds a ship (or just the component)
if a player builds a ship, the ship is built with the component installed on that ship as a component.
if the player builds the component, the player can transport that component around as cargo.
when the component is installed on a ship (or colony)
The game re-calculates the ship's stats and updates any ship level datablobs as appropriate.
the ship has a structure something like this:
ShipEntity

  • ShipInfoDB
  • ComponentInstancesDB
    • ComponentDesign
      • ComponentInstance
      • ComponentInstance
    • ComponentDesign
      • ComponentInstance
  • SomeOtherDB

1: Write the processors

I find it easiest to start off with the logic, while writing the logic you'll start to see what data the logic is going to need to have stored

2: Write the Ship/Colony level datablob

This will hold data that is specific to an instance of a ship or colony, but not specific to an instance of a component

3: Write the Recalc Processor.

(as a method in the processor class in step 1) and hook it into the RecalcProcesor.TypeProcessorMap found in RecalcProcessor.cs the TypeProcessorMap is just a dictionary of <Type,delegate> key value pairs. the ship/colony level datablob you wrote in step 2 will be the key, and the recalc method you wrote in step 3 will be the value.

4: Write component level instance datablobs (if required)

if data for an instance of a component needs to be stored (for example, the cooldown on a specific weapon needs to be stored for that instance, but the amount of damage that the weapon does does not need to be stored in the instance, it can be kept in the design

5: Write component level design datablobs

These are sufixed with AtbDB they are the attributes that make up a component template and hold the data specific for a component design.

6: Link to AttributeToAbilityMap.TypeMap

This is another <Type,delegate> type dictionary simular to the TypeProcessorMap. the component level design datablob you wrote in step 5 is the key, shipOrColonyEntity.SetDataBlob is the delegate function, with the ship level datablob from step 2 being the input for the SetDataBlob method. the whole delegate has an if statement to check whether the ship entity already has that datablob. this will allow the ship level datablob you wrote to be added to the ship when a component with the component level design, or instance datablob is added to the ship.

7: Write a ComponentTemplate

This is the Json data, it defines what the player can tweak when designing the component during the game.

7: If the processor needs to trigger another processor after a specific timeframe:

you'll need to create an PulseActionEnum and map that to the processor in the PulseActionDictionary.EnumProcessorMap this is a map that is an <enum, delegate> key value pair. this was required due to it being extremely hard to serialize delegates. once that is set up, you can set the processor to set the managerSubPulse to do an action to happen on a given datetime.

Clone this wiki locally