Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / leveldesign / mission_compiler_lib / step.h
blob4a0ecb958cf5586086119b08ac839ee0b9a38321
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2011 Fabien HENON
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "nel/misc/types_nl.h"
21 #include "nel/ligo/primitive.h"
22 #include <string>
24 #ifndef __STEP_H__
25 #define __STEP_H__
28 /** Action and objective base class */
29 class IStepContent
31 public:
32 enum TStepContentType
34 objective,
35 action
37 protected:
38 std::string _ContentName;
39 TStepContentType _ContentType;
40 /// post action list
41 std::vector<IStepContent*> _PostActions;
43 // called by base class to retrieve the predefined parameters lists
44 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef) = 0;
45 public:
47 virtual void init(CMissionData &md, NLLIGO::IPrimitive *prim);
49 /// Generate the mission script code for this step content.
50 std::string genStepContentCode(CMissionData &md);
52 /// Generate the phrase string.
53 std::string genStepContentPhrase();
55 static IStepContent *createStepContent(CMissionData &md, NLLIGO::IPrimitive *prim);
57 virtual void fillJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints);
59 protected:
60 /// Generate the mission script code for this step content.
61 virtual std::string genCode(CMissionData &md) = 0;
62 /// Generate the phrase string.
63 virtual std::string genPhrase() { return std::string();}
67 /** Step base class */
68 class IStep
70 protected:
71 /// The name of the step
72 std::string _StepName;
73 /// The type of the step
74 std::string _StepType;
75 /// Pointer on primitive that generate this step
76 NLLIGO::IPrimitive *_Primitive;
78 /// The list of pre-action
79 std::vector<IStepContent *> _PreActions;
80 /// The list of objectives
81 std::vector<IStepContent *> _Objectives;
82 /// The list of post action
83 std::vector<IStepContent *> _PostActions;
84 /// Substeps used for sequence interruption (like an if)
85 std::vector<IStep*> _SubSteps;
86 public:
87 /// Flag this step a last of a branch, the compiler will generate a fail after it.
88 bool EndOfBranch;
89 /// Flag this step as a jump point. This mean that there is a jump that jump on this step.
90 bool JumpPoint;
92 IStep(CMissionData &md, NLLIGO::IPrimitive *prim);
93 virtual ~IStep() {}
95 virtual void init(CMissionData &md, NLLIGO::IPrimitive *prim) {}
98 /// Get the step name
99 const std::string &getStepName()
101 return _StepName;
104 NLLIGO::IPrimitive *getPrimitive()
106 return _Primitive;
109 /// Return true if the step is an action step.
110 // virtual bool isAction() { return false; }
112 virtual bool isAJump() { return false; }
114 virtual bool isEnd() { return false; }
116 /// Return a set of primitive pointer on the sub branch of this step (if any)
117 virtual NLLIGO::TPrimitiveSet getSubBranchs() { return NLLIGO::TPrimitiveSet(); }
119 /// Fill a vector of step name where this step eventualy jump (if any)
120 void fillStepJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints);
122 /// Generate the mission script code for this step.
123 virtual std::string genCode(CMissionData &md);
125 virtual std::string genCodePreActions(CMissionData &md);
126 virtual std::string genCodeObjectives(CMissionData &md);
127 virtual std::string genCodePostActions(CMissionData &md);
129 void addSubStep(IStep *s) { _SubSteps.push_back(s); }
132 /// Generate the string phrase text.
133 virtual std::string genPhrase();
135 /// Factory function to create a new step. The caller is responsible for deleting the allocated object.
136 static IStep *createStep(CMissionData &md, NLLIGO::IPrimitive *prim);
138 protected:
139 /// Fill a vector of step name where this step eventualy jump (if any)
140 virtual void fillJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints);
145 /** StepContent FACTORY **/
146 class IStepContentFactory
148 public:
149 virtual IStepContent *createStepContent(CMissionData &md, NLLIGO::IPrimitive *prim) =0;
152 template <class contentClass>
153 class CStepContentFactory : public IStepContentFactory
155 public:
156 IStepContent *createStepContent(CMissionData &md, NLLIGO::IPrimitive *prim)
158 IStepContent *ret = new contentClass;
159 ret->init(md, prim);
160 return ret;
164 #define REGISTER_STEP_CONTENT(className, key) typedef CStepContentFactory<className> TStepContentFactory##className; \
165 NLMISC_REGISTER_OBJECT_INDIRECT(IStepContentFactory, TStepContentFactory##className, string, key)
169 /** Step FACTORY **/
170 class IStepFactory
172 public:
173 virtual IStep *createStep(CMissionData &md, NLLIGO::IPrimitive *prim) = 0;
176 template <class StepClass>
177 class CStepFactory : public IStepFactory
179 IStep *createStep(CMissionData &md, NLLIGO::IPrimitive *prim)
181 return new StepClass(md, prim);
185 #define REGISTER_STEP_INDIRECT(stepClass, key) typedef CStepFactory<stepClass> TStepFactory##stepClass; \
186 NLMISC_REGISTER_OBJECT_INDIRECT(IStepFactory, TStepFactory##stepClass, string, string(key));
189 /** objective base class **/
190 class CContentObjective : public IStepContent
192 protected:
193 std::vector<std::string> _OverloadObj;
194 CPhrase _OverloadPhrase;
195 std::vector<std::string> _RoleplayObj;
196 CPhrase _RoleplayPhrase;
197 bool _HideObj;
199 // Option nb_guild_members_needed, available for each objective
200 /*int _NbGuildMembersNeeded;
202 std::string genNbGuildMembersNeededOption(CMissionData &md);*/
204 public:
205 void init(CMissionData &md, NLLIGO::IPrimitive *prim);
207 std::string genCode(CMissionData &md);
209 std::string genPhrase();
212 /** special case for step if **/
214 class CStepIf : public IStep
217 enum TIfType
219 it_mission_done,
220 it_skills,
221 it_bricks,
222 it_sdb,
223 it_race,
224 it_cult,
225 it_civ,
226 it_faction_point,
227 it_guild_cult,
228 it_guild_civ,
229 it_guild_fame,
230 it_no_trial,
231 it_item_in_inv,
234 public:
236 CStepIf(CMissionData &md, NLLIGO::IPrimitive *prim);
238 NLLIGO::TPrimitiveSet getSubBranchs();
240 void fillJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints);
242 std::string genCode(CMissionData &md);
244 /// type of test
245 TIfType _IfType;
246 /// If parameters
247 std::vector<std::string> _IfParams;
248 /// the list of sub branch for the dyn chat.
249 NLLIGO::TPrimitiveSet _SubBranchs;
252 /** special case for step player reconnect **/
254 class CStepPlayerReconnect : public IStep
256 // Optional jump at end of failure
257 std::string _JumpTo;
258 /// the list of sub branch
259 NLLIGO::TPrimitiveSet _SubBranchs;
261 public:
262 CStepPlayerReconnect(CMissionData &md, NLLIGO::IPrimitive *prim);
264 NLLIGO::TPrimitiveSet getSubBranchs();
266 std::string genCode(CMissionData &md);
268 void fillJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints);
271 #endif // __STEP_H__