X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fminigames%2Fminigame%2Fttt.qc;h=6bac28c930b56f6a470c980a4e91dbf8fee0e892;hb=021728329f7609ccd73e24dfda4bd8ef36a482ae;hp=c3c76376c169cd8b19ab22c715b50c3f47401582;hpb=43eba8ca70f00458db385630f86009f6d7fa849a;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/minigames/minigame/ttt.qc b/qcsrc/common/minigames/minigame/ttt.qc index c3c76376c..6bac28c93 100644 --- a/qcsrc/common/minigames/minigame/ttt.qc +++ b/qcsrc/common/minigames/minigame/ttt.qc @@ -1,4 +1,5 @@ -REGISTER_MINIGAME(ttt, "Tic Tac Toe"); +#include "ttt.qh" +REGISTER_MINIGAME(ttt, _("Tic Tac Toe")); const int TTT_TURN_PLACE = 0x0100; // player has to place a piece on the board const int TTT_TURN_WIN = 0x0200; // player has won @@ -25,11 +26,11 @@ const int TTT_TILE_SIZE = 3; // find tic tac toe piece given its tile name entity ttt_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,10 +121,10 @@ void ttt_next_match(entity minigame, entity player) minigame.minigame_flags = TTT_TURN_PLACE | minigame.ttt_nexteam; minigame_server_sendflags(minigame,MINIG_SF_UPDATE); minigame.ttt_npieces = 0; - entity e = world; + entity e = NULL; while ( ( e = findentity(e,owner,minigame) ) ) if ( e.classname == "minigame_board_piece" ) - remove(e); + delete(e); } } @@ -142,12 +143,12 @@ int ttt_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; } @@ -272,7 +273,7 @@ void ttt_hud_board(vector pos, vector mySize) // Required function, draw the game status panel void ttt_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); @@ -295,7 +296,7 @@ void ttt_hud_status(vector pos, vector mySize) if ( e.team == 2 ) mypos_y += player_fontsize_y + ts_y; minigame_drawcolorcodedstring_trunc(mySize_x,mypos, - (e.minigame_playerslot ? GetPlayerName(e.minigame_playerslot-1) : _("AI")), + (e.minigame_playerslot ? entcs_GetName(e.minigame_playerslot-1) : _("AI")), player_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); mypos_y += player_fontsize_y; @@ -319,9 +320,11 @@ string ttt_turn_to_string(int turnflags) if ( turnflags & TTT_TURN_WIN ) { + // translator-friendly messages composed of 2 existing messages + // TODO: proper "you win" banner instead of hijacking the help message if ( (turnflags&TTT_TURN_TEAM) != minigame_self.team ) - return _("You lost the game!\nSelect \"^1Next Match^7\" on the menu for a rematch!"); - return _("You win!\nSelect \"^1Next Match^7\" on the menu to start a new match!"); + 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!")); } if ( turnflags & TTT_TURN_NEXT ) @@ -417,11 +420,11 @@ int ttt_ai_random(int piecemask) for ( int i = 0; i < 9; i++ ) { if ( piecemask & f ) - RandomSelection_Add(world, f, string_null, 1, 1); + RandomSelection_AddFloat(f, 1, 1); f <<= 1; } - LOG_TRACE(sprintf("TTT AI: selected %x from %x\n", + LOG_TRACE(sprintf("TTT AI: selected %x from %x", RandomSelection_chosen_float, piecemask) ); return RandomSelection_chosen_float; } @@ -439,7 +442,7 @@ int ttt_ai_block3 ( int piecemask, int piecemask_free ) r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A3,TTT_AI_POSFLAG_B3,TTT_AI_POSFLAG_C3); r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A1,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_C3); r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A3,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_C1); - LOG_TRACE(sprintf("TTT AI: possible 3 in a rows in %x: %x (%x)\n",piecemask,r, r&piecemask_free)); + LOG_TRACE(sprintf("TTT AI: possible 3 in a rows in %x: %x (%x)",piecemask,r, r&piecemask_free)); r &= piecemask_free; return ttt_ai_random(r); } @@ -452,15 +455,15 @@ string ttt_ai_choose_simple(int piecemask_self, int piecemask_opponent, int piec { int move = 0; - LOG_TRACE("TTT AI: checking winning move\n"); + LOG_TRACE("TTT AI: checking winning move"); if (( move = ttt_ai_block3(piecemask_self,piecemask_free) )) return ttt_ai_piece_flag2pos(move); // place winning move - LOG_TRACE("TTT AI: checking opponent's winning move\n"); + LOG_TRACE("TTT AI: checking opponent's winning move"); if (( move = ttt_ai_block3(piecemask_opponent,piecemask_free) )) return ttt_ai_piece_flag2pos(move); // block opponent - LOG_TRACE("TTT AI: random move\n"); + LOG_TRACE("TTT AI: random move"); return ttt_ai_piece_flag2pos(ttt_ai_random(piecemask_free)); } @@ -469,7 +472,7 @@ void ttt_aimove(entity minigame) { if ( minigame.minigame_flags == (TTT_TURN_PLACE|minigame.ttt_ai) ) { - entity aiplayer = world; + entity aiplayer = NULL; while ( ( aiplayer = findentity(aiplayer,owner,minigame) ) ) if ( aiplayer.classname == "minigame_player" && !aiplayer.minigame_playerslot ) break; @@ -510,16 +513,16 @@ void ttt_aimove(entity minigame) } // TODO multiple AI difficulties - LOG_TRACE(sprintf("TTT AI: self: %x opponent: %x free: %x\n", + LOG_TRACE(sprintf("TTT AI: self: %x opponent: %x free: %x", piecemask_self, piecemask_opponent, piecemask_free)); pos = ttt_ai_choose_simple(piecemask_self, piecemask_opponent, piecemask_free); - LOG_TRACE("TTT AI: chosen move: ",pos,"\n\n"); + LOG_TRACE("TTT AI: chosen move: ", pos); if ( !pos ) - LOG_TRACE("Tic Tac Toe AI has derped!\n"); + LOG_TRACE("Tic Tac Toe AI has derped!"); else ttt_move(minigame,aiplayer,pos); } - minigame.message = ttt_turn_to_string(minigame.minigame_flags); + strcpy(minigame.message, ttt_turn_to_string(minigame.minigame_flags)); } // Make the correct move @@ -539,8 +542,7 @@ void ttt_make_move(entity minigame) void ttt_set_curr_pos(string s) { - if ( ttt_curr_pos ) - strunzone(ttt_curr_pos); + strfree(ttt_curr_pos); if ( s ) s = strzone(s); ttt_curr_pos = s; @@ -554,7 +556,12 @@ int ttt_client_event(entity minigame, string event, ...) case "activate": { ttt_set_curr_pos(""); - minigame.message = ttt_turn_to_string(minigame.minigame_flags); + strcpy(minigame.message, ttt_turn_to_string(minigame.minigame_flags)); + return false; + } + case "deactivate": + { + strfree(minigame.message); return false; } case "key_pressed": @@ -629,7 +636,7 @@ int ttt_client_event(entity minigame, string event, ...) { if ( sf & MINIG_SF_UPDATE ) { - sent.message = ttt_turn_to_string(sent.minigame_flags); + strcpy(sent.message, ttt_turn_to_string(sent.minigame_flags)); if ( sent.minigame_flags & minigame_self.team ) minigame_prompt(); }