From 89ed46d832576eda62a749cffad61a29a672c2b5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 3 Dec 2022 11:11:16 +0200 Subject: [PATCH 44/44] Score: Add units_used counter See osdn #45628 Signed-off-by: Marko Lindqvist --- common/player.h | 1 + server/plrhand.c | 1 + server/report.c | 13 ++++++++++++- server/savegame/savegame2.c | 1 + server/savegame/savegame3.c | 5 +++++ server/unittools.c | 6 ++++-- 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/player.h b/common/player.h index e446668114..81a5564eef 100644 --- a/common/player.h +++ b/common/player.h @@ -112,6 +112,7 @@ struct player_score { int units_killed; /* Number of enemy units killed. */ int units_lost; /* Number of own units that died, * by combat or otherwise. */ + int units_used; /* Number of own units that disappeared upon use */ int culture; int game; /* Total score you get in player dialog. */ }; diff --git a/server/plrhand.c b/server/plrhand.c index 3a4937f091..59d710f331 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -1604,6 +1604,7 @@ void server_player_init(struct player *pplayer, bool initmap, pplayer->score.units_built = 0; pplayer->score.units_killed = 0; pplayer->score.units_lost = 0; + pplayer->score.units_used = 0; /* No delegation. */ pplayer->server.delegate_to[0] = '\0'; diff --git a/server/report.c b/server/report.c index a7bf833333..a46ede0137 100644 --- a/server/report.c +++ b/server/report.c @@ -674,6 +674,14 @@ static int get_units_lost(const struct player *pplayer) return pplayer->score.units_lost; } +/**********************************************************************//** + Number of units used +**************************************************************************/ +static int get_units_used(const struct player *pplayer) +{ + return pplayer->score.units_used; +} + /**********************************************************************//** Amount of gold. **************************************************************************/ @@ -1388,7 +1396,9 @@ void log_civ_score_now(void) {"unitskilled", get_units_killed}, {"unitslost", get_units_lost}, - {"culture", get_culture} /* New tag in 2.6.0. */ + {"culture", get_culture}, /* New tag in 2.6.0. */ + + {"unitsused", get_units_used} /* New tag in 3.2.0. */ }; if (!game.server.scorelog) { @@ -1591,6 +1601,7 @@ void report_final_scores(struct conn_list *dest) { N_("Built Units\n"), get_units_built }, { N_("Killed Units\n"), get_units_killed }, { N_("Unit Losses\n"), get_units_lost }, + { N_("Units Used\n"), get_units_used }, }; const size_t score_categories_num = ARRAY_SIZE(score_categories); diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index ba68473d4f..cd577d5e7c 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -3221,6 +3221,7 @@ static void sg_load_player_main(struct loaddata *loading, plr->score.units_lost = secfile_lookup_int_default(loading->file, 0, "score%d.units_lost", plrno); + plr->score.units_used = 0; /* Was never saved to savegame2.c saves */ plr->score.culture = secfile_lookup_int_default(loading->file, 0, "score%d.culture", plrno); diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 29eef41c40..4cb4b10670 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -4374,6 +4374,9 @@ static void sg_load_player_main(struct loaddata *loading, plr->score.units_lost = secfile_lookup_int_default(loading->file, 0, "score%d.units_lost", plrno); + plr->score.units_used = + secfile_lookup_int_default(loading->file, 0, + "score%d.units_used", plrno); plr->score.culture = secfile_lookup_int_default(loading->file, 0, "score%d.culture", plrno); @@ -4717,6 +4720,8 @@ static void sg_save_player_main(struct savedata *saving, "score%d.units_killed", plrno); secfile_insert_int(saving->file, plr->score.units_lost, "score%d.units_lost", plrno); + secfile_insert_int(saving->file, plr->score.units_used, + "score%d.units_used", plrno); secfile_insert_int(saving->file, plr->score.culture, "score%d.culture", plrno); secfile_insert_int(saving->file, plr->score.game, diff --git a/server/unittools.c b/server/unittools.c index 851d2f95aa..470d13f133 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -2105,10 +2105,12 @@ static void wipe_unit_full(struct unit *punit, bool transported, case ULR_RETIRED: case ULR_DISBANDED: case ULR_USED: - case ULR_EDITOR: - case ULR_PLAYER_DIED: case ULR_DETONATED: case ULR_MISSILE: + pplayer->score.units_used++; + break; + case ULR_EDITOR: + case ULR_PLAYER_DIED: break; } -- 2.35.1