Skip to content

Commit

Permalink
Add a basic lua seed explorer
Browse files Browse the repository at this point in the history
This prints out information about vaults, monsters, and items so far; it
is packaged as a test that prints these for the first 5 seeds (replacing
a less interesting test), but is fairly configurable if you're willing
to edit the lua. To run it directly, you'll need to use util/fake_pty
(which may need to be built), e.g.:

    util/fake_pty ./crawl -test seed_explorer.lua

This also introduces a few lua support things that were missing that
might be of general interest, especially monster inventory (which is
easy now that all monster items are id'd).
  • Loading branch information
rawlins committed May 25, 2019
1 parent bc69b92 commit 0dde086
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 43 deletions.
15 changes: 14 additions & 1 deletion crawl-ref/source/dungeon.cc
Expand Up @@ -4726,6 +4726,8 @@ monster* dgn_place_monster(mons_spec &mspec, coord_def where,

if (!mspec.place.is_valid())
mspec.place = level_id::current();
bool chose_ood = false;
const int starting_depth = mspec.place.depth;

if (type == RANDOM_SUPER_OOD || type == RANDOM_MODERATE_OOD)
{
Expand Down Expand Up @@ -4763,7 +4765,12 @@ monster* dgn_place_monster(mons_spec &mspec, coord_def where,
if (mons_class_is_zombified(mspec.monbase))
type = pick_local_zombifiable_monster(mspec.place, mspec.monbase, coord_def());
else
type = pick_random_monster(mspec.place, mspec.monbase);
{
level_id place = mspec.place;
type = pick_random_monster(mspec.place, mspec.monbase, &place);
if (place.depth > starting_depth + 5)
chose_ood = true;
}
if (!type)
type = RANDOM_MONSTER;
}
Expand Down Expand Up @@ -4851,6 +4858,12 @@ monster* dgn_place_monster(mons_spec &mspec, coord_def where,
mons->props[CUSTOM_SPELLS_KEY] = true;
}

// this prop is mainly for the seed explorer.
// not a great or complete measure of monster danger: the builder can roll
// on the low side of the ood range, and vaults don't get this set.
if (chose_ood)
mons->props[MON_OOD_KEY].get_bool() = true;

if (!mspec.items.empty())
_dgn_give_mon_spec_items(mspec, mons, type);

Expand Down
19 changes: 19 additions & 0 deletions crawl-ref/source/l-mons.cc
Expand Up @@ -9,6 +9,7 @@
#include "cluautil.h"
#include "database.h"
#include "dlua.h"
#include "items.h"
#include "libutil.h"
#include "mon-act.h"
#include "mon-behv.h"
Expand Down Expand Up @@ -207,6 +208,23 @@ MDEF(muse)
return 0;
}

static int l_mons_get_inventory(lua_State *ls)
{
monster* mons = clua_get_lightuserdata<monster>(ls, lua_upvalueindex(1));
lua_newtable(ls);
int index = 0;
for (mon_inv_iterator ii(*mons); ii; ++ii)
{
if (ii->defined())
{
clua_push_item(ls, &*ii);
lua_rawseti(ls, -2, ++index);
}
}
return 1;
}
MDEFN(inventory, get_inventory)

static int l_mons_do_dismiss(lua_State *ls)
{
// dismiss is only callable from dlua, not from managed VMs (i.e.
Expand Down Expand Up @@ -521,6 +539,7 @@ static MonsAccessor mons_attrs[] =
{ "add_ench", l_mons_add_ench },
{ "del_ench", l_mons_del_ench },
{ "you_can_see", l_mons_you_can_see },
{ "get_inventory", l_mons_inventory },

{ "speak", l_mons_speak }
};
Expand Down
5 changes: 4 additions & 1 deletion crawl-ref/source/l-wiz.cc
Expand Up @@ -12,6 +12,7 @@ module "crawl"
#include "mon-util.h"
#include "stringutil.h"
#include "wiz-fsim.h"
#include "wiz-item.h"

#ifdef WIZARD

Expand Down Expand Up @@ -39,10 +40,12 @@ LUAFN(wiz_quick_fsim)
PLUARET(number, fdata.player.av_eff_dam);
}

LUAWRAP(wiz_identify_all_items, wizard_identify_all_items())

static const struct luaL_reg wiz_dlib[] =
{
{ "quick_fsim", wiz_quick_fsim },

{ "identify_all_items", wiz_identify_all_items},
{ nullptr, nullptr }
};

Expand Down
6 changes: 5 additions & 1 deletion crawl-ref/source/mon-place.cc
Expand Up @@ -264,7 +264,7 @@ static void _apply_ood(level_id &place)
if (fuzz)
{
place.depth += fuzz;
dprf(DIAG_MONPLACE, "Monster level fuzz: %d (old: %s, new: %s)",
dprf("Monster level fuzz: %d (old: %s, new: %s)",
fuzz, old_place.describe().c_str(), place.describe().c_str());
}
}
Expand Down Expand Up @@ -646,6 +646,7 @@ monster* place_monster(mgen_data mg, bool force_pos, bool dont_place)
mg.cls = resolve_monster_type(mg.cls, mg.base_type, mg.proximity,
&mg.pos, mg.map_mask,
&place, &want_band, allow_ood);
// TODO: it doesn't seem that this check can ever come out to be true??
bool chose_ood_monster = place.absdepth() > mg.place.absdepth() + 5;
if (want_band)
mg.flags |= MG_PERMIT_BANDS;
Expand Down Expand Up @@ -737,6 +738,9 @@ monster* place_monster(mgen_data mg, bool force_pos, bool dont_place)
if (mg.props.exists(MAP_KEY))
mon->set_originating_map(mg.props[MAP_KEY].get_string());

if (chose_ood_monster)
mon->props[MON_OOD_KEY].get_bool() = true;

if (mg.needs_patrol_point()
|| (mon->type == MONS_ALLIGATOR
&& !testbits(mon->flags, MF_BAND_MEMBER)))
Expand Down
2 changes: 2 additions & 0 deletions crawl-ref/source/mon-place.h
Expand Up @@ -124,6 +124,8 @@ void replace_boris();
// Active monster band may influence gear generation on band followers.
extern band_type active_monster_band;

#define MON_OOD_KEY "mons_is_ood"

#if TAG_MAJOR_VERSION == 34
#define VAULT_MON_TYPES_KEY "vault_mon_types"
#define VAULT_MON_BASES_KEY "vault_mon_bases"
Expand Down
40 changes: 0 additions & 40 deletions crawl-ref/source/test/d1_vaults.lua

This file was deleted.

0 comments on commit 0dde086

Please sign in to comment.