From 2a67631b62ec47c8f0ed85b6a27c5f559ceca9ac Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 12 Mar 2021 00:27:39 +0100 Subject: [PATCH] "Unit May Embark" action sub result. Introduce the new action sub result "Unit May Embark". It is true if a unit may end up loading into a transport at the target tile if it can't survive there on its own. Represent civstyle.paradrop_to_transport internally - the ruleset representation remains the same - by setting "Unit May Embark" for the paradrop actions. See osdn #41739 --- client/helpdata.c | 9 +++++++++ common/actions.c | 2 +- common/actions.h | 4 ++++ common/networking/packets.def | 1 - server/ruleset.c | 18 ++++++++++++++---- server/unithand.c | 18 +++++++++++------- server/unittools.c | 10 ++++++---- tools/ruleutil/rulesave.c | 4 +++- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/client/helpdata.c b/client/helpdata.c index 082f519795..e7781a84db 100644 --- a/client/helpdata.c +++ b/client/helpdata.c @@ -2863,6 +2863,15 @@ char *helptext_unit(char *buf, size_t bufsz, struct player *pplayer, _(" * if a suitable hut is at the targetet tile it" " will be frightened.\n")); } + if (BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)) { + cat_snprintf(buf, bufsz, + /* TRANS: indented unit action property, preserve + * leading spaces. + * The %s is the unit type name */ + _(" * the %s may end up loaded into a transport if it" + " can't survive on its own at the target tile.\n"), + utype_name_translation(utype)); + } i = 0; action_iterate(blocker_id) { diff --git a/common/actions.c b/common/actions.c index 3a0513a2d7..c045ed83db 100644 --- a/common/actions.c +++ b/common/actions.c @@ -3845,7 +3845,7 @@ is_action_possible(const action_id wanted_action, /* Reason: Keep the old rules. Be merciful. */ /* Info leak: The player sees the target tile. */ if (!can_unit_exist_at_tile(&(wld.map), actor_unit, target_tile) - && (!game.info.paradrop_to_transport + && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK) || !unit_could_load_at(actor_unit, target_tile))) { return TRI_NO; } diff --git a/common/actions.h b/common/actions.h index d9c3d3557a..b430925c1c 100644 --- a/common/actions.h +++ b/common/actions.h @@ -294,6 +294,10 @@ extern "C" { /* Will frighten each frightenable hut at the target tile */ #define SPECENUM_VALUE1 ACT_SUB_RES_HUT_FRIGHTEN #define SPECENUM_VALUE1NAME "Unit Frighten Hut" +/* The actor may load into a transport if it can't survive on its own at the + * target tile. */ +#define SPECENUM_VALUE2 ACT_SUB_RES_MAY_EMBARK +#define SPECENUM_VALUE2NAME "Unit May Embark" #define SPECENUM_BITVECTOR bv_action_sub_results #define SPECENUM_COUNT ACT_SUB_RES_COUNT #include "specenum_gen.h" diff --git a/common/networking/packets.def b/common/networking/packets.def index 8e84fe4bf4..c786979233 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -592,7 +592,6 @@ PACKET_GAME_INFO = 16; sc, is-info BOOL civil_war_enabled; SINT16 civil_war_bonus_celebrating; SINT16 civil_war_bonus_unhappy; - BOOL paradrop_to_transport; UINT16 granularity; end diff --git a/server/ruleset.c b/server/ruleset.c index 8df2c72fff..0a41ae3194 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -6560,10 +6560,6 @@ static bool load_ruleset_game(struct section_file *file, bool act, = secfile_lookup_int_default(file, RS_DEFAULT_CIVIL_WAR_UNHAPPY, "civstyle.civil_war_bonus_unhappy"); - game.info.paradrop_to_transport - = secfile_lookup_bool_default(file, FALSE, - "civstyle.paradrop_to_transport"); - /* TODO: move to global_unit_options */ game.info.base_bribe_cost = secfile_lookup_int_default_min_max(file, @@ -7087,6 +7083,20 @@ static bool load_ruleset_game(struct section_file *file, bool act, ACT_SUB_RES_HUT_FRIGHTEN); BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN_CONQUER)->sub_results, ACT_SUB_RES_HUT_FRIGHTEN); + + /* Unit May Embark */ + action_iterate(act_id) { + struct action *paction = action_by_number(act_id); + + if (secfile_lookup_bool_default(file, FALSE, + "civstyle.paradrop_to_transport") + && (action_has_result(paction, ACTRES_PARADROP) + || action_has_result(paction, ACTRES_PARADROP_CONQUER))) { + BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK); + } + + /* Embark actions will always embark, not maybe embark. */ + } action_iterate_end; } if (ok) { diff --git a/server/unithand.c b/server/unithand.c index 1884129207..de5efc1830 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -495,7 +495,8 @@ static bool do_conquer_extras(struct player *act_player, act_utype = unit_type_get(act_unit); unit_move(act_unit, tgt_tile, move_cost, - NULL, FALSE, FALSE, TRUE, + NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK), + FALSE, TRUE, BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER), BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN)); @@ -674,7 +675,8 @@ static bool do_disembark(struct player *act_player, fc_assert_ret_val(paction, FALSE); unit_move(act_unit, tgt_tile, move_cost, - NULL, FALSE, FALSE, FALSE, + NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK), + FALSE, FALSE, BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER), BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN)); @@ -701,7 +703,8 @@ static bool do_unit_hut(struct player *act_player, fc_assert_ret_val(paction, FALSE); unit_move(act_unit, tgt_tile, move_cost, - NULL, FALSE, FALSE, FALSE, + NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK), + FALSE, FALSE, BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER), BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN)); @@ -738,7 +741,9 @@ static bool do_unit_embark(struct player *act_player, /* Do it. */ tgt_tile = unit_tile(tgt_unit); move_cost = map_move_cost_unit(&(wld.map), act_unit, tgt_tile); - unit_move(act_unit, tgt_tile, move_cost, tgt_unit, FALSE, + unit_move(act_unit, tgt_tile, move_cost, + tgt_unit, BV_ISSET(paction->sub_results, + ACT_SUB_RES_MAY_EMBARK), FALSE, FALSE, BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER), BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN)); @@ -1308,7 +1313,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, && map_is_known_and_seen(target_tile, unit_owner(punit), V_MAIN) && (!can_unit_exist_at_tile(&(wld.map), punit, target_tile) - && (!game.info.paradrop_to_transport + && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK) || !unit_could_load_at(punit, target_tile)))) { explnat->kind = ANEK_BAD_TERRAIN_TGT; explnat->no_act_terrain = tile_terrain(target_tile); @@ -4902,8 +4907,7 @@ static bool unit_do_regular_move(struct player *actor_player, int move_cost = map_move_cost_unit(&(wld.map), actor_unit, target_tile); unit_move(actor_unit, target_tile, move_cost, - /* Don't override "Transport Embark" */ - NULL, FALSE, + NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK), /* Don't override "Conquer City" */ FALSE, /* Don't override "Conquer Extras" */ diff --git a/server/unittools.c b/server/unittools.c index db3125cb2d..91071d4fdf 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -2780,9 +2780,10 @@ bool do_airline(struct unit *punit, struct city *pdest_city, _("%s transported successfully."), unit_link(punit)); - unit_move(punit, pdest_city->tile, punit->moves_left, NULL, + unit_move(punit, pdest_city->tile, punit->moves_left, + NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK), /* Can only airlift to allied and domestic cities */ - FALSE, FALSE, FALSE, + FALSE, FALSE, BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER), BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN)); @@ -2877,7 +2878,7 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, /* Safe terrain, really? Not transformed since player last saw it. */ if (!can_unit_exist_at_tile(&(wld.map), punit, ptile) - && (!game.info.paradrop_to_transport + && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK) || !unit_could_load_at(punit, ptile))) { map_show_circle(pplayer, ptile, unit_type_get(punit)->vision_radius_sq); notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server, @@ -2916,7 +2917,8 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, if (unit_move(punit, ptile, /* Done by Action_Success_Actor_Move_Cost */ 0, - NULL, game.info.paradrop_to_transport, + NULL, BV_ISSET(paction->sub_results, + ACT_SUB_RES_MAY_EMBARK), paction->result == ACTRES_PARADROP_CONQUER, paction->result == ACTRES_PARADROP_CONQUER, BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER), diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 994b335696..97189764f0 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -1142,7 +1142,9 @@ static bool save_game_ruleset(const char *filename, const char *name) save_default_int(sfile, game.info.civil_war_bonus_unhappy, RS_DEFAULT_CIVIL_WAR_UNHAPPY, "civstyle.civil_war_bonus_unhappy", NULL); - save_default_bool(sfile, game.info.paradrop_to_transport, + save_default_bool(sfile, + BV_ISSET(action_by_number(ACTION_PARADROP)->sub_results, + ACT_SUB_RES_MAY_EMBARK), FALSE, "civstyle.paradrop_to_transport", NULL); save_default_int(sfile, game.info.base_bribe_cost, -- 2.20.1