From 42289e3df5140df69b394b13e7025c279fdb16c9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 17 Oct 2021 18:12:25 +0300 Subject: [PATCH 50/50] Use common sex module in savegame handling See osdn #43026 Signed-off-by: Marko Lindqvist --- common/sex.c | 15 +++++++++++++++ common/sex.h | 1 + server/savegame/savegame3.c | 7 ++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/common/sex.c b/common/sex.c index e33421daa2..5c0b103e86 100644 --- a/common/sex.c +++ b/common/sex.c @@ -35,3 +35,18 @@ int sex_by_name(const char *name) return SEX_UNKNOWN; } + +/************************************************************************//** + Return name of the sex. +****************************************************************************/ +const char *sex_rule_name(int kind) +{ + switch (kind) { + case SEX_MALE: + return "Male"; + case SEX_FEMALE: + return "Female"; + } + + return NULL; +} diff --git a/common/sex.h b/common/sex.h index c05a5ae1c3..278aed6ab1 100644 --- a/common/sex.h +++ b/common/sex.h @@ -22,6 +22,7 @@ extern "C" { #define SEX_UNKNOWN -1 int sex_by_name(const char *name); +const char *sex_rule_name(int kind); #ifdef __cplusplus } diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index bf6ea140d0..aca6c1ee1b 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -99,6 +99,7 @@ #include "packets.h" #include "research.h" #include "rgbcolor.h" +#include "sex.h" #include "specialist.h" #include "unit.h" #include "unitlist.h" @@ -4062,7 +4063,7 @@ static void sg_load_player_main(struct loaddata *loading, "player%d.idle_turns", plrno), "%s", secfile_error()); kind = secfile_lookup_str(loading->file, "player%d.kind", plrno); - if (!strcmp("male", kind)) { + if (sex_by_name(kind) == SEX_MALE) { plr->is_male = TRUE; } else { plr->is_male = FALSE; @@ -4399,10 +4400,10 @@ static void sg_save_player_main(struct savedata *saving, secfile_insert_int(saving->file, plr->nturns_idle, "player%d.idle_turns", plrno); if (plr->is_male) { - secfile_insert_str(saving->file, "male", + secfile_insert_str(saving->file, sex_rule_name(SEX_MALE), "player%d.kind", plrno); } else { - secfile_insert_str(saving->file, "female", + secfile_insert_str(saving->file, sex_rule_name(SEX_FEMALE), "player%d.kind", plrno); } secfile_insert_bool(saving->file, plr->is_alive, -- 2.33.0