From b4bc9eaac4470635d1f4efb91680cd41eec3a9d8 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 15 Feb 2020 11:03:16 +0100 Subject: Apply code style to ACMD(pethungry) function --- src/map/atcommand.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/map/atcommand.c') 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; } -- cgit v1.2.3-70-g09d2