Ticket #638: Summary_v2.diff

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

     
    212212    var cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver);
    213213    if (!cmpDamageReceiver)
    214214        return;
    215     cmpDamageReceiver.TakeDamage(strengths.hack, strengths.pierce, strengths.crush);
     215    var targetState = cmpDamageReceiver.TakeDamage(strengths.hack, strengths.pierce, strengths.crush);
     216    // if target killed pick up loot and credit experience
     217    if (targetState.killed == true)
     218    {
     219        var cmpLooter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Looter);
     220        cmpLooter.TargetKilled(this.entity, data.target);
     221    }
    216222
    217223    Engine.PostMessage(data.target, MT_Attacked,
    218224        { "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 cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     112        var playerEntityId = cmpPlayerManager.GetPlayerByID(cmpOwnership.GetOwner());
     113        var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
     114        cmpPlayer.IncreaseConstructedBuildingsCounter();
     115       
     116        var cmpIdentity = Engine.QueryInterface(building, IID_Identity);
     117        if (cmpIdentity.GetClassesList().indexOf("CivCentre") != -1) cmpPlayer.IncreaseBuildCivCentresCounter();
     118       
    111119        var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
    112120        var cmpBuildingHealth = Engine.QueryInterface(building, IID_Health);
    113121        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)
     
    4145            "team": cmpPlayer.GetTeam(),
    4246            "diplomacy": cmpPlayer.GetDiplomacy(),
    4347            "phase": cmpPlayer.GetPhase(),
     48            "statistics": cmpPlayer.GetStatistics()
    4449        };
    4550        ret.players.push(playerData);
    4651    }
  • 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/Looter.js

     
    11function Looter() {}
    22
    33Looter.prototype.Schema =
    4     "<empty/>";
     4    "<a:component type='system'/><empty/>";
    55
    6 /*
    7  * TODO: this all needs to be designed and implemented
    8  */
     6// called when some units kills something (another unit, building, animal etc)
     7// updating player statistics only for now
     8Looter.prototype.TargetKilled = function(killerEntity, targetEntity)
     9{
     10    var cmpTargetIdentity = Engine.QueryInterface(targetEntity, IID_Identity);
     11    if (cmpTargetIdentity)
     12    {
     13        var classes = cmpTargetIdentity.GetClassesList();
     14        // we want to deal only with real structures, not foundations
     15        var cmpFoundation = Engine.QueryInterface(targetEntity, IID_Foundation);
     16        var targetIsStructure = classes.indexOf("Structure") != -1 && cmpFoundation == null;
     17        var targetIsUnit = classes.indexOf("Unit") != -1;
     18        var targetIsCivCentre = classes.indexOf("CivCentre") != -1;
     19       
     20        var cmpKillerOwnership = Engine.QueryInterface(killerEntity, IID_Ownership);
     21        var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     22        var killerPlayerEntityId = cmpPlayerManager.GetPlayerByID(cmpKillerOwnership.GetOwner());
     23        var cmpKillerPlayer = Engine.QueryInterface(killerPlayerEntityId, IID_Player);
     24       
     25        var cmpTargetOwnership = Engine.QueryInterface(targetEntity, IID_Ownership);
     26       
     27        // don't increase counters if target player is gaia (player 0)
     28        if (cmpTargetOwnership.GetOwner() != 0)
     29        {
     30            if (targetIsUnit) cmpKillerPlayer.IncreaseEnemyUnitsKilledCounter();
     31            if (targetIsStructure) cmpKillerPlayer.IncreaseEnemyBuildingsDestroyedCounter();
     32            if (targetIsCivCentre) cmpKillerPlayer.IncreaseEnemyCivCentresDestroyedCounter();
     33        }
     34    }
     35}
    936
    1037Engine.RegisterComponentType(IID_Looter, "Looter", Looter);
    1138
  • binaries/data/mods/public/simulation/components/Player.js

     
    2424    this.state = "active"; // game state - one of "active", "defeated", "won"
    2525    this.diplomacy = [];    // array of diplomatic stances for this player with respect to other players (including self)
    2626    this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class
     27    // statistics
     28    // units
     29    this.statistics = {
     30        "unitsTrained" : 0,
     31        "unitsLost" : 0,
     32        "enemyUnitsKilled" : 0,
     33        //buildings
     34        "buildingsConstructed" : 0,
     35        "buildingsLost" : 0,
     36        "enemyBuildingsDestroyed" : 0,
     37        // civ centres
     38        "civCentresBuild" : 0,
     39        "enemyCivCentresDestroyed" : 0,
     40        // resources
     41        "resourcesGathered" : {
     42            "food": 0, 
     43            "wood": 0, 
     44            "metal": 0,
     45            "stone": 0,
     46            "vegetarianFood": 0
     47        }
     48    };
    2749    this.phase = "village";
    2850};
    2951
     
    121143    return this.resourceCount;
    122144};
    123145
    124 Player.prototype.AddResource = function(type, amount)
     146/* last param should be passed only from ResourceGatherer.PerformGather */
     147Player.prototype.AddResource = function(type, amount, specificType)
    125148{
    126149    this.resourceCount[type] += (+amount);
     150    this.statistics.resourcesGathered[type] += amount;
     151   
     152    if (type == "food" && (specificType == "fruit" || specificType == "grain"))
     153        this.statistics.resourcesGathered["vegetarianFood"] += amount;
    127154};
    128155
    129156Player.prototype.AddResources = function(amounts)
    130157{
    131158    for (var type in amounts)
     159    {
    132160        this.resourceCount[type] += (+amounts[type]);
     161    }
    133162};
    134163
    135164Player.prototype.TrySubtractResources = function(amounts)
     
    177206    return this.conquestCriticalEntitiesCount;
    178207};
    179208
     209
    180210Player.prototype.GetTeam = function()
    181211{
    182212    return this.team;
     
    207237    this.phase = p;
    208238};
    209239
     240Player.prototype.GetStatistics = function()
     241{
     242    return this.statistics;
     243};
     244
     245Player.prototype.IncreaseTrainedUnitsCounter = function()
     246{
     247    return this.statistics.unitsTrained++;
     248};
     249
     250Player.prototype.IncreaseEnemyUnitsKilledCounter = function()
     251{
     252    return this.statistics.enemyUnitsKilled++;
     253};
     254
     255Player.prototype.IncreaseConstructedBuildingsCounter = function()
     256{
     257    return this.statistics.buildingsConstructed++;
     258};
     259
     260Player.prototype.IncreaseEnemyBuildingsDestroyedCounter = function()
     261{
     262    return this.statistics.enemyBuildingsDestroyed++;
     263};
     264
     265Player.prototype.IncreaseBuildCivCentresCounter = function()
     266{
     267    return this.statistics.civCentresBuild++;
     268};
     269
     270Player.prototype.IncreaseEnemyCivCentresDestroyedCounter = function()
     271{
     272    return this.statistics.enemyCivCentresDestroyed++;
     273};
     274
    210275// Keep track of population effects of all entities that
    211276// become owned or unowned by this player
    212277Player.prototype.OnGlobalOwnershipChanged = function(msg)
    213278{
    214     var classes = [];
     279    var isConquestCritical = false;
     280    var isStructure = false;
     281    var isUnit = false;
    215282
    216283    // Load class list only if we're going to need it
    217284    if (msg.from == this.playerID || msg.to == this.playerID)
    218285    {
    219286        var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity);
    220287        if (cmpIdentity)
    221             classes = cmpIdentity.GetClassesList();
     288        {
     289            var classes = cmpIdentity.GetClassesList();
     290            isConquestCritical = classes.indexOf("ConquestCritical") != -1;
     291            // we want to count only real structures, not foundations
     292            var cmpFoundation = Engine.QueryInterface(msg.entity, IID_Foundation);
     293            isStructure = classes.indexOf("Structure") != -1 && cmpFoundation == null;
     294            isUnit = classes.indexOf("Unit") != -1;
     295        }
    222296    }
    223 
     297   
    224298    if (msg.from == this.playerID)
    225299    {
    226         if (classes.indexOf("ConquestCritical") != -1)
    227             this.conquestCriticalEntitiesCount--;
     300        if (isConquestCritical)
     301            this.conquestCriticalEntitiesCount--;   
     302        if (isStructure)
     303            this.statistics.buildingsLost++;
     304        if (isUnit)
     305            this.statistics.unitsLost++;
    228306
    229307        var cost = Engine.QueryInterface(msg.entity, IID_Cost);
    230308        if (cost)
     
    236314   
    237315    if (msg.to == this.playerID)
    238316    {
    239         if (classes.indexOf("ConquestCritical") != -1)
     317        if (isConquestCritical)
    240318            this.conquestCriticalEntitiesCount++;
    241 
     319           
    242320        var cost = Engine.QueryInterface(msg.entity, IID_Cost);
    243321        if (cost)
    244322        {
  • 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/tests/test_GuiInterface.js

     
    4141    GetTeam: function() { return -1; },
    4242    GetDiplomacy: function() { return []; },
    4343    GetPhase: function() { return ""; },
     44    GetConquestCriticalEntitiesCount: function() { return 1; },
     45    GetUnitsTrained: function() { return 10; },
     46    GetUnitsLost: function() { return 9; },
     47    GetBuildingsConstructed: function() { return 5; },
     48    GetBuildingsLost: function() { return 4; },
     49    GetCivCentresBuild: function() { return 1; },
     50    GetResourcesGathered: function() { return { food: 100 }; },
    4451});
    4552
    4653AddMock(101, IID_Player, {
     
    5562    GetTeam: function() { return -1; },
    5663    GetDiplomacy: function() { return [1]; },
    5764    GetPhase: function() { return "village"; },
     65    GetConquestCriticalEntitiesCount: function() { return 1; },
     66    GetUnitsTrained: function() { return 10; },
     67    GetUnitsLost: function() { return 9; },
     68    GetBuildingsConstructed: function() { return 5; },
     69    GetBuildingsLost: function() { return 4; },
     70    GetCivCentresBuild: function() { return 1; },
     71    GetResourcesGathered: function() { return { food: 100 }; },
    5872});
    5973
    6074TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
     
    7185            team: -1,
    7286            diplomacy: [],
    7387            phase: "",
     88            conquestCriticalEntitiesCount = 1;
     89            unitsTrained = 10;
     90            unitsLost = 9;
     91            buildingsConstructed = 5;
     92            buildingsLost = 4;
     93            civCentresBuild = 1;
     94            resourcesGathered = {
     95                "food": 100,   
     96                "wood": 0, 
     97                "metal": 0,
     98                "stone": 0 
     99            },
    74100        },
    75101        {
    76102            name: "Player 2",
     
    84110            team: -1,
    85111            diplomacy: [1],
    86112            phase: "village",
     113            conquestCriticalEntitiesCount = 1;
     114            unitsTrained = 10;
     115            unitsLost = 9;
     116            buildingsConstructed = 5;
     117            buildingsLost = 4;
     118            civCentresBuild = 1;
     119            resourcesGathered = {
     120                "food": 100,   
     121                "wood": 0, 
     122                "metal": 0,
     123                "stone": 0 
     124            },
    87125        }
    88126    ],
    89127    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 cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     223        var playerEntityId = cmpPlayerManager.GetPlayerByID(cmpOwnership.GetOwner());
     224        var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
     225        cmpPlayer.IncreaseTrainedUnitsCounter();
     226       
    222227        ents.push(ent);
    223228
    224229        // Play a sound, but only for the first in the batch (to avoid nasty phasing effects)
  • 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>
  • source/simulation2/Simulation2.cpp

     
    100100            LOAD_SCRIPTED_COMPONENT("PlayerManager");
    101101            LOAD_SCRIPTED_COMPONENT("Timer");
    102102            LOAD_SCRIPTED_COMPONENT("EndGameManager");
     103            LOAD_SCRIPTED_COMPONENT("Looter");
    103104
    104105#undef LOAD_SCRIPTED_COMPONENT
    105106        }