From 5fd5321a530c9ea7025744f6a7287d058d0afd69 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 20 Aug 2023 15:48:25 +0300
Subject: [PATCH 6/6] Create unit/city/tile links for messages from supplied
 lua scripts

See osdn #43389

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 data/alien/script.lua         |  7 ++++---
 data/default/default.lua      | 29 ++++++++++++++++-------------
 data/sandbox/script.lua       | 22 +++++++++++-----------
 data/webperimental/script.lua |  8 ++++----
 4 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/data/alien/script.lua b/data/alien/script.lua
index fa2fd77943..383bf9c922 100644
--- a/data/alien/script.lua
+++ b/data/alien/script.lua
@@ -81,14 +81,15 @@ function alien_hut_get_barbarians(unit)
     return true
   end
 
+  local dead_link = unit:tile_link_text()
   local alive = tile:unleash_barbarians()
   if alive then
     notify.event(owner, tile, E.HUT_BARB,
-                  _("It was a trap! Set by the outcasts."));
+                 _("It was a trap! Set by the outcasts."));
   else
     notify.event(owner, tile, E.HUT_BARB_KILLED,
-                  _("Your %s has been killed by outcasts!"),
-                  type:name_translation());
+                 _("Your %s has been killed by outcasts!"),
+                 dead_link);
   end
   return alive
 end
diff --git a/data/default/default.lua b/data/default/default.lua
index 97fd85fd73..8db6eb7e93 100644
--- a/data/default/default.lua
+++ b/data/default/default.lua
@@ -19,9 +19,10 @@
 function _deflua_hut_get_gold(unit, gold)
   local owner = unit.owner
 
-  notify.event(owner, unit.tile, E.HUT_GOLD, PL_("You found %d gold.",
-                                                 "You found %d gold.", gold),
-               gold)
+  notify.event(owner, unit.tile, E.HUT_GOLD,
+               -- TRANS: Begins with a unit name
+               PL_("%s found %d gold.", "%s found %d gold.", gold),
+               unit:link_text(), gold)
   owner:change_gold(gold)
 end
 
@@ -40,10 +41,10 @@ function _deflua_hut_get_tech(unit)
                  _("You found %s in ancient scrolls of wisdom."),
                  tech:name_translation())
     notify.research(owner, false, E.TECH_GAIN,
-                 -- /* TRANS: One player got tech for the whole team. */
-                 _("The %s found %s in ancient scrolls of wisdom for you."),
-                 owner.nation:plural_translation(),
-                 tech:name_translation())
+                    -- /* TRANS: One player got tech for the whole team. */
+                    _("The %s found %s in ancient scrolls of wisdom for you."),
+                    owner.nation:plural_translation(),
+                    tech:name_translation())
     notify.research_embassies(owner, E.TECH_EMBASSY,
                  -- /* TRANS: first %s is nation plural or team name */
                  _("The %s have acquired %s from ancient scrolls of wisdom."),
@@ -115,14 +116,15 @@ function _deflua_hut_get_barbarians(unit)
     return true
   end
 
+  local dead_link = unit:tile_link_text()
   local alive = tile:unleash_barbarians()
   if alive then
     notify.event(owner, tile, E.HUT_BARB,
-                  _("You have unleashed a horde of barbarians!"));
+                 _("You have unleashed a horde of barbarians!"));
   else
     notify.event(owner, tile, E.HUT_BARB_KILLED,
-                  _("Your %s has been killed by barbarians!"),
-                  utype:name_translation());
+                 _("Your %s has been killed by barbarians!"),
+                 dead_link);
   end
   return alive
 end
@@ -132,7 +134,8 @@ function _deflua_hut_reveal_map(unit)
   local owner = unit.owner
 
   notify.event(owner, unit.tile, E.HUT_MAP,
-               _("You find a map of the surrounding terrain."))
+               _("%s finds a map of the surrounding terrain."),
+               unit:link_text())
   for revealtile in unit.tile:circle_iterate(30) do
     revealtile:show(owner)
   end
@@ -214,9 +217,9 @@ function _deflua_make_partisans_callback(city, loser, winner, reason)
   end
   city.tile:place_partisans(loser, partisans, city:map_sq_radius())
   notify.event(loser, city.tile, E.CITY_LOST,
-      _("The loss of %s has inspired partisans!"), city.name)
+      _("The loss of %s has inspired partisans!"), city:link_text())
   notify.event(winner, city.tile, E.UNIT_WIN_ATT,
-      _("The loss of %s has inspired partisans!"), city.name)
+      _("The loss of %s has inspired partisans!"), city:link_text())
 end
 
 signal.connect("city_transferred", "_deflua_make_partisans_callback")
