diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/arena.c | 12 | ||||
| -rw-r--r-- | src/base/gun.c | 3 | ||||
| -rw-r--r-- | src/base/proto.c | 9 | ||||
| -rw-r--r-- | src/base/server.c | 15 | ||||
| -rw-r--r-- | src/base/server.h | 2 | ||||
| -rw-r--r-- | src/base/shot.c | 69 | ||||
| -rw-r--r-- | src/base/tux.c | 1 | ||||
| -rw-r--r-- | src/client/Makefile | 4 | ||||
| -rw-r--r-- | src/client/game.c | 1 | ||||
| -rw-r--r-- | src/client/radar.c | 117 | ||||
| -rw-r--r-- | src/client/radar.h | 24 | ||||
| -rwxr-xr-x | src/modules/modWall.c | 33 | ||||
| -rw-r--r-- | src/screen/screen_world.c | 14 | ||||
| -rw-r--r-- | src/server/publicServer.c | 6 |
14 files changed, 243 insertions, 67 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" diff --git a/src/client/Makefile b/src/client/Makefile index c5637ea..f8fee47 100644 --- a/src/client/Makefile +++ b/src/client/Makefile @@ -1,6 +1,6 @@ -all: client.o configFile.o font.o game.o image.o interface.o keytable.o language.o layer.o panel.o screen.o term.o +all: client.o configFile.o font.o game.o image.o interface.o keytable.o language.o layer.o panel.o radar.o screen.o term.o client.o: client.c client.h $(CC) $(CFLAGS) -o client.o -c client.c @@ -26,6 +26,8 @@ layer.o: layer.c layer.h panel.o: panel.c panel.h $(CC) $(CFLAGS) -o panel.o -c panel.c +radar.o: radar.c radar.h + $(CC) $(CFLAGS) -o radar.o -c radar.c screen.o: screen.c screen.h $(CC) $(CFLAGS) -o screen.o -c screen.c diff --git a/src/client/game.c b/src/client/game.c index 7ea9145..66da14e 100644 --- a/src/client/game.c +++ b/src/client/game.c @@ -23,6 +23,7 @@ #include "client/keytable.h" #include "client/language.h" #include "client/panel.h" +#include "client/radar.h" #include "audio/audio.h" #include "audio/sound.h" diff --git a/src/client/radar.c b/src/client/radar.c new file mode 100644 index 0000000..d993d41 --- /dev/null +++ b/src/client/radar.c @@ -0,0 +1,117 @@ + +#include <stdio.h> +#include <assert.h> + +#include "base/main.h" +#include "base/list.h" +#include "base/tux.h" +#include "base/arena.h" + +#include "client/interface.h" +#include "client/image.h" +#include "client/radar.h" + +static SDL_Surface *g_radar; +static list_t *listRadar; + +typedef struct radar_item_struct +{ + int id; + int x, y; + int type; +} radar_item_t; + +static radar_item_t* newRadarItem(int id, int x, int y, int type) +{ + radar_item_t *new; + + new = malloc( sizeof(radar_item_t) ); + new->id = id; + new->x = x; + new->y = y; + new->type = type; + + return new; +} + +static void destroyRadarItem(radar_item_t *p) +{ + assert( p != NULL ); + free(p); +} + +void addToRadar(int id, int x, int y, int type) +{ + int i; + + for( i = 0 ; i < listRadar->count ; i++ ) + { + radar_item_t *thisRadarItem; + + thisRadarItem = (radar_item_t *)listRadar->list[i]; + + if( thisRadarItem->id == id ) + { + thisRadarItem->x = x; + thisRadarItem->y = y; + thisRadarItem->type = type; + return; + } + } + + addList(listRadar, newRadarItem(id, x, y, type) ); +} + +void delFromRadar(int id) +{ + int i; + + for( i = 0 ; i < listRadar->count ; i++ ) + { + radar_item_t *thisRadarItem; + + thisRadarItem = (radar_item_t *)listRadar->list[i]; + + if( thisRadarItem->id == id ) + { + delListItem(listRadar, i, destroyRadarItem); + return; + } + } +} + +void initRadar() +{ + assert( isImageInicialized() == TRUE ); + assert( isInterfaceInicialized() == TRUE ); + + g_radar = addImageData("radar.png", IMAGE_ALPHA, "radar", IMAGE_GROUP_USER); + listRadar = newList(); +} + +void drawRadar(arena_t *arena) +{ + int i; + + drawImage(g_radar, RADAR_LOCATION_X, RADAR_LOCATION_Y, 0, 0, RADAR_SIZE_X+2, RADAR_SIZE_Y+2); + + for( i = 0 ; i < listRadar->count ; i++ ) + { + radar_item_t *thisRadarItem; + int x, y; + + thisRadarItem = (radar_item_t *)listRadar->list[i]; + + x = ( ( (float)RADAR_SIZE_X) / ( (float)arena->w ) ) * ( (float)thisRadarItem->x ); + y = ( ( (float)RADAR_SIZE_Y) / ( (float)arena->h ) ) * ( (float)thisRadarItem->y ); + + drawImage(g_radar, + RADAR_LOCATION_X+1+x, RADAR_LOCATION_Y+1+y, + 2*thisRadarItem->type, RADAR_SIZE_Y+2, 2, 2); + } +} + +void quitRadar() +{ + destroyListItem(listRadar, destroyRadarItem); +} diff --git a/src/client/radar.h b/src/client/radar.h new file mode 100644 index 0000000..989856a --- /dev/null +++ b/src/client/radar.h @@ -0,0 +1,24 @@ + +#ifndef RADAR_H + +#define RADAR_H + +#include "base/arena.h" + +#define RADAR_LOCATION_X (WINDOW_SIZE_X-110) +#define RADAR_LOCATION_Y (10) + +#define RADAR_SIZE_X 100 +#define RADAR_SIZE_Y 100 + +#define RADAR_TYPE_YOU 3 +#define RADAR_TYPE_TUX 1 +#define RADAR_TYPE_ITEM 2 + +extern void initRadar(); +extern void addToRadar(int id, int x, int y, int type); +extern void delFromRadar(int id); +extern void drawRadar(arena_t *arena); +extern void quitRadar(); + +#endif diff --git a/src/modules/modWall.c b/src/modules/modWall.c index c5e01ce..35d84e6 100755 --- a/src/modules/modWall.c +++ b/src/modules/modWall.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -214,8 +213,14 @@ static void cmd_wall(char *line) char str_h[STR_NUM_SIZE]; char str_layer[STR_NUM_SIZE]; char str_image[STR_SIZE]; + char str_rel[STR_SIZE]; + int x, y, w, h, img_x, img_y, layer; + int rel; wall_t *new; + rel = 0; + + if( export_fce->fce_getValue(line, "rel", str_rel, STR_NUM_SIZE) != 0 ); if( export_fce->fce_getValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return; if( export_fce->fce_getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; if( export_fce->fce_getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; @@ -225,18 +230,28 @@ static void cmd_wall(char *line) if( export_fce->fce_getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; if( export_fce->fce_getValue(line, "image", str_image, STR_SIZE) != 0 )return; + + rel = atoi(str_rel); + x = atoi(str_x); + y = atoi(str_y); + w = atoi(str_w); + h = atoi(str_h); + img_x = atoi(str_img_x); + img_y = atoi(str_img_y); + layer = atoi(str_layer); + + if( rel == 1 ) + { + img_x += x; + img_y += y; + } + #ifndef PUBLIC_SERVER - new = newWall(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_img_x), atoi(str_img_y), - atoi(str_layer), export_fce->fce_getImage(IMAGE_GROUP_USER, str_image) ); + new = newWall(x, y, w, h, img_x, img_y, layer, export_fce->fce_getImage(IMAGE_GROUP_USER, str_image) ); #endif #ifdef PUBLIC_SERVER - new = newWall(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_img_x), atoi(str_img_y), - atoi(str_layer) ); + new = newWall(x, y, w, h, img_x, img_y, layer); #endif if( spaceWall == NULL ) diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index 78628b2..380fd43 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -24,6 +24,7 @@ #include "client/term.h" #include "client/font.h" #include "client/panel.h" +#include "client/radar.h" #ifndef NO_SOUND #include "audio/music.h" @@ -196,6 +197,11 @@ void drawWorld() { drawArena(arena); drawPanel(arena->spaceTux->list); + + if( arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y ) + { + drawRadar(arena); + } } drawTerm(); @@ -481,6 +487,11 @@ void eventWorld() eventArena(arena); //eventModule(); + addToRadar(tuxWithControlRightKeyboard->id, + tuxWithControlRightKeyboard->x, + tuxWithControlRightKeyboard->y, + RADAR_TYPE_YOU); + eventTerm(); eventEnd(); eventEsc(); @@ -495,6 +506,7 @@ void startWorld() lastServerLag = LAG_SERVER_UNKNOWN; initListID(); + initRadar(); initModule(); setGameType(); initTerm(); @@ -556,6 +568,8 @@ void stoptWorld() destroyArena(arena); } + quitRadar(); + #ifndef NO_SOUND stopMusic(); #endif diff --git a/src/server/publicServer.c b/src/server/publicServer.c index c69857a..1d2ccf0 100644 --- a/src/server/publicServer.c +++ b/src/server/publicServer.c @@ -246,12 +246,10 @@ void eventPublicServer() return; } -/* - printf("interval = %d\n", interval); -*/ + //printf("interval = %d\n", interval); + lastActive = getMyTime(); - //fce_interval(); eventArena(arena); } |