summaryrefslogtreecommitdiff
path: root/src/map/atcommand.c
diff options
context:
space:
mode:
authorKenpachi Developer <Kenpachi.Developer@gmx.de>2020-02-15 11:03:16 +0100
committerHaru <haru@dotalux.com>2020-04-05 21:20:35 +0200
commitb4bc9eaac4470635d1f4efb91680cd41eec3a9d8 (patch)
tree22abb7fdc9ddb6e00a1952c1880cb9b465d9f8df /src/map/atcommand.c
parentd7706989c9b464b21b8cf7e69d8b48fa5661df83 (diff)
downloadhercules-b4bc9eaac4470635d1f4efb91680cd41eec3a9d8.tar.gz
hercules-b4bc9eaac4470635d1f4efb91680cd41eec3a9d8.tar.bz2
hercules-b4bc9eaac4470635d1f4efb91680cd41eec3a9d8.tar.xz
hercules-b4bc9eaac4470635d1f4efb91680cd41eec3a9d8.zip
Apply code style to ACMD(pethungry) function
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r--src/map/atcommand.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 4f6f1c476..6d7898fde 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -2849,36 +2849,46 @@ ACMD(petfriendly)
return true;
}
-/*==========================================
+/**
+ * Sets a pet's hunger value.
*
- *------------------------------------------*/
+ * @code{.herc}
+ * @pethungry <0-100>
+ * @endcode
+ *
+ **/
ACMD(pethungry)
{
- int hungry;
- struct pet_data *pd;
-
- if (!*message || (hungry = atoi(message)) < 0) {
- clif->message(fd, msg_fd(fd,1017)); // Please enter a valid number (usage: @pethungry <0-100>).
+ if (*message == '\0' || (atoi(message) == 0 && isdigit(*message) == 0)) {
+ clif->message(fd, msg_fd(fd, 1017)); // Please enter a valid number (usage: @pethungry <0-100>).
return false;
}
- pd = sd->pd;
- if (!sd->status.pet_id || !pd) {
- clif->message(fd, msg_fd(fd,184)); // Sorry, but you have no pet.
+ int hungry = atoi(message);
+
+ if (hungry < PET_HUNGER_STARVING || hungry > PET_HUNGER_STUFFED) {
+ clif->message(fd, msg_fd(fd, 1017)); // Please enter a valid number (usage: @pethungry <0-100>).
return false;
}
- if (hungry < PET_HUNGER_STARVING || hungry > PET_HUNGER_STUFFED) {
- clif->message(fd, msg_fd(fd,37)); // An invalid number was specified.
+
+ struct pet_data *pd = sd->pd;
+
+ if (sd->status.pet_id == 0 || pd == NULL) {
+ clif->message(fd, msg_fd(fd, 184)); // Sorry, but you have no pet.
return false;
}
- if (hungry == pd->pet.hungry) {
- clif->message(fd, msg_fd(fd,186)); // Pet hunger is already at maximum.
+
+ if (hungry == pd->pet.hungry && hungry == PET_HUNGER_STUFFED) {
+ clif->message(fd, msg_fd(fd, 186)); // Pet hunger is already at maximum.
return false;
}
- pet->set_hunger(pd, hungry);
- clif->send_petstatus(sd);
- clif->message(fd, msg_fd(fd,185)); // Pet hunger changed.
+ if (hungry != pd->pet.hungry) { // No need to update the pet's status if hunger value won't change.
+ pd->pet.hungry = hungry;
+ clif->send_petstatus(sd);
+ }
+
+ clif->message(fd, msg_fd(fd, 185)); // Pet hunger changed. (Send message regardless of value has changed or not.)
return true;
}