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) 2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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 #ifndef RYAI_EVENT_MANAGER_H
21 #define RYAI_EVENT_MANAGER_H
25 #include "event_reaction.h"
28 //---------------------------------------------------------------------------------
30 //---------------------------------------------------------------------------------
32 class CAIEvent
: public NLMISC::CDbgRefCount
<CAIEvent
>
38 virtual ~CAIEvent() {}
41 // called when an event reaction is added during parse of a .primitive file
42 // called by the event reaction object
43 inline void addReaction( CAIEventReaction
*reaction
);
45 // called when an event reaction is deleted due to a modification in a .primitive file
46 inline void removeReaction(CAIEventReaction
*reaction
);
48 inline void removeAllReaction ()
53 void setName(const std::string
&name
)
58 const std::string
&getName() const
63 typedef std::vector
<NLMISC::CDbgPtr
<CAIEventReaction
> > TReactionList
;
65 const TReactionList
&reactionList() const
72 TReactionList _Reactions
;
76 //---------------------------------------------------------------------------------
78 //---------------------------------------------------------------------------------
80 inline void CAIEvent::addReaction (CAIEventReaction
*reaction
)
83 if (std::find_if(_Reactions
.begin(), _Reactions
.end(), std::bind2nd(std::equal_to
<CAIEventReaction
*>(),reaction
))==_Reactions
.end())
85 _Reactions
.push_back(reaction
);
89 nlwarning("BUG: Attempt to add the same reaction '%s' to event manager more than once", reaction
->getAliasNode()->fullName().c_str());
94 inline void CAIEvent::removeReaction(CAIEventReaction
*reaction
)
97 TReactionList::iterator it
=std::find_if(_Reactions
.begin(), _Reactions
.end(), std::bind2nd(std::equal_to
<CAIEventReaction
*>(),reaction
));
98 if (it
==_Reactions
.end())
100 nlwarning("BUG: Failed to remove event reaction from manager as object not found!!!");
104 *it
=_Reactions
.back();
105 _Reactions
.pop_back();
109 // for (uint i=0;i<_Reactions.size();++i)
111 // if (_Reactions[i].ptr()!=reaction)
114 // _Reactions[i]=_Reactions[_Reactions.size()-1];
115 // _Reactions.pop_back();
118 // nlwarning("BUG: Failed to remove event reaction from manager as object not found!!!");
122 //---------------------------------------------------------------------------------