From 82aad7f5bacc5120bdfbbccf7441111da4d3c38f Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 12 Jan 2024 07:49:52 +0200
Subject: [PATCH 44/44] Add hut frightening variants of teleport actions

See RM #174

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c                    | 40 +++++++++++++++++++++++++++
 doc/README.actions                  | 42 +++++++++++++++++++++++++++++
 gen_headers/enums/actions_enums.def |  2 ++
 server/citytools.c                  |  2 ++
 server/ruleset/ruleload.c           |  4 +++
 5 files changed, 90 insertions(+)

diff --git a/common/actions.c b/common/actions.c
index 8a9f8243a4..c78a9cc0a8 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -728,6 +728,18 @@ static void hard_code_actions(void)
                       TRUE, TRUE,
                       MAK_TELEPORT, 1,
                       ACTION_DISTANCE_MAX, FALSE);
+  actions[ACTION_TELEPORT_FRIGHTEN] =
+      unit_action_new(ACTION_TELEPORT_FRIGHTEN,
+                      ACTRES_TELEPORT,
+                      TRUE, TRUE,
+                      MAK_TELEPORT, 1,
+                      ACTION_DISTANCE_MAX, FALSE);
+  actions[ACTION_TELEPORT_FRIGHTEN_CONQUER] =
+      unit_action_new(ACTION_TELEPORT_FRIGHTEN_CONQUER,
+                      ACTRES_TELEPORT_CONQUER,
+                      TRUE, TRUE,
+                      MAK_TELEPORT, 1,
+                      ACTION_DISTANCE_MAX, FALSE);
   actions[ACTION_TELEPORT_ENTER] =
       unit_action_new(ACTION_TELEPORT_ENTER,
                       ACTRES_TELEPORT,
@@ -5925,6 +5937,10 @@ const char *action_ui_name_ruleset_var_name(int act)
     return "ui_name_teleport_3";
   case ACTION_TELEPORT_CONQUER:
     return "ui_name_teleport_conquer";
+  case ACTION_TELEPORT_FRIGHTEN:
+    return "ui_name_teleport_frighten";
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
+    return "ui_name_teleport_frighten_conquer";
   case ACTION_TELEPORT_ENTER:
     return "ui_name_teleport_enter";
   case ACTION_TELEPORT_ENTER_CONQUER:
@@ -6264,6 +6280,12 @@ const char *action_ui_name_default(int act)
   case ACTION_TELEPORT_CONQUER:
     /* TRANS: _Teleport (100% chance of success). */
     return N_("%sTeleport%s");
+  case ACTION_TELEPORT_FRIGHTEN:
+    /* TRANS: _Teleport (100% chance of success). */
+    return N_("%sTeleport%s");
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
+    /* TRANS: _Teleport (100% chance of success). */
+    return N_("%sTeleport%s");
   case ACTION_TELEPORT_ENTER:
     /* TRANS: _Teleport (100% chance of success). */
     return N_("%sTeleport%s");
@@ -6439,6 +6461,10 @@ const char *action_min_range_ruleset_var_name(int act)
     return "teleport_3_min_range";
   case ACTION_TELEPORT_CONQUER:
     return "teleport_conquer_min_range";
+  case ACTION_TELEPORT_FRIGHTEN:
+    return "teleport_frighten_min_range";
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
+    return "teleport_frighten_conquer_min_range";
   case ACTION_TELEPORT_ENTER:
     return "teleport_enter_min_range";
   case ACTION_TELEPORT_ENTER_CONQUER:
@@ -6614,6 +6640,10 @@ const char *action_max_range_ruleset_var_name(int act)
     return "teleport_3_max_range";
   case ACTION_TELEPORT_CONQUER:
     return "teleport_conquer_max_range";
+  case ACTION_TELEPORT_FRIGHTEN:
+    return "teleport_frighten_max_range";
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
+    return "teleport_frighten_conquer_max_range";
   case ACTION_TELEPORT_ENTER:
     return "teleport_enter_max_range";
   case ACTION_TELEPORT_ENTER_CONQUER:
@@ -6767,6 +6797,8 @@ const char *action_target_kind_ruleset_var_name(int act)
   case ACTION_TELEPORT2:
   case ACTION_TELEPORT3:
   case ACTION_TELEPORT_CONQUER:
+  case ACTION_TELEPORT_FRIGHTEN:
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
   case ACTION_TELEPORT_ENTER:
   case ACTION_TELEPORT_ENTER_CONQUER:
   case ACTION_SPY_ESCAPE:
@@ -7135,6 +7167,8 @@ const char *action_actor_consuming_always_ruleset_var_name(action_id act)
   case ACTION_TELEPORT2:
   case ACTION_TELEPORT3:
   case ACTION_TELEPORT_CONQUER:
+  case ACTION_TELEPORT_FRIGHTEN:
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
   case ACTION_TELEPORT_ENTER:
   case ACTION_TELEPORT_ENTER_CONQUER:
   case ACTION_GAIN_VETERANCY:
@@ -7234,6 +7268,10 @@ const char *action_blocked_by_ruleset_var_name(const struct action *act)
     return "teleport_3_blocked_by";
   case ACTION_TELEPORT_CONQUER:
     return "teleport_conquer_blocked_by";
+  case ACTION_TELEPORT_FRIGHTEN:
+    return "teleport_frighten_blocked_by";
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
+    return "teleport_frighten_conquer_blocked_by";
   case ACTION_TELEPORT_ENTER:
     return "teleport_enter_blocked_by";
   case ACTION_TELEPORT_ENTER_CONQUER:
@@ -7500,6 +7538,8 @@ action_post_success_forced_ruleset_var_name(const struct action *act)
   case ACTION_TELEPORT2:
   case ACTION_TELEPORT3:
   case ACTION_TELEPORT_CONQUER:
+  case ACTION_TELEPORT_FRIGHTEN:
+  case ACTION_TELEPORT_FRIGHTEN_CONQUER:
   case ACTION_TELEPORT_ENTER:
   case ACTION_TELEPORT_ENTER_CONQUER:
   case ACTION_GAIN_VETERANCY:
diff --git a/doc/README.actions b/doc/README.actions
index 3cee728647..5fefe8dca1 100644
--- a/doc/README.actions
+++ b/doc/README.actions
@@ -1515,6 +1515,48 @@ Actions done by a unit against a tile
 * the target tile can't contain any units not allied to the actor
   unit and all its cargo.
 
+"Teleport Frighten" - teleport unit to the target tile.
+* UI name can be set using ui_name_teleport_frighten
+* any action listed in teleport_blocked_by must be impossible
+* the range of legal distance between actor unit and target tile
+  must be between teleport_min_range and teleport_max_range
+* the actor unit may not be transported (!)
+* the actor unit's type must be the target tile's terrain animal if the
+  player's nation is an animal barbarian.
+* the actor unit must be able to exist outside of a transport at the target
+  tile.
+* the actor unit doesn't have the "CoastStrict" unit type flag or the
+  target tile is on or adjacent to a tile that doesn't have the
+  "UnsafeCoast" terrain flag.
+* the actor unit can't be diplomatically forbidden from entering the target
+  tile.
+* the target tile can't contain any city or units not allied to the actor
+  unit and all its cargo.
+* can result in hut frightening if
+   - the target tile has an extra with "Enter" in its rmcauses (a Hut)
+   - the target tile's Hut's rmreqs are fulfilled
+
+"Teleport Frighten Conquer" - teleport unit to the target tile and conquer it
+* UI name can be set using ui_name_teleport_frighten_conquer
+* any action listed in teleport_conquer_blocked_by must be impossible
+* the range of legal distance between actor unit and target tile
+  must be between teleport_conquer_min_range and teleport_conquer_max_range
+* the actor unit may not be transported (!)
+* the actor unit's type must be the target tile's terrain animal if the
+  player's nation is an animal barbarian.
+* the actor unit must be able to exist outside of a transport at the target
+  tile.
+* the actor unit doesn't have the "CoastStrict" unit type flag or the
+  target tile is on or adjacent to a tile that doesn't have the
+  "UnsafeCoast" terrain flag.
+* the actor unit can't be diplomatically forbidden from entering the target
+  tile.
+* the target tile can't contain any units not allied to the actor
+  unit and all its cargo.
+* can result in hut frightening if
+   - the target tile has an extra with "Enter" in its rmcauses (a Hut)
+   - the target tile's Hut's rmreqs are fulfilled
+
 "Teleport Enter" - teleport unit to the target tile.
 * UI name can be set using ui_name_teleport
 * any action listed in teleport_blocked_by must be impossible
diff --git a/gen_headers/enums/actions_enums.def b/gen_headers/enums/actions_enums.def
index 6312af9fcf..4940bb3193 100644
--- a/gen_headers/enums/actions_enums.def
+++ b/gen_headers/enums/actions_enums.def
@@ -122,6 +122,8 @@ values
   ACTION_TELEPORT2                        "Teleport2"
   ACTION_TELEPORT3                        "Teleport3"
   ACTION_TELEPORT_CONQUER                 "Teleport Conquer"
+  ACTION_TELEPORT_FRIGHTEN                "Teleport Unit Frighten"
+  ACTION_TELEPORT_FRIGHTEN_CONQUER        "Teleport Unit Frighten Conquer"
   ACTION_TELEPORT_ENTER                   "Teleport Unit Enter"
   ACTION_TELEPORT_ENTER_CONQUER           "Teleport Unit Enter Conquer"
   ACTION_CLEAN                            "Clean"
diff --git a/server/citytools.c b/server/citytools.c
index 640c928546..94b68b6b98 100644
--- a/server/citytools.c
+++ b/server/citytools.c
@@ -1991,6 +1991,8 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity)
                                                ACTION_PARADROP_FRIGHTEN_CONQUER)
                         || utype_can_do_action(unit_type_get(punit),
                                                ACTION_PARADROP_ENTER_CONQUER)
