Part 8: Invasions
The standard way for setting up invasions is using the classes in Tools.cs as explained on the Scripting Invasions page. The methods on this page are for advanced use only.
ClearInvasions()
This appears to clear records of invasions previously set up in memory. Have only used this to clear memory of the remnants of invasion data in a .scn file (which was causing an unscripted invasion to appear). Presumably this could be used as a way of preventing any future invasions of any type.
GetEnemyCohortData(int inCohortID, out string outDbID, out RomeScriptInterfaces.BasicCohortType outBasicType)
Obtains the cohort type ( Gaul light, Greek cavalry etc.) in outDbID, for the given CohortID (obtained from GetInvaderCohorts). The outher output parameter (not used in Tools.cs) is believed to identify whether the cohort type are either Archers, Cavalry, Infantry, Other, or Siege.
GetInvaderCohorts(ref string inInvasionName, out int[] outIDs)
This is used in Tools.cs, and could be used to monitor an ongoing invasion. Example use (derived from Tools.cs):
int[] enemyCohorts; string invasion = mGame.RunInvasion; game.GetInvaderCohorts(ref invasion, out enemyCohorts);
This returns a set of IDs to the enemyCohorts array. This could then be used to manipulate an ongoing invasion, e.g. through SetCohortOrders below.
SetCohortOrders(int inCohortID, ref string inOrders)
Used in Tools.cs to set the orders of individual enemy cohorts, identified by their ID (as obtained through GetInvaderCohorts above). Example (derived from Tools.cs):
foreach (Int32 cohortID in enemyCohorts)
{
string cohortDbID;
string orders = sCohortOrders.kRetreat;
game.SetCohortOrders(cohortID, ref orders);
}
This causes every invading cohort to retreat, e.g. after a certain time or condition met. You can use kFlee or any of the other possible orders given in the public structure sCohortOrders in Tools.cs.
SetCohortTargets(int inCohortID, ref string[] inTargets)
Used in Tools.cs to control the invasion. It could in principle (not tested yet) be used to direct enemy cohorts to target specific buildings. The input array inTargets consists of the string identifiers for the buildings to be targeted, such as "C4b Governor's Palace Large", "C4b infra granary". See Part 10 below for a complete list of building IDs that could be used.
StartInvasion(ref string inInvasionName)
Can be used to trigger an invasion (which has to have been just created - does not work on those set up in OnBeginScenario).
Example from Cyrene Revisited:
mInvasion = new InvasionSetup(invasionName,
sInvasionFactions.kCarthaginian, eInvasionType.kPillagers,
nRaidBribe, 4, 0);
mInvasion.AddCohort(sCohortDbIDs.kCarth_Lt, 1, 3, 3);
mInvasion.AddCohort(sCohortDbIDs.kCarth_Aux, 1, 3, 3);
mInvasion.CreateInvasion(game, nInvasion, 0);
game.StartInvasion(ref invasionName);
It should be noted that this method gives the player no warning of the attack, so it requires a separate message to be fired. Also, the invaders can only be bribed via the Legion Adviser screen.
StopCurrentInvasions()
This is used in Tools.cs to stop the current invasion after a defined period of time, or after a specified percentage of buildings have been razed. It can be used in conjunction with SetCohortOrders, which gets them to leave the map. This suggests (not verified through testing yet) that this function just stops the enemy attacking further targets.
StopInvasion(ref string inInvasionName, bool inStopFutureRecurrences)
This seems to perform a similar function, but is aimed at the identified invasion. The additional effect is (potentially) to stop this invasion recurring again, as directed by the Boolean flag. For example:
string invasion = mGame.RunInvasion; bool bStop = true; game.StopInvasion(ref invasion, bStop);
AddCohortToInvasion(ref string inInvasionName, ref string inCohortID, uint inNumFullCohorts, uint inEntryWaypoint, uint inExitWaypoint)
This is called from the CreateInvasion method of the InvasionSetup class. It has no obvious use as it allows you to do no more than the methods available through InvasionSetup (as invoked in OnBeginScenario).
CreateInvasion(ref string inInvasionName, int inTextIndex, ref string inFaction, int inBuyoffDenarii, int inStartWeek, int inVariance, int inDuration, int inRecurrenceInterval)
Used in Tools.cs, called from mInvasions.CreateInvasion. This suggests that invasions can be set up directly, although this does not seem to be advisable, e.g. OnInvasionArrival won't recognise the invasion.
NOTE: I've discovered that if, instead of using something like sCohortDbIDs.kCarth_Lt to identify the invading cohorts you put this in instead:
string sRomans = "ENEMY_ROMAN";
and use that as input, then Caesar's legions will appear. From brief testing they seem to behave as would be expected. Note you can also use "ENEMY_ROMAN_CATAPULT" as input too.
< Previous: Trade & Empire map | Editor Guide | Next: Military requests >