Ticket #638: Summary_v3.diff

File Summary_v3.diff, 33.6 KB (added by fcxSanya, 14 years ago)
  • binaries/data/mods/public/gui/page_summary.xml

     
    55    <include>common/sprite1.xml</include>
    66    <include>common/init.xml</include>
    77    <include>summary/summary.xml</include>
     8    <include>summary/sprites.xml</include>
    89    <include>common/global.xml</include>
    910</page>
  • binaries/data/mods/public/gui/session_new/session.js

     
    114114    stopMusic();
    115115    endGame();
    116116   
    117     Engine.SwitchGuiPage("page_summary.xml", { "gameResult" : gameResult });
    118    
     117    Engine.SwitchGuiPage("page_summary.xml",
     118                            { "gameResult"  : gameResult,
     119                              "timeElapsed" : simState.timeElapsed,
     120                              "playerStates": simState.players
     121                            });
    119122}
    120123
    121124// Return some data that we'll use when hotloading this file after changes
  • binaries/data/mods/public/gui/summary/sprites.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2
     3<sprites>
     4    <sprite name="bgInfoHeading">
     5        <image  backcolor="0 0 0 150" size="0 0 100% 100%" />
     6    </sprite>
     7   
     8    <sprite name="bgInfoBox">
     9        <image  backcolor="120 70 0 100" size="0 0 100% 100%" />
     10    </sprite>
     11</sprites>
  • binaries/data/mods/public/gui/summary/summary.js

     
     1// Max player slots for any map (should read from config)
     2const MAX_SLOTS = 8;
     3
     4var panelNames = [ 'unitsBuildingsPanel', 'resourcesPanel' ];
     5var panelButtonNames = [ 'unitsBuildingsPanelButton', 'resourcesPanelButton' ];
     6
     7/**
     8 * @param time Time period in milliseconds (integer)
     9 * @return String representing time period
     10 */
     11function timeToString(time)
     12{
     13    var hours   = Math.floor(time / 1000 / 60 / 60);
     14    var minutes = Math.floor(time / 1000 / 60) % 60;
     15    var seconds = Math.floor(time / 1000) % 60;
     16    return hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds);
     17}
     18
     19/**
     20 * Select active panel
     21 * @param panelNumber Number of panel, which should get active state (integer)
     22 */
     23function selectPanel(panelNumber)
     24{
     25    for (var i = 0; i < panelNames.length; i++)
     26    {
     27        if (i != panelNumber)
     28        {
     29            getGUIObjectByName(panelNames[i]).hidden = true;
     30            getGUIObjectByName(panelButtonNames[i]).sprite = "bgInfoHeading";
     31        }
     32        else
     33        {   
     34            getGUIObjectByName(panelNames[i]).hidden = false;
     35            getGUIObjectByName(panelButtonNames[i]).sprite = "bgInfoBox";
     36        }
     37    }
     38}
     39
    140function init(data)
    241{
     42    getGUIObjectByName("timeElapsed").caption = "Time elapsed: " + timeToString(data.timeElapsed);
     43
    344    getGUIObjectByName("summaryText").caption = data.gameResult;
     45   
     46    //Space player boxes
     47    var boxSpacing = 32;
     48    for (var i = 0; i < panelNames.length; ++i)
     49        for (var j = 0; j < MAX_SLOTS; ++j)
     50        {
     51            var box = getGUIObjectByName("playerBox"+i+"["+j+"]");
     52            var boxSize = box.size;
     53            var h = boxSize.bottom - boxSize.top;
     54            boxSize.top = j * boxSpacing;
     55            boxSize.bottom = j * boxSpacing + h;
     56            box.size = boxSize;
     57        }
     58   
     59    // TODO set mapPlayers as playerCounters.length
     60    var maxPlayers = data.playerStates.length - 1;
     61   
     62    // align headers
     63    var left = 50;
     64    var width = 100;
     65    getGUIObjectByName("playerNameHeading").size                = left + " 26 " + (left + width) + " 100%"; left += width;
     66    getGUIObjectByName("unitsTrainedHeading").size              = left + " 16 " + (left + width) + " 100%"; left += width;
     67    getGUIObjectByName("unitsLostHeading").size                 = left + " 16 " + (left + width) + " 100%"; left += width;
     68    getGUIObjectByName("enemyUnitsKilledHeading").size          = left + " 16 " + (left + width) + " 100%"; left += width;
     69    getGUIObjectByName("buildingsConstructedHeading").size      = left + " 16 " + (left + width) + " 100%"; left += width;
     70    getGUIObjectByName("buildingsLostHeading").size             = left + " 16 " + (left + width) + " 100%"; left += width;
     71    getGUIObjectByName("enemyBuildingsDestroyedHeading").size   = left +  " 6 " + (left + width) + " 100%"; left += width;
     72    getGUIObjectByName("civCentresBuildHeading").size           = left + " 16 " + (left + width) + " 100%"; left += width;
     73    getGUIObjectByName("enemyCivCentresDestroyedHeading").size  = left +  " 6 " + (left + width) + " 100%"; left += width;
     74   
     75    var left = 50;
     76    getGUIObjectByName("playerName2Heading").size       = left + " 26 " + (left + width) + " 100%"; left += width;
     77    getGUIObjectByName("foodGatheredHeading").size      = left + " 16 " + (left + width) + " 100%"; left += width;
     78    getGUIObjectByName("vegetarianRatioHeading").size   = left + " 16 " + (left + width) + " 100%"; left += width;
     79    getGUIObjectByName("woodGatheredHeading").size      = left + " 16 " + (left + width) + " 100%"; left += width;
     80    getGUIObjectByName("metalGatheredHeading").size     = left + " 16 " + (left + width) + " 100%"; left += width;
     81    getGUIObjectByName("stoneGatheredHeading").size     = left + " 16 " + (left + width) + " 100%"; left += width;
     82   
     83    // Show counters
     84    for (var i = 0; i < MAX_SLOTS; ++i)
     85    {       
     86        if (i < maxPlayers)
     87        {
     88            var playerState = data.playerStates[i+1];
     89       
     90            for (var k = 0; k < panelNames.length; ++k)
     91            {
     92                var playerBox = getGUIObjectByName("playerBox"+k+"["+i+"]");
     93                playerBox.hidden = false;       
     94               
     95                var colourString = "colour: "
     96                    + Math.floor(playerState.colour.r * 255) + " "
     97                    + Math.floor(playerState.colour.g * 255) + " "
     98                    + Math.floor(playerState.colour.b * 255);
     99                playerBox.sprite = colourString + " 32";
     100                var playerColourBox = getGUIObjectByName("playerColourBox"+k+"["+i+"]");
     101                playerColourBox.sprite = colourString + " 255";
     102           
     103                var playerName = getGUIObjectByName("playerName"+k+"["+i+"]");
     104                playerName.caption = playerState.name;
     105            }
     106           
     107            var unitsTrained                = getGUIObjectByName("unitsTrained["+i+"]");
     108            var unitsLost                   = getGUIObjectByName("unitsLost["+i+"]");
     109            var enemyUnitsKilled            = getGUIObjectByName("enemyUnitsKilled["+i+"]");
     110            var buildingsConstructed        = getGUIObjectByName("buildingsConstructed["+i+"]");
     111            var buildingsLost               = getGUIObjectByName("buildingsLost["+i+"]");
     112            var enemyBuildingsDestroyed     = getGUIObjectByName("enemyBuildingsDestroyed["+i+"]");
     113            var civCentresBuild             = getGUIObjectByName("civCentresBuild["+i+"]");
     114            var enemyCivCentresDestroyed    = getGUIObjectByName("enemyCivCentresDestroyed["+i+"]");
     115           
     116            var foodGathered                = getGUIObjectByName("foodGathered["+i+"]");
     117            var vegetarianRatio             = getGUIObjectByName("vegetarianRatio["+i+"]");
     118            var woodGathered                = getGUIObjectByName("woodGathered["+i+"]");
     119            var metalGathered               = getGUIObjectByName("metalGathered["+i+"]");
     120            var stoneGathered               = getGUIObjectByName("stoneGathered["+i+"]");
     121           
     122            // align counters
     123           
     124            var left = 140;
     125            var width = 100;
     126            unitsTrained.size               = left + " 2 " + (left + width) + " 100%"; left += width;
     127            unitsLost.size                  = left + " 2 " + (left + width) + " 100%"; left += width;
     128            enemyUnitsKilled.size           = left + " 2 " + (left + width) + " 100%"; left += width;
     129            buildingsConstructed.size       = left + " 2 " + (left + width) + " 100%"; left += width;
     130            buildingsLost.size              = left + " 2 " + (left + width) + " 100%"; left += width;
     131            enemyBuildingsDestroyed.size    = left + " 2 " + (left + width) + " 100%"; left += width;
     132            civCentresBuild.size            = left + " 2 " + (left + width) + " 100%"; left += width;
     133            enemyCivCentresDestroyed.size   = left + " 2 " + (left + width) + " 100%"; left += width;
     134            var size = getGUIObjectByName("playerBox0["+i+"]").size;
     135            size.right = left + 10;
     136            getGUIObjectByName("playerBox0["+i+"]").size = size;
     137           
     138           
     139            var left = 140;
     140            foodGathered.size       = left + " 2 " + (left + width) + " 100%"; left += width;
     141            vegetarianRatio.size    = left + " 2 " + (left + width) + " 100%"; left += width;
     142            woodGathered.size       = left + " 2 " + (left + width) + " 100%"; left += width;
     143            metalGathered.size      = left + " 2 " + (left + width) + " 100%"; left += width;
     144            stoneGathered.size      = left + " 2 " + (left + width) + " 100%"; left += width;
     145            var size = getGUIObjectByName("playerBox1["+i+"]").size;
     146            size.right = left + 10;
     147            getGUIObjectByName("playerBox1["+i+"]").size = size;
     148           
     149            // display counters
     150            unitsTrained.caption                = playerState.statistics.unitsTrained;
     151            unitsLost.caption                   = playerState.statistics.unitsLost;
     152            enemyUnitsKilled.caption            = playerState.statistics.enemyUnitsKilled;
     153            buildingsConstructed.caption        = playerState.statistics.buildingsConstructed;
     154            buildingsLost.caption               = playerState.statistics.buildingsLost;
     155            enemyBuildingsDestroyed.caption     = playerState.statistics.enemyBuildingsDestroyed;
     156            civCentresBuild.caption             = playerState.statistics.civCentresBuild;
     157            enemyCivCentresDestroyed.caption    = playerState.statistics.enemyCivCentresDestroyed;
     158           
     159            foodGathered.caption         = playerState.statistics.resourcesGathered.food;
     160            vegetarianRatio.caption      = Math.floor(playerState.statistics.resourcesGathered.food > 0 ?
     161                (playerState.statistics.resourcesGathered.vegetarianFood / playerState.statistics.resourcesGathered.food) * 100 : 0) + "%";
     162            woodGathered.caption         = playerState.statistics.resourcesGathered.wood;
     163            metalGathered.caption        = playerState.statistics.resourcesGathered.metal;
     164            stoneGathered.caption        = playerState.statistics.resourcesGathered.stone;
     165        }
     166        else
     167        {
     168            // hide player boxes
     169            for (var k = 0; k < panelNames.length; ++k)
     170            {
     171                var playerBox = getGUIObjectByName("playerBox"+k+"["+i+"]");
     172                playerBox.hidden = true;
     173            }
     174        }
     175    }
    4176}
  • binaries/data/mods/public/gui/summary/summary.xml

     
    1111    <object type="image" sprite="bkFillBlack">
    1212
    1313        <object type="image"
    14             style="wheatWindowGranite"
     14            style="wheatWindow"
    1515            size="25 35 100%-25 100%-25"
    1616        >
    1717            <object type="button" style="wheatWindowTitleBar">
    1818                Summary
    1919            </object>
    2020           
    21             <object name="summaryText"
    22                 type="text"
    23                 size="50 50 100%-50 100%-200"
    24                 font="serif-16"
    25                 text_align="center"
    26                 text_valign="center"
    27             />
     21            <object type="image" sprite="bgInfoHeading" size="0 10 100% 40">               
     22                <object
     23                    name="summaryText"
     24                    type="text"
     25                    size="50 0 100%-50 30"
     26                    font="serif-bold-18"
     27                    textcolor="255 255 255"
     28                    text_align="center"
     29                />
    2830           
     31                <object
     32                    name="timeElapsed"
     33                    type="text"
     34                    size="100%-200 0 100%-10 30"
     35                    font="serif-16"
     36                    textcolor="255 255 255"
     37                    text_align="center"
     38                />
     39            </object>
     40           
     41           
     42            <object name="unitsBuildingsPanelButton" type="button" sprite="bgInfoBox" text_align="center" size="10 75 160 101">
     43                <action on="Press">selectPanel(0);</action>
     44                Units/buildings
     45            </object>
     46            <object name="resourcesPanelButton" type="button" sprite="bgInfoHeading" text_align="center" size="160 75 310 101">
     47                <action on="Press">selectPanel(1);</action>
     48                Resources
     49            </object>
     50            <object name="unitsBuildingsPanel" type="image" sprite="bgInfoBox" size="10 100 100%-10 100%-50">
     51               
     52                <object size="0 0 100% 100%-50">
     53                    <object name="playerNameHeading" type="text" text_align="left" font="serif-bold-14" >
     54                        Player name
     55                    </object>
     56                    <object name="unitsTrainedHeading" type="text" text_align="center" font="serif-bold-14" >
     57                        Units&#10;trained
     58                    </object>
     59                    <object name="unitsLostHeading" type="text" text_align="center" font="serif-bold-14" >
     60                        Units&#10;lost
     61                    </object>
     62                    <object name="enemyUnitsKilledHeading" type="text" text_align="center" font="serif-bold-14" >
     63                        Enemy units&#10;killed
     64                    </object>
     65                    <object name="buildingsConstructedHeading" type="text" text_align="center" font="serif-bold-14" >
     66                        Buildings&#10;constructed
     67                    </object>
     68                    <object name="buildingsLostHeading" type="text" text_align="center" font="serif-bold-14" >
     69                        Buildings&#10;lost
     70                    </object>
     71                    <object name="enemyBuildingsDestroyedHeading" type="text" text_align="center" font="serif-bold-14" >
     72                        Enemy&#10;buildings&#10;destroyed
     73                    </object>
     74                    <object name="civCentresBuildHeading" type="text" text_align="center" font="serif-bold-14" >
     75                        Civ centres&#10;build
     76                    </object>
     77                    <object name="enemyCivCentresDestroyedHeading" type="text" text_align="center" font="serif-bold-14" >
     78                        Enemy&#10;civ centres&#10;destroyed
     79                    </object>
     80                   
     81                </object>   
     82               
     83                <object size="0 65 100% 100%-50">
     84                    <repeat count="8">
     85                        <object type="image" name="playerBox0[n]" size="10 0 10 30" hidden="true">
     86                            <object name="playerColourBox0[n]"          type="image" size="10 4 30 24" />
     87                            <object name="playerName0[n]"               type="text" text_align="left"  size="40 2 140 100%" />
     88                            <object name="unitsTrained[n]"              type="text" text_align="center" />
     89                            <object name="unitsLost[n]"                 type="text" text_align="center" />
     90                            <object name="enemyUnitsKilled[n]"          type="text" text_align="center" />
     91                            <object name="buildingsConstructed[n]"      type="text" text_align="center" />
     92                            <object name="buildingsLost[n]"             type="text" text_align="center" />
     93                            <object name="enemyBuildingsDestroyed[n]"   type="text" text_align="center" />
     94                            <object name="civCentresBuild[n]"           type="text" text_align="center" />
     95                            <object name="enemyCivCentresDestroyed[n]"  type="text" text_align="center" />
     96                        </object>
     97                    </repeat>
     98                </object>
     99           
     100            </object>
     101            <object name="resourcesPanel" type="image" sprite="bgInfoBox" size="10 100 100%-10 100%-50" hidden="true">
     102           
     103                <object size="0 0 100% 100%-50">
     104                    <object name="playerName2Heading" type="text" text_align="left" font="serif-bold-14" >
     105                        Player name
     106                    </object>
     107                    <object name="foodGatheredHeading" type="text" text_align="center" font="serif-bold-14" >
     108                        Food&#10;gathered
     109                    </object>
     110                    <object name="vegetarianRatioHeading" type="text" text_align="center" font="serif-bold-14" >
     111                        Vegetarian&#10;ratio
     112                    </object>
     113                    <object name="woodGatheredHeading" type="text" text_align="center" font="serif-bold-14" >
     114                        Wood&#10;gathered
     115                    </object>
     116                    <object name="metalGatheredHeading" type="text" text_align="center" font="serif-bold-14" >
     117                        Metal&#10;gathered
     118                    </object>
     119                    <object name="stoneGatheredHeading" type="text" text_align="center" font="serif-bold-14" >
     120                        Stone&#10;gathered
     121                    </object>
     122                   
     123                </object>   
     124               
     125                <object size="0 65 100% 100%-50">
     126                    <repeat count="8">
     127                        <object type="image" name="playerBox1[n]" size="10 0 10 30" hidden="true">
     128                            <object name="playerColourBox1[n]" type="image" size="10 4 30 24" />
     129                            <object name="playerName1[n]"      type="text" text_align="left"  size="40 2 140 100%" />
     130                            <object name="foodGathered[n]"     type="text" text_align="center" />
     131                            <object name="vegetarianRatio[n]"  type="text" text_align="center" />
     132                            <object name="woodGathered[n]"     type="text" text_align="center" />
     133                            <object name="metalGathered[n]"    type="text" text_align="center" />
     134                            <object name="stoneGathered[n]"    type="text" text_align="center" />
     135                        </object>
     136                    </repeat>
     137                </object>
     138           
     139            </object>
     140           
    29141            <object type="button" style="wheatButton" size="100%-150 100%-40 100% 100%">
    30142                Main menu
    31143                <action on="Press"><![CDATA[
  • binaries/data/mods/public/simulation/components/Armour.js

     
    3333
    3434    // Reduce health
    3535    var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
    36     cmpHealth.Reduce(total);
     36    return cmpHealth.Reduce(total);
    3737};
    3838
    3939Armour.prototype.GetArmourStrengths = function()
  • binaries/data/mods/public/simulation/components/Attack.js

     
    203203    // TODO: charge attacks (need to design how they work)
    204204};
    205205
     206/**
     207 * Ñalled when some units kills something (another unit, building, animal etc)
     208 * update player statistics only for now
     209 */
     210Attack.prototype.TargetKilled = function(killerEntity, targetEntity)
     211{
     212    var cmpKillerPlayerStatisticsTracker = QueryOwnerInterface(killerEntity, IID_StatisticsTracker);
     213    cmpKillerPlayerStatisticsTracker.KilledEntity(targetEntity);
     214    var cmpTargetPlayerStatisticsTracker = QueryOwnerInterface(targetEntity, IID_StatisticsTracker);
     215    cmpTargetPlayerStatisticsTracker.LostEntity(targetEntity);
     216}
    206217
    207 // Inflict damage on the target
     218/**
     219 * Inflict damage on the target
     220 */
    208221Attack.prototype.CauseDamage = function(data)
    209222{
    210223    var strengths = this.GetAttackStrengths(data.type);
     
    212225    var cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver);
    213226    if (!cmpDamageReceiver)
    214227        return;
    215     cmpDamageReceiver.TakeDamage(strengths.hack, strengths.pierce, strengths.crush);
     228    var targetState = cmpDamageReceiver.TakeDamage(strengths.hack, strengths.pierce, strengths.crush);
     229    // if target killed pick up loot and credit experience
     230    if (targetState.killed == true)
     231    {
     232        this.TargetKilled(this.entity, data.target);
     233    }
    216234
    217235    Engine.PostMessage(data.target, MT_Attacked,
    218236        { "attacker": this.entity, "target": data.target });
  • binaries/data/mods/public/simulation/components/Foundation.js

     
    107107        var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    108108        var cmpBuildingOwnership = Engine.QueryInterface(building, IID_Ownership);
    109109        cmpBuildingOwnership.SetOwner(cmpOwnership.GetOwner());
    110 
     110       
     111        var cmpPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
     112        cmpPlayerStatisticsTracker.IncreaseConstructedBuildingsCounter();
     113               
     114        var cmpIdentity = Engine.QueryInterface(building, IID_Identity);
     115        if (cmpIdentity.GetClassesList().indexOf("CivCentre") != -1) cmpPlayerStatisticsTracker.IncreaseBuildCivCentresCounter();
     116       
    111117        var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
    112118        var cmpBuildingHealth = Engine.QueryInterface(building, IID_Health);
    113119        cmpBuildingHealth.SetHitpoints(cmpHealth.GetHitpoints());
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    2020GuiInterface.prototype.GetSimulationState = function(player)
    2121{
    2222    var ret = {
    23         "players": []
     23        "players": [],
     24        "timeElapsed": 0   
    2425    };
    2526
     27    var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     28    ret.timeElapsed = cmpTimer.GetTime();
     29   
    2630    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    2731    var n = cmpPlayerMan.GetNumPlayers();
    2832    for (var i = 0; i < n; ++i)
    2933    {
    3034        var playerEnt = cmpPlayerMan.GetPlayerByID(i);
    3135        var cmpPlayer = Engine.QueryInterface(playerEnt, IID_Player);
     36        var cmpPlayerStatisticsTracker = Engine.QueryInterface(playerEnt, IID_StatisticsTracker);
    3237        var playerData = {
    3338            "name": cmpPlayer.GetName(),
    3439            "civ": cmpPlayer.GetCiv(),
     
    4146            "team": cmpPlayer.GetTeam(),
    4247            "diplomacy": cmpPlayer.GetDiplomacy(),
    4348            "phase": cmpPlayer.GetPhase(),
     49            "statistics": cmpPlayerStatisticsTracker.GetStatistics()
    4450        };
    4551        ret.players.push(playerData);
    4652    }
  • binaries/data/mods/public/simulation/components/Health.js

     
    7979
    8080Health.prototype.Reduce = function(amount)
    8181{
     82    var state = { "killed": false };
    8283    if (amount >= this.hitpoints)
    8384    {
    8485        // If this is the first time we reached 0, then die.
     
    8687        // might get called multiple times)
    8788        if (this.hitpoints)
    8889        {
     90            state.killed = true;
     91           
    8992            PlaySound("death", this.entity);
    9093
    9194            if (this.template.DeathType == "corpse")
     
    121124
    122125        Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints });
    123126    }
     127    return state;
    124128};
    125129
    126130Health.prototype.Increase = function(amount)
  • binaries/data/mods/public/simulation/components/Identity.js

     
    7373                        "<value>Organic</value>" +
    7474                        "<value>Structure</value>" +
    7575                        "<value>Civic</value>" +
     76                        "<value>CivCentre</value>" +
    7677                        "<value>Economic</value>" +
    7778                        "<value>Defensive</value>" +
    7879                        "<value>Village</value>" +
  • binaries/data/mods/public/simulation/components/interfaces/StatisticsTracker.js

     
     1Engine.RegisterInterface("StatisticsTracker");
  • binaries/data/mods/public/simulation/components/Looter.js

     
    11function Looter() {}
    22
    33Looter.prototype.Schema =
    4     "<empty/>";
    5 
     4    "<a:component type='system'/><empty/>";
     5   
    66/*
    77 * TODO: this all needs to be designed and implemented
    88 */
    9 
     9 
    1010Engine.RegisterComponentType(IID_Looter, "Looter", Looter);
    1111
  • binaries/data/mods/public/simulation/components/Player.js

     
    121121    return this.resourceCount;
    122122};
    123123
    124 Player.prototype.AddResource = function(type, amount)
     124/**
     125 * Add resource of specified type to player and increase gathered resources statistics
     126 * @param type Generic type of resource (string)
     127 * @param amount Amount of resource, whick should be added (integer)
     128 * @param specificType Specific type of resource (string, optional)
     129 */
     130Player.prototype.AddResource = function(type, amount, specificType)
    125131{
    126132    this.resourceCount[type] += (+amount);
     133    var cmpStatisticsTracker = Engine.QueryInterface(this.entity, IID_StatisticsTracker);
     134    cmpStatisticsTracker.IncreaseResourceGatheredCounter(type, amount, specificType);
    127135};
    128136
     137/**
     138 * Add resources to player but not increase gathered resources statistics
     139 */
    129140Player.prototype.AddResources = function(amounts)
    130141{
    131142    for (var type in amounts)
     143    {
    132144        this.resourceCount[type] += (+amounts[type]);
     145    }
    133146};
    134147
    135148Player.prototype.TrySubtractResources = function(amounts)
     
    177190    return this.conquestCriticalEntitiesCount;
    178191};
    179192
     193
    180194Player.prototype.GetTeam = function()
    181195{
    182196    return this.team;
     
    207221    this.phase = p;
    208222};
    209223
    210 // Keep track of population effects of all entities that
    211 // become owned or unowned by this player
     224/**
     225 * Keep track of population effects of all entities that
     226 * become owned or unowned by this player
     227 */
    212228Player.prototype.OnGlobalOwnershipChanged = function(msg)
    213229{
    214     var classes = [];
     230    var isConquestCritical = false;
    215231
    216232    // Load class list only if we're going to need it
    217233    if (msg.from == this.playerID || msg.to == this.playerID)
    218234    {
    219235        var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity);
    220236        if (cmpIdentity)
    221             classes = cmpIdentity.GetClassesList();
     237        {
     238            var classes = cmpIdentity.GetClassesList();
     239            isConquestCritical = classes.indexOf("ConquestCritical") != -1;
     240        }
    222241    }
    223 
     242   
    224243    if (msg.from == this.playerID)
    225244    {
    226         if (classes.indexOf("ConquestCritical") != -1)
    227             this.conquestCriticalEntitiesCount--;
     245        if (isConquestCritical)
     246            this.conquestCriticalEntitiesCount--;   
    228247
    229248        var cost = Engine.QueryInterface(msg.entity, IID_Cost);
    230249        if (cost)
     
    236255   
    237256    if (msg.to == this.playerID)
    238257    {
    239         if (classes.indexOf("ConquestCritical") != -1)
     258        if (isConquestCritical)
    240259            this.conquestCriticalEntitiesCount++;
    241 
     260           
    242261        var cost = Engine.QueryInterface(msg.entity, IID_Cost);
    243262        if (cost)
    244263        {
  • binaries/data/mods/public/simulation/components/ResourceGatherer.js

     
    7474    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    7575    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    7676    var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(cmpOwnership.GetOwner()), IID_Player);
    77     cmpPlayer.AddResource(type.generic, status.amount);
     77    cmpPlayer.AddResource(type.generic, status.amount, type.specific);
    7878
    7979    // Tell the target we're gathering from it
    8080    Engine.PostMessage(target, MT_ResourceGather,
  • binaries/data/mods/public/simulation/components/StatisticsTracker.js

     
     1function StatisticsTracker() {}
     2
     3StatisticsTracker.prototype.Schema =
     4    "<a:component type='system'/><empty/>";
     5   
     6StatisticsTracker.prototype.Init = function()
     7{
     8    // units
     9    this.unitsTrained = 0;
     10    this.unitsLost = 0;
     11    this.enemyUnitsKilled = 0;
     12    //buildings
     13    this.buildingsConstructed = 0;
     14    this.buildingsLost = 0;
     15    this.enemyBuildingsDestroyed = 0;
     16    // civ centres
     17    this.civCentresBuild = 0;
     18    this.enemyCivCentresDestroyed = 0;
     19    // resources
     20    this.resourcesGathered = {
     21            "food": 0, 
     22            "wood": 0, 
     23            "metal": 0,
     24            "stone": 0,
     25            "vegetarianFood": 0
     26    }
     27};
     28
     29StatisticsTracker.prototype.GetStatistics = function()
     30{
     31    return {
     32        "unitsTrained" : this.unitsTrained,
     33        "unitsLost" : this.unitsLost,
     34        "enemyUnitsKilled" : this.enemyUnitsKilled,
     35        "buildingsConstructed" : this.buildingsConstructed,
     36        "buildingsLost" : this.buildingsLost,
     37        "enemyBuildingsDestroyed" : this.enemyBuildingsDestroyed,
     38        "civCentresBuild" : this.civCentresBuild,
     39        "enemyCivCentresDestroyed" : this.enemyCivCentresDestroyed,
     40        "resourcesGathered" : this.resourcesGathered
     41    };
     42};
     43
     44StatisticsTracker.prototype.IncreaseTrainedUnitsCounter = function()
     45{
     46    return this.unitsTrained++;
     47};
     48
     49StatisticsTracker.prototype.IncreaseConstructedBuildingsCounter = function()
     50{
     51    return this.buildingsConstructed++;
     52};
     53
     54StatisticsTracker.prototype.IncreaseBuildCivCentresCounter = function()
     55{
     56    return this.civCentresBuild++;
     57};
     58
     59StatisticsTracker.prototype.KilledEntity = function(targetEntity)
     60{
     61    var cmpTargetEntityIdentity = Engine.QueryInterface(targetEntity, IID_Identity);
     62    if (cmpTargetEntityIdentity)
     63    {
     64        var classes = cmpTargetEntityIdentity.GetClassesList();
     65        // we want to deal only with real structures, not foundations
     66        var cmpFoundation = Engine.QueryInterface(targetEntity, IID_Foundation);
     67        var targetIsStructure = classes.indexOf("Structure") != -1 && cmpFoundation == null;
     68        var targetIsUnit = classes.indexOf("Unit") != -1;
     69        var targetIsCivCentre = classes.indexOf("CivCentre") != -1;
     70               
     71        var cmpTargetOwnership = Engine.QueryInterface(targetEntity, IID_Ownership);
     72       
     73        // don't increase counters if target player is gaia (player 0)
     74        if (cmpTargetOwnership.GetOwner() != 0)
     75        {
     76            if (targetIsUnit) this.enemyUnitsKilled++;
     77            if (targetIsStructure) this.enemyBuildingsDestroyed++;
     78            if (targetIsCivCentre) this.enemyCivCentresDestroyed++;
     79        }
     80    }
     81};
     82
     83StatisticsTracker.prototype.LostEntity = function(lostEntity)
     84{
     85    var cmpLostEntityIdentity = Engine.QueryInterface(lostEntity, IID_Identity);
     86    if (cmpLostEntityIdentity)
     87    {
     88        var classes = cmpLostEntityIdentity.GetClassesList();
     89        // we want to deal only with real structures, not foundations
     90        var cmpFoundation = Engine.QueryInterface(lostEntity, IID_Foundation);
     91        var lostEntityIsStructure = classes.indexOf("Structure") != -1 && cmpFoundation == null;
     92        var lostEntityIsUnit = classes.indexOf("Unit") != -1;
     93
     94        if (lostEntityIsUnit) this.unitsLost++;
     95        if (lostEntityIsStructure) this.buildingsLost++;
     96    }
     97};
     98
     99/**
     100 * @param type Generic type of resource (string)
     101 * @param amount Amount of resource, whick should be added (integer)
     102 * @param specificType Specific type of resource (string, optional)
     103 */
     104StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amount, specificType)
     105{
     106    this.resourcesGathered[type] += amount;
     107   
     108    if (type == "food" && (specificType == "fruit" || specificType == "grain"))
     109        this.resourcesGathered["vegetarianFood"] += amount;
     110};
     111
     112Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker);
  • binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js

     
    4141    GetTeam: function() { return -1; },
    4242    GetDiplomacy: function() { return []; },
    4343    GetPhase: function() { return ""; },
     44    GetConquestCriticalEntitiesCount: function() { return 1; },
    4445});
    4546
    4647AddMock(101, IID_Player, {
     
    5556    GetTeam: function() { return -1; },
    5657    GetDiplomacy: function() { return [1]; },
    5758    GetPhase: function() { return "village"; },
     59    GetConquestCriticalEntitiesCount: function() { return 1; },
    5860});
    5961
    6062TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
     
    7173            team: -1,
    7274            diplomacy: [],
    7375            phase: "",
     76            statistics: {
     77                unitsTrained: 10,
     78                unitsLost: 9,
     79                buildingsConstructed: 5,
     80                buildingsLost: 4,
     81                civCentresBuild: 1,
     82                resourcesGathered: {
     83                    food: 100, 
     84                    wood: 0,   
     85                    metal: 0,   
     86                    stone: 0,
     87                    vegetarianFood: 0
     88                }
     89            },
    7490        },
    7591        {
    7692            name: "Player 2",
     
    84100            team: -1,
    85101            diplomacy: [1],
    86102            phase: "village",
     103            statistics: {
     104                unitsTrained: 10,
     105                unitsLost: 9,
     106                buildingsConstructed: 5,
     107                buildingsLost: 4,
     108                civCentresBuild: 1,
     109                resourcesGathered: {
     110                    food: 100, 
     111                    wood: 0,   
     112                    metal: 0,   
     113                    stone: 0,
     114                    vegetarianFood: 0
     115                }
     116            },
    87117        }
    88118    ],
    89119    circularMap: false,
  • binaries/data/mods/public/simulation/components/TrainingQueue.js

     
    218218
    219219        var cmpNewOwnership = Engine.QueryInterface(ent, IID_Ownership);
    220220        cmpNewOwnership.SetOwner(cmpOwnership.GetOwner());
    221 
     221       
     222        var cmpPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
     223        cmpPlayerStatisticsTracker.IncreaseTrainedUnitsCounter();
     224       
    222225        ents.push(ent);
    223226
    224227        // Play a sound, but only for the first in the batch (to avoid nasty phasing effects)
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity>
    33  <Player/>
     4  <StatisticsTracker/>
    45</Entity>
  • binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml

     
    33  <Identity>
    44    <GenericName>Civic Centre</GenericName>
    55    <Tooltip>Build upon a settlement to capture territory.</Tooltip>
    6     <Classes datatype="tokens">Village Defensive</Classes>
     6    <Classes datatype="tokens">
     7        Village
     8        Defensive
     9        CivCentre
     10    </Classes>
    711    <Icon>structures/civic_centre.png</Icon>
    812  </Identity>
    913  <BuildRestrictions>