From 73a4b058b3f433ff66de53ab641bd8d9de6fc462 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 20 Apr 2024 13:21:39 +0200 Subject: Revised com_revert() --- FICS/obsproc.c | 97 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/FICS/obsproc.c b/FICS/obsproc.c index a9cf6d4..42576a2 100644 --- a/FICS/obsproc.c +++ b/FICS/obsproc.c @@ -1308,50 +1308,63 @@ PUBLIC int com_backward(int p, param_list param) return COM_OK; } -PUBLIC int com_revert(int p, param_list param) +PUBLIC int +com_revert(int p, param_list param) { - int nHalfMoves = 1; - int g, i; - int p1; - unsigned now; + int g, i; + int nHalfMoves = 1; + int p1; + unsigned int now; + + if (!(parray[p].game >= 0 && garray[parray[p].game].status == + GAME_EXAMINE)) { + pprintf(p, "You are not examining any games.\n"); + return COM_OK; + } - if (!((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE))) { - pprintf(p, "You are not examining any games.\n"); - return COM_OK; - } - g = parray[p].game; - nHalfMoves = garray[g].numHalfMoves - garray[g].revertHalfMove; - if (nHalfMoves == 0) { - pprintf(p, "Already at mainline.\n"); - return COM_OK; - } - if (nHalfMoves < 0) { /* eek - should NEVER happen! */ - fprintf(stderr, "OUCH! in com_revert: nHalfMoves < 0\n"); - return COM_OK; - } - for (p1 = 0; p1 < p_num; p1++) { - if (parray[p1].status != PLAYER_PROMPT) - continue; - if (player_is_observe(p1, g) || parray[p1].game == g) { - pprintf(p1, "%s reverts to mainline.\n", parray[p].name); - } - } - for (i = 0; i < nHalfMoves; i++) { - backup_move(g, REL_EXAMINE);/* should never return error */ - } - /* roll back time */ - if (garray[g].game_state.onMove == WHITE) { - garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime); - } else { - garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime); - } - now = tenth_secs(); - if (garray[g].numHalfMoves == 0) - garray[g].timeOfStart = now; - garray[g].lastMoveTime = now; - garray[g].lastDecTime = now; - send_boards(g); - return COM_OK; + g = parray[p].game; + nHalfMoves = garray[g].numHalfMoves - garray[g].revertHalfMove; + + if (nHalfMoves == 0) { + pprintf(p, "Already at mainline.\n"); + return COM_OK; + } + + if (nHalfMoves < 0) { // eek - should NEVER happen! + fprintf(stderr, "OUCH! in %s: nHalfMoves < 0\n", __func__); + return COM_OK; + } + + for (p1 = 0; p1 < p_num; p1++) { + if (parray[p1].status != PLAYER_PROMPT) + continue; + if (player_is_observe(p1, g) || parray[p1].game == g) { + pprintf(p1, "%s reverts to mainline.\n", + parray[p].name); + } + } + + for (i = 0; i < nHalfMoves; i++) + backup_move(g, REL_EXAMINE); + + // roll back time + if (garray[g].game_state.onMove == WHITE) { + garray[g].wTime += (garray[g].lastDecTime - + garray[g].lastMoveTime); + } else { + garray[g].bTime += (garray[g].lastDecTime - + garray[g].lastMoveTime); + } + + now = tenth_secs(); + + if (garray[g].numHalfMoves == 0) + garray[g].timeOfStart = now; + garray[g].lastMoveTime = now; + garray[g].lastDecTime = now; + + send_boards(g); + return COM_OK; } PUBLIC int -- cgit v1.2.3