+                        || utype_can_do_action(unit_type_get(punit),
+                                               ACTION_TELEPORT_FRIGHTEN_CONQUER)
                         || utype_can_do_action(unit_type_get(punit),
                                                ACTION_TELEPORT_ENTER_CONQUER),
                         FALSE, "Bad unit for city occupation.");
diff --git a/server/ruleset/ruleload.c b/server/ruleset/ruleload.c
index 89c5a9278e..fdf0d4caae 100644
--- a/server/ruleset/ruleload.c
+++ b/server/ruleset/ruleload.c
@@ -7719,6 +7719,10 @@ static bool load_ruleset_actions(struct section_file *file,
              ACT_SUB_RES_HUT_FRIGHTEN);
       BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN_CONQUER)->sub_results,
              ACT_SUB_RES_HUT_FRIGHTEN);
+      BV_SET(action_by_number(ACTION_TELEPORT_FRIGHTEN)->sub_results,
+             ACT_SUB_RES_HUT_FRIGHTEN);
+      BV_SET(action_by_number(ACTION_TELEPORT_FRIGHTEN_CONQUER)->sub_results,
+             ACT_SUB_RES_HUT_FRIGHTEN);
 
       /* Unit May Embark */
       action_iterate(act_id) {
-- 
2.43.0

