LCOV - code coverage report
Current view: top level - simulation/components - Cost.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 35 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 6 0.0 %

          Line data    Source code
       1             : function Cost() {}
       2             : 
       3           0 : Cost.prototype.Schema =
       4             :         "<a:help>Specifies the construction/training costs of this entity.</a:help>" +
       5             :         "<a:example>" +
       6             :                 "<Population>1</Population>" +
       7             :                 "<BuildTime>20.0</BuildTime>" +
       8             :                 "<Resources>" +
       9             :                         "<food>50</food>" +
      10             :                         "<wood>0</wood>" +
      11             :                         "<stone>0</stone>" +
      12             :                         "<metal>25</metal>" +
      13             :                 "</Resources>" +
      14             :         "</a:example>" +
      15             :         "<element name='Population' a:help='Population cost'>" +
      16             :                 "<data type='nonNegativeInteger'/>" +
      17             :         "</element>" +
      18             :         "<element name='BuildTime' a:help='Time taken to construct/train this entity (in seconds)'>" +
      19             :                 "<ref name='nonNegativeDecimal'/>" +
      20             :         "</element>" +
      21             :         "<element name='Resources' a:help='Resource costs to construct/train this entity'>" +
      22             :                 Resources.BuildSchema("nonNegativeInteger") +
      23             :         "</element>";
      24             : 
      25           0 : Cost.prototype.Init = function()
      26             : {
      27           0 :         this.populationCost = +this.template.Population;
      28             : };
      29             : 
      30           0 : Cost.prototype.GetPopCost = function()
      31             : {
      32           0 :         return this.populationCost;
      33             : };
      34             : 
      35             : 
      36           0 : Cost.prototype.GetBuildTime = function()
      37             : {
      38           0 :         return ApplyValueModificationsToEntity("Cost/BuildTime", +this.template.BuildTime, this.entity);
      39             : };
      40             : 
      41           0 : Cost.prototype.GetResourceCosts = function()
      42             : {
      43           0 :         let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
      44           0 :         if (!cmpOwnership)
      45             :         {
      46           0 :                 error("GetResourceCosts called without valid ownership on " + this.entity + ".");
      47           0 :                 return {};
      48             :         }
      49             : 
      50           0 :         let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
      51           0 :         let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.entity);
      52           0 :         let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName);
      53             : 
      54           0 :         let owner = cmpOwnership.GetOwner();
      55           0 :         let costs = {};
      56           0 :         for (let res in this.template.Resources)
      57           0 :                 costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate);
      58             : 
      59           0 :         return costs;
      60             : };
      61             : 
      62             : 
      63           0 : Cost.prototype.OnValueModification = function(msg)
      64             : {
      65           0 :         if (msg.component != "Cost")
      66           0 :                 return;
      67             : 
      68             :         // Foundations shouldn't have a pop cost.
      69           0 :         var cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation);
      70           0 :         if (cmpFoundation)
      71           0 :                 return;
      72             : 
      73             :         // update the population costs
      74           0 :         var newPopCost = Math.round(ApplyValueModificationsToEntity("Cost/Population", +this.template.Population, this.entity));
      75           0 :         var popCostDifference = newPopCost - this.populationCost;
      76           0 :         this.populationCost = newPopCost;
      77             : 
      78           0 :         var cmpPlayer = QueryOwnerInterface(this.entity);
      79           0 :         if (!cmpPlayer)
      80           0 :                 return;
      81           0 :         if (popCostDifference)
      82           0 :                 cmpPlayer.AddPopulation(popCostDifference);
      83             : };
      84             : 
      85           0 : Engine.RegisterComponentType(IID_Cost, "Cost", Cost);

Generated by: LCOV version 1.14