summaryrefslogtreecommitdiff
path: root/src/map/pet.c
diff options
context:
space:
mode:
authorKenpachi Developer <Kenpachi.Developer@gmx.de>2020-02-16 07:12:53 +0100
committerHaru <haru@dotalux.com>2020-04-05 21:26:11 +0200
commit48daed792b6329fdaf384ccf89fbe17cc5d1666e (patch)
tree7f2d3d7c493383bed6e3e5414c0c478fda8c2206 /src/map/pet.c
parentc6e7334418e3013ac2995e0a0cd9641d2afb4572 (diff)
downloadhercules-48daed792b6329fdaf384ccf89fbe17cc5d1666e.tar.gz
hercules-48daed792b6329fdaf384ccf89fbe17cc5d1666e.tar.bz2
hercules-48daed792b6329fdaf384ccf89fbe17cc5d1666e.tar.xz
hercules-48daed792b6329fdaf384ccf89fbe17cc5d1666e.zip
Apply code style to pet_hungry() function
Diffstat (limited to 'src/map/pet.c')
-rw-r--r--src/map/pet.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/map/pet.c b/src/map/pet.c
index 9c2832228..c77e20094 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -259,69 +259,72 @@ static int pet_sc_check(struct map_session_data *sd, int type)
return 0;
}
+/**
+ * Updates a pet's hunger value and timer and updates the pet's intimacy value if starving.
+ *
+ * @param tid The timer ID.
+ * @param tick The base amount of ticks to add to the pet's hunger timer. (The timer's current ticks when calling this fuction.)
+ * @param id The pet master's account ID.
+ * @param data Unused.
+ * @return 1 on failure, 0 on success.
+ *
+ **/
static int pet_hungry(int tid, int64 tick, int id, intptr_t data)
{
- struct map_session_data *sd;
- struct pet_data *pd;
- int interval;
-
- sd=map->id2sd(id);
- if(!sd)
- return 1;
+ struct map_session_data *sd = map->id2sd(id);
- if(!sd->status.pet_id || !sd->pd)
+ if (sd == NULL || sd->status.pet_id == 0 || sd->pd == NULL)
return 1;
- pd = sd->pd;
+ struct pet_data *pd = sd->pd;
/**
* If HungerDelay is 0, there's nothing to do.
* Actually this shouldn't happen, since the timer wasn't added in pet_data_init(), but just to be sure...
*
**/
- if (pd->petDB != NULL && pd->petDB->hungry_delay == 0) {
+ if (pd->petDB->hungry_delay == 0) {
pet->hungry_timer_delete(pd);
return 0;
}
- if(pd->pet_hungry_timer != tid){
- ShowError("pet_hungry_timer %d != %d\n",pd->pet_hungry_timer,tid);
- return 0;
+ if (pd->pet_hungry_timer != tid) {
+ ShowError("pet_hungry: pet_hungry_timer %d != %d\n", pd->pet_hungry_timer, tid);
+ return 1;
}
+
pd->pet_hungry_timer = INVALID_TIMER;
if (pd->pet.intimate <= PET_INTIMACY_NONE)
- return 1; //You lost the pet already, the rest is irrelevant.
+ return 1; // You lost the pet already, the rest is irrelevant.
pet->set_hunger(pd, pd->pet.hungry - pd->petDB->hunger_decrement);
- /* Pet Autofeed */
- if (battle_config.feature_enable_pet_autofeed != 0) {
- if (pd->petDB->autofeed == 1 && pd->pet.autofeed == 1 && pd->pet.hungry <= PET_HUNGER_HUNGRY) {
+
+ // Pet auto-feed.
+ if (battle_config.feature_enable_pet_autofeed == 1) {
+ if (pd->petDB->autofeed == 1 && pd->pet.autofeed == 1 && pd->pet.hungry <= PET_HUNGER_HUNGRY)
pet->food(sd, pd);
- }
}
- interval = pd->petDB->hungry_delay;
+ int interval = pd->petDB->hungry_delay;
- if (pd->pet.hungry == PET_HUNGER_STARVING)
- {
+ if (pd->pet.hungry == PET_HUNGER_STARVING) {
pet_stop_attack(pd);
pet->set_intimate(pd, pd->pet.intimate - pd->petDB->starving_decrement);
+
if (pd->pet.intimate == PET_INTIMACY_NONE)
pd->status.speed = pd->db->status.speed;
+
status_calc_pet(pd, SCO_NONE);
- clif->send_petdata(sd,pd,1,pd->pet.intimate);
+ clif->send_petdata(sd, pd, 1, pd->pet.intimate);
if (pd->petDB->starving_delay > 0)
interval = pd->petDB->starving_delay;
}
- clif->send_petdata(sd,pd,2,pd->pet.hungry);
+ clif->send_petdata(sd, pd, 2, pd->pet.hungry);
interval *= battle_config.pet_hungry_delay_rate / 100;
-
- if(interval <= 0)
- interval = 1;
- pd->pet_hungry_timer = timer->add(tick+interval,pet->hungry,sd->bl.id,0);
+ pd->pet_hungry_timer = timer->add(tick + max(interval, 1), pet->hungry, sd->bl.id, 0);
return 0;
}