| 83 | ProductionQueue.prototype.OnOwnershipChanged = function(msg) |
| 84 | { |
| 85 | if (msg.from == -1) |
| 86 | { |
| 87 | //Deploy units once the structure is built |
| 88 | if (this.template.DirectDeployUnit && this.template.DirectDeployCount) |
| 89 | { |
| 90 | var directDeployCount = +this.template.DirectDeployCount; |
| 91 | var directDeployUnit = this.template.DirectDeployUnit._string; |
| 92 | |
| 93 | // Replace the "{civ}" codes with this entity's civ ID |
| 94 | var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); |
| 95 | if (cmpIdentity) |
| 96 | directDeployUnit = directDeployUnit.replace(/\{civ\}/g, cmpIdentity.GetCiv()) |
| 97 | |
| 98 | //Deploy the units |
| 99 | this.AddBatch(directDeployUnit, "directDeploy", directDeployCount, ""); |
| 100 | } |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | // Unset flag that previous owner's training may be blocked |
| 105 | var cmpPlayer = QueryPlayerIDInterface(msg.from, IID_Player); |
| 106 | if (cmpPlayer && this.queue.length > 0) |
| 107 | cmpPlayer.UnBlockTraining(); |
| 108 | |
| 109 | // Reset the production queue whenever the owner changes. |
| 110 | // (This should prevent players getting surprised when they capture |
| 111 | // an enemy building, and then loads of the enemy's civ's soldiers get |
| 112 | // created from it. Also it means we don't have to worry about |
| 113 | // updating the reserved pop slots.) |
| 114 | this.ResetQueue(); |
| 115 | } |
| 116 | }; |
| 117 | |
225 | | |
226 | | this.queue.push({ |
227 | | "id": this.nextID++, |
228 | | "player": cmpPlayer.GetPlayerID(), |
229 | | "unitTemplate": templateName, |
230 | | "count": count, |
231 | | "metadata": metadata, |
232 | | "resources": costs, |
233 | | "population": population, |
234 | | "productionStarted": false, |
235 | | "timeTotal": time*1000, |
236 | | "timeRemaining": time*1000, |
237 | | }); |
| 269 | |
| 270 | if (type == "unit") |
| 271 | { |
| 272 | // TrySubtractResources should report error to player (they ran out of resources) |
| 273 | if (!cmpPlayer.TrySubtractResources(totalCosts)) |
| 274 | return; |
| 275 | |
| 276 | this.queue.push({ |
| 277 | "id": this.nextID++, |
| 278 | "player": cmpPlayer.GetPlayerID(), |
| 279 | "unitTemplate": templateName, |
| 280 | "count": count, |
| 281 | "metadata": metadata, |
| 282 | "resources": costs, |
| 283 | "population": population, |
| 284 | "productionStarted": false, |
| 285 | "timeTotal": time*1000, |
| 286 | "timeRemaining": time*1000, |
| 287 | }); |
| 288 | } |
| 289 | else if (type == "directDeploy") |
| 290 | { |
| 291 | this.queue.push({ |
| 292 | "id": this.nextID++, |
| 293 | "player": cmpPlayer.GetPlayerID(), |
| 294 | "unitTemplate": templateName, |
| 295 | "count": count, |
| 296 | "metadata": metadata, |
| 297 | "resources": [], |
| 298 | "population": 0, |
| 299 | "productionStarted": false, |
| 300 | "timeTotal": 1000, |
| 301 | "timeRemaining": 1000, |
| 302 | }); |
| 303 | } |
414 | | ProductionQueue.prototype.OnOwnershipChanged = function(msg) |
415 | | { |
416 | | if (msg.from != -1) |
417 | | { |
418 | | // Unset flag that previous owner's training may be blocked |
419 | | var cmpPlayer = QueryPlayerIDInterface(msg.from, IID_Player); |
420 | | if (cmpPlayer && this.queue.length > 0) |
421 | | cmpPlayer.UnBlockTraining(); |
422 | | } |
423 | | |
424 | | // Reset the production queue whenever the owner changes. |
425 | | // (This should prevent players getting surprised when they capture |
426 | | // an enemy building, and then loads of the enemy's civ's soldiers get |
427 | | // created from it. Also it means we don't have to worry about |
428 | | // updating the reserved pop slots.) |
429 | | this.ResetQueue(); |
430 | | }; |
431 | | |