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,8 +17,12 @@ "" + "" + "" + - "" + - "" + + "" + + "" + + "male" + + "female" + + "random" + + "" + "" + "" + "" + @@ -95,14 +99,21 @@ { this.classesList = GetIdentityClasses(this.template); this.visibleClassesList = GetVisibleIdentityClasses(this.template); + this.gender = !!this.template.Gender == "random" ? randBool() ? "male" : "female" : this.template.Gender || "male"; // ugly default }; -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() { @@ -116,7 +127,7 @@ Identity.prototype.GetGender = function() { - return this.template.Gender || "male"; // ugly default + 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" @@ -66,7 +67,7 @@ DEFAULT_COMPONENT_ALLOCATOR(VisualActor) private: - std::wstring m_BaseActorName, m_ActorName; + std::wstring m_BaseActorName, m_ActorName, m_BaseActorString; bool m_IsFoundationActor; // Not initialized in non-visual mode @@ -202,7 +203,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"{gender}") != std::wstring::npos) + m_BaseActorString.replace(m_BaseActorString.find(L"{gender}"), 8, cmpIdentity->GetGender()); + + 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 GetGender() = 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 GetGender() + { + return m_Script.Call("GetGender"); + } }; REGISTER_COMPONENT_SCRIPT_WRAPPER(IdentityScripted)