diff options
| -rw-r--r-- | arena/for_a_good_night.map | 6 | ||||
| -rw-r--r-- | arena/night_workshift.map | 2 | ||||
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | include/arena.h | 10 | ||||
| -rw-r--r-- | include/item.h | 17 | ||||
| -rwxr-xr-x | include/list.h | 1 | ||||
| -rw-r--r-- | include/main.h | 4 | ||||
| -rw-r--r-- | include/modules.h | 4 | ||||
| -rw-r--r-- | include/screen_world.h | 1 | ||||
| -rw-r--r-- | include/server.h | 2 | ||||
| -rw-r--r-- | include/shot.h | 2 | ||||
| -rw-r--r-- | include/space.h | 36 | ||||
| -rw-r--r-- | include/tux.h | 7 | ||||
| -rwxr-xr-x | modules/Makefile | 3 | ||||
| -rwxr-xr-x | modules/list.c | 5 | ||||
| -rwxr-xr-x | modules/list.h | 1 | ||||
| -rwxr-xr-x | modules/modWall.c | 86 | ||||
| -rwxr-xr-x | src/Makefile | 7 | ||||
| -rw-r--r-- | src/arena.c | 61 | ||||
| -rw-r--r-- | src/arenaFile.c | 14 | ||||
| -rw-r--r-- | src/gun.c | 17 | ||||
| -rw-r--r-- | src/idManager.c | 5 | ||||
| -rw-r--r-- | src/item.c | 181 | ||||
| -rw-r--r-- | src/language.c | 2 | ||||
| -rwxr-xr-x | src/list.c | 5 | ||||
| -rw-r--r-- | src/main.c | 9 | ||||
| -rwxr-xr-x | src/modules.c | 6 | ||||
| -rw-r--r-- | src/proto.c | 54 | ||||
| -rw-r--r-- | src/screen_world.c | 57 | ||||
| -rw-r--r-- | src/server.c | 58 | ||||
| -rw-r--r-- | src/shot.c | 82 | ||||
| -rw-r--r-- | src/space.c | 370 | ||||
| -rw-r--r-- | src/tux.c | 149 |
33 files changed, 1059 insertions, 207 deletions
diff --git a/arena/for_a_good_night.map b/arena/for_a_good_night.map index 0680404..cb714d3 100644 --- a/arena/for_a_good_night.map +++ b/arena/for_a_good_night.map @@ -7,17 +7,17 @@ loadModule file="modWall.so" loadMusic file="for_a_good_night.ogg" name="for_a_good_night" -loadImage file="l1.grow.png" name="grow" alpha="no" +loadImage file="tl1.grow.png" name="grow" alpha="no" loadImage file="l1.hut.png" name="hut" alpha="yes" loadImage file="l1.peduncle.png" name="peduncle" alpha="yes" loadImage file="l1.tree.png" name="tree" alpha="yes" loadImage file="l1.wood.png" name="wood" alpha="yes" -arena background="grow" w="800" h="600" +arena background="grow" w="2000" h="2000" playMusic music="for_a_good_night" -wall x="0" y="0" w="0" h="0" img_x="75" img_y="20" layer="1" image="hut" +wall x="1" y="1" w="0" h="0" img_x="75" img_y="20" layer="1" image="hut" wall x="120" y="159" w="180" h="65" img_x="90" img_y="159" layer="0" image="peduncle" wall x="520" y="260" w="161" h="100" img_x="500" img_y="180" layer="0" image="tree" wall x="220" y="400" w="110" h="10" img_x="200" img_y="370" layer="0" image="wood" diff --git a/arena/night_workshift.map b/arena/night_workshift.map index 2211665..49d637b 100644 --- a/arena/night_workshift.map +++ b/arena/night_workshift.map @@ -4,7 +4,7 @@ netName NW screen night_workshift.png loadModule file="modWall.so" -loadModule file="modPipe.so" +#loadModule file="modPipe.so" loadMusic file="night_workshift.ogg" name="night_workshift" @@ -6,7 +6,7 @@ #define DEBUG_CLIENT_RECV */ -#define TUXANCI_NG_VERSION "svn62" +#define TUXANCI_NG_VERSION "svn63" #define DESTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP diff --git a/include/arena.h b/include/arena.h index c800169..2c06659 100644 --- a/include/arena.h +++ b/include/arena.h @@ -4,10 +4,13 @@ #define ARENA_H #include "main.h" + #ifndef PUBLIC_SERVER #include "interface.h" #endif + #include "list.h" +#include "space.h" typedef struct arena_struct { @@ -18,14 +21,15 @@ typedef struct arena_struct #endif int w, h; list_t *listTimer; - list_t *listTux; + //list_t *listTux; list_t *listShot; - list_t *listItem; + space_t *spaceTux; + space_t *spaceItem; } arena_t; extern void setCurrentArena(arena_t *p); extern arena_t* getCurrentArena(); -extern arena_t* newArena(); +extern arena_t* newArena(int w, int h); extern int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2); extern int isFreeSpace(arena_t *arena, int x, int y, int w, int h); extern void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h); diff --git a/include/item.h b/include/item.h index dd67765..b8a9825 100644 --- a/include/item.h +++ b/include/item.h @@ -60,19 +60,18 @@ typedef struct item_struct extern bool_t isItemInicialized(); extern void initItem(); extern item_t* newItem(int x, int y, int type, int author_id); -extern item_t* getItemID(list_t *listItem, int id); +extern void getStatusItem(void *p, int *id, int *x, int *y ,int *w, int *h); +extern void setStatusItem(void *p, int x, int y, int w, int h); extern void replaceItemID(item_t *item, int id); -extern void addNewItem(list_t *listItem, int author_id); +extern void addNewItem(space_t *spaceItem, int author_id); #ifndef PUBLIC_SERVER -extern void drawItem(item_t *p); extern void drawListItem(list_t *listItem); +extern void eventListItem(space_t *listSpace); #endif -extern void eventListItem(list_t *listItem); -extern void eventConflictShotWithItem(list_t *listItem, list_t *listShot); -extern int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h); -extern void mineExplosion(list_t *listItem, item_t *item); -extern int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item); -extern void eventGiveTuxListItem(tux_t *tux, list_t *listItem); +extern void mineExplosion(space_t *spaceItem, item_t *item); +extern void eventConflictShotWithItem(arena_t *arena); +extern void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem); +extern void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem); extern void destroyItem(item_t *p); extern void quitItem(); diff --git a/include/list.h b/include/list.h index 8722baa..5a15786 100755 --- a/include/list.h +++ b/include/list.h @@ -25,6 +25,7 @@ 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 listDoEmpty(list_t *p); extern void destroyList(list_t *p); extern void destroyListItem(list_t *p,void *f); diff --git a/include/main.h b/include/main.h index ea3d703..942064f 100644 --- a/include/main.h +++ b/include/main.h @@ -21,6 +21,10 @@ #define WINDOW_SIZE_X 800 #define WINDOW_SIZE_Y 600 +#include "list.h" + +extern list_t *listHelp; + extern char* getParam(char *s); extern char* getParamElse(char *s1, char *s2); extern bool_t isParamFlag(char *s); diff --git a/include/modules.h b/include/modules.h index f05234f..085e476 100644 --- a/include/modules.h +++ b/include/modules.h @@ -52,7 +52,7 @@ typedef struct module_s int (*fce_init)(export_fce_t *p); #ifndef PUBLIC_SERVER - int (*fce_draw)(); + int (*fce_draw)(int x, int y,int w, int h); #endif int (*fce_event)(); int (*fce_isConflict)(int x, int y, int w, int h); @@ -64,7 +64,7 @@ typedef struct module_s extern void initModule(); extern int loadModule(char *name); #ifndef PUBLIC_SERVER -extern void drawModule(); +extern void drawModule(int x, int y, int w, int h); #endif extern void eventModule(); extern void cmdModule(char *s); diff --git a/include/screen_world.h b/include/screen_world.h index b6a4259..0ba4b41 100644 --- a/include/screen_world.h +++ b/include/screen_world.h @@ -20,6 +20,7 @@ extern void countRoundInc(); extern void setWorldEnd(); extern void setMaxCountRound(int n); extern tux_t* getControlTux(int control_type); +extern void setControlTux(tux_t *tux, int control_type); extern void tuxControl(tux_t *p); extern void drawWorld(); extern void eventWorld(); diff --git a/include/server.h b/include/server.h index 8d97ed3..178dc34 100644 --- a/include/server.h +++ b/include/server.h @@ -81,8 +81,10 @@ extern void sendAllClientSeesTux(char *msg, tux_t *tux); extern void addMsgClient(client_t *p, char *msg, int id); extern void addMsgAllClientBut(char *msg, client_t *p, int id); extern void addMsgAllClient(char *msg, int id); +extern void addMsgAllClientSeesTux(char *msg, tux_t *tux, int id); extern tux_t *getServerTux(); +extern client_t *getClientFromTux(tux_t *tux); extern void eventClientListBuffer(); extern void sendInfoCreateClient(client_t *client); extern void eventServer(); diff --git a/include/shot.h b/include/shot.h index 4ec8acf..fa7516a 100644 --- a/include/shot.h +++ b/include/shot.h @@ -9,6 +9,7 @@ #endif #include "list.h" #include "tux.h" +#include "arena.h" typedef struct shot_struct { @@ -45,6 +46,7 @@ extern void drawListShot(list_t *listShot); #endif extern int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h); extern void eventMoveListShot(list_t *listShot); +extern void checkShotIsInTuxScreen(arena_t *arena); extern void boundBombBall(shot_t *shot); extern void transformOnlyLasser(shot_t *shot); diff --git a/include/space.h b/include/space.h new file mode 100644 index 0000000..8f5ad7c --- /dev/null +++ b/include/space.h @@ -0,0 +1,36 @@ + +#ifndef SPACE_H + +#define SPACE_H + +#include "main.h" +#include "list.h" + +typedef struct space_struct +{ + int w; + int h; + int segW; + int segH; + list_t ***area; + list_t *list; + void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h); + void (*setStatus)(void *p, int x, int y, int w, int h); +} space_t; + +extern space_t *newSpace(int w, int h, int segW, int segH, + void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h), + void (*setStatus)(void *p, int x, int y, int w, int h)); + +extern void addObjectToSpace(space_t *p, void *item); +extern void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list); +extern void* getObjectFromSpaceWithID(space_t *p, int id); +extern int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h); +extern void delObjectFromSpace(space_t *p, void *item); +extern void delObjectFromSpaceWithMem(space_t *p, void *item, void *f); +extern void moveObjectInSpace(space_t *p, void *item, int move_x, int move_y); +extern void printSpace(space_t *p); +extern void destroySpace(space_t *p, void *f); + +#endif + diff --git a/include/tux.h b/include/tux.h index c07cf0a..2905ffe 100644 --- a/include/tux.h +++ b/include/tux.h @@ -5,6 +5,7 @@ #include "main.h" #include "list.h" +#include "arena.h" #define TUX_STEP 7 #define TUX_LAYER 0 @@ -56,6 +57,8 @@ #define ITEM_COUNT 16 +#define SHOT_CHECK_AREA 25 + #define GUN_SIMPLE 0 #define GUN_DUAL_SIMPLE 1 #define GUN_SCATTER 2 @@ -114,7 +117,7 @@ extern void drawListTux(list_t *listTux); extern void eventTuxIsDead(tux_t *tux); extern tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h); extern int isConflictTuxWithListTux(tux_t *tux, list_t *listTux); -extern void eventConflictTuxWithShot(list_t *listTux, list_t *listShot); +extern void eventConflictTuxWithShot(arena_t *arena); extern void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport); extern void tuxTeleport(tux_t *tux); extern void actionTux(tux_t *tux, int action); @@ -124,6 +127,8 @@ extern void getTuxProportion(tux_t *tux, int *x,int *y, int *w, int *h); extern void replaceTuxID(tux_t *tux, int id); extern int isTuxSeesTux(tux_t *tux, tux_t *thisTux); extern void setTuxProportion(tux_t *tux, int x, int y); +extern void getStatusTux(void *p, int *id, int *x,int *y, int *w, int *h); +extern void setStatusTux(void *p, int x, int y, int w, int h); extern void destroyTux(tux_t *tux); extern void quitTux(); diff --git a/modules/Makefile b/modules/Makefile index b8c86b8..c7eee69 100755 --- a/modules/Makefile +++ b/modules/Makefile @@ -13,8 +13,9 @@ modPipe: modWall: gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c list.c -o list.o + gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c space.c -o space.o gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c modWall.c -o modWall.o - gcc $(CFLAGS) -I../include -shared -fPIC -o modWall.so modWall.o list.o + gcc $(CFLAGS) -I../include -shared -fPIC -o modWall.so modWall.o list.o space.o clean: rm -rf *.o diff --git a/modules/list.c b/modules/list.c index 56f7e17..27b0ed8 100755 --- a/modules/list.c +++ b/modules/list.c @@ -168,6 +168,11 @@ void delListItem(list_t *p, int n, void *f) delList(p, n); } +void listDoEmpty(list_t *p) +{ + p->count = 0; +} + void destroyList(list_t *p) { assert( p != NULL ); diff --git a/modules/list.h b/modules/list.h index 8722baa..5a15786 100755 --- a/modules/list.h +++ b/modules/list.h @@ -25,6 +25,7 @@ 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 listDoEmpty(list_t *p); extern void destroyList(list_t *p); extern void destroyListItem(list_t *p,void *f); diff --git a/modules/modWall.c b/modules/modWall.c index ba8593a..bd1f8b6 100755 --- a/modules/modWall.c +++ b/modules/modWall.c @@ -10,6 +10,7 @@ #include "shot.h" #include "list.h" #include "gun.h" +#include "space.h" #ifndef PUBLIC_SERVER #include "interface.h" @@ -40,6 +41,8 @@ typedef struct wall_struct static export_fce_t *export_fce; +static space_t *spaceWall; +static space_t *spaceImgWall; static list_t *listWall; #ifndef PUBLIC_SERVER @@ -128,17 +131,15 @@ void eventConflictShotWithWall(list_t *listShot) tux_t *author; int i; - assert( listWall != NULL ); - assert( listShot != NULL ); - for( i = 0 ; i < listShot->count ; i++ ) { thisShot = (shot_t *)listShot->list[i]; assert( thisShot != NULL ); - if( isConflictWithListWall(listWall, thisShot->x, thisShot->y, thisShot->w, thisShot->h) != NULL ) + if( isConflictWithObjectFromSpace(spaceWall, thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) { - author = export_fce->fce_getTuxID( listShot, thisShot->author_id ); + author = getObjectFromSpaceWithID( + export_fce->fce_getCurrentArena()->spaceTux, thisShot->author_id ); if( author != NULL && author->bonus == BONUS_GHOST && @@ -165,6 +166,48 @@ void destroyWall(wall_t *p) free(p); } +static void getStatusWall(void *p, int *id, int *x, int *y, int *w, int *h) +{ + wall_t *wall; + + wall = p; + + *id = -1; + *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; +} + +static void getStatusImgWall(void *p, int *id, int *x, int *y, int *w, int *h) +{ + wall_t *wall; + + wall = p; + + *id = -1; + *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) +{ +} + static void cmd_wall(char *line) { char str_x[STR_NUM_SIZE]; @@ -200,13 +243,22 @@ static void cmd_wall(char *line) atoi(str_layer) ); #endif - addList(listWall, new); + if( spaceWall == NULL ) + { + spaceWall = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, + 320, 240, getStatusWall, setStatusWall); + + spaceImgWall = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, + 320, 240, getStatusImgWall, setStatusImgWall); + } + + addObjectToSpace(spaceWall, new); + addObjectToSpace(spaceImgWall, new); } int init(export_fce_t *p) { export_fce = p; - listWall = newList(); return 0; @@ -214,12 +266,15 @@ int init(export_fce_t *p) #ifndef PUBLIC_SERVER -int draw() +int draw(int x, int y, int w, int h) { wall_t *thisWall; int i; - assert( listWall != NULL ); + assert( spaceWall != NULL ); + + listDoEmpty(listWall); + getObjectFromSpace(spaceImgWall, x, y, w, h, listWall); for( i = 0 ; i < listWall->count ; i++ ) { @@ -228,6 +283,8 @@ int draw() drawWall(thisWall); } + //printSpace(spaceWall); + return 0; } #endif @@ -241,14 +298,7 @@ int event() int isConflict(int x, int y, int w, int h) { - if( isConflictWithListWall(listWall, x, y, w, h) != NULL ) - { - return 1; - } - else - { - return 0; - } + return isConflictWithObjectFromSpace(spaceWall, x, y, w, h); } void cmd(char *line) @@ -258,7 +308,7 @@ void cmd(char *line) int destroy() { - destroyListItem(listWall, destroyWall); + destroyList(listWall); return 0; } diff --git a/src/Makefile b/src/Makefile index aa1bad1..57e51d8 100755 --- a/src/Makefile +++ b/src/Makefile @@ -9,8 +9,8 @@ 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 idManager.o storage.o font.o list.o modules.o image.o layer.o director.o\ - configFile.o tux.o main.o checkFront.o\ +FILES = interface.o space.o idManager.o storage.o font.o list.o modules.o\ + image.o layer.o director.o configFile.o tux.o main.o checkFront.o\ screen.o screen_world.o shot.o myTimer.o panel.o net_multiplayer.o \ buffer.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 \ @@ -24,6 +24,9 @@ tuxanci-ng: $(FILES) main.o: main.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/main.o -c main.c +space.o: space.c ../include/space.h + $(CC) $(CFLAGS) -o $(BUILD_DIR)/space.o -c space.c + interface.o: interface.c ../include/interface.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/interface.o -c interface.c diff --git a/src/arena.c b/src/arena.c index 98ec0d8..5b11bcb 100644 --- a/src/arena.c +++ b/src/arena.c @@ -29,7 +29,7 @@ arena_t* getCurrentArena() return currentArena; } -arena_t* newArena() +arena_t* newArena(int w, int h) { arena_t *new; new = malloc( sizeof(arena_t) ); @@ -39,10 +39,17 @@ arena_t* newArena() strcpy(new->music, ""); #endif + new->w = w; + new->h = h; + new->listTimer = newList(); - new->listTux = newList(); + + //new->listTux = newList(); + //new->listItem = newList(); + new->spaceTux = newSpace(w, h, 320, 240, getStatusTux, setStatusTux); + new->spaceItem = newSpace(w, h, 320, 240, getStatusItem, setStatusItem); + new->listShot = newList(); - new->listItem = newList(); return new; } @@ -54,9 +61,9 @@ int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) int isFreeSpace(arena_t *arena, int x, int y, int w, int h) { - if( isConflictWithListTux(arena->listTux, x, y, w, h) )return 0; + if( isConflictWithObjectFromSpace(arena->spaceTux, 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( isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h) )return 0; if( isConflictModule(x, y, w, h) )return 0; //if( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0; //if( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; @@ -74,8 +81,8 @@ void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h) assert( y != NULL ); do{ - z_x = random() % arena->w; - z_y = random() % arena->h; + z_x = random() % WINDOW_SIZE_X;//arena->w; + z_y = random() % WINDOW_SIZE_Y;//arena->h; }while( isFreeSpace(arena, z_x, z_y ,w ,h) == 0 ); *x = z_x; @@ -122,6 +129,10 @@ void drawArena(arena_t *arena) tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + if( tux == NULL ) + { + return; + } /* screen_x = tux->x - WINDOW_SIZE_X/2; screen_y = tux->y - WINDOW_SIZE_Y/2; @@ -143,14 +154,29 @@ void drawArena(arena_t *arena) } - drawListTux(arena->listTux); + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceTux, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp); + drawListTux(listHelp); + + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceItem, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp); + drawListItem(listHelp); + + printSpace(arena->spaceItem); + + //drawListTux(arena->listTux); //drawListWall(arena->listWall); //drawListTeleport(arena->listTeleport); //drawListPipe(arena->listPipe); drawListShot(arena->listShot); - drawListItem(arena->listItem); + //drawListItem(arena->listItem); + drawModule(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); +/* + my_time_t t; + t = getMyTime(); +*/ if( tux == NULL ) { drawLayerCenter(WINDOW_SIZE_X/2, WINDOW_SIZE_Y/2); @@ -159,6 +185,8 @@ void drawArena(arena_t *arena) { drawLayerCenter(tux->x, tux->y); } + +// printf("time = %d\n", getMyTime() - t ); } #endif @@ -168,31 +196,32 @@ void eventArena(arena_t *arena) int i; //eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); - eventConflictTuxWithShot(arena->listTux, arena->listShot); + //eventConflictTuxWithShot(arena); for( i = 0 ; i < 8 ; i++) { eventMoveListShot(arena->listShot); + checkShotIsInTuxScreen(arena); //eventConflictShotWithWall(arena->listWall, arena->listShot); //eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); //eventConflictShotWithPipe(arena->listPipe, arena->listShot); - eventConflictShotWithItem(arena->listItem, arena->listShot); - eventConflictTuxWithShot(arena->listTux, arena->listShot); + eventConflictShotWithItem(arena); + eventConflictTuxWithShot(arena); eventModule(); } - eventListItem(arena->listItem); + eventListItem(arena->spaceItem); - eventListTux(arena->listTux); + eventListTux(arena->spaceTux->list); eventTimer(arena->listTimer); } void destroyArena(arena_t *p) { - destroyListItem(p->listTux, destroyTux); + destroySpace(p->spaceTux, destroyTux); + destroySpace(p->spaceItem, destroyItem); destroyListItem(p->listShot, destroyShot); - destroyListItem(p->listItem, destroyItem); destroyTimer(p->listTimer); free(p); } diff --git a/src/arenaFile.c b/src/arenaFile.c index f0971b3..52f31c0 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -68,7 +68,7 @@ static void cmd_loadMusic(char *line) addMusic(str_file, str_name, MUSIC_GROUP_USER); } -static void cmd_arena(arena_t *arena, char *line) +static void cmd_arena(arena_t **arena, char *line) { char str_image[STR_SIZE]; char str_w[STR_SIZE]; @@ -78,9 +78,12 @@ static void cmd_arena(arena_t *arena, char *line) if( getValue(line, "w", str_w, STR_SIZE) != 0 )return; if( getValue(line, "h", str_h, STR_SIZE) != 0 )return; - arena->background = getImage(IMAGE_GROUP_USER, str_image); - arena->w = atoi(str_w); - arena->h = atoi(str_h); + (*arena) = newArena(atoi(str_w), atoi(str_h)); + (*arena)->background = getImage(IMAGE_GROUP_USER, str_image); + //(*arena)->w = atoi(str_w); + //(*arena)->h = atoi(str_h); + setCurrentArena(*arena); + printf("new arena\n"); } static void cmd_playMusic(arena_t *arena, char *line) @@ -167,7 +170,6 @@ arena_t* getArena(int id) int i; ts = (textFile_t *) listArenaFile->list[id]; - arena = newArena(); for( i = 0 ; i < ts->text->count ; i++ ) { @@ -179,7 +181,7 @@ arena_t* getArena(int id) #ifndef PUBLIC_SERVER if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line); if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line); - if( strncmp(line, "arena", 5) == 0 )cmd_arena(arena, line); + if( strncmp(line, "arena", 5) == 0 )cmd_arena(&arena, line); if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line); #endif @@ -93,7 +93,16 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + client_t *thisClient; + + thisClient = getClientFromTux(tux); + + if( thisClient != NULL ) + { + proto_send_shot_server(PROTO_SEND_ONE, thisClient, shot); + } + + proto_send_shot_server(PROTO_SEND_ALL_SEES_TUX, thisClient, shot); } } @@ -178,7 +187,7 @@ static void timer_addShotTimer(void *p) id = * ((int *)p); free(p); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux == NULL )return; @@ -209,7 +218,7 @@ static void timer_addLaserTimer(void *p) id = * ((int *)p); free(p); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux == NULL )return; @@ -281,7 +290,7 @@ static void putInGunMine(tux_t *tux) proto_send_additem_server(PROTO_SEND_ALL, NULL, item); } - addList(arena->listItem, item ); + addObjectToSpace(arena->spaceItem, item ); } } } diff --git a/src/idManager.c b/src/idManager.c index 9c866c9..3162771 100644 --- a/src/idManager.c +++ b/src/idManager.c @@ -81,6 +81,11 @@ void delID(int id) void replaceID(int old_id, int new_id) { + if( old_id == new_id ) + { + return; + } + delID(old_id); if( new_id != -1 ) @@ -128,6 +128,7 @@ item_t* newItem(int x, int y, int type, int author_id) return new; } +/* item_t* getItemID(list_t *listItem, int id) { item_t *thisItem; @@ -148,6 +149,31 @@ item_t* getItemID(list_t *listItem, int id) return NULL; } +*/ + +void getStatusItem(void *p, int *id, int *x, int *y ,int *w, int *h) +{ + item_t *item; + + item = p; + + *id = item->id; + *x = item->x; + *y = item->y; + *w = item->w; + *h = item->h; +} + +void setStatusItem(void *p, int x, int y, int w, int h) +{ + item_t *item; + + item = p; + item->x = x; + item->y = y; + item->w = w; + item->h = h; +} void replaceItemID(item_t *item, int id) { @@ -155,7 +181,7 @@ void replaceItemID(item_t *item, int id) item->id = id; } -void addNewItem(list_t *listItem, int author_id) +void addNewItem(space_t *spaceItem, int author_id) { #ifndef PUBLIC_SERVER char msg[STR_SIZE]; @@ -214,7 +240,7 @@ void addNewItem(list_t *listItem, int author_id) #endif item = newItem(new_x, new_y, type, author_id); - addList(listItem, item); + addObjectToSpace(spaceItem, item); if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { @@ -254,7 +280,7 @@ void drawListItem(list_t *listItem) #endif -void eventListItem(list_t *listItem) +void eventListItem(space_t *spaceItem) { my_time_t currentTime; item_t *thisItem; @@ -262,11 +288,11 @@ void eventListItem(list_t *listItem) currentTime = getMyTime(); - assert( listItem != NULL ); + assert( spaceItem != NULL ); - for( i = 0 ; i < listItem->count ; i++ ) + for( i = 0 ; i < spaceItem->list->count ; i++ ) { - thisItem = (item_t *)listItem->list[i]; + thisItem = (item_t *)spaceItem->list->list[i]; assert( thisItem != NULL ); thisItem->count++; @@ -302,7 +328,7 @@ void eventListItem(list_t *listItem) case ITEM_BIG_EXPLOSION : if( thisItem->frame == ITEM_EXPLOSION_MAX_FRAME ) { - delListItem(listItem, i, destroyItem); + delObjectFromSpaceWithMem(spaceItem, thisItem, destroyItem); i--; } break; @@ -322,6 +348,7 @@ void eventListItem(list_t *listItem) } } +/* int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h) { item_t *thisItem; @@ -343,15 +370,10 @@ int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h) return 0; } +*/ -void mineExplosion(list_t *listItem, item_t *item) +void mineExplosion(space_t *spaceItem, item_t *item) { - int index; - - index = searchListItem(listItem, item); - - if( index == -1 )return; - /* x = ( item->x + item->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2; y = ( item->y + item->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2; @@ -373,12 +395,13 @@ void mineExplosion(list_t *listItem, item_t *item) proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion); } - addList(listItem, item_explosion ); + addObjectToSpace(spaceItem, item_explosion ); } - delListItem(listItem, index, destroyItem); + delObjectFromSpaceWithMem(spaceItem, item, destroyItem); } +/* void eventConflictShotWithItem(list_t *listItem, list_t *listShot) { shot_t *thisShot; @@ -446,6 +469,68 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot) } } } +*/ + +void eventConflictShotWithItem(arena_t *arena) +{ + shot_t *thisShot; + item_t *thisItem; + int i, j; + + if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return; + } + + for( i = 0 ; i < arena->listShot->count ; i++ ) + { + bool_t isDelShot; + + isDelShot = FALSE; + thisShot = (shot_t *)arena->listShot->list[i]; + assert( thisShot != NULL ); + + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceItem, thisShot->x, thisShot->y, thisShot->w, thisShot->h, listHelp); + + for( j = 0 ; j < listHelp->count ; j++ ) + { + thisItem = (item_t *)listHelp->list[j]; + assert( thisItem != NULL ); + + switch( thisItem->type ) + { + case ITEM_MINE : + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem); + } + + mineExplosion(arena->spaceItem, thisItem); + } + break; + + case ITEM_EXPLOSION : + case ITEM_BIG_EXPLOSION : + isDelShot = TRUE; + break; + } + } + + if( isDelShot ) + { + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + proto_send_delshot_server(PROTO_SEND_ALL, NULL, thisShot); + } + + delListItem(arena->listShot, i, destroyShot); + i--; + } + } +} static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item) { @@ -464,7 +549,7 @@ static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item) { tux_t *author; - author = getTuxID(getCurrentArena()->listTux, item->author_id); + author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, item->author_id); if( author != NULL ) { @@ -514,14 +599,8 @@ static void tuxGiveGun(tux_t *tux, item_t *item) } -int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item) +void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem) { - int index; - - index = searchListItem(listItem, item); - - if( index == -1 ) return -1; - switch( item->type ) { case GUN_TOMMY : @@ -531,15 +610,13 @@ int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item) case GUN_MINE : case GUN_BOMBBALL : tuxGiveGun(tux, item); - delListItem(listItem, index, destroyItem); - return index; + delObjectFromSpace(spaceItem, item); break; case ITEM_MINE : if( tux->bonus != BONUS_GHOST ) { - mineExplosion(listItem, item); - return index; + mineExplosion(spaceItem, item); } break; @@ -548,22 +625,19 @@ int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item) eventTuxIsDeadWithItem(tux, item); break; - case BONUS_SPEED : - case BONUS_SHOT : - case BONUS_TELEPORT : - case BONUS_GHOST : - case BONUS_4X : - case BONUS_HIDDEN : - tuxGiveBonus(tux, item); - delListItem(listItem, index, destroyItem); - return index; - break; - } - - return -1; + case BONUS_SPEED : + case BONUS_SHOT : + case BONUS_TELEPORT : + case BONUS_GHOST : + case BONUS_4X : + case BONUS_HIDDEN : + tuxGiveBonus(tux, item); + delObjectFromSpace(spaceItem, item); + break; + } } -void eventGiveTuxListItem(tux_t *tux, list_t *listItem) +void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem) { item_t *thisItem; int x, y, w, h; @@ -574,7 +648,7 @@ void eventGiveTuxListItem(tux_t *tux, list_t *listItem) return; } - assert( listItem != NULL ); + assert( spaceItem != NULL ); assert( tux != NULL ); if( tux->status == TUX_STATUS_DEAD ) @@ -584,23 +658,20 @@ void eventGiveTuxListItem(tux_t *tux, list_t *listItem) getTuxProportion(tux, &x, &y, &w, &h); - for( i = 0 ; i < listItem->count ; i++ ) + listDoEmpty(listHelp); + getObjectFromSpace(spaceItem, x, y, w, h, listHelp); + + for( i = 0 ; i < listHelp->count ; i++ ) { - thisItem = (item_t *)listItem->list[i]; + thisItem = (item_t *)listHelp->list[i]; assert( thisItem != NULL ); - if( conflictSpace(x, y, w, h, thisItem->x, thisItem->y, thisItem->w, thisItem->h) ) + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem); - } - - if( eventGiveTuxItem(tux, listItem, thisItem) >= 0 ) - { - i--; - } + proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem); } + + eventGiveTuxItem(tux, thisItem, spaceItem); } } diff --git a/src/language.c b/src/language.c index d1b20e8..06cb9c1 100644 --- a/src/language.c +++ b/src/language.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -42,6 +41,7 @@ int initLanguage() char *head; sprintf(path, "%s/lang.conf", getHomeDirector()); + printf("open %s\n", path); languageTypeFile = loadTextFile(path); if( languageTypeFile == NULL ) @@ -168,6 +168,11 @@ void delListItem(list_t *p, int n, void *f) delList(p, n); } +void listDoEmpty(list_t *p) +{ + p->count = 0; +} + void destroyList(list_t *p) { assert( p != NULL ); @@ -21,6 +21,8 @@ static int my_argc; static char **my_argv; +list_t *listHelp; + char* getParam(char *s) { int i; @@ -100,11 +102,16 @@ void accessExistFile(const char *s) int main(int argc, char *argv[]) { + listHelp = newList(); + srand( (unsigned) time(NULL) ); my_argc = argc; my_argv = argv; - +/* + test_space(); + exit(0); +*/ #ifndef PUBLIC_SERVER startGame(); #endif diff --git a/src/modules.c b/src/modules.c index 6ba3234..bf7eec6 100755 --- a/src/modules.c +++ b/src/modules.c @@ -38,7 +38,7 @@ static export_fce_t export_fce = .fce_getNetTypeGame = getNetTypeGame, .fce_getTuxProportion = getTuxProportion, .fce_setTuxProportion = setTuxProportion, - .fce_getTuxID = getTuxID, + //.fce_getTuxID = getTuxID, .fce_getCurrentArena = getCurrentArena, .fce_conflictSpace = conflictSpace, @@ -170,7 +170,7 @@ void cmdModule(char *s) #ifndef PUBLIC_SERVER -void drawModule() +void drawModule(int x, int y, int w, int h) { int i; @@ -178,7 +178,7 @@ void drawModule() { module_t *this; this = (module_t *)listModule->list[i]; - this->fce_draw(); + this->fce_draw(x, y, w, h); } } diff --git a/src/proto.c b/src/proto.c index c9aa408..062693e 100644 --- a/src/proto.c +++ b/src/proto.c @@ -58,7 +58,7 @@ static void proto_send(int type, client_t *client, char *msg) } else { - sendAllClientSeesTux(msg, getServerTux()); + sendAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); } break; default : @@ -85,6 +85,16 @@ static void proto_check(int type, client_t *client, char *msg, int id) assert( client != NULL ); addMsgAllClientBut(msg, client, id); break; + case PROTO_SEND_ALL_SEES_TUX : + if( client != NULL ) + { + addMsgAllClientSeesTux(msg, client->tux, id); + } + else + { + addMsgAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), id); + } + break; default : assert( ! "Premenna type ma zlu hodnotu !" ); break; @@ -159,7 +169,7 @@ void proto_recv_hello_server(client_t *client, char *msg) client->tux = newTux(); client->tux->control = TUX_CONTROL_NET; - addList(getCurrentArena()->listTux, client->tux); + addObjectToSpace(getCurrentArena()->spaceTux, client->tux); if( strlen(name) > STR_NAME_SIZE-1 ) { @@ -179,7 +189,7 @@ void proto_send_status_server(int type, client_t *client) "maxclients: %d\n" "uptime: %d\n" "arena: %s\n", - TUXANCI_NG_VERSION, getCurrentArena()->listTux->count, + TUXANCI_NG_VERSION, getCurrentArena()->spaceTux->list->count, getServerMaxClients(), (unsigned int)getUpdateServer(), getArenaNetName( getChoiceArenaId() ) ); @@ -306,10 +316,11 @@ void proto_recv_init_client(char *msg) tux->x = x; tux->y = y; tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); getSettingNameRight(tux->name); - addList(getCurrentArena()->listTux, tux); + addObjectToSpace(getCurrentArena()->spaceTux, tux); } #endif @@ -337,7 +348,7 @@ void proto_recv_event_client(char *msg) sscanf(msg, "%s %d %d", cmd, &id, &action); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux != NULL ) { @@ -393,6 +404,8 @@ void proto_send_newtux_server(int type, client_t *client, tux_t *tux) y = tux->y; } + getTuxProportion(tux, &x, &y, NULL, NULL); + sprintf(msg, "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n", tux->id ,x, y, tux->status, tux->position ,tux->frame, tux->score, tux->name, tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], @@ -426,7 +439,7 @@ void proto_recv_newtux_client(char *msg) cmd, &id, &x, &y, &status, &position, &frame, &score, name, &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux == NULL ) { @@ -436,12 +449,11 @@ void proto_recv_newtux_client(char *msg) tux = newTux(); tux->control = TUX_CONTROL_NET; - addList(getCurrentArena()->listTux, tux); + addObjectToSpace(getCurrentArena()->spaceTux, tux); } replaceTuxID(tux, id); - tux->x = x; - tux->y = y; + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); tux->status = status; tux->position = position; tux->frame = frame; @@ -485,7 +497,7 @@ void proto_recv_kill_client(char *msg) sscanf(msg, "%s %d", cmd, &id); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux != NULL ) { @@ -518,7 +530,7 @@ void proto_recv_score_client(char *msg) sscanf(msg, "%s %d %d", cmd, &id, &score); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux != NULL ) { @@ -557,18 +569,18 @@ void proto_recv_deltux_client(char *msg) sscanf(msg, "%s %d", cmd, &id); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux != NULL ) { char term_msg[STR_SIZE]; - int index; + //int index; sprintf(term_msg, "tux with id %d is disconnect\n", tux->id); appendTextInTerm(term_msg); - index = searchListItem(getCurrentArena()->listTux, tux); - delListItem(getCurrentArena()->listTux, index, destroyTux); + //index = searchListItem(getCurrentArena()->listTux, tux); + delObjectFromSpaceWithMem(getCurrentArena()->spaceTux, tux, destroyTux); } } @@ -610,7 +622,7 @@ void proto_recv_additem_client(char *msg) proto_send_check_client(check_id); - if( ( item = getItemID(getCurrentArena()->listItem, id) ) != NULL ) + if( ( item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id) ) != NULL ) { return; } @@ -627,7 +639,7 @@ void proto_recv_additem_client(char *msg) item->count = count; item->frame = frame; - addList(getCurrentArena()->listItem, item); + addObjectToSpace(getCurrentArena()->spaceItem, item); } #endif @@ -674,8 +686,8 @@ void proto_recv_item_client(char *msg) arena = getCurrentArena(); - item = getItemID(arena->listItem, item_id); - tux = getTuxID(arena->listTux, tux_id); + item = getObjectFromSpaceWithID(arena->spaceItem, item_id); + tux = getObjectFromSpaceWithID(arena->spaceTux, tux_id); if( item == NULL) { @@ -684,11 +696,11 @@ void proto_recv_item_client(char *msg) if( tux != NULL ) { - eventGiveTuxItem(tux, arena->listItem, item); + eventGiveTuxItem(tux, item, arena->spaceItem); } else { - mineExplosion(arena->listItem, item); + mineExplosion(arena->spaceItem, item); } } diff --git a/src/screen_world.c b/src/screen_world.c index de2d591..077153f 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -43,6 +43,9 @@ static my_time_t lastServerLag; static bool_t isScreenWorldInit = FALSE; static bool_t isEndWorld; +static tux_t *tuxWithControlRightKeyboard; +static tux_t *tuxWithControlLeftKeyboard; + bool_t isScreenWorldInicialized() { return isScreenWorldInit; @@ -65,7 +68,6 @@ void setWorldArena(int id) { arena = getArena(id); playMusic(arena->music, MUSIC_GROUP_USER); - setCurrentArena(arena); } void setMaxCountRound(int n) @@ -118,29 +120,32 @@ void prepareArena() { case NET_GAME_TYPE_NONE : setWorldArena( getChoiceArenaId() ); - addNewItem(arena->listItem, ID_UNKNOWN); + addNewItem(arena->spaceItem, ID_UNKNOWN); getSettingCountRound(&max_count); tux = newTux(); tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + tuxWithControlRightKeyboard = tux; getSettingNameRight(tux->name); - addList(arena->listTux, tux); + addObjectToSpace(arena->spaceTux, tux); tux = newTux(); tux->control = TUX_CONTROL_KEYBOARD_LEFT; + tuxWithControlLeftKeyboard = tux; getSettingNameLeft(tux->name); - addList(arena->listTux, tux); + addObjectToSpace(arena->spaceTux, tux); break; case NET_GAME_TYPE_SERVER : setWorldArena( getChoiceArenaId() ); - addNewItem(arena->listItem, ID_UNKNOWN); + addNewItem(arena->spaceItem, ID_UNKNOWN); getSettingCountRound(&max_count); tux = newTux(); tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + tuxWithControlRightKeyboard = tux; getSettingNameRight(tux->name); - addList(arena->listTux, tux); + addObjectToSpace(arena->spaceTux, tux); break; case NET_GAME_TYPE_CLIENT : @@ -172,10 +177,9 @@ void drawWorld() if( arena != NULL ) { drawArena(arena); - drawPanel(arena->listTux); + drawPanel(arena->spaceTux->list); } - drawModule(); drawTerm(); } @@ -393,25 +397,32 @@ static void eventEnd() tux_t* getControlTux(int control_type) { - arena_t *arena; - tux_t *thisTux; - int i; - - arena = getCurrentArena(); - - for( i = 0 ; i < arena->listTux->count ; i++ ) + switch(control_type) { - thisTux = (tux_t *)(arena->listTux->list[i]); - - if( thisTux->control == control_type ) - { - return thisTux; - } + case TUX_CONTROL_KEYBOARD_RIGHT : + return tuxWithControlRightKeyboard; + break; + case TUX_CONTROL_KEYBOARD_LEFT : + return tuxWithControlLeftKeyboard; + break; } return NULL; } +void setControlTux(tux_t *tux, int control_type) +{ + switch(control_type) + { + case TUX_CONTROL_KEYBOARD_RIGHT : + tuxWithControlRightKeyboard = tux; + break; + case TUX_CONTROL_KEYBOARD_LEFT : + tuxWithControlLeftKeyboard = tux; + break; + } +} + void tuxControl(tux_t *p) { assert( p != NULL ); @@ -479,9 +490,9 @@ static void setAnalyze() restartAnalyze(); - for( i = 0 ; i < arena->listTux->count ; i++ ) + for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) { - tux = (tux_t *)(arena->listTux->list[i]); + tux = (tux_t *)(arena->spaceTux->list->list[i]); addAnalyze(tux->name, tux->score); } diff --git a/src/server.c b/src/server.c index b9a611e..3ca0637 100644 --- a/src/server.c +++ b/src/server.c @@ -103,10 +103,10 @@ static void eventPeriodicSyncClient(void *p_nothink) } #ifndef PUBLIC_SERVER - thisTux = (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]); - + thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); if( isTuxSeesTux(thisClientSend->tux, thisTux) ) proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux); + #endif for( j = 0 ; j < listClient->count; j++) @@ -261,7 +261,7 @@ client_t* newSdlUdpClient(sock_sdl_udp_t *sock_sdl_udp) void destroyClient(client_t *p) { - int index; +// int index; assert( p != NULL ); @@ -282,8 +282,11 @@ void destroyClient(client_t *p) #ifdef PUBLIC_SERVER addPlayerInHighScore(p->tux->name, p->tux->score); #endif +/* index = searchListItem(getCurrentArena()->listTux, p->tux); delListItem(getCurrentArena()->listTux, index, destroyTux); +*/ + delObjectFromSpaceWithMem(getCurrentArena()->spaceTux, p->tux, destroyTux); } free(p); @@ -413,9 +416,49 @@ void addMsgAllClient(char *msg, int id) addMsgAllClientBut(msg, NULL, id); } +void addMsgAllClientSeesTux(char *msg, tux_t *tux, int id) +{ + int i; + + assert( msg != NULL ); + + for( i = 0 ; i < listClient->count ; i++ ) + { + client_t *thisClient; + tux_t *thisTux; + + thisClient = (client_t *)listClient->list[i]; + thisTux = (tux_t *)thisClient->tux; + + if( tux != thisTux && + isTuxSeesTux(thisTux, tux) ) + { + addMsgClient(thisClient, msg, id); + } + } +} + tux_t *getServerTux() { - return (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]); + return NULL; +} + +client_t *getClientFromTux(tux_t *tux) +{ + client_t *thisClient; + int i; + + for( i = 0 ; i < listClient->count; i++) + { + thisClient = (client_t *) listClient->list[i]; + + if( thisClient->tux == tux ) + { + return thisClient; + } + } + + return NULL; } void sendInfoCreateClient(client_t *client) @@ -430,8 +473,7 @@ void sendInfoCreateClient(client_t *client) proto_send_init_server(PROTO_SEND_ONE, client, client); #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, client, - (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]) ); + proto_send_newtux_server(PROTO_SEND_ONE, client, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT) ); #endif for( i = 0 ; i < listClient->count; i++) @@ -446,9 +488,9 @@ void sendInfoCreateClient(client_t *client) } } - for( i = 0 ; i < getCurrentArena()->listItem->count; i++) + for( i = 0 ; i < getCurrentArena()->spaceItem->list->count; i++) { - thisItem = (item_t *) getCurrentArena()->listItem->list[i]; + thisItem = (item_t *) getCurrentArena()->spaceItem->list->list[i]; proto_send_additem_server(PROTO_SEND_ONE, client, thisItem); } } @@ -72,7 +72,7 @@ shot_t* newShot(int x,int y, int px, int py, int gun, int author_id) new->position = POSITION_UNKNOWN; - author = getTuxID(getCurrentArena()->listTux, author_id); + author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id); if( author != NULL ) { @@ -311,6 +311,86 @@ void eventMoveListShot(list_t *listShot) } } +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) ); +} + + +void checkShotIsInTuxScreen(arena_t *arena) +{ + return; +/* + int screen_x, screen_y; + shot_t *thisShot; + tux_t *thisTux; + int speed; + int i, j; + + if( getNetTypeGame() != NET_GAME_TYPE_SERVER ) + { + return; + } + + for( i = 0 ; i < arena->listTux->count ; i++ ) + { + thisTux = (tux_t *)arena->listTux->list[i]; + + if( thisTux->control != TUX_CONTROL_NET ) + { + continue; + } + + getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y); + + for( j = 0 ; j < arena->listShot->count ; j++ ) + { + thisShot = (shot_t *)arena->listShot->list[j]; + + speed = getSppedShot(thisShot); + + if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h, + screen_x-speed, screen_y, speed, WINDOW_SIZE_Y) ) + { + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + + if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h, + screen_x+WINDOW_SIZE_X, screen_y, speed, WINDOW_SIZE_Y) ) + { + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + + if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h, + screen_x, screen_y-speed, WINDOW_SIZE_X, speed) ) + { + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + + if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h, + screen_x, screen_y+WINDOW_SIZE_Y, WINDOW_SIZE_X, speed) ) + { + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + } + } +*/ +} + /* static int getSppedShot(shot_t *shot) { diff --git a/src/space.c b/src/space.c new file mode 100644 index 0000000..ce662f0 --- /dev/null +++ b/src/space.c @@ -0,0 +1,370 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "space.h" + +#ifdef DEBUG_SPACE + +typedef struct recv_struct +{ + int id; + int x, y; + int w, h; +} recv_t; + +recv_t* newRecv(int x , int y, int w, int h) +{ + static int last_id = 0; + + recv_t *new; + + new = malloc( sizeof(recv_t) ); + memset(new, 0, sizeof(recv_t)); + + new->id = ++last_id; + new->x = x; + new->y = y; + new->w = w; + new->h = h; + + return new; +} + +void getStatus(void *p, int *id, int *x, int *y, int *w, int *h) +{ + recv_t *recv; + + recv = p; + + *id = recv->id; + *x = recv->x; + *y = recv->y; + *w = recv->w; + *h = recv->h; +} + +void setStatus(void *p, int x, int y, int w, int h) +{ + recv_t *recv; + + recv = p; + + recv->x = x; + recv->y = y; + recv->w = w; + recv->h = h; + recv->x = x; +} + +void destroyRecv(recv_t *p) +{ + free(p); +} + +#endif + +static int my_conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) +{ + return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1); +} + +space_t *newSpace(int w, int h, int segW, int segH, + void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h), + void (*setStatus)(void *p, int x, int y, int w, int h)) +{ + space_t *new; + int i, j; + + new = malloc( sizeof(space_t) ); + memset(new, 0, sizeof(space_t)); + + new->w = w / segW + 1; + new->h = h / segH + 1; + new->segW = segW; + new->segH = segH; + new->getStatus = getStatus; + new->setStatus = setStatus; + new->list = newList(); + + new->area = malloc( new->w * sizeof(list_t **) ); + + for( i = 0 ; i < new->w ; i++ ) + { + new->area[i] = malloc( new->h * sizeof(list_t *) ); + } + + for( i = 0 ; i < new->h ; i++ ) + { + for( j = 0 ; j < new->w ; j++ ) + { + new->area[j][i] = newList(); + } + } + + return new; +} + +static void getSegment(space_t *p, int x, int y, int w, int h, + int *segX, int *segY, int *segW, int *segH) +{ + *segX = x / p->segW; + *segY = y / p->segH; + *segW = ( (x+w) / p->segW + 1 ) - *segX; + *segH = ( (y+h) / p->segH + 1 ) - *segY; +} + +void addObjectToSpace(space_t *p, void *item) +{ + int segX, segY, segW, segH; + int id, x, y, w, h; + int i, j; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for( i = segY ; i < segY + segH ; i++ ) + { + for( j = segX ; j < segX + segW ; j++ ) + { + addList(p->area[j][i], item); + } + } + + addList(p->list, item); +} + +void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list) +{ + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; + + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for( i = segY ; i < segY + segH ; i++ ) + { + for( j = segX ; j < segX + segW ; j++ ) + { + void *this; + + for( k = 0 ; k < p->area[j][i]->count ; k++ ) + { + this = p->area[j][i]->list[k]; + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + + if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) && + searchListItem(list, this) == -1 ) + { + addList(list, this); + } + } + } + } +} + +void* getObjectFromSpaceWithID(space_t *p, int id) +{ + int this_id, x, y, w, h; + void *this; + int i; + + for( i = 0 ; i < p->list->count ; i++ ) + { + this = p->list->list[i]; + assert( this != NULL ); + + p->getStatus(this, &this_id, &x, &y, &w, &h); + + if( this_id == id ) + { + return this; + } + } + + return NULL; +} + +int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h) +{ + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; + + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for( i = segY ; i < segY + segH ; i++ ) + { + for( j = segX ; j < segX + segW ; j++ ) + { + void *this; + + for( k = 0 ; k < p->area[j][i]->count ; k++ ) + { + this = p->area[j][i]->list[k]; + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + + if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) ) + { + return 1; + } + } + } + } + + return 0; +} + +void delObjectFromSpace(space_t *p, void *item) +{ + int segX, segY, segW, segH; + int id, x, y, w, h; + int index; + int i, j; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for( i = segY ; i < segY + segH ; i++ ) + { + for( j = segX ; j < segX + segW ; j++ ) + { + index = searchListItem(p->area[j][i], item); + assert( index != -1 ); + delList(p->area[j][i], index); + } + } + + index = searchListItem(p->list, item); + assert( index != -1 ); + delList(p->list, index); +} + +void delObjectFromSpaceWithMem(space_t *p, void *item, void *f) +{ + void (*fce)(void *param); + + fce = f; + + delObjectFromSpace(p, item); + fce(item); +} + +void moveObjectInSpace(space_t *p, void *item, int move_x, int move_y) +{ + int old_segX, old_segY, old_segW, old_segH; + int new_segX, new_segY, new_segW, new_segH; + int id, x, y, w, h; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &old_segX, &old_segY, &old_segW, &old_segH); + getSegment(p, move_x, move_y, w, h, &new_segX, &new_segY, &new_segW, &new_segH); +/* + printf("%d %d %d %d -> %d %d %d %d \n", + old_segX, old_segY, old_segW, old_segH, + new_segX, new_segY, new_segW, new_segH); +*/ + if( old_segX != new_segX || old_segY != new_segY || + old_segW != new_segW || old_segH != new_segH ) + { + delObjectFromSpace(p, item); + p->setStatus(item, move_x, move_y, w, h); + addObjectToSpace(p, item); + return; + } + + p->setStatus(item, move_x, move_y, w, h); +} + +void printSpace(space_t *p) +{ + int i, j; + + printf("print space : \n"); + + for( i = 0 ; i < p->h ; i++ ) + { + for( j = 0 ; j < p->w ; j++ ) + { + printf("%3d ", p->area[j][i]->count); + } + + putchar('\n'); + } +} + +void destroySpace(space_t *p, void *f) +{ + void (*fce)(void *param); + int j, i; + + fce = f; + + //getObjectFromSpace(p, 0, 0, p->w * p->segW - 1 , p->h * p->segH - 1, list); + + destroyListItem(p->list, fce); + + for( i = 0 ; i < p->h ; i++ ) + { + for( j = 0 ; j < p->w ; j++ ) + { + destroyList(p->area[j][i]); + } + } + + for( i = 0 ; i < p->w ; i++ ) + { + free(p->area[i]); + } + + free(p->area); + free(p); +} + +#ifdef DEBUG_SPACE + +void test_space() +{ + space_t *space; + list_t *list; + int i, j; + + space = newSpace(5000, 2500, 320, 240, getStatus, setStatus); + + for( i = 1 ; i < 16 ; i++ ) + for( j = 1 ; j < 16 ; j++ ) + { + recv_t *this; + + this = newRecv(j*160, i*120, 32, 32); + //addToSpace(space, newRecv(j*550, i*550, 1, 1) ); + addObjectToSpace(space, this ); + delObjectFromSpaceWithMem(space, this, destroyRecv); + } + + list = newList(); + getObjectFromSpace(space, 640, 480, 800 , 600, list); + + printf("list->count = %d\n", list->count); + + for( i = 0 ; i < list->count ; i++ ) + { + recv_t *recv; + recv = list->list[i]; + + printf("%3d %3d %3d %3d\n", recv->x, recv->y, recv->w, recv->h); + } + + destroyList(list); + + printSpace(space); + + destroySpace(space, destroyRecv); +} + +#endif + @@ -221,6 +221,7 @@ void drawListTux(list_t *listTux) #endif +/* tux_t* getTuxID(list_t *listTux, int id) { tux_t *thisTux; @@ -241,6 +242,7 @@ tux_t* getTuxID(list_t *listTux, int id) return NULL; } +*/ void replaceTuxID(tux_t *tux, int id) { @@ -259,10 +261,11 @@ int isTuxSeesTux(tux_t *tux, tux_t *thisTux) getCenterScreen(&screen_x, &screen_y, tux->x, tux->y); - return conflictSpace(screen_x, screen_y, - WINDOW_SIZE_X, WINDOW_SIZE_Y, thisTux_x, thisTux_y, thisTux_w, thisTux_h); + return conflictSpace(screen_x-WINDOW_SIZE_X/4, screen_y-WINDOW_SIZE_Y/4, + WINDOW_SIZE_X*1.25, WINDOW_SIZE_Y*1.25, thisTux_x, thisTux_y, thisTux_w, thisTux_h); } +/* tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h) { tux_t *thisTux; @@ -286,7 +289,9 @@ tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h) return NULL; } +*/ +/* int isConflictTuxWithListTux(tux_t *tux, list_t *listTux) { tux_t *thisTux; @@ -320,6 +325,7 @@ int isConflictTuxWithListTux(tux_t *tux, list_t *listTux) return 0; } +*/ static void timer_spawnTux(void *p) { @@ -332,16 +338,16 @@ static void timer_spawnTux(void *p) free(p); arena = getCurrentArena(); - tux = getTuxID(arena->listTux, id); + tux = getObjectFromSpaceWithID(arena->spaceTux, id); if( tux == NULL )return; tux->status = TUX_STATUS_ALIVE; findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - setTuxProportion(tux, x, y); + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); tux->gun = GUN_SIMPLE; - addNewItem(arena->listItem, ID_UNKNOWN); + addNewItem(arena->spaceItem, ID_UNKNOWN); if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { @@ -357,7 +363,7 @@ static void timer_tuxCanShot(void *p) id = * ((int *)p); free(p); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux == NULL )return; @@ -372,7 +378,7 @@ static void timer_tuxCanSwitchGun(void *p) id = * ((int *)p); free(p); - tux = getTuxID(getCurrentArena()->listTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); if( tux == NULL )return; @@ -425,7 +431,7 @@ static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot) { tux_t *author; - author = getTuxID(getCurrentArena()->listTux, shot->author_id); + author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, shot->author_id); if( author != NULL ) { @@ -477,7 +483,7 @@ static void bombBallExplosion(shot_t *shot) y = ( shot->y + shot->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2; item = newItem(x, y, ITEM_BIG_EXPLOSION, shot->author_id ); - addList(getCurrentArena()->listItem, item ); + addObjectToSpace(getCurrentArena()->spaceItem, item ); if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { @@ -486,6 +492,7 @@ static void bombBallExplosion(shot_t *shot) } } +/* void eventConflictTuxWithShot(list_t *listTux, list_t *listShot) { shot_t *thisShot; @@ -543,6 +550,66 @@ void eventConflictTuxWithShot(list_t *listTux, list_t *listShot) } } } +*/ + +void eventConflictTuxWithShot(arena_t *arena) +{ + shot_t *thisShot; + tux_t *thisTux; + int i, j; + + for( i = 0 ; i < arena->listShot->count ; i++ ) + { + thisShot = (shot_t *)arena->listShot->list[i]; + assert( thisShot != NULL ); + + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceTux, thisShot->x, thisShot->y, + thisShot->w, thisShot->h, listHelp); + + for( j = 0 ; j < listHelp->count ; j++ ) + { + thisTux = listHelp->list[j]; + + if( thisTux->status == TUX_STATUS_ALIVE ) + { + if( thisShot->author_id == thisTux->id && + thisShot->isCanKillAuthor == FALSE ) + { + continue; + } + + if( thisTux->bonus == BONUS_TELEPORT ) + { + tuxTeleport(thisTux); + continue; + } + + if( thisShot->gun == GUN_BOMBBALL ) + { + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + bombBallExplosion(thisShot); + delListItem(arena->listShot, i, destroyShot); + i--; + } + + continue; + } + + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + eventTuxIsDeadWIthShot(thisTux, thisShot); + } + } + + delListItem(arena->listShot, i, destroyShot); + i--; + + continue; + } + } +} /* void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport) @@ -576,6 +643,7 @@ void moveTux(tux_t *tux, int n) { int px, py; int zal_x, zal_y; + int new_x, new_y; int x, y, w, h; arena_t *arena; @@ -628,36 +696,46 @@ void moveTux(tux_t *tux, int n) return; } + getTuxProportion(tux, &zal_x, &zal_y, &w, &h); + getCourse(tux->position, &px, &py); - zal_x = tux->x; - zal_y = tux->y; + new_x = zal_x; + new_y = zal_y; - tux->x += px * TUX_STEP; - tux->y += py * TUX_STEP; + new_x += px * TUX_STEP; + new_y += py * TUX_STEP; if( tux->bonus == BONUS_SPEED ) { - tux->x += px * TUX_STEP; - tux->y += py * TUX_STEP; + new_x += px * TUX_STEP; + new_y += py * TUX_STEP; } - - getTuxProportion(tux, &x, &y, &w, &h); - +/* + setTuxProportion(tux, new_x, new_y); if( tux->bonus != BONUS_GHOST && ( - isConflictTuxWithListTux(tux, arena->listTux) || + isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) || isConflictModule(x, y, w, h) ) ) { - tux->x = zal_x; - tux->y = zal_y; + setTuxProportion(tux, zal_x, zal_y); + return; } - else +*/ + + if( tux->bonus != BONUS_GHOST && ( + /*isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) ||*/ + isConflictModule(new_x, new_y, w, h) ) ) { - eventGiveTuxListItem(tux, getCurrentArena()->listItem); - tux->frame++; - if( tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME ) tux->frame = 0; + setTuxProportion(tux, zal_x, zal_y); + return; } + + setTuxProportion(tux, zal_x, zal_y); + moveObjectInSpace(arena->spaceTux, tux, new_x, new_y); + eventGiveTuxListItem(tux, getCurrentArena()->spaceItem); + tux->frame++; + if( tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME ) tux->frame = 0; } void switchTuxGun(tux_t *tux) @@ -817,7 +895,7 @@ static void eventBonus(tux_t *tux) tux->bonus = BONUS_NONE; - if( isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || + if( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ isConflictModule(x, y, w, h) ) { tux->bonus = BONUS_GHOST; @@ -859,7 +937,7 @@ void eventListTux(list_t *listTux) #endif pickUpGun(thisTux); eventBonus(thisTux); - eventGiveTuxListItem(thisTux, arena->listItem); + eventGiveTuxListItem(thisTux, arena->spaceItem); } } @@ -881,6 +959,23 @@ void setTuxProportion(tux_t *tux, int x, int y) tux->y = y + TUX_WIDTH / 2; } +void getStatusTux(void *p, int *id, int *x,int *y, int *w, int *h) +{ + tux_t *tux; + + tux = p; + *id = tux->id; + getTuxProportion(tux, x, y, w, h); +} + +void setStatusTux(void *p, int x, int y, int w, int h) +{ + tux_t *tux; + + tux = p; + setTuxProportion(tux, x, y); +} + void destroyTux(tux_t *tux) { assert( tux != NULL ); |