summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rw-r--r--src/base/checkFront.c17
-rw-r--r--src/base/idManager.c131
-rw-r--r--src/base/idManager.h4
-rw-r--r--src/base/item.c15
-rw-r--r--src/base/proto.c6
-rw-r--r--src/base/shot.c24
-rw-r--r--src/base/space.c78
-rw-r--r--src/base/space.h7
-rw-r--r--src/base/tux.c17
-rwxr-xr-xsrc/client/layer.c1
11 files changed, 206 insertions, 96 deletions
diff --git a/config.h b/config.h
index d9663d2..1d82d6d 100644
--- a/config.h
+++ b/config.h
@@ -1 +1 @@
-#define TUXANCI_NG_VERSION "svn126"
+#define TUXANCI_NG_VERSION "svn127"
diff --git a/src/base/checkFront.c b/src/base/checkFront.c
index f6164f3..941f41d 100644
--- a/src/base/checkFront.c
+++ b/src/base/checkFront.c
@@ -53,6 +53,11 @@ list_t* newCheckFront()
void addMsgInCheckFront(list_t *list, char *msg, int type, int id)
{
+ if( type == CHECK_FORNT_TYPE_CHECK )
+ {
+ incID(id);
+ }
+
addList(list, newCheck(msg, type, id) );
}
@@ -87,11 +92,7 @@ void eventMsgInCheckFront(client_t *client)
if( this->count > CHECK_FRONT_MAX_COUNT_SEND )
{
- if( isRegisterID(this->id) != -1 )
- {
- delID(this->id);
- }
-
+ delID(this->id);
delListItem(client->listSendMsg, i, destroyCheck);
i--;
}
@@ -116,11 +117,7 @@ void delMsgInCheckFront(list_t *listCheckFront, int id)
if( this->id == id )
{
- if( isRegisterID(this->id) != -1 )
- {
- delID(this->id);
- }
-
+ delID(this->id);
delListItem(listCheckFront, i, destroyCheck);
return;
}
diff --git a/src/base/idManager.c b/src/base/idManager.c
index ea7e679..ee77239 100644
--- a/src/base/idManager.c
+++ b/src/base/idManager.c
@@ -10,6 +10,30 @@
static list_t *listID;
static int lastID;
+typedef struct id_item_struct
+{
+ int id;
+ int count;
+} id_item_t;
+
+static id_item_t* newIdItem(int id, int count)
+{
+ id_item_t *new;
+
+ new = malloc( sizeof(id_item_t) );
+ new->id = id;
+ new->count = count;
+
+ return new;
+}
+
+static void destroyIdItem(id_item_t *p)
+{
+ assert( p != NULL );
+
+ free(p);
+}
+
void initListID()
{
listID = newList();
@@ -25,11 +49,11 @@ int isRegisterID(int id)
for( i = 0 ; i < listID->count ; i++ )
{
- int *z;
+ id_item_t *this;
- z = (int *) listID->list[i];
+ this = listID->list[i];
- if( *z == id )
+ if( this->id == id )
{
return i;
}
@@ -38,7 +62,7 @@ int isRegisterID(int id)
return -1;
}
-int getNewID()
+static int findNewID()
{
int ret;
@@ -46,26 +70,56 @@ int getNewID()
do{
ret = random() % MAX_ID;
-/*
- ret = ++lastID;
- if( lastID > MAX_ID )
- {
- lastID = 0;
- }
-*/
}while( isRegisterID(ret) != -1 );
- addList(listID, newInt(ret) );
-
- //printf("new ID -> %d\n", ret);
return ret;
}
-void delID(int id)
+int getNewIDcount(int count)
{
+ int id;
+
+ id = findNewID();
+
+ addList(listID, newIdItem(id, count) );
+
+ return id;
+}
+
+int getNewID()
+{
+ return getNewIDcount(1);
+}
+
+void incID(int id)
+{
+ id_item_t *this;
int index;
+
+ assert( listID != NULL );
+
+ index = isRegisterID(id);
+
+ if( index == -1 )
+ {
+ assert( ! "takyto ID nebol nikdy registrovany !" );
+ return; // ha ha ha
+ }
+
+ this = listID->list[index];
+
+ this->count++;
+
+ //printf("inc ID %d %d\n", this->id, this->count);
+ return;
+}
+void delID(int id)
+{
+ id_item_t *this;
+ int index;
+
assert( listID != NULL );
index = isRegisterID(id);
@@ -76,25 +130,60 @@ void delID(int id)
return; // ha ha ha
}
- delListItem(listID, index, free);
+ this = listID->list[index];
+ this->count--;
+ //printf("dec ID %d %d\n", this->id, this->count);
+
+ if( this->count <= 0 )
+ {
+ delListItem(listID, index, free);
+ }
+
return;
}
void replaceID(int old_id, int new_id)
{
+ int index_old_id;
+ int index_new_id;
+ id_item_t *this;
+
if( old_id == new_id )
{
return;
}
- delID(old_id);
+ index_old_id = isRegisterID(old_id);
+ assert( index_old_id != -1 );
- if( new_id != -1 )
+ index_new_id = isRegisterID(new_id);
+ assert( index_new_id == -1 );
+
+ this = listID->list[index_old_id];
+ this->id = new_id;
+}
+
+void infoID(int id)
+{
+ id_item_t *this;
+ int index;
+
+ assert( listID != NULL );
+
+ index = isRegisterID(id);
+
+ if( index == -1 )
{
- assert( isRegisterID(new_id) == -1 );
- addList(listID, newInt(new_id) );
+ printf("ID %d not exists\n", id);
+ return;
}
+
+ this = listID->list[index];
+
+ printf("ID %d ( count %d )\n", this->id, this->count);
+
+ return;
}
void quitListID()
@@ -102,6 +191,6 @@ void quitListID()
printf("quit ID manger..\n");
assert( listID != NULL );
- destroyListItem(listID, free);
+ destroyListItem(listID, destroyIdItem);
}
diff --git a/src/base/idManager.h b/src/base/idManager.h
index 62e2651..a261316 100644
--- a/src/base/idManager.h
+++ b/src/base/idManager.h
@@ -10,8 +10,10 @@
#include "list.h"
extern void initListID();
-extern int getNewID();
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();
diff --git a/src/base/item.c b/src/base/item.c
index ccbdd62..70d6c0e 100644
--- a/src/base/item.c
+++ b/src/base/item.c
@@ -86,6 +86,11 @@ item_t* newItem(int x, int y, int type, int author_id)
#endif
new->author_id = author_id;
+ if( author_id != ID_UNKNOWN )
+ {
+ incID(author_id);
+ }
+
switch( type )
{
case GUN_DUAL_SIMPLE :
@@ -216,6 +221,7 @@ void addNewItem(space_t *spaceItem, int author_id)
case 11 : type = BONUS_HIDDEN;
break;
}
+
#ifndef PUBLIC_SERVER
}while( isSettingItem(type) == FALSE ||
(getNetTypeGame() == NET_GAME_TYPE_NONE && type == BONUS_HIDDEN) );
@@ -399,7 +405,7 @@ void eventConflictShotWithItem(arena_t *arena)
case ITEM_EXPLOSION :
case ITEM_BIG_EXPLOSION :
- isDelShot = TRUE;
+ isDelShot = TRUE;
break;
}
}
@@ -595,7 +601,14 @@ void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem)
void destroyItem(item_t *p)
{
assert( p != NULL );
+
delID(p->id);
+
+ if( p->author_id != ID_UNKNOWN )
+ {
+ delID(p->author_id);
+ }
+
free(p);
}
diff --git a/src/base/proto.c b/src/base/proto.c
index 5d1debd..af8a9f7 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -251,7 +251,7 @@ void proto_send_init_server(int type, client_t *client, client_t *client2)
getSettingCountRound(&count);
#endif
- check_id = getNewID();
+ check_id = getNewIDcount(0);
sprintf(msg, "init %d %d %d %d %s %d\n",
client2->tux->id, client2->tux->x, client2->tux->y,
@@ -519,7 +519,7 @@ void proto_send_del_server(int type, client_t *client, int id)
char msg[STR_PROTO_SIZE];
int check_id;
- check_id = getNewID();
+ check_id = getNewIDcount(0);
sprintf(msg, "del %d %d\n",
id, check_id);
@@ -590,7 +590,7 @@ void proto_send_additem_server(int type, client_t *client, item_t *p)
assert( p != NULL );
- check_id = getNewID();
+ check_id = getNewIDcount(0);
sprintf(msg, "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);
diff --git a/src/base/shot.c b/src/base/shot.c
index e0d9dbf..6911d1a 100644
--- a/src/base/shot.c
+++ b/src/base/shot.c
@@ -70,6 +70,11 @@ shot_t* newShot(int x,int y, int px, int py, int gun, int author_id)
new->gun = gun;
new->author_id = author_id;
+ if( author_id != ID_UNKNOWN )
+ {
+ incID(author_id);
+ }
+
new->position = POSITION_UNKNOWN;
author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id);
@@ -294,18 +299,6 @@ void eventMoveListShot(arena_t *arena)
}
}
-#if 0
-static int myAbs(int n)
-{
- return ( n > 0 ? n : -n );
-}
-
-static int getSppedShot(shot_t *shot)
-{
- return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) );
-}
-#endif
-
static int isValueInList(list_t *list, int x)
{
int i;
@@ -374,7 +367,14 @@ void checkShotIsInTuxScreen(arena_t *arena)
void destroyShot(shot_t *p)
{
assert( p != NULL );
+
delID(p->id);
+
+ if( p->author_id != ID_UNKNOWN )
+ {
+ delID(p->author_id);
+ }
+
free(p);
}
diff --git a/src/base/space.c b/src/base/space.c
index b32ae33..fb51c40 100644
--- a/src/base/space.c
+++ b/src/base/space.c
@@ -9,6 +9,24 @@
#include "space.h"
#include "index.h"
+zone_t* newZone()
+{
+ zone_t *new;
+
+ new = malloc( sizeof(zone_t) );
+ new->list = newList();
+
+ return new;
+}
+
+void destroyZone(zone_t *p)
+{
+ assert( p != NULL );
+
+ 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)
{
return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1);
@@ -33,18 +51,18 @@ space_t *newSpace(int w, int h, int segW, int segH,
new->list = newList();
new->listIndex = newIndex();
- new->area = malloc( new->w * sizeof(list_t **) );
+ new->zone = malloc( new->w * sizeof(list_t **) );
for( i = 0 ; i < new->w ; i++ )
{
- new->area[i] = malloc( new->h * sizeof(list_t *) );
+ new->zone[i] = malloc( new->h * sizeof(list_t *) );
}
for( i = 0 ; i < new->h ; i++ )
{
for( j = 0 ; j < new->w ; j++ )
{
- new->area[j][i] = newList();
+ new->zone[j][i] = newZone();
}
}
@@ -79,7 +97,7 @@ void addObjectToSpace(space_t *p, void *item)
continue;
}
- addList(p->area[j][i], item);
+ addList(p->zone[j][i]->list, item);
}
}
@@ -101,14 +119,14 @@ void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list)
{
void *this;
- for( k = 0 ; k < p->area[j][i]->count ; k++ )
+ if( j < 0 || j >= p->w || i < 0 || i >= p->h )
{
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
+ continue;
+ }
- this = p->area[j][i]->list[k];
+ 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) &&
@@ -144,14 +162,14 @@ int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h)
{
void *this;
- for( k = 0 ; k < p->area[j][i]->count ; k++ )
+ if( j < 0 || j >= p->w || i < 0 || i >= p->h )
{
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
+ continue;
+ }
- this = p->area[j][i]->list[k];
+ 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) )
@@ -179,14 +197,14 @@ int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, voi
{
void *this;
- for( k = 0 ; k < p->area[j][i]->count ; k++ )
+ if( j < 0 || j >= p->w || i < 0 || i >= p->h )
{
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
+ continue;
+ }
- this = p->area[j][i]->list[k];
+ for( k = 0 ; k < p->zone[j][i]->list->count ; k++ )
+ {
+ this = p->zone[j][i]->list->list[k];
if( this == but )
{
@@ -225,9 +243,9 @@ void delObjectFromSpace(space_t *p, void *item)
continue;
}
- index = searchListItem(p->area[j][i], item);
+ index = searchListItem(p->zone[j][i]->list, item);
assert( index != -1 );
- delList(p->area[j][i], index);
+ delList(p->zone[j][i]->list, index);
}
}
@@ -285,13 +303,17 @@ void printSpace(space_t *p)
{
for( j = 0 ; j < p->w ; j++ )
{
- printf("%3d ", p->area[j][i]->count);
+ printf("%3d ", p->zone[j][i]->list->count);
}
putchar('\n');
}
}
+void actionSpace(space_t *space)
+{
+}
+
void destroySpace(space_t *p)
{
int j, i;
@@ -303,16 +325,16 @@ void destroySpace(space_t *p)
{
for( j = 0 ; j < p->w ; j++ )
{
- destroyList(p->area[j][i]);
+ destroyZone(p->zone[j][i]);
}
}
for( i = 0 ; i < p->w ; i++ )
{
- free(p->area[i]);
+ free(p->zone[i]);
}
- free(p->area);
+ free(p->zone);
free(p);
}
diff --git a/src/base/space.h b/src/base/space.h
index be21411..ed46a87 100644
--- a/src/base/space.h
+++ b/src/base/space.h
@@ -6,6 +6,11 @@
#include "main.h"
#include "list.h"
+typedef struct zone_struct
+{
+ list_t *list;
+} zone_t;
+
typedef struct space_struct
{
int w;
@@ -14,7 +19,7 @@ typedef struct space_struct
int segW;
int segH;
- list_t ***area;
+ zone_t ***zone;
list_t *list;
list_t *listIndex;
diff --git a/src/base/tux.c b/src/base/tux.c
index 5907a49..21fa7e6 100644
--- a/src/base/tux.c
+++ b/src/base/tux.c
@@ -233,23 +233,6 @@ void replaceTuxID(tux_t *tux, int id)
tux->id = id;
}
-#if 0
-int isTuxSeesTux(tux_t *tux, tux_t *thisTux)
-{
- int tux_x, tux_y, tux_w, tux_h;
- int thisTux_x, thisTux_y, thisTux_w, thisTux_h;
- int screen_x, screen_y;
-
- getTuxProportion(tux, &tux_x, &tux_y, &tux_w, &tux_h);
- getTuxProportion(thisTux, &thisTux_x, &thisTux_y, &thisTux_w, &thisTux_h);
-
- getCenterScreen(&screen_x, &screen_y, tux->x, tux->y);
-
- return conflictSpace(screen_x-WINDOW_SIZE_X/4, screen_y-WINDOW_SIZE_Y/4,
- WINDOW_SIZE_X*1.25, WINDOW_SIZE_Y*1.25, thisTux_x, thisTux_y, thisTux_w, thisTux_h);
-}
-#endif
-
static void timer_spawnTux(void *p)
{
tux_t *tux;
diff --git a/src/client/layer.c b/src/client/layer.c
index 9354aae..102af1c 100755
--- a/src/client/layer.c
+++ b/src/client/layer.c
@@ -26,7 +26,6 @@ bool_t isLayerInicialized()
*/
void initLayer()
{
- printf("*******************\nnew layer\n**********************\n");
listLayer = newList();
isLayerInit = TRUE;
}