NPC Building Regulator
The NPC Building Regulator allows to handle the creation of building entities for the NPC faction. Each building type that the NPC faction is allowed to create has its own regulator.
In this guide, we will setup a building regulator for the villager_house demo building.
1. Create NPC Building Regulator Data
The NPC Building Regulator Data is responsible for regulating the creation of one or multiple building types for one or multiple NPC types, one or multiple faction types or a combination of those two.
To create a new NPC Building Regulator Data, right-click with the mouse in the project tab and click on: Create -> RTS Engine -> NPC Building Regulator Data. An asset file will be then created, select it and define the new building regulator fields.
Call it tutorial_npc_house_regulator for example. Select it and let's explore its fields:
- Min Amount Range: Minimum amount that must be created from the building type.
- Max Amount Range: The maximum allowed amount that can be created from the building type.
- Max Pending Amount: The maximum allowed amount of this building-type-creation tasks that the faction can have at the same time. In this case, building-type-creation tasks refers to the active placed but not completely constructed building instances.
- Create On Demand: Allow NPC components (other than the NPC Building Creator component, the component responsible for creating buildings, which we will get to later) to request the creation of this building type.
- Start Creating After (in seconds): The creation of this building type will start after the delay provided in this field.
- Spawn Reload Range (in seconds): The timer length that will be used by the NPC Building Creator component to decide whether to create this building type or not.
- Auto Create: Enable/disable the creation of this building type by the NPC Building Creator component.
- Faction Entity Requirements: Input a list of required faction entities (defined by their codes and/or categories) with a specific amount that must be available and present for the NPC faction to create the building regulated by this data.
- Regulate Per Building Center: Should the building type be regulated per building center or for the whole faction overall? This is only valid when your game is making use of the building centers provided by the Border components. When enabled, the building type min, max and pending amounts will be constrainted to buildings within each building center. Otherwise, they will be considered for the whole NPC faction buildings.
- Place Around: Make the NPC faction place the building only around specific entities. Define the place around entities (buildings, units or resource entities) in order of priority (using codes and categories). Leave empty to place around a valid building center (that has a Border component). For each element, you can find the min and max range that the building will take in relation to the entity it is being built around.
- Force Place Around: Enable this option to force the building to be placed around the above defined place around data or else the building placement would be discarded. Disable to allow the building to be placed around a building center if all defined place around conditions fail.
- Can Rotate: Enable this option to allow the building to be rotated to look at its place around entity according to above placement data.
We will configure the tutorial_npc_building_regulator data fields as the following screenshot: You can of course tweak these values for different effects.
But what is worth noting here is the Place Around data: What we have defined here is that we want the tutorial_house building to be built around other existing houses within a small range of 1 to 4. But if there are no houses available then we will build it around the town center with a distance of 5 to 25. We make sure to enable Force Place Around as well.
2. Configure Building Prefab
Now we need to assign the regulator data to the building prefab. Open the villager_house building prefab and add the NPC Building Regulator Data Input component to its parent object.
In this component, you can assign a NPC Building Regulator Data asset file to be used for the building for all types (all NPC and faction types) or go into the Type Specific field to pick what NPC Building Regulator Data asset files can be used for certain NPC and faction types. We will add a new element to the Type Specific field and link the regulator data asset we created to the tutorial_npc_type that we are dealing with in this tutorial. So the new NPC Building Regulator Data Input component should look like this now:
- Faction Types: Set to All because we want to assign the regulator data no matter the faction type of the NPC type.
- NPC Types: Set to All In List and in the Options list, add the tutorial_npc_type. This would ensure that the regulator data is only used with the NPC type we created.
Download Files
You can download the results of this tutorial here.