Skip to content

Commit

Permalink
Server: Backport 0080-savegame-Save-ACTION_NONE-as-1.patch
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Lindqvist <[email protected]>
  • Loading branch information
cazfi committed May 14, 2024
1 parent 489b40e commit 07f2681
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
4 changes: 4 additions & 0 deletions freeciv/apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
# 0077-Meson-Make-pack_client-to-depend-on-verhdr.patch
# Build fix
# RM #596
# 0080-savegame-Save-ACTION_NONE-as-1.patch
# Savegame loading fix
# RM #598

# Not in the upstream Freeciv server
# ----------------------------------
Expand Down Expand Up @@ -69,6 +72,7 @@ declare -a PATCHLIST=(
"backports/0061-savegame-Correct-loading-last-turn-change-time"
"backports/0073-savecompat-Fix-adding-ACTION_NONE-actions-for-units-"
"backports/0077-Meson-Make-pack_client-to-depend-on-verhdr"
"backports/0080-savegame-Save-ACTION_NONE-as-1"
"RevertAmplio2ExtraUnits"
"meson_webperimental"
"metachange"
Expand Down
113 changes: 113 additions & 0 deletions freeciv/patches/backports/0080-savegame-Save-ACTION_NONE-as-1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
From c902b55fde30f4d24d7bbd95fce4fbe5f6281e03 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <[email protected]>
Date: Sun, 12 May 2024 11:21:28 +0300
Subject: [PATCH 80/80] savegame: Save ACTION_NONE as -1

See RM #598

Signed-off-by: Marko Lindqvist <[email protected]>
---
server/savegame/savecompat.c | 4 ++--
server/savegame/savegame3.c | 26 +++++++++++++++++++++-----
2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c
index 322aae8644..152b756cb3 100644
--- a/server/savegame/savecompat.c
+++ b/server/savegame/savecompat.c
@@ -2556,7 +2556,7 @@ static void compat_load_030300(struct loaddata *loading,
}

if (!found) {
- secfile_insert_int(loading->file, ACTION_NONE, "player%d.u%d.action",
+ secfile_insert_int(loading->file, -1, "player%d.u%d.action",
plrno, unro);
}
}
@@ -3439,7 +3439,7 @@ static void compat_load_dev(struct loaddata *loading)
}

if (!found) {
- secfile_insert_int(loading->file, ACTION_NONE, "player%d.u%d.action",
+ secfile_insert_int(loading->file, -1, "player%d.u%d.action",
plrno, unro);
}
}
diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c
index 137a990700..8c349fc295 100644
--- a/server/savegame/savegame3.c
+++ b/server/savegame/savegame3.c
@@ -5502,11 +5502,13 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr,
order->dir = char2dir(rally_dirs[i]);
order->activity = char2activity(rally_activities[i]);

- unconverted = secfile_lookup_int_default(loading->file, ACTION_NONE,
+ unconverted = secfile_lookup_int_default(loading->file, -1,
"%s.rally_point_action_vec,%d",
citystr, i);

- if (unconverted >= 0 && unconverted < loading->action.size) {
+ if (unconverted == -1) {
+ order->action = ACTION_NONE;
+ } else if (unconverted >= 0 && unconverted < loading->action.size) {
/* Look up what action id the unconverted number represents. */
order->action = loading->action.order[unconverted];
} else {
@@ -5910,6 +5912,10 @@ static void sg_save_player_cities(struct savedata *saving,
case ORDER_LAST:
break;
}
+
+ if (actions[j] == ACTION_NONE) {
+ actions[j] = -1;
+ }
}
orders[len] = dirs[len] = activities[len] = '\0';

@@ -6197,7 +6203,7 @@ static bool sg_load_player_unit(struct loaddata *loading,
sg_warn_ret_val(secfile_lookup_int(loading->file, &ei,
"%s.action", unitstr), FALSE,
"%s", secfile_error());
- if (ei == ACTION_NONE) {
+ if (ei == -1) {
action = ACTION_NONE;
} else {
action = loading->action.order[ei];
@@ -6454,7 +6460,9 @@ static bool sg_load_player_unit(struct loaddata *loading,
"%s.action_vec,%d",
unitstr, j);

- if (unconverted >= 0 && unconverted < loading->action.size) {
+ if (unconverted == -1) {
+ order->action = ACTION_NONE;
+ } else if (unconverted >= 0 && unconverted < loading->action.size) {
/* Look up what action id the unconverted number represents. */
order->action = loading->action.order[unconverted];
} else {
@@ -6725,7 +6733,11 @@ static void sg_save_player_units(struct savedata *saving,
secfile_insert_int(saving->file, punit->activity, "%s.activity", buf);
secfile_insert_int(saving->file, punit->activity_count,
"%s.activity_count", buf);
- secfile_insert_int(saving->file, punit->action, "%s.action", buf);
+ if (punit->action == ACTION_NONE) {
+ secfile_insert_int(saving->file, -1, "%s.action", buf);
+ } else {
+ secfile_insert_int(saving->file, punit->action, "%s.action", buf);
+ }
if (punit->activity_target == NULL) {
secfile_insert_int(saving->file, -1, "%s.activity_tgt", buf);
} else {
@@ -6857,6 +6869,10 @@ static void sg_save_player_units(struct savedata *saving,
case ORDER_LAST:
break;
}
+
+ if (action_buf[j] == ACTION_NONE) {
+ action_buf[j] = -1;
+ }
}
orders_buf[len] = dir_buf[len] = act_buf[len] = '\0';

--
2.43.0

0 comments on commit 07f2681

Please sign in to comment.