Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / nel / src / logic / logic_event.cpp
blob5410c7ed9b1aee24f2174a832549381b91f2a861
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
18 #include "stdlogic.h"
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;
27 using namespace std;
29 namespace NLLOGIC
32 //----------------------------------- MESSAGE ----------------------------------
35 //-------------------------------------------------
36 // serial
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 );
48 f.xmlPop();
50 } // serial //*/
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 //-------------------------------------------------
79 // enableSendMessage
81 //-------------------------------------------------
82 void CLogicEventAction::enableSendMessage()
84 EventMessage.ToSend = true;
86 } // enableSendMessage //
89 //-------------------------------------------------
90 // serial
92 //-------------------------------------------------
93 /*void CLogicEventAction::serial( IStream &f )
95 f.xmlPush("EVENT_ACTION");
97 f.serial( IsStateChange );
98 if( IsStateChange )
100 f.serial( StateChange );
102 else
104 f.serial( EventMessage );
107 f.xmlPop();
109 } // serial //*/
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());
115 if (IsStateChange)
117 xmlSetProp (elmPtr, (const xmlChar*)"StateChange", (const xmlChar*)StateChange.c_str());
119 else
121 EventMessage.write(elmPtr);
125 void CLogicEventAction::read (xmlNodePtr node)
127 xmlCheckNodeName (node, "EVENT_ACTION");
129 NLMISC::fromString(getXMLProp(node, "IsStateChange"), IsStateChange);
130 if (IsStateChange)
132 StateChange = getXMLProp (node, "StateChange");
134 else
136 EventMessage.read(node);
147 //----------------------------------- EVENT ----------------------------------
151 //-------------------------------------------------
152 // reset
154 //-------------------------------------------------
155 void CLogicEvent::reset()
157 EventAction.EventMessage.Sent = false;
158 EventAction.EventMessage.ToSend = false;
160 } // reset //
164 //-------------------------------------------------
165 // setLogicStateMachine
167 //-------------------------------------------------
168 void CLogicEvent::setLogicStateMachine( CLogicStateMachine * logicStateMachine )
170 if( logicStateMachine == 0 )
172 nlwarning("(LOGIC)<CLogicEvent::setLogicStateMachine> The state machine is null");
174 else
176 // init the logic state machine for this event
177 _LogicStateMachine = logicStateMachine;
180 } // setLogicStateMachine //
184 //-------------------------------------------------
185 // testCondition
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();
199 else
201 nlwarning("(LOGIC)<CLogicEvent::testCondition> Condition %s not found in the state machine",ConditionName.c_str());
202 return false;
205 else
207 nlwarning("(LOGIC)<CLogicEvent::testCondition> Condition undefined");
208 return false;
211 else
213 nlwarning("(LOGIC)<CLogicEvent::testCondition> The state machine managing this event is Null");
216 return false;
218 } // testCondition //
221 //-------------------------------------------------
222 // serial
224 //-------------------------------------------------
225 /*void CLogicEvent::serial( IStream &f )
227 f.xmlPush("EVENT");
229 f.serial( ConditionName );
230 f.serial( EventAction );
232 f.xmlPop();
234 } // serial //*/
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);
251 } // NLLOGIC