diff --git a/src/thing_list.c b/src/thing_list.c index eb60bb382..1342ba4f9 100644 --- a/src/thing_list.c +++ b/src/thing_list.c @@ -2037,11 +2037,35 @@ long do_to_players_all_creatures_of_model(PlayerNumber plyr_idx, int crmodel, Th * * @return Count of players creatures. */ -long count_player_creatures_of_model(PlayerNumber plyr_idx, ThingModel crmodel) +long count_player_creatures_of_model(PlayerNumber plyr_idx, int crmodel) { struct Dungeon *dungeon; + Thing_Maximizer_Filter filter; + struct CompoundTngFilterParam param; + SYNCDBG(19,"Starting"); dungeon = get_players_num_dungeon(plyr_idx); - return count_player_list_creatures_of_model(dungeon->creatr_list_start, crmodel); + filter = anywhere_thing_filter_is_of_class_and_model_and_owned_by; + param.class_id = TCls_Creature; + param.model_id = (crmodel<=0) ? -1 : crmodel; + param.plyr_idx = plyr_idx; + param.num1 = -1; + param.num2 = -1; + param.num3 = -1; + if (dungeon_invalid(dungeon)) { + // Invalid dungeon - use list of creatures not associated to any dungeon + return count_player_list_creatures_with_filter(game.nodungeon_creatr_list_start, filter, ¶m); + } + ThingModel spdig_model; + spdig_model = get_players_special_digger_model(plyr_idx); + long count; + count = 0; + if (((crmodel > 0) && (crmodel != spdig_model)) || (crmodel == -1) || (crmodel == -2)) { + count += count_player_list_creatures_with_filter(dungeon->creatr_list_start, filter, ¶m); + } + if (((crmodel > 0) && (crmodel == spdig_model)) || (crmodel == -1) || (crmodel == -3)) { + count += count_player_list_creatures_with_filter(dungeon->digger_list_start, filter, ¶m); + } + return count; } long count_player_list_creatures_of_model(long thing_idx, ThingModel crmodel) @@ -2259,6 +2283,10 @@ long count_player_list_creatures_of_model_matching_bool_filter(PlayerNumber plyr param.num1 = -1; param.num2 = -1; param.ptr3 = (void *)matcher_cb; + if (dungeon_invalid(dungeon)) { + // Invalid dungeon - use list of creatures not associated to any dungeon + return count_player_list_creatures_with_filter(game.nodungeon_creatr_list_start, filter, ¶m); + } ThingModel spdig_model; spdig_model = get_players_special_digger_model(plyr_idx); long count; diff --git a/src/thing_list.h b/src/thing_list.h index 4129d5109..b982150c7 100644 --- a/src/thing_list.h +++ b/src/thing_list.h @@ -276,7 +276,7 @@ void init_all_creature_states(void); TbBool perform_action_on_all_creatures_in_group(struct Thing *thing, Thing_Bool_Modifier action); long creature_of_model_in_prison_or_tortured(ThingModel crmodel); -long count_player_creatures_of_model(PlayerNumber plyr_idx, ThingModel crmodel); +long count_player_creatures_of_model(PlayerNumber plyr_idx, int crmodel); long count_player_list_creatures_of_model(long thing_idx, ThingModel crmodel); GoldAmount compute_player_payday_total(const struct Dungeon *dungeon); TbBool lord_of_the_land_in_prison_or_tortured(void);