summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/archive.c77
-rw-r--r--src/base/archive.h2
-rw-r--r--src/base/arena.c565
-rw-r--r--src/base/arena.h57
-rw-r--r--src/base/arenaFile.c440
-rw-r--r--src/base/arenaFile.h23
-rw-r--r--src/base/bool.h10
-rw-r--r--src/base/buffer.c177
-rw-r--r--src/base/buffer.h13
-rw-r--r--src/base/checkFront.c153
-rw-r--r--src/base/checkFront.h16
-rw-r--r--src/base/director.c77
-rw-r--r--src/base/director.h13
-rw-r--r--src/base/gun.c417
-rw-r--r--src/base/gun.h18
-rw-r--r--src/base/homeDirector.c40
-rw-r--r--src/base/homeDirector.h6
-rw-r--r--src/base/idManager.c223
-rw-r--r--src/base/idManager.h14
-rw-r--r--src/base/index.c322
-rw-r--r--src/base/index.h13
-rw-r--r--src/base/item.c813
-rw-r--r--src/base/item.h85
-rw-r--r--src/base/list.c248
-rw-r--r--src/base/list.h15
-rw-r--r--src/base/main.c173
-rw-r--r--src/base/main.h30
-rw-r--r--src/base/modules.c394
-rw-r--r--src/base/modules.h143
-rw-r--r--src/base/myTimer.c196
-rw-r--r--src/base/myTimer.h29
-rw-r--r--src/base/net_multiplayer.c169
-rw-r--r--src/base/net_multiplayer.h42
-rw-r--r--src/base/protect.c95
-rw-r--r--src/base/protect.h25
-rw-r--r--src/base/proto.c1231
-rw-r--r--src/base/proto.h78
-rw-r--r--src/base/server.c458
-rw-r--r--src/base/server.h59
-rw-r--r--src/base/serverSelect.c103
-rw-r--r--src/base/serverSelect.h2
-rw-r--r--src/base/serverSendMsg.c184
-rw-r--r--src/base/serverSendMsg.h14
-rw-r--r--src/base/shareFunction.c63
-rw-r--r--src/base/shareFunction.h2
-rw-r--r--src/base/shot.c454
-rw-r--r--src/base/shot.h61
-rw-r--r--src/base/space.c494
-rw-r--r--src/base/space.h49
-rw-r--r--src/base/storage.c185
-rw-r--r--src/base/storage.h10
-rw-r--r--src/base/string_length.h20
-rw-r--r--src/base/tcp_server.c363
-rw-r--r--src/base/tcp_server.h8
-rw-r--r--src/base/textFile.c181
-rw-r--r--src/base/textFile.h17
-rw-r--r--src/base/tux.c911
-rw-r--r--src/base/tux.h151
-rw-r--r--src/base/udp_server.c298
-rw-r--r--src/base/udp_server.h6
60 files changed, 5056 insertions, 5479 deletions
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);