diff options
| author | Connor Thomson <blumatrikz@gmail.com> | 2026-09-08 18:27:39 -0700 |
|---|---|---|
| committer | Connor Thomson <blumatrikz@gmail.com> | 2026-09-08 18:27:39 -0700 |
| commit | f1ddc12b68b4e4c8087962de25260470e6df2bea (patch) | |
| tree | 7d0440a6402a9b0ef75ded23fa64b68534255bba /src/modules | |
| parent | 6025860a61386bf767b29c3ec5fd0d31285f1056 (diff) | |
Add tuxanci2 files
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/CMakeLists.txt | 32 | ||||
| -rw-r--r-- | src/modules/modAI.c | 410 | ||||
| -rw-r--r-- | src/modules/modBasic.c | 84 | ||||
| -rw-r--r-- | src/modules/modMove.c | 269 | ||||
| -rw-r--r-- | src/modules/modPipe.c | 335 | ||||
| -rw-r--r-- | src/modules/modTeleport.c | 343 | ||||
| -rw-r--r-- | src/modules/modWall.c | 336 |
7 files changed, 0 insertions, 1809 deletions
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt deleted file mode 100644 index 50b3c79..0000000 --- a/src/modules/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################### -# tuxanci/src/modules/CMakeLists.txt -############################################################################### -############################################################################### -# SOURCE SPECIFICATION -############################################################################### -INCLUDE_DIRECTORIES ( ${CMAKE_BINARY_DIR}/src/base/ ) -IF ( BUILD_SERVER ) - SET ( SRC_base_modules - ${WORKDIR}/server/publicServer.h - ) -ELSE ( BUILD_SERVER ) - SET ( SRC_base_modules - ${WORKDIR}/client/interface.h ${WORKDIR}/client/image.h - ) -ENDIF ( BUILD_SERVER ) -SET ( SRC_base_modules - ${SRC_base_modules} - ${WORKDIR}/base/main.h ${WORKDIR}/base/modules.h - ${WORKDIR}/base/shot.h ${WORKDIR}/base/tux.h - ${WORKDIR}/base/list ${WORKDIR}/base/gun.h - ${WORKDIR}/base/space ${WORKDIR}/base/index -) -############################################################################### -# COMPILATION AND INSTALLATION ITSELF -############################################################################### -FILE ( GLOB _lib_files mod*.c ) -FOREACH ( _current_LIB_FILE ${_lib_files} ) - GET_FILENAME_COMPONENT( _lib ${_current_LIB_FILE} NAME_WE ) - ADD_LIBRARY ( ${_lib} STATIC ${SRC_base_modules} ${_current_LIB_FILE} ) -ENDFOREACH ( _current_LIB_FILE ) -############################################################################### diff --git a/src/modules/modAI.c b/src/modules/modAI.c deleted file mode 100644 index c7d2c02..0000000 --- a/src/modules/modAI.c +++ /dev/null @@ -1,410 +0,0 @@ -#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 "list.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 */ - -static export_fce_t *export_fce; - -typedef struct alternative_struct { - int first; - int route; - int step; - int x, y; -} alternative_t; - -static alternative_t *newAlternative(int route, int x, int y) -{ - alternative_t *new; - - new = malloc(sizeof(alternative_t)); - new->first = route; - new->route = route; - new->x = x; - new->y = y; - new->step = 0; - - return new; -} - -static alternative_t *cloneAlternative(alternative_t *p, int route, int x, int y) -{ - alternative_t *new; - - assert(p != NULL); - - new = newAlternative(route, p->x, p->y); - new->first = p->first; - new->step = p->step; - - return new; -} - -static void forkAlternative(list_t *list, alternative_t *p, int w, int h) -{ - int x, y; - - assert(list != NULL); - assert(p != NULL); - - x = p->x; - y = p->y; - - switch (p->route) { - case TUX_UP: - list_add(list, cloneAlternative(p, TUX_RIGHT, x + (w + 5), y)); - list_add(list, cloneAlternative(p, TUX_LEFT, x - (w + 5), y)); - break; - case TUX_RIGHT: - list_add(list, cloneAlternative(p, TUX_UP, x, y - (h + 5))); - list_add(list, cloneAlternative(p, TUX_DOWN, x, y + (h + 5))); - break; - case TUX_LEFT: - list_add(list, cloneAlternative(p, TUX_UP, x, y - (h + 5))); - list_add(list, cloneAlternative(p, TUX_DOWN, x, y + (h + 5))); - break; - case TUX_DOWN: - list_add(list, cloneAlternative(p, TUX_RIGHT, x + (w + 5), y)); - list_add(list, cloneAlternative(p, TUX_LEFT, x - (w + 5), y)); - break; - } - -} - -static void moveAlternative(alternative_t *p, int offset) -{ - assert(p != NULL); - - p->step++; - - /*printf("move %d %d %d\n", p->x, p->y, p->step);*/ - - switch (p->route) { - case TUX_UP: - p->y -= offset; - break; - case TUX_RIGHT: - p->x += offset; - break; - case TUX_LEFT: - p->x -= offset; - break; - case TUX_DOWN: - p->y += offset; - break; - } -} - -static void destroyAlternative(alternative_t *p) -{ - assert(p != NULL); - free(p); -} - -static void cmd_ai(char *line) -{ -} - -static int init(export_fce_t *p) -{ - export_fce = p; - - return 0; -} - -#ifndef PUBLIC_SERVER -static int draw(int x, int y, int w, int h) -{ - return 0; -} -#endif /* PUBLIC_SERVER */ - -static tux_t *findOtherTux(space_t *space) -{ - int i; - - for (i = 0; i < space_get_count(space); i++) { - tux_t *thisTux; - - thisTux = space_get_item(space, i); - - if (thisTux->control != TUX_CONTROL_AI) { - return thisTux; - } - } - - return NULL; -} - -static void shotTux(arena_t *arena, tux_t *tux_ai, tux_t *tux_rival) -{ - const int limit = 20; - int x_ai, y_ai; - int x_rival, y_rival; - int w, h; - - export_fce->fce_tux_get_proportion(tux_ai, &x_ai, &y_ai, &w, &h); - export_fce->fce_tux_get_proportion(tux_rival, &x_rival, &y_rival, &w, &h); - - if (y_rival < y_ai && x_rival > x_ai && x_rival < x_ai + limit) { - export_fce->fce_tux_action(tux_ai, TUX_UP); - export_fce->fce_tux_action(tux_ai, TUX_SHOT); - } - - if (x_rival > x_ai && y_rival > y_ai && y_rival < y_ai + limit) { - export_fce->fce_tux_action(tux_ai, TUX_RIGHT); - export_fce->fce_tux_action(tux_ai, TUX_SHOT); - } - - if (x_rival < x_ai && y_rival > y_ai && y_rival < y_ai + limit) { - export_fce->fce_tux_action(tux_ai, TUX_LEFT); - export_fce->fce_tux_action(tux_ai, TUX_SHOT); - } - - if (y_rival > y_ai && x_rival > x_ai && x_rival < x_ai + limit) { - export_fce->fce_tux_action(tux_ai, TUX_DOWN); - export_fce->fce_tux_action(tux_ai, TUX_SHOT); - } -} - -static void tux_eventAI(tux_t *tux) -{ - arena_t *arena; - tux_t *rivalTux; - - list_t *listAlternative; - list_t *listDst; - list_t *listFork; - - int x, y, w, h; - int rival_x, rival_y; - int i, my_index; - - int countFork = 0; - int countDel = 0; - int countLimit = 0; - int countDo = 0; - - export_fce->fce_tux_get_proportion(tux, &x, &y, &w, &h); - /*printf("tux AI %d %d\n", x, y);*/ - - arena = export_fce->fce_arena_get_current(); - - rivalTux = findOtherTux(arena->spaceTux); - - if (rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE) { - return; - } - - listAlternative = list_new(); - listDst = list_new(); - listFork = list_new(); - - shotTux(arena, tux, rivalTux); - - export_fce->fce_tux_get_proportion(rivalTux, &rival_x, &rival_y, NULL, NULL); - /*printf("tux rival %d %d\n", rival_x, rival_y);*/ - - list_add(listAlternative, newAlternative(TUX_UP, x, y - (h + 10))); - list_add(listAlternative, newAlternative(TUX_RIGHT, x + (w + 10), y)); - list_add(listAlternative, newAlternative(TUX_LEFT, x - (w + 10), y)); - list_add(listAlternative, newAlternative(TUX_DOWN, x, y + (h + 10))); - - my_index = -1; - for (;;) { - alternative_t *this; - - my_index++; - if (my_index < 0 || my_index >= listAlternative->count) { - int j; - - /*printf("listFork->count = %d\n", listFork->count);*/ - - for (j = 0; j < listFork->count; j++) { - list_add(listAlternative, listFork->list[j]); - } - - list_do_empty(listFork); - - my_index = 0; - } - - if (listAlternative->count == 0) { - break; - } - - this = (alternative_t *) listAlternative->list[my_index]; - - if (++countDo == 100) { - break; - } - - if (this->step > 100) { - list_del_item(listAlternative, my_index, destroyAlternative); - countLimit++; - my_index--; - continue; - } - - moveAlternative(this, w * 2); - - if (export_fce->fce_arena_is_free_space(arena, this->x, this->y, w, h) == 1) { - forkAlternative(listFork, this, 2 * w, 2 * h); - countFork++; - continue; - } - - if (export_fce->fce_arena_conflict_space(this->x, this->y, w, h, - rival_x, rival_y, w, h)) { - /*printf("this->step = %d\n", this->step);*/ - - list_del(listAlternative, my_index); - list_add(listDst, this); - my_index--; - /*continue;*/ - break; - } - - if (export_fce->fce_arena_is_free_space(arena, this->x, this->y, w, h) == 0) { - /*forkAlternative(listFork, this, w*2, h*2);*/ - list_del_item(listAlternative, my_index, destroyAlternative); - my_index--; - countDel++; - - continue; - } - - } - - int minStep = 1000; - int recRoute = 0; - - /*printf("------------\n");*/ - for (i = 0; i < listDst->count; i++) { - alternative_t *this; - - this = (alternative_t *) listDst->list[i]; - - /*printf("XXX step %d route = %d\n", this->step, this->first);*/ - if (this->step < minStep) { - minStep = this->step; - recRoute = this->first; - } - } - - if (recRoute != 0) { - export_fce->fce_tux_action(tux, recRoute); - } - - list_destroy_item(listFork, destroyAlternative); - list_destroy_item(listAlternative, destroyAlternative); - list_destroy_item(listDst, destroyAlternative); -/* - printf("countFork = %d\n", countFork); - printf("countDel = %d\n", countDel); - printf("countLimit = %d\n", countLimit); - printf("countDo = %d\n", countDo); -*/ -} - -static void action_tuxAI(space_t *space, tux_t *tux, void *p) -{ - if (tux->control == TUX_CONTROL_AI && tux->status == TUX_STATUS_ALIVE) { - tux_eventAI(tux); - } -} - -static int event() -{ - static my_time_t lastEvent = 0; - my_time_t curentTime; - arena_t *arena; - int countTuxAI; - /*int i;*/ - - if (lastEvent == 0) { - lastEvent = export_fce->fce_timer_get_current_time(); - } - - curentTime = export_fce->fce_timer_get_current_time(); - - if (curentTime - lastEvent < 25) { - return 0; - } - - lastEvent = export_fce->fce_timer_get_current_time(); - /*printf("event AI\n");*/ - - arena = export_fce->fce_arena_get_current(); - - if (arena == NULL) { - return 0; - } - - countTuxAI = 0; - - space_action(arena->spaceTux, action_tuxAI, NULL); -/* - for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) - { - tux_t *thisTux; - - thisTux = arena->spaceTux->list->list[i]; - - if( thisTux->control == TUX_CONTROL_AI && - thisTux->status == TUX_STATUS_ALIVE ) - { - tux_event(thisTux); - countTuxAI = 0; - } - } -*/ - return 0; -} - -static int isConflict(int x, int y, int w, int h) -{ - return 0; -} - -static void cmdArena(char *line) -{ - if (strncmp(line, "ai", 2) == 0) { - cmd_ai(line); - } -} - -static void recvMsg(char *msg) -{ -} - -static int destroy() -{ - return 0; -} - -mod_sym_t modai_sym = { &init, -#ifndef PUBLIC_SERVER - &draw, -#else /* PUBLIC_SERVER */ - 0, -#endif /* PUBLIC_SERVER */ - &event, - &isConflict, - &cmdArena, - &recvMsg, - &destroy }; diff --git a/src/modules/modBasic.c b/src/modules/modBasic.c deleted file mode 100644 index 8494916..0000000 --- a/src/modules/modBasic.c +++ /dev/null @@ -1,84 +0,0 @@ -#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 "list.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 */ - -static export_fce_t *export_fce; - -static int init(export_fce_t *p) -{ - export_fce = p; - - debug("Initializing Basic module"); - return 0; -} - -#ifndef PUBLIC_SERVER -static int draw(int x, int y, int w, int h) -{ - debug("Drawing Basic module"); - return 0; -} -#endif /* PUBLIC_SERVER */ - -static int event() -{ - debug("Basic module catch event"); - return 0; -} - -static int isConflict(int x, int y, int w, int h) -{ - debug("isConflict(%d, %d, %d, %d) in Basic module", x, y, w, h); - return 0; -} - -static void cmd_basic(char *line) -{ - debug("cmd_basic(%s) in Basic module", line); -} - -static void cmdArena(char *line) -{ - if (strncmp(line, "basic", 5) == 0) { - cmd_basic(line); - } -} - -static void recvMsg(char *msg) -{ - debug("recvMsg(%s) in Basic module", msg); -} - -static int destroy() -{ - debug("Destroying Basic module"); - return 0; -} - -mod_sym_t modbasic_sym = { &init, -#ifndef PUBLIC_SERVER - &draw, -#else /* PUBLIC_SERVER */ - 0, -#endif /* PUBLIC_SERVER */ - &event, - &isConflict, - &cmdArena, - &recvMsg, - &destroy }; diff --git a/src/modules/modMove.c b/src/modules/modMove.c deleted file mode 100644 index 9774170..0000000 --- a/src/modules/modMove.c +++ /dev/null @@ -1,269 +0,0 @@ -#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 "list.h" -#include "gun.h" -#include "space.h" -#include "serverSendMsg.h" - -#ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#else /* PUBLIC_SERVER */ -#include "publicServer.h" -#endif /* PUBLIC_SERVER */ - -static export_fce_t *export_fce; - -static void move_tux(tux_t *tux, int x, int y, int w, int h) -{ - int dist_x = 0, dist_y = 0; - - if (tux->bonus == BONUS_GHOST || export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { - return; - } - - switch (tux->position) { - case TUX_UP: - dist_x = x + w / 2; - dist_y = y - (TUX_HEIGHT + 20); - break; - case TUX_LEFT: - dist_x = x - (TUX_WIDTH + 20); - dist_y = y + h / 2; - break; - case TUX_RIGHT: - dist_x = x + w + 20; - dist_y = y + h / 2; - break; - case TUX_DOWN: - dist_x = x + w / 2; - dist_y = y + h + 20; - break; - default: - fatal("Variable tux->position in modMove has an undefined value [%d]", tux->position); - break; - } - - if (export_fce->fce_arena_is_free_space(export_fce->fce_arena_get_current(), dist_x, dist_y, TUX_WIDTH, TUX_HEIGHT)) { - space_move_object(export_fce->fce_arena_get_current()->spaceTux, tux, dist_x, dist_y); -#ifndef PUBLIC_SERVER - /*sound_play("teleport", SOUND_GROUP_BASE);*/ -#endif /* PUBLIC_SERVER */ - if (export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { - char msg[STR_PROTO_SIZE]; - sprintf(msg, "movetux %d %d %d", tux->id, dist_x, dist_y); - if (tux->bonus == BONUS_HIDDEN) { - export_fce->fce_proto_send_module_server(PROTO_SEND_ONE, (client_t *) tux->client, msg); - } else { - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); - } - } - } -} - -static int myAbs(int n) -{ - return (n > 0 ? n : -n); -} - - -static int getSppedShot(shot_t *shot) -{ - return (myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py)); -} - -static void transformShot(shot_t *shot, int position) -{ - int speed; - - speed = getSppedShot(shot); - switch (position) { - case TUX_UP: - shot->px = 0; - shot->py = -speed; - break; - case TUX_LEFT: - shot->px = -speed; - shot->py = 0; - break; - case TUX_RIGHT: - shot->px = +speed; - shot->py = 0; - break; - case TUX_DOWN: - shot->px = 0; - shot->py = +speed; - break; - } - - shot->position = position; - shot->isCanKillAuthor = TRUE; - - if (shot->gun == GUN_LASSER) { - export_fce->fce_shot_transform_lasser(shot); - } -} - -static void move_shot(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h) -{ - int offset = 0; - int new_x = 0, new_y = 0; - - switch (shot->position) { - case TUX_UP: - case TUX_DOWN: - offset = shot->x - src_x; - break; - - case TUX_RIGHT: - case TUX_LEFT: - offset = shot->y - src_y; - break; - } - - transformShot(shot, position); - - switch (shot->position) { - case TUX_UP: - new_x = dist_x + offset; - new_y = dist_y - (shot->h + 5); - break; - case TUX_LEFT: - new_x = dist_x - (shot->w + 5); - new_y = dist_y + offset; - break; - case TUX_RIGHT: - new_x = dist_x + dist_w + 5; - new_y = dist_y + offset; - break; - case TUX_DOWN: - new_x = dist_x + offset; - new_y = dist_y + dist_h + 5; - break; - } - - space_move_object(export_fce->fce_arena_get_current()->spaceShot, shot, new_x, new_y); - if (export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { - char msg[STR_PROTO_SIZE]; - - sprintf(msg, "moveshot %d %d %d %d %d %d", shot->id, - shot->x, shot->y, shot->px, shot->py, shot->position); - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); - } -} - -static int init(export_fce_t *p) -{ - export_fce = p; - export_fce->fce_share_function_add("move_tux", (void *) move_tux); - export_fce->fce_share_function_add("move_shot", (void *) move_shot); - - return 0; -} - -static void proto_movetux(char *msg) -{ - char cmd[STR_PROTO_SIZE]; - int id, x, y; - space_t *space; - tux_t *tux; - - assert(msg != NULL); - - sscanf(msg, "%s %d %d %d", cmd, &id, &x, &y); - space = export_fce->fce_arena_get_current()->spaceTux; - tux = space_get_object_id(space, id); - - if (tux != NULL) { - space_move_object(space, tux, x, y); - } -} - -static void proto_moveshot(char *msg) -{ - char cmd[STR_PROTO_SIZE]; - int shot_id, x, y, px, py, position; - space_t *space; - shot_t *shot; - - assert(msg != NULL); - - sscanf(msg, "%s %d %d %d %d %d %d", cmd, &shot_id, &x, &y, &px, &py, &position); - - space = export_fce->fce_arena_get_current()->spaceShot; - - if ((shot = space_get_object_id(space, shot_id)) == NULL) { - return; - } - - space_move_object(space, shot, x, y); - shot->isCanKillAuthor = 1; - shot->position = position; - shot->px = px; - shot->py = py; - - if (shot->gun == GUN_LASSER) { - export_fce->fce_shot_transform_lasser(shot); - } -} - -#ifndef PUBLIC_SERVER -static int draw(int x, int y, int w, int h) -{ - return 0; -} -#endif /* PUBLIC_SERVER */ - -static int event() -{ - return 0; -} - -static int isConflict(int x, int y, int w, int h) -{ - return 0; -} - -static void cmdArena(char *line) -{ -} - -static void recvMsg(char *msg) -{ - if (export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { - return; - } - - if (strncmp(msg, "movetux", 7) == 0) { - proto_movetux(msg); - } - - if (strncmp(msg, "moveshot", 8) == 0) { - proto_moveshot(msg); - } -} - -static int destroy() -{ - return 0; -} - -mod_sym_t modmove_sym = { &init, -#ifndef PUBLIC_SERVER - &draw, -#else /* PUBLIC_SERVER */ - 0, -#endif /* PUBLIC_SERVER */ - &event, - &isConflict, - &cmdArena, - &recvMsg, - &destroy }; diff --git a/src/modules/modPipe.c b/src/modules/modPipe.c deleted file mode 100644 index 9319fe0..0000000 --- a/src/modules/modPipe.c +++ /dev/null @@ -1,335 +0,0 @@ -#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 "list.h" -#include "gun.h" -#include "space.h" -#include "proto.h" -#include "serverSendMsg.h" - -#ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#else /* PUBLIC_SERVER */ -#include "publicServer.h" -#endif /* PUBLIC_SERVER */ - -typedef struct pipe_struct { - /* position of the pipe */ - int x; - int y; - - /* size of the pipe */ - int w; - int h; - - int id; - int id_out; - int position; - - /* layer in the arena where the pipe lies */ - int layer; - -#ifndef PUBLIC_SERVER - /* its image */ - image_t *img; -#endif /* PUBLIC_SERVER */ -} pipe_t; - -static void (*fce_move_shot) (shot_t *shot, int position, int src_x, int src_y, int dist_x, int dist_y, int dist_w, int dist_h); - -static export_fce_t *export_fce; - -static list_t *listPipe; -static space_t *spacePipe; - -#ifndef PUBLIC_SERVER -static pipe_t *newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, image_t *img) -#else /* PUBLIC_SERVER */ -static pipe_t *newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position) -#endif /* PUBLIC_SERVER */ -{ - pipe_t *new; - -#ifndef PUBLIC_SERVER - assert(img != NULL); -#endif /* PUBLIC_SERVER */ - - new = malloc(sizeof(pipe_t)); - assert(new != NULL); - - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->layer = layer; - new->id = id; - new->id_out = id_out; - new->position = position; -#ifndef PUBLIC_SERVER - new->img = img; -#endif /* PUBLIC_SERVER */ - return new; -} - -static void setStatusPipe(void *p, int x, int y, int w, int h) -{ - pipe_t *pipe; - - pipe = p; - - pipe->x = x; - pipe->y = y; - pipe->w = w; - pipe->h = h; -} - -static void getStatusPipe(void *p, int *id, int *x, int *y, int *w, int *h) -{ - pipe_t *pipe; - - pipe = p; - - *id = pipe->id; - *x = pipe->x; - *y = pipe->y; - *w = pipe->w; - *h = pipe->h; -} - -#ifndef PUBLIC_SERVER -static void drawPipe(pipe_t *p) -{ - assert(p != NULL); - - export_fce->fce_addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer); -} -#endif /* PUBLIC_SERVER */ - -static void destroyPipe(pipe_t *p) -{ - assert(p != NULL); - free(p); -} - -static void cmd_teleport(char *line) -{ - char str_x[STR_NUM_SIZE]; - char str_y[STR_NUM_SIZE]; - char str_w[STR_NUM_SIZE]; - char str_h[STR_NUM_SIZE]; - char str_id[STR_NUM_SIZE]; - char str_id_out[STR_NUM_SIZE]; - char str_position[STR_NUM_SIZE]; - char str_layer[STR_NUM_SIZE]; - char str_image[STR_SIZE]; - pipe_t *new; - - 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, "id", str_id, STR_NUM_SIZE) != 0 || - export_fce->fce_getValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 || - export_fce->fce_getValue(line, "position", str_position, 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; - } - -#ifndef PUBLIC_SERVER - new = newPipe(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer), atoi(str_id), atoi(str_id_out), - atoi(str_position), - export_fce->fce_image_get(IMAGE_GROUP_USER, str_image)); -#else /* PUBLIC_SERVER */ - new = newPipe(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer), atoi(str_id), atoi(str_id_out), - atoi(str_position)); -#endif /* PUBLIC_SERVER */ - - if (spacePipe == NULL) { - spacePipe = space_new(export_fce->fce_arena_get_current()->w, - export_fce->fce_arena_get_current()->h, 320, 240, - getStatusPipe, setStatusPipe); - } - - space_add(spacePipe, new); -} - -static void moveShotFromPipe(shot_t *shot, pipe_t *pipe) -{ - pipe_t *distPipe; - - distPipe = space_get_object_id(spacePipe, pipe->id_out); - - if (distPipe == NULL) { - error("Pipe ID was not found [%d]", pipe->id); - return; - } - - fce_move_shot(shot, distPipe->position, pipe->x, pipe->y, distPipe->x, distPipe->y, distPipe->w, distPipe->h); -} - -static int init(export_fce_t *p) -{ - export_fce = p; - - listPipe = list_new(); - - if (export_fce->fce_module_load_dep("libmodMove") != 0) { - return -1; - } - - if ((fce_move_shot = export_fce->fce_share_function_get("move_shot")) == NULL) { - return -1; - } - - return 0; -} - -#ifndef PUBLIC_SERVER -static void action_drawpipe(space_t *space, pipe_t *pipe, void *p) -{ - drawPipe(pipe); -} - -static int draw(int x, int y, int w, int h) -{ - if (spacePipe == NULL) { - return 0; - } - - space_action_from_location(spacePipe, action_drawpipe, NULL, x, y, w, h); - /*space_print(spacePipe);*/ - - return 0; -} -#endif /* PUBLIC_SERVER */ - -static int negPosition(int n) -{ - switch (n) { - case TUX_UP: - return TUX_DOWN; - - case TUX_LEFT: - return TUX_RIGHT; - - case TUX_RIGHT: - return TUX_LEFT; - - case TUX_DOWN: - return TUX_UP; - - default: - fatal("Tux is probably moving in another dimension"); - break; - } - - return -1; -} - -static void action_eventpipe(space_t *space, pipe_t *pipe, 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 (negPosition(shot->position) == pipe->position) { - moveShotFromPipe(shot, pipe); - } else { - if (shot->gun == GUN_BOMBBALL) { - export_fce->fce_shot_bound_bombBall(shot); - } else { - shot->del = TRUE; - } - } -} - -static void action_eventshot(space_t *space, shot_t *shot, space_t *p_spacePipe) -{ - space_action_from_location(p_spacePipe, action_eventpipe, shot, shot->x, shot->y, shot->w, shot->h); - - if (shot->del == TRUE) { - if (export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { - export_fce->fce_proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); - } - - space_del_with_item(space, shot, export_fce->fce_shot_destroy); - } -} - -static int event() -{ - if (spacePipe == NULL) { - return 0; - } - - /* just for a test */ - if (export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { - return 0; - } - - space_action(export_fce->fce_arena_get_current()->spaceShot, action_eventshot, spacePipe); - - return 0; -} - -static int isConflict(int x, int y, int w, int h) -{ - if (spacePipe == NULL) { - return 0; - } - - return space_is_conflict_with_object(spacePipe, x, y, w, h); -} - -static void cmdArena(char *line) -{ - if (strncmp(line, "pipe", 4) == 0) { - cmd_teleport(line); - } -} - -static void recvMsg(char *msg) -{ -} - -static int destroy() -{ - space_destroy_with_item(spacePipe, destroyPipe); - spacePipe = NULL; - - list_destroy(listPipe); - listPipe = NULL; - - return 0; -} - -mod_sym_t modpipe_sym = { &init, -#ifndef PUBLIC_SERVER - &draw, -#else /* PUBLIC_SERVER */ - 0, -#endif /* PUBLIC_SERVER */ - &event, - &isConflict, - &cmdArena, - &recvMsg, - &destroy }; diff --git a/src/modules/modTeleport.c b/src/modules/modTeleport.c deleted file mode 100644 index c8cf573..0000000 --- a/src/modules/modTeleport.c +++ /dev/null @@ -1,343 +0,0 @@ -#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 "list.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 teleport_struct { - int id; - - /* position of the teleport */ - int x; - int y; - - /* size of the teleport */ - int w; - int h; - - /* layer in the arena where the teleport lies */ - int layer; - -#ifndef PUBLIC_SERVER - /* its image */ - image_t *img; -#endif /* PUBLIC_SERVER */ -} teleport_t; - -static export_fce_t *export_fce; - -static space_t *spaceTeleport; -static list_t *listTeleport; - -static void (*fce_move_tux) (tux_t *tux, int x, int y, int w, int h); -static void (*fce_move_shot) (shot_t *shot, int position, int src_x, - int src_y, int dist_x, int dist_y, int dist_w, - int dist_h); - -#ifndef PUBLIC_SERVER -static teleport_t *newTeleport(int x, int y, int w, int h, int layer, image_t *img) -#else /* PUBLIC_SERVER */ -static teleport_t *newTeleport(int x, int y, int w, int h, int layer) -#endif /* PUBLIC_SERVER */ -{ - static int last_id = 0; - - teleport_t *new; - -#ifndef PUBLIC_SERVER - assert(img != NULL); -#endif /* PUBLIC_SERVER */ - - new = malloc(sizeof(teleport_t)); - assert(new != NULL); - - new->id = ++last_id; - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->layer = layer; -#ifndef PUBLIC_SERVER - new->img = img; -#endif /* PUBLIC_SERVER */ - - return new; -} - -static void setStatusTeleport(void *p, int x, int y, int w, int h) -{ - teleport_t *teleport; - - teleport = p; - - teleport->x = x; - teleport->y = y; - teleport->w = w; - teleport->h = h; -} - -static void getStatusTeleport(void *p, int *id, int *x, int *y, int *w, int *h) -{ - teleport_t *teleport; - teleport = p; - - *id = teleport->id; - *x = teleport->x; - *y = teleport->y; - *w = teleport->w; - *h = teleport->h; -} - -#ifndef PUBLIC_SERVER -static void drawTeleport(teleport_t *p) -{ - assert(p != NULL); - - export_fce->fce_addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer); -} -#endif /* PUBLIC_SERVER */ - -static void destroyTeleport(teleport_t *p) -{ - assert(p != NULL); - free(p); -} - -static void cmd_teleport(char *line) -{ - char str_x[STR_NUM_SIZE]; - char str_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]; - teleport_t *new; - - 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, "layer", str_layer, STR_NUM_SIZE) != 0 || - export_fce->fce_getValue(line, "image", str_image, STR_SIZE) != 0) { - return; - } - -#ifndef PUBLIC_SERVER - new = newTeleport(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer), - export_fce->fce_image_get(IMAGE_GROUP_USER, str_image)); -#else /* PUBLIC_SERVER */ - new = newTeleport(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer)); -#endif /* PUBLIC_SERVER */ - - if (spaceTeleport == NULL) { - spaceTeleport = space_new(export_fce->fce_arena_get_current()->w, - export_fce->fce_arena_get_current()->h, - 320, 240, - getStatusTeleport, setStatusTeleport); - } - - space_add(spaceTeleport, new); -} - -static teleport_t *getRandomTeleportBut(space_t *space, teleport_t *teleport) -{ - int my_index; - - do { - my_index = random() % space_get_count(space); - } while (space_get_item(space, my_index) == teleport); - - return (teleport_t *) space_get_item(space, my_index); -} - -static int getRandomPosition() -{ - switch (random() % 4) { - case 0: - return TUX_UP; - - case 1: - return TUX_LEFT; - - case 2: - return TUX_RIGHT; - - case 3: - return TUX_DOWN; - } - - fatal("Generated a random number which is not in range 0 to 3"); - - return -1; -} - -static void teleportTux(tux_t *tux, teleport_t *teleport) -{ - teleport_t *distTeleport; - - if (tux->bonus == BONUS_GHOST || - export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { - return; - } - - distTeleport = getRandomTeleportBut(spaceTeleport, teleport); - - fce_move_tux(tux, distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); -} - -static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, space_t *space) -{ - teleport_t *distTeleport; - - distTeleport = getRandomTeleportBut(space, teleport); - - fce_move_shot(shot, getRandomPosition(), teleport->x, teleport->y, - distTeleport->x, distTeleport->y, distTeleport->w, - distTeleport->h); -} - -static int init(export_fce_t *p) -{ - export_fce = p; - - listTeleport = list_new(); - - if (export_fce->fce_module_load_dep("libmodMove") != 0 || - (fce_move_tux = export_fce->fce_share_function_get("move_tux")) == NULL || - (fce_move_shot = export_fce->fce_share_function_get("move_shot")) == NULL) { - return -1; - } - - return 0; -} - -#ifndef PUBLIC_SERVER -static void action_drawteleport(space_t *space, teleport_t *teleport, void *p) -{ - drawTeleport(teleport); -} - -static int draw(int x, int y, int w, int h) -{ - if (spaceTeleport == NULL) { - return 0; - } - - space_action_from_location(spaceTeleport, action_drawteleport, NULL, x, y, w, h); - - return 0; -} -#endif /* PUBLIC_SERVER */ - -static void action_eventteleportshot(space_t *space, teleport_t *teleport, 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; - } - - moveShotFromTeleport(shot, teleport, spaceTeleport); -} - -static void action_eventshot(space_t *space, shot_t *shot, space_t *p_spaceTeleport) -{ - space_action_from_location(p_spaceTeleport, action_eventteleportshot, - shot, shot->x, shot->y, shot->w, shot->h); -} - -static void action_eventteleporttux(space_t *space, teleport_t *teleport, tux_t *tux) -{ - teleportTux(tux, teleport); -} - -static void action_eventtux(space_t *space, tux_t *tux, space_t *p_spaceTeleport) -{ - int x, y, w, h; - - export_fce->fce_tux_get_proportion(tux, &x, &y, &w, &h); - - space_action_from_location(p_spaceTeleport, action_eventteleporttux, tux, x, y, w, h); -} - -static int event() -{ - if (spaceTeleport == NULL) { - return 0; - } - - if (export_fce->fce_net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { - return 0; - } - - space_action(export_fce->fce_arena_get_current()->spaceShot, action_eventshot, spaceTeleport); - space_action(export_fce->fce_arena_get_current()->spaceTux, action_eventtux, spaceTeleport); - - return 0; -} - -static int isConflict(int x, int y, int w, int h) -{ - if (spaceTeleport == NULL) { - return 0; - } - - return 0; -} - -static void cmdArena(char *line) -{ - if (strncmp(line, "teleport", 8) == 0) { - cmd_teleport(line); - } -} - -static void recvMsg(char *msg) -{ -} - -static int destroy() -{ - space_destroy_with_item(spaceTeleport, destroyTeleport); - spaceTeleport = NULL; - - list_destroy(listTeleport); - listTeleport = NULL; - - return 0; -} - -mod_sym_t modteleport_sym = { &init, -#ifndef PUBLIC_SERVER - &draw, -#else /* PUBLIC_SERVER */ - 0, -#endif /* PUBLIC_SERVER */ - &event, - &isConflict, - &cmdArena, - &recvMsg, - &destroy }; diff --git a/src/modules/modWall.c b/src/modules/modWall.c deleted file mode 100644 index 7a1fa7a..0000000 --- a/src/modules/modWall.c +++ /dev/null @@ -1,336 +0,0 @@ -#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 }; |