From 6c4fe3323d79253af707df90623e433ce12c35f2 Mon Sep 17 00:00:00 2001 From: scarab Date: Sat, 5 Jul 2008 16:43:55 +0000 Subject: * Prechod na novou verzi instalace pseudoautotools -> cmake * Odstraneni bordelu kterej tu byl (pokud vam neco chybi brecte na me ja to zkusim najit v zaloze) * TODO instalace: SEPSAT AUTORY, IKONKU VYROBIT git-svn-id: http://opensvn.csie.org/tuxanci_ng@94 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- modules/Makefile | 28 -- modules/Makefile-publicserver | 24 -- modules/list.c | 241 ----------------- modules/list.h | 33 --- modules/modAI.c | 256 ------------------ modules/modPipe.c | 453 ------------------------------- modules/modTeleport.c | 506 ---------------------------------- modules/modWall.c | 343 ----------------------- modules/space.c | 615 ------------------------------------------ modules/space.h | 38 --- 10 files changed, 2537 deletions(-) delete mode 100755 modules/Makefile delete mode 100755 modules/Makefile-publicserver delete mode 100755 modules/list.c delete mode 100755 modules/list.h delete mode 100755 modules/modAI.c delete mode 100755 modules/modPipe.c delete mode 100755 modules/modTeleport.c delete mode 100755 modules/modWall.c delete mode 100644 modules/space.c delete mode 100644 modules/space.h (limited to 'modules') diff --git a/modules/Makefile b/modules/Makefile deleted file mode 100755 index e9546c8..0000000 --- a/modules/Makefile +++ /dev/null @@ -1,28 +0,0 @@ - -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 space.c -o space.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 space.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 space.c -o space.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 space.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 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 space.o - -modAI: - gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c modAI.c -o modAI.o - gcc $(CFLAGS) -I../include -shared -fPIC -o modAI.so modAI.o - -clean: - rm -rf *.o - rm -rf *.so diff --git a/modules/Makefile-publicserver b/modules/Makefile-publicserver deleted file mode 100755 index 030361c..0000000 --- a/modules/Makefile-publicserver +++ /dev/null @@ -1,24 +0,0 @@ - -CFLAGS = -g -O0 -I../include -Wall - -modTeleport: - gcc $(CFLAGS) -fPIC -I../include -c list.c -o list.o - gcc $(CFLAGS) -fPIC -I../include -c space.c -o space.o - gcc $(CFLAGS) -fPIC -I../include -c modTeleport.c -o modTeleport.o - gcc $(CFLAGS) -I../include -shared -fPIC -o modTeleport.so modTeleport.o list.o space.o - -modPipe: - gcc $(CFLAGS) -fPIC -I../include -c list.c -o list.o - gcc $(CFLAGS) -fPIC -I../include -c space.c -o space.o - gcc $(CFLAGS) -fPIC -I../include -c modPipe.c -o modPipe.o - gcc $(CFLAGS) -I../include -shared -fPIC -o modPipe.so modPipe.o list.o space.o - -modWall: - gcc $(CFLAGS) -fPIC -I../include -c list.c -o list.o - gcc $(CFLAGS) -fPIC -I../include -c space.c -o space.o - gcc $(CFLAGS) -fPIC -I../include -c modWall.c -o modWall.o - gcc $(CFLAGS) -I../include -shared -fPIC -o modWall.so modWall.o list.o space.o - -clean: - rm -rf *.o - rm -rf *.so diff --git a/modules/list.c b/modules/list.c deleted file mode 100755 index 27b0ed8..0000000 --- a/modules/list.c +++ /dev/null @@ -1,241 +0,0 @@ - -#include "main.h" -#include "list.h" - -#include -#include -#include -#include - -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 listDoEmpty(list_t *p) -{ - p->count = 0; -} - -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 deleted file mode 100755 index 5a15786..0000000 --- a/modules/list.h +++ /dev/null @@ -1,33 +0,0 @@ - -#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 listDoEmpty(list_t *p); - -extern void destroyList(list_t *p); -extern void destroyListItem(list_t *p,void *f); - -#endif diff --git a/modules/modAI.c b/modules/modAI.c deleted file mode 100755 index 53f689e..0000000 --- a/modules/modAI.c +++ /dev/null @@ -1,256 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "modules.h" -#include "tux.h" -#include "shot.h" -#include "list.h" -#include "gun.h" -#include "space.h" - -#ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#endif - -#ifdef PUBLIC_SERVER -#include "publicServer.h" -#endif - -static export_fce_t *export_fce; - -static void cmd_ai(char *line) -{ -} - -int init(export_fce_t *p) -{ - export_fce = p; - - return 0; -} - -#ifndef PUBLIC_SERVER - -int draw(int x, int y, int w, int h) -{ - return 0; -} -#endif - -///////////////// - -int colisionAll(tux_t *tux, int px, int py) -{ - arena_t *arena; - int x, y, w, h; - - arena = export_fce->fce_getCurrentArena(); - - export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); - x += px; - y += py; - - return export_fce->fce_isFreeSpace(arena, x, y, w, h); -} - -void gotoTux(tux_t *tux, int x, int y, int w, int h) -{ - int px = 0,py = 0; - int smer = TUX_DOWN; - - if(tux->x > x+w ) px = -TUX_STEP; - if(tux->x < x ) px = +TUX_STEP; - if(tux->y > y+h ) py = -TUX_STEP; - if(tux->y < y ) py = +TUX_STEP; - - if( px != 0 && py !=0 ) px = 0; - - while( colisionAll(tux, px, 0 ) ) - { - px=0; - if(py==0) py = +TUX_STEP; - goto sem; - } - - while( colisionAll(tux, 0, py ) ) - { - py = 0; - if( px == 0 ) px = +TUX_STEP; - } - - sem: - if( px != 0 && py != 0 ) px = 0; - - if( py== -TUX_STEP )smer = TUX_UP; - if( px== +TUX_STEP )smer = TUX_RIGHT; - if( px== -TUX_STEP )smer = TUX_LEFT; - if( py== +TUX_STEP )smer = TUX_DOWN; - - //printf("smer=%d\n",smer); - export_fce->fce_actionTux(tux, smer); -} - -void gotoTuxShot(tux_t *tux, int x, int y, int w, int h) -{ - if( tux->x > x && tux->x < x+w ) - { - if( tux->y > y+h )tux->position = TUX_UP; - if( tux->y < y )tux->position = TUX_DOWN; - - if( colisionAll(tux, 0, 0) == 0 ) - { - if( tux->shot[GUN_SIMPLE] > 0 )tux->gun = GUN_SIMPLE; - if( tux->shot[GUN_DUAL_SIMPLE] > 0 )tux->gun = GUN_DUAL_SIMPLE; - if( tux->shot[GUN_SCATTER] > 0 )tux->gun = GUN_SCATTER; - if( tux->shot[GUN_TOMMY] > 0 )tux->gun = GUN_TOMMY; - if( tux->shot[GUN_LASSER] > 0 )tux->gun = GUN_LASSER; - if( tux->shot[GUN_BOMBBALL] > 0 )tux->gun = GUN_BOMBBALL; - - export_fce->fce_actionTux(tux, TUX_SHOT); - } - } - - if( tux->y > y && tux->y < y+h ) - { - if( tux->x > x+w )tux->position=TUX_LEFT; - if( tux->x < x )tux->position=TUX_RIGHT; - - if( colisionAll(tux, 0 , 0) == 0 ) - { - if( tux->shot[GUN_SIMPLE] > 0 )tux->gun = GUN_SIMPLE; - if( tux->shot[GUN_DUAL_SIMPLE] > 0 )tux->gun = GUN_DUAL_SIMPLE; - if( tux->shot[GUN_SCATTER] > 0 )tux->gun = GUN_SCATTER; - if( tux->shot[GUN_TOMMY] > 0 )tux->gun = GUN_TOMMY; - if( tux->shot[GUN_LASSER] > 0 )tux->gun = GUN_LASSER; - if( tux->shot[GUN_BOMBBALL] > 0 )tux->gun = GUN_BOMBBALL; - - export_fce->fce_actionTux(tux, TUX_SHOT); - } - } -} - -void killTux(tux_t *tux, int active) -{ - arena_t *arena; - int i; - - arena = export_fce->fce_getCurrentArena(); - - for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) - { - tux_t *thisTux; - - thisTux = arena->spaceTux->list->list[i]; - - if( thisTux->control != TUX_CONTROL_KEYBOARD_LEFT && - thisTux->status == TUX_STATUS_ALIVE ) - { - gotoTuxShot(tux, thisTux->x, thisTux->y, - TUX_WIDTH, TUX_HEIGHT); - - if( active ) - { - gotoTux(tux, thisTux->x, thisTux->y, - TUX_WIDTH, TUX_HEIGHT); - - gotoTuxShot(tux, thisTux->x, thisTux->y, - TUX_WIDTH, TUX_HEIGHT); - - break; - } - } - } -} - -///////////////// - -static void eventTux(tux_t *tux) -{ - arena_t *arena; - item_t *item; - - arena = export_fce->fce_getCurrentArena(); - - killTux(tux, 0); - - item = NULL; - - if( arena->spaceItem->list->count > 0 ) - { - item = (item_t *) arena->spaceItem->list->list[0]; - } - - if( item != NULL && - item->type != GUN_MINE ) - { - gotoTux(tux, item->x, item->y, - item->w, item->h); - } - else - { - killTux(tux, 1); - } -} - -int event() -{ - static my_time_t lastEvent = 0; - my_time_t curentTime; - arena_t *arena; - int countTuxAI; - int i; - - if( lastEvent == 0 ) - { - lastEvent = export_fce->fce_getMyTime(); - } - - curentTime = export_fce->fce_getMyTime(); - - if( curentTime - lastEvent < 25 ) - { - return 0; - } - - lastEvent = export_fce->fce_getMyTime(); - //printf("event AI\n"); - - arena = export_fce->fce_getCurrentArena(); - countTuxAI = 0; - - for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) - { - tux_t *thisTux; - - thisTux = arena->spaceTux->list->list[i]; - - if( thisTux->control == TUX_CONTROL_AI && - thisTux->status == TUX_STATUS_ALIVE ) - { - eventTux(thisTux); - countTuxAI = 0; - } - } - - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - return 0; -} - -void cmd(char *line) -{ - if( strncmp(line, "ai", 2) == 0 )cmd_ai(line); -} - -int destroy() -{ - return 0; -} diff --git a/modules/modPipe.c b/modules/modPipe.c deleted file mode 100755 index 2c1a6e5..0000000 --- a/modules/modPipe.c +++ /dev/null @@ -1,453 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "modules.h" -#include "tux.h" -#include "shot.h" -#include "list.h" -#include "gun.h" -#include "space.h" - -#ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#endif - -#ifdef PUBLIC_SERVER -#include "publicServer.h" -#endif - -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; -static space_t *spacePipe; - -#ifndef PUBLIC_SERVER -static pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, 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; -} - -static void setStatusPipe(void *p, int x, int y, int w, int h) -{ - pipe_t *pipe; - - pipe = p; - - pipe->x = x; - pipe->y = y; - pipe->w = w; - pipe->h = h; -} - -static void getStatusPipe(void *p, int *id, int *x, int *y, int *w, int *h) -{ - pipe_t *pipe; - - pipe = p; - - *id = pipe->id; - *x = pipe->x; - *y = pipe->y; - *w = pipe->w; - *h = pipe->h; -} - -#ifndef PUBLIC_SERVER - -static void drawPipe(pipe_t *p) -{ - assert( p != NULL ); - - export_fce->fce_addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer); -} - -#endif - -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 - - if( spacePipe == NULL ) - { - spacePipe = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, - 320, 240, getStatusPipe, setStatusPipe); - } - - addObjectToSpace(spacePipe, new); -} - -static int myAbs(int n) -{ - return ( n > 0 ? n : -n ); -} - - -static int getSppedShot(shot_t *shot) -{ - return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); -} - -static void transformShot(shot_t *shot, int position) -{ - int speed; - - speed = getSppedShot(shot); - - switch( position ) - { - case TUX_UP : - shot->px = 0; - shot->py = -speed; - break; - - case TUX_LEFT : - shot->px = -speed; - shot->py = 0; - break; - - case TUX_RIGHT : - shot->px = speed; - shot->py = 0; - break; - - case TUX_DOWN : - shot->px = 0; - shot->py = +speed; - break; - } - - shot->position = position; - shot->isCanKillAuthor = TRUE; - - if( shot->gun == GUN_LASSER ) - { - export_fce->fce_transformOnlyLasser(shot); - } -} - -static void moveShot(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h) -{ - int offset = 0; - int new_x, new_y; - - switch( shot->position ) - { - case TUX_UP : - case TUX_DOWN : - offset = shot->x - src_x; - break; - - case TUX_RIGHT : - case TUX_LEFT : - offset = shot->y - src_y; - break; - } - - transformShot(shot, position); - - switch( shot->position ) - { - case TUX_UP : - new_x = dist_x + offset; - new_y = dist_y; - break; - - case TUX_LEFT : - new_x = dist_x; - new_y = dist_y + offset; - break; - - case TUX_RIGHT : - new_x = dist_x + dist_w; - new_y = dist_y + offset; - break; - - case TUX_DOWN : - new_x = dist_x + offset; - new_y = dist_y + dist_h; - break; - } - - new_y += shot->px; - new_y += shot->py; - - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); - - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); - } -} - -static void moveShotFromPipe(shot_t *shot, pipe_t *pipe) -{ - pipe_t *distPipe; - - distPipe = getObjectFromSpaceWithID(spacePipe, 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(int x, int y, int w, int h) -{ - pipe_t *thisPipe; - int i; - - if( spacePipe == NULL ) - { - return 0; - } - - listDoEmpty(listPipe); - getObjectFromSpace(spacePipe, x, y, w, h, listPipe); - //printSpace(spacePipe); - - 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; - - if( spacePipe == NULL ) - { - return 0; - } - -/* - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return; - } -*/ - arena = export_fce->fce_getCurrentArena(); - - for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) - { - shot_t *thisShot; - int j; - - thisShot = (shot_t *) arena->spaceShot->list->list[i]; - assert( thisShot != NULL ); - - listDoEmpty(listPipe); - getObjectFromSpace(spacePipe, thisShot->x, thisShot->y, thisShot->w, thisShot->h, listPipe); - - for( j = 0 ; j < listPipe->count ; j++ ) - { - tux_t *author; - - thisPipe = (pipe_t *)listPipe->list[j]; - - author = getObjectFromSpaceWithID(arena->spaceTux, thisShot->author_id); - - if( author != NULL && - author->bonus == BONUS_GHOST && - author->bonus_time > 0 ) - { - continue; - } - - if( negPosition( thisShot->position ) == thisPipe->position ) - { - //moveShotFromPipe(thisShot, thisPipe, listPipe); - - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - if( thisShot->gun != GUN_BOMBBALL ) - { - delObjectFromSpaceWithObject(export_fce->fce_getCurrentArena()->spaceShot, - thisShot, export_fce->fce_destroyShot); - //delListItem(arena->listShot, i, export_fce->fce_destroyShot); - i--; - } - } - else - { - moveShotFromPipe(thisShot, thisPipe); - } - - } - else - { - if( thisShot->gun == GUN_BOMBBALL && - export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - export_fce->fce_boundBombBall(thisShot); - continue; - } - else - { - delObjectFromSpaceWithObject(export_fce->fce_getCurrentArena()->spaceShot, - thisShot, export_fce->fce_destroyShot); - i--; - } - } - } - } - - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - if( spacePipe == NULL ) - { - return 0; - } - - return isConflictWithObjectFromSpace(spacePipe, x, y, w, h); -} - -void cmd(char *line) -{ - if( strncmp(line, "pipe", 4) == 0 )cmd_teleport(line); -} - -int destroy() -{ - destroySpaceWithObject(spacePipe, destroyPipe); - destroyList(listPipe); - - return 0; -} diff --git a/modules/modTeleport.c b/modules/modTeleport.c deleted file mode 100755 index 2b94e2f..0000000 --- a/modules/modTeleport.c +++ /dev/null @@ -1,506 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "modules.h" -#include "tux.h" -#include "shot.h" -#include "list.h" -#include "gun.h" -#include "space.h" - -#ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#endif - -#ifdef PUBLIC_SERVER -#include "publicServer.h" -#endif - -typedef struct teleport_struct -{ - int id; - - 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 space_t *spaceTeleport; -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 -{ - static int last_id = 0; - - teleport_t *new; - -#ifndef PUBLIC_SERVER - assert( img != NULL ); -#endif - - new = malloc( sizeof(teleport_t) ); - assert( new != NULL ); - - new->id = ++last_id; - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->layer = layer; -#ifndef PUBLIC_SERVER - new->img = img; -#endif - - return new; -} - -static void setStatusTeleport(void *p, int x, int y, int w, int h) -{ - teleport_t *teleport; - - teleport = p; - - teleport->x = x; - teleport->y = y; - teleport->w = w; - teleport->h = h; -} - -static void getStatusTeleport(void *p, int *id, int *x, int *y, int *w, int *h) -{ - teleport_t *teleport; - teleport = p; - - *id = teleport->id; - *x = teleport->x; - *y = teleport->y; - *w = teleport->w; - *h = teleport->h; -} - -#ifndef PUBLIC_SERVER - -static void drawTeleport(teleport_t *p) -{ - assert( p != NULL ); - - export_fce->fce_addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer); -} - -#endif - -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 - - if( spaceTeleport == NULL ) - { - spaceTeleport = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, - 320, 240, getStatusTeleport, setStatusTeleport); - } - - addObjectToSpace(spaceTeleport, new); -} - -static teleport_t* getRandomTeleportBut(list_t *list, teleport_t *teleport) -{ - int x; - - do{ - x = random() % list->count; - }while( list->list[x] == teleport ); - - return (teleport_t *) list->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 dist_x, dist_y; - - if( tux->bonus == BONUS_GHOST || - export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return; - } - - distTeleport = getRandomTeleportBut(spaceTeleport->list, 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) ) - { - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceTux, tux, dist_x, dist_y); - //export_fce->fce_setTuxProportion(tux, dist_x, dist_y); -#ifndef PUBLIC_SERVER - //playSound("teleport", SOUND_GROUP_BASE); -#endif - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - 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 ) - { - export_fce->fce_transformOnlyLasser(shot); - } -} - -static void moveShot(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h) -{ - int offset = 0; - int new_x, new_y; - - switch( shot->position ) - { - case TUX_UP : - case TUX_DOWN : - offset = shot->x - src_x; - break; - - case TUX_RIGHT : - case TUX_LEFT : - offset = shot->y - src_y; - break; - } - - transformShot(shot, position); - - switch( shot->position ) - { - case TUX_UP : - new_x = dist_x + offset; - new_y = dist_y; - break; - - case TUX_LEFT : - new_x = dist_x; - new_y = dist_y + offset; - break; - - case TUX_RIGHT : - new_x = dist_x + dist_w; - new_y = dist_y + offset; - break; - - case TUX_DOWN : - new_x = dist_x + offset; - new_y = dist_y + dist_h; - break; - } - - new_y += shot->px; - new_y += shot->py; - - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); - - 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 *list) -{ - teleport_t *distTeleport; - - distTeleport = getRandomTeleportBut(list, teleport); - - moveShot(shot, getRandomPosition(), teleport->x, teleport->y, - distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); -} - -int init(export_fce_t *p) -{ - export_fce = p; - - listTeleport = newList(); - - return 0; -} - -#ifndef PUBLIC_SERVER -int draw(int x, int y, int w, int h) -{ - teleport_t *thisTeleport; - int i; - - if( spaceTeleport == NULL ) - { - return 0; - } - - listDoEmpty(listTeleport); - getObjectFromSpace(spaceTeleport, x, y, w, h, listTeleport); - - 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; - - if( spaceTeleport == NULL ) - { - return 0; - } - - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return 0; - } - - arena = export_fce->fce_getCurrentArena(); - - for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) - { - tux_t *thisTux; - int x, y, w, h; - int j; - - thisTux = (tux_t *)arena->spaceTux->list->list[i]; - export_fce->fce_getTuxProportion(thisTux, &x, &y, &w, &h); - - listDoEmpty(listTeleport); - getObjectFromSpace(spaceTeleport, x, y, w, h, listTeleport); - - for( j = 0 ; j < listTeleport->count ; j++ ) - { - thisTeleport = (teleport_t *)listTeleport->list[j]; - teleportTux(thisTux, thisTeleport); - } - } - - for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) - { - shot_t *thisShot; - int j; - - thisShot = (shot_t *)arena->spaceShot->list->list[i]; - assert( thisShot != NULL ); - - listDoEmpty(listTeleport); - getObjectFromSpace(spaceTeleport, thisShot->x, thisShot->y, thisShot->w, thisShot->h, listTeleport); - - for( j = 0 ; j < listTeleport->count ; j++ ) - { - tux_t *author; - - thisTeleport = (teleport_t *)listTeleport->list[j]; - author = getObjectFromSpaceWithID(arena->spaceTux, thisShot->author_id); - - if( author != NULL && - author->bonus == BONUS_GHOST && - author->bonus_time > 0 ) - { - continue; - } - - moveShotFromTeleport(thisShot, thisTeleport, spaceTeleport->list); - } - } - - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - if( spaceTeleport == NULL ) - { - return 0; - } - - return 0; -} - -void cmd(char *line) -{ - if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(line); -} - -int destroy() -{ - destroySpaceWithObject(spaceTeleport, destroyTeleport); - destroyList(listTeleport); - return 0; -} diff --git a/modules/modWall.c b/modules/modWall.c deleted file mode 100755 index d917309..0000000 --- a/modules/modWall.c +++ /dev/null @@ -1,343 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "modules.h" -#include "tux.h" -#include "shot.h" -#include "list.h" -#include "gun.h" -#include "space.h" - -#ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#endif - -#ifdef PUBLIC_SERVER -#include "publicServer.h" -#endif - -typedef struct wall_struct -{ - int id; - - 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 space_t *spaceWall; - -#ifndef PUBLIC_SERVER -static space_t *spaceImgWall; -#endif - -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 -{ - static int last_id = 0; - wall_t *new; - -#ifndef PUBLIC_SERVER - assert( img != NULL ); -#endif - new = malloc( sizeof(wall_t) ); - assert( new != NULL ); - - new->id = ++last_id; - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->img_x = img_x; - new->img_y = img_y; - new->layer = layer; -#ifndef PUBLIC_SERVER - new->img = img; -#endif - - 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 *list) -{ - wall_t *thisWall; - int i; - - assert( list != NULL ); - - for( i = 0 ; i < list->count ; i++ ) - { - thisWall = (wall_t *)list->list[i]; - assert( thisWall != NULL ); - drawWall(thisWall); - } -} - -#endif - -void eventConflictShotWithWall() -{ - arena_t *arena; - shot_t *thisShot; - tux_t *author; - int i; - - arena = export_fce->fce_getCurrentArena(); - - for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) - { - thisShot = (shot_t *)arena->spaceShot->list->list[i]; - assert( thisShot != NULL ); - - if( isConflictWithObjectFromSpace(spaceWall, thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) - { - author = getObjectFromSpaceWithID( - export_fce->fce_getCurrentArena()->spaceTux, 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; - } - - delObjectFromSpaceWithObject(export_fce->fce_getCurrentArena()->spaceShot, - thisShot, export_fce->fce_destroyShot); - - //delListItem(listShot, i, export_fce->fce_destroyShot); - i--; - } - } -} - -void destroyWall(wall_t *p) -{ - assert( p != NULL ); - free(p); -} - -static void getStatusWall(void *p, int *id, int *x, int *y, int *w, int *h) -{ - wall_t *wall; - - wall = p; - - *id = wall->id; - *x = wall->x; - *y = wall->y; - *w = wall->w; - *h = wall->h; -} - -static void setStatusWall(void *p, int x, int y, int w, int h) -{ - wall_t *wall; - - wall = p; - - wall->x = x; - wall->y = y; - wall->w = w; - wall->h = h; -} - -#ifndef PUBLIC_SERVER - -static void getStatusImgWall(void *p, int *id, int *x, int *y, int *w, int *h) -{ - wall_t *wall; - - wall = p; - - *id = wall->id; - *x = wall->img_x; - *y = wall->img_y; - *w = wall->img->w; - *h = wall->img->h; -} - -static void setStatusImgWall(void *p, int x, int y, int w, int h) -{ -} - -#endif - -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 - - if( spaceWall == NULL ) - { - spaceWall = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, - 320, 240, getStatusWall, setStatusWall); - -#ifndef PUBLIC_SERVER - spaceImgWall = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, - 320, 240, getStatusImgWall, setStatusImgWall); -#endif - } - - addObjectToSpace(spaceWall, new); - -#ifndef PUBLIC_SERVER - addObjectToSpace(spaceImgWall, new); -#endif -} - -int init(export_fce_t *p) -{ - export_fce = p; - listWall = newList(); - - return 0; -} - -#ifndef PUBLIC_SERVER - -int draw(int x, int y, int w, int h) -{ - wall_t *thisWall; - int i; - - if( spaceWall == NULL ) - { - return 0; - } - - listDoEmpty(listWall); - getObjectFromSpace(spaceImgWall, x, y, w, h, listWall); - - for( i = 0 ; i < listWall->count ; i++ ) - { - thisWall = (wall_t *)listWall->list[i]; - assert( thisWall != NULL ); - drawWall(thisWall); - } - - //printSpace(spaceWall); - - return 0; -} -#endif - - -int event() -{ - if( spaceWall == NULL ) - { - return 0; - } - - eventConflictShotWithWall(export_fce->fce_getCurrentArena()->spaceShot->list); - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - if( spaceWall == NULL ) - { - return 0; - } - - return isConflictWithObjectFromSpace(spaceWall, x, y, w, h); -} - -void cmd(char *line) -{ - if( strncmp(line, "wall", 4) == 0 )cmd_wall(line); -} - -int destroy() -{ - if( spaceWall != NULL ) - { - destroySpaceWithObject(spaceWall, destroyWall); - } - -#ifndef PUBLIC_SERVER - if( spaceImgWall != NULL ) - { - destroySpace(spaceImgWall); - } -#endif - - if( listWall != NULL ) - { - destroyList(listWall); - } - - return 0; -} diff --git a/modules/space.c b/modules/space.c deleted file mode 100644 index 96ac81b..0000000 --- a/modules/space.c +++ /dev/null @@ -1,615 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "space.h" - -#define DEBUG_SPACE -#define ERROR_SUPPORT - -#ifdef DEBUG_SPACE - - -typedef struct recv_struct -{ - int id; - int x, y; - int w, h; -} recv_t; - -recv_t* newRecv(int id, int x , int y, int w, int h) -{ - recv_t *new; - - new = malloc( sizeof(recv_t) ); - memset(new, 0, sizeof(recv_t)); - - new->id = 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 (x1w = 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; -} - -#ifdef ERROR_SUPPORT - -void printListID(space_t *space) -{ - int i; - - for( i = 0 ; i < space->list->count ; i++ ) - { - int id, x, y, w, h; - - space->getStatus(space->list->list[i], &id, &x, &y, &w, &h); - printf("%d\n", id); - } - - putchar('\n'); -} - -static void checkList(space_t *space) -{ - int id, x, y, w, h; - int thisId; - int i; - - if( space->list->count == 0 ) - { - printf("nothing\n"); - return; - } - - space->getStatus(space->list->list[0], &thisId, &x, &y, &w, &h); - - for( i = 1 ; i < space->list->count ; i++ ) - { - space->getStatus(space->list->list[i], &id, &x, &y, &w, &h); - - if( id <= thisId ) - { - printListID(space); - assert( ! "error" ); - } - - thisId = id; - } -} - -static void addToListOnTheBaseIndex(space_t *space, void *p) -{ - int id, point_id, inc_point_id; - int x, y, w, h; - int len; - int min, max; - int point; - - - len = space->list->count; - - space->getStatus(p, &id, &x, &y, &w, &h); -/* - printf("addToListOnTheBaseIndex (%d)\n", id); - printListID(space); - assert( id >= 0 ); -*/ - if( len == 0 ) - { - //printf("OK first\n"); - addList(space->list, p); - return; - } - - if( len == 1 ) - { - space->getStatus(space->list->list[0], &point_id, &x, &y, &w, &h); - - if( id > point_id ) - { - addList(space->list, p); - } - - if( id < point_id ) - { - insList(space->list, 0, p); - } - - //printf("OK\n"); - - return; - } - - min = 0; - max = len-1; -/* - if( max < 0 ) - { - max = 0; - } -*/ - for(;;) - { - point = min + ( max - min ) / 2; -/* - space->getStatus(space->list->list[min], &id_min, &x, &y, &w, &h); - space->getStatus(space->list->list[max], &id_max, &x, &y, &w, &h); -*/ - //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id); - - if( max < 0 ) - { - //printf("OK first\n"); - insList(space->list, 0, p); - //checkList(space); - return; - } - - if( point+1 >= len /*|| min >= len*/ ) - { - addList(space->list, p); - //printf("OK height\n"); - //checkList(space); - return; - } - - space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h); - space->getStatus(space->list->list[point+1], &inc_point_id, &x, &y, &w, &h); -/* - if( min == max ) - { - //printf("OK\n"); - insList(space->list, min, p); - checkList(space); - return; - } -*/ - if( point_id < id && id < inc_point_id ) - { - //printf("OK\n"); - insList(space->list, point+1, p); - //checkList(space); - return; - } - - if( id > inc_point_id ) - { - min = point + 1; - continue; - } - - if( id < point_id ) - { - max = point - 1; - continue; - } - } -} - -#endif - -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); - } - } - -#ifdef ERROR_SUPPORT - addToListOnTheBaseIndex(p, item); -#endif - -#ifndef ERROR_SUPPORT - addList(p->list, item); -#endif -} - -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 *space, int id) -{ -#ifdef ERROR_SUPPORT - int point_id; - int x, y, w, h; - int len; - int min, max; - int point; - -/* - printf("getObjectFromSpaceWithID %d\n", id); - printListID(space); -*/ - len = space->list->count; - - min = 0; - max = len-1; - - for(;;) - { - point = min + ( max - min ) / 2; - - //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id); - - if( max < 0 || point >= len || max < min ) - { - return NULL; - } - - space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h); - - if( min == max ) - { - space->getStatus(space->list->list[min], &point_id, &x, &y, &w, &h); - } - - if( point_id == id ) - { - return space->list->list[point]; - } - - if( id > point_id ) - { - min = point + 1; - continue; - } - - if( id < point_id ) - { - max = point - 1; - continue; - } - } - -#endif - -#ifndef ERROR_SUPPORT - int this_id, x, y, w, h; - void *this; - int i; - - for( i = 0 ; i < space->list->count ; i++ ) - { - this = space->list->list[i]; - assert( this != NULL ); - - space->getStatus(this, &this_id, &x, &y, &w, &h); - - if( this_id == id ) - { - return this; - } - } - - return NULL; -#endif -} - -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; -} - -int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, void *but) -{ - 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]; - - if( this == but ) - { - continue; - } - - 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 delObjectFromSpaceWithObject(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) -{ - int j, i; - - destroyList(p->list); - - 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); -} - -void destroySpaceWithObject(space_t *p, void *f) -{ - void (*fce)(void *param); - int i; - - fce = f; - - for( i = 0 ; i < p->list->count ; i++ ) - fce(p->list->list[i]); - - destroySpace(p); -} - -#ifdef DEBUG_SPACE - -void test_space() -{/* - space_t *space; - recv_t *recv; - - space = newSpace(5000, 2500, 320, 240, getStatus, setStatus); - - addObjectToSpace(space, newRecv(5, 0, 0, 1, 1) ); - addObjectToSpace(space, newRecv(7, 0, 0, 1, 1) ); - addObjectToSpace(space, newRecv(8, 0, 0, 1, 1) ); - addObjectToSpace(space, newRecv(9, 0, 0, 1, 1) ); - addObjectToSpace(space, newRecv(6, 0, 0, 1, 1) ); -*/ -/* - recv = getObjectFromSpaceWithID(space, 6); - if( recv != NULL )printf("id = %d\n", recv->id); -*/ -// printListID(space); -} - -#endif - diff --git a/modules/space.h b/modules/space.h deleted file mode 100644 index de31768..0000000 --- a/modules/space.h +++ /dev/null @@ -1,38 +0,0 @@ - -#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 int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, void *but); -extern void delObjectFromSpace(space_t *p, void *item); -extern void delObjectFromSpaceWithObject(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); -extern void destroySpaceWithObject(space_t *p, void *f); - -#endif - -- cgit v1.2.3