]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigame/c4.qc
Merge branch 'bones_was_here/strafehud_jumpheight' into Juhu/strafehud-fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigame / c4.qc
index 86c9f1889fd5ecc803b7789442a6cc35d1ce6046..6727655bc52853836e8b081d11e11980f056ec47 100644 (file)
@@ -1,5 +1,5 @@
 #include "c4.qh"
-REGISTER_MINIGAME(c4, "Connect Four");
+REGISTER_MINIGAME(c4, _("Connect Four"));
 
 const float C4_TURN_PLACE = 0x0100; // player has to place a piece on the board
 const float C4_TURN_WIN   = 0x0200; // player has won
@@ -18,6 +18,7 @@ const int C4_MAX_TILES = 42;
 const int C4_TILE_SIZE = 8;
 
 const int C4_TEAMS = 2;
+const int C4_SPECTATOR_TEAM = 255; // must be above max teams and equal to or below 255
 
 .int c4_npieces; // (minigame) number of pieces on the board (simplifies checking a draw)
 .int c4_nexteam; // (minigame) next team (used to change the starting team on following matches)
@@ -163,7 +164,7 @@ void c4_move(entity minigame, entity player, string pos )
                if ( c4_valid_tile(pos) )
                if ( !c4_find_piece(minigame,pos) )
                {
-                       entity piece = msle_spawn(minigame,"minigame_board_piece");
+                       entity piece = msle_spawn(minigame,new(minigame_board_piece));
                        piece.team = player.team;
                        piece.netname = strzone(pos);
                        minigame_server_sendflags(piece,MINIG_SF_ALL);
@@ -201,7 +202,7 @@ int c4_server_event(entity minigame, string event, ...)
                        while( (e = findentity(e, owner, minigame)) )
                        if(e.classname == "minigame_board_piece")
                        {
-                               if(e.netname) { strunzone(e.netname); }
+                               strfree(e.netname);
                                delete(e);
                        }
                        return false;
@@ -211,7 +212,7 @@ int c4_server_event(entity minigame, string event, ...)
                        int pl_num = minigame_count_players(minigame);
 
                        // Don't allow more than 2 players
-                       if(pl_num >= C4_TEAMS) { return false; }
+                       if(pl_num >= C4_TEAMS) { return C4_SPECTATOR_TEAM; }
 
                        // Get the right team
                        if(minigame.minigame_players)
@@ -222,9 +223,13 @@ int c4_server_event(entity minigame, string event, ...)
                }
                case "cmd":
                {
+                       entity player = ...(0,entity);
+                       bool event_blocked = (player.team == C4_SPECTATOR_TEAM);
                        switch(argv(0))
                        {
                                case "move":
+                                       if(event_blocked)
+                                               return true;
                                        c4_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null );
                                        return true;
                        }
@@ -299,22 +304,22 @@ void c4_hud_board(vector pos, vector mySize)
        if ( active_minigame.minigame_flags & C4_TURN_WIN )
        {
                vector winfs = hud_fontsize*2;
-               string playername = "";
+               string pname = "";
                FOREACH_MINIGAME_ENTITY(e)
                        if ( e.classname == "minigame_player" &&
                                        e.team == (active_minigame.minigame_flags & C4_TURN_TEAM) )
-                               playername = entcs_GetName(e.minigame_playerslot-1);
+                               pname = entcs_GetName(e.minigame_playerslot-1);
 
                vector win_pos = pos+eY*(mySize_y-winfs_y)/2;
                vector win_sz;
                win_sz = minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
-                       sprintf("%s^7 won the game!",playername),
+                       sprintf(_("%s^7 won the game!"), pname),
                        winfs, 0, DRAWFLAG_NORMAL, 0.5);
 
                drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
-                       sprintf("%s^7 won the game!",playername),
+                       sprintf(_("%s^7 won the game!"), pname),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
 }
@@ -323,7 +328,7 @@ void c4_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void c4_hud_status(vector pos, vector mySize)
 {
-       HUD_Panel_DrawBg(1);
+       HUD_Panel_DrawBg();
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
                hud_fontsize * 2, '0.25 0.47 0.72', panel_fg_alpha, DRAWFLAG_NORMAL,0.5);
