From f4af4eeedea5a492ccbfa619d2df20ed0bae6143 Mon Sep 17 00:00:00 2001 From: UberWaffe Date: Thu, 21 Sep 2023 18:22:29 +0200 Subject: [PATCH] fix: Building counts for specific fort types (#966) --- src/building/count.c | 26 +++++++++++++++++++ src/building/count.h | 15 +++++++++++ .../condition_types/condition_types.c | 18 +++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/building/count.c b/src/building/count.c index d6bd640b46..0e11c66c96 100644 --- a/src/building/count.c +++ b/src/building/count.c @@ -58,3 +58,29 @@ int building_count_upgraded(building_type type) } return upgraded; } + +int building_count_active_fort_type(figure_type type) +{ + int active = 0; + for (building *b = building_first_of_type(BUILDING_FORT); b; b = b->next_of_type) { + if (building_is_active(b) && b == building_main(b)) { + if (b->subtype.fort_figure_type == type) { + active++; + } + } + } + return active; +} + +int building_count_fort_type_total(figure_type type) +{ + int total = 0; + for (building *b = building_first_of_type(BUILDING_FORT); b; b = b->next_of_type) { + if ((b->state == BUILDING_STATE_IN_USE || b->state == BUILDING_STATE_CREATED) && b == building_main(b)) { + if (b->subtype.fort_figure_type == type) { + total++; + } + } + } + return total; +} diff --git a/src/building/count.h b/src/building/count.h index ea22862c85..4c3e3fdec6 100644 --- a/src/building/count.h +++ b/src/building/count.h @@ -3,6 +3,7 @@ #include "core/buffer.h" #include "building/type.h" +#include "figure/type.h" #include "game/resource.h" /** @@ -44,4 +45,18 @@ int building_count_grand_temples(void); int building_count_grand_temples(void); int building_count_grand_temples_active(void); +/** + * Returns the active building count for forts based on the assigned soldier (figure) type + * @param type Figure type + * @return Number of active forts of that type + */ +int building_count_active_fort_type(figure_type type); + +/** + * Returns the building count for forts based on the assigned soldier (figure) type + * @param type Figure type + * @return Total number of forts of that type + */ +int building_count_fort_type_total(figure_type type); + #endif // BUILDING_COUNT_H diff --git a/src/scenario/condition_types/condition_types.c b/src/scenario/condition_types/condition_types.c index d5d6907c4c..9211677a8d 100644 --- a/src/scenario/condition_types/condition_types.c +++ b/src/scenario/condition_types/condition_types.c @@ -110,6 +110,15 @@ int scenario_condition_type_building_count_active_met(const scenario_condition_t total_active_count += building_count_active(BUILDING_LARGE_POND); total_active_count += building_count_active(BUILDING_DOLPHIN_FOUNTAIN); break; + case BUILDING_FORT_LEGIONARIES: + total_active_count += building_count_fort_type_total(FIGURE_FORT_LEGIONARY); + break; + case BUILDING_FORT_JAVELIN: + total_active_count += building_count_fort_type_total(FIGURE_FORT_JAVELIN); + break; + case BUILDING_FORT_MOUNTED: + total_active_count += building_count_fort_type_total(FIGURE_FORT_MOUNTED); + break; default: total_active_count += building_count_active(type); break; @@ -205,6 +214,15 @@ int scenario_condition_type_building_count_any_met(const scenario_condition_t *c total_active_count += building_count_total(BUILDING_LARGE_POND); total_active_count += building_count_total(BUILDING_DOLPHIN_FOUNTAIN); break; + case BUILDING_FORT_LEGIONARIES: + total_active_count += building_count_fort_type_total(FIGURE_FORT_LEGIONARY); + break; + case BUILDING_FORT_JAVELIN: + total_active_count += building_count_fort_type_total(FIGURE_FORT_JAVELIN); + break; + case BUILDING_FORT_MOUNTED: + total_active_count += building_count_fort_type_total(FIGURE_FORT_MOUNTED); + break; default: total_active_count += building_count_total(type); break;