function Identity() {}
Identity.prototype.Schema =
"Specifies various names and values associated with the entity, typically for GUI display to users." +
"" +
"athen" +
"Athenian Hoplite" +
"Hoplī́tēs Athēnaïkós" +
"units/athen_infantry_spearman.png" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"tokens" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"Basic" +
"Advanced" +
"Elite" +
"" +
"" +
"" +
"" +
"" +
"" +
"tokens" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"tokens" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
RequirementsHelper.BuildSchema() +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
Identity.prototype.Init = function()
{
this.classesList = GetIdentityClasses(this.template);
this.visibleClassesList = GetVisibleIdentityClasses(this.template);
if (this.template.Phenotype)
{
const phenotypes = this.GetPossiblePhenotypes();
// TODO: this is a workaround to avoid calling Math.random,
// which causes out of sync RNG caused by preview entities.
// However, it's not random enough. Perhaps use the actor seed.
this.phenotype = phenotypes[this.entity % phenotypes.length];
}
else
this.phenotype = "default";
this.controllable = this.template.Controllable ? this.template.Controllable == "true" : true;
};
Identity.prototype.Deserialize = function(data)
{
this.Init();
this.phenotype = data.phenotype;
this.controllable = data.controllable;
if (data.name)
this.name = data.name;
};
Identity.prototype.Serialize = function()
{
const result = {
"phenotype": this.phenotype,
"controllable": this.controllable,
};
if (this.name)
result.name = this.name;
return result;
};
Identity.prototype.GetCiv = function()
{
return this.template.Civ;
};
Identity.prototype.GetLang = function()
{
return this.template.Lang || "greek"; // ugly default
};
/**
* Get a list of possible Phenotypes.
* @return {string[]} A list of possible phenotypes.
*/
Identity.prototype.GetPossiblePhenotypes = function()
{
return this.template.Phenotype._string.split(/\s+/);
};
/**
* Get the current Phenotype.
* @return {string} The current phenotype.
*/
Identity.prototype.GetPhenotype = function()
{
return this.phenotype;
};
Identity.prototype.GetRank = function()
{
return this.template.Rank || "";
};
Identity.prototype.GetRankTechName = function()
{
return this.template.Rank ? "unit_" + this.template.Rank.toLowerCase() : "";
};
Identity.prototype.GetClassesList = function()
{
return this.classesList;
};
Identity.prototype.GetVisibleClassesList = function()
{
return this.visibleClassesList;
};
Identity.prototype.HasClass = function(name)
{
return this.GetClassesList().indexOf(name) != -1;
};
Identity.prototype.GetSelectionGroupName = function()
{
return this.template.SelectionGroupName || "";
};
Identity.prototype.GetGenericName = function()
{
return this.template.GenericName;
};
Identity.prototype.IsUndeletable = function()
{
return this.template.Undeletable == "true";
};
Identity.prototype.IsControllable = function()
{
return this.controllable;
};
Identity.prototype.SetControllable = function(controllability)
{
this.controllable = controllability;
};
/**
* Change the phenotype of the entity.
* @param {string} phenotype
* @returns {boolean} Whether the phenotype was changed.
* If yes, check if VisualActor::RecomputeActorName needs to be called.
*/
Identity.prototype.SetPhenotype = function(phenotype)
{
if (this.phenotype == phenotype)
return false;
if (this.GetPossiblePhenotypes().indexOf(phenotype) === -1)
return false;
this.phenotype = phenotype;
return true;
};
/**
* @param {string} newName -
*/
Identity.prototype.SetName = function(newName)
{
this.name = newName;
};
/**
* @return {string} -
*/
Identity.prototype.GetName = function()
{
return this.name || this.template.GenericName;
};
function IdentityMirage() {}
IdentityMirage.prototype.Init = function(cmpIdentity)
{
// Mirages don't get identity classes via the template-filter, so that code can query
// identity components via Engine.QueryInterface without having to explicitly check for mirages.
// This is cloned as otherwise we get a reference to Identity's property,
// and that array is deleted when serializing (as it's not seralized), which ends in OOS.
this.classes = clone(cmpIdentity.GetClassesList());
};
IdentityMirage.prototype.GetClassesList = function() { return this.classes; };
Engine.RegisterGlobal("IdentityMirage", IdentityMirage);
Identity.prototype.Mirage = function()
{
const mirage = new IdentityMirage();
mirage.Init(this);
return mirage;
};
Engine.RegisterComponentType(IID_Identity, "Identity", Identity);