diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-05-12 20:39:34 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-05-12 20:39:34 +0000 |
| commit | 7055882c93022da3a6a1cf74cebf3d17c44ce6c4 (patch) | |
| tree | bacb905bbfb33a5ee5a203c4e327495fcbd85ef7 | |
| parent | 46958f55432bcbb6f4e90f4dd937d8de355e5785 (diff) | |
- podpora modulov
- hra sa musi kompilovat s GUI ako
v config.h _zakomenotvane_ #define PUBLIC_SERVER
make clean
make
make mod
su
make install
- hra sa musi ako server kompilovat
v config.h _odkomentovane__ #define PUBLIC_SERVER
make clean
make
make mod
- pozor, urcite tam je este vela bugov //je to nedoladene
zatial to ani nedavajte na server
git-svn-id: http://opensvn.csie.org/tuxanci_ng@52 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | arena/in_a_captivity_of_8-bit.map | 2 | ||||
| -rw-r--r-- | arena/night_workshift.map | 2 | ||||
| -rw-r--r-- | config.h | 4 | ||||
| -rw-r--r-- | include/main.h | 2 | ||||
| -rw-r--r-- | include/modules.h | 73 | ||||
| -rw-r--r-- | include/path.h | 1 | ||||
| -rw-r--r-- | include/shot.h | 4 | ||||
| -rwxr-xr-x | modules/Makefile | 16 | ||||
| -rwxr-xr-x | modules/list.c | 236 | ||||
| -rwxr-xr-x | modules/list.h | 32 | ||||
| -rwxr-xr-x | modules/modPipe.c | 423 | ||||
| -rwxr-xr-x | modules/modTeleport.c | 480 | ||||
| -rw-r--r-- | server.conf | 2 | ||||
| -rwxr-xr-x | src/Makefile | 15 | ||||
| -rwxr-xr-x | src/Makefile-publicServer | 19 | ||||
| -rw-r--r-- | src/arena.c | 17 | ||||
| -rw-r--r-- | src/arenaFile.c | 51 | ||||
| -rwxr-xr-x | src/modules.c | 220 | ||||
| -rw-r--r-- | src/pipe.c | 3 | ||||
| -rw-r--r-- | src/proto.c | 3 | ||||
| -rw-r--r-- | src/publicServer.c | 4 | ||||
| -rw-r--r-- | src/screen_world.c | 6 | ||||
| -rw-r--r-- | src/shot.c | 9 | ||||
| -rw-r--r-- | src/tux.c | 9 |
25 files changed, 1564 insertions, 77 deletions
@@ -6,6 +6,7 @@ all: clean: make -C ./src clean make -C ./src -f Makefile-publicServer clean + make -C ./modules -f Makefile clean run: ./tuxanci-ng.sh @@ -49,9 +50,13 @@ server: nosound: make -C ./src -f Makefile-nosound +mod: + make -C ./modules -f Makefile modTeleport + make -C ./modules -f Makefile modPipe + install: mkdir -p $(DESTDIR)/bin - mkdir -p $(DESTDIR)/share/tuxanci-ng/{arena,data,font,image,lang,music,sound,conf} + mkdir -p $(DESTDIR)/share/tuxanci-ng/{arena,data,font,image,lang,music,sound,conf,modules} cp ./src/tuxanci-ng $(DESTDIR)/bin/ cp -rf ./arena/* $(DESTDIR)/share/tuxanci-ng/arena/ @@ -62,6 +67,7 @@ install: cp -rf ./sound/* $(DESTDIR)/share/tuxanci-ng/sound/ cp -rf ./data/* $(DESTDIR)/share/tuxanci-ng/data/ cp -rf ./conf/* $(DESTDIR)/share/tuxanci-ng/conf/ + cp -rf ./modules/*.so $(DESTDIR)/share/tuxanci-ng/modules/ uninstall: rm -rf $(DESTDIR)/{bin,share}/tuxanci-ng diff --git a/arena/in_a_captivity_of_8-bit.map b/arena/in_a_captivity_of_8-bit.map index 37682e9..b078b33 100644 --- a/arena/in_a_captivity_of_8-bit.map +++ b/arena/in_a_captivity_of_8-bit.map @@ -3,6 +3,8 @@ name In a captivity of 8-bit netName IACO8B screen in_a_captivity_of_8-bit.png +loadModule file="modTeleport.so" + loadMusic file="in_a_captivity_of_8-bit.ogg" name="in_a_captivity_of_8-bit" loadImage file="l3.nic.png" name="nic" alpha="no" diff --git a/arena/night_workshift.map b/arena/night_workshift.map index 4aaac22..8ea7765 100644 --- a/arena/night_workshift.map +++ b/arena/night_workshift.map @@ -3,6 +3,8 @@ name night workshift netName NW screen night_workshift.png +loadModule file="modPipe.so" + loadMusic file="night_workshift.ogg" name="night_workshift" loadImage file="l2.pitch.png" name="pitch" alpha="no" @@ -6,8 +6,8 @@ #define DEBUG_CLIENT_RECV */ -#define TUXANCI_NG_VERSION "svn50" +#define TUXANCI_NG_VERSION "svn52" #define DESTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP -//#define DEBUG_LOST_PACKET 2 +//#define PUBLIC_SERVER diff --git a/include/main.h b/include/main.h index 3dd5fc1..09280d0 100644 --- a/include/main.h +++ b/include/main.h @@ -9,7 +9,7 @@ #undef DESTDIR #undef SUPPORT_NET_SDL_UDP -#undef SUPPORT_NET_UNIX_TCP +#define SUPPORT_NET_UNIX_UDP #endif diff --git a/include/modules.h b/include/modules.h new file mode 100644 index 0000000..872cab7 --- /dev/null +++ b/include/modules.h @@ -0,0 +1,73 @@ + +#ifndef MODULE_H + +#define MODULE_H + +#include "tux.h" +#include "shot.h" +#include "arena.h" +#include "proto.h" + +#ifndef PUBLIC_SERVER +#include "image.h" +#endif + +typedef struct export_fce_s +{ + int (*fce_getValue)(char *line, char *env, char *val, int len); + +#ifndef PUBLIC_SERVER + SDL_Surface* (*fce_getImage)(char *group, char *name); + + void (*fce_addLayer)(SDL_Surface *img, + int x,int y, int px,int py, + int w,int h, int player); +#endif + + int (*fce_getNetTypeGame)(); + + void (*fce_getTuxProportion)(tux_t *tux, int *x,int *y, int *w, int *h); + void (*fce_setTuxProportion)(tux_t *tux, int x, int y); + tux_t* (*fce_getTuxID)(list_t *listTux, int id); + + arena_t* (*fce_getCurrentArena)(); + int (*fce_conflictSpace)(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2); + int (*fce_isFreeSpace)(arena_t *arena, int x, int y, int w, int h); + void (*fce_findFreeSpace)(arena_t *arena, int *x, int *y, int w, int h); + void (*fce_proto_send_newtux_server)(int type, client_t *client, tux_t *tux); + void (*fce_proto_send_shot_server)(int type, client_t *client, shot_t *p); + + void (*fce_destroyShot)(shot_t *p); + void (*fce_boundBombBall)(shot_t *shot); + + int (*fce_pokus)(char *s); + +} export_fce_t; + +typedef struct module_s +{ + char *file; + void *image; + + int (*fce_init)(export_fce_t *p); +#ifndef PUBLIC_SERVER + int (*fce_draw)(); +#endif + int (*fce_event)(); + int (*fce_isConflict)(int x, int y, int w, int h); + void (*fce_cmd)(char *line); + int (*fce_destroy)(); + +} module_t; + +extern void initModule(); +extern int loadModule(char *name); +#ifndef PUBLIC_SERVER +extern void drawModule(); +#endif +extern void eventModule(); +extern void cmdModule(char *s); +extern int isConflictModule(int x, int y, int w, int h); +extern void quitModule(); + +#endif diff --git a/include/path.h b/include/path.h index 884e13e..d253fe1 100644 --- a/include/path.h +++ b/include/path.h @@ -28,5 +28,6 @@ #define PATH_CONFIG DESTDIR PATH_DIR "conf/" #define PATH_LANG DESTDIR PATH_DIR "lang/" #define PATH_DATA DESTDIR PATH_DIR "data/" +#define PATH_MODULES DESTDIR PATH_DIR "modules/" #endif diff --git a/include/shot.h b/include/shot.h index cc10c9a..156a736 100644 --- a/include/shot.h +++ b/include/shot.h @@ -45,12 +45,8 @@ extern void drawListShot(list_t *listShot); extern int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h); extern void eventMoveListShot(list_t *listShot); -extern void transformOnlyLasser(shot_t *shot); extern void boundBombBall(shot_t *shot); -extern 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); - extern void destroyShot(shot_t *p); extern void quitShot(); diff --git a/modules/Makefile b/modules/Makefile new file mode 100755 index 0000000..a3e5588 --- /dev/null +++ b/modules/Makefile @@ -0,0 +1,16 @@ + +CFLAGS = -g -O0 -I../include -Wall + +modTeleport: + gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c list.c -o list.o + gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c modTeleport.c -o modTeleport.o + gcc $(CFLAGS) -I../include -shared -fPIC -o modTeleport.so modTeleport.o list.o + +modPipe: + gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c list.c -o list.o + gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c modPipe.c -o modPipe.o + gcc $(CFLAGS) -I../include -shared -fPIC -o modPipe.so modPipe.o list.o + +clean: + rm -rf *.o + rm -rf *.so diff --git a/modules/list.c b/modules/list.c new file mode 100755 index 0000000..56f7e17 --- /dev/null +++ b/modules/list.c @@ -0,0 +1,236 @@ + +#include "main.h" +#include "list.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +list_t* newList() +{ + list_t *new; + + new = malloc( sizeof(list_t) ); + memset(new, 0, sizeof(list_t) ); + + return new; +} + +list_t* cloneList(list_t *p) +{ + list_t *new; + + assert( p != NULL ); + + new = malloc( sizeof(list_t) ); + memcpy(new, p, sizeof(list_t) ); + + if( p->list != NULL ) + { + new->list = malloc( p->alloc * sizeof(void *) ); + memcpy(new->list, p->list, p->alloc * sizeof(void *)); + } + + return new; +} + +list_t* cloneListItem(list_t *p, void *f) +{ + list_t *new; + void* (*fce)(void *); + int i; + + assert( p != NULL ); + assert( f != NULL ); + + new = cloneList(p); + fce = f; + + for(i = 0 ; i < p->count ; i++) + new->list[i] = fce(p->list[i]); + + return new; +} + +void addList(list_t *p, void *item) +{ + assert( p != NULL ); + + if( p->alloc == 0 ) + { + p->alloc = LIST_ALLOC_LIMIT; + p->count = 1; + p->list = malloc(p->alloc * sizeof(void *) ); + p->list[0] = item; + + return; + } + + if( p->count + 1 <= p->alloc ) + { + p->list[p->count] = item; + p->count += 1; + + return; + } + + if( p->count + 1 > p->alloc ) + { + void **new; + +#ifdef DEBUG_LIST + printf("realokujem z %d na %d (count=%d)\n", + p->alloc, p->alloc+LIST_ALLOC_LIMIT, p->count); +#endif + + p->alloc += LIST_ALLOC_LIMIT; + new = malloc(p->alloc * sizeof(void *) ); + memcpy(new, p->list, p->count * sizeof(void *) ); + free(p->list); + p->list = new; + p->list[p->count] = item; + p->count++; + + return; + } +} + +void insList(list_t *p, int n, void *item) +{ + assert( p != NULL ); + + addList(p, NULL); // :) + + assert( n >= 0 || n < p->count ); + + memmove(p->list+n+1, p->list+n, ( (p->count-1) - n ) * sizeof(void *)); + + p->list[n] = item; +} + +void *getList(list_t *p, int n) +{ + assert( p != NULL ); + assert( n >= 0 || n < p->count ); + + return p->list[n]; +} + +int searchListItem(list_t *p, void *n) +{ + int i; + + assert( p != NULL ); + + for( i = 0 ; i < p->count ; i++ ) + if( p->list[i] == n )return i; + + return -1; +} + +void delList(list_t *p, int n) +{ + assert( p != NULL ); + assert( n >= 0 || n < p->count ); + + memmove(p->list+n, p->list+n+1, ( (p->count-1) - n ) * sizeof(void *)); + + p->count--; + + if( p->count + LIST_ALLOC_LIMIT < p->alloc ) + { + void **new; + +#ifdef DEBUG_LIST + printf("realokujem z %d na %d (count=%d)\n", + p->alloc, p->alloc-LIST_ALLOC_LIMIT, p->count); +#endif + + p->alloc -= LIST_ALLOC_LIMIT; + new = malloc(p->alloc * sizeof(void *) ); + memcpy(new, p->list, p->count * sizeof(void *) ); + free(p->list); + p->list = new; + } +} + +void delListItem(list_t *p, int n, void *f) +{ + int (*fce)(void *); + + assert( p != NULL ); + assert( n >= 0 || n < p->count ); + + fce = f; + if( fce != NULL )fce(p->list[n]); + + delList(p, n); +} + +void destroyList(list_t *p) +{ + assert( p != NULL ); + + if( p->list != NULL )free(p->list); + free(p); +} + +void destroyListItem(list_t *p, void *f) +{ + void (*fce)(void *); + int i; + + assert( p != NULL ); + assert( f != NULL ); + + fce = f; + + for(i = 0 ; i < p->count ; i++) + fce(p->list[i]); + + destroyList(p); +} + +/* +typedef struct pokus_str +{ + int x; +} pokus; + +pokus* newPokus(int n) +{ + pokus *new; + new = malloc(sizeof(pokus)); + new->x = n; + return new; +} + +pokus *clonePokus(pokus *p) +{ + pokus *new; + new = malloc(sizeof(pokus)); + memcpy(new, p, sizeof(pokus)); + return new; +} + +void destroyPokus(pokus *p) +{ + free(p); +} + +int main() +{ + list_t *my; + int i; + + my = newList(); + + for(i = 0; i < 100; i++) + addList(my, newPokus(i)); + + destroyListItem(my, destroyPokus); + + return 0; +} +*/ diff --git a/modules/list.h b/modules/list.h new file mode 100755 index 0000000..8722baa --- /dev/null +++ b/modules/list.h @@ -0,0 +1,32 @@ + +#ifndef LIST_H + +#define LIST_H + +#include "main.h" + +#define LIST_ALLOC_LIMIT 16 + +typedef struct list_str +{ + void **list; + int count; + int alloc; +} list_t; + +extern list_t* newList(); +extern list_t* cloneList(list_t *p); +extern list_t* cloneListItem(list_t *p, void *f); + +extern void addList(list_t *p, void *item); +extern void insList(list_t *p, int n, void *item); +extern void *getList(list_t *p,int n); +extern int searchListItem(list_t *p, void *n); + +extern void delList(list_t *p,int n); +extern void delListItem(list_t *p,int n,void *f); + +extern void destroyList(list_t *p); +extern void destroyListItem(list_t *p,void *f); + +#endif diff --git a/modules/modPipe.c b/modules/modPipe.c new file mode 100755 index 0000000..fa5f99e --- /dev/null +++ b/modules/modPipe.c @@ -0,0 +1,423 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "main.h" +#include "interface.h" +#include "modules.h" +#include "tux.h" +#include "shot.h" +#include "list.h" +#include "gun.h" +#include "image.h" + +#ifdef PUBLIC_SERVER +#include "publicServer.h" +#endif + +typedef struct pipe_struct +{ + int x; // poloha steny + int y; + + int w; // rozmery steny + int h; + + int id; + int id_out; + int position; + + int layer; // vrstva + +#ifndef PUBLIC_SERVER + SDL_Surface *img; //obrazok +#endif +} pipe_t; + +static export_fce_t *export_fce; + +static list_t *listPipe; + +#ifndef PUBLIC_SERVER +static pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, SDL_Surface *img) +#endif + +#ifdef PUBLIC_SERVER +static pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position) +#endif + +{ + pipe_t *new; + +#ifndef PUBLIC_SERVER + assert( img != NULL ); +#endif + + 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 + return new; +} + +#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 + +static pipe_t* isConflictWithListPipe(list_t *listPipe, int x, int y, int w, int h) +{ + pipe_t *thisPipe; + int i; + + assert( listPipe != NULL ); + + for( i = 0 ; i < listPipe->count ; i++ ) + { + thisPipe = (pipe_t *)listPipe->list[i]; + assert( thisPipe != NULL ); + + if( export_fce->fce_conflictSpace(x, y, w, h, + thisPipe->x, thisPipe->y, thisPipe->w, thisPipe->h) ) + { + return thisPipe; + } + } + + return NULL; +} + +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 )return; + if( export_fce->fce_getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "id", str_id, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "position", str_position, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; + if( 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_getImage(IMAGE_GROUP_USER, str_image) ); +#endif + +#ifdef 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 + + addList(listPipe, 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; +} + +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; + + 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 : + shot->x = dist_x + offset; + shot->y = dist_y; + break; + + case TUX_LEFT : + shot->x = dist_x; + shot->y = dist_y + offset; + break; + + case TUX_RIGHT : + shot->x = dist_x + dist_w; + shot->y = dist_y + offset; + break; + + case TUX_DOWN : + shot->x = dist_x + offset; + shot->y = dist_y + dist_h; + break; + } + + shot->x += shot->px; + shot->y += shot->py; + + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + } + +} + +static pipe_t* getPipeId(list_t *listPipe, int id) +{ + int i; + + for( i = 0 ; i < listPipe->count ; i++ ) + { + pipe_t *thisPipe; + + thisPipe = (pipe_t *) listPipe->list[i]; + + if( thisPipe->id == id ) + { + return thisPipe; + } + } + + return NULL; +} + +static void moveShotFromPipe(shot_t *shot, pipe_t *pipe, list_t *listPipe) +{ + pipe_t *distPipe; + + distPipe = getPipeId(listPipe, pipe->id_out); + + if( distPipe == NULL ) + { + fprintf(stderr, "Pipe %d ID not found\n", pipe->id); + return; + } + + moveShot(shot, distPipe->position, pipe->x, pipe->y, + distPipe->x, distPipe->y, distPipe->w, distPipe->h); +} + +int init(export_fce_t *p) +{ + export_fce = p; + + listPipe = newList(); + + return 0; +} + +#ifndef PUBLIC_SERVER + +int draw() +{ + pipe_t *thisPipe; + int i; + + assert( listPipe != NULL ); + + for( i = 0 ; i < listPipe->count ; i++ ) + { + thisPipe = (pipe_t *)listPipe->list[i]; + assert( thisPipe != NULL ); + drawPipe(thisPipe); + } + + return 0; +} +#endif + +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 : + assert( ! "premenna n ma zlu hodnotu !" ); + break; + } +} + +int event() +{ + pipe_t *thisPipe; + arena_t *arena; + int i; + + arena = export_fce->fce_getCurrentArena(); + + for( i = 0 ; i < arena->listShot->count ; i++ ) + { + shot_t *thisShot; + + thisShot = (shot_t *)arena->listShot->list[i]; + assert( thisShot != NULL ); + + if( ( thisPipe = isConflictWithListPipe(listPipe, thisShot->x, thisShot->y, + thisShot->w, thisShot->h) ) != NULL ) + { + tux_t *author; + + author = export_fce->fce_getTuxID(arena->listTux, thisShot->author_id); + + if( author != NULL && + author->bonus == BONUS_GHOST && + author->bonus_time > 0 ) + { + continue; + } + + if( negPosition( thisShot->position ) == thisPipe->position ) + { + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + if( thisShot->gun != GUN_BOMBBALL ) + { + delListItem(arena->listShot, i, export_fce->fce_destroyShot); + i--; + } + } + else + { + moveShotFromPipe(thisShot, thisPipe, listPipe); + } + } + else + { + if( thisShot->gun == GUN_BOMBBALL && + export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + export_fce->fce_boundBombBall(thisShot); + continue; + } + else + { + delListItem(arena->listShot, i, export_fce->fce_destroyShot); + i--; + } + } + } + } + + return 0; +} + +int isConflict(int x, int y, int w, int h) +{ + if( isConflictWithListPipe(listPipe, x, y, w, h) != NULL ) + { + return 1; + } + else + { + return 0; + } +} + +void cmd(char *line) +{ + if( strncmp(line, "pipe", 4) == 0 )cmd_teleport(line); +} + +int destroy() +{ + destroyListItem(listPipe, destroyPipe); + + return 0; +} diff --git a/modules/modTeleport.c b/modules/modTeleport.c new file mode 100755 index 0000000..fb59470 --- /dev/null +++ b/modules/modTeleport.c @@ -0,0 +1,480 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "main.h" +#include "interface.h" +#include "modules.h" +#include "tux.h" +#include "shot.h" +#include "list.h" +#include "gun.h" +#include "image.h" + +#ifdef PUBLIC_SERVER +#include "publicServer.h" +#endif + +typedef struct teleport_struct +{ + int x; // poloha steny + int y; + + int w; // rozmery steny + int h; + + int layer; // vrstva + +#ifndef PUBLIC_SERVER + SDL_Surface *img; //obrazok +#endif +} teleport_t; + +static export_fce_t *export_fce; + +static list_t *listTeleport; + +#ifndef PUBLIC_SERVER +teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img) +#endif + +#ifdef PUBLIC_SERVER +teleport_t* newTeleport(int x, int y, int w, int h, int layer) +#endif +{ + teleport_t *new; + +#ifndef PUBLIC_SERVER + assert( img != NULL ); +#endif + + new = malloc( sizeof(teleport_t) ); + assert( new != NULL ); + + new->x = x; + new->y = y; + new->w = w; + new->h = h; + new->layer = layer; +#ifndef PUBLIC_SERVER + new->img = img; +#endif + + printf("new teleport\n"); + return new; +} + +#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 + +static teleport_t* isConflictWithListTeleport(list_t *listTeleport, int x, int y, int w, int h) +{ + teleport_t *thisTeleport; + int i; + + assert( listTeleport != NULL ); + + for( i = 0 ; i < listTeleport->count ; i++ ) + { + thisTeleport = (teleport_t *)listTeleport->list[i]; + assert( thisTeleport != NULL ); + + if( export_fce->fce_conflictSpace(x, y, w, h, + thisTeleport->x, thisTeleport->y, thisTeleport->w, thisTeleport->h) ) + { + return thisTeleport; + } + } + + return NULL; +} + +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 )return; + if( export_fce->fce_getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; + if( 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_getImage(IMAGE_GROUP_USER, str_image) ); +#endif + +#ifdef PUBLIC_SERVER + new = newTeleport(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_layer) ); +#endif + + addList(listTeleport, new); +} + +static teleport_t* getRandomTeleportBut(list_t *listTeleport, teleport_t *teleport) +{ + int x; + + do{ + x = random() % listTeleport->count; + }while( listTeleport->list[x] == teleport ); + + return (teleport_t *) listTeleport->list[x]; +} + +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 ! " ); +} + +static void teleportTux(tux_t *tux, teleport_t *teleport) +{ + teleport_t *distTeleport; + int current_x, current_y; + int dist_x, dist_y; + + if( tux->bonus == BONUS_GHOST || + export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return; + } + + distTeleport = getRandomTeleportBut(listTeleport, teleport); + + export_fce->fce_getTuxProportion(tux, ¤t_x, ¤t_y, NULL, NULL); + + 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) ) + { + 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 ) + { + export_fce->fce_proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } +} + +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 transformOnlyLasser(shot_t *shot) +{ + switch( shot->position ) + { + case TUX_RIGHT : + case TUX_LEFT : + shot->w = GUN_LASSER_HORIZONTAL; + shot->h = GUN_SHOT_VERTICAL; +#ifndef PUBLIC_SERVER + shot->img = g_shot_lasserX; +#endif + break; + case TUX_UP : + case TUX_DOWN : + shot->w = GUN_SHOT_VERTICAL; + shot->h = GUN_LASSER_HORIZONTAL; +#ifndef PUBLIC_SERVER + shot->img = g_shot_lasserY; +#endif + break; + } +} +*/ + +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 ) + { + 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; + + 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 : + shot->x = dist_x + offset; + shot->y = dist_y; + break; + + case TUX_LEFT : + shot->x = dist_x; + shot->y = dist_y + offset; + break; + + case TUX_RIGHT : + shot->x = dist_x + dist_w; + shot->y = dist_y + offset; + break; + + case TUX_DOWN : + shot->x = dist_x + offset; + shot->y = dist_y + dist_h; + break; + } + + shot->x += shot->px; + shot->y += shot->py; + + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + } + +} + +static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *listTeleport) +{ + teleport_t *distTeleport; + + distTeleport = getRandomTeleportBut(listTeleport, 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; +} + +#ifndef PUBLIC_SERVER +int draw() +{ + teleport_t *thisTeleport; + int i; + + assert( listTeleport != NULL ); + + for( i = 0 ; i < listTeleport->count ; i++ ) + { + thisTeleport = (teleport_t *)listTeleport->list[i]; + assert( thisTeleport != NULL ); + drawTeleport(thisTeleport); + } + + return 0; +} +#endif + +int event() +{ + teleport_t *thisTeleport; + arena_t *arena; + int i; + + arena = export_fce->fce_getCurrentArena(); + + for( i = 0 ; i < arena->listTux->count ; i++ ) + { + tux_t *thisTux; + int x, y, w, h; + + thisTux = (tux_t *)arena->listTux->list[i]; + export_fce->fce_getTuxProportion(thisTux, &x, &y, &w, &h); + + if( ( thisTeleport = isConflictWithListTeleport(listTeleport, x, y, w, h) ) != NULL ) + { + teleportTux(thisTux, thisTeleport); + } + } + + for( i = 0 ; i < arena->listShot->count ; i++ ) + { + shot_t *thisShot; + + thisShot = (shot_t *)arena->listShot->list[i]; + assert( thisShot != NULL ); + + if( thisShot->gun == GUN_LASSER ) + { + continue; + } + + if( ( thisTeleport = isConflictWithListTeleport(listTeleport, + thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) != NULL ) + { + tux_t *author; + + author = export_fce->fce_getTuxID(arena->listTux, thisShot->author_id); + + if( author != NULL && + author->bonus == BONUS_GHOST && + author->bonus_time > 0 ) + { + continue; + } + + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + delListItem(arena->listShot, i, export_fce->fce_destroyShot); + i--; + } + else + { + moveShotFromTeleport(thisShot, thisTeleport, listTeleport); + } + } + } + + return 0; +} + +int isConflict(int x, int y, int w, int h) +{ + return 0; +} + + +void eventConflictWithTux(tux_t *tux) +{ +} + +void eventConflictWithShot(shot_t *tux) +{ +} + +void cmd(char *line) +{ + if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(line); +} + +int destroy() +{ + destroyListItem(listTeleport, destroyTeleport); + return 0; +} diff --git a/server.conf b/server.conf index 135863f..0155ddd 100644 --- a/server.conf +++ b/server.conf @@ -1,5 +1,5 @@ IP 0.0.0.0 PORT 2200 MAX_CLIENTS 32 -ARENA NW +ARENA IACO8B diff --git a/src/Makefile b/src/Makefile index 0db4928..ab243b6 100755 --- a/src/Makefile +++ b/src/Makefile @@ -9,12 +9,12 @@ CFLAGS = -g -O0 -std=c99 -I../include -Wall `sdl-config --cflags` BUILD_DIR = . LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_net -FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o main.o \ +FILES = interface.o font.o list.o modules.o image.o layer.o director.o configFile.o tux.o main.o \ screen.o screen_world.o wall.o shot.o myTimer.o panel.o net_multiplayer.o \ buffer.o dynamicInt.o arena.o arenaFile.o textFile.o audio.o sound.o music.o gun.o \ item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \ widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \ - widget_buttonimage.o screen_credits.o teleport.o pipe.o homeDirector.o screen_table.o \ + widget_buttonimage.o screen_credits.o homeDirector.o screen_table.o \ sdl_udp.o proto.o server.o client.o term.o keytable.o language.o game.o tuxanci-ng: $(FILES) @@ -26,6 +26,9 @@ main.o: main.c interface.o: interface.c ../include/interface.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/interface.o -c interface.c +modules.o: modules.c ../include/modules.h + $(CC) $(CFLAGS) -o $(BUILD_DIR)/modules.o -c modules.c + font.o: font.c ../include/font.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/font.o -c font.c @@ -155,11 +158,11 @@ widget_check.o: widget_check.c ../include/widget_check.h widget_image.o: widget_image.c ../include/widget_image.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/widget_image.o -c widget_image.c -teleport.o: teleport.c ../include/teleport.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c +#teleport.o: teleport.c ../include/teleport.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c -pipe.o: pipe.c ../include/pipe.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c +#pipe.o: pipe.c ../include/pipe.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c homeDirector.o: homeDirector.c ../include/homeDirector.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/homeDirector.o -c homeDirector.c diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer index 39537ee..d6956bf 100755 --- a/src/Makefile-publicServer +++ b/src/Makefile-publicServer @@ -4,14 +4,14 @@ CC = gcc DESTDIR:=/usr/local -CFLAGS = -g -O0 -DPUBLIC_SERVER -DSUPPORT_NET_UNIX_UDP -I../include -Wall +CFLAGS = -g -O0 -I../include -Wall #CFLAGS = -O2 -DDESTDIR=\"$(DESTDIR)\" `sdl-config --cflags` -I../include -Wall BUILD_DIR = ../build-server -LIBS = +LIBS = -ldl -FILES = list.o director.o configFile.o tux.o wall.o shot.o myTimer.o \ - buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o teleport.o pipe.o \ +FILES = list.o modules.o director.o configFile.o tux.o wall.o shot.o myTimer.o \ + buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o\ udp.o proto.o server.o publicServer.o net_multiplayer.o serverConfigFile.o main.o $(BUILD_DIR)/publicserver: mkdir_build $(FILES) @@ -23,6 +23,9 @@ mkdir_build: main.o: main.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/main.o -c main.c +modules.o: modules.c + $(CC) $(CFLAGS) -o $(BUILD_DIR)/modules.o -c modules.c + publicServer.o: publicServer.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/publicServer.o -c publicServer.c @@ -83,11 +86,11 @@ gun.o: gun.c ../include/gun.h item.o: item.c ../include/item.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/item.o -c item.c -teleport.o: teleport.c ../include/teleport.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c +#teleport.o: teleport.c ../include/teleport.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c -pipe.o: pipe.c ../include/pipe.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c +#pipe.o: pipe.c ../include/pipe.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c serverConfigFile.o: serverConfigFile.c ../include/serverConfigFile.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/serverConfigFile.o -c serverConfigFile.c diff --git a/src/arena.c b/src/arena.c index b762937..05749d6 100644 --- a/src/arena.c +++ b/src/arena.c @@ -13,6 +13,7 @@ #include "teleport.h" #include "pipe.h" #include "myTimer.h" +#include "modules.h" #ifndef PUBLIC_SERVER #include "layer.h" @@ -62,8 +63,8 @@ int isFreeSpace(arena_t *arena, int x, int y, int w, int h) if ( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0; if ( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0; if ( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0; - if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; - if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; + //if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; + //if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; return 1; } @@ -95,8 +96,8 @@ void drawArena(arena_t *arena) drawListTux(arena->listTux); drawListWall(arena->listWall); - drawListTeleport(arena->listTeleport); - drawListPipe(arena->listPipe); + //drawListTeleport(arena->listTeleport); + //drawListPipe(arena->listPipe); drawListShot(arena->listShot); drawListItem(arena->listItem); @@ -120,15 +121,15 @@ void eventArena(arena_t *arena) { int i; - eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); + //eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); eventConflictTuxWithShot(arena->listTux, arena->listShot); for( i = 0 ; i < 4 ; i++) { eventMoveListShot(arena->listShot); eventConflictShotWithWall(arena->listWall, arena->listShot); - eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); - eventConflictShotWithPipe(arena->listPipe, arena->listShot); + //eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); + //eventConflictShotWithPipe(arena->listPipe, arena->listShot); eventConflictShotWithItem(arena->listItem, arena->listShot); } @@ -142,7 +143,7 @@ void eventArena(arena_t *arena) int isConflictWithObjectInArena(arena_t *arena, int x, int y, int w, int h) { if( isConflictWithListWall(arena->listWall, x, y, w, h) || - isConflictWithListPipe(arena->listPipe, x, y, w, h) ) + isConflictModule(x, y, w, h) ) { return 1; } diff --git a/src/arenaFile.c b/src/arenaFile.c index b30c231..90ae231 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -18,6 +18,7 @@ #include "item.h" #include "director.h" #include "path.h" +#include "modules.h" #include "string_length.h" #ifndef PUBLIC_SERVER @@ -35,6 +36,15 @@ bool_t isAreaFileInicialized() return isArenaFileInit; } +static void cmd_loadModule(char *line) +{ + char str_file[STR_SIZE]; + + if( getValue(line, "file", str_file, STR_SIZE) != 0 )return; + + loadModule(str_file); +} + #ifndef PUBLIC_SERVER static void cmd_loadImage(char *line) @@ -119,38 +129,7 @@ static void cmd_wall(arena_t *arena, char *line) addList(arena->listWall, new); } -static void cmd_teleport(arena_t *arena, 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( getValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; - if( 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), getImage(IMAGE_GROUP_USER, str_image) ); -#endif - -#ifdef PUBLIC_SERVER - new = newTeleport(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer) ); -#endif - - addList(arena->listTeleport, new); -} - +/* static void cmd_pipe(arena_t *arena, char *line) { char str_x[STR_NUM_SIZE]; @@ -189,6 +168,7 @@ static void cmd_pipe(arena_t *arena, char *line) addList(arena->listPipe, new); } +*/ int getArenaCount() { @@ -270,6 +250,8 @@ arena_t* getArena(int id) char *line; line = (char *) (ts->text->list[i]); + cmdModule(line); + #ifndef PUBLIC_SERVER if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line); if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line); @@ -277,9 +259,10 @@ arena_t* getArena(int id) if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line); #endif + if( strncmp(line, "loadModule", 10) == 0 )cmd_loadModule(line); if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); - if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); - if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); + //if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); + //if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); } return arena; diff --git a/src/modules.c b/src/modules.c new file mode 100755 index 0000000..7a8f3cd --- /dev/null +++ b/src/modules.c @@ -0,0 +1,220 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <assert.h> + +#include "main.h" +#include "configFile.h" +#include "list.h" +#include "path.h" +#include "tux.h" +#include "shot.h" +#include "modules.h" +#include "tux.h" +#include "arena.h" +#include "proto.h" + +#ifndef PUBLIC_SERVER +#include "interface.h" +#include "image.h" +#include "layer.h" +#endif + +int pokus(char *s) +{ + printf("s = %s\n", s); + return 0; +} + +static export_fce_t export_fce = + { +#ifndef PUBLIC_SERVER + .fce_addLayer = addLayer, + .fce_getImage = getImage, +#endif + .fce_getValue = getValue, + .fce_getNetTypeGame = getNetTypeGame, + .fce_getTuxProportion = getTuxProportion, + .fce_setTuxProportion = setTuxProportion, + .fce_getTuxID = getTuxID, + + .fce_getCurrentArena = getCurrentArena, + .fce_conflictSpace = conflictSpace, + .fce_isFreeSpace = isFreeSpace, + .fce_findFreeSpace = findFreeSpace, + .fce_proto_send_newtux_server = proto_send_newtux_server, + .fce_proto_send_shot_server = proto_send_shot_server, + .fce_destroyShot = destroyShot, + .fce_boundBombBall = boundBombBall + }; + +static list_t *listModule; + +static void* getFce(module_t *p, char *s) +{ + void *ret; + char *error; + + assert( p != NULL ); + assert( s != NULL ); + + ret = dlsym(p->image, s); + + if( ( error = dlerror() ) != NULL) + { + fprintf (stderr, "error = %s\n", error); + return NULL; + } + + return (void *)ret; +} + +static module_t* newModule(char *name) +{ + module_t *ret; + + assert( name != NULL ); + + ret = malloc( sizeof(module_t) ); + + ret->image = dlopen (name, RTLD_LAZY); + + if(!ret->image) + { + fputs (dlerror(), stderr); + free(ret); + return NULL; + } + + ret->file = strdup(name); + + ret->fce_init = getFce(ret, "init"); +#ifndef PUBLIC_SERVER + ret->fce_draw = getFce(ret, "draw"); +#endif + ret->fce_event = getFce(ret, "event"); + ret->fce_destroy = getFce(ret, "destroy"); + ret->fce_isConflict = getFce(ret, "isConflict"); + ret->fce_cmd = getFce(ret, "cmd"); + + printf("load module.. (%s)\n", name); + + if( ret->fce_init(&export_fce) != 0 ) + { + fprintf(stderr, "init module failed !\n"); + + dlclose(ret->image); + free(ret->file); + free(ret); + return NULL; + } + + return ret; +} + +static int destroyModule(module_t *p) +{ + assert( p != NULL ); + + p->fce_destroy(); + + free(p->file); + dlclose(p->image); + free(p); + + + printf("destroy module..\n"); + + return 0; +} + +void initModule() +{ + listModule = newList(); +} + +int loadModule(char *name) +{ + char str[STR_PATH_SIZE]; + module_t *module; + + sprintf(str, PATH_MODULES "%s", name); + accessExistFile(str); + + module = newModule(str); + + if( module == NULL ) + { + fprintf(stderr, "load module %s failed !\n", name); + return -1; + } + + addList(listModule, module); + + return 0; +} + +void cmdModule(char *s) +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + this->fce_cmd(s); + } +} + +#ifndef PUBLIC_SERVER + +void drawModule() +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + this->fce_draw(); + } +} + +#endif + +void eventModule() +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + this->fce_event(); + } +} + +int isConflictModule(int x, int y, int w, int h) +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + + if( this->fce_isConflict(x, y, w, h) == 1 ) + { + return 1; + } + } + + return 0; +} + +void quitModule() +{ + destroyListItem(listModule, destroyModule); +} @@ -149,9 +149,10 @@ static void moveShotFromPipe(shot_t *shot, pipe_t *pipe, list_t *listPipe) fprintf(stderr, "Pipe %d ID not found\n", pipe->id); return; } - +/* moveShot(shot, distPipe->position, pipe->x, pipe->y, distPipe->x, distPipe->y, distPipe->w, distPipe->h); +*/ } void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot) diff --git a/src/proto.c b/src/proto.c index db45109..0441371 100644 --- a/src/proto.c +++ b/src/proto.c @@ -610,11 +610,12 @@ void proto_recv_shot_client(char *msg) shot->isCanKillAuthor = isCanKillAuthor; shot->position = position; +/* if( shot->gun == GUN_LASSER ) { transformOnlyLasser(shot); } - +*/ addList(getCurrentArena()->listShot, shot); } diff --git a/src/publicServer.c b/src/publicServer.c index 4b7774b..66d530f 100644 --- a/src/publicServer.c +++ b/src/publicServer.c @@ -21,6 +21,7 @@ #include "publicServer.h" #include "net_multiplayer.h" #include "serverConfigFile.h" +#include "modules.h" static int arenaId; static arena_t *arena; @@ -37,6 +38,7 @@ static char *getSetting(char *env, char *param, char *default_val) int initPublicServer() { + initModule(); initArenaFile(); initTux(); initItem(); @@ -97,6 +99,7 @@ void eventPublicServer() lastActive = getMyTime(); eventArena(arena); + eventModule(); } void my_handler_quit(int n) @@ -112,6 +115,7 @@ void quitPublicServer() destroyArena(arena); quitArenaFile(); quitServerConfigFile(); + quitModule(); exit(0); } diff --git a/src/screen_world.c b/src/screen_world.c index 9858a8b..671a858 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -35,6 +35,8 @@ #include "proto.h" #include "term.h" #include "font.h" +#include "music.h" +#include "modules.h" static arena_t *arena; static int count; @@ -193,6 +195,7 @@ void drawWorld() drawPanel(arena->listTux); } + drawModule(); drawTerm(); } @@ -358,6 +361,7 @@ void eventWorld() eventNetMultiplayer(); eventArena(arena); + eventModule(); eventTerm(); eventEnd(); @@ -372,6 +376,7 @@ void startWorld() count = 0; lastServerLag = LAG_SERVER_UNKNOWN; + initModule(); setGameType(); initTerm(); prepareArena(); @@ -435,6 +440,7 @@ void stoptWorld() stopMusic(); delAllImageInGroup(IMAGE_GROUP_USER); delAllMusicInGroup(MUSIC_GROUP_USER); + quitModule(); } void initWorld() @@ -201,12 +201,6 @@ int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h) return 0; } -static int myAbs(int n) -{ - return ( n > 0 ? n : -n ); -} - - static int getRandomCourse(int x, int y) { int ret; @@ -287,6 +281,7 @@ void eventMoveListShot(list_t *listShot) } } +/* static int getSppedShot(shot_t *shot) { return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); @@ -405,7 +400,7 @@ void moveShot(shot_t *shot, int position, int src_x, int src_y, } } - +*/ void destroyShot(shot_t *p) { assert( p != NULL ); @@ -18,6 +18,7 @@ #include "net_multiplayer.h" #include "dynamicInt.h" #include "proto.h" +#include "modules.h" #ifndef PUBLIC_SERVER #include "image.h" @@ -526,6 +527,7 @@ void eventConflictTuxWithShot(list_t *listTux, list_t *listShot) } } +/* void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport) { teleport_t *thisTeleport; @@ -551,6 +553,7 @@ void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport) } } } +*/ void moveTux(tux_t *tux, int n) { @@ -623,8 +626,8 @@ void moveTux(tux_t *tux, int n) if( tux->bonus != BONUS_GHOST && ( isConflictTuxWithListTux(tux, arena->listTux) || - isConflictWithListWall(arena->listWall, x, y, w, h) || - isConflictWithListPipe(arena->listPipe, x, y, w, h) ) ) + isConflictWithListWall(arena->listWall, x, y, w, h) || + isConflictModule(x, y, w, h) ) ) { tux->x = zal_x; tux->y = zal_y; @@ -795,7 +798,7 @@ static void eventBonus(tux_t *tux) tux->bonus = BONUS_NONE; if ( isConflictWithListWall(getCurrentArena()->listWall, x, y, w, h) || - isConflictWithListPipe(getCurrentArena()->listPipe, x, y, w, h) || + isConflictModule(x, y, w, h) || isConflictTuxWithListTux(tux, getCurrentArena()->listTux) ) { tux->bonus = BONUS_GHOST; |