MCPcopy Index your code
hub / github.com/NetHack/NetHack / there_cmd_menu

Function there_cmd_menu

src/cmd.c:4842–4896  ·  view source on GitHub ↗

offer choice of actions to perform at adjacent location ; a few choices can be farther away */

Source from the content-addressed store, hash-verified

4840/* offer choice of actions to perform at adjacent location <x,y>;
4841 a few choices can be farther away */
4842staticfn char
4843there_cmd_menu(coordxy x, coordxy y, int mod)
4844{
4845 winid win;
4846 char ch = '\0';
4847 int npick = 0, K = 0;
4848 menu_item *picks = (menu_item *) 0;
4849 /*int dx = sgn(x - u.ux), dy = sgn(y - u.uy);*/
4850 coordxy dx = x - u.ux, dy = y - u.uy;
4851 int act = MCMD_NOTHING;
4852
4853 win = create_nhwindow(NHW_MENU);
4854 start_menu(win, MENU_BEHAVE_STANDARD);
4855
4856 if (u_at(x, y))
4857 K += there_cmd_menu_self(win, x, y, &act);
4858 else if (next2u(x, y))
4859 K += there_cmd_menu_next2u(win, x, y, mod, &act);
4860 else
4861 K += there_cmd_menu_far(win, x, y, mod);
4862 K += there_cmd_menu_common(win, x, y, mod, &act);
4863
4864 if (!K) {
4865 /* no menu options, try to move */
4866 if (next2u(x, y) && test_move(u.ux, u.uy, dx, dy, TEST_MOVE)) {
4867 int dir = xytodir(dx, dy);
4868
4869 cmdq_add_ec(CQ_CANNED, move_funcs[dir][MV_WALK]);
4870 } else if (flags.travelcmd) {
4871 iflags.travelcc.x = u.tx = x;
4872 iflags.travelcc.y = u.ty = y;
4873 cmdq_add_ec(CQ_CANNED, dotravel_target);
4874 }
4875 npick = 0;
4876 ch = '\0';
4877 } else if (K == 1 && act != MCMD_NOTHING && act != MCMD_TRAVEL) {
4878 destroy_nhwindow(win);
4879
4880 act_on_act(act, dx, dy);
4881 return '\0';
4882 } else {
4883 end_menu(win, "What do you want to do?");
4884 npick = select_menu(win, PICK_ONE, &picks);
4885 ch = '\033';
4886 }
4887 destroy_nhwindow(win);
4888 if (npick > 0) {
4889 act = picks->item.a_int;
4890 free((genericptr_t) picks);
4891
4892 act_on_act(act, dx, dy);
4893 return '\0';
4894 }
4895 return ch;
4896}
4897
4898staticfn char
4899here_cmd_menu(void)

Callers 2

dotherecmdmenuFunction · 0.85
here_cmd_menuFunction · 0.85

Calls 9

there_cmd_menu_selfFunction · 0.85
there_cmd_menu_next2uFunction · 0.85
there_cmd_menu_farFunction · 0.85
there_cmd_menu_commonFunction · 0.85
test_moveFunction · 0.85
xytodirFunction · 0.85
cmdq_add_ecFunction · 0.85
act_on_actFunction · 0.85
select_menuFunction · 0.85

Tested by

no test coverage detected