From 87966fd320b047e9ffa3b5fc9a1e71d4c0695930 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Thu, 4 Feb 2021 19:13:49 +0100 Subject: [PATCH 10/12] rscompat: clean up slow_invasion. Actions that will need slow_invasion upgrade isn't limited to "Transport Disembark" and "Conquer City 2". Move enabler upgrade to a function. Handle "Transport Disembark 2" as an enabler upgrade even if it was new in 3.1 by inserting the unupgraded enabler first. Move punishment effect insertion to a function too. See osnd #41468 --- server/rscompat.c | 307 ++++++++++++++++++---------------------------- 1 file changed, 119 insertions(+), 188 deletions(-) diff --git a/server/rscompat.c b/server/rscompat.c index 909259018a..a6ffd54e1a 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -1138,6 +1138,120 @@ bool rscompat_auto_attack_3_1(struct rscompat_info *compat, return TRUE; } +/**********************************************************************//** + Slow invasion split existing action enablers for action_orig. +**************************************************************************/ +static bool slow_invasion_enablers(action_id action_orig, + action_id action_copy) +{ + struct action_enabler_list *to_upgrade; + + struct action_enabler *enabler; + struct requirement e_req; + + /* Upgrade exisiting action enablers */ + to_upgrade = action_enabler_list_copy( + action_enablers_for_action(action_orig)); + + action_enabler_list_iterate(to_upgrade, ae) { + /* City center counts as native. */ + enabler = action_enabler_copy(ae); + e_req = req_from_values(VUT_CITYTILE, + REQ_RANGE_LOCAL, + FALSE, TRUE, TRUE, + CITYT_CENTER); + requirement_vector_append(&enabler->actor_reqs, e_req); + action_enabler_add(enabler); + } action_enabler_list_iterate_end; + + action_enabler_list_iterate(to_upgrade, ae) { + /* No TerrainSpeed sees everything as native. */ + enabler = action_enabler_copy(ae); + e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, + FALSE, FALSE, TRUE, + UCF_TERRAIN_SPEED); + requirement_vector_append(&enabler->actor_reqs, e_req); + action_enabler_add(enabler); + } action_enabler_list_iterate_end; + + action_enabler_list_iterate(to_upgrade, ae) { + /* "BeachLander" sees everything as native. */ + enabler = action_enabler_copy(ae); + e_req = req_from_str("UnitFlag", "Local", + FALSE, TRUE, TRUE, + "BeachLander"); + requirement_vector_append(&enabler->actor_reqs, e_req); + action_enabler_add(enabler); + } action_enabler_list_iterate_end; + + action_enabler_list_iterate(to_upgrade, ae) { + /* Use the action_copy for acting from non native. */ + enabler = action_enabler_copy(ae); + enabler->action = action_copy; + + /* Native terrain is native. */ + e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, + FALSE, FALSE, TRUE, USP_NATIVE_TILE); + requirement_vector_append(&enabler->actor_reqs, e_req); + + /* City is native. */ + e_req = req_from_values(VUT_CITYTILE, + REQ_RANGE_LOCAL, + FALSE, FALSE, TRUE, + CITYT_CENTER); + requirement_vector_append(&enabler->actor_reqs, e_req); + + /* No TerrainSpeed sees everything as native. */ + e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, + FALSE, TRUE, TRUE, + UCF_TERRAIN_SPEED); + requirement_vector_append(&enabler->actor_reqs, e_req); + + /* "BeachLander" sees everything as native. */ + e_req = req_from_str("UnitFlag", "Local", + FALSE, FALSE, TRUE, + "BeachLander"); + requirement_vector_append(&enabler->actor_reqs, e_req); + + action_enabler_add(enabler); + } action_enabler_list_iterate_end; + + action_enabler_list_iterate(to_upgrade, ae) { + /* Use for acting from native terrain so acting from + * non native terain is handled by action_copy. */ + e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, + FALSE, TRUE, TRUE, USP_NATIVE_TILE); + requirement_vector_append(&ae->actor_reqs, e_req); + } action_enabler_list_iterate_end; + + action_enabler_list_destroy(to_upgrade); + + return TRUE; +} + +/**********************************************************************//** + Slow invasion movement punishment. +**************************************************************************/ +static bool slow_invasion_effects(const char *action_rule_name) +{ + struct effect *peffect; + + /* Take movement for action from non native terrain */ + peffect = effect_new(EFT_ACTION_SUCCESS_MOVE_COST, + MAX_MOVE_FRAGS, NULL); + /* The reduction only applies to this action. */ + effect_req_append(peffect, req_from_str("Action", "Local", + FALSE, TRUE, TRUE, + action_rule_name)); + /* No reduction here unless disembarking to native terrain. */ + effect_req_append(peffect, req_from_values(VUT_UNITSTATE, + REQ_RANGE_LOCAL, + FALSE, TRUE, TRUE, + USP_NATIVE_TILE)); + + return TRUE; +} + /**********************************************************************//** Replace slow_invasions and friends. **************************************************************************/ @@ -1149,29 +1263,20 @@ bool rscompat_old_slow_invasions_3_1(struct rscompat_info *compat, * generalized" Transport Disembark and Conquer City to handle it. */ struct action_enabler *enabler; - struct requirement e_req; enabler = action_enabler_new(); enabler->action = ACTION_TRANSPORT_DISEMBARK1; - if (slow_invasions) { - /* Use for disembarking from native terrain so disembarking from - * non native terain is handled by "Transport Disembark 2". */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&enabler->actor_reqs, e_req); - } - action_enabler_add(enabler); if (slow_invasions) { /* Make disembarking from non native terrain a different action. */ - struct effect *peffect; struct action *paction; - struct action_enabler_list *to_upgrade; - + slow_invasion_enablers(ACTION_CONQUER_CITY, ACTION_CONQUER_CITY2); + slow_invasion_enablers(ACTION_TRANSPORT_DISEMBARK1, + ACTION_TRANSPORT_DISEMBARK2); /* Add the actions */ @@ -1196,185 +1301,11 @@ bool rscompat_old_slow_invasions_3_1(struct rscompat_info *compat, /* TRANS: _Conquer City from non native (100% chance of success). */ sz_strlcpy(paction->ui_name, N_("%sConquer City from non native%s")); - - /* Enablers for disembark */ - - /* City center counts as native. */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - - - /* No TerrainSpeed sees everything as native. */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - - - /* "BeachLander" sees everything as native. */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - e_req = req_from_str("UnitFlag", "Local", - FALSE, TRUE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - - - /* "Transport Disembark 2" enabler */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK2; - - /* Native terrain is native. */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* City is native. */ - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* "BeachLander" sees everything as native. */ - e_req = req_from_str("UnitFlag", "Local", - FALSE, FALSE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* No TerrainSpeed sees everything as native. */ - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - - action_enabler_add(enabler); - - /* Take movement for disembarking and conquering native terrain from * non native terrain */ - /* Take movement for disembarking from non native terrain */ - peffect = effect_new(EFT_ACTION_SUCCESS_MOVE_COST, - MAX_MOVE_FRAGS, NULL); - - /* The reduction only applies to "Transport Disembark 2". */ - effect_req_append(peffect, req_from_str("Action", "Local", - FALSE, TRUE, TRUE, - "Transport Disembark 2")); - - /* No reduction here unless disembarking to native terrain. */ - effect_req_append(peffect, req_from_values(VUT_UNITSTATE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - USP_NATIVE_TILE)); - - - /* Take movement for conquering from non native terrain */ - peffect = effect_new(EFT_ACTION_SUCCESS_MOVE_COST, - MAX_MOVE_FRAGS, NULL); - - /* The reduction only applies to "Conquer City 2". */ - effect_req_append(peffect, req_from_str("Action", "Local", - FALSE, TRUE, TRUE, - "Conquer City 2")); - - /* No reduction here unless disembarking to native terrain. */ - effect_req_append(peffect, req_from_values(VUT_UNITSTATE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - USP_NATIVE_TILE)); - - /* Upgrade exisiting Conquer City action enablers */ - to_upgrade = action_enabler_list_copy( - action_enablers_for_action(ACTION_CONQUER_CITY)); - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* City center counts as native. */ - enabler = action_enabler_copy(conquer_city_enabler); - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* No TerrainSpeed sees everything as native. */ - enabler = action_enabler_copy(conquer_city_enabler); - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* "BeachLander" sees everything as native. */ - enabler = action_enabler_copy(conquer_city_enabler); - e_req = req_from_str("UnitFlag", "Local", - FALSE, TRUE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* Use "Conquer City 2" for conquring from non native. */ - enabler = action_enabler_copy(conquer_city_enabler); - enabler->action = ACTION_CONQUER_CITY2; - - /* Native terrain is native. */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* City is native. */ - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* No TerrainSpeed sees everything as native. */ - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* "BeachLander" sees everything as native. */ - e_req = req_from_str("UnitFlag", "Local", - FALSE, FALSE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* Use for conquering from native terrain so conquest from - * non native terain is handled by "Conquer City 2". */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&conquer_city_enabler->actor_reqs, e_req); - } action_enabler_list_iterate_end; - - action_enabler_list_destroy(to_upgrade); + slow_invasion_effects("Transport Disembark 2"); + slow_invasion_effects("Conquer City 2"); } } -- 2.20.1