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

Function lspo_drawbridge

src/sp_lev.c:5719–5763  ·  view source on GitHub ↗

drawbridge({ dir="east", state="closed", x=05,y=08 }); */ drawbridge({ dir="east", state="closed", coord={05,08} }); */

Source from the content-addressed store, hash-verified

5717/* drawbridge({ dir="east", state="closed", x=05,y=08 }); */
5718/* drawbridge({ dir="east", state="closed", coord={05,08} }); */
5719int
5720lspo_drawbridge(lua_State *L)
5721{
5722 static const char *const mwdirs[] = {
5723 "north", "south", "west", "east", "random", NULL
5724 };
5725 static const int mwdirs2i[] = {
5726 DB_NORTH, DB_SOUTH, DB_WEST, DB_EAST, -1, -2
5727 };
5728 static const char *const dbopens[] = {
5729 "open", "closed", "random", NULL
5730 };
5731 static const int dbopens2i[] = { 1, 0, -1, -2 };
5732 coordxy x, y;
5733 lua_Integer mx, my;
5734 int dir;
5735 int db_open;
5736 long dcoord;
5737
5738 create_des_coder();
5739
5740 lcheck_param_table(L);
5741
5742 get_table_xy_or_coord(L, &mx, &my);
5743
5744 dir = mwdirs2i[get_table_option(L, "dir", "random", mwdirs)];
5745 dcoord = SP_COORD_PACK(mx, my);
5746 db_open = dbopens2i[get_table_option(L, "state", "random", dbopens)];
5747 x = mx;
5748 y = my;
5749
5750 get_location_coord(&x, &y, DRY | WET | HOT, gc.coder->croom, dcoord);
5751 if (!isok(mx, my)) {
5752 nhl_error(L, "drawbridge coord not ok");
5753 /*NOTREACHED*/
5754 return 0;
5755 }
5756 if (db_open == -1)
5757 db_open = !rn2(2);
5758 if (!create_drawbridge(x, y, dir, db_open ? TRUE : FALSE))
5759 impossible("Cannot create drawbridge.");
5760 SpLev_Map[x][y] = 1;
5761
5762 return 0;
5763}
5764
5765/* mazewalk({ x = NN, y = NN, typ = ".", dir = "north", stocked = 0 }); */
5766/* mazewalk({ coord = {XX, YY}, typ = ".", dir = "north", stocked = 0 }); */

Callers

nothing calls this directly

Calls 10

create_des_coderFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_optionFunction · 0.85
get_location_coordFunction · 0.85
isokFunction · 0.85
nhl_errorFunction · 0.85
rn2Function · 0.85
create_drawbridgeFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected