summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/arenaFile.c125
-rw-r--r--src/base/arenaFile.h35
-rw-r--r--src/base/bool.h14
-rw-r--r--src/base/checkFront.c52
-rw-r--r--src/base/checkFront.h29
-rwxr-xr-xsrc/base/director.c23
-rw-r--r--src/base/director.h28
-rw-r--r--src/base/gun.c172
-rw-r--r--src/base/gun.h30
-rwxr-xr-xsrc/base/homeDirector.c19
-rwxr-xr-xsrc/base/homeDirector.h13
-rw-r--r--src/base/idManager.h37
-rw-r--r--src/base/item.c281
-rw-r--r--src/base/item.h146
-rwxr-xr-xsrc/base/list.c142
-rwxr-xr-xsrc/base/list.h54
-rw-r--r--src/base/main.c7
-rw-r--r--src/base/main.h42
-rwxr-xr-xsrc/base/modules.c117
-rw-r--r--src/base/myTimer.c104
-rw-r--r--src/base/myTimer.h54
-rw-r--r--src/base/path.h75
-rw-r--r--src/base/protect.c18
-rw-r--r--src/base/protect.h49
-rw-r--r--src/base/proto.c30
-rw-r--r--src/base/shot.h112
-rw-r--r--src/base/storage.c79
-rw-r--r--src/base/storage.h20
28 files changed, 715 insertions, 1192 deletions
diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c
index 3375843..b89e1c3 100644
--- a/src/base/arenaFile.c
+++ b/src/base/arenaFile.c
@@ -19,12 +19,12 @@
#include "configFile.h"
#include "image.h"
#endif
+
#ifndef NO_SOUND
#include "music.h"
#endif
static list_t *listArenaFile;
-
static bool_t isArenaFileInit = FALSE;
bool_t isAreaFileInicialized()
@@ -42,22 +42,20 @@ int getArenaValue(char *line, char *env, char *val, int len)
strcpy(clone_env, " ");
strcat(clone_env, env);
-
offset_env = strstr(line, clone_env);
- if( offset_env == NULL )return -1;
-
+ if (offset_env == NULL)
+ return -1;
offset_val_begin = strchr(offset_env, '"');
- if( offset_val_begin == NULL )return -1;
-
+ 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;
-
+ 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;
}
@@ -68,10 +66,12 @@ static void cmd_arena(arena_t **arena, char *line)
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;
-
+ 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);
@@ -79,15 +79,17 @@ static void cmd_arena(arena_t **arena, char *line)
//(*arena)->w = atoi(str_w);
//(*arena)->h = atoi(str_h);
setCurrentArena(*arena);
- printf("new arena\n");
+#ifndef DEBUG
+ printf(_("Loaded new arena...\n"));
+#endif
}
static void cmd_loadModule(char *line)
{
char str_file[STR_SIZE];
- if( getArenaValue(line, "file", str_file, STR_SIZE) != 0 )return;
-
+ if (getArenaValue(line, "file", str_file, STR_SIZE) != 0)
+ return;
loadModule(str_file);
}
@@ -99,10 +101,12 @@ static void cmd_loadImage(char *line)
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;
-
+ 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;
addImageData(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER);
}
@@ -111,9 +115,10 @@ static void cmd_loadMusic(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;
-
+ 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);
#endif
@@ -123,11 +128,10 @@ static void cmd_playMusic(arena_t *arena, char *line)
{
char str_music[STR_SIZE];
- if( getArenaValue(line, "music", str_music, STR_SIZE) != 0 )return;
-
+ if (getArenaValue(line, "music", str_music, STR_SIZE) != 0)
+ return;
strcpy(arena->music, str_music);
}
-
#endif
int getArenaCount()
@@ -143,18 +147,12 @@ static char *getArenaStatus(int id, char *s)
ts = (textFile_t *) listArenaFile->list[id];
len = strlen(s);
-
- for( i = 0 ; i < ts->text->count ; i++ )
- {
+ 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;
}
@@ -163,7 +161,6 @@ char *getArenaName(int id)
char *ret;
ret = getArenaStatus(id, "name");
-
return ( ret != NULL ? ret : "arena_no_name" );
}
@@ -172,7 +169,6 @@ char *getArenaNetName(int id)
char *ret;
ret = getArenaStatus(id, "netName");
-
return ( ret != NULL ? ret : "arena_no_net_name" );
}
@@ -180,14 +176,9 @@ int getArenaIdFormNetName(char *s)
{
int i;
- for( i = 0 ; i < listArenaFile->count ; i++ )
- {
- if( strcmp(getArenaNetName(i), s) == 0 )
- {
+ for (i = 0; i < listArenaFile->count; i++)
+ if (strcmp(getArenaNetName(i), s) == 0)
return i;
- }
- }
-
return -1;
}
@@ -203,27 +194,27 @@ arena_t* getArena(int id)
int i;
ts = (textFile_t *) listArenaFile->list[id];
-
- for( i = 0 ; i < ts->text->count ; i++ )
- {
+ for( i = 0 ; i < ts->text->count ; i++ ) {
char *line;
- line = (char *) (ts->text->list[i]);
+ line = (char *) (ts->text->list[i]);
cmdModule(line);
-
#ifndef PUBLIC_SERVER
- if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line);
- if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line);
- if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line);
+ if (strncmp(line, "loadImage", 9) == 0)
+ cmd_loadImage(line);
+ if (strncmp(line, "loadMusic", 9) == 0)
+ cmd_loadMusic(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, "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;
}
@@ -235,33 +226,26 @@ void initArenaFile()
#ifndef PUBLIC_SERVER
assert( isImageInicialized() == TRUE );
#endif
-
isArenaFileInit = TRUE;
listArenaFile = newList();
-
p = loadDirector(PATH_ARENA);
-
- for( i = 0 ; i < p->list->count ; i++ )
- {
+ for (i = 0; i < p->list->count; i++) {
char *line;
line = (char *)( p->list->list[i] );
-
- if( strstr(line, ".map") != NULL && strstr(line, "~") == NULL )
- {
+ if (strstr(line, ".map") != NULL &&
+ strstr(line, "~") == NULL) {
char path[STR_PATH_SIZE];
sprintf(path, PATH_ARENA "%s", line);
-
- printf("load map %s\n", line);
-
+#ifdef DEBUG
+ printf(_("Loading map file: %s\n"), line);
+#endif
accessExistFile(path);
addList(listArenaFile, loadTextFile(path));
}
}
-
//printf("No. of Arens: %d\n", listArenaFile->count);
-
destroyDirector(p);
}
@@ -270,4 +254,3 @@ void quitArenaFile()
isArenaFileInit = FALSE;
destroyListItem(listArenaFile, destroyTextFile);
}
-
diff --git a/src/base/arenaFile.h b/src/base/arenaFile.h
index 5f71f5b..75efec8 100644
--- a/src/base/arenaFile.h
+++ b/src/base/arenaFile.h
@@ -1,22 +1,19 @@
#ifndef ARENA_FILE_H
-
-#define ARENA_FILE_H
-
-#include "main.h"
-#include "arena.h"
-
-#define PUBLIC_SERVER_PATH_ARENA "./arena/"
-
-extern int getArenaValue(char *line, char *env, char *val, int len);
-extern bool_t isArenaFileInicialized();
-extern void initArenaFile();
-extern int getArenaCount();
-extern char *getArenaName(int id);
-extern char *getArenaNetName(int id);
-extern int getArenaIdFormNetName(char *s);
-extern char *getArenaImage(int id);
-extern arena_t* getArena(int id);
-extern void quitArenaFile();
-
+ #define ARENA_FILE_H
+ #define PUBLIC_SERVER_PATH_ARENA "./arena/"
+
+ #include "main.h"
+ #include "arena.h"
+
+ extern int getArenaValue(char *line, char *env, char *val, int len);
+ extern bool_t isArenaFileInicialized();
+ extern void initArenaFile();
+ extern int getArenaCount();
+ extern char *getArenaName(int id);
+ extern char *getArenaNetName(int id);
+ extern int getArenaIdFormNetName(char *s);
+ extern char *getArenaImage(int id);
+ extern arena_t* getArena(int id);
+ extern void quitArenaFile();
#endif
diff --git a/src/base/bool.h b/src/base/bool.h
index d122b85..9d02ba2 100644
--- a/src/base/bool.h
+++ b/src/base/bool.h
@@ -1,13 +1,9 @@
#ifndef BOOL_H
+ #define BOOL_H
+ #define bool_t int
+ #define TRUE 1
+ #define FALSE 0
-#define BOOL_H
-
-#include "main.h"
-
-#define bool_t int
-
-#define TRUE 1
-#define FALSE 0
-
+ #include "main.h"
#endif
diff --git a/src/base/checkFront.c b/src/base/checkFront.c
index 941f41d..2f6e00a 100644
--- a/src/base/checkFront.c
+++ b/src/base/checkFront.c
@@ -25,23 +25,19 @@ static checkfront_t* newCheck(char *s, int type, int id)
checkfront_t *new;
assert( s != NULL );
-
new = malloc( sizeof(checkfront_t) );
memset(new, 0, sizeof(checkfront_t));
-
new->msg = strdup(s);
new->time = getMyTime();
new->id = id;
new->type = type;
new->count = 0;
-
return new;
}
static void destroyCheck(checkfront_t *p)
{
assert( p != NULL );
-
free(p->msg);
free(p);
}
@@ -53,11 +49,8 @@ list_t* newCheckFront()
void addMsgInCheckFront(list_t *list, char *msg, int type, int id)
{
- if( type == CHECK_FORNT_TYPE_CHECK )
- {
+ if (type == CHECK_FRONT_TYPE_CHECK)
incID(id);
- }
-
addList(list, newCheck(msg, type, id) );
}
@@ -67,40 +60,31 @@ void eventMsgInCheckFront(client_t *client)
int i;
currentTime = getMyTime();
-
- for( i = 0 ; i < client->listSendMsg->count ; i++ )
- {
+ for(i = 0; i < client->listSendMsg->count; i++) {
checkfront_t *this;
this = (checkfront_t *)client->listSendMsg->list[i];
-
- switch( this->type )
- {
- case CHECK_FORNT_TYPE_SIMPLE :
- sendClient(client, this->msg);
- delListItem(client->listSendMsg, i, destroyCheck);
- i--;
- break;
-
- case CHECK_FORNT_TYPE_CHECK :
- if( this->count == 0 || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL )
- {
+ 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 )
- {
+ if (this->count > CHECK_FRONT_MAX_COUNT_SEND) {
delID(this->id);
delListItem(client->listSendMsg, i, destroyCheck);
i--;
}
- break;
-
+ break;
default :
- assert( ! "Zly typ !" );
- break;
+ assert(! _("Bad type of front!"));
+ break;
}
}
}
@@ -109,14 +93,11 @@ void delMsgInCheckFront(list_t *listCheckFront, int id)
{
int i;
- for( i = 0 ; i < listCheckFront->count ; i++ )
- {
+ for( i = 0 ; i < listCheckFront->count ; i++ ) {
checkfront_t *this;
this = (checkfront_t *)listCheckFront->list[i];
-
- if( this->id == id )
- {
+ if (this->id == id) {
delID(this->id);
delListItem(listCheckFront, i, destroyCheck);
return;
@@ -127,7 +108,6 @@ void delMsgInCheckFront(list_t *listCheckFront, int id)
void destroyCheckFront(list_t *p)
{
assert( p != NULL );
-
destroyListItem(p, destroyCheck);
}
diff --git a/src/base/checkFront.h b/src/base/checkFront.h
index dde30f0..bcf0a18 100644
--- a/src/base/checkFront.h
+++ b/src/base/checkFront.h
@@ -1,22 +1,21 @@
#ifndef CHECK_FRONT_H
-#define CHECK_FRONT_H
+ #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
-#include "list.h"
-#include "server.h"
+ #include "list.h"
+ #include "server.h"
-#define CHECK_FRONT_SEND_TIME_INTERVAL 100
-#define CHECK_FRONT_MAX_COUNT_SEND 30
-
-#define CHECK_FRONT_ID_NONE -1
-#define CHECK_FORNT_TYPE_SIMPLE 1
-#define CHECK_FORNT_TYPE_CHECK 2
-
-extern list_t* newCheckFront();
-extern void addMsgInCheckFront(list_t *list, char *msg, int type, int id);
-extern void eventMsgInCheckFront(client_t *client);
-extern void delMsgInCheckFront(list_t *listCheckFront, int id);
-extern void destroyCheckFront(list_t *p);
+ extern list_t* newCheckFront();
+ extern void addMsgInCheckFront(list_t *list, char *msg, int type, int id);
+ extern void eventMsgInCheckFront(client_t *client);
+ extern void delMsgInCheckFront(list_t *listCheckFront, int id);
+ extern void destroyCheckFront(list_t *p);
#endif
diff --git a/src/base/director.c b/src/base/director.c
index 68bfae5..a4c8496 100755
--- a/src/base/director.c
+++ b/src/base/director.c
@@ -22,55 +22,40 @@ director_t* loadDirector(char *s)
DIR *dir;
struct dirent *item;
char path[STR_PATH_SIZE];
-
assert( s != 0 );
-
new = malloc( sizeof(director_t) );
memset(new, 0, sizeof(director_t) );
-
new->list = newList();
#ifndef __WIN32__
if( s[0] == '/' )
#else
if( s[1] == ':' )
#endif
- {
strcpy(path, s);
- }
- else
- {
- // tohle je opravdu dobre...
+ 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 )
- {
+ if( dir == NULL ) {
free(new->path);
free(new);
-
return NULL;
}
- while( ( item = readdir(dir) ) != NULL )
+ while((item = readdir(dir)) != NULL)
addList(new->list, strdup(item->d_name) );
-
closedir(dir);
-
return new;
}
void destroyDirector(director_t *p)
{
assert( p != NULL );
-
destroyListItem(p->list, free);
free(p->path);
free(p);
}
-
-
diff --git a/src/base/director.h b/src/base/director.h
index 8a07ed0..1baad86 100644
--- a/src/base/director.h
+++ b/src/base/director.h
@@ -1,18 +1,16 @@
#ifndef DIRECTOR_H
-
-#define DIRECTOR_H
-
-#include "main.h"
-#include "list.h"
-
-typedef struct director_struct
-{
- char *path;
- list_t *list;
-} director_t;
-
-extern director_t* loadDirector(char *s);
-extern void destroyDirector(director_t *p);
-
+ #define DIRECTOR_H
+
+ #include "main.h"
+ #include "list.h"
+
+ typedef struct director_struct
+ {
+ char *path;
+ list_t *list;
+ } director_t;
+
+ extern director_t* loadDirector(char *s);
+ extern void destroyDirector(director_t *p);
#endif
diff --git a/src/base/gun.c b/src/base/gun.c
index 8befcbb..7198a1e 100644
--- a/src/base/gun.c
+++ b/src/base/gun.c
@@ -17,42 +17,38 @@
#ifndef NO_SOUND
#include "sound.h"
#endif
-
#ifndef PUBLIC_SERVER
#include "interface.h"
#include "screen_world.h"
#endif
-
#ifdef PUBLIC_SERVER
#include "publicServer.h"
#endif
static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, int *dest_y)
{
- assert( dest_x != NULL );
- assert( dest_y != NULL );
-
- switch( courser )
- {
+ assert(dest_x != NULL);
+ assert(dest_y != NULL);
+ switch (courser) {
case TUX_UP :
*dest_x = right_y;
*dest_y = -right_x;
- break;
+ break;
case TUX_RIGHT :
*dest_x = right_x;
*dest_y = right_y;
- break;
+ break;
case TUX_LEFT :
*dest_x = -right_x;
*dest_y = right_y;
- break;
+ break;
case TUX_DOWN :
*dest_x = right_y;
*dest_y = right_x;
- break;
+ break;
default :
- assert( ! "V premennej courser je zly smer !" );
- break;
+ assert(! _("There is wrong value in course variable!"));
+ break;
}
}
@@ -64,26 +60,20 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun)
modificiationCopuse(tux->position, px, py, &dest_px, &dest_py);
modificiationCopuse(tux->position, x, y, &dest_x, &dest_y);
-
- if( gun == GUN_LASSER )
- {
- switch( tux->position )
- {
+ if (gun == GUN_LASSER)
+ switch (tux->position) {
case TUX_UP :
dest_y -= GUN_LASSER_HORIZONTAL;
- break;
+ break;
case TUX_RIGHT :
break;
case TUX_LEFT :
dest_x -= GUN_LASSER_HORIZONTAL;
- break;
- case TUX_DOWN :
- break;
+ 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);
}
@@ -91,48 +81,39 @@ static void addShot(tux_t *tux,int x, int y, int px, int py)
{
int gun;
- if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_CLIENT)
return;
- }
-
- if( tux->gun == GUN_BOMBBALL )
- {
+ if (tux->gun == GUN_BOMBBALL)
gun = GUN_BOMBBALL;
- }
- else if( tux->gun == GUN_LASSER )
- {
+ else if (tux->gun == GUN_LASSER)
gun = GUN_LASSER;
- }
else
- {
gun = GUN_SIMPLE;
- }
- if( tux->bonus == BONUS_4X )
- {
+ 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;
+ 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
- {
+ }else{
addShotTrivial(tux, x, y, px, py, gun);
}
}
@@ -152,10 +133,8 @@ static void shotInGunScatter(tux_t *tux)
{
int i;
- for( i = -2 ; i <= +2 ; i++ )
- {
+ for (i = -2 ; i <= +2 ; i++)
addShot(tux, 0, 0, +8, i);
- }
}
static void timer_addShotTimer(void *p)
@@ -166,13 +145,11 @@ static void timer_addShotTimer(void *p)
id = * ((int *)p);
free(p);
-
tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
-
- if( tux == NULL )return;
-
- if( tux->status != TUX_STATUS_ALIVE )return;
-
+ if (tux == NULL)
+ return;
+ if (tux->status != TUX_STATUS_ALIVE)
+ return;
gun = tux->gun;
tux->gun = GUN_SIMPLE;
addShot(tux, 0, 0, +6, 0);
@@ -183,10 +160,8 @@ static void shotInGunTommy(tux_t *tux)
{
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)
@@ -197,21 +172,16 @@ static void timer_addLaserTimer(void *p)
id = * ((int *)p);
free(p);
-
tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
-
- if( tux == NULL )return;
-
- if( tux->status != TUX_STATUS_ALIVE )return;
-
+ 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;
}
@@ -219,10 +189,8 @@ static void shotInGunLasser(tux_t *tux)
{
int i;
- for( i = 0 ; i < 50 ; i++ )
- {
+ for (i = 0; i < 50; i++)
addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_addLaserTimer, newInt(tux->id), i * 10 );
- }
}
static void putInGunMine(tux_t *tux)
@@ -232,43 +200,31 @@ static void putInGunMine(tux_t *tux)
x = tux->x;
y = tux->y;
-
- switch( tux->position )
- {
+ switch (tux->position) {
case TUX_UP :
y += TUX_HEIGHT;
- break;
+ break;
case TUX_RIGHT :
x -= TUX_WIDTH;
- break;
+ break;
case TUX_LEFT :
x += TUX_WIDTH;
- break;
+ break;
case TUX_DOWN :
y -= TUX_HEIGHT;
- break;
+ break;
}
-
arena = getCurrentArena();
-
- if( isFreeSpace(getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT) )
- {
+ if (isFreeSpace(getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) {
item_t *item;
#ifndef NO_SOUND
playSound("put_mine", SOUND_GROUP_BASE);
#endif
-
tux->shot[tux->gun]--;
-
- if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
- {
+ if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) {
item = newItem(x, y, ITEM_MINE, tux->id);
-
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
- }
-
addObjectToSpace(arena->spaceItem, item );
}
}
@@ -281,10 +237,8 @@ static void shotInGunBombball(tux_t *tux)
void shotInGun(tux_t *tux)
{
- if( tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE )
- {
+ if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE)
tux->shot[tux->gun]--;
- }
switch( tux->gun )
{
@@ -293,36 +247,36 @@ void shotInGun(tux_t *tux)
playSound("gun_revolver", SOUND_GROUP_BASE);
#endif
shotInGunSimpe(tux);
- break;
+ break;
case GUN_DUAL_SIMPLE :
#ifndef NO_SOUND
playSound("gun_revolver", SOUND_GROUP_BASE);
#endif
shotInGunDualSimpe(tux);
- break;
+ break;
case GUN_SCATTER :
#ifndef NO_SOUND
- playSound("gun_scatter", SOUND_GROUP_BASE);
+ playSound("gun_scatter", SOUND_GROUP_BASE);
#endif
shotInGunScatter(tux);
- break;
+ break;
case GUN_TOMMY :
#ifndef NO_SOUND
playSound("gun_tommy", SOUND_GROUP_BASE);
#endif
shotInGunTommy(tux);
- break;
+ break;
case GUN_LASSER :
#ifndef NO_SOUND
playSound("gun_lasser", SOUND_GROUP_BASE);
#endif
shotInGunLasser(tux);
- break;
+ break;
case GUN_BOMBBALL :
shotInGunBombball(tux);
- break;
+ break;
case GUN_MINE :
putInGunMine(tux);
- break;
+ break;
}
}
diff --git a/src/base/gun.h b/src/base/gun.h
index 835c2c8..77ab4fe 100644
--- a/src/base/gun.h
+++ b/src/base/gun.h
@@ -1,21 +1,15 @@
#ifndef GUN_H
-
-#define GUN_H
-
-#include "main.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 "tux.h"
-
-extern void shotInGun(tux_t *p);
-
+ #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"
+
+ extern void shotInGun(tux_t *p);
#endif
diff --git a/src/base/homeDirector.c b/src/base/homeDirector.c
index a3ae1d1..1f10920 100755
--- a/src/base/homeDirector.c
+++ b/src/base/homeDirector.c
@@ -18,24 +18,23 @@ void createHomeDirector()
#else
envHome = getenv("USERPROFILE");
#endif
- if( envHome == NULL )
- {
- fprintf(stderr, "Environment HOME not found !\n");
+ if (envHome == NULL) {
+ fprintf(stderr, _("Environment variable HOME not found!\n"));
exit(0);
}
sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME);
- if ( access(homeDirector, F_OK) != 0 )
- {
- printf("Create home director %s\n", homeDirector);
+ if (access(homeDirector, F_OK) != 0) {
+#ifdef DEBUG
+ 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, "Can't create home directory!\n");
+ fprintf(stderr, _("Unable to create home directory!\n"));
exit(0);
}
}
diff --git a/src/base/homeDirector.h b/src/base/homeDirector.h
index c8b1114..22c9243 100755
--- a/src/base/homeDirector.h
+++ b/src/base/homeDirector.h
@@ -1,13 +1,10 @@
#ifndef HOMEDIRECTOR_H
+ #define HOMEDIRECTOR_H
+ #define HOMEDIRECTOR_NAME ".tuxanci"
-#define HOMEDIRECTOR_H
+ #include "main.h"
-#include "main.h"
-
-#define HOMEDIRECTOR_NAME ".tuxanci"
-
-extern void createHomeDirector();
-extern char *getHomeDirector();
-
+ extern void createHomeDirector();
+ extern char *getHomeDirector();
#endif
diff --git a/src/base/idManager.h b/src/base/idManager.h
index c80ff7c..fc28c74 100644
--- a/src/base/idManager.h
+++ b/src/base/idManager.h
@@ -1,25 +1,20 @@
-
#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"
-
-extern void initListID();
-extern int isRegisterID(int id);
-extern int getNewIDcount(int count);
-extern int getNewID();
-extern void incID(int id);
-extern void delID(int id);
-extern void replaceID(int old_id, int new_id);
-extern void quitListID();
+ #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);
+ extern int getNewIDcount(int count);
+ extern int getNewID();
+ extern void incID(int id);
+ extern void delID(int id);
+ extern void replaceID(int old_id, int new_id);
+ extern void quitListID();
#endif
diff --git a/src/base/item.c b/src/base/item.c
index bd61728..56ad293 100644
--- a/src/base/item.c
+++ b/src/base/item.c
@@ -63,7 +63,6 @@ void initItem()
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;
}
@@ -73,9 +72,7 @@ item_t* newItem(int x, int y, int type, int author_id)
new = malloc( sizeof(item_t) );
assert( new != NULL );
-
new->type = type;
-
new->id = getNewID();
new->x = x;
new->y = y;
@@ -85,9 +82,7 @@ item_t* newItem(int x, int y, int type, int author_id)
new->img = g_item[type];
#endif
new->author_id = author_id;
-
- switch( type )
- {
+ switch (type) {
case GUN_DUAL_SIMPLE :
case GUN_SCATTER :
case GUN_TOMMY :
@@ -96,29 +91,25 @@ item_t* newItem(int x, int y, int type, int author_id)
case GUN_BOMBBALL :
new->w = ITEM_GUN_WIDTH;
new->h = ITEM_GUN_HEIGHT;
- break;
-
+ break;
case ITEM_MINE :
new->w = ITEM_MINE_WIDTH;
new->h = ITEM_MINE_HEIGHT;
- break;
-
+ break;
case ITEM_EXPLOSION :
#ifndef NO_SOUND
playSound("explozion", SOUND_GROUP_BASE);
#endif
new->w = ITEM_EXPLOSION_WIDTH;
new->h = ITEM_EXPLOSION_HEIGHT;
- break;
-
+ break;
case ITEM_BIG_EXPLOSION :
#ifndef NO_SOUND
playSound("explozion", SOUND_GROUP_BASE);
#endif
new->w = ITEM_BIG_EXPLOSION_WIDTH;
new->h = ITEM_BIG_EXPLOSION_HEIGHT;
- break;
-
+ break;
case BONUS_SPEED :
case BONUS_SHOT :
case BONUS_TELEPORT :
@@ -127,9 +118,8 @@ item_t* newItem(int x, int y, int type, int author_id)
case BONUS_HIDDEN :
new->w = ITEM_BONUS_WIDTH;
new->h = ITEM_BONUS_HEIGHT;
- break;
+ break;
}
-
return new;
}
@@ -138,7 +128,6 @@ 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;
@@ -191,56 +180,61 @@ void addNewItem(space_t *spaceItem, int author_id)
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 )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
- }
}
-#ifndef PUBLIC_SERVER
-
+#ifndef PUBLIC_SERVER
void drawItem(item_t *p)
{
- assert( p != NULL );
-
+ assert(p != NULL);
addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER);
}
@@ -249,10 +243,8 @@ void drawListItem(list_t *listItem)
item_t *thisItem;
int i;
- assert( listItem != NULL );
-
- for( i = 0 ; i < listItem->count ; i++ )
- {
+ assert(listItem != NULL);
+ for (i = 0; i < listItem->count; i++) {
thisItem = (item_t *)listItem->list[i];
assert( thisItem != NULL );
drawItem(thisItem);
@@ -266,44 +258,30 @@ 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 )
- {
+ if (item->count == ITEM_MAX_COUNT) {
item->count = 0;
item->frame++;
}
-
- switch( item->type )
- {
+ 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 )
- {
+ if (item->frame == ITEM_GUN_MAX_FRAME)
item->frame = 0;
- }
- break;
-
+ break;
case ITEM_MINE :
- if( item->frame == ITEM_MINE_MAX_FRAME )
- {
+ if(item->frame == ITEM_MINE_MAX_FRAME)
item->frame = 0;
- }
- break;
-
+ break;
case ITEM_EXPLOSION :
case ITEM_BIG_EXPLOSION :
- if( item->frame == ITEM_EXPLOSION_MAX_FRAME )
- {
+ if(item->frame == ITEM_EXPLOSION_MAX_FRAME)
delObjectFromSpaceWithObject(space, item, destroyItem);
- }
- break;
-
+ break;
case BONUS_SPEED :
case BONUS_SHOT :
case BONUS_TELEPORT :
@@ -311,10 +289,8 @@ static void action_itemevent(space_t *space, item_t *item, void *p)
case BONUS_4X :
case BONUS_HIDDEN :
if( item->frame == ITEM_GUN_MAX_FRAME )
- {
item->frame = 0;
- }
- break;
+ break;
}
}
@@ -325,33 +301,21 @@ void eventListItem(space_t *spaceItem)
static void mineExplosion(space_t *spaceItem, item_t *item)
{
- if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
- {
+ 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 )
- {
+ 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 )
- {
+ 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)
@@ -359,20 +323,15 @@ static void action_item(space_t *space, item_t *item, int *isDel)
arena_t *arena;
arena = getCurrentArena();
-
- switch( item->type )
- {
+ switch(item->type) {
case ITEM_MINE :
if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
- {
mineExplosion(space, item);
- }
- break;
-
+ break;
case ITEM_EXPLOSION :
case ITEM_BIG_EXPLOSION :
*isDel = 1;
- break;
+ break;
}
}
@@ -381,58 +340,38 @@ 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 )
- {
+ 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)
{
- if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_CLIENT)
return;
- }
-
actionSpace(arena->spaceShot, action_shot, arena->spaceItem);
}
static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item)
{
- if( tux->bonus == BONUS_GHOST )
- {
+ if (tux->bonus == BONUS_GHOST)
return;
- }
-
- if( tux->bonus == BONUS_TELEPORT )
- {
+ if (tux->bonus == BONUS_TELEPORT) {
tuxTeleport(tux);
return;
}
-
- if( item->author_id != tux->id )
- {
+ if (item->author_id != tux->id) {
tux_t *author;
author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, item->author_id);
-
- if( author != NULL )
- {
+ if (author != NULL) {
author->score++;
-
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_newtux_server(PROTO_SEND_ALL, NULL, author);
- }
}
}
-
countRoundInc();
eventTuxIsDead(tux);
}
@@ -442,14 +381,10 @@ static void tuxGiveBonus(tux_t *tux, item_t *item)
#ifndef NO_SOUND
playSound("item_bonus", SOUND_GROUP_BASE);
#endif
-
tux->bonus = item->type;
tux->bonus_time = TUX_MAX_BONUS;
-
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
}
static void tuxGiveGun(tux_t *tux, item_t *item)
@@ -457,21 +392,16 @@ static void tuxGiveGun(tux_t *tux, item_t *item)
#ifndef NO_SOUND
playSound("item_gun", SOUND_GROUP_BASE);
#endif
-
tux->pickup_time = 0;
tux->shot[ item->type ] += GUN_MAX_SHOT;
tux->gun = item->type;
-
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
}
static void action_giveitem(space_t *space, item_t *item, tux_t *tux)
{
- switch( item->type )
- {
+ switch (item->type) {
case GUN_TOMMY :
case GUN_DUAL_SIMPLE :
case GUN_SCATTER :
@@ -479,34 +409,23 @@ static void action_giveitem(space_t *space, item_t *item, tux_t *tux)
case GUN_MINE :
case GUN_BOMBBALL :
tuxGiveGun(tux, item);
-
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
- }
-
delObjectFromSpaceWithObject(space, item, destroyItem);
-
#ifdef PUBLIC_SERVER
addNewItem(space, ID_UNKNOWN);
#endif
- break;
+ break;
case ITEM_MINE :
- if( tux->bonus != BONUS_GHOST )
- {
+ if (tux->bonus != BONUS_GHOST)
mineExplosion(space, item);
- }
- break;
-
+ break;
case ITEM_EXPLOSION :
case ITEM_BIG_EXPLOSION :
- if( tux->bonus != BONUS_GHOST )
- {
+ if (tux->bonus != BONUS_GHOST)
eventTuxIsDeadWithItem(tux, item);
- }
- break;
-
+ break;
case BONUS_SPEED :
case BONUS_SHOT :
case BONUS_TELEPORT :
@@ -514,18 +433,13 @@ static void action_giveitem(space_t *space, item_t *item, tux_t *tux)
case BONUS_4X :
case BONUS_HIDDEN :
tuxGiveBonus(tux, item);
-
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER)
proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
- }
-
delObjectFromSpaceWithObject(space, item, destroyItem);
-
#ifdef PUBLIC_SERVER
addNewItem(space, ID_UNKNOWN);
#endif
- break;
+ break;
}
}
@@ -533,28 +447,19 @@ void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem)
{
int x, y, w, h;
- assert( spaceItem != NULL );
- assert( tux != NULL );
-
- if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
- {
+ assert(spaceItem != NULL);
+ assert(tux != NULL);
+ if (getNetTypeGame() == NET_GAME_TYPE_CLIENT)
return;
- }
-
- if( tux->status == TUX_STATUS_DEAD )
- {
+ if (tux->status == TUX_STATUS_DEAD)
return;
- }
-
getTuxProportion(tux, &x, &y, &w, &h);
-
actionSpaceFromLocation(spaceItem, action_giveitem, tux, x, y, w, h);
}
void destroyItem(item_t *p)
{
- assert( p != NULL );
-
+ assert(p != NULL);
delID(p->id);
free(p);
}
diff --git a/src/base/item.h b/src/base/item.h
index 822283e..78ea944 100644
--- a/src/base/item.h
+++ b/src/base/item.h
@@ -1,83 +1,69 @@
#ifndef ITEM_H
-
-#define ITEM_H
-
-#include "main.h"
-
-#define ITEM_SYNC_TIMEOUT 5000
-
-#ifndef PUBLIC_SERVER
-#include "image.h"
-#endif
-
-#ifdef __WIN32__
-#define random rand
-#endif
-
-#include "list.h"
-#include "tux.h"
-#include "myTimer.h"
-
-typedef struct item_struct
-{
- int id;
- int type; // typ veci
-
- int x; // poloha veci
- int y;
-
- int w; // rozmery veci
- int h;
-
- int frame; //poradove cislo animacie
- int count;
-
- int author_id;
-#ifndef PUBLIC_SERVER
- image_t *img; //obrazok
-#endif
-} item_t;
-
-#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
-
-extern bool_t isItemInicialized();
-extern void initItem();
-extern item_t* newItem(int x, int y, int type, int author_id);
-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
-extern void drawItem(item_t *p);
-extern void drawListItem(list_t *listItem);
+ #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"
+
+ typedef struct item_struct
+ {
+ int id;
+ int type; // type of thing
+
+ int x; // item position
+ int y;
+
+ int w; // item size
+ int h;
+
+ int frame; //number of animation
+ int count;
+
+ int author_id;
+ #ifndef PUBLIC_SERVER
+ image_t *img; //picture
+ #endif
+ } item_t;
+
+ extern bool_t isItemInicialized();
+ extern void initItem();
+ extern item_t* newItem(int x, int y, int type, int author_id);
+ 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
+ extern void drawItem(item_t *p);
+ extern void drawListItem(list_t *listItem);
+ #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);
+ extern void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem);
+ extern void destroyItem(item_t *p);
+ extern void quitItem();
#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);
-extern void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem);
-extern void destroyItem(item_t *p);
-extern void quitItem();
-
-#endif
-
diff --git a/src/base/list.c b/src/base/list.c
index 39b3962..b59f64b 100755
--- a/src/base/list.c
+++ b/src/base/list.c
@@ -1,19 +1,18 @@
-#include "main.h"
-#include "list.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include "main.h"
+#include "list.h"
+
list_t* newList()
{
list_t *new;
- new = malloc( sizeof(list_t) );
- memset(new, 0, sizeof(list_t) );
-
+ new = malloc(sizeof(list_t));
+ memset(new, 0, sizeof(list_t));
return new;
}
@@ -21,17 +20,13 @@ list_t* cloneList(list_t *p)
{
list_t *new;
- assert( p != NULL );
-
+ assert(p != NULL);
new = malloc( sizeof(list_t) );
memcpy(new, p, sizeof(list_t) );
-
- if( p->list != NULL )
- {
+ if(p->list != NULL) {
new->list = malloc( p->alloc * sizeof(void *) );
memcpy(new->list, p->list, p->alloc * sizeof(void *));
}
-
return new;
}
@@ -41,15 +36,12 @@ list_t* cloneListItem(list_t *p, void *f)
void* (*fce)(void *);
int i;
- assert( p != NULL );
- assert( f != NULL );
-
+ assert(p != NULL);
+ assert(f != NULL);
new = cloneList(p);
fce = f;
-
- for(i = 0 ; i < p->count ; i++)
+ for (i = 0; i < p->count; i++)
new->list[i] = fce(p->list[i]);
-
return new;
}
@@ -57,41 +49,33 @@ void addList(list_t *p, void *item)
{
assert( p != NULL );
- if( p->alloc == 0 )
- {
+ if (p->alloc == 0) {
p->alloc = LIST_ALLOC_LIMIT;
p->count = 1;
- p->list = malloc(p->alloc * sizeof(void *) );
+ p->list = malloc(p->alloc * sizeof(void *));
p->list[0] = item;
-
return;
}
- if( p->count + 1 <= p->alloc )
- {
+ if (p->count + 1 <= p->alloc) {
p->list[p->count] = item;
p->count += 1;
-
return;
}
- if( p->count + 1 > p->alloc )
- {
+ if (p->count + 1 > p->alloc) {
void **new;
-
#ifdef DEBUG_LIST
- printf("realocating from %d to %d (count=%d)\n",
+ 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 *) );
+ 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;
}
}
@@ -99,21 +83,16 @@ void addList(list_t *p, 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 *));
-
+ assert(n >= 0 || n < p->count);
+ memmove(p->list+n+1, p->list+n, ((p->count-1) - n) * sizeof(void *));
p->list[n] = item;
}
void *getList(list_t *p, int n)
{
- assert( p != NULL );
- assert( n >= 0 || n < p->count );
-
+ assert(p != NULL);
+ assert(n >= 0 || n < p->count);
return p->list[n];
}
@@ -122,31 +101,25 @@ int searchListItem(list_t *p, void *n)
int i;
assert( p != NULL );
-
- for( i = 0 ; i < p->count ; i++ )
- if( p->list[i] == n )return i;
-
+ for (i = 0; i < p->count; i++)
+ if (p->list[i] == n)
+ return i;
return -1;
}
void delList(list_t *p, int n)
{
- assert( p != NULL );
- assert( n >= 0 || n < p->count );
-
+ 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 )
- {
+ if(p->count + LIST_ALLOC_LIMIT < p->alloc) {
void **new;
#ifdef DEBUG_LIST
- printf("realocating from %d to %d (count=%d)\n",
+ 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 *) );
@@ -159,12 +132,11 @@ void delListItem(list_t *p, int n, void *f)
{
int (*fce)(void *);
- assert( p != NULL );
- assert( n >= 0 || n < p->count );
-
+ assert(p != NULL);
+ assert(n >= 0 || n < p->count);
fce = f;
- if( fce != NULL )fce(p->list[n]);
-
+ if(fce != NULL)
+ fce(p->list[n]);
delList(p, n);
}
@@ -188,54 +160,8 @@ void destroyListItem(list_t *p, void *f)
assert( p != NULL );
assert( f != NULL );
-
fce = f;
-
- for(i = 0 ; i < p->count ; i++)
+ for (i = 0; i < p->count; i++)
fce(p->list[i]);
-
destroyList(p);
-}
-
-/*
-typedef struct pokus_str
-{
- int x;
-} pokus;
-
-pokus* newPokus(int n)
-{
- pokus *new;
- new = malloc(sizeof(pokus));
- new->x = n;
- return new;
-}
-
-pokus *clonePokus(pokus *p)
-{
- pokus *new;
- new = malloc(sizeof(pokus));
- memcpy(new, p, sizeof(pokus));
- return new;
-}
-
-void destroyPokus(pokus *p)
-{
- free(p);
-}
-
-int main()
-{
- list_t *my;
- int i;
-
- my = newList();
-
- for(i = 0; i < 100; i++)
- addList(my, newPokus(i));
-
- destroyListItem(my, destroyPokus);
-
- return 0;
-}
-*/
+} \ No newline at end of file
diff --git a/src/base/list.h b/src/base/list.h
index 5a15786..3813b35 100755
--- a/src/base/list.h
+++ b/src/base/list.h
@@ -1,33 +1,27 @@
#ifndef LIST_H
-
-#define LIST_H
-
-#include "main.h"
-
-#define LIST_ALLOC_LIMIT 16
-
-typedef struct list_str
-{
- void **list;
- int count;
- int alloc;
-} list_t;
-
-extern list_t* newList();
-extern list_t* cloneList(list_t *p);
-extern list_t* cloneListItem(list_t *p, void *f);
-
-extern void addList(list_t *p, void *item);
-extern void insList(list_t *p, int n, void *item);
-extern void *getList(list_t *p,int n);
-extern int searchListItem(list_t *p, void *n);
-
-extern void delList(list_t *p,int n);
-extern void delListItem(list_t *p,int n,void *f);
-extern void listDoEmpty(list_t *p);
-
-extern void destroyList(list_t *p);
-extern void destroyListItem(list_t *p,void *f);
-
+ #define LIST_H
+ #define LIST_ALLOC_LIMIT 16
+
+ #include "main.h"
+
+ typedef struct list_str
+ {
+ void **list;
+ int count;
+ int alloc;
+ } list_t;
+
+ extern list_t* newList();
+ extern list_t* cloneList(list_t *p);
+ extern list_t* cloneListItem(list_t *p, void *f);
+ extern void addList(list_t *p, void *item);
+ extern void insList(list_t *p, int n, void *item);
+ extern void *getList(list_t *p,int n);
+ extern int searchListItem(list_t *p, void *n);
+ extern void delList(list_t *p,int n);
+ extern void delListItem(list_t *p,int n,void *f);
+ extern void listDoEmpty(list_t *p);
+ extern void destroyList(list_t *p);
+ extern void destroyListItem(list_t *p,void *f);
#endif
diff --git a/src/base/main.c b/src/base/main.c
index 6221dd8..4c40b97 100644
--- a/src/base/main.c
+++ b/src/base/main.c
@@ -129,6 +129,13 @@ int main(int argc, char *argv[])
srand( (unsigned) time(NULL) );
+
+#ifdef NLS
+ setlocale( LC_ALL, "" );
+ bindtextdomain( "tuxanci", PATH_LOCALE);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain( "tuxanci" );
+#endif
#ifndef __WIN32__
my_argc = argc;
my_argv = argv;
diff --git a/src/base/main.h b/src/base/main.h
index 5fbd81a..cfa4ee0 100644
--- a/src/base/main.h
+++ b/src/base/main.h
@@ -1,24 +1,28 @@
#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
-
-#include "../../config.h"
-
-#include "bool.h"
-#include "string_length.h"
-#include "path.h"
-
-// screen resolution
-#define WINDOW_SIZE_X 800
-#define WINDOW_SIZE_Y 600
-
-extern char* getParam(char *s);
-extern char* getParamElse(char *s1, char *s2);
-extern bool_t isParamFlag(char *s);
-extern char *getString(int n);
-extern int* newInt(int x);
-extern void accessExistFile(const char *s);
-extern int tryExistFile (const char *s);
+#ifdef NLS
+ #include <libintl.h>
+ #include <locale.h>
+#endif
+ #include "../../config.h"
+ #include "bool.h"
+ #include "string_length.h"
+ #include "path.h"
+ extern char* getParam(char *s);
+ extern char* getParamElse(char *s1, char *s2);
+ extern bool_t isParamFlag(char *s);
+ extern char *getString(int n);
+ extern int* newInt(int x);
+ extern void accessExistFile(const char *s);
+ extern int tryExistFile (const char *s);
#endif
diff --git a/src/base/modules.c b/src/base/modules.c
index 1443f21..f03decd 100755
--- a/src/base/modules.c
+++ b/src/base/modules.c
@@ -16,7 +16,6 @@
#include "arenaFile.h"
#include "proto.h"
#include "shareFunction.h"
-
#ifndef PUBLIC_SERVER
#include "interface.h"
#include "image.h"
@@ -51,37 +50,30 @@ static export_fce_t export_fce =
#ifndef PUBLIC_SERVER
.fce_proto_send_module_client = proto_send_module_client,
#endif
-
.fce_destroyShot = destroyShot,
.fce_boundBombBall = boundBombBall,
.fce_transformOnlyLasser = transformOnlyLasser
};
-
static list_t *listModule;
static void* getFce(module_t *p, char *s)
{
#ifndef __WIN32__
-
void *ret;
char *error;
- assert( p != NULL );
- assert( s != NULL );
-
+ assert(p != NULL);
+ assert(s != NULL);
ret = dlsym(p->image, s);
- if( ( error = dlerror() ) != NULL)
- {
- fprintf (stderr, "error = %s\n", error);
+ 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, "n_dllsymbol(%s) failed!\n", s);
-
-
+ if (!ret)
+ fprintf(stderr, _("Error %s occured when using getFce function!\n"), s);
#endif
return (void *)ret;
}
@@ -91,9 +83,7 @@ static void* mapImage(char *name)
#ifndef __WIN32__
void *image;
image = dlopen (name, RTLD_LAZY);
-
- if( image == NULL )
- {
+ if( image == NULL ) {
fputs (dlerror(), stderr);
return NULL;
}
@@ -101,8 +91,7 @@ static void* mapImage(char *name)
HINSTANCE image;
image = LoadLibrary((LPCSTR) name);
- if (!image)
- {
+ if (!image) {
LPVOID msg;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -120,9 +109,8 @@ static void* mapImage(char *name)
FreeLibrary(image);
return NULL;
}
- //FreeLibrary(image); //to tu nema bejt
+ //FreeLibrary(image); //never ever untag this
#endif
-
return image;
}
@@ -152,22 +140,16 @@ static module_t* newModule(char *name)
void *image;
module_t *ret;
- assert( name != NULL );
-
+ assert(name != NULL);
setModulePath(name, path);
image = mapImage(path);
-
- if( image == NULL )
- {
- fprintf(stderr, "I dont map %s file !\n", name);
+ if (image == NULL) {
+ fprintf(stderr, _("Unable to map file %s!\n"), name);
return NULL;
}
-
- ret = malloc( sizeof(module_t) );
-
+ 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");
@@ -177,33 +159,29 @@ static module_t* newModule(char *name)
ret->fce_isConflict = getFce(ret, "isConflict");
ret->fce_cmd = getFce(ret, "cmdArena");
ret->fce_recvMsg = getFce(ret, "recvMsg");
-
- printf("load module: (%s)\n", name);
-
- if( ret->fce_init(&export_fce) != 0 )
- {
- fprintf(stderr, "init module failed !\n");
+#ifdef DEBUG
+ printf(_("Loading module: \"%s\""), 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;
}
static int destroyModule(module_t *p)
{
assert( p != NULL );
-
p->fce_destroy();
unmapImage(p->image);
free(p->name);
free(p);
-
- printf("destroy module..\n");
-
+#ifdef DEBUG
+ printf(_("Destroing module...\n"));
+#endif
return 0;
}
@@ -217,18 +195,13 @@ int isModuleLoaded(char *name)
{
int i;
- for( i = 0 ; i < listModule->count ; i++ )
- {
+ for (i = 0; i < listModule->count; i++) {
module_t *this;
this = (module_t *)listModule->list[i];
-
- if( strcmp(this->name, name) == 0 )
- {
+ if (strcmp(this->name, name) == 0)
return 1;
- }
}
-
return 0;
}
@@ -236,32 +209,23 @@ int loadModule(char *name)
{
module_t *module;
- if( isModuleLoaded(name) )
- {
- fprintf(stderr, "dupicit loaded module %s !\n", name);
+ 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, "load module %s failed !\n", name);
+ if (module == NULL) {
+ fprintf(stderr, _("Loading module %s failed!\n"), name);
return -1;
}
-
addList(listModule, module);
-
return 0;
}
int loadDepModule(char *name)
{
- if( isModuleLoaded(name) )
- {
+ if (isModuleLoaded(name))
return 0;
- }
-
return loadModule(name);
}
@@ -269,8 +233,7 @@ void cmdModule(char *s)
{
int i;
- for( i = 0 ; i < listModule->count ; i++ )
- {
+ for (i = 0; i < listModule->count; i++) {
module_t *this;
this = (module_t *)listModule->list[i];
this->fce_cmd(s);
@@ -278,27 +241,23 @@ void cmdModule(char *s)
}
#ifndef PUBLIC_SERVER
-
void drawModule(int x, int y, int w, int h)
{
int i;
- for( i = 0 ; i < listModule->count ; i++ )
- {
+ 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()
{
int i;
- for( i = 0 ; i < listModule->count ; i++ )
- {
+ for (i = 0; i < listModule->count; i++ ) {
module_t *this;
this = (module_t *)listModule->list[i];
this->fce_event();
@@ -309,17 +268,13 @@ int isConflictModule(int x, int y, int w, int h)
{
int i;
- for( i = 0 ; i < listModule->count ; i++ )
- {
+ 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 )
- {
+ this = (module_t *)listModule->list[i];
+ if (this->fce_isConflict(x, y, w, h) == 1)
return 1;
- }
}
-
return 0;
}
@@ -327,14 +282,12 @@ int recvMsgModule(char *msg)
{
int i;
- for( i = 0 ; i < listModule->count ; i++ )
- {
+ for (i = 0; i < listModule->count; i++) {
module_t *this;
this = (module_t *)listModule->list[i];
this->fce_recvMsg(msg);
}
-
return 0;
}
diff --git a/src/base/myTimer.c b/src/base/myTimer.c
index 2fbee7b..4de0fcc 100644
--- a/src/base/myTimer.c
+++ b/src/base/myTimer.c
@@ -5,55 +5,17 @@
#include <string.h>
#include <sys/time.h>
#include <signal.h>
+#ifdef __WIN32__
+#include <time.h>
+#endif
#include "main.h"
#include "list.h"
#include "myTimer.h"
-
#ifndef PUBLIC_SERVER
#include "interface.h"
#endif
-#ifdef __WIN32__
-#include <windows.h>
-#include <time.h>
-#endif
-/* // uncoment when having issues with gettimeofday in Windows
-#ifdef __WIN32__
-#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
-struct timezone
-{
- int tz_minuteswest;
- int tz_dsttime;
-};
-
-int gettimeofday(struct timeval *tv, struct timezone *tz)
-{
- FILETIME ft;
- unsigned __int64 tmpres = 0;
- static int tzflag;
- if (NULL != tv) {
- GetSystemTimeAsFileTime(&ft);
- tmpres |= ft.dwHighDateTime;
- tmpres <<= 32;
- tmpres |= ft.dwLowDateTime;
- tmpres /= 10;
- tmpres -= DELTA_EPOCH_IN_MICROSECS;
- tv->tv_sec = (long)(tmpres / 1000000UL);
- tv->tv_usec = (long)(tmpres % 1000000UL);
- }
- if (NULL != tz) {
- if (!tzflag) {
- _tzset();
- tzflag++;
- }
- tz->tz_minuteswest = _timezone / 60;
- tz->tz_dsttime = _daylight;
- }
- return 0;
-}
-#endif
-*/
static struct timeval start = { .tv_sec = 0, .tv_usec = 0 };
list_t* newTimer()
@@ -72,15 +34,10 @@ my_time_t getMyTime()
struct timeval now;
my_time_t ticks;
- if( start.tv_sec == 0 && start.tv_usec == 0 )
- {
+ 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;
}
@@ -90,16 +47,10 @@ 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 )
- {
+ 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;
}
@@ -108,20 +59,15 @@ my_timer_t* newTimerItem(int type, void (*fce)(void *p), void *arg, my_time_t my
{
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;
}
@@ -137,7 +83,6 @@ int addTaskToTimer(list_t *listTimer, int type, void (*fce)(void *p), void *arg,
new = newTimerItem(type, fce, arg, my_time);
addList(listTimer, new);
-
return new->id;
}
@@ -146,37 +91,28 @@ void eventTimer(list_t *listTimer)
int i;
my_timer_t *thisTimer;
my_time_t currentTime;
-
currentTime = getMyTime();
-
- for( i = 0 ; i < listTimer->count ; i++ )
- {
+ for (i = 0; i < listTimer->count; i++) {
thisTimer = (my_timer_t *)listTimer->list[i];
- assert( thisTimer != NULL );
-
- switch( thisTimer->type )
- {
+ assert(thisTimer != NULL);
+ switch (thisTimer->type) {
case TIMER_ONE:
- if( currentTime >= thisTimer->createTime + thisTimer->time )
- {
+ if (currentTime >= thisTimer->createTime + thisTimer->time) {
thisTimer->fce(thisTimer->arg);
-
delListItem(listTimer, i, free);
i--;
}
- break;
+ break;
case TIMER_PERIODIC:
- if( currentTime >= thisTimer->createTime + thisTimer->time )
- {
+ if (currentTime >= thisTimer->createTime + thisTimer->time) {
thisTimer->fce(thisTimer->arg);
thisTimer->createTime = getMyTime();
}
- break;
+ break;
default :
- assert( ! "bad timer type !" );
- break;
+ assert(! _("Timer is really wierdly set!"));
+ break;
}
-
}
}
@@ -185,19 +121,15 @@ void delTimer(list_t *listTimer, int id)
int i;
my_timer_t *thisTimer;
- for( i = 0 ; i < listTimer->count ; i++ )
- {
+ for (i = 0; i < listTimer->count; i++) {
thisTimer = (my_timer_t *)listTimer->list[i];
- assert( thisTimer != NULL );
-
- if( thisTimer->id == id )
- {
+ assert(thisTimer != NULL);
+ if (thisTimer->id == id ) {
delListItem(listTimer, i, free);
return;
}
}
-
- assert( ! "Uloha s id nenajdena !" );
+ assert(! _("There is no such ID!"));
}
diff --git a/src/base/myTimer.h b/src/base/myTimer.h
index 97c2f65..24980fb 100644
--- a/src/base/myTimer.h
+++ b/src/base/myTimer.h
@@ -1,32 +1,28 @@
#ifndef MY_TIME_H
-
-#define MY_TIME_H
-
-#include "main.h"
-#include "list.h"
-
-#define my_time_t unsigned int
-
-#define TIMER_ONE 0
-#define TIMER_PERIODIC 1
-
-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);
-extern void eventTimer(list_t *listTimer);
-extern void delTimer(list_t *listTimer, int id);
-extern void destroyTimer(list_t *listTimer);
-
+ #define MY_TIME_H
+ #define my_time_t unsigned int
+ #define TIMER_ONE 0
+ #define TIMER_PERIODIC 1
+
+ #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;
+ } 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);
+ extern void eventTimer(list_t *listTimer);
+ extern void delTimer(list_t *listTimer, int id);
+ extern void destroyTimer(list_t *listTimer);
#endif
diff --git a/src/base/path.h b/src/base/path.h
index f547f69..3c44600 100644
--- a/src/base/path.h
+++ b/src/base/path.h
@@ -1,43 +1,38 @@
#ifndef PATH_H
-
-#define PATH_H
-
-#include "main.h"
-
-#ifndef PREFIX
-#ifndef __WIN32__
- #define PREFIX "/usr/local"
-#else
- #define PREFIX ".."
-#endif
-#endif
-
-#ifndef PUBLIC_SERVER
- #define PATH_DIR PREFIX "/share/tuxanci/"
-#ifndef __WIN32__
- #define PATH_MODULES PREFIX "/lib/tuxanci/"
-#else
- #define PATH_MODULES PREFIX "/bin/"
-#endif
-#else
- #define PATH_DIR PREFIX "/share/tuxanci-server/"
-#ifndef __WIN32__
- #define PATH_MODULES PREFIX "/lib/tuxanci-server/"
- #define SERVER_CONFIG "/etc/tuxanci-server/server.conf"
-#else
- #define PATH_MODULES PREFIX "/bin/"
- #define SERVER_CONFIG PREFIX "/etc/tuxanci-server/server.conf"
-#endif
-#endif
-
-#define PATH_IMAGE PATH_DIR "image/"
-#define PATH_FONT PATH_DIR "font/"
-#define PATH_ARENA PATH_DIR "arena/"
-#define PATH_SOUND PATH_DIR "sound/"
-#define PATH_MUSIC PATH_DIR "music/"
-#define PATH_CONFIG PATH_DIR "conf/"
-#define PATH_LANG PATH_DIR "lang/"
-#define PATH_DATA PATH_DIR "doc/"
-
+ #define PATH_H
+ #ifndef PREFIX
+ #ifndef __WIN32__
+ #define PREFIX "/usr/local"
+ #else
+ #define PREFIX ".."
+ #endif
+ #endif
+ #ifndef PUBLIC_SERVER
+ #define PATH_DIR PREFIX "/share/tuxanci/"
+ #ifndef __WIN32__
+ #define PATH_MODULES PREFIX "/lib/tuxanci/"
+ #else
+ #define PATH_MODULES PREFIX "/bin/"
+ #endif
+ #else
+ #define PATH_DIR PREFIX "/share/tuxanci-server/"
+ #ifndef __WIN32__
+ #define PATH_MODULES PREFIX "/lib/tuxanci-server/"
+ #define SERVER_CONFIG "/etc/tuxanci-server/server.conf"
+ #else
+ #define PATH_MODULES PREFIX "/bin/"
+ #define SERVER_CONFIG PREFIX "/etc/tuxanci-server/server.conf"
+ #endif
+ #endif
+ #define PATH_IMAGE PATH_DIR "image/"
+ #define PATH_FONT PATH_DIR "font/"
+ #define PATH_ARENA PATH_DIR "arena/"
+ #define PATH_SOUND PATH_DIR "sound/"
+ #define PATH_MUSIC PATH_DIR "music/"
+ #define PATH_CONFIG PATH_DIR "conf/"
+ #define PATH_LANG PATH_DIR "lang/"
+ #define PATH_DATA PATH_DIR "doc/"
+ #define PATH_LOCALE PREFIX "share/locale/"
+ #include "main.h"
#endif
diff --git a/src/base/protect.c b/src/base/protect.c
index cf567b8..e83c1ec 100644
--- a/src/base/protect.c
+++ b/src/base/protect.c
@@ -11,7 +11,6 @@
protect_t* newProtect()
{
protect_t *new;
-
new = malloc( sizeof(protect_t) );
new->lastMove = getMyTime();
new->lastPing = getMyTime();
@@ -27,21 +26,16 @@ void refreshLastMove(protect_t *p)
my_time_t interval;
currentTime = getMyTime();
-
interval = currentTime - p->lastMove;
p->lastMove = getMyTime();
-
p->avarage += interval;
p->count++;
-
- if( p->count == PROTECT_SPEED_AVARAGE )
- {
+ if (p->count == PROTECT_SPEED_AVARAGE) {
int index;
index = p->avarage/PROTECT_SPEED_AVARAGE;
p->avarage = 0;
p->count = 0;
-
#if 0
if( index < PROTECT_SPEED_INTERVAL_TIMEOUT )
{
@@ -56,12 +50,9 @@ 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);
}
@@ -71,14 +62,9 @@ bool_t isDown(protect_t *p)
my_time_t interval;
currentTime = getMyTime();
-
interval = currentTime - p->lastPing;
-
- if( interval > PROTECT_PING_INTERVAL_TIMEOUT )
- {
+ if (interval > PROTECT_PING_INTERVAL_TIMEOUT)
p->isDown = TRUE;
- }
-
return p->isDown;
}
diff --git a/src/base/protect.h b/src/base/protect.h
index e0553dd..ec9db56 100644
--- a/src/base/protect.h
+++ b/src/base/protect.h
@@ -1,30 +1,25 @@
#ifndef PROTECT_H
-
-#define PROTECT_H
-
-#include "main.h"
-#include "myTimer.h"
-
-#define PROTECT_PING_INTERVAL_TIMEOUT 5000
-#define PROTECT_SPEED_INTERVAL_TIMEOUT 40
-#define PROTECT_SPEED_AVARAGE 10
-
-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();
-extern void refreshLastMove(protect_t *p);
-extern void rereshLastPing(protect_t *p);
-extern bool_t isDown(protect_t *p);
-extern void destroyProtect(protect_t *p);
-
+ #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"
+
+ 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();
+ extern void refreshLastMove(protect_t *p);
+ extern void rereshLastPing(protect_t *p);
+ extern bool_t isDown(protect_t *p);
+ extern void destroyProtect(protect_t *p);
#endif
diff --git a/src/base/proto.c b/src/base/proto.c
index 8386a52..cb54bab 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -44,7 +44,7 @@ void proto_send_error_server(int type, client_t *client, int errorcode)
snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -226,7 +226,7 @@ void proto_send_status_server(int type, client_t *client)
name, version, clients,
maxclients, uptime, arena);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
//proto_send(type, client, msg);
}
@@ -260,7 +260,7 @@ void proto_send_listscore_server(int type, client_t *client, int max)
}
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
free(msg);
}
@@ -337,7 +337,7 @@ void proto_send_init_server(int type, client_t *client, client_t *client2)
count, getArenaNetName( getChoiceArenaId() ), check_id);
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id);
}
#ifndef PUBLIC_SERVER
@@ -393,7 +393,7 @@ void proto_send_event_server(int type, client_t *client, tux_t *tux, int action)
snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action);
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -492,7 +492,7 @@ void proto_send_newtux_server(int type, client_t *client, tux_t *tux)
tux->bonus_time, tux->pickup_time);
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -582,7 +582,7 @@ void proto_send_kill_server(int type, client_t *client, tux_t *tux)
snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id);
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -623,7 +623,7 @@ void proto_send_del_server(int type, client_t *client, int id)
snprintf(msg, STR_PROTO_SIZE, "del %d %d\n",
id, check_id);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id);
//proto_check(type, client, msg, check_id);
}
@@ -696,7 +696,7 @@ void proto_send_additem_server(int type, client_t *client, item_t *p)
//proto_send(type, client, msg);
//proto_check(type, client, msg, check_id);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id);
}
#ifndef PUBLIC_SERVER
@@ -757,7 +757,7 @@ void proto_send_shot_server(int type, client_t *client, shot_t *p)
//proto_send(type, client, msg);
//proto_check(type, client, msg, check_id);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -833,7 +833,7 @@ void proto_recv_chat_server(client_t *client, char *msg)
void proto_send_chat_server(int type, client_t *client, char *msg)
{
- protoSendClient(type, client, msg, CHECK_FORNT_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);
@@ -889,7 +889,7 @@ void proto_send_module_server(int type, client_t *client, char *msg)
strcat(out, "\n");
*/
- protoSendClient(type, client, out, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -921,7 +921,7 @@ void proto_send_ping_server(int type, client_t *client)
char msg[STR_PROTO_SIZE];
snprintf(msg, STR_PROTO_SIZE, "ping\n");
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -943,7 +943,7 @@ void proto_send_echo_server(int type, client_t *client, char *s)
snprintf(msg, STR_PROTO_SIZE, "echo%s", s);
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
void proto_send_end_server(int type, client_t *client)
@@ -952,7 +952,7 @@ void proto_send_end_server(int type, client_t *client)
snprintf(msg, STR_PROTO_SIZE, "end\n");
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
diff --git a/src/base/shot.h b/src/base/shot.h
index 189cf52..1b3569e 100644
--- a/src/base/shot.h
+++ b/src/base/shot.h
@@ -1,66 +1,54 @@
#ifndef SHOT_H
-
-#define SHOT_H
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "arena.h"
-
-#ifdef __WIN32__
-#define random rand
-#endif
-
-#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
-} shot_t;
-
-extern bool_t isShotInicialized();
-extern void initShot();
-extern shot_t* newShot(int x,int y, int px, int py, int gun, int author_id);
-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
-extern void drawShot(shot_t *p);
-extern void drawListShot(list_t *listShot);
-#endif
-extern int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h);
-extern void eventMoveListShot(arena_t *arena);
-extern void checkShotIsInTuxScreen(arena_t *arena);
-
-extern void boundBombBall(shot_t *shot);
-extern void transformOnlyLasser(shot_t *shot);
-
-extern void destroyShot(shot_t *p);
-extern void quitShot();
-
+ #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
+
+ 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();
+ extern void initShot();
+ extern shot_t* newShot(int x,int y, int px, int py, int gun, int author_id);
+ 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
+ extern void drawShot(shot_t *p);
+ extern void drawListShot(list_t *listShot);
+ #endif
+ extern int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h);
+ extern void eventMoveListShot(arena_t *arena);
+ extern void checkShotIsInTuxScreen(arena_t *arena);
+ extern void boundBombBall(shot_t *shot);
+ extern void transformOnlyLasser(shot_t *shot);
+ extern void destroyShot(shot_t *p);
+ extern void quitShot();
#endif
diff --git a/src/base/storage.c b/src/base/storage.c
index 0d48711..be27321 100644
--- a/src/base/storage.c
+++ b/src/base/storage.c
@@ -1,3 +1,4 @@
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -22,15 +23,13 @@ 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) );
+ 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;
}
@@ -38,11 +37,9 @@ static void destroyStorageItem(storage_item_t *p, void *f)
{
void(*fce)(void *);
- assert( p != NULL );
- assert( f != NULL );
-
+ assert(p != NULL);
+ assert(f != NULL);
fce = f;
-
fce(p->data);
free(p->name);
free(p->group);
@@ -51,10 +48,9 @@ static void destroyStorageItem(storage_item_t *p, void *f)
void addItemToStorage(list_t *list, char *group, char *name, void *data)
{
- assert( list != NULL );
- assert( group != NULL );
- assert( name != NULL );
-
+ assert(list != NULL);
+ assert(group != NULL);
+ assert(name != NULL);
addList(list, newStorageItem(group, name, data) );
}
@@ -63,21 +59,17 @@ 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++)
- {
+ 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 )
- {
+ if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0)
return this->data;
- }
}
-
- printf("%s %s not found in storage !!!\n", group, name);
+#ifdef DEBUG
+ printf("%s %s was not found in storage!\n", group, name);
+#endif
return NULL;
}
@@ -86,22 +78,17 @@ 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++)
- {
+ 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 )
- {
+ if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) {
destroyStorageItem(this, f);
delList(list, i);
return;
}
}
-
return;
}
@@ -110,15 +97,12 @@ void delAllItemFromStorage(list_t *list, char *group, void *f)
storage_item_t *this;
int i;
- assert( list != NULL );
- assert( group != NULL );
+ assert(list != NULL);
+ assert(group != NULL);
- for(i = 0 ; i < list->count; i++)
- {
+ for (i = 0; i < list->count; i++) {
this = (storage_item_t *) list->list[i];
-
- if( strcmp(group, this->group) == 0 )
- {
+ if (strcmp(group, this->group) == 0) {
destroyStorageItem(this, f);
delList(list, i);
i--;
@@ -131,14 +115,11 @@ 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++ )
- {
+ 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 81e554e..8943f6c 100644
--- a/src/base/storage.h
+++ b/src/base/storage.h
@@ -1,16 +1,14 @@
#ifndef STORAGE_H
+ #define STORAGE_H
-#define STORAGE_H
-
-#include "main.h"
-#include "list.h"
-
-extern list_t* newStorage();
-extern void addItemToStorage(list_t *list, char *group, char *name, void *data);
-extern void* getItemFromStorage(list_t *list, char *group, char *name);
-extern void delItemFromStorage(list_t *list, char *group, char *name, void *f);
-extern void delAllItemFromStorage(list_t *list, char *group, void *f);
-extern void destroyStorage(list_t *p, void *f);
+ #include "main.h"
+ #include "list.h"
+ extern list_t* newStorage();
+ extern void addItemToStorage(list_t *list, char *group, char *name, void *data);
+ extern void* getItemFromStorage(list_t *list, char *group, char *name);
+ extern void delItemFromStorage(list_t *list, char *group, char *name, void *f);
+ extern void delAllItemFromStorage(list_t *list, char *group, void *f);
+ extern void destroyStorage(list_t *p, void *f);
#endif