Pyrogenesis  trunk
ICmpTemplateManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 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 
22 
23 #include <vector>
24 
25 /**
26  * Template manager: Handles the loading of entity template files for the initialisation
27  * and deserialization of entity components.
28  *
29  * Template names are intentionally restricted to ASCII strings for storage/serialization
30  * efficiency (we have a lot of strings so this is significant);
31  * they correspond to filenames so they shouldn't contain non-ASCII anyway.
32  */
34 {
35 public:
36  /**
37  * Loads the template XML file identified by 'templateName' (including inheritance
38  * from parent XML files) for use with a new entity 'ent'.
39  * The returned CParamNode must not be used for any entities other than 'ent'.
40  *
41  * If templateName is of the form "actor|foo" then it will load a default
42  * stationary entity template that uses actor "foo". (This is a convenience to
43  * avoid the need for hundreds of tiny decorative-object entity templates.)
44  *
45  * If templateName is of the form "preview|foo" then it will load a template
46  * based on entity template "foo" with the non-graphical components removed.
47  * (This is for previewing construction/placement of units.)
48  *
49  * If templateName is of the form "corpse|foo" then it will load a template
50  * like "preview|foo" but with corpse-related components included.
51  *
52  * If templateName is of the form "foundation|foo" then it will load a template
53  * based on entity template "foo" with various components removed and a few changed
54  * and added. (This is for constructing foundations of buildings.)
55  *
56  * @return NULL on error
57  */
58  virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName) = 0;
59 
60  /**
61  * Loads the template XML file identified by 'templateName' (including inheritance
62  * from parent XML files). The templateName syntax is the same as LoadTemplate.
63  *
64  * @return NULL on error
65  */
66  virtual const CParamNode* GetTemplate(const std::string& templateName) = 0;
67 
68  /**
69  * Like GetTemplate, except without doing the XML validation (so it's faster but
70  * may return invalid templates).
71  *
72  * @return NULL on error
73  */
74  virtual const CParamNode* GetTemplateWithoutValidation(const std::string& templateName) = 0;
75 
76  /**
77  * Check if the template XML file exists, without trying to load it.
78  */
79  virtual bool TemplateExists(const std::string& templateName) const = 0;
80 
81  /**
82  * Returns the template most recently specified for the entity 'ent'.
83  * Used during deserialization.
84  *
85  * @return NULL on error
86  */
87  virtual const CParamNode* LoadLatestTemplate(entity_id_t ent) = 0;
88 
89  /**
90  * Returns the name of the template most recently specified for the entity 'ent'.
91  */
92  virtual std::string GetCurrentTemplateName(entity_id_t ent) const = 0;
93 
94  /**
95  * Returns the list of entities having the specified template.
96  */
97  virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(const std::string& templateName) const = 0;
98 
99  /**
100  * Returns a list of strings that could be validly passed as @c templateName to LoadTemplate.
101  * (This includes "actor|foo" etc names).
102  * Intended for use by the map editor. This is likely to be quite slow.
103  */
104  virtual std::vector<std::string> FindAllTemplates(bool includeActors) const = 0;
105 
106  /**
107  * Returns some data of the civs from the templates.
108  * Intended for use by the map editor.
109  */
110  virtual std::vector<std::vector<std::wstring>> GetCivData() = 0;
111 
112  /**
113  * Returns a list of strings that could be validly passed as @c templateName to LoadTemplate.
114  * Intended for use by the AI manager.
115  */
116  virtual std::vector<std::string> FindUsedTemplates() const = 0;
117 
118  /**
119  * Permanently disable XML validation (intended solely for test cases).
120  */
121  virtual void DisableValidation() = 0;
122 
123  /*
124  * TODO:
125  * When an entity changes template (e.g. upgrades) or player ownership, it
126  * should call some Reload(ent, templateName, playerID) function to load its new template.
127  * When a file changes on disk, something should call Reload(templateName).
128  *
129  * Reloading should happen by sending a message to affected components (containing
130  * their new CParamNode), then automatically updating this.template of scripted components.
131  */
132 
133  DECLARE_INTERFACE_TYPE(TemplateManager)
134 };
135 
136 #endif // INCLUDED_ICMPTEMPLATEMANAGER
An entity initialisation parameter node.
Definition: ParamNode.h:150
Definition: IComponent.h:32
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 std::string GetCurrentTemplateName(entity_id_t ent) const =0
Returns the name of the template most recently specified for the entity &#39;ent&#39;.
virtual std::vector< entity_id_t > GetEntitiesUsingTemplate(const std::string &templateName) const =0
Returns the list of entities having the specified template.
virtual const CParamNode * GetTemplateWithoutValidation(const std::string &templateName)=0
Like GetTemplate, except without doing the XML validation (so it&#39;s faster but may return invalid temp...
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
Template manager: Handles the loading of entity template files for the initialisation and deserializa...
Definition: ICmpTemplateManager.h:33
virtual std::vector< std::string > FindUsedTemplates() const =0
Returns a list of strings that could be validly passed as templateName to LoadTemplate.
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 const CParamNode * LoadLatestTemplate(entity_id_t ent)=0
Returns the template most recently specified for the entity &#39;ent&#39;.
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
virtual const CParamNode * LoadTemplate(entity_id_t ent, const std::string &templateName)=0
Loads the template XML file identified by &#39;templateName&#39; (including inheritance from parent XML files...
virtual bool TemplateExists(const std::string &templateName) const =0
Check if the template XML file exists, without trying to load it.
virtual const CParamNode * GetTemplate(const std::string &templateName)=0
Loads the template XML file identified by &#39;templateName&#39; (including inheritance from parent XML files...