summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Makefile7
-rw-r--r--src/arena.c61
-rw-r--r--src/arenaFile.c14
-rw-r--r--src/gun.c17
-rw-r--r--src/idManager.c5
-rw-r--r--src/item.c181
-rw-r--r--src/language.c2
-rwxr-xr-xsrc/list.c5
-rw-r--r--src/main.c9
-rwxr-xr-xsrc/modules.c6
-rw-r--r--src/proto.c54
-rw-r--r--src/screen_world.c57
-rw-r--r--src/server.c58
-rw-r--r--src/shot.c82
-rw-r--r--src/space.c370
-rw-r--r--src/tux.c149
16 files changed, 909 insertions, 168 deletions
diff --git a/src/Makefile b/src/Makefile
index aa1bad1..57e51d8 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -9,8 +9,8 @@ CFLAGS = -g -O0 -std=c99 -I../include -Wall `sdl-config --cflags`
BUILD_DIR = .
LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_net
-FILES = interface.o idManager.o storage.o font.o list.o modules.o image.o layer.o director.o\
- configFile.o tux.o main.o checkFront.o\
+FILES = interface.o space.o idManager.o storage.o font.o list.o modules.o\
+ image.o layer.o director.o configFile.o tux.o main.o checkFront.o\
screen.o screen_world.o shot.o myTimer.o panel.o net_multiplayer.o \
buffer.o arena.o arenaFile.o textFile.o audio.o sound.o music.o gun.o \
item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \
@@ -24,6 +24,9 @@ tuxanci-ng: $(FILES)
main.o: main.c
$(CC) $(CFLAGS) -o $(BUILD_DIR)/main.o -c main.c
+space.o: space.c ../include/space.h
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)/space.o -c space.c
+
interface.o: interface.c ../include/interface.h
$(CC) $(CFLAGS) -o $(BUILD_DIR)/interface.o -c interface.c
diff --git a/src/arena.c b/src/arena.c
index 98ec0d8..5b11bcb 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -29,7 +29,7 @@ arena_t* getCurrentArena()
return currentArena;
}
-arena_t* newArena()
+arena_t* newArena(int w, int h)
{
arena_t *new;
new = malloc( sizeof(arena_t) );
@@ -39,10 +39,17 @@ arena_t* newArena()
strcpy(new->music, "");
#endif
+ new->w = w;
+ new->h = h;
+
new->listTimer = newList();
- new->listTux = newList();
+
+ //new->listTux = newList();
+ //new->listItem = newList();
+ new->spaceTux = newSpace(w, h, 320, 240, getStatusTux, setStatusTux);
+ new->spaceItem = newSpace(w, h, 320, 240, getStatusItem, setStatusItem);
+
new->listShot = newList();
- new->listItem = newList();
return new;
}
@@ -54,9 +61,9 @@ int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2)
int isFreeSpace(arena_t *arena, int x, int y, int w, int h)
{
- if( isConflictWithListTux(arena->listTux, x, y, w, h) )return 0;
+ if( isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) )return 0;
if( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0;
- if( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0;
+ if( isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h) )return 0;
if( isConflictModule(x, y, w, h) )return 0;
//if( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0;
//if( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0;
@@ -74,8 +81,8 @@ void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h)
assert( y != NULL );
do{
- z_x = random() % arena->w;
- z_y = random() % arena->h;
+ z_x = random() % WINDOW_SIZE_X;//arena->w;
+ z_y = random() % WINDOW_SIZE_Y;//arena->h;
}while( isFreeSpace(arena, z_x, z_y ,w ,h) == 0 );
*x = z_x;
@@ -122,6 +129,10 @@ void drawArena(arena_t *arena)
tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT);
+ if( tux == NULL )
+ {
+ return;
+ }
/*
screen_x = tux->x - WINDOW_SIZE_X/2;
screen_y = tux->y - WINDOW_SIZE_Y/2;
@@ -143,14 +154,29 @@ void drawArena(arena_t *arena)
}
- drawListTux(arena->listTux);
+ listDoEmpty(listHelp);
+ getObjectFromSpace(arena->spaceTux, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp);
+ drawListTux(listHelp);
+
+ listDoEmpty(listHelp);
+ getObjectFromSpace(arena->spaceItem, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp);
+ drawListItem(listHelp);
+
+ printSpace(arena->spaceItem);
+
+ //drawListTux(arena->listTux);
//drawListWall(arena->listWall);
//drawListTeleport(arena->listTeleport);
//drawListPipe(arena->listPipe);
drawListShot(arena->listShot);
- drawListItem(arena->listItem);
+ //drawListItem(arena->listItem);
+ drawModule(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
+/*
+ my_time_t t;
+ t = getMyTime();
+*/
if( tux == NULL )
{
drawLayerCenter(WINDOW_SIZE_X/2, WINDOW_SIZE_Y/2);
@@ -159,6 +185,8 @@ void drawArena(arena_t *arena)
{
drawLayerCenter(tux->x, tux->y);
}
+
+// printf("time = %d\n", getMyTime() - t );
}
#endif
@@ -168,31 +196,32 @@ void eventArena(arena_t *arena)
int i;
//eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport);
- eventConflictTuxWithShot(arena->listTux, arena->listShot);
+ //eventConflictTuxWithShot(arena);
for( i = 0 ; i < 8 ; i++)
{
eventMoveListShot(arena->listShot);
+ checkShotIsInTuxScreen(arena);
//eventConflictShotWithWall(arena->listWall, arena->listShot);
//eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
//eventConflictShotWithPipe(arena->listPipe, arena->listShot);
- eventConflictShotWithItem(arena->listItem, arena->listShot);
- eventConflictTuxWithShot(arena->listTux, arena->listShot);
+ eventConflictShotWithItem(arena);
+ eventConflictTuxWithShot(arena);
eventModule();
}
- eventListItem(arena->listItem);
+ eventListItem(arena->spaceItem);
- eventListTux(arena->listTux);
+ eventListTux(arena->spaceTux->list);
eventTimer(arena->listTimer);
}
void destroyArena(arena_t *p)
{
- destroyListItem(p->listTux, destroyTux);
+ destroySpace(p->spaceTux, destroyTux);
+ destroySpace(p->spaceItem, destroyItem);
destroyListItem(p->listShot, destroyShot);
- destroyListItem(p->listItem, destroyItem);
destroyTimer(p->listTimer);
free(p);
}
diff --git a/src/arenaFile.c b/src/arenaFile.c
index f0971b3..52f31c0 100644
--- a/src/arenaFile.c
+++ b/src/arenaFile.c
@@ -68,7 +68,7 @@ static void cmd_loadMusic(char *line)
addMusic(str_file, str_name, MUSIC_GROUP_USER);
}
-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];
@@ -78,9 +78,12 @@ static void cmd_arena(arena_t *arena, char *line)
if( getValue(line, "w", str_w, STR_SIZE) != 0 )return;
if( getValue(line, "h", str_h, STR_SIZE) != 0 )return;
- arena->background = getImage(IMAGE_GROUP_USER, str_image);
- arena->w = atoi(str_w);
- arena->h = atoi(str_h);
+ (*arena) = newArena(atoi(str_w), atoi(str_h));
+ (*arena)->background = getImage(IMAGE_GROUP_USER, str_image);
+ //(*arena)->w = atoi(str_w);
+ //(*arena)->h = atoi(str_h);
+ setCurrentArena(*arena);
+ printf("new arena\n");
}
static void cmd_playMusic(arena_t *arena, char *line)
@@ -167,7 +170,6 @@ arena_t* getArena(int id)
int i;
ts = (textFile_t *) listArenaFile->list[id];
- arena = newArena();
for( i = 0 ; i < ts->text->count ; i++ )
{
@@ -179,7 +181,7 @@ arena_t* getArena(int id)
#ifndef PUBLIC_SERVER
if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line);
if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line);
- if( strncmp(line, "arena", 5) == 0 )cmd_arena(arena, line);
+ if( strncmp(line, "arena", 5) == 0 )cmd_arena(&arena, line);
if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line);
#endif
diff --git a/src/gun.c b/src/gun.c
index 96d0f21..bddeda1 100644
--- a/src/gun.c
+++ b/src/gun.c
@@ -93,7 +93,16 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun)
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- proto_send_shot_server(PROTO_SEND_ALL, NULL, shot);
+ client_t *thisClient;
+
+ thisClient = getClientFromTux(tux);
+
+ if( thisClient != NULL )
+ {
+ proto_send_shot_server(PROTO_SEND_ONE, thisClient, shot);
+ }
+
+ proto_send_shot_server(PROTO_SEND_ALL_SEES_TUX, thisClient, shot);
}
}
@@ -178,7 +187,7 @@ static void timer_addShotTimer(void *p)
id = * ((int *)p);
free(p);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux == NULL )return;
@@ -209,7 +218,7 @@ static void timer_addLaserTimer(void *p)
id = * ((int *)p);
free(p);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux == NULL )return;
@@ -281,7 +290,7 @@ static void putInGunMine(tux_t *tux)
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
}
- addList(arena->listItem, item );
+ addObjectToSpace(arena->spaceItem, item );
}
}
}
diff --git a/src/idManager.c b/src/idManager.c
index 9c866c9..3162771 100644
--- a/src/idManager.c
+++ b/src/idManager.c
@@ -81,6 +81,11 @@ void delID(int id)
void replaceID(int old_id, int new_id)
{
+ if( old_id == new_id )
+ {
+ return;
+ }
+
delID(old_id);
if( new_id != -1 )
diff --git a/src/item.c b/src/item.c
index 9a05601..fdd0ad3 100644
--- a/src/item.c
+++ b/src/item.c
@@ -128,6 +128,7 @@ item_t* newItem(int x, int y, int type, int author_id)
return new;
}
+/*
item_t* getItemID(list_t *listItem, int id)
{
item_t *thisItem;
@@ -148,6 +149,31 @@ item_t* getItemID(list_t *listItem, int id)
return NULL;
}
+*/
+
+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;
+}
+
+void setStatusItem(void *p, int x, int y, int w, int h)
+{
+ item_t *item;
+
+ item = p;
+ item->x = x;
+ item->y = y;
+ item->w = w;
+ item->h = h;
+}
void replaceItemID(item_t *item, int id)
{
@@ -155,7 +181,7 @@ void replaceItemID(item_t *item, int id)
item->id = id;
}
-void addNewItem(list_t *listItem, int author_id)
+void addNewItem(space_t *spaceItem, int author_id)
{
#ifndef PUBLIC_SERVER
char msg[STR_SIZE];
@@ -214,7 +240,7 @@ void addNewItem(list_t *listItem, int author_id)
#endif
item = newItem(new_x, new_y, type, author_id);
- addList(listItem, item);
+ addObjectToSpace(spaceItem, item);
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
@@ -254,7 +280,7 @@ void drawListItem(list_t *listItem)
#endif
-void eventListItem(list_t *listItem)
+void eventListItem(space_t *spaceItem)
{
my_time_t currentTime;
item_t *thisItem;
@@ -262,11 +288,11 @@ void eventListItem(list_t *listItem)
currentTime = getMyTime();
- assert( listItem != NULL );
+ assert( spaceItem != NULL );
- for( i = 0 ; i < listItem->count ; i++ )
+ for( i = 0 ; i < spaceItem->list->count ; i++ )
{
- thisItem = (item_t *)listItem->list[i];
+ thisItem = (item_t *)spaceItem->list->list[i];
assert( thisItem != NULL );
thisItem->count++;
@@ -302,7 +328,7 @@ void eventListItem(list_t *listItem)
case ITEM_BIG_EXPLOSION :
if( thisItem->frame == ITEM_EXPLOSION_MAX_FRAME )
{
- delListItem(listItem, i, destroyItem);
+ delObjectFromSpaceWithMem(spaceItem, thisItem, destroyItem);
i--;
}
break;
@@ -322,6 +348,7 @@ void eventListItem(list_t *listItem)
}
}
+/*
int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h)
{
item_t *thisItem;
@@ -343,15 +370,10 @@ int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h)
return 0;
}
+*/
-void mineExplosion(list_t *listItem, item_t *item)
+void mineExplosion(space_t *spaceItem, item_t *item)
{
- int index;
-
- index = searchListItem(listItem, item);
-
- if( index == -1 )return;
-
/*
x = ( item->x + item->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2;
y = ( item->y + item->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2;
@@ -373,12 +395,13 @@ void mineExplosion(list_t *listItem, item_t *item)
proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion);
}
- addList(listItem, item_explosion );
+ addObjectToSpace(spaceItem, item_explosion );
}
- delListItem(listItem, index, destroyItem);
+ delObjectFromSpaceWithMem(spaceItem, item, destroyItem);
}
+/*
void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
{
shot_t *thisShot;
@@ -446,6 +469,68 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
}
}
}
+*/
+
+void eventConflictShotWithItem(arena_t *arena)
+{
+ shot_t *thisShot;
+ item_t *thisItem;
+ int i, j;
+
+ if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
+ {
+ return;
+ }
+
+ for( i = 0 ; i < arena->listShot->count ; i++ )
+ {
+ bool_t isDelShot;
+
+ isDelShot = FALSE;
+ thisShot = (shot_t *)arena->listShot->list[i];
+ assert( thisShot != NULL );
+
+ listDoEmpty(listHelp);
+ getObjectFromSpace(arena->spaceItem, thisShot->x, thisShot->y, thisShot->w, thisShot->h, listHelp);
+
+ for( j = 0 ; j < listHelp->count ; j++ )
+ {
+ thisItem = (item_t *)listHelp->list[j];
+ assert( thisItem != NULL );
+
+ switch( thisItem->type )
+ {
+ case ITEM_MINE :
+ if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
+ {
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem);
+ }
+
+ mineExplosion(arena->spaceItem, thisItem);
+ }
+ break;
+
+ case ITEM_EXPLOSION :
+ case ITEM_BIG_EXPLOSION :
+ isDelShot = TRUE;
+ break;
+ }
+ }
+
+ if( isDelShot )
+ {
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_delshot_server(PROTO_SEND_ALL, NULL, thisShot);
+ }
+
+ delListItem(arena->listShot, i, destroyShot);
+ i--;
+ }
+ }
+}
static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item)
{
@@ -464,7 +549,7 @@ static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item)
{
tux_t *author;
- author = getTuxID(getCurrentArena()->listTux, item->author_id);
+ author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, item->author_id);
if( author != NULL )
{
@@ -514,14 +599,8 @@ static void tuxGiveGun(tux_t *tux, item_t *item)
}
-int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item)
+void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem)
{
- int index;
-
- index = searchListItem(listItem, item);
-
- if( index == -1 ) return -1;
-
switch( item->type )
{
case GUN_TOMMY :
@@ -531,15 +610,13 @@ int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item)
case GUN_MINE :
case GUN_BOMBBALL :
tuxGiveGun(tux, item);
- delListItem(listItem, index, destroyItem);
- return index;
+ delObjectFromSpace(spaceItem, item);
break;
case ITEM_MINE :
if( tux->bonus != BONUS_GHOST )
{
- mineExplosion(listItem, item);
- return index;
+ mineExplosion(spaceItem, item);
}
break;
@@ -548,22 +625,19 @@ int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item)
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);
- delListItem(listItem, index, destroyItem);
- return index;
- break;
- }
-
- return -1;
+ case BONUS_SPEED :
+ case BONUS_SHOT :
+ case BONUS_TELEPORT :
+ case BONUS_GHOST :
+ case BONUS_4X :
+ case BONUS_HIDDEN :
+ tuxGiveBonus(tux, item);
+ delObjectFromSpace(spaceItem, item);
+ break;
+ }
}
-void eventGiveTuxListItem(tux_t *tux, list_t *listItem)
+void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem)
{
item_t *thisItem;
int x, y, w, h;
@@ -574,7 +648,7 @@ void eventGiveTuxListItem(tux_t *tux, list_t *listItem)
return;
}
- assert( listItem != NULL );
+ assert( spaceItem != NULL );
assert( tux != NULL );
if( tux->status == TUX_STATUS_DEAD )
@@ -584,23 +658,20 @@ void eventGiveTuxListItem(tux_t *tux, list_t *listItem)
getTuxProportion(tux, &x, &y, &w, &h);
- for( i = 0 ; i < listItem->count ; i++ )
+ listDoEmpty(listHelp);
+ getObjectFromSpace(spaceItem, x, y, w, h, listHelp);
+
+ for( i = 0 ; i < listHelp->count ; i++ )
{
- thisItem = (item_t *)listItem->list[i];
+ thisItem = (item_t *)listHelp->list[i];
assert( thisItem != NULL );
- if( conflictSpace(x, y, w, h, thisItem->x, thisItem->y, thisItem->w, thisItem->h) )
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
- proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem);
- }
-
- if( eventGiveTuxItem(tux, listItem, thisItem) >= 0 )
- {
- i--;
- }
+ proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem);
}
+
+ eventGiveTuxItem(tux, thisItem, spaceItem);
}
}
diff --git a/src/language.c b/src/language.c
index d1b20e8..06cb9c1 100644
--- a/src/language.c
+++ b/src/language.c
@@ -1,4 +1,3 @@
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -42,6 +41,7 @@ int initLanguage()
char *head;
sprintf(path, "%s/lang.conf", getHomeDirector());
+ printf("open %s\n", path);
languageTypeFile = loadTextFile(path);
if( languageTypeFile == NULL )
diff --git a/src/list.c b/src/list.c
index 56f7e17..27b0ed8 100755
--- a/src/list.c
+++ b/src/list.c
@@ -168,6 +168,11 @@ void delListItem(list_t *p, int n, void *f)
delList(p, n);
}
+void listDoEmpty(list_t *p)
+{
+ p->count = 0;
+}
+
void destroyList(list_t *p)
{
assert( p != NULL );
diff --git a/src/main.c b/src/main.c
index 7e98938..4f9774c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,6 +21,8 @@
static int my_argc;
static char **my_argv;
+list_t *listHelp;
+
char* getParam(char *s)
{
int i;
@@ -100,11 +102,16 @@ void accessExistFile(const char *s)
int main(int argc, char *argv[])
{
+ listHelp = newList();
+
srand( (unsigned) time(NULL) );
my_argc = argc;
my_argv = argv;
-
+/*
+ test_space();
+ exit(0);
+*/
#ifndef PUBLIC_SERVER
startGame();
#endif
diff --git a/src/modules.c b/src/modules.c
index 6ba3234..bf7eec6 100755
--- a/src/modules.c
+++ b/src/modules.c
@@ -38,7 +38,7 @@ static export_fce_t export_fce =
.fce_getNetTypeGame = getNetTypeGame,
.fce_getTuxProportion = getTuxProportion,
.fce_setTuxProportion = setTuxProportion,
- .fce_getTuxID = getTuxID,
+ //.fce_getTuxID = getTuxID,
.fce_getCurrentArena = getCurrentArena,
.fce_conflictSpace = conflictSpace,
@@ -170,7 +170,7 @@ void cmdModule(char *s)
#ifndef PUBLIC_SERVER
-void drawModule()
+void drawModule(int x, int y, int w, int h)
{
int i;
@@ -178,7 +178,7 @@ void drawModule()
{
module_t *this;
this = (module_t *)listModule->list[i];
- this->fce_draw();
+ this->fce_draw(x, y, w, h);
}
}
diff --git a/src/proto.c b/src/proto.c
index c9aa408..062693e 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -58,7 +58,7 @@ static void proto_send(int type, client_t *client, char *msg)
}
else
{
- sendAllClientSeesTux(msg, getServerTux());
+ sendAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT));
}
break;
default :
@@ -85,6 +85,16 @@ static void proto_check(int type, client_t *client, char *msg, int id)
assert( client != NULL );
addMsgAllClientBut(msg, client, id);
break;
+ case PROTO_SEND_ALL_SEES_TUX :
+ if( client != NULL )
+ {
+ addMsgAllClientSeesTux(msg, client->tux, id);
+ }
+ else
+ {
+ addMsgAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), id);
+ }
+ break;
default :
assert( ! "Premenna type ma zlu hodnotu !" );
break;
@@ -159,7 +169,7 @@ void proto_recv_hello_server(client_t *client, char *msg)
client->tux = newTux();
client->tux->control = TUX_CONTROL_NET;
- addList(getCurrentArena()->listTux, client->tux);
+ addObjectToSpace(getCurrentArena()->spaceTux, client->tux);
if( strlen(name) > STR_NAME_SIZE-1 )
{
@@ -179,7 +189,7 @@ void proto_send_status_server(int type, client_t *client)
"maxclients: %d\n"
"uptime: %d\n"
"arena: %s\n",
- TUXANCI_NG_VERSION, getCurrentArena()->listTux->count,
+ TUXANCI_NG_VERSION, getCurrentArena()->spaceTux->list->count,
getServerMaxClients(), (unsigned int)getUpdateServer(),
getArenaNetName( getChoiceArenaId() ) );
@@ -306,10 +316,11 @@ void proto_recv_init_client(char *msg)
tux->x = x;
tux->y = y;
tux->control = TUX_CONTROL_KEYBOARD_RIGHT;
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT);
getSettingNameRight(tux->name);
- addList(getCurrentArena()->listTux, tux);
+ addObjectToSpace(getCurrentArena()->spaceTux, tux);
}
#endif
@@ -337,7 +348,7 @@ void proto_recv_event_client(char *msg)
sscanf(msg, "%s %d %d", cmd, &id, &action);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux != NULL )
{
@@ -393,6 +404,8 @@ void proto_send_newtux_server(int type, client_t *client, tux_t *tux)
y = tux->y;
}
+ getTuxProportion(tux, &x, &y, NULL, NULL);
+
sprintf(msg, "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],
@@ -426,7 +439,7 @@ void proto_recv_newtux_client(char *msg)
cmd, &id, &x, &y, &status, &position, &frame, &score, name,
&myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux == NULL )
{
@@ -436,12 +449,11 @@ void proto_recv_newtux_client(char *msg)
tux = newTux();
tux->control = TUX_CONTROL_NET;
- addList(getCurrentArena()->listTux, tux);
+ addObjectToSpace(getCurrentArena()->spaceTux, tux);
}
replaceTuxID(tux, id);
- tux->x = x;
- tux->y = y;
+ moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y);
tux->status = status;
tux->position = position;
tux->frame = frame;
@@ -485,7 +497,7 @@ void proto_recv_kill_client(char *msg)
sscanf(msg, "%s %d", cmd, &id);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux != NULL )
{
@@ -518,7 +530,7 @@ void proto_recv_score_client(char *msg)
sscanf(msg, "%s %d %d", cmd, &id, &score);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux != NULL )
{
@@ -557,18 +569,18 @@ void proto_recv_deltux_client(char *msg)
sscanf(msg, "%s %d", cmd, &id);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux != NULL )
{
char term_msg[STR_SIZE];
- int index;
+ //int index;
sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
appendTextInTerm(term_msg);
- index = searchListItem(getCurrentArena()->listTux, tux);
- delListItem(getCurrentArena()->listTux, index, destroyTux);
+ //index = searchListItem(getCurrentArena()->listTux, tux);
+ delObjectFromSpaceWithMem(getCurrentArena()->spaceTux, tux, destroyTux);
}
}
@@ -610,7 +622,7 @@ void proto_recv_additem_client(char *msg)
proto_send_check_client(check_id);
- if( ( item = getItemID(getCurrentArena()->listItem, id) ) != NULL )
+ if( ( item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id) ) != NULL )
{
return;
}
@@ -627,7 +639,7 @@ void proto_recv_additem_client(char *msg)
item->count = count;
item->frame = frame;
- addList(getCurrentArena()->listItem, item);
+ addObjectToSpace(getCurrentArena()->spaceItem, item);
}
#endif
@@ -674,8 +686,8 @@ void proto_recv_item_client(char *msg)
arena = getCurrentArena();
- item = getItemID(arena->listItem, item_id);
- tux = getTuxID(arena->listTux, tux_id);
+ item = getObjectFromSpaceWithID(arena->spaceItem, item_id);
+ tux = getObjectFromSpaceWithID(arena->spaceTux, tux_id);
if( item == NULL)
{
@@ -684,11 +696,11 @@ void proto_recv_item_client(char *msg)
if( tux != NULL )
{
- eventGiveTuxItem(tux, arena->listItem, item);
+ eventGiveTuxItem(tux, item, arena->spaceItem);
}
else
{
- mineExplosion(arena->listItem, item);
+ mineExplosion(arena->spaceItem, item);
}
}
diff --git a/src/screen_world.c b/src/screen_world.c
index de2d591..077153f 100644
--- a/src/screen_world.c
+++ b/src/screen_world.c
@@ -43,6 +43,9 @@ static my_time_t lastServerLag;
static bool_t isScreenWorldInit = FALSE;
static bool_t isEndWorld;
+static tux_t *tuxWithControlRightKeyboard;
+static tux_t *tuxWithControlLeftKeyboard;
+
bool_t isScreenWorldInicialized()
{
return isScreenWorldInit;
@@ -65,7 +68,6 @@ void setWorldArena(int id)
{
arena = getArena(id);
playMusic(arena->music, MUSIC_GROUP_USER);
- setCurrentArena(arena);
}
void setMaxCountRound(int n)
@@ -118,29 +120,32 @@ void prepareArena()
{
case NET_GAME_TYPE_NONE :
setWorldArena( getChoiceArenaId() );
- addNewItem(arena->listItem, ID_UNKNOWN);
+ addNewItem(arena->spaceItem, ID_UNKNOWN);
getSettingCountRound(&max_count);
tux = newTux();
tux->control = TUX_CONTROL_KEYBOARD_RIGHT;
+ tuxWithControlRightKeyboard = tux;
getSettingNameRight(tux->name);
- addList(arena->listTux, tux);
+ addObjectToSpace(arena->spaceTux, tux);
tux = newTux();
tux->control = TUX_CONTROL_KEYBOARD_LEFT;
+ tuxWithControlLeftKeyboard = tux;
getSettingNameLeft(tux->name);
- addList(arena->listTux, tux);
+ addObjectToSpace(arena->spaceTux, tux);
break;
case NET_GAME_TYPE_SERVER :
setWorldArena( getChoiceArenaId() );
- addNewItem(arena->listItem, ID_UNKNOWN);
+ addNewItem(arena->spaceItem, ID_UNKNOWN);
getSettingCountRound(&max_count);
tux = newTux();
tux->control = TUX_CONTROL_KEYBOARD_RIGHT;
+ tuxWithControlRightKeyboard = tux;
getSettingNameRight(tux->name);
- addList(arena->listTux, tux);
+ addObjectToSpace(arena->spaceTux, tux);
break;
case NET_GAME_TYPE_CLIENT :
@@ -172,10 +177,9 @@ void drawWorld()
if( arena != NULL )
{
drawArena(arena);
- drawPanel(arena->listTux);
+ drawPanel(arena->spaceTux->list);
}
- drawModule();
drawTerm();
}
@@ -393,25 +397,32 @@ static void eventEnd()
tux_t* getControlTux(int control_type)
{
- arena_t *arena;
- tux_t *thisTux;
- int i;
-
- arena = getCurrentArena();
-
- for( i = 0 ; i < arena->listTux->count ; i++ )
+ switch(control_type)
{
- thisTux = (tux_t *)(arena->listTux->list[i]);
-
- if( thisTux->control == control_type )
- {
- return thisTux;
- }
+ case TUX_CONTROL_KEYBOARD_RIGHT :
+ return tuxWithControlRightKeyboard;
+ break;
+ case TUX_CONTROL_KEYBOARD_LEFT :
+ return tuxWithControlLeftKeyboard;
+ break;
}
return NULL;
}
+void setControlTux(tux_t *tux, int control_type)
+{
+ switch(control_type)
+ {
+ case TUX_CONTROL_KEYBOARD_RIGHT :
+ tuxWithControlRightKeyboard = tux;
+ break;
+ case TUX_CONTROL_KEYBOARD_LEFT :
+ tuxWithControlLeftKeyboard = tux;
+ break;
+ }
+}
+
void tuxControl(tux_t *p)
{
assert( p != NULL );
@@ -479,9 +490,9 @@ static void setAnalyze()
restartAnalyze();
- for( i = 0 ; i < arena->listTux->count ; i++ )
+ for( i = 0 ; i < arena->spaceTux->list->count ; i++ )
{
- tux = (tux_t *)(arena->listTux->list[i]);
+ tux = (tux_t *)(arena->spaceTux->list->list[i]);
addAnalyze(tux->name, tux->score);
}
diff --git a/src/server.c b/src/server.c
index b9a611e..3ca0637 100644
--- a/src/server.c
+++ b/src/server.c
@@ -103,10 +103,10 @@ static void eventPeriodicSyncClient(void *p_nothink)
}
#ifndef PUBLIC_SERVER
- thisTux = (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]);
-
+ thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT);
if( isTuxSeesTux(thisClientSend->tux, thisTux) )
proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux);
+
#endif
for( j = 0 ; j < listClient->count; j++)
@@ -261,7 +261,7 @@ client_t* newSdlUdpClient(sock_sdl_udp_t *sock_sdl_udp)
void destroyClient(client_t *p)
{
- int index;
+// int index;
assert( p != NULL );
@@ -282,8 +282,11 @@ void destroyClient(client_t *p)
#ifdef PUBLIC_SERVER
addPlayerInHighScore(p->tux->name, p->tux->score);
#endif
+/*
index = searchListItem(getCurrentArena()->listTux, p->tux);
delListItem(getCurrentArena()->listTux, index, destroyTux);
+*/
+ delObjectFromSpaceWithMem(getCurrentArena()->spaceTux, p->tux, destroyTux);
}
free(p);
@@ -413,9 +416,49 @@ void addMsgAllClient(char *msg, int id)
addMsgAllClientBut(msg, NULL, id);
}
+void addMsgAllClientSeesTux(char *msg, tux_t *tux, int id)
+{
+ int i;
+
+ assert( msg != NULL );
+
+ for( i = 0 ; i < listClient->count ; i++ )
+ {
+ client_t *thisClient;
+ tux_t *thisTux;
+
+ thisClient = (client_t *)listClient->list[i];
+ thisTux = (tux_t *)thisClient->tux;
+
+ if( tux != thisTux &&
+ isTuxSeesTux(thisTux, tux) )
+ {
+ addMsgClient(thisClient, msg, id);
+ }
+ }
+}
+
tux_t *getServerTux()
{
- return (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]);
+ return NULL;
+}
+
+client_t *getClientFromTux(tux_t *tux)
+{
+ client_t *thisClient;
+ int i;
+
+ for( i = 0 ; i < listClient->count; i++)
+ {
+ thisClient = (client_t *) listClient->list[i];
+
+ if( thisClient->tux == tux )
+ {
+ return thisClient;
+ }
+ }
+
+ return NULL;
}
void sendInfoCreateClient(client_t *client)
@@ -430,8 +473,7 @@ void sendInfoCreateClient(client_t *client)
proto_send_init_server(PROTO_SEND_ONE, client, client);
#ifndef PUBLIC_SERVER
- proto_send_newtux_server(PROTO_SEND_ONE, client,
- (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]) );
+ proto_send_newtux_server(PROTO_SEND_ONE, client, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT) );
#endif
for( i = 0 ; i < listClient->count; i++)
@@ -446,9 +488,9 @@ void sendInfoCreateClient(client_t *client)
}
}
- for( i = 0 ; i < getCurrentArena()->listItem->count; i++)
+ for( i = 0 ; i < getCurrentArena()->spaceItem->list->count; i++)
{
- thisItem = (item_t *) getCurrentArena()->listItem->list[i];
+ thisItem = (item_t *) getCurrentArena()->spaceItem->list->list[i];
proto_send_additem_server(PROTO_SEND_ONE, client, thisItem);
}
}
diff --git a/src/shot.c b/src/shot.c
index 2db8424..65d2147 100644
--- a/src/shot.c
+++ b/src/shot.c
@@ -72,7 +72,7 @@ shot_t* newShot(int x,int y, int px, int py, int gun, int author_id)
new->position = POSITION_UNKNOWN;
- author = getTuxID(getCurrentArena()->listTux, author_id);
+ author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id);
if( author != NULL )
{
@@ -311,6 +311,86 @@ void eventMoveListShot(list_t *listShot)
}
}
+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) );
+}
+
+
+void checkShotIsInTuxScreen(arena_t *arena)
+{
+ return;
+/*
+ int screen_x, screen_y;
+ shot_t *thisShot;
+ tux_t *thisTux;
+ int speed;
+ int i, j;
+
+ if( getNetTypeGame() != NET_GAME_TYPE_SERVER )
+ {
+ return;
+ }
+
+ for( i = 0 ; i < arena->listTux->count ; i++ )
+ {
+ thisTux = (tux_t *)arena->listTux->list[i];
+
+ if( thisTux->control != TUX_CONTROL_NET )
+ {
+ continue;
+ }
+
+ getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y);
+
+ for( j = 0 ; j < arena->listShot->count ; j++ )
+ {
+ thisShot = (shot_t *)arena->listShot->list[j];
+
+ speed = getSppedShot(thisShot);
+
+ if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
+ screen_x-speed, screen_y, speed, WINDOW_SIZE_Y) )
+ {
+ client_t *thisClient;
+ thisClient = getClientFromTux(thisTux);
+ proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ }
+
+ if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
+ screen_x+WINDOW_SIZE_X, screen_y, speed, WINDOW_SIZE_Y) )
+ {
+ client_t *thisClient;
+ thisClient = getClientFromTux(thisTux);
+ proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ }
+
+ if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
+ screen_x, screen_y-speed, WINDOW_SIZE_X, speed) )
+ {
+ client_t *thisClient;
+ thisClient = getClientFromTux(thisTux);
+ proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ }
+
+ if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
+ screen_x, screen_y+WINDOW_SIZE_Y, WINDOW_SIZE_X, speed) )
+ {
+ client_t *thisClient;
+ thisClient = getClientFromTux(thisTux);
+ proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ }
+ }
+ }
+*/
+}
+
/*
static int getSppedShot(shot_t *shot)
{
diff --git a/src/space.c b/src/space.c
new file mode 100644
index 0000000..ce662f0
--- /dev/null
+++ b/src/space.c
@@ -0,0 +1,370 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "space.h"
+
+#ifdef DEBUG_SPACE
+
+typedef struct recv_struct
+{
+ int id;
+ int x, y;
+ int w, h;
+} recv_t;
+
+recv_t* newRecv(int x , int y, int w, int h)
+{
+ static int last_id = 0;
+
+ recv_t *new;
+
+ new = malloc( sizeof(recv_t) );
+ memset(new, 0, sizeof(recv_t));
+
+ new->id = ++last_id;
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+
+ return new;
+}
+
+void getStatus(void *p, int *id, int *x, int *y, int *w, int *h)
+{
+ recv_t *recv;
+
+ recv = p;
+
+ *id = recv->id;
+ *x = recv->x;
+ *y = recv->y;
+ *w = recv->w;
+ *h = recv->h;
+}
+
+void setStatus(void *p, int x, int y, int w, int h)
+{
+ recv_t *recv;
+
+ recv = p;
+
+ recv->x = x;
+ recv->y = y;
+ recv->w = w;
+ recv->h = h;
+ recv->x = x;
+}
+
+void destroyRecv(recv_t *p)
+{
+ free(p);
+}
+
+#endif
+
+static int my_conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2)
+{
+ return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1);
+}
+
+space_t *newSpace(int w, int h, int segW, int segH,
+ void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h),
+ void (*setStatus)(void *p, int x, int y, int w, int h))
+{
+ space_t *new;
+ int i, j;
+
+ 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->list = newList();
+
+ new->area = malloc( new->w * sizeof(list_t **) );
+
+ for( i = 0 ; i < new->w ; i++ )
+ {
+ new->area[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();
+ }
+ }
+
+ return new;
+}
+
+static void getSegment(space_t *p, int x, int y, int w, int h,
+ int *segX, int *segY, int *segW, int *segH)
+{
+ *segX = x / p->segW;
+ *segY = y / p->segH;
+ *segW = ( (x+w) / p->segW + 1 ) - *segX;
+ *segH = ( (y+h) / p->segH + 1 ) - *segY;
+}
+
+void addObjectToSpace(space_t *p, void *item)
+{
+ 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);
+
+ for( i = segY ; i < segY + segH ; i++ )
+ {
+ for( j = segX ; j < segX + segW ; j++ )
+ {
+ addList(p->area[j][i], item);
+ }
+ }
+
+ addList(p->list, item);
+}
+
+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;
+
+ for( k = 0 ; k < p->area[j][i]->count ; k++ )
+ {
+ this = p->area[j][i]->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 *p, int id)
+{
+ int this_id, x, y, w, h;
+ void *this;
+ int i;
+
+ for( i = 0 ; i < p->list->count ; i++ )
+ {
+ this = p->list->list[i];
+ assert( this != NULL );
+
+ p->getStatus(this, &this_id, &x, &y, &w, &h);
+
+ if( this_id == id )
+ {
+ return this;
+ }
+ }
+
+ return NULL;
+}
+
+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;
+
+ 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( k = 0 ; k < p->area[j][i]->count ; k++ )
+ {
+ this = p->area[j][i]->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;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+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++ )
+ {
+ index = searchListItem(p->area[j][i], item);
+ assert( index != -1 );
+ delList(p->area[j][i], index);
+ }
+ }
+
+ index = searchListItem(p->list, item);
+ assert( index != -1 );
+ delList(p->list, index);
+}
+
+void delObjectFromSpaceWithMem(space_t *p, void *item, void *f)
+{
+ void (*fce)(void *param);
+
+ fce = f;
+
+ delObjectFromSpace(p, item);
+ fce(item);
+}
+
+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);
+/*
+ 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);
+}
+
+void printSpace(space_t *p)
+{
+ int i, j;
+
+ printf("print space : \n");
+
+ for( i = 0 ; i < p->h ; i++ )
+ {
+ for( j = 0 ; j < p->w ; j++ )
+ {
+ printf("%3d ", p->area[j][i]->count);
+ }
+
+ putchar('\n');
+ }
+}
+
+void destroySpace(space_t *p, void *f)
+{
+ void (*fce)(void *param);
+ int j, i;
+
+ fce = f;
+
+ //getObjectFromSpace(p, 0, 0, p->w * p->segW - 1 , p->h * p->segH - 1, list);
+
+ destroyListItem(p->list, fce);
+
+ for( i = 0 ; i < p->h ; i++ )
+ {
+ for( j = 0 ; j < p->w ; j++ )
+ {
+ destroyList(p->area[j][i]);
+ }
+ }
+
+ for( i = 0 ; i < p->w ; i++ )
+ {
+ free(p->area[i]);
+ }
+
+ free(p->area);
+ free(p);
+}
+
+#ifdef DEBUG_SPACE
+
+void test_space()
+{
+ space_t *space;
+ list_t *list;
+ int i, j;
+
+ space = newSpace(5000, 2500, 320, 240, getStatus, setStatus);
+
+ for( i = 1 ; i < 16 ; i++ )
+ for( j = 1 ; j < 16 ; j++ )
+ {
+ recv_t *this;
+
+ this = newRecv(j*160, i*120, 32, 32);
+ //addToSpace(space, newRecv(j*550, i*550, 1, 1) );
+ addObjectToSpace(space, this );
+ delObjectFromSpaceWithMem(space, this, destroyRecv);
+ }
+
+ list = newList();
+ getObjectFromSpace(space, 640, 480, 800 , 600, list);
+
+ printf("list->count = %d\n", list->count);
+
+ for( i = 0 ; i < list->count ; i++ )
+ {
+ recv_t *recv;
+ recv = list->list[i];
+
+ printf("%3d %3d %3d %3d\n", recv->x, recv->y, recv->w, recv->h);
+ }
+
+ destroyList(list);
+
+ printSpace(space);
+
+ destroySpace(space, destroyRecv);
+}
+
+#endif
+
diff --git a/src/tux.c b/src/tux.c
index 8c89207..a4153c6 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -221,6 +221,7 @@ void drawListTux(list_t *listTux)
#endif
+/*
tux_t* getTuxID(list_t *listTux, int id)
{
tux_t *thisTux;
@@ -241,6 +242,7 @@ tux_t* getTuxID(list_t *listTux, int id)
return NULL;
}
+*/
void replaceTuxID(tux_t *tux, int id)
{
@@ -259,10 +261,11 @@ int isTuxSeesTux(tux_t *tux, tux_t *thisTux)
getCenterScreen(&screen_x, &screen_y, tux->x, tux->y);
- return conflictSpace(screen_x, screen_y,
- WINDOW_SIZE_X, WINDOW_SIZE_Y, thisTux_x, thisTux_y, thisTux_w, thisTux_h);
+ 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);
}
+/*
tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h)
{
tux_t *thisTux;
@@ -286,7 +289,9 @@ tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h)
return NULL;
}
+*/
+/*
int isConflictTuxWithListTux(tux_t *tux, list_t *listTux)
{
tux_t *thisTux;
@@ -320,6 +325,7 @@ int isConflictTuxWithListTux(tux_t *tux, list_t *listTux)
return 0;
}
+*/
static void timer_spawnTux(void *p)
{
@@ -332,16 +338,16 @@ static void timer_spawnTux(void *p)
free(p);
arena = getCurrentArena();
- tux = getTuxID(arena->listTux, id);
+ tux = getObjectFromSpaceWithID(arena->spaceTux, id);
if( tux == NULL )return;
tux->status = TUX_STATUS_ALIVE;
findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT);
- setTuxProportion(tux, x, y);
+ moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y);
tux->gun = GUN_SIMPLE;
- addNewItem(arena->listItem, ID_UNKNOWN);
+ addNewItem(arena->spaceItem, ID_UNKNOWN);
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
@@ -357,7 +363,7 @@ static void timer_tuxCanShot(void *p)
id = * ((int *)p);
free(p);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux == NULL )return;
@@ -372,7 +378,7 @@ static void timer_tuxCanSwitchGun(void *p)
id = * ((int *)p);
free(p);
- tux = getTuxID(getCurrentArena()->listTux, id);
+ tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux == NULL )return;
@@ -425,7 +431,7 @@ static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot)
{
tux_t *author;
- author = getTuxID(getCurrentArena()->listTux, shot->author_id);
+ author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, shot->author_id);
if( author != NULL )
{
@@ -477,7 +483,7 @@ static void bombBallExplosion(shot_t *shot)
y = ( shot->y + shot->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2;
item = newItem(x, y, ITEM_BIG_EXPLOSION, shot->author_id );
- addList(getCurrentArena()->listItem, item );
+ addObjectToSpace(getCurrentArena()->spaceItem, item );
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
@@ -486,6 +492,7 @@ static void bombBallExplosion(shot_t *shot)
}
}
+/*
void eventConflictTuxWithShot(list_t *listTux, list_t *listShot)
{
shot_t *thisShot;
@@ -543,6 +550,66 @@ void eventConflictTuxWithShot(list_t *listTux, list_t *listShot)
}
}
}
+*/
+
+void eventConflictTuxWithShot(arena_t *arena)
+{
+ shot_t *thisShot;
+ tux_t *thisTux;
+ int i, j;
+
+ for( i = 0 ; i < arena->listShot->count ; i++ )
+ {
+ thisShot = (shot_t *)arena->listShot->list[i];
+ assert( thisShot != NULL );
+
+ listDoEmpty(listHelp);
+ getObjectFromSpace(arena->spaceTux, thisShot->x, thisShot->y,
+ thisShot->w, thisShot->h, listHelp);
+
+ for( j = 0 ; j < listHelp->count ; j++ )
+ {
+ thisTux = listHelp->list[j];
+
+ if( thisTux->status == TUX_STATUS_ALIVE )
+ {
+ if( thisShot->author_id == thisTux->id &&
+ thisShot->isCanKillAuthor == FALSE )
+ {
+ continue;
+ }
+
+ if( thisTux->bonus == BONUS_TELEPORT )
+ {
+ tuxTeleport(thisTux);
+ continue;
+ }
+
+ if( thisShot->gun == GUN_BOMBBALL )
+ {
+ if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
+ {
+ bombBallExplosion(thisShot);
+ delListItem(arena->listShot, i, destroyShot);
+ i--;
+ }
+
+ continue;
+ }
+
+ if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
+ {
+ eventTuxIsDeadWIthShot(thisTux, thisShot);
+ }
+ }
+
+ delListItem(arena->listShot, i, destroyShot);
+ i--;
+
+ continue;
+ }
+ }
+}
/*
void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport)
@@ -576,6 +643,7 @@ void moveTux(tux_t *tux, int n)
{
int px, py;
int zal_x, zal_y;
+ int new_x, new_y;
int x, y, w, h;
arena_t *arena;
@@ -628,36 +696,46 @@ void moveTux(tux_t *tux, int n)
return;
}
+ getTuxProportion(tux, &zal_x, &zal_y, &w, &h);
+
getCourse(tux->position, &px, &py);
- zal_x = tux->x;
- zal_y = tux->y;
+ new_x = zal_x;
+ new_y = zal_y;
- tux->x += px * TUX_STEP;
- tux->y += py * TUX_STEP;
+ new_x += px * TUX_STEP;
+ new_y += py * TUX_STEP;
if( tux->bonus == BONUS_SPEED )
{
- tux->x += px * TUX_STEP;
- tux->y += py * TUX_STEP;
+ new_x += px * TUX_STEP;
+ new_y += py * TUX_STEP;
}
-
- getTuxProportion(tux, &x, &y, &w, &h);
-
+/*
+ setTuxProportion(tux, new_x, new_y);
if( tux->bonus != BONUS_GHOST && (
- isConflictTuxWithListTux(tux, arena->listTux) ||
+ isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) ||
isConflictModule(x, y, w, h) ) )
{
- tux->x = zal_x;
- tux->y = zal_y;
+ setTuxProportion(tux, zal_x, zal_y);
+ return;
}
- else
+*/
+
+ if( tux->bonus != BONUS_GHOST && (
+ /*isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) ||*/
+ isConflictModule(new_x, new_y, w, h) ) )
{
- eventGiveTuxListItem(tux, getCurrentArena()->listItem);
- tux->frame++;
- if( tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME ) tux->frame = 0;
+ 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;
}
void switchTuxGun(tux_t *tux)
@@ -817,7 +895,7 @@ static void eventBonus(tux_t *tux)
tux->bonus = BONUS_NONE;
- if( isConflictTuxWithListTux(tux, getCurrentArena()->listTux) ||
+ if( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */
isConflictModule(x, y, w, h) )
{
tux->bonus = BONUS_GHOST;
@@ -859,7 +937,7 @@ void eventListTux(list_t *listTux)
#endif
pickUpGun(thisTux);
eventBonus(thisTux);
- eventGiveTuxListItem(thisTux, arena->listItem);
+ eventGiveTuxListItem(thisTux, arena->spaceItem);
}
}
@@ -881,6 +959,23 @@ void setTuxProportion(tux_t *tux, int x, int y)
tux->y = y + TUX_WIDTH / 2;
}
+void getStatusTux(void *p, int *id, int *x,int *y, int *w, int *h)
+{
+ tux_t *tux;
+
+ tux = p;
+ *id = tux->id;
+ getTuxProportion(tux, x, y, w, h);
+}
+
+void setStatusTux(void *p, int x, int y, int w, int h)
+{
+ tux_t *tux;
+
+ tux = p;
+ setTuxProportion(tux, x, y);
+}
+
void destroyTux(tux_t *tux)
{
assert( tux != NULL );