From 43d82332dbfde84bf0348ef6c2921aaaef24634e Mon Sep 17 00:00:00 2001
From: shennetsind <ind@henn.et>
Date: Tue, 7 May 2013 22:15:05 -0300
Subject: Fixed Bug #7223

http://hercules.ws/board/tracker/issue-7223-homunculus-s-max-level-overshooting/
src/map/homunculus.c Hercules Renewal Phase One complete.
http://hercules.ws/board/topic/237-hercules-renewal/

Signed-off-by: shennetsind <ind@henn.et>
---
 src/map/atcommand.c  |  53 ++--
 src/map/battle.c     |   4 +-
 src/map/chrif.c      |   4 +-
 src/map/clif.c       |  63 ++---
 src/map/homunculus.c | 697 ++++++++++++++++++++++++++-------------------------
 src/map/homunculus.h | 150 +++++------
 src/map/intif.c      |  13 +-
 src/map/intif.h      |   2 +-
 src/map/map.c        |   4 +-
 src/map/mob.c        |   7 +-
 src/map/pc.c         |  14 +-
 src/map/script.c     |  30 ++-
 src/map/skill.c      |  18 +-
 src/map/status.c     |  38 ++-
 src/map/unit.c       |   9 +-
 15 files changed, 564 insertions(+), 542 deletions(-)

(limited to 'src')

diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 33e0d03cb..1877571e0 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -3596,12 +3596,11 @@ ACMD(reloaditemdb)
 /*==========================================
  *
  *------------------------------------------*/
