summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKenpachi Developer <Kenpachi.Developer@gmx.de>2020-02-15 09:05:16 +0100
committerHaru <haru@dotalux.com>2020-04-05 21:20:35 +0200
commitf6b8fe728b4f0cf97da9fea8935c186893868c4d (patch)
treeabde95c1af461159900f8cc91158da76c35491c6 /src
parent70edf6f2d4f042b470cb1f62e408c076f5c8d76b (diff)
downloadhercules-f6b8fe728b4f0cf97da9fea8935c186893868c4d.tar.gz
hercules-f6b8fe728b4f0cf97da9fea8935c186893868c4d.tar.bz2
hercules-f6b8fe728b4f0cf97da9fea8935c186893868c4d.tar.xz
hercules-f6b8fe728b4f0cf97da9fea8935c186893868c4d.zip
Add pet_set_hunger() function
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c2
-rw-r--r--src/map/pet.c24
-rw-r--r--src/map/pet.h1
-rw-r--r--src/map/script.c2
4 files changed, 21 insertions, 8 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 96093ffec..c84f14785 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -2861,7 +2861,7 @@ ACMD(pethungry)
return false;
}
- pd->pet.hungry = hungry;
+ pet->set_hunger(pd, hungry);
clif->send_petstatus(sd);
clif->message(fd, msg_fd(fd,185)); // Pet hunger changed.
diff --git a/src/map/pet.c b/src/map/pet.c
index a1ddec8e3..d112edfc1 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -76,6 +76,20 @@ static int pet_hungry_val(struct pet_data *pd)
return 0;
}
+/**
+ * Sets a pet's hunger value.
+ *
+ * @param pd The pet.
+ * @param value The pet's new hunger value.
+ *
+ **/
+static void pet_set_hunger(struct pet_data *pd, int value)
+{
+ nullpo_retv(pd);
+
+ pd->pet.hungry = cap_value(value, PET_HUNGER_STARVING, PET_HUNGER_STUFFED);
+}
+
static void pet_set_intimate(struct pet_data *pd, int value)
{
struct map_session_data *sd;
@@ -259,7 +273,7 @@ static int pet_hungry(int tid, int64 tick, int id, intptr_t data)
if (pd->pet.intimate <= PET_INTIMACY_NONE)
return 1; //You lost the pet already, the rest is irrelevant.
- pd->pet.hungry -= pd->petDB->hunger_decrement;
+ 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) {
@@ -269,10 +283,9 @@ static int pet_hungry(int tid, int64 tick, int id, intptr_t data)
interval = pd->petDB->hungry_delay;
- if (pd->pet.hungry < PET_HUNGER_STARVING)
+ if (pd->pet.hungry == PET_HUNGER_STARVING)
{
pet_stop_attack(pd);
- pd->pet.hungry = PET_HUNGER_STARVING;
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;
@@ -873,9 +886,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
pd->status.speed = pd->db->status.speed;
}
status_calc_pet(pd, SCO_NONE);
- pd->pet.hungry += pd->petDB->fullness;
- if (pd->pet.hungry > PET_HUNGER_STUFFED)
- pd->pet.hungry = PET_HUNGER_STUFFED;
+ pet->set_hunger(pd, pd->pet.hungry + pd->petDB->fullness);
clif->send_petdata(sd,pd,2,pd->pet.hungry);
clif->send_petdata(sd,pd,1,pd->pet.intimate);
@@ -1665,6 +1676,7 @@ void pet_defaults(void)
pet->final = do_final_pet;
pet->hungry_val = pet_hungry_val;
+ pet->set_hunger = pet_set_hunger;
pet->set_intimate = pet_set_intimate;
pet->create_egg = pet_create_egg;
pet->unlocktarget = pet_unlocktarget;
diff --git a/src/map/pet.h b/src/map/pet.h
index 3d3712243..fa37e896a 100644
--- a/src/map/pet.h
+++ b/src/map/pet.h
@@ -146,6 +146,7 @@ struct pet_interface {
int (*final) (void);
/* */
int (*hungry_val) (struct pet_data *pd);
+ void (*set_hunger) (struct pet_data *pd, int value);
void (*set_intimate) (struct pet_data *pd, int value);
int (*create_egg) (struct map_session_data *sd, int item_id);
int (*unlocktarget) (struct pet_data *pd);
diff --git a/src/map/script.c b/src/map/script.c
index b6e3b8198..a9336a854 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -20109,7 +20109,7 @@ static BUILDIN(setunitdata)
clif->send_petdata(pd->msd, pd, 1, pd->pet.intimate);
break;
case UDT_HUNGER:
- pd->pet.hungry = (short) val;
+ pet->set_hunger(pd, val);
break;
default:
ShowWarning("buildin_setunitdata: Invalid data type '%s' for pet unit.\n", udtype);