diff --git a/data/sandbox/script.lua b/data/sandbox/script.lua
index 7796252164..5351a05ef3 100644
--- a/data/sandbox/script.lua
+++ b/data/sandbox/script.lua
@@ -52,8 +52,8 @@ function hermit_nest_blown(unit, extra)
   if extra == "Hermit" then
     notify.event(unit.owner, unit.tile, E.HUT_BARB,
                  _("Your %s has overflied a Hermit's Place and destroyed it!"),
-                 unit.utype:name_translation())
-    -- do not process default.lua
+                 unit:link_text())
+    -- Do not process default.lua
     return true
   end
 end
@@ -454,10 +454,10 @@ function notify_unit_unit(action, actor, target)
                E.UNIT_ACTION_ACTOR_SUCCESS,
                -- /* TRANS: Your Marines does Disrupt Supply Lines to American Armor. */
                _("Your %s does %s to %s %s."),
-               actor.utype:name_translation(),
+               actor:link_text(),
                action:name_translation(),
                target.owner.nation:name_translation(),
-               target.utype:name_translation())
+               target:link_text())
 
   -- Notify target
   notify.event(target.owner, actor.tile,
@@ -465,9 +465,9 @@ function notify_unit_unit(action, actor, target)
                -- /* TRANS: German Paratroopers does Disrupt Supply Lines to your Armor. */
                _("%s %s does %s to your %s."),
                actor.owner.nation:name_translation(),
-               actor.utype:name_translation(),
+               actor:link_Text(),
                action:name_translation(),
-               target.utype:name_translation())
+               target:link_text())
 end
 
 -- Handle unit targeted unit action start
@@ -482,20 +482,20 @@ signal.connect("action_started_unit_unit", "action_started_unit_unit_callback")
 
 -- Use Ancient Transportation Network
 function transport_network(action, actor, target)
-  local actor_name = actor.utype:name_translation()
+  local actor_link = actor:link_text()
   local invade_city_val = effects.unit_bonus(actor, target.owner,
                                              "User_Effect_1")
   local invade_extra_val = effects.unit_vs_tile_bonus(actor, target,
                                                       "User_Effect_2")
   local survived = actor:teleport(target,
-                                  -- allow transport to transport
+                                  -- Allow transport to transport
                                   find.transport_unit(actor.owner,
                                                       actor.utype, target),
                                   true,
-                                  -- take city and castle conquest from
+                                  -- Take city and castle conquest from
                                   -- boolean user effects
                                   invade_city_val > 0, invade_extra_val > 0,
-                                  -- a unit appearing from the Ancient
+                                  -- A unit appearing from the Ancient
                                   -- Transportation Network is scary to see
                                   false, true)
 
@@ -505,7 +505,7 @@ function transport_network(action, actor, target)
                  -- /* TRANS: Your Marines didn't survive doing
                  --  * Use Ancient Transportation Network. */
                  _("Your %s didn't survive doing %s."),
-                 actor_name,
+                 actor_link,
                  action:name_translation())
     notify.event(actor.owner, target,
                  E.UNIT_ACTION_ACTOR_FAILURE,
diff --git a/data/webperimental/script.lua b/data/webperimental/script.lua
index d7ff253ad8..37331a071e 100644
--- a/data/webperimental/script.lua
+++ b/data/webperimental/script.lua
@@ -104,10 +104,10 @@ function notify_unit_unit(action, actor, target)
                E.UNIT_ACTION_ACTOR_SUCCESS,
                -- /* TRANS: Your Marines does Disrupt Supply Lines to American Armor. */
                _("Your %s does %s to %s %s."),
-               actor.utype:name_translation(),
+               actor:link_text(),
                action:name_translation(),
                target.owner.nation:name_translation(),
-               target.utype:name_translation())
+               target:link_text())
 
   -- Notify target
   notify.event(target.owner, actor.tile,
@@ -115,9 +115,9 @@ function notify_unit_unit(action, actor, target)
                -- /* TRANS: German Paratroopers does Disrupt Supply Lines to your Armor. */
                _("%s %s does %s to your %s."),
                actor.owner.nation:name_translation(),
-               actor.utype:name_translation(),
+               actor:link_text(),
                action:name_translation(),
-               target.utype:name_translation())
+               target:link_text())
 end
 
 -- Handle unit targeted unit action start
-- 
2.40.1