Allow defining an ID for a joker to always appear in shop and be tested

This commit is contained in:
MeirGavish
2025-10-13 20:58:44 +03:00
parent 4b35b2f7d8
commit 8c25089966
3 changed files with 39 additions and 4 deletions
+17 -4
View File
@@ -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));
+20
View File
@@ -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);
}