Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ICmpTemplateManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 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), and applies the techs that are currently active for
39  * player 'playerID', for use with a new entity 'ent'.
40  * The returned CParamNode must not be used for any entities other than 'ent'.
41  *
42  * If templateName is of the form "actor|foo" then it will load a default
43  * stationary entity template that uses actor "foo". (This is a convenience to
44  * avoid the need for hundreds of tiny decorative-object entity templates.)
45  *
46  * If templateName is of the form "preview|foo" then it will load a template
47  * based on entity template "foo" with the non-graphical components removed.
48  * (This is for previewing construction/placement of units.)
49  *
50  * If templateName is of the form "corpse|foo" then it will load a template
51  * like "preview|foo" but with corpse-related components included.
52  *
53  * If templateName is of the form "foundation|foo" then it will load a template
54  * based on entity template "foo" with various components removed and a few changed
55  * and added. (This is for constructing foundations of buildings.)
56  *
57  * @return NULL on error
58  */
59  virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName, int playerID) = 0;
60 
61  /**
62  * Loads the template XML file identified by 'templateName' (including inheritance
63  * from parent XML files). The templateName syntax is the same as LoadTemplate.
64  *
65  * @return NULL on error
66  */
67  virtual const CParamNode* GetTemplate(std::string templateName) = 0;
68 
69  /**
70  * Like GetTemplate, except without doing the XML validation (so it's faster but
71  * may return invalid templates).
72  *
73  * @return NULL on error
74  */
75  virtual const CParamNode* GetTemplateWithoutValidation(std::string templateName) = 0;
76 
77  /**
78  * Returns the template most recently specified for the entity 'ent'.
79  * Used during deserialization.
80  *
81  * @return NULL on error
82  */
83  virtual const CParamNode* LoadLatestTemplate(entity_id_t ent) = 0;
84 
85  /**
86  * Returns the name of the template most recently specified for the entity 'ent'.
87  */
88  virtual std::string GetCurrentTemplateName(entity_id_t ent) = 0;
89 
90  /**
91  * Returns the list of entities having the specified template.
92  */
93  virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(std::string templateName) = 0;
94 
95  /**
96  * Returns a list of strings that could be validly passed as @c templateName to LoadTemplate.
97  * (This includes "actor|foo" etc names).
98  * Intended for use by the map editor. This is likely to be quite slow.
99  */
100  virtual std::vector<std::string> FindAllTemplates(bool includeActors) = 0;
101 
102  /**
103  * Permanently disable XML validation (intended solely for test cases).
104  */
105  virtual void DisableValidation() = 0;
106 
107  /*
108  * TODO:
109  * When an entity changes template (e.g. upgrades) or player ownership, it
110  * should call some Reload(ent, templateName, playerID) function to load its new template.
111  * When a player researches new techs, it should call Reload(playerID).
112  * When a file changes on disk, something should call Reload(templateName).
113  *
114  * Reloading should happen by sending a message to affected components (containing
115  * their new CParamNode), then automatically updating this.template of scripted components.
116  */
117 
118  DECLARE_INTERFACE_TYPE(TemplateManager)
119 };
120 
121 #endif // INCLUDED_ICMPTEMPLATEMANAGER
An entity initialisation parameter node.
Definition: ParamNode.h:112
virtual void DisableValidation()=0
Permanently disable XML validation (intended solely for test cases).
virtual const CParamNode * GetTemplate(std::string templateName)=0
Loads the template XML file identified by &#39;templateName&#39; (including inheritance from parent XML files...
virtual std::vector< entity_id_t > GetEntitiesUsingTemplate(std::string templateName)=0
Returns the list of entities having the specified template.
virtual const CParamNode * GetTemplateWithoutValidation(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
virtual std::vector< std::string > FindAllTemplates(bool includeActors)=0
Returns a list of strings that could be validly passed as templateName to LoadTemplate.
Template manager: Handles the loading of entity template files for the initialisation and deserializa...
virtual const CParamNode * LoadTemplate(entity_id_t ent, const std::string &templateName, int playerID)=0
Loads the template XML file identified by &#39;templateName&#39; (including inheritance from parent XML files...
virtual const CParamNode * LoadLatestTemplate(entity_id_t ent)=0
Returns the template most recently specified for the entity &#39;ent&#39;.
virtual std::string GetCurrentTemplateName(entity_id_t ent)=0
Returns the name of the template most recently specified for the entity &#39;ent&#39;.
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24