From 9968351553d3bc28b0b52decf42274240806a38b Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Mon, 13 May 2024 16:50:50 +0200 Subject: [PATCH 1/3] Make req eval functions take other_context insted of just other_player See RM #613 Signed-off-by: Alina Lenk --- ai/default/daimilitary.c | 16 +- common/actions.c | 43 +-- common/base.c | 8 +- common/combat.c | 5 +- common/diptreaty.c | 12 +- common/effects.c | 17 +- common/effects.h | 2 +- common/extras.c | 38 ++- common/metaknowledge.c | 31 ++- common/metaknowledge.h | 4 +- common/player.c | 4 +- common/requirements.c | 382 +++++++++++++++------------ common/requirements.h | 20 +- common/research.c | 6 +- common/road.c | 10 +- common/scriptcore/api_game_effects.c | 4 +- common/traderoutes.c | 5 +- common/unit.c | 4 +- server/actiontools.c | 5 +- server/diplhand.c | 8 +- server/diplomats.c | 4 +- server/savegame/savegame2.c | 10 +- server/unithand.c | 11 +- server/unittools.c | 6 +- 24 files changed, 390 insertions(+), 265 deletions(-) diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index 9fda555337..ec9ecf1339 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -360,7 +360,7 @@ static int assess_defense_igwall(struct ai_type *ait, struct city *pcity) **************************************************************************/ static enum fc_tristate tactical_req_cb(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, void *data, int n_data) { @@ -372,7 +372,7 @@ tactical_req_cb(const struct req_context *context, /* FIXME: in actor_reqs, may allow attack _from_ a city with... */ if (req->survives || NULL == context->city || is_great_wonder(b) || !city_has_building(context->city, b) || b->sabotage <= 0) { - return tri_req_active(context, other_player, req); + return tri_req_active(context, other_context, req); } /* Else may be sabotaged */ } @@ -388,12 +388,12 @@ tactical_req_cb(const struct req_context *context, return TRI_MAYBE; case VUT_MINVETERAN: /* Can be changed forth but not back */ - return is_req_preventing(context, other_player, req, RPT_POSSIBLE) + return is_req_preventing(context, other_context, req, RPT_POSSIBLE) > REQUCH_CTRL ? TRI_NO : TRI_MAYBE; case VUT_MINFOREIGNPCT: case VUT_NATIONALITY: /* Can be changed back but hardly forth (foreign citizens reduced first) */ - switch (tri_req_active(context, other_player, req)) { + switch (tri_req_active(context, other_context, req)) { case TRI_NO: return req->present ? TRI_NO : TRI_MAYBE; case TRI_YES: @@ -414,7 +414,7 @@ tactical_req_cb(const struct req_context *context, case VUT_MINYEAR: /* If it is not near, won't change */ return tri_req_active_turns(n_data, 5 /* WAG */, - context, other_player, req); + context, other_context, req); case VUT_CITYSTATUS: if (CITYS_OWNED_BY_ORIGINAL != req->source.value.citystatus && CITYS_TRANSFERRED != req->source.value.citystatus) { @@ -460,7 +460,7 @@ tactical_req_cb(const struct req_context *context, case VUT_TERRFLAG: case VUT_TERRAINALTER: case VUT_NONE: - return tri_req_active(context, other_player, req); + return tri_req_active(context, other_context, req); case VUT_COUNT: /* Not implemented. */ break; @@ -503,11 +503,11 @@ action_may_happen_unit_on_city(const action_id wanted_action, enabler) { /* We assume that we could build or move units into the city * that are not present there yet */ - if (TRI_NO != tri_reqs_cb_active(&actor_ctx, target_player, + if (TRI_NO != tri_reqs_cb_active(&actor_ctx, &target_ctx, &enabler->actor_reqs, NULL, tactical_req_cb, NULL, turns) && - TRI_NO != tri_reqs_cb_active(&target_ctx, actor_player, + TRI_NO != tri_reqs_cb_active(&target_ctx, &actor_ctx, &enabler->target_reqs, NULL, tactical_req_cb, NULL, turns)) { return TRUE; diff --git a/common/actions.c b/common/actions.c index 3839f53d83..103c90051f 100644 --- a/common/actions.c +++ b/common/actions.c @@ -2932,10 +2932,8 @@ static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target) { - return are_reqs_active(actor, target != NULL ? target->player : NULL, - &enabler->actor_reqs, RPT_CERTAIN) - && are_reqs_active(target, actor != NULL ? actor->player : NULL, - &enabler->target_reqs, RPT_CERTAIN); + return are_reqs_active(actor, target, &enabler->actor_reqs, RPT_CERTAIN) + && are_reqs_active(target, actor, &enabler->target_reqs, RPT_CERTAIN); } /**********************************************************************//** @@ -3488,12 +3486,12 @@ action_enabled_local(const action_id wanted_action, result = TRI_NO; action_enabler_list_iterate(action_enablers_for_action(wanted_action), enabler) { - current = fc_tristate_and(mke_eval_reqs(actor->player, actor, - target->player, + current = fc_tristate_and(mke_eval_reqs(actor->player, + actor, target, &enabler->actor_reqs, RPT_CERTAIN), - mke_eval_reqs(actor->player, target, - actor->player, + mke_eval_reqs(actor->player, + target, actor, &enabler->target_reqs, RPT_CERTAIN)); if (current == TRI_YES) { @@ -3513,16 +3511,16 @@ action_enabled_local(const action_id wanted_action, If meta knowledge is missing TRI_MAYBE will be returned. - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. **************************************************************************/ static bool is_effect_val_known(enum effect_type effect_type, const struct player *pov_player, const struct req_context *context, - const struct player *other_player) + const struct req_context *other_context) { effect_list_iterate(get_effects(effect_type), peffect) { - if (TRI_MAYBE == mke_eval_reqs(pov_player, context, - other_player, + if (TRI_MAYBE == mke_eval_reqs(pov_player, context, other_context, &(peffect->reqs), RPT_CERTAIN)) { return FALSE; } @@ -3707,14 +3705,18 @@ action_prob_pre_action_dice_roll(const struct player *act_player, .unit = act_unit, .unittype = unit_type_get(act_unit), }, - tgt_player) + &(const struct req_context) { + .player = tgt_player, + }) && is_effect_val_known(EFT_ACTION_RESIST_PCT, act_player, &(const struct req_context) { .player = tgt_player, .city = tgt_city, .unit = act_unit, }, - act_player)) { + &(const struct req_context) { + .player = act_player, + })) { int unconverted = action_dice_roll_odds(act_player, act_unit, tgt_city, tgt_player, paction); struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT, @@ -5368,7 +5370,9 @@ int action_dice_roll_odds(const struct player *act_player, .unittype = actu_type, .action = paction, }, - tgt_player, + &(const struct req_context) { + .player = tgt_player, + }, EFT_ACTION_ODDS_PCT)) / 100) - ((odds @@ -5380,7 +5384,9 @@ int action_dice_roll_odds(const struct player *act_player, .unittype = actu_type, .action = paction, }, - act_player, + &(const struct req_context) { + .player = act_player, + }, EFT_ACTION_RESIST_PCT)) / 100); @@ -5421,7 +5427,10 @@ static bool is_target_possible(const action_id wanted_action, { action_enabler_list_iterate(action_enablers_for_action(wanted_action), enabler) { - if (are_reqs_active(target, actor_player, + if (are_reqs_active(target, + &(const struct req_context) { + .player = actor_player, + }, &enabler->target_reqs, RPT_POSSIBLE)) { return TRUE; } diff --git a/common/base.c b/common/base.c index c87c542667..460a23411a 100644 --- a/common/base.c +++ b/common/base.c @@ -43,7 +43,9 @@ bool player_can_build_base(const struct base_type *pbase, .player = pplayer, .tile = ptile, }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->reqs, RPT_POSSIBLE); } @@ -66,7 +68,9 @@ bool can_build_base(const struct unit *punit, const struct base_type *pbase, .unit = punit, .unittype = unit_type_get(punit), }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->reqs, RPT_CERTAIN); } diff --git a/common/combat.c b/common/combat.c index 7ae7c60b4c..5552df5bf4 100644 --- a/common/combat.c +++ b/common/combat.c @@ -515,7 +515,10 @@ struct city *sdi_try_defend(const struct civ_map *nmap, .city = pcity, .tile = ptile, }, - owner, EFT_NUKE_PROOF)) { + &(const struct req_context) { + .player = owner, + }, + EFT_NUKE_PROOF)) { return pcity; } } square_iterate_end; diff --git a/common/diptreaty.c b/common/diptreaty.c index 9efddb8c1f..60e034847d 100644 --- a/common/diptreaty.c +++ b/common/diptreaty.c @@ -191,23 +191,27 @@ bool add_clause(struct Treaty *ptreaty, struct player *pfrom, * the requirements. */ if (client_player == NULL || client_player == pfrom) { if (!are_reqs_active(&(const struct req_context) { .player = pfrom }, - pto, &clause_infos[type].giver_reqs, RPT_POSSIBLE)) { + &(const struct req_context) { .player = pto }, + &clause_infos[type].giver_reqs, RPT_POSSIBLE)) { return FALSE; } } if (client_player == NULL || client_player == pto) { if (!are_reqs_active(&(const struct req_context) { .player = pto }, - pfrom, &clause_infos[type].receiver_reqs, + &(const struct req_context) { .player = pfrom }, + &clause_infos[type].receiver_reqs, RPT_POSSIBLE)) { return FALSE; } } if (client_player == NULL) { if (!are_reqs_active(&(const struct req_context) { .player = pfrom }, - pfrom, &clause_infos[type].either_reqs, + &(const struct req_context) { .player = pto }, + &clause_infos[type].either_reqs, RPT_POSSIBLE) && !are_reqs_active(&(const struct req_context) { .player = pto }, - pfrom, &clause_infos[type].either_reqs, + &(const struct req_context) { .player = pfrom }, + &clause_infos[type].either_reqs, RPT_POSSIBLE)) { return FALSE; } diff --git a/common/effects.c b/common/effects.c index 2ccbc52ce8..f21cb673ec 100644 --- a/common/effects.c +++ b/common/effects.c @@ -668,7 +668,7 @@ bool building_has_effect(const struct impr_type *pimprove, context may be NULL. This is equivalent to passing an empty context. **************************************************************************/ static bool is_effect_prevented(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct effect *peffect, const enum req_problem_type prob_type) { @@ -676,7 +676,7 @@ static bool is_effect_prevented(const struct req_context *context, /* Only check present=FALSE requirements; these will return _FALSE_ * from is_req_active() if met, and need reversed prob_type */ if (!preq->present - && !is_req_active(context, other_player, + && !is_req_active(context, other_context, preq, REVERSED_RPT(prob_type))) { return TRUE; } @@ -733,7 +733,8 @@ bool is_building_replaced(const struct city *pcity, context gives the target (or targets) to evaluate requirements against effect_type gives the effect type to be considered - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Returns the effect sources of this type _currently active_. @@ -742,7 +743,7 @@ bool is_building_replaced(const struct city *pcity, **************************************************************************/ int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, enum effect_type effect_type) { int bonus = 0; @@ -754,9 +755,9 @@ int get_target_bonus_effects(struct effect_list *plist, /* Loop over all effects of this type. */ effect_list_iterate(get_effects(effect_type), peffect) { /* For each effect, see if it is active. */ - if (are_reqs_active(context, other_player, + if (are_reqs_active(context, other_context, &peffect->reqs, RPT_CERTAIN)) { - /* This code will add value of effect. If there's multiplier for + /* This code will add value of effect. If there's multiplier for * effect and target_player aren't null, then value is multiplied * by player's multiplier factor. */ if (peffect->multiplier) { @@ -1112,7 +1113,9 @@ int get_unit_vs_tile_bonus(const struct tile *ptile, .unit = punit, .unittype = utype, }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, etype); } diff --git a/common/effects.h b/common/effects.h index beae367755..c78304df57 100644 --- a/common/effects.h +++ b/common/effects.h @@ -169,7 +169,7 @@ int get_city_bonus_effects(struct effect_list *plist, int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, enum effect_type effect_type); double get_effect_expected_value(const struct req_context *context, const struct player *other_player, diff --git a/common/extras.c b/common/extras.c index 0d682d8e6e..7474f2fc17 100644 --- a/common/extras.c +++ b/common/extras.c @@ -477,7 +477,9 @@ bool player_can_build_extra(const struct extra_type *pextra, .player = pplayer, .tile = ptile, }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->reqs, RPT_POSSIBLE); } @@ -546,7 +548,9 @@ bool can_build_extra(const struct extra_type *pextra, .unit = punit, .unittype = unit_type_get(punit), }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->reqs, RPT_CERTAIN); } @@ -600,7 +604,9 @@ bool player_can_remove_extra(const struct extra_type *pextra, .player = pplayer, .tile = ptile, }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->rmreqs, RPT_POSSIBLE); } @@ -623,7 +629,9 @@ bool can_remove_extra(const struct extra_type *pextra, .unit = punit, .unittype = unit_type_get(punit), }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->rmreqs, RPT_CERTAIN); } @@ -723,8 +731,11 @@ bool unit_can_enter_hut(const struct unit *punit, } extra_type_by_rmcause_iterate(ERM_ENTER, extra) { if (tile_has_extra(ptile, extra) - && are_reqs_active(&context, tile_owner(ptile), &extra->rmreqs, - RPT_POSSIBLE)) { + && are_reqs_active(&context, + &(const struct req_context) { + .player = tile_owner(ptile), + }, + &extra->rmreqs, RPT_POSSIBLE)) { return TRUE; } } extra_type_by_rmcause_iterate_end; @@ -751,8 +762,11 @@ bool unit_can_displace_hut(const struct unit *punit, } extra_type_by_rmcause_iterate(ERM_ENTER, extra) { if (tile_has_extra(ptile, extra) - && are_reqs_active(&context, tile_owner(ptile), &extra->rmreqs, - RPT_POSSIBLE)) { + && are_reqs_active(&context, + &(const struct req_context) { + .player = tile_owner(ptile), + }, + &extra->rmreqs, RPT_POSSIBLE)) { return TRUE; } } extra_type_by_rmcause_iterate_end; @@ -1126,7 +1140,9 @@ bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile) && is_native_tile_to_extra(pextra, ptile) && !extra_conflicting_on_tile(pextra, ptile) && are_reqs_active(&(const struct req_context) { .tile = ptile }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->appearance_reqs, RPT_CERTAIN); } @@ -1139,7 +1155,9 @@ bool can_extra_disappear(const struct extra_type *pextra, const struct tile *pti && is_extra_removed_by(pextra, ERM_DISAPPEARANCE) && can_extra_be_removed(pextra, ptile) && are_reqs_active(&(const struct req_context) { .tile = ptile }, - tile_owner(ptile), + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->disappearance_reqs, RPT_CERTAIN); } diff --git a/common/metaknowledge.c b/common/metaknowledge.c index 3cfcff8c03..488dd8889c 100644 --- a/common/metaknowledge.c +++ b/common/metaknowledge.c @@ -151,7 +151,8 @@ static bool can_plr_see_all_sym_diplrels_of(const struct player *pplayer, Is an evaluation of the requirement accurate when pov_player evaluates it? - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. TODO: Move the data to a data file. That will - let non programmers help complete it and/or fix what is wrong @@ -159,7 +160,7 @@ static bool can_plr_see_all_sym_diplrels_of(const struct player *pplayer, **************************************************************************/ static bool is_req_knowable(const struct player *pov_player, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type) { @@ -168,6 +169,9 @@ static bool is_req_knowable(const struct player *pov_player, if (context == NULL) { context = req_context_empty(); } + if (other_context == NULL) { + other_context = req_context_empty(); + } if (req->source.kind == VUT_UTFLAG || req->source.kind == VUT_UTYPE @@ -282,7 +286,7 @@ static bool is_req_knowable(const struct player *pov_player, || req->source.kind == VUT_DIPLREL_UNITANY_O) { switch (req->range) { case REQ_RANGE_LOCAL: - if (other_player == NULL + if (other_context->player == NULL || context->player == NULL) { /* The two players may exist but not be passed when the problem * type is RPT_POSSIBLE. */ @@ -290,12 +294,13 @@ static bool is_req_knowable(const struct player *pov_player, } if (pov_player == context->player - || pov_player == other_player) { + || pov_player == other_context->player) { return TRUE; } if (can_plr_see_all_sym_diplrels_of(pov_player, context->player) - || can_plr_see_all_sym_diplrels_of(pov_player, other_player)) { + || can_plr_see_all_sym_diplrels_of(pov_player, + other_context->player)) { return TRUE; } @@ -714,23 +719,24 @@ static bool is_req_knowable(const struct player *pov_player, /**********************************************************************//** Evaluate a single requirement given pov_player's knowledge. - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Note: Assumed to use pov_player's data. **************************************************************************/ enum fc_tristate mke_eval_req(const struct player *pov_player, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type) { - if (!is_req_knowable(pov_player, context, other_player, + if (!is_req_knowable(pov_player, context, other_context, req, prob_type)) { return TRI_MAYBE; } - if (is_req_active(context, other_player, req, prob_type)) { + if (is_req_active(context, other_context, req, prob_type)) { return TRI_YES; } else { return TRI_NO; @@ -740,14 +746,15 @@ mke_eval_req(const struct player *pov_player, /**********************************************************************//** Evaluate a requirement vector given pov_player's knowledge. - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Note: Assumed to use pov_player's data. **************************************************************************/ enum fc_tristate mke_eval_reqs(const struct player *pov_player, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type) { @@ -756,7 +763,7 @@ mke_eval_reqs(const struct player *pov_player, result = TRI_YES; requirement_vector_iterate(reqs, preq) { - current = mke_eval_req(pov_player, context, other_player, + current = mke_eval_req(pov_player, context, other_context, preq, prob_type); if (current == TRI_NO) { return TRI_NO; diff --git a/common/metaknowledge.h b/common/metaknowledge.h index 97e7e6e103..e04038d5dc 100644 --- a/common/metaknowledge.h +++ b/common/metaknowledge.h @@ -24,14 +24,14 @@ extern "C" { enum fc_tristate mke_eval_req(const struct player *pov_player, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type); enum fc_tristate mke_eval_reqs(const struct player *pov_player, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type); diff --git a/common/player.c b/common/player.c index 209b9c6571..3024008410 100644 --- a/common/player.c +++ b/common/player.c @@ -1661,7 +1661,9 @@ enum casus_belli_range casus_belli_range_for(const struct player *offender, .unittype = off_ut, .action = paction, }, - tgt_plr, + &(const struct req_context) { + .player = tgt_plr, + }, outcome); if (casus_belli_amount >= CASUS_BELLI_OUTRAGE) { diff --git a/common/requirements.c b/common/requirements.c index 055f4d55ca..da6846be34 100644 --- a/common/requirements.c +++ b/common/requirements.c @@ -54,14 +54,14 @@ static universal_found universal_found_function[VUT_COUNT] = {NULL}; static enum fc_tristate tri_req_present(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req); /* Function pointer for requirement-type-specific is_req_active handlers */ typedef enum fc_tristate (*is_req_active_cb)(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req); static inline bool are_tiles_in_range(const struct tile *tile1, @@ -1955,12 +1955,13 @@ static inline bool players_in_same_range(const struct player *pplayer1, is satisfied in a given context (it always is), ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a none requirement + context, other_context and req must not be null, + and req must be a none requirement **************************************************************************/ static enum fc_tristate is_none_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_NONE); @@ -2058,12 +2059,13 @@ static int num_continent_buildings(const struct player *pplayer, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a building requirement + context, other_context and req must not be null, + and req must be a building requirement **************************************************************************/ static enum fc_tristate is_building_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct impr_type *building; @@ -2219,13 +2221,13 @@ is_building_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a building genus - requirement + context, other_context and req must not be null, + and req must be a building genus requirement **************************************************************************/ static enum fc_tristate is_buildinggenus_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_IMPR_GENUS); @@ -2264,13 +2266,13 @@ static enum fc_tristate is_buildingflag_in_city(const struct city *pcity, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a building flag - requirement + context, other_context and req must not be null, + and req must be a building flag requirement **************************************************************************/ static enum fc_tristate is_buildingflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_IMPR_FLAG); @@ -2311,13 +2313,13 @@ is_buildingflag_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a building flag - requirement + context, other_context and req must not be null, + and req must be a player flag requirement **************************************************************************/ static enum fc_tristate is_plr_flag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_PLAYER_FLAG); @@ -2352,13 +2354,13 @@ is_plr_flag_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a building flag - requirement + context, other_context and req must not be null, + and req must be a player state requirement **************************************************************************/ static enum fc_tristate is_plr_state_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_PLAYER_STATE); @@ -2393,12 +2395,13 @@ is_plr_state_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a tech requirement + context, other_context and req must not be null, + and req must be a tech requirement **************************************************************************/ static enum fc_tristate is_tech_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { Tech_type_id tech; @@ -2465,12 +2468,13 @@ is_tech_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a techflag requirement + context, other_context and req must not be null, + and req must be a techflag requirement **************************************************************************/ static enum fc_tristate is_techflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum tech_flag_id techflag; @@ -2529,12 +2533,13 @@ is_techflag_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minculture requirement + context, other_context and req must not be null, + and req must be a minculture requirement **************************************************************************/ static enum fc_tristate is_minculture_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { int minculture; @@ -2602,13 +2607,13 @@ is_minculture_req_active(const struct civ_map *nmap, a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minforeignpct - requirement + context, other_context and req must not be null, + and req must be a minforeignpct requirement **************************************************************************/ static enum fc_tristate is_minforeignpct_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { int min_foreign_pct, foreign_pct; @@ -2673,13 +2678,13 @@ is_minforeignpct_req_active(const struct civ_map *nmap, given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a maxunitsontile - requirement + context, other_context and req must not be null, + and req must be a maxunitsontile requirement **************************************************************************/ static enum fc_tristate is_maxunitsontile_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { int max_units; @@ -2743,12 +2748,13 @@ is_maxunitsontile_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an extra requirement + context, other_context and req must not be null, + and req must be an extra requirement **************************************************************************/ static enum fc_tristate is_extra_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct extra_type *pextra; @@ -2841,12 +2847,13 @@ is_extra_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a goods requirement + context, other_context and req must not be null, + and req must be a goods requirement **************************************************************************/ static enum fc_tristate is_good_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct goods_type *pgood; @@ -2888,12 +2895,13 @@ is_good_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an action requirement + context, other_context and req must not be null, + and req must be an action requirement **************************************************************************/ static enum fc_tristate is_action_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_ACTION); @@ -2917,13 +2925,13 @@ is_action_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an output type - requirement + context, other_context and req must not be null, + and req must be an output type requirement **************************************************************************/ static enum fc_tristate is_outputtype_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_OTYPE); @@ -2938,12 +2946,13 @@ is_outputtype_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a specialist requirement + context, other_context and req must not be null, + and req must be a specialist requirement **************************************************************************/ static enum fc_tristate is_specialist_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_SPECIALIST); @@ -2958,12 +2967,13 @@ is_specialist_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a terrain requirement + context, other_context and req must not be null, + and req must be a terrain requirement **************************************************************************/ static enum fc_tristate is_terrain_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct terrain *pterrain; @@ -3054,13 +3064,13 @@ is_terrain_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a terrain class - requirement + context, other_context and req must not be null, + and req must be a terrain class requirement **************************************************************************/ static enum fc_tristate is_terrainclass_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum terrain_class pclass; @@ -3156,13 +3166,13 @@ is_terrainclass_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a terrain flag - requirement + context, other_context and req must not be null, + and req must be a terrain flag requirement **************************************************************************/ static enum fc_tristate is_terrainflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum terrain_flag_id terrflag; @@ -3264,12 +3274,13 @@ is_terrainflag_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a roadflag requirement + context, other_context and req must not be null, + and req must be a roadflag requirement **************************************************************************/ static enum fc_tristate is_roadflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum road_flag_id roadflag; @@ -3368,12 +3379,13 @@ is_roadflag_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an extraflag requirement + context, other_context and req must not be null, + and req must be an extraflag requirement **************************************************************************/ static enum fc_tristate is_extraflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum extra_flag_id extraflag; @@ -3464,13 +3476,13 @@ is_extraflag_req_active(const struct civ_map *nmap, is satisfied in a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a terrainalter - requirement + context, other_context and req must not be null, + and req must be a terrainalter requirement **************************************************************************/ static enum fc_tristate is_terrainalter_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum terrain_alteration alteration; @@ -3511,12 +3523,13 @@ is_terrainalter_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a gov requirement + context, other_context and req must not be null, + and req must be a gov requirement **************************************************************************/ static enum fc_tristate is_gov_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_GOVERNMENT); @@ -3534,12 +3547,13 @@ is_gov_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a style requirement + context, other_context and req must not be null, + and req must be a style requirement **************************************************************************/ static enum fc_tristate is_style_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_STYLE); @@ -3557,12 +3571,13 @@ is_style_req_active(const struct civ_map *nmap, given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a mintechs requirement + context, other_context and req must not be null, + and req must be a mintechs requirement **************************************************************************/ static enum fc_tristate is_mintechs_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINTECHS); @@ -3592,12 +3607,13 @@ is_mintechs_req_active(const struct civ_map *nmap, given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a mincities requirement + context, other_context and req must not be null, + and req must be a mincities requirement **************************************************************************/ static enum fc_tristate is_mincities_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINCITIES); @@ -3623,12 +3639,13 @@ is_mincities_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an AI level requirement + context, other_context and req must not be null, + and req must be an AI level requirement **************************************************************************/ static enum fc_tristate is_ai_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_AI_LEVEL); @@ -3647,12 +3664,13 @@ is_ai_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a nation requirement + context, other_context and req must not be null, + and req must be a nation requirement **************************************************************************/ static enum fc_tristate is_nation_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct nation_type *nation; @@ -3708,13 +3726,13 @@ is_nation_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a nation group - requirement + context, other_context and req must not be null, + and req must be a nation group requirement **************************************************************************/ static enum fc_tristate is_nationgroup_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct nation_group *ngroup; @@ -3765,13 +3783,13 @@ is_nationgroup_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a nationality - requirement + context, other_context and req must not be null, + and req must be a nationality requirement **************************************************************************/ static enum fc_tristate is_nationality_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct nation_type *nationality; @@ -3840,13 +3858,13 @@ is_nationality_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an original owner - requirement + context, other_context and req must not be null, + and req must be an original owner requirement **************************************************************************/ static enum fc_tristate is_originalowner_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct nation_type *nation; @@ -3937,18 +3955,19 @@ static enum fc_tristate is_diplrel_in_range(const struct player *target_player, satisfied in a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a diplrel requirement + context, other_context and req must not be null, + and req must be a diplrel requirement **************************************************************************/ static enum fc_tristate is_diplrel_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_DIPLREL); - return is_diplrel_in_range(context->player, other_player, req->range, - req->source.value.diplrel); + return is_diplrel_in_range(context->player, other_context->player, + req->range, req->source.value.diplrel); } /**********************************************************************//** @@ -3956,13 +3975,13 @@ is_diplrel_req_active(const struct civ_map *nmap, requirement is satisfied in a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a diplrel_tile - requirement + context, other_context and req must not be null, + and req must be a diplrel_tile requirement **************************************************************************/ static enum fc_tristate is_diplrel_tile_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_DIPLREL_TILE); @@ -3980,20 +3999,20 @@ is_diplrel_tile_req_active(const struct civ_map *nmap, parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a diplrel_tile_o - requirement + context, other_context and req must not be null, + and req must be a diplrel_tile_o requirement **************************************************************************/ static enum fc_tristate is_diplrel_tile_o_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_DIPLREL_TILE_O); return is_diplrel_in_range(context->tile ? tile_owner(context->tile) : NULL, - other_player, + other_context->player, req->range, req->source.value.diplrel); } @@ -4029,13 +4048,13 @@ is_diplrel_unitany_in_range(const struct tile *target_tile, parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a diplrel_unitany - requirement + context, other_context and req must not be null, + and req must be a diplrel_unitany requirement **************************************************************************/ static enum fc_tristate is_diplrel_unitany_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_DIPLREL_UNITANY); @@ -4051,18 +4070,18 @@ is_diplrel_unitany_req_active(const struct civ_map *nmap, parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a diplrel_unitany_o - requirement + context, other_context and req must not be null, + and req must be a diplrel_unitany_o requirement **************************************************************************/ static enum fc_tristate is_diplrel_unitany_o_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_DIPLREL_UNITANY_O); - return is_diplrel_unitany_in_range(context->tile, other_player, + return is_diplrel_unitany_in_range(context->tile, other_context->player, req->range, req->source.value.diplrel); } @@ -4072,12 +4091,13 @@ is_diplrel_unitany_o_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a unittype requirement + context, other_context and req must not be null, + and req must be a unittype requirement **************************************************************************/ static enum fc_tristate is_unittype_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct unit_type *punittype; @@ -4151,12 +4171,13 @@ is_unittype_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a unitflag requirement + context, other_context and req must not be null, + and req must be a unitflag requirement **************************************************************************/ static enum fc_tristate is_unitflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum unit_type_flag_id unitflag; @@ -4230,12 +4251,13 @@ is_unitflag_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a unitclass requirement + context, other_context and req must not be null, + and req must be a unitclass requirement **************************************************************************/ static enum fc_tristate is_unitclass_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct unit_class *pclass; @@ -4309,13 +4331,13 @@ is_unitclass_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a unitclassflag - requirement + context, other_context and req must not be null, + and req must be a unitclassflag requirement **************************************************************************/ static enum fc_tristate is_unitclassflag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum unit_class_flag_id ucflag; @@ -4389,12 +4411,13 @@ is_unitclassflag_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a unitstate requirement + context, other_context and req must not be null, + and req must be a unitstate requirement **************************************************************************/ static enum fc_tristate is_unitstate_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum ustate_prop uprop; @@ -4454,12 +4477,13 @@ is_unitstate_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an activity requirement + context, other_context and req must not be null, + and req must be an activity requirement **************************************************************************/ static enum fc_tristate is_activity_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum unit_activity activity; @@ -4506,12 +4530,13 @@ is_activity_req_active(const struct civ_map *nmap, satisfied in a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minveteran requirement + context, other_context and req must not be null, + and req must be a minveteran requirement **************************************************************************/ static enum fc_tristate is_minveteran_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINVETERAN); @@ -4529,13 +4554,13 @@ is_minveteran_req_active(const struct civ_map *nmap, is satisfied in a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minmovefrags - requirement + context, other_context and req must not be null, + and req must be a minmovefrags requirement **************************************************************************/ static enum fc_tristate is_minmovefrags_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINMOVES); @@ -4553,13 +4578,13 @@ is_minmovefrags_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minhitpoints - requirement + context, other_context and req must not be null, + and req must be a minhitpoints requirement **************************************************************************/ static enum fc_tristate is_minhitpoints_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINHP); @@ -4577,12 +4602,13 @@ is_minhitpoints_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an age requirement + context, other_context and req must not be null, + and req must be an age requirement **************************************************************************/ static enum fc_tristate is_age_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_AGE); @@ -4625,12 +4651,13 @@ is_age_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a form age requirement + context, other_context and req must not be null, + and req must be a form age requirement **************************************************************************/ static enum fc_tristate is_form_age_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_FORM_AGE); @@ -4669,12 +4696,13 @@ static bool is_city_in_tile(const struct tile *ptile, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a citytile requirement + context, other_context and req must not be null, + and req must be a citytile requirement **************************************************************************/ static enum fc_tristate is_citytile_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum citytile_type citytile; @@ -5056,13 +5084,13 @@ is_citytile_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a city status - requirement + context, other_context and req must not be null, + and req must be a city status requirement **************************************************************************/ static enum fc_tristate is_citystatus_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { enum citystatus_type citystatus; @@ -5300,12 +5328,13 @@ is_citystatus_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minsize requirement + context, other_context and req must not be null, + and req must be a minsize requirement **************************************************************************/ static enum fc_tristate is_minsize_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINSIZE); @@ -5342,12 +5371,13 @@ is_minsize_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a counter requirement + context, other_context and req must not be null, + and req must be a counter requirement **************************************************************************/ static enum fc_tristate is_counter_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct counter *count; @@ -5369,13 +5399,13 @@ is_counter_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be an achievement - requirement + context, other_context and req must not be null, + and req must be an achievement requirement **************************************************************************/ static enum fc_tristate is_achievement_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct achievement *achievement; @@ -5415,13 +5445,13 @@ is_achievement_req_active(const struct civ_map *nmap, in a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minlatitude or - maxlatitude requirement + context, other_context and req must not be null, + and req must be a minlatitude or maxlatitude requirement **************************************************************************/ static enum fc_tristate is_latitude_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { int min = -MAP_MAX_LATITUDE, max = MAP_MAX_LATITUDE; @@ -5506,12 +5536,13 @@ is_latitude_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a minyear requirement + context, other_context and req must not be null, + and req must be a minyear requirement **************************************************************************/ static enum fc_tristate is_minyear_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINYEAR); @@ -5524,12 +5555,13 @@ is_minyear_req_active(const struct civ_map *nmap, a given context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a mincalfrag requirement + context, other_context and req must not be null, + and req must be a mincalfrag requirement **************************************************************************/ static enum fc_tristate is_mincalfrag_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_MINCALFRAG); @@ -5543,12 +5575,13 @@ is_mincalfrag_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a topology requirement + context, other_context and req must not be null, + and req must be a topology requirement **************************************************************************/ static enum fc_tristate is_topology_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_TOPO); @@ -5562,12 +5595,13 @@ is_topology_req_active(const struct civ_map *nmap, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a wrap requirement + context, other_context and req must not be null, + and req must be a wrap requirement **************************************************************************/ static enum fc_tristate is_wrap_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_WRAP); @@ -5581,13 +5615,13 @@ is_wrap_req_active(const struct civ_map *nmap, context, ignoring parts of the requirement that can be handled uniformly for all requirement types. - context and req must not be null, and req must be a server setting - requirement + context, other_context and req must not be null, + and req must be a server setting requirement **************************************************************************/ static enum fc_tristate is_serversetting_req_active(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_SERVERSETTING); @@ -5667,19 +5701,21 @@ static struct req_def req_definitions[VUT_COUNT] = { context gives the target (or targets) to evaluate against req gives the requirement itself - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Make sure you give all aspects of the target when calling this function: for instance if you have TARGET_CITY pass the city's owner as the target player as well as the city itself as the target city. **************************************************************************/ bool is_req_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type) { const struct civ_map *nmap = &(wld.map); - enum fc_tristate eval = tri_req_present(nmap, context, other_player, req); + enum fc_tristate eval = tri_req_present(nmap, context, other_context, + req); if (eval == TRI_MAYBE) { if (prob_type == RPT_POSSIBLE) { @@ -5694,7 +5730,8 @@ bool is_req_active(const struct req_context *context, /**********************************************************************//** Applies the standard evaluation of req in context, ignoring req->present. - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Fields of context that are NULL are considered unspecified and will produce TRI_MAYBE if req needs them to evaluate. @@ -5702,12 +5739,15 @@ bool is_req_active(const struct req_context *context, static enum fc_tristate tri_req_present(const struct civ_map *nmap, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { - if (context == NULL) { + if (!context) { context = req_context_empty(); } + if (!other_context) { + other_context = req_context_empty(); + } if (req->source.kind >= VUT_COUNT) { log_error("tri_req_present(): invalid source kind %d.", @@ -5718,23 +5758,24 @@ enum fc_tristate tri_req_present(const struct civ_map *nmap, fc_assert_ret_val(req_definitions[req->source.kind].cb != NULL, TRI_NO); return req_definitions[req->source.kind].cb(nmap, context, - other_player, req); + other_context, req); } /**********************************************************************//** - Evaluates req in context with other_player to fc_tristate. + Evaluates req in context to fc_tristate. - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Fields of context that are NULL are considered unspecified and will produce TRI_MAYBE if req needs them to evaluate. **************************************************************************/ enum fc_tristate tri_req_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { const struct civ_map *nmap = &(wld.map); - enum fc_tristate eval = tri_req_present(nmap, context, other_player, req); + enum fc_tristate eval = tri_req_present(nmap, context, other_context, req); if (!req->present) { if (TRI_NO == eval) { @@ -5756,19 +5797,20 @@ enum fc_tristate tri_req_active(const struct req_context *context, reqs gives the requirement vector. The function returns TRUE only if all requirements are active. - context may be NULL. This is equivalent to passing an empty context. + context and other_context may be NULL. This is equivalent to passing + empty contexts. Make sure you give all aspects of the target when calling this function: for instance if you have TARGET_CITY pass the city's owner as the target player as well as the city itself as the target city. **************************************************************************/ bool are_reqs_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type) { requirement_vector_iterate(reqs, preq) { - if (!is_req_active(context, other_player, preq, prob_type)) { + if (!is_req_active(context, other_context, preq, prob_type)) { return FALSE; } } requirement_vector_iterate_end; @@ -5783,13 +5825,13 @@ bool are_reqs_active(const struct req_context *context, bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type) { requirement_vector_iterate(reqs, preq) { if (preq->range >= min_range && preq->range <= max_range) { - if (!is_req_active(context, other_player, preq, prob_type)) { + if (!is_req_active(context, other_context, preq, prob_type)) { return FALSE; } } @@ -5807,7 +5849,7 @@ bool are_reqs_active_ranges(const enum req_range min_range, enum fc_tristate tri_req_active_turns(int pass, int period, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req) { /* FIXME: doubles code from calendar.c */ @@ -5918,7 +5960,7 @@ tri_req_active_turns(int pass, int period, break; default: /* No special handling invented */ - return tri_req_active(context, other_player, req); + return tri_req_active(context, other_context, req); } return BOOL_TO_TRISTATE(req->present ? present || present1 : !(present && present1)); @@ -5931,7 +5973,7 @@ tri_req_active_turns(int pass, int period, **************************************************************************/ enum fc_tristate default_tester_cb (const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, void *data, int n_data) { @@ -5948,7 +5990,7 @@ enum fc_tristate default_tester_cb } } - return tri_req_active(context, other_player, req); + return tri_req_active(context, other_context, req); } /**********************************************************************//** @@ -5959,7 +6001,7 @@ enum fc_tristate default_tester_cb **************************************************************************/ enum fc_tristate tri_reqs_cb_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, struct requirement_vector *maybe_reqs, req_tester_cb tester, @@ -5970,7 +6012,7 @@ enum fc_tristate fc_assert_ret_val(NULL != tester, TRI_NO); requirement_vector_iterate(reqs, preq) { - switch(tester(context, other_player, preq, + switch(tester(context, other_context, preq, data, n_data)) { case TRI_NO: active = FALSE; @@ -6054,7 +6096,7 @@ enum req_unchanging_status ***************************************************************************/ enum req_unchanging_status is_req_preventing(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, enum req_problem_type prob_type) { @@ -6069,7 +6111,7 @@ enum req_unchanging_status || REQUC_WORLD == req_definitions[req->source.kind].unchanging_cond; if (auto_present ? req->present - : is_req_active(context, other_player, req, RPT_POSSIBLE)) { + : is_req_active(context, other_context, req, RPT_POSSIBLE)) { /* Unchanging but does not block */ return REQUCH_NO; } diff --git a/common/requirements.h b/common/requirements.h index 60783f7548..590bec8aac 100644 --- a/common/requirements.h +++ b/common/requirements.h @@ -126,7 +126,7 @@ enum req_unchanging_status { /* A callback that may transform kind-specific default unchanging status * to another one (usually higher but not always) - * Passing other_player is just not needed for it in any known cases */ + * Passing other_context is just not needed for it in any known cases */ typedef enum req_unchanging_status (*req_unchanging_cond_cb)(const struct civ_map *nmap, enum req_unchanging_status def, @@ -165,44 +165,44 @@ bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec); enum fc_tristate tri_req_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req); bool is_req_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type); bool are_reqs_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type); bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type); enum fc_tristate tri_req_active_turns(int pass, int period, const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req); /* Type of a callback that tests requirements due to a context * and something else in some manner different from tri_req_active() */ typedef enum fc_tristate (*req_tester_cb)(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, void *data, int n_data); enum fc_tristate default_tester_cb(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, void *data, int n_data); enum fc_tristate tri_reqs_cb_active(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, struct requirement_vector *maybe_reqs, req_tester_cb tester, @@ -213,7 +213,7 @@ enum req_unchanging_status const struct requirement *req); enum req_unchanging_status is_req_preventing(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement *req, enum req_problem_type prob_type); diff --git a/common/research.c b/common/research.c index d6f4ee3fbf..d4d313bb88 100644 --- a/common/research.c +++ b/common/research.c @@ -301,12 +301,12 @@ research_advance_name_translation(const struct research *presearch, If may become active if all unchangeable requirements are active. ****************************************************************************/ static bool reqs_may_activate(const struct req_context *context, - const struct player *other_player, + const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type) { requirement_vector_iterate(reqs, preq) { - if (is_req_preventing(context, other_player, preq, prob_type)) { + if (is_req_preventing(context, other_context, preq, prob_type)) { return FALSE; } } requirement_vector_iterate_end; @@ -327,7 +327,7 @@ static bool research_allowed(const struct research *presearch, Tech_type_id tech, bool (*reqs_eval)(const struct req_context *context, - const struct player *oplr, + const struct req_context *ocontext, const struct requirement_vector *reqs, const enum req_problem_type ptype)) { diff --git a/common/road.c b/common/road.c index 2e071bac1b..4936350e03 100644 --- a/common/road.c +++ b/common/road.c @@ -263,14 +263,20 @@ static bool are_road_reqs_fulfilled(const struct civ_map *nmap, } extra_type_list_iterate_end; if (beginning) { - if (!are_reqs_active(&context, tile_owner(ptile), + if (!are_reqs_active(&context, + &(const struct req_context) { + .player = tile_owner(ptile), + }, &proad->first_reqs, RPT_POSSIBLE)) { return FALSE; } } } - return are_reqs_active(&context, tile_owner(ptile), + return are_reqs_active(&context, + &(const struct req_context) { + .player = tile_owner(ptile), + }, &pextra->reqs, RPT_POSSIBLE); } diff --git a/common/scriptcore/api_game_effects.c b/common/scriptcore/api_game_effects.c index 4ea4e7e25f..b61999da8f 100644 --- a/common/scriptcore/api_game_effects.c +++ b/common/scriptcore/api_game_effects.c @@ -105,7 +105,9 @@ int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player, .unit = punit, .unittype = unit_type_get(punit), }, - other_player, + &(const struct req_context) { + .player = other_player, + }, etype); } diff --git a/common/traderoutes.c b/common/traderoutes.c index c9e996162c..952ef7e3ea 100644 --- a/common/traderoutes.c +++ b/common/traderoutes.c @@ -530,7 +530,10 @@ int get_caravan_enter_city_trade_bonus(const struct city *pc1, ? ACTION_TRADE_ROUTE : ACTION_MARKETPLACE ), - }, city_owner(pc2), + }, + &(const struct req_context) { + .player = city_owner(pc2), + }, EFT_TRADE_REVENUE_BONUS); /* Be mercy full to players with small amounts. Round up. */ diff --git a/common/unit.c b/common/unit.c index 16e5a1b926..6690b5bbf2 100644 --- a/common/unit.c +++ b/common/unit.c @@ -2389,7 +2389,9 @@ int unit_bribe_cost(struct unit *punit, struct player *briber) .unit = punit, .unittype = ptype, }, - briber, + &(const struct req_context) { + .player = briber, + }, EFT_UNIT_BRIBE_COST_PCT)) / 100; diff --git a/server/actiontools.c b/server/actiontools.c index 2860b933b5..4d3473dc34 100644 --- a/server/actiontools.c +++ b/server/actiontools.c @@ -958,7 +958,10 @@ action_auto_perf_unit_sel(const enum action_auto_perf_cause cause, }; action_auto_perf_by_cause_iterate(cause, autoperformer) { - if (are_reqs_active(&actor_ctxt, other_player, + if (are_reqs_active(&actor_ctxt, + &(const struct req_context) { + .player = other_player, + }, &autoperformer->reqs, RPT_CERTAIN)) { /* Select this action auto performer. */ return autoperformer; diff --git a/server/diplhand.c b/server/diplhand.c index 988ba6df15..05eab429de 100644 --- a/server/diplhand.c +++ b/server/diplhand.c @@ -184,9 +184,9 @@ void handle_diplomacy_accept_treaty_req(struct player *pplayer, if (pclause->from == pplayer) { struct clause_info *info = clause_info_get(pclause->type); - if (!are_reqs_active(&player_ctxt, pother, + if (!are_reqs_active(&player_ctxt, &other_ctxt, &(info->giver_reqs), RPT_POSSIBLE) - || !are_reqs_active(&other_ctxt, pplayer, + || !are_reqs_active(&other_ctxt, &player_ctxt, &(info->receiver_reqs), RPT_POSSIBLE)) { log_error("Requirements of a clause between %s and %s not fulfilled", player_name(pplayer), player_name(pother)); @@ -341,9 +341,9 @@ void handle_diplomacy_accept_treaty_req(struct player *pplayer, if (pclause->from == pother) { struct clause_info *info = clause_info_get(pclause->type); - if (!are_reqs_active(&other_ctxt, pplayer, + if (!are_reqs_active(&other_ctxt, &player_ctxt, &(info->giver_reqs), RPT_POSSIBLE) - || !are_reqs_active(&player_ctxt, pother, + || !are_reqs_active(&player_ctxt, &other_ctxt, &(info->receiver_reqs), RPT_POSSIBLE)) { notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server, _("Clause requirements are no longer fulfilled. " diff --git a/server/diplomats.c b/server/diplomats.c index 05b08a91bf..1a4e4920b3 100644 --- a/server/diplomats.c +++ b/server/diplomats.c @@ -1790,7 +1790,9 @@ bool spy_steal_some_maps(struct player *act_player, struct unit *act_unit, .unittype = unit_type_get(act_unit), .action = paction, }, - tgt_player, + &(const struct req_context) { + .player = tgt_player, + }, EFT_MAPS_STOLEN_PCT); give_distorted_map(tgt_player, act_player, normal_tile_prob, diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index f5bbd75fdf..67f21c237c 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -1029,7 +1029,10 @@ static void sg_special_set_dbv(struct tile *ptile, struct dbv *extras, char ch, if ((!is_extra_caused_by(candidate, EC_BASE) || tile_city(vtile) != NULL || extra_base_get(candidate)->border_sq <= 0) - && are_reqs_active(&tile_ctxt, tile_owner(vtile), + && are_reqs_active(&tile_ctxt, + &(const struct req_context) { + .player = tile_owner(vtile), + }, &candidate->reqs, RPT_POSSIBLE)) { pextra = candidate; @@ -1166,7 +1169,10 @@ static void sg_special_set_bv(struct tile *ptile, bv_extras *extras, char ch, if ((!is_extra_caused_by(candidate, EC_BASE) || tile_city(vtile) != NULL || extra_base_get(candidate)->border_sq <= 0) - && are_reqs_active(&tile_ctxt, tile_owner(vtile), + && are_reqs_active(&tile_ctxt, + &(const struct req_context) { + .player = tile_owner(vtile), + }, &candidate->reqs, RPT_POSSIBLE)) { pextra = candidate; diff --git a/server/unithand.c b/server/unithand.c index e7fee8a5aa..694be8cad6 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -776,7 +776,9 @@ static bool do_heal_unit(struct player *act_player, .unittype = unit_type_get(act_unit), .action = paction, }, - unit_owner(tgt_unit), + &(const struct req_context) { + .player = unit_owner(tgt_unit), + }, EFT_HEAL_UNIT_PCT ) + 100) * tgt_hp_max) / 100; @@ -2998,6 +3000,9 @@ static bool illegal_action_pay_price(struct player *pplayer, .unittype = unit_type_get(act_unit), .action = stopped_action, }; + const struct req_context tgt_ctxt = { + .player = tgt_player, + }; /* Don't punish the player for something the game did. Don't tell the * player that the rules required the game to try to do something @@ -3016,7 +3021,7 @@ static bool illegal_action_pay_price(struct player *pplayer, /* The mistake may have a cost. */ /* HP cost */ - punishment_hp = get_target_bonus_effects(NULL, &actor_ctxt, tgt_player, + punishment_hp = get_target_bonus_effects(NULL, &actor_ctxt, &tgt_ctxt, EFT_ILLEGAL_ACTION_HP_COST); /* Stay in range */ @@ -3068,7 +3073,7 @@ static bool illegal_action_pay_price(struct player *pplayer, } /* MP cost */ - punishment_mp = get_target_bonus_effects(NULL, &actor_ctxt, tgt_player, + punishment_mp = get_target_bonus_effects(NULL, &actor_ctxt, &tgt_ctxt, EFT_ILLEGAL_ACTION_MOVE_COST); /* Stay in range */ diff --git a/server/unittools.c b/server/unittools.c index fcd4a60648..b1a938158e 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -3341,7 +3341,11 @@ static void unit_enter_hut(struct unit *punit, bool frighten_hut) extra_type_by_rmcause_iterate(ERM_ENTER, pextra) { if (tile_has_extra(ptile, pextra) - && are_reqs_active(&context, tile_owner(ptile), &pextra->rmreqs, + && are_reqs_active(&context, + &(const struct req_context) { + .player = tile_owner(ptile), + }, + &pextra->rmreqs, RPT_CERTAIN) ) { hut = TRUE; -- 2.34.1