static void treasure_type_by_letter_A_test(void) { struct treasure_type *treasure_type = treasure_type_by_letter('A'); assert(NULL != treasure_type); char *name = treasure_type_alloc_name(treasure_type); assert(str_eq("A", name)); free_or_die(name); char *description = treasure_type_alloc_description(treasure_type, false); char const *expected = " A | 1-6:25% | 1-6:30% | 1-6:35% | 1-10:40% | 1-4:25% | 4-40:60% | 3-30:50% | any 3: 30%\n"; assert(str_eq(expected, description)); free_or_die(description); description = treasure_type_alloc_description(treasure_type, true); expected = " | 1,000's | 1,000's | 1,000's | 1,000's | 100's | | | Maps \n" "Treasure | of | of | of | of | of | | | or \n" " Type | Copper | Silver | Electrum | Gold | Platinum | Gems | Jewelry | Magic \n" "----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------\n" " A | 1-6:25% | 1-6:30% | 1-6:35% | 1-10:40% | 1-4:25% | 4-40:60% | 3-30:50% | any 3: 30%\n"; assert(str_eq(expected, description)); free_or_die(description); }
static void generate_treasure_type(struct rnd *rnd, FILE *out, char letter) { struct treasure treasure; int individual_count; fprintf(out, "Treasure type %c: ", letter); if (letter >= 'J' && letter <= 'N') { individual_count = roll("1d10", rnd); } else { individual_count = 0; } treasure_initialize(&treasure); treasure_type_generate(treasure_type_by_letter(letter), rnd, individual_count, &treasure); char *description = treasure_alloc_description(&treasure); int value_cp = treasure_value_in_cp(&treasure); char *value_gp = coins_alloc_gp_cp_description(value_cp); fprintf(out, "%s (total %s)\n", description, value_gp); free_or_die(value_gp); free_or_die(description); enumerate_treasure_items(&treasure, out); treasure_finalize(&treasure); }
static void generate_treasure_type_table(FILE *out) { for (char letter = 'A'; letter <= 'Z'; ++letter) { struct treasure_type *treasureType = treasure_type_by_letter(letter); char *description = treasure_type_alloc_description(treasureType, letter == 'A'); fprintf(out, "%s", description); free_or_die(description); } }
static void treasure_create_json_object_for_type_A_test(void) { struct rnd *rnd = rnd_alloc_fake_min(); struct treasure treasure; treasure_initialize(&treasure); struct treasure_type *treasure_type = treasure_type_by_letter('A'); treasure_type_generate(treasure_type, rnd, &treasure); struct cJSON *json_object = treasure_create_json_object(&treasure); assert(cJSON_IsObject(json_object)); char *json_string = cJSON_PrintUnformatted(json_object); char const *expected = "{" "\"struct\":\"treasure\"," "\"rev\":0," "\"type\":\"A\"," "\"coins\":{" "\"struct\":\"coins\"," "\"rev\":0," "\"pp\":100," "\"gp\":1000," "\"ep\":1000," "\"sp\":1000," "\"cp\":1000" "}," "\"gems\":[" "{\"struct\":\"gem\",\"rev\":0,\"size\":\"very small\",\"type\":\"ornamental\",\"kind\":\"azurite\",\"colors\":\"mottled deep blue\",\"value_percent_modifier\":0,\"value_rank_modifier\":7}," "{\"struct\":\"gem\",\"rev\":0,\"size\":\"very small\",\"type\":\"ornamental\",\"kind\":\"azurite\",\"colors\":\"mottled deep blue\",\"value_percent_modifier\":0,\"value_rank_modifier\":7}," "{\"struct\":\"gem\",\"rev\":0,\"size\":\"very small\",\"type\":\"ornamental\",\"kind\":\"azurite\",\"colors\":\"mottled deep blue\",\"value_percent_modifier\":0,\"value_rank_modifier\":7}," "{\"struct\":\"gem\",\"rev\":0,\"size\":\"very small\",\"type\":\"ornamental\",\"kind\":\"azurite\",\"colors\":\"mottled deep blue\",\"value_percent_modifier\":0,\"value_rank_modifier\":7}" "]," "\"jewelry\":[" "{\"struct\":\"jewelry\",\"rev\":0,\"has_gems\":false,\"form\":\"anklet\",\"material\":\"ivory\",\"workmanship_bonus\":12,\"exceptional_stone_bonus\":0,\"value_in_cp\":400000}," "{\"struct\":\"jewelry\",\"rev\":0,\"has_gems\":false,\"form\":\"anklet\",\"material\":\"ivory\",\"workmanship_bonus\":12,\"exceptional_stone_bonus\":0,\"value_in_cp\":400000}," "{\"struct\":\"jewelry\",\"rev\":0,\"has_gems\":false,\"form\":\"anklet\",\"material\":\"ivory\",\"workmanship_bonus\":12,\"exceptional_stone_bonus\":0,\"value_in_cp\":400000}" "]," "\"maps\":[" "{\"struct\":\"treasure_map\",\"rev\":0,\"is_false\":true,\"treasure\":{\"struct\":\"treasure\",\"rev\":0,\"type\":null,\"coins\":{\"struct\":\"coins\",\"rev\":0,\"pp\":0,\"gp\":0,\"ep\":0,\"sp\":0,\"cp\":0},\"gems\":[],\"jewelry\":[],\"maps\":[],\"magic_items\":[]},\"true_description\":\"false map to treasure of (no treasure) in nearby labyrinth to the north\"}," "{\"struct\":\"treasure_map\",\"rev\":0,\"is_false\":true,\"treasure\":{\"struct\":\"treasure\",\"rev\":0,\"type\":null,\"coins\":{\"struct\":\"coins\",\"rev\":0,\"pp\":0,\"gp\":0,\"ep\":0,\"sp\":0,\"cp\":0},\"gems\":[],\"jewelry\":[],\"maps\":[],\"magic_items\":[]},\"true_description\":\"false map to treasure of (no treasure) in nearby labyrinth to the north\"}," "{\"struct\":\"treasure_map\",\"rev\":0,\"is_false\":true,\"treasure\":{\"struct\":\"treasure\",\"rev\":0,\"type\":null,\"coins\":{\"struct\":\"coins\",\"rev\":0,\"pp\":0,\"gp\":0,\"ep\":0,\"sp\":0,\"cp\":0},\"gems\":[],\"jewelry\":[],\"maps\":[],\"magic_items\":[]},\"true_description\":\"false map to treasure of (no treasure) in nearby labyrinth to the north\"}" "]," "\"magic_items\":[]" "}"; assert(str_eq(expected, json_string)); free(json_string); cJSON_Delete(json_object); treasure_finalize(&treasure); rnd_free(rnd); }
static void treasure_type_generate_for_A_with_fake_fixed_test(void) { struct rnd *rnd = rnd_alloc_fake_fixed(25); struct treasure treasure; treasure_initialize(&treasure); struct treasure_type *treasure_type = treasure_type_by_letter('A'); treasure_type_generate(treasure_type, rnd, &treasure); assert(0 == treasure.coins.cp); assert(2000 == treasure.coins.sp); assert(2000 == treasure.coins.ep); assert(6000 == treasure.coins.gp); assert(0 == treasure.coins.pp); assert(24 == treasure.gems_count); assert(18 == treasure.jewelry_count); assert(3 == treasure.magic_items_count); assert(0 == treasure.maps_count); treasure_finalize(&treasure); rnd_free(rnd); }