Class: XComMod - XCOM:EU 2012

From Nexus Mods Wiki
Jump to: navigation, search


Overview

The following is taken from the Nexus Mod Talk Forum thread Scripting with UDK, as a result of explorations by wghost81.

The XComMod class is a base class, defined in the XComGame package. It is one of the keys to adding your own UDK created mods to the game, by providing the means of extending the objects defined for the game.

This class is utilized in the "Add new scripting" subtopic of the Modding with the UDK wiki article, and this explanation is best understood in context after reading that topic.

Programs and Tools

Details

The XComMod class is a base class, defined in the XComGame package. It is empty and contains only one function:

class XComMod extends Object;

simulated function StartMatch() { return; }

The class is utilized by the XComGameInfo class of the same package. XComGameInfo has two member variables, which deal with the mods:

var config array<config string> ModNames;
var array<XComMod> Mods;

ModNames is a config variable, containing the class name of the mod; in this example the mod name TestMod added to the appropriate section (in the tutorial of Modding with the UDK this is the [XComStrategyGame.XComHeadquartersGame] section) of <game path>\Config\DefaultGame.ini with the following line:

+ModNames=XComMod.TestMod

When InitGame function is called inside XComGameInfo, it calls for the CacheMods function, which iterates through the ModNames array, creates a new Mod object of the ModClass class (as defined in DefaultGame.ini) and adds this object (TestMod) to the array of active mods (Mods array variable).

XComGameInfo also has a function called ModStartMatch:

simulated function ModStartMatch()
{
   local XComMod Mod;
   foreach Mods(Mod,)
   {
       Mod.StartMatch();        
   }    
   return;
}

This function is later called by XComHeadquartersGame class (a child of XComGameInfo class) at the end of the StartMatch function.

In EU it is also called by the same function of XComTacticalGame class (which is also a child of XComGameInfo class). But for EW, this piece of the code was removed.

To add an active mod into the tactical game in EU (and EW), one needs to add a section to the DefaultGame.ini file:

[XComStrategyGame.XComHeadquartersGame]
+ModNames=ModPackageName.ModClassName

As a result of all this, the StartMatch function of each of the active mods is called each time when the Strategic (or Tactical) game starts (that's why there are $200,000 on the screenshot in the tutorial in Modding with the UDK, and not $100,000). For example, in the EU Slingshot DLC it is used to add a new mission to the array of Council missions.

Using this method we can create our own classes to work in parallel with existing classes and add changes to the game.

Theoretically, instead of using dummy scripts (as in the tutorial previously mentioned), we can try to compile actual XCOM scripts, decompiled by UEExplorer. But UEExplorer decompiles some functions incorrectly and has problems with some of the Default Properties, so doing this this will require a lot of work.

See also the "Adding with Mutators" section of the Modding with the UDK article for another method of adding mods.


References

Referred to by this article:



That refer to this article: