summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:50:54 +0200
committerTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:50:54 +0200
commite12753d2ec9db83ec08bb9db63902a82fb245cdd (patch)
tree6e4a63b790d6335f969f88b797a927e0fb25f37a /src/client
parent0b4d9821c7333b8c4bdf7e0eeb750aef502a1137 (diff)
X
Diffstat (limited to 'src/client')
-rw-r--r--src/client/chat.c321
-rw-r--r--src/client/chat.c~245
-rw-r--r--src/client/client.c456
-rw-r--r--src/client/client.c~388
-rw-r--r--src/client/configFile.c220
-rw-r--r--src/client/configFile.c~138
-rwxr-xr-xsrc/client/font.c156
-rw-r--r--src/client/font.c~138
-rw-r--r--src/client/game.c119
-rw-r--r--src/client/game.c~122
-rw-r--r--src/client/hotKey.c175
-rw-r--r--src/client/hotKey.c~158
-rwxr-xr-xsrc/client/image.c195
-rw-r--r--src/client/image.c~176
-rwxr-xr-xsrc/client/interface.c336
-rw-r--r--src/client/interface.c~286
-rw-r--r--src/client/keyboardBuffer.c136
-rw-r--r--src/client/keyboardBuffer.c~151
-rwxr-xr-xsrc/client/layer.c260
-rw-r--r--src/client/layer.c~221
-rw-r--r--src/client/panel.c276
-rw-r--r--src/client/panel.c~180
-rw-r--r--src/client/pauza.c63
-rw-r--r--src/client/pauza.c~68
-rw-r--r--src/client/radar.c135
-rw-r--r--src/client/radar.c~121
-rw-r--r--src/client/saveDialog.c172
-rw-r--r--src/client/saveDialog.c~147
-rw-r--r--src/client/saveLoad.c384
-rw-r--r--src/client/saveLoad.c~270
-rw-r--r--src/client/screen.c223
-rw-r--r--src/client/screen.c~193
-rw-r--r--src/client/term.c216
-rw-r--r--src/client/term.c~156
34 files changed, 5131 insertions, 1870 deletions
diff --git a/src/client/chat.c b/src/client/chat.c
index eeca8d8..e6bba4b 100644
--- a/src/client/chat.c
+++ b/src/client/chat.c
@@ -33,213 +33,226 @@ static bool_t receivedNewMsg;
static void hotkey_chat();
-static void hotkey_chat()
+static void
+hotkey_chat()
{
- chat_active = TRUE;
- receivedNewMsg = FALSE;
+ chat_active = TRUE;
+ receivedNewMsg = FALSE;
- disableHotKey(SDLK_RETURN);
- disableHotKey(SDLK_p);
+ disableHotKey(SDLK_RETURN);
+ disableHotKey(SDLK_p);
- enableKeyboardBuffer();
- clearKeyboardBuffer();
+ enableKeyboardBuffer();
+ clearKeyboardBuffer();
}
-void initChat()
+void
+initChat()
{
- g_chat = addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER);
-
- listText = newList();
- strcpy(line, "");
- chat_active = FALSE;
- registerHotKey(SDLK_RETURN, hotkey_chat);
-
- receivedNewMsg = FALSE;
- line_time = 0;
- line_atime = 0;
- timeBlick = 0;
+ g_chat =
+ addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER);
+
+ listText = newList();
+ strcpy(line, "");
+ chat_active = FALSE;
+ registerHotKey(SDLK_RETURN, hotkey_chat);
+
+ receivedNewMsg = FALSE;
+ line_time = 0;
+ line_atime = 0;
+ timeBlick = 0;
}
-void drawChat()
+void
+drawChat()
{
- char str[STR_SIZE];
- int i;
+ char str[STR_SIZE];
+ int i;
- if (chat_active == FALSE) {
- return;
- }
+ if (chat_active == FALSE) {
+ return;
+ }
- drawImage(g_chat,
- CHAT_LOCATION_X, CHAT_LOCATION_Y,
- 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y);
+ drawImage(g_chat,
+ CHAT_LOCATION_X, CHAT_LOCATION_Y,
+ 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y);
- for (i = 0; i < listText->count; i++) {
- char *s;
+ for (i = 0; i < listText->count; i++) {
+ char *s;
- s = (char *)listText->list[i];
+ s = (char *) listText->list[i];
- drawFontMaxSize(s,
- CHAT_LOCATION_X + 5, CHAT_LOCATION_Y + 5 + i * 20,
- CHAT_SIZE_X - 10, 20, COLOR_WHITE);
- }
+ drawFontMaxSize(s,
+ CHAT_LOCATION_X + 5, CHAT_LOCATION_Y + 5 + i * 20,
+ CHAT_SIZE_X - 10, 20, COLOR_WHITE);
+ }
- strcpy(str, line);
+ strcpy(str, line);
- if (timeBlick > CHAT_TIME_BLICK_CURSOR / 2) {
- strcat(str, "\f");
- }
+ if (timeBlick > CHAT_TIME_BLICK_CURSOR / 2) {
+ strcat(str, "\f");
+ }
- timeBlick++;
+ timeBlick++;
- if (timeBlick == CHAT_TIME_BLICK_CURSOR) {
- timeBlick = 0;
- }
+ if (timeBlick == CHAT_TIME_BLICK_CURSOR) {
+ timeBlick = 0;
+ }
- drawFont(str, CHAT_LOCATION_X + 5, (CHAT_LOCATION_Y + 5) + (CHAT_MAX_LINES * 20), COLOR_WHITE);
+ drawFont(str, CHAT_LOCATION_X + 5,
+ (CHAT_LOCATION_Y + 5) + (CHAT_MAX_LINES * 20), COLOR_WHITE);
}
-static void processMessageKey(SDL_keysym keysym)
+static void
+processMessageKey(SDL_keysym keysym)
{
- int w, h;
- int len;
- //int i;
-
- if (line_atime < 100)
- line_atime ++;
-
- len = strlen(line);
- getTextSize(line, &w, &h);
-
- if (w > CHAT_SIZE_X - 40) {
- return;
- }
-
- /* processing of backspace */
- if (keysym.sym == SDLK_BACKSPACE && len > 0) {
- line[len - 1] = '\0';
- return;
- }
-
- /* processing of printable chars but not letters */
- if ((keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT)
- || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE)) {
- /* here would be much better to put 'strcat' as 'line' is expected
- * to be full of '0' up to its end
- */
- line[len] = keysym.sym;
- }
-
- /* processing of letters */
- if (keysym.sym >= SDLK_a && keysym.sym <= SDLK_z) {
- char c = keysym.sym;
- if (keysym.mod == KMOD_SHIFT) {
- c = toupper(c);
- }
- /* here would be much better to put 'strcat' as 'line' is expected
- * to be full of '0' up to its end
- */
- line[len] = c;
- }
-
- return;
+ int w, h;
+ int len;
+ //int i;
+
+ if (line_atime < 100)
+ line_atime++;
+
+ len = strlen(line);
+ getTextSize(line, &w, &h);
+
+ if (w > CHAT_SIZE_X - 40) {
+ return;
+ }
+
+ /* processing of backspace */
+ if (keysym.sym == SDLK_BACKSPACE && len > 0) {
+ line[len - 1] = '\0';
+ return;
+ }
+
+ /* processing of printable chars but not letters */
+ if ((keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT)
+ || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE)) {
+ /* here would be much better to put 'strcat' as 'line' is expected
+ * to be full of '0' up to its end
+ */
+ line[len] = keysym.sym;
+ }
+
+ /* processing of letters */
+ if (keysym.sym >= SDLK_a && keysym.sym <= SDLK_z) {
+ char c = keysym.sym;
+ if (keysym.mod == KMOD_SHIFT) {
+ c = toupper(c);
+ }
+ /* here would be much better to put 'strcat' as 'line' is expected
+ * to be full of '0' up to its end
+ */
+ line[len] = c;
+ }
+
+ return;
}
-static void sendNewMessage()
+static void
+sendNewMessage()
{
- if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) {
- proto_send_chat_client(line);
- }
+ if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) {
+ proto_send_chat_client(line);
+ }
- if (getNetTypeGame() == NET_GAME_TYPE_SERVER) {
- char out[STR_PROTO_SIZE];
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER) {
+ char out[STR_PROTO_SIZE];
- snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n",
- getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line);
+ snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n",
+ getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line);
- proto_send_chat_server(PROTO_SEND_ALL, NULL, out);
- }
+ proto_send_chat_server(PROTO_SEND_ALL, NULL, out);
+ }
}
-static void eventChatDisable()
-{
- chat_active = FALSE;
- memset(line, '\0', STR_SIZE);
-
- enableHotKey(SDLK_RETURN);
- enableHotKey(SDLK_p);
+static void
+eventChatDisable()
+{
+ chat_active = FALSE;
+ memset(line, '\0', STR_SIZE);
- disableKeyboardBuffer();
- clearKeyboardBuffer();
+ enableHotKey(SDLK_RETURN);
+ enableHotKey(SDLK_p);
+
+ disableKeyboardBuffer();
+ clearKeyboardBuffer();
}
-static void eventChatEnable()
+static void
+eventChatEnable()
{
- /* The chat window is displayed. It is needed to process all keys in the buffer
- * but when ENTER is pressed the chat row is sent to the server
- */
-
- while (isAnyKeyInKeyboardBuffer() == TRUE) {
- SDL_keysym key;
- key = popKeyFromKeyboardBuffer();
-
- if (key.sym == SDLK_RETURN) {
- if (strcmp(line, "") != 0) {
- /* the chat row is already written - it is needed to send it */
- sendNewMessage();
- memset(line, '\0', STR_SIZE);
- continue; /* continue with other keys */
- }
- else {
- /* the chat row is empty - it is needed to turn off the chat window */
- eventChatDisable();
- /* turn off key catching into the buffer and clear the buffer */
- //disableKeyboardBuffer();
- //clearKeyboardBuffer();
- }
- }
-
- processMessageKey(key);
- }
+ /* The chat window is displayed. It is needed to process all keys in the buffer
+ * but when ENTER is pressed the chat row is sent to the server
+ */
+
+ while (isAnyKeyInKeyboardBuffer() == TRUE) {
+ SDL_keysym key;
+ key = popKeyFromKeyboardBuffer();
+
+ if (key.sym == SDLK_RETURN) {
+ if (strcmp(line, "") != 0) {
+ /* the chat row is already written - it is needed to send it */
+ sendNewMessage();
+ memset(line, '\0', STR_SIZE);
+ continue; /* continue with other keys */
+ }
+ else {
+ /* the chat row is empty - it is needed to turn off the chat window */
+ eventChatDisable();
+ /* turn off key catching into the buffer and clear the buffer */
+ //disableKeyboardBuffer();
+ //clearKeyboardBuffer();
+ }
+ }
+
+ processMessageKey(key);
+ }
}
/**
* Processing of chat 'events'
*/
-void eventChat()
+void
+eventChat()
{
- if (isChatActive()) {
- eventChatEnable();
- }
+ if (isChatActive()) {
+ eventChatEnable();
+ }
}
-bool_t isChatActive()
+bool_t
+isChatActive()
{
- return chat_active;
+ return chat_active;
}
-bool_t isRecivedNewMsg()
+bool_t
+isRecivedNewMsg()
{
- return receivedNewMsg;
+ return receivedNewMsg;
}
-void addToChat(char *s)
+void
+addToChat(char *s)
{
- addList(listText, strdup(s));
+ addList(listText, strdup(s));
- if (listText->count > CHAT_MAX_LINES) {
- delListItem(listText, 0, free);
- }
+ if (listText->count > CHAT_MAX_LINES) {
+ delListItem(listText, 0, free);
+ }
- if (chat_active == FALSE) {
- receivedNewMsg = TRUE;
- }
+ if (chat_active == FALSE) {
+ receivedNewMsg = TRUE;
+ }
}
-void quitChat()
+void
+quitChat()
{
- assert(listText != NULL);
+ assert(listText != NULL);
- unregisterHotKey(SDLK_RETURN);
- destroyListItem(listText, free);
+ unregisterHotKey(SDLK_RETURN);
+ destroyListItem(listText, free);
}
-
diff --git a/src/client/chat.c~ b/src/client/chat.c~
new file mode 100644
index 0000000..eeca8d8
--- /dev/null
+++ b/src/client/chat.c~
@@ -0,0 +1,245 @@
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <assert.h>
+#include <SDL.h>
+
+#include "main.h"
+#include "list.h"
+#include "myTimer.h"
+#include "image.h"
+#include "serverSendMsg.h"
+
+#include "net_multiplayer.h"
+#include "screen_world.h"
+#include "proto.h"
+#include "interface.h"
+#include "chat.h"
+#include "font.h"
+#include "keyboardBuffer.h"
+#include "hotKey.h"
+
+static image_t *g_chat;
+
+static list_t *listText;
+
+static char line[STR_SIZE];
+
+static int line_time, line_atime;
+static int timeBlick;
+
+static bool_t chat_active;
+static bool_t receivedNewMsg;
+
+static void hotkey_chat();
+
+static void hotkey_chat()
+{
+ chat_active = TRUE;
+ receivedNewMsg = FALSE;
+
+ disableHotKey(SDLK_RETURN);
+ disableHotKey(SDLK_p);
+
+ enableKeyboardBuffer();
+ clearKeyboardBuffer();
+}
+
+void initChat()
+{
+ g_chat = addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER);
+
+ listText = newList();
+ strcpy(line, "");
+ chat_active = FALSE;
+ registerHotKey(SDLK_RETURN, hotkey_chat);
+
+ receivedNewMsg = FALSE;
+ line_time = 0;
+ line_atime = 0;
+ timeBlick = 0;
+}
+
+void drawChat()
+{
+ char str[STR_SIZE];
+ int i;
+
+ if (chat_active == FALSE) {
+ return;
+ }
+
+ drawImage(g_chat,
+ CHAT_LOCATION_X, CHAT_LOCATION_Y,
+ 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y);
+
+ for (i = 0; i < listText->count; i++) {
+ char *s;
+
+ s = (char *)listText->list[i];
+
+ drawFontMaxSize(s,
+ CHAT_LOCATION_X + 5, CHAT_LOCATION_Y + 5 + i * 20,
+ CHAT_SIZE_X - 10, 20, COLOR_WHITE);
+ }
+
+ strcpy(str, line);
+
+ if (timeBlick > CHAT_TIME_BLICK_CURSOR / 2) {
+ strcat(str, "\f");
+ }
+
+ timeBlick++;
+
+ if (timeBlick == CHAT_TIME_BLICK_CURSOR) {
+ timeBlick = 0;
+ }
+
+ drawFont(str, CHAT_LOCATION_X + 5, (CHAT_LOCATION_Y + 5) + (CHAT_MAX_LINES * 20), COLOR_WHITE);
+}
+
+static void processMessageKey(SDL_keysym keysym)
+{
+ int w, h;
+ int len;
+ //int i;
+
+ if (line_atime < 100)
+ line_atime ++;
+
+ len = strlen(line);
+ getTextSize(line, &w, &h);
+
+ if (w > CHAT_SIZE_X - 40) {
+ return;
+ }
+
+ /* processing of backspace */
+ if (keysym.sym == SDLK_BACKSPACE && len > 0) {
+ line[len - 1] = '\0';
+ return;
+ }
+
+ /* processing of printable chars but not letters */
+ if ((keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT)
+ || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE)) {
+ /* here would be much better to put 'strcat' as 'line' is expected
+ * to be full of '0' up to its end
+ */
+ line[len] = keysym.sym;
+ }
+
+ /* processing of letters */
+ if (keysym.sym >= SDLK_a && keysym.sym <= SDLK_z) {
+ char c = keysym.sym;
+ if (keysym.mod == KMOD_SHIFT) {
+ c = toupper(c);
+ }
+ /* here would be much better to put 'strcat' as 'line' is expected
+ * to be full of '0' up to its end
+ */
+ line[len] = c;
+ }
+
+ return;
+}
+
+static void sendNewMessage()
+{
+ if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) {
+ proto_send_chat_client(line);
+ }
+
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER) {
+ char out[STR_PROTO_SIZE];
+
+ snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n",
+ getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line);
+
+ proto_send_chat_server(PROTO_SEND_ALL, NULL, out);
+ }
+}
+
+static void eventChatDisable()
+{
+ chat_active = FALSE;
+ memset(line, '\0', STR_SIZE);
+
+ enableHotKey(SDLK_RETURN);
+ enableHotKey(SDLK_p);
+
+ disableKeyboardBuffer();
+ clearKeyboardBuffer();
+}
+
+static void eventChatEnable()
+{
+ /* The chat window is displayed. It is needed to process all keys in the buffer
+ * but when ENTER is pressed the chat row is sent to the server
+ */
+
+ while (isAnyKeyInKeyboardBuffer() == TRUE) {
+ SDL_keysym key;
+ key = popKeyFromKeyboardBuffer();
+
+ if (key.sym == SDLK_RETURN) {
+ if (strcmp(line, "") != 0) {
+ /* the chat row is already written - it is needed to send it */
+ sendNewMessage();
+ memset(line, '\0', STR_SIZE);
+ continue; /* continue with other keys */
+ }
+ else {
+ /* the chat row is empty - it is needed to turn off the chat window */
+ eventChatDisable();
+ /* turn off key catching into the buffer and clear the buffer */
+ //disableKeyboardBuffer();
+ //clearKeyboardBuffer();
+ }
+ }
+
+ processMessageKey(key);
+ }
+}
+
+/**
+ * Processing of chat 'events'
+ */
+void eventChat()
+{
+ if (isChatActive()) {
+ eventChatEnable();
+ }
+}
+
+bool_t isChatActive()
+{
+ return chat_active;
+}
+
+bool_t isRecivedNewMsg()
+{
+ return receivedNewMsg;
+}
+
+void addToChat(char *s)
+{
+ addList(listText, strdup(s));
+
+ if (listText->count > CHAT_MAX_LINES) {
+ delListItem(listText, 0, free);
+ }
+
+ if (chat_active == FALSE) {
+ receivedNewMsg = TRUE;
+ }
+}
+
+void quitChat()
+{
+ assert(listText != NULL);
+
+ unregisterHotKey(SDLK_RETURN);
+ destroyListItem(listText, free);
+}
+
diff --git a/src/client/client.c b/src/client/client.c
index 7512ab8..808dc2b 100644
--- a/src/client/client.c
+++ b/src/client/client.c
@@ -47,342 +47,334 @@ static int traffic_up;
typedef struct proto_cmd_client_struct
{
- char *name;
- int len;
- void (*fce_proto)(char *msg);
+ char *name;
+ int len;
+ void (*fce_proto) (char *msg);
} proto_cmd_client_t;
-static proto_cmd_client_t proto_cmd_list[] =
-{
- { .name = "error", .len = 5, .fce_proto = proto_recv_error_client },
- { .name = "init", .len = 4, .fce_proto = proto_recv_init_client },
- { .name = "event", .len = 5, .fce_proto = proto_recv_event_client },
- { .name = "newtux", .len = 6, .fce_proto = proto_recv_newtux_client },
- { .name = "del", .len = 3, .fce_proto = proto_recv_del_client },
- { .name = "additem", .len = 7, .fce_proto = proto_recv_additem_client },
- { .name = "shot", .len = 4, .fce_proto = proto_recv_shot_client },
- { .name = "kill", .len = 4, .fce_proto = proto_recv_kill_client },
- { .name = "module", .len = 6, .fce_proto = proto_recv_module_client },
- { .name = "chat", .len = 4, .fce_proto = proto_recv_chat_client },
- { .name = "ping", .len = 4, .fce_proto = proto_recv_ping_client },
- { .name = "end", .len = 3, .fce_proto = proto_recv_end_client },
- { .name = "", .len = 0, .fce_proto = NULL },
+static proto_cmd_client_t proto_cmd_list[] = {
+ {.name = "error",.len = 5,.fce_proto = proto_recv_error_client},
+ {.name = "init",.len = 4,.fce_proto = proto_recv_init_client},
+ {.name = "event",.len = 5,.fce_proto = proto_recv_event_client},
+ {.name = "newtux",.len = 6,.fce_proto = proto_recv_newtux_client},
+ {.name = "del",.len = 3,.fce_proto = proto_recv_del_client},
+ {.name = "additem",.len = 7,.fce_proto = proto_recv_additem_client},
+ {.name = "shot",.len = 4,.fce_proto = proto_recv_shot_client},
+ {.name = "kill",.len = 4,.fce_proto = proto_recv_kill_client},
+ {.name = "module",.len = 6,.fce_proto = proto_recv_module_client},
+ {.name = "chat",.len = 4,.fce_proto = proto_recv_chat_client},
+ {.name = "ping",.len = 4,.fce_proto = proto_recv_ping_client},
+ {.name = "end",.len = 3,.fce_proto = proto_recv_end_client},
+ {.name = "",.len = 0,.fce_proto = NULL},
};
-static proto_cmd_client_t* findCmdProto(char *msg)
+static proto_cmd_client_t *
+findCmdProto(char *msg)
{
- int len;
- int i;
+ int len;
+ int i;
+
+ len = strlen(msg);
- len = strlen(msg);
+ for (i = 0; proto_cmd_list[i].len != 0; i++) {
+ proto_cmd_client_t *thisCmd;
- for( i = 0 ; proto_cmd_list[i].len != 0 ; i++ )
- {
- proto_cmd_client_t *thisCmd;
-
- thisCmd = &proto_cmd_list[i];
+ thisCmd = &proto_cmd_list[i];
- if( len >= thisCmd->len && strncmp(msg, thisCmd->name, thisCmd->len) == 0 )
- {
- return thisCmd;
- }
- }
+ if (len >= thisCmd->len
+ && strncmp(msg, thisCmd->name, thisCmd->len) == 0) {
+ return thisCmd;
+ }
+ }
- return NULL;
+ return NULL;
}
-static int initUdpClient(char *ip, int port, int proto)
+static int
+initUdpClient(char *ip, int port, int proto)
{
- sock_server_udp = connectUdpSocket(ip, port, proto);
+ sock_server_udp = connectUdpSocket(ip, port, proto);
- if( sock_server_udp == NULL )
- {
- return -1;
- }
+ if (sock_server_udp == NULL) {
+ return -1;
+ }
#ifdef DEBUG
- printf(_("Connected to: %s on port: %d via UDP\n"), ip, port);
+ printf(_("Connected to: %s on port: %d via UDP\n"), ip, port);
#endif
- return 0;
+ return 0;
}
-int initClient(char *ip, int port, int proto)
+int
+initClient(char *ip, int port, int proto)
{
- char name[STR_NAME_SIZE];
- int ret;
+ char name[STR_NAME_SIZE];
+ int ret;
- listRecvMsg = newList();
- lastPing = getMyTime();
- lastPingServerAlive = getMyTime();
+ listRecvMsg = newList();
+ lastPing = getMyTime();
+ lastPingServerAlive = getMyTime();
#ifdef SUPPORT_TRAFFIC
- lastTraffic = getMyTime();
- traffic_down = 0;
- traffic_up = 0;
+ lastTraffic = getMyTime();
+ traffic_down = 0;
+ traffic_up = 0;
#endif
- clientRecvBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
- clientSendBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
+ clientRecvBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
+ clientSendBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
- ret = initUdpClient(ip, port, proto);
+ ret = initUdpClient(ip, port, proto);
- if( ret < 0 )
- {
- return -1;
- }
+ if (ret < 0) {
+ return -1;
+ }
- getSettingNameRight(name);
- proto_send_hello_client(name);
+ getSettingNameRight(name);
+ proto_send_hello_client(name);
- return 0;
+ return 0;
}
-static void errorWithServer()
+static void
+errorWithServer()
{
- fprintf(stderr, _("Server did not respond!\n"));
- setMsgToAnalyze(_("Server is not running or being blocked. I was unable to connect."));
- setWorldEnd();
+ fprintf(stderr, _("Server did not respond!\n"));
+ setMsgToAnalyze(_
+ ("Server is not running or being blocked. I was unable to connect."));
+ setWorldEnd();
}
-void sendServer(char *msg)
+void
+sendServer(char *msg)
{
- int ret;
+ int ret;
- assert( msg != NULL );
+ assert(msg != NULL);
- ret = -1;
+ ret = -1;
#ifndef PUBLIC_SERVER
- if( isParamFlag("--send") )
- {
- printf(_("Sending: \"%s\""), msg);
- }
+ if (isParamFlag("--send")) {
+ printf(_("Sending: \"%s\""), msg);
+ }
#endif
#ifdef SUPPORT_TRAFFIC
- traffic_up += strlen(msg);
+ traffic_up += strlen(msg);
#endif
- if( sock_server_udp != NULL )
- {
- ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg));
- }
+ if (sock_server_udp != NULL) {
+ ret =
+ writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg));
+ }
- if( ret < 0 )
- {
- errorWithServer();
- return;
- }
+ if (ret < 0) {
+ errorWithServer();
+ return;
+ }
}
-static int eventServerSelect()
+static int
+eventServerSelect()
{
- char buffer[STR_PROTO_SIZE];
- int ret;
-
- memset(buffer, 0, STR_PROTO_SIZE);
- ret = -1;
-
- if( sock_server_udp != NULL )
- {
- ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1);
- }
-
- if( ret < 0 )
- {
- errorWithServer();
- return ret;
- }
+ char buffer[STR_PROTO_SIZE];
+ int ret;
+
+ memset(buffer, 0, STR_PROTO_SIZE);
+ ret = -1;
+
+ if (sock_server_udp != NULL) {
+ ret =
+ readUdpSocket(sock_server_udp, sock_server_udp, buffer,
+ STR_PROTO_SIZE - 1);
+ }
+
+ if (ret < 0) {
+ errorWithServer();
+ return ret;
+ }
#ifdef SUPPORT_TRAFFIC
- traffic_down += ret;
+ traffic_down += ret;
#endif
- addList(listRecvMsg, strdup(buffer));
+ addList(listRecvMsg, strdup(buffer));
#if 0
- if( addBuffer(clientRecvBuffer, buffer, ret) < 0 )
- {
- errorWithServer();
- return ret;
- }
-
- while( getBufferLine(clientRecvBuffer, buffer, STR_PROTO_SIZE) >= 0 )
- {
- if( strlen(buffer) > 0)
- {
- addList(listRecvMsg, strdup(buffer) );
- }
- }
+ if (addBuffer(clientRecvBuffer, buffer, ret) < 0) {
+ errorWithServer();
+ return ret;
+ }
+
+ while (getBufferLine(clientRecvBuffer, buffer, STR_PROTO_SIZE) >= 0) {
+ if (strlen(buffer) > 0) {
+ addList(listRecvMsg, strdup(buffer));
+ }
+ }
#endif
- return ret;
+ return ret;
}
-static void eventClientWorkRecvList()
+static void
+eventClientWorkRecvList()
{
- proto_cmd_client_t *protoCmd;
- char *line;
- int i;
+ proto_cmd_client_t *protoCmd;
+ char *line;
+ int i;
+
+ /* obsluha udalosti od servera */
- /* obsluha udalosti od servera */
-
- assert( listRecvMsg != NULL );
+ assert(listRecvMsg != NULL);
- for( i = 0 ; i < listRecvMsg->count ; i++ )
- {
- line = (char *)listRecvMsg->list[i];
- protoCmd = findCmdProto(line);
+ for (i = 0; i < listRecvMsg->count; i++) {
+ line = (char *) listRecvMsg->list[i];
+ protoCmd = findCmdProto(line);
#ifndef PUBLIC_SERVER
- if( isParamFlag("--recv") )
- {
- printf(_("Recieved: \"%s\""), line);
- }
+ if (isParamFlag("--recv")) {
+ printf(_("Recieved: \"%s\""), line);
+ }
#endif
- if( protoCmd != NULL )
- {
- protoCmd->fce_proto(line);
- lastPingServerAlive = getMyTime();
- }
- }
-
- destroyListItem(listRecvMsg, free);
- listRecvMsg = newList();
+ if (protoCmd != NULL) {
+ protoCmd->fce_proto(line);
+ lastPingServerAlive = getMyTime();
+ }
+ }
+
+ destroyListItem(listRecvMsg, free);
+ listRecvMsg = newList();
}
-static void eventPingServer()
+static void
+eventPingServer()
{
- my_time_t currentTime;
+ my_time_t currentTime;
- currentTime = getMyTime();
+ currentTime = getMyTime();
- if( currentTime - lastPing > CLIENT_TIMEOUT )
- {
- proto_send_ping_client();
- lastPing = getMyTime();
- }
+ if (currentTime - lastPing > CLIENT_TIMEOUT) {
+ proto_send_ping_client();
+ lastPing = getMyTime();
+ }
}
-static bool_t isServerAlive()
+static bool_t
+isServerAlive()
{
- my_time_t currentTime;
+ my_time_t currentTime;
- currentTime = getMyTime();
+ currentTime = getMyTime();
- if( currentTime - lastPingServerAlive > SERVER_TIMEOUT_ALIVE )
- {
- return FALSE;
- }
+ if (currentTime - lastPingServerAlive > SERVER_TIMEOUT_ALIVE) {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
-static void selectClientSocket()
+static void
+selectClientSocket()
{
- fd_set readfds;
- struct timeval tv;
- int max_fd;
- int sock;
- bool_t isNext;
-
- max_fd = 0;
- sock = 0;
-
- if( sock_server_udp != NULL )
- {
- if( isServerAlive() == FALSE )
- {
- errorWithServer();
- return;
- }
- }
-
- do{
- isNext = FALSE;
-
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- FD_ZERO(&readfds);
-
- if( sock_server_udp != NULL )
- {
- sock = sock_server_udp->sock;
- }
-
- FD_SET(sock, &readfds);
- max_fd = sock;
- select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
-
- if( FD_ISSET(sock, &readfds) )
- {
- if( eventServerSelect() > 0 )
- {
- isNext = TRUE;
- }
- }
-
- }while( isNext == TRUE );
+ fd_set readfds;
+ struct timeval tv;
+ int max_fd;
+ int sock;
+ bool_t isNext;
+
+ max_fd = 0;
+ sock = 0;
+
+ if (sock_server_udp != NULL) {
+ if (isServerAlive() == FALSE) {
+ errorWithServer();
+ return;
+ }
+ }
+
+ do {
+ isNext = FALSE;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&readfds);
+
+ if (sock_server_udp != NULL) {
+ sock = sock_server_udp->sock;
+ }
+
+ FD_SET(sock, &readfds);
+ max_fd = sock;
+ select(max_fd + 1, &readfds, (fd_set *) NULL, (fd_set *) NULL, &tv);
+
+ if (FD_ISSET(sock, &readfds)) {
+ if (eventServerSelect() > 0) {
+ isNext = TRUE;
+ }
+ }
+
+ } while (isNext == TRUE);
}
#ifdef SUPPORT_TRAFFIC
-static void eventTraffic()
+static void
+eventTraffic()
{
- my_time_t currentTime;
+ my_time_t currentTime;
- currentTime = getMyTime();
+ currentTime = getMyTime();
- if( currentTime - lastTraffic > 5000 )
- {
- lastTraffic = currentTime;
+ if (currentTime - lastTraffic > 5000) {
+ lastTraffic = currentTime;
#ifdef DEBUG
- printf(_("down: %d\n")
- _("up : %d\n"),
- traffic_down, traffic_up);
+ printf(_("down: %d\n")
+ _("up : %d\n"), traffic_down, traffic_up);
#endif
- traffic_down = 0;
- traffic_up = 0;
- }
+ traffic_down = 0;
+ traffic_up = 0;
+ }
}
#endif
-void eventClient()
+void
+eventClient()
{
#ifdef SUPPORT_TRAFFIC
- eventTraffic();
+ eventTraffic();
#endif
- eventPingServer();
- selectClientSocket();
- eventClientWorkRecvList();
+ eventPingServer();
+ selectClientSocket();
+ eventClientWorkRecvList();
}
-static void quitUdpClient()
+static void
+quitUdpClient()
{
- assert( sock_server_udp != NULL );
- closeUdpSocket(sock_server_udp);
+ assert(sock_server_udp != NULL);
+ closeUdpSocket(sock_server_udp);
#ifdef DEBUG
- printf(_("Closing UDP connection.\n"));
+ printf(_("Closing UDP connection.\n"));
#endif
}
-void quitClient()
+void
+quitClient()
{
- proto_send_end_client();
+ proto_send_end_client();
- assert( listRecvMsg != NULL );
+ assert(listRecvMsg != NULL);
- destroyListItem(listRecvMsg, free);
- destroyBuffer(clientRecvBuffer);
- destroyBuffer(clientSendBuffer);
+ destroyListItem(listRecvMsg, free);
+ destroyBuffer(clientRecvBuffer);
+ destroyBuffer(clientSendBuffer);
- if( sock_server_udp != NULL )
- {
- quitUdpClient();
- }
+ if (sock_server_udp != NULL) {
+ quitUdpClient();
+ }
}
-
diff --git a/src/client/client.c~ b/src/client/client.c~
new file mode 100644
index 0000000..7512ab8
--- /dev/null
+++ b/src/client/client.c~
@@ -0,0 +1,388 @@
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#ifndef __WIN32__
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/select.h>
+#else
+#include <io.h>
+#include <winsock2.h>
+#endif
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+#include "proto.h"
+
+#include "client.h"
+
+#include "screen_analyze.h"
+#include "screen_world.h"
+#include "buffer.h"
+
+#include "udp.h"
+
+static sock_udp_t *sock_server_udp;
+
+static list_t *listRecvMsg;
+
+static buffer_t *clientRecvBuffer;
+static buffer_t *clientSendBuffer;
+
+static my_time_t lastPing;
+static my_time_t lastPingServerAlive;
+
+#ifdef SUPPORT_TRAFFIC
+static my_time_t lastTraffic;
+static int traffic_down;
+static int traffic_up;
+#endif
+
+typedef struct proto_cmd_client_struct
+{
+ char *name;
+ int len;
+ void (*fce_proto)(char *msg);
+} proto_cmd_client_t;
+
+static proto_cmd_client_t proto_cmd_list[] =
+{
+ { .name = "error", .len = 5, .fce_proto = proto_recv_error_client },
+ { .name = "init", .len = 4, .fce_proto = proto_recv_init_client },
+ { .name = "event", .len = 5, .fce_proto = proto_recv_event_client },
+ { .name = "newtux", .len = 6, .fce_proto = proto_recv_newtux_client },
+ { .name = "del", .len = 3, .fce_proto = proto_recv_del_client },
+ { .name = "additem", .len = 7, .fce_proto = proto_recv_additem_client },
+ { .name = "shot", .len = 4, .fce_proto = proto_recv_shot_client },
+ { .name = "kill", .len = 4, .fce_proto = proto_recv_kill_client },
+ { .name = "module", .len = 6, .fce_proto = proto_recv_module_client },
+ { .name = "chat", .len = 4, .fce_proto = proto_recv_chat_client },
+ { .name = "ping", .len = 4, .fce_proto = proto_recv_ping_client },
+ { .name = "end", .len = 3, .fce_proto = proto_recv_end_client },
+ { .name = "", .len = 0, .fce_proto = NULL },
+};
+
+static proto_cmd_client_t* findCmdProto(char *msg)
+{
+ int len;
+ int i;
+
+ len = strlen(msg);
+
+ for( i = 0 ; proto_cmd_list[i].len != 0 ; i++ )
+ {
+ proto_cmd_client_t *thisCmd;
+
+ thisCmd = &proto_cmd_list[i];
+
+ if( len >= thisCmd->len && strncmp(msg, thisCmd->name, thisCmd->len) == 0 )
+ {
+ return thisCmd;
+ }
+ }
+
+ return NULL;
+}
+
+static int initUdpClient(char *ip, int port, int proto)
+{
+ sock_server_udp = connectUdpSocket(ip, port, proto);
+
+ if( sock_server_udp == NULL )
+ {
+ return -1;
+ }
+#ifdef DEBUG
+ printf(_("Connected to: %s on port: %d via UDP\n"), ip, port);
+#endif
+ return 0;
+}
+
+int initClient(char *ip, int port, int proto)
+{
+ char name[STR_NAME_SIZE];
+ int ret;
+
+ listRecvMsg = newList();
+ lastPing = getMyTime();
+ lastPingServerAlive = getMyTime();
+
+#ifdef SUPPORT_TRAFFIC
+ lastTraffic = getMyTime();
+ traffic_down = 0;
+ traffic_up = 0;
+#endif
+
+ clientRecvBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
+ clientSendBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
+
+ ret = initUdpClient(ip, port, proto);
+
+ if( ret < 0 )
+ {
+ return -1;
+ }
+
+ getSettingNameRight(name);
+ proto_send_hello_client(name);
+
+ return 0;
+}
+
+static void errorWithServer()
+{
+ fprintf(stderr, _("Server did not respond!\n"));
+ setMsgToAnalyze(_("Server is not running or being blocked. I was unable to connect."));
+ setWorldEnd();
+}
+
+void sendServer(char *msg)
+{
+ int ret;
+
+ assert( msg != NULL );
+
+ ret = -1;
+
+#ifndef PUBLIC_SERVER
+ if( isParamFlag("--send") )
+ {
+ printf(_("Sending: \"%s\""), msg);
+ }
+
+#endif
+
+#ifdef SUPPORT_TRAFFIC
+ traffic_up += strlen(msg);
+#endif
+
+ if( sock_server_udp != NULL )
+ {
+ ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg));
+ }
+
+ if( ret < 0 )
+ {
+ errorWithServer();
+ return;
+ }
+}
+
+static int eventServerSelect()
+{
+ char buffer[STR_PROTO_SIZE];
+ int ret;
+
+ memset(buffer, 0, STR_PROTO_SIZE);
+ ret = -1;
+
+ if( sock_server_udp != NULL )
+ {
+ ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1);
+ }
+
+ if( ret < 0 )
+ {
+ errorWithServer();
+ return ret;
+ }
+
+#ifdef SUPPORT_TRAFFIC
+ traffic_down += ret;
+#endif
+
+ addList(listRecvMsg, strdup(buffer));
+
+#if 0
+ if( addBuffer(clientRecvBuffer, buffer, ret) < 0 )
+ {
+ errorWithServer();
+ return ret;
+ }
+
+ while( getBufferLine(clientRecvBuffer, buffer, STR_PROTO_SIZE) >= 0 )
+ {
+ if( strlen(buffer) > 0)
+ {
+ addList(listRecvMsg, strdup(buffer) );
+ }
+ }
+#endif
+
+ return ret;
+}
+
+static void eventClientWorkRecvList()
+{
+ proto_cmd_client_t *protoCmd;
+ char *line;
+ int i;
+
+ /* obsluha udalosti od servera */
+
+ assert( listRecvMsg != NULL );
+
+ for( i = 0 ; i < listRecvMsg->count ; i++ )
+ {
+ line = (char *)listRecvMsg->list[i];
+ protoCmd = findCmdProto(line);
+
+#ifndef PUBLIC_SERVER
+ if( isParamFlag("--recv") )
+ {
+ printf(_("Recieved: \"%s\""), line);
+ }
+#endif
+ if( protoCmd != NULL )
+ {
+ protoCmd->fce_proto(line);
+ lastPingServerAlive = getMyTime();
+ }
+ }
+
+ destroyListItem(listRecvMsg, free);
+ listRecvMsg = newList();
+}
+
+static void eventPingServer()
+{
+ my_time_t currentTime;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastPing > CLIENT_TIMEOUT )
+ {
+ proto_send_ping_client();
+ lastPing = getMyTime();
+ }
+}
+
+static bool_t isServerAlive()
+{
+ my_time_t currentTime;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastPingServerAlive > SERVER_TIMEOUT_ALIVE )
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void selectClientSocket()
+{
+ fd_set readfds;
+ struct timeval tv;
+ int max_fd;
+ int sock;
+ bool_t isNext;
+
+ max_fd = 0;
+ sock = 0;
+
+ if( sock_server_udp != NULL )
+ {
+ if( isServerAlive() == FALSE )
+ {
+ errorWithServer();
+ return;
+ }
+ }
+
+ do{
+ isNext = FALSE;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&readfds);
+
+ if( sock_server_udp != NULL )
+ {
+ sock = sock_server_udp->sock;
+ }
+
+ FD_SET(sock, &readfds);
+ max_fd = sock;
+ select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
+
+ if( FD_ISSET(sock, &readfds) )
+ {
+ if( eventServerSelect() > 0 )
+ {
+ isNext = TRUE;
+ }
+ }
+
+ }while( isNext == TRUE );
+}
+
+#ifdef SUPPORT_TRAFFIC
+
+static void eventTraffic()
+{
+ my_time_t currentTime;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastTraffic > 5000 )
+ {
+ lastTraffic = currentTime;
+#ifdef DEBUG
+ printf(_("down: %d\n")
+ _("up : %d\n"),
+ traffic_down, traffic_up);
+#endif
+ traffic_down = 0;
+ traffic_up = 0;
+ }
+}
+
+#endif
+
+void eventClient()
+{
+#ifdef SUPPORT_TRAFFIC
+ eventTraffic();
+#endif
+
+ eventPingServer();
+ selectClientSocket();
+ eventClientWorkRecvList();
+
+}
+
+static void quitUdpClient()
+{
+ assert( sock_server_udp != NULL );
+ closeUdpSocket(sock_server_udp);
+#ifdef DEBUG
+ printf(_("Closing UDP connection.\n"));
+#endif
+}
+
+void quitClient()
+{
+ proto_send_end_client();
+
+ assert( listRecvMsg != NULL );
+
+ destroyListItem(listRecvMsg, free);
+ destroyBuffer(clientRecvBuffer);
+ destroyBuffer(clientSendBuffer);
+
+ if( sock_server_udp != NULL )
+ {
+ quitUdpClient();
+ }
+}
+
diff --git a/src/client/configFile.c b/src/client/configFile.c
index dc5d0fd..9f7d03b 100644
--- a/src/client/configFile.c
+++ b/src/client/configFile.c
@@ -7,132 +7,142 @@
#include "main.h"
#include "configFile.h"
-int isYesOrNO(char *s)
+int
+isYesOrNO(char *s)
{
- if( s[0] == 'Y' || s[0] == 'y' )return 1;
- return 0;
+ if (s[0] == 'Y' || s[0] == 'y')
+ return 1;
+ return 0;
}
-char* getYesOrNo(int n)
+char *
+getYesOrNo(int n)
{
- return ( n != 0 ? "YES" : "NO" );
+ return (n != 0 ? "YES" : "NO");
}
-int getValue(char *line, char *env, char *val, int len)
+int
+getValue(char *line, char *env, char *val, int len)
{
- char *offset_env;
- char *offset_val_begin;
- char *offset_val_end;
- char clone_env[STR_SIZE];
- int val_len;
-
- strcpy(clone_env, env);
-
- offset_env = strstr(line, clone_env);
- if( offset_env == NULL )return -1;
-
- offset_val_begin = strchr(offset_env, '"');
- if( offset_val_begin == NULL )return -1;
-
- offset_val_end = strchr(offset_val_begin+1, '"');
- if( offset_val_end == NULL )return -1;
-
- val_len = (int)(offset_val_end - ( offset_val_begin + 1) );
- if( val_len > len - 1 ) val_len = len - 1;
-
- memset(val, 0, len);
- memcpy(val, offset_val_begin+1, val_len);
-
- return 0;
+ char *offset_env;
+ char *offset_val_begin;
+ char *offset_val_end;
+ char clone_env[STR_SIZE];
+ int val_len;
+
+ strcpy(clone_env, env);
+
+ offset_env = strstr(line, clone_env);
+ if (offset_env == NULL)
+ return -1;
+
+ offset_val_begin = strchr(offset_env, '"');
+ if (offset_val_begin == NULL)
+ return -1;
+
+ offset_val_end = strchr(offset_val_begin + 1, '"');
+ if (offset_val_end == NULL)
+ return -1;
+
+ val_len = (int) (offset_val_end - (offset_val_begin + 1));
+ if (val_len > len - 1)
+ val_len = len - 1;
+
+ memset(val, 0, len);
+ memcpy(val, offset_val_begin + 1, val_len);
+
+ return 0;
}
-char* setValue(char *line, char *env, char *val)
+char *
+setValue(char *line, char *env, char *val)
{
- char *offset_env;
- char *offset_val_begin;
- char *offset_val_end;
- char clone_env[STR_SIZE];
- char clone[STR_SIZE];
-
- //strcpy(clone_env, " ");
- strcpy(clone_env, env);
-
- offset_env = strstr(line, clone_env);
- if( offset_env == NULL )return NULL;
-
- offset_val_begin = strchr(offset_env, '"');
- if( offset_val_begin == NULL )return NULL;
-
- offset_val_end = strchr(offset_val_begin+1, '"');
- if( offset_val_end == NULL )return NULL;
-
- memset(clone, 0, STR_SIZE);
- strncpy(clone, line, (int) ( (offset_val_begin - line) + 1 ) );
- strcat(clone, val);
- strcat(clone, offset_val_end);
-
- return strdup( clone );
+ char *offset_env;
+ char *offset_val_begin;
+ char *offset_val_end;
+ char clone_env[STR_SIZE];
+ char clone[STR_SIZE];
+
+ //strcpy(clone_env, " ");
+ strcpy(clone_env, env);
+
+ offset_env = strstr(line, clone_env);
+ if (offset_env == NULL)
+ return NULL;
+
+ offset_val_begin = strchr(offset_env, '"');
+ if (offset_val_begin == NULL)
+ return NULL;
+
+ offset_val_end = strchr(offset_val_begin + 1, '"');
+ if (offset_val_end == NULL)
+ return NULL;
+
+ memset(clone, 0, STR_SIZE);
+ strncpy(clone, line, (int) ((offset_val_begin - line) + 1));
+ strcat(clone, val);
+ strcat(clone, offset_val_end);
+
+ return strdup(clone);
}
-int getValueInConfigFile(textFile_t *textFile, char *env, char *val, int len)
+int
+getValueInConfigFile(textFile_t * textFile, char *env, char *val, int len)
{
- int i;
- char *line;
-
- for( i = 0 ; i < textFile->text->count ; i++ )
- {
- line = (char *) (textFile->text->list[i]);
-
- //printf("env = %s line = %s\n", env, line);
-
- if( strncmp(line, env, strlen(env)) == 0 )
- {
- return getValue(line, env, val, len);
- }
- }
-
- return -1;
+ int i;
+ char *line;
+
+ for (i = 0; i < textFile->text->count; i++) {
+ line = (char *) (textFile->text->list[i]);
+
+ //printf("env = %s line = %s\n", env, line);
+
+ if (strncmp(line, env, strlen(env)) == 0) {
+ return getValue(line, env, val, len);
+ }
+ }
+
+ return -1;
}
-int setValueInConfigFile(textFile_t *textFile, char *env, char *val)
+int
+setValueInConfigFile(textFile_t * textFile, char *env, char *val)
{
- int i;
- char *line;
- char *ret;
-
- for( i = 0 ; i < textFile->text->count ; i++ )
- {
- line = (char *) (textFile->text->list[i]);
-
- if( strncmp(line, env, strlen(env)) == 0 )
- {
- ret = setValue(line, env, val);
-
- if( ret != NULL )
- {
- delListItem(textFile->text, i, free);
- insList(textFile->text, i, ret);
-
- return 0;
- }
- }
- }
-
- return -1;
+ int i;
+ char *line;
+ char *ret;
+
+ for (i = 0; i < textFile->text->count; i++) {
+ line = (char *) (textFile->text->list[i]);
+
+ if (strncmp(line, env, strlen(env)) == 0) {
+ ret = setValue(line, env, val);
+
+ if (ret != NULL) {
+ delListItem(textFile->text, i, free);
+ insList(textFile->text, i, ret);
+
+ return 0;
+ }
+ }
+ }
+
+ return -1;
}
-void loadValueFromConfigFile(textFile_t *textFile, char *env, char *val, int len, char *butVal)
+void
+loadValueFromConfigFile(textFile_t * textFile, char *env, char *val, int len,
+ char *butVal)
{
- strcpy(val, butVal);
+ strcpy(val, butVal);
- if( getValueInConfigFile(textFile, env, val, len) != 0 )
- {
- char line[STR_SIZE];
+ if (getValueInConfigFile(textFile, env, val, len) != 0) {
+ char line[STR_SIZE];
- sprintf(line, "%s=\"%s\"", env, butVal);
- addList(textFile->text, strdup(line) );
+ sprintf(line, "%s=\"%s\"", env, butVal);
+ addList(textFile->text, strdup(line));
#ifdef DEBUG
- printf(_("ADDING: \"%s\" into config file.\n"), line);
+ printf(_("ADDING: \"%s\" into config file.\n"), line);
#endif
- }
+ }
}
diff --git a/src/client/configFile.c~ b/src/client/configFile.c~
new file mode 100644
index 0000000..dc5d0fd
--- /dev/null
+++ b/src/client/configFile.c~
@@ -0,0 +1,138 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "configFile.h"
+
+int isYesOrNO(char *s)
+{
+ if( s[0] == 'Y' || s[0] == 'y' )return 1;
+ return 0;
+}
+
+char* getYesOrNo(int n)
+{
+ return ( n != 0 ? "YES" : "NO" );
+}
+
+int getValue(char *line, char *env, char *val, int len)
+{
+ char *offset_env;
+ char *offset_val_begin;
+ char *offset_val_end;
+ char clone_env[STR_SIZE];
+ int val_len;
+
+ strcpy(clone_env, env);
+
+ offset_env = strstr(line, clone_env);
+ if( offset_env == NULL )return -1;
+
+ offset_val_begin = strchr(offset_env, '"');
+ if( offset_val_begin == NULL )return -1;
+
+ offset_val_end = strchr(offset_val_begin+1, '"');
+ if( offset_val_end == NULL )return -1;
+
+ val_len = (int)(offset_val_end - ( offset_val_begin + 1) );
+ if( val_len > len - 1 ) val_len = len - 1;
+
+ memset(val, 0, len);
+ memcpy(val, offset_val_begin+1, val_len);
+
+ return 0;
+}
+
+char* setValue(char *line, char *env, char *val)
+{
+ char *offset_env;
+ char *offset_val_begin;
+ char *offset_val_end;
+ char clone_env[STR_SIZE];
+ char clone[STR_SIZE];
+
+ //strcpy(clone_env, " ");
+ strcpy(clone_env, env);
+
+ offset_env = strstr(line, clone_env);
+ if( offset_env == NULL )return NULL;
+
+ offset_val_begin = strchr(offset_env, '"');
+ if( offset_val_begin == NULL )return NULL;
+
+ offset_val_end = strchr(offset_val_begin+1, '"');
+ if( offset_val_end == NULL )return NULL;
+
+ memset(clone, 0, STR_SIZE);
+ strncpy(clone, line, (int) ( (offset_val_begin - line) + 1 ) );
+ strcat(clone, val);
+ strcat(clone, offset_val_end);
+
+ return strdup( clone );
+}
+
+int getValueInConfigFile(textFile_t *textFile, char *env, char *val, int len)
+{
+ int i;
+ char *line;
+
+ for( i = 0 ; i < textFile->text->count ; i++ )
+ {
+ line = (char *) (textFile->text->list[i]);
+
+ //printf("env = %s line = %s\n", env, line);
+
+ if( strncmp(line, env, strlen(env)) == 0 )
+ {
+ return getValue(line, env, val, len);
+ }
+ }
+
+ return -1;
+}
+
+int setValueInConfigFile(textFile_t *textFile, char *env, char *val)
+{
+ int i;
+ char *line;
+ char *ret;
+
+ for( i = 0 ; i < textFile->text->count ; i++ )
+ {
+ line = (char *) (textFile->text->list[i]);
+
+ if( strncmp(line, env, strlen(env)) == 0 )
+ {
+ ret = setValue(line, env, val);
+
+ if( ret != NULL )
+ {
+ delListItem(textFile->text, i, free);
+ insList(textFile->text, i, ret);
+
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+void loadValueFromConfigFile(textFile_t *textFile, char *env, char *val, int len, char *butVal)
+{
+ strcpy(val, butVal);
+
+ if( getValueInConfigFile(textFile, env, val, len) != 0 )
+ {
+ char line[STR_SIZE];
+
+ sprintf(line, "%s=\"%s\"", env, butVal);
+ addList(textFile->text, strdup(line) );
+#ifdef DEBUG
+ printf(_("ADDING: \"%s\" into config file.\n"), line);
+#endif
+ }
+}
diff --git a/src/client/font.c b/src/client/font.c
index 9a37b9f..f66f8cf 100755
--- a/src/client/font.c
+++ b/src/client/font.c
@@ -1,5 +1,5 @@
-#include "main.h"
-#include "interface.h"
+#include "main.h"
+#include "interface.h"
#include "font.h"
static TTF_Font *g_font;
@@ -7,132 +7,136 @@ static int fontSize;
static bool_t isFontInit = FALSE;
-bool_t isFontInicialized()
+bool_t
+isFontInicialized()
{
- return isFontInit;
+ return isFontInit;
}
-void initFont(char *file,int size)
+void
+initFont(char *file, int size)
{
- char str[STR_PATH_SIZE];
+ char str[STR_PATH_SIZE];
- assert( file != NULL );
- assert( size > 0 );
+ assert(file != NULL);
+ assert(size > 0);
- assert( isInterfaceInicialized() == TRUE );
+ assert(isInterfaceInicialized() == TRUE);
- sprintf(str, "%s", file);
+ sprintf(str, "%s", file);
- if( TTF_Init() == -1 )
- {
- fprintf(stderr, "%s\n", SDL_GetError());
- return;
- }
+ if (TTF_Init() == -1) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return;
+ }
- accessExistFile(str);
+ accessExistFile(str);
- g_font = TTF_OpenFont(str, size);
- TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL);
+ g_font = TTF_OpenFont(str, size);
+ TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL);
- fontSize = size;
+ fontSize = size;
#ifdef DEBUG
- printf(_("Loading font: \"%s\"\n"), file);
+ printf(_("Loading font: \"%s\"\n"), file);
#endif
- isFontInit = TRUE;
+ isFontInit = TRUE;
}
/*
* Zobrazi text *s na suradnicu x y s farbou RGB
*/
-void drawFont(char *s, int x, int y, int r, int g, int b)
+void
+drawFont(char *s, int x, int y, int r, int g, int b)
{
- SDL_Rect dst_rect;
- SDL_Surface *text;
- SDL_Surface *p;
- SDL_Color farba_pisma = {r, g, b, 0};
+ SDL_Rect dst_rect;
+ SDL_Surface *text;
+ SDL_Surface *p;
+ SDL_Color farba_pisma = { r, g, b, 0 };
- //printf("drawFont %s\n", s);
+ //printf("drawFont %s\n", s);
- assert( s != NULL );
+ assert(s != NULL);
- p = getSDL_Screen();
+ p = getSDL_Screen();
- text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
+ text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
- dst_rect.x = x;
- dst_rect.y = y;
-
- SDL_BlitSurface(text, NULL, p, &dst_rect);
- SDL_FreeSurface(text);
+ dst_rect.x = x;
+ dst_rect.y = y;
+
+ SDL_BlitSurface(text, NULL, p, &dst_rect);
+ SDL_FreeSurface(text);
}
-void drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g, int b)
+void
+drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g, int b)
{
- SDL_Rect src_rect, dst_rect;
- SDL_Surface *text;
- SDL_Surface *p;
- SDL_Color farba_pisma = {r, g, b, 0};
- int my_w, my_h;
+ SDL_Rect src_rect, dst_rect;
+ SDL_Surface *text;
+ SDL_Surface *p;
+ SDL_Color farba_pisma = { r, g, b, 0 };
+ int my_w, my_h;
+
+ assert(s != NULL);
+
+ p = getSDL_Screen();
- assert( s != NULL );
+ text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
- p = getSDL_Screen();
- text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
+ my_w = text->w;
-
- my_w = text->w;
+ if (my_w > w) {
+ my_w = w;
+ }
- if( my_w > w )
- {
- my_w = w;
- }
+ my_h = text->h;
- my_h = text->h;
+ if (my_w > w) {
+ my_h = h;
+ }
- if( my_w > w )
- {
- my_h = h;
- }
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.w = my_w;
+ src_rect.h = my_h;
- src_rect.x = 0;
- src_rect.y = 0;
- src_rect.w = my_w;
- src_rect.h = my_h;
+ dst_rect.x = x;
+ dst_rect.y = y;
- dst_rect.x = x;
- dst_rect.y = y;
-
- SDL_BlitSurface(text, &src_rect, p, &dst_rect);
- SDL_FreeSurface(text);
+ SDL_BlitSurface(text, &src_rect, p, &dst_rect);
+ SDL_FreeSurface(text);
}
/*
* Vrati velkost daneho fontu.
*/
-int getFontSize()
+int
+getFontSize()
{
- return fontSize;
+ return fontSize;
}
-void getTextSize(char *s, int *w, int *h)
+void
+getTextSize(char *s, int *w, int *h)
{
- assert( s != NULL );
- assert( w != NULL );
- assert( h != NULL );
+ assert(s != NULL);
+ assert(w != NULL);
+ assert(h != NULL);
- TTF_SizeUTF8(g_font, s, w, h);
+ TTF_SizeUTF8(g_font, s, w, h);
}
/*
* Uvolni font z pamete.
*/
-void quitFont()
+void
+quitFont()
{
- TTF_CloseFont(g_font);
- TTF_Quit();
+ TTF_CloseFont(g_font);
+ TTF_Quit();
#ifdef DEBUG
- printf(_("Unloading font\n"));
+ printf(_("Unloading font\n"));
#endif
- isFontInit = FALSE;
+ isFontInit = FALSE;
}
diff --git a/src/client/font.c~ b/src/client/font.c~
new file mode 100644
index 0000000..9a37b9f
--- /dev/null
+++ b/src/client/font.c~
@@ -0,0 +1,138 @@
+#include "main.h"
+#include "interface.h"
+#include "font.h"
+
+static TTF_Font *g_font;
+static int fontSize;
+
+static bool_t isFontInit = FALSE;
+
+bool_t isFontInicialized()
+{
+ return isFontInit;
+}
+
+void initFont(char *file,int size)
+{
+ char str[STR_PATH_SIZE];
+
+ assert( file != NULL );
+ assert( size > 0 );
+
+ assert( isInterfaceInicialized() == TRUE );
+
+ sprintf(str, "%s", file);
+
+ if( TTF_Init() == -1 )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return;
+ }
+
+ accessExistFile(str);
+
+ g_font = TTF_OpenFont(str, size);
+ TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL);
+
+ fontSize = size;
+#ifdef DEBUG
+ printf(_("Loading font: \"%s\"\n"), file);
+#endif
+ isFontInit = TRUE;
+}
+
+/*
+ * Zobrazi text *s na suradnicu x y s farbou RGB
+ */
+void drawFont(char *s, int x, int y, int r, int g, int b)
+{
+ SDL_Rect dst_rect;
+ SDL_Surface *text;
+ SDL_Surface *p;
+ SDL_Color farba_pisma = {r, g, b, 0};
+
+ //printf("drawFont %s\n", s);
+
+ assert( s != NULL );
+
+ p = getSDL_Screen();
+
+ text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
+
+ dst_rect.x = x;
+ dst_rect.y = y;
+
+ SDL_BlitSurface(text, NULL, p, &dst_rect);
+ SDL_FreeSurface(text);
+}
+
+void drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g, int b)
+{
+ SDL_Rect src_rect, dst_rect;
+ SDL_Surface *text;
+ SDL_Surface *p;
+ SDL_Color farba_pisma = {r, g, b, 0};
+ int my_w, my_h;
+
+ assert( s != NULL );
+
+ p = getSDL_Screen();
+
+ text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
+
+
+ my_w = text->w;
+
+ if( my_w > w )
+ {
+ my_w = w;
+ }
+
+ my_h = text->h;
+
+ if( my_w > w )
+ {
+ my_h = h;
+ }
+
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.w = my_w;
+ src_rect.h = my_h;
+
+ dst_rect.x = x;
+ dst_rect.y = y;
+
+ SDL_BlitSurface(text, &src_rect, p, &dst_rect);
+ SDL_FreeSurface(text);
+}
+
+/*
+ * Vrati velkost daneho fontu.
+ */
+int getFontSize()
+{
+ return fontSize;
+}
+
+void getTextSize(char *s, int *w, int *h)
+{
+ assert( s != NULL );
+ assert( w != NULL );
+ assert( h != NULL );
+
+ TTF_SizeUTF8(g_font, s, w, h);
+}
+
+/*
+ * Uvolni font z pamete.
+ */
+void quitFont()
+{
+ TTF_CloseFont(g_font);
+ TTF_Quit();
+#ifdef DEBUG
+ printf(_("Unloading font\n"));
+#endif
+ isFontInit = FALSE;
+}
diff --git a/src/client/game.c b/src/client/game.c
index 68b88d7..066acab 100644
--- a/src/client/game.c
+++ b/src/client/game.c
@@ -42,81 +42,84 @@
#include "screen_credits.h"
#include "screen_browser.h"
-static void initGame()
+static void
+initGame()
{
- createHomeDirector();
+ createHomeDirector();
- initSDL();
- initFont(FONT_FILE , FONT_SIZE);
- initLayer();
- initImageData();
+ initSDL();
+ initFont(FONT_FILE, FONT_SIZE);
+ initLayer();
+ initImageData();
#ifndef NO_SOUND
- initAudio();
- initSound();
- initMusic();
+ initAudio();
+ initSound();
+ initMusic();
#endif
- initScreen();
- initArenaFile();
- initTux();
- initItem();
- initShot();
- initPanel();
- initWorld();
+ initScreen();
+ initArenaFile();
+ initTux();
+ initItem();
+ initShot();
+ initPanel();
+ initWorld();
- initScreenMainMenu();
- initScreenAnalyze();
- initScreenChoiceArena();
- initScreenSetting();
- initScreenSettingKeys();
- initScreenGameType();
- initScreenDownArena();
- initScreenCredits();
- initScreenTable();
- initScreenBrowser();
+ initScreenMainMenu();
+ initScreenAnalyze();
+ initScreenChoiceArena();
+ initScreenSetting();
+ initScreenSettingKeys();
+ initScreenGameType();
+ initScreenDownArena();
+ initScreenCredits();
+ initScreenTable();
+ initScreenBrowser();
}
-void quitGame()
+void
+quitGame()
{
- quitSDL();
+ quitSDL();
- quitScreenMainMenu();
- quitScreenAnalyze();
- quitScreenSetting();
- quitScreenSettingKeys();
- quitScreenGameType();
- quitScreenDownArena();
- quitScreenChoiceArena();
- quitScreenCredits();
- quitScreenTable();
- quitScreenBrowser();
+ quitScreenMainMenu();
+ quitScreenAnalyze();
+ quitScreenSetting();
+ quitScreenSettingKeys();
+ quitScreenGameType();
+ quitScreenDownArena();
+ quitScreenChoiceArena();
+ quitScreenCredits();
+ quitScreenTable();
+ quitScreenBrowser();
- quitLayer();
- quitFont();
- quitScreen();
- quitArenaFile();
- quitItem();
- quitTux();
- quitShot();
- quitPanel();
- quitWorld();
- quitImageData();
+ quitLayer();
+ quitFont();
+ quitScreen();
+ quitArenaFile();
+ quitItem();
+ quitTux();
+ quitShot();
+ quitPanel();
+ quitWorld();
+ quitImageData();
#ifndef NO_SOUND
- quitSound();
- quitMusic();
- quitAudio();
+ quitSound();
+ quitMusic();
+ quitAudio();
#endif
#ifdef DEBUG
- printf(_("Quitting TUXANCI...\n"));
+ printf(_("Quitting TUXANCI...\n"));
#endif
- exit(0);
+ exit(0);
}
-void startGame()
+void
+startGame()
{
- initGame();
+ initGame();
- startScreen("mainMenu");
+ startScreen("mainMenu");
- eventSDL();
- quitGame();
+ eventSDL();
+ quitGame();
}
diff --git a/src/client/game.c~ b/src/client/game.c~
new file mode 100644
index 0000000..68b88d7
--- /dev/null
+++ b/src/client/game.c~
@@ -0,0 +1,122 @@
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/stat.h>
+
+#include "main.h"
+#include "tux.h"
+#include "homeDirector.h"
+#include "item.h"
+#include "shot.h"
+#include "arenaFile.h"
+
+#include "image.h"
+#include "layer.h"
+#include "interface.h"
+#include "screen.h"
+#include "font.h"
+#include "screen_settingKeys.h"
+#include "panel.h"
+#include "radar.h"
+
+#ifndef NO_SOUND
+#include "audio.h"
+#include "sound.h"
+#include "music.h"
+#endif
+
+#include "screen_world.h"
+#include "screen_mainMenu.h"
+#include "screen_analyze.h"
+#include "screen_setting.h"
+#include "screen_settingKeys.h"
+#include "screen_gameType.h"
+#include "screen_downArena.h"
+#include "screen_choiceArena.h"
+#include "screen_table.h"
+#include "screen_credits.h"
+#include "screen_browser.h"
+
+static void initGame()
+{
+ createHomeDirector();
+
+ initSDL();
+ initFont(FONT_FILE , FONT_SIZE);
+ initLayer();
+ initImageData();
+#ifndef NO_SOUND
+ initAudio();
+ initSound();
+ initMusic();
+#endif
+ initScreen();
+ initArenaFile();
+ initTux();
+ initItem();
+ initShot();
+ initPanel();
+ initWorld();
+
+ initScreenMainMenu();
+ initScreenAnalyze();
+ initScreenChoiceArena();
+ initScreenSetting();
+ initScreenSettingKeys();
+ initScreenGameType();
+ initScreenDownArena();
+ initScreenCredits();
+ initScreenTable();
+ initScreenBrowser();
+}
+
+void quitGame()
+{
+ quitSDL();
+
+ quitScreenMainMenu();
+ quitScreenAnalyze();
+ quitScreenSetting();
+ quitScreenSettingKeys();
+ quitScreenGameType();
+ quitScreenDownArena();
+ quitScreenChoiceArena();
+ quitScreenCredits();
+ quitScreenTable();
+ quitScreenBrowser();
+
+ quitLayer();
+ quitFont();
+ quitScreen();
+ quitArenaFile();
+ quitItem();
+ quitTux();
+ quitShot();
+ quitPanel();
+ quitWorld();
+ quitImageData();
+#ifndef NO_SOUND
+ quitSound();
+ quitMusic();
+ quitAudio();
+#endif
+#ifdef DEBUG
+ printf(_("Quitting TUXANCI...\n"));
+#endif
+ exit(0);
+}
+
+void startGame()
+{
+ initGame();
+
+ startScreen("mainMenu");
+
+ eventSDL();
+ quitGame();
+}
diff --git a/src/client/hotKey.c b/src/client/hotKey.c
index 43a13ca..9418057 100644
--- a/src/client/hotKey.c
+++ b/src/client/hotKey.c
@@ -12,147 +12,148 @@
typedef struct hotKey_struct
{
- SDLKey key;
- bool_t active;
- void (*handler)();
+ SDLKey key;
+ bool_t active;
+ void (*handler) ();
} hotKey_t;
static list_t *listHotKey;
static my_time_t lastActive;
-static hotKey_t* newHotKey(SDLKey key, void (*handler)())
+static hotKey_t *
+newHotKey(SDLKey key, void (*handler) ())
{
- hotKey_t *new;
+ hotKey_t *new;
- new = malloc( sizeof(hotKey_t) );
- new->key = key;
- new->active = TRUE;
- new->handler = handler;
+ new = malloc(sizeof(hotKey_t));
+ new->key = key;
+ new->active = TRUE;
+ new->handler = handler;
- return new;
+ return new;
}
-static void destroyHotKey(hotKey_t *hotkey)
+static void
+destroyHotKey(hotKey_t * hotkey)
{
- free(hotkey);
+ free(hotkey);
}
-static hotKey_t* findHotkey(SDLKey key)
+static hotKey_t *
+findHotkey(SDLKey key)
{
- int i;
+ int i;
- for( i = 0 ; i < listHotKey->count ; i++ )
- {
- hotKey_t *this;
+ for (i = 0; i < listHotKey->count; i++) {
+ hotKey_t *this;
- this = (hotKey_t *)listHotKey->list[i];
+ this = (hotKey_t *) listHotKey->list[i];
- if( this->key == key )
- {
- return this;
- }
- }
+ if (this->key == key) {
+ return this;
+ }
+ }
- return NULL;
+ return NULL;
}
-void initHotKey()
+void
+initHotKey()
{
- listHotKey = newList();
- lastActive = getMyTime();
+ listHotKey = newList();
+ lastActive = getMyTime();
}
-void registerHotKey(SDLKey key, void (*handler)())
+void
+registerHotKey(SDLKey key, void (*handler) ())
{
- hotKey_t *hotkey;
+ hotKey_t *hotkey;
- if( findHotkey(key) != NULL )
- {
- assert( ! "Conflict with register key");
- }
+ if (findHotkey(key) != NULL) {
+ assert(!"Conflict with register key");
+ }
- hotkey = newHotKey(key, handler);
- addList(listHotKey, hotkey);
+ hotkey = newHotKey(key, handler);
+ addList(listHotKey, hotkey);
}
-void unregisterHotKey(SDLKey key)
+void
+unregisterHotKey(SDLKey key)
{
- hotKey_t *hotkey;
- int index;
+ hotKey_t *hotkey;
+ int index;
- hotkey = findHotkey(key);
+ hotkey = findHotkey(key);
- if( hotkey == NULL )
- {
- assert( ! "This hotkey not register");
- }
+ if (hotkey == NULL) {
+ assert(!"This hotkey not register");
+ }
- index = searchListItem(listHotKey, hotkey);
- assert( index != -1 );
- delListItem(listHotKey, index, destroyHotKey);
+ index = searchListItem(listHotKey, hotkey);
+ assert(index != -1);
+ delListItem(listHotKey, index, destroyHotKey);
}
-void enableHotKey(SDLKey key)
+void
+enableHotKey(SDLKey key)
{
- hotKey_t *hotkey;
+ hotKey_t *hotkey;
- hotkey = findHotkey(key);
+ hotkey = findHotkey(key);
- if( hotkey == NULL )
- {
- assert( ! "This hotkey not register");
- }
+ if (hotkey == NULL) {
+ assert(!"This hotkey not register");
+ }
- lastActive = getMyTime();
- hotkey->active = TRUE;
+ lastActive = getMyTime();
+ hotkey->active = TRUE;
}
-void disableHotKey(SDLKey key)
+void
+disableHotKey(SDLKey key)
{
- hotKey_t *hotkey;
+ hotKey_t *hotkey;
- hotkey = findHotkey(key);
+ hotkey = findHotkey(key);
- if( hotkey == NULL )
- {
- assert( ! "This hotkey not register");
- }
+ if (hotkey == NULL) {
+ assert(!"This hotkey not register");
+ }
- lastActive = getMyTime();
- hotkey->active = FALSE;
+ lastActive = getMyTime();
+ hotkey->active = FALSE;
}
-void eventHotKey()
+void
+eventHotKey()
{
- my_time_t currentTime;
- Uint8 *mapa;
- int i;
+ my_time_t currentTime;
+ Uint8 *mapa;
+ int i;
- currentTime = getMyTime();
+ currentTime = getMyTime();
- if( currentTime - lastActive < HOTKEY_ACTIVE_INTERVAL )
- {
- return;
- }
+ if (currentTime - lastActive < HOTKEY_ACTIVE_INTERVAL) {
+ return;
+ }
- mapa = SDL_GetKeyState(NULL);
+ mapa = SDL_GetKeyState(NULL);
- for( i = 0 ; i < listHotKey->count ; i++ )
- {
- hotKey_t *this;
+ for (i = 0; i < listHotKey->count; i++) {
+ hotKey_t *this;
- this = (hotKey_t *)listHotKey->list[i];
+ this = (hotKey_t *) listHotKey->list[i];
- if( mapa[this->key] == SDL_PRESSED && this->active == TRUE )
- {
- lastActive = getMyTime();
- //printf("hotKey = %d\n", this->key);
- this->handler();
- }
- }
+ if (mapa[this->key] == SDL_PRESSED && this->active == TRUE) {
+ lastActive = getMyTime();
+ //printf("hotKey = %d\n", this->key);
+ this->handler();
+ }
+ }
}
-void quitHotKey()
+void
+quitHotKey()
{
- destroyListItem(listHotKey, destroyHotKey);
+ destroyListItem(listHotKey, destroyHotKey);
}
diff --git a/src/client/hotKey.c~ b/src/client/hotKey.c~
new file mode 100644
index 0000000..43a13ca
--- /dev/null
+++ b/src/client/hotKey.c~
@@ -0,0 +1,158 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "myTimer.h"
+
+#include "interface.h"
+#include "hotKey.h"
+
+typedef struct hotKey_struct
+{
+ SDLKey key;
+ bool_t active;
+ void (*handler)();
+} hotKey_t;
+
+static list_t *listHotKey;
+static my_time_t lastActive;
+
+static hotKey_t* newHotKey(SDLKey key, void (*handler)())
+{
+ hotKey_t *new;
+
+ new = malloc( sizeof(hotKey_t) );
+ new->key = key;
+ new->active = TRUE;
+ new->handler = handler;
+
+ return new;
+}
+
+static void destroyHotKey(hotKey_t *hotkey)
+{
+ free(hotkey);
+}
+
+static hotKey_t* findHotkey(SDLKey key)
+{
+ int i;
+
+ for( i = 0 ; i < listHotKey->count ; i++ )
+ {
+ hotKey_t *this;
+
+ this = (hotKey_t *)listHotKey->list[i];
+
+ if( this->key == key )
+ {
+ return this;
+ }
+ }
+
+ return NULL;
+}
+
+void initHotKey()
+{
+ listHotKey = newList();
+ lastActive = getMyTime();
+}
+
+void registerHotKey(SDLKey key, void (*handler)())
+{
+ hotKey_t *hotkey;
+
+ if( findHotkey(key) != NULL )
+ {
+ assert( ! "Conflict with register key");
+ }
+
+ hotkey = newHotKey(key, handler);
+ addList(listHotKey, hotkey);
+}
+
+void unregisterHotKey(SDLKey key)
+{
+ hotKey_t *hotkey;
+ int index;
+
+ hotkey = findHotkey(key);
+
+ if( hotkey == NULL )
+ {
+ assert( ! "This hotkey not register");
+ }
+
+ index = searchListItem(listHotKey, hotkey);
+ assert( index != -1 );
+ delListItem(listHotKey, index, destroyHotKey);
+}
+
+void enableHotKey(SDLKey key)
+{
+ hotKey_t *hotkey;
+
+ hotkey = findHotkey(key);
+
+ if( hotkey == NULL )
+ {
+ assert( ! "This hotkey not register");
+ }
+
+ lastActive = getMyTime();
+ hotkey->active = TRUE;
+}
+
+void disableHotKey(SDLKey key)
+{
+ hotKey_t *hotkey;
+
+ hotkey = findHotkey(key);
+
+ if( hotkey == NULL )
+ {
+ assert( ! "This hotkey not register");
+ }
+
+ lastActive = getMyTime();
+ hotkey->active = FALSE;
+}
+
+void eventHotKey()
+{
+ my_time_t currentTime;
+ Uint8 *mapa;
+ int i;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastActive < HOTKEY_ACTIVE_INTERVAL )
+ {
+ return;
+ }
+
+ mapa = SDL_GetKeyState(NULL);
+
+ for( i = 0 ; i < listHotKey->count ; i++ )
+ {
+ hotKey_t *this;
+
+ this = (hotKey_t *)listHotKey->list[i];
+
+ if( mapa[this->key] == SDL_PRESSED && this->active == TRUE )
+ {
+ lastActive = getMyTime();
+ //printf("hotKey = %d\n", this->key);
+ this->handler();
+ }
+ }
+}
+
+void quitHotKey()
+{
+ destroyListItem(listHotKey, destroyHotKey);
+}
diff --git a/src/client/image.c b/src/client/image.c
index 4c4010c..52585e2 100755
--- a/src/client/image.c
+++ b/src/client/image.c
@@ -14,79 +14,82 @@ static list_t *listStorage;
static bool_t isImageDataInit = FALSE;
-bool_t isImageInicialized()
+bool_t
+isImageInicialized()
{
- return isImageDataInit;
+ return isImageDataInit;
}
/*
* Inicializuje globalny zoznam obrazkov
*/
-void initImageData()
+void
+initImageData()
{
- assert( isInterfaceInicialized() == TRUE );
+ assert(isInterfaceInicialized() == TRUE);
#ifdef DEBUG
- printf(_("Initializing image database\n"));
+ printf(_("Initializing image database\n"));
#endif
- listStorage = newStorage();
- isImageDataInit = TRUE;
+ listStorage = newStorage();
+ isImageDataInit = TRUE;
}
-static SDL_Surface *loadImage(const char *filename, int alpha)
+static SDL_Surface *
+loadImage(const char *filename, int alpha)
{
- SDL_Surface *tmp;
- SDL_Surface *ret;
-
- char str[STR_PATH_SIZE];
-
-
- if( isFillPath(filename) )
- {
- strcpy(str, filename);
- }
- else
- {
- sprintf(str, PATH_IMAGE "%s", filename);
- }
-
- accessExistFile(str);
-
- if( ( tmp = IMG_Load(str) ) == NULL )
- {
- fprintf(stderr, "%s\n", SDL_GetError());
- return NULL;
- }
-
- if( ( ret = (alpha) ? SDL_DisplayFormatAlpha(tmp) : SDL_DisplayFormat(tmp) ) == NULL )
- {
- fprintf(stderr, "%s\n", SDL_GetError());
- SDL_FreeSurface(tmp);
- return NULL;
- }
-
- SDL_FreeSurface(tmp);
- return ret;
+ SDL_Surface *tmp;
+ SDL_Surface *ret;
+
+ char str[STR_PATH_SIZE];
+
+
+ if (isFillPath(filename)) {
+ strcpy(str, filename);
+ }
+ else {
+ sprintf(str, PATH_IMAGE "%s", filename);
+ }
+
+ accessExistFile(str);
+
+ if ((tmp = IMG_Load(str)) == NULL) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return NULL;
+ }
+
+ if ((ret =
+ (alpha) ? SDL_DisplayFormatAlpha(tmp) : SDL_DisplayFormat(tmp)) ==
+ NULL) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_FreeSurface(tmp);
+ return NULL;
+ }
+
+ SDL_FreeSurface(tmp);
+ return ret;
}
-image_t* newImage(SDL_Surface *surface)
+image_t *
+newImage(SDL_Surface * surface)
{
- image_t *new;
+ image_t *new;
- assert( surface != NULL );
+ assert(surface != NULL);
- new = malloc( sizeof(image_t) );
- new->image = surface;
- new->w = surface->w;
- new->h = surface->h;
+ new = malloc(sizeof(image_t));
+ new->image = surface;
+ new->w = surface->w;
+ new->h = surface->h;
- return new;
+ return new;
}
-static void destroyImage(image_t *p)
+static void
+destroyImage(image_t * p)
{
- assert( p != NULL );
- SDL_FreeSurface((SDL_Surface *)p->image);
- free(p);
+ assert(p != NULL);
+ SDL_FreeSurface((SDL_Surface *) p->image);
+ free(p);
}
/*
@@ -95,82 +98,86 @@ static void destroyImage(image_t *p)
* *name - nazov obrazku ( pouzije sa ako vyhadavaci retazec v zazanem )
* alpha - 0 - nema alpha kanal | 1 - ma alpha kanal
*/
-image_t* addImageData(char *file, int alpha, char *name, char *group)
+image_t *
+addImageData(char *file, int alpha, char *name, char *group)
{
- SDL_Surface *surface;
- image_t *new;
+ SDL_Surface *surface;
+ image_t *new;
- assert( file != NULL );
- assert( name != NULL );
- assert( group != NULL );
+ assert(file != NULL);
+ assert(name != NULL);
+ assert(group != NULL);
- surface = loadImage(file, alpha);
- new = newImage(surface);
+ surface = loadImage(file, alpha);
+ new = newImage(surface);
- addItemToStorage(listStorage, group, name, new );
+ addItemToStorage(listStorage, group, name, new);
#ifdef DEBUG
- printf(_("Loading image %s\n"), file);
+ printf(_("Loading image %s\n"), file);
#endif
- return new;
+ return new;
}
/*
* Vrati odkaz na image_data v globalnom zozname obrazkov
* a nazvom *s
*/
-image_t* getImage(char *group, char *name)
+image_t *
+getImage(char *group, char *name)
{
- assert( group != NULL );
- assert( name != NULL );
+ assert(group != NULL);
+ assert(name != NULL);
- return getItemFromStorage(listStorage, group, name);
+ return getItemFromStorage(listStorage, group, name);
}
-void delImage(char *group, char *name)
+void
+delImage(char *group, char *name)
{
- assert( group != NULL );
- assert( name != NULL );
-
- delItemFromStorage(listStorage, group, name, destroyImage);
+ assert(group != NULL);
+ assert(name != NULL);
+
+ delItemFromStorage(listStorage, group, name, destroyImage);
}
-void delAllImageInGroup(char *group)
+void
+delAllImageInGroup(char *group)
{
- assert( group != NULL );
+ assert(group != NULL);
- delAllItemFromStorage(listStorage, group, destroyImage);
+ delAllItemFromStorage(listStorage, group, destroyImage);
}
-void drawImage(image_t *p, int x,int y, int px, int py, int w, int h)
+void
+drawImage(image_t * p, int x, int y, int px, int py, int w, int h)
{
- static SDL_Surface *screen = NULL;
- SDL_Rect dst_rect, src_rect;
+ static SDL_Surface *screen = NULL;
+ SDL_Rect dst_rect, src_rect;
- if( screen == NULL )
- {
- screen = getSDL_Screen();
- }
+ if (screen == NULL) {
+ screen = getSDL_Screen();
+ }
- dst_rect.x = x;
- dst_rect.y = y;
+ dst_rect.x = x;
+ dst_rect.y = y;
- src_rect.x = px;
- src_rect.y = py;
- src_rect.w = w;
- src_rect.h = h;
+ src_rect.x = px;
+ src_rect.y = py;
+ src_rect.w = w;
+ src_rect.h = h;
- SDL_BlitSurface(p->image, &src_rect, screen, &dst_rect);
+ SDL_BlitSurface(p->image, &src_rect, screen, &dst_rect);
}
/*
* Odstrani zoznam obrazkov z pamate
*/
-void quitImageData()
+void
+quitImageData()
{
#ifdef DEBUG
- printf(_("Quitting image database\n"));
+ printf(_("Quitting image database\n"));
#endif
- destroyStorage(listStorage, destroyImage);
- isImageDataInit = FALSE;
+ destroyStorage(listStorage, destroyImage);
+ isImageDataInit = FALSE;
}
-
diff --git a/src/client/image.c~ b/src/client/image.c~
new file mode 100644
index 0000000..4c4010c
--- /dev/null
+++ b/src/client/image.c~
@@ -0,0 +1,176 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "storage.h"
+
+#include "interface.h"
+#include "image.h"
+
+static list_t *listStorage;
+
+static bool_t isImageDataInit = FALSE;
+
+bool_t isImageInicialized()
+{
+ return isImageDataInit;
+}
+
+/*
+ * Inicializuje globalny zoznam obrazkov
+ */
+void initImageData()
+{
+ assert( isInterfaceInicialized() == TRUE );
+#ifdef DEBUG
+ printf(_("Initializing image database\n"));
+#endif
+ listStorage = newStorage();
+ isImageDataInit = TRUE;
+}
+
+static SDL_Surface *loadImage(const char *filename, int alpha)
+{
+ SDL_Surface *tmp;
+ SDL_Surface *ret;
+
+ char str[STR_PATH_SIZE];
+
+
+ if( isFillPath(filename) )
+ {
+ strcpy(str, filename);
+ }
+ else
+ {
+ sprintf(str, PATH_IMAGE "%s", filename);
+ }
+
+ accessExistFile(str);
+
+ if( ( tmp = IMG_Load(str) ) == NULL )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return NULL;
+ }
+
+ if( ( ret = (alpha) ? SDL_DisplayFormatAlpha(tmp) : SDL_DisplayFormat(tmp) ) == NULL )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_FreeSurface(tmp);
+ return NULL;
+ }
+
+ SDL_FreeSurface(tmp);
+ return ret;
+}
+
+image_t* newImage(SDL_Surface *surface)
+{
+ image_t *new;
+
+ assert( surface != NULL );
+
+ new = malloc( sizeof(image_t) );
+ new->image = surface;
+ new->w = surface->w;
+ new->h = surface->h;
+
+ return new;
+}
+
+static void destroyImage(image_t *p)
+{
+ assert( p != NULL );
+ SDL_FreeSurface((SDL_Surface *)p->image);
+ free(p);
+}
+
+/*
+ * Prida obrazok do globalneho zoznamu obrazkov
+ * *file - nazov suboru v ktorom je obrazok ulozeny
+ * *name - nazov obrazku ( pouzije sa ako vyhadavaci retazec v zazanem )
+ * alpha - 0 - nema alpha kanal | 1 - ma alpha kanal
+ */
+image_t* addImageData(char *file, int alpha, char *name, char *group)
+{
+ SDL_Surface *surface;
+ image_t *new;
+
+ assert( file != NULL );
+ assert( name != NULL );
+ assert( group != NULL );
+
+ surface = loadImage(file, alpha);
+ new = newImage(surface);
+
+ addItemToStorage(listStorage, group, name, new );
+#ifdef DEBUG
+ printf(_("Loading image %s\n"), file);
+#endif
+ return new;
+}
+
+/*
+ * Vrati odkaz na image_data v globalnom zozname obrazkov
+ * a nazvom *s
+ */
+image_t* getImage(char *group, char *name)
+{
+ assert( group != NULL );
+ assert( name != NULL );
+
+ return getItemFromStorage(listStorage, group, name);
+}
+
+void delImage(char *group, char *name)
+{
+ assert( group != NULL );
+ assert( name != NULL );
+
+ delItemFromStorage(listStorage, group, name, destroyImage);
+}
+
+void delAllImageInGroup(char *group)
+{
+ assert( group != NULL );
+
+ delAllItemFromStorage(listStorage, group, destroyImage);
+}
+
+void drawImage(image_t *p, int x,int y, int px, int py, int w, int h)
+{
+ static SDL_Surface *screen = NULL;
+ SDL_Rect dst_rect, src_rect;
+
+ if( screen == NULL )
+ {
+ screen = getSDL_Screen();
+ }
+
+ dst_rect.x = x;
+ dst_rect.y = y;
+
+ src_rect.x = px;
+ src_rect.y = py;
+ src_rect.w = w;
+ src_rect.h = h;
+
+ SDL_BlitSurface(p->image, &src_rect, screen, &dst_rect);
+}
+
+/*
+ * Odstrani zoznam obrazkov z pamate
+ */
+void quitImageData()
+{
+#ifdef DEBUG
+ printf(_("Quitting image database\n"));
+#endif
+ destroyStorage(listStorage, destroyImage);
+ isImageDataInit = FALSE;
+}
+
diff --git a/src/client/interface.c b/src/client/interface.c
index 5fb77c1..39e5d4c 100755
--- a/src/client/interface.c
+++ b/src/client/interface.c
@@ -17,77 +17,84 @@ static SDL_Surface *screen;
static SDL_TimerID timer;
// window flags
-static Uint32 g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_ANYFORMAT;
+static Uint32 g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
static bool_t isInterfaceInit = FALSE;
// flag, kterym se ridi zarazovani klaves do bufferu
bool_t keyboardBufferEnabled = FALSE;
-bool_t isInterfaceInicialized()
+bool_t
+isInterfaceInicialized()
{
- return isInterfaceInit;
+ return isInterfaceInit;
}
-static Uint32 TimerCallback(Uint32 interval, void *param)
+static Uint32
+TimerCallback(Uint32 interval, void *param)
{
- SDL_Event event;
- event.type = SDL_USEREVENT;
- event.user.code = USR_EVT_TIMER;
- event.user.data1 = NULL;
- event.user.data2 = NULL;
+ SDL_Event event;
+ event.type = SDL_USEREVENT;
+ event.user.code = USR_EVT_TIMER;
+ event.user.data1 = NULL;
+ event.user.data2 = NULL;
- SDL_PushEvent(&event);
+ SDL_PushEvent(&event);
- return interval;
+ return interval;
}
-void enableKeyboardBuffer(){
- keyboardBufferEnabled=TRUE;
+void
+enableKeyboardBuffer()
+{
+ keyboardBufferEnabled = TRUE;
}
-void disableKeyboardBuffer(){
- keyboardBufferEnabled=FALSE;
+void
+disableKeyboardBuffer()
+{
+ keyboardBufferEnabled = FALSE;
}
-void hotkey_screen()
+void
+hotkey_screen()
{
- if(g_win_flags & SDL_FULLSCREEN)
- g_win_flags &= ~SDL_FULLSCREEN;
- else
- g_win_flags |= SDL_FULLSCREEN;
-
- if( SDL_WM_ToggleFullScreen(screen) == 0 )
- {
- fprintf(stderr, _("Unable to switch to FULLSCREEN mode!\n"));
-
- SDL_FreeSurface(screen);
- screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, g_win_flags);
-
- if(screen == NULL)
- {
- fprintf(stderr, _("Unable to switch to WINDOW mode! Error: %s\n"), SDL_GetError());
- return;
- }
- }
+ if (g_win_flags & SDL_FULLSCREEN)
+ g_win_flags &= ~SDL_FULLSCREEN;
+ else
+ g_win_flags |= SDL_FULLSCREEN;
+
+ if (SDL_WM_ToggleFullScreen(screen) == 0) {
+ fprintf(stderr, _("Unable to switch to FULLSCREEN mode!\n"));
+
+ SDL_FreeSurface(screen);
+ screen =
+ SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, g_win_flags);
+
+ if (screen == NULL) {
+ fprintf(stderr, _("Unable to switch to WINDOW mode! Error: %s\n"),
+ SDL_GetError());
+ return;
+ }
+ }
}
-int initSDL()
+int
+initSDL()
{
#ifdef DEBUG
- printf(_("Initializing SDL system\n"));
+ printf(_("Initializing SDL system\n"));
#endif
- // initialization of SDL
- if( SDL_Init(SDL_SUBSYSTEMS) == -1 )
- {
- fprintf(stderr, "%s\n", SDL_GetError());
- SDL_Quit();
- return -1;
- }
+ // initialization of SDL
+ if (SDL_Init(SDL_SUBSYSTEMS) == -1) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_Quit();
+ return -1;
+ }
- // initialization of SDL
- //screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
- screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ // initialization of SDL
+ //screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
/*
my_surface = SDL_CreateRGBSurface(screen->flags, WINDOW_SIZE_X, WINDOW_SIZE_Y,
@@ -95,85 +102,88 @@ int initSDL()
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());
- SDL_Quit();
- return -1;
- }
+ if (screen == NULL) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_Quit();
+ return -1;
+ }
- SDL_WM_SetCaption(WINDOW_TITLE, NULL);
- //SDL_ShowCursor(0);
- SDL_EnableKeyRepeat(0,1);
- timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL);
+ SDL_WM_SetCaption(WINDOW_TITLE, NULL);
+ //SDL_ShowCursor(0);
+ SDL_EnableKeyRepeat(0, 1);
+ timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL);
- initKeyboardBuffer(KEYBOARD_BUFFER_SIZE);
-
- initHotKey();
- registerHotKey(SDLK_F1, hotkey_screen);
-
- srand((unsigned)time(NULL));
- isInterfaceInit = TRUE;
+ initKeyboardBuffer(KEYBOARD_BUFFER_SIZE);
- return 0;
+ initHotKey();
+ registerHotKey(SDLK_F1, hotkey_screen);
+
+ srand((unsigned) time(NULL));
+ isInterfaceInit = TRUE;
+
+ return 0;
}
-SDL_Surface* getSDL_Screen()
+SDL_Surface *
+getSDL_Screen()
{
- //return my_surface;
- return screen;
+ //return my_surface;
+ return screen;
}
-void interfaceRefresh()
+void
+interfaceRefresh()
{
- //SDL_BlitSurface(my_surface, NULL, screen, NULL);
- //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
+ //SDL_BlitSurface(my_surface, NULL, screen, NULL);
+ //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
- //drawImage(my_surface, 200, 100, 0, 0, 200, 200);
- SDL_Flip(screen);
- //SDL_UpdateRect(screen, 400, 0, 400, 600);
+ //drawImage(my_surface, 200, 100, 0, 0, 200, 200);
+ SDL_Flip(screen);
+ //SDL_UpdateRect(screen, 400, 0, 400, 600);
}
-void getMousePosition(int *x, int *y)
+void
+getMousePosition(int *x, int *y)
{
- SDL_GetMouseState(x, y);
+ SDL_GetMouseState(x, y);
}
-int isMouseClicked()
+int
+isMouseClicked()
{
- return SDL_GetMouseState(NULL,NULL) & SDL_BUTTON(SDL_BUTTON_LEFT);
+ return SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT);
}
-int isPressAnyKey()
+int
+isPressAnyKey()
{
- Uint8 *mapa;
- int i;
+ Uint8 *mapa;
+ int i;
- mapa = SDL_GetKeyState(NULL);
+ mapa = SDL_GetKeyState(NULL);
- for( i = SDLK_BACKSPACE ; i < SDLK_KP9 ; i++ )
- if( mapa[i] == SDL_PRESSED )
- {
- return 1;
- }
+ for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++)
+ if (mapa[i] == SDL_PRESSED) {
+ return 1;
+ }
- return 0;
+ return 0;
}
-void printPressAnyKey()
+void
+printPressAnyKey()
{
- Uint8 *mapa;
- int i;
+ Uint8 *mapa;
+ int i;
- mapa = SDL_GetKeyState(NULL);
+ mapa = SDL_GetKeyState(NULL);
- for( i = SDLK_BACKSPACE ; i < SDLK_KP9 ; i++ )
- if( mapa[i] == SDL_PRESSED )
- {
- printf(_("Pressed key with SDL value: %d\n"), i);
- }
+ for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++)
+ if (mapa[i] == SDL_PRESSED) {
+ printf(_("Pressed key with SDL value: %d\n"), i);
+ }
}
@@ -194,18 +204,16 @@ static void action_esc()
}
*/
-int eventAction()
+int
+eventAction()
{
- SDL_Event event;
+ SDL_Event event;
- while(SDL_WaitEvent(&event))
- {
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
+ while (SDL_WaitEvent(&event)) {
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
/*
case SDLK_ESCAPE:
action_esc();
@@ -217,70 +225,74 @@ int eventAction()
if(!toggleFullscreen())return 0;
break;
*/
- default:
- //neni potreba vyuzivat frontu stale
- if (keyboardBufferEnabled==TRUE)
- pushKeyToKeyboardBuffer(event.key.keysym);
- break;
- }
- break;
-
- case SDL_USEREVENT:
- switch(event.user.code)
- {
- case USR_EVT_TIMER:
- drawScreen();
- eventScreen();
- eventHotKey();
- switchScreen();
- break;
-
- default:
- break;
- }
- break;
-
- // change of window size
- case SDL_VIDEORESIZE:
- screen = SDL_SetVideoMode(event.resize.w,event.resize.h, WIN_BPP, g_win_flags);
-
- if(screen == NULL)
- {
- fprintf(stderr, _("Unable to change WINDOW resolution! Error: %s\n"),SDL_GetError());
- return 0;
- }
- break;
-
- // termination request
- case SDL_QUIT:
- return -1;
- break;
-
- default:
- break;
- }
- }
-
- return 0;
+ default:
+ //neni potreba vyuzivat frontu stale
+ if (keyboardBufferEnabled == TRUE)
+ pushKeyToKeyboardBuffer(event.key.keysym);
+ break;
+ }
+ break;
+
+ case SDL_USEREVENT:
+ switch (event.user.code) {
+ case USR_EVT_TIMER:
+ drawScreen();
+ eventScreen();
+ eventHotKey();
+ switchScreen();
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ // change of window size
+ case SDL_VIDEORESIZE:
+ screen =
+ SDL_SetVideoMode(event.resize.w, event.resize.h, WIN_BPP,
+ g_win_flags);
+
+ if (screen == NULL) {
+ fprintf(stderr,
+ _("Unable to change WINDOW resolution! Error: %s\n"),
+ SDL_GetError());
+ return 0;
+ }
+ break;
+
+ // termination request
+ case SDL_QUIT:
+ return -1;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return 0;
}
-void eventSDL()
+void
+eventSDL()
{
- while(1)
- {
- if ( eventAction() == -1 )return;
- }
+ while (1) {
+ if (eventAction() == -1)
+ return;
+ }
}
-void quitSDL()
+void
+quitSDL()
{
#ifdef DEBUG
- printf(_("Quitting SDL\n"));
+ printf(_("Quitting SDL\n"));
#endif
- quitHotKey();
- quitKeyboardBuffer();
+ quitHotKey();
+ quitKeyboardBuffer();
- SDL_Quit();
+ SDL_Quit();
- isInterfaceInit = FALSE;
+ isInterfaceInit = FALSE;
}
diff --git a/src/client/interface.c~ b/src/client/interface.c~
new file mode 100644
index 0000000..5fb77c1
--- /dev/null
+++ b/src/client/interface.c~
@@ -0,0 +1,286 @@
+
+#include <stdlib.h>
+
+#include "main.h"
+#include "myTimer.h"
+
+#include "interface.h"
+#include "screen.h"
+#include "keyboardBuffer.h"
+#include "hotKey.h"
+
+// window surface
+static SDL_Surface *screen;
+//static SDL_Surface *my_surface;
+
+// timer
+static SDL_TimerID timer;
+
+// window flags
+static Uint32 g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_ANYFORMAT;
+
+static bool_t isInterfaceInit = FALSE;
+
+// flag, kterym se ridi zarazovani klaves do bufferu
+bool_t keyboardBufferEnabled = FALSE;
+
+bool_t isInterfaceInicialized()
+{
+ return isInterfaceInit;
+}
+
+static Uint32 TimerCallback(Uint32 interval, void *param)
+{
+ SDL_Event event;
+ event.type = SDL_USEREVENT;
+ event.user.code = USR_EVT_TIMER;
+ event.user.data1 = NULL;
+ event.user.data2 = NULL;
+
+ SDL_PushEvent(&event);
+
+ return interval;
+}
+
+void enableKeyboardBuffer(){
+ keyboardBufferEnabled=TRUE;
+}
+
+void disableKeyboardBuffer(){
+ keyboardBufferEnabled=FALSE;
+}
+
+void hotkey_screen()
+{
+ if(g_win_flags & SDL_FULLSCREEN)
+ g_win_flags &= ~SDL_FULLSCREEN;
+ else
+ g_win_flags |= SDL_FULLSCREEN;
+
+ if( SDL_WM_ToggleFullScreen(screen) == 0 )
+ {
+ fprintf(stderr, _("Unable to switch to FULLSCREEN mode!\n"));
+
+ SDL_FreeSurface(screen);
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, g_win_flags);
+
+ if(screen == NULL)
+ {
+ fprintf(stderr, _("Unable to switch to WINDOW mode! Error: %s\n"), SDL_GetError());
+ return;
+ }
+ }
+}
+
+int initSDL()
+{
+#ifdef DEBUG
+ printf(_("Initializing SDL system\n"));
+#endif
+ // initialization of SDL
+ if( SDL_Init(SDL_SUBSYSTEMS) == -1 )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_Quit();
+ return -1;
+ }
+
+ // initialization of SDL
+ //screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+
+/*
+ my_surface = SDL_CreateRGBSurface(screen->flags, WINDOW_SIZE_X, WINDOW_SIZE_Y,
+ screen->format->BitsPerPixel,
+ screen->format->Rmask, screen->format->Gmask,
+ screen->format->Bmask, screen->format->Amask);
+*/
+ //memset(my_surface->pixels, 128, 200);
+
+ if (screen == NULL )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_Quit();
+ return -1;
+ }
+
+ SDL_WM_SetCaption(WINDOW_TITLE, NULL);
+ //SDL_ShowCursor(0);
+ SDL_EnableKeyRepeat(0,1);
+ timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL);
+
+ initKeyboardBuffer(KEYBOARD_BUFFER_SIZE);
+
+ initHotKey();
+ registerHotKey(SDLK_F1, hotkey_screen);
+
+ srand((unsigned)time(NULL));
+ isInterfaceInit = TRUE;
+
+ return 0;
+}
+
+SDL_Surface* getSDL_Screen()
+{
+ //return my_surface;
+ return screen;
+}
+
+void interfaceRefresh()
+{
+ //SDL_BlitSurface(my_surface, NULL, screen, NULL);
+ //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
+
+ //drawImage(my_surface, 200, 100, 0, 0, 200, 200);
+ SDL_Flip(screen);
+ //SDL_UpdateRect(screen, 400, 0, 400, 600);
+}
+
+void getMousePosition(int *x, int *y)
+{
+ SDL_GetMouseState(x, y);
+}
+
+int isMouseClicked()
+{
+ return SDL_GetMouseState(NULL,NULL) & SDL_BUTTON(SDL_BUTTON_LEFT);
+}
+
+int isPressAnyKey()
+{
+ Uint8 *mapa;
+ int i;
+
+ mapa = SDL_GetKeyState(NULL);
+
+ for( i = SDLK_BACKSPACE ; i < SDLK_KP9 ; i++ )
+ if( mapa[i] == SDL_PRESSED )
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+void printPressAnyKey()
+{
+ Uint8 *mapa;
+ int i;
+
+ mapa = SDL_GetKeyState(NULL);
+
+ for( i = SDLK_BACKSPACE ; i < SDLK_KP9 ; i++ )
+ if( mapa[i] == SDL_PRESSED )
+ {
+ printf(_("Pressed key with SDL value: %d\n"), i);
+ }
+
+}
+
+
+/*
+static void action_esc()
+{
+ if( strcmp(getScreen(), "world") == 0 )
+ {
+ setScreen("analyze");
+ }
+
+ if( strcmp(getScreen(), "mainMenu") == 0 )
+ {
+ quit();
+ }
+
+}
+*/
+
+int eventAction()
+{
+ SDL_Event event;
+
+
+ while(SDL_WaitEvent(&event))
+ {
+ switch(event.type)
+ {
+ case SDL_KEYDOWN:
+ switch(event.key.keysym.sym)
+ {
+/*
+ case SDLK_ESCAPE:
+ action_esc();
+ return 0;
+ break;
+*/
+/*
+ case SDLK_F1:
+ if(!toggleFullscreen())return 0;
+ break;
+*/
+ default:
+ //neni potreba vyuzivat frontu stale
+ if (keyboardBufferEnabled==TRUE)
+ pushKeyToKeyboardBuffer(event.key.keysym);
+ break;
+ }
+ break;
+
+ case SDL_USEREVENT:
+ switch(event.user.code)
+ {
+ case USR_EVT_TIMER:
+ drawScreen();
+ eventScreen();
+ eventHotKey();
+ switchScreen();
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ // change of window size
+ case SDL_VIDEORESIZE:
+ screen = SDL_SetVideoMode(event.resize.w,event.resize.h, WIN_BPP, g_win_flags);
+
+ if(screen == NULL)
+ {
+ fprintf(stderr, _("Unable to change WINDOW resolution! Error: %s\n"),SDL_GetError());
+ return 0;
+ }
+ break;
+
+ // termination request
+ case SDL_QUIT:
+ return -1;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}
+
+void eventSDL()
+{
+ while(1)
+ {
+ if ( eventAction() == -1 )return;
+ }
+}
+
+void quitSDL()
+{
+#ifdef DEBUG
+ printf(_("Quitting SDL\n"));
+#endif
+ quitHotKey();
+ quitKeyboardBuffer();
+
+ SDL_Quit();
+
+ isInterfaceInit = FALSE;
+}
diff --git a/src/client/keyboardBuffer.c b/src/client/keyboardBuffer.c
index 246d262..894060f 100644
--- a/src/client/keyboardBuffer.c
+++ b/src/client/keyboardBuffer.c
@@ -23,129 +23,137 @@ static SDL_keysym emptyKey;
/*
* Key buffer initializes. The parameter sets the number of keys.
*/
-void initKeyboardBuffer(int size)
+void
+initKeyboardBuffer(int size)
{
- assert(size > 0);
- assert(keyboardBuffer == NULL);
+ assert(size > 0);
+ assert(keyboardBuffer == NULL);
- keyboardBuffer = malloc(sizeof(keyboardBuffer_t));
- assert(keyboardBuffer != NULL);
- memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t));
+ keyboardBuffer = malloc(sizeof(keyboardBuffer_t));
+ assert(keyboardBuffer != NULL);
+ memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t));
- keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym));
- assert(keyboardBuffer->buff != NULL);
- memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym));
+ keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym));
+ assert(keyboardBuffer->buff != NULL);
+ memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym));
- keyboardBuffer->begin = 0;
- keyboardBuffer->end = 0;
- keyboardBuffer->count = 0;
- keyboardBuffer->size = size;
+ keyboardBuffer->begin = 0;
+ keyboardBuffer->end = 0;
+ keyboardBuffer->count = 0;
+ keyboardBuffer->size = size;
- emptyKey.sym = SDLK_UNKNOWN;
+ emptyKey.sym = SDLK_UNKNOWN;
}
/*
* Empty the buffer
*/
-void clearKeyboardBuffer()
+void
+clearKeyboardBuffer()
{
- assert(keyboardBuffer != NULL);
+ assert(keyboardBuffer != NULL);
- keyboardBuffer->begin = 0;
- keyboardBuffer->end = 0;
- keyboardBuffer->count = 0;
- memset(keyboardBuffer->buff, 0, keyboardBuffer->size * sizeof(SDL_keysym));
+ keyboardBuffer->begin = 0;
+ keyboardBuffer->end = 0;
+ keyboardBuffer->count = 0;
+ memset(keyboardBuffer->buff, 0, keyboardBuffer->size * sizeof(SDL_keysym));
}
/*
* Adds key to the end of the buffer. If the buffer is overrun,
* an error is printed to stderr and the key is dropped.
*/
-bool_t pushKeyToKeyboardBuffer(SDL_keysym key)
+bool_t
+pushKeyToKeyboardBuffer(SDL_keysym key)
{
- assert(keyboardBuffer != NULL);
+ assert(keyboardBuffer != NULL);
- if (keyboardBuffer->count >= keyboardBuffer->size){
- fprintf(stderr, _("Keyboard Buffer overrun! Dropping key: %02x\n"), key.sym);
- return FALSE;
- }
+ if (keyboardBuffer->count >= keyboardBuffer->size) {
+ fprintf(stderr, _("Keyboard Buffer overrun! Dropping key: %02x\n"),
+ key.sym);
+ return FALSE;
+ }
- keyboardBuffer->buff[keyboardBuffer->end] = key;
+ keyboardBuffer->buff[keyboardBuffer->end] = key;
- keyboardBuffer->end++;
- if (keyboardBuffer->end >= keyboardBuffer->size) {
- keyboardBuffer->end = 0;
- }
+ keyboardBuffer->end++;
+ if (keyboardBuffer->end >= keyboardBuffer->size) {
+ keyboardBuffer->end = 0;
+ }
- keyboardBuffer->count++;
+ keyboardBuffer->count++;
- return TRUE;
+ return TRUE;
}
/*
* Takes out first key from the buffer and returns it. If the buffer is empty,
* an error is printed to stderr and SDLK_UNKNOWN is returned.
*/
-SDL_keysym popKeyFromKeyboardBuffer()
+SDL_keysym
+popKeyFromKeyboardBuffer()
{
- assert(keyboardBuffer != NULL);
+ assert(keyboardBuffer != NULL);
- if (keyboardBuffer->count <= 0){
- fprintf(stderr, _("Keyboard Buffer underrun!\n"));
- return emptyKey;
- }
+ if (keyboardBuffer->count <= 0) {
+ fprintf(stderr, _("Keyboard Buffer underrun!\n"));
+ return emptyKey;
+ }
- SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin];
- keyboardBuffer->buff[keyboardBuffer->begin] = emptyKey;
+ SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin];
+ keyboardBuffer->buff[keyboardBuffer->begin] = emptyKey;
- keyboardBuffer->begin++;
- if (keyboardBuffer->begin >= keyboardBuffer->size) {
- keyboardBuffer->begin = 0;
- }
+ keyboardBuffer->begin++;
+ if (keyboardBuffer->begin >= keyboardBuffer->size) {
+ keyboardBuffer->begin = 0;
+ }
- keyboardBuffer->count--;
+ keyboardBuffer->count--;
- return key;
+ return key;
}
/*
* The buffer size
*/
-int getKeyboardBufferSize()
+int
+getKeyboardBufferSize()
{
- assert(keyboardBuffer != NULL);
- return keyboardBuffer->size;
+ assert(keyboardBuffer != NULL);
+ return keyboardBuffer->size;
}
/*
* Number of keys in the buffer
*/
-int KeyboardBufferCount()
+int
+KeyboardBufferCount()
{
- assert(keyboardBuffer != NULL);
- return keyboardBuffer->count;
+ assert(keyboardBuffer != NULL);
+ return keyboardBuffer->count;
}
-bool_t isAnyKeyInKeyboardBuffer()
+bool_t
+isAnyKeyInKeyboardBuffer()
{
- return KeyboardBufferCount() > 0 ? TRUE : FALSE;
+ return KeyboardBufferCount() > 0 ? TRUE : FALSE;
}
/*
* Frees the buffer. If it is not empty, information
* about filling is prined to stderr first.
*/
-void quitKeyboardBuffer()
+void
+quitKeyboardBuffer()
{
- assert(keyboardBuffer != NULL);
+ assert(keyboardBuffer != NULL);
- if (keyboardBuffer->count > 0){
- fprintf(stderr, _("Keyboard buffer is not empty!\n"));
- }
+ if (keyboardBuffer->count > 0) {
+ fprintf(stderr, _("Keyboard buffer is not empty!\n"));
+ }
- free(keyboardBuffer->buff);
- free(keyboardBuffer);
- keyboardBuffer = NULL;
+ free(keyboardBuffer->buff);
+ free(keyboardBuffer);
+ keyboardBuffer = NULL;
}
-
diff --git a/src/client/keyboardBuffer.c~ b/src/client/keyboardBuffer.c~
new file mode 100644
index 0000000..246d262
--- /dev/null
+++ b/src/client/keyboardBuffer.c~
@@ -0,0 +1,151 @@
+/*
+ * keyboardBuffer.c
+ *
+ * Created on: 1. 8. 2008
+ * Author: Karel Podvolecky
+ *
+ * Simple front of pressed keys.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <SDL.h>
+
+#include "keyboardBuffer.h"
+
+static keyboardBuffer_t *keyboardBuffer = NULL;
+
+static SDL_keysym emptyKey;
+
+/*
+ * Key buffer initializes. The parameter sets the number of keys.
+ */
+void initKeyboardBuffer(int size)
+{
+ assert(size > 0);
+ assert(keyboardBuffer == NULL);
+
+ keyboardBuffer = malloc(sizeof(keyboardBuffer_t));
+ assert(keyboardBuffer != NULL);
+ memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t));
+
+ keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym));
+ assert(keyboardBuffer->buff != NULL);
+ memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym));
+
+ keyboardBuffer->begin = 0;
+ keyboardBuffer->end = 0;
+ keyboardBuffer->count = 0;
+ keyboardBuffer->size = size;
+
+ emptyKey.sym = SDLK_UNKNOWN;
+}
+
+/*
+ * Empty the buffer
+ */
+void clearKeyboardBuffer()
+{
+ assert(keyboardBuffer != NULL);
+
+ keyboardBuffer->begin = 0;
+ keyboardBuffer->end = 0;
+ keyboardBuffer->count = 0;
+ memset(keyboardBuffer->buff, 0, keyboardBuffer->size * sizeof(SDL_keysym));
+}
+
+/*
+ * Adds key to the end of the buffer. If the buffer is overrun,
+ * an error is printed to stderr and the key is dropped.
+ */
+bool_t pushKeyToKeyboardBuffer(SDL_keysym key)
+{
+ assert(keyboardBuffer != NULL);
+
+ if (keyboardBuffer->count >= keyboardBuffer->size){
+ fprintf(stderr, _("Keyboard Buffer overrun! Dropping key: %02x\n"), key.sym);
+ return FALSE;
+ }
+
+ keyboardBuffer->buff[keyboardBuffer->end] = key;
+
+ keyboardBuffer->end++;
+ if (keyboardBuffer->end >= keyboardBuffer->size) {
+ keyboardBuffer->end = 0;
+ }
+
+ keyboardBuffer->count++;
+
+ return TRUE;
+}
+
+/*
+ * Takes out first key from the buffer and returns it. If the buffer is empty,
+ * an error is printed to stderr and SDLK_UNKNOWN is returned.
+ */
+SDL_keysym popKeyFromKeyboardBuffer()
+{
+ assert(keyboardBuffer != NULL);
+
+ if (keyboardBuffer->count <= 0){
+ fprintf(stderr, _("Keyboard Buffer underrun!\n"));
+ return emptyKey;
+ }
+
+ SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin];
+ keyboardBuffer->buff[keyboardBuffer->begin] = emptyKey;
+
+ keyboardBuffer->begin++;
+ if (keyboardBuffer->begin >= keyboardBuffer->size) {
+ keyboardBuffer->begin = 0;
+ }
+
+ keyboardBuffer->count--;
+
+ return key;
+}
+
+/*
+ * The buffer size
+ */
+int getKeyboardBufferSize()
+{
+ assert(keyboardBuffer != NULL);
+ return keyboardBuffer->size;
+}
+
+/*
+ * Number of keys in the buffer
+ */
+int KeyboardBufferCount()
+{
+ assert(keyboardBuffer != NULL);
+ return keyboardBuffer->count;
+}
+
+
+bool_t isAnyKeyInKeyboardBuffer()
+{
+ return KeyboardBufferCount() > 0 ? TRUE : FALSE;
+}
+
+/*
+ * Frees the buffer. If it is not empty, information
+ * about filling is prined to stderr first.
+ */
+void quitKeyboardBuffer()
+{
+ assert(keyboardBuffer != NULL);
+
+ if (keyboardBuffer->count > 0){
+ fprintf(stderr, _("Keyboard buffer is not empty!\n"));
+ }
+
+ free(keyboardBuffer->buff);
+ free(keyboardBuffer);
+ keyboardBuffer = NULL;
+}
+
diff --git a/src/client/layer.c b/src/client/layer.c
index 8e77ee4..cadb7c6 100755
--- a/src/client/layer.c
+++ b/src/client/layer.c
@@ -16,18 +16,20 @@ static list_t *listLayer;
static bool_t isLayerInit = FALSE;
-bool_t isLayerInicialized()
+bool_t
+isLayerInicialized()
{
- return isLayerInit;
+ return isLayerInit;
}
/*
* Inicializuje globalny zoznam vsrtiev
*/
-void initLayer()
+void
+initLayer()
{
- listLayer = newList();
- isLayerInit = TRUE;
+ listLayer = newList();
+ isLayerInit = TRUE;
}
/*
@@ -37,46 +39,42 @@ void initLayer()
* px py pw ph - suradnica casti obrazka *img ktora sa ma zobrazit
* layer - vrstva na ktorej sa zobrazi obrazok
*/
-void addLayer(image_t *img,
- int x,int y, int px,int py,
- int w,int h, int player)
+void
+addLayer(image_t * img,
+ int x, int y, int px, int py, int w, int h, int player)
{
- layer_t *new;
- layer_t *this;
- int i, j;
-
- assert( img != NULL );
-
- new = malloc( sizeof(layer_t) );
- new->x = x;
- new->y = y;
- new->w = w;
- new->h = h;
- new->px = px;
- new->py = py;
- new->layer = player;
- new->image = img;
-
- for( i = 0 ; i < listLayer->count ; i++ )
- {
- this = (layer_t *)listLayer->list[i];
-
- if( this->layer == new->layer )
- {
- for( j = i ; j < listLayer->count ; j++ )
- {
- this = (layer_t *)listLayer->list[j];
-
- if( this->y+this->h > new->y+new->h )
- {
- insList(listLayer, j, new);
- return;
- }
- }
- }
- }
-
- addList(listLayer, new);
+ layer_t *new;
+ layer_t *this;
+ int i, j;
+
+ assert(img != NULL);
+
+ new = malloc(sizeof(layer_t));
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->px = px;
+ new->py = py;
+ new->layer = player;
+ new->image = img;
+
+ for (i = 0; i < listLayer->count; i++) {
+ this = (layer_t *) listLayer->list[i];
+
+ if (this->layer == new->layer) {
+ for (j = i; j < listLayer->count; j++) {
+ this = (layer_t *) listLayer->list[j];
+
+ if (this->y + this->h > new->y + new->h) {
+ insList(listLayer, j, new);
+ return;
+ }
+ }
+ }
+ }
+
+ addList(listLayer, new);
}
/*
@@ -84,138 +82,130 @@ void addLayer(image_t *img,
* poukadane podla vrstvy a suradnice Y+H
* po dokresleni sa zoznam uvolni.
*/
-void drawLayer()
+void
+drawLayer()
{
- layer_t *this;
- int i;
+ layer_t *this;
+ int i;
- for( i = 0 ; i < listLayer->count ; i++ )
- {
- this = (layer_t *)listLayer->list[i];
+ for (i = 0; i < listLayer->count; i++) {
+ this = (layer_t *) listLayer->list[i];
- drawImage(this->image,
- this->x, this->y,
- this->px, this->py,
- this->w, this->h);
- }
+ drawImage(this->image,
+ this->x, this->y, this->px, this->py, this->w, this->h);
+ }
- //printf("listLayer->count = %d\n", listLayer->count);
+ //printf("listLayer->count = %d\n", listLayer->count);
- destroyListItem(listLayer, free);
- listLayer = newList();
+ destroyListItem(listLayer, free);
+ listLayer = newList();
}
-void drawLayerCenter(int x, int y)
+void
+drawLayerCenter(int x, int y)
{
- layer_t *this;
- int screen_x, screen_y;
- int i;
- //int count = 0;
+ layer_t *this;
+ int screen_x, screen_y;
+ int i;
+ //int count = 0;
- getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
+ getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
- for( i = 0 ; i < listLayer->count ; i++ )
- {
- this = (layer_t *)listLayer->list[i];
+ for (i = 0; i < listLayer->count; i++) {
+ this = (layer_t *) listLayer->list[i];
- if( this->x + this->w < screen_x || this->x > screen_x + WINDOW_SIZE_X ||
- this->y + this->h < screen_y || this->y > screen_y + WINDOW_SIZE_Y )
- {
- continue;
- }
+ if (this->x + this->w < screen_x || this->x > screen_x + WINDOW_SIZE_X
+ || this->y + this->h < screen_y
+ || this->y > screen_y + WINDOW_SIZE_Y) {
+ continue;
+ }
- //count++;
+ //count++;
- drawImage(this->image,
- this->x - screen_x, this->y - screen_y,
- this->px, this->py,
- this->w, this->h);
+ drawImage(this->image,
+ this->x - screen_x, this->y - screen_y,
+ this->px, this->py, this->w, this->h);
- //printf("%d %d\n", this->x - screen_x, this->y - screen_y);
- }
+ //printf("%d %d\n", this->x - screen_x, this->y - screen_y);
+ }
- //printf("count = %d\n", count);
+ //printf("count = %d\n", count);
- destroyListItem(listLayer, free);
- listLayer = newList();
+ destroyListItem(listLayer, free);
+ listLayer = newList();
}
-void drawLayerSplit(int local_x, int local_y, int x, int y, int w, int h)
+void
+drawLayerSplit(int local_x, int local_y, int x, int y, int w, int h)
{
- layer_t *this;
- int i;
- //int count = 0;
+ layer_t *this;
+ int i;
+ //int count = 0;
- for( i = 0 ; i < listLayer->count ; i++ )
- {
- this = (layer_t *)listLayer->list[i];
+ for (i = 0; i < listLayer->count; i++) {
+ this = (layer_t *) listLayer->list[i];
- if( this->x + this->w < x || this->x > x + w ||
- this->y + this->h < y || this->y > y + h )
- {
- continue;
- }
+ if (this->x + this->w < x || this->x > x + w ||
+ this->y + this->h < y || this->y > y + h) {
+ continue;
+ }
- //count++;
+ //count++;
- if( local_x + (this->x - x) < local_x )
- {
- int z;
+ if (local_x + (this->x - x) < local_x) {
+ int z;
- z = local_x - ( local_x + (this->x - x) );
+ z = local_x - (local_x + (this->x - x));
- this->x += z;
- this->px += z;
- this->w -= z;
- }
+ this->x += z;
+ this->px += z;
+ this->w -= z;
+ }
- if( local_x + (this->x - x) + this->w > local_x+w )
- {
- this->w -= ( local_x + (this->x - x) + this->w ) - (local_x + w);
- }
+ if (local_x + (this->x - x) + this->w > local_x + w) {
+ this->w -= (local_x + (this->x - x) + this->w) - (local_x + w);
+ }
- if( local_y + (this->y - y) < local_y )
- {
- int z;
+ if (local_y + (this->y - y) < local_y) {
+ int z;
- z = local_y - ( local_y + (this->y - y) );
+ z = local_y - (local_y + (this->y - y));
- this->y += z;
- this->py += z;
- this->h -= z;
- }
+ this->y += z;
+ this->py += z;
+ this->h -= z;
+ }
- if( local_y + (this->y - y) + this->h > local_y+h )
- {
- this->h -= ( local_y + (this->y - y) + this->h ) - (local_y + h);
- }
+ if (local_y + (this->y - y) + this->h > local_y + h) {
+ this->h -= (local_y + (this->y - y) + this->h) - (local_y + h);
+ }
- drawImage(this->image,
- local_x + (this->x - x), local_y + (this->y - y),
- this->px, this->py,
- this->w, this->h);
+ drawImage(this->image,
+ local_x + (this->x - x), local_y + (this->y - y),
+ this->px, this->py, this->w, this->h);
- //printf("%d %d\n", this->x - screen_x, this->y - screen_y);
- }
+ //printf("%d %d\n", this->x - screen_x, this->y - screen_y);
+ }
- //printf("count = %d\n", count);
+ //printf("count = %d\n", count);
- destroyListItem(listLayer, free);
- listLayer = newList();
+ destroyListItem(listLayer, free);
+ listLayer = newList();
}
-void flushLayer()
+void
+flushLayer()
{
- destroyListItem(listLayer, free);
- listLayer = newList();
+ destroyListItem(listLayer, free);
+ listLayer = newList();
}
/*
* Odstrani zoznam vrtsiev z pamete.
*/
-void quitLayer()
+void
+quitLayer()
{
- destroyListItem(listLayer, free);
- isLayerInit = FALSE;
+ destroyListItem(listLayer, free);
+ isLayerInit = FALSE;
}
-
diff --git a/src/client/layer.c~ b/src/client/layer.c~
new file mode 100644
index 0000000..8e77ee4
--- /dev/null
+++ b/src/client/layer.c~
@@ -0,0 +1,221 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+
+#include "interface.h"
+#include "layer.h"
+#include "image.h"
+
+#include "screen_world.h"
+
+static list_t *listLayer;
+
+static bool_t isLayerInit = FALSE;
+
+bool_t isLayerInicialized()
+{
+ return isLayerInit;
+}
+
+/*
+ * Inicializuje globalny zoznam vsrtiev
+ */
+void initLayer()
+{
+ listLayer = newList();
+ isLayerInit = TRUE;
+}
+
+/*
+ * Prida novu polozku do zoznamu vrstiev
+ * *img - obrazok, ktory obsahuje polozka
+ * x y w h - suradnca kam sa obrazok vykresli a jeho rozmery
+ * px py pw ph - suradnica casti obrazka *img ktora sa ma zobrazit
+ * layer - vrstva na ktorej sa zobrazi obrazok
+ */
+void addLayer(image_t *img,
+ int x,int y, int px,int py,
+ int w,int h, int player)
+{
+ layer_t *new;
+ layer_t *this;
+ int i, j;
+
+ assert( img != NULL );
+
+ new = malloc( sizeof(layer_t) );
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->px = px;
+ new->py = py;
+ new->layer = player;
+ new->image = img;
+
+ for( i = 0 ; i < listLayer->count ; i++ )
+ {
+ this = (layer_t *)listLayer->list[i];
+
+ if( this->layer == new->layer )
+ {
+ for( j = i ; j < listLayer->count ; j++ )
+ {
+ this = (layer_t *)listLayer->list[j];
+
+ if( this->y+this->h > new->y+new->h )
+ {
+ insList(listLayer, j, new);
+ return;
+ }
+ }
+ }
+ }
+
+ addList(listLayer, new);
+}
+
+/*
+ * Vykresli vsetky polozky na obrazovku
+ * poukadane podla vrstvy a suradnice Y+H
+ * po dokresleni sa zoznam uvolni.
+ */
+void drawLayer()
+{
+ layer_t *this;
+ int i;
+
+ for( i = 0 ; i < listLayer->count ; i++ )
+ {
+ this = (layer_t *)listLayer->list[i];
+
+ drawImage(this->image,
+ this->x, this->y,
+ this->px, this->py,
+ this->w, this->h);
+ }
+
+ //printf("listLayer->count = %d\n", listLayer->count);
+
+ destroyListItem(listLayer, free);
+ listLayer = newList();
+}
+
+void drawLayerCenter(int x, int y)
+{
+ layer_t *this;
+ int screen_x, screen_y;
+ int i;
+ //int count = 0;
+
+ getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
+
+ for( i = 0 ; i < listLayer->count ; i++ )
+ {
+ this = (layer_t *)listLayer->list[i];
+
+ if( this->x + this->w < screen_x || this->x > screen_x + WINDOW_SIZE_X ||
+ this->y + this->h < screen_y || this->y > screen_y + WINDOW_SIZE_Y )
+ {
+ continue;
+ }
+
+ //count++;
+
+ drawImage(this->image,
+ this->x - screen_x, this->y - screen_y,
+ this->px, this->py,
+ this->w, this->h);
+
+ //printf("%d %d\n", this->x - screen_x, this->y - screen_y);
+ }
+
+ //printf("count = %d\n", count);
+
+ destroyListItem(listLayer, free);
+ listLayer = newList();
+}
+
+void drawLayerSplit(int local_x, int local_y, int x, int y, int w, int h)
+{
+ layer_t *this;
+ int i;
+ //int count = 0;
+
+ for( i = 0 ; i < listLayer->count ; i++ )
+ {
+ this = (layer_t *)listLayer->list[i];
+
+ if( this->x + this->w < x || this->x > x + w ||
+ this->y + this->h < y || this->y > y + h )
+ {
+ continue;
+ }
+
+ //count++;
+
+ if( local_x + (this->x - x) < local_x )
+ {
+ int z;
+
+ z = local_x - ( local_x + (this->x - x) );
+
+ this->x += z;
+ this->px += z;
+ this->w -= z;
+ }
+
+ if( local_x + (this->x - x) + this->w > local_x+w )
+ {
+ this->w -= ( local_x + (this->x - x) + this->w ) - (local_x + w);
+ }
+
+ if( local_y + (this->y - y) < local_y )
+ {
+ int z;
+
+ z = local_y - ( local_y + (this->y - y) );
+
+ this->y += z;
+ this->py += z;
+ this->h -= z;
+ }
+
+ if( local_y + (this->y - y) + this->h > local_y+h )
+ {
+ this->h -= ( local_y + (this->y - y) + this->h ) - (local_y + h);
+ }
+
+ drawImage(this->image,
+ local_x + (this->x - x), local_y + (this->y - y),
+ this->px, this->py,
+ this->w, this->h);
+
+ //printf("%d %d\n", this->x - screen_x, this->y - screen_y);
+ }
+
+ //printf("count = %d\n", count);
+
+ destroyListItem(listLayer, free);
+ listLayer = newList();
+}
+
+void flushLayer()
+{
+ destroyListItem(listLayer, free);
+ listLayer = newList();
+}
+
+/*
+ * Odstrani zoznam vrtsiev z pamete.
+ */
+void quitLayer()
+{
+ destroyListItem(listLayer, free);
+ isLayerInit = FALSE;
+}
+
diff --git a/src/client/panel.c b/src/client/panel.c
index b84cdfb..774d3e1 100644
--- a/src/client/panel.c
+++ b/src/client/panel.c
@@ -19,162 +19,196 @@ static image_t *g_bonus;
static bool_t isPanelInit = FALSE;
-bool_t isPanelInicialized()
+bool_t
+isPanelInicialized()
{
- return isPanelInit;
+ return isPanelInit;
}
-void initPanel()
+void
+initPanel()
{
- assert( isImageInicialized() == TRUE );
- assert( isInterfaceInicialized() == TRUE );
-
- g_panel = addImageData("panel.png", IMAGE_ALPHA, "panel", IMAGE_GROUP_BASE);
- g_shot = addImageData("panel_shot.png", IMAGE_ALPHA, "panel_image_shot", IMAGE_GROUP_BASE);
- g_bonus = addImageData("graf.bonus.png", IMAGE_ALPHA, "panel_graf_bonus", IMAGE_GROUP_BASE);
-
- g_icon[GUN_SIMPLE] = addImageData("icon.gun.simple.png", IMAGE_ALPHA, "panel_gun", IMAGE_GROUP_BASE);
- g_icon[GUN_DUAL_SIMPLE] = addImageData("icon.gun.dual.simple.png", IMAGE_ALPHA, "panel_dual", IMAGE_GROUP_BASE);
- g_icon[GUN_TOMMY] = addImageData("icon.gun.tommy.png", IMAGE_ALPHA, "panel_tommy", IMAGE_GROUP_BASE);
- g_icon[GUN_SCATTER] = addImageData("icon.gun.scatter.png", IMAGE_ALPHA, "panel_scatter", IMAGE_GROUP_BASE);
- g_icon[GUN_LASSER] = addImageData("icon.gun.lasser.png", IMAGE_ALPHA, "panel_lasser", IMAGE_GROUP_BASE);
- g_icon[GUN_MINE] = addImageData("icon.gun.mine.png", IMAGE_ALPHA, "panel_mine", IMAGE_GROUP_BASE);
- g_icon[GUN_BOMBBALL] = addImageData("icon.gun.bombball.png", IMAGE_ALPHA, "panel_bombball", IMAGE_GROUP_BASE);
-
- g_icon[BONUS_SPEED] = addImageData("icon.bonus.speed.png", IMAGE_ALPHA, "panel_speed", IMAGE_GROUP_BASE);
- g_icon[BONUS_SHOT] = addImageData("icon.bonus.shot.png", IMAGE_ALPHA, "panel_shot", IMAGE_GROUP_BASE);
- g_icon[BONUS_TELEPORT] = addImageData("icon.bonus.teleport.png", IMAGE_ALPHA, "panel_teleport", IMAGE_GROUP_BASE);
- g_icon[BONUS_GHOST] = addImageData("icon.bonus.ghost.png", IMAGE_ALPHA, "panel_ghost", IMAGE_GROUP_BASE);
- g_icon[BONUS_4X] = addImageData("icon.bonus.4x.png", IMAGE_ALPHA, "panel_4x", IMAGE_GROUP_BASE);
- g_icon[BONUS_HIDDEN] = addImageData("icon.bonus.hidden.png", IMAGE_ALPHA, "panel_hidden", IMAGE_GROUP_BASE);
-
- isPanelInit = TRUE;
+ assert(isImageInicialized() == TRUE);
+ assert(isInterfaceInicialized() == TRUE);
+
+ g_panel =
+ addImageData("panel.png", IMAGE_ALPHA, "panel", IMAGE_GROUP_BASE);
+ g_shot =
+ addImageData("panel_shot.png", IMAGE_ALPHA, "panel_image_shot",
+ IMAGE_GROUP_BASE);
+ g_bonus =
+ addImageData("graf.bonus.png", IMAGE_ALPHA, "panel_graf_bonus",
+ IMAGE_GROUP_BASE);
+
+ g_icon[GUN_SIMPLE] =
+ addImageData("icon.gun.simple.png", IMAGE_ALPHA, "panel_gun",
+ IMAGE_GROUP_BASE);
+ g_icon[GUN_DUAL_SIMPLE] =
+ addImageData("icon.gun.dual.simple.png", IMAGE_ALPHA, "panel_dual",
+ IMAGE_GROUP_BASE);
+ g_icon[GUN_TOMMY] =
+ addImageData("icon.gun.tommy.png", IMAGE_ALPHA, "panel_tommy",
+ IMAGE_GROUP_BASE);
+ g_icon[GUN_SCATTER] =
+ addImageData("icon.gun.scatter.png", IMAGE_ALPHA, "panel_scatter",
+ IMAGE_GROUP_BASE);
+ g_icon[GUN_LASSER] =
+ addImageData("icon.gun.lasser.png", IMAGE_ALPHA, "panel_lasser",
+ IMAGE_GROUP_BASE);
+ g_icon[GUN_MINE] =
+ addImageData("icon.gun.mine.png", IMAGE_ALPHA, "panel_mine",
+ IMAGE_GROUP_BASE);
+ g_icon[GUN_BOMBBALL] =
+ addImageData("icon.gun.bombball.png", IMAGE_ALPHA, "panel_bombball",
+ IMAGE_GROUP_BASE);
+
+ g_icon[BONUS_SPEED] =
+ addImageData("icon.bonus.speed.png", IMAGE_ALPHA, "panel_speed",
+ IMAGE_GROUP_BASE);
+ g_icon[BONUS_SHOT] =
+ addImageData("icon.bonus.shot.png", IMAGE_ALPHA, "panel_shot",
+ IMAGE_GROUP_BASE);
+ g_icon[BONUS_TELEPORT] =
+ addImageData("icon.bonus.teleport.png", IMAGE_ALPHA, "panel_teleport",
+ IMAGE_GROUP_BASE);
+ g_icon[BONUS_GHOST] =
+ addImageData("icon.bonus.ghost.png", IMAGE_ALPHA, "panel_ghost",
+ IMAGE_GROUP_BASE);
+ g_icon[BONUS_4X] =
+ addImageData("icon.bonus.4x.png", IMAGE_ALPHA, "panel_4x",
+ IMAGE_GROUP_BASE);
+ g_icon[BONUS_HIDDEN] =
+ addImageData("icon.bonus.hidden.png", IMAGE_ALPHA, "panel_hidden",
+ IMAGE_GROUP_BASE);
+
+ isPanelInit = TRUE;
}
-static void drawScore(tux_t *tux_right, tux_t *tux_left)
+static void
+drawScore(tux_t * tux_right, tux_t * tux_left)
{
- char strScoreLine[STR_SIZE];
- int w, h;
-
- 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);
- }
-
- getTextSize(strScoreLine, &w , &h);
- drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y, COLOR_WHITE);
+ char strScoreLine[STR_SIZE];
+ int w, h;
+
+ 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);
+ }
+
+ getTextSize(strScoreLine, &w, &h);
+ drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y,
+ COLOR_WHITE);
}
-static void drawShot(int n, int x, int y)
+static void
+drawShot(int n, int x, int y)
{
- drawImage(g_shot, x, y,n * PANEL_SHOT_WIDTH, 0, PANEL_SHOT_WIDTH, PANEL_SHOT_HEIGHT);
+ drawImage(g_shot, x, y, n * PANEL_SHOT_WIDTH, 0, PANEL_SHOT_WIDTH,
+ PANEL_SHOT_HEIGHT);
}
-static void drawShotInfo(tux_t *tux,int x, int y)
+static void
+drawShotInfo(tux_t * tux, int x, int y)
{
- int i;
-
- if( tux->pickup_time > 0 )
- {
- for( i = 0 ; i < tux->pickup_time / 3 ; i++ )
- {
- drawShot(PANEL_SHOT_LINE, x + i * PANEL_SHOT_WIDTH, y);
- }
-
- return;
- }
-
- for( i = 0 ; i < GUN_MAX_SHOT ; i++ )
- {
- if( tux->shot[tux->gun] > i )
- {
- drawShot(PANEL_SHOT_FILL, x + i * ( PANEL_SHOT_WIDTH + 2 ), y);
- }
- else
- {
- drawShot(PANEL_SHOT_EMPTY, x + i * ( PANEL_SHOT_WIDTH + 2 ) , y);
- }
- }
+ int i;
+
+ if (tux->pickup_time > 0) {
+ for (i = 0; i < tux->pickup_time / 3; i++) {
+ drawShot(PANEL_SHOT_LINE, x + i * PANEL_SHOT_WIDTH, y);
+ }
+
+ return;
+ }
+
+ for (i = 0; i < GUN_MAX_SHOT; i++) {
+ if (tux->shot[tux->gun] > i) {
+ drawShot(PANEL_SHOT_FILL, x + i * (PANEL_SHOT_WIDTH + 2), y);
+ }
+ else {
+ drawShot(PANEL_SHOT_EMPTY, x + i * (PANEL_SHOT_WIDTH + 2), y);
+ }
+ }
}
-static void drawGunInfo(tux_t *tux,int x, int y)
+static void
+drawGunInfo(tux_t * tux, int x, int y)
{
- drawImage(g_icon[ tux->gun ], x, y, 0, 0,
- g_icon[ tux->gun ]->w, g_icon[ tux->gun ]->h);
+ drawImage(g_icon[tux->gun], x, y, 0, 0,
+ g_icon[tux->gun]->w, g_icon[tux->gun]->h);
}
-static void drawBonusInfo(tux_t *tux,int x, int y)
+static void
+drawBonusInfo(tux_t * tux, int x, int y)
{
- drawImage(g_icon[ tux->bonus ], x, y, 0, 0, g_icon[ tux->bonus ]->w, g_icon[ tux->bonus ]->h);
+ drawImage(g_icon[tux->bonus], x, y, 0, 0, g_icon[tux->bonus]->w,
+ g_icon[tux->bonus]->h);
}
-static void drawGrafBonus(tux_t *tux,int x, int y)
+static void
+drawGrafBonus(tux_t * tux, int x, int y)
{
- int offset;
+ int offset;
- offset = tux->bonus_time / 5;
- drawImage(g_bonus, x, y, 0, 0, g_bonus->w, g_bonus->h/2);
- drawImage(g_bonus, x+1, y, 0, g_bonus->h/2, offset, g_bonus->h/2);
+ offset = tux->bonus_time / 5;
+ drawImage(g_bonus, x, y, 0, 0, g_bonus->w, g_bonus->h / 2);
+ drawImage(g_bonus, x + 1, y, 0, g_bonus->h / 2, offset, g_bonus->h / 2);
}
-static void drawTuxRight(tux_t *tux)
+static void
+drawTuxRight(tux_t * tux)
{
- if( tux == NULL )
- {
- return;
- }
-
- drawShotInfo(tux, PANEL_LOCATION_X+740, PANEL_LOCATION_Y+34);
- drawGunInfo(tux, PANEL_LOCATION_X+620, PANEL_LOCATION_Y+30);
-
- 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 (tux == NULL) {
+ return;
+ }
+
+ drawShotInfo(tux, PANEL_LOCATION_X + 740, PANEL_LOCATION_Y + 34);
+ drawGunInfo(tux, PANEL_LOCATION_X + 620, PANEL_LOCATION_Y + 30);
+
+ 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);
+ }
}
-static void drawTuxLeft(tux_t *tux)
+static void
+drawTuxLeft(tux_t * tux)
{
- if( tux == NULL )
- {
- return;
- }
-
- 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 )
- {
- drawGrafBonus(tux, PANEL_LOCATION_X+200, PANEL_LOCATION_Y+50);
- drawBonusInfo(tux, PANEL_LOCATION_X+200, PANEL_LOCATION_Y+30);
- }
+ if (tux == NULL) {
+ return;
+ }
+
+ 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) {
+ drawGrafBonus(tux, PANEL_LOCATION_X + 200, PANEL_LOCATION_Y + 50);
+ drawBonusInfo(tux, PANEL_LOCATION_X + 200, PANEL_LOCATION_Y + 30);
+ }
}
-void drawPanel(tux_t *tux_right, tux_t *tux_left)
+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);
+ drawImage(g_panel, PANEL_LOCATION_X, PANEL_LOCATION_Y, 0, 0, g_panel->w,
+ g_panel->h);
+ drawScore(tux_right, tux_left);
- if( isRecivedNewMsg() )
- {
- drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y, COLOR_WHITE);
- }
+ if (isRecivedNewMsg()) {
+ drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y,
+ COLOR_WHITE);
+ }
- drawTuxRight(tux_right);
- drawTuxLeft(tux_left);
+ drawTuxRight(tux_right);
+ drawTuxLeft(tux_left);
}
-void quitPanel()
+void
+quitPanel()
{
- isPanelInit = FALSE;
+ isPanelInit = FALSE;
}
-
diff --git a/src/client/panel.c~ b/src/client/panel.c~
new file mode 100644
index 0000000..b84cdfb
--- /dev/null
+++ b/src/client/panel.c~
@@ -0,0 +1,180 @@
+
+#include <stdio.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+
+#include "interface.h"
+#include "image.h"
+#include "panel.h"
+#include "font.h"
+#include "chat.h"
+
+static image_t *g_panel;
+static image_t *g_shot;
+static image_t *g_icon[ITEM_COUNT];
+static image_t *g_bonus;
+
+static bool_t isPanelInit = FALSE;
+
+bool_t isPanelInicialized()
+{
+ return isPanelInit;
+}
+
+void initPanel()
+{
+ assert( isImageInicialized() == TRUE );
+ assert( isInterfaceInicialized() == TRUE );
+
+ g_panel = addImageData("panel.png", IMAGE_ALPHA, "panel", IMAGE_GROUP_BASE);
+ g_shot = addImageData("panel_shot.png", IMAGE_ALPHA, "panel_image_shot", IMAGE_GROUP_BASE);
+ g_bonus = addImageData("graf.bonus.png", IMAGE_ALPHA, "panel_graf_bonus", IMAGE_GROUP_BASE);
+
+ g_icon[GUN_SIMPLE] = addImageData("icon.gun.simple.png", IMAGE_ALPHA, "panel_gun", IMAGE_GROUP_BASE);
+ g_icon[GUN_DUAL_SIMPLE] = addImageData("icon.gun.dual.simple.png", IMAGE_ALPHA, "panel_dual", IMAGE_GROUP_BASE);
+ g_icon[GUN_TOMMY] = addImageData("icon.gun.tommy.png", IMAGE_ALPHA, "panel_tommy", IMAGE_GROUP_BASE);
+ g_icon[GUN_SCATTER] = addImageData("icon.gun.scatter.png", IMAGE_ALPHA, "panel_scatter", IMAGE_GROUP_BASE);
+ g_icon[GUN_LASSER] = addImageData("icon.gun.lasser.png", IMAGE_ALPHA, "panel_lasser", IMAGE_GROUP_BASE);
+ g_icon[GUN_MINE] = addImageData("icon.gun.mine.png", IMAGE_ALPHA, "panel_mine", IMAGE_GROUP_BASE);
+ g_icon[GUN_BOMBBALL] = addImageData("icon.gun.bombball.png", IMAGE_ALPHA, "panel_bombball", IMAGE_GROUP_BASE);
+
+ g_icon[BONUS_SPEED] = addImageData("icon.bonus.speed.png", IMAGE_ALPHA, "panel_speed", IMAGE_GROUP_BASE);
+ g_icon[BONUS_SHOT] = addImageData("icon.bonus.shot.png", IMAGE_ALPHA, "panel_shot", IMAGE_GROUP_BASE);
+ g_icon[BONUS_TELEPORT] = addImageData("icon.bonus.teleport.png", IMAGE_ALPHA, "panel_teleport", IMAGE_GROUP_BASE);
+ g_icon[BONUS_GHOST] = addImageData("icon.bonus.ghost.png", IMAGE_ALPHA, "panel_ghost", IMAGE_GROUP_BASE);
+ g_icon[BONUS_4X] = addImageData("icon.bonus.4x.png", IMAGE_ALPHA, "panel_4x", IMAGE_GROUP_BASE);
+ g_icon[BONUS_HIDDEN] = addImageData("icon.bonus.hidden.png", IMAGE_ALPHA, "panel_hidden", IMAGE_GROUP_BASE);
+
+ isPanelInit = TRUE;
+}
+
+static void drawScore(tux_t *tux_right, tux_t *tux_left)
+{
+ char strScoreLine[STR_SIZE];
+ int w, h;
+
+ 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);
+ }
+
+ getTextSize(strScoreLine, &w , &h);
+ drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y, COLOR_WHITE);
+}
+
+static void drawShot(int n, int x, int y)
+{
+ drawImage(g_shot, x, y,n * PANEL_SHOT_WIDTH, 0, PANEL_SHOT_WIDTH, PANEL_SHOT_HEIGHT);
+}
+
+static void drawShotInfo(tux_t *tux,int x, int y)
+{
+ int i;
+
+ if( tux->pickup_time > 0 )
+ {
+ for( i = 0 ; i < tux->pickup_time / 3 ; i++ )
+ {
+ drawShot(PANEL_SHOT_LINE, x + i * PANEL_SHOT_WIDTH, y);
+ }
+
+ return;
+ }
+
+ for( i = 0 ; i < GUN_MAX_SHOT ; i++ )
+ {
+ if( tux->shot[tux->gun] > i )
+ {
+ drawShot(PANEL_SHOT_FILL, x + i * ( PANEL_SHOT_WIDTH + 2 ), y);
+ }
+ else
+ {
+ drawShot(PANEL_SHOT_EMPTY, x + i * ( PANEL_SHOT_WIDTH + 2 ) , y);
+ }
+ }
+}
+
+static void drawGunInfo(tux_t *tux,int x, int y)
+{
+ drawImage(g_icon[ tux->gun ], x, y, 0, 0,
+ g_icon[ tux->gun ]->w, g_icon[ tux->gun ]->h);
+}
+
+static void drawBonusInfo(tux_t *tux,int x, int y)
+{
+ drawImage(g_icon[ tux->bonus ], x, y, 0, 0, g_icon[ tux->bonus ]->w, g_icon[ tux->bonus ]->h);
+}
+
+static void drawGrafBonus(tux_t *tux,int x, int y)
+{
+ int offset;
+
+ offset = tux->bonus_time / 5;
+ drawImage(g_bonus, x, y, 0, 0, g_bonus->w, g_bonus->h/2);
+ drawImage(g_bonus, x+1, y, 0, g_bonus->h/2, offset, g_bonus->h/2);
+}
+
+static void drawTuxRight(tux_t *tux)
+{
+ if( tux == NULL )
+ {
+ return;
+ }
+
+ drawShotInfo(tux, PANEL_LOCATION_X+740, PANEL_LOCATION_Y+34);
+ drawGunInfo(tux, PANEL_LOCATION_X+620, PANEL_LOCATION_Y+30);
+
+ 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);
+ }
+}
+
+static void drawTuxLeft(tux_t *tux)
+{
+ if( tux == NULL )
+ {
+ return;
+ }
+
+ 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 )
+ {
+ drawGrafBonus(tux, PANEL_LOCATION_X+200, PANEL_LOCATION_Y+50);
+ drawBonusInfo(tux, PANEL_LOCATION_X+200, PANEL_LOCATION_Y+30);
+ }
+}
+
+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);
+
+ if( isRecivedNewMsg() )
+ {
+ drawFont("recived new msg", PANEL_LOCATION_X, PANEL_LOCATION_Y, COLOR_WHITE);
+ }
+
+ drawTuxRight(tux_right);
+ drawTuxLeft(tux_left);
+}
+
+void quitPanel()
+{
+ isPanelInit = FALSE;
+}
+
diff --git a/src/client/pauza.c b/src/client/pauza.c
index a4a9a4c..701a0da 100644
--- a/src/client/pauza.c
+++ b/src/client/pauza.c
@@ -15,54 +15,57 @@
static image_t *g_pauza;
static bool_t activePauza;
-static void switchPauzed()
+static void
+switchPauzed()
{
- if( activePauza == TRUE )
- {
- activePauza = FALSE;
- }
- else
- {
- activePauza = TRUE;
- }
+ if (activePauza == TRUE) {
+ activePauza = FALSE;
+ }
+ else {
+ activePauza = TRUE;
+ }
}
-static void hotkey_pauze()
+static void
+hotkey_pauze()
{
- switchPauzed();
+ switchPauzed();
}
-void initPauza()
+void
+initPauza()
{
- g_pauza = addImageData("pauza.png", IMAGE_ALPHA, "pauza", IMAGE_GROUP_USER);
- activePauza = FALSE;
+ g_pauza =
+ addImageData("pauza.png", IMAGE_ALPHA, "pauza", IMAGE_GROUP_USER);
+ activePauza = FALSE;
- registerHotKey(SDLK_p, hotkey_pauze);
+ registerHotKey(SDLK_p, hotkey_pauze);
}
-void drawPauza()
+void
+drawPauza()
{
- if( activePauza )
- {
- drawImage(g_pauza,
- WINDOW_SIZE_X/2 - g_pauza->w/2,
- WINDOW_SIZE_Y/2 - g_pauza->h/2,
- 0, 0,
- g_pauza->w, g_pauza->h);
- }
+ if (activePauza) {
+ drawImage(g_pauza,
+ WINDOW_SIZE_X / 2 - g_pauza->w / 2,
+ WINDOW_SIZE_Y / 2 - g_pauza->h / 2,
+ 0, 0, g_pauza->w, g_pauza->h);
+ }
}
-void eventPauza()
+void
+eventPauza()
{
}
-bool_t isPauzeActive()
+bool_t
+isPauzeActive()
{
- return activePauza;
+ return activePauza;
}
-void quitPauza()
+void
+quitPauza()
{
- unregisterHotKey(SDLK_p);
+ unregisterHotKey(SDLK_p);
}
-
diff --git a/src/client/pauza.c~ b/src/client/pauza.c~
new file mode 100644
index 0000000..a4a9a4c
--- /dev/null
+++ b/src/client/pauza.c~
@@ -0,0 +1,68 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "myTimer.h"
+
+#include "interface.h"
+#include "image.h"
+#include "pauza.h"
+#include "hotKey.h"
+
+static image_t *g_pauza;
+static bool_t activePauza;
+
+static void switchPauzed()
+{
+ if( activePauza == TRUE )
+ {
+ activePauza = FALSE;
+ }
+ else
+ {
+ activePauza = TRUE;
+ }
+}
+
+static void hotkey_pauze()
+{
+ switchPauzed();
+}
+
+void initPauza()
+{
+ g_pauza = addImageData("pauza.png", IMAGE_ALPHA, "pauza", IMAGE_GROUP_USER);
+ activePauza = FALSE;
+
+ registerHotKey(SDLK_p, hotkey_pauze);
+}
+
+void drawPauza()
+{
+ if( activePauza )
+ {
+ drawImage(g_pauza,
+ WINDOW_SIZE_X/2 - g_pauza->w/2,
+ WINDOW_SIZE_Y/2 - g_pauza->h/2,
+ 0, 0,
+ g_pauza->w, g_pauza->h);
+ }
+}
+
+void eventPauza()
+{
+}
+
+bool_t isPauzeActive()
+{
+ return activePauza;
+}
+
+void quitPauza()
+{
+ unregisterHotKey(SDLK_p);
+}
+
diff --git a/src/client/radar.c b/src/client/radar.c
index afa48d4..6fd3a68 100644
--- a/src/client/radar.c
+++ b/src/client/radar.c
@@ -17,105 +17,110 @@ static list_t *listRadar;
typedef struct radar_item_struct
{
- int id;
- int x, y;
- int type;
+ int id;
+ int x, y;
+ int type;
} radar_item_t;
-static radar_item_t* newRadarItem(int id, int x, int y, int type)
+static radar_item_t *
+newRadarItem(int id, int x, int y, int type)
{
- radar_item_t *new;
+ radar_item_t *new;
- new = malloc( sizeof(radar_item_t) );
- new->id = id;
- new->x = x;
- new->y = y;
- new->type = type;
+ new = malloc(sizeof(radar_item_t));
+ new->id = id;
+ new->x = x;
+ new->y = y;
+ new->type = type;
- return new;
+ return new;
}
-static void destroyRadarItem(radar_item_t *p)
+static void
+destroyRadarItem(radar_item_t * p)
{
- assert( p != NULL );
- free(p);
+ assert(p != NULL);
+ free(p);
}
-void addToRadar(int id, int x, int y, int type)
+void
+addToRadar(int id, int x, int y, int type)
{
- int i;
+ int i;
- for( i = 0 ; i < listRadar->count ; i++ )
- {
- radar_item_t *thisRadarItem;
+ for (i = 0; i < listRadar->count; i++) {
+ radar_item_t *thisRadarItem;
- thisRadarItem = (radar_item_t *)listRadar->list[i];
+ thisRadarItem = (radar_item_t *) listRadar->list[i];
- if( thisRadarItem->id == id )
- {
- thisRadarItem->x = x;
- thisRadarItem->y = y;
- thisRadarItem->type = type;
- return;
- }
- }
+ if (thisRadarItem->id == id) {
+ thisRadarItem->x = x;
+ thisRadarItem->y = y;
+ thisRadarItem->type = type;
+ return;
+ }
+ }
- addList(listRadar, newRadarItem(id, x, y, type) );
+ addList(listRadar, newRadarItem(id, x, y, type));
}
-void delFromRadar(int id)
+void
+delFromRadar(int id)
{
- int i;
+ int i;
- for( i = 0 ; i < listRadar->count ; i++ )
- {
- radar_item_t *thisRadarItem;
+ for (i = 0; i < listRadar->count; i++) {
+ radar_item_t *thisRadarItem;
- thisRadarItem = (radar_item_t *)listRadar->list[i];
+ thisRadarItem = (radar_item_t *) listRadar->list[i];
- if( thisRadarItem->id == id )
- {
- delListItem(listRadar, i, destroyRadarItem);
- return;
- }
- }
+ if (thisRadarItem->id == id) {
+ delListItem(listRadar, i, destroyRadarItem);
+ return;
+ }
+ }
}
-void initRadar()
+void
+initRadar()
{
- assert( isImageInicialized() == TRUE );
- assert( isInterfaceInicialized() == TRUE );
+ assert(isImageInicialized() == TRUE);
+ assert(isInterfaceInicialized() == TRUE);
- g_radar = addImageData("radar.png", IMAGE_NO_ALPHA, "radar", IMAGE_GROUP_USER);
- listRadar = newList();
+ g_radar =
+ addImageData("radar.png", IMAGE_NO_ALPHA, "radar", IMAGE_GROUP_USER);
+ listRadar = newList();
}
-void drawRadar(arena_t *arena)
+void
+drawRadar(arena_t * arena)
{
- int i;
+ int i;
- drawImage(g_radar, RADAR_LOCATION_X, RADAR_LOCATION_Y, 0, 0, RADAR_SIZE_X+2, RADAR_SIZE_Y+2);
+ 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;
+ for (i = 0; i < listRadar->count; i++) {
+ radar_item_t *thisRadarItem;
+ int x, y;
- thisRadarItem = (radar_item_t *)listRadar->list[i];
+ 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 );
+ x = (((float) RADAR_SIZE_X) / ((float) arena->w)) *
+ ((float) thisRadarItem->x);
+ y = (((float) RADAR_SIZE_Y) / ((float) arena->h)) *
+ ((float) thisRadarItem->y);
- if( x >= 0 && x <= RADAR_SIZE_X && y >= 0 && y <= RADAR_SIZE_Y )
- {
- drawImage(g_radar,
- RADAR_LOCATION_X+1+x, RADAR_LOCATION_Y+1+y,
- 2*thisRadarItem->type, RADAR_SIZE_Y+2, 2, 2);
- }
- }
+ if (x >= 0 && x <= RADAR_SIZE_X && y >= 0 && y <= RADAR_SIZE_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()
+void
+quitRadar()
{
- destroyListItem(listRadar, destroyRadarItem);
+ destroyListItem(listRadar, destroyRadarItem);
}
diff --git a/src/client/radar.c~ b/src/client/radar.c~
new file mode 100644
index 0000000..afa48d4
--- /dev/null
+++ b/src/client/radar.c~
@@ -0,0 +1,121 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+#include "arena.h"
+
+#include "interface.h"
+#include "image.h"
+#include "radar.h"
+
+static image_t *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_NO_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 );
+
+ if( x >= 0 && x <= RADAR_SIZE_X && y >= 0 && y <= RADAR_SIZE_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/saveDialog.c b/src/client/saveDialog.c
index 37a3d8f..125d681 100644
--- a/src/client/saveDialog.c
+++ b/src/client/saveDialog.c
@@ -30,118 +30,118 @@ static widget_t *widgetTextFieldName;
static widget_t *widgetButtonSave;
static widget_t *widgetButtonBack;
-static void switchTerm()
+static void
+switchTerm()
{
- if( activeSaveDialog == TRUE )
- {
- activeSaveDialog = FALSE;
- }
- else
- {
- activeSaveDialog = TRUE;
- }
+ if (activeSaveDialog == TRUE) {
+ activeSaveDialog = FALSE;
+ }
+ else {
+ activeSaveDialog = TRUE;
+ }
}
-static void eventWidget(void *p)
+static void
+eventWidget(void *p)
{
- widget_t *button;
+ widget_t *button;
- button = (widget_t *)p;
+ button = (widget_t *) p;
- if( button == widgetButtonSave )
- {
- saveArena(getTextFromWidgetTextfield(widgetTextFieldName), getCurrentArena());
- switchTerm();
- }
+ if (button == widgetButtonSave) {
+ saveArena(getTextFromWidgetTextfield(widgetTextFieldName),
+ getCurrentArena());
+ switchTerm();
+ }
- if( button == widgetButtonBack )
- {
- switchTerm();
- }
+ if (button == widgetButtonBack) {
+ switchTerm();
+ }
}
-static void hotkey_saveDialog()
+static void
+hotkey_saveDialog()
{
- switchTerm();
+ switchTerm();
}
-void initSaveDialog()
+void
+initSaveDialog()
{
- activeSaveDialog = FALSE;
-
- g_background = getImage(IMAGE_GROUP_BASE, "screen_main");
-
- widgetLabelMsg = newWidgetLabel(
- "name",
- SAVE_DIALOG_LOCATIN_X+20,
- SAVE_DIALOG_LOCATIN_Y+20,
- WIDGET_LABEL_LEFT);
-
- widgetTextFieldName = newWidgetTextfield(
- "noname",
- WIDGET_TEXTFIELD_FILTER_ALPHANUM,
- widgetLabelMsg->x+widgetLabelMsg->w+10,
- widgetLabelMsg->y);
-
- widgetButtonSave = newWidgetButton(
- "Save",
- SAVE_DIALOG_LOCATIN_X+20,
- SAVE_DIALOG_LOCATIN_Y+60,
- eventWidget);
-
- widgetButtonBack = newWidgetButton(
- "Back",
- SAVE_DIALOG_LOCATIN_X+20+WIDGET_BUTTON_WIDTH+20,
- SAVE_DIALOG_LOCATIN_Y+60,
- eventWidget);
-
- registerHotKey(SDLK_F2, hotkey_saveDialog);
+ activeSaveDialog = FALSE;
+
+ g_background = getImage(IMAGE_GROUP_BASE, "screen_main");
+
+ widgetLabelMsg = newWidgetLabel("name",
+ SAVE_DIALOG_LOCATIN_X + 20,
+ SAVE_DIALOG_LOCATIN_Y + 20,
+ WIDGET_LABEL_LEFT);
+
+ widgetTextFieldName = newWidgetTextfield("noname",
+ WIDGET_TEXTFIELD_FILTER_ALPHANUM,
+ widgetLabelMsg->x +
+ widgetLabelMsg->w + 10,
+ widgetLabelMsg->y);
+
+ widgetButtonSave = newWidgetButton("Save",
+ SAVE_DIALOG_LOCATIN_X + 20,
+ SAVE_DIALOG_LOCATIN_Y + 60,
+ eventWidget);
+
+ widgetButtonBack = newWidgetButton("Back",
+ SAVE_DIALOG_LOCATIN_X + 20 +
+ WIDGET_BUTTON_WIDTH + 20,
+ SAVE_DIALOG_LOCATIN_Y + 60,
+ eventWidget);
+
+ registerHotKey(SDLK_F2, hotkey_saveDialog);
}
-bool_t isSaveDialogActive()
+bool_t
+isSaveDialogActive()
{
- return activeSaveDialog;
+ return activeSaveDialog;
}
-void drawSaveDialog()
+void
+drawSaveDialog()
{
- if( activeSaveDialog == FALSE )
- {
- return;
- }
-
- drawImage(g_background,
- SAVE_DIALOG_LOCATIN_X,
- SAVE_DIALOG_LOCATIN_Y,
- SAVE_DIALOG_LOCATIN_X,
- SAVE_DIALOG_LOCATIN_Y,
- SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y);
-
- drawWidgetLabel(widgetLabelMsg);
- drawWidgetTextfield(widgetTextFieldName);
- drawWidgetButton(widgetButtonSave);
- drawWidgetButton(widgetButtonBack);
+ if (activeSaveDialog == FALSE) {
+ return;
+ }
+
+ drawImage(g_background,
+ SAVE_DIALOG_LOCATIN_X,
+ SAVE_DIALOG_LOCATIN_Y,
+ SAVE_DIALOG_LOCATIN_X,
+ SAVE_DIALOG_LOCATIN_Y, SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y);
+
+ drawWidgetLabel(widgetLabelMsg);
+ drawWidgetTextfield(widgetTextFieldName);
+ drawWidgetButton(widgetButtonSave);
+ drawWidgetButton(widgetButtonBack);
}
-void eventSaveDialog()
+void
+eventSaveDialog()
{
- if( activeSaveDialog == FALSE )
- {
- return;
- }
+ if (activeSaveDialog == FALSE) {
+ return;
+ }
- eventWidgetTextfield(widgetTextFieldName);
- eventWidgetButton(widgetButtonSave);
- eventWidgetButton(widgetButtonBack);
+ eventWidgetTextfield(widgetTextFieldName);
+ eventWidgetButton(widgetButtonSave);
+ eventWidgetButton(widgetButtonBack);
}
-void quitSaveDialog()
+void
+quitSaveDialog()
{
- unregisterHotKey(SDLK_F2);
+ unregisterHotKey(SDLK_F2);
- destroyWidgetLabel(widgetLabelMsg);
- destroyWidgetTextfield(widgetTextFieldName);
- destroyWidgetButton(widgetButtonSave);
- destroyWidgetButton(widgetButtonBack);
+ destroyWidgetLabel(widgetLabelMsg);
+ destroyWidgetTextfield(widgetTextFieldName);
+ destroyWidgetButton(widgetButtonSave);
+ destroyWidgetButton(widgetButtonBack);
}
diff --git a/src/client/saveDialog.c~ b/src/client/saveDialog.c~
new file mode 100644
index 0000000..37a3d8f
--- /dev/null
+++ b/src/client/saveDialog.c~
@@ -0,0 +1,147 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+#include "space.h"
+#include "arena.h"
+#include "net_multiplayer.h"
+
+#include "interface.h"
+#include "saveDialog.h"
+#include "image.h"
+#include "font.h"
+#include "saveLoad.h"
+#include "hotKey.h"
+
+#include "widget.h"
+#include "widget_label.h"
+#include "widget_button.h"
+#include "widget_textfield.h"
+
+static image_t *g_background;
+static bool_t activeSaveDialog;
+
+static widget_t *widgetLabelMsg;
+static widget_t *widgetTextFieldName;
+
+static widget_t *widgetButtonSave;
+static widget_t *widgetButtonBack;
+
+static void switchTerm()
+{
+ if( activeSaveDialog == TRUE )
+ {
+ activeSaveDialog = FALSE;
+ }
+ else
+ {
+ activeSaveDialog = TRUE;
+ }
+}
+
+static void eventWidget(void *p)
+{
+ widget_t *button;
+
+ button = (widget_t *)p;
+
+ if( button == widgetButtonSave )
+ {
+ saveArena(getTextFromWidgetTextfield(widgetTextFieldName), getCurrentArena());
+ switchTerm();
+ }
+
+ if( button == widgetButtonBack )
+ {
+ switchTerm();
+ }
+}
+
+static void hotkey_saveDialog()
+{
+ switchTerm();
+}
+
+void initSaveDialog()
+{
+ activeSaveDialog = FALSE;
+
+ g_background = getImage(IMAGE_GROUP_BASE, "screen_main");
+
+ widgetLabelMsg = newWidgetLabel(
+ "name",
+ SAVE_DIALOG_LOCATIN_X+20,
+ SAVE_DIALOG_LOCATIN_Y+20,
+ WIDGET_LABEL_LEFT);
+
+ widgetTextFieldName = newWidgetTextfield(
+ "noname",
+ WIDGET_TEXTFIELD_FILTER_ALPHANUM,
+ widgetLabelMsg->x+widgetLabelMsg->w+10,
+ widgetLabelMsg->y);
+
+ widgetButtonSave = newWidgetButton(
+ "Save",
+ SAVE_DIALOG_LOCATIN_X+20,
+ SAVE_DIALOG_LOCATIN_Y+60,
+ eventWidget);
+
+ widgetButtonBack = newWidgetButton(
+ "Back",
+ SAVE_DIALOG_LOCATIN_X+20+WIDGET_BUTTON_WIDTH+20,
+ SAVE_DIALOG_LOCATIN_Y+60,
+ eventWidget);
+
+ registerHotKey(SDLK_F2, hotkey_saveDialog);
+}
+
+bool_t isSaveDialogActive()
+{
+ return activeSaveDialog;
+}
+
+void drawSaveDialog()
+{
+ if( activeSaveDialog == FALSE )
+ {
+ return;
+ }
+
+ drawImage(g_background,
+ SAVE_DIALOG_LOCATIN_X,
+ SAVE_DIALOG_LOCATIN_Y,
+ SAVE_DIALOG_LOCATIN_X,
+ SAVE_DIALOG_LOCATIN_Y,
+ SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y);
+
+ drawWidgetLabel(widgetLabelMsg);
+ drawWidgetTextfield(widgetTextFieldName);
+ drawWidgetButton(widgetButtonSave);
+ drawWidgetButton(widgetButtonBack);
+}
+
+void eventSaveDialog()
+{
+ if( activeSaveDialog == FALSE )
+ {
+ return;
+ }
+
+ eventWidgetTextfield(widgetTextFieldName);
+ eventWidgetButton(widgetButtonSave);
+ eventWidgetButton(widgetButtonBack);
+
+}
+
+void quitSaveDialog()
+{
+ unregisterHotKey(SDLK_F2);
+
+ destroyWidgetLabel(widgetLabelMsg);
+ destroyWidgetTextfield(widgetTextFieldName);
+ destroyWidgetButton(widgetButtonSave);
+ destroyWidgetButton(widgetButtonBack);
+}
diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c
index be7933b..5b5a4b7 100644
--- a/src/client/saveLoad.c
+++ b/src/client/saveLoad.c
@@ -19,252 +19,254 @@
#include "screen_choiceArena.h"
#include "screen_world.h"
-static void action_saveTux(space_t *space, tux_t *tux, textFile_t *textFile)
+static void
+action_saveTux(space_t * space, tux_t * tux, textFile_t * textFile)
{
- char str[STR_PROTO_SIZE];
-
- snprintf(str, STR_PROTO_SIZE,
- "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
- tux->id, tux->x, tux->y, tux->status, tux->position ,tux->control, tux->frame, tux->score, tux->name,
- tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE],
- tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER],
- tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL],
- tux->bonus_time, tux->pickup_time);
-
- addList(textFile->text, strdup(str));
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE,
+ "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ tux->id, tux->x, tux->y, tux->status, tux->position, tux->control,
+ tux->frame, tux->score, tux->name, tux->gun, tux->bonus,
+ tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE],
+ tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY],
+ tux->shot[GUN_LASSER], tux->shot[GUN_MINE],
+ tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time);
+
+ addList(textFile->text, strdup(str));
}
-static void action_saveShot(space_t *space, shot_t *shot, textFile_t *textFile)
+static void
+action_saveShot(space_t * space, shot_t * shot, textFile_t * textFile)
{
- char str[STR_PROTO_SIZE];
+ char str[STR_PROTO_SIZE];
- snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d",
- shot->id, shot->x, shot->y, shot->px, shot->py,
- shot->position, shot->gun, shot->author_id, shot->isCanKillAuthor);
+ snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d",
+ shot->id, shot->x, shot->y, shot->px, shot->py,
+ shot->position, shot->gun, shot->author_id,
+ shot->isCanKillAuthor);
- addList(textFile->text, strdup(str));
+ addList(textFile->text, strdup(str));
}
-static void action_saveItem(space_t *space, item_t *item, textFile_t *textFile)
+static void
+action_saveItem(space_t * space, item_t * item, textFile_t * textFile)
{
- char str[STR_PROTO_SIZE];
+ char str[STR_PROTO_SIZE];
- snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d",
- item->id, item->type, item->x, item->y,
- item->count, item->frame, item->author_id);
+ snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d",
+ item->id, item->type, item->x, item->y,
+ item->count, item->frame, item->author_id);
- addList(textFile->text, strdup(str));
+ addList(textFile->text, strdup(str));
}
-static void saveContextArenaToTextFile(textFile_t *textFile, arena_t *arena)
+static void
+saveContextArenaToTextFile(textFile_t * textFile, arena_t * arena)
{
- char str[STR_PROTO_SIZE];
+ char str[STR_PROTO_SIZE];
- sprintf(str, "ARENA %s %d %d",
- getArenaNetName(getChoiceArena()),
- arena->countRound,
- arena->max_countRound);
+ sprintf(str, "ARENA %s %d %d",
+ getArenaNetName(getChoiceArena()),
+ arena->countRound, arena->max_countRound);
- addList(textFile->text, strdup(str));
+ addList(textFile->text, strdup(str));
- actionSpace(arena->spaceTux, action_saveTux, textFile);
- actionSpace(arena->spaceShot, action_saveShot, textFile);
- actionSpace(arena->spaceItem, action_saveItem, textFile);
+ actionSpace(arena->spaceTux, action_saveTux, textFile);
+ actionSpace(arena->spaceShot, action_saveShot, textFile);
+ actionSpace(arena->spaceItem, action_saveItem, textFile);
}
-void saveArena(char *filename, arena_t *arena)
+void
+saveArena(char *filename, arena_t * arena)
{
- textFile_t *textFile;
- char path[STR_PATH_SIZE];
+ textFile_t *textFile;
+ char path[STR_PATH_SIZE];
- sprintf(path, "%s/%s.sav", getHomeDirector(), filename);
+ sprintf(path, "%s/%s.sav", getHomeDirector(), filename);
#ifdef DEBUG
- printf(_("Saving game to: \"%s\"\n"), path);
+ printf(_("Saving game to: \"%s\"\n"), path);
#endif
- textFile = newTextFile(path);
-
- if( textFile != NULL )
- {
- saveContextArenaToTextFile(textFile, arena);
- saveTextFile(textFile);
- destroyTextFile(textFile);
- }
- else
- {
- fprintf(stderr, _("I was unable to save: \"%s\"\n"), path);
- }
+ textFile = newTextFile(path);
+
+ if (textFile != NULL) {
+ saveContextArenaToTextFile(textFile, arena);
+ saveTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+ else {
+ fprintf(stderr, _("I was unable to save: \"%s\"\n"), path);
+ }
}
-static arena_t* loadArenaFromLine(char *line)
+static arena_t *
+loadArenaFromLine(char *line)
{
- char cmd[STR_SIZE];
- char name[STR_SIZE];
- int countRound;
- int max_countRound;
- arena_t *arena;
+ char cmd[STR_SIZE];
+ char name[STR_SIZE];
+ int countRound;
+ int max_countRound;
+ arena_t *arena;
- sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound);
+ sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound);
- setWorldArena( getArenaFileFormNetName(name) );
+ setWorldArena(getArenaFileFormNetName(name));
- arena = getCurrentArena();
- arena->max_countRound = max_countRound;
- arena->countRound = countRound;
+ arena = getCurrentArena();
+ arena->max_countRound = max_countRound;
+ arena->countRound = countRound;
- return arena;
+ return arena;
}
-static void loadTuxFromLine(char *line, arena_t *arena)
+static void
+loadTuxFromLine(char *line, arena_t * arena)
{
- char cmd[STR_PROTO_SIZE];
- char name[STR_NAME_SIZE];
- int id, x, y, status, position, frame, score, control;
- int myGun, myBonus;
- int gun1, gun2, gun3, gun4, gun5, gun6, gun7;
- int time1, time2;
- tux_t *tux;
-
- sscanf(line, "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
- cmd, &id, &x, &y, &status, &position, &control, &frame, &score, name,
- &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2);
-
- tux = newTux();
- replaceTuxID(tux, id);
- addObjectToSpace(arena->spaceTux, tux);
-
- tux->control = control;
-
- if( tux->control == TUX_CONTROL_KEYBOARD_RIGHT )
- {
- setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT);
- }
-
- if( tux->control == TUX_CONTROL_KEYBOARD_LEFT )
- {
- setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
- }
-
- if( tux->control == TUX_CONTROL_AI )
- {
- loadModule("libmodAI");
- setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
- }
-
- moveObjectInSpace(arena->spaceTux, tux, x, y);
- tux->status = status;
- tux->position = position;
- tux->frame = frame;
- tux->score = score;
- strcpy(tux->name, name);
- tux->gun = myGun;
- tux->bonus = myBonus;
- tux->shot[GUN_SIMPLE] = gun1;
- tux->shot[GUN_DUAL_SIMPLE] = gun2;
- tux->shot[GUN_SCATTER] = gun3;
- tux->shot[GUN_TOMMY] = gun4;
- tux->shot[GUN_LASSER] = gun5;
- tux->shot[GUN_MINE] = gun6;
- tux->shot[GUN_BOMBBALL] = gun7;
- tux->bonus_time = time1;
- tux->pickup_time = time2;
+ char cmd[STR_PROTO_SIZE];
+ char name[STR_NAME_SIZE];
+ int id, x, y, status, position, frame, score, control;
+ int myGun, myBonus;
+ int gun1, gun2, gun3, gun4, gun5, gun6, gun7;
+ int time1, time2;
+ tux_t *tux;
+
+ sscanf(line,
+ "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ cmd, &id, &x, &y, &status, &position, &control, &frame, &score,
+ name, &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6,
+ &gun7, &time1, &time2);
+
+ tux = newTux();
+ replaceTuxID(tux, id);
+ addObjectToSpace(arena->spaceTux, tux);
+
+ tux->control = control;
+
+ if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT) {
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT);
+ }
+
+ if (tux->control == TUX_CONTROL_KEYBOARD_LEFT) {
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
+ }
+
+ if (tux->control == TUX_CONTROL_AI) {
+ loadModule("libmodAI");
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
+ }
+
+ moveObjectInSpace(arena->spaceTux, tux, x, y);
+ tux->status = status;
+ tux->position = position;
+ tux->frame = frame;
+ tux->score = score;
+ strcpy(tux->name, name);
+ tux->gun = myGun;
+ tux->bonus = myBonus;
+ tux->shot[GUN_SIMPLE] = gun1;
+ tux->shot[GUN_DUAL_SIMPLE] = gun2;
+ tux->shot[GUN_SCATTER] = gun3;
+ tux->shot[GUN_TOMMY] = gun4;
+ tux->shot[GUN_LASSER] = gun5;
+ tux->shot[GUN_MINE] = gun6;
+ tux->shot[GUN_BOMBBALL] = gun7;
+ tux->bonus_time = time1;
+ tux->pickup_time = time2;
}
-static void loadShotFromLine(char *line, arena_t *arena)
+static void
+loadShotFromLine(char *line, arena_t * arena)
{
- char cmd[STR_PROTO_SIZE];
- int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor;
- shot_t *shot;
+ char cmd[STR_PROTO_SIZE];
+ int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor;
+ shot_t *shot;
- sscanf(line, "%s %d %d %d %d %d %d %d %d %d",
- cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, &isCanKillAuthor);
+ sscanf(line, "%s %d %d %d %d %d %d %d %d %d",
+ cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id,
+ &isCanKillAuthor);
- shot = newShot(x, y, px, py, gun, author_id);
+ shot = newShot(x, y, px, py, gun, author_id);
- replaceShotID(shot, shot_id);
- shot->isCanKillAuthor = isCanKillAuthor;
- shot->position = position;
+ replaceShotID(shot, shot_id);
+ shot->isCanKillAuthor = isCanKillAuthor;
+ shot->position = position;
- if( shot->gun == GUN_LASSER )
- {
- transformOnlyLasser(shot);
- }
+ if (shot->gun == GUN_LASSER) {
+ transformOnlyLasser(shot);
+ }
- addObjectToSpace(arena->spaceShot, shot);
+ addObjectToSpace(arena->spaceShot, shot);
}
-static void loadItemFromLine(char *line, arena_t *arena)
+static void
+loadItemFromLine(char *line, arena_t * arena)
{
- char cmd[STR_PROTO_SIZE];
- int id, type, x, y, count, frame, author_id, check_id;
- item_t *item;
+ char cmd[STR_PROTO_SIZE];
+ int id, type, x, y, count, frame, author_id, check_id;
+ item_t *item;
- sscanf(line, "%s %d %d %d %d %d %d %d %d",
- cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id);
+ sscanf(line, "%s %d %d %d %d %d %d %d %d",
+ cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id);
- item = newItem(x, y, type, author_id);
+ item = newItem(x, y, type, author_id);
- replaceItemID(item, id);
- item->count = count;
- item->frame = frame;
+ replaceItemID(item, id);
+ item->count = count;
+ item->frame = frame;
- addObjectToSpace(arena->spaceItem, item);
+ addObjectToSpace(arena->spaceItem, item);
}
-static arena_t* loadContextArenaFromTextFile(textFile_t *textFile)
+static arena_t *
+loadContextArenaFromTextFile(textFile_t * textFile)
{
- arena_t *arena;
- int i;
-
- arena = NULL;
-
- for( i = 0 ; i < textFile->text->count ; i++ )
- {
- char *line;
-
- line = (char *)textFile->text->list[i];
-
- if( strncmp(line, "ARENA", 5) == 0 )
- {
- arena = loadArenaFromLine(line);
- }
-
- if( strncmp(line, "TUX", 3) == 0 )
- {
- loadTuxFromLine(line, arena);
- }
-
- if( strncmp(line, "SHOT", 4) == 0 )
- {
- loadShotFromLine(line, arena);
- }
-
- if( strncmp(line, "ITEM", 4) == 0 )
- {
- loadItemFromLine(line, arena);
- }
- }
-
- return arena;
+ arena_t *arena;
+ int i;
+
+ arena = NULL;
+
+ for (i = 0; i < textFile->text->count; i++) {
+ char *line;
+
+ line = (char *) textFile->text->list[i];
+
+ if (strncmp(line, "ARENA", 5) == 0) {
+ arena = loadArenaFromLine(line);
+ }
+
+ if (strncmp(line, "TUX", 3) == 0) {
+ loadTuxFromLine(line, arena);
+ }
+
+ if (strncmp(line, "SHOT", 4) == 0) {
+ loadShotFromLine(line, arena);
+ }
+
+ if (strncmp(line, "ITEM", 4) == 0) {
+ loadItemFromLine(line, arena);
+ }
+ }
+
+ return arena;
}
-void loadArena(char *filename)
+void
+loadArena(char *filename)
{
- textFile_t *textFile;
- char path[STR_PATH_SIZE];
+ textFile_t *textFile;
+ char path[STR_PATH_SIZE];
- sprintf(path, "%s/%s", getHomeDirector(), filename);
+ sprintf(path, "%s/%s", getHomeDirector(), filename);
#ifdef DEBUG
- printf(_("Loadig game from file: \"%s\"\n"), path);
+ printf(_("Loadig game from file: \"%s\"\n"), path);
#endif
- textFile = loadTextFile(path);
-
- if( textFile != NULL )
- {
- loadContextArenaFromTextFile(textFile);
- destroyTextFile(textFile);
- }
- else
- {
- fprintf(stderr, _("Unable to load save: \"%s\"\n"), path);
- }
+ textFile = loadTextFile(path);
+
+ if (textFile != NULL) {
+ loadContextArenaFromTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+ else {
+ fprintf(stderr, _("Unable to load save: \"%s\"\n"), path);
+ }
}
diff --git a/src/client/saveLoad.c~ b/src/client/saveLoad.c~
new file mode 100644
index 0000000..be7933b
--- /dev/null
+++ b/src/client/saveLoad.c~
@@ -0,0 +1,270 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "textFile.h"
+#include "homeDirector.h"
+
+#include "arena.h"
+#include "arenaFile.h"
+#include "tux.h"
+#include "shot.h"
+#include "item.h"
+#include "modules.h"
+
+#include "saveLoad.h"
+
+#include "screen_choiceArena.h"
+#include "screen_world.h"
+
+static void action_saveTux(space_t *space, tux_t *tux, textFile_t *textFile)
+{
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE,
+ "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ tux->id, tux->x, tux->y, tux->status, tux->position ,tux->control, tux->frame, tux->score, tux->name,
+ tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE],
+ tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER],
+ tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL],
+ tux->bonus_time, tux->pickup_time);
+
+ addList(textFile->text, strdup(str));
+}
+
+static void action_saveShot(space_t *space, shot_t *shot, textFile_t *textFile)
+{
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d",
+ shot->id, shot->x, shot->y, shot->px, shot->py,
+ shot->position, shot->gun, shot->author_id, shot->isCanKillAuthor);
+
+ addList(textFile->text, strdup(str));
+}
+
+static void action_saveItem(space_t *space, item_t *item, textFile_t *textFile)
+{
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d",
+ item->id, item->type, item->x, item->y,
+ item->count, item->frame, item->author_id);
+
+ addList(textFile->text, strdup(str));
+}
+
+static void saveContextArenaToTextFile(textFile_t *textFile, arena_t *arena)
+{
+ char str[STR_PROTO_SIZE];
+
+ sprintf(str, "ARENA %s %d %d",
+ getArenaNetName(getChoiceArena()),
+ arena->countRound,
+ arena->max_countRound);
+
+ addList(textFile->text, strdup(str));
+
+ actionSpace(arena->spaceTux, action_saveTux, textFile);
+ actionSpace(arena->spaceShot, action_saveShot, textFile);
+ actionSpace(arena->spaceItem, action_saveItem, textFile);
+}
+
+void saveArena(char *filename, arena_t *arena)
+{
+ textFile_t *textFile;
+ char path[STR_PATH_SIZE];
+
+ sprintf(path, "%s/%s.sav", getHomeDirector(), filename);
+#ifdef DEBUG
+ printf(_("Saving game to: \"%s\"\n"), path);
+#endif
+ textFile = newTextFile(path);
+
+ if( textFile != NULL )
+ {
+ saveContextArenaToTextFile(textFile, arena);
+ saveTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+ else
+ {
+ fprintf(stderr, _("I was unable to save: \"%s\"\n"), path);
+ }
+}
+
+static arena_t* loadArenaFromLine(char *line)
+{
+ char cmd[STR_SIZE];
+ char name[STR_SIZE];
+ int countRound;
+ int max_countRound;
+ arena_t *arena;
+
+ sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound);
+
+ setWorldArena( getArenaFileFormNetName(name) );
+
+ arena = getCurrentArena();
+ arena->max_countRound = max_countRound;
+ arena->countRound = countRound;
+
+ return arena;
+}
+
+static void loadTuxFromLine(char *line, arena_t *arena)
+{
+ char cmd[STR_PROTO_SIZE];
+ char name[STR_NAME_SIZE];
+ int id, x, y, status, position, frame, score, control;
+ int myGun, myBonus;
+ int gun1, gun2, gun3, gun4, gun5, gun6, gun7;
+ int time1, time2;
+ tux_t *tux;
+
+ sscanf(line, "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ cmd, &id, &x, &y, &status, &position, &control, &frame, &score, name,
+ &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2);
+
+ tux = newTux();
+ replaceTuxID(tux, id);
+ addObjectToSpace(arena->spaceTux, tux);
+
+ tux->control = control;
+
+ if( tux->control == TUX_CONTROL_KEYBOARD_RIGHT )
+ {
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT);
+ }
+
+ if( tux->control == TUX_CONTROL_KEYBOARD_LEFT )
+ {
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
+ }
+
+ if( tux->control == TUX_CONTROL_AI )
+ {
+ loadModule("libmodAI");
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
+ }
+
+ moveObjectInSpace(arena->spaceTux, tux, x, y);
+ tux->status = status;
+ tux->position = position;
+ tux->frame = frame;
+ tux->score = score;
+ strcpy(tux->name, name);
+ tux->gun = myGun;
+ tux->bonus = myBonus;
+ tux->shot[GUN_SIMPLE] = gun1;
+ tux->shot[GUN_DUAL_SIMPLE] = gun2;
+ tux->shot[GUN_SCATTER] = gun3;
+ tux->shot[GUN_TOMMY] = gun4;
+ tux->shot[GUN_LASSER] = gun5;
+ tux->shot[GUN_MINE] = gun6;
+ tux->shot[GUN_BOMBBALL] = gun7;
+ tux->bonus_time = time1;
+ tux->pickup_time = time2;
+}
+
+static void loadShotFromLine(char *line, arena_t *arena)
+{
+ char cmd[STR_PROTO_SIZE];
+ int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor;
+ shot_t *shot;
+
+ sscanf(line, "%s %d %d %d %d %d %d %d %d %d",
+ cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, &isCanKillAuthor);
+
+ shot = newShot(x, y, px, py, gun, author_id);
+
+ replaceShotID(shot, shot_id);
+ shot->isCanKillAuthor = isCanKillAuthor;
+ shot->position = position;
+
+ if( shot->gun == GUN_LASSER )
+ {
+ transformOnlyLasser(shot);
+ }
+
+ addObjectToSpace(arena->spaceShot, shot);
+}
+
+static void loadItemFromLine(char *line, arena_t *arena)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id, type, x, y, count, frame, author_id, check_id;
+ item_t *item;
+
+ sscanf(line, "%s %d %d %d %d %d %d %d %d",
+ cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id);
+
+ item = newItem(x, y, type, author_id);
+
+ replaceItemID(item, id);
+ item->count = count;
+ item->frame = frame;
+
+ addObjectToSpace(arena->spaceItem, item);
+}
+
+static arena_t* loadContextArenaFromTextFile(textFile_t *textFile)
+{
+ arena_t *arena;
+ int i;
+
+ arena = NULL;
+
+ for( i = 0 ; i < textFile->text->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)textFile->text->list[i];
+
+ if( strncmp(line, "ARENA", 5) == 0 )
+ {
+ arena = loadArenaFromLine(line);
+ }
+
+ if( strncmp(line, "TUX", 3) == 0 )
+ {
+ loadTuxFromLine(line, arena);
+ }
+
+ if( strncmp(line, "SHOT", 4) == 0 )
+ {
+ loadShotFromLine(line, arena);
+ }
+
+ if( strncmp(line, "ITEM", 4) == 0 )
+ {
+ loadItemFromLine(line, arena);
+ }
+ }
+
+ return arena;
+}
+
+void loadArena(char *filename)
+{
+ textFile_t *textFile;
+ char path[STR_PATH_SIZE];
+
+ sprintf(path, "%s/%s", getHomeDirector(), filename);
+#ifdef DEBUG
+ printf(_("Loadig game from file: \"%s\"\n"), path);
+#endif
+ textFile = loadTextFile(path);
+
+ if( textFile != NULL )
+ {
+ loadContextArenaFromTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+ else
+ {
+ fprintf(stderr, _("Unable to load save: \"%s\"\n"), path);
+ }
+}
diff --git a/src/client/screen.c b/src/client/screen.c
index db08260..903e431 100644
--- a/src/client/screen.c
+++ b/src/client/screen.c
@@ -19,175 +19,182 @@ static list_t *listScreen;
static bool_t isScreenInit = FALSE;
-bool_t isScreenInicialized()
+bool_t
+isScreenInicialized()
{
- return isScreenInit;
+ return isScreenInit;
}
-screen_t* newScreen(char *name,
- void (*fce_start)(), void (*fce_event)(),
- void (*fce_draw)(), void (*fce_stop)())
+screen_t *
+newScreen(char *name,
+ void (*fce_start) (), void (*fce_event) (),
+ void (*fce_draw) (), void (*fce_stop) ())
{
- screen_t *new;
-
- assert( name != NULL );
- assert( fce_start != NULL );
- assert( fce_event != NULL );
- assert( fce_draw != NULL );
- assert( fce_stop != NULL );
-
- new = malloc( sizeof(screen_t) );
- new->name = strdup(name);
- new->fce_start = fce_start;
- new->fce_event = fce_event;
- new->fce_draw = fce_draw;
- new->fce_stop = fce_stop;
-
- return new;
+ screen_t *new;
+
+ assert(name != NULL);
+ assert(fce_start != NULL);
+ assert(fce_event != NULL);
+ assert(fce_draw != NULL);
+ assert(fce_stop != NULL);
+
+ new = malloc(sizeof(screen_t));
+ new->name = strdup(name);
+ new->fce_start = fce_start;
+ new->fce_event = fce_event;
+ new->fce_draw = fce_draw;
+ new->fce_stop = fce_stop;
+
+ return new;
}
-void destroyScreen(screen_t *p)
+void
+destroyScreen(screen_t * p)
{
- assert( p != NULL );
+ assert(p != NULL);
- free(p->name);
- free(p);
+ free(p->name);
+ free(p);
}
-void registerScreen(screen_t *p)
+void
+registerScreen(screen_t * p)
{
- assert( p != NULL );
+ assert(p != NULL);
#ifdef DEBUG
- printf(_("Registering screen: \"%s\"\n"), p->name);
+ printf(_("Registering screen: \"%s\"\n"), p->name);
#endif
- addList(listScreen, p);
+ addList(listScreen, p);
}
-void initScreen()
+void
+initScreen()
{
- listScreen = newList();
+ listScreen = newList();
- currentScreen = NULL;
- futureScreen = NULL;
+ currentScreen = NULL;
+ futureScreen = NULL;
- isScreenInit = TRUE;
+ isScreenInit = TRUE;
}
-static screen_t* findScreen(char *name)
+static screen_t *
+findScreen(char *name)
{
- screen_t *this;
- int i;
+ screen_t *this;
+ int i;
- for( i = 0 ; i < listScreen->count ; i++ )
- {
- this = (screen_t *) (listScreen->list[i]);
- assert( this != NULL );
+ for (i = 0; i < listScreen->count; i++) {
+ this = (screen_t *) (listScreen->list[i]);
+ assert(this != NULL);
- if( strcmp(name, this->name) == 0 )
- {
- return this;
- }
- }
+ if (strcmp(name, this->name) == 0) {
+ return this;
+ }
+ }
- return NULL;
+ return NULL;
}
-void setScreen(char *name)
+void
+setScreen(char *name)
{
- futureScreen = findScreen(name);
- assert( futureScreen != NULL );
+ futureScreen = findScreen(name);
+ assert(futureScreen != NULL);
}
-void switchScreen()
+void
+switchScreen()
{
- if( futureScreen == NULL )
- {
- return;
- }
+ if (futureScreen == NULL) {
+ return;
+ }
- flushLayer();
+ flushLayer();
- if( currentScreen != NULL )
- {
+ if (currentScreen != NULL) {
#ifdef DEBUG
- printf(_("Stopping screen:\" %s\"\n"), currentScreen->name);
+ printf(_("Stopping screen:\" %s\"\n"), currentScreen->name);
#endif
- currentScreen->fce_stop();
- }
+ currentScreen->fce_stop();
+ }
- currentScreen = futureScreen;
- futureScreen = NULL;
+ currentScreen = futureScreen;
+ futureScreen = NULL;
- //printf("switch screen %s..\n", currentScreen->name);
+ //printf("switch screen %s..\n", currentScreen->name);
#ifdef DEBUG
- printf(_("Starting screen: \"%s\"\n"), currentScreen->name);
+ printf(_("Starting screen: \"%s\"\n"), currentScreen->name);
#endif
- currentScreen->fce_start();
+ currentScreen->fce_start();
}
-void startScreen(char *name)
+void
+startScreen(char *name)
{
- setScreen(name);
- switchScreen();
+ setScreen(name);
+ switchScreen();
}
-char* getScreen()
+char *
+getScreen()
{
- assert( currentScreen != NULL );
- return currentScreen->name;
+ assert(currentScreen != NULL);
+ return currentScreen->name;
}
-void drawScreen()
+void
+drawScreen()
{
- static int count = 0;
-
- count++;
-
- if( count == 1 )
- {
- count = 0;
-
- assert( currentScreen != NULL );
-
- #ifdef DEBUG_TIME_DRAW
- my_time_t prev;
-
- prev = getMyTimeMicro();
- #endif
-
- currentScreen->fce_draw();
-
- interfaceRefresh();
-
- #ifdef DEBUG_TIME_DRAW
- printf("c draw time = %d\n", getMyTimeMicro() - prev );
- #endif
- }
+ static int count = 0;
+
+ count++;
+
+ if (count == 1) {
+ count = 0;
+
+ assert(currentScreen != NULL);
+
+#ifdef DEBUG_TIME_DRAW
+ my_time_t prev;
+
+ prev = getMyTimeMicro();
+#endif
+
+ currentScreen->fce_draw();
+
+ interfaceRefresh();
+
+#ifdef DEBUG_TIME_DRAW
+ printf("c draw time = %d\n", getMyTimeMicro() - prev);
+#endif
+ }
}
-void eventScreen()
+void
+eventScreen()
{
- assert( currentScreen != NULL );
+ assert(currentScreen != NULL);
#ifdef DEBUG_TIME_EVENT
- my_time_t prev;
+ my_time_t prev;
- prev = getMyTimeMicro();
+ prev = getMyTimeMicro();
#endif
- currentScreen->fce_event();
+ currentScreen->fce_event();
#ifdef DEBUG_TIME_EVENT
- printf("c event time = %d\n", getMyTimeMicro() - prev );
+ printf("c event time = %d\n", getMyTimeMicro() - prev);
#endif
}
-void quitScreen()
+void
+quitScreen()
{
- assert( listScreen != NULL );
+ assert(listScreen != NULL);
- destroyListItem(listScreen, destroyScreen);
- isScreenInit = FALSE;
+ destroyListItem(listScreen, destroyScreen);
+ isScreenInit = FALSE;
}
-
diff --git a/src/client/screen.c~ b/src/client/screen.c~
new file mode 100644
index 0000000..db08260
--- /dev/null
+++ b/src/client/screen.c~
@@ -0,0 +1,193 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+
+#include "interface.h"
+#include "screen.h"
+#include "layer.h"
+#include "myTimer.h"
+
+//#define DEBUG_TIME_DRAW
+
+static screen_t *currentScreen;
+static screen_t *futureScreen;
+
+static list_t *listScreen;
+
+static bool_t isScreenInit = FALSE;
+
+bool_t isScreenInicialized()
+{
+ return isScreenInit;
+}
+
+screen_t* newScreen(char *name,
+ void (*fce_start)(), void (*fce_event)(),
+ void (*fce_draw)(), void (*fce_stop)())
+{
+ screen_t *new;
+
+ assert( name != NULL );
+ assert( fce_start != NULL );
+ assert( fce_event != NULL );
+ assert( fce_draw != NULL );
+ assert( fce_stop != NULL );
+
+ new = malloc( sizeof(screen_t) );
+ new->name = strdup(name);
+ new->fce_start = fce_start;
+ new->fce_event = fce_event;
+ new->fce_draw = fce_draw;
+ new->fce_stop = fce_stop;
+
+ return new;
+}
+
+void destroyScreen(screen_t *p)
+{
+ assert( p != NULL );
+
+ free(p->name);
+ free(p);
+}
+
+void registerScreen(screen_t *p)
+{
+ assert( p != NULL );
+#ifdef DEBUG
+ printf(_("Registering screen: \"%s\"\n"), p->name);
+#endif
+ addList(listScreen, p);
+}
+
+void initScreen()
+{
+ listScreen = newList();
+
+ currentScreen = NULL;
+ futureScreen = NULL;
+
+ isScreenInit = TRUE;
+}
+
+static screen_t* findScreen(char *name)
+{
+ screen_t *this;
+ int i;
+
+ for( i = 0 ; i < listScreen->count ; i++ )
+ {
+ this = (screen_t *) (listScreen->list[i]);
+ assert( this != NULL );
+
+ if( strcmp(name, this->name) == 0 )
+ {
+ return this;
+ }
+ }
+
+ return NULL;
+}
+
+void setScreen(char *name)
+{
+ futureScreen = findScreen(name);
+ assert( futureScreen != NULL );
+}
+
+void switchScreen()
+{
+ if( futureScreen == NULL )
+ {
+ return;
+ }
+
+ flushLayer();
+
+ if( currentScreen != NULL )
+ {
+#ifdef DEBUG
+ printf(_("Stopping screen:\" %s\"\n"), currentScreen->name);
+#endif
+ currentScreen->fce_stop();
+ }
+
+ currentScreen = futureScreen;
+ futureScreen = NULL;
+
+ //printf("switch screen %s..\n", currentScreen->name);
+#ifdef DEBUG
+ printf(_("Starting screen: \"%s\"\n"), currentScreen->name);
+#endif
+ currentScreen->fce_start();
+}
+
+void startScreen(char *name)
+{
+ setScreen(name);
+ switchScreen();
+}
+
+char* getScreen()
+{
+ assert( currentScreen != NULL );
+ return currentScreen->name;
+}
+
+void drawScreen()
+{
+ static int count = 0;
+
+ count++;
+
+ if( count == 1 )
+ {
+ count = 0;
+
+ assert( currentScreen != NULL );
+
+ #ifdef DEBUG_TIME_DRAW
+ my_time_t prev;
+
+ prev = getMyTimeMicro();
+ #endif
+
+ currentScreen->fce_draw();
+
+ interfaceRefresh();
+
+ #ifdef DEBUG_TIME_DRAW
+ printf("c draw time = %d\n", getMyTimeMicro() - prev );
+ #endif
+ }
+}
+
+
+void eventScreen()
+{
+ assert( currentScreen != NULL );
+
+#ifdef DEBUG_TIME_EVENT
+ my_time_t prev;
+
+ prev = getMyTimeMicro();
+#endif
+
+ currentScreen->fce_event();
+
+#ifdef DEBUG_TIME_EVENT
+ printf("c event time = %d\n", getMyTimeMicro() - prev );
+#endif
+}
+
+void quitScreen()
+{
+ assert( listScreen != NULL );
+
+ destroyListItem(listScreen, destroyScreen);
+ isScreenInit = FALSE;
+}
+
diff --git a/src/client/term.c b/src/client/term.c
index 6cad4d4..7619900 100644
--- a/src/client/term.c
+++ b/src/client/term.c
@@ -18,139 +18,151 @@ static bool_t activeTerm;
static my_time_t lastActive;
static my_time_t lastRefresh;
-void initTerm()
+void
+initTerm()
{
- listText = newList();
+ listText = newList();
- activeTerm = FALSE;
- lastActive = getMyTime();
- lastRefresh = lastActive;
+ activeTerm = FALSE;
+ lastActive = getMyTime();
+ lastRefresh = lastActive;
}
-static char* getStrGun(int gun)
+static char *
+getStrGun(int gun)
{
- switch( gun )
- {
- case GUN_SIMPLE : return "revolver";
- case GUN_DUAL_SIMPLE : return "dual revolver";
- case GUN_SCATTER : return "scatter";
- case GUN_TOMMY : return "tommy";
- case GUN_LASSER : return "lasser";
- case GUN_MINE : return "mine";
- case GUN_BOMBBALL : return "bombball";
- default : return "none";
- }
-
- return "gun_unknow";
+ switch (gun) {
+ case GUN_SIMPLE:
+ return "revolver";
+ case GUN_DUAL_SIMPLE:
+ return "dual revolver";
+ case GUN_SCATTER:
+ return "scatter";
+ case GUN_TOMMY:
+ return "tommy";
+ case GUN_LASSER:
+ return "lasser";
+ case GUN_MINE:
+ return "mine";
+ case GUN_BOMBBALL:
+ return "bombball";
+ default:
+ return "none";
+ }
+
+ return "gun_unknow";
}
-static char* getStrBonus(int bonus)
+static char *
+getStrBonus(int bonus)
{
- switch( bonus )
- {
- case BONUS_SPEED : return "speed";
- case BONUS_SHOT : return "shot";
- case BONUS_TELEPORT : return "teleport";
- case BONUS_GHOST : return "ghost";
- case BONUS_4X : return "4X";
- case BONUS_HIDDEN : return "hidden";
- default : return "none";
- }
-
- return "bonus_unknow";
+ switch (bonus) {
+ case BONUS_SPEED:
+ return "speed";
+ case BONUS_SHOT:
+ return "shot";
+ case BONUS_TELEPORT:
+ return "teleport";
+ case BONUS_GHOST:
+ return "ghost";
+ case BONUS_4X:
+ return "4X";
+ case BONUS_HIDDEN:
+ return "hidden";
+ default:
+ return "none";
+ }
+
+ return "bonus_unknow";
}
-static void action_refreshTerm(space_t *space, tux_t *tux, void *p)
+static void
+action_refreshTerm(space_t * space, tux_t * tux, void *p)
{
- char str[STR_SIZE];
-
- sprintf(str,
- "name: %s "
- "score: %d "
- "gun: %s "
- "shot: %d "
- "bonus: %s",
-
- tux->name, tux->score,
- getStrGun(tux->gun),
- tux->shot[tux->gun],
- getStrBonus(tux->bonus)
- );
-
- addList(listText, strdup(str) );
+ char str[STR_SIZE];
+
+ sprintf(str,
+ "name: %s "
+ "score: %d "
+ "gun: %s "
+ "shot: %d "
+ "bonus: %s",
+ tux->name, tux->score,
+ getStrGun(tux->gun), tux->shot[tux->gun], getStrBonus(tux->bonus)
+ );
+
+ addList(listText, strdup(str));
}
-static void refreshTerm()
+static void
+refreshTerm()
{
- arena_t *arena;
+ arena_t *arena;
- arena = getCurrentArena();
+ arena = getCurrentArena();
- destroyListItem(listText, free);
- listText = newList();
+ destroyListItem(listText, free);
+ listText = newList();
- actionSpace(arena->spaceTux, action_refreshTerm, NULL);
+ actionSpace(arena->spaceTux, action_refreshTerm, NULL);
- //printf("refresh term..\n");
+ //printf("refresh term..\n");
}
-void drawTerm()
+void
+drawTerm()
{
- int i;
+ int i;
- if( activeTerm == FALSE )
- {
- return;
- }
+ if (activeTerm == FALSE) {
+ return;
+ }
- for( i = 0 ; i < listText->count ; i++ )
- {
- char *line;
+ for (i = 0; i < listText->count; i++) {
+ char *line;
- line = (char *) listText->list[i];
- drawFont(line, 10, 10 + i*20, COLOR_WHITE);
- }
+ line = (char *) listText->list[i];
+ drawFont(line, 10, 10 + i * 20, COLOR_WHITE);
+ }
}
-static void switchTerm()
+static void
+switchTerm()
{
- if( activeTerm == TRUE )
- {
- activeTerm = FALSE;
- }
- else
- {
- activeTerm = TRUE;
- }
+ if (activeTerm == TRUE) {
+ activeTerm = FALSE;
+ }
+ else {
+ activeTerm = TRUE;
+ }
}
-void eventTerm()
+void
+eventTerm()
{
- my_time_t currentTime;
- Uint8 *mapa;
-
- mapa = SDL_GetKeyState(NULL);
-
- currentTime = getMyTime();
-
- if( currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL )
- {
- lastRefresh = currentTime;
- refreshTerm();
- }
-
- if( mapa[SDLK_TAB] == SDL_PRESSED )
- {
- if( currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL )
- {
- lastActive = currentTime;
- switchTerm();
- }
- }
+ my_time_t currentTime;
+ Uint8 *mapa;
+
+ mapa = SDL_GetKeyState(NULL);
+
+ currentTime = getMyTime();
+
+ if (currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL) {
+ lastRefresh = currentTime;
+ refreshTerm();
+ }
+
+ if (mapa[SDLK_TAB] == SDL_PRESSED) {
+ if (currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL) {
+ lastActive = currentTime;
+ switchTerm();
+ }
+ }
}
-void quitTerm()
+void
+quitTerm()
{
- assert( listText != NULL );
- destroyListItem(listText, free);
+ assert(listText != NULL);
+ destroyListItem(listText, free);
}
diff --git a/src/client/term.c~ b/src/client/term.c~
new file mode 100644
index 0000000..6cad4d4
--- /dev/null
+++ b/src/client/term.c~
@@ -0,0 +1,156 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "myTimer.h"
+#include "tux.h"
+#include "space.h"
+#include "arena.h"
+
+#include "interface.h"
+#include "term.h"
+#include "font.h"
+
+static list_t *listText;
+static bool_t activeTerm;
+static my_time_t lastActive;
+static my_time_t lastRefresh;
+
+void initTerm()
+{
+ listText = newList();
+
+ activeTerm = FALSE;
+ lastActive = getMyTime();
+ lastRefresh = lastActive;
+}
+
+static char* getStrGun(int gun)
+{
+ switch( gun )
+ {
+ case GUN_SIMPLE : return "revolver";
+ case GUN_DUAL_SIMPLE : return "dual revolver";
+ case GUN_SCATTER : return "scatter";
+ case GUN_TOMMY : return "tommy";
+ case GUN_LASSER : return "lasser";
+ case GUN_MINE : return "mine";
+ case GUN_BOMBBALL : return "bombball";
+ default : return "none";
+ }
+
+ return "gun_unknow";
+}
+
+static char* getStrBonus(int bonus)
+{
+ switch( bonus )
+ {
+ case BONUS_SPEED : return "speed";
+ case BONUS_SHOT : return "shot";
+ case BONUS_TELEPORT : return "teleport";
+ case BONUS_GHOST : return "ghost";
+ case BONUS_4X : return "4X";
+ case BONUS_HIDDEN : return "hidden";
+ default : return "none";
+ }
+
+ return "bonus_unknow";
+}
+
+static void action_refreshTerm(space_t *space, tux_t *tux, void *p)
+{
+ char str[STR_SIZE];
+
+ sprintf(str,
+ "name: %s "
+ "score: %d "
+ "gun: %s "
+ "shot: %d "
+ "bonus: %s",
+
+ tux->name, tux->score,
+ getStrGun(tux->gun),
+ tux->shot[tux->gun],
+ getStrBonus(tux->bonus)
+ );
+
+ addList(listText, strdup(str) );
+}
+
+static void refreshTerm()
+{
+ arena_t *arena;
+
+ arena = getCurrentArena();
+
+ destroyListItem(listText, free);
+ listText = newList();
+
+ actionSpace(arena->spaceTux, action_refreshTerm, NULL);
+
+ //printf("refresh term..\n");
+}
+
+void drawTerm()
+{
+ int i;
+
+ if( activeTerm == FALSE )
+ {
+ return;
+ }
+
+ for( i = 0 ; i < listText->count ; i++ )
+ {
+ char *line;
+
+ line = (char *) listText->list[i];
+ drawFont(line, 10, 10 + i*20, COLOR_WHITE);
+ }
+}
+
+static void switchTerm()
+{
+ if( activeTerm == TRUE )
+ {
+ activeTerm = FALSE;
+ }
+ else
+ {
+ activeTerm = TRUE;
+ }
+}
+
+void eventTerm()
+{
+ my_time_t currentTime;
+ Uint8 *mapa;
+
+ mapa = SDL_GetKeyState(NULL);
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL )
+ {
+ lastRefresh = currentTime;
+ refreshTerm();
+ }
+
+ if( mapa[SDLK_TAB] == SDL_PRESSED )
+ {
+ if( currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL )
+ {
+ lastActive = currentTime;
+ switchTerm();
+ }
+ }
+}
+
+void quitTerm()
+{
+ assert( listText != NULL );
+ destroyListItem(listText, free);
+}