Index: source/simulation2/TypeList.h =================================================================== --- source/simulation2/TypeList.h +++ source/simulation2/TypeList.h @@ -102,6 +102,7 @@ COMPONENT(GuiInterfaceScripted) INTERFACE(Identity) +COMPONENT(Identity) COMPONENT(IdentityScripted) INTERFACE(Minimap) Index: source/simulation2/components/CCmpIdentity.cpp =================================================================== --- /dev/null +++ source/simulation2/components/CCmpIdentity.cpp @@ -0,0 +1,87 @@ +/* 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 + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "simulation2/system/Component.h" +#include "ICmpIdentity.h" + +#include "simulation2/MessageTypes.h" + +/** + * Basic ICmpIdentity implementation. + */ +class CCmpIdentity : public ICmpIdentity +{ +public: + static void ClassInit(CComponentManager& UNUSED(componentManager)) + { + // Any messages we want to be subscribed to? + } + + DEFAULT_COMPONENT_ALLOCATOR(Identity) + + std::wstring m_Gender; + + static std::string GetSchema() + { + return + "" + "Specifies various names and values associated with the unit type, typically for GUI display to users." + ""; + } + + virtual void Init(const CParamNode& paramNode) + { + m_Gender = paramNode.GetChild("Gender").ToString(); + } + + virtual void Deinit() + { + } + + virtual void Serialize(ISerializer& serialize) + { + //?? + } + + virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize) + { + //?? + } + +/* virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) + { + switch (msg.GetType()) + { + case MT_Destroy: + { + // Reset the owner so this entity is e.g. removed from population counts + SetOwner(INVALID_PLAYER); + break; + } + } + } +*/ + virtual std::wstring GetGender() const + { + return m_Gender; + } + +}; + +REGISTER_COMPONENT_TYPE(Identity) Index: source/simulation2/components/CCmpVisualActor.cpp =================================================================== --- source/simulation2/components/CCmpVisualActor.cpp +++ source/simulation2/components/CCmpVisualActor.cpp @@ -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 @@ -29,6 +29,8 @@ public: virtual std::string GetSelectionGroupName() = 0; + virtual std::string GetGender() = 0; + DECLARE_INTERFACE_TYPE(Identity) }; Index: source/simulation2/components/ICmpIdentity.cpp =================================================================== --- source/simulation2/components/ICmpIdentity.cpp +++ source/simulation2/components/ICmpIdentity.cpp @@ -35,6 +35,11 @@ { return m_Script.Call("GetSelectionGroupName"); } + + virtual std::string GetGender() + { + return m_Script.Call("GetGender"); + } }; REGISTER_COMPONENT_SCRIPT_WRAPPER(IdentityScripted)