From 6c17875a60e060d780fd69b4dbc639333105ea28 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 | 22 ++++++++++++---------- 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, 68 insertions(+), 14 deletions(-) diff --git a/ai/default/daieffects.c b/ai/default/daieffects.c index ea628e55d9..b0ce514ce0 100644 --- a/ai/default/daieffects.c +++ b/ai/default/daieffects.c @@ -561,6 +561,7 @@ adv_want dai_effect_value(struct player *pplayer, struct government *gov, case EFT_MAPS_STOLEN_PCT: case EFT_UNIT_SHIELD_VALUE_PCT: case EFT_NUKE_BLAST_RADIUS_1_SQ: + 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 ce5826fd96..cee38b1df5 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 3ecf2a4d28..e905320108 100644 --- a/common/effects.h +++ b/common/effects.h @@ -314,17 +314,19 @@ extern "C" { #define SPECENUM_VALUE125NAME "Illegal_Action_HP_Cost" #define SPECENUM_VALUE126 EFT_POPCOST_FREE #define SPECENUM_VALUE126NAME "Popcost_Free" -#define SPECENUM_VALUE127 EFT_NUKE_BLAST_RADIUS_1_SQ -#define SPECENUM_VALUE127NAME "Nuke_Blast_Radius_1_Sq" +#define SPECENUM_VALUE127 EFT_HEAL_UNIT_PCT +#define SPECENUM_VALUE127NAME "Heal_Unit_Pct" +#define SPECENUM_VALUE128 EFT_NUKE_BLAST_RADIUS_1_SQ +#define SPECENUM_VALUE128NAME "Nuke_Blast_Radius_1_Sq" /* Ruleset specific effects for use from Lua scripts */ -#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" +#define SPECENUM_VALUE129 EFT_USER_EFFECT_1 +#define SPECENUM_VALUE129NAME "User_Effect_1" +#define SPECENUM_VALUE130 EFT_USER_EFFECT_2 +#define SPECENUM_VALUE130NAME "User_Effect_2" +#define SPECENUM_VALUE131 EFT_USER_EFFECT_3 +#define SPECENUM_VALUE131NAME "User_Effect_3" +#define SPECENUM_VALUE132 EFT_USER_EFFECT_4 +#define SPECENUM_VALUE132NAME "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 36a34ed22b..c550fd7d51 100644 --- a/data/sandbox/effects.ruleset +++ b/data/sandbox/effects.ruleset @@ -4694,6 +4694,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 cdc3986150..ce419ac7c9 100644 --- a/data/webperimental/effects.ruleset +++ b/data/webperimental/effects.ruleset @@ -2920,6 +2920,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 9dd151adb1..4520f4959b 100644 --- a/doc/README.actions +++ b/doc/README.actions @@ -595,6 +595,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 210675c1ea..45b78bc991 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% + Nuke_Blast_Radius_1_Sq The size of the radius of the blast area in squared distance from ground zero in amount tiles. diff --git a/server/rscompat.c b/server/rscompat.c index 2eb5970582..3329cc1c92 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -812,6 +812,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 e9233d93cd..a5cb29c0ad 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