]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigame/c4.qc
Merge branch 'master' into terencehill/bot_waypoints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigame / c4.qc
index a153b39939ea47b061c85d9a0c124221b345b5ff..be65e6ac13528bc4446b8b0e1ee8768636387fff 100644 (file)
@@ -1,7 +1,9 @@
+#include "c4.qh"
+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
 const float C4_TURN_DRAW  = 0x0400; // no moves are possible
-const float C4_TURN_TYPE  = 0x0f00; // turn type mask
 
 const float C4_TURN_TEAM1 = 0x0001;
 const float C4_TURN_TEAM2 = 0x0002;
@@ -23,11 +25,11 @@ const int C4_TEAMS = 2;
 // find connect 4 piece given its tile name
 entity c4_find_piece(entity minig, string tile)
 {
-       entity e = world;
+       entity e = NULL;
        while ( ( e = findentity(e,owner,minig) ) )
                if ( e.classname == "minigame_board_piece" && e.netname == tile )
                        return e;
-       return world;
+       return NULL;
 }
 
 // Checks if the given piece completes a row
@@ -120,7 +122,7 @@ bool c4_winning_piece(entity piece)
 
        if(found >= C4_WIN_CNT)
                return true;
-       
+
        return false;
 }
 
@@ -195,12 +197,12 @@ int c4_server_event(entity minigame, string event, ...)
                }
                case "end":
                {
-                       entity e = world;
+                       entity e = NULL;
                        while( (e = findentity(e, owner, minigame)) )
                        if(e.classname == "minigame_board_piece")
                        {
-                               if(e.netname) { strunzone(e.netname); }
-                               remove(e);
+                               strfree(e.netname);
+                               delete(e);
                        }
                        return false;
                }
@@ -222,15 +224,15 @@ int c4_server_event(entity minigame, string event, ...)
                {
                        switch(argv(0))
                        {
-                               case "move": 
-                                       c4_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null ); 
+                               case "move":
+                                       c4_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null );
                                        return true;
                        }
 
                        return false;
                }
        }
-       
+
        return false;
 }
 
@@ -248,7 +250,7 @@ void c4_hud_board(vector pos, vector mySize)
        minigame_hud_fitsqare(pos, mySize);
        c4_boardpos = pos;
        c4_boardsize = mySize;
-       
+
        minigame_hud_simpleboard(pos,mySize,minigame_texture("c4/board_under"));
 
        drawpic(pos, minigame_texture("c4/board_over"), mySize, '1 1 1', 1, 0);
@@ -261,11 +263,11 @@ void c4_hud_board(vector pos, vector mySize)
        {
                tile_pos = minigame_tile_pos(c4_curr_pos,C4_NUM_CNT,C4_LET_CNT);
                tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
-               minigame_drawpic_centered( tile_pos,  
+               minigame_drawpic_centered( tile_pos,
                                minigame_texture(strcat("c4/piece",ftos(minigame_self.team))),
                                tile_size, '1 1 1', panel_fg_alpha/2, DRAWFLAG_NORMAL );
        }
-       
+
        entity e;
        FOREACH_MINIGAME_ENTITY(e)
        {
@@ -273,11 +275,11 @@ void c4_hud_board(vector pos, vector mySize)
                {
                        tile_pos = minigame_tile_pos(e.netname,C4_NUM_CNT,C4_LET_CNT);
                        tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
-                       
+
                        if ( active_minigame.minigame_flags & C4_TURN_WIN )
                        if ( !e.c4_checkwin )
                                e.c4_checkwin = c4_winning_piece(e) ? 1 : -1;
-                       
+
                        float icon_color = 1;
                        if ( e.c4_checkwin == -1 )
                                icon_color = 0.4;
@@ -287,8 +289,8 @@ void c4_hud_board(vector pos, vector mySize)
                                minigame_drawpic_centered( tile_pos, minigame_texture("c4/winglow"),
                                                tile_size, '1 1 1', panel_fg_alpha, DRAWFLAG_ADDITIVE );
                        }
-                               
-                       minigame_drawpic_centered( tile_pos,  
+
+                       minigame_drawpic_centered( tile_pos,
                                        minigame_texture(strcat("c4/piece",ftos(e.team))),
                                        tile_size, '1 1 1'*icon_color, panel_fg_alpha, DRAWFLAG_NORMAL );
                }
@@ -297,22 +299,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" && 
+                       if ( e.classname == "minigame_player" &&
                                        e.team == (active_minigame.minigame_flags & C4_TURN_TEAM) )
-                               playername = GetPlayerName(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);
        }
 }
@@ -321,14 +323,14 @@ 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);
-       
+
        pos_y += ts_y;
        mySize_y -= ts_y;
-       
+
        vector player_fontsize = hud_fontsize * 1.75;
        ts_y = ( mySize_y - 2*player_fontsize_y ) / 2;
        ts_x = mySize_x;
@@ -351,14 +353,14 @@ void c4_hud_status(vector pos, vector mySize)
                        if ( e.team == 2 )
                                mypos_y  += player_fontsize_y + ts_y;
                        minigame_drawcolorcodedstring_trunc(mySize_x,mypos,
-                               GetPlayerName(e.minigame_playerslot-1),
+                               entcs_GetName(e.minigame_playerslot-1),
                                player_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
-                       
+
                        mypos_y += player_fontsize_y;
-                       drawpic( mypos,  
+                       drawpic( mypos,
                                        minigame_texture(strcat("c4/piece",ftos(e.team))),
                                        tile_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL );
-                       
+
                        mypos_x += tile_size_x;
                }
        }
@@ -369,20 +371,20 @@ string c4_turn_to_string(int turnflags)
 {
        if ( turnflags & C4_TURN_DRAW )
                return _("Draw");
-       
+
        if ( turnflags & C4_TURN_WIN )
        {
                if ( (turnflags&C4_TURN_TEAM) != minigame_self.team )
                        return _("You lost the game!");
                return _("You win!");
        }
-       
+
        if ( (turnflags & C4_TURN_TEAM) != minigame_self.team )
                return _("Wait for your opponent to make their move");
-       
+
        if ( turnflags & C4_TURN_PLACE )
                return _("Click on the game board to place your piece");
-       
+
        return "";
 }
 
@@ -397,8 +399,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;
@@ -412,7 +413,12 @@ 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":
@@ -489,7 +495,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();
                                }
@@ -502,4 +508,4 @@ int c4_client_event(entity minigame, string event, ...)
        return false;
 }
 
-#endif
\ No newline at end of file
+#endif