diff options
| author | Dusan Durech <dusan@debian.(none)> | 2008-11-11 23:39:21 +0100 |
|---|---|---|
| committer | Dusan Durech <dusan@debian.(none)> | 2008-11-11 23:39:21 +0100 |
| commit | 957f3411170ca1d5f30ee2e2c4e25393195cce75 (patch) | |
| tree | 18567d663d6d759d447b65458a410f426dae9044 /src/base | |
| parent | de05256afe45ad24cda83ed1e2cf873c97de132c (diff) | |
modification coding stile :)
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/arena.c | 112 | ||||
| -rw-r--r-- | src/base/arenaFile.c | 55 | ||||
| -rw-r--r-- | src/base/buffer.c | 1 | ||||
| -rw-r--r-- | src/base/checkFront.c | 41 | ||||
| -rw-r--r-- | src/base/director.c | 10 | ||||
| -rw-r--r-- | src/base/gun.c | 191 | ||||
| -rw-r--r-- | src/base/idManager.c | 4 | ||||
| -rw-r--r-- | src/base/item.c | 398 | ||||
| -rw-r--r-- | src/base/list.c | 20 | ||||
| -rw-r--r-- | src/base/main.c | 6 | ||||
| -rw-r--r-- | src/base/modules.c | 27 | ||||
| -rw-r--r-- | src/base/myTimer.c | 60 | ||||
| -rw-r--r-- | src/base/protect.c | 6 | ||||
| -rw-r--r-- | src/base/proto.c | 146 | ||||
| -rw-r--r-- | src/base/server.c | 28 | ||||
| -rw-r--r-- | src/base/serverSendMsg.c | 57 | ||||
| -rw-r--r-- | src/base/shareFunction.c | 1 | ||||
| -rw-r--r-- | src/base/shot.c | 158 | ||||
| -rw-r--r-- | src/base/space.c | 38 | ||||
| -rw-r--r-- | src/base/storage.c | 13 | ||||
| -rw-r--r-- | src/base/textFile.c | 4 | ||||
| -rw-r--r-- | src/base/tux.c | 188 | ||||
| -rw-r--r-- | src/base/udp_server.c | 18 |
23 files changed, 797 insertions, 785 deletions
diff --git a/src/base/arena.c b/src/base/arena.c index 4391af9..4658e08 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -35,7 +35,7 @@ static int isBigArena(arena_t * arena) 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) { + abs(tux1->y - tux2->y) < WINDOW_SIZE_Y) { return 1; } @@ -112,10 +112,8 @@ arena_t *newArena(int w, int h) } 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->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; @@ -137,10 +135,13 @@ int isFreeSpace(arena_t * arena, int x, int y, int w, int h) 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; @@ -167,9 +168,7 @@ void findFreeSpace(arena_t * arena, int *x, int *y, int w, int h) *y = z_y; } -void -getCenterScreen(int *screen_x, int *screen_y, int x, int y, int screen_size_x, - int screen_size_y) +void getCenterScreen(int *screen_x, int *screen_y, int x, int y, int screen_size_x, int screen_size_y) { arena_t *arena; @@ -204,23 +203,20 @@ static void drawBackground(arena_t * arena, int screen_x, int screen_y) int i, j; for (i = screen_y / arena->background->h; - i <= - screen_y / arena->background->h + - WINDOW_SIZE_Y / arena->background->h + 1; i++) { + 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++) { + 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); + 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); + addLayer(arena->background, 0, 0, 0, 0, arena->background->w, arena->background->h, -100); } } @@ -241,57 +237,46 @@ static void action_drawShot(space_t * space, shot_t * shot, void *p) 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->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->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->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); } -static void -drawSplitArenaForTux(arena_t * arena, tux_t * tux, int location_x, - int location_y) +static void drawSplitArenaForTux(arena_t * arena, tux_t * tux, int location_x, 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; + 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; + 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; } } @@ -303,12 +288,12 @@ void drawSplitArena(arena_t * arena) 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; + 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; } } @@ -351,7 +336,7 @@ void drawSimpleArena(arena_t * arena) void drawArena(arena_t * arena) { if (isBigArena(arena) && - getNetTypeGame() == NET_GAME_TYPE_NONE && !isSettingAI()) { + getNetTypeGame() == NET_GAME_TYPE_NONE && !isSettingAI()) { tux_t *tux1; tux_t *tux2; @@ -359,8 +344,7 @@ void drawArena(arena_t * arena) tux2 = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); if (isTuxNear(tux1, tux2)) { - drawCenterArena(arena, (tux1->x + tux2->x) / 2, - (tux1->y + tux2->y) / 2); + drawCenterArena(arena, (tux1->x + tux2->x) / 2, (tux1->y + tux2->y) / 2); } else { drawSplitArena(arena); } diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c index 1a16cbf..cd76561 100644 --- a/src/base/arenaFile.c +++ b/src/base/arenaFile.c @@ -44,27 +44,36 @@ int getArenaValue(char *line, char *env, char *val, int 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; @@ -76,10 +85,8 @@ image_t *loadImageFromArena(arenaFile_t * arenaFile, char *filename, return image; } -# ifndef NO_SOUND -void -loadMusicFromArena(arenaFile_t * arenaFile, char *filename, char *group, - char *name) +#ifndef NO_SOUND +void loadMusicFromArena(arenaFile_t * arenaFile, char *filename, char *group, char *name) { char *extractFile; @@ -87,7 +94,7 @@ loadMusicFromArena(arenaFile_t * arenaFile, char *filename, char *group, addMusic(extractFile, name, group); deleteExtractFile(extractFile); } -# endif +#endif #endif static void cmd_arena(arena_t ** arena, char *line) @@ -98,10 +105,13 @@ static void cmd_arena(arena_t ** arena, char *line) 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); @@ -120,6 +130,7 @@ static void cmd_loadModule(char *line) if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) return; + loadModule(str_file); } @@ -133,14 +144,15 @@ static void cmd_loadImage(arenaFile_t * arenaFile, char *line) 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)); + loadImageFromArena(arenaFile, str_file, IMAGE_GROUP_USER, str_name, isYesOrNO(str_alpha)); //addImageData(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER); } @@ -152,8 +164,10 @@ static void cmd_loadMusic(arenaFile_t * arenaFile, char *line) 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); @@ -166,6 +180,7 @@ static void cmd_playMusic(arena_t * arena, char *line) if (getArenaValue(line, "music", str_music, STR_SIZE) != 0) return; + strcpy(arena->music, str_music); } #endif @@ -181,12 +196,16 @@ static char *getArenaStatus(textFile_t * ts, char *s) 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; } @@ -209,11 +228,12 @@ char *getArenaNetName(arenaFile_t * arenaFile) arenaFile_t *getArenaFileFormNetName(char *s) { int i; -// + for (i = 0; i < listArenaFile->count; i++) { arenaFile_t *arenaFile; arenaFile = (arenaFile_t *) listArenaFile->list[i]; + if (strcmp(getArenaNetName(arenaFile), s) == 0) return arenaFile; } @@ -264,18 +284,19 @@ arena_t *getArena(arenaFile_t * arenaFile) #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); + #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; @@ -327,15 +348,13 @@ static void loadArenaFromDirector(char *director) line = (char *) (p->list->list[i]); - if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) { + if (strstr(line, ".zip") != NULL && strstr(line, "~")==NULL) { char path[STR_PATH_SIZE]; - if( director[strlen(director)-1] == '/' ) - { + if (director[strlen(director)-1]=='/') { sprintf(path, "%s%s", director, line); } - else - { + else { sprintf(path, "%s/%s", director, line); } #ifdef DEBUG diff --git a/src/base/buffer.c b/src/base/buffer.c index 7140444..dff0f05 100644 --- a/src/base/buffer.c +++ b/src/base/buffer.c @@ -132,5 +132,6 @@ void destroyBuffer(buffer_t * p) if (p->data != NULL) free(p->data); + free(p); } diff --git a/src/base/checkFront.c b/src/base/checkFront.c index 53984fb..571cdd3 100644 --- a/src/base/checkFront.c +++ b/src/base/checkFront.c @@ -24,6 +24,7 @@ static checkfront_t *newCheck(char *s, int type, int id) checkfront_t *new; assert(s != NULL); + new = malloc(sizeof(checkfront_t)); memset(new, 0, sizeof(checkfront_t)); new->msg = strdup(s); @@ -31,6 +32,7 @@ static checkfront_t *newCheck(char *s, int type, int id) new->id = id; new->type = type; new->count = 0; + return new; } @@ -50,6 +52,7 @@ 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)); } @@ -59,32 +62,33 @@ void eventMsgInCheckFront(client_t * client) int i; 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) { + case CHECK_FRONT_TYPE_SIMPLE: 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; + 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; } } } @@ -97,6 +101,7 @@ void delMsgInCheckFront(list_t * listCheckFront, int id) checkfront_t *this; this = (checkfront_t *) listCheckFront->list[i]; + if (this->id == id) { delID(this->id); delListItem(listCheckFront, i, destroyCheck); diff --git a/src/base/director.c b/src/base/director.c index dfcc9cb..49522de 100644 --- a/src/base/director.c +++ b/src/base/director.c @@ -21,24 +21,31 @@ director_t *loadDirector(char *s) 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] == '/') #else 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); @@ -47,13 +54,16 @@ director_t *loadDirector(char *s) while ((item = readdir(dir)) != NULL) addList(new->list, strdup(item->d_name)); + closedir(dir); + return new; } void destroyDirector(director_t * p) { assert(p != NULL); + destroyListItem(p->list, free); free(p->path); free(p); diff --git a/src/base/gun.c b/src/base/gun.c index 408233e..27f88bd 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -25,32 +25,31 @@ # include "publicServer.h" #endif -static void -modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, - int *dest_y) +static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, 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; + 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; } } @@ -62,22 +61,22 @@ static void addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun) 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; + 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); + + shot = newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux->id); addObjectToSpace(getCurrentArena()->spaceShot, shot); } @@ -87,6 +86,7 @@ static void addShot(tux_t * tux, int x, int y, int px, int py) if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) return; + if (tux->gun == GUN_BOMBBALL) gun = GUN_BOMBBALL; else if (tux->gun == GUN_LASSER) @@ -99,6 +99,7 @@ static void addShot(tux_t * tux, int x, int y, int px, int py) int i; zal = tux->position; + for (i = 0; i < 4; i++) { switch (i) { case 0: @@ -114,8 +115,10 @@ static void addShot(tux_t * tux, int x, int y, int px, int py) tux->position = TUX_DOWN; break; } + addShotTrivial(tux, x, y, px, py, gun); } + tux->position = zal; } else { addShotTrivial(tux, x, y, px, py, gun); @@ -149,11 +152,15 @@ static void timer_addShotTimer(void *p) 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); @@ -166,7 +173,7 @@ static void shotInGunTommy(tux_t * tux) for (i = 0; i < 10; i++) addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_addShotTimer, newInt(tux->id), i * 100); + timer_addShotTimer, newInt(tux->id), i * 100); } static void timer_addLaserTimer(void *p) @@ -177,13 +184,18 @@ static void timer_addLaserTimer(void *p) 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); @@ -196,7 +208,7 @@ static void shotInGunLasser(tux_t * tux) for (i = 0; i < 50; i++) addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_addLaserTimer, newInt(tux->id), i * 10); + timer_addLaserTimer, newInt(tux->id), i * 10); } static void putInGunMine(tux_t * tux) @@ -206,32 +218,37 @@ static void putInGunMine(tux_t * tux) 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; + 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)) { + + if (isFreeSpace(getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) { item_t *item; #ifndef NO_SOUND 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); } } @@ -248,41 +265,41 @@ void shotInGun(tux_t * tux) tux->shot[tux->gun]--; switch (tux->gun) { - case GUN_SIMPLE: -#ifndef NO_SOUND - playSound("gun_revolver", SOUND_GROUP_BASE); -#endif - shotInGunSimpe(tux); - break; - case GUN_DUAL_SIMPLE: -#ifndef NO_SOUND - playSound("gun_revolver", SOUND_GROUP_BASE); -#endif - shotInGunDualSimpe(tux); - break; - case GUN_SCATTER: -#ifndef NO_SOUND - playSound("gun_scatter", SOUND_GROUP_BASE); -#endif - shotInGunScatter(tux); - break; - case GUN_TOMMY: -#ifndef NO_SOUND - playSound("gun_tommy", SOUND_GROUP_BASE); -#endif - shotInGunTommy(tux); - break; - case GUN_LASSER: -#ifndef NO_SOUND - playSound("gun_lasser", SOUND_GROUP_BASE); -#endif - shotInGunLasser(tux); - break; - case GUN_BOMBBALL: - shotInGunBombball(tux); - break; - case GUN_MINE: - putInGunMine(tux); - break; + case GUN_SIMPLE: + #ifndef NO_SOUND + playSound("gun_revolver", SOUND_GROUP_BASE); + #endif + shotInGunSimpe(tux); + break; + case GUN_DUAL_SIMPLE: + #ifndef NO_SOUND + playSound("gun_revolver", SOUND_GROUP_BASE); + #endif + shotInGunDualSimpe(tux); + break; + case GUN_SCATTER: + #ifndef NO_SOUND + playSound("gun_scatter", SOUND_GROUP_BASE); + #endif + shotInGunScatter(tux); + break; + case GUN_TOMMY: + #ifndef NO_SOUND + playSound("gun_tommy", SOUND_GROUP_BASE); + #endif + shotInGunTommy(tux); + break; + case GUN_LASSER: + #ifndef NO_SOUND + playSound("gun_lasser", SOUND_GROUP_BASE); + #endif + shotInGunLasser(tux); + break; + case GUN_BOMBBALL: + shotInGunBombball(tux); + break; + case GUN_MINE: + putInGunMine(tux); + break; } } diff --git a/src/base/idManager.c b/src/base/idManager.c index e79534e..7f82282 100644 --- a/src/base/idManager.c +++ b/src/base/idManager.c @@ -108,7 +108,7 @@ void incID(int id) if (index == -1) { assert(!_("This kind of ID was never registered!")); - return; // ha ha ha + return; // ha ha ha } this = listID->list[index]; @@ -130,7 +130,7 @@ void delID(int id) if (index == -1) { assert(!_("This kind of ID was never registered!")); - return; // ha ha ha + return; // ha ha ha } this = listID->list[index]; diff --git a/src/base/item.c b/src/base/item.c index 4239697..822d6b4 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -46,53 +46,21 @@ bool_t isItemInicialized() 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; } @@ -113,44 +81,46 @@ item_t *newItem(int x, int y, int type, int author_id) 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: -#ifndef NO_SOUND - playSound("explozion", SOUND_GROUP_BASE); -#endif - new->w = ITEM_EXPLOSION_WIDTH; - new->h = ITEM_EXPLOSION_HEIGHT; - break; - case ITEM_BIG_EXPLOSION: -#ifndef NO_SOUND - 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; + 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); + #endif + new->w = ITEM_EXPLOSION_WIDTH; + new->h = ITEM_EXPLOSION_HEIGHT; + break; + case ITEM_BIG_EXPLOSION: + #ifndef NO_SOUND + 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; } @@ -187,7 +157,7 @@ void replaceItemID(item_t * item, int id) 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)) { + (item->type >= BONUS_SPEED && item->type <= BONUS_HIDDEN) ) { (*count)++; } } @@ -210,22 +180,19 @@ void addNewItem(space_t * spaceItem, int author_id) int type; #ifdef PUBLIC_SERVER - if (getCountWeaponOrBonusItem(spaceItem) >= - atoi(getSetting("MAX_ITEM", "--max-item", "100"))) { + if (getCountWeaponOrBonusItem(spaceItem) >= atoi(getSetting("MAX_ITEM", "--max-item", "100"))) { return; } #endif #ifndef PUBLIC_SERVER - if (isSettingAnyItem() == FALSE || - getNetTypeGame() == NET_GAME_TYPE_CLIENT) { + if (isSettingAnyItem() == FALSE || getNetTypeGame() == NET_GAME_TYPE_CLIENT) { return; } #endif arena = getCurrentArena(); - findFreeSpace(getCurrentArena(), &new_x, &new_y, ITEM_GUN_WIDTH, - ITEM_GUN_HEIGHT); + findFreeSpace(getCurrentArena(), &new_x, &new_y, ITEM_GUN_WIDTH, ITEM_GUN_HEIGHT); type = GUN_DUAL_SIMPLE; @@ -233,49 +200,50 @@ void addNewItem(space_t * spaceItem, int author_id) 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; + 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)); + (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); @@ -298,6 +266,7 @@ void drawListItem(list_t * listItem) int i; assert(listItem != NULL); + for (i = 0; i < listItem->count; i++) { thisItem = (item_t *) listItem->list[i]; assert(thisItem != NULL); @@ -313,38 +282,40 @@ static void action_itemevent(space_t * space, item_t * item, void *p) 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; + 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; } } @@ -362,12 +333,16 @@ static void mineExplosion(space_t * spaceItem, item_t * item) 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); } @@ -377,15 +352,16 @@ 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; + case ITEM_MINE: + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + mineExplosion(space, item); + break; + case ITEM_EXPLOSION: + case ITEM_BIG_EXPLOSION: + *isDel = 1; + break; } } @@ -393,11 +369,13 @@ 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); + 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); } } @@ -406,6 +384,7 @@ void eventConflictShotWithItem(arena_t * arena) { if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) return; + actionSpace(arena->spaceShot, action_shot, arena->spaceItem); } @@ -413,27 +392,32 @@ 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); + 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); } @@ -476,44 +460,48 @@ static void tuxGiveGun(tux_t * tux, item_t * item) 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); -#ifdef PUBLIC_SERVER - 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); -#ifdef PUBLIC_SERVER - addNewItem(space, ID_UNKNOWN); -#endif - break; + 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); + #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); + #ifdef PUBLIC_SERVER + addNewItem(space, ID_UNKNOWN); + #endif + break; } } diff --git a/src/base/list.c b/src/base/list.c index d98b8d0..dc22a0b 100644 --- a/src/base/list.c +++ b/src/base/list.c @@ -13,6 +13,7 @@ list_t *newList() new = malloc(sizeof(list_t)); memset(new, 0, sizeof(list_t)); + return new; } @@ -23,6 +24,7 @@ list_t *cloneList(list_t * p) 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 *)); @@ -40,8 +42,10 @@ list_t *cloneListItem(list_t * p, void *f) assert(f != NULL); new = cloneList(p); fce = f; + for (i = 0; i < p->count; i++) new->list[i] = fce(p->list[i]); + return new; } @@ -85,8 +89,7 @@ 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 *)); + memmove(p->list + n + 1, p->list + n, ((p->count - 1) - n) * sizeof(void *)); p->list[n] = item; } @@ -102,9 +105,11 @@ int searchListItem(list_t * p, void *n) int i; assert(p != NULL); + for (i = 0; i < p->count; i++) if (p->list[i] == n) return i; + return -1; } @@ -112,9 +117,10 @@ 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 *)); + + 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; @@ -137,8 +143,10 @@ void delListItem(list_t * p, int n, void *f) assert(p != NULL); assert(n >= 0 || n < p->count); fce = f; + if (fce != NULL) fce(p->list[n]); + delList(p, n); } @@ -153,6 +161,7 @@ void destroyList(list_t * p) if (p->list != NULL) free(p->list); + free(p); } @@ -163,8 +172,11 @@ void destroyListItem(list_t * p, void *f) 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/main.c b/src/base/main.c index 6d36cd7..fce5a9f 100644 --- a/src/base/main.c +++ b/src/base/main.c @@ -84,8 +84,10 @@ char *getString(int n) int *newInt(int x) { int *new; + new = malloc(sizeof(int)); *new = x; + return new; } @@ -110,9 +112,9 @@ int isFillPath(const char *path) 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; diff --git a/src/base/modules.c b/src/base/modules.c index 149a92f..82b5d56 100644 --- a/src/base/modules.c +++ b/src/base/modules.c @@ -66,15 +66,14 @@ static void *getFce(module_t * p, char *s) ret = dlsym(p->image, s); if ((error = dlerror()) != NULL) { - fprintf(stderr, _("Error %s occured when using getFce function!\n"), - error); + 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); + if (!ret) { + fprintf(stderr, _("Error %s occured when using getFce function!\n"), s); + } #endif return (void *) ret; } @@ -84,6 +83,7 @@ static void *mapImage(char *name) #ifndef __WIN32__ void *image; image = dlopen(name, RTLD_LAZY); + if (image == NULL) { fputs(dlerror(), stderr); return NULL; @@ -140,10 +140,12 @@ static module_t *newModule(char *name) 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); @@ -166,6 +168,7 @@ static module_t *newModule(char *name) free(ret); return NULL; } + return ret; } @@ -196,6 +199,7 @@ int isModuleLoaded(char *name) module_t *this; this = (module_t *) listModule->list[i]; + if (strcmp(this->name, name) == 0) return 1; } @@ -207,17 +211,17 @@ 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); + 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; } @@ -226,6 +230,7 @@ int loadDepModule(char *name) { if (isModuleLoaded(name)) return 0; + return loadModule(name); } @@ -235,6 +240,7 @@ void cmdModule(char *s) for (i = 0; i < listModule->count; i++) { module_t *this; + this = (module_t *) listModule->list[i]; this->fce_cmd(s); } @@ -247,6 +253,7 @@ void drawModule(int x, int y, int w, int h) for (i = 0; i < listModule->count; i++) { module_t *this; + this = (module_t *) listModule->list[i]; this->fce_draw(x, y, w, h); } @@ -259,6 +266,7 @@ void eventModule() for (i = 0; i < listModule->count; i++) { module_t *this; + this = (module_t *) listModule->list[i]; this->fce_event(); } @@ -272,6 +280,7 @@ int isConflictModule(int x, int y, int w, int h) module_t *this; this = (module_t *) listModule->list[i]; + if (this->fce_isConflict(x, y, w, h) == 1) return 1; } diff --git a/src/base/myTimer.c b/src/base/myTimer.c index 08abb99..90d5731 100644 --- a/src/base/myTimer.c +++ b/src/base/myTimer.c @@ -36,11 +36,11 @@ my_time_t getMyTime() 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; + ticks = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; //printf("-> %d\n", ticks); + return ticks; } @@ -49,22 +49,25 @@ 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); + 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_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++; @@ -73,6 +76,7 @@ my_timer_t *newTimerItem(int type, void (*fce) (void *p), void *arg, new->arg = arg; new->createTime = getMyTime(); new->time = my_time; + return new; } @@ -82,14 +86,13 @@ static void destroyTimerItem(my_timer_t * p) free(p); } -int -addTaskToTimer(list_t * listTimer, int type, void (*fce) (void *p), void *arg, - my_time_t my_time) +int addTaskToTimer(list_t * listTimer, int type, void (*fce) (void *p), void *arg, my_time_t my_time) { my_timer_t *new; new = newTimerItem(type, fce, arg, my_time); addList(listTimer, new); + return new->id; } @@ -98,27 +101,30 @@ 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; + 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; } } } @@ -130,7 +136,9 @@ void delTimer(list_t * listTimer, int id) 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; diff --git a/src/base/protect.c b/src/base/protect.c index e06c618..9661e32 100644 --- a/src/base/protect.c +++ b/src/base/protect.c @@ -11,12 +11,14 @@ 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; } @@ -27,9 +29,11 @@ void refreshLastMove(protect_t * p) currentTime = getMyTime(); interval = currentTime - p->lastMove; + p->lastMove = getMyTime(); p->avarage += interval; p->count++; + if (p->count == PROTECT_SPEED_AVARAGE) { int index; @@ -62,8 +66,10 @@ bool_t isDown(protect_t * p) currentTime = getMyTime(); interval = currentTime - p->lastPing; + if (interval > PROTECT_PING_INTERVAL_TIMEOUT) p->isDown = TRUE; + return p->isDown; } diff --git a/src/base/proto.c b/src/base/proto.c index f14a29a..de098ab 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -44,8 +44,7 @@ void proto_send_error_server(int type, client_t * client, int 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 @@ -63,24 +62,24 @@ void proto_recv_error_client(char *msg) if (recv_count != 2) { return; } -# ifdef DEBUG + +#ifdef DEBUG printf(_("Proto error code: \"%d\"\n"), errorcode); -# endif +#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; + 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; } } @@ -93,7 +92,7 @@ void proto_send_hello_client(char *name) char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", - getParamElse("--version", TUXANCI_VERSION), name); + getParamElse("--version", TUXANCI_VERSION), name); printf("-> %s", msg); sendServer(msg); @@ -120,8 +119,7 @@ static void sendInfoCreateClient(client_t * client) proto_send_init_server(PROTO_SEND_ONE, client, client); #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, client, - 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++) { @@ -155,8 +153,7 @@ void proto_recv_hello_server(client_t * client, char *msg) assert(client != NULL); if (getSpaceCount(getCurrentArena()->spaceTux) + 1 > getServerMaxClients()) { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_LIMIT_MAX_CLIENT); + proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_LIMIT_MAX_CLIENT); eventMsgInCheckFront(client); client->status = NET_STATUS_ZOMBIE; return; @@ -167,9 +164,7 @@ void proto_recv_hello_server(client_t * client, char *msg) #ifdef PUBLIC_SERVER if (supportVersion == NULL) { - supportVersion = - getSetting("SUPPORT_CLIENTS", "--support-clients", - TUXANCI_VERSION); + supportVersion = getSetting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); } #endif @@ -186,8 +181,7 @@ void proto_recv_hello_server(client_t * client, char *msg) } if (strstr(supportVersion, version) == NULL) { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_CODE_BAD_VERSION); + proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION); eventMsgInCheckFront(client); client->status = NET_STATUS_ZOMBIE; return; @@ -232,15 +226,14 @@ void proto_send_status_server(int type, client_t * client) 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); + "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); } @@ -272,8 +265,7 @@ void proto_send_listscore_server(int type, client_t * client, int max) } //proto_send(type, client, 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); free(msg); } @@ -342,8 +334,8 @@ void proto_send_init_server(int type, client_t * client, client_t * client2) 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); + 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); @@ -365,7 +357,7 @@ void proto_recv_init_client(char *msg) assert(msg != NULL); recv_count = sscanf(msg, "%s %d %d %d %d %s %d", - cmd, &id, &x, &y, &n, arena_name, &check_id); + cmd, &id, &x, &y, &n, arena_name, &check_id); if (recv_count != 7) { return; @@ -404,8 +396,7 @@ proto_send_event_server(int type, client_t * client, tux_t * tux, int 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); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER @@ -466,8 +457,7 @@ void proto_recv_event_server(client_t * client, char *msg) } if (client->tux->bonus != BONUS_HIDDEN) { - proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, - action); + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action); } refreshLastMove(client->protect); @@ -489,8 +479,7 @@ void proto_send_newtux_server(int type, client_t * client, tux_t * tux) 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", + 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], @@ -523,8 +512,7 @@ void proto_recv_newtux_client(char *msg) } recv_count = - sscanf(msg, - "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + 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); @@ -547,7 +535,7 @@ void proto_recv_newtux_client(char *msg) } if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT && - x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) { + x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) { getTuxProportion(tux, &x, &y, NULL, NULL); } @@ -587,8 +575,7 @@ void proto_send_kill_server(int type, client_t * client, tux_t * tux) 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); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER @@ -655,8 +642,7 @@ void proto_recv_del_client(char *msg) if (tux != NULL) { delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, - destroyTux); + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, destroyTux); return; } @@ -665,8 +651,7 @@ void proto_recv_del_client(char *msg) if (shot != NULL) { //printf("delete shot..\n"); delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, - destroyShot); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); return; } @@ -675,8 +660,7 @@ void proto_recv_del_client(char *msg) if (item != NULL) { //printf("delete item..\n"); delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, - destroyItem); + delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, destroyItem); return; } } @@ -693,8 +677,7 @@ void proto_send_additem_server(int type, client_t * client, item_t * p) 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); + 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); @@ -717,8 +700,7 @@ void proto_recv_additem_client(char *msg) } recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", - cmd, &id, &type, &x, &y, &count, &frame, &author_id, - &check_id); + cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id); if (recv_count != 9) { return; @@ -731,8 +713,8 @@ void proto_recv_additem_client(char *msg) return; } - if (type != ITEM_MINE && type != ITEM_EXPLOSION - && type != ITEM_BIG_EXPLOSION) { + if (type != ITEM_MINE && type != ITEM_EXPLOSION && + type != ITEM_BIG_EXPLOSION) { addToRadar(id, x, y, RADAR_TYPE_ITEM); } @@ -754,13 +736,12 @@ void proto_send_shot_server(int type, client_t * client, shot_t * p) 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); + 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); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER @@ -775,19 +756,15 @@ void proto_recv_shot_client(char *msg) 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); + cmd, &shot_id, &x, &y, &px, &py, &position, &gun, + &author_id, &isCanKillAuthor); 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; } @@ -836,8 +813,7 @@ void proto_recv_chat_server(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); @@ -893,8 +869,7 @@ void proto_send_module_server(int type, client_t * client, char *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 @@ -926,8 +901,7 @@ 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); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER @@ -949,8 +923,7 @@ void proto_send_echo_server(int type, client_t * client, char *s) 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); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } void proto_send_end_server(int type, client_t * client) @@ -959,8 +932,7 @@ void proto_send_end_server(int type, client_t * client) snprintf(msg, STR_PROTO_SIZE, "end\n"); //proto_send(type, client, 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 diff --git a/src/base/server.c b/src/base/server.c index 282d135..2112927 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -86,8 +86,7 @@ static proto_cmd_server_t *findCmdProto(client_t * client, char *msg) thisCmd = &proto_cmd_list[i]; - if (len >= thisCmd->len - && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { + if (len >= thisCmd->len && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { if (thisCmd->tux && client->tux == NULL) { return NULL; } @@ -140,8 +139,7 @@ void destroyAnyClient(client_t * p) #ifdef PUBLIC_SERVER addPlayerInHighScore(p->tux->name, p->tux->score); #endif - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, - destroyTux); + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, destroyTux); } free(p); @@ -177,8 +175,7 @@ static void delZombieCLient(void *p_nothink) if (thisClient->status == NET_STATUS_ZOMBIE) { if (thisClient->tux != NULL) { - proto_send_del_server(PROTO_SEND_ALL, NULL, - thisClient->tux->id); + proto_send_del_server(PROTO_SEND_ALL, NULL, thisClient->tux->id); } eventDelClientFromListClient(thisClient); @@ -194,8 +191,7 @@ static void eventPeriodicSyncClient(void *p_nothink) 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++) { @@ -205,6 +201,7 @@ static void eventPeriodicSyncClient(void *p_nothink) if (thisTux == NULL) { continue; } + //proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux); proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux); } @@ -224,12 +221,9 @@ void setServerTimer() 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); + 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) @@ -276,14 +270,13 @@ void sendClient(client_t * p, char *msg) assert(msg != NULL); if (p->status != NET_STATUS_ZOMBIE) { - int ret = -1; // no Warnnings + int ret = -1; // no Warnnings #ifndef PUBLIC_SERVER if (isParamFlag("--send")) { printf(_("Sending: \"%s\""), msg); } #endif - ret = writeUdpSocket(p->socket_udp, p->socket_udp, msg, strlen(msg)); if (ret <= 0) { @@ -316,8 +309,7 @@ static void eventClientWorkRecvList(client_t * client) protoCmd->fce_proto(client, line); rereshLastPing(client->protect); } else { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_CODE_BAD_COMMAND); + proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_COMMAND); } } diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c index afe258d..e7d1c09 100644 --- a/src/base/serverSendMsg.c +++ b/src/base/serverSendMsg.c @@ -71,10 +71,13 @@ static void addMsgAllClientSeesTux(char *msg, tux_t * tux, int type, int id) 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); @@ -108,34 +111,32 @@ 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: -#ifndef PUBLIC_SERVER - if (client != NULL) { + 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); + } + #endif + #ifdef PUBLIC_SERVER 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); -#endif - break; - default: - assert(!_("Type variable has a really wierd value!")); - break; + #endif + break; + default: + assert(!_("Type variable has a really wierd value!")); + break; } } diff --git a/src/base/shareFunction.c b/src/base/shareFunction.c index e6e912a..f3a83d5 100644 --- a/src/base/shareFunction.c +++ b/src/base/shareFunction.c @@ -52,6 +52,7 @@ void *getShareFce(char *name) share_fce_item_t *this; this = (share_fce_item_t *) listShareFce->list[i]; + if (strcmp(this->name, name) == 0) return this->function; } diff --git a/src/base/shot.c b/src/base/shot.c index a233712..977ccb4 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -44,18 +44,10 @@ void initShot() #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 @@ -90,47 +82,47 @@ shot_t *newShot(int x, int y, int px, int py, int gun, int author_id) new->del = FALSE; switch (gun) { - case GUN_SIMPLE: - new->w = GUN_SHOT_WIDTH; - new->h = GUN_SHOT_HEIGHT; -#ifndef PUBLIC_SERVER - 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; -#ifndef PUBLIC_SERVER - new->img = g_shot_lasserX; -#endif + case GUN_SIMPLE: + new->w = GUN_SHOT_WIDTH; + new->h = GUN_SHOT_HEIGHT; + #ifndef PUBLIC_SERVER + new->img = g_shot_simple; + #endif 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; -#endif + + 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; + #endif + 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; + #endif + break; + } + break; + + case GUN_BOMBBALL: + new->w = GUN_BOMBBALL_WIDTH; + new->h = GUN_BOMBBALL_HEIGHT; + + #ifndef PUBLIC_SERVER + new->img = g_shot_bombball; + #endif + break; + + default: + assert(!_("Type variable has a really wierd value!")); break; - } - break; - - case GUN_BOMBBALL: - new->w = GUN_BOMBBALL_WIDTH; - new->h = GUN_BOMBBALL_HEIGHT; - -#ifndef PUBLIC_SERVER - new->img = g_shot_bombball; -#endif - break; - - default: - assert(!_("Type variable has a really wierd value!")); - break; } return new; @@ -192,19 +184,19 @@ void drawListShot(list_t * listShot) static int getRandomCourse(int x, int y) { - int ret = -1; // no warnning + int ret = -1; // no warnning do { switch (random() % 3) { - case 0: - ret = y; - break; - case 1: - ret = -y; - break; - case 2: - ret = 0; - break; + case 0: + ret = y; + break; + case 1: + ret = -y; + break; + case 2: + ret = 0; + break; } } while (ret == x); @@ -242,22 +234,22 @@ void transformOnlyLasser(shot_t * shot) } switch (shot->position) { - case TUX_RIGHT: - case TUX_LEFT: - shot->w = GUN_LASSER_HORIZONTAL; - shot->h = GUN_SHOT_VERTICAL; -#ifndef PUBLIC_SERVER - shot->img = g_shot_lasserX; -#endif - break; - case TUX_UP: - case TUX_DOWN: - shot->w = GUN_SHOT_VERTICAL; - shot->h = GUN_LASSER_HORIZONTAL; -#ifndef PUBLIC_SERVER - shot->img = g_shot_lasserY; -#endif - break; + case TUX_RIGHT: + case TUX_LEFT: + shot->w = GUN_LASSER_HORIZONTAL; + shot->h = GUN_SHOT_VERTICAL; + #ifndef PUBLIC_SERVER + shot->img = g_shot_lasserX; + #endif + break; + case TUX_UP: + case TUX_DOWN: + shot->w = GUN_SHOT_VERTICAL; + shot->h = GUN_LASSER_HORIZONTAL; + #ifndef PUBLIC_SERVER + shot->img = g_shot_lasserY; + #endif + break; } if (mustRefesh) { @@ -278,7 +270,7 @@ static void action_moveShot(space_t * space, shot_t * shot, void *p) 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) { + shot->y + shot->h < 0 || shot->y > arena->h) { delObjectFromSpaceWithObject(space, shot, destroyShot); } } @@ -304,8 +296,8 @@ static int isValueInList(list_t * list, int x) 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); + addList(client->listSeesShot, newInt(shot->id)); + proto_send_shot_server(PROTO_SEND_ONE, client, shot); } } @@ -333,11 +325,11 @@ void checkShotIsInTuxScreen(arena_t * arena) } getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y, - WINDOW_SIZE_X, WINDOW_SIZE_Y); + WINDOW_SIZE_X, WINDOW_SIZE_Y); actionSpaceFromLocation(arena->spaceShot, action_check, - thisClient, screen_x, screen_y, WINDOW_SIZE_X, - WINDOW_SIZE_Y); + thisClient, screen_x, screen_y, + WINDOW_SIZE_X, WINDOW_SIZE_Y); while (thisClient->listSeesShot->count > 100) { delListItem(thisClient->listSeesShot, 0, free); diff --git a/src/base/space.c b/src/base/space.c index 0988011..2250e37 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -27,18 +27,15 @@ void destroyZone(zone_t * p) free(p); } -static int -my_conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, int w2, +static int my_conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); } space_t *newSpace(int w, int h, int segW, int segH, - void (*getStatus) (void *p, int *id, int *x, int *y, int *w, - int *h), void (*setStatus) (void *p, - int x, int y, - int w, int h)) + 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; @@ -69,9 +66,8 @@ space_t *newSpace(int w, int h, int segW, int segH, return new; } -static void -getSegment(space_t * p, int x, int y, int w, int h, - int *segX, int *segY, int *segW, int *segH) +static void getSegment(space_t * p, int x, int y, int w, int h, + int *segX, int *segY, int *segW, int *segH) { *segX = x / p->segW; *segY = y / p->segH; @@ -134,9 +130,8 @@ void getObjectFromSpace(space_t * p, int x, int y, int w, int h, list_t * list) 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) { + if (my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) && + searchListItem(list, this) == -1) { addList(list, this); } } @@ -169,8 +164,7 @@ int isConflictWithObjectFromSpace(space_t * p, int x, int y, int w, int h) 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)) { + if (my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h)) { return 1; } } @@ -180,9 +174,7 @@ int isConflictWithObjectFromSpace(space_t * p, int x, int y, int w, int h) return 0; } -int -isConflictWithObjectFromSpaceBut(space_t * p, int x, int y, int w, int h, - void *but) +int isConflictWithObjectFromSpaceBut(space_t * p, int x, int y, int w, int h, void *but) { int segX, segY, segW, segH; int id, this_x, this_y, this_w, this_h; @@ -207,8 +199,7 @@ isConflictWithObjectFromSpaceBut(space_t * p, int x, int y, int w, int 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)) { + if (my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h)) { return 1; } } @@ -261,15 +252,14 @@ void moveObjectInSpace(space_t * p, void *item, int move_x, int move_y) 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); + 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) { + old_segW != new_segW || old_segH != new_segH) { delObjectFromSpace(p, item); p->setStatus(item, move_x, move_y, w, h); addObjectToSpace(p, item); @@ -313,9 +303,7 @@ void actionSpace(space_t * space, void *f, void *p) } } -void -actionSpaceFromLocation(space_t * space, void *f, void *p, int x, int y, - int w, int h) +void actionSpaceFromLocation(space_t * space, void *f, void *p, int x, int y, int w, int h) { void (*fce) (space_t * space, void *f, void *p); list_t *list; diff --git a/src/base/storage.c b/src/base/storage.c index 1ae5f5a..8307cdf 100644 --- a/src/base/storage.c +++ b/src/base/storage.c @@ -29,6 +29,7 @@ static storage_item_t *newStorageItem(char *group, char *name, void *data) new->name = strdup(name); new->group = strdup(group); new->data = data; + return new; } @@ -38,6 +39,7 @@ static void destroyStorageItem(storage_item_t * p, void *f) assert(p != NULL); assert(f != NULL); + fce = f; fce(p->data); free(p->name); @@ -50,6 +52,7 @@ 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)); } @@ -61,11 +64,14 @@ void *getItemFromStorage(list_t * list, char *group, char *name) 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); #endif @@ -80,14 +86,17 @@ void delItemFromStorage(list_t * list, char *group, char *name, void *f) 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; } @@ -101,6 +110,7 @@ void delAllItemFromStorage(list_t * list, char *group, void *f) 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); @@ -116,9 +126,12 @@ void destroyStorage(list_t * p, void *f) 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/textFile.c b/src/base/textFile.c index 776b1cc..222af97 100644 --- a/src/base/textFile.c +++ b/src/base/textFile.c @@ -13,6 +13,7 @@ textFile_t *newTextFile(char *s) { textFile_t *new; char path[STR_PATH_SIZE]; + assert(s != NULL); if (isFillPath(s)) { @@ -45,6 +46,7 @@ static void createLine(list_t * list, char *p, int len) do { end_line = memchr(begin_line, '\n', len); + if (end_line == NULL) break; @@ -126,9 +128,11 @@ void saveTextFile(textFile_t * p) { 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]); } diff --git a/src/base/tux.c b/src/base/tux.c index 7fe9a68..171046c 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -60,16 +60,11 @@ void initTux() #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_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; } @@ -134,29 +129,29 @@ void getCourse(int n, int *x, int *y) assert(y != NULL); switch (n) { - case TUX_UP: - *x = 0; - *y = -1; - break; - - case TUX_LEFT: - *x = -1; - *y = 0; - break; - - case TUX_RIGHT: - *x = +1; - *y = 0; - break; - - case TUX_DOWN: - *x = 0; - *y = +1; - break; - - default: - assert(!_("Type variable has a really wierd value!")); - break; + case TUX_UP: + *x = 0; + *y = -1; + break; + + case TUX_LEFT: + *x = -1; + *y = 0; + break; + + case TUX_RIGHT: + *x = +1; + *y = 0; + break; + + case TUX_DOWN: + *x = 0; + *y = +1; + break; + + default: + assert(!_("Type variable has a really wierd value!")); + break; } } @@ -169,38 +164,37 @@ void drawTux(tux_t * tux) assert(tux != NULL); if (tux->bonus == BONUS_HIDDEN && - getNetTypeGame() != NET_GAME_TYPE_NONE && - tux->control == TUX_CONTROL_NET) { + getNetTypeGame() != NET_GAME_TYPE_NONE && + tux->control == TUX_CONTROL_NET) { return; } switch (tux->position) { - case TUX_UP: - g_image = g_tux_up; - break; - - case TUX_LEFT: - g_image = g_tux_left; - break; - - case TUX_RIGHT: - g_image = g_tux_right; - break; - - case TUX_DOWN: - g_image = g_tux_down; - break; - - default: - assert(!_("p->control has a really wierd value!")); - break; + case TUX_UP: + g_image = g_tux_up; + break; + + case TUX_LEFT: + g_image = g_tux_left; + break; + + case TUX_RIGHT: + g_image = g_tux_right; + break; + + case TUX_DOWN: + g_image = g_tux_down; + break; + + default: + assert(!_("p->control has a really wierd value!")); + break; } if (tux->status == TUX_STATUS_DEAD) { g_image = g_cross; - addLayer(g_cross, - tux->x - g_cross->w / 2, + 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); @@ -216,8 +210,7 @@ void drawTux(tux_t * tux) tux->g_name->w, tux->g_name->h, TUX_LAYER); } */ - addLayer(g_image, - tux->x - TUX_IMG_WIDTH / 2, + 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); @@ -312,6 +305,7 @@ void eventTuxIsDead(tux_t * tux) if (tux->status == TUX_STATUS_DEAD) { return; } + #ifndef NO_SOUND playSound("dead", SOUND_GROUP_BASE); #endif @@ -330,7 +324,7 @@ void eventTuxIsDead(tux_t * tux) if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN); + timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN); } if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { @@ -351,9 +345,7 @@ static void eventTuxIsDeadWIthShot(tux_t * tux, shot_t * shot) 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++; @@ -405,8 +397,7 @@ static void bombBallExplosion(shot_t * shot) 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) @@ -443,8 +434,7 @@ static void action_tux(space_t * space, tux_t * tux, shot_t * shot) 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) @@ -454,7 +444,7 @@ void eventConflictTuxWithShot(arena_t * arena) void moveTux(tux_t * tux, int n) { - int px = 0, py = 0; // no warninng + int px = 0, py = 0; // no warninng int zal_x, zal_y; int new_x, new_y; int w, h; @@ -471,9 +461,9 @@ void moveTux(tux_t * tux, int n) } 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)) { + (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; } @@ -492,11 +482,9 @@ void moveTux(tux_t * tux, int n) 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))) { + 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; } @@ -505,6 +493,7 @@ void moveTux(tux_t * tux, int n) 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; } @@ -522,8 +511,8 @@ void switchTuxGun(tux_t * tux) tux->gun = i; tux->isCanSwitchGun = FALSE; addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, - timer_tuxCanSwitchGun, newInt(tux->id), - TUX_TIME_CAN_SWITCH_GUN); + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND playSound("switch_gun", SOUND_GROUP_BASE); #endif @@ -535,14 +524,14 @@ void switchTuxGun(tux_t * tux) 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); + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND playSound("switch_gun", SOUND_GROUP_BASE); #endif - return; } } @@ -555,6 +544,7 @@ void shotTux(tux_t * tux) if (tux->isCanShot == FALSE || tux->shot[tux->gun] == 0) { return; } + #ifndef NO_SOUND playSound("switch_gun", SOUND_GROUP_BASE); #endif @@ -564,7 +554,7 @@ void shotTux(tux_t * tux) tux->isCanShot = FALSE; addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanShot, - newInt(tux->id), TUX_TIME_CAN_SHOT); + newInt(tux->id), TUX_TIME_CAN_SHOT); if (tux->shot[tux->gun] == 0) { switchTuxGun(tux); @@ -578,20 +568,20 @@ void actionTux(tux_t * tux, int action) } 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; + 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; } } @@ -604,8 +594,7 @@ static void pickUpGun(tux_t * tux) 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); #endif @@ -635,8 +624,8 @@ static void eventBonus(tux_t * tux) tux->bonus = BONUS_NONE; - if ( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ - isConflictModule(x, y, w, h)) { + if ( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ + isConflictModule(x, y, w, h)) { tux->bonus = BONUS_GHOST; return; } @@ -687,10 +676,13 @@ void getTuxProportion(tux_t * tux, int *x, int *y, int *w, int *h) 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; } diff --git a/src/base/udp_server.c b/src/base/udp_server.c index 1b3e9b6..c2d6486 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -61,8 +61,7 @@ client_t *newUdpClient(sock_udp_t * sock_udp) 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)); + sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, getSockUdpPort(sock_udp)); addToLog(LOG_INF, str_log); #endif @@ -78,8 +77,7 @@ void destroyUdpClient(client_t * p) 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)); + sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, getSockUdpPort(p->socket_udp)); addToLog(LOG_INF, str_log); #endif @@ -104,8 +102,7 @@ int initUdpServer(char *ip4, int port4, char *ip6, int port6) #endif } 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 } } @@ -120,8 +117,7 @@ int initUdpServer(char *ip4, int port4, char *ip6, int port6) #endif } 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 } } @@ -157,7 +153,7 @@ static client_t *findUdpClient(sock_udp_t * sock_udp) client = (client_t *) listClient->list[i]; if (client->type == CLIENT_TYPE_UDP && - getSockUdpPort(client->socket_udp) == port) { + getSockUdpPort(client->socket_udp) == port) { return client; } } @@ -203,6 +199,7 @@ static void eventClientUdpSelect(sock_udp_t * sock_server) client->status = NET_STATUS_ZOMBIE; return; } + //printf("add packet >>%s<<\n", listRecvMsg); addList(client->listRecvMsg, strdup(listRecvMsg)); } @@ -252,8 +249,7 @@ void quitUdpServer() 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); } |