Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / combat_action.h
blob5e5ce7bf4c3cd5736d924478e29cee26c4adcac4
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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 RY_COMBAT_ACTION_H
20 #define RY_COMBAT_ACTION_H
22 #include "nel/misc/types_nl.h"
24 #include "game_share/egs_sheets/egs_static_brick.h"
27 class CCombatPhrase;
30 /**
31 * <Class description>
32 * \author David Fleury
33 * \author Nevrax France
34 * \date 2003
36 class CCombatAction
38 public:
39 /// Constructor
40 CCombatAction() : _CombatPhrase(NULL)
43 /// build
44 virtual bool build( const TDataSetRow & actorRowId, const std::vector< const CStaticBrick* >& bricks, uint &brickIndex, CCombatPhrase * phrase ) = 0;
46 /// validate the combat action
47 virtual bool validate(CCombatPhrase *phrase, std::string &errorCode) { return true; }
49 /// apply combat action effects
50 virtual void apply(CCombatPhrase *phrase) {}
52 /// set target
53 inline void setTarget( const TDataSetRow &entityRowId) { _TargetRowId = entityRowId; }
55 protected:
56 TDataSetRow _ActorRowId;
57 TDataSetRow _TargetRowId;
58 CCombatPhrase *_CombatPhrase;
63 /**
64 * <Class description>
65 * \author David Fleury
66 * \author Nevrax France
67 * \date 2003
70 class CCombatActionFactory
72 public:
73 /// clear the class factory
74 static void clear();
76 /**
77 * Build the desired step from a primitive node
78 * \param prim : the primitive node used to build the step
79 * \return a pointer on the built step (NULL if failure)
81 /* inline static CCombatAction * buildAction( const TDataSetRow & actorRowId, const TDataSetRow &targetRowId, const std::vector< const CStaticBrick* >& bricks, uint & brickIndex, CCombatPhrase * phrase )
83 //get appropriate factory
84 for ( uint i = 0; i < Factories->size(); i++ )
86 if ( (*Factories)[i].first == bricks[brickIndex]->Family )
88 return (*Factories)[i].second->build( actorRowId, bricks, brickIndex, phrase);
91 nlwarning( "<CCombatActionFactory buildAction> the brick family %s has no corresponding magic action class", BRICK_FAMILIES::toString( bricks[0]->Family ).c_str() );
92 return NULL;
94 protected:
95 ///\init the factories
96 inline static void init()
98 // if( !Factories )
99 // Factories = new std::vector< std::pair< BRICK_FAMILIES::TBrickFamily , CCombatActionFactory* > >;
102 * Create a step from parameters
103 * \param params : a vector of vector of strings describing the step params
104 * \return a pointer on the built step (NULL if failure)
106 // virtual IMagicAction * build( const TDataSetRow & actorRowId, const std::vector< const CStaticBrick* >& brickIds, uint & index, CMagicPhrase * phrase ) = 0;
108 ///the phrase factories. We use a pointer here because we cant control the order inwhich ctor of static members are called
109 // static std::vector< std::pair< BRICK_FAMILIES::TBrickFamily , CCombatActionFactory* > >* Factories;
115 * Combat action template factory
116 * \author David Fleury
117 * \author Nevrax France
118 * \date 2003
121 template <class T> class CCombatActionTFactory : public CCombatActionFactory
123 public:
124 /// build method
125 T *build( const TDataSetRow & actorRowId, const TDataSetRow &targetRowId, const std::vector< const CStaticBrick* >& bricks, uint &brickIndex, CCombatPhrase * phrase )
127 T *instance = new T;
128 if (!instance)
130 nlwarning("<CCombatActionFactory> failed to allocate element of template type");
131 return 0;
133 if ( !instance->build(actorRowId, targetRowId, bricks, brickIndex, phrase) )
135 delete instance;
136 return 0;
138 return instance:
147 #endif // RY_COMBAT_ACTION_H
149 /* End of combat_action.h */