Ticket #2128: DirectDeploy.diff

File DirectDeploy.diff, 5.1 KB (added by Palantius, 11 years ago)
  • home/albert/VirtualBox

     
    2929            "</attribute>" +
    3030            "<text/>" +
    3131        "</element>" +
    32     "</optional>";
     32    "</optional>" +
     33    "<optional>" +
     34        "<element name='DirectDeployUnit'>" +
     35            "<attribute name='datatype'>" +
     36                "<value>tokens</value>" +
     37            "</attribute>" +
     38            "<text/>" +
     39        "</element>" +
     40    "</optional>" +
     41    "<optional>" +
     42        "<element name='DirectDeployCount'>" +
     43            "<data type='nonNegativeInteger'/>" +
     44        "</element>" +
     45    "</optional>";;
    3346
    3447ProductionQueue.prototype.Init = function()
    3548{
     
    6780    this.spawnNotified = false;
    6881};
    6982
     83ProductionQueue.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
    70118/*
    71119 * Returns list of entities that can be trained by this building.
    72120 */
     
    185233    if (this.queue.length < MAX_QUEUE_SIZE)
    186234    {
    187235       
    188         if (type == "unit")
     236        if (type == "unit" || type == "directDeploy")
    189237        {
    190238            // Find the template data so we can determine the build costs
    191239            var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     
    211259
    212260            var population = +template.Cost.Population;
    213261
    214             // TrySubtractResources should report error to player (they ran out of resources)
    215             if (!cmpPlayer.TrySubtractResources(totalCosts))
    216                 return;
    217 
    218262            // Update entity count in the EntityLimits component
    219263            if (template.TrainingRestrictions)
    220264            {
     
    222266                var cmpPlayerEntityLimits = QueryOwnerInterface(this.entity, IID_EntityLimits);
    223267                cmpPlayerEntityLimits.IncreaseCount(unitCategory, count);
    224268            }
    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            }
    238304        }
    239305        else if (type == "technology")
    240306        {
     
    411477    return Math.pow(batchSize, batchTimeModifier) * cmpPlayer.GetCheatTimeMultiplier();
    412478};
    413479
    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 
    432480ProductionQueue.prototype.OnDestroy = function()
    433481{
    434482    // Reset the queue to refund any resources