فهرست منبع

Bug Fixes:
- 'hp_rate' and 'sp_rate' config aren't working. http://rathena.org/board/tracker/issue-8742-max-hpsp-battleconf-not-working/
- Mercenary DB that aren't being read properly whic also happens for Homunculus DB. http://rathena.org/board/tracker/issue-8761-mercenary-db-import-folder-issue/
- Fixed Elemental DBs that aren't being imported yet. (also changed to sv_readdb)

Rebellion Skill Updates:
- Some updates according to kRO updates on http://forums.irowiki.org/showpost.php?p=1364894&postcount=579, http://forums.irowiki.org/showpost.php?p=1388802&postcount=981, and http://forums.irowiki.org/showpost.php?p=1389627&postcount=1008
- Partial merge from idAthena.
- Using 0x107 as temporary marker on mini-map for Crimson Marker target.
- Some stuffs maybe still wrong, feel free to report/fix it.
- Thank people on those links, Ziu, and idAthena.

Misc changes:
- Changed some function names for homunculus.c/h with prefix hom_* and mercenary.c/h with prefix mercenary_*
- Change unnecessary 'int' return value tos 'void'

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>

Cydh Ramdh 11 سال پیش
والد
کامیت
dd67f9de96

+ 5 - 5
db/re/skill_cast_db.txt

@@ -1643,15 +1643,15 @@
 //-- RL_MASS_SPIRAL
 2553,0,1000,0,0,30000,1000,-1
 //-- RL_BANISHING_BUSTER
-2554,0,1000,0,0,0,1500,-1
+2554,3000:2500:2000:1500:1000,1000,0,0,0,1500,-1
 //-- RL_B_TRAP
 2555,0,0,0,10000:11000:12000:13000:14000,0,2000,-1
 //-- RL_FLICKER
 2556,0,500,0,0,0,2000,-1
 //-- RL_S_STORM
-2557,0,1000,0,0,0,1500,-1
+2557,3000:2500:2000:1500:1000,1000,0,0,0,2000,-1
 //-- RL_E_CHAIN
-2558,0,500,0,30000:45000:60000:75000:90000:105000:120000:135000:150000:165000,0,5000,-1
+2558,0,500,0,45000:60000:75000:90000:105000:120000:135000:150000:165000:180000,0,5000,-1
 //-- RL_QD_SHOT
 2559,0,1000,0,1500,0,5000,-1
 //-- RL_C_MARKER
@@ -1673,9 +1673,9 @@
 //-- RL_HEAT_BARREL
 2568,0,1000,0,60000,10000,10000,-1
 //-- RL_AM_BLAST
-2569,0,1500,0,0,12000:14000:16000:18000:20000,3000,-1
+2569,2000,1500,0,0,6000:7000:8000:9000:10000,1000,-1
 //-- RL_SLUGSHOT
-2570,0,1000,0,0,10000,1500,-1
+2570,5000:6000:7000:8000:9000,1000,0,0,10000,1500,1000
 //-- RL_HAMMER_OF_GOD
 2571,0,1000,0,0,3000:3000:4000:4000:5000,3000,-1
 //-- RL_R_TRIP_PLUSATK

+ 4 - 4
db/re/skill_db.txt

@@ -1234,19 +1234,19 @@
 2552,0,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,	RL_RICHS_COIN,Rich's Coin
 2553,15,6,1,-1,0,0,5,1,no,0,0,0,weapon,0,0x0,	RL_MASS_SPIRAL,Mass Spiral
 2554,9,6,1,-1,0x2,2,5,1,no,0,0,0,weapon,0,0x0,	RL_BANISHING_BUSTER,Banishing Buster
-2555,3,6,2,0,0x1,1,5,1,no,0,0,1,misc,0,0x0,	RL_B_TRAP,Bind Trap
+2555,3,6,2,0,0x1,1,5,1,no,0,0,3,misc,0,0x0,	RL_B_TRAP,Bind Trap
 2556,0,6,4,0,0x3,-1,1,1,no,0,0,0,none,0,0x0,	RL_FLICKER,Flicker
 2557,9,6,1,-1,0x2,2,5,1,no,0,0,0,weapon,0,0x0,	RL_S_STORM,Shatter Storm
 2558,0,6,4,0,0x1,0,10,1,no,0,0,0,none,0,0x0,	RL_E_CHAIN,Eternal Chain
 2559,-9,6,4,-1,0x3,21,1,1,no,0,0x0,0,weapon,0,0x0,	RL_QD_SHOT,Quick Draw Shot
 2560,11,6,1,0,0x1,0,1,1,no,0,0,3,none,0,0x0,	RL_C_MARKER,Crimson Marker
-2561,0,6,4,-1,0x2,3,5,1,no,0,0,0,weapon,0,0x0,	RL_FIREDANCE,Fire Dance
+2561,0,6,4,-1,0x2,2,5,1,no,0,0,0,weapon,0,0x0,	RL_FIREDANCE,Fire Dance
 2562,7:8:9:10:11,6,1,-1,0x2,2,5,1,no,0,0,0,weapon,0,0x0,	RL_H_MINE,Howling Mine
 2563,0,6,4,0,0x1,0,5,1,no,0,0,0,none,0,0x0,	RL_P_ALTER,Platinum Alter
 2564,9,6,2,0,0x1,0,5,1,no,0,0,0,none,0,0x0,	RL_FALLEN_ANGEL,Fallen Angel
-2565,0,6,4,-1,0x2,2:2:2:2:3,5,1,no,0,0,0,weapon,3,0x0,	RL_R_TRIP,Round Trip
+2565,0,6,4,-1,0x2,3:3:4:5:6,5,1,no,0,0,0,weapon,3,0x0,	RL_R_TRIP,Round Trip
 2566,0,6,4,-1,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	RL_D_TAIL,Dragon Tail
-2567,3,6,1,-1,0x2,5,5,1,no,0,0,0,weapon,0,0,	RL_FIRE_RAIN,Fire Rain
+2567,9,6,2,-1,0x2,1,5,1,no,0,0,0,weapon,0,0,	RL_FIRE_RAIN,Fire Rain
 2568,0,6,4,0,0x1,0,5,1,no,0,0,0,none,0,0x0,	RL_HEAT_BARREL,Heat Barrel
 2569,9,6,1,-1,0,0,5,1,no,0,0,0,weapon,0,0x0,	RL_AM_BLAST,Anti-Material Blast
 2570,9,6,1,-1,0,0,5,1,no,0,0,0,weapon,0,0x0,	RL_SLUGSHOT,Slug Shot

+ 5 - 5
db/re/skill_require_db.txt

@@ -901,16 +901,16 @@
 2559,0,0,5,0,0,0,17:18:19:20:21,3:4:5,1,none,SC_QD_SHOT_READY,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_QD_SHOT#Quick Draw Shot#
 2560,0,0,10,0,0,0,17:18:19:20:21,0,0,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_C_MARKER#Crimson Marker#
 2561,0,0,10:15:20:25:30,0,0,0,17,3,5,none,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_FIREDANCE#Fire Dance#
-2562,0,0,45:50:55:60:65,0,0,0,21,0,0,none,0,0,7664,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_H_MINE#Howling Mine#
-2563,0,0,20:24:28:32:36,0,0,0,99,0,0,none,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13201	//RL_P_ALTER#Platinum Alter#
-2564,0,0,90,0,0,0,17,0,0,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_FALLEN_ANGEL#Fallen Angel#
-2565,0,0,40:45:50:55:60,0,0,0,19,3,5,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_R_TRIP#Round Trip#
+2562,0,0,45:50:55:60:65,0,0,0,21,0,0,none,0,1,7664,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_H_MINE#Howling Mine#
+2563,0,0,20:24:28:32:36,0,0,0,99,0,0,none,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_P_ALTER#Platinum Alter#
+2564,0,0,10,0,0,0,17,0,0,none,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_FALLEN_ANGEL#Fallen Angel#
+2565,0,0,40:45:50:55:60,0,0,0,19,3,5,none,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_R_TRIP#Round Trip#
 2566,0,0,60:70:80:90:100,0,0,0,21,5,1,none,0,0,7665,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_D_TAIL#Dragon Tail#
 2567,0,0,70,0,0,0,19,3,10,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_FIRE_RAIN#Fire Rain#
 2568,0,0,30:40:50:60:70,0,0,0,99,0,0,none,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_HEAT_BARREL#Heat Barrel#
 2569,0,0,80:84:88:92:96,0,0,0,17:18:19:20:21,0,0,none,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_AM_BLAST#Anti-Material Blast#
 2570,0,0,55:60:65:70:75,0,0,0,20,3,1,none,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_SLUGSHOT#Slug Shot#
-2571,0,0,70:80:90:100:110,0,0,0,18,3,1,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_HAMMER_OF_GOD#Hammer of God#
+2571,0,0,70:80:90:100:110,0,0,0,18,3,0,none,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_HAMMER_OF_GOD#Hammer of God#
 //2572,0,0,1,0,0,0,99,0,0,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_R_TRIP_PLUSATK#Round Trip Plus Attack#
 //2573,0,0,1,0,0,0,99,0,0,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_B_FLICKER_ATK#Bind Flicker Attack#
 //2574,0,0,1,0,0,0,99,0,0,none,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	//RL_GLITTERING_GREED_ATK#Flip The Coin Greed Attack#

+ 2 - 2
db/re/skill_unit_db.txt

@@ -157,8 +157,8 @@
 2488,0xe9,    ,  0, 2, 500,enemy, 0x000	//GN_FIRE_EXPANSION_TEAR_GAS
 2490,0xea,    ,  0, 1,1000,enemy, 0x002	//GN_HELLS_PLANT
 
-2555,0x104,   ,  0, 1:2:2:3:3,500,enemy,0x006	//RL_B_TRAP
-2567,0x105,   ,  2, 2,1000,enemy, 0x0	//RL_FIRE_RAIN
+2555,0x104,   ,  0, 1:2:2:3:3,500,enemy,0x6	//RL_B_TRAP
+2567,0x105,   , -1, 0,1000,enemy, 0x98	//RL_FIRE_RAIN
 
 3006,0x86,    ,  0, 2,1000,enemy, 0x018	//KO_BAKURETSU
 3008,0x86,    ,  0, 2,1000,enemy, 0x018	//KO_MUCHANAGE

+ 18 - 18
src/map/atcommand.c

@@ -3687,16 +3687,16 @@ ACMD_FUNC(reload) {
 	} else if (strstr(command, "mobdb") || strncmp(message, "mobdb", 3) == 0) {
 		mob_reload();
 		read_petdb();
-		merc_reload();
-		read_mercenarydb();
-		read_mercenary_skilldb();
+		hom_reload();
+		mercenary_readdb();
+		mercenary_read_skilldb();
 		reload_elementaldb();
 		clif_displaymessage(fd, msg_txt(sd,98)); // Monster database has been reloaded.
 	} else if (strstr(command, "skilldb") || strncmp(message, "skilldb", 4) == 0) {
 		skill_reload();
-		merc_skill_reload();
+		hom_reload_skill();
 		reload_elemental_skilldb();
-		read_mercenary_skilldb();
+		mercenary_read_skilldb();
 		clif_displaymessage(fd, msg_txt(sd,99)); // Skill database has been reloaded.
 	} else if (strstr(command, "atcommand") || strncmp(message, "atcommand", 4) == 0) {
 		config_t run_test;
@@ -5522,7 +5522,7 @@ ACMD_FUNC(useskill)
 	}
 
 	if (skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE+MAX_HOMUNSKILL
-		&& sd->hd && merc_is_hom_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
+		&& sd->hd && hom_is_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
 		bl = &sd->hd->bl;
 	else
 		bl = &sd->bl;
@@ -7132,7 +7132,7 @@ ACMD_FUNC(homlevel)
 		return -1;
 	}
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7141,7 +7141,7 @@ ACMD_FUNC(homlevel)
 
 	for (i = 1; i <= level && hd->exp_next; i++){
 		hd->homunculus.exp += hd->exp_next;
-		if( !merc_hom_levelup(hd) ){
+		if( !hom_levelup(hd) ){
 			break;
 		}
 	}
@@ -7158,12 +7158,12 @@ ACMD_FUNC(homevolution)
 {
 	nullpo_retr(-1, sd);
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
 
-	if ( !merc_hom_evolution(sd->hd) ) {
+	if ( !hom_evolution(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1255)); // Your homunculus doesn't evolve.
 		return -1;
 	}
@@ -7176,7 +7176,7 @@ ACMD_FUNC(hommutate)
 	int homun_id, m_class = 0, m_id;
 	nullpo_retr(-1, sd);
 
-	if (!merc_is_hom_active(sd->hd)) {
+	if (!hom_is_active(sd->hd)) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7223,7 +7223,7 @@ ACMD_FUNC(makehomun)
 		return -1;
 	}
 
-	merc_create_homunculus_request(sd,homunid);
+	hom_create_request(sd,homunid);
 	return 0;
 }
 
@@ -7236,7 +7236,7 @@ ACMD_FUNC(homfriendly)
 
 	nullpo_retr(-1, sd);
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7263,7 +7263,7 @@ ACMD_FUNC(homhungry)
 
 	nullpo_retr(-1, sd);
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7299,7 +7299,7 @@ ACMD_FUNC(homtalk)
 	if (sd->sc.cant.chat)
 		return -1; //no "chatting" while muted.
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7324,7 +7324,7 @@ ACMD_FUNC(hominfo)
 	struct status_data *status;
 	nullpo_retr(-1, sd);
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7363,7 +7363,7 @@ ACMD_FUNC(homstats)
 
 	nullpo_retr(-1, sd);
 
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !hom_is_active(sd->hd) ) {
 		clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
 		return -1;
 	}
@@ -7430,7 +7430,7 @@ ACMD_FUNC(homshuffle)
 	if(!sd->hd)
 		return -1; // nothing to do
 
-	if(!merc_hom_shuffle(sd->hd))
+	if(!hom_shuffle(sd->hd))
 		return -1;
 
 	clif_displaymessage(sd->fd, msg_txt(sd,1275)); // Homunculus stats altered.

+ 11 - 13
src/map/battle.c

@@ -2866,6 +2866,10 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s
 		if( sc && sc->data[SC_TRUESIGHT] )
 			skillratio += 2*sc->data[SC_TRUESIGHT]->val1;
 #endif
+		if(sc->data[SC_HEAT_BARREL])
+			skillratio += 200;
+		if(sc->data[SC_P_ALTER])
+			skillratio += sc->data[SC_P_ALTER]->val2;
 	}
 
 	switch( skill_id )
