00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021 #ifndef AIFSM_H
00022 #define AIFSM_H
00023
00024 #include "AIBase.h"
00025
00040 class AIState {
00041 public:
00042 int stateID;
00043 std::vector<AIAction> theactions;
00044 std::vector<int> inputs;
00045 std::vector<AIState*> next;
00046
00047 AIState(int stateID_=-1, std::vector<AIAction> theactions_=std::vector<AIAction>());
00048 AIState* returnNextState(int input_);
00049
00050 int serialize(std::ofstream& fout_) const;
00051 int assemble(std::ifstream& fin_, std::vector<int>& nextStateIDs_);
00052 };
00053
00057 extern std::vector<AIState> states;
00058
00070 class AIFSM {
00071 static bool areGlobalStatesSerialized;
00072 static bool areGlobalStatesAssembled;
00073 AI_FSM_IDS FSMID;
00074 bool isInitialStateSet;
00075 int statesindex;
00076 AIState* thestates[AI_FSM_STATE_MAX];
00077 public:
00082 AIFSM(AI_FSM_IDS FSMID_);
00083 AIFSM(AI_FSM_IDS FSMID_, AIState& initialstate_);
00084
00088 AI_FSM_IDS getFSMID() const { return FSMID; }
00089
00098 bool setInitialState(AIState& initialstate_);
00099
00105 AIState*& getInitialState() { return thestates[0]; }
00106
00114 bool addState(AIState& currentstate_, int input_, AIState& nextstate_);
00115
00120 AIState* getStateByID(int ID_) const;
00121
00127 static void initAIFSMFileIO() {
00128 areGlobalStatesSerialized = false;
00129 areGlobalStatesAssembled = false;
00130 }
00131
00137 int serialize(std::ofstream& fout_) const;
00138
00144 int assemble(std::ifstream& fin_);
00145 };
00146
00150 namespace AIFileIO {
00157 template <>
00158 int serialize(std::ofstream& fout_, const std::vector<AIState>& stateVector_);
00159
00166 template <>
00167 int assemble(std::ifstream& fin_, std::vector<AIState>& stateVector_);
00168 }
00169
00170 #endif //AIFSM_H