ScummVM API documentation
StateMachine.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of HPL1 Engine.
26 */
27
28#ifndef HPL_STATE_MACHINE_H
29#define HPL_STATE_MACHINE_H
30
31#include "hpl1/engine/game/GameTypes.h"
32#include "hpl1/engine/system/SystemTypes.h"
33
34#include "common/stablemap.h"
35
36namespace hpl {
37
38//-----------------------------------------
39class cStateMachine;
40
41class iAIState {
42 friend class cStateMachine;
43
44public:
45 iAIState();
46 virtual ~iAIState() {}
47
48 virtual void OnUpdate(float afTime) = 0;
49
50 virtual void OnEnterState(int alLastState) = 0;
51 virtual void OnLeaveState(int alNextState) = 0;
52
53 int GetId() { return mlId; }
54 const tString &GetName() { return msName; }
55 float GetUpdateStep() { return mfUpdateStep; }
56
57 void Sleep(float afTime);
58
59protected:
60 int mlId;
61 tString msName;
62 float mfUpdateStep;
63 cStateMachine *mpStateMachine;
64
65private:
66 void Update(float afTime);
67 void SetStateMachine(cStateMachine *apStateMachine) { mpStateMachine = apStateMachine; }
68
69 float mfTimeCount;
70};
71
73typedef tAIStateMap::iterator tAIStateMapIt;
74
75//-----------------------------------------
76
78public:
80 virtual ~cStateMachine();
81
82 void Update(float afTime);
83
87 void AddState(iAIState *apState, const tString &asName, int alId, float afUpdateStep);
88
89 void ChangeState(int alId);
90
91 void SetActive(bool abX) { mbActive = abX; }
92 bool IsActive() { return mbActive; }
93
94 iAIState *GetState(int alId);
95
96 iAIState *CurrentState();
97
98private:
99 bool mbActive;
100
101 tAIStateMap m_mapStates;
102
103 iAIState *mpCurrentState;
104};
105
106} // namespace hpl
107
108#endif // HPL_STATE_MACHINE_H
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: str.h:59
Definition: StateMachine.h:77
void AddState(iAIState *apState, const tString &asName, int alId, float afUpdateStep)
Definition: StateMachine.h:41