00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef LOGIC_STATE_MACHINE_H
00027 #define LOGIC_STATE_MACHINE_H
00028
00029 #include "logic_state.h"
00030 #include "logic_variable.h"
00031 #include "logic_condition.h"
00032
00033 #include "nel/misc/o_xml.h"
00034 #include "nel/misc/i_xml.h"
00035
00036 #include "nel/net/service.h"
00037
00038 #include <vector>
00039 #include <map>
00040 #include <string>
00041
00042
00043 namespace NLLOGIC
00044 {
00045
00046 void xmlCheckNodeName (xmlNodePtr &node, const char *nodeName);
00047 std::string getXMLProp (xmlNodePtr node, const char *propName);
00048
00056 class CLogicStateMachine
00057 {
00059 std::map<std::string, CLogicVariable> _Variables;
00060
00062 std::map<std::string, CLogicCounter> _Counters;
00063
00065 std::map<std::string, CLogicCondition> _Conditions;
00066
00068 std::map<std::string, CLogicState> _States;
00069
00071 std::string _CurrentState;
00072
00074 std::string _Name;
00075
00076 public:
00077
00078 const std::map<std::string, CLogicVariable> &getVariables () { return _Variables; }
00079 const std::map<std::string, CLogicCounter> &getCounters () { return _Counters; }
00080 const std::map<std::string, CLogicCondition> &getConditions () { return _Conditions; }
00081 const std::map<std::string, CLogicState> &getStates () { return _States; }
00082
00083
00087 CLogicStateMachine() { _Name = "no_name"; }
00088
00094 void setName( const std::string& name ) { _Name = name; }
00095
00101 std::string getName() const { return _Name; }
00102
00108 void setCurrentState( std::string stateName );
00109
00115 void addSIdMap( const TSIdMap& sIdMap );
00116
00120 void processLogic();
00121
00127 void getSelfAddressedMessages( std::list<NLNET::CMessage>& msgs );
00128
00134 void addVariable( CLogicVariable var ) { _Variables.insert( std::make_pair(var.getName(),var) ); }
00135
00143 bool getVariable( std::string& varName, CLogicVariable& var );
00144
00150 void addCounter( CLogicCounter counter ) { _Counters.insert( std::make_pair(counter.getName(),counter) ); }
00151
00157 void addCondition( CLogicCondition condition );
00158
00166 bool getCondition( const std::string& condName, CLogicCondition& cond );
00167
00173 void getMessagesToSend( std::multimap<NLMISC::CEntityId,NLNET::CMessage>& msgs );
00174
00180 void addState( CLogicState logicState );
00181
00189 void modifyVariable( std::string varName, std::string modifOperator, sint64 value );
00190
00194
00195
00199 void displayVariables();
00200
00204 void displayStates();
00205
00212 void setVerbose( std::string varName, bool b );
00213
00214 void write (xmlDocPtr doc) const;
00215 void read (xmlNodePtr node);
00216 };
00217
00218 }
00219
00220 #endif //LOGIC_SYSTEM
00221
00222
00223