Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / event_manager.h
blob6c9d8181808726d6fd44e759bc0fd88f69098359
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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
23 #include <functional>
25 #include "event_reaction.h"
26 #include "states.h"
28 //---------------------------------------------------------------------------------
29 // CAIEvent
30 //---------------------------------------------------------------------------------
32 class CAIEvent : public NLMISC::CDbgRefCount<CAIEvent>
34 public:
35 CAIEvent () : _Name()
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 ()
50 _Reactions.clear ();
53 void setName(const std::string &name)
55 _Name=name;
58 const std::string &getName() const
60 return _Name;
63 typedef std::vector<NLMISC::CDbgPtr<CAIEventReaction> > TReactionList;
65 const TReactionList &reactionList() const
67 return _Reactions;
70 private:
71 std::string _Name;
72 TReactionList _Reactions;
76 //---------------------------------------------------------------------------------
77 // CAIEvent
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);
87 else
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!!!");
102 else
104 *it=_Reactions.back();
105 _Reactions.pop_back();
109 // for (uint i=0;i<_Reactions.size();++i)
110 // {
111 // if (_Reactions[i].ptr()!=reaction)
112 // continue;
114 // _Reactions[i]=_Reactions[_Reactions.size()-1];
115 // _Reactions.pop_back();
116 // return;
117 // }
118 // nlwarning("BUG: Failed to remove event reaction from manager as object not found!!!");
122 //---------------------------------------------------------------------------------
123 #endif