From ecbca44f124c5e379c9a1ef5433c2c3c0ed07c4f Mon Sep 17 00:00:00 2001 From: skotlex Date: Wed, 10 May 2006 00:37:24 +0000 Subject: - Modified @commands to use Meruru's code which is faster and does a fair attempt at tabulating the commands presented. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6541 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-Trunk.txt | 2 ++ src/map/atcommand.c | 60 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 68c9f82a0..29b1688eb 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. 2006/05/09 + * Modified @commands to use Meruru's code which is faster and does a fair + attempt at tabulating the commands presented. [Skotlex] * Updated SKA to return a random value between 0 and 99 each time status_get_def is invoked. [Skotlex] * Updated Making Arrow to not include unidentified items in the list. diff --git a/src/map/atcommand.c b/src/map/atcommand.c index c2bbfda12..1e6f76516 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1162,37 +1162,49 @@ int duel_reject( */ /*========================================== - * @commands Lists available @ commands to you. + * @commands Lists available @ commands to you (code 98% from Meruru) *------------------------------------------ */ -int atcommand_commands(const int fd, struct map_session_data* sd, +int atcommand_commands( + const int fd, struct map_session_data* sd, const char* command, const char* message) { - int i,count=0,level; - nullpo_retr(-1, sd); - level = pc_isGM(sd); - + char cz_line_buff[MESSAGE_SIZE+1]; + + register char *lpcz_cur = cz_line_buff; + register unsigned int ui_slen; + + int i_cur_cmd,gm_lvl = pc_isGM(sd), count = 0; + + memset(cz_line_buff,' ',MESSAGE_SIZE); + cz_line_buff[MESSAGE_SIZE] = 0; + clif_displaymessage(fd, msg_txt(273)); - memset(atcmd_output, 0, sizeof atcmd_output); - for (i = 0; atcommand_info[i].type != AtCommand_Unknown; i++) - if (atcommand_info[i].level <= level && atcommand_info[i].command) { - count++; - strcat(atcmd_output, atcommand_info[i].command); - strcat(atcmd_output, " "); - if (!(count%10)) { - clif_displaymessage(fd, atcmd_output); - memset(atcmd_output, 0, sizeof atcmd_output); - } + + for (i_cur_cmd = 0;atcommand_info[i_cur_cmd].type != AtCommand_Unknown;i_cur_cmd++) + { + if(gm_lvl < atcommand_info[i_cur_cmd].level) + continue; + + count++; + ui_slen = (unsigned int)strlen(atcommand_info[i_cur_cmd].command); + + //rember not <= bc we need null terminator + if(((MESSAGE_SIZE+(int)cz_line_buff)-(int)lpcz_cur) < (int)ui_slen) + { + clif_displaymessage(fd,(char*)cz_line_buff); + lpcz_cur = cz_line_buff; + memset(cz_line_buff,' ',MESSAGE_SIZE); + cz_line_buff[MESSAGE_SIZE] = 0; } - if (count%10) - clif_displaymessage(fd, atcmd_output); - if (count) { - sprintf(atcmd_output, msg_txt(274), count); - clif_displaymessage(fd, atcmd_output); - } else - clif_displaymessage(fd, msg_txt(275)); - + memcpy(lpcz_cur,atcommand_info[i_cur_cmd].command,ui_slen); + lpcz_cur += ui_slen+(10-ui_slen%10); + } + + clif_displaymessage(fd,(char*)cz_line_buff); + sprintf(atcmd_output, msg_txt(274), count); //There will always be at least 1 command (@commands) + clif_displaymessage(fd, atcmd_output); return 0; } -- cgit v1.2.3-70-g09d2