Allow defining an ID for a joker to always appear in shop and be tested
This commit is contained in:
@@ -17,9 +17,11 @@ bool list_remove_by_idx(List *list, int index);
|
|||||||
void* list_get(List *list, int index);
|
void* list_get(List *list, int index);
|
||||||
int list_get_size(List *list);
|
int list_get_size(List *list);
|
||||||
bool list_remove_by_value(List *list, void *value);
|
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);
|
bool int_list_append(List *list, intptr_t value);
|
||||||
intptr_t int_list_get(List *list, int index);
|
intptr_t int_list_get(List *list, int index);
|
||||||
bool int_list_remove_by_value(List *list, intptr_t value);
|
bool int_list_remove_by_value(List *list, intptr_t value);
|
||||||
|
bool int_list_exists(List *list, intptr_t value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+15
-2
@@ -2307,10 +2307,23 @@ static void game_shop_create_items()
|
|||||||
|
|
||||||
for (int i = 0; i < MAX_SHOP_JOKERS; i++)
|
for (int i = 0; i < MAX_SHOP_JOKERS; i++)
|
||||||
{
|
{
|
||||||
|
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
|
// 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);
|
list_remove_by_idx(jokers_available_to_shop, joker_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JokerObject *joker_object = joker_object_new(joker_new(joker_id));
|
JokerObject *joker_object = joker_object_new(joker_new(joker_id));
|
||||||
|
|
||||||
|
|||||||
@@ -99,3 +99,23 @@ int list_get_size(List *list)
|
|||||||
}
|
}
|
||||||
return list->size;
|
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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user