StarMade Dev Update: NPC Factions
Greetings citizens, ~
At this stage, our current version is ready to be tested on the Official test server. It contains all core features where we can expand on with the upcoming releases.
The test server is running the build for a public test on play.star-made.org:4848.
These builds are only available on the Dev branch; it’s highly recommended that you use a different installation location or make a backup of your entire StarMade folder before overwriting it with a dev build.
Keep in mind that follow-up dev builds will most likely require you to also start a new world.
To get a fresh install of the dev build, select a different install folder in the launcher and switch to the dev branch.
Click on the gear (1), and change the build type (2) from “Release” to “Dev”, it is also recommended to use a separate installation directory (3). (Append a “DEV” to the installation path, to keep your original installation intact.)
The dev build has mechanics that will be disabled in the next public release, but are a necessity for experimenting with the NPC factions:
~ Debug menu, press F1 + B
~ Extra logging in your logstarmade.log files
~ Disabled Fog of War
~ Shows all fleets
~ Shows info in the galaxy map if you go into a NPC faction controlled system
~ Will send extra information to clients so it might be a bit more bandwidth intensive and prone to lag in multiplayer as long as in debug mode
In 2 weeks, we’ll release a stable public build for all servers to use.
NPC factions are a new AI controlled entity in the game. They represent a faction in the main galaxy. Although it is possible to have them spawn in other galaxies too, we want to focus on the main galaxy to give players a good experience without endless repeating patterns the further you go out. While you will still be able to do that, and there might be something special to find, the action will always be in the main galaxy.
Each faction has a config and blueprints that are copied from a set of faction configurations located in ./data/npcFactions/. There you can also add your own custom factions or edit the existing ones. When making a new world, they get copied over into the world’s database ./server-database/worldName/npcFactions/.
We have a lot of new assets for the npc factions, possibly including the fleets from the contest. Some of them are already included in this dev build, and we’ll continue to do so for the full release. Expect to encounter A LOT of new high-quality ships across the universe. We will also be doing further contests to expand the arsenal of default factions.
NPC spawning is the first step. On Galaxy creation the system will mark suitable spots, so it is efficient to select them later without having to iterate through every system and looking at its properties.
Normal NPC factions only spawn in star systems. However there will be special ones, that will also spawn in the void.
A NPC faction can grow initially to simulate them being further ahead in time. It will use a particular algorithm to determine the way they will grow. They will look at potential resources which are now distributed in the universe. They will also prefer star systems over void systems for that reason. Depending on the faction’s config setting, they will also either try to be densely clustered or expand much more loosely.
A faction wants to grow and to do that it needs blocks to construct the new stations and ships it will add. We call that “demand” and it’s calculated from the blueprints that have been made available to them. Each faction has an individual config and individual blueprints they can and will use. The demand is calculated not only considering the actual resources used but also what resources those blocks are made of. The result is weighed to determine what resources a faction prefers and how much.
An NPC faction will keep track of all its possessions in a central inventory. Its start inventory will be filled according to a faction’s demand. You can change that in its’ NPC Faction config to adjust which and how many blocks they will initially get.
In the next step, the faction will set its trade prices. Each faction’s homebase serves as a trading station, which can trade with other NPC factions as well as other players. The prices are set by demand. That means it first will look at the faction’s general demand as determined in the previous steps, but also how much of that demand is satisfied. If the amount is within a certain range, which can be adjusted in its config, the faction will be trading it. It will also adjust the prices depending on how much of its demand is already satisfied. So for example, if the stock is low but there is a high demand, the faction will pay more for it and at the same time stop selling that item.
A contingent is the collection of entities a faction could possibly own. Each NPC faction can spawn a certain amount and types of ships per owned system. The types and mass distribution can be defined in the config. There is also a distribution by distance from the home system. That means you can have the faction spawn smaller fighters and outpost stations on the outer edges of its territory, and bigger battleships and factory stations the closer you get to the home system. A blueprint can now be saved with a classification that determines its usage. These classes are then used to look up ships in a faction’s available blueprints. Blueprints will now also save their capacity, so they can spawn with items if necessary (trading ships), and a score based on salvage beams.
The contingent will adapt over time as the faction grows. Keep in mind that a contingent is only possible ships which are then spawned on demand when a player gets close.
This solution is used to combat scalability issues you would have if we would spawn everything when they’re created. It also helps to respond to player actions with specific ships.
A faction has system fleets and general fleets. System fleets will include everything within an owned system of an NPC faction. This includes patrolling ships that will respond to any attack, mining, and other events. There are different fleet types like attack, defend, mining, scavenging and more that can be configured to contain weighted amount of ship classes. So if there is an asteroid that needs mining, the faction will spawn a mining fleet if the contingent allows it and send it to mine that asteroid. Patrol fleets are going from station to station and will react to any potential threat that is entering the system.
General fleets, however, are mostly for faction wide events. This includes actual trading fleets spawned on trading with the actual resources traded, but also attack fleets in case of war, scouts, scavengers and more. Those fleets can then be encountered outside of NPC territory.
We will also add more ways to scan for fleet activity. The dev build is very verbose currently and will show all information.
A system keeps track on what ships it spawned from their contingent. That means it also knows how many resources are invested at the time, including cargo. When a faction ship or station gets blown up, the amount of resources are considered lost.
This can then be used to apply a system status percentage of resources lost. This status will be visible to the player. When the status gets below a certain point, the system will be abandoned by the faction due to losses. If the status doesn’t go below that point, the faction will focus to replenish the resources first using their own inventory before considering expanding again. If the faction can’t replenish enough resources to bring the status back over a threshold, the system will still be abandoned after all.
An NPC faction will also enable diplomacy both with other factions and with individual players. The diplomacy will be based on a point system. Those points can range between a minimum and a maximum value to represent the relation to another entity.
There are two ways that can modify your relationship points with a faction:
~ Status effects: these effects add or remove a constant amount of points based on status. This means that if you are in war with a faction, they will apply -X points to your score, though the points will go back to its original point value as soon as that status no longer persists. This means, that status effects don’t actually permanently change points. There are several advanced status effects available including having close territory to them, being at war with their allies, or positive ones for being at war with their enemies.
~ Action effects: these effects create modifiers that add or remove points permanently over time. In war for example, in addition of the status effect, you’ll also get a negative action modifier for starting the war. This modifier will slowly remove points over time as long as you are in conflict. This means that you will end up with less points permanently after the war. There will also be negative modifiers for any aggression towards the faction and their allies. So no matter how much they liked you in the past, if you start to kill their stuff, they will get mad at you depending on how much of that you do. Action modifiers, when no longer reset by repeating the action or by a persistent status will slowly fade out till it runs out of penalty points or enough time has been spent since then.
Attacking them, their friends or their enemies. Mining in their territory. Getting territory close to them. Going to war with them, their friends or their enemies.
Also some effects don’t have a modifier but trigger a reaction like offering peace, or offering an alliance.
Right now diplomacy requires a lot of testing especially with the action modifiers that change over time.
NPC Faction Turn
A NPC faction turn are triggered periodically and that amount of time can be adjusted in the NPC config. Currently it’s every 15 minutes. In each turn, a faction will do the following actions in that order.
For each owned system, the faction will simulate mining. Each system calculates a total amount of resources depending on what resources the system is rich in. The system then looks at its contingent and how many mining ships it has. It then calculates a score based on the blueprints used as mining ships and from that calculates how many resources are mined. This is in addition to the actual resources mined by mining ships when a player is close by.
Each mined system has a max amount of resources it can hold and how fast they replenish each turn. This resource status is then used for actual asteroid generation when a player gets close. Sectors with a low amount of available resources will not have many asteroids spawning or any at all if it is completely depleted..
For each owned system, the faction will simulate factory production. It will take all the factory class stations it has in its contingent and craft items. The amount of raw resources used for production can be adjusted. The types of resources produced will again be focused on the faction’s demand (which changes based on the amount of systems the faction has). The production turn has multiple steps to ensure that higher level items are crafted from the lower level ones, that have been produced in previous steps.
The systems will now use their faction inventory to resupply themselves based on resources lost. These resources are taken out of the faction inventory. If a system can not resupply to put its status above an adjustable value, it will abandon the system.
As an additional block sink and tool for balancing, a system consumes blocks each turn based on its contingent. This is used to balance the ability of mining and producing everywhere at once. It can be set to be temporary, so a new system will only consume items up to a certain point, which makes it handy to control faction growth.
One of the most complicated parts of a faction turn is the trading turn. A faction will look at all available trade nodes. Then it determines the price difference of its buy/sell price with the other node’s buy/sell price and how much can be bought/sold based on stock and money. From this difference the faction accumulates a trade value. The value also goes down the further the other node is away in the universe. That means that trading with far away nodes is only done when it is determined to be very lucrative or in very large amounts.
The best value is then selected and the trading will start. Depending on config settings a maximum amount of items to trade with can be set, so a faction can potentially do multiple trades at once.
Since an NPC trade is not dependent on the Trading guild, it will spawn an actual trading fleet that will be attached to the route. This makes it possible to raid NPC trading ships. We will be making the same for trading guild ships with some modifications for extra security. In the future we will also allow players to use their own fleets for trading so they no longer have to pay the trading guild, at the risk of losing their ships in a raid of course.
The last part of the faction turn is the expand turn. The faction will assess its current inventory and determine if it can expand. Expansion cost is dependent on the demand and how many systems the faction already owns. If the faction can expand, the cost is immediately consumed and the system is then taken.
Testing the entire system is extremely time consuming and complex, especially when you’re looking at the scale. Minor mistakes could have major consequences. In the coming days we’ll also add more in depth descriptions to the NPC Faction config to clarify what each config value exactly does.
Thanks for playing StarMade,
~ Schema and the Schine Team