From c5f8606a36bad92d01f0672ccdf7b647e4ddde02 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 10 Jan 2010 13:50:07 -0600 Subject: better plant clumping algorithm --- crawl-ref/source/dungeon.cc | 62 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) (limited to 'crawl-ref/source/dungeon.cc') diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index 09949dca20..168cb760d0 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -7792,21 +7792,65 @@ static void _add_plant_clumps() { for (rectangle_iterator ri(1); ri; ++ri) { - if (grd(*ri) != DNGN_FLOOR || !one_chance_in(500)) + mgen_data mg; + if (mgrd(*ri) != NON_MONSTER) { + /* clump plants around things that already exist */ + monster_type type = menv[mgrd(*ri)].type; + if ((type == MONS_PLANT || type == MONS_FUNGUS) && + one_chance_in(10)) { + mg.cls = type; + } + else { + continue; + } + } + else { continue; } - mgen_data mg; - mg.cls = coinflip() ? MONS_PLANT : MONS_FUNGUS; - mg.pos = *ri; - mons_place(mgen_data(mg)); - for (adjacent_iterator ai(*ri); ai; ++ai) + + std::vector to_place; + to_place.push_back(*ri); + for (int i = 1; i < 4; ++i) + { + for (radius_iterator rad(*ri, i, C_SQUARE); rad; ++rad) + { + if (grd(*rad) != DNGN_FLOOR) + { + continue; + } + + /* make sure the iterator stays valid */ + to_place.reserve((2 * i + 1) * (2 * i + 1)); + for (std::vector::const_iterator it = to_place.begin(); + it != to_place.end(); + ++it) + { + if (*rad == *it) + { + continue; + } + /* only place plants next to previously placed plants */ + if (abs(rad->x - it->x) <= 1 && abs(rad->y - it->y) <= 1) + { + if (one_chance_in(12)) { + to_place.push_back(*rad); + } + } + } + } + } + + for (std::vector::const_iterator it = to_place.begin(); + it != to_place.end(); + ++it) { - if (grd(*ai) == DNGN_FLOOR && coinflip()) + if (*it == *ri) { - mg.pos = *ai; - mons_place(mgen_data(mg)); + continue; } + mg.pos = *it; + mons_place(mgen_data(mg)); } } } -- cgit v1.2.3-54-g00ecf