diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-28 16:33:48 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-28 16:33:48 +0000 |
| commit | 554234f4f238305ee82504bdbb51096efaea74f0 (patch) | |
| tree | d3ca5826ff970de0abbcb96a370a8adcac80744d /src/modules | |
| parent | f1fca3a63e37866dbcc84ffbf5927697fc60c263 (diff) | |
- moduly si medzi sebou mozu exportovat a imporotvat funkcie
- na premiestnovanie striel a tuxov v moduloch modPipe a modTetelport sa pouzivaju funkcie z modulu modMove
- uhladeny kod v module.c ;)
git-svn-id: http://opensvn.csie.org/tuxanci_ng@176 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/CMakeLists.txt | 7 | ||||
| -rwxr-xr-x | src/modules/modMove.c | 322 | ||||
| -rwxr-xr-x | src/modules/modPipe.c | 162 | ||||
| -rwxr-xr-x | src/modules/modTeleport.c | 238 |
4 files changed, 363 insertions, 366 deletions
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 3f35c09..b2aaf41 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -31,15 +31,22 @@ SET ( SRC_modTeleport ${WORKDIR}/base/index ${WORKDIR}/base/space.c modTeleport.c ) +SET ( SRC_modMove + ${SRC_base_modules} + ${WORKDIR}/base/index ${WORKDIR}/base/space.c + modMove.c +) SET ( SRC_modAI ${SRC_base_modules} modAI.c ) ADD_LIBRARY ( modWall SHARED ${SRC_modWall} ) ADD_LIBRARY ( modPipe SHARED ${SRC_modPipe} ) +ADD_LIBRARY ( modMove SHARED ${SRC_modMove} ) ADD_LIBRARY ( modTeleport SHARED ${SRC_modTeleport} ) ADD_LIBRARY ( modAI SHARED ${SRC_modAI} ) INSTALL ( TARGETS modWall LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${APPNAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) INSTALL ( TARGETS modPipe LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${APPNAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) +INSTALL ( TARGETS modMove LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${APPNAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) INSTALL ( TARGETS modTeleport LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${APPNAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) INSTALL ( TARGETS modAI LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${APPNAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) diff --git a/src/modules/modMove.c b/src/modules/modMove.c new file mode 100755 index 0000000..3b8d09c --- /dev/null +++ b/src/modules/modMove.c @@ -0,0 +1,322 @@ + +#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" +#endif + +#ifdef PUBLIC_SERVER +#include "publicServer.h" +#endif + + +static export_fce_t *export_fce; + +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; + } + + assert( ! "Stupid error ! " ); + + return -1; // no warnning +} + +static void move_tux(tux_t *tux, int x, int y, int w, int h) +{ + int dist_x = 0, dist_y = 0; // no warnning + + //printf("move_tux\n"); + + if( tux->bonus == BONUS_GHOST || + export_fce->fce_getNetTypeGame() == 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 : + assert( ! "premenna p->control ma zlu hodnotu !" ); + break; + } + + if( export_fce->fce_isFreeSpace(export_fce->fce_getCurrentArena(), dist_x, dist_y, TUX_WIDTH, TUX_HEIGHT) ) + { + moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceTux, tux, dist_x, dist_y); + //export_fce->fce_setTuxProportion(tux, dist_x, dist_y); +#ifndef PUBLIC_SERVER + //playSound("teleport", SOUND_GROUP_BASE); +#endif + if( export_fce->fce_getNetTypeGame() == 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); + //export_fce->fce_proto_send_newtux_server(PROTO_SEND_ONE, (client_t *)tux->client, tux); + } + else + { + export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); + //export_fce->fce_proto_send_newtux_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_transformOnlyLasser(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; // no warninng + + //printf("move_shot\n"); + + 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; + } + + moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); + + if( export_fce->fce_getNetTypeGame() == 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); + } +} + +int init(export_fce_t *p) +{ + export_fce = p; + + export_fce->fce_addToExportFce("move_tux", move_tux); + export_fce->fce_addToExportFce("move_shot", 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_getCurrentArena()->spaceTux; + tux = getObjectFromSpaceWithID(space, id); + + if( tux != NULL ) + { + moveObjectInSpace(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_getCurrentArena()->spaceShot; + + if( ( shot = getObjectFromSpaceWithID(space, shot_id) ) == NULL ) + { + return; + } + + moveObjectInSpace(space, shot, x, y); + shot->isCanKillAuthor = 1; + shot->position = position; + shot->px = px; + shot->py = py; + + if( shot->gun == GUN_LASSER ) + { + export_fce->fce_transformOnlyLasser(shot); + } +} + +#ifndef PUBLIC_SERVER + +int draw(int x, int y, int w, int h) +{ + return 0; +} + +#endif + +int event() +{ + return 0; +} + +int isConflict(int x, int y, int w, int h) +{ + return 0; +} + +void cmdArena(char *line) +{ +} + +void recvMsg(char *msg) +{ + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + return; + } + + if( strncmp(msg, "movetux", 7) == 0 )proto_movetux(msg); + if( strncmp(msg, "moveshot", 8) == 0 )proto_moveshot(msg); +} + +int destroy() +{ + return 0; +} diff --git a/src/modules/modPipe.c b/src/modules/modPipe.c index 9c5b443..50db335 100755 --- a/src/modules/modPipe.c +++ b/src/modules/modPipe.c @@ -40,6 +40,9 @@ typedef struct pipe_struct #endif } 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; @@ -165,114 +168,6 @@ static void cmd_teleport(char *line) addObjectToSpace(spacePipe, new); } -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_transformOnlyLasser(shot); - } -} - -static void moveShot(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; // no warninng - - 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; - } - - //new_x += myValueOperator(shot->px) * shot->w; - //new_y += myValueOperator(shot->py) * shot->h; - - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); - - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - char msg[STR_PROTO_SIZE]; - - sprintf(msg, "pipe %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 void moveShotFromPipe(shot_t *shot, pipe_t *pipe) { pipe_t *distPipe; @@ -285,7 +180,7 @@ static void moveShotFromPipe(shot_t *shot, pipe_t *pipe) return; } - moveShot(shot, distPipe->position, pipe->x, pipe->y, + fce_move_shot(shot, distPipe->position, pipe->x, pipe->y, distPipe->x, distPipe->y, distPipe->w, distPipe->h); } @@ -295,6 +190,16 @@ int init(export_fce_t *p) listPipe = newList(); + if( export_fce->fce_loadDepModule("libmodMove") != 0 ) + { + return -1; + } + + if( ( fce_move_shot = export_fce->fce_getExportFce("move_shot") ) == NULL ) + { + return -1; + } + return 0; } @@ -416,48 +321,9 @@ void cmdArena(char *line) if( strncmp(line, "pipe", 4) == 0 )cmd_teleport(line); } -static void proto_pipe(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_getCurrentArena()->spaceShot; - - if( ( shot = getObjectFromSpaceWithID(space, shot_id) ) == NULL ) - { - //delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); - - return; - } - - moveObjectInSpace(space, shot, x, y); - shot->isCanKillAuthor = 1; - shot->position = position; - shot->px = px; - shot->py = py; - - if( shot->gun == GUN_LASSER ) - { - export_fce->fce_transformOnlyLasser(shot); - } -} - void recvMsg(char *msg) { - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - return; - } - if( strncmp(msg, "pipe", 4) == 0 )proto_pipe(msg); } int destroy() diff --git a/src/modules/modTeleport.c b/src/modules/modTeleport.c index 28ebeb6..53b3369 100755 --- a/src/modules/modTeleport.c +++ b/src/modules/modTeleport.c @@ -43,6 +43,10 @@ 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 teleport_t* newTeleport(int x, int y, int w, int h, int layer, image_t *img) #endif @@ -191,7 +195,6 @@ static int getRandomPosition() static void teleportTux(tux_t *tux, teleport_t *teleport) { teleport_t *distTeleport; - int dist_x = 0, dist_y = 0; // no warnning if( tux->bonus == BONUS_GHOST || export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) @@ -200,181 +203,40 @@ static void teleportTux(tux_t *tux, teleport_t *teleport) } distTeleport = getRandomTeleportBut(spaceTeleport->list, teleport); - - switch( tux->position ) - { - case TUX_UP : - dist_x = distTeleport->x + distTeleport->w/2; - dist_y = distTeleport->y - ( TUX_HEIGHT + 20 ); - break; - case TUX_LEFT : - dist_x = distTeleport->x - ( TUX_WIDTH + 20 ); - dist_y = distTeleport->y + distTeleport->h/2; - break; - - case TUX_RIGHT : - dist_x = distTeleport->x + distTeleport->w + 20; - dist_y = distTeleport->y + distTeleport->h/2; - break; - - case TUX_DOWN : - dist_x = distTeleport->x + distTeleport->w/2; - dist_y = distTeleport->y + distTeleport->h + 20; - break; - - default : - assert( ! "premenna p->control ma zlu hodnotu !" ); - break; - } - - if( export_fce->fce_isFreeSpace(export_fce->fce_getCurrentArena(), dist_x, dist_y, TUX_WIDTH, TUX_HEIGHT) ) - { - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceTux, tux, dist_x, dist_y); - //export_fce->fce_setTuxProportion(tux, dist_x, dist_y); -#ifndef PUBLIC_SERVER - //playSound("teleport", SOUND_GROUP_BASE); -#endif - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - char msg[STR_PROTO_SIZE]; - - sprintf(msg, "teleporttux %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); - //export_fce->fce_proto_send_newtux_server(PROTO_SEND_ONE, (client_t *)tux->client, tux); - } - else - { - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); - //export_fce->fce_proto_send_newtux_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) ); + fce_move_tux(tux, distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); } -static void transformShot(shot_t *shot, int position) +static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *list) { - 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; - } + teleport_t *distTeleport; - shot->position = position; - shot->isCanKillAuthor = TRUE; + distTeleport = getRandomTeleportBut(list, teleport); - if( shot->gun == GUN_LASSER ) - { - export_fce->fce_transformOnlyLasser(shot); - } + fce_move_shot(shot, getRandomPosition(), teleport->x, teleport->y, + distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); } -static void moveShot(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h) +int init(export_fce_t *p) { - int offset = 0; - int new_x = 0, new_y = 0; // no warninng + export_fce = p; - switch( shot->position ) + listTeleport = newList(); + + if( export_fce->fce_loadDepModule("libmodMove") != 0 ) { - case TUX_UP : - case TUX_DOWN : - offset = shot->x - src_x; - break; - - case TUX_RIGHT : - case TUX_LEFT : - offset = shot->y - src_y; - break; + return -1; } - transformShot(shot, position); - - switch( shot->position ) + if( ( fce_move_tux = export_fce->fce_getExportFce("move_tux") ) == NULL ) { - 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; + return -1; } - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); - - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) + if( ( fce_move_shot = export_fce->fce_getExportFce("move_shot") ) == NULL ) { - char msg[STR_PROTO_SIZE]; - - sprintf(msg, "teleportshot %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); + return -1; } -} - -static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *list) -{ - teleport_t *distTeleport; - - distTeleport = getRandomTeleportBut(list, teleport); - - moveShot(shot, getRandomPosition(), teleport->x, teleport->y, - distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); -} - -int init(export_fce_t *p) -{ - export_fce = p; - - listTeleport = newList(); return 0; } @@ -470,68 +332,8 @@ void cmdArena(char *line) if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(line); } -static void proto_teleporttux(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_getCurrentArena()->spaceTux; - tux = getObjectFromSpaceWithID(space, id); - - if( tux != NULL ) - { - moveObjectInSpace(space, tux, x, y); - } -} - -static void proto_teleportshot(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_getCurrentArena()->spaceShot; - - if( ( shot = getObjectFromSpaceWithID(space, shot_id) ) == NULL ) - { - return; - } - - moveObjectInSpace(space, shot, x, y); - shot->isCanKillAuthor = 1; - shot->position = position; - shot->px = px; - shot->py = py; - - if( shot->gun == GUN_LASSER ) - { - export_fce->fce_transformOnlyLasser(shot); - } -} - void recvMsg(char *msg) { - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - return; - } - - if( strncmp(msg, "teleporttux", 11) == 0 )proto_teleporttux(msg); - if( strncmp(msg, "teleportshot", 12) == 0 )proto_teleportshot(msg); } int destroy() |