@@ -3698,8 +3702,8 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s
 		case RL_SLUGSHOT:
 			{
 				uint16 w = 50;
-				if (sd->equip_index[EQI_AMMO] > 0) {
-					uint16 idx = sd->equip_index[EQI_AMMO];
+				int16 idx = 0;
+				if (sd && (idx = sd->equip_index[EQI_AMMO]) > 0) {
 					struct item_data *id = NULL;
 					if ((id = itemdb_exists(sd->status.inventory[idx].nameid)))
 						w = id->weight;
@@ -3723,13 +3727,16 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s
 				skillratio += 400 + (300 * skill_lv);
 			break;
 		case RL_HAMMER_OF_GOD:
-			skillratio += -100 + (2000 + (skill_lv - 1) * 500);
+			//! TODO: Please check the right formula. [Cydh]
+			//kRO Update 2013-07-24. Ratio: 1600+lv*800
+			//kRO Update 2014-02-12. Coins increase the damage
+			skillratio += -100 + (1600 + skill_lv * 800) + ((sd) ? sd->spiritball_old : 10) * 20; //(custom)
 			break;
 		case RL_QD_SHOT:
 			skillratio += -100 + (max(pc_checkskill(sd,GS_CHAINACTION),1) * status_get_dex(src) / 5); //(custom)
 			break;
 		case RL_FIRE_RAIN:
-			skillratio += -100 + 500 + (200 * (skill_lv - 1)) + status_get_dex(src); //(custom)
+			skillratio += -100 + 2000 + status_get_dex(src); //(custom) //kRO Update 2013-07-24. 2,000% + caster's DEX (?) [Cydh]
 			break;
 	}
 	return skillratio;
@@ -3937,14 +3944,6 @@ struct Damage battle_attack_sc_bonus(struct Damage wd, struct block_list *src, u
 				ATK_ADD(wd.damage, wd.damage2, sc->data[SC_FLASHCOMBO]->val2);
 				RE_ALLATK_ADD(wd, sc->data[SC_FLASHCOMBO]->val2);
 			}
-			if(sc->data[SC_HEAT_BARREL]) {
-				ATK_ADD(wd.damage, wd.damage2, sc->data[SC_HEAT_BARREL]->val2);
-				RE_ALLATK_ADD(wd, sc->data[SC_HEAT_BARREL]->val2);
-			}
-			if(sc->data[SC_P_ALTER]) {
-				ATK_ADD(wd.damage, wd.damage2, sc->data[SC_P_ALTER]->val2);
-				RE_ALLATK_ADD(wd, sc->data[SC_P_ALTER]->val2);
-			}
 			// Monster Transformation bonus
 			if(wd.flag&BF_LONG && sc->data[SC_MTF_RANGEATK]) {
 				ATK_ADD(wd.damage, wd.damage2, 25);
@@ -6691,7 +6690,6 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
 					case SR_RAMPAGEBLASTER:
 					case NC_COLDSLOWER:
 					case NC_SELFDESTRUCTION:
-					case RL_FIRE_RAIN:
 #ifdef RENEWAL
 					case KN_BOWLINGBASH:
 					case KN_SPEARSTAB:

+ 2 - 6
src/map/cashshop.c

@@ -312,7 +312,7 @@ void cashshop_reloaddb( void ){
  * Destroys cashshop class.
  * Closes all and cleanup.
  */
-int do_final_cashshop( void ){
+void do_final_cashshop( void ){
 	int tab, i;
 
 	for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
@@ -322,8 +322,6 @@ int do_final_cashshop( void ){
 		aFree( cash_shop_items[tab].item );
 	}
 	memset( cash_shop_items, 0, sizeof( cash_shop_items ) );
-
-	return 0;
 }
 
 /*
@@ -331,8 +329,6 @@ int do_final_cashshop( void ){
  * return
  *  0 : success
  */
-int do_init_cashshop( void ){
+void do_init_cashshop( void ){
 	cashshop_read_db();
-
-	return 0;
 }

+ 2 - 2
src/map/cashshop.h

@@ -7,8 +7,8 @@
 #include "../common/cbasetypes.h" // uint16, uint32
 #include "pc.h" // struct map_session_data
 
-int do_init_cashshop( void );
-int do_final_cashshop( void );
+void do_init_cashshop( void );
+void do_final_cashshop( void );
 void cashshop_reloaddb( void );
 bool cashshop_buylist( struct map_session_data* sd, uint32 kafrapoints, int n, uint16* item_list );
 

+ 1 - 2
src/map/channel.c

@@ -1137,11 +1137,10 @@ void channel_read_config(void) {
  * return
  *  0 : success
  */
-int do_init_channel(void) {
+void do_init_channel(void) {
 	channel_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, CHAN_NAME_LENGTH);
 	Channel_Config.ally_enable = Channel_Config.map_enable = Channel_Config.ally_autojoin = Channel_Config.map_autojoin = false;
 	channel_read_config();
-	return 0;
 }
 
 /*

+ 1 - 1
src/map/channel.h

@@ -84,7 +84,7 @@ int channel_pcunbind(struct map_session_data *sd);
 int channel_pcban(struct map_session_data *sd, char *chname, struct map_session_data *tsd, int flag);
 int channel_pcsetopt(struct map_session_data *sd, char *chname, const char *option, const char *val);
 
-int do_init_channel(void);
+void do_init_channel(void);
 void do_final_channel(void);
 
 #ifdef	__cplusplus

+ 4 - 8
src/map/chrif.c

@@ -341,8 +341,8 @@ int chrif_save(struct map_session_data *sd, int flag) {
 
 	if( sd->status.pet_id > 0 && sd->pd )
 		intif_save_petdata(sd->status.account_id,&sd->pd->pet);
-	if( sd->hd && merc_is_hom_active(sd->hd) )
-		merc_save(sd->hd);
+	if( sd->hd && hom_is_active(sd->hd) )
+		hom_save(sd->hd);
 	if( sd->md && mercenary_get_lifetime(sd->md) > 0 )
 		mercenary_save(sd->md);
 	if( sd->ed && elemental_get_lifetime(sd->ed) > 0 )
@@ -1921,7 +1921,7 @@ int auth_db_final(DBKey key, DBData *data, va_list ap) {
 /*==========================================
  * Destructor
  *------------------------------------------*/
-int do_final_chrif(void) {
+void do_final_chrif(void) {
 
 	if( char_fd != -1 ) {
 		do_close(char_fd);
@@ -1931,14 +1931,12 @@ int do_final_chrif(void) {
 	auth_db->destroy(auth_db, auth_db_final);
 
 	ers_destroy(auth_db_ers);
-
-	return 0;
 }
 
 /*==========================================
  *
  *------------------------------------------*/
-int do_init_chrif(void) {
+void do_init_chrif(void) {
 	if(sizeof(struct mmo_charstatus) > 0xFFFF){
 		ShowError("mmo_charstatus size = %d is too big to be transmitted. (must be below 0xFFFF) \n",
 			sizeof(struct mmo_charstatus));
@@ -1958,6 +1956,4 @@ int do_init_chrif(void) {
 
 	// send the user count every 10 seconds, to hide the charserver's online counting problem
 	add_timer_interval(gettick() + 1000, send_usercount_tochar, 0, 0, UPDATE_INTERVAL);
-
-	return 0;
 }

+ 2 - 2
src/map/chrif.h

@@ -76,8 +76,8 @@ int chrif_bsdata_request(int char_id);
 int chrif_save_bsdata(struct map_session_data *sd);
 int chrif_load_bsdata(int fd);
 
-int do_final_chrif(void);
-int do_init_chrif(void);
+void do_final_chrif(void);
+void do_init_chrif(void);
 
 int chrif_flush_fifo(void);
 

+ 32 - 17
src/map/clif.c

@@ -1484,7 +1484,7 @@ void clif_send_homdata(struct map_session_data *sd, int state, int param)
 	int fd = sd->fd;
 
 	if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
-		merc_hom_calc_skilltree(sd->hd, 0);
+		hom_calc_skilltree(sd->hd, 0);
 
 	WFIFOHEAD(fd, packet_len(0x230));
 	WFIFOW(fd,0)=0x230;
@@ -1519,7 +1519,7 @@ int clif_homskillinfoblock(struct map_session_data *sd)
 			WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
 			WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
 			safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
-			WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
+			WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < hom_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
 			len+=37;
 		}
 	}
@@ -8629,7 +8629,7 @@ void clif_refresh(struct map_session_data *sd)
 	}
 	if (sd->vd.cloth_color)
 		clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
-	if(merc_is_hom_active(sd->hd))
+	if(hom_is_active(sd->hd))
 		clif_send_homdata(sd,SP_ACK,0);
 	if( sd->md ) {
 		clif_mercenary_info(sd);
@@ -9565,7 +9565,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 	}
 
 	//homunculus [blackhole89]
-	if( merc_is_hom_active(sd->hd) ) {
+	if( hom_is_active(sd->hd) ) {
 		if(map_addblock(&sd->hd->bl))
 			return;
 		clif_spawn(&sd->hd->bl);
@@ -9632,8 +9632,8 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 		if(sd->pd && sd->pd->pet.intimate > 900)
 			clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
 
-		if(merc_is_hom_active(sd->hd))
-			merc_hom_init_timers(sd->hd);
+		if(hom_is_active(sd->hd))
+			hom_init_timers(sd->hd);
 
 		if (night_flag && map[sd->bl.m].flag.nightenabled) {
 			sd->state.night = 1;
@@ -11107,7 +11107,7 @@ static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_sess
 	else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
 		return;
 
-	lv = merc_hom_checkskill(hd, skill_id);
+	lv = hom_checkskill(hd, skill_id);
 	if( skill_lv > lv )
 		skill_lv = lv;
 	if( skill_lv )
@@ -11128,7 +11128,7 @@ static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_ses
 
 	if( hd->sc.data[SC_BASILICA] )
 		return;
-	lv = merc_hom_checkskill(hd, skill_id);
+	lv = hom_checkskill(hd, skill_id);
 	if( skill_lv > lv )
 		skill_lv = lv;
 	if( skill_lv )
@@ -13864,7 +13864,7 @@ void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
 /// Request to change homunculus' name (CZ_RENAME_MER).
 /// 0231 <name>.24B
 void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
-	merc_hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
+	hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
 }
 
 
@@ -13877,7 +13877,7 @@ void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
 
 	if( sd->md && sd->md->bl.id == id )
 		bl = &sd->md->bl;
-	else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
+	else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
 		bl = &sd->hd->bl; // Moving Homunculus
 	else
 		return;
@@ -13900,7 +13900,7 @@ void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
 
 	if( sd->md && sd->md->bl.id == id )
 		bl = &sd->md->bl; // Moving Mercenary
-	else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
+	else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
 		bl = &sd->hd->bl; // Moving Homunculus
 	else
 		return;
@@ -13921,7 +13921,7 @@ void clif_parse_HomAttack(int fd,struct map_session_data *sd)
 	int target_id = RFIFOL(fd,info->pos[1]);
 	int action_type = RFIFOB(fd,info->pos[2]);
 
-	if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
+	if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
 		bl = &sd->hd->bl;
 	else if( sd->md && sd->md->bl.id == id )
 		bl = &sd->md->bl;
@@ -13944,10 +13944,10 @@ void clif_parse_HomMenu(int fd, struct map_session_data *sd)
 {	//[orn]
 	int cmd = RFIFOW(fd,0);
 	//int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
-	if(!merc_is_hom_active(sd->hd))
+	if(!hom_is_active(sd->hd))
 		return;
 
-	merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
+	hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
 }
 
 
@@ -15493,7 +15493,7 @@ void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
 	if( sd->md == NULL )
 		return;
 
-	if( option == 2 ) merc_delete(sd->md, 2);
+	if( option == 2 ) mercenary_delete(sd->md, 2);
 }
 
 
@@ -17200,6 +17200,22 @@ void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
 	is_atcommand(fd, sd, cmd, 1);
 }
 
+/**
+* Marks Crimson Marker target on mini-map to the caster
+* TODO: Please, check the proper packet for Crimson Marker [Cydh]
+* @param fd
+* @param bl Crimson Marker target
+* @param remove True remove the marker from map, false therwise
+**/
+void clif_crimson_marker(int fd, struct block_list *bl, bool remove) {
+	WFIFOHEAD(fd,packet_len(0x107));
+	WFIFOW(fd,0) = 0x107;
+	WFIFOL(fd,2) = bl->id;
+	WFIFOW(fd,6) = (remove) ? -1 : bl->x;
+	WFIFOW(fd,8) = (remove) ? -1 : bl->y;
+	WFIFOSET(fd,packet_len(0x107));
+}
+
 ///TODO: Special item that obtained, must be broadcasted by this packet
 //void clif_broadcast_obtain_special_item() {}
 
@@ -18018,7 +18034,7 @@ void packetdb_readdb(void)
 /*==========================================
  *
  *------------------------------------------*/
-int do_init_clif(void) {
+void do_init_clif(void) {
 	const char* colors[COLOR_MAX] = {
 		"0xFF0000",
 		"0xFFFFFF",
@@ -18048,7 +18064,6 @@ int do_init_clif(void) {
 	add_timer_func_list(clif_delayquit, "clif_delayquit");
 
 	delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
-	return 0;
 }
 
 void do_final_clif(void) {

+ 3 - 1
src/map/clif.h

@@ -699,7 +699,7 @@ void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, s
 void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest);
 
 int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type);
-int do_init_clif(void);
+void do_init_clif(void);
 void do_final_clif(void);
 
 // MAIL SYSTEM
@@ -838,6 +838,8 @@ void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char
 void clif_ranklist(struct map_session_data *sd, int16 rankingType);
 void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point);
 
+void clif_crimson_marker(int fd, struct block_list *bl, bool remove);
+
 //void clif_broadcast_obtain_special_item(); ///TODO!
 
 #endif /* _CLIF_H_ */

+ 105 - 146
src/map/elemental.c

@@ -39,11 +39,12 @@
 #include <math.h>
 
 struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database
+static uint16 elemental_count;
 
 int elemental_search_index(int class_) {
 	int i;
-	ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental_db[i].class_ == class_);
-	return (i == MAX_ELEMENTAL_CLASS)?-1:i;
+	ARR_FIND(0, elemental_count, i, elemental_db[i].class_ == class_);
+	return (i == elemental_count)?-1:i;
 }
 
 bool elemental_class(int class_) {
@@ -764,166 +765,126 @@ static int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data)
 	return 0;
 }
 
-int read_elementaldb(void) {
-	FILE *fp;
-	char line[1024], *p;
-	char *str[26];
-	int i, j = 0, k = 0, ele;
+/**
+* Reads Elemental DB lines
+* ID,Sprite_Name,Name,LV,HP,SP,Range1,ATK1,ATK2,DEF,MDEF,STR,AGI,VIT,INT,DEX,LUK,Range2,Range3,Scale,Race,Element,Speed,aDelay,aMotion,dMotion
+*/
+static bool read_elementaldb_sub(char* str[], int columns, int current) {
+	uint16 class_ = atoi(str[0]), i, ele;
 	struct s_elemental_db *db;
 	struct status_data *status;
 
-	sprintf(line, "%s/%s", db_path, "elemental_db.txt");
-	memset(elemental_db,0,sizeof(elemental_db));
-
-	fp = fopen(line, "r");
-	if( !fp ) {
-		ShowError("read_elementaldb: Can't read elemental_db.txt\n");
-		return -1;
+	//Find the ID, already exist or not in elemental_db
+	ARR_FIND(0,elemental_count,i,elemental_db[i].class_ == class_);
+	if (i >= elemental_count)
+		db = &elemental_db[elemental_count];
+	else
+		db = &elemental_db[i];
+	
+	db->class_ = atoi(str[0]);
+	safestrncpy(db->sprite, str[1], NAME_LENGTH);
+	safestrncpy(db->name, str[2], NAME_LENGTH);
+	db->lv = atoi(str[3]);
+
+	status = &db->status;
+	db->vd.class_ = db->class_;
+
+	status->max_hp = atoi(str[4]);
+	status->max_sp = atoi(str[5]);
+	status->rhw.range = atoi(str[6]);
+	status->rhw.atk = atoi(str[7]);
+	status->rhw.atk2 = atoi(str[8]);
+	status->def = atoi(str[9]);
+	status->mdef = atoi(str[10]);
+	status->str = atoi(str[11]);
+	status->agi = atoi(str[12]);
+	status->vit = atoi(str[13]);
+	status->int_ = atoi(str[14]);
+	status->dex = atoi(str[15]);
+	status->luk = atoi(str[16]);
+	db->range2 = atoi(str[17]);
+	db->range3 = atoi(str[18]);
+	status->size = atoi(str[19]);
+	status->race = atoi(str[20]);
+
+	ele = atoi(str[21]);
+	status->def_ele = ele%10;
+	status->ele_lv = ele/20;
+	if( status->def_ele >= ELE_ALL ) {
+		ShowWarning("read_elementaldb_sub: Elemental %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_ALL - 1);
+		status->def_ele = ELE_NEUTRAL;
+	}
+	if( status->ele_lv < 1 || status->ele_lv > 4 ) {
+		ShowWarning("read_elementaldb_sub: Elemental %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
+		status->ele_lv = 1;
 	}
 
-	while( fgets(line, sizeof(line), fp) && j < MAX_ELEMENTAL_CLASS ) {
-		k++;
-		if( line[0] == '/' && line[1] == '/' )
-			continue;
-
-		if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
-			continue;
-
-		i = 0;
-		p = strtok(line, ",");
-		while( p != NULL && i < 26 ) {
-			str[i++] = p;
-			p = strtok(NULL, ",");
-		}
-		if( i < 26 ) {
-			ShowError("read_elementaldb: Incorrect number of columns at elemental_db.txt line %d.\n", k);
-			continue;
-		}
+	status->aspd_rate = 1000;
+	status->speed = atoi(str[22]);
+	status->adelay = atoi(str[23]);
+	status->amotion = atoi(str[24]);
+	status->dmotion = atoi(str[25]);
 
-		db = &elemental_db[j];
-		db->class_ = atoi(str[0]);
-		safestrncpy(db->sprite, str[1], NAME_LENGTH);
-		safestrncpy(db->name, str[2], NAME_LENGTH);
-		db->lv = atoi(str[3]);
-
-		status = &db->status;
-		db->vd.class_ = db->class_;
-
-		status->max_hp = atoi(str[4]);
-		status->max_sp = atoi(str[5]);
-		status->rhw.range = atoi(str[6]);
-		status->rhw.atk = atoi(str[7]);
-		status->rhw.atk2 = atoi(str[8]);
-		status->def = atoi(str[9]);
-		status->mdef = atoi(str[10]);
-		status->str = atoi(str[11]);
-		status->agi = atoi(str[12]);
-		status->vit = atoi(str[13]);
-		status->int_ = atoi(str[14]);
-		status->dex = atoi(str[15]);
-		status->luk = atoi(str[16]);
-		db->range2 = atoi(str[17]);
-		db->range3 = atoi(str[18]);
-		status->size = atoi(str[19]);
-		status->race = atoi(str[20]);
-
-		ele = atoi(str[21]);
-		status->def_ele = ele%10;
-		status->ele_lv = ele/20;
-		if( status->def_ele >= ELE_ALL ) {
-			ShowWarning("Elemental %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_ALL - 1);
-			status->def_ele = ELE_NEUTRAL;
-		}
-		if( status->ele_lv < 1 || status->ele_lv > 4 ) {
-			ShowWarning("Elemental %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
-			status->ele_lv = 1;
-		}
+	if (i >= elemental_count)
+		elemental_count++;
+	return true;
+}
 
-		status->aspd_rate = 1000;
-		status->speed = atoi(str[22]);
-		status->adelay = atoi(str[23]);
-		status->amotion = atoi(str[24]);
-		status->dmotion = atoi(str[25]);
+void read_elementaldb(void) {
+	const char *filename[] = { "elemental_db.txt", DBIMPORT"/elemental_db.txt" };
+	uint8 i;
 
-		j++;
+	elemental_count = 0;
+	for(i = 0; i<ARRAYLENGTH(filename); i++){
+		sv_readdb(db_path, filename[i], ',', 26, 26, -1, &read_elementaldb_sub, i);
 	}
-
-	fclose(fp);
-	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' elementals in '"CL_WHITE"db/elemental_db.txt"CL_RESET"'.\n",j);
-
-	return 0;
 }
 
-int read_elemental_skilldb(void) {
-	FILE *fp;
-	char line[1024], *p;
-	char *str[4];
+/**
+* Reads Elemental Skill DB lines
+* ElementalID,SkillID,SkillLevel,ReqMode
+*/
+static bool read_elemental_skilldb_sub(char* str[], int columns, int current) {
+	uint16 class_ = atoi(str[0]), i, skill_id, skill_lv, skillmode;
 	struct s_elemental_db *db;
-	int i, j = 0, k = 0, class_;
-	uint16 skill_id, skill_lv;
-	int skillmode;
 
-	sprintf(line, "%s/%s", db_path, "elemental_skill_db.txt");
-	fp = fopen(line, "r");
-	if( !fp ) {
-		ShowError("read_elemental_skilldb: Can't read elemental_skill_db.txt\n");
-		return -1;
+	ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental_db[i].class_);
+	if( i == MAX_ELEMENTAL_CLASS ) {
+		ShowError("read_elemental_skilldb_sub: Class not found in elemental_db for skill entry, line %d.\n", current);
+		return false;
 	}
 
-	while( fgets(line, sizeof(line), fp) ) {
-		k++;
-		if( line[0] == '/' && line[1] == '/' )
-			continue;
-
-		if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
-			continue;
-
-		i = 0;
-		p = strtok(line, ",");
-		while( p != NULL && i < 4 ) {
-			str[i++] = p;
-			p = strtok(NULL, ",");
-		}
-		if( i < 4 ) {
-			ShowError("read_elemental_skilldb: Incorrect number of columns at elemental_skill_db.txt line %d.\n", k);
-			continue;
-		}
-
-		class_ = atoi(str[0]);
-		ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental_db[i].class_);
-		if( i == MAX_ELEMENTAL_CLASS ) {
-			ShowError("read_elemental_skilldb: Class not found in elemental_db for skill entry, line %d.\n", k);
-			continue;
-		}
-
-		skill_id = atoi(str[1]);
-		if( skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL ) {
-			ShowError("read_elemental_skilldb: Skill out of range, line %d.\n", k);
-			continue;
-		}
+	skill_id = atoi(str[1]);
+	if( skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL ) {
+		ShowError("read_elemental_skilldb_sub: Skill out of range, line %d.\n", current);
+		return false;
+	}
 
-		db = &elemental_db[i];
-		skill_lv = atoi(str[2]);
+	db = &elemental_db[i];
+	skill_lv = atoi(str[2]);
 
-		skillmode = atoi(str[3]);
-		if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
-			ShowError("read_elemental_skilldb: Skillmode out of range, line %d.\n",k);
-			continue;
-		}
-		ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id );
-		if( i == MAX_ELESKILLTREE ) {
-			ShowWarning("Unable to load skill %d into Elemental %d's tree. Maximum number of skills per elemental has been reached.\n", skill_id, class_);
-			continue;
-		}
-		db->skill[i].id = skill_id;
-		db->skill[i].lv = skill_lv;
-		db->skill[i].mode = skillmode;
-		j++;
+	skillmode = atoi(str[3]);
+	if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
+		ShowError("read_elemental_skilldb_sub: Skillmode out of range, line %d.\n",current);
+		return false;
 	}
+	ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id );
+	if( i == MAX_ELESKILLTREE ) {
+		ShowWarning("read_elemental_skilldb_sub: Unable to load skill %d into Elemental %d's tree. Maximum number of skills per elemental has been reached.\n", skill_id, class_);
+		return false;
+	}
+	db->skill[i].id = skill_id;
+	db->skill[i].lv = skill_lv;
+	db->skill[i].mode = skillmode;
+	return true;
+}
 
-	fclose(fp);
-	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/elemental_skill_db.txt"CL_RESET"'.\n",j);
-	return 0;
+void read_elemental_skilldb(void) {
+	const char *filename[] = { "elemental_skill_db.txt", DBIMPORT"/elemental_skill_db.txt" };
+	uint8 i;
+	for(i = 0; i<ARRAYLENGTH(filename); i++){
+		sv_readdb(db_path, filename[i], ',', 4, 4, -1, &read_elemental_skilldb_sub, i);
+	}
 }
 
 void reload_elementaldb(void) {
@@ -935,14 +896,12 @@ void reload_elemental_skilldb(void) {
 	read_elemental_skilldb();
 }
 
-int do_init_elemental(void) {
+void do_init_elemental(void) {
 	read_elementaldb();
 	read_elemental_skilldb();
 
 	add_timer_func_list(elemental_ai_timer,"elemental_ai_timer");
 	add_timer_interval(gettick()+MIN_ELETHINKTIME,elemental_ai_timer,0,0,MIN_ELETHINKTIME);
-
-	return 0;
 }
 
 void do_final_elemental(void) {

+ 2 - 2
src/map/elemental.h

@@ -102,10 +102,10 @@ struct skill_condition elemental_skill_get_requirements(uint16 skill_id, uint16
 #define elemental_stop_walking(ed, type) unit_stop_walking(&(ed)->bl, type)
 #define elemental_stop_attack(ed) unit_stop_attack(&(ed)->bl)
 
-int read_elemental_skilldb(void);
+void read_elemental_skilldb(void);
 void reload_elementaldb(void);
 void reload_elemental_skilldb(void);
-int do_init_elemental(void);
+void do_init_elemental(void);
 void do_final_elemental(void);
 
 #endif /* _ELEMENTAL_H_ */

+ 106 - 102
src/map/homunculus.c

@@ -42,14 +42,14 @@
 struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS];	//[orn]
 struct homun_skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE];
 
-static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr_t data);
-
+static int hom_hungry(int tid, unsigned int tick, int id, intptr_t data);
+static uint16 homunculus_count;
 static unsigned int hexptbl[MAX_LEVEL];
 
 //For holding the view data of npc classes. [Skotlex]
 static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS];
 
-struct view_data* merc_get_hom_viewdata(int class_)
+struct view_data* hom_get_viewdata(int class_)
 {	//Returns the viewdata for homunculus
 	if (homdb_checkid(class_))
 		return &hom_viewdb[class_-HM_CLASS_BASE];
@@ -133,11 +133,11 @@ int hom_delspiritball(TBL_HOM *hd, int count, int type) {
     return 0;
 }
 
-void merc_damage(struct homun_data *hd) {
+void hom_damage(struct homun_data *hd) {
 	clif_hominfo(hd->master,hd,0);
 }
 
-int merc_hom_dead(struct homun_data *hd)
+int hom_dead(struct homun_data *hd)
 {
 	//There's no intimacy penalties on death (from Tharis)
 	struct map_session_data *sd = hd->master;
@@ -145,7 +145,7 @@ int merc_hom_dead(struct homun_data *hd)
 	clif_emotion(&hd->bl, E_WAH);
 
 	//Delete timers when dead.
-	merc_hom_hungry_timer_delete(hd);
+	hom_hungry_timer_delete(hd);
 	hd->homunculus.hp = 0;
 
 	if (!sd) //unit remove map will invoke unit free
@@ -157,7 +157,7 @@ int merc_hom_dead(struct homun_data *hd)
 }
 
 //Vaporize a character's homun. If flag == 1 then HP needs to be 80% or above, if flag == 2 then set to morph state.
-int merc_hom_vaporize(struct map_session_data *sd, int flag)
+int hom_vaporize(struct map_session_data *sd, int flag)
 {
 	struct homun_data *hd;
 
@@ -175,18 +175,18 @@ int merc_hom_vaporize(struct map_session_data *sd, int flag)
 
 	hd->regen.state.block = 3; //Block regen while vaporized.
 	//Delete timers when vaporized.
-	merc_hom_hungry_timer_delete(hd);
+	hom_hungry_timer_delete(hd);
 	hd->homunculus.vaporize = flag ? flag : HOM_ST_REST;
 	if(battle_config.hom_setting&0x40)
 		memset(hd->blockskill, 0, sizeof(hd->blockskill));
 	clif_hominfo(sd, sd->hd, 0);
-	merc_save(hd);
+	hom_save(hd);
 	return unit_remove_map(&hd->bl, CLR_OUTSIGHT);
 }
 
 //delete a homunculus, completely "killing it".
 //Emote is the emotion the master should use, send negative to disable.
-int merc_hom_delete(struct homun_data *hd, int emote)
+int hom_delete(struct homun_data *hd, int emote)
 {
 	struct map_session_data *sd;
 	nullpo_ret(hd);
@@ -206,7 +206,7 @@ int merc_hom_delete(struct homun_data *hd, int emote)
 	return unit_remove_map(&hd->bl,CLR_OUTSIGHT);
 }
 
-int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
+int hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
 {
 	int i, id = 0;
 	int j, f = 1;
@@ -223,7 +223,7 @@ int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
 			if(!battle_config.skillfree) {
 				for( j = 0; j < MAX_PC_SKILL_REQUIRE; j++ ) {
 					if( hskill_tree[c][i].need[j].id &&
-					   merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv ) {
+					   hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv ) {
 						f = 0;
 						break;
 					}
@@ -247,7 +247,7 @@ int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
 		if(!battle_config.skillfree) {
 			for( j = 0; j < MAX_PC_SKILL_REQUIRE; j++ ) {
 				if( hskill_tree[c][i].need[j].id &&
-					merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv ) {
+					hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv ) {
 					f = 0;
 					break;
 				}
@@ -262,7 +262,7 @@ int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
 	return 0;
 }
 
-int merc_hom_checkskill(struct homun_data *hd,uint16 skill_id)
+int hom_checkskill(struct homun_data *hd,uint16 skill_id)
 {
 	int i = skill_id - HM_SKILLBASE;
 	if(!hd || !&hd->homunculus)
@@ -274,7 +274,7 @@ int merc_hom_checkskill(struct homun_data *hd,uint16 skill_id)
 	return 0;
 }
 
-int merc_skill_tree_get_max(int id, int b_class){
+int hom_skill_tree_get_max(int id, int b_class){
 	int i, skill_id;
 	b_class -= HM_CLASS_BASE;
 	for(i=0;(skill_id=hskill_tree[b_class][i].id)>0;i++)
@@ -283,7 +283,7 @@ int merc_skill_tree_get_max(int id, int b_class){
 	return skill_get_max(id);
 }
 
-void merc_hom_skillup(struct homun_data *hd,uint16 skill_id)
+void hom_skillup(struct homun_data *hd,uint16 skill_id)
 {
 	int i = 0 ;
 	nullpo_retv(hd);
@@ -295,7 +295,7 @@ void merc_hom_skillup(struct homun_data *hd,uint16 skill_id)
 	if(hd->homunculus.skillpts > 0 &&
 		hd->homunculus.hskill[i].id &&
 		hd->homunculus.hskill[i].flag == SKILL_FLAG_PERMANENT && //Don't allow raising while you have granted skills. [Skotlex]
-		hd->homunculus.hskill[i].lv < merc_skill_tree_get_max(skill_id, hd->homunculus.class_)
+		hd->homunculus.hskill[i].lv < hom_skill_tree_get_max(skill_id, hd->homunculus.class_)
 		)
 	{
 		hd->homunculus.hskill[i].lv++;
@@ -309,7 +309,7 @@ void merc_hom_skillup(struct homun_data *hd,uint16 skill_id)
 	}
 }
 
-int merc_hom_levelup(struct homun_data *hd)
+int hom_levelup(struct homun_data *hd)
 {
 	struct s_homunculus *hom;
 	struct h_stats *min = NULL, *max = NULL;
@@ -318,7 +318,7 @@ int merc_hom_levelup(struct homun_data *hd)
 	int m_class;
 
 	if((m_class = hom_class2mapid(hd->homunculus.class_)) == -1) {
-		ShowError("merc_hom_levelup: Invalid class %d. \n", hd->homunculus.class_);
+		ShowError("hom_levelup: Invalid class %d. \n", hd->homunculus.class_);
 		return 0;
 	}
 
@@ -330,7 +330,7 @@ int merc_hom_levelup(struct homun_data *hd)
 			hd->homunculus.prev_class = 6001;
 		}
 		// Give the homunculus the level up stats database it needs
-		i = search_homunculusDB_index(hd->homunculus.prev_class,HOMUNCULUS_CLASS);
+		i = hom_search(hd->homunculus.prev_class,HOMUNCULUS_CLASS);
 		if(i < 0) // Nothing should go wrong here, but check anyways
 			return 0;
 		max = &homunculus_db[i].gmax;
@@ -390,20 +390,19 @@ int merc_hom_levelup(struct homun_data *hd)
 			growth_int/10.0, growth_dex/10.0, growth_luk/10.0);
 		clif_disp_onlyself(hd->master,output,strlen(output));
 	}
-	return 1 ;
+	return 1;
 }
 
-int merc_hom_change_class(struct homun_data *hd, short class_)
-{
+static bool hom_change_class(struct homun_data *hd, short class_) {
 	int i;
-	i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS);
+	i = hom_search(class_,HOMUNCULUS_CLASS);
 	if(i < 0)
-		return 0;
+		return false;
 	hd->homunculusDB = &homunculus_db[i];
 	hd->homunculus.class_ = class_;
 	status_set_viewdata(&hd->bl, class_);
-	merc_hom_calc_skilltree(hd, 1);
-	return 1;
+	hom_calc_skilltree(hd, 1);
+	return true;
 }
 
 /**
@@ -411,7 +410,7 @@ int merc_hom_change_class(struct homun_data *hd, short class_)
  * @param hd : homonculus datas
  * @return 0:failure, 1:success
  */
-int merc_hom_evolution(struct homun_data *hd)
+int hom_evolution(struct homun_data *hd)
 {
 	struct s_homunculus *hom;
 	struct h_stats *max, *min;
@@ -427,8 +426,8 @@ int merc_hom_evolution(struct homun_data *hd)
 	if (!sd)
 		return 0;
 
-	if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class)) {
-		ShowError("merc_hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class);
+	if (!hom_change_class(hd, hd->homunculusDB->evo_class)) {
+		ShowError("hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class);
 		return 0;
 	}
 
@@ -492,7 +491,7 @@ int hom_mutate(struct homun_data *hd, int homun_id)
 
 	prev_class = hd->homunculus.class_;
 
-	if (!merc_hom_change_class(hd, homun_id)) {
+	if (!hom_change_class(hd, homun_id)) {
 		ShowError("hom_mutate: Can't evolve homunc from %d to %d", hd->homunculus.class_, homun_id);
 		return 0;
 	}
@@ -519,7 +518,7 @@ int hom_mutate(struct homun_data *hd, int homun_id)
 	return 1;
 }
 
-int merc_hom_gainexp(struct homun_data *hd,int exp)
+int hom_gainexp(struct homun_data *hd,int exp)
 {
 	int m_class;
 
@@ -527,7 +526,7 @@ int merc_hom_gainexp(struct homun_data *hd,int exp)
 		return 1;
 
 	if((m_class = hom_class2mapid(hd->homunculus.class_)) == -1) {
-		ShowError("merc_hom_gainexp: Invalid class %d. \n", hd->homunculus.class_);
+		ShowError("hom_gainexp: Invalid class %d. \n", hd->homunculus.class_);
 		return 0;
 	}
 
@@ -548,7 +547,7 @@ int merc_hom_gainexp(struct homun_data *hd,int exp)
  	// Do the levelup(s)
 	while( hd->homunculus.exp > hd->exp_next ){
 		// Max level reached or error
-		if( !merc_hom_levelup(hd) ){
+		if( !hom_levelup(hd) ){
 			break;
 		}
 	}
@@ -563,7 +562,7 @@ int merc_hom_gainexp(struct homun_data *hd,int exp)
 }
 
 // Return the new value
-int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value)
+int hom_increase_intimacy(struct homun_data * hd, unsigned int value)
 {
 	if (battle_config.homunculus_friendly_rate != 100)
 		value = (value * battle_config.homunculus_friendly_rate) / 100;
@@ -576,7 +575,7 @@ int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value)
 }
 
 // Return 0 if decrease fails or intimacy became 0 else the new value
-int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value)
+int hom_decrease_intimacy(struct homun_data * hd, unsigned int value)
 {
 	if (hd->homunculus.intimacy >= value)
 		hd->homunculus.intimacy -= value;
@@ -586,11 +585,11 @@ int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value)
 	return hd->homunculus.intimacy;
 }
 
-void merc_hom_heal(struct homun_data *hd) {
+void hom_heal(struct homun_data *hd) {
 	clif_hominfo(hd->master,hd,0);
 }
 
-void merc_save(struct homun_data *hd)
+void hom_save(struct homun_data *hd)
 {
 	// copy data that must be saved in homunculus struct ( hp / sp )
 	TBL_PC * sd = hd->master;
@@ -602,7 +601,7 @@ void merc_save(struct homun_data *hd)
 	intif_homunculus_requestsave(sd->status.account_id, &hd->homunculus);
 }
 
-int merc_menu(struct map_session_data *sd,int menunum)
+int hom_menu(struct map_session_data *sd,int menunum)
 {
 	nullpo_ret(sd);
 	if (sd->hd == NULL)
@@ -612,19 +611,19 @@ int merc_menu(struct map_session_data *sd,int menunum)
 		case 0:
 			break;
 		case 1:
-			merc_hom_food(sd, sd->hd);
+			hom_food(sd, sd->hd);
 			break;
 		case 2:
-			merc_hom_delete(sd->hd, -1);
+			hom_delete(sd->hd, -1);
 			break;
 		default:
-			ShowError("merc_menu : unknown menu choice : %d\n", menunum) ;
+			ShowError("hom_menu : unknown menu choice : %d\n", menunum) ;
 			break;
 	}
 	return 0;
 }
 
-int merc_hom_food(struct map_session_data *sd, struct homun_data *hd)
+int hom_food(struct map_session_data *sd, struct homun_data *hd)
 {
 	int i, foodID, emotion;
 
@@ -640,19 +639,19 @@ int merc_hom_food(struct map_session_data *sd, struct homun_data *hd)
 	pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME);
 
 	if ( hd->homunculus.hunger >= 91 ) {
-		merc_hom_decrease_intimacy(hd, 50);
+		hom_decrease_intimacy(hd, 50);
 		emotion = E_WAH;
 	} else if ( hd->homunculus.hunger >= 76 ) {
-		merc_hom_decrease_intimacy(hd, 5);
+		hom_decrease_intimacy(hd, 5);
 		emotion = E_SWT2;
 	} else if ( hd->homunculus.hunger >= 26 ) {
-		merc_hom_increase_intimacy(hd, 75);
+		hom_increase_intimacy(hd, 75);
 		emotion = E_HO;
 	} else if ( hd->homunculus.hunger >= 11 ) {
-		merc_hom_increase_intimacy(hd, 100);
+		hom_increase_intimacy(hd, 100);
 		emotion = E_HO;
 	} else {
-		merc_hom_increase_intimacy(hd, 50);
+		hom_increase_intimacy(hd, 50);
 		emotion = E_HO;
 	}
 
@@ -667,12 +666,12 @@ int merc_hom_food(struct map_session_data *sd, struct homun_data *hd)
 
 	// Too much food :/
 	if(hd->homunculus.intimacy == 0)
-		return merc_hom_delete(sd->hd, E_OMG);
+		return hom_delete(sd->hd, E_OMG);
 
 	return 0;
 }
 
-static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr_t data)
+static int hom_hungry(int tid, unsigned int tick, int id, intptr_t data)
 {
 	struct map_session_data *sd;
 	struct homun_data *hd;
@@ -685,7 +684,7 @@ static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr_t data)
 		return 1;
 
 	if(hd->hungry_timer != tid){
-		ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid);
+		ShowError("hom_hungry_timer %d != %d\n",hd->hungry_timer,tid);
 		return 0;
 	}
 
@@ -703,34 +702,34 @@ static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr_t data)
 	if(hd->homunculus.hunger < 0) {
 		hd->homunculus.hunger = 0;
 		// Delete the homunculus if intimacy <= 100
-		if ( !merc_hom_decrease_intimacy(hd, 100) )
-			return merc_hom_delete(hd, E_OMG);
+		if ( !hom_decrease_intimacy(hd, 100) )
+			return hom_delete(hd, E_OMG);
 		clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100);
 	}
 
 	clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger);
-	hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,merc_hom_hungry,sd->bl.id,0); //simple Fix albator
+	hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,hom_hungry,sd->bl.id,0); //simple Fix albator
 	return 0;
 }
 
-int merc_hom_hungry_timer_delete(struct homun_data *hd)
+int hom_hungry_timer_delete(struct homun_data *hd)
 {
 	nullpo_ret(hd);
 	if(hd->hungry_timer != INVALID_TIMER) {
-		delete_timer(hd->hungry_timer,merc_hom_hungry);
+		delete_timer(hd->hungry_timer,hom_hungry);
 		hd->hungry_timer = INVALID_TIMER;
 	}
 	return 1;
 }
 
-int merc_hom_change_name(struct map_session_data *sd,char *name)
+int hom_change_name(struct map_session_data *sd,char *name)
 {
 	int i;
 	struct homun_data *hd;
 	nullpo_retr(1, sd);
 
 	hd = sd->hd;
-	if (!merc_is_hom_active(hd))
+	if (!hom_is_active(hd))
 		return 1;
 	if(hd->homunculus.rename_flag && !battle_config.hom_rename)
 		return 1;
@@ -743,10 +742,10 @@ int merc_hom_change_name(struct map_session_data *sd,char *name)
 	return intif_rename_hom(sd, name);
 }
 
-int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag)
+int hom_change_name_ack(struct map_session_data *sd, char* name, int flag)
 {
 	struct homun_data *hd = sd->hd;
-	if (!merc_is_hom_active(hd)) return 0;
+	if (!hom_is_active(hd)) return 0;
 
 	normalize_name(name," ");//bugreport:3032
 
@@ -761,11 +760,11 @@ int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag)
 	return 1;
 }
 
-int search_homunculusDB_index(int key,int type)
+int hom_search(int key,int type)
 {
 	int i;
 
-	for(i=0;i<MAX_HOMUNCULUS_CLASS;i++) {
+	for(i=0;i<homunculus_count;i++) {
 		if(homunculus_db[i].base_class <= 0)
 			continue;
 		switch(type) {
@@ -786,21 +785,20 @@ int search_homunculusDB_index(int key,int type)
 }
 
 // Create homunc structure
-int merc_hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
-{
+void hom_alloc(struct map_session_data *sd, struct s_homunculus *hom) {
 	struct homun_data *hd;
 	int i = 0;
 
-	nullpo_retr(1, sd);
+	nullpo_retv(sd);
 
 	Assert((sd->status.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd);
 
-	i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS);
+	i = hom_search(hom->class_,HOMUNCULUS_CLASS);
 	if(i < 0) {
-		ShowError("merc_hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name);
+		ShowError("hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name);
 		sd->status.hom_id = 0;
 		intif_homunculus_requestdelete(hom->hom_id);
-		return 1;
+		return;
 	}
 	sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data));
 	hd->bl.type = BL_HOM;
@@ -829,13 +827,12 @@ int merc_hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
 
 	hd->hungry_timer = INVALID_TIMER;
 	hd->masterteleport_timer = INVALID_TIMER;
-	return 0;
 }
 
-void merc_hom_init_timers(struct homun_data * hd)
+void hom_init_timers(struct homun_data * hd)
 {
 	if (hd->hungry_timer == INVALID_TIMER)
-		hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0);
+		hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,hom_hungry,hd->master->bl.id,0);
 	hd->regen.state.block = 0; //Restore HP/SP block.
 	hd->masterteleport_timer = INVALID_TIMER;
 }
@@ -845,12 +842,12 @@ void merc_hom_init_timers(struct homun_data * hd)
  * @param sd
  * @return 0:failure, 1:sucess
  */
-int merc_call_homunculus(struct map_session_data *sd)
+int hom_call(struct map_session_data *sd)
 {
 	struct homun_data *hd;
 
 	if (!sd->status.hom_id) //Create a new homun.
-		return merc_create_homunculus_request(sd, HM_CLASS_BASE + rnd_value(0, 7)) ;
+		return hom_create_request(sd, HM_CLASS_BASE + rnd_value(0, 7)) ;
 
 	// If homunc not yet loaded, load it
 	if (!sd->hd)
@@ -864,7 +861,7 @@ int merc_call_homunculus(struct map_session_data *sd)
 	if (hd->homunculus.vaporize == HOM_ST_MORPH)
 		return 0; // Can't call homunculus (morph state).
 
-	merc_hom_init_timers(hd);
+	hom_init_timers(hd);
 	hd->homunculus.vaporize = HOM_ST_ACTIVE;
 	if (hd->bl.prev == NULL)
 	{	//Spawn him
@@ -880,7 +877,7 @@ int merc_call_homunculus(struct map_session_data *sd)
 		clif_homskillinfoblock(sd);
 		if (battle_config.slaves_inherit_speed&1)
 			status_calc_bl(&hd->bl, SCB_SPEED);
-		merc_save(hd);
+		hom_save(hd);
 	} else
 		//Warp him to master.
 		unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,CLR_OUTSIGHT);
@@ -894,7 +891,7 @@ int merc_call_homunculus(struct map_session_data *sd)
  * @param flag : does the creation in inter-serv was a success (0:no,1:yes)
  * @return 0:failure, 1:sucess
  */
-int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag)
+int hom_recv_data(int account_id, struct s_homunculus *sh, int flag)
 {
 	struct map_session_data *sd;
 	struct homun_data *hd;
@@ -919,7 +916,7 @@ int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag)
 	if (sd->hd) //uh? Overwrite the data.
 		memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus));
 	else
-		merc_hom_alloc(sd, sh);
+		hom_alloc(sd, sh);
 
 	hd = sd->hd;
 	if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL)
@@ -931,13 +928,13 @@ int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag)
 		clif_hominfo(sd,hd,1);
 		clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89]
 		clif_homskillinfoblock(sd);
-		merc_hom_init_timers(hd);
+		hom_init_timers(hd);
 	}
 	return 1;
 }
 
 // Ask homunculus creation to char server
