LCOV - code coverage report
Current view: top level - simulation/components - Identity.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 40 51 78.4 %
Date: 2023-04-02 12:52:40 Functions: 12 23 52.2 %

          Line data    Source code
       1             : function Identity() {}
       2             : 
       3           1 : Identity.prototype.Schema =
       4             :         "<a:help>Specifies various names and values associated with the entity, typically for GUI display to users.</a:help>" +
       5             :         "<a:example>" +
       6             :                 "<Civ>athen</Civ>" +
       7             :                 "<GenericName>Athenian Hoplite</GenericName>" +
       8             :                 "<SpecificName>Hoplī́tēs Athēnaïkós</SpecificName>" +
       9             :                 "<Icon>units/athen_infantry_spearman.png</Icon>" +
      10             :         "</a:example>" +
      11             :         "<element name='Civ' a:help='Civilization that this unit is primarily associated with, typically a 4-letter code. Choices include: gaia (world objects), skirm (skirmish map placeholders), athen (Athenians), brit (Britons), cart (Carthaginians), gaul (Gauls), iber (Iberians), kush (Kushites), mace (Macedonians), maur (Mauryas), pers (Persians), ptol (Ptolemies), rome (Romans), sele (Seleucids), spart (Spartans).'>" +
      12             :                 "<text/>" +
      13             :         "</element>" +
      14             :         "<optional>" +
      15             :                 "<element name='Lang' a:help='Unit language for voices.'>" +
      16             :                         "<text/>" +
      17             :                 "</element>" +
      18             :         "</optional>" +
      19             :         "<optional>" +
      20             :                 "<element name='Phenotype' a:help='Unit phenotype for voices and visual. If more than one is specified a random one will be chosen.'>" +
      21             :                         "<attribute name='datatype'>" +
      22             :                                 "<value>tokens</value>" +
      23             :                         "</attribute>" +
      24             :                         "<text/>" +
      25             :                 "</element>" +
      26             :         "</optional>" +
      27             :         "<element name='GenericName' a:help='Generic English-language name for this entity.'>" +
      28             :                 "<text/>" +
      29             :         "</element>" +
      30             :         "<optional>" +
      31             :                 "<element name='SpecificName' a:help='Specific native-language name for this entity.'>" +
      32             :                         "<text/>" +
      33             :                 "</element>" +
      34             :         "</optional>" +
      35             :         "<optional>" +
      36             :                 "<element name='SelectionGroupName' a:help='Name used to group ranked entities.'>" +
      37             :                         "<text/>" +
      38             :                 "</element>" +
      39             :         "</optional>" +
      40             :         "<optional>" +
      41             :                 "<element name='Tooltip'>" +
      42             :                         "<text/>" +
      43             :                 "</element>" +
      44             :         "</optional>" +
      45             :         "<optional>" +
      46             :                 "<element name='History'>" +
      47             :                         "<text/>" +
      48             :                 "</element>" +
      49             :         "</optional>" +
      50             :         "<optional>" +
      51             :                 "<element name='Rank'>" +
      52             :                         "<choice>" +
      53             :                                 "<value>Basic</value>" +
      54             :                                 "<value>Advanced</value>" +
      55             :                                 "<value>Elite</value>" +
      56             :                         "</choice>" +
      57             :                 "</element>" +
      58             :         "</optional>" +
      59             :         "<optional>" +
      60             :                 "<element name='Classes' a:help='Optional list of space-separated classes applying to this entity. Choices include: AfricanElephant, AmunGuard, Animal, ApedemakGuard, Ashoka, Barter, CitizenSoldier, CivCentre, CivSpecific, ConquestCritical, Domestic, DropsiteFood, DropsiteMetal, DropsiteStone, DropsiteWood, FastMoving, FemaleCitizen, Foundation, GarrisonFortress, Human, IndianElephant, Juggernaut, KushTrireme, MercenaryCamp, Organic, Player, PtolemyIV, SeaCreature, Spy, Structure, Unit, WallLong, WallMedium, WallShort, WallTower.'>" +
      61             :                         "<attribute name='datatype'>" +
      62             :                                 "<value>tokens</value>" +
      63             :                         "</attribute>" +
      64             :                         "<text/>" +
      65             :                 "</element>" +
      66             :         "</optional>" +
      67             :         "<optional>" +
      68             :                 "<element name='VisibleClasses' a:help='Optional list of space-separated classes applying to this entity. These classes will also be visible in various GUI elements. If the classes need spaces, underscores will be replaced with spaces. Choices include: Amphitheater, Archer, ArmyCamp, Arsenal, ArtilleryTower, Axeman, Barracks, Bireme, BoltShooter, BoltTower, Bribable, Builder, Camel, Cavalry, Champion, Chariot, Citizen, City, Civic, CivilCentre, Colony, Corral, Council, Crossbowman, Defensive, Dock, Dog, Economic, Elephant, ElephantStable, Embassy, Farmstead, Field, Fireship, FishingBoat, Forge, Fortress, Gate, Gladiator, Gymnasium, Hall, Healer, Hero, House, Immortal, Infantry, Javelineer, Library, Lighthouse, Maceman, Melee, Market, Mercenary, Military, Monument, Naval, Outpost, Palace, Palisade, Pikeman, Pillar, Pyramid, Quinquereme, Ram, Range, Ranged, Relic, Resource, RotaryMill, SentryTower, Ship, Shipyard, Siege, SiegeTower, SiegeWall, Slave, Slinger, Soldier, Spearman, Stable, Stoa, StoneThrower, StoneTower, Storehouse, Support, Swordsman, Syssiton, Temple, TempleOfAmun, TempleOfApedemak, TempleOfMars, TempleOfVesta, Theater, Tower, Town, Trade, Trader, Trireme, TriumphalArch, Village, Wall, Warship, Wonder, Worker.'>" +
      69             :                         "<attribute name='datatype'>" +
      70             :                                 "<value>tokens</value>" +
      71             :                         "</attribute>" +
      72             :                         "<text/>" +
      73             :                 "</element>" +
      74             :         "</optional>" +
      75             :         "<element name='Icon'>" +
      76             :                 "<text/>" +
      77             :         "</element>" +
      78             :         "<optional>" +
      79             :                 RequirementsHelper.BuildSchema() +
      80             :         "</optional>" +
      81             :         "<optional>" +
      82             :                 "<element name='Controllable' a:help='Whether players can control this entity. Defaults to true.'>" +
      83             :                         "<data type='boolean'/>" +
      84             :                 "</element>" +
      85             :         "</optional>" +
      86             :         "<element name='Undeletable' a:help='Prevent players from deleting this entity.'>" +
      87             :                 "<data type='boolean'/>" +
      88             :         "</element>";
      89             : 
      90           1 : Identity.prototype.Init = function()
      91             : {
      92           4 :         this.classesList = GetIdentityClasses(this.template);
      93           4 :         this.visibleClassesList = GetVisibleIdentityClasses(this.template);
      94           4 :         if (this.template.Phenotype)
      95           3 :                 this.phenotype = pickRandom(this.GetPossiblePhenotypes());
      96             :         else
      97           1 :                 this.phenotype = "default";
      98             : 
      99           4 :         this.controllable = this.template.Controllable ? this.template.Controllable == "true" : true;
     100             : };
     101             : 
     102           1 : Identity.prototype.GetCiv = function()
     103             : {
     104           2 :         return this.template.Civ;
     105             : };
     106             : 
     107           1 : Identity.prototype.GetLang = function()
     108             : {
     109           2 :         return this.template.Lang || "greek"; // ugly default
     110             : };
     111             : 
     112             : /**
     113             :  * Get a list of possible Phenotypes.
     114             :  * @return {string[]} A list of possible phenotypes.
     115             :  */
     116           1 : Identity.prototype.GetPossiblePhenotypes = function()
     117             : {
     118           4 :         return this.template.Phenotype._string.split(/\s+/);
     119             : };
     120             : 
     121             : /**
     122             :  * Get the current Phenotype.
     123             :  * @return {string} The current phenotype.
     124             :  */
     125           1 : Identity.prototype.GetPhenotype = function()
     126             : {
     127           4 :         return this.phenotype;
     128             : };
     129             : 
     130           1 : Identity.prototype.GetRank = function()
     131             : {
     132           2 :         return this.template.Rank || "";
     133             : };
     134             : 
     135           1 : Identity.prototype.GetRankTechName = function()
     136             : {
     137           0 :         return this.template.Rank ? "unit_" + this.template.Rank.toLowerCase() : "";
     138             : };
     139             : 
     140           1 : Identity.prototype.GetClassesList = function()
     141             : {
     142           5 :         return this.classesList;
     143             : };
     144             : 
     145           1 : Identity.prototype.GetVisibleClassesList = function()
     146             : {
     147           2 :         return this.visibleClassesList;
     148             : };
     149             : 
     150           1 : Identity.prototype.HasClass = function(name)
     151             : {
     152           3 :         return this.GetClassesList().indexOf(name) != -1;
     153             : };
     154             : 
     155           1 : Identity.prototype.GetSelectionGroupName = function()
     156             : {
     157           2 :         return this.template.SelectionGroupName || "";
     158             : };
     159             : 
     160           1 : Identity.prototype.GetGenericName = function()
     161             : {
     162           2 :         return this.template.GenericName;
     163             : };
     164             : 
     165           1 : Identity.prototype.IsUndeletable = function()
     166             : {
     167           0 :         return this.template.Undeletable == "true";
     168             : };
     169             : 
     170           1 : Identity.prototype.IsControllable = function()
     171             : {
     172           0 :         return this.controllable;
     173             : };
     174             : 
     175           1 : Identity.prototype.SetControllable = function(controllability)
     176             : {
     177           0 :         this.controllable = controllability;
     178             : };
     179             : 
     180           1 : Identity.prototype.SetPhenotype = function(phenotype)
     181             : {
     182           0 :         this.phenotype = phenotype;
     183             : };
     184             : 
     185             : /**
     186             :  * @param {string} newName -
     187             :  */
     188           1 : Identity.prototype.SetName = function(newName)
     189             : {
     190           0 :         this.name = newName;
     191             : };
     192             : 
     193             : /**
     194             :  * @return {string} -
     195             :  */
     196           1 : Identity.prototype.GetName = function()
     197             : {
     198           0 :         return this.name || this.template.GenericName;
     199             : };
     200             : 
     201             : function IdentityMirage() {}
     202           1 : IdentityMirage.prototype.Init = function(cmpIdentity)
     203             : {
     204             :         // Mirages don't get identity classes via the template-filter, so that code can query
     205             :         // identity components via Engine.QueryInterface without having to explicitly check for mirages.
     206             :         // This is cloned as otherwise we get a reference to Identity's property,
     207             :         // and that array is deleted when serializing (as it's not seralized), which ends in OOS.
     208           0 :         this.classes = clone(cmpIdentity.GetClassesList());
     209             : };
     210           1 : IdentityMirage.prototype.GetClassesList = function() { return this.classes; };
     211             : 
     212           1 : Engine.RegisterGlobal("IdentityMirage", IdentityMirage);
     213             : 
     214           1 : Identity.prototype.Mirage = function()
     215             : {
     216           0 :         let mirage = new IdentityMirage();
     217           0 :         mirage.Init(this);
     218           0 :         return mirage;
     219             : };
     220             : 
     221           1 : Engine.RegisterComponentType(IID_Identity, "Identity", Identity);

Generated by: LCOV version 1.14