static void test_repair( const std::vector<item> &tools, bool expect_craftable ) { clear_player(); clear_map(); const tripoint test_origin( 60, 60, 0 ); g->u.setpos( test_origin ); const item backpack( "backpack" ); g->u.wear( g->u.i_add( backpack ), false ); for( const item gear : tools ) { g->u.i_add( gear ); } const tripoint vehicle_origin = test_origin + tripoint( 1, 1, 0 ); vehicle *veh_ptr = g->m.add_vehicle( vproto_id( "bicycle" ), vehicle_origin, -90, 0, 0 ); REQUIRE( veh_ptr != nullptr ); // Find the frame at the origin. vehicle_part *origin_frame = nullptr; for( vehicle_part *part : veh_ptr->get_parts_at( vehicle_origin, "", part_status_flag::any ) ) { if( part->info().location == "structure" ) { origin_frame = part; break; } } REQUIRE( origin_frame != nullptr ); REQUIRE( origin_frame->hp() == origin_frame->info().durability ); veh_ptr->mod_hp( *origin_frame, -100 ); REQUIRE( origin_frame->hp() < origin_frame->info().durability ); const vpart_info &vp = origin_frame->info(); // Assertions about frame part? requirement_data reqs = vp.repair_requirements(); // Bust cache on crafting_inventory() g->u.mod_moves( 1 ); inventory crafting_inv = g->u.crafting_inventory(); bool can_repair = vp.repair_requirements().can_make_with_inventory( g->u.crafting_inventory(), is_crafting_component ); CHECK( can_repair == expect_craftable ); }
int NEAR PASCAL CommandHandler(WORD wParam, LONG lParam) { /* if (HIWORD(lParam) == EN_CHANGE) { if (focus(GetDlgCtrlID(LOWORD(lParam))) && players.player_numb > -1) bNeedSaveP = TRUE; else if (courses.course_numb > -1) bNeedSaveC = TRUE; } */ switch (wParam) { case IDOK: SendMessage(hWnd, WM_COMMAND, IDD_RLIST, MAKELONG(0, LBN_DBLCLK)); return NULL; case IDM_CONTENTS: case IDM_SEARCHON: case IDM_USE: MessageBox(hWnd, "Help to come soon!", szAppName, MB_OK | MB_ICONEXCLAMATION); return NULL; case IDM_ABOUT: /* display about dialog box */ lpfnGenericDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst); DialogBox(hInst, "ABOUT", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_HANDICAP: lpfnGenericDlgProc = MakeProcInstance((FARPROC)HandicapDlgProc, hInst); DialogBox(hInst, "HANDICAP", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_P_SEARCH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; /* fall through */ case IDM_C_SEARCH: if (!get_course(hWnd, &courses, c_index)) return NULL; wWhich = wParam; lpfnGenericDlgProc = MakeProcInstance((FARPROC)SearchDlgProc, hInst); DialogBox(hInst, "SEARCH", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_GRAPH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (!get_course(hWnd, &courses, c_index)) return NULL; if (IDYES == MessageBox(hWnd, "You must have Microsoft Excel\nto use this option. Continue?", szAppName, MB_YESNO | MB_ICONQUESTION)) GraphData(&(players).player[p_index].p_scores, &courses); return NULL; case IDM_NEW_P: /* save current file and clear viewport */ if (bNeedSaveP && IDCANCEL == AskAboutSave(hWnd, szFileTitleP, PLAYER_MARKER)) return FALSE; szFileTitleP[NULL] = '\0'; bNeedSaveP = FALSE; p_index = r_index = r_last = 0; players.player_numb = -1; clear_player(hWnd, hWndRList); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_NEW_C: if (bNeedSaveC && IDCANCEL == AskAboutSave(hWnd, szFileTitleC, COURSE_MARKER)) return FALSE; szFileTitleC[NULL] = '\0'; bNeedSaveC = FALSE; c_index = 0; courses.course_numb = -1; clear_course(hWnd); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_OPEN_P: /* open an existing file */ of_player.lpstrTitle = "Open Player"; of_player.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_player)) return FALSE; if (ReadFile(hWnd, szFileP, szFileTitleP, szFileTitleC, bNeedSaveP, &players, &courses, PLAYER_MARKER)) { bNeedSaveP = FALSE; p_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_OPEN_C: /* open an existing file */ of_course.lpstrTitle = "Open Course"; of_course.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_course)) return FALSE; if (ReadFile(hWnd, szFileC, szFileTitleP, szFileTitleC, bNeedSaveC, &players, &courses, COURSE_MARKER)) { bNeedSaveC = FALSE; c_index = 0; show_course(hWnd, &courses, &c_index); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_SAVE_P: /* write current file */ if (szFileTitleP[NULL]) { if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_P: /* change file name */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; of_player.lpstrTitle = "Save Player"; of_player.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_player)) return FALSE; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_SAVE_C: /* write current file */ if (szFileTitleC[NULL]) { if (!get_course(hWnd, &courses, c_index)) return NULL; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_C: /* change file name */ if (!get_course(hWnd, &courses, c_index)) return NULL; of_course.lpstrTitle = "Save Course"; of_course.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_course)) return FALSE; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_PRINT_P: /* Print current file */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleP[NULL] ? szFileTitleP : szUntitled); return NULL; case IDM_PRINT_C: /* Print current file */ if (!get_course(hWnd, &courses, c_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleC[NULL] ? szFileTitleC : szUntitled); return NULL; case IDM_EXIT: /* Send a close message, and exit the program */ SendMessage(hWnd, WM_CLOSE, NULL, 0L); return NULL; case IDM_UNDO: /* Check for undo status */ SendMessage(GetFocus(), WM_UNDO, 0, 0L); return 0; case IDM_CUT: /* Send cut message */ SendMessage(GetFocus(), WM_CUT, 0, 0L); return 0; case IDM_COPY: /* Send copy message */ SendMessage(GetFocus(), WM_COPY, 0, 0L); return 0; case IDM_PASTE: /* Send paste message */ SendMessage(GetFocus(), WM_PASTE, 0, 0L); return 0; case IDM_CLEAR: /* Send clear message */ SendMessage(GetFocus(), WM_CLEAR, 0, 0L); return 0; case IDM_P_ADD: if (AddPlayer(hWnd, &players, &p_index, &r_index)) bNeedSaveP = TRUE; return NULL; case IDM_R_ADD: if (AddRound(hWnd, &players, &p_index, &r_index, &r_last)) bNeedSaveP = TRUE; return NULL; case IDM_C_ADD: if (AddCourse(hWnd, &courses, &c_index)) bNeedSaveC = TRUE; return NULL; case IDM_P_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player, players.player_numb+1, sizeof(players.player[0]), compare_player); bNeedSaveP = TRUE; p_index = r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_R_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player[p_index].p_scores.history, players.player[p_index].p_scores.round_numb+1, sizeof(players.player[p_index].p_scores.history[0]), compare_round); bNeedSaveP = TRUE; r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_C_SORT: if (!get_course(hWnd, &courses, c_index)) return NULL; qsort(courses.course, courses.course_numb, sizeof(courses.course[0]), compare_course); bNeedSaveC = TRUE; c_index = 0; show_course(hWnd, &courses, &c_index); return NULL; case IDM_P_DELETE: if (players.player_numb > -1) { GetDlgItemText(hWnd, IDD_PLAST, (players).player[p_index].p_last, LAST_NAME_LENGTH+1); GetDlgItemText(hWnd, IDD_PFIRST, (players).player[p_index].p_first, FIRST_NAME_LENGTH+1); lstrcpy(szDelete, "Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_first); lstrcat(szDelete, " "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_last); if (IDYES == MessageBox(hWnd, szDelete, "Delete Player", MB_YESNO | MB_ICONQUESTION)) { bNeedSaveP = TRUE; delete_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); } } /* if */ return NULL; case IDM_R_DELETE: if (players.player[p_index].p_scores.round_numb > -1) { convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); lstrcpy(szDelete, (LPSTR)"Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lstrcat(szDelete, " "); lstrcat(szDelete, szDate); if (IDYES == MessageBox(hWnd, szDelete, "Delete Round", MB_YESNO | MB_ICONQUESTION)) { delete_round(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); bNeedSaveP = TRUE; } /* if */ } /* if */ return NULL; case IDM_C_DELETE: if (courses.course_numb > -1) { GetDlgItemText(hWnd, IDD_CNAME, (courses).course[c_index].c_name, COURSE_NAME_LENGTH+1); lstrcpy(szc_name, (courses).course[c_index].c_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)DeleteCourseDlgProc, hInst); DialogBox(hInst, "DELETEC", hWnd, lpfnGenericDlgProc); FreeProcInstance(DeleteCourseDlgProc); /* Release memory */ if (bYesNo == IDYES) { bNeedSaveC = TRUE; delete_course(&courses, &c_index); if (bDeleteRounds && delete_rounds(&players, szc_name)) { bNeedSaveP = TRUE; show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, TRUE); } /* if */ show_course(hWnd, &courses, &c_index); } /* if */ } /* if */ return NULL; case IDD_RLIST: switch(HIWORD(lParam)) { case LBN_DBLCLK: if ((players.player_numb == -1) || (players.player[p_index].p_scores.round_numb == -1)) return NULL; lstrcpy(szNDTitle, "Change Course / Name Date"); convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); get_date_elements(szDate, szmm, szdd, szyy); lstrcpy(szc_name, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)NameDateDlgProc, hInst); DialogBox(hInst, "NAMEDATE", hWnd, lpfnGenericDlgProc); FreeProcInstance(NameDateDlgProc); /* Release memory */ if (bNameDate == IDOK) { bNeedSaveP = TRUE; players.player[p_index].p_scores.history[r_index].date = string_to_date(szmm, szdd, szyy); lstrcpy((LPSTR)players.player[p_index].p_scores.history[r_index].course_name, szc_name); show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, FALSE); } /* if */ return NULL; case LBN_SELCHANGE: if ((int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L) == r_index) break; if (!get_round(hWnd, &players, p_index, r_index)) { SendMessage(hWndRList, LB_SETCURSEL, r_index, 0L); return NULL; } r_index = (int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L); if (r_index != LB_ERR && r_index != r_last) { show_round(hWnd, players.player[p_index].p_scores.history[r_index].score); r_last = r_index; } /* if */ return NULL; } /* switch (HIWORD(lParam)) */ return NULL; default: return FALSE; } /* switch (wParam) */ } /* CommandHandler */