1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef RYZOM_FABER_ACTION_H
20 #define RYZOM_FABER_ACTION_H
22 #include "nel/misc/types_nl.h"
24 #include "game_share/brick_families.h"
25 #include "game_share/item_type.h"
26 #include "game_share/egs_sheets/egs_static_game_item.h"
30 /// Macro used to declare a Sabrina Faber action ( i.e. : Sword Faber )
31 #define FABER_ACTION_FACTORY(_class_,_type_) \
32 class _class_##Factory : public IFaberActionFactory \
37 for (uint i = 0; i < Factories.size(); i++ ){ \
38 if ( Factories[i].first == _type_){nlerror("<IFaberActionFactory buildPhrase> item type %s is affected to more than one class",ITEM_TYPE::toString(_type_).c_str() );}} \
39 Factories.push_back(std::make_pair(_type_,this));\
42 IFaberAction * build( const TDataSetRow & actorRowId, const std::vector< const CStaticBrick* >& bricks, CFaberPhrase * phrase )\
44 _class_ *inst = new _class_;\
45 if ( !inst->build( actorRowId, bricks, phrase ) ){delete inst;return NULL;} \
49 _class_##Factory* _class_##FactoryInstance = new _class_##Factory;
51 // CFaber action, interface and common members
55 bool build( const TDataSetRow
& actorRowId
, const std::vector
< const CStaticBrick
* >& bricks
, CFaberPhrase
* phrase
)
57 if ( !checkSentenceValidity( bricks
, phrase
) ) return false;
60 virtual void apply(CFaberPhrase
* phrase
) = 0;
61 virtual void systemApply(CFaberPhrase
* phrase
) = 0;
64 //check sentence validity
65 virtual bool checkSentenceValidity( const std::vector
< const CStaticBrick
* >& bricks
, CFaberPhrase
* phrase
) = 0;
69 * class factory for sabrina Faber action
70 * \author Nicolas Brigand
71 * \author Nevrax France
74 class IFaberActionFactory
77 /// clear the class factory
81 * Build the desired step from a primitive node
82 * \param prim : the primitive node used to build the step
83 * \return a pointer on the built step (NULL if failure)
85 inline static IFaberAction
* buildAction( const TDataSetRow
& actorRowId
, const std::vector
< const CStaticBrick
* >& bricks
, CFaberPhrase
* phrase
)
87 //get the root brick family
88 for ( uint i
= 0; i
< Factories
.size(); i
++ )
90 if ( Factories
[i
].first
== ( (CStaticItem
*) bricks
[0] )->Type
)
92 return Factories
[i
].second
->build( actorRowId
, bricks
, phrase
);
95 nlwarning( "<IFaberActionFactory buildAction> the item type %s has no corresponding faber action class", ITEM_TYPE::toString( ((CStaticItem
*)bricks
[0])->Type
).c_str() );
101 * Create a step from parameters
102 * \param params : a vector of vector of strings describing the step params
103 * \return a pointer on the built step (NULL if failure)
105 virtual IFaberAction
* build( const TDataSetRow
& actorRowId
, const std::vector
< const CStaticBrick
* >& brickIds
, CFaberPhrase
* phrase
) = 0;
107 static std::vector
< std::pair
< ITEM_TYPE::TItemType
, IFaberActionFactory
* > > Factories
;
110 #endif // RYZOM_FABER_ACTION_H
112 /* End of faber_action.h */