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" @@ -35,6 +36,7 @@ #include "simulation2/serialization/SerializeTemplates.h" +#include #include "graphics/Decal.h" #include "graphics/Frustum.h" #include "graphics/Model.h" @@ -202,7 +204,17 @@ if (m_IsFoundationActor) m_BaseActorName = m_ActorName = paramNode.GetChild("FoundationActor").ToString(); else - m_BaseActorName = m_ActorName = paramNode.GetChild("Actor").ToString(); + { + std::wstring baseActorString = paramNode.GetChild("Actor").ToString(); + + CmpPtr cmpIdentity(GetEntityHandle()); + const std::wstring pattern = L"{phenotype}"; + auto patternPos = baseActorString.find(pattern); + if (patternPos != std::wstring::npos) + boost::replace_all(baseActorString , "{phenotype}", cmpIdentity->GetPhenotype()); + + m_BaseActorName = m_ActorName = 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)