-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathLevelFunc.h
151 lines (127 loc) · 3.64 KB
/
LevelFunc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef LEVELFUNC_H
#define LEVELFUNC_H
#include "../CommonTypes.h"
#include "../scriptsystem/ScriptSystem.h"
#include "../math/Vector3.h"
#include <vector>
#include <string>
class WorldCell;
class Object;
class LevelFunc
{
public:
enum StateType_e
{
ST_TIME=0,
ST_HOLD,
ST_TERMINATE,
ST_COMPLETE
};
enum
{
IMSG_TRIGGER=0,
IMSG_GOTO_STOP,
IMSG_NEXT_STOP,
IMSG_PREV_STOP,
IMSG_MASTER_ON,
IMSG_MASTER_OFF,
IMSG_CLEAR_BITS,
IMSG_SET_BITS,
IMSG_COMPLETE,
IMSG_DONE,
IMSG_WAKEUP,
IMSG_LIGHTS,
IMSG_NUDGE,
IMSG_ACTIVATE,
IMSG_SHOOT,
IMSG_COUNT
};
enum
{
EMASK_ENEMY = 1,
EMASK_WEAPON = 8,
EMASK_PLAYER = 2147483648
};
typedef void (*LFunc_ActivateCB)(LevelFunc *, int32_t, int32_t, bool);
typedef void (*LFunc_SetValueCB)(LevelFunc *, int32_t, float, bool);
struct ClientObject
{
Object *pObj;
Vector3 vInitialPos;
uint32_t uFlags;
};
public:
//Setup
LevelFunc(WorldCell *pWorldCell, int32_t nSector, int32_t nWall);
~LevelFunc();
void SetActivateCB( LevelFunc::LFunc_ActivateCB pCB ) { m_ActivateCB = pCB; }
void SetSetValueCB( LevelFunc::LFunc_SetValueCB pCB ) { m_SetValueCB = pCB; }
//Level Load
void AddState(float value, int32_t type=ST_TIME, int32_t delay=240);
void AddClient(LevelFunc *pFunc)
{
m_Clients.push_back( pFunc );
}
void AddClientObj(Object *pObj, uint32_t uFlags);
void SetSpeed(float speed) { m_fSpeed = speed; }
void SetAccel(float accel=0.0f) { m_fAccel = accel; }
//API
//Override this function for triggers.
void Activate(int32_t mask, int32_t items, bool bForce=false)
{
if ( m_ActivateCB )
m_ActivateCB(this, mask, items, bForce);
}
//Override for sector effects.
void SetValue(int32_t nSector, float value, bool bInstant=false)
{
if ( m_SetValueCB )
m_SetValueCB(this, nSector, value, bInstant);
}
void SendMessage(int msg, int param0, int param1);
void Update();
void SetInitialState(int32_t state, bool bStartOnInit=false);
WorldCell *GetWorldCell() { return m_pWorldCell; }
uint32_t GetClientCount() { return (uint32_t)m_Clients.size(); }
LevelFunc *GetClient(uint32_t clientID) { return m_Clients[clientID]; }
uint32_t GetClientObjCount() { return (uint32_t)m_ClientObjects.size(); }
ClientObject *GetClientObj(uint32_t clientID) { return m_ClientObjects[clientID]; }
void SetDirection(const Vector3& vDir) { m_vDir = vDir; }
const Vector3& GetDirection() { return m_vDir; }
void SetPivot(const Vector3& vPivot) { m_vPivot = vPivot; }
const Vector3& GetPivot() { return m_vPivot; }
protected:
struct State
{
float value;
int32_t delay;
uint8_t type;
};
std::vector<State *> m_States;
std::vector<LevelFunc *> m_Clients;
std::vector<ClientObject *> m_ClientObjects;
std::vector<int32_t> m_Slaves;
LevelFunc::LFunc_ActivateCB m_ActivateCB;
LevelFunc::LFunc_SetValueCB m_SetValueCB;
int32_t m_nInitialState;
int32_t m_nCurState;
int32_t m_nNextState;
int32_t m_nSector;
int32_t m_nWall;
int32_t m_nKeyNeeded;
int32_t m_nEventMask;
int32_t m_nEntityMask;
int32_t m_nEvent;
int32_t m_nDelay;
float m_fInterp;
float m_fDelta;
float m_fSpeed;
float m_fAccel;
float m_fVel;
float m_fScale;
Vector3 m_vDir;
Vector3 m_vPivot;
WorldCell *m_pWorldCell;
bool m_bActive;
};
#endif //LEVELFUNC_H