]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigame/pp.qc
Wrap all status and bitflag checks with parentesis to avoid possible obscure bugs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigame / pp.qc
index 5a46aa91452f1ef37882514be28d20b52f48ae8e..9a7e54234d7bab0aa48aa57c811123fd872b400e 100644 (file)
@@ -11,7 +11,7 @@ const int PP_TURN_TEAM1 = 0x0001;
 const int PP_TURN_TEAM2 = 0x0002;
 const int PP_TURN_TEAM  = 0x000f; // turn team mask
 
-const int PP_BLOCKED_TEAM = 5; // there won't ever be a 5th team, so we can abuse this
+const int PP_SPECTATOR_TEAM = 255; // must be above max teams and equal to or below 255
 
 const int PP_LET_CNT = 7;
 const int PP_NUM_CNT = 7;
@@ -225,7 +225,7 @@ int pp_server_event(entity minigame, string event, ...)
                        int pl_num = minigame_count_players(minigame);
 
                        // Don't allow more than 2 players
-                       if(pl_num >= 2) { return false; }
+                       if(pl_num >= 2) { return PP_SPECTATOR_TEAM; }
 
                        // Get the right team
                        if(minigame.minigame_players)
@@ -236,12 +236,18 @@ int pp_server_event(entity minigame, string event, ...)
                }
                case "cmd":
                {
+                       entity player = ...(0,entity);
+                       bool event_blocked = (player.team == PP_SPECTATOR_TEAM);
                        switch(argv(0))
                        {
                                case "move":
+                                       if(event_blocked)
+                                               return true;
                                        pp_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null );
                                        return true;
                                case "next":
+                                       if(event_blocked)
+                                               return true;
                                        pp_next_match(minigame,...(0,entity));
                                        return true;
                        }
@@ -388,17 +394,20 @@ void pp_hud_status(vector pos, vector mySize)
        vector mypos;
        vector tile_size = '48 48 0';
 
-       mypos = pos;
-       if ( (active_minigame.minigame_flags&PP_TURN_TEAM) == 2 )
-               mypos_y  += player_fontsize_y + ts_y;
-       drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
-       mypos_y += player_fontsize_y;
-       drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
+       if(minigame_self.team != PP_SPECTATOR_TEAM)
+       {
+               mypos = pos;
+               if ( (active_minigame.minigame_flags&PP_TURN_TEAM) == 2 )
+                       mypos_y  += player_fontsize_y + ts_y;
+               drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
+               mypos_y += player_fontsize_y;
+               drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
+       }
 
        entity e;
        FOREACH_MINIGAME_ENTITY(e)
        {
-               if ( e.classname == "minigame_player" )
+               if ( e.classname == "minigame_player" && e.team != PP_SPECTATOR_TEAM )
                {
                        vector tile_color = '1 1 1';
                        switch(e.team)
@@ -434,13 +443,16 @@ void pp_hud_status(vector pos, vector mySize)
 // Turn a set of flags into a help message
 string pp_turn_to_string(int turnflags)
 {
+       if(minigame_self.team == PP_SPECTATOR_TEAM)
+               return _("You are spectating");
+
        if ( turnflags & PP_TURN_DRAW )
                return _("Draw");
 
        if ( turnflags & PP_TURN_WIN )
        {
                // translator-friendly messages composed of 2 existing messages
-               if ( (turnflags&PP_TURN_TEAM) != minigame_self.team )
+               if ( (turnflags & PP_TURN_TEAM) != minigame_self.team )
                        return strcat(_("You lost the game!"), "\n", _("Select \"^1Next Match^7\" on the menu for a rematch!"));
                return strcat(_("You win!"), "\n", _("Select \"^1Next Match^7\" on the menu to start a new match!"));
        }
@@ -495,13 +507,18 @@ int pp_client_event(entity minigame, string event, ...)
                        return false;
                }
                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_blocked)
+                                                       return true;
                                                if ( ! pp_curr_pos )
                                                        pp_set_curr_pos("a3");
                                                else
@@ -509,6 +526,8 @@ int pp_client_event(entity minigame, string event, ...)
                                                return true;
                                        case K_LEFTARROW:
                                        case K_KP_LEFTARROW:
+                                               if (event_blocked)
+                                                       return true;
                                                if ( ! pp_curr_pos )
                                                        pp_set_curr_pos("c3");
                                                else
@@ -516,6 +535,8 @@ int pp_client_event(entity minigame, string event, ...)
                                                return true;
                                        case K_UPARROW:
                                        case K_KP_UPARROW:
+                                               if (event_blocked)
+                                                       return true;
                                                if ( ! pp_curr_pos )
                                                        pp_set_curr_pos("a1");
                                                else
@@ -523,6 +544,8 @@ int pp_client_event(entity minigame, string event, ...)
                                                return true;
                                        case K_DOWNARROW:
                                        case K_KP_DOWNARROW:
+                                               if (event_blocked)
+                                                       return true;
                                                if ( ! pp_curr_pos )
                                                        pp_set_curr_pos("a3");
                                                else
@@ -531,6 +554,8 @@ int pp_client_event(entity minigame, string event, ...)
                                        case K_ENTER:
                                        case K_KP_ENTER:
                                        case K_SPACE:
+                                               if (event_blocked)
+                                                       return true;
                                                pp_make_move(minigame);
                                                return true;
                                }
@@ -542,6 +567,7 @@ int pp_client_event(entity minigame, string event, ...)
                {
                        if(...(0,int) == K_MOUSE1)
                        {
+                               pp_client_event(minigame, "mouse_moved");
                                pp_make_move(minigame);
                                return true;
                        }