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

Function l_selection_setpoint

src/nhlsel.c:158–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156/* local sel = selection.set(sel); */
157/* TODO: allow setting multiple coords at once: set({x1,y1},{x2,y2},...); */
158staticfn int
159l_selection_setpoint(lua_State *L)
160{
161 struct selectionvar *sel = (struct selectionvar *) 0;
162 coordxy x = -1, y = -1;
163 int val = 1;
164 int argc = lua_gettop(L);
165 long crd = 0L;
166
167 if (argc == 0) {
168 (void) l_selection_new(L);
169 } else if (argc == 1) {
170 sel = l_selection_check(L, 1);
171 } else if (argc == 2) {
172 x = (coordxy) luaL_checkinteger(L, 1);
173 y = (coordxy) luaL_checkinteger(L, 2);
174 lua_pop(L, 2);
175 (void) l_selection_new(L);
176 sel = l_selection_check(L, 1);
177 } else {
178 sel = l_selection_check(L, 1);
179 x = (coordxy) luaL_checkinteger(L, 2);
180 y = (coordxy) luaL_checkinteger(L, 3);
181 val = (int) luaL_optinteger(L, 4, 1);
182 }
183
184 if (!sel || !sel->map) {
185 nhl_error(L, "Selection setpoint error");
186 /*NOTREACHED*/
187 return 0;
188 }
189
190 if (x == -1 && y == -1)
191 crd = SP_COORD_PACK_RANDOM(0);
192 else
193 crd = SP_COORD_PACK(x,y);
194 get_location_coord(&x, &y, ANY_LOC,
195 gc.coder ? gc.coder->croom : NULL, crd);
196 selection_setpoint(x, y, sel, val);
197 lua_settop(L, 1);
198 return 1;
199}
200
201/* local numpoints = selection.numpoints(sel); */
202staticfn int

Callers

nothing calls this directly

Calls 5

l_selection_newFunction · 0.85
l_selection_checkFunction · 0.85
nhl_errorFunction · 0.85
get_location_coordFunction · 0.85
selection_setpointFunction · 0.85

Tested by

no test coverage detected