diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 9 | ||||
-rw-r--r-- | src/char_sql/char.c | 5 | ||||
-rw-r--r-- | src/common/mmo.h | 7 | ||||
-rw-r--r-- | src/login/login.c | 2 | ||||
-rw-r--r-- | src/login_sql/login.c | 2 | ||||
-rw-r--r-- | src/map/clif.c | 6 | ||||
-rw-r--r-- | src/map/itemdb.c | 6 | ||||
-rw-r--r-- | src/map/mob.c | 111 | ||||
-rw-r--r-- | src/map/script.c | 1 | ||||
-rw-r--r-- | src/map/status.h | 1 |
10 files changed, 74 insertions, 76 deletions
diff --git a/src/char/char.c b/src/char/char.c index d714a60bc..d3bd322c7 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -452,17 +452,18 @@ int mmo_friends_list_data_str(char *str, struct mmo_charstatus *p) --------------------------------------------------*/ int mmo_hotkeys_tostr(char *str, struct mmo_charstatus *p) { +#ifdef HOTKEY_SAVING int i; char *str_p = str; str_p += sprintf(str_p, "%d", p->char_id); -#ifdef HOTKEY_SAVING - for (i=0;i<HOTKEY_SAVING;i++) + for (i=0;i<MAX_HOTKEYS;i++) str_p += sprintf(str_p, ",%d,%d,%d", p->hotkeys[i].type, p->hotkeys[i].id, p->hotkeys[i].lv); -#endif str_p += '\0'; +#endif return 0; } + //------------------------------------------------- // Function to create the character line (for save) //------------------------------------------------- @@ -935,7 +936,7 @@ int parse_hotkey_txt(struct mmo_charstatus *p) //Read hotkeys len = strlen(line); next = pos; - for (count = 0; next < len && count < HOTKEY_SAVING; count++) + for (count = 0; next < len && count < MAX_HOTKEYS; count++) { if (sscanf(line+next, ",%d,%d,%d%n",&type,&id,&lv, &pos) < 3) //Invalid entry? diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 2244db57a..0f42d3b96 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -828,9 +828,10 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything struct item tmp_item; struct skill tmp_skill; struct s_friend tmp_friend; +#ifdef HOTKEY_SAVING struct hotkey tmp_hotkey; int hotkey_num; - +#endif memset(p, 0, sizeof(struct mmo_charstatus)); @@ -1041,7 +1042,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything while( SQL_SUCCESS == SqlStmt_NextRow(stmt) ) { - if( hotkey_num >= 0 && hotkey_num < HOTKEY_SAVING ) + if( hotkey_num >= 0 && hotkey_num < MAX_HOTKEYS ) memcpy(&p->hotkeys[hotkey_num], &tmp_hotkey, sizeof(tmp_hotkey)); else ShowWarning("mmo_char_fromsql: ignoring invalid hotkey (hotkey=%d,type=%u,id=%u,lv=%u) of character %s (AID=%d,CID=%d)\n", hotkey_num, tmp_hotkey.type, tmp_hotkey.id, tmp_hotkey.lv, p->name, p->account_id, p->char_id); diff --git a/src/common/mmo.h b/src/common/mmo.h index 4858a1667..ddc43ebbf 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -11,11 +11,12 @@ //Remove/Comment this line to disable sc_data saving. [Skotlex] #define ENABLE_SC_SAVING - //Remove/Comment this line to disable server-side hot-key saving support [Skotlex] //Note that newer clients no longer save hotkeys in the registry! +#define HOTKEY_SAVING + //The number is the max number of hotkeys to save (27 = 9 skills x 3 bars) -#define HOTKEY_SAVING 27 +#define MAX_HOTKEYS 27 #define MAX_MAP_PER_SERVER 1024 #define MAX_INVENTORY 100 @@ -230,7 +231,7 @@ struct mmo_charstatus { struct s_friend friends[MAX_FRIENDS]; //New friend system [Skotlex] #ifdef HOTKEY_SAVING - struct hotkey hotkeys[HOTKEY_SAVING]; + struct hotkey hotkeys[MAX_HOTKEYS]; #endif }; diff --git a/src/login/login.c b/src/login/login.c index 0a06dcb75..f0ca3c29f 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -3034,7 +3034,7 @@ int parse_login(int fd) login_log("Request for connection (encryption mode) of %s (ip: %s).\n", account.userid, ip); memcpy(account.passwd, RFIFOP(fd,30), 16); account.passwd[16] = '\0'; // binary data here } - account.passwdenc = (command != 0x01dd) ? 0 : PASSWORDENC; + account.passwdenc = (command == 0x01dd) ? PASSWORDENC : 0; result = mmo_auth(&account, fd); if( result == -1 ) diff --git a/src/login_sql/login.c b/src/login_sql/login.c index b3f5e2058..c64f14fcd 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -1312,7 +1312,7 @@ int parse_login(int fd) account.version = 1; //Force some version... safestrncpy(account.userid, RFIFOP(fd,6), NAME_LENGTH);//## does it have to be nul-terminated? safestrncpy(account.passwd, RFIFOP(fd,30), NAME_LENGTH);//## does it have to be nul-terminated? - account.passwdenc = (command != 0x01dd) ? 0 : PASSWORDENC; + account.passwdenc = (command == 0x01dd) ? PASSWORDENC : 0; Sql_EscapeStringLen(sql_handle, esc_userid, account.userid, strlen(account.userid)); result = mmo_auth(&account, fd); diff --git a/src/map/clif.c b/src/map/clif.c index e48714c4e..a66bd72d5 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -8003,9 +8003,9 @@ void clif_hotkeys_send(struct map_session_data *sd) { const int fd = sd->fd; int i; if (!fd) return; - WFIFOHEAD(fd, 2+HOTKEY_SAVING*7); + WFIFOHEAD(fd, 2+MAX_HOTKEYS*7); WFIFOW(fd, 0) = 0x02b9; - for(i = 0; i < HOTKEY_SAVING; i++) { + for(i = 0; i < MAX_HOTKEYS; i++) { WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level @@ -8021,7 +8021,7 @@ void clif_parse_Hotkey(int fd, struct map_session_data *sd) { cmd = RFIFOW(fd, 0); idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]); - if (idx >= HOTKEY_SAVING) return; + if (idx >= MAX_HOTKEYS) return; sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]); sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]); diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 91eaeafce..7d6514446 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -799,7 +799,7 @@ static bool itemdb_parse_dbrow(char** str, char* source, int line) *------------------------------------------*/ static int itemdb_readdb(void) { - char* filename[] = { "item_db.txt", "item_db2.txt" }; + const char* filename[] = { "item_db.txt", "item_db2.txt" }; int fi; for( fi = 0; fi < ARRAYLENGTH(filename); ++fi ) @@ -911,10 +911,10 @@ static int itemdb_readdb(void) *======================================*/ static int itemdb_read_sqldb(void) { - char* item_db_name[] = { item_db_db, item_db2_db }; + const char* item_db_name[] = { item_db_db, item_db2_db }; int fi; - for (fi = 0; fi < 2; fi++) + for( fi = 0; fi < ARRAYLENGTH(item_db_name); ++fi ) { uint32 lines = 0, count = 0; diff --git a/src/map/mob.c b/src/map/mob.c index d83229af1..da151faed 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -2588,12 +2588,8 @@ int mob_skillid2skillidx(int class_,int skillid) if(ms==NULL) return -1; - for(i=0;i<max;i++){ - if(ms[i].skill_id == skillid) - return i; - } - return -1; - + ARR_FIND( 0, max, i, ms[i].skill_id == skillid ); + return ( i < max ) ? i : -1; } /*========================================== @@ -2689,12 +2685,10 @@ int mob_getfriendstatus_sub(struct block_list *bl,va_list ap) struct mob_data *mob_getfriendstatus(struct mob_data *md,int cond1,int cond2) { - struct mob_data *fr=NULL; - + struct mob_data* fr = NULL; nullpo_retr(0, md); - map_foreachinrange(mob_getfriendstatus_sub, &md->bl, 8, - BL_MOB,md,cond1,cond2,&fr); + map_foreachinrange(mob_getfriendstatus_sub, &md->bl, 8,BL_MOB, md,cond1,cond2,&fr); return fr; } @@ -2953,12 +2947,8 @@ int mob_clone_spawn(struct map_session_data *sd, int m, int x, int y, const char nullpo_retr(0, sd); - for(class_=MOB_CLONE_START; class_<MOB_CLONE_END; class_++){ - if(mob_db_data[class_]==NULL) - break; - } - - if(class_>MOB_CLONE_END) + ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob_db_data[class_] == NULL ); + if(class_ >= MOB_CLONE_END) return 0; mob_db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db)); @@ -3459,10 +3449,10 @@ static bool mob_parse_dbrow(char** str) *------------------------------------------*/ static int mob_readdb(void) { - char* filename[] = { "mob_db.txt", "mob_db2.txt" }; + const char* filename[] = { "mob_db.txt", "mob_db2.txt" }; int fi; - for(fi = 0; fi < 2; fi++) + for( fi = 0; fi < ARRAYLENGTH(filename); ++fi ) { uint32 lines = 0, count = 0; char line[1024]; @@ -3520,10 +3510,10 @@ static int mob_readdb(void) *------------------------------------------*/ static int mob_read_sqldb(void) { - char* mob_db_name[] = { mob_db_db, mob_db2_db }; + const char* mob_db_name[] = { mob_db_db, mob_db2_db }; int fi; - for (fi = 0; fi < 2; fi++) + for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi ) { uint32 lines = 0, count = 0; @@ -3630,7 +3620,7 @@ static int mob_readdb_mobavail(void) mob_db_data[class_]->vd.head_top=atoi(str[7]); mob_db_data[class_]->vd.head_mid=atoi(str[8]); mob_db_data[class_]->vd.head_bottom=atoi(str[9]); - mob_db_data[class_]->option=atoi(str[10])&~0x46; + mob_db_data[class_]->option=atoi(str[10])&~(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE); mob_db_data[class_]->vd.cloth_color=atoi(str[11]); // Monster player dye option - Valaris } else if(str[2] && atoi(str[2]) > 0) @@ -3661,7 +3651,8 @@ static int mob_read_randommonster(void) memset(&summon, 0, sizeof(summon)); - for(i=0;i<MAX_RANDOMMONSTER;i++){ + for( i = 0; i < ARRAYLENGTH(mobfile) && i < MAX_RANDOMMONSTER; i++ ) + { mob_db_data[0]->summonper[i] = 1002; // 設定し忘れた場合はポリンが出るようにしておく sprintf(line, "%s/%s", db_path, mobfile[i]); fp=fopen(line,"r"); @@ -3689,7 +3680,7 @@ static int mob_read_randommonster(void) continue; mob_db_data[class_]->summonper[i]=atoi(str[2]); if (i) { - if (summon[i].qty < sizeof(summon[i].class_)/sizeof(summon[i].class_[0])) //MvPs + if( summon[i].qty < ARRAYLENGTH(summon[i].class_) ) //MvPs summon[i].class_[summon[i].qty++] = class_; else { ShowDebug("Can't store more random mobs from %s, increase size of mob.c:summon variable!\n", mobfile[i]); @@ -3748,7 +3739,7 @@ static int mob_readskilldb(void) { "anybad", -1 }, { "stone", SC_STONE }, { "freeze", SC_FREEZE }, - { "stan", SC_STUN }, + { "stun", SC_STUN }, { "sleep", SC_SLEEP }, { "poison", SC_POISON }, { "curse", SC_CURSE }, @@ -3786,13 +3777,15 @@ static int mob_readskilldb(void) }; int x; - char *filename[]={ "mob_skill_db.txt","mob_skill_db2.txt" }; + const char* filename[] = { "mob_skill_db.txt","mob_skill_db2.txt" }; - if (!battle_config.mob_skill_rate) { + if( battle_config.mob_skill_rate == 0 ) { ShowStatus("Mob skill use disabled. Not reading mob skills.\n"); return 0; } - for(x=0;x<2;x++){ + + for( x = 0; x < ARRAYLENGTH(filename); ++x ) + { int last_mob_id = 0; count = 0; sprintf(line, "%s/%s", db_path, filename[x]); @@ -3837,7 +3830,7 @@ static int mob_readskilldb(void) if (mob_id < 0) continue; memset(mob_db_data[mob_id]->skill,0,sizeof(struct mob_skill)); - mob_db_data[mob_id]->maxskill=0; + mob_db_data[mob_id]->maxskill=0; continue; } @@ -3845,28 +3838,24 @@ static int mob_readskilldb(void) { //Prepare global skill. [Skotlex] memset(&gms, 0, sizeof (struct mob_skill)); ms = &gms; - } else { - for(i=0;i<MAX_MOBSKILL;i++) - if( (ms=&mob_db_data[mob_id]->skill[i])->skill_id == 0) - break; - if(i==MAX_MOBSKILL){ + } else { + ARR_FIND( 0, MAX_MOBSKILL, i, (ms = &mob_db_data[mob_id]->skill[i])->skill_id == 0 ); + if( i == MAX_MOBSKILL ) { if (mob_id != last_mob_id) { - ShowError("mob_skill: readdb: too many skill! Line %d in %d[%s]\n", - count,mob_id,mob_db_data[mob_id]->sprite); + ShowError("mob_skill: readdb: too many skills! Line %d in %d[%s]\n", count,mob_id,mob_db_data[mob_id]->sprite); last_mob_id = mob_id; } continue; } } - ms->state=atoi(sp[2]); - tmp = sizeof(state)/sizeof(state[0]); - for(j=0;j<tmp && strcmp(sp[2],state[j].str);j++); - if (j < tmp) - ms->state=state[j].id; - else if (!ms->state) { + //State + ARR_FIND( 0, ARRAYLENGTH(state), j, strcmp(sp[2],state[j].str) == 0 ); + if( j < ARRAYLENGTH(state) ) + ms->state = state[j].id; + else { ShowWarning("mob_skill: Unrecognized state %s at %s, line %d\n", sp[2], filename[x], count); - ms->state=MSS_ANY; + ms->state = MSS_ANY; } //Skill ID @@ -3880,6 +3869,7 @@ static int mob_readskilldb(void) continue; } ms->skill_id=j; + //Skill lvl j= atoi(sp[4])<=0 ? 1 : atoi(sp[4]); ms->skill_lv= j>battle_config.mob_max_skilllvl ? battle_config.mob_max_skilllvl : j; //we strip max skill level @@ -3900,10 +3890,14 @@ static int mob_readskilldb(void) ms->delay = INT_MAX; ms->cancel=atoi(sp[8]); if( strcmp(sp[8],"yes")==0 ) ms->cancel=1; - ms->target=atoi(sp[9]); - for(j=0;j<sizeof(target)/sizeof(target[0]);j++){ - if( strcmp(sp[9],target[j].str)==0) - ms->target=target[j].id; + + //Target + ARR_FIND( 0, ARRAYLENGTH(target), j, strcmp(sp[9],target[j].str) == 0 ); + if( j < ARRAYLENGTH(target) ) + ms->target = target[j].id; + else { + ShowWarning("mob_skill: Unrecognized target %s at %s, line %d\n", sp[9], filename[x], count); + ms->target = MST_TARGET; } //Check that the target condition is right for the skill type. [Skotlex] @@ -3925,21 +3919,22 @@ static int mob_readskilldb(void) ms->target = MST_TARGET; } - tmp = sizeof(cond1)/sizeof(cond1[0]); - for(j=0;j<tmp && strcmp(sp[10],cond1[j].str);j++); - if (j < tmp) - ms->cond1=cond1[j].id; + //Cond1 + ARR_FIND( 0, ARRAYLENGTH(cond1), j, strcmp(sp[10],cond1[j].str) == 0 ); + if( j < ARRAYLENGTH(cond1) ) + ms->cond1 = cond1[j].id; else { - ShowWarning("mob_skill: Unrecognized condition 1 %s at %s, line %d\n", - sp[10], filename[x], count); - ms->cond1=-1; + ShowWarning("mob_skill: Unrecognized condition 1 %s at %s, line %d\n", sp[10], filename[x], count); + ms->cond1 = -1; } - ms->cond2=atoi(sp[11]); - tmp = sizeof(cond2)/sizeof(cond2[0]); - for(j=0;j<tmp && strcmp(sp[11],cond2[j].str);j++); - if (j < tmp) - ms->cond2=cond2[j].id; + //Cond2 + // numeric value + ms->cond2 = atoi(sp[11]); + // or special constant + ARR_FIND( 0, ARRAYLENGTH(cond2), j, strcmp(sp[11],cond2[j].str) == 0 ); + if( j < ARRAYLENGTH(cond2) ) + ms->cond2 = cond2[j].id; ms->val[0]=(int)strtol(sp[12],NULL,0); ms->val[1]=(int)strtol(sp[13],NULL,0); diff --git a/src/map/script.c b/src/map/script.c index fc2d75eee..09113d577 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5863,6 +5863,7 @@ BUILDIN_FUNC(countitem) if (nameid < 500) { if(battle_config.error_log) ShowError("wrong item ID : countitem(%i)\n", nameid); + script_reportsrc(st); script_pushint(st,0); return 1; } diff --git a/src/map/status.h b/src/map/status.h index 91981bdf4..489a08c66 100644 --- a/src/map/status.h +++ b/src/map/status.h @@ -579,7 +579,6 @@ int status_percent_change(struct block_list *src,struct block_list *target,signe #define status_percent_heal(bl, hp_rate, sp_rate) status_percent_change(NULL, bl, -(hp_rate), -(sp_rate), 1) #define status_percent_damage(src, target, hp_rate, sp_rate) status_percent_change(src, target, hp_rate, sp_rate, 0) //Instant kill with no drops/exp/etc -// #define status_kill(bl) status_percent_damage(NULL, bl, 100, 0) //Used to set the hp/sp of an object to an absolute value (can't kill) int status_set_hp(struct block_list *bl, unsigned int hp, int flag); |