Ticket #638: Summary_v3.diff
File Summary_v3.diff, 33.6 KB (added by , 14 years ago) |
---|
-
binaries/data/mods/public/gui/page_summary.xml
5 5 <include>common/sprite1.xml</include> 6 6 <include>common/init.xml</include> 7 7 <include>summary/summary.xml</include> 8 <include>summary/sprites.xml</include> 8 9 <include>common/global.xml</include> 9 10 </page> -
binaries/data/mods/public/gui/session_new/session.js
114 114 stopMusic(); 115 115 endGame(); 116 116 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 }); 119 122 } 120 123 121 124 // 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) 2 const MAX_SLOTS = 8; 3 4 var panelNames = [ 'unitsBuildingsPanel', 'resourcesPanel' ]; 5 var panelButtonNames = [ 'unitsBuildingsPanelButton', 'resourcesPanelButton' ]; 6 7 /** 8 * @param time Time period in milliseconds (integer) 9 * @return String representing time period 10 */ 11 function 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 */ 23 function 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 1 40 function init(data) 2 41 { 42 getGUIObjectByName("timeElapsed").caption = "Time elapsed: " + timeToString(data.timeElapsed); 43 3 44 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 } 4 176 } -
binaries/data/mods/public/gui/summary/summary.xml
11 11 <object type="image" sprite="bkFillBlack"> 12 12 13 13 <object type="image" 14 style="wheatWindow Granite"14 style="wheatWindow" 15 15 size="25 35 100%-25 100%-25" 16 16 > 17 17 <object type="button" style="wheatWindowTitleBar"> 18 18 Summary 19 19 </object> 20 20 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 /> 28 30 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 trained 58 </object> 59 <object name="unitsLostHeading" type="text" text_align="center" font="serif-bold-14" > 60 Units lost 61 </object> 62 <object name="enemyUnitsKilledHeading" type="text" text_align="center" font="serif-bold-14" > 63 Enemy units killed 64 </object> 65 <object name="buildingsConstructedHeading" type="text" text_align="center" font="serif-bold-14" > 66 Buildings constructed 67 </object> 68 <object name="buildingsLostHeading" type="text" text_align="center" font="serif-bold-14" > 69 Buildings lost 70 </object> 71 <object name="enemyBuildingsDestroyedHeading" type="text" text_align="center" font="serif-bold-14" > 72 Enemy buildings destroyed 73 </object> 74 <object name="civCentresBuildHeading" type="text" text_align="center" font="serif-bold-14" > 75 Civ centres build 76 </object> 77 <object name="enemyCivCentresDestroyedHeading" type="text" text_align="center" font="serif-bold-14" > 78 Enemy civ centres 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 gathered 109 </object> 110 <object name="vegetarianRatioHeading" type="text" text_align="center" font="serif-bold-14" > 111 Vegetarian ratio 112 </object> 113 <object name="woodGatheredHeading" type="text" text_align="center" font="serif-bold-14" > 114 Wood gathered 115 </object> 116 <object name="metalGatheredHeading" type="text" text_align="center" font="serif-bold-14" > 117 Metal gathered 118 </object> 119 <object name="stoneGatheredHeading" type="text" text_align="center" font="serif-bold-14" > 120 Stone 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 29 141 <object type="button" style="wheatButton" size="100%-150 100%-40 100% 100%"> 30 142 Main menu 31 143 <action on="Press"><![CDATA[ -
binaries/data/mods/public/simulation/components/Armour.js
33 33 34 34 // Reduce health 35 35 var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); 36 cmpHealth.Reduce(total);36 return cmpHealth.Reduce(total); 37 37 }; 38 38 39 39 Armour.prototype.GetArmourStrengths = function() -
binaries/data/mods/public/simulation/components/Attack.js
203 203 // TODO: charge attacks (need to design how they work) 204 204 }; 205 205 206 /** 207 * Ñalled when some units kills something (another unit, building, animal etc) 208 * update player statistics only for now 209 */ 210 Attack.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 } 206 217 207 // Inflict damage on the target 218 /** 219 * Inflict damage on the target 220 */ 208 221 Attack.prototype.CauseDamage = function(data) 209 222 { 210 223 var strengths = this.GetAttackStrengths(data.type); … … 212 225 var cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); 213 226 if (!cmpDamageReceiver) 214 227 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 } 216 234 217 235 Engine.PostMessage(data.target, MT_Attacked, 218 236 { "attacker": this.entity, "target": data.target }); -
binaries/data/mods/public/simulation/components/Foundation.js
107 107 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 108 108 var cmpBuildingOwnership = Engine.QueryInterface(building, IID_Ownership); 109 109 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 111 117 var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); 112 118 var cmpBuildingHealth = Engine.QueryInterface(building, IID_Health); 113 119 cmpBuildingHealth.SetHitpoints(cmpHealth.GetHitpoints()); -
binaries/data/mods/public/simulation/components/GuiInterface.js
20 20 GuiInterface.prototype.GetSimulationState = function(player) 21 21 { 22 22 var ret = { 23 "players": [] 23 "players": [], 24 "timeElapsed": 0 24 25 }; 25 26 27 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 28 ret.timeElapsed = cmpTimer.GetTime(); 29 26 30 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 27 31 var n = cmpPlayerMan.GetNumPlayers(); 28 32 for (var i = 0; i < n; ++i) 29 33 { 30 34 var playerEnt = cmpPlayerMan.GetPlayerByID(i); 31 35 var cmpPlayer = Engine.QueryInterface(playerEnt, IID_Player); 36 var cmpPlayerStatisticsTracker = Engine.QueryInterface(playerEnt, IID_StatisticsTracker); 32 37 var playerData = { 33 38 "name": cmpPlayer.GetName(), 34 39 "civ": cmpPlayer.GetCiv(), … … 41 46 "team": cmpPlayer.GetTeam(), 42 47 "diplomacy": cmpPlayer.GetDiplomacy(), 43 48 "phase": cmpPlayer.GetPhase(), 49 "statistics": cmpPlayerStatisticsTracker.GetStatistics() 44 50 }; 45 51 ret.players.push(playerData); 46 52 } -
binaries/data/mods/public/simulation/components/Health.js
79 79 80 80 Health.prototype.Reduce = function(amount) 81 81 { 82 var state = { "killed": false }; 82 83 if (amount >= this.hitpoints) 83 84 { 84 85 // If this is the first time we reached 0, then die. … … 86 87 // might get called multiple times) 87 88 if (this.hitpoints) 88 89 { 90 state.killed = true; 91 89 92 PlaySound("death", this.entity); 90 93 91 94 if (this.template.DeathType == "corpse") … … 121 124 122 125 Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints }); 123 126 } 127 return state; 124 128 }; 125 129 126 130 Health.prototype.Increase = function(amount) -
binaries/data/mods/public/simulation/components/Identity.js
73 73 "<value>Organic</value>" + 74 74 "<value>Structure</value>" + 75 75 "<value>Civic</value>" + 76 "<value>CivCentre</value>" + 76 77 "<value>Economic</value>" + 77 78 "<value>Defensive</value>" + 78 79 "<value>Village</value>" + -
binaries/data/mods/public/simulation/components/interfaces/StatisticsTracker.js
1 Engine.RegisterInterface("StatisticsTracker"); -
binaries/data/mods/public/simulation/components/Looter.js
1 1 function Looter() {} 2 2 3 3 Looter.prototype.Schema = 4 "< empty/>";5 4 "<a:component type='system'/><empty/>"; 5 6 6 /* 7 7 * TODO: this all needs to be designed and implemented 8 8 */ 9 9 10 10 Engine.RegisterComponentType(IID_Looter, "Looter", Looter); 11 11 -
binaries/data/mods/public/simulation/components/Player.js
121 121 return this.resourceCount; 122 122 }; 123 123 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 */ 130 Player.prototype.AddResource = function(type, amount, specificType) 125 131 { 126 132 this.resourceCount[type] += (+amount); 133 var cmpStatisticsTracker = Engine.QueryInterface(this.entity, IID_StatisticsTracker); 134 cmpStatisticsTracker.IncreaseResourceGatheredCounter(type, amount, specificType); 127 135 }; 128 136 137 /** 138 * Add resources to player but not increase gathered resources statistics 139 */ 129 140 Player.prototype.AddResources = function(amounts) 130 141 { 131 142 for (var type in amounts) 143 { 132 144 this.resourceCount[type] += (+amounts[type]); 145 } 133 146 }; 134 147 135 148 Player.prototype.TrySubtractResources = function(amounts) … … 177 190 return this.conquestCriticalEntitiesCount; 178 191 }; 179 192 193 180 194 Player.prototype.GetTeam = function() 181 195 { 182 196 return this.team; … … 207 221 this.phase = p; 208 222 }; 209 223 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 */ 212 228 Player.prototype.OnGlobalOwnershipChanged = function(msg) 213 229 { 214 var classes = [];230 var isConquestCritical = false; 215 231 216 232 // Load class list only if we're going to need it 217 233 if (msg.from == this.playerID || msg.to == this.playerID) 218 234 { 219 235 var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity); 220 236 if (cmpIdentity) 221 classes = cmpIdentity.GetClassesList(); 237 { 238 var classes = cmpIdentity.GetClassesList(); 239 isConquestCritical = classes.indexOf("ConquestCritical") != -1; 240 } 222 241 } 223 242 224 243 if (msg.from == this.playerID) 225 244 { 226 if ( classes.indexOf("ConquestCritical") != -1)227 this.conquestCriticalEntitiesCount--; 245 if (isConquestCritical) 246 this.conquestCriticalEntitiesCount--; 228 247 229 248 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 230 249 if (cost) … … 236 255 237 256 if (msg.to == this.playerID) 238 257 { 239 if ( classes.indexOf("ConquestCritical") != -1)258 if (isConquestCritical) 240 259 this.conquestCriticalEntitiesCount++; 241 260 242 261 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 243 262 if (cost) 244 263 { -
binaries/data/mods/public/simulation/components/ResourceGatherer.js
74 74 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 75 75 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 76 76 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); 78 78 79 79 // Tell the target we're gathering from it 80 80 Engine.PostMessage(target, MT_ResourceGather, -
binaries/data/mods/public/simulation/components/StatisticsTracker.js
1 function StatisticsTracker() {} 2 3 StatisticsTracker.prototype.Schema = 4 "<a:component type='system'/><empty/>"; 5 6 StatisticsTracker.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 29 StatisticsTracker.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 44 StatisticsTracker.prototype.IncreaseTrainedUnitsCounter = function() 45 { 46 return this.unitsTrained++; 47 }; 48 49 StatisticsTracker.prototype.IncreaseConstructedBuildingsCounter = function() 50 { 51 return this.buildingsConstructed++; 52 }; 53 54 StatisticsTracker.prototype.IncreaseBuildCivCentresCounter = function() 55 { 56 return this.civCentresBuild++; 57 }; 58 59 StatisticsTracker.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 83 StatisticsTracker.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 */ 104 StatisticsTracker.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 112 Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker); -
binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
41 41 GetTeam: function() { return -1; }, 42 42 GetDiplomacy: function() { return []; }, 43 43 GetPhase: function() { return ""; }, 44 GetConquestCriticalEntitiesCount: function() { return 1; }, 44 45 }); 45 46 46 47 AddMock(101, IID_Player, { … … 55 56 GetTeam: function() { return -1; }, 56 57 GetDiplomacy: function() { return [1]; }, 57 58 GetPhase: function() { return "village"; }, 59 GetConquestCriticalEntitiesCount: function() { return 1; }, 58 60 }); 59 61 60 62 TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { … … 71 73 team: -1, 72 74 diplomacy: [], 73 75 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 }, 74 90 }, 75 91 { 76 92 name: "Player 2", … … 84 100 team: -1, 85 101 diplomacy: [1], 86 102 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 }, 87 117 } 88 118 ], 89 119 circularMap: false, -
binaries/data/mods/public/simulation/components/TrainingQueue.js
218 218 219 219 var cmpNewOwnership = Engine.QueryInterface(ent, IID_Ownership); 220 220 cmpNewOwnership.SetOwner(cmpOwnership.GetOwner()); 221 221 222 var cmpPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 223 cmpPlayerStatisticsTracker.IncreaseTrainedUnitsCounter(); 224 222 225 ents.push(ent); 223 226 224 227 // 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
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity> 3 3 <Player/> 4 <StatisticsTracker/> 4 5 </Entity> -
binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
3 3 <Identity> 4 4 <GenericName>Civic Centre</GenericName> 5 5 <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> 7 11 <Icon>structures/civic_centre.png</Icon> 8 12 </Identity> 9 13 <BuildRestrictions>