Added a randomized response on unknown commands.

Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely Polonkai (W00d5t0ck) 2012-03-14 20:19:05 +01:00
parent c715d19b2d
commit b29f7c9063
3 changed files with 28 additions and 7 deletions

View File

@ -4,6 +4,7 @@
#include "interpreter.h" #include "interpreter.h"
#include "networking.h" #include "networking.h"
#include "main.h"
#define IS_SPACE(c) (g_ascii_isspace((c)) || (!(c))) #define IS_SPACE(c) (g_ascii_isspace((c)) || (!(c)))
@ -95,7 +96,7 @@ wmud_interpret_game_command(wmudClient *client)
{ {
wmud_client_send(client, "You should close quotes of any kind, like %c, shouldn't you?\r\n", str_delim); wmud_client_send(client, "You should close quotes of any kind, like %c, shouldn't you?\r\n", str_delim);
#if GLIB_CHECK_VERSION(2, 28, 0) #if GLIB_CHECK_VERSION(2, 28, 0)
g_slist_free_full(command_parts, destroy_string); g_slist_free_full(command_parts, (GDestroyNotify)destroy_string);
#else #else
g_slist_foreach(command_parts, (GFunc)destroy_string, NULL); g_slist_foreach(command_parts, (GFunc)destroy_string, NULL);
g_slist_free(command_parts); g_slist_free(command_parts);
@ -131,12 +132,26 @@ wmud_interpret_game_command(wmudClient *client)
} }
} }
if (match_count == 1) switch (match_count)
{ {
((wmudCommand *)(matches->data))->commandFunc(client, ((GString *)(command_parts->data))->str, command_parts->next); case 0:
switch (random_number(1, 3))
{
case 1:
wmud_client_send(client, "Huh?\r\n");
break;
case 2:
wmud_client_send(client, "What?\r\n");
break;
case 3:
wmud_client_send(client, "I can hardly understand you...\r\n");
break;
} }
else break;
{ case 1:
((wmudCommand *)(matches->data))->commandFunc(client, ((GString *)(command_parts->data))->str, command_parts->next);
break;
default:
wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n"); wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n");
} }

View File

@ -18,6 +18,7 @@ struct {
GMainContext *game_context; GMainContext *game_context;
guint32 elapsed_seconds = 0; guint32 elapsed_seconds = 0;
guint32 elapsed_cycle = 0; guint32 elapsed_cycle = 0;
GRand *main_rand = NULL;
gboolean gboolean
rl_sec_elapsed(gpointer user_data) rl_sec_elapsed(gpointer user_data)
@ -61,6 +62,8 @@ main(int argc, char **argv)
g_print("Starting up...\n"); g_print("Starting up...\n");
main_rand = g_rand_new();
game_context = g_main_context_new(); game_context = g_main_context_new();
game_loop = g_main_loop_new(game_context, FALSE); game_loop = g_main_loop_new(game_context, FALSE);

View File

@ -5,6 +5,9 @@
extern GMainContext *game_context; extern GMainContext *game_context;
extern guint32 elapsed_seconds; extern guint32 elapsed_seconds;
extern GRand *main_rand;
#define random_number(a, b) g_rand_int_range(main_rand, (a), (b) + 1)
#endif /* __WMUD_MAIN_H__ */ #endif /* __WMUD_MAIN_H__ */