diff options
author | xazax-hun <xazax-hun@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-07-24 09:18:04 +0000 |
---|---|---|
committer | xazax-hun <xazax-hun@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-07-24 09:18:04 +0000 |
commit | 0158bf00e1ee3ba27878dff9ad2af488055bcd24 (patch) | |
tree | 9233a5405ad889cc881b8cbab3300e21187226b2 /src/map | |
parent | bd2b6f5c05c7fdd3506d0bc298ec3db699f679ef (diff) | |
download | hercules-0158bf00e1ee3ba27878dff9ad2af488055bcd24.tar.gz hercules-0158bf00e1ee3ba27878dff9ad2af488055bcd24.tar.bz2 hercules-0158bf00e1ee3ba27878dff9ad2af488055bcd24.tar.xz hercules-0158bf00e1ee3ba27878dff9ad2af488055bcd24.zip |
Refinements to atcommand suggestions.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16489 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index ab2fadae2..9fe68da08 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8917,66 +8917,61 @@ static void atcommand_get_suggestions(struct map_session_data* sd, const char *n DBIterator* alias_iter; AtCommandInfo* command_info = NULL; AliasInfo* alias_info = NULL; - AtCommandType type; + AtCommandType type = atcommand ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND; + char* full_match[MAX_SUGGESTIONS]; char* suggestions[MAX_SUGGESTIONS]; - int count = 0; - + char* match; + int prefix_count = 0, full_count = 0; + bool can_use; + if (!battle_config.atcommand_suggestions_enabled) return; atcommand_iter = db_iterator(atcommand_db); - alias_iter = db_iterator(atcommand_alias_db); + alias_iter = db_iterator(atcommand_alias_db); - if (atcommand) - type = COMMAND_ATCOMMAND; - else - type = COMMAND_CHARCOMMAND; - - - // First match the beginnings of the commands - for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter) && count < MAX_SUGGESTIONS; command_info = dbi_next(atcommand_iter)) { - if ( strstr(command_info->command, name) == command_info->command && pc_can_use_command(sd, command_info->command, type) ) - { - suggestions[count] = command_info->command; - ++count; + // Build the matches + for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter); command_info = dbi_next(atcommand_iter)) { + match = strstr(command_info->command, name); + can_use = pc_can_use_command(sd, command_info->command, type); + if ( prefix_count < MAX_SUGGESTIONS && match == command_info->command && can_use ) { + suggestions[prefix_count] = command_info->command; + ++prefix_count; } - } - - for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter) && count < MAX_SUGGESTIONS; alias_info = dbi_next(alias_iter)) { - if ( strstr(alias_info->alias, name) == alias_info->alias && pc_can_use_command(sd, alias_info->command->command, type) ) - { - suggestions[count] = alias_info->alias; - ++count; + if ( full_count < MAX_SUGGESTIONS && match != NULL && match != command_info->command && can_use ) { + full_match[full_count] = command_info->command; + ++full_count; } } - // Fill up the space left, with full matches - for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter) && count < MAX_SUGGESTIONS; command_info = dbi_next(atcommand_iter)) { - if ( strstr(command_info->command, name) != NULL && pc_can_use_command(sd, command_info->command, type) ) - { - suggestions[count] = command_info->command; - ++count; + for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter); alias_info = dbi_next(alias_iter)) { + match = strstr(alias_info->alias, name); + can_use = pc_can_use_command(sd, alias_info->command->command, type); + if ( prefix_count < MAX_SUGGESTIONS && match == alias_info->alias && can_use) { + suggestions[prefix_count] = alias_info->alias; + ++prefix_count; } - } - - for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter) && count < MAX_SUGGESTIONS; alias_info = dbi_next(alias_iter)) { - if ( strstr(alias_info->alias, name) != NULL && pc_can_use_command(sd, alias_info->command->command, type) ) - { - suggestions[count] = alias_info->alias; - ++count; + if ( full_count < MAX_SUGGESTIONS && match != NULL && match != alias_info->alias && can_use ) { + full_match[full_count] = alias_info->alias; + ++full_count; } } - if (count > 0) - { + if ((full_count+prefix_count) > 0) { char buffer[512]; int i; + // Merge full match and prefix match results + if (prefix_count < MAX_SUGGESTIONS) { + memmove(&suggestions[prefix_count], full_match, sizeof(char*) * (MAX_SUGGESTIONS-prefix_count)); + prefix_count = min(prefix_count+full_count, MAX_SUGGESTIONS); + } + + // Build the suggestion string strcpy(buffer, msg_txt(205)); strcat(buffer,"\n"); - for(i=0; i < count; ++i) - { + for(i=0; i < prefix_count; ++i) { strcat(buffer,suggestions[i]); strcat(buffer," "); } |