1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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 #include "nel/logic/logic_event.h"
21 #include "nel/logic/logic_state_machine.h"
23 #include "nel/net/service.h"
25 using namespace NLMISC
;
26 using namespace NLNET
;
32 //----------------------------------- MESSAGE ----------------------------------
35 //-------------------------------------------------
38 //-------------------------------------------------
39 /*void CLogicEventMessage::serial( IStream &f )
41 f.xmlPush("EVENT_MESSAGE");
43 f.serial( Destination );
44 f.serial( DestinationId );
45 f.serial( MessageId );
46 f.serial( Arguments );
52 void CLogicEventMessage::write (xmlNodePtr node
, const char *subName
) const
54 xmlNodePtr elmPtr
= xmlNewChild ( node
, NULL
, (const xmlChar
*)string(string(subName
)+string("EVENT_MESSAGE")).c_str(), NULL
);
55 xmlSetProp (elmPtr
, (const xmlChar
*)"Destination", (const xmlChar
*)Destination
.c_str());
56 xmlSetProp (elmPtr
, (const xmlChar
*)"DestinationId", (const xmlChar
*)toString(DestinationId
).c_str());
57 xmlSetProp (elmPtr
, (const xmlChar
*)"MessageId", (const xmlChar
*)toString(MessageId
).c_str());
58 xmlSetProp (elmPtr
, (const xmlChar
*)"Arguments", (const xmlChar
*)toString(Arguments
).c_str());
61 void CLogicEventMessage::read (xmlNodePtr node
, const char *subName
)
63 xmlCheckNodeName (node
, string(string(subName
)+string("EVENT_MESSAGE")).c_str());
65 Destination
= getXMLProp (node
, "Destination");
66 DestinationId
= atoiInt64(getXMLProp (node
, "DestinationId").c_str());
67 MessageId
= getXMLProp (node
, "MessageId");
68 Arguments
= getXMLProp (node
, "Arguments");
75 //----------------------------------- ACTION ----------------------------------
78 //-------------------------------------------------
81 //-------------------------------------------------
82 void CLogicEventAction::enableSendMessage()
84 EventMessage
.ToSend
= true;
86 } // enableSendMessage //
89 //-------------------------------------------------
92 //-------------------------------------------------
93 /*void CLogicEventAction::serial( IStream &f )
95 f.xmlPush("EVENT_ACTION");
97 f.serial( IsStateChange );
100 f.serial( StateChange );
104 f.serial( EventMessage );
111 void CLogicEventAction::write (xmlNodePtr node
) const
113 xmlNodePtr elmPtr
= xmlNewChild ( node
, NULL
, (const xmlChar
*)"EVENT_ACTION", NULL
);
114 xmlSetProp (elmPtr
, (const xmlChar
*)"IsStateChange", (const xmlChar
*)toString(IsStateChange
).c_str());
117 xmlSetProp (elmPtr
, (const xmlChar
*)"StateChange", (const xmlChar
*)StateChange
.c_str());
121 EventMessage
.write(elmPtr
);
125 void CLogicEventAction::read (xmlNodePtr node
)
127 xmlCheckNodeName (node
, "EVENT_ACTION");
129 NLMISC::fromString(getXMLProp(node
, "IsStateChange"), IsStateChange
);
132 StateChange
= getXMLProp (node
, "StateChange");
136 EventMessage
.read(node
);
147 //----------------------------------- EVENT ----------------------------------
151 //-------------------------------------------------
154 //-------------------------------------------------
155 void CLogicEvent::reset()
157 EventAction
.EventMessage
.Sent
= false;
158 EventAction
.EventMessage
.ToSend
= false;
164 //-------------------------------------------------
165 // setLogicStateMachine
167 //-------------------------------------------------
168 void CLogicEvent::setLogicStateMachine( CLogicStateMachine
* logicStateMachine
)
170 if( logicStateMachine
== 0 )
172 nlwarning("(LOGIC)<CLogicEvent::setLogicStateMachine> The state machine is null");
176 // init the logic state machine for this event
177 _LogicStateMachine
= logicStateMachine
;
180 } // setLogicStateMachine //
184 //-------------------------------------------------
187 //-------------------------------------------------
188 bool CLogicEvent::testCondition()
190 if( _LogicStateMachine
)
192 if( ConditionName
!= "no_condition" )
194 CLogicCondition cond
;
195 if( _LogicStateMachine
->getCondition( ConditionName
, cond
) )
197 return cond
.testLogic();
201 nlwarning("(LOGIC)<CLogicEvent::testCondition> Condition %s not found in the state machine",ConditionName
.c_str());
207 nlwarning("(LOGIC)<CLogicEvent::testCondition> Condition undefined");
213 nlwarning("(LOGIC)<CLogicEvent::testCondition> The state machine managing this event is Null");
218 } // testCondition //
221 //-------------------------------------------------
224 //-------------------------------------------------
225 /*void CLogicEvent::serial( IStream &f )
229 f.serial( ConditionName );
230 f.serial( EventAction );
236 void CLogicEvent::write (xmlNodePtr node
) const
238 xmlNodePtr elmPtr
= xmlNewChild ( node
, NULL
, (const xmlChar
*)"EVENT", NULL
);
239 xmlSetProp (elmPtr
, (const xmlChar
*)"ConditionName", (const xmlChar
*)ConditionName
.c_str());
240 EventAction
.write(elmPtr
);
243 void CLogicEvent::read (xmlNodePtr node
)
245 xmlCheckNodeName (node
, "EVENT");
247 ConditionName
= getXMLProp (node
, "ConditionName");
248 EventAction
.read(node
);