Allow entities to upgrade into other entities.
[0ad.git] / binaries / data / mods / public / simulation / components / Identity.js
blobac792f9af79a7ff096b8a937b1e3fe1b339f6794
1 function Identity() {}
3 Identity.prototype.Schema =
4         "<a:help>Specifies various names and values associated with the unit type, 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='Civilisation that this unit is primarily associated with, typically a 4-letter code. Choices include: gaia (world objects), athen (Athenians), brit (Britons), cart (Carthaginians), gaul (Gauls), iber (Iberians), mace (Macedonians), 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='Gender' a:help='Unit gender for voices. Choices includes male or female.'>" +
21                         "<text/>" +
22                 "</element>" +
23         "</optional>" +
24         "<element name='GenericName' a:help='Generic English-language name for this class of unit'>" +
25                 "<text/>" +
26         "</element>" +
27         "<optional>" +
28                 "<element name='SpecificName' a:help='Specific native-language name for this unit type'>" +
29                         "<text/>" +
30                 "</element>" +
31         "</optional>" +
32         "<optional>" +
33                 "<element name='SelectionGroupName' a:help='Name used to group ranked entities'>" +
34                         "<text/>" +
35                 "</element>" +
36         "</optional>" +
37         "<optional>" +
38                 "<element name='Tooltip'>" +
39                         "<text/>" +
40                 "</element>" +
41         "</optional>" +
42         "<optional>" +
43                 "<element name='Rollover'>" +
44                         "<text/>" +
45                 "</element>" +
46         "</optional>" +
47         "<optional>" +
48                 "<element name='History'>" +
49                         "<text/>" +
50                 "</element>" +
51         "</optional>" +
52         "<optional>" +
53                 "<element name='Rank'>" +
54                         "<choice>" +
55                                 "<value>Basic</value>" +
56                                 "<value>Advanced</value>" +
57                                 "<value>Elite</value>" +
58                         "</choice>" +
59                 "</element>" +
60         "</optional>" +
61         "<optional>" +
62                 "<element name='Classes' a:help='Optional list of space-separated classes applying to this entity. Choices include: Unit, Infantry, Melee, Cavalry, Ranged, Mechanical, Ship, Siege, Champion, Hero, Elephant, Chariot, Mercenary, Spear, Sword, Bow, Javelin, Sling, Support, Animal, Domestic, Organic, Structure, Civic, CivCentre, Economic, Defensive, Gates, Wall, BarterMarket, Village, Town, City, ConquestCritical, Worker, Female, Healer, Slave, CitizenSoldier, Trade, Market, NavalMarket, Warship, SeaCreature, ForestPlant, DropsiteFood, DropsiteWood, DropsiteStone, DropsiteMetal, GarrisonTower, GarrisonFortress'>" +
63                         "<attribute name='datatype'>" +
64                                 "<value>tokens</value>" +
65                         "</attribute>" +
66                         "<text/>" +
67                 "</element>" +
68         "</optional>" +
69         "<optional>" +
70                 "<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.'>" +
71                         "<attribute name='datatype'>" +
72                                 "<value>tokens</value>" +
73                         "</attribute>" +
74                         "<text/>" +
75                 "</element>" +
76         "</optional>" +
77         "<optional>" +
78                 "<element name='Formations' a:help='Optional list of space-separated formations this unit is allowed to use. Choices include: Scatter, Box, ColumnClosed, LineClosed, ColumnOpen, LineOpen, Flank, Skirmish, Wedge, Testudo, Phalanx, Syntagma, BattleLine'>" +
79                         "<attribute name='datatype'>" +
80                                 "<value>tokens</value>" +
81                         "</attribute>" +
82                         "<text/>" +
83                 "</element>" +
84         "</optional>" +
85         "<optional>" +
86                 "<element name='Icon'>" +
87                         "<text/>" +
88                 "</element>" +
89         "</optional>" +
90         "<optional>" +
91                 "<element name='RequiredTechnology' a:help='Optional name of a technology which must be researched before the entity can be produced'>" +
92                         "<text/>" +
93                 "</element>" +
94         "</optional>";
97 Identity.prototype.Init = function()
99         // caching
100         this.classesList = GetIdentityClasses(this.template);
101         this.visibleClassesList = GetVisibleIdentityClasses(this.template);
104 Identity.prototype.Deserialize = function ()
106         this.Init();
109 Identity.prototype.Serialize = null; // we have no dynamic state to save
111 Identity.prototype.GetCiv = function()
113         return this.template.Civ;
116 Identity.prototype.GetLang = function()
118         return this.template.Lang || "greek"; // ugly default
121 Identity.prototype.GetGender = function()
123         return this.template.Gender || "male"; // ugly default
126 Identity.prototype.GetRank = function()
128         return (this.template.Rank || "");
131 Identity.prototype.GetClassesList = function()
133         return this.classesList;
136 Identity.prototype.GetVisibleClassesList = function()
138         return this.visibleClassesList;
141 Identity.prototype.HasClass = function(name)
143         return this.GetClassesList().indexOf(name) != -1;
146 Identity.prototype.GetFormationsList = function()
148         if (this.template.Formations && "_string" in this.template.Formations)
149         {
150                 var string = this.template.Formations._string;
151                 return string.split(/\s+/);
152         }
153         return [];
156 Identity.prototype.CanUseFormation = function(template)
158         return this.GetFormationsList().indexOf(template) != -1;
161 Identity.prototype.GetSelectionGroupName = function()
163         return (this.template.SelectionGroupName || "");
166 Identity.prototype.GetGenericName = function()
168         return this.template.GenericName;
171 Engine.RegisterComponentType(IID_Identity, "Identity", Identity);