diff options
author | Shmuale Mark <shm.mark@gmail.com> | 2014-05-05 23:30:12 -0400 |
---|---|---|
committer | Shmuale Mark <shm.mark@gmail.com> | 2014-05-05 23:30:12 -0400 |
commit | 339c82ad633d84ce6da69f1a841c9da7ca9cb90d (patch) | |
tree | 859c48b4e6a125da7929dfd5c7d117f843565dec /crawl-ref/source/mon-grow.cc | |
parent | 533d93433149189156afea26f63e14bba40a7734 (diff) | |
download | crawl-ref-339c82ad633d84ce6da69f1a841c9da7ca9cb90d.tar.gz crawl-ref-339c82ad633d84ce6da69f1a841c9da7ca9cb90d.zip |
Fix a memory leak (greensnark).
This might also be a better place to put the code, anyway, even
though there's a bit of duplication.
Partially reverts 8b0589b2b84b012d14d5e95f6c54ddbcd71c88db.
Diffstat (limited to 'crawl-ref/source/mon-grow.cc')
-rw-r--r-- | crawl-ref/source/mon-grow.cc | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/crawl-ref/source/mon-grow.cc b/crawl-ref/source/mon-grow.cc index 0a3ae59e7a..6d446a963a 100644 --- a/crawl-ref/source/mon-grow.cc +++ b/crawl-ref/source/mon-grow.cc @@ -26,7 +26,7 @@ const mons_experience_levels mexplevs; // No special cases are in place: make sure source and target forms are similar. // If the target form requires special handling of some sort, add the handling // to level_up_change(). -// + static const monster_level_up mon_grow[] = { monster_level_up(MONS_ORC, MONS_ORC_WARRIOR), @@ -97,19 +97,14 @@ static const monster_level_up *_monster_level_up_target(monster_type type, { for (unsigned i = 0; i < ARRAYSZ(mon_grow); ++i) { - const monster_level_up *mlup = &mon_grow[i]; - // XXX: A hack to let draconians level up wihout specifying every - // single possible combination. - bool upgrade_drac = mons_is_base_draconian(type); - if (mlup->before == type || upgrade_drac) + const monster_level_up &mlup(mon_grow[i]); + if (mlup.before == type) { - if (upgrade_drac) - mlup = new monster_level_up(type, resolve_monster_type(RANDOM_NONBASE_DRACONIAN, type)); - const monsterentry *me = get_monster_data(mlup->after); + const monsterentry *me = get_monster_data(mlup.after); if (static_cast<int>(me->hpdice[0]) == hit_dice - && x_chance_in_y(mlup->chance, 1000)) + && x_chance_in_y(mlup.chance, 1000)) { - return mlup; + return &mlup; } } } @@ -119,9 +114,6 @@ static const monster_level_up *_monster_level_up_target(monster_type type, void monster::upgrade_type(monster_type after, bool adjust_hd, bool adjust_hp) { - // Needed for draconians growing into non-base ones. - base_monster = type; - const monsterentry *orig = get_monster_data(type); // Ta-da! type = after; @@ -173,6 +165,13 @@ bool monster::level_up_change() upgrade_type(lup->after, false, lup->adjust_hp); return true; } + else if (mons_is_base_draconian(type)) + { + base_monster = type; + monster_type upgrade = resolve_monster_type(RANDOM_NONBASE_DRACONIAN, type); + if (static_cast<int>(get_monster_data(upgrade)->hpdice[0]) == hit_dice) + upgrade_type(upgrade, false, true); + } return false; } |