Skip to content
26 changes: 25 additions & 1 deletion src/include/nle.h
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,11 @@ void nle_end(nle_ctx_t *);
void nle_set_seed(nle_ctx_t *, unsigned long, unsigned long, boolean);
void nle_get_seed(nle_ctx_t *, unsigned long *, unsigned long *, boolean *);

/* Debug: dump the per-env arena memory map (named buffers + fmon/fobj chains +
* monster grid with fmon-membership/data-validity) to `path` (NULL => stderr).
* Diagnostic for arena-reuse / dangling-pointer investigations. */
void nle_dbg_memmap(nle_ctx_t *, const char *);

/* Single-level blob save/load.
*
* nle_save_level serializes the current dungeon level to a malloc'd byte
Expand Down Expand Up @@ -1210,7 +1215,9 @@ int nle_load_player(nle_ctx_t *, const void *blob, long len);
/* Secure state-modification API.
*
* nle_set_state pokes a curated whitelist of simple integer player fields.
* "field" is one of: "hp", "max_hp", "gold", "xp_level", "hunger".
* "field" is one of: "hp", "max_hp", "gold", "xp_level", "hunger", or one of
* the six attributes "str"/"dex"/"con"/"int"/"wis"/"cha" (value is NetHack's
* encoded attribute: 3..18, 19..118 == 18/01..18/00, 119..125 == 19..25).
* Returns 0 on success, nonzero for an unknown field. The C side only
* provides the setters; the binding is responsible for validating bounds.
*
Expand All @@ -1234,6 +1241,23 @@ int nle_goto_depth(nle_ctx_t *, int n);
int nle_seat_on_stair(nle_ctx_t *, int down);
int nle_level_up(nle_ctx_t *, int n);

/* Curriculum traversal: cross-branch goto + dungeon-table query.
*
* nle_num_dungeons returns the number of dungeon branches defined.
* nle_dungeon_info reports branch `idx`'s name / depth_start / num_dunlevs
* (any out pointer may be NULL); lets the caller map an absolute "Dlvl N" to
* a (dnum, dlevel) and find Gehennom / the Elemental Planes by name.
* nle_goto_abs schedules a DEFERRED move to an arbitrary (dnum, dlevel),
* including a different branch than the hero's current one (unlike
* nle_goto_depth, which pins the branch). Two-phase: goto_level() runs via
* deferred_goto() on the next nle_step() and generates the level on demand.
* Reaching the Elemental Planes grants the Amulet (the goto_level gate). All
* return 0 on success, nonzero on a bad index / out-of-range target. */
int nle_num_dungeons(nle_ctx_t *);
int nle_dungeon_info(nle_ctx_t *, int idx, char *name_out, int name_cap,
int *depth_start_out, int *num_dunlevs_out);
int nle_goto_abs(nle_ctx_t *, int dnum, int dlevel);

/* nle_state refactor — per-instance accessors. Called from rnd.c (and
* other subsystems as they migrate). Each returns a pointer into the
* current nle_ctx_t. CORE = 0 (gameplay RNG), DISP = 1 (display RNG). */
Expand Down
8 changes: 8 additions & 0 deletions src/include/nleobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ typedef struct nle_settings {
int tune_n;
int tune_idx[NLE_TUNE_MAX];
double tune_val[NLE_TUNE_MAX];
/* Optional read-only data directory holding the shared, immutable game
* data (the DLB `nhdat`, data/oracles/rumors, config, …). When non-empty,
* the read-only file prefixes (DATA/HACK/SYSCONF/CONFIG) resolve here while
* the writable prefixes (LEVEL/SAVE/BONES/SCORE/LOCK/TROUBLE) stay under
* `hackdir`. This lets many envs share one data dir read-only and keep only
* a tiny per-env writable `hackdir`, instead of each copying the ~3.7MB dat
* tree. Empty => every prefix resolves under `hackdir` (legacy behavior). */
char datadir[256];
} nle_settings;

