diff options
author | Pete Hurst <pete@streamuniverse.tv> | 2013-05-29 22:20:41 +0100 |
---|---|---|
committer | Pete Hurst <pete@streamuniverse.tv> | 2013-06-21 18:26:13 +0100 |
commit | caba246645aa69161dafcabe6111ec341383e54d (patch) | |
tree | 9f79344f0295a8b02cc5a7fa0b305309490db2cb /crawl-ref/source/mon-pick.cc | |
parent | 6f4e5b9996c5fd8ef5e1ef43ee8ec3fb40af18ef (diff) | |
download | crawl-ref-caba246645aa69161dafcabe6111ec341383e54d.tar.gz crawl-ref-caba246645aa69161dafcabe6111ec341383e54d.zip |
Allow mon-pick to be used with arbitrary pop_entry lists
The pick_monster_from function can now be called with a pop_entry
table and a depth to allow reuse of the mon-pick algorithm
in other situations (e.g. spawn lists for summoning effects).
Diffstat (limited to 'crawl-ref/source/mon-pick.cc')
-rw-r--r-- | crawl-ref/source/mon-pick.cc | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/crawl-ref/source/mon-pick.cc b/crawl-ref/source/mon-pick.cc index c681395d81..f2f51755de 100644 --- a/crawl-ref/source/mon-pick.cc +++ b/crawl-ref/source/mon-pick.cc @@ -14,25 +14,6 @@ #include "mon-util.h" #include "place.h" -enum distrib_type -{ - FLAT, // full chance throughout the range - SEMI, // 50% chance at range ends, 100% in the middle - PEAK, // 0% chance just outside range ends, 100% in the middle, range - // ends typically get ~20% or more - UP, // linearly from near-zero to 100%, increasing with depth - DOWN, // linearly from 100% at the start to near-zero -}; - -typedef struct -{ - int minr; - int maxr; - int rarity; // 0..1000 - distrib_type distrib; - monster_type mons; -} pop_entry; - #include "mon-pick-data.h" int branch_ood_cap(branch_type branch) @@ -148,20 +129,25 @@ static int _rarity_at(const pop_entry *pop, int depth) monster_type pick_monster(level_id place, mon_pick_vetoer veto) { + ASSERT(place.is_valid()); + return pick_monster_from(population[place.branch].pop, place.depth, veto); +} + +monster_type pick_monster_from(const pop_entry *fpop, int depth, mon_pick_vetoer veto) +{ struct { monster_type mons; int rarity; } valid[NUM_MONSTERS]; int nvalid = 0; int totalrar = 0; - ASSERT(place.is_valid()); - for (const pop_entry *pop = population[place.branch].pop; pop->mons; pop++) + for (const pop_entry *pop = fpop; pop->mons; pop++) { - if (place.depth < pop->minr || place.depth > pop->maxr) + if (depth < pop->minr || depth > pop->maxr) continue; if (veto && (*veto)(pop->mons)) continue; - int rar = _rarity_at(pop, place.depth); + int rar = _rarity_at(pop, depth); ASSERT(rar > 0); valid[nvalid].mons = pop->mons; |