-int merc_create_homunculus_request(struct map_session_data *sd, int class_)
+int hom_create_request(struct map_session_data *sd, int class_)
 {
 	struct s_homunculus homun;
 	struct h_stats *base;
@@ -945,7 +942,7 @@ int merc_create_homunculus_request(struct map_session_data *sd, int class_)
 
 	nullpo_retr(1, sd);
 
-	i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS);
+	i = hom_search(class_,HOMUNCULUS_CLASS);
 	if(i < 0) return 0;
 
 	memset(&homun, 0, sizeof(struct s_homunculus));
@@ -981,7 +978,7 @@ int merc_create_homunculus_request(struct map_session_data *sd, int class_)
  * @param y : Y map coordinate
  * @return 0:failure, 1:success
  */
-int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y)
+int hom_ressurect(struct map_session_data* sd, unsigned char per, short x, short y)
 {
 	struct homun_data* hd;
 	nullpo_ret(sd);
@@ -1000,7 +997,7 @@ int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, sh
 	if (!status_isdead(&hd->bl))
 		return 0; // already alive
 
-	merc_hom_init_timers(hd);
+	hom_init_timers(hd);
 
 	if (!hd->bl.prev)
 	{	//Add it back to the map.
@@ -1014,7 +1011,7 @@ int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, sh
 	return status_revive(&hd->bl, per, 0);
 }
 
-void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp)
+void hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp)
 {
 	struct map_session_data *sd = hd->master;
 	hd->homunculus.hp = hd->battle_status.hp;
@@ -1028,7 +1025,7 @@ void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp)
 		sc_start(&hd->bl,&hd->bl, SC_STYLE_CHANGE, 100, MH_MD_FIGHTING, -1);
 }
 
