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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef LASTEXPRESS_ENTITY_INTERN_H
#define LASTEXPRESS_ENTITY_INTERN_H
namespace LastExpress {
//////////////////////////////////////////////////////////////////////////
// Setup
//////////////////////////////////////////////////////////////////////////
#define IMPLEMENT_SETUP(class, callback_class, name, index) \
void class::setup_##name() { \
BEGIN_SETUP(callback_class, name, index, EntityData::EntityParametersIIII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::setup_" #name "()"); \
END_SETUP() \
}
#define BEGIN_SETUP(class, name, index, type) \
_engine->getGameLogic()->getGameState()->getGameSavePoints()->setCallback(_entityIndex, _callbacks[index]); \
_data->setCurrentCallback(index); \
_data->resetCurrentParameters<type>();
#define END_SETUP() \
_engine->getGameLogic()->getGameState()->getGameSavePoints()->call(_entityIndex, _entityIndex, kActionDefault);
//////////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////////
// Expose parameters and check validity
#define EXPOSE_PARAMS(type) \
type *params = (type *)_data->getCurrentParameters(); \
if (!params) \
error("[EXPOSE_PARAMS] Trying to call an entity function with invalid parameters"); \
// function signature without setup (we keep the index for consistency but never use it)
#define IMPLEMENT_FUNCTION_NOSETUP(index, class, name) \
void class::name(const SavePoint &savepoint) { \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(index=" #index ")");
// simple setup with no parameters
#define IMPLEMENT_FUNCTION(index, class, name) \
IMPLEMENT_SETUP(class, class, name, index) \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersIIII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "() - action: %s", ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_END }
// nullfunction call
#define IMPLEMENT_NULL_FUNCTION(index, class) \
IMPLEMENT_SETUP(class, Entity, nullfunction, index)
// setup with one uint parameter
#define IMPLEMENT_FUNCTION_I(index, class, name, paramType) \
void class::setup_##name(paramType param1) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersIIII) \
EntityData::EntityParametersIIII *params = (EntityData::EntityParametersIIII*)_data->getCurrentParameters(); \
params->param1 = (unsigned int)param1; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersIIII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d) - action: %s", params->param1, ACTION_NAME(savepoint.action));
// setup with two uint parameters
#define IMPLEMENT_FUNCTION_II(index, class, name, paramType1, paramType2) \
void class::setup_##name(paramType1 param1, paramType2 param2) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersIIII) \
EntityData::EntityParametersIIII *params = (EntityData::EntityParametersIIII*)_data->getCurrentParameters(); \
params->param1 = param1; \
params->param2 = param2; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersIIII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d, %d) - action: %s", params->param1, params->param2, ACTION_NAME(savepoint.action));
// setup with three uint parameters
#define IMPLEMENT_FUNCTION_III(index, class, name, paramType1, paramType2, paramType3) \
void class::setup_##name(paramType1 param1, paramType2 param2, paramType3 param3) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersIIII) \
EntityData::EntityParametersIIII *params = (EntityData::EntityParametersIIII*)_data->getCurrentParameters(); \
params->param1 = param1; \
params->param2 = param2; \
params->param3 = param3; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersIIII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d, %d, %d) - action: %s", params->param1, params->param2, params->param3, ACTION_NAME(savepoint.action));
// setup with one char *parameter
#define IMPLEMENT_FUNCTION_S(index, class, name) \
void class::setup_##name(const char *seq1) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSIIS) \
EntityData::EntityParametersSIIS *params = (EntityData::EntityParametersSIIS*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq1, seq1, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSIIS) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s) - action: %s", (char *)¶ms->seq1, ACTION_NAME(savepoint.action));
// setup with one char *parameter and one uint
#define IMPLEMENT_FUNCTION_SI(index, class, name, paramType2) \
void class::setup_##name(const char *seq1, paramType2 param4) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSIIS) \
EntityData::EntityParametersSIIS *params = (EntityData::EntityParametersSIIS*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq1, seq1, 12); \
params->param4 = param4; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSIIS) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s, %d) - action: %s", (char *)¶ms->seq1, params->param4, ACTION_NAME(savepoint.action));
// setup with one char *parameter and two uints
#define IMPLEMENT_FUNCTION_SII(index, class, name, paramType2, paramType3) \
void class::setup_##name(const char *seq1, paramType2 param4, paramType3 param5) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSIIS) \
EntityData::EntityParametersSIIS *params = (EntityData::EntityParametersSIIS*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq1, seq1, 12); \
params->param4 = param4; \
params->param5 = param5; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSIIS) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s, %d, %d) - action: %s", (char *)¶ms->seq1, params->param4, params->param5, ACTION_NAME(savepoint.action));
// setup with one char *parameter and three uints
#define IMPLEMENT_FUNCTION_SIII(index, class, name, paramType2, paramType3, paramType4) \
void class::setup_##name(const char *seq, paramType2 param4, paramType3 param5, paramType4 param6) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSIII) \
EntityData::EntityParametersSIII *params = (EntityData::EntityParametersSIII*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq, seq, 12); \
params->param4 = param4; \
params->param5 = param5; \
params->param6 = param6; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSIII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s, %d, %d, %d) - action: %s", (char *)¶ms->seq, params->param4, params->param5, params->param6, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_SIIS(index, class, name, paramType2, paramType3) \
void class::setup_##name(const char *seq1, paramType2 param4, paramType3 param5, const char *seq2) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSIIS) \
EntityData::EntityParametersSIIS *params = (EntityData::EntityParametersSIIS*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq1, seq1, 12); \
params->param4 = param4; \
params->param5 = param5; \
strncpy((char *)¶ms->seq2, seq2, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSIIS) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s, %d, %d, %s) - action: %s", (char *)¶ms->seq1, params->param4, params->param5, (char *)¶ms->seq2, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_SS(index, class, name) \
void class::setup_##name(const char *seq1, const char *seq2) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSSII) \
EntityData::EntityParametersSSII *params = (EntityData::EntityParametersSSII*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq1, seq1, 12); \
strncpy((char *)¶ms->seq2, seq2, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSSII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s, %s) - action: %s", (char *)¶ms->seq1, (char *)¶ms->seq2, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_SSI(index, class, name, paramType3) \
void class::setup_##name(const char *seq1, const char *seq2, paramType3 param7) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersSSII) \
EntityData::EntityParametersSSII *params = (EntityData::EntityParametersSSII*)_data->getCurrentParameters(); \
strncpy((char *)¶ms->seq1, seq1, 12); \
strncpy((char *)¶ms->seq2, seq2, 12); \
params->param7 = param7; \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersSSII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%s, %s, %d) - action: %s", (char *)¶ms->seq1, (char *)¶ms->seq2, params->param7, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_IS(index, class, name, paramType) \
void class::setup_##name(paramType param1, const char *seq) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersISII) \
EntityData::EntityParametersISII *params = (EntityData::EntityParametersISII*)_data->getCurrentParameters(); \
params->param1 = (unsigned int)param1; \
strncpy((char *)¶ms->seq, seq, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersISII) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d, %s) - action: %s", params->param1, (char *)¶ms->seq, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_ISS(index, class, name, paramType) \
void class::setup_##name(paramType param1, const char *seq1, const char *seq2) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersISSI) \
EntityData::EntityParametersISSI *params = (EntityData::EntityParametersISSI*)_data->getCurrentParameters(); \
params->param1 = param1; \
strncpy((char *)¶ms->seq1, seq1, 12); \
strncpy((char *)¶ms->seq2, seq2, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersISSI) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d, %s, %s) - action: %s", params->param1, (char *)¶ms->seq1, (char *)¶ms->seq2, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_IIS(index, class, name, paramType1, paramType2) \
void class::setup_##name(paramType1 param1, paramType2 param2, const char *seq) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersIISI) \
EntityData::EntityParametersIISI *params = (EntityData::EntityParametersIISI*)_data->getCurrentParameters(); \
params->param1 = param1; \
params->param2 = param2; \
strncpy((char *)¶ms->seq, seq, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersIISI) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d, %d, %s) - action: %s", params->param1, params->param2, (char *)¶ms->seq, ACTION_NAME(savepoint.action));
#define IMPLEMENT_FUNCTION_IISS(index, class, name, paramType1, paramType2) \
void class::setup_##name(paramType1 param1, paramType2 param2, const char *seq1, const char *seq2) { \
BEGIN_SETUP(class, name, index, EntityData::EntityParametersIISS) \
EntityData::EntityParametersIISS *params = (EntityData::EntityParametersIISS*)_data->getCurrentParameters(); \
params->param1 = param1; \
params->param2 = param2; \
strncpy((char *)¶ms->seq1, seq1, 12); \
strncpy((char *)¶ms->seq2, seq2, 12); \
END_SETUP() \
} \
void class::name(const SavePoint &savepoint) { \
EXPOSE_PARAMS(EntityData::EntityParametersIISS) \
debugC(6, kLastExpressDebugLogic, "Entity: " #class "::" #name "(%d, %d, %s, %s) - action: %s", params->param1, params->param2, (char *)¶ms->seq1, (char *)¶ms->seq2, ACTION_NAME(savepoint.action));
//////////////////////////////////////////////////////////////////////////
// Time check macros
//////////////////////////////////////////////////////////////////////////
#define TIME_CHECK_CALLBACK_1(timeValue, parameter, callback, function, param1) \
if (getState()->time > timeValue && !parameter) { \
parameter = 1; \
setCallback(callback); \
function(param1); \
break; \
}
#define TIME_CHECK_CALLBACK_3(timeValue, parameter, callback, function, param1, param2, param3) \
if (getState()->time > timeValue && !parameter) { \
parameter = 1; \
setCallback(callback); \
function(param1, param2, param3); \
break; \
}
} // End of namespace LastExpress
#endif // LASTEXPRESS_ENTITY_INTERN_H
|