6 | | StatisticsTracker.prototype.Init = function() |
7 | | { |
8 | | // units |
9 | | this.unitsClasses = [ |
10 | | "Infantry", |
11 | | "Worker", |
12 | | "Female", |
13 | | "Cavalry", |
14 | | "Champion", |
15 | | "Hero", |
16 | | "Ship" |
17 | | ]; |
18 | | this.unitsTrained = { |
19 | | "Infantry": 0, |
20 | | "Worker": 0, |
21 | | "Female": 0, |
22 | | "Cavalry": 0, |
23 | | "Champion": 0, |
24 | | "Hero": 0, |
25 | | "Ship": 0, |
26 | | "total": 0 |
27 | | }; |
28 | | this.unitsLost = { |
29 | | "Infantry": 0, |
30 | | "Worker": 0, |
31 | | "Female": 0, |
32 | | "Cavalry": 0, |
33 | | "Champion": 0, |
34 | | "Hero": 0, |
35 | | "Ship": 0, |
36 | | "total": 0 |
37 | | }; |
38 | | this.unitsLostValue = 0; |
39 | | this.enemyUnitsKilled = { |
40 | | "Infantry": 0, |
41 | | "Worker": 0, |
42 | | "Female": 0, |
43 | | "Cavalry": 0, |
44 | | "Champion": 0, |
45 | | "Hero": 0, |
46 | | "Ship": 0, |
47 | | "total": 0 |
48 | | }; |
49 | | this.enemyUnitsKilledValue = 0; |
50 | | // buildings |
51 | | this.buildingsClasses = [ |
52 | | "House", |
53 | | "Economic", |
54 | | "Outpost", |
55 | | "Military", |
56 | | "Fortress", |
57 | | "CivCentre", |
58 | | "Wonder" |
59 | | ]; |
60 | | this.buildingsConstructed = { |
61 | | "House": 0, |
62 | | "Economic": 0, |
63 | | "Outpost": 0, |
64 | | "Military": 0, |
65 | | "Fortress": 0, |
66 | | "CivCentre": 0, |
67 | | "Wonder": 0, |
68 | | "total": 0 |
69 | | }; |
70 | | this.buildingsLost = { |
71 | | "House": 0, |
72 | | "Economic": 0, |
73 | | "Outpost": 0, |
74 | | "Military": 0, |
75 | | "Fortress": 0, |
76 | | "CivCentre": 0, |
77 | | "Wonder": 0, |
78 | | "total": 0 |
79 | | }; |
80 | | this.buildingsLostValue = 0; |
81 | | this.enemyBuildingsDestroyed = { |
82 | | "House": 0, |
83 | | "Economic": 0, |
84 | | "Outpost": 0, |
85 | | "Military": 0, |
86 | | "Fortress": 0, |
87 | | "CivCentre": 0, |
88 | | "Wonder": 0, |
89 | | "total": 0 |
90 | | }; |
91 | | this.enemyBuildingsDestroyedValue = 0; |
92 | | // resources |
93 | | this.resourcesGathered = { |
94 | | "food": 0, |
95 | | "wood": 0, |
96 | | "metal": 0, |
97 | | "stone": 0, |
98 | | "vegetarianFood": 0 |
99 | | }; |
100 | | this.resourcesUsed = { |
101 | | "food": 0, |
102 | | "wood": 0, |
103 | | "metal": 0, |
104 | | "stone": 0 |
105 | | }; |
106 | | this.resourcesSold = { |
107 | | "food": 0, |
108 | | "wood": 0, |
109 | | "metal": 0, |
110 | | "stone": 0 |
111 | | }; |
112 | | this.resourcesBought = { |
113 | | "food": 0, |
114 | | "wood": 0, |
115 | | "metal": 0, |
116 | | "stone": 0 |
117 | | }; |
118 | | this.tributesSent = 0; |
119 | | this.tributesReceived = 0; |
| 6 | StatisticsTracker.prototype.Init = function() |
| 7 | { |
| 8 | // units |
| 9 | this.unitsClasses = [ |
| 10 | "Infantry", |
| 11 | "Worker", |
| 12 | "Female", |
| 13 | "Cavalry", |
| 14 | "Champion", |
| 15 | "Hero", |
| 16 | "Ship", |
| 17 | "Trader" |
| 18 | ]; |
| 19 | this.unitsTrained = { |
| 20 | "Infantry": 0, |
| 21 | "Worker": 0, |
| 22 | "Female": 0, |
| 23 | "Cavalry": 0, |
| 24 | "Champion": 0, |
| 25 | "Hero": 0, |
| 26 | "Ship": 0, |
| 27 | "Trader": 0, |
| 28 | "total": 0 |
| 29 | }; |
| 30 | this.unitsLost = { |
| 31 | "Infantry": 0, |
| 32 | "Worker": 0, |
| 33 | "Female": 0, |
| 34 | "Cavalry": 0, |
| 35 | "Champion": 0, |
| 36 | "Hero": 0, |
| 37 | "Ship": 0, |
| 38 | "Trader": 0, |
| 39 | "total": 0 |
| 40 | }; |
| 41 | this.unitsLostValue = 0; |
| 42 | this.enemyUnitsKilled = { |
| 43 | "Infantry": 0, |
| 44 | "Worker": 0, |
| 45 | "Female": 0, |
| 46 | "Cavalry": 0, |
| 47 | "Champion": 0, |
| 48 | "Hero": 0, |
| 49 | "Ship": 0, |
| 50 | "Trader": 0, |
| 51 | "total": 0 |
| 52 | }; |
| 53 | this.enemyUnitsKilledValue = 0; |
| 54 | // buildings |
| 55 | this.buildingsClasses = [ |
| 56 | "House", |
| 57 | "Economic", |
| 58 | "Outpost", |
| 59 | "Military", |
| 60 | "Fortress", |
| 61 | "CivCentre", |
| 62 | "Wonder" |
| 63 | ]; |
| 64 | this.buildingsConstructed = { |
| 65 | "House": 0, |
| 66 | "Economic": 0, |
| 67 | "Outpost": 0, |
| 68 | "Military": 0, |
| 69 | "Fortress": 0, |
| 70 | "CivCentre": 0, |
| 71 | "Wonder": 0, |
| 72 | "total": 0 |
| 73 | }; |
| 74 | this.buildingsLost = { |
| 75 | "House": 0, |
| 76 | "Economic": 0, |
| 77 | "Outpost": 0, |
| 78 | "Military": 0, |
| 79 | "Fortress": 0, |
| 80 | "CivCentre": 0, |
| 81 | "Wonder": 0, |
| 82 | "total": 0 |
| 83 | }; |
| 84 | this.buildingsLostValue = 0; |
| 85 | this.enemyBuildingsDestroyed = { |
| 86 | "House": 0, |
| 87 | "Economic": 0, |
| 88 | "Outpost": 0, |
| 89 | "Military": 0, |
| 90 | "Fortress": 0, |
| 91 | "CivCentre": 0, |
| 92 | "Wonder": 0, |
| 93 | "total": 0 |
| 94 | }; |
| 95 | this.enemyBuildingsDestroyedValue = 0; |
| 96 | // resources |
| 97 | this.resourcesGathered = { |
| 98 | "food": 0, |
| 99 | "wood": 0, |
| 100 | "metal": 0, |
| 101 | "stone": 0, |
| 102 | "vegetarianFood": 0 |
| 103 | }; |
| 104 | this.resourcesUsed = { |
| 105 | "food": 0, |
| 106 | "wood": 0, |
| 107 | "metal": 0, |
| 108 | "stone": 0 |
| 109 | }; |
| 110 | this.resourcesSold = { |
| 111 | "food": 0, |
| 112 | "wood": 0, |
| 113 | "metal": 0, |
| 114 | "stone": 0 |
| 115 | }; |
| 116 | this.resourcesBought = { |
| 117 | "food": 0, |
| 118 | "wood": 0, |
| 119 | "metal": 0, |
| 120 | "stone": 0 |
| 121 | }; |
| 122 | this.tributesSent = 0; |
| 123 | this.tributesReceived = 0; |
150 | | "buildingsLostValue": this.buildingsLostValue, |
151 | | "enemyBuildingsDestroyed": this.enemyBuildingsDestroyed, |
152 | | "enemyBuildingsDestroyedValue": this.enemyBuildingsDestroyedValue, |
153 | | "resourcesGathered": this.resourcesGathered, |
154 | | "resourcesUsed": this.resourcesUsed, |
155 | | "resourcesSold": this.resourcesSold, |
| 155 | "buildingsLostValue": this.buildingsLostValue, |
| 156 | "enemyBuildingsDestroyed": this.enemyBuildingsDestroyed, |
| 157 | "enemyBuildingsDestroyedValue": this.enemyBuildingsDestroyedValue, |
| 158 | "resourcesGathered": this.resourcesGathered, |
| 159 | "resourcesUsed": this.resourcesUsed, |
| 160 | "resourcesSold": this.resourcesSold, |
163 | | }; |
164 | | }; |
165 | | |
166 | | /** |
167 | | * Increments counter associated with certain entity/counter and type of given entity. |
168 | | * @param cmpIdentity The entity identity component |
169 | | * @param counter The name of the counter to increment (e.g. "unitsTrained") |
170 | | * @param type The type of the counter (e.g. "workers") |
171 | | */ |
172 | | StatisticsTracker.prototype.CounterIncrement = function(cmpIdentity, counter, type) |
173 | | { |
174 | | var classes = cmpIdentity.GetClassesList(); |
175 | | if (!classes) |
176 | | return; |
177 | | if (classes.indexOf(type) != -1) |
178 | | this[counter][type]++; |
179 | | }; |
180 | | |
181 | | /** |
182 | | * Counts the total number of units trained as well as an individual count for |
183 | | * each unit type. Based on templates. |
184 | | * @param trainedUnit The unit that has been trained |
185 | | */ |
186 | | StatisticsTracker.prototype.IncreaseTrainedUnitsCounter = function(trainedUnit) |
187 | | { |
188 | | var cmpUnitEntityIdentity = Engine.QueryInterface(trainedUnit, IID_Identity); |
189 | | |
190 | | if (!cmpUnitEntityIdentity) |
191 | | return; |
192 | | |
193 | | for each (var type in this.unitsClasses) |
194 | | this.CounterIncrement(cmpUnitEntityIdentity, "unitsTrained", type); |
195 | | |
196 | | this.unitsTrained.total++; |
197 | | }; |
198 | | |
199 | | /** |
200 | | * Counts the total number of buildings constructed as well as an individual count for |
201 | | * each building type. Based on templates. |
202 | | * @param constructedBuilding The building that has been constructed |
203 | | */ |
204 | | StatisticsTracker.prototype.IncreaseConstructedBuildingsCounter = function(constructedBuilding) |
205 | | { |
206 | | var cmpBuildingEntityIdentity = Engine.QueryInterface(constructedBuilding, IID_Identity); |
207 | | |
208 | | if (!cmpBuildingEntityIdentity) |
209 | | return; |
210 | | |
211 | | for each(var type in this.buildingsClasses) |
212 | | this.CounterIncrement(cmpBuildingEntityIdentity, "buildingsConstructed", type); |
213 | | |
214 | | this.buildingsConstructed.total++; |
215 | | }; |
216 | | |
217 | | StatisticsTracker.prototype.KilledEntity = function(targetEntity) |
| 169 | }; |
| 170 | }; |
| 171 | |
| 172 | /** |
| 173 | * Increments counter associated with certain entity/counter and type of given entity. |
| 174 | * @param cmpIdentity The entity identity component |
| 175 | * @param counter The name of the counter to increment (e.g. "unitsTrained") |
| 176 | * @param type The type of the counter (e.g. "workers") |
| 177 | */ |
| 178 | StatisticsTracker.prototype.CounterIncrement = function(cmpIdentity, counter, type) |
219 | | var cmpTargetEntityIdentity = Engine.QueryInterface(targetEntity, IID_Identity); |
220 | | var cmpCost = Engine.QueryInterface(targetEntity, IID_Cost); |
221 | | var costs = cmpCost.GetResourceCosts(); |
222 | | if (!cmpTargetEntityIdentity) |
223 | | return; |
224 | | |
225 | | var cmpFoundation = Engine.QueryInterface(targetEntity, IID_Foundation); |
226 | | // We want to deal only with real structures, not foundations |
227 | | var targetIsStructure = cmpTargetEntityIdentity.HasClass("Structure") && cmpFoundation == null; |
228 | | var targetIsDomesticAnimal = cmpTargetEntityIdentity.HasClass("Animal") && cmpTargetEntityIdentity.HasClass("Domestic"); |
229 | | // Don't count domestic animals as units |
230 | | var targetIsUnit = cmpTargetEntityIdentity.HasClass("Unit") && !targetIsDomesticAnimal; |
231 | | |
232 | | var cmpTargetOwnership = Engine.QueryInterface(targetEntity, IID_Ownership); |
233 | | |
234 | | // Don't increase counters if target player is gaia (player 0) |
235 | | if (cmpTargetOwnership.GetOwner() == 0) |
236 | | return; |
237 | | |
238 | | if (targetIsUnit) |
239 | | { |
240 | | for each (var type in this.unitsClasses) |
241 | | this.CounterIncrement(cmpTargetEntityIdentity, "enemyUnitsKilled", type); |
242 | | |
243 | | this.enemyUnitsKilled.total++; |
244 | | |
245 | | for each (var cost in costs) |
246 | | this.enemyUnitsKilledValue += cost; |
247 | | } |
248 | | if (targetIsStructure) |
249 | | { |
250 | | for each (var type in this.buildingsClasses) |
251 | | this.CounterIncrement(cmpTargetEntityIdentity, "enemyBuildingsDestroyed", type); |
252 | | |
253 | | this.enemyBuildingsDestroyed.total++; |
254 | | |
255 | | for each (var cost in costs) |
256 | | this.enemyBuildingsDestroyedValue += cost; |
257 | | } |
258 | | }; |
259 | | |
| 180 | var classes = cmpIdentity.GetClassesList(); |
| 181 | if (!classes) |
| 182 | return; |
| 183 | if (classes.indexOf(type) != -1) |
| 184 | this[counter][type]++; |
| 185 | }; |
| 186 | |
| 187 | /** |
| 188 | * Counts the total number of units trained as well as an individual count for |
| 189 | * each unit type. Based on templates. |
| 190 | * @param trainedUnit The unit that has been trained |
| 191 | */ |
| 192 | StatisticsTracker.prototype.IncreaseTrainedUnitsCounter = function(trainedUnit) |
| 193 | { |
| 194 | var cmpUnitEntityIdentity = Engine.QueryInterface(trainedUnit, IID_Identity); |
| 195 | |
| 196 | if (!cmpUnitEntityIdentity) |
| 197 | return; |
| 198 | |
| 199 | for each (var type in this.unitsClasses) |
| 200 | this.CounterIncrement(cmpUnitEntityIdentity, "unitsTrained", type); |
| 201 | |
| 202 | this.unitsTrained.total++; |
| 203 | }; |
| 204 | |
| 205 | /** |
| 206 | * Counts the total number of buildings constructed as well as an individual count for |
| 207 | * each building type. Based on templates. |
| 208 | * @param constructedBuilding The building that has been constructed |
| 209 | */ |
| 210 | StatisticsTracker.prototype.IncreaseConstructedBuildingsCounter = function(constructedBuilding) |
| 211 | { |
| 212 | var cmpBuildingEntityIdentity = Engine.QueryInterface(constructedBuilding, IID_Identity); |
| 213 | |
| 214 | if (!cmpBuildingEntityIdentity) |
| 215 | return; |
| 216 | |
| 217 | for each(var type in this.buildingsClasses) |
| 218 | this.CounterIncrement(cmpBuildingEntityIdentity, "buildingsConstructed", type); |
| 219 | |
| 220 | this.buildingsConstructed.total++; |
| 221 | }; |
| 222 | |
| 223 | StatisticsTracker.prototype.KilledEntity = function(targetEntity) |
| 224 | { |
| 225 | var cmpTargetEntityIdentity = Engine.QueryInterface(targetEntity, IID_Identity); |
| 226 | var cmpCost = Engine.QueryInterface(targetEntity, IID_Cost); |
| 227 | var costs = cmpCost.GetResourceCosts(); |
| 228 | if (!cmpTargetEntityIdentity) |
| 229 | return; |
| 230 | |
| 231 | var cmpFoundation = Engine.QueryInterface(targetEntity, IID_Foundation); |
| 232 | // We want to deal only with real structures, not foundations |
| 233 | var targetIsStructure = cmpTargetEntityIdentity.HasClass("Structure") && cmpFoundation == null; |
| 234 | var targetIsDomesticAnimal = cmpTargetEntityIdentity.HasClass("Animal") && cmpTargetEntityIdentity.HasClass("Domestic"); |
| 235 | // Don't count domestic animals as units |
| 236 | var targetIsUnit = cmpTargetEntityIdentity.HasClass("Unit") && !targetIsDomesticAnimal; |
| 237 | |
| 238 | var cmpTargetOwnership = Engine.QueryInterface(targetEntity, IID_Ownership); |
| 239 | |
| 240 | // Don't increase counters if target player is gaia (player 0) |
| 241 | if (cmpTargetOwnership.GetOwner() == 0) |
| 242 | return; |
| 243 | |
| 244 | if (targetIsUnit) |
| 245 | { |
| 246 | for each (var type in this.unitsClasses) |
| 247 | this.CounterIncrement(cmpTargetEntityIdentity, "enemyUnitsKilled", type); |
| 248 | |
| 249 | this.enemyUnitsKilled.total++; |
| 250 | |
| 251 | for each (var cost in costs) |
| 252 | this.enemyUnitsKilledValue += cost; |
| 253 | } |
| 254 | if (targetIsStructure) |
| 255 | { |
| 256 | for each (var type in this.buildingsClasses) |
| 257 | this.CounterIncrement(cmpTargetEntityIdentity, "enemyBuildingsDestroyed", type); |
| 258 | |
| 259 | this.enemyBuildingsDestroyed.total++; |
| 260 | |
| 261 | for each (var cost in costs) |
| 262 | this.enemyBuildingsDestroyedValue += cost; |
| 263 | } |
| 264 | }; |
| 265 | |
262 | | var cmpLostEntityIdentity = Engine.QueryInterface(lostEntity, IID_Identity); |
263 | | var cmpCost = Engine.QueryInterface(lostEntity, IID_Cost); |
264 | | var costs = cmpCost.GetResourceCosts(); |
265 | | if (!cmpLostEntityIdentity) |
266 | | return; |
267 | | |
268 | | var cmpFoundation = Engine.QueryInterface(lostEntity, IID_Foundation); |
269 | | // We want to deal only with real structures, not foundations |
270 | | var lostEntityIsStructure = cmpLostEntityIdentity.HasClass("Structure") && cmpFoundation == null; |
271 | | var lostEntityIsDomesticAnimal = cmpLostEntityIdentity.HasClass("Animal") && cmpLostEntityIdentity.HasClass("Domestic"); |
272 | | // Don't count domestic animals as units |
273 | | var lostEntityIsUnit = cmpLostEntityIdentity.HasClass("Unit") && !lostEntityIsDomesticAnimal; |
274 | | |
275 | | if (lostEntityIsUnit) |
276 | | { |
277 | | for each (var type in this.unitsClasses) |
278 | | this.CounterIncrement(cmpLostEntityIdentity, "unitsLost", type); |
279 | | |
280 | | this.unitsLost.total++; |
281 | | |
282 | | for each (var cost in costs) |
283 | | this.unitsLostValue += cost; |
284 | | } |
285 | | if (lostEntityIsStructure) |
286 | | { |
287 | | for each (var type in this.buildingsClasses) |
288 | | this.CounterIncrement(cmpLostEntityIdentity, "buildingsLost", type); |
289 | | |
290 | | this.buildingsLost.total++; |
291 | | |
292 | | for each (var cost in costs) |
293 | | this.buildingsLostValue += cost; |
294 | | } |
295 | | }; |
296 | | |
| 268 | var cmpLostEntityIdentity = Engine.QueryInterface(lostEntity, IID_Identity); |
| 269 | var cmpCost = Engine.QueryInterface(lostEntity, IID_Cost); |
| 270 | var costs = cmpCost.GetResourceCosts(); |
| 271 | if (!cmpLostEntityIdentity) |
| 272 | return; |
| 273 | |
| 274 | var cmpFoundation = Engine.QueryInterface(lostEntity, IID_Foundation); |
| 275 | // We want to deal only with real structures, not foundations |
| 276 | var lostEntityIsStructure = cmpLostEntityIdentity.HasClass("Structure") && cmpFoundation == null; |
| 277 | var lostEntityIsDomesticAnimal = cmpLostEntityIdentity.HasClass("Animal") && cmpLostEntityIdentity.HasClass("Domestic"); |
| 278 | // Don't count domestic animals as units |
| 279 | var lostEntityIsUnit = cmpLostEntityIdentity.HasClass("Unit") && !lostEntityIsDomesticAnimal; |
| 280 | |
| 281 | if (lostEntityIsUnit) |
| 282 | { |
| 283 | for each (var type in this.unitsClasses) |
| 284 | this.CounterIncrement(cmpLostEntityIdentity, "unitsLost", type); |
| 285 | |
| 286 | this.unitsLost.total++; |
| 287 | |
| 288 | for each (var cost in costs) |
| 289 | this.unitsLostValue += cost; |
| 290 | } |
| 291 | if (lostEntityIsStructure) |
| 292 | { |
| 293 | for each (var type in this.buildingsClasses) |
| 294 | this.CounterIncrement(cmpLostEntityIdentity, "buildingsLost", type); |
| 295 | |
| 296 | this.buildingsLost.total++; |
| 297 | |
| 298 | for each (var cost in costs) |
| 299 | this.buildingsLostValue += cost; |
| 300 | } |
| 301 | }; |
| 302 | |
318 | | |
319 | | StatisticsTracker.prototype.IncreaseTreasuresCollectedCounter = function() |
320 | | { |
321 | | this.treasuresCollected++; |
322 | | }; |
323 | | |
324 | | StatisticsTracker.prototype.IncreaseResourcesSoldCounter = function(type, amount) |
325 | | { |
326 | | this.resourcesSold[type] += amount; |
327 | | }; |
328 | | |
329 | | StatisticsTracker.prototype.IncreaseResourcesBoughtCounter = function(type, amount) |
330 | | { |
331 | | this.resourcesBought[type] += amount; |
332 | | }; |
333 | | |
334 | | StatisticsTracker.prototype.IncreaseTributesSentCounter = function(amount) |
335 | | { |
336 | | this.tributesSent += amount; |
337 | | }; |
338 | | |
339 | | StatisticsTracker.prototype.IncreaseTributesReceivedCounter = function(amount) |
340 | | { |
341 | | this.tributesReceived += amount; |
342 | | }; |
343 | | |
344 | | StatisticsTracker.prototype.IncreaseTradeIncomeCounter = function(amount) |
345 | | { |
346 | | this.tradeIncome += amount; |
347 | | }; |
348 | | |
349 | | StatisticsTracker.prototype.GetPercentMapExplored = function() |
350 | | { |
| 324 | |
| 325 | StatisticsTracker.prototype.IncreaseTreasuresCollectedCounter = function() |
| 326 | { |
| 327 | this.treasuresCollected++; |
| 328 | }; |
| 329 | |
| 330 | StatisticsTracker.prototype.IncreaseLootCollectedCounter = function(amount) |
| 331 | { |
| 332 | for (var type in amount) |
| 333 | { |
| 334 | this.lootCollected += (+amount[type]); |
| 335 | } |
| 336 | }; |
| 337 | StatisticsTracker.prototype.IncreaseResourcesSoldCounter = function(type, amount) |
| 338 | { |
| 339 | this.resourcesSold[type] += amount; |
| 340 | }; |
| 341 | |
| 342 | StatisticsTracker.prototype.IncreaseResourcesBoughtCounter = function(type, amount) |
| 343 | { |
| 344 | this.resourcesBought[type] += amount; |
| 345 | }; |
| 346 | |
| 347 | StatisticsTracker.prototype.IncreaseTributesSentCounter = function(amount) |
| 348 | { |
| 349 | this.tributesSent += amount; |
| 350 | }; |
| 351 | |
| 352 | StatisticsTracker.prototype.IncreaseTributesReceivedCounter = function(amount) |
| 353 | { |
| 354 | this.tributesReceived += amount; |
| 355 | }; |
| 356 | |
| 357 | StatisticsTracker.prototype.IncreaseTradeIncomeCounter = function(amount) |
| 358 | { |
| 359 | this.tradeIncome += amount; |
| 360 | }; |
| 361 | |
| 362 | StatisticsTracker.prototype.GetPercentMapExplored = function() |
| 363 | { |