Merge branch 'NetHack-3.7'

This commit is contained in:
nhmall
2019-11-15 22:13:00 -05:00
10 changed files with 249 additions and 113 deletions

2
src/decl.c Normal file → Executable file
View File

@@ -108,6 +108,8 @@ const char *materialnm[] = { "mysterious", "liquid", "wax", "organic",
"platinum", "mithril", "plastic", "glass",
"gemstone", "stone" };
char emptystr[] = {0}; /* non-const */
/* Global windowing data, defined here for multi-window-system support */
NEARDATA winid WIN_MESSAGE, WIN_STATUS, WIN_MAP, WIN_INVEN;
#ifdef WIN32

42
src/dungeon.c Normal file → Executable file
View File

@@ -35,7 +35,9 @@ struct lchoice {
char menuletter;
};
#if 0
static void FDECL(Fread, (genericptr_t, int, int, dlb *));
#endif
static xchar FDECL(dname_to_dnum, (const char *));
static int FDECL(find_branch, (const char *, struct proto_dungeon *));
static xchar FDECL(parent_dnum, (const char *, struct proto_dungeon *));
@@ -293,6 +295,7 @@ NHFILE *nhfp;
}
}
#if 0
static void
Fread(ptr, size, nitems, stream)
genericptr_t ptr;
@@ -308,6 +311,7 @@ dlb *stream;
nh_terminate(EXIT_FAILURE);
}
}
#endif
static xchar
dname_to_dnum(s)
@@ -776,7 +780,7 @@ lua_State *L;
if (lua_type(L, -1) == LUA_TTABLE) {
int f, nflags;
lua_len(L, -1);
nflags = lua_tointeger(L, -1);
nflags = LUA_INTCAST(lua_tointeger(L, -1));
lua_pop(L, 1);
for (f = 0; f < nflags; f++) {
lua_pushinteger(L, f+1);
@@ -807,7 +811,9 @@ init_dungeons()
register s_level *x;
struct proto_dungeon pd;
struct level_map *lev_map;
int tidx;
nhUse(cb);
(void) memset(&pd, 0, sizeof(struct proto_dungeon));
pd.n_levs = pd.n_brs = 0;
@@ -850,7 +856,7 @@ init_dungeons()
panic("dungeon is not a lua table");
lua_len(L, -1);
g.n_dgns = lua_tointeger(L, -1);
g.n_dgns = LUA_INTCAST(lua_tointeger(L, -1));
lua_pop(L, 1);
pd.start = 0;
@@ -865,23 +871,26 @@ init_dungeons()
if (g.n_dgns >= MAXDUNGEON)
panic("init_dungeons: too many dungeons");
int tidx = lua_gettop(L);
tidx = lua_gettop(L);
lua_pushnil(L); /* first key */
i = 0;
while (lua_next(L, tidx) != 0) {
char *dgn_name, *dgn_bonetag, *dgn_protoname;
int dgn_base, dgn_range, dgn_align, dgn_entry, dgn_chance, dgn_flags;
if (!lua_istable(L, -1))
panic("dungeon[%i] is not a lua table", i);
char *dgn_name = get_table_str(L, "name");
char *dgn_bonetag = get_table_str_opt(L, "bonetag", ""); /* TODO: single char or "none" */
char *dgn_protoname = get_table_str_opt(L, "protofile", "");
int dgn_base = get_table_int(L, "base");
int dgn_range = get_table_int_opt(L, "range", 0);
int dgn_align = dgnaligns2i[get_table_option(L, "alignment", "unaligned", dgnaligns)];
int dgn_entry = get_table_int_opt(L, "entry", 0);
int dgn_chance = get_table_int_opt(L, "chance", 100);
int dgn_flags = get_dgn_flags(L);
dgn_name = get_table_str(L, "name");
dgn_bonetag = get_table_str_opt(L, "bonetag", emptystr); /* TODO: single char or "none" */
dgn_protoname = get_table_str_opt(L, "protofile", emptystr);
dgn_base = get_table_int(L, "base");
dgn_range = get_table_int_opt(L, "range", 0);
dgn_align = dgnaligns2i[get_table_option(L, "alignment", "unaligned", dgnaligns)];
dgn_entry = get_table_int_opt(L, "entry", 0);
dgn_chance = get_table_int_opt(L, "chance", 100);
dgn_flags = get_dgn_flags(L);
debugpline4("DUNGEON[%i]: %s, base=(%i,%i)", i, dgn_name, dgn_base, dgn_range);
@@ -897,7 +906,7 @@ init_dungeons()
if (lua_type(L, -1) == LUA_TTABLE) {
int f, nlevels;
lua_len(L, -1);
nlevels = lua_tointeger(L, -1);
nlevels = LUA_INTCAST(lua_tointeger(L, -1));
pd.tmpdungeon[i].levels = nlevels;
lua_pop(L, 1);
for (f = 0; f < nlevels; f++) {
@@ -906,7 +915,7 @@ init_dungeons()
if (lua_type(L, -1) == LUA_TTABLE) {
int bi;
char *lvl_name = get_table_str(L, "name");
char *lvl_bonetag = get_table_str_opt(L, "bonetag", "");
char *lvl_bonetag = get_table_str_opt(L, "bonetag", emptystr);
int lvl_base = get_table_int(L, "base");
int lvl_range = get_table_int_opt(L, "range", 0);
int lvl_nlevels = get_table_int_opt(L, "nlevels", 0);
@@ -915,6 +924,9 @@ init_dungeons()
int lvl_align = dgnaligns2i[get_table_option(L, "alignment", "unaligned", dgnaligns)];
int lvl_flags = get_dgn_flags(L);
struct tmplevel *tmpl = &pd.tmplevel[pd.n_levs + f];
nhUse(lvl_bonetag);
nhUse(lvl_align);
debugpline4("LEVEL[%i]:%s,(%i,%i)", f, lvl_name, lvl_base, lvl_range);
tmpl->name = lvl_name;
tmpl->chainlvl = lvl_chain;
@@ -953,7 +965,7 @@ init_dungeons()
if (lua_type(L, -1) == LUA_TTABLE) {
int f, nbranches;
lua_len(L, -1);
nbranches = lua_tointeger(L, -1);
nbranches = LUA_INTCAST(lua_tointeger(L, -1));
pd.tmpdungeon[i].branches = nbranches;
lua_pop(L, 1);
for (f = 0; f < nbranches; f++) {

36
src/nhlsel.c Normal file → Executable file
View File

@@ -23,17 +23,27 @@ static int FDECL(l_selection_filter_mapchar, (lua_State *));
static int FDECL(l_selection_flood, (lua_State *));
static int FDECL(l_selection_circle, (lua_State *));
static int FDECL(l_selection_ellipse, (lua_State *));
static int FDECL(l_selection_gradient, (lua_State *));
static int FDECL(l_selection_iterate, (lua_State *));
static int FDECL(l_selection_gc, (lua_State *));
static int FDECL(l_selection_not, (lua_State *));
static int FDECL(l_selection_and, (lua_State *));
static int FDECL(l_selection_or, (lua_State *));
static int FDECL(l_selection_xor, (lua_State *));
static int FDECL(l_selection_not, (lua_State *));
#if 0
/* the following do not appear to currently be
used and because they are static, the OSX
compiler is complaining about them. I've
if ifdef'd out the prototype here and the
function body below.
*/
static int FDECL(l_selection_gradient, (lua_State *));
static int FDECL(l_selection_iterate, (lua_State *));
static int FDECL(l_selection_add, (lua_State *));
static int FDECL(l_selection_sub, (lua_State *));
static int FDECL(l_selection_ipairs, (lua_State *));
/* this prototype was missing but function body was below */
static struct selectionvar *FDECL(l_selection_to, (lua_State *, int));
#endif
struct selectionvar *
l_selection_check(L, index)
@@ -588,6 +598,17 @@ lua_State *L;
filled = (int) luaL_optinteger(L, 5, 0); /* TODO: boolean */
} else {
nhl_error(L, "wrong parameters");
/*
* FIXME: OSX compiler is issuing a complaint
* about r being passed to selection_do_ellipse()
* below without ever having been initialized
* to something when this else clause is encountered.
* I could have added an initializer to r at the
* top, but I didn't know what it should be initialized
* to in order for selection_do_ellipse() to not
* misbehave. The parameters passed in previous versions
* were related to xaxis and yaxis.
*/
}
get_location_coord(&x, &y, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x,y));
@@ -639,6 +660,17 @@ lua_State *L;
filled = (int) luaL_optinteger(L, 6, 0); /* TODO: boolean */
} else {
nhl_error(L, "wrong parameters");
/*
* FIXME: OSX compiler is issuing a complaint
* about r1 and r2 being passed to selection_do_ellipse()
* below without ever having been initialized
* to something when this else clause is encountered.
* I could have added an initializer to r1,r2 at the
* top, but I didn't know what they should be initialized
* to in order for selection_do_ellipse() to not
* misbehave. The parameters passed in previous versions
* were related to xaxis and yaxis.
*/
}
get_location_coord(&x, &y, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x,y));

24
src/nhlua.c Normal file → Executable file
View File

@@ -16,7 +16,9 @@
/* lua_CFunction prototypes */
static int FDECL(nhl_test, (lua_State *));
static int FDECL(nhl_getmap, (lua_State *));
#if 0
static int FDECL(nhl_setmap, (lua_State *));
#endif
static int FDECL(nhl_pline, (lua_State *));
static int FDECL(nhl_verbalize, (lua_State *));
static int FDECL(nhl_menu, (lua_State *));
@@ -87,7 +89,7 @@ schar defval;
char *ter;
xchar typ;
ter = get_table_str_opt(L, name, "");
ter = get_table_str_opt(L, name, emptystr);
if (name && *ter) {
typ = check_mapchr(ter);
if (typ == INVALID_TYPE)
@@ -213,8 +215,8 @@ lua_State *L;
int argc = lua_gettop(L);
if (argc == 2) {
int x = lua_tointeger(L, 1);
int y = lua_tointeger(L, 2);
int x = LUA_INTCAST(lua_tointeger(L, 1));
int y = LUA_INTCAST(lua_tointeger(L, 2));
if (x >= 0 && x < COLNO && y >= 0 && y < ROWNO) {
char buf[BUFSZ];
@@ -572,7 +574,9 @@ const char *name;
if (ltyp == LUA_TSTRING) {
const char *const boolstr[] = { "true", "false", "yes", "no", NULL };
const int boolstr2i[] = { TRUE, FALSE, TRUE, FALSE, -1 };
ret = luaL_checkoption(L, -1, NULL, boolstr);
nhUse(boolstr2i[0]);
} else if (ltyp == LUA_TBOOLEAN) {
ret = lua_toboolean(L, -1);
} else if (ltyp == LUA_TNUMBER) {
@@ -625,14 +629,17 @@ static int
nhl_test(L)
lua_State *L;
{
int x, y;
char *name, Player[] = "Player";
/* discard any extra arguments passed in */
lua_settop(L, 1);
luaL_checktype(L, 1, LUA_TTABLE);
int x = get_table_int(L, "x");
int y = get_table_int(L, "y");
char *name = get_table_str_opt(L, "name", "Player");
x = get_table_int(L, "x");
y = get_table_int(L, "y");
name = get_table_str_opt(L, "name", Player);
pline("TEST:{ x=%i, y=%i, name=\"%s\" }", x,y, name);
@@ -645,8 +652,9 @@ static const struct luaL_Reg nhl_functions[] = {
{"test", nhl_test},
{"getmap", nhl_getmap},
/*{"setmap", nhl_setmap},*/
#if 0
{"setmap", nhl_setmap},
#endif
{"pline", nhl_pline},
{"verbalize", nhl_verbalize},
{"menu", nhl_menu},

75
src/sp_lev.c Normal file → Executable file
View File

@@ -64,17 +64,13 @@ static void FDECL(wallify_map, (int, int, int, int));
static void FDECL(maze1xy, (coord *, int));
static void NDECL(fill_empty_maze);
static void FDECL(splev_initlev, (lev_init *));
#if 0
/* macosx complains that these are unused */
static long FDECL(sp_code_jmpaddr, (long, long));
static void NDECL(spo_end_moninvent);
static void NDECL(spo_pop_container);
static void FDECL(spo_room, (struct sp_coder *));
static void FDECL(spo_endroom, (struct sp_coder *));
static void FDECL(spo_trap, (struct sp_coder *));
static void FDECL(spo_gold, (struct sp_coder *));
static void FDECL(spo_corridor, (struct sp_coder *));
static void FDECL(sel_set_ter, (int, int, genericptr_t));
static void FDECL(sel_set_feature, (int, int, genericptr_t));
static void FDECL(sel_set_door, (int, int, genericptr_t));
static void FDECL(spo_feature, (struct sp_coder *));
static void FDECL(spo_terrain, (struct sp_coder *));
static void FDECL(spo_replace_terrain, (struct sp_coder *));
@@ -84,8 +80,15 @@ static void FDECL(spo_drawbridge, (struct sp_coder *));
static void FDECL(spo_mazewalk, (struct sp_coder *));
static void FDECL(spo_wall_property, (struct sp_coder *));
static void FDECL(spo_room_door, (struct sp_coder *));
static void FDECL(sel_set_wallify, (int, int, genericptr_t));
static void FDECL(spo_wallify, (struct sp_coder *));
static void FDECL(sel_set_wallify, (int, int, genericptr_t));
#endif
static void NDECL(spo_end_moninvent);
static void NDECL(spo_pop_container);
static void FDECL(spo_endroom, (struct sp_coder *));
static void FDECL(sel_set_ter, (int, int, genericptr_t));
static void FDECL(sel_set_door, (int, int, genericptr_t));
static void FDECL(sel_set_feature, (int, int, genericptr_t));
static int FDECL(get_coord, (lua_State *, int, int *, int *));
static int FDECL(get_table_region, (lua_State *, const char *, int *, int *, int *, int *, BOOLEAN_P));
@@ -2247,13 +2250,14 @@ lev_init *linit;
}
}
#if 0
static long
sp_code_jmpaddr(curpos, jmpaddr)
long curpos, jmpaddr;
{
return (curpos + jmpaddr);
}
#endif
/*ARGUSED*/
@@ -2282,6 +2286,7 @@ lua_State *L;
{
char *levmsg;
int old_n, n;
const char *msg;
int argc = lua_gettop(L);
@@ -2292,7 +2297,7 @@ lua_State *L;
create_des_coder();
const char *msg = luaL_checkstring(L, 1);
msg = luaL_checkstring(L, 1);
old_n = g.lev_message ? (strlen(g.lev_message) + 1) : 0;
n = strlen(msg);
@@ -2315,10 +2320,10 @@ int
get_table_align(L)
lua_State *L;
{
const char *const aligns[] = { "noalign", "law", "neutral", "chaos", "coaligned", "noncoaligned", "random", NULL };
const char *const gtaligns[] = { "noalign", "law", "neutral", "chaos", "coaligned", "noncoaligned", "random", NULL };
const int aligns2i[] = { AM_NONE, AM_LAWFUL, AM_NEUTRAL, AM_CHAOTIC, AM_SPLEV_CO, AM_SPLEV_NONCO, AM_SPLEV_RANDOM, 0 };
int a = aligns2i[get_table_option(L, "align", "random", aligns)];
int a = aligns2i[get_table_option(L, "align", "random", gtaligns)];
return a;
}
@@ -2347,6 +2352,7 @@ const char *s;
for (i = LOW_PM; i < NUMMONS; i++)
if (!strcmpi(mons[i].mname, s))
return i;
nhUse(L);
return NON_PM;
}
@@ -2501,7 +2507,7 @@ lua_State *L;
tmpmons.coord = SP_COORD_PACK(mx, my);
if (tmpmons.id != NON_PM && tmpmons.class == -1)
tmpmons.class = def_monsyms[mons[tmpmons.id].mlet].sym;
tmpmons.class = def_monsyms[(int) mons[tmpmons.id].mlet].sym;
create_monster(&tmpmons, g.coder->croom);
@@ -2528,6 +2534,7 @@ const char *name;
int rndval;
{
int ret;
char buf[BUFSZ];
lua_getfield(L, 1, name);
if (lua_type(L, -1) == LUA_TNIL) {
@@ -2541,7 +2548,6 @@ int rndval;
lua_pop(L, 1);
return rndval;
}
char buf[BUFSZ];
Sprintf(buf, "Expected integer or \"random\" for \"%s\", got %s", name, tmp);
nhl_error(L, buf);
lua_pop(L, 1);
@@ -2626,7 +2632,9 @@ int
lspo_object(L)
lua_State *L;
{
#if 0
int nparams = 0;
#endif
long quancnt;
object tmpobj;
int ox = -1, oy = -1;
@@ -2727,8 +2735,9 @@ lua_State *L;
tmpobj.id = -1;
if (tmpobj.id == STATUE || tmpobj.id == EGG || tmpobj.id == CORPSE || tmpobj.id == TIN) {
int flags = 0;
int lflags = 0;
const char *montype = get_table_str_opt(L, "montype", NULL);
if (montype) {
struct permonst *pm = NULL;
if (strlen(montype) == 1 && def_char_to_monclass(*montype) != MAXMCLASSES) {
@@ -2747,10 +2756,10 @@ lua_State *L;
nhl_error(L, "Unknown montype");
}
if (tmpobj.id == STATUE) {
flags |= (get_table_boolean_opt(L, "historic", 0) ? STATUE_HISTORIC : 0x00);
flags |= (get_table_boolean_opt(L, "male", 0) ? STATUE_MALE : 0x00);
flags |= (get_table_boolean_opt(L, "female", 0) ? STATUE_FEMALE : 0x00);
tmpobj.spe = flags;
lflags |= (get_table_boolean_opt(L, "historic", 0) ? STATUE_HISTORIC : 0x00);
lflags |= (get_table_boolean_opt(L, "male", 0) ? STATUE_MALE : 0x00);
lflags |= (get_table_boolean_opt(L, "female", 0) ? STATUE_FEMALE : 0x00);
tmpobj.spe = lflags;
} else if (tmpobj.id == EGG) {
tmpobj.spe = get_table_boolean_opt(L, "laid_by_you", 0) ? 1 : 0;
}
@@ -2877,7 +2886,7 @@ int
lspo_engraving(L)
lua_State *L;
{
int etyp;
int etyp = DUST;
char *txt = (char *) 0;
long ecoord;
const char *const engrtypes[] = { "dust", "engrave", "burn", "mark", "blood", NULL };
@@ -2885,6 +2894,8 @@ lua_State *L;
xchar x, y;
int argc = lua_gettop(L);
x = y = 0; /* FIXME: quiet a warning for else clause below.
should it actually be -1? */
create_des_coder();
if (argc == 1) {
@@ -2903,6 +2914,8 @@ lua_State *L;
txt = dupstr(luaL_checkstring(L, 3));
} else {
nhl_error(L, "Wrong parameters");
/* FIXME: this clause left etyp uninitialized so initialization
to DUST was added above to quiet a macosx warning */
}
if (x == -1 && y == -1)
@@ -2975,7 +2988,7 @@ lua_State *L;
const char *name;
int defval;
{
char *roomstr = get_table_str_opt(L, name, "");
char *roomstr = get_table_str_opt(L, name, emptystr);
if (roomstr && *roomstr) {
int i;
for (i = 0; room_types[i].name; i++)
@@ -3055,7 +3068,7 @@ lua_State *L;
static void
spo_endroom(coder)
struct sp_coder *coder;
struct sp_coder *coder UNUSED;
{
if (g.coder->n_subroom > 1) {
g.coder->n_subroom--;
@@ -3095,15 +3108,15 @@ lua_State *L;
const int stairdirs2i[] = { 0, 1 };
long scoord;
int ax = -1,ay = -1;
int ax = -1, ay = -1;
int up;
int ltype = lua_type(L, 1);
create_des_coder();
if (argc == 1 && ltype == LUA_TSTRING)
if (argc == 1 && ltype == LUA_TSTRING) {
up = stairdirs2i[luaL_checkoption(L, 1, "down", stairdirs)];
else if (argc == 3 && ltype == LUA_TSTRING) {
} else if (argc == 3 && ltype == LUA_TSTRING) {
up = stairdirs2i[luaL_checkoption(L, 1, "down", stairdirs)];
ax = luaL_checkinteger(L, 2);
ay = luaL_checkinteger(L, 3);
@@ -3154,15 +3167,15 @@ lua_State *L;
const int stairdirs2i[] = { 0, 1 };
long scoord;
int ax, ay;
int ax = -1, ay = -1; /* FIXME: initializers added, macosx warning */
int up;
int ltype = lua_type(L, 1);
create_des_coder();
if (argc == 1 && ltype == LUA_TSTRING)
if (argc == 1 && ltype == LUA_TSTRING) {
up = stairdirs2i[luaL_checkoption(L, 1, "down", stairdirs)];
else if (argc == 3 && ltype == LUA_TSTRING) {
} else if (argc == 3 && ltype == LUA_TSTRING) {
up = stairdirs2i[luaL_checkoption(L, 1, "down", stairdirs)];
ax = luaL_checkinteger(L, 2);
ay = luaL_checkinteger(L, 3);
@@ -3325,7 +3338,7 @@ lua_State *L;
const char *name;
int defval;
{
char *trapstr = get_table_str_opt(L, name, "");
char *trapstr = get_table_str_opt(L, name, emptystr);
if (trapstr && *trapstr) {
int i;
for (i = 0; trap_types[i].name; i++)
@@ -3474,7 +3487,7 @@ lua_State *L;
/* random_corridors(); */
int
lspo_random_corridors(L)
lua_State *L;
lua_State *L UNUSED;
{
corridor tc;
@@ -5119,6 +5132,7 @@ lua_State *L;
return 0;
}
#if 0
/*ARGSUSED*/
static void
sel_set_wallify(x, y, arg)
@@ -5127,6 +5141,7 @@ genericptr_t arg UNUSED;
{
wallify_map(x, y, x, y);
}
#endif
/* TODO: wallify(selection) */
/* wallify({ x1=NN,y1=NN, x2=NN,y2=NN }); */
@@ -5161,7 +5176,7 @@ lua_State *L;
/* reset_level is only needed for testing purposes */
int
lspo_reset_level(L)
lua_State *L;
lua_State *L UNUSED; /* macosx complaint needed UNUSED */
{
boolean wtower = In_W_tower(u.ux, u.uy, &u.uz);