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/>.
20 #ifndef RYAI_EVENT_REACTION_H
21 #define RYAI_EVENT_REACTION_H
23 #include "ai_logic_action.h"
25 #include "child_container.h"
28 template <class T
> class CAliasCont
;
32 // This is the base class for event handlers for NPC groups
36 class CAIEventDescription
;
37 class CAIEventActionNode
;
39 class CAIEventReaction
:
40 public NLMISC::CDbgRefCount
<CAIEventReaction
>,
41 public NLMISC::CRefCount
,
42 public CAliasChild
<CStateMachine
>
44 , public NLMISC::IDbgPtrData
48 enum EType
{ Generic
, FixedGroup
, FixedState
};
51 // ctor & dtor ------------------------------------------------------
52 CAIEventReaction(CStateMachine
* container
,CAIAliasDescriptionNode
*aliasDescription
):
53 CAliasChild
<CStateMachine
>(container
,aliasDescription
), _eventMgr(), _action(NULL
), _type(Generic
)
57 CAIEventReaction(CStateMachine
* container
, uint32 alias
, std::string
const& name
)
58 : CAliasChild
<CStateMachine
>(container
, alias
, name
)
66 std::string
getIndexString() const;
68 void setType(EType type
)
73 // NOTE if the event mgr is set then we need to remove self from event mgr befor deletion
74 virtual ~CAIEventReaction()
78 // basic accessors --------------------------------------------------
79 IAILogicAction::TSmartPtr
getAction() const { return _action
; }
81 // write accesoors used during parse operations
82 void processEventDescription(CAIEventDescription
*dsc
,CStateMachine
*container
); // process a complete new event description record
84 IAILogicAction
*newAILogicAction( const char *name
,const std::vector
<std::string
> &args
, const std::vector
<IAILogicAction::TSmartPtr
> &subActions
, const CAIAliasDescriptionNode
*eventNode
, CStateMachine
*container
);
86 void setEvent (const std::string
&eventName
,CStateMachine
*container
);// this causes the event reaction to be linked to an event manager
87 void setState (uint32 alias
); // used for events that apply to a specific state
88 uint32
getState (); // used for events that apply to a specific state
89 void setGroup (uint32 alias
); // used for events that apply to a specific group
91 // the following routine shouldn't be needed it should be superceded by a better alternative
92 // in the event manager
93 template <class TState
>
94 bool testCompatibility(CStateInstance
*const stateInstance
, const TState
*const state
) const;
97 // protected data ---------------------------------------------------
98 NLMISC::CDbgPtr
<CAIEvent
> _eventMgr
; // my parent
100 IAILogicAction::TSmartPtr _action
; // my child actions (managed by me)
102 std::vector
<uint32
> _states
; // vector of aliases of specific states
103 CKeywordFilter _stateFilter
; // keyword filter describing states that reation applies to
105 std::vector
<uint32
> _groups
; // vector of aliases of specific groups
106 CKeywordFilter _groupFilter
; // keyword filter for describing groups that reaction applies to
112 IAILogicAction::TSmartPtr
buildAction(CAIEventActionNode
*dsc
, const CAIAliasDescriptionNode
*eventNode
, CStateMachine
*container
);