]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigame/bd.qc
Fix error spam that occurs when standing in the way of rotating doors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigame / bd.qc
index 253dd612e396fa3a0762afe65e82b28881d51e26..635d1b8d5328e7dfcdb34582f4ac887d4fa67e8b 100644 (file)
@@ -21,6 +21,7 @@ const int BD_NUM_CNT = 20;
 const int BD_TILE_SIZE = 20;
 
 const int BD_TEAMS = 1;
+const int BD_SPECTATOR_TEAM = 255; // must be above max teams and equal to or below 255
 
 .int bd_dir;
 
@@ -881,30 +882,44 @@ int bd_server_event(entity minigame, string event, ...)
                {
                        int pl_num = minigame_count_players(minigame);
 
-                       if(pl_num >= BD_TEAMS) { return false; }
+                       if(pl_num >= BD_TEAMS) { return BD_SPECTATOR_TEAM; }
 
                        return 1;
                }
                case "cmd":
                {
+                       entity player = ...(0,entity);
+                       bool event_blocked = (player.team == BD_SPECTATOR_TEAM);
                        switch(argv(0))
                        {
                                case "move":
+                                       if(event_blocked)
+                                               return true;
                                        bd_do_move(minigame, ...(0,entity), ((...(1,int)) >= 2 ? argv(1) : string_null), ((...(1,int)) >= 3 ? argv(2) : string_null), ((...(1,int)) >= 4 ? argv(3) : string_null));
                                        return true;
                                case "next":
+                                       if(event_blocked)
+                                               return true;
                                        bd_next_match(minigame,...(0,entity), ((...(1,int) >= 2 ? argv(1) : string_null)));
                                        return true;
                                case "restart":
+                                       if(event_blocked)
+                                               return true;
                                        bd_restart_match(minigame,...(0,entity));
                                        return true;
                                case "edit":
+                                       if(event_blocked)
+                                               return true;
                                        bd_activate_editor(minigame,...(0,entity));
                                        return true;
                                case "save":
+                                       if(event_blocked)
+                                               return true;
                                        bd_close_editor(minigame,...(0,entity));
                                        return true;
                                case "fill":
+                                       if(event_blocked)
+                                               return true;
                                        bd_do_fill(minigame, ...(0,entity), ((...(1,int)) >= 2 ? argv(1) : string_null), ((...(1,int)) >= 3 ? argv(2) : string_null));
                                        return true;
                        }
@@ -1124,15 +1139,18 @@ void bd_hud_status(vector pos, vector mySize)
        vector mypos;
        vector tile_size = '48 48 0';
 
-       mypos = pos;
-       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 != BD_SPECTATOR_TEAM)
+       {
+               mypos = pos;
+               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 != BD_SPECTATOR_TEAM )
                {
                        mypos = pos;
                        minigame_drawcolorcodedstring_trunc(mySize_x,mypos,
@@ -1143,9 +1161,10 @@ void bd_hud_status(vector pos, vector mySize)
                        string thepiece = "bd/dozer";
                        if(active_minigame.minigame_flags & BD_TURN_EDIT)
                                thepiece = bd_get_tile_pic(bd_curr_tile);
-                       drawpic( mypos,
+                       const float tile_scale = 0.7;
+                       drawpic( mypos + tile_size * 0.5 * (1 - tile_scale),
                                        minigame_texture(thepiece),
-                                       tile_size * 0.7, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL );
+                                       tile_size * tile_scale, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL );
 
                        mypos_x += tile_size_x;
 
@@ -1158,6 +1177,9 @@ void bd_hud_status(vector pos, vector mySize)
 // Turn a set of flags into a help message
 string bd_turn_to_string(int turnflags)
 {
+       if(minigame_self.team == BD_SPECTATOR_TEAM)
+               return _("You are spectating");
+
        if ( turnflags & BD_TURN_LOSS )
                return _("Better luck next time!");
 
@@ -1251,31 +1273,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) || (minigame_self.team == BD_SPECTATOR_TEAM));
+                       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 +1312,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 +1321,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 +1330,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 +1339,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 +1348,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;
@@ -1344,16 +1368,18 @@ int bd_client_event(entity minigame, string event, ...)
                }
                case "mouse_pressed":
                {
-                       if(minigame.minigame_flags & BD_TURN_EDIT)
+                       if((minigame.minigame_flags & BD_TURN_EDIT) && minigame_self.team != BD_SPECTATOR_TEAM)
                        {
                                if(...(0,int) == K_MOUSE1)
                                {
+                                       bd_client_event(minigame, "mouse_moved");
                                        bd_editor_make_move(minigame, "");
                                        return true;
                                }
 
                                if(...(0,int) == K_MOUSE2)
                                {
+                                       bd_client_event(minigame, "mouse_moved");
                                        bd_editor_fill(minigame);
                                        return true;
                                }
@@ -1363,7 +1389,7 @@ int bd_client_event(entity minigame, string event, ...)
                }
                case "mouse_moved":
                {
-                       if(minigame.minigame_flags & BD_TURN_EDIT)
+                       if((minigame.minigame_flags & BD_TURN_EDIT) && minigame_self.team != BD_SPECTATOR_TEAM)
                        {
                                vector mouse_pos = minigame_hud_normalize(mousepos,bd_boardpos,bd_boardsize);
                                bd_set_curr_pos(minigame_tile_name(mouse_pos,BD_LET_CNT,BD_NUM_CNT));