summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base/arena.c7
-rw-r--r--src/base/fake_audio.c89
-rw-r--r--src/base/idManager.c5
-rw-r--r--src/base/index.c227
-rw-r--r--src/base/index.h15
-rw-r--r--src/base/item.c2
-rw-r--r--src/base/proto.c13
-rw-r--r--src/base/space.c66
-rw-r--r--src/base/space.h3
-rw-r--r--src/base/tux.c24
-rw-r--r--src/base/tux.h1
-rw-r--r--src/base/udp_server.c2
-rwxr-xr-xsrc/client/interface.c7
-rw-r--r--src/client/panel.c112
-rw-r--r--src/client/panel.h2
-rwxr-xr-xsrc/modules/modAI.c25
-rwxr-xr-xsrc/modules/modTeleport.c18
-rw-r--r--src/screen/screen_world.c18
18 files changed, 322 insertions, 314 deletions
diff --git a/src/base/arena.c b/src/base/arena.c
index 437f7a6..f7e917d 100644
--- a/src/base/arena.c
+++ b/src/base/arena.c
@@ -223,6 +223,11 @@ void drawArena(arena_t *arena)
#endif
+static void action_tux(space_t *space, tux_t *tux, void *p)
+{
+ eventTux(tux);
+}
+
void eventArena(arena_t *arena)
{
int i;
@@ -240,7 +245,7 @@ void eventArena(arena_t *arena)
eventListItem(arena->spaceItem);
- eventListTux(arena->spaceTux->list);
+ actionSpace(arena->spaceTux, action_tux, NULL);
eventTimer(arena->listTimer);
}
diff --git a/src/base/fake_audio.c b/src/base/fake_audio.c
deleted file mode 100644
index 2149c86..0000000
--- a/src/base/fake_audio.c
+++ /dev/null
@@ -1,89 +0,0 @@
-
-#include "base/main.h"
-#include "base/fake_audio.h"
-
-bool_t isAudioInicialized()
-{
- return TRUE;
-}
-
-void initAudio()
-{
-}
-
-void quitAudio()
-{
-}
-
-bool_t isSoundInicialized()
-{
- return TRUE;
-}
-
-void initSound()
-{
-}
-
-void addSound(char *file, char *name, int group)
-{
-}
-
-void playSound(char *name, int group)
-{
-}
-
-void setSoundActive(bool_t n)
-{
-}
-
-bool_t isSoundActive()
-{
- return FALSE;
-}
-
-void quitSound()
-{
-}
-
-bool_t isMusicInicialized()
-{
- return FALSE;
-}
-
-void initMusic()
-{
-}
-
-void addMusic(char *file, char *name, int group)
-{
-}
-
-void stopMusic()
-{
-}
-
-void playMusic(char *name, int group)
-{
-}
-
-void setMusicActive(bool_t n)
-{
-}
-
-bool_t isMusicActive()
-{
- return FALSE;
-}
-
-char* getCurrentMusic()
-{
- return "no_sound";
-}
-
-void delAllMusicInGroup(int group)
-{
-}
-
-void quitMusic()
-{
-}
diff --git a/src/base/idManager.c b/src/base/idManager.c
index b4217ae..63667bf 100644
--- a/src/base/idManager.c
+++ b/src/base/idManager.c
@@ -74,10 +74,11 @@ static int findNewID()
}
do{
- ret = random() % MAX_ID;
-
+ ret = ( random() % (listID->count + 8 ) ) + 1;
}while( isRegisterID(ret) != -1 );
+ //printf("new ID %d\n", ret);
+
return ret;
}
diff --git a/src/base/index.c b/src/base/index.c
index b7ee929..77b0eac 100644
--- a/src/base/index.c
+++ b/src/base/index.c
@@ -8,81 +8,96 @@
#include "list.h"
#include "index.h"
-static int* index_newInt(int x)
+#define DEBUG_INDEX
+
+static index_item_t* newIndexItem(int key, void *data)
{
- int *new;
- new = malloc( sizeof(int) );
- *new = x;
+ index_item_t *new;
+
+ new = malloc( sizeof(index_item_t) );
+ new->key = key;
+ new->data = data;
+
return new;
}
-#ifdef CHECK_INDEX
-static void printIndex(list_t *list)
+#ifdef DEBUG_INDEX
+static void printIndexItem(index_item_t *p)
+{
+ printf("key = %d data = %p\n", p->key, p->data);
+}
+
+static void printListIndexItem(list_t *list)
{
int i;
- printf("printIndex\n");
+ printf("list :\n");
+ printf("------------------\n");
for( i = 0 ; i < list->count ; i++ )
{
- int thisIndex;
+ index_item_t *this;
- thisIndex = *(int *)list->list[i];
- printf("%d\n", thisIndex);
+ this = (index_item_t *)list->list[i];
+ printIndexItem(this);
}
}
-#endif
-#ifdef CHECK_INDEX
-static void checkIndex(list_t *list)
+static void checkList(list_t *list)
{
- int index, thisIndex;
int i;
+ int prev;
+ int this;
- //printf("check index\n");
+ //return;
if( list->count == 0 )
{
printf("nothing\n");
- return;
+ return;
}
- thisIndex = *(int *)list->list[0];
-
+ prev = ( (index_item_t *) list->list[0] )->key;
for( i = 1 ; i < list->count ; i++ )
{
- index = *(int *)list->list[i];
- //printf("check %d\n", index);
+ this = ( (index_item_t *) list->list[i] )->key;
- if( index <= thisIndex )
+ if( prev >= this )
{
- printIndex(list);
+ printListIndexItem(list);
assert( ! "error" );
}
- thisIndex = index;
+ prev = this;
}
}
#endif
+static void destroyIndexItem(index_item_t *p)
+{
+ free(p);
+}
+
list_t* newIndex()
{
return newList();
}
-int addToIndex(list_t *list, int index)
+void addToIndex(list_t *list, int key, void *data)
{
- int min, max;
- int point;
- int point_index;
+#ifdef DEBUG_INDEX
+ int count = 0;
+#endif
+
+ index_item_t *item;
+ index_item_t *this;
+ int min, max, point;
int len;
+ item = newIndexItem(key, data);
len = list->count;
- //printf("addToIndex (%p, %d)\n", list, index);
- //printIndex(list);
-
min = 0;
max = len-1;
@@ -90,42 +105,58 @@ int addToIndex(list_t *list, int index)
{
point = min + ( max - min ) / 2;
- if( max < 0 )
+#ifdef DEBUG_INDEX
+ if( ++count == len*5 )
{
- insList(list, 0, index_newInt(index));
-#ifdef CHECK_INDEX
- checkIndex(list);
+ printf("CICLIC ERROR\n");
+ printIndexItem(item);
+ printf("-------------------\n");
+ printListIndexItem(list);
+ assert( 0 );
+ }
#endif
- return 0;
+
+ if( max < 0 )
+ {
+ insList(list, 0, item);
+#ifdef DEBUG_INDEX
+ checkList(list);
+#endif
+ return;
}
- if( min >= len )
+ if( min >= len )
{
- addList(list, index_newInt(index) );
-#ifdef CHECK_INDEX
- checkIndex(list);
+ addList(list, item);
+#ifdef DEBUG_INDEX
+ checkList(list);
#endif
- return len;
+ return;
}
- point_index = *(int *)list->list[point];
+ this = (index_item_t *)list->list[point];
+/*
+ printf("min = %d max = %d point = %d len = %d offset = %d\n",
+ min, max, point, len, offset);
+
+*/
if( min > max )
{
- insList(list, point, index_newInt(index) );
-#ifdef CHECK_INDEX
- checkIndex(list);
+ insList(list, point, item);
+#ifdef DEBUG_INDEX
+ checkList(list);
#endif
- return point;
+ return;
}
- if( index > point_index )
+ if( item->key > this->key )
{
min = point + 1;
continue;
}
- if( index < point_index )
+ if( item->key < this->key )
{
max = point - 1;
continue;
@@ -133,17 +164,17 @@ int addToIndex(list_t *list, int index)
}
}
-int getFormIndex(list_t *list, int index)
+static int getOffsetFromIndex(list_t *list, int key)
{
- int point_index;
- int len;
- int min, max;
- int point;
+ index_item_t *this;
+ int min, max, point, len;
- //printf("getFormIndex %d\n", index);
- //printIndex(list);
+ len = list->count;
- len =list->count;
+ if( len == 0 )
+ {
+ return -1;
+ }
min = 0;
max = len-1;
@@ -156,21 +187,24 @@ int getFormIndex(list_t *list, int index)
{
return -1;
}
-
- point_index = *(int *)list->list[point];
-
- if( point_index == index )
+
+ this = (index_item_t *)list->list[point];
+/*
+ printf("min = %d max = %d point = %d len = %d offset = %d\n",
+ min, max, point, len, offset);
+*/
+ if( key == this->key )
{
return point;
}
- if( index > point_index )
+ if( key > this->key )
{
min = point + 1;
continue;
}
- if( index < point_index )
+ if( key < this->key )
{
max = point - 1;
continue;
@@ -178,19 +212,78 @@ int getFormIndex(list_t *list, int index)
}
}
-void delFromIndex(list_t *list, int index)
+void* getFromIndex(list_t *list, int key)
{
int offset;
- offset = getFormIndex(list, index);
- assert( offset != -1 );
+ offset = getOffsetFromIndex(list, key);
+
+ if( offset != -1 )
+ {
+ index_item_t *this;
+
+ this = list->list[offset];
+ return this->data;
+ }
- delListItem(list, offset, free);
+ return NULL;
+}
+
+void delFromIndex(list_t *list, int key)
+{
+ int offset;
+
+ offset = getOffsetFromIndex(list, key);
+
+ if( offset != -1 )
+ {
+ delListItem(list, offset, destroyIndexItem);
+ }
+}
+
+void delFromIndexWithObject(list_t *list, int key, void *f)
+{
+ int offset;
+
+ offset = getOffsetFromIndex(list, key);
+
+ if( offset != -1 )
+ {
+ index_item_t *this;
+ void (*fce)(void *p);
+
+ this = list->list[offset];
+
+ fce = f;
+ fce(this);
+
+ delListItem(list, offset, destroyIndexItem);
+ }
+}
+
+void actionIndexWithObject(list_t *list, void *f)
+{
+ int i;
+
+ for( i = 0 ; i < list->count ; i++)
+ {
+ index_item_t *this;
+ void (*fce)(void *p);
+
+ this = list->list[i];
+
+ fce = f;
+ fce(this);
+ }
}
void destroyIndex(list_t *list)
{
- assert( list != NULL);
+ destroyListItem(list, destroyIndexItem);
+}
- destroyListItem(list, free);
+void destroyIndexWithObject(list_t *list, void *f)
+{
+ actionIndexWithObject(list, f);
+ destroyListItem(list, destroyIndexItem);
}
diff --git a/src/base/index.h b/src/base/index.h
index 3799aa3..0dd544c 100644
--- a/src/base/index.h
+++ b/src/base/index.h
@@ -6,10 +6,19 @@
#include "main.h"
#include "list.h"
+typedef struct index_item_struct
+{
+ int key;
+ void *data;
+} index_item_t;
+
extern list_t* newIndex();
-extern int addToIndex(list_t *list, int index);
-extern int getFormIndex(list_t *list, int index);
-extern void delFromIndex(list_t *list, int index);
+extern void addToIndex(list_t *list, int key, void *data);
+extern void* getFromIndex(list_t *list, int key);
+extern void delFromIndex(list_t *list, int key);
+extern void delFromIndexWithObject(list_t *list, int key, void *f);
+extern void actionIndexWithObject(list_t *list, void *f);
extern void destroyIndex(list_t *list);
+extern void destroyIndexWithObject(list_t *list, void *f);
#endif
diff --git a/src/base/item.c b/src/base/item.c
index 0eb70c3..bd61728 100644
--- a/src/base/item.c
+++ b/src/base/item.c
@@ -171,7 +171,7 @@ void addNewItem(space_t *spaceItem, int author_id)
int type;
#ifdef PUBLIC_SERVER
- if( spaceItem->list->count >= atoi( getSetting("MAX_ITEM", "--max-item", "100") ) )
+ if( getSpaceCount(spaceItem) >= atoi( getSetting("MAX_ITEM", "--max-item", "100") ) )
{
return;
}
diff --git a/src/base/proto.c b/src/base/proto.c
index 47acd81..8386a52 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -90,12 +90,16 @@ void proto_send_hello_client(char *name)
#endif
+static void action_sendItem(space_t *space, item_t *item, client_t *client)
+{
+ proto_send_additem_server(PROTO_SEND_ONE, client, item);
+}
+
static void sendInfoCreateClient(client_t *client)
{
list_t *listClient;
client_t *thisClient;
tux_t *thisTux;
- item_t *thisItem;
int i;
assert( client != NULL );
@@ -120,11 +124,14 @@ static void sendInfoCreateClient(client_t *client)
}
}
- for( i = 0 ; i < getCurrentArena()->spaceItem->list->count; i++)
+ actionSpace(getCurrentArena()->spaceItem, action_sendItem, client);
+/*
+ for( i = 0 ; i < getCurrentArena()->spaceItem->listIndex->count; i++)
{
thisItem = (item_t *) getCurrentArena()->spaceItem->list->list[i];
proto_send_additem_server(PROTO_SEND_ONE, client, thisItem);
}
+*/
}
void proto_recv_hello_server(client_t *client, char *msg)
@@ -203,7 +210,7 @@ void proto_send_status_server(int type, client_t *client)
#endif
version = TUXANCI_VERSION;
- clients = getCurrentArena()->spaceTux->list->count;
+ clients = getCurrentArena()->spaceTux->listIndex->count;
maxclients = getServerMaxClients();
uptime = (unsigned int)getUpdateServer();
arena = getArenaNetName( getChoiceArenaId() );
diff --git a/src/base/space.c b/src/base/space.c
index 42fce71..382c4a4 100644
--- a/src/base/space.c
+++ b/src/base/space.c
@@ -48,7 +48,6 @@ space_t *newSpace(int w, int h, int segW, int segH,
new->segH = segH;
new->getStatus = getStatus;
new->setStatus = setStatus;
- new->list = newList();
new->listIndex = newIndex();
new->zone = malloc( new->w * sizeof(list_t **) );
@@ -78,12 +77,24 @@ static void getSegment(space_t *p, int x, int y, int w, int h,
*segH = ( (y+h) / p->segH + 1 ) - *segY;
}
+int getSpaceCount(space_t *p)
+{
+ return p->listIndex->count;
+}
+
+void* getItemFromSpace(space_t *p, int offset)
+{
+ index_item_t *this;
+
+ this = (index_item_t *)p->listIndex->list[offset];
+ return this->data;
+}
+
void addObjectToSpace(space_t *p, void *item)
{
int segX, segY, segW, segH;
int id, x, y, w, h;
int i, j;
- int offset;
p->getStatus(item, &id, &x, &y, &w, &h);
getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
@@ -101,8 +112,7 @@ void addObjectToSpace(space_t *p, void *item)
}
}
- offset = addToIndex(p->listIndex, id);
- insList(p->list, offset, item);
+ addToIndex(p->listIndex, id, item);
}
void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list)
@@ -141,11 +151,7 @@ void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list)
void* getObjectFromSpaceWithID(space_t *space, int id)
{
- int index;
-
- index = getFormIndex(space->listIndex, id);
-
- return ( index != -1 ? space->list->list[index] : NULL );
+ return getFromIndex(space->listIndex, id);
}
int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h)
@@ -249,11 +255,6 @@ void delObjectFromSpace(space_t *p, void *item)
}
}
- index = getFormIndex(p->listIndex, id);
- assert( index != -1 );
-
- delList(p->list, index);
-
delFromIndex(p->listIndex, id);
}
@@ -317,13 +318,13 @@ void actionSpace(space_t *space, void *f, void *p)
int i;
fce = f;
- len = space->list->count;
+ len = space->listIndex->count;
for( i = 0 ; i < len ; i++ )
{
- fce(space, space->list->list[i], p);
+ fce(space, getItemFromSpace(space, i), p);
- if( space->list->count == len-1 )
+ if( space->listIndex->count == len-1 )
{
len--;
i--;
@@ -358,7 +359,6 @@ void destroySpace(space_t *p)
{
int j, i;
- destroyList(p->list);
destroyIndex(p->listIndex);
for( i = 0 ; i < p->h ; i++ )
@@ -385,33 +385,11 @@ void destroySpaceWithObject(space_t *p, void *f)
fce = f;
- for( i = 0 ; i < p->list->count ; i++ )
- fce(p->list->list[i]);
+ for( i = 0 ; i < p->listIndex->count ; i++ )
+ {
+ fce( getItemFromSpace(p, i) );
+ }
destroySpace(p);
}
-#ifdef DEBUG_SPACE
-
-void test_space()
-{/*
- space_t *space;
- recv_t *recv;
-
- space = newSpace(5000, 2500, 320, 240, getStatus, setStatus);
-
- addObjectToSpace(space, newRecv(5, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(7, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(8, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(9, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(6, 0, 0, 1, 1) );
-*/
-/*
- recv = getObjectFromSpaceWithID(space, 6);
- if( recv != NULL )printf("id = %d\n", recv->id);
-*/
-// printListID(space);
-}
-
-#endif
-
diff --git a/src/base/space.h b/src/base/space.h
index 868c5a9..cf2d7c8 100644
--- a/src/base/space.h
+++ b/src/base/space.h
@@ -21,7 +21,6 @@ typedef struct space_struct
zone_t ***zone;
- list_t *list;
list_t *listIndex;
void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h);
@@ -32,6 +31,8 @@ extern space_t *newSpace(int w, int h, int segW, int segH,
void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h),
void (*setStatus)(void *p, int x, int y, int w, int h));
+extern int getSpaceCount(space_t *p);
+extern void* getItemFromSpace(space_t *p, int offset);
extern void addObjectToSpace(space_t *p, void *item);
extern void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list);
extern void* getObjectFromSpaceWithID(space_t *p, int id);
diff --git a/src/base/tux.c b/src/base/tux.c
index 75b6c03..f35a530 100644
--- a/src/base/tux.c
+++ b/src/base/tux.c
@@ -675,26 +675,32 @@ static void eventBonus(tux_t *tux)
}
}
+void eventTux(tux_t *tux)
+{
+ arena_t *arena;
+
+ arena = getCurrentArena();
+
+#ifndef PUBLIC_SERVER
+ tuxControl(tux);
+#endif
+ pickUpGun(tux);
+ eventBonus(tux);
+ eventGiveTuxListItem(tux, arena->spaceItem);
+}
+
void eventListTux(list_t *listTux)
{
tux_t *thisTux;
- arena_t *arena;
int i;
assert( listTux != NULL );
- arena = getCurrentArena();
for( i = 0 ; i < listTux->count ; i++ )
{
thisTux = (tux_t *)listTux->list[i];
assert( thisTux != NULL );
-
-#ifndef PUBLIC_SERVER
- tuxControl(thisTux);
-#endif
- pickUpGun(thisTux);
- eventBonus(thisTux);
- eventGiveTuxListItem(thisTux, arena->spaceItem);
+ eventTux(thisTux);
}
}
diff --git a/src/base/tux.h b/src/base/tux.h
index 2d39195..17cc0e9 100644
--- a/src/base/tux.h
+++ b/src/base/tux.h
@@ -124,6 +124,7 @@ extern void eventConflictTuxWithShot(arena_t *arena);
extern void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport);
extern void tuxTeleport(tux_t *tux);
extern void actionTux(tux_t *tux, int action);
+extern void eventTux(tux_t *tux);
extern void eventListTux(list_t *listTux);
extern tux_t* getTuxID(list_t *listTux, int id);
extern void getTuxProportion(tux_t *tux, int *x,int *y, int *w, int *h);
diff --git a/src/base/udp_server.c b/src/base/udp_server.c
index 1c0c38d..ce54802 100644
--- a/src/base/udp_server.c
+++ b/src/base/udp_server.c
@@ -184,7 +184,7 @@ static void eventClientUdpSelect(sock_udp_t *sock_server)
if( client == NULL )
{
- if( getCurrentArena()->spaceTux->list->count+1 > getServerMaxClients() )
+ if( getSpaceCount(getCurrentArena()->spaceTux)+1 > getServerMaxClients() )
{
destroySockUdp(sock_client);
return;
diff --git a/src/client/interface.c b/src/client/interface.c
index 37aa361..b697524 100755
--- a/src/client/interface.c
+++ b/src/client/interface.c
@@ -16,7 +16,7 @@ static SDL_Surface *screen;
static SDL_TimerID timer;
// window flags
-static Uint32 g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
+static Uint32 g_win_flags = SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_ANYFORMAT;
static bool_t isInterfaceInit = FALSE;
@@ -70,9 +70,9 @@ int initSDL()
screen->format->BitsPerPixel,
screen->format->Rmask, screen->format->Gmask,
screen->format->Bmask, screen->format->Amask);
-
- memset(my_surface->pixels, 128, 200);
*/
+ //memset(my_surface->pixels, 128, 200);
+
if (screen == NULL )
{
fprintf(stderr, "%s\n", SDL_GetError());
@@ -106,6 +106,7 @@ void interfaceRefresh()
//drawImage(my_surface, 200, 100, 0, 0, 200, 200);
SDL_Flip(screen);
+ //SDL_UpdateRect(screen, 400, 0, 400, 600);
}
int toggleFullscreen()
diff --git a/src/client/panel.c b/src/client/panel.c
index f63e481..b84cdfb 100644
--- a/src/client/panel.c
+++ b/src/client/panel.c
@@ -51,36 +51,24 @@ void initPanel()
isPanelInit = TRUE;
}
-static void setScoreline(list_t *listTux, char *str)
-{
- tux_t *thisTux;
- int i;
-
- assert( listTux != NULL );
- assert( str != NULL );
-
- strcpy(str, "");
-
- for( i = 0 ; i < listTux->count ; i++ )
- {
- char num[STR_SIZE];
-
- thisTux = (tux_t *)listTux->list[i];
- assert( thisTux != NULL );
-
- sprintf(num, "%s%d", ( i == 0 ? "" : " : " ), thisTux->score);
- strcat(str, num);
- }
-}
-
-static void drawScore(list_t *listTux)
+static void drawScore(tux_t *tux_right, tux_t *tux_left)
{
char strScoreLine[STR_SIZE];
int w, h;
- assert( listTux != NULL );
+ if( tux_right != NULL && tux_left != NULL )
+ {
+ sprintf(strScoreLine, "%d : %d", tux_right->score, tux_left->score);
+ }
+ else if( tux_right != NULL )
+ {
+ sprintf(strScoreLine, "%d", tux_right->score);
+ }
+ else if( tux_left != NULL )
+ {
+ sprintf(strScoreLine, "%d", tux_left->score);
+ }
- setScoreline(listTux, strScoreLine);
getTextSize(strScoreLine, &w , &h);
drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y, COLOR_WHITE);
}
@@ -137,56 +125,52 @@ static void drawGrafBonus(tux_t *tux,int x, int y)
drawImage(g_bonus, x+1, y, 0, g_bonus->h/2, offset, g_bonus->h/2);
}
-void drawPanel(list_t *listTux)
+static void drawTuxRight(tux_t *tux)
{
- int i;
+ if( tux == NULL )
+ {
+ return;
+ }
- assert( listTux != NULL );
+ drawShotInfo(tux, PANEL_LOCATION_X+740, PANEL_LOCATION_Y+34);
+ drawGunInfo(tux, PANEL_LOCATION_X+620, PANEL_LOCATION_Y+30);
- drawImage(g_panel, PANEL_LOCATION_X, PANEL_LOCATION_Y, 0, 0, g_panel->w, g_panel->h);
- drawScore(listTux);
+ if( tux->bonus != BONUS_NONE )
+ {
+ drawGrafBonus(tux, PANEL_LOCATION_X+460, PANEL_LOCATION_Y+50);
+ drawBonusInfo(tux, PANEL_LOCATION_X+460, PANEL_LOCATION_Y+30);
+ }
+}
- if( isRecivedNewMsg() )
+static void drawTuxLeft(tux_t *tux)
+{
+ if( tux == NULL )
{
- drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y, COLOR_WHITE);
+ return;
}
- for( i = 0 ; i < listTux->count ; i++ )
+ drawShotInfo(tux, PANEL_LOCATION_X+8, PANEL_LOCATION_Y+34);
+ drawGunInfo(tux, PANEL_LOCATION_X+130, PANEL_LOCATION_Y+30);
+
+ if( tux->bonus != BONUS_NONE )
{
- tux_t *thisTux;
- int x, y;
-
- thisTux = (tux_t *)listTux->list[i];
- assert( thisTux != NULL );
+ drawGrafBonus(tux, PANEL_LOCATION_X+200, PANEL_LOCATION_Y+50);
+ drawBonusInfo(tux, PANEL_LOCATION_X+200, PANEL_LOCATION_Y+30);
+ }
+}
- x = PANEL_LOCATION_X;
- y = PANEL_LOCATION_Y;
+void drawPanel(tux_t *tux_right, tux_t *tux_left)
+{
+ drawImage(g_panel, PANEL_LOCATION_X, PANEL_LOCATION_Y, 0, 0, g_panel->w, g_panel->h);
+ drawScore(tux_right, tux_left);
- switch( i )
- {
- case 0 :
- drawShotInfo(thisTux, x+8, y+34);
- drawGunInfo(thisTux, x+130, y+30);
-
- if( thisTux->bonus != BONUS_NONE )
- {
- drawGrafBonus(thisTux,x+200, y+50);
- drawBonusInfo(thisTux,x+200, y+30);
- }
- break;
-
- case 1 :
- drawShotInfo(thisTux, x+740, y+34);
- drawGunInfo(thisTux, x+620, y+30);
-
- if( thisTux->bonus != BONUS_NONE )
- {
- drawGrafBonus(thisTux,x+460, y+50);
- drawBonusInfo(thisTux,x+460, y+30);
- }
- break;
- }
+ if( isRecivedNewMsg() )
+ {
+ drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y, COLOR_WHITE);
}
+
+ drawTuxRight(tux_right);
+ drawTuxLeft(tux_left);
}
void quitPanel()
diff --git a/src/client/panel.h b/src/client/panel.h
index 4935c75..6eadd92 100644
--- a/src/client/panel.h
+++ b/src/client/panel.h
@@ -21,7 +21,7 @@
extern bool_t isPanelInicialized();
extern void initPanel();
-extern void drawPanel(list_t *listTux);
+extern void drawPanel(tux_t *tux_right, tux_t *tux_left);
extern void quitPanel();
#endif
diff --git a/src/modules/modAI.c b/src/modules/modAI.c
index 105b410..ccd444a 100755
--- a/src/modules/modAI.c
+++ b/src/modules/modAI.c
@@ -137,15 +137,15 @@ int draw(int x, int y, int w, int h)
}
#endif
-tux_t *findOtherTux(list_t *list)
+tux_t *findOtherTux(space_t *space)
{
int i;
- for( i = 0 ; i < list->count ; i++ )
+ for( i = 0 ; i < getSpaceCount(space) ; i++ )
{
tux_t *thisTux;
- thisTux = list->list[i];
+ thisTux = getItemFromSpace(space, i);
if( thisTux->control != TUX_CONTROL_AI )
{
@@ -191,7 +191,7 @@ static void shotTux(arena_t *arena, tux_t *tux_ai, tux_t *tux_rival)
}
}
-static void eventTux(tux_t *tux)
+static void eventTuxAI(tux_t *tux)
{
arena_t *arena;
tux_t *rivalTux;
@@ -218,7 +218,7 @@ static void eventTux(tux_t *tux)
arena = export_fce->fce_getCurrentArena();
- rivalTux = findOtherTux(arena->spaceTux->list);
+ rivalTux = findOtherTux(arena->spaceTux);
if( rivalTux == NULL || rivalTux->status != TUX_STATUS_ALIVE )
{
@@ -340,13 +340,22 @@ static void eventTux(tux_t *tux)
*/
}
+static void action_tuxAI(space_t *space, tux_t *tux, void *p)
+{
+ if( tux->control == TUX_CONTROL_AI &&
+ tux->status == TUX_STATUS_ALIVE )
+ {
+ eventTuxAI(tux);
+ }
+}
+
int event()
{
static my_time_t lastEvent = 0;
my_time_t curentTime;
arena_t *arena;
int countTuxAI;
- int i;
+ //int i;
if( lastEvent == 0 )
{
@@ -372,6 +381,8 @@ int event()
countTuxAI = 0;
+ actionSpace(arena->spaceTux, action_tuxAI, NULL);
+/*
for( i = 0 ; i < arena->spaceTux->list->count ; i++ )
{
tux_t *thisTux;
@@ -385,7 +396,7 @@ int event()
countTuxAI = 0;
}
}
-
+*/
return 0;
}
diff --git a/src/modules/modTeleport.c b/src/modules/modTeleport.c
index 3dafd77..0ce27bf 100755
--- a/src/modules/modTeleport.c
+++ b/src/modules/modTeleport.c
@@ -159,15 +159,15 @@ static void cmd_teleport(char *line)
addObjectToSpace(spaceTeleport, new);
}
-static teleport_t* getRandomTeleportBut(list_t *list, teleport_t *teleport)
+static teleport_t* getRandomTeleportBut(space_t *space, teleport_t *teleport)
{
- int x;
+ int index;
do{
- x = random() % list->count;
- }while( list->list[x] == teleport );
+ index = random() % getSpaceCount(space);
+ }while( getItemFromSpace(space, index) == teleport );
- return (teleport_t *) list->list[x];
+ return (teleport_t *) getItemFromSpace(space, index);
}
static int getRandomPosition()
@@ -202,16 +202,16 @@ static void teleportTux(tux_t *tux, teleport_t *teleport)
return;
}
- distTeleport = getRandomTeleportBut(spaceTeleport->list, teleport);
+ distTeleport = getRandomTeleportBut(spaceTeleport, teleport);
fce_move_tux(tux, distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h);
}
-static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *list)
+static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, space_t *space)
{
teleport_t *distTeleport;
- distTeleport = getRandomTeleportBut(list, teleport);
+ distTeleport = getRandomTeleportBut(space, teleport);
fce_move_shot(shot, getRandomPosition(), teleport->x, teleport->y,
distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h);
@@ -277,7 +277,7 @@ static void action_eventteleportshot(space_t *space, teleport_t *teleport, shot_
return;
}
- moveShotFromTeleport(shot, teleport, spaceTeleport->list);
+ moveShotFromTeleport(shot, teleport, spaceTeleport);
}
static void action_eventshot(space_t *space, shot_t *shot, space_t *spaceTeleport)
diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c
index 1c3d433..12da3a1 100644
--- a/src/screen/screen_world.c
+++ b/src/screen/screen_world.c
@@ -125,6 +125,8 @@ void prepareArena()
//printf("getSettingAI = %s\n", getSettingAI());
setCurrentArena(NULL);
+ tuxWithControlRightKeyboard = NULL;
+ tuxWithControlLeftKeyboard = NULL;
switch( getNetTypeGame() )
{
@@ -179,7 +181,7 @@ void drawWorld()
if( arena != NULL )
{
drawArena(arena);
- drawPanel(arena->spaceTux->list);
+ drawPanel(tuxWithControlRightKeyboard, tuxWithControlLeftKeyboard);
if( arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y )
{
@@ -505,18 +507,16 @@ void startWorld()
prepareArena();
}
-static void setAnalyze()
+static void action_analyze(space_t *space, tux_t *tux, void *p)
{
- int i;
- tux_t *tux;
+ addAnalyze(tux->name, tux->score);
+}
+static void setAnalyze()
+{
restartAnalyze();
- for( i = 0 ; i < arena->spaceTux->list->count ; i++ )
- {
- tux = (tux_t *)(arena->spaceTux->list->list[i]);
- addAnalyze(tux->name, tux->score);
- }
+ actionSpace(arena->spaceTux, action_analyze, NULL);
endAnalyze();
}