Space Engineers

Space Engineers

DEPRICATED (see description): Sector 15
Wartank  [developer] 21 Feb, 2015 @ 7:39am
The AI (2)
The commander
The commander (also called the station manager inside the code) handles the Incursion system. This means that this AI handles the financial means of executing the incursion. And decides what will be build.

Finances
For the AI to do anything it will need money. Money in this mod is handled like in one of those oldschool rts games (red alert, the tiberium series...that little money counter in the right op of your screen). The AI gains money with each ping and from different sources.

  • Default income: Starts with 20 per turn but is increased by 1 with each turn (so after 5 turns the commander will gain 25 resources). This can increase to a maximum of 75 per turn. Reloading the game resets this and puts it back to 20. This is done to give the player some breathing room when loading in the game again
  • Shipyards and Missile stations: Shipyards and missile stations give a small amount of resources with each commander turn. Unlike the Default income this number is static
  • Logistics stations: These stations are specially build to increase the AI income. They produce a small but rapidly increasing resource boost for the ai. If a player leave these rather weak stations untended the could become there downfall.
note: The ECM station (incursion level 6) gives NO resources bonus to the ai

When the commander wants to buy a ship or station it will need to pay for it. Depending on the level of the station the price might go up. The exact table of prices and costs I will leave hidden as they would make it to easy for a player to figure out what the ai commander does with every step. But Expect the first scout to attack you after about 20 to 30 minutes of you play from a clean save and don't allow the ai to cheat or increase its speed.

Construction
Next to the Finances the commander AI also takes care of construction orders for both stations and ships. To do this the AI has a certain amount of construction slots. The commander ai self has 1 construction slots that can produce stations. This construction slot cannot be stopped or destroyed, leaving the incursion a ongoing event even if the player destroys all hostile stations. Next to that the commander ai can get Access to additional construction slots that can build a specific ship type. Each shipyard and missile launcher grants the ai 1 production slot that can build the ship class of the station (so a cruiser shipyard can only build cruisers, a frigate shipyard can only build frigates and so on). A player can disrupt these production slots by destroying the corresponding station.

The main priority of the AI is to produce a certain structure of stations towards incursion level 7. this structure can be best described as a pyramid of stations. With level 1 stations at the bottom of a level 7 station on top. It will produce this by a rather simple switch statement (it will build the first station that is true in the list of statements).
in psuedo code this would look liek:
if (fStationCount + 1 < IncursionState) { if (MissionComponent.host.AiPay(FrigateStation.BuildCosts)) { StartStationProduction(Station.StationType.Frigate); } } else if (dStationCount < IncursionState) { if (MissionComponent.host.AiPay(DestroyerStation.BuildCosts)) { StartStationProduction(Station.StationType.Destroyer); } } else if (sLStationCount - 1 < IncursionState) { if (MissionComponent.host.AiPay(SmallFactoryStation.BuildCosts)) { StartStationProduction(Station.StationType.SmallLogistic); } } else if (cStationCount - 2 < IncursionState) { if (MissionComponent.host.AiPay(CruiserStation.Buildconsts)) { StartStationProduction(Station.StationType.Cruiser); } } else if (lMStationCount - 3 < IncursionState) { if (MissionComponent.host.AiPay(LargeLaunchPlatform.BuildCost)) { StartStationProduction(Station.StationType.LargeLauncher); } } else if (LLStationCount - 4 < IncursionState) { if (ecmStation == null) { if (MissionComponent.host.AiPay(800)) { StartStationProduction(Station.StationType.Ecm); } } else { if (MissionComponent.host.AiPay(LargeFactoryStation.BuildCosts)) { StartStationProduction(Station.StationType.LargeLogistics); } } } else if (bStationCount - 5 < IncursionState) { if (MissionComponent.host.AiPay(BattleshipStation.BuildCosts)) { StartStationProduction(Station.StationType.Battleship); } }

Note that in incursion level 6 the ECM station takes priority over a Large logistics station. And that only 1 ECM station can be build at any given point. Also note that if you shoot down a low level station the ai has to spend time and resources to replace this station before it can push on to higher level again. So as a player it is smart to take any opportunities you have to shoot down a station.

Once the Commander has finished the 'pyramid' of stations it will means it is 'done'. At this point it will check if the pyramid is still intact. If this is not true it will build the stations needed to repair the structure. If it is true it will pick a incursion level randomly and start building a station for that one. Note that a ECM station takes absolute priority over all. So for example if the ai can build a level 7 station but has no ECM station it will build the level 6 ECM station FIRST and only THEN the battleship station.

Once the ai is building a station it will start looking about building ships. It will always choose to build most valuable ships first and then move its way down. So say for example we are in level 4 then the AI can build a cruiser first. If it has enough money and has a free cruiser production slot it will start doing so. After that it will check if it can produce a destroyer and lost it will check if it can build a frigate. Note that the previous steps do not have to be successful. So say the AI didn't have enough resources to build a destroyer, it might still start producing a frigate if the commander has enough money.

note: the commander ai is not responsible for the placement of stations and ships, this is done by the station AI.

part 3: https://steamhost.cn/steamcommunity_com/workshop/filedetails/discussion/366011702/617328415064655382/
Last edited by Wartank; 21 Feb, 2015 @ 7:41am