summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/arena.c12
-rw-r--r--src/base/gun.c3
-rw-r--r--src/base/proto.c9
-rw-r--r--src/base/server.c15
-rw-r--r--src/base/server.h2
-rw-r--r--src/base/shot.c69
-rw-r--r--src/base/tux.c1
7 files changed, 58 insertions, 53 deletions
diff --git a/src/base/arena.c b/src/base/arena.c
index bd471a2..9de1dce 100644
--- a/src/base/arena.c
+++ b/src/base/arena.c
@@ -90,8 +90,8 @@ void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h)
assert( y != NULL );
do{
- z_x = random() % WINDOW_SIZE_X;//arena->w;
- z_y = random() % WINDOW_SIZE_Y;//arena->h;
+ z_x = random() % (arena->w-w);
+ z_y = random() % (arena->h-h);
}while( isFreeSpace(arena, z_x, z_y ,w ,h) == 0 );
*x = z_x;
@@ -201,16 +201,10 @@ void eventArena(arena_t *arena)
{
int i;
- //eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport);
- //eventConflictTuxWithShot(arena);
-
for( i = 0 ; i < 8 ; i++)
{
- eventMoveListShot(arena);
checkShotIsInTuxScreen(arena);
- //eventConflictShotWithWall(arena->listWall, arena->listShot);
- //eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
- //eventConflictShotWithPipe(arena->listPipe, arena->listShot);
+ eventMoveListShot(arena);
eventConflictShotWithItem(arena);
eventConflictTuxWithShot(arena);
eventModule();
diff --git a/src/base/gun.c b/src/base/gun.c
index 0a7e1a1..c59bd98 100644
--- a/src/base/gun.c
+++ b/src/base/gun.c
@@ -95,6 +95,7 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun)
//addList( getCurrentArena()->listShot, shot );
addObjectToSpace(getCurrentArena()->spaceShot, shot);
+/*
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
client_t *thisClient;
@@ -108,7 +109,7 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun)
proto_send_shot_server(PROTO_SEND_ALL_SEES_TUX, thisClient, shot);
}
-
+*/
}
static void addShot(tux_t *tux,int x, int y, int px, int py)
diff --git a/src/base/proto.c b/src/base/proto.c
index 9c9c3c7..b109115 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -26,6 +26,7 @@
#include "screen/screen_analyze.h"
#include "client/client.h"
#include "client/term.h"
+#include "client/radar.h"
#endif
#ifdef PUBLIC_SERVER
@@ -325,6 +326,7 @@ void proto_recv_event_client(char *msg)
if( tux != NULL )
{
actionTux(tux, action);
+ addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX);
}
}
@@ -438,6 +440,8 @@ void proto_recv_newtux_client(char *msg)
addObjectToSpace(getCurrentArena()->spaceTux, tux);
}
+ addToRadar(id, x, y, RADAR_TYPE_TUX);
+
moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y);
tux->status = status;
tux->position = position;
@@ -534,6 +538,7 @@ void proto_recv_del_client(char *msg)
sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
appendTextInTerm(term_msg);
+ delFromRadar(id);
delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, destroyTux);
return;
}
@@ -543,6 +548,7 @@ void proto_recv_del_client(char *msg)
if( shot != NULL )
{
//printf("delete shot..\n");
+ delFromRadar(id);
delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot);
return;
}
@@ -552,6 +558,7 @@ void proto_recv_del_client(char *msg)
if( item != NULL )
{
//printf("delete item..\n");
+ delFromRadar(id);
delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, destroyItem);
return;
}
@@ -601,6 +608,8 @@ void proto_recv_additem_client(char *msg)
return;
}
+ addToRadar(id, x, y, RADAR_TYPE_ITEM);
+
item = newItem(x, y, type, author_id);
replaceItemID(item, id);
diff --git a/src/base/server.c b/src/base/server.c
index fba543c..941b62e 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -120,7 +120,8 @@ static void eventPeriodicSyncClient(void *p_nothink)
continue;
}
- proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux);
+ //proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux);
+ proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux);
}
}
@@ -228,6 +229,7 @@ client_t* newUdpClient(sock_udp_t *sock_udp)
new->status = NET_STATUS_OK;
new->listRecvMsg = newList();
new->listSendMsg = newCheckFront();
+ new->listSeesShot = newList();
new->protect = newProtect();
new->socket_udp = sock_udp;
@@ -248,6 +250,7 @@ void destroyClient(client_t *p)
closeUdpSocket(p->socket_udp);
destroyListItem(p->listRecvMsg, free);
+ destroyListItem(p->listSeesShot, free);
destroyCheckFront(p->listSendMsg);
destroyProtect(p->protect);
@@ -367,11 +370,11 @@ static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id)
arena = getCurrentArena();
space = arena->spaceTux;
- x = tux->x-(WINDOW_SIZE_X/2)*1.25;
- y = tux->y-(WINDOW_SIZE_Y/2)*1.25;
+ x = tux->x - WINDOW_SIZE_X;
+ y = tux->y - WINDOW_SIZE_Y;
- w = WINDOW_SIZE_X*1.5;
- h = WINDOW_SIZE_Y*1.5;
+ w = 2 * WINDOW_SIZE_X;
+ h = 2 * WINDOW_SIZE_Y;
if( x < 0 )
{
@@ -730,7 +733,7 @@ int selectServerUdpSocket()
#ifdef PUBLIC_SERVER
tv.tv_sec = 0;
- tv.tv_usec = 5000;
+ tv.tv_usec = 1000;
#endif
FD_ZERO(&readfds);
diff --git a/src/base/server.h b/src/base/server.h
index 4a946ea..670258c 100644
--- a/src/base/server.h
+++ b/src/base/server.h
@@ -52,6 +52,8 @@ typedef struct client_struct
list_t *listSendMsg;
list_t *listRecvMsg;
+
+ list_t *listSeesShot;
} client_t;
#ifdef PUBLIC_SERVER
diff --git a/src/base/shot.c b/src/base/shot.c
index 1858bc0..96f5692 100644
--- a/src/base/shot.c
+++ b/src/base/shot.c
@@ -294,6 +294,7 @@ void eventMoveListShot(arena_t *arena)
}
}
+#if 0
static int myAbs(int n)
{
return ( n > 0 ? n : -n );
@@ -303,14 +304,30 @@ 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;
+ for( i = 0 ; i < list->count ; i++ )
+ {
+ if( x == ( *(int *)list->list[i] ) )
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
void checkShotIsInTuxScreen(arena_t *arena)
{
int screen_x, screen_y;
shot_t *thisShot;
tux_t *thisTux;
- int speed;
+ client_t *thisClient;
+ list_t *listClient;
int i, j;
if( getNetTypeGame() != NET_GAME_TYPE_SERVER )
@@ -318,12 +335,14 @@ void checkShotIsInTuxScreen(arena_t *arena)
return;
}
- for( i = 0 ; i < arena->spaceTux->list->count ; i++ )
+ listClient = getListServerClient();
+
+ for( i = 0 ; i < listClient->count ; i++ )
{
- thisTux = (tux_t *)arena->spaceTux->list->list[i];
- speed = 25;
+ thisClient = (client_t *)listClient->list[i];
+ thisTux = (tux_t *)thisClient->tux;
- if( thisTux->control != TUX_CONTROL_NET )
+ if( thisTux == NULL || thisTux->control != TUX_CONTROL_NET )
{
continue;
}
@@ -331,47 +350,23 @@ void checkShotIsInTuxScreen(arena_t *arena)
getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y);
listDoEmpty(listHelp);
- getObjectFromSpace(arena->spaceShot, screen_x-speed, screen_y, speed, WINDOW_SIZE_Y, listHelp);
- for( j = 0 ; j <listHelp->count ; j++ )
- {
- thisShot = (shot_t *)listHelp->list[j];
- client_t *thisClient;
- thisClient = getClientFromTux(thisTux);
- proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
- }
-
- listDoEmpty(listHelp);
- getObjectFromSpace(arena->spaceShot, screen_x+WINDOW_SIZE_X, screen_y, speed, WINDOW_SIZE_Y, listHelp);
+ getObjectFromSpace(arena->spaceShot, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp);
for( j = 0 ; j <listHelp->count ; j++ )
{
thisShot = (shot_t *)listHelp->list[j];
- client_t *thisClient;
- thisClient = getClientFromTux(thisTux);
- proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
- }
- listDoEmpty(listHelp);
- getObjectFromSpace(arena->spaceShot, screen_x, screen_y-speed, WINDOW_SIZE_X, speed, listHelp);
-
- for( j = 0 ; j <listHelp->count ; j++ )
- {
- thisShot = (shot_t *)listHelp->list[j];
- client_t *thisClient;
- thisClient = getClientFromTux(thisTux);
- proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ if( isValueInList(thisClient->listSeesShot, thisShot->id) == 0 )
+ {
+ addList(thisClient->listSeesShot, newInt(thisShot->id) );
+ proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ }
}
- listDoEmpty(listHelp);
- getObjectFromSpace(arena->spaceShot, screen_x, screen_y+WINDOW_SIZE_Y, WINDOW_SIZE_X, speed, listHelp);
-
- for( j = 0 ; j <listHelp->count ; j++ )
+ while( thisClient->listSeesShot->count > 100 )
{
- thisShot = (shot_t *)listHelp->list[j];
- client_t *thisClient;
- thisClient = getClientFromTux(thisTux);
- proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot);
+ delListItem(thisClient->listSeesShot, 0, free);
}
}
}
diff --git a/src/base/tux.c b/src/base/tux.c
index 9d34cc9..f60bd1b 100644
--- a/src/base/tux.c
+++ b/src/base/tux.c
@@ -21,6 +21,7 @@
#include "client/image.h"
#include "client/layer.h"
#include "client/term.h"
+#include "client/radar.h"
#include "audio/sound.h"