Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeply copy blows for player ghost #421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/mon-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,12 @@ static void cleanup_monster(void)
mem_free(r->blow);
}

/*
* Melee blows for the ghost race have to be freed. The rest of it
* is a shallow copy of one of the other races.
*/
mem_free(r_info[z_info->r_max - 1].blow);

mem_free(r_info);
}

Expand Down
14 changes: 13 additions & 1 deletion src/mon-make.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ bool prepare_ghost(struct chunk *c, int r_idx, struct monster *mon,
{
int ghost_race, ghost_class = 0;
uint8_t try, i;
uint16_t iblow;

struct monster_race *race = &r_info[r_idx];
struct monster_lore *lore = get_lore(race);
Expand Down Expand Up @@ -739,8 +740,18 @@ bool prepare_ghost(struct chunk *c, int r_idx, struct monster *mon,
c->ghost->race = r_idx;

/* Copy the info from the template to the special "ghost slot", and use
* that from here on */
* that from here on. Melee blows have to be deeply copied so those of
* the base race are not modified. */
mem_free(r_info[PLAYER_GHOST_RACE].blow);
memcpy(&r_info[PLAYER_GHOST_RACE], race, sizeof(*race));
r_info[PLAYER_GHOST_RACE].blow = mem_alloc(z_info->mon_blows_max
* sizeof(*r_info[PLAYER_GHOST_RACE].blow));
for (iblow = 0; iblow < z_info->mon_blows_max; ++iblow) {
r_info[PLAYER_GHOST_RACE].blow[iblow] = race->blow[iblow];
r_info[PLAYER_GHOST_RACE].blow[iblow].next =
(iblow < z_info->mon_blows_max - 1) ?
r_info[PLAYER_GHOST_RACE].blow + iblow + 1 : NULL;
}
race = &r_info[PLAYER_GHOST_RACE];
mon->race = race;

Expand Down Expand Up @@ -1229,6 +1240,7 @@ void wipe_mon_list(struct chunk *c, struct player *p)
}

/* Delete the player ghost record completely */
mem_free(r_info[PLAYER_GHOST_RACE].blow);
memset(&r_info[PLAYER_GHOST_RACE], 0, sizeof(struct monster_race));

/* Delete all the monster groups */
Expand Down