From 44daf03024fbf7cbffa10349044786f6ab784821 Mon Sep 17 00:00:00 2001 From: "Tomas Chvatal (scarabeus)" Date: Wed, 22 Oct 2008 22:51:24 +0200 Subject: Revert "X" This reverts commit e12753d2ec9db83ec08bb9db63902a82fb245cdd. --- src/modules/modAI.c | 541 +++++++++++++++++++++++---------------------- src/modules/modAI.c~ | 421 ----------------------------------- src/modules/modBasic.c | 54 ++--- src/modules/modBasic.c~ | 75 ------- src/modules/modMove.c | 351 ++++++++++++++--------------- src/modules/modMove.c~ | 239 -------------------- src/modules/modPipe.c | 421 +++++++++++++++++------------------ src/modules/modPipe.c~ | 335 ---------------------------- src/modules/modTeleport.c | 403 ++++++++++++++++----------------- src/modules/modTeleport.c~ | 344 ---------------------------- src/modules/modWall.c | 414 ++++++++++++++++------------------ src/modules/modWall.c~ | 343 ---------------------------- 12 files changed, 1041 insertions(+), 2900 deletions(-) delete mode 100644 src/modules/modAI.c~ delete mode 100644 src/modules/modBasic.c~ delete mode 100644 src/modules/modMove.c~ delete mode 100644 src/modules/modPipe.c~ delete mode 100644 src/modules/modTeleport.c~ delete mode 100644 src/modules/modWall.c~ (limited to 'src/modules') diff --git a/src/modules/modAI.c b/src/modules/modAI.c index d758813..372e8cb 100755 --- a/src/modules/modAI.c +++ b/src/modules/modAI.c @@ -13,319 +13,326 @@ #include "space.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" + #include "interface.h" + #include "image.h" #else -#include "publicServer.h" + #include "publicServer.h" #endif static export_fce_t *export_fce; typedef struct alternative_struct { - int first; - int route; - int step; - int x, y; + int first; + int route; + int step; + int x, y; } alternative_t; -alternative_t * -newAlternative(int route, int x, int y) +alternative_t* newAlternative(int route, int x, int y) { - alternative_t *new; + alternative_t *new; - new = malloc(sizeof(alternative_t)); - new->first = route; - new->route = route; - new->x = x; - new->y = y; - new->step = 0; + new = malloc( sizeof(alternative_t) ); + new->first = route; + new->route = route; + new->x = x; + new->y = y; + new->step = 0; - return new; + return new; } -alternative_t * -cloneAlternative(alternative_t * p, int route, int x, int y) +alternative_t* cloneAlternative(alternative_t *p, int route, int x, int y) { - alternative_t *new; + alternative_t *new; - assert(p != NULL); + assert( p != NULL ); + + new = newAlternative(route, p->x, p->y); + new->first = p->first; + new->step = p->step; - new = newAlternative(route, p->x, p->y); - new->first = p->first; - new->step = p->step; - - return new; + return new; } -void -forkAlternative(list_t * list, alternative_t * p, int w, int h) +void forkAlternative(list_t *list, alternative_t *p, int w, int h) { - int x, y; - - assert(list != NULL); - assert(p != NULL); - - x = p->x; - y = p->y; - - switch (p->route) { - case TUX_UP: - addList(list, cloneAlternative(p, TUX_RIGHT, x + (w + 5), y)); - addList(list, cloneAlternative(p, TUX_LEFT, x - (w + 5), y)); - break; - case TUX_RIGHT: - addList(list, cloneAlternative(p, TUX_UP, x, y - (h + 5))); - addList(list, cloneAlternative(p, TUX_DOWN, x, y + (h + 5))); - break; - case TUX_LEFT: - addList(list, cloneAlternative(p, TUX_UP, x, y - (h + 5))); - addList(list, cloneAlternative(p, TUX_DOWN, x, y + (h + 5))); - break; - case TUX_DOWN: - addList(list, cloneAlternative(p, TUX_RIGHT, x + (w + 5), y)); - addList(list, cloneAlternative(p, TUX_LEFT, x - (w + 5), y)); - break; - } + int x, y; + + assert( list != NULL ); + assert( p != NULL ); + + x = p->x; + y = p->y; + + switch( p->route ) + { + case TUX_UP : + addList(list, cloneAlternative(p, TUX_RIGHT, x+(w+5), y ) ); + addList(list, cloneAlternative(p, TUX_LEFT, x-(w+5), y ) ); + break; + case TUX_RIGHT : + addList(list, cloneAlternative(p, TUX_UP, x, y-(h+5) ) ); + addList(list, cloneAlternative(p, TUX_DOWN, x, y+(h+5) ) ); + break; + case TUX_LEFT : + addList(list, cloneAlternative(p, TUX_UP, x, y-(h+5) ) ); + addList(list, cloneAlternative(p, TUX_DOWN, x, y+(h+5) ) ); + break; + case TUX_DOWN : + addList(list, cloneAlternative(p, TUX_RIGHT, x+(w+5), y ) ); + addList(list, cloneAlternative(p, TUX_LEFT, x-(w+5), y ) ); + break; + } } -void -moveAlternative(alternative_t * p, int offset) +void moveAlternative(alternative_t *p, int offset) { - assert(p != NULL); - - p->step++; - - //printf("move %d %d %d\n", p->x, p->y, p->step); - - switch (p->route) { - case TUX_UP: - p->y -= offset; - break; - case TUX_RIGHT: - p->x += offset; - break; - case TUX_LEFT: - p->x -= offset; - break; - case TUX_DOWN: - p->y += offset; - break; - } + assert( p != NULL ); + + p->step++; + + //printf("move %d %d %d\n", p->x, p->y, p->step); + + switch( p->route ) + { + case TUX_UP : + p->y -= offset; + break; + case TUX_RIGHT : + p->x += offset; + break; + case TUX_LEFT : + p->x -= offset; + break; + case TUX_DOWN : + p->y += offset; + break; + } } -void -destroyAlternative(alternative_t * p) +void destroyAlternative(alternative_t *p) { - assert(p != NULL); - free(p); + assert( p != NULL ); + free(p); } -static void -cmd_ai(char *line) +static void cmd_ai(char *line) { } -int -init(export_fce_t * p) +int init(export_fce_t *p) { - export_fce = p; + export_fce = p; - return 0; + return 0; } #ifndef PUBLIC_SERVER -int -draw(int x, int y, int w, int h) +int draw(int x, int y, int w, int h) { - return 0; + return 0; } #endif -tux_t * -findOtherTux(space_t * space) +tux_t *findOtherTux(space_t *space) { - int i; + int i; - for (i = 0; i < getSpaceCount(space); i++) { - tux_t *thisTux; + for( i = 0 ; i < getSpaceCount(space) ; i++ ) + { + tux_t *thisTux; - thisTux = getItemFromSpace(space, i); + thisTux = getItemFromSpace(space, i); - if (thisTux->control != TUX_CONTROL_AI) { - return thisTux; - } - } + if( thisTux->control != TUX_CONTROL_AI ) + { + return thisTux; + } + } - return NULL; + return NULL; } -static void -shotTux(arena_t * arena, tux_t * tux_ai, tux_t * tux_rival) +static void shotTux(arena_t *arena, tux_t *tux_ai, tux_t *tux_rival) { - const int limit = 20; - int x_ai, y_ai; - int x_rival, y_rival; - int w, h; - - export_fce->fce_getTuxProportion(tux_ai, &x_ai, &y_ai, &w, &h); - export_fce->fce_getTuxProportion(tux_rival, &x_rival, &y_rival, &w, &h); - - if (y_rival < y_ai && x_rival > x_ai && x_rival < x_ai + limit) { - export_fce->fce_actionTux(tux_ai, TUX_UP); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } - - if (x_rival > x_ai && y_rival > y_ai && y_rival < y_ai + limit) { - export_fce->fce_actionTux(tux_ai, TUX_RIGHT); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } - - if (x_rival < x_ai && y_rival > y_ai && y_rival < y_ai + limit) { - export_fce->fce_actionTux(tux_ai, TUX_LEFT); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } - - if (y_rival > y_ai && x_rival > x_ai && x_rival < x_ai + limit) { - export_fce->fce_actionTux(tux_ai, TUX_DOWN); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } -} + const int limit = 20; + int x_ai, y_ai; + int x_rival, y_rival; + int w, h; -static void -eventTuxAI(tux_t * tux) -{ - arena_t *arena; - tux_t *rivalTux; + export_fce->fce_getTuxProportion(tux_ai, &x_ai, &y_ai, &w, &h); + export_fce->fce_getTuxProportion(tux_rival, &x_rival, &y_rival, &w, &h); - list_t *listAlternative; - list_t *listDst; - list_t *listFork; + if( y_rival < y_ai && x_rival > x_ai && x_rival < x_ai+limit ) + { + export_fce->fce_actionTux(tux_ai, TUX_UP); + export_fce->fce_actionTux(tux_ai, TUX_SHOT); + } - int x, y, w, h; - int rival_x, rival_y; - int i, index; + if( x_rival > x_ai && y_rival > y_ai && y_rival < y_ai+limit ) + { + export_fce->fce_actionTux(tux_ai, TUX_RIGHT); + export_fce->fce_actionTux(tux_ai, TUX_SHOT); + } - int countFork = 0; - int countDel = 0; - int countLimit = 0; - int countDo = 0; + if( x_rival < x_ai && y_rival > y_ai && y_rival < y_ai+limit ) + { + export_fce->fce_actionTux(tux_ai, TUX_LEFT); + export_fce->fce_actionTux(tux_ai, TUX_SHOT); + } - export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); - //printf("tux AI %d %d\n", x, y); + if( y_rival > y_ai && x_rival > x_ai && x_rival < x_ai+limit ) + { + export_fce->fce_actionTux(tux_ai, TUX_DOWN); + export_fce->fce_actionTux(tux_ai, TUX_SHOT); + } +} - arena = export_fce->fce_getCurrentArena(); +static void eventTuxAI(tux_t *tux) +{ + arena_t *arena; + tux_t *rivalTux; - rivalTux = findOtherTux(arena->spaceTux); + list_t *listAlternative; + list_t *listDst; + list_t *listFork; - if (rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE) { - return; - } + int x, y, w, h; + int rival_x, rival_y; + int i, index; - listAlternative = newList(); - listDst = newList(); - listFork = newList(); + int countFork = 0; + int countDel = 0; + int countLimit = 0; + int countDo = 0; - shotTux(arena, tux, rivalTux); + export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); + //printf("tux AI %d %d\n", x, y); - export_fce->fce_getTuxProportion(rivalTux, &rival_x, &rival_y, NULL, NULL); - //printf("tux rival %d %d\n", rival_x, rival_y); + arena = export_fce->fce_getCurrentArena(); - addList(listAlternative, newAlternative(TUX_UP, x, y - (h + 10))); - addList(listAlternative, newAlternative(TUX_RIGHT, x + (w + 10), y)); - addList(listAlternative, newAlternative(TUX_LEFT, x - (w + 10), y)); - addList(listAlternative, newAlternative(TUX_DOWN, x, y + (h + 10))); + rivalTux = findOtherTux(arena->spaceTux); - index = -1; - while (1) { - alternative_t *this; + if( rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE ) + { + return; + } - index++; - if (index < 0 || index >= listAlternative->count) { + listAlternative = newList(); + listDst = newList(); + listFork = newList(); - int j; + shotTux(arena, tux, rivalTux); - //printf("listFork->count = %d\n", listFork->count); + export_fce->fce_getTuxProportion(rivalTux, &rival_x, &rival_y, NULL, NULL); + //printf("tux rival %d %d\n", rival_x, rival_y); - for (j = 0; j < listFork->count; j++) { - addList(listAlternative, listFork->list[j]); - } + addList(listAlternative, newAlternative(TUX_UP, x, y-(h+10)) ); + addList(listAlternative, newAlternative(TUX_RIGHT, x+(w+10), y) ); + addList(listAlternative, newAlternative(TUX_LEFT, x-(w+10), y) ); + addList(listAlternative, newAlternative(TUX_DOWN, x, y+(h+10)) ); - listDoEmpty(listFork); + index = -1; + while(1) + { + alternative_t *this; - index = 0; - } + index++; + if( index < 0 || index >= listAlternative->count ) + { - if (listAlternative->count == 0) { - break; - } + int j; - this = (alternative_t *) listAlternative->list[index]; + //printf("listFork->count = %d\n", listFork->count); - if (++countDo == 100) - break; + for( j = 0; j < listFork->count ; j++ ) + { + addList(listAlternative, listFork->list[j]); + } - if (this->step > 100) { - delListItem(listAlternative, index, destroyAlternative); - countLimit++; - index--; - continue; - } + listDoEmpty(listFork); - moveAlternative(this, w * 2); + index = 0; + } - if (export_fce->fce_isFreeSpace(arena, this->x, this->y, w, h) == 1) { - forkAlternative(listFork, this, 2 * w, 2 * h); - countFork++; - continue; - } + if( listAlternative->count == 0 ) + { + break; + } - if (export_fce-> - fce_conflictSpace(this->x, this->y, w, h, rival_x, rival_y, w, h)) { - //printf("this->step = %d\n", this->step); + this = (alternative_t *)listAlternative->list[index]; + + if( ++countDo == 100 )break; - delList(listAlternative, index); - addList(listDst, this); - index--; - //continue; - break; - } + if( this->step > 100 ) + { + delListItem(listAlternative, index, destroyAlternative); + countLimit++; + index--; + continue; + } - if (export_fce->fce_isFreeSpace(arena, this->x, this->y, w, h) == 0) { - //forkAlternative(listFork, this, w*2, h*2); - delListItem(listAlternative, index, destroyAlternative); - index--; - countDel++; + moveAlternative(this, w*2); - continue; - } + if( export_fce->fce_isFreeSpace(arena, this->x, this->y, w, h) == 1 ) + { + forkAlternative(listFork, this, 2*w, 2*h); + countFork++; + continue; + } + + if( export_fce->fce_conflictSpace(this->x, this->y, w, h, rival_x, rival_y, w, h) ) + { + //printf("this->step = %d\n", this->step); + + delList(listAlternative, index); + addList(listDst, this); + index--; + //continue; + break; + } + + if( export_fce->fce_isFreeSpace(arena, this->x, this->y, w, h) == 0 ) + { + //forkAlternative(listFork, this, w*2, h*2); + delListItem(listAlternative, index, destroyAlternative); + index--; + countDel++; + + continue; + } - } + } - int minStep = 1000; - int recRoute = 0; + int minStep = 1000; + int recRoute = 0; - //printf("------------\n"); - for (i = 0; i < listDst->count; i++) { - alternative_t *this; + //printf("------------\n"); + for( i = 0 ; i < listDst->count ; i++ ) + { + alternative_t *this; - this = (alternative_t *) listDst->list[i]; + this = (alternative_t *)listDst->list[i]; - //printf("XXX step %d route = %d\n", this->step, this->first); - if (this->step < minStep) { - minStep = this->step; - recRoute = this->first; - } - } + //printf("XXX step %d route = %d\n", this->step, this->first); + if( this->step < minStep ) + { + minStep = this->step; + recRoute = this->first; + } + } - if (recRoute != 0) { - export_fce->fce_actionTux(tux, recRoute); - } + if( recRoute != 0 ) + { + export_fce->fce_actionTux(tux, recRoute); + } - destroyListItem(listFork, destroyAlternative); - destroyListItem(listAlternative, destroyAlternative); - destroyListItem(listDst, destroyAlternative); + destroyListItem(listFork, destroyAlternative); + destroyListItem(listAlternative, destroyAlternative); + destroyListItem(listDst, destroyAlternative); /* printf("countFork = %d\n", countFork); printf("countDel = %d\n", countDel); @@ -334,45 +341,48 @@ eventTuxAI(tux_t * tux) */ } -static void -action_tuxAI(space_t * space, tux_t * tux, void *p) +static void action_tuxAI(space_t *space, tux_t *tux, void *p) { - if (tux->control == TUX_CONTROL_AI && tux->status == TUX_STATUS_ALIVE) { - eventTuxAI(tux); - } + if( tux->control == TUX_CONTROL_AI && + tux->status == TUX_STATUS_ALIVE ) + { + eventTuxAI(tux); + } } -int -event() +int event() { - static my_time_t lastEvent = 0; - my_time_t curentTime; - arena_t *arena; - int countTuxAI; - //int i; + 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(); - } + if( lastEvent == 0 ) + { + lastEvent = export_fce->fce_getMyTime(); + } - curentTime = export_fce->fce_getMyTime(); + curentTime = export_fce->fce_getMyTime(); - if (curentTime - lastEvent < 25) { - return 0; - } + if( curentTime - lastEvent < 25 ) + { + return 0; + } - lastEvent = export_fce->fce_getMyTime(); - //printf("event AI\n"); + lastEvent = export_fce->fce_getMyTime(); + //printf("event AI\n"); - arena = export_fce->fce_getCurrentArena(); + arena = export_fce->fce_getCurrentArena(); - if (arena == NULL) { - return 0; - } + if( arena == NULL ) + { + return 0; + } - countTuxAI = 0; + countTuxAI = 0; - actionSpace(arena->spaceTux, action_tuxAI, NULL); + actionSpace(arena->spaceTux, action_tuxAI, NULL); /* for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) { @@ -388,29 +398,24 @@ event() } } */ - return 0; + return 0; } -int -isConflict(int x, int y, int w, int h) +int isConflict(int x, int y, int w, int h) { - return 0; + return 0; } -void -cmdArena(char *line) +void cmdArena(char *line) { - if (strncmp(line, "ai", 2) == 0) - cmd_ai(line); + if( strncmp(line, "ai", 2) == 0 )cmd_ai(line); } -void -recvMsg(char *msg) +void recvMsg(char *msg) { } -int -destroy() +int destroy() { - return 0; + return 0; } diff --git a/src/modules/modAI.c~ b/src/modules/modAI.c~ deleted file mode 100644 index 372e8cb..0000000 --- a/src/modules/modAI.c~ +++ /dev/null @@ -1,421 +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" -#else - #include "publicServer.h" -#endif - -static export_fce_t *export_fce; - -typedef struct alternative_struct -{ - int first; - int route; - int step; - int x, y; -} alternative_t; - -alternative_t* newAlternative(int route, int x, int y) -{ - alternative_t *new; - - new = malloc( sizeof(alternative_t) ); - new->first = route; - new->route = route; - new->x = x; - new->y = y; - new->step = 0; - - return new; -} - -alternative_t* cloneAlternative(alternative_t *p, int route, int x, int y) -{ - alternative_t *new; - - assert( p != NULL ); - - new = newAlternative(route, p->x, p->y); - new->first = p->first; - new->step = p->step; - - return new; -} - -void forkAlternative(list_t *list, alternative_t *p, int w, int h) -{ - int x, y; - - assert( list != NULL ); - assert( p != NULL ); - - x = p->x; - y = p->y; - - switch( p->route ) - { - case TUX_UP : - addList(list, cloneAlternative(p, TUX_RIGHT, x+(w+5), y ) ); - addList(list, cloneAlternative(p, TUX_LEFT, x-(w+5), y ) ); - break; - case TUX_RIGHT : - addList(list, cloneAlternative(p, TUX_UP, x, y-(h+5) ) ); - addList(list, cloneAlternative(p, TUX_DOWN, x, y+(h+5) ) ); - break; - case TUX_LEFT : - addList(list, cloneAlternative(p, TUX_UP, x, y-(h+5) ) ); - addList(list, cloneAlternative(p, TUX_DOWN, x, y+(h+5) ) ); - break; - case TUX_DOWN : - addList(list, cloneAlternative(p, TUX_RIGHT, x+(w+5), y ) ); - addList(list, cloneAlternative(p, TUX_LEFT, x-(w+5), y ) ); - break; - } - -} - -void moveAlternative(alternative_t *p, int offset) -{ - assert( p != NULL ); - - p->step++; - - //printf("move %d %d %d\n", p->x, p->y, p->step); - - switch( p->route ) - { - case TUX_UP : - p->y -= offset; - break; - case TUX_RIGHT : - p->x += offset; - break; - case TUX_LEFT : - p->x -= offset; - break; - case TUX_DOWN : - p->y += offset; - break; - } -} - -void destroyAlternative(alternative_t *p) -{ - assert( p != NULL ); - free(p); -} - -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 - -tux_t *findOtherTux(space_t *space) -{ - int i; - - for( i = 0 ; i < getSpaceCount(space) ; i++ ) - { - tux_t *thisTux; - - thisTux = getItemFromSpace(space, i); - - if( thisTux->control != TUX_CONTROL_AI ) - { - return thisTux; - } - } - - return NULL; -} - -static void shotTux(arena_t *arena, tux_t *tux_ai, tux_t *tux_rival) -{ - const int limit = 20; - int x_ai, y_ai; - int x_rival, y_rival; - int w, h; - - export_fce->fce_getTuxProportion(tux_ai, &x_ai, &y_ai, &w, &h); - export_fce->fce_getTuxProportion(tux_rival, &x_rival, &y_rival, &w, &h); - - if( y_rival < y_ai && x_rival > x_ai && x_rival < x_ai+limit ) - { - export_fce->fce_actionTux(tux_ai, TUX_UP); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } - - if( x_rival > x_ai && y_rival > y_ai && y_rival < y_ai+limit ) - { - export_fce->fce_actionTux(tux_ai, TUX_RIGHT); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } - - if( x_rival < x_ai && y_rival > y_ai && y_rival < y_ai+limit ) - { - export_fce->fce_actionTux(tux_ai, TUX_LEFT); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } - - if( y_rival > y_ai && x_rival > x_ai && x_rival < x_ai+limit ) - { - export_fce->fce_actionTux(tux_ai, TUX_DOWN); - export_fce->fce_actionTux(tux_ai, TUX_SHOT); - } -} - -static void eventTuxAI(tux_t *tux) -{ - arena_t *arena; - tux_t *rivalTux; - - list_t *listAlternative; - list_t *listDst; - list_t *listFork; - - int x, y, w, h; - int rival_x, rival_y; - int i, index; - - int countFork = 0; - int countDel = 0; - int countLimit = 0; - int countDo = 0; - - export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); - //printf("tux AI %d %d\n", x, y); - - arena = export_fce->fce_getCurrentArena(); - - rivalTux = findOtherTux(arena->spaceTux); - - if( rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE ) - { - return; - } - - listAlternative = newList(); - listDst = newList(); - listFork = newList(); - - shotTux(arena, tux, rivalTux); - - export_fce->fce_getTuxProportion(rivalTux, &rival_x, &rival_y, NULL, NULL); - //printf("tux rival %d %d\n", rival_x, rival_y); - - addList(listAlternative, newAlternative(TUX_UP, x, y-(h+10)) ); - addList(listAlternative, newAlternative(TUX_RIGHT, x+(w+10), y) ); - addList(listAlternative, newAlternative(TUX_LEFT, x-(w+10), y) ); - addList(listAlternative, newAlternative(TUX_DOWN, x, y+(h+10)) ); - - index = -1; - while(1) - { - alternative_t *this; - - index++; - if( index < 0 || index >= listAlternative->count ) - { - - int j; - - //printf("listFork->count = %d\n", listFork->count); - - for( j = 0; j < listFork->count ; j++ ) - { - addList(listAlternative, listFork->list[j]); - } - - listDoEmpty(listFork); - - index = 0; - } - - if( listAlternative->count == 0 ) - { - break; - } - - this = (alternative_t *)listAlternative->list[index]; - - if( ++countDo == 100 )break; - - if( this->step > 100 ) - { - delListItem(listAlternative, index, destroyAlternative); - countLimit++; - index--; - continue; - } - - moveAlternative(this, w*2); - - if( export_fce->fce_isFreeSpace(arena, this->x, this->y, w, h) == 1 ) - { - forkAlternative(listFork, this, 2*w, 2*h); - countFork++; - continue; - } - - if( export_fce->fce_conflictSpace(this->x, this->y, w, h, rival_x, rival_y, w, h) ) - { - //printf("this->step = %d\n", this->step); - - delList(listAlternative, index); - addList(listDst, this); - index--; - //continue; - break; - } - - if( export_fce->fce_isFreeSpace(arena, this->x, this->y, w, h) == 0 ) - { - //forkAlternative(listFork, this, w*2, h*2); - delListItem(listAlternative, index, destroyAlternative); - index--; - countDel++; - - continue; - } - - } - - int minStep = 1000; - int recRoute = 0; - - //printf("------------\n"); - for( i = 0 ; i < listDst->count ; i++ ) - { - alternative_t *this; - - this = (alternative_t *)listDst->list[i]; - - //printf("XXX step %d route = %d\n", this->step, this->first); - if( this->step < minStep ) - { - minStep = this->step; - recRoute = this->first; - } - } - - if( recRoute != 0 ) - { - export_fce->fce_actionTux(tux, recRoute); - } - - destroyListItem(listFork, destroyAlternative); - destroyListItem(listAlternative, destroyAlternative); - destroyListItem(listDst, destroyAlternative); -/* - printf("countFork = %d\n", countFork); - printf("countDel = %d\n", countDel); - printf("countLimit = %d\n", countLimit); - printf("countDo = %d\n", countDo); -*/ -} - -static void action_tuxAI(space_t *space, tux_t *tux, void *p) -{ - if( tux->control == TUX_CONTROL_AI && - tux->status == TUX_STATUS_ALIVE ) - { - eventTuxAI(tux); - } -} - -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(); - - if( arena == NULL ) - { - return 0; - } - - countTuxAI = 0; - - actionSpace(arena->spaceTux, action_tuxAI, NULL); -/* - 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 cmdArena(char *line) -{ - if( strncmp(line, "ai", 2) == 0 )cmd_ai(line); -} - -void recvMsg(char *msg) -{ -} - -int destroy() -{ - return 0; -} diff --git a/src/modules/modBasic.c b/src/modules/modBasic.c index d50c8f8..8329b14 100755 --- a/src/modules/modBasic.c +++ b/src/modules/modBasic.c @@ -23,61 +23,53 @@ static export_fce_t *export_fce; -int -init(export_fce_t * p) +int init(export_fce_t *p) { - export_fce = p; + export_fce = p; - printf("Initializing Basic module.\n"); - return 0; + printf("Initializing Basic module.\n"); + return 0; } #ifndef PUBLIC_SERVER -int -draw(int x, int y, int w, int h) +int draw(int x, int y, int w, int h) { - printf("Drawing Basic module.\n"); - return 0; + printf("Drawing Basic module.\n"); + return 0; } #endif -int -event() +int event() { - printf("Basic module catch event.\n"); - return 0; + printf("Basic module catch event.\n"); + return 0; } -int -isConflict(int x, int y, int w, int h) +int isConflict(int x, int y, int w, int h) { - printf("isConflict(%d, %d, %d, %d) in Basic module.\n", x, y, w, h); - return 0; + printf("isConflict(%d, %d, %d, %d) in Basic module.\n", x, y, w, h); + return 0; } -static void -cmd_basic(char *line) +static void cmd_basic(char *line) { - printf("cmd_basic(%s) in Basic module.\n", line); + printf("cmd_basic(%s) in Basic module.\n", line); } -void -cmdArena(char *line) +void cmdArena(char *line) { - if (strncmp(line, "basic", 5) == 0) - cmd_basic(line); + if (strncmp(line, "basic", 5) == 0) + cmd_basic(line); } -void -recvMsg(char *msg) +void recvMsg(char *msg) { - printf("recvMsg(%s) in Basic module.\n", msg); + printf("recvMsg(%s) in Basic module.\n", msg); } -int -destroy() +int destroy() { - printf("Destroying Basic module.\n"); - return 0; + printf("Destroying Basic module.\n"); + return 0; } diff --git a/src/modules/modBasic.c~ b/src/modules/modBasic.c~ deleted file mode 100644 index 8329b14..0000000 --- a/src/modules/modBasic.c~ +++ /dev/null @@ -1,75 +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; - -int init(export_fce_t *p) -{ - export_fce = p; - - printf("Initializing Basic module.\n"); - return 0; -} - -#ifndef PUBLIC_SERVER - -int draw(int x, int y, int w, int h) -{ - printf("Drawing Basic module.\n"); - return 0; -} -#endif - -int event() -{ - printf("Basic module catch event.\n"); - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - printf("isConflict(%d, %d, %d, %d) in Basic module.\n", x, y, w, h); - return 0; -} - -static void cmd_basic(char *line) -{ - printf("cmd_basic(%s) in Basic module.\n", line); -} - -void cmdArena(char *line) -{ - if (strncmp(line, "basic", 5) == 0) - cmd_basic(line); -} - -void recvMsg(char *msg) -{ - printf("recvMsg(%s) in Basic module.\n", msg); -} - -int destroy() -{ - printf("Destroying Basic module.\n"); - return 0; -} diff --git a/src/modules/modMove.c b/src/modules/modMove.c index 6cfd59a..34222a6 100755 --- a/src/modules/modMove.c +++ b/src/modules/modMove.c @@ -24,237 +24,216 @@ static export_fce_t *export_fce; -static void -move_tux(tux_t * tux, int x, int y, int w, int h) +static void move_tux(tux_t *tux, int x, int y, int w, int h) { - int dist_x = 0, dist_y = 0; // no warnning - - if (tux->bonus == BONUS_GHOST || - export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; - switch (tux->position) { - case TUX_UP: - dist_x = x + w / 2; - dist_y = y - (TUX_HEIGHT + 20); - break; - case TUX_LEFT: - dist_x = x - (TUX_WIDTH + 20); - dist_y = y + h / 2; - break; - case TUX_RIGHT: - dist_x = x + w + 20; - dist_y = y + h / 2; - break; - case TUX_DOWN: - dist_x = x + w / 2; - dist_y = y + h + 20; - break; - default: - assert(!"Variable p->control has a really wierd value!"); - 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); + int dist_x = 0, dist_y = 0; // no warnning + + if (tux->bonus == BONUS_GHOST || + export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; + switch (tux->position) { + case TUX_UP : + dist_x = x + w/2; + dist_y = y - ( TUX_HEIGHT + 20 ); + break; + case TUX_LEFT : + dist_x = x - ( TUX_WIDTH + 20 ); + dist_y = y + h/2; + break; + case TUX_RIGHT : + dist_x = x + w + 20; + dist_y = y + h/2; + break; + case TUX_DOWN : + dist_x = x + w/2; + dist_y = y + h + 20; + break; + default : + assert( ! "Variable p->control has a really wierd value!" ); + 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); #ifndef PUBLIC_SERVER - //playSound("teleport", SOUND_GROUP_BASE); + //playSound("teleport", SOUND_GROUP_BASE); #endif - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) { - char msg[STR_PROTO_SIZE]; - sprintf(msg, "movetux %d %d %d", tux->id, dist_x, dist_y); - if (tux->bonus == BONUS_HIDDEN) - export_fce->fce_proto_send_module_server(PROTO_SEND_ONE, - (client_t *) tux->client, - msg); - else - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, - msg); - } - } + if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) { + char msg[STR_PROTO_SIZE]; + sprintf(msg, "movetux %d %d %d", tux->id, dist_x, dist_y); + if( tux->bonus == BONUS_HIDDEN ) + export_fce->fce_proto_send_module_server(PROTO_SEND_ONE, (client_t *)tux->client, msg); + else + export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); + } + } } -static int -myAbs(int n) +static int myAbs(int n) { - return (n > 0 ? n : -n); + return ( n > 0 ? n : -n ); } -static int -getSppedShot(shot_t * shot) +static int getSppedShot(shot_t *shot) { - return (myAbs(shot->px) > - myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py)); + return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); } -static void -transformShot(shot_t * shot, int position) +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); + int speed; + + speed = getSppedShot(shot); + switch (position) { + case TUX_UP : + shot->px = 0; + shot->py = -speed; + break; + case TUX_LEFT : + shot->px = -speed; + shot->py = 0; + break; + case TUX_RIGHT : + shot->px = speed; + shot->py = 0; + break; + case TUX_DOWN : + shot->px = 0; + shot->py = +speed; + break; + } + shot->position = position; + shot->isCanKillAuthor = TRUE; + if( shot->gun == GUN_LASSER ) + export_fce->fce_transformOnlyLasser(shot); } -static void -move_shot(shot_t * shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h) +static void move_shot(shot_t *shot, int position, int src_x, int src_y, + int dist_x, int dist_y, int dist_w, int dist_h) { - int offset = 0; - int new_x = 0, new_y = 0; // no warninng - - //printf("move_shot\n"); - switch (shot->position) { - case TUX_UP: - case TUX_DOWN: - offset = shot->x - src_x; - break; - case TUX_RIGHT: - case TUX_LEFT: - offset = shot->y - src_y; - break; - } - transformShot(shot, position); - switch (shot->position) { - case TUX_UP: - new_x = dist_x + offset; - new_y = dist_y - (shot->h + 5); - break; - case TUX_LEFT: - new_x = dist_x - (shot->w + 5); - new_y = dist_y + offset; - break; - case TUX_RIGHT: - new_x = dist_x + dist_w + 5; - new_y = dist_y + offset; - break; - case TUX_DOWN: - new_x = dist_x + offset; - new_y = dist_y + dist_h + 5; - break; - } - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, - new_x, new_y); - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) { - char msg[STR_PROTO_SIZE]; - - sprintf(msg, "moveshot %d %d %d %d %d %d", - shot->id, shot->x, shot->y, shot->px, shot->py, shot->position); - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); - } + int offset = 0; + int new_x = 0, new_y = 0; // no warninng + + //printf("move_shot\n"); + switch (shot->position) { + case TUX_UP : + case TUX_DOWN : + offset = shot->x - src_x; + break; + case TUX_RIGHT : + case TUX_LEFT : + offset = shot->y - src_y; + break; + } + transformShot(shot, position); + switch (shot->position) { + case TUX_UP : + new_x = dist_x + offset; + new_y = dist_y - ( shot->h + 5 ); + break; + case TUX_LEFT : + new_x = dist_x - ( shot->w + 5 ); + new_y = dist_y + offset; + break; + case TUX_RIGHT : + new_x = dist_x + dist_w + 5; + new_y = dist_y + offset; + break; + case TUX_DOWN : + new_x = dist_x + offset; + new_y = dist_y + dist_h + 5; + break; + } + moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); + if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) { + char msg[STR_PROTO_SIZE]; + + sprintf(msg, "moveshot %d %d %d %d %d %d", + shot->id, shot->x, shot->y, shot->px, shot->py, shot->position); + export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); + } } -int -init(export_fce_t * p) +int init(export_fce_t *p) { - export_fce = p; - export_fce->fce_addToShareFce("move_tux", (void *) move_tux); - export_fce->fce_addToShareFce("move_shot", (void *) move_shot); - return 0; + export_fce = p; + export_fce->fce_addToShareFce("move_tux", (void *)move_tux); + export_fce->fce_addToShareFce("move_shot", (void *)move_shot); + return 0; } -static void -proto_movetux(char *msg) +static void proto_movetux(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, x, y; - space_t *space; - tux_t *tux; - - assert(msg != NULL); - sscanf(msg, "%s %d %d %d", cmd, &id, &x, &y); - space = export_fce->fce_getCurrentArena()->spaceTux; - tux = getObjectFromSpaceWithID(space, id); - if (tux != NULL) - moveObjectInSpace(space, tux, x, y); + char cmd[STR_PROTO_SIZE]; + int id, x, y; + space_t *space; + tux_t *tux; + + assert( msg != NULL ); + sscanf(msg, "%s %d %d %d", + cmd, &id, &x, &y); + space = export_fce->fce_getCurrentArena()->spaceTux; + tux = getObjectFromSpaceWithID(space, id); + if (tux != NULL) + moveObjectInSpace(space, tux, x, y); } -static void -proto_moveshot(char *msg) +static void proto_moveshot(char *msg) { - char cmd[STR_PROTO_SIZE]; - int shot_id, x, y, px, py, position; - space_t *space; - shot_t *shot; - - assert(msg != NULL); - sscanf(msg, "%s %d %d %d %d %d %d", - cmd, &shot_id, &x, &y, &px, &py, &position); - space = export_fce->fce_getCurrentArena()->spaceShot; - if ((shot = getObjectFromSpaceWithID(space, shot_id)) == NULL) - return; - moveObjectInSpace(space, shot, x, y); - shot->isCanKillAuthor = 1; - shot->position = position; - shot->px = px; - shot->py = py; - if (shot->gun == GUN_LASSER) - export_fce->fce_transformOnlyLasser(shot); + char cmd[STR_PROTO_SIZE]; + int shot_id, x, y, px, py, position; + space_t *space; + shot_t *shot; + + assert( msg != NULL ); + sscanf(msg, "%s %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position); + space = export_fce->fce_getCurrentArena()->spaceShot; + if ((shot = getObjectFromSpaceWithID(space, shot_id)) == NULL) + return; + moveObjectInSpace(space, shot, x, y); + shot->isCanKillAuthor = 1; + shot->position = position; + shot->px = px; + shot->py = py; + if (shot->gun == GUN_LASSER) + export_fce->fce_transformOnlyLasser(shot); } #ifndef PUBLIC_SERVER -int -draw(int x, int y, int w, int h) +int draw(int x, int y, int w, int h) { - return 0; + return 0; } #endif -int -event() +int event() { - return 0; + return 0; } -int -isConflict(int x, int y, int w, int h) +int isConflict(int x, int y, int w, int h) { - return 0; + return 0; } -void -cmdArena(char *line) +void cmdArena(char *line) { } -void -recvMsg(char *msg) +void recvMsg(char *msg) { - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) - return; - if (strncmp(msg, "movetux", 7) == 0) - proto_movetux(msg); - if (strncmp(msg, "moveshot", 8) == 0) - proto_moveshot(msg); + if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) + return; + if (strncmp(msg, "movetux", 7) == 0) + proto_movetux(msg); + if (strncmp(msg, "moveshot", 8) == 0) + proto_moveshot(msg); } -int -destroy() +int destroy() { - return 0; + return 0; } diff --git a/src/modules/modMove.c~ b/src/modules/modMove.c~ deleted file mode 100644 index 34222a6..0000000 --- a/src/modules/modMove.c~ +++ /dev/null @@ -1,239 +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" -#include "serverSendMsg.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 move_tux(tux_t *tux, int x, int y, int w, int h) -{ - int dist_x = 0, dist_y = 0; // no warnning - - if (tux->bonus == BONUS_GHOST || - export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; - switch (tux->position) { - case TUX_UP : - dist_x = x + w/2; - dist_y = y - ( TUX_HEIGHT + 20 ); - break; - case TUX_LEFT : - dist_x = x - ( TUX_WIDTH + 20 ); - dist_y = y + h/2; - break; - case TUX_RIGHT : - dist_x = x + w + 20; - dist_y = y + h/2; - break; - case TUX_DOWN : - dist_x = x + w/2; - dist_y = y + h + 20; - break; - default : - assert( ! "Variable p->control has a really wierd value!" ); - 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); -#ifndef PUBLIC_SERVER - //playSound("teleport", SOUND_GROUP_BASE); -#endif - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) { - char msg[STR_PROTO_SIZE]; - sprintf(msg, "movetux %d %d %d", tux->id, dist_x, dist_y); - if( tux->bonus == BONUS_HIDDEN ) - export_fce->fce_proto_send_module_server(PROTO_SEND_ONE, (client_t *)tux->client, msg); - else - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); - } - } -} - -static int myAbs(int n) -{ - return ( n > 0 ? n : -n ); -} - - -static int getSppedShot(shot_t *shot) -{ - return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); -} - -static void transformShot(shot_t *shot, int position) -{ - int speed; - - speed = getSppedShot(shot); - switch (position) { - case TUX_UP : - shot->px = 0; - shot->py = -speed; - break; - case TUX_LEFT : - shot->px = -speed; - shot->py = 0; - break; - case TUX_RIGHT : - shot->px = speed; - shot->py = 0; - break; - case TUX_DOWN : - shot->px = 0; - shot->py = +speed; - break; - } - shot->position = position; - shot->isCanKillAuthor = TRUE; - if( shot->gun == GUN_LASSER ) - export_fce->fce_transformOnlyLasser(shot); -} - -static void move_shot(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h) -{ - int offset = 0; - int new_x = 0, new_y = 0; // no warninng - - //printf("move_shot\n"); - switch (shot->position) { - case TUX_UP : - case TUX_DOWN : - offset = shot->x - src_x; - break; - case TUX_RIGHT : - case TUX_LEFT : - offset = shot->y - src_y; - break; - } - transformShot(shot, position); - switch (shot->position) { - case TUX_UP : - new_x = dist_x + offset; - new_y = dist_y - ( shot->h + 5 ); - break; - case TUX_LEFT : - new_x = dist_x - ( shot->w + 5 ); - new_y = dist_y + offset; - break; - case TUX_RIGHT : - new_x = dist_x + dist_w + 5; - new_y = dist_y + offset; - break; - case TUX_DOWN : - new_x = dist_x + offset; - new_y = dist_y + dist_h + 5; - break; - } - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) { - char msg[STR_PROTO_SIZE]; - - sprintf(msg, "moveshot %d %d %d %d %d %d", - shot->id, shot->x, shot->y, shot->px, shot->py, shot->position); - export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); - } -} - -int init(export_fce_t *p) -{ - export_fce = p; - export_fce->fce_addToShareFce("move_tux", (void *)move_tux); - export_fce->fce_addToShareFce("move_shot", (void *)move_shot); - return 0; -} - -static void proto_movetux(char *msg) -{ - char cmd[STR_PROTO_SIZE]; - int id, x, y; - space_t *space; - tux_t *tux; - - assert( msg != NULL ); - sscanf(msg, "%s %d %d %d", - cmd, &id, &x, &y); - space = export_fce->fce_getCurrentArena()->spaceTux; - tux = getObjectFromSpaceWithID(space, id); - if (tux != NULL) - moveObjectInSpace(space, tux, x, y); -} - -static void proto_moveshot(char *msg) -{ - char cmd[STR_PROTO_SIZE]; - int shot_id, x, y, px, py, position; - space_t *space; - shot_t *shot; - - assert( msg != NULL ); - sscanf(msg, "%s %d %d %d %d %d %d", - cmd, &shot_id, &x, &y, &px, &py, &position); - space = export_fce->fce_getCurrentArena()->spaceShot; - if ((shot = getObjectFromSpaceWithID(space, shot_id)) == NULL) - return; - moveObjectInSpace(space, shot, x, y); - shot->isCanKillAuthor = 1; - shot->position = position; - shot->px = px; - shot->py = py; - if (shot->gun == GUN_LASSER) - export_fce->fce_transformOnlyLasser(shot); -} - -#ifndef PUBLIC_SERVER - -int draw(int x, int y, int w, int h) -{ - return 0; -} - -#endif - -int event() -{ - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - return 0; -} - -void cmdArena(char *line) -{ -} - -void recvMsg(char *msg) -{ - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER) - return; - if (strncmp(msg, "movetux", 7) == 0) - proto_movetux(msg); - if (strncmp(msg, "moveshot", 8) == 0) - proto_moveshot(msg); -} - -int destroy() -{ - return 0; -} diff --git a/src/modules/modPipe.c b/src/modules/modPipe.c index 9099dd6..efe3b7a 100755 --- a/src/modules/modPipe.c +++ b/src/modules/modPipe.c @@ -23,336 +23,313 @@ typedef struct pipe_struct { - int x; // poloha steny - int y; + int x; // poloha steny + int y; - int w; // rozmery steny - int h; + int w; // rozmery steny + int h; - int id; - int id_out; - int position; + int id; + int id_out; + int position; - int layer; // vrstva + int layer; // vrstva -#ifndef PUBLIC_SERVER - image_t *img; //obrazok +#ifndef PUBLIC_SERVER + image_t *img; //obrazok #endif } pipe_t; -static void (*fce_move_shot) (shot_t * shot, int position, int src_x, - int src_y, int dist_x, int dist_y, int dist_w, - int dist_h); +static void (*fce_move_shot)(shot_t *shot, int position, int src_x, int src_y, + int dist_x, int dist_y, int dist_w, int dist_h); static export_fce_t *export_fce; static list_t *listPipe; 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, image_t * img) +#ifndef PUBLIC_SERVER +static pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, image_t *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) + +#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); +{ + 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; + 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; + return new; } -static void -setStatusPipe(void *p, int x, int y, int w, int h) +static void setStatusPipe(void *p, int x, int y, int w, int h) { - pipe_t *pipe; + pipe_t *pipe; - pipe = p; + pipe = p; - pipe->x = x; - pipe->y = y; - pipe->w = w; - pipe->h = h; + 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) +static void getStatusPipe(void *p, int *id, int *x, int *y, int *w, int *h) { - pipe_t *pipe; + pipe_t *pipe; - pipe = p; + pipe = p; - *id = pipe->id; - *x = pipe->x; - *y = pipe->y; - *w = pipe->w; - *h = pipe->h; + *id = pipe->id; + *x = pipe->x; + *y = pipe->y; + *w = pipe->w; + *h = pipe->h; } -#ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER -static void -drawPipe(pipe_t * p) +static void drawPipe(pipe_t *p) { - assert(p != NULL); + assert( p != NULL ); - export_fce->fce_addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, - p->layer); + 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) +static void destroyPipe(pipe_t *p) { - assert(p != NULL); - free(p); + assert( p != NULL ); + free(p); } -static void -cmd_teleport(char *line) +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; + 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)); + 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)); + 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); - } + if( spacePipe == NULL ) + { + spacePipe = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, + 320, 240, getStatusPipe, setStatusPipe); + } - addObjectToSpace(spacePipe, new); + addObjectToSpace(spacePipe, new); } -static void -moveShotFromPipe(shot_t * shot, pipe_t * pipe) +static void moveShotFromPipe(shot_t *shot, pipe_t *pipe) { - pipe_t *distPipe; + pipe_t *distPipe; - distPipe = getObjectFromSpaceWithID(spacePipe, pipe->id_out); + distPipe = getObjectFromSpaceWithID(spacePipe, pipe->id_out); - if (distPipe == NULL) { - fprintf(stderr, "Pipe ID for pipe \"%d\" was not found\n", pipe->id); - return; - } + if( distPipe == NULL ) + { + fprintf(stderr, "Pipe ID for pipe \"%d\" was not found\n", pipe->id); + return; + } - fce_move_shot(shot, distPipe->position, pipe->x, pipe->y, - distPipe->x, distPipe->y, distPipe->w, distPipe->h); + fce_move_shot(shot, distPipe->position, pipe->x, pipe->y, + distPipe->x, distPipe->y, distPipe->w, distPipe->h); } -int -init(export_fce_t * p) +int init(export_fce_t *p) { - export_fce = p; + export_fce = p; - listPipe = newList(); + listPipe = newList(); - if (export_fce->fce_loadDepModule("libmodMove") != 0) { - return -1; - } + if( export_fce->fce_loadDepModule("libmodMove") != 0 ) + { + return -1; + } - if ((fce_move_shot = export_fce->fce_getShareFce("move_shot")) == NULL) { - return -1; - } + if( ( fce_move_shot = export_fce->fce_getShareFce("move_shot") ) == NULL ) + { + return -1; + } - return 0; + return 0; } #ifndef PUBLIC_SERVER -static void -action_drawpipe(space_t * space, pipe_t * pipe, void *p) +static void action_drawpipe(space_t *space, pipe_t *pipe, void *p) { - drawPipe(pipe); + drawPipe(pipe); } -int -draw(int x, int y, int w, int h) +int draw(int x, int y, int w, int h) { - if (spacePipe == NULL) { - return 0; - } + if( spacePipe == NULL ) + { + return 0; + } - actionSpaceFromLocation(spacePipe, action_drawpipe, NULL, x, y, w, h); - //printSpace(spacePipe); + actionSpaceFromLocation(spacePipe, action_drawpipe, NULL, x, y, w, h); + //printSpace(spacePipe); - return 0; + return 0; } #endif -static int -negPosition(int n) +static int negPosition(int n) { - switch (n) { - case TUX_UP: - return TUX_DOWN; + switch( n ) + { + case TUX_UP : + return TUX_DOWN; - case TUX_LEFT: - return TUX_RIGHT; + case TUX_LEFT : + return TUX_RIGHT; - case TUX_RIGHT: - return TUX_LEFT; + case TUX_RIGHT : + return TUX_LEFT; - case TUX_DOWN: - return TUX_UP; + case TUX_DOWN : + return TUX_UP; - default: - assert(!"Tux is moving in another dimension maybe!"); - break; - } + default : + assert( ! "Tux is moving in another dimension maybe!" ); + break; + } - return -1; // no warnning + return -1; // no warnning } -static void -action_eventpipe(space_t * space, pipe_t * pipe, shot_t * shot) +static void action_eventpipe(space_t *space, pipe_t *pipe, shot_t *shot) { - arena_t *arena; - tux_t *author; - - arena = export_fce->fce_getCurrentArena(); - - author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); - - if (author != NULL && - author->bonus == BONUS_GHOST && author->bonus_time > 0) { - return; - } - - if (negPosition(shot->position) == pipe->position && - export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - moveShotFromPipe(shot, pipe); - } - else { - if (shot->gun == GUN_BOMBBALL && - export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - export_fce->fce_boundBombBall(shot); - } - else { - //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); - shot->del = TRUE; - } - } + arena_t *arena; + tux_t *author; + + arena = export_fce->fce_getCurrentArena(); + + author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); + + if( author != NULL && + author->bonus == BONUS_GHOST && + author->bonus_time > 0 ) + { + return; + } + + if( negPosition( shot->position ) == pipe->position && + export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + moveShotFromPipe(shot, pipe); + } + else + { + if( shot->gun == GUN_BOMBBALL && + export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + export_fce->fce_boundBombBall(shot); + } + else + { + //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); + shot->del = TRUE; + } + } } -static void -action_eventshot(space_t * space, shot_t * shot, space_t * spacePipe) +static void action_eventshot(space_t *space, shot_t *shot, space_t *spacePipe) { - actionSpaceFromLocation(spacePipe, action_eventpipe, shot, shot->x, - shot->y, shot->w, shot->h); + actionSpaceFromLocation(spacePipe, action_eventpipe, shot, shot->x, shot->y, shot->w, shot->h); - if (shot->del == TRUE) { - delObjectFromSpaceWithObject(space, shot, export_fce->fce_destroyShot); - } + if( shot->del == TRUE ) + { + delObjectFromSpaceWithObject(space, shot, export_fce->fce_destroyShot); + } } -int -event() +int event() { - if (spacePipe == NULL) { - return 0; - } + if( spacePipe == NULL ) + { + return 0; + } - actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, - spacePipe); + actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, spacePipe); - return 0; + return 0; } -int -isConflict(int x, int y, int w, int h) +int isConflict(int x, int y, int w, int h) { - if (spacePipe == NULL) { - return 0; - } + if( spacePipe == NULL ) + { + return 0; + } - return isConflictWithObjectFromSpace(spacePipe, x, y, w, h); + return isConflictWithObjectFromSpace(spacePipe, x, y, w, h); } -void -cmdArena(char *line) +void cmdArena(char *line) { - if (strncmp(line, "pipe", 4) == 0) - cmd_teleport(line); + if( strncmp(line, "pipe", 4) == 0 )cmd_teleport(line); } -void -recvMsg(char *msg) +void recvMsg(char *msg) { } -int -destroy() +int destroy() { - destroySpaceWithObject(spacePipe, destroyPipe); - destroyList(listPipe); + destroySpaceWithObject(spacePipe, destroyPipe); + destroyList(listPipe); - return 0; + return 0; } diff --git a/src/modules/modPipe.c~ b/src/modules/modPipe.c~ deleted file mode 100644 index efe3b7a..0000000 --- a/src/modules/modPipe.c~ +++ /dev/null @@ -1,335 +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 - image_t *img; //obrazok -#endif -} pipe_t; - -static void (*fce_move_shot)(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h); - -static export_fce_t *export_fce; - -static list_t *listPipe; -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, image_t *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 void moveShotFromPipe(shot_t *shot, pipe_t *pipe) -{ - pipe_t *distPipe; - - distPipe = getObjectFromSpaceWithID(spacePipe, pipe->id_out); - - if( distPipe == NULL ) - { - fprintf(stderr, "Pipe ID for pipe \"%d\" was not found\n", pipe->id); - return; - } - - fce_move_shot(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(); - - if( export_fce->fce_loadDepModule("libmodMove") != 0 ) - { - return -1; - } - - if( ( fce_move_shot = export_fce->fce_getShareFce("move_shot") ) == NULL ) - { - return -1; - } - - return 0; -} - -#ifndef PUBLIC_SERVER - -static void action_drawpipe(space_t *space, pipe_t *pipe, void *p) -{ - drawPipe(pipe); -} - -int draw(int x, int y, int w, int h) -{ - if( spacePipe == NULL ) - { - return 0; - } - - actionSpaceFromLocation(spacePipe, action_drawpipe, NULL, x, y, w, h); - //printSpace(spacePipe); - - 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( ! "Tux is moving in another dimension maybe!" ); - break; - } - - return -1; // no warnning -} - -static void action_eventpipe(space_t *space, pipe_t *pipe, shot_t *shot) -{ - arena_t *arena; - tux_t *author; - - arena = export_fce->fce_getCurrentArena(); - - author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); - - if( author != NULL && - author->bonus == BONUS_GHOST && - author->bonus_time > 0 ) - { - return; - } - - if( negPosition( shot->position ) == pipe->position && - export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - moveShotFromPipe(shot, pipe); - } - else - { - if( shot->gun == GUN_BOMBBALL && - export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - export_fce->fce_boundBombBall(shot); - } - else - { - //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); - shot->del = TRUE; - } - } -} - -static void action_eventshot(space_t *space, shot_t *shot, space_t *spacePipe) -{ - actionSpaceFromLocation(spacePipe, action_eventpipe, shot, shot->x, shot->y, shot->w, shot->h); - - if( shot->del == TRUE ) - { - delObjectFromSpaceWithObject(space, shot, export_fce->fce_destroyShot); - } -} - -int event() -{ - if( spacePipe == NULL ) - { - return 0; - } - - actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, spacePipe); - - 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 cmdArena(char *line) -{ - if( strncmp(line, "pipe", 4) == 0 )cmd_teleport(line); -} - -void recvMsg(char *msg) -{ - -} - -int destroy() -{ - destroySpaceWithObject(spacePipe, destroyPipe); - destroyList(listPipe); - - return 0; -} diff --git a/src/modules/modTeleport.c b/src/modules/modTeleport.c index ff014ae..dfd983a 100755 --- a/src/modules/modTeleport.c +++ b/src/modules/modTeleport.c @@ -23,18 +23,18 @@ typedef struct teleport_struct { - int id; + int id; - int x; // poloha steny - int y; + int x; // poloha steny + int y; - int w; // rozmery steny - int h; + int w; // rozmery steny + int h; - int layer; // vrstva + int layer; // vrstva -#ifndef PUBLIC_SERVER - image_t *img; //obrazok +#ifndef PUBLIC_SERVER + image_t *img; //obrazok #endif } teleport_t; @@ -43,331 +43,302 @@ static export_fce_t *export_fce; static space_t *spaceTeleport; static list_t *listTeleport; -static void (*fce_move_tux) (tux_t * tux, int x, int y, int w, int h); -static void (*fce_move_shot) (shot_t * shot, int position, int src_x, - int src_y, int dist_x, int dist_y, int dist_w, - int dist_h); +static void (*fce_move_tux)(tux_t *tux, int x, int y, int w, int h); +static void (*fce_move_shot)(shot_t *shot, int position, int src_x, int src_y, + int dist_x, int dist_y, int dist_w, int dist_h); -#ifndef PUBLIC_SERVER -teleport_t * -newTeleport(int x, int y, int w, int h, int layer, image_t * img) +#ifndef PUBLIC_SERVER +teleport_t* newTeleport(int x, int y, int w, int h, int layer, image_t *img) #endif -#ifdef PUBLIC_SERVER - teleport_t *newTeleport(int x, int y, int w, int h, int layer) + +#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; + static int last_id = 0; -#ifndef PUBLIC_SERVER - assert(img != NULL); + 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; + 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; + return new; } -static void -setStatusTeleport(void *p, int x, int y, int w, int h) +static void setStatusTeleport(void *p, int x, int y, int w, int h) { - teleport_t *teleport; + teleport_t *teleport; - teleport = p; + teleport = p; - teleport->x = x; - teleport->y = y; - teleport->w = w; - teleport->h = h; + 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) +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; + 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) +static void drawTeleport(teleport_t *p) { - assert(p != NULL); + assert( p != NULL ); - export_fce->fce_addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, - p->layer); + 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) +static void destroyTeleport(teleport_t *p) { - assert(p != NULL); - free(p); + assert( p != NULL ); + free(p); } -static void -cmd_teleport(char *line) +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; + 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)); + 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)); + 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); - } + if( spaceTeleport == NULL ) + { + spaceTeleport = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, + 320, 240, getStatusTeleport, setStatusTeleport); + } - addObjectToSpace(spaceTeleport, new); + addObjectToSpace(spaceTeleport, new); } -static teleport_t * -getRandomTeleportBut(space_t * space, teleport_t * teleport) +static teleport_t* getRandomTeleportBut(space_t *space, teleport_t *teleport) { - int index; + int index; - do { - index = random() % getSpaceCount(space); - } while (getItemFromSpace(space, index) == teleport); + do{ + index = random() % getSpaceCount(space); + }while( getItemFromSpace(space, index) == teleport ); - return (teleport_t *) getItemFromSpace(space, index); + return (teleport_t *) getItemFromSpace(space, index); } -static int -getRandomPosition() +static int getRandomPosition() { - switch (random() % 4) { - case 0: - return TUX_UP; + switch( random() % 4 ) + { + case 0 : + return TUX_UP; - case 1: - return TUX_LEFT; + case 1 : + return TUX_LEFT; - case 2: - return TUX_RIGHT; + case 2 : + return TUX_RIGHT; - case 3: - return TUX_DOWN; - } + case 3 : + return TUX_DOWN; + } - assert - (!"When generating random value in range 0 to 3 i got some other value?!"); + assert( ! "When generating random value in range 0 to 3 i got some other value?!" ); - return -1; // no warnning + return -1; // no warnning } -static void -teleportTux(tux_t * tux, teleport_t * teleport) +static void teleportTux(tux_t *tux, teleport_t *teleport) { - teleport_t *distTeleport; + teleport_t *distTeleport; - if (tux->bonus == BONUS_GHOST || - export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT) { - return; - } + if( tux->bonus == BONUS_GHOST || + export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return; + } - distTeleport = getRandomTeleportBut(spaceTeleport, teleport); + distTeleport = getRandomTeleportBut(spaceTeleport, teleport); - fce_move_tux(tux, distTeleport->x, distTeleport->y, distTeleport->w, - distTeleport->h); + fce_move_tux(tux, distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); } -static void -moveShotFromTeleport(shot_t * shot, teleport_t * teleport, space_t * space) +static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, space_t *space) { - teleport_t *distTeleport; + teleport_t *distTeleport; - distTeleport = getRandomTeleportBut(space, teleport); + distTeleport = getRandomTeleportBut(space, teleport); - fce_move_shot(shot, getRandomPosition(), teleport->x, teleport->y, - distTeleport->x, distTeleport->y, distTeleport->w, - distTeleport->h); + fce_move_shot(shot, getRandomPosition(), teleport->x, teleport->y, + distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); } -int -init(export_fce_t * p) +int init(export_fce_t *p) { - export_fce = p; + export_fce = p; - listTeleport = newList(); + listTeleport = newList(); - if (export_fce->fce_loadDepModule("libmodMove") != 0) { - return -1; - } + if( export_fce->fce_loadDepModule("libmodMove") != 0 ) + { + return -1; + } - if ((fce_move_tux = export_fce->fce_getShareFce("move_tux")) == NULL) { - return -1; - } + if( ( fce_move_tux = export_fce->fce_getShareFce("move_tux") ) == NULL ) + { + return -1; + } - if ((fce_move_shot = export_fce->fce_getShareFce("move_shot")) == NULL) { - return -1; - } + if( ( fce_move_shot = export_fce->fce_getShareFce("move_shot") ) == NULL ) + { + return -1; + } - return 0; + return 0; } #ifndef PUBLIC_SERVER -static void -action_drawteleport(space_t * space, teleport_t * teleport, void *p) +static void action_drawteleport(space_t *space, teleport_t *teleport, void *p) { - drawTeleport(teleport); + drawTeleport(teleport); } -int -draw(int x, int y, int w, int h) +int draw(int x, int y, int w, int h) { - if (spaceTeleport == NULL) { - return 0; - } + if( spaceTeleport == NULL ) + { + return 0; + } - actionSpaceFromLocation(spaceTeleport, action_drawteleport, NULL, x, y, w, - h); + actionSpaceFromLocation(spaceTeleport, action_drawteleport, NULL, x, y, w, h); - return 0; + return 0; } #endif -static void -action_eventteleportshot(space_t * space, teleport_t * teleport, - shot_t * shot) +static void action_eventteleportshot(space_t *space, teleport_t *teleport, shot_t *shot) { - arena_t *arena; - tux_t *author; - - arena = export_fce->fce_getCurrentArena(); + arena_t *arena; + tux_t *author; - author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); + arena = export_fce->fce_getCurrentArena(); - if (author != NULL && - author->bonus == BONUS_GHOST && author->bonus_time > 0) { - return; - } + author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); + + if( author != NULL && + author->bonus == BONUS_GHOST && + author->bonus_time > 0 ) + { + return; + } - moveShotFromTeleport(shot, teleport, spaceTeleport); + moveShotFromTeleport(shot, teleport, spaceTeleport); } -static void -action_eventshot(space_t * space, shot_t * shot, space_t * spaceTeleport) +static void action_eventshot(space_t *space, shot_t *shot, space_t *spaceTeleport) { - actionSpaceFromLocation(spaceTeleport, action_eventteleportshot, shot, - shot->x, shot->y, shot->w, shot->h); + actionSpaceFromLocation(spaceTeleport, action_eventteleportshot, shot, shot->x, shot->y, shot->w, shot->h); } -static void -action_eventteleporttux(space_t * space, teleport_t * teleport, tux_t * tux) +static void action_eventteleporttux(space_t *space, teleport_t *teleport, tux_t *tux) { - teleportTux(tux, teleport); + teleportTux(tux, teleport); } -static void -action_eventtux(space_t * space, tux_t * tux, space_t * spaceTeleport) +static void action_eventtux(space_t *space, tux_t *tux, space_t *spaceTeleport) { - int x, y, w, h; + int x, y, w, h; - export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); + export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); - actionSpaceFromLocation(spaceTeleport, action_eventteleporttux, tux, x, y, - w, h); + actionSpaceFromLocation(spaceTeleport, action_eventteleporttux, tux, x, y, w, h); } -int -event() +int event() { - if (spaceTeleport == NULL) { - return 0; - } + if( spaceTeleport == NULL ) + { + return 0; + } - if (export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT) { - return 0; - } + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return 0; + } - actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, - spaceTeleport); - actionSpace(export_fce->fce_getCurrentArena()->spaceTux, action_eventtux, - spaceTeleport); + actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, spaceTeleport); + actionSpace(export_fce->fce_getCurrentArena()->spaceTux, action_eventtux, spaceTeleport); - return 0; + return 0; } -int -isConflict(int x, int y, int w, int h) +int isConflict(int x, int y, int w, int h) { - if (spaceTeleport == NULL) { - return 0; - } + if( spaceTeleport == NULL ) + { + return 0; + } - return 0; + return 0; } -void -cmdArena(char *line) +void cmdArena(char *line) { - if (strncmp(line, "teleport", 8) == 0) - cmd_teleport(line); + if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(line); } -void -recvMsg(char *msg) +void recvMsg(char *msg) { } -int -destroy() +int destroy() { - destroySpaceWithObject(spaceTeleport, destroyTeleport); - destroyList(listTeleport); - return 0; + destroySpaceWithObject(spaceTeleport, destroyTeleport); + destroyList(listTeleport); + return 0; } diff --git a/src/modules/modTeleport.c~ b/src/modules/modTeleport.c~ deleted file mode 100644 index dfd983a..0000000 --- a/src/modules/modTeleport.c~ +++ /dev/null @@ -1,344 +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 - image_t *img; //obrazok -#endif -} teleport_t; - -static export_fce_t *export_fce; - -static space_t *spaceTeleport; -static list_t *listTeleport; - -static void (*fce_move_tux)(tux_t *tux, int x, int y, int w, int h); -static void (*fce_move_shot)(shot_t *shot, int position, int src_x, int src_y, - int dist_x, int dist_y, int dist_w, int dist_h); - -#ifndef PUBLIC_SERVER -teleport_t* newTeleport(int x, int y, int w, int h, int layer, image_t *img) -#endif - -#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(space_t *space, teleport_t *teleport) -{ - int index; - - do{ - index = random() % getSpaceCount(space); - }while( getItemFromSpace(space, index) == teleport ); - - return (teleport_t *) getItemFromSpace(space, index); -} - -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( ! "When generating random value in range 0 to 3 i got some other value?!" ); - - return -1; // no warnning -} - -static void teleportTux(tux_t *tux, teleport_t *teleport) -{ - teleport_t *distTeleport; - - if( tux->bonus == BONUS_GHOST || - export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return; - } - - distTeleport = getRandomTeleportBut(spaceTeleport, teleport); - - fce_move_tux(tux, distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); -} - -static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, space_t *space) -{ - teleport_t *distTeleport; - - distTeleport = getRandomTeleportBut(space, teleport); - - fce_move_shot(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(); - - if( export_fce->fce_loadDepModule("libmodMove") != 0 ) - { - return -1; - } - - if( ( fce_move_tux = export_fce->fce_getShareFce("move_tux") ) == NULL ) - { - return -1; - } - - if( ( fce_move_shot = export_fce->fce_getShareFce("move_shot") ) == NULL ) - { - return -1; - } - - return 0; -} - -#ifndef PUBLIC_SERVER - -static void action_drawteleport(space_t *space, teleport_t *teleport, void *p) -{ - drawTeleport(teleport); -} - -int draw(int x, int y, int w, int h) -{ - if( spaceTeleport == NULL ) - { - return 0; - } - - actionSpaceFromLocation(spaceTeleport, action_drawteleport, NULL, x, y, w, h); - - return 0; -} -#endif - -static void action_eventteleportshot(space_t *space, teleport_t *teleport, shot_t *shot) -{ - arena_t *arena; - tux_t *author; - - arena = export_fce->fce_getCurrentArena(); - - author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); - - if( author != NULL && - author->bonus == BONUS_GHOST && - author->bonus_time > 0 ) - { - return; - } - - moveShotFromTeleport(shot, teleport, spaceTeleport); -} - -static void action_eventshot(space_t *space, shot_t *shot, space_t *spaceTeleport) -{ - actionSpaceFromLocation(spaceTeleport, action_eventteleportshot, shot, shot->x, shot->y, shot->w, shot->h); -} - -static void action_eventteleporttux(space_t *space, teleport_t *teleport, tux_t *tux) -{ - teleportTux(tux, teleport); -} - -static void action_eventtux(space_t *space, tux_t *tux, space_t *spaceTeleport) -{ - int x, y, w, h; - - export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); - - actionSpaceFromLocation(spaceTeleport, action_eventteleporttux, tux, x, y, w, h); -} - -int event() -{ - if( spaceTeleport == NULL ) - { - return 0; - } - - if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return 0; - } - - actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, spaceTeleport); - actionSpace(export_fce->fce_getCurrentArena()->spaceTux, action_eventtux, spaceTeleport); - - return 0; -} - -int isConflict(int x, int y, int w, int h) -{ - if( spaceTeleport == NULL ) - { - return 0; - } - - return 0; -} - -void cmdArena(char *line) -{ - if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(line); -} - -void recvMsg(char *msg) -{ -} - -int destroy() -{ - destroySpaceWithObject(spaceTeleport, destroyTeleport); - destroyList(listTeleport); - return 0; -} diff --git a/src/modules/modWall.c b/src/modules/modWall.c index 05f3cef..e1d3083 100755 --- a/src/modules/modWall.c +++ b/src/modules/modWall.c @@ -23,21 +23,21 @@ typedef struct wall_struct { - int id; + int id; - int x; // poloha steny - int y; + int x; // poloha steny + int y; - int w; // rozmery steny - int h; + int w; // rozmery steny + int h; - int img_x; // poloha obrazka - int img_y; + int img_x; // poloha obrazka + int img_y; - int layer; // vrstva + int layer; // vrstva -#ifndef PUBLIC_SERVER - image_t *img; //obrazok +#ifndef PUBLIC_SERVER + image_t *img; //obrazok #endif } wall_t; @@ -45,325 +45,299 @@ static export_fce_t *export_fce; static space_t *spaceWall; -#ifndef PUBLIC_SERVER +#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, image_t * img) +#ifndef PUBLIC_SERVER +wall_t* newWall(int x, int y, int w, int h, + int img_x, int img_y, int layer, image_t *img) #endif -#ifdef PUBLIC_SERVER - wall_t *newWall(int x, int y, int w, int h, - int img_x, int img_y, int layer) + +#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); + 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; + 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; + new->img = img; #endif - return new; + return new; } -#ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER -void -drawWall(wall_t * p) +void drawWall(wall_t *p) { - assert(p != NULL); + 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); + 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) +void drawListWall(list_t *list) { - wall_t *thisWall; - int i; + wall_t *thisWall; + int i; - assert(list != NULL); + assert( list != NULL ); - for (i = 0; i < list->count; i++) { - thisWall = (wall_t *) list->list[i]; - assert(thisWall != NULL); - drawWall(thisWall); - } + for( i = 0 ; i < list->count ; i++ ) + { + thisWall = (wall_t *)list->list[i]; + assert( thisWall != NULL ); + drawWall(thisWall); + } } #endif -void -destroyWall(wall_t * p) +void destroyWall(wall_t *p) { - assert(p != NULL); - free(p); + assert( p != NULL ); + free(p); } -static void -getStatusWall(void *p, int *id, int *x, int *y, int *w, int *h) +static void getStatusWall(void *p, int *id, int *x, int *y, int *w, int *h) { - wall_t *wall; + wall_t *wall; - wall = p; + wall = p; - *id = wall->id; - *x = wall->x; - *y = wall->y; - *w = wall->w; - *h = wall->h; + *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) +static void setStatusWall(void *p, int x, int y, int w, int h) { - wall_t *wall; + wall_t *wall; - wall = p; + wall = p; - wall->x = x; - wall->y = y; - wall->w = w; - wall->h = h; + wall->x = x; + wall->y = y; + wall->w = w; + wall->h = h; } -#ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER -static void -getStatusImgWall(void *p, int *id, int *x, int *y, int *w, int *h) +static void getStatusImgWall(void *p, int *id, int *x, int *y, int *w, int *h) { - wall_t *wall; + wall_t *wall; - wall = p; + wall = p; - *id = wall->id; - *x = wall->img_x; - *y = wall->img_y; - *w = wall->img->w; - *h = wall->img->h; + *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) +static void setStatusImgWall(void *p, int x, int y, int w, int h) { } #endif -static void -cmd_wall(char *line) +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]; - char str_rel[STR_SIZE]; - int x, y, w, h, img_x, img_y, layer; - int rel; - wall_t *new; - - rel = 0; - - if (export_fce->fce_getValue(line, "rel", str_rel, STR_NUM_SIZE) != 0) - strcpy(str_rel, "0"); - 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; - - rel = atoi(str_rel); - x = atoi(str_x); - y = atoi(str_y); - w = atoi(str_w); - h = atoi(str_h); - img_x = atoi(str_img_x); - img_y = atoi(str_img_y); - layer = atoi(str_layer); - - if (rel == 1) { - img_x += x; - img_y += y; - } + 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]; + char str_rel[STR_SIZE]; + int x, y, w, h, img_x, img_y, layer; + int rel; + wall_t *new; + + rel = 0; + + if( export_fce->fce_getValue(line, "rel", str_rel, STR_NUM_SIZE) != 0 )strcpy(str_rel, "0"); + 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; + + rel = atoi(str_rel); + x = atoi(str_x); + y = atoi(str_y); + w = atoi(str_w); + h = atoi(str_h); + img_x = atoi(str_img_x); + img_y = atoi(str_img_y); + layer = atoi(str_layer); + + if( rel == 1 ) + { + img_x += x; + img_y += y; + } #ifndef PUBLIC_SERVER - new = - newWall(x, y, w, h, img_x, img_y, layer, - export_fce->fce_getImage(IMAGE_GROUP_USER, str_image)); + new = newWall(x, y, w, h, img_x, img_y, layer, export_fce->fce_getImage(IMAGE_GROUP_USER, str_image) ); #endif #ifdef PUBLIC_SERVER - new = newWall(x, y, w, h, img_x, img_y, layer); + new = newWall(x, y, w, h, img_x, img_y, layer); #endif - if (spaceWall == NULL) { - spaceWall = - newSpace(export_fce->fce_getCurrentArena()->w, - export_fce->fce_getCurrentArena()->h, 320, 240, - getStatusWall, setStatusWall); + 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); +#ifndef PUBLIC_SERVER + spaceImgWall = newSpace(export_fce->fce_getCurrentArena()->w, export_fce->fce_getCurrentArena()->h, + 320, 240, getStatusImgWall, setStatusImgWall); #endif - } + } - addObjectToSpace(spaceWall, new); + addObjectToSpace(spaceWall, new); -#ifndef PUBLIC_SERVER - addObjectToSpace(spaceImgWall, new); +#ifndef PUBLIC_SERVER + addObjectToSpace(spaceImgWall, new); #endif } -int -init(export_fce_t * p) +int init(export_fce_t *p) { - export_fce = p; - listWall = newList(); + export_fce = p; + listWall = newList(); - return 0; + return 0; } #ifndef PUBLIC_SERVER -static void -action_drawwall(space_t * space, wall_t * wall, void *p) +static void action_drawwall(space_t *space, wall_t *wall, void *p) { - drawWall(wall); + drawWall(wall); } -int -draw(int x, int y, int w, int h) +int draw(int x, int y, int w, int h) { - if (spaceWall == NULL) { - return 0; - } + if( spaceWall == NULL ) + { + return 0; + } - actionSpaceFromLocation(spaceImgWall, action_drawwall, NULL, x, y, w, h); + actionSpaceFromLocation(spaceImgWall, action_drawwall, NULL, x, y, w, h); - //printSpace(spaceWall); + //printSpace(spaceWall); - return 0; + return 0; } #endif -static void -action_eventwall(space_t * space, wall_t * wall, shot_t * shot) +static void action_eventwall(space_t *space, wall_t *wall, shot_t *shot) { - arena_t *arena; - tux_t *author; + arena_t *arena; + tux_t *author; - arena = export_fce->fce_getCurrentArena(); + arena = export_fce->fce_getCurrentArena(); - author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id); + author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id ); - if (author != NULL && - author->bonus == BONUS_GHOST && author->bonus_time > 0) { - return; - } + if( author != NULL && + author->bonus == BONUS_GHOST && + author->bonus_time > 0 ) + { + return; + } - if (shot->gun == GUN_BOMBBALL) { - if (export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - export_fce->fce_boundBombBall(shot); - } + if( shot->gun == GUN_BOMBBALL) + { + if( export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + export_fce->fce_boundBombBall(shot); + } - return; - } + return; + } - //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); - shot->del = TRUE; + //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); + shot->del = TRUE; } -static void -action_eventshot(space_t * space, shot_t * shot, space_t * spaceWall) +static void action_eventshot(space_t *space, shot_t *shot, space_t *spaceWall) { - actionSpaceFromLocation(spaceWall, action_eventwall, shot, shot->x, - shot->y, shot->w, shot->h); + actionSpaceFromLocation(spaceWall, action_eventwall, shot, shot->x, shot->y, shot->w, shot->h); - if (shot->del == TRUE) { - delObjectFromSpaceWithObject(space, shot, export_fce->fce_destroyShot); - } + if( shot->del == TRUE ) + { + delObjectFromSpaceWithObject(space, shot, export_fce->fce_destroyShot); + } } -int -event() +int event() { - if (spaceWall == NULL) { - return 0; - } + if( spaceWall == NULL ) + { + return 0; + } - actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, - spaceWall); + actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, spaceWall); - return 0; + return 0; } -int -isConflict(int x, int y, int w, int h) +int isConflict(int x, int y, int w, int h) { - if (spaceWall == NULL) { - return 0; - } + if( spaceWall == NULL ) + { + return 0; + } - return isConflictWithObjectFromSpace(spaceWall, x, y, w, h); + return isConflictWithObjectFromSpace(spaceWall, x, y, w, h); } -void -cmdArena(char *line) +void cmdArena(char *line) { - if (strncmp(line, "wall", 4) == 0) - cmd_wall(line); + if( strncmp(line, "wall", 4) == 0 )cmd_wall(line); } -void -recvMsg(char *msg) +void recvMsg(char *msg) { } -int -destroy() +int destroy() { - destroySpaceWithObject(spaceWall, destroyWall); -#ifndef PUBLIC_SERVER - destroySpace(spaceImgWall); + destroySpaceWithObject(spaceWall, destroyWall); +#ifndef PUBLIC_SERVER + destroySpace(spaceImgWall); #endif - destroyList(listWall); - return 0; + destroyList(listWall); + return 0; } diff --git a/src/modules/modWall.c~ b/src/modules/modWall.c~ deleted file mode 100644 index e1d3083..0000000 --- a/src/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 - image_t *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, image_t *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 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]; - char str_rel[STR_SIZE]; - int x, y, w, h, img_x, img_y, layer; - int rel; - wall_t *new; - - rel = 0; - - if( export_fce->fce_getValue(line, "rel", str_rel, STR_NUM_SIZE) != 0 )strcpy(str_rel, "0"); - 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; - - rel = atoi(str_rel); - x = atoi(str_x); - y = atoi(str_y); - w = atoi(str_w); - h = atoi(str_h); - img_x = atoi(str_img_x); - img_y = atoi(str_img_y); - layer = atoi(str_layer); - - if( rel == 1 ) - { - img_x += x; - img_y += y; - } - -#ifndef PUBLIC_SERVER - new = newWall(x, y, w, h, img_x, img_y, layer, export_fce->fce_getImage(IMAGE_GROUP_USER, str_image) ); -#endif - -#ifdef PUBLIC_SERVER - new = newWall(x, y, w, h, img_x, img_y, 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 - -static void action_drawwall(space_t *space, wall_t *wall, void *p) -{ - drawWall(wall); -} - -int draw(int x, int y, int w, int h) -{ - if( spaceWall == NULL ) - { - return 0; - } - - actionSpaceFromLocation(spaceImgWall, action_drawwall, NULL, x, y, w, h); - - //printSpace(spaceWall); - - return 0; -} -#endif - -static void action_eventwall(space_t *space, wall_t *wall, shot_t *shot) -{ - arena_t *arena; - tux_t *author; - - arena = export_fce->fce_getCurrentArena(); - - author = getObjectFromSpaceWithID(arena->spaceTux, shot->author_id ); - - if( author != NULL && - author->bonus == BONUS_GHOST && - author->bonus_time > 0 ) - { - return; - } - - if( shot->gun == GUN_BOMBBALL) - { - if( export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - export_fce->fce_boundBombBall(shot); - } - - return; - } - - //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); - shot->del = TRUE; -} - -static void action_eventshot(space_t *space, shot_t *shot, space_t *spaceWall) -{ - actionSpaceFromLocation(spaceWall, action_eventwall, shot, shot->x, shot->y, shot->w, shot->h); - - if( shot->del == TRUE ) - { - delObjectFromSpaceWithObject(space, shot, export_fce->fce_destroyShot); - } -} - -int event() -{ - if( spaceWall == NULL ) - { - return 0; - } - - actionSpace(export_fce->fce_getCurrentArena()->spaceShot, action_eventshot, spaceWall); - - 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 cmdArena(char *line) -{ - if( strncmp(line, "wall", 4) == 0 )cmd_wall(line); -} - -void recvMsg(char *msg) -{ -} - -int destroy() -{ - destroySpaceWithObject(spaceWall, destroyWall); -#ifndef PUBLIC_SERVER - destroySpace(spaceImgWall); -#endif - destroyList(listWall); - return 0; -} -- cgit v1.2.3