diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-05-22 20:13:25 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-05-22 20:13:25 +0000 |
| commit | a1e9bc7430ca827808a502f455b20a23ba15e31a (patch) | |
| tree | 0f5367068425be881657840c08756662510adf39 | |
| parent | 7055882c93022da3a6a1cf74cebf3d17c44ce6c4 (diff) | |
- dopisany skutocny ID manager
- objekt wall je ako modul
- oprava chyby, pri prepinani screenov sa nevyprazdnoval layer
- oprava chyby, pri odstraneni vsetkych obrazkov zo skupiny sa odstrani iba prvy obrazok
- oprava chyby, pri odstraneni vsetkej hudby zo skupiny sa odstrani iba prva hudba
PS: (asi) zajtra ten kod trochu esteticky upravim
git-svn-id: http://opensvn.csie.org/tuxanci_ng@53 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | arena/construction_site.map | 2 | ||||
| -rw-r--r-- | arena/for_a_good_night.map | 2 | ||||
| -rw-r--r-- | arena/in_a_captivity_of_8-bit.map | 1 | ||||
| -rw-r--r-- | arena/night_workshift.map | 1 | ||||
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | include/arena.h | 3 | ||||
| -rw-r--r-- | include/idManager.h | 18 | ||||
| -rw-r--r-- | include/main.h | 1 | ||||
| -rwxr-xr-x | modules/Makefile | 5 | ||||
| -rwxr-xr-x | modules/modWall.c | 261 | ||||
| -rwxr-xr-x | src/Makefile | 20 | ||||
| -rw-r--r-- | src/arena.c | 34 | ||||
| -rw-r--r-- | src/arenaFile.c | 81 | ||||
| -rw-r--r-- | src/dynamicInt.c | 1 | ||||
| -rw-r--r-- | src/idManager.c | 97 | ||||
| -rwxr-xr-x | src/image.c | 4 | ||||
| -rw-r--r-- | src/item.c | 14 | ||||
| -rwxr-xr-x | src/layer.c | 6 | ||||
| -rw-r--r-- | src/main.c | 8 | ||||
| -rw-r--r-- | src/music.c | 2 | ||||
| -rw-r--r-- | src/proto.c | 9 | ||||
| -rw-r--r-- | src/screen.c | 2 | ||||
| -rw-r--r-- | src/screen_world.c | 18 | ||||
| -rw-r--r-- | src/shot.c | 15 | ||||
| -rw-r--r-- | src/tux.c | 23 |
26 files changed, 477 insertions, 154 deletions
@@ -53,6 +53,7 @@ nosound: mod: make -C ./modules -f Makefile modTeleport make -C ./modules -f Makefile modPipe + make -C ./modules -f Makefile modWall install: mkdir -p $(DESTDIR)/bin diff --git a/arena/construction_site.map b/arena/construction_site.map index a334521..1a3bcb2 100644 --- a/arena/construction_site.map +++ b/arena/construction_site.map @@ -3,6 +3,8 @@ name construction site netName CS screen construction_site.png +loadModule file="modWall.so" + loadMusic file="night_workshift.ogg" name="night_workshift" loadImage file="l4.pozadi.png" name="pozadi" alpha="no" diff --git a/arena/for_a_good_night.map b/arena/for_a_good_night.map index b8387ff..bf2711d 100644 --- a/arena/for_a_good_night.map +++ b/arena/for_a_good_night.map @@ -3,6 +3,8 @@ name For a good night netName FAGN screen for_a_good_night.png +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" diff --git a/arena/in_a_captivity_of_8-bit.map b/arena/in_a_captivity_of_8-bit.map index b078b33..d0a8180 100644 --- a/arena/in_a_captivity_of_8-bit.map +++ b/arena/in_a_captivity_of_8-bit.map @@ -3,6 +3,7 @@ name In a captivity of 8-bit netName IACO8B screen in_a_captivity_of_8-bit.png +loadModule file="modWall.so" loadModule file="modTeleport.so" loadMusic file="in_a_captivity_of_8-bit.ogg" name="in_a_captivity_of_8-bit" diff --git a/arena/night_workshift.map b/arena/night_workshift.map index 8ea7765..0dd83b2 100644 --- a/arena/night_workshift.map +++ b/arena/night_workshift.map @@ -3,6 +3,7 @@ name night workshift netName NW screen night_workshift.png +loadModule file="modWall.so" loadModule file="modPipe.so" loadMusic file="night_workshift.ogg" name="night_workshift" @@ -8,6 +8,6 @@ #define TUXANCI_NG_VERSION "svn52" -#define DESTDIR "/usr/local/" +//#define DESTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP //#define PUBLIC_SERVER diff --git a/include/arena.h b/include/arena.h index f133c14..b79c094 100644 --- a/include/arena.h +++ b/include/arena.h @@ -20,10 +20,7 @@ typedef struct arena_struct list_t *listTimer; list_t *listTux; list_t *listShot; - list_t *listWall; list_t *listItem; - list_t *listTeleport; - list_t *listPipe; } arena_t; extern void setCurrentArena(arena_t *p); diff --git a/include/idManager.h b/include/idManager.h new file mode 100644 index 0000000..a525a56 --- /dev/null +++ b/include/idManager.h @@ -0,0 +1,18 @@ + + +#ifndef ID_MANAGER_H + +#define ID_MANAGER_H + +#define MAX_ID 1000 + +#include "list.h" + +extern list_t * newListID(); +extern int getNewID(list_t *p); +extern int isRegisterID(list_t *p, int id); +extern void delID(list_t *p, int id); +extern void replaceID(list_t *p, int old_id, int new_id); +extern void destroyListID(list_t *p); + +#endif diff --git a/include/main.h b/include/main.h index 09280d0..ea3d703 100644 --- a/include/main.h +++ b/include/main.h @@ -25,6 +25,7 @@ extern char* getParam(char *s); extern char* getParamElse(char *s1, char *s2); extern bool_t isParamFlag(char *s); extern char *getString(int n); +extern int* newInt(int x); extern void accessExistFile(const char *s); #endif diff --git a/modules/Makefile b/modules/Makefile index a3e5588..b8c86b8 100755 --- a/modules/Makefile +++ b/modules/Makefile @@ -11,6 +11,11 @@ modPipe: 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 +modWall: + gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c list.c -o list.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 + clean: rm -rf *.o rm -rf *.so diff --git a/modules/modWall.c b/modules/modWall.c new file mode 100755 index 0000000..50756e8 --- /dev/null +++ b/modules/modWall.c @@ -0,0 +1,261 @@ + +#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 wall_struct +{ + int x; // poloha steny + int y; + + int w; // rozmery steny + int h; + + int img_x; // poloha obrazka + int img_y; + + int layer; // vrstva + +#ifndef PUBLIC_SERVER + SDL_Surface *img; //obrazok +#endif +} wall_t; + +static export_fce_t *export_fce; + +static list_t *listWall; + +#ifndef PUBLIC_SERVER +wall_t* newWall(int x, int y, int w, int h, + int img_x, int img_y, int layer, SDL_Surface *img) +#endif + +#ifdef PUBLIC_SERVER +wall_t* newWall(int x, int y, int w, int h, + int img_x, int img_y, int layer) +#endif +{ + wall_t *new; + +#ifndef PUBLIC_SERVER + assert( img != NULL ); +#endif + new = malloc( sizeof(wall_t) ); + assert( new != NULL ); + + new->x = x; + new->y = y; + new->w = w; + new->h = h; + new->img_x = img_x; + new->img_y = img_y; + new->layer = layer; +#ifndef PUBLIC_SERVER + new->img = img; +#endif + + return new; +} + +#ifndef PUBLIC_SERVER + +void drawWall(wall_t *p) +{ + assert( p != NULL ); + + export_fce->fce_addLayer(p->img, p->img_x, p->img_y, 0, 0, p->img->w, p->img->h, p->layer); +} + +void drawListWall(list_t *listWall) +{ + wall_t *thisWall; + int i; + + assert( listWall != NULL ); + + for( i = 0 ; i < listWall->count ; i++ ) + { + thisWall = (wall_t *)listWall->list[i]; + assert( thisWall != NULL ); + drawWall(thisWall); + } +} + +#endif + +wall_t* isConflictWithListWall(list_t *listWall, int x, int y, int w, int h) +{ + wall_t *thisWall; + int i; + + assert( listWall != NULL ); + + for( i = 0 ; i < listWall->count ; i++ ) + { + thisWall = (wall_t *)listWall->list[i]; + assert( thisWall != NULL ); + + if( export_fce->fce_conflictSpace(x, y, w, h, + thisWall->x, thisWall->y, thisWall->w, thisWall->h) ) + { + return thisWall; + } + } + + return NULL; +} + +void eventConflictShotWithWall(list_t *listShot) +{ + shot_t *thisShot; + 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 ) + { + author = export_fce->fce_getTuxID( listShot, thisShot->author_id ); + + if( author != NULL && + author->bonus == BONUS_GHOST && + author->bonus_time > 0 ) + { + continue; + } + + if( thisShot->gun == GUN_BOMBBALL && export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + export_fce->fce_boundBombBall(thisShot); + continue; + } + + delListItem(listShot, i, export_fce->fce_destroyShot); + i--; + } + } +} + +void destroyWall(wall_t *p) +{ + assert( p != NULL ); + free(p); +} + +static void cmd_wall(char *line) +{ + char str_x[STR_NUM_SIZE]; + char str_y[STR_NUM_SIZE]; + char str_img_x[STR_NUM_SIZE]; + char str_img_y[STR_NUM_SIZE]; + char str_w[STR_NUM_SIZE]; + char str_h[STR_NUM_SIZE]; + char str_layer[STR_NUM_SIZE]; + char str_image[STR_SIZE]; + wall_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, "img_x", str_img_x, STR_NUM_SIZE) != 0 )return; + if( export_fce->fce_getValue(line, "img_y", str_img_y, 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 = newWall(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_img_x), atoi(str_img_y), + atoi(str_layer), export_fce->fce_getImage(IMAGE_GROUP_USER, str_image) ); +#endif + +#ifdef PUBLIC_SERVER + new = newWall(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_img_x), atoi(str_img_y), + atoi(str_layer) ); +#endif + + addList(listWall, new); +} + +int init(export_fce_t *p) +{ + export_fce = p; + + listWall = newList(); + + return 0; +} + +#ifndef PUBLIC_SERVER + +int draw() +{ + wall_t *thisWall; + int i; + + assert( listWall != NULL ); + + for( i = 0 ; i < listWall->count ; i++ ) + { + thisWall = (wall_t *)listWall->list[i]; + assert( thisWall != NULL ); + drawWall(thisWall); + } + + return 0; +} +#endif + + +int event() +{ + eventConflictShotWithWall(export_fce->fce_getCurrentArena()->listShot); + return 0; +} + +int isConflict(int x, int y, int w, int h) +{ + if( isConflictWithListWall(listWall, x, y, w, h) != NULL ) + { + return 1; + } + else + { + return 0; + } +} + +void cmd(char *line) +{ + if( strncmp(line, "wall", 4) == 0 )cmd_wall(line); +} + +int destroy() +{ + destroyListItem(listWall, destroyWall); + + return 0; +} diff --git a/src/Makefile b/src/Makefile index ab243b6..25db7f8 100755 --- a/src/Makefile +++ b/src/Makefile @@ -9,9 +9,10 @@ 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 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 \ +FILES = interface.o idManager.o checkFront.o font.o list.o modules.o image.o layer.o director.o\ + configFile.o tux.o main.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 \ widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \ widget_buttonimage.o screen_credits.o homeDirector.o screen_table.o \ @@ -29,6 +30,12 @@ interface.o: interface.c ../include/interface.h modules.o: modules.c ../include/modules.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/modules.o -c modules.c +idManager.o: idManager.c ../include/idManager.h + $(CC) $(CFLAGS) -o $(BUILD_DIR)/idManager.o -c idManager.c + +checkFront.o: checkFront.c ../include/checkFront.h + $(CC) $(CFLAGS) -o $(BUILD_DIR)/checkFront.o -c checkFront.c + font.o: font.c ../include/font.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/font.o -c font.c @@ -56,8 +63,8 @@ screen.o: screen.c ../include/screen.h screen_world.o: screen_world.c ../include/screen_world.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/screen_world.o -c screen_world.c -wall.o: wall.c ../include/wall.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/wall.o -c wall.c +#wall.o: wall.c ../include/wall.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/wall.o -c wall.c shot.o: shot.c ../include/shot.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/shot.o -c shot.c @@ -95,9 +102,6 @@ network.o: network.c ../include/network.h net_multiplayer.o: net_multiplayer.c ../include/net_multiplayer.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/net_multiplayer.o -c net_multiplayer.c -dynamicInt.o: dynamicInt.c ../include/dynamicInt.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/dynamicInt.o -c dynamicInt.c - arena.o: arena.c ../include/arena.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/arena.o -c arena.c diff --git a/src/arena.c b/src/arena.c index 05749d6..3e14066 100644 --- a/src/arena.c +++ b/src/arena.c @@ -44,10 +44,7 @@ arena_t* newArena() new->listTimer = newList(); new->listTux = newList(); new->listShot = newList(); - new->listWall = newList(); new->listItem = newList(); - new->listTeleport = newList(); - new->listPipe = newTimer(); return new; } @@ -59,12 +56,13 @@ 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 ( 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( isConflictWithListTux(arena->listTux, 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( 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; + //if( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; return 1; } @@ -95,7 +93,7 @@ void drawArena(arena_t *arena) addLayer(arena->background, 0, 0, 0, 0, WINDOW_SIZE_X, WINDOW_SIZE_Y, -100); drawListTux(arena->listTux); - drawListWall(arena->listWall); + //drawListWall(arena->listWall); //drawListTeleport(arena->listTeleport); //drawListPipe(arena->listPipe); drawListShot(arena->listShot); @@ -127,7 +125,7 @@ void eventArena(arena_t *arena) for( i = 0 ; i < 4 ; i++) { eventMoveListShot(arena->listShot); - eventConflictShotWithWall(arena->listWall, arena->listShot); + //eventConflictShotWithWall(arena->listWall, arena->listShot); //eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); //eventConflictShotWithPipe(arena->listPipe, arena->listShot); eventConflictShotWithItem(arena->listItem, arena->listShot); @@ -140,25 +138,11 @@ void eventArena(arena_t *arena) eventTimer(arena->listTimer); } -int isConflictWithObjectInArena(arena_t *arena, int x, int y, int w, int h) -{ - if( isConflictWithListWall(arena->listWall, x, y, w, h) || - isConflictModule(x, y, w, h) ) - { - return 1; - } - - return 0; -} - void destroyArena(arena_t *p) { destroyListItem(p->listTux, destroyTux); destroyListItem(p->listShot, destroyShot); - destroyListItem(p->listWall, destroyWall); destroyListItem(p->listItem, destroyItem); - destroyListItem(p->listTeleport, destroyItem); - destroyListItem(p->listPipe, destroyItem); destroyTimer(p->listTimer); free(p); } diff --git a/src/arenaFile.c b/src/arenaFile.c index 90ae231..dc705fd 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -91,85 +91,6 @@ static void cmd_playMusic(arena_t *arena, char *line) #endif -static void cmd_wall(arena_t *arena, char *line) -{ - char str_x[STR_NUM_SIZE]; - char str_y[STR_NUM_SIZE]; - char str_img_x[STR_NUM_SIZE]; - char str_img_y[STR_NUM_SIZE]; - char str_w[STR_NUM_SIZE]; - char str_h[STR_NUM_SIZE]; - char str_layer[STR_NUM_SIZE]; - char str_image[STR_SIZE]; - wall_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, "img_x", str_img_x, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "img_y", str_img_y, 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 = newWall(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_img_x), atoi(str_img_y), - atoi(str_layer), getImage(IMAGE_GROUP_USER, str_image) ); -#endif - -#ifdef PUBLIC_SERVER - new = newWall(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_img_x), atoi(str_img_y), - atoi(str_layer) ); -#endif - - addList(arena->listWall, new); -} - -/* -static void cmd_pipe(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_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( 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, "id", str_id, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "position", str_position, 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 = 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), - 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(arena->listPipe, new); -} -*/ - int getArenaCount() { return listArenaFile->count; @@ -260,7 +181,7 @@ arena_t* getArena(int id) #endif if( strncmp(line, "loadModule", 10) == 0 )cmd_loadModule(line); - if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, 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); } diff --git a/src/dynamicInt.c b/src/dynamicInt.c index 4dd32ce..0b53762 100644 --- a/src/dynamicInt.c +++ b/src/dynamicInt.c @@ -3,6 +3,7 @@ #include "main.h" #include "dynamicInt.h" + int* newInt(int x) { int *new; diff --git a/src/idManager.c b/src/idManager.c new file mode 100644 index 0000000..1da30bc --- /dev/null +++ b/src/idManager.c @@ -0,0 +1,97 @@ + +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "idManager.h" + +list_t * newListID() +{ + return newList(); +} + +int getNewID(list_t *p) +{ + int ret; + int i; + + assert( p != NULL ); + + do{ + ret = random() % MAX_ID + 1; + + for( i = 0 ; i < p->count ; i++ ) + { + int *z; + + z = (int *) p->list[i]; + + if( *z == ret )continue; + } + + }while(0); + + addList(p, newInt(ret) ); + + //printf("new ID -> %d\n", ret); + return ret; +} + +int isRegisterID(list_t *p, int id) +{ + int i; + + assert( p != NULL ); + + for( i = 0 ; i < p->count ; i++ ) + { + int *z; + + z = (int *) p->list[i]; + + if( *z == id ) + { + return i; + } + } + + return -1; +} + +void delID(list_t *p, int id) +{ + int index; + + assert( p != NULL ); + + index = isRegisterID(p, id); + + if( index == -1 ) + { + assert( ! "takyto ID nebol nikdy registrovany !" ); + return; // ha ha ha + } + + delListItem(p, index, free); + + return; +} + +void replaceID(list_t *p, int old_id, int new_id) +{ + delID(p, old_id); + + if( new_id != -1 ) + { + assert( isRegisterID(p, new_id) == -1 ); + addList(p, newInt(new_id) ); + } +} + +void destroyListID(list_t *p) +{ + assert( p != NULL ); + destroyListItem(p, free); +} diff --git a/src/image.c b/src/image.c index a7c2261..1462b56 100755 --- a/src/image.c +++ b/src/image.c @@ -155,11 +155,11 @@ void delAllImageInGroup(char *group) for(i = 0 ; i < listImageData->count; i++) { this = (image_data_t *) listImageData->list[i]; - + if( strcmp(group, this->group) == 0 ) { delListItem(listImageData, i, destroyImageData); - break; + i--; } } @@ -8,6 +8,7 @@ #include "item.h" #include "shot.h" #include "proto.h" +#include "idManager.h" #include "net_multiplayer.h" #ifndef PUBLIC_SERVER @@ -30,6 +31,7 @@ static SDL_Surface *g_item[ITEM_COUNT]; #endif static bool_t isItemInit = FALSE; +static list_t *listID; bool_t isItemInicialized() { @@ -57,12 +59,12 @@ void initItem() g_item[BONUS_4X] = addImageData("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", IMAGE_GROUP_BASE); g_item[BONUS_HIDDEN] = addImageData("item.bonus.hidden.png", IMAGE_ALPHA, "item_hidden_speed", IMAGE_GROUP_BASE); #endif + listID = newListID(); isItemInit = TRUE; } item_t* newItem(int x, int y, int type, int author_id) { - static unsigned int last_id = 0; item_t *new; new = malloc( sizeof(item_t) ); @@ -70,7 +72,7 @@ item_t* newItem(int x, int y, int type, int author_id) new->type = type; - new->id = last_id++; + new->id = getNewID(listID); new->x = x; new->y = y; new->frame = 0; @@ -149,6 +151,12 @@ item_t* getItemID(list_t *listItem, int id) return NULL; } +void replaceItemID(item_t *item, int id) +{ + replaceID(listID, item->id, id); + item->id = id; +} + void addNewItem(list_t *listItem, int author_id) { #ifndef PUBLIC_SERVER @@ -614,10 +622,12 @@ void eventGiveTuxListItem(tux_t *tux, list_t *listItem) void destroyItem(item_t *p) { assert( p != NULL ); + delID(listID, p->id); free(p); } void quitItem() { + destroyListID(listID); isItemInit = FALSE; } diff --git a/src/layer.c b/src/layer.c index 05dc62a..d8740dc 100755 --- a/src/layer.c +++ b/src/layer.c @@ -129,6 +129,12 @@ void drawLayerCenter(int x, int y) listLayer = newList(); } +void flushLayer() +{ + destroyListItem(listLayer, free); + listLayer = newList(); +} + /* * Odstrani zoznam vrtsiev z pamete. */ @@ -81,6 +81,14 @@ char *getString(int n) return strdup(str); } +int* newInt(int x) +{ + int *new; + new = malloc( sizeof(int) ); + *new = x; + return new; +} + void accessExistFile(const char *s) { if( access(s, F_OK) != 0 ) diff --git a/src/music.c b/src/music.c index 5ef4ae6..2fd8e31 100644 --- a/src/music.c +++ b/src/music.c @@ -211,7 +211,7 @@ void delAllMusicInGroup(int group) if( this->group == group ) { delListItem(listMusic, i, destroyMusic); - break; + i--; } } } diff --git a/src/proto.c b/src/proto.c index 0441371..45abf8c 100644 --- a/src/proto.c +++ b/src/proto.c @@ -190,7 +190,7 @@ void proto_recv_init_client(char *msg) setMaxCountRound(n); tux = newTux(); - tux->id = id; + replaceTuxID(tux, id); tux->x = x; tux->y = y; tux->control = TUX_CONTROL_KEYBOARD_RIGHT; @@ -329,8 +329,7 @@ void proto_recv_newtux_client(char *msg) addList(getCurrentArena()->listTux, tux); } - tux->id = id; - + replaceTuxID(tux, id); tux->x = x; tux->y = y; tux->status = status; @@ -508,7 +507,7 @@ void proto_recv_additem_client(char *msg) return; } */ - item->id = id; + replaceItemID(item, id); item->count = count; item->frame = frame; item->lastSync = getMyTime(); @@ -606,7 +605,7 @@ void proto_recv_shot_client(char *msg) */ shot = newShot(x, y, px, py, gun, author_id); - shot->id = shot_id; + replaceShotID(shot, shot_id); shot->isCanKillAuthor = isCanKillAuthor; shot->position = position; diff --git a/src/screen.c b/src/screen.c index dba91bc..0fc0d69 100644 --- a/src/screen.c +++ b/src/screen.c @@ -84,6 +84,8 @@ void setScreen(char *name) if( strcmp(name, this->name) == 0 ) { + flushLayer(); + if( currentScreen != NULL ) { printf("stop screen %s..\n", currentScreen->name); diff --git a/src/screen_world.c b/src/screen_world.c index 671a858..fde1d4a 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -214,27 +214,9 @@ static void netAction(tux_t *tux, int action) static void control_keyboard_right(tux_t *tux) { -/* - static my_time_t lastTime = 0; - my_time_t currentTime; -*/ Uint8 *mapa; mapa = SDL_GetKeyState(NULL); -/* - if( lastTime == 0 ) - { - lastTime = getMyTime(); - } - - currentTime = getMyTime(); - if( currentTime - lastTime < 45 ) - { - return; - } - - lastTime = getMyTime(); -*/ assert( tux != NULL ); assert( mapa != NULL ); @@ -10,6 +10,7 @@ #include "pipe.h" #include "net_multiplayer.h" #include "proto.h" +#include "idManager.h" #ifndef PUBLIC_SERVER #include "image.h" @@ -31,6 +32,7 @@ static SDL_Surface *g_shot_bombball; #endif static bool_t isShotInit = FALSE; +static list_t *listID; bool_t isShotInicialized() { @@ -52,6 +54,8 @@ void initShot() #endif + listID = newListID(); + isShotInit = TRUE; } @@ -59,12 +63,11 @@ shot_t* newShot(int x,int y, int px, int py, int gun, int author_id) { shot_t *new; tux_t *author; - static int last_id = 0; new = malloc( sizeof(shot_t) ); memset(new, 0, sizeof(shot_t) ); - new->id = ++last_id; + new->id = getNewID(listID); new->x = x; new->y = y; new->px = px; @@ -153,6 +156,12 @@ shot_t* getShotID(list_t *listShot, int id) return NULL; } +void replaceShotID(shot_t *shot, int id) +{ + replaceID(listID, shot->id, id); + shot->id = id; +} + #ifndef PUBLIC_SERVER @@ -404,11 +413,13 @@ void moveShot(shot_t *shot, int position, int src_x, int src_y, void destroyShot(shot_t *p) { assert( p != NULL ); + delID(listID, p->id); free(p); } void quitShot() { + destroyListID(listID); isShotInit = FALSE; } @@ -19,6 +19,7 @@ #include "dynamicInt.h" #include "proto.h" #include "modules.h" +#include "idManager.h" #ifndef PUBLIC_SERVER #include "image.h" @@ -43,6 +44,8 @@ static SDL_Surface *g_cross; #endif +static list_t *listID; + static bool_t isTuxInit = FALSE; bool_t isTuxInicialized() @@ -64,12 +67,13 @@ void initTux() g_cross = addImageData("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); #endif + listID = newListID(); + isTuxInit = TRUE; } tux_t* newTux() { - static int last_id = 0; int x, y; tux_t *new; @@ -78,7 +82,7 @@ tux_t* newTux() memset(new, 0, sizeof(tux_t) ); - new->id = last_id++; + new->id = getNewID(listID); new->status = TUX_STATUS_ALIVE; new->control = TUX_CONTROL_NONE; @@ -246,6 +250,12 @@ tux_t* getTuxID(list_t *listTux, int id) return NULL; } +void replaceTuxID(tux_t *tux, int id) +{ + replaceID(listID, tux->id, id); + tux->id = id; +} + tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h) { tux_t *thisTux; @@ -626,7 +636,6 @@ void moveTux(tux_t *tux, int n) if( tux->bonus != BONUS_GHOST && ( isConflictTuxWithListTux(tux, arena->listTux) || - isConflictWithListWall(arena->listWall, x, y, w, h) || isConflictModule(x, y, w, h) ) ) { tux->x = zal_x; @@ -797,9 +806,8 @@ static void eventBonus(tux_t *tux) tux->bonus = BONUS_NONE; - if ( isConflictWithListWall(getCurrentArena()->listWall, x, y, w, h) || - isConflictModule(x, y, w, h) || - isConflictTuxWithListTux(tux, getCurrentArena()->listTux) ) + if( isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || + isConflictModule(x, y, w, h) ) { tux->bonus = BONUS_GHOST; return; @@ -865,11 +873,12 @@ void setTuxProportion(tux_t *tux, int x, int y) void destroyTux(tux_t *tux) { assert( tux != NULL ); + delID(listID, tux->id); free(tux); } void quitTux() { + destroyListID(listID); isTuxInit = FALSE; } - |