diff --git a/include/list.h b/include/list.h index fd1c366..42ff1cd 100644 --- a/include/list.h +++ b/include/list.h @@ -17,9 +17,11 @@ bool list_remove_by_idx(List *list, int index); void* list_get(List *list, int index); int list_get_size(List *list); bool list_remove_by_value(List *list, void *value); +bool list_exists(List *list, void *value); bool int_list_append(List *list, intptr_t value); intptr_t int_list_get(List *list, int index); bool int_list_remove_by_value(List *list, intptr_t value); +bool int_list_exists(List *list, intptr_t value); #endif diff --git a/source/game.c b/source/game.c index 49a6604..e41b1d6 100644 --- a/source/game.c +++ b/source/game.c @@ -2307,10 +2307,23 @@ static void game_shop_create_items() for (int i = 0; i < MAX_SHOP_JOKERS; i++) { - // TODO: weight the random choice by joker rarity - int joker_idx = random() % list_get_size(jokers_available_to_shop); - intptr_t joker_id = int_list_get(jokers_available_to_shop, joker_idx); - list_remove_by_idx(jokers_available_to_shop, joker_idx); + int joker_idx = 0; + intptr_t joker_id = 0; + #ifdef TEST_JOKER_ID // Allow defining an ID for a joker to always appear in shop and be tested + if (int_list_exists(jokers_available_to_shop, TEST_JOKER_ID)) + { + joker_id = TEST_JOKER_ID; + int_list_remove_by_value(jokers_available_to_shop, joker_id); + } + else + #endif + { + joker_idx = random() % list_get_size(jokers_available_to_shop); + joker_id = int_list_get(jokers_available_to_shop, joker_idx); + // TODO: weight the random choice by joker rarity + list_remove_by_idx(jokers_available_to_shop, joker_idx); + } + JokerObject *joker_object = joker_object_new(joker_new(joker_id)); diff --git a/source/list.c b/source/list.c index c57324a..cf66125 100644 --- a/source/list.c +++ b/source/list.c @@ -99,3 +99,23 @@ int list_get_size(List *list) } return list->size; } + +bool list_exists(List *list, void *value) +{ + if (list == NULL) return false; + + for (int i = 0; i < list->size; i++) + { + if (list->_array[i] == value) + { + return true; + } + } + + return false; +} + +bool int_list_exists(List *list, intptr_t value) +{ + return list_exists(list, (void*)value); +} \ No newline at end of file