Ticket #3934: resource_agnostic-v7.2.patch

File resource_agnostic-v7.2.patch, 109.1 KB (added by s0600204, 8 years ago)

More suggestions from elexis, and adding precautions in session gui in case of more than eight resources

  • new file inaries/data/mods/public/globalscripts/Resources.js

    diff --git a/binaries/data/mods/public/globalscripts/Resources.js b/binaries/data/mods/public/globalscripts/Resources.js
    new file mode 100644
    index 0000000..f07a80a
    - +  
     1/**
     2 * Resources Global
     3 *
     4 * Engine.FindJSONFiles only exists within the session context
     5 * Engine.BuildDirEntList only exists within the gui context
     6 * The AI and test contexts have no access to any JSON file access functions
     7 */
     8function Resources()
     9{
     10    let jsonFiles = [];
     11    if (Engine.FindJSONFiles)
     12    {
     13        jsonFiles = Engine.FindJSONFiles("resources", false);
     14        for (let file in jsonFiles)
     15            jsonFiles[file] = "resources/" + jsonFiles[file] + ".json";
     16    }
     17    else if (Engine.BuildDirEntList)
     18        jsonFiles = Engine.BuildDirEntList("simulation/data/resources/", "*.json", false);
     19    else
     20    {
     21        warn("Resources: No JSON access functions are unavailable");
     22        return;
     23    }
     24
     25    this.resourceData = [];
     26    this.resourceCodes = [];
     27
     28    for (let filename of jsonFiles)
     29    {
     30        let data = Engine.ReadJSONFile(filename);
     31        if (!data)
     32            continue;
     33
     34        data.subtypeNames = data.subtypes;
     35        data.subtypes = Object.keys(data.subtypes);
     36
     37        this.resourceData.push(data);
     38        if (data.enabled)
     39            this.resourceCodes.push(data.code);
     40    }
     41};
     42
     43Resources.prototype.GetData = function()
     44{
     45    return this.resourceData.filter(resource => resource.enabled);
     46};
     47
     48Resources.prototype.GetResource = function(type)
     49{
     50    let lType = type.toLowerCase();
     51    return this.GetData().find(resource => resource.code == lType);
     52};
     53
     54Resources.prototype.GetCodes = function()
     55{
     56    return this.resourceCodes;
     57};
     58
     59/**
     60 * Returns an object containing untranslated resource names mapped to
     61 * resource codes. Includes subtypes.
     62 */
     63Resources.prototype.GetNames = function()
     64{
     65    let names = {};
     66    for (let res of this.GetData())
     67    {
     68        names[res.code] = res.name;
     69        for (let subres of res.subtypes)
     70            names[subres] = res.subtypeNames[subres]
     71    }
     72    return names;
     73};
  • binaries/data/mods/public/gui/common/functions_utility.js

    diff --git a/binaries/data/mods/public/gui/common/functions_utility.js b/binaries/data/mods/public/gui/common/functions_utility.js
    index 9984cb0..bbb1a35 100644
    a b function formatPlayerInfo(playerDataArray, playerStates)  
    416416
    417417    return teamDescription.join("\n\n");
    418418}
     419
     420/**
     421 * Horizontally fit objects within a parent.
     422 *
     423 * @param margin - The gap, in px, between the repeated objects
     424 * @param limit - The number of elements to fit
     425 */
     426function horizontallyDistributeObjects(parentName, margin = 0, limit = undefined)
     427{
     428    let objects = Engine.GetGUIObjectByName(parentName).children;
     429    if (limit)
     430        objects = objects.splice(0, limit);
     431
     432    let i = 0;
     433    for (let child of objects)
     434    {
     435        let size = child.size;
     436        size.rleft = 100 / objects.length * i;
     437        size.rright = 100 / objects.length * (i + 1);
     438        size.right = -margin;
     439        child.size = size;
     440        ++i;
     441    }
     442}
     443
     444/**
     445 * Hide all children after a certain index
     446 *
     447 * @param idx - The index from which to start
     448 */
     449function hideRemaining(parentName, idx = 0)
     450{
     451    let objects = Engine.GetGUIObjectByName(parentName).children;
     452
     453    for (; idx < objects.length; ++idx)
     454        objects[idx].hidden = true;
     455}
  • binaries/data/mods/public/gui/common/l10n.js

    diff --git a/binaries/data/mods/public/gui/common/l10n.js b/binaries/data/mods/public/gui/common/l10n.js
    index 53c16c2..3fd4570 100644
    a b  
    1 const localisedResourceNames = {
    2     "firstWord": {
    3         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    4         "food": translateWithContext("firstWord", "Food"),
    5         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    6         "meat": translateWithContext("firstWord", "Meat"),
    7         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    8         "metal": translateWithContext("firstWord", "Metal"),
    9         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    10         "ore": translateWithContext("firstWord", "Ore"),
    11         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    12         "rock": translateWithContext("firstWord", "Rock"),
    13         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    14         "ruins": translateWithContext("firstWord", "Ruins"),
    15         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    16         "stone": translateWithContext("firstWord", "Stone"),
    17         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    18         "treasure": translateWithContext("firstWord", "Treasure"),
    19         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    20         "tree": translateWithContext("firstWord", "Tree"),
    21         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    22         "wood": translateWithContext("firstWord", "Wood"),
    23         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    24         "fruit": translateWithContext("firstWord", "Fruit"),
    25         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    26         "grain": translateWithContext("firstWord", "Grain"),
    27         // Translation: Word as used at the beginning of a sentence or as a single-word sentence.
    28         "fish": translateWithContext("firstWord", "Fish"),
    29     },
    30     "withinSentence": {
    31         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    32         "food": translateWithContext("withinSentence", "Food"),
    33         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    34         "meat": translateWithContext("withinSentence", "Meat"),
    35         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    36         "metal": translateWithContext("withinSentence", "Metal"),
    37         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    38         "ore": translateWithContext("withinSentence", "Ore"),
    39         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    40         "rock": translateWithContext("withinSentence", "Rock"),
    41         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    42         "ruins": translateWithContext("withinSentence", "Ruins"),
    43         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    44         "stone": translateWithContext("withinSentence", "Stone"),
    45         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    46         "treasure": translateWithContext("withinSentence", "Treasure"),
    47         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    48         "tree": translateWithContext("withinSentence", "Tree"),
    49         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    50         "wood": translateWithContext("withinSentence", "Wood"),
    51         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    52         "fruit": translateWithContext("withinSentence", "Fruit"),
    53         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    54         "grain": translateWithContext("withinSentence", "Grain"),
    55         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    56         "fish": translateWithContext("withinSentence", "Fish"),
    57     }
    58 };
    591
    60 function getLocalizedResourceName(resourceCode, context)
     2function getLocalizedResourceName(resourceName, context)
    613{
    62     if (!localisedResourceNames[context])
    63     {
    64         warn("Internationalization: Unexpected context for resource type localization found: ‘" + context + "’. This context is not supported.");
    65         return resourceCode;
    66     }
    67     if (!localisedResourceNames[context][resourceCode])
    68     {
    69         warn("Internationalization: Unexpected resource type found with code ‘" + resourceCode + ". This resource type must be internationalized.");
    70         return resourceCode;
    71     }
    72     return localisedResourceNames[context][resourceCode];
     4    return translateWithContext(context, resourceName);
    735}
    746
    757/**
    function getLocalizedResourceAmounts(resources)  
    8113        .filter(type => resources[type] > 0)
    8214        .map(type => sprintf(translate("%(amount)s %(resourceType)s"), {
    8315            "amount": resources[type],
    84             "resourceType": getLocalizedResourceName(type, "withinSentence")
     16            "resourceType": translateWithContext("withinSentence", type)
    8517        }));
    8618
    8719    if (amounts.length > 1)
  • binaries/data/mods/public/gui/common/tooltips.js

    diff --git a/binaries/data/mods/public/gui/common/tooltips.js b/binaries/data/mods/public/gui/common/tooltips.js
    index ada0ca7..0fe4e0b 100644
    a b function getEntityCostComponentsTooltipString(template, trainNum, entity)  
    342342
    343343    return costs;
    344344}
     345
    345346function getGatherTooltip(template)
    346347{
    347348    if (!template.gather)
  • binaries/data/mods/public/gui/session/diplomacy_window.xml

    diff --git a/binaries/data/mods/public/gui/session/diplomacy_window.xml b/binaries/data/mods/public/gui/session/diplomacy_window.xml
    index 1708159..8857a57 100644
    a b  
    11<?xml version="1.0" encoding="utf-8"?>
    22
    33<object name="diplomacyDialogPanel"
    4     size="50%-300 50%-200 50%+300 50%+150"
     4    size="50%-260 50%-200 50%+260 50%+150"
    55    type="image"
    66    hidden="true"
    77    sprite="ModernDialog"
     
    1111    </object>
    1212
    1313    <object name="diplomacyHeader" size="32 32 100%-32 64">
    14         <object name="diplomacyHeaderName" size="0 0 150 100%" type="text" style="chatPanel" ghost="true">
     14        <object name="diplomacyHeaderName" size="0 0 140 100%" type="text" style="chatPanel" ghost="true" text_align="center">
    1515            <translatableAttribute id="caption">Name</translatableAttribute>
    1616        </object>
    1717        <object name="diplomacyHeaderCiv" size="150 0 250 100%" type="text" style="chatPanel" ghost="true">
     
    2323        <object name="diplomacyHeaderTheirs" size="300 0 360 100%" type="text" style="chatPanel" ghost="true">
    2424            <translatableAttribute id="caption">Theirs</translatableAttribute>
    2525        </object>
    26         <object name="diplomacyHeaderAlly" size="100%-180 0 100%-160 100%" type="text" style="chatPanel" tooltip_style="sessionToolTipBold">
     26        <object name="diplomacyHeaderAlly" size="360 0 380 100%" type="text" style="chatPanel" tooltip_style="sessionToolTipBold">
    2727            <translatableAttribute id="caption">A</translatableAttribute>
    2828            <translatableAttribute id="tooltip">Ally</translatableAttribute>
    2929        </object>
    30         <object name="diplomacyHeaderNeutral" size="100%-160 0 100%-140 100%" type="text" style="chatPanel" tooltip_style="sessionToolTipBold">
     30        <object name="diplomacyHeaderNeutral" size="380 0 400 100%" type="text" style="chatPanel" tooltip_style="sessionToolTipBold">
    3131            <translatableAttribute id="caption">N</translatableAttribute>
    3232            <translatableAttribute id="tooltip">Neutral</translatableAttribute>
    3333        </object>
    34         <object name="diplomacyHeaderEnemy" size="100%-140 0 100%-120 100%" type="text" style="chatPanel" tooltip_style="sessionToolTipBold">
     34        <object name="diplomacyHeaderEnemy" size="400 0 420 100%" type="text" style="chatPanel" tooltip_style="sessionToolTipBold">
    3535            <translatableAttribute id="caption">E</translatableAttribute>
    3636            <translatableAttribute id="tooltip">Enemy</translatableAttribute>
    3737        </object>
    38         <object name="diplomacyHeaderTribute" size="100%-110 0 100% 100%" type="text" style="chatPanel">
     38        <object name="diplomacyHeaderTribute" size="430 0 100%-30 100%" type="text" style="chatPanel" text_align="center">
    3939            <translatableAttribute id="caption">Tribute</translatableAttribute>
    4040        </object>
    4141    </object>
     
    4848                <object name="diplomacyPlayerTheirs[n]" size="300 0 360 100%" type="text" style="chatPanel" ghost="true"/>
    4949
    5050                <!-- Diplomatic stance - selection -->
    51                 <object name="diplomacyPlayerAlly[n]" size="100%-180 0 100%-160 100%" type="button" style="StoneButton" hidden="true"/>
    52                 <object name="diplomacyPlayerNeutral[n]" size="100%-160 0 100%-140 100%" type="button" style="StoneButton" hidden="true"/>
    53                 <object name="diplomacyPlayerEnemy[n]" size="100%-140 0 100%-120 100%" type="button" style="StoneButton" hidden="true"/>
     51                <object name="diplomacyPlayerAlly[n]" size="360 0 380 100%" type="button" style="StoneButton" hidden="true"/>
     52                <object name="diplomacyPlayerNeutral[n]" size="380 0 400 100%" type="button" style="StoneButton" hidden="true"/>
     53                <object name="diplomacyPlayerEnemy[n]" size="400 0 420 100%" type="button" style="StoneButton" hidden="true"/>
    5454
    5555                <!-- Tribute -->
    56                 <object name="diplomacyPlayerTributeFood[n]" size="100%-110 0 100%-90 100%" type="button" style="iconButton" tooltip_style="sessionToolTipBold" hidden="true">
    57                     <object name="diplomacyPlayerTributeFoodImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/food.png" ghost="true"/>
    58                 </object>
    59                 <object name="diplomacyPlayerTributeWood[n]" size="100%-90 0 100%-70 100%" type="button" style="iconButton" tooltip_style="sessionToolTipBold" hidden="true">
    60                     <object name="diplomacyPlayerTributeWoodImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/wood.png" ghost="true"/>
    61                 </object>
    62                 <object name="diplomacyPlayerTributeStone[n]" size="100%-70 0 100%-50 100%" type="button" style="iconButton" tooltip_style="sessionToolTipBold" hidden="true">
    63                     <object name="diplomacyPlayerTributeStoneImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/stone.png" ghost="true"/>
    64                 </object>
    65                 <object name="diplomacyPlayerTributeMetal[n]" size="100%-50 0 100%-30 100%" type="button" style="iconButton" tooltip_style="sessionToolTipBold" hidden="true">
    66                     <object name="diplomacyPlayerTributeMetalImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/metal.png" ghost="true"/>
     56                <object size="430 0 100%-40 100%">
     57                    <repeat count="8" var="r">
     58                        <object name="diplomacyPlayer[n]_tribute[r]" size="0 0 20 100%" type="button" style="iconButton" tooltip_style="sessionToolTipBold" hidden="true">
     59                            <object name="diplomacyPlayer[n]_tribute[r]_image" type="image" size="0 0 100% 100%" ghost="true"/>
     60                        </object>
     61                    </repeat>
    6762                </object>
    6863
    6964                <object name="diplomacyAttackRequest[n]" size="100%-20 0 100% 100%" type="button" style="iconButton" tooltip_style="sessionToolTipBold" hidden="true">
  • binaries/data/mods/public/gui/session/menu.js

    diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js
    index 494bd14..e6c2cf9 100644
    a b const INITIAL_MENU_POSITION = "100%-164 " + MENU_TOP + " 100% " + MENU_BOTTOM;  
    2222// Number of pixels per millisecond to move
    2323const MENU_SPEED = 1.2;
    2424
    25 // Available resources in trade and tribute menu
    26 const RESOURCES = ["food", "wood", "stone", "metal"];
    27 
    2825// Trade menu: step for probability changes
    2926const STEP = 5;
    3027
    function closeChat()  
    227224    Engine.GetGUIObjectByName("chatDialogPanel").hidden = true;
    228225}
    229226
     227function initDiplomacy()
     228{
     229    let dialog = Engine.GetGUIObjectByName("diplomacyDialogPanel");
     230    let size = dialog.size;
     231    let width = size.right - size.left;
     232
     233    let tribSize = Engine.GetGUIObjectByName("diplomacyPlayer[0]_tribute[0]").size;
     234    width += g_ResourceData.GetCodes().length * (tribSize.right - tribSize.left);
     235
     236    size.left = -width / 2;
     237    size.right = width / 2;
     238    dialog.size = size;
     239
     240    initDiplomacy = () => {};
     241}
     242
    230243function openDiplomacy()
    231244{
    232245    closeOpenDialogs();
     246    initDiplomacy();
    233247
    234248    if (g_ViewedPlayer < 1)
    235249        return;
    function openDiplomacy()  
    254268        diplomacyFormatTributeButtons(i, myself || playerInactive);
    255269        diplomacyFormatAttackRequestButton(i, myself || playerInactive || isCeasefireActive || !hasAllies || !g_Players[i].isEnemy[g_ViewedPlayer]);
    256270    }
    257 
    258271    Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = false;
    259272}
    260273
    function diplomacyFormatStanceButtons(i, hidden)  
    305318
    306319function diplomacyFormatTributeButtons(i, hidden)
    307320{
    308     for (let resource of RESOURCES)
     321    let resNames = g_ResourceData.GetNames();
     322    let resCodes = g_ResourceData.GetCodes();
     323    let r = 0;
     324    for (let resCode of resCodes)
    309325    {
    310         let button = Engine.GetGUIObjectByName("diplomacyPlayerTribute"+resource[0].toUpperCase()+resource.substring(1)+"["+(i-1)+"]");
     326        let button = Engine.GetGUIObjectByName("diplomacyPlayer["+(i-1)+"]_tribute["+r+"]");
     327        if (!button)
     328            break;
     329        Engine.GetGUIObjectByName("diplomacyPlayer["+(i-1)+"]_tribute["+r+"]_image").sprite = "stretched:session/icons/resources/"+resCode+".png";
    311330        button.hidden = hidden;
     331        setPanelObjectPosition(button, r, 8, 0);
     332        ++r;
    312333        if (hidden)
    313334            continue;
    314335
    315336        button.enabled = controlsPlayer(g_ViewedPlayer);
    316         button.tooltip = formatTributeTooltip(i, resource, 100);
    317         button.onpress = (function(i, resource, button) {
     337        button.tooltip = formatTributeTooltip(i, resNames[resCode], 100);
     338        button.onpress = (function(i, resCode, button) {
    318339            // Shift+click to send 500, shift+click+click to send 1000, etc.
    319340            // See INPUT_MASSTRIBUTING in input.js
    320341            let multiplier = 1;
    function diplomacyFormatTributeButtons(i, hidden)  
    327348                }
    328349
    329350                let amounts = {};
    330                 for (let type of RESOURCES)
    331                     amounts[type] = 0;
    332                 amounts[resource] = 100 * multiplier;
     351                for (let res of resCodes)
     352                    amounts[res] = 0;
     353                amounts[resCode] = 100 * multiplier,
    333354
    334                 button.tooltip = formatTributeTooltip(i, resource, amounts[resource]);
     355                button.tooltip = formatTributeTooltip(i, resNames[resCode], amounts[resCode]);
    335356
    336357                // This is in a closure so that we have access to `player`, `amounts`, and `multiplier` without some
    337358                // evil global variable hackery.
    338359                g_FlushTributing = function() {
    339360                    Engine.PostNetworkCommand({ "type": "tribute", "player": i, "amounts":  amounts });
    340361                    multiplier = 1;
    341                     button.tooltip = formatTributeTooltip(i, resource, 100);
     362                    button.tooltip = formatTributeTooltip(i, resNames[resCode], 100);
    342363                };
    343364
    344365                if (!isBatchTrainPressed)
    345366                    g_FlushTributing();
    346367            };
    347         })(i, resource, button);
     368        })(i, resCode, button);
    348369    }
    349370}
    350371
    function toggleDiplomacy()  
    377398        openDiplomacy();
    378399}
    379400
     401function initTrade()
     402{
     403    let dialog = Engine.GetGUIObjectByName("tradeDialogPanel");
     404    let size = dialog.size;
     405    let width = size.right - size.left;
     406
     407    let tradeSize = Engine.GetGUIObjectByName("tradeResource[0]").size;
     408    width += g_ResourceData.GetCodes().length * (tradeSize.right - tradeSize.left);
     409
     410    size.left = -width / 2;
     411    size.right = width / 2;
     412    dialog.size = size;
     413
     414    initTrade = () => {};
     415}
     416
    380417function openTrade()
    381418{
    382419    closeOpenDialogs();
     420    initTrade();
    383421
    384422    if (g_ViewedPlayer < 1)
    385423        return;
    function openTrade()  
    388426
    389427    var updateButtons = function()
    390428    {
    391         for (var res in button)
     429        for (let res in button)
    392430        {
    393431            button[res].label.caption = proba[res] + "%";
    394432
    function openTrade()  
    398436        }
    399437    };
    400438
    401     var proba = Engine.GuiInterfaceCall("GetTradingGoods", g_ViewedPlayer);
    402     var button = {};
    403     var selec = RESOURCES[0];
    404     for (var i = 0; i < RESOURCES.length; ++i)
    405     {
    406         var buttonResource = Engine.GetGUIObjectByName("tradeResource["+i+"]");
    407         if (i > 0)
    408         {
    409             var size = Engine.GetGUIObjectByName("tradeResource["+(i-1)+"]").size;
    410             var width = size.right - size.left;
    411             size.left += width;
    412             size.right += width;
    413             Engine.GetGUIObjectByName("tradeResource["+i+"]").size = size;
    414         }
    415         var resource = RESOURCES[i];
    416         proba[resource] = (proba[resource] ? proba[resource] : 0);
    417         var buttonResource = Engine.GetGUIObjectByName("tradeResourceButton["+i+"]");
    418         var icon = Engine.GetGUIObjectByName("tradeResourceIcon["+i+"]");
    419         icon.sprite = "stretched:session/icons/resources/" + resource + ".png";
    420         var label = Engine.GetGUIObjectByName("tradeResourceText["+i+"]");
    421         var buttonUp = Engine.GetGUIObjectByName("tradeArrowUp["+i+"]");
    422         var buttonDn = Engine.GetGUIObjectByName("tradeArrowDn["+i+"]");
    423         var iconSel = Engine.GetGUIObjectByName("tradeResourceSelection["+i+"]");
    424         button[resource] = { "up": buttonUp, "dn": buttonDn, "label": label, "sel": iconSel };
     439    let proba = Engine.GuiInterfaceCall("GetTradingGoods", g_ViewedPlayer);
     440    let button = {};
     441    let resCodes = g_ResourceData.GetCodes();
     442    let selec = resCodes[0];
     443    hideRemaining("tradeResources", resCodes.length);
     444    Engine.GetGUIObjectByName("tradeHelp").hidden = false;
    425445
     446    for (let i = 0; i < resCodes.length; ++i)
     447    {
     448        if (!Engine.GetGUIObjectByName("tradeResource["+i+"]"))
     449            break;
     450        setPanelObjectPosition(Engine.GetGUIObjectByName("tradeResource["+i+"]"), i, 8);
     451        let resCode = resCodes[i];
     452        proba[resCode] = proba[resCode] || 0;
     453        let icon = Engine.GetGUIObjectByName("tradeResourceIcon["+i+"]");
     454        icon.sprite = "stretched:session/icons/resources/" + resCode + ".png";
     455        let label = Engine.GetGUIObjectByName("tradeResourceText["+i+"]");
     456        let buttonUp = Engine.GetGUIObjectByName("tradeArrowUp["+i+"]");
     457        let buttonDn = Engine.GetGUIObjectByName("tradeArrowDn["+i+"]");
     458        let iconSel = Engine.GetGUIObjectByName("tradeResourceSelection["+i+"]");
     459        button[resCode] = { "up": buttonUp, "dn": buttonDn, "label": label, "sel": iconSel };
     460
     461        let buttonResource = Engine.GetGUIObjectByName("tradeResourceButton["+i+"]");
    426462        buttonResource.enabled = controlsPlayer(g_ViewedPlayer);
    427463        buttonResource.onpress = (function(resource){
    428464            return function() {
    429465                if (Engine.HotkeyIsPressed("session.fulltradeswap"))
    430466                {
    431                     for (var ress of RESOURCES)
    432                         proba[ress] = 0;
     467                    for (let res of resCodes)
     468                        proba[res] = 0;
    433469                    proba[resource] = 100;
    434470                    Engine.PostNetworkCommand({"type": "set-trading-goods", "tradingGoods": proba});
    435471                }
    436472                selec = resource;
    437473                updateButtons();
    438474            };
    439         })(resource);
     475        })(resCode);
    440476
    441477        buttonUp.enabled = controlsPlayer(g_ViewedPlayer);
    442478        buttonUp.onpress = (function(resource){
    function openTrade()  
    446482                Engine.PostNetworkCommand({"type": "set-trading-goods", "tradingGoods": proba});
    447483                updateButtons();
    448484            };
    449         })(resource);
     485        })(resCode);
    450486
    451487        buttonDn.enabled = controlsPlayer(g_ViewedPlayer);
    452488        buttonDn.onpress = (function(resource){
    function openTrade()  
    456492                Engine.PostNetworkCommand({"type": "set-trading-goods", "tradingGoods": proba});
    457493                updateButtons();
    458494            };
    459         })(resource);
     495        })(resCode);
    460496    }
    461497    updateButtons();
    462498
    463499    let traderNumber = Engine.GuiInterfaceCall("GetTraderNumber", g_ViewedPlayer);
    464500    Engine.GetGUIObjectByName("landTraders").caption = getIdleLandTradersText(traderNumber);
    465501    Engine.GetGUIObjectByName("shipTraders").caption = getIdleShipTradersText(traderNumber);
    466 
    467502    Engine.GetGUIObjectByName("tradeDialogPanel").hidden = false;
    468503}
    469504
  • binaries/data/mods/public/gui/session/selection_details.js

    diff --git a/binaries/data/mods/public/gui/session/selection_details.js b/binaries/data/mods/public/gui/session/selection_details.js
    index 29acc09..36fa2a6 100644
    a b function layoutSelectionMultiple()  
    1313function getResourceTypeDisplayName(resourceType)
    1414{
    1515    let resourceCode = resourceType.generic;
    16     if (resourceCode == "treasure")
    17         return getLocalizedResourceName(resourceType.specific, "firstWord");
    18     else
    19         return getLocalizedResourceName(resourceCode, "firstWord");
     16    let resourceName = g_ResourceData.GetNames()[(resourceCode == "treasure" ? resourceType.specific : resourceCode)]
     17    return getLocalizedResourceName(resourceName, "firstWord");
    2018}
    2119
    2220// Updates the health bar of garrisoned units
  • binaries/data/mods/public/gui/session/selection_panels.js

    diff --git a/binaries/data/mods/public/gui/session/selection_panels.js b/binaries/data/mods/public/gui/session/selection_panels.js
    index c21fc4f..ceae7a9 100644
    a b let g_FormationsInfo = new Map();  
    3434
    3535let g_SelectionPanels = {};
    3636
     37let g_BarterSell;
     38
    3739g_SelectionPanels.Alert = {
    3840    "getMaxNumberOfItems": function()
    3941    {
    g_SelectionPanels.Alert = {  
    8789g_SelectionPanels.Barter = {
    8890    "getMaxNumberOfItems": function()
    8991    {
    90         return 4;
     92        return 8;
    9193    },
    9294    "rowLength": 4,
    9395    "getItems": function(unitEntState, selection)
    9496    {
    9597        if (!unitEntState.barterMarket)
    9698            return [];
    97         // ["food", "wood", "stone", "metal"]
    98         return BARTER_RESOURCES;
     99        return g_ResourceData.GetCodes();
    99100    },
    100101    "setupButton": function(data)
    101102    {
    g_SelectionPanels.Barter = {  
    115116        if (Engine.HotkeyIsPressed("session.massbarter"))
    116117            amountToSell *= BARTER_BUNCH_MULTIPLIER;
    117118
     119        if (!g_BarterSell)
     120            g_BarterSell = g_ResourceData.GetCodes()[0];
     121
    118122        amount.Sell.caption = "-" + amountToSell;
    119123        let prices = data.unitEntState.barterMarket.prices;
    120124        amount.Buy.caption = "+" + Math.round(prices.sell[g_BarterSell] / prices.buy[data.item] * amountToSell);
    121125
    122         let resource = getLocalizedResourceName(data.item, "withinSentence");
     126        let resource = getLocalizedResourceName(g_ResourceData.GetNames()[data.item], "firstWord");
    123127        button.Buy.tooltip = sprintf(translate("Buy %(resource)s"), { "resource": resource });
    124128        button.Sell.tooltip = sprintf(translate("Sell %(resource)s"), { "resource": resource });
    125129
    g_SelectionPanels.Barter = {  
    164168        button.Sell.hidden = false;
    165169        selectionIcon.hidden = !isSelected;
    166170
    167         setPanelObjectPosition(button.Sell, data.i, data.rowLength);
    168         setPanelObjectPosition(button.Buy, data.i + data.rowLength, data.rowLength);
     171        let sellPos = data.i + (data.i >= data.rowLength ? data.rowLength : 0);
     172        let buyPos = data.i + data.rowLength * (data.i >= data.rowLength ? 2 : 1);
     173        setPanelObjectPosition(button.Sell, sellPos, data.rowLength);
     174        setPanelObjectPosition(button.Buy, buyPos, data.rowLength);
    169175        return true;
    170176    }
    171177};
  • binaries/data/mods/public/gui/session/selection_panels_helpers.js

    diff --git a/binaries/data/mods/public/gui/session/selection_panels_helpers.js b/binaries/data/mods/public/gui/session/selection_panels_helpers.js
    index fc0e7a6..46976f9 100644
    a b  
    11const BARTER_RESOURCE_AMOUNT_TO_SELL = 100;
    22const BARTER_BUNCH_MULTIPLIER = 5;
    3 const BARTER_RESOURCES = ["food", "wood", "stone", "metal"];
    43const BARTER_ACTIONS = ["Sell", "Buy"];
    54const GATE_ACTIONS = ["lock", "unlock"];
    65
    7 // upgrade constants
    86const UPGRADING_NOT_STARTED = -2;
    97const UPGRADING_CHOSEN_OTHER = -1;
    108
    11 // ==============================================
    12 // BARTER HELPERS
    13 // Resources to sell on barter panel
    14 var g_BarterSell = "food";
    15 
    169function canMoveSelectionIntoFormation(formationTemplate)
    1710{
    1811    if (!(formationTemplate in g_canMoveIntoFormation))
  • binaries/data/mods/public/gui/session/selection_panels_left/barter_panel.xml

    diff --git a/binaries/data/mods/public/gui/session/selection_panels_left/barter_panel.xml b/binaries/data/mods/public/gui/session/selection_panels_left/barter_panel.xml
    index f32e117..717efce 100644
    a b  
    11<?xml version="1.0" encoding="utf-8"?>
    22<object name="unitBarterPanel"
    3     size="6 36 100% 100%"
     3    size="24 12 100% 100%"
    44    hidden="true"
    55>
    6     <object ghost="true" style="resourceText" type="text" size="0 0 100% 20">
    7         <translatableAttribute id="tooltip">Exchange resources:</translatableAttribute>
    8     </object>
    9     <object size="0 32 100% 124">
    10         <repeat count="4">
    11             <!-- sell -->
    12             <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    13                 <object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    14                 <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    15                 <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
    16             </object>
    17             <!-- buy -->
    18             <object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    19                 <object name="unitBarterBuyIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    20                 <object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    21             </object>
    22         </repeat>
    23     </object>
     6
     7    <repeat count="8">
     8
     9        <!-- Sell -->
     10        <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" hidden="true">
     11            <object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
     12            <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
     13            <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 33 33" sprite="stretched:session/icons/corners.png"/>
     14        </object>
     15
     16        <!-- Buy -->
     17        <object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" hidden="true">
     18            <object name="unitBarterBuyIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
     19            <object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
     20        </object>
     21
     22    </repeat>
     23
    2424</object>
  • binaries/data/mods/public/gui/session/session.js

    diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js
    index 35af7a7..22a41b6 100644
    a b var g_EntityStates = {};  
    122122var g_TemplateData = {};
    123123var g_TemplateDataWithoutLocalization = {};
    124124var g_TechnologyData = {};
     125var g_ResourceData = new Resources();
    125126
    126127/**
    127128 * Top coordinate of the research list.
    function updateTopPanel()  
    463464    let viewPlayer = Engine.GetGUIObjectByName("viewPlayer");
    464465    viewPlayer.hidden = !g_IsObserver && !g_DevSettings.changePerspective;
    465466
    466     Engine.GetGUIObjectByName("food").hidden = !isPlayer;
    467     Engine.GetGUIObjectByName("wood").hidden = !isPlayer;
    468     Engine.GetGUIObjectByName("stone").hidden = !isPlayer;
    469     Engine.GetGUIObjectByName("metal").hidden = !isPlayer;
     467    let resCodes = g_ResourceData.GetCodes();
     468    let resNames = g_ResourceData.GetNames();
     469    let r = 0;
     470    for (let res of resCodes)
     471    {
     472        if (!Engine.GetGUIObjectByName("resource["+r+"]"))
     473        {
     474            warn("Current GUI limits prevent displaying more than eight (8) resources");
     475            break;
     476        }
     477        Engine.GetGUIObjectByName("resource["+r+"]_icon").sprite = "stretched:session/icons/resources/" + res + ".png";
     478        Engine.GetGUIObjectByName("resource["+r+"]").hidden = !isPlayer;
     479        ++r;
     480    }
     481    horizontallyDistributeObjects("resourceCounts", 0, r);
     482    hideRemaining("resourceCounts", r);
     483
    470484    Engine.GetGUIObjectByName("population").hidden = !isPlayer;
    471485    Engine.GetGUIObjectByName("diplomacyButton1").hidden = !isPlayer;
    472486    Engine.GetGUIObjectByName("tradeButton1").hidden = !isPlayer;
    function leaveGame(willRejoin)  
    547561            "disconnected": g_Disconnected,
    548562            "isReplay": g_IsReplay,
    549563            "replayDirectory": !g_HasRejoined && replayDirectory,
    550             "replaySelectionData": g_ReplaySelectionData
     564            "replaySelectionData": g_ReplaySelectionData,
     565            "resources": GetSimState().resources
    551566        }
    552567    });
    553568}
    function getAllyStatTooltip(resource)  
    947962
    948963function updatePlayerDisplay()
    949964{
    950     let playerState = GetSimState().players[g_ViewedPlayer];
     965    let simState = GetSimState();
     966    let playerState = simState.players[g_ViewedPlayer];
    951967    if (!playerState)
    952968        return;
    953969
    954     for (let res of RESOURCES)
     970    let resCodes = g_ResourceData.GetCodes();
     971    let resNames = g_ResourceData.GetNames();
     972    for (let r = 0; r < resCodes.length; ++r)
    955973    {
    956         Engine.GetGUIObjectByName("resource_" + res).caption = Math.floor(playerState.resourceCounts[res]);
    957         Engine.GetGUIObjectByName(res).tooltip = getLocalizedResourceName(res, "firstWord") + getAllyStatTooltip(res);
     974        if (!Engine.GetGUIObjectByName("resource["+r+"]"))
     975            break;
     976        let res = resCodes[r];
     977        Engine.GetGUIObjectByName("resource["+r+"]").tooltip = getLocalizedResourceName(resNames[res], "firstWord") + getAllyStatTooltip(res);
     978        Engine.GetGUIObjectByName("resource["+r+"]_count").caption = Math.floor(playerState.resourceCounts[res]);
    958979    }
    959980
    960981    Engine.GetGUIObjectByName("resourcePop").caption = sprintf(translate("%(popCount)s/%(popLimit)s"), playerState);
  • deleted file binaries/data/mods/public/gui/session/top_panel/resource_food.xml

    diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_food.xml b/binaries/data/mods/public/gui/session/top_panel/resource_food.xml
    deleted file mode 100644
    index 4d84ca7..0000000
    + -  
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <object name="food" size="10 0 100 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png" ghost="true"/>
    4         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_food"/>
    5 </object>
  • deleted file binaries/data/mods/public/gui/session/top_panel/resource_metal.xml

    diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_metal.xml b/binaries/data/mods/public/gui/session/top_panel/resource_metal.xml
    deleted file mode 100644
    index 4edba79..0000000
    + -  
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <object name="metal" size="280 0 370 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png" ghost="true"/>
    4         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_metal"/>
    5 </object>
  • binaries/data/mods/public/gui/session/top_panel/resource_population.xml

    diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_population.xml b/binaries/data/mods/public/gui/session/top_panel/resource_population.xml
    index 9c9dcc2..9d66e40 100644
    a b  
    11<?xml version="1.0" encoding="utf-8"?>
    2 <object name="population" size="370 0 460 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
     2<object name="population" size="50%-90-52 0 50%-52 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    33    <object size="0 -4 40 34" type="image" sprite="stretched:session/icons/resources/population.png" ghost="true"/>
    44    <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourcePop"/>
    55</object>
  • deleted file binaries/data/mods/public/gui/session/top_panel/resource_stone.xml

    diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_stone.xml b/binaries/data/mods/public/gui/session/top_panel/resource_stone.xml
    deleted file mode 100644
    index 6133acc..0000000
    + -  
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <object name="stone" size="190 0 280 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png" ghost="true"/>
    4         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_stone"/>
    5 </object>
  • deleted file binaries/data/mods/public/gui/session/top_panel/resource_wood.xml

    diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_wood.xml b/binaries/data/mods/public/gui/session/top_panel/resource_wood.xml
    deleted file mode 100644
    index f020979..0000000
    + -  
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <object name="wood" size="100 0 190 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png" ghost="true"/>
    4         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_wood"/>
    5 </object>
  • new file inaries/data/mods/public/gui/session/top_panel/resources.xml

    diff --git a/binaries/data/mods/public/gui/session/top_panel/resources.xml b/binaries/data/mods/public/gui/session/top_panel/resources.xml
    new file mode 100644
    index 0000000..520aa35
    - +  
     1<?xml version="1.0" encoding="utf-8"?>
     2
     3<object size="10 0 50%-90-52 100%" name="resourceCounts">
     4  <repeat count="8">
     5    <object name="resource[n]" size="0 0 90 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
     6      <object size="0 -4 40 36" type="image" name="resource[n]_icon" ghost="true"/>
     7      <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource[n]_count"/>
     8    </object>
     9  </repeat>
     10</object>
  • binaries/data/mods/public/gui/session/trade_window.xml

    diff --git a/binaries/data/mods/public/gui/session/trade_window.xml b/binaries/data/mods/public/gui/session/trade_window.xml
    index 80b226c..4e1e5e0 100644
    a b  
    11<?xml version="1.0" encoding="utf-8"?>
    22<object name="tradeDialogPanel"
    3     size="50%-250 50%-130 50%+250 50%+100"
     3    size="50%-134 50%-130 50%+134 50%+100"
    44    type="image"
    55    hidden="true"
    66    sprite="ModernDialog"
     
    1515            <translatableAttribute id="caption">Trading goods selection:</translatableAttribute>
    1616        </object>
    1717
    18         <object size="180 0 100% 100%">
    19             <repeat count="4">
     18        <object size="180 0 100% 100%" name="tradeResources">
     19            <repeat count="8">
    2020                <object name="tradeResource[n]" size="0 0 58 32">
    2121                    <object name="tradeResourceButton[n]" size="4 0 36 100%" type="button" style="StoneButton">
    2222                        <object name="tradeResourceIcon[n]" type="image" ghost="true"/>
  • binaries/data/mods/public/gui/structree/draw.js

    diff --git a/binaries/data/mods/public/gui/structree/draw.js b/binaries/data/mods/public/gui/structree/draw.js
    index 92c60ce..c81f1e5 100644
    a b function draw()  
    112112                if (p>c)
    113113                    c = p;
    114114
    115                 hideRemaining("phase["+i+"]_struct["+s+"]_row["+r+"]_prod[", p, "]");
     115                hideRemaining("phase["+i+"]_struct["+s+"]_row["+r+"]", p);
    116116            }
    117117
    118118            let size = thisEle.size;
    function draw()  
    132132                phaEle.size = size;
    133133            }
    134134            ++r;
    135             hideRemaining("phase["+i+"]_struct["+s+"]_row[", r, "]");
     135            hideRemaining("phase["+i+"]_struct["+s+"]_rows", r);
    136136            ++s;
    137137        }
    138         hideRemaining("phase["+i+"]_struct[", s, "]");
     138        hideRemaining("phase["+i+"]", s);
    139139        ++i;
    140140    }
    141141   
    function draw()  
    179179                ++p;
    180180            }
    181181        }
    182         hideRemaining("trainer["+t+"]_prod[", p, "]");
     182        hideRemaining("trainer["+t+"]_row", p);
    183183
    184184        let size = thisEle.size;
    185185        size.right = size.left + Math.max(p*24, defWidth) + 4;
    function draw()  
    193193        phaEle.size = size;
    194194        ++t;
    195195    }
    196     hideRemaining("trainer[", t, "]");
     196    hideRemaining("trainers", t);
    197197
    198198    let size = Engine.GetGUIObjectByName("display_tree").size;
    199199    size.right = t > 0 ? -124 : -4;
    function getPositionOffset(idx)  
    235235    return size;
    236236}
    237237
    238 function hideRemaining(prefix, idx, suffix)
    239 {
    240     let obj = Engine.GetGUIObjectByName(prefix + idx + suffix);
    241     while (obj)
    242     {
    243         obj.hidden = true;
    244         ++idx;
    245         obj = Engine.GetGUIObjectByName(prefix + idx + suffix);
    246     }
    247 }
    248 
    249 
    250238/**
    251239 * Positions certain elements that only need to be positioned once
    252240 * (as <repeat> does not reposition automatically).
    function predraw()  
    283271            prodBarIcon.sprite = "stretched:session/portraits/"+g_ParsedData.phases[phaseList[i+j]].icon;
    284272        }
    285273        // Hide remaining prod bars
    286         hideRemaining("phase["+i+"]_bar[", j-1, "]");
     274        hideRemaining("phase["+i+"]_bars", j-1);
    287275
    288276        let s = 0;
    289277        let ele = Engine.GetGUIObjectByName("phase["+i+"]_struct["+s+"]");
    function predraw()  
    334322        g_DrawLimits[pha].structQuant = s;
    335323        ++i;
    336324    }
    337     hideRemaining("phase[", i, "]");
    338     hideRemaining("phase[", i, "]_bar");
    339    
     325    hideRemaining("phase_rows", i);
     326    hideRemaining("phase_ident", i);
     327
    340328    let t = 0;
    341329    let ele = Engine.GetGUIObjectByName("trainer["+t+"]");
    342330    g_DrawLimits.trainer = {
  • binaries/data/mods/public/gui/structree/load.js

    diff --git a/binaries/data/mods/public/gui/structree/load.js b/binaries/data/mods/public/gui/structree/load.js
    index 534747b..dfeb24a 100644
    a b  
    55 */
    66function getGatherRates(templateName)
    77{
    8     // TODO: It would be nice to use the gather rates present in the templates
    9     // instead of hard-coding the possible rates here.
    10 
    11     // We ignore ruins here, as those are not that common and would skew the results
    12     var types = {
    13         "food": ["food", "food.fish", "food.fruit", "food.grain", "food.meat", "food.milk"],
    14         "wood": ["wood", "wood.tree"],
    15         "stone": ["stone", "stone.rock"],
    16         "metal": ["metal", "metal.ore"]
    17     };
    18     var rates = {};
     8    let rates = {};
    199
    20     for (let type in types)
     10    for (let resource of g_ResourceData.GetData())
    2111    {
     12        let types = [resource.code];
     13        for (let subtype of resource.subtypes)
     14            // We ignore ruins as those are not that common and skew the results
     15            if (subtype !== "ruins")
     16                types.push(resource.code + "." + subtype);
     17
    2218        let count, rate;
    23         [rate, count] = types[type].reduce(function(sum, t) {
     19        [rate, count] = types.reduce((sum, t) => {
    2420                let r = +fetchValue(templateName, "ResourceGatherer/Rates/"+t);
    2521                return [sum[0] + (r > 0 ? r : 0), sum[1] + (r > 0 ? 1 : 0)];
    2622            }, [0, 0]);
    2723
    2824        if (rate > 0)
    29             rates[type] = Math.round(rate / count * 100) / 100;
     25            rates[resource.code] = +(rate / count).toFixed(1);
    3026    }
    3127
    3228    if (!Object.keys(rates).length)
  • binaries/data/mods/public/gui/structree/rows.xml

    diff --git a/binaries/data/mods/public/gui/structree/rows.xml b/binaries/data/mods/public/gui/structree/rows.xml
    index f6d700f..fdffe3c 100644
    a b  
    99                    <object type="image" style="StructIcon" name="phase[k]_struct[s]_icon"
    1010                        sprite="stretched:pregame/shell/logo/wfg_logo_white.png"
    1111                    />
    12                     <repeat count="4" var="r">
    13                         <object name="phase[k]_struct[s]_row[r]">
    14                             <repeat count="24" var="p">
    15                                 <object type="image" style="ProdBox" name="phase[k]_struct[s]_row[r]_prod[p]"/>
    16                             </repeat>
    17                         </object>
    18                     </repeat>
    19                 </object>   
     12                    <object name="phase[k]_struct[s]_rows">
     13                        <repeat count="4" var="r">
     14                            <object name="phase[k]_struct[s]_row[r]">
     15                                <repeat count="24" var="p">
     16                                    <object type="image" style="ProdBox" name="phase[k]_struct[s]_row[r]_prod[p]"/>
     17                                </repeat>
     18                            </object>
     19                        </repeat>
     20                    </object>
     21                </object>
    2022            </repeat>
    2123        </object>
    2224    </repeat>
  • binaries/data/mods/public/gui/structree/structree.js

    diff --git a/binaries/data/mods/public/gui/structree/structree.js b/binaries/data/mods/public/gui/structree/structree.js
    index 65bfd9e..fcb6a9c 100644
    a b var g_Lists = {};  
    99var g_CivData = {};
    1010var g_SelectedCiv = "";
    1111var g_CallbackSet = false;
     12var g_ResourceData = new Resources();
    1213
    1314/**
    1415 * Initialize the dropdown containing all the available civs
  • binaries/data/mods/public/gui/structree/structree.xml

    diff --git a/binaries/data/mods/public/gui/structree/structree.xml b/binaries/data/mods/public/gui/structree/structree.xml
    index 4165e1c..2e35b38 100644
    a b  
    6363
    6464        <!-- Structure Tree display -->
    6565        <object size="0 54+64 100%-124 100%-54" name="display_tree">
    66             <repeat count="4" var="n">
    67                 <object name="phase[n]_phase" type="image"/>
    68                 <object name="phase[n]_bar">
    69                     <repeat count="4" var="k">
    70                         <object name="phase[n]_bar[k]" type="image" sprite="ProdBar">
    71                             <object name="phase[n]_bar[k]_icon" type="image" size="2 2 20 20"/>
     66            <object name="phase_ident">
     67                <repeat count="4" var="n">
     68                    <object>
     69                        <object name="phase[n]_phase" type="image"/>
     70                        <object name="phase[n]_bars">
     71                            <repeat count="4" var="k">
     72                                <object name="phase[n]_bar[k]" type="image" sprite="ProdBar">
     73                                    <object name="phase[n]_bar[k]_icon" type="image" size="2 2 20 20"/>
     74                                </object>
     75                            </repeat>
    7276                        </object>
    73                     </repeat>
    74                 </object>
    75             </repeat>
     77                    </object>
     78                </repeat>
     79            </object>
    7680
    7781            <object type="image" style="TreeDisplay" size="48+16+8 0 100%-12 100%">
    7882                <include file="gui/structree/rows.xml"/>
     
    9296                <translatableAttribute id="caption">Trainer Units</translatableAttribute>
    9397            </object>
    9498           
    95             <object type="image" style="TreeDisplay" size="0 24 100% 100%">
     99            <object type="image" style="TreeDisplay" size="0 24 100% 100%" name="trainers">
    96100                <repeat count="3" var="t">
    97101                    <object type="image" style="StructBox" name="trainer[t]">
    98102                        <object type="text" style="StructNameSpecific" name="trainer[t]_name"/>
  • binaries/data/mods/public/gui/summary/counters.js

    diff --git a/binaries/data/mods/public/gui/summary/counters.js b/binaries/data/mods/public/gui/summary/counters.js
    index 562e3bb..36b1812 100644
    a b function updateCountersPlayer(playerState, counters, idGUI)  
    6363{
    6464    for (let w in counters)
    6565    {
     66        if (!Engine.GetGUIObjectByName(idGUI + "[" + w + "]"))
     67            break;
    6668        let fn = counters[w].fn;
    6769        Engine.GetGUIObjectByName(idGUI + "[" + w + "]").caption = fn && fn(playerState, w);
    6870    }
    function calculateUnits(playerState, position)  
    250252
    251253function calculateResources(playerState, position)
    252254{
    253     let type = g_ResourcesTypes[position];
     255    let type = g_ResourceData.GetCodes()[position];
    254256
    255257    return formatIncome(
    256258        playerState.statistics.resourcesGathered[type],
    function calculateTotalResources(playerState)  
    262264    let totalGathered = 0;
    263265    let totalUsed = 0;
    264266
    265     for (let type of g_ResourcesTypes)
     267    for (let type of g_ResourceData.GetCodes())
    266268    {
    267269        totalGathered += playerState.statistics.resourcesGathered[type];
    268270        totalUsed += playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type];
    function calculateResourcesTeam(counters)  
    330332
    331333function calculateResourceExchanged(playerState, position)
    332334{
    333     let type = g_ResourcesTypes[position];
     335    let type = g_ResourceData.GetCodes()[position];
    334336
    335337    return formatIncome(
    336338        playerState.statistics.resourcesBought[type],
  • binaries/data/mods/public/gui/summary/layout.js

    diff --git a/binaries/data/mods/public/gui/summary/layout.js b/binaries/data/mods/public/gui/summary/layout.js
    index 7feeb45..efb20e9 100644
    a b var g_ScorePanelsData = {  
    9292    "resources": {
    9393        "headings": [
    9494            { "caption": translate("Player name"), "yStart": 26, "width": 200 },
    95             { "caption": translate("Food"), "yStart": 34, "width": 100 },
    96             { "caption": translate("Wood"), "yStart": 34, "width": 100 },
    97             { "caption": translate("Stone"), "yStart": 34, "width": 100 },
    98             { "caption": translate("Metal"), "yStart": 34, "width": 100 },
    9995            { "caption": translate("Total"), "yStart": 34, "width": 110 },
    10096            {
    10197                "caption": sprintf(translate("Tributes \n(%(sent)s / %(received)s)"),
    var g_ScorePanelsData = {  
    121117            }, // width = 510
    122118        ],
    123119        "counters": [
    124             { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
    125             { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
    126             { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
    127             { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
    128120            { "width": 110, "fn": calculateTotalResources, "verticalOffset": 12 },
    129121            { "width": 121, "fn": calculateTributeSent, "verticalOffset": 12 },
    130122            { "width": 100, "fn": calculateTreasureCollected, "verticalOffset": 12 },
    var g_ScorePanelsData = {  
    135127    "market": {
    136128        "headings": [
    137129            { "caption": translate("Player name"), "yStart": 26, "width": 200 },
    138             { "caption": translate("Food exchanged"), "yStart": 16, "width": 100 },
    139             { "caption": translate("Wood exchanged"), "yStart": 16, "width": 100 },
    140             { "caption": translate("Stone exchanged"), "yStart": 16, "width": 100 },
    141             { "caption": translate("Metal exchanged"), "yStart": 16, "width": 100 },
    142130            { "caption": translate("Barter efficiency"), "yStart": 16, "width": 100 },
    143131            { "caption": translate("Trade income"), "yStart": 16, "width": 100 }
    144132        ],
    145133        "titleHeadings": [],
    146134        "counters": [
    147             { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
    148             { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
    149             { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
    150             { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
    151135            { "width": 100, "fn": calculateBarterEfficiency, "verticalOffset": 12 },
    152136            { "width": 100, "fn": calculateTradeIncome, "verticalOffset": 12 }
    153137        ],
    function updateGeneralPanelHeadings(headings)  
    206190            headerGUIName = "Heading[" + (h - 1) + "]";
    207191
    208192        let headerGUI = Engine.GetGUIObjectByName(headerGUIName);
     193        if (!headerGUI)
     194            break;
    209195        headerGUI.caption = headings[h].caption;
    210196        headerGUI.size = left + " " + headings[h].yStart + " " + (left + headings[h].width) + " 100%";
    211197        headerGUI.hidden = false;
    function updateGeneralPanelCounter(counters)  
    249235        for (let w in counters)
    250236        {
    251237            counterObject = Engine.GetGUIObjectByName("valueData[" + p + "][" + w + "]");
     238            if (!counterObject)
     239                break;
    252240            counterObject.size = left + " " + counters[w].verticalOffset + " " + (left + counters[w].width) + " 100%";
    253241            counterObject.hidden = false;
    254242            left += counters[w].width;
    function updateGeneralPanelCounter(counters)  
    264252            for (let w in counters)
    265253            {
    266254                counterObject = Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]");
     255                if (!counterObject)
     256                    break;
    267257                counterObject.size = left + " " + counters[w].verticalOffset + " " + (left + counters[w].width) + " 100%";
    268258                counterObject.hidden = false;
    269259
  • binaries/data/mods/public/gui/summary/summary.js

    diff --git a/binaries/data/mods/public/gui/summary/summary.js b/binaries/data/mods/public/gui/summary/summary.js
    index 51e5577..7849b1f 100644
    a b  
    1 const g_MaxHeadingTitle= 8;
     1const g_MaxHeadingTitle= 12;
    22
    33// const for filtering long collective headings
    44const g_LongHeadingWidth = 250;
    const g_CapturedColor = '[color="255 255 157"]';  
    1717
    1818const g_BuildingsTypes = [ "total", "House", "Economic", "Outpost", "Military", "Fortress", "CivCentre", "Wonder" ];
    1919const g_UnitsTypes = [ "total", "Infantry", "Worker", "Cavalry", "Champion", "Hero", "Ship", "Trader" ];
    20 const g_ResourcesTypes = [ "food", "wood", "stone", "metal" ];
    2120
    2221// Colors used for gathered and traded resources
    2322const g_IncomeColor = '[color="201 255 200"]';
    var g_PlayerCount = 0;  
    3433// Count players without team (or all if teams are not displayed)
    3534var g_WithoutTeam = 0;
    3635var g_GameData;
     36var g_ResourceData = new Resources();
    3737
    3838function selectPanel(panel)
    3939{
    function init(data)  
    242242    else
    243243        g_Teams = false;
    244244
     245    // Resource names and counters
     246    let resHeads = [];
     247    let tradeHeads = [];
     248    let resPanel = g_ScorePanelsData.resources;
     249    let tradePanel = g_ScorePanelsData.market;
     250    let resNames = g_ResourceData.GetNames();
     251    let resCodes = g_ResourceData.GetCodes();
     252    for (let code of resCodes)
     253    {
     254        resHeads.push({
     255            "caption": translateWithContext("firstWord", resNames[code]),
     256            "yStart": 34,
     257            "width": 100
     258        });
     259
     260        resPanel.counters.unshift({
     261            "width": 100,
     262            "fn": calculateResources,
     263            "verticalOffset": 12
     264        });
     265
     266        tradeHeads.push({
     267            "caption": sprintf(
     268                translate("%(resource)s exchanged"), {
     269                    "resource": translateWithContext("withinSentence", resNames[code])
     270                }),
     271            "yStart": 16,
     272            "width": 100
     273        });
     274
     275        tradePanel.counters.unshift({
     276            "width": 100,
     277            "fn": calculateResourceExchanged,
     278            "verticalOffset": 12
     279        });
     280    }
     281    resPanel.headings.splice.apply(resPanel.headings, [1, 0].concat(resHeads));
     282    resPanel.titleHeadings[0].width = 100 * resCodes.length + 110;
     283    tradePanel.headings.splice.apply(tradePanel.headings, [1, 0].concat(tradeHeads));
     284
    245285    // Erase teams data if teams are not displayed
    246286    if (!g_Teams)
    247287    {
  • binaries/data/mods/public/gui/summary/summary.xml

    diff --git a/binaries/data/mods/public/gui/summary/summary.xml b/binaries/data/mods/public/gui/summary/summary.xml
    index 2c47f16..015638f 100644
    a b  
    103103                <object name="playerNameHeading" type="text" style="ModernLeftTabLabelText">
    104104                    <translatableAttribute id="caption">Player name</translatableAttribute>
    105105                </object>
    106                 <repeat var="x" count="8">
     106                <repeat var="x" count="12">
    107107                    <object name="titleHeading[x]" type="text" style="ModernTabLabelText">
    108108                    </object>
    109109                </repeat>
    110                 <repeat var="x" count="8">
     110                <repeat var="x" count="12">
    111111                    <object name="Heading[x]" type="text" style="ModernTabLabelText">
    112112                    </object>
    113113                </repeat>
     
    124124                                </object>
    125125                                <object name="playerNamet[i][n]" type="text" size="40 2 208 100%" style="ModernLeftLabelText"/>
    126126                                <object name="civIcont[i][n]" type="image" size="208 5 240 37" />
    127                                 <repeat var="x" count="8">
     127                                <repeat var="x" count="12">
    128128                                    <object name="valueDataTeam[i][n][x]" type="text" style="ModernTabLabelText">
    129129                                    </object>
    130130                                </repeat>
     
    132132                        </repeat>
    133133                    </object>
    134134                    <object name="teamHeadingt[i]" type="text" style="ModernLeftTabLabelText"/>
    135                     <repeat var="x" count="8">
     135                    <repeat var="x" count="12">
    136136                        <object name="valueDataTeam[i][x]" type="text" style="ModernTabLabelText">
    137137                        </object>
    138138                    </repeat>
     
    147147                        </object>
    148148                        <object name="playerName[n]" type="text"  size="40 2 208 100%" style="ModernLeftLabelText"/>
    149149                        <object name="civIcon[n]" type="image" size="208 5 240 37"/>
    150                         <repeat var="x" count="8">
     150                        <repeat var="x" count="12">
    151151                            <object name="valueData[n][x]" type="text" style="ModernTabLabelText">
    152152                            </object>
    153153                        </repeat>
  • binaries/data/mods/public/l10n/messages.json

    diff --git a/binaries/data/mods/public/l10n/messages.json b/binaries/data/mods/public/l10n/messages.json
    index 188e3cc..34bd751 100644
    a b  
    289289                    }
    290290                }
    291291            },
    292             {
     292            {
    293293                "extractor": "json",
    294294                "filemasks": [
    295295                    "gui/credits/texts/**.json"
     
    562562                        "description"
    563563                    ]
    564564                }
     565            },
     566            {
     567                "extractor": "json",
     568                "filemasks": [
     569                    "simulation/data/resources/**.json"
     570                ],
     571                "options": {
     572                    "keywords": [
     573                        "name",
     574                        "subtypes"
     575                    ],
     576                    "context": "firstWord"
     577                }
     578            },
     579            {
     580                "extractor": "json",
     581                "filemasks": [
     582                    "simulation/data/resources/**.json"
     583                ],
     584                "options": {
     585                    "keywords": [
     586                        "name",
     587                        "subtypes"
     588                    ],
     589                    "context": "withinSentence"
     590                }
    565591            }
    566592        ]
    567593    },
  • binaries/data/mods/public/simulation/ai/common-api/resources.js

    diff --git a/binaries/data/mods/public/simulation/ai/common-api/resources.js b/binaries/data/mods/public/simulation/ai/common-api/resources.js
    index 8130676..b6fe84b 100644
    a b m.Resources = function(amounts = {}, population = 0)  
    99    this.population = population > 0 ? population : 0;
    1010};
    1111
    12 m.Resources.prototype.types = []; // This array will be filled in SharedScript.init
     12// This array will be filled in SharedScript.init
     13m.Resources.prototype.types = [];
    1314
    1415m.Resources.prototype.reset = function()
    1516{
  • binaries/data/mods/public/simulation/ai/common-api/shared.js

    diff --git a/binaries/data/mods/public/simulation/ai/common-api/shared.js b/binaries/data/mods/public/simulation/ai/common-api/shared.js
    index 68ab45d..0e7b6c5 100644
    a b m.SharedScript.prototype.init = function(state, deserialization)  
    180180    this.accessibility.init(state, this.terrainAnalyzer);
    181181
    182182    // Setup resources
    183     this.resourceTypes = { "food": 0, "wood": 1, "stone": 2, "metal": 2 };
    184     this.resourceList = [];
    185     for (let res in this.resourceTypes)
    186         this.resourceList.push(res);
    187     m.Resources.prototype.types = this.resourceList;
     183    this.resourceInfo = state.resources;
     184    m.Resources.prototype.types = state.resources.codes;
    188185    // Resource types: 0 = not used for resource maps
    189     //                 1 = abondant resource with small amount each
     186    //                 1 = abundant resource with small amount each
    190187    //                 2 = spare resource, but huge amount each
    191188    // The following maps are defined in TerrainAnalysis.js and are used for some building placement (cc, dropsites)
    192189    // They are updated by checking for create and destroy events for all resources
    m.SharedScript.prototype.init = function(state, deserialization)  
    197194    this.ccResourceMaps = {}; // Contains maps showing the density of resources, optimized for CC placement.
    198195    this.createResourceMaps();
    199196
    200     /** Keep in sync with gui/common/l10n.js */
    201     this.resourceNames = {
    202         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    203         "food": markForTranslationWithContext("withinSentence", "Food"),
    204         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    205         "wood": markForTranslationWithContext("withinSentence", "Wood"),
    206         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    207         "metal": markForTranslationWithContext("withinSentence", "Metal"),
    208         // Translation: Word as used in the middle of a sentence (which may require using lowercase for your language).
    209         "stone": markForTranslationWithContext("withinSentence", "Stone"),
    210     };
    211 
    212197    this.gameState = {};
    213198    for (let i in this._players)
    214199    {
  • binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js

    diff --git a/binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js b/binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js
    index 04633dc..0639911 100644
    a b m.Accessibility.prototype.floodFill = function(startIndex, value, onWater)  
    383383/** creates a map of resource density */
    384384m.SharedScript.prototype.createResourceMaps = function()
    385385{
    386     for (let resource of this.resourceList)
     386    for (let resource of this.resourceInfo.codes)
    387387    {
    388         if (this.resourceTypes[resource] !== 1 && this.resourceTypes[resource] !== 2)
     388        if (this.resourceInfo.aiInfluenceGroups[resource] === 0)
    389389            continue;
    390390        // if there is no resourceMap create one with an influence for everything with that resource
    391391        if (this.resourceMaps[resource])
    m.SharedScript.prototype.createResourceMaps = function()  
    405405        let cellSize = this.resourceMaps[resource].cellSize;
    406406        let x = Math.floor(ent.position()[0] / cellSize);
    407407        let z = Math.floor(ent.position()[1] / cellSize);
    408         let type = this.resourceTypes[resource];
    409         let strength = Math.floor(ent.resourceSupplyMax()/this.normalizationFactor[type]);
    410         this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[type]/cellSize, strength/2, "constant");
    411         this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[type]/cellSize, strength/2);
    412         this.ccResourceMaps[resource].addInfluence(x, z, this.ccInfluenceRadius[type]/cellSize, strength, "constant");
     408        let grp = this.resourceInfo.aiInfluenceGroups[resource];
     409        let strength = Math.floor(ent.resourceSupplyMax() / this.normalizationFactor[grp]);
     410        this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[grp] / cellSize, strength/2, "constant");
     411        this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[grp] / cellSize, strength/2);
     412        this.ccResourceMaps[resource].addInfluence(x, z, this.ccInfluenceRadius[grp] / cellSize, strength, "constant");
    413413    }
    414414};
    415415
    m.SharedScript.prototype.createResourceMaps = function()  
    420420 */
    421421m.SharedScript.prototype.updateResourceMaps = function(events)
    422422{
    423     for (let resource of this.resourceList)
     423    for (let resource of this.resourceInfo.codes)
    424424    {
    425         if (this.resourceTypes[resource] !== 1 && this.resourceTypes[resource] !== 2)
     425        if (this.resourceInfo.aiInfluenceGroups[resource] === 0)
    426426            continue;
    427427        // if there is no resourceMap create one with an influence for everything with that resource
    428428        if (this.resourceMaps[resource])
    m.SharedScript.prototype.updateResourceMaps = function(events)  
    447447        let cellSize = this.resourceMaps[resource].cellSize;
    448448        let x = Math.floor(ent.position()[0] / cellSize);
    449449        let z = Math.floor(ent.position()[1] / cellSize);
    450         let type = this.resourceTypes[resource];
    451         let strength = -Math.floor(ent.resourceSupplyMax()/this.normalizationFactor[type]);
    452         this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[type]/cellSize, strength/2, "constant");
    453         this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[type]/cellSize, strength/2);
    454         this.ccResourceMaps[resource].addInfluence(x, z, this.ccInfluenceRadius[type]/cellSize, strength, "constant");
     450        let grp = this.resourceInfo.aiInfluenceGroups[resource];
     451        let strength = -Math.floor(ent.resourceSupplyMax() / this.normalizationFactor[grp]);
     452        this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[grp] / cellSize, strength/2, "constant");
     453        this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[grp] / cellSize, strength/2);
     454        this.ccResourceMaps[resource].addInfluence(x, z, this.ccInfluenceRadius[grp] / cellSize, strength, "constant");
    455455    }
    456456    for (let e of events.Create)
    457457    {
    m.SharedScript.prototype.updateResourceMaps = function(events)  
    466466        let cellSize = this.resourceMaps[resource].cellSize;
    467467        let x = Math.floor(ent.position()[0] / cellSize);
    468468        let z = Math.floor(ent.position()[1] / cellSize);
    469         let type = this.resourceTypes[resource];
    470         let strength = Math.floor(ent.resourceSupplyMax()/this.normalizationFactor[type]);
    471         this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[type]/cellSize, strength/2, "constant");
    472         this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[type]/cellSize, strength/2);
    473         this.ccResourceMaps[resource].addInfluence(x, z, this.ccInfluenceRadius[type]/cellSize, strength, "constant");
     469        let grp = this.resourceInfo.aiInfluenceGroups[resource];
     470        let strength = Math.floor(ent.resourceSupplyMax() / this.normalizationFactor[grp]);
     471        this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[grp] / cellSize, strength/2, "constant");
     472        this.resourceMaps[resource].addInfluence(x, z, this.influenceRadius[grp] / cellSize, strength/2);
     473        this.ccResourceMaps[resource].addInfluence(x, z, this.ccInfluenceRadius[grp] / cellSize, strength, "constant");
    474474    }
    475475};
    476476
  • binaries/data/mods/public/simulation/ai/petra/baseManager.js

    diff --git a/binaries/data/mods/public/simulation/ai/petra/baseManager.js b/binaries/data/mods/public/simulation/ai/petra/baseManager.js
    index f1b338f..1c823c7 100644
    a b m.BaseManager.prototype.init = function(gameState, state)  
    5555    this.dropsites = {};
    5656    this.dropsiteSupplies = {};
    5757    this.gatherers = {};
    58     for (let res of gameState.sharedScript.resourceList)
     58    for (let res of gameState.sharedScript.resourceInfo.codes)
    5959    {
    6060        this.dropsiteSupplies[res] = { "nearby": [], "medium": [], "faraway": [] };
    6161        this.gatherers[res] = { "nextCheck": 0, "used": 0, "lost": 0 };
    m.BaseManager.prototype.getResourceLevel = function (gameState, type, nearbyOnly  
    434434/** check our resource levels and react accordingly */
    435435m.BaseManager.prototype.checkResourceLevels = function (gameState, queues)
    436436{
    437     for (let type of gameState.sharedScript.resourceList)
     437    for (let type of gameState.sharedScript.resourceInfo.codes)
    438438    {
    439439        if (type === "food")
    440440        {
  • binaries/data/mods/public/simulation/ai/petra/chatHelper.js

    diff --git a/binaries/data/mods/public/simulation/ai/petra/chatHelper.js b/binaries/data/mods/public/simulation/ai/petra/chatHelper.js
    index 60999e8..1ef89be 100644
    a b m.chatLaunchAttack = function(gameState, player, type)  
    1717        "message": message,
    1818        "translateMessage": true,
    1919        "translateParameters": ["_player_"],
    20         "parameters": {"_player_": player}
     20        "parameters": { "_player_": player }
    2121    });
    2222};
    2323
    m.chatAnswerRequestAttack = function(gameState, player, answer, other)  
    4545        "message": message,
    4646        "translateMessage": true,
    4747        "translateParameters": ["_player_"],
    48         "parameters": {"_player_": player}
     48        "parameters": { "_player_": player }
    4949    };
    5050    if (other !== undefined)
    5151    {
    m.chatSentTribute = function(gameState, player)  
    7171        "message": message,
    7272        "translateMessage": true,
    7373        "translateParameters": ["_player_"],
    74         "parameters": {"_player_": player}
     74        "parameters": { "_player_": player }
    7575    });
    7676};
    7777
    m.chatRequestTribute = function(gameState, resource)  
    9090        "type": "aichat",
    9191        "message": message,
    9292        "translateMessage": true,
    93         "translateParameters": {"resource": "withinSentence"},
    94         "parameters": {"resource": gameState.sharedScript.resourceNames[resource]}
     93        "translateParameters": { "resource": "withinSentence" },
     94        "parameters": { "resource": gameState.sharedScript.resourceInfo.names[resource] }
    9595    });
    9696};
    9797
    m.chatNewTradeRoute = function(gameState, player)  
    109109        "message": message,
    110110        "translateMessage": true,
    111111        "translateParameters": ["_player_"],
    112         "parameters": {"_player_": player}
     112        "parameters": { "_player_": player }
    113113    });
    114114};
    115115
  • binaries/data/mods/public/simulation/ai/petra/config.js

    diff --git a/binaries/data/mods/public/simulation/ai/petra/config.js b/binaries/data/mods/public/simulation/ai/petra/config.js
    index d5dc6b3..b0f5e7f 100644
    a b m.Config = function(difficulty)  
    103103        "defensive": 0.5
    104104    };
    105105
    106     this.resources = ["food", "wood", "stone", "metal"];
     106    // See m.QueueManager.prototype.wantedGatherRates()
     107    this.queues =
     108    {
     109        "firstTurn": {
     110            "food": 10,
     111            "wood": 10,
     112            "default": 0
     113        },
     114        "short": {
     115            "food": 200,
     116            "wood": 200,
     117            "default": 100
     118        },
     119        "medium": {
     120            "default": 0
     121        },
     122        "long": {
     123            "default": 0
     124        }
     125    };
    107126};
    108127
    109128m.Config.prototype.setConfig = function(gameState)
  • binaries/data/mods/public/simulation/ai/petra/headquarters.js

    diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js
    index 3e67da9..871035f 100644
    a b m.HQ.prototype.init = function(gameState, queues)  
    6969    this.navalMap = false;
    7070    this.navalRegions = {};
    7171
    72     for (let res of gameState.sharedScript.resourceList)
     72    for (let res of gameState.sharedScript.resourceInfo.codes)
    7373    {
    7474        this.wantedRates[res] = 0;
    7575        this.currentRates[res] = 0;
    m.HQ.prototype.bulkPickWorkers = function(gameState, baseRef, number)  
    653653m.HQ.prototype.getTotalResourceLevel = function(gameState)
    654654{
    655655    let total = {};
    656     for (let res of gameState.sharedScript.resourceList)
     656    for (let res of gameState.sharedScript.resourceInfo.codes)
    657657        total[res] = 0;
    658658    for (let base of this.baseManagers)
    659659        for (let res in total)
  • binaries/data/mods/public/simulation/ai/petra/queueManager.js

    diff --git a/binaries/data/mods/public/simulation/ai/petra/queueManager.js b/binaries/data/mods/public/simulation/ai/petra/queueManager.js
    index 4691d11..671131d 100644
    a b m.QueueManager.prototype.wantedGatherRates = function(gameState)  
    8484    if (gameState.ai.playedTurn === 0)
    8585    {
    8686        let ret = {};
    87         for (let res of gameState.sharedScript.resourceList)
    88             ret[res] = (res === "food" || res === "wood" ) ? 10 : 0;
     87        for (let res of gameState.sharedScript.resourceInfo.codes)
     88            ret[res] = this.Config.queues.firstTurn[res] || this.Config.queues.firstTurn.default;
    8989        return ret;
    9090    }
    9191
    m.QueueManager.prototype.wantedGatherRates = function(gameState)  
    9797    let totalShort = {};
    9898    let totalMedium = {};
    9999    let totalLong = {};
    100     for (let res of gameState.sharedScript.resourceList)
     100    for (let res of gameState.sharedScript.resourceInfo.codes)
    101101    {
    102         totalShort[res] = (res === "food" || res === "wood" ) ? 200 : 100;
    103         totalMedium[res] = 0;
    104         totalLong[res] = 0;
     102        totalShort[res] = this.Config.queues.short[res] || this.Config.queues.short.default;
     103        totalMedium[res] = this.Config.queues.medium[res] || this.Config.queues.medium.default;
     104        totalLong[res] = this.Config.queues.long[res] || this.Config.queues.long.default;
    105105    }
    106106    let total;
    107107    //queueArrays because it's faster.
    m.QueueManager.prototype.wantedGatherRates = function(gameState)  
    133133    // global rates
    134134    let rates = {};
    135135    let diff;
    136     for (let res of gameState.sharedScript.resourceList)
     136    for (let res of gameState.sharedScript.resourceInfo.codes)
    137137    {
    138138        if (current[res] > 0)
    139139        {
  • binaries/data/mods/public/simulation/ai/petra/researchManager.js

    diff --git a/binaries/data/mods/public/simulation/ai/petra/researchManager.js b/binaries/data/mods/public/simulation/ai/petra/researchManager.js
    index f169b39..8e409a1 100644
    a b m.ResearchManager.prototype.researchWantedTechs = function(gameState, techs)  
    100100            let cost = template.cost;
    101101            let costMax = 0;
    102102            for (let res in cost)
    103                 costMax = Math.max(costMax, Math.max(cost[res]-available[res], 0));
     103                if (gameState.sharedScript.resourceInfo.codes.indexOf(res))
     104                    costMax = Math.max(costMax, Math.max(cost[res]-available[res], 0));
    104105            if (10*numWorkers < costMax)
    105106                continue;
    106107        }
  • binaries/data/mods/public/simulation/components/Barter.js

    diff --git a/binaries/data/mods/public/simulation/components/Barter.js b/binaries/data/mods/public/simulation/components/Barter.js
    index 24c39a4..106d1e3 100644
    a b  
    1 // True price of 100 units of resource (for case if some resource is more worth).
     1// The "true price" is a base price of 100 units of resource (for the case of some resources being of more worth than others).
    22// With current bartering system only relative values makes sense
    33// so if for example stone is two times more expensive than wood,
    44// there will 2:1 exchange rate.
    5 const TRUE_PRICES = { "food": 100, "wood": 100, "stone": 100, "metal": 100 };
    6 
     5//
    76// Constant part of price difference between true price and buy/sell price.
    87// In percents.
    98// Buy price equal to true price plus constant difference.
    const DIFFERENCE_RESTORE = 0.5;  
    2120// Interval of timer which slowly restore prices after deals
    2221const RESTORE_TIMER_INTERVAL = 5000;
    2322
    24 // Array of resource names
    25 const RESOURCES = ["food", "wood", "stone", "metal"];
    26 
    2723function Barter() {}
    2824
    2925Barter.prototype.Schema =
    Barter.prototype.Schema =  
    3228Barter.prototype.Init = function()
    3329{
    3430    this.priceDifferences = {};
    35     for (var resource of RESOURCES)
     31    for (let resource of Resources.GetCodes())
    3632        this.priceDifferences[resource] = 0;
    3733    this.restoreTimer = undefined;
    3834};
    Barter.prototype.Init = function()  
    4036Barter.prototype.GetPrices = function()
    4137{
    4238    var prices = { "buy": {}, "sell": {} };
    43     for (var resource of RESOURCES)
     39    for (let resource of Resources.GetCodes())
    4440    {
    45         prices["buy"][resource] = TRUE_PRICES[resource] * (100 + CONSTANT_DIFFERENCE + this.priceDifferences[resource]) / 100;
    46         prices["sell"][resource] = TRUE_PRICES[resource] * (100 - CONSTANT_DIFFERENCE + this.priceDifferences[resource]) / 100;
     41        let truePrice = Resources.GetResource(resource).truePrice;
     42        prices.buy[resource] = truePrice * (100 + CONSTANT_DIFFERENCE + this.priceDifferences[resource]) / 100;
     43        prices.sell[resource] = truePrice * (100 - CONSTANT_DIFFERENCE + this.priceDifferences[resource]) / 100;
    4744    }
    4845    return prices;
    4946};
    Barter.prototype.ExchangeResources = function(playerEntity, resourceToSell, reso  
    7168        warn("ExchangeResources: incorrect amount: " + uneval(amount));
    7269        return;
    7370    }
    74     if (RESOURCES.indexOf(resourceToSell) == -1)
     71    let availResources = Resources.GetCodes();
     72    if (availResources.indexOf(resourceToSell) == -1)
    7573    {
    7674        warn("ExchangeResources: incorrect resource to sell: " + uneval(resourceToSell));
    7775        return;
    7876    }
    79     if (RESOURCES.indexOf(resourceToBuy) == -1)
     77    if (availResources.indexOf(resourceToBuy) == -1)
    8078    {
    8179        warn("ExchangeResources: incorrect resource to buy: " + uneval(resourceToBuy));
    8280        return;
    Barter.prototype.ExchangeResources = function(playerEntity, resourceToSell, reso  
    123121Barter.prototype.ProgressTimeout = function(data)
    124122{
    125123    var needRestore = false;
    126     for (var resource of RESOURCES)
     124    for (let resource of Resources.GetCodes())
    127125    {
    128126        // Calculate value to restore, it should be limited to [-DIFFERENCE_RESTORE; DIFFERENCE_RESTORE] interval
    129127        var differenceRestore = Math.min(DIFFERENCE_RESTORE, Math.max(-DIFFERENCE_RESTORE, this.priceDifferences[resource]));
  • binaries/data/mods/public/simulation/components/Cost.js

    diff --git a/binaries/data/mods/public/simulation/components/Cost.js b/binaries/data/mods/public/simulation/components/Cost.js
    index b3196a6..9fd3ad3 100644
    a b  
    11function Cost() {}
    22
     3Cost.prototype.ResourcesSchema = Resources.BuildSchema("nonNegativeDecimal");
     4
    35Cost.prototype.Schema =
    46    "<a:help>Specifies the construction/training costs of this entity.</a:help>" +
    57    "<a:example>" +
    Cost.prototype.Schema =  
    1921    "<element name='PopulationBonus' a:help='Population cap increase while this entity exists'>" +
    2022        "<data type='nonNegativeInteger'/>" +
    2123    "</element>" +
    22     "<element name='BuildTime' a:help='Time taken to construct/train this unit (in seconds)'>" +
     24    "<element name='BuildTime' a:help='Time taken to construct/train this entity (in seconds)'>" +
    2325        "<ref name='nonNegativeDecimal'/>" +
    2426    "</element>" +
    25     "<element name='Resources' a:help='Resource costs to construct/train this unit'>" +
    26         "<interleave>" +
    27             "<element name='food'><ref name='nonNegativeDecimal'/></element>" +
    28             "<element name='wood'><ref name='nonNegativeDecimal'/></element>" +
    29             "<element name='stone'><ref name='nonNegativeDecimal'/></element>" +
    30             "<element name='metal'><ref name='nonNegativeDecimal'/></element>" +
    31         "</interleave>" +
     27    "<element name='Resources' a:help='Resource costs to construct/train this entity'>" +
     28        Cost.prototype.ResourcesSchema +
    3229    "</element>";
    3330
    3431Cost.prototype.Init = function()
    Cost.prototype.GetResourceCosts = function(owner)  
    7067    let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName);
    7168
    7269    let costs = {};
    73     for (let r in this.template.Resources)
    74         costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, +this.template.Resources[r], owner, entityTemplate);
     70    let resCodes = Resources.GetCodes();
     71
     72    for (let res in this.template.Resources)
     73    {
     74        if (resCodes.indexOf(res) < 0)
     75            continue;
     76        costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate);
     77    }
     78
    7579    return costs;
    7680};
    7781
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
    index aaa7855..1b89b40 100644
    a b GuiInterface.prototype.GetSimulationState = function()  
    152152    let cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter);
    153153    ret.barterPrices = cmpBarter.GetPrices();
    154154
     155    // Add Resource Codes, untranslated names and AI Analysis
     156    ret.resources = {
     157        "codes": Resources.GetCodes(),
     158        "names": Resources.GetNames(),
     159        "aiInfluenceGroups": {}
     160    };
     161    for (let res of ret.resources.codes)
     162        ret.resources.aiInfluenceGroups[res] = Resources.GetResource(res).aiAnalysisInfluenceGroup || 0;
     163
    155164    // Add basic statistics to each player
    156165    for (let i = 0; i < numPlayers; ++i)
    157166    {
    GuiInterface.prototype.SetWallPlacementPreview = function(player, cmd)  
    12691278
    12701279    let result = {
    12711280        "pieces": [],
    1272         "cost": { "food": 0, "wood": 0, "stone": 0, "metal": 0, "population": 0, "populationBonus": 0, "time": 0 },
     1281        "cost": { "population": 0, "populationBonus": 0, "time": 0 },
    12731282    };
     1283    for (let res of Resources.GetCodes())
     1284        result.cost[res] = 0;
    12741285
    12751286    let previewEntities = [];
    12761287    if (end.pos)
    GuiInterface.prototype.SetWallPlacementPreview = function(player, cmd)  
    15451556            // copied over, so we need to fetch it from the template instead).
    15461557            // TODO: we should really use a Cost object or at least some utility functions for this, this is mindless
    15471558            // boilerplate that's probably duplicated in tons of places.
    1548             result.cost.food += tplData.cost.food;
    1549             result.cost.wood += tplData.cost.wood;
    1550             result.cost.stone += tplData.cost.stone;
    1551             result.cost.metal += tplData.cost.metal;
    1552             result.cost.population += tplData.cost.population;
    1553             result.cost.populationBonus += tplData.cost.populationBonus;
    1554             result.cost.time += tplData.cost.time;
     1559            let entries = Resources.GetCodes().concat("population", "populationBonus", "time");
     1560            for (let res of entries)
     1561                result.cost[res] = tplData.cost[res];
    15551562        }
    15561563
    15571564        let canAfford = true;
  • binaries/data/mods/public/simulation/components/Loot.js

    diff --git a/binaries/data/mods/public/simulation/components/Loot.js b/binaries/data/mods/public/simulation/components/Loot.js
    index 3161340..b17fdb3 100644
    a b  
    11function Loot() {}
    22
     3Loot.prototype.ResourcesSchema = Resources.BuildSchema("nonNegativeInteger", [ "xp" ]);
     4
    35Loot.prototype.Schema =
    4     "<optional>" +
    5         "<element name='xp'><data type='nonNegativeInteger'/></element>" +
    6     "</optional>" +
    7     "<optional>" +
    8         "<element name='food'><data type='nonNegativeInteger'/></element>" +
    9     "</optional>" +
    10     "<optional>" +
    11         "<element name='wood'><data type='nonNegativeInteger'/></element>" +
    12     "</optional>" +
    13     "<optional>" +
    14         "<element name='stone'><data type='nonNegativeInteger'/></element>" +
    15     "</optional>" +
    16     "<optional>" +
    17         "<element name='metal'><data type='nonNegativeInteger'/></element>" +
    18     "</optional>";
     6    "<a:help>Specifies the loot credited when this entity is killed.</a:help>" +
     7    "<a:example>" +
     8        "<xp>35</xp>" +
     9        "<metal>10</metal>" +
     10    "</a:example>" +
     11    Loot.prototype.ResourcesSchema;
    1912
    2013Loot.prototype.Serialize = null; // we have no dynamic state to save
    2114
    Loot.prototype.GetXp = function()  
    2619
    2720Loot.prototype.GetResources = function()
    2821{
    29     return {
    30         "food": +(this.template.food || 0),
    31         "wood": +(this.template.wood || 0),
    32         "metal": +(this.template.metal || 0),
    33         "stone": +(this.template.stone || 0)
    34     };
     22    let ret = {};
     23    for (let res of Resources.GetCodes())
     24        ret[res] = +this.template[res] || 0;
     25
     26    return ret;
    3527};
    3628
    3729Engine.RegisterComponentType(IID_Loot, "Loot", Loot);
  • binaries/data/mods/public/simulation/components/Player.js

    diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js
    index cb137dd..ce9371a 100644
    a b Player.prototype.Init = function()  
    1818    this.popBonuses = 0; // sum of population bonuses of player's entities
    1919    this.maxPop = 300; // maximum population
    2020    this.trainingBlocked = false; // indicates whether any training queue is currently blocked
    21     this.resourceCount = {
    22         "food": 300,
    23         "wood": 300,
    24         "metal": 300,
    25         "stone": 300
    26     };
    27     // goods for next trade-route and its proba in % (the sum of probas must be 100)
    28     this.tradingGoods = [
    29         { "goods":  "wood", "proba": 30 },
    30         { "goods": "stone", "proba": 35 },
    31         { "goods": "metal", "proba": 35 },
    32     ];
     21    this.resourceCount = {};
     22    this.tradingGoods = []; // goods for next trade-route and its proba in % (the sum of probas must be 100)
    3323    this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc.
    3424    this.teamsLocked = false;
    3525    this.state = "active"; // game state - one of "active", "defeated", "won"
    Player.prototype.Init = function()  
    4434    this.cheatsEnabled = false;
    4535    this.cheatTimeMultiplier = 1;
    4636    this.heroes = [];
    47     this.resourceNames = {
    48         "food": markForTranslation("Food"),
    49         "wood": markForTranslation("Wood"),
    50         "metal": markForTranslation("Metal"),
    51         "stone": markForTranslation("Stone"),
    52     };
     37    this.resourceNames = {};
    5338    this.disabledTemplates = {};
    5439    this.disabledTechnologies = {};
    5540    this.startingTechnologies = [];
     41
     42    // Initial resources and trading goods probability in steps of 5
     43    let resCodes = Resources.GetCodes();
     44    let quotient = Math.floor(20 / resCodes.length);
     45    let remainder = 20 % resCodes.length;
     46    for (let i in resCodes)
     47    {
     48        let res = resCodes[i];
     49        this.resourceCount[res] = 300;
     50        this.resourceNames[res] = Resources.GetResource(res).name;
     51        this.tradingGoods.push({
     52            "goods":  res,
     53            "proba": 5 * (quotient + (+i < remainder ? 1 : 0))
     54        });
     55    }
    5656};
    5757
    5858Player.prototype.SetPlayerID = function(id)
    Player.prototype.UnBlockTraining = function()  
    197197
    198198Player.prototype.SetResourceCounts = function(resources)
    199199{
    200     if (resources.food !== undefined)
    201         this.resourceCount.food = resources.food;
    202     if (resources.wood !== undefined)
    203         this.resourceCount.wood = resources.wood;
    204     if (resources.stone !== undefined)
    205         this.resourceCount.stone = resources.stone;
    206     if (resources.metal !== undefined)
    207         this.resourceCount.metal = resources.metal;
     200    for (let res in resources)
     201        if (this.resourceCount[res])
     202            this.resourceCount[res] = resources[res];
    208203};
    209204
    210205Player.prototype.GetResourceCounts = function()
    Player.prototype.SubtractResourcesOrNotify = function(amounts)  
    297292
    298293    // Subtract the resources
    299294    for (var type in amounts)
    300         this.resourceCount[type] -= amounts[type];
     295        if (this.resourceCount[type])
     296            this.resourceCount[type] -= amounts[type];
    301297
    302298    return true;
    303299};
    Player.prototype.GetTradingGoods = function()  
    340336
    341337Player.prototype.SetTradingGoods = function(tradingGoods)
    342338{
    343     var sumProba = 0;
    344     for (var resource in tradingGoods)
     339    let sumProba = 0;
     340    for (let resource in tradingGoods)
    345341        sumProba += tradingGoods[resource];
    346342    if (sumProba != 100)    // consistency check
    347343    {
    348344        error("Player.js SetTradingGoods: " + uneval(tradingGoods));
    349         tradingGoods = { "food": 20, "wood":20, "stone":30, "metal":30 };
     345        let resCodes = Resources.GetCodes();
     346        for (let r = 0; r < resCodes.length; ++r)
     347            tradingGoods[resCodes[r]] = r == 0 ? 100 : 0;
    350348    }
    351349
    352350    this.tradingGoods = [];
    353     for (var resource in tradingGoods)
     351    for (let resource in tradingGoods)
    354352        this.tradingGoods.push( {"goods": resource, "proba": tradingGoods[resource]} );
    355353};
    356354
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

    diff --git a/binaries/data/mods/public/simulation/components/ProductionQueue.js b/binaries/data/mods/public/simulation/components/ProductionQueue.js
    index 6c72202..5023f7f 100644
    a b const MAX_QUEUE_SIZE = 16;  
    33
    44function ProductionQueue() {}
    55
     6ProductionQueue.prototype.ResourceSchema = Resources.BuildSchema("nonNegativeDecimal", [ "time" ]);
     7
    68ProductionQueue.prototype.Schema =
    79    "<a:help>Allows the building to train new units and research technologies</a:help>" +
    810    "<a:example>" +
    ProductionQueue.prototype.Schema =  
    3133        "</element>" +
    3234    "</optional>" +
    3335    "<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" +
    34         "<interleave>" +
    35             "<element name='food'><ref name='nonNegativeDecimal'/></element>" +
    36             "<element name='wood'><ref name='nonNegativeDecimal'/></element>" +
    37             "<element name='stone'><ref name='nonNegativeDecimal'/></element>" +
    38             "<element name='metal'><ref name='nonNegativeDecimal'/></element>" +
    39             "<element name='time'><ref name='nonNegativeDecimal'/></element>" +
    40         "</interleave>" +
     36        ProductionQueue.prototype.ResourceSchema +
    4137    "</element>";
    4238
    4339ProductionQueue.prototype.Init = function()
    ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat  
    260256    // TODO: there should probably be a limit on the number of queued batches
    261257    // TODO: there should be a way for the GUI to determine whether it's going
    262258    // to be possible to add a batch (based on resource costs and length limits)
    263     var cmpPlayer = QueryOwnerInterface(this.entity);
     259    let cmpPlayer = QueryOwnerInterface(this.entity);
     260    let resCodes = Resources.GetCodes();
    264261
    265262    if (this.queue.length < MAX_QUEUE_SIZE)
    266263    {
    ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat  
    293290            var buildTime = ApplyValueModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, cmpPlayer.GetPlayerID(), template);
    294291            var time = timeMult * buildTime;
    295292
    296             for (var r in template.Cost.Resources)
     293            for (let res in template.Cost.Resources)
    297294            {
    298                 costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template);
    299                 totalCosts[r] = Math.floor(count * costs[r]);
     295                if (resCodes.indexOf(res) < 0)
     296                    continue;
     297                costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +template.Cost.Resources[res], cmpPlayer.GetPlayerID(), template);
     298                totalCosts[res] = Math.floor(count * costs[res]);
    300299            }
    301300
    302301            var population = ApplyValueModificationsToTemplate("Cost/Population",  +template.Cost.Population, cmpPlayer.GetPlayerID(), template);
    ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat  
    341340            let techCostMultiplier = this.GetTechCostMultiplier();
    342341            let time =  techCostMultiplier.time * template.researchTime * cmpPlayer.GetCheatTimeMultiplier();
    343342
    344             var cost = {};
     343            let cost = {};
    345344            for (let res in template.cost)
    346                 cost[res] = Math.floor(techCostMultiplier[res] * template.cost[res]);
     345            {
     346                if (resCodes.indexOf(res) < 0)
     347                    continue;
     348                cost[res] = Math.floor((techCostMultiplier[res] || 1) * template.cost[res]);
     349            }
    347350
    348351            // TrySubtractResources should report error to player (they ran out of resources)
    349352            if (!cmpPlayer.TrySubtractResources(cost))
    ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat  
    361364                "player": cmpPlayer.GetPlayerID(),
    362365                "count": 1,
    363366                "technologyTemplate": templateName,
    364                 "resources": deepcopy(template.cost), // need to copy to avoid serialization problems
     367                "resources": cost,
    365368                "productionStarted": false,
    366369                "timeTotal": time*1000,
    367370                "timeRemaining": time*1000,
    ProductionQueue.prototype.RemoveBatch = function(id)  
    433436        // Refund the resource cost for this batch
    434437        var totalCosts = {};
    435438        var cmpStatisticsTracker = QueryPlayerIDInterface(item.player, IID_StatisticsTracker);
    436         for each (var r in ["food", "wood", "stone", "metal"])
     439        for (let r of Resources.GetCodes())
    437440        {
     441            if (!item.resources[r])
     442                continue;
    438443            totalCosts[r] = Math.floor(item.count * item.resources[r]);
    439444            if (cmpStatisticsTracker)
    440445                cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -totalCosts[r]);
  • binaries/data/mods/public/simulation/components/ResourceDropsite.js

    diff --git a/binaries/data/mods/public/simulation/components/ResourceDropsite.js b/binaries/data/mods/public/simulation/components/ResourceDropsite.js
    index 819807c..a14ddaf 100644
    a b  
    11function ResourceDropsite() {}
    22
     3ResourceDropsite.prototype.ResourceChoiceSchema = Resources.BuildChoicesSchema();
     4
    35ResourceDropsite.prototype.Schema =
    46    "<element name='Types'>" +
    57        "<list>" +
    68            "<zeroOrMore>" +
    7                 "<choice>" +
    8                     "<value>food</value>" +
    9                     "<value>wood</value>" +
    10                     "<value>stone</value>" +
    11                     "<value>metal</value>" +
    12                 "</choice>" +
     9                ResourceDropsite.prototype.ResourceChoiceSchema +
    1310            "</zeroOrMore>" +
    1411        "</list>" +
    1512    "</element>" +
    ResourceDropsite.prototype.Init = function()  
    2421};
    2522
    2623/**
    27  * Returns the list of resource types accepted by this dropsite.
     24 * Returns the list of resource types accepted by this dropsite,
     25 * as defined by it being referred to in the template and the resource being enabled.
    2826 */
    2927ResourceDropsite.prototype.GetTypes = function()
    3028{
    3129    let types = ApplyValueModificationsToEntity("ResourceDropsite/Types", this.template.Types, this.entity);
    32     return types ? types.split(/\s+/) : [];
     30    let resources = Resources.GetCodes();
     31    return types.split(/\s+/).filter(type => resources.indexOf(type.toLowerCase()) > -1);
    3332};
    3433
    3534/**
  • binaries/data/mods/public/simulation/components/ResourceGatherer.js

    diff --git a/binaries/data/mods/public/simulation/components/ResourceGatherer.js b/binaries/data/mods/public/simulation/components/ResourceGatherer.js
    index acd5fbd..be597f9 100644
    a b  
    11function ResourceGatherer() {}
    22
     3ResourceGatherer.prototype.ResourcesSchema = Resources.BuildSchema("positiveDecimal", [ "treasure" ], true);
     4ResourceGatherer.prototype.CapacitiesSchema = Resources.BuildSchema("positiveDecimal");
     5
    36ResourceGatherer.prototype.Schema =
    47    "<a:help>Lets the unit gather resources from entities that have the ResourceSupply component.</a:help>" +
    58    "<a:example>" +
    ResourceGatherer.prototype.Schema =  
    2528        "<ref name='positiveDecimal'/>" +
    2629    "</element>" +
    2730    "<element name='Rates' a:help='Per-resource-type gather rate multipliers. If a resource type is not specified then it cannot be gathered by this unit'>" +
    28         "<interleave>" +
    29             "<optional><element name='food' a:help='Food gather rate (may be overridden by \"food.*\" subtypes)'><ref name='positiveDecimal'/></element></optional>" +
    30             "<optional><element name='wood' a:help='Wood gather rate'><ref name='positiveDecimal'/></element></optional>" +
    31             "<optional><element name='stone' a:help='Stone gather rate'><ref name='positiveDecimal'/></element></optional>" +
    32             "<optional><element name='metal' a:help='Metal gather rate'><ref name='positiveDecimal'/></element></optional>" +
    33             "<optional><element name='treasure' a:help='Treasure gather rate (only presense on value makes sense, size is only used to determine the delay before gathering, so it should be set to 1)'><ref name='positiveDecimal'/></element></optional>" +
    34             "<optional><element name='food.fish' a:help='Fish gather rate (overrides \"food\")'><ref name='positiveDecimal'/></element></optional>" +
    35             "<optional><element name='food.fruit' a:help='Fruit gather rate (overrides \"food\")'><ref name='positiveDecimal'/></element></optional>" +
    36             "<optional><element name='food.grain' a:help='Grain gather rate (overrides \"food\")'><ref name='positiveDecimal'/></element></optional>" +
    37             "<optional><element name='food.meat' a:help='Meat gather rate (overrides \"food\")'><ref name='positiveDecimal'/></element></optional>" +
    38             "<optional><element name='food.milk' a:help='Milk gather rate (overrides \"food\")'><ref name='positiveDecimal'/></element></optional>" +
    39             "<optional><element name='wood.tree' a:help='Tree gather rate (overrides \"wood\")'><ref name='positiveDecimal'/></element></optional>" +
    40             "<optional><element name='wood.ruins' a:help='Tree gather rate (overrides \"wood\")'><ref name='positiveDecimal'/></element></optional>" +
    41             "<optional><element name='stone.rock' a:help='Rock gather rate (overrides \"stone\")'><ref name='positiveDecimal'/></element></optional>" +
    42             "<optional><element name='stone.ruins' a:help='Rock gather rate (overrides \"stone\")'><ref name='positiveDecimal'/></element></optional>" +
    43             "<optional><element name='metal.ore' a:help='Ore gather rate (overrides \"metal\")'><ref name='positiveDecimal'/></element></optional>" +
    44             "<optional><element name='treasure.food' a:help='Food treasure gather rate (overrides \"treasure\")'><ref name='positiveDecimal'/></element></optional>" +
    45             "<optional><element name='treasure.wood' a:help='Wood treasure gather rate (overrides \"treasure\")'><ref name='positiveDecimal'/></element></optional>" +
    46             "<optional><element name='treasure.stone' a:help='Stone treasure gather rate (overrides \"treasure\")'><ref name='positiveDecimal'/></element></optional>" +
    47             "<optional><element name='treasure.metal' a:help='Metal treasure gather rate (overrides \"treasure\")'><ref name='positiveDecimal'/></element></optional>" +
    48         "</interleave>" +
     31        ResourceGatherer.prototype.ResourcesSchema +
    4932    "</element>" +
    5033    "<element name='Capacities' a:help='Per-resource-type maximum carrying capacity'>" +
    51         "<interleave>" +
    52             "<element name='food' a:help='Food capacity'><ref name='positiveDecimal'/></element>" +
    53             "<element name='wood' a:help='Wood capacity'><ref name='positiveDecimal'/></element>" +
    54             "<element name='stone' a:help='Stone capacity'><ref name='positiveDecimal'/></element>" +
    55             "<element name='metal' a:help='Metal capacity'><ref name='positiveDecimal'/></element>" +
    56         "</interleave>" +
     34        ResourceGatherer.prototype.CapacitiesSchema +
    5735    "</element>";
    5836
    5937ResourceGatherer.prototype.Init = function()
    ResourceGatherer.prototype.RecalculateGatherRatesAndCapacities = function()  
    137115    this.rates = {};
    138116    for (let r in this.template.Rates)
    139117    {
     118        let type = r.split(".");
     119        let res = Resources.GetResource(type[0]);
     120
     121        if (!res && type[0] !== "treasure" || type.length > 1 && res.subtypes.indexOf(type[1]) == -1)
     122            continue;
     123
    140124        let rate = ApplyValueModificationsToEntity("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity);
    141125        this.rates[r] = rate * this.baseSpeed;
    142126    }
    ResourceGatherer.prototype.GetRange = function()  
    174158
    175159/**
    176160 * Try to gather treasure
    177  * @return 'true' if treasure is successfully gathered and 'false' in the other case
     161 * @return 'true' if treasure is successfully gathered, otherwise 'false'
    178162 */
    179163ResourceGatherer.prototype.TryInstantGather = function(target)
    180164{
  • binaries/data/mods/public/simulation/components/ResourceSupply.js

    diff --git a/binaries/data/mods/public/simulation/components/ResourceSupply.js b/binaries/data/mods/public/simulation/components/ResourceSupply.js
    index 04e95da..b39a39d 100644
    a b  
    11function ResourceSupply() {}
    22
     3ResourceSupply.prototype.ResourceChoiceSchema = Resources.BuildChoicesSchema(true, true);
     4
    35ResourceSupply.prototype.Schema =
    46    "<a:help>Provides a supply of one particular type of resource.</a:help>" +
    57    "<a:example>" +
    ResourceSupply.prototype.Schema =  
    1214    "<element name='Amount' a:help='Amount of resources available from this entity'>" +
    1315        "<choice><data type='nonNegativeInteger'/><value>Infinity</value></choice>" +
    1416    "</element>" +
    15     "<element name='Type' a:help='Type of resources'>" +
    16         "<choice>" +
    17             "<value>wood.tree</value>" +
    18             "<value>wood.ruins</value>" +
    19             "<value>stone.rock</value>" +
    20             "<value>stone.ruins</value>" +
    21             "<value>metal.ore</value>" +
    22             "<value>food.fish</value>" +
    23             "<value>food.fruit</value>" +
    24             "<value>food.grain</value>" +
    25             "<value>food.meat</value>" +
    26             "<value>food.milk</value>" +
    27             "<value>treasure.wood</value>" +
    28             "<value>treasure.stone</value>" +
    29             "<value>treasure.metal</value>" +
    30             "<value>treasure.food</value>" +
    31         "</choice>" +
     17    "<element name='Type' a:help='Type and Subtype of resource available from this entity'>" +
     18        ResourceSupply.prototype.ResourceChoiceSchema +
    3219    "</element>" +
    3320    "<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" +
    3421        "<data type='nonNegativeInteger'/>" +
    ResourceSupply.prototype.Init = function()  
    4532    this.amount = this.GetMaxAmount();
    4633
    4734    this.gatherers = [];    // list of IDs for each players
    48     var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); // system component so that's safe.
    49     var numPlayers = cmpPlayerManager.GetNumPlayers();
    50     for (var i = 0; i <= numPlayers; ++i)   // use "<=" because we want Gaia too.
     35    let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); // system component so that's safe.
     36    let numPlayers = cmpPlayerManager.GetNumPlayers();
     37    for (let i = 0; i <= numPlayers; ++i)   // use "<=" because we want Gaia too.
    5138        this.gatherers.push([]);
    5239
    5340    this.infinite = !isFinite(+this.template.Amount);
    5441
    55     [this.type,this.subType] = this.template.Type.split('.');
    56     this.cachedType = { "generic" : this.type, "specific" : this.subType };
     42    [this.type, this.subtype] = this.template.Type.split('.');
     43    let resData = Resources.GetResource(this.type);
     44    if (this.type === "treasure")
     45        resData = { "subtypes": Resources.GetCodes() };
     46
     47    // Remove entity from gameworld if the resource supplied by this entity is disabled or not valid.
     48    if (!resData || resData.subtypes.indexOf(this.subtype) === -1)
     49        Engine.DestroyEntity(this.entity);
    5750
     51    this.cachedType = { "generic": this.type, "specific": this.subtype };
    5852};
    5953
    6054ResourceSupply.prototype.IsInfinite = function()
  • binaries/data/mods/public/simulation/components/ResourceTrickle.js

    diff --git a/binaries/data/mods/public/simulation/components/ResourceTrickle.js b/binaries/data/mods/public/simulation/components/ResourceTrickle.js
    index 5c554e7..7bed918 100644
    a b  
    11function ResourceTrickle() {}
    22
     3ResourceTrickle.prototype.ResourcesSchema = Resources.BuildSchema("nonNegativeDecimal");
     4
    35ResourceTrickle.prototype.Schema =
    46    "<a:help>Controls the resource trickle ability of the unit.</a:help>" +
    57    "<element name='Rates' a:help='Trickle Rates'>" +
    6         "<interleave>" +
    7             "<optional>" +
    8                 "<element name='food' a:help='Food given to the player every interval'>" +
    9                     "<ref name='nonNegativeDecimal'/>" +
    10                 "</element>" +
    11             "</optional>" +
    12             "<optional>" +
    13                 "<element name='wood' a:help='Wood given to the player every interval'>" +
    14                     "<ref name='nonNegativeDecimal'/>" +
    15                 "</element>" +
    16             "</optional>" +
    17             "<optional>" +
    18                 "<element name='stone' a:help='Stone given to the player every interval'>" +
    19                     "<ref name='nonNegativeDecimal'/>" +
    20                 "</element>" +
    21             "</optional>" +
    22             "<optional>" +
    23                 "<element name='metal' a:help='Metal given to the player every interval'>" +
    24                     "<ref name='nonNegativeDecimal'/>" +
    25                 "</element>" +
    26             "</optional>" +
    27         "</interleave>" +
     8        ResourceTrickle.prototype.ResourcesSchema +
    289    "</element>" +
    2910    "<element name='Interval' a:help='Number of miliseconds must pass for the player to gain the next trickle.'>" +
    3011        "<ref name='nonNegativeDecimal'/>" +
    ResourceTrickle.prototype.GetTimer = function()  
    4526
    4627ResourceTrickle.prototype.GetRates = function()
    4728{
    48     var rates = {};
    49     for (var resource in this.template.Rates)
     29    let rates = {};
     30    let resCodes = Resources.GetCodes();
     31    for (let resource in this.template.Rates)
     32    {
     33        if (resCodes.indexOf(resource) < 0)
     34            continue;
    5035        rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/Rates/"+resource, +this.template.Rates[resource], this.entity);
     36    }
    5137
    5238    return rates;
    5339};
    ResourceTrickle.prototype.GetRates = function()  
    5541// Do the actual work here
    5642ResourceTrickle.prototype.Trickle = function(data, lateness)
    5743{
    58     var cmpPlayer = QueryOwnerInterface(this.entity);
    59     if (!cmpPlayer)
    60         return;
    61 
    62     var rates = this.GetRates();
    63     for (var resource in rates)
    64         cmpPlayer.AddResource(resource, rates[resource]);
     44    let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
     45    if (cmpPlayer)
     46        cmpPlayer.AddResources(this.GetRates());
    6547};
    6648
    6749Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle);
  • binaries/data/mods/public/simulation/components/StatisticsTracker.js

    diff --git a/binaries/data/mods/public/simulation/components/StatisticsTracker.js b/binaries/data/mods/public/simulation/components/StatisticsTracker.js
    index 3bc1f79..482502d 100644
    a b StatisticsTracker.prototype.Init = function()  
    105105    this.buildingsCapturedValue = 0;
    106106
    107107    this.resourcesGathered = {
    108         "food": 0,
    109         "wood": 0,
    110         "metal": 0,
    111         "stone": 0,
    112108        "vegetarianFood": 0
    113109    };
    114     this.resourcesUsed = {
    115         "food": 0,
    116         "wood": 0,
    117         "metal": 0,
    118         "stone": 0
    119     };
    120     this.resourcesSold = {
    121         "food": 0,
    122         "wood": 0,
    123         "metal": 0,
    124         "stone": 0
    125     };
    126     this.resourcesBought = {
    127         "food": 0,
    128         "wood": 0,
    129         "metal": 0,
    130         "stone": 0
    131     };
     110    this.resourcesUsed = {};
     111    this.resourcesSold = {};
     112    this.resourcesBought = {};
     113    for (let res of Resources.GetCodes())
     114    {
     115        this.resourcesGathered[res] = 0;
     116        this.resourcesUsed[res] = 0;
     117        this.resourcesSold[res] = 0;
     118        this.resourcesBought[res] = 0;
     119    }
    132120
    133121    this.tributesSent = 0;
    134122    this.tributesReceived = 0;
    StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amo  
    347335 */
    348336StatisticsTracker.prototype.IncreaseResourceUsedCounter = function(type, amount)
    349337{
    350     this.resourcesUsed[type] += amount;
     338    if (typeof this.resourcesUsed[type] === "number")
     339        this.resourcesUsed[type] += amount;
    351340};
    352341
    353342StatisticsTracker.prototype.IncreaseTreasuresCollectedCounter = function()
  • binaries/data/mods/public/simulation/components/Trader.js

    diff --git a/binaries/data/mods/public/simulation/components/Trader.js b/binaries/data/mods/public/simulation/components/Trader.js
    index 735778d..771a814 100644
    a b  
    44// Additional gain for ships for each garrisoned trader, in percents
    55const GARRISONED_TRADER_ADDITION = 20;
    66
    7 // Array of resource names
    8 const RESOURCES = ["food", "wood", "stone", "metal"];
    9 
    107function Trader() {}
    118
    129Trader.prototype.Schema =
  • binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js

    diff --git a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
    index 6ae026e..f1c9e98 100644
    a b Engine.LoadComponentScript("interfaces/Upgrade.js");  
    3333Engine.LoadComponentScript("interfaces/BuildingAI.js");
    3434Engine.LoadComponentScript("GuiInterface.js");
    3535
     36Resources = {
     37    "GetCodes": () => ["food", "metal", "stone", "wood"],
     38    "GetNames": () => ({ "food": "Food", "metal": "Metal", "stone": "Stone", "wood": "Wood" }),
     39    "GetResource": () => ({}),
     40};
     41
    3642var cmp = ConstructComponent(SYSTEM_ENTITY, "GuiInterface");
    3743
    3844
    TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {  
    330336    circularMap: false,
    331337    timeElapsed: 0,
    332338    gameType: "conquest",
    333     barterPrices: {buy: {food: 150}, sell: {food: 25}}
     339    barterPrices: { buy: { "food": 150 }, sell: { "food": 25 } },
     340    resources: {
     341        codes: ["food", "metal", "stone", "wood"],
     342        names: {
     343            "food": "Food",
     344            "metal": "Metal",
     345            "stone": "Stone",
     346            "wood": "Wood",
     347        },
     348        aiInfluenceGroups: {
     349            "food": 0,
     350            "metal": 0,
     351            "stone": 0,
     352            "wood": 0,
     353        }
     354    },
    334355});
    335356
    336357TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
    TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {  
    449470    circularMap: false,
    450471    timeElapsed: 0,
    451472    gameType: "conquest",
    452     barterPrices: {buy: {food: 150}, sell: {food: 25}}
     473    barterPrices: { buy: { "food": 150 }, sell: { "food": 25 } },
     474    resources: {
     475        codes: ["food", "metal", "stone", "wood"],
     476        names: {
     477            "food": "Food",
     478            "metal": "Metal",
     479            "stone": "Stone",
     480            "wood": "Wood",
     481        },
     482        aiInfluenceGroups: {
     483            "food": 0,
     484            "metal": 0,
     485            "stone": 0,
     486            "wood": 0,
     487        }
     488    },
    453489});
    454490
    455491
  • binaries/data/mods/public/simulation/components/tests/test_Player.js

    diff --git a/binaries/data/mods/public/simulation/components/tests/test_Player.js b/binaries/data/mods/public/simulation/components/tests/test_Player.js
    index 4191a68..3649351 100644
    a b Engine.LoadComponentScript("Timer.js")  
    99ConstructComponent(SYSTEM_ENTITY, "EndGameManager");
    1010ConstructComponent(SYSTEM_ENTITY, "Timer");
    1111
     12Resources = {
     13    "GetCodes": () => ["food", "metal", "stone", "wood"],
     14    "GetResource": () => ({}),
     15};
     16
    1217var cmpPlayer = ConstructComponent(10, "Player");
    1318
    1419TS_ASSERT_EQUALS(cmpPlayer.GetPopulationCount(), 0);
  • new file inaries/data/mods/public/simulation/data/resources/food.json

    diff --git a/binaries/data/mods/public/simulation/data/resources/food.json b/binaries/data/mods/public/simulation/data/resources/food.json
    new file mode 100644
    index 0000000..67c85e7
    - +  
     1{
     2    "code": "food",
     3    "name": "Food",
     4    "subtypes": {
     5        "fish": "Fish",
     6        "fruit": "Fruit",
     7        "grain": "Grain",
     8        "meat": "Meat",
     9        "milk": "Milk"
     10    },
     11    "truePrice": 100,
     12    "aiAnalysisInfluenceGroup": 0,
     13    "enabled": true
     14}
  • new file inaries/data/mods/public/simulation/data/resources/metal.json

    diff --git a/binaries/data/mods/public/simulation/data/resources/metal.json b/binaries/data/mods/public/simulation/data/resources/metal.json
    new file mode 100644
    index 0000000..2a8b590
    - +  
     1{
     2    "code": "metal",
     3    "name": "Metal",
     4    "subtypes": {
     5        "ore": "Ore"
     6    },
     7    "truePrice": 100,
     8    "aiAnalysisInfluenceGroup": 2,
     9    "enabled": true
     10}
  • new file inaries/data/mods/public/simulation/data/resources/stone.json

    diff --git a/binaries/data/mods/public/simulation/data/resources/stone.json b/binaries/data/mods/public/simulation/data/resources/stone.json
    new file mode 100644
    index 0000000..034783e
    - +  
     1{
     2    "code": "stone",
     3    "name": "Stone",
     4    "subtypes": {
     5        "rock": "Rock",
     6        "ruins": "Ruins"
     7    },
     8    "truePrice": 100,
     9    "aiAnalysisInfluenceGroup": 2,
     10    "enabled": true
     11}
  • new file inaries/data/mods/public/simulation/data/resources/wood.json

    diff --git a/binaries/data/mods/public/simulation/data/resources/wood.json b/binaries/data/mods/public/simulation/data/resources/wood.json
    new file mode 100644
    index 0000000..9e5a904
    - +  
     1{
     2    "code": "wood",
     3    "name": "Wood",
     4    "subtypes": {
     5        "tree": "Tree",
     6        "ruins": "Ruins"
     7    },
     8    "truePrice": 100,
     9    "aiAnalysisInfluenceGroup": 1,
     10    "enabled": true
     11}
  • new file inaries/data/mods/public/simulation/helpers/Resources.js

    diff --git a/binaries/data/mods/public/simulation/helpers/Resources.js b/binaries/data/mods/public/simulation/helpers/Resources.js
    new file mode 100644
    index 0000000..7c399b0
    - +  
     1/**
     2 * Builds a RelaxRNG schema based on currently valid elements.
     3 *
     4 * To prevent validation errors, disabled resources are included in the schema.
     5 *
     6 * @param datatype - The datatype of the element
     7 * @param additional - Array of additional data elements. Time, xp, treasure, etc.
     8 * @param subtypes - If true, resource subtypes will be included as well.
     9 * @return RelaxNG schema string
     10 */
     11Resources.prototype.BuildSchema = function(datatype, additional = [], subtypes = false)
     12{
     13    if (!datatype)
     14        return "";
     15
     16    switch (datatype)
     17    {
     18    case "decimal":
     19    case "nonNegativeDecimal":
     20    case "positiveDecimal":
     21        datatype = "<ref name='" + datatype + "'/>";
     22        break;
     23
     24    default:
     25        datatype = "<data type='" + datatype + "'/>";
     26    }
     27
     28    let resCodes = this.resourceData.map(resource => resource.code);
     29    let schema = "";
     30    for (let res of resCodes.concat(additional))
     31        schema +=
     32            "<optional>" +
     33                "<element name='" + res + "'>" +
     34                    datatype +
     35                "</element>" +
     36            "</optional>";
     37
     38    if (!subtypes)
     39        return "<interleave>" + schema + "</interleave>";
     40
     41    for (let res of this.resourceData)
     42        for (let subtype of res.subtypes)
     43            schema +=
     44                "<optional>" +
     45                    "<element name='" + res.code + "." + subtype + "'>" +
     46                        datatype +
     47                    "</element>" +
     48                "</optional>";
     49
     50    if (additional.indexOf("treasure") !== -1)
     51        for (let res of resCodes)
     52            schema +=
     53                "<optional>" +
     54                    "<element name='" + "treasure." + res + "'>" +
     55                        datatype +
     56                    "</element>" +
     57                "</optional>";
     58
     59    return "<interleave>" + schema + "</interleave>";
     60}
     61
     62/**
     63 * Builds the value choices for a RelaxNG `<choice></choice>` object, based on currently valid resources.
     64 *
     65 * @oaram subtypes - If set to true, the choices returned will be resource subtypes, rather than main types
     66 * @param treasure - If set to true, the pseudo resource 'treasure' (or its subtypes) will be included
     67 * @return String of RelaxNG Schema `<choice/>` values.
     68 */
     69Resources.prototype.BuildChoicesSchema = function(subtypes = false, treasure = false)
     70{
     71    let schema = "";
     72
     73    if (!subtypes)
     74    {
     75        let resCodes = this.resourceData.map(resource => resource.code);
     76        if (treasure)
     77            resCodes.push("treasure");
     78        for (let res of resCodes)
     79            schema += "<value>" + res + "</value>";
     80    }
     81    else
     82        for (let res of this.resourceData)
     83        {
     84            for (let subtype of res.subtypes)
     85                schema += "<value>" + res.code + "." + subtype + "</value>";
     86            if (treasure)
     87                schema += "<value>" + "treasure." + res.code + "</value>";
     88        }
     89
     90    return "<choice>" + schema + "</choice>";
     91}
     92
     93Resources = new Resources();