18 #include "precompiled.h"
46 return "<a:component type='system'/><empty/>";
79 serialize.
StringASCII(
"template", it->second, 0, 256);
93 for (
u32 i = 0; i < numEntities; ++i)
96 std::string templateName;
98 deserialize.
StringASCII(
"template", templateName, 0, 256);
191 m_LatestTemplates[ent] = templateName;
193 const CParamNode* templateRoot = GetTemplate(templateName);
207 LOGERROR(L
"Failed to load entity template '%hs'", templateName.c_str());
220 LOGERROR(L
"Failed to validate entity template '%hs'", templateName.c_str());
228 if (!templateRoot.
IsOk())
231 LOGERROR(L
"Invalid root element in entity template '%hs'", templateName.c_str());
235 return &templateRoot;
243 LOGERROR(L
"Failed to load entity template '%hs'", templateName.c_str());
248 if (!templateRoot.
IsOk())
251 return &templateRoot;
256 std::map<entity_id_t, std::string>::const_iterator it =
m_LatestTemplates.find(ent);
264 std::map<entity_id_t, std::string>::const_iterator it =
m_LatestTemplates.find(ent);
279 LOGERROR(L
"Probable infinite inheritance loop in entity template '%hs'", templateName.c_str());
284 if (templateName.find(
"actor|") == 0)
291 if (templateName.find(
"preview|") == 0)
294 std::string baseName = templateName.substr(8);
297 LOGERROR(L
"Failed to load entity template '%hs'", baseName.c_str());
306 if (templateName.find(
"corpse|") == 0)
309 std::string baseName = templateName.substr(7);
312 LOGERROR(L
"Failed to load entity template '%hs'", baseName.c_str());
321 if (templateName.find(
"foundation|") == 0)
324 std::string baseName = templateName.substr(11);
327 LOGERROR(L
"Failed to load entity template '%hs'", baseName.c_str());
336 if (templateName.find(
"construction|") == 0)
339 std::string baseName = templateName.substr(13);
342 LOGERROR(L
"Failed to load entity template '%hs'", baseName.c_str());
351 if (templateName.find(
"resource|") == 0)
354 std::string baseName = templateName.substr(9);
357 LOGERROR(L
"Failed to load entity template '%hs'", baseName.c_str());
375 if (!parentName.empty())
378 if (parentName.find(
'|') != parentName.npos)
380 LOGERROR(L
"Invalid parent '%hs' in entity template '%hs'", parentName.c_str(), templateName.c_str());
387 LOGERROR(L
"Failed to load parent '%hs' of entity template '%hs'", parentName.c_str(), templateName.c_str());
406 const char* templateName =
"special/actor";
409 LOGERROR(L
"Failed to load entity template '%hs'", templateName);
419 std::string
xml =
"<Entity>"
420 "<VisualActor><Actor>" + name +
"</Actor></VisualActor>"
422 "<Footprint><Circle radius='2.0'/><Height>1.0</Height></Footprint>"
425 "<Overlay><Texture><MainTexture>actor.png</MainTexture><MainTextureMask>actor_mask.png</MainTextureMask></Texture></Overlay>"
434 std::vector<std::string>& templates = *(std::vector<std::string>*)cbData;
442 if (name.substr(0, 9) == L
"template_")
445 templates.push_back(std::string(name.begin(), name.end()));
451 std::vector<std::string>& templates = *(std::vector<std::string>*)cbData;
456 templates.push_back(
"actor|" + std::string(name.begin(), name.end()));
466 std::vector<std::string> templates;
489 std::vector<entity_id_t> entities;
492 if(it->second == templateName)
493 entities.push_back(it->first);
503 std::set<std::string> permittedComponentTypes;
504 permittedComponentTypes.insert(
"Identity");
505 permittedComponentTypes.insert(
"Ownership");
506 permittedComponentTypes.insert(
"Position");
507 permittedComponentTypes.insert(
"VisualActor");
508 permittedComponentTypes.insert(
"Footprint");
509 permittedComponentTypes.insert(
"Obstruction");
510 permittedComponentTypes.insert(
"Decay");
511 permittedComponentTypes.insert(
"BuildRestrictions");
514 permittedComponentTypes.insert(
"Attack");
515 permittedComponentTypes.insert(
"UnitMotion");
516 permittedComponentTypes.insert(
"Sound");
535 CParamNode::LoadXMLString(out,
"<Entity><Vision><Range>0</Range><RetainInFog>false</RetainInFog><AlwaysVisible>true</AlwaysVisible></Vision></Entity>");
546 CParamNode::LoadXMLString(out,
"<Entity><VisualActor><SilhouetteDisplay>false</SilhouetteDisplay></VisualActor></Entity>");
555 std::set<std::string> permittedComponentTypes;
556 permittedComponentTypes.insert(
"Ownership");
557 permittedComponentTypes.insert(
"Position");
558 permittedComponentTypes.insert(
"VisualActor");
559 permittedComponentTypes.insert(
"Identity");
560 permittedComponentTypes.insert(
"BuildRestrictions");
561 permittedComponentTypes.insert(
"Obstruction");
562 permittedComponentTypes.insert(
"Selectable");
563 permittedComponentTypes.insert(
"Footprint");
564 permittedComponentTypes.insert(
"Armour");
565 permittedComponentTypes.insert(
"Health");
566 permittedComponentTypes.insert(
"StatusBars");
567 permittedComponentTypes.insert(
"OverlayRenderer");
568 permittedComponentTypes.insert(
"Decay");
569 permittedComponentTypes.insert(
"Cost");
570 permittedComponentTypes.insert(
"Sound");
571 permittedComponentTypes.insert(
"Vision");
572 permittedComponentTypes.insert(
"AIProxy");
573 permittedComponentTypes.insert(
"RallyPoint");
574 permittedComponentTypes.insert(
"RallyPointRenderer");
590 CParamNode::LoadXMLString(out,
"<Entity><Obstruction><DisableBlockMovement>true</DisableBlockMovement><DisableBlockPathfinding>true</DisableBlockPathfinding></Obstruction></Entity>");
606 std::set<std::string> permittedComponentTypes;
607 permittedComponentTypes.insert(
"Footprint");
608 permittedComponentTypes.insert(
"Ownership");
609 permittedComponentTypes.insert(
"Position");
610 permittedComponentTypes.insert(
"VisualActor");
621 std::set<std::string> permittedComponentTypes;
622 permittedComponentTypes.insert(
"Ownership");
623 permittedComponentTypes.insert(
"Position");
624 permittedComponentTypes.insert(
"VisualActor");
625 permittedComponentTypes.insert(
"Identity");
626 permittedComponentTypes.insert(
"Obstruction");
627 permittedComponentTypes.insert(
"Minimap");
628 permittedComponentTypes.insert(
"ResourceSupply");
629 permittedComponentTypes.insert(
"Selectable");
630 permittedComponentTypes.insert(
"Footprint");
631 permittedComponentTypes.insert(
"StatusBars");
632 permittedComponentTypes.insert(
"OverlayRenderer");
633 permittedComponentTypes.insert(
"Sound");
634 permittedComponentTypes.insert(
"AIProxy");
An entity initialisation parameter node.
virtual void StringASCII(const char *name, std::string &out, uint32_t minlength, uint32_t maxlength)
static void ClassInit(CComponentManager &componentManager)
#define REGISTER_COMPONENT_TYPE(cname)
RelaxNGValidator m_Validator
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
#define WARN_IF_ERR(expression)
Path VfsPath
VFS path of the form "(dir/)*file?".
static std::wstring EscapeXMLString(const std::wstring &str)
Escapes a string so that it is well-formed XML content/attribute text.
PSRETURN Load(const PIVFS &vfs, const VfsPath &filename)
Load from an XML file (with invisible XMB caching).
const PSRETURN PSRETURN_OK
#define ENTITY_IS_LOCAL(id)
virtual std::vector< std::string > FindAllTemplates(bool includeActors)
Returns a list of strings that could be validly passed as templateName to LoadTemplate.
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
static std::string GetSchema()
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
void CopyConstructionSubset(CParamNode &out, const CParamNode &in)
Serialization interface; see serialization overview.
void CopyFoundationSubset(CParamNode &out, const CParamNode &in)
static void out(const wchar_t *fmt,...)
virtual const CParamNode * LoadTemplate(entity_id_t ent, const std::string &templateName, int playerID)
Loads the template XML file identified by 'templateName' (including inheritance from parent XML files...
XMBAttributeList GetAttributes() const
void CopyPreviewSubset(CParamNode &out, const CParamNode &in, bool corpse)
virtual void NumberU32_Unbounded(const char *name, uint32_t &out)
static void LoadXML(CParamNode &ret, const XMBFile &file, const wchar_t *sourceIdentifier=NULL)
Loads the XML data specified by file into the node ret.
virtual int GetType() const =0
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
void StringASCII(const char *name, const std::string &value, uint32_t minlength, uint32_t maxlength)
Serialize an ASCII string.
std::map< std::string, bool > m_TemplateSchemaValidity
This is sent immediately before a destroyed entity is flushed and really destroyed.
static PSRETURN LoadXMLString(CParamNode &ret, const char *xml, const wchar_t *sourceIdentifier=NULL)
See LoadXML, but parses the XML string xml.
const String & string() const
virtual void DisableValidation()
Permanently disable XML validation (intended solely for test cases).
static Status AddToTemplates(const VfsPath &pathname, const CFileInfo &fileInfo, const uintptr_t cbData)
bool LoadTemplateFile(const std::string &templateName, int depth)
static const wchar_t TEMPLATE_ROOT[]
virtual std::vector< entity_id_t > GetEntitiesUsingTemplate(std::string templateName)
Get the list of entities using the specified template.
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
i64 Status
Error handling system.
const CSimContext & GetSimContext() const
CStr8 GetNamedItem(const int AttributeName) const
void SubscribeGloballyToMessageType(MessageTypeId mtid)
Subscribe the current component type to all messages of the given message type.
bool Validate(const std::wstring &filename, const std::wstring &document)
void NumberU32_Unbounded(const char *name, uint32_t value)
Serialize a number.
virtual void Init(const CParamNode ¶mNode)
std::wstring wstring_from_utf8(const std::string &src, Status *err)
convert UTF-8 to a wide string (UTF-16 or UCS-4, depending on the platform's wchar_t).
XMBElement GetRoot() const
Path ChangeExtension(Path extension) const
Template manager: Handles the loading of entity template files for the initialisation and deserializa...
Status ForEachFile(const PIVFS &fs, const VfsPath &startPath, FileCallback cb, uintptr_t cbData, const wchar_t *pattern, size_t flags)
call back for each file in a directory tree
void ConstructTemplateActor(const std::string &actorName, CParamNode &out)
void CopyResourceSubset(CParamNode &out, const CParamNode &in)
virtual void Serialize(ISerializer &serialize)
bool LoadGrammar(const std::string &grammar)
void CopyFilteredChildrenOfChild(const CParamNode &src, const char *name, const std::set< std::string > &permitted)
Finds the childs named name from src and from this, and copies the source child's children which are ...
int GetAttributeID(const char *Name) const
virtual std::string GetCurrentTemplateName(entity_id_t ent)
Returns the name of the template most recently specified for the entity 'ent'.
virtual const CParamNode * LoadLatestTemplate(entity_id_t ent)
Returns the template most recently specified for the entity 'ent'.
std::map< entity_id_t, std::string > m_LatestTemplates
static Status AddActorToTemplates(const VfsPath &pathname, const CFileInfo &fileInfo, const uintptr_t cbData)
u32 entity_id_t
Entity ID type.
virtual const CParamNode * GetTemplate(std::string templateName)
Loads the template XML file identified by 'templateName' (including inheritance from parent XML files...
virtual const CParamNode * GetTemplateWithoutValidation(std::string templateName)
Like GetTemplate, except without doing the XML validation (so it's faster but may return invalid temp...
std::map< std::string, CParamNode > m_TemplateFileData
virtual void HandleMessage(const CMessage &msg, bool global)
static const wchar_t ACTOR_ROOT[]
Deserialization interface; see serialization overview.