Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ICmpTemplateManager.h
Go to the documentation of this file.
1/* Copyright (C) 2025 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_ICMPTEMPLATEMANAGER
19#define INCLUDED_ICMPTEMPLATEMANAGER
20
24
25#include <js/Value.h>
26#include <string>
27#include <vector>
28
29/**
30 * Template manager: Handles the loading of entity template files for the initialisation
31 * and deserialization of entity components.
32 *
33 * Template names are intentionally restricted to ASCII strings for storage/serialization
34 * efficiency (we have a lot of strings so this is significant);
35 * they correspond to filenames so they shouldn't contain non-ASCII anyway.
36 */
38{
39public:
40 /**
41 * Loads the template XML file identified by 'templateName' (including inheritance
42 * from parent XML files) for use with a new entity 'ent'.
43 * The returned CParamNode must not be used for any entities other than 'ent'.
44 *
45 * If templateName is of the form "actor|foo" then it will load a default
46 * stationary entity template that uses actor "foo". (This is a convenience to
47 * avoid the need for hundreds of tiny decorative-object entity templates.)
48 *
49 * If templateName is of the form "preview|foo" then it will load a template
50 * based on entity template "foo" with the non-graphical components removed.
51 * (This is for previewing construction/placement of units.)
52 *
53 * If templateName is of the form "corpse|foo" then it will load a template
54 * like "preview|foo" but with corpse-related components included.
55 *
56 * If templateName is of the form "foundation|foo" then it will load a template
57 * based on entity template "foo" with various components removed and a few changed
58 * and added. (This is for constructing foundations of buildings.)
59 *
60 * @return NULL on error
61 */
62 virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName) = 0;
63
64 /**
65 * Loads the template XML file identified by 'templateName' (including inheritance
66 * from parent XML files). The templateName syntax is the same as LoadTemplate.
67 *
68 * @return NULL on error
69 */
70 virtual const CParamNode* GetTemplate(const std::string& templateName) = 0;
71
72 /**
73 * Like GetTemplate, except without doing the XML validation (so it's faster but
74 * may return invalid templates).
75 *
76 * @return NULL on error
77 */
78 virtual const CParamNode* GetTemplateWithoutValidation(const std::string& templateName) = 0;
79
80 /**
81 * Check if the template XML file exists, without trying to load it.
82 */
83 virtual bool TemplateExists(const std::string& templateName) const = 0;
84
85 /**
86 * Returns the template most recently specified for the entity 'ent'.
87 * Used during deserialization.
88 *
89 * @return NULL on error
90 */
91 virtual const CParamNode* LoadLatestTemplate(entity_id_t ent) = 0;
92
93 /**
94 * Returns the name of the template most recently specified for the entity 'ent'.
95 */
96 virtual std::string GetCurrentTemplateName(entity_id_t ent) const = 0;
97
98 /**
99 * Returns the list of entities having the specified template.
100 */
101 virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(const std::string& templateName) const = 0;
102
103 /**
104 * Returns a list of strings that could be validly passed as @c templateName to LoadTemplate.
105 * (This includes "actor|foo" etc names).
106 * Intended for use by the map editor. This is likely to be quite slow.
107 */
108 virtual std::vector<std::string> FindAllTemplates(bool includeActors) const = 0;
109
110 /**
111 * Returns some data of the civs from the templates.
112 * Intended for use by the map editor.
113 */
114 virtual std::vector<std::vector<std::wstring>> GetCivData() = 0;
115
116 /**
117 * Returns a list of strings that could be validly passed as @c templateName to LoadTemplate.
118 * Intended for use by the AI manager.
119 */
120 virtual std::vector<std::string> FindUsedTemplates() const = 0;
121
122 /**
123 * Permanently disable XML validation (intended solely for test cases).
124 */
125 virtual void DisableValidation() = 0;
126
127 /*
128 * TODO:
129 * When an entity changes template (e.g. upgrades) or player ownership, it
130 * should call some Reload(ent, templateName, playerID) function to load its new template.
131 * When a file changes on disk, something should call Reload(templateName).
132 *
133 * Reloading should happen by sending a message to affected components (containing
134 * their new CParamNode), then automatically updating this.template of scripted components.
135 */
136
137 DECLARE_INTERFACE_TYPE(TemplateManager)
138};
139
140#endif // INCLUDED_ICMPTEMPLATEMANAGER
An entity initialisation parameter node.
Definition: ParamNode.h:153
Template manager: Handles the loading of entity template files for the initialisation and deserializa...
Definition: ICmpTemplateManager.h:38
virtual const CParamNode * GetTemplate(const std::string &templateName)=0
Loads the template XML file identified by 'templateName' (including inheritance from parent XML files...
virtual void DisableValidation()=0
Permanently disable XML validation (intended solely for test cases).
virtual std::vector< std::vector< std::wstring > > GetCivData()=0
Returns some data of the civs from the templates.
virtual const CParamNode * LoadLatestTemplate(entity_id_t ent)=0
Returns the template most recently specified for the entity 'ent'.
virtual std::string GetCurrentTemplateName(entity_id_t ent) const =0
Returns the name of the template most recently specified for the entity 'ent'.
virtual std::vector< entity_id_t > GetEntitiesUsingTemplate(const std::string &templateName) const =0
Returns the list of entities having the specified template.
virtual bool TemplateExists(const std::string &templateName) const =0
Check if the template XML file exists, without trying to load it.
virtual const CParamNode * LoadTemplate(entity_id_t ent, const std::string &templateName)=0
Loads the template XML file identified by 'templateName' (including inheritance from parent XML files...
virtual const CParamNode * GetTemplateWithoutValidation(const std::string &templateName)=0
Like GetTemplate, except without doing the XML validation (so it's faster but may return invalid temp...
virtual std::vector< std::string > FindAllTemplates(bool includeActors) const =0
Returns a list of strings that could be validly passed as templateName to LoadTemplate.
virtual std::vector< std::string > FindUsedTemplates() const =0
Returns a list of strings that could be validly passed as templateName to LoadTemplate.
Definition: IComponent.h:33
std::uint32_t entity_id_t
Entity ID type.
Definition: Entity.h:29
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23