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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "main.h"
#include "modules.h"
#include "tux.h"
#include "shot.h"
#include "gun.h"
#include "space.h"
#ifndef PUBLIC_SERVER
#include "interface.h"
#include "image.h"
#else /* PUBLIC_SERVER */
#include "publicServer.h"
#endif /* PUBLIC_SERVER */
typedef struct wall_struct {
int id;
/* position of the teleport */
int x;
int y;
/* size of the teleport */
int w;
int h;
int img_x;
int img_y;
/* layer in the arena where the teleport lies */
int layer;
#ifndef PUBLIC_SERVER
/* its image */
image_t *img;
#endif /* PUBLIC_SERVER */
} wall_t;
static export_fce_t *export_fce;
static space_t *spaceWall;
#ifndef PUBLIC_SERVER
static space_t *spaceImgWall;
#endif /* PUBLIC_SERVER */
#ifndef PUBLIC_SERVER
static wall_t *newWall(int x, int y, int w, int h, int img_x, int img_y, int layer, image_t *img)
#else /* PUBLIC_SERVER */
static wall_t *newWall(int x, int y, int w, int h, int img_x, int img_y, int layer)
#endif /* PUBLIC_SERVER */
{
static int last_id = 0;
wall_t *new;
#ifndef PUBLIC_SERVER
assert(img != NULL);
#endif /* PUBLIC_SERVER */
new = malloc(sizeof(wall_t));
assert(new != NULL);
new->id = ++last_id;
new->x = x;
new->y = y;
new->w = w;
new->h = h;
new->img_x = img_x;
new->img_y = img_y;
new->layer = layer;
#ifndef PUBLIC_SERVER
new->img = img;
#endif /* PUBLIC_SERVER */
return new;
}
#ifndef PUBLIC_SERVER
static void drawWall(wall_t *p)
{
assert(p != NULL);
export_fce->fce_addLayer(p->img,
p->img_x, p->img_y,
0, 0,
p->img->w, p->img->h,
p->layer);
}
#endif /* PUBLIC_SERVER */
static void destroyWall(wall_t *p)
{
assert(p != NULL);
free(p);
}
static void getStatusWall(void *p, int *id, int *x, int *y, int *w, int *h)
{
wall_t *wall;
wall = p;
*id = wall->id;
*x = wall->x;
*y = wall->y;
*w = wall->w;
*h = wall->h;
}
static void setStatusWall(void *p, int x, int y, int w, int h)
{
wall_t *wall;
wall = p;
wall->x = x;
wall->y = y;
wall->w = w;
wall->h = h;
}
#ifndef PUBLIC_SERVER
static void getStatusImgWall(void *p, int *id, int *x, int *y, int *w, int *h)
{
wall_t *wall;
wall = p;
*id = wall->id;
*x = wall->img_x;
*y = wall->img_y;
*w = wall->img->w;
*h = wall->img->h;
}
static void setStatusImgWall(void *p, int x, int y, int w, int h)
{
}
#endif /* PUBLIC_SERVER */
static void cmd_wall(char *line)
{
char str_x[STR_NUM_SIZE];
char str_y[STR_NUM_SIZE];
char str_img_x[STR_NUM_SIZE];
char str_img_y[STR_NUM_SIZE];
char str_w[STR_NUM_SIZE];
char str_h[STR_NUM_SIZE];
char str_layer[STR_NUM_SIZE];
char str_image[STR_SIZE];
char str_rel[STR_SIZE];
int x, y, w, h, img_x, img_y, layer;
int rel;
wall_t *new;
rel = 0;
if (export_fce->fce_getValue(line, "rel", str_rel, STR_NUM_SIZE) != 0) {
strcpy(str_rel, "0");
}
if (export_fce->fce_getValue(line, "x", str_x, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "y", str_y, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "w", str_w, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "h", str_h, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "img_x", str_img_x, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "img_y", str_img_y, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 ||
export_fce->fce_getValue(line, "image", str_image, STR_SIZE) != 0) {
return;
}
rel = atoi(str_rel);
x = atoi(str_x);
y = atoi(str_y);
w = atoi(str_w);
h = atoi(str_h);
img_x = atoi(str_img_x);
img_y = atoi(str_img_y);
layer = atoi(str_layer);
if (rel == 1) {
img_x += x;
img_y += y;
}
#ifndef PUBLIC_SERVER
new = newWall(x, y, w, h, img_x, img_y, layer, export_fce->fce_image_get(IMAGE_GROUP_USER, str_image));
#else /* PUBLIC_SERVER */
new = newWall(x, y, w, h, img_x, img_y, layer);
#endif /* PUBLIC_SERVER */
if (spaceWall == NULL) {
spaceWall = space_new(export_fce->fce_arena_get_current()->w,
export_fce->fce_arena_get_current()->h,
320, 240,
getStatusWall, setStatusWall);
}
#ifndef PUBLIC_SERVER
if (spaceImgWall == NULL) {
spaceImgWall = space_new(export_fce->fce_arena_get_current()->w,
export_fce->fce_arena_get_current()->h,
320, 240,
getStatusImgWall, setStatusImgWall);
}
#endif /* PUBLIC_SERVER */
space_add(spaceWall, new);
#ifndef PUBLIC_SERVER
space_add(spaceImgWall, new);
#endif /* PUBLIC_SERVER */
}
static int init(export_fce_t *p)
{
export_fce = p;
return 0;
}
#ifndef PUBLIC_SERVER
static void action_drawwall(space_t *space, wall_t *wall, void *p)
{
drawWall(wall);
}
static int draw(int x, int y, int w, int h)
{
if (spaceWall == NULL) {
return 0;
}
space_action_from_location(spaceImgWall, action_drawwall, NULL, x, y, w, h);
/*space_print(spaceWall);*/
return 0;
}
#endif /* PUBLIC_SERVER */
static void action_eventwall(space_t *space, wall_t *wall, shot_t *shot)
{
arena_t *arena;
tux_t *author;
arena = export_fce->fce_arena_get_current();
author = space_get_object_id(arena->spaceTux, shot->author_id);
if (author != NULL && author->bonus == BONUS_GHOST && author->bonus_time > 0) {
return;
}
if (shot->gun == GUN_BOMBBALL) {
if (export_fce->fce_net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
export_fce->fce_shot_bound_bombBall(shot);
}
return;
}
/*space_del_with_item(arena->spaceShot, shot, export_fce->fce_shot_destroy);*/
shot->del = TRUE;
}
static void action_eventshot(space_t *space, shot_t *shot, space_t *p_spaceWall)
{
space_action_from_location(p_spaceWall, action_eventwall,
shot, shot->x, shot->y,
shot->w, shot->h);
if (shot->del == TRUE) {
space_del_with_item(space, shot, export_fce->fce_shot_destroy);
}
}
static int event()
{
if (spaceWall == NULL) {
return 0;
}
space_action(export_fce->fce_arena_get_current()->spaceShot,
action_eventshot, spaceWall);
return 0;
}
static int isConflict(int x, int y, int w, int h)
{
if (spaceWall == NULL) {
return 0;
}
return space_is_conflict_with_object(spaceWall, x, y, w, h);
}
static void cmdArena(char *line)
{
if (strncmp(line, "wall", 4) == 0) {
cmd_wall(line);
}
}
static void recvMsg(char *msg)
{
}
static int destroy()
{
space_destroy_with_item(spaceWall, destroyWall);
#ifndef PUBLIC_SERVER
space_destroy(spaceImgWall);
spaceImgWall = NULL;
#endif /* PUBLIC_SERVER */
spaceWall = NULL;
return 0;
}
mod_sym_t modwall_sym = { &init,
#ifndef PUBLIC_SERVER
&draw,
#else /* PUBLIC_SERVER */
0,
#endif /* PUBLIC_SERVER */
&event,
&isConflict,
&cmdArena,
&recvMsg,
&destroy };
|