MCPcopy Create free account
hub / github.com/NetHack/NetHack / lspo_mazewalk

Function lspo_mazewalk

src/sp_lev.c:5768–5869  ·  view source on GitHub ↗

mazewalk({ x = NN, y = NN, typ = ".", dir = "north", stocked = 0 }); */ mazewalk({ coord = {XX, YY}, typ = ".", dir = "north", stocked = 0 }); */ mazewalk(x,y,dir); */

Source from the content-addressed store, hash-verified

5766/* mazewalk({ coord = {XX, YY}, typ = ".", dir = "north", stocked = 0 }); */
5767/* mazewalk(x,y,dir); */
5768int
5769lspo_mazewalk(lua_State *L)
5770{
5771 static const char *const mwdirs[] = {
5772 "north", "south", "east", "west", "random", NULL
5773 };
5774 static const int mwdirs2i[] = {
5775 W_NORTH, W_SOUTH, W_EAST, W_WEST, W_RANDOM, -2
5776 };
5777 coordxy x, y;
5778 lua_Integer mx, my;
5779 coordxy ftyp = ROOM;
5780 int fstocked = 1, dir = -1;
5781 long mcoord;
5782 int argc = lua_gettop(L);
5783
5784 create_des_coder();
5785
5786 if (argc == 3) {
5787 mx = luaL_checkinteger(L, 1);
5788 my = luaL_checkinteger(L, 2);
5789 dir = mwdirs2i[luaL_checkoption(L, 3, "random", mwdirs)];
5790 } else {
5791 lcheck_param_table(L);
5792
5793 get_table_xy_or_coord(L, &mx, &my);
5794 ftyp = get_table_mapchr_opt(L, "typ", ROOM);
5795 fstocked = get_table_boolean_opt(L, "stocked", 1);
5796 dir = mwdirs2i[get_table_option(L, "dir", "random", mwdirs)];
5797 }
5798
5799 mcoord = SP_COORD_PACK(mx, my);
5800 x = mx;
5801 y = my;
5802
5803 get_location_coord(&x, &y, ANY_LOC, gc.coder->croom, mcoord);
5804
5805 if (!isok(x, y)) {
5806 nhl_error(L, "mazewalk coord not ok");
5807 /*NOTREACHED*/
5808 return 0;
5809 }
5810
5811 if (ftyp < 1) {
5812 ftyp = svl.level.flags.corrmaze ? CORR : ROOM;
5813 }
5814
5815 if (dir == W_RANDOM)
5816 dir = random_wdir();
5817
5818 /* don't use move() - it doesn't use W_NORTH, etc. */
5819 switch (dir) {
5820 case W_NORTH:
5821 --y;
5822 break;
5823 case W_SOUTH:
5824 y++;
5825 break;

Callers

nothing calls this directly

Calls 13

create_des_coderFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_mapchr_optFunction · 0.85
get_table_boolean_optFunction · 0.85
get_table_optionFunction · 0.85
get_location_coordFunction · 0.85
isokFunction · 0.85
nhl_errorFunction · 0.85
random_wdirFunction · 0.85
walkfromFunction · 0.85
fill_empty_mazeFunction · 0.85

Tested by

no test coverage detected