@@ -337,17 +342,20 @@ void c4_hud_status(vector pos, vector mySize)
        vector mypos;
        vector tile_size = '48 48 0';
 
-       mypos = pos;
-       if ( (active_minigame.minigame_flags&C4_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 != C4_SPECTATOR_TEAM)
+       {
+               mypos = pos;
+               if ( (active_minigame.minigame_flags&C4_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 != C4_SPECTATOR_TEAM )
                {
                        mypos = pos;
                        if ( e.team == 2 )
@@ -369,6 +377,9 @@ void c4_hud_status(vector pos, vector mySize)
 // Turn a set of flags into a help message
 string c4_turn_to_string(int turnflags)
 {
+       if(minigame_self.team == C4_SPECTATOR_TEAM)
+               return _("You are spectating");
+
        if ( turnflags & C4_TURN_DRAW )
                return _("Draw");
 
@@ -399,8 +410,7 @@ void c4_make_move(entity minigame)
 
 void c4_set_curr_pos(string s)
 {
-       if ( c4_curr_pos )
-               strunzone(c4_curr_pos);
+       strfree(c4_curr_pos);
        if ( s )
                s = strzone(s);
        c4_curr_pos = s;
@@ -414,17 +424,27 @@ int c4_client_event(entity minigame, string event, ...)
                case "activate":
                {
                        c4_set_curr_pos("");
-                       minigame.message = c4_turn_to_string(minigame.minigame_flags);
+                       strcpy(minigame.message, c4_turn_to_string(minigame.minigame_flags));
+                       return false;
+               }
+               case "deactivate":
+               {
+                       strfree(minigame.message);
                        return false;
                }
                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_blocked)
+                                                       return true;
                                                if ( ! c4_curr_pos )
                                                        c4_set_curr_pos(c4_get_lowest_tile(minigame, "a3"));
                                                else
@@ -432,13 +452,22 @@ int c4_client_event(entity minigame, string event, ...)
                                                return true;
                                        case K_LEFTARROW:
                                        case K_KP_LEFTARROW:
+                                               if (event_blocked)
+                                                       return true;
                                                if ( ! c4_curr_pos )
                                                        c4_set_curr_pos(c4_get_lowest_tile(minigame, "c3"));
                                                else
                                                        c4_set_curr_pos(c4_get_lowest_tile(minigame, minigame_relative_tile(c4_curr_pos,-1,0,C4_NUM_CNT,C4_LET_CNT)));
                                                return true;
+                                       case K_UPARROW:
+                                       case K_KP_UPARROW:
+                                       case K_DOWNARROW:
+                                       case K_KP_DOWNARROW:
+                                               return true;
                                        /*case K_UPARROW:
                                        case K_KP_UPARROW:
+                                               if (event_blocked)
+                                                       return true;
                                                if ( ! c4_curr_pos )
                                                        c4_set_curr_pos("a1");
                                                else
@@ -446,6 +475,8 @@ int c4_client_event(entity minigame, string event, ...)
                                                return true;
                                        case K_DOWNARROW:
                                        case K_KP_DOWNARROW:
+                                               if (event_blocked)
+                                                       return true;
                                                if ( ! c4_curr_pos )
                                                        c4_set_curr_pos("a3");
                                                else
@@ -454,6 +485,8 @@ int c4_client_event(entity minigame, string event, ...)
                                        case K_ENTER:
                                        case K_KP_ENTER:
                                        case K_SPACE:
+                                               if (event_blocked)
+                                                       return true;
                                                c4_make_move(minigame);
                                                return true;
                                }
@@ -465,6 +498,7 @@ int c4_client_event(entity minigame, string event, ...)
                {
                        if(...(0,int) == K_MOUSE1)
                        {
+                               c4_client_event(minigame, "mouse_moved");
                                c4_make_move(minigame);
                                return true;
                        }
@@ -491,7 +525,7 @@ int c4_client_event(entity minigame, string event, ...)
                        {
                                if ( sf & MINIG_SF_UPDATE )
                                {
-                                       sent.message = c4_turn_to_string(sent.minigame_flags);
+                                       strcpy(sent.message, c4_turn_to_string(sent.minigame_flags));
                                        if ( sent.minigame_flags & minigame_self.team )
                                                minigame_prompt();
                                }