Allow substitution of engines during tournament
[xboard.git] / winboard / wsettings.c
index 11de72b..bfad588 100644 (file)
@@ -486,6 +486,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
                if( activeList[j].type  == SaveButton)\r
                     GetOptionValues(hDlg, activeCps, activeList);\r
                else if( activeList[j].type  != Button) break;\r
+               else if( !activeCps ) { (*(ButtonCallback*) activeList[j].target)(hDlg); break; }\r
                snprintf(buf, MSG_SIZ, "option %s\n", activeList[j].name);\r
                SendToProgram(buf, activeCps);\r
            }\r
@@ -694,8 +695,35 @@ int MatchOK()
 {\r
     if(autoinc) appData.loadGameIndex = appData.loadPositionIndex = -(twice + 1);\r
     if(swiss) { appData.defaultMatchGames = 1; appData.tourneyType = -1; }\r
-    if(CreateTourney(tfName)) MatchEvent(2); else return !appData.participants[0];\r
-    return 1;\r
+    if(CreateTourney(tfName) && !matchMode) { // CreateTourney reloads original settings if file already existed\r
+       MatchEvent(2);\r
+       return 1; // close dialog\r
+    }\r
+    return matchMode || !appData.participants[0]; // if we failed to create and are not in playing, forbid popdown if there are participants\r
+}\r
+\r
+char *GetParticipants(HWND hDlg)\r
+{\r
+    int len = GetWindowTextLength(GetDlgItem(hDlg, 2001+2*9)) + 1;\r
+    char *participants,*p, *q;\r
+    if(len < 4) return NULL; // box is empty (enough)\r
+    participants = (char*) malloc(len);\r
+    GetDlgItemText(hDlg, 2001+2*9, participants, len );\r
+    p = q = participants;\r
+    while(*p++ = *q++) if(p[-1] == '\r') p--;\r
+    return participants;\r
+}\r
+\r
+void ReplaceParticipant(HWND hDlg)\r
+{\r
+    char *participants = GetParticipants(hDlg);\r
+    Substitute(participants, TRUE);\r
+}\r
+       \r
+void UpgradeParticipant(HWND hDlg)\r
+{\r
+    char *participants = GetParticipants(hDlg);\r
+    Substitute(participants, FALSE);\r
 }\r
 \r
 Option tourneyOptions[] = {\r
@@ -719,6 +747,8 @@ Option tourneyOptions[] = {
   { 0,  0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind after (0 = never):") },\r
   { 0,  0,          0, NULL, (void*) &twice, "", NULL, CheckBox, N_("Use each line/position twice") },\r
   { 0,  0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Games (ms):") },\r
+  { 0,  0,          0, NULL, (void*) &ReplaceParticipant, "", NULL, Button, N_("Replace Engine") },\r
+  { 0,  0,          0, NULL, (void*) &UpgradeParticipant, "", NULL, Button, N_("Upgrade Engine") },\r
   { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }\r
 };\r
 \r