Commander Wars Modding Tutorial - Robosturm/Commander_Wars GitHub Wiki

This tutorial tries to help you on how to mod Commander Wars. I always recommend to take a look at the existing mods or CO's, Units etc. Since all work the same way indpendent if they're in a mod or in the actual game.

For debugging and testing take a look here

For Variable Support take a look here

Starting

  1. Go to the mods-folder which is somewhere around the Commander_Wars.exe
  2. Create a new folder with any name you like
  3. Create a mod.txt file in the new folder.
  4. Open the mod.txt and enter the mod name starting with "name=". Everything after "name=" will be shown in the option menu under mods-option

Visual modding (also required for new co's or units)

  1. create a images folder in your above created mods folder.
  2. create a units, terrain, building or co-folder depending on what sprites you want to mod into the game. Note: The folder structure needs to be the same as in the resources folder
  3. create a res.xml in the folder -> similar to that in the resources folder you want to mod. I recommend to read the Oxygine resource Doku when adding new sprites to the game or take a look at the existing xml-files. For example the following res.xml would add the images for a co named test in the army of amber corona. For the mod in the folder "my_custom_mod"
<?xml version="1.0"?>
<resources>
     <set path = "mods/my_custom_mod/images/co/" />
     <atlas>
          <image file="ac/co_test+nrm.png" />
  <image file="ac/co_test+info.png" />
  <image file="ac/co_test+face.png" cols = "3" />
     </atlas>
</resources>

Modding in the co named test

Note: You need to add images as descriped above to see your co in the game. ;)

  1. create a scripts folder in your mods folder
  2. create a cos folder in the scripts folder.
  3. create a java-scripts file named co_test.js in the folder. The name of the scripts file is the name of co-image and the unique internal id for the game. The name of the file doesn't need to be the same as the co-name but i recommend to name them co_ followed by the co name in lower letters.
  4. Open the java script file with an editor. Notepad or an actual javascript/qml ide.
  5. Add the following code to the script. Note that the last line the name CO_TEST needs to be the javascript file name in capital letters.
var Constructor = function()
{
}
Constructor.prototype = CO;
var CO_TEST = new Constructor();
  1. Now we have an empty CO who's playable but does exactly nothing.
  2. It's important to have the given lines of code in your co since it needs to be derived from the base co-script to avoid unneeded error callbacks which will slow down the game. Though they won't crash it.

Sidenotes:

If you want to create a CO with a name which already exists in the game for example Amy, you can do the following trick name it CO_1AMY or CO_AMY1 and change the CO object you create in the js-file of your mod. The engine matches file names as global unique objects. The shown names however can be the same. So if you return the CO-Name as Amy and let's say make her part of OS you have two CO's named Amy hopefully with different sprites 😄 and you can play both. The file names are pretty much a unique identifier for the game, but the content e.g. names that get returned or set by the callbacks can be used/returned multiple times.

Adding CO functionality

  1. open the resources\scripts\general\co.js
  2. This file contains all callbacks from the game to add funcionality to your co.
  3. I recommend to take a look at the existing co's in the resources\scripts\cos-folder to get a groove of what is possible. Example to create an extended movement range for all units during the power or superpower
  4. add the following lines of code to the script file after
var Constructor = function()
{

Here the example for the movement range

this.getMovementpointModifier = function(co, unit, posX, posY)
{
    if (co.getPowerMode() === GameEnums.PowerMode_Superpower)
    {
        return 2;
    }
  else if (co.getPowerMode() === GameEnums.PowerMode_Power)
    {
        return 1;
    }
    return 0;
};

Select CO-Army and CO-Unit-Range

  1. add the following lines of code to the script file after
var Constructor = function()
{

Here the lines of code

this.getCOUnitRange = function(co)
{
    return 4;
};
this.getCOArmy = function()
{
    return "BH"; // needs to be one of the existing armies in the game in capital letters ;) bh, bg os, bm, yc ...
};

Adding a CO description\CO-Intel to the co

  1. add the following lines of code to the script file after
var Constructor = function()
{

CO-Intel example:

// CO - Intel
this.getBio = function()
{
    return qsTr("A co created for testing.");
};
this.getHits = function()
{
    return qsTr("I like that");
};
this.getMiss = function()
{
    return qsTr("I hate this");
};
this.getCODescription = function()
{
    return qsTr("CO skill description");
};
this.getPowerDescription = function()
{
    return qsTr("Power description");
};
this.getPowerName = function()
{
    return qsTr("Power name");
};
this.getSuperPowerDescription = function()
{
    return qsTr("Super power description");
};
this.getSuperPowerName = function()
{
    return qsTr("Test Supername");
};
this.getPowerSentences = function()
{
    return [qsTr("First power sentence"),
            qsTr("one more"),
            qsTr("Another one. One is picked at random every time you use one.")];
};
this.getVictorySentences = function()
{
    return [qsTr("First victory sentence"),
  qsTr("Another victory sentence"),
  qsTr("And as many follow as you want")];
};
this.getDefeatSentences = function()
{
    return [qsTr("First loose sentence"),
            qsTr("Second loose sentence. We can add as many as we want")];
};
this.getName = function()
{
    return qsTr("Test");
};

Adding music to the co

  1. add a music folder to the mod
  2. add a cos folder to the mod
  3. add any music to the folder
  4. add the following lines of code to the script file after
var Constructor = function()
{

Example code to play bh-power music and a day to day music called test.mp3

this.loadCOMusic = function(co)
{
    // put the co music in here.
    switch (co.getPowerMode())
    {
        case GameEnums.PowerMode_Power:
            audio.addMusic("mods/my_custom_mod/music/cos/bh_power.mp3");
            break;
        case GameEnums.PowerMode_Superpower:
            audio.addMusic("mods/my_custom_mod/music/cos/bh_superpower.mp3");
            break;
        case GameEnums.PowerMode_Tagpower:
            audio.addMusic("mods/my_custom_mod/music/cos/bh_tagpower.mp3");
            break;
        default:
            audio.addMusic("mods/my_custom_mod/music/cos/test.mp3")
            break;
    }
};

Playing your mod

  1. Go to the option menu
  2. Check your mod checkbox
  3. Exit the option menu. The game will restart now, which will enable your mod.
  4. Play the game with your newly created co or unit ...
⚠️ **GitHub.com Fallback** ⚠️