Skip to content

Commit

Permalink
fix: Building counts for specific fort types (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
UberWaffe authored Sep 21, 2023
1 parent eee1fc6 commit f4af4ee
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/building/count.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 15 additions & 0 deletions src/building/count.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "core/buffer.h"
#include "building/type.h"
#include "figure/type.h"
#include "game/resource.h"

/**
Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions src/scenario/condition_types/condition_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f4af4ee

Please sign in to comment.