AI War 2:Adding Factions

From Arcen Wiki
Revision as of 04:04, 8 July 2019 by Dominus Arbitrationis (talk | contribs) (Starting page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is going to a quick and dirty way of setting up a basic faction, as well as providing a heavily commented example faction that does work, but isn't balanced or otherwise useful for play. Overall, this should provide a good framework to start with that is easy for you to read and understand. You can also take additional code from other factions as necessary if you aren't sure what can or can't be added.

Getting Started

To start, go ahead and download the basic necessary components if you haven't already. This tutorial will be using Visual Studio 2017 (, the release build of AI War 2 version 0.873, the AIWar2ExternalCode Project that is shipped with the game, and NotePad++ ( Note that you do not have to use the two tools listed if you don't want to download them, but they can be useful, at least for following along.

Get all of those set up and updated and all that fun stuff. Then, open your Project in Visual Studio. Go ahead and navigate to the Special Factions folder, right click on it, go to Add, then "New Item..."; you will then select Code File as the option you want to use. Naming it something that corresponds to the faction name is recommended, but not required. I named mine ExampleFaction.cs


Let's start by telling the code what namespaces we are using.

using Arcen.AIW2.Core;
using System;
using System.Collections.Generic;
using System.Text;
using Arcen.Universal;

We want to call Arcen.AIW2.Core and Arcen.Universal because they are baked into the game and contain additional things we can use and call. The system ones are just good defaults to have, and nothing else is needed.

Now go ahead and set up your namespace that we will be working in. For anything you do in External code, you will always want to use namespace Arcen.AIW2.External. Now, to define the class. Go ahead and use start with public class SpecialFaction_ExampleFaction : BaseSpecialFaction. This says to make a new public class named SpecialFaction_ExampleFaction based off of the the BaseSpecialFaction. In other words, if it appears in the BaseSpecialFaction file, you can pull it over here and modify it easily.

At this point, we can start with the protected override values. There are only going to be three of them for this example, and they will be

protected override string TracingName => "ExampleFaction"; 
protected override bool EverNeedsToRunLongRangePlanning => true;
protected override FInt MinimumSecondsBetweenLongRangePlannings => FInt.FromParts( 10, 000 );

While there are plenty more you can, for this basic example faction, those are the only three that are required. At this point your code should look like this, but minus the comments:


Let's go ahead and start with making this faction friendly to the AI and its special forces, but hostile to everyone else. For simplicity, that will include factions that are allied with the AI, since this faction spawns Hunter/Killers, and they're mean. Think wasps, except worse. Anyways, to set it up, use public override void SetStartingFactionRelationships( Faction ExampleFaction ). In that, go ahead and put base.SetStartingFactionRelationships( ExampleFaction ); just so it runs its normal stuff.