15 #include "interface.h"
18 #include "publicServer.h"
21 typedef struct teleport_struct
{
24 /* position of the teleport */
28 /* size of the teleport */
32 /* layer in the arena where the teleport lies */
41 static export_fce_t
*export_fce
;
43 static space_t
*spaceTeleport
;
44 static list_t
*listTeleport
;
46 static void (*fce_move_tux
) (tux_t
*tux
, int x
, int y
, int w
, int h
);
47 static void (*fce_move_shot
) (shot_t
*shot
, int position
, int src_x
,
48 int src_y
, int dist_x
, int dist_y
, int dist_w
,
52 static teleport_t
*newTeleport(int x
, int y
, int w
, int h
, int layer
, image_t
*img
)
54 static teleport_t
*newTeleport(int x
, int y
, int w
, int h
, int layer
)
57 static int last_id
= 0;
65 new = malloc(sizeof(teleport_t
));
81 static void setStatusTeleport(void *p
, int x
, int y
, int w
, int h
)
93 static void getStatusTeleport(void *p
, int *id
, int *x
, int *y
, int *w
, int *h
)
105 #ifndef PUBLIC_SERVER
106 static void drawTeleport(teleport_t
*p
)
110 export_fce
->fce_addLayer(p
->img
, p
->x
, p
->y
, 0, 0, p
->img
->w
, p
->img
->h
, p
->layer
);
114 static void destroyTeleport(teleport_t
*p
)
120 static void cmd_teleport(char *line
)
122 char str_x
[STR_NUM_SIZE
];
123 char str_y
[STR_NUM_SIZE
];
124 char str_w
[STR_NUM_SIZE
];
125 char str_h
[STR_NUM_SIZE
];
126 char str_layer
[STR_NUM_SIZE
];
127 char str_image
[STR_SIZE
];
130 if (export_fce
->fce_getValue(line
, "x", str_x
, STR_NUM_SIZE
) != 0)
132 if (export_fce
->fce_getValue(line
, "y", str_y
, STR_NUM_SIZE
) != 0)
134 if (export_fce
->fce_getValue(line
, "w", str_w
, STR_NUM_SIZE
) != 0)
136 if (export_fce
->fce_getValue(line
, "h", str_h
, STR_NUM_SIZE
) != 0)
138 if (export_fce
->fce_getValue(line
, "layer", str_layer
, STR_NUM_SIZE
) != 0)
140 if (export_fce
->fce_getValue(line
, "image", str_image
, STR_SIZE
) != 0)
143 #ifndef PUBLIC_SERVER
144 new = newTeleport(atoi(str_x
), atoi(str_y
),
145 atoi(str_w
), atoi(str_h
),
147 export_fce
->fce_image_get(IMAGE_GROUP_USER
, str_image
));
149 new = newTeleport(atoi(str_x
), atoi(str_y
),
150 atoi(str_w
), atoi(str_h
),
154 if (spaceTeleport
== NULL
) {
155 spaceTeleport
= space_new(export_fce
->fce_arena_get_current()->w
,
156 export_fce
->fce_arena_get_current()->h
,
158 getStatusTeleport
, setStatusTeleport
);
161 space_add(spaceTeleport
, new);
164 static teleport_t
*getRandomTeleportBut(space_t
*space
, teleport_t
*teleport
)
169 my_index
= random() % space_get_count(space
);
170 } while (space_get_item(space
, my_index
) == teleport
);
172 return (teleport_t
*) space_get_item(space
, my_index
);
175 static int getRandomPosition()
177 switch (random() % 4) {
191 fatal("Generated a random number which is not in range 0 to 3");
193 return -1; /* no warnings */
196 static void teleportTux(tux_t
*tux
, teleport_t
*teleport
)
198 teleport_t
*distTeleport
;
200 if (tux
->bonus
== BONUS_GHOST
||
201 export_fce
->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT
) {
205 distTeleport
= getRandomTeleportBut(spaceTeleport
, teleport
);
207 fce_move_tux(tux
, distTeleport
->x
, distTeleport
->y
, distTeleport
->w
, distTeleport
->h
);
210 static void moveShotFromTeleport(shot_t
*shot
, teleport_t
*teleport
, space_t
*space
)
212 teleport_t
*distTeleport
;
214 distTeleport
= getRandomTeleportBut(space
, teleport
);
216 fce_move_shot(shot
, getRandomPosition(), teleport
->x
, teleport
->y
,
217 distTeleport
->x
, distTeleport
->y
, distTeleport
->w
,
221 static int init(export_fce_t
*p
)
225 listTeleport
= list_new();
227 if (export_fce
->fce_module_load_dep("libmodMove") != 0) {
231 if ((fce_move_tux
= export_fce
->fce_share_function_get("move_tux")) == NULL
) {
235 if ((fce_move_shot
= export_fce
->fce_share_function_get("move_shot")) == NULL
) {
242 #ifndef PUBLIC_SERVER
243 static void action_drawteleport(space_t
*space
, teleport_t
*teleport
, void *p
)
248 drawTeleport(teleport
);
251 static int draw(int x
, int y
, int w
, int h
)
253 if (spaceTeleport
== NULL
) {
257 space_action_from_location(spaceTeleport
, action_drawteleport
, NULL
, x
, y
, w
, h
);
263 static void action_eventteleportshot(space_t
*space
, teleport_t
*teleport
, shot_t
*shot
)
270 arena
= export_fce
->fce_arena_get_current();
272 author
= space_get_object_id(arena
->spaceTux
, shot
->author_id
);
274 if (author
!= NULL
&& author
->bonus
== BONUS_GHOST
&& author
->bonus_time
> 0) {
278 moveShotFromTeleport(shot
, teleport
, spaceTeleport
);
281 static void action_eventshot(space_t
*space
, shot_t
*shot
, space_t
*p_spaceTeleport
)
285 space_action_from_location(p_spaceTeleport
, action_eventteleportshot
,
286 shot
, shot
->x
, shot
->y
, shot
->w
, shot
->h
);
289 static void action_eventteleporttux(space_t
*space
, teleport_t
*teleport
, tux_t
*tux
)
293 teleportTux(tux
, teleport
);
296 static void action_eventtux(space_t
*space
, tux_t
*tux
, space_t
*p_spaceTeleport
)
302 export_fce
->fce_tux_get_proportion(tux
, &x
, &y
, &w
, &h
);
304 space_action_from_location(p_spaceTeleport
, action_eventteleporttux
, tux
, x
, y
, w
, h
);
309 if (spaceTeleport
== NULL
) {
313 if (export_fce
->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT
) {
317 space_action(export_fce
->fce_arena_get_current()->spaceShot
, action_eventshot
, spaceTeleport
);
318 space_action(export_fce
->fce_arena_get_current()->spaceTux
, action_eventtux
, spaceTeleport
);
323 static int isConflict(int x
, int y
, int w
, int h
)
330 if (spaceTeleport
== NULL
) {
337 static void cmdArena(char *line
)
339 if (strncmp(line
, "teleport", 8) == 0) {
344 static void recvMsg(char *msg
)
351 space_destroy_with_item(spaceTeleport
, destroyTeleport
);
352 spaceTeleport
= NULL
;
354 list_destroy(listTeleport
);
360 mod_sym_t modteleport_sym
= { &init
,
361 #ifndef PUBLIC_SERVER