mazewalk({ x = NN, y = NN, typ = ".", dir = "north", stocked = 0 }); */ mazewalk({ coord = {XX, YY}, typ = ".", dir = "north", stocked = 0 }); */ mazewalk(x,y,dir); */
| 5766 | /* mazewalk({ coord = {XX, YY}, typ = ".", dir = "north", stocked = 0 }); */ |
| 5767 | /* mazewalk(x,y,dir); */ |
| 5768 | int |
| 5769 | lspo_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; |
nothing calls this directly
no test coverage detected