-void merc_reset_stats(struct homun_data *hd)
+void hom_reset_stats(struct homun_data *hd)
 {	//Resets a homunc stats back to zero (but doesn't touches hunger or intimacy)
 	struct s_homunculus_db *db;
 	struct s_homunculus *hom;
@@ -1052,14 +1049,14 @@ void merc_reset_stats(struct homun_data *hd)
 	hd->homunculus.skillpts = 0;
 }
 
-int merc_hom_shuffle(struct homun_data *hd)
+int hom_shuffle(struct homun_data *hd)
 {
 	struct map_session_data *sd;
 	int lv, i, skillpts;
 	unsigned int exp;
 	struct s_skill b_skill[MAX_HOMUNSKILL];
 
-	if (!merc_is_hom_active(hd))
+	if (!hom_is_active(hd))
 		return 0;
 
 	sd = hd->master;
@@ -1068,12 +1065,12 @@ int merc_hom_shuffle(struct homun_data *hd)
 	memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill));
 	skillpts = hd->homunculus.skillpts;
 	//Reset values to level 1.
-	merc_reset_stats(hd);
+	hom_reset_stats(hd);
 	//Level it back up
 	for (i = 1; i < lv && hd->exp_next; i++){
 		hd->homunculus.exp += hd->exp_next;
 		// Should never happen, but who knows
-		if( !merc_hom_levelup(hd) ) {
+		if( !hom_levelup(hd) ) {
 			break;
 		}
 	}
@@ -1106,6 +1103,7 @@ int merc_hom_shuffle(struct homun_data *hd)
 static bool read_homunculusdb_sub(char* str[], int columns, int current)
 {
 	int classid;
+	uint16 i;
 	struct s_homunculus_db *db;
 
 	//Base Class,Evo Class
@@ -1115,7 +1113,14 @@ static bool read_homunculusdb_sub(char* str[], int columns, int current)
 		ShowError("read_homunculusdb : Invalid class %d\n", classid);
 		return false;
 	}
-	db = &homunculus_db[current];
+
+	//Find the ClassID, already exist or not in homunculus_db
+	ARR_FIND(0,homunculus_count,i,homunculus_db[i].base_class == classid);
+	if (i >= homunculus_count)
+		db = &homunculus_db[homunculus_count];
+	else
+		db = &homunculus_db[i];
+
 	db->base_class = classid;
 	classid = atoi(str[1]);
 	if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
@@ -1213,21 +1218,22 @@ static bool read_homunculusdb_sub(char* str[], int columns, int current)
 	if(db->emin.luk > db->emax.luk)
 		db->emin.luk = db->emax.luk;
 
+	if (i >= homunculus_count)
+		homunculus_count++;
 	return true;
 }
 
-int read_homunculusdb(void)
-{
-	int i;
+void read_homunculusdb(void) {
+	uint8 i;
 	const char *filename[] = {
 		DBPATH"homunculus_db.txt",
 		DBIMPORT"/homunculus_db.txt",
 	};
+	homunculus_count = 0;
 	memset(homunculus_db,0,sizeof(homunculus_db));
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
 		sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, &read_homunculusdb_sub, i);
 	}
-	return 0;
 }
 
 static bool read_homunculus_skilldb_sub(char* split[], int columns, int current)
@@ -1324,31 +1330,29 @@ void read_homunculus_expdb(void)
 	}
 }
 
-void merc_reload(void)
-{
+void hom_reload(void){
 	read_homunculusdb();
 	read_homunculus_expdb();
 }
 
-void merc_skill_reload(void)
-{
+void hom_reload_skill(void){
 	read_homunculus_skilldb();
 }
 
-int do_init_merc(void)
-{
+void do_init_homunculus(void){
 	int class_;
 	read_homunculusdb();
 	read_homunculus_expdb();
 	read_homunculus_skilldb();
 	// Add homunc timer function to timer func list [Toms]
-	add_timer_func_list(merc_hom_hungry, "merc_hom_hungry");
+	add_timer_func_list(hom_hungry, "hom_hungry");
 
 	//Stock view data for homuncs
 	memset(&hom_viewdb, 0, sizeof(hom_viewdb));
 	for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++)
 		hom_viewdb[class_].class_ = HM_CLASS_BASE+class_;
-	return 0;
 }
 
-int do_final_merc(void);
+void do_final_homunculus(void) {
+	//Nothing todo yet
+}

+ 37 - 35
src/map/homunculus.h

@@ -100,46 +100,48 @@ enum homun_type {
 #define homdb_checkid(id) (id >=  HM_CLASS_BASE && id <= HM_CLASS_MAX)
 
 // merc_is_hom_alive(struct homun_data *)
-#define merc_is_hom_active(x) (x && x->homunculus.vaporize == HOM_ST_ACTIVE && x->battle_status.hp > 0)
-int do_init_merc(void);
-int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag); //albator
-struct view_data* merc_get_hom_viewdata(int class_);
+#define hom_is_active(x) (x && x->homunculus.vaporize == HOM_ST_ACTIVE && x->battle_status.hp > 0)
+int hom_recv_data(int account_id, struct s_homunculus *sh, int flag); //albator
+struct view_data* hom_get_viewdata(int class_);
 int hom_class2mapid(int hom_class);
 enum homun_type hom_class2type(int class_);
-void merc_damage(struct homun_data *hd);
-int merc_hom_dead(struct homun_data *hd);
-void merc_hom_skillup(struct homun_data *hd,uint16 skill_id);
-int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve);
-int merc_hom_checkskill(struct homun_data *hd,uint16 skill_id);
-int merc_hom_gainexp(struct homun_data *hd,int exp);
-int merc_hom_levelup(struct homun_data *hd);
-int merc_hom_evolution(struct homun_data *hd);
+void hom_damage(struct homun_data *hd);
+int hom_dead(struct homun_data *hd);
+void hom_skillup(struct homun_data *hd,uint16 skill_id);
+int hom_calc_skilltree(struct homun_data *hd, int flag_evolve);
+int hom_checkskill(struct homun_data *hd,uint16 skill_id);
+int hom_gainexp(struct homun_data *hd,int exp);
+int hom_levelup(struct homun_data *hd);
+int hom_evolution(struct homun_data *hd);
 int hom_mutate(struct homun_data *hd,int homun_id);
-void merc_hom_heal(struct homun_data *hd);
-int merc_hom_vaporize(struct map_session_data *sd, int flag);
-int merc_resurrect_homunculus(struct map_session_data *sd, unsigned char per, short x, short y);
-void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp);
-void merc_reset_stats(struct homun_data *hd);
-int merc_hom_shuffle(struct homun_data *hd); // [Zephyrus]
-void merc_save(struct homun_data *hd);
-int merc_call_homunculus(struct map_session_data *sd);
-int merc_create_homunculus_request(struct map_session_data *sd, int class_);
-int search_homunculusDB_index(int key,int type);
-int merc_menu(struct map_session_data *sd,int menunum);
-int merc_hom_food(struct map_session_data *sd, struct homun_data *hd);
-int merc_hom_hungry_timer_delete(struct homun_data *hd);
-int merc_hom_change_name(struct map_session_data *sd,char *name);
-int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag);
-#define merc_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type)
-#define merc_stop_attack(hd) unit_stop_attack(&(hd)->bl)
-int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value);
-int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value);
-int merc_skill_tree_get_max(int id, int b_class);
-void merc_hom_init_timers(struct homun_data * hd);
-void merc_skill_reload(void);
-void merc_reload(void);
+void hom_heal(struct homun_data *hd);
+int hom_vaporize(struct map_session_data *sd, int flag);
+int hom_ressurect(struct map_session_data *sd, unsigned char per, short x, short y);
+void hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp);
+void hom_reset_stats(struct homun_data *hd);
+int hom_shuffle(struct homun_data *hd); // [Zephyrus]
+void hom_save(struct homun_data *hd);
+int hom_call(struct map_session_data *sd);
+int hom_create_request(struct map_session_data *sd, int class_);
+int hom_search(int key,int type);
+int hom_menu(struct map_session_data *sd,int menunum);
+int hom_food(struct map_session_data *sd, struct homun_data *hd);
+int hom_hungry_timer_delete(struct homun_data *hd);
+int hom_change_name(struct map_session_data *sd,char *name);
+int hom_change_name_ack(struct map_session_data *sd, char* name, int flag);
+#define hom_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type)
+#define hom_stop_attack(hd) unit_stop_attack(&(hd)->bl)
+int hom_increase_intimacy(struct homun_data * hd, unsigned int value);
+int hom_decrease_intimacy(struct homun_data * hd, unsigned int value);
+int hom_skill_tree_get_max(int id, int b_class);
+void hom_init_timers(struct homun_data * hd);
+void hom_reload_skill(void);
+void hom_reload(void);
 
 int hom_addspiritball(TBL_HOM *hd, int max);
 int hom_delspiritball(TBL_HOM *hd, int count, int type);
 
+void do_final_homunculus(void);
+void do_init_homunculus(void);
+
 #endif /* _HOMUNCULUS_H_ */

+ 4 - 4
src/map/intif.c

@@ -1349,7 +1349,7 @@ int intif_parse_ChangeNameOk(int fd)
 		pet_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
 		break;
 	case 2: //Hom
-		merc_hom_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
+		hom_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
 		break;
 	}
 	return 0;
@@ -1367,7 +1367,7 @@ int intif_parse_CreateHomunculus(int fd)
 			ShowError("intif: create homun data: data size error %d != %d\n",sizeof(struct s_homunculus),len);
 		return 0;
 	}
-	merc_hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
+	hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
 	return 0;
 }
 
@@ -1382,7 +1382,7 @@ int intif_parse_RecvHomunculusData(int fd)
 			ShowError("intif: homun data: data size error %d %d\n",sizeof(struct s_homunculus),len);
 		return 0;
 	}
-	merc_hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
+	hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
 	return 0;
 }
 
@@ -1985,7 +1985,7 @@ int intif_parse_mercenary_received(int fd)
 		return 0;
 	}
 
-	merc_data_received((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4));
+	mercenary_recv_data((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4));
 	return 0;
 }
 

+ 1 - 2
src/map/itemdb.c

