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/>.
17 #ifndef RYAI_EVENT_REACTION_CONTAINER_H
18 #define RYAI_EVENT_REACTION_CONTAINER_H
20 #include "event_manager.h"
22 class CPersistentStateInstance
;
26 : public NLMISC::IDbgPtrData
32 _LastStateEventAlias
= 0;
34 virtual ~CStateMachine()
36 clearEventContainerContent ();
39 virtual std::vector
<std::string
> getMultiLineInfoString() const;
41 CAIEvent EventPositionalStateTimeout
;
42 CAIEvent EventPunctualStateTimeout
;
43 CAIEvent EventStartOfState
;
44 CAIEvent EventEndOfState
;
45 CAIEvent EventUserTimer
[4];
46 CAIEvent EventUserEvent
[10];
47 CAIEvent EventEscortAway
;
48 CAIEvent EventEscortBack
;
50 CAIEvent EventVariableChanged
;
51 CAIEvent EventVariableChangedTab
[4];
52 CAIEvent EventPlayerTargetNpc
;
53 CAIEvent EventPlayerFollowNpc
;
54 CAIEvent EventBotBeginFight
;
55 CAIEvent EventBotTargetKilled
;
56 CAIEvent EventGroupBeginFight
;
57 CAIEvent EventGroupEndFight
;
59 CAIEvent EventLastBotDespawned
;
60 CAIEvent EventFirstBotSpawned
;
63 CAIEvent EventPlayerEnterTriggerZone
;
64 CAIEvent EventPlayerLeaveTriggerZone
;
67 virtual void registerEvents()
69 addEvent("punctual_state_timeout", EventPunctualStateTimeout
);
70 addEvent("start_of_state", EventStartOfState
);
71 addEvent("end_of_state", EventEndOfState
);
72 addEvent("state_timeout", EventPositionalStateTimeout
);
73 addEvent("timer_t0_triggered", EventUserTimer
[0] );
74 addEvent("timer_t1_triggered", EventUserTimer
[1] );
75 addEvent("timer_t2_triggered", EventUserTimer
[2] );
76 addEvent("timer_t3_triggered", EventUserTimer
[3] );
77 addEvent("user_event_0", EventUserEvent
[0] );
78 addEvent("user_event_1", EventUserEvent
[1] );
79 addEvent("user_event_2", EventUserEvent
[2] );
80 addEvent("user_event_3", EventUserEvent
[3] );
81 addEvent("user_event_4", EventUserEvent
[4] );
82 addEvent("user_event_5", EventUserEvent
[5] );
83 addEvent("user_event_6", EventUserEvent
[6] );
84 addEvent("user_event_7", EventUserEvent
[7] );
85 addEvent("user_event_8", EventUserEvent
[8] );
86 addEvent("user_event_9", EventUserEvent
[9] );
87 addEvent("escort_away", EventEscortAway
);
88 addEvent("escort_back", EventEscortBack
);
90 addEvent("variable_changed", EventVariableChanged
);
91 addEvent("variable_v0_changed", EventVariableChangedTab
[0] );
92 addEvent("variable_v1_changed", EventVariableChangedTab
[1] );
93 addEvent("variable_v2_changed", EventVariableChangedTab
[2] );
94 addEvent("variable_v3_changed", EventVariableChangedTab
[3] );
96 addEvent("player_target_npc", EventPlayerTargetNpc
);
97 addEvent("player_follow_npc", EventPlayerFollowNpc
);
98 addEvent("bot_begin_fight", EventBotBeginFight
);
99 addEvent("bot_target_killed", EventBotTargetKilled
);
100 addEvent("group_under_attack", EventGroupBeginFight
);
101 addEvent("group_attack_end", EventGroupEndFight
);
103 addEvent("group_despawned", EventLastBotDespawned
);
104 addEvent("group_spawned", EventFirstBotSpawned
);
105 addEvent("egs_up", EventEGSUp
);
106 addEvent("player_arrived_trigger_zone", EventPlayerEnterTriggerZone
);
107 addEvent("player_left_trigger_zone", EventPlayerLeaveTriggerZone
);
110 void addEvent(std::string
const& name
, CAIEvent
& event
)
112 _eventNameMap
[name
] = &event
;
114 _eventNameMap
[name
].setData(this);
119 void delEvent(std::string
const& name
)
121 _eventNameMap
.erase(name
);
124 void clearEventContainerContent()
126 std::map
<std::string
, NLMISC::CDbgPtr
<CAIEvent
> >::iterator it
=_eventNameMap
.begin(), itEnd
=_eventNameMap
.end();
129 it
->second
->removeAllReaction();
133 _eventReactions
.clear();
134 _eventNameMap
.clear();
137 std::map
<std::string
,NLMISC::CDbgPtr
<CAIEvent
> > const& GetEventManagerMap() const
139 return _eventNameMap
;
142 //--------------------------------------------------------------------------
143 // CAIMgr METHOD Encapsulating user event trigger system
144 //--------------------------------------------------------------------------
146 CAIEvent
* getEventManager(std::string
const& name
)
148 std::map
<std::string
,NLMISC::CDbgPtr
<CAIEvent
> >::const_iterator it
= GetEventManagerMap().find(name
);
149 if (it
!=GetEventManagerMap().end())
154 std::string
const& getEventManagerName(CAIEvent
const* evtMgr
)
156 static std::string
const unknown("UNKNOWN MANAGER");
157 typedef std::map
<std::string
, NLMISC::CDbgPtr
<CAIEvent
> > TTmpCont
;
158 FOREACH(it
, TTmpCont
, _eventNameMap
)
160 if (it
->second
!=evtMgr
)
167 virtual std::string
getIndexString()
169 return std::string("0");
172 inline CAliasCont
<CAIEventReaction
>& eventReactions() { return _eventReactions
; }
174 CAliasCont
<CAIState
>& states() { return _states
; }
175 CAliasCont
<CAIState
> const& cstStates() const { return _states
; }
177 uint32
getLastStateEventAlias() { return ++_LastStateEventAlias
; }
180 uint32 _LastStateEventAlias
;
181 CAliasCont
<CAIState
> _states
;
182 CAliasCont
<CAIEventReaction
> _eventReactions
;
183 std::map
<std::string
,NLMISC::CDbgPtr
<CAIEvent
> > _eventNameMap
;