1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2011 Fabien HENON
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"
28 /** Action and objective base class */
38 std::string _ContentName
;
39 TStepContentType _ContentType
;
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;
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
);
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 */
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
;
87 /// Flag this step a last of a branch, the compiler will generate a fail after it.
89 /// Flag this step as a jump point. This mean that there is a jump that jump on this step.
92 IStep(CMissionData
&md
, NLLIGO::IPrimitive
*prim
);
95 virtual void init(CMissionData
&md
, NLLIGO::IPrimitive
*prim
) {}
99 const std::string
&getStepName()
104 NLLIGO::IPrimitive
*getPrimitive()
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
);
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
149 virtual IStepContent
*createStepContent(CMissionData
&md
, NLLIGO::IPrimitive
*prim
) =0;
152 template <class contentClass
>
153 class CStepContentFactory
: public IStepContentFactory
156 IStepContent
*createStepContent(CMissionData
&md
, NLLIGO::IPrimitive
*prim
)
158 IStepContent
*ret
= new contentClass
;
164 #define REGISTER_STEP_CONTENT(className, key) typedef CStepContentFactory<className> TStepContentFactory##className; \
165 NLMISC_REGISTER_OBJECT_INDIRECT(IStepContentFactory, TStepContentFactory##className, string, key)
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
193 std::vector
<std::string
> _OverloadObj
;
194 CPhrase _OverloadPhrase
;
195 std::vector
<std::string
> _RoleplayObj
;
196 CPhrase _RoleplayPhrase
;
199 // Option nb_guild_members_needed, available for each objective
200 /*int _NbGuildMembersNeeded;
202 std::string genNbGuildMembersNeededOption(CMissionData &md);*/
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
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
);
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
258 /// the list of sub branch
259 NLLIGO::TPrimitiveSet _SubBranchs
;
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
);