summaryrefslogtreecommitdiff
path: root/src/map/pet.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-09-16 11:53:58 -0300
committershennetsind <ind@henn.et>2013-09-16 11:53:58 -0300
commita1bdf6b04263653699c3ea0ec428aadb7b297fec (patch)
tree386004147429a1e06192da586dfb06b0baca0486 /src/map/pet.c
parent4337e65f1dc35d244dc3abf43ed084c43d064b24 (diff)
downloadhercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.tar.gz
hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.tar.bz2
hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.tar.xz
hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.zip
HPM: Pet.c Interface
Fully Integrated. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/pet.c')
-rw-r--r--src/map/pet.c358
1 files changed, 200 insertions, 158 deletions
diff --git a/src/map/pet.c b/src/map/pet.c
index c1bce0b5b..8498517ef 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -34,14 +34,10 @@
#include <stdlib.h>
#include <string.h>
+struct pet_interface pet_s;
#define MIN_PETTHINKTIME 100
-struct s_pet_db pet_db[MAX_PET_DB];
-
-static struct eri *item_drop_ers; //For loot drops delay structures.
-static struct eri *item_drop_list_ers;
-
int pet_hungry_val(struct pet_data *pd)
{
nullpo_ret(pd);
@@ -74,16 +70,16 @@ void pet_set_intimate(struct pet_data *pd, int value)
int pet_create_egg(struct map_session_data *sd, int item_id)
{
- int pet_id = search_petDB_index(item_id, PET_EGG);
+ int pet_id = pet->search_petDB_index(item_id, PET_EGG);
if (pet_id < 0) return 0; //No pet egg here.
if (!pc->inventoryblank(sd)) return 0; // Inventory full
- sd->catch_target_class = pet_db[pet_id].class_;
+ sd->catch_target_class = pet->db[pet_id].class_;
intif->create_pet(sd->status.account_id, sd->status.char_id,
- (short)pet_db[pet_id].class_,
- (short)mob->db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0,
- (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
+ (short)pet->db[pet_id].class_,
+ (short)mob->db(pet->db[pet_id].class_)->lv,
+ (short)pet->db[pet_id].EggID, 0,
+ (short)pet->db[pet_id].intimate,
+ 100, 0, 1, pet->db[pet_id].jname);
return 1;
}
@@ -187,12 +183,12 @@ int pet_sc_check(struct map_session_data *sd, int type)
|| pd->recovery->type != type )
return 1;
- pd->recovery->timer = iTimer->add_timer(iTimer->gettick()+pd->recovery->delay*1000,pet_recovery_timer,sd->bl.id,0);
+ pd->recovery->timer = iTimer->add_timer(iTimer->gettick()+pd->recovery->delay*1000,pet->recovery_timer,sd->bl.id,0);
return 0;
}
-static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
+int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
{
struct map_session_data *sd;
struct pet_data *pd;
@@ -220,7 +216,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
{
pet_stop_attack(pd);
pd->pet.hungry = 0;
- pet_set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease);
+ pet->set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease);
if( pd->pet.intimate <= 0 )
{
pd->pet.intimate = 0;
@@ -237,7 +233,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
interval = pd->petDB->hungry_delay;
if(interval <= 0)
interval = 1;
- pd->pet_hungry_timer = iTimer->add_timer(tick+interval,pet_hungry,sd->bl.id,0);
+ pd->pet_hungry_timer = iTimer->add_timer(tick+interval,pet->hungry,sd->bl.id,0);
return 0;
}
@@ -248,14 +244,14 @@ int search_petDB_index(int key,int type)
for( i = 0; i < MAX_PET_DB; i++ )
{
- if(pet_db[i].class_ <= 0)
+ if(pet->db[i].class_ <= 0)
continue;
switch(type) {
- case PET_CLASS: if(pet_db[i].class_ == key) return i; break;
- case PET_CATCH: if(pet_db[i].itemID == key) return i; break;
- case PET_EGG: if(pet_db[i].EggID == key) return i; break;
- case PET_EQUIP: if(pet_db[i].AcceID == key) return i; break;
- case PET_FOOD: if(pet_db[i].FoodID == key) return i; break;
+ case PET_CLASS: if(pet->db[i].class_ == key) return i; break;
+ case PET_CATCH: if(pet->db[i].itemID == key) return i; break;
+ case PET_EGG: if(pet->db[i].EggID == key) return i; break;
+ case PET_EQUIP: if(pet->db[i].AcceID == key) return i; break;
+ case PET_FOOD: if(pet->db[i].FoodID == key) return i; break;
default:
return -1;
}
@@ -267,14 +263,14 @@ int pet_hungry_timer_delete(struct pet_data *pd)
{
nullpo_ret(pd);
if(pd->pet_hungry_timer != INVALID_TIMER) {
- iTimer->delete_timer(pd->pet_hungry_timer,pet_hungry);
+ iTimer->delete_timer(pd->pet_hungry_timer,pet->hungry);
pd->pet_hungry_timer = INVALID_TIMER;
}
return 1;
}
-static int pet_performance(struct map_session_data *sd, struct pet_data *pd)
+int pet_performance(struct map_session_data *sd, struct pet_data *pd)
{
int val;
@@ -287,16 +283,16 @@ static int pet_performance(struct map_session_data *sd, struct pet_data *pd)
pet_stop_walking(pd,2000<<8);
clif->send_petdata(NULL, pd, 4, rnd()%val + 1);
- pet_lootitem_drop(pd,NULL);
+ pet->lootitem_drop(pd,NULL);
return 1;
}
-static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
+int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
{
struct item tmp_item;
int flag;
- pet_lootitem_drop(pd,sd);
+ pet->lootitem_drop(pd,sd);
memset(&tmp_item,0,sizeof(tmp_item));
tmp_item.nameid = pd->petDB->EggID;
tmp_item.identify = 1;
@@ -317,7 +313,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
return 1;
}
-int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
+int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo)
{
struct pet_data *pd;
int i=0,interval=0;
@@ -326,23 +322,23 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd);
- if(sd->status.account_id != pet->account_id || sd->status.char_id != pet->char_id) {
+ if(sd->status.account_id != petinfo->account_id || sd->status.char_id != petinfo->char_id) {
sd->status.pet_id = 0;
return 1;
}
- if (sd->status.pet_id != pet->pet_id) {
+ if (sd->status.pet_id != petinfo->pet_id) {
if (sd->status.pet_id) {
//Wrong pet?? Set incuvate to no and send it back for saving.
- pet->incuvate = 1;
- intif->save_petdata(sd->status.account_id,pet);
+ petinfo->incuvate = 1;
+ intif->save_petdata(sd->status.account_id,petinfo);
sd->status.pet_id = 0;
return 1;
}
//The pet_id value was lost? odd... restore it.
- sd->status.pet_id = pet->pet_id;
+ sd->status.pet_id = petinfo->pet_id;
}
- i = search_petDB_index(pet->class_,PET_CLASS);
+ i = pet->search_petDB_index(petinfo->class_,PET_CLASS);
if(i < 0) {
sd->status.pet_id = 0;
return 1;
@@ -352,10 +348,10 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
pd->bl.id = npc->get_new_npc_id();
pd->msd = sd;
- pd->petDB = &pet_db[i];
- pd->db = mob->db(pet->class_);
- memcpy(&pd->pet, pet, sizeof(struct s_pet));
- iStatus->set_viewdata(&pd->bl, pet->class_);
+ pd->petDB = &pet->db[i];
+ pd->db = mob->db(petinfo->class_);
+ memcpy(&pd->pet, petinfo, sizeof(struct s_pet));
+ iStatus->set_viewdata(&pd->bl, petinfo->class_);
unit->dataset(&pd->bl);
pd->ud.dir = sd->ud.dir;
@@ -372,7 +368,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
pd->last_thinktime = iTimer->gettick();
pd->state.skillbonus = 0;
if( battle_config.pet_status_support )
- script->run(pet_db[i].pet_script,0,sd->bl.id,0);
+ script->run(pet->db[i].pet_script,0,sd->bl.id,0);
if( pd->petDB && pd->petDB->equip_script )
status_calc_pc(sd,0);
@@ -382,31 +378,31 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
interval = pd->petDB->hungry_delay;
if( interval <= 0 )
interval = 1;
- pd->pet_hungry_timer = iTimer->add_timer(iTimer->gettick() + interval, pet_hungry, sd->bl.id, 0);
+ pd->pet_hungry_timer = iTimer->add_timer(iTimer->gettick() + interval, pet->hungry, sd->bl.id, 0);
return 0;
}
-int pet_birth_process(struct map_session_data *sd, struct s_pet *pet)
+int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo)
{
nullpo_retr(1, sd);
Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd);
- if(sd->status.pet_id && pet->incuvate == 1) {
+ if(sd->status.pet_id && petinfo->incuvate == 1) {
sd->status.pet_id = 0;
return 1;
}
- pet->incuvate = 0;
- pet->account_id = sd->status.account_id;
- pet->char_id = sd->status.char_id;
- sd->status.pet_id = pet->pet_id;
- if(pet_data_init(sd, pet)) {
+ petinfo->incuvate = 0;
+ petinfo->account_id = sd->status.account_id;
+ petinfo->char_id = sd->status.char_id;
+ sd->status.pet_id = petinfo->pet_id;
+ if(pet->data_init(sd, petinfo)) {
sd->status.pet_id = 0;
return 1;
}
- intif->save_petdata(sd->status.account_id,pet);
+ intif->save_petdata(sd->status.account_id,petinfo);
if (iMap->save_settings&8)
chrif->save(sd,0); //is it REALLY Needed to save the char for hatching a pet? [Skotlex]
@@ -447,10 +443,10 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag)
sd->status.pet_id = 0;
return 1;
}
- if (!pet_birth_process(sd,p)) //Pet hatched. Delete egg.
+ if (!pet->birth_process(sd,p)) //Pet hatched. Delete egg.
pc->delitem(sd,i,1,0,0,LOG_TYPE_OTHER);
} else {
- pet_data_init(sd,p);
+ pet->data_init(sd,p);
if(sd->pd && sd->bl.prev != NULL) {
iMap->addblock(&sd->pd->bl);
clif->spawn(&sd->pd->bl);
@@ -507,7 +503,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id)
//FIXME: delete taming item here, if this was an item-invoked capture and the item was flagged as delay-consume [ultramage]
- i = search_petDB_index(md->class_,PET_CLASS);
+ i = pet->search_petDB_index(md->class_,PET_CLASS);
//catch_target_class == 0 is used for universal lures (except bosses for now). [Skotlex]
if (sd->catch_target_class == 0 && !(md->status.mode&MD_BOSS))
sd->catch_target_class = md->class_;
@@ -518,7 +514,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id)
return 1;
}
- pet_catch_rate = (pet_db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100;
+ pet_catch_rate = (pet->db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100;
if(pet_catch_rate < 1) pet_catch_rate = 1;
if(battle_config.pet_catch_rate != 100)
@@ -529,8 +525,8 @@ int pet_catch_process2(struct map_session_data* sd, int target_id)
unit->remove_map(&md->bl,CLR_OUTSIGHT,ALC_MARK);
status_kill(&md->bl);
clif->pet_roulette(sd,1);
- intif->create_pet(sd->status.account_id,sd->status.char_id,pet_db[i].class_,mob->db(pet_db[i].class_)->lv,
- pet_db[i].EggID,0,pet_db[i].intimate,100,0,1,pet_db[i].jname);
+ intif->create_pet(sd->status.account_id,sd->status.char_id,pet->db[i].class_,mob->db(pet->db[i].class_)->lv,
+ pet->db[i].EggID,0,pet->db[i].intimate,100,0,1,pet->db[i].jname);
}
else
{
@@ -554,7 +550,7 @@ int pet_get_egg(int account_id,int pet_id,int flag)
if(sd == NULL)
return 0;
- i = search_petDB_index(sd->catch_target_class,PET_CLASS);
+ i = pet->search_petDB_index(sd->catch_target_class,PET_CLASS);
sd->catch_target_class = -1;
if(i < 0) {
@@ -563,7 +559,7 @@ int pet_get_egg(int account_id,int pet_id,int flag)
}
memset(&tmp_item,0,sizeof(tmp_item));
- tmp_item.nameid = pet_db[i].EggID;
+ tmp_item.nameid = pet->db[i].EggID;
tmp_item.identify = 1;
tmp_item.card[0] = CARD0_PET;
tmp_item.card[1] = GetWord(pet_id,0);
@@ -577,10 +573,6 @@ int pet_get_egg(int account_id,int pet_id,int flag)
return 1;
}
-static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd);
-static int pet_food(struct map_session_data *sd, struct pet_data *pd);
-static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap);
-
int pet_menu(struct map_session_data *sd,int menunum)
{
struct item_data *egg_id;
@@ -605,16 +597,16 @@ int pet_menu(struct map_session_data *sd,int menunum)
clif->send_petstatus(sd);
break;
case 1:
- pet_food(sd, sd->pd);
+ pet->food(sd, sd->pd);
break;
case 2:
- pet_performance(sd, sd->pd);
+ pet->performance(sd, sd->pd);
break;
case 3:
- pet_return_egg(sd, sd->pd);
+ pet->return_egg(sd, sd->pd);
break;
case 4:
- pet_unequipitem(sd, sd->pd);
+ pet->unequipitem(sd, sd->pd);
break;
}
return 0;
@@ -684,18 +676,18 @@ int pet_equipitem(struct map_session_data *sd,int index)
if (pd->s_skill && pd->s_skill->timer == INVALID_TIMER)
{
if (pd->s_skill->id)
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet_skill_support_timer, sd->bl.id, 0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet->skill_support_timer, sd->bl.id, 0);
else
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet_heal_timer, sd->bl.id, 0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet->heal_timer, sd->bl.id, 0);
}
if (pd->bonus && pd->bonus->timer == INVALID_TIMER)
- pd->bonus->timer=iTimer->add_timer(tick+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
+ pd->bonus->timer=iTimer->add_timer(tick+pd->bonus->delay*1000, pet->skill_bonus_timer, sd->bl.id, 0);
}
return 0;
}
-static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
+int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
{
struct item tmp_item;
int nameid,flag;
@@ -724,14 +716,14 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
if( pd->s_skill && pd->s_skill->timer != INVALID_TIMER )
{
if( pd->s_skill->id )
- iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer);
else
- iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer);
pd->s_skill->timer = INVALID_TIMER;
}
if( pd->bonus && pd->bonus->timer != INVALID_TIMER )
{
- iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
+ iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer);
pd->bonus->timer = INVALID_TIMER;
}
}
@@ -739,7 +731,7 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
return 0;
}
-static int pet_food(struct map_session_data *sd, struct pet_data *pd)
+int pet_food(struct map_session_data *sd, struct pet_data *pd)
{
int i,k;
@@ -752,7 +744,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
pc->delitem(sd,i,1,0,0,LOG_TYPE_CONSUME);
if( pd->pet.hungry > 90 )
- pet_set_intimate(pd, pd->pet.intimate - pd->petDB->r_full);
+ pet->set_intimate(pd, pd->pet.intimate - pd->petDB->r_full);
else
{
if( battle_config.pet_friendly_rate != 100 )
@@ -765,7 +757,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
if( k <= 0 )
k = 1;
}
- pet_set_intimate(pd, pd->pet.intimate + k);
+ pet->set_intimate(pd, pd->pet.intimate + k);
}
if( pd->pet.intimate <= 0 )
{
@@ -787,7 +779,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
return 0;
}
-static int pet_randomwalk(struct pet_data *pd,unsigned int tick)
+int pet_randomwalk(struct pet_data *pd,unsigned int tick)
{
nullpo_ret(pd);
@@ -828,7 +820,7 @@ static int pet_randomwalk(struct pet_data *pd,unsigned int tick)
return 0;
}
-static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, unsigned int tick)
+int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, unsigned int tick)
{
struct block_list *target = NULL;
@@ -847,14 +839,14 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if(pd->pet.intimate <= 0) {
//Pet should just... well, random walk.
- pet_randomwalk(pd,tick);
+ pet->randomwalk(pd,tick);
return 0;
}
if (!check_distance_bl(&sd->bl, &pd->bl, pd->db->range3)) {
//Master too far, chase.
if(pd->target_id)
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
if(pd->ud.walktimer != INVALID_TIMER && pd->ud.target == sd->bl.id)
return 0; //Already walking to him
if (DIFF_TICK(tick, pd->ud.canmove_tick) < 0)
@@ -863,7 +855,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if(pd->status.speed <= 0)
pd->status.speed = 1;
if (!unit->walktobl(&pd->bl, &sd->bl, 3, 0))
- pet_randomwalk(pd,tick);
+ pet->randomwalk(pd,tick);
return 0;
}
@@ -881,13 +873,13 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
!check_distance_bl(&pd->bl, target, pd->db->range3))
{
target = NULL;
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
}
}
if(!target && pd->loot && pd->msd && pc->has_permission(pd->msd, PC_PERM_TRADE) && pd->loot->count < pd->loot->max && DIFF_TICK(tick,pd->ud.canact_tick)>0) {
//Use half the pet's range of sight.
- iMap->foreachinrange(pet_ai_sub_hard_lootsearch,&pd->bl,
+ iMap->foreachinrange(pet->ai_sub_hard_lootsearch,&pd->bl,
pd->db->range2/2, BL_ITEM,pd,&target);
}
@@ -901,7 +893,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
if(!unit->walktoxy(&pd->bl,pd->ud.to_x,pd->ud.to_y,0))
- pet_randomwalk(pd,tick);
+ pet->randomwalk(pd,tick);
return 0;
}
@@ -915,7 +907,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if(!battle->check_range(&pd->bl,target,pd->status.rhw.range))
{ //Chase
if(!unit->walktobl(&pd->bl, target, pd->status.rhw.range, 2))
- pet_unlocktarget(pd); //Unreachable target.
+ pet->unlocktarget(pd); //Unreachable target.
return 0;
}
//Continuous attack.
@@ -924,7 +916,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if (!check_distance_bl(&pd->bl, target, 1))
{ //Out of range
if(!unit->walktobl(&pd->bl, target, 1, 1)) //Unreachable target.
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
return 0;
} else{
struct flooritem_data *fitem = (struct flooritem_data *)target;
@@ -934,29 +926,29 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
iMap->clearflooritem(target);
}
//Target is unlocked regardless of whether it was picked or not.
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
}
}
return 0;
}
-static int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
+int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
{
unsigned int tick = va_arg(ap,unsigned int);
if(sd->status.pet_id && sd->pd)
- pet_ai_sub_hard(sd->pd,sd,tick);
+ pet->ai_sub_hard(sd->pd,sd,tick);
return 0;
}
-static int pet_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
+int pet_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
{
- iMap->map_foreachpc(pet_ai_sub_foreachclient,tick);
+ iMap->map_foreachpc(pet->ai_sub_foreachclient,tick);
return 0;
}
-static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
+int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
{
struct pet_data* pd;
struct flooritem_data *fitem = (struct flooritem_data *)bl;
@@ -983,7 +975,7 @@ static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
return 0;
}
-static int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
+int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
{
struct item_drop_list *list;
struct item_drop *ditem, *ditem_prev;
@@ -995,9 +987,9 @@ static int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data
list->first_charid,list->second_charid,list->third_charid,0);
ditem_prev = ditem;
ditem = ditem->next;
- ers_free(item_drop_ers, ditem_prev);
+ ers_free(pet->item_drop_ers, ditem_prev);
}
- ers_free(item_drop_list_ers, list);
+ ers_free(pet->item_drop_list_ers, list);
return 0;
}
@@ -1009,7 +1001,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
struct item *it;
if(!pd || !pd->loot || !pd->loot->count)
return 0;
- dlist = ers_alloc(item_drop_list_ers, struct item_drop_list);
+ dlist = ers_alloc(pet->item_drop_list_ers, struct item_drop_list);
dlist->m = pd->bl.m;
dlist->x = pd->bl.x;
dlist->y = pd->bl.y;
@@ -1023,14 +1015,14 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
if(sd){
if((flag = pc->additem(sd,it,it->amount,LOG_TYPE_PICKDROP_PLAYER))){
clif->additem(sd,0,0,flag);
- ditem = ers_alloc(item_drop_ers, struct item_drop);
+ ditem = ers_alloc(pet->item_drop_ers, struct item_drop);
memcpy(&ditem->item_data, it, sizeof(struct item));
ditem->next = dlist->item;
dlist->item = ditem;
}
}
else {
- ditem = ers_alloc(item_drop_ers, struct item_drop);
+ ditem = ers_alloc(pet->item_drop_ers, struct item_drop);
memcpy(&ditem->item_data, it, sizeof(struct item));
ditem->next = dlist->item;
dlist->item = ditem;
@@ -1043,9 +1035,9 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
pd->ud.canact_tick = iTimer->gettick()+10000; //prevent picked up during 10*1000ms
if (dlist->item)
- iTimer->add_timer(iTimer->gettick()+540,pet_delay_item_drop,0,(intptr_t)dlist);
+ iTimer->add_timer(iTimer->gettick()+540,pet->delay_item_drop,0,(intptr_t)dlist);
else
- ers_free(item_drop_list_ers, dlist);
+ ers_free(pet->item_drop_list_ers, dlist);
return 1;
}
@@ -1087,7 +1079,7 @@ int pet_skill_bonus_timer(int tid, unsigned int tick, int id, intptr_t data)
status_calc_pc(sd, 0);
}
// wait for the next timer
- pd->bonus->timer=iTimer->add_timer(tick+timer,pet_skill_bonus_timer,sd->bl.id,0);
+ pd->bonus->timer=iTimer->add_timer(tick+timer,pet->skill_bonus_timer,sd->bl.id,0);
return 0;
}
@@ -1146,14 +1138,14 @@ int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data)
(rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp ||
(rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect
) { //Wait (how long? 1 sec for every 10% of remaining)
- pd->s_skill->timer=iTimer->add_timer(iTimer->gettick()+(rate>10?rate:10)*100,pet_heal_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(iTimer->gettick()+(rate>10?rate:10)*100,pet->heal_timer,sd->bl.id,0);
return 0;
}
pet_stop_attack(pd);
pet_stop_walking(pd,1);
clif->skill_nodamage(&pd->bl,&sd->bl,AL_HEAL,pd->s_skill->lv,1);
iStatus->heal(&sd->bl, pd->s_skill->lv,0, 0);
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet->heal_timer,sd->bl.id,0);
return 0;
}
@@ -1180,7 +1172,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
if (DIFF_TICK(pd->ud.canact_tick, tick) > 0)
{ //Wait until the pet can act again.
- pd->s_skill->timer=iTimer->add_timer(pd->ud.canact_tick,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(pd->ud.canact_tick,pet->skill_support_timer,sd->bl.id,0);
return 0;
}
@@ -1189,13 +1181,13 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
(rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp ||
(rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect
) { //Wait (how long? 1 sec for every 10% of remaining)
- pd->s_skill->timer=iTimer->add_timer(tick+(rate>10?rate:10)*100,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(tick+(rate>10?rate:10)*100,pet->skill_support_timer,sd->bl.id,0);
return 0;
}
pet_stop_attack(pd);
pet_stop_walking(pd,1);
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet->skill_support_timer,sd->bl.id,0);
if (skill->get_inf(pd->s_skill->id) & INF_GROUND_SKILL)
unit->skilluse_pos(&pd->bl, sd->bl.x, sd->bl.y, pd->s_skill->id, pd->s_skill->lv);
else
@@ -1205,8 +1197,8 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
/*==========================================
* Pet read db data
- * pet_db.txt
- * pet_db2.txt
+ * pet->db.txt
+ * pet->db2.txt
*------------------------------------------*/
int read_petdb()
{
@@ -1217,20 +1209,20 @@ int read_petdb()
// Remove any previous scripts in case reloaddb was invoked.
for( j = 0; j < MAX_PET_DB; j++ )
{
- if( pet_db[j].pet_script )
+ if( pet->db[j].pet_script )
{
- script->free_code(pet_db[j].pet_script);
- pet_db[j].pet_script = NULL;
+ script->free_code(pet->db[j].pet_script);
+ pet->db[j].pet_script = NULL;
}
- if( pet_db[j].equip_script )
+ if( pet->db[j].equip_script )
{
- script->free_code(pet_db[j].equip_script);
- pet_db[j].pet_script = NULL;
+ script->free_code(pet->db[j].equip_script);
+ pet->db[j].pet_script = NULL;
}
}
// clear database
- memset(pet_db,0,sizeof(pet_db));
+ memset(pet->db,0,sizeof(pet->db));
j = 0; // entry counter
for( i = 0; i < ARRAYLENGTH(filename); i++ )
@@ -1311,35 +1303,35 @@ int read_petdb()
continue;
}
- pet_db[j].class_ = nameid;
- safestrncpy(pet_db[j].name,str[1],NAME_LENGTH);
- safestrncpy(pet_db[j].jname,str[2],NAME_LENGTH);
- pet_db[j].itemID=atoi(str[3]);
- pet_db[j].EggID=atoi(str[4]);
- pet_db[j].AcceID=atoi(str[5]);
- pet_db[j].FoodID=atoi(str[6]);
- pet_db[j].fullness=atoi(str[7]);
- pet_db[j].hungry_delay=atoi(str[8])*1000;
- pet_db[j].r_hungry=atoi(str[9]);
- if( pet_db[j].r_hungry <= 0 )
- pet_db[j].r_hungry=1;
- pet_db[j].r_full=atoi(str[10]);
- pet_db[j].intimate=atoi(str[11]);
- pet_db[j].die=atoi(str[12]);
- pet_db[j].capture=atoi(str[13]);
- pet_db[j].speed=atoi(str[14]);
- pet_db[j].s_perfor=(char)atoi(str[15]);
- pet_db[j].talk_convert_class=atoi(str[16]);
- pet_db[j].attack_rate=atoi(str[17]);
- pet_db[j].defence_attack_rate=atoi(str[18]);
- pet_db[j].change_target_rate=atoi(str[19]);
- pet_db[j].pet_script = NULL;
- pet_db[j].equip_script = NULL;
+ pet->db[j].class_ = nameid;
+ safestrncpy(pet->db[j].name,str[1],NAME_LENGTH);
+ safestrncpy(pet->db[j].jname,str[2],NAME_LENGTH);
+ pet->db[j].itemID=atoi(str[3]);
+ pet->db[j].EggID=atoi(str[4]);
+ pet->db[j].AcceID=atoi(str[5]);
+ pet->db[j].FoodID=atoi(str[6]);
+ pet->db[j].fullness=atoi(str[7]);
+ pet->db[j].hungry_delay=atoi(str[8])*1000;
+ pet->db[j].r_hungry=atoi(str[9]);
+ if( pet->db[j].r_hungry <= 0 )
+ pet->db[j].r_hungry=1;
+ pet->db[j].r_full=atoi(str[10]);
+ pet->db[j].intimate=atoi(str[11]);
+ pet->db[j].die=atoi(str[12]);
+ pet->db[j].capture=atoi(str[13]);
+ pet->db[j].speed=atoi(str[14]);
+ pet->db[j].s_perfor=(char)atoi(str[15]);
+ pet->db[j].talk_convert_class=atoi(str[16]);
+ pet->db[j].attack_rate=atoi(str[17]);
+ pet->db[j].defence_attack_rate=atoi(str[18]);
+ pet->db[j].change_target_rate=atoi(str[19]);
+ pet->db[j].pet_script = NULL;
+ pet->db[j].equip_script = NULL;
if( *str[20] )
- pet_db[j].pet_script = script->parse(str[20], filename[i], lines, 0);
+ pet->db[j].pet_script = script->parse(str[20], filename[i], lines, 0);
if( *str[21] )
- pet_db[j].equip_script = script->parse(str[21], filename[i], lines, 0);
+ pet->db[j].equip_script = script->parse(str[21], filename[i], lines, 0);
j++;
entries++;
@@ -1358,19 +1350,19 @@ int read_petdb()
*------------------------------------------*/
int do_init_pet(void)
{
- read_petdb();
+ pet->read_db();
- item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE);
- item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE);
+ pet->item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE);
+ pet->item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE);
- iTimer->add_timer_func_list(pet_hungry,"pet_hungry");
- iTimer->add_timer_func_list(pet_ai_hard,"pet_ai_hard");
- iTimer->add_timer_func_list(pet_skill_bonus_timer,"pet_skill_bonus_timer"); // [Valaris]
- iTimer->add_timer_func_list(pet_delay_item_drop,"pet_delay_item_drop");
- iTimer->add_timer_func_list(pet_skill_support_timer, "pet_skill_support_timer"); // [Skotlex]
- iTimer->add_timer_func_list(pet_recovery_timer,"pet_recovery_timer"); // [Valaris]
- iTimer->add_timer_func_list(pet_heal_timer,"pet_heal_timer"); // [Valaris]
- iTimer->add_timer_interval(iTimer->gettick()+MIN_PETTHINKTIME,pet_ai_hard,0,0,MIN_PETTHINKTIME);
+ iTimer->add_timer_func_list(pet->hungry,"pet_hungry");
+ iTimer->add_timer_func_list(pet->ai_hard,"pet_ai_hard");
+ iTimer->add_timer_func_list(pet->skill_bonus_timer,"pet_skill_bonus_timer"); // [Valaris]
+ iTimer->add_timer_func_list(pet->delay_item_drop,"pet_delay_item_drop");
+ iTimer->add_timer_func_list(pet->skill_support_timer, "pet_skill_support_timer"); // [Skotlex]
+ iTimer->add_timer_func_list(pet->recovery_timer,"pet_recovery_timer"); // [Valaris]
+ iTimer->add_timer_func_list(pet->heal_timer,"pet_heal_timer"); // [Valaris]
+ iTimer->add_timer_interval(iTimer->gettick()+MIN_PETTHINKTIME,pet->ai_hard,0,0,MIN_PETTHINKTIME);
return 0;
}
@@ -1380,18 +1372,68 @@ int do_final_pet(void)
int i;
for( i = 0; i < MAX_PET_DB; i++ )
{
- if( pet_db[i].pet_script )
+ if( pet->db[i].pet_script )
{
- script->free_code(pet_db[i].pet_script);
- pet_db[i].pet_script = NULL;
+ script->free_code(pet->db[i].pet_script);
+ pet->db[i].pet_script = NULL;
}
- if( pet_db[i].equip_script )
+ if( pet->db[i].equip_script )
{
- script->free_code(pet_db[i].equip_script);
- pet_db[i].equip_script = NULL;
+ script->free_code(pet->db[i].equip_script);
+ pet->db[i].equip_script = NULL;
}
}
- ers_destroy(item_drop_ers);
- ers_destroy(item_drop_list_ers);
+ ers_destroy(pet->item_drop_ers);
+ ers_destroy(pet->item_drop_list_ers);
return 0;
}
+void pet_defaults(void) {
+ pet = &pet_s;
+
+ memset(pet->db,0,sizeof(pet->db));
+ pet->item_drop_ers = NULL;
+ pet->item_drop_list_ers = NULL;
+
+ /* */
+ pet->init = do_init_pet;
+ pet->final = do_final_pet;
+
+ /* */
+ pet->hungry_val = pet_hungry_val;
+ pet->set_intimate = pet_set_intimate;
+ pet->create_egg = pet_create_egg;
+ pet->unlocktarget = pet_unlocktarget;
+ pet->attackskill = pet_attackskill;
+ pet->target_check = pet_target_check;
+ pet->sc_check = pet_sc_check;
+ pet->hungry = pet_hungry;
+ pet->search_petDB_index = search_petDB_index;
+ pet->hungry_timer_delete = pet_hungry_timer_delete;
+ pet->performance = pet_performance;
+ pet->return_egg = pet_return_egg;
+ pet->data_init = pet_data_init;
+ pet->birth_process = pet_birth_process;
+ pet->recv_petdata = pet_recv_petdata;
+ pet->select_egg = pet_select_egg;
+ pet->catch_process1 = pet_catch_process1;
+ pet->catch_process2 = pet_catch_process2;
+ pet->get_egg = pet_get_egg;
+ pet->unequipitem = pet_unequipitem;
+ pet->food = pet_food;
+ pet->ai_sub_hard_lootsearch = pet_ai_sub_hard_lootsearch;
+ pet->menu = pet_menu;
+ pet->change_name = pet_change_name;
+ pet->change_name_ack = pet_change_name_ack;
+ pet->equipitem = pet_equipitem;
+ pet->randomwalk = pet_randomwalk;
+ pet->ai_sub_hard = pet_ai_sub_hard;
+ pet->ai_sub_foreachclient = pet_ai_sub_foreachclient;
+ pet->ai_hard = pet_ai_hard;
+ pet->delay_item_drop = pet_delay_item_drop;
+ pet->lootitem_drop = pet_lootitem_drop;
+ pet->skill_bonus_timer = pet_skill_bonus_timer;
+ pet->recovery_timer = pet_recovery_timer;
+ pet->heal_timer = pet_heal_timer;
+ pet->skill_support_timer = pet_skill_support_timer;
+ pet->read_db = read_petdb;
+}