From 556834d0508101b70660c5904b24adacacced3e0 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 19 Sep 2013 17:12:27 +0200 Subject: Cleaned up and de-duplicated ranklist-related code Follow-up to 6cf032d. Special thanks to Ind. Signed-off-by: Haru --- src/char/char.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/char') diff --git a/src/char/char.c b/src/char/char.c index 943d1f52e..dc7966e8d 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -136,7 +136,7 @@ int guild_exp_rate = 100; //Custom limits for the fame lists. [Skotlex] int fame_list_size_chemist = MAX_FAME_LIST; -int fame_list_size_smith = MAX_FAME_LIST; +int fame_list_size_smith = MAX_FAME_LIST; int fame_list_size_taekwon = MAX_FAME_LIST; // Char-server-side stored fame lists [DracoRPG] @@ -2517,8 +2517,7 @@ int save_accreg2(unsigned char* buf, int len) return 0; } -void char_read_fame_list(void) -{ +void char_read_fame_list(void) { int i; char* data; size_t len; @@ -2576,8 +2575,7 @@ void char_read_fame_list(void) } // Send map-servers the fame ranking lists -int char_send_fame_list(int fd) -{ +int char_send_fame_list(int fd) { int i, len = 8; unsigned char buf[32000]; @@ -2612,8 +2610,7 @@ int char_send_fame_list(int fd) return 0; } -void char_update_fame_list(int type, int index, int fame) -{ +void char_update_fame_list(int type, int index, int fame) { unsigned char buf[8]; WBUFW(buf,0) = 0x2b22; WBUFB(buf,2) = type; @@ -3210,12 +3207,11 @@ int parse_frommap(int fd) int player_pos; int fame_pos; - switch(type) - { - case 1: size = fame_list_size_smith; list = smith_fame_list; break; - case 2: size = fame_list_size_chemist; list = chemist_fame_list; break; - case 3: size = fame_list_size_taekwon; list = taekwon_fame_list; break; - default: size = 0; list = NULL; break; + switch(type) { + case RANKTYPE_BLACKSMITH: size = fame_list_size_smith; list = smith_fame_list; break; + case RANKTYPE_ALCHEMIST: size = fame_list_size_chemist; list = chemist_fame_list; break; + case RANKTYPE_TAEKWON: size = fame_list_size_taekwon; list = taekwon_fame_list; break; + default: size = 0; list = NULL; break; } ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player @@ -3223,22 +3219,20 @@ int parse_frommap(int fd) if( player_pos == size && fame_pos == size ) ;// not on list and not enough fame to get on it - else if( fame_pos == player_pos ) - {// same position + else if( fame_pos == player_pos ) { + // same position list[player_pos].fame = fame; char_update_fame_list(type, player_pos, fame); - } - else - {// move in the list - if( player_pos == size ) - {// new ranker - not in the list + } else { + // move in the list + if( player_pos == size ) { + // new ranker - not in the list ARR_MOVE(size - 1, fame_pos, list, struct fame_list); list[fame_pos].id = cid; list[fame_pos].fame = fame; char_loadName(cid, list[fame_pos].name); - } - else - {// already in the list + } else { + // already in the list if( fame_pos == size ) --fame_pos;// move to the end of the list ARR_MOVE(player_pos, fame_pos, list, struct fame_list); -- cgit v1.2.3-60-g2f50