summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/proto.h2
-rw-r--r--include/publicServer.h2
-rw-r--r--include/screen_world.h1
-rw-r--r--include/term.h17
-rwxr-xr-xsrc/Makefile5
-rwxr-xr-xsrc/Makefile-publicServer5
-rw-r--r--src/gun.c23
-rw-r--r--src/item.c30
-rw-r--r--src/main.c10
-rw-r--r--src/proto.c57
-rw-r--r--src/publicServer.c101
-rw-r--r--src/screen_world.c38
-rw-r--r--src/server.c20
-rw-r--r--src/term.c105
-rw-r--r--src/tux.c66
15 files changed, 377 insertions, 105 deletions
diff --git a/include/proto.h b/include/proto.h
index f91b60b..f7422ec 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -63,8 +63,6 @@ extern void proto_send_additem_server(int type, client_t *client, item_t *p);
extern void proto_recv_additem_client(char *msg);
extern void proto_send_shot_server(int type, client_t *client, shot_t *p);
extern void proto_recv_shot_client(char *msg);
-extern void proto_send_context_client(tux_t *tux);
-extern void proto_recv_context_server(client_t *client, char *msg);
extern void proto_send_ping_client();
extern void proto_recv_ping_server(client_t *client, char *msg);
extern void proto_send_end_client();
diff --git a/include/publicServer.h b/include/publicServer.h
index 9b453d7..7577932 100644
--- a/include/publicServer.h
+++ b/include/publicServer.h
@@ -5,6 +5,8 @@
#include "arena.h"
+#define WORLD_COUNT_ROUND_UNLIMITED -1
+
extern arena_t* getWorldArena();
extern void countRoundInc();
extern int initPublicServer();
diff --git a/include/screen_world.h b/include/screen_world.h
index d6dfd12..7ad6a41 100644
--- a/include/screen_world.h
+++ b/include/screen_world.h
@@ -8,6 +8,7 @@
#include "arena.h"
#define TIMER_END_ARENA 5000
+#define WORLD_COUNT_ROUND_UNLIMITED -1
extern bool_t isScreenWorldInicialized();
extern void initWorld();
diff --git a/include/term.h b/include/term.h
new file mode 100644
index 0000000..b48a2b7
--- /dev/null
+++ b/include/term.h
@@ -0,0 +1,17 @@
+
+#ifndef TERM_H
+
+#define TERM_H
+
+#include "main.h"
+
+#define TERM_MAX_LINES 10
+#define TERM_DEL_TEXT_TIMEOUT 2000
+
+extern void initTerm();
+extern void drawTerm();
+extern void eventTerm();
+extern void appendTextInTerm(char *s);
+extern void quitTerm();
+
+#endif
diff --git a/src/Makefile b/src/Makefile
index 405812f..4c2e4ef 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -14,7 +14,7 @@ FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o
item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \
widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \
widget_buttonimage.o screen_credits.o teleport.o pipe.o homeDirector.o screen_table.o \
- sdl_udp.o proto.o server.o client.o
+ sdl_udp.o proto.o server.o client.o term.o
tuxanci-ng: $(FILES)
$(CC) $(CFLAGS) $(LIBS) -o tuxanci-ng $(FILES)
@@ -166,5 +166,8 @@ homeDirector.o: homeDirector.c ../include/homeDirector.h
screen_table.o: screen_table.c ../include/screen_table.h
$(CC) $(CFLAGS) -o screen_table.o -c screen_table.c
+term.o: term.c ../include/term.h
+ $(CC) $(CFLAGS) -o term.o -c term.c
+
clean:
rm -rf *.o *.c~ ../include/*.h~ Makefile~ tuxanci-ng
diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer
index e0a2a56..ff6cf15 100755
--- a/src/Makefile-publicServer
+++ b/src/Makefile-publicServer
@@ -9,16 +9,13 @@ CFLAGS = -g -O0 -DBUBLIC_SERVER -DSUPPORT_NET_UNIX_UDP -I../include -Wall
LIBS =
-FILES = list.o director.o configFile.o tux.o main.o wall.o shot.o myTimer.o \
+FILES = list.o director.o configFile.o tux.o wall.o shot.o myTimer.o \
buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o teleport.o pipe.o\
udp.o proto.o server.o publicServer.o net_multiplayer.o
publicserver: $(FILES)
$(CC) $(CFLAGS) $(LIBS) -o publicserver $(FILES)
-main.o: main.c
- $(CC) $(CFLAGS) -o main.o -c main.c
-
publicServer.o: publicServer.c
$(CC) $(CFLAGS) -o publicServer.o -c publicServer.c
diff --git a/src/gun.c b/src/gun.c
index 61ece2b..0768b67 100644
--- a/src/gun.c
+++ b/src/gun.c
@@ -16,6 +16,7 @@
#include "sound.h"
#include "screen_world.h"
#include "interface.h"
+#include "term.h"
#endif
#ifdef BUBLIC_SERVER
@@ -124,13 +125,13 @@ static void addShot(tux_t *tux,int x, int y, int px, int py)
static void shotInGunSimpe(tux_t *tux)
{
- addShot(tux, 0, 0, +20, 0);
+ addShot(tux, 0, 0, +5, 0);
}
static void shotInGunDualSimpe(tux_t *tux)
{
- addShot(tux, 0, -5, +20, 0);
- addShot(tux, 0, +5, +20, 0);
+ addShot(tux, 0, -10, +6, 0);
+ addShot(tux, 0, +10, +6, 0);
}
static void shotInGunScatter(tux_t *tux)
@@ -139,7 +140,7 @@ static void shotInGunScatter(tux_t *tux)
for( i = -2 ; i <= +2 ; i++ )
{
- addShot(tux, 0, 0, +25, i);
+ addShot(tux, 0, 0, +8, i);
}
}
@@ -158,7 +159,7 @@ static void timer_addShotTimer(void *p)
gun = tux->gun;
tux->gun = GUN_SIMPLE;
- addShot(tux, 0, 0, +25, 0);
+ addShot(tux, 0, 0, +6, 0);
tux->gun = gun;
}
@@ -188,7 +189,7 @@ static void timer_addLaserTimer(void *p)
gun = tux->gun;
tux->gun = GUN_LASSER;
- addShot(tux, 0, 0, +25, 0);
+ addShot(tux, 0, 0, +10, 0);
tux->gun = gun;
}
@@ -230,6 +231,13 @@ static void putInGunMine(tux_t *tux)
if( isFreeSpace(x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT) )
{
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+ playSound("put_mine", SOUND_GROUP_BASE);
+ sprintf(msg, "tux with id %d pu mine\n", tux->id);
+ appendTextInTerm(msg);
+#endif
+
addList(arena->listItem, newItem(x, y, ITEM_MINE, tux) );
tux->shot[tux->gun]--;
}
@@ -275,9 +283,6 @@ void shotInGun(tux_t *tux)
shotInGunLasser(tux);
break;
case GUN_MINE :
-#ifndef BUBLIC_SERVER
- playSound("put_mine", SOUND_GROUP_BASE);
-#endif
putInGunMine(tux);
break;
}
diff --git a/src/item.c b/src/item.c
index bcde2b1..ae9ab71 100644
--- a/src/item.c
+++ b/src/item.c
@@ -17,6 +17,7 @@
#include "layer.h"
#include "screen_world.h"
#include "screen_setting.h"
+#include "term.h"
#endif
#ifdef BUBLIC_SERVER
@@ -122,6 +123,9 @@ item_t* newItem(int x, int y, int type, tux_t *author)
void addNewItem(list_t *listItem, tux_t *author)
{
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+#endif
arena_t *arena;
item_t *item;
int new_x, new_y;
@@ -178,6 +182,12 @@ void addNewItem(list_t *listItem, tux_t *author)
{
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
}
+
+#ifndef BUBLIC_SERVER
+ sprintf(msg, "in arena is new item\n");
+ appendTextInTerm(msg);
+#endif
+
}
#ifndef BUBLIC_SERVER
@@ -321,12 +331,11 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
{
int x, y;
- delListItem(listItem, j, destroyItem);
-
x = ( thisItem->x + thisItem->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2;
y = ( thisItem->y + thisItem->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2;
-
- addList(listItem, newItem(x, y, ITEM_BIG_EXPLOSION, NULL) );
+ addList(listItem, newItem(x, y, ITEM_BIG_EXPLOSION, NULL) );
+
+ delListItem(listItem, j, destroyItem);
j--;
}
break;
@@ -348,6 +357,9 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
void eventGiveTuxItem(tux_t *tux, list_t *listItem)
{
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+#endif
item_t *thisItem;
int x, y, w, h;
int i;
@@ -384,6 +396,11 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem)
tux->gun = thisItem->type;
delListItem(listItem, i, destroyItem);
i--;
+
+#ifndef BUBLIC_SERVER
+ sprintf(msg, "tux with id %d has new gun\n", tux->id);
+ appendTextInTerm(msg);
+#endif
break;
case ITEM_MINE :
@@ -425,6 +442,11 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem)
tux->bonus_time = TUX_MAX_BONUS;
delListItem(listItem, i, destroyItem);
i--;
+
+#ifndef BUBLIC_SERVER
+ sprintf(msg, "tux with id %d bonus enabled\n", tux->id);
+ appendTextInTerm(msg);
+#endif
break;
}
diff --git a/src/main.c b/src/main.c
index 41dc5f7..a9622e3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,9 @@
#include "screen_table.h"
#include "screen_credits.h"
#include "homeDirector.h"
+#include "item.h"
+#include "shot.h"
+#include "arenaFile.h"
#include "panel.h"
#include "audio.h"
#include "sound.h"
@@ -31,13 +34,6 @@
#endif
-#include "wall.h"
-#include "shot.h"
-#include "myTimer.h"
-#include "arenaFile.h"
-#include "item.h"
-#include "publicServer.h"
-
static int my_argc;
static char **my_argv;
diff --git a/src/proto.c b/src/proto.c
index e2ade65..4372217 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -21,6 +21,7 @@
#include "screen_setting.h"
#include "screen_choiceArena.h"
#include "client.h"
+#include "term.h"
#endif
#ifdef BUBLIC_SERVER
@@ -102,7 +103,7 @@ void proto_send_status_server(int type, client_t *client)
"clients: %d\n"
"maxclients: %d\n"
"uptime: %d\n",
- TUXANCI_NG_VERSION, getListServerClient()->count,
+ TUXANCI_NG_VERSION, getWorldArena()->listTux->count,
getServerMaxClients(), getMyTime() );
proto_send(type, client, msg);
@@ -116,7 +117,7 @@ void proto_recv_status_server(client_t *client, char *msg)
void proto_send_init_server(int type, client_t *client, client_t *client2)
{
char msg[STR_PROTO_SIZE];
- int n = 9999;
+ int n = WORLD_COUNT_ROUND_UNLIMITED;
assert( client2 != NULL );
@@ -157,7 +158,6 @@ void proto_recv_init_client(char *msg)
getSettingNameRight(tux->name);
-// proto_send_context_client(tux);
addList(getWorldArena()->listTux, tux);
}
@@ -262,6 +262,10 @@ void proto_recv_newtux_client(char *msg)
if( tux == NULL )
{
+ char term_msg[STR_SIZE];
+ sprintf(term_msg, "connect new client( id = %d)\n", id);
+ appendTextInTerm(term_msg);
+
tux = newTux();
tux->control = TUX_CONTROL_NET;
addList(getWorldArena()->listTux, tux);
@@ -350,6 +354,10 @@ void proto_recv_score_client(char *msg)
if( tux != NULL )
{
+ char term_msg[STR_SIZE];
+ sprintf(term_msg, "tux with id %d set score to %d\n", tux->id, score);
+ appendTextInTerm(term_msg);
+
tux->score = score;
}
@@ -385,8 +393,12 @@ void proto_recv_deltux_client(char *msg)
if( tux != NULL )
{
+ char term_msg[STR_SIZE];
int index;
-
+
+ sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
+ appendTextInTerm(term_msg);
+
index = searchListItem(getWorldArena()->listTux, tux);
delListItem(getWorldArena()->listTux, index, destroyTux);
}
@@ -416,6 +428,7 @@ void proto_send_additem_server(int type, client_t *client, item_t *p)
void proto_recv_additem_client(char *msg)
{
+ char term_msg[STR_SIZE];
char cmd[STR_PROTO_SIZE];
int type, x, y, count, frame, id;
item_t *item;
@@ -436,6 +449,10 @@ void proto_recv_additem_client(char *msg)
item->frame = frame;
addList(getWorldArena()->listItem, item);
+
+ sprintf(term_msg, "in arena is new item\n");
+ appendTextInTerm(term_msg);
+
}
#endif
@@ -487,38 +504,6 @@ void proto_recv_shot_client(char *msg)
#endif
-/*
-#ifndef BUBLIC_SERVER
-
-void proto_send_context_client(tux_t *tux)
-{
- char msg[STR_PROTO_SIZE];
-
- assert( tux != NULL );
-
- sprintf(msg, "context %s\n", tux->name);
-
- sendServer(msg);
-}
-
-#endif
-
-void proto_recv_context_server(client_t *client, char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- char name[STR_NAME_SIZE];
-
- assert( client != NULL );
- assert( msg != NULL );
-
- sscanf(msg, "%s %s\n", cmd, name);
-
- strcpy(client->tux->name, name);
-
-// proto_send_newtux_server(NULL, client->tux);
-}
-*/
-
#ifndef BUBLIC_SERVER
void proto_send_ping_client()
diff --git a/src/publicServer.c b/src/publicServer.c
index 2f07b3d..204cdba 100644
--- a/src/publicServer.c
+++ b/src/publicServer.c
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <signal.h>
+#include <time.h>
#include "main.h"
#include "list.h"
@@ -10,10 +12,10 @@
#include "wall.h"
#include "teleport.h"
#include "pipe.h"
-#include "item.h"
-#include "shot.h"
#include "myTimer.h"
#include "arena.h"
+#include "item.h"
+#include "shot.h"
#include "arenaFile.h"
#include "proto.h"
#include "publicServer.h"
@@ -23,6 +25,9 @@ static int arenaId;
static arena_t *arena;
static bool_t isSignalEnd;
+static int my_argc;
+static char **my_argv;
+
arena_t* getWorldArena()
{
return arena;
@@ -99,6 +104,7 @@ void eventPublicServer()
{
static my_time_t lastActive = 0;
my_time_t interval;
+ int i;
eventNetMultiplayer();
@@ -118,6 +124,7 @@ void eventPublicServer()
{
return;
}
+
/*
printf("interval = %d\n", interval);
*/
@@ -126,12 +133,15 @@ void eventPublicServer()
eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport);
eventConflictTuxWithShot(arena->listTux, arena->listShot);
- eventConflictShotWithWall(arena->listWall, arena->listShot);
- eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
- eventConflictShotWithPipe(arena->listPipe, arena->listShot);
- eventConflictShotWithItem(arena->listItem, arena->listShot);
+ for( i = 0 ; i < 4 ; i++)
+ {
+ eventMoveListShot(arena->listShot);
+ eventConflictShotWithWall(arena->listWall, arena->listShot);
+ eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
+ eventConflictShotWithPipe(arena->listPipe, arena->listShot);
+ eventConflictShotWithItem(arena->listItem, arena->listShot);
+ }
- eventMoveListShot(arena->listShot);
eventListItem(arena->listItem);
eventListTux(arena->listTux);
@@ -154,3 +164,80 @@ void quitPublicServer()
exit(0);
}
+char* getParam(char *s)
+{
+ int i;
+
+ for( i = 0 ; i < my_argc - 1 ; i++ )
+ {
+ if( strcmp(s, my_argv[i]) == 0 )
+ {
+ return my_argv[i+1];
+ }
+ }
+
+ return NULL;
+}
+
+char* getParamElse(char *s1, char *s2)
+{
+ char *ret;
+ ret = getParam(s1);
+
+ if( ret == NULL)
+ {
+ return s2;
+ }
+
+ return ret;
+}
+
+bool_t isParamFlag(char *s)
+{
+ int i;
+
+ for( i = 0 ; i < my_argc ; i++ )
+ {
+ if( strcmp(s, my_argv[i]) == 0 )
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+char *getString(int n)
+{
+ char str[STR_NUM_SIZE];
+ sprintf(str, "%d", n);
+ return strdup(str);
+}
+
+int main(int argc, char *argv[])
+{
+ srand( (unsigned) time(NULL) );
+
+ my_argc = argc;
+ my_argv = argv;
+
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGINT, my_handler_quit);
+ signal(SIGTERM, my_handler_quit);
+ signal(SIGQUIT, my_handler_quit);
+
+ if( initPublicServer() < 0 )
+ {
+ quitPublicServer();
+ return -1;
+ }
+
+ while(1)
+ {
+ eventPublicServer();
+ }
+
+ return 0;
+}
+
+
diff --git a/src/screen_world.c b/src/screen_world.c
index d4540b1..49d94ac 100644
--- a/src/screen_world.c
+++ b/src/screen_world.c
@@ -31,6 +31,7 @@
#include "arena.h"
#include "arenaFile.h"
#include "proto.h"
+#include "term.h"
static arena_t *arena;
static int count;
@@ -49,17 +50,7 @@ void setGameType()
int ret = 0;
ret = initNetMuliplayer( getSettingGameType(), getSettingIP(), getSettingPort() );
-/*
- if( getSettingGameType() == NET_GAME_TYPE_SERVER )
- {
- ret = initServer( getSettingPort() );
- }
- if( getSettingGameType() == NET_GAME_TYPE_CLIENT )
- {
- ret = initClient( getSettingPort() , getSettingIP() );
- }
-*/
if( ret != 0 )
{
fprintf(stderr, "Chyba inicalizacie sieti !\n");
@@ -99,7 +90,8 @@ static void timer_endArena()
void countRoundInc()
{
- if( count >= max_count )
+ if( count == WORLD_COUNT_ROUND_UNLIMITED ||
+ count >= max_count )
{
return;
}
@@ -201,6 +193,7 @@ void drawWorld()
}
drawPanel(arena->listTux);
+ drawTerm();
}
int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2)
@@ -371,6 +364,8 @@ void tuxControl(tux_t *p)
void eventWorld()
{
+ int i;
+
if( arena == NULL )
{
eventNetMultiplayer();
@@ -379,21 +374,26 @@ void eventWorld()
return;
}
+ eventNetMultiplayer();
+
eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport);
eventConflictTuxWithShot(arena->listTux, arena->listShot);
- eventConflictShotWithWall(arena->listWall, arena->listShot);
- eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
- eventConflictShotWithPipe(arena->listPipe, arena->listShot);
- eventConflictShotWithItem(arena->listItem, arena->listShot);
+ for( i = 0 ; i < 4 ; i++)
+ {
+ eventMoveListShot(arena->listShot);
+ eventConflictShotWithWall(arena->listWall, arena->listShot);
+ eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
+ eventConflictShotWithPipe(arena->listPipe, arena->listShot);
+ eventConflictShotWithItem(arena->listItem, arena->listShot);
+ }
- eventMoveListShot(arena->listShot);
eventListItem(arena->listItem);
-
- eventNetMultiplayer();
+
eventListTux(arena->listTux);
eventTimer();
+ eventTerm();
eventEnd();
eventEsc();
}
@@ -406,6 +406,7 @@ void startWorld()
count = 0;
setGameType();
+ initTerm();
prepareArena();
initTimer();
}
@@ -469,6 +470,7 @@ void stoptWorld()
delAllImageInGroup(IMAGE_GROUP_USER);
delAllMusicInGroup(MUSIC_GROUP_USER);
quitTimer();
+ quitTerm();
}
void initWorld()
diff --git a/src/server.c b/src/server.c
index 91e26c0..e1dacf1 100644
--- a/src/server.c
+++ b/src/server.c
@@ -226,15 +226,6 @@ void sendClient(client_t *p, char *msg)
#ifdef SUPPORT_NET_UNIX_TCP
ret = writeTcpSocket(p->socket_tcp, msg, strlen(msg));
-#endif
-
-#ifdef SUPPORT_NET_UNIX_UDP
- ret = writeUdpSocket(sock_server_udp, p->socket_udp, msg, strlen(msg));
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
- ret = writeSdlUdpSocket(sock_server_sdl_udp, p->socket_sdl_udp, msg, strlen(msg));
-#endif
if( ret == 0 )
{
@@ -247,6 +238,15 @@ void sendClient(client_t *p, char *msg)
fprintf(stderr, "nastala chyba pri posielanie spravy clientovy\n");
p->status = NET_STATUS_ZOMBIE;
}
+#endif
+
+#ifdef SUPPORT_NET_UNIX_UDP
+ ret = writeUdpSocket(sock_server_udp, p->socket_udp, msg, strlen(msg));
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+ ret = writeSdlUdpSocket(sock_server_sdl_udp, p->socket_sdl_udp, msg, strlen(msg));
+#endif
}
}
@@ -598,7 +598,7 @@ static void eventClientUdpSelect(sock_udp_t *sock_server)
if( client == NULL )
{
- if( listClient->count+1 > maxClients )
+ if( getWorldArena()->listTux->count+1 > maxClients )
{
destroySockUdp(sock_client);
return;
diff --git a/src/term.c b/src/term.c
new file mode 100644
index 0000000..62dcd8f
--- /dev/null
+++ b/src/term.c
@@ -0,0 +1,105 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "interface.h"
+#include "font.h"
+#include "term.h"
+#include "myTimer.h"
+
+typedef struct struct_term_t
+{
+ char *text;
+ my_time_t delTime;
+} term_t;
+
+static list_t *listText;
+
+static term_t* newTermItem(char *s)
+{
+ term_t *new;
+ char *line;
+ int len;
+
+ assert( s != NULL );
+
+ line = strdup(s);
+ len = strlen(line);
+ line[len-1] = '\0';
+
+ new = malloc( sizeof(term_t) );
+ memset(new, 0, sizeof(term_t));
+
+ new->text = line;
+ new->delTime = getMyTime() + TERM_DEL_TEXT_TIMEOUT;
+
+ return new;
+}
+
+static void destroyTermItem(term_t *p)
+{
+ assert( p != NULL );
+
+ free(p->text);
+ free(p);
+}
+
+void initTerm()
+{
+ listText = newList();
+}
+
+void drawTerm()
+{
+ int i;
+
+ for( i = 0 ; i < listText->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)( (term_t *)listText->list[i] )->text;
+ drawFont(line, 10, 10 + i*20, COLOR_WHITE);
+ }
+}
+
+void eventTerm()
+{
+ my_time_t currentTime;
+ int i;
+
+ currentTime = getMyTime();
+
+
+ for( i = 0 ; i < listText->count ; i++ )
+ {
+ my_time_t thisTime;
+
+ thisTime = ( (term_t *)listText->list[i] )->delTime;
+
+ if( currentTime > thisTime )
+ {
+ delListItem(listText, i, destroyTermItem);
+ i--;
+ }
+ }
+
+}
+
+void appendTextInTerm(char *s)
+{
+
+ addList(listText, newTermItem(s) );
+
+ if( listText->count > TERM_MAX_LINES )
+ {
+ delListItem(listText, 0, destroyTermItem);
+ }
+}
+
+void quitTerm()
+{
+ assert( listText != NULL );
+ destroyListItem(listText, destroyTermItem);
+}
diff --git a/src/tux.c b/src/tux.c
index 9672f28..60cdd2a 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -23,6 +23,7 @@
#include "sound.h"
#include "layer.h"
#include "screen_world.h"
+#include "term.h"
#endif
#ifdef BUBLIC_SERVER
@@ -360,15 +361,20 @@ static void timer_tuxCanSwitchGun(void *p)
void eventTuxIsDead(tux_t *tux)
{
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+#endif
+
if( tux->status == TUX_STATUS_DEAD )
{
return;
}
#ifndef BUBLIC_SERVER
+ sprintf(msg, "tux with id %d is dead\n", tux->id);
playSound("dead", SOUND_GROUP_BASE);
+ appendTextInTerm(msg);
#endif
- printf("tux id %d is dead\n", tux->id);
tux->status = TUX_STATUS_DEAD;
memset(tux->shot, 0, sizeof(int) * GUN_COUNT);
@@ -397,6 +403,14 @@ static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot)
{
if( shot->author != NULL && shot->author != tux )
{
+#ifndef BUBLIC_SERVER
+ char term_msg[STR_SIZE];
+
+ sprintf(term_msg, "tux with id %d set score to %d\n",
+ shot->author->id, shot->author->score+1);
+
+ appendTextInTerm(term_msg);
+#endif
shot->author->score++;
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
@@ -412,11 +426,15 @@ static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot)
void tuxTeleport(tux_t *tux)
{
int x, y;
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+#endif
#ifndef BUBLIC_SERVER
+ sprintf(msg, "tux with id %d teleporting\n", tux->id);
playSound("teleport", SOUND_GROUP_BASE);
+ appendTextInTerm(msg);
#endif
- printf("tux id %d teleporting\n", tux->id);
if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
{
@@ -569,21 +587,23 @@ void moveTux(tux_t *tux, int n)
if( tux->frame == TUX_MAX_ANIMATION_FRAME ) tux->frame = 0;
}
+
+// printf("move %d %d %d\n", tux->id, tux->x, tux->y);
}
void switchTuxGun(tux_t *tux)
{
int i;
-
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+#endif
+
if( tux->control != TUX_CONTROL_NET &&
tux->isCanSwitchGun == FALSE )
{
return;
}
-#ifndef BUBLIC_SERVER
- playSound("switch_gun", SOUND_GROUP_BASE);
-#endif
for( i = tux->gun+1 ; i < GUN_COUNT ; i++ )
{
if( tux->shot[i] > 0 )
@@ -591,6 +611,11 @@ void switchTuxGun(tux_t *tux)
tux->gun = i;
tux->isCanSwitchGun = FALSE;
addTimer(timer_tuxCanSwitchGun, newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN );
+#ifndef BUBLIC_SERVER
+ playSound("switch_gun", SOUND_GROUP_BASE);
+ sprintf(msg, "tux with id %d switch gun\n", tux->id);
+ appendTextInTerm(msg);
+#endif
return;
}
}
@@ -602,6 +627,13 @@ void switchTuxGun(tux_t *tux)
tux->gun = i;
tux->isCanSwitchGun = FALSE;
addTimer(timer_tuxCanSwitchGun, newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN );
+
+#ifndef BUBLIC_SERVER
+ playSound("switch_gun", SOUND_GROUP_BASE);
+ sprintf(msg, "tux with id %d switch gun\n", tux->id);
+ appendTextInTerm(msg);
+#endif
+
return;
}
}
@@ -617,6 +649,10 @@ void shotTux(tux_t *tux)
return;
}
+#ifndef BUBLIC_SERVER
+ playSound("switch_gun", SOUND_GROUP_BASE);
+#endif
+
shotInGun(tux);
tux->isCanShot = FALSE;
@@ -663,6 +699,13 @@ static void pickUpGun(tux_t *tux)
if( tux->pickup_time == TUX_MAX_PICKUP )
{
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+ playSound("switch_gun", SOUND_GROUP_BASE);
+ sprintf(msg, "tux with id %d pickup\n", tux->id);
+ appendTextInTerm(msg);
+#endif
+
tux->gun = GUN_SIMPLE;
tux->shot[ tux->gun ] = GUN_MAX_SHOT;
tux->pickup_time = 0;
@@ -679,8 +722,12 @@ static void eventBonus(tux_t *tux)
tux->bonus_time--;
}
- if( tux->bonus_time == 0 && getNetTypeGame() != NET_GAME_TYPE_CLIENT )
+ if( tux->bonus_time == 0 && getNetTypeGame() != NET_GAME_TYPE_CLIENT )
{
+#ifndef BUBLIC_SERVER
+ char msg[STR_SIZE];
+#endif
+
if( tux->bonus == BONUS_GHOST )
{
int x, y, w, h;
@@ -694,6 +741,11 @@ static void eventBonus(tux_t *tux)
tux->bonus = BONUS_NONE;
+#ifndef BUBLIC_SERVER
+ sprintf(msg, "tux with id %d bonus disabled\n", tux->id);
+ appendTextInTerm(msg);
+#endif
+
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);