From 6588b4757e4f8ce7781bc2ccbd23f99eb0221e88 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 9 Feb 2021 20:36:08 +0100 Subject: [PATCH] Sentry is server side client state. Make it possible to set it with PACKET_UNIT_SSCS_SET. See osdn #41581 --- common/unit.h | 6 ++++++ server/unithand.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/common/unit.h b/common/unit.h index bf19b5b5c4..0f580a5b85 100644 --- a/common/unit.h +++ b/common/unit.h @@ -111,6 +111,12 @@ struct unit_order { /* The player wants to record that the unit now belongs to the specified * battle group. */ #define SPECENUM_VALUE2 USSDT_BATTLE_GROUP +/* The player wants the unit to stop bothering him unless: + * - a hostile units comes within 3 tiles + * - the unit has its hitpoints restored + * - the unit is bounced + * if 1, 0 to still be bothered. */ +#define SPECENUM_VALUE3 USSDT_SENTRY #include "specenum_gen.h" /* Used in the network protocol */ diff --git a/server/unithand.c b/server/unithand.c index a5ef9e5121..12e34a95da 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -5572,6 +5572,30 @@ void handle_unit_sscs_set(struct player *pplayer, punit->battlegroup = CLIP(-1, value, MAX_NUM_BATTLEGROUPS); + break; + case USSDT_SENTRY: + if (value == 0) { + if (punit->activity != ACTIVITY_SENTRY) { + return; + } + + if (!unit_activity_internal(punit, ACTIVITY_IDLE)) { + /* Impossible to set to Idle? */ + fc_assert(FALSE); + } + } else if (value == 1) { + if (!can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + return; + } + + if (!unit_activity_internal(punit, ACTIVITY_SENTRY)) { + /* Should have been caught above */ + fc_assert(FALSE); + } + } else { + log_verbose("handle_unit_sscs_set(): illegal sentry state for %s %d", + unit_rule_name(punit), punit->id); + } break; } } -- 2.20.1