diff options
| author | xHire <xhire@tuxportal.cz> | 2008-10-25 14:11:06 +0200 |
|---|---|---|
| committer | xHire <xhire@tuxportal.cz> | 2008-10-25 14:11:06 +0200 |
| commit | c8a9209d77a896bf49227e5aeccd54e91ccf29cc (patch) | |
| tree | 6b7367406ebbc6ce3ea5e0c8668c75f6fb3f6ae9 | |
| parent | cb9deba915dd7b114eeb76601eb1c8b07c1ba90f (diff) | |
Changed style of the code to the K&R standard
163 files changed, 12958 insertions, 14034 deletions
diff --git a/src/audio/audio.c b/src/audio/audio.c index 15ad6f7..0d9b0a2 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -11,50 +11,46 @@ static bool_t isAudioInit = FALSE; /* * Returns state of audio */ -bool_t -isAudioInicialized() +bool_t isAudioInicialized() { - return isAudioInit; + return isAudioInit; } /* * Inicialize audio */ -void -initAudio() +void initAudio() { - if (isParamFlag("--noaudio")) { - return; - } + if (isParamFlag("--noaudio")) { + return; + } - if (SDL_Init(SDL_INIT_AUDIO) == -1) { - fprintf(stderr, _("Unable to initialize audio: %s\n"), - SDL_GetError()); - return; - } - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == - -1) { - fprintf(stderr, _("Unable to create proper audio settings: %s\n"), - Mix_GetError()); - return; - } - Mix_AllocateChannels(16); - Mix_Volume(-1, MIX_MAX_VOLUME); + if (SDL_Init(SDL_INIT_AUDIO) == -1) { + fprintf(stderr, _("Unable to initialize audio: %s\n"), SDL_GetError()); + return; + } + if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == + -1) { + fprintf(stderr, _("Unable to create proper audio settings: %s\n"), + Mix_GetError()); + return; + } + Mix_AllocateChannels(16); + Mix_Volume(-1, MIX_MAX_VOLUME); #ifdef DEBUG - printf(_("Initializing audio system...\n")); + printf(_("Initializing audio system...\n")); #endif - isAudioInit = TRUE; + isAudioInit = TRUE; } /* * Quit audio */ -void -quitAudio() +void quitAudio() { - Mix_CloseAudio(); - isAudioInit = TRUE; + Mix_CloseAudio(); + isAudioInit = TRUE; #ifdef DEBUG - printf(_("Quitting audio...\n")); + printf(_("Quitting audio...\n")); #endif } diff --git a/src/audio/audio.h b/src/audio/audio.h index 61873c3..1f1f95b 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -1,8 +1,8 @@ #ifndef AUDIO_H -#define AUDIO_H +# define AUDIO_H -#include "main.h" +# include "main.h" extern bool_t isAudioInicialized(); extern void initAudio(); diff --git a/src/audio/music.c b/src/audio/music.c index 58be368..04de359 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -18,224 +18,210 @@ static Mix_Music *currentMusic; /* * Return state of music initialization */ -bool_t -isMusicInicialized() +bool_t isMusicInicialized() { - return isMusicInit; + return isMusicInit; } /* * Initialize music */ -void -initMusic() +void initMusic() { - if (isAudioInicialized() == FALSE) { - isMusicInit = FALSE; - return; - } - listStorage = newStorage(); - currentMusic = NULL; - isMusicInit = TRUE; - var_isMusicActive = TRUE; - if (isParamFlag("--nomusic")) - setMusicActive(FALSE); - if (isParamFlag("--music")) - setMusicActive(TRUE); + if (isAudioInicialized() == FALSE) { + isMusicInit = FALSE; + return; + } + listStorage = newStorage(); + currentMusic = NULL; + isMusicInit = TRUE; + var_isMusicActive = TRUE; + if (isParamFlag("--nomusic")) + setMusicActive(FALSE); + if (isParamFlag("--music")) + setMusicActive(TRUE); #ifdef DEBUG - printf(_("Initializing music...\n")); + printf(_("Initializing music...\n")); #endif } /* * Load music file and returns it */ -static Mix_Music * -loadMixMusic(char *file) +static Mix_Music *loadMixMusic(char *file) { - Mix_Music *mixer; - char str[STR_PATH_SIZE]; + Mix_Music *mixer; + char str[STR_PATH_SIZE]; #ifdef DEBUG - printf(_("Loading music file: %s\n"), file); + printf(_("Loading music file: %s\n"), file); #endif - if (isFillPath(file)) { - strcpy(str, file); - } - else { - sprintf(str, PATH_MUSIC "%s", file); - } + if (isFillPath(file)) { + strcpy(str, file); + } else { + sprintf(str, PATH_MUSIC "%s", file); + } - accessExistFile(str); + accessExistFile(str); - mixer = Mix_LoadMUS(str); + mixer = Mix_LoadMUS(str); - if (mixer == NULL) { - fprintf(stderr, _("Unable to load music from file: %s\n"), file); - return NULL; - } + if (mixer == NULL) { + fprintf(stderr, _("Unable to load music from file: %s\n"), file); + return NULL; + } - return mixer; + return mixer; } /* * Prepare music mixer */ -static void -playMixMusic() +static void playMixMusic() { - if (currentMusic != NULL) - Mix_PlayMusic(currentMusic, 1000); + if (currentMusic != NULL) + Mix_PlayMusic(currentMusic, 1000); } /* * Free memory of music */ -static void -destroyMusic(void *p) +static void destroyMusic(void *p) { - Mix_FreeMusic((Mix_Music *) p); + Mix_FreeMusic((Mix_Music *) p); } /* * Add file to list with music */ -void -addMusic(char *file, char *name, char *group) +void addMusic(char *file, char *name, char *group) { - Mix_Music *new; - if (isMusicInit == FALSE) - return; + Mix_Music *new; + if (isMusicInit == FALSE) + return; - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); + assert(file != NULL); + assert(name != NULL); + assert(group != NULL); - new = loadMixMusic(file); - addItemToStorage(listStorage, group, name, new); + new = loadMixMusic(file); + addItemToStorage(listStorage, group, name, new); } /* * Disable music and stop playback */ -void -stopMusic() +void stopMusic() { - if (isMusicInit == FALSE || var_isMusicActive == FALSE) - return; + if (isMusicInit == FALSE || var_isMusicActive == FALSE) + return; - if (currentMusic != NULL) { + if (currentMusic != NULL) { #ifdef DEBUG - printf(_("Stopping music...\n")); + printf(_("Stopping music...\n")); #endif - Mix_HaltMusic(); - currentMusic = NULL; - } + Mix_HaltMusic(); + currentMusic = NULL; + } } /* * start music playback */ -void -playMusic(char *name, char *group) +void playMusic(char *name, char *group) { - static char currentMusic_group[STR_SIZE]; - static char currentMusic_name[STR_SIZE]; - static int isStrInit = 0; + static char currentMusic_group[STR_SIZE]; + static char currentMusic_name[STR_SIZE]; + static int isStrInit = 0; - if (isStrInit == 0) { - strcpy(currentMusic_group, "none"); - strcpy(currentMusic_name, "none"); - isStrInit = 1; - } + if (isStrInit == 0) { + strcpy(currentMusic_group, "none"); + strcpy(currentMusic_name, "none"); + isStrInit = 1; + } - if (isMusicInit == FALSE || var_isMusicActive == FALSE) - return; + if (isMusicInit == FALSE || var_isMusicActive == FALSE) + return; - if (currentMusic != NULL && - strcmp(currentMusic_group, group) == 0 && - strcmp(currentMusic_name, name) == 0) { - return; - } + if (currentMusic != NULL && + strcmp(currentMusic_group, group) == 0 && + strcmp(currentMusic_name, name) == 0) { + return; + } - if (currentMusic != NULL) - stopMusic(); + if (currentMusic != NULL) + stopMusic(); - currentMusic = getItemFromStorage(listStorage, group, name); - strcpy(currentMusic_group, group); - strcpy(currentMusic_name, name); + currentMusic = getItemFromStorage(listStorage, group, name); + strcpy(currentMusic_group, group); + strcpy(currentMusic_name, name); - if (currentMusic != NULL) { + if (currentMusic != NULL) { #ifdef DEBUG - printf(_("Playing music file %s\n"), name); + printf(_("Playing music file %s\n"), name); #endif - playMixMusic(); - } + playMixMusic(); + } } /* * Set music active/deactivated */ -void -setMusicActive(bool_t n) +void setMusicActive(bool_t n) { - static Mix_Music *music = NULL; - - if (n == FALSE) { - music = currentMusic; - stopMusic(); - } - if (n == TRUE) { - currentMusic = music; - playMixMusic(); - } - - var_isMusicActive = n; + static Mix_Music *music = NULL; + + if (n == FALSE) { + music = currentMusic; + stopMusic(); + } + if (n == TRUE) { + currentMusic = music; + playMixMusic(); + } + + var_isMusicActive = n; } /* * Return status of music */ -bool_t -isMusicActive() +bool_t isMusicActive() { - return var_isMusicActive; + return var_isMusicActive; } /* * TOCOMMENT */ -char * -getCurrentMusic() +char *getCurrentMusic() { - return "unknown"; + return "unknown"; } /* * TOCOMMENT */ -void -delAllMusicInGroup(char *group) +void delAllMusicInGroup(char *group) { - if (isMusicInit == FALSE) - return; - delAllItemFromStorage(listStorage, group, destroyMusic); + if (isMusicInit == FALSE) + return; + delAllItemFromStorage(listStorage, group, destroyMusic); } /* * Deactivate all what is ment for music */ -void -quitMusic() +void quitMusic() { - if (isMusicInit == FALSE) - return; + if (isMusicInit == FALSE) + return; - stopMusic(); - destroyStorage(listStorage, destroyMusic); - isMusicInit = FALSE; + stopMusic(); + destroyStorage(listStorage, destroyMusic); + isMusicInit = FALSE; #ifdef DEBUG - printf(_("Quitting music...\n")); + printf(_("Quitting music...\n")); #endif } diff --git a/src/audio/music.h b/src/audio/music.h index 2e6cd3f..1b0e1fb 100644 --- a/src/audio/music.h +++ b/src/audio/music.h @@ -1,21 +1,21 @@ #ifndef MUSIC_H -#define MUSIC_H -#ifndef NO_SOUND -#include <SDL_mixer.h> -#include "main.h" +# define MUSIC_H +# ifndef NO_SOUND +# include <SDL_mixer.h> +# include "main.h" -#define MUSIC_GROUP_BASE "base" -#define MUSIC_GROUP_USER "user" +# define MUSIC_GROUP_BASE "base" +# define MUSIC_GROUP_USER "user" - /* - typedef struct music_struct - { - char *name; - int group; - Mix_Music *music; - } music_t; - */ + /* + typedef struct music_struct + { + char *name; + int group; + Mix_Music *music; + } music_t; + */ extern bool_t isMusicInicialized(); extern void initMusic(); @@ -27,5 +27,5 @@ extern bool_t isMusicActive(); extern char *getCurrentMusic(); extern void delAllMusicInGroup(char *group); extern void quitMusic(); -#endif +# endif #endif diff --git a/src/audio/sound.c b/src/audio/sound.c index 50a5aad..c96e3ac 100644 --- a/src/audio/sound.c +++ b/src/audio/sound.c @@ -16,137 +16,127 @@ static bool_t var_isSoundActive = TRUE; /* * Return state of sound */ -bool_t -isSoundInicialized() +bool_t isSoundInicialized() { - return isSoundInit; + return isSoundInit; } /* * Audio initialization */ -void -initSound() +void initSound() { - if (isAudioInicialized() == FALSE) { - isSoundInit = FALSE; - return; - } + if (isAudioInicialized() == FALSE) { + isSoundInit = FALSE; + return; + } - listStorage = newStorage(); - isSoundInit = TRUE; - var_isSoundActive = TRUE; - if (isParamFlag("--nosound")) - setSoundActive(FALSE); - if (isParamFlag("--sound")) - setSoundActive(TRUE); + listStorage = newStorage(); + isSoundInit = TRUE; + var_isSoundActive = TRUE; + if (isParamFlag("--nosound")) + setSoundActive(FALSE); + if (isParamFlag("--sound")) + setSoundActive(TRUE); #ifdef DEBUG - printf(_("Initializing sound...\n")); + printf(_("Initializing sound...\n")); #endif } /* * Load sound file (Null/mixer) */ -static Mix_Chunk * -loadMixSound(char *file) +static Mix_Chunk *loadMixSound(char *file) { - Mix_Chunk *new; - char str[STR_PATH_SIZE]; + Mix_Chunk *new; + char str[STR_PATH_SIZE]; #ifdef DEBUG - printf(_("Loading sound file: %s\n"), file); + printf(_("Loading sound file: %s\n"), file); #endif - sprintf(str, PATH_SOUND "%s", file); - accessExistFile(str); - new = Mix_LoadWAV(str); - if (new == NULL) { - fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"), - str, Mix_GetError()); - return NULL; - } - return new; + sprintf(str, PATH_SOUND "%s", file); + accessExistFile(str); + new = Mix_LoadWAV(str); + if (new == NULL) { + fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"), + str, Mix_GetError()); + return NULL; + } + return new; } /* * Play sound with mixer */ -static void -playMixSound(Mix_Chunk * p) +static void playMixSound(Mix_Chunk * p) { - if (Mix_PlayChannel(-1, p, 0) == -1) { - fprintf(stderr, _("Unable to playback sound with error: %s\n"), - Mix_GetError()); - return; - } + if (Mix_PlayChannel(-1, p, 0) == -1) { + fprintf(stderr, _("Unable to playback sound with error: %s\n"), + Mix_GetError()); + return; + } } /* * Destroy mixer chunk */ -static void -destroySound(void *p) +static void destroySound(void *p) { - Mix_FreeChunk((Mix_Chunk *) p); + Mix_FreeChunk((Mix_Chunk *) p); } /* * Add sound to list */ -void -addSound(char *file, char *name, char *group) +void addSound(char *file, char *name, char *group) { - Mix_Chunk *new; + Mix_Chunk *new; - if (isSoundInit == FALSE) - return; - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); - new = loadMixSound(file); - addItemToStorage(listStorage, group, name, new); + if (isSoundInit == FALSE) + return; + assert(file != NULL); + assert(name != NULL); + assert(group != NULL); + new = loadMixSound(file); + addItemToStorage(listStorage, group, name, new); } /* * Start playback file from list */ -void -playSound(char *name, char *group) +void playSound(char *name, char *group) { - if (isSoundInit == FALSE || var_isSoundActive == FALSE) - return; - playMixSound(getItemFromStorage(listStorage, group, name)); + if (isSoundInit == FALSE || var_isSoundActive == FALSE) + return; + playMixSound(getItemFromStorage(listStorage, group, name)); } /* * Set if sound is active True/False */ -void -setSoundActive(bool_t n) +void setSoundActive(bool_t n) { - var_isSoundActive = n; + var_isSoundActive = n; } /* * Return state of sound */ -bool_t -isSoundActive() +bool_t isSoundActive() { - return var_isSoundActive; + return var_isSoundActive; } /* * Quit all sound stuff */ -void -quitSound() +void quitSound() { - if (isSoundInit == FALSE) - return; - destroyStorage(listStorage, destroySound); - isSoundInit = FALSE; + if (isSoundInit == FALSE) + return; + destroyStorage(listStorage, destroySound); + isSoundInit = FALSE; #ifdef DEBUG - printf(_("Quitting sound...\n")); + printf(_("Quitting sound...\n")); #endif } diff --git a/src/audio/sound.h b/src/audio/sound.h index cb85471..f63af13 100644 --- a/src/audio/sound.h +++ b/src/audio/sound.h @@ -1,21 +1,21 @@ #ifndef SOUND_H -#define SOUND_H -#ifndef NO_SOUND -#include <SDL_mixer.h> -#include "main.h" +# define SOUND_H +# ifndef NO_SOUND +# include <SDL_mixer.h> +# include "main.h" -#define SOUND_GROUP_BASE "base" -#define SOUND_GROUP_USER "user" +# define SOUND_GROUP_BASE "base" +# define SOUND_GROUP_USER "user" - /* - typedef struct sound_struct - { - char *name; - int group; - Mix_Chunk *sound; - } sound_t; - */ + /* + typedef struct sound_struct + { + char *name; + int group; + Mix_Chunk *sound; + } sound_t; + */ extern bool_t isSoundInicialized(); extern void initSound(); @@ -24,5 +24,5 @@ extern void playSound(char *name, char *group); extern void setSoundActive(bool_t n); extern bool_t isSoundActive(); extern void quitSound(); -#endif +# endif #endif diff --git a/src/base/archive.c b/src/base/archive.c index 7311930..f851a86 100644 --- a/src/base/archive.c +++ b/src/base/archive.c @@ -10,63 +10,60 @@ #define ARCHIVE_BUFFER_SIZE 1024 #define STR_TMP_FILE_NAME 4096 -char * -extractFileFromArchive(char *archive, char *filename) +char *extractFileFromArchive(char *archive, char *filename) { - char buf[ARCHIVE_BUFFER_SIZE]; - char archive_name[STR_TMP_FILE_NAME]; - char name[STR_TMP_FILE_NAME]; + char buf[ARCHIVE_BUFFER_SIZE]; + char archive_name[STR_TMP_FILE_NAME]; + char name[STR_TMP_FILE_NAME]; - ZZIP_FILE *zip_file; - FILE *file; - zzip_ssize_t len; + ZZIP_FILE *zip_file; + FILE *file; + zzip_ssize_t len; - strcpy(archive_name, archive); - sprintf(strrchr(archive_name, '.'), "/%s", filename); + strcpy(archive_name, archive); + sprintf(strrchr(archive_name, '.'), "/%s", filename); - sprintf(name, "/tmp/tuxanci%d-%s", getpid(), filename); + sprintf(name, "/tmp/tuxanci%d-%s", getpid(), filename); - if ((zip_file = zzip_open(archive_name, O_RDONLY)) == NULL) { - fprintf(stderr, "No do not open %s archive\n", archive_name); - return NULL; - } + if ((zip_file = zzip_open(archive_name, O_RDONLY)) == NULL) { + fprintf(stderr, "No do not open %s archive\n", archive_name); + return NULL; + } - if ((file = fopen(name, "wb")) == NULL) { - fprintf(stderr, "No do not create temp file %s\n", name); - return NULL; - } + if ((file = fopen(name, "wb")) == NULL) { + fprintf(stderr, "No do not create temp file %s\n", name); + return NULL; + } - do { - len = zzip_read(zip_file, buf, ARCHIVE_BUFFER_SIZE); - //printf("len = %d\n", len); + do { + len = zzip_read(zip_file, buf, ARCHIVE_BUFFER_SIZE); + //printf("len = %d\n", len); - if (len > 0) { - fwrite(buf, len, 1, file); - } - } while (len > 0); + if (len > 0) { + fwrite(buf, len, 1, file); + } + } while (len > 0); - zzip_close(zip_file); - fclose(file); + zzip_close(zip_file); + fclose(file); - return strdup(name); + return strdup(name); } -void -deleteExtractFile(char *s) +void deleteExtractFile(char *s) { - unlink(s); - free(s); + unlink(s); + free(s); } #if ARCHIVE_TEST -int -main() +int main() { - char *name; + char *name; - name = extractFileFromArchive("hello/a/b/hello"); - printf("name = %s\n", name); - deleteExtractFile(name); - return 0; + name = extractFileFromArchive("hello/a/b/hello"); + printf("name = %s\n", name); + deleteExtractFile(name); + return 0; } #endif diff --git a/src/base/archive.h b/src/base/archive.h index 62e1109..0817418 100644 --- a/src/base/archive.h +++ b/src/base/archive.h @@ -1,7 +1,7 @@ #ifndef ARCHIVE_H -#define ARCHIVE_H +# define ARCHIVE_H extern char *extractFileFromArchive(char *archive, char *file); extern void deleteExtractFile(char *s); diff --git a/src/base/arena.c b/src/base/arena.c index f1310d1..4391af9 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -13,439 +13,410 @@ #include "modules.h" #ifndef PUBLIC_SERVER -#include "hotKey.h" -#include "screen_world.h" -#include "screen_setting.h" -#include "layer.h" +# include "hotKey.h" +# include "screen_world.h" +# include "screen_setting.h" +# include "layer.h" #endif static arena_t *currentArena; static int splitType; #ifndef PUBLIC_SERVER -static int -isBigArena(arena_t * arena) +static int isBigArena(arena_t * arena) { - if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { - return 1; - } - else { - return 0; - } + if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { + return 1; + } else { + return 0; + } } -static int -isTuxNear(tux_t * tux1, tux_t * tux2) +static int isTuxNear(tux_t * tux1, tux_t * tux2) { - if (abs(tux1->x - tux2->x) < WINDOW_SIZE_X && - abs(tux1->y - tux2->y) < WINDOW_SIZE_Y) { - return 1; - } + if (abs(tux1->x - tux2->x) < WINDOW_SIZE_X && + abs(tux1->y - tux2->y) < WINDOW_SIZE_Y) { + return 1; + } - return 0; + return 0; } #endif -void -setCurrentArena(arena_t * p) +void setCurrentArena(arena_t * p) { - currentArena = p; + currentArena = p; } -arena_t * -getCurrentArena() +arena_t *getCurrentArena() { - return currentArena; + return currentArena; } -void -hotkey_splitArena() +void hotkey_splitArena() { - if (splitType == SCREEN_SPLIT_VERTICAL) { - splitType = SCREEN_SPLIT_HORIZONTAL; - } - else { - splitType = SCREEN_SPLIT_VERTICAL; - } + if (splitType == SCREEN_SPLIT_VERTICAL) { + splitType = SCREEN_SPLIT_HORIZONTAL; + } else { + splitType = SCREEN_SPLIT_VERTICAL; + } } #ifndef PUBLIC_SERVER -void -initArena() +void initArena() { - splitType = SCREEN_SPLIT_VERTICAL; + splitType = SCREEN_SPLIT_VERTICAL; - if (getParam("--split-vertical")) { - splitType = SCREEN_SPLIT_VERTICAL; - printf("SCREEN_SPLIT_VERTICAL\n"); - } + if (getParam("--split-vertical")) { + splitType = SCREEN_SPLIT_VERTICAL; + printf("SCREEN_SPLIT_VERTICAL\n"); + } - if (getParam("--split-horizontal")) { - splitType = SCREEN_SPLIT_HORIZONTAL; - printf("SCREEN_SPLIT_HORIZONTAL\n"); - } + if (getParam("--split-horizontal")) { + splitType = SCREEN_SPLIT_HORIZONTAL; + printf("SCREEN_SPLIT_HORIZONTAL\n"); + } - registerHotKey(SDLK_F3, hotkey_splitArena); + registerHotKey(SDLK_F3, hotkey_splitArena); } -void -quitArena() +void quitArena() { - unregisterHotKey(SDLK_F3); + unregisterHotKey(SDLK_F3); } #endif -arena_t * -newArena(int w, int h) +arena_t *newArena(int w, int h) { - arena_t *new; - int zone_w, zone_h; + arena_t *new; + int zone_w, zone_h; - new = malloc(sizeof(arena_t)); + new = malloc(sizeof(arena_t)); #ifndef PUBLIC_SERVER - new->background = NULL; - strcpy(new->music, ""); + new->background = NULL; + strcpy(new->music, ""); #endif - new->w = w; - new->h = h; + new->w = w; + new->h = h; - new->listTimer = newList(); + new->listTimer = newList(); - if (w > 800 || h > 600) { - zone_w = 320; - zone_h = 240; - } - else { - zone_w = 80; - zone_h = 60; - } + if (w > 800 || h > 600) { + zone_w = 320; + zone_h = 240; + } else { + zone_w = 80; + zone_h = 60; + } - new->spaceTux = - newSpace(w, h, zone_w, zone_h, getStatusTux, setStatusTux); - new->spaceItem = - newSpace(w, h, zone_w, zone_h, getStatusItem, setStatusItem); - new->spaceShot = - newSpace(w, h, zone_w, zone_h, getStatusShot, setStatusShot); + new->spaceTux = newSpace(w, h, zone_w, zone_h, getStatusTux, setStatusTux); + new->spaceItem = + newSpace(w, h, zone_w, zone_h, getStatusItem, setStatusItem); + new->spaceShot = + newSpace(w, h, zone_w, zone_h, getStatusShot, setStatusShot); - new->countRound = 0; - new->max_countRound = 0; + new->countRound = 0; + new->max_countRound = 0; - return new; + return new; } int conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { - return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); + return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); } -int -isFreeSpace(arena_t * arena, int x, int y, int w, int h) +int isFreeSpace(arena_t * arena, int x, int y, int w, int h) { - if (x < 0 || y < 0 || x + w > arena->w || y + h > arena->h) { - return 0; - } - - if (isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h)) - return 0; - if (isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h)) - return 0; - if (isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h)) - return 0; - if (isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h)) - return 0; - - if (isConflictModule(x, y, w, h)) - return 0; - - return 1; + if (x < 0 || y < 0 || x + w > arena->w || y + h > arena->h) { + return 0; + } + + if (isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h)) + return 0; + if (isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h)) + return 0; + if (isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h)) + return 0; + if (isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h)) + return 0; + + if (isConflictModule(x, y, w, h)) + return 0; + + return 1; } -void -findFreeSpace(arena_t * arena, int *x, int *y, int w, int h) +void findFreeSpace(arena_t * arena, int *x, int *y, int w, int h) { - int z_x; - int z_y; + int z_x; + int z_y; - assert(x != NULL); - assert(y != NULL); + assert(x != NULL); + assert(y != NULL); - do { - z_x = random() % (arena->w - w); - z_y = random() % (arena->h - h); - } while (isFreeSpace(arena, z_x, z_y, w, h) == 0); + do { + z_x = random() % (arena->w - w); + z_y = random() % (arena->h - h); + } while (isFreeSpace(arena, z_x, z_y, w, h) == 0); - *x = z_x; - *y = z_y; + *x = z_x; + *y = z_y; } void getCenterScreen(int *screen_x, int *screen_y, int x, int y, int screen_size_x, - int screen_size_y) + int screen_size_y) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - *screen_x = x - screen_size_x / 2; - *screen_y = y - screen_size_y / 2; + *screen_x = x - screen_size_x / 2; + *screen_y = y - screen_size_y / 2; - if (*screen_x < 0) { - *screen_x = 0; - } + if (*screen_x < 0) { + *screen_x = 0; + } - if (*screen_y < 0) { - *screen_y = 0; - } + if (*screen_y < 0) { + *screen_y = 0; + } - if (*screen_x + screen_size_x >= arena->w) { - *screen_x = arena->w - screen_size_x; - } + if (*screen_x + screen_size_x >= arena->w) { + *screen_x = arena->w - screen_size_x; + } - if (*screen_y + screen_size_y >= arena->h) { - *screen_y = arena->h - screen_size_y; - } + if (*screen_y + screen_size_y >= arena->h) { + *screen_y = arena->h - screen_size_y; + } } #ifndef PUBLIC_SERVER -static void -drawBackground(arena_t * arena, int screen_x, int screen_y) +static void drawBackground(arena_t * arena, int screen_x, int screen_y) { - if (isBigArena(arena)) { - int i, j; - - for (i = screen_y / arena->background->h; - i <= - screen_y / arena->background->h + - WINDOW_SIZE_Y / arena->background->h + 1; i++) { - for (j = screen_x / arena->background->w; - j <= - screen_x / arena->background->w + - WINDOW_SIZE_X / arena->background->w + 1; j++) { - addLayer(arena->background, j * arena->background->w, - i * arena->background->h, 0, 0, arena->background->w, - arena->background->h, -100); - - //count++; - } - } - } - else { - addLayer(arena->background, - 0, 0, - 0, 0, arena->background->w, arena->background->h, -100); - } + if (isBigArena(arena)) { + int i, j; + + for (i = screen_y / arena->background->h; + i <= + screen_y / arena->background->h + + WINDOW_SIZE_Y / arena->background->h + 1; i++) { + for (j = screen_x / arena->background->w; + j <= + screen_x / arena->background->w + + WINDOW_SIZE_X / arena->background->w + 1; j++) { + addLayer(arena->background, j * arena->background->w, + i * arena->background->h, 0, 0, arena->background->w, + arena->background->h, -100); + + //count++; + } + } + } else { + addLayer(arena->background, + 0, 0, 0, 0, arena->background->w, arena->background->h, -100); + } } -static void -action_drawTux(space_t * space, tux_t * tux, void *p) +static void action_drawTux(space_t * space, tux_t * tux, void *p) { - drawTux(tux); + drawTux(tux); } -static void -action_drawItem(space_t * space, item_t * item, void *p) +static void action_drawItem(space_t * space, item_t * item, void *p) { - drawItem(item); + drawItem(item); } -static void -action_drawShot(space_t * space, shot_t * shot, void *p) +static void action_drawShot(space_t * space, shot_t * shot, void *p) { - drawShot(shot); + drawShot(shot); } -static void -drawObjects(arena_t * arena, int screen_x, int screen_y) +static void drawObjects(arena_t * arena, int screen_x, int screen_y) { - actionSpaceFromLocation(arena->spaceTux, action_drawTux, NULL, - screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceTux, action_drawTux, NULL, + screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - actionSpaceFromLocation(arena->spaceItem, action_drawItem, NULL, - screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceItem, action_drawItem, NULL, + screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - actionSpaceFromLocation(arena->spaceShot, action_drawShot, NULL, - screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceShot, action_drawShot, NULL, + screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - drawModule(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + drawModule(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); } static void drawSplitArenaForTux(arena_t * arena, tux_t * tux, int location_x, - int location_y) + int location_y) { - int screen_x, screen_y; - - switch (splitType) { - case SCREEN_SPLIT_HORIZONTAL: - getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X, - WINDOW_SIZE_Y / 2); - break; - case SCREEN_SPLIT_VERTICAL: - getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, - WINDOW_SIZE_X / 2, WINDOW_SIZE_Y); - break; - default: - screen_x = -1; - screen_y = -1; - assert(!"stupd error "); - break; - } - - drawBackground(arena, screen_x, screen_y); - drawObjects(arena, screen_x, screen_y); - - switch (splitType) { - case SCREEN_SPLIT_HORIZONTAL: - drawLayerSplit(location_x, location_y, screen_x, screen_y, - WINDOW_SIZE_X, WINDOW_SIZE_Y / 2); - break; - case SCREEN_SPLIT_VERTICAL: - drawLayerSplit(location_x, location_y, screen_x, screen_y, - WINDOW_SIZE_X / 2, WINDOW_SIZE_Y); - break; - default: - screen_x = -1; - screen_y = -1; - assert(!"stupd error "); - break; - } + int screen_x, screen_y; + + switch (splitType) { + case SCREEN_SPLIT_HORIZONTAL: + getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X, + WINDOW_SIZE_Y / 2); + break; + case SCREEN_SPLIT_VERTICAL: + getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, + WINDOW_SIZE_X / 2, WINDOW_SIZE_Y); + break; + default: + screen_x = -1; + screen_y = -1; + assert(!"stupd error "); + break; + } + + drawBackground(arena, screen_x, screen_y); + drawObjects(arena, screen_x, screen_y); + + switch (splitType) { + case SCREEN_SPLIT_HORIZONTAL: + drawLayerSplit(location_x, location_y, screen_x, screen_y, + WINDOW_SIZE_X, WINDOW_SIZE_Y / 2); + break; + case SCREEN_SPLIT_VERTICAL: + drawLayerSplit(location_x, location_y, screen_x, screen_y, + WINDOW_SIZE_X / 2, WINDOW_SIZE_Y); + break; + default: + screen_x = -1; + screen_y = -1; + assert(!"stupd error "); + break; + } } -void -drawSplitArena(arena_t * arena) +void drawSplitArena(arena_t * arena) { - tux_t *tux = NULL; - - tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - - if (tux != NULL) { - switch (splitType) { - case SCREEN_SPLIT_HORIZONTAL: - drawSplitArenaForTux(arena, tux, 0, WINDOW_SIZE_Y / 2); - break; - case SCREEN_SPLIT_VERTICAL: - drawSplitArenaForTux(arena, tux, WINDOW_SIZE_X / 2, 0); - break; - } - } - - tux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - - if (tux != NULL) { - drawSplitArenaForTux(arena, tux, 0, 0); - } + tux_t *tux = NULL; + + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + + if (tux != NULL) { + switch (splitType) { + case SCREEN_SPLIT_HORIZONTAL: + drawSplitArenaForTux(arena, tux, 0, WINDOW_SIZE_Y / 2); + break; + case SCREEN_SPLIT_VERTICAL: + drawSplitArenaForTux(arena, tux, WINDOW_SIZE_X / 2, 0); + break; + } + } + + tux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + + if (tux != NULL) { + drawSplitArenaForTux(arena, tux, 0, 0); + } } -void -drawCenterArena(arena_t * arena, int x, int y) +void drawCenterArena(arena_t * arena, int x, int y) { - int screen_x, screen_y; + int screen_x, screen_y; - getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - drawBackground(arena, screen_x, screen_y); - drawObjects(arena, screen_x, screen_y); - drawLayerCenter(x, y); + getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + drawBackground(arena, screen_x, screen_y); + drawObjects(arena, screen_x, screen_y); + drawLayerCenter(x, y); } -void -drawSimpleArena(arena_t * arena) +void drawSimpleArena(arena_t * arena) { - int screen_x, screen_y; - tux_t *tux = NULL; + int screen_x, screen_y; + tux_t *tux = NULL; - tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - if (tux == NULL) { - return; - } + if (tux == NULL) { + return; + } - screen_x = 0; - screen_y = 0; + screen_x = 0; + screen_y = 0; - drawBackground(arena, screen_x, screen_y); - drawObjects(arena, screen_x, screen_y); - drawLayer(tux->x, tux->y); + drawBackground(arena, screen_x, screen_y); + drawObjects(arena, screen_x, screen_y); + drawLayer(tux->x, tux->y); } -void -drawArena(arena_t * arena) +void drawArena(arena_t * arena) { - if (isBigArena(arena) && - getNetTypeGame() == NET_GAME_TYPE_NONE && !isSettingAI()) { - tux_t *tux1; - tux_t *tux2; + if (isBigArena(arena) && + getNetTypeGame() == NET_GAME_TYPE_NONE && !isSettingAI()) { + tux_t *tux1; + tux_t *tux2; - tux1 = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - tux2 = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + tux1 = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tux2 = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - if (isTuxNear(tux1, tux2)) { - drawCenterArena(arena, (tux1->x + tux2->x) / 2, - (tux1->y + tux2->y) / 2); - } - else { - drawSplitArena(arena); - } + if (isTuxNear(tux1, tux2)) { + drawCenterArena(arena, (tux1->x + tux2->x) / 2, + (tux1->y + tux2->y) / 2); + } else { + drawSplitArena(arena); + } - return; - } + return; + } - if (isBigArena(arena)) { - tux_t *tux = NULL; + if (isBigArena(arena)) { + tux_t *tux = NULL; - tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - if (tux == NULL) { - return; - } + if (tux == NULL) { + return; + } - drawCenterArena(arena, tux->x, tux->y); - return; - } + drawCenterArena(arena, tux->x, tux->y); + return; + } - drawSimpleArena(arena); + drawSimpleArena(arena); } #endif -static void -action_tux(space_t * space, tux_t * tux, void *p) +static void action_tux(space_t * space, tux_t * tux, void *p) { - eventTux(tux); + eventTux(tux); } -void -eventArena(arena_t * arena) +void eventArena(arena_t * arena) { - int i; + int i; - for (i = 0; i < 8; i++) { - checkShotIsInTuxScreen(arena); + for (i = 0; i < 8; i++) { + checkShotIsInTuxScreen(arena); - eventConflictShotWithItem(arena); - eventConflictTuxWithShot(arena); - eventModule(); + eventConflictShotWithItem(arena); + eventConflictTuxWithShot(arena); + eventModule(); - eventMoveListShot(arena); - } + eventMoveListShot(arena); + } - eventListItem(arena->spaceItem); + eventListItem(arena->spaceItem); - actionSpace(arena->spaceTux, action_tux, NULL); + actionSpace(arena->spaceTux, action_tux, NULL); - eventTimer(arena->listTimer); + eventTimer(arena->listTimer); } -void -destroyArena(arena_t * p) +void destroyArena(arena_t * p) { - destroySpaceWithObject(p->spaceTux, destroyTux); - destroySpaceWithObject(p->spaceItem, destroyItem); - destroySpaceWithObject(p->spaceShot, destroyShot); - destroyTimer(p->listTimer); - free(p); + destroySpaceWithObject(p->spaceTux, destroyTux); + destroySpaceWithObject(p->spaceItem, destroyItem); + destroySpaceWithObject(p->spaceShot, destroyShot); + destroyTimer(p->listTimer); + free(p); } diff --git a/src/base/arena.h b/src/base/arena.h index 3ff21d3..14f0f1f 100644 --- a/src/base/arena.h +++ b/src/base/arena.h @@ -1,41 +1,40 @@ #ifndef ARENA_H -#define ARENA_H +# define ARENA_H -#include "main.h" +# include "main.h" -#ifndef PUBLIC_SERVER -#include "image.h" -#endif +# ifndef PUBLIC_SERVER +# include "image.h" +# endif -#ifdef __WIN32__ -#define random rand -#endif +# ifdef __WIN32__ +# define random rand +# endif -#define SCREEN_SPLIT_HORIZONTAL 1 -#define SCREEN_SPLIT_VERTICAL 2 +# define SCREEN_SPLIT_HORIZONTAL 1 +# define SCREEN_SPLIT_VERTICAL 2 -#include "list.h" -#include "space.h" +# include "list.h" +# include "space.h" -typedef struct arena_struct -{ -#ifndef PUBLIC_SERVER - char music[STR_SIZE]; +typedef struct arena_struct { +# ifndef PUBLIC_SERVER + char music[STR_SIZE]; - image_t *background; -#endif - int w, h; + image_t *background; +# endif + int w, h; - list_t *listTimer; + list_t *listTimer; - space_t *spaceShot; - space_t *spaceTux; - space_t *spaceItem; + space_t *spaceShot; + space_t *spaceTux; + space_t *spaceItem; - int countRound; - int max_countRound; + int countRound; + int max_countRound; } arena_t; @@ -45,14 +44,14 @@ extern void initArena(); extern void quitArena(); extern arena_t *newArena(int w, int h); extern int conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, - int w2, int h2); + int w2, int h2); extern int isFreeSpace(arena_t * arena, int x, int y, int w, int h); extern void findFreeSpace(arena_t * arena, int *x, int *y, int w, int h); extern void getCenterScreen(int *screen_x, int *screen_y, int x, int y, - int screen_size_x, int screen_size_y); -#ifndef PUBLIC_SERVER + int screen_size_x, int screen_size_y); +# ifndef PUBLIC_SERVER extern void drawArena(arena_t * arena); -#endif +# endif extern void eventArena(arena_t * arena); extern void destroyArena(arena_t * p); diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c index 3a1ff59..efab611 100644 --- a/src/base/arenaFile.c +++ b/src/base/arenaFile.c @@ -18,354 +18,332 @@ #include "homeDirector.h" #ifndef PUBLIC_SERVER -#include "configFile.h" -#include "image.h" +# include "configFile.h" +# include "image.h" #endif #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif static list_t *listArenaFile; static bool_t isArenaFileInit = FALSE; -bool_t -isAreaFileInicialized() +bool_t isAreaFileInicialized() { - return isArenaFileInit; + return isArenaFileInit; } -int -getArenaValue(char *line, char *env, char *val, int len) +int getArenaValue(char *line, char *env, char *val, int len) { - char *offset_env; - char *offset_val_begin; - char *offset_val_end; - char clone_env[STR_SIZE]; - int val_len; - - strcpy(clone_env, " "); - strcat(clone_env, env); - offset_env = strstr(line, clone_env); - if (offset_env == NULL) - return -1; - offset_val_begin = strchr(offset_env, '"'); - if (offset_val_begin == NULL) - return -1; - offset_val_end = strchr(offset_val_begin + 1, '"'); - if (offset_val_end == NULL) - return -1; - val_len = (int) (offset_val_end - (offset_val_begin + 1)); - if (val_len > len - 1) - val_len = len - 1; - memset(val, 0, len); - memcpy(val, offset_val_begin + 1, val_len); - return 0; + char *offset_env; + char *offset_val_begin; + char *offset_val_end; + char clone_env[STR_SIZE]; + int val_len; + + strcpy(clone_env, " "); + strcat(clone_env, env); + offset_env = strstr(line, clone_env); + if (offset_env == NULL) + return -1; + offset_val_begin = strchr(offset_env, '"'); + if (offset_val_begin == NULL) + return -1; + offset_val_end = strchr(offset_val_begin + 1, '"'); + if (offset_val_end == NULL) + return -1; + val_len = (int) (offset_val_end - (offset_val_begin + 1)); + if (val_len > len - 1) + val_len = len - 1; + memset(val, 0, len); + memcpy(val, offset_val_begin + 1, val_len); + return 0; } #ifndef PUBLIC_SERVER -image_t * -loadImageFromArena(arenaFile_t * arenaFile, char *filename, char *group, - char *name, int alpha) +image_t *loadImageFromArena(arenaFile_t * arenaFile, char *filename, + char *group, char *name, int alpha) { - char *extractFile; - image_t *image; + char *extractFile; + image_t *image; - extractFile = extractFileFromArchive(arenaFile->path, filename); - image = addImageData(extractFile, alpha, name, group); - deleteExtractFile(extractFile); + extractFile = extractFileFromArchive(arenaFile->path, filename); + image = addImageData(extractFile, alpha, name, group); + deleteExtractFile(extractFile); - return image; + return image; } -#ifndef NO_SOUND +# ifndef NO_SOUND void loadMusicFromArena(arenaFile_t * arenaFile, char *filename, char *group, - char *name) + char *name) { - char *extractFile; + char *extractFile; - extractFile = extractFileFromArchive(arenaFile->path, filename); - addMusic(extractFile, name, group); - deleteExtractFile(extractFile); + extractFile = extractFileFromArchive(arenaFile->path, filename); + addMusic(extractFile, name, group); + deleteExtractFile(extractFile); } -#endif +# endif #endif -static void -cmd_arena(arena_t ** arena, char *line) +static void cmd_arena(arena_t ** arena, char *line) { - char str_image[STR_SIZE]; - char str_w[STR_SIZE]; - char str_h[STR_SIZE]; - - if (getArenaValue(line, "background", str_image, STR_SIZE) != 0) - return; - if (getArenaValue(line, "w", str_w, STR_SIZE) != 0) - return; - if (getArenaValue(line, "h", str_h, STR_SIZE) != 0) - return; - (*arena) = newArena(atoi(str_w), atoi(str_h)); + char str_image[STR_SIZE]; + char str_w[STR_SIZE]; + char str_h[STR_SIZE]; + + if (getArenaValue(line, "background", str_image, STR_SIZE) != 0) + return; + if (getArenaValue(line, "w", str_w, STR_SIZE) != 0) + return; + if (getArenaValue(line, "h", str_h, STR_SIZE) != 0) + return; + (*arena) = newArena(atoi(str_w), atoi(str_h)); #ifndef PUBLIC_SERVER - (*arena)->background = getImage(IMAGE_GROUP_USER, str_image); + (*arena)->background = getImage(IMAGE_GROUP_USER, str_image); #endif - //(*arena)->w = atoi(str_w); - //(*arena)->h = atoi(str_h); - setCurrentArena(*arena); + //(*arena)->w = atoi(str_w); + //(*arena)->h = atoi(str_h); + setCurrentArena(*arena); #ifdef DEBUG - printf(_("Loaded new arena...\n")); + printf(_("Loaded new arena...\n")); #endif } -static void -cmd_loadModule(char *line) +static void cmd_loadModule(char *line) { - char str_file[STR_SIZE]; + char str_file[STR_SIZE]; - if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) - return; - loadModule(str_file); + if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) + return; + loadModule(str_file); } #ifndef PUBLIC_SERVER -static void -cmd_loadImage(arenaFile_t * arenaFile, char *line) +static void cmd_loadImage(arenaFile_t * arenaFile, char *line) { - char str_file[STR_SIZE]; - char str_name[STR_SIZE]; - char str_alpha[STR_SIZE]; - - if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) - return; - if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) - return; - if (getArenaValue(line, "alpha", str_alpha, STR_SIZE) != 0) - return; - - //printf("str_file=%s str_name=%s str_alpha=%s\n", str_file, str_name, str_alpha); - loadImageFromArena(arenaFile, str_file, IMAGE_GROUP_USER, str_name, - isYesOrNO(str_alpha)); - - //addImageData(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER); + char str_file[STR_SIZE]; + char str_name[STR_SIZE]; + char str_alpha[STR_SIZE]; + + if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) + return; + if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) + return; + if (getArenaValue(line, "alpha", str_alpha, STR_SIZE) != 0) + return; + + //printf("str_file=%s str_name=%s str_alpha=%s\n", str_file, str_name, str_alpha); + loadImageFromArena(arenaFile, str_file, IMAGE_GROUP_USER, str_name, + isYesOrNO(str_alpha)); + + //addImageData(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER); } -static void -cmd_loadMusic(arenaFile_t * arenaFile, char *line) +static void cmd_loadMusic(arenaFile_t * arenaFile, char *line) { - char str_file[STR_SIZE]; - char str_name[STR_SIZE]; - - if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) - return; - if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) - return; -#ifndef NO_SOUND - //addMusic(str_file, str_name, MUSIC_GROUP_USER); - loadMusicFromArena(arenaFile, str_file, MUSIC_GROUP_USER, str_name); -#endif + char str_file[STR_SIZE]; + char str_name[STR_SIZE]; + + if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) + return; + if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) + return; +# ifndef NO_SOUND + //addMusic(str_file, str_name, MUSIC_GROUP_USER); + loadMusicFromArena(arenaFile, str_file, MUSIC_GROUP_USER, str_name); +# endif } -static void -cmd_playMusic(arena_t * arena, char *line) +static void cmd_playMusic(arena_t * arena, char *line) { - char str_music[STR_SIZE]; + char str_music[STR_SIZE]; - if (getArenaValue(line, "music", str_music, STR_SIZE) != 0) - return; - strcpy(arena->music, str_music); + if (getArenaValue(line, "music", str_music, STR_SIZE) != 0) + return; + strcpy(arena->music, str_music); } #endif -int -getArenaCount() +int getArenaCount() { - return listArenaFile->count; + return listArenaFile->count; } -static char * -getArenaStatus(textFile_t * ts, char *s) +static char *getArenaStatus(textFile_t * ts, char *s) { - int len; - int i; - - len = strlen(s); - for (i = 0; i < ts->text->count; i++) { - char *line; - line = (char *) (ts->text->list[i]); - if (strncmp(line, s, len) == 0) - return line + len + 1; - } - return NULL; + int len; + int i; + + len = strlen(s); + for (i = 0; i < ts->text->count; i++) { + char *line; + line = (char *) (ts->text->list[i]); + if (strncmp(line, s, len) == 0) + return line + len + 1; + } + return NULL; } -char * -getArenaName(arenaFile_t * arenaFile) +char *getArenaName(arenaFile_t * arenaFile) { - char *ret; + char *ret; - ret = getArenaStatus(arenaFile->map, "name"); - return (ret != NULL ? ret : "arena_no_name"); + ret = getArenaStatus(arenaFile->map, "name"); + return (ret != NULL ? ret : "arena_no_name"); } -char * -getArenaNetName(arenaFile_t * arenaFile) +char *getArenaNetName(arenaFile_t * arenaFile) { - char *ret; + char *ret; - ret = getArenaStatus(arenaFile->map, "netName"); - return (ret != NULL ? ret : "arena_no_net_name"); + ret = getArenaStatus(arenaFile->map, "netName"); + return (ret != NULL ? ret : "arena_no_net_name"); } -arenaFile_t * -getArenaFileFormNetName(char *s) +arenaFile_t *getArenaFileFormNetName(char *s) { - int i; + int i; // - for (i = 0; i < listArenaFile->count; i++) { - arenaFile_t *arenaFile; + for (i = 0; i < listArenaFile->count; i++) { + arenaFile_t *arenaFile; - arenaFile = (arenaFile_t *) listArenaFile->list[i]; - if (strcmp(getArenaNetName(arenaFile), s) == 0) - return arenaFile; - } + arenaFile = (arenaFile_t *) listArenaFile->list[i]; + if (strcmp(getArenaNetName(arenaFile), s) == 0) + return arenaFile; + } - return NULL; + return NULL; } -char * -getArenaImage(arenaFile_t * arenaFile) +char *getArenaImage(arenaFile_t * arenaFile) { - return getArenaStatus(arenaFile->map, "screen"); + return getArenaStatus(arenaFile->map, "screen"); } -arenaFile_t * -getArenaFile(int n) +arenaFile_t *getArenaFile(int n) { - return (arenaFile_t *) listArenaFile->list[n]; + return (arenaFile_t *) listArenaFile->list[n]; } -int -getArenaFileID(arenaFile_t * arenaFile) +int getArenaFileID(arenaFile_t * arenaFile) { - int i; + int i; - for (i = 0; i < listArenaFile->count; i++) { - arenaFile_t *this; + for (i = 0; i < listArenaFile->count; i++) { + arenaFile_t *this; - this = (arenaFile_t *) listArenaFile->list[i]; + this = (arenaFile_t *) listArenaFile->list[i]; - if (this == arenaFile) { - return i; - } - } + if (this == arenaFile) { + return i; + } + } - return -1; + return -1; } -arena_t * -getArena(arenaFile_t * arenaFile) +arena_t *getArena(arenaFile_t * arenaFile) { - textFile_t *ts; - arena_t *arena = NULL; // no warninng - int i; + textFile_t *ts; + arena_t *arena = NULL; // no warninng + int i; - ts = (textFile_t *) arenaFile->map; + ts = (textFile_t *) arenaFile->map; - for (i = 0; i < ts->text->count; i++) { - char *line; + for (i = 0; i < ts->text->count; i++) { + char *line; - line = (char *) (ts->text->list[i]); - cmdModule(line); + line = (char *) (ts->text->list[i]); + cmdModule(line); #ifndef PUBLIC_SERVER - if (strncmp(line, "loadImage", 9) == 0) - cmd_loadImage(arenaFile, line); - if (strncmp(line, "loadMusic", 9) == 0) - cmd_loadMusic(arenaFile, line); - if (strncmp(line, "playMusic", 9) == 0) - cmd_playMusic(arena, line); + if (strncmp(line, "loadImage", 9) == 0) + cmd_loadImage(arenaFile, line); + if (strncmp(line, "loadMusic", 9) == 0) + cmd_loadMusic(arenaFile, line); + if (strncmp(line, "playMusic", 9) == 0) + cmd_playMusic(arena, line); #endif - if (strncmp(line, "arena", 5) == 0) - cmd_arena(&arena, line); - if (strncmp(line, "loadModule", 10) == 0) - cmd_loadModule(line); - //if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); - //if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); - //if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); - } - - return arena; + if (strncmp(line, "arena", 5) == 0) + cmd_arena(&arena, line); + if (strncmp(line, "loadModule", 10) == 0) + cmd_loadModule(line); + //if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); + //if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); + //if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); + } + + return arena; } -arenaFile_t * -newArenaFile(char *path) +arenaFile_t *newArenaFile(char *path) { - arenaFile_t *new; - char *extractFile; + arenaFile_t *new; + char *extractFile; - new = malloc(sizeof(arenaFile_t)); - new->path = strdup(path); + new = malloc(sizeof(arenaFile_t)); + new->path = strdup(path); - extractFile = extractFileFromArchive(path, "arena.map"); - new->map = loadTextFile(extractFile); - deleteExtractFile(extractFile); + extractFile = extractFileFromArchive(path, "arena.map"); + new->map = loadTextFile(extractFile); + deleteExtractFile(extractFile); - return new; + return new; } -void -destroyArenaFile(arenaFile_t * p) +void destroyArenaFile(arenaFile_t * p) { - destroyTextFile(p->map); - free(p->path); - free(p); + destroyTextFile(p->map); + free(p->path); + free(p); } -void -loadArenaFile(char *path) +void loadArenaFile(char *path) { - addList(listArenaFile, newArenaFile(path)); + addList(listArenaFile, newArenaFile(path)); } -void -initArenaFile() +void initArenaFile() { - director_t *p; - int i; + director_t *p; + int i; #ifndef PUBLIC_SERVER - assert(isImageInicialized() == TRUE); + assert(isImageInicialized() == TRUE); #endif - isArenaFileInit = TRUE; - listArenaFile = newList(); + isArenaFileInit = TRUE; + listArenaFile = newList(); - p = loadDirector(PATH_ARENA); - //p = loadDirector( getHomeDirector() ); + p = loadDirector(PATH_ARENA); + //p = loadDirector( getHomeDirector() ); - for (i = 0; i < p->list->count; i++) { - char *line; + for (i = 0; i < p->list->count; i++) { + char *line; - line = (char *) (p->list->list[i]); + line = (char *) (p->list->list[i]); - if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) { - char path[STR_PATH_SIZE]; + if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) { + char path[STR_PATH_SIZE]; - sprintf(path, PATH_ARENA "%s", line); + sprintf(path, PATH_ARENA "%s", line); #ifdef DEBUG - printf(_("Loading arena: %s\n"), line); + printf(_("Loading arena: %s\n"), line); #endif - accessExistFile(path); - loadArenaFile(path); - } - } - //printf("No. of Arens: %d\n", listArenaFile->count); - destroyDirector(p); + accessExistFile(path); + loadArenaFile(path); + } + } + //printf("No. of Arens: %d\n", listArenaFile->count); + destroyDirector(p); } -void -quitArenaFile() +void quitArenaFile() { - isArenaFileInit = FALSE; - destroyListItem(listArenaFile, destroyArenaFile); + isArenaFileInit = FALSE; + destroyListItem(listArenaFile, destroyArenaFile); } diff --git a/src/base/arenaFile.h b/src/base/arenaFile.h index bc54176..05728d4 100644 --- a/src/base/arenaFile.h +++ b/src/base/arenaFile.h @@ -1,17 +1,16 @@ #ifndef ARENA_FILE_H -#define ARENA_FILE_H -#define PUBLIC_SERVER_PATH_ARENA "./arena/" +# define ARENA_FILE_H +# define PUBLIC_SERVER_PATH_ARENA "./arena/" -#include "main.h" -#include "arena.h" -#include "textFile.h" +# include "main.h" +# include "arena.h" +# include "textFile.h" -typedef struct -{ - char *path; - textFile_t *map; +typedef struct { + char *path; + textFile_t *map; } arenaFile_t; extern bool_t isAreaFileInicialized(); @@ -21,10 +20,10 @@ extern char *getArenaName(arenaFile_t * arenaFile); extern char *getArenaNetName(arenaFile_t * arenaFile); extern arenaFile_t *getArenaFileFormNetName(char *s); extern char *getArenaImage(arenaFile_t * arenaFile); -#ifndef PUBLIC_SERVER +# ifndef PUBLIC_SERVER extern image_t *loadImageFromArena(arenaFile_t * arenaFile, char *filename, - char *group, char *name, int alpha); -#endif + char *group, char *name, int alpha); +# endif extern arenaFile_t *getArenaFile(int n); extern int getArenaFileID(arenaFile_t * arenaFile); extern arena_t *getArena(arenaFile_t * arenaFile); diff --git a/src/base/bool.h b/src/base/bool.h index 4289878..7334348 100644 --- a/src/base/bool.h +++ b/src/base/bool.h @@ -1,9 +1,9 @@ #ifndef BOOL_H -#define BOOL_H -#define bool_t int -#define TRUE 1 -#define FALSE 0 +# define BOOL_H +# define bool_t int +# define TRUE 1 +# define FALSE 0 -#include "main.h" +# include "main.h" #endif diff --git a/src/base/buffer.c b/src/base/buffer.c index e09b7f2..7140444 100644 --- a/src/base/buffer.c +++ b/src/base/buffer.c @@ -6,140 +6,131 @@ #include "buffer.h" -buffer_t * -newBuffer(int n) +buffer_t *newBuffer(int n) { - buffer_t *new; + buffer_t *new; - new = malloc(sizeof(buffer_t)); - memset(new, 0, sizeof(buffer_t)); - new->alloc = n; - new->data = malloc(n); - memset(new->data, 0, n); + new = malloc(sizeof(buffer_t)); + memset(new, 0, sizeof(buffer_t)); + new->alloc = n; + new->data = malloc(n); + memset(new->data, 0, n); - return new; + return new; } -void * -getBufferData(buffer_t * p) +void *getBufferData(buffer_t * p) { - return p->data; + return p->data; } -int -getBufferSize(buffer_t * p) +int getBufferSize(buffer_t * p) { - return p->size; + return p->size; } -int -addBuffer(buffer_t * p, char *data, int len) +int addBuffer(buffer_t * p, char *data, int len) { - assert(p != NULL); - assert(data != NULL); - assert(len >= 0); + assert(p != NULL); + assert(data != NULL); + assert(len >= 0); - if (p->size + len <= p->alloc) { - memcpy(p->data + p->size, data, len); - p->size += len; - return len; - } + if (p->size + len <= p->alloc) { + memcpy(p->data + p->size, data, len); + p->size += len; + return len; + } - return -1; + return -1; } -int -cutBuffer(buffer_t * p, int len) +int cutBuffer(buffer_t * p, int len) { - assert(p != NULL); - assert(len >= 0); + assert(p != NULL); + assert(len >= 0); - if (p->size - len >= 0) { - memmove(p->data, p->data + len, p->size - len); - p->size -= len; - return 0; - } + if (p->size - len >= 0) { + memmove(p->data, p->data + len, p->size - len); + p->size -= len; + return 0; + } - return -1; + return -1; } -int -getBufferCount(buffer_t * p) +int getBufferCount(buffer_t * p) { - char *begin; - char *end; - int count; - int size; - - assert(p != NULL); - - count = 0; - begin = p->data; - size = p->size; - - while ((end = memchr(begin, '\n', size)) != NULL) { - count++; - size -= ((end + 1) - begin); - begin = end + 1; - } - - //printf("count = %d\n", count); - //printf("data = %s\n", p->data); - return count; + char *begin; + char *end; + int count; + int size; + + assert(p != NULL); + + count = 0; + begin = p->data; + size = p->size; + + while ((end = memchr(begin, '\n', size)) != NULL) { + count++; + size -= ((end + 1) - begin); + begin = end + 1; + } + + //printf("count = %d\n", count); + //printf("data = %s\n", p->data); + return count; } -int -getBufferLine(buffer_t * p, char *line, int len) +int getBufferLine(buffer_t * p, char *line, int len) { - char *end; - int ret_len; + char *end; + int ret_len; - assert(p != NULL); - assert(line != NULL); - assert(len >= 0); + assert(p != NULL); + assert(line != NULL); + assert(len >= 0); - end = NULL; + end = NULL; - end = memchr(p->data, '\n', p->size); + end = memchr(p->data, '\n', p->size); - if (end == NULL) - return -1; + if (end == NULL) + return -1; - ret_len = (int) (end - p->data) + 1; - if (ret_len > len - 1) - ret_len = len - 1; + ret_len = (int) (end - p->data) + 1; + if (ret_len > len - 1) + ret_len = len - 1; - memset(line, 0, len); - memcpy(line, p->data, ret_len); + memset(line, 0, len); + memcpy(line, p->data, ret_len); - cutBuffer(p, ret_len); + cutBuffer(p, ret_len); - return ret_len; + return ret_len; } -int -getBufferDataLen(buffer_t * p, char *line, int len) +int getBufferDataLen(buffer_t * p, char *line, int len) { - assert(p != NULL); - assert(line != NULL); - assert(len >= 0); + assert(p != NULL); + assert(line != NULL); + assert(len >= 0); - if (p->size < len) { - len = p->size; - } + if (p->size < len) { + len = p->size; + } - memcpy(line, p->data, len); - cutBuffer(p, len); + memcpy(line, p->data, len); + cutBuffer(p, len); - return len; + return len; } -void -destroyBuffer(buffer_t * p) +void destroyBuffer(buffer_t * p) { - assert(p != NULL); + assert(p != NULL); - if (p->data != NULL) - free(p->data); - free(p); + if (p->data != NULL) + free(p->data); + free(p); } diff --git a/src/base/buffer.h b/src/base/buffer.h index 8c2e3ce..a5f9717 100644 --- a/src/base/buffer.h +++ b/src/base/buffer.h @@ -1,15 +1,14 @@ #ifndef BUFFER_H -#define BUFFER_H +# define BUFFER_H -#define BUFFER_LIMIT_ALLOC 1024 +# define BUFFER_LIMIT_ALLOC 1024 -typedef struct str_buffer -{ - char *data; - unsigned int size; - unsigned int alloc; +typedef struct str_buffer { + char *data; + unsigned int size; + unsigned int alloc; } buffer_t; extern buffer_t *newBuffer(int n); diff --git a/src/base/checkFront.c b/src/base/checkFront.c index dfe11eb..53984fb 100644 --- a/src/base/checkFront.c +++ b/src/base/checkFront.c @@ -11,111 +11,102 @@ #include "idManager.h" #include "server.h" -typedef struct struct_checkfront_t -{ - char *msg; - my_time_t time; - int id; - int count; - int type; +typedef struct struct_checkfront_t { + char *msg; + my_time_t time; + int id; + int count; + int type; } checkfront_t; -static checkfront_t * -newCheck(char *s, int type, int id) +static checkfront_t *newCheck(char *s, int type, int id) { - checkfront_t *new; + checkfront_t *new; - assert(s != NULL); - new = malloc(sizeof(checkfront_t)); - memset(new, 0, sizeof(checkfront_t)); - new->msg = strdup(s); - new->time = getMyTime(); - new->id = id; - new->type = type; - new->count = 0; - return new; + assert(s != NULL); + new = malloc(sizeof(checkfront_t)); + memset(new, 0, sizeof(checkfront_t)); + new->msg = strdup(s); + new->time = getMyTime(); + new->id = id; + new->type = type; + new->count = 0; + return new; } -static void -destroyCheck(checkfront_t * p) +static void destroyCheck(checkfront_t * p) { - assert(p != NULL); - free(p->msg); - free(p); + assert(p != NULL); + free(p->msg); + free(p); } -list_t * -newCheckFront() +list_t *newCheckFront() { - return newList(); + return newList(); } -void -addMsgInCheckFront(list_t * list, char *msg, int type, int id) +void addMsgInCheckFront(list_t * list, char *msg, int type, int id) { - if (type == CHECK_FRONT_TYPE_CHECK) - incID(id); - addList(list, newCheck(msg, type, id)); + if (type == CHECK_FRONT_TYPE_CHECK) + incID(id); + addList(list, newCheck(msg, type, id)); } -void -eventMsgInCheckFront(client_t * client) +void eventMsgInCheckFront(client_t * client) { - my_time_t currentTime; - int i; + my_time_t currentTime; + int i; - currentTime = getMyTime(); - for (i = 0; i < client->listSendMsg->count; i++) { - checkfront_t *this; + currentTime = getMyTime(); + for (i = 0; i < client->listSendMsg->count; i++) { + checkfront_t *this; - this = (checkfront_t *) client->listSendMsg->list[i]; - switch (this->type) { - case CHECK_FRONT_TYPE_SIMPLE: - sendClient(client, this->msg); - delListItem(client->listSendMsg, i, destroyCheck); - i--; - break; - case CHECK_FRONT_TYPE_CHECK: - if (this->count == 0 - || currentTime - this->time > - CHECK_FRONT_SEND_TIME_INTERVAL) { - sendClient(client, this->msg); - this->time = currentTime; - this->count++; - } - if (this->count > CHECK_FRONT_MAX_COUNT_SEND) { - delID(this->id); - delListItem(client->listSendMsg, i, destroyCheck); - i--; - } - break; - default: - assert(!_("Bad type of front!")); - break; - } - } + this = (checkfront_t *) client->listSendMsg->list[i]; + switch (this->type) { + case CHECK_FRONT_TYPE_SIMPLE: + sendClient(client, this->msg); + delListItem(client->listSendMsg, i, destroyCheck); + i--; + break; + case CHECK_FRONT_TYPE_CHECK: + if (this->count == 0 + || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL) { + sendClient(client, this->msg); + this->time = currentTime; + this->count++; + } + if (this->count > CHECK_FRONT_MAX_COUNT_SEND) { + delID(this->id); + delListItem(client->listSendMsg, i, destroyCheck); + i--; + } + break; + default: + assert(!_("Bad type of front!")); + break; + } + } } -void -delMsgInCheckFront(list_t * listCheckFront, int id) +void delMsgInCheckFront(list_t * listCheckFront, int id) { - int i; + int i; - for (i = 0; i < listCheckFront->count; i++) { - checkfront_t *this; + for (i = 0; i < listCheckFront->count; i++) { + checkfront_t *this; - this = (checkfront_t *) listCheckFront->list[i]; - if (this->id == id) { - delID(this->id); - delListItem(listCheckFront, i, destroyCheck); - return; - } - } + this = (checkfront_t *) listCheckFront->list[i]; + if (this->id == id) { + delID(this->id); + delListItem(listCheckFront, i, destroyCheck); + return; + } + } } -void -destroyCheckFront(list_t * p) +void destroyCheckFront(list_t * p) { - assert(p != NULL); - destroyListItem(p, destroyCheck); + assert(p != NULL); + destroyListItem(p, destroyCheck); } diff --git a/src/base/checkFront.h b/src/base/checkFront.h index 32d23b7..85ed2fb 100644 --- a/src/base/checkFront.h +++ b/src/base/checkFront.h @@ -1,16 +1,16 @@ #ifndef CHECK_FRONT_H -#define CHECK_FRONT_H -#define CHECK_FRONT_SEND_TIME_INTERVAL 100 -#define CHECK_FRONT_MAX_COUNT_SEND 30 +# define CHECK_FRONT_H +# define CHECK_FRONT_SEND_TIME_INTERVAL 100 +# define CHECK_FRONT_MAX_COUNT_SEND 30 -#define CHECK_FRONT_ID_NONE -1 -#define CHECK_FRONT_TYPE_SIMPLE 1 -#define CHECK_FRONT_TYPE_CHECK 2 +# define CHECK_FRONT_ID_NONE -1 +# define CHECK_FRONT_TYPE_SIMPLE 1 +# define CHECK_FRONT_TYPE_CHECK 2 -#include "list.h" -#include "server.h" +# include "list.h" +# include "server.h" extern list_t *newCheckFront(); extern void addMsgInCheckFront(list_t * list, char *msg, int type, int id); diff --git a/src/base/director.c b/src/base/director.c index eea7ea4..dfcc9cb 100644 --- a/src/base/director.c +++ b/src/base/director.c @@ -10,54 +10,51 @@ #include "main.h" #include "list.h" -typedef struct director_struct -{ - char *path; - list_t *list; +typedef struct director_struct { + char *path; + list_t *list; } director_t; -director_t * -loadDirector(char *s) +director_t *loadDirector(char *s) { - director_t *new; - DIR *dir; - struct dirent *item; - char path[STR_PATH_SIZE]; - assert(s != 0); - new = malloc(sizeof(director_t)); - memset(new, 0, sizeof(director_t)); - new->list = newList(); + director_t *new; + DIR *dir; + struct dirent *item; + char path[STR_PATH_SIZE]; + assert(s != 0); + new = malloc(sizeof(director_t)); + memset(new, 0, sizeof(director_t)); + new->list = newList(); #ifndef __WIN32__ - if (s[0] == '/') + if (s[0] == '/') #else - if (s[1] == ':') + if (s[1] == ':') #endif - strcpy(path, s); - else { - // this is really correct aproach - getcwd(path, STR_PATH_SIZE); - strcat(path, "/"); - strcat(path, s); - } - new->path = strdup(path); - dir = opendir(new->path); - if (dir == NULL) { - free(new->path); - free(new); - return NULL; - } + strcpy(path, s); + else { + // this is really correct aproach + getcwd(path, STR_PATH_SIZE); + strcat(path, "/"); + strcat(path, s); + } + new->path = strdup(path); + dir = opendir(new->path); + if (dir == NULL) { + free(new->path); + free(new); + return NULL; + } - while ((item = readdir(dir)) != NULL) - addList(new->list, strdup(item->d_name)); - closedir(dir); - return new; + while ((item = readdir(dir)) != NULL) + addList(new->list, strdup(item->d_name)); + closedir(dir); + return new; } -void -destroyDirector(director_t * p) +void destroyDirector(director_t * p) { - assert(p != NULL); - destroyListItem(p->list, free); - free(p->path); - free(p); + assert(p != NULL); + destroyListItem(p->list, free); + free(p->path); + free(p); } diff --git a/src/base/director.h b/src/base/director.h index f050642..ea61dd0 100644 --- a/src/base/director.h +++ b/src/base/director.h @@ -1,14 +1,13 @@ #ifndef DIRECTOR_H -#define DIRECTOR_H +# define DIRECTOR_H -#include "main.h" -#include "list.h" +# include "main.h" +# include "list.h" -typedef struct director_struct -{ - char *path; - list_t *list; +typedef struct director_struct { + char *path; + list_t *list; } director_t; extern director_t *loadDirector(char *s); diff --git a/src/base/gun.c b/src/base/gun.c index bf6545e..408233e 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -15,287 +15,274 @@ #include "serverSendMsg.h" #ifndef NO_SOUND -#include "sound.h" +# include "sound.h" #endif #ifndef PUBLIC_SERVER -#include "interface.h" -#include "screen_world.h" +# include "interface.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, - int *dest_y) + int *dest_y) { - assert(dest_x != NULL); - assert(dest_y != NULL); - switch (courser) { - case TUX_UP: - *dest_x = right_y; - *dest_y = -right_x; - break; - case TUX_RIGHT: - *dest_x = right_x; - *dest_y = right_y; - break; - case TUX_LEFT: - *dest_x = -right_x; - *dest_y = right_y; - break; - case TUX_DOWN: - *dest_x = right_y; - *dest_y = right_x; - break; - default: - assert(!_("There is wrong value in course variable!")); - break; - } + assert(dest_x != NULL); + assert(dest_y != NULL); + switch (courser) { + case TUX_UP: + *dest_x = right_y; + *dest_y = -right_x; + break; + case TUX_RIGHT: + *dest_x = right_x; + *dest_y = right_y; + break; + case TUX_LEFT: + *dest_x = -right_x; + *dest_y = right_y; + break; + case TUX_DOWN: + *dest_x = right_y; + *dest_y = right_x; + break; + default: + assert(!_("There is wrong value in course variable!")); + break; + } } -static void -addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun) +static void addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun) { - int dest_x = 0, dest_y = 0; - int dest_px = 0, dest_py = 0; - shot_t *shot; + int dest_x = 0, dest_y = 0; + int dest_px = 0, dest_py = 0; + shot_t *shot; - modificiationCopuse(tux->position, px, py, &dest_px, &dest_py); - modificiationCopuse(tux->position, x, y, &dest_x, &dest_y); - if (gun == GUN_LASSER) - switch (tux->position) { - case TUX_UP: - dest_y -= GUN_LASSER_HORIZONTAL; - break; - case TUX_RIGHT: - break; - case TUX_LEFT: - dest_x -= GUN_LASSER_HORIZONTAL; - break; - case TUX_DOWN: - break; - } - shot = - newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, - tux->id); - addObjectToSpace(getCurrentArena()->spaceShot, shot); + modificiationCopuse(tux->position, px, py, &dest_px, &dest_py); + modificiationCopuse(tux->position, x, y, &dest_x, &dest_y); + if (gun == GUN_LASSER) + switch (tux->position) { + case TUX_UP: + dest_y -= GUN_LASSER_HORIZONTAL; + break; + case TUX_RIGHT: + break; + case TUX_LEFT: + dest_x -= GUN_LASSER_HORIZONTAL; + break; + case TUX_DOWN: + break; + } + shot = + newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, + tux->id); + addObjectToSpace(getCurrentArena()->spaceShot, shot); } -static void -addShot(tux_t * tux, int x, int y, int px, int py) +static void addShot(tux_t * tux, int x, int y, int px, int py) { - int gun; + int gun; - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; - if (tux->gun == GUN_BOMBBALL) - gun = GUN_BOMBBALL; - else if (tux->gun == GUN_LASSER) - gun = GUN_LASSER; - else - gun = GUN_SIMPLE; + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; + if (tux->gun == GUN_BOMBBALL) + gun = GUN_BOMBBALL; + else if (tux->gun == GUN_LASSER) + gun = GUN_LASSER; + else + gun = GUN_SIMPLE; - if (tux->bonus == BONUS_4X) { - int zal; - int i; + if (tux->bonus == BONUS_4X) { + int zal; + int i; - zal = tux->position; - for (i = 0; i < 4; i++) { - switch (i) { - case 0: - tux->position = TUX_UP; - break; - case 1: - tux->position = TUX_RIGHT; - break; - case 2: - tux->position = TUX_LEFT; - break; - case 3: - tux->position = TUX_DOWN; - break; - } - addShotTrivial(tux, x, y, px, py, gun); - } - tux->position = zal; - } - else { - addShotTrivial(tux, x, y, px, py, gun); - } + zal = tux->position; + for (i = 0; i < 4; i++) { + switch (i) { + case 0: + tux->position = TUX_UP; + break; + case 1: + tux->position = TUX_RIGHT; + break; + case 2: + tux->position = TUX_LEFT; + break; + case 3: + tux->position = TUX_DOWN; + break; + } + addShotTrivial(tux, x, y, px, py, gun); + } + tux->position = zal; + } else { + addShotTrivial(tux, x, y, px, py, gun); + } } -static void -shotInGunSimpe(tux_t * tux) +static void shotInGunSimpe(tux_t * tux) { - addShot(tux, 0, 0, +5, 0); + addShot(tux, 0, 0, +5, 0); } -static void -shotInGunDualSimpe(tux_t * tux) +static void shotInGunDualSimpe(tux_t * tux) { - addShot(tux, 0, -10, +6, 0); - addShot(tux, 0, +10, +6, 0); + addShot(tux, 0, -10, +6, 0); + addShot(tux, 0, +10, +6, 0); } -static void -shotInGunScatter(tux_t * tux) +static void shotInGunScatter(tux_t * tux) { - int i; + int i; - for (i = -2; i <= +2; i++) - addShot(tux, 0, 0, +8, i); + for (i = -2; i <= +2; i++) + addShot(tux, 0, 0, +8, i); } -static void -timer_addShotTimer(void *p) +static void timer_addShotTimer(void *p) { - tux_t *tux; - int id; - int gun; + tux_t *tux; + int id; + int gun; - id = *((int *) p); - free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux == NULL) - return; - if (tux->status != TUX_STATUS_ALIVE) - return; - gun = tux->gun; - tux->gun = GUN_SIMPLE; - addShot(tux, 0, 0, +6, 0); - tux->gun = gun; + id = *((int *) p); + free(p); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + if (tux == NULL) + return; + if (tux->status != TUX_STATUS_ALIVE) + return; + gun = tux->gun; + tux->gun = GUN_SIMPLE; + addShot(tux, 0, 0, +6, 0); + tux->gun = gun; } -static void -shotInGunTommy(tux_t * tux) +static void shotInGunTommy(tux_t * tux) { - int i; + int i; - for (i = 0; i < 10; i++) - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_addShotTimer, newInt(tux->id), i * 100); + for (i = 0; i < 10; i++) + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_addShotTimer, newInt(tux->id), i * 100); } -static void -timer_addLaserTimer(void *p) +static void timer_addLaserTimer(void *p) { - tux_t *tux; - int id; - int gun; + tux_t *tux; + int id; + int gun; - id = *((int *) p); - free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux == NULL) - return; - if (tux->status != TUX_STATUS_ALIVE) - return; - gun = tux->gun; - tux->gun = GUN_LASSER; - addShot(tux, 0, 0, +10, 0); - addShot(tux, +40, 0, +10, 0); - //addShot(tux, +40, 0, +10, 0); - tux->gun = gun; + id = *((int *) p); + free(p); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + if (tux == NULL) + return; + if (tux->status != TUX_STATUS_ALIVE) + return; + gun = tux->gun; + tux->gun = GUN_LASSER; + addShot(tux, 0, 0, +10, 0); + addShot(tux, +40, 0, +10, 0); + //addShot(tux, +40, 0, +10, 0); + tux->gun = gun; } -static void -shotInGunLasser(tux_t * tux) +static void shotInGunLasser(tux_t * tux) { - int i; + int i; - for (i = 0; i < 50; i++) - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_addLaserTimer, newInt(tux->id), i * 10); + for (i = 0; i < 50; i++) + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_addLaserTimer, newInt(tux->id), i * 10); } -static void -putInGunMine(tux_t * tux) +static void putInGunMine(tux_t * tux) { - int x, y; - arena_t *arena; + int x, y; + arena_t *arena; - x = tux->x; - y = tux->y; - switch (tux->position) { - case TUX_UP: - y += TUX_HEIGHT; - break; - case TUX_RIGHT: - x -= TUX_WIDTH; - break; - case TUX_LEFT: - x += TUX_WIDTH; - break; - case TUX_DOWN: - y -= TUX_HEIGHT; - break; - } - arena = getCurrentArena(); - if (isFreeSpace - (getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) { - item_t *item; + x = tux->x; + y = tux->y; + switch (tux->position) { + case TUX_UP: + y += TUX_HEIGHT; + break; + case TUX_RIGHT: + x -= TUX_WIDTH; + break; + case TUX_LEFT: + x += TUX_WIDTH; + break; + case TUX_DOWN: + y -= TUX_HEIGHT; + break; + } + arena = getCurrentArena(); + if (isFreeSpace + (getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) { + item_t *item; #ifndef NO_SOUND - playSound("put_mine", SOUND_GROUP_BASE); + playSound("put_mine", SOUND_GROUP_BASE); #endif - tux->shot[tux->gun]--; - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - item = newItem(x, y, ITEM_MINE, tux->id); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_additem_server(PROTO_SEND_ALL, NULL, item); - addObjectToSpace(arena->spaceItem, item); - } - } + tux->shot[tux->gun]--; + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + item = newItem(x, y, ITEM_MINE, tux->id); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + addObjectToSpace(arena->spaceItem, item); + } + } } -static void -shotInGunBombball(tux_t * tux) +static void shotInGunBombball(tux_t * tux) { - addShot(tux, 0, 0, +10, 0); + addShot(tux, 0, 0, +10, 0); } -void -shotInGun(tux_t * tux) +void shotInGun(tux_t * tux) { - if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) - tux->shot[tux->gun]--; + if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) + tux->shot[tux->gun]--; - switch (tux->gun) { - case GUN_SIMPLE: + switch (tux->gun) { + case GUN_SIMPLE: #ifndef NO_SOUND - playSound("gun_revolver", SOUND_GROUP_BASE); + playSound("gun_revolver", SOUND_GROUP_BASE); #endif - shotInGunSimpe(tux); - break; - case GUN_DUAL_SIMPLE: + shotInGunSimpe(tux); + break; + case GUN_DUAL_SIMPLE: #ifndef NO_SOUND - playSound("gun_revolver", SOUND_GROUP_BASE); + playSound("gun_revolver", SOUND_GROUP_BASE); #endif - shotInGunDualSimpe(tux); - break; - case GUN_SCATTER: + shotInGunDualSimpe(tux); + break; + case GUN_SCATTER: #ifndef NO_SOUND - playSound("gun_scatter", SOUND_GROUP_BASE); + playSound("gun_scatter", SOUND_GROUP_BASE); #endif - shotInGunScatter(tux); - break; - case GUN_TOMMY: + shotInGunScatter(tux); + break; + case GUN_TOMMY: #ifndef NO_SOUND - playSound("gun_tommy", SOUND_GROUP_BASE); + playSound("gun_tommy", SOUND_GROUP_BASE); #endif - shotInGunTommy(tux); - break; - case GUN_LASSER: + shotInGunTommy(tux); + break; + case GUN_LASSER: #ifndef NO_SOUND - playSound("gun_lasser", SOUND_GROUP_BASE); + playSound("gun_lasser", SOUND_GROUP_BASE); #endif - shotInGunLasser(tux); - break; - case GUN_BOMBBALL: - shotInGunBombball(tux); - break; - case GUN_MINE: - putInGunMine(tux); - break; - } + shotInGunLasser(tux); + break; + case GUN_BOMBBALL: + shotInGunBombball(tux); + break; + case GUN_MINE: + putInGunMine(tux); + break; + } } diff --git a/src/base/gun.h b/src/base/gun.h index 38727e1..1f64327 100644 --- a/src/base/gun.h +++ b/src/base/gun.h @@ -1,15 +1,15 @@ #ifndef GUN_H -#define GUN_H -#define GUN_SHOT_WIDTH 5 -#define GUN_SHOT_HEIGHT 5 -#define GUN_LASSER_HORIZONTAL 40 -#define GUN_SHOT_VERTICAL 5 -#define GUN_BOMBBALL_WIDTH 20 -#define GUN_BOMBBALL_HEIGHT 20 +# define GUN_H +# define GUN_SHOT_WIDTH 5 +# define GUN_SHOT_HEIGHT 5 +# define GUN_LASSER_HORIZONTAL 40 +# define GUN_SHOT_VERTICAL 5 +# define GUN_BOMBBALL_WIDTH 20 +# define GUN_BOMBBALL_HEIGHT 20 -#include "main.h" -#include "tux.h" +# include "main.h" +# include "tux.h" extern void shotInGun(tux_t * p); #endif diff --git a/src/base/homeDirector.c b/src/base/homeDirector.c index 81d34c5..1f10920 100644 --- a/src/base/homeDirector.c +++ b/src/base/homeDirector.c @@ -10,39 +10,37 @@ static char homeDirector[STR_PATH_SIZE]; -void -createHomeDirector() +void createHomeDirector() { - char *envHome; + char *envHome; #ifndef __WIN32__ - envHome = getenv("HOME"); + envHome = getenv("HOME"); #else - envHome = getenv("USERPROFILE"); + envHome = getenv("USERPROFILE"); #endif - if (envHome == NULL) { - fprintf(stderr, _("Environment variable HOME not found!\n")); - exit(0); - } + if (envHome == NULL) { + fprintf(stderr, _("Environment variable HOME not found!\n")); + exit(0); + } - sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME); + sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME); - if (access(homeDirector, F_OK) != 0) { + if (access(homeDirector, F_OK) != 0) { #ifdef DEBUG - printf(_("Creating home directory %s.\n"), homeDirector); + printf(_("Creating home directory %s.\n"), homeDirector); #endif #ifndef __WIN32__ - if (mkdir(homeDirector, 0755) != 0) { + if (mkdir(homeDirector, 0755) != 0) { #else - if (mkdir(homeDirector) != 0) { + if (mkdir(homeDirector) != 0) { #endif - fprintf(stderr, _("Unable to create home directory!\n")); - exit(0); - } - } + fprintf(stderr, _("Unable to create home directory!\n")); + exit(0); + } + } } -char * -getHomeDirector() +char *getHomeDirector() { - return homeDirector; + return homeDirector; } diff --git a/src/base/homeDirector.h b/src/base/homeDirector.h index e4133ee..0fe1bd9 100644 --- a/src/base/homeDirector.h +++ b/src/base/homeDirector.h @@ -1,9 +1,9 @@ #ifndef HOMEDIRECTOR_H -#define HOMEDIRECTOR_H -#define HOMEDIRECTOR_NAME ".tuxanci" +# define HOMEDIRECTOR_H +# define HOMEDIRECTOR_NAME ".tuxanci" -#include "main.h" +# include "main.h" extern void createHomeDirector(); extern char *getHomeDirector(); diff --git a/src/base/idManager.c b/src/base/idManager.c index 0e2fbfb..e79534e 100644 --- a/src/base/idManager.c +++ b/src/base/idManager.c @@ -10,203 +10,190 @@ static list_t *listID; static int lastID; -typedef struct id_item_struct -{ - int id; - int count; +typedef struct id_item_struct { + int id; + int count; } id_item_t; -static id_item_t * -newIdItem(int id, int count) +static id_item_t *newIdItem(int id, int count) { - id_item_t *new; + id_item_t *new; - new = malloc(sizeof(id_item_t)); - new->id = id; - new->count = count; + new = malloc(sizeof(id_item_t)); + new->id = id; + new->count = count; - return new; + return new; } -static void -destroyIdItem(id_item_t * p) +static void destroyIdItem(id_item_t * p) { - assert(p != NULL); + assert(p != NULL); - free(p); + free(p); } -void -initListID() +void initListID() { - listID = newList(); - lastID = 0; + listID = newList(); + lastID = 0; #ifdef DEBUG - printf(_("Starting ID manger\n")); + printf(_("Starting ID manger\n")); #endif } -int -isRegisterID(int id) +int isRegisterID(int id) { - int i; + int i; - assert(listID != NULL); + assert(listID != NULL); - for (i = 0; i < listID->count; i++) { - id_item_t *this; + for (i = 0; i < listID->count; i++) { + id_item_t *this; - this = listID->list[i]; + this = listID->list[i]; - if (this->id == id) { - return i; - } - } + if (this->id == id) { + return i; + } + } - return -1; + return -1; } -static int -findNewID() +static int findNewID() { - int ret; + int ret; - assert(listID != NULL); + assert(listID != NULL); - if (listID->count >= MAX_ID - 1) { - assert(!_("No free ID left!")); - } + if (listID->count >= MAX_ID - 1) { + assert(!_("No free ID left!")); + } - do { - //ret = ( random() % (listID->count + 8 ) ) + 1; - ret = random() % MAX_ID + 1; - } while (isRegisterID(ret) != -1); + do { + //ret = ( random() % (listID->count + 8 ) ) + 1; + ret = random() % MAX_ID + 1; + } while (isRegisterID(ret) != -1); - //printf("new ID %d\n", ret); + //printf("new ID %d\n", ret); - return ret; + return ret; } -int -getNewIDcount(int count) +int getNewIDcount(int count) { - int id; + int id; - id = findNewID(); + id = findNewID(); - addList(listID, newIdItem(id, count)); + addList(listID, newIdItem(id, count)); - return id; + return id; } -int -getNewID() +int getNewID() { - return getNewIDcount(1); + return getNewIDcount(1); } -void -incID(int id) +void incID(int id) { - id_item_t *this; - int index; + id_item_t *this; + int index; - assert(listID != NULL); + assert(listID != NULL); - index = isRegisterID(id); + index = isRegisterID(id); - if (index == -1) { - assert(!_("This kind of ID was never registered!")); - return; // ha ha ha - } + if (index == -1) { + assert(!_("This kind of ID was never registered!")); + return; // ha ha ha + } - this = listID->list[index]; + this = listID->list[index]; - this->count++; + this->count++; - //printf("inc ID %d %d\n", this->id, this->count); - return; + //printf("inc ID %d %d\n", this->id, this->count); + return; } -void -delID(int id) +void delID(int id) { - id_item_t *this; - int index; + id_item_t *this; + int index; - assert(listID != NULL); + assert(listID != NULL); - index = isRegisterID(id); + index = isRegisterID(id); - if (index == -1) { - assert(!_("This kind of ID was never registered!")); - return; // ha ha ha - } + if (index == -1) { + assert(!_("This kind of ID was never registered!")); + return; // ha ha ha + } - this = listID->list[index]; + this = listID->list[index]; - this->count--; - //printf("dec ID %d %d\n", this->id, this->count); + this->count--; + //printf("dec ID %d %d\n", this->id, this->count); - if (this->count <= 0) { - delListItem(listID, index, free); - //printf("listID->count = %d\n", listID->count); - } + if (this->count <= 0) { + delListItem(listID, index, free); + //printf("listID->count = %d\n", listID->count); + } - return; + return; } -void -replaceID(int old_id, int new_id) +void replaceID(int old_id, int new_id) { - int index_old_id; - int index_new_id; - id_item_t *this; + int index_old_id; + int index_new_id; + id_item_t *this; - if (old_id == new_id) { - return; - } + if (old_id == new_id) { + return; + } - index_old_id = isRegisterID(old_id); - assert(index_old_id != -1); + index_old_id = isRegisterID(old_id); + assert(index_old_id != -1); - index_new_id = isRegisterID(new_id); - assert(index_new_id == -1); + index_new_id = isRegisterID(new_id); + assert(index_new_id == -1); - this = listID->list[index_old_id]; - this->id = new_id; + this = listID->list[index_old_id]; + this->id = new_id; } -void -infoID(int id) +void infoID(int id) { - id_item_t *this; - int index; + id_item_t *this; + int index; - assert(listID != NULL); + assert(listID != NULL); - index = isRegisterID(id); + index = isRegisterID(id); - if (index == -1) { + if (index == -1) { #ifdef DEBUG - printf(_("ID %d does not exist\n"), id); + printf(_("ID %d does not exist\n"), id); #endif - return; - } + return; + } - this = listID->list[index]; + this = listID->list[index]; #ifdef DEBUG - printf(_("ID %d (count %d)\n"), this->id, this->count); + printf(_("ID %d (count %d)\n"), this->id, this->count); #endif - return; + return; } -void -quitListID() +void quitListID() { #ifdef DEBUG - printf(_("Quitting ID manger\n")); + printf(_("Quitting ID manger\n")); #endif - assert(listID != NULL); - destroyListItem(listID, destroyIdItem); + assert(listID != NULL); + destroyListItem(listID, destroyIdItem); } diff --git a/src/base/idManager.h b/src/base/idManager.h index d157419..c5c2fbf 100644 --- a/src/base/idManager.h +++ b/src/base/idManager.h @@ -1,12 +1,12 @@ #ifndef ID_MANAGER_H -#define ID_MANAGER_H -#define MAX_ID 1000000 -#define ID_UNKNOWN -1 -#ifdef __WIN32__ -#define random rand -#endif -#include "list.h" +# define ID_MANAGER_H +# define MAX_ID 1000000 +# define ID_UNKNOWN -1 +# ifdef __WIN32__ +# define random rand +# endif +# include "list.h" extern void initListID(); extern int isRegisterID(int id); diff --git a/src/base/index.c b/src/base/index.c index 5247018..b5da90e 100644 --- a/src/base/index.c +++ b/src/base/index.c @@ -10,273 +10,259 @@ #define DEBUG_INDEX -static index_item_t * -newIndexItem(int key, void *data) +static index_item_t *newIndexItem(int key, void *data) { - index_item_t *new; + index_item_t *new; - new = malloc(sizeof(index_item_t)); - new->key = key; - new->data = data; + new = malloc(sizeof(index_item_t)); + new->key = key; + new->data = data; - return new; + return new; } #ifdef DEBUG_INDEX -static void -printIndexItem(index_item_t * p) +static void printIndexItem(index_item_t * p) { - printf("key = %d data = %p\n", p->key, p->data); + printf("key = %d data = %p\n", p->key, p->data); } -static void -printListIndexItem(list_t * list) +static void printListIndexItem(list_t * list) { - int i; + int i; - printf("list :\n"); - printf("------------------\n"); + printf("list :\n"); + printf("------------------\n"); - for (i = 0; i < list->count; i++) { - index_item_t *this; + for (i = 0; i < list->count; i++) { + index_item_t *this; - this = (index_item_t *) list->list[i]; - printIndexItem(this); - } + this = (index_item_t *) list->list[i]; + printIndexItem(this); + } } -static void -checkList(list_t * list) +static void checkList(list_t * list) { - int i; - int prev; - int this; + int i; + int prev; + int this; - //return; + //return; - if (list->count == 0) { - printf("nothing\n"); - return; - } + if (list->count == 0) { + printf("nothing\n"); + return; + } - prev = ((index_item_t *) list->list[0])->key; + prev = ((index_item_t *) list->list[0])->key; - for (i = 1; i < list->count; i++) { - this = ((index_item_t *) list->list[i])->key; + for (i = 1; i < list->count; i++) { + this = ((index_item_t *) list->list[i])->key; - if (prev >= this) { - printListIndexItem(list); - assert(!"error"); - } + if (prev >= this) { + printListIndexItem(list); + assert(!"error"); + } - prev = this; - } + prev = this; + } } #endif -static void -destroyIndexItem(index_item_t * p) +static void destroyIndexItem(index_item_t * p) { - free(p); + free(p); } -list_t * -newIndex() +list_t *newIndex() { - return newList(); + return newList(); } -void -addToIndex(list_t * list, int key, void *data) +void addToIndex(list_t * list, int key, void *data) { #ifdef DEBUG_INDEX - int count = 0; + int count = 0; #endif - index_item_t *item; - index_item_t *this; - int min, max, point; - int len; + index_item_t *item; + index_item_t *this; + int min, max, point; + int len; - item = newIndexItem(key, data); - len = list->count; + item = newIndexItem(key, data); + len = list->count; - min = 0; - max = len - 1; + min = 0; + max = len - 1; - for (;;) { - point = min + (max - min) / 2; + for (;;) { + point = min + (max - min) / 2; #ifdef DEBUG_INDEX - if (++count == len * 5) { - printf("CICLIC ERROR\n"); - printIndexItem(item); - printf("-------------------\n"); - printListIndexItem(list); - assert(0); - } + if (++count == len * 5) { + printf("CICLIC ERROR\n"); + printIndexItem(item); + printf("-------------------\n"); + printListIndexItem(list); + assert(0); + } #endif - if (max < 0) { - insList(list, 0, item); + if (max < 0) { + insList(list, 0, item); #ifdef DEBUG_INDEX - checkList(list); + checkList(list); #endif - return; - } + return; + } - if (min >= len) { - addList(list, item); + if (min >= len) { + addList(list, item); #ifdef DEBUG_INDEX - checkList(list); + checkList(list); #endif - return; - } + return; + } - this = (index_item_t *) list->list[point]; + this = (index_item_t *) list->list[point]; /* printf("min = %d max = %d point = %d len = %d offset = %d\n", min, max, point, len, offset); */ - if (min > max) { - insList(list, point, item); + if (min > max) { + insList(list, point, item); #ifdef DEBUG_INDEX - checkList(list); + checkList(list); #endif - return; - } - - if (item->key > this->key) { - min = point + 1; - continue; - } - - if (item->key < this->key) { - max = point - 1; - continue; - } - } + return; + } + + if (item->key > this->key) { + min = point + 1; + continue; + } + + if (item->key < this->key) { + max = point - 1; + continue; + } + } } -static int -getOffsetFromIndex(list_t * list, int key) +static int getOffsetFromIndex(list_t * list, int key) { - index_item_t *this; - int min, max, point, len; + index_item_t *this; + int min, max, point, len; - len = list->count; + len = list->count; - if (len == 0) { - return -1; - } + if (len == 0) { + return -1; + } - min = 0; - max = len - 1; + min = 0; + max = len - 1; - for (;;) { - point = min + (max - min) / 2; + for (;;) { + point = min + (max - min) / 2; - if (max < 0 || point >= len || max < min) { - return -1; - } + if (max < 0 || point >= len || max < min) { + return -1; + } - this = (index_item_t *) list->list[point]; + this = (index_item_t *) list->list[point]; /* printf("min = %d max = %d point = %d len = %d offset = %d\n", min, max, point, len, offset); */ - if (key == this->key) { - return point; - } - - if (key > this->key) { - min = point + 1; - continue; - } - - if (key < this->key) { - max = point - 1; - continue; - } - } + if (key == this->key) { + return point; + } + + if (key > this->key) { + min = point + 1; + continue; + } + + if (key < this->key) { + max = point - 1; + continue; + } + } } -void * -getFromIndex(list_t * list, int key) +void *getFromIndex(list_t * list, int key) { - int offset; + int offset; - offset = getOffsetFromIndex(list, key); + offset = getOffsetFromIndex(list, key); - if (offset != -1) { - index_item_t *this; + if (offset != -1) { + index_item_t *this; - this = list->list[offset]; - return this->data; - } + this = list->list[offset]; + return this->data; + } - return NULL; + return NULL; } -void -delFromIndex(list_t * list, int key) +void delFromIndex(list_t * list, int key) { - int offset; + int offset; - offset = getOffsetFromIndex(list, key); + offset = getOffsetFromIndex(list, key); - if (offset != -1) { - delListItem(list, offset, destroyIndexItem); - } + if (offset != -1) { + delListItem(list, offset, destroyIndexItem); + } } -void -delFromIndexWithObject(list_t * list, int key, void *f) +void delFromIndexWithObject(list_t * list, int key, void *f) { - int offset; + int offset; - offset = getOffsetFromIndex(list, key); + offset = getOffsetFromIndex(list, key); - if (offset != -1) { - index_item_t *this; - void (*fce) (void *p); + if (offset != -1) { + index_item_t *this; + void (*fce) (void *p); - this = list->list[offset]; + this = list->list[offset]; - fce = f; - fce(this); + fce = f; + fce(this); - delListItem(list, offset, destroyIndexItem); - } + delListItem(list, offset, destroyIndexItem); + } } -void -actionIndexWithObject(list_t * list, void *f) +void actionIndexWithObject(list_t * list, void *f) { - int i; + int i; - for (i = 0; i < list->count; i++) { - index_item_t *this; - void (*fce) (void *p); + for (i = 0; i < list->count; i++) { + index_item_t *this; + void (*fce) (void *p); - this = list->list[i]; + this = list->list[i]; - fce = f; - fce(this); - } + fce = f; + fce(this); + } } -void -destroyIndex(list_t * list) +void destroyIndex(list_t * list) { - destroyListItem(list, destroyIndexItem); + destroyListItem(list, destroyIndexItem); } -void -destroyIndexWithObject(list_t * list, void *f) +void destroyIndexWithObject(list_t * list, void *f) { - actionIndexWithObject(list, f); - destroyListItem(list, destroyIndexItem); + actionIndexWithObject(list, f); + destroyListItem(list, destroyIndexItem); } diff --git a/src/base/index.h b/src/base/index.h index 9126706..7f9cbea 100644 --- a/src/base/index.h +++ b/src/base/index.h @@ -1,15 +1,14 @@ #ifndef INDEX_H -#define INDEX_H +# define INDEX_H -#include "main.h" -#include "list.h" +# include "main.h" +# include "list.h" -typedef struct index_item_struct -{ - int key; - void *data; +typedef struct index_item_struct { + int key; + void *data; } index_item_t; extern list_t *newIndex(); diff --git a/src/base/item.c b/src/base/item.c index fb93c6a..4239697 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -14,22 +14,22 @@ #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#include "radar.h" -#include "layer.h" +# include "interface.h" +# include "image.h" +# include "radar.h" +# include "layer.h" -#include "screen_world.h" -#include "screen_setting.h" +# include "screen_world.h" +# include "screen_setting.h" -#ifndef NO_SOUND -#include "sound.h" -#endif +# ifndef NO_SOUND +# include "sound.h" +# endif #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif #ifndef PUBLIC_SERVER @@ -38,535 +38,510 @@ static image_t *g_item[ITEM_COUNT]; static bool_t isItemInit = FALSE; -bool_t -isItemInicialized() +bool_t isItemInicialized() { - return isItemInit; + return isItemInit; } -void -initItem() +void initItem() { #ifndef PUBLIC_SERVER - g_item[GUN_DUAL_SIMPLE] = - addImageData("item.dual.png", IMAGE_ALPHA, "item_dual_simple", - IMAGE_GROUP_BASE); - g_item[GUN_TOMMY] = - addImageData("item.tommy.png", IMAGE_ALPHA, "item_tommy_simple", - IMAGE_GROUP_BASE); - g_item[GUN_SCATTER] = - addImageData("item.scatter.png", IMAGE_ALPHA, "item_scatter_simple", - IMAGE_GROUP_BASE); - g_item[GUN_LASSER] = - addImageData("item.lasser.png", IMAGE_ALPHA, "item_lasser_simple", - IMAGE_GROUP_BASE); - g_item[GUN_MINE] = - addImageData("item.mine.png", IMAGE_ALPHA, "item_mines_simple", - IMAGE_GROUP_BASE); - g_item[GUN_BOMBBALL] = - addImageData("item.bombball.png", IMAGE_ALPHA, "item_bombball_simple", - IMAGE_GROUP_BASE); - - g_item[ITEM_MINE] = - addImageData("mine.png", IMAGE_ALPHA, "item_mine_simple", - IMAGE_GROUP_BASE); - g_item[ITEM_EXPLOSION] = - addImageData("explosion.png", IMAGE_ALPHA, "item_explosion_simple", - IMAGE_GROUP_BASE); - g_item[ITEM_BIG_EXPLOSION] = - addImageData("big-explosion.png", IMAGE_ALPHA, - "item_big-explosion_simple", IMAGE_GROUP_BASE); - - g_item[BONUS_SPEED] = - addImageData("item.bonus.speed.png", IMAGE_ALPHA, "item_bonus_speed", - IMAGE_GROUP_BASE); - g_item[BONUS_SHOT] = - addImageData("item.bonus.shot.png", IMAGE_ALPHA, "item_shot_speed", - IMAGE_GROUP_BASE); - g_item[BONUS_TELEPORT] = - addImageData("item.bonus.teleport.png", IMAGE_ALPHA, - "item_teleport_speed", IMAGE_GROUP_BASE); - g_item[BONUS_GHOST] = - addImageData("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", - IMAGE_GROUP_BASE); - g_item[BONUS_4X] = - addImageData("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", - IMAGE_GROUP_BASE); - g_item[BONUS_HIDDEN] = - addImageData("item.bonus.hidden.png", IMAGE_ALPHA, - "item_hidden_speed", IMAGE_GROUP_BASE); + g_item[GUN_DUAL_SIMPLE] = + addImageData("item.dual.png", IMAGE_ALPHA, "item_dual_simple", + IMAGE_GROUP_BASE); + g_item[GUN_TOMMY] = + addImageData("item.tommy.png", IMAGE_ALPHA, "item_tommy_simple", + IMAGE_GROUP_BASE); + g_item[GUN_SCATTER] = + addImageData("item.scatter.png", IMAGE_ALPHA, "item_scatter_simple", + IMAGE_GROUP_BASE); + g_item[GUN_LASSER] = + addImageData("item.lasser.png", IMAGE_ALPHA, "item_lasser_simple", + IMAGE_GROUP_BASE); + g_item[GUN_MINE] = + addImageData("item.mine.png", IMAGE_ALPHA, "item_mines_simple", + IMAGE_GROUP_BASE); + g_item[GUN_BOMBBALL] = + addImageData("item.bombball.png", IMAGE_ALPHA, "item_bombball_simple", + IMAGE_GROUP_BASE); + + g_item[ITEM_MINE] = + addImageData("mine.png", IMAGE_ALPHA, "item_mine_simple", + IMAGE_GROUP_BASE); + g_item[ITEM_EXPLOSION] = + addImageData("explosion.png", IMAGE_ALPHA, "item_explosion_simple", + IMAGE_GROUP_BASE); + g_item[ITEM_BIG_EXPLOSION] = + addImageData("big-explosion.png", IMAGE_ALPHA, + "item_big-explosion_simple", IMAGE_GROUP_BASE); + + g_item[BONUS_SPEED] = + addImageData("item.bonus.speed.png", IMAGE_ALPHA, "item_bonus_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_SHOT] = + addImageData("item.bonus.shot.png", IMAGE_ALPHA, "item_shot_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_TELEPORT] = + addImageData("item.bonus.teleport.png", IMAGE_ALPHA, + "item_teleport_speed", IMAGE_GROUP_BASE); + g_item[BONUS_GHOST] = + addImageData("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_4X] = + addImageData("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_HIDDEN] = + addImageData("item.bonus.hidden.png", IMAGE_ALPHA, + "item_hidden_speed", IMAGE_GROUP_BASE); #endif - isItemInit = TRUE; + isItemInit = TRUE; } -item_t * -newItem(int x, int y, int type, int author_id) +item_t *newItem(int x, int y, int type, int author_id) { - item_t *new; - - new = malloc(sizeof(item_t)); - assert(new != NULL); - new->type = type; - new->id = getNewID(); - new->x = x; - new->y = y; - new->frame = 0; - new->count = 0; + item_t *new; + + new = malloc(sizeof(item_t)); + assert(new != NULL); + new->type = type; + new->id = getNewID(); + new->x = x; + new->y = y; + new->frame = 0; + new->count = 0; #ifndef PUBLIC_SERVER - new->img = g_item[type]; + new->img = g_item[type]; #endif - new->author_id = author_id; - switch (type) { - case GUN_DUAL_SIMPLE: - case GUN_SCATTER: - case GUN_TOMMY: - case GUN_LASSER: - case GUN_MINE: - case GUN_BOMBBALL: - new->w = ITEM_GUN_WIDTH; - new->h = ITEM_GUN_HEIGHT; - break; - case ITEM_MINE: - new->w = ITEM_MINE_WIDTH; - new->h = ITEM_MINE_HEIGHT; - break; - case ITEM_EXPLOSION: + new->author_id = author_id; + switch (type) { + case GUN_DUAL_SIMPLE: + case GUN_SCATTER: + case GUN_TOMMY: + case GUN_LASSER: + case GUN_MINE: + case GUN_BOMBBALL: + new->w = ITEM_GUN_WIDTH; + new->h = ITEM_GUN_HEIGHT; + break; + case ITEM_MINE: + new->w = ITEM_MINE_WIDTH; + new->h = ITEM_MINE_HEIGHT; + break; + case ITEM_EXPLOSION: #ifndef NO_SOUND - playSound("explozion", SOUND_GROUP_BASE); + playSound("explozion", SOUND_GROUP_BASE); #endif - new->w = ITEM_EXPLOSION_WIDTH; - new->h = ITEM_EXPLOSION_HEIGHT; - break; - case ITEM_BIG_EXPLOSION: + new->w = ITEM_EXPLOSION_WIDTH; + new->h = ITEM_EXPLOSION_HEIGHT; + break; + case ITEM_BIG_EXPLOSION: #ifndef NO_SOUND - playSound("explozion", SOUND_GROUP_BASE); + playSound("explozion", SOUND_GROUP_BASE); #endif - new->w = ITEM_BIG_EXPLOSION_WIDTH; - new->h = ITEM_BIG_EXPLOSION_HEIGHT; - break; - case BONUS_SPEED: - case BONUS_SHOT: - case BONUS_TELEPORT: - case BONUS_GHOST: - case BONUS_4X: - case BONUS_HIDDEN: - new->w = ITEM_BONUS_WIDTH; - new->h = ITEM_BONUS_HEIGHT; - break; - } - return new; + new->w = ITEM_BIG_EXPLOSION_WIDTH; + new->h = ITEM_BIG_EXPLOSION_HEIGHT; + break; + case BONUS_SPEED: + case BONUS_SHOT: + case BONUS_TELEPORT: + case BONUS_GHOST: + case BONUS_4X: + case BONUS_HIDDEN: + new->w = ITEM_BONUS_WIDTH; + new->h = ITEM_BONUS_HEIGHT; + break; + } + return new; } -void -getStatusItem(void *p, int *id, int *x, int *y, int *w, int *h) +void getStatusItem(void *p, int *id, int *x, int *y, int *w, int *h) { - item_t *item; - - item = p; - *id = item->id; - *x = item->x; - *y = item->y; - *w = item->w; - *h = item->h; + item_t *item; + + item = p; + *id = item->id; + *x = item->x; + *y = item->y; + *w = item->w; + *h = item->h; } -void -setStatusItem(void *p, int x, int y, int w, int h) +void setStatusItem(void *p, int x, int y, int w, int h) { - item_t *item; + item_t *item; - item = p; - item->x = x; - item->y = y; - item->w = w; - item->h = h; + item = p; + item->x = x; + item->y = y; + item->w = w; + item->h = h; } -void -replaceItemID(item_t * item, int id) +void replaceItemID(item_t * item, int id) { - replaceID(item->id, id); - item->id = id; + replaceID(item->id, id); + item->id = id; } #ifdef PUBLIC_SERVER -static void -action_countitem(space_t * space, item_t * item, int *count) +static void action_countitem(space_t * space, item_t * item, int *count) { - if ((item->type >= GUN_DUAL_SIMPLE && item->type <= GUN_BOMBBALL) || - (item->type >= BONUS_SPEED && item->type <= BONUS_HIDDEN)) { - (*count)++; - } + if ((item->type >= GUN_DUAL_SIMPLE && item->type <= GUN_BOMBBALL) || + (item->type >= BONUS_SPEED && item->type <= BONUS_HIDDEN)) { + (*count)++; + } } -static int -getCountWeaponOrBonusItem(space_t * spaceItem) +static int getCountWeaponOrBonusItem(space_t * spaceItem) { - int count = 0; + int count = 0; - actionSpace(spaceItem, action_countitem, &count); + actionSpace(spaceItem, action_countitem, &count); - return count; + return count; } #endif -void -addNewItem(space_t * spaceItem, int author_id) +void addNewItem(space_t * spaceItem, int author_id) { - arena_t *arena; - item_t *item; - int new_x, new_y; - int type; + arena_t *arena; + item_t *item; + int new_x, new_y; + int type; #ifdef PUBLIC_SERVER - if (getCountWeaponOrBonusItem(spaceItem) >= - atoi(getSetting("MAX_ITEM", "--max-item", "100"))) { - return; - } + if (getCountWeaponOrBonusItem(spaceItem) >= + atoi(getSetting("MAX_ITEM", "--max-item", "100"))) { + return; + } #endif #ifndef PUBLIC_SERVER - if (isSettingAnyItem() == FALSE || - getNetTypeGame() == NET_GAME_TYPE_CLIENT) { - return; - } + if (isSettingAnyItem() == FALSE || + getNetTypeGame() == NET_GAME_TYPE_CLIENT) { + return; + } #endif - arena = getCurrentArena(); - findFreeSpace(getCurrentArena(), &new_x, &new_y, ITEM_GUN_WIDTH, - ITEM_GUN_HEIGHT); + arena = getCurrentArena(); + findFreeSpace(getCurrentArena(), &new_x, &new_y, ITEM_GUN_WIDTH, + ITEM_GUN_HEIGHT); - type = GUN_DUAL_SIMPLE; + type = GUN_DUAL_SIMPLE; #ifndef PUBLIC_SERVER - do { + do { #endif - switch (random() % 12) { - case 0: - type = GUN_DUAL_SIMPLE; - break; - case 1: - type = GUN_SCATTER; - break; - case 2: - type = GUN_TOMMY; - break; - case 3: - type = GUN_MINE; - break; - case 4: - type = GUN_LASSER; - break; - case 5: - type = GUN_BOMBBALL; - break; - case 6: - type = BONUS_SPEED; - break; - case 7: - type = BONUS_SHOT; - break; - case 8: - type = BONUS_TELEPORT; - break; - case 9: - type = BONUS_GHOST; - break; - case 10: - type = BONUS_4X; - break; - case 11: - type = BONUS_HIDDEN; - break; - } + switch (random() % 12) { + case 0: + type = GUN_DUAL_SIMPLE; + break; + case 1: + type = GUN_SCATTER; + break; + case 2: + type = GUN_TOMMY; + break; + case 3: + type = GUN_MINE; + break; + case 4: + type = GUN_LASSER; + break; + case 5: + type = GUN_BOMBBALL; + break; + case 6: + type = BONUS_SPEED; + break; + case 7: + type = BONUS_SHOT; + break; + case 8: + type = BONUS_TELEPORT; + break; + case 9: + type = BONUS_GHOST; + break; + case 10: + type = BONUS_4X; + break; + case 11: + type = BONUS_HIDDEN; + break; + } #ifndef PUBLIC_SERVER - } while (isSettingItem(type) == FALSE || - (getNetTypeGame() == NET_GAME_TYPE_NONE - && type == BONUS_HIDDEN)); + } while (isSettingItem(type) == FALSE || + (getNetTypeGame() == NET_GAME_TYPE_NONE && type == BONUS_HIDDEN)); #endif - item = newItem(new_x, new_y, type, author_id); - addObjectToSpace(spaceItem, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + item = newItem(new_x, new_y, type, author_id); + addObjectToSpace(spaceItem, item); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); #ifndef PUBLIC_SERVER - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - addToRadar(item->id, new_x, new_y, RADAR_TYPE_ITEM); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + addToRadar(item->id, new_x, new_y, RADAR_TYPE_ITEM); #endif } #ifndef PUBLIC_SERVER -void -drawItem(item_t * p) +void drawItem(item_t * p) { - assert(p != NULL); - addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER); + assert(p != NULL); + addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER); } -void -drawListItem(list_t * listItem) +void drawListItem(list_t * listItem) { - item_t *thisItem; - int i; - - assert(listItem != NULL); - for (i = 0; i < listItem->count; i++) { - thisItem = (item_t *) listItem->list[i]; - assert(thisItem != NULL); - drawItem(thisItem); - } + item_t *thisItem; + int i; + + assert(listItem != NULL); + for (i = 0; i < listItem->count; i++) { + thisItem = (item_t *) listItem->list[i]; + assert(thisItem != NULL); + drawItem(thisItem); + } } #endif -static void -action_itemevent(space_t * space, item_t * item, void *p) +static void action_itemevent(space_t * space, item_t * item, void *p) { - my_time_t currentTime; - - currentTime = getMyTime(); - item->count++; - if (item->count == ITEM_MAX_COUNT) { - item->count = 0; - item->frame++; - } - switch (item->type) { - case GUN_TOMMY: - case GUN_DUAL_SIMPLE: - case GUN_SCATTER: - case GUN_LASSER: - case GUN_MINE: - case GUN_BOMBBALL: - if (item->frame == ITEM_GUN_MAX_FRAME) - item->frame = 0; - break; - case ITEM_MINE: - if (item->frame == ITEM_MINE_MAX_FRAME) - item->frame = 0; - break; - case ITEM_EXPLOSION: - case ITEM_BIG_EXPLOSION: - if (item->frame == ITEM_EXPLOSION_MAX_FRAME) - delObjectFromSpaceWithObject(space, item, destroyItem); - break; - case BONUS_SPEED: - case BONUS_SHOT: - case BONUS_TELEPORT: - case BONUS_GHOST: - case BONUS_4X: - case BONUS_HIDDEN: - if (item->frame == ITEM_GUN_MAX_FRAME) - item->frame = 0; - break; - } + my_time_t currentTime; + + currentTime = getMyTime(); + item->count++; + if (item->count == ITEM_MAX_COUNT) { + item->count = 0; + item->frame++; + } + switch (item->type) { + case GUN_TOMMY: + case GUN_DUAL_SIMPLE: + case GUN_SCATTER: + case GUN_LASSER: + case GUN_MINE: + case GUN_BOMBBALL: + if (item->frame == ITEM_GUN_MAX_FRAME) + item->frame = 0; + break; + case ITEM_MINE: + if (item->frame == ITEM_MINE_MAX_FRAME) + item->frame = 0; + break; + case ITEM_EXPLOSION: + case ITEM_BIG_EXPLOSION: + if (item->frame == ITEM_EXPLOSION_MAX_FRAME) + delObjectFromSpaceWithObject(space, item, destroyItem); + break; + case BONUS_SPEED: + case BONUS_SHOT: + case BONUS_TELEPORT: + case BONUS_GHOST: + case BONUS_4X: + case BONUS_HIDDEN: + if (item->frame == ITEM_GUN_MAX_FRAME) + item->frame = 0; + break; + } } -void -eventListItem(space_t * spaceItem) +void eventListItem(space_t * spaceItem) { - actionSpace(spaceItem, action_itemevent, NULL); + actionSpace(spaceItem, action_itemevent, NULL); } -static void -mineExplosion(space_t * spaceItem, item_t * item) +static void mineExplosion(space_t * spaceItem, item_t * item) { - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - int x, y; - item_t *item_explosion; - - x = (item->x + item->w / 2) - ITEM_BIG_EXPLOSION_WIDTH / 2; - y = (item->y + item->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; - item_explosion = newItem(x, y, ITEM_BIG_EXPLOSION, item->author_id); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion); - addObjectToSpace(spaceItem, item_explosion); - } - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - delObjectFromSpaceWithObject(spaceItem, item, destroyItem); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + int x, y; + item_t *item_explosion; + + x = (item->x + item->w / 2) - ITEM_BIG_EXPLOSION_WIDTH / 2; + y = (item->y + item->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; + item_explosion = newItem(x, y, ITEM_BIG_EXPLOSION, item->author_id); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion); + addObjectToSpace(spaceItem, item_explosion); + } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + delObjectFromSpaceWithObject(spaceItem, item, destroyItem); } -static void -action_item(space_t * space, item_t * item, int *isDel) +static void action_item(space_t * space, item_t * item, int *isDel) { - arena_t *arena; - - arena = getCurrentArena(); - switch (item->type) { - case ITEM_MINE: - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - mineExplosion(space, item); - break; - case ITEM_EXPLOSION: - case ITEM_BIG_EXPLOSION: - *isDel = 1; - break; - } + arena_t *arena; + + arena = getCurrentArena(); + switch (item->type) { + case ITEM_MINE: + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + mineExplosion(space, item); + break; + case ITEM_EXPLOSION: + case ITEM_BIG_EXPLOSION: + *isDel = 1; + break; + } } -static void -action_shot(space_t * space, shot_t * shot, space_t * spaceItem) +static void action_shot(space_t * space, shot_t * shot, space_t * spaceItem) { - int isDel = 0; - - actionSpaceFromLocation(spaceItem, action_item, &isDel, shot->x, shot->y, - shot->w, shot->h); - if (isDel) { - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); - delObjectFromSpaceWithObject(space, shot, destroyShot); - } + int isDel = 0; + + actionSpaceFromLocation(spaceItem, action_item, &isDel, shot->x, shot->y, + shot->w, shot->h); + if (isDel) { + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + delObjectFromSpaceWithObject(space, shot, destroyShot); + } } -void -eventConflictShotWithItem(arena_t * arena) +void eventConflictShotWithItem(arena_t * arena) { - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; - actionSpace(arena->spaceShot, action_shot, arena->spaceItem); + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; + actionSpace(arena->spaceShot, action_shot, arena->spaceItem); } -static void -eventTuxIsDeadWithItem(tux_t * tux, item_t * item) +static void eventTuxIsDeadWithItem(tux_t * tux, item_t * item) { - if (tux->bonus == BONUS_GHOST) - return; - if (tux->bonus == BONUS_TELEPORT) { - tuxTeleport(tux); - return; - } - if (item->author_id == tux->id) { - tux->score--; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - if (item->author_id != tux->id) { - tux_t *author; - - author = - getObjectFromSpaceWithID(getCurrentArena()->spaceTux, - item->author_id); - if (author != NULL) { - author->score++; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); - } - } - countRoundInc(); - eventTuxIsDead(tux); + if (tux->bonus == BONUS_GHOST) + return; + if (tux->bonus == BONUS_TELEPORT) { + tuxTeleport(tux); + return; + } + if (item->author_id == tux->id) { + tux->score--; + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + if (item->author_id != tux->id) { + tux_t *author; + + author = + getObjectFromSpaceWithID(getCurrentArena()->spaceTux, + item->author_id); + if (author != NULL) { + author->score++; + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); + } + } + countRoundInc(); + eventTuxIsDead(tux); } -static void -tuxGiveBonus(tux_t * tux, item_t * item) +static void tuxGiveBonus(tux_t * tux, item_t * item) { #ifndef NO_SOUND - playSound("item_bonus", SOUND_GROUP_BASE); + playSound("item_bonus", SOUND_GROUP_BASE); #endif - tux->bonus = item->type; - tux->bonus_time = TUX_MAX_BONUS; + tux->bonus = item->type; + tux->bonus_time = TUX_MAX_BONUS; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); #ifndef PUBLIC_SERVER - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - delFromRadar(item->id); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + delFromRadar(item->id); #endif } -static void -tuxGiveGun(tux_t * tux, item_t * item) +static void tuxGiveGun(tux_t * tux, item_t * item) { #ifndef NO_SOUND - playSound("item_gun", SOUND_GROUP_BASE); + playSound("item_gun", SOUND_GROUP_BASE); #endif - tux->pickup_time = 0; - tux->shot[item->type] += GUN_MAX_SHOT; - tux->gun = item->type; + tux->pickup_time = 0; + tux->shot[item->type] += GUN_MAX_SHOT; + tux->gun = item->type; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); #ifndef PUBLIC_SERVER - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - delFromRadar(item->id); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + delFromRadar(item->id); #endif } -static void -action_giveitem(space_t * space, item_t * item, tux_t * tux) +static void action_giveitem(space_t * space, item_t * item, tux_t * tux) { - switch (item->type) { - case GUN_TOMMY: - case GUN_DUAL_SIMPLE: - case GUN_SCATTER: - case GUN_LASSER: - case GUN_MINE: - case GUN_BOMBBALL: - tuxGiveGun(tux, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); - delObjectFromSpaceWithObject(space, item, destroyItem); + switch (item->type) { + case GUN_TOMMY: + case GUN_DUAL_SIMPLE: + case GUN_SCATTER: + case GUN_LASSER: + case GUN_MINE: + case GUN_BOMBBALL: + tuxGiveGun(tux, item); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + delObjectFromSpaceWithObject(space, item, destroyItem); #ifdef PUBLIC_SERVER - addNewItem(space, ID_UNKNOWN); + addNewItem(space, ID_UNKNOWN); #endif - break; - - case ITEM_MINE: - if (tux->bonus != BONUS_GHOST) - mineExplosion(space, item); - break; - case ITEM_EXPLOSION: - case ITEM_BIG_EXPLOSION: - if (tux->bonus != BONUS_GHOST) - eventTuxIsDeadWithItem(tux, item); - break; - case BONUS_SPEED: - case BONUS_SHOT: - case BONUS_TELEPORT: - case BONUS_GHOST: - case BONUS_4X: - case BONUS_HIDDEN: - tuxGiveBonus(tux, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); - delObjectFromSpaceWithObject(space, item, destroyItem); + break; + + case ITEM_MINE: + if (tux->bonus != BONUS_GHOST) + mineExplosion(space, item); + break; + case ITEM_EXPLOSION: + case ITEM_BIG_EXPLOSION: + if (tux->bonus != BONUS_GHOST) + eventTuxIsDeadWithItem(tux, item); + break; + case BONUS_SPEED: + case BONUS_SHOT: + case BONUS_TELEPORT: + case BONUS_GHOST: + case BONUS_4X: + case BONUS_HIDDEN: + tuxGiveBonus(tux, item); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + delObjectFromSpaceWithObject(space, item, destroyItem); #ifdef PUBLIC_SERVER - addNewItem(space, ID_UNKNOWN); + addNewItem(space, ID_UNKNOWN); #endif - break; - } + break; + } } -void -eventGiveTuxListItem(tux_t * tux, space_t * spaceItem) +void eventGiveTuxListItem(tux_t * tux, space_t * spaceItem) { - int x, y, w, h; + int x, y, w, h; - assert(spaceItem != NULL); - assert(tux != NULL); + assert(spaceItem != NULL); + assert(tux != NULL); - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; - if (tux->status == TUX_STATUS_DEAD) - return; + if (tux->status == TUX_STATUS_DEAD) + return; - getTuxProportion(tux, &x, &y, &w, &h); - actionSpaceFromLocation(spaceItem, action_giveitem, tux, x, y, w, h); + getTuxProportion(tux, &x, &y, &w, &h); + actionSpaceFromLocation(spaceItem, action_giveitem, tux, x, y, w, h); } -void -destroyItem(item_t * p) +void destroyItem(item_t * p) { - assert(p != NULL); - delID(p->id); - free(p); + assert(p != NULL); + delID(p->id); + free(p); } -void -quitItem() +void quitItem() { - isItemInit = FALSE; + isItemInit = FALSE; } diff --git a/src/base/item.h b/src/base/item.h index f007e59..5782ffa 100644 --- a/src/base/item.h +++ b/src/base/item.h @@ -1,52 +1,51 @@ #ifndef ITEM_H -#define ITEM_H -#define ITEM_SYNC_TIMEOUT 5000 -#ifdef __WIN32__ -#define random rand -#endif -#define ITEM_MAX_COUNT 1 -#define ITEM_GUN_MAX_FRAME 8 -#define ITEM_MINE_MAX_FRAME 1 -#define ITEM_EXPLOSION_MAX_FRAME 10 -#define ITEM_BONUS_MAX_FRAME 8 -#define ITEM_GUN_WIDTH 50 -#define ITEM_GUN_HEIGHT 20 -#define ITEM_MINE_WIDTH 15 -#define ITEM_MINE_HEIGHT 11 -#define ITEM_EXPLOSION_WIDTH 40 -#define ITEM_EXPLOSION_HEIGHT 40 -#define ITEM_BIG_EXPLOSION_WIDTH 100 -#define ITEM_BIG_EXPLOSION_HEIGHT 100 -#define ITEM_BONUS_WIDTH 20 -#define ITEM_BONUS_HEIGHT 20 +# define ITEM_H +# define ITEM_SYNC_TIMEOUT 5000 +# ifdef __WIN32__ +# define random rand +# endif +# define ITEM_MAX_COUNT 1 +# define ITEM_GUN_MAX_FRAME 8 +# define ITEM_MINE_MAX_FRAME 1 +# define ITEM_EXPLOSION_MAX_FRAME 10 +# define ITEM_BONUS_MAX_FRAME 8 +# define ITEM_GUN_WIDTH 50 +# define ITEM_GUN_HEIGHT 20 +# define ITEM_MINE_WIDTH 15 +# define ITEM_MINE_HEIGHT 11 +# define ITEM_EXPLOSION_WIDTH 40 +# define ITEM_EXPLOSION_HEIGHT 40 +# define ITEM_BIG_EXPLOSION_WIDTH 100 +# define ITEM_BIG_EXPLOSION_HEIGHT 100 +# define ITEM_BONUS_WIDTH 20 +# define ITEM_BONUS_HEIGHT 20 -#include "main.h" -#ifndef PUBLIC_SERVER -#include "image.h" -#endif -#include "list.h" -#include "tux.h" -#include "myTimer.h" +# include "main.h" +# ifndef PUBLIC_SERVER +# include "image.h" +# endif +# include "list.h" +# include "tux.h" +# include "myTimer.h" -typedef struct item_struct -{ - int id; - int type; // type of thing +typedef struct item_struct { + int id; + int type; // type of thing - int x; // item position - int y; + int x; // item position + int y; - int w; // item size - int h; + int w; // item size + int h; - int frame; //number of animation - int count; + int frame; //number of animation + int count; - int author_id; -#ifndef PUBLIC_SERVER - image_t *img; //picture -#endif + int author_id; +# ifndef PUBLIC_SERVER + image_t *img; //picture +# endif } item_t; extern bool_t isItemInicialized(); @@ -56,10 +55,10 @@ extern void getStatusItem(void *p, int *id, int *x, int *y, int *w, int *h); extern void setStatusItem(void *p, int x, int y, int w, int h); extern void replaceItemID(item_t * item, int id); extern void addNewItem(space_t * spaceItem, int author_id); -#ifndef PUBLIC_SERVER +# ifndef PUBLIC_SERVER extern void drawItem(item_t * p); extern void drawListItem(list_t * listItem); -#endif +# endif extern void eventListItem(space_t * listSpace); extern void eventConflictShotWithItem(arena_t * arena); extern void eventGiveTuxItem(tux_t * tux, item_t * item, space_t * spaceItem); diff --git a/src/base/list.c b/src/base/list.c index 1a5a449..d98b8d0 100644 --- a/src/base/list.c +++ b/src/base/list.c @@ -7,176 +7,164 @@ #include "main.h" #include "list.h" -list_t * -newList() +list_t *newList() { - list_t *new; + list_t *new; - new = malloc(sizeof(list_t)); - memset(new, 0, sizeof(list_t)); - return new; + new = malloc(sizeof(list_t)); + memset(new, 0, sizeof(list_t)); + return new; } -list_t * -cloneList(list_t * p) +list_t *cloneList(list_t * p) { - list_t *new; - - assert(p != NULL); - new = malloc(sizeof(list_t)); - memcpy(new, p, sizeof(list_t)); - if (p->list != NULL) { - new->list = malloc(p->alloc * sizeof(void *)); - memcpy(new->list, p->list, p->alloc * sizeof(void *)); - } - return new; + list_t *new; + + assert(p != NULL); + new = malloc(sizeof(list_t)); + memcpy(new, p, sizeof(list_t)); + if (p->list != NULL) { + new->list = malloc(p->alloc * sizeof(void *)); + memcpy(new->list, p->list, p->alloc * sizeof(void *)); + } + return new; } -list_t * -cloneListItem(list_t * p, void *f) +list_t *cloneListItem(list_t * p, void *f) { - list_t *new; - void *(*fce) (void *); - int i; - - assert(p != NULL); - assert(f != NULL); - new = cloneList(p); - fce = f; - for (i = 0; i < p->count; i++) - new->list[i] = fce(p->list[i]); - return new; + list_t *new; + void *(*fce) (void *); + int i; + + assert(p != NULL); + assert(f != NULL); + new = cloneList(p); + fce = f; + for (i = 0; i < p->count; i++) + new->list[i] = fce(p->list[i]); + return new; } -void -addList(list_t * p, void *item) +void addList(list_t * p, void *item) { - assert(p != NULL); - - if (p->alloc == 0) { - p->alloc = LIST_ALLOC_LIMIT; - p->count = 1; - p->list = malloc(p->alloc * sizeof(void *)); - p->list[0] = item; - return; - } - - if (p->count + 1 <= p->alloc) { - p->list[p->count] = item; - p->count += 1; - return; - } - - if (p->count + 1 > p->alloc) { - void **new; + assert(p != NULL); + + if (p->alloc == 0) { + p->alloc = LIST_ALLOC_LIMIT; + p->count = 1; + p->list = malloc(p->alloc * sizeof(void *)); + p->list[0] = item; + return; + } + + if (p->count + 1 <= p->alloc) { + p->list[p->count] = item; + p->count += 1; + return; + } + + if (p->count + 1 > p->alloc) { + void **new; #ifdef DEBUG_LIST - printf("Realocating from %d to %d (count=%d)\n", - p->alloc, p->alloc + LIST_ALLOC_LIMIT, p->count); + printf("Realocating from %d to %d (count=%d)\n", + p->alloc, p->alloc + LIST_ALLOC_LIMIT, p->count); #endif - p->alloc += LIST_ALLOC_LIMIT; - new = malloc(p->alloc * sizeof(void *)); - memcpy(new, p->list, p->count * sizeof(void *)); - free(p->list); - p->list = new; - p->list[p->count] = item; - p->count++; - return; - } + p->alloc += LIST_ALLOC_LIMIT; + new = malloc(p->alloc * sizeof(void *)); + memcpy(new, p->list, p->count * sizeof(void *)); + free(p->list); + p->list = new; + p->list[p->count] = item; + p->count++; + return; + } } -void -insList(list_t * p, int n, void *item) +void insList(list_t * p, int n, void *item) { - assert(p != NULL); - addList(p, NULL); // :) - assert(n >= 0 || n < p->count); - memmove(p->list + n + 1, p->list + n, - ((p->count - 1) - n) * sizeof(void *)); - p->list[n] = item; + assert(p != NULL); + addList(p, NULL); // :) + assert(n >= 0 || n < p->count); + memmove(p->list + n + 1, p->list + n, + ((p->count - 1) - n) * sizeof(void *)); + p->list[n] = item; } -void * -getList(list_t * p, int n) +void *getList(list_t * p, int n) { - assert(p != NULL); - assert(n >= 0 || n < p->count); - return p->list[n]; + assert(p != NULL); + assert(n >= 0 || n < p->count); + return p->list[n]; } -int -searchListItem(list_t * p, void *n) +int searchListItem(list_t * p, void *n) { - int i; + int i; - assert(p != NULL); - for (i = 0; i < p->count; i++) - if (p->list[i] == n) - return i; - return -1; + assert(p != NULL); + for (i = 0; i < p->count; i++) + if (p->list[i] == n) + return i; + return -1; } -void -delList(list_t * p, int n) +void delList(list_t * p, int n) { - assert(p != NULL); - assert(n >= 0 || n < p->count); - memmove(p->list + n, p->list + n + 1, - ((p->count - 1) - n) * sizeof(void *)); - p->count--; - if (p->count + LIST_ALLOC_LIMIT < p->alloc) { - void **new; + assert(p != NULL); + assert(n >= 0 || n < p->count); + memmove(p->list + n, p->list + n + 1, + ((p->count - 1) - n) * sizeof(void *)); + p->count--; + if (p->count + LIST_ALLOC_LIMIT < p->alloc) { + void **new; #ifdef DEBUG_LIST - printf("Realocating from %d to %d (count=%d)\n", - p->alloc, p->alloc - LIST_ALLOC_LIMIT, p->count); + printf("Realocating from %d to %d (count=%d)\n", + p->alloc, p->alloc - LIST_ALLOC_LIMIT, p->count); #endif - p->alloc -= LIST_ALLOC_LIMIT; - new = malloc(p->alloc * sizeof(void *)); - memcpy(new, p->list, p->count * sizeof(void *)); - free(p->list); - p->list = new; - } + p->alloc -= LIST_ALLOC_LIMIT; + new = malloc(p->alloc * sizeof(void *)); + memcpy(new, p->list, p->count * sizeof(void *)); + free(p->list); + p->list = new; + } } -void -delListItem(list_t * p, int n, void *f) +void delListItem(list_t * p, int n, void *f) { - int (*fce) (void *); - - assert(p != NULL); - assert(n >= 0 || n < p->count); - fce = f; - if (fce != NULL) - fce(p->list[n]); - delList(p, n); + int (*fce) (void *); + + assert(p != NULL); + assert(n >= 0 || n < p->count); + fce = f; + if (fce != NULL) + fce(p->list[n]); + delList(p, n); } -void -listDoEmpty(list_t * p) +void listDoEmpty(list_t * p) { - p->count = 0; + p->count = 0; } -void -destroyList(list_t * p) +void destroyList(list_t * p) { - assert(p != NULL); + assert(p != NULL); - if (p->list != NULL) - free(p->list); - free(p); + if (p->list != NULL) + free(p->list); + free(p); } -void -destroyListItem(list_t * p, void *f) +void destroyListItem(list_t * p, void *f) { - void (*fce) (void *); - int i; - - assert(p != NULL); - assert(f != NULL); - fce = f; - for (i = 0; i < p->count; i++) - fce(p->list[i]); - destroyList(p); + void (*fce) (void *); + int i; + + assert(p != NULL); + assert(f != NULL); + fce = f; + for (i = 0; i < p->count; i++) + fce(p->list[i]); + destroyList(p); } diff --git a/src/base/list.h b/src/base/list.h index e532cb2..f63628e 100644 --- a/src/base/list.h +++ b/src/base/list.h @@ -1,15 +1,14 @@ #ifndef LIST_H -#define LIST_H -#define LIST_ALLOC_LIMIT 16 +# define LIST_H +# define LIST_ALLOC_LIMIT 16 -#include "main.h" +# include "main.h" -typedef struct list_str -{ - void **list; - int count; - int alloc; +typedef struct list_str { + void **list; + int count; + int alloc; } list_t; extern list_t *newList(); diff --git a/src/base/main.c b/src/base/main.c index 4163cac..6d36cd7 100644 --- a/src/base/main.c +++ b/src/base/main.c @@ -9,151 +9,142 @@ #include <sys/stat.h> #ifdef __WIN32__ -# include <windows.h> -# include <wininet.h> +# include <windows.h> +# include <wininet.h> #endif #include "main.h" #include "tux.h" #ifndef PUBLIC_SERVER -#include "game.h" +# include "game.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif static int my_argc; static char **my_argv; -char * -getParam(char *s) +char *getParam(char *s) { - int i; - int len; + int i; + int len; - len = strlen(s); + len = strlen(s); - for (i = 1; i < my_argc; i++) { - //printf("%s %s\n", s, my_argv[i]); + for (i = 1; i < my_argc; i++) { + //printf("%s %s\n", s, my_argv[i]); - if (strlen(my_argv[i]) < len) { - continue; - } + if (strlen(my_argv[i]) < len) { + continue; + } - if (strncmp(s, my_argv[i], len) == 0) { - return strchr(my_argv[i], '=') + 1; - } - } + if (strncmp(s, my_argv[i], len) == 0) { + return strchr(my_argv[i], '=') + 1; + } + } - return NULL; + return NULL; } -char * -getParamElse(char *s1, char *s2) +char *getParamElse(char *s1, char *s2) { - char *ret; - ret = getParam(s1); + char *ret; + ret = getParam(s1); - if (ret == NULL) { - return s2; - } + if (ret == NULL) { + return s2; + } - return ret; + return ret; } -bool_t -isParamFlag(char *s) +bool_t isParamFlag(char *s) { - int i; + int i; - for (i = 0; i < my_argc; i++) { - if (strcmp(s, my_argv[i]) == 0) { - return TRUE; - } - } + for (i = 0; i < my_argc; i++) { + if (strcmp(s, my_argv[i]) == 0) { + return TRUE; + } + } - return FALSE; + return FALSE; } -char * -getString(int n) +char *getString(int n) { - char str[STR_NUM_SIZE]; - sprintf(str, "%d", n); - return strdup(str); + char str[STR_NUM_SIZE]; + sprintf(str, "%d", n); + return strdup(str); } -int * -newInt(int x) +int *newInt(int x) { - int *new; - new = malloc(sizeof(int)); - *new = x; - return new; + int *new; + new = malloc(sizeof(int)); + *new = x; + return new; } -void -accessExistFile(const char *s) +void accessExistFile(const char *s) { - if (access(s, F_OK) != 0) { - fprintf(stderr, _("File %s not found !\nProgram shutdown !\n"), s); - exit(-1); - } + if (access(s, F_OK) != 0) { + fprintf(stderr, _("File %s not found !\nProgram shutdown !\n"), s); + exit(-1); + } } -int -tryExistFile(const char *s) +int tryExistFile(const char *s) { - if (access(s, F_OK) != 0) - return 1; - else - return 0; + if (access(s, F_OK) != 0) + return 1; + else + return 0; } -int -isFillPath(const char *path) +int isFillPath(const char *path) { - assert(path != NULL); + assert(path != NULL); #ifndef __WIN32__ - if (path[0] == '/') // for Unix-like systems ;) + if (path[0] == '/') // for Unix-like systems ;) #else - if (path[1] == ':') // for Windows-like systems ;) + if (path[1] == ':') // for Windows-like systems ;) #endif - { - return 1; - } + { + return 1; + } - return 0; + return 0; } #ifdef __WIN32__ int WINAPI WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) + HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #else -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) #endif { #ifndef __WIN32__ - signal(SIGPIPE, SIG_IGN); + signal(SIGPIPE, SIG_IGN); #endif - srand((unsigned) time(NULL)); + srand((unsigned) time(NULL)); #ifdef NLS - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, PATH_LOCALE); - bind_textdomain_codeset(PACKAGE, "UTF-8"); - textdomain(PACKAGE); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, PATH_LOCALE); + bind_textdomain_codeset(PACKAGE, "UTF-8"); + textdomain(PACKAGE); #endif #ifndef __WIN32__ - my_argc = argc; - my_argv = argv; + my_argc = argc; + my_argv = argv; #endif /* test_space(); @@ -161,24 +152,24 @@ main(int argc, char *argv[]) */ #ifdef __WIN32__ - WORD wVersionRequested = MAKEWORD(1, 1); // WinSock version - WSADATA data; // WinSock information structure - - /* Let's initialize WinSock */ - if (WSAStartup(wVersionRequested, &data) != 0) { - fprintf(stderr, - _("WinSock initialization failed !\nProgram shutdown !\n")); - exit(-1); - } + WORD wVersionRequested = MAKEWORD(1, 1); // WinSock version + WSADATA data; // WinSock information structure + + /* Let's initialize WinSock */ + if (WSAStartup(wVersionRequested, &data) != 0) { + fprintf(stderr, + _("WinSock initialization failed !\nProgram shutdown !\n")); + exit(-1); + } #endif #ifndef PUBLIC_SERVER - startGame(); + startGame(); #endif #ifdef PUBLIC_SERVER - startPublicServer(); + startPublicServer(); #endif - return 0; + return 0; } diff --git a/src/base/main.h b/src/base/main.h index 9b0f59c..a8b5f7b 100644 --- a/src/base/main.h +++ b/src/base/main.h @@ -1,21 +1,21 @@ #ifndef MAIN_H -#define MAIN_H -#define WINDOW_SIZE_X 800 -#define WINDOW_SIZE_Y 600 -#ifdef NLS -#define _(text) gettext(text) -#else -#define _(text) (text) -#endif +# define MAIN_H +# define WINDOW_SIZE_X 800 +# define WINDOW_SIZE_Y 600 +# ifdef NLS +# define _(text) gettext(text) +# else +# define _(text) (text) +# endif -#ifdef NLS -#include <libintl.h> -#include <locale.h> -#endif -#include "bool.h" -#include "string_length.h" -#include "path.h" +# ifdef NLS +# include <libintl.h> +# include <locale.h> +# endif +# include "bool.h" +# include "string_length.h" +# include "path.h" extern char *getParam(char *s); extern char *getParamElse(char *s1, char *s2); diff --git a/src/base/modules.c b/src/base/modules.c index 6248e8a..149a92f 100644 --- a/src/base/modules.c +++ b/src/base/modules.c @@ -3,7 +3,7 @@ #include <stdlib.h> #include <string.h> #ifndef __WIN32__ -#include <dlfcn.h> +# include <dlfcn.h> #endif #include <assert.h> @@ -17,298 +17,282 @@ #include "proto.h" #include "shareFunction.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" -#include "layer.h" -#include "configFile.h" +# include "interface.h" +# include "image.h" +# include "layer.h" +# include "configFile.h" #endif static export_fce_t export_fce = { #ifndef PUBLIC_SERVER - .fce_addLayer = addLayer, - .fce_getImage = getImage, + .fce_addLayer = addLayer, + .fce_getImage = getImage, #endif - .fce_loadDepModule = loadDepModule, - .fce_addToShareFce = addToShareFce, - .fce_getShareFce = getShareFce, + .fce_loadDepModule = loadDepModule, + .fce_addToShareFce = addToShareFce, + .fce_getShareFce = getShareFce, - .fce_getValue = getArenaValue, - .fce_getNetTypeGame = getNetTypeGame, - .fce_getTuxProportion = getTuxProportion, - .fce_setTuxProportion = setTuxProportion, - .fce_actionTux = actionTux, + .fce_getValue = getArenaValue, + .fce_getNetTypeGame = getNetTypeGame, + .fce_getTuxProportion = getTuxProportion, + .fce_setTuxProportion = setTuxProportion, + .fce_actionTux = actionTux, - .fce_getMyTime = getMyTime, + .fce_getMyTime = getMyTime, - .fce_getCurrentArena = getCurrentArena, - .fce_conflictSpace = conflictSpace, - .fce_isFreeSpace = isFreeSpace, - .fce_findFreeSpace = findFreeSpace, + .fce_getCurrentArena = getCurrentArena, + .fce_conflictSpace = conflictSpace, + .fce_isFreeSpace = isFreeSpace, + .fce_findFreeSpace = findFreeSpace, - .fce_proto_send_module_server = proto_send_module_server, + .fce_proto_send_module_server = proto_send_module_server, #ifndef PUBLIC_SERVER - .fce_proto_send_module_client = proto_send_module_client, + .fce_proto_send_module_client = proto_send_module_client, #endif - .fce_destroyShot = destroyShot, - .fce_boundBombBall = boundBombBall, - .fce_transformOnlyLasser = transformOnlyLasser + .fce_destroyShot = destroyShot, + .fce_boundBombBall = boundBombBall, + .fce_transformOnlyLasser = transformOnlyLasser }; static list_t *listModule; -static void * -getFce(module_t * p, char *s) +static void *getFce(module_t * p, char *s) { #ifndef __WIN32__ - void *ret; - char *error; - - assert(p != NULL); - assert(s != NULL); - ret = dlsym(p->image, s); - - if ((error = dlerror()) != NULL) { - fprintf(stderr, _("Error %s occured when using getFce function!\n"), - error); - return NULL; - } + void *ret; + char *error; + + assert(p != NULL); + assert(s != NULL); + ret = dlsym(p->image, s); + + if ((error = dlerror()) != NULL) { + fprintf(stderr, _("Error %s occured when using getFce function!\n"), + error); + return NULL; + } #else - FARPROC ret = GetProcAddress((HMODULE) p->image, (LPCSTR) s); - if (!ret) - fprintf(stderr, _("Error %s occured when using getFce function!\n"), - s); + FARPROC ret = GetProcAddress((HMODULE) p->image, (LPCSTR) s); + if (!ret) + fprintf(stderr, _("Error %s occured when using getFce function!\n"), + s); #endif - return (void *) ret; + return (void *) ret; } -static void * -mapImage(char *name) +static void *mapImage(char *name) { #ifndef __WIN32__ - void *image; - image = dlopen(name, RTLD_LAZY); - if (image == NULL) { - fputs(dlerror(), stderr); - return NULL; - } + void *image; + image = dlopen(name, RTLD_LAZY); + if (image == NULL) { + fputs(dlerror(), stderr); + return NULL; + } #else - HINSTANCE image; - image = LoadLibrary((LPCSTR) name); - - if (!image) { - LPVOID msg; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) & msg, 0, NULL); - fputs(msg, stderr); - free(msg); - FreeLibrary(image); - return NULL; - } - //FreeLibrary(image); //never ever untag this + HINSTANCE image; + image = LoadLibrary((LPCSTR) name); + + if (!image) { + LPVOID msg; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) & msg, 0, NULL); + fputs(msg, stderr); + free(msg); + FreeLibrary(image); + return NULL; + } + //FreeLibrary(image); //never ever untag this #endif - return image; + return image; } -static void -unmapImage(void *image) +static void unmapImage(void *image) { #ifndef __WIN32__ - dlclose(image); + dlclose(image); #else - FreeLibrary(image); + FreeLibrary(image); #endif } -static void -setModulePath(char *name, char *path) +static void setModulePath(char *name, char *path) { - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); // linux + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); // linux #ifdef __WIN32__ - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows #endif #ifdef APPLE - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); // apple + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); // apple #endif } -static module_t * -newModule(char *name) +static module_t *newModule(char *name) { - char path[STR_PATH_SIZE]; - void *image; - module_t *ret; - - assert(name != NULL); - setModulePath(name, path); - image = mapImage(path); - if (image == NULL) { - fprintf(stderr, _("Unable to map file %s!\n"), name); - return NULL; - } - ret = malloc(sizeof(module_t)); - ret->image = image; - ret->name = strdup(name); - ret->fce_init = getFce(ret, "init"); + char path[STR_PATH_SIZE]; + void *image; + module_t *ret; + + assert(name != NULL); + setModulePath(name, path); + image = mapImage(path); + if (image == NULL) { + fprintf(stderr, _("Unable to map file %s!\n"), name); + return NULL; + } + ret = malloc(sizeof(module_t)); + ret->image = image; + ret->name = strdup(name); + ret->fce_init = getFce(ret, "init"); #ifndef PUBLIC_SERVER - ret->fce_draw = getFce(ret, "draw"); + ret->fce_draw = getFce(ret, "draw"); #endif - ret->fce_event = getFce(ret, "event"); - ret->fce_destroy = getFce(ret, "destroy"); - ret->fce_isConflict = getFce(ret, "isConflict"); - ret->fce_cmd = getFce(ret, "cmdArena"); - ret->fce_recvMsg = getFce(ret, "recvMsg"); + ret->fce_event = getFce(ret, "event"); + ret->fce_destroy = getFce(ret, "destroy"); + ret->fce_isConflict = getFce(ret, "isConflict"); + ret->fce_cmd = getFce(ret, "cmdArena"); + ret->fce_recvMsg = getFce(ret, "recvMsg"); #ifdef DEBUG - printf(_("Loading module: \"%s\"\n"), name); + printf(_("Loading module: \"%s\"\n"), name); #endif - if (ret->fce_init(&export_fce) != 0) { - fprintf(stderr, _("Failed initialization of module \"%s\""), name); - unmapImage(image); - free(ret->name); - free(ret); - return NULL; - } - return ret; + if (ret->fce_init(&export_fce) != 0) { + fprintf(stderr, _("Failed initialization of module \"%s\""), name); + unmapImage(image); + free(ret->name); + free(ret); + return NULL; + } + return ret; } -static int -destroyModule(module_t * p) +static int destroyModule(module_t * p) { - assert(p != NULL); - p->fce_destroy(); - unmapImage(p->image); - free(p->name); - free(p); + assert(p != NULL); + p->fce_destroy(); + unmapImage(p->image); + free(p->name); + free(p); #ifdef DEBUG - printf(_("Destroing module...\n")); + printf(_("Destroing module...\n")); #endif - return 0; + return 0; } -void -initModule() +void initModule() { - listModule = newList(); - initShareFunction(); + listModule = newList(); + initShareFunction(); } -int -isModuleLoaded(char *name) +int isModuleLoaded(char *name) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; + for (i = 0; i < listModule->count; i++) { + module_t *this; - this = (module_t *) listModule->list[i]; - if (strcmp(this->name, name) == 0) - return 1; - } - return 0; + this = (module_t *) listModule->list[i]; + if (strcmp(this->name, name) == 0) + return 1; + } + return 0; } -int -loadModule(char *name) +int loadModule(char *name) { - module_t *module; - - if (isModuleLoaded(name)) { - fprintf(stderr, - _ - ("I've done this once, dont want to mess memory with module %s again!\n"), - name); - return -1; - } - module = newModule(name); - if (module == NULL) { - fprintf(stderr, _("Loading module %s failed!\n"), name); - return -1; - } - addList(listModule, module); - return 0; + module_t *module; + + if (isModuleLoaded(name)) { + fprintf(stderr, + _ + ("I've done this once, dont want to mess memory with module %s again!\n"), + name); + return -1; + } + module = newModule(name); + if (module == NULL) { + fprintf(stderr, _("Loading module %s failed!\n"), name); + return -1; + } + addList(listModule, module); + return 0; } -int -loadDepModule(char *name) +int loadDepModule(char *name) { - if (isModuleLoaded(name)) - return 0; - return loadModule(name); + if (isModuleLoaded(name)) + return 0; + return loadModule(name); } -void -cmdModule(char *s) +void cmdModule(char *s) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; - this = (module_t *) listModule->list[i]; - this->fce_cmd(s); - } + for (i = 0; i < listModule->count; i++) { + module_t *this; + this = (module_t *) listModule->list[i]; + this->fce_cmd(s); + } } #ifndef PUBLIC_SERVER -void -drawModule(int x, int y, int w, int h) +void drawModule(int x, int y, int w, int h) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; - this = (module_t *) listModule->list[i]; - this->fce_draw(x, y, w, h); - } + for (i = 0; i < listModule->count; i++) { + module_t *this; + this = (module_t *) listModule->list[i]; + this->fce_draw(x, y, w, h); + } } #endif -void -eventModule() +void eventModule() { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; - this = (module_t *) listModule->list[i]; - this->fce_event(); - } + for (i = 0; i < listModule->count; i++) { + module_t *this; + this = (module_t *) listModule->list[i]; + this->fce_event(); + } } -int -isConflictModule(int x, int y, int w, int h) +int isConflictModule(int x, int y, int w, int h) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; + for (i = 0; i < listModule->count; i++) { + module_t *this; - this = (module_t *) listModule->list[i]; - if (this->fce_isConflict(x, y, w, h) == 1) - return 1; - } - return 0; + this = (module_t *) listModule->list[i]; + if (this->fce_isConflict(x, y, w, h) == 1) + return 1; + } + return 0; } -int -recvMsgModule(char *msg) +int recvMsgModule(char *msg) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; + for (i = 0; i < listModule->count; i++) { + module_t *this; - this = (module_t *) listModule->list[i]; - this->fce_recvMsg(msg); - } - return 0; + this = (module_t *) listModule->list[i]; + this->fce_recvMsg(msg); + } + return 0; } -void -quitModule() +void quitModule() { - destroyListItem(listModule, destroyModule); - quitShareFunction(); + destroyListItem(listModule, destroyModule); + quitShareFunction(); } diff --git a/src/base/modules.h b/src/base/modules.h index f0cbfb1..a22c972 100644 --- a/src/base/modules.h +++ b/src/base/modules.h @@ -1,88 +1,85 @@ #ifndef MODULE_H -#define MODULE_H - -#include "tux.h" -#include "shot.h" -#include "arena.h" -#include "proto.h" -#include "myTimer.h" - -#ifndef PUBLIC_SERVER -#include "image.h" -#endif - -#define MODULE_TYPE_UNIX ".so" -#define MODULE_TYPE_APPLE ".dylib" -#define MODULE_TYPE_WIN ".dll" - -typedef struct export_fce_s -{ - int (*fce_getValue) (char *line, char *env, char *val, int len); - -#ifndef PUBLIC_SERVER - image_t *(*fce_getImage) (char *group, char *name); - - void (*fce_addLayer) (image_t * img, - int x, int y, int px, int py, - int w, int h, int player); -#endif - - int (*fce_getNetTypeGame) (); - int (*fce_loadDepModule) (char *name); - void (*fce_addToShareFce) (char *name, void *function); - void *(*fce_getShareFce) (char *name); - - void (*fce_getTuxProportion) (tux_t * tux, int *x, int *y, int *w, - int *h); - void (*fce_setTuxProportion) (tux_t * tux, int x, int y); - tux_t *(*fce_getTuxID) (list_t * listTux, int id); - void (*fce_actionTux) (tux_t * tux, int action); - - arena_t *(*fce_getCurrentArena) (); - int (*fce_conflictSpace) (int x1, int y1, int w1, int h1, int x2, int y2, - int w2, int h2); - int (*fce_isFreeSpace) (arena_t * arena, int x, int y, int w, int h); - void (*fce_findFreeSpace) (arena_t * arena, int *x, int *y, int w, int h); - void (*fce_proto_send_module_server) (int type, client_t * client, - char *msg); - void (*fce_proto_send_module_client) (char *msg); - - my_time_t(*fce_getMyTime) (); - - void (*fce_destroyShot) (shot_t * p); - void (*fce_boundBombBall) (shot_t * shot); - void (*fce_transformOnlyLasser) (shot_t * shot); +# define MODULE_H + +# include "tux.h" +# include "shot.h" +# include "arena.h" +# include "proto.h" +# include "myTimer.h" + +# ifndef PUBLIC_SERVER +# include "image.h" +# endif + +# define MODULE_TYPE_UNIX ".so" +# define MODULE_TYPE_APPLE ".dylib" +# define MODULE_TYPE_WIN ".dll" + +typedef struct export_fce_s { + int (*fce_getValue) (char *line, char *env, char *val, int len); + +# ifndef PUBLIC_SERVER + image_t *(*fce_getImage) (char *group, char *name); + + void (*fce_addLayer) (image_t * img, + int x, int y, int px, int py, + int w, int h, int player); +# endif + + int (*fce_getNetTypeGame) (); + int (*fce_loadDepModule) (char *name); + void (*fce_addToShareFce) (char *name, void *function); + void *(*fce_getShareFce) (char *name); + + void (*fce_getTuxProportion) (tux_t * tux, int *x, int *y, int *w, int *h); + void (*fce_setTuxProportion) (tux_t * tux, int x, int y); + tux_t *(*fce_getTuxID) (list_t * listTux, int id); + void (*fce_actionTux) (tux_t * tux, int action); + + arena_t *(*fce_getCurrentArena) (); + int (*fce_conflictSpace) (int x1, int y1, int w1, int h1, int x2, int y2, + int w2, int h2); + int (*fce_isFreeSpace) (arena_t * arena, int x, int y, int w, int h); + void (*fce_findFreeSpace) (arena_t * arena, int *x, int *y, int w, int h); + void (*fce_proto_send_module_server) (int type, client_t * client, + char *msg); + void (*fce_proto_send_module_client) (char *msg); + + my_time_t(*fce_getMyTime) (); + + void (*fce_destroyShot) (shot_t * p); + void (*fce_boundBombBall) (shot_t * shot); + void (*fce_transformOnlyLasser) (shot_t * shot); } export_fce_t; -typedef struct module_s -{ - char *name; -#ifndef __WIN32__ - void *image; -#else - HINSTANCE *image; -#endif - - int (*fce_init) (export_fce_t * p); -#ifndef PUBLIC_SERVER - int (*fce_draw) (int x, int y, int w, int h); -#endif - int (*fce_event) (); - int (*fce_isConflict) (int x, int y, int w, int h); - void (*fce_cmd) (char *line); - void (*fce_recvMsg) (char *msg); - int (*fce_destroy) (); +typedef struct module_s { + char *name; +# ifndef __WIN32__ + void *image; +# else + HINSTANCE *image; +# endif + + int (*fce_init) (export_fce_t * p); +# ifndef PUBLIC_SERVER + int (*fce_draw) (int x, int y, int w, int h); +# endif + int (*fce_event) (); + int (*fce_isConflict) (int x, int y, int w, int h); + void (*fce_cmd) (char *line); + void (*fce_recvMsg) (char *msg); + int (*fce_destroy) (); } module_t; extern void initModule(); extern int loadModule(char *name); extern int loadDepModule(char *name); -#ifndef PUBLIC_SERVER +# ifndef PUBLIC_SERVER extern void drawModule(int x, int y, int w, int h); -#endif +# endif extern void eventModule(); extern void cmdModule(char *s); extern int isConflictModule(int x, int y, int w, int h); diff --git a/src/base/myTimer.c b/src/base/myTimer.c index fa2ba12..08abb99 100644 --- a/src/base/myTimer.c +++ b/src/base/myTimer.c @@ -6,149 +6,141 @@ #include <sys/time.h> #include <signal.h> #ifdef __WIN32__ -#include <time.h> +# include <time.h> #endif #include "main.h" #include "list.h" #include "myTimer.h" #ifndef PUBLIC_SERVER -#include "interface.h" +# include "interface.h" #endif static struct timeval start = {.tv_sec = 0,.tv_usec = 0 }; -list_t * -newTimer() +list_t *newTimer() { - return newList(); + return newList(); } -void -restartTimer() +void restartTimer() { - gettimeofday(&start, NULL); + gettimeofday(&start, NULL); } -my_time_t -getMyTime() +my_time_t getMyTime() { - struct timeval now; - my_time_t ticks; - - if (start.tv_sec == 0 && start.tv_usec == 0) - restartTimer(); - gettimeofday(&now, NULL); - ticks = - (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - - start.tv_usec) / 1000; - //printf("-> %d\n", ticks); - return ticks; + struct timeval now; + my_time_t ticks; + + if (start.tv_sec == 0 && start.tv_usec == 0) + restartTimer(); + gettimeofday(&now, NULL); + ticks = + (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - + start.tv_usec) / 1000; + //printf("-> %d\n", ticks); + return ticks; } -my_time_t -getMyTimeMicro() +my_time_t getMyTimeMicro() { - static struct timeval start = {.tv_sec = 0,.tv_usec = 0 }; - struct timeval now; - my_time_t ticks; - if (start.tv_sec == 0 && start.tv_usec == 0) - gettimeofday(&start, NULL); - gettimeofday(&now, NULL); - ticks = - (now.tv_sec - start.tv_sec) * 1000 * 1000 + (now.tv_usec - - start.tv_usec); - //printf("-> %d\n", ticks); - return ticks; + static struct timeval start = {.tv_sec = 0,.tv_usec = 0 }; + struct timeval now; + my_time_t ticks; + if (start.tv_sec == 0 && start.tv_usec == 0) + gettimeofday(&start, NULL); + gettimeofday(&now, NULL); + ticks = + (now.tv_sec - start.tv_sec) * 1000 * 1000 + (now.tv_usec - + start.tv_usec); + //printf("-> %d\n", ticks); + return ticks; } -my_timer_t * -newTimerItem(int type, void (*fce) (void *p), void *arg, my_time_t my_time) +my_timer_t *newTimerItem(int type, void (*fce) (void *p), void *arg, + my_time_t my_time) { - static int new_id = 0; - my_timer_t *new; - assert(fce != NULL); - new = malloc(sizeof(my_timer_t)); - memset(new, 0, sizeof(my_timer_t)); - new->id = new_id++; - new->type = type; - new->fce = fce; - new->arg = arg; - new->createTime = getMyTime(); - new->time = my_time; - return new; + static int new_id = 0; + my_timer_t *new; + assert(fce != NULL); + new = malloc(sizeof(my_timer_t)); + memset(new, 0, sizeof(my_timer_t)); + new->id = new_id++; + new->type = type; + new->fce = fce; + new->arg = arg; + new->createTime = getMyTime(); + new->time = my_time; + return new; } -static void -destroyTimerItem(my_timer_t * p) +static void destroyTimerItem(my_timer_t * p) { - assert(p != NULL); - free(p); + assert(p != NULL); + free(p); } int addTaskToTimer(list_t * listTimer, int type, void (*fce) (void *p), void *arg, - my_time_t my_time) + my_time_t my_time) { - my_timer_t *new; + my_timer_t *new; - new = newTimerItem(type, fce, arg, my_time); - addList(listTimer, new); - return new->id; + new = newTimerItem(type, fce, arg, my_time); + addList(listTimer, new); + return new->id; } -void -eventTimer(list_t * listTimer) +void eventTimer(list_t * listTimer) { - int i; - my_timer_t *thisTimer; - my_time_t currentTime; - currentTime = getMyTime(); - for (i = 0; i < listTimer->count; i++) { - thisTimer = (my_timer_t *) listTimer->list[i]; - assert(thisTimer != NULL); - switch (thisTimer->type) { - case TIMER_ONE: - if (currentTime >= thisTimer->createTime + thisTimer->time) { - thisTimer->fce(thisTimer->arg); - delListItem(listTimer, i, free); - i--; - } - break; - case TIMER_PERIODIC: - if (currentTime >= thisTimer->createTime + thisTimer->time) { - thisTimer->fce(thisTimer->arg); - thisTimer->createTime = getMyTime(); - } - break; - default: - assert(!_("Timer is really weirdly set!")); - break; - } - } + int i; + my_timer_t *thisTimer; + my_time_t currentTime; + currentTime = getMyTime(); + for (i = 0; i < listTimer->count; i++) { + thisTimer = (my_timer_t *) listTimer->list[i]; + assert(thisTimer != NULL); + switch (thisTimer->type) { + case TIMER_ONE: + if (currentTime >= thisTimer->createTime + thisTimer->time) { + thisTimer->fce(thisTimer->arg); + delListItem(listTimer, i, free); + i--; + } + break; + case TIMER_PERIODIC: + if (currentTime >= thisTimer->createTime + thisTimer->time) { + thisTimer->fce(thisTimer->arg); + thisTimer->createTime = getMyTime(); + } + break; + default: + assert(!_("Timer is really weirdly set!")); + break; + } + } } -void -delTimer(list_t * listTimer, int id) +void delTimer(list_t * listTimer, int id) { - int i; - my_timer_t *thisTimer; - - for (i = 0; i < listTimer->count; i++) { - thisTimer = (my_timer_t *) listTimer->list[i]; - assert(thisTimer != NULL); - if (thisTimer->id == id) { - delListItem(listTimer, i, free); - return; - } - } - assert(!_("There is no such ID!")); + int i; + my_timer_t *thisTimer; + + for (i = 0; i < listTimer->count; i++) { + thisTimer = (my_timer_t *) listTimer->list[i]; + assert(thisTimer != NULL); + if (thisTimer->id == id) { + delListItem(listTimer, i, free); + return; + } + } + assert(!_("There is no such ID!")); } -void -destroyTimer(list_t * listTimer) +void destroyTimer(list_t * listTimer) { - destroyListItem(listTimer, destroyTimerItem); + destroyListItem(listTimer, destroyTimerItem); } diff --git a/src/base/myTimer.h b/src/base/myTimer.h index 548a883..66a5e67 100644 --- a/src/base/myTimer.h +++ b/src/base/myTimer.h @@ -1,28 +1,27 @@ #ifndef MY_TIME_H -#define MY_TIME_H -#define my_time_t unsigned int -#define TIMER_ONE 0 -#define TIMER_PERIODIC 1 +# define MY_TIME_H +# define my_time_t unsigned int +# define TIMER_ONE 0 +# define TIMER_PERIODIC 1 -#include "main.h" -#include "list.h" +# include "main.h" +# include "list.h" -typedef struct my_timer_struct -{ - unsigned int id; - void (*fce) (void *p); - void *arg; - int type; - my_time_t createTime; - my_time_t time; +typedef struct my_timer_struct { + unsigned int id; + void (*fce) (void *p); + void *arg; + int type; + my_time_t createTime; + my_time_t time; } my_timer_t; extern list_t *newTimer(); extern void restartTimer(); extern my_time_t getMyTime(); extern int addTaskToTimer(list_t * listTimer, int type, void (*fce) (void *p), - void *arg, my_time_t my_time); + void *arg, my_time_t my_time); extern void eventTimer(list_t * listTimer); extern void delTimer(list_t * listTimer, int id); extern void destroyTimer(list_t * listTimer); diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c index bfd4f94..d967413 100644 --- a/src/base/net_multiplayer.c +++ b/src/base/net_multiplayer.c @@ -15,125 +15,120 @@ #include "udp.h" #ifndef PUBLIC_SERVER -#include "screen_setting.h" -#include "screen_choiceArena.h" +# include "screen_setting.h" +# include "screen_choiceArena.h" -#include "screen.h" -#include "client.h" +# include "screen.h" +# include "client.h" #endif static int netGameType; -int -getNetTypeGame() +int getNetTypeGame() { - return netGameType; + return netGameType; } -int -initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, int port6) +int initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - ret = initServer(ip4, port4, ip6, port6); + ret = initServer(ip4, port4, ip6, port6); - if (ret > 0) { - netGameType = NET_GAME_TYPE_SERVER; - } + if (ret > 0) { + netGameType = NET_GAME_TYPE_SERVER; + } - return ret; + return ret; } -int -initNetMuliplayer(int type, char *ip, int port, int proto) +int initNetMuliplayer(int type, char *ip, int port, int proto) { - netGameType = type; - - switch (netGameType) { - case NET_GAME_TYPE_NONE: - break; - - case NET_GAME_TYPE_SERVER: - switch (proto) { - case PROTO_UDPv4: - if (initServer(ip, port, NULL, 0) != 1) { - fprintf(stderr, - _("Unable to inicialize network game as server!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; - case PROTO_UDPv6: - if (initServer(NULL, 0, ip, port) != 1) { - fprintf(stderr, - _("Unable to inicialize network game as server!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; - } - break; + netGameType = type; + + switch (netGameType) { + case NET_GAME_TYPE_NONE: + break; + + case NET_GAME_TYPE_SERVER: + switch (proto) { + case PROTO_UDPv4: + if (initServer(ip, port, NULL, 0) != 1) { + fprintf(stderr, + _("Unable to inicialize network game as server!\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; + case PROTO_UDPv6: + if (initServer(NULL, 0, ip, port) != 1) { + fprintf(stderr, + _("Unable to inicialize network game as server!\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; + } + break; #ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT: - if (initClient(ip, port, proto) != 0) { - fprintf(stderr, - _("Unable to inicialize network game as client!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; + case NET_GAME_TYPE_CLIENT: + if (initClient(ip, port, proto) != 0) { + fprintf(stderr, + _("Unable to inicialize network game as client!\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; #endif - default: - assert(!_("Variable netGameType has a really weird value!")); - break; - } + default: + assert(!_("Variable netGameType has a really weird value!")); + break; + } - return 0; + return 0; } -void -eventNetMultiplayer() +void eventNetMultiplayer() { - switch (netGameType) { - case NET_GAME_TYPE_NONE: - break; + switch (netGameType) { + case NET_GAME_TYPE_NONE: + break; - case NET_GAME_TYPE_SERVER: - eventServer(); - break; + case NET_GAME_TYPE_SERVER: + eventServer(); + break; #ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT: - eventClient(); - break; + case NET_GAME_TYPE_CLIENT: + eventClient(); + break; #endif - default: - assert(!_("Variable netGameType has a really weird value!")); - break; - } + default: + assert(!_("Variable netGameType has a really weird value!")); + break; + } } -void -quitNetMultiplayer() +void quitNetMultiplayer() { - switch (netGameType) { - case NET_GAME_TYPE_NONE: - break; + switch (netGameType) { + case NET_GAME_TYPE_NONE: + break; - case NET_GAME_TYPE_SERVER: - quitServer(); - break; + case NET_GAME_TYPE_SERVER: + quitServer(); + break; #ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT: - quitClient(); - break; + case NET_GAME_TYPE_CLIENT: + quitClient(); + break; #endif - default: - assert(!_("Variable netGameType has a really weird value!")); - break; - } + default: + assert(!_("Variable netGameType has a really weird value!")); + break; + } - netGameType = NET_GAME_TYPE_NONE; + netGameType = NET_GAME_TYPE_NONE; } diff --git a/src/base/net_multiplayer.h b/src/base/net_multiplayer.h index d92d3e5..f9118b1 100644 --- a/src/base/net_multiplayer.h +++ b/src/base/net_multiplayer.h @@ -1,36 +1,36 @@ #ifndef NET_MULTIPLAYER_H -#define NET_MULTIPLAYER_H +# define NET_MULTIPLAYER_H -#include "main.h" -#include "tux.h" -#include "item.h" -#include "arena.h" +# include "main.h" +# include "tux.h" +# include "item.h" +# include "arena.h" -#define PROTO_UDPv4 0 -#define PROTO_UDPv6 1 +# define PROTO_UDPv4 0 +# define PROTO_UDPv6 1 -#define NET_GAME_TYPE_NONE 0 -#define NET_GAME_TYPE_SERVER 1 -#define NET_GAME_TYPE_CLIENT 2 +# define NET_GAME_TYPE_NONE 0 +# define NET_GAME_TYPE_SERVER 1 +# define NET_GAME_TYPE_CLIENT 2 -#define NET_STATUS_OK 0 -#define NET_STATUS_ZOMBIE 1 +# define NET_STATUS_OK 0 +# define NET_STATUS_ZOMBIE 1 -#define NET_PROTOCOL_TYPE_TCP 0 -#define NET_PROTOCOL_TYPE_UDP 1 +# define NET_PROTOCOL_TYPE_TCP 0 +# define NET_PROTOCOL_TYPE_UDP 1 -#define LIMIT_BUFFER 10240 +# define LIMIT_BUFFER 10240 -#define NET_MASTER_SERVER_DOMAIN "ms.tuxanci.org" -#define NET_MASTER_SERVER "193.85.244.165" -#define NET_MASTER_PORT 2200 +# define NET_MASTER_SERVER_DOMAIN "ms.tuxanci.org" +# define NET_MASTER_SERVER "193.85.244.165" +# define NET_MASTER_PORT 2200 -#ifdef PUBLIC_SERVER +# ifdef PUBLIC_SERVER extern int initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, - int port6); -#endif + int port6); +# endif extern int initNetMuliplayer(int type, char *ip, int port, int proto); extern int getNetTypeGame(); diff --git a/src/base/protect.c b/src/base/protect.c index acfc1e3..e06c618 100644 --- a/src/base/protect.c +++ b/src/base/protect.c @@ -8,72 +8,67 @@ #include "myTimer.h" #include "protect.h" -protect_t * -newProtect() +protect_t *newProtect() { - protect_t *new; - new = malloc(sizeof(protect_t)); - new->lastMove = getMyTime(); - new->lastPing = getMyTime(); - new->avarage = 0; - new->count = 0; - new->isDown = FALSE; - return new; + protect_t *new; + new = malloc(sizeof(protect_t)); + new->lastMove = getMyTime(); + new->lastPing = getMyTime(); + new->avarage = 0; + new->count = 0; + new->isDown = FALSE; + return new; } -void -refreshLastMove(protect_t * p) +void refreshLastMove(protect_t * p) { - my_time_t currentTime; - my_time_t interval; + my_time_t currentTime; + my_time_t interval; - currentTime = getMyTime(); - interval = currentTime - p->lastMove; - p->lastMove = getMyTime(); - p->avarage += interval; - p->count++; - if (p->count == PROTECT_SPEED_AVARAGE) { - int index; + currentTime = getMyTime(); + interval = currentTime - p->lastMove; + p->lastMove = getMyTime(); + p->avarage += interval; + p->count++; + if (p->count == PROTECT_SPEED_AVARAGE) { + int index; - index = p->avarage / PROTECT_SPEED_AVARAGE; - p->avarage = 0; - p->count = 0; + index = p->avarage / PROTECT_SPEED_AVARAGE; + p->avarage = 0; + p->count = 0; #if 0 - if (index < PROTECT_SPEED_INTERVAL_TIMEOUT) { - p->isDown = TRUE; - } + if (index < PROTECT_SPEED_INTERVAL_TIMEOUT) { + p->isDown = TRUE; + } #endif - //printf("speed index = %d\n", index); - } + //printf("speed index = %d\n", index); + } } -void -rereshLastPing(protect_t * p) +void rereshLastPing(protect_t * p) { - //my_time_t currentTime; - //my_time_t interval; - //currentTime = getMyTime(); - //interval = currentTime - p->lastPing; - p->lastPing = getMyTime(); - //printf("interval = %d\n", interval); + //my_time_t currentTime; + //my_time_t interval; + //currentTime = getMyTime(); + //interval = currentTime - p->lastPing; + p->lastPing = getMyTime(); + //printf("interval = %d\n", interval); } -bool_t -isDown(protect_t * p) +bool_t isDown(protect_t * p) { - my_time_t currentTime; - my_time_t interval; + my_time_t currentTime; + my_time_t interval; - currentTime = getMyTime(); - interval = currentTime - p->lastPing; - if (interval > PROTECT_PING_INTERVAL_TIMEOUT) - p->isDown = TRUE; - return p->isDown; + currentTime = getMyTime(); + interval = currentTime - p->lastPing; + if (interval > PROTECT_PING_INTERVAL_TIMEOUT) + p->isDown = TRUE; + return p->isDown; } -void -destroyProtect(protect_t * p) +void destroyProtect(protect_t * p) { - assert(p != NULL); - free(p); + assert(p != NULL); + free(p); } diff --git a/src/base/protect.h b/src/base/protect.h index 54c5554..9a1cf1d 100644 --- a/src/base/protect.h +++ b/src/base/protect.h @@ -1,20 +1,19 @@ #ifndef PROTECT_H -#define PROTECT_H -#define PROTECT_PING_INTERVAL_TIMEOUT 5000 -#define PROTECT_SPEED_INTERVAL_TIMEOUT 40 -#define PROTECT_SPEED_AVARAGE 10 +# define PROTECT_H +# define PROTECT_PING_INTERVAL_TIMEOUT 5000 +# define PROTECT_SPEED_INTERVAL_TIMEOUT 40 +# define PROTECT_SPEED_AVARAGE 10 -#include "main.h" -#include "myTimer.h" +# include "main.h" +# include "myTimer.h" -typedef struct protect_struct -{ - my_time_t lastPing; - my_time_t lastMove; - my_time_t avarage; - int count; - bool_t isDown; +typedef struct protect_struct { + my_time_t lastPing; + my_time_t lastMove; + my_time_t avarage; + int count; + bool_t isDown; } protect_t; extern protect_t *newProtect(); diff --git a/src/base/proto.c b/src/base/proto.c index 7c510c5..51fedaa 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -21,123 +21,118 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -#include "screen_world.h" -#include "screen_setting.h" -#include "screen_choiceArena.h" -#include "screen_analyze.h" -#include "screen_downArena.h" -#include "client.h" -#include "term.h" -#include "radar.h" -#include "chat.h" +# include "screen_world.h" +# include "screen_setting.h" +# include "screen_choiceArena.h" +# include "screen_analyze.h" +# include "screen_downArena.h" +# include "client.h" +# include "term.h" +# include "radar.h" +# include "chat.h" #endif #ifdef PUBLIC_SERVER -#include "highScore.h" -#include "publicServer.h" -#include "serverConfigFile.h" +# include "highScore.h" +# include "publicServer.h" +# include "serverConfigFile.h" #endif -void -proto_send_error_server(int type, client_t * client, int errorcode) +void proto_send_error_server(int type, client_t * client, int errorcode) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode); + snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_error_client(char *msg) +void proto_recv_error_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int errorcode; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int errorcode; + int recv_count; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", cmd, &errorcode); + recv_count = sscanf(msg, "%s %d", cmd, &errorcode); - if (recv_count != 2) { - return; - } -#ifdef DEBUG - printf(_("Proto error code: \"%d\"\n"), errorcode); -#endif - switch (errorcode) { - case PROTO_ERROR_CODE_BAD_VERSION: - setMsgToAnalyze(_ - ("Version of your client isn't supported by the server.")); - setWorldEnd(); - break; - case PROTO_ERROR_CODE_TIMEOUT: - setMsgToAnalyze(_("The timeout of ping from server is out")); - setWorldEnd(); - break; - case PROTO_ERROR_LIMIT_MAX_CLIENT: - setMsgToAnalyze(_ - ("The maximum amount of connected players has been exceeded!")); - setWorldEnd(); - break; - } + if (recv_count != 2) { + return; + } +# ifdef DEBUG + printf(_("Proto error code: \"%d\"\n"), errorcode); +# endif + switch (errorcode) { + case PROTO_ERROR_CODE_BAD_VERSION: + setMsgToAnalyze(_ + ("Version of your client isn't supported by the server.")); + setWorldEnd(); + break; + case PROTO_ERROR_CODE_TIMEOUT: + setMsgToAnalyze(_("The timeout of ping from server is out")); + setWorldEnd(); + break; + case PROTO_ERROR_LIMIT_MAX_CLIENT: + setMsgToAnalyze(_ + ("The maximum amount of connected players has been exceeded!")); + setWorldEnd(); + break; + } } #endif #ifndef PUBLIC_SERVER -void -proto_send_hello_client(char *name) +void proto_send_hello_client(char *name) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", - getParamElse("--version", TUXANCI_VERSION), name); - sendServer(msg); + snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", + getParamElse("--version", TUXANCI_VERSION), name); + sendServer(msg); } #endif -static void -action_sendItem(space_t * space, item_t * item, client_t * client) +static void action_sendItem(space_t * space, item_t * item, client_t * client) { - proto_send_additem_server(PROTO_SEND_ONE, client, item); + proto_send_additem_server(PROTO_SEND_ONE, client, item); } -static void -sendInfoCreateClient(client_t * client) +static void sendInfoCreateClient(client_t * client) { - list_t *listClient; - client_t *thisClient; - tux_t *thisTux; - int i; + list_t *listClient; + client_t *thisClient; + tux_t *thisTux; + int i; - assert(client != NULL); + assert(client != NULL); - listClient = getListServerClient(); + listClient = getListServerClient(); - proto_send_init_server(PROTO_SEND_ONE, client, client); + proto_send_init_server(PROTO_SEND_ONE, client, client); #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, client, - getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); + proto_send_newtux_server(PROTO_SEND_ONE, client, + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); #endif - for (i = 0; i < listClient->count; i++) { - thisClient = (client_t *) listClient->list[i]; - thisTux = thisClient->tux; + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; + thisTux = thisClient->tux; - if (thisTux != NULL && thisTux != client->tux) { - proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); - proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); - } - } + if (thisTux != NULL && thisTux != client->tux) { + proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); + proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); + } + } - actionSpace(getCurrentArena()->spaceItem, action_sendItem, client); + actionSpace(getCurrentArena()->spaceItem, action_sendItem, client); /* for( i = 0 ; i < getCurrentArena()->spaceItem->listIndex->count; i++) { @@ -147,265 +142,254 @@ sendInfoCreateClient(client_t * client) */ } -void -proto_recv_hello_server(client_t * client, char *msg) +void proto_recv_hello_server(client_t * client, char *msg) { - static char *supportVersion = NULL; - char cmd[STR_PROTO_SIZE]; - char version[STR_NAME_SIZE]; - char name[STR_NAME_SIZE]; - int recv_count; - - assert(client != NULL); - - if (getSpaceCount(getCurrentArena()->spaceTux) + 1 > - getServerMaxClients()) { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_LIMIT_MAX_CLIENT); - eventMsgInCheckFront(client); - client->status = NET_STATUS_ZOMBIE; - return; - } - - strcpy(version, ""); - strcpy(name, ""); + static char *supportVersion = NULL; + char cmd[STR_PROTO_SIZE]; + char version[STR_NAME_SIZE]; + char name[STR_NAME_SIZE]; + int recv_count; + + assert(client != NULL); + + if (getSpaceCount(getCurrentArena()->spaceTux) + 1 > getServerMaxClients()) { + proto_send_error_server(PROTO_SEND_ONE, client, + PROTO_ERROR_LIMIT_MAX_CLIENT); + eventMsgInCheckFront(client); + client->status = NET_STATUS_ZOMBIE; + return; + } + + strcpy(version, ""); + strcpy(name, ""); #ifdef PUBLIC_SERVER - if (supportVersion == NULL) { - supportVersion = - getSetting("SUPPORT_CLIENTS", "--support-clients", - TUXANCI_VERSION); - } + if (supportVersion == NULL) { + supportVersion = + getSetting("SUPPORT_CLIENTS", "--support-clients", + TUXANCI_VERSION); + } #endif #ifndef PUBLIC_SERVER - if (supportVersion == NULL) { - supportVersion = TUXANCI_VERSION; - } + if (supportVersion == NULL) { + supportVersion = TUXANCI_VERSION; + } #endif - recv_count = sscanf(msg, "%s %s %s", cmd, version, name); + recv_count = sscanf(msg, "%s %s %s", cmd, version, name); - if (recv_count != 3) { - return; - } + if (recv_count != 3) { + return; + } - if (strstr(supportVersion, version) == NULL) { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_CODE_BAD_VERSION); - eventMsgInCheckFront(client); - client->status = NET_STATUS_ZOMBIE; - return; - } + if (strstr(supportVersion, version) == NULL) { + proto_send_error_server(PROTO_SEND_ONE, client, + PROTO_ERROR_CODE_BAD_VERSION); + eventMsgInCheckFront(client); + client->status = NET_STATUS_ZOMBIE; + return; + } - client->tux = newTux(); - client->tux->control = TUX_CONTROL_NET; - client->tux->client = client; + client->tux = newTux(); + client->tux->control = TUX_CONTROL_NET; + client->tux->client = client; - addObjectToSpace(getCurrentArena()->spaceTux, client->tux); + addObjectToSpace(getCurrentArena()->spaceTux, client->tux); - if (strlen(name) > STR_NAME_SIZE - 1) { - name[STR_NAME_SIZE - 1] = '\0'; - } + if (strlen(name) > STR_NAME_SIZE - 1) { + name[STR_NAME_SIZE - 1] = '\0'; + } - tuxSetName(client->tux, name); - sendInfoCreateClient(client); + tuxSetName(client->tux, name); + sendInfoCreateClient(client); } -void -proto_send_status_server(int type, client_t * client) +void proto_send_status_server(int type, client_t * client) { - char msg[STR_PROTO_SIZE]; - char *name; - char *version; - int clients; - int maxclients; - unsigned int uptime; - char *arena; + char msg[STR_PROTO_SIZE]; + char *name; + char *version; + int clients; + int maxclients; + unsigned int uptime; + char *arena; #ifndef PUBLIC_SERVER - name = "noname"; + name = "noname"; #endif #ifdef PUBLIC_SERVER - name = getSetting("NAME", "--name", "noname"); + name = getSetting("NAME", "--name", "noname"); #endif - version = TUXANCI_VERSION; - clients = getCurrentArena()->spaceTux->listIndex->count; - maxclients = getServerMaxClients(); - uptime = (unsigned int) getUpdateServer(); - arena = getArenaNetName(getChoiceArena()); - - snprintf(msg, STR_PROTO_SIZE, - "name: %s\n" - "version: %s\n" - "clients: %d\n" - "maxclients: %d\n" - "uptime: %d\n" - "arena: %s\n", - name, version, clients, maxclients, uptime, arena); - - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); - //proto_send(type, client, msg); + version = TUXANCI_VERSION; + clients = getCurrentArena()->spaceTux->listIndex->count; + maxclients = getServerMaxClients(); + uptime = (unsigned int) getUpdateServer(); + arena = getArenaNetName(getChoiceArena()); + + snprintf(msg, STR_PROTO_SIZE, + "name: %s\n" + "version: %s\n" + "clients: %d\n" + "maxclients: %d\n" + "uptime: %d\n" + "arena: %s\n", name, version, clients, maxclients, uptime, arena); + + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); } -void -proto_recv_status_server(client_t * client, char *msg) +void proto_recv_status_server(client_t * client, char *msg) { - proto_send_status_server(PROTO_SEND_ONE, client); + proto_send_status_server(PROTO_SEND_ONE, client); } #ifdef PUBLIC_SERVER -void -proto_send_listscore_server(int type, client_t * client, int max) +void proto_send_listscore_server(int type, client_t * client, int max) { - char *str; - char *msg; - int i; + char *str; + char *msg; + int i; - msg = malloc((max * 48) * sizeof(char)); - strcpy(msg, ""); + msg = malloc((max * 48) * sizeof(char)); + strcpy(msg, ""); - for (i = 0; i < max; i++) { - str = getTableItem(i); + for (i = 0; i < max; i++) { + str = getTableItem(i); - if (str == NULL) { - break; - } + if (str == NULL) { + break; + } - strcat(msg, str); - strcat(msg, "\n"); - } + strcat(msg, str); + strcat(msg, "\n"); + } - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); - free(msg); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); + free(msg); } -void -proto_recv_listscore_server(client_t * client, char *msg) +void proto_recv_listscore_server(client_t * client, char *msg) { - char cmd[STR_PROTO_SIZE]; - int recv_count; - int max; + char cmd[STR_PROTO_SIZE]; + int recv_count; + int max; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", cmd, &max); + recv_count = sscanf(msg, "%s %d", cmd, &max); - if (recv_count != 2) { - max = HIGHSCORE_MAX_PLAYERS; - } + if (recv_count != 2) { + max = HIGHSCORE_MAX_PLAYERS; + } - proto_send_listscore_server(PROTO_SEND_ONE, client, max); + proto_send_listscore_server(PROTO_SEND_ONE, client, max); } #endif #ifndef PUBLIC_SERVER -void -proto_send_check_client(int id) +void proto_send_check_client(int id) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); - sendServer(msg); + snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); + sendServer(msg); } #endif -void -proto_recv_check_server(client_t * client, char *msg) +void proto_recv_check_server(client_t * client, char *msg) { - char cmd[STR_PROTO_SIZE]; - int recv_count; - int id; + char cmd[STR_PROTO_SIZE]; + int recv_count; + int id; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", cmd, &id); + recv_count = sscanf(msg, "%s %d", cmd, &id); - if (recv_count != 2) { - return; - } + if (recv_count != 2) { + return; + } - delMsgInCheckFront(client->listSendMsg, id); + delMsgInCheckFront(client->listSendMsg, id); } -void -proto_send_init_server(int type, client_t * client, client_t * client2) +void proto_send_init_server(int type, client_t * client, client_t * client2) { - char msg[STR_PROTO_SIZE]; - int count; - int check_id; + char msg[STR_PROTO_SIZE]; + int count; + int check_id; - assert(client2 != NULL); + assert(client2 != NULL); - count = WORLD_COUNT_ROUND_UNLIMITED; + count = WORLD_COUNT_ROUND_UNLIMITED; #ifndef PUBLIC_SERVER - getSettingCountRound(&count); + getSettingCountRound(&count); #endif - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n", - client2->tux->id, client2->tux->x, client2->tux->y, - count, getArenaNetName(getChoiceArena()), check_id); + snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n", + client2->tux->id, client2->tux->x, client2->tux->y, + count, getArenaNetName(getChoiceArena()), check_id); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER -void -proto_recv_init_client(char *msg) +void proto_recv_init_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - char arena_name[STR_PROTO_SIZE]; - tux_t *tux; - int id; - int x, y, n; - int check_id; - int recv_count; - arena_t *arena; + char cmd[STR_PROTO_SIZE]; + char arena_name[STR_PROTO_SIZE]; + tux_t *tux; + int id; + int x, y, n; + int check_id; + int recv_count; + arena_t *arena; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d %d %d %d %s %d", - cmd, &id, &x, &y, &n, arena_name, &check_id); + recv_count = sscanf(msg, "%s %d %d %d %d %s %d", + cmd, &id, &x, &y, &n, arena_name, &check_id); - if (recv_count != 7) { - return; - } + if (recv_count != 7) { + return; + } - proto_send_check_client(check_id); + proto_send_check_client(check_id); - if (getCurrentArena() != NULL) { - return; - } + if (getCurrentArena() != NULL) { + return; + } - setWorldArena(getArenaFileFormNetName(arena_name)); + setWorldArena(getArenaFileFormNetName(arena_name)); - arena = getCurrentArena(); - arena->max_countRound = n; + arena = getCurrentArena(); + arena->max_countRound = n; - tux = newTux(); - replaceTuxID(tux, id); - tux->x = x; - tux->y = y; - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); + tux = newTux(); + replaceTuxID(tux, id); + tux->x = x; + tux->y = y; + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); - getSettingNameRight(tux->name); + getSettingNameRight(tux->name); - addObjectToSpace(arena->spaceTux, tux); + addObjectToSpace(arena->spaceTux, tux); } #endif @@ -413,630 +397,597 @@ proto_recv_init_client(char *msg) void proto_send_event_server(int type, client_t * client, tux_t * tux, int action) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action); + snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_event_client(char *msg) +void proto_recv_event_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, action; - tux_t *tux; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id, action; + tux_t *tux; + int recv_count; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action); + recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action); - if (recv_count != 3) { - return; - } + if (recv_count != 3) { + return; + } - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux != NULL) { - actionTux(tux, action); - addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX); - } + if (tux != NULL) { + actionTux(tux, action); + addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX); + } } #endif #ifndef PUBLIC_SERVER -void -proto_send_event_client(int action) +void proto_send_event_client(int action) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "event %d\n", action); + snprintf(msg, STR_PROTO_SIZE, "event %d\n", action); - sendServer(msg); + sendServer(msg); } #endif -void -proto_recv_event_server(client_t * client, char *msg) +void proto_recv_event_server(client_t * client, char *msg) { - char cmd[STR_PROTO_SIZE]; - int action; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int action; + int recv_count; - assert(client != NULL); - assert(msg != NULL); + assert(client != NULL); + assert(msg != NULL); - //debug_interval(); + //debug_interval(); - recv_count = sscanf(msg, "%s %d", cmd, &action); + recv_count = sscanf(msg, "%s %d", cmd, &action); - if (recv_count != 2) { - return; - } + if (recv_count != 2) { + return; + } - if (client->tux->bonus != BONUS_HIDDEN) { - proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, - action); - } + if (client->tux->bonus != BONUS_HIDDEN) { + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, + action); + } - refreshLastMove(client->protect); + refreshLastMove(client->protect); - actionTux(client->tux, action); + actionTux(client->tux, action); } -void -proto_send_newtux_server(int type, client_t * client, tux_t * tux) +void proto_send_newtux_server(int type, client_t * client, tux_t * tux) { - char msg[STR_PROTO_SIZE]; - int x, y; - - assert(tux != NULL); - - if (tux->bonus == BONUS_HIDDEN) { - x = TUX_LOCATE_UNKNOWN; - y = TUX_LOCATE_UNKNOWN; - } - else { - getTuxProportion(tux, &x, &y, NULL, NULL); - } - - snprintf(msg, STR_PROTO_SIZE, - "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n", - tux->id, x, y, tux->status, tux->position, tux->frame, - tux->score, tux->name, tux->gun, tux->bonus, - tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], - tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], - tux->shot[GUN_LASSER], tux->shot[GUN_MINE], - tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + int x, y; + + assert(tux != NULL); + + if (tux->bonus == BONUS_HIDDEN) { + x = TUX_LOCATE_UNKNOWN; + y = TUX_LOCATE_UNKNOWN; + } else { + getTuxProportion(tux, &x, &y, NULL, NULL); + } + + snprintf(msg, STR_PROTO_SIZE, + "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n", + tux->id, x, y, tux->status, tux->position, tux->frame, + tux->score, tux->name, tux->gun, tux->bonus, + tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], + tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], + tux->shot[GUN_LASSER], tux->shot[GUN_MINE], + tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_newtux_client(char *msg) +void proto_recv_newtux_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - char name[STR_NAME_SIZE]; - int id, x, y, status, position, frame, score; - int myGun, myBonus; - int gun1, gun2, gun3, gun4, gun5, gun6, gun7; - int time1, time2; - tux_t *tux; - int recv_count; - - assert(msg != NULL); - - if (getCurrentArena() == NULL) { - return; - } - - recv_count = - sscanf(msg, - "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", - cmd, &id, &x, &y, &status, &position, &frame, &score, name, - &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, - &gun7, &time1, &time2); - - if (recv_count != 20) { - return; - } - - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - - if (tux != NULL) { - assert(tux->id == id); - } - - if (tux == NULL) { - tux = newTux(); - replaceTuxID(tux, id); - tux->control = TUX_CONTROL_NET; - addObjectToSpace(getCurrentArena()->spaceTux, tux); - } - - if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT && - x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) { - getTuxProportion(tux, &x, &y, NULL, NULL); - } - - addToRadar(id, x, y, RADAR_TYPE_TUX); - - if (tux->bonus == BONUS_HIDDEN) { - delFromRadar(id); - } - - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - tux->status = status; - tux->position = position; - tux->frame = frame; - tux->score = score; - strcpy(tux->name, name); - tux->gun = myGun; - tux->bonus = myBonus; - tux->shot[GUN_SIMPLE] = gun1; - tux->shot[GUN_DUAL_SIMPLE] = gun2; - tux->shot[GUN_SCATTER] = gun3; - tux->shot[GUN_TOMMY] = gun4; - tux->shot[GUN_LASSER] = gun5; - tux->shot[GUN_MINE] = gun6; - tux->shot[GUN_BOMBBALL] = gun7; - tux->bonus_time = time1; - tux->pickup_time = time2; + char cmd[STR_PROTO_SIZE]; + char name[STR_NAME_SIZE]; + int id, x, y, status, position, frame, score; + int myGun, myBonus; + int gun1, gun2, gun3, gun4, gun5, gun6, gun7; + int time1, time2; + tux_t *tux; + int recv_count; + + assert(msg != NULL); + + if (getCurrentArena() == NULL) { + return; + } + + recv_count = + sscanf(msg, + "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + cmd, &id, &x, &y, &status, &position, &frame, &score, name, + &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, + &gun7, &time1, &time2); + + if (recv_count != 20) { + return; + } + + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + + if (tux != NULL) { + assert(tux->id == id); + } + + if (tux == NULL) { + tux = newTux(); + replaceTuxID(tux, id); + tux->control = TUX_CONTROL_NET; + addObjectToSpace(getCurrentArena()->spaceTux, tux); + } + + if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT && + x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) { + getTuxProportion(tux, &x, &y, NULL, NULL); + } + + addToRadar(id, x, y, RADAR_TYPE_TUX); + + if (tux->bonus == BONUS_HIDDEN) { + delFromRadar(id); + } + + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + tux->status = status; + tux->position = position; + tux->frame = frame; + tux->score = score; + strcpy(tux->name, name); + tux->gun = myGun; + tux->bonus = myBonus; + tux->shot[GUN_SIMPLE] = gun1; + tux->shot[GUN_DUAL_SIMPLE] = gun2; + tux->shot[GUN_SCATTER] = gun3; + tux->shot[GUN_TOMMY] = gun4; + tux->shot[GUN_LASSER] = gun5; + tux->shot[GUN_MINE] = gun6; + tux->shot[GUN_BOMBBALL] = gun7; + tux->bonus_time = time1; + tux->pickup_time = time2; } #endif -void -proto_send_kill_server(int type, client_t * client, tux_t * tux) +void proto_send_kill_server(int type, client_t * client, tux_t * tux) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - assert(tux != NULL); + assert(tux != NULL); - snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); + snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_kill_client(char *msg) +void proto_recv_kill_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id; - tux_t *tux; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id; + tux_t *tux; + int recv_count; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", cmd, &id); + recv_count = sscanf(msg, "%s %d", cmd, &id); - if (recv_count != 2) { - return; - } + if (recv_count != 2) { + return; + } - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux != NULL) { - eventTuxIsDead(tux); - } + if (tux != NULL) { + eventTuxIsDead(tux); + } } #endif -void -proto_send_del_server(int type, client_t * client, int id) +void proto_send_del_server(int type, client_t * client, int id) { - char msg[STR_PROTO_SIZE]; - int check_id; + char msg[STR_PROTO_SIZE]; + int check_id; - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", id, check_id); + snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", id, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); - //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_check(type, client, msg, check_id); } #ifndef PUBLIC_SERVER -void -proto_recv_del_client(char *msg) +void proto_recv_del_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, check_id; - tux_t *tux; - shot_t *shot; - item_t *item; - int recv_count; - - assert(msg != NULL); - - recv_count = sscanf(msg, "%s %d %d", cmd, &id, &check_id); - - if (recv_count != 3) { - return; - } - - proto_send_check_client(check_id); - - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - - if (tux != NULL) { - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, - destroyTux); - return; - } - - shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); - - if (shot != NULL) { - //printf("delete shot..\n"); - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, - destroyShot); - return; - } - - item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id); - - if (item != NULL) { - //printf("delete item..\n"); - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, - destroyItem); - return; - } + char cmd[STR_PROTO_SIZE]; + int id, check_id; + tux_t *tux; + shot_t *shot; + item_t *item; + int recv_count; + + assert(msg != NULL); + + recv_count = sscanf(msg, "%s %d %d", cmd, &id, &check_id); + + if (recv_count != 3) { + return; + } + + proto_send_check_client(check_id); + + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + + if (tux != NULL) { + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, + destroyTux); + return; + } + + shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); + + if (shot != NULL) { + //printf("delete shot..\n"); + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, + destroyShot); + return; + } + + item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id); + + if (item != NULL) { + //printf("delete item..\n"); + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, + destroyItem); + return; + } } #endif -void -proto_send_additem_server(int type, client_t * client, item_t * p) +void proto_send_additem_server(int type, client_t * client, item_t * p) { - char msg[STR_PROTO_SIZE]; - int check_id; + char msg[STR_PROTO_SIZE]; + int check_id; - assert(p != NULL); + assert(p != NULL); - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - snprintf(msg, STR_PROTO_SIZE, "additem %d %d %d %d %d %d %d %d\n", - p->id, p->type, p->x, p->y, p->count, p->frame, p->author_id, - check_id); + snprintf(msg, STR_PROTO_SIZE, "additem %d %d %d %d %d %d %d %d\n", + p->id, p->type, p->x, p->y, p->count, p->frame, p->author_id, + check_id); - //proto_send(type, client, msg); - //proto_check(type, client, msg, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_send(type, client, msg); + //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER -void -proto_recv_additem_client(char *msg) +void proto_recv_additem_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, type, x, y, count, frame, author_id, check_id; - item_t *item; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id, type, x, y, count, frame, author_id, check_id; + item_t *item; + int recv_count; - assert(msg != NULL); + assert(msg != NULL); - if (getCurrentArena() == NULL) { - return; - } + if (getCurrentArena() == NULL) { + return; + } - recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", - cmd, &id, &type, &x, &y, &count, &frame, &author_id, - &check_id); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", + cmd, &id, &type, &x, &y, &count, &frame, &author_id, + &check_id); - if (recv_count != 9) { - return; - } + if (recv_count != 9) { + return; + } - proto_send_check_client(check_id); + proto_send_check_client(check_id); - if ((item = - getObjectFromSpaceWithID(getCurrentArena()->spaceItem, - id)) != NULL) { - return; - } + if ((item = + getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id)) != NULL) { + return; + } - if (type != ITEM_MINE && type != ITEM_EXPLOSION - && type != ITEM_BIG_EXPLOSION) { - addToRadar(id, x, y, RADAR_TYPE_ITEM); - } + if (type != ITEM_MINE && type != ITEM_EXPLOSION + && type != ITEM_BIG_EXPLOSION) { + addToRadar(id, x, y, RADAR_TYPE_ITEM); + } - item = newItem(x, y, type, author_id); + item = newItem(x, y, type, author_id); - replaceItemID(item, id); - item->count = count; - item->frame = frame; + replaceItemID(item, id); + item->count = count; + item->frame = frame; - addObjectToSpace(getCurrentArena()->spaceItem, item); + addObjectToSpace(getCurrentArena()->spaceItem, item); } #endif -void -proto_send_shot_server(int type, client_t * client, shot_t * p) +void proto_send_shot_server(int type, client_t * client, shot_t * p) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - assert(p != NULL); + assert(p != NULL); - snprintf(msg, STR_PROTO_SIZE, "shot %d %d %d %d %d %d %d %d %d\n", - p->id, p->x, p->y, p->px, p->py, p->position, p->gun, - p->author_id, p->isCanKillAuthor); + snprintf(msg, STR_PROTO_SIZE, "shot %d %d %d %d %d %d %d %d %d\n", + p->id, p->x, p->y, p->px, p->py, p->position, p->gun, + p->author_id, p->isCanKillAuthor); - //proto_send(type, client, msg); - //proto_check(type, client, msg, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); + //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_shot_client(char *msg) +void proto_recv_shot_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; - shot_t *shot; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; + shot_t *shot; + int recv_count; - assert(msg != NULL); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d %d", - cmd, &shot_id, &x, &y, &px, &py, &position, &gun, - &author_id, &isCanKillAuthor); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position, &gun, + &author_id, &isCanKillAuthor); - if (recv_count != 10) { - return; - } + if (recv_count != 10) { + return; + } - if ((shot = - getObjectFromSpaceWithID(getCurrentArena()->spaceShot, - shot_id)) != NULL) { - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, - destroyShot); + if ((shot = + getObjectFromSpaceWithID(getCurrentArena()->spaceShot, + shot_id)) != NULL) { + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, + destroyShot); - //return; - } + //return; + } - shot = newShot(x, y, px, py, gun, author_id); + shot = newShot(x, y, px, py, gun, author_id); - replaceShotID(shot, shot_id); - shot->isCanKillAuthor = isCanKillAuthor; - shot->position = position; + replaceShotID(shot, shot_id); + shot->isCanKillAuthor = isCanKillAuthor; + shot->position = position; - if (shot->gun == GUN_LASSER) { - transformOnlyLasser(shot); - } + if (shot->gun == GUN_LASSER) { + transformOnlyLasser(shot); + } - addObjectToSpace(getCurrentArena()->spaceShot, shot); + addObjectToSpace(getCurrentArena()->spaceShot, shot); } #endif #ifndef PUBLIC_SERVER -void -proto_send_chat_client(char *s) +void proto_send_chat_client(char *s) { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); + sendServer(msg); } #endif -void -proto_recv_chat_server(client_t * client, char *msg) +void proto_recv_chat_server(client_t * client, char *msg) { - char out[STR_PROTO_SIZE]; - int len; + char out[STR_PROTO_SIZE]; + int len; - if (client->tux == NULL) { - return; - } + if (client->tux == NULL) { + return; + } - len = strlen(msg); - msg[len - 1] = '\0'; + len = strlen(msg); + msg[len - 1] = '\0'; - snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg + 5); + snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg + 5); - proto_send_chat_server(PROTO_SEND_ALL, NULL, out); + proto_send_chat_server(PROTO_SEND_ALL, NULL, out); } -void -proto_send_chat_server(int type, client_t * client, char *msg) +void proto_send_chat_server(int type, client_t * client, char *msg) { - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); #ifndef PUBLIC_SERVER - proto_recv_chat_client(msg); + proto_recv_chat_client(msg); #endif } #ifndef PUBLIC_SERVER -void -proto_recv_chat_client(char *msg) +void proto_recv_chat_client(char *msg) { - int len; + int len; - assert(msg != NULL); + assert(msg != NULL); - len = strlen(msg); - msg[len - 1] = '\0'; + len = strlen(msg); + msg[len - 1] = '\0'; - addToChat(msg + 5); + addToChat(msg + 5); } #endif #ifndef PUBLIC_SERVER -void -proto_send_module_client(char *msg) +void proto_send_module_client(char *msg) { - char out[STR_PROTO_SIZE]; + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ - sendServer(out); + sendServer(out); } #endif -void -proto_recv_module_server(client_t * client, char *msg) +void proto_recv_module_server(client_t * client, char *msg) { - recvMsgModule(msg + 7); + recvMsgModule(msg + 7); } -void -proto_send_module_server(int type, client_t * client, char *msg) +void proto_send_module_server(int type, client_t * client, char *msg) { - char out[STR_PROTO_SIZE]; + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ - protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_module_client(char *msg) +void proto_recv_module_client(char *msg) { - recvMsgModule(msg + 7); + recvMsgModule(msg + 7); } #endif #ifndef PUBLIC_SERVER -void -proto_send_ping_client() +void proto_send_ping_client() { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "ping\n"); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "ping\n"); + sendServer(msg); } #endif -void -proto_recv_ping_server(client_t * client, char *msg) +void proto_recv_ping_server(client_t * client, char *msg) { } -void -proto_send_ping_server(int type, client_t * client) +void proto_send_ping_server(int type, client_t * client) { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "ping\n"); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "ping\n"); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_ping_client(char *msg) +void proto_recv_ping_client(char *msg) { } #endif -void -proto_recv_echo_server(client_t * client, char *msg) +void proto_recv_echo_server(client_t * client, char *msg) { - proto_send_echo_server(PROTO_SEND_ONE, client, msg + 4); // msg + strlen("echo"); + proto_send_echo_server(PROTO_SEND_ONE, client, msg + 4); // msg + strlen("echo"); } -void -proto_send_echo_server(int type, client_t * client, char *s) +void proto_send_echo_server(int type, client_t * client, char *s) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "echo%s", s); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "echo%s", s); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } -void -proto_send_end_server(int type, client_t * client) +void proto_send_end_server(int type, client_t * client) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "end\n"); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "end\n"); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_end_client(char *msg) +void proto_recv_end_client(char *msg) { - assert(msg != NULL); + assert(msg != NULL); - setWorldEnd(); + setWorldEnd(); } #endif #ifndef PUBLIC_SERVER -void -proto_send_end_client() +void proto_send_end_client() { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "end\n"); - sendServer(msg); + snprintf(msg, STR_PROTO_SIZE, "end\n"); + sendServer(msg); } #endif -void -proto_recv_end_server(client_t * client, char *msg) +void proto_recv_end_server(client_t * client, char *msg) { - assert(msg != NULL); - assert(client != NULL); + assert(msg != NULL); + assert(client != NULL); - client->status = NET_STATUS_ZOMBIE; + client->status = NET_STATUS_ZOMBIE; } diff --git a/src/base/proto.h b/src/base/proto.h index 6442469..590317b 100644 --- a/src/base/proto.h +++ b/src/base/proto.h @@ -1,42 +1,42 @@ #ifndef MY_PROTO -#define MY_PROTO - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> - -#include "main.h" -#include "list.h" -#include "item.h" -#include "shot.h" -#include "arenaFile.h" -#include "myTimer.h" -#include "server.h" -#include "net_multiplayer.h" - -#ifndef PUBLIC_SERVER -#include "screen_world.h" -#include "screen_setting.h" -#include "screen_choiceArena.h" -#include "client.h" -#endif - -#ifdef PUBLIC_SERVER -#include "publicServer.h" -#endif - -#define PROTO_ERROR_CODE_UNKNOWN 0 -#define PROTO_ERROR_CODE_BAD_VERSION 1 -#define PROTO_ERROR_CODE_BAD_NAME 2 -#define PROTO_ERROR_CODE_BAD_COMMAND 3 -#define PROTO_ERROR_CODE_TIMEOUT 4 -#define PROTO_ERROR_LIMIT_MAX_CLIENT 5 +# define MY_PROTO + +# include <stdio.h> +# include <stdlib.h> +# include <string.h> +# include <assert.h> + +# include "main.h" +# include "list.h" +# include "item.h" +# include "shot.h" +# include "arenaFile.h" +# include "myTimer.h" +# include "server.h" +# include "net_multiplayer.h" + +# ifndef PUBLIC_SERVER +# include "screen_world.h" +# include "screen_setting.h" +# include "screen_choiceArena.h" +# include "client.h" +# endif + +# ifdef PUBLIC_SERVER +# include "publicServer.h" +# endif + +# define PROTO_ERROR_CODE_UNKNOWN 0 +# define PROTO_ERROR_CODE_BAD_VERSION 1 +# define PROTO_ERROR_CODE_BAD_NAME 2 +# define PROTO_ERROR_CODE_BAD_COMMAND 3 +# define PROTO_ERROR_CODE_TIMEOUT 4 +# define PROTO_ERROR_LIMIT_MAX_CLIENT 5 extern void proto_send_error_server(int type, client_t * client, - int errorcode); + int errorcode); extern void proto_recv_error_client(char *msg); extern void proto_send_hello_client(char *name); @@ -52,17 +52,16 @@ extern void proto_send_check_client(int id); extern void proto_recv_check_server(client_t * client, char *msg); extern void proto_send_init_server(int type, client_t * client, - client_t * client2); + client_t * client2); extern void proto_recv_init_client(char *msg); extern void proto_send_event_server(int type, client_t * client, tux_t * tux, - int action); + int action); extern void proto_recv_event_client(char *msg); extern void proto_send_event_client(int action); extern void proto_recv_event_server(client_t * client, char *msg); -extern void proto_send_newtux_server(int type, client_t * client, - tux_t * tux); +extern void proto_send_newtux_server(int type, client_t * client, tux_t * tux); extern void proto_recv_newtux_client(char *msg); extern void proto_send_kill_server(int type, client_t * client, tux_t * tux); @@ -74,8 +73,7 @@ extern void proto_recv_score_client(char *msg); extern void proto_send_del_server(int type, client_t * client, int id); extern void proto_recv_del_client(char *msg); -extern void proto_send_additem_server(int type, client_t * client, - item_t * p); +extern void proto_send_additem_server(int type, client_t * client, item_t * p); extern void proto_recv_additem_client(char *msg); extern void proto_send_shot_server(int type, client_t * client, shot_t * p); diff --git a/src/base/server.c b/src/base/server.c index cc4cff2..f98ae2f 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -1,13 +1,13 @@ #ifndef __WIN32__ -# include <sys/socket.h> -# include <sys/types.h> -# include <netinet/in.h> -# include <arpa/inet.h> -# include <netdb.h> +# include <sys/socket.h> +# include <sys/types.h> +# include <netinet/in.h> +# include <arpa/inet.h> +# include <netdb.h> #else -# include <windows.h> -# include <wininet.h> +# include <windows.h> +# include <wininet.h> #endif #include <unistd.h> @@ -32,12 +32,12 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -#include "screen_world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" -#include "highScore.h" +# include "publicServer.h" +# include "highScore.h" #endif @@ -49,358 +49,334 @@ static list_t *listServerTimer; static time_t timeUpdate; static int maxClients; -typedef struct proto_cmd_server_struct -{ - char *name; - int len; - int tux; - void (*fce_proto) (client_t *, char *msg); +typedef struct proto_cmd_server_struct { + char *name; + int len; + int tux; + void (*fce_proto) (client_t *, char *msg); } proto_cmd_server_t; static proto_cmd_server_t proto_cmd_list[] = { - {.name = "hello",.len = 5,.tux = 0,.fce_proto = proto_recv_hello_server}, - {.name = "status",.len = 6,.tux = 0,.fce_proto = - proto_recv_status_server}, + {.name = "hello",.len = 5,.tux = 0,.fce_proto = proto_recv_hello_server}, + {.name = "status",.len = 6,.tux = 0,.fce_proto = proto_recv_status_server}, #ifdef PUBLIC_SERVER - {.name = "list",.len = 4,.tux = 0,.fce_proto = - proto_recv_listscore_server}, + {.name = "list",.len = 4,.tux = 0,.fce_proto = + proto_recv_listscore_server}, #endif - {.name = "event",.len = 5,.tux = 1,.fce_proto = proto_recv_event_server}, - {.name = "check",.len = 5,.tux = 1,.fce_proto = proto_recv_check_server}, - {.name = "module",.len = 6,.tux = 1,.fce_proto = - proto_recv_module_server}, - {.name = "chat",.len = 4,.tux = 1,.fce_proto = proto_recv_chat_server}, - {.name = "ping",.len = 4,.tux = 1,.fce_proto = proto_recv_ping_server}, - {.name = "echo",.len = 4,.tux = 0,.fce_proto = proto_recv_echo_server}, - {.name = "end",.len = 3,.tux = 1,.fce_proto = proto_recv_end_server}, - {.name = "",.len = 0,.tux = 0,.fce_proto = NULL}, + {.name = "event",.len = 5,.tux = 1,.fce_proto = proto_recv_event_server}, + {.name = "check",.len = 5,.tux = 1,.fce_proto = proto_recv_check_server}, + {.name = "module",.len = 6,.tux = 1,.fce_proto = proto_recv_module_server}, + {.name = "chat",.len = 4,.tux = 1,.fce_proto = proto_recv_chat_server}, + {.name = "ping",.len = 4,.tux = 1,.fce_proto = proto_recv_ping_server}, + {.name = "echo",.len = 4,.tux = 0,.fce_proto = proto_recv_echo_server}, + {.name = "end",.len = 3,.tux = 1,.fce_proto = proto_recv_end_server}, + {.name = "",.len = 0,.tux = 0,.fce_proto = NULL}, }; -static proto_cmd_server_t * -findCmdProto(client_t * client, char *msg) +static proto_cmd_server_t *findCmdProto(client_t * client, char *msg) { - int len; - int i; + int len; + int i; - len = strlen(msg); + len = strlen(msg); - for (i = 0; proto_cmd_list[i].len != 0; i++) { - proto_cmd_server_t *thisCmd; + for (i = 0; proto_cmd_list[i].len != 0; i++) { + proto_cmd_server_t *thisCmd; - thisCmd = &proto_cmd_list[i]; + thisCmd = &proto_cmd_list[i]; - if (len >= thisCmd->len - && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { - if (thisCmd->tux && client->tux == NULL) { - return NULL; - } + if (len >= thisCmd->len + && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { + if (thisCmd->tux && client->tux == NULL) { + return NULL; + } - return thisCmd; - } - } + return thisCmd; + } + } - return NULL; + return NULL; } -static void -startUpdateServer() +static void startUpdateServer() { - timeUpdate = time(NULL); + timeUpdate = time(NULL); } -time_t -getUpdateServer() +time_t getUpdateServer() { - return time(NULL) - timeUpdate; + return time(NULL) - timeUpdate; } -client_t * -newAnyClient() +client_t *newAnyClient() { - client_t *new; + client_t *new; - new = malloc(sizeof(client_t)); - memset(new, 0, sizeof(client_t)); + new = malloc(sizeof(client_t)); + memset(new, 0, sizeof(client_t)); - new->status = NET_STATUS_OK; - new->listRecvMsg = newList(); - new->listSendMsg = newCheckFront(); - new->listSeesShot = newList(); - new->protect = newProtect(); + new->status = NET_STATUS_OK; + new->listRecvMsg = newList(); + new->listSendMsg = newCheckFront(); + new->listSeesShot = newList(); + new->protect = newProtect(); - return new; + return new; } -void -destroyAnyClient(client_t * p) +void destroyAnyClient(client_t * p) { - assert(p != NULL); + assert(p != NULL); - //eventMsgInCheckFront(p); - destroyListItem(p->listRecvMsg, free); - destroyListItem(p->listSeesShot, free); - destroyCheckFront(p->listSendMsg); + //eventMsgInCheckFront(p); + destroyListItem(p->listRecvMsg, free); + destroyListItem(p->listSeesShot, free); + destroyCheckFront(p->listSendMsg); - destroyProtect(p->protect); + destroyProtect(p->protect); - if (p->tux != NULL) { + if (p->tux != NULL) { #ifdef PUBLIC_SERVER - addPlayerInHighScore(p->tux->name, p->tux->score); + addPlayerInHighScore(p->tux->name, p->tux->score); #endif - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, - destroyTux); - } + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, + destroyTux); + } - free(p); + free(p); } -static void -eventDelClientFromListClient(client_t * client) +static void eventDelClientFromListClient(client_t * client) { - int offset; + int offset; - offset = searchListItem(listClient, client); + offset = searchListItem(listClient, client); - assert(offset != -1); + assert(offset != -1); - delListItem(listClient, offset, destroyUdpClient); + delListItem(listClient, offset, destroyUdpClient); } -static void -delZombieCLient(void *p_nothink) +static void delZombieCLient(void *p_nothink) { - client_t *thisClient; - my_time_t currentTime; - int i; - - currentTime = getMyTime(); - - for (i = 0; i < listClient->count; i++) { - thisClient = (client_t *) listClient->list[i]; - - if (isDown(thisClient->protect) == TRUE) { - proto_send_end_server(PROTO_SEND_ONE, thisClient); - eventMsgInCheckFront(thisClient); - thisClient->status = NET_STATUS_ZOMBIE; - } - - if (thisClient->status == NET_STATUS_ZOMBIE) { - if (thisClient->tux != NULL) { - proto_send_del_server(PROTO_SEND_ALL, NULL, - thisClient->tux->id); - } - - eventDelClientFromListClient(thisClient); - i--; - } - } + client_t *thisClient; + my_time_t currentTime; + int i; + + currentTime = getMyTime(); + + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; + + if (isDown(thisClient->protect) == TRUE) { + proto_send_end_server(PROTO_SEND_ONE, thisClient); + eventMsgInCheckFront(thisClient); + thisClient->status = NET_STATUS_ZOMBIE; + } + + if (thisClient->status == NET_STATUS_ZOMBIE) { + if (thisClient->tux != NULL) { + proto_send_del_server(PROTO_SEND_ALL, NULL, + thisClient->tux->id); + } + + eventDelClientFromListClient(thisClient); + i--; + } + } } -static void -eventPeriodicSyncClient(void *p_nothink) +static void eventPeriodicSyncClient(void *p_nothink) { - client_t *thisClientSend; - tux_t *thisTux; - int i; + client_t *thisClientSend; + tux_t *thisTux; + int i; #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, - getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); + proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); #endif - for (i = 0; i < listClient->count; i++) { - thisClientSend = (client_t *) listClient->list[i]; - thisTux = thisClientSend->tux; - - if (thisTux == NULL) { - continue; - } + for (i = 0; i < listClient->count; i++) { + thisClientSend = (client_t *) listClient->list[i]; + thisTux = thisClientSend->tux; - //proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux); - proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux); - } + if (thisTux == NULL) { + continue; + } + //proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux); + proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux); + } } -static void -eventSendPingClients(void *p_nothink) +static void eventSendPingClients(void *p_nothink) { - proto_send_ping_server(PROTO_SEND_ALL, NULL); + proto_send_ping_server(PROTO_SEND_ALL, NULL); } -void -setServerTimer() +void setServerTimer() { - if (listServerTimer != NULL) { - destroyTimer(listServerTimer); - } - - restartTimer(); - listServerTimer = newTimer(); - - addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, - SERVER_TIMEOUT); - addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, - NULL, SERVER_TIME_SYNC); - addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, - NULL, SERVER_TIME_PING); + if (listServerTimer != NULL) { + destroyTimer(listServerTimer); + } + + restartTimer(); + listServerTimer = newTimer(); + + addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, + SERVER_TIMEOUT); + addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, + NULL, SERVER_TIME_SYNC); + addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, + NULL, SERVER_TIME_PING); } -int -initServer(char *ip4, int port4, char *ip6, int port6) +int initServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - startUpdateServer(); - listServerTimer = NULL; + startUpdateServer(); + listServerTimer = NULL; - listClient = newList(); + listClient = newList(); - setServerMaxClients(SERVER_MAX_CLIENTS); - setServerTimer(); + setServerMaxClients(SERVER_MAX_CLIENTS); + setServerTimer(); - ret = initUdpServer(ip4, port4, ip6, port6); + ret = initUdpServer(ip4, port4, ip6, port6); - if (ret == 0) { - return -1; - } + if (ret == 0) { + return -1; + } - return ret; + return ret; } -list_t * -getListServerClient() +list_t *getListServerClient() { - return listClient; + return listClient; } -int -getServerMaxClients() +int getServerMaxClients() { - return maxClients; + return maxClients; } -void -setServerMaxClients(int n) +void setServerMaxClients(int n) { - maxClients = n; + maxClients = n; } -void -sendClient(client_t * p, char *msg) +void sendClient(client_t * p, char *msg) { - assert(p != NULL); - assert(msg != NULL); + assert(p != NULL); + assert(msg != NULL); - if (p->status != NET_STATUS_ZOMBIE) { - int ret = -1; // no Warnnings + if (p->status != NET_STATUS_ZOMBIE) { + int ret = -1; // no Warnnings #ifndef PUBLIC_SERVER - if (isParamFlag("--send")) { - printf(_("Sending: \"%s\""), msg); - } + if (isParamFlag("--send")) { + printf(_("Sending: \"%s\""), msg); + } #endif - ret = writeUdpSocket(p->socket_udp, p->socket_udp, msg, strlen(msg)); + ret = writeUdpSocket(p->socket_udp, p->socket_udp, msg, strlen(msg)); - if (ret <= 0) { - p->status = NET_STATUS_ZOMBIE; - } - } + if (ret <= 0) { + p->status = NET_STATUS_ZOMBIE; + } + } } -static void -eventClientWorkRecvList(client_t * client) +static void eventClientWorkRecvList(client_t * client) { - proto_cmd_server_t *protoCmd; - char *line; - int i; + proto_cmd_server_t *protoCmd; + char *line; + int i; - assert(client != NULL); + assert(client != NULL); - /* obsluha udalosti od clientov */ + /* obsluha udalosti od clientov */ - for (i = 0; i < client->listRecvMsg->count; i++) { - line = (char *) client->listRecvMsg->list[i]; - protoCmd = findCmdProto(client, line); + for (i = 0; i < client->listRecvMsg->count; i++) { + line = (char *) client->listRecvMsg->list[i]; + protoCmd = findCmdProto(client, line); #ifndef PUBLIC_SERVER - if (isParamFlag("--recv")) { - printf(_("Recieved: \"%s\""), line); - } + if (isParamFlag("--recv")) { + printf(_("Recieved: \"%s\""), line); + } #endif - if (protoCmd != NULL) { - protoCmd->fce_proto(client, line); - rereshLastPing(client->protect); - } - else { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_CODE_BAD_COMMAND); - } - } - - destroyListItem(client->listRecvMsg, free); - client->listRecvMsg = newList(); + if (protoCmd != NULL) { + protoCmd->fce_proto(client, line); + rereshLastPing(client->protect); + } else { + proto_send_error_server(PROTO_SEND_ONE, client, + PROTO_ERROR_CODE_BAD_COMMAND); + } + } + + destroyListItem(client->listRecvMsg, free); + client->listRecvMsg = newList(); } -static void -porcesListClients() +static void porcesListClients() { - int i; - client_t *thisClient; + int i; + client_t *thisClient; - for (i = 0; i < listClient->count; i++) { - thisClient = (client_t *) listClient->list[i]; + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; - eventClientWorkRecvList(thisClient); - eventMsgInCheckFront(thisClient); - } + eventClientWorkRecvList(thisClient); + eventMsgInCheckFront(thisClient); + } } -void -eventServer() +void eventServer() { #ifndef PUBLIC_SERVER - int count; + int count; - do { - restartSelect(); - setServerUdpSelect(); - actionSelect(); - count = selectServerUdpSocket(); - } while (count > 0); + do { + restartSelect(); + setServerUdpSelect(); + actionSelect(); + count = selectServerUdpSocket(); + } while (count > 0); #endif #ifdef PUBLIC_SERVER - int ret; + int ret; - restartSelect(); + restartSelect(); - setServerUdpSelect(); + setServerUdpSelect(); - ret = actionSelect(); + ret = actionSelect(); - if (ret > 0) { - selectServerUdpSocket(); - } + if (ret > 0) { + selectServerUdpSocket(); + } #endif - porcesListClients(); - eventTimer(listServerTimer); + porcesListClients(); + eventTimer(listServerTimer); } -void -quitServer() +void quitServer() { - proto_send_end_server(PROTO_SEND_ALL, NULL); + proto_send_end_server(PROTO_SEND_ALL, NULL); - assert(listClient != NULL); + assert(listClient != NULL); - destroyListItem(listClient, destroyUdpClient); + destroyListItem(listClient, destroyUdpClient); - destroyTimer(listServerTimer); + destroyTimer(listServerTimer); - quitUdpServer(); + quitUdpServer(); } diff --git a/src/base/server.h b/src/base/server.h index b95b9d9..b7e9433 100644 --- a/src/base/server.h +++ b/src/base/server.h @@ -1,51 +1,50 @@ #ifndef MY_SERVER -#define MY_SERVER +# define MY_SERVER -#include <time.h> +# include <time.h> -#include "list.h" -#include "tux.h" -#include "myTimer.h" -#include "protect.h" -#include "buffer.h" +# include "list.h" +# include "tux.h" +# include "myTimer.h" +# include "protect.h" +# include "buffer.h" -#ifndef PUBLIC_SERVER -#include "interface.h" -#endif +# ifndef PUBLIC_SERVER +# include "interface.h" +# endif -#include "udp.h" +# include "udp.h" -#define SERVER_TIMEOUT 1000 -#define SERVER_TIME_SYNC 1000 -#define SERVER_TIME_PING 1000 -#define SERVER_MAX_CLIENTS 100 +# define SERVER_TIMEOUT 1000 +# define SERVER_TIME_SYNC 1000 +# define SERVER_TIME_PING 1000 +# define SERVER_MAX_CLIENTS 100 -#define SERVER_INDEX_ROOT_TUX 0 +# define SERVER_INDEX_ROOT_TUX 0 -#define CLIENT_TYPE_UDP 1 -#define CLIENT_TYPE_TCP 2 +# define CLIENT_TYPE_UDP 1 +# define CLIENT_TYPE_TCP 2 -typedef struct client_struct -{ - int type; +typedef struct client_struct { + int type; - sock_udp_t *socket_udp; + sock_udp_t *socket_udp; - buffer_t *recvBuffer; - buffer_t *sendBuffer; + buffer_t *recvBuffer; + buffer_t *sendBuffer; - int status; + int status; - tux_t *tux; + tux_t *tux; - protect_t *protect; + protect_t *protect; - list_t *listSendMsg; - list_t *listRecvMsg; + list_t *listSendMsg; + list_t *listRecvMsg; - list_t *listSeesShot; + list_t *listSeesShot; } client_t; extern int initServer(char *ip4, int port4, char *ip6, int port6); diff --git a/src/base/serverSelect.c b/src/base/serverSelect.c index 710142f..e25c91f 100644 --- a/src/base/serverSelect.c +++ b/src/base/serverSelect.c @@ -10,12 +10,12 @@ #include <sys/time.h> #ifndef __WIN32__ -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/select.h> +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <sys/select.h> #else -#include <io.h> -#include <winsock2.h> +# include <io.h> +# include <winsock2.h> #endif #include "server.h" @@ -25,93 +25,86 @@ static fd_set readfds; static fd_set writefds; static int max_fd; -void -restartSelect() +void restartSelect() { #ifndef PUBLIC_SERVER - tv.tv_sec = 0; - tv.tv_usec = 0; + tv.tv_sec = 0; + tv.tv_usec = 0; #endif #ifdef PUBLIC_SERVER - tv.tv_sec = 0; - tv.tv_usec = 1000; + tv.tv_sec = 0; + tv.tv_usec = 1000; #endif - FD_ZERO(&readfds); - FD_ZERO(&writefds); - max_fd = 0; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + max_fd = 0; } -void -addSockToSelectRead(int sock) +void addSockToSelectRead(int sock) { - //printf("addSockToSelectRead %d\n", sock); + //printf("addSockToSelectRead %d\n", sock); - FD_SET(sock, &readfds); + FD_SET(sock, &readfds); - if (sock > max_fd) { - max_fd = sock; - } + if (sock > max_fd) { + max_fd = sock; + } } -void -addSockToSelectWrite(int sock) +void addSockToSelectWrite(int sock) { - //printf("addSockToSelectWrite %d\n", sock); + //printf("addSockToSelectWrite %d\n", sock); - FD_SET(sock, &writefds); + FD_SET(sock, &writefds); - if (sock > max_fd) { - max_fd = sock; - } + if (sock > max_fd) { + max_fd = sock; + } } -int -actionSelect() +int actionSelect() { - int ret; + int ret; #ifdef PUBLIC_SERVER - list_t *listClient; - listClient = getListServerClient(); - - if (listClient->count == 0) { - ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, NULL); - setServerTimer(); - } - else { - ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); - } + list_t *listClient; + listClient = getListServerClient(); + + if (listClient->count == 0) { + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, NULL); + setServerTimer(); + } else { + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); + } #endif #ifndef PUBLIC_SERVER - ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); #endif - return ret; + return ret; } -int -isChangeSockInSelectRead(int sock) +int isChangeSockInSelectRead(int sock) { - int ret; + int ret; - ret = FD_ISSET(sock, &readfds); + ret = FD_ISSET(sock, &readfds); - //printf("isChangeSockInSelect %d -> %d\n", sock, ret); + //printf("isChangeSockInSelect %d -> %d\n", sock, ret); - return ret; + return ret; } -int -isChangeSockInSelectWrite(int sock) +int isChangeSockInSelectWrite(int sock) { - int ret; + int ret; - ret = FD_ISSET(sock, &writefds); + ret = FD_ISSET(sock, &writefds); - //printf("isChangeSockInSelect %d -> %d\n", sock, ret); + //printf("isChangeSockInSelect %d -> %d\n", sock, ret); - return ret; + return ret; } diff --git a/src/base/serverSelect.h b/src/base/serverSelect.h index 5873956..390dfcc 100644 --- a/src/base/serverSelect.h +++ b/src/base/serverSelect.h @@ -1,7 +1,7 @@ #ifndef SERVER_SELECT -#define SERVER_SELECT +# define SERVER_SELECT extern void restartSelect(); extern void addSockToSelectRead(int sock); diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c index 013d41c..afe258d 100644 --- a/src/base/serverSendMsg.c +++ b/src/base/serverSendMsg.c @@ -11,137 +11,131 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -#include "screen_world.h" +# include "screen_world.h" #endif -static void -addMsgClient(client_t * p, char *msg, int type, int id) +static void addMsgClient(client_t * p, char *msg, int type, int id) { - assert(p != NULL); - assert(msg != NULL); + assert(p != NULL); + assert(msg != NULL); - if (p->status != NET_STATUS_ZOMBIE) { - addMsgInCheckFront(p->listSendMsg, msg, type, id); - } + if (p->status != NET_STATUS_ZOMBIE) { + addMsgInCheckFront(p->listSendMsg, msg, type, id); + } } -static void -addMsgAllClientBut(char *msg, client_t * p, int type, int id) +static void addMsgAllClientBut(char *msg, client_t * p, int type, int id) { - list_t *listClient; - client_t *thisClient; - int i; + list_t *listClient; + client_t *thisClient; + int i; - assert(msg != NULL); + assert(msg != NULL); - listClient = getListServerClient(); + listClient = getListServerClient(); - for (i = 0; i < listClient->count; i++) { - thisClient = (client_t *) listClient->list[i]; + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; - if (thisClient->tux != NULL && thisClient != p) { - addMsgClient(thisClient, msg, type, id); - } - } + if (thisClient->tux != NULL && thisClient != p) { + addMsgClient(thisClient, msg, type, id); + } + } } -static void -addMsgAllClient(char *msg, int type, int id) +static void addMsgAllClient(char *msg, int type, int id) { - assert(msg != NULL); + assert(msg != NULL); - addMsgAllClientBut(msg, NULL, type, id); + addMsgAllClientBut(msg, NULL, type, id); } -static void -addMsgAllClientSeesTux(char *msg, tux_t * tux, int type, int id) +static void addMsgAllClientSeesTux(char *msg, tux_t * tux, int type, int id) { - list_t *listHelp; - arena_t *arena; - space_t *space; - int x, y, w, h; - int i; + list_t *listHelp; + arena_t *arena; + space_t *space; + int x, y, w, h; + int i; - assert(msg != NULL); + assert(msg != NULL); - arena = getCurrentArena(); - space = arena->spaceTux; + arena = getCurrentArena(); + space = arena->spaceTux; - x = tux->x - WINDOW_SIZE_X; - y = tux->y - WINDOW_SIZE_Y; + x = tux->x - WINDOW_SIZE_X; + y = tux->y - WINDOW_SIZE_Y; - w = 2 * WINDOW_SIZE_X; - h = 2 * WINDOW_SIZE_Y; + w = 2 * WINDOW_SIZE_X; + h = 2 * WINDOW_SIZE_Y; - if (x < 0) - x = 0; - if (y < 0) - y = 0; - if (w + x >= arena->w) - w = arena->w - (x + 1); - if (h + y >= arena->h) - h = arena->h - (y + 1); + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (w + x >= arena->w) + w = arena->w - (x + 1); + if (h + y >= arena->h) + h = arena->h - (y + 1); - listHelp = newList(); + listHelp = newList(); - getObjectFromSpace(space, x, y, w, h, listHelp); - //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); + getObjectFromSpace(space, x, y, w, h, listHelp); + //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); - for (i = 0; i < listHelp->count; i++) { - tux_t *thisTux; - client_t *thisClient; + for (i = 0; i < listHelp->count; i++) { + tux_t *thisTux; + client_t *thisClient; - thisTux = (tux_t *) listHelp->list[i]; + thisTux = (tux_t *) listHelp->list[i]; - if (thisTux == tux) { - continue; - } + if (thisTux == tux) { + continue; + } - thisClient = thisTux->client; + thisClient = thisTux->client; - if (thisClient != NULL) { - addMsgClient(thisClient, msg, type, id); - } - } + if (thisClient != NULL) { + addMsgClient(thisClient, msg, type, id); + } + } - destroyList(listHelp); + destroyList(listHelp); } -void -protoSendClient(int type, client_t * client, char *msg, int type2, int id) +void protoSendClient(int type, client_t * client, char *msg, int type2, int id) { - assert(msg != NULL); - - switch (type) { - case PROTO_SEND_ONE: - assert(client != NULL); - addMsgClient(client, msg, type2, id); - break; - case PROTO_SEND_ALL: - assert(client == NULL); - addMsgAllClient(msg, type2, id); - break; - case PROTO_SEND_BUT: - assert(client != NULL); - addMsgAllClientBut(msg, client, type2, id); - break; - case PROTO_SEND_ALL_SEES_TUX: + assert(msg != NULL); + + switch (type) { + case PROTO_SEND_ONE: + assert(client != NULL); + addMsgClient(client, msg, type2, id); + break; + case PROTO_SEND_ALL: + assert(client == NULL); + addMsgAllClient(msg, type2, id); + break; + case PROTO_SEND_BUT: + assert(client != NULL); + addMsgAllClientBut(msg, client, type2, id); + break; + case PROTO_SEND_ALL_SEES_TUX: #ifndef PUBLIC_SERVER - if (client != NULL) { - addMsgAllClientSeesTux(msg, client->tux, type2, id); - } - else { - addMsgAllClientSeesTux(msg, - getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), - type2, id); - } + if (client != NULL) { + addMsgAllClientSeesTux(msg, client->tux, type2, id); + } else { + addMsgAllClientSeesTux(msg, + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), + type2, id); + } #endif #ifdef PUBLIC_SERVER - addMsgAllClientSeesTux(msg, client->tux, type2, id); + addMsgAllClientSeesTux(msg, client->tux, type2, id); #endif - break; - default: - assert(!_("Type variable has a really wierd value!")); - break; - } + break; + default: + assert(!_("Type variable has a really wierd value!")); + break; + } } diff --git a/src/base/serverSendMsg.h b/src/base/serverSendMsg.h index c09c0f9..7bb19a3 100644 --- a/src/base/serverSendMsg.h +++ b/src/base/serverSendMsg.h @@ -1,16 +1,16 @@ #ifndef SERVER_SEND_MSG_H -#define SERVER_SEND_MSG_H +# define SERVER_SEND_MSG_H -#include "server.h" +# include "server.h" -#define PROTO_SEND_ONE 0 -#define PROTO_SEND_ALL 1 -#define PROTO_SEND_BUT 3 -#define PROTO_SEND_ALL_SEES_TUX 4 +# define PROTO_SEND_ONE 0 +# define PROTO_SEND_ALL 1 +# define PROTO_SEND_BUT 3 +# define PROTO_SEND_ALL_SEES_TUX 4 extern void protoSendClient(int type, client_t * client, char *msg, int type2, - int id); + int id); #endif diff --git a/src/base/shareFunction.c b/src/base/shareFunction.c index fa7d56b..e6e912a 100644 --- a/src/base/shareFunction.c +++ b/src/base/shareFunction.c @@ -8,64 +8,57 @@ #include "list.h" #include "shareFunction.h" -typedef struct share_fce_item_struct -{ - char *name; - void *function; +typedef struct share_fce_item_struct { + char *name; + void *function; } share_fce_item_t; static list_t *listShareFce; -static share_fce_item_t * -newShareFceItem(char *name, void *function) +static share_fce_item_t *newShareFceItem(char *name, void *function) { - share_fce_item_t *new; + share_fce_item_t *new; - new = malloc(sizeof(share_fce_item_t)); - new->name = strdup(name); - new->function = function; - return new; + new = malloc(sizeof(share_fce_item_t)); + new->name = strdup(name); + new->function = function; + return new; } -static void -destroyShareFce(share_fce_item_t * p) +static void destroyShareFce(share_fce_item_t * p) { - free(p->name); - free(p); + free(p->name); + free(p); } -void -initShareFunction() +void initShareFunction() { - listShareFce = newList(); + listShareFce = newList(); } -void -addToShareFce(char *name, void *function) +void addToShareFce(char *name, void *function) { #ifdef DEBUG - printf(_("Adding \"%s\" to share function.\n"), name); + printf(_("Adding \"%s\" to share function.\n"), name); #endif - addList(listShareFce, newShareFceItem(name, function)); + addList(listShareFce, newShareFceItem(name, function)); } -void * -getShareFce(char *name) +void *getShareFce(char *name) { - int i; + int i; - for (i = 0; i < listShareFce->count; i++) { - share_fce_item_t *this; + for (i = 0; i < listShareFce->count; i++) { + share_fce_item_t *this; - this = (share_fce_item_t *) listShareFce->list[i]; - if (strcmp(this->name, name) == 0) - return this->function; - } - return NULL; + this = (share_fce_item_t *) listShareFce->list[i]; + if (strcmp(this->name, name) == 0) + return this->function; + } + return NULL; } -void -quitShareFunction() +void quitShareFunction() { - destroyListItem(listShareFce, destroyShareFce); + destroyListItem(listShareFce, destroyShareFce); } diff --git a/src/base/shareFunction.h b/src/base/shareFunction.h index de4677e..226c377 100644 --- a/src/base/shareFunction.h +++ b/src/base/shareFunction.h @@ -1,6 +1,6 @@ #ifndef SHARE_FUNCTION_H -#define SHARE_FUNCTION_H +# define SHARE_FUNCTION_H extern void initShareFunction(); extern void addToShareFce(char *name, void *function); diff --git a/src/base/shot.c b/src/base/shot.c index 2fe1490..a233712 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -12,13 +12,13 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -#include "image.h" -#include "layer.h" -#include "screen_world.h" +# include "image.h" +# include "layer.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif #ifndef PUBLIC_SERVER @@ -32,350 +32,332 @@ static image_t *g_shot_bombball; static bool_t isShotInit = FALSE; -bool_t -isShotInicialized() +bool_t isShotInicialized() { - return isShotInit; + return isShotInit; } -void -initShot() +void initShot() { #ifndef PUBLIC_SERVER - assert(isImageInicialized() == TRUE); + assert(isImageInicialized() == TRUE); #endif #ifndef PUBLIC_SERVER - g_shot_simple = - addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); - g_shot_lasserX = - addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX", - IMAGE_GROUP_BASE); - g_shot_lasserY = - addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY", - IMAGE_GROUP_BASE); - g_shot_bombball = - addImageData("bombball.png", IMAGE_ALPHA, "bombball", - IMAGE_GROUP_BASE); + g_shot_simple = + addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); + g_shot_lasserX = + addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX", + IMAGE_GROUP_BASE); + g_shot_lasserY = + addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY", + IMAGE_GROUP_BASE); + g_shot_bombball = + addImageData("bombball.png", IMAGE_ALPHA, "bombball", + IMAGE_GROUP_BASE); #endif - isShotInit = TRUE; + isShotInit = TRUE; } -shot_t * -newShot(int x, int y, int px, int py, int gun, int author_id) +shot_t *newShot(int x, int y, int px, int py, int gun, int author_id) { - shot_t *new; - tux_t *author; + shot_t *new; + tux_t *author; - new = malloc(sizeof(shot_t)); - memset(new, 0, sizeof(shot_t)); + new = malloc(sizeof(shot_t)); + memset(new, 0, sizeof(shot_t)); - new->id = getNewID(); - new->x = x; - new->y = y; - new->px = px; - new->py = py; - new->gun = gun; - new->author_id = author_id; + new->id = getNewID(); + new->x = x; + new->y = y; + new->px = px; + new->py = py; + new->gun = gun; + new->author_id = author_id; - new->position = POSITION_UNKNOWN; + new->position = POSITION_UNKNOWN; - author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id); + author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id); - if (author != NULL) { - new->position = author->position; - } + if (author != NULL) { + new->position = author->position; + } - new->isCanKillAuthor = FALSE; - new->del = FALSE; + new->isCanKillAuthor = FALSE; + new->del = FALSE; - switch (gun) { - case GUN_SIMPLE: - new->w = GUN_SHOT_WIDTH; - new->h = GUN_SHOT_HEIGHT; + switch (gun) { + case GUN_SIMPLE: + new->w = GUN_SHOT_WIDTH; + new->h = GUN_SHOT_HEIGHT; #ifndef PUBLIC_SERVER - new->img = g_shot_simple; + new->img = g_shot_simple; #endif - break; - - case GUN_LASSER: - switch (author->position) { - case TUX_RIGHT: - case TUX_LEFT: - new->w = GUN_LASSER_HORIZONTAL; - new->h = GUN_SHOT_VERTICAL; + break; + + case GUN_LASSER: + switch (author->position) { + case TUX_RIGHT: + case TUX_LEFT: + new->w = GUN_LASSER_HORIZONTAL; + new->h = GUN_SHOT_VERTICAL; #ifndef PUBLIC_SERVER - new->img = g_shot_lasserX; + new->img = g_shot_lasserX; #endif - break; - case TUX_UP: - case TUX_DOWN: - new->w = GUN_SHOT_VERTICAL; - new->h = GUN_LASSER_HORIZONTAL; + break; + case TUX_UP: + case TUX_DOWN: + new->w = GUN_SHOT_VERTICAL; + new->h = GUN_LASSER_HORIZONTAL; #ifndef PUBLIC_SERVER - new->img = g_shot_lasserY; + new->img = g_shot_lasserY; #endif - break; - } - break; + break; + } + break; - case GUN_BOMBBALL: - new->w = GUN_BOMBBALL_WIDTH; - new->h = GUN_BOMBBALL_HEIGHT; + case GUN_BOMBBALL: + new->w = GUN_BOMBBALL_WIDTH; + new->h = GUN_BOMBBALL_HEIGHT; #ifndef PUBLIC_SERVER - new->img = g_shot_bombball; + new->img = g_shot_bombball; #endif - break; + break; - default: - assert(!_("Type variable has a really wierd value!")); - break; - } + default: + assert(!_("Type variable has a really wierd value!")); + break; + } - return new; + return new; } -void -replaceShotID(shot_t * shot, int id) +void replaceShotID(shot_t * shot, int id) { - replaceID(shot->id, id); - shot->id = id; + replaceID(shot->id, id); + shot->id = id; } -void -getStatusShot(void *p, int *id, int *x, int *y, int *w, int *h) +void getStatusShot(void *p, int *id, int *x, int *y, int *w, int *h) { - shot_t *shot; - - shot = p; - *id = shot->id; - *x = shot->x; - *y = shot->y; - *w = shot->w; - *h = shot->h; + shot_t *shot; + + shot = p; + *id = shot->id; + *x = shot->x; + *y = shot->y; + *w = shot->w; + *h = shot->h; } -void -setStatusShot(void *p, int x, int y, int w, int h) +void setStatusShot(void *p, int x, int y, int w, int h) { - shot_t *shot; + shot_t *shot; - shot = p; - shot->x = x; - shot->y = y; - shot->w = w; - shot->h = h; + shot = p; + shot->x = x; + shot->y = y; + shot->w = w; + shot->h = h; } #ifndef PUBLIC_SERVER -void -drawShot(shot_t * p) +void drawShot(shot_t * p) { - assert(p != NULL); - addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER); + assert(p != NULL); + addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER); } -void -drawListShot(list_t * listShot) +void drawListShot(list_t * listShot) { - shot_t *thisShot; - int i; + shot_t *thisShot; + int i; - assert(listShot != NULL); + assert(listShot != NULL); - for (i = 0; i < listShot->count; i++) { - thisShot = (shot_t *) listShot->list[i]; - assert(thisShot != NULL); - drawShot(thisShot); - } + for (i = 0; i < listShot->count; i++) { + thisShot = (shot_t *) listShot->list[i]; + assert(thisShot != NULL); + drawShot(thisShot); + } } #endif -static int -getRandomCourse(int x, int y) +static int getRandomCourse(int x, int y) { - int ret = -1; // no warnning - - do { - switch (random() % 3) { - case 0: - ret = y; - break; - case 1: - ret = -y; - break; - case 2: - ret = 0; - break; - } - } while (ret == x); - - return ret; + int ret = -1; // no warnning + + do { + switch (random() % 3) { + case 0: + ret = y; + break; + case 1: + ret = -y; + break; + case 2: + ret = 0; + break; + } + } while (ret == x); + + return ret; } -void -boundBombBall(shot_t * shot) +void boundBombBall(shot_t * shot) { - if (shot->gun != GUN_BOMBBALL) { - return; - } + if (shot->gun != GUN_BOMBBALL) { + return; + } - shot->px = getRandomCourse(shot->px, +10); - shot->py = getRandomCourse(shot->py, +10); - shot->isCanKillAuthor = 1; + shot->px = getRandomCourse(shot->px, +10); + shot->py = getRandomCourse(shot->py, +10); + shot->isCanKillAuthor = 1; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + } } -void -transformOnlyLasser(shot_t * shot) +void transformOnlyLasser(shot_t * shot) { - space_t *space; - int mustRefesh = 0; + space_t *space; + int mustRefesh = 0; - space = getCurrentArena()->spaceShot; + space = getCurrentArena()->spaceShot; - if (getObjectFromSpaceWithID(space, shot->id) != NULL) { - mustRefesh = 1; - } + if (getObjectFromSpaceWithID(space, shot->id) != NULL) { + mustRefesh = 1; + } - if (mustRefesh) { - delObjectFromSpace(space, shot); - } + if (mustRefesh) { + delObjectFromSpace(space, shot); + } - switch (shot->position) { - case TUX_RIGHT: - case TUX_LEFT: - shot->w = GUN_LASSER_HORIZONTAL; - shot->h = GUN_SHOT_VERTICAL; + switch (shot->position) { + case TUX_RIGHT: + case TUX_LEFT: + shot->w = GUN_LASSER_HORIZONTAL; + shot->h = GUN_SHOT_VERTICAL; #ifndef PUBLIC_SERVER - shot->img = g_shot_lasserX; + shot->img = g_shot_lasserX; #endif - break; - case TUX_UP: - case TUX_DOWN: - shot->w = GUN_SHOT_VERTICAL; - shot->h = GUN_LASSER_HORIZONTAL; + break; + case TUX_UP: + case TUX_DOWN: + shot->w = GUN_SHOT_VERTICAL; + shot->h = GUN_LASSER_HORIZONTAL; #ifndef PUBLIC_SERVER - shot->img = g_shot_lasserY; + shot->img = g_shot_lasserY; #endif - break; - } + break; + } - if (mustRefesh) { - addObjectToSpace(space, shot); - } + if (mustRefesh) { + addObjectToSpace(space, shot); + } } -static void -action_moveShot(space_t * space, shot_t * shot, void *p) +static void action_moveShot(space_t * space, shot_t * shot, void *p) { - int new_x, new_y; - arena_t *arena; + int new_x, new_y; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - new_x = shot->x + shot->px; - new_y = shot->y + shot->py; + new_x = shot->x + shot->px; + new_y = shot->y + shot->py; - moveObjectInSpace(space, shot, new_x, new_y); + moveObjectInSpace(space, shot, new_x, new_y); - if (shot->x + shot->w < 0 || shot->x > arena->w || - shot->y + shot->h < 0 || shot->y > arena->h) { - delObjectFromSpaceWithObject(space, shot, destroyShot); - } + if (shot->x + shot->w < 0 || shot->x > arena->w || + shot->y + shot->h < 0 || shot->y > arena->h) { + delObjectFromSpaceWithObject(space, shot, destroyShot); + } } -void -eventMoveListShot(arena_t * arena) +void eventMoveListShot(arena_t * arena) { - actionSpace(arena->spaceShot, action_moveShot, NULL); + actionSpace(arena->spaceShot, action_moveShot, NULL); } -static int -isValueInList(list_t * list, int x) +static int isValueInList(list_t * list, int x) { - int i; + int i; - for (i = 0; i < list->count; i++) { - if (x == (*(int *) list->list[i])) { - return 1; - } - } + for (i = 0; i < list->count; i++) { + if (x == (*(int *) list->list[i])) { + return 1; + } + } - return 0; + return 0; } -static void -action_check(space_t * space, shot_t * shot, client_t * client) +static void action_check(space_t * space, shot_t * shot, client_t * client) { - if (isValueInList(client->listSeesShot, shot->id) == 0) { - addList(client->listSeesShot, newInt(shot->id)); - proto_send_shot_server(PROTO_SEND_ONE, client, shot); - } + if (isValueInList(client->listSeesShot, shot->id) == 0) { + addList(client->listSeesShot, newInt(shot->id)); + proto_send_shot_server(PROTO_SEND_ONE, client, shot); + } } -void -checkShotIsInTuxScreen(arena_t * arena) +void checkShotIsInTuxScreen(arena_t * arena) { - int screen_x, screen_y; - tux_t *thisTux; - client_t *thisClient; - list_t *listClient; - int i; + int screen_x, screen_y; + tux_t *thisTux; + client_t *thisClient; + list_t *listClient; + int i; - if (getNetTypeGame() != NET_GAME_TYPE_SERVER) { - return; - } + if (getNetTypeGame() != NET_GAME_TYPE_SERVER) { + return; + } - listClient = getListServerClient(); + listClient = getListServerClient(); - for (i = 0; i < listClient->count; i++) { - thisClient = (client_t *) listClient->list[i]; - thisTux = (tux_t *) thisClient->tux; - int del = 0; + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; + thisTux = (tux_t *) thisClient->tux; + int del = 0; - if (thisTux == NULL || thisTux->control != TUX_CONTROL_NET) { - continue; - } + if (thisTux == NULL || thisTux->control != TUX_CONTROL_NET) { + continue; + } - getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y, - WINDOW_SIZE_X, WINDOW_SIZE_Y); + getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y, + WINDOW_SIZE_X, WINDOW_SIZE_Y); - actionSpaceFromLocation(arena->spaceShot, action_check, - thisClient, screen_x, screen_y, WINDOW_SIZE_X, - WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceShot, action_check, + thisClient, screen_x, screen_y, WINDOW_SIZE_X, + WINDOW_SIZE_Y); - while (thisClient->listSeesShot->count > 100) { - delListItem(thisClient->listSeesShot, 0, free); - del++; - } + while (thisClient->listSeesShot->count > 100) { + delListItem(thisClient->listSeesShot, 0, free); + del++; + } - //if( del > 0 )printf("del = %d\n", del); - } + //if( del > 0 )printf("del = %d\n", del); + } } -void -destroyShot(shot_t * p) +void destroyShot(shot_t * p) { - assert(p != NULL); + assert(p != NULL); - delID(p->id); + delID(p->id); - free(p); + free(p); } -void -quitShot() +void quitShot() { - isShotInit = FALSE; + isShotInit = FALSE; } diff --git a/src/base/shot.h b/src/base/shot.h index 6a2a8e2..a9c04fe 100644 --- a/src/base/shot.h +++ b/src/base/shot.h @@ -1,35 +1,34 @@ #ifndef SHOT_H -#define SHOT_H -#ifdef __WIN32__ -#define random rand -#endif +# define SHOT_H +# ifdef __WIN32__ +# define random rand +# endif -#include "main.h" -#include "list.h" -#include "tux.h" -#include "arena.h" -#ifndef PUBLIC_SERVER -#include "image.h" -#endif +# include "main.h" +# include "list.h" +# include "tux.h" +# include "arena.h" +# ifndef PUBLIC_SERVER +# include "image.h" +# endif -typedef struct shot_struct -{ - int id; - int x; - int y; - int w; - int h; - int px; - int py; - int position; - int gun; - int author_id; - bool_t isCanKillAuthor; - bool_t del; -#ifndef PUBLIC_SERVER - image_t *img; -#endif +typedef struct shot_struct { + int id; + int x; + int y; + int w; + int h; + int px; + int py; + int position; + int gun; + int author_id; + bool_t isCanKillAuthor; + bool_t del; +# ifndef PUBLIC_SERVER + image_t *img; +# endif } shot_t; extern bool_t isShotInicialized(); @@ -39,12 +38,12 @@ extern shot_t *getShotID(list_t * listShot, int id); extern void replaceShotID(shot_t * shot, int id); extern void getStatusShot(void *p, int *id, int *x, int *y, int *w, int *h); extern void setStatusShot(void *p, int x, int y, int w, int h); -#ifndef PUBLIC_SERVER +# ifndef PUBLIC_SERVER extern void drawShot(shot_t * p); extern void drawListShot(list_t * listShot); -#endif +# endif extern int isConflictWithListShot(list_t * listShot, int x, int y, int w, - int h); + int h); extern void eventMoveListShot(arena_t * arena); extern void checkShotIsInTuxScreen(arena_t * arena); extern void boundBombBall(shot_t * shot); diff --git a/src/base/space.c b/src/base/space.c index dff34c5..0988011 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -9,378 +9,364 @@ #include "space.h" #include "index.h" -zone_t * -newZone() +zone_t *newZone() { - zone_t *new; + zone_t *new; - new = malloc(sizeof(zone_t)); - new->list = newList(); + new = malloc(sizeof(zone_t)); + new->list = newList(); - return new; + return new; } -void -destroyZone(zone_t * p) +void destroyZone(zone_t * p) { - assert(p != NULL); + assert(p != NULL); - destroyList(p->list); - free(p); + destroyList(p->list); + free(p); } static int my_conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, int w2, - int h2) + int h2) { - return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); + return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); } -space_t * -newSpace(int w, int h, int segW, int segH, - void (*getStatus) (void *p, int *id, int *x, int *y, int *w, int *h), - void (*setStatus) (void *p, int x, int y, int w, int h)) +space_t *newSpace(int w, int h, int segW, int segH, + void (*getStatus) (void *p, int *id, int *x, int *y, int *w, + int *h), void (*setStatus) (void *p, + int x, int y, + int w, int h)) { - space_t *new; - int i, j; + space_t *new; + int i, j; - new = malloc(sizeof(space_t)); - memset(new, 0, sizeof(space_t)); + new = malloc(sizeof(space_t)); + memset(new, 0, sizeof(space_t)); - new->w = w / segW + 1; - new->h = h / segH + 1; - new->segW = segW; - new->segH = segH; - new->getStatus = getStatus; - new->setStatus = setStatus; - new->listIndex = newIndex(); + new->w = w / segW + 1; + new->h = h / segH + 1; + new->segW = segW; + new->segH = segH; + new->getStatus = getStatus; + new->setStatus = setStatus; + new->listIndex = newIndex(); - new->zone = malloc(new->w * sizeof(list_t **)); + new->zone = malloc(new->w * sizeof(list_t **)); - for (i = 0; i < new->w; i++) { - new->zone[i] = malloc(new->h * sizeof(list_t *)); - } + for (i = 0; i < new->w; i++) { + new->zone[i] = malloc(new->h * sizeof(list_t *)); + } - for (i = 0; i < new->h; i++) { - for (j = 0; j < new->w; j++) { - new->zone[j][i] = newZone(); - } - } + for (i = 0; i < new->h; i++) { + for (j = 0; j < new->w; j++) { + new->zone[j][i] = newZone(); + } + } - return new; + return new; } static void getSegment(space_t * p, int x, int y, int w, int h, - int *segX, int *segY, int *segW, int *segH) + int *segX, int *segY, int *segW, int *segH) { - *segX = x / p->segW; - *segY = y / p->segH; - *segW = ((x + w) / p->segW + 1) - *segX; - *segH = ((y + h) / p->segH + 1) - *segY; + *segX = x / p->segW; + *segY = y / p->segH; + *segW = ((x + w) / p->segW + 1) - *segX; + *segH = ((y + h) / p->segH + 1) - *segY; } -int -getSpaceCount(space_t * p) +int getSpaceCount(space_t * p) { - return p->listIndex->count; + return p->listIndex->count; } -void * -getItemFromSpace(space_t * p, int offset) +void *getItemFromSpace(space_t * p, int offset) { - index_item_t *this; + index_item_t *this; - this = (index_item_t *) p->listIndex->list[offset]; - return this->data; + this = (index_item_t *) p->listIndex->list[offset]; + return this->data; } -void -addObjectToSpace(space_t * p, void *item) +void addObjectToSpace(space_t * p, void *item) { - int segX, segY, segW, segH; - int id, x, y, w, h; - int i, j; + int segX, segY, segW, segH; + int id, x, y, w, h; + int i, j; - p->getStatus(item, &id, &x, &y, &w, &h); - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - for (i = segY; i < segY + segH; i++) { - for (j = segX; j < segX + segW; j++) { - if (j < 0 || j >= p->w || i < 0 || i >= p->h) { - continue; - } + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } - addList(p->zone[j][i]->list, item); - } - } + addList(p->zone[j][i]->list, item); + } + } - addToIndex(p->listIndex, id, item); + addToIndex(p->listIndex, id, item); } -void -getObjectFromSpace(space_t * p, int x, int y, int w, int h, list_t * list) +void getObjectFromSpace(space_t * p, int x, int y, int w, int h, list_t * list) { - int segX, segY, segW, segH; - int id, this_x, this_y, this_w, this_h; - int i, j, k; - - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for (i = segY; i < segY + segH; i++) { - for (j = segX; j < segX + segW; j++) { - void *this; - - if (j < 0 || j >= p->w || i < 0 || i >= p->h) { - continue; - } - - for (k = 0; k < p->zone[j][i]->list->count; k++) { - this = p->zone[j][i]->list->list[k]; - p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); - - if (my_conflictSpace - (x, y, w, h, this_x, this_y, this_w, this_h) - && searchListItem(list, this) == -1) { - addList(list, this); - } - } - } - } + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; + + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + void *this; + + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + for (k = 0; k < p->zone[j][i]->list->count; k++) { + this = p->zone[j][i]->list->list[k]; + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + + if (my_conflictSpace + (x, y, w, h, this_x, this_y, this_w, this_h) + && searchListItem(list, this) == -1) { + addList(list, this); + } + } + } + } } -void * -getObjectFromSpaceWithID(space_t * space, int id) +void *getObjectFromSpaceWithID(space_t * space, int id) { - return getFromIndex(space->listIndex, id); + return getFromIndex(space->listIndex, id); } -int -isConflictWithObjectFromSpace(space_t * p, int x, int y, int w, int h) +int isConflictWithObjectFromSpace(space_t * p, int x, int y, int w, int h) { - int segX, segY, segW, segH; - int id, this_x, this_y, this_w, this_h; - int i, j, k; + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - for (i = segY; i < segY + segH; i++) { - for (j = segX; j < segX + segW; j++) { - void *this; + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + void *this; - if (j < 0 || j >= p->w || i < 0 || i >= p->h) { - continue; - } + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } - for (k = 0; k < p->zone[j][i]->list->count; k++) { - this = p->zone[j][i]->list->list[k]; - p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + for (k = 0; k < p->zone[j][i]->list->count; k++) { + this = p->zone[j][i]->list->list[k]; + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); - if (my_conflictSpace - (x, y, w, h, this_x, this_y, this_w, this_h)) { - return 1; - } - } - } - } + if (my_conflictSpace + (x, y, w, h, this_x, this_y, this_w, this_h)) { + return 1; + } + } + } + } - return 0; + return 0; } int isConflictWithObjectFromSpaceBut(space_t * p, int x, int y, int w, int h, - void *but) + void *but) { - int segX, segY, segW, segH; - int id, this_x, this_y, this_w, this_h; - int i, j, k; + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - for (i = segY; i < segY + segH; i++) { - for (j = segX; j < segX + segW; j++) { - void *this; + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + void *this; - if (j < 0 || j >= p->w || i < 0 || i >= p->h) { - continue; - } + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } - for (k = 0; k < p->zone[j][i]->list->count; k++) { - this = p->zone[j][i]->list->list[k]; + for (k = 0; k < p->zone[j][i]->list->count; k++) { + this = p->zone[j][i]->list->list[k]; - if (this == but) { - continue; - } + if (this == but) { + continue; + } - p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); - if (my_conflictSpace - (x, y, w, h, this_x, this_y, this_w, this_h)) { - return 1; - } - } - } - } + if (my_conflictSpace + (x, y, w, h, this_x, this_y, this_w, this_h)) { + return 1; + } + } + } + } - return 0; + return 0; } -void -delObjectFromSpace(space_t * p, void *item) +void delObjectFromSpace(space_t * p, void *item) { - int segX, segY, segW, segH; - int id, x, y, w, h; - int index; - int i, j; - - p->getStatus(item, &id, &x, &y, &w, &h); - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for (i = segY; i < segY + segH; i++) { - for (j = segX; j < segX + segW; j++) { - if (j < 0 || j >= p->w || i < 0 || i >= p->h) { - continue; - } - - index = searchListItem(p->zone[j][i]->list, item); - assert(index != -1); - delList(p->zone[j][i]->list, index); - } - } - - delFromIndex(p->listIndex, id); + int segX, segY, segW, segH; + int id, x, y, w, h; + int index; + int i, j; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + index = searchListItem(p->zone[j][i]->list, item); + assert(index != -1); + delList(p->zone[j][i]->list, index); + } + } + + delFromIndex(p->listIndex, id); } -void -delObjectFromSpaceWithObject(space_t * p, void *item, void *f) +void delObjectFromSpaceWithObject(space_t * p, void *item, void *f) { - void (*fce) (void *param); + void (*fce) (void *param); - fce = f; + fce = f; - delObjectFromSpace(p, item); - fce(item); + delObjectFromSpace(p, item); + fce(item); } -void -moveObjectInSpace(space_t * p, void *item, int move_x, int move_y) +void moveObjectInSpace(space_t * p, void *item, int move_x, int move_y) { - int old_segX, old_segY, old_segW, old_segH; - int new_segX, new_segY, new_segW, new_segH; - int id, x, y, w, h; - - p->getStatus(item, &id, &x, &y, &w, &h); - getSegment(p, x, y, w, h, &old_segX, &old_segY, &old_segW, &old_segH); - getSegment(p, move_x, move_y, w, h, &new_segX, &new_segY, &new_segW, - &new_segH); + int old_segX, old_segY, old_segW, old_segH; + int new_segX, new_segY, new_segW, new_segH; + int id, x, y, w, h; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &old_segX, &old_segY, &old_segW, &old_segH); + getSegment(p, move_x, move_y, w, h, &new_segX, &new_segY, &new_segW, + &new_segH); /* printf("%d %d %d %d -> %d %d %d %d \n", old_segX, old_segY, old_segW, old_segH, new_segX, new_segY, new_segW, new_segH); */ - if (old_segX != new_segX || old_segY != new_segY || - old_segW != new_segW || old_segH != new_segH) { - delObjectFromSpace(p, item); - p->setStatus(item, move_x, move_y, w, h); - addObjectToSpace(p, item); - return; - } - - p->setStatus(item, move_x, move_y, w, h); + if (old_segX != new_segX || old_segY != new_segY || + old_segW != new_segW || old_segH != new_segH) { + delObjectFromSpace(p, item); + p->setStatus(item, move_x, move_y, w, h); + addObjectToSpace(p, item); + return; + } + + p->setStatus(item, move_x, move_y, w, h); } -void -printSpace(space_t * p) +void printSpace(space_t * p) { - int i, j; + int i, j; - printf("print space : \n"); + printf("print space : \n"); - for (i = 0; i < p->h; i++) { - for (j = 0; j < p->w; j++) { - printf("%3d ", p->zone[j][i]->list->count); - } + for (i = 0; i < p->h; i++) { + for (j = 0; j < p->w; j++) { + printf("%3d ", p->zone[j][i]->list->count); + } - putchar('\n'); - } + putchar('\n'); + } } -void -actionSpace(space_t * space, void *f, void *p) +void actionSpace(space_t * space, void *f, void *p) { - void (*fce) (space_t * space, void *f, void *p); - int len; - int i; + void (*fce) (space_t * space, void *f, void *p); + int len; + int i; - fce = f; - len = space->listIndex->count; + fce = f; + len = space->listIndex->count; - for (i = 0; i < len; i++) { - fce(space, getItemFromSpace(space, i), p); + for (i = 0; i < len; i++) { + fce(space, getItemFromSpace(space, i), p); - if (space->listIndex->count == len - 1) { - len--; - i--; - } - } + if (space->listIndex->count == len - 1) { + len--; + i--; + } + } } void actionSpaceFromLocation(space_t * space, void *f, void *p, int x, int y, - int w, int h) + int w, int h) { - void (*fce) (space_t * space, void *f, void *p); - list_t *list; - int len; - int i; + void (*fce) (space_t * space, void *f, void *p); + list_t *list; + int len; + int i; - fce = f; + fce = f; - list = newList(); + list = newList(); - getObjectFromSpace(space, x, y, w, h, list); + getObjectFromSpace(space, x, y, w, h, list); - len = list->count; + len = list->count; - for (i = 0; i < len; i++) { - fce(space, list->list[i], p); - } + for (i = 0; i < len; i++) { + fce(space, list->list[i], p); + } - destroyList(list); + destroyList(list); } -void -destroySpace(space_t * p) +void destroySpace(space_t * p) { - int j, i; + int j, i; - destroyIndex(p->listIndex); + destroyIndex(p->listIndex); - for (i = 0; i < p->h; i++) { - for (j = 0; j < p->w; j++) { - destroyZone(p->zone[j][i]); - } - } + for (i = 0; i < p->h; i++) { + for (j = 0; j < p->w; j++) { + destroyZone(p->zone[j][i]); + } + } - for (i = 0; i < p->w; i++) { - free(p->zone[i]); - } + for (i = 0; i < p->w; i++) { + free(p->zone[i]); + } - free(p->zone); - free(p); + free(p->zone); + free(p); } -void -destroySpaceWithObject(space_t * p, void *f) +void destroySpaceWithObject(space_t * p, void *f) { - void (*fce) (void *param); - int i; + void (*fce) (void *param); + int i; - fce = f; + fce = f; - for (i = 0; i < p->listIndex->count; i++) { - fce(getItemFromSpace(p, i)); - } + for (i = 0; i < p->listIndex->count; i++) { + fce(getItemFromSpace(p, i)); + } - destroySpace(p); + destroySpace(p); } diff --git a/src/base/space.h b/src/base/space.h index e1ac594..a166c06 100644 --- a/src/base/space.h +++ b/src/base/space.h @@ -1,56 +1,53 @@ #ifndef SPACE_H -#define SPACE_H +# define SPACE_H -#include "main.h" -#include "list.h" +# include "main.h" +# include "list.h" -typedef struct zone_struct -{ - list_t *list; +typedef struct zone_struct { + list_t *list; } zone_t; -typedef struct space_struct -{ - int w; - int h; +typedef struct space_struct { + int w; + int h; - int segW; - int segH; + int segW; + int segH; - zone_t ***zone; + zone_t ***zone; - list_t *listIndex; + list_t *listIndex; - void (*getStatus) (void *p, int *id, int *x, int *y, int *w, int *h); - void (*setStatus) (void *p, int x, int y, int w, int h); + void (*getStatus) (void *p, int *id, int *x, int *y, int *w, int *h); + void (*setStatus) (void *p, int x, int y, int w, int h); } space_t; extern space_t *newSpace(int w, int h, int segW, int segH, - void (*getStatus) (void *p, int *id, int *x, int *y, - int *w, int *h), - void (*setStatus) (void *p, int x, int y, int w, - int h)); + void (*getStatus) (void *p, int *id, int *x, int *y, + int *w, int *h), + void (*setStatus) (void *p, int x, int y, int w, + int h)); extern int getSpaceCount(space_t * p); extern void *getItemFromSpace(space_t * p, int offset); extern void addObjectToSpace(space_t * p, void *item); extern void getObjectFromSpace(space_t * p, int x, int y, int w, int h, - list_t * list); + list_t * list); extern void *getObjectFromSpaceWithID(space_t * p, int id); extern int isConflictWithObjectFromSpace(space_t * p, int x, int y, int w, - int h); + int h); extern int isConflictWithObjectFromSpaceBut(space_t * p, int x, int y, int w, - int h, void *but); + int h, void *but); extern void delObjectFromSpace(space_t * p, void *item); extern void delObjectFromSpaceWithObject(space_t * p, void *item, void *f); -extern void moveObjectInSpace(space_t * p, void *item, int move_x, - int move_y); +extern void moveObjectInSpace(space_t * p, void *item, int move_x, int move_y); extern void printSpace(space_t * p); extern void actionSpace(space_t * space, void *f, void *p); extern void actionSpaceFromLocation(space_t * space, void *f, void *p, int x, - int y, int w, int h); + int y, int w, int h); extern void destroySpace(space_t * p); extern void destroySpaceWithObject(space_t * p, void *f); diff --git a/src/base/storage.c b/src/base/storage.c index ca55bc4..1ae5f5a 100644 --- a/src/base/storage.c +++ b/src/base/storage.c @@ -7,127 +7,118 @@ #include "main.h" #include "list.h" -typedef struct struct_storage_item -{ - char *name; - char *group; - void *data; +typedef struct struct_storage_item { + char *name; + char *group; + void *data; } storage_item_t; -list_t * -newStorage() +list_t *newStorage() { - return newList(); + return newList(); } -static storage_item_t * -newStorageItem(char *group, char *name, void *data) +static storage_item_t *newStorageItem(char *group, char *name, void *data) { - storage_item_t *new; - - assert(name != NULL); - assert(group != NULL); - assert(data != NULL); - new = malloc(sizeof(storage_item_t)); - new->name = strdup(name); - new->group = strdup(group); - new->data = data; - return new; + storage_item_t *new; + + assert(name != NULL); + assert(group != NULL); + assert(data != NULL); + new = malloc(sizeof(storage_item_t)); + new->name = strdup(name); + new->group = strdup(group); + new->data = data; + return new; } -static void -destroyStorageItem(storage_item_t * p, void *f) +static void destroyStorageItem(storage_item_t * p, void *f) { - void (*fce) (void *); - - assert(p != NULL); - assert(f != NULL); - fce = f; - fce(p->data); - free(p->name); - free(p->group); - free(p); + void (*fce) (void *); + + assert(p != NULL); + assert(f != NULL); + fce = f; + fce(p->data); + free(p->name); + free(p->group); + free(p); } -void -addItemToStorage(list_t * list, char *group, char *name, void *data) +void addItemToStorage(list_t * list, char *group, char *name, void *data) { - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - addList(list, newStorageItem(group, name, data)); + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + addList(list, newStorageItem(group, name, data)); } -void * -getItemFromStorage(list_t * list, char *group, char *name) +void *getItemFromStorage(list_t * list, char *group, char *name) { - storage_item_t *this; - int i; - - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - for (i = 0; i < list->count; i++) { - this = (storage_item_t *) list->list[i]; - if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) - return this->data; - } + storage_item_t *this; + int i; + + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + for (i = 0; i < list->count; i++) { + this = (storage_item_t *) list->list[i]; + if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) + return this->data; + } #ifdef DEBUG - printf(_("%s %s was not found in storage!\n"), group, name); + printf(_("%s %s was not found in storage!\n"), group, name); #endif - return NULL; + return NULL; } -void -delItemFromStorage(list_t * list, char *group, char *name, void *f) +void delItemFromStorage(list_t * list, char *group, char *name, void *f) { - storage_item_t *this; - int i; - - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - for (i = 0; i < list->count; i++) { - this = (storage_item_t *) list->list[i]; - if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) { - destroyStorageItem(this, f); - delList(list, i); - return; - } - } - return; + storage_item_t *this; + int i; + + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + for (i = 0; i < list->count; i++) { + this = (storage_item_t *) list->list[i]; + if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) { + destroyStorageItem(this, f); + delList(list, i); + return; + } + } + return; } -void -delAllItemFromStorage(list_t * list, char *group, void *f) +void delAllItemFromStorage(list_t * list, char *group, void *f) { - storage_item_t *this; - int i; - - assert(list != NULL); - assert(group != NULL); - - for (i = 0; i < list->count; i++) { - this = (storage_item_t *) list->list[i]; - if (strcmp(group, this->group) == 0) { - destroyStorageItem(this, f); - delList(list, i); - i--; - } - } + storage_item_t *this; + int i; + + assert(list != NULL); + assert(group != NULL); + + for (i = 0; i < list->count; i++) { + this = (storage_item_t *) list->list[i]; + if (strcmp(group, this->group) == 0) { + destroyStorageItem(this, f); + delList(list, i); + i--; + } + } } -void -destroyStorage(list_t * p, void *f) +void destroyStorage(list_t * p, void *f) { - storage_item_t *this; - int i; - - assert(p != NULL); - assert(f != NULL); - for (i = 0; i < p->count; i++) { - this = (storage_item_t *) p->list[i]; - destroyStorageItem(this, f); - } - destroyList(p); + storage_item_t *this; + int i; + + assert(p != NULL); + assert(f != NULL); + for (i = 0; i < p->count; i++) { + this = (storage_item_t *) p->list[i]; + destroyStorageItem(this, f); + } + destroyList(p); } diff --git a/src/base/storage.h b/src/base/storage.h index 6305f81..8cf8801 100644 --- a/src/base/storage.h +++ b/src/base/storage.h @@ -1,16 +1,16 @@ #ifndef STORAGE_H -#define STORAGE_H +# define STORAGE_H -#include "main.h" -#include "list.h" +# include "main.h" +# include "list.h" extern list_t *newStorage(); extern void addItemToStorage(list_t * list, char *group, char *name, - void *data); + void *data); extern void *getItemFromStorage(list_t * list, char *group, char *name); extern void delItemFromStorage(list_t * list, char *group, char *name, - void *f); + void *f); extern void delAllItemFromStorage(list_t * list, char *group, void *f); extern void destroyStorage(list_t * p, void *f); #endif diff --git a/src/base/string_length.h b/src/base/string_length.h index 7a8ab04..021bfe8 100644 --- a/src/base/string_length.h +++ b/src/base/string_length.h @@ -1,17 +1,17 @@ #ifndef STR_LENGTH_H -#define STR_LENGTH_H +# define STR_LENGTH_H -#include "main.h" +# include "main.h" -#define STR_SIZE 128 -#define STR_PROTO_SIZE 128 -#define STR_LOG_SIZE 256 -#define STR_NUM_SIZE 8 -#define STR_NAME_SIZE 32 -#define STR_PATH_SIZE 4096 -#define STR_FILE_NAME_SIZE 256 -#define STR_IP_SIZE 64 +# define STR_SIZE 128 +# define STR_PROTO_SIZE 128 +# define STR_LOG_SIZE 256 +# define STR_NUM_SIZE 8 +# define STR_NAME_SIZE 32 +# define STR_PATH_SIZE 4096 +# define STR_FILE_NAME_SIZE 256 +# define STR_IP_SIZE 64 #endif diff --git a/src/base/tcp_server.c b/src/base/tcp_server.c index f1f93c4..aeb3b8c 100644 --- a/src/base/tcp_server.c +++ b/src/base/tcp_server.c @@ -9,12 +9,12 @@ #include <sys/time.h> #ifndef __WIN32__ -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/select.h> +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <sys/select.h> #else -#include <io.h> -#include <winsock2.h> +# include <io.h> +# include <winsock2.h> #endif #include "main.h" @@ -30,13 +30,13 @@ #include "index.h" #ifndef PUBLIC_SERVER -#include "screen_world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" -#include "highScore.h" -#include "log.h" +# include "publicServer.h" +# include "highScore.h" +# include "log.h" #endif #include "tcp.h" @@ -46,242 +46,228 @@ static sock_tcp_t *sock_server_tcp; static sock_tcp_t *sock_server_tcp_second; -client_t * -newTcpClient(sock_tcp_t * sock_tcp) +client_t *newTcpClient(sock_tcp_t * sock_tcp) { - client_t *new; + client_t *new; - assert(sock_tcp != NULL); + assert(sock_tcp != NULL); - new = newAnyClient(); - new->type = CLIENT_TYPE_TCP; - new->socket_tcp = sock_tcp; - new->recvBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); - new->sendBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); + new = newAnyClient(); + new->type = CLIENT_TYPE_TCP; + new->socket_tcp = sock_tcp; + new->recvBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); + new->sendBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockTcpIp(sock_tcp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, - getSockTcpPort(sock_tcp)); - addToLog(LOG_INF, str_log); + getSockTcpIp(sock_tcp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, + getSockTcpPort(sock_tcp)); + addToLog(LOG_INF, str_log); #endif - return new; + return new; } -void -sendTcpClientBuffer(client_t * client) +void sendTcpClientBuffer(client_t * client) { - void *data; - int len; - int res; + void *data; + int len; + int res; - len = getBufferSize(client->sendBuffer); + len = getBufferSize(client->sendBuffer); - if (len == 0) { - return; - } + if (len == 0) { + return; + } - data = getBufferData(client->sendBuffer); + data = getBufferData(client->sendBuffer); - res = writeTcpSocket(client->socket_tcp, data, len); - //printf("writeTcpSocket = %d\n", res); + res = writeTcpSocket(client->socket_tcp, data, len); + //printf("writeTcpSocket = %d\n", res); - if (res < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (res < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - cutBuffer(client->sendBuffer, res); + cutBuffer(client->sendBuffer, res); } -void -destroyTcpClient(client_t * client) +void destroyTcpClient(client_t * client) { - eventMsgInCheckFront(client); - sendTcpClientBuffer(client); + eventMsgInCheckFront(client); + sendTcpClientBuffer(client); #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockTcpIp(client->socket_tcp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, - getSockTcpPort(client->socket_tcp)); - addToLog(LOG_INF, str_log); + getSockTcpIp(client->socket_tcp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, + getSockTcpPort(client->socket_tcp)); + addToLog(LOG_INF, str_log); #endif - closeTcpSocket(client->socket_tcp); - destroyBuffer(client->recvBuffer); - destroyBuffer(client->sendBuffer); + closeTcpSocket(client->socket_tcp); + destroyBuffer(client->recvBuffer); + destroyBuffer(client->sendBuffer); - destroyAnyClient(client); + destroyAnyClient(client); } -int -initTcpServer(char *ip4, int port4, char *ip6, int port6) +int initTcpServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - ret = 0; + ret = 0; - if (ip4 != NULL) { - sock_server_tcp = bindTcpSocket(ip4, port4, PROTO_UDPv4); + if (ip4 != NULL) { + sock_server_tcp = bindTcpSocket(ip4, port4, PROTO_UDPv4); - if (sock_server_tcp != NULL) { - ret++; - disableNagle(sock_server_tcp); + if (sock_server_tcp != NULL) { + ret++; + disableNagle(sock_server_tcp); #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, - port4); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, port4); #endif - } - else { + } else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), - ip4, port4); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip4, port4); #endif - } - } + } + } - if (ip6 != NULL) { - sock_server_tcp_second = bindTcpSocket(ip6, port6, PROTO_UDPv6); + if (ip6 != NULL) { + sock_server_tcp_second = bindTcpSocket(ip6, port6, PROTO_UDPv6); - if (sock_server_tcp_second != NULL) { - ret++; - disableNagle(sock_server_tcp_second); + if (sock_server_tcp_second != NULL) { + ret++; + disableNagle(sock_server_tcp_second); #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, - port6); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, port6); #endif - } - else { + } else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), - ip6, port6); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip6, port6); #endif - } - } + } + } - return ret; + return ret; } -static void -eventNewClient(sock_tcp_t * server_sock) +static void eventNewClient(sock_tcp_t * server_sock) { - list_t *listClient; - sock_tcp_t *sock; - client_t *client; + list_t *listClient; + sock_tcp_t *sock; + client_t *client; - listClient = getListServerClient(); + listClient = getListServerClient(); - sock = getTcpNewClient(server_sock); - disableNagle(sock); - setTcpSockNonBlock(sock); + sock = getTcpNewClient(server_sock); + disableNagle(sock); + setTcpSockNonBlock(sock); - client = newTcpClient(sock); - addList(listClient, client); + client = newTcpClient(sock); + addList(listClient, client); } -static void -eventTcpClient(client_t * client) +static void eventTcpClient(client_t * client) { - char buffer[STR_PROTO_SIZE]; - int ret; + char buffer[STR_PROTO_SIZE]; + int ret; - memset(buffer, 0, STR_PROTO_SIZE); + memset(buffer, 0, STR_PROTO_SIZE); - ret = readTcpSocket(client->socket_tcp, buffer, STR_PROTO_SIZE - 1); - //printf("readTcpSocket = %d\n", ret); + ret = readTcpSocket(client->socket_tcp, buffer, STR_PROTO_SIZE - 1); + //printf("readTcpSocket = %d\n", ret); - if (ret <= 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (ret <= 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - if (addBuffer(client->recvBuffer, buffer, ret) < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (addBuffer(client->recvBuffer, buffer, ret) < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - while (getBufferLine(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0) { - addList(client->listRecvMsg, strdup(buffer)); - } + while (getBufferLine(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0) { + addList(client->listRecvMsg, strdup(buffer)); + } } -void -setServerTcpSelect() +void setServerTcpSelect() { - list_t *listClient; - int i; + list_t *listClient; + int i; - listClient = getListServerClient(); + listClient = getListServerClient(); - if (sock_server_tcp != NULL) { - addSockToSelectRead(sock_server_tcp->sock); - } + if (sock_server_tcp != NULL) { + addSockToSelectRead(sock_server_tcp->sock); + } - if (sock_server_tcp_second != NULL) { - addSockToSelectRead(sock_server_tcp_second->sock); - } + if (sock_server_tcp_second != NULL) { + addSockToSelectRead(sock_server_tcp_second->sock); + } - for (i = 0; i < listClient->count; i++) { - client_t *client; + for (i = 0; i < listClient->count; i++) { + client_t *client; - client = (client_t *) listClient->list[i]; + client = (client_t *) listClient->list[i]; - if (client->status != NET_STATUS_OK - || client->type != CLIENT_TYPE_TCP) { - continue; - } + if (client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP) { + continue; + } - addSockToSelectRead(client->socket_tcp->sock); - } + addSockToSelectRead(client->socket_tcp->sock); + } } -int -selectServerTcpSocket() +int selectServerTcpSocket() { - list_t *listClient; - int count; - int i; - - count = 0; - - if (sock_server_tcp != NULL) { - if (isChangeSockInSelectRead(sock_server_tcp->sock)) { - eventNewClient(sock_server_tcp); - count++; - } - } - - if (sock_server_tcp_second != NULL) { - if (isChangeSockInSelectRead(sock_server_tcp_second->sock)) { - eventNewClient(sock_server_tcp_second); - count++; - } - } - - listClient = getListServerClient(); - - for (i = 0; i < listClient->count; i++) { - client_t *client; - - client = (client_t *) listClient->list[i]; - - if (client->status != NET_STATUS_OK - || client->type != CLIENT_TYPE_TCP) { - continue; - } - - if (isChangeSockInSelectRead(client->socket_tcp->sock)) { - //printf("sChangeSockInSelectRead\n"); - eventTcpClient(client); - count++; - } + list_t *listClient; + int count; + int i; + + count = 0; + + if (sock_server_tcp != NULL) { + if (isChangeSockInSelectRead(sock_server_tcp->sock)) { + eventNewClient(sock_server_tcp); + count++; + } + } + + if (sock_server_tcp_second != NULL) { + if (isChangeSockInSelectRead(sock_server_tcp_second->sock)) { + eventNewClient(sock_server_tcp_second); + count++; + } + } + + listClient = getListServerClient(); + + for (i = 0; i < listClient->count; i++) { + client_t *client; + + client = (client_t *) listClient->list[i]; + + if (client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP) { + continue; + } + + if (isChangeSockInSelectRead(client->socket_tcp->sock)) { + //printf("sChangeSockInSelectRead\n"); + eventTcpClient(client); + count++; + } /* if( isChangeSockInSelectWrite(client->socket_tcp->sock) ) { @@ -290,29 +276,28 @@ selectServerTcpSocket() count++; } */ - } + } - return count; + return count; } -void -quitTcpServer() +void quitTcpServer() { - if (sock_server_tcp != NULL) { + if (sock_server_tcp != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), getSockTcpPort(sock_server_tcp)); + printf(_("Closing port: \"%d\"\n"), getSockTcpPort(sock_server_tcp)); #endif - closeTcpSocket(sock_server_tcp); - } + closeTcpSocket(sock_server_tcp); + } - if (sock_server_tcp_second != NULL) { + if (sock_server_tcp_second != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), - getSockTcpPort(sock_server_tcp_second)); + printf(_("Closing port: \"%d\"\n"), + getSockTcpPort(sock_server_tcp_second)); #endif - closeTcpSocket(sock_server_tcp_second); - } + closeTcpSocket(sock_server_tcp_second); + } #ifdef DEBUG - printf("Quitting TCP\n"); + printf("Quitting TCP\n"); #endif } diff --git a/src/base/tcp_server.h b/src/base/tcp_server.h index 508d880..592df30 100644 --- a/src/base/tcp_server.h +++ b/src/base/tcp_server.h @@ -1,12 +1,12 @@ #ifndef SERVER_TCP_H -#define SERVER_TCP_H +# define SERVER_TCP_H -#include "server.h" -#include "tcp.h" +# include "server.h" +# include "tcp.h" -#define SERVER_TCP_BUFFER_LIMIT 4096 +# define SERVER_TCP_BUFFER_LIMIT 4096 extern client_t *newTcpClient(sock_tcp_t * sock_tcp); extern void destroyTcpClient(client_t * p); diff --git a/src/base/textFile.c b/src/base/textFile.c index 4b93d5c..776b1cc 100644 --- a/src/base/textFile.c +++ b/src/base/textFile.c @@ -9,149 +9,142 @@ #include "main.h" #include "textFile.h" -textFile_t * -newTextFile(char *s) +textFile_t *newTextFile(char *s) { - textFile_t *new; - char path[STR_PATH_SIZE]; - assert(s != NULL); - - if (isFillPath(s)) { - strcpy(path, s); - } - else { - getcwd(path, STR_PATH_SIZE); - strcat(path, "/"); - strcat(path, s); - } - - new = malloc(sizeof(textFile_t)); - new->file = strdup(path); - new->text = newList(); - - return new; + textFile_t *new; + char path[STR_PATH_SIZE]; + assert(s != NULL); + + if (isFillPath(s)) { + strcpy(path, s); + } else { + getcwd(path, STR_PATH_SIZE); + strcat(path, "/"); + strcat(path, s); + } + + new = malloc(sizeof(textFile_t)); + new->file = strdup(path); + new->text = newList(); + + return new; } -static void -createLine(list_t * list, char *p, int len) +static void createLine(list_t * list, char *p, int len) { - char *line; - char *begin_line; - char *end_line; - int length_line = 0; + char *line; + char *begin_line; + char *end_line; + int length_line = 0; - assert(list != NULL); - assert(p != NULL); - assert(len >= 0); + assert(list != NULL); + assert(p != NULL); + assert(len >= 0); - begin_line = p; + begin_line = p; - do { - end_line = memchr(begin_line, '\n', len); - if (end_line == NULL) - break; + do { + end_line = memchr(begin_line, '\n', len); + if (end_line == NULL) + break; - length_line = (int) (end_line - (begin_line)); + length_line = (int) (end_line - (begin_line)); - line = malloc((length_line + 1) * sizeof(char)); - memset(line, 0, (length_line + 1) * sizeof(char)); - strncpy(line, begin_line, length_line); + line = malloc((length_line + 1) * sizeof(char)); + memset(line, 0, (length_line + 1) * sizeof(char)); + strncpy(line, begin_line, length_line); - addList(list, line); - len -= (length_line + 1); + addList(list, line); + len -= (length_line + 1); - begin_line = end_line + 1; + begin_line = end_line + 1; - } while (begin_line != NULL); + } while (begin_line != NULL); } /* * Nacita subor *s a vrati ho f * formatovany v type textFile_t* */ -textFile_t * -loadTextFile(char *s) +textFile_t *loadTextFile(char *s) { - FILE *file; - textFile_t *ret; - char *p; - int file_length = 0; - struct stat buf; + FILE *file; + textFile_t *ret; + char *p; + int file_length = 0; + struct stat buf; - assert(s != NULL); + assert(s != NULL); - if (lstat(s, &buf) < 0) { - fprintf(stderr, _("ERROR: unable to get file status for %s!\n"), s); - return NULL; - } + if (lstat(s, &buf) < 0) { + fprintf(stderr, _("ERROR: unable to get file status for %s!\n"), s); + return NULL; + } - file_length = buf.st_size; - if ((file = fopen(s, "rb")) == NULL) { - fprintf(stderr, _("ERROR: unable to open file %s for reading\n"), s); - return NULL; - } + file_length = buf.st_size; + if ((file = fopen(s, "rb")) == NULL) { + fprintf(stderr, _("ERROR: unable to open file %s for reading\n"), s); + return NULL; + } - p = malloc(file_length * sizeof(char)); + p = malloc(file_length * sizeof(char)); - if (fread(p, file_length * sizeof(char), 1, file) != 1) { - fprintf(stderr, _("ERROR: unable to read data from file %s\n"), s); - fclose(file); - return NULL; - } + if (fread(p, file_length * sizeof(char), 1, file) != 1) { + fprintf(stderr, _("ERROR: unable to read data from file %s\n"), s); + fclose(file); + return NULL; + } - fclose(file); + fclose(file); - ret = newTextFile(s); - createLine(ret->text, p, file_length); + ret = newTextFile(s); + createLine(ret->text, p, file_length); - free(p); + free(p); - return ret; + return ret; } /* * Zobrazi text ulozeny v *p * do stdout */ -void -printTextFile(textFile_t * p) +void printTextFile(textFile_t * p) { - int i; + int i; - assert(p != NULL); + assert(p != NULL); - printf(_("Printing file: \"%s\"\n\n"), p->file); + printf(_("Printing file: \"%s\"\n\n"), p->file); - for (i = 0; i < p->text->count; i++) { - printf("%3d >> %s\n", i, (char *) p->text->list[i]); - } + for (i = 0; i < p->text->count; i++) { + printf("%3d >> %s\n", i, (char *) p->text->list[i]); + } } -void -saveTextFile(textFile_t * p) +void saveTextFile(textFile_t * p) { - int i; - FILE *file; - assert(p != NULL); + int i; + FILE *file; + assert(p != NULL); - file = fopen(p->file, "wb"); - for (i = 0; i < p->text->count; i++) { - fprintf(file, "%s\n", (char *) p->text->list[i]); - } + file = fopen(p->file, "wb"); + for (i = 0; i < p->text->count; i++) { + fprintf(file, "%s\n", (char *) p->text->list[i]); + } - fclose(file); + fclose(file); } /* * Uvolni text ulozeny v type textFile_t* * z pamate. */ -void -destroyTextFile(textFile_t * p) +void destroyTextFile(textFile_t * p) { - assert(p != NULL); + assert(p != NULL); - free(p->file); - destroyListItem(p->text, free); - free(p); + free(p->file); + destroyListItem(p->text, free); + free(p); } diff --git a/src/base/textFile.h b/src/base/textFile.h index 9dd0d33..88744e0 100644 --- a/src/base/textFile.h +++ b/src/base/textFile.h @@ -1,18 +1,17 @@ #ifndef TEXTFILE_H -#define TEXTFILE_H +# define TEXTFILE_H -#include "list.h" +# include "list.h" -#ifdef __WIN32__ -#define lstat stat -#endif +# ifdef __WIN32__ +# define lstat stat +# endif -typedef struct str_textFile_t -{ - char *file; - list_t *text; +typedef struct str_textFile_t { + char *file; + list_t *text; } textFile_t; extern textFile_t *newTextFile(char *s); diff --git a/src/base/tux.c b/src/base/tux.c index 13467bb..7fe9a68 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -19,20 +19,20 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -#include "font.h" -#include "image.h" -#include "layer.h" -#include "radar.h" +# include "font.h" +# include "image.h" +# include "layer.h" +# include "radar.h" -#ifndef NO_SOUND -#include "sound.h" -#endif +# ifndef NO_SOUND +# include "sound.h" +# endif -#include "screen_world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif #ifndef PUBLIC_SERVER @@ -47,173 +47,165 @@ static image_t *g_cross; static bool_t isTuxInit = FALSE; -bool_t -isTuxInicialized() +bool_t isTuxInicialized() { - return isTuxInit; + return isTuxInit; } -void -initTux() +void initTux() { #ifndef PUBLIC_SERVER - assert(isImageInicialized() == TRUE); + assert(isImageInicialized() == TRUE); #endif #ifndef PUBLIC_SERVER - g_tux_up = - addImageData("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE); - g_tux_right = - addImageData("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE); - g_tux_left = - addImageData("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE); - g_tux_down = - addImageData("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE); - g_cross = - addImageData("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); + g_tux_up = addImageData("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE); + g_tux_right = + addImageData("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE); + g_tux_left = + addImageData("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE); + g_tux_down = + addImageData("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE); + g_cross = + addImageData("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); #endif - isTuxInit = TRUE; + isTuxInit = TRUE; } -tux_t * -newTux() +tux_t *newTux() { - int x, y; - tux_t *new; + int x, y; + tux_t *new; - new = malloc(sizeof(tux_t)); - assert(new != NULL); + new = malloc(sizeof(tux_t)); + assert(new != NULL); - memset(new, 0, sizeof(tux_t)); + memset(new, 0, sizeof(tux_t)); - new->id = getNewID(); - new->status = TUX_STATUS_ALIVE; - new->control = TUX_CONTROL_NONE; + new->id = getNewID(); + new->status = TUX_STATUS_ALIVE; + new->control = TUX_CONTROL_NONE; - findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - setTuxProportion(new, x, y); + findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); + setTuxProportion(new, x, y); - new->position = TUX_DOWN; - new->gun = GUN_SIMPLE; - new->shot[new->gun] = GUN_MAX_SHOT; + new->position = TUX_DOWN; + new->gun = GUN_SIMPLE; + new->shot[new->gun] = GUN_MAX_SHOT; - sprintf(new->name, "no_name_id_%d", new->id); - new->score = 0; - new->frame = 0; + sprintf(new->name, "no_name_id_%d", new->id); + new->score = 0; + new->frame = 0; - new->bonus = BONUS_NONE; - new->bonus_time = 0; + new->bonus = BONUS_NONE; + new->bonus_time = 0; - new->isCanShot = TRUE; - new->isCanSwitchGun = TRUE; + new->isCanShot = TRUE; + new->isCanSwitchGun = TRUE; - new->client = NULL; + new->client = NULL; - return new; + return new; } -void -tuxSetName(tux_t * tux, char *name) +void tuxSetName(tux_t * tux, char *name) { - strcpy(tux->name, name); - //tux->g_name = getFontImage(name, COLOR_WHITE); + strcpy(tux->name, name); + //tux->g_name = getFontImage(name, COLOR_WHITE); } -bool_t -isTuxAnyGun(tux_t * tux) +bool_t isTuxAnyGun(tux_t * tux) { - int i; + int i; - for (i = 0; i < GUN_COUNT; i++) { - if (tux->shot[i] > 0) { - return TRUE; - } - } + for (i = 0; i < GUN_COUNT; i++) { + if (tux->shot[i] > 0) { + return TRUE; + } + } - return FALSE; + return FALSE; } -void -getCourse(int n, int *x, int *y) +void getCourse(int n, int *x, int *y) { - assert(x != NULL); - assert(y != NULL); + assert(x != NULL); + assert(y != NULL); - switch (n) { - case TUX_UP: - *x = 0; - *y = -1; - break; + switch (n) { + case TUX_UP: + *x = 0; + *y = -1; + break; - case TUX_LEFT: - *x = -1; - *y = 0; - break; + case TUX_LEFT: + *x = -1; + *y = 0; + break; - case TUX_RIGHT: - *x = +1; - *y = 0; - break; + case TUX_RIGHT: + *x = +1; + *y = 0; + break; - case TUX_DOWN: - *x = 0; - *y = +1; - break; + case TUX_DOWN: + *x = 0; + *y = +1; + break; - default: - assert(!_("Type variable has a really wierd value!")); - break; - } + default: + assert(!_("Type variable has a really wierd value!")); + break; + } } #ifndef PUBLIC_SERVER -void -drawTux(tux_t * tux) +void drawTux(tux_t * tux) { - image_t *g_image = NULL; + image_t *g_image = NULL; - assert(tux != NULL); + assert(tux != NULL); - if (tux->bonus == BONUS_HIDDEN && - getNetTypeGame() != NET_GAME_TYPE_NONE && - tux->control == TUX_CONTROL_NET) { - return; - } + if (tux->bonus == BONUS_HIDDEN && + getNetTypeGame() != NET_GAME_TYPE_NONE && + tux->control == TUX_CONTROL_NET) { + return; + } - switch (tux->position) { - case TUX_UP: - g_image = g_tux_up; - break; + switch (tux->position) { + case TUX_UP: + g_image = g_tux_up; + break; - case TUX_LEFT: - g_image = g_tux_left; - break; + case TUX_LEFT: + g_image = g_tux_left; + break; - case TUX_RIGHT: - g_image = g_tux_right; - break; + case TUX_RIGHT: + g_image = g_tux_right; + break; - case TUX_DOWN: - g_image = g_tux_down; - break; + case TUX_DOWN: + g_image = g_tux_down; + break; - default: - assert(!_("p->control has a really wierd value!")); - break; - } + default: + assert(!_("p->control has a really wierd value!")); + break; + } - if (tux->status == TUX_STATUS_DEAD) { - g_image = g_cross; + if (tux->status == TUX_STATUS_DEAD) { + g_image = g_cross; - addLayer(g_cross, - tux->x - g_cross->w / 2, - (tux->y + g_cross->h / 2) - g_cross->h, - 0, 0, g_cross->w, g_cross->h, TUX_LAYER); + addLayer(g_cross, + tux->x - g_cross->w / 2, + (tux->y + g_cross->h / 2) - g_cross->h, + 0, 0, g_cross->w, g_cross->h, TUX_LAYER); - return; - } + return; + } /* if( tux->g_name != NULL ) { @@ -224,11 +216,11 @@ drawTux(tux_t * tux) tux->g_name->w, tux->g_name->h, TUX_LAYER); } */ - addLayer(g_image, - tux->x - TUX_IMG_WIDTH / 2, - (tux->y + TUX_HEIGHT / 2) - TUX_IMG_HEIGHT, - (tux->frame / TUX_KEY) * TUX_IMG_WIDTH, 0, - TUX_IMG_WIDTH, TUX_IMG_HEIGHT, TUX_LAYER); + addLayer(g_image, + tux->x - TUX_IMG_WIDTH / 2, + (tux->y + TUX_HEIGHT / 2) - TUX_IMG_HEIGHT, + (tux->frame / TUX_KEY) * TUX_IMG_WIDTH, 0, + TUX_IMG_WIDTH, TUX_IMG_HEIGHT, TUX_LAYER); } /* @@ -249,448 +241,428 @@ void drawListTux(list_t *listTux) */ #endif -void -replaceTuxID(tux_t * tux, int id) +void replaceTuxID(tux_t * tux, int id) { - replaceID(tux->id, id); - tux->id = id; + replaceID(tux->id, id); + tux->id = id; } -static void -timer_spawnTux(void *p) +static void timer_spawnTux(void *p) { - tux_t *tux; - arena_t *arena; - int x, y; - int id; + tux_t *tux; + arena_t *arena; + int x, y; + int id; - id = *((int *) p); - free(p); + id = *((int *) p); + free(p); - arena = getCurrentArena(); - tux = getObjectFromSpaceWithID(arena->spaceTux, id); + arena = getCurrentArena(); + tux = getObjectFromSpaceWithID(arena->spaceTux, id); - if (tux == NULL) - return; + if (tux == NULL) + return; - tux->status = TUX_STATUS_ALIVE; - findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - tux->gun = GUN_SIMPLE; + tux->status = TUX_STATUS_ALIVE; + findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + tux->gun = GUN_SIMPLE; - addNewItem(arena->spaceItem, ID_UNKNOWN); + addNewItem(arena->spaceItem, ID_UNKNOWN); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } } -static void -timer_tuxCanShot(void *p) +static void timer_tuxCanShot(void *p) { - tux_t *tux; - int id; + tux_t *tux; + int id; - id = *((int *) p); - free(p); + id = *((int *) p); + free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux == NULL) - return; + if (tux == NULL) + return; - tux->isCanShot = TRUE; + tux->isCanShot = TRUE; } -static void -timer_tuxCanSwitchGun(void *p) +static void timer_tuxCanSwitchGun(void *p) { - tux_t *tux; - int id; + tux_t *tux; + int id; - id = *((int *) p); - free(p); + id = *((int *) p); + free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux == NULL) - return; + if (tux == NULL) + return; - tux->isCanSwitchGun = TRUE; + tux->isCanSwitchGun = TRUE; } -void -eventTuxIsDead(tux_t * tux) +void eventTuxIsDead(tux_t * tux) { - if (tux->status == TUX_STATUS_DEAD) { - return; - } - + if (tux->status == TUX_STATUS_DEAD) { + return; + } #ifndef NO_SOUND - playSound("dead", SOUND_GROUP_BASE); + playSound("dead", SOUND_GROUP_BASE); #endif - tux->status = TUX_STATUS_DEAD; - memset(tux->shot, 0, sizeof(int) * GUN_COUNT); - tux->gun = GUN_SIMPLE; - tux->shot[tux->gun] = GUN_MAX_SHOT; + tux->status = TUX_STATUS_DEAD; + memset(tux->shot, 0, sizeof(int) * GUN_COUNT); + tux->gun = GUN_SIMPLE; + tux->shot[tux->gun] = GUN_MAX_SHOT; - tux->bonus = BONUS_NONE; - tux->bonus_time = 0; - tux->pickup_time = 0; + tux->bonus = BONUS_NONE; + tux->bonus_time = 0; + tux->pickup_time = 0; - tux->isCanShot = TRUE; - tux->isCanSwitchGun = TRUE; + tux->isCanShot = TRUE; + tux->isCanSwitchGun = TRUE; - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN); - } + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN); + } - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_kill_server(PROTO_SEND_ALL, NULL, tux); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_kill_server(PROTO_SEND_ALL, NULL, tux); + } } -static void -eventTuxIsDeadWIthShot(tux_t * tux, shot_t * shot) +static void eventTuxIsDeadWIthShot(tux_t * tux, shot_t * shot) { - if (shot->author_id == tux->id) { - tux->score--; + if (shot->author_id == tux->id) { + tux->score--; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } - if (shot->author_id != tux->id) { - tux_t *author; + if (shot->author_id != tux->id) { + tux_t *author; - author = - getObjectFromSpaceWithID(getCurrentArena()->spaceTux, - shot->author_id); + author = + getObjectFromSpaceWithID(getCurrentArena()->spaceTux, + shot->author_id); - if (author != NULL) { - author->score++; + if (author != NULL) { + author->score++; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); - } - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); + } + } - } + } - countRoundInc(); - eventTuxIsDead(tux); + countRoundInc(); + eventTuxIsDead(tux); } -void -tuxTeleport(tux_t * tux) +void tuxTeleport(tux_t * tux) { - int x, y; + int x, y; #ifndef NO_SOUND - playSound("teleport", SOUND_GROUP_BASE); + playSound("teleport", SOUND_GROUP_BASE); #endif - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - //setTuxProportion(tux, x, y); - } + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + //setTuxProportion(tux, x, y); + } - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } } -static void -bombBallExplosion(shot_t * shot) +static void bombBallExplosion(shot_t * shot) { - item_t *item; - int x, y; + item_t *item; + int x, y; - x = (shot->x + shot->w / 2) - ITEM_BIG_EXPLOSION_WIDTH / 2; - y = (shot->y + shot->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; + x = (shot->x + shot->w / 2) - ITEM_BIG_EXPLOSION_WIDTH / 2; + y = (shot->y + shot->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; - item = newItem(x, y, ITEM_BIG_EXPLOSION, shot->author_id); + item = newItem(x, y, ITEM_BIG_EXPLOSION, shot->author_id); - addObjectToSpace(getCurrentArena()->spaceItem, item); + addObjectToSpace(getCurrentArena()->spaceItem, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); - proto_send_additem_server(PROTO_SEND_ALL, NULL, item); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + } - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, - destroyShot); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, + destroyShot); } -static void -action_tux(space_t * space, tux_t * tux, shot_t * shot) +static void action_tux(space_t * space, tux_t * tux, shot_t * shot) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - if (tux->status == TUX_STATUS_ALIVE) { - if (shot->author_id == tux->id && shot->isCanKillAuthor == FALSE) { - return; - } + if (tux->status == TUX_STATUS_ALIVE) { + if (shot->author_id == tux->id && shot->isCanKillAuthor == FALSE) { + return; + } - if (tux->bonus == BONUS_TELEPORT) { - tuxTeleport(tux); - return; - } + if (tux->bonus == BONUS_TELEPORT) { + tuxTeleport(tux); + return; + } - if (shot->gun == GUN_BOMBBALL) { - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - bombBallExplosion(shot); - } + if (shot->gun == GUN_BOMBBALL) { + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + bombBallExplosion(shot); + } - return; - } + return; + } - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - eventTuxIsDeadWIthShot(tux, shot); - } - } + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + eventTuxIsDeadWIthShot(tux, shot); + } + } - delObjectFromSpaceWithObject(arena->spaceShot, shot, destroyShot); + delObjectFromSpaceWithObject(arena->spaceShot, shot, destroyShot); } -static void -action_shot(space_t * space, shot_t * shot, space_t * spaceTux) +static void action_shot(space_t * space, shot_t * shot, space_t * spaceTux) { - actionSpaceFromLocation(spaceTux, action_tux, shot, shot->x, shot->y, - shot->w, shot->h); + actionSpaceFromLocation(spaceTux, action_tux, shot, shot->x, shot->y, + shot->w, shot->h); } -void -eventConflictTuxWithShot(arena_t * arena) +void eventConflictTuxWithShot(arena_t * arena) { - actionSpace(arena->spaceShot, action_shot, arena->spaceTux); + actionSpace(arena->spaceShot, action_shot, arena->spaceTux); } -void -moveTux(tux_t * tux, int n) +void moveTux(tux_t * tux, int n) { - int px = 0, py = 0; // no warninng - int zal_x, zal_y; - int new_x, new_y; - int w, h; - arena_t *arena; + int px = 0, py = 0; // no warninng + int zal_x, zal_y; + int new_x, new_y; + int w, h; + arena_t *arena; - assert(tux != NULL); + assert(tux != NULL); - arena = getCurrentArena(); - //interval(); + arena = getCurrentArena(); + //interval(); - if (tux->position != n) { - tux->position = n; - return; - } + if (tux->position != n) { + tux->position = n; + return; + } - if ((n == TUX_LEFT && tux->x - TUX_STEP <= 0) || - (n == TUX_RIGHT && tux->x + TUX_STEP >= arena->w) || - (n == TUX_UP && tux->y - TUX_STEP <= 0) || - (n == TUX_DOWN && tux->y + TUX_STEP >= arena->h)) { - return; - } + if ((n == TUX_LEFT && tux->x - TUX_STEP <= 0) || + (n == TUX_RIGHT && tux->x + TUX_STEP >= arena->w) || + (n == TUX_UP && tux->y - TUX_STEP <= 0) || + (n == TUX_DOWN && tux->y + TUX_STEP >= arena->h)) { + return; + } - getTuxProportion(tux, &zal_x, &zal_y, &w, &h); + getTuxProportion(tux, &zal_x, &zal_y, &w, &h); - getCourse(tux->position, &px, &py); + getCourse(tux->position, &px, &py); - new_x = zal_x; - new_y = zal_y; + new_x = zal_x; + new_y = zal_y; - new_x += px * TUX_STEP; - new_y += py * TUX_STEP; + new_x += px * TUX_STEP; + new_y += py * TUX_STEP; - if (tux->bonus == BONUS_SPEED) { - new_x += px * TUX_STEP; - new_y += py * TUX_STEP; - } + if (tux->bonus == BONUS_SPEED) { + new_x += px * TUX_STEP; + new_y += py * TUX_STEP; + } - if (tux->bonus != BONUS_GHOST - && - (isConflictWithObjectFromSpaceBut - (arena->spaceTux, new_x, new_y, w, h, tux) - || isConflictModule(new_x, new_y, w, h))) { - setTuxProportion(tux, zal_x, zal_y); - return; - } + if (tux->bonus != BONUS_GHOST + && + (isConflictWithObjectFromSpaceBut + (arena->spaceTux, new_x, new_y, w, h, tux) + || isConflictModule(new_x, new_y, w, h))) { + setTuxProportion(tux, zal_x, zal_y); + return; + } - setTuxProportion(tux, zal_x, zal_y); - moveObjectInSpace(arena->spaceTux, tux, new_x, new_y); - eventGiveTuxListItem(tux, getCurrentArena()->spaceItem); - tux->frame++; - if (tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME) - tux->frame = 0; + setTuxProportion(tux, zal_x, zal_y); + moveObjectInSpace(arena->spaceTux, tux, new_x, new_y); + eventGiveTuxListItem(tux, getCurrentArena()->spaceItem); + tux->frame++; + if (tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME) + tux->frame = 0; } -void -switchTuxGun(tux_t * tux) +void switchTuxGun(tux_t * tux) { - int i; + int i; - if (tux->control != TUX_CONTROL_NET && tux->isCanSwitchGun == FALSE) { - return; - } + if (tux->control != TUX_CONTROL_NET && tux->isCanSwitchGun == FALSE) { + return; + } - for (i = tux->gun + 1; i < GUN_COUNT; i++) { - if (tux->shot[i] > 0) { - tux->gun = i; - tux->isCanSwitchGun = FALSE; - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_tuxCanSwitchGun, newInt(tux->id), - TUX_TIME_CAN_SWITCH_GUN); + for (i = tux->gun + 1; i < GUN_COUNT; i++) { + if (tux->shot[i] > 0) { + tux->gun = i; + tux->isCanSwitchGun = FALSE; + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - return; - } - } - - for (i = 0; i < GUN_COUNT; i++) { - if (tux->shot[i] > 0) { - tux->gun = i; - tux->isCanSwitchGun = FALSE; - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_tuxCanSwitchGun, newInt(tux->id), - TUX_TIME_CAN_SWITCH_GUN); + return; + } + } + + for (i = 0; i < GUN_COUNT; i++) { + if (tux->shot[i] > 0) { + tux->gun = i; + tux->isCanSwitchGun = FALSE; + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - return; - } - } + return; + } + } } -void -shotTux(tux_t * tux) +void shotTux(tux_t * tux) { - assert(tux != NULL); - - if (tux->isCanShot == FALSE || tux->shot[tux->gun] == 0) { - return; - } + assert(tux != NULL); + if (tux->isCanShot == FALSE || tux->shot[tux->gun] == 0) { + return; + } #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - shotInGun(tux); + shotInGun(tux); - tux->isCanShot = FALSE; + tux->isCanShot = FALSE; - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanShot, - newInt(tux->id), TUX_TIME_CAN_SHOT); + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanShot, + newInt(tux->id), TUX_TIME_CAN_SHOT); - if (tux->shot[tux->gun] == 0) { - switchTuxGun(tux); - } + if (tux->shot[tux->gun] == 0) { + switchTuxGun(tux); + } } -void -actionTux(tux_t * tux, int action) +void actionTux(tux_t * tux, int action) { - if (tux->status == TUX_STATUS_DEAD) { - return; - } - - switch (action) { - case TUX_UP: - case TUX_LEFT: - case TUX_RIGHT: - case TUX_DOWN: - moveTux(tux, action); - break; - - case TUX_SHOT: - shotTux(tux); - break; + if (tux->status == TUX_STATUS_DEAD) { + return; + } - case TUX_SWITCH_GUN: - switchTuxGun(tux); - break; - } + switch (action) { + case TUX_UP: + case TUX_LEFT: + case TUX_RIGHT: + case TUX_DOWN: + moveTux(tux, action); + break; + + case TUX_SHOT: + shotTux(tux); + break; + + case TUX_SWITCH_GUN: + switchTuxGun(tux); + break; + } } -static void -pickUpGun(tux_t * tux) +static void pickUpGun(tux_t * tux) { - if (isTuxAnyGun(tux) == FALSE) { - tux->gun = GUN_SIMPLE; + if (isTuxAnyGun(tux) == FALSE) { + tux->gun = GUN_SIMPLE; - if (tux->pickup_time < TUX_MAX_PICKUP) { - tux->pickup_time++; - } + if (tux->pickup_time < TUX_MAX_PICKUP) { + tux->pickup_time++; + } - if (tux->pickup_time == TUX_MAX_PICKUP - && getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + if (tux->pickup_time == TUX_MAX_PICKUP + && getNetTypeGame() != NET_GAME_TYPE_CLIENT) { #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - tux->gun = GUN_SIMPLE; - tux->shot[tux->gun] = GUN_MAX_SHOT; - tux->pickup_time = 0; + tux->gun = GUN_SIMPLE; + tux->shot[tux->gun] = GUN_MAX_SHOT; + tux->pickup_time = 0; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } + } } -static void -eventBonus(tux_t * tux) +static void eventBonus(tux_t * tux) { - if (tux->bonus != BONUS_NONE) { - if (tux->bonus_time > 0) { - tux->bonus_time--; - } + if (tux->bonus != BONUS_NONE) { + if (tux->bonus_time > 0) { + tux->bonus_time--; + } - if (tux->bonus_time == 0 && getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - if (tux->bonus == BONUS_GHOST) { - int x, y, w, h; - getTuxProportion(tux, &x, &y, &w, &h); + if (tux->bonus_time == 0 && getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + if (tux->bonus == BONUS_GHOST) { + int x, y, w, h; + getTuxProportion(tux, &x, &y, &w, &h); - tux->bonus = BONUS_NONE; + tux->bonus = BONUS_NONE; - if ( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ - isConflictModule(x, y, w, h)) { - tux->bonus = BONUS_GHOST; - return; - } - } + if ( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ + isConflictModule(x, y, w, h)) { + tux->bonus = BONUS_GHOST; + return; + } + } - tux->bonus = BONUS_NONE; + tux->bonus = BONUS_NONE; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } + } } -void -eventTux(tux_t * tux) +void eventTux(tux_t * tux) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); #ifndef PUBLIC_SERVER - tuxControl(tux); + tuxControl(tux); #endif - pickUpGun(tux); - eventBonus(tux); - eventGiveTuxListItem(tux, arena->spaceItem); + pickUpGun(tux); + eventBonus(tux); + eventGiveTuxListItem(tux, arena->spaceItem); } /* @@ -709,75 +681,68 @@ void eventListTux(list_t *listTux) } } */ -void -getTuxProportion(tux_t * tux, int *x, int *y, int *w, int *h) +void getTuxProportion(tux_t * tux, int *x, int *y, int *w, int *h) { - assert(tux != NULL); + assert(tux != NULL); - if (x != NULL) - *x = tux->x - TUX_WIDTH / 2; - if (y != NULL) - *y = tux->y - TUX_HEIGHT / 2; - if (w != NULL) - *w = TUX_WIDTH; - if (h != NULL) - *h = TUX_HEIGHT; + if (x != NULL) + *x = tux->x - TUX_WIDTH / 2; + if (y != NULL) + *y = tux->y - TUX_HEIGHT / 2; + if (w != NULL) + *w = TUX_WIDTH; + if (h != NULL) + *h = TUX_HEIGHT; } -void -setTuxProportion(tux_t * tux, int x, int y) +void setTuxProportion(tux_t * tux, int x, int y) { - assert(tux != NULL); + assert(tux != NULL); - tux->x = x + TUX_WIDTH / 2; - tux->y = y + TUX_WIDTH / 2; + tux->x = x + TUX_WIDTH / 2; + tux->y = y + TUX_WIDTH / 2; } -void -getStatusTux(void *p, int *id, int *x, int *y, int *w, int *h) +void getStatusTux(void *p, int *id, int *x, int *y, int *w, int *h) { - tux_t *tux; + tux_t *tux; - tux = p; - *id = tux->id; - getTuxProportion(tux, x, y, w, h); + tux = p; + *id = tux->id; + getTuxProportion(tux, x, y, w, h); } -void -setStatusTux(void *p, int x, int y, int w, int h) +void setStatusTux(void *p, int x, int y, int w, int h) { - tux_t *tux; + tux_t *tux; - tux = p; - setTuxProportion(tux, x, y); + tux = p; + setTuxProportion(tux, x, y); } -static void -action_checkMine(space_t * space, item_t * item, tux_t * tux) +static void action_checkMine(space_t * space, item_t * item, tux_t * tux) { - if (item->type == ITEM_MINE && item->author_id == tux->id) { - item->author_id = ID_UNKNOWN; - } + if (item->type == ITEM_MINE && item->author_id == tux->id) { + item->author_id = ID_UNKNOWN; + } } -void -destroyTux(tux_t * tux) +void destroyTux(tux_t * tux) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - assert(tux != NULL); + assert(tux != NULL); - delID(tux->id); + delID(tux->id); - actionSpace(arena->spaceItem, action_checkMine, tux); + actionSpace(arena->spaceItem, action_checkMine, tux); - free(tux); + free(tux); } -void -quitTux() +void quitTux() { - isTuxInit = FALSE; + isTuxInit = FALSE; } diff --git a/src/base/tux.h b/src/base/tux.h index 39ead49..ae86c71 100644 --- a/src/base/tux.h +++ b/src/base/tux.h @@ -1,112 +1,111 @@ #ifndef TUX_H -#define TUX_H +# define TUX_H -#include "main.h" -#include "list.h" -#include "arena.h" +# include "main.h" +# include "list.h" +# include "arena.h" -#define TUX_STEP 7 -#define TUX_LAYER 0 +# define TUX_STEP 7 +# define TUX_LAYER 0 -#define TUX_MAX_ANIMATION_FRAME 10 -#define TUX_KEY 1 +# define TUX_MAX_ANIMATION_FRAME 10 +# define TUX_KEY 1 -#define TUX_LOCATE_UNKNOWN -100 +# define TUX_LOCATE_UNKNOWN -100 -#define TUX_MAX_PICKUP 50 -#define TUX_MAX_BONUS 500 +# define TUX_MAX_PICKUP 50 +# define TUX_MAX_BONUS 500 -#define TUX_TIME_SPAWN 2000 -#define TUX_TIME_CAN_SHOT 500 -#define TUX_TIME_CAN_SWITCH_GUN 100 +# define TUX_TIME_SPAWN 2000 +# define TUX_TIME_CAN_SHOT 500 +# define TUX_TIME_CAN_SWITCH_GUN 100 -#define TUX_STATUS_ALIVE 0 -#define TUX_STATUS_DEAD 1 -#define TUX_STATUS_PAUZED 2 +# define TUX_STATUS_ALIVE 0 +# define TUX_STATUS_DEAD 1 +# define TUX_STATUS_PAUZED 2 -#define TUX_CONTROL_NONE 0 -#define TUX_CONTROL_KEYBOARD_LEFT 1 -#define TUX_CONTROL_KEYBOARD_RIGHT 2 -#define TUX_CONTROL_NET 3 -#define TUX_CONTROL_AI 4 +# define TUX_CONTROL_NONE 0 +# define TUX_CONTROL_KEYBOARD_LEFT 1 +# define TUX_CONTROL_KEYBOARD_RIGHT 2 +# define TUX_CONTROL_NET 3 +# define TUX_CONTROL_AI 4 -#define TUX_WIDTH 30 -#define TUX_HEIGHT 30 +# define TUX_WIDTH 30 +# define TUX_HEIGHT 30 -#define TUX_IMG_WIDTH 40 -#define TUX_IMG_HEIGHT 54 +# define TUX_IMG_WIDTH 40 +# define TUX_IMG_HEIGHT 54 -#define TUX_UP 8 -#define TUX_LEFT 4 -#define TUX_RIGHT 6 -#define TUX_DOWN 2 -#define POSITION_UNKNOWN -1 +# define TUX_UP 8 +# define TUX_LEFT 4 +# define TUX_RIGHT 6 +# define TUX_DOWN 2 +# define POSITION_UNKNOWN -1 -#define TUX_SHOT 5 -#define TUX_SWITCH_GUN 0 +# define TUX_SHOT 5 +# define TUX_SWITCH_GUN 0 -#define GUN_NONE -1 +# define GUN_NONE -1 -#define GUN_COUNT 7 -#define GUN_MAX_SHOT 5 +# define GUN_COUNT 7 +# define GUN_MAX_SHOT 5 -#define BONUS_COUNT 6 -#define ITEM_COUNT 16 +# define BONUS_COUNT 6 +# define ITEM_COUNT 16 -#define SHOT_CHECK_AREA 25 +# define SHOT_CHECK_AREA 25 -#define GUN_SIMPLE 0 -#define GUN_DUAL_SIMPLE 1 -#define GUN_SCATTER 2 -#define GUN_TOMMY 3 -#define GUN_LASSER 4 -#define GUN_MINE 5 -#define GUN_BOMBBALL 6 +# define GUN_SIMPLE 0 +# define GUN_DUAL_SIMPLE 1 +# define GUN_SCATTER 2 +# define GUN_TOMMY 3 +# define GUN_LASSER 4 +# define GUN_MINE 5 +# define GUN_BOMBBALL 6 -#define ITEM_MINE 7 -#define ITEM_EXPLOSION 8 -#define ITEM_BIG_EXPLOSION 9 +# define ITEM_MINE 7 +# define ITEM_EXPLOSION 8 +# define ITEM_BIG_EXPLOSION 9 -#define BONUS_NONE -1 -#define BONUS_SPEED 10 -#define BONUS_SHOT 11 -#define BONUS_TELEPORT 12 -#define BONUS_GHOST 13 -#define BONUS_4X 14 -#define BONUS_HIDDEN 15 +# define BONUS_NONE -1 +# define BONUS_SPEED 10 +# define BONUS_SHOT 11 +# define BONUS_TELEPORT 12 +# define BONUS_GHOST 13 +# define BONUS_4X 14 +# define BONUS_HIDDEN 15 -typedef struct tux_struct -{ - int id; +typedef struct tux_struct { + int id; - int x; - int y; + int x; + int y; - char name[STR_NAME_SIZE]; + char name[STR_NAME_SIZE]; - int status; - int control; - int position; - int score; + int status; + int control; + int position; + int score; - int gun; - int shot[GUN_COUNT]; - int round; - int bonus; + int gun; + int shot[GUN_COUNT]; + int round; + int bonus; - int bonus_time; - int pickup_time; + int bonus_time; + int pickup_time; - bool_t isCanShot; - bool_t isCanSwitchGun; + bool_t isCanShot; + bool_t isCanSwitchGun; - int frame; + int frame; - void *client; + void *client; } tux_t; extern bool_t isTuxInicialized(); diff --git a/src/base/udp_server.c b/src/base/udp_server.c index 7656ff1..1b3e9b6 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -9,12 +9,12 @@ #include <sys/time.h> #ifndef __WIN32__ -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/select.h> +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <sys/select.h> #else -#include <io.h> -#include <winsock2.h> +# include <io.h> +# include <winsock2.h> #endif #include "main.h" @@ -30,13 +30,13 @@ #include "index.h" #ifndef PUBLIC_SERVER -#include "screen_world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" -#include "highScore.h" -#include "log.h" +# include "publicServer.h" +# include "highScore.h" +# include "log.h" #endif #include "udp.h" @@ -46,232 +46,218 @@ static sock_udp_t *sock_server_udp; static sock_udp_t *sock_server_udp_second; -client_t * -newUdpClient(sock_udp_t * sock_udp) +client_t *newUdpClient(sock_udp_t * sock_udp) { - client_t *new; + client_t *new; - assert(sock_udp != NULL); + assert(sock_udp != NULL); - new = newAnyClient(); - new->type = CLIENT_TYPE_UDP; - new->socket_udp = sock_udp; + new = newAnyClient(); + new->type = CLIENT_TYPE_UDP; + new->socket_udp = sock_udp; #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, - getSockUdpPort(sock_udp)); - addToLog(LOG_INF, str_log); + getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, + getSockUdpPort(sock_udp)); + addToLog(LOG_INF, str_log); #endif - return new; + return new; } -void -destroyUdpClient(client_t * p) +void destroyUdpClient(client_t * p) { - eventMsgInCheckFront(p); + eventMsgInCheckFront(p); #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, - getSockUdpPort(p->socket_udp)); - addToLog(LOG_INF, str_log); + getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, + getSockUdpPort(p->socket_udp)); + addToLog(LOG_INF, str_log); #endif - destroySockUdp(p->socket_udp); + destroySockUdp(p->socket_udp); - destroyAnyClient(p); + destroyAnyClient(p); } -int -initUdpServer(char *ip4, int port4, char *ip6, int port6) +int initUdpServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - ret = 0; + ret = 0; - if (ip4 != NULL) { - sock_server_udp = bindUdpSocket(ip4, port4, PROTO_UDPv4); + if (ip4 != NULL) { + sock_server_udp = bindUdpSocket(ip4, port4, PROTO_UDPv4); - if (sock_server_udp != NULL) { - ret++; + if (sock_server_udp != NULL) { + ret++; #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, - port4); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, port4); #endif - } - else { + } else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), - ip4, port4); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip4, port4); #endif - } - } + } + } - if (ip6 != NULL) { - sock_server_udp_second = bindUdpSocket(ip6, port6, PROTO_UDPv6); + if (ip6 != NULL) { + sock_server_udp_second = bindUdpSocket(ip6, port6, PROTO_UDPv6); - if (sock_server_udp_second != NULL) { - ret++; + if (sock_server_udp_second != NULL) { + ret++; #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, - port6); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, port6); #endif - } - else { + } else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), - ip6, port6); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip6, port6); #endif - } - } + } + } - return ret; + return ret; } -static void -eventCreateNewUdpClient(sock_udp_t * socket_udp) +static void eventCreateNewUdpClient(sock_udp_t * socket_udp) { - list_t *listClient; - client_t *client; + list_t *listClient; + client_t *client; - assert(socket_udp != NULL); + assert(socket_udp != NULL); - listClient = getListServerClient(); + listClient = getListServerClient(); - client = newUdpClient(socket_udp); - addList(listClient, client); + client = newUdpClient(socket_udp); + addList(listClient, client); } -static client_t * -findUdpClient(sock_udp_t * sock_udp) +static client_t *findUdpClient(sock_udp_t * sock_udp) { - list_t *listClient; - int port; - int i; + list_t *listClient; + int port; + int i; - port = getSockUdpPort(sock_udp); - listClient = getListServerClient(); + port = getSockUdpPort(sock_udp); + listClient = getListServerClient(); - for (i = 0; i < listClient->count; i++) { - client_t *client; + for (i = 0; i < listClient->count; i++) { + client_t *client; - client = (client_t *) listClient->list[i]; + client = (client_t *) listClient->list[i]; - if (client->type == CLIENT_TYPE_UDP && - getSockUdpPort(client->socket_udp) == port) { - return client; - } - } + if (client->type == CLIENT_TYPE_UDP && + getSockUdpPort(client->socket_udp) == port) { + return client; + } + } - return NULL; + return NULL; } -static void -eventClientUdpSelect(sock_udp_t * sock_server) +static void eventClientUdpSelect(sock_udp_t * sock_server) { - sock_udp_t *sock_client; - client_t *client; - char listRecvMsg[STR_SIZE]; - bool_t isCreateNewClient; - int ret; + sock_udp_t *sock_client; + client_t *client; + char listRecvMsg[STR_SIZE]; + bool_t isCreateNewClient; + int ret; - assert(sock_server != NULL); + assert(sock_server != NULL); - sock_client = newSockUdp(sock_server->proto); - isCreateNewClient = FALSE; + sock_client = newSockUdp(sock_server->proto); + isCreateNewClient = FALSE; - memset(listRecvMsg, 0, STR_SIZE); + memset(listRecvMsg, 0, STR_SIZE); - ret = readUdpSocket(sock_server, sock_client, listRecvMsg, STR_SIZE - 1); + ret = readUdpSocket(sock_server, sock_client, listRecvMsg, STR_SIZE - 1); - client = findUdpClient(sock_client); + client = findUdpClient(sock_client); - if (client == NULL) { - eventCreateNewUdpClient(sock_client); - client = findUdpClient(sock_client); - isCreateNewClient = TRUE; - } + if (client == NULL) { + eventCreateNewUdpClient(sock_client); + client = findUdpClient(sock_client); + isCreateNewClient = TRUE; + } - if (client == NULL) { - fprintf(stderr, _("Client was not FOUND!\n")); - return; - } + if (client == NULL) { + fprintf(stderr, _("Client was not FOUND!\n")); + return; + } - if (isCreateNewClient == FALSE) { - destroySockUdp(sock_client); - } + if (isCreateNewClient == FALSE) { + destroySockUdp(sock_client); + } - if (ret <= 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } - - //printf("add packet >>%s<<\n", listRecvMsg); - addList(client->listRecvMsg, strdup(listRecvMsg)); + if (ret <= 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } + //printf("add packet >>%s<<\n", listRecvMsg); + addList(client->listRecvMsg, strdup(listRecvMsg)); } -void -setServerUdpSelect() +void setServerUdpSelect() { - if (sock_server_udp != NULL) { - addSockToSelectRead(sock_server_udp->sock); - } + if (sock_server_udp != NULL) { + addSockToSelectRead(sock_server_udp->sock); + } - if (sock_server_udp_second != NULL) { - addSockToSelectRead(sock_server_udp_second->sock); - } + if (sock_server_udp_second != NULL) { + addSockToSelectRead(sock_server_udp_second->sock); + } } -int -selectServerUdpSocket() +int selectServerUdpSocket() { - int count; + int count; - count = 0; + count = 0; - if (sock_server_udp != NULL) { - if (isChangeSockInSelectRead(sock_server_udp->sock)) { - eventClientUdpSelect(sock_server_udp); - count++; - } - } + if (sock_server_udp != NULL) { + if (isChangeSockInSelectRead(sock_server_udp->sock)) { + eventClientUdpSelect(sock_server_udp); + count++; + } + } - if (sock_server_udp_second != NULL) { - if (isChangeSockInSelectRead(sock_server_udp_second->sock)) { - eventClientUdpSelect(sock_server_udp_second); - count++; - } - } + if (sock_server_udp_second != NULL) { + if (isChangeSockInSelectRead(sock_server_udp_second->sock)) { + eventClientUdpSelect(sock_server_udp_second); + count++; + } + } - return count; + return count; } -void -quitUdpServer() +void quitUdpServer() { - if (sock_server_udp != NULL) { + if (sock_server_udp != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), getSockUdpPort(sock_server_udp)); + printf(_("Closing port: \"%d\"\n"), getSockUdpPort(sock_server_udp)); #endif - closeUdpSocket(sock_server_udp); - } + closeUdpSocket(sock_server_udp); + } - if (sock_server_udp_second != NULL) { + if (sock_server_udp_second != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), - getSockUdpPort(sock_server_udp_second)); + printf(_("Closing port: \"%d\"\n"), + getSockUdpPort(sock_server_udp_second)); #endif - closeUdpSocket(sock_server_udp_second); - } + closeUdpSocket(sock_server_udp_second); + } #ifdef DEBUG - printf(_("Quitting UDP\n")); + printf(_("Quitting UDP\n")); #endif } diff --git a/src/base/udp_server.h b/src/base/udp_server.h index 85a6f8e..25d680d 100644 --- a/src/base/udp_server.h +++ b/src/base/udp_server.h @@ -1,10 +1,10 @@ #ifndef SERVER_UDP_H -#define SERVER_UDP_H +# define SERVER_UDP_H -#include "server.h" -#include "udp.h" +# include "server.h" +# include "udp.h" extern client_t *newUdpClient(sock_udp_t * sock_udp); extern void destroyUdpClient(client_t * p); diff --git a/src/client/chat.c b/src/client/chat.c index c6d0325..ceb4796 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -33,226 +33,213 @@ static bool_t receivedNewMsg; static void hotkey_chat(); -static void -hotkey_chat() +static void hotkey_chat() { - chat_active = TRUE; - receivedNewMsg = FALSE; + chat_active = TRUE; + receivedNewMsg = FALSE; - disableHotKey(SDLK_RETURN); - disableHotKey(SDLK_p); + disableHotKey(SDLK_RETURN); + disableHotKey(SDLK_p); - enableKeyboardBuffer(); - clearKeyboardBuffer(); + enableKeyboardBuffer(); + clearKeyboardBuffer(); } -void -initChat() +void initChat() { - g_chat = - addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER); - - listText = newList(); - strcpy(line, ""); - chat_active = FALSE; - registerHotKey(SDLK_RETURN, hotkey_chat); - - receivedNewMsg = FALSE; - line_time = 0; - line_atime = 0; - timeBlick = 0; + g_chat = + addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER); + + listText = newList(); + strcpy(line, ""); + chat_active = FALSE; + registerHotKey(SDLK_RETURN, hotkey_chat); + + receivedNewMsg = FALSE; + line_time = 0; + line_atime = 0; + timeBlick = 0; } -void -drawChat() +void drawChat() { - char str[STR_SIZE]; - int i; + char str[STR_SIZE]; + int i; - if (chat_active == FALSE) { - return; - } + if (chat_active == FALSE) { + return; + } - drawImage(g_chat, - CHAT_LOCATION_X, CHAT_LOCATION_Y, - 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y); + drawImage(g_chat, + CHAT_LOCATION_X, CHAT_LOCATION_Y, + 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y); - for (i = 0; i < listText->count; i++) { - char *s; + for (i = 0; i < listText->count; i++) { + char *s; - s = (char *) listText->list[i]; + s = (char *) listText->list[i]; - drawFontMaxSize(s, - CHAT_LOCATION_X + 5, CHAT_LOCATION_Y + 5 + i * 20, - CHAT_SIZE_X - 10, 20, COLOR_WHITE); - } + drawFontMaxSize(s, + CHAT_LOCATION_X + 5, CHAT_LOCATION_Y + 5 + i * 20, + CHAT_SIZE_X - 10, 20, COLOR_WHITE); + } - strcpy(str, line); + strcpy(str, line); - if (timeBlick > CHAT_TIME_BLICK_CURSOR / 2) { - strcat(str, "\f"); - } + if (timeBlick > CHAT_TIME_BLICK_CURSOR / 2) { + strcat(str, "\f"); + } - timeBlick++; + timeBlick++; - if (timeBlick == CHAT_TIME_BLICK_CURSOR) { - timeBlick = 0; - } + if (timeBlick == CHAT_TIME_BLICK_CURSOR) { + timeBlick = 0; + } - drawFont(str, CHAT_LOCATION_X + 5, - (CHAT_LOCATION_Y + 5) + (CHAT_MAX_LINES * 20), COLOR_WHITE); + drawFont(str, CHAT_LOCATION_X + 5, + (CHAT_LOCATION_Y + 5) + (CHAT_MAX_LINES * 20), COLOR_WHITE); } -static void -processMessageKey(SDL_keysym keysym) +static void processMessageKey(SDL_keysym keysym) { - int w, h; - int len; - //int i; - - if (line_atime < 100) - line_atime++; - - len = strlen(line); - getTextSize(line, &w, &h); - - if (w > CHAT_SIZE_X - 40) { - return; - } - - /* processing of backspace */ - if (keysym.sym == SDLK_BACKSPACE && len > 0) { - line[len - 1] = '\0'; - return; - } - - /* processing of printable chars but not letters */ - if ((keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT) - || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE)) { - /* here would be much better to put 'strcat' as 'line' is expected - * to be full of '0' up to its end - */ - line[len] = keysym.sym; - } - - /* processing of letters */ - if (keysym.sym >= SDLK_a && keysym.sym <= SDLK_z) { - char c = keysym.sym; - if (keysym.mod == KMOD_SHIFT) { - c = toupper(c); - } - /* here would be much better to put 'strcat' as 'line' is expected - * to be full of '0' up to its end - */ - line[len] = c; - } - - return; + int w, h; + int len; + //int i; + + if (line_atime < 100) + line_atime++; + + len = strlen(line); + getTextSize(line, &w, &h); + + if (w > CHAT_SIZE_X - 40) { + return; + } + + /* processing of backspace */ + if (keysym.sym == SDLK_BACKSPACE && len > 0) { + line[len - 1] = '\0'; + return; + } + + /* processing of printable chars but not letters */ + if ((keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT) + || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE)) { + /* here would be much better to put 'strcat' as 'line' is expected + * to be full of '0' up to its end + */ + line[len] = keysym.sym; + } + + /* processing of letters */ + if (keysym.sym >= SDLK_a && keysym.sym <= SDLK_z) { + char c = keysym.sym; + if (keysym.mod == KMOD_SHIFT) { + c = toupper(c); + } + /* here would be much better to put 'strcat' as 'line' is expected + * to be full of '0' up to its end + */ + line[len] = c; + } + + return; } -static void -sendNewMessage() +static void sendNewMessage() { - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) { - proto_send_chat_client(line); - } + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) { + proto_send_chat_client(line); + } - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { - char out[STR_PROTO_SIZE]; + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", - getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line); + snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line); - proto_send_chat_server(PROTO_SEND_ALL, NULL, out); - } + proto_send_chat_server(PROTO_SEND_ALL, NULL, out); + } } -static void -eventChatDisable() +static void eventChatDisable() { - chat_active = FALSE; - memset(line, '\0', STR_SIZE); + chat_active = FALSE; + memset(line, '\0', STR_SIZE); - enableHotKey(SDLK_RETURN); - enableHotKey(SDLK_p); + enableHotKey(SDLK_RETURN); + enableHotKey(SDLK_p); - disableKeyboardBuffer(); - clearKeyboardBuffer(); + disableKeyboardBuffer(); + clearKeyboardBuffer(); } -static void -eventChatEnable() +static void eventChatEnable() { - /* The chat window is displayed. It is needed to process all keys in the buffer - * but when ENTER is pressed the chat row is sent to the server - */ - - while (isAnyKeyInKeyboardBuffer() == TRUE) { - SDL_keysym key; - key = popKeyFromKeyboardBuffer(); - - if (key.sym == SDLK_RETURN) { - if (strcmp(line, "") != 0) { - /* the chat row is already written - it is needed to send it */ - sendNewMessage(); - memset(line, '\0', STR_SIZE); - continue; /* continue with other keys */ - } - else { - /* the chat row is empty - it is needed to turn off the chat window */ - eventChatDisable(); - /* turn off key catching into the buffer and clear the buffer */ - //disableKeyboardBuffer(); - //clearKeyboardBuffer(); - } - } - - processMessageKey(key); - } + /* The chat window is displayed. It is needed to process all keys in the buffer + * but when ENTER is pressed the chat row is sent to the server + */ + + while (isAnyKeyInKeyboardBuffer() == TRUE) { + SDL_keysym key; + key = popKeyFromKeyboardBuffer(); + + if (key.sym == SDLK_RETURN) { + if (strcmp(line, "") != 0) { + /* the chat row is already written - it is needed to send it */ + sendNewMessage(); + memset(line, '\0', STR_SIZE); + continue; /* continue with other keys */ + } else { + /* the chat row is empty - it is needed to turn off the chat window */ + eventChatDisable(); + /* turn off key catching into the buffer and clear the buffer */ + //disableKeyboardBuffer(); + //clearKeyboardBuffer(); + } + } + + processMessageKey(key); + } } /** * Processing of chat 'events' */ -void -eventChat() +void eventChat() { - if (isChatActive()) { - eventChatEnable(); - } + if (isChatActive()) { + eventChatEnable(); + } } -bool_t -isChatActive() +bool_t isChatActive() { - return chat_active; + return chat_active; } -bool_t -isRecivedNewMsg() +bool_t isRecivedNewMsg() { - return receivedNewMsg; + return receivedNewMsg; } -void -addToChat(char *s) +void addToChat(char *s) { - addList(listText, strdup(s)); + addList(listText, strdup(s)); - if (listText->count > CHAT_MAX_LINES) { - delListItem(listText, 0, free); - } + if (listText->count > CHAT_MAX_LINES) { + delListItem(listText, 0, free); + } - if (chat_active == FALSE) { - receivedNewMsg = TRUE; - } + if (chat_active == FALSE) { + receivedNewMsg = TRUE; + } } -void -quitChat() +void quitChat() { - assert(listText != NULL); + assert(listText != NULL); - unregisterHotKey(SDLK_RETURN); - destroyListItem(listText, free); + unregisterHotKey(SDLK_RETURN); + destroyListItem(listText, free); } diff --git a/src/client/chat.h b/src/client/chat.h index fc6abc3..9022466 100644 --- a/src/client/chat.h +++ b/src/client/chat.h @@ -1,18 +1,18 @@ #ifndef CHAT_H -#define CHAT_H +# define CHAT_H -#define CHAT_MAX_LINES 10 -#define CHAT_TIME_MULTIPLE 10 -#define CHAT_TIME_BLICK_CURSOR 20 -#define CHAT_LINE_WIDTH 320 +# define CHAT_MAX_LINES 10 +# define CHAT_TIME_MULTIPLE 10 +# define CHAT_TIME_BLICK_CURSOR 20 +# define CHAT_LINE_WIDTH 320 -#define CHAT_SIZE_X 320 -#define CHAT_SIZE_Y 240 +# define CHAT_SIZE_X 320 +# define CHAT_SIZE_Y 240 -#define CHAT_LOCATION_X (WINDOW_SIZE_X/2 - CHAT_SIZE_X/2) -#define CHAT_LOCATION_Y (WINDOW_SIZE_Y/2 - CHAT_SIZE_Y/2) +# define CHAT_LOCATION_X (WINDOW_SIZE_X/2 - CHAT_SIZE_X/2) +# define CHAT_LOCATION_Y (WINDOW_SIZE_Y/2 - CHAT_SIZE_Y/2) extern void initChat(); extern void drawChat(); diff --git a/src/client/client.c b/src/client/client.c index 7ff9257..1f309fa 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -8,12 +8,12 @@ #include <sys/time.h> #ifndef __WIN32__ -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/select.h> +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <sys/select.h> #else -#include <io.h> -#include <winsock2.h> +# include <io.h> +# include <winsock2.h> #endif #include "main.h" @@ -45,337 +45,319 @@ static int traffic_down; static int traffic_up; #endif -typedef struct proto_cmd_client_struct -{ - char *name; - int len; - void (*fce_proto) (char *msg); +typedef struct proto_cmd_client_struct { + char *name; + int len; + void (*fce_proto) (char *msg); } proto_cmd_client_t; static proto_cmd_client_t proto_cmd_list[] = { - {.name = "error",.len = 5,.fce_proto = proto_recv_error_client}, - {.name = "init",.len = 4,.fce_proto = proto_recv_init_client}, - {.name = "event",.len = 5,.fce_proto = proto_recv_event_client}, - {.name = "newtux",.len = 6,.fce_proto = proto_recv_newtux_client}, - {.name = "del",.len = 3,.fce_proto = proto_recv_del_client}, - {.name = "additem",.len = 7,.fce_proto = proto_recv_additem_client}, - {.name = "shot",.len = 4,.fce_proto = proto_recv_shot_client}, - {.name = "kill",.len = 4,.fce_proto = proto_recv_kill_client}, - {.name = "module",.len = 6,.fce_proto = proto_recv_module_client}, - {.name = "chat",.len = 4,.fce_proto = proto_recv_chat_client}, - {.name = "ping",.len = 4,.fce_proto = proto_recv_ping_client}, - {.name = "end",.len = 3,.fce_proto = proto_recv_end_client}, - {.name = "",.len = 0,.fce_proto = NULL}, + {.name = "error",.len = 5,.fce_proto = proto_recv_error_client}, + {.name = "init",.len = 4,.fce_proto = proto_recv_init_client}, + {.name = "event",.len = 5,.fce_proto = proto_recv_event_client}, + {.name = "newtux",.len = 6,.fce_proto = proto_recv_newtux_client}, + {.name = "del",.len = 3,.fce_proto = proto_recv_del_client}, + {.name = "additem",.len = 7,.fce_proto = proto_recv_additem_client}, + {.name = "shot",.len = 4,.fce_proto = proto_recv_shot_client}, + {.name = "kill",.len = 4,.fce_proto = proto_recv_kill_client}, + {.name = "module",.len = 6,.fce_proto = proto_recv_module_client}, + {.name = "chat",.len = 4,.fce_proto = proto_recv_chat_client}, + {.name = "ping",.len = 4,.fce_proto = proto_recv_ping_client}, + {.name = "end",.len = 3,.fce_proto = proto_recv_end_client}, + {.name = "",.len = 0,.fce_proto = NULL}, }; -static proto_cmd_client_t * -findCmdProto(char *msg) +static proto_cmd_client_t *findCmdProto(char *msg) { - int len; - int i; + int len; + int i; - len = strlen(msg); + len = strlen(msg); - for (i = 0; proto_cmd_list[i].len != 0; i++) { - proto_cmd_client_t *thisCmd; + for (i = 0; proto_cmd_list[i].len != 0; i++) { + proto_cmd_client_t *thisCmd; - thisCmd = &proto_cmd_list[i]; + thisCmd = &proto_cmd_list[i]; - if (len >= thisCmd->len - && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { - return thisCmd; - } - } + if (len >= thisCmd->len + && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { + return thisCmd; + } + } - return NULL; + return NULL; } -static int -initUdpClient(char *ip, int port, int proto) +static int initUdpClient(char *ip, int port, int proto) { - sock_server_udp = connectUdpSocket(ip, port, proto); + sock_server_udp = connectUdpSocket(ip, port, proto); - if (sock_server_udp == NULL) { - return -1; - } + if (sock_server_udp == NULL) { + return -1; + } #ifdef DEBUG - printf(_("Connected to: %s on port: %d via UDP\n"), ip, port); + printf(_("Connected to: %s on port: %d via UDP\n"), ip, port); #endif - return 0; + return 0; } -int -initClient(char *ip, int port, int proto) +int initClient(char *ip, int port, int proto) { - char name[STR_NAME_SIZE]; - int ret; + char name[STR_NAME_SIZE]; + int ret; - listRecvMsg = newList(); - lastPing = getMyTime(); - lastPingServerAlive = getMyTime(); + listRecvMsg = newList(); + lastPing = getMyTime(); + lastPingServerAlive = getMyTime(); #ifdef SUPPORT_TRAFFIC - lastTraffic = getMyTime(); - traffic_down = 0; - traffic_up = 0; + lastTraffic = getMyTime(); + traffic_down = 0; + traffic_up = 0; #endif - clientRecvBuffer = newBuffer(CLIENT_BUFFER_LIMIT); - clientSendBuffer = newBuffer(CLIENT_BUFFER_LIMIT); + clientRecvBuffer = newBuffer(CLIENT_BUFFER_LIMIT); + clientSendBuffer = newBuffer(CLIENT_BUFFER_LIMIT); - ret = initUdpClient(ip, port, proto); + ret = initUdpClient(ip, port, proto); - if (ret < 0) { - return -1; - } + if (ret < 0) { + return -1; + } - getSettingNameRight(name); - proto_send_hello_client(name); + getSettingNameRight(name); + proto_send_hello_client(name); - return 0; + return 0; } -static void -errorWithServer() +static void errorWithServer() { - fprintf(stderr, _("Server did not respond!\n")); - setMsgToAnalyze(_ - ("Server is not running or being blocked. I was unable to connect.")); - setWorldEnd(); + fprintf(stderr, _("Server did not respond!\n")); + setMsgToAnalyze(_ + ("Server is not running or being blocked. I was unable to connect.")); + setWorldEnd(); } -void -sendServer(char *msg) +void sendServer(char *msg) { - int ret; + int ret; - assert(msg != NULL); + assert(msg != NULL); - ret = -1; + ret = -1; #ifndef PUBLIC_SERVER - if (isParamFlag("--send")) { - printf(_("Sending: \"%s\""), msg); - } - + if (isParamFlag("--send")) { + printf(_("Sending: \"%s\""), msg); + } #endif #ifdef SUPPORT_TRAFFIC - traffic_up += strlen(msg); + traffic_up += strlen(msg); #endif - if (sock_server_udp != NULL) { - ret = - writeUdpSocket(sock_server_udp, sock_server_udp, msg, - strlen(msg)); - } + if (sock_server_udp != NULL) { + ret = + writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)); + } - if (ret < 0) { - errorWithServer(); - return; - } + if (ret < 0) { + errorWithServer(); + return; + } } -static int -eventServerSelect() +static int eventServerSelect() { - char buffer[STR_PROTO_SIZE]; - int ret; - - memset(buffer, 0, STR_PROTO_SIZE); - ret = -1; - - if (sock_server_udp != NULL) { - ret = - readUdpSocket(sock_server_udp, sock_server_udp, buffer, - STR_PROTO_SIZE - 1); - } - - if (ret < 0) { - errorWithServer(); - return ret; - } - + char buffer[STR_PROTO_SIZE]; + int ret; + + memset(buffer, 0, STR_PROTO_SIZE); + ret = -1; + + if (sock_server_udp != NULL) { + ret = + readUdpSocket(sock_server_udp, sock_server_udp, buffer, + STR_PROTO_SIZE - 1); + } + + if (ret < 0) { + errorWithServer(); + return ret; + } #ifdef SUPPORT_TRAFFIC - traffic_down += ret; + traffic_down += ret; #endif - addList(listRecvMsg, strdup(buffer)); + addList(listRecvMsg, strdup(buffer)); #if 0 - if (addBuffer(clientRecvBuffer, buffer, ret) < 0) { - errorWithServer(); - return ret; - } - - while (getBufferLine(clientRecvBuffer, buffer, STR_PROTO_SIZE) >= 0) { - if (strlen(buffer) > 0) { - addList(listRecvMsg, strdup(buffer)); - } - } + if (addBuffer(clientRecvBuffer, buffer, ret) < 0) { + errorWithServer(); + return ret; + } + + while (getBufferLine(clientRecvBuffer, buffer, STR_PROTO_SIZE) >= 0) { + if (strlen(buffer) > 0) { + addList(listRecvMsg, strdup(buffer)); + } + } #endif - return ret; + return ret; } -static void -eventClientWorkRecvList() +static void eventClientWorkRecvList() { - proto_cmd_client_t *protoCmd; - char *line; - int i; + proto_cmd_client_t *protoCmd; + char *line; + int i; - /* obsluha udalosti od servera */ + /* obsluha udalosti od servera */ - assert(listRecvMsg != NULL); + assert(listRecvMsg != NULL); - for (i = 0; i < listRecvMsg->count; i++) { - line = (char *) listRecvMsg->list[i]; - protoCmd = findCmdProto(line); + for (i = 0; i < listRecvMsg->count; i++) { + line = (char *) listRecvMsg->list[i]; + protoCmd = findCmdProto(line); #ifndef PUBLIC_SERVER - if (isParamFlag("--recv")) { - printf(_("Recieved: \"%s\""), line); - } + if (isParamFlag("--recv")) { + printf(_("Recieved: \"%s\""), line); + } #endif - if (protoCmd != NULL) { - protoCmd->fce_proto(line); - lastPingServerAlive = getMyTime(); - } - } - - destroyListItem(listRecvMsg, free); - listRecvMsg = newList(); + if (protoCmd != NULL) { + protoCmd->fce_proto(line); + lastPingServerAlive = getMyTime(); + } + } + + destroyListItem(listRecvMsg, free); + listRecvMsg = newList(); } -static void -eventPingServer() +static void eventPingServer() { - my_time_t currentTime; + my_time_t currentTime; - currentTime = getMyTime(); + currentTime = getMyTime(); - if (currentTime - lastPing > CLIENT_TIMEOUT) { - proto_send_ping_client(); - lastPing = getMyTime(); - } + if (currentTime - lastPing > CLIENT_TIMEOUT) { + proto_send_ping_client(); + lastPing = getMyTime(); + } } -static bool_t -isServerAlive() +static bool_t isServerAlive() { - my_time_t currentTime; + my_time_t currentTime; - currentTime = getMyTime(); + currentTime = getMyTime(); - if (currentTime - lastPingServerAlive > SERVER_TIMEOUT_ALIVE) { - return FALSE; - } + if (currentTime - lastPingServerAlive > SERVER_TIMEOUT_ALIVE) { + return FALSE; + } - return TRUE; + return TRUE; } -static void -selectClientSocket() +static void selectClientSocket() { - fd_set readfds; - struct timeval tv; - int max_fd; - int sock; - bool_t isNext; + fd_set readfds; + struct timeval tv; + int max_fd; + int sock; + bool_t isNext; - max_fd = 0; - sock = 0; + max_fd = 0; + sock = 0; - if (sock_server_udp != NULL) { - if (isServerAlive() == FALSE) { - errorWithServer(); - return; - } - } + if (sock_server_udp != NULL) { + if (isServerAlive() == FALSE) { + errorWithServer(); + return; + } + } - do { - isNext = FALSE; + do { + isNext = FALSE; - tv.tv_sec = 0; - tv.tv_usec = 0; + tv.tv_sec = 0; + tv.tv_usec = 0; - FD_ZERO(&readfds); + FD_ZERO(&readfds); - if (sock_server_udp != NULL) { - sock = sock_server_udp->sock; - } + if (sock_server_udp != NULL) { + sock = sock_server_udp->sock; + } - FD_SET(sock, &readfds); - max_fd = sock; - select(max_fd + 1, &readfds, (fd_set *) NULL, (fd_set *) NULL, &tv); + FD_SET(sock, &readfds); + max_fd = sock; + select(max_fd + 1, &readfds, (fd_set *) NULL, (fd_set *) NULL, &tv); - if (FD_ISSET(sock, &readfds)) { - if (eventServerSelect() > 0) { - isNext = TRUE; - } - } + if (FD_ISSET(sock, &readfds)) { + if (eventServerSelect() > 0) { + isNext = TRUE; + } + } - } while (isNext == TRUE); + } while (isNext == TRUE); } #ifdef SUPPORT_TRAFFIC -static void -eventTraffic() +static void eventTraffic() { - my_time_t currentTime; - - currentTime = getMyTime(); - - if (currentTime - lastTraffic > 5000) { - lastTraffic = currentTime; -#ifdef DEBUG - printf(_("down: %d\n") - _("up : %d\n"), traffic_down, traffic_up); -#endif - traffic_down = 0; - traffic_up = 0; - } + my_time_t currentTime; + + currentTime = getMyTime(); + + if (currentTime - lastTraffic > 5000) { + lastTraffic = currentTime; +# ifdef DEBUG + printf(_("down: %d\n") + _("up : %d\n"), traffic_down, traffic_up); +# endif + traffic_down = 0; + traffic_up = 0; + } } #endif -void -eventClient() +void eventClient() { #ifdef SUPPORT_TRAFFIC - eventTraffic(); + eventTraffic(); #endif - eventPingServer(); - selectClientSocket(); - eventClientWorkRecvList(); + eventPingServer(); + selectClientSocket(); + eventClientWorkRecvList(); } -static void -quitUdpClient() +static void quitUdpClient() { - assert(sock_server_udp != NULL); - closeUdpSocket(sock_server_udp); + assert(sock_server_udp != NULL); + closeUdpSocket(sock_server_udp); #ifdef DEBUG - printf(_("Closing UDP connection.\n")); + printf(_("Closing UDP connection.\n")); #endif } -void -quitClient() +void quitClient() { - proto_send_end_client(); + proto_send_end_client(); - assert(listRecvMsg != NULL); + assert(listRecvMsg != NULL); - destroyListItem(listRecvMsg, free); - destroyBuffer(clientRecvBuffer); - destroyBuffer(clientSendBuffer); + destroyListItem(listRecvMsg, free); + destroyBuffer(clientRecvBuffer); + destroyBuffer(clientSendBuffer); - if (sock_server_udp != NULL) { - quitUdpClient(); - } + if (sock_server_udp != NULL) { + quitUdpClient(); + } } diff --git a/src/client/client.h b/src/client/client.h index bfde073..6795c92 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -1,15 +1,15 @@ #ifndef MY_CLIENT -#define MY_CLIENT +# define MY_CLIENT -#include "main.h" +# include "main.h" -#define CLIENT_TIMEOUT 1000 -#define SERVER_TIMEOUT_ALIVE 5000 +# define CLIENT_TIMEOUT 1000 +# define SERVER_TIMEOUT_ALIVE 5000 -#define CLIENT_BUFFER_LIMIT 4096 +# define CLIENT_BUFFER_LIMIT 4096 extern int initClient(char *ip, int port, int proto); extern void sendServer(char *msg); diff --git a/src/client/configFile.c b/src/client/configFile.c index 4df4d6e..71f4237 100644 --- a/src/client/configFile.c +++ b/src/client/configFile.c @@ -7,142 +7,136 @@ #include "main.h" #include "configFile.h" -int -isYesOrNO(char *s) +int isYesOrNO(char *s) { - if (s[0] == 'Y' || s[0] == 'y') - return 1; - return 0; + if (s[0] == 'Y' || s[0] == 'y') + return 1; + return 0; } -char * -getYesOrNo(int n) +char *getYesOrNo(int n) { - return (n != 0 ? "YES" : "NO"); + return (n != 0 ? "YES" : "NO"); } -int -getValue(char *line, char *env, char *val, int len) +int getValue(char *line, char *env, char *val, int len) { - char *offset_env; - char *offset_val_begin; - char *offset_val_end; - char clone_env[STR_SIZE]; - int val_len; + char *offset_env; + char *offset_val_begin; + char *offset_val_end; + char clone_env[STR_SIZE]; + int val_len; - strcpy(clone_env, env); + strcpy(clone_env, env); - offset_env = strstr(line, clone_env); - if (offset_env == NULL) - return -1; + offset_env = strstr(line, clone_env); + if (offset_env == NULL) + return -1; - offset_val_begin = strchr(offset_env, '"'); - if (offset_val_begin == NULL) - return -1; + offset_val_begin = strchr(offset_env, '"'); + if (offset_val_begin == NULL) + return -1; - offset_val_end = strchr(offset_val_begin + 1, '"'); - if (offset_val_end == NULL) - return -1; + offset_val_end = strchr(offset_val_begin + 1, '"'); + if (offset_val_end == NULL) + return -1; - val_len = (int) (offset_val_end - (offset_val_begin + 1)); - if (val_len > len - 1) - val_len = len - 1; + val_len = (int) (offset_val_end - (offset_val_begin + 1)); + if (val_len > len - 1) + val_len = len - 1; - memset(val, 0, len); - memcpy(val, offset_val_begin + 1, val_len); + memset(val, 0, len); + memcpy(val, offset_val_begin + 1, val_len); - return 0; + return 0; } -char * -setValue(char *line, char *env, char *val) +char *setValue(char *line, char *env, char *val) { - char *offset_env; - char *offset_val_begin; - char *offset_val_end; - char clone_env[STR_SIZE]; - char clone[STR_SIZE]; + char *offset_env; + char *offset_val_begin; + char *offset_val_end; + char clone_env[STR_SIZE]; + char clone[STR_SIZE]; - //strcpy(clone_env, " "); - strcpy(clone_env, env); + //strcpy(clone_env, " "); + strcpy(clone_env, env); - offset_env = strstr(line, clone_env); - if (offset_env == NULL) - return NULL; + offset_env = strstr(line, clone_env); + if (offset_env == NULL) + return NULL; - offset_val_begin = strchr(offset_env, '"'); - if (offset_val_begin == NULL) - return NULL; + offset_val_begin = strchr(offset_env, '"'); + if (offset_val_begin == NULL) + return NULL; - offset_val_end = strchr(offset_val_begin + 1, '"'); - if (offset_val_end == NULL) - return NULL; + offset_val_end = strchr(offset_val_begin + 1, '"'); + if (offset_val_end == NULL) + return NULL; - memset(clone, 0, STR_SIZE); - strncpy(clone, line, (int) ((offset_val_begin - line) + 1)); - strcat(clone, val); - strcat(clone, offset_val_end); + memset(clone, 0, STR_SIZE); + strncpy(clone, line, (int) ((offset_val_begin - line) + 1)); + strcat(clone, val); + strcat(clone, offset_val_end); - return strdup(clone); + return strdup(clone); } -int -getValueInConfigFile(textFile_t * textFile, char *env, char *val, int len) +int getValueInConfigFile(textFile_t * textFile, char *env, char *val, int len) { - int i; - char *line; + int i; + char *line; - for (i = 0; i < textFile->text->count; i++) { - line = (char *) (textFile->text->list[i]); + for (i = 0; i < textFile->text->count; i++) { + line = (char *) (textFile->text->list[i]); - //printf("env = %s line = %s\n", env, line); + //printf("env = %s line = %s\n", env, line); - if (strncmp(line, env, strlen(env)) == 0) { - return getValue(line, env, val, len); - } - } + if (strncmp(line, env, strlen(env)) == 0) { + return getValue(line, env, val, len); + } + } - return -1; + return -1; } -int -setValueInConfigFile(textFile_t * textFile, char *env, char *val) +int setValueInConfigFile(textFile_t * textFile, char *env, char *val) { - int i; - char *line; - char *ret; + int i; + char *line; + char *ret; - for (i = 0; i < textFile->text->count; i++) { - line = (char *) (textFile->text->list[i]); + for (i = 0; i < textFile->text->count; i++) { + line = (char *) (textFile->text->list[i]); - if (strncmp(line, env, strlen(env)) == 0) { - ret = setValue(line, env, val); + if (strncmp(line, env, strlen(env)) == 0) { + ret = setValue(line, env, val); - if (ret != NULL) { - delListItem(textFile->text, i, free); - insList(textFile->text, i, ret); + if (ret != NULL) { + delListItem(textFile->text, i, free); + insList(textFile->text, i, ret); - return 0; - } - } - } + return 0; + } + } + } - return -1; + return -1; } void loadValueFromConfigFile(textFile_t * textFile, char *env, char *val, int len, - char *butVal) + char *butVal) { - strcpy(val, butVal); + strcpy(val, butVal); - if (getValueInConfigFile(textFile, env, val, len) != 0) { - char line[STR_SIZE]; + if (getValueInConfigFile(textFile, env, val, len) != 0) { + char line[STR_SIZE]; - sprintf(line, "%s=\"%s\"", env, butVal); - addList(textFile->text, strdup(line)); + sprintf(line, "%s=\"%s\"", env, butVal); + addList(textFile->text, strdup(line)); #ifdef DEBUG - printf(_("ADDING: \"%s\" into config file.\n"), line); + printf(_("ADDING: \"%s\" into config file.\n"), line); #endif - } + } } diff --git a/src/client/configFile.h b/src/client/configFile.h index f7f16fc..67dad48 100644 --- a/src/client/configFile.h +++ b/src/client/configFile.h @@ -1,10 +1,10 @@ #ifndef CONFIGFILE_H -#define CONFIGFILE_H +# define CONFIGFILE_H -#include "main.h" -#include "textFile.h" +# include "main.h" +# include "textFile.h" extern int isYesOrNO(char *s); extern char *getYesOrNo(int n); @@ -13,10 +13,10 @@ extern int getValue(char *line, char *env, char *val, int len); extern char *setValue(char *line, char *env, char *val); extern int getValueInConfigFile(textFile_t * textFile, char *env, char *val, - int len); + int len); extern int setValueInConfigFile(textFile_t * textFile, char *env, char *val); extern void loadValueFromConfigFile(textFile_t * textFile, char *env, - char *val, int len, char *butVal); + char *val, int len, char *butVal); #endif diff --git a/src/client/font.c b/src/client/font.c index faf46ea..282b3d9 100644 --- a/src/client/font.c +++ b/src/client/font.c @@ -7,136 +7,129 @@ static int fontSize; static bool_t isFontInit = FALSE; -bool_t -isFontInicialized() +bool_t isFontInicialized() { - return isFontInit; + return isFontInit; } -void -initFont(char *file, int size) +void initFont(char *file, int size) { - char str[STR_PATH_SIZE]; + char str[STR_PATH_SIZE]; - assert(file != NULL); - assert(size > 0); + assert(file != NULL); + assert(size > 0); - assert(isInterfaceInicialized() == TRUE); + assert(isInterfaceInicialized() == TRUE); - sprintf(str, "%s", file); + sprintf(str, "%s", file); - if (TTF_Init() == -1) { - fprintf(stderr, "%s\n", SDL_GetError()); - return; - } + if (TTF_Init() == -1) { + fprintf(stderr, "%s\n", SDL_GetError()); + return; + } - accessExistFile(str); + accessExistFile(str); - g_font = TTF_OpenFont(str, size); - TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL); + g_font = TTF_OpenFont(str, size); + TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL); - fontSize = size; + fontSize = size; #ifdef DEBUG - printf(_("Loading font: \"%s\"\n"), file); + printf(_("Loading font: \"%s\"\n"), file); #endif - isFontInit = TRUE; + isFontInit = TRUE; } /* * Zobrazi text *s na suradnicu x y s farbou RGB */ -void -drawFont(char *s, int x, int y, int r, int g, int b) +void drawFont(char *s, int x, int y, int r, int g, int b) { - SDL_Rect dst_rect; - SDL_Surface *text; - SDL_Surface *p; - SDL_Color farba_pisma = { r, g, b, 0 }; + SDL_Rect dst_rect; + SDL_Surface *text; + SDL_Surface *p; + SDL_Color farba_pisma = { r, g, b, 0 }; - //printf("drawFont %s\n", s); + //printf("drawFont %s\n", s); - assert(s != NULL); + assert(s != NULL); - p = getSDL_Screen(); + p = getSDL_Screen(); - text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma); + text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma); - dst_rect.x = x; - dst_rect.y = y; + dst_rect.x = x; + dst_rect.y = y; - SDL_BlitSurface(text, NULL, p, &dst_rect); - SDL_FreeSurface(text); + SDL_BlitSurface(text, NULL, p, &dst_rect); + SDL_FreeSurface(text); } -void -drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g, int b) +void drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g, int b) { - SDL_Rect src_rect, dst_rect; - SDL_Surface *text; - SDL_Surface *p; - SDL_Color farba_pisma = { r, g, b, 0 }; - int my_w, my_h; + SDL_Rect src_rect, dst_rect; + SDL_Surface *text; + SDL_Surface *p; + SDL_Color farba_pisma = { r, g, b, 0 }; + int my_w, my_h; - assert(s != NULL); + assert(s != NULL); - p = getSDL_Screen(); + p = getSDL_Screen(); - text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma); + text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma); - my_w = text->w; + my_w = text->w; - if (my_w > w) { - my_w = w; - } + if (my_w > w) { + my_w = w; + } - my_h = text->h; + my_h = text->h; - if (my_w > w) { - my_h = h; - } + if (my_w > w) { + my_h = h; + } - src_rect.x = 0; - src_rect.y = 0; - src_rect.w = my_w; - src_rect.h = my_h; + src_rect.x = 0; + src_rect.y = 0; + src_rect.w = my_w; + src_rect.h = my_h; - dst_rect.x = x; - dst_rect.y = y; + dst_rect.x = x; + dst_rect.y = y; - SDL_BlitSurface(text, &src_rect, p, &dst_rect); - SDL_FreeSurface(text); + SDL_BlitSurface(text, &src_rect, p, &dst_rect); + SDL_FreeSurface(text); } /* * Vrati velkost daneho fontu. */ -int -getFontSize() +int getFontSize() { - return fontSize; + return fontSize; } -void -getTextSize(char *s, int *w, int *h) +void getTextSize(char *s, int *w, int *h) { - assert(s != NULL); - assert(w != NULL); - assert(h != NULL); + assert(s != NULL); + assert(w != NULL); + assert(h != NULL); - TTF_SizeUTF8(g_font, s, w, h); + TTF_SizeUTF8(g_font, s, w, h); } /* * Uvolni font z pamete. */ -void -quitFont() +void quitFont() { - TTF_CloseFont(g_font); - TTF_Quit(); + TTF_CloseFont(g_font); + TTF_Quit(); #ifdef DEBUG - printf(_("Unloading font\n")); + printf(_("Unloading font\n")); #endif - isFontInit = FALSE; + isFontInit = FALSE; } diff --git a/src/client/font.h b/src/client/font.h index 28f7373..f728e86 100644 --- a/src/client/font.h +++ b/src/client/font.h @@ -1,27 +1,27 @@ #ifndef FONT_H -#define FONT_H +# define FONT_H -#include <SDL_ttf.h> -#include <assert.h> -#include "main.h" +# include <SDL_ttf.h> +# include <assert.h> +# include "main.h" -#define COLOR_WHITE 255, 255, 255 -#define COLOR_BLACK 0, 0, 0 +# define COLOR_WHITE 255, 255, 255 +# define COLOR_BLACK 0, 0, 0 -#define COLOR_RED 255, 0, 0 -#define COLOR_GREEN 0, 255, 0 -#define COLOR_BLUE 0, 0, 255 +# define COLOR_RED 255, 0, 0 +# define COLOR_GREEN 0, 255, 0 +# define COLOR_BLUE 0, 0, 255 -#define COLOR_YELLOW 255, 255, 0 -#define FONT_SIZE 16 +# define COLOR_YELLOW 255, 255, 0 +# define FONT_SIZE 16 extern bool_t isFontInicialized(); extern void initFont(char *file, int size); extern void drawFont(char *s, int x, int y, int r, int g, int b); extern void drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g, - int b); + int b); extern int getFontSize(); extern void getTextSize(char *s, int *w, int *h); extern void quitFont(); diff --git a/src/client/game.c b/src/client/game.c index 2f90216..d0773a4 100644 --- a/src/client/game.c +++ b/src/client/game.c @@ -25,9 +25,9 @@ #include "radar.h" #ifndef NO_SOUND -#include "audio.h" -#include "sound.h" -#include "music.h" +# include "audio.h" +# include "sound.h" +# include "music.h" #endif #include "screen_world.h" @@ -42,84 +42,81 @@ #include "screen_credits.h" #include "screen_browser.h" -static void -initGame() +static void initGame() { - createHomeDirector(); + createHomeDirector(); - initSDL(); - initFont(FONT_FILE, FONT_SIZE); - initLayer(); - initImageData(); + initSDL(); + initFont(FONT_FILE, FONT_SIZE); + initLayer(); + initImageData(); #ifndef NO_SOUND - initAudio(); - initSound(); - initMusic(); + initAudio(); + initSound(); + initMusic(); #endif - initScreen(); - initArenaFile(); - initTux(); - initItem(); - initShot(); - initPanel(); - initWorld(); + initScreen(); + initArenaFile(); + initTux(); + initItem(); + initShot(); + initPanel(); + initWorld(); - initScreenMainMenu(); - initScreenAnalyze(); - initScreenChoiceArena(); - initScreenSetting(); - initScreenSettingKeys(); - initScreenGameType(); - initScreenDownArena(); - initScreenCredits(); - initScreenTable(); - initScreenBrowser(); + initScreenMainMenu(); + initScreenAnalyze(); + initScreenChoiceArena(); + initScreenSetting(); + initScreenSettingKeys(); + initScreenGameType(); + initScreenDownArena(); + initScreenCredits(); + initScreenTable(); + initScreenBrowser(); } -void -quitGame() +void quitGame() { - quitSDL(); + quitSDL(); - quitScreenMainMenu(); - quitScreenAnalyze(); - quitScreenSetting(); - quitScreenSettingKeys(); - quitScreenGameType(); - quitScreenDownArena(); - quitScreenChoiceArena(); - quitScreenCredits(); - quitScreenTable(); - quitScreenBrowser(); + quitScreenMainMenu(); + quitScreenAnalyze(); + quitScreenSetting(); + quitScreenSettingKeys(); + quitScreenGameType(); + quitScreenDownArena(); + quitScreenChoiceArena(); + quitScreenCredits(); + quitScreenTable(); + quitScreenBrowser(); - quitLayer(); - quitFont(); - quitScreen(); - quitArenaFile(); - quitItem(); - quitTux(); - quitShot(); - quitPanel(); - quitWorld(); - quitImageData(); + quitLayer(); + quitFont(); + quitScreen(); + quitArenaFile(); + quitItem(); + quitTux(); + quitShot(); + quitPanel(); + quitWorld(); + quitImageData(); #ifndef NO_SOUND - quitSound(); - quitMusic(); - quitAudio(); + quitSound(); + quitMusic(); + quitAudio(); #endif #ifdef DEBUG - printf(_("Quitting TUXANCI...\n")); + printf(_("Quitting TUXANCI...\n")); #endif - exit(0); + exit(0); } -void -startGame() +void startGame() { - initGame(); + initGame(); - startScreen("mainMenu"); + startScreen("mainMenu"); - eventSDL(); - quitGame(); + eventSDL(); + quitGame(); } diff --git a/src/client/game.h b/src/client/game.h index 6ce694d..981e975 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -1,7 +1,7 @@ #ifndef GAME_H -#define GAME_H +# define GAME_H extern void quitGame(); extern void startGame(); diff --git a/src/client/hotKey.c b/src/client/hotKey.c index ebbfdef..2462140 100644 --- a/src/client/hotKey.c +++ b/src/client/hotKey.c @@ -10,150 +10,139 @@ #include "interface.h" #include "hotKey.h" -typedef struct hotKey_struct -{ - SDLKey key; - bool_t active; - void (*handler) (); +typedef struct hotKey_struct { + SDLKey key; + bool_t active; + void (*handler) (); } hotKey_t; static list_t *listHotKey; static my_time_t lastActive; -static hotKey_t * -newHotKey(SDLKey key, void (*handler) ()) +static hotKey_t *newHotKey(SDLKey key, void (*handler) ()) { - hotKey_t *new; + hotKey_t *new; - new = malloc(sizeof(hotKey_t)); - new->key = key; - new->active = TRUE; - new->handler = handler; + new = malloc(sizeof(hotKey_t)); + new->key = key; + new->active = TRUE; + new->handler = handler; - return new; + return new; } -static void -destroyHotKey(hotKey_t * hotkey) +static void destroyHotKey(hotKey_t * hotkey) { - free(hotkey); + free(hotkey); } -static hotKey_t * -findHotkey(SDLKey key) +static hotKey_t *findHotkey(SDLKey key) { - int i; + int i; - for (i = 0; i < listHotKey->count; i++) { - hotKey_t *this; + for (i = 0; i < listHotKey->count; i++) { + hotKey_t *this; - this = (hotKey_t *) listHotKey->list[i]; + this = (hotKey_t *) listHotKey->list[i]; - if (this->key == key) { - return this; - } - } + if (this->key == key) { + return this; + } + } - return NULL; + return NULL; } -void -initHotKey() +void initHotKey() { - listHotKey = newList(); - lastActive = getMyTime(); + listHotKey = newList(); + lastActive = getMyTime(); } -void -registerHotKey(SDLKey key, void (*handler) ()) +void registerHotKey(SDLKey key, void (*handler) ()) { - hotKey_t *hotkey; + hotKey_t *hotkey; - if (findHotkey(key) != NULL) { - assert(!"Conflict with register key"); - } + if (findHotkey(key) != NULL) { + assert(!"Conflict with register key"); + } - hotkey = newHotKey(key, handler); - addList(listHotKey, hotkey); + hotkey = newHotKey(key, handler); + addList(listHotKey, hotkey); } -void -unregisterHotKey(SDLKey key) +void unregisterHotKey(SDLKey key) { - hotKey_t *hotkey; - int index; + hotKey_t *hotkey; + int index; - hotkey = findHotkey(key); + hotkey = findHotkey(key); - if (hotkey == NULL) { - assert(!"This hotkey not register"); - } + if (hotkey == NULL) { + assert(!"This hotkey not register"); + } - index = searchListItem(listHotKey, hotkey); - assert(index != -1); - delListItem(listHotKey, index, destroyHotKey); + index = searchListItem(listHotKey, hotkey); + assert(index != -1); + delListItem(listHotKey, index, destroyHotKey); } -void -enableHotKey(SDLKey key) +void enableHotKey(SDLKey key) { - hotKey_t *hotkey; + hotKey_t *hotkey; - hotkey = findHotkey(key); + hotkey = findHotkey(key); - if (hotkey == NULL) { - assert(!"This hotkey not register"); - } + if (hotkey == NULL) { + assert(!"This hotkey not register"); + } - lastActive = getMyTime(); - hotkey->active = TRUE; + lastActive = getMyTime(); + hotkey->active = TRUE; } -void -disableHotKey(SDLKey key) +void disableHotKey(SDLKey key) { - hotKey_t *hotkey; + hotKey_t *hotkey; - hotkey = findHotkey(key); + hotkey = findHotkey(key); - if (hotkey == NULL) { - assert(!"This hotkey not register"); - } + if (hotkey == NULL) { + assert(!"This hotkey not register"); + } - lastActive = getMyTime(); - hotkey->active = FALSE; + lastActive = getMyTime(); + hotkey->active = FALSE; } -void -eventHotKey() +void eventHotKey() { - my_time_t currentTime; - Uint8 *mapa; - int i; + my_time_t currentTime; + Uint8 *mapa; + int i; - currentTime = getMyTime(); + currentTime = getMyTime(); - if (currentTime - lastActive < HOTKEY_ACTIVE_INTERVAL) { - return; - } + if (currentTime - lastActive < HOTKEY_ACTIVE_INTERVAL) { + return; + } - mapa = SDL_GetKeyState(NULL); + mapa = SDL_GetKeyState(NULL); - for (i = 0; i < listHotKey->count; i++) { - hotKey_t *this; + for (i = 0; i < listHotKey->count; i++) { + hotKey_t *this; - this = (hotKey_t *) listHotKey->list[i]; + this = (hotKey_t *) listHotKey->list[i]; - if (mapa[this->key] == SDL_PRESSED && this->active == TRUE) { - lastActive = getMyTime(); - //printf("hotKey = %d\n", this->key); - this->handler(); - } - } + if (mapa[this->key] == SDL_PRESSED && this->active == TRUE) { + lastActive = getMyTime(); + //printf("hotKey = %d\n", this->key); + this->handler(); + } + } } -void -quitHotKey() +void quitHotKey() { - destroyListItem(listHotKey, destroyHotKey); + destroyListItem(listHotKey, destroyHotKey); } diff --git a/src/client/hotKey.h b/src/client/hotKey.h index 383033d..1cdf647 100644 --- a/src/client/hotKey.h +++ b/src/client/hotKey.h @@ -1,9 +1,9 @@ #ifndef HOTKEY_H -#define HOTKEY_H +# define HOTKEY_H -#define HOTKEY_ACTIVE_INTERVAL 500 +# define HOTKEY_ACTIVE_INTERVAL 500 extern void initHotKey(); extern void registerHotKey(SDLKey key, void (*handler) ()); diff --git a/src/client/image.c b/src/client/image.c index 3ed4403..6046732 100644 --- a/src/client/image.c +++ b/src/client/image.c @@ -14,82 +14,76 @@ static list_t *listStorage; static bool_t isImageDataInit = FALSE; -bool_t -isImageInicialized() +bool_t isImageInicialized() { - return isImageDataInit; + return isImageDataInit; } /* * Inicializuje globalny zoznam obrazkov */ -void -initImageData() +void initImageData() { - assert(isInterfaceInicialized() == TRUE); + assert(isInterfaceInicialized() == TRUE); #ifdef DEBUG - printf(_("Initializing image database\n")); + printf(_("Initializing image database\n")); #endif - listStorage = newStorage(); - isImageDataInit = TRUE; + listStorage = newStorage(); + isImageDataInit = TRUE; } -static SDL_Surface * -loadImage(const char *filename, int alpha) +static SDL_Surface *loadImage(const char *filename, int alpha) { - SDL_Surface *tmp; - SDL_Surface *ret; + SDL_Surface *tmp; + SDL_Surface *ret; - char str[STR_PATH_SIZE]; + char str[STR_PATH_SIZE]; - if (isFillPath(filename)) { - strcpy(str, filename); - } - else { - sprintf(str, PATH_IMAGE "%s", filename); - } + if (isFillPath(filename)) { + strcpy(str, filename); + } else { + sprintf(str, PATH_IMAGE "%s", filename); + } - accessExistFile(str); + accessExistFile(str); - if ((tmp = IMG_Load(str)) == NULL) { - fprintf(stderr, "%s\n", SDL_GetError()); - return NULL; - } + if ((tmp = IMG_Load(str)) == NULL) { + fprintf(stderr, "%s\n", SDL_GetError()); + return NULL; + } - if ((ret = - (alpha) ? SDL_DisplayFormatAlpha(tmp) : SDL_DisplayFormat(tmp)) == - NULL) { - fprintf(stderr, "%s\n", SDL_GetError()); - SDL_FreeSurface(tmp); - return NULL; - } + if ((ret = + (alpha) ? SDL_DisplayFormatAlpha(tmp) : SDL_DisplayFormat(tmp)) == + NULL) { + fprintf(stderr, "%s\n", SDL_GetError()); + SDL_FreeSurface(tmp); + return NULL; + } - SDL_FreeSurface(tmp); - return ret; + SDL_FreeSurface(tmp); + return ret; } -image_t * -newImage(SDL_Surface * surface) +image_t *newImage(SDL_Surface * surface) { - image_t *new; + image_t *new; - assert(surface != NULL); + assert(surface != NULL); - new = malloc(sizeof(image_t)); - new->image = surface; - new->w = surface->w; - new->h = surface->h; + new = malloc(sizeof(image_t)); + new->image = surface; + new->w = surface->w; + new->h = surface->h; - return new; + return new; } -static void -destroyImage(image_t * p) +static void destroyImage(image_t * p) { - assert(p != NULL); - SDL_FreeSurface((SDL_Surface *) p->image); - free(p); + assert(p != NULL); + SDL_FreeSurface((SDL_Surface *) p->image); + free(p); } /* @@ -98,86 +92,80 @@ destroyImage(image_t * p) * *name - nazov obrazku ( pouzije sa ako vyhadavaci retazec v zazanem ) * alpha - 0 - nema alpha kanal | 1 - ma alpha kanal */ -image_t * -addImageData(char *file, int alpha, char *name, char *group) +image_t *addImageData(char *file, int alpha, char *name, char *group) { - SDL_Surface *surface; - image_t *new; + SDL_Surface *surface; + image_t *new; - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); + assert(file != NULL); + assert(name != NULL); + assert(group != NULL); - surface = loadImage(file, alpha); - new = newImage(surface); + surface = loadImage(file, alpha); + new = newImage(surface); - addItemToStorage(listStorage, group, name, new); + addItemToStorage(listStorage, group, name, new); #ifdef DEBUG - printf(_("Loading image %s\n"), file); + printf(_("Loading image %s\n"), file); #endif - return new; + return new; } /* * Vrati odkaz na image_data v globalnom zozname obrazkov * a nazvom *s */ -image_t * -getImage(char *group, char *name) +image_t *getImage(char *group, char *name) { - assert(group != NULL); - assert(name != NULL); + assert(group != NULL); + assert(name != NULL); - return getItemFromStorage(listStorage, group, name); + return getItemFromStorage(listStorage, group, name); } -void -delImage(char *group, char *name) +void delImage(char *group, char *name) { - assert(group != NULL); - assert(name != NULL); + assert(group != NULL); + assert(name != NULL); - delItemFromStorage(listStorage, group, name, destroyImage); + delItemFromStorage(listStorage, group, name, destroyImage); } -void -delAllImageInGroup(char *group) +void delAllImageInGroup(char *group) { - assert(group != NULL); + assert(group != NULL); - delAllItemFromStorage(listStorage, group, destroyImage); + delAllItemFromStorage(listStorage, group, destroyImage); } -void -drawImage(image_t * p, int x, int y, int px, int py, int w, int h) +void drawImage(image_t * p, int x, int y, int px, int py, int w, int h) { - static SDL_Surface *screen = NULL; - SDL_Rect dst_rect, src_rect; + static SDL_Surface *screen = NULL; + SDL_Rect dst_rect, src_rect; - if (screen == NULL) { - screen = getSDL_Screen(); - } + if (screen == NULL) { + screen = getSDL_Screen(); + } - dst_rect.x = x; - dst_rect.y = y; + dst_rect.x = x; + dst_rect.y = y; - src_rect.x = px; - src_rect.y = py; - src_rect.w = w; - src_rect.h = h; + src_rect.x = px; + src_rect.y = py; + src_rect.w = w; + src_rect.h = h; - SDL_BlitSurface(p->image, &src_rect, screen, &dst_rect); + SDL_BlitSurface(p->image, &src_rect, screen, &dst_rect); } /* * Odstrani zoznam obrazkov z pamate */ -void -quitImageData() +void quitImageData() { #ifdef DEBUG - printf(_("Quitting image database\n")); + printf(_("Quitting image database\n")); #endif - destroyStorage(listStorage, destroyImage); - isImageDataInit = FALSE; + destroyStorage(listStorage, destroyImage); + isImageDataInit = FALSE; } diff --git a/src/client/image.h b/src/client/image.h index 5b637b2..015c0d2 100644 --- a/src/client/image.h +++ b/src/client/image.h @@ -1,18 +1,18 @@ #ifndef IMAGE_H -#define IMAGE_H +# define IMAGE_H //#include "image.h" -#include "interface.h" +# include "interface.h" -#define IMAGE_NO_ALPHA 0 -#define IMAGE_ALPHA 1 +# define IMAGE_NO_ALPHA 0 +# define IMAGE_ALPHA 1 -#define IMAGE_GROUP_BASE "base" -#define IMAGE_GROUP_EXTENDSIO "extension" -#define IMAGE_GROUP_USER "user" -#define IMAGE_GROUP_OTHER "other" +# define IMAGE_GROUP_BASE "base" +# define IMAGE_GROUP_EXTENDSIO "extension" +# define IMAGE_GROUP_USER "user" +# define IMAGE_GROUP_OTHER "other" /* typedef struct image_struct @@ -23,11 +23,10 @@ typedef struct image_struct } image_data_t; */ -typedef struct image_struct -{ - int w; - int h; - SDL_Surface *image; +typedef struct image_struct { + int w; + int h; + SDL_Surface *image; } image_t; extern bool_t isImageInicialized(); @@ -36,8 +35,7 @@ extern image_t *addImageData(char *file, int alpha, char *name, char *group); extern image_t *getImage(char *group, char *name); extern void delImage(char *group, char *name); extern void delAllImageInGroup(char *group); -extern void drawImage(image_t * p, int x, int y, int px, int py, int w, - int h); +extern void drawImage(image_t * p, int x, int y, int px, int py, int w, int h); extern void quitImageData(); #endif diff --git a/src/client/interface.c b/src/client/interface.c index 94a9fdb..d2f99fb 100644 --- a/src/client/interface.c +++ b/src/client/interface.c @@ -24,78 +24,71 @@ static bool_t isInterfaceInit = FALSE; // flag, kterym se ridi zarazovani klaves do bufferu bool_t keyboardBufferEnabled = FALSE; -bool_t -isInterfaceInicialized() +bool_t isInterfaceInicialized() { - return isInterfaceInit; + return isInterfaceInit; } -static Uint32 -TimerCallback(Uint32 interval, void *param) +static Uint32 TimerCallback(Uint32 interval, void *param) { - SDL_Event event; - event.type = SDL_USEREVENT; - event.user.code = USR_EVT_TIMER; - event.user.data1 = NULL; - event.user.data2 = NULL; + SDL_Event event; + event.type = SDL_USEREVENT; + event.user.code = USR_EVT_TIMER; + event.user.data1 = NULL; + event.user.data2 = NULL; - SDL_PushEvent(&event); + SDL_PushEvent(&event); - return interval; + return interval; } -void -enableKeyboardBuffer() +void enableKeyboardBuffer() { - keyboardBufferEnabled = TRUE; + keyboardBufferEnabled = TRUE; } -void -disableKeyboardBuffer() +void disableKeyboardBuffer() { - keyboardBufferEnabled = FALSE; + keyboardBufferEnabled = FALSE; } -void -hotkey_screen() +void hotkey_screen() { - if (g_win_flags & SDL_FULLSCREEN) - g_win_flags &= ~SDL_FULLSCREEN; - else - g_win_flags |= SDL_FULLSCREEN; - - if (SDL_WM_ToggleFullScreen(screen) == 0) { - fprintf(stderr, _("Unable to switch to FULLSCREEN mode!\n")); - - SDL_FreeSurface(screen); - screen = - SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, - g_win_flags); - - if (screen == NULL) { - fprintf(stderr, _("Unable to switch to WINDOW mode! Error: %s\n"), - SDL_GetError()); - return; - } - } + if (g_win_flags & SDL_FULLSCREEN) + g_win_flags &= ~SDL_FULLSCREEN; + else + g_win_flags |= SDL_FULLSCREEN; + + if (SDL_WM_ToggleFullScreen(screen) == 0) { + fprintf(stderr, _("Unable to switch to FULLSCREEN mode!\n")); + + SDL_FreeSurface(screen); + screen = + SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, + g_win_flags); + + if (screen == NULL) { + fprintf(stderr, _("Unable to switch to WINDOW mode! Error: %s\n"), + SDL_GetError()); + return; + } + } } -int -initSDL() +int initSDL() { #ifdef DEBUG - printf(_("Initializing SDL system\n")); + printf(_("Initializing SDL system\n")); #endif - // initialization of SDL - if (SDL_Init(SDL_SUBSYSTEMS) == -1) { - fprintf(stderr, "%s\n", SDL_GetError()); - SDL_Quit(); - return -1; - } - - // initialization of SDL - //screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags); - screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags); + // initialization of SDL + if (SDL_Init(SDL_SUBSYSTEMS) == -1) { + fprintf(stderr, "%s\n", SDL_GetError()); + SDL_Quit(); + return -1; + } + // initialization of SDL + //screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags); + screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags); /* my_surface = SDL_CreateRGBSurface(screen->flags, WINDOW_SIZE_X, WINDOW_SIZE_Y, @@ -103,88 +96,82 @@ initSDL() screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); */ - //memset(my_surface->pixels, 128, 200); + //memset(my_surface->pixels, 128, 200); - if (screen == NULL) { - fprintf(stderr, "%s\n", SDL_GetError()); - SDL_Quit(); - return -1; - } + if (screen == NULL) { + fprintf(stderr, "%s\n", SDL_GetError()); + SDL_Quit(); + return -1; + } - SDL_WM_SetCaption(WINDOW_TITLE, NULL); - //SDL_ShowCursor(0); - SDL_EnableKeyRepeat(0, 1); - timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL); + SDL_WM_SetCaption(WINDOW_TITLE, NULL); + //SDL_ShowCursor(0); + SDL_EnableKeyRepeat(0, 1); + timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL); - initKeyboardBuffer(KEYBOARD_BUFFER_SIZE); + initKeyboardBuffer(KEYBOARD_BUFFER_SIZE); - initHotKey(); - registerHotKey(SDLK_F1, hotkey_screen); + initHotKey(); + registerHotKey(SDLK_F1, hotkey_screen); - srand((unsigned) time(NULL)); - isInterfaceInit = TRUE; + srand((unsigned) time(NULL)); + isInterfaceInit = TRUE; - return 0; + return 0; } -SDL_Surface * -getSDL_Screen() +SDL_Surface *getSDL_Screen() { - //return my_surface; - return screen; + //return my_surface; + return screen; } -void -interfaceRefresh() +void interfaceRefresh() { - //SDL_BlitSurface(my_surface, NULL, screen, NULL); - //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); + //SDL_BlitSurface(my_surface, NULL, screen, NULL); + //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); - //drawImage(my_surface, 200, 100, 0, 0, 200, 200); - SDL_Flip(screen); - //SDL_UpdateRect(screen, 400, 0, 400, 600); + //drawImage(my_surface, 200, 100, 0, 0, 200, 200); + SDL_Flip(screen); + //SDL_UpdateRect(screen, 400, 0, 400, 600); } -void -getMousePosition(int *x, int *y) +void getMousePosition(int *x, int *y) { - SDL_GetMouseState(x, y); + SDL_GetMouseState(x, y); } -int -isMouseClicked() +int isMouseClicked() { - return SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT); + return SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT); } -int -isPressAnyKey() +int isPressAnyKey() { - Uint8 *mapa; - int i; + Uint8 *mapa; + int i; - mapa = SDL_GetKeyState(NULL); + mapa = SDL_GetKeyState(NULL); - for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++) - if (mapa[i] == SDL_PRESSED) { - return 1; - } + for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++) + if (mapa[i] == SDL_PRESSED) { + return 1; + } - return 0; + return 0; } -void -printPressAnyKey() +void printPressAnyKey() { - Uint8 *mapa; - int i; + Uint8 *mapa; + int i; - mapa = SDL_GetKeyState(NULL); + mapa = SDL_GetKeyState(NULL); - for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++) - if (mapa[i] == SDL_PRESSED) { - printf(_("Pressed key with SDL value: %d\n"), i); - } + for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++) + if (mapa[i] == SDL_PRESSED) { + printf(_("Pressed key with SDL value: %d\n"), i); + } } @@ -205,16 +192,15 @@ static void action_esc() } */ -int -eventAction() +int eventAction() { - SDL_Event event; + SDL_Event event; - while (SDL_WaitEvent(&event)) { - switch (event.type) { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { + while (SDL_WaitEvent(&event)) { + switch (event.type) { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { /* case SDLK_ESCAPE: action_esc(); @@ -226,74 +212,72 @@ eventAction() if(!toggleFullscreen())return 0; break; */ - default: - //neni potreba vyuzivat frontu stale - if (keyboardBufferEnabled == TRUE) - pushKeyToKeyboardBuffer(event.key.keysym); - break; - } - break; - - case SDL_USEREVENT: - switch (event.user.code) { - case USR_EVT_TIMER: - drawScreen(); - eventScreen(); - eventHotKey(); - switchScreen(); - break; - - default: - break; - } - break; - - // change of window size - case SDL_VIDEORESIZE: - screen = - SDL_SetVideoMode(event.resize.w, event.resize.h, WIN_BPP, - g_win_flags); - - if (screen == NULL) { - fprintf(stderr, - _("Unable to change WINDOW resolution! Error: %s\n"), - SDL_GetError()); - return 0; - } - break; - - // termination request - case SDL_QUIT: - return -1; - break; - - default: - break; - } - } - - return 0; + default: + //neni potreba vyuzivat frontu stale + if (keyboardBufferEnabled == TRUE) + pushKeyToKeyboardBuffer(event.key.keysym); + break; + } + break; + + case SDL_USEREVENT: + switch (event.user.code) { + case USR_EVT_TIMER: + drawScreen(); + eventScreen(); + eventHotKey(); + switchScreen(); + break; + + default: + break; + } + break; + + // change of window size + case SDL_VIDEORESIZE: + screen = + SDL_SetVideoMode(event.resize.w, event.resize.h, WIN_BPP, + g_win_flags); + + if (screen == NULL) { + fprintf(stderr, + _("Unable to change WINDOW resolution! Error: %s\n"), + SDL_GetError()); + return 0; + } + break; + + // termination request + case SDL_QUIT: + return -1; + break; + + default: + break; + } + } + + return 0; } -void -eventSDL() +void eventSDL() { - while (1) { - if (eventAction() == -1) - return; - } + while (1) { + if (eventAction() == -1) + return; + } } -void -quitSDL() +void quitSDL() { #ifdef DEBUG - printf(_("Quitting SDL\n")); + printf(_("Quitting SDL\n")); #endif - quitHotKey(); - quitKeyboardBuffer(); + quitHotKey(); + quitKeyboardBuffer(); - SDL_Quit(); + SDL_Quit(); - isInterfaceInit = FALSE; + isInterfaceInit = FALSE; } diff --git a/src/client/interface.h b/src/client/interface.h index 95bef25..b5df62a 100644 --- a/src/client/interface.h +++ b/src/client/interface.h @@ -1,33 +1,33 @@ #ifndef INTERFACE_H -#define INTERFACE_H +# define INTERFACE_H -#include <stdio.h> -#include <string.h> -#include <time.h> +# include <stdio.h> +# include <string.h> +# include <time.h> -#include <SDL.h> -#include <SDL_image.h> -#include <SDL_thread.h> -#include "main.h" +# include <SDL.h> +# include <SDL_image.h> +# include <SDL_thread.h> +# include "main.h" /* #include <SDL_net.h> */ -#define SDL_SUBSYSTEMS SDL_INIT_VIDEO|SDL_INIT_TIMER +# define SDL_SUBSYSTEMS SDL_INIT_VIDEO|SDL_INIT_TIMER // windows title -#define WINDOW_TITLE "Tuxánci " TUXANCI_VERSION -#define WIN_BPP 0 -#define USR_EVT_TIMER 0 +# define WINDOW_TITLE "Tuxánci " TUXANCI_VERSION +# define WIN_BPP 0 +# define USR_EVT_TIMER 0 // interval (in ms) of triggering akcia(); -#define INTERVAL 50 +# define INTERVAL 50 // velikost klavesoveho bufferu (ve znacich) -#define KEYBOARD_BUFFER_SIZE 256 +# define KEYBOARD_BUFFER_SIZE 256 extern bool_t isInterfaceInicialized(); extern void enableKeyboardBuffer(); diff --git a/src/client/keyboardBuffer.c b/src/client/keyboardBuffer.c index c135822..4c24e9b 100644 --- a/src/client/keyboardBuffer.c +++ b/src/client/keyboardBuffer.c @@ -23,138 +23,129 @@ static SDL_keysym emptyKey; /* * Key buffer initializes. The parameter sets the number of keys. */ -void -initKeyboardBuffer(int size) +void initKeyboardBuffer(int size) { - assert(size > 0); - assert(keyboardBuffer == NULL); + assert(size > 0); + assert(keyboardBuffer == NULL); - keyboardBuffer = malloc(sizeof(keyboardBuffer_t)); - assert(keyboardBuffer != NULL); - memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t)); + keyboardBuffer = malloc(sizeof(keyboardBuffer_t)); + assert(keyboardBuffer != NULL); + memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t)); - keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym)); - assert(keyboardBuffer->buff != NULL); - memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym)); + keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym)); + assert(keyboardBuffer->buff != NULL); + memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym)); - keyboardBuffer->begin = 0; - keyboardBuffer->end = 0; - keyboardBuffer->count = 0; - keyboardBuffer->size = size; + keyboardBuffer->begin = 0; + keyboardBuffer->end = 0; + keyboardBuffer->count = 0; + keyboardBuffer->size = size; - emptyKey.sym = SDLK_UNKNOWN; + emptyKey.sym = SDLK_UNKNOWN; } /* * Empty the buffer */ -void -clearKeyboardBuffer() +void clearKeyboardBuffer() { - assert(keyboardBuffer != NULL); + assert(keyboardBuffer != NULL); - keyboardBuffer->begin = 0; - keyboardBuffer->end = 0; - keyboardBuffer->count = 0; - memset(keyboardBuffer->buff, 0, - keyboardBuffer->size * sizeof(SDL_keysym)); + keyboardBuffer->begin = 0; + keyboardBuffer->end = 0; + keyboardBuffer->count = 0; + memset(keyboardBuffer->buff, 0, keyboardBuffer->size * sizeof(SDL_keysym)); } /* * Adds key to the end of the buffer. If the buffer is overrun, * an error is printed to stderr and the key is dropped. */ -bool_t -pushKeyToKeyboardBuffer(SDL_keysym key) +bool_t pushKeyToKeyboardBuffer(SDL_keysym key) { - assert(keyboardBuffer != NULL); + assert(keyboardBuffer != NULL); - if (keyboardBuffer->count >= keyboardBuffer->size) { - fprintf(stderr, _("Keyboard Buffer overrun! Dropping key: %02x\n"), - key.sym); - return FALSE; - } + if (keyboardBuffer->count >= keyboardBuffer->size) { + fprintf(stderr, _("Keyboard Buffer overrun! Dropping key: %02x\n"), + key.sym); + return FALSE; + } - keyboardBuffer->buff[keyboardBuffer->end] = key; + keyboardBuffer->buff[keyboardBuffer->end] = key; - keyboardBuffer->end++; - if (keyboardBuffer->end >= keyboardBuffer->size) { - keyboardBuffer->end = 0; - } + keyboardBuffer->end++; + if (keyboardBuffer->end >= keyboardBuffer->size) { + keyboardBuffer->end = 0; + } - keyboardBuffer->count++; + keyboardBuffer->count++; - return TRUE; + return TRUE; } /* * Takes out first key from the buffer and returns it. If the buffer is empty, * an error is printed to stderr and SDLK_UNKNOWN is returned. */ -SDL_keysym -popKeyFromKeyboardBuffer() +SDL_keysym popKeyFromKeyboardBuffer() { - assert(keyboardBuffer != NULL); + assert(keyboardBuffer != NULL); - if (keyboardBuffer->count <= 0) { - fprintf(stderr, _("Keyboard Buffer underrun!\n")); - return emptyKey; - } + if (keyboardBuffer->count <= 0) { + fprintf(stderr, _("Keyboard Buffer underrun!\n")); + return emptyKey; + } - SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin]; - keyboardBuffer->buff[keyboardBuffer->begin] = emptyKey; + SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin]; + keyboardBuffer->buff[keyboardBuffer->begin] = emptyKey; - keyboardBuffer->begin++; - if (keyboardBuffer->begin >= keyboardBuffer->size) { - keyboardBuffer->begin = 0; - } + keyboardBuffer->begin++; + if (keyboardBuffer->begin >= keyboardBuffer->size) { + keyboardBuffer->begin = 0; + } - keyboardBuffer->count--; + keyboardBuffer->count--; - return key; + return key; } /* * The buffer size */ -int -getKeyboardBufferSize() +int getKeyboardBufferSize() { - assert(keyboardBuffer != NULL); - return keyboardBuffer->size; + assert(keyboardBuffer != NULL); + return keyboardBuffer->size; } /* * Number of keys in the buffer */ -int -KeyboardBufferCount() +int KeyboardBufferCount() { - assert(keyboardBuffer != NULL); - return keyboardBuffer->count; + assert(keyboardBuffer != NULL); + return keyboardBuffer->count; } -bool_t -isAnyKeyInKeyboardBuffer() +bool_t isAnyKeyInKeyboardBuffer() { - return KeyboardBufferCount() > 0 ? TRUE : FALSE; + return KeyboardBufferCount() > 0 ? TRUE : FALSE; } /* * Frees the buffer. If it is not empty, information * about filling is prined to stderr first. */ -void -quitKeyboardBuffer() +void quitKeyboardBuffer() { - assert(keyboardBuffer != NULL); + assert(keyboardBuffer != NULL); - if (keyboardBuffer->count > 0) { - fprintf(stderr, _("Keyboard buffer is not empty!\n")); - } + if (keyboardBuffer->count > 0) { + fprintf(stderr, _("Keyboard buffer is not empty!\n")); + } - free(keyboardBuffer->buff); - free(keyboardBuffer); - keyboardBuffer = NULL; + free(keyboardBuffer->buff); + free(keyboardBuffer); + keyboardBuffer = NULL; } diff --git a/src/client/keyboardBuffer.h b/src/client/keyboardBuffer.h index 81f183b..c3c40af 100644 --- a/src/client/keyboardBuffer.h +++ b/src/client/keyboardBuffer.h @@ -9,18 +9,17 @@ #ifndef KEYBOARD_BUFFER_H -#define KEYBOARD_BUFFER_H +# define KEYBOARD_BUFFER_H -#include <SDL.h> -#include "main.h" +# include <SDL.h> +# include "main.h" -typedef struct -{ - SDL_keysym *buff; /* buffer klaves (kod dle SDLKey enumu) */ - int size; /* aktualni velikost alokovaneho bufferu (v poctu uchovatelnych klaves) */ - int count; /* pocet klaves aktualne v bufferu */ - int begin; /* ukazatel na zacatek bufferu (tj. kam se pridavaji klavesy) */ - int end; /* ukazatel na konec bufferu (tj. odkud se odebiraji klavesy) */ +typedef struct { + SDL_keysym *buff; /* buffer klaves (kod dle SDLKey enumu) */ + int size; /* aktualni velikost alokovaneho bufferu (v poctu uchovatelnych klaves) */ + int count; /* pocet klaves aktualne v bufferu */ + int begin; /* ukazatel na zacatek bufferu (tj. kam se pridavaji klavesy) */ + int end; /* ukazatel na konec bufferu (tj. odkud se odebiraji klavesy) */ } keyboardBuffer_t; extern void initKeyboardBuffer(int size); @@ -32,4 +31,4 @@ extern int KeyboardBufferCount(); extern bool_t isAnyKeyInKeyboardBuffer(); extern void quitKeyboardBuffer(); -#endif /* KEYBOARDBUFFER_H_ */ +#endif /* KEYBOARDBUFFER_H_ */ diff --git a/src/client/layer.c b/src/client/layer.c index 1c8e8d1..d06c92a 100644 --- a/src/client/layer.c +++ b/src/client/layer.c @@ -16,20 +16,18 @@ static list_t *listLayer; static bool_t isLayerInit = FALSE; -bool_t -isLayerInicialized() +bool_t isLayerInicialized() { - return isLayerInit; + return isLayerInit; } /* * Inicializuje globalny zoznam vsrtiev */ -void -initLayer() +void initLayer() { - listLayer = newList(); - isLayerInit = TRUE; + listLayer = newList(); + isLayerInit = TRUE; } /* @@ -40,41 +38,40 @@ initLayer() * layer - vrstva na ktorej sa zobrazi obrazok */ void -addLayer(image_t * img, - int x, int y, int px, int py, int w, int h, int player) +addLayer(image_t * img, int x, int y, int px, int py, int w, int h, int player) { - layer_t *new; - layer_t *this; - int i, j; - - assert(img != NULL); - - new = malloc(sizeof(layer_t)); - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->px = px; - new->py = py; - new->layer = player; - new->image = img; - - for (i = 0; i < listLayer->count; i++) { - this = (layer_t *) listLayer->list[i]; - - if (this->layer == new->layer) { - for (j = i; j < listLayer->count; j++) { - this = (layer_t *) listLayer->list[j]; - - if (this->y + this->h > new->y + new->h) { - insList(listLayer, j, new); - return; - } - } - } - } - - addList(listLayer, new); + layer_t *new; + layer_t *this; + int i, j; + + assert(img != NULL); + + new = malloc(sizeof(layer_t)); + new->x = x; + new->y = y; + new->w = w; + new->h = h; + new->px = px; + new->py = py; + new->layer = player; + new->image = img; + + for (i = 0; i < listLayer->count; i++) { + this = (layer_t *) listLayer->list[i]; + + if (this->layer == new->layer) { + for (j = i; j < listLayer->count; j++) { + this = (layer_t *) listLayer->list[j]; + + if (this->y + this->h > new->y + new->h) { + insList(listLayer, j, new); + return; + } + } + } + } + + addList(listLayer, new); } /* @@ -82,130 +79,123 @@ addLayer(image_t * img, * poukadane podla vrstvy a suradnice Y+H * po dokresleni sa zoznam uvolni. */ -void -drawLayer() +void drawLayer() { - layer_t *this; - int i; + layer_t *this; + int i; - for (i = 0; i < listLayer->count; i++) { - this = (layer_t *) listLayer->list[i]; + for (i = 0; i < listLayer->count; i++) { + this = (layer_t *) listLayer->list[i]; - drawImage(this->image, - this->x, this->y, this->px, this->py, this->w, this->h); - } + drawImage(this->image, + this->x, this->y, this->px, this->py, this->w, this->h); + } - //printf("listLayer->count = %d\n", listLayer->count); + //printf("listLayer->count = %d\n", listLayer->count); - destroyListItem(listLayer, free); - listLayer = newList(); + destroyListItem(listLayer, free); + listLayer = newList(); } -void -drawLayerCenter(int x, int y) +void drawLayerCenter(int x, int y) { - layer_t *this; - int screen_x, screen_y; - int i; - //int count = 0; - - getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + layer_t *this; + int screen_x, screen_y; + int i; + //int count = 0; - for (i = 0; i < listLayer->count; i++) { - this = (layer_t *) listLayer->list[i]; + getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - if (this->x + this->w < screen_x || this->x > screen_x + WINDOW_SIZE_X - || this->y + this->h < screen_y - || this->y > screen_y + WINDOW_SIZE_Y) { - continue; - } + for (i = 0; i < listLayer->count; i++) { + this = (layer_t *) listLayer->list[i]; - //count++; + if (this->x + this->w < screen_x || this->x > screen_x + WINDOW_SIZE_X + || this->y + this->h < screen_y + || this->y > screen_y + WINDOW_SIZE_Y) { + continue; + } + //count++; - drawImage(this->image, - this->x - screen_x, this->y - screen_y, - this->px, this->py, this->w, this->h); + drawImage(this->image, + this->x - screen_x, this->y - screen_y, + this->px, this->py, this->w, this->h); - //printf("%d %d\n", this->x - screen_x, this->y - screen_y); - } + //printf("%d %d\n", this->x - screen_x, this->y - screen_y); + } - //printf("count = %d\n", count); + //printf("count = %d\n", count); - destroyListItem(listLayer, free); - listLayer = newList(); + destroyListItem(listLayer, free); + listLayer = newList(); } -void -drawLayerSplit(int local_x, int local_y, int x, int y, int w, int h) +void drawLayerSplit(int local_x, int local_y, int x, int y, int w, int h) { - layer_t *this; - int i; - //int count = 0; - - for (i = 0; i < listLayer->count; i++) { - this = (layer_t *) listLayer->list[i]; + layer_t *this; + int i; + //int count = 0; - if (this->x + this->w < x || this->x > x + w || - this->y + this->h < y || this->y > y + h) { - continue; - } + for (i = 0; i < listLayer->count; i++) { + this = (layer_t *) listLayer->list[i]; - //count++; + if (this->x + this->w < x || this->x > x + w || + this->y + this->h < y || this->y > y + h) { + continue; + } + //count++; - if (local_x + (this->x - x) < local_x) { - int z; + if (local_x + (this->x - x) < local_x) { + int z; - z = local_x - (local_x + (this->x - x)); + z = local_x - (local_x + (this->x - x)); - this->x += z; - this->px += z; - this->w -= z; - } + this->x += z; + this->px += z; + this->w -= z; + } - if (local_x + (this->x - x) + this->w > local_x + w) { - this->w -= (local_x + (this->x - x) + this->w) - (local_x + w); - } + if (local_x + (this->x - x) + this->w > local_x + w) { + this->w -= (local_x + (this->x - x) + this->w) - (local_x + w); + } - if (local_y + (this->y - y) < local_y) { - int z; + if (local_y + (this->y - y) < local_y) { + int z; - z = local_y - (local_y + (this->y - y)); + z = local_y - (local_y + (this->y - y)); - this->y += z; - this->py += z; - this->h -= z; - } + this->y += z; + this->py += z; + this->h -= z; + } - if (local_y + (this->y - y) + this->h > local_y + h) { - this->h -= (local_y + (this->y - y) + this->h) - (local_y + h); - } + if (local_y + (this->y - y) + this->h > local_y + h) { + this->h -= (local_y + (this->y - y) + this->h) - (local_y + h); + } - drawImage(this->image, - local_x + (this->x - x), local_y + (this->y - y), - this->px, this->py, this->w, this->h); + drawImage(this->image, + local_x + (this->x - x), local_y + (this->y - y), + this->px, this->py, this->w, this->h); - //printf("%d %d\n", this->x - screen_x, this->y - screen_y); - } + //printf("%d %d\n", this->x - screen_x, this->y - screen_y); + } - //printf("count = %d\n", count); + //printf("count = %d\n", count); - destroyListItem(listLayer, free); - listLayer = newList(); + destroyListItem(listLayer, free); + listLayer = newList(); } -void -flushLayer() +void flushLayer() { - destroyListItem(listLayer, free); - listLayer = newList(); + destroyListItem(listLayer, free); + listLayer = newList(); } /* * Odstrani zoznam vrtsiev z pamete. */ -void -quitLayer() +void quitLayer() { - destroyListItem(listLayer, free); - isLayerInit = FALSE; + destroyListItem(listLayer, free); + isLayerInit = FALSE; } diff --git a/src/client/layer.h b/src/client/layer.h index ece1d01..fc17a23 100644 --- a/src/client/layer.h +++ b/src/client/layer.h @@ -1,28 +1,27 @@ #ifndef MY_LAYER_H -#define MY_LAYER_H +# define MY_LAYER_H -#include "main.h" -#include "image.h" +# include "main.h" +# include "image.h" -typedef struct layer_str -{ - int x; //suradnice obrazka na obrazovke - int y; +typedef struct layer_str { + int x; //suradnice obrazka na obrazovke + int y; - int w; //rozmery obrazka na obrazovke - int h; + int w; //rozmery obrazka na obrazovke + int h; - int px; //suradnice casti surfrace - int py; + int px; //suradnice casti surfrace + int py; - int pw; //rozmeri casti surfrace - int ph; + int pw; //rozmeri casti surfrace + int ph; - int layer; + int layer; - image_t *image; //dane surfrace + image_t *image; //dane surfrace } layer_t; extern bool_t isLayerInicialized(); @@ -40,7 +39,7 @@ extern void initLayer(); */ extern void addLayer(image_t * img, - int x, int y, int px, int py, int w, int h, int player); + int x, int y, int px, int py, int w, int h, int player); /* * Vykresli zoznam na obrazovku @@ -48,7 +47,7 @@ extern void addLayer(image_t * img, extern void drawLayer(); extern void drawLayerCenter(int x, int y); extern void drawLayerSplit(int local_x, int local_y, int x, int y, int w, - int h); + int h); extern void flushLayer(); extern void quitLayer(); diff --git a/src/client/panel.c b/src/client/panel.c index 70a7de5..ea87c1a 100644 --- a/src/client/panel.c +++ b/src/client/panel.c @@ -19,196 +19,181 @@ static image_t *g_bonus; static bool_t isPanelInit = FALSE; -bool_t -isPanelInicialized() +bool_t isPanelInicialized() { - return isPanelInit; + return isPanelInit; } -void -initPanel() +void initPanel() { - assert(isImageInicialized() == TRUE); - assert(isInterfaceInicialized() == TRUE); - - g_panel = - addImageData("panel.png", IMAGE_ALPHA, "panel", IMAGE_GROUP_BASE); - g_shot = - addImageData("panel_shot.png", IMAGE_ALPHA, "panel_image_shot", - IMAGE_GROUP_BASE); - g_bonus = - addImageData("graf.bonus.png", IMAGE_ALPHA, "panel_graf_bonus", - IMAGE_GROUP_BASE); - - g_icon[GUN_SIMPLE] = - addImageData("icon.gun.simple.png", IMAGE_ALPHA, "panel_gun", - IMAGE_GROUP_BASE); - g_icon[GUN_DUAL_SIMPLE] = - addImageData("icon.gun.dual.simple.png", IMAGE_ALPHA, "panel_dual", - IMAGE_GROUP_BASE); - g_icon[GUN_TOMMY] = - addImageData("icon.gun.tommy.png", IMAGE_ALPHA, "panel_tommy", - IMAGE_GROUP_BASE); - g_icon[GUN_SCATTER] = - addImageData("icon.gun.scatter.png", IMAGE_ALPHA, "panel_scatter", - IMAGE_GROUP_BASE); - g_icon[GUN_LASSER] = - addImageData("icon.gun.lasser.png", IMAGE_ALPHA, "panel_lasser", - IMAGE_GROUP_BASE); - g_icon[GUN_MINE] = - addImageData("icon.gun.mine.png", IMAGE_ALPHA, "panel_mine", - IMAGE_GROUP_BASE); - g_icon[GUN_BOMBBALL] = - addImageData("icon.gun.bombball.png", IMAGE_ALPHA, "panel_bombball", - IMAGE_GROUP_BASE); - - g_icon[BONUS_SPEED] = - addImageData("icon.bonus.speed.png", IMAGE_ALPHA, "panel_speed", - IMAGE_GROUP_BASE); - g_icon[BONUS_SHOT] = - addImageData("icon.bonus.shot.png", IMAGE_ALPHA, "panel_shot", - IMAGE_GROUP_BASE); - g_icon[BONUS_TELEPORT] = - addImageData("icon.bonus.teleport.png", IMAGE_ALPHA, "panel_teleport", - IMAGE_GROUP_BASE); - g_icon[BONUS_GHOST] = - addImageData("icon.bonus.ghost.png", IMAGE_ALPHA, "panel_ghost", - IMAGE_GROUP_BASE); - g_icon[BONUS_4X] = - addImageData("icon.bonus.4x.png", IMAGE_ALPHA, "panel_4x", - IMAGE_GROUP_BASE); - g_icon[BONUS_HIDDEN] = - addImageData("icon.bonus.hidden.png", IMAGE_ALPHA, "panel_hidden", - IMAGE_GROUP_BASE); - - isPanelInit = TRUE; + assert(isImageInicialized() == TRUE); + assert(isInterfaceInicialized() == TRUE); + + g_panel = + addImageData("panel.png", IMAGE_ALPHA, "panel", IMAGE_GROUP_BASE); + g_shot = + addImageData("panel_shot.png", IMAGE_ALPHA, "panel_image_shot", + IMAGE_GROUP_BASE); + g_bonus = + addImageData("graf.bonus.png", IMAGE_ALPHA, "panel_graf_bonus", + IMAGE_GROUP_BASE); + + g_icon[GUN_SIMPLE] = + addImageData("icon.gun.simple.png", IMAGE_ALPHA, "panel_gun", + IMAGE_GROUP_BASE); + g_icon[GUN_DUAL_SIMPLE] = + addImageData("icon.gun.dual.simple.png", IMAGE_ALPHA, "panel_dual", + IMAGE_GROUP_BASE); + g_icon[GUN_TOMMY] = + addImageData("icon.gun.tommy.png", IMAGE_ALPHA, "panel_tommy", + IMAGE_GROUP_BASE); + g_icon[GUN_SCATTER] = + addImageData("icon.gun.scatter.png", IMAGE_ALPHA, "panel_scatter", + IMAGE_GROUP_BASE); + g_icon[GUN_LASSER] = + addImageData("icon.gun.lasser.png", IMAGE_ALPHA, "panel_lasser", + IMAGE_GROUP_BASE); + g_icon[GUN_MINE] = + addImageData("icon.gun.mine.png", IMAGE_ALPHA, "panel_mine", + IMAGE_GROUP_BASE); + g_icon[GUN_BOMBBALL] = + addImageData("icon.gun.bombball.png", IMAGE_ALPHA, "panel_bombball", + IMAGE_GROUP_BASE); + + g_icon[BONUS_SPEED] = + addImageData("icon.bonus.speed.png", IMAGE_ALPHA, "panel_speed", + IMAGE_GROUP_BASE); + g_icon[BONUS_SHOT] = + addImageData("icon.bonus.shot.png", IMAGE_ALPHA, "panel_shot", + IMAGE_GROUP_BASE); + g_icon[BONUS_TELEPORT] = + addImageData("icon.bonus.teleport.png", IMAGE_ALPHA, "panel_teleport", + IMAGE_GROUP_BASE); + g_icon[BONUS_GHOST] = + addImageData("icon.bonus.ghost.png", IMAGE_ALPHA, "panel_ghost", + IMAGE_GROUP_BASE); + g_icon[BONUS_4X] = + addImageData("icon.bonus.4x.png", IMAGE_ALPHA, "panel_4x", + IMAGE_GROUP_BASE); + g_icon[BONUS_HIDDEN] = + addImageData("icon.bonus.hidden.png", IMAGE_ALPHA, "panel_hidden", + IMAGE_GROUP_BASE); + + isPanelInit = TRUE; } -static void -drawScore(tux_t * tux_right, tux_t * tux_left) +static void drawScore(tux_t * tux_right, tux_t * tux_left) { - char strScoreLine[STR_SIZE]; - int w, h; - - if (tux_right != NULL && tux_left != NULL) { - sprintf(strScoreLine, "%d : %d", tux_right->score, tux_left->score); - } - else if (tux_right != NULL) { - sprintf(strScoreLine, "%d", tux_right->score); - } - else if (tux_left != NULL) { - sprintf(strScoreLine, "%d", tux_left->score); - } - - getTextSize(strScoreLine, &w, &h); - drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y, - COLOR_WHITE); + char strScoreLine[STR_SIZE]; + int w, h; + + if (tux_right != NULL && tux_left != NULL) { + sprintf(strScoreLine, "%d : %d", tux_right->score, tux_left->score); + } else if (tux_right != NULL) { + sprintf(strScoreLine, "%d", tux_right->score); + } else if (tux_left != NULL) { + sprintf(strScoreLine, "%d", tux_left->score); + } + + getTextSize(strScoreLine, &w, &h); + drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y, + COLOR_WHITE); } -static void -drawShot(int n, int x, int y) +static void drawShot(int n, int x, int y) { - drawImage(g_shot, x, y, n * PANEL_SHOT_WIDTH, 0, PANEL_SHOT_WIDTH, - PANEL_SHOT_HEIGHT); + drawImage(g_shot, x, y, n * PANEL_SHOT_WIDTH, 0, PANEL_SHOT_WIDTH, + PANEL_SHOT_HEIGHT); } -static void -drawShotInfo(tux_t * tux, int x, int y) +static void drawShotInfo(tux_t * tux, int x, int y) { - int i; - - if (tux->pickup_time > 0) { - for (i = 0; i < tux->pickup_time / 3; i++) { - drawShot(PANEL_SHOT_LINE, x + i * PANEL_SHOT_WIDTH, y); - } - - return; - } - - for (i = 0; i < GUN_MAX_SHOT; i++) { - if (tux->shot[tux->gun] > i) { - drawShot(PANEL_SHOT_FILL, x + i * (PANEL_SHOT_WIDTH + 2), y); - } - else { - drawShot(PANEL_SHOT_EMPTY, x + i * (PANEL_SHOT_WIDTH + 2), y); - } - } + int i; + + if (tux->pickup_time > 0) { + for (i = 0; i < tux->pickup_time / 3; i++) { + drawShot(PANEL_SHOT_LINE, x + i * PANEL_SHOT_WIDTH, y); + } + + return; + } + + for (i = 0; i < GUN_MAX_SHOT; i++) { + if (tux->shot[tux->gun] > i) { + drawShot(PANEL_SHOT_FILL, x + i * (PANEL_SHOT_WIDTH + 2), y); + } else { + drawShot(PANEL_SHOT_EMPTY, x + i * (PANEL_SHOT_WIDTH + 2), y); + } + } } -static void -drawGunInfo(tux_t * tux, int x, int y) +static void drawGunInfo(tux_t * tux, int x, int y) { - drawImage(g_icon[tux->gun], x, y, 0, 0, - g_icon[tux->gun]->w, g_icon[tux->gun]->h); + drawImage(g_icon[tux->gun], x, y, 0, 0, + g_icon[tux->gun]->w, g_icon[tux->gun]->h); } -static void -drawBonusInfo(tux_t * tux, int x, int y) +static void drawBonusInfo(tux_t * tux, int x, int y) { - drawImage(g_icon[tux->bonus], x, y, 0, 0, g_icon[tux->bonus]->w, - g_icon[tux->bonus]->h); + drawImage(g_icon[tux->bonus], x, y, 0, 0, g_icon[tux->bonus]->w, + g_icon[tux->bonus]->h); } -static void -drawGrafBonus(tux_t * tux, int x, int y) +static void drawGrafBonus(tux_t * tux, int x, int y) { - int offset; + int offset; - offset = tux->bonus_time / 5; - drawImage(g_bonus, x, y, 0, 0, g_bonus->w, g_bonus->h / 2); - drawImage(g_bonus, x + 1, y, 0, g_bonus->h / 2, offset, g_bonus->h / 2); + offset = tux->bonus_time / 5; + drawImage(g_bonus, x, y, 0, 0, g_bonus->w, g_bonus->h / 2); + drawImage(g_bonus, x + 1, y, 0, g_bonus->h / 2, offset, g_bonus->h / 2); } -static void -drawTuxRight(tux_t * tux) +static void drawTuxRight(tux_t * tux) { - if (tux == NULL) { - return; - } + if (tux == NULL) { + return; + } - drawShotInfo(tux, PANEL_LOCATION_X + 740, PANEL_LOCATION_Y + 34); - drawGunInfo(tux, PANEL_LOCATION_X + 620, PANEL_LOCATION_Y + 30); + drawShotInfo(tux, PANEL_LOCATION_X + 740, PANEL_LOCATION_Y + 34); + drawGunInfo(tux, PANEL_LOCATION_X + 620, PANEL_LOCATION_Y + 30); - if (tux->bonus != BONUS_NONE) { - drawGrafBonus(tux, PANEL_LOCATION_X + 460, PANEL_LOCATION_Y + 50); - drawBonusInfo(tux, PANEL_LOCATION_X + 460, PANEL_LOCATION_Y + 30); - } + if (tux->bonus != BONUS_NONE) { + drawGrafBonus(tux, PANEL_LOCATION_X + 460, PANEL_LOCATION_Y + 50); + drawBonusInfo(tux, PANEL_LOCATION_X + 460, PANEL_LOCATION_Y + 30); + } } -static void -drawTuxLeft(tux_t * tux) +static void drawTuxLeft(tux_t * tux) { - if (tux == NULL) { - return; - } + if (tux == NULL) { + return; + } - drawShotInfo(tux, PANEL_LOCATION_X + 8, PANEL_LOCATION_Y + 34); - drawGunInfo(tux, PANEL_LOCATION_X + 130, PANEL_LOCATION_Y + 30); + drawShotInfo(tux, PANEL_LOCATION_X + 8, PANEL_LOCATION_Y + 34); + drawGunInfo(tux, PANEL_LOCATION_X + 130, PANEL_LOCATION_Y + 30); - if (tux->bonus != BONUS_NONE) { - drawGrafBonus(tux, PANEL_LOCATION_X + 200, PANEL_LOCATION_Y + 50); - drawBonusInfo(tux, PANEL_LOCATION_X + 200, PANEL_LOCATION_Y + 30); - } + if (tux->bonus != BONUS_NONE) { + drawGrafBonus(tux, PANEL_LOCATION_X + 200, PANEL_LOCATION_Y + 50); + drawBonusInfo(tux, PANEL_LOCATION_X + 200, PANEL_LOCATION_Y + 30); + } } -void -drawPanel(tux_t * tux_right, tux_t * tux_left) +void drawPanel(tux_t * tux_right, tux_t * tux_left) { - drawImage(g_panel, PANEL_LOCATION_X, PANEL_LOCATION_Y, 0, 0, g_panel->w, - g_panel->h); - drawScore(tux_right, tux_left); + drawImage(g_panel, PANEL_LOCATION_X, PANEL_LOCATION_Y, 0, 0, g_panel->w, + g_panel->h); + drawScore(tux_right, tux_left); - if (isRecivedNewMsg()) { - drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y, - COLOR_WHITE); - } + if (isRecivedNewMsg()) { + drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y, + COLOR_WHITE); + } - drawTuxRight(tux_right); - drawTuxLeft(tux_left); + drawTuxRight(tux_right); + drawTuxLeft(tux_left); } -void -quitPanel() +void quitPanel() { - isPanelInit = FALSE; + isPanelInit = FALSE; } diff --git a/src/client/panel.h b/src/client/panel.h index cfc0b5e..6478f3b 100644 --- a/src/client/panel.h +++ b/src/client/panel.h @@ -1,23 +1,23 @@ #ifndef PANEL_H -#define PANEL_H +# define PANEL_H -#include "main.h" -#include "list.h" +# include "main.h" +# include "list.h" -#define PANEL_SCORE_LOCATION_X ( WINDOW_SIZE_X / 2 - w / 2 ) -#define PANEL_SCORE_LOCATION_Y ( WINDOW_SIZE_Y - 40 ) +# define PANEL_SCORE_LOCATION_X ( WINDOW_SIZE_X / 2 - w / 2 ) +# define PANEL_SCORE_LOCATION_Y ( WINDOW_SIZE_Y - 40 ) -#define PANEL_SHOT_WIDTH 4 -#define PANEL_SHOT_HEIGHT 8 +# define PANEL_SHOT_WIDTH 4 +# define PANEL_SHOT_HEIGHT 8 -#define PANEL_LOCATION_X 0 -#define PANEL_LOCATION_Y (WINDOW_SIZE_Y-g_panel->h) +# define PANEL_LOCATION_X 0 +# define PANEL_LOCATION_Y (WINDOW_SIZE_Y-g_panel->h) -#define PANEL_SHOT_FILL 0 -#define PANEL_SHOT_EMPTY 1 -#define PANEL_SHOT_LINE 2 +# define PANEL_SHOT_FILL 0 +# define PANEL_SHOT_EMPTY 1 +# define PANEL_SHOT_LINE 2 extern bool_t isPanelInicialized(); extern void initPanel(); diff --git a/src/client/pauza.c b/src/client/pauza.c index f520660..6003d51 100644 --- a/src/client/pauza.c +++ b/src/client/pauza.c @@ -15,57 +15,49 @@ static image_t *g_pauza; static bool_t activePauza; -static void -switchPauzed() +static void switchPauzed() { - if (activePauza == TRUE) { - activePauza = FALSE; - } - else { - activePauza = TRUE; - } + if (activePauza == TRUE) { + activePauza = FALSE; + } else { + activePauza = TRUE; + } } -static void -hotkey_pauze() +static void hotkey_pauze() { - switchPauzed(); + switchPauzed(); } -void -initPauza() +void initPauza() { - g_pauza = - addImageData("pauza.png", IMAGE_ALPHA, "pauza", IMAGE_GROUP_USER); - activePauza = FALSE; + g_pauza = + addImageData("pauza.png", IMAGE_ALPHA, "pauza", IMAGE_GROUP_USER); + activePauza = FALSE; - registerHotKey(SDLK_p, hotkey_pauze); + registerHotKey(SDLK_p, hotkey_pauze); } -void -drawPauza() +void drawPauza() { - if (activePauza) { - drawImage(g_pauza, - WINDOW_SIZE_X / 2 - g_pauza->w / 2, - WINDOW_SIZE_Y / 2 - g_pauza->h / 2, - 0, 0, g_pauza->w, g_pauza->h); - } + if (activePauza) { + drawImage(g_pauza, + WINDOW_SIZE_X / 2 - g_pauza->w / 2, + WINDOW_SIZE_Y / 2 - g_pauza->h / 2, + 0, 0, g_pauza->w, g_pauza->h); + } } -void -eventPauza() +void eventPauza() { } -bool_t -isPauzeActive() +bool_t isPauzeActive() { - return activePauza; + return activePauza; } -void -quitPauza() +void quitPauza() { - unregisterHotKey(SDLK_p); + unregisterHotKey(SDLK_p); } diff --git a/src/client/pauza.h b/src/client/pauza.h index b5eb58e..8ddd1f8 100644 --- a/src/client/pauza.h +++ b/src/client/pauza.h @@ -1,11 +1,11 @@ #ifndef PAUZA_H -#define PAUZA_H +# define PAUZA_H -#define PAUZE_ACTIVE_TIME_INTERVAL 1000 +# define PAUZE_ACTIVE_TIME_INTERVAL 1000 -#include "main.h" +# include "main.h" extern void initPauza(); extern void drawPauza(); diff --git a/src/client/radar.c b/src/client/radar.c index ade5599..990f8cb 100644 --- a/src/client/radar.c +++ b/src/client/radar.c @@ -15,112 +15,104 @@ static image_t *g_radar; static list_t *listRadar; -typedef struct radar_item_struct -{ - int id; - int x, y; - int type; +typedef struct radar_item_struct { + int id; + int x, y; + int type; } radar_item_t; -static radar_item_t * -newRadarItem(int id, int x, int y, int type) +static radar_item_t *newRadarItem(int id, int x, int y, int type) { - radar_item_t *new; + radar_item_t *new; - new = malloc(sizeof(radar_item_t)); - new->id = id; - new->x = x; - new->y = y; - new->type = type; + new = malloc(sizeof(radar_item_t)); + new->id = id; + new->x = x; + new->y = y; + new->type = type; - return new; + return new; } -static void -destroyRadarItem(radar_item_t * p) +static void destroyRadarItem(radar_item_t * p) { - assert(p != NULL); - free(p); + assert(p != NULL); + free(p); } -void -addToRadar(int id, int x, int y, int type) +void addToRadar(int id, int x, int y, int type) { - int i; + int i; - for (i = 0; i < listRadar->count; i++) { - radar_item_t *thisRadarItem; + for (i = 0; i < listRadar->count; i++) { + radar_item_t *thisRadarItem; - thisRadarItem = (radar_item_t *) listRadar->list[i]; + thisRadarItem = (radar_item_t *) listRadar->list[i]; - if (thisRadarItem->id == id) { - thisRadarItem->x = x; - thisRadarItem->y = y; - thisRadarItem->type = type; - return; - } - } + if (thisRadarItem->id == id) { + thisRadarItem->x = x; + thisRadarItem->y = y; + thisRadarItem->type = type; + return; + } + } - addList(listRadar, newRadarItem(id, x, y, type)); + addList(listRadar, newRadarItem(id, x, y, type)); } -void -delFromRadar(int id) +void delFromRadar(int id) { - int i; + int i; - for (i = 0; i < listRadar->count; i++) { - radar_item_t *thisRadarItem; + for (i = 0; i < listRadar->count; i++) { + radar_item_t *thisRadarItem; - thisRadarItem = (radar_item_t *) listRadar->list[i]; + thisRadarItem = (radar_item_t *) listRadar->list[i]; - if (thisRadarItem->id == id) { - delListItem(listRadar, i, destroyRadarItem); - return; - } - } + if (thisRadarItem->id == id) { + delListItem(listRadar, i, destroyRadarItem); + return; + } + } } -void -initRadar() +void initRadar() { - assert(isImageInicialized() == TRUE); - assert(isInterfaceInicialized() == TRUE); + assert(isImageInicialized() == TRUE); + assert(isInterfaceInicialized() == TRUE); - g_radar = - addImageData("radar.png", IMAGE_NO_ALPHA, "radar", IMAGE_GROUP_USER); - listRadar = newList(); + g_radar = + addImageData("radar.png", IMAGE_NO_ALPHA, "radar", IMAGE_GROUP_USER); + listRadar = newList(); } -void -drawRadar(arena_t * arena) +void drawRadar(arena_t * arena) { - int i; + int i; - drawImage(g_radar, RADAR_LOCATION_X, RADAR_LOCATION_Y, 0, 0, - RADAR_SIZE_X + 2, RADAR_SIZE_Y + 2); + drawImage(g_radar, RADAR_LOCATION_X, RADAR_LOCATION_Y, 0, 0, + RADAR_SIZE_X + 2, RADAR_SIZE_Y + 2); - for (i = 0; i < listRadar->count; i++) { - radar_item_t *thisRadarItem; - int x, y; + for (i = 0; i < listRadar->count; i++) { + radar_item_t *thisRadarItem; + int x, y; - thisRadarItem = (radar_item_t *) listRadar->list[i]; + thisRadarItem = (radar_item_t *) listRadar->list[i]; - x = (((float) RADAR_SIZE_X) / ((float) arena->w)) * - ((float) thisRadarItem->x); - y = (((float) RADAR_SIZE_Y) / ((float) arena->h)) * - ((float) thisRadarItem->y); + x = (((float) RADAR_SIZE_X) / ((float) arena->w)) * + ((float) thisRadarItem->x); + y = (((float) RADAR_SIZE_Y) / ((float) arena->h)) * + ((float) thisRadarItem->y); - if (x >= 0 && x <= RADAR_SIZE_X && y >= 0 && y <= RADAR_SIZE_Y) { - drawImage(g_radar, - RADAR_LOCATION_X + 1 + x, RADAR_LOCATION_Y + 1 + y, - 2 * thisRadarItem->type, RADAR_SIZE_Y + 2, 2, 2); - } - } + if (x >= 0 && x <= RADAR_SIZE_X && y >= 0 && y <= RADAR_SIZE_Y) { + drawImage(g_radar, + RADAR_LOCATION_X + 1 + x, RADAR_LOCATION_Y + 1 + y, + 2 * thisRadarItem->type, RADAR_SIZE_Y + 2, 2, 2); + } + } } -void -quitRadar() +void quitRadar() { - destroyListItem(listRadar, destroyRadarItem); + destroyListItem(listRadar, destroyRadarItem); } diff --git a/src/client/radar.h b/src/client/radar.h index a3f7b69..0092055 100644 --- a/src/client/radar.h +++ b/src/client/radar.h @@ -1,19 +1,19 @@ #ifndef RADAR_H -#define RADAR_H +# define RADAR_H -#include "arena.h" +# include "arena.h" -#define RADAR_LOCATION_X (WINDOW_SIZE_X-110) -#define RADAR_LOCATION_Y (10) +# define RADAR_LOCATION_X (WINDOW_SIZE_X-110) +# define RADAR_LOCATION_Y (10) -#define RADAR_SIZE_X 100 -#define RADAR_SIZE_Y 100 +# define RADAR_SIZE_X 100 +# define RADAR_SIZE_Y 100 -#define RADAR_TYPE_YOU 3 -#define RADAR_TYPE_TUX 1 -#define RADAR_TYPE_ITEM 2 +# define RADAR_TYPE_YOU 3 +# define RADAR_TYPE_TUX 1 +# define RADAR_TYPE_ITEM 2 extern void initRadar(); extern void addToRadar(int id, int x, int y, int type); diff --git a/src/client/saveDialog.c b/src/client/saveDialog.c index 39343db..d154791 100644 --- a/src/client/saveDialog.c +++ b/src/client/saveDialog.c @@ -30,118 +30,109 @@ static widget_t *widgetTextFieldName; static widget_t *widgetButtonSave; static widget_t *widgetButtonBack; -static void -switchTerm() +static void switchTerm() { - if (activeSaveDialog == TRUE) { - activeSaveDialog = FALSE; - } - else { - activeSaveDialog = TRUE; - } + if (activeSaveDialog == TRUE) { + activeSaveDialog = FALSE; + } else { + activeSaveDialog = TRUE; + } } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) p; + button = (widget_t *) p; - if (button == widgetButtonSave) { - saveArena(getTextFromWidgetTextfield(widgetTextFieldName), - getCurrentArena()); - switchTerm(); - } + if (button == widgetButtonSave) { + saveArena(getTextFromWidgetTextfield(widgetTextFieldName), + getCurrentArena()); + switchTerm(); + } - if (button == widgetButtonBack) { - switchTerm(); - } + if (button == widgetButtonBack) { + switchTerm(); + } } -static void -hotkey_saveDialog() +static void hotkey_saveDialog() { - switchTerm(); + switchTerm(); } -void -initSaveDialog() +void initSaveDialog() { - activeSaveDialog = FALSE; + activeSaveDialog = FALSE; - g_background = getImage(IMAGE_GROUP_BASE, "screen_main"); + g_background = getImage(IMAGE_GROUP_BASE, "screen_main"); - widgetLabelMsg = newWidgetLabel("name", - SAVE_DIALOG_LOCATIN_X + 20, - SAVE_DIALOG_LOCATIN_Y + 20, - WIDGET_LABEL_LEFT); + widgetLabelMsg = newWidgetLabel("name", + SAVE_DIALOG_LOCATIN_X + 20, + SAVE_DIALOG_LOCATIN_Y + 20, + WIDGET_LABEL_LEFT); - widgetTextFieldName = newWidgetTextfield("noname", - WIDGET_TEXTFIELD_FILTER_ALPHANUM, - widgetLabelMsg->x + - widgetLabelMsg->w + 10, - widgetLabelMsg->y); + widgetTextFieldName = newWidgetTextfield("noname", + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + widgetLabelMsg->x + + widgetLabelMsg->w + 10, + widgetLabelMsg->y); - widgetButtonSave = newWidgetButton("Save", - SAVE_DIALOG_LOCATIN_X + 20, - SAVE_DIALOG_LOCATIN_Y + 60, - eventWidget); + widgetButtonSave = newWidgetButton("Save", + SAVE_DIALOG_LOCATIN_X + 20, + SAVE_DIALOG_LOCATIN_Y + 60, + eventWidget); - widgetButtonBack = newWidgetButton("Back", - SAVE_DIALOG_LOCATIN_X + 20 + - WIDGET_BUTTON_WIDTH + 20, - SAVE_DIALOG_LOCATIN_Y + 60, - eventWidget); + widgetButtonBack = newWidgetButton("Back", + SAVE_DIALOG_LOCATIN_X + 20 + + WIDGET_BUTTON_WIDTH + 20, + SAVE_DIALOG_LOCATIN_Y + 60, + eventWidget); - registerHotKey(SDLK_F2, hotkey_saveDialog); + registerHotKey(SDLK_F2, hotkey_saveDialog); } -bool_t -isSaveDialogActive() +bool_t isSaveDialogActive() { - return activeSaveDialog; + return activeSaveDialog; } -void -drawSaveDialog() +void drawSaveDialog() { - if (activeSaveDialog == FALSE) { - return; - } - - drawImage(g_background, - SAVE_DIALOG_LOCATIN_X, - SAVE_DIALOG_LOCATIN_Y, - SAVE_DIALOG_LOCATIN_X, - SAVE_DIALOG_LOCATIN_Y, SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y); - - drawWidgetLabel(widgetLabelMsg); - drawWidgetTextfield(widgetTextFieldName); - drawWidgetButton(widgetButtonSave); - drawWidgetButton(widgetButtonBack); + if (activeSaveDialog == FALSE) { + return; + } + + drawImage(g_background, + SAVE_DIALOG_LOCATIN_X, + SAVE_DIALOG_LOCATIN_Y, + SAVE_DIALOG_LOCATIN_X, + SAVE_DIALOG_LOCATIN_Y, SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y); + + drawWidgetLabel(widgetLabelMsg); + drawWidgetTextfield(widgetTextFieldName); + drawWidgetButton(widgetButtonSave); + drawWidgetButton(widgetButtonBack); } -void -eventSaveDialog() +void eventSaveDialog() { - if (activeSaveDialog == FALSE) { - return; - } + if (activeSaveDialog == FALSE) { + return; + } - eventWidgetTextfield(widgetTextFieldName); - eventWidgetButton(widgetButtonSave); - eventWidgetButton(widgetButtonBack); + eventWidgetTextfield(widgetTextFieldName); + eventWidgetButton(widgetButtonSave); + eventWidgetButton(widgetButtonBack); } -void -quitSaveDialog() +void quitSaveDialog() { - unregisterHotKey(SDLK_F2); + unregisterHotKey(SDLK_F2); - destroyWidgetLabel(widgetLabelMsg); - destroyWidgetTextfield(widgetTextFieldName); - destroyWidgetButton(widgetButtonSave); - destroyWidgetButton(widgetButtonBack); + destroyWidgetLabel(widgetLabelMsg); + destroyWidgetTextfield(widgetTextFieldName); + destroyWidgetButton(widgetButtonSave); + destroyWidgetButton(widgetButtonBack); } diff --git a/src/client/saveDialog.h b/src/client/saveDialog.h index 0849bdb..d96a252 100644 --- a/src/client/saveDialog.h +++ b/src/client/saveDialog.h @@ -1,15 +1,15 @@ #ifndef SAVE_DIALOG_H -#define SAVE_DIALOG_H +# define SAVE_DIALOG_H -#define SAVEDIALOG_ACTIVE_TIME_INTERVAL 500 +# define SAVEDIALOG_ACTIVE_TIME_INTERVAL 500 -#define SAVE_DIALOG_SIZE_X 320 -#define SAVE_DIALOG_SIZE_Y 120 +# define SAVE_DIALOG_SIZE_X 320 +# define SAVE_DIALOG_SIZE_Y 120 -#define SAVE_DIALOG_LOCATIN_X (WINDOW_SIZE_X/2 - SAVE_DIALOG_SIZE_X/2) -#define SAVE_DIALOG_LOCATIN_Y (WINDOW_SIZE_Y/2 - SAVE_DIALOG_SIZE_Y/2) +# define SAVE_DIALOG_LOCATIN_X (WINDOW_SIZE_X/2 - SAVE_DIALOG_SIZE_X/2) +# define SAVE_DIALOG_LOCATIN_Y (WINDOW_SIZE_Y/2 - SAVE_DIALOG_SIZE_Y/2) extern void initSaveDialog(); diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c index c49245f..01f6ea1 100644 --- a/src/client/saveLoad.c +++ b/src/client/saveLoad.c @@ -19,254 +19,243 @@ #include "screen_choiceArena.h" #include "screen_world.h" -static void -action_saveTux(space_t * space, tux_t * tux, textFile_t * textFile) +static void action_saveTux(space_t * space, tux_t * tux, textFile_t * textFile) { - char str[STR_PROTO_SIZE]; - - snprintf(str, STR_PROTO_SIZE, - "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", - tux->id, tux->x, tux->y, tux->status, tux->position, - tux->control, tux->frame, tux->score, tux->name, tux->gun, - tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], - tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], - tux->shot[GUN_LASSER], tux->shot[GUN_MINE], - tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); - - addList(textFile->text, strdup(str)); + char str[STR_PROTO_SIZE]; + + snprintf(str, STR_PROTO_SIZE, + "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + tux->id, tux->x, tux->y, tux->status, tux->position, + tux->control, tux->frame, tux->score, tux->name, tux->gun, + tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], + tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], + tux->shot[GUN_LASSER], tux->shot[GUN_MINE], + tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); + + addList(textFile->text, strdup(str)); } static void action_saveShot(space_t * space, shot_t * shot, textFile_t * textFile) { - char str[STR_PROTO_SIZE]; + char str[STR_PROTO_SIZE]; - snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d", - shot->id, shot->x, shot->y, shot->px, shot->py, - shot->position, shot->gun, shot->author_id, - shot->isCanKillAuthor); + snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d", + shot->id, shot->x, shot->y, shot->px, shot->py, + shot->position, shot->gun, shot->author_id, + shot->isCanKillAuthor); - addList(textFile->text, strdup(str)); + addList(textFile->text, strdup(str)); } static void action_saveItem(space_t * space, item_t * item, textFile_t * textFile) { - char str[STR_PROTO_SIZE]; + char str[STR_PROTO_SIZE]; - snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d", - item->id, item->type, item->x, item->y, - item->count, item->frame, item->author_id); + snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d", + item->id, item->type, item->x, item->y, + item->count, item->frame, item->author_id); - addList(textFile->text, strdup(str)); + addList(textFile->text, strdup(str)); } -static void -saveContextArenaToTextFile(textFile_t * textFile, arena_t * arena) +static void saveContextArenaToTextFile(textFile_t * textFile, arena_t * arena) { - char str[STR_PROTO_SIZE]; + char str[STR_PROTO_SIZE]; - sprintf(str, "ARENA %s %d %d", - getArenaNetName(getChoiceArena()), - arena->countRound, arena->max_countRound); + sprintf(str, "ARENA %s %d %d", + getArenaNetName(getChoiceArena()), + arena->countRound, arena->max_countRound); - addList(textFile->text, strdup(str)); + addList(textFile->text, strdup(str)); - actionSpace(arena->spaceTux, action_saveTux, textFile); - actionSpace(arena->spaceShot, action_saveShot, textFile); - actionSpace(arena->spaceItem, action_saveItem, textFile); + actionSpace(arena->spaceTux, action_saveTux, textFile); + actionSpace(arena->spaceShot, action_saveShot, textFile); + actionSpace(arena->spaceItem, action_saveItem, textFile); } -void -saveArena(char *filename, arena_t * arena) +void saveArena(char *filename, arena_t * arena) { - textFile_t *textFile; - char path[STR_PATH_SIZE]; + textFile_t *textFile; + char path[STR_PATH_SIZE]; - sprintf(path, "%s/%s.sav", getHomeDirector(), filename); + sprintf(path, "%s/%s.sav", getHomeDirector(), filename); #ifdef DEBUG - printf(_("Saving game to: \"%s\"\n"), path); + printf(_("Saving game to: \"%s\"\n"), path); #endif - textFile = newTextFile(path); - - if (textFile != NULL) { - saveContextArenaToTextFile(textFile, arena); - saveTextFile(textFile); - destroyTextFile(textFile); - } - else { - fprintf(stderr, _("I was unable to save: \"%s\"\n"), path); - } + textFile = newTextFile(path); + + if (textFile != NULL) { + saveContextArenaToTextFile(textFile, arena); + saveTextFile(textFile); + destroyTextFile(textFile); + } else { + fprintf(stderr, _("I was unable to save: \"%s\"\n"), path); + } } -static arena_t * -loadArenaFromLine(char *line) +static arena_t *loadArenaFromLine(char *line) { - char cmd[STR_SIZE]; - char name[STR_SIZE]; - int countRound; - int max_countRound; - arena_t *arena; + char cmd[STR_SIZE]; + char name[STR_SIZE]; + int countRound; + int max_countRound; + arena_t *arena; - sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound); + sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound); - setWorldArena(getArenaFileFormNetName(name)); + setWorldArena(getArenaFileFormNetName(name)); - arena = getCurrentArena(); - arena->max_countRound = max_countRound; - arena->countRound = countRound; + arena = getCurrentArena(); + arena->max_countRound = max_countRound; + arena->countRound = countRound; - return arena; + return arena; } -static void -loadTuxFromLine(char *line, arena_t * arena) +static void loadTuxFromLine(char *line, arena_t * arena) { - char cmd[STR_PROTO_SIZE]; - char name[STR_NAME_SIZE]; - int id, x, y, status, position, frame, score, control; - int myGun, myBonus; - int gun1, gun2, gun3, gun4, gun5, gun6, gun7; - int time1, time2; - tux_t *tux; - - sscanf(line, - "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", - cmd, &id, &x, &y, &status, &position, &control, &frame, &score, - name, &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, - &gun7, &time1, &time2); - - tux = newTux(); - replaceTuxID(tux, id); - addObjectToSpace(arena->spaceTux, tux); - - tux->control = control; - - if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT) { - setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); - } - - if (tux->control == TUX_CONTROL_KEYBOARD_LEFT) { - setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT); - } - - if (tux->control == TUX_CONTROL_AI) { - loadModule("libmodAI"); - setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT); - } - - moveObjectInSpace(arena->spaceTux, tux, x, y); - tux->status = status; - tux->position = position; - tux->frame = frame; - tux->score = score; - strcpy(tux->name, name); - tux->gun = myGun; - tux->bonus = myBonus; - tux->shot[GUN_SIMPLE] = gun1; - tux->shot[GUN_DUAL_SIMPLE] = gun2; - tux->shot[GUN_SCATTER] = gun3; - tux->shot[GUN_TOMMY] = gun4; - tux->shot[GUN_LASSER] = gun5; - tux->shot[GUN_MINE] = gun6; - tux->shot[GUN_BOMBBALL] = gun7; - tux->bonus_time = time1; - tux->pickup_time = time2; + char cmd[STR_PROTO_SIZE]; + char name[STR_NAME_SIZE]; + int id, x, y, status, position, frame, score, control; + int myGun, myBonus; + int gun1, gun2, gun3, gun4, gun5, gun6, gun7; + int time1, time2; + tux_t *tux; + + sscanf(line, + "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + cmd, &id, &x, &y, &status, &position, &control, &frame, &score, + name, &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, + &gun7, &time1, &time2); + + tux = newTux(); + replaceTuxID(tux, id); + addObjectToSpace(arena->spaceTux, tux); + + tux->control = control; + + if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT) { + setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); + } + + if (tux->control == TUX_CONTROL_KEYBOARD_LEFT) { + setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT); + } + + if (tux->control == TUX_CONTROL_AI) { + loadModule("libmodAI"); + setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT); + } + + moveObjectInSpace(arena->spaceTux, tux, x, y); + tux->status = status; + tux->position = position; + tux->frame = frame; + tux->score = score; + strcpy(tux->name, name); + tux->gun = myGun; + tux->bonus = myBonus; + tux->shot[GUN_SIMPLE] = gun1; + tux->shot[GUN_DUAL_SIMPLE] = gun2; + tux->shot[GUN_SCATTER] = gun3; + tux->shot[GUN_TOMMY] = gun4; + tux->shot[GUN_LASSER] = gun5; + tux->shot[GUN_MINE] = gun6; + tux->shot[GUN_BOMBBALL] = gun7; + tux->bonus_time = time1; + tux->pickup_time = time2; } -static void -loadShotFromLine(char *line, arena_t * arena) +static void loadShotFromLine(char *line, arena_t * arena) { - char cmd[STR_PROTO_SIZE]; - int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; - shot_t *shot; + char cmd[STR_PROTO_SIZE]; + int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; + shot_t *shot; - sscanf(line, "%s %d %d %d %d %d %d %d %d %d", - cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, - &isCanKillAuthor); + sscanf(line, "%s %d %d %d %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, + &isCanKillAuthor); - shot = newShot(x, y, px, py, gun, author_id); + shot = newShot(x, y, px, py, gun, author_id); - replaceShotID(shot, shot_id); - shot->isCanKillAuthor = isCanKillAuthor; - shot->position = position; + replaceShotID(shot, shot_id); + shot->isCanKillAuthor = isCanKillAuthor; + shot->position = position; - if (shot->gun == GUN_LASSER) { - transformOnlyLasser(shot); - } + if (shot->gun == GUN_LASSER) { + transformOnlyLasser(shot); + } - addObjectToSpace(arena->spaceShot, shot); + addObjectToSpace(arena->spaceShot, shot); } -static void -loadItemFromLine(char *line, arena_t * arena) +static void loadItemFromLine(char *line, arena_t * arena) { - char cmd[STR_PROTO_SIZE]; - int id, type, x, y, count, frame, author_id, check_id; - item_t *item; + char cmd[STR_PROTO_SIZE]; + int id, type, x, y, count, frame, author_id, check_id; + item_t *item; - sscanf(line, "%s %d %d %d %d %d %d %d %d", - cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id); + sscanf(line, "%s %d %d %d %d %d %d %d %d", + cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id); - item = newItem(x, y, type, author_id); + item = newItem(x, y, type, author_id); - replaceItemID(item, id); - item->count = count; - item->frame = frame; + replaceItemID(item, id); + item->count = count; + item->frame = frame; - addObjectToSpace(arena->spaceItem, item); + addObjectToSpace(arena->spaceItem, item); } -static arena_t * -loadContextArenaFromTextFile(textFile_t * textFile) +static arena_t *loadContextArenaFromTextFile(textFile_t * textFile) { - arena_t *arena; - int i; + arena_t *arena; + int i; - arena = NULL; + arena = NULL; - for (i = 0; i < textFile->text->count; i++) { - char *line; + for (i = 0; i < textFile->text->count; i++) { + char *line; - line = (char *) textFile->text->list[i]; + line = (char *) textFile->text->list[i]; - if (strncmp(line, "ARENA", 5) == 0) { - arena = loadArenaFromLine(line); - } + if (strncmp(line, "ARENA", 5) == 0) { + arena = loadArenaFromLine(line); + } - if (strncmp(line, "TUX", 3) == 0) { - loadTuxFromLine(line, arena); - } + if (strncmp(line, "TUX", 3) == 0) { + loadTuxFromLine(line, arena); + } - if (strncmp(line, "SHOT", 4) == 0) { - loadShotFromLine(line, arena); - } + if (strncmp(line, "SHOT", 4) == 0) { + loadShotFromLine(line, arena); + } - if (strncmp(line, "ITEM", 4) == 0) { - loadItemFromLine(line, arena); - } - } + if (strncmp(line, "ITEM", 4) == 0) { + loadItemFromLine(line, arena); + } + } - return arena; + return arena; } -void -loadArena(char *filename) +void loadArena(char *filename) { - textFile_t *textFile; - char path[STR_PATH_SIZE]; + textFile_t *textFile; + char path[STR_PATH_SIZE]; - sprintf(path, "%s/%s", getHomeDirector(), filename); + sprintf(path, "%s/%s", getHomeDirector(), filename); #ifdef DEBUG - printf(_("Loadig game from file: \"%s\"\n"), path); + printf(_("Loadig game from file: \"%s\"\n"), path); #endif - textFile = loadTextFile(path); - - if (textFile != NULL) { - loadContextArenaFromTextFile(textFile); - destroyTextFile(textFile); - } - else { - fprintf(stderr, _("Unable to load save: \"%s\"\n"), path); - } + textFile = loadTextFile(path); + + if (textFile != NULL) { + loadContextArenaFromTextFile(textFile); + destroyTextFile(textFile); + } else { + fprintf(stderr, _("Unable to load save: \"%s\"\n"), path); + } } diff --git a/src/client/saveLoad.h b/src/client/saveLoad.h index 2860408..f62e293 100644 --- a/src/client/saveLoad.h +++ b/src/client/saveLoad.h @@ -1,10 +1,10 @@ #ifndef SAVELOAD_H -#define SAVELOAD_H +# define SAVELOAD_H -#include "textFile.h" -#include "arena.h" +# include "textFile.h" +# include "arena.h" extern void saveArena(char *filename, arena_t * arena); extern void loadArena(char *filename); diff --git a/src/client/screen.c b/src/client/screen.c index f9f1f2f..b5264bd 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -19,182 +19,169 @@ static list_t *listScreen; static bool_t isScreenInit = FALSE; -bool_t -isScreenInicialized() +bool_t isScreenInicialized() { - return isScreenInit; + return isScreenInit; } -screen_t * -newScreen(char *name, - void (*fce_start) (), void (*fce_event) (), - void (*fce_draw) (), void (*fce_stop) ()) +screen_t *newScreen(char *name, + void (*fce_start) (), void (*fce_event) (), + void (*fce_draw) (), void (*fce_stop) ()) { - screen_t *new; - - assert(name != NULL); - assert(fce_start != NULL); - assert(fce_event != NULL); - assert(fce_draw != NULL); - assert(fce_stop != NULL); - - new = malloc(sizeof(screen_t)); - new->name = strdup(name); - new->fce_start = fce_start; - new->fce_event = fce_event; - new->fce_draw = fce_draw; - new->fce_stop = fce_stop; - - return new; + screen_t *new; + + assert(name != NULL); + assert(fce_start != NULL); + assert(fce_event != NULL); + assert(fce_draw != NULL); + assert(fce_stop != NULL); + + new = malloc(sizeof(screen_t)); + new->name = strdup(name); + new->fce_start = fce_start; + new->fce_event = fce_event; + new->fce_draw = fce_draw; + new->fce_stop = fce_stop; + + return new; } -void -destroyScreen(screen_t * p) +void destroyScreen(screen_t * p) { - assert(p != NULL); + assert(p != NULL); - free(p->name); - free(p); + free(p->name); + free(p); } -void -registerScreen(screen_t * p) +void registerScreen(screen_t * p) { - assert(p != NULL); + assert(p != NULL); #ifdef DEBUG - printf(_("Registering screen: \"%s\"\n"), p->name); + printf(_("Registering screen: \"%s\"\n"), p->name); #endif - addList(listScreen, p); + addList(listScreen, p); } -void -initScreen() +void initScreen() { - listScreen = newList(); + listScreen = newList(); - currentScreen = NULL; - futureScreen = NULL; + currentScreen = NULL; + futureScreen = NULL; - isScreenInit = TRUE; + isScreenInit = TRUE; } -static screen_t * -findScreen(char *name) +static screen_t *findScreen(char *name) { - screen_t *this; - int i; + screen_t *this; + int i; - for (i = 0; i < listScreen->count; i++) { - this = (screen_t *) (listScreen->list[i]); - assert(this != NULL); + for (i = 0; i < listScreen->count; i++) { + this = (screen_t *) (listScreen->list[i]); + assert(this != NULL); - if (strcmp(name, this->name) == 0) { - return this; - } - } + if (strcmp(name, this->name) == 0) { + return this; + } + } - return NULL; + return NULL; } -void -setScreen(char *name) +void setScreen(char *name) { - futureScreen = findScreen(name); - assert(futureScreen != NULL); + futureScreen = findScreen(name); + assert(futureScreen != NULL); } -void -switchScreen() +void switchScreen() { - if (futureScreen == NULL) { - return; - } + if (futureScreen == NULL) { + return; + } - flushLayer(); + flushLayer(); - if (currentScreen != NULL) { + if (currentScreen != NULL) { #ifdef DEBUG - printf(_("Stopping screen: \"%s\"\n"), currentScreen->name); + printf(_("Stopping screen: \"%s\"\n"), currentScreen->name); #endif - currentScreen->fce_stop(); - } + currentScreen->fce_stop(); + } - currentScreen = futureScreen; - futureScreen = NULL; + currentScreen = futureScreen; + futureScreen = NULL; - //printf("switch screen %s..\n", currentScreen->name); + //printf("switch screen %s..\n", currentScreen->name); #ifdef DEBUG - printf(_("Starting screen: \"%s\"\n"), currentScreen->name); + printf(_("Starting screen: \"%s\"\n"), currentScreen->name); #endif - currentScreen->fce_start(); + currentScreen->fce_start(); } -void -startScreen(char *name) +void startScreen(char *name) { - setScreen(name); - switchScreen(); + setScreen(name); + switchScreen(); } -char * -getScreen() +char *getScreen() { - assert(currentScreen != NULL); - return currentScreen->name; + assert(currentScreen != NULL); + return currentScreen->name; } -void -drawScreen() +void drawScreen() { - static int count = 0; + static int count = 0; - count++; + count++; - if (count == 1) { - count = 0; + if (count == 1) { + count = 0; - assert(currentScreen != NULL); + assert(currentScreen != NULL); #ifdef DEBUG_TIME_DRAW - my_time_t prev; + my_time_t prev; - prev = getMyTimeMicro(); + prev = getMyTimeMicro(); #endif - currentScreen->fce_draw(); + currentScreen->fce_draw(); - interfaceRefresh(); + interfaceRefresh(); #ifdef DEBUG_TIME_DRAW - printf("c draw time = %d\n", getMyTimeMicro() - prev); + printf("c draw time = %d\n", getMyTimeMicro() - prev); #endif - } + } } -void -eventScreen() +void eventScreen() { - assert(currentScreen != NULL); + assert(currentScreen != NULL); #ifdef DEBUG_TIME_EVENT - my_time_t prev; + my_time_t prev; - prev = getMyTimeMicro(); + prev = getMyTimeMicro(); #endif - currentScreen->fce_event(); + currentScreen->fce_event(); #ifdef DEBUG_TIME_EVENT - printf("c event time = %d\n", getMyTimeMicro() - prev); + printf("c event time = %d\n", getMyTimeMicro() - prev); #endif } -void -quitScreen() +void quitScreen() { - assert(listScreen != NULL); + assert(listScreen != NULL); - destroyListItem(listScreen, destroyScreen); - isScreenInit = FALSE; + destroyListItem(listScreen, destroyScreen); + isScreenInit = FALSE; } diff --git a/src/client/screen.h b/src/client/screen.h index b0bdca3..3227bfe 100644 --- a/src/client/screen.h +++ b/src/client/screen.h @@ -1,24 +1,23 @@ #ifndef SCREEN_H -#define SCREEN_H +# define SCREEN_H -#include "main.h" +# include "main.h" -typedef struct screen_struct -{ - char *name; - void (*fce_start) (); - void (*fce_event) (); - void (*fce_draw) (); - void (*fce_stop) (); +typedef struct screen_struct { + char *name; + void (*fce_start) (); + void (*fce_event) (); + void (*fce_draw) (); + void (*fce_stop) (); } screen_t; extern bool_t isScreenInicialized(); extern screen_t *newScreen(char *name, - void (*fce_start) (), void (*fce_event) (), - void (*fce_draw) (), void (*fce_stop) ()); + void (*fce_start) (), void (*fce_event) (), + void (*fce_draw) (), void (*fce_stop) ()); extern void destroyScreen(screen_t * p); extern void registerScreen(screen_t * p); diff --git a/src/client/term.c b/src/client/term.c index e0eb939..5266c53 100644 --- a/src/client/term.c +++ b/src/client/term.c @@ -18,151 +18,141 @@ static bool_t activeTerm; static my_time_t lastActive; static my_time_t lastRefresh; -void -initTerm() +void initTerm() { - listText = newList(); + listText = newList(); - activeTerm = FALSE; - lastActive = getMyTime(); - lastRefresh = lastActive; + activeTerm = FALSE; + lastActive = getMyTime(); + lastRefresh = lastActive; } -static char * -getStrGun(int gun) +static char *getStrGun(int gun) { - switch (gun) { - case GUN_SIMPLE: - return "revolver"; - case GUN_DUAL_SIMPLE: - return "dual revolver"; - case GUN_SCATTER: - return "scatter"; - case GUN_TOMMY: - return "tommy"; - case GUN_LASSER: - return "lasser"; - case GUN_MINE: - return "mine"; - case GUN_BOMBBALL: - return "bombball"; - default: - return "none"; - } - - return "gun_unknow"; + switch (gun) { + case GUN_SIMPLE: + return "revolver"; + case GUN_DUAL_SIMPLE: + return "dual revolver"; + case GUN_SCATTER: + return "scatter"; + case GUN_TOMMY: + return "tommy"; + case GUN_LASSER: + return "lasser"; + case GUN_MINE: + return "mine"; + case GUN_BOMBBALL: + return "bombball"; + default: + return "none"; + } + + return "gun_unknow"; } -static char * -getStrBonus(int bonus) +static char *getStrBonus(int bonus) { - switch (bonus) { - case BONUS_SPEED: - return "speed"; - case BONUS_SHOT: - return "shot"; - case BONUS_TELEPORT: - return "teleport"; - case BONUS_GHOST: - return "ghost"; - case BONUS_4X: - return "4X"; - case BONUS_HIDDEN: - return "hidden"; - default: - return "none"; - } - - return "bonus_unknow"; + switch (bonus) { + case BONUS_SPEED: + return "speed"; + case BONUS_SHOT: + return "shot"; + case BONUS_TELEPORT: + return "teleport"; + case BONUS_GHOST: + return "ghost"; + case BONUS_4X: + return "4X"; + case BONUS_HIDDEN: + return "hidden"; + default: + return "none"; + } + + return "bonus_unknow"; } -static void -action_refreshTerm(space_t * space, tux_t * tux, void *p) +static void action_refreshTerm(space_t * space, tux_t * tux, void *p) { - char str[STR_SIZE]; - - sprintf(str, - "name: %s " - "score: %d " - "gun: %s " - "shot: %d " - "bonus: %s", - tux->name, tux->score, - getStrGun(tux->gun), tux->shot[tux->gun], getStrBonus(tux->bonus) - ); - - addList(listText, strdup(str)); + char str[STR_SIZE]; + + sprintf(str, + "name: %s " + "score: %d " + "gun: %s " + "shot: %d " + "bonus: %s", + tux->name, tux->score, + getStrGun(tux->gun), tux->shot[tux->gun], getStrBonus(tux->bonus) + ); + + addList(listText, strdup(str)); } -static void -refreshTerm() +static void refreshTerm() { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - destroyListItem(listText, free); - listText = newList(); + destroyListItem(listText, free); + listText = newList(); - actionSpace(arena->spaceTux, action_refreshTerm, NULL); + actionSpace(arena->spaceTux, action_refreshTerm, NULL); - //printf("refresh term..\n"); + //printf("refresh term..\n"); } -void -drawTerm() +void drawTerm() { - int i; + int i; - if (activeTerm == FALSE) { - return; - } + if (activeTerm == FALSE) { + return; + } - for (i = 0; i < listText->count; i++) { - char *line; + for (i = 0; i < listText->count; i++) { + char *line; - line = (char *) listText->list[i]; - drawFont(line, 10, 10 + i * 20, COLOR_WHITE); - } + line = (char *) listText->list[i]; + drawFont(line, 10, 10 + i * 20, COLOR_WHITE); + } } -static void -switchTerm() +static void switchTerm() { - if (activeTerm == TRUE) { - activeTerm = FALSE; - } - else { - activeTerm = TRUE; - } + if (activeTerm == TRUE) { + activeTerm = FALSE; + } else { + activeTerm = TRUE; + } } -void -eventTerm() +void eventTerm() { - my_time_t currentTime; - Uint8 *mapa; + my_time_t currentTime; + Uint8 *mapa; - mapa = SDL_GetKeyState(NULL); + mapa = SDL_GetKeyState(NULL); - currentTime = getMyTime(); + currentTime = getMyTime(); - if (currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL) { - lastRefresh = currentTime; - refreshTerm(); - } + if (currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL) { + lastRefresh = currentTime; + refreshTerm(); + } - if (mapa[SDLK_TAB] == SDL_PRESSED) { - if (currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL) { - lastActive = currentTime; - switchTerm(); - } - } + if (mapa[SDLK_TAB] == SDL_PRESSED) { + if (currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL) { + lastActive = currentTime; + switchTerm(); + } + } } -void -quitTerm() +void quitTerm() { - assert(listText != NULL); - destroyListItem(listText, free); + assert(listText != NULL); + destroyListItem(listText, free); } diff --git a/src/client/term.h b/src/client/term.h index 99dbf79..ffc0e14 100644 --- a/src/client/term.h +++ b/src/client/term.h @@ -1,12 +1,12 @@ #ifndef TERM_H -#define TERM_H +# define TERM_H -#include "main.h" +# include "main.h" -#define TERM_ACTIVE_TIME_INTERVAL 500 -#define TERM_REFRESH_TIME_INTERVAL 1000 +# define TERM_ACTIVE_TIME_INTERVAL 500 +# define TERM_REFRESH_TIME_INTERVAL 1000 extern void initTerm(); extern void drawTerm(); diff --git a/src/downserver/downServer.c b/src/downserver/downServer.c index 0580337..e783f06 100644 --- a/src/downserver/downServer.c +++ b/src/downserver/downServer.c @@ -32,331 +32,312 @@ static sock_tcp_t *sock_server_tcp; static list_t *listClient; static textFile_t *configFile; -typedef struct -{ - int status; +typedef struct { + int status; - FILE *file; - int fileSize; - int fileOffset; + FILE *file; + int fileSize; + int fileOffset; - sock_tcp_t *socket; - buffer_t *recvBuffer; - buffer_t *sendBuffer; + sock_tcp_t *socket; + buffer_t *recvBuffer; + buffer_t *sendBuffer; } client_t; -static client_t * -newClient(sock_tcp_t * sock) +static client_t *newClient(sock_tcp_t * sock) { - client_t *new; + client_t *new; - new = malloc(sizeof(client_t)); - new->socket = sock; - new->status = NET_STATUS_OK; - new->file = NULL; - new->recvBuffer = newBuffer(CLIENT_LIMIT_BUFFER); - new->sendBuffer = newBuffer(CLIENT_LIMIT_BUFFER); + new = malloc(sizeof(client_t)); + new->socket = sock; + new->status = NET_STATUS_OK; + new->file = NULL; + new->recvBuffer = newBuffer(CLIENT_LIMIT_BUFFER); + new->sendBuffer = newBuffer(CLIENT_LIMIT_BUFFER); - return new; + return new; } -static void -destroyClient(client_t * client) +static void destroyClient(client_t * client) { - if (client->file != NULL) - fclose(client->file); - closeTcpSocket(client->socket); - destroyBuffer(client->recvBuffer); - destroyBuffer(client->sendBuffer); - free(client); + if (client->file != NULL) + fclose(client->file); + closeTcpSocket(client->socket); + destroyBuffer(client->recvBuffer); + destroyBuffer(client->sendBuffer); + free(client); } -int -getFileSize(char *s) +int getFileSize(char *s) { - struct stat buf; + struct stat buf; - if (lstat(s, &buf) < 0) { - return -1; - } + if (lstat(s, &buf) < 0) { + return -1; + } - return buf.st_size; + return buf.st_size; } -static char * -getFileFromArenaNetName(char *s) +static char *getFileFromArenaNetName(char *s) { - int i; + int i; - for (i = 0; i < configFile->text->count; i++) { - char path[STR_PATH_SIZE]; - char arena[STR_ARENA_NET_NAME_SIZE]; - char *line; - int len; + for (i = 0; i < configFile->text->count; i++) { + char path[STR_PATH_SIZE]; + char arena[STR_ARENA_NET_NAME_SIZE]; + char *line; + int len; - line = configFile->text->list[i]; + line = configFile->text->list[i]; - sscanf(line, "%s %s", path, arena); - len = strlen(arena); + sscanf(line, "%s %s", path, arena); + len = strlen(arena); - if (strncmp(arena, s, len) == 0) { - return strdup(path); - } - } + if (strncmp(arena, s, len) == 0) { + return strdup(path); + } + } - return NULL; + return NULL; } -static void -proto_getarena(client_t * client, char *msg) +static void proto_getarena(client_t * client, char *msg) { - char msg_out[PROTO_SIZE]; - char *path; - - path = getFileFromArenaNetName(msg); - - if (path != NULL) { - client->file = fopen(path, "rb"); - client->fileSize = getFileSize(path); - client->fileOffset = 0; - free(path); - - if (client->file == NULL || client->fileSize < 0) { - client->file = NULL; - client->fileSize = 0; - sprintf(msg_out, "ERR server has a problem !\n"); - } - else { - sprintf(msg_out, "OK %d\n", client->fileSize); - } - } - else { - sprintf(msg_out, "ERR arena not found\n"); - } - - addBuffer(client->sendBuffer, msg_out, strlen(msg_out)); + char msg_out[PROTO_SIZE]; + char *path; + + path = getFileFromArenaNetName(msg); + + if (path != NULL) { + client->file = fopen(path, "rb"); + client->fileSize = getFileSize(path); + client->fileOffset = 0; + free(path); + + if (client->file == NULL || client->fileSize < 0) { + client->file = NULL; + client->fileSize = 0; + sprintf(msg_out, "ERR server has a problem !\n"); + } else { + sprintf(msg_out, "OK %d\n", client->fileSize); + } + } else { + sprintf(msg_out, "ERR arena not found\n"); + } + + addBuffer(client->sendBuffer, msg_out, strlen(msg_out)); } -static void -doProto(client_t * client, char *msg) +static void doProto(client_t * client, char *msg) { - printf("hmm msg = %s\n", msg); + printf("hmm msg = %s\n", msg); - if (strncmp(msg, "GETARENA", 8) == 0 && client->file == NULL) { - proto_getarena(client, msg + 9); - } + if (strncmp(msg, "GETARENA", 8) == 0 && client->file == NULL) { + proto_getarena(client, msg + 9); + } } -static int -initDownServer(char *ip, int port) +static int initDownServer(char *ip, int port) { - sock_server_tcp = bindTcpSocket(ip, port, PROTO_TCPv4); + sock_server_tcp = bindTcpSocket(ip, port, PROTO_TCPv4); - listClient = newList(); + listClient = newList(); - configFile = loadTextFile("arena.conf"); + configFile = loadTextFile("arena.conf"); - return 0; + return 0; } -static void -eventNewClient(sock_tcp_t * server_sock) +static void eventNewClient(sock_tcp_t * server_sock) { - sock_tcp_t *sock; - client_t *client; + sock_tcp_t *sock; + client_t *client; - sock = getTcpNewClient(server_sock); - setTcpSockNonBlock(sock); + sock = getTcpNewClient(server_sock); + setTcpSockNonBlock(sock); - client = newClient(sock); - addList(listClient, client); + client = newClient(sock); + addList(listClient, client); } -static void -eventRecvClient(client_t * client) +static void eventRecvClient(client_t * client) { - char buffer[BUFFER_SIZE]; - char line[PROTO_SIZE]; - int ret; + char buffer[BUFFER_SIZE]; + char line[PROTO_SIZE]; + int ret; - memset(buffer, 0, BUFFER_SIZE); + memset(buffer, 0, BUFFER_SIZE); - ret = readTcpSocket(client->socket, buffer, BUFFER_SIZE - 1); - //printf("readTcpSocket = %d\n", ret); + ret = readTcpSocket(client->socket, buffer, BUFFER_SIZE - 1); + //printf("readTcpSocket = %d\n", ret); - if (ret <= 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (ret <= 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - if (addBuffer(client->recvBuffer, buffer, ret) < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (addBuffer(client->recvBuffer, buffer, ret) < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - while (getBufferLine(client->recvBuffer, line, PROTO_SIZE) >= 0) { - doProto(client, line); - } + while (getBufferLine(client->recvBuffer, line, PROTO_SIZE) >= 0) { + doProto(client, line); + } } -static void -eventSendClient(client_t * client) +static void eventSendClient(client_t * client) { - void *data; - int len; - int res; + void *data; + int len; + int res; - len = getBufferSize(client->sendBuffer); + len = getBufferSize(client->sendBuffer); - if (len == 0) { - return; - } + if (len == 0) { + return; + } - data = getBufferData(client->sendBuffer); + data = getBufferData(client->sendBuffer); - res = writeTcpSocket(client->socket, data, len); - //printf("send = %d\n", res); - //printf("writeTcpSocket = %d\n", res); + res = writeTcpSocket(client->socket, data, len); + //printf("send = %d\n", res); + //printf("writeTcpSocket = %d\n", res); - if (res < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (res < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - cutBuffer(client->sendBuffer, res); + cutBuffer(client->sendBuffer, res); } -static void -eventClient(client_t * client) +static void eventClient(client_t * client) { - if (client->file != NULL && getBufferSize(client->sendBuffer) == 0) { - char buffer[BUFFER_SEND_FILE_SIZE]; - int count; - int ret; - - count = client->fileSize - client->fileOffset; - - if (count > BUFFER_SEND_FILE_SIZE) { - count = BUFFER_SEND_FILE_SIZE; - } - - ret = fread(buffer, count, 1, client->file); - //printf("read = %d\n", count); - - if (ret == 1) { - if (addBuffer(client->sendBuffer, buffer, count) < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } - - client->fileOffset += count; - } - else { - client->status = NET_STATUS_ZOMBIE; - } - } + if (client->file != NULL && getBufferSize(client->sendBuffer) == 0) { + char buffer[BUFFER_SEND_FILE_SIZE]; + int count; + int ret; + + count = client->fileSize - client->fileOffset; + + if (count > BUFFER_SEND_FILE_SIZE) { + count = BUFFER_SEND_FILE_SIZE; + } + + ret = fread(buffer, count, 1, client->file); + //printf("read = %d\n", count); + + if (ret == 1) { + if (addBuffer(client->sendBuffer, buffer, count) < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } + + client->fileOffset += count; + } else { + client->status = NET_STATUS_ZOMBIE; + } + } } -void -startDownServer() +void startDownServer() { - struct timeval tv; - fd_set readfds; - fd_set writefds; - int max_fd; - int ret; - int i; + struct timeval tv; + fd_set readfds; + fd_set writefds; + int max_fd; + int ret; + int i; - tv.tv_sec = 1; - tv.tv_usec = 0; - FD_ZERO(&readfds); - FD_ZERO(&writefds); + tv.tv_sec = 1; + tv.tv_usec = 0; + FD_ZERO(&readfds); + FD_ZERO(&writefds); - max_fd = sock_server_tcp->sock; + max_fd = sock_server_tcp->sock; - FD_SET(sock_server_tcp->sock, &readfds); + FD_SET(sock_server_tcp->sock, &readfds); - for (i = 0; i < listClient->count; i++) { - client_t *client; - int sock; + for (i = 0; i < listClient->count; i++) { + client_t *client; + int sock; - client = (client_t *) listClient->list[i]; + client = (client_t *) listClient->list[i]; - if (client->status != NET_STATUS_ZOMBIE) { - sock = client->socket->sock; + if (client->status != NET_STATUS_ZOMBIE) { + sock = client->socket->sock; - if (sock > max_fd) { - max_fd = sock; - } + if (sock > max_fd) { + max_fd = sock; + } - FD_SET(sock, &readfds); + FD_SET(sock, &readfds); - if (getBufferSize(client->sendBuffer) > 0) { - FD_SET(sock, &writefds); - } - } - } + if (getBufferSize(client->sendBuffer) > 0) { + FD_SET(sock, &writefds); + } + } + } - ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); - if (ret > 0) { - if (FD_ISSET(sock_server_tcp->sock, &readfds)) { - eventNewClient(sock_server_tcp); - } + if (ret > 0) { + if (FD_ISSET(sock_server_tcp->sock, &readfds)) { + eventNewClient(sock_server_tcp); + } - for (i = 0; i < listClient->count; i++) { - client_t *client; - int sock; + for (i = 0; i < listClient->count; i++) { + client_t *client; + int sock; - client = (client_t *) listClient->list[i]; - sock = client->socket->sock; + client = (client_t *) listClient->list[i]; + sock = client->socket->sock; - if (FD_ISSET(sock, &readfds)) { - eventRecvClient(client); - } + if (FD_ISSET(sock, &readfds)) { + eventRecvClient(client); + } - if (FD_ISSET(sock, &writefds)) { - eventSendClient(client); - } - } - } + if (FD_ISSET(sock, &writefds)) { + eventSendClient(client); + } + } + } - for (i = 0; i < listClient->count; i++) { - client_t *client; + for (i = 0; i < listClient->count; i++) { + client_t *client; - client = (client_t *) listClient->list[i]; + client = (client_t *) listClient->list[i]; - if (client->status == NET_STATUS_ZOMBIE) { - delListItem(listClient, i, destroyClient); - i--; - continue; - } + if (client->status == NET_STATUS_ZOMBIE) { + delListItem(listClient, i, destroyClient); + i--; + continue; + } - eventClient(client); - } + eventClient(client); + } } -void -quitDownServer() +void quitDownServer() { - closeTcpSocket(sock_server_tcp); - destroyListItem(listClient, destroyClient); + closeTcpSocket(sock_server_tcp); + destroyListItem(listClient, destroyClient); } -int -isFillPath(const char *path) +int isFillPath(const char *path) { - return 0; + return 0; } -int -main(int argc, char **argv) +int main(int argc, char **argv) { - signal(SIGPIPE, SIG_IGN); + signal(SIGPIPE, SIG_IGN); - initDownServer("127.0.0.1", 2200); + initDownServer("127.0.0.1", 2200); - while (1) { - startDownServer(); - } + while (1) { + startDownServer(); + } } diff --git a/src/modules/modAI.c b/src/modules/modAI.c index b29e141..003c65e 100644 --- a/src/modules/modAI.c +++ b/src/modules/modAI.c @@ -13,321 +13,308 @@ #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; +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 *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; + + 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) +static void eventTuxAI(tux_t * tux) { - arena_t *arena; - tux_t *rivalTux; + arena_t *arena; + tux_t *rivalTux; - list_t *listAlternative; - list_t *listDst; - list_t *listFork; + list_t *listAlternative; + list_t *listDst; + list_t *listFork; - int x, y, w, h; - int rival_x, rival_y; - int i, index; + 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; + 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); + export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h); + //printf("tux AI %d %d\n", x, y); - arena = export_fce->fce_getCurrentArena(); + arena = export_fce->fce_getCurrentArena(); - rivalTux = findOtherTux(arena->spaceTux); + rivalTux = findOtherTux(arena->spaceTux); - if (rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE) { - return; - } + if (rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE) { + return; + } - listAlternative = newList(); - listDst = newList(); - listFork = newList(); + listAlternative = newList(); + listDst = newList(); + listFork = newList(); - shotTux(arena, tux, rivalTux); + 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); + 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))); + 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 = -1; + while (1) { + alternative_t *this; - index++; - if (index < 0 || index >= listAlternative->count) { + index++; + if (index < 0 || index >= listAlternative->count) { - int j; + int j; - //printf("listFork->count = %d\n", listFork->count); + //printf("listFork->count = %d\n", listFork->count); - for (j = 0; j < listFork->count; j++) { - addList(listAlternative, listFork->list[j]); - } + for (j = 0; j < listFork->count; j++) { + addList(listAlternative, listFork->list[j]); + } - listDoEmpty(listFork); + listDoEmpty(listFork); - index = 0; - } + index = 0; + } - if (listAlternative->count == 0) { - break; - } + if (listAlternative->count == 0) { + break; + } - this = (alternative_t *) listAlternative->list[index]; + this = (alternative_t *) listAlternative->list[index]; - if (++countDo == 100) - break; + if (++countDo == 100) + break; - if (this->step > 100) { - delListItem(listAlternative, index, destroyAlternative); - countLimit++; - index--; - continue; - } + if (this->step > 100) { + delListItem(listAlternative, index, destroyAlternative); + countLimit++; + index--; + continue; + } - moveAlternative(this, w * 2); + 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_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); + 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; - } + 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++; + 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; - } + 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); @@ -336,45 +323,43 @@ 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; - - if (lastEvent == 0) { - lastEvent = export_fce->fce_getMyTime(); - } + 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(); + 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++ ) { @@ -390,29 +375,25 @@ 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/modBasic.c b/src/modules/modBasic.c index bf37fcb..7bddd7a 100644 --- a/src/modules/modBasic.c +++ b/src/modules/modBasic.c @@ -13,71 +13,63 @@ #include "space.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" +# include "interface.h" +# include "image.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif 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/modMove.c b/src/modules/modMove.c index 854b5bb..55366ff 100644 --- a/src/modules/modMove.c +++ b/src/modules/modMove.c @@ -14,248 +14,235 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" +# include "interface.h" +# include "image.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# 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) +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) + 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/modPipe.c b/src/modules/modPipe.c index fef68a1..9049731 100644 --- a/src/modules/modPipe.c +++ b/src/modules/modPipe.c @@ -13,36 +13,35 @@ #include "space.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" +# include "interface.h" +# include "image.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif -typedef struct pipe_struct -{ - int x; // poloha steny - int y; +typedef struct pipe_struct { + 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 + 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); + int src_y, int dist_x, int dist_y, int dist_w, + int dist_h); static export_fce_t *export_fce; @@ -50,310 +49,290 @@ 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) +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) + 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; + pipe_t *new; #ifndef PUBLIC_SERVER - assert(img != NULL); + 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; + 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->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 -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) { - 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/modTeleport.c b/src/modules/modTeleport.c index 3c136cb..492de5b 100644 --- a/src/modules/modTeleport.c +++ b/src/modules/modTeleport.c @@ -13,28 +13,27 @@ #include "space.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" +# include "interface.h" +# include "image.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif -typedef struct teleport_struct -{ - int id; +typedef struct teleport_struct { + 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 + image_t *img; //obrazok #endif } teleport_t; @@ -45,217 +44,207 @@ 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); + 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) +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) + teleport_t *newTeleport(int x, int y, int w, int h, int layer) #endif { - static int last_id = 0; + static int last_id = 0; - teleport_t *new; + teleport_t *new; #ifndef PUBLIC_SERVER - assert(img != NULL); + assert(img != NULL); #endif - new = malloc(sizeof(teleport_t)); - assert(new != NULL); + 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; + 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->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) { - 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 @@ -263,111 +252,104 @@ init(export_fce_t * 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) +action_eventteleportshot(space_t * space, teleport_t * teleport, 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; + } - moveShotFromTeleport(shot, teleport, spaceTeleport); + 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); + 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); + teleportTux(tux, teleport); } 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/modWall.c b/src/modules/modWall.c index 66954d9..41b7e04 100644 --- a/src/modules/modWall.c +++ b/src/modules/modWall.c @@ -13,31 +13,30 @@ #include "space.h" #ifndef PUBLIC_SERVER -#include "interface.h" -#include "image.h" +# include "interface.h" +# include "image.h" #endif #ifdef PUBLIC_SERVER -#include "publicServer.h" +# include "publicServer.h" #endif -typedef struct wall_struct -{ - int id; +typedef struct wall_struct { + 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 + image_t *img; //obrazok #endif } wall_t; @@ -52,319 +51,298 @@ static space_t *spaceImgWall; 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) +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) + 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; + static int last_id = 0; + wall_t *new; #ifndef PUBLIC_SERVER - assert(img != NULL); + 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 -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 -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); + 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); + 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 = 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 (shot->gun == GUN_BOMBBALL) { - if (export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - export_fce->fce_boundBombBall(shot); - } + if (author != NULL && + author->bonus == BONUS_GHOST && author->bonus_time > 0) { + return; + } - return; - } + if (shot->gun == GUN_BOMBBALL) { + if (export_fce->fce_getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + export_fce->fce_boundBombBall(shot); + } - //delObjectFromSpaceWithObject(arena->spaceShot, shot, export_fce->fce_destroyShot); - shot->del = TRUE; + 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); + 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); + destroySpaceWithObject(spaceWall, destroyWall); #ifndef PUBLIC_SERVER - destroySpace(spaceImgWall); + destroySpace(spaceImgWall); #endif - destroyList(listWall); - return 0; + destroyList(listWall); + return 0; } diff --git a/src/net/dns.c b/src/net/dns.c index 44bb6ae..2167a52 100644 --- a/src/net/dns.c +++ b/src/net/dns.c @@ -1,27 +1,26 @@ #ifndef __WIN32__ -# include <sys/socket.h> -# include <netinet/in.h> -# include <arpa/inet.h> -# include <netdb.h> +# include <sys/socket.h> +# include <netinet/in.h> +# include <arpa/inet.h> +# include <netdb.h> #else -# include <windows.h> -# include <wininet.h> +# include <windows.h> +# include <wininet.h> #endif #include <string.h> #include "main.h" -char * -getIPFormDNS(char *domain) +char *getIPFormDNS(char *domain) { - struct hostent *host; + struct hostent *host; - host = gethostbyname(domain); + host = gethostbyname(domain); - if (host == NULL || host->h_addr_list[0] == NULL) { - return NULL; - } + if (host == NULL || host->h_addr_list[0] == NULL) { + return NULL; + } - return strdup(inet_ntoa(*((struct in_addr *) host->h_addr_list[0]))); + return strdup(inet_ntoa(*((struct in_addr *) host->h_addr_list[0]))); } diff --git a/src/net/dns.h b/src/net/dns.h index a2cd997..281a056 100644 --- a/src/net/dns.h +++ b/src/net/dns.h @@ -1,7 +1,7 @@ #ifndef DNS_H -#define DNS_H +# define DNS_H extern char *getIPFormDNS(char *domain); diff --git a/src/net/tcp.c b/src/net/tcp.c index 44a080b..3737b1f 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -21,366 +21,344 @@ #include "tcp.h" -sock_tcp_t * -newSockTcp(int proto) +sock_tcp_t *newSockTcp(int proto) { - sock_tcp_t *new; + sock_tcp_t *new; - new = malloc(sizeof(sock_tcp_t)); - memset(new, 0, sizeof(sock_tcp_t)); - new->proto = proto; + new = malloc(sizeof(sock_tcp_t)); + memset(new, 0, sizeof(sock_tcp_t)); + new->proto = proto; - return new; + return new; } -void -destroySockTcp(sock_tcp_t * p) +void destroySockTcp(sock_tcp_t * p) { - assert(p != NULL); - free(p); + assert(p != NULL); + free(p); } -sock_tcp_t * -bindTcpSocket(char *address, int port, int proto) +sock_tcp_t *bindTcpSocket(char *address, int port, int proto) { - sock_tcp_t *new; - unsigned long param_setsock = 1; - int len; - int ret; + sock_tcp_t *new; + unsigned long param_setsock = 1; + int len; + int ret; - assert(port > 0 && port < 65535); + assert(port > 0 && port < 65535); - new = newSockTcp(proto); - ret = -1; // no Warnnings + new = newSockTcp(proto); + ret = -1; // no Warnnings - assert(new != NULL); - - if (new->proto == PROTO_TCPv4) { - new->sock = socket(AF_INET, SOCK_STREAM, 0); - } + assert(new != NULL); + if (new->proto == PROTO_TCPv4) { + new->sock = socket(AF_INET, SOCK_STREAM, 0); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_TCPv6) { - new->sock = socket(AF_INET6, SOCK_STREAM, 0); - } + if (new->proto == PROTO_TCPv6) { + new->sock = socket(AF_INET6, SOCK_STREAM, 0); + } #endif - if (new->sock < 0) { - fprintf(stderr, _("Unable to create socket when connecting!\n")); - destroySockTcp(new); - return NULL; - } - - setsockopt(new->sock, SOL_SOCKET, SO_REUSEADDR, (char *) ¶m_setsock, - sizeof(param_setsock)); + if (new->sock < 0) { + fprintf(stderr, _("Unable to create socket when connecting!\n")); + destroySockTcp(new); + return NULL; + } - if (new->proto == PROTO_TCPv4) { - new->sockAddr.sin_family = AF_INET; - inet_pton(AF_INET, address, &(new->sockAddr.sin_addr)); - new->sockAddr.sin_port = htons(port); + setsockopt(new->sock, SOL_SOCKET, SO_REUSEADDR, (char *) ¶m_setsock, + sizeof(param_setsock)); - len = sizeof(new->sockAddr); - ret = bind(new->sock, (struct sockaddr *) &new->sockAddr, len); - } + if (new->proto == PROTO_TCPv4) { + new->sockAddr.sin_family = AF_INET; + inet_pton(AF_INET, address, &(new->sockAddr.sin_addr)); + new->sockAddr.sin_port = htons(port); + len = sizeof(new->sockAddr); + ret = bind(new->sock, (struct sockaddr *) &new->sockAddr, len); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_TCPv6) { - new->sockAddr6.sin6_family = AF_INET6; - //new->sockAddr.sin_addr.s_addr = htonl(INADDR_ANY); - inet_pton(AF_INET6, address, &(new->sockAddr6.sin6_addr)); - new->sockAddr6.sin6_port = htons(port); - - len = sizeof(new->sockAddr6); - ret = bind(new->sock, (struct sockaddr *) &new->sockAddr6, len); - } + if (new->proto == PROTO_TCPv6) { + new->sockAddr6.sin6_family = AF_INET6; + //new->sockAddr.sin_addr.s_addr = htonl(INADDR_ANY); + inet_pton(AF_INET6, address, &(new->sockAddr6.sin6_addr)); + new->sockAddr6.sin6_port = htons(port); + + len = sizeof(new->sockAddr6); + ret = bind(new->sock, (struct sockaddr *) &new->sockAddr6, len); + } #endif - if (ret < 0) { - fprintf(stderr, _("Unable to bint to port: %d\n"), port); - destroySockTcp(new); - return NULL; - } + if (ret < 0) { + fprintf(stderr, _("Unable to bint to port: %d\n"), port); + destroySockTcp(new); + return NULL; + } - listen(new->sock, 5); + listen(new->sock, 5); - return new; + return new; } -sock_tcp_t * -getTcpNewClient(sock_tcp_t * p) +sock_tcp_t *getTcpNewClient(sock_tcp_t * p) { - sock_tcp_t *new; - int client_len; + sock_tcp_t *new; + int client_len; - assert(p != NULL); - assert(p->sock >= 0); + assert(p != NULL); + assert(p->sock >= 0); - new = newSockTcp(p->proto); + new = newSockTcp(p->proto); - if (new->proto == PROTO_TCPv4) { - client_len = sizeof(new->sockAddr); - - new->sock = accept(p->sock, (struct sockaddr *) &new->sockAddr, - (socklen_t *) & client_len); - } + if (new->proto == PROTO_TCPv4) { + client_len = sizeof(new->sockAddr); + new->sock = accept(p->sock, (struct sockaddr *) &new->sockAddr, + (socklen_t *) & client_len); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_TCPv6) { - client_len = sizeof(new->sockAddr6); + if (new->proto == PROTO_TCPv6) { + client_len = sizeof(new->sockAddr6); - new->sock = accept(p->sock, (struct sockaddr *) &new->sockAddr6, - (socklen_t *) & client_len); - } + new->sock = accept(p->sock, (struct sockaddr *) &new->sockAddr6, + (socklen_t *) & client_len); + } #endif - if (new->sock < 0) { - //printf("XXX\n"); - destroySockTcp(new); - return NULL; - } + if (new->sock < 0) { + //printf("XXX\n"); + destroySockTcp(new); + return NULL; + } - return new; + return new; } -void -getSockTcpIp(sock_tcp_t * p, char *str_ip, int len) +void getSockTcpIp(sock_tcp_t * p, char *str_ip, int len) { - assert(p != NULL); - assert(str_ip != NULL); - + assert(p != NULL); + assert(str_ip != NULL); - if (p->proto == PROTO_TCPv4) { - inet_ntop(AF_INET, &(p->sockAddr.sin_addr), str_ip, len); - strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr)); - //printf("strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr));\n"); - } + if (p->proto == PROTO_TCPv4) { + inet_ntop(AF_INET, &(p->sockAddr.sin_addr), str_ip, len); + strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr)); + //printf("strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr));\n"); + } #ifdef SUPPORT_IPv6 - if (p->proto == PROTO_TCPv6) { - inet_ntop(AF_INET6, &(p->sockAddr6.sin6_addr), str_ip, len); - } + if (p->proto == PROTO_TCPv6) { + inet_ntop(AF_INET6, &(p->sockAddr6.sin6_addr), str_ip, len); + } #endif } -int -getSockTcpPort(sock_tcp_t * p) +int getSockTcpPort(sock_tcp_t * p) { - assert(p != NULL); - - if (p->proto == PROTO_TCPv4) { - return htons(p->sockAddr.sin_port); - } + assert(p != NULL); + if (p->proto == PROTO_TCPv4) { + return htons(p->sockAddr.sin_port); + } #ifdef SUPPORT_IPv6 - if (p->proto == PROTO_TCPv6) { - return htons(p->sockAddr6.sin6_port); - } + if (p->proto == PROTO_TCPv6) { + return htons(p->sockAddr6.sin6_port); + } #endif - assert(!_("Bad IP proto!")); + assert(!_("Bad IP proto!")); - return -1; + return -1; } -sock_tcp_t * -connectTcpSocket(char *ip, int port, int proto) +sock_tcp_t *connectTcpSocket(char *ip, int port, int proto) { - sock_tcp_t *new; - int len; - int ret; - - assert(ip != NULL); - assert(port > 0 && port < 65535); + sock_tcp_t *new; + int len; + int ret; - new = newSockTcp(proto); - ret = -1; // no Warnnings + assert(ip != NULL); + assert(port > 0 && port < 65535); - if (new->proto == PROTO_TCPv4) { - new->sock = socket(AF_INET, SOCK_STREAM, 0); - } + new = newSockTcp(proto); + ret = -1; // no Warnnings + if (new->proto == PROTO_TCPv4) { + new->sock = socket(AF_INET, SOCK_STREAM, 0); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_TCPv6) { - new->sock = socket(AF_INET6, SOCK_STREAM, 0); - } + if (new->proto == PROTO_TCPv6) { + new->sock = socket(AF_INET6, SOCK_STREAM, 0); + } #endif - if (new->sock < 0) { - fprintf(stderr, _("Unable to create TCP socket!\n")); - destroySockTcp(new); - return NULL; - } + if (new->sock < 0) { + fprintf(stderr, _("Unable to create TCP socket!\n")); + destroySockTcp(new); + return NULL; + } - if (new->proto == PROTO_TCPv4) { - new->sockAddr.sin_family = AF_INET; - new->sockAddr.sin_addr.s_addr = inet_addr(ip); - new->sockAddr.sin_port = htons(port); - - len = sizeof(new->sockAddr); - ret = connect(new->sock, (struct sockaddr *) &new->sockAddr, len); - } + if (new->proto == PROTO_TCPv4) { + new->sockAddr.sin_family = AF_INET; + new->sockAddr.sin_addr.s_addr = inet_addr(ip); + new->sockAddr.sin_port = htons(port); + len = sizeof(new->sockAddr); + ret = connect(new->sock, (struct sockaddr *) &new->sockAddr, len); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_TCPv6) { - new->sockAddr6.sin6_family = AF_INET6; - inet_pton(AF_INET6, ip, &(new->sockAddr6.sin6_addr)); - new->sockAddr6.sin6_port = htons(port); - - len = sizeof(new->sockAddr6); - ret = connect(new->sock, (struct sockaddr *) &new->sockAddr6, len); - } + if (new->proto == PROTO_TCPv6) { + new->sockAddr6.sin6_family = AF_INET6; + inet_pton(AF_INET6, ip, &(new->sockAddr6.sin6_addr)); + new->sockAddr6.sin6_port = htons(port); + + len = sizeof(new->sockAddr6); + ret = connect(new->sock, (struct sockaddr *) &new->sockAddr6, len); + } #endif - if (ret < 0) { - fprintf(stderr, "Unable to connect on: \"%s\" port: \"%d\"\n", ip, - port); - destroySockTcp(new); - return NULL; - } + if (ret < 0) { + fprintf(stderr, "Unable to connect on: \"%s\" port: \"%d\"\n", ip, + port); + destroySockTcp(new); + return NULL; + } - return new; + return new; } -int -disableNagle(sock_tcp_t * p) +int disableNagle(sock_tcp_t * p) { - int flag = 1; + int flag = 1; - int result; + int result; - result = setsockopt(p->sock, /* socket affected */ - IPPROTO_TCP, /* set option at TCP level */ - TCP_NODELAY, /* name of option */ - (char *) &flag, /* the cast is historical cruft */ - sizeof(int)); /* length of option value */ + result = setsockopt(p->sock, /* socket affected */ + IPPROTO_TCP, /* set option at TCP level */ + TCP_NODELAY, /* name of option */ + (char *) &flag, /* the cast is historical cruft */ + sizeof(int)); /* length of option value */ #if 0 - if (result < 0) { - printf("disabled nagle error\n"); - } - else { - printf("disabled nagle OK\n"); - } + if (result < 0) { + printf("disabled nagle error\n"); + } else { + printf("disabled nagle OK\n"); + } #endif - return result; + return result; } -int -setTcpSockNonBlock(sock_tcp_t * p) +int setTcpSockNonBlock(sock_tcp_t * p) { - /* Set to nonblocking socket mode */ + /* Set to nonblocking socket mode */ #ifndef __WIN32__ - int oldFlag; - - oldFlag = fcntl(p->sock, F_GETFL, 0); + int oldFlag; - if (fcntl(p->sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - //printf("error setTcpSockNonBlock\n"); - return -1; - } + oldFlag = fcntl(p->sock, F_GETFL, 0); - //printf("setTcpSockNonBlock OK\n"); + if (fcntl(p->sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + //printf("error setTcpSockNonBlock\n"); + return -1; + } + //printf("setTcpSockNonBlock OK\n"); #else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(p->sock, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(p->sock, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } #endif - return 0; + return 0; } -int -readTcpSocket(sock_tcp_t * p, void *address, int len) +int readTcpSocket(sock_tcp_t * p, void *address, int len) { - assert(p != NULL); - assert(address != NULL); + assert(p != NULL); + assert(address != NULL); - return read(p->sock, address, len); + return read(p->sock, address, len); } -int -writeTcpSocket(sock_tcp_t * p, void *address, int len) +int writeTcpSocket(sock_tcp_t * p, void *address, int len) { - assert(p != NULL); - assert(address != NULL); + assert(p != NULL); + assert(address != NULL); - return write(p->sock, address, len); + return write(p->sock, address, len); } -void -closeTcpSocket(sock_tcp_t * p) +void closeTcpSocket(sock_tcp_t * p) { - assert(p != NULL); + assert(p != NULL); - close(p->sock); - destroySockTcp(p); + close(p->sock); + destroySockTcp(p); } #if 0 -#define MAX_CLIENTS 32 -#define BUF_SIZE 512 +# define MAX_CLIENTS 32 +# define BUF_SIZE 512 -int -main(int argc, char **argv) +int main(int argc, char **argv) { - sock_tcp_t *sock; - sock_tcp_t *client[MAX_CLIENTS]; - int count_client; - int changed, i; - struct pollfd *tmp; + sock_tcp_t *sock; + sock_tcp_t *client[MAX_CLIENTS]; + int count_client; + int changed, i; + struct pollfd *tmp; - sock = bindTcpSocket("127.0.0.1", 2200, PROTO_TCPv4); - disableNagle(sock); - count_client = 0; + sock = bindTcpSocket("127.0.0.1", 2200, PROTO_TCPv4); + disableNagle(sock); + count_client = 0; - for (;;) { - tmp = malloc((count_client + 1) * sizeof(struct pollfd)); + for (;;) { + tmp = malloc((count_client + 1) * sizeof(struct pollfd)); - tmp[0].fd = sock->sock; - tmp[0].events = POLLIN; - tmp[0].revents = 0; + tmp[0].fd = sock->sock; + tmp[0].events = POLLIN; + tmp[0].revents = 0; - for (i = 0; i < count_client; i++) { - tmp[1 + i].fd = client[i]->sock; - tmp[1 + i].events = POLLIN; - tmp[1 + i].revents = 0; - } + for (i = 0; i < count_client; i++) { + tmp[1 + i].fd = client[i]->sock; + tmp[1 + i].events = POLLIN; + tmp[1 + i].revents = 0; + } - changed = poll(tmp, count_client + 1, 1000); + changed = poll(tmp, count_client + 1, 1000); - if (tmp[0].revents & POLLIN != 0) { - client[count_client] = getTcpNewClient(sock); - disableNagle(client[count_client]); - count_client++; - } + if (tmp[0].revents & POLLIN != 0) { + client[count_client] = getTcpNewClient(sock); + disableNagle(client[count_client]); + count_client++; + } - for (i = 0; i < count_client; i++) { - if (tmp[1 + i].revents & POLLIN != 0) { - char buf[BUF_SIZE]; - int ret; + for (i = 0; i < count_client; i++) { + if (tmp[1 + i].revents & POLLIN != 0) { + char buf[BUF_SIZE]; + int ret; - ret = read(client[i]->sock, buf, BUF_SIZE); + ret = read(client[i]->sock, buf, BUF_SIZE); - if (ret <= 0) { - closeTcpSocket(client[i]); + if (ret <= 0) { + closeTcpSocket(client[i]); - memmove(client + i, - client + (i + 1), - ((count_client - 1) - i) * sizeof(sock_tcp_t *)); + memmove(client + i, + client + (i + 1), + ((count_client - 1) - i) * sizeof(sock_tcp_t *)); - count_client--; - continue; - } + count_client--; + continue; + } - write(client[i]->sock, buf, ret); - } - } + write(client[i]->sock, buf, ret); + } + } - free(tmp); - } + free(tmp); + } } #endif diff --git a/src/net/tcp.h b/src/net/tcp.h index 4dcc5f4..88b2c4e 100644 --- a/src/net/tcp.h +++ b/src/net/tcp.h @@ -1,27 +1,26 @@ #ifndef MY_TCP_H -#define MY_TCP_H -#include "main.h" +# define MY_TCP_H +# include "main.h" -#include <sys/socket.h> -#include <netinet/in.h> -#include <netinet/tcp.h> +# include <sys/socket.h> +# include <netinet/in.h> +# include <netinet/tcp.h> -#define SUPPORT_IPv6 +# define SUPPORT_IPv6 -#define PROTO_TCPv4 0 -#define PROTO_TCPv6 1 +# define PROTO_TCPv4 0 +# define PROTO_TCPv6 1 -typedef struct struct_sock_tcp_t -{ - int sock; - int proto; +typedef struct struct_sock_tcp_t { + int sock; + int proto; - struct sockaddr_in sockAddr; -#ifdef SUPPORT_IPv6 - struct sockaddr_in6 sockAddr6; -#endif + struct sockaddr_in sockAddr; +# ifdef SUPPORT_IPv6 + struct sockaddr_in6 sockAddr6; +# endif } sock_tcp_t; extern sock_tcp_t *newSockTcp(int proto); diff --git a/src/net/udp.c b/src/net/udp.c index 62dbec7..99fa19e 100644 --- a/src/net/udp.c +++ b/src/net/udp.c @@ -1,14 +1,14 @@ #ifndef __WIN32__ -# include <sys/socket.h> -# include <sys/types.h> -# include <netinet/in.h> -# include <arpa/inet.h> -# include <netdb.h> +# include <sys/socket.h> +# include <sys/types.h> +# include <netinet/in.h> +# include <arpa/inet.h> +# include <netdb.h> #else -# include <windows.h> -# include <wininet.h> +# include <windows.h> +# include <wininet.h> #endif #include <unistd.h> @@ -26,389 +26,369 @@ #include "udp.h" -sock_udp_t * -newSockUdp(int proto) +sock_udp_t *newSockUdp(int proto) { - sock_udp_t *new; + sock_udp_t *new; - new = malloc(sizeof(sock_udp_t)); - memset(new, 0, sizeof(sock_udp_t)); - new->proto = proto; + new = malloc(sizeof(sock_udp_t)); + memset(new, 0, sizeof(sock_udp_t)); + new->proto = proto; - return new; + return new; } -void -destroySockUdp(sock_udp_t * p) +void destroySockUdp(sock_udp_t * p) { - assert(p != NULL); - free(p); + assert(p != NULL); + free(p); } -sock_udp_t * -bindUdpSocket(char *address, int port, int proto) +sock_udp_t *bindUdpSocket(char *address, int port, int proto) { - sock_udp_t *new; - int res = -1; // no warninng + sock_udp_t *new; + int res = -1; // no warninng - assert(port > 0 && port < 65535); + assert(port > 0 && port < 65535); - new = newSockUdp(proto); + new = newSockUdp(proto); - assert(new != NULL); - - if (new->proto == PROTO_UDPv4) { - new->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - } + assert(new != NULL); + if (new->proto == PROTO_UDPv4) { + new->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_UDPv6) { - new->sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); - } + if (new->proto == PROTO_UDPv6) { + new->sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + } #endif - if (new->sock < 0) { - fprintf(stderr, _("Unable to create socket when binding!\n")); - destroySockUdp(new); + if (new->sock < 0) { + fprintf(stderr, _("Unable to create socket when binding!\n")); + destroySockUdp(new); #ifdef __WIN32__ - WSACleanup(); + WSACleanup(); #endif - return NULL; - } - - memset(&(new->sockAddr), 0, sizeof(new->sockAddr)); + return NULL; + } - if (new->proto == PROTO_UDPv4) { - new->sockAddr.sin_family = AF_INET; - new->sockAddr.sin_port = htons(port); - new->sockAddr.sin_addr.s_addr = inet_addr(address); + memset(&(new->sockAddr), 0, sizeof(new->sockAddr)); - res = - bind(new->sock, (struct sockaddr *) &(new->sockAddr), - sizeof(new->sockAddr)); - } + if (new->proto == PROTO_UDPv4) { + new->sockAddr.sin_family = AF_INET; + new->sockAddr.sin_port = htons(port); + new->sockAddr.sin_addr.s_addr = inet_addr(address); + res = + bind(new->sock, (struct sockaddr *) &(new->sockAddr), + sizeof(new->sockAddr)); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_UDPv6) { - new->sockAddr6.sin6_family = AF_INET6; - new->sockAddr6.sin6_port = htons(port); - inet_pton(AF_INET6, address, &(new->sockAddr6.sin6_addr)); - - res = - bind(new->sock, (struct sockaddr *) &(new->sockAddr6), - sizeof(new->sockAddr6)); - } + if (new->proto == PROTO_UDPv6) { + new->sockAddr6.sin6_family = AF_INET6; + new->sockAddr6.sin6_port = htons(port); + inet_pton(AF_INET6, address, &(new->sockAddr6.sin6_addr)); + + res = + bind(new->sock, (struct sockaddr *) &(new->sockAddr6), + sizeof(new->sockAddr6)); + } #endif - if (res < 0) { - fprintf(stderr, _("Unable to set socket %s %d!\n"), address, port); - destroySockUdp(new); + if (res < 0) { + fprintf(stderr, _("Unable to set socket %s %d!\n"), address, port); + destroySockUdp(new); #ifdef __WIN32__ - WSACleanup(); + WSACleanup(); #endif - return NULL; - } + return NULL; + } - return new; + return new; } -sock_udp_t * -connectUdpSocket(char *address, int port, int proto) +sock_udp_t *connectUdpSocket(char *address, int port, int proto) { - sock_udp_t *new; + sock_udp_t *new; - assert(address != NULL); - assert(port > 0 && port < 65536); + assert(address != NULL); + assert(port > 0 && port < 65536); - new = newSockUdp(proto); + new = newSockUdp(proto); - assert(new != NULL); - - if (new->proto == PROTO_UDPv4) { - new->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - } + assert(new != NULL); + if (new->proto == PROTO_UDPv4) { + new->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_UDPv6) { - new->sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); - } + if (new->proto == PROTO_UDPv6) { + new->sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + } #endif - if (new->sock < 0) { - fprintf(stderr, _("Unable to create socket when connecting!\n")); - destroySockUdp(new); + if (new->sock < 0) { + fprintf(stderr, _("Unable to create socket when connecting!\n")); + destroySockUdp(new); #ifdef __WIN32__ - WSACleanup(); + WSACleanup(); #endif - return NULL; - } - - memset(&(new->sockAddr), 0, sizeof(new->sockAddr)); + return NULL; + } - if (new->proto == PROTO_UDPv4) { - new->sockAddr.sin_family = AF_INET; - new->sockAddr.sin_port = htons(port); - new->sockAddr.sin_addr.s_addr = inet_addr(address); - } + memset(&(new->sockAddr), 0, sizeof(new->sockAddr)); + if (new->proto == PROTO_UDPv4) { + new->sockAddr.sin_family = AF_INET; + new->sockAddr.sin_port = htons(port); + new->sockAddr.sin_addr.s_addr = inet_addr(address); + } #ifdef SUPPORT_IPv6 - if (new->proto == PROTO_UDPv6) { - new->sockAddr6.sin6_family = AF_INET6; - new->sockAddr6.sin6_port = htons(port); - inet_pton(AF_INET6, address, &(new->sockAddr6.sin6_addr)); - } + if (new->proto == PROTO_UDPv6) { + new->sockAddr6.sin6_family = AF_INET6; + new->sockAddr6.sin6_port = htons(port); + inet_pton(AF_INET6, address, &(new->sockAddr6.sin6_addr)); + } #endif - return new; + return new; } -int -setUdpSockNonBlock(sock_udp_t * p) +int setUdpSockNonBlock(sock_udp_t * p) { - /* Set to nonblocking socket mode */ + /* Set to nonblocking socket mode */ #ifndef __WIN32__ - int oldFlag; + int oldFlag; - oldFlag = fcntl(p->sock, F_GETFL, 0); + oldFlag = fcntl(p->sock, F_GETFL, 0); - if (fcntl(p->sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - return -1; - } + if (fcntl(p->sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } #else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(p->sock, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(p->sock, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } #endif - return 0; + return 0; } -int -readUdpSocket(sock_udp_t * src, sock_udp_t * dst, void *address, int len) +int readUdpSocket(sock_udp_t * src, sock_udp_t * dst, void *address, int len) { - int addrlen; - int size = -1; // no warninng + int addrlen; + int size = -1; // no warninng - assert(src != NULL); - assert(dst != NULL); - assert(address != NULL); + assert(src != NULL); + assert(dst != NULL); + assert(address != NULL); - if (dst->proto == PROTO_UDPv4) { - addrlen = sizeof(src->sockAddr); + if (dst->proto == PROTO_UDPv4) { + addrlen = sizeof(src->sockAddr); #ifndef __WIN32 - size = - recvfrom(src->sock, address, len, 0, - (struct sockaddr *) &dst->sockAddr, - (socklen_t *) & addrlen); + size = + recvfrom(src->sock, address, len, 0, + (struct sockaddr *) &dst->sockAddr, + (socklen_t *) & addrlen); #else - size = - recvfrom(src->sock, address, len, 0, - (struct sockaddr *) &dst->sockAddr, (int *) &addrlen); + size = + recvfrom(src->sock, address, len, 0, + (struct sockaddr *) &dst->sockAddr, (int *) &addrlen); #endif - } - + } #ifdef SUPPORT_IPv6 - if (dst->proto == PROTO_UDPv6) { - addrlen = sizeof(src->sockAddr6); + if (dst->proto == PROTO_UDPv6) { + addrlen = sizeof(src->sockAddr6); - size = recvfrom(src->sock, address, len, 0, - (struct sockaddr *) &dst->sockAddr6, - (socklen_t *) & addrlen); - } + size = recvfrom(src->sock, address, len, 0, + (struct sockaddr *) &dst->sockAddr6, + (socklen_t *) & addrlen); + } #endif - dst->sock = src->sock; + dst->sock = src->sock; - if (size < 0) { - char str_ip[STR_IP_SIZE]; + if (size < 0) { + char str_ip[STR_IP_SIZE]; - getSockUdpIp(dst, str_ip, STR_IP_SIZE); + getSockUdpIp(dst, str_ip, STR_IP_SIZE); - fprintf(stderr, _("Unable to read form socket %d %s %d!\n"), size, - str_ip, getSockUdpPort(dst)); + fprintf(stderr, _("Unable to read form socket %d %s %d!\n"), size, + str_ip, getSockUdpPort(dst)); #ifdef __WIN32__ - WSACleanup(); + WSACleanup(); #endif - return -1; - } + return -1; + } - return size; + return size; } -int -writeUdpSocket(sock_udp_t * src, sock_udp_t * dst, void *address, int len) +int writeUdpSocket(sock_udp_t * src, sock_udp_t * dst, void *address, int len) { - int addrlen; - int size = -1; // no warninng - - assert(src != NULL); - assert(dst != NULL); - assert(address != NULL); + int addrlen; + int size = -1; // no warninng - if (dst->proto == PROTO_UDPv4) { - addrlen = sizeof(src->sockAddr); + assert(src != NULL); + assert(dst != NULL); + assert(address != NULL); - size = - sendto(src->sock, address, len, 0, - (struct sockaddr *) &dst->sockAddr, addrlen); - } + if (dst->proto == PROTO_UDPv4) { + addrlen = sizeof(src->sockAddr); + size = + sendto(src->sock, address, len, 0, + (struct sockaddr *) &dst->sockAddr, addrlen); + } #ifdef SUPPORT_IPv6 - if (dst->proto == PROTO_UDPv6) { - addrlen = sizeof(src->sockAddr6); + if (dst->proto == PROTO_UDPv6) { + addrlen = sizeof(src->sockAddr6); - size = - sendto(src->sock, address, len, 0, - (struct sockaddr *) &dst->sockAddr6, addrlen); - } + size = + sendto(src->sock, address, len, 0, + (struct sockaddr *) &dst->sockAddr6, addrlen); + } #endif - if (size < 0) { - char str_ip[STR_IP_SIZE]; + if (size < 0) { + char str_ip[STR_IP_SIZE]; - getSockUdpIp(dst, str_ip, STR_IP_SIZE); + getSockUdpIp(dst, str_ip, STR_IP_SIZE); - fprintf(stderr, _("Unable to write on socket %d %s %d!\n"), size, - str_ip, getSockUdpPort(dst)); + fprintf(stderr, _("Unable to write on socket %d %s %d!\n"), size, + str_ip, getSockUdpPort(dst)); #ifdef __WIN32__ - WSACleanup(); + WSACleanup(); #endif - return -1; - } + return -1; + } - return size; + return size; } -void -getSockUdpIp(sock_udp_t * p, char *str_ip, int len) +void getSockUdpIp(sock_udp_t * p, char *str_ip, int len) { - assert(p != NULL); - assert(str_ip != NULL); + assert(p != NULL); + assert(str_ip != NULL); - if (p->proto == PROTO_UDPv4) { + if (p->proto == PROTO_UDPv4) { #ifndef __WIN32__ - inet_ntop(AF_INET, &(p->sockAddr.sin_addr), str_ip, len); + inet_ntop(AF_INET, &(p->sockAddr.sin_addr), str_ip, len); #else - strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr)); - //printf("strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr));\n"); + strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr)); + //printf("strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr));\n"); #endif - } - + } #ifdef SUPPORT_IPv6 - if (p->proto == PROTO_UDPv6) { - inet_ntop(AF_INET6, &(p->sockAddr6.sin6_addr), str_ip, len); - } + if (p->proto == PROTO_UDPv6) { + inet_ntop(AF_INET6, &(p->sockAddr6.sin6_addr), str_ip, len); + } #endif } -int -getSockUdpPort(sock_udp_t * p) +int getSockUdpPort(sock_udp_t * p) { - assert(p != NULL); - - if (p->proto == PROTO_UDPv4) { - return htons(p->sockAddr.sin_port); - } + assert(p != NULL); + if (p->proto == PROTO_UDPv4) { + return htons(p->sockAddr.sin_port); + } #ifdef SUPPORT_IPv6 - if (p->proto == PROTO_UDPv6) { - return htons(p->sockAddr6.sin6_port); - } + if (p->proto == PROTO_UDPv6) { + return htons(p->sockAddr6.sin6_port); + } #endif - assert(!_("Bad IP proto!")); + assert(!_("Bad IP proto!")); - return -1; + return -1; } -void -closeUdpSocket(sock_udp_t * p) +void closeUdpSocket(sock_udp_t * p) { - assert(p != NULL); + assert(p != NULL); #ifndef __WIN32__ - close(p->sock); + close(p->sock); #else - closesocket(p->sock); - //WSACleanup(); //kdyz ukoncime socket dobre neni treba cleanup + closesocket(p->sock); + //WSACleanup(); //kdyz ukoncime socket dobre neni treba cleanup #endif - destroySockUdp(p); + destroySockUdp(p); } #if 0 -static int -myWait(sock_udp_t * p) +static int myWait(sock_udp_t * p) { - fd_set readfds; - fd_set errorfds; - struct timeval tv; - int max_fd; + fd_set readfds; + fd_set errorfds; + struct timeval tv; + int max_fd; - tv.tv_sec = 1; - tv.tv_usec = 0; + tv.tv_sec = 1; + tv.tv_usec = 0; - FD_ZERO(&readfds); - FD_ZERO(&errorfds); - max_fd = p->sock; + FD_ZERO(&readfds); + FD_ZERO(&errorfds); + max_fd = p->sock; - FD_SET(p->sock, &readfds); - FD_SET(p->sock, &errorfds); + FD_SET(p->sock, &readfds); + FD_SET(p->sock, &errorfds); - select(max_fd + 1, &readfds, (fd_set *) 0, &errorfds, &tv); + select(max_fd + 1, &readfds, (fd_set *) 0, &errorfds, &tv); - if (FD_ISSET(p->sock, &readfds)) { - FD_CLR(p->sock, &readfds); - return 1; - } + if (FD_ISSET(p->sock, &readfds)) { + FD_CLR(p->sock, &readfds); + return 1; + } - return 0; + return 0; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - sock_udp_t *sock; - char buf[BUFSIZE]; - int ret; + sock_udp_t *sock; + char buf[BUFSIZE]; + int ret; - if (strcmp(argv[1], "s") == 0) { - sock_udp_t *cli; + if (strcmp(argv[1], "s") == 0) { + sock_udp_t *cli; - //sock = bindUdpSocket("::1", atoi(argv[2]), PROTO_UDPv6 ); - sock = bindUdpSocket("127.0.0.1", atoi(argv[2]), PROTO_UDPv4); + //sock = bindUdpSocket("::1", atoi(argv[2]), PROTO_UDPv6 ); + sock = bindUdpSocket("127.0.0.1", atoi(argv[2]), PROTO_UDPv4); - //cli = newSockUdp(PROTO_UDPv6); - cli = newSockUdp(PROTO_UDPv4); + //cli = newSockUdp(PROTO_UDPv6); + cli = newSockUdp(PROTO_UDPv4); - while (1) { - while (myWait(sock) == 0); + while (1) { + while (myWait(sock) == 0); - memset(buf, 0, BUFSIZE); - ret = readUdpSocket(sock, cli, buf, BUFSIZE); - writeUdpSocket(sock, cli, buf, ret); - } - } + memset(buf, 0, BUFSIZE); + ret = readUdpSocket(sock, cli, buf, BUFSIZE); + writeUdpSocket(sock, cli, buf, ret); + } + } - if (strcmp(argv[1], "c") == 0) { - //sock = connectUdpSocket("::1", atoi(argv[2]), PROTO_UDPv6); - sock = connectUdpSocket("127.0.0.1", atoi(argv[2]), PROTO_UDPv4); + if (strcmp(argv[1], "c") == 0) { + //sock = connectUdpSocket("::1", atoi(argv[2]), PROTO_UDPv6); + sock = connectUdpSocket("127.0.0.1", atoi(argv[2]), PROTO_UDPv4); - strcpy(buf, "Hello world !\n"); - writeUdpSocket(sock, sock, buf, strlen(buf)); + strcpy(buf, "Hello world !\n"); + writeUdpSocket(sock, sock, buf, strlen(buf)); - memset(buf, 0, BUFSIZE); - readUdpSocket(sock, sock, buf, BUFSIZE); + memset(buf, 0, BUFSIZE); + readUdpSocket(sock, sock, buf, BUFSIZE); - printf("buf = %s", buf); - //while(1)sleep(1); - closeUdpSocket(sock); - } + printf("buf = %s", buf); + //while(1)sleep(1); + closeUdpSocket(sock); + } - return 0; + return 0; } #endif diff --git a/src/net/udp.h b/src/net/udp.h index 827c1c8..97541c6 100644 --- a/src/net/udp.h +++ b/src/net/udp.h @@ -1,32 +1,31 @@ #ifndef MY_UDP -#ifndef __WIN32__ -# include <netinet/in.h> -#else -# include <windows.h> -# include <wininet.h> -#endif +# ifndef __WIN32__ +# include <netinet/in.h> +# else +# include <windows.h> +# include <wininet.h> +# endif -#define MY_UDP +# define MY_UDP -#ifndef __WIN32__ -#define SUPPORT_IPv6 -#endif +# ifndef __WIN32__ +# define SUPPORT_IPv6 +# endif -typedef struct struct_sock_udp_t -{ -#ifndef __WIN32__ - int sock; -#else - SOCKET sock; -#endif - int proto; +typedef struct struct_sock_udp_t { +# ifndef __WIN32__ + int sock; +# else + SOCKET sock; +# endif + int proto; -#ifdef SUPPORT_IPv6 - struct sockaddr_in6 sockAddr6; -#endif - struct sockaddr_in sockAddr; +# ifdef SUPPORT_IPv6 + struct sockaddr_in6 sockAddr6; +# endif + struct sockaddr_in sockAddr; } sock_udp_t; extern sock_udp_t *newSockUdp(int proto); @@ -35,9 +34,9 @@ extern sock_udp_t *bindUdpSocket(char *address, int port, int proto); extern sock_udp_t *connectUdpSocket(char *address, int port, int proto); extern int setUdpSockNonBlock(sock_udp_t * p); extern int readUdpSocket(sock_udp_t * src, sock_udp_t * dst, void *address, - int len); + int len); extern int writeUdpSocket(sock_udp_t * src, sock_udp_t * dst, void *address, - int len); + int len); extern void getSockUdpIp(sock_udp_t * p, char *str_ip, int len); extern int getSockUdpPort(sock_udp_t * p); extern void closeUdpSocket(sock_udp_t * p); diff --git a/src/screen/screen_analyze.c b/src/screen/screen_analyze.c index 0933e72..b52ca77 100644 --- a/src/screen/screen_analyze.c +++ b/src/screen/screen_analyze.c @@ -11,7 +11,7 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_mainMenu.h" @@ -31,166 +31,153 @@ static widget_t *widgetLabelMsg; static widget_t *button_ok; -static analyze_t * -newAnalyze(char *name, int score) +static analyze_t *newAnalyze(char *name, int score) { - analyze_t *new; + analyze_t *new; - new = malloc(sizeof(analyze_t)); - new->name = strdup(name); - new->score = score; + new = malloc(sizeof(analyze_t)); + new->name = strdup(name); + new->score = score; - return new; + return new; } -static void -destroyAnalyze(analyze_t * p) +static void destroyAnalyze(analyze_t * p) { - free(p->name); - free(p); + free(p->name); + free(p); } -void -startScreenAnalyze() +void startScreenAnalyze() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif } -void -drawScreenAnalyze() +void drawScreenAnalyze() { - widget_t *this; - int i; + widget_t *this; + int i; - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - for (i = 0; i < listWidgetLabelName->count; i++) { - this = (widget_t *) (listWidgetLabelName->list[i]); - drawWidgetLabel(this); - } + for (i = 0; i < listWidgetLabelName->count; i++) { + this = (widget_t *) (listWidgetLabelName->list[i]); + drawWidgetLabel(this); + } - for (i = 0; i < listWidgetLabelScore->count; i++) { - this = (widget_t *) (listWidgetLabelScore->list[i]); - drawWidgetLabel(this); - } + for (i = 0; i < listWidgetLabelScore->count; i++) { + this = (widget_t *) (listWidgetLabelScore->list[i]); + drawWidgetLabel(this); + } - drawWidgetLabel(widgetLabelMsg); - drawWidgetButton(button_ok); + drawWidgetLabel(widgetLabelMsg); + drawWidgetButton(button_ok); } -void -eventScreenAnalyze() +void eventScreenAnalyze() { - eventWidgetButton(button_ok); + eventWidgetButton(button_ok); } -void -stopScreenAnalyze() +void stopScreenAnalyze() { - destroyWidgetLabel(widgetLabelMsg); - widgetLabelMsg = - newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + destroyWidgetLabel(widgetLabelMsg); + widgetLabelMsg = + newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_ok) { - setScreen("mainMenu"); - } + if (button == button_ok) { + setScreen("mainMenu"); + } } -void -restartAnalyze() +void restartAnalyze() { - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - destroyListItem(listAnalyze, destroyAnalyze); + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + destroyListItem(listAnalyze, destroyAnalyze); - listWidgetLabelName = newList(); - listWidgetLabelScore = newList(); - listAnalyze = newList(); + listWidgetLabelName = newList(); + listWidgetLabelScore = newList(); + listAnalyze = newList(); } -void -addAnalyze(char *name, int score) +void addAnalyze(char *name, int score) { - addList(listAnalyze, newAnalyze(name, score)); + addList(listAnalyze, newAnalyze(name, score)); } -void -setMsgToAnalyze(char *msg) +void setMsgToAnalyze(char *msg) { - destroyWidgetLabel(widgetLabelMsg); - widgetLabelMsg = - newWidgetLabel(msg, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + destroyWidgetLabel(widgetLabelMsg); + widgetLabelMsg = + newWidgetLabel(msg, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); } -void -endAnalyze() +void endAnalyze() { - int i; + int i; - for (i = 0; i < listAnalyze->count; i++) { - analyze_t *this; - char *str; + for (i = 0; i < listAnalyze->count; i++) { + analyze_t *this; + char *str; - this = (analyze_t *) (listAnalyze->list[i]); + this = (analyze_t *) (listAnalyze->list[i]); - addList(listWidgetLabelName, newWidgetLabel(this->name, - 100, 200 + 20 * i, - WIDGET_LABEL_LEFT)); + addList(listWidgetLabelName, newWidgetLabel(this->name, + 100, 200 + 20 * i, + WIDGET_LABEL_LEFT)); - str = getString(this->score); + str = getString(this->score); - addList(listWidgetLabelScore, newWidgetLabel(str, - WINDOW_SIZE_X - 100, - 200 + 20 * i, - WIDGET_LABEL_RIGHT)); + addList(listWidgetLabelScore, newWidgetLabel(str, + WINDOW_SIZE_X - 100, + 200 + 20 * i, + WIDGET_LABEL_RIGHT)); - free(str); - } + free(str); + } } -void -initScreenAnalyze() +void initScreenAnalyze() { - image_t *image; + image_t *image; - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); - listWidgetLabelName = newList(); - listWidgetLabelScore = newList(); - listAnalyze = newList(); + listWidgetLabelName = newList(); + listWidgetLabelScore = newList(); + listAnalyze = newList(); - button_ok = - newWidgetButton("OK", WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 100, eventWidget); + button_ok = + newWidgetButton("OK", WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 100, eventWidget); - registerScreen(newScreen - ("analyze", startScreenAnalyze, eventScreenAnalyze, - drawScreenAnalyze, stopScreenAnalyze)); + registerScreen(newScreen + ("analyze", startScreenAnalyze, eventScreenAnalyze, + drawScreenAnalyze, stopScreenAnalyze)); - widgetLabelMsg = - newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + widgetLabelMsg = + newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); } -void -quitScreenAnalyze() +void quitScreenAnalyze() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - destroyListItem(listAnalyze, destroyAnalyze); + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + destroyListItem(listAnalyze, destroyAnalyze); - destroyWidgetButton(button_ok); - destroyWidgetLabel(widgetLabelMsg); + destroyWidgetButton(button_ok); + destroyWidgetLabel(widgetLabelMsg); } diff --git a/src/screen/screen_analyze.h b/src/screen/screen_analyze.h index 9894399..8f975b4 100644 --- a/src/screen/screen_analyze.h +++ b/src/screen/screen_analyze.h @@ -1,14 +1,13 @@ #ifndef SCREEN_ANALYZE_H -#define SCREEN_ANALYZE_H +# define SCREEN_ANALYZE_H -#include "main.h" +# include "main.h" -typedef struct analyze_struct -{ - char *name; - int score; +typedef struct analyze_struct { + char *name; + int score; } analyze_t; extern void startScreenAnalyze(); diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c index 4b82edf..edf222a 100644 --- a/src/screen/screen_browser.c +++ b/src/screen/screen_browser.c @@ -15,15 +15,15 @@ #ifndef __WIN32__ -#include <sys/socket.h> -#include <sys/select.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> +# include <sys/socket.h> +# include <sys/select.h> +# include <sys/types.h> +# include <netinet/in.h> +# include <arpa/inet.h> +# include <netdb.h> #else -#include <windows.h> -#include <wininet.h> +# include <windows.h> +# include <wininet.h> #endif #include <unistd.h> @@ -36,7 +36,7 @@ extern int errno; #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_gameType.h" @@ -73,662 +73,649 @@ static int RefreshServers(); static server_t *server_getcurr(); -void -startScreenBrowser() +void startScreenBrowser() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif - LoadServers(); + LoadServers(); } -void -drawScreenBrowser() +void drawScreenBrowser() { - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - drawWidgetLabel(label_server); - drawWidgetLabel(label_version); - drawWidgetLabel(label_address); - drawWidgetLabel(label_arena); - drawWidgetLabel(label_players); - drawWidgetLabel(label_ping); + drawWidgetLabel(label_server); + drawWidgetLabel(label_version); + drawWidgetLabel(label_address); + drawWidgetLabel(label_arena); + drawWidgetLabel(label_players); + drawWidgetLabel(label_ping); - drawWidgetSelect(select_server); + drawWidgetSelect(select_server); - drawWidgetButton(button_play); - drawWidgetButton(button_back); - drawWidgetButton(button_refresh); + drawWidgetButton(button_play); + drawWidgetButton(button_back); + drawWidgetButton(button_refresh); } -void -eventScreenBrowser() +void eventScreenBrowser() { - eventWidgetSelect(select_server); + eventWidgetSelect(select_server); - eventWidgetButton(button_play); - eventWidgetButton(button_back); - eventWidgetButton(button_refresh); + eventWidgetButton(button_play); + eventWidgetButton(button_back); + eventWidgetButton(button_refresh); } -void -stopScreenBrowser() +void stopScreenBrowser() { - unsigned i = 0; - server_t *server; + unsigned i = 0; + server_t *server; - //destroyListItem(select_server->list, free); - //select_server->list = newList(); - removeAllFromWidgetSelect(select_server); + //destroyListItem(select_server->list, free); + //select_server->list = newList(); + removeAllFromWidgetSelect(select_server); - while (1) { - i = 0; - for (server = server_list.next; server != &server_list; - server = server->next) { - server->next->prev = server->prev; - server->prev->next = server->next; + while (1) { + i = 0; + for (server = server_list.next; server != &server_list; + server = server->next) { + server->next->prev = server->prev; + server->prev->next = server->next; - if (server->name) - free(server->name); + if (server->name) + free(server->name); - if (server->version) - free(server->version); + if (server->version) + free(server->version); - if (server->arena) - free(server->arena); + if (server->arena) + free(server->arena); - free(server); + free(server); - i++; - break; - } + i++; + break; + } - if (!i) - return; - } + if (!i) + return; + } } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_play) { - server_t *server = server_getcurr(); + if (button == button_play) { + server_t *server = server_getcurr(); - if (!server) - return; + if (!server) + return; - /* server je offline */ - if (!server->state) - return; + /* server je offline */ + if (!server->state) + return; - struct in_addr srv; - srv.s_addr = server->ip; + struct in_addr srv; + srv.s_addr = server->ip; - char *address = (char *) inet_ntoa(srv); + char *address = (char *) inet_ntoa(srv); - setSettingGameType(NET_GAME_TYPE_CLIENT); - setSettingIP(address); - setSettingPort(server->port); + setSettingGameType(NET_GAME_TYPE_CLIENT); + setSettingIP(address); + setSettingPort(server->port); - setScreen("world"); - } + setScreen("world"); + } - if (button == button_back) { - setScreen("gameType"); - } + if (button == button_back) { + setScreen("gameType"); + } - if (button == button_refresh) { - RefreshServers(); - } + if (button == button_refresh) { + RefreshServers(); + } } -server_t * -server_getcurr() +server_t *server_getcurr() { - unsigned i = 0; - server_t *server; + unsigned i = 0; + server_t *server; - for (server = server_list.next; server != &server_list; - server = server->next) { - if (i == getWidgetSelectIndex(select_server)) - return server; + for (server = server_list.next; server != &server_list; + server = server->next) { + if (i == getWidgetSelectIndex(select_server)) + return server; - i++; - } + i++; + } - return 0; + return 0; } -int -server_getinfo(server_t * server) +int server_getinfo(server_t * server) { - struct sockaddr_in srv; - int mySocket; - - if ((mySocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { - return -1; - } + struct sockaddr_in srv; + int mySocket; + if ((mySocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { + return -1; + } #ifndef __WIN32__ - // Lets make socket non-blocking - int oldFlag = fcntl(mySocket, F_GETFL, 0); - if (fcntl(mySocket, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - return -1; - } + // Lets make socket non-blocking + int oldFlag = fcntl(mySocket, F_GETFL, 0); + if (fcntl(mySocket, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } #else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(mySocket, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(mySocket, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } #endif - struct timeval tv; + struct timeval tv; - fd_set myset; - FD_ZERO(&myset); - FD_SET(mySocket, &myset); + fd_set myset; + FD_ZERO(&myset); + FD_SET(mySocket, &myset); - tv.tv_sec = 2; - tv.tv_usec = 0; + tv.tv_sec = 2; + tv.tv_usec = 0; - srv.sin_family = AF_INET; - srv.sin_port = htons(server->port); - srv.sin_addr.s_addr = server->ip; + srv.sin_family = AF_INET; + srv.sin_port = htons(server->port); + srv.sin_addr.s_addr = server->ip; - if (connect(mySocket, (struct sockaddr *) &srv, sizeof(srv)) == -1) { + if (connect(mySocket, (struct sockaddr *) &srv, sizeof(srv)) == -1) { #ifndef __WIN32__ - if (errno != EINPROGRESS) - return -1; + if (errno != EINPROGRESS) + return -1; #else - if (WSAGetLastError() != WSAEWOULDBLOCK) { - WSACleanup(); - return -1; - } + if (WSAGetLastError() != WSAEWOULDBLOCK) { + WSACleanup(); + return -1; + } #endif - } + } - int ret = select(mySocket + 1, NULL, &myset, NULL, &tv); + int ret = select(mySocket + 1, NULL, &myset, NULL, &tv); - if (ret == -1) - return 0; + if (ret == -1) + return 0; - if (ret == 0) - return -2; + if (ret == 0) + return -2; - char request[8]; - memcpy(request, "status\n", 7); + char request[8]; + memcpy(request, "status\n", 7); - int r = send(mySocket, request, 7, 0); + int r = send(mySocket, request, 7, 0); - if (r == -1) - return -2; + if (r == -1) + return -2; - FD_ZERO(&myset); - FD_SET(mySocket, &myset); - tv.tv_sec = 1; - tv.tv_usec = 0; + FD_ZERO(&myset); + FD_SET(mySocket, &myset); + tv.tv_sec = 1; + tv.tv_usec = 0; - char *str = (char *) malloc(sizeof(char) * 257); + char *str = (char *) malloc(sizeof(char) * 257); - if (!str) - return -1; + if (!str) + return -1; - while (1) { - int sel = select(mySocket + 1, &myset, NULL, NULL, &tv); + while (1) { + int sel = select(mySocket + 1, &myset, NULL, NULL, &tv); - if (sel == 0) { - free(str); + if (sel == 0) { + free(str); #ifndef __WIN32__ - close(mySocket); + close(mySocket); #else - closesocket(mySocket); - WSACleanup(); + closesocket(mySocket); + WSACleanup(); #endif - return -2; - } + return -2; + } - if (sel == -1) { - free(str); + if (sel == -1) { + free(str); #ifndef __WIN32__ - close(mySocket); + close(mySocket); #else - closesocket(mySocket); - WSACleanup(); + closesocket(mySocket); + WSACleanup(); #endif - return -2; - } + return -2; + } - if ((ret = recv(mySocket, str, 256, 0)) == -1) { - free(str); + if ((ret = recv(mySocket, str, 256, 0)) == -1) { + free(str); #ifndef __WIN32__ - close(mySocket); + close(mySocket); #else - closesocket(mySocket); - WSACleanup(); + closesocket(mySocket); + WSACleanup(); #endif - return -1; - } + return -1; + } - if (ret > 0) - break; - } + if (ret > 0) + break; + } #ifndef __WIN32__ - close(mySocket); + close(mySocket); #else - closesocket(mySocket); - WSACleanup(); + closesocket(mySocket); + WSACleanup(); #endif - server->ping = 1000 - (tv.tv_usec / 1000); - /* - ["name: F\n"] >= svn82 - "version: svnX\n" - "clients: N\n" - "maxclients: M\n" - "uptime: D\n" - */ + server->ping = 1000 - (tv.tv_usec / 1000); + /* + ["name: F\n"] >= svn82 + "version: svnX\n" + "clients: N\n" + "maxclients: M\n" + "uptime: D\n" + */ - unsigned i = 0; + unsigned i = 0; - while (i < ret) { - if (str[i] == '\n') - str[i] = '\0'; + while (i < ret) { + if (str[i] == '\n') + str[i] = '\0'; - i++; - } + i++; + } - unsigned name = 0; + unsigned name = 0; - if (strstr(str, "name: ")) - name = 1; + if (strstr(str, "name: ")) + name = 1; - int len = 0; + int len = 0; - if (name) { - len = strlen(str); - if (!strncmp(str, "name: ", 6)) { - unsigned name_len = strlen(str + 6); - server->name = (char *) malloc(sizeof(char) * (name_len + 2)); + if (name) { + len = strlen(str); + if (!strncmp(str, "name: ", 6)) { + unsigned name_len = strlen(str + 6); + server->name = (char *) malloc(sizeof(char) * (name_len + 2)); - if (!server->name) - return 0; + if (!server->name) + return 0; - memcpy(server->name, str + 6, name_len + 1); - server->name[name_len + 1] = '\0'; - } - } + memcpy(server->name, str + 6, name_len + 1); + server->name[name_len + 1] = '\0'; + } + } - /* HACK */ - if (!name) - len = -1; + /* HACK */ + if (!name) + len = -1; - if (!strncmp(str + len + 1, "version: ", 9)) { - unsigned ver_len = strlen(str + len + 10); - server->version = (char *) malloc(sizeof(char) * (ver_len + 2)); + if (!strncmp(str + len + 1, "version: ", 9)) { + unsigned ver_len = strlen(str + len + 10); + server->version = (char *) malloc(sizeof(char) * (ver_len + 2)); - if (!server->version) - return 0; + if (!server->version) + return 0; - memcpy(server->version, str + len + 10, ver_len + 1); - server->version[ver_len + 1] = '\0'; - } + memcpy(server->version, str + len + 10, ver_len + 1); + server->version[ver_len + 1] = '\0'; + } - len += strlen(str + len + 1) + 1; + len += strlen(str + len + 1) + 1; - if (!strncmp(str + len + 1, "clients: ", 9)) - server->clients = atoi(str + len + 10); + if (!strncmp(str + len + 1, "clients: ", 9)) + server->clients = atoi(str + len + 10); - len += strlen(str + len + 1) + 1; + len += strlen(str + len + 1) + 1; - if (!strncmp(str + len + 1, "maxclients: ", 12)) - server->maxclients = atoi(str + len + 13); + if (!strncmp(str + len + 1, "maxclients: ", 12)) + server->maxclients = atoi(str + len + 13); - len += strlen(str + len + 1) + 1; + len += strlen(str + len + 1) + 1; - if (!strncmp(str + len + 1, "uptime: ", 8)) - server->uptime = atoi(str + len + 9); + if (!strncmp(str + len + 1, "uptime: ", 8)) + server->uptime = atoi(str + len + 9); - len += strlen(str + len + 1) + 1; + len += strlen(str + len + 1) + 1; - if (!strncmp(str + len + 1, "arena: ", 7)) { - unsigned arena_len = strlen(str + len + 9); - server->arena = (char *) malloc(sizeof(char) * (arena_len + 2)); + if (!strncmp(str + len + 1, "arena: ", 7)) { + unsigned arena_len = strlen(str + len + 9); + server->arena = (char *) malloc(sizeof(char) * (arena_len + 2)); - if (!server->arena) - return 0; + if (!server->arena) + return 0; - memcpy(server->arena, str + len + 8, arena_len + 1); - server->arena[arena_len + 1] = '\0'; - } + memcpy(server->arena, str + len + 8, arena_len + 1); + server->arena[arena_len + 1] = '\0'; + } - free(str); + free(str); - server->state = 1; + server->state = 1; - return 1; + return 1; } -static int -LoadServers() +static int LoadServers() // Get server list { #ifndef __WIN32__ - int s; + int s; #else - SOCKET s; + SOCKET s; #endif - char buf[1025]; + char buf[1025]; - /* TODO: dodelat TCP makro */ - struct sockaddr_in server; - char *master_server_ip; + /* TODO: dodelat TCP makro */ + struct sockaddr_in server; + char *master_server_ip; - master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); + master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); - //printf("master_server_ip = %s\n", master_server_ip); + //printf("master_server_ip = %s\n", master_server_ip); - if (master_server_ip == NULL) // master server is down - { - return -1; - } + if (master_server_ip == NULL) // master server is down + { + return -1; + } - server.sin_family = AF_INET; - server.sin_port = htons(NET_MASTER_PORT); - server.sin_addr.s_addr = inet_addr(master_server_ip); + server.sin_family = AF_INET; + server.sin_port = htons(NET_MASTER_PORT); + server.sin_addr.s_addr = inet_addr(master_server_ip); - free(master_server_ip); + free(master_server_ip); - if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) - return 0; + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) + return 0; #ifndef __WIN32__ - // Lets make socket non-blocking - int oldFlag = fcntl(s, F_GETFL, 0); - if (fcntl(s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - return -1; - } + // Lets make socket non-blocking + int oldFlag = fcntl(s, F_GETFL, 0); + if (fcntl(s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } #else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(s, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(s, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } #endif - if (connect(s, (struct sockaddr *) &server, sizeof(server)) == -1) { + if (connect(s, (struct sockaddr *) &server, sizeof(server)) == -1) { #ifndef __WIN32__ - if (errno != EINPROGRESS) - return -1; + if (errno != EINPROGRESS) + return -1; #else - if (WSAGetLastError() != WSAEWOULDBLOCK) { - WSACleanup(); - return -1; - } + if (WSAGetLastError() != WSAEWOULDBLOCK) { + WSACleanup(); + return -1; + } #endif - } + } - struct timeval tv; + struct timeval tv; - fd_set myset; + fd_set myset; - FD_ZERO(&myset); - FD_SET(s, &myset); + FD_ZERO(&myset); + FD_SET(s, &myset); - tv.tv_sec = 3; - tv.tv_usec = 0; + tv.tv_sec = 3; + tv.tv_usec = 0; - int ret = select(s + 1, NULL, &myset, NULL, &tv); + int ret = select(s + 1, NULL, &myset, NULL, &tv); - if (ret == -1) - return 0; + if (ret == -1) + return 0; - if (ret == 0) - return -2; + if (ret == 0) + return -2; - /* send request for server list */ - send(s, "l", 1, 0); + /* send request for server list */ + send(s, "l", 1, 0); - FD_ZERO(&myset); - FD_SET(s, &myset); + FD_ZERO(&myset); + FD_SET(s, &myset); - ret = select(s + 1, &myset, NULL, NULL, &tv); + ret = select(s + 1, &myset, NULL, NULL, &tv); - if (ret == -1) - return 0; + if (ret == -1) + return 0; - if (ret == 0) - return -2; + if (ret == 0) + return -2; - int len = recv(s, buf, 1024, 0); + int len = recv(s, buf, 1024, 0); #ifndef __WIN32__ - close(s); + close(s); #else - closesocket(s); - WSACleanup(); + closesocket(s); + WSACleanup(); #endif - if (len <= 0) - return 0; + if (len <= 0) + return 0; - unsigned i = 0; - char list[256]; + unsigned i = 0; + char list[256]; - struct in_addr srv; + struct in_addr srv; - typedef struct - { - unsigned port; - unsigned ip; - } response_head; + typedef struct { + unsigned port; + unsigned ip; + } response_head; - while (1) { - response_head *header = (response_head *) ((char *) buf + i); + while (1) { + response_head *header = (response_head *) ((char *) buf + i); - server_t *ctx; + server_t *ctx; - // alloc and init context - ctx = (server_t *) malloc(sizeof(server_t)); + // alloc and init context + ctx = (server_t *) malloc(sizeof(server_t)); - ctx->ip = header->ip; - ctx->port = header->port; - ctx->name = 0; - ctx->version = 0; - ctx->arena = 0; + ctx->ip = header->ip; + ctx->port = header->port; + ctx->name = 0; + ctx->version = 0; + ctx->arena = 0; - int ret = server_getinfo(ctx); + int ret = server_getinfo(ctx); - srv.s_addr = ctx->ip; + srv.s_addr = ctx->ip; - char *address = (char *) inet_ntoa(srv); + char *address = (char *) inet_ntoa(srv); - memset(list, ' ', 254); - list[255] = '\0'; + memset(list, ' ', 254); + list[255] = '\0'; - if (ret == 1) { - /*sprintf (list, "%s (%s) - %s:%d - %s - %d/%d - %dms", ctx->name ? ctx->name : "Unknown", ctx->version, address, ctx->port, - ctx->arena ? ctx->arena : "Unknown", ctx->clients, ctx->maxclients, ctx->ping); */ + if (ret == 1) { + /*sprintf (list, "%s (%s) - %s:%d - %s - %d/%d - %dms", ctx->name ? ctx->name : "Unknown", ctx->version, address, ctx->port, + ctx->arena ? ctx->arena : "Unknown", ctx->clients, ctx->maxclients, ctx->ping); */ - if (ctx->name) - memcpy(list, ctx->name, strlen(ctx->name)); - else - memcpy(list, "Unknown", 7); + if (ctx->name) + memcpy(list, ctx->name, strlen(ctx->name)); + else + memcpy(list, "Unknown", 7); - memcpy(list + 30, ctx->version, strlen(ctx->version)); + memcpy(list + 30, ctx->version, strlen(ctx->version)); - unsigned a_len = strlen(address); - memcpy(list + 38, address, a_len); - memcpy(list + 38 + a_len, ":", 1); + unsigned a_len = strlen(address); + memcpy(list + 38, address, a_len); + memcpy(list + 38 + a_len, ":", 1); - sprintf(buf, "%d", ctx->port); + sprintf(buf, "%d", ctx->port); - memcpy(list + 39 + a_len, buf, strlen(buf)); + memcpy(list + 39 + a_len, buf, strlen(buf)); - memcpy(list + 60, ctx->arena, strlen(ctx->arena)); + memcpy(list + 60, ctx->arena, strlen(ctx->arena)); - sprintf(buf, "%d/%d", ctx->clients, ctx->maxclients); + sprintf(buf, "%d/%d", ctx->clients, ctx->maxclients); - memcpy(list + 75, buf, strlen(buf)); + memcpy(list + 75, buf, strlen(buf)); - sprintf(buf, "%dms", ctx->ping); + sprintf(buf, "%dms", ctx->ping); - memcpy(list + 83, buf, strlen(buf)); - } + memcpy(list + 83, buf, strlen(buf)); + } - addToWidgetSelect(select_server, list); + addToWidgetSelect(select_server, list); - // add into list - ctx->next = &server_list; - ctx->prev = server_list.prev; - ctx->prev->next = ctx; - ctx->next->prev = ctx; + // add into list + ctx->next = &server_list; + ctx->prev = server_list.prev; + ctx->prev->next = ctx; + ctx->next->prev = ctx; - i += sizeof(response_head) + 1; + i += sizeof(response_head) + 1; - if (buf[i - 1] != '\n' || (i + 1) > len) - break; - } + if (buf[i - 1] != '\n' || (i + 1) > len) + break; + } - return 1; + return 1; } -static int -RefreshServers() +static int RefreshServers() { /* destroyListItem(select_server->list, free); select_server->list = newList(); */ - removeAllFromWidgetSelect(select_server); + removeAllFromWidgetSelect(select_server); - struct in_addr srv; + struct in_addr srv; - server_t *server; - for (server = server_list.next; server != &server_list; - server = server->next) { - if (server->name) - free(server->name); + server_t *server; + for (server = server_list.next; server != &server_list; + server = server->next) { + if (server->name) + free(server->name); - if (server->version) - free(server->version); + if (server->version) + free(server->version); - if (server->arena) - free(server->arena); + if (server->arena) + free(server->arena); - server->name = 0; - server->version = 0; - server->arena = 0; + server->name = 0; + server->version = 0; + server->arena = 0; - char list[256]; - char buf[32]; + char list[256]; + char buf[32]; - int ret = server_getinfo(server); + int ret = server_getinfo(server); - srv.s_addr = server->ip; + srv.s_addr = server->ip; - char *address = (char *) inet_ntoa(srv); + char *address = (char *) inet_ntoa(srv); - if (ret == 1) { - memset(list, ' ', 254); - list[255] = '\0'; + if (ret == 1) { + memset(list, ' ', 254); + list[255] = '\0'; - if (server->name) - memcpy(list, server->name, strlen(server->name)); - else - memcpy(list, "Unknown", 7); + if (server->name) + memcpy(list, server->name, strlen(server->name)); + else + memcpy(list, "Unknown", 7); - memcpy(list + 30, server->version, strlen(server->version)); + memcpy(list + 30, server->version, strlen(server->version)); - unsigned a_len = strlen(address); - memcpy(list + 38, address, a_len); - memcpy(list + 38 + a_len, ":", 1); + unsigned a_len = strlen(address); + memcpy(list + 38, address, a_len); + memcpy(list + 38 + a_len, ":", 1); - sprintf(buf, "%d", server->port); + sprintf(buf, "%d", server->port); - memcpy(list + 39 + a_len, buf, strlen(buf)); + memcpy(list + 39 + a_len, buf, strlen(buf)); - memcpy(list + 60, server->arena, strlen(server->arena)); + memcpy(list + 60, server->arena, strlen(server->arena)); - sprintf(buf, "%d/%d", server->clients, server->maxclients); + sprintf(buf, "%d/%d", server->clients, server->maxclients); - memcpy(list + 75, buf, strlen(buf)); + memcpy(list + 75, buf, strlen(buf)); - sprintf(buf, "%dms", server->ping); + sprintf(buf, "%dms", server->ping); - memcpy(list + 83, buf, strlen(buf)); - } + memcpy(list + 83, buf, strlen(buf)); + } - addToWidgetSelect(select_server, list); + addToWidgetSelect(select_server, list); - } + } - return 1; + return 1; } -void -initScreenBrowser() +void initScreenBrowser() { - image_t *image; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); - button_play = - newWidgetButton(_("Play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); - button_refresh = - newWidgetButton(_("Refresh"), WINDOW_SIZE_X / 2 - 50, - WINDOW_SIZE_Y - 100, eventWidget); - - label_server = newWidgetLabel(_("server"), 120, 145, WIDGET_LABEL_LEFT); - label_version = newWidgetLabel(_("version"), 290, 145, WIDGET_LABEL_LEFT); - label_address = newWidgetLabel(_("IP"), 400, 145, WIDGET_LABEL_LEFT); - label_arena = newWidgetLabel(_("arena"), 550, 145, WIDGET_LABEL_LEFT); - label_players = newWidgetLabel(_("clients"), 645, 145, WIDGET_LABEL_LEFT); - label_ping = newWidgetLabel(_("ping"), 720, 145, WIDGET_LABEL_LEFT); - - select_server = newWidgetSelect(50, label_server->y + 40, eventWidget); - - registerScreen(newScreen - ("browser", startScreenBrowser, eventScreenBrowser, - drawScreenBrowser, stopScreenBrowser)); - - server_list.next = &server_list; - server_list.prev = &server_list; + image_t *image; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); + button_play = + newWidgetButton(_("Play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); + button_refresh = + newWidgetButton(_("Refresh"), WINDOW_SIZE_X / 2 - 50, + WINDOW_SIZE_Y - 100, eventWidget); + + label_server = newWidgetLabel(_("server"), 120, 145, WIDGET_LABEL_LEFT); + label_version = newWidgetLabel(_("version"), 290, 145, WIDGET_LABEL_LEFT); + label_address = newWidgetLabel(_("IP"), 400, 145, WIDGET_LABEL_LEFT); + label_arena = newWidgetLabel(_("arena"), 550, 145, WIDGET_LABEL_LEFT); + label_players = newWidgetLabel(_("clients"), 645, 145, WIDGET_LABEL_LEFT); + label_ping = newWidgetLabel(_("ping"), 720, 145, WIDGET_LABEL_LEFT); + + select_server = newWidgetSelect(50, label_server->y + 40, eventWidget); + + registerScreen(newScreen + ("browser", startScreenBrowser, eventScreenBrowser, + drawScreenBrowser, stopScreenBrowser)); + + server_list.next = &server_list; + server_list.prev = &server_list; } -void -quitScreenBrowser() +void quitScreenBrowser() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_play); - destroyWidgetButton(button_back); - destroyWidgetButton(button_refresh); + destroyWidgetButton(button_play); + destroyWidgetButton(button_back); + destroyWidgetButton(button_refresh); - destroyWidgetLabel(label_server); - destroyWidgetLabel(label_version); - destroyWidgetLabel(label_address); - destroyWidgetLabel(label_arena); - destroyWidgetLabel(label_players); - destroyWidgetLabel(label_ping); + destroyWidgetLabel(label_server); + destroyWidgetLabel(label_version); + destroyWidgetLabel(label_address); + destroyWidgetLabel(label_arena); + destroyWidgetLabel(label_players); + destroyWidgetLabel(label_ping); - destroyWidgetSelect(select_server); + destroyWidgetSelect(select_server); } diff --git a/src/screen/screen_browser.h b/src/screen/screen_browser.h index 28bbd4e..e810e58 100644 --- a/src/screen/screen_browser.h +++ b/src/screen/screen_browser.h @@ -1,26 +1,25 @@ #ifndef SCREEN_BROWSER_H -#define SCREEN_BROWSER_H +# define SCREEN_BROWSER_H -typedef struct server_context -{ - struct server_context *next, *prev; +typedef struct server_context { + struct server_context *next, *prev; - unsigned char state; + unsigned char state; - unsigned char ping; + unsigned char ping; - unsigned ip; - unsigned port; + unsigned ip; + unsigned port; - char *name; + char *name; - char *version; - unsigned char clients; - unsigned char maxclients; - unsigned uptime; - char *arena; + char *version; + unsigned char clients; + unsigned char maxclients; + unsigned uptime; + char *arena; } server_t; diff --git a/src/screen/screen_choiceArena.c b/src/screen/screen_choiceArena.c index 8bc12a2..c269f62 100644 --- a/src/screen/screen_choiceArena.c +++ b/src/screen/screen_choiceArena.c @@ -11,7 +11,7 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_mainMenu.h" @@ -31,168 +31,157 @@ static widget_t *button_back; static list_t *listWidgetButtonimage; static arenaFile_t *currentArena; -void -startScreenChoiceArena() +void startScreenChoiceArena() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif } -void -drawScreenChoiceArena() +void drawScreenChoiceArena() { - int i; + int i; - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - drawWidgetButton(button_play); - drawWidgetButton(button_back); + drawWidgetButton(button_play); + drawWidgetButton(button_back); - for (i = 0; i < listWidgetButtonimage->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetButtonimage->list[i]; - drawWidgetButtonimage(this); - } + for (i = 0; i < listWidgetButtonimage->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetButtonimage->list[i]; + drawWidgetButtonimage(this); + } } -void -eventScreenChoiceArena() +void eventScreenChoiceArena() { - int i; + int i; - eventWidgetButton(button_play); - eventWidgetButton(button_back); + eventWidgetButton(button_play); + eventWidgetButton(button_back); - for (i = 0; i < listWidgetButtonimage->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetButtonimage->list[i]; - eventWidgetButtonimage(this); - } + for (i = 0; i < listWidgetButtonimage->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetButtonimage->list[i]; + eventWidgetButtonimage(this); + } } -void -stopScreenChoiceArena() +void stopScreenChoiceArena() { } -static void -eventWidgetButtonImage(void *p) +static void eventWidgetButtonImage(void *p) { - widget_t *buttonimage; - int i; + widget_t *buttonimage; + int i; - buttonimage = (widget_t *) (p); + buttonimage = (widget_t *) (p); - for (i = 0; i < listWidgetButtonimage->count; i++) { - widget_t *this; + for (i = 0; i < listWidgetButtonimage->count; i++) { + widget_t *this; - this = (widget_t *) (listWidgetButtonimage->list[i]); + this = (widget_t *) (listWidgetButtonimage->list[i]); - if (buttonimage == this) { - setWidgetButtonimageActive(this, TRUE); - currentArena = getArenaFile(i); - } - else { - setWidgetButtonimageActive(this, FALSE); - } - } + if (buttonimage == this) { + setWidgetButtonimageActive(this, TRUE); + currentArena = getArenaFile(i); + } else { + setWidgetButtonimageActive(this, FALSE); + } + } } -arenaFile_t * -getChoiceArena() +arenaFile_t *getChoiceArena() { - return currentArena; + return currentArena; } -void -setChoiceArena(arenaFile_t * arenaFile) +void setChoiceArena(arenaFile_t * arenaFile) { - widget_t *widget_buttonimage; - int id; + widget_t *widget_buttonimage; + int id; - id = getArenaFileID(arenaFile); - currentArena = arenaFile; + id = getArenaFileID(arenaFile); + currentArena = arenaFile; - if (id >= 0) { - widget_buttonimage = (widget_t *) listWidgetButtonimage->list[id]; - setWidgetButtonimageActive(widget_buttonimage, TRUE); - } + if (id >= 0) { + widget_buttonimage = (widget_t *) listWidgetButtonimage->list[id]; + setWidgetButtonimageActive(widget_buttonimage, TRUE); + } } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_play) { - setScreen("world"); - } + if (button == button_play) { + setScreen("world"); + } - if (button == button_back) { - setScreen("gameType"); - } + if (button == button_back) { + setScreen("gameType"); + } } -void -initScreenChoiceArena() +void initScreenChoiceArena() { - image_t *image; - int i; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); - button_play = - newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); - - listWidgetButtonimage = newList(); - currentArena = NULL; - - for (i = 0; i < getArenaCount(); i++) { - widget_t *widget_buttonimage; - arenaFile_t *arenaFile; - int x, y; - - arenaFile = getArenaFile(i); - //image = addImageData(getArenaImage(i), IMAGE_NO_ALPHA, "none", IMAGE_GROUP_BASE); - image = loadImageFromArena(arenaFile, - getArenaImage(arenaFile), - IMAGE_GROUP_BASE, "none", IMAGE_NO_ALPHA); - - x = 100 + 200 * (i - 3 * (i / 3)); - y = 150 + 200 * (i / 3); - - widget_buttonimage = newWidgetButtonimage(image, - x, y, - eventWidgetButtonImage); + image_t *image; + int i; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); + button_play = + newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); + + listWidgetButtonimage = newList(); + currentArena = NULL; + + for (i = 0; i < getArenaCount(); i++) { + widget_t *widget_buttonimage; + arenaFile_t *arenaFile; + int x, y; + + arenaFile = getArenaFile(i); + //image = addImageData(getArenaImage(i), IMAGE_NO_ALPHA, "none", IMAGE_GROUP_BASE); + image = loadImageFromArena(arenaFile, + getArenaImage(arenaFile), + IMAGE_GROUP_BASE, "none", IMAGE_NO_ALPHA); + + x = 100 + 200 * (i - 3 * (i / 3)); + y = 150 + 200 * (i / 3); + + widget_buttonimage = newWidgetButtonimage(image, + x, y, + eventWidgetButtonImage); /* if( i == choiceArenaId ) { widget_buttonimage->active = 1; } */ - addList(listWidgetButtonimage, widget_buttonimage); - } + addList(listWidgetButtonimage, widget_buttonimage); + } - registerScreen(newScreen - ("chiceArena", startScreenChoiceArena, - eventScreenChoiceArena, drawScreenChoiceArena, - stopScreenChoiceArena)); + registerScreen(newScreen + ("chiceArena", startScreenChoiceArena, + eventScreenChoiceArena, drawScreenChoiceArena, + stopScreenChoiceArena)); } -void -quitScreenChoiceArena() +void quitScreenChoiceArena() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_play); - destroyWidgetButton(button_back); + destroyWidgetButton(button_play); + destroyWidgetButton(button_back); - destroyListItem(listWidgetButtonimage, destroyWidgetButtonimage); + destroyListItem(listWidgetButtonimage, destroyWidgetButtonimage); } diff --git a/src/screen/screen_choiceArena.h b/src/screen/screen_choiceArena.h index 7203065..dbe12de 100644 --- a/src/screen/screen_choiceArena.h +++ b/src/screen/screen_choiceArena.h @@ -1,13 +1,13 @@ #ifndef SCREEN_CHOICE_ARENA -#define SCREEN_CHOICE_ARENA +# define SCREEN_CHOICE_ARENA -#include "main.h" -#include "arenaFile.h" +# include "main.h" +# include "arenaFile.h" -#define SCREENSHOT_ARENA_WIDTH 160 -#define SCREENSHOT_ARENA_HEIGHT 107 +# define SCREENSHOT_ARENA_WIDTH 160 +# define SCREENSHOT_ARENA_HEIGHT 107 extern void drawScreenChoiceArena(); extern void eventScreenChoiceArena(); diff --git a/src/screen/screen_credits.c b/src/screen/screen_credits.c index 90f1d10..e3edabf 100644 --- a/src/screen/screen_credits.c +++ b/src/screen/screen_credits.c @@ -11,7 +11,7 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_credits.h" @@ -28,134 +28,125 @@ static textFile_t *textFile; static int offset; static int creditExists; -void -startScreenCredits() +void startScreenCredits() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif - offset = 0; + offset = 0; } -void -drawScreenCredits() +void drawScreenCredits() { - int i; + int i; - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - drawWidgetButton(button_back); + drawWidgetButton(button_back); - for (i = 0; i < listWidgetLabel->count; i++) { - int z; + for (i = 0; i < listWidgetLabel->count; i++) { + int z; - widget_t *this; - this = (widget_t *) listWidgetLabel->list[i]; + widget_t *this; + this = (widget_t *) listWidgetLabel->list[i]; - z = this->y; - this->y += offset; + z = this->y; + this->y += offset; - if (this->y > SCREEN_CREDITS_OFFSET_MIN - && this->y < SCREEN_CREDITS_OFFSET_MAX) { - drawWidgetLabel(this); - } + if (this->y > SCREEN_CREDITS_OFFSET_MIN + && this->y < SCREEN_CREDITS_OFFSET_MAX) { + drawWidgetLabel(this); + } - this->y = z; - } + this->y = z; + } } -void -eventScreenCredits() +void eventScreenCredits() { - eventWidgetButton(button_back); + eventWidgetButton(button_back); - offset -= SCREEN_CREDITS_OFFSET_SPEED; + offset -= SCREEN_CREDITS_OFFSET_SPEED; - if (offset < SCREEN_CREDITS_OFFSET_RESTART) { - offset = 0; - } - - //printf("offset = %d\n", offset); + if (offset < SCREEN_CREDITS_OFFSET_RESTART) { + offset = 0; + } + //printf("offset = %d\n", offset); } -void -stopScreenCredits() +void stopScreenCredits() { } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_back) { - setScreen("mainMenu"); - } + if (button == button_back) { + setScreen("mainMenu"); + } } -void -initScreenCredits() +void initScreenCredits() { - image_t *image; - int i; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 80, eventWidget); - - listWidgetLabel = newList(); - - if (tryExistFile(PATH_DOC SCREEN_CREDITS_FILE) == 0) { - creditExists = 1; - textFile = loadTextFile(PATH_DOC SCREEN_CREDITS_FILE); - for (i = 0; i < textFile->text->count; i++) { - widget_t *label; - char *line; - line = (char *) textFile->text->list[i]; - label = - newWidgetLabel(line, WINDOW_SIZE_X / 2 - WINDOW_SIZE_X / 4, - (WINDOW_SIZE_Y - 100) + i * 20, - WIDGET_LABEL_LEFT); - - addList(listWidgetLabel, label); - } - } - else { - for (i = 0; i < 5; i++) { - creditExists = 0; - widget_t *label; - char line[STR_SIZE]; - sprintf(line, _("Credit file not found... %s/%s"), PATH_DOC, - SCREEN_CREDITS_FILE); - label = - newWidgetLabel(line, WINDOW_SIZE_X / 2, - (WINDOW_SIZE_Y - 100) + i * 20, - WIDGET_LABEL_CENTER); - - addList(listWidgetLabel, label); - } - } - - registerScreen(newScreen - ("credits", startScreenCredits, eventScreenCredits, - drawScreenCredits, stopScreenCredits)); + image_t *image; + int i; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 80, eventWidget); + + listWidgetLabel = newList(); + + if (tryExistFile(PATH_DOC SCREEN_CREDITS_FILE) == 0) { + creditExists = 1; + textFile = loadTextFile(PATH_DOC SCREEN_CREDITS_FILE); + for (i = 0; i < textFile->text->count; i++) { + widget_t *label; + char *line; + line = (char *) textFile->text->list[i]; + label = + newWidgetLabel(line, WINDOW_SIZE_X / 2 - WINDOW_SIZE_X / 4, + (WINDOW_SIZE_Y - 100) + i * 20, + WIDGET_LABEL_LEFT); + + addList(listWidgetLabel, label); + } + } else { + for (i = 0; i < 5; i++) { + creditExists = 0; + widget_t *label; + char line[STR_SIZE]; + sprintf(line, _("Credit file not found... %s/%s"), PATH_DOC, + SCREEN_CREDITS_FILE); + label = + newWidgetLabel(line, WINDOW_SIZE_X / 2, + (WINDOW_SIZE_Y - 100) + i * 20, + WIDGET_LABEL_CENTER); + + addList(listWidgetLabel, label); + } + } + + registerScreen(newScreen + ("credits", startScreenCredits, eventScreenCredits, + drawScreenCredits, stopScreenCredits)); } -void -quitScreenCredits() +void quitScreenCredits() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_back); - destroyListItem(listWidgetLabel, destroyWidgetLabel); - if (creditExists) { - destroyTextFile(textFile); - } + destroyWidgetButton(button_back); + destroyListItem(listWidgetLabel, destroyWidgetLabel); + if (creditExists) { + destroyTextFile(textFile); + } } diff --git a/src/screen/screen_credits.h b/src/screen/screen_credits.h index 37ec3eb..37c25f3 100644 --- a/src/screen/screen_credits.h +++ b/src/screen/screen_credits.h @@ -1,14 +1,14 @@ #ifndef SCREEN_CREDITS_H -#define SCREEN_CREDITS_H +# define SCREEN_CREDITS_H -#define SCREEN_CREDITS_FILE "AUTHORS" +# define SCREEN_CREDITS_FILE "AUTHORS" -#define SCREEN_CREDITS_OFFSET_MIN 130 -#define SCREEN_CREDITS_OFFSET_MAX WINDOW_SIZE_Y-120 -#define SCREEN_CREDITS_OFFSET_RESTART -1000 -#define SCREEN_CREDITS_OFFSET_SPEED 2 +# define SCREEN_CREDITS_OFFSET_MIN 130 +# define SCREEN_CREDITS_OFFSET_MAX WINDOW_SIZE_Y-120 +# define SCREEN_CREDITS_OFFSET_RESTART -1000 +# define SCREEN_CREDITS_OFFSET_SPEED 2 extern void startScreenCredits(); extern void drawScreenCredits(); diff --git a/src/screen/screen_downArena.c b/src/screen/screen_downArena.c index 19c7b6e..0ff0c7b 100644 --- a/src/screen/screen_downArena.c +++ b/src/screen/screen_downArena.c @@ -50,367 +50,347 @@ static int fileOffset; static my_time_t timeSendMsg; static int countSendMsg; -static void -setStatusString(char *s) +static void setStatusString(char *s) { - //printf("status -> %s\n", s); - destroyWidgetLabel(label_status); - label_status = - newWidgetLabel(s, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + //printf("status -> %s\n", s); + destroyWidgetLabel(label_status); + label_status = + newWidgetLabel(s, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); } -static void -connectToDownServer() +static void connectToDownServer() { - char status[STR_SIZE]; - char msg[STR_PROTO_SIZE]; + char status[STR_SIZE]; + char msg[STR_PROTO_SIZE]; - sock_server_tcp = - connectTcpSocket(getSettingIP(), getSettingPort(), PROTO_TCPv4); + sock_server_tcp = + connectTcpSocket(getSettingIP(), getSettingPort(), PROTO_TCPv4); - if (sock_server_tcp == NULL) { - sprintf(status, "I do not connect to %s %d TCP down server", - getSettingIP(), getSettingPort()); - setStatusString(status); - return; - } + if (sock_server_tcp == NULL) { + sprintf(status, "I do not connect to %s %d TCP down server", + getSettingIP(), getSettingPort()); + setStatusString(status); + return; + } - setTcpSockNonBlock(sock_server_tcp); + setTcpSockNonBlock(sock_server_tcp); - recvBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); - sendBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); - status_tcp_socket = DOWN_SERVER_STATUS_OK; + recvBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); + sendBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); + status_tcp_socket = DOWN_SERVER_STATUS_OK; - file = NULL; - countSendMsg = 0; - timeSendMsg = getMyTime(); + file = NULL; + countSendMsg = 0; + timeSendMsg = getMyTime(); - sprintf(msg, "GETARENA %s\n", arenaNetName); + sprintf(msg, "GETARENA %s\n", arenaNetName); - addBuffer(sendBuffer, msg, strlen(msg)); + addBuffer(sendBuffer, msg, strlen(msg)); - sprintf(status, "Connect to %s %d TCP down server", getSettingIP(), - getSettingPort()); - setStatusString(status); + sprintf(status, "Connect to %s %d TCP down server", getSettingIP(), + getSettingPort()); + setStatusString(status); } -static void -closeConnectFromDownServer() +static void closeConnectFromDownServer() { - closeTcpSocket(sock_server_tcp); - destroyBuffer(recvBuffer); - destroyBuffer(sendBuffer); - sock_server_tcp = NULL; - recvBuffer = NULL; - sendBuffer = NULL; + closeTcpSocket(sock_server_tcp); + destroyBuffer(recvBuffer); + destroyBuffer(sendBuffer); + sock_server_tcp = NULL; + recvBuffer = NULL; + sendBuffer = NULL; } -static void -sendStatusToGameServer() +static void sendStatusToGameServer() { - char *msg = "status\n"; - - if (countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS) { - char status[STR_SIZE]; - sprintf(status, "Game server %s %d is down", getSettingIP(), - getSettingPort()); - setStatusString(status); - return; - } - - timeSendMsg = getMyTime(); - countSendMsg++; - printf("countSendMsg = %d\n", countSendMsg++); - - if (writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < - 0) { - char status[STR_SIZE]; - sprintf(status, "I do not send message to %s %d UDP game server", - getSettingIP(), getSettingPort()); - setStatusString(status); - } + char *msg = "status\n"; + + if (countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS) { + char status[STR_SIZE]; + sprintf(status, "Game server %s %d is down", getSettingIP(), + getSettingPort()); + setStatusString(status); + return; + } + + timeSendMsg = getMyTime(); + countSendMsg++; + printf("countSendMsg = %d\n", countSendMsg++); + + if (writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0) { + char status[STR_SIZE]; + sprintf(status, "I do not send message to %s %d UDP game server", + getSettingIP(), getSettingPort()); + setStatusString(status); + } } -void -startScreenDownArena() +void startScreenDownArena() { - char status[STR_SIZE]; + char status[STR_SIZE]; - strcpy(str_status, "none"); - memset(arenaNetName, 0, STR_SIZE); + strcpy(str_status, "none"); + memset(arenaNetName, 0, STR_SIZE); - sock_server_udp = - connectUdpSocket(getSettingIP(), getSettingPort(), PROTO_UDPv4); + sock_server_udp = + connectUdpSocket(getSettingIP(), getSettingPort(), PROTO_UDPv4); - if (sock_server_udp == NULL) { - sprintf(status, "I do not connect to %s %d UDP game server", - getSettingIP(), getSettingPort()); - setStatusString(status); - return; - } + if (sock_server_udp == NULL) { + sprintf(status, "I do not connect to %s %d UDP game server", + getSettingIP(), getSettingPort()); + setStatusString(status); + return; + } - setUdpSockNonBlock(sock_server_udp); + setUdpSockNonBlock(sock_server_udp); - sprintf(status, "Connect to %s %d UDP game server", getSettingIP(), - getSettingPort()); - setStatusString(status); + sprintf(status, "Connect to %s %d UDP game server", getSettingIP(), + getSettingPort()); + setStatusString(status); - sendStatusToGameServer(); + sendStatusToGameServer(); } -void -drawScreenDownArena() +void drawScreenDownArena() { - drawWidgetImage(image_backgorund); - drawWidgetLabel(label_status); - drawWidgetButton(button_back); + drawWidgetImage(image_backgorund); + drawWidgetLabel(label_status); + drawWidgetButton(button_back); } -static void -proto_ok(char *line) +static void proto_ok(char *line) { - //printf("line = %s\n", line); - fileSize = atoi(line + 3); - fileOffset = 0; + //printf("line = %s\n", line); + fileSize = atoi(line + 3); + fileOffset = 0; - sprintf(path, "%s/%s.zip", getHomeDirector(), arenaNetName); - //printf("path = %s\n", path); - file = fopen(path, "wb"); + sprintf(path, "%s/%s.zip", getHomeDirector(), arenaNetName); + //printf("path = %s\n", path); + file = fopen(path, "wb"); } -static void -proto_err(char *line) +static void proto_err(char *line) { - //printf("line = %s\n", line); - setStatusString(line + 4); - closeConnectFromDownServer(); + //printf("line = %s\n", line); + setStatusString(line + 4); + closeConnectFromDownServer(); } -static void -eventProto(char *line) +static void eventProto(char *line) { - if (strncmp(line, "OK", 2) == 0) { - proto_ok(line); - } + if (strncmp(line, "OK", 2) == 0) { + proto_ok(line); + } - if (strncmp(line, "ERR", 3) == 0) { - proto_err(line); - } + if (strncmp(line, "ERR", 3) == 0) { + proto_err(line); + } } -static int -downArenaFile() +static int downArenaFile() { - char status[STR_SIZE]; - void *data; - int len; + char status[STR_SIZE]; + void *data; + int len; - len = getBufferSize(recvBuffer); - data = getBufferData(recvBuffer); - cutBuffer(recvBuffer, len); + len = getBufferSize(recvBuffer); + data = getBufferData(recvBuffer); + cutBuffer(recvBuffer, len); - fwrite(data, len, 1, file); - fileOffset += len; + fwrite(data, len, 1, file); + fileOffset += len; - sprintf(status, "I down %d / %d", fileOffset, fileSize); - setStatusString(status); + sprintf(status, "I down %d / %d", fileOffset, fileSize); + setStatusString(status); - return len; + return len; } -static int -eventRecvBuffer() +static int eventRecvBuffer() { - char buffer[STR_PROTO_SIZE]; - char line[STR_PROTO_SIZE]; - int ret; + char buffer[STR_PROTO_SIZE]; + char line[STR_PROTO_SIZE]; + int ret; - memset(buffer, 0, STR_PROTO_SIZE); + memset(buffer, 0, STR_PROTO_SIZE); - ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE - 1); - //if (ret <= 0) printf("readTcpSocket = %d\n", ret); + ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE - 1); + //if (ret <= 0) printf("readTcpSocket = %d\n", ret); - if (ret < 0) { - return -1; - } + if (ret < 0) { + return -1; + } - if (addBuffer(recvBuffer, buffer, ret) < 0) { - char status[STR_SIZE]; - sprintf(status, "Error -- recv buffer is full"); - setStatusString(status); - closeConnectFromDownServer(); - return -1; - } + if (addBuffer(recvBuffer, buffer, ret) < 0) { + char status[STR_SIZE]; + sprintf(status, "Error -- recv buffer is full"); + setStatusString(status); + closeConnectFromDownServer(); + return -1; + } - if (file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0) { - eventProto(line); - return ret; - } + if (file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0) { + eventProto(line); + return ret; + } - if (file != NULL) { - return downArenaFile(); - } + if (file != NULL) { + return downArenaFile(); + } - return -1; + return -1; } -static int -eventSendBuffer() +static int eventSendBuffer() { - void *data; - int len; - int res; + void *data; + int len; + int res; - len = getBufferSize(sendBuffer); + len = getBufferSize(sendBuffer); - if (len == 0) { - return -1; - } + if (len == 0) { + return -1; + } - data = getBufferData(sendBuffer); + data = getBufferData(sendBuffer); - res = writeTcpSocket(sock_server_tcp, data, len); + res = writeTcpSocket(sock_server_tcp, data, len); - if (res < 0) { - return -1; - } + if (res < 0) { + return -1; + } - cutBuffer(sendBuffer, res); - return res; + cutBuffer(sendBuffer, res); + return res; } -static void -readArenaFromStatus() +static void readArenaFromStatus() { - const char *str_arena = "arena: "; + const char *str_arena = "arena: "; - char *offset_begin; - char *offset_end; + char *offset_begin; + char *offset_end; - offset_begin = strstr(str_status, str_arena); + offset_begin = strstr(str_status, str_arena); - if (offset_begin != NULL) { - offset_begin += strlen(str_arena); - offset_end = strstr(offset_begin, "\n"); + if (offset_begin != NULL) { + offset_begin += strlen(str_arena); + offset_end = strstr(offset_begin, "\n"); - if (offset_end != NULL) { - closeUdpSocket(sock_server_udp); - sock_server_udp = NULL; - strncpy(arenaNetName, offset_begin, offset_end - offset_begin); + if (offset_end != NULL) { + closeUdpSocket(sock_server_udp); + sock_server_udp = NULL; + strncpy(arenaNetName, offset_begin, offset_end - offset_begin); - if (getArenaFileFormNetName(arenaNetName) != NULL) { - setScreen("world"); - return; - } + if (getArenaFileFormNetName(arenaNetName) != NULL) { + setScreen("world"); + return; + } - connectToDownServer(); + connectToDownServer(); - printf("arenaNetName = >>%s<<\n", arenaNetName); - } - } + printf("arenaNetName = >>%s<<\n", arenaNetName); + } + } } -static void -eventStatus() +static void eventStatus() { - if (getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT) { - sendStatusToGameServer(); - } - - if (readUdpSocket - (sock_server_udp, sock_server_udp, str_status, - STR_PROTO_SIZE - 1) > 0) { - //printf("str_status = %s\n", str_status); - readArenaFromStatus(); - } + if (getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT) { + sendStatusToGameServer(); + } + + if (readUdpSocket + (sock_server_udp, sock_server_udp, str_status, + STR_PROTO_SIZE - 1) > 0) { + //printf("str_status = %s\n", str_status); + readArenaFromStatus(); + } } -void -eventScreenDownArena() +void eventScreenDownArena() { - int i; - - if (strcmp(str_status, "none") == 0) { - eventStatus(); - } - - if (recvBuffer != NULL) { - for (i = 0; i < DOWN_ARENA_COUNT_READ_SOCKET; i++) { - if (eventRecvBuffer() <= 0) { - break; - } - } - } - - if (sendBuffer != NULL) { - eventSendBuffer(); - } - - if (file != NULL && fileSize == fileOffset && fileSize > 0) { - fclose(file); - file = NULL; - closeConnectFromDownServer(); - loadArenaFile(path); - setScreen("world"); - } - - eventWidgetButton(button_back); + int i; + + if (strcmp(str_status, "none") == 0) { + eventStatus(); + } + + if (recvBuffer != NULL) { + for (i = 0; i < DOWN_ARENA_COUNT_READ_SOCKET; i++) { + if (eventRecvBuffer() <= 0) { + break; + } + } + } + + if (sendBuffer != NULL) { + eventSendBuffer(); + } + + if (file != NULL && fileSize == fileOffset && fileSize > 0) { + fclose(file); + file = NULL; + closeConnectFromDownServer(); + loadArenaFile(path); + setScreen("world"); + } + + eventWidgetButton(button_back); } -void -stopScreenDownArena() +void stopScreenDownArena() { - if (file != NULL) { - unlink(path); - } + if (file != NULL) { + unlink(path); + } - if (sock_server_tcp != NULL) { - closeConnectFromDownServer(); - } + if (sock_server_tcp != NULL) { + closeConnectFromDownServer(); + } - if (sock_server_udp != NULL) { - closeUdpSocket(sock_server_udp); - } + if (sock_server_udp != NULL) { + closeUdpSocket(sock_server_udp); + } } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_back) { - setScreen("mainMenu"); - } + if (button == button_back) { + setScreen("mainMenu"); + } } -void -initScreenDownArena() +void initScreenDownArena() { - image_t *image; + image_t *image; - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); - button_back = - newWidgetButton(_("back"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 80, eventWidget); + button_back = + newWidgetButton(_("back"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 80, eventWidget); - label_status = - newWidgetLabel("none", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + label_status = + newWidgetLabel("none", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); - registerScreen(newScreen - ("downArena", startScreenDownArena, eventScreenDownArena, - drawScreenDownArena, stopScreenDownArena)); + registerScreen(newScreen + ("downArena", startScreenDownArena, eventScreenDownArena, + drawScreenDownArena, stopScreenDownArena)); } -void -quitScreenDownArena() +void quitScreenDownArena() { - destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_back); - destroyWidgetLabel(label_status); + destroyWidgetImage(image_backgorund); + destroyWidgetButton(button_back); + destroyWidgetLabel(label_status); } diff --git a/src/screen/screen_downArena.h b/src/screen/screen_downArena.h index 0e71887..d9f25d7 100644 --- a/src/screen/screen_downArena.h +++ b/src/screen/screen_downArena.h @@ -1,16 +1,16 @@ #ifndef SCREEN_DOWN_ARENA_H -#define SCREEN_DOWN_ARENA_H +# define SCREEN_DOWN_ARENA_H -#define DOWN_SERVER_STATUS_OK 0 -#define DOWN_SERVER_STATUS_ZOMBIE 1 +# define DOWN_SERVER_STATUS_OK 0 +# define DOWN_SERVER_STATUS_ZOMBIE 1 -#define DOWN_ARENA_BUFFER_SIZE 4096 +# define DOWN_ARENA_BUFFER_SIZE 4096 -#define DOWN_ARENA_MAX_SEND_MSG_STATUS 10 -#define DOWN_ARENA_MAX_TIEMOUT_LIMIT 500 -#define DOWN_ARENA_COUNT_READ_SOCKET 100 +# define DOWN_ARENA_MAX_SEND_MSG_STATUS 10 +# define DOWN_ARENA_MAX_TIEMOUT_LIMIT 500 +# define DOWN_ARENA_COUNT_READ_SOCKET 100 extern void startScreenDownArena(); extern void drawScreenDownArena(); diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c index 12c12ba..bba8146 100644 --- a/src/screen/screen_gameType.c +++ b/src/screen/screen_gameType.c @@ -15,7 +15,7 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_gameType.h" @@ -56,356 +56,335 @@ static widget_t *textfield_port; static widget_t *selectSession; -static void -loadSession(widget_t * p) +static void loadSession(widget_t * p) { - director_t *director; - int i; + director_t *director; + int i; - director = loadDirector(getHomeDirector()); + director = loadDirector(getHomeDirector()); - removeAllFromWidgetSelect(p); + removeAllFromWidgetSelect(p); - if (director == NULL) { - return; - } + if (director == NULL) { + return; + } - for (i = 0; i < director->list->count; i++) { - char *line; + for (i = 0; i < director->list->count; i++) { + char *line; - line = director->list->list[i]; + line = director->list->list[i]; - if (strstr(line, ".sav") != NULL) { - addToWidgetSelect(p, line); - } - } + if (strstr(line, ".sav") != NULL) { + addToWidgetSelect(p, line); + } + } - destroyDirector(director); + destroyDirector(director); } -void -startScreenGameType() +void startScreenGameType() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif - setWidgetChoiceStatus(check_none, TRUE); - setWidgetChoiceStatus(check_server, FALSE); - setWidgetChoiceStatus(check_client, FALSE); - setWidgetChoiceStatus(check_load_session, FALSE); + setWidgetChoiceStatus(check_none, TRUE); + setWidgetChoiceStatus(check_server, FALSE); + setWidgetChoiceStatus(check_client, FALSE); + setWidgetChoiceStatus(check_load_session, FALSE); - loadSession(selectSession); + loadSession(selectSession); } -void -drawScreenGameType() +void drawScreenGameType() { - int i; - - drawWidgetImage(image_backgorund); - - for (i = 0; i < listChoiceGroup->count; i++) { - widget_t *this; - - this = (widget_t *) listChoiceGroup->list[i]; - drawWidgetChoicegroup(this); - } - - drawWidgetLabel(label_none); - drawWidgetLabel(label_server); - drawWidgetLabel(label_client); - drawWidgetLabel(label_load_session); - - if (getWidgetChoiceStatus(check_server) == TRUE - || getWidgetChoiceStatus(check_client) == TRUE) { - drawWidgetLabel(label_port); - drawWidgetTextfield(textfield_port); - drawWidgetLabel(label_ip); - drawWidgetTextfield(textfield_ip); - } - - if (getWidgetChoiceStatus(check_load_session) == TRUE) { - drawWidgetLabel(label_session); - drawWidgetSelect(selectSession); - } - + int i; + + drawWidgetImage(image_backgorund); + + for (i = 0; i < listChoiceGroup->count; i++) { + widget_t *this; + + this = (widget_t *) listChoiceGroup->list[i]; + drawWidgetChoicegroup(this); + } + + drawWidgetLabel(label_none); + drawWidgetLabel(label_server); + drawWidgetLabel(label_client); + drawWidgetLabel(label_load_session); + + if (getWidgetChoiceStatus(check_server) == TRUE + || getWidgetChoiceStatus(check_client) == TRUE) { + drawWidgetLabel(label_port); + drawWidgetTextfield(textfield_port); + drawWidgetLabel(label_ip); + drawWidgetTextfield(textfield_ip); + } + + if (getWidgetChoiceStatus(check_load_session) == TRUE) { + drawWidgetLabel(label_session); + drawWidgetSelect(selectSession); + } #if 0 - if (check_server->status == TRUE) { - setSettingIP(getParamElse("--ip", "127.0.0.1")); - setSettingPort(atoi(getParamElse("--port", "2200"))); - } + if (check_server->status == TRUE) { + setSettingIP(getParamElse("--ip", "127.0.0.1")); + setSettingPort(atoi(getParamElse("--port", "2200"))); + } #endif - if (getWidgetChoiceStatus(check_client) == TRUE) - drawWidgetButton(button_browser); + if (getWidgetChoiceStatus(check_client) == TRUE) + drawWidgetButton(button_browser); - drawWidgetButton(button_back); - drawWidgetButton(button_play); + drawWidgetButton(button_back); + drawWidgetButton(button_play); } -void -eventScreenGameType() +void eventScreenGameType() { - int i; + int i; - for (i = 0; i < listChoiceGroup->count; i++) { - widget_t *this; + for (i = 0; i < listChoiceGroup->count; i++) { + widget_t *this; - this = (widget_t *) listChoiceGroup->list[i]; - eventWidgetChoicegroup(this); - } + this = (widget_t *) listChoiceGroup->list[i]; + eventWidgetChoicegroup(this); + } - if (getWidgetChoiceStatus(check_server) == TRUE - || getWidgetChoiceStatus(check_client) == TRUE) { - eventWidgetTextfield(textfield_ip); - eventWidgetTextfield(textfield_port); - } + if (getWidgetChoiceStatus(check_server) == TRUE + || getWidgetChoiceStatus(check_client) == TRUE) { + eventWidgetTextfield(textfield_ip); + eventWidgetTextfield(textfield_port); + } - if (getWidgetChoiceStatus(check_load_session) == TRUE) { - eventWidgetSelect(selectSession); - } + if (getWidgetChoiceStatus(check_load_session) == TRUE) { + eventWidgetSelect(selectSession); + } - eventWidgetButton(button_back); - eventWidgetButton(button_play); + eventWidgetButton(button_back); + eventWidgetButton(button_play); - if (getWidgetChoiceStatus(check_client) == TRUE) - eventWidgetButton(button_browser); + if (getWidgetChoiceStatus(check_client) == TRUE) + eventWidgetButton(button_browser); } -void -stopScreenGameType() +void stopScreenGameType() { } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_back) { - setScreen("mainMenu"); - } + if (button == button_back) { + setScreen("mainMenu"); + } - if (button == button_play) { - char *str; + if (button == button_play) { + char *str; - str = getGemeTypeLoadSession(); + str = getGemeTypeLoadSession(); - if (str != NULL) { - setScreen("world"); - return; - } + if (str != NULL) { + setScreen("world"); + return; + } - if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { - setScreen("downArena"); - //setScreen("world"); - } - else { - setScreen("chiceArena"); - } - } + if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { + setScreen("downArena"); + //setScreen("world"); + } else { + setScreen("chiceArena"); + } + } - if (button == button_browser) { - setScreen("browser"); - } + if (button == button_browser) { + setScreen("browser"); + } } -void -initScreenGameType() +void initScreenGameType() { - image_t *image; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); - button_play = - newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); - button_browser = newWidgetButton(_("browser"), 300, 345, eventWidget); - - listChoiceGroup = newList(); - check_none = - newWidgetChoicegroup(100, 150, FALSE, listChoiceGroup, eventWidget); - check_server = - newWidgetChoicegroup(100, 200, FALSE, listChoiceGroup, eventWidget); - check_client = - newWidgetChoicegroup(100, 250, FALSE, listChoiceGroup, eventWidget); - check_load_session = - newWidgetChoicegroup(100, 300, FALSE, listChoiceGroup, eventWidget); - - if (isParamFlag("--server")) { - setWidgetChoiceStatus(check_server, TRUE); - } - else if (isParamFlag("--client")) { - setWidgetChoiceStatus(check_client, TRUE); - } - else { - setWidgetChoiceStatus(check_none, TRUE); - } - - label_none = newWidgetLabel(_("Local game"), 130, 145, WIDGET_LABEL_LEFT); - label_server = - newWidgetLabel(_("Set up a server"), 130, 195, WIDGET_LABEL_LEFT); - label_client = - newWidgetLabel(_("Network game"), 130, 245, WIDGET_LABEL_LEFT); - label_load_session = - newWidgetLabel("load session", 130, 295, WIDGET_LABEL_LEFT); - - label_ip = newWidgetLabel(_("IP"), 300, 145, WIDGET_LABEL_LEFT); - label_port = newWidgetLabel(_("port"), 300, 245, WIDGET_LABEL_LEFT); - label_session = - newWidgetLabel("load session :", 300, 145, WIDGET_LABEL_LEFT); - - textfield_ip = newWidgetTextfield(getParamElse("--ip", "127.0.0.1"), - WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN, - 300, 180); - - textfield_port = newWidgetTextfield(getParamElse("--port", "2200"), - WIDGET_TEXTFIELD_FILTER_NUM, - 300, 280); - - selectSession = newWidgetSelect(300, 185, eventWidget); - - registerScreen(newScreen - ("gameType", startScreenGameType, eventScreenGameType, - drawScreenGameType, stopScreenGameType)); + image_t *image; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); + button_play = + newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); + button_browser = newWidgetButton(_("browser"), 300, 345, eventWidget); + + listChoiceGroup = newList(); + check_none = + newWidgetChoicegroup(100, 150, FALSE, listChoiceGroup, eventWidget); + check_server = + newWidgetChoicegroup(100, 200, FALSE, listChoiceGroup, eventWidget); + check_client = + newWidgetChoicegroup(100, 250, FALSE, listChoiceGroup, eventWidget); + check_load_session = + newWidgetChoicegroup(100, 300, FALSE, listChoiceGroup, eventWidget); + + if (isParamFlag("--server")) { + setWidgetChoiceStatus(check_server, TRUE); + } else if (isParamFlag("--client")) { + setWidgetChoiceStatus(check_client, TRUE); + } else { + setWidgetChoiceStatus(check_none, TRUE); + } + + label_none = newWidgetLabel(_("Local game"), 130, 145, WIDGET_LABEL_LEFT); + label_server = + newWidgetLabel(_("Set up a server"), 130, 195, WIDGET_LABEL_LEFT); + label_client = + newWidgetLabel(_("Network game"), 130, 245, WIDGET_LABEL_LEFT); + label_load_session = + newWidgetLabel("load session", 130, 295, WIDGET_LABEL_LEFT); + + label_ip = newWidgetLabel(_("IP"), 300, 145, WIDGET_LABEL_LEFT); + label_port = newWidgetLabel(_("port"), 300, 245, WIDGET_LABEL_LEFT); + label_session = + newWidgetLabel("load session :", 300, 145, WIDGET_LABEL_LEFT); + + textfield_ip = newWidgetTextfield(getParamElse("--ip", "127.0.0.1"), + WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN, + 300, 180); + + textfield_port = newWidgetTextfield(getParamElse("--port", "2200"), + WIDGET_TEXTFIELD_FILTER_NUM, 300, 280); + + selectSession = newWidgetSelect(300, 185, eventWidget); + + registerScreen(newScreen + ("gameType", startScreenGameType, eventScreenGameType, + drawScreenGameType, stopScreenGameType)); } -int -setSettingGameType(int status) +int setSettingGameType(int status) { - if (status == NET_GAME_TYPE_NONE) { - setWidgetChoiceStatus(check_none, TRUE); - return 0; - } - - if (status == NET_GAME_TYPE_SERVER) { - setWidgetChoiceStatus(check_server, TRUE); - return 0; - } - - if (status == NET_GAME_TYPE_CLIENT) { - setWidgetChoiceStatus(check_client, TRUE); - return 0; - } - - return -1; + if (status == NET_GAME_TYPE_NONE) { + setWidgetChoiceStatus(check_none, TRUE); + return 0; + } + + if (status == NET_GAME_TYPE_SERVER) { + setWidgetChoiceStatus(check_server, TRUE); + return 0; + } + + if (status == NET_GAME_TYPE_CLIENT) { + setWidgetChoiceStatus(check_client, TRUE); + return 0; + } + + return -1; } -int -getSettingGameType() +int getSettingGameType() { - if (getWidgetChoiceStatus(check_none) == TRUE || - getWidgetChoiceStatus(check_load_session) == TRUE) { - return NET_GAME_TYPE_NONE; - } + if (getWidgetChoiceStatus(check_none) == TRUE || + getWidgetChoiceStatus(check_load_session) == TRUE) { + return NET_GAME_TYPE_NONE; + } - if (getWidgetChoiceStatus(check_server) == TRUE) { - return NET_GAME_TYPE_SERVER; - } + if (getWidgetChoiceStatus(check_server) == TRUE) { + return NET_GAME_TYPE_SERVER; + } - if (getWidgetChoiceStatus(check_client) == TRUE) { - return NET_GAME_TYPE_CLIENT; - } + if (getWidgetChoiceStatus(check_client) == TRUE) { + return NET_GAME_TYPE_CLIENT; + } - assert(!_("Unknown game type!")); + assert(!_("Unknown game type!")); - return -1; + return -1; } -char * -getGemeTypeLoadSession() +char *getGemeTypeLoadSession() { - if (getWidgetChoiceStatus(check_load_session) == TRUE) { - return getWidgetSelectItem(selectSession); - } + if (getWidgetChoiceStatus(check_load_session) == TRUE) { + return getWidgetSelectItem(selectSession); + } - return NULL; + return NULL; } -int -setSettingIP(char *address) +int setSettingIP(char *address) { - char str[STR_SIZE]; + char str[STR_SIZE]; - strcpy(str, address); - setWidgetTextFiledText(textfield_ip, str); + strcpy(str, address); + setWidgetTextFiledText(textfield_ip, str); - return 1; + return 1; } -char * -getSettingIP() +char *getSettingIP() { - return getTextFromWidgetTextfield(textfield_ip); + return getTextFromWidgetTextfield(textfield_ip); } -int -setSettingPort(int port) +int setSettingPort(int port) { - char str[STR_SIZE]; + char str[STR_SIZE]; - sprintf(str, "%d", port); - setWidgetTextFiledText(textfield_port, str); + sprintf(str, "%d", port); + setWidgetTextFiledText(textfield_port, str); - return 0; + return 0; } -int -getSettingPort() +int getSettingPort() { - return atoi(getTextFromWidgetTextfield(textfield_port)); + return atoi(getTextFromWidgetTextfield(textfield_port)); } -int -getSettingProto() +int getSettingProto() { - if (strstr(getTextFromWidgetTextfield(textfield_ip), ".") != NULL) { - return PROTO_UDPv4; - } + if (strstr(getTextFromWidgetTextfield(textfield_ip), ".") != NULL) { + return PROTO_UDPv4; + } - if (strstr(getTextFromWidgetTextfield(textfield_ip), ":") != NULL) { - return PROTO_UDPv6; - } + if (strstr(getTextFromWidgetTextfield(textfield_ip), ":") != NULL) { + return PROTO_UDPv6; + } #ifdef DEBUG - printf(_("Unknown IP protocol!\n")); + printf(_("Unknown IP protocol!\n")); #endif - return -1; + return -1; } -void -quitScreenGameType() +void quitScreenGameType() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetLabel(label_none); - destroyWidgetLabel(label_server); - destroyWidgetLabel(label_client); - destroyWidgetLabel(label_load_session); + destroyWidgetLabel(label_none); + destroyWidgetLabel(label_server); + destroyWidgetLabel(label_client); + destroyWidgetLabel(label_load_session); - destroyWidgetLabel(label_ip); - destroyWidgetLabel(label_port); - destroyWidgetLabel(label_session); + destroyWidgetLabel(label_ip); + destroyWidgetLabel(label_port); + destroyWidgetLabel(label_session); - destroyWidgetTextfield(textfield_ip); - destroyWidgetTextfield(textfield_port); + destroyWidgetTextfield(textfield_ip); + destroyWidgetTextfield(textfield_port); - destroyWidgetSelect(selectSession); + destroyWidgetSelect(selectSession); - destroyWidgetButton(button_back); - destroyWidgetButton(button_play); - destroyWidgetButton(button_browser); + destroyWidgetButton(button_back); + destroyWidgetButton(button_play); + destroyWidgetButton(button_browser); - destroyWidgetChoicegroup(check_none); - destroyWidgetChoicegroup(check_server); - destroyWidgetChoicegroup(check_client); - destroyWidgetChoicegroup(check_load_session); + destroyWidgetChoicegroup(check_none); + destroyWidgetChoicegroup(check_server); + destroyWidgetChoicegroup(check_client); + destroyWidgetChoicegroup(check_load_session); - destroyList(listChoiceGroup); + destroyList(listChoiceGroup); } diff --git a/src/screen/screen_gameType.h b/src/screen/screen_gameType.h index a83ddf2..2c836fc 100644 --- a/src/screen/screen_gameType.h +++ b/src/screen/screen_gameType.h @@ -1,9 +1,9 @@ #ifndef SCREEN_GAME_TYPE -#define SCREEN_GAME_TYPE +# define SCREEN_GAME_TYPE -#include "main.h" +# include "main.h" extern void drawScreenGameType(); extern void eventScreenGameType(); diff --git a/src/screen/screen_mainMenu.c b/src/screen/screen_mainMenu.c index a513bc7..580bfab 100644 --- a/src/screen/screen_mainMenu.c +++ b/src/screen/screen_mainMenu.c @@ -10,7 +10,7 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_mainMenu.h" @@ -31,117 +31,110 @@ static widget_t *button_table; static widget_t *button_credits; static widget_t *button_end; -void -startScreenMainMenu() +void startScreenMainMenu() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif } -void -drawScreenMainMenu() +void drawScreenMainMenu() { - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - drawWidgetButton(button_play); - drawWidgetButton(button_setting); - drawWidgetButton(button_table); - drawWidgetButton(button_credits); - drawWidgetButton(button_end); + drawWidgetButton(button_play); + drawWidgetButton(button_setting); + drawWidgetButton(button_table); + drawWidgetButton(button_credits); + drawWidgetButton(button_end); } -void -eventScreenMainMenu() +void eventScreenMainMenu() { - eventWidgetButton(button_play); - eventWidgetButton(button_setting); - eventWidgetButton(button_table); - eventWidgetButton(button_credits); - eventWidgetButton(button_end); + eventWidgetButton(button_play); + eventWidgetButton(button_setting); + eventWidgetButton(button_table); + eventWidgetButton(button_credits); + eventWidgetButton(button_end); } -void -stopScreenMainMenu() +void stopScreenMainMenu() { } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_play) { - setScreen("gameType"); - } + if (button == button_play) { + setScreen("gameType"); + } - if (button == button_setting) { - setScreen("setting"); - } + if (button == button_setting) { + setScreen("setting"); + } - if (button == button_table) { - setScreen("table"); - } + if (button == button_table) { + setScreen("table"); + } - if (button == button_credits) { - setScreen("credits"); - } + if (button == button_credits) { + setScreen("credits"); + } - if (button == button_end) { - quitGame(); - } + if (button == button_end) { + quitGame(); + } } -void -initScreenMainMenu() +void initScreenMainMenu() { - image_t *image; - - image = - addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_main", - IMAGE_GROUP_BASE); - image_backgorund = newWidgetImage(0, 0, image); - - button_play = - newWidgetButton(_("Start game"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 200, - eventWidget); - button_setting = - newWidgetButton(_("Settings"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 250, - eventWidget); - button_table = - newWidgetButton(_("Highscore"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 300, - eventWidget); - button_credits = - newWidgetButton(_("Credits"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 350, - eventWidget); - button_end = - newWidgetButton(_("Quit game"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 400, - eventWidget); + image_t *image; + + image = + addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_main", + IMAGE_GROUP_BASE); + image_backgorund = newWidgetImage(0, 0, image); + + button_play = + newWidgetButton(_("Start game"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 200, + eventWidget); + button_setting = + newWidgetButton(_("Settings"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 250, + eventWidget); + button_table = + newWidgetButton(_("Highscore"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 300, + eventWidget); + button_credits = + newWidgetButton(_("Credits"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 350, + eventWidget); + button_end = + newWidgetButton(_("Quit game"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 400, + eventWidget); #ifndef NO_SOUND - addMusic("menu.ogg", "menu", MUSIC_GROUP_BASE); + addMusic("menu.ogg", "menu", MUSIC_GROUP_BASE); #endif - registerScreen(newScreen - ("mainMenu", startScreenMainMenu, eventScreenMainMenu, - drawScreenMainMenu, stopScreenMainMenu)); + registerScreen(newScreen + ("mainMenu", startScreenMainMenu, eventScreenMainMenu, + drawScreenMainMenu, stopScreenMainMenu)); } -void -quitScreenMainMenu() +void quitScreenMainMenu() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_play); - destroyWidgetButton(button_setting); - destroyWidgetButton(button_table); - destroyWidgetButton(button_credits); - destroyWidgetButton(button_end); + destroyWidgetButton(button_play); + destroyWidgetButton(button_setting); + destroyWidgetButton(button_table); + destroyWidgetButton(button_credits); + destroyWidgetButton(button_end); } diff --git a/src/screen/screen_mainMenu.h b/src/screen/screen_mainMenu.h index 909e541..ecb369b 100644 --- a/src/screen/screen_mainMenu.h +++ b/src/screen/screen_mainMenu.h @@ -1,9 +1,9 @@ #ifndef SCREEN_MIAN_MENU_H -#define SCREEN_MIAN_MENU_H +# define SCREEN_MIAN_MENU_H -#include "main.h" +# include "main.h" extern void startScreenMainMenu(); extern void drawScreenMainMenu(); diff --git a/src/screen/screen_setting.c b/src/screen/screen_setting.c index 22e524c..790f42b 100644 --- a/src/screen/screen_setting.c +++ b/src/screen/screen_setting.c @@ -17,8 +17,8 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" -#include "sound.h" +# include "music.h" +# include "sound.h" #endif #include "screen_mainMenu.h" @@ -38,7 +38,7 @@ static widget_t *image_backgorund; static widget_t *button_back; -static widget_t *button_keys; // setting of keycontrols +static widget_t *button_keys; // setting of keycontrols static widget_t *label_count_round; static widget_t *label_name_player1; @@ -78,539 +78,518 @@ static widget_t *check_ai; static textFile_t *configFile; -void -startScreenSetting() +void startScreenSetting() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif } -void -drawScreenSetting() +void drawScreenSetting() { - int i; + int i; - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - drawWidgetLabel(label_count_round); - drawWidgetLabel(label_name_player1); - drawWidgetLabel(label_ai); + drawWidgetLabel(label_count_round); + drawWidgetLabel(label_name_player1); + drawWidgetLabel(label_ai); #ifndef NO_SOUND - drawWidgetLabel(label_music); - drawWidgetLabel(label_sound); + drawWidgetLabel(label_music); + drawWidgetLabel(label_sound); #endif - drawWidgetTextfield(textfield_count_cound); - drawWidgetTextfield(textfield_name_player1); + drawWidgetTextfield(textfield_count_cound); + drawWidgetTextfield(textfield_name_player1); - if (getWidgetCheckStatus(check_ai) == FALSE) { - drawWidgetLabel(label_name_player2); - drawWidgetTextfield(textfield_name_player2); - } + if (getWidgetCheckStatus(check_ai) == FALSE) { + drawWidgetLabel(label_name_player2); + drawWidgetTextfield(textfield_name_player2); + } - drawWidgetImage(image_gun_dual_revolver); - drawWidgetImage(image_gun_scatter); - drawWidgetImage(image_gun_tommy); - drawWidgetImage(image_gun_lasser); - drawWidgetImage(image_gun_mine); - drawWidgetImage(image_gun_bombball); + drawWidgetImage(image_gun_dual_revolver); + drawWidgetImage(image_gun_scatter); + drawWidgetImage(image_gun_tommy); + drawWidgetImage(image_gun_lasser); + drawWidgetImage(image_gun_mine); + drawWidgetImage(image_gun_bombball); - drawWidgetImage(image_bonus_speed); - drawWidgetImage(image_bonus_shot); - drawWidgetImage(image_bonus_teleport); - drawWidgetImage(image_bonus_ghost); - drawWidgetImage(image_bonus_4x); - drawWidgetImage(image_bonus_hidden); + drawWidgetImage(image_bonus_speed); + drawWidgetImage(image_bonus_shot); + drawWidgetImage(image_bonus_teleport); + drawWidgetImage(image_bonus_ghost); + drawWidgetImage(image_bonus_4x); + drawWidgetImage(image_bonus_hidden); #ifndef NO_SOUND - drawWidgetCheck(check_music); - drawWidgetCheck(check_sound); + drawWidgetCheck(check_music); + drawWidgetCheck(check_sound); #endif - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - drawWidgetCheck(check[i]); - } + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + drawWidgetCheck(check[i]); + } - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - drawWidgetCheck(check[i]); - } + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + drawWidgetCheck(check[i]); + } - drawWidgetCheck(check_ai); + drawWidgetCheck(check_ai); - drawWidgetButton(button_back); - drawWidgetButton(button_keys); + drawWidgetButton(button_back); + drawWidgetButton(button_keys); } -void -eventScreenSetting() +void eventScreenSetting() { - int i; + int i; - eventWidgetTextfield(textfield_count_cound); - eventWidgetTextfield(textfield_name_player1); - - if (getWidgetCheckStatus(check_ai) == FALSE) { - eventWidgetTextfield(textfield_name_player2); - } + eventWidgetTextfield(textfield_count_cound); + eventWidgetTextfield(textfield_name_player1); + if (getWidgetCheckStatus(check_ai) == FALSE) { + eventWidgetTextfield(textfield_name_player2); + } #ifndef NO_SOUND - eventWidgetCheck(check_music); - eventWidgetCheck(check_sound); + eventWidgetCheck(check_music); + eventWidgetCheck(check_sound); #endif - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - eventWidgetCheck(check[i]); - } + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + eventWidgetCheck(check[i]); + } - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - eventWidgetCheck(check[i]); - } + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + eventWidgetCheck(check[i]); + } - eventWidgetCheck(check_ai); + eventWidgetCheck(check_ai); - eventWidgetButton(button_back); - eventWidgetButton(button_keys); + eventWidgetButton(button_back); + eventWidgetButton(button_keys); } -void -stopScreenSetting() +void stopScreenSetting() { } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; - widget_t *check; - - button = (widget_t *) (p); - check = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } - if (button == button_keys) { - setScreen("settingKeys"); - } - + widget_t *button; + widget_t *check; + + button = (widget_t *) (p); + check = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } + if (button == button_keys) { + setScreen("settingKeys"); + } #ifndef NO_SOUND - if (check == check_music) { - setMusicActive(getWidgetCheckStatus(check_music)); - } + if (check == check_music) { + setMusicActive(getWidgetCheckStatus(check_music)); + } - if (check == check_sound) { - setSoundActive(getWidgetCheckStatus(check_sound)); - } + if (check == check_sound) { + setSoundActive(getWidgetCheckStatus(check_sound)); + } #endif } -static void -initSettingFile() +static void initSettingFile() { - char path[STR_PATH_SIZE]; - char val[STR_SIZE]; - - sprintf(path, "%s/tuxanci.conf", getHomeDirector()); - - configFile = loadTextFile(path); - - if (configFile == NULL) { - fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); - fprintf(stderr, _("Creating: \"%s\"\n"), path); - - configFile = newTextFile(path); - } - - if (configFile == NULL) { - fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); - return; - } - - loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15"); - setWidgetTextFiledText(textfield_count_cound, val); - - loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, - NAME_PLAYER_RIGHT); - setWidgetTextFiledText(textfield_name_player1, val); - - loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, - NAME_PLAYER_LEFT); - setWidgetTextFiledText(textfield_name_player2, val); - - loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, - "YES"); - setWidgetCheckStatus(check[GUN_DUAL_SIMPLE], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_SCATTER", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_SCATTER], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_TOMMY], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_LASSER], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_MINE], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_BOMBBALL], isYesOrNO(val)); - - loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_SPEED], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_SHOT], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, - "YES"); - setWidgetCheckStatus(check[BONUS_TELEPORT], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_GHOST], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_4X], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_HIDDEN], isYesOrNO(val)); - - loadValueFromConfigFile(configFile, "AI", val, STR_SIZE, "NO"); - setWidgetCheckStatus(check_ai, isYesOrNO(val)); + char path[STR_PATH_SIZE]; + char val[STR_SIZE]; + + sprintf(path, "%s/tuxanci.conf", getHomeDirector()); + + configFile = loadTextFile(path); + + if (configFile == NULL) { + fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); + fprintf(stderr, _("Creating: \"%s\"\n"), path); + + configFile = newTextFile(path); + } + + if (configFile == NULL) { + fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); + return; + } + + loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15"); + setWidgetTextFiledText(textfield_count_cound, val); + + loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, + NAME_PLAYER_RIGHT); + setWidgetTextFiledText(textfield_name_player1, val); + + loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, + NAME_PLAYER_LEFT); + setWidgetTextFiledText(textfield_name_player2, val); + + loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, + "YES"); + setWidgetCheckStatus(check[GUN_DUAL_SIMPLE], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_SCATTER", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_SCATTER], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_TOMMY], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_LASSER], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_MINE], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_BOMBBALL], isYesOrNO(val)); + + loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_SPEED], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_SHOT], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, + "YES"); + setWidgetCheckStatus(check[BONUS_TELEPORT], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_GHOST], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_4X], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_HIDDEN], isYesOrNO(val)); + + loadValueFromConfigFile(configFile, "AI", val, STR_SIZE, "NO"); + setWidgetCheckStatus(check_ai, isYesOrNO(val)); #ifndef NO_SOUND - loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check_music, isYesOrNO(val)); + loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check_music, isYesOrNO(val)); - loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check_sound, isYesOrNO(val)); + loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check_sound, isYesOrNO(val)); #endif - loadValueFromConfigFile(configFile, "ARENA", val, STR_SIZE, "FAGN"); - setChoiceArena(getArenaFileFormNetName(val)); + loadValueFromConfigFile(configFile, "ARENA", val, STR_SIZE, "FAGN"); + setChoiceArena(getArenaFileFormNetName(val)); - saveTextFile(configFile); + saveTextFile(configFile); } -static void -saveAndDestroyConfigFile() +static void saveAndDestroyConfigFile() { - if (configFile == NULL) { - fprintf(stderr, - _ - ("I am unable to save configure file, because config file was not initialised!\n")); - - return; - } - - setValueInConfigFile(configFile, "COUNT_ROUND", - getTextFromWidgetTextfield(textfield_count_cound)); - setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", - getTextFromWidgetTextfield(textfield_name_player1)); - setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", - getTextFromWidgetTextfield(textfield_name_player2)); - - setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", - getYesOrNo(getWidgetCheckStatus - (check[GUN_DUAL_SIMPLE]))); - setValueInConfigFile(configFile, "GUN_SCATTER", - getYesOrNo(getWidgetCheckStatus - (check[GUN_SCATTER]))); - setValueInConfigFile(configFile, "GUN_TOMMY", - getYesOrNo(getWidgetCheckStatus(check[GUN_TOMMY]))); - setValueInConfigFile(configFile, "GUN_LASSER", - getYesOrNo(getWidgetCheckStatus(check[GUN_LASSER]))); - setValueInConfigFile(configFile, "GUN_MINE", - getYesOrNo(getWidgetCheckStatus(check[GUN_MINE]))); - setValueInConfigFile(configFile, "GUN_BOMBBALL", - getYesOrNo(getWidgetCheckStatus - (check[GUN_BOMBBALL]))); - - setValueInConfigFile(configFile, "BONUS_SPEED", - getYesOrNo(getWidgetCheckStatus - (check[BONUS_SPEED]))); - setValueInConfigFile(configFile, "BONUS_SHOT", - getYesOrNo(getWidgetCheckStatus(check[BONUS_SHOT]))); - setValueInConfigFile(configFile, "BONUS_TELEPORT", - getYesOrNo(getWidgetCheckStatus - (check[BONUS_TELEPORT]))); - setValueInConfigFile(configFile, "BONUS_GHOST", - getYesOrNo(getWidgetCheckStatus - (check[BONUS_GHOST]))); - setValueInConfigFile(configFile, "BONUS_4X", - getYesOrNo(getWidgetCheckStatus(check[BONUS_4X]))); - setValueInConfigFile(configFile, "BONUS_HIDDEN", - getYesOrNo(getWidgetCheckStatus - (check[BONUS_HIDDEN]))); - - setValueInConfigFile(configFile, "AI", - getYesOrNo(getWidgetCheckStatus(check_ai))); + if (configFile == NULL) { + fprintf(stderr, + _ + ("I am unable to save configure file, because config file was not initialised!\n")); + + return; + } + + setValueInConfigFile(configFile, "COUNT_ROUND", + getTextFromWidgetTextfield(textfield_count_cound)); + setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", + getTextFromWidgetTextfield(textfield_name_player1)); + setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", + getTextFromWidgetTextfield(textfield_name_player2)); + + setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", + getYesOrNo(getWidgetCheckStatus + (check[GUN_DUAL_SIMPLE]))); + setValueInConfigFile(configFile, "GUN_SCATTER", + getYesOrNo(getWidgetCheckStatus(check[GUN_SCATTER]))); + setValueInConfigFile(configFile, "GUN_TOMMY", + getYesOrNo(getWidgetCheckStatus(check[GUN_TOMMY]))); + setValueInConfigFile(configFile, "GUN_LASSER", + getYesOrNo(getWidgetCheckStatus(check[GUN_LASSER]))); + setValueInConfigFile(configFile, "GUN_MINE", + getYesOrNo(getWidgetCheckStatus(check[GUN_MINE]))); + setValueInConfigFile(configFile, "GUN_BOMBBALL", + getYesOrNo(getWidgetCheckStatus + (check[GUN_BOMBBALL]))); + + setValueInConfigFile(configFile, "BONUS_SPEED", + getYesOrNo(getWidgetCheckStatus(check[BONUS_SPEED]))); + setValueInConfigFile(configFile, "BONUS_SHOT", + getYesOrNo(getWidgetCheckStatus(check[BONUS_SHOT]))); + setValueInConfigFile(configFile, "BONUS_TELEPORT", + getYesOrNo(getWidgetCheckStatus + (check[BONUS_TELEPORT]))); + setValueInConfigFile(configFile, "BONUS_GHOST", + getYesOrNo(getWidgetCheckStatus(check[BONUS_GHOST]))); + setValueInConfigFile(configFile, "BONUS_4X", + getYesOrNo(getWidgetCheckStatus(check[BONUS_4X]))); + setValueInConfigFile(configFile, "BONUS_HIDDEN", + getYesOrNo(getWidgetCheckStatus + (check[BONUS_HIDDEN]))); + + setValueInConfigFile(configFile, "AI", + getYesOrNo(getWidgetCheckStatus(check_ai))); #ifndef NO_SOUND - setValueInConfigFile(configFile, "MUSIC", - getYesOrNo(getWidgetCheckStatus(check_music))); - setValueInConfigFile(configFile, "SOUND", - getYesOrNo(getWidgetCheckStatus(check_sound))); + setValueInConfigFile(configFile, "MUSIC", + getYesOrNo(getWidgetCheckStatus(check_music))); + setValueInConfigFile(configFile, "SOUND", + getYesOrNo(getWidgetCheckStatus(check_sound))); #endif - setValueInConfigFile(configFile, "ARENA", - getArenaNetName(getChoiceArena())); - //TODO + setValueInConfigFile(configFile, "ARENA", + getArenaNetName(getChoiceArena())); + //TODO - saveTextFile(configFile); - destroyTextFile(configFile); + saveTextFile(configFile); + destroyTextFile(configFile); } -void -initScreenSetting() +void initScreenSetting() { - image_t *image; - int i; + image_t *image; + int i; - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); - button_back = - newWidgetButton(_("back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); - button_keys = - newWidgetButton(_("controls"), WINDOW_SIZE_X - 200, - button_back->y - WIDGET_BUTTON_HEIGHT - 10, - eventWidget); + button_back = + newWidgetButton(_("back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); + button_keys = + newWidgetButton(_("controls"), WINDOW_SIZE_X - 200, + button_back->y - WIDGET_BUTTON_HEIGHT - 10, + eventWidget); #ifndef NO_SOUND - label_music = - newWidgetLabel(_("Music:"), 100, WINDOW_SIZE_Y - 85, - WIDGET_LABEL_LEFT); - check_music = - newWidgetCheck(label_music->x + label_music->w + 10, - WINDOW_SIZE_Y - 80, isMusicActive(), eventWidget); - label_sound = - newWidgetLabel(_("Sound:"), check_music->x + WIDGET_CHECK_WIDTH + 10, - WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); - check_sound = - newWidgetCheck(label_sound->x + label_sound->w + 10, - WINDOW_SIZE_Y - 80, isSoundActive(), eventWidget); - label_ai = - newWidgetLabel(_("AI:"), check_sound->x + WIDGET_CHECK_WIDTH + 10, - WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); + label_music = + newWidgetLabel(_("Music:"), 100, WINDOW_SIZE_Y - 85, + WIDGET_LABEL_LEFT); + check_music = + newWidgetCheck(label_music->x + label_music->w + 10, + WINDOW_SIZE_Y - 80, isMusicActive(), eventWidget); + label_sound = + newWidgetLabel(_("Sound:"), check_music->x + WIDGET_CHECK_WIDTH + 10, + WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); + check_sound = + newWidgetCheck(label_sound->x + label_sound->w + 10, + WINDOW_SIZE_Y - 80, isSoundActive(), eventWidget); + label_ai = + newWidgetLabel(_("AI:"), check_sound->x + WIDGET_CHECK_WIDTH + 10, + WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); #else - label_ai = - newWidgetLabel(_("AI:"), 100, WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); + label_ai = + newWidgetLabel(_("AI:"), 100, WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); #endif - check_ai = - newWidgetCheck(label_ai->x + label_ai->w + 10, WINDOW_SIZE_Y - 80, - FALSE, eventWidget); - - label_count_round = - newWidgetLabel(_("No. of rounds:"), 100, WINDOW_SIZE_Y - 200, - WIDGET_LABEL_LEFT); - label_name_player1 = - newWidgetLabel(_("Player 1:"), 100, WINDOW_SIZE_Y - 160, - WIDGET_LABEL_LEFT); - label_name_player2 = - newWidgetLabel(_("Player 2:"), 100, WINDOW_SIZE_Y - 120, - WIDGET_LABEL_LEFT); - - textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), - WIDGET_TEXTFIELD_FILTER_NUM, - 110 + label_count_round->w, - WINDOW_SIZE_Y - 200); - - textfield_name_player1 = - newWidgetTextfield(getParamElse("--name1", NAME_PLAYER_RIGHT), - WIDGET_TEXTFIELD_FILTER_ALPHANUM, - 110 + label_count_round->w, WINDOW_SIZE_Y - 160); - - textfield_name_player2 = - newWidgetTextfield(getParamElse("--name2", NAME_PLAYER_LEFT), - WIDGET_TEXTFIELD_FILTER_ALPHANUM, - 110 + label_count_round->w, WINDOW_SIZE_Y - 120); - - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - int x = 0; - int y = 0; - - if (i >= GUN_DUAL_SIMPLE && i <= GUN_TOMMY) { - x = 100; - y = 200 + (i - GUN_DUAL_SIMPLE) * 50; - } - - if (i >= GUN_LASSER && i <= GUN_BOMBBALL) { - x = 250; - y = 200 + (i - GUN_LASSER) * 50; - } - - check[i] = newWidgetCheck(x, y, TRUE, NULL); - } - - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - int x = 0; - int y = 0; - - if (i >= BONUS_SPEED && i <= BONUS_TELEPORT) { - x = 430; - y = 200 + (i - BONUS_SPEED) * 50; - } - - if (i >= BONUS_GHOST && i <= BONUS_HIDDEN) { - x = 580; - y = 200 + (i - BONUS_GHOST) * 50; - } - - check[i] = newWidgetCheck(x, y, TRUE, NULL); - } - - image_gun_dual_revolver = - newWidgetImage(110 + WIDGET_CHECK_WIDTH, 200, - getImage(IMAGE_GROUP_BASE, "panel_dual")); - image_gun_scatter = - newWidgetImage(110 + WIDGET_CHECK_WIDTH, 250, - getImage(IMAGE_GROUP_BASE, "panel_scatter")); - image_gun_tommy = - newWidgetImage(110 + WIDGET_CHECK_WIDTH, 300, - getImage(IMAGE_GROUP_BASE, "panel_tommy")); - image_gun_lasser = - newWidgetImage(260 + WIDGET_CHECK_WIDTH, 200, - getImage(IMAGE_GROUP_BASE, "panel_lasser")); - image_gun_mine = - newWidgetImage(260 + WIDGET_CHECK_WIDTH, 250, - getImage(IMAGE_GROUP_BASE, "panel_mine")); - image_gun_bombball = - newWidgetImage(260 + WIDGET_CHECK_WIDTH, 300, - getImage(IMAGE_GROUP_BASE, "panel_bombball")); - - image_bonus_speed = - newWidgetImage(430 + WIDGET_CHECK_WIDTH, 200, - getImage(IMAGE_GROUP_BASE, "panel_speed"));; - image_bonus_shot = - newWidgetImage(430 + WIDGET_CHECK_WIDTH, 250, - getImage(IMAGE_GROUP_BASE, "panel_shot"));; - image_bonus_teleport = - newWidgetImage(430 + WIDGET_CHECK_WIDTH, 300, - getImage(IMAGE_GROUP_BASE, "panel_teleport"));; - image_bonus_ghost = - newWidgetImage(580 + WIDGET_CHECK_WIDTH, 200, - getImage(IMAGE_GROUP_BASE, "panel_ghost"));; - image_bonus_4x = - newWidgetImage(580 + WIDGET_CHECK_WIDTH, 250, - getImage(IMAGE_GROUP_BASE, "panel_4x"));; - image_bonus_hidden = - newWidgetImage(580 + WIDGET_CHECK_WIDTH, 300, - getImage(IMAGE_GROUP_BASE, "panel_hidden"));; - - registerScreen(newScreen - ("setting", startScreenSetting, eventScreenSetting, - drawScreenSetting, stopScreenSetting)); - - initSettingFile(); + check_ai = + newWidgetCheck(label_ai->x + label_ai->w + 10, WINDOW_SIZE_Y - 80, + FALSE, eventWidget); + + label_count_round = + newWidgetLabel(_("No. of rounds:"), 100, WINDOW_SIZE_Y - 200, + WIDGET_LABEL_LEFT); + label_name_player1 = + newWidgetLabel(_("Player 1:"), 100, WINDOW_SIZE_Y - 160, + WIDGET_LABEL_LEFT); + label_name_player2 = + newWidgetLabel(_("Player 2:"), 100, WINDOW_SIZE_Y - 120, + WIDGET_LABEL_LEFT); + + textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), + WIDGET_TEXTFIELD_FILTER_NUM, + 110 + label_count_round->w, + WINDOW_SIZE_Y - 200); + + textfield_name_player1 = + newWidgetTextfield(getParamElse("--name1", NAME_PLAYER_RIGHT), + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + 110 + label_count_round->w, WINDOW_SIZE_Y - 160); + + textfield_name_player2 = + newWidgetTextfield(getParamElse("--name2", NAME_PLAYER_LEFT), + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + 110 + label_count_round->w, WINDOW_SIZE_Y - 120); + + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + int x = 0; + int y = 0; + + if (i >= GUN_DUAL_SIMPLE && i <= GUN_TOMMY) { + x = 100; + y = 200 + (i - GUN_DUAL_SIMPLE) * 50; + } + + if (i >= GUN_LASSER && i <= GUN_BOMBBALL) { + x = 250; + y = 200 + (i - GUN_LASSER) * 50; + } + + check[i] = newWidgetCheck(x, y, TRUE, NULL); + } + + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + int x = 0; + int y = 0; + + if (i >= BONUS_SPEED && i <= BONUS_TELEPORT) { + x = 430; + y = 200 + (i - BONUS_SPEED) * 50; + } + + if (i >= BONUS_GHOST && i <= BONUS_HIDDEN) { + x = 580; + y = 200 + (i - BONUS_GHOST) * 50; + } + + check[i] = newWidgetCheck(x, y, TRUE, NULL); + } + + image_gun_dual_revolver = + newWidgetImage(110 + WIDGET_CHECK_WIDTH, 200, + getImage(IMAGE_GROUP_BASE, "panel_dual")); + image_gun_scatter = + newWidgetImage(110 + WIDGET_CHECK_WIDTH, 250, + getImage(IMAGE_GROUP_BASE, "panel_scatter")); + image_gun_tommy = + newWidgetImage(110 + WIDGET_CHECK_WIDTH, 300, + getImage(IMAGE_GROUP_BASE, "panel_tommy")); + image_gun_lasser = + newWidgetImage(260 + WIDGET_CHECK_WIDTH, 200, + getImage(IMAGE_GROUP_BASE, "panel_lasser")); + image_gun_mine = + newWidgetImage(260 + WIDGET_CHECK_WIDTH, 250, + getImage(IMAGE_GROUP_BASE, "panel_mine")); + image_gun_bombball = + newWidgetImage(260 + WIDGET_CHECK_WIDTH, 300, + getImage(IMAGE_GROUP_BASE, "panel_bombball")); + + image_bonus_speed = + newWidgetImage(430 + WIDGET_CHECK_WIDTH, 200, + getImage(IMAGE_GROUP_BASE, "panel_speed"));; + image_bonus_shot = + newWidgetImage(430 + WIDGET_CHECK_WIDTH, 250, + getImage(IMAGE_GROUP_BASE, "panel_shot"));; + image_bonus_teleport = + newWidgetImage(430 + WIDGET_CHECK_WIDTH, 300, + getImage(IMAGE_GROUP_BASE, "panel_teleport"));; + image_bonus_ghost = + newWidgetImage(580 + WIDGET_CHECK_WIDTH, 200, + getImage(IMAGE_GROUP_BASE, "panel_ghost"));; + image_bonus_4x = + newWidgetImage(580 + WIDGET_CHECK_WIDTH, 250, + getImage(IMAGE_GROUP_BASE, "panel_4x"));; + image_bonus_hidden = + newWidgetImage(580 + WIDGET_CHECK_WIDTH, 300, + getImage(IMAGE_GROUP_BASE, "panel_hidden"));; + + registerScreen(newScreen + ("setting", startScreenSetting, eventScreenSetting, + drawScreenSetting, stopScreenSetting)); + + initSettingFile(); #ifndef NO_SOUND - eventWidget(check_music); - eventWidget(check_sound); + eventWidget(check_music); + eventWidget(check_sound); #endif } -void -getSettingNameRight(char *s) +void getSettingNameRight(char *s) { - strcpy(s, getTextFromWidgetTextfield(textfield_name_player1)); + strcpy(s, getTextFromWidgetTextfield(textfield_name_player1)); } -void -getSettingNameLeft(char *s) +void getSettingNameLeft(char *s) { - if (getWidgetCheckStatus(check_ai)) { - strcpy(s, NAME_AI); - } - else { - strcpy(s, getTextFromWidgetTextfield(textfield_name_player2)); - } + if (getWidgetCheckStatus(check_ai)) { + strcpy(s, NAME_AI); + } else { + strcpy(s, getTextFromWidgetTextfield(textfield_name_player2)); + } } -void -getSettingCountRound(int *n) +void getSettingCountRound(int *n) { - *n = atoi(getTextFromWidgetTextfield(textfield_count_cound)); + *n = atoi(getTextFromWidgetTextfield(textfield_count_cound)); } -bool_t -isSettingAI() +bool_t isSettingAI() { - return getWidgetCheckStatus(check_ai); + return getWidgetCheckStatus(check_ai); } -bool_t -isSettingAnyItem() +bool_t isSettingAnyItem() { - int i; + int i; - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - if (getWidgetCheckStatus(check[i]) == TRUE) { - return TRUE; - } - } + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + if (getWidgetCheckStatus(check[i]) == TRUE) { + return TRUE; + } + } - for (i = BONUS_SPEED; i < BONUS_HIDDEN; i++) { - if (getWidgetCheckStatus(check[i]) == TRUE) { - return TRUE; - } - } + for (i = BONUS_SPEED; i < BONUS_HIDDEN; i++) { + if (getWidgetCheckStatus(check[i]) == TRUE) { + return TRUE; + } + } - return FALSE; + return FALSE; } -bool_t -isSettingItem(int item) +bool_t isSettingItem(int item) { - return getWidgetCheckStatus(check[item]); + return getWidgetCheckStatus(check[item]); } -void -quitScreenSetting() +void quitScreenSetting() { - int i; + int i; - saveAndDestroyConfigFile(); + saveAndDestroyConfigFile(); - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetLabel(label_count_round); - destroyWidgetLabel(label_name_player1); - destroyWidgetLabel(label_ai); + destroyWidgetLabel(label_count_round); + destroyWidgetLabel(label_name_player1); + destroyWidgetLabel(label_ai); #ifndef NO_SOUND - destroyWidgetLabel(label_music); - destroyWidgetLabel(label_sound); + destroyWidgetLabel(label_music); + destroyWidgetLabel(label_sound); #endif - destroyWidgetLabel(label_name_player2); - destroyWidgetTextfield(textfield_name_player2); - - destroyWidgetTextfield(textfield_name_player1); - destroyWidgetTextfield(textfield_count_cound); - - destroyWidgetImage(image_gun_dual_revolver); - destroyWidgetImage(image_gun_scatter); - destroyWidgetImage(image_gun_tommy); - destroyWidgetImage(image_gun_lasser); - destroyWidgetImage(image_gun_mine); - destroyWidgetImage(image_gun_bombball); - - destroyWidgetImage(image_bonus_speed); - destroyWidgetImage(image_bonus_shot); - destroyWidgetImage(image_bonus_teleport); - destroyWidgetImage(image_bonus_ghost); - destroyWidgetImage(image_bonus_4x); - destroyWidgetImage(image_bonus_hidden); + destroyWidgetLabel(label_name_player2); + destroyWidgetTextfield(textfield_name_player2); + + destroyWidgetTextfield(textfield_name_player1); + destroyWidgetTextfield(textfield_count_cound); + + destroyWidgetImage(image_gun_dual_revolver); + destroyWidgetImage(image_gun_scatter); + destroyWidgetImage(image_gun_tommy); + destroyWidgetImage(image_gun_lasser); + destroyWidgetImage(image_gun_mine); + destroyWidgetImage(image_gun_bombball); + + destroyWidgetImage(image_bonus_speed); + destroyWidgetImage(image_bonus_shot); + destroyWidgetImage(image_bonus_teleport); + destroyWidgetImage(image_bonus_ghost); + destroyWidgetImage(image_bonus_4x); + destroyWidgetImage(image_bonus_hidden); #ifndef NO_SOUND - destroyWidgetCheck(check_music); - destroyWidgetCheck(check_sound); + destroyWidgetCheck(check_music); + destroyWidgetCheck(check_sound); #endif - destroyWidgetCheck(check_ai); + destroyWidgetCheck(check_ai); - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - destroyWidgetCheck(check[i]); - } + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + destroyWidgetCheck(check[i]); + } - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - destroyWidgetCheck(check[i]); - } + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + destroyWidgetCheck(check[i]); + } - destroyWidgetButton(button_back); - destroyWidgetButton(button_keys); + destroyWidgetButton(button_back); + destroyWidgetButton(button_keys); } diff --git a/src/screen/screen_setting.h b/src/screen/screen_setting.h index 7381d82..9521cca 100644 --- a/src/screen/screen_setting.h +++ b/src/screen/screen_setting.h @@ -1,13 +1,13 @@ #ifndef SCREEN_SETTING -#define SCREEN_SETTING +# define SCREEN_SETTING -#include "main.h" +# include "main.h" -#define NAME_AI "TuxBot" -#define NAME_PLAYER_RIGHT "Name1" -#define NAME_PLAYER_LEFT "Name2" +# define NAME_AI "TuxBot" +# define NAME_PLAYER_RIGHT "Name1" +# define NAME_PLAYER_LEFT "Name2" extern void initScreenSetting(); extern void drawScreenSetting(); diff --git a/src/screen/screen_settingKeys.c b/src/screen/screen_settingKeys.c index 4ac13e8..5bfc802 100644 --- a/src/screen/screen_settingKeys.c +++ b/src/screen/screen_settingKeys.c @@ -2,7 +2,7 @@ #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
-
+
#include "main.h"
#include "list.h"
#include "tux.h"
@@ -14,13 +14,13 @@ #include "screen.h"
#include "image.h"
#ifndef NO_SOUND
-#include "music.h"
-#include "sound.h"
-#endif /*
*/ +# include "music.h"
+# include "sound.h"
+#endif /*
*/ #include "screen_mainMenu.h"
#include "screen_setting.h"
#include "screen_settingKeys.h"
-
+
#include "widget.h"
#include "widget_button.h"
#include "widget_image.h"
@@ -65,77 +65,76 @@ static widget_t *tux_right_keyup_val; // todo add key images
// possible variant will be reusing widget_image for current widget_label so there wont
// be key names but only images
-
void -startScreenSettingKeys()
+
void startScreenSettingKeys()
{ -
+
#ifndef NO_SOUND
- playMusic("menu", MUSIC_GROUP_BASE); -
-#endif /*
*/ + playMusic("menu", MUSIC_GROUP_BASE); +
+#endif /*
*/ }
static void -setKeytableFromConfigFile(textFile_t * configFile)
+ setKeytableFromConfigFile(textFile_t * configFile)
{ -
char val[STR_SIZE]; -
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_UP", val, STR_SIZE, - "273"); -
keytable[KEY_TUX_RIGHT_MOVE_UP] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", val, - STR_SIZE, "275"); -
keytable[KEY_TUX_RIGHT_MOVE_RIGHT] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", val, STR_SIZE, - "276"); -
keytable[KEY_TUX_RIGHT_MOVE_LEFT] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", val, STR_SIZE, - "274"); -
keytable[KEY_TUX_RIGHT_MOVE_DOWN] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_RIGHT_SHOOT", val, STR_SIZE, - "48"); -
keytable[KEY_TUX_RIGHT_SHOOT] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", val, - STR_SIZE, "49"); -
keytable[KEY_TUX_RIGHT_SWITCH_WEAPON] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_UP", val, STR_SIZE, - "119"); -
keytable[KEY_TUX_LEFT_MOVE_UP] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", val, STR_SIZE, - "100"); -
keytable[KEY_TUX_LEFT_MOVE_RIGHT] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", val, STR_SIZE, - "97"); -
keytable[KEY_TUX_LEFT_MOVE_LEFT] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", val, STR_SIZE, - "115"); -
keytable[KEY_TUX_LEFT_MOVE_DOWN] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_LEFT_SHOOT", val, STR_SIZE, - "113"); -
keytable[KEY_TUX_LEFT_SHOOT] = atoi(val); -
loadValueFromConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", val, - STR_SIZE, "9"); -
keytable[KEY_TUX_LEFT_SWITCH_WEAPON] = atoi(val); +
char val[STR_SIZE]; +
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_UP", val, STR_SIZE, + "273"); +
keytable[KEY_TUX_RIGHT_MOVE_UP] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", val, + STR_SIZE, "275"); +
keytable[KEY_TUX_RIGHT_MOVE_RIGHT] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", val, STR_SIZE, + "276"); +
keytable[KEY_TUX_RIGHT_MOVE_LEFT] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", val, STR_SIZE, + "274"); +
keytable[KEY_TUX_RIGHT_MOVE_DOWN] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_RIGHT_SHOOT", val, STR_SIZE, + "48"); +
keytable[KEY_TUX_RIGHT_SHOOT] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", val, + STR_SIZE, "49"); +
keytable[KEY_TUX_RIGHT_SWITCH_WEAPON] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_UP", val, STR_SIZE, + "119"); +
keytable[KEY_TUX_LEFT_MOVE_UP] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", val, STR_SIZE, + "100"); +
keytable[KEY_TUX_LEFT_MOVE_RIGHT] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", val, STR_SIZE, + "97"); +
keytable[KEY_TUX_LEFT_MOVE_LEFT] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", val, STR_SIZE, + "115"); +
keytable[KEY_TUX_LEFT_MOVE_DOWN] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_LEFT_SHOOT", val, STR_SIZE, + "113"); +
keytable[KEY_TUX_LEFT_SHOOT] = atoi(val); +
loadValueFromConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", val, + STR_SIZE, "9"); +
keytable[KEY_TUX_LEFT_SWITCH_WEAPON] = atoi(val);
}
void -initKeyTable()
+ initKeyTable()
{ -
char path[STR_PATH_SIZE]; -
+
char path[STR_PATH_SIZE]; +
/*
int i;
*/
- sprintf(path, "%s/keycontrol.conf", getHomeDirector()); -
keycontrolFile = loadTextFile(path); -
if (keycontrolFile == NULL) { -
fprintf(stderr, _("I was unable to load file: %s\n"), path); -
fprintf(stderr, _("I try to create file: %s\n"), path); -
keycontrolFile = newTextFile(path); -
} -
if (keycontrolFile == NULL) { -
fprintf(stderr, _("I was unable to create file: %s\n"), path); -
return; -
} -
setKeytableFromConfigFile(keycontrolFile); -
+ sprintf(path, "%s/keycontrol.conf", getHomeDirector()); +
keycontrolFile = loadTextFile(path); +
if (keycontrolFile == NULL) { +
fprintf(stderr, _("I was unable to load file: %s\n"), path); +
fprintf(stderr, _("I try to create file: %s\n"), path); +
keycontrolFile = newTextFile(path); +
} +
if (keycontrolFile == NULL) { +
fprintf(stderr, _("I was unable to create file: %s\n"), path); +
return; +
} +
setKeytableFromConfigFile(keycontrolFile); +
/*
for( i = 0 ; i < KEY_LENGTH ; i++)
{
@@ -143,284 +142,280 @@ initKeyTable() }
*/
} -
int -getKey(int n)
+
int getKey(int n)
{ -
+
// printf("keytable[n] = %d\n", keytable[n]);
- return keytable[n]; + return keytable[n];
} -
void -drawScreenSettingKeys()
+
void drawScreenSettingKeys()
{ -
drawWidgetImage(image_backgorund); -
drawWidgetButton(button_back); -
- // key names
- drawWidgetLabel(tux_right); -
drawWidgetLabel(tux_left); -
drawWidgetLabel(tux_right_keyup); -
drawWidgetLabel(tux_right_keydown); -
drawWidgetLabel(tux_right_keyleft); -
drawWidgetLabel(tux_right_keyright); -
drawWidgetLabel(tux_right_keyswitch); -
drawWidgetLabel(tux_right_keyfire); -
drawWidgetLabel(tux_left_keyup); -
drawWidgetLabel(tux_left_keydown); -
drawWidgetLabel(tux_left_keyleft); -
drawWidgetLabel(tux_left_keyright); -
drawWidgetLabel(tux_left_keyswitch); -
drawWidgetLabel(tux_left_keyfire); -
- // key values
- drawWidgetCatchkey(tux_right_keyup_val); -
drawWidgetCatchkey(tux_right_keydown_val); -
drawWidgetCatchkey(tux_right_keyleft_val); -
drawWidgetCatchkey(tux_right_keyright_val); -
drawWidgetCatchkey(tux_right_keyswitch_val); -
drawWidgetCatchkey(tux_right_keyfire_val); -
drawWidgetCatchkey(tux_left_keyup_val); -
drawWidgetCatchkey(tux_left_keydown_val); -
drawWidgetCatchkey(tux_left_keyleft_val); -
drawWidgetCatchkey(tux_left_keyright_val); -
drawWidgetCatchkey(tux_left_keyswitch_val); -
drawWidgetCatchkey(tux_left_keyfire_val); +
drawWidgetImage(image_backgorund); +
drawWidgetButton(button_back); +
+ // key names
+ drawWidgetLabel(tux_right); +
drawWidgetLabel(tux_left); +
drawWidgetLabel(tux_right_keyup); +
drawWidgetLabel(tux_right_keydown); +
drawWidgetLabel(tux_right_keyleft); +
drawWidgetLabel(tux_right_keyright); +
drawWidgetLabel(tux_right_keyswitch); +
drawWidgetLabel(tux_right_keyfire); +
drawWidgetLabel(tux_left_keyup); +
drawWidgetLabel(tux_left_keydown); +
drawWidgetLabel(tux_left_keyleft); +
drawWidgetLabel(tux_left_keyright); +
drawWidgetLabel(tux_left_keyswitch); +
drawWidgetLabel(tux_left_keyfire); +
+ // key values
+ drawWidgetCatchkey(tux_right_keyup_val); +
drawWidgetCatchkey(tux_right_keydown_val); +
drawWidgetCatchkey(tux_right_keyleft_val); +
drawWidgetCatchkey(tux_right_keyright_val); +
drawWidgetCatchkey(tux_right_keyswitch_val); +
drawWidgetCatchkey(tux_right_keyfire_val); +
drawWidgetCatchkey(tux_left_keyup_val); +
drawWidgetCatchkey(tux_left_keydown_val); +
drawWidgetCatchkey(tux_left_keyleft_val); +
drawWidgetCatchkey(tux_left_keyright_val); +
drawWidgetCatchkey(tux_left_keyswitch_val); +
drawWidgetCatchkey(tux_left_keyfire_val);
}
static void -refreshKeytable()
+ refreshKeytable()
{ -
keytable[6] = getWidgetCatchKey(tux_left_keyup_val); -
keytable[9] = getWidgetCatchKey(tux_left_keydown_val); -
keytable[8] = getWidgetCatchKey(tux_left_keyleft_val); -
keytable[7] = getWidgetCatchKey(tux_left_keyright_val); -
keytable[10] = getWidgetCatchKey(tux_left_keyfire_val); -
keytable[11] = getWidgetCatchKey(tux_left_keyswitch_val); -
keytable[0] = getWidgetCatchKey(tux_right_keyup_val); -
keytable[3] = getWidgetCatchKey(tux_right_keydown_val); -
keytable[2] = getWidgetCatchKey(tux_right_keyleft_val); -
keytable[1] = getWidgetCatchKey(tux_right_keyright_val); -
keytable[4] = getWidgetCatchKey(tux_right_keyfire_val); -
keytable[5] = getWidgetCatchKey(tux_right_keyswitch_val); -
}
static void -eventWidget(void *p)
+
keytable[6] = getWidgetCatchKey(tux_left_keyup_val); +
keytable[9] = getWidgetCatchKey(tux_left_keydown_val); +
keytable[8] = getWidgetCatchKey(tux_left_keyleft_val); +
keytable[7] = getWidgetCatchKey(tux_left_keyright_val); +
keytable[10] = getWidgetCatchKey(tux_left_keyfire_val); +
keytable[11] = getWidgetCatchKey(tux_left_keyswitch_val); +
keytable[0] = getWidgetCatchKey(tux_right_keyup_val); +
keytable[3] = getWidgetCatchKey(tux_right_keydown_val); +
keytable[2] = getWidgetCatchKey(tux_right_keyleft_val); +
keytable[1] = getWidgetCatchKey(tux_right_keyright_val); +
keytable[4] = getWidgetCatchKey(tux_right_keyfire_val); +
keytable[5] = getWidgetCatchKey(tux_right_keyswitch_val); +
}
static void eventWidget(void *p)
{ -
widget_t * button; -
widget_t * catcher; -
button = (widget_t *) (p); -
catcher = (widget_t *) (p); -
if (button == button_back) -
setScreen("setting"); -
- //events on value
- if ((catcher == tux_left_keyup_val) ||
- (catcher == tux_left_keydown_val) ||
- (catcher == tux_left_keyleft_val) ||
- (catcher == tux_left_keyright_val) ||
- (catcher == tux_left_keyfire_val) ||
- (catcher == tux_left_keyswitch_val) ||
- (catcher == tux_right_keyup_val) ||
- (catcher == tux_right_keydown_val) ||
- (catcher == tux_right_keyleft_val) ||
- (catcher == tux_right_keyright_val) ||
- (catcher == tux_right_keyswitch_val) ||
- (catcher == tux_right_keyfire_val)) { -
- // draw press any key picture
- //this will be done by widget catchkey
- // check if there is no other key with new value (what to revert if yes?)
- refreshKeytable(); -
} +
widget_t * button; +
widget_t * catcher; +
button = (widget_t *) (p); +
catcher = (widget_t *) (p); +
if (button == button_back) +
setScreen("setting"); +
+ //events on value
+ if ((catcher == tux_left_keyup_val) ||
+ (catcher == tux_left_keydown_val) ||
+ (catcher == tux_left_keyleft_val) ||
+ (catcher == tux_left_keyright_val) ||
+ (catcher == tux_left_keyfire_val) ||
+ (catcher == tux_left_keyswitch_val) ||
+ (catcher == tux_right_keyup_val) ||
+ (catcher == tux_right_keydown_val) ||
+ (catcher == tux_right_keyleft_val) ||
+ (catcher == tux_right_keyright_val) ||
+ (catcher == tux_right_keyswitch_val) ||
+ (catcher == tux_right_keyfire_val)) { +
+ // draw press any key picture
+ //this will be done by widget catchkey
+ // check if there is no other key with new value (what to revert if yes?)
+ refreshKeytable(); +
}
} -
void -eventScreenSettingKeys()
+
void eventScreenSettingKeys()
{ -
eventWidgetButton(button_back); -
eventWidgetCatchkey(tux_right_keyup_val); -
eventWidgetCatchkey(tux_right_keydown_val); -
eventWidgetCatchkey(tux_right_keyleft_val); -
eventWidgetCatchkey(tux_right_keyright_val); -
eventWidgetCatchkey(tux_right_keyswitch_val); -
eventWidgetCatchkey(tux_right_keyfire_val); -
eventWidgetCatchkey(tux_left_keyup_val); -
eventWidgetCatchkey(tux_left_keydown_val); -
eventWidgetCatchkey(tux_left_keyleft_val); -
eventWidgetCatchkey(tux_left_keyright_val); -
eventWidgetCatchkey(tux_left_keyswitch_val); -
eventWidgetCatchkey(tux_left_keyfire_val); +
eventWidgetButton(button_back); +
eventWidgetCatchkey(tux_right_keyup_val); +
eventWidgetCatchkey(tux_right_keydown_val); +
eventWidgetCatchkey(tux_right_keyleft_val); +
eventWidgetCatchkey(tux_right_keyright_val); +
eventWidgetCatchkey(tux_right_keyswitch_val); +
eventWidgetCatchkey(tux_right_keyfire_val); +
eventWidgetCatchkey(tux_left_keyup_val); +
eventWidgetCatchkey(tux_left_keydown_val); +
eventWidgetCatchkey(tux_left_keyleft_val); +
eventWidgetCatchkey(tux_left_keyright_val); +
eventWidgetCatchkey(tux_left_keyswitch_val); +
eventWidgetCatchkey(tux_left_keyfire_val);
}
void -stopScreenSettingKeys()
+ stopScreenSettingKeys()
{
}
void -initScreenSettingKeys()
+ initScreenSettingKeys()
{ -
image_t * image; -
initKeyTable(); -
image = getImage(IMAGE_GROUP_BASE, "screen_main"); -
image_backgorund = newWidgetImage(0, 0, image); -
button_back = - newWidgetButton(_("Back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); -
tux_left = - newWidgetLabel(_("Player 2"), WINDOW_SIZE_X / 4, 150, - WIDGET_LABEL_CENTER); -
tux_left_keyup = - newWidgetLabel(_("Up"), 50, tux_left->y + 50, WIDGET_LABEL_LEFT); -
tux_left_keydown = - newWidgetLabel(_("Down:"), tux_left_keyup->x, tux_left_keyup->y + 20, - WIDGET_LABEL_LEFT); -
tux_left_keyleft = - newWidgetLabel(_("Left:"), tux_left_keyup->x, - tux_left_keydown->y + 20, WIDGET_LABEL_LEFT); -
tux_left_keyright = - newWidgetLabel(_("Right:"), tux_left_keyup->x, - tux_left_keyleft->y + 20, WIDGET_LABEL_LEFT); -
tux_left_keyfire = - newWidgetLabel(_("Fire gun:"), tux_left_keyup->x, - tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); -
tux_left_keyswitch = - newWidgetLabel(_("Switch gun:"), tux_left_keyup->x, - tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); -
tux_right = - newWidgetLabel(_("Player 1"), WINDOW_SIZE_X / 2 + WINDOW_SIZE_X / 4, - tux_left->y, WIDGET_LABEL_CENTER); -
tux_right_keyup = - newWidgetLabel(_("Up:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left->y + 50, WIDGET_LABEL_LEFT); -
tux_right_keydown = - newWidgetLabel(_("Down:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left_keyup->y + 20, WIDGET_LABEL_LEFT); -
tux_right_keyleft = - newWidgetLabel(_("Left:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_right_keydown->y + 20, WIDGET_LABEL_LEFT); -
tux_right_keyright = - newWidgetLabel(_("Right:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_right_keyleft->y + 20, WIDGET_LABEL_LEFT); -
tux_right_keyfire = - newWidgetLabel(_("Fire gun:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); -
tux_right_keyswitch = - newWidgetLabel(_("Switch gun:"), - WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); -
tux_left_keyup_val = - newWidgetCatchkey(keytable[6], tux_left_keyup->x + 200, - tux_left->y + 50, eventWidget); -
tux_left_keydown_val = - newWidgetCatchkey(keytable[9], tux_left_keyup_val->x, - tux_left_keyup->y + 20, eventWidget); -
tux_left_keyleft_val = - newWidgetCatchkey(keytable[8], tux_left_keyup_val->x, - tux_left_keydown->y + 20, eventWidget); -
tux_left_keyright_val = - newWidgetCatchkey(keytable[7], tux_left_keyup_val->x, - tux_left_keyleft->y + 20, eventWidget); -
tux_left_keyfire_val = - newWidgetCatchkey(keytable[10], tux_left_keyup_val->x, - tux_left_keyright->y + 20, eventWidget); -
tux_left_keyswitch_val = - newWidgetCatchkey(keytable[11], tux_left_keyup_val->x, - tux_left_keyfire->y + 20, eventWidget); -
tux_right_keyup_val = - newWidgetCatchkey(keytable[0], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left->y + 50, eventWidget); -
tux_right_keydown_val = - newWidgetCatchkey(keytable[3], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left_keyup->y + 20, eventWidget); -
tux_right_keyleft_val = - newWidgetCatchkey(keytable[2], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_right_keydown->y + 20, eventWidget); -
tux_right_keyright_val = - newWidgetCatchkey(keytable[1], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_right_keyleft->y + 20, eventWidget); -
tux_right_keyfire_val = - newWidgetCatchkey(keytable[4], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left_keyright->y + 20, eventWidget); -
tux_right_keyswitch_val = - newWidgetCatchkey(keytable[5], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left_keyfire->y + 20, eventWidget); -
registerScreen(newScreen - ("settingKeys", startScreenSettingKeys, - eventScreenSettingKeys,
drawScreenSettingKeys, - stopScreenSettingKeys)); +
image_t * image; +
initKeyTable(); +
image = getImage(IMAGE_GROUP_BASE, "screen_main"); +
image_backgorund = newWidgetImage(0, 0, image); +
button_back = + newWidgetButton(_("Back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); +
tux_left = + newWidgetLabel(_("Player 2"), WINDOW_SIZE_X / 4, 150, + WIDGET_LABEL_CENTER); +
tux_left_keyup = + newWidgetLabel(_("Up"), 50, tux_left->y + 50, WIDGET_LABEL_LEFT); +
tux_left_keydown = + newWidgetLabel(_("Down:"), tux_left_keyup->x, tux_left_keyup->y + 20, + WIDGET_LABEL_LEFT); +
tux_left_keyleft = + newWidgetLabel(_("Left:"), tux_left_keyup->x, + tux_left_keydown->y + 20, WIDGET_LABEL_LEFT); +
tux_left_keyright = + newWidgetLabel(_("Right:"), tux_left_keyup->x, + tux_left_keyleft->y + 20, WIDGET_LABEL_LEFT); +
tux_left_keyfire = + newWidgetLabel(_("Fire gun:"), tux_left_keyup->x, + tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); +
tux_left_keyswitch = + newWidgetLabel(_("Switch gun:"), tux_left_keyup->x, + tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); +
tux_right = + newWidgetLabel(_("Player 1"), WINDOW_SIZE_X / 2 + WINDOW_SIZE_X / 4, + tux_left->y, WIDGET_LABEL_CENTER); +
tux_right_keyup = + newWidgetLabel(_("Up:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left->y + 50, WIDGET_LABEL_LEFT); +
tux_right_keydown = + newWidgetLabel(_("Down:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left_keyup->y + 20, WIDGET_LABEL_LEFT); +
tux_right_keyleft = + newWidgetLabel(_("Left:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_right_keydown->y + 20, WIDGET_LABEL_LEFT); +
tux_right_keyright = + newWidgetLabel(_("Right:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_right_keyleft->y + 20, WIDGET_LABEL_LEFT); +
tux_right_keyfire = + newWidgetLabel(_("Fire gun:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); +
tux_right_keyswitch = + newWidgetLabel(_("Switch gun:"), + WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); +
tux_left_keyup_val = + newWidgetCatchkey(keytable[6], tux_left_keyup->x + 200, + tux_left->y + 50, eventWidget); +
tux_left_keydown_val = + newWidgetCatchkey(keytable[9], tux_left_keyup_val->x, + tux_left_keyup->y + 20, eventWidget); +
tux_left_keyleft_val = + newWidgetCatchkey(keytable[8], tux_left_keyup_val->x, + tux_left_keydown->y + 20, eventWidget); +
tux_left_keyright_val = + newWidgetCatchkey(keytable[7], tux_left_keyup_val->x, + tux_left_keyleft->y + 20, eventWidget); +
tux_left_keyfire_val = + newWidgetCatchkey(keytable[10], tux_left_keyup_val->x, + tux_left_keyright->y + 20, eventWidget); +
tux_left_keyswitch_val = + newWidgetCatchkey(keytable[11], tux_left_keyup_val->x, + tux_left_keyfire->y + 20, eventWidget); +
tux_right_keyup_val = + newWidgetCatchkey(keytable[0], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left->y + 50, eventWidget); +
tux_right_keydown_val = + newWidgetCatchkey(keytable[3], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left_keyup->y + 20, eventWidget); +
tux_right_keyleft_val = + newWidgetCatchkey(keytable[2], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_right_keydown->y + 20, eventWidget); +
tux_right_keyright_val = + newWidgetCatchkey(keytable[1], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_right_keyleft->y + 20, eventWidget); +
tux_right_keyfire_val = + newWidgetCatchkey(keytable[4], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left_keyright->y + 20, eventWidget); +
tux_right_keyswitch_val = + newWidgetCatchkey(keytable[5], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left_keyfire->y + 20, eventWidget); +
registerScreen(newScreen + ("settingKeys", startScreenSettingKeys, + eventScreenSettingKeys,
drawScreenSettingKeys, + stopScreenSettingKeys));
}
void -quitKeyTable()
+ quitKeyTable()
{ -
destroyTextFile(keycontrolFile); +
destroyTextFile(keycontrolFile);
}
void -saveKeyTable(textFile_t * configFile) + saveKeyTable(textFile_t * configFile) { -
char str[STR_SIZE]; -
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyup_val)); -
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_UP", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_left_keydown_val)); -
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyleft_val)); -
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyright_val)); -
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyfire_val)); -
setValueInConfigFile(configFile, "TUX_LEFT_SHOOT", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyswitch_val)); -
setValueInConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyup_val)); -
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_UP", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_right_keydown_val)); -
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyleft_val)); -
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyright_val)); -
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyfire_val)); -
setValueInConfigFile(configFile, "TUX_RIGHT_SHOOT", str); -
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyswitch_val)); -
setValueInConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", str); -
saveTextFile(configFile); +
char str[STR_SIZE]; +
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyup_val)); +
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_UP", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_left_keydown_val)); +
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyleft_val)); +
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyright_val)); +
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyfire_val)); +
setValueInConfigFile(configFile, "TUX_LEFT_SHOOT", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_left_keyswitch_val)); +
setValueInConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyup_val)); +
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_UP", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_right_keydown_val)); +
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyleft_val)); +
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyright_val)); +
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyfire_val)); +
setValueInConfigFile(configFile, "TUX_RIGHT_SHOOT", str); +
sprintf(str, "%d", getWidgetCatchKey(tux_right_keyswitch_val)); +
setValueInConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", str); +
saveTextFile(configFile);
}
void -quitScreenSettingKeys()
+ quitScreenSettingKeys()
{ -
saveKeyTable(keycontrolFile); -
quitKeyTable(); -
- // key names
- destroyWidgetImage(image_backgorund); -
destroyWidgetLabel(tux_right); -
destroyWidgetLabel(tux_left); -
destroyWidgetLabel(tux_right_keyup); -
destroyWidgetLabel(tux_right_keydown); -
destroyWidgetLabel(tux_right_keyleft); -
destroyWidgetLabel(tux_right_keyright); -
destroyWidgetLabel(tux_right_keyswitch); -
destroyWidgetLabel(tux_right_keyfire); -
destroyWidgetLabel(tux_left_keyup); -
destroyWidgetLabel(tux_left_keydown); -
destroyWidgetLabel(tux_left_keyright); -
destroyWidgetLabel(tux_left_keyleft); -
destroyWidgetLabel(tux_left_keyswitch); -
destroyWidgetLabel(tux_left_keyfire); -
- // key values
- destroyWidgetCatchkey(tux_right_keyup_val); -
destroyWidgetCatchkey(tux_right_keydown_val); -
destroyWidgetCatchkey(tux_right_keyleft_val); -
destroyWidgetCatchkey(tux_right_keyright_val); -
destroyWidgetCatchkey(tux_right_keyswitch_val); -
destroyWidgetCatchkey(tux_right_keyfire_val); -
destroyWidgetCatchkey(tux_left_keyup_val); -
destroyWidgetCatchkey(tux_left_keydown_val); -
destroyWidgetCatchkey(tux_left_keyleft_val); -
destroyWidgetCatchkey(tux_left_keyright_val); -
destroyWidgetCatchkey(tux_left_keyswitch_val); -
destroyWidgetCatchkey(tux_left_keyfire_val); -
destroyWidgetButton(button_back); +
saveKeyTable(keycontrolFile); +
quitKeyTable(); +
+ // key names
+ destroyWidgetImage(image_backgorund); +
destroyWidgetLabel(tux_right); +
destroyWidgetLabel(tux_left); +
destroyWidgetLabel(tux_right_keyup); +
destroyWidgetLabel(tux_right_keydown); +
destroyWidgetLabel(tux_right_keyleft); +
destroyWidgetLabel(tux_right_keyright); +
destroyWidgetLabel(tux_right_keyswitch); +
destroyWidgetLabel(tux_right_keyfire); +
destroyWidgetLabel(tux_left_keyup); +
destroyWidgetLabel(tux_left_keydown); +
destroyWidgetLabel(tux_left_keyright); +
destroyWidgetLabel(tux_left_keyleft); +
destroyWidgetLabel(tux_left_keyswitch); +
destroyWidgetLabel(tux_left_keyfire); +
+ // key values
+ destroyWidgetCatchkey(tux_right_keyup_val); +
destroyWidgetCatchkey(tux_right_keydown_val); +
destroyWidgetCatchkey(tux_right_keyleft_val); +
destroyWidgetCatchkey(tux_right_keyright_val); +
destroyWidgetCatchkey(tux_right_keyswitch_val); +
destroyWidgetCatchkey(tux_right_keyfire_val); +
destroyWidgetCatchkey(tux_left_keyup_val); +
destroyWidgetCatchkey(tux_left_keydown_val); +
destroyWidgetCatchkey(tux_left_keyleft_val); +
destroyWidgetCatchkey(tux_left_keyright_val); +
destroyWidgetCatchkey(tux_left_keyswitch_val); +
destroyWidgetCatchkey(tux_left_keyfire_val); +
destroyWidgetButton(button_back);
}
diff --git a/src/screen/screen_settingKeys.h b/src/screen/screen_settingKeys.h index 54749eb..c90006e 100644 --- a/src/screen/screen_settingKeys.h +++ b/src/screen/screen_settingKeys.h @@ -1,21 +1,21 @@ #ifndef SCREEN_SETTING_KEYS
-#define SCREEN_SETTING_KEYS
-#define KEY_TUX_RIGHT_MOVE_UP 0
-#define KEY_TUX_RIGHT_MOVE_RIGHT 1
-#define KEY_TUX_RIGHT_MOVE_LEFT 2
-#define KEY_TUX_RIGHT_MOVE_DOWN 3
-#define KEY_TUX_RIGHT_SHOOT 4
-#define KEY_TUX_RIGHT_SWITCH_WEAPON 5
-#define KEY_TUX_LEFT_MOVE_UP 6
-#define KEY_TUX_LEFT_MOVE_RIGHT 7
-#define KEY_TUX_LEFT_MOVE_LEFT 8
-#define KEY_TUX_LEFT_MOVE_DOWN 9
-#define KEY_TUX_LEFT_SHOOT 10
-#define KEY_TUX_LEFT_SWITCH_WEAPON 11
-#define KEY_LENGTH 12
-
-#include "main.h"
+# define SCREEN_SETTING_KEYS
+# define KEY_TUX_RIGHT_MOVE_UP 0
+# define KEY_TUX_RIGHT_MOVE_RIGHT 1
+# define KEY_TUX_RIGHT_MOVE_LEFT 2
+# define KEY_TUX_RIGHT_MOVE_DOWN 3
+# define KEY_TUX_RIGHT_SHOOT 4
+# define KEY_TUX_RIGHT_SWITCH_WEAPON 5
+# define KEY_TUX_LEFT_MOVE_UP 6
+# define KEY_TUX_LEFT_MOVE_RIGHT 7
+# define KEY_TUX_LEFT_MOVE_LEFT 8
+# define KEY_TUX_LEFT_MOVE_DOWN 9
+# define KEY_TUX_LEFT_SHOOT 10
+# define KEY_TUX_LEFT_SWITCH_WEAPON 11
+# define KEY_LENGTH 12
+
+# include "main.h"
extern void initScreenSettingKeys();
extern void drawScreenSettingKeys();
extern void eventScreenSettingKeys(); @@ -24,4 +24,4 @@
extern int getKey(int n);
extern void quitKeyTable(); -#endif /*
*/ +#endif /*
*/ diff --git a/src/screen/screen_table.c b/src/screen/screen_table.c index 1a5ffcd..f78d97c 100644 --- a/src/screen/screen_table.c +++ b/src/screen/screen_table.c @@ -13,7 +13,7 @@ #include "image.h" #ifndef NO_SOUND -#include "music.h" +# include "music.h" #endif #include "screen_table.h" @@ -31,212 +31,201 @@ static list_t *listWidgetLabelScore; static textFile_t *textFile; -void -startScreenTable() +void startScreenTable() { #ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); + playMusic("menu", MUSIC_GROUP_BASE); #endif } -void -drawScreenTable() +void drawScreenTable() { - int i; + int i; - drawWidgetImage(image_backgorund); + drawWidgetImage(image_backgorund); - drawWidgetButton(button_back); + drawWidgetButton(button_back); - for (i = 0; i < listWidgetLabelNumer->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetLabelNumer->list[i]; - drawWidgetLabel(this); - } + for (i = 0; i < listWidgetLabelNumer->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetLabelNumer->list[i]; + drawWidgetLabel(this); + } - for (i = 0; i < listWidgetLabelName->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetLabelName->list[i]; - drawWidgetLabel(this); - } + for (i = 0; i < listWidgetLabelName->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetLabelName->list[i]; + drawWidgetLabel(this); + } - for (i = 0; i < listWidgetLabelScore->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetLabelScore->list[i]; - drawWidgetLabel(this); - } + for (i = 0; i < listWidgetLabelScore->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetLabelScore->list[i]; + drawWidgetLabel(this); + } } -void -eventScreenTable() +void eventScreenTable() { - eventWidgetButton(button_back); + eventWidgetButton(button_back); } -void -stopScreenTable() +void stopScreenTable() { } -static void -eventWidget(void *p) +static void eventWidget(void *p) { - widget_t *button; + widget_t *button; - button = (widget_t *) (p); + button = (widget_t *) (p); - if (button == button_back) { - setScreen("mainMenu"); - } + if (button == button_back) { + setScreen("mainMenu"); + } } -static void -setWidgetLabel() +static void setWidgetLabel() { - int i; - - if (textFile == NULL) { - fprintf(stderr, _("Highscore file: \"%s\" was not loaded!"), - SCREEN_TABLE_FILE_HIGHSCORE_NAME); - - return; - } - - if (listWidgetLabelNumer != NULL || - listWidgetLabelName != NULL || listWidgetLabelScore != NULL) { - destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - } - - listWidgetLabelNumer = newList(); - listWidgetLabelName = newList(); - listWidgetLabelScore = newList(); - - for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { - widget_t *label; - char name[STR_NAME_SIZE]; - char score[STR_NUM_SIZE]; - char num[STR_NUM_SIZE]; - char *line; - - line = (char *) textFile->text->list[i]; - - sscanf(line, "%s %s", name, score); - sprintf(num, "%2d)", i + 1); - - label = - newWidgetLabel(num, WINDOW_SIZE_X / 2 - 100, 200 + i * 20, - WIDGET_LABEL_LEFT); - addList(listWidgetLabelNumer, label); - - label = - newWidgetLabel(name, WINDOW_SIZE_X / 2, 200 + i * 20, - WIDGET_LABEL_CENTER); - addList(listWidgetLabelName, label); - - label = - newWidgetLabel(score, WINDOW_SIZE_X / 2 + 80, 200 + i * 20, - WIDGET_LABEL_LEFT); - addList(listWidgetLabelScore, label); - } + int i; + + if (textFile == NULL) { + fprintf(stderr, _("Highscore file: \"%s\" was not loaded!"), + SCREEN_TABLE_FILE_HIGHSCORE_NAME); + + return; + } + + if (listWidgetLabelNumer != NULL || + listWidgetLabelName != NULL || listWidgetLabelScore != NULL) { + destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + } + + listWidgetLabelNumer = newList(); + listWidgetLabelName = newList(); + listWidgetLabelScore = newList(); + + for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { + widget_t *label; + char name[STR_NAME_SIZE]; + char score[STR_NUM_SIZE]; + char num[STR_NUM_SIZE]; + char *line; + + line = (char *) textFile->text->list[i]; + + sscanf(line, "%s %s", name, score); + sprintf(num, "%2d)", i + 1); + + label = + newWidgetLabel(num, WINDOW_SIZE_X / 2 - 100, 200 + i * 20, + WIDGET_LABEL_LEFT); + addList(listWidgetLabelNumer, label); + + label = + newWidgetLabel(name, WINDOW_SIZE_X / 2, 200 + i * 20, + WIDGET_LABEL_CENTER); + addList(listWidgetLabelName, label); + + label = + newWidgetLabel(score, WINDOW_SIZE_X / 2 + 80, 200 + i * 20, + WIDGET_LABEL_LEFT); + addList(listWidgetLabelScore, label); + } } -static void -loadHighscoreFile() +static void loadHighscoreFile() { - char path[STR_PATH_SIZE]; - int i; - - sprintf(path, "%s/" SCREEN_TABLE_FILE_HIGHSCORE_NAME, getHomeDirector()); - textFile = loadTextFile(path); - - if (textFile == NULL) { - fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); - fprintf(stderr, _("Creating: \"%s\"\n"), path); - textFile = newTextFile(path); - } - else { - return; - } - - if (textFile == NULL) { - fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); - return; - } - - for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { - addList(textFile->text, strdup("no_name 0")); - } - - saveTextFile(textFile); + char path[STR_PATH_SIZE]; + int i; + + sprintf(path, "%s/" SCREEN_TABLE_FILE_HIGHSCORE_NAME, getHomeDirector()); + textFile = loadTextFile(path); + + if (textFile == NULL) { + fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); + fprintf(stderr, _("Creating: \"%s\"\n"), path); + textFile = newTextFile(path); + } else { + return; + } + + if (textFile == NULL) { + fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); + return; + } + + for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { + addList(textFile->text, strdup("no_name 0")); + } + + saveTextFile(textFile); } -int -addPlayerInHighScore(char *name, int score) +int addPlayerInHighScore(char *name, int score) { - int i; + int i; - for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { - char *line; - char thisName[STR_NAME_SIZE]; - int thisCore; + for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { + char *line; + char thisName[STR_NAME_SIZE]; + int thisCore; - line = (char *) textFile->text->list[i]; - sscanf(line, "%s %d", thisName, &thisCore); + line = (char *) textFile->text->list[i]; + sscanf(line, "%s %d", thisName, &thisCore); - if (score >= thisCore) { - char new[STR_SIZE]; + if (score >= thisCore) { + char new[STR_SIZE]; - sprintf(new, "%s %d", name, score); - insList(textFile->text, i, strdup(new)); - delListItem(textFile->text, SCREEN_TABLE_MAX_PLAYERS, free); - setWidgetLabel(); + sprintf(new, "%s %d", name, score); + insList(textFile->text, i, strdup(new)); + delListItem(textFile->text, SCREEN_TABLE_MAX_PLAYERS, free); + setWidgetLabel(); - return 0; - } - } + return 0; + } + } - return -1; + return -1; } -void -initScreenTable() +void initScreenTable() { - image_t *image; - - image = - addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table", - IMAGE_GROUP_BASE); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), - WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 100, eventWidget); - - loadHighscoreFile(); - listWidgetLabelNumer = NULL; - listWidgetLabelName = NULL; - listWidgetLabelScore = NULL; - setWidgetLabel(); - - registerScreen(newScreen("table", startScreenTable, eventScreenTable, - drawScreenTable, stopScreenTable)); + image_t *image; + + image = + addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table", + IMAGE_GROUP_BASE); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), + WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 100, eventWidget); + + loadHighscoreFile(); + listWidgetLabelNumer = NULL; + listWidgetLabelName = NULL; + listWidgetLabelScore = NULL; + setWidgetLabel(); + + registerScreen(newScreen("table", startScreenTable, eventScreenTable, + drawScreenTable, stopScreenTable)); } -void -quitScreenTable() +void quitScreenTable() { - destroyWidgetImage(image_backgorund); + destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_back); - destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + destroyWidgetButton(button_back); + destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - if (textFile != NULL) { - saveTextFile(textFile); - destroyTextFile(textFile); - } + if (textFile != NULL) { + saveTextFile(textFile); + destroyTextFile(textFile); + } } diff --git a/src/screen/screen_table.h b/src/screen/screen_table.h index d16cbbb..a91b233 100644 --- a/src/screen/screen_table.h +++ b/src/screen/screen_table.h @@ -1,10 +1,10 @@ #ifndef SCREEN_TABLE_H -#define SCREEN_TABLE_H +# define SCREEN_TABLE_H -#define SCREEN_TABLE_MAX_PLAYERS 10 -#define SCREEN_TABLE_FILE_HIGHSCORE_NAME "highscore" +# define SCREEN_TABLE_MAX_PLAYERS 10 +# define SCREEN_TABLE_FILE_HIGHSCORE_NAME "highscore" extern void startScreenTable(); extern void drawScreenTable(); diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index fb6f38f..a2d0baf 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -32,8 +32,8 @@ #include "saveLoad.h" #ifndef NO_SOUND -#include "music.h" -#include "sound.h" +# include "music.h" +# include "sound.h" #endif #include "screen.h" @@ -53,580 +53,555 @@ static bool_t isEndWorld; static tux_t *tuxWithControlRightKeyboard; static tux_t *tuxWithControlLeftKeyboard; -bool_t -isScreenWorldInicialized() +bool_t isScreenWorldInicialized() { - return isScreenWorldInit; + return isScreenWorldInit; } -void -setGameType() +void setGameType() { - int ret = 0; + int ret = 0; - ret = - initNetMuliplayer(getSettingGameType(), getSettingIP(), - getSettingPort(), getSettingProto()); + ret = + initNetMuliplayer(getSettingGameType(), getSettingIP(), + getSettingPort(), getSettingProto()); - if (ret != 0) { - fprintf(stderr, _("Network initialization error!\n")); - setWorldEnd(); - } + if (ret != 0) { + fprintf(stderr, _("Network initialization error!\n")); + setWorldEnd(); + } } -void -setWorldArena(arenaFile_t * arenaFile) +void setWorldArena(arenaFile_t * arenaFile) { - arena = getArena(arenaFile); + arena = getArena(arenaFile); #ifndef NO_SOUND - playMusic(arena->music, MUSIC_GROUP_USER); + playMusic(arena->music, MUSIC_GROUP_USER); #endif } -void -setWorldEnd() +void setWorldEnd() { - isEndWorld = TRUE; + isEndWorld = TRUE; } -static void -timer_endArena() +static void timer_endArena() { - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - setWorldEnd(); - return; - } + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + setWorldEnd(); + return; + } } -void -countRoundInc() +void countRoundInc() { - if (arena->max_countRound == WORLD_COUNT_ROUND_UNLIMITED || - arena->countRound >= arena->max_countRound) { - return; - } + if (arena->max_countRound == WORLD_COUNT_ROUND_UNLIMITED || + arena->countRound >= arena->max_countRound) { + return; + } - arena->countRound++; - //printf("count %d/%d\n", count, max_count); + arena->countRound++; + //printf("count %d/%d\n", count, max_count); - if (arena->countRound >= arena->max_countRound) { - //printf("count %d ending\n", count); + if (arena->countRound >= arena->max_countRound) { + //printf("count %d ending\n", count); #ifndef NO_SOUND - playSound("end", SOUND_GROUP_BASE); + playSound("end", SOUND_GROUP_BASE); #endif - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_endArena, NULL, TIMER_END_ARENA); - } + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_endArena, NULL, TIMER_END_ARENA); + } } -void -prepareArena() +void prepareArena() { - tux_t *tux; - char name[STR_NAME_SIZE]; - - //printf("getSettingAI = %s\n", getSettingAI()); - setCurrentArena(NULL); - tuxWithControlRightKeyboard = NULL; - tuxWithControlLeftKeyboard = NULL; - - if (getGemeTypeLoadSession() != NULL) { - loadArena(getGemeTypeLoadSession()); - return; - } - - switch (getNetTypeGame()) { - case NET_GAME_TYPE_NONE: - setWorldArena(getChoiceArena()); - addNewItem(arena->spaceItem, ID_UNKNOWN); - getSettingCountRound(&arena->max_countRound); - - tux = newTux(); - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - tuxWithControlRightKeyboard = tux; - getSettingNameRight(name); - tuxSetName(tux, name); - addObjectToSpace(arena->spaceTux, tux); - - tux = newTux(); - tux->control = TUX_CONTROL_KEYBOARD_LEFT; - tuxWithControlLeftKeyboard = tux; - getSettingNameLeft(name); - tuxSetName(tux, name); - addObjectToSpace(arena->spaceTux, tux); - - if (isSettingAI()) { - tux->control = TUX_CONTROL_AI; - - if (loadModule("libmodAI") != 0) { - tux->control = TUX_CONTROL_KEYBOARD_LEFT; - } - } - - //printf("getGemeTypeLoadSession = %s\n", getGemeTypeLoadSession()); - - break; - - case NET_GAME_TYPE_SERVER: - setWorldArena(getChoiceArena()); - addNewItem(arena->spaceItem, ID_UNKNOWN); - getSettingCountRound(&arena->max_countRound); - - tux = newTux(); - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - tuxWithControlRightKeyboard = tux; - getSettingNameRight(name); - tuxSetName(tux, name); - addObjectToSpace(arena->spaceTux, tux); - break; - - case NET_GAME_TYPE_CLIENT: - break; - } + tux_t *tux; + char name[STR_NAME_SIZE]; + + //printf("getSettingAI = %s\n", getSettingAI()); + setCurrentArena(NULL); + tuxWithControlRightKeyboard = NULL; + tuxWithControlLeftKeyboard = NULL; + + if (getGemeTypeLoadSession() != NULL) { + loadArena(getGemeTypeLoadSession()); + return; + } + + switch (getNetTypeGame()) { + case NET_GAME_TYPE_NONE: + setWorldArena(getChoiceArena()); + addNewItem(arena->spaceItem, ID_UNKNOWN); + getSettingCountRound(&arena->max_countRound); + + tux = newTux(); + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + tuxWithControlRightKeyboard = tux; + getSettingNameRight(name); + tuxSetName(tux, name); + addObjectToSpace(arena->spaceTux, tux); + + tux = newTux(); + tux->control = TUX_CONTROL_KEYBOARD_LEFT; + tuxWithControlLeftKeyboard = tux; + getSettingNameLeft(name); + tuxSetName(tux, name); + addObjectToSpace(arena->spaceTux, tux); + + if (isSettingAI()) { + tux->control = TUX_CONTROL_AI; + + if (loadModule("libmodAI") != 0) { + tux->control = TUX_CONTROL_KEYBOARD_LEFT; + } + } + //printf("getGemeTypeLoadSession = %s\n", getGemeTypeLoadSession()); + + break; + + case NET_GAME_TYPE_SERVER: + setWorldArena(getChoiceArena()); + addNewItem(arena->spaceItem, ID_UNKNOWN); + getSettingCountRound(&arena->max_countRound); + + tux = newTux(); + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + tuxWithControlRightKeyboard = tux; + getSettingNameRight(name); + tuxSetName(tux, name); + addObjectToSpace(arena->spaceTux, tux); + break; + + case NET_GAME_TYPE_CLIENT: + break; + } } -void -drawWorld() +void drawWorld() { - if (arena != NULL) { - drawArena(arena); - drawPanel(tuxWithControlRightKeyboard, tuxWithControlLeftKeyboard); - - if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { - drawRadar(arena); - } - } - - drawChat(); - drawPauza(); - drawTerm(); - drawSaveDialog(); + if (arena != NULL) { + drawArena(arena); + drawPanel(tuxWithControlRightKeyboard, tuxWithControlLeftKeyboard); + + if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { + drawRadar(arena); + } + } + + drawChat(); + drawPauza(); + drawTerm(); + drawSaveDialog(); } -static void -netAction(tux_t * tux, int action) +static void netAction(tux_t * tux, int action) { - if (getSettingGameType() == NET_GAME_TYPE_SERVER) { - proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, NULL, tux, action); - } + if (getSettingGameType() == NET_GAME_TYPE_SERVER) { + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, NULL, tux, action); + } - if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { - proto_send_event_client(action); - } + if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { + proto_send_event_client(action); + } } -static void -control_keyboard_right(tux_t * tux) +static void control_keyboard_right(tux_t * tux) { - static int lastKey = 0; - int countKey; - Uint8 *mapa; - mapa = SDL_GetKeyState(NULL); - - assert(tux != NULL); - assert(mapa != NULL); - - countKey = 0; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) - countKey++; - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) - countKey++; - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) - countKey++; - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED - && tux->isCanSwitchGun == TRUE) { - netAction(tux, TUX_SWITCH_GUN); - actionTux(tux, TUX_SWITCH_GUN); - return; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED - && tux->isCanShot == TRUE) { - netAction(tux, TUX_SHOT); - actionTux(tux, TUX_SHOT); - return; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_UP)) - goto tuUp; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_UP); - netAction(tux, TUX_UP); - actionTux(tux, TUX_UP); - return; - - tuUp:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_RIGHT)) - goto tuRight; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_RIGHT); - netAction(tux, TUX_RIGHT); - actionTux(tux, TUX_RIGHT); - return; - - tuRight:; - - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_LEFT)) - goto tuLeft; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_LEFT); - netAction(tux, TUX_LEFT); - actionTux(tux, TUX_LEFT); - return; - - tuLeft:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_DOWN)) - goto tuDown; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_DOWN); - netAction(tux, TUX_DOWN); - actionTux(tux, TUX_DOWN); - return; - - tuDown:; - } + static int lastKey = 0; + int countKey; + Uint8 *mapa; + mapa = SDL_GetKeyState(NULL); + + assert(tux != NULL); + assert(mapa != NULL); + + countKey = 0; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) + countKey++; + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) + countKey++; + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) + countKey++; + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED + && tux->isCanSwitchGun == TRUE) { + netAction(tux, TUX_SWITCH_GUN); + actionTux(tux, TUX_SWITCH_GUN); + return; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED + && tux->isCanShot == TRUE) { + netAction(tux, TUX_SHOT); + actionTux(tux, TUX_SHOT); + return; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_UP)) + goto tuUp; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_UP); + netAction(tux, TUX_UP); + actionTux(tux, TUX_UP); + return; + + tuUp:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_RIGHT)) + goto tuRight; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_RIGHT); + netAction(tux, TUX_RIGHT); + actionTux(tux, TUX_RIGHT); + return; + + tuRight:; + + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_LEFT)) + goto tuLeft; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_LEFT); + netAction(tux, TUX_LEFT); + actionTux(tux, TUX_LEFT); + return; + + tuLeft:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_DOWN)) + goto tuDown; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_DOWN); + netAction(tux, TUX_DOWN); + actionTux(tux, TUX_DOWN); + return; + + tuDown:; + } } -static void -control_keyboard_left(tux_t * tux) +static void control_keyboard_left(tux_t * tux) { - static int lastKey = 0; - int countKey; - Uint8 *mapa; - mapa = SDL_GetKeyState(NULL); - - assert(tux != NULL); - assert(mapa != NULL); - - countKey = 0; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) - countKey++; - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) - countKey++; - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) - countKey++; - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED) { - if (tux->isCanSwitchGun == TRUE) { - actionTux(tux, TUX_SWITCH_GUN); - return; - } - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED - && tux->isCanShot == TRUE) { - actionTux(tux, TUX_SHOT); - return; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_UP)) - goto tuUp; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_UP); - actionTux(tux, TUX_UP); - return; - - tuUp:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_RIGHT)) - goto tuRight; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_RIGHT); - actionTux(tux, TUX_RIGHT); - return; - - tuRight:; - - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_LEFT)) - goto tuLeft; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_LEFT); - actionTux(tux, TUX_LEFT); - return; - - tuLeft:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_DOWN)) - goto tuDown; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_DOWN); - actionTux(tux, TUX_DOWN); - return; - - tuDown:; - } + static int lastKey = 0; + int countKey; + Uint8 *mapa; + mapa = SDL_GetKeyState(NULL); + + assert(tux != NULL); + assert(mapa != NULL); + + countKey = 0; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) + countKey++; + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) + countKey++; + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) + countKey++; + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED) { + if (tux->isCanSwitchGun == TRUE) { + actionTux(tux, TUX_SWITCH_GUN); + return; + } + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED + && tux->isCanShot == TRUE) { + actionTux(tux, TUX_SHOT); + return; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_UP)) + goto tuUp; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_UP); + actionTux(tux, TUX_UP); + return; + + tuUp:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_RIGHT)) + goto tuRight; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_RIGHT); + actionTux(tux, TUX_RIGHT); + return; + + tuRight:; + + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_LEFT)) + goto tuLeft; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_LEFT); + actionTux(tux, TUX_LEFT); + return; + + tuLeft:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_DOWN)) + goto tuDown; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_DOWN); + actionTux(tux, TUX_DOWN); + return; + + tuDown:; + } } -static void -eventEnd() +static void eventEnd() { - if (isEndWorld == TRUE) { - setScreen("analyze"); - return; - } + if (isEndWorld == TRUE) { + setScreen("analyze"); + return; + } } -tux_t * -getControlTux(int control_type) +tux_t *getControlTux(int control_type) { - switch (control_type) { - case TUX_CONTROL_KEYBOARD_RIGHT: - return tuxWithControlRightKeyboard; - break; - case TUX_CONTROL_KEYBOARD_LEFT: - return tuxWithControlLeftKeyboard; - break; - } - - return NULL; + switch (control_type) { + case TUX_CONTROL_KEYBOARD_RIGHT: + return tuxWithControlRightKeyboard; + break; + case TUX_CONTROL_KEYBOARD_LEFT: + return tuxWithControlLeftKeyboard; + break; + } + + return NULL; } -void -setControlTux(tux_t * tux, int control_type) +void setControlTux(tux_t * tux, int control_type) { - switch (control_type) { - case TUX_CONTROL_KEYBOARD_RIGHT: - tuxWithControlRightKeyboard = tux; - break; - case TUX_CONTROL_KEYBOARD_LEFT: - tuxWithControlLeftKeyboard = tux; - break; - } + switch (control_type) { + case TUX_CONTROL_KEYBOARD_RIGHT: + tuxWithControlRightKeyboard = tux; + break; + case TUX_CONTROL_KEYBOARD_LEFT: + tuxWithControlLeftKeyboard = tux; + break; + } } -void -tuxControl(tux_t * p) +void tuxControl(tux_t * p) { - assert(p != NULL); - - if (p->status != TUX_STATUS_ALIVE) { - return; - } - - switch (p->control) { - case TUX_CONTROL_NONE: - assert(!_("Tux has not defined controls!")); - break; - - case TUX_CONTROL_KEYBOARD_LEFT: - if (isChatActive() == FALSE) { - control_keyboard_left(p); - } - break; - - case TUX_CONTROL_KEYBOARD_RIGHT: - if (isChatActive() == FALSE) { - control_keyboard_right(p); - } - break; - } + assert(p != NULL); + + if (p->status != TUX_STATUS_ALIVE) { + return; + } + + switch (p->control) { + case TUX_CONTROL_NONE: + assert(!_("Tux has not defined controls!")); + break; + + case TUX_CONTROL_KEYBOARD_LEFT: + if (isChatActive() == FALSE) { + control_keyboard_left(p); + } + break; + + case TUX_CONTROL_KEYBOARD_RIGHT: + if (isChatActive() == FALSE) { + control_keyboard_right(p); + } + break; + } } -void -eventWorld() +void eventWorld() { - tux_t *thisTux; + tux_t *thisTux; - if (arena == NULL) { - eventNetMultiplayer(); - eventEnd(); - return; - } + if (arena == NULL) { + eventNetMultiplayer(); + eventEnd(); + return; + } - eventNetMultiplayer(); + eventNetMultiplayer(); - if (isPauzeActive() == FALSE && isSaveDialogActive() == FALSE) { - eventArena(arena); - //eventModule(); - } + if (isPauzeActive() == FALSE && isSaveDialogActive() == FALSE) { + eventArena(arena); + //eventModule(); + } - thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_YOU); + addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_YOU); - thisTux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + thisTux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - if (thisTux != NULL) { - addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_TUX); - } + if (thisTux != NULL) { + addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_TUX); + } - eventEnd(); - eventChat(); - eventPauza(); - eventTerm(); - eventSaveDialog(); + eventEnd(); + eventChat(); + eventPauza(); + eventTerm(); + eventSaveDialog(); } -static void -hotkey_escape() +static void hotkey_escape() { - setWorldEnd(); + setWorldEnd(); } -void -startWorld() +void startWorld() { - arena = NULL; - isEndWorld = FALSE; - - registerHotKey(SDLK_ESCAPE, hotkey_escape); - initArena(); - initListID(); - initRadar(); - initPauza(); - initTerm(); - initSaveDialog(); - - initModule(); - setGameType(); - initChat(); - prepareArena(); + arena = NULL; + isEndWorld = FALSE; + + registerHotKey(SDLK_ESCAPE, hotkey_escape); + initArena(); + initListID(); + initRadar(); + initPauza(); + initTerm(); + initSaveDialog(); + + initModule(); + setGameType(); + initChat(); + prepareArena(); } -static void -action_analyze(space_t * space, tux_t * tux, void *p) +static void action_analyze(space_t * space, tux_t * tux, void *p) { - addAnalyze(tux->name, tux->score); + addAnalyze(tux->name, tux->score); } -static void -setAnalyze() +static void setAnalyze() { - restartAnalyze(); + restartAnalyze(); - actionSpace(arena->spaceTux, action_analyze, NULL); + actionSpace(arena->spaceTux, action_analyze, NULL); - endAnalyze(); + endAnalyze(); } -static void -setTable() +static void setTable() { - tux_t *tuxRight; - tux_t *tuxLeft; + tux_t *tuxRight; + tux_t *tuxLeft; - if (getSettingGameType() != NET_GAME_TYPE_NONE) { - return; - } + if (getSettingGameType() != NET_GAME_TYPE_NONE) { + return; + } - tuxRight = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - tuxLeft = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + tuxRight = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tuxLeft = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - if (tuxRight->score > tuxLeft->score) { - addPlayerInHighScore(tuxRight->name, tuxRight->score); - } + if (tuxRight->score > tuxLeft->score) { + addPlayerInHighScore(tuxRight->name, tuxRight->score); + } - if (tuxLeft->score > tuxRight->score) { - addPlayerInHighScore(tuxLeft->name, tuxLeft->score); - } + if (tuxLeft->score > tuxRight->score) { + addPlayerInHighScore(tuxLeft->name, tuxLeft->score); + } } -void -stoptWorld() +void stoptWorld() { - if (arena != NULL) { - setTable(); - setAnalyze(); - } + if (arena != NULL) { + setTable(); + setAnalyze(); + } - unregisterHotKey(SDLK_ESCAPE); - quitArena(); + unregisterHotKey(SDLK_ESCAPE); + quitArena(); - quitNetMultiplayer(); + quitNetMultiplayer(); - if (arena != NULL) { - destroyArena(arena); - } + if (arena != NULL) { + destroyArena(arena); + } - quitRadar(); - quitPauza(); - quitTerm(); - quitSaveDialog(); + quitRadar(); + quitPauza(); + quitTerm(); + quitSaveDialog(); #ifndef NO_SOUND - stopMusic(); + stopMusic(); #endif - delAllImageInGroup(IMAGE_GROUP_USER); + delAllImageInGroup(IMAGE_GROUP_USER); #ifndef NO_SOUND - delAllMusicInGroup(MUSIC_GROUP_USER); + delAllMusicInGroup(MUSIC_GROUP_USER); #endif - quitModule(); - quitChat(); - quitListID(); + quitModule(); + quitChat(); + quitListID(); } -void -initWorld() +void initWorld() { - assert(isImageInicialized() == TRUE); - assert(isTuxInicialized() == TRUE); - assert(isShotInicialized() == TRUE); - assert(isPanelInicialized() == TRUE); - assert(isScreenInicialized() == TRUE); + assert(isImageInicialized() == TRUE); + assert(isTuxInicialized() == TRUE); + assert(isShotInicialized() == TRUE); + assert(isPanelInicialized() == TRUE); + assert(isScreenInicialized() == TRUE); - registerScreen(newScreen - ("world", startWorld, eventWorld, drawWorld, stoptWorld)); + registerScreen(newScreen + ("world", startWorld, eventWorld, drawWorld, stoptWorld)); #ifndef NO_SOUND - addSound("dead.ogg", "dead", SOUND_GROUP_BASE); - addSound("explozion.ogg", "explozion", SOUND_GROUP_BASE); - addSound("gun_lasser.ogg", "gun_lasser", SOUND_GROUP_BASE); - addSound("gun_revolver.ogg", "gun_revolver", SOUND_GROUP_BASE); - addSound("gun_scatter.ogg", "gun_scatter", SOUND_GROUP_BASE); - addSound("gun_tommy.ogg", "gun_tommy", SOUND_GROUP_BASE); - addSound("put_mine.ogg", "put_mine", SOUND_GROUP_BASE); - addSound("teleport.ogg", "teleport", SOUND_GROUP_BASE); - addSound("item_bonus.ogg", "item_bonus", SOUND_GROUP_BASE); - addSound("item_gun.ogg", "item_gun", SOUND_GROUP_BASE); - addSound("switch_gun.ogg", "switch_gun", SOUND_GROUP_BASE); - addSound("end.ogg", "end", SOUND_GROUP_BASE); + addSound("dead.ogg", "dead", SOUND_GROUP_BASE); + addSound("explozion.ogg", "explozion", SOUND_GROUP_BASE); + addSound("gun_lasser.ogg", "gun_lasser", SOUND_GROUP_BASE); + addSound("gun_revolver.ogg", "gun_revolver", SOUND_GROUP_BASE); + addSound("gun_scatter.ogg", "gun_scatter", SOUND_GROUP_BASE); + addSound("gun_tommy.ogg", "gun_tommy", SOUND_GROUP_BASE); + addSound("put_mine.ogg", "put_mine", SOUND_GROUP_BASE); + addSound("teleport.ogg", "teleport", SOUND_GROUP_BASE); + addSound("item_bonus.ogg", "item_bonus", SOUND_GROUP_BASE); + addSound("item_gun.ogg", "item_gun", SOUND_GROUP_BASE); + addSound("switch_gun.ogg", "switch_gun", SOUND_GROUP_BASE); + addSound("end.ogg", "end", SOUND_GROUP_BASE); #endif - isScreenWorldInit = TRUE; + isScreenWorldInit = TRUE; } -void -quitWorld() +void quitWorld() { #ifdef DEBUG - printf(_("Quitting screen world\n")); + printf(_("Quitting screen world\n")); #endif - isScreenWorldInit = FALSE; + isScreenWorldInit = FALSE; } diff --git a/src/screen/screen_world.h b/src/screen/screen_world.h index bf7a142..67935f7 100644 --- a/src/screen/screen_world.h +++ b/src/screen/screen_world.h @@ -1,17 +1,17 @@ #ifndef SCREEN_WORLD_H -#define SCREEN_WORLD_H +# define SCREEN_WORLD_H -#include "main.h" -#include "myTimer.h" -#include "tux.h" -#include "arenaFile.h" -#include "arena.h" +# include "main.h" +# include "myTimer.h" +# include "tux.h" +# include "arenaFile.h" +# include "arena.h" -#define TIMER_END_ARENA 5000 -#define WORLD_COUNT_ROUND_UNLIMITED -1 -#define LAG_SERVER_UNKNOWN -1 +# define TIMER_END_ARENA 5000 +# define WORLD_COUNT_ROUND_UNLIMITED -1 +# define LAG_SERVER_UNKNOWN -1 extern bool_t isScreenWorldInicialized(); extern void initWorld(); diff --git a/src/server/highScore.c b/src/server/highScore.c index 1ae7001..37c87b4 100644 --- a/src/server/highScore.c +++ b/src/server/highScore.c @@ -11,85 +11,80 @@ static textFile_t *textFile; -void -initHighScore(char *file) +void initHighScore(char *file) { - int i; + int i; - textFile = loadTextFile(file); + textFile = loadTextFile(file); - if (textFile == NULL) { - fprintf(stderr, _("I am unable to load: \"%s\"!\n"), file); - fprintf(stderr, _("Creating: \"%s\"\n"), file); - textFile = newTextFile(file); - } - else { + if (textFile == NULL) { + fprintf(stderr, _("I am unable to load: \"%s\"!\n"), file); + fprintf(stderr, _("Creating: \"%s\"\n"), file); + textFile = newTextFile(file); + } else { #ifdef DEBUG - printf(_("Scorefile: \"%s\"\n"), file); + printf(_("Scorefile: \"%s\"\n"), file); #endif - return; - } + return; + } - if (textFile == NULL) { - fprintf(stderr, _("I was unable to create: \"%s\"!\n"), file); - return; - } + if (textFile == NULL) { + fprintf(stderr, _("I was unable to create: \"%s\"!\n"), file); + return; + } - for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { - addList(textFile->text, strdup("no_name 0")); - } + for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { + addList(textFile->text, strdup("no_name 0")); + } - saveTextFile(textFile); + saveTextFile(textFile); } -int -addPlayerInHighScore(char *name, int score) +int addPlayerInHighScore(char *name, int score) { - int i; + int i; - if (score <= 0) { - return -1; // Ha ha ha - } + if (score <= 0) { + return -1; // Ha ha ha + } - for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { - char *line; - char thisName[STR_NAME_SIZE]; - int thisCore; + for (i = 0; i < HIGHSCORE_MAX_PLAYERS; i++) { + char *line; + char thisName[STR_NAME_SIZE]; + int thisCore; - line = (char *) textFile->text->list[i]; - sscanf(line, "%s %d", thisName, &thisCore); + line = (char *) textFile->text->list[i]; + sscanf(line, "%s %d", thisName, &thisCore); - if (score >= thisCore) { - char new[STR_SIZE]; + if (score >= thisCore) { + char new[STR_SIZE]; - sprintf(new, "%s %d", name, score); - insList(textFile->text, i, strdup(new)); - delListItem(textFile->text, HIGHSCORE_MAX_PLAYERS, free); - //printTextFile(textFile); - saveTextFile(textFile); + sprintf(new, "%s %d", name, score); + insList(textFile->text, i, strdup(new)); + delListItem(textFile->text, HIGHSCORE_MAX_PLAYERS, free); + //printTextFile(textFile); + saveTextFile(textFile); - return 0; - } - } + return 0; + } + } - return -1; + return -1; } -char * -getTableItem(int index) +char *getTableItem(int index) { - if (textFile != NULL && index >= 0 && index < textFile->text->count) { - return (char *) textFile->text->list[index]; - } + if (textFile != NULL && index >= 0 && index < textFile->text->count) { + return (char *) textFile->text->list[index]; + } - return NULL; + return NULL; } -void -quitHighScore() +void quitHighScore() { - if (textFile != NULL) { - saveTextFile(textFile); - destroyTextFile(textFile); - } + if (textFile != NULL) { + saveTextFile(textFile); + destroyTextFile(textFile); + } } diff --git a/src/server/highScore.h b/src/server/highScore.h index 56850f2..8c3c141 100644 --- a/src/server/highScore.h +++ b/src/server/highScore.h @@ -1,9 +1,9 @@ #ifndef HIGH_SCORE_H -#define HIGH_SCORE_H +# define HIGH_SCORE_H -#define HIGHSCORE_MAX_PLAYERS 100 +# define HIGHSCORE_MAX_PLAYERS 100 extern void initHighScore(char *file); extern int addPlayerInHighScore(char *name, int score); diff --git a/src/server/log.c b/src/server/log.c index 658a30c..207da2a 100644 --- a/src/server/log.c +++ b/src/server/log.c @@ -11,65 +11,62 @@ static FILE *logFile; -int -initLog(char *name) +int initLog(char *name) { - logFile = fopen(name, "a"); + logFile = fopen(name, "a"); - if (logFile == NULL) { - fprintf(stderr, _("Opening logfile \"%s\" failed!\n"), name); - return -1; - } + if (logFile == NULL) { + fprintf(stderr, _("Opening logfile \"%s\" failed!\n"), name); + return -1; + } #ifdef DEBUG - printf(_("I use logfile: \"%s\")\n"), name); + printf(_("I use logfile: \"%s\")\n"), name); #endif - addToLog(LOG_INF, "open log file"); + addToLog(LOG_INF, "open log file"); - return 0; + return 0; } -void -addToLog(int type, char *msg) +void addToLog(int type, char *msg) { - char str[STR_LOG_SIZE]; - struct tm *tm_struct; - time_t currentTime; - char *str_type; + char str[STR_LOG_SIZE]; + struct tm *tm_struct; + time_t currentTime; + char *str_type; - currentTime = time(NULL); - tm_struct = localtime(¤tTime); + currentTime = time(NULL); + tm_struct = localtime(¤tTime); - switch (type) { - case LOG_INF: - str_type = "INF"; - break; - case LOG_DBG: - str_type = "DBG"; - break; - case LOG_WRN: - str_type = "WRN"; - break; - case LOG_ERR: - str_type = "ERR"; - break; - default: - assert(!_("Really bad log value!")); - break; - } + switch (type) { + case LOG_INF: + str_type = "INF"; + break; + case LOG_DBG: + str_type = "DBG"; + break; + case LOG_WRN: + str_type = "WRN"; + break; + case LOG_ERR: + str_type = "ERR"; + break; + default: + assert(!_("Really bad log value!")); + break; + } - sprintf(str, "(%02d-%02d-%02d %02d:%02d:%02d) %s %s\n", - 1900 + tm_struct->tm_year, tm_struct->tm_mon, tm_struct->tm_mday, - tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec, - str_type, msg); + sprintf(str, "(%02d-%02d-%02d %02d:%02d:%02d) %s %s\n", + 1900 + tm_struct->tm_year, tm_struct->tm_mon, tm_struct->tm_mday, + tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec, + str_type, msg); - fprintf(logFile, str); + fprintf(logFile, str); - fflush(logFile); + fflush(logFile); } -void -quitLog() +void quitLog() { - addToLog(LOG_INF, "close log file"); - fclose(logFile); + addToLog(LOG_INF, "close log file"); + fclose(logFile); } diff --git a/src/server/log.h b/src/server/log.h index af60911..01f2c8b 100644 --- a/src/server/log.h +++ b/src/server/log.h @@ -1,12 +1,12 @@ #ifndef LOG_H -#define LOG_H +# define LOG_H -#define LOG_INF 1 -#define LOG_DBG 2 -#define LOG_WRN 3 -#define LOG_ERR 4 +# define LOG_INF 1 +# define LOG_DBG 2 +# define LOG_WRN 3 +# define LOG_ERR 4 extern int initLog(char *name); extern void addToLog(int type, char *msg); diff --git a/src/server/publicServer.c b/src/server/publicServer.c index 4944115..9aade66 100644 --- a/src/server/publicServer.c +++ b/src/server/publicServer.c @@ -7,12 +7,12 @@ #include <time.h> #ifndef __WIN32 -#include <sys/socket.h> -#include <sys/select.h> -#include <arpa/inet.h> +# include <sys/socket.h> +# include <sys/select.h> +# include <arpa/inet.h> #else -# include <windows.h> -# include <wininet.h> +# include <windows.h> +# include <wininet.h> #endif #include <unistd.h> @@ -47,330 +47,315 @@ extern int errno; #define __PACKED__ __attribute__ ((__packed__)) -void -countRoundInc() +void countRoundInc() { } -char * -getSetting(char *env, char *param, char *default_val) +char *getSetting(char *env, char *param, char *default_val) { - return getParamElse(param, getServerConfigFileValue(env, default_val)); + return getParamElse(param, getServerConfigFileValue(env, default_val)); } -static int -registerPublicServer() +static int registerPublicServer() { #ifndef __WIN32 - int s; + int s; #else - SOCKET s; + SOCKET s; #endif - /* TODO: dodelat TCP makro */ - struct sockaddr_in server; - char *master_server_ip; + /* TODO: dodelat TCP makro */ + struct sockaddr_in server; + char *master_server_ip; - master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); + master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); - //printf("master_server_ip = %s\n", master_server_ip); + //printf("master_server_ip = %s\n", master_server_ip); - if (master_server_ip == NULL) // master server is down - { - return -1; - } + if (master_server_ip == NULL) // master server is down + { + return -1; + } - server.sin_family = AF_INET; - server.sin_port = htons(NET_MASTER_PORT); - server.sin_addr.s_addr = inet_addr(master_server_ip); + server.sin_family = AF_INET; + server.sin_port = htons(NET_MASTER_PORT); + server.sin_addr.s_addr = inet_addr(master_server_ip); - free(master_server_ip); + free(master_server_ip); - if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - return 0; - } + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + return 0; + } - /* Set to nonblocking socket mode */ + /* Set to nonblocking socket mode */ #ifndef __WIN32__ - int oldFlag; + int oldFlag; - oldFlag = fcntl(s, F_GETFL, 0); + oldFlag = fcntl(s, F_GETFL, 0); - if (fcntl(s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - return -1; - } + if (fcntl(s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } #else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(s, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(s, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } #endif - if (connect(s, (struct sockaddr *) &server, sizeof(server)) == -1) { + if (connect(s, (struct sockaddr *) &server, sizeof(server)) == -1) { #ifndef __WIN32__ - if (errno != EINPROGRESS) - return -1; + if (errno != EINPROGRESS) + return -1; #else - if (WSAGetLastError() != WSAEWOULDBLOCK) { - WSACleanup(); - return -1; - } + if (WSAGetLastError() != WSAEWOULDBLOCK) { + WSACleanup(); + return -1; + } #endif - } + } - struct timeval tv; + struct timeval tv; - fd_set myset; + fd_set myset; - FD_ZERO(&myset); - FD_SET(s, &myset); + FD_ZERO(&myset); + FD_SET(s, &myset); - tv.tv_sec = 3; - tv.tv_usec = 0; + tv.tv_sec = 3; + tv.tv_usec = 0; - int ret = select(s + 1, NULL, &myset, NULL, &tv); + int ret = select(s + 1, NULL, &myset, NULL, &tv); - if (ret == -1) - return -1; + if (ret == -1) + return -1; - if (ret == 0) - return -1; + if (ret == 0) + return -1; - FD_ZERO(&myset); - FD_SET(s, &myset); + FD_ZERO(&myset); + FD_SET(s, &myset); - tv.tv_sec = 1; - tv.tv_usec = 0; + tv.tv_sec = 1; + tv.tv_usec = 0; - ret = select(s + 1, NULL, &myset, NULL, &tv); + ret = select(s + 1, NULL, &myset, NULL, &tv); - if (ret == -1) - return -1; + if (ret == -1) + return -1; - if (ret == 0) - return -1; + if (ret == 0) + return -1; - typedef struct - { - unsigned char cmd; - unsigned port; - unsigned ip; - } __PACKED__ register_head; + typedef struct { + unsigned char cmd; + unsigned port; + unsigned ip; + } __PACKED__ register_head; - char *str = (char *) malloc(sizeof(register_head)); + char *str = (char *) malloc(sizeof(register_head)); - register_head *head = (register_head *) str; + register_head *head = (register_head *) str; - head->cmd = 'p'; - head->port = atoi(getSetting("PORT4", "--port4", "2200")); - head->ip = 0; // TODO + head->cmd = 'p'; + head->port = atoi(getSetting("PORT4", "--port4", "2200")); + head->ip = 0; // TODO - /* send request for server list */ - int r = send(s, str, 9, 0); + /* send request for server list */ + int r = send(s, str, 9, 0); - free(str); + free(str); - if (r == -1) { + if (r == -1) { #ifndef __WIN32 - close(s); + close(s); #else - closesocket(s); + closesocket(s); #endif - return -1; - } - + return -1; + } #ifndef __WIN32 - close(s); + close(s); #else - closesocket(s); + closesocket(s); #endif - return 0; + return 0; } -static int -initPublicServerNetwork() +static int initPublicServerNetwork() { - char ip4[STR_IP_SIZE]; - char ip6[STR_IP_SIZE]; - char *p_ip4, *p_ip6; - int port4; - int port6; - int ret; + char ip4[STR_IP_SIZE]; + char ip6[STR_IP_SIZE]; + char *p_ip4, *p_ip6; + int port4; + int port6; + int ret; - ret = -1; + ret = -1; - strcpy(ip4, getSetting("IP4", "--ip4", "none")); - strcpy(ip6, getSetting("IP6", "--ip6", "none")); + strcpy(ip4, getSetting("IP4", "--ip4", "none")); + strcpy(ip6, getSetting("IP6", "--ip6", "none")); - p_ip4 = ip4; + p_ip4 = ip4; - if (strcmp(ip4, "none") == 0) { - p_ip4 = NULL; - } + if (strcmp(ip4, "none") == 0) { + p_ip4 = NULL; + } - p_ip6 = ip6; + p_ip6 = ip6; - if (strcmp(ip6, "none") == 0) { - p_ip6 = NULL; - } + if (strcmp(ip6, "none") == 0) { + p_ip6 = NULL; + } - port4 = atoi(getSetting("PORT4", "--port4", "2200")); - port6 = atoi(getSetting("PORT6", "--port6", "2200")); + port4 = atoi(getSetting("PORT4", "--port4", "2200")); + port6 = atoi(getSetting("PORT6", "--port6", "2200")); - //ret = initNetMulitplayerPublicServer(p_ip4, port4, p_ip6, port6); + //ret = initNetMulitplayerPublicServer(p_ip4, port4, p_ip6, port6); - ret = initNetMuliplayerForGameServer(p_ip4, port4, p_ip6, port6); + ret = initNetMuliplayerForGameServer(p_ip4, port4, p_ip6, port6); - return ret; + return ret; } -static void -loadArena() +static void loadArena() { - choice_arenaFile = - getArenaFileFormNetName(getSetting("ARENA", "--arena", "FAGN")); - arena = getArena(choice_arenaFile); - setCurrentArena(arena); + choice_arenaFile = + getArenaFileFormNetName(getSetting("ARENA", "--arena", "FAGN")); + arena = getArena(choice_arenaFile); + setCurrentArena(arena); } -int -initPublicServer() +int initPublicServer() { - int ret; - int i; + int ret; + int i; - initListID(); - initModule(); - initArenaFile(); - initTux(); - initItem(); - initShot(); - initServerConfigFile(); + initListID(); + initModule(); + initArenaFile(); + initTux(); + initItem(); + initShot(); + initServerConfigFile(); - ret = - initLog(getSetting - ("LOG_FILE", "--log-file", "/tmp/tuxanci-server.log")); + ret = + initLog(getSetting + ("LOG_FILE", "--log-file", "/tmp/tuxanci-server.log")); - if (ret < 0) { - fprintf(stderr, _("I was unable to open config file!\n")); - return -1; - } + if (ret < 0) { + fprintf(stderr, _("I was unable to open config file!\n")); + return -1; + } - initHighScore(getSetting - ("SCORE_FILE", "--score-file", "/tmp/highscore")); + initHighScore(getSetting("SCORE_FILE", "--score-file", "/tmp/highscore")); - loadArena(); + loadArena(); - for (i = 0; i < atoi(getSetting("ITEM", "--item", "10")); i++) { - addNewItem(arena->spaceItem, ID_UNKNOWN); - } + for (i = 0; i < atoi(getSetting("ITEM", "--item", "10")); i++) { + addNewItem(arena->spaceItem, ID_UNKNOWN); + } - isSignalEnd = FALSE; + isSignalEnd = FALSE; - ret = initPublicServerNetwork(); + ret = initPublicServerNetwork(); - if (ret < 0) { - printf(_("Unable to initialize network socket!\n")); - return -1; - } + if (ret < 0) { + printf(_("Unable to initialize network socket!\n")); + return -1; + } - setServerMaxClients(atoi - (getSetting("MAX_CLIENTS", "--max-clients", "32"))); + setServerMaxClients(atoi + (getSetting("MAX_CLIENTS", "--max-clients", "32"))); - if (registerPublicServer() < 0) { - printf(_("Unable to contact MasterServer!)\n")); - } + if (registerPublicServer() < 0) { + printf(_("Unable to contact MasterServer!)\n")); + } - return 0; + return 0; } -arenaFile_t * -getChoiceArena() +arenaFile_t *getChoiceArena() { - return choice_arenaFile; + return choice_arenaFile; } -void -eventPublicServer() +void eventPublicServer() { - static my_time_t lastActive = 0; - my_time_t interval; - - eventNetMultiplayer(); + static my_time_t lastActive = 0; + my_time_t interval; - if (isSignalEnd == TRUE) { - quitPublicServer(); - } + eventNetMultiplayer(); - if (lastActive == 0) { - lastActive = getMyTime(); - } + if (isSignalEnd == TRUE) { + quitPublicServer(); + } - interval = getMyTime() - lastActive; + if (lastActive == 0) { + lastActive = getMyTime(); + } - if (interval < 50) { - return; - } + interval = getMyTime() - lastActive; - //printf("interval = %d\n", interval); + if (interval < 50) { + return; + } + //printf("interval = %d\n", interval); - lastActive = getMyTime(); + lastActive = getMyTime(); - eventArena(arena); + eventArena(arena); } -void -my_handler_quit(int n) +void my_handler_quit(int n) { #ifdef DEBUG - printf("my_handler_quit\n"); + printf("my_handler_quit\n"); #endif - isSignalEnd = TRUE; + isSignalEnd = TRUE; } -void -quitPublicServer() +void quitPublicServer() { #ifdef DEBUG - printf(_("Quitting public server\n")); + printf(_("Quitting public server\n")); #endif - quitNetMultiplayer(); - destroyArena(arena); + quitNetMultiplayer(); + destroyArena(arena); - quitTux(); - quitItem(); - quitShot(); + quitTux(); + quitItem(); + quitShot(); - quitArenaFile(); - quitServerConfigFile(); - quitModule(); - quitListID(); - quitHighScore(); - quitLog(); + quitArenaFile(); + quitServerConfigFile(); + quitModule(); + quitListID(); + quitHighScore(); + quitLog(); - exit(0); + exit(0); } -int -startPublicServer() +int startPublicServer() { #ifndef __WIN32__ - signal(SIGINT, my_handler_quit); - signal(SIGTERM, my_handler_quit); - signal(SIGQUIT, my_handler_quit); + signal(SIGINT, my_handler_quit); + signal(SIGTERM, my_handler_quit); + signal(SIGQUIT, my_handler_quit); #endif - if (initPublicServer() < 0) { - quitPublicServer(); - return -1; - } + if (initPublicServer() < 0) { + quitPublicServer(); + return -1; + } - while (1) { - eventPublicServer(); - } + while (1) { + eventPublicServer(); + } - return 0; + return 0; } diff --git a/src/server/publicServer.h b/src/server/publicServer.h index 9bf97fc..e5538b6 100644 --- a/src/server/publicServer.h +++ b/src/server/publicServer.h @@ -1,12 +1,12 @@ #ifndef PUBLIC_SERVER_H -#define PUBLIC_SERVER_H +# define PUBLIC_SERVER_H -#include "arena.h" -#include "arenaFile.h" +# include "arena.h" +# include "arenaFile.h" -#define WORLD_COUNT_ROUND_UNLIMITED -1 +# define WORLD_COUNT_ROUND_UNLIMITED -1 extern char *getSetting(char *env, char *param, char *default_val); extern void countRoundInc(); diff --git a/src/server/serverConfigFile.c b/src/server/serverConfigFile.c index 82cb49b..0af58f9 100644 --- a/src/server/serverConfigFile.c +++ b/src/server/serverConfigFile.c @@ -11,95 +11,90 @@ static textFile_t *serverTextFile; -static void -prepareConfigFile(textFile_t * ts) +static void prepareConfigFile(textFile_t * ts) { - int i; - int j; - - for (i = 0; i < serverTextFile->text->count; i++) { - char *line; - int len; - - line = (char *) (serverTextFile->text->list[i]); - len = strlen(line); - - for (j = 0; j < len; j++) { - if (line[j] == ' ') // [TAB] - { - line[j] = ' '; - } - } - } + int i; + int j; + + for (i = 0; i < serverTextFile->text->count; i++) { + char *line; + int len; + + line = (char *) (serverTextFile->text->list[i]); + len = strlen(line); + + for (j = 0; j < len; j++) { + if (line[j] == ' ') // [TAB] + { + line[j] = ' '; + } + } + } } -void -initServerConfigFile() +void initServerConfigFile() { - char *configFile; + char *configFile; - configFile = getParamElse("--config-file", SERVER_CONFIG); - printf(_("Loading configuration from: \"%s\"\n"), - getParamElse("--config-file", SERVER_CONFIG)); + configFile = getParamElse("--config-file", SERVER_CONFIG); + printf(_("Loading configuration from: \"%s\"\n"), + getParamElse("--config-file", SERVER_CONFIG)); - serverTextFile = loadTextFile(configFile); + serverTextFile = loadTextFile(configFile); - if (serverTextFile == NULL) { - fprintf(stderr, - _ - ("I was unable to load config file. Falling back to defaults!\n")); - return; - } + if (serverTextFile == NULL) { + fprintf(stderr, + _ + ("I was unable to load config file. Falling back to defaults!\n")); + return; + } - prepareConfigFile(serverTextFile); + prepareConfigFile(serverTextFile); } -static char * -findValue(char *s) +static char *findValue(char *s) { - int len; - int i; + int len; + int i; - len = strlen(s); + len = strlen(s); - for (i = 0; i < len - 1; i++) { - if (s[i] == ' ' && s[i + 1] != ' ') { - return s + i + 1; - } - } + for (i = 0; i < len - 1; i++) { + if (s[i] == ' ' && s[i + 1] != ' ') { + return s + i + 1; + } + } - return NULL; + return NULL; } -char * -getServerConfigFileValue(char *env, char *s) +char *getServerConfigFileValue(char *env, char *s) { - int i; - int len; + int i; + int len; - if (serverTextFile == NULL) { - return s; - } + if (serverTextFile == NULL) { + return s; + } - len = strlen(env); + len = strlen(env); - for (i = 0; i < serverTextFile->text->count; i++) { - char *line; + for (i = 0; i < serverTextFile->text->count; i++) { + char *line; - line = (char *) (serverTextFile->text->list[i]); + line = (char *) (serverTextFile->text->list[i]); - if (strncmp(line, env, len) == 0) { - return findValue(line); - } - } + if (strncmp(line, env, len) == 0) { + return findValue(line); + } + } - return s; + return s; } -void -quitServerConfigFile() +void quitServerConfigFile() { - if (serverTextFile != NULL) { - destroyTextFile(serverTextFile); - } + if (serverTextFile != NULL) { + destroyTextFile(serverTextFile); + } } diff --git a/src/server/serverConfigFile.h b/src/server/serverConfigFile.h index 7021a6b..221557b 100644 --- a/src/server/serverConfigFile.h +++ b/src/server/serverConfigFile.h @@ -2,7 +2,7 @@ #ifndef SERVER_CONFIG_FILE_H -#define SERVER_CONFIG_FILE_H +# define SERVER_CONFIG_FILE_H extern void initServerConfigFile(); extern char *getServerConfigFileValue(char *env, char *s); diff --git a/src/widget/widget.c b/src/widget/widget.c index 4eaca17..0dcfb41 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -7,56 +7,50 @@ #include "widget.h" #include "widget_label.h" -widget_t * -newWidget(int type, int x, int y, int w, int h, void *private_data) +widget_t *newWidget(int type, int x, int y, int w, int h, void *private_data) { - widget_t *new; + widget_t *new; - new = malloc(sizeof(widget_t)); - new->type = type; - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->private_data = private_data; + new = malloc(sizeof(widget_t)); + new->type = type; + new->x = x; + new->y = y; + new->w = w; + new->h = h; + new->private_data = private_data; - return new; + return new; } -void -widgetSetLocation(widget_t * p, int x, int y) +void widgetSetLocation(widget_t * p, int x, int y) { - p->x = x; - p->y = y; + p->x = x; + p->y = y; } -void -widgetGetLocation(widget_t * p, int *x, int *y) +void widgetGetLocation(widget_t * p, int *x, int *y) { - if (x != NULL) - *x = p->x; - if (y != NULL) - *y = p->y; + if (x != NULL) + *x = p->x; + if (y != NULL) + *y = p->y; } -void -widgetSetSize(widget_t * p, int w, int h) +void widgetSetSize(widget_t * p, int w, int h) { - p->w = w; - p->h = h; + p->w = w; + p->h = h; } -void -widgetGetSize(widget_t * p, int *w, int *h) +void widgetGetSize(widget_t * p, int *w, int *h) { - if (w != NULL) - *w = p->w; - if (h != NULL) - *h = p->h; + if (w != NULL) + *w = p->w; + if (h != NULL) + *h = p->h; } -void -destroyWidget(widget_t * p) +void destroyWidget(widget_t * p) { - free(p); + free(p); } diff --git a/src/widget/widget.h b/src/widget/widget.h index 05fce33..c18a687 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -1,30 +1,29 @@ #ifndef WIDGET_H -#define WIDGET_H +# define WIDGET_H -#include "main.h" +# include "main.h" -#define WIDGET_TYPE_LABEL 1 -#define WIDGET_TYPE_BUTTON 2 -#define WIDGET_TYPE_BUTTONIMAGE 3 -#define WIDGET_TYPE_TEXTFILED 4 -#define WIDGET_TYPE_CATCHKEY 4 -#define WIDGET_TYPE_CHECK 5 -#define WIDGET_TYPE_CHOICE 6 -#define WIDGET_TYPE_IMAGE 7 -#define WIDGET_TYPE_SELECT 8 +# define WIDGET_TYPE_LABEL 1 +# define WIDGET_TYPE_BUTTON 2 +# define WIDGET_TYPE_BUTTONIMAGE 3 +# define WIDGET_TYPE_TEXTFILED 4 +# define WIDGET_TYPE_CATCHKEY 4 +# define WIDGET_TYPE_CHECK 5 +# define WIDGET_TYPE_CHOICE 6 +# define WIDGET_TYPE_IMAGE 7 +# define WIDGET_TYPE_SELECT 8 -typedef struct widget_struct -{ - int type; - int x, y; - int w, h; - void *private_data; +typedef struct widget_struct { + int type; + int x, y; + int w, h; + void *private_data; } widget_t; extern widget_t *newWidget(int type, int x, int y, int w, int h, - void *private_data); + void *private_data); extern void widgetSetLocation(widget_t * p, int x, int y); extern void widgetGetLocation(widget_t * p, int *x, int *y); extern void widgetSetSize(widget_t * p, int w, int h); diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c index 10391e7..d02a568 100644 --- a/src/widget/widget_button.c +++ b/src/widget/widget_button.c @@ -11,104 +11,99 @@ #include "widget.h" #include "widget_button.h" -widget_t * -newWidgetButton(char *text, int x, int y, void (*fce_event) (void *)) +widget_t *newWidgetButton(char *text, int x, int y, void (*fce_event) (void *)) { - widget_button_t *new; + widget_button_t *new; - new = malloc(sizeof(widget_button_t)); - new->text = strdup(text); - new->fce_event = fce_event; - getTextSize(text, &(new->w), &(new->h)); + new = malloc(sizeof(widget_button_t)); + new->text = strdup(text); + new->fce_event = fce_event; + getTextSize(text, &(new->w), &(new->h)); - return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, - WIDGET_BUTTON_HEIGHT, new); + return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, + WIDGET_BUTTON_HEIGHT, new); } -void -drawWidgetButton(widget_t * widget) +void drawWidgetButton(widget_t * widget) { - widget_button_t *p; - static image_t *g_button0 = NULL; - static image_t *g_button1 = NULL; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); - - p = (widget_button_t *) widget->private_data; - getMousePosition(&x, &y); - - if (g_button0 == NULL) { - g_button0 = - addImageData("button0.png", IMAGE_ALPHA, "button0", - IMAGE_GROUP_BASE); - } - - if (g_button1 == NULL) { - g_button1 = - addImageData("button1.png", IMAGE_ALPHA, "button1", - IMAGE_GROUP_BASE); - } - - if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT) { - drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, - g_button0->h); - } - else { - drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, - g_button0->h); - } - - //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); - drawFont(p->text, - widget->x + WIDGET_BUTTON_WIDTH / 2 - p->w / 2, - widget->y + WIDGET_BUTTON_HEIGHT / 2 - p->h / 2, COLOR_WHITE); + widget_button_t *p; + static image_t *g_button0 = NULL; + static image_t *g_button1 = NULL; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTON); + + p = (widget_button_t *) widget->private_data; + getMousePosition(&x, &y); + + if (g_button0 == NULL) { + g_button0 = + addImageData("button0.png", IMAGE_ALPHA, "button0", + IMAGE_GROUP_BASE); + } + + if (g_button1 == NULL) { + g_button1 = + addImageData("button1.png", IMAGE_ALPHA, "button1", + IMAGE_GROUP_BASE); + } + + if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT) { + drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, + g_button0->h); + } else { + drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, + g_button0->h); + } + + //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); + drawFont(p->text, + widget->x + WIDGET_BUTTON_WIDTH / 2 - p->w / 2, + widget->y + WIDGET_BUTTON_HEIGHT / 2 - p->h / 2, COLOR_WHITE); } -void -eventWidgetButton(widget_t * widget) +void eventWidgetButton(widget_t * widget) { - widget_button_t *p; - static int time = 0; - int x, y; + widget_button_t *p; + static int time = 0; + int x, y; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTON); - p = (widget_button_t *) widget->private_data; + p = (widget_button_t *) widget->private_data; - if (time > 0) { - time--; - return; - } + if (time > 0) { + time--; + return; + } - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && - isMouseClicked()) { - time = WIDGET_BUTTON_TIME; + if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && + isMouseClicked()) { + time = WIDGET_BUTTON_TIME; #ifdef DEBUG - printf(_("Event caught\n")); + printf(_("Event caught\n")); #endif - p->fce_event(widget); - } + p->fce_event(widget); + } } -void -destroyWidgetButton(widget_t * widget) +void destroyWidgetButton(widget_t * widget) { - widget_button_t *p; + widget_button_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTON); - p = (widget_button_t *) widget->private_data; + p = (widget_button_t *) widget->private_data; - free(p->text); - free(p); + free(p->text); + free(p); - destroyWidget(widget); + destroyWidget(widget); } diff --git a/src/widget/widget_button.h b/src/widget/widget_button.h index a0e50db..ac238be 100644 --- a/src/widget/widget_button.h +++ b/src/widget/widget_button.h @@ -1,25 +1,24 @@ #ifndef WIDGET_BUTTON_H -#define WIDGET_BUTTON_H +# define WIDGET_BUTTON_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -#define WIDGET_BUTTON_TIME 10 +# define WIDGET_BUTTON_TIME 10 -#define WIDGET_BUTTON_WIDTH 125 -#define WIDGET_BUTTON_HEIGHT 36 +# define WIDGET_BUTTON_WIDTH 125 +# define WIDGET_BUTTON_HEIGHT 36 -typedef struct widget_button -{ - char *text; - int w, h; - void (*fce_event) (void *); +typedef struct widget_button { + char *text; + int w, h; + void (*fce_event) (void *); } widget_button_t; extern widget_t *newWidgetButton(char *text, int x, int y, - void (*fce_event) (void *)); + void (*fce_event) (void *)); extern void drawWidgetButton(widget_t * widget); extern void eventWidgetButton(widget_t * widget); extern void destroyWidgetButton(widget_t * widget); diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c index 8c567a3..6c89d79 100644 --- a/src/widget/widget_buttonimage.c +++ b/src/widget/widget_buttonimage.c @@ -10,83 +10,77 @@ #include "widget.h" #include "widget_buttonimage.h" -widget_t * -newWidgetButtonimage(image_t * image, int x, int y, - void (*fce_event) (void *)) +widget_t *newWidgetButtonimage(image_t * image, int x, int y, + void (*fce_event) (void *)) { - widget_buttonimage_t *new; + widget_buttonimage_t *new; - new = malloc(sizeof(widget_buttonimage_t)); - new->image = image; - new->w = image->w / 2; - new->h = image->h; - new->active = 0; - new->fce_event = fce_event; + new = malloc(sizeof(widget_buttonimage_t)); + new->image = image; + new->w = image->w / 2; + new->h = image->h; + new->active = 0; + new->fce_event = fce_event; - return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); + return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); } -void -setWidgetButtonimageActive(widget_t * widget, bool_t active) +void setWidgetButtonimageActive(widget_t * widget, bool_t active) { - widget_buttonimage_t *p; + widget_buttonimage_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - p = (widget_buttonimage_t *) widget->private_data; - p->active = active; + p = (widget_buttonimage_t *) widget->private_data; + p->active = active; } -void -drawWidgetButtonimage(widget_t * widget) +void drawWidgetButtonimage(widget_t * widget) { - widget_buttonimage_t *p; + widget_buttonimage_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - p = (widget_buttonimage_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, p->active * p->w, 0, p->w, - p->h); + p = (widget_buttonimage_t *) widget->private_data; + drawImage(p->image, widget->x, widget->y, p->active * p->w, 0, p->w, p->h); } -void -eventWidgetButtonimage(widget_t * widget) +void eventWidgetButtonimage(widget_t * widget) { - widget_buttonimage_t *p; - static int time = 0; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - - p = (widget_buttonimage_t *) widget->private_data; - if (time > 0) { - time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + p->w && - y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { - time = WIDGET_BUTTONIMAGE_TIME; - p->active = 1; - p->fce_event(widget); - } + widget_buttonimage_t *p; + static int time = 0; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + + p = (widget_buttonimage_t *) widget->private_data; + if (time > 0) { + time--; + return; + } + + getMousePosition(&x, &y); + + if (x >= widget->x && x <= widget->x + p->w && + y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { + time = WIDGET_BUTTONIMAGE_TIME; + p->active = 1; + p->fce_event(widget); + } } -void -destroyWidgetButtonimage(widget_t * widget) +void destroyWidgetButtonimage(widget_t * widget) { - widget_buttonimage_t *p; + widget_buttonimage_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - p = (widget_buttonimage_t *) widget->private_data; + p = (widget_buttonimage_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_buttonimage.h b/src/widget/widget_buttonimage.h index a607127..5a0ab7c 100644 --- a/src/widget/widget_buttonimage.h +++ b/src/widget/widget_buttonimage.h @@ -1,24 +1,23 @@ #ifndef WIDGET_BUTTONIMAGE_H -#include "main.h" +# include "main.h" -#define WIDGET_BUTTONIMAGE_H +# define WIDGET_BUTTONIMAGE_H -#define WIDGET_BUTTONIMAGE_TIME 10 +# define WIDGET_BUTTONIMAGE_TIME 10 -#include "widget.h" +# include "widget.h" -typedef struct widget_buttonimageimage -{ - int w, h; - int active; - image_t *image; - void (*fce_event) (void *); +typedef struct widget_buttonimageimage { + int w, h; + int active; + image_t *image; + void (*fce_event) (void *); } widget_buttonimage_t; extern widget_t *newWidgetButtonimage(image_t * image, int x, int y, - void (*fce_event) (void *)); + void (*fce_event) (void *)); extern void setWidgetButtonimageActive(widget_t * widget, bool_t active); extern void drawWidgetButtonimage(widget_t * widget); diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c index fd3389e..37fab55 100644 --- a/src/widget/widget_catchkey.c +++ b/src/widget/widget_catchkey.c @@ -9,141 +9,132 @@ #include "widget.h" #include "widget_catchkey.h" -widget_t * -newWidgetCatchkey(int key, int x, int y, void *event) +widget_t *newWidgetCatchkey(int key, int x, int y, void *event) { - widget_catchkey_t *new; + widget_catchkey_t *new; - new = malloc(sizeof(widget_catchkey_t)); - new->key = key; - new->fce_event = event; - new->active = FALSE; + new = malloc(sizeof(widget_catchkey_t)); + new->key = key; + new->fce_event = event; + new->active = FALSE; - return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, - WIDGET_CATCHKEY_HEIGHT, new); + return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, + WIDGET_CATCHKEY_HEIGHT, new); } -int -getWidgetCatchKey(widget_t * widget) +int getWidgetCatchKey(widget_t * widget) { - widget_catchkey_t *p; + widget_catchkey_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - return p->key; + return p->key; } -void -setWidgetCatchKey(widget_t * widget, int key) +void setWidgetCatchKey(widget_t * widget, int key) { - widget_catchkey_t *p; + widget_catchkey_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - p->key = key; + p->key = key; } -void -drawWidgetCatchkey(widget_t * widget) +void drawWidgetCatchkey(widget_t * widget) { - widget_catchkey_t *p; - char *name; + widget_catchkey_t *p; + char *name; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); - p = (widget_catchkey_t *) widget->private_data; - name = NULL; + p = (widget_catchkey_t *) widget->private_data; + name = NULL; - if (p->key != WIDGET_CATCHKEY_NOKEY) { - name = (char *) SDL_GetKeyName(p->key); - } + if (p->key != WIDGET_CATCHKEY_NOKEY) { + name = (char *) SDL_GetKeyName(p->key); + } - if (name == NULL) { - name = "no key"; - } + if (name == NULL) { + name = "no key"; + } - if (p->active) { - drawFont(name, widget->x, widget->y, COLOR_RED); - } - else { - drawFont(name, widget->x, widget->y, COLOR_WHITE); - } + if (p->active) { + drawFont(name, widget->x, widget->y, COLOR_RED); + } else { + drawFont(name, widget->x, widget->y, COLOR_WHITE); + } } -static int -getPessAnyKey() +static int getPessAnyKey() { - Uint8 *mapa; - int i; + Uint8 *mapa; + int i; - mapa = SDL_GetKeyState(NULL); + mapa = SDL_GetKeyState(NULL); - for (i = SDLK_FIRST; i <= SDLK_COMPOSE; i++) { - if (i == SDLK_NUMLOCK || // black key - i == SDLK_CAPSLOCK || i == SDLK_SCROLLOCK) { - continue; - } + for (i = SDLK_FIRST; i <= SDLK_COMPOSE; i++) { + if (i == SDLK_NUMLOCK || // black key + i == SDLK_CAPSLOCK || i == SDLK_SCROLLOCK) { + continue; + } - if (mapa[i] == SDL_PRESSED) { - return i; - } - } + if (mapa[i] == SDL_PRESSED) { + return i; + } + } - return WIDGET_CATCHKEY_NOKEY; + return WIDGET_CATCHKEY_NOKEY; } -void -eventWidgetCatchkey(widget_t * widget) +void eventWidgetCatchkey(widget_t * widget) { - widget_catchkey_t *p; - int x, y; + widget_catchkey_t *p; + int x, y; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (isMouseClicked()) { - if (x >= widget->x && x <= widget->x + WIDGET_CATCHKEY_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CATCHKEY_HEIGHT) { - p->active = TRUE; - } - else { - p->active = FALSE; - } - } + if (isMouseClicked()) { + if (x >= widget->x && x <= widget->x + WIDGET_CATCHKEY_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_CATCHKEY_HEIGHT) { + p->active = TRUE; + } else { + p->active = FALSE; + } + } - if (p->active == TRUE) { - int key; + if (p->active == TRUE) { + int key; - key = getPessAnyKey(); + key = getPessAnyKey(); - if (key != WIDGET_CATCHKEY_NOKEY) { - p->key = key; - p->fce_event(widget); - } - } + if (key != WIDGET_CATCHKEY_NOKEY) { + p->key = key; + p->fce_event(widget); + } + } } -void -destroyWidgetCatchkey(widget_t * widget) +void destroyWidgetCatchkey(widget_t * widget) { - widget_catchkey_t *p; + widget_catchkey_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_catchkey.h b/src/widget/widget_catchkey.h index 1b318c6..106bc92 100644 --- a/src/widget/widget_catchkey.h +++ b/src/widget/widget_catchkey.h @@ -1,21 +1,20 @@ #ifndef WIDGET_CATCHKEY_H -#define WIDGET_CATCHKEY_H +# define WIDGET_CATCHKEY_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -#define WIDGET_CATCHKEY_WIDTH 110 -#define WIDGET_CATCHKEY_HEIGHT 12 +# define WIDGET_CATCHKEY_WIDTH 110 +# define WIDGET_CATCHKEY_HEIGHT 12 -#define WIDGET_CATCHKEY_NOKEY -1 +# define WIDGET_CATCHKEY_NOKEY -1 -typedef struct widget_catchkey_struct -{ - int w, h; - int key; - bool_t active; - void (*fce_event) (void *p); +typedef struct widget_catchkey_struct { + int w, h; + int key; + bool_t active; + void (*fce_event) (void *p); } widget_catchkey_t; extern widget_t *newWidgetCatchkey(int key, int x, int y, void *event); diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c index 6ca1203..e57f151 100644 --- a/src/widget/widget_check.c +++ b/src/widget/widget_check.c @@ -9,121 +9,114 @@ #include "widget.h" #include "widget_check.h" -widget_t * -newWidgetCheck(int x, int y, bool_t status, void (*fce_event) (void *)) +widget_t *newWidgetCheck(int x, int y, bool_t status, + void (*fce_event) (void *)) { - widget_check_t *new; + widget_check_t *new; - new = malloc(sizeof(widget_check_t)); - new->time = 0; - new->status = status; - new->fce_event = fce_event; + new = malloc(sizeof(widget_check_t)); + new->time = 0; + new->status = status; + new->fce_event = fce_event; - return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, - WIDGET_CHECK_HEIGHT, new); + return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, + WIDGET_CHECK_HEIGHT, new); } -void -drawWidgetCheck(widget_t * widget) +void drawWidgetCheck(widget_t * widget) { - widget_check_t *p; - static image_t *g_check = NULL; - int x, y; - int offset; + widget_check_t *p; + static image_t *g_check = NULL; + int x, y; + int offset; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); - p = (widget_check_t *) widget->private_data; + p = (widget_check_t *) widget->private_data; - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (g_check == NULL) { - g_check = - addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); - } + if (g_check == NULL) { + g_check = + addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); + } - if (p->status == TRUE) { - offset = 0; - } - else { - offset = WIDGET_CHECK_WIDTH; - } + if (p->status == TRUE) { + offset = 0; + } else { + offset = WIDGET_CHECK_WIDTH; + } - drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, - WIDGET_CHECK_HEIGHT); + drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, + WIDGET_CHECK_HEIGHT); } -void -eventWidgetCheck(widget_t * widget) +void eventWidgetCheck(widget_t * widget) { - widget_check_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - - if (p->time > 0) { - p->time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && - isMouseClicked()) { - if (p->status == TRUE) { - p->status = FALSE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - else { - p->status = TRUE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - - if (p->fce_event != NULL) { - p->fce_event(widget); - } - } + widget_check_t *p; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); + + p = (widget_check_t *) widget->private_data; + + if (p->time > 0) { + p->time--; + return; + } + + getMousePosition(&x, &y); + + if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && + isMouseClicked()) { + if (p->status == TRUE) { + p->status = FALSE; + p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; + } else { + p->status = TRUE; + p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; + } + + if (p->fce_event != NULL) { + p->fce_event(widget); + } + } } -bool_t -getWidgetCheckStatus(widget_t * widget) +bool_t getWidgetCheckStatus(widget_t * widget) { - widget_check_t *p; + widget_check_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); - p = (widget_check_t *) widget->private_data; + p = (widget_check_t *) widget->private_data; - return p->status; + return p->status; } -void -setWidgetCheckStatus(widget_t * widget, bool_t status) +void setWidgetCheckStatus(widget_t * widget, bool_t status) { - widget_check_t *p; + widget_check_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); - p = (widget_check_t *) widget->private_data; - p->status = status; + p = (widget_check_t *) widget->private_data; + p->status = status; } -void -destroyWidgetCheck(widget_t * widget) +void destroyWidgetCheck(widget_t * widget) { - widget_check_t *p; + widget_check_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); - p = (widget_check_t *) widget->private_data; - free(p); - destroyWidget(widget); + p = (widget_check_t *) widget->private_data; + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_check.h b/src/widget/widget_check.h index df42001..007e82c 100644 --- a/src/widget/widget_check.h +++ b/src/widget/widget_check.h @@ -1,25 +1,24 @@ #ifndef WIDGET_CHECK_H -#define WIDGET_CHECK_H +# define WIDGET_CHECK_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -#define WIDGET_CHECK_TIME_SWITCH_STATUS 5 +# define WIDGET_CHECK_TIME_SWITCH_STATUS 5 -#define WIDGET_CHECK_WIDTH 25 -#define WIDGET_CHECK_HEIGHT 25 +# define WIDGET_CHECK_WIDTH 25 +# define WIDGET_CHECK_HEIGHT 25 -typedef struct widget_check -{ - bool_t status; - int time; - void (*fce_event) (void *); +typedef struct widget_check { + bool_t status; + int time; + void (*fce_event) (void *); } widget_check_t; extern widget_t *newWidgetCheck(int x, int y, bool_t status, - void (*fce_event) (void *)); + void (*fce_event) (void *)); extern void drawWidgetCheck(widget_t * widget); extern void eventWidgetCheck(widget_t * widget); extern bool_t getWidgetCheckStatus(widget_t * widget); diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c index 62eeb89..64533af 100644 --- a/src/widget/widget_choicegroup.c +++ b/src/widget/widget_choicegroup.c @@ -9,152 +9,143 @@ #include "widget.h" #include "widget_choicegroup.h" -widget_t * -newWidgetChoicegroup(int x, int y, bool_t status, list_t * list, - void (*fce_event) (void *)) +widget_t *newWidgetChoicegroup(int x, int y, bool_t status, list_t * list, + void (*fce_event) (void *)) { - widget_choicegroup_t *new; - widget_t *widget; + widget_choicegroup_t *new; + widget_t *widget; - new = malloc(sizeof(widget_choicegroup_t)); - new->time = 0; - new->status = status; - new->fce_event = fce_event; - new->list = list; + new = malloc(sizeof(widget_choicegroup_t)); + new->time = 0; + new->status = status; + new->fce_event = fce_event; + new->list = list; - widget = - newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, - WIDGET_CHOICEGROUP_HEIGHT, new); - addList(new->list, widget); + widget = + newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, + WIDGET_CHOICEGROUP_HEIGHT, new); + addList(new->list, widget); - return widget; + return widget; } -void -drawWidgetChoicegroup(widget_t * widget) +void drawWidgetChoicegroup(widget_t * widget) { - widget_choicegroup_t *p; - static image_t *g_choicegroup = NULL; - int x, y; - int offset; + widget_choicegroup_t *p; + static image_t *g_choicegroup = NULL; + int x, y; + int offset; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); - p = (widget_choicegroup_t *) widget->private_data; + p = (widget_choicegroup_t *) widget->private_data; - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (g_choicegroup == NULL) { - g_choicegroup = - addImageData("choice.png", IMAGE_ALPHA, "choicegroup", - IMAGE_GROUP_BASE); - } + if (g_choicegroup == NULL) { + g_choicegroup = + addImageData("choice.png", IMAGE_ALPHA, "choicegroup", + IMAGE_GROUP_BASE); + } - if (p->status == TRUE) { - offset = 0; - } - else { - offset = WIDGET_CHOICEGROUP_WIDTH; - } + if (p->status == TRUE) { + offset = 0; + } else { + offset = WIDGET_CHOICEGROUP_WIDTH; + } - drawImage(g_choicegroup, widget->x, widget->y, offset, 0, - WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); + drawImage(g_choicegroup, widget->x, widget->y, offset, 0, + WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); } -void -setWidgetChoiceActive(widget_t * widget) +void setWidgetChoiceActive(widget_t * widget) { - widget_choicegroup_t *p; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - - for (i = 0; i < p->list->count; i++) { - widget_t *this; - widget_choicegroup_t *thisChoice; - - this = (widget_t *) p->list->list[i]; - thisChoice = (widget_choicegroup_t *) this->private_data; - - if (widget == this) { - thisChoice->status = TRUE; - thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; - thisChoice->fce_event(p); - } - else { - thisChoice->status = FALSE; - } - } + widget_choicegroup_t *p; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + + for (i = 0; i < p->list->count; i++) { + widget_t *this; + widget_choicegroup_t *thisChoice; + + this = (widget_t *) p->list->list[i]; + thisChoice = (widget_choicegroup_t *) this->private_data; + + if (widget == this) { + thisChoice->status = TRUE; + thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; + thisChoice->fce_event(p); + } else { + thisChoice->status = FALSE; + } + } } -bool_t -getWidgetChoiceStatus(widget_t * widget) +bool_t getWidgetChoiceStatus(widget_t * widget) { - widget_choicegroup_t *p; + widget_choicegroup_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); - p = (widget_choicegroup_t *) widget->private_data; + p = (widget_choicegroup_t *) widget->private_data; - return p->status; + return p->status; } -void -setWidgetChoiceStatus(widget_t * widget, bool_t status) +void setWidgetChoiceStatus(widget_t * widget, bool_t status) { - widget_choicegroup_t *p; + widget_choicegroup_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); - p = (widget_choicegroup_t *) widget->private_data; - p->status = status; + p = (widget_choicegroup_t *) widget->private_data; + p->status = status; } -void -eventWidgetChoicegroup(widget_t * widget) +void eventWidgetChoicegroup(widget_t * widget) { - widget_choicegroup_t *p; - int x, y; + widget_choicegroup_t *p; + int x, y; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); - p = (widget_choicegroup_t *) widget->private_data; + p = (widget_choicegroup_t *) widget->private_data; - if (p->time > 0) { - p->time--; - return; - } + if (p->time > 0) { + p->time--; + return; + } - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && - isMouseClicked()) { - setWidgetChoiceActive(widget); - } + if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && + isMouseClicked()) { + setWidgetChoiceActive(widget); + } } -void -destroyWidgetChoicegroup(widget_t * widget) +void destroyWidgetChoicegroup(widget_t * widget) { - widget_choicegroup_t *p; - int index; + widget_choicegroup_t *p; + int index; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); - p = (widget_choicegroup_t *) widget->private_data; - index = searchListItem(p->list, widget); - assert(index != -1); - delList(p->list, index); + p = (widget_choicegroup_t *) widget->private_data; + index = searchListItem(p->list, widget); + assert(index != -1); + delList(p->list, index); - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_choicegroup.h b/src/widget/widget_choicegroup.h index 8cc6764..a892d74 100644 --- a/src/widget/widget_choicegroup.h +++ b/src/widget/widget_choicegroup.h @@ -1,28 +1,27 @@ #ifndef WIDGET_CHOICEGROUP_H -#define WIDGET_CHOICEGROUP_H +# define WIDGET_CHOICEGROUP_H -#include "main.h" -#include "list.h" -#include "widget.h" +# include "main.h" +# include "list.h" +# include "widget.h" -#define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 +# define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 -#define WIDGET_CHOICEGROUP_WIDTH 25 -#define WIDGET_CHOICEGROUP_HEIGHT 25 +# define WIDGET_CHOICEGROUP_WIDTH 25 +# define WIDGET_CHOICEGROUP_HEIGHT 25 -typedef struct widget_choicegroup -{ - bool_t status; - int time; - void (*fce_event) (void *); - list_t *list; +typedef struct widget_choicegroup { + bool_t status; + int time; + void (*fce_event) (void *); + list_t *list; } widget_choicegroup_t; extern widget_t *newWidgetChoicegroup(int x, int y, bool_t status, - list_t * list, - void (*fce_event) (void *)); + list_t * list, + void (*fce_event) (void *)); extern void drawWidgetChoicegroup(widget_t * p); extern void setWidgetChoiceActive(widget_t * widget); diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c index 2287541..ad49f9e 100644 --- a/src/widget/widget_image.c +++ b/src/widget/widget_image.c @@ -11,46 +11,42 @@ #include "widget.h" #include "widget_image.h" -widget_t * -newWidgetImage(int x, int y, image_t * image) +widget_t *newWidgetImage(int x, int y, image_t * image) { - widget_image_t *new; + widget_image_t *new; - new = malloc(sizeof(widget_image_t)); - new->image = image; + new = malloc(sizeof(widget_image_t)); + new->image = image; - return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); + return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); } -void -drawWidgetImage(widget_t * widget) +void drawWidgetImage(widget_t * widget) { - widget_image_t *p; + widget_image_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_IMAGE); - p = (widget_image_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); + p = (widget_image_t *) widget->private_data; + drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); } -void -eventWidgetImage(widget_t * widget) +void eventWidgetImage(widget_t * widget) { - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_IMAGE); } -void -destroyWidgetImage(widget_t * widget) +void destroyWidgetImage(widget_t * widget) { - widget_image_t *p; + widget_image_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_IMAGE); - p = (widget_image_t *) widget->private_data; + p = (widget_image_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_image.h b/src/widget/widget_image.h index 86cf6bc..081fbda 100644 --- a/src/widget/widget_image.h +++ b/src/widget/widget_image.h @@ -1,15 +1,14 @@ #ifndef WIDGET_IMAGE_H -#define WIDGET_IMAGE_H +# define WIDGET_IMAGE_H -#include "main.h" -#include "interface.h" -#include "widget.h" +# include "main.h" +# include "interface.h" +# include "widget.h" -typedef struct widget_image -{ - image_t *image; +typedef struct widget_image { + image_t *image; } widget_image_t; extern widget_t *newWidgetImage(int x, int y, image_t * image); diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c index 449f916..d4bb813 100644 --- a/src/widget/widget_label.c +++ b/src/widget/widget_label.c @@ -8,63 +8,58 @@ #include "widget_label.h" #include "widget.h" -widget_t * -newWidgetLabel(char *text, int x, int y, int bind) +widget_t *newWidgetLabel(char *text, int x, int y, int bind) { - widget_label_t *new; + widget_label_t *new; - new = malloc(sizeof(widget_label_t)); - new->text = strdup(text); - new->bind = bind; - getTextSize(text, &(new->w), &(new->h)); + new = malloc(sizeof(widget_label_t)); + new->text = strdup(text); + new->bind = bind; + getTextSize(text, &(new->w), &(new->h)); - return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); + return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); } -void -drawWidgetLabel(widget_t * widget) +void drawWidgetLabel(widget_t * widget) { - widget_label_t *p; + widget_label_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_LABEL); - p = (widget_label_t *) widget->private_data; + p = (widget_label_t *) widget->private_data; - switch (p->bind) { - case WIDGET_LABEL_RIGHT: - drawFont(p->text, widget->x + p->w, widget->y + p->h / 2, - COLOR_WHITE); - break; - case WIDGET_LABEL_LEFT: - drawFont(p->text, widget->x, widget->y + widget->h / 2, COLOR_WHITE); - break; - case WIDGET_LABEL_CENTER: - drawFont(p->text, widget->x - p->w / 2, widget->y + p->h / 2, - COLOR_WHITE); - break; - } + switch (p->bind) { + case WIDGET_LABEL_RIGHT: + drawFont(p->text, widget->x + p->w, widget->y + p->h / 2, COLOR_WHITE); + break; + case WIDGET_LABEL_LEFT: + drawFont(p->text, widget->x, widget->y + widget->h / 2, COLOR_WHITE); + break; + case WIDGET_LABEL_CENTER: + drawFont(p->text, widget->x - p->w / 2, widget->y + p->h / 2, + COLOR_WHITE); + break; + } } -void -eventWidgetLabel(widget_t * widget) +void eventWidgetLabel(widget_t * widget) { - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_LABEL); } -void -destroyWidgetLabel(widget_t * widget) +void destroyWidgetLabel(widget_t * widget) { - widget_label_t *p; + widget_label_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_LABEL); - p = (widget_label_t *) widget->private_data; + p = (widget_label_t *) widget->private_data; - free(p->text); - free(p); + free(p->text); + free(p); - destroyWidget(widget); + destroyWidget(widget); } diff --git a/src/widget/widget_label.h b/src/widget/widget_label.h index 8ad29b5..743db7e 100644 --- a/src/widget/widget_label.h +++ b/src/widget/widget_label.h @@ -1,21 +1,20 @@ #ifndef WIDGET_LABEL_H -#define WIDGET_LABEL_H +# define WIDGET_LABEL_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -typedef struct widget_label -{ - int w, h; - char *text; - int bind; +typedef struct widget_label { + int w, h; + char *text; + int bind; } widget_label_t; -#define WIDGET_LABEL_RIGHT 1 -#define WIDGET_LABEL_LEFT 2 -#define WIDGET_LABEL_CENTER 3 +# define WIDGET_LABEL_RIGHT 1 +# define WIDGET_LABEL_LEFT 2 +# define WIDGET_LABEL_CENTER 3 extern widget_t *newWidgetLabel(char *text, int x, int y, int bind); extern void drawWidgetLabel(widget_t * widget); diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c index 78877f0..2f89fe2 100644 --- a/src/widget/widget_select.c +++ b/src/widget/widget_select.c @@ -9,152 +9,142 @@ #include "widget.h" #include "widget_select.h" -widget_t * -newWidgetSelect(int x, int y, void (*fce_event) (void *)) +widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)) { - widget_select_t *new; + widget_select_t *new; - new = malloc(sizeof(widget_select_t)); - new->select = -1; - new->fce_event = fce_event; - new->list = newList(); + new = malloc(sizeof(widget_select_t)); + new->select = -1; + new->fce_event = fce_event; + new->list = newList(); - return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); + return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); } -char * -getWidgetSelectItem(widget_t * widget) +char *getWidgetSelectItem(widget_t * widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *) widget->private_data; - if (p->select == -1) { - return NULL; - } + if (p->select == -1) { + return NULL; + } - return (char *) p->list->list[p->select]; + return (char *) p->list->list[p->select]; } -int -getWidgetSelectIndex(widget_t * widget) +int getWidgetSelectIndex(widget_t * widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *) widget->private_data; - return p->select; + return p->select; } -void -addToWidgetSelect(widget_t * widget, char *s) +void addToWidgetSelect(widget_t * widget, char *s) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *) widget->private_data; - addList(p->list, strdup(s)); + addList(p->list, strdup(s)); } -void -removeAllFromWidgetSelect(widget_t * widget) +void removeAllFromWidgetSelect(widget_t * widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *) widget->private_data; - while (p->list->count > 0) { - delListItem(p->list, 0, free); - } + while (p->list->count > 0) { + delListItem(p->list, 0, free); + } } -void -drawWidgetSelect(widget_t * widget) +void drawWidgetSelect(widget_t * widget) { - widget_select_t *p; - int x, y, w, h; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - getMousePosition(&x, &y); - p = (widget_select_t *) widget->private_data; - - for (i = 0; i < p->list->count; i++) { - char *line; - - line = (char *) p->list->list[i]; - - getTextSize(line, &w, &h); - - if (x > widget->x && y > widget->y + i * 20 && x < widget->x + w - && y < widget->y + i * 20 + h) { - drawFont(line, widget->x, widget->y + i * 20, COLOR_YELLOW); - } - else { - if (p->select == i) { - drawFont(line, widget->x, widget->y + i * 20, COLOR_RED); - } - else { - drawFont(line, widget->x, widget->y + i * 20, COLOR_WHITE); - } - } - } + widget_select_t *p; + int x, y, w, h; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + getMousePosition(&x, &y); + p = (widget_select_t *) widget->private_data; + + for (i = 0; i < p->list->count; i++) { + char *line; + + line = (char *) p->list->list[i]; + + getTextSize(line, &w, &h); + + if (x > widget->x && y > widget->y + i * 20 && x < widget->x + w + && y < widget->y + i * 20 + h) { + drawFont(line, widget->x, widget->y + i * 20, COLOR_YELLOW); + } else { + if (p->select == i) { + drawFont(line, widget->x, widget->y + i * 20, COLOR_RED); + } else { + drawFont(line, widget->x, widget->y + i * 20, COLOR_WHITE); + } + } + } } -void -eventWidgetSelect(widget_t * widget) +void eventWidgetSelect(widget_t * widget) { - widget_select_t *p; - int x, y, w, h; - int i; + widget_select_t *p; + int x, y, w, h; + int i; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); - p = (widget_select_t *) widget->private_data; - getMousePosition(&x, &y); + p = (widget_select_t *) widget->private_data; + getMousePosition(&x, &y); - for (i = 0; i < p->list->count; i++) { - char *line; + for (i = 0; i < p->list->count; i++) { + char *line; - line = (char *) p->list->list[i]; + line = (char *) p->list->list[i]; - getTextSize(line, &w, &h); + getTextSize(line, &w, &h); - if (x > widget->x && y > widget->y + i * 20 && - x < widget->x + w && y < widget->y + i * 20 + h && - isMouseClicked()) { - p->select = i; - p->fce_event(p); - } - } + if (x > widget->x && y > widget->y + i * 20 && + x < widget->x + w && y < widget->y + i * 20 + h && + isMouseClicked()) { + p->select = i; + p->fce_event(p); + } + } } -void -destroyWidgetSelect(widget_t * widget) +void destroyWidgetSelect(widget_t * widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *) widget->private_data; - destroyListItem(p->list, free); - free(p); - destroyWidget(widget); + destroyListItem(p->list, free); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h index ba7b9d4..9d772cc 100644 --- a/src/widget/widget_select.h +++ b/src/widget/widget_select.h @@ -1,18 +1,17 @@ #ifndef WIDGET_SELECT_H -#define WIDGET_SELECT_H +# define WIDGET_SELECT_H -#include "main.h" -#include "list.h" -#include "widget.h" +# include "main.h" +# include "list.h" +# include "widget.h" -typedef struct widget_select -{ - int w, h; - list_t *list; - int select; - void (*fce_event) (void *); +typedef struct widget_select { + int w, h; + list_t *list; + int select; + void (*fce_event) (void *); } widget_select_t; extern widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)); diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index 77abb40..b3aeeb3 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -12,457 +12,438 @@ //#define ZZEEXX86_READKEY -widget_t * -newWidgetTextfield(char *text, int filter, int x, int y) +widget_t *newWidgetTextfield(char *text, int filter, int x, int y) { - widget_textfield_t *new; + widget_textfield_t *new; - new = malloc(sizeof(widget_textfield_t)); - memset(new, 0, sizeof(widget_textfield_t)); + new = malloc(sizeof(widget_textfield_t)); + memset(new, 0, sizeof(widget_textfield_t)); - strcpy(new->text, text); - new->time = 0; - new->timeBlick = 0; - new->atime = 0; - new->active = FALSE; - new->filter = filter; - getTextSize(text, &new->w, &new->h); + strcpy(new->text, text); + new->time = 0; + new->timeBlick = 0; + new->atime = 0; + new->active = FALSE; + new->filter = filter; + getTextSize(text, &new->w, &new->h); - return newWidget(WIDGET_TYPE_TEXTFILED, x, y, WIDGET_TEXTFIELD_WIDTH, - WIDGET_TEXTFIELD_HEIGHT, new); + return newWidget(WIDGET_TYPE_TEXTFILED, x, y, WIDGET_TEXTFIELD_WIDTH, + WIDGET_TEXTFIELD_HEIGHT, new); } -static void -drawBackground(widget_t * widget) +static void drawBackground(widget_t * widget) { - static image_t *g_textfield0 = NULL; - static image_t *g_textfield1 = NULL; - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - if (g_textfield0 == NULL) { - g_textfield0 = - addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", - IMAGE_GROUP_BASE); - } - - if (g_textfield1 == NULL) { - g_textfield1 = - addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", - IMAGE_GROUP_BASE); - } - - if (p->active) { - drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, - g_textfield1->h); - } - else { - drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, - g_textfield0->h); - } + static image_t *g_textfield0 = NULL; + static image_t *g_textfield1 = NULL; + widget_textfield_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + + if (g_textfield0 == NULL) { + g_textfield0 = + addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", + IMAGE_GROUP_BASE); + } + + if (g_textfield1 == NULL) { + g_textfield1 = + addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", + IMAGE_GROUP_BASE); + } + + if (p->active) { + drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, + g_textfield1->h); + } else { + drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, + g_textfield0->h); + } } -static void -drawText(widget_t * widget) +static void drawText(widget_t * widget) { - char str[STR_SIZE]; - widget_textfield_t *p; + char str[STR_SIZE]; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - strcpy(str, p->text); + strcpy(str, p->text); - if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && - p->active == TRUE) { - //strcat(str, ">"); - strcat(str, "\f"); - } + if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && + p->active == TRUE) { + //strcat(str, ">"); + strcat(str, "\f"); + } - p->timeBlick++; + p->timeBlick++; - if (p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR) { - p->timeBlick = 0; - } + if (p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR) { + p->timeBlick = 0; + } + //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); + //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); - //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); - //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); - - drawFont(str, - widget->x + WIDGET_TEXTFIELD_TEXT_OFFSET_X, - widget->y + WIDGET_TEXTFIELD_HEIGHT / 2 - p->h / 2, COLOR_WHITE); + drawFont(str, + widget->x + WIDGET_TEXTFIELD_TEXT_OFFSET_X, + widget->y + WIDGET_TEXTFIELD_HEIGHT / 2 - p->h / 2, COLOR_WHITE); } -void -drawWidgetTextfield(widget_t * widget) +void drawWidgetTextfield(widget_t * widget) { - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); - drawBackground(widget); - drawText(widget); + drawBackground(widget); + drawText(widget); } -void -setWidgetTextFiledText(widget_t * widget, char *text) +void setWidgetTextFiledText(widget_t * widget, char *text) { - widget_textfield_t *p; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - memset(p->text, 0, STR_SIZE); - strcpy(p->text, text); - getTextSize(text, &p->w, &p->h); + memset(p->text, 0, STR_SIZE); + strcpy(p->text, text); + getTextSize(text, &p->w, &p->h); } -char * -getTextFromWidgetTextfield(widget_t * widget) +char *getTextFromWidgetTextfield(widget_t * widget) { - widget_textfield_t *p; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); - p = (widget_textfield_t *) widget->private_data; - return p->text; + p = (widget_textfield_t *) widget->private_data; + return p->text; } -static void -checkText(widget_textfield_t * p) +static void checkText(widget_textfield_t * p) { - int len; - int i; - - //printf("check\n"); - - len = strlen(p->text); - - for (i = 0; i < len; i++) { - char c; - bool_t isDel; - - c = p->text[i]; - isDel = TRUE; - - switch (p->filter) { - case WIDGET_TEXTFIELD_FILTER_ALL: - isDel = FALSE; - break; - - case WIDGET_TEXTFIELD_FILTER_NUM: - if (c >= '0' && c <= '9') { - isDel = FALSE; - } - break; - - case WIDGET_TEXTFIELD_FILTER_ALPHANUM: - if ((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || (c == '_' || c == '-')) { - isDel = FALSE; - } - break; - - case WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN: - if ((c >= '0' && c <= '9') || (c == '.' || c == ':' || c == '-')) { - isDel = FALSE; - } - break; - - default: - assert(!_("Bad filter!")); - break; - } - - if (isDel) { - memmove(p->text + i, p->text + i + 1, len - i); - len = strlen(p->text); - i--; - } - } - - getTextSize(p->text, &p->w, &p->h); + int len; + int i; + + //printf("check\n"); + + len = strlen(p->text); + + for (i = 0; i < len; i++) { + char c; + bool_t isDel; + + c = p->text[i]; + isDel = TRUE; + + switch (p->filter) { + case WIDGET_TEXTFIELD_FILTER_ALL: + isDel = FALSE; + break; + + case WIDGET_TEXTFIELD_FILTER_NUM: + if (c >= '0' && c <= '9') { + isDel = FALSE; + } + break; + + case WIDGET_TEXTFIELD_FILTER_ALPHANUM: + if ((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || (c == '_' || c == '-')) { + isDel = FALSE; + } + break; + + case WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN: + if ((c >= '0' && c <= '9') || (c == '.' || c == ':' || c == '-')) { + isDel = FALSE; + } + break; + + default: + assert(!_("Bad filter!")); + break; + } + + if (isDel) { + memmove(p->text + i, p->text + i + 1, len - i); + len = strlen(p->text); + i--; + } + } + + getTextSize(p->text, &p->w, &p->h); } #ifdef ZZEEXX86_READKEY -static void -readKey(widget_textfield_t * p) +static void readKey(widget_textfield_t * p) { - Uint8 *mapa; - int len; - int i; - - //printf("readKey w=%d\n", p->w); - - if (p->active == FALSE) { - return; - } - - if (p->atime < 100) - p->atime++; - - mapa = SDL_GetKeyState(NULL); - len = strlen(p->text); - - // mazanie posledneho klavesu - if (mapa[SDLK_BACKSPACE] == SDL_PRESSED) { - if (len > 0) { - p->time = 0; - p->text[len - 1] = '\0'; - getTextSize(p->text, &p->w, &p->h); - } - - return; - } - - if (p->w > WIDGET_TEXTFIELD_WIDTH - 40) { - return; - } - - // klavesy abecedy - for (i = SDLK_SPACE /*SDLK_a */ ; i <= SDLK_z; i++) { - //if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED) - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - if (i == SDLK_SPACE) { - strcat(p->text, " "); - checkText(p); - return; - } - - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - if (p->text[len - 1] == *c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } - else - p->time = 0; - } - - p->atime = 0; - - strcat(p->text, c); - checkText(p); - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { - p->text[strlen(p->text) - 1] -= 32; - checkText(p); - return; - } - } - } - - // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice - for (i = SDLK_0; i <= SDLK_9; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - if (p->text[len - 1] == *c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } - else - p->time = 0; - } - - p->atime = 0; - - strcat(p->text, c); - checkText(p); - return; - } - } - - // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici - for (i = SDLK_KP0; i <= SDLK_KP9; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - const char *c = (const char *) SDL_GetKeyName(i) + 1; - - if (len) { - if (p->text[len - 1] == *c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } - else - p->time = 0; - } - - p->atime = 0; - - strncat(p->text, c, 1); // napr. "[4]" - checkText(p); - return; - } - } + Uint8 *mapa; + int len; + int i; + + //printf("readKey w=%d\n", p->w); + + if (p->active == FALSE) { + return; + } + + if (p->atime < 100) + p->atime++; + + mapa = SDL_GetKeyState(NULL); + len = strlen(p->text); + + // mazanie posledneho klavesu + if (mapa[SDLK_BACKSPACE] == SDL_PRESSED) { + if (len > 0) { + p->time = 0; + p->text[len - 1] = '\0'; + getTextSize(p->text, &p->w, &p->h); + } + + return; + } + + if (p->w > WIDGET_TEXTFIELD_WIDTH - 40) { + return; + } + // klavesy abecedy + for (i = SDLK_SPACE /*SDLK_a */ ; i <= SDLK_z; i++) { + //if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED) + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + if (i == SDLK_SPACE) { + strcat(p->text, " "); + checkText(p); + return; + } + + const char *c = (const char *) SDL_GetKeyName(i); + + if (len) { + if (p->text[len - 1] == *c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else + p->time = 0; + } + + p->atime = 0; + + strcat(p->text, c); + checkText(p); + + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) { + p->text[strlen(p->text) - 1] -= 32; + checkText(p); + return; + } + } + } + + // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice + for (i = SDLK_0; i <= SDLK_9; i++) { + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + const char *c = (const char *) SDL_GetKeyName(i); + + if (len) { + if (p->text[len - 1] == *c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else + p->time = 0; + } + + p->atime = 0; + + strcat(p->text, c); + checkText(p); + return; + } + } + + // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici + for (i = SDLK_KP0; i <= SDLK_KP9; i++) { + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + const char *c = (const char *) SDL_GetKeyName(i) + 1; + + if (len) { + if (p->text[len - 1] == *c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else + p->time = 0; + } + + p->atime = 0; + + strncat(p->text, c, 1); // napr. "[4]" + checkText(p); + return; + } + } } #endif #ifndef ZZEEXX86_READKEY -static void -readKey(widget_textfield_t * p) +static void readKey(widget_textfield_t * p) { - Uint8 *mapa; - int len; - int i; - - const int len_shift_map = 20; - - char shift_map[] = { - '-', '_', - '=', '+', - '[', '{', - ']', '}', - ';', ':', - '/', '\"', - '\\', '|', - ',', '<', - '.', '>', - '/', '?' - }; - - if (p->active == FALSE) { - return; - } - - if (p->atime < 100) - p->atime++; - - mapa = SDL_GetKeyState(NULL); - len = strlen(p->text); - - for (i = SDLK_FIRST; i <= SDLK_F15; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - char *name = (char *) SDL_GetKeyName(i); - char c = '\0'; - - if (name == NULL) - continue; - //printf("name %s\n", name); - - if (strlen(name) == 1) - c = name[0]; - if (strlen(name) == 3) - c = name[1]; - if (strcmp(name, "space") == 0) - c = ' '; - - - if (strcmp(name, "backspace") == 0 && len > 0) { - p->time = 0; - p->text[len - 1] = '\0'; - checkText(p); - return; - } - - if (c == '\0' || p->w > WIDGET_TEXTFIELD_WIDTH - 40) { - continue; - } - - if (len > 0) { - if (p->text[len - 1] == c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } - else { - p->time = 0; - } - } - - p->atime = 0; - - p->text[len] = c; - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { - int i; - - for (i = 0; i < len_shift_map; i += 2) { - if (c == shift_map[i]) { - p->text[len] = shift_map[i + 1]; - } - } - - checkText(p); - return; - } - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { - p->text[len] -= 32; - } - - checkText(p); - return; - } - } + Uint8 *mapa; + int len; + int i; + + const int len_shift_map = 20; + + char shift_map[] = { + '-', '_', + '=', '+', + '[', '{', + ']', '}', + ';', ':', + '/', '\"', + '\\', '|', + ',', '<', + '.', '>', + '/', '?' + }; + + if (p->active == FALSE) { + return; + } + + if (p->atime < 100) + p->atime++; + + mapa = SDL_GetKeyState(NULL); + len = strlen(p->text); + + for (i = SDLK_FIRST; i <= SDLK_F15; i++) { + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + char *name = (char *) SDL_GetKeyName(i); + char c = '\0'; + + if (name == NULL) + continue; + //printf("name %s\n", name); + + if (strlen(name) == 1) + c = name[0]; + if (strlen(name) == 3) + c = name[1]; + if (strcmp(name, "space") == 0) + c = ' '; + + + if (strcmp(name, "backspace") == 0 && len > 0) { + p->time = 0; + p->text[len - 1] = '\0'; + checkText(p); + return; + } + + if (c == '\0' || p->w > WIDGET_TEXTFIELD_WIDTH - 40) { + continue; + } + + if (len > 0) { + if (p->text[len - 1] == c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else { + p->time = 0; + } + } + + p->atime = 0; + + p->text[len] = c; + + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) { + int i; + + for (i = 0; i < len_shift_map; i += 2) { + if (c == shift_map[i]) { + p->text[len] = shift_map[i + 1]; + } + } + + checkText(p); + return; + } + + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) { + p->text[len] -= 32; + } + + checkText(p); + return; + } + } } #endif -void -eventWidgetTextfield(widget_t * widget) +void eventWidgetTextfield(widget_t * widget) { - widget_textfield_t *p; - int x, y; + widget_textfield_t *p; + int x, y; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (isMouseClicked()) { - if (x >= widget->x && x <= widget->x + WIDGET_TEXTFIELD_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { - p->active = TRUE; - } - else { - p->active = FALSE; - } - } + if (isMouseClicked()) { + if (x >= widget->x && x <= widget->x + WIDGET_TEXTFIELD_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { + p->active = TRUE; + } else { + p->active = FALSE; + } + } - readKey(p); + readKey(p); } -void -destroyWidgetTextfield(widget_t * widget) +void destroyWidgetTextfield(widget_t * widget) { - widget_textfield_t *p; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h index be46ea0..7991deb 100644 --- a/src/widget/widget_textfield.h +++ b/src/widget/widget_textfield.h @@ -1,35 +1,34 @@ #ifndef WIDGET_TEXTFIELD_H -#define WIDGET_TEXTFIELD_H - -#include "main.h" -#include "widget.h" - -#define WIDGET_TEXTFIELD_WIDTH 175 -#define WIDGET_TEXTFIELD_HEIGHT 36 - -#define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10 - -#define WIDGET_TEXTFIELD_TIME_MULTIPLE 10 -#define WIDGET_TEXTFIELD_TIME_READ_KEY 2 -#define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20 - -#define WIDGET_TEXTFIELD_FILTER_ALL 0 -#define WIDGET_TEXTFIELD_FILTER_NUM 2 -#define WIDGET_TEXTFIELD_FILTER_ALPHANUM 3 -#define WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN 4 - -typedef struct widget_textfield -{ - int w, h; - int canWrite; - int timeBlick; - int time; - int atime; - int filter; - char text[STR_SIZE]; - bool_t active; +# define WIDGET_TEXTFIELD_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_TEXTFIELD_WIDTH 175 +# define WIDGET_TEXTFIELD_HEIGHT 36 + +# define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10 + +# define WIDGET_TEXTFIELD_TIME_MULTIPLE 10 +# define WIDGET_TEXTFIELD_TIME_READ_KEY 2 +# define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20 + +# define WIDGET_TEXTFIELD_FILTER_ALL 0 +# define WIDGET_TEXTFIELD_FILTER_NUM 2 +# define WIDGET_TEXTFIELD_FILTER_ALPHANUM 3 +# define WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN 4 + +typedef struct widget_textfield { + int w, h; + int canWrite; + int timeBlick; + int time; + int atime; + int filter; + char text[STR_SIZE]; + bool_t active; } widget_textfield_t; extern widget_t *newWidgetTextfield(char *text, int filter, int x, int y); |