Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AIWrapper.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2011 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef AIWRAPPER_H
22 #define AIWRAPPER_H
23 
24 #include "AIManager.h"
25 
26 #include <stack>
27 
35 namespace OpenSkyNet {
36  namespace AI {
40  class Wrapper {
41  protected:
42  struct FSMWrapper {
47  bool _isEnabled;
48 
49  FSMWrapper();
50  };
51 
53  std::stack<FSMWrapper*> _stackFSMs;
55  KB* _kB;
58  public:
62  Wrapper();
63 
65 
71  virtual void init(LOGIC_IDS logicId_, FSM_IDS fSMId_, State* state_);
78  virtual void init(LOGIC_IDS logicId_, FSM_IDS fSMId_, State* state_, KB* kB_);
80 
85  virtual bool performLogic(bool includeGlobalKB_=false);
86 
90  virtual const State* getCurrentState() const { return _fSMs[_currFSMIndex]._state; }
91 
96  void enableSwitchingToFSM(FSM_IDS fSMId_, State* state_=0);
97 
101  inline void disableSwitchingToFSM(FSM_IDS fSMId_) { _fSMs[fSMId_]._isEnabled = false; }
102 
112  bool setFSM(FSM_IDS fSMId_, State* state_=0, bool autoEnable_=true); //< returns true if successful, false otherwise
113 
117  FSM_IDS getFSM() const { return _currFSMIndex; }
118 
128  bool pushFSM(FSM_IDS fSMId_, State* state_=0, bool autoEnable_=true); //< returns true if successful, false otherwise
129 
134  bool popFSM(); //< returns true if the current FSM changes, false otherwise
135 
139  bool setLogic(LOGIC_IDS logicId_); //< returns true if successful, false otherwise
140 
145 
149  virtual KB* getKB() { return _kB; }
150 
151  virtual void doAction();
152 
156  virtual ~Wrapper();
157  };
158 
159  extern bool g_usedHeap;
160 
166  void initAIEngine(std::ifstream* fin_=0);
167 
168  void destroyAIEngine();
169 
175  void popAllRecords(bool onlyAddNew_=false, bool removeAll_=false);
176  }
177 }
178 
179 #endif //AIWRAPPER_H
virtual ~Wrapper()
Definition: AIWrapper.cpp:134
bool setLogic(LOGIC_IDS logicId_)
Definition: AIWrapper.cpp:125
bool setFSM(FSM_IDS fSMId_, State *state_=0, bool autoEnable_=true)
Definition: AIWrapper.cpp:77
Definition: AIFSM.h:74
void initAIEngine(std::ifstream *fin_=0)
FSM * _fSM
Definition: AIWrapper.h:43
bool _isEnabled
Definition: AIWrapper.h:47
void disableSwitchingToFSM(FSM_IDS fSMId_)
Definition: AIWrapper.h:101
KB * _kB
Definition: AIWrapper.h:55
Definition: AIKB.h:33
void enableSwitchingToFSM(FSM_IDS fSMId_, State *state_=0)
Definition: AIWrapper.cpp:61
LOGIC_IDS getCurrentLogicId()
Definition: AIWrapper.h:144
Definition: AIConsts.h:29
virtual void init(LOGIC_IDS logicId_, FSM_IDS fSMId_, State *state_)
Definition: AIWrapper.cpp:30
virtual const State * getCurrentState() const
Definition: AIWrapper.h:90
bool pushFSM(FSM_IDS fSMId_, State *state_=0, bool autoEnable_=true)
Definition: AIWrapper.cpp:98
bool _wasKBCreatedHere
Definition: AIWrapper.h:56
LOGIC_IDS getLogicId() const
Definition: AILogic.h:82
Definition: AIWrapper.h:40
float _timeStampStateChange
Definition: AIWrapper.h:45
std::stack< FSMWrapper * > _stackFSMs
Definition: AIWrapper.h:53
FSMWrapper()
Definition: AIWrapper.cpp:23
Wrapper()
Definition: AIWrapper.cpp:25
LOGIC_IDS
Definition: AIConsts.h:32
Definition: AILogic.h:35
FSM_IDS
Definition: AIConsts.h:28
Logic * _logic
Definition: AIWrapper.h:57
FSM_IDS getFSM() const
Definition: AIWrapper.h:117
Definition: AIFSM.h:42
bool popFSM()
Definition: AIWrapper.cpp:117
bool g_usedHeap
Definition: AIWrapper.cpp:15
void destroyAIEngine()
Definition: AIWrapper.cpp:171
virtual KB * getKB()
Definition: AIWrapper.h:149
virtual void doAction()
to be implemented by derived or containing class
Definition: AIWrapper.cpp:132
FSMWrapper _fSMs[FSM_MAX]
Definition: AIWrapper.h:52
FSM_IDS _currFSMIndex
Definition: AIWrapper.h:54
void popAllRecords(bool onlyAddNew_=false, bool removeAll_=false)
Definition: AIWrapper.cpp:194
FSM_IDS _index
Definition: AIWrapper.h:46
Definition: AIWrapper.h:42
State * _state
Definition: AIWrapper.h:44
virtual bool performLogic(bool includeGlobalKB_=false)
returns true if state changed, false otherwise
Definition: AIWrapper.cpp:55