Scripting: Events

Earthquakes

An earthquake is quite easy to set up compared with the invasions and military requests, so we’ll start with it. For setting up earthquakes, you can configure three parameters:

  1. The type of earthquake: long or short
  2. The probability that an earthquake occurs in a given time period, given as a percentage from 1 to 100
  3. The length of the time period mentioned above, in game weeks

Some explanation of the time period is in order. If you enter, for example, 48 weeks (one year) as the time period, the game will evaluate once every year whether an earthquake should occur, according to the probability parameter.

To set up an earthquake, you have to add code in three parts of the script file: the variables, the OnBeginScenario() method, and the OnTick() method.

Variables
Add the following to the variables section:

  // Nature event manager for the earthquake
  private NatureEvent mNatureEvent = null;

OnBeginScenario()
This is where you will configure the earthquake. The example below sets up a long earthquake with a probability of 3% and a time period of 27 weeks. Add the following code to the OnBeginScenario() method:

  // this event has a 3% chance of occurring every 27 weeks
  mNatureEvent = new NatureEvent(game, eNatureEventTypes.kDisaster,
    sDisasterEventTypes.kLongEarthquake, 0.03, 27,
    "EVENT_Earthquake_Title", "EVENT_Earthquake_Message");

To change the earthquake to a short one, change “kLongEarthquake” in the code to “kShortEarthquake”.

OnTick()
The following lines have to be added to the OnTick method in your script:

  // Update nature event (for earthquakes)
  mNatureEvent.DoTick(game);

Once you have set up the earthquake, don’t forget to add these two strings to your XML file:

  • EVENT_Earthquake_Title – Title of the message announcing the earthquake
  • EVENT_Earthquake_Message – The message itself

Wage changes

Changes in the wages for plebs or equites are set up in about the same way as earthquakes, but this time we have three possibilities (actually four: no wage changes at all):

  1. Only pleb wages can change
  2. Only equite wages can change
  3. Both pleb and equite wages can change

Wage changes are evaluated every year, and the new wage is chosen randomly from a set of wages that you can set up. For example, you can let pleb wages be one of 17, 20, and 23: the game chooses randomly which one of these it will be. The standard wages are 20 for plebs, and 24 for equites.

You can add “weights” to the wage amounts: continuing the example, we can have a 25% chance that the wage will be 17, 25% chance that the wage will be 23, and a 50% chance that the wage will be 20.

Let’s have a look at the code to set this up. Just like with earthquakes, we have to add code in three places in the script file: the variables, the OnBeginScenario() method, and the OnTick() method.

Variables
If you want only pleb wage changes, add this to the variables section:

  // Custom wage manager for pleb wages
  private StandardWageManager mWageManagerPlebe = null;

If you want only equite wage changes, add this to the variables section:

  // Custom wage manager for equite wages
  private StandardWageManager mWageManagerEquite = null;

If you want both pleb and equite changes, add both pieces of code above.

OnBeginScenario()
Just like with the earthquakes, this is where you’ll set up the wage change parameters. Each wage “step” is added separately, this allows you to set up as many wage steps as you like. In the examples below, the pleb wages are chosen out of three values, the equite wages are chosen from two values. When setting up the wage changes, you also have to set the wage at the start of the scenario, in the examples these are the default values of 20 (pleb) and 24 (equite).

If you want only pleb wage changes, add this to the OnBeginScenario() method:

  // Create a wage manager for pleb wages
  mWageManagerPlebe = new StandardWageManager(game, eWageTypes.kPleb, 20);
  
  // Add wage steps -- the potential wages that the standard rate
  // can switch to
  // Format: mWageManagerPlebe.AddWageStep(<wage amount>, <weight>);
  mWageManagerPlebe.AddWageStep(17, 25);
  mWageManagerPlebe.AddWageStep(20, 50);
  mWageManagerPlebe.AddWageStep(23, 25);
  
  // ensure the Rome standard wage is set properly at start
  mWageManagerPlebe.SetGameWage(game);

If you want only equite wage changes, add this to the OnBeginScenario() method:

  // Create a wage manager for equite wages
  mWageManagerEquite = new StandardWageManager(game, eWageTypes.kEques, 24);
  
  // Add wage steps -- the potential wages that the standard rate
  // can switch to
  // Format: mWageManagerEquite.AddWageStep(<wage amount>, <weight>);
  mWageManagerEquite.AddWageStep(24, 50);
  mWageManagerEquite.AddWageStep(30, 50);
  
  // ensure the Rome standard wage is set properly at start
  mWageManagerEquite.SetGameWage(game);

If you want both pleb and equite changes, add and configure both pieces of code above.

OnTick()
If you want only pleb wage changes, add this to the OnTick() method:

  // Update pleb wage manager
  mWageManagerPlebe.DoTick(game);

If you want only equite wage changes, add this to the OnTick() method:

  // Update equite wage manager
  mWageManagerEquite.DoTick(game);

If you want both pleb and equite changes, add both pieces of code above.

Once you have set up the wage changes, don’t forget to add these two strings to your XML file:

  • EVENT_Wage_Change_Title – Title of the message announcing the wage change
  • EVENT_Wage_Change_Message – The message itself

The game doesn’t make a difference between the message for pleb and equite wage changes: it uses the same message for both. If you have both equite and pleb wage changes, this may require you to be creative when writing your message.

< Previous: scripting basics | Editor Home | Next: scripting military requests >