Skip to content

Commit

Permalink
Assign artifact IDs for generated randarts
Browse files Browse the repository at this point in the history
May resolve #435 (previous behavior had all the randarts with an ID of zero at the exit of initialize_random_artifacts() so marking one created would mark all as created).  Also reduce the number of reallocations in initialize_random_artifacts() to be more efficient.
  • Loading branch information
backwardsEric authored and NickMcConnell committed Dec 20, 2024
1 parent e06b249 commit 73dc244
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/obj-design.c
Original file line number Diff line number Diff line change
Expand Up @@ -4051,23 +4051,26 @@ void initialize_random_artifacts(uint32_t randart_seed)
randart_seed);

/* Initialize, name and write artifacts to the file */
a_info = mem_realloc(a_info,
(z_info->a_max + ART_NUM_RANDOM) * sizeof(*a_info));
aup_info = mem_realloc(aup_info,
(z_info->a_max + ART_NUM_RANDOM) * sizeof(*aup_info));
for (i = 0; i < ART_NUM_RANDOM; i++) {
/* Extend the artifact array with a zero entry */
struct artifact *art;
a_info = mem_realloc(a_info, (z_info->a_max + 1) * sizeof(*art));
aup_info = mem_realloc(aup_info, (z_info->a_max + 1)
* sizeof(*aup_info));
art = &a_info[z_info->a_max];
memset(art, 0, sizeof(*art));
memset(&aup_info[z_info->a_max], 0, sizeof(*aup_info));
aup_info[z_info->a_max].aidx = z_info->a_max;
z_info->a_max += 1;

/* Design the artifact, storing information as we go along. */
design_random_artifact(art);
art->aidx = z_info->a_max;

/* Write the entry to the randart file */
write_randart_file_entry(randart_file, art);

z_info->a_max += 1;
}

/* Close the file */
Expand Down

0 comments on commit 73dc244

Please sign in to comment.