Index: binaries/data/mods/public/simulation/components/Identity.js
===================================================================
--- binaries/data/mods/public/simulation/components/Identity.js
+++ binaries/data/mods/public/simulation/components/Identity.js
@@ -17,7 +17,15 @@
"" +
"" +
"" +
- "" +
+ "" +
+ "" +
+ "tokens" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"" +
"" +
"" +
@@ -95,14 +103,21 @@
{
this.classesList = GetIdentityClasses(this.template);
this.visibleClassesList = GetVisibleIdentityClasses(this.template);
+ this.SetGender();
};
-Identity.prototype.Deserialize = function ()
+Identity.prototype.Deserialize = function(data)
{
this.Init();
+ this.gender = data.gender;
};
-Identity.prototype.Serialize = null; // we have no dynamic state to save
+Identity.prototype.Serialize = function()
+{
+ return {
+ "gender": this.gender
+ };
+};
Identity.prototype.GetCiv = function()
{
@@ -114,9 +129,30 @@
return this.template.Lang || "greek"; // ugly default
};
+Identity.prototype.GetPossibleGenders = function()
+{
+ return !!this.template.PossibleGenders ? this.template.PossibleGenders._string.split(/\s+/) : ["none"];
+};
+
+Identity.prototype.SetGender = function(newGender = "none")
+{
+ if (newGender == this.gender)
+ return;
+
+ if (!this.template.Gender)
+ this.gender = "male"; // ugly default
+ else
+ this.gender = this.template.Gender == "random" ? pickRandom(this.GetPossibleGenders()) : this.template.Gender;
+};
+
Identity.prototype.GetGender = function()
{
- return this.template.Gender || "male"; // ugly default
+ return this.gender;
+};
+
+Identity.prototype.GetPhenotype = function()
+{
+ return this.gender;
};
Identity.prototype.GetRank = function()
Index: source/simulation2/components/CCmpVisualActor.cpp
===================================================================
--- source/simulation2/components/CCmpVisualActor.cpp
+++ source/simulation2/components/CCmpVisualActor.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -23,6 +23,7 @@
#include "simulation2/MessageTypes.h"
#include "ICmpFootprint.h"
+#include "ICmpIdentity.h"
#include "ICmpUnitRenderer.h"
#include "ICmpOwnership.h"
#include "ICmpPosition.h"
@@ -191,6 +192,7 @@
virtual void Init(const CParamNode& paramNode)
{
+ std::wstring m_BaseActorString;
m_Unit = NULL;
m_R = m_G = m_B = fixed::FromInt(1);
@@ -202,7 +204,15 @@
if (m_IsFoundationActor)
m_BaseActorName = m_ActorName = paramNode.GetChild("FoundationActor").ToString();
else
- m_BaseActorName = m_ActorName = paramNode.GetChild("Actor").ToString();
+ {
+ m_BaseActorString = paramNode.GetChild("Actor").ToString();
+
+ CmpPtr cmpIdentity(GetEntityHandle());
+ if (m_BaseActorString.find(L"{phenotype}") != std::wstring::npos)
+ m_BaseActorString.replace(m_BaseActorString.find(L"{phenotype}"), 11, cmpIdentity->GetPhenotype());
+
+ m_BaseActorName = m_ActorName = m_BaseActorString;
+ }
m_VisibleInAtlasOnly = paramNode.GetChild("VisibleInAtlasOnly").ToBool();
m_IsActorOnly = paramNode.GetChild("ActorOnly").IsOk();
Index: source/simulation2/components/ICmpIdentity.h
===================================================================
--- source/simulation2/components/ICmpIdentity.h
+++ source/simulation2/components/ICmpIdentity.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -29,6 +29,8 @@
public:
virtual std::string GetSelectionGroupName() = 0;
+ virtual std::wstring GetPhenotype() = 0;
+
DECLARE_INTERFACE_TYPE(Identity)
};
Index: source/simulation2/components/ICmpIdentity.cpp
===================================================================
--- source/simulation2/components/ICmpIdentity.cpp
+++ source/simulation2/components/ICmpIdentity.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -35,6 +35,11 @@
{
return m_Script.Call("GetSelectionGroupName");
}
+
+ virtual std::wstring GetPhenotype()
+ {
+ return m_Script.Call("GetPhenotype");
+ }
};
REGISTER_COMPONENT_SCRIPT_WRAPPER(IdentityScripted)