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 RY_EFFECT_MANAGER_H
20 #define RY_EFFECT_MANAGER_H
22 #include "nel/misc/types_nl.h"
24 #include "game_share/base_types.h"
25 #include "basic_effect.h"
27 class TEffectVector
: public std::vector
<CBasicEffect
>
29 NL_INSTANCE_COUNTER_DECL(TEffectVector
);
33 //typedef std::vector< CBasicEffect > TEffectVector;
34 typedef std::map
< TDataSetRow
, TEffectVector
* > TEntitiesEffectMap
;
37 * Singleton managing effects for EGS and AIS
38 * \author David Fleury
39 * \author Nevrax France
52 static void release();
54 /// update method (should be called each tick)
57 /// add a effect to given entity
58 inline static void addEffect( const TDataSetRow
&entityRow
, const CBasicEffect
&effect
)
60 TEntitiesEffectMap::iterator it
= _Effects
.find(entityRow
);
61 if ( it
!= _Effects
.end())
63 if ( (*it
).second
!= NULL
)
65 (*it
).second
->push_back(effect
);
69 nlwarning("<CEffectManager::addEffect> NULL pointer instead of effect vector for entity RowId %u", entityRow
.getIndex() );
70 (*it
).second
= new TEffectVector();
72 (*it
).second
->push_back(effect
);
78 TEffectVector
*vector
= new TEffectVector();
81 vector
->push_back(effect
);
82 _Effects
.insert( std::make_pair(entityRow
, vector
) );
86 _NewEffects
.push_back(effect
);
89 /// add a vector of spells to given entity
90 inline static void addEffects( const TDataSetRow
&entityRow
, const std::vector
<CBasicEffect
> &spells
)
92 TEntitiesEffectMap::iterator it
= _Effects
.find(entityRow
);
93 if ( it
!= _Effects
.end())
95 if ( (*it
).second
!= NULL
)
97 (*it
).second
->insert( (*it
).second
->end(), spells
.begin(), spells
.end() );
101 nlwarning("<CEffectManager::addEffect> NULL pointer instead of effect vector for entity RowId %u", entityRow
.getIndex() );
102 (*it
).second
= new TEffectVector();
104 (*it
).second
->insert( (*it
).second
->end(), spells
.begin(), spells
.end() );
110 TEffectVector
*vector
= new TEffectVector();
113 vector
->insert( vector
->end(), spells
.begin(), spells
.end() );
114 _Effects
.insert( std::make_pair(entityRow
, vector
) );
118 _NewEffects
.insert(_NewEffects
.end(), spells
.begin(), spells
.end() );
122 inline static void removeEffect( const TDataSetRow
&entityRow
, uint32 effectId
)
124 TEntitiesEffectMap::iterator it
= _Effects
.find(entityRow
);
125 if ( it
== _Effects
.end())
130 if ( (*it
).second
== NULL
)
132 nlwarning("<CEffectManager::addEffect> NULL pointer instead of effect vector for entity RowId %u", entityRow
.getIndex() );
137 TEffectVector::iterator itEffect
;
138 const TEffectVector::const_iterator itEnd
= (*it
).second
->end();
139 for ( itEffect
= (*it
).second
->begin() ; itEffect
!= itEnd
; ++itEffect
)
141 if ( (*itEffect
).effectId() == effectId
)
143 _RemovedEffects
.push_back(*itEffect
);
144 (*it
).second
->erase(itEffect
);
146 // if last effect, erase entry
147 if ((*it
).second
->empty())
160 inline void removeEntity( const TDataSetRow
&entityRow
)
162 TEntitiesEffectMap::iterator it
= _Effects
.find(entityRow
);
163 if ( it
!= _Effects
.end())
165 if ( (*it
).second
!= NULL
)
174 /// register a service
175 inline void static registerService( NLNET::TServiceId serviceId
)
177 _RegisteredServices
.insert( serviceId
);
180 /// unregister a service
181 inline void static unregisterService( NLNET::TServiceId serviceId
)
183 _RegisteredServices
.erase( serviceId
);
187 /// map entities to their active spells
188 static TEntitiesEffectMap _Effects
;
190 /// the spells created since last update
191 static std::vector
< CBasicEffect
> _NewEffects
;
193 /// the spells deleted since last update
194 static std::vector
< CBasicEffect
> _RemovedEffects
;
196 /// list of services registered to new and removed spells/effects
197 static std::set
<NLNET::TServiceId
> _RegisteredServices
;
202 #endif // RY_EFFECT_MANAGER_H
204 /* End of effect_manager.h */