1 /* Copyright (C) 2001 by Alex Kompel <shurikk@pacbell.net> */
2 /* NetHack may be freely redistributed. See license for details. */
4 /* various dialog boxes are defined here */
12 /*---------------------------------------------------------------*/
13 /* data for getlin dialog */
20 BOOL CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM);
22 int mswin_getlin_window (
29 struct getlin_data data;
31 /* initilize dialog data */
32 ZeroMemory(&data, sizeof(data));
33 data.question = question;
35 data.result_size = result_size;
37 /* create modal dialog window */
40 MAKEINTRESOURCE(IDD_GETLIN),
45 if( ret==-1 ) panic("Cannot create getlin window");
50 BOOL CALLBACK GetlinDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
52 struct getlin_data* data;
68 data = (struct getlin_data*)lParam;
69 SetWindowText(hWnd, NH_A2W(data->question, wbuf, sizeof(wbuf)));
70 SetWindowLong(hWnd, GWL_USERDATA, lParam);
72 /* center dialog in the main window */
73 GetWindowRect(hWnd, &dlg_rt);
74 GetWindowRect(GetNHApp()->hMainWnd, &main_rt);
75 WindowDC = GetWindowDC(hWnd);
77 if (!GetWindowExtEx(WindowDC, &WindowExtents) ||
78 !GetViewportExtEx(WindowDC, &ViewPortExtents) ||
79 !GetTextExtentPoint32(GetWindowDC (hWnd), wbuf, _tcslen(wbuf), &dlg_sz))
85 /* I think we need to do the following scaling */
86 dlg_sz.cx *= ViewPortExtents.cx; dlg_sz.cx /= WindowExtents.cx;
87 /* Add the size of the various items in the caption bar */
88 dlg_sz.cx += GetSystemMetrics(SM_CXSIZE) +
89 2 * (GetSystemMetrics (SM_CXBORDER) + GetSystemMetrics(SM_CXFRAME));
92 if (dlg_sz.cx < dlg_rt.right - dlg_rt.left)
93 dlg_sz.cx = dlg_rt.right - dlg_rt.left;
94 dlg_sz.cy = dlg_rt.bottom - dlg_rt.top;
95 dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2;
96 dlg_rt.right = dlg_rt.left + dlg_sz.cx;
97 dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2;
98 dlg_rt.bottom = dlg_rt.top + dlg_sz.cy;
100 (main_rt.left+main_rt.right-dlg_sz.cx)/2,
101 (main_rt.top+main_rt.bottom-dlg_sz.cy)/2,
106 /* set focus and size of the edit control */
107 ControlHWND = GetDlgItem(hWnd, IDC_GETLIN_EDIT);
108 SetFocus(ControlHWND);
109 GetClientRect (hWnd, &ClientRect);
110 GetWindowRect (ControlHWND, &ControlRect);
111 MoveWindow (ControlHWND, 0, 0,
112 ClientRect.right - ClientRect.left,
113 ControlRect.bottom - ControlRect.top, TRUE);
114 ButtonOffset = ControlRect.bottom - ControlRect.top;
116 /* Now get the OK and CANCEL buttons */
117 ControlHWND = GetDlgItem(hWnd, IDOK);
118 GetWindowRect (ControlHWND, &ControlRect);
119 Division = ((ClientRect.right - ClientRect.left) -
120 2 * (ControlRect.right - ControlRect.left)) / 3;
121 MoveWindow (ControlHWND, Division,
123 ControlRect.right - ControlRect.left,
124 ControlRect.bottom - ControlRect.top, TRUE);
125 ControlHWND = GetDlgItem(hWnd, IDCANCEL);
126 MoveWindow (ControlHWND,
127 Division * 2 + ControlRect.right - ControlRect.left,
129 ControlRect.right - ControlRect.left,
130 ControlRect.bottom - ControlRect.top, TRUE);
132 /* tell windows that we've set the focus */
140 switch (LOWORD(wParam))
142 /* OK button was pressed */
144 data = (struct getlin_data*)GetWindowLong(hWnd, GWL_USERDATA);
145 SendDlgItemMessage(hWnd, IDC_GETLIN_EDIT, WM_GETTEXT, (WPARAM)sizeof(wbuf), (LPARAM)wbuf );
146 NH_W2A(wbuf, data->result, data->result_size);
150 /* cancel button was pressed */
152 EndDialog(hWnd, wParam);
157 } /* end switch (message) */
162 /*---------------------------------------------------------------*/
163 /* dialog data for the list of extended commands */
168 BOOL CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM);
170 int mswin_ext_cmd_window (int* selection)
173 struct extcmd_data data;
175 /* init dialog data */
176 ZeroMemory(&data, sizeof(data));
178 data.selection = selection;
180 /* create modal dialog window */
181 ret = DialogBoxParam(
183 MAKEINTRESOURCE(IDD_EXTCMD),
184 GetNHApp()->hMainWnd,
188 if( ret==-1 ) panic("Cannot create extcmd window");
192 BOOL CALLBACK ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
194 struct extcmd_data* data;
195 RECT main_rt, dlg_rt;
204 data = (struct extcmd_data*)lParam;
205 SetWindowLong(hWnd, GWL_USERDATA, lParam);
207 /* center dialog in the main window */
208 GetWindowRect(GetNHApp()->hMainWnd, &main_rt);
209 GetWindowRect(hWnd, &dlg_rt);
210 dlg_sz.cx = dlg_rt.right - dlg_rt.left;
211 dlg_sz.cy = dlg_rt.bottom - dlg_rt.top;
213 dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2;
214 dlg_rt.right = dlg_rt.left + dlg_sz.cx;
215 dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2;
216 dlg_rt.bottom = dlg_rt.top + dlg_sz.cy;
218 (main_rt.left+main_rt.right-dlg_sz.cx)/2,
219 (main_rt.top+main_rt.bottom-dlg_sz.cy)/2,
224 /* fill combobox with extended commands */
225 for(i=0; (ptr=extcmdlist[i].ef_txt); i++) {
226 SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(ptr, wbuf, sizeof(wbuf)) );
229 /* set focus to the list control */
230 SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST));
232 /* tell windows we set the focus */
237 data = (struct extcmd_data*)GetWindowLong(hWnd, GWL_USERDATA);
238 switch (LOWORD(wParam))
240 /* OK button ws clicked */
242 *data->selection = SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
243 if( *data->selection==LB_ERR )
244 *data->selection = -1;
247 /* CANCEL button ws clicked */
249 EndDialog(hWnd, wParam);
252 /* list control events */
253 case IDC_EXTCMD_LIST:
254 switch(HIWORD(wParam)) {
257 /* double click within the list
259 The low-order word is the list box identifier.
260 The high-order word is the notification message.
262 Handle to the list box
264 *data->selection = SendMessage((HWND)lParam, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
265 if( *data->selection==LB_ERR )
266 *data->selection = -1;
267 EndDialog(hWnd, IDOK);
276 /*---------------------------------------------------------------*/
277 /* player selector dialog data */
282 BOOL CALLBACK PlayerSelectorDlgProc(HWND, UINT, WPARAM, LPARAM);
283 static void plselInitDialog(HWND hWnd);
284 static void plselAdjustLists(HWND hWnd, int changed_opt);
285 static int plselFinalSelection(HWND hWnd, int* selection);
287 int mswin_player_selection_window ( int* selection )
290 struct plsel_data data;
292 /* init dialog data */
293 ZeroMemory(&data, sizeof(data));
294 data.selection = selection;
296 /* create modal dialog */
297 ret = DialogBoxParam(
299 MAKEINTRESOURCE(IDD_PLAYER_SELECTOR),
300 GetNHApp()->hMainWnd,
301 PlayerSelectorDlgProc,
304 if( ret==-1 ) panic("Cannot create getlin window");
309 BOOL CALLBACK PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
311 struct plsel_data* data;
312 RECT main_rt, dlg_rt;
318 data = (struct plsel_data*)lParam;
319 SetWindowLong(hWnd, GWL_USERDATA, lParam);
321 /* center dialog in the main window */
322 GetWindowRect(GetNHApp()->hMainWnd, &main_rt);
323 GetWindowRect(hWnd, &dlg_rt);
324 dlg_sz.cx = dlg_rt.right - dlg_rt.left;
325 dlg_sz.cy = dlg_rt.bottom - dlg_rt.top;
327 dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2;
328 dlg_rt.right = dlg_rt.left + dlg_sz.cx;
329 dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2;
330 dlg_rt.bottom = dlg_rt.top + dlg_sz.cy;
332 (main_rt.left+main_rt.right-dlg_sz.cx)/2,
333 (main_rt.top+main_rt.bottom-dlg_sz.cy)/2,
339 plselInitDialog(hWnd);
341 /* set focus on the role checkbox (random) field */
342 SetFocus(GetDlgItem(hWnd, IDC_PLSEL_ROLE_RANDOM));
344 /* tell windows we set the focus */
349 data = (struct plsel_data*)GetWindowLong(hWnd, GWL_USERDATA);
350 switch (LOWORD(wParam)) {
352 /* OK button was clicked */
354 if( plselFinalSelection(hWnd, data->selection) ) {
355 EndDialog(hWnd, wParam);
357 NHMessageBox(hWnd, TEXT("Cannot match this role. Try something else."), MB_ICONSTOP | MB_OK );
361 /* CANCEL button was clicked */
363 *data->selection = -1;
364 EndDialog(hWnd, wParam);
367 /* following are events from dialog controls:
368 "random" checkboxes send BN_CLICKED messages;
369 role/race/... combo-boxes send CBN_SELENDOK
370 if something was selected;
372 case IDC_PLSEL_ROLE_RANDOM:
373 if( HIWORD(wParam)==BN_CLICKED ) {
374 /* enable corresponding list window if "random"
375 checkbox was "unchecked" */
377 GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST),
378 SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED
383 case IDC_PLSEL_RACE_RANDOM:
384 if( HIWORD(wParam)==BN_CLICKED ) {
386 GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST),
387 SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED
392 case IDC_PLSEL_GENDER_RANDOM:
393 if( HIWORD(wParam)==BN_CLICKED ) {
395 GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST),
396 SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED
401 case IDC_PLSEL_ALIGN_RANDOM:
402 if( HIWORD(wParam)==BN_CLICKED ) {
404 GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST),
405 SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED
410 case IDC_PLSEL_ROLE_LIST:
411 if( HIWORD(wParam)==CBN_SELENDOK ) {
412 /* filter out invalid options if
413 the selection was made */
414 plselAdjustLists( hWnd, LOWORD(wParam) );
418 case IDC_PLSEL_RACE_LIST:
419 if( HIWORD(wParam)==CBN_SELENDOK ) {
420 plselAdjustLists( hWnd, LOWORD(wParam) );
424 case IDC_PLSEL_GENDER_LIST:
425 if( HIWORD(wParam)==CBN_SELENDOK ) {
426 plselAdjustLists( hWnd, LOWORD(wParam) );
430 case IDC_PLSEL_ALIGN_LIST:
431 if( HIWORD(wParam)==CBN_SELENDOK ) {
432 plselAdjustLists( hWnd, LOWORD(wParam) );
441 void setComboBoxValue(HWND hWnd, int combo_box, int value)
443 int index_max = SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0);
445 int value_to_set = LB_ERR;
446 for (index = 0; index < index_max; index++) {
447 if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, (WPARAM)index, 0) == value) {
448 value_to_set = index;
452 SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM)value_to_set, 0);
455 /* initialize player selector dialog */
456 void plselInitDialog(HWND hWnd)
460 /* set player name */
461 SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf)));
463 /* check flags for consistency */
464 if( flags.initrole>=0 ) {
465 if (flags.initrace>=0 && !validrace(flags.initrole, flags.initrace)) {
466 flags.initrace = ROLE_NONE;
469 if (flags.initgend>=0 && !validgend(flags.initrole, flags.initrace, flags.initgend)) {
470 flags.initgend = ROLE_NONE;
473 if (flags.initalign>=0 && !validalign(flags.initrole, flags.initrace, flags.initalign)) {
474 flags.initalign = ROLE_NONE;
478 /* populate select boxes */
479 plselAdjustLists(hWnd, -1);
481 /* intialize roles list */
482 if( flags.initrole<0 || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) {
483 CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED);
484 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE);
486 CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED);
487 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE);
488 setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole);
491 /* intialize races list */
492 if( flags.initrace<0 || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE) ) {
493 CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED);
494 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE);
496 CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED);
497 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE);
498 setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace);
501 /* intialize genders list */
502 if( flags.initgend<0 || !ok_gend(flags.initrole, flags.initrace, flags.initgend, ROLE_NONE)) {
503 CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED);
504 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE);
506 CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED);
507 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE);
508 setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend);
511 /* intialize alignments list */
512 if( flags.initalign<0 || !ok_align(flags.initrole, flags.initrace, flags.initgend, flags.initalign) ) {
513 CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED);
514 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE);
516 CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED);
517 EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE);
518 setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign);
522 /* adjust role/race/alignment/gender list - filter out
524 changed_sel points to the list where selection occured
527 void plselAdjustLists(HWND hWnd, int changed_sel)
529 HWND control_role, control_race, control_gender, control_align;
530 int initrole, initrace, initgend, initalign;
536 /* get control handles */
537 control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST);
538 control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST);
539 control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST);
540 control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST);
542 /* get current selections */
543 ind = SendMessage(control_role, CB_GETCURSEL, 0, 0);
544 initrole = (ind==LB_ERR)? flags.initrole : SendMessage(control_role, CB_GETITEMDATA, ind, 0);
546 ind = SendMessage(control_race, CB_GETCURSEL, 0, 0);
547 initrace = (ind==LB_ERR)? flags.initrace : SendMessage(control_race, CB_GETITEMDATA, ind, 0);
549 ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0);
550 initgend = (ind==LB_ERR)? flags.initgend : SendMessage(control_gender, CB_GETITEMDATA, ind, 0);
552 ind = SendMessage(control_align, CB_GETCURSEL, 0, 0);
553 initalign = (ind==LB_ERR)? flags.initalign : SendMessage(control_align, CB_GETITEMDATA, ind, 0);
555 /* intialize roles list */
556 if( changed_sel==-1 ) {
559 /* reset content and populate the list */
560 SendMessage(control_role, CB_RESETCONTENT, 0, 0);
561 for (i = 0; roles[i].name.m; i++) {
562 if (initgend>=0 && flags.female && roles[i].name.f)
563 ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) );
565 ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) );
567 SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
569 SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
574 /* set selection to the previously selected role
575 if it is still valid */
577 initrole = ROLE_NONE;
578 initrace = ROLE_NONE;
579 initgend = ROLE_NONE;
580 initalign = ROLE_NONE;
581 SendMessage(control_role, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 );
584 /* trigger change of the races list */
585 changed_sel=IDC_PLSEL_ROLE_LIST;
588 /* intialize races list */
589 if( changed_sel==IDC_PLSEL_ROLE_LIST ) {
592 /* reset content and populate the list */
593 SendMessage(control_race, CB_RESETCONTENT, 0, 0);
594 for (i = 0; races[i].noun; i++)
595 if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) {
596 ind = SendMessage(control_race, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(races[i].noun, wbuf, sizeof(wbuf)) );
597 SendMessage(control_race, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
599 SendMessage(control_race, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
604 /* set selection to the previously selected race
605 if it is still valid */
607 initrace = ROLE_NONE;
608 initgend = ROLE_NONE;
609 initalign = ROLE_NONE;
610 SendMessage(control_race, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 );
613 /* trigger change of the genders list */
614 changed_sel=IDC_PLSEL_RACE_LIST;
617 /* intialize genders list */
618 if( changed_sel==IDC_PLSEL_RACE_LIST ) {
621 /* reset content and populate the list */
622 SendMessage(control_gender, CB_RESETCONTENT, 0, 0);
623 for (i = 0; i < ROLE_GENDERS; i++)
624 if (ok_gend(initrole, initrace, i, ROLE_NONE)) {
625 ind = SendMessage(control_gender, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(genders[i].adj, wbuf, sizeof(wbuf)) );
626 SendMessage(control_gender, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
628 SendMessage(control_gender, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
633 /* set selection to the previously selected gender
634 if it is still valid */
636 initgend = ROLE_NONE;
637 initalign = ROLE_NONE;
638 SendMessage(control_gender, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 );
641 /* trigger change of the alignments list */
642 changed_sel=IDC_PLSEL_GENDER_LIST;
645 /* intialize alignments list */
646 if( changed_sel==IDC_PLSEL_GENDER_LIST ) {
649 /* reset content and populate the list */
650 SendMessage(control_align, CB_RESETCONTENT, 0, 0);
651 for (i = 0; i < ROLE_ALIGNS; i++)
652 if (ok_align(initrole, initrace, initgend, i)) {
653 ind = SendMessage(control_align, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf)) );
654 SendMessage(control_align, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
656 SendMessage(control_align, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
661 /* set selection to the previously selected alignment
662 if it is still valid */
664 initalign = ROLE_NONE;
665 SendMessage(control_align, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 );
670 /* player made up his mind - get final selection here */
671 int plselFinalSelection(HWND hWnd, int* selection)
675 /* get current selections */
676 if( SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) {
677 flags.initrole = ROLE_RANDOM;
679 ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETCURSEL, 0, 0);
680 flags.initrole = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETITEMDATA, ind, 0);
683 if( SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) {
684 flags.initrace = ROLE_RANDOM;
686 ind = SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETCURSEL, 0, 0);
687 flags.initrace = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETITEMDATA, ind, 0);
690 if( SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) {
691 flags.initgend = ROLE_RANDOM;
693 ind = SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETCURSEL, 0, 0);
694 flags.initgend = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETITEMDATA, ind, 0);
697 if( SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) {
698 flags.initalign = ROLE_RANDOM;
700 ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETCURSEL, 0, 0);
701 flags.initalign = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETITEMDATA, ind, 0);
706 if( flags.initrole==ROLE_RANDOM ) {
707 flags.initrole = pick_role(flags.initrace, flags.initgend, flags.initalign, PICK_RANDOM);
708 if (flags.initrole < 0) {
709 NHMessageBox(hWnd, TEXT("Incompatible role!"), MB_ICONSTOP | MB_OK);
714 /* Select a race, if necessary */
715 /* force compatibility with role */
716 if (flags.initrace==ROLE_RANDOM || !validrace(flags.initrole, flags.initrace)) {
717 /* pre-selected race not valid */
718 if (flags.initrace == ROLE_RANDOM) {
719 flags.initrace = pick_race(flags.initrole, flags.initgend, flags.initalign, PICK_RANDOM);
722 if (flags.initrace < 0) {
723 NHMessageBox(hWnd, TEXT("Incompatible race!"), MB_ICONSTOP | MB_OK);
728 /* Select a gender, if necessary */
729 /* force compatibility with role/race, try for compatibility with
730 * pre-selected alignment */
731 if (flags.initgend < 0 ||
732 !validgend(flags.initrole, flags.initrace, flags.initgend)) {
733 /* pre-selected gender not valid */
734 if (flags.initgend == ROLE_RANDOM) {
735 flags.initgend = pick_gend(flags.initrole, flags.initrace, flags.initalign, PICK_RANDOM);
738 if (flags.initgend < 0) {
739 NHMessageBox(hWnd, TEXT("Incompatible gender!"), MB_ICONSTOP | MB_OK);
744 /* Select an alignment, if necessary */
745 /* force compatibility with role/race/gender */
746 if (flags.initalign < 0 ||
747 !validalign(flags.initrole, flags.initrace, flags.initalign)) {
748 /* pre-selected alignment not valid */
749 if (flags.initalign == ROLE_RANDOM) {
750 flags.initalign = pick_align(flags.initrole, flags.initrace, flags.initgend, PICK_RANDOM);
752 NHMessageBox(hWnd, TEXT("Incompatible alignment!"), MB_ICONSTOP | MB_OK);