@@ -1766,12 +1766,11 @@ void do_final_itemdb(void) {
 /**
 * Initializing Item DB
 */
-int do_init_itemdb(void) {
+void do_init_itemdb(void) {
 	memset(itemdb_array, 0, sizeof(itemdb_array));
 	itemdb_other = idb_alloc(DB_OPT_BASE);
 	itemdb_combo = idb_alloc(DB_OPT_BASE);
 	create_dummy_data(); //Dummy data item.
 	
 	itemdb_read();
-	return 0;
 }

+ 1 - 1
src/map/itemdb.h

@@ -484,6 +484,6 @@ DBMap * itemdb_get_combodb();
 void itemdb_reload(void);
 
 void do_final_itemdb(void);
-int do_init_itemdb(void);
+void do_init_itemdb(void);
 
 #endif /* _ITEMDB_H_ */

+ 3 - 1
src/map/map.c

@@ -3790,6 +3790,8 @@ void do_final(void)
 	do_final_party();
 	do_final_pc();
 	do_final_pet();
+	do_final_homunculus();
+	do_final_mercenary();
 	do_final_mob();
 	do_final_msg();
 	do_final_skill();
@@ -4101,7 +4103,7 @@ int do_init(int argc, char *argv[])
 	do_init_guild();
 	do_init_storage();
 	do_init_pet();
-	do_init_merc();
+	do_init_homunculus();
 	do_init_mercenary();
 	do_init_elemental();
 	do_init_quest();

+ 198 - 107
src/map/mercenary.c

@@ -39,37 +39,56 @@
 #include <math.h>
 
 struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; // Mercenary Database
+static uint16 mercenary_count;
 
-int merc_search_index(int class_)
-{
-	int i;
-	ARR_FIND(0, MAX_MERCENARY_CLASS, i, mercenary_db[i].class_ == class_);
-	return (i == MAX_MERCENARY_CLASS)?-1:i;
+/**
+* Search Mercenary by class
+* @param class_ Class ID of Mercenary
+* @return The index of mercenary on mercenary_db, or -1 if not found
+**/
+static int16 mercenary_search_index(int class_) {
+	int16 i;
+	ARR_FIND(0, mercenary_count, i, mercenary_db[i].class_ == class_);
+	return (i == mercenary_count)?-1:i;
 }
 
-bool merc_class(int class_)
-{
-	return (bool)(merc_search_index(class_) > -1);
+/**
+* Check if the Class ID is a Mercenary
+* @param class_ The Class ID
+* @return true if Class ID is a Mercenary, false otherwise
+**/
+bool mercenary_class(int class_){
+	return (bool)(mercenary_search_index(class_) > -1);
 }
 
-struct view_data * merc_get_viewdata(int class_)
-{
-	int i = merc_search_index(class_);
+/**
+* Get View Data of Mercenary by Class ID
+* @param class_ The Class ID
+* @return View Data of Mercenary
+**/
+struct view_data * mercenary_get_viewdata(int class_){
+	int i = mercenary_search_index(class_);
 	if( i < 0 )
 		return 0;
 
 	return &mercenary_db[i].vd;
 }
 
-int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
-{
+/**
+* Create a new Mercenary for Player
+* @param sd The Player
+* @param class_ Mercenary Class
+* @param lifetime Contract duration
+* @return false if failed, true otherwise
+**/
+bool mercenary_create(struct map_session_data *sd, int class_, unsigned int lifetime) {
 	struct s_mercenary merc;
 	struct s_mercenary_db *db;
-	int i;
-	nullpo_retr(0,sd);
+	int16 i;
+	nullpo_retr(false,sd);
 
-	if( (i = merc_search_index(class_)) < 0 )
-		return 0;
+	if( (i = mercenary_search_index(class_)) < 0 )
+		return false;
 
 	db = &mercenary_db[i];
 	memset(&merc,0,sizeof(struct s_mercenary));
@@ -83,11 +102,15 @@ int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
 	// Request Char Server to create this mercenary
 	intif_mercenary_create(&merc);
 
-	return 1;
+	return true;
 }
 
-int mercenary_get_lifetime(struct mercenary_data *md)
-{
+/**
+* Get current Mercenary lifetime
+* @param md The Mercenary
+* @return The Lifetime
+**/
+int mercenary_get_lifetime(struct mercenary_data *md) {
 	const struct TimerData * td;
 	if( md == NULL || md->contract_timer == INVALID_TIMER )
 		return 0;
@@ -96,9 +119,13 @@ int mercenary_get_lifetime(struct mercenary_data *md)
 	return (td != NULL) ? DIFF_TICK(td->tick, gettick()) : 0;
 }
 
-int mercenary_get_guild(struct mercenary_data *md)
-{
-	int class_;
+/**
+* Get Guild type of Mercenary
+* @param md Mercenary
+* @return -1 if not found, 0 - ARCH_MERC_GUILD, 1 - SPEAR_MERC_GUILD, or 2 - SWORD_MERC_GUILD
+**/
+int mercenary_get_guild(struct mercenary_data *md){
+	uint16 class_;
 
 	if( md == NULL || md->db == NULL )
 		return -1;
@@ -115,10 +142,14 @@ int mercenary_get_guild(struct mercenary_data *md)
 	return -1;
 }
 
-int mercenary_get_faith(struct mercenary_data *md)
-{
+/**
+* Get Faith value of Mercenary
+* @param md Mercenary
+* @return the Faith value
+**/
+int mercenary_get_faith(struct mercenary_data *md) {
 	struct map_session_data *sd;
-	int class_;
+	uint16 class_;
 
 	if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
 		return 0;
@@ -135,13 +166,18 @@ int mercenary_get_faith(struct mercenary_data *md)
 	return 0;
 }
 
-int mercenary_set_faith(struct mercenary_data *md, int value)
-{
+/**
+* Set faith value of Mercenary
+* @param md The Mercenary
+* @param value Faith Value
+**/
+void mercenary_set_faith(struct mercenary_data *md, int value) {
 	struct map_session_data *sd;
-	int class_, *faith;
+	uint16 class_;
+	int *faith;
 
 	if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
-		return 0;
+		return;
 
 	class_ = md->db->class_;
 
@@ -152,19 +188,21 @@ int mercenary_set_faith(struct mercenary_data *md, int value)
 	else if( class_ >= 6037 && class_ <= 6046 )
 		faith = &sd->status.sword_faith;
 	else
-		return 0;
+		return;
 
 	*faith += value;
 	*faith = cap_value(*faith, 0, SHRT_MAX);
 	clif_mercenary_updatestatus(sd, SP_MERCFAITH);
-
-	return 0;
 }
 
-int mercenary_get_calls(struct mercenary_data *md)
-{
+/**
+* Get Mercenary's calls
+* @param md Mercenary
+* @return Number of calls
+**/
+int mercenary_get_calls(struct mercenary_data *md) {
 	struct map_session_data *sd;
-	int class_;
+	uint16 class_;
 
 	if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
 		return 0;
@@ -181,13 +219,18 @@ int mercenary_get_calls(struct mercenary_data *md)
 	return 0;
 }
 
-int mercenary_set_calls(struct mercenary_data *md, int value)
-{
+/**
+* Set Mercenary's calls
+* @param md Mercenary
+* @param value
+**/
+void mercenary_set_calls(struct mercenary_data *md, int value) {
 	struct map_session_data *sd;
-	int class_, *calls;
+	uint16 class_;
+	int *calls;
 
 	if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
-		return 0;
+		return;
 
 	class_ = md->db->class_;
 
@@ -198,26 +241,28 @@ int mercenary_set_calls(struct mercenary_data *md, int value)
 	else if( class_ >= 6037 && class_ <= 6046 )
 		calls = &sd->status.sword_calls;
 	else
-		return 0;
+		return;
 
 	*calls += value;
 	*calls = cap_value(*calls, 0, INT_MAX);
-
-	return 0;
 }
 
-int mercenary_save(struct mercenary_data *md)
-{
+/**
+* Save Mercenary data
+* @param md Mercenary
+**/
+void mercenary_save(struct mercenary_data *md) {
 	md->mercenary.hp = md->battle_status.hp;
 	md->mercenary.sp = md->battle_status.sp;
 	md->mercenary.life_time = mercenary_get_lifetime(md);
 
 	intif_mercenary_save(&md->mercenary);
-	return 1;
 }
 
-static int merc_contract_end(int tid, unsigned int tick, int id, intptr_t data)
-{
+/**
+* Ends contract of Mercenary
+**/
+static int merc_contract_end(int tid, unsigned int tick, int id, intptr_t data) {
 	struct map_session_data *sd;
 	struct mercenary_data *md;
 
@@ -233,17 +278,21 @@ static int merc_contract_end(int tid, unsigned int tick, int id, intptr_t data)
 	}
 
 	md->contract_timer = INVALID_TIMER;
-	merc_delete(md, 0); // Mercenary soldier's duty hour is over.
+	mercenary_delete(md, 0); // Mercenary soldier's duty hour is over.
 
 	return 0;
 }
 
-int merc_delete(struct mercenary_data *md, int reply)
-{
+/**
+* Delete Mercenary
+* @param md Mercenary
+* @param reply
+**/
+int mercenary_delete(struct mercenary_data *md, int reply) {
 	struct map_session_data *sd = md->master;
 	md->mercenary.life_time = 0;
 
-	merc_contract_stop(md);
+	mercenary_contract_stop(md);
 
 	if( !sd )
 		return unit_free(&md->bl, CLR_OUTSIGHT);
@@ -264,16 +313,22 @@ int merc_delete(struct mercenary_data *md, int reply)
 	return unit_remove_map(&md->bl, CLR_OUTSIGHT);
 }
 
-void merc_contract_stop(struct mercenary_data *md)
-{
+/**
+* Stop contract of Mercenary
+* @param md Mercenary
+**/
+void mercenary_contract_stop(struct mercenary_data *md) {
 	nullpo_retv(md);
 	if( md->contract_timer != INVALID_TIMER )
 		delete_timer(md->contract_timer, merc_contract_end);
 	md->contract_timer = INVALID_TIMER;
 }
 
-void merc_contract_init(struct mercenary_data *md)
-{
+/**
+* Init contract of Mercenary
+* @param md Mercenary
+**/
+void merc_contract_init(struct mercenary_data *md) {
 	if( md->contract_timer == INVALID_TIMER )
 		md->contract_timer = add_timer(gettick() + md->mercenary.life_time, merc_contract_end, md->master->bl.id, 0);
 
@@ -284,21 +339,20 @@ void merc_contract_init(struct mercenary_data *md)
  * Received mercenary data from char-serv
  * @param merc : mercenary datas
  * @param flag : if inter-serv request was sucessfull
- * @return 0:failure, 1:sucess
+ * @return false:failure, true:sucess
  */
-int merc_data_received(struct s_mercenary *merc, bool flag)
-{
+bool mercenary_recv_data(struct s_mercenary *merc, bool flag){
 	struct map_session_data *sd;
 	struct mercenary_data *md;
 	struct s_mercenary_db *db;
-	int i = merc_search_index(merc->class_);
+	int i = mercenary_search_index(merc->class_);
 
 	if( (sd = map_charid2sd(merc->char_id)) == NULL )
-		return 0;
+		return false;
 	if( !flag || i < 0 )
 	{ // Not created - loaded - DB info
 		sd->status.mer_id = 0;
-		return 0;
+		return false;
 	}
 
 	db = &mercenary_db[i];
@@ -343,40 +397,53 @@ int merc_data_received(struct s_mercenary *merc, bool flag)
 	if( md && md->bl.prev == NULL && sd->bl.prev != NULL )
 	{
 		if(map_addblock(&md->bl))
-			return 0;
+			return false;
 		clif_spawn(&md->bl);
 		clif_mercenary_info(sd);
 		clif_mercenary_skillblock(sd);
 	}
 
-	return 1;
+	return true;
 }
 
-void mercenary_heal(struct mercenary_data *md, int hp, int sp)
-{
+/**
+* Heals Mercenary
+* @param md Mercenary
+* @param hp HP amount
+* @param sp SP amount
+**/
+void mercenary_heal(struct mercenary_data *md, int hp, int sp) {
 	if( hp )
 		clif_mercenary_updatestatus(md->master, SP_HP);
 	if( sp )
 		clif_mercenary_updatestatus(md->master, SP_SP);
 }
 
-int mercenary_dead(struct mercenary_data *md)
-{
-	merc_delete(md, 1);
-	return 0;
+/**
+* Delete Mercenary
+* @param md Mercenary
+**/
+bool mercenary_dead(struct mercenary_data *md) {
+	mercenary_delete(md, 1);
+	return true;
 }
 
-int mercenary_killbonus(struct mercenary_data *md)
-{
+/**
+* Gives bonus to Mercenary
+* @param md Mercenary
+**/
+void mercenary_killbonus(struct mercenary_data *md) {
 	const enum sc_type scs[] = { SC_MERC_FLEEUP, SC_MERC_ATKUP, SC_MERC_HPUP, SC_MERC_SPUP, SC_MERC_HITUP };
-	int index = rnd() % ARRAYLENGTH(scs);
+	uint8 index = rnd() % ARRAYLENGTH(scs);
 
 	sc_start(&md->bl,&md->bl, scs[index], 100, rnd() % 5, 600000);
-	return 0;
 }
 
-int mercenary_kills(struct mercenary_data *md)
-{
+/**
+* Mercenary does kill
+* @param md Mercenary
+**/
+void mercenary_kills(struct mercenary_data *md){
 	if(md->mercenary.kill_count <= (INT_MAX-1)) //safe cap to INT_MAX
 		md->mercenary.kill_count++;
 
@@ -388,12 +455,15 @@ int mercenary_kills(struct mercenary_data *md)
 
 	if( md->master )
 		clif_mercenary_updatestatus(md->master, SP_MERCKILLS);
-
-	return 0;
 }
 
-int mercenary_checkskill(struct mercenary_data *md, uint16 skill_id)
-{
+/**
+* Check if Mercenary has the skill
+* @param md Mercenary
+* @param skill_id The skill
+* @return Skill Level or 0 if Mercenary doesn't have the skill
+**/
+int mercenary_checkskill(struct mercenary_data *md, uint16 skill_id) {
 	int i = skill_id - MC_SKILLBASE;
 
 	if( !md || !md->db )
@@ -404,14 +474,24 @@ int mercenary_checkskill(struct mercenary_data *md, uint16 skill_id)
 	return 0;
 }
 
-static bool read_mercenarydb_sub(char* str[], int columns, int current)
+/**
+* Read each line of Mercenary's database
+**/
+static bool mercenary_readdb_sub(char* str[], int columns, int current)
 {
 	int ele;
+	uint16 i, class_ = atoi(str[0]);
 	struct s_mercenary_db *db;
 	struct status_data *status;
 
-	db = &mercenary_db[current];
-	db->class_ = atoi(str[0]);
+	//Find the ID, already exist or not in mercenary_db
+	ARR_FIND(0,mercenary_count,i,mercenary_db[i].class_ == class_);
+	if (i >= mercenary_count)
+		db = &mercenary_db[mercenary_count];
+	else
+		db = &mercenary_db[i];
+
+	db->class_ = class_;
 	safestrncpy(db->sprite, str[1], NAME_LENGTH);
 	safestrncpy(db->name, str[2], NAME_LENGTH);
 	db->lv = atoi(str[3]);
@@ -456,27 +536,32 @@ static bool read_mercenarydb_sub(char* str[], int columns, int current)
 	status->adelay = atoi(str[23]);
 	status->amotion = atoi(str[24]);
 	status->dmotion = atoi(str[25]);
-
+	
+	if (i >= mercenary_count)
+		mercenary_count++;
 	return true;
 }
 
-int read_mercenarydb(void)
-{
-	const char *filename[]={ "mercenary_db.txt","import/mercenary_db.txt"};
-	int i;
+/**
+* Load Mercenary's database
+**/
+void mercenary_readdb(void) {
+	const char *filename[]={ "mercenary_db.txt",DBIMPORT"/mercenary_db.txt"};
+	uint8 i;
+	mercenary_count = 0; //Reset the counter
 	memset(mercenary_db,0,sizeof(mercenary_db));
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 26, 26, MAX_MERCENARY_CLASS, &mercenary_readdb_sub, i);
 	}
-
-	return 0;
 }
 
-static bool read_mercenary_skilldb_sub(char* str[], int columns, int current)
+/**
+* Read each line of Mercenary's skill
+**/
+static bool mercenary_read_skilldb_sub(char* str[], int columns, int current)
 {// <merc id>,<skill id>,<skill level>
 	struct s_mercenary_db *db;
-	int i, class_;
-	uint16 skill_id, skill_lv;
+	uint16 i, class_, skill_id, skill_lv;
 
 	class_ = atoi(str[0]);
 	ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary_db[i].class_);
@@ -503,24 +588,30 @@ static bool read_mercenary_skilldb_sub(char* str[], int columns, int current)
 	return true;
 }
 
-int read_mercenary_skilldb(void)
-{
-	const char *filename[]={ "mercenary_skill_db.txt","import/mercenary_skill_db.txt"};
-	int i;
+/**
+* Load Mercenary's skill database
+**/
+void mercenary_read_skilldb(void){
+	const char *filename[]={ "mercenary_skill_db.txt",DBIMPORT"/mercenary_skill_db.txt"};
+	uint8 i;
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 3, 3, -1, &read_mercenary_skilldb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 3, 3, -1, &mercenary_read_skilldb_sub, i);
 	}
-
-	return 0;
 }
 
-int do_init_mercenary(void)
-{
-	read_mercenarydb();
-	read_mercenary_skilldb();
+/**
+* Init Mercenary datas
+**/
+void do_init_mercenary(void){
+	mercenary_readdb();
+	mercenary_read_skilldb();
 
 	//add_timer_func_list(mercenary_contract, "mercenary_contract");
-	return 0;
 }
 
-int do_final_mercenary(void);
+/**
+* Do Final Mercenary datas
+**/
+void do_final_mercenary(void){
+	//Nothing to do yet
+}

+ 15 - 14
src/map/mercenary.h

@@ -49,35 +49,36 @@ struct mercenary_data {
 	unsigned devotion_flag : 1;
 };
 
-bool merc_class(int class_);
-struct view_data * merc_get_viewdata(int class_);
+bool mercenary_class(int class_);
+struct view_data * mercenary_get_viewdata(int class_);
 
-int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime);
-int merc_data_received(struct s_mercenary *merc, bool flag);
-int mercenary_save(struct mercenary_data *md);
+bool mercenary_create(struct map_session_data *sd, int class_, unsigned int lifetime);
+bool mercenary_recv_data(struct s_mercenary *merc, bool flag);
+void mercenary_save(struct mercenary_data *md);
 
 void mercenary_heal(struct mercenary_data *md, int hp, int sp);
-int mercenary_dead(struct mercenary_data *md);
+bool mercenary_dead(struct mercenary_data *md);
 
-int merc_delete(struct mercenary_data *md, int reply);
-void merc_contract_stop(struct mercenary_data *md);
+int mercenary_delete(struct mercenary_data *md, int reply);
+void mercenary_contract_stop(struct mercenary_data *md);
 
 int mercenary_get_lifetime(struct mercenary_data *md);
 int mercenary_get_guild(struct mercenary_data *md);
 int mercenary_get_faith(struct mercenary_data *md);
-int mercenary_set_faith(struct mercenary_data *md, int value);
+void mercenary_set_faith(struct mercenary_data *md, int value);
 int mercenary_get_calls(struct mercenary_data *md);
-int mercenary_set_calls(struct mercenary_data *md, int value);
-int mercenary_kills(struct mercenary_data *md);
+void mercenary_set_calls(struct mercenary_data *md, int value);
+void mercenary_kills(struct mercenary_data *md);
 
 int mercenary_checkskill(struct mercenary_data *md, uint16 skill_id);
 
 /**
  * atcommand.c required
  **/
-int read_mercenarydb(void);
-int read_mercenary_skilldb(void);
+void mercenary_readdb(void);
+void mercenary_read_skilldb(void);
 
-int do_init_mercenary(void);
+void do_init_mercenary(void);
+void do_final_mercenary(void);
 
 #endif /* _MERCENARY_H_ */

+ 4 - 9
src/map/mob.c

@@ -2156,7 +2156,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 		count++; //Only logged into same map chars are counted for the total.
 		if (pc_isdead(tsd))
 			continue; // skip dead players
-		if(md->dmglog[i].flag == MDLF_HOMUN && !merc_is_hom_active(tsd->hd))
+		if(md->dmglog[i].flag == MDLF_HOMUN && !hom_is_active(tsd->hd))
 			continue; // skip homunc's share if inactive
 		if( md->dmglog[i].flag == MDLF_PET && (!tsd->status.pet_id || !tsd->pd) )
 			continue; // skip pet's share if inactive
@@ -2297,7 +2297,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 				}
 			}
 			if(base_exp && md->dmglog[i].flag == MDLF_HOMUN) //tmpsd[i] is null if it has no homunc.
-				merc_hom_gainexp(tmpsd[i]->hd, base_exp);
+				hom_gainexp(tmpsd[i]->hd, base_exp);
 			if(flag) {
 				if(base_exp || job_exp) {
 					if( md->dmglog[i].flag != MDLF_PET || battle_config.pet_attack_exp_to_master ) {
@@ -4619,8 +4619,7 @@ void mob_clear_spawninfo()
 /*==========================================
  * Circumference initialization of mob
  *------------------------------------------*/
-int do_init_mob(void)
-{	//Initialize the mob database
+void do_init_mob(void){
 	memset(mob_db_data,0,sizeof(mob_db_data)); //Clear the array
 	mob_db_data[0] = (struct mob_db*)aCalloc(1, sizeof (struct mob_db));	//This mob is used for random spawns
 	mob_makedummymobdb(0); //The first time this is invoked, it creates the dummy mob
@@ -4638,15 +4637,12 @@ int do_init_mob(void)
 	add_timer_func_list(mob_respawn,"mob_respawn");
 	add_timer_interval(gettick()+MIN_MOBTHINKTIME,mob_ai_hard,0,0,MIN_MOBTHINKTIME);
 	add_timer_interval(gettick()+MIN_MOBTHINKTIME*10,mob_ai_lazy,0,0,MIN_MOBTHINKTIME*10);
-
-	return 0;
 }
 
 /*==========================================
  * Clean memory usage.
  *------------------------------------------*/
-int do_final_mob(void)
-{
+void do_final_mob(void){
 	int i;
 	if (mob_dummy)
 	{
@@ -4679,5 +4675,4 @@ int do_final_mob(void)
 	}
 	ers_destroy(item_drop_ers);
 	ers_destroy(item_drop_list_ers);
-	return 0;
 }

+ 2 - 2
src/map/mob.h

@@ -278,8 +278,8 @@ void mob_heal(struct mob_data *md,unsigned int heal);
 #define mob_is_samename(md, mid) (strcmp(mob_db((md)->mob_id)->jname, mob_db(mid)->jname) == 0)
 
 void mob_clear_spawninfo();
-int do_init_mob(void);
-int do_final_mob(void);
+void do_init_mob(void);
+void do_final_mob(void);
 
 int mob_timer_delete(int tid, unsigned int tick, int id, intptr_t data);
 int mob_deleteslave(struct mob_data *md);

+ 2 - 7
src/map/npc.c

@@ -4128,15 +4128,13 @@ void do_clear_npc(void) {
 /*==========================================
  * Destructor
  *------------------------------------------*/
-int do_final_npc(void) {
+void do_final_npc(void) {
 	npc_clear_pathlist();
 	ev_db->destroy(ev_db, NULL);
 	npcname_db->destroy(npcname_db, NULL);
 	npc_path_db->destroy(npc_path_db, NULL);
 	ers_destroy(timer_event_ers);
 	npc_clearsrcfile();
-
-	return 0;
 }
 
 static void npc_debug_warps_sub(struct npc_data* nd)
@@ -4176,8 +4174,7 @@ static void npc_debug_warps(void)
 /*==========================================
  * npc initialization
  *------------------------------------------*/
-int do_init_npc(void)
-{
+void do_init_npc(void){
 	struct npc_src_list *file;
 	int i;
 
@@ -4238,6 +4235,4 @@ int do_init_npc(void)
 	fake_nd->u.scr.timerid = INVALID_TIMER;
 	map_addiddb(&fake_nd->bl);
 	// End of initialization
-
-	return 0;
 }

+ 2 - 2
src/map/npc.h

@@ -150,8 +150,8 @@ void npc_addsrcfile(const char* name);
 void npc_delsrcfile(const char* name);
 void npc_parsesrcfile(const char* filepath, bool runOnInit);
 void do_clear_npc(void);
-int do_final_npc(void);
-int do_init_npc(void);
+void do_final_npc(void);
+void do_init_npc(void);
 void npc_event_do_oninit(void);
 int npc_do_ontimer(int npc_id, int option);
 

+ 12 - 15
src/map/pc.c

@@ -5053,7 +5053,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
 		sd->pd->ud.dir = sd->ud.dir;
 	}
 
-	if( merc_is_hom_active(sd->hd) )
+	if( hom_is_active(sd->hd) )
 	{
 		sd->hd->bl.m = m;
 		sd->hd->bl.x = sd->hd->ud.to_x = x;
@@ -6351,7 +6351,7 @@ int pc_skillup(struct map_session_data *sd,uint16 skill_id)
 
 	if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE+MAX_HOMUNSKILL && sd->hd )
 	{
-		merc_hom_skillup(sd->hd, skill_id);
+		hom_skillup(sd->hd, skill_id);
 		return 0;
 	}
 
@@ -6642,8 +6642,8 @@ int pc_resetskill(struct map_session_data* sd, int flag)
 		if( i != sd->sc.option )
 			pc_setoption(sd, i);
 
-		if( merc_is_hom_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
-			merc_hom_vaporize(sd, HOM_ST_ACTIVE);
+		if( hom_is_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
+			hom_vaporize(sd, HOM_ST_ACTIVE);
 	}
 
 	for( i = 1; i < MAX_SKILL; i++ )
@@ -6940,11 +6940,11 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
 
 	if (sd->status.hom_id > 0) {
 		if(battle_config.homunculus_auto_vapor && sd->hd && !sd->hd->sc.data[SC_LIGHT_OF_REGENE])
-			merc_hom_vaporize(sd, HOM_ST_ACTIVE);
+			hom_vaporize(sd, HOM_ST_ACTIVE);
 	}
 
 	if( sd->md )
-		merc_delete(sd->md, 3); // Your mercenary soldier has ran away.
+		mercenary_delete(sd->md, 3); // Your mercenary soldier has ran away.
 
 	if( sd->ed )
 		elemental_delete(sd->ed, 0);
@@ -7827,8 +7827,8 @@ int pc_jobchange(struct map_session_data *sd,int job, int upper)
 	if(i != sd->sc.option)
 		pc_setoption(sd, i);
 
-	if(merc_is_hom_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
-		merc_hom_vaporize(sd, HOM_ST_ACTIVE);
+	if(hom_is_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
+		hom_vaporize(sd, HOM_ST_ACTIVE);
 
 	if(sd->status.manner < 0)
 		clif_changestatus(sd,SP_MANNER,sd->status.manner);
@@ -10222,8 +10222,7 @@ static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
  * job_db2.txt		- job,stats bonuses/lvl
  * job_maxhpsp_db.txt	- strtlvl,maxlvl,job,type,values/lvl (values=hp|sp)
  *------------------------------------------*/
-int pc_readdb(void)
-{
+void pc_readdb(void) {
 	int i, k, s = 1;
 	const char* dbsubpath[] = {
 		"",
@@ -10323,7 +10322,6 @@ int pc_readdb(void)
 				job_info[idx].base_sp[j] = 10 + (unsigned int)floor((j+1) * (job_info[idx].sp_factor / 100.));
 		}
 	}
- 	return 0;
 }
 
 // Read MOTD on startup. [Valaris]
@@ -10537,7 +10535,9 @@ void pc_crimson_marker_clear(struct map_session_data *sd) {
 		struct block_list *bl = NULL;
 		if (sd->c_marker.target[i] && (bl = map_id2bl(sd->c_marker.target[i])))
 			status_change_end(bl,SC_C_MARKER,INVALID_TIMER);
+		sd->c_marker.target[i] = 0;
 	}
+	sd->c_marker.count = 0;
 }
 
 /**
@@ -10686,10 +10686,9 @@ void do_final_pc(void) {
 	db_destroy(itemcd_db);
 
 	do_final_pc_groups();
-	return;
 }
 
-int do_init_pc(void) {
+void do_init_pc(void) {
 
 	itemcd_db = idb_alloc(DB_OPT_RELEASE_DATA);
 
@@ -10723,6 +10722,4 @@ int do_init_pc(void) {
 	}
 
 	do_init_pc_groups();
-
-	return 0;
 }

+ 3 - 3
src/map/pc.h

@@ -568,7 +568,7 @@ struct map_session_data {
 
 	struct s_crimson_marker { ///Store target that marked by Crimson Marker [Cydh]
 		int target[MAX_SKILL_CRIMSON_MARKER]; //Target id storage
-		uint8 count; //Count of target for skill like RL_D_TAIL
+		uint8 count; //Count of target for skill used (i.e. RL_D_TAIL).
 	} c_marker;
 	bool flicker; ///Is Flicker Skill skill as player's last action? [Cydh]
 
@@ -1026,8 +1026,8 @@ extern struct fame_list smith_fame_list[MAX_FAME_LIST];
 extern struct fame_list chemist_fame_list[MAX_FAME_LIST];
 extern struct fame_list taekwon_fame_list[MAX_FAME_LIST];
 
-int pc_readdb(void);
-int do_init_pc(void);
+void pc_readdb(void);
+void do_init_pc(void);
 void do_final_pc(void);
 
 enum {CHKADDITEM_EXIST,CHKADDITEM_NEW,CHKADDITEM_OVERAMOUNT};

+ 3 - 10
src/map/pet.c

@@ -1211,8 +1211,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
  * pet_db.txt
  * pet_db2.txt
  *------------------------------------------*/
-int read_petdb()
-{
+void read_petdb(){
 	char* filename[] = {"pet_db.txt",DBIMPORT"/pet_db.txt"};
 	FILE *fp;
 	int nameid,i,j,k;
@@ -1351,14 +1350,12 @@ int read_petdb()
 		fclose(fp);
 		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' pets in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, db_path, filename[i]);
 	}
-	return 0;
 }
 
 /*==========================================
  * Initialization process relationship skills
  *------------------------------------------*/
-int do_init_pet(void)
-{
+void do_init_pet(void){
 	read_petdb();
 
 	item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE);
@@ -1372,12 +1369,9 @@ int do_init_pet(void)
 	add_timer_func_list(pet_recovery_timer,"pet_recovery_timer"); // [Valaris]
 	add_timer_func_list(pet_heal_timer,"pet_heal_timer"); // [Valaris]
 	add_timer_interval(gettick()+MIN_PETTHINKTIME,pet_ai_hard,0,0,MIN_PETTHINKTIME);
-
-	return 0;
 }
 
-int do_final_pet(void)
-{
+void do_final_pet(void){
 	int i;
 	for( i = 0; i < MAX_PET_DB; i++ )
 	{
@@ -1394,5 +1388,4 @@ int do_final_pet(void)
 	}
 	ers_destroy(item_drop_ers);
 	ers_destroy(item_drop_list_ers);
-	return 0;
 }

+ 3 - 3
src/map/pet.h

@@ -130,8 +130,8 @@ int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valar
 #define pet_stop_walking(pd, type) unit_stop_walking(&(pd)->bl, type)
 #define pet_stop_attack(pd) unit_stop_attack(&(pd)->bl)
 
-int read_petdb(void);
-int do_init_pet(void);
-int do_final_pet(void);
+void read_petdb(void);
+void do_init_pet(void);
+void do_final_pet(void);
 
 #endif /* _PET_H_ */

+ 12 - 16
src/map/script.c

@@ -4240,7 +4240,7 @@ static void *queryThread_main(void *x) {
 /*==========================================
  * Destructor
  *------------------------------------------*/
-int do_final_script() {
+void do_final_script() {
 	int i;
 #ifdef DEBUG_HASH
 	if (battle_config.etc_log)
@@ -4346,13 +4346,11 @@ int do_final_script() {
 
 	aFree(logThreadData.entry);
 #endif
-
-	return 0;
 }
 /*==========================================
  * Initialization
  *------------------------------------------*/
-int do_init_script() {
+void do_init_script(void) {
 	userfunc_db=strdb_alloc(DB_OPT_DUP_KEY,0);
 	scriptlabel_db=strdb_alloc(DB_OPT_DUP_KEY,50);
 	autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0);
@@ -4381,10 +4379,9 @@ int do_init_script() {
 
 	add_timer_func_list(queryThread_timer, "queryThread_timer");
 #endif
-	return 0;
 }
 
-int script_reload() {
+void script_reload(void) {
 	int i;
 
 #ifdef BETA_THREAD_TEST
@@ -4429,7 +4426,6 @@ int script_reload() {
 		linkdb_final(&sleep_db);
 	}
 	mapreg_reload();
-	return 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -10342,10 +10338,10 @@ BUILDIN_FUNC(homunculus_evolution)
 	if( sd == NULL )
 		return 0;
 
-	if(merc_is_hom_active(sd->hd))
+	if(hom_is_active(sd->hd))
 	{
 		if (sd->hd->homunculus.intimacy > 91000)
-			merc_hom_evolution(sd->hd);
+			hom_evolution(sd->hd);
 		else
 			clif_emotion(&sd->hd->bl, E_SWT);
 	}
@@ -10378,7 +10374,7 @@ BUILDIN_FUNC(homunculus_mutate)
 
 		if ( m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99 && i >= 0 ) {
 			sd->hd->homunculus.vaporize = HOM_ST_REST; // Remove morph state.
-			merc_call_homunculus(sd); // Respawn homunculus.
+			hom_call(sd); // Respawn homunculus.
 			hom_mutate(sd->hd, homun_id);
 			pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_SCRIPT);
 			script_pushint(st, 1);
@@ -10407,7 +10403,7 @@ BUILDIN_FUNC(morphembryo)
 	if( sd == NULL || sd->hd == NULL )
 		return 0;
 
-	if( merc_is_hom_active(sd->hd) ) {
+	if( hom_is_active(sd->hd) ) {
 		m_class = hom_class2mapid(sd->hd->homunculus.class_);
 
 		if ( m_class != -1 && m_class&HOM_EVO && sd->hd->homunculus.level >= 99 ) {
@@ -10419,7 +10415,7 @@ BUILDIN_FUNC(morphembryo)
 				clif_additem(sd, 0, 0, i);
 				clif_emotion(&sd->bl, E_SWT); // Fail to avoid item drop exploit.
 			} else {
-				merc_hom_vaporize(sd, HOM_ST_MORPH);
+				hom_vaporize(sd, HOM_ST_MORPH);
 				script_pushint(st, 1);
 				return 0;
 			}
@@ -10442,8 +10438,8 @@ BUILDIN_FUNC(homunculus_shuffle)
 	if( sd == NULL )
 		return 0;
 
-	if(merc_is_hom_active(sd->hd))
-		merc_hom_shuffle(sd->hd);
+	if(hom_is_active(sd->hd))
+		hom_shuffle(sd->hd);
 
 	return SCRIPT_CMD_SUCCESS;
 }
@@ -16369,11 +16365,11 @@ BUILDIN_FUNC(mercenary_create)
 
 	class_ = script_getnum(st,2);
 
-	if( !merc_class(class_) )
+	if( !mercenary_class(class_) )
 		return 0;
 
 	contract_time = script_getnum(st,3);
-	merc_create(sd, class_, contract_time);
+	mercenary_create(sd, class_, contract_time);
 	return SCRIPT_CMD_SUCCESS;
 }
 

+ 3 - 3
src/map/script.h

@@ -187,11 +187,11 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void
 void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache);
 
 int script_config_read(char *cfgName);
-int do_init_script(void);
-int do_final_script(void);
+void do_init_script(void);
+void do_final_script(void);
 int add_str(const char* p);
 const char* get_str(int id);
-int script_reload(void);
+void script_reload(void);
 
 // @commands (script based)
 void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct DBMap **ref);

+ 203 - 48
src/map/skill.c

@@ -104,6 +104,7 @@ struct s_skill_unit_layout skill_unit_layout[MAX_SKILL_UNIT_LAYOUT];
 int firewall_unit_pos;
 int icewall_unit_pos;
 int earthstrain_unit_pos;
+int firerain_unit_pos;
 //early declaration
 int skill_block_check(struct block_list *bl, enum sc_type type, uint16 skill_id);
 static int skill_check_unit_range (struct block_list *bl, int x, int y, uint16 skill_id, uint16 skill_lv);
@@ -385,7 +386,7 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk
 				hp = hp * ( 17 + 3 * skill_lv ) / 10;
 			if( sd && ((skill = pc_checkskill(sd, HP_MEDITATIO)) > 0) )
 				hp += hp * skill * 2 / 100;
-			else if( src->type == BL_HOM && (skill = merc_hom_checkskill(((TBL_HOM*)src), HLIF_BRAIN)) > 0 )
+			else if( src->type == BL_HOM && (skill = hom_checkskill(((TBL_HOM*)src), HLIF_BRAIN)) > 0 )
 				hp += hp * skill * 2 / 100;
 			if( sd && tsd && sd->status.partner_id == tsd->status.char_id && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.sex == 0 )
 				hp *= 2;
@@ -793,6 +794,8 @@ struct s_skill_unit_layout* skill_get_unit_layout (uint16 skill_id, uint16 skill
 		return &skill_unit_layout [icewall_unit_pos + dir];
 	else if( skill_id == WL_EARTHSTRAIN ) //Warlock
 		return &skill_unit_layout [earthstrain_unit_pos + dir];
+	else if( skill_id == RL_FIRE_RAIN )
+		return &skill_unit_layout[firerain_unit_pos + dir];
 
 	ShowError("skill_get_unit_layout: unknown unit layout for skill %d (level %d)\n", skill_id, skill_lv);
 	return &skill_unit_layout[0]; // default 1x1 layout
@@ -1567,32 +1570,106 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
 		}
 		break;
 	case RL_BANISHING_BUSTER:
-		if (dstsd && tsc) {
-			uint16 i = 0;
-			uint8 n = skill_lv * 2 + 2; //4, 6, 8, 10, 12
-			for (i = 0; i < SC_MAX && n > 0; i++) {
-				if (tsc->data[i] && rnd()%400 < status_get_dex(src)) { //(custom)
-					status_change_end(bl,(sc_type)i,INVALID_TIMER);
-					n--;
+		{
+			//kRO update 2014-02-12. 100% chance to remove random buff(s) (1/2/3/4/5)
+			//TODO:
+			//- Confirm the removeable buffs. I'm using SA_DISPEL behavior
+			//- Make this removes 'random' buffs
+			uint16 i, n = skill_lv;
+
+			if (!tsc || !tsc->count)
+				break;
+
+			if (status_isimmune(bl))
+				break;
+
+			if (dstsd && (dstsd->class_&MAPID_UPPERMASK) == MAPID_SOUL_LINKER) {
+				if (sd)
+					clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
+				break;
+			}
+
+			for (i = 0; n > 0 && i < SC_MAX; i++) {
+				if (!tsc->data[i])
+					continue;
+				switch (i) {
+					case SC_WEIGHT50:		case SC_WEIGHT90:		case SC_HALLUCINATION:
+					case SC_STRIPWEAPON:	case SC_STRIPSHIELD:	case SC_STRIPARMOR:
+					case SC_STRIPHELM:		case SC_CP_WEAPON:		case SC_CP_SHIELD:
+					case SC_CP_ARMOR:		case SC_CP_HELM:		case SC_COMBO:
+					case SC_STRFOOD:		case SC_AGIFOOD:		case SC_VITFOOD:
+					case SC_INTFOOD:		case SC_DEXFOOD:		case SC_LUKFOOD:
+					case SC_HITFOOD:		case SC_FLEEFOOD:		case SC_BATKFOOD:
+					case SC_WATKFOOD:		case SC_MATKFOOD:		case SC_DANCING:
+					case SC_EDP:			case SC_AUTOBERSERK:
+					case SC_CARTBOOST:		case SC_MELTDOWN:		case SC_SAFETYWALL:
+					case SC_SMA:			case SC_SPEEDUP0:		case SC_NOCHAT:
+					case SC_ANKLE:			case SC_SPIDERWEB:		case SC_JAILED:
+					case SC_ITEMBOOST:		case SC_EXPBOOST:		case SC_LIFEINSURANCE:
+					case SC_BOSSMAPINFO:	case SC_PNEUMA:			case SC_AUTOSPELL:
+					case SC_INCHITRATE:		case SC_INCATKRATE:		case SC_NEN:
+					case SC_READYSTORM:		case SC_READYDOWN:		case SC_READYTURN:
+					case SC_READYCOUNTER:	case SC_DODGE:			case SC_WARM:
+					case SC_SPEEDUP1:		case SC_AUTOTRADE:		case SC_CRITICALWOUND:
+					case SC_JEXPBOOST:		case SC_INVINCIBLE:		case SC_INVINCIBLEOFF:
+					case SC_HELLPOWER:		case SC_MANU_ATK:		case SC_MANU_DEF:
+					case SC_SPL_ATK:		case SC_SPL_DEF:		case SC_MANU_MATK:
+					case SC_SPL_MATK:		case SC_RICHMANKIM:		case SC_ETERNALCHAOS:
+					case SC_DRUMBATTLE:		case SC_NIBELUNGEN:		case SC_ROKISWEIL:
+					case SC_INTOABYSS:		case SC_SIEGFRIED:		case SC_FOOD_STR_CASH:
+					case SC_FOOD_AGI_CASH:	case SC_FOOD_VIT_CASH:	case SC_FOOD_DEX_CASH:
+					case SC_FOOD_INT_CASH:	case SC_FOOD_LUK_CASH:	case SC_SEVENWIND:
+					case SC_MIRACLE:		case SC_S_LIFEPOTION:	case SC_L_LIFEPOTION:
+					case SC_INCHEALRATE:	case SC_ELECTRICSHOCKER:		case SC__STRIPACCESSORY:
+					//case SC_SAVAGE_STEAK:			case SC_COCKTAIL_WARG_BLOOD:		case SC_MINOR_BBQ:
+					//case SC_SIROMA_ICE_TEA:			case SC_DROCERA_HERB_STEAMED:		case SC_PUTTI_TAILS_NOODLES:
+					case SC_NEUTRALBARRIER_MASTER:		case SC_NEUTRALBARRIER:			case SC_STEALTHFIELD_MASTER:
+					case SC_STEALTHFIELD:	case SC_GIANTGROWTH:	case SC_MILLENNIUMSHIELD:
+					case SC_REFRESH:		case SC_STONEHARDSKIN:	case SC_VITALITYACTIVATION:
+					case SC_FIGHTINGSPIRIT:	case SC_ABUNDANCE:		case SC__SHADOWFORM:
+					case SC_LEADERSHIP:		case SC_GLORYWOUNDS:	case SC_SOULCOLD:
+					case SC_HAWKEYES:		case SC_GUILDAURA:		case SC_PUSH_CART:
+					case SC_RAISINGDRAGON:	case SC_GT_ENERGYGAIN:	case SC_GT_CHANGE:
+					case SC_GT_REVITALIZE:	case SC_REFLECTDAMAGE:	case SC_INSPIRATION:
+					case SC_EXEEDBREAK:		case SC_FORCEOFVANGUARD:	case SC_BANDING:
+					case SC_DUPLELIGHT:		case SC_EXPIATIO:		case SC_LAUDAAGNUS:
+					case SC_LAUDARAMUS:		case SC_GATLINGFEVER:	case SC_INCREASING:
+					case SC_ADJUSTMENT:		case SC_MADNESSCANCEL:
+					case SC_ANGEL_PROTECT:	case SC_MONSTER_TRANSFORM:	case SC_FULL_THROTTLE:
+					case SC_REBOUND:		case SC_TELEKINESIS_INTENSE:
+					case SC_HEAT_BARREL:	case SC_HEAT_BARREL_AFTER:	case SC_P_ALTER:
+					case SC_E_CHAIN:		case SC_C_MARKER:		case SC_B_TRAP:
+					case SC_H_MINE:			case SC_RECOGNIZEDSPELL:
+					case SC_MTF_ASPD:		case SC_MTF_RANGEATK:	case SC_MTF_MATK:
+					case SC_MTF_MLEATKED:	case SC_MTF_CRIDAMAGE:	case SC_GN_CARTBOOST:
+#ifdef RENEWAL
+					case SC_EXTREMITYFIST2:
+#endif
+						continue;
+					case SC_WHISTLE:		case SC_ASSNCROS:		case SC_POEMBRAGI:
+					case SC_APPLEIDUN:		case SC_HUMMING:		case SC_DONTFORGETME:
+					case SC_FORTUNE:		case SC_SERVICE4U:
+						if(tsc->data[i]->val4==0)
+							continue; //if in song-area don't end it
+						break;
+					case SC_ASSUMPTIO:
+						if( bl->type == BL_MOB )
+							continue;
+						break;
 				}
+				if (i == SC_BERSERK || i == SC_SATURDAYNIGHTFEVER) tsc->data[i]->val2=0; //Mark a dispelled berserk to avoid setting hp to 100 by setting hp penalty to 0.
+				status_change_end(bl, (sc_type)i, INVALID_TIMER);
+				n--;
 			}
 		}
 		break;
 	case RL_S_STORM:
-		if (dstsd) {
-			uint8 i = 0, n, rand_pos[EQI_MAX];
+		//kRO update 2014-02-12. Break 1 Equipment by minimum chance 5%/10%/15%/20%/25%
+		{
 			uint16 pos[] = { EQP_HEAD_LOW, EQP_HEAD_MID, EQP_HEAD_TOP, EQP_HAND_R, EQP_HAND_L, EQP_ARMOR, EQP_SHOES, EQP_GARMENT, EQP_ACC_L, EQP_ACC_R };
-			n = cap_value(skill_lv,2,ARRAYLENGTH(pos));
-
-			while (i < n) {
-				uint8 res = rnd()%ARRAYLENGTH(pos);
-				if (i && res == rand_pos[i-1]) //Make sure the value is not same with previous!
-					continue;
-				
-				rand_pos[i] = res;
-				skill_break_equip(src,bl,pos[res],(status_get_dex(src)*skill_lv*10)-(status_get_agi(bl)*20),BCT_ENEMY); //(custom)
-				i++;
-			}
+			skill_break_equip(src,bl,pos[rnd()%ARRAYLENGTH(pos)],
+				max(skill_lv * 500,(sstatus->dex * skill_lv * 10) - (tstatus->agi * 20)), //(custom)
+				BCT_ENEMY);
 		}
 		break;
 	case RL_AM_BLAST:
@@ -1602,7 +1679,6 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
 		if (sd && sd->skill_id_old == RL_FLICKER && tsc && tsc->data[SC_B_TRAP])
 			status_change_end(bl,SC_B_TRAP,INVALID_TIMER);
 		break;
-
 	case RL_HAMMER_OF_GOD:
 		sc_start(src,bl,SC_STUN,100,skill_lv,skill_get_time2(skill_id,skill_lv));
 	case RL_D_TAIL:
@@ -3687,6 +3763,13 @@ static int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data)
 						map_foreachinarea(skill_area_sub, src->m, x, y, x2, y2, BL_CHAR, src, skl->skill_id, skl->skill_lv, tick, skl->flag|BCT_ENEMY|SD_ANIMATION|1, skill_castend_damage_id);
 					}
 					break;
+				case RL_FIRE_RAIN: {
+						int dummy = 1, i = skill_get_splash(skl->skill_id,skl->skill_lv);
+
+						map_foreachinarea(skill_cell_overlap,src->m,skl->x-i,skl->y-i,skl->x+i,skl->y+i,BL_SKILL,skl->skill_id,&dummy,src);
+						skill_unitsetting(src,skl->skill_id,skl->skill_lv,skl->x,skl->y,0);
+					}
+					break;
 			}
 		}
 	} while (0);
@@ -4214,7 +4297,6 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
 	case RL_FLICKER:
 	case RL_HAMMER_OF_GOD:
 	case RL_QD_SHOT:
-	case RL_FIRE_RAIN:
 		if( flag&1 ) {//Recursive invocation
 			// skill_area_temp[0] holds number of targets in area
 			// skill_area_temp[1] holds the id of the original target
@@ -7990,13 +8072,13 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 		break;
 
 	case AM_CALLHOMUN:	//[orn]
-		if (sd && !merc_call_homunculus(sd))
+		if (sd && !hom_call(sd))
 			clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
 		break;
 
 	case AM_REST:
 		if (sd) {
-			if (merc_hom_vaporize(sd,HOM_ST_REST))
+			if (hom_vaporize(sd,HOM_ST_REST))
 				clif_skill_nodamage(src, bl, skill_id, skill_lv, 1);
 			else
 				clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
@@ -9906,9 +9988,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 	case RL_RICHS_COIN:
 		if (sd) {
 			clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
-			if (rnd()%100 < 50)
-				for (i = 0; i < 10; i++)
-					pc_addspiritball(sd,skill_get_time(skill_id,skill_lv),10);
+			for (i = 0; i < 10; i++)
+				pc_addspiritball(sd,skill_get_time(skill_id,skill_lv),10);
 		}
 		break;
 	case RL_C_MARKER:
@@ -9941,7 +10022,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 			skill_area_temp[1] = 0;
 			clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
 			if (sd->c_marker.count)
-				i = map_foreachinrange(skill_area_sub,bl,skill_get_splash(skill_id,skill_lv),splash_target(src),src,skill_id,skill_lv,tick,flag|BCT_ENEMY|SD_SPLASH|1,skill_castend_damage_id);
+				map_foreachinrange(skill_area_sub,bl,skill_get_splash(skill_id,skill_lv),splash_target(src),src,skill_id,skill_lv,tick,flag|BCT_ENEMY|SD_SPLASH|1,skill_castend_damage_id);
 			sd->c_marker.count = 0;
 		}
 		break;
@@ -9954,7 +10035,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 			skill_area_temp[1] = 0;
 			clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
 			if (i)
-				i = map_foreachinrange(skill_area_sub,bl,skill_get_splash(skill_id,skill_lv),splash_target(src),src,skill_id,skill_lv,tick,flag|BCT_ENEMY|SD_SPLASH|1,skill_castend_damage_id);
+				map_foreachinrange(skill_area_sub,bl,skill_get_splash(skill_id,skill_lv),splash_target(src),src,skill_id,skill_lv,tick,flag|BCT_ENEMY|SD_SPLASH|1,skill_castend_damage_id);
 		}
 		//Doesn't matter if the main target has SC_C_MARKER or not
 		skill_attack(skill_get_type(RL_QD_SHOT),src,src,bl,skill_id,skill_lv,tick,flag|BCT_ENEMY|SD_LEVEL|SD_ANIMATION);
@@ -10539,6 +10620,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
 		case HW_GANBANTEIN:
 		case LG_EARTHDRIVE:
 		case SC_ESCAPE:
+		case RL_HAMMER_OF_GOD:
 			break; //Effect is displayed on respective switch case.
 		default:
 			if(skill_get_inf(skill_id)&INF_SELF_SKILL)
@@ -10968,7 +11050,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
 	case AM_RESURRECTHOMUN:	//[orn]
 		if (sd)
 		{
-			if (!merc_resurrect_homunculus(sd, 20*skill_lv, x, y))
+			if (!hom_ressurect(sd, 20*skill_lv, x, y))
 			{
 				clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
 				break;
@@ -11230,9 +11312,36 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
 			clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
 		break;
 	case RL_HAMMER_OF_GOD:
-		i = skill_get_splash(skill_id, skill_lv);
-		map_foreachinarea(skill_area_sub, src->m, x-i, y-i, x+i, y+i, BL_CHAR,
-			src, skill_id, skill_lv, tick, flag|BCT_ENEMY|2, skill_castend_damage_id);
+		if (sd && &sd->c_marker) {
+			i = skill_get_splash(skill_id, skill_lv);
+			//Get how many target around the clicked area
+			if (map_foreachinarea(skill_check_target_c_marker, src->m, x-i, y-i, x+i, y+i, BL_CHAR, src)) {
+				skill_area_temp[1] = 0;
+				map_foreachinarea(skill_area_sub, src->m, x-i, y-i, x+i, y+i, BL_CHAR,
+					src, skill_id, skill_lv, tick, flag|BCT_ENEMY|2, skill_castend_damage_id);
+			}
+			else
+				clif_skill_poseffect(src,skill_id,skill_lv,x,y,tick+500);
+		}
+		break;
+	case RL_FIRE_RAIN: {
+			int i, wave = skill_lv + 5, dir = map_calc_dir(src,x,y);
+			int sx = x = src->x, sy = y = src->y;
+
+			for (i = 1; i <= wave; i++) {
+				switch (dir) {
+					case 0: sy = y + i; break;
+					case 1: sy = y + i; sx = x - i; break;
+					case 2: sx = x - i; break;
+					case 3: sx = x - i; sy = y - i; break;
+					case 4: sy = y - i; break;
+					case 5: sx = x + i; sy = y - i; break;
+					case 6: sx = x + i; break;
+					case 7: sy = y + i; sx = x + i; break;
+				}
+				skill_addtimerskill(src,gettick() + (140 * i),0,sx,sy,skill_id,skill_lv,dir,flag);
+			}
+		}
 		break;
 
 	default:
@@ -12911,15 +13020,17 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
 			status_change_start(ss, bl, SC_BLIND, (10 + 10 * sg->skill_lv)*100, sg->skill_lv, sg->skill_id, 0, 0, skill_get_time2(sg->skill_id, sg->skill_lv), 2|8);
 			break;
 
-		case UNT_B_TRAP:
+		case UNT_B_TRAP: //! FIXME: Unit ID isn't correct, it doesn't show proper client effect.
 			sc_start(ss,bl,SC_B_TRAP,100,sg->skill_lv,max(status_get_str(bl) * 150,5000)); //(custom)
 			sg->unit_id = UNT_USED_TRAPS;
 			clif_changetraplook(&src->bl, UNT_USED_TRAPS);
 			sg->limit=DIFF_TICK(tick,sg->tick)+1500;
 			break;
-		/*case UNT_FIRE_RAIN:
-			skill_attack(skill_get_type(sg->skill_id),ss,&src->bl,bl,sg->skill_id,sg->skill_lv,tick,SD_LEVEL|SD_ANIMATION|SD_SPLASH);
-			break;*/
+		case UNT_FIRE_RAIN: //! FIXME: Unit ID isn't correct, it doesn't show proper client effect.
+			clif_skill_damage(ss,bl,tick,status_get_amotion(ss),0,
+				skill_attack(skill_get_type(sg->skill_id),ss,&src->bl,bl,sg->skill_id,sg->skill_lv,tick,SD_ANIMATION|SD_SPLASH),
+				1,sg->skill_id,sg->skill_lv,6);
+			break;
 	}
 
 	if (bl->type == BL_MOB && ss != bl)
@@ -13838,7 +13949,7 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i
 			}
 			break;
 		case AM_REST: //Can't vapo homun if you don't have an active homunc or it's hp is < 80%
-			if (!merc_is_hom_active(sd->hd) || sd->hd->battle_status.hp < (sd->hd->battle_status.max_hp*80/100)) {
+			if (!hom_is_active(sd->hd) || sd->hd->battle_status.hp < (sd->hd->battle_status.max_hp*80/100)) {
 				clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
 				return false;
 			}
@@ -15049,6 +15160,8 @@ int skill_vfcastfix (struct block_list *bl, double time, uint16 skill_id, uint16
 			fixed -= 1000;
 		if (sc->data[SC_DANCEWITHWUG])
 			fixed -= fixed * sc->data[SC_DANCEWITHWUG]->val4 / 100;
+		if( sc->data[SC_HEAT_BARREL] )
+			fixcast_r = max(fixcast_r, sc->data[SC_HEAT_BARREL]->val2);
 	}
 
 	if( sd && !(skill_get_castnodex(skill_id, skill_lv)&4) ){
@@ -15977,6 +16090,26 @@ static int skill_cell_overlap(struct block_list *bl, va_list ap)
 					return 1;
 			}
 			break;
+		case RL_FIRE_RAIN:
+			switch (unit->group->unit_id) {
+				case UNT_LANDPROTECTOR:	case UNT_ICEWALL:		case UNT_FIREWALL:
+				case UNT_WARMER:		case UNT_CLOUD_KILL:	case UNT_VACUUM_EXTREME:
+				case UNT_SPIDERWEB:		case UNT_FOGWALL:		case UNT_DELUGE:
+				case UNT_VIOLENTGALE:	case UNT_VOLCANO:		case UNT_QUAGMIRE:
+				case UNT_GRAVITATION:	case UNT_MAGNUS:		case UNT_THORNS_TRAP:
+				case UNT_WALLOFTHORN:	case UNT_DEMONIC_FIRE:	case UNT_HELLS_PLANT:
+				case UNT_POISONSMOKE:	case UNT_VENOMDUST:		case UNT_MAELSTROM:
+				case UNT_MANHOLE:		case UNT_DIMENSIONDOOR:	case UNT_GRAFFITI:
+				case UNT_LANDMINE:		case UNT_SANDMAN:		case UNT_SHOCKWAVE:
+				case UNT_SKIDTRAP:		case UNT_ANKLESNARE:	case UNT_CLAYMORETRAP:
+				case UNT_TALKIEBOX:		case UNT_FREEZINGTRAP:	case UNT_VERDURETRAP:
+				case UNT_ICEBOUNDTRAP:	case UNT_FIRINGTRAP:	case UNT_ELECTRICSHOCKER:
+				case UNT_DISSONANCE:	case UNT_ROKISWEIL:		case UNT_ETERNALCHAOS:
+				case UNT_SUITON:		case UNT_KAEN:
+					skill_delunit(unit);
+					return 1;
+			}
+			break;
 	}
 
 	if (unit->group->skill_id == SA_LANDPROTECTOR && !(skill_get_inf2(skill_id)&(INF2_TRAP)) && !(skill_get_inf3(skill_id)&(INF3_NOLP) ) ) { //It deletes everything except traps and barriers
@@ -17335,9 +17468,9 @@ int skill_produce_mix (struct map_session_data *sd, uint16 skill_id, int nameid,
 				make_per = pc_checkskill(sd,AM_LEARNINGPOTION)*50
 					+ pc_checkskill(sd,AM_PHARMACY)*300 + sd->status.job_level*20
 					+ (status->int_/2)*10 + status->dex*10+status->luk*10;
-				if(merc_is_hom_active(sd->hd)) {//Player got a homun
+				if(hom_is_active(sd->hd)) {//Player got a homun
 					int skill;
-					if((skill=merc_hom_checkskill(sd->hd,HVAN_INSTRUCT)) > 0) //His homun is a vanil with instruction change
+					if((skill=hom_checkskill(sd->hd,HVAN_INSTRUCT)) > 0) //His homun is a vanil with instruction change
 						make_per += skill*100; //+1% bonus per level
 				}
 				switch(nameid){
@@ -18412,6 +18545,7 @@ void skill_init_unit_layout (void) {
 				case MG_FIREWALL:
 				case WZ_ICEWALL:
 				case WL_EARTHSTRAIN://Warlock
+				case RL_FIRE_RAIN:
 					// these will be handled later
 					break;
 				case PR_SANCTUARY:
@@ -18645,6 +18779,32 @@ void skill_init_unit_layout (void) {
 		}
 		pos++;
 	}
+	firerain_unit_pos = pos;
+	for( i = 0; i < 8; i++ ) {
+		skill_unit_layout[pos].count = 3;
+		switch( i ) {
+			case 0: case 1: case 3: case 4: case 5: case 7:
+				{
+					static const int dx[] = {-1, 0, 1};
+					static const int dy[] = { 0, 0, 0};
+
+					memcpy(skill_unit_layout[pos].dx,dx,sizeof(dx));
+					memcpy(skill_unit_layout[pos].dy,dy,sizeof(dy));
+				}
+				break;
+			case 2:
+			case 6:
+				{
+					static const int dx[] = { 0, 0, 0};
+					static const int dy[] = {-1, 0, 1};
+
+					memcpy(skill_unit_layout[pos].dx,dx,sizeof(dx));
+					memcpy(skill_unit_layout[pos].dy,dy,sizeof(dy));
+				}
+				break;
+		}
+		pos++;
+	}
 
 }
 
@@ -19366,8 +19526,7 @@ void skill_reload (void) {
 /*==========================================
  *
  *------------------------------------------*/
-int do_init_skill (void)
-{
+void do_init_skill (void){
 	skilldb_name2id = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, 0);
 	skill_readdb();
 
@@ -19385,12 +19544,9 @@ int do_init_skill (void)
 	add_timer_func_list(skill_blockpc_end, "skill_blockpc_end");
 
 	add_timer_interval(gettick()+SKILLUNITTIMER_INTERVAL,skill_unit_timer,0,0,SKILLUNITTIMER_INTERVAL);
-
-	return 0;
 }
 
-int do_final_skill(void)
-{
+void do_final_skill(void){
 	skill_destroy_requirement();
 	db_destroy(skilldb_name2id);
 	db_destroy(group_db);
@@ -19399,5 +19555,4 @@ int do_final_skill(void)
 	db_destroy(bowling_db);
 	ers_destroy(skill_unit_ers);
 	ers_destroy(skill_timer_ers);
-	return 0;
 }

+ 2 - 2
src/map/skill.h

@@ -283,8 +283,8 @@ extern struct s_skill_abra_db skill_abra_db[MAX_SKILL_ABRA_DB];
 extern int enchant_eff[5];
 extern int deluge_eff[5];
 
-int do_init_skill(void);
-int do_final_skill(void);
+void do_init_skill(void);
+void do_final_skill(void);
 
 /// Cast type
 enum { CAST_GROUND, CAST_DAMAGE, CAST_NODAMAGE };

+ 161 - 123
src/map/status.c

@@ -778,12 +778,12 @@ void initChangeTables(void)
 	add_sc( RL_MASS_SPIRAL		, SC_BLEEDING );
 	add_sc( RL_HAMMER_OF_GOD	, SC_STUN );
 	set_sc( RL_B_TRAP		, SC_B_TRAP		, SI_B_TRAP		, SCB_SPEED );
-	set_sc( RL_E_CHAIN			, SC_E_CHAIN		, SI_E_CHAIN		, SCB_NONE );
-	set_sc_with_vfx( RL_C_MARKER	, SC_C_MARKER	, SI_C_MARKER		, SCB_SPEED );
-	set_sc( RL_P_ALTER			, SC_P_ALTER		, SI_P_ALTER		, SCB_BATK );
-	set_sc( RL_SLUGSHOT		, SC_STUN		, SI_SLUGSHOT		, SCB_NONE );
-	set_sc( RL_AM_BLAST			, SC_ANTI_M_BLAST	, SI_ANTI_M_BLAST	, SCB_DEF_ELE );
-	set_sc( RL_HEAT_BARREL		, SC_HEAT_BARREL	, SI_HEAT_BARREL	, SCB_BATK|SCB_ASPD|SCB_HIT );
+	set_sc( RL_E_CHAIN		, SC_E_CHAIN	, SI_E_CHAIN	, SCB_NONE );
+	set_sc( RL_P_ALTER		, SC_P_ALTER	, SI_P_ALTER	, SCB_BATK );
+	set_sc( RL_SLUGSHOT		, SC_STUN		, SI_SLUGSHOT	, SCB_NONE );
+	set_sc( RL_HEAT_BARREL	, SC_HEAT_BARREL	, SI_HEAT_BARREL	, SCB_BATK|SCB_ASPD|SCB_HIT );
+	set_sc_with_vfx( RL_C_MARKER	, SC_C_MARKER		, SI_C_MARKER		, SCB_SPEED );
+	set_sc_with_vfx( RL_AM_BLAST	, SC_ANTI_M_BLAST	, SI_ANTI_M_BLAST	, SCB_DEF_ELE );
 
 	set_sc_with_vfx( SC_ALL_RIDING		, SC_ALL_RIDING		, SI_ALL_RIDING		, SCB_SPEED );
 
@@ -1357,7 +1357,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in
 	switch (target->type) {
 		case BL_PC:  pc_damage((TBL_PC*)target,src,hp,sp); break;
 		case BL_MOB: mob_damage((TBL_MOB*)target, src, hp); break;
-		case BL_HOM: merc_damage((TBL_HOM*)target); break;
+		case BL_HOM: hom_damage((TBL_HOM*)target); break;
 		case BL_MER: mercenary_heal((TBL_MER*)target,hp,sp); break;
 		case BL_ELEM: elemental_heal((TBL_ELEM*)target,hp,sp); break;
 	}
@@ -1383,7 +1383,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in
 	switch (target->type) {
 		case BL_PC:  flag = pc_dead((TBL_PC*)target,src); break;
 		case BL_MOB: flag = mob_dead((TBL_MOB*)target, src, flag&4?3:0); break;
-		case BL_HOM: flag = merc_hom_dead((TBL_HOM*)target); break;
+		case BL_HOM: flag = hom_dead((TBL_HOM*)target); break;
 		case BL_MER: flag = mercenary_dead((TBL_MER*)target); break;
 		case BL_ELEM: flag = elemental_dead((TBL_ELEM*)target); break;
 		default:	// Unhandled case, do nothing to object.
@@ -1548,7 +1548,7 @@ int status_heal(struct block_list *bl,int64 hhp,int64 hsp, int flag)
 	switch(bl->type) {
 		case BL_PC:  pc_heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
 		case BL_MOB: mob_heal((TBL_MOB*)bl,hp); break;
-		case BL_HOM: merc_hom_heal((TBL_HOM*)bl); break;
+		case BL_HOM: hom_heal((TBL_HOM*)bl); break;
 		case BL_MER: mercenary_heal((TBL_MER*)bl,hp,sp); break;
 		case BL_ELEM: elemental_heal((TBL_ELEM*)bl,hp,sp); break;
 	}
@@ -1665,7 +1665,7 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per
 	switch (bl->type) {
 		case BL_PC:  pc_revive((TBL_PC*)bl, hp, sp); break;
 		case BL_MOB: mob_revive((TBL_MOB*)bl, hp); break;
-		case BL_HOM: merc_hom_revive((TBL_HOM*)bl, hp, sp); break;
+		case BL_HOM: hom_revive((TBL_HOM*)bl, hp, sp); break;
 	}
 	return 1;
 }
@@ -2679,13 +2679,12 @@ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned
 	if (isHP) { //Calculates MaxHP
 		max = job_info[idx].base_hp[level-1] * (1 + (max(stat,1) * 0.01)) * ((sd->class_&JOBL_UPPER)?1.25:1);
 		max += status_get_hpbonus(&sd->bl,STATUS_BONUS_FIX);
-		max = max * (1 + status_get_hpbonus(&sd->bl,STATUS_BONUS_RATE) * 0.01);
+		max *= (1 + status_get_hpbonus(&sd->bl,STATUS_BONUS_RATE) * 0.01);
 	}
 	else { //Calculates MaxSP
-		max = job_info[idx].base_sp[level-1] * (1 + (max(stat,1) * 0.01));
+		max = job_info[idx].base_sp[level-1] * (1 + (max(stat,1) * 0.01)) * ((sd->class_&JOBL_UPPER)?1.25:1);
 		max += status_get_spbonus(&sd->bl,STATUS_BONUS_FIX);
-		max = max * (1 + status_get_spbonus(&sd->bl,STATUS_BONUS_RATE) * 0.01);
-		max = (max * ((sd->class_&JOBL_UPPER)?1.25:1)) + 0.5; //Don't have round()
+		max *= (1 + status_get_spbonus(&sd->bl,STATUS_BONUS_RATE) * 0.01);
 	}
 
 	return cap_value((unsigned int)max,1,UINT_MAX);
@@ -3179,23 +3178,17 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
 	status->max_hp = sd->status.max_hp = status_calc_maxhpsp_pc(sd,status->vit,true);
 	
 	if(battle_config.hp_rate != 100)
-		status->max_hp = (int64)status->max_hp * battle_config.hp_rate/100;
+		status->max_hp = (unsigned int)(battle_config.hp_rate * (status->max_hp/100.));
 
-	if(status->max_hp > (unsigned int)battle_config.max_hp)
-		status->max_hp = battle_config.max_hp;
-	else if(!status->max_hp)
-		status->max_hp = 1;
+	status->max_hp = cap_value(status->max_hp,1,(unsigned int)battle_config.max_hp);
 
 // ----- SP MAX CALCULATION -----
 	status->max_sp = sd->status.max_sp = status_calc_maxhpsp_pc(sd,status->int_,false);
 
 	if(battle_config.sp_rate != 100)
-		status->max_sp = (int64)status->max_sp * battle_config.sp_rate/100;
+		status->max_sp = (unsigned int)(battle_config.sp_rate * (status->max_sp/100.));
 
-	if(status->max_sp > (unsigned int)battle_config.max_sp)
-		status->max_sp = battle_config.max_sp;
-	else if(!status->max_sp)
-		status->max_sp = 1;
+	status->max_sp = cap_value(status->max_sp,1,(unsigned int)battle_config.max_sp);
 
 // ----- RESPAWN HP/SP -----
 
@@ -3617,20 +3610,20 @@ int status_calc_homunculus_(struct homun_data *hd, bool first)
 	status->max_hp = hom->max_hp ;
 	status->max_sp = hom->max_sp ;
 
-	merc_hom_calc_skilltree(hd, 0);
+	hom_calc_skilltree(hd, 0);
 
-	if((skill=merc_hom_checkskill(hd,HAMI_SKIN)) > 0)
+	if((skill=hom_checkskill(hd,HAMI_SKIN)) > 0)
 		status->def +=	skill * 4;
 
-	if((skill = merc_hom_checkskill(hd,HVAN_INSTRUCT)) > 0) {
+	if((skill = hom_checkskill(hd,HVAN_INSTRUCT)) > 0) {
 		status->int_ += 1 +skill/2 +skill/4 +skill/5;
 		status->str  += 1 +skill/3 +skill/3 +skill/4;
 	}
 
-	if((skill=merc_hom_checkskill(hd,HAMI_SKIN)) > 0)
+	if((skill=hom_checkskill(hd,HAMI_SKIN)) > 0)
 		status->max_hp += skill * 2 * status->max_hp / 100;
 
-	if((skill = merc_hom_checkskill(hd,HLIF_BRAIN)) > 0)
+	if((skill = hom_checkskill(hd,HLIF_BRAIN)) > 0)
 		status->max_sp += (1 +skill/2 -skill/4 +skill/5) * status->max_sp / 100 ;
 
 	if (first) {
@@ -3829,11 +3822,11 @@ void status_calc_regen(struct block_list *bl, struct status_data *status, struct
 
 	if( bl->type == BL_HOM ) {
 		struct homun_data *hd = (TBL_HOM*)bl;
-		if( (skill = merc_hom_checkskill(hd,HAMI_SKIN)) > 0 ) {
+		if( (skill = hom_checkskill(hd,HAMI_SKIN)) > 0 ) {
 			val = regen->hp*(100+5*skill)/100;
 			regen->hp = cap_value(val, 1, SHRT_MAX);
 		}
-		if( (skill = merc_hom_checkskill(hd,HLIF_BRAIN)) > 0 ) {
+		if( (skill = hom_checkskill(hd,HLIF_BRAIN)) > 0 ) {
 			val = regen->sp*(100+3*skill)/100;
 			regen->sp = cap_value(val, 1, SHRT_MAX);
 		}
@@ -4282,10 +4275,13 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag)
 	if(flag&SCB_MAXHP) {
 		if( bl->type&BL_PC ) {
 			status->max_hp = status_calc_maxhpsp_pc(sd,status->vit,true);
-			
-			if( status->max_hp > (unsigned int)battle_config.max_hp )
-				status->max_hp = (unsigned int)battle_config.max_hp;
-		} else
+
+			if(battle_config.hp_rate != 100)
+				status->max_hp = (unsigned int)(battle_config.hp_rate * (status->max_hp/100.));
+
+			status->max_hp = min(status->max_hp,(unsigned int)battle_config.max_hp);
+		}
+		else
 			status->max_hp = status_calc_maxhp(bl, b_status->max_hp);
 
 		if( status->hp > status->max_hp ) { // !FIXME: Should perhaps a status_zap should be issued?
@@ -4297,10 +4293,13 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag)
 	if(flag&SCB_MAXSP) {
 		if( bl->type&BL_PC ) {
 			status->max_sp = status_calc_maxhpsp_pc(sd,status->int_,false);
-			
-			if( status->max_sp > (unsigned int)battle_config.max_sp )
-				status->max_sp = (unsigned int)battle_config.max_sp;
-		} else
+
+			if(battle_config.sp_rate != 100)
+				status->max_sp = (unsigned int)(battle_config.sp_rate * (status->max_sp/100.));
+
+			status->max_sp = min(status->max_sp,(unsigned int)battle_config.max_sp);
+		}
+		else
 			status->max_sp = status_calc_maxsp(bl, b_status->max_sp);
 
 		if( status->sp > status->max_sp ) {
@@ -5359,8 +5358,6 @@ static signed short status_calc_hit(struct block_list *bl, struct status_change
 		hit -= hit * 50 / 100;
 	if(sc->data[SC_ILLUSIONDOPING])
 		hit -= hit * (5 + sc->data[SC_ILLUSIONDOPING]->val1) / 100; // Custom
-	if(sc->data[SC_HEAT_BARREL])
-		hit -= sc->data[SC_HEAT_BARREL]->val4;
 	if (sc->data[SC_MTF_ASPD])
 		hit += 5;
 
@@ -5457,6 +5454,10 @@ static signed short status_calc_flee(struct block_list *bl, struct status_change
 		flee += flee * 20 / 100;
 	if (sc->data[SC_TEARGAS])
 		flee -= flee * 50 / 100;
+	if( sc->data[SC_C_MARKER] )
+		flee -= 10;
+	if(sc->data[SC_HEAT_BARREL])
+		flee -= sc->data[SC_HEAT_BARREL]->val4;
 
 	return (short)cap_value(flee,1,SHRT_MAX);
 }
@@ -5829,8 +5830,6 @@ static unsigned short status_calc_speed(struct block_list *bl, struct status_cha
 				val = max( val, sc->data[SC_POWER_OF_GAIA]->val2 );
 			if( sc->data[SC_MELON_BOMB] )
 				val = max( val, sc->data[SC_MELON_BOMB]->val1 );
-			if( sc->data[SC_C_MARKER] )
-				val = max( val, 10 );
 			if( sc->data[SC_B_TRAP] )
 				val = max( val, sc->data[SC_B_TRAP]->val3 );
 
@@ -6202,6 +6201,8 @@ static short status_calc_aspd_rate(struct block_list *bl, struct status_change *
 		aspd_rate += sc->data[SC_PAIN_KILLER]->val2 * 10;
 	if( sc->data[SC_GOLDENE_FERSE])
 		aspd_rate -= sc->data[SC_GOLDENE_FERSE]->val3 * 10;
+	if( sc->data[SC_HEAT_BARREL] )
+		aspd_rate -= sc->data[SC_HEAT_BARREL]->val3 * 10;
 
 	return (short)cap_value(aspd_rate,0,SHRT_MAX);
 }
@@ -6233,7 +6234,6 @@ static unsigned short status_calc_dmotion(struct block_list *bl, struct status_c
 /**
 * Calculates a max HP based on status changes
 * Values can either be percentages or fixed, based on how equations are formulated
-* Examples: maxhp += maxhp * value; (percentage increase)
 * @param bl: Object's block_list data
 * @param maxhp: Object's current max HP
 * @return modified maxhp
@@ -6253,7 +6253,6 @@ static unsigned int status_calc_maxhp(struct block_list *bl, uint64 maxhp)
 /**
 * Calculates a max SP based on status changes
 * Values can either be percentages or fixed, bas ed on how equations are formulated
-* Examples: maxsp += maxsp * value; (percentage increase)
 * @param bl: Object's block_list data
 * @param maxsp: Object's current max SP
 * @return modified maxsp
@@ -6755,9 +6754,9 @@ void status_set_viewdata(struct block_list *bl, int class_)
 	else if (npcdb_checkid(class_) || (bl->type == BL_NPC && class_ == WARP_CLASS))
 		vd = npc_get_viewdata(class_);
 	else if (homdb_checkid(class_))
-		vd = merc_get_hom_viewdata(class_);
-	else if (merc_class(class_))
-		vd = merc_get_viewdata(class_);
+		vd = hom_get_viewdata(class_);
+	else if (mercenary_class(class_))
+		vd = mercenary_get_viewdata(class_);
 	else if (elemental_class(class_))
 		vd = elemental_get_viewdata(class_);
 	else
@@ -7641,6 +7640,20 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 		if(sc->data[SC_HOVERING])
 			return 0;
 		break;
+	case SC_HEAT_BARREL:
+		//kRO Update 2014-02-12
+		//- Cannot be stacked with Platinum Alter and Madness Canceler (and otherwise?) [Cydh]
+		if (sc->data[SC_P_ALTER] || sc->data[SC_MADNESSCANCEL])
+			return 0;
+		break;
+	case SC_P_ALTER:
+		if (sc->data[SC_HEAT_BARREL] || sc->data[SC_MADNESSCANCEL])
+			return 0;
+		break;
+	case SC_MADNESSCANCEL:
+		if (sc->data[SC_P_ALTER] || sc->data[SC_HEAT_BARREL])
+			return 0;
+		break;
 	case SC_C_MARKER:
 		if (src == bl)
 			return 0;
@@ -7655,9 +7668,9 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 
 	// Check for BOSS resistances
 	if(status->mode&MD_BOSS && !(flag&1)) {
-		 if (type>=SC_COMMON_MIN && type <= SC_COMMON_MAX)
-			 return 0;
-		 switch (type) {
+		if (type>=SC_COMMON_MIN && type <= SC_COMMON_MAX)
+			return 0;
+		switch (type) {
 			case SC_BLESSING:
 			case SC_DECREASEAGI:
 			case SC_PROVOKE:
@@ -9075,8 +9088,8 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 				if( pc_isridingwug(sd) ) pc_setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
 				if( pc_isfalcon(sd) ) pc_setoption(sd, sd->sc.option&~OPTION_FALCON);
 				if( sd->status.pet_id > 0 ) pet_menu(sd, 3);
-				if( merc_is_hom_active(sd->hd) ) merc_hom_vaporize(sd,HOM_ST_REST);
-				//if( sd->md ) merc_delete(sd->md,3); // Are Mercenaries removed? [aleos]
+				if( hom_is_active(sd->hd) ) hom_vaporize(sd,HOM_ST_REST);
+				//if( sd->md ) mercenary_delete(sd->md,3); // Are Mercenaries removed? [aleos]
 			}
 			break;
 		case SC__LAZINESS:
@@ -9559,42 +9572,50 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 			break;
 
 		/* Rebellion */
-		case SC_HEAT_BARREL_AFTER:
-		case SC_QD_SHOT_READY:
-			break;
-
 		case SC_B_TRAP:
+			val2 = src->id;
 			val3 = val1 * 25; // -movespeed (custom)
+			break;
 		case SC_C_MARKER:
+			val2 = src->id;
+			//Start timer to send mark on mini map
+			val3 = tick/1000;
+			tick_time = 1000;
+			break;
 		case SC_H_MINE:
 			val2 = src->id;
 			break;
-
 		case SC_HEAT_BARREL:
-			if (sd) {
-				uint8 n = (uint8)sd->spiritball_old;
-				val2 = val1 * n * 4; // +atk (custom)
+			//kRO Update 2014-02-26
+			{
+				short n = 10;
+				if (sd) n = sd->spiritball_old;
+				val2 = val1 * 5; // -fixed casttime (custom)
 				val3 = val1 * n / 5; // +aspd (custom)
-				val4 = val1 * n * 2; // -hit (custom)
+				val4 = 75 - val1 * 5; // -flee
 			}
 			break;
 		case SC_P_ALTER:
-			if (sd) {
-				uint8 n = (uint8)sd->spiritball_old;
+			{
+				short n = 10;
+				if (sd) n = sd->spiritball_old;
 				val2 = val1 * n * 2; // +atk (custom)
 				val3 = val1 * 15; // +def (custom)
 			}
 			break;
 		case SC_E_CHAIN:
+			val2 = 10;
 			if (sd)
 				val2 = (uint8)sd->spiritball_old;
 			break;
 		case SC_ANTI_M_BLAST:
 			val2 = val1 * 10;
+			if (bl->type != BL_PC)
+				val2 /= 5; //(custom) //kRO update 2012-02-12, reduce the rate for Non-Player target [Cydh]
 			break;
 
 		default:
-			if( calc_flag == SCB_NONE && StatusSkillChangeTable[type] == 0 && StatusIconChangeTable[type] == 0 ) {
+			if( calc_flag == SCB_NONE && StatusSkillChangeTable[type] == -1 && StatusIconChangeTable[type] == SI_BLANK ) {
 				// Status change with no calc, no icon, and no skill associated...?
 				ShowError("UnknownStatusChange [%d]\n", type);
 				return 0;
@@ -9946,68 +9967,73 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 
 	 // 1st thing to execute when loading status
 	switch (type) {
-	case SC_FULL_THROTTLE:
-		status_percent_heal(bl,100,0);
-		break;
-	case SC_BERSERK:
-		if (!(sce->val2)) { // Don't heal if already set
-			status_heal(bl, status->max_hp, 0, 1); // Do not use percent_heal as this healing must override BERSERK's block.
-			status_set_sp(bl, 0, 0); // Damage all SP
-		}
-		sce->val2 = 5 * status->max_hp / 100;
-		break;
-	case SC_CHANGE:
-		status_percent_heal(bl, 100, 100);
-		break;
-	case SC_RUN:
-		{
-			struct unit_data *ud = unit_bl2ud(bl);
-			if( ud )
-				ud->state.running = unit_run(bl);
-		}
-		break;
-	case SC_BOSSMAPINFO:
-		clif_bossmapinfo(sd->fd, map_id2boss(sce->val1), 0); // First Message
-		break;
-	case SC_MERC_HPUP:
-		status_percent_heal(bl, 100, 0); // Recover Full HP
-		break;
-	case SC_MERC_SPUP:
-		status_percent_heal(bl, 0, 100); // Recover Full SP
-		break;
-	case SC_WUGDASH:
-		{
-			struct unit_data *ud = unit_bl2ud(bl);
-			if( ud )
-				ud->state.running = unit_wugdash(bl, sd);
-		}
-		break;
-	case SC_COMBO:
-		switch(sce->val1) {
-		case TK_STORMKICK:
-			clif_skill_nodamage(bl,bl,TK_READYSTORM,1,1);
+		case SC_FULL_THROTTLE:
+			status_percent_heal(bl,100,0);
+			break;
+		case SC_BERSERK:
+			if (!(sce->val2)) { // Don't heal if already set
+				status_heal(bl, status->max_hp, 0, 1); // Do not use percent_heal as this healing must override BERSERK's block.
+				status_set_sp(bl, 0, 0); // Damage all SP
+			}
+			sce->val2 = 5 * status->max_hp / 100;
+			break;
+		case SC_CHANGE:
+			status_percent_heal(bl, 100, 100);
 			break;
-		case TK_DOWNKICK:
-			clif_skill_nodamage(bl,bl,TK_READYDOWN,1,1);
+		case SC_RUN:
+			{
+				struct unit_data *ud = unit_bl2ud(bl);
+				if( ud )
+					ud->state.running = unit_run(bl);
+			}
 			break;
-		case TK_TURNKICK:
-			clif_skill_nodamage(bl,bl,TK_READYTURN,1,1);
+		case SC_BOSSMAPINFO:
+			clif_bossmapinfo(sd->fd, map_id2boss(sce->val1), 0); // First Message
 			break;
-		case TK_COUNTER:
-			clif_skill_nodamage(bl,bl,TK_READYCOUNTER,1,1);
+		case SC_MERC_HPUP:
+			status_percent_heal(bl, 100, 0); // Recover Full HP
 			break;
-		default: // Rest just toogle inf to enable autotarget
-			skill_combo_toogle_inf(bl,sce->val1,INF_SELF_SKILL);
+		case SC_MERC_SPUP:
+			status_percent_heal(bl, 0, 100); // Recover Full SP
+			break;
+		case SC_WUGDASH:
+			{
+				struct unit_data *ud = unit_bl2ud(bl);
+				if( ud )
+					ud->state.running = unit_wugdash(bl, sd);
+			}
+			break;
+		case SC_COMBO:
+			switch(sce->val1) {
+			case TK_STORMKICK:
+				clif_skill_nodamage(bl,bl,TK_READYSTORM,1,1);
+				break;
+			case TK_DOWNKICK:
+				clif_skill_nodamage(bl,bl,TK_READYDOWN,1,1);
+				break;
+			case TK_TURNKICK:
+				clif_skill_nodamage(bl,bl,TK_READYTURN,1,1);
+				break;
+			case TK_COUNTER:
+				clif_skill_nodamage(bl,bl,TK_READYCOUNTER,1,1);
+				break;
+			default: // Rest just toogle inf to enable autotarget
+				skill_combo_toogle_inf(bl,sce->val1,INF_SELF_SKILL);
+				break;
+			}
+			break;
+		case SC_RAISINGDRAGON:
+			sce->val2 = status->max_hp / 100; // Officially tested its 1%hp drain. [Jobbie]
+			break;
+		case SC_EQC:
+			sc_start2(src, bl,SC_STUN,100,val1,bl->id,(1000*status_get_lv(src))/50+500*val1);
+			status_change_end(bl,SC_TINDER_BREAKER2,INVALID_TIMER);
+			break;
+		case SC_C_MARKER:
+			//Send mini-map, don't wait for first timer triggered
+			if (src->type == BL_PC && (sd = map_id2sd(src->id)))
+				clif_crimson_marker(sd->fd,bl,false);
 			break;
-		}
-		break;
-	case SC_RAISINGDRAGON:
-		sce->val2 = status->max_hp / 100; // Officially tested its 1%hp drain. [Jobbie]
-		break;
-	case SC_EQC:
-		sc_start2(src, bl,SC_STUN,100,val1,bl->id,(1000*status_get_lv(src))/50+500*val1);
-		status_change_end(bl,SC_TINDER_BREAKER2,INVALID_TIMER);
-		break;
 	}
 
 	if( opt_flag&2 && sd && sd->touching_id )
@@ -10633,8 +10659,10 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
 				if (!caster || !&caster->c_marker || !caster->c_marker.target)
 					break;
 				ARR_FIND(0,MAX_SKILL_CRIMSON_MARKER,i,caster->c_marker.target[i] == bl->id);
-				if (i < MAX_SKILL_CRIMSON_MARKER)
+				if (i < MAX_SKILL_CRIMSON_MARKER) {
 					caster->c_marker.target[i] = 0;
+					clif_crimson_marker(caster->fd,bl,true);
+				}
 			}
 			break;
 		case SC_H_MINE:
@@ -11718,6 +11746,16 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
 			return 0;
 		}
 		break;
+	case SC_C_MARKER:
+		if( --(sce->val3) > 0 ) {
+			TBL_PC *tsd = map_id2sd(sce->val2);
+			if (!tsd || tsd->bl.m != bl->m) //End the SC if caster isn't in same map
+				break;
+			sc_timer_next(1000 + tick, status_change_timer, bl->id, data);
+			clif_crimson_marker(tsd->fd,bl,false);
+			return 0;
+		}
+		break;
 	}
 
 	// Default for all non-handled control paths is to end the status

+ 1 - 3
src/map/storage.c

@@ -68,10 +68,8 @@ static void storage_sortitem(struct item* items, unsigned int size)
  * Called from map.c::do_init()
  * @return 1
  */
-int do_init_storage(void) // 
-{
+void do_init_storage(void){
 	guild_storage_db=idb_alloc(DB_OPT_RELEASE_DATA);
-	return 1;
 }
 
 /**

+ 1 - 1
src/map/storage.h

@@ -18,7 +18,7 @@ int storage_storageget(struct map_session_data *sd,int index,int amount);
 int storage_storageaddfromcart(struct map_session_data *sd,int index,int amount);
 int storage_storagegettocart(struct map_session_data *sd,int index,int amount);
 void storage_storageclose(struct map_session_data *sd);
-int do_init_storage(void);
+void do_init_storage(void);
 void do_final_storage(void);
 void do_reconnect_storage(void);
 void storage_storage_quit(struct map_session_data *sd, int flag);

+ 6 - 10
src/map/unit.c

@@ -2556,7 +2556,7 @@ void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype)
 
 	if(sd->pd)
 		unit_remove_map(&sd->pd->bl, clrtype);
-	if(merc_is_hom_active(sd->hd))
+	if(hom_is_active(sd->hd))
 		unit_remove_map(&sd->hd->bl, clrtype);
 	if(sd->md)
 		unit_remove_map(&sd->md->bl, clrtype);
@@ -2752,9 +2752,9 @@ int unit_free(struct block_list *bl, clr_type clrtype)
 		{
 			struct homun_data *hd = (TBL_HOM*)bl;
 			struct map_session_data *sd = hd->master;
-			merc_hom_hungry_timer_delete(hd);
+			hom_hungry_timer_delete(hd);
 			if( hd->homunculus.intimacy > 0 )
-				merc_save(hd);
+				hom_save(hd);
 			else {
 				intif_homunculus_requestdelete(hd->homunculus.hom_id);
 				if( sd )
@@ -2778,7 +2778,7 @@ int unit_free(struct block_list *bl, clr_type clrtype)
 			if( sd )
 				sd->md = NULL;
 
-			merc_contract_stop(md);
+			mercenary_contract_stop(md);
 			break;
 		}
 		case BL_ELEM: {
@@ -2812,15 +2812,13 @@ int unit_free(struct block_list *bl, clr_type clrtype)
  * Initialization function for unit on map start
  * called in map::do_init
  */
-int do_init_unit(void)
-{
+void do_init_unit(void){
 	add_timer_func_list(unit_attack_timer,  "unit_attack_timer");
 	add_timer_func_list(unit_walktoxy_timer,"unit_walktoxy_timer");
 	add_timer_func_list(unit_walktobl_sub, "unit_walktobl_sub");
 	add_timer_func_list(unit_delay_walktoxy_timer,"unit_delay_walktoxy_timer");
 	add_timer_func_list(unit_delay_walktobl_timer,"unit_delay_walktobl_timer");
 	add_timer_func_list(unit_teleport_timer,"unit_teleport_timer");
-	return 0;
 }
 
 /**
@@ -2828,8 +2826,6 @@ int do_init_unit(void)
  * called in map::do_final
  * @return 0
  */
-int do_final_unit(void)
-{
+void do_final_unit(void){
 	// Nothing to do
-	return 0;
 }

+ 2 - 2
src/map/unit.h

@@ -133,8 +133,8 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
 int unit_free(struct block_list *bl, clr_type clrtype);
 int unit_changeviewsize(struct block_list *bl,short size);
 
-int do_init_unit(void);
-int do_final_unit(void);
+void do_init_unit(void);
+void do_final_unit(void);
 
 
 #endif /* _UNIT_H_ */