#endif /* NLEOBS_H */
2 changes: 1 addition & 1 deletion src/src/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ nle_apply(void)
if (!current_nle_ctx) return NULL;
struct nle_apply_state *s = (struct nle_apply_state *) current_nle_ctx->s_apply_state;
if (!s) {
s = (struct nle_apply_state *) calloc(1, sizeof(struct nle_apply_state));
s = (struct nle_apply_state *) nle_arena_calloc(1, sizeof(struct nle_apply_state));
current_nle_ctx->s_apply_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/botl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ nle_botl(void)
if (!current_nle_ctx) return NULL;
struct nle_botl_state *s = (struct nle_botl_state *) current_nle_ctx->s_botl_state;
if (!s) {
s = (struct nle_botl_state *) calloc(1, sizeof(struct nle_botl_state));
s = (struct nle_botl_state *) nle_arena_calloc(1, sizeof(struct nle_botl_state));
current_nle_ctx->s_botl_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ nle_cmd(void)
if (!current_nle_ctx) return NULL;
struct nle_cmd_state *s = (struct nle_cmd_state *) current_nle_ctx->s_cmd_state;
if (!s) {
s = (struct nle_cmd_state *) calloc(1, sizeof(struct nle_cmd_state));
s = (struct nle_cmd_state *) nle_arena_calloc(1, sizeof(struct nle_cmd_state));
current_nle_ctx->s_cmd_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ nle_display(void)
if (!current_nle_ctx) return NULL;
struct nle_display_state *s = (struct nle_display_state *) current_nle_ctx->s_display_state;
if (!s) {
s = (struct nle_display_state *) calloc(1, sizeof(struct nle_display_state));
s = (struct nle_display_state *) nle_arena_calloc(1, sizeof(struct nle_display_state));
current_nle_ctx->s_display_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/do_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ nle_do_name(void)
if (!current_nle_ctx) return NULL;
struct nle_do_name_state *s = (struct nle_do_name_state *) current_nle_ctx->s_do_name_state;
if (!s) {
s = (struct nle_do_name_state *) calloc(1, sizeof(struct nle_do_name_state));
s = (struct nle_do_name_state *) nle_arena_calloc(1, sizeof(struct nle_do_name_state));
current_nle_ctx->s_do_name_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/do_wear.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ nle_do_wear(void)
if (!current_nle_ctx) return NULL;
struct nle_do_wear_state *s = (struct nle_do_wear_state *) current_nle_ctx->s_do_wear_state;
if (!s) {
s = (struct nle_do_wear_state *) calloc(1, sizeof(struct nle_do_wear_state));
s = (struct nle_do_wear_state *) nle_arena_calloc(1, sizeof(struct nle_do_wear_state));
current_nle_ctx->s_do_wear_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/dokick.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ nle_dokick(void)
if (!current_nle_ctx) return NULL;
struct nle_dokick_state *s = (struct nle_dokick_state *) current_nle_ctx->s_dokick_state;
if (!s) {
s = (struct nle_dokick_state *) calloc(1, sizeof(struct nle_dokick_state));
s = (struct nle_dokick_state *) nle_arena_calloc(1, sizeof(struct nle_dokick_state));
current_nle_ctx->s_dokick_state = s;
}
return s;
Expand Down
2 changes: 1 addition & 1 deletion src/src/end.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static struct nle_end_state *nle_end_st(void) {
if (!current_nle_ctx) return NULL;
struct nle_end_state *s = (struct nle_end_state *) current_nle_ctx->s_end_state;
if (!s) {
s = (struct nle_end_state *) calloc(1, sizeof(struct nle_end_state));
s = (struct nle_end_state *) nle_arena_calloc(1, sizeof(struct nle_end_state));
current_nle_ctx->s_end_state = s;
}
if (!s->_valuables_inited) {
Expand Down
2 changes: 1 addition & 1 deletion src/src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ nle_files(void)
if (!current_nle_ctx) return NULL;
struct nle_files_state *s = (struct nle_files_state *) current_nle_ctx->s_files_state;
if (!s) {
s = (struct nle_files_state *) calloc(1, sizeof(struct nle_files_state));
s = (struct nle_files_state *) nle_arena_calloc(1, sizeof(struct nle_files_state));
s->_lockfd = -1; /* non-zero default */
current_nle_ctx->s_files_state = s;
}
Expand Down
Loading