diff --git a/src/interpreter.c b/src/interpreter.c index be0cabf..b2f7c4f 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -4,6 +4,7 @@ #include "interpreter.h" #include "networking.h" +#include "main.h" #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); #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 g_slist_foreach(command_parts, (GFunc)destroy_string, NULL); g_slist_free(command_parts); @@ -131,13 +132,27 @@ 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); - } - else - { - wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n"); + 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; + } + 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"); } g_slist_free(matches); diff --git a/src/main.c b/src/main.c index f63247b..a111336 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,7 @@ struct { GMainContext *game_context; guint32 elapsed_seconds = 0; guint32 elapsed_cycle = 0; +GRand *main_rand = NULL; gboolean rl_sec_elapsed(gpointer user_data) @@ -61,6 +62,8 @@ main(int argc, char **argv) g_print("Starting up...\n"); + main_rand = g_rand_new(); + game_context = g_main_context_new(); game_loop = g_main_loop_new(game_context, FALSE); diff --git a/src/main.h b/src/main.h index fd4e7f0..6ef7a50 100644 --- a/src/main.h +++ b/src/main.h @@ -5,6 +5,9 @@ extern GMainContext *game_context; 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__ */