Scripting: Military Requests

If a military request (or order) occurs, the player has to select some of his own troops to send abroad to fight some enemies. How many enemies will be encountered is set by the script. Military requests are again a little harder to set up than the earthquakes and the wage changes, but this is mainly due to the many variables you need to fill in for them.

In terms of code, the requests are easy: the only place where you have to add code is the OnBeginScenario() function. We first need to set up two temporary variables in this code:

  sMilitaryRequestInfo requestInfo;
  MilitaryRequest request;

Then, we have to do the following for each request:

  1. Create a new RequestInfo object that will hold the information for your military request
  2. Fill in the information for the request
  3. Add cohorts to the request
  4. Add the military request to the game

The code for step 1 and 2 looks like this, where you will have to replace the <NUMBER> placeholders with your own values:

  requestInfo = new sMilitaryRequestInfo();
  requestInfo.mRequestID = <NUMBER>;
  requestInfo.mReward = <NUMBER>;
  requestInfo.mPenalty = <NUMBER>;
  requestInfo.mStartWeek = <NUMBER>;
  requestInfo.mVariance = <NUMBER>;
  requestInfo.mRecursionWeek = <NUMBER>;
  requestInfo.mDeadline = <NUMBER>;
  requestInfo.mFirstWarning = <NUMBER>;
  requestInfo.mSecondWarning = <NUMBER>;
  requestInfo.mTravelTime = <NUMBER>;
  requestInfo.mWorldSiteIndex = <NUMBER>;

An explanation of the variables:

mRequestID
The unique ID of the request. Watch out, since you have to take the requests you set up in the editor into account. If you have, for example, three requests for goods set up in the editor, you will have to start numbering your military requests from 3.

mReward
The favor reward the player gets when he has sent troops that have defeated the invasion. Set this to 0 for a military aid “order”, set it to a positive number for a request.

mPenalty
The favor penalty when the player has not sent any troops at all, or if the troops sent were destroyed by the enemy. Set this to zero for a request, and to a positive number for an order

mStartWeek
The week when the request fires, since the start of the scenario. One year is 48 weeks, so setting this to, for example, 72 will make the request pop up halfway the second year. This time is when the request is first made known to the player, not the time when the player has to fulfil it.

mVariance
The variance in the start week of the request: if this value is set to, for example 8, the request can come up to two months earlier or later than mStartWeek indicates

mRecursionWeek
After how many weeks the request should occur again. Set this to 0 for a one-time request

mDeadline
The deadline of the request in weeks: the player has this many weeks to fulfil the request

mFirstWarning
The time of the first reminder warning, in weeks after the start of the request. This is usually set to half of the deadline

mSecondWarning
The time of the second reminder warning, in weeks after the start of the request. This message is normally set to one month before the deadline, in which case you set this to (deadline – 4)

mTravelTime
The time (in weeks) it takes for player cohorts to reach their destination enemy site, usually set to 4 (one month)

mWorldSiteIndex
The index into the list of world site on the Empire. This is the camp where the enemy is supposed to be gathering. Must be a valid enemy camp

Adding cohorts

Cohorts are added to the request in a straightforward way: you enter the type of cohort you want to add, and the number of cohorts you wish to add. You can look up the type of enemy cohort on the scripting constants page. You can add different types of cohorts by adding more lines.

We’ll show the code for step 3 and 4 together: adding cohorts and adding the request to the game.

Example 1: 2 Germanian heavy infantry cohorts

  request = new MilitaryRequest();
  request.AddCohort(sCohortDbIDs.kGerm_Hvy, 2);
  request.AddMilitaryRequest(requestInfo, game);

Example 2: a large enemy force of 4 Greek heavy infantry, 2 Greek light infantry, 3 Greek missile auxilia, and 1 Greek cavalry

  request = new MilitaryRequest();
  request.AddCohort(sCohortDbIDs.kGreek_Hvy, 4);
  request.AddCohort(sCohortDbIDs.kGreek_Lt, 2);
  request.AddCohort(sCohortDbIDs.kGreek_Aux, 3);
  request.AddCohort(sCohortDbIDs.kGreek_Cav, 1);
  request.AddMilitaryRequest(requestInfo, game);

While it’s possible to also add catapults and rams to the invasion force, this is never used in the official scenarios, and might not work as expected.

Message texts in XML

Once you’ve set up the requests in the script, don’t forget to add messages to the XML file!

Full example

Here’s a full example of the code you will need to add to the OnBeginScenario() function, for two military requests: one recurring request, one order.

  sMilitaryRequestInfo requestInfo;
  MilitaryRequest request;
  
  // Recurring request
  requestInfo = new sMilitaryRequestInfo();
  requestInfo.mRequestID = 0;
  requestInfo.mReward = 10;
  requestInfo.mPenalty = 0;
  requestInfo.mStartWeek = 108;
  requestInfo.mVariance = 8;
  requestInfo.mRecursionWeek = 120;
  requestInfo.mDeadline = 60;
  requestInfo.mFirstWarning = 30;
  requestInfo.mSecondWarning = 56;
  requestInfo.mTravelTime = 4;
  requestInfo.mWorldSiteIndex = 7;
  
  request = new MilitaryRequest();
  request.AddCohort(sCohortDbIDs.kGreek_Cav, 4);
  request.AddMilitaryRequest(requestInfo, game);
  
  // One-time order
  requestInfo = new sMilitaryRequestInfo();
  requestInfo.mRequestID = 1;
  requestInfo.mReward = 0;
  requestInfo.mPenalty = 15;
  requestInfo.mStartWeek = 204;
  requestInfo.mVariance = 8;
  requestInfo.mRecursionWeek = 0;
  requestInfo.mDeadline = 72;
  requestInfo.mFirstWarning = 36;
  requestInfo.mSecondWarning = 68;
  requestInfo.mTravelTime = 4;
  requestInfo.mWorldSiteIndex = 8;
  
  request = new MilitaryRequest();
  request.AddCohort(sCohortDbIDs.kGreek_Lt, 3);
  request.AddCohort(sCohortDbIDs.kGreek_Aux, 1);
  request.AddMilitaryRequest(requestInfo, game);

< Previous: scripting events | Editor Home | Next: scripting invasions >