-ACMD(reloadmobdb)
-{
+ACMD(reloadmobdb) {
 	nullpo_retr(-1, sd);
 	mob_reload();
 	read_petdb();
-	merc_reload();
+	homun->reload();
 	read_mercenarydb();
 	read_mercenary_skilldb();
 	reload_elementaldb();
@@ -3617,7 +3616,7 @@ ACMD(reloadskilldb)
 {
 	nullpo_retr(-1, sd);
 	skill->reload();
-	merc_skill_reload();
+	homun->reload_skill();
 	reload_elemental_skilldb();
 	read_mercenary_skilldb();
 	clif->message(fd, msg_txt(99)); // Skill database has been reloaded.
@@ -5410,7 +5409,7 @@ ACMD(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 && homun_alive(sd->hd)) // (If used with @useskill, put the homunc as dest)
 		bl = &sd->hd->bl;
 	else
 		bl = &sd->bl;
@@ -6850,7 +6849,7 @@ ACMD(homlevel)
 		return false;
 	}
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -6862,7 +6861,7 @@ ACMD(homlevel)
 	
 	do{
 		hd->homunculus.exp += hd->exp_next;
-	}while( hd->homunculus.level < level && merc_hom_levelup(hd) );
+	} while( hd->homunculus.level < level && homun->levelup(hd) );
 	
 	status_calc_homunculus(hd,0);
 	status_percent_heal(&hd->bl, 100, 100);
@@ -6877,12 +6876,12 @@ ACMD(homevolution)
 {
 	nullpo_retr(-1, sd);
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
 	
-	if ( !merc_hom_evolution(sd->hd) ) {
+	if ( !homun->evolve(sd->hd) ) {
 		clif->message(fd, msg_txt(1255)); // Your homunculus doesn't evolve.
 		return false;
 	}
@@ -6890,12 +6889,12 @@ ACMD(homevolution)
 	return true;
 }
 
-ACMD(hommutate)
-{
-	int homun_id, m_class = 0, m_id;
+ACMD(hommutate) {
+	int homun_id;
+	enum homun_type m_class, m_id;
 	nullpo_retr(-1, sd);
 	
-	if (!merc_is_hom_active(sd->hd)) {
+	if (!homun_alive(sd->hd)) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -6906,11 +6905,11 @@ ACMD(hommutate)
 		homun_id = atoi(message);
 	}
 	
-	m_class = hom_class2mapid(sd->hd->homunculus.class_);
-	m_id	= hom_class2mapid(homun_id);
+	m_class = homun->class2type(sd->hd->homunculus.class_);
+	m_id	= homun->class2type(homun_id);
 	
-	if (m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99) {
-		hom_mutate(sd->hd, homun_id);
+	if (m_class != -1 && m_id != -1 && m_class == HT_EVO && m_id == HT_S && sd->hd->homunculus.level >= 99) {
+		homun->mutate(sd->hd, homun_id);
 	} else {
 		clif->emotion(&sd->hd->bl, E_SWT);
 	}
@@ -6920,8 +6919,7 @@ ACMD(hommutate)
 /*==========================================
  * call choosen homunculus [orn]
  *------------------------------------------*/
-ACMD(makehomun)
-{
+ACMD(makehomun) {
 	int homunid;
 	nullpo_retr(-1, sd);
 	
@@ -6942,7 +6940,7 @@ ACMD(makehomun)
 		return false;
 	}
 	
-	merc_create_homunculus_request(sd,homunid);
+	homun->creation_request(sd,homunid);
 	return true;
 }
 
@@ -6955,7 +6953,7 @@ ACMD(homfriendly)
 	
 	nullpo_retr(-1, sd);
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -6982,7 +6980,7 @@ ACMD(homhungry)
 	
 	nullpo_retr(-1, sd);
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -7020,7 +7018,7 @@ ACMD(homtalk)
 		 (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
 		return false;
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -7045,7 +7043,7 @@ ACMD(hominfo)
 	struct status_data *status;
 	nullpo_retr(-1, sd);
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -7084,7 +7082,7 @@ ACMD(homstats)
 	
 	nullpo_retr(-1, sd);
 	
-	if ( !merc_is_hom_active(sd->hd) ) {
+	if ( !homun_alive(sd->hd) ) {
 		clif->message(fd, msg_txt(1254)); // You do not have a homunculus.
 		return false;
 	}
@@ -7144,14 +7142,13 @@ ACMD(homstats)
 	return true;
 }
 
-ACMD(homshuffle)
-{
+ACMD(homshuffle) {
 	nullpo_retr(-1, sd);
 	
 	if(!sd->hd)
 		return false; // nothing to do
 	
-	if(!merc_hom_shuffle(sd->hd))
+	if(!homun->shuffle(sd->hd))
 		return false;
 	
 	clif->message(sd->fd, msg_txt(1275)); // Homunculus stats altered.
diff --git a/src/map/battle.c b/src/map/battle.c
index 796938926..02b88eff6 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -1134,7 +1134,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
 			pc_addspiritball(sd,skill->get_time(LG_FORCEOFVANGUARD,sce->val1),sce->val3);
 		if (sc->data[SC_STYLE_CHANGE] && rnd()%2) {
                     TBL_HOM *hd = BL_CAST(BL_HOM,bl);
-                    if (hd) hom_addspiritball(hd, 10); //add a sphere
+                    if (hd) homun->addspiritball(hd, 10); //add a sphere
                 }
 
 		if( sc->data[SC__DEADLYINFECT] && damage > 0 && rnd()%100 < 65 + 5 * sc->data[SC__DEADLYINFECT]->val1 )
@@ -1195,7 +1195,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
 			status_change_spread(src, bl);
                 if (sc->data[SC_STYLE_CHANGE] && rnd()%2) {
                     TBL_HOM *hd = BL_CAST(BL_HOM,bl);
-                    if (hd) hom_addspiritball(hd, 10);
+                    if (hd) homun->addspiritball(hd, 10);
                 }
 	}
 	/* no data claims these settings affect anything other than players */
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 69fc79bb8..eed7ba2a6 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -310,8 +310,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 && homun_alive(sd->hd) )
+		homun->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 )
diff --git a/src/map/clif.c b/src/map/clif.c
index 8837dc274..f391cdf2b 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1393,16 +1393,15 @@ int clif_spawn(struct block_list *bl)
 
 /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
 /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W
-void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
-{
+void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag) {
 	struct status_data *status;
 	unsigned char buf[128];
-	int m_class;
+	enum homun_type htype;
 
 	nullpo_retv(hd);
 
 	status  = &hd->battle_status;
-	m_class = hom_class2mapid(hd->homunculus.class_);
+	htype = homun->class2type(hd->homunculus.class_);
 
 	memset(buf,0,packet_len(0x22e));
 	WBUFW(buf,0)=0x22e;
@@ -1439,10 +1438,18 @@ void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
 		WBUFW(buf,57)=status->max_sp;
 	}
 	WBUFL(buf,59)=hd->homunculus.exp;
-	if( ((m_class&HOM_REG) && hd->homunculus.level >= battle_config.hom_max_level) || ((m_class&HOM_S) && hd->homunculus.level >= battle_config.hom_S_max_level) )
-		WBUFL(buf,63)=0;
-	else
-		WBUFL(buf,63)=hd->exp_next;
+	WBUFL(buf,63)=hd->exp_next;
+	switch( htype ) {
+		case HT_REG:
+		case HT_EVO:
+			if( hd->homunculus.level >= battle_config.hom_max_level )
+				WBUFL(buf,63)=0;
+			break;
+		case HT_S:
+			if( hd->homunculus.level >= battle_config.hom_S_max_level )
+				WBUFL(buf,63)=0;
+			break;
+	}
 	WBUFW(buf,67)=hd->homunculus.skillpts;
 	WBUFW(buf,69)=status_get_range(&hd->bl);
 	clif->send(buf,packet_len(0x22e),&sd->bl,SELF);
@@ -1464,7 +1471,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);
+		homun->calc_skilltree(sd->hd, 0);
 
 	WFIFOHEAD(fd, packet_len(0x230));
 	WFIFOW(fd,0)=0x230;
@@ -1476,8 +1483,7 @@ void clif_send_homdata(struct map_session_data *sd, int state, int param)
 }
 
 
-int clif_homskillinfoblock(struct map_session_data *sd)
-{	//[orn]
+int clif_homskillinfoblock(struct map_session_data *sd) { //[orn]
 	struct homun_data *hd;
 	int fd = sd->fd;
 	int i,j,len=4,id;
@@ -1498,7 +1504,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 < homun->skill_tree_get_max(id, hd->homunculus.class_))?1:0;
 			len+=37;
 		}
 	}
@@ -1508,8 +1514,7 @@ int clif_homskillinfoblock(struct map_session_data *sd)
 	return 0;
 }
 
-void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
-{	//[orn]
+void clif_homskillup(struct map_session_data *sd, uint16 skill_id) { //[orn]
 	struct homun_data *hd;
 	int fd, idx;
 	nullpo_retv(sd);
@@ -8459,7 +8464,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(homun_alive(sd->hd))
 		clif->send_homdata(sd,SP_ACK,0);
 	if( sd->md ) {
 		clif->mercenary_info(sd);
@@ -9385,7 +9390,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 	}
 
 	//homunculus [blackhole89]
-	if( merc_is_hom_active(sd->hd) ) {
+	if( homun_alive(sd->hd) ) {
 		map_addblock(&sd->hd->bl);
 		clif->spawn(&sd->hd->bl);
 		clif->send_homdata(sd,SP_ACK,0);
@@ -9449,8 +9454,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(homun_alive(sd->hd))
+			homun->init_timers(sd->hd);
 
 		if (night_flag && map[sd->bl.m].flag.nightenabled) {
 			sd->state.night = 1;
@@ -11036,7 +11041,7 @@ void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_dat
 	} else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
 		return;
 
-	lv = merc_hom_checkskill(hd, skill_id);
+	lv = homun->checkskill(hd, skill_id);
 	if( skill_lv > lv )
 		skill_lv = lv;
 	if( skill_lv )
@@ -11057,7 +11062,7 @@ void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_da
 
 	if( hd->sc.data[SC_BASILICA] )
 		return;
-	lv = merc_hom_checkskill(hd, skill_id);
+	lv = homun->checkskill(hd, skill_id);
 	if( skill_lv > lv )
 		skill_lv = lv;
 	if( skill_lv )
@@ -13664,9 +13669,8 @@ 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,2));
+void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) {
+	homun->change_name(sd,(char*)RFIFOP(fd,2));
 }
 
 
@@ -13680,7 +13684,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( homun_alive(sd->hd) && sd->hd->bl.id == id )
 		bl = &sd->hd->bl; // Moving Homunculus
 	else
 		return;
@@ -13703,7 +13707,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( homun_alive(sd->hd) && sd->hd->bl.id == id )
 		bl = &sd->hd->bl; // Moving Homunculus
 	else
 		return;
@@ -13723,7 +13727,7 @@ void clif_parse_HomAttack(int fd,struct map_session_data *sd)
 		target_id = RFIFOL(fd,6),
 		action_type = RFIFOB(fd,10);
 
-	if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
+	if( homun_alive(sd->hd) && sd->hd->bl.id == id )
 		bl = &sd->hd->bl;
 	else if( sd->md && sd->md->bl.id == id )
 		bl = &sd->md->bl;
@@ -13742,16 +13746,15 @@ void clif_parse_HomAttack(int fd,struct map_session_data *sd)
 ///     0 = homunculus information
 ///     1 = feed
 ///     2 = delete
-void clif_parse_HomMenu(int fd, struct map_session_data *sd)
-{	//[orn]
+void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
 	int cmd;
 
 	cmd = RFIFOW(fd,0);
 
-	if(!merc_is_hom_active(sd->hd))
+	if(!homun_alive(sd->hd))
 		return;
 
-	merc_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
+	homun->menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
 }
 
 
diff --git a/src/map/homunculus.c b/src/map/homunculus.c
index 904b773eb..6e9ce58b6 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -40,50 +40,41 @@
 #include <string.h>
 #include <math.h>
 
-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 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_)
-{	//Returns the viewdata for homunculus
+//Returns the viewdata for homunculus
+struct view_data* homunculus_get_viewdata(int class_) {
 	if (homdb_checkid(class_))
-		return &hom_viewdb[class_-HM_CLASS_BASE];
+		return &homun->viewdb[class_-HM_CLASS_BASE];
 	return NULL;
 }
 
-int hom_class2mapid(int hom_class)
-{
-	switch(hom_class)
-	{
+enum homun_type homunculus_class2type(int class_) {
+	switch(class_) {
 		// Normal Homunculus
-		case 6001: case 6005:                return MAPID_LIF;
-		case 6002: case 6006:                return MAPID_AMISTR;
-		case 6003: case 6007:                return MAPID_FILIR;
-		case 6004: case 6008:                return MAPID_VANILMIRTH;
+		case 6001: case 6005:
+		case 6002: case 6006:
+		case 6003: case 6007:
+		case 6004: case 6008:
+			return HT_REG;
 		// Evolved Homunculus
-		case 6009: case 6013:                return MAPID_LIF_E;
-		case 6010: case 6014:                return MAPID_AMISTR_E;
-		case 6011: case 6015:                return MAPID_FILIR_E;
-		case 6012: case 6016:                return MAPID_VANILMIRTH_E;
+		case 6009: case 6013:
+		case 6010: case 6014:
+		case 6011: case 6015:
+		case 6012: case 6016:
+			return HT_EVO;
 		// Homunculus S
-		case 6048:                           return MAPID_EIRA;
-		case 6049:                           return MAPID_BAYERI;
-		case 6050:                           return MAPID_SERA;
-		case 6051:                           return MAPID_DIETER;
-		case 6052:                           return MAPID_ELANOR;
-
-		default:                             return -1;
+		case 6048:
+		case 6049:
+		case 6050:
+		case 6051:
+		case 6052:
+			return HT_S;
+		default:
+			return -1;
 	}
 }
 
-int hom_addspiritball(TBL_HOM *hd, int max) {
-    nullpo_ret(hd);
+void homunculus_addspiritball(struct homun_data *hd, int max) {
+    nullpo_retv(hd);
 
     if (max > MAX_SKILL_LEVEL)
         max = MAX_SKILL_LEVEL;
@@ -97,19 +88,17 @@ int hom_addspiritball(TBL_HOM *hd, int max) {
         hd->homunculus.spiritball++;
 
     clif->spiritball(&hd->bl);
-
-    return 0;
 }
 
-int hom_delspiritball(TBL_HOM *hd, int count, int type) {
-    nullpo_ret(hd);
+void homunculus_delspiritball(struct homun_data *hd, int count, int type) {
+    nullpo_retv(hd);
 
     if (hd->homunculus.spiritball <= 0) {
         hd->homunculus.spiritball = 0;
-        return 0;
+        return;
     }
     if (count <= 0)
-        return 0;
+        return;
     if (count > MAX_SKILL_LEVEL)
         count = MAX_SKILL_LEVEL;
     if (count > hd->homunculus.spiritball)
@@ -118,23 +107,20 @@ int hom_delspiritball(TBL_HOM *hd, int count, int type) {
     hd->homunculus.spiritball -= count;
     if (!type)
         clif->spiritball(&hd->bl);
-
-    return 0;
 }
 
-void merc_damage(struct homun_data *hd) {
+void homunculus_damaged(struct homun_data *hd) {
 	clif->hominfo(hd->master,hd,0);
 }
 
-int merc_hom_dead(struct homun_data *hd)
-{
+int homunculus_dead(struct homun_data *hd) {
 	//There's no intimacy penalties on death (from Tharis)
 	struct map_session_data *sd = hd->master;
 
 	clif->emotion(&hd->bl, E_WAH);
 
 	//Delete timers when dead.
-	merc_hom_hungry_timer_delete(hd);
+	homun->hunger_timer_delete(hd);
 	hd->homunculus.hp = 0;
 
 	if (!sd) //unit remove map will invoke unit free
@@ -146,8 +132,7 @@ int merc_hom_dead(struct homun_data *hd)
 }
 
 //Vaporize a character's homun. If flag, HP needs to be 80% or above.
-int merc_hom_vaporize(struct map_session_data *sd, int flag)
-{
+int homunculus_vaporize(struct map_session_data *sd, int flag) {
 	struct homun_data *hd;
 
 	nullpo_ret(sd);
@@ -164,19 +149,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);
+	homun->hunger_timer_delete(hd);
 	hd->homunculus.vaporize = 1;
 	if(battle_config.hom_setting&0x40)
 		memset(hd->blockskill, 0, sizeof(hd->blockskill));
 	clif->hominfo(sd, sd->hd, 0);
-	merc_save(hd);
+	homun->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 homunculus_delete(struct homun_data *hd, int emote) {
 	struct map_session_data *sd;
 	nullpo_ret(hd);
 	sd = hd->master;
@@ -195,8 +179,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 homunculus_calc_skilltree(struct homun_data *hd, int flag_evolve) {
 	int i, id = 0;
 	int j, f = 1;
 	int c = 0;
@@ -206,13 +189,13 @@ int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
 	if( hd->homunculus.prev_class != 0 ) {
 		c = hd->homunculus.prev_class - HM_CLASS_BASE;
 
-		for( i = 0; i < MAX_SKILL_TREE && ( id = hskill_tree[c][i].id ) > 0; i++ ) {
+		for( i = 0; i < MAX_SKILL_TREE && ( id = homun->skill_tree[c][i].id ) > 0; i++ ) {
 			if( hd->homunculus.hskill[ id - HM_SKILLBASE ].id )
 				continue; //Skill already known.
 			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 ) {
+					if( homun->skill_tree[c][i].need[j].id &&
+					   homun->checkskill(hd,homun->skill_tree[c][i].need[j].id) < homun->skill_tree[c][i].need[j].lv ) {
 						f = 0;
 						break;
 					}
@@ -227,16 +210,16 @@ int merc_hom_calc_skilltree(struct homun_data *hd, int flag_evolve)
 
 	c = hd->homunculus.class_ - HM_CLASS_BASE;
 
-	for( i = 0; i < MAX_SKILL_TREE && ( id = hskill_tree[c][i].id ) > 0; i++ ) {
+	for( i = 0; i < MAX_SKILL_TREE && ( id = homun->skill_tree[c][i].id ) > 0; i++ ) {
 		if( hd->homunculus.hskill[ id - HM_SKILLBASE ].id )
 			continue; //Skill already known.
 		j = ( flag_evolve ) ? 10 : hd->homunculus.intimacy;
-		if( j < hskill_tree[c][i].intimacylv )
+		if( j < homun->skill_tree[c][i].intimacylv )
 			continue;
 		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 ) {
+				if( homun->skill_tree[c][i].need[j].id &&
+					homun->checkskill(hd,homun->skill_tree[c][i].need[j].id) < homun->skill_tree[c][i].need[j].lv ) {
 					f = 0;
 					break;
 				}
@@ -251,8 +234,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 homunculus_checkskill(struct homun_data *hd,uint16 skill_id) {
 	int i = skill_id - HM_SKILLBASE;
 	if(!hd)
 		return 0;
@@ -263,17 +245,16 @@ 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 homunculus_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++)
+	for(i=0;(skill_id=homun->skill_tree[b_class][i].id)>0;i++)
 		if (id == skill_id)
-			return hskill_tree[b_class][i].max;
+			return homun->skill_tree[b_class][i].max;
 	return skill->get_max(id);
 }
 
-void merc_hom_skillup(struct homun_data *hd,uint16 skill_id)
-{
+void homunculus_skillup(struct homun_data *hd,uint16 skill_id) {
 	int i = 0 ;
 	nullpo_retv(hd);
 
@@ -284,7 +265,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 < homun->skill_tree_get_max(skill_id, hd->homunculus.class_)
 		)
 	{
 		hd->homunculus.hskill[i].lv++;
@@ -298,29 +279,40 @@ void merc_hom_skillup(struct homun_data *hd,uint16 skill_id)
 	}
 }
 
-int merc_hom_levelup(struct homun_data *hd)
-{
+bool homunculus_levelup(struct homun_data *hd) {
 	struct s_homunculus *hom;
 	struct h_stats *min, *max;
 	int growth_str, growth_agi, growth_vit, growth_int, growth_dex, growth_luk ;
-	int growth_max_hp, growth_max_sp ;
-	int m_class;
+	int growth_max_hp, growth_max_sp;
+	enum homun_type htype;
 
-	if((m_class = hom_class2mapid(hd->homunculus.class_)) == -1) {
-		ShowError("merc_hom_levelup: Invalid class %d. \n", hd->homunculus.class_);
-		return 0;
+	if((htype = homun->class2type(hd->homunculus.class_)) == -1) {
+		ShowError("homunculus_levelup: Invalid class %d. \n", hd->homunculus.class_);
+		return false;
 	}
-
-	if((m_class&HOM_REG) && (hd->homunculus.level >= battle_config.hom_max_level || ((m_class&HOM_S) && hd->homunculus.level >= battle_config.hom_S_max_level) || !hd->exp_next || hd->homunculus.exp < hd->exp_next))
-		return 0;
-
+	
+	if( !hd->exp_next || hd->homunculus.exp < hd->exp_next )
+		return false;
+	
+	switch( htype ) {
+		case HT_REG:
+		case HT_EVO:
+			if( hd->homunculus.level >= battle_config.hom_max_level )
+				return false;
+			break;
+		case HT_S:
+			if( hd->homunculus.level >= battle_config.hom_S_max_level )
+				return false;
+			break;
+	}
+		
 	hom = &hd->homunculus;
 	hom->level++ ;
 	if (!(hom->level % 3))
-		hom->skillpts++ ;	//1 skillpoint each 3 base level
+		hom->skillpts++;	//1 skillpoint each 3 base level
 
-	hom->exp -= hd->exp_next ;
-	hd->exp_next = hexptbl[hom->level - 1] ;
+	hom->exp -= hd->exp_next;
+	hd->exp_next = homun->exptable[hom->level - 1];
 
 	max  = &hd->homunculusDB->gmax;
 	min  = &hd->homunculusDB->gmin;
@@ -360,41 +352,39 @@ 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 true;
 }
 
-int merc_hom_change_class(struct homun_data *hd, short class_)
-{
+int homunculus_change_class(struct homun_data *hd, short class_) {
 	int i;
-	i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS);
+	i = homun->db_search(class_,HOMUNCULUS_CLASS);
 	if(i < 0)
 		return 0;
-	hd->homunculusDB = &homunculus_db[i];
+	hd->homunculusDB = &homun->db[i];
 	hd->homunculus.class_ = class_;
 	status_set_viewdata(&hd->bl, class_);
-	merc_hom_calc_skilltree(hd, 1);
+	homun->calc_skilltree(hd, 1);
 	return 1;
 }
 
-int merc_hom_evolution(struct homun_data *hd)
-{
+bool homunculus_evolve(struct homun_data *hd) {
 	struct s_homunculus *hom;
 	struct h_stats *max, *min;
 	struct map_session_data *sd;
 	nullpo_ret(hd);
 
-	if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class)
-	{
-		clif->emotion(&hd->bl, E_SWT);
-		return 0 ;
-	}
 	sd = hd->master;
 	if (!sd)
-		return 0;
+		return false;
+	
+	if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) {
+		clif->emotion(&hd->bl, E_SWT);
+		return false;
+	}
 
-	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);
-		return 0;
+	if (!homun->change_class(hd, hd->homunculusDB->evo_class)) {
+		ShowError("homunculus_evolve: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class);
+		return false;
 	}
 
 	//Apply evolution bonuses
@@ -426,33 +416,33 @@ int merc_hom_evolution(struct homun_data *hd)
 	if (!(battle_config.hom_setting&0x2))
 		skill->unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
 
-	return 1 ;
+	return true;
 }
 
-int hom_mutate(struct homun_data *hd, int homun_id)
-{
+bool homunculus_mutate(struct homun_data *hd, int homun_id) {
 	struct s_homunculus *hom;
 	struct map_session_data *sd;
-	int m_class, m_id, prev_class = 0;
+	int prev_class = 0;
+	enum homun_type m_class, m_id;
 	nullpo_ret(hd);
 
-	m_class = hom_class2mapid(hd->homunculus.class_);
-	m_id    = hom_class2mapid(homun_id);
+	sd = hd->master;
+	if (!sd)
+		return false;
+	
+	m_class = homun->class2type(hd->homunculus.class_);
+	m_id    = homun->class2type(homun_id);
 
-	if( m_class == -1 || m_id == -1 || !(m_class&HOM_EVO) || !(m_id&HOM_S) ) {
+	if( m_class == -1 || m_id == -1 || m_class != HT_EVO || m_id != HT_S ) {
 		clif->emotion(&hd->bl, E_SWT);
-		return 0;
+		return false;
 	}
 
-	sd = hd->master;
-	if (!sd)
-		return 0;
-
 	prev_class = hd->homunculus.class_;
 
-	if (!merc_hom_change_class(hd, homun_id)) {
-		ShowError("hom_mutate: Can't evolve homunc from %d to %d", hd->homunculus.class_, homun_id);
-		return 0;
+	if (!homun->change_class(hd, homun_id)) {
+		ShowError("homunculus_mutate: Can't evolve homunc from %d to %d", hd->homunculus.class_, homun_id);
+		return false;
 	}
 
 	unit_remove_map(&hd->bl, CLR_OUTSIGHT);
@@ -473,26 +463,33 @@ int hom_mutate(struct homun_data *hd, int homun_id)
 	if (!(battle_config.hom_setting&0x2))
 		skill->unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
 
-	return 1;
+	return true;
 }
 
-int merc_hom_gainexp(struct homun_data *hd,int exp)
-{
-	int m_class;
+int homunculus_gainexp(struct homun_data *hd,unsigned int exp) {
+	enum homun_type htype;
 
 	if(hd->homunculus.vaporize)
 		return 1;
 
-	if((m_class = hom_class2mapid(hd->homunculus.class_)) == -1) {
-		ShowError("merc_hom_gainexp: Invalid class %d. \n", hd->homunculus.class_);
+	if((htype = homun->class2type(hd->homunculus.class_)) == -1) {
+		ShowError("homunculus_gainexp: Invalid class %d. \n", hd->homunculus.class_);
 		return 0;
 	}
-
-	if( hd->exp_next == 0 ||
-	   ((m_class&HOM_REG) && hd->homunculus.level >= battle_config.hom_max_level) ||
-	   ((m_class&HOM_S)   && hd->homunculus.level >= battle_config.hom_S_max_level) ) {
-	  	hd->homunculus.exp = 0;
+	
+	if( !hd->exp_next || hd->homunculus.exp < hd->exp_next )
 		return 0;
+	
+	switch( htype ) {
+		case HT_REG:
+		case HT_EVO:
+			if( hd->homunculus.level >= battle_config.hom_max_level )
+				return 0;
+			break;
+		case HT_S:
+			if( hd->homunculus.level >= battle_config.hom_S_max_level )
+				return 0;
+			break;
 	}
 
 	hd->homunculus.exp += exp;
@@ -503,10 +500,10 @@ int merc_hom_gainexp(struct homun_data *hd,int exp)
 	}
 
  	//levelup
-	while( hd->homunculus.exp > hd->exp_next && merc_hom_levelup(hd) );
+	while( hd->homunculus.exp > hd->exp_next && homun->levelup(hd) );
 
 	if( hd->exp_next == 0 )
-		hd->homunculus.exp = 0 ;
+		hd->homunculus.exp = 0;
 
 	clif->specialeffect(&hd->bl,568,AREA);
 	status_calc_homunculus(hd,0);
@@ -515,8 +512,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)
-{
+unsigned int homunculus_add_intimacy(struct homun_data *hd, unsigned int value) {
 	if (battle_config.homunculus_friendly_rate != 100)
 		value = (value * battle_config.homunculus_friendly_rate) / 100;
 
@@ -528,8 +524,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)
-{
+unsigned int homunculus_consume_intimacy(struct homun_data *hd, unsigned int value) {
 	if (hd->homunculus.intimacy >= value)
 		hd->homunculus.intimacy -= value;
 	else
@@ -538,12 +533,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 homunculus_healed (struct homun_data *hd) {
 	clif->hominfo(hd->master,hd,0);
 }
 
-void merc_save(struct homun_data *hd)
-{
+void homunculus_save(struct homun_data *hd) {
 	// copy data that must be saved in homunculus struct ( hp / sp )
 	TBL_PC * sd = hd->master;
 	//Do not check for max_hp/max_sp caps as current could be higher to max due
@@ -554,57 +548,55 @@ 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)
-{
+unsigned char homunculus_menu(struct map_session_data *sd,unsigned char menu_num) {
 	nullpo_ret(sd);
 	if (sd->hd == NULL)
 		return 1;
 
-	switch(menunum) {
+	switch(menu_num) {
 		case 0:
 			break;
 		case 1:
-			merc_hom_food(sd, sd->hd);
+			homun->feed(sd, sd->hd);
 			break;
 		case 2:
-			merc_hom_delete(sd->hd, -1);
+			homun->delete(sd->hd, -1);
 			break;
 		default:
-			ShowError("merc_menu : unknown menu choice : %d\n", menunum) ;
+			ShowError("homunculus_menu : unknown menu choice : %d\n", menu_num) ;
 			break;
 	}
 	return 0;
 }
 
-int merc_hom_food(struct map_session_data *sd, struct homun_data *hd)
-{
+bool homunculus_feed(struct map_session_data *sd, struct homun_data *hd) {
 	int i, foodID, emotion;
 
 	if(hd->homunculus.vaporize)
-		return 1 ;
+		return false;
 
 	foodID = hd->homunculusDB->foodID;
 	i = pc_search_inventory(sd,foodID);
 	if(i < 0) {
 		clif->hom_food(sd,foodID,0);
-		return 1;
+		return false;
 	}
 	pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME);
 
 	if ( hd->homunculus.hunger >= 91 ) {
-		merc_hom_decrease_intimacy(hd, 50);
+		homun->consume_intimacy(hd, 50);
 		emotion = E_WAH;
 	} else if ( hd->homunculus.hunger >= 76 ) {
-		merc_hom_decrease_intimacy(hd, 5);
+		homun->consume_intimacy(hd, 5);
 		emotion = E_SWT2;
 	} else if ( hd->homunculus.hunger >= 26 ) {
-		merc_hom_increase_intimacy(hd, 75);
+		homun->add_intimacy(hd, 75);
 		emotion = E_HO;
 	} else if ( hd->homunculus.hunger >= 11 ) {
-		merc_hom_increase_intimacy(hd, 100);
+		homun->add_intimacy(hd, 100);
 		emotion = E_HO;
 	} else {
-		merc_hom_increase_intimacy(hd, 50);
+		homun->add_intimacy(hd, 50);
 		emotion = E_HO;
 	}
 
@@ -619,25 +611,20 @@ 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 homun->delete(sd->hd, E_OMG);
 
-	return 0;
+	return true;
 }
 
-static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr_t data)
-{
+int homunculus_hunger_timer(int tid, unsigned int tick, int id, intptr_t data) {
 	struct map_session_data *sd;
 	struct homun_data *hd;
 
-	sd=map_id2sd(id);
-	if(!sd)
-		return 1;
-
-	if(!sd->status.hom_id || !(hd=sd->hd))
+	if(!(sd=map_id2sd(id)) || !sd->status.hom_id || !(hd=sd->hd))
 		return 1;
 
 	if(hd->hungry_timer != tid){
-		ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid);
+		ShowError("homunculus_hunger_timer %d != %d\n",hd->hungry_timer,tid);
 		return 0;
 	}
 
@@ -655,34 +642,31 @@ 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 ( !homun->consume_intimacy(hd, 100) )
+			return homun->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,homun->hunger_timer,sd->bl.id,0); //simple Fix albator
 	return 0;
 }
 
-int merc_hom_hungry_timer_delete(struct homun_data *hd)
-{
-	nullpo_ret(hd);
+void homunculus_hunger_timer_delete(struct homun_data *hd) {
+	nullpo_retv(hd);
 	if(hd->hungry_timer != INVALID_TIMER) {
-		delete_timer(hd->hungry_timer,merc_hom_hungry);
+		delete_timer(hd->hungry_timer,homun->hunger_timer);
 		hd->hungry_timer = INVALID_TIMER;
 	}
-	return 1;
 }
 
-int merc_hom_change_name(struct map_session_data *sd,char *name)
-{
+int homunculus_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 (!homun_alive(hd))
 		return 1;
 	if(hd->homunculus.rename_flag && !battle_config.hom_rename)
 		return 1;
@@ -695,39 +679,37 @@ 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)
-{
+bool homunculus_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 (!homun_alive(hd)) return false;
 
 	normalize_name(name," ");//bugreport:3032
 
 	if ( !flag || !strlen(name) ) {
 		clif->message(sd->fd, msg_txt(280)); // You cannot use this name
-		return 0;
+		return false;
 	}
 	safestrncpy(hd->homunculus.name,name,NAME_LENGTH);
 	clif->charnameack (0,&hd->bl);
 	hd->homunculus.rename_flag = 1;
 	clif->hominfo(sd,hd,0);
-	return 1;
+	return true;
 }
 
-int search_homunculusDB_index(int key,int type)
-{
+int homunculus_db_search(int key,int type) {
 	int i;
 
 	for(i=0;i<MAX_HOMUNCULUS_CLASS;i++) {
-		if(homunculus_db[i].base_class <= 0)
+		if(homun->db[i].base_class <= 0)
 			continue;
 		switch(type) {
 			case HOMUNCULUS_CLASS:
-				if(homunculus_db[i].base_class == key ||
-					homunculus_db[i].evo_class == key)
+				if(homun->db[i].base_class == key ||
+					homun->db[i].evo_class == key)
 					return i;
 				break;
 			case HOMUNCULUS_FOOD:
-				if(homunculus_db[i].foodID == key)
+				if(homun->db[i].foodID == key)
 					return i;
 				break;
 			default:
@@ -738,30 +720,29 @@ int search_homunculusDB_index(int key,int type)
 }
 
 // Create homunc structure
-int merc_hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
-{
+bool homunculus_create(struct map_session_data *sd, struct s_homunculus *hom) {
 	struct homun_data *hd;
 	int i = 0;
 
-	nullpo_retr(1, sd);
+	nullpo_retr(false, sd);
 
 	Assert((sd->status.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd);
 
-	i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS);
+	i = homun->db_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("homunculus_create: 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 false;
 	}
 	sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data));
 	hd->bl.type = BL_HOM;
 	hd->bl.id = npc_get_new_npc_id();
 
 	hd->master = sd;
-	hd->homunculusDB = &homunculus_db[i];
+	hd->homunculusDB = &homun->db[i];
 	memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus));
-	hd->exp_next = hexptbl[hd->homunculus.level - 1];
+	hd->exp_next = homun->exptable[hd->homunculus.level - 1];
 
 	status_set_viewdata(&hd->bl, hd->homunculus.class_);
 	status_change_init(&hd->bl);
@@ -780,22 +761,20 @@ int merc_hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
 	status_calc_homunculus(hd,1);
 
 	hd->hungry_timer = INVALID_TIMER;
-	return 0;
+	return true;
 }
 
-void merc_hom_init_timers(struct homun_data * hd)
-{
+void homunculus_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,homun->hunger_timer,hd->master->bl.id,0);
 	hd->regen.state.block = 0; //Restore HP/SP block.
 }
 
-int merc_call_homunculus(struct map_session_data *sd)
-{
+bool homunculus_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 homun->creation_request(sd, HM_CLASS_BASE + rnd_value(0, 7));
 
 	// If homunc not yet loaded, load it
 	if (!sd->hd)
@@ -804,12 +783,11 @@ int merc_call_homunculus(struct map_session_data *sd)
 	hd = sd->hd;
 
 	if (!hd->homunculus.vaporize)
-		return 0; //Can't use this if homun wasn't vaporized.
+		return false; //Can't use this if homun wasn't vaporized.
 
-	merc_hom_init_timers(hd);
+	homun->init_timers(hd);
 	hd->homunculus.vaporize = 0;
-	if (hd->bl.prev == NULL)
-	{	//Spawn him
+	if (hd->bl.prev == NULL) { //Spawn him
 		hd->bl.x = sd->bl.x;
 		hd->bl.y = sd->bl.y;
 		hd->bl.m = sd->bl.m;
@@ -821,99 +799,110 @@ 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);
+		homun->save(hd);
 	} else
 		//Warp him to master.
 		unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,CLR_OUTSIGHT);
-	return 1;
+	return true;
 }
 
 // Recv homunculus data from char server
-int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag)
-{
+bool homunculus_recv_data(int account_id, struct s_homunculus *sh, int flag) {
 	struct map_session_data *sd;
 	struct homun_data *hd;
 
 	sd = map_id2sd(account_id);
 	if(!sd)
-		return 0;
-	if (sd->status.char_id != sh->char_id)
-	{
+		return false;
+	if (sd->status.char_id != sh->char_id) {
 		if (sd->status.hom_id == sh->hom_id)
 			sh->char_id = sd->status.char_id; //Correct char id.
 		else
-			return 0;
+			return false;
 	}
 	if(!flag) { // Failed to load
 		sd->status.hom_id = 0;
-		return 0;
+		return false;
 	}
 
 	if (!sd->status.hom_id) //Hom just created.
 		sd->status.hom_id = sh->hom_id;
+	
 	if (sd->hd) //uh? Overwrite the data.
 		memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus));
 	else
-		merc_hom_alloc(sd, sh);
+		homun->create(sd, sh);
 
 	hd = sd->hd;
-	if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL)
-	{
+	if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL) {
+		enum homun_type htype = homun->class2type(hd->homunculus.class_);
+
 		map_addblock(&hd->bl);
 		clif->spawn(&hd->bl);
 		clif->send_homdata(sd,SP_ACK,0);
 		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);
+		homun->init_timers(hd);
+		/* force shuffle if your level is higher than the allowed */
+		switch( htype ) {
+			case HT_REG:
+			case HT_EVO:
+				if( hd->homunculus.level > battle_config.hom_max_level )
+					homun->shuffle(hd);
+				break;
+			case HT_S:
+				if( hd->homunculus.level > battle_config.hom_S_max_level )
+					homun->shuffle(hd);
+				break;
+		}
+
 	}
-	return 1;
+	return true;
 }
 
 // Ask homunculus creation to char server
-int merc_create_homunculus_request(struct map_session_data *sd, int class_)
-{
-	struct s_homunculus homun;
+bool homunculus_creation_request(struct map_session_data *sd, int class_) {
+	struct s_homunculus hom;
 	struct h_stats *base;
 	int i;
 
-	nullpo_retr(1, sd);
+	nullpo_retr(false, sd);
 
-	i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS);
-	if(i < 0) return 0;
+	i = homun->db_search(class_,HOMUNCULUS_CLASS);
+	if(i < 0) return false;
 
-	memset(&homun, 0, sizeof(struct s_homunculus));
+	memset(&hom, 0, sizeof(struct s_homunculus));
 	//Initial data
-	safestrncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1);
-	homun.class_ = class_;
-	homun.level = 1;
-	homun.hunger = 32; //32%
-	homun.intimacy = 2100; //21/1000
-	homun.char_id = sd->status.char_id;
-
-	homun.hp = 10 ;
-	base = &homunculus_db[i].base;
-	homun.max_hp = base->HP;
-	homun.max_sp = base->SP;
-	homun.str = base->str *10;
-	homun.agi = base->agi *10;
-	homun.vit = base->vit *10;
-	homun.int_= base->int_*10;
-	homun.dex = base->dex *10;
-	homun.luk = base->luk *10;
+	safestrncpy(hom.name, homun->db[i].name, NAME_LENGTH-1);
+	hom.class_ = class_;
+	hom.level = 1;
+	hom.hunger = 32; //32%
+	hom.intimacy = 2100; //21/1000
+	hom.char_id = sd->status.char_id;
+
+	hom.hp = 10 ;
+	base = &homun->db[i].base;
+	hom.max_hp = base->HP;
+	hom.max_sp = base->SP;
+	hom.str = base->str *10;
+	hom.agi = base->agi *10;
+	hom.vit = base->vit *10;
+	hom.int_= base->int_*10;
+	hom.dex = base->dex *10;
+	hom.luk = base->luk *10;
 
 	// Request homunculus creation
-	intif_homunculus_create(sd->status.account_id, &homun);
-	return 1;
+	intif_homunculus_create(sd->status.account_id, &hom);
+	return true;
 }
 
-int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y)
-{
+bool homunculus_ressurect(struct map_session_data* sd, unsigned char per, short x, short y) {
 	struct homun_data* hd;
-	nullpo_ret(sd);
+	nullpo_retr(false,sd);
 
 	if (!sd->status.hom_id)
-		return 0; // no homunculus
+		return false; // no homunculus
 
 	if (!sd->hd) //Load homun data;
 		return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
@@ -921,15 +910,15 @@ int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, sh
 	hd = sd->hd;
 
   	if (hd->homunculus.vaporize)
-		return 0; // vaporized homunculi need to be 'called'
+		return false; // vaporized homunculi need to be 'called'
 
 	if (!status_isdead(&hd->bl))
-		return 0; // already alive
+		return false; // already alive
 
-	merc_hom_init_timers(hd);
+	homun->init_timers(hd);
 
-	if (!hd->bl.prev)
-	{	//Add it back to the map.
+	if (!hd->bl.prev) {
+		//Add it back to the map.
 		hd->bl.m = sd->bl.m;
 		hd->bl.x = x;
 		hd->bl.y = y;
@@ -937,11 +926,10 @@ int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, sh
 		clif->spawn(&hd->bl);
 	}
 	status_revive(&hd->bl, per, 0);
-	return 1;
+	return true;
 }
 
-void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp)
-{
+void homunculus_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;
 	if (!sd)
@@ -951,9 +939,8 @@ void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp)
 	clif->hominfo(sd,hd,0);
 	clif->homskillinfoblock(sd);
 }
-
-void merc_reset_stats(struct homun_data *hd)
-{	//Resets a homunc stats back to zero (but doesn't touches hunger or intimacy)
+//Resets a homunc stats back to zero (but doesn't touches hunger or intimacy)
+void homunculus_stat_reset(struct homun_data *hd) {
 	struct s_homunculus_db *db;
 	struct s_homunculus *hom;
 	struct h_stats *base;
@@ -971,32 +958,33 @@ void merc_reset_stats(struct homun_data *hd)
 	hom->dex = base->dex *10;
 	hom->luk = base->luk *10;
 	hom->exp = 0;
-	hd->exp_next = hexptbl[0];
+	hd->exp_next = homun->exptable[0];
 	memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill);
 	hd->homunculus.skillpts = 0;
 }
 
-int merc_hom_shuffle(struct homun_data *hd)
-{
+bool homunculus_shuffle(struct homun_data *hd) {
 	struct map_session_data *sd;
 	int lv, skillpts;
 	unsigned int exp;
 	struct s_skill b_skill[MAX_HOMUNSKILL];
 
-	if (!merc_is_hom_active(hd))
-		return 0;
+	if (!homun_alive(hd))
+		return false;
 
 	sd = hd->master;
 	lv = hd->homunculus.level;
 	exp = hd->homunculus.exp;
 	memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill));
 	skillpts = hd->homunculus.skillpts;
+	
 	//Reset values to level 1.
-	merc_reset_stats(hd);
+	homun->stat_reset(hd);
+	
 	//Level it back up
-	do{
+	do {
 		hd->homunculus.exp += hd->exp_next;
-	}while( hd->homunculus.level < lv && merc_hom_levelup(hd) );
+	} while( hd->homunculus.level < lv && homun->levelup(hd) );
 
 	if(hd->homunculus.class_ == hd->homunculusDB->evo_class) {
 		//Evolved bonuses
@@ -1020,28 +1008,25 @@ int merc_hom_shuffle(struct homun_data *hd)
 	status_percent_heal(&hd->bl, 100, 100);
 	clif->specialeffect(&hd->bl,568,AREA);
 
-	return 1;
+	return true;
 }
 
-static bool read_homunculusdb_sub(char* str[], int columns, int current)
-{
+bool homunculus_read_db_sub(char* str[], int columns, int current) {
 	int classid;
 	struct s_homunculus_db *db;
 
 	//Base Class,Evo Class
 	classid = atoi(str[0]);
-	if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
-	{
-		ShowError("read_homunculusdb : Invalid class %d\n", classid);
+	if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) {
+		ShowError("homunculus_read_db_sub : Invalid class %d\n", classid);
 		return false;
 	}
-	db = &homunculus_db[current];
+	db = &homun->db[current];
 	db->base_class = classid;
 	classid = atoi(str[1]);
-	if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
-	{
+	if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) {
 		db->base_class = 0;
-		ShowError("read_homunculusdb : Invalid class %d\n", classid);
+		ShowError("homunculus_read_db_sub : Invalid class %d\n", classid);
 		return false;
 	}
 	db->evo_class = classid;
@@ -1136,34 +1121,28 @@ static bool read_homunculusdb_sub(char* str[], int columns, int current)
 	return true;
 }
 
-int read_homunculusdb(void)
-{
+void homunculus_read_db(void) {
 	int i;
 	const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"};
 
-	memset(homunculus_db,0,sizeof(homunculus_db));
-	for(i = 0; i<ARRAYLENGTH(filename); i++)
-	{
-		if( i > 0 )
-		{
+	memset(homun->db,0,sizeof(homun->db));
+	for(i = 0; i<ARRAYLENGTH(filename); i++) {
+		if( i > 0 ) {
 			char path[256];
 
 			sprintf(path, "%s/%s", db_path, filename[i]);
 
-			if( !exists(path) )
-			{
+			if( !exists(path) ) {
 				continue;
 			}
 		}
 
-		sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, &read_homunculusdb_sub);
+		sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, homun->read_db_sub);
 	}
 
-	return 0;
 }
-
-static bool read_homunculus_skilldb_sub(char* split[], int columns, int current)
-{// <hom class>,<skill id>,<max level>[,<job level>],<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>,<intimacy lv req>
+// <hom class>,<skill id>,<max level>[,<job level>],<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>,<intimacy lv req>
+bool homunculus_read_skill_db_sub(char* split[], int columns, int current) {
 	int k, classid;
 	int j;
 	int minJobLevelPresent = 0;
@@ -1173,47 +1152,42 @@ static bool read_homunculus_skilldb_sub(char* split[], int columns, int current)
 
 	// check for bounds [celest]
 	classid = atoi(split[0]) - HM_CLASS_BASE;
-	if ( classid >= MAX_HOMUNCULUS_CLASS )
-	{
-		ShowWarning("read_homunculus_skilldb: Invalud homunculus class %d.\n", atoi(split[0]));
+	
+	if ( classid >= MAX_HOMUNCULUS_CLASS ) {
+		ShowWarning("homunculus_read_skill_db_sub: Invalud homunculus class %d.\n", atoi(split[0]));
 		return false;
 	}
 
 	k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex]
 	// Search an empty line or a line with the same skill_id (stored in j)
-	ARR_FIND( 0, MAX_SKILL_TREE, j, !hskill_tree[classid][j].id || hskill_tree[classid][j].id == k );
-	if (j == MAX_SKILL_TREE)
-	{
+	ARR_FIND( 0, MAX_SKILL_TREE, j, !homun->skill_tree[classid][j].id || homun->skill_tree[classid][j].id == k );
+	if (j == MAX_SKILL_TREE) {
 		ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid);
 		return false;
 	}
 
-	hskill_tree[classid][j].id = k;
-	hskill_tree[classid][j].max = atoi(split[2]);
+	homun->skill_tree[classid][j].id = k;
+	homun->skill_tree[classid][j].max = atoi(split[2]);
 	if (minJobLevelPresent)
-		hskill_tree[classid][j].joblv = atoi(split[3]);
+		homun->skill_tree[classid][j].joblv = atoi(split[3]);
 
-	for( k = 0; k < MAX_PC_SKILL_REQUIRE; k++ )
-	{
-		hskill_tree[classid][j].need[k].id = atoi(split[3+k*2+minJobLevelPresent]);
-		hskill_tree[classid][j].need[k].lv = atoi(split[3+k*2+minJobLevelPresent+1]);
+	for( k = 0; k < MAX_PC_SKILL_REQUIRE; k++ ) {
+		homun->skill_tree[classid][j].need[k].id = atoi(split[3+k*2+minJobLevelPresent]);
+		homun->skill_tree[classid][j].need[k].lv = atoi(split[3+k*2+minJobLevelPresent+1]);
 	}
 
-	hskill_tree[classid][j].intimacylv = atoi(split[13+minJobLevelPresent]);
+	homun->skill_tree[classid][j].intimacylv = atoi(split[13+minJobLevelPresent]);
 
 	return true;
 }
 
-int read_homunculus_skilldb(void)
-{
-	memset(hskill_tree,0,sizeof(hskill_tree));
-	sv_readdb(db_path, "homun_skill_tree.txt", ',', 13, 15, -1, &read_homunculus_skilldb_sub);
+void homunculus_skill_db_read(void) {
+	memset(homun->skill_tree,0,sizeof(homun->skill_tree));
+	sv_readdb(db_path, "homun_skill_tree.txt", ',', 13, 15, -1, homun->read_skill_db_sub);
 
-	return 0;
 }
 
-void read_homunculus_expdb(void)
-{
+void homunculus_exp_db_read(void) {
 	FILE *fp;
 	char line[1024];
 	int i, j=0;
@@ -1221,60 +1195,105 @@ void read_homunculus_expdb(void)
 		DBPATH"exp_homun.txt",
 		"exp_homun2.txt"};
 
-	memset(hexptbl,0,sizeof(hexptbl));
-	for(i=0; i<2; i++){
+	memset(homun->exptable,0,sizeof(homun->exptable));
+	for(i = 0; i < 2; i++) {
 		sprintf(line, "%s/%s", db_path, filename[i]);
-		fp=fopen(line,"r");
-		if(fp == NULL){
+		if( (fp=fopen(line,"r")) == NULL) {
 			if(i != 0)
 				continue;
 			ShowError("can't read %s\n",line);
 			return;
 		}
-		while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL)
-		{
+		while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL) {
 			if(line[0] == '/' && line[1] == '/')
 				continue;
 
-			hexptbl[j] = strtoul(line, NULL, 10);
-			if (!hexptbl[j++])
+			if (!(homun->exptable[j++] = strtoul(line, NULL, 10)))
 				break;
 		}
-		if (hexptbl[MAX_LEVEL - 1]) // Last permitted level have to be 0!
-		{
-			ShowWarning("read_hexptbl: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL);
-			hexptbl[MAX_LEVEL - 1] = 0;
+		// Last permitted level have to be 0!
+		if (homun->exptable[MAX_LEVEL - 1]) {
+			ShowWarning("homunculus_exp_db_read: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL);
+			homun->exptable[MAX_LEVEL - 1] = 0;
 		}
 		fclose(fp);
 		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s"CL_RESET"'.\n", j, filename[i]);
 	}
 }
 
-void merc_reload(void)
-{
-	read_homunculusdb();
-	read_homunculus_expdb();
+void homunculus_reload(void) {
+	homun->read_db();
+	homun->exp_db_read();
 }
 
-void merc_skill_reload(void)
-{
-	read_homunculus_skilldb();
+void homunculus_skill_reload(void) {
+	homun->skill_db_read();
 }
 
-int do_init_merc(void)
-{
+void do_init_homunculus(void) {
 	int class_;
-	read_homunculusdb();
-	read_homunculus_expdb();
-	read_homunculus_skilldb();
+	homun->read_db();
+	homun->exp_db_read();
+	homun->skill_db_read();
 	// Add homunc timer function to timer func list [Toms]
-	add_timer_func_list(merc_hom_hungry, "merc_hom_hungry");
+	add_timer_func_list(homun->hunger_timer, "homunculus_hunger_timer");
 
 	//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;
+	memset(&homun->viewdb, 0, sizeof(homun->viewdb));
+	for (class_ = 0; class_ < ARRAYLENGTH(homun->viewdb); class_++)
+		homun->viewdb[class_].class_ = HM_CLASS_BASE+class_;
 }
 
-int do_final_merc(void);
+void do_final_homunculus(void) {
+	
+}
+
+void homunculus_defaults(void) {
+	homun = &homunculus_s;
+	
+	homun->init = do_init_homunculus;
+	homun->final = do_final_homunculus;
+	homun->reload = homunculus_reload;
+	homun->reload_skill = homunculus_skill_reload;
+	/* */
+	homun->get_viewdata = homunculus_get_viewdata;
+	homun->class2type = homunculus_class2type;
+	homun->damaged = homunculus_damaged;
+	homun->dead = homunculus_dead;
+	homun->vaporize = homunculus_vaporize;
+	homun->delete = homunculus_delete;
+	homun->checkskill = homunculus_checkskill;
+	homun->calc_skilltree = homunculus_calc_skilltree;
+	homun->skill_tree_get_max = homunculus_skill_tree_get_max;
+	homun->skillup = homunculus_skillup;
+	homun->levelup = homunculus_levelup;
+	homun->change_class = homunculus_change_class;
+	homun->evolve = homunculus_evolve;
+	homun->mutate = homunculus_mutate;
+	homun->gainexp = homunculus_gainexp;
+	homun->add_intimacy = homunculus_add_intimacy;
+	homun->consume_intimacy = homunculus_consume_intimacy;
+	homun->healed = homunculus_healed;
+	homun->save = homunculus_save;
+	homun->menu = homunculus_menu;
+	homun->feed = homunculus_feed;
+	homun->hunger_timer = homunculus_hunger_timer;
+	homun->hunger_timer_delete = homunculus_hunger_timer_delete;
+	homun->change_name = homunculus_change_name;
+	homun->change_name_ack = homunculus_change_name_ack;
+	homun->db_search = homunculus_db_search;
+	homun->create = homunculus_create;
+	homun->init_timers = homunculus_init_timers;
+	homun->call = homunculus_call;
+	homun->recv_data = homunculus_recv_data;
+	homun->creation_request = homunculus_creation_request;
+	homun->ressurect = homunculus_ressurect;
+	homun->revive = homunculus_revive;
+	homun->stat_reset = homunculus_stat_reset;
+	homun->shuffle = homunculus_shuffle;
+	homun->read_db_sub = homunculus_read_db_sub;
+	homun->read_db = homunculus_read_db;
+	homun->read_skill_db_sub = homunculus_read_skill_db_sub;
+	homun->skill_db_read = homunculus_skill_db_read;
+	homun->exp_db_read = homunculus_exp_db_read;
+}
diff --git a/src/map/homunculus.h b/src/map/homunculus.h
index 50e82eeac..86d437e73 100644
--- a/src/map/homunculus.h
+++ b/src/map/homunculus.h
@@ -1,11 +1,17 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
 
 #ifndef _HOMUNCULUS_H_
 #define _HOMUNCULUS_H_
 
 #include "status.h" // struct status_data, struct status_change
 #include "unit.h" // struct unit_data
+#include "pc.h"
+
+#define MAX_HOM_SKILL_REQUIRE 5
+#define homdb_checkid(id) (id >=  HM_CLASS_BASE && id <= HM_CLASS_MAX)
+#define homun_alive(x) ((x) && (x)->homunculus.vaporize != 1 && (x)->battle_status.hp > 0)
 
 struct h_stats {
 	unsigned int HP, SP;
@@ -23,9 +29,16 @@ struct s_homunculus_db {
 };
 
 extern struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS];
-enum { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD };
 
-enum { MH_MD_FIGHTING=1, MH_MD_GRAPPLING };
+enum {
+	HOMUNCULUS_CLASS,
+	HOMUNCULUS_FOOD
+};
+
+enum {
+	MH_MD_FIGHTING = 1,
+	MH_MD_GRAPPLING
+};
 
 enum {
 	SP_ACK      = 0x0,
@@ -49,7 +62,6 @@ struct homun_data {
 	char blockskill[MAX_SKILL];	// [orn]
 };
 
-#define MAX_HOM_SKILL_REQUIRE 5
 struct homun_skill_tree_entry {
 	short id;
 	unsigned char max;
@@ -61,72 +73,70 @@ struct homun_skill_tree_entry {
 	} need[MAX_HOM_SKILL_REQUIRE];
 }; // Celest
 
-#define HOM_EVO 0x100 //256
-#define HOM_S 0x200 //512
-
-#define HOM_REG 0x1000 //4096
-
-enum {
-// Normal Homunculus
-	MAPID_LIF = HOM_REG|0x0,
-	MAPID_AMISTR,
-	MAPID_FILIR,
-	MAPID_VANILMIRTH,
-// Evolved Homunulus
-	MAPID_LIF_E = HOM_REG|HOM_EVO|0x0,
-	MAPID_AMISTR_E,
-	MAPID_FILIR_E,
-	MAPID_VANILMIRTH_E,
-// Homunculus S
-	MAPID_EIRA = HOM_S|0x0,
-	MAPID_BAYERI,
-	MAPID_SERA,
-	MAPID_DIETER,
-	MAPID_ELANOR,
+enum homun_type {
+	HT_REG	= 0x1,
+	HT_EVO	= 0x2,
+	HT_S	= 0x4,
 };
 
-#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 != 1 && 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_);
-int hom_class2mapid(int hom_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);
-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);
-
-int hom_addspiritball(TBL_HOM *hd, int max);
-int hom_delspiritball(TBL_HOM *hd, int count, int type);
+/* homunculus.c interface */
+struct homunculus_interface {
+	unsigned int exptable[MAX_LEVEL];
+	struct view_data viewdb[MAX_HOMUNCULUS_CLASS];
+	struct s_homunculus_db db[MAX_HOMUNCULUS_CLASS];
+	struct homun_skill_tree_entry skill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE];
+	/* */
+	void (*init) (void);
+	void (*final) (void);
+	void (*reload) (void);
+	void (*reload_skill) (void);
+	/* */
+	struct view_data* (*get_viewdata) (int class_);
+	enum homun_type (*class2type) (int class_);
+	void (*damaged) (struct homun_data *hd);
+	int (*dead) (struct homun_data *hd);
+	int (*vaporize) (struct map_session_data *sd, int flag);
+	int (*delete) (struct homun_data *hd, int emote);
+	int (*checkskill) (struct homun_data *hd, uint16 skill_id);
+	int (*calc_skilltree) (struct homun_data *hd, int flag_evolve);
+	int (*skill_tree_get_max) (int id, int b_class);
+	void (*skillup) (struct homun_data *hd, uint16 skill_id);
+	bool (*levelup) (struct homun_data *hd);
+	int (*change_class) (struct homun_data *hd, short class_);
+	bool (*evolve) (struct homun_data *hd);
+	bool (*mutate) (struct homun_data *hd, int homun_id);
+	int (*gainexp) (struct homun_data *hd, unsigned int exp);
+	unsigned int (*add_intimacy) (struct homun_data * hd, unsigned int value);
+	unsigned int (*consume_intimacy) (struct homun_data *hd, unsigned int value);
+	void (*healed) (struct homun_data *hd);
+	void (*save) (struct homun_data *hd);
+	unsigned char (*menu) (struct map_session_data *sd,unsigned char menu_num);
+	bool (*feed) (struct map_session_data *sd, struct homun_data *hd);
+	int (*hunger_timer) (int tid, unsigned int tick, int id, intptr_t data);
+	void (*hunger_timer_delete) (struct homun_data *hd);
+	int (*change_name) (struct map_session_data *sd,char *name);
+	bool (*change_name_ack) (struct map_session_data *sd, char* name, int flag);
+	int (*db_search) (int key,int type);
+	bool (*create) (struct map_session_data *sd, struct s_homunculus *hom);
+	void (*init_timers) (struct homun_data * hd);
+	bool (*call) (struct map_session_data *sd);
+	bool (*recv_data) (int account_id, struct s_homunculus *sh, int flag);
+	bool (*creation_request) (struct map_session_data *sd, int class_);
+	bool (*ressurect) (struct map_session_data* sd, unsigned char per, short x, short y);
+	void (*revive) (struct homun_data *hd, unsigned int hp, unsigned int sp);
+	void (*stat_reset) (struct homun_data *hd);
+	bool (*shuffle) (struct homun_data *hd);
+	bool (*read_db_sub) (char* str[], int columns, int current);
+	void (*read_db) (void);
+	bool (*read_skill_db_sub) (char* split[], int columns, int current);
+	void (*skill_db_read) (void);
+	void (*exp_db_read) (void);
+	void (*addspiritball) (struct homun_data *hd, int max);
+	void (*delspiritball) (struct homun_data *hd, int count, int type);
+} homunculus_s;
+
+struct homunculus_interface *homun;
+
+void homunculus_defaults(void);
 
 #endif /* _HOMUNCULUS_H_ */
diff --git a/src/map/intif.c b/src/map/intif.c
index 102dbf84e..bab8470a4 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -810,16 +810,15 @@ int intif_homunculus_create(int account_id, struct s_homunculus *sh)
 	return 0;
 }
 
-int intif_homunculus_requestload(int account_id, int homun_id)
-{
+bool intif_homunculus_requestload(int account_id, int homun_id) {
 	if (CheckForCharServer())
-		return 0;
+		return false;
 	WFIFOHEAD(inter_fd, 10);
 	WFIFOW(inter_fd,0) = 0x3091;
 	WFIFOL(inter_fd,2) = account_id;
 	WFIFOL(inter_fd,6) = homun_id;
 	WFIFOSET(inter_fd, 10);
-	return 1;
+	return true;
 }
 
 int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh)
@@ -1334,7 +1333,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));
+		homun->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
 		break;
 	}
 	return 0;
@@ -1352,7 +1351,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)) ;
+	homun->recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
 	return 0;
 }
 
@@ -1367,7 +1366,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));
+	homun->recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
 	return 0;
 }
 
diff --git a/src/map/intif.h b/src/map/intif.h
index 75b48d625..43bbc0859 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -71,7 +71,7 @@ int intif_rename(struct map_session_data *sd, int type, char *name);
 #define intif_rename_pet(sd, name) intif_rename(sd, 1, name)
 #define intif_rename_hom(sd, name) intif_rename(sd, 2, name)
 int intif_homunculus_create(int account_id, struct s_homunculus *sh);
-int intif_homunculus_requestload(int account_id, int homun_id);
+bool intif_homunculus_requestload(int account_id, int homun_id);
 int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh);
 int intif_homunculus_requestdelete(int homun_id);
 
diff --git a/src/map/map.c b/src/map/map.c
index ed4eba209..313abb2c6 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -4968,6 +4968,7 @@ void do_final(void)
 	do_final_pc();
 	do_final_pet();
 	do_final_mob();
+	homun->final();
 	atcommand->final_msg();
 	skill->final();
 	do_final_status();
@@ -5172,6 +5173,7 @@ void load_defaults(void) {
 	battle_defaults();
 	buyingstore_defaults();
 	clif_defaults();
+	homunculus_defaults();
 	ircbot_defaults();
 	log_defaults();
 	script_defaults();
@@ -5367,7 +5369,7 @@ int do_init(int argc, char *argv[])
 	do_init_guild();
 	do_init_storage();
 	do_init_pet();
-	do_init_merc();
+	homun->init();
 	do_init_mercenary();
 	do_init_elemental();
 	do_init_quest();
diff --git a/src/map/mob.c b/src/map/mob.c
index e5520b622..86c0f8455 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -2142,7 +2142,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 && !homun_alive(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
@@ -2283,10 +2283,9 @@ 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);
+			homun->gainexp(tmpsd[i]->hd, base_exp);
 		if(flag) {
-			if(base_exp || job_exp)
-			{
+			if(base_exp || job_exp) {
 				if( md->dmglog[i].flag != MDLF_PET || battle_config.pet_attack_exp_to_master ) {
 #ifdef RENEWAL_EXP
 					int rate = pc_level_penalty_mod(tmpsd[i], md, 1);
diff --git a/src/map/pc.c b/src/map/pc.c
index 543132d53..aaf89e09a 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4837,7 +4837,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( homun_alive(sd->hd) )
 	{
 		sd->hd->bl.m = m;
 		sd->hd->bl.x = sd->hd->ud.to_x = x;
@@ -6058,7 +6058,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);
+		homun->skillup(sd->hd, skill_id);
 		return 0;
 	}
 
@@ -6345,8 +6345,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, 0);
+		if( homun_alive(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
+			homun->vaporize(sd, 0);
 	}
 
 	for( i = 1; i < MAX_SKILL; i++ ) {
@@ -6572,7 +6572,7 @@ 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, 0);
+		    homun->vaporize(sd, 0);
 	}
 
 	if( sd->md )
@@ -7487,8 +7487,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, 0);
+	if(homun_alive(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
+		homun->vaporize(sd, 0);
 
 	if(sd->status.manner < 0)
 		clif->changestatus(sd,SP_MANNER,sd->status.manner);
diff --git a/src/map/script.c b/src/map/script.c
index 61996b414..9d9800a32 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -9739,10 +9739,9 @@ BUILDIN(homunculus_evolution)
 	if( sd == NULL )
 		return true;
 	
-	if(merc_is_hom_active(sd->hd))
-	{
+	if(homun_alive(sd->hd)) {
 		if (sd->hd->homunculus.intimacy > 91000)
-			merc_hom_evolution(sd->hd);
+			homun->evolve(sd->hd);
 		else
 			clif->emotion(&sd->hd->bl, E_SWT);
 	}
@@ -9752,9 +9751,9 @@ BUILDIN(homunculus_evolution)
 /*==========================================
  * [Xantara]
  *------------------------------------------*/
-BUILDIN(homunculus_mutate)
-{
-	int homun_id, m_class, m_id;
+BUILDIN(homunculus_mutate) {
+	int homun_id;
+	enum homun_type m_class, m_id;
 	TBL_PC *sd;
 	
 	sd = script_rid2sd(st);
@@ -9766,12 +9765,12 @@ BUILDIN(homunculus_mutate)
 	else
 		homun_id = 6048 + (rnd() % 4);
 	
-	if(merc_is_hom_active(sd->hd)) {
-		m_class = hom_class2mapid(sd->hd->homunculus.class_);
-		m_id    = hom_class2mapid(homun_id);
+	if(homun_alive(sd->hd)) {
+		m_class = homun->class2type(sd->hd->homunculus.class_);
+		m_id    = homun->class2type(homun_id);
 		
-		if ( m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99 )
-			hom_mutate(sd->hd, homun_id);
+		if ( m_class != -1 && m_id != -1 && m_class == HT_EVO && m_id == HT_S && sd->hd->homunculus.level >= 99 )
+			homun->mutate(sd->hd, homun_id);
 		else
 			clif->emotion(&sd->hd->bl, E_SWT);
 	}
@@ -9779,16 +9778,15 @@ BUILDIN(homunculus_mutate)
 }
 
 // [Zephyrus]
-BUILDIN(homunculus_shuffle)
-{
+BUILDIN(homunculus_shuffle) {
 	TBL_PC *sd;
 	
 	sd=script_rid2sd(st);
 	if( sd == NULL )
 		return true;
 	
-	if(merc_is_hom_active(sd->hd))
-		merc_hom_shuffle(sd->hd);
+	if(homun_alive(sd->hd))
+		homun->shuffle(sd->hd);
 	
 	return true;
 }
@@ -12362,7 +12360,7 @@ BUILDIN(gethominfo)
 	int type=script_getnum(st,2);
 	
 	hd = sd?sd->hd:NULL;
-	if(!merc_is_hom_active(hd))
+	if(!homun_alive(hd))
 	{
 		if (type == 2)
 			script_pushconststr(st,"null");
diff --git a/src/map/skill.c b/src/map/skill.c
index c17004793..828d600c1 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -405,7 +405,7 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk
 		#endif
 			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 = homun->checkskill(((TBL_HOM*)src), HLIF_BRAIN)) > 0 )
 				hp += hp * skill * 2 / 100;
 			break;
 	}
@@ -7292,13 +7292,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 && homun->call(sd))
 				clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
 			break;
 
 		case AM_REST:
 			if (sd) {
-				if (merc_hom_vaporize(sd,1))
+				if (homun->vaporize(sd,1))
 					clif->skill_nodamage(src, bl, skill_id, skill_lv, 1);
 				else
 					clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
@@ -10005,10 +10005,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
 			break;
 
 		case AM_RESURRECTHOMUN:	//[orn]
-			if (sd)
-			{
-				if (!merc_resurrect_homunculus(sd, 20*skill_lv, x, y))
-				{
+			if (sd) {
+				if (!homun->ressurect(sd, 20*skill_lv, x, y)) {
 					clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
 					break;
 				}
@@ -12760,7 +12758,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
 			}
 			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 (!homun_alive(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 0;
@@ -15986,9 +15984,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(homun_alive(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=homun->checkskill(sd->hd,HVAN_INSTRUCT)) > 0) //His homun is a vanil with instruction change
 						make_per += skill*100; //+1% bonus per level
 				}
 				switch(nameid){
diff --git a/src/map/status.c b/src/map/status.c
index aab2d3b18..f13c1ce3a 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -1201,7 +1201,7 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
 	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: homun->damaged((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;
 	}
@@ -1226,7 +1226,7 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
 	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 = homun->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.
@@ -1370,11 +1370,11 @@ int status_heal(struct block_list *bl,int hp,int sp, int flag)
 
 	// send hp update to client
 	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_MER: mercenary_heal((TBL_MER*)bl,hp,sp); break;
-	case BL_ELEM: elemental_heal((TBL_ELEM*)bl,hp,sp); break;
+		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: homun->healed((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;
 	}
 
 	return hp+sp;
@@ -1476,7 +1476,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: homun->revive((TBL_HOM*)bl, hp, sp); break;
 	}
 	return 1;
 }
@@ -3147,21 +3147,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);
+	homun->calc_skilltree(hd, 0);
 
-	if((skill=merc_hom_checkskill(hd,HAMI_SKIN)) > 0)
+	if((skill=homun->checkskill(hd,HAMI_SKIN)) > 0)
 		status->def +=	skill * 4;
 
-	if((skill = merc_hom_checkskill(hd,HVAN_INSTRUCT)) > 0)
-	{
+	if((skill = homun->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=homun->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 = homun->checkskill(hd,HLIF_BRAIN)) > 0)
 		status->max_sp += (1 +skill/2 -skill/4 +skill/5) * status->max_sp / 100 ;
 
 	if (first) {
@@ -3373,11 +3372,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 = homun->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 = homun->checkskill(hd,HLIF_BRAIN)) > 0 ) {
 			val = regen->sp*(100+3*skill)/100;
 			regen->sp = cap_value(val, 1, SHRT_MAX);
 		}
@@ -5951,7 +5950,7 @@ 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_);
+		vd = homun->get_viewdata(class_);
 	else if (merc_class(class_))
 		vd = merc_get_viewdata(class_);
 	else if (elemental_class(class_))
@@ -8187,15 +8186,14 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
 				val2 = 20 + 10 * val1; //ASPD. Need to confirm if Movement Speed reduction is the same. [Jobbie]
 				val3 = 20 * val1; //HIT
 				val_flag |= 1|2|4;
-				if( sd )
-				{ // Removes Animals
+				if( sd ) { // Removes Animals
 					if( pc_isriding(sd) ) pc_setriding(sd, 0);
 					if( pc_isridingdragon(sd) ) pc_setoption(sd, sd->sc.option&~OPTION_DRAGON);
 					if( pc_iswug(sd) ) pc_setoption(sd, sd->sc.option&~OPTION_WUG);
 					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,1);
+					if( homun_alive(sd->hd) ) homun->vaporize(sd,1);
 					if( sd->md ) merc_delete(sd->md,3);
 				}
 				break;
diff --git a/src/map/unit.c b/src/map/unit.c
index 7a08d1b81..0c241f2f0 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2264,7 +2264,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(homun_alive(sd->hd))
 		unit_remove_map(&sd->hd->bl, clrtype);
 	if(sd->md)
 		unit_remove_map(&sd->md->bl, clrtype);
@@ -2474,11 +2474,10 @@ 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);
+			homun->hunger_timer_delete(hd);
 			if( hd->homunculus.intimacy > 0 )
-				merc_save(hd);
-			else
-			{
+				homun->save(hd);
+			else {
 				intif_homunculus_requestdelete(hd->homunculus.hom_id);
 				if( sd )
 					sd->status.hom_id = 0;
-- 
cgit v1.2.3-70-g09d2