From e7fcfe0c55e89965d3f15adbe1deb1784159351a Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 29 Dec 2020 16:38:14 +0100 Subject: [PATCH] Minigames: don't let the player interact with minigame menu via keyboard while waiting for the opponent's move --- qcsrc/common/minigames/minigame/bd.qc | 24 ++-- qcsrc/common/minigames/minigame/c4.qc | 14 ++- qcsrc/common/minigames/minigame/nmm.qc | 143 ++++++++++++------------ qcsrc/common/minigames/minigame/pong.qc | 67 +++++------ qcsrc/common/minigames/minigame/pp.qc | 14 ++- qcsrc/common/minigames/minigame/ps.qc | 13 ++- qcsrc/common/minigames/minigame/ttt.qc | 14 ++- 7 files changed, 152 insertions(+), 137 deletions(-) diff --git a/qcsrc/common/minigames/minigame/bd.qc b/qcsrc/common/minigames/minigame/bd.qc index 253dd612e..0744c0b37 100644 --- a/qcsrc/common/minigames/minigame/bd.qc +++ b/qcsrc/common/minigames/minigame/bd.qc @@ -1251,31 +1251,33 @@ int bd_client_event(entity minigame, string event, ...) case "key_pressed": case "key_released": { - if(minigame.minigame_flags & BD_TURN_MOVE) + bool event_blocked = ((event == "key_released") + || !(minigame.minigame_flags & BD_TURN_MOVE)); + if (!(minigame.minigame_flags & BD_TURN_WIN) && !(minigame.minigame_flags & BD_TURN_LOSS)) { switch ( ...(0,int) ) { case K_RIGHTARROW: case K_KP_RIGHTARROW: - if (event == "key_released") + if (event_blocked) return true; bd_make_move(minigame, "r"); return true; case K_LEFTARROW: case K_KP_LEFTARROW: - if (event == "key_released") + if (event_blocked) return true; bd_make_move(minigame, "l"); return true; case K_UPARROW: case K_KP_UPARROW: - if (event == "key_released") + if (event_blocked) return true; bd_make_move(minigame, "u"); return true; case K_DOWNARROW: case K_KP_DOWNARROW: - if (event == "key_released") + if (event_blocked) return true; bd_make_move(minigame, "d"); return true; @@ -1288,7 +1290,7 @@ int bd_client_event(entity minigame, string event, ...) { case K_RIGHTARROW: case K_KP_RIGHTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! bd_curr_pos ) bd_set_curr_pos("a3"); @@ -1297,7 +1299,7 @@ int bd_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! bd_curr_pos ) bd_set_curr_pos("c3"); @@ -1306,7 +1308,7 @@ int bd_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! bd_curr_pos ) bd_set_curr_pos("a1"); @@ -1315,7 +1317,7 @@ int bd_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! bd_curr_pos ) bd_set_curr_pos("a3"); @@ -1324,12 +1326,12 @@ int bd_client_event(entity minigame, string event, ...) return true; case K_ENTER: case K_KP_ENTER: - if (event == "key_released") + if (event_blocked) return true; bd_editor_make_move(minigame, ""); return true; case K_SPACE: - if (event == "key_released") + if (event_blocked) return true; if(bd_change_dozer_angle(minigame)) return true; diff --git a/qcsrc/common/minigames/minigame/c4.qc b/qcsrc/common/minigames/minigame/c4.qc index 8c12f8dfb..665f72f9c 100644 --- a/qcsrc/common/minigames/minigame/c4.qc +++ b/qcsrc/common/minigames/minigame/c4.qc @@ -424,13 +424,15 @@ int c4_client_event(entity minigame, string event, ...) case "key_pressed": case "key_released": { - if((minigame.minigame_flags & C4_TURN_TEAM) == minigame_self.team) + bool event_blocked = ((event == "key_released") + || ((minigame.minigame_flags & C4_TURN_TEAM) != minigame_self.team)); + if (!(minigame.minigame_flags & C4_TURN_WIN) && !(minigame.minigame_flags & C4_TURN_DRAW)) { switch ( ...(0,int) ) { case K_RIGHTARROW: case K_KP_RIGHTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! c4_curr_pos ) c4_set_curr_pos(c4_get_lowest_tile(minigame, "a3")); @@ -439,7 +441,7 @@ int c4_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! c4_curr_pos ) c4_set_curr_pos(c4_get_lowest_tile(minigame, "c3")); @@ -453,7 +455,7 @@ int c4_client_event(entity minigame, string event, ...) return true; /*case K_UPARROW: case K_KP_UPARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! c4_curr_pos ) c4_set_curr_pos("a1"); @@ -462,7 +464,7 @@ int c4_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! c4_curr_pos ) c4_set_curr_pos("a3"); @@ -472,7 +474,7 @@ int c4_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: - if (event == "key_released") + if (event_blocked) return true; c4_make_move(minigame); return true; diff --git a/qcsrc/common/minigames/minigame/nmm.qc b/qcsrc/common/minigames/minigame/nmm.qc index bc049ca8e..18ed02009 100644 --- a/qcsrc/common/minigames/minigame/nmm.qc +++ b/qcsrc/common/minigames/minigame/nmm.qc @@ -632,85 +632,90 @@ int nmm_client_event(entity minigame, string event, ...) nmm_kill_tiles(minigame); strfree(minigame.message); } - else if ( (event == "key_pressed" || event == "key_released") && (minigame.minigame_flags&NMM_TURN_TEAM) == minigame_self.team ) + else if ( (event == "key_pressed" || event == "key_released") ) { - switch ( ...(0,int) ) + bool event_blocked = ((event == "key_released") + || ((minigame.minigame_flags & NMM_TURN_TEAM) != minigame_self.team)); + if (!(minigame.minigame_flags & NMM_TURN_WIN)) { - case K_RIGHTARROW: - case K_KP_RIGHTARROW: - if (event == "key_released") - return true; - if ( ! nmm_currtile ) - nmm_currtile = nmm_find_tile(active_minigame,"a7"); - else - { - string tileid = nmm_currtile.netname; - nmm_currtile = NULL; - while ( !nmm_currtile ) + switch ( ...(0,int) ) + { + case K_RIGHTARROW: + case K_KP_RIGHTARROW: + if (event_blocked) + return true; + if ( ! nmm_currtile ) + nmm_currtile = nmm_find_tile(active_minigame,"a7"); + else { - tileid = minigame_relative_tile(tileid,1,0,7,7); - nmm_currtile = nmm_find_tile(active_minigame,tileid); + string tileid = nmm_currtile.netname; + nmm_currtile = NULL; + while ( !nmm_currtile ) + { + tileid = minigame_relative_tile(tileid,1,0,7,7); + nmm_currtile = nmm_find_tile(active_minigame,tileid); + } } - } - return 1; - case K_LEFTARROW: - case K_KP_LEFTARROW: - if (event == "key_released") - return true; - if ( ! nmm_currtile ) - nmm_currtile = nmm_find_tile(active_minigame,"g7"); - else - { - string tileid = nmm_currtile.netname; - nmm_currtile = NULL; - while ( !nmm_currtile ) + return 1; + case K_LEFTARROW: + case K_KP_LEFTARROW: + if (event_blocked) + return true; + if ( ! nmm_currtile ) + nmm_currtile = nmm_find_tile(active_minigame,"g7"); + else { - tileid = minigame_relative_tile(tileid,-1,0,7,7); - nmm_currtile = nmm_find_tile(active_minigame,tileid); + string tileid = nmm_currtile.netname; + nmm_currtile = NULL; + while ( !nmm_currtile ) + { + tileid = minigame_relative_tile(tileid,-1,0,7,7); + nmm_currtile = nmm_find_tile(active_minigame,tileid); + } } - } - return 1; - case K_UPARROW: - case K_KP_UPARROW: - if (event == "key_released") - return true; - if ( ! nmm_currtile ) - nmm_currtile = nmm_find_tile(active_minigame,"a1"); - else - { - string tileid = nmm_currtile.netname; - nmm_currtile = NULL; - while ( !nmm_currtile ) + return 1; + case K_UPARROW: + case K_KP_UPARROW: + if (event_blocked) + return true; + if ( ! nmm_currtile ) + nmm_currtile = nmm_find_tile(active_minigame,"a1"); + else { - tileid = minigame_relative_tile(tileid,0,1,7,7); - nmm_currtile = nmm_find_tile(active_minigame,tileid); + string tileid = nmm_currtile.netname; + nmm_currtile = NULL; + while ( !nmm_currtile ) + { + tileid = minigame_relative_tile(tileid,0,1,7,7); + nmm_currtile = nmm_find_tile(active_minigame,tileid); + } } - } - return 1; - case K_DOWNARROW: - case K_KP_DOWNARROW: - if (event == "key_released") - return true; - if ( ! nmm_currtile ) - nmm_currtile = nmm_find_tile(active_minigame,"a7"); - else - { - string tileid = nmm_currtile.netname; - nmm_currtile = NULL; - while ( !nmm_currtile ) + return 1; + case K_DOWNARROW: + case K_KP_DOWNARROW: + if (event_blocked) + return true; + if ( ! nmm_currtile ) + nmm_currtile = nmm_find_tile(active_minigame,"a7"); + else { - tileid = minigame_relative_tile(tileid,0,-1,7,7); - nmm_currtile = nmm_find_tile(active_minigame,tileid); + string tileid = nmm_currtile.netname; + nmm_currtile = NULL; + while ( !nmm_currtile ) + { + tileid = minigame_relative_tile(tileid,0,-1,7,7); + nmm_currtile = nmm_find_tile(active_minigame,tileid); + } } - } - return 1; - case K_ENTER: - case K_KP_ENTER: - case K_SPACE: - if (event == "key_released") - return true; - nmm_make_move(minigame); - return 1; + return 1; + case K_ENTER: + case K_KP_ENTER: + case K_SPACE: + if (event_blocked) + return true; + nmm_make_move(minigame); + return 1; + } } return 0; } diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index 5ae108660..30bdd8066 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -621,39 +621,40 @@ int pong_client_event(entity minigame, string event, ...) } case "key_pressed": case "key_released": - switch ( ...(0,int) ) - { - case K_UPARROW: - case K_KP_UPARROW: - case K_LEFTARROW: - case K_KP_LEFTARROW: - if (event == "key_pressed") - { - //minigame_cmd("+moved"); - pong_keys_pressed |= PONG_KEY_DECREASE; - } - else - { - //minigame_cmd("-moved"); - pong_keys_pressed &= ~PONG_KEY_DECREASE; - } - return true; - case K_DOWNARROW: - case K_KP_DOWNARROW: - case K_RIGHTARROW: - case K_KP_RIGHTARROW: - if (event == "key_pressed") - { - //minigame_cmd("+movei"); - pong_keys_pressed |= PONG_KEY_INCREASE; - } - else - { - //minigame_cmd("-movei"); - pong_keys_pressed &= ~PONG_KEY_INCREASE; - } - return true; - } + if ((minigame.minigame_flags & PONG_STATUS_PLAY)) + switch ( ...(0,int) ) + { + case K_UPARROW: + case K_KP_UPARROW: + case K_LEFTARROW: + case K_KP_LEFTARROW: + if (event == "key_pressed") + { + //minigame_cmd("+moved"); + pong_keys_pressed |= PONG_KEY_DECREASE; + } + else + { + //minigame_cmd("-moved"); + pong_keys_pressed &= ~PONG_KEY_DECREASE; + } + return true; + case K_DOWNARROW: + case K_KP_DOWNARROW: + case K_RIGHTARROW: + case K_KP_RIGHTARROW: + if (event == "key_pressed") + { + //minigame_cmd("+movei"); + pong_keys_pressed |= PONG_KEY_INCREASE; + } + else + { + //minigame_cmd("-movei"); + pong_keys_pressed &= ~PONG_KEY_INCREASE; + } + return true; + } return false; case "network_receive": { diff --git a/qcsrc/common/minigames/minigame/pp.qc b/qcsrc/common/minigames/minigame/pp.qc index 91b4142f4..7204ddf8d 100644 --- a/qcsrc/common/minigames/minigame/pp.qc +++ b/qcsrc/common/minigames/minigame/pp.qc @@ -497,13 +497,15 @@ int pp_client_event(entity minigame, string event, ...) case "key_pressed": case "key_released": { - if((minigame.minigame_flags & PP_TURN_TEAM) == minigame_self.team) + bool event_blocked = ((event == "key_released") + || ((minigame.minigame_flags & PP_TURN_TEAM) != minigame_self.team)); + if (!(minigame.minigame_flags & PP_TURN_WIN) && !(minigame.minigame_flags & PP_TURN_DRAW)) { switch ( ...(0,int) ) { case K_RIGHTARROW: case K_KP_RIGHTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! pp_curr_pos ) pp_set_curr_pos("a3"); @@ -512,7 +514,7 @@ int pp_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! pp_curr_pos ) pp_set_curr_pos("c3"); @@ -521,7 +523,7 @@ int pp_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! pp_curr_pos ) pp_set_curr_pos("a1"); @@ -530,7 +532,7 @@ int pp_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! pp_curr_pos ) pp_set_curr_pos("a3"); @@ -540,7 +542,7 @@ int pp_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: - if (event == "key_released") + if (event_blocked) return true; pp_make_move(minigame); return true; diff --git a/qcsrc/common/minigames/minigame/ps.qc b/qcsrc/common/minigames/minigame/ps.qc index 7dc19ee63..b60a6a7fc 100644 --- a/qcsrc/common/minigames/minigame/ps.qc +++ b/qcsrc/common/minigames/minigame/ps.qc @@ -543,13 +543,14 @@ int ps_client_event(entity minigame, string event, ...) case "key_pressed": case "key_released": { - //if((minigame.minigame_flags & PS_TURN_TEAM) == minigame_self.team) + bool event_blocked = (event == "key_released"); + if (!(minigame.minigame_flags & PS_TURN_WIN) && !(minigame.minigame_flags & PS_TURN_DRAW)) { switch ( ...(0,int) ) { case K_RIGHTARROW: case K_KP_RIGHTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ps_curr_pos ) ps_set_curr_pos("a3"); @@ -558,7 +559,7 @@ int ps_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ps_curr_pos ) ps_set_curr_pos("c3"); @@ -567,7 +568,7 @@ int ps_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ps_curr_pos ) ps_set_curr_pos("a1"); @@ -576,7 +577,7 @@ int ps_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ps_curr_pos ) ps_set_curr_pos("a3"); @@ -586,7 +587,7 @@ int ps_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: - if (event == "key_released") + if (event_blocked) return true; ps_make_move(minigame); return true; diff --git a/qcsrc/common/minigames/minigame/ttt.qc b/qcsrc/common/minigames/minigame/ttt.qc index 42e844bd3..d578aa961 100644 --- a/qcsrc/common/minigames/minigame/ttt.qc +++ b/qcsrc/common/minigames/minigame/ttt.qc @@ -567,13 +567,15 @@ int ttt_client_event(entity minigame, string event, ...) case "key_pressed": case "key_released": { - if((minigame.minigame_flags & TTT_TURN_TEAM) == minigame_self.team) + bool event_blocked = ((event == "key_released") + || ((minigame.minigame_flags & TTT_TURN_TEAM) != minigame_self.team)); + if (!(minigame.minigame_flags & TTT_TURN_WIN) && !(minigame.minigame_flags & TTT_TURN_DRAW)) { switch ( ...(0,int) ) { case K_RIGHTARROW: case K_KP_RIGHTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("a3"); @@ -582,7 +584,7 @@ int ttt_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("c3"); @@ -591,7 +593,7 @@ int ttt_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("a1"); @@ -600,7 +602,7 @@ int ttt_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: - if (event == "key_released") + if (event_blocked) return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("a3"); @@ -610,7 +612,7 @@ int ttt_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: - if (event == "key_released") + if (event_blocked) return true; ttt_make_move(minigame); return true; -- 2.39.2