From acc8d1cbc35a06a2ac8fbbe7a69c19d0097c2541 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 16 Feb 2021 15:20:00 +0100 Subject: [PATCH] universal_fulfills_requirement(): unit state. Add a universal_found_function for UnitState properties. See osdn #41588 --- common/requirements.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/common/requirements.c b/common/requirements.c index 4034991348..69b1119b90 100644 --- a/common/requirements.c +++ b/common/requirements.c @@ -4603,6 +4603,42 @@ static enum req_item_found output_type_found(const struct requirement *preq, } } +/**********************************************************************//** + Find if a unit state property fulfills a requirement. +**************************************************************************/ +static enum req_item_found ustate_found(const struct requirement *preq, + const struct universal *source) +{ + fc_assert_ret_val(preq->range == REQ_RANGE_LOCAL, ITF_NOT_APPLICABLE); + + if (preq->source.kind == VUT_UNITSTATE) { + switch (source->value.unit_state) { + case USP_TRANSPORTED: + case USP_TRANSPORTING: + /* USP_TRANSPORTED and USP_TRANSPORTING don't exclude each other. */ + case USP_LIVABLE_TILE: + case USP_NATIVE_TILE: + /* USP_NATIVE_TILE isn't a strict subset of USP_LIVABLE_TILE. See + * UTYF_COAST_STRICT. */ + case USP_DOMESTIC_TILE: + case USP_HAS_HOME_CITY: + case USP_NATIVE_EXTRA: + case USP_MOVED_THIS_TURN: + if (source->value.unit_state == preq->source.value.unit_state) { + /* The other unit states doesn't contradict */ + return ITF_YES; + } + break; + case USP_COUNT: + fc_assert_ret_val(source->value.unit_state != USP_COUNT, + ITF_NOT_APPLICABLE); + } + } + + /* Not found and not relevant. */ + return ITF_NOT_APPLICABLE; +} + /**********************************************************************//** Initialise universal_found_function array. **************************************************************************/ @@ -4620,6 +4656,7 @@ void universal_found_functions_init(void) universal_found_function[VUT_OTYPE] = &output_type_found; universal_found_function[VUT_ACTION] = &action_found; universal_found_function[VUT_DIPLREL] = &diplrel_found; + universal_found_function[VUT_UNITSTATE] = &ustate_found; } /**********************************************************************//** -- 2.20.1