From c3b8eb1fb129538d327e0357049da8524512f16f Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Sun, 14 Mar 2021 13:29:17 +0100 Subject: [PATCH] New effect Heal_Unit_Pct. Make how much of the unit's full health the heal unit action will restore ruleset controlled. See osdn #41789 --- ai/default/daieffects.c | 1 + client/helpdata.c | 17 ++++++++++++++--- common/effects.h | 18 ++++++++++-------- data/sandbox/effects.ruleset | 8 ++++++++ data/webperimental/effects.ruleset | 8 ++++++++ doc/README.actions | 1 + doc/README.effects | 5 +++++ server/rscompat.c | 8 ++++++++ server/unithand.c | 12 +++++++++++- 9 files changed, 66 insertions(+), 12 deletions(-) diff --git a/ai/default/daieffects.c b/ai/default/daieffects.c index caf3b4078f..8ce336d626 100644 --- a/ai/default/daieffects.c +++ b/ai/default/daieffects.c @@ -560,6 +560,7 @@ adv_want dai_effect_value(struct player *pplayer, struct government *gov, case EFT_STEALINGS_IGNORE: case EFT_MAPS_STOLEN_PCT: case EFT_UNIT_SHIELD_VALUE_PCT: + case EFT_HEAL_UNIT_PCT: break; /* This has no effect for AI */ case EFT_VISIBLE_WALLS: diff --git a/client/helpdata.c b/client/helpdata.c index e7781a84db..b9f981d280 100644 --- a/client/helpdata.c +++ b/client/helpdata.c @@ -2611,9 +2611,20 @@ char *helptext_unit(char *buf, size_t bufsz, struct player *pplayer, utype_build_shield_cost_base(utype)); break; case ACTRES_HEAL_UNIT: - cat_snprintf(buf, bufsz, - _(" * restores up to 25%% of the target unit's" - " hit points.\n")); + { + struct universal req_pattern[] = { + { .kind = VUT_ACTION, .value.action = paction }, + { .kind = VUT_UTYPE, .value.utype = utype }, + }; + + cat_snprintf(buf, bufsz, + _(" * restores up to %d%% of the target unit's" + " hit points.\n"), + effect_value_from_universals( + EFT_HEAL_UNIT_PCT, + req_pattern, ARRAY_SIZE(req_pattern)) + + 100); + } break; case ACTRES_FOUND_CITY: if (game.scenario.prevent_new_cities) { diff --git a/common/effects.h b/common/effects.h index 70ca8b2740..ce6878dd1d 100644 --- a/common/effects.h +++ b/common/effects.h @@ -314,15 +314,17 @@ extern "C" { #define SPECENUM_VALUE125NAME "Illegal_Action_HP_Cost" #define SPECENUM_VALUE126 EFT_POPCOST_FREE #define SPECENUM_VALUE126NAME "Popcost_Free" +#define SPECENUM_VALUE127 EFT_HEAL_UNIT_PCT +#define SPECENUM_VALUE127NAME "Heal_Unit_Pct" /* Ruleset specific effects for use from Lua scripts */ -#define SPECENUM_VALUE127 EFT_USER_EFFECT_1 -#define SPECENUM_VALUE127NAME "User_Effect_1" -#define SPECENUM_VALUE128 EFT_USER_EFFECT_2 -#define SPECENUM_VALUE128NAME "User_Effect_2" -#define SPECENUM_VALUE129 EFT_USER_EFFECT_3 -#define SPECENUM_VALUE129NAME "User_Effect_3" -#define SPECENUM_VALUE130 EFT_USER_EFFECT_4 -#define SPECENUM_VALUE130NAME "User_Effect_4" +#define SPECENUM_VALUE128 EFT_USER_EFFECT_1 +#define SPECENUM_VALUE128NAME "User_Effect_1" +#define SPECENUM_VALUE129 EFT_USER_EFFECT_2 +#define SPECENUM_VALUE129NAME "User_Effect_2" +#define SPECENUM_VALUE130 EFT_USER_EFFECT_3 +#define SPECENUM_VALUE130NAME "User_Effect_3" +#define SPECENUM_VALUE131 EFT_USER_EFFECT_4 +#define SPECENUM_VALUE131NAME "User_Effect_4" /* keep this last */ #define SPECENUM_COUNT EFT_COUNT #include "specenum_gen.h" diff --git a/data/sandbox/effects.ruleset b/data/sandbox/effects.ruleset index 73135e38ce..9c525aeb33 100644 --- a/data/sandbox/effects.ruleset +++ b/data/sandbox/effects.ruleset @@ -4670,6 +4670,14 @@ reqs = "Action", "Heal Unit 2", "Local", TRUE } +[effect_heal_2_amount] +type = "Heal_Unit_Pct" +value = -75 +reqs = + { "type", "name", "range", "present" + "Action", "Heal Unit 2", "Local", TRUE + } + ; The treasury is better guarded than the drinking water ; See "Poison City Escape" [effect_steal_gold_escape_lower_chance] diff --git a/data/webperimental/effects.ruleset b/data/webperimental/effects.ruleset index 7cf2fb28a0..232ade09c4 100644 --- a/data/webperimental/effects.ruleset +++ b/data/webperimental/effects.ruleset @@ -2880,6 +2880,14 @@ reqs = "Action", "Heal Unit", "Local", TRUE } +[effect_heal_amount] +type = "Heal_Unit_Pct" +value = -75 +reqs = + { "type", "name", "range", "present" + "Action", "Heal Unit", "Local", TRUE + } + [effect_action_success_move_cost_royal_sapper] type = "Action_Success_Actor_Move_Cost" value = 65535 diff --git a/doc/README.actions b/doc/README.actions index bf40bb94b8..db4f6d45b1 100644 --- a/doc/README.actions +++ b/doc/README.actions @@ -593,6 +593,7 @@ Actions done by a unit against another unit "Heal Unit" - Restore the target unit's health. * UI name can be set using ui_name_heal_unit * actor must be on the same tile as the target or on the tile next to it. + * the amount healed is set by the "Heal_Unit_Pct" effect. * the target unit can't be at full health * target must be visible for the actor. diff --git a/doc/README.effects b/doc/README.effects index 65988222a1..d406a73048 100644 --- a/doc/README.effects +++ b/doc/README.effects @@ -293,6 +293,11 @@ DiplRel reqs are unit owner to city owner. Requirements evaluated against tile or city not supported. Default value: 100% +Heal_Unit_Pct + The amount of the units full health the heal unit action will restore. +Will not "heal" the unit to more than 100% of its health. +Default value: 100% + Illegal_Action_Move_Cost The number of move fragments lost when the player tries to do an action that turns out to be illegal. Only applied when the player wasn't aware that diff --git a/server/rscompat.c b/server/rscompat.c index b30826ec7b..f47ffbd086 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -873,6 +873,14 @@ void rscompat_postprocess(struct rscompat_info *info) peffect = effect_new(EFT_UNIT_SHIELD_VALUE_PCT, -50, NULL); effect_req_append(peffect, req_from_str("Action", "Local", FALSE, TRUE, FALSE, "Upgrade Unit")); + + /* The rule that "Heal Unit" heals up to 25% has moved to the + * ruleset. */ + peffect = effect_new(EFT_HEAL_UNIT_PCT, -75, NULL); + effect_req_append(peffect, req_from_str("Action", "Local", FALSE, TRUE, + FALSE, "Heal Unit")); + + } if (info->ver_game < 20) { diff --git a/server/unithand.c b/server/unithand.c index 74e0ff0cbb..998a7e605e 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -555,7 +555,17 @@ static bool do_heal_unit(struct player *act_player, fc_assert_ret_val(tgt_tile, FALSE); /* The max amount of HP that can be added. */ - healing_limit = tgt_hp_max / 4; + healing_limit = ((get_target_bonus_effects(NULL, + unit_owner(act_unit), + unit_owner(tgt_unit), + tile_city(unit_tile(act_unit)), + NULL, unit_tile(act_unit), + act_unit, + unit_type_get(act_unit), + NULL, NULL, paction, + EFT_HEAL_UNIT_PCT) + + 100) + * tgt_hp_max) / 100; /* Heal the target unit. */ tgt_unit->hp = MIN(tgt_unit->hp + healing_limit, tgt_hp_max); -- 2.20.1