From 25eb78b2fd416e94d754c3624b18ca3f34a8c410 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 10 Nov 2026 04:34:23 +0200
Subject: [PATCH 77/77] Setup unit scout vision on savegame load

See RM #2330

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/savegame/savegame3.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c
index 16d7662b11..84ede78679 100644
--- a/server/savegame/savegame3.c
+++ b/server/savegame/savegame3.c
@@ -6187,6 +6187,7 @@ static bool sg_load_player_unit(struct loaddata *loading,
   int unconverted;
   const char *str;
   enum gen_action action;
+  int gnat_x, gnat_y;
 
   sg_warn_ret_val(secfile_lookup_int(loading->file, &punit->id, "%s.id",
                                      unitstr), FALSE, "%s", secfile_error());
@@ -6355,8 +6356,6 @@ static bool sg_load_player_unit(struct loaddata *loading,
 
   if (secfile_lookup_bool_default(loading->file, FALSE,
                                   "%s.go", unitstr)) {
-    int gnat_x, gnat_y;
-
     sg_warn_ret_val(secfile_lookup_int(loading->file, &gnat_x,
                                        "%s.goto_x", unitstr), FALSE,
                     "%s", secfile_error());
@@ -6381,6 +6380,33 @@ static bool sg_load_player_unit(struct loaddata *loading,
     secfile_entry_ignore(loading->file, "%s.goto_y", unitstr);
   }
 
+  sg_warn_ret_val(secfile_lookup_int(loading->file, &gnat_x,
+                                     "%s.scout_x", unitstr), FALSE,
+                  "%s", secfile_error());
+  sg_warn_ret_val(secfile_lookup_int(loading->file, &gnat_y,
+                                     "%s.scout_y", unitstr), FALSE,
+                  "%s", secfile_error());
+
+  if (gnat_x >= 0) {
+    if (gnat_y >= 0) {
+      struct tile *scout_tile = native_pos_to_tile(&(wld.map), gnat_x, gnat_y);
+
+      unit_scout_vision_gain(punit, scout_tile);
+    } else {
+      log_sg("Unit %d has valid scout tile x-coordinate, "
+             "but invalid y-coordinate.",
+             punit->id);
+      punit->server.scout_vision = nullptr;
+    }
+  } else {
+    if (gnat_y >= 0) {
+      log_sg("Unit %d has valid scout tile y-coordinate, "
+             "but invalid x-coordinate.",
+             punit->id);
+    }
+    punit->server.scout_vision = nullptr;
+  }
+
   /* Load AI data of the unit. */
   CALL_FUNC_EACH_AI(unit_load, loading->file, punit, unitstr);
 
-- 
2.53.0

