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

Function lspo_gold

src/sp_lev.c:4472–4522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4470}
4471
4472DISABLE_WARNING_UNREACHABLE_CODE
4473
4474/* gold(500, 3,5); */
4475/* gold(500, {5, 6}); */
4476/* gold({ amount = 500, x = 2, y = 5 });*/
4477/* gold({ amount = 500, coord = {2, 5} });*/
4478/* gold(); */
4479int
4480lspo_gold(lua_State *L)
4481{
4482 int argc = lua_gettop(L);
4483 coordxy x, y;
4484 long amount;
4485 long gcoord;
4486 lua_Integer gldx, gldy;
4487
4488 create_des_coder();
4489
4490 if (argc == 3) {
4491 amount = luaL_checkinteger(L, 1);
4492 x = gldx = luaL_checkinteger(L, 2);
4493 y = gldy = luaL_checkinteger(L, 3);
4494 } else if (argc == 2 && lua_type(L, 2) == LUA_TTABLE) {
4495 amount = luaL_checkinteger(L, 1);
4496 (void) get_coord(L, 2, &gldx, &gldy);
4497 x = gldx;
4498 y = gldy;
4499 } else if (argc == 0 || (argc == 1 && lua_type(L, 1) == LUA_TTABLE)) {
4500 lcheck_param_table(L);
4501
4502 amount = get_table_int_opt(L, "amount", -1);
4503 get_table_xy_or_coord(L, &gldx, &gldy);
4504 x = gldx, y = gldy;
4505 } else {
4506 nhl_error(L, "Wrong parameters");
4507 /*NOTREACHED*/
4508 return 0;
4509 }
4510
4511 if (x == -1 && y == -1)
4512 gcoord = SP_COORD_PACK_RANDOM(0);
4513 else
4514 gcoord = SP_COORD_PACK(gldx, gldy);
4515
4516 get_location_coord(&x, &y, DRY, gc.coder->croom, gcoord);
4517 if (amount < 0)
4518 amount = rnd(200);
4519 mkgold(amount, x, y);
4520
4521 return 0;
4522}
4523
4524RESTORE_WARNING_UNREACHABLE_CODE
4525

Callers

nothing calls this directly

Calls 9

create_des_coderFunction · 0.85
get_coordFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_int_optFunction · 0.85
get_table_xy_or_coordFunction · 0.85
nhl_errorFunction · 0.85
get_location_coordFunction · 0.85
rndFunction · 0.85
mkgoldFunction · 0.85

Tested by

no test coverage detected