Xonotic
ttt.qc File Reference
#include "ttt.qh"
+ Include dependency graph for ttt.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 REGISTER_MINIGAME (ttt, _("Tic Tac Toe"))
 
entity ttt_find_piece (entity minig, string tile)
 
void ttt_move (entity minigame, entity player, string pos)
 
void ttt_next_match (entity minigame, entity player)
 
bool ttt_valid_tile (string tile)
 
bool ttt_winning_piece (entity piece)
 

Variables

int ttt_ai
 
const int TTT_LET_CNT = 3
 
int ttt_nexteam
 
int ttt_npieces
 
const int TTT_NUM_CNT = 3
 
const int TTT_SF_PLAYERSCORE = MINIG_SF_CUSTOM
 
const int TTT_SF_SINGLEPLAYER = MINIG_SF_CUSTOM<<1
 
const int TTT_SPECTATOR_TEAM = 255
 
const int TTT_TILE_SIZE = 3
 
const int TTT_TURN_DRAW = 0x0400
 
const int TTT_TURN_NEXT = 0x0800
 
const int TTT_TURN_PLACE = 0x0100
 
const int TTT_TURN_TEAM = 0x000f
 
const int TTT_TURN_TEAM1 = 0x0001
 
const int TTT_TURN_TEAM2 = 0x0002
 
const int TTT_TURN_TYPE = 0x0f00
 
const int TTT_TURN_WIN = 0x0200
 

Function Documentation

◆ REGISTER_MINIGAME()

REGISTER_MINIGAME ( ttt  ,
_("Tic Tac Toe")   
)

◆ ttt_find_piece()

entity ttt_find_piece ( entity  minig,
string  tile 
)

Definition at line 29 of file ttt.qc.

References entity(), findentity(), NULL, and owner.

Referenced by ttt_move(), and ttt_winning_piece().

30 {
31  entity e = NULL;
32  while ( ( e = findentity(e,owner,minig) ) )
33  if ( e.classname == "minigame_board_piece" && e.netname == tile )
34  return e;
35  return NULL;
36 }
entity() spawn
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ttt_move()

void ttt_move ( entity  minigame,
entity  player,
string  pos 
)

Definition at line 80 of file ttt.qc.

References entity(), MINIG_SF_ALL, MINIG_SF_UPDATE, minigame_next_team(), minigame_server_sendflags(), msle_spawn(), strzone(), ttt_find_piece(), TTT_TURN_DRAW, ttt_valid_tile(), and ttt_winning_piece().

Referenced by ttt_next_match().

81 {
82  if ( minigame.minigame_flags & TTT_TURN_PLACE )
83  if ( pos && player.team == (minigame.minigame_flags & TTT_TURN_TEAM) )
84  {
85  if ( ttt_valid_tile(pos) )
86  if ( !ttt_find_piece(minigame,pos) )
87  {
88  entity piece = msle_spawn(minigame,new(minigame_board_piece));
89  piece.team = player.team;
90  piece.netname = strzone(pos);
93  minigame.ttt_npieces++;
94  minigame.ttt_nexteam = minigame_next_team(player.team,2);
95  if ( ttt_winning_piece(piece) )
96  {
97  player.minigame_flags++;
99  minigame.minigame_flags = TTT_TURN_WIN | player.team;
100  }
101  else if ( minigame.ttt_npieces >= (TTT_LET_CNT * TTT_NUM_CNT) )
102  minigame.minigame_flags = TTT_TURN_DRAW;
103  else
104  minigame.minigame_flags = TTT_TURN_PLACE | minigame.ttt_nexteam;
105  }
106  }
107 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
const int MINIG_SF_ALL
Definition: minigames.qh:112
entity msle_spawn(entity minigame_session, entity e)
Definition: minigames.qc:87
int minigame_next_team(int curr_team, int n_teams)
Definition: minigames.qc:65
entity() spawn
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
const int TTT_SF_PLAYERSCORE
Definition: ttt.qc:15
const int TTT_TURN_DRAW
Definition: ttt.qc:6
const int TTT_TURN_TEAM
Definition: ttt.qc:12
const int TTT_NUM_CNT
Definition: ttt.qc:21
bool ttt_valid_tile(string tile)
Definition: ttt.qc:70
entity ttt_find_piece(entity minig, string tile)
Definition: ttt.qc:29
const int TTT_TURN_WIN
Definition: ttt.qc:5
const int TTT_LET_CNT
Definition: ttt.qc:20
const int TTT_TURN_PLACE
Definition: ttt.qc:4
bool ttt_winning_piece(entity piece)
Definition: ttt.qc:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ttt_next_match()

void ttt_next_match ( entity  minigame,
entity  player 
)

Definition at line 110 of file ttt.qc.

References active_minigame, argv(), DRAWFLAG_ADDITIVE, DRAWFLAG_NORMAL, entity(), findentity(), FOREACH_MINIGAME_ENTITY, ftos(), hud_fontsize, HUD_Panel_DrawBg, int, MINIG_SF_UPDATE, minigame_count_players(), minigame_drawcolorcodedstring_trunc(), minigame_drawpic_centered(), minigame_drawstring_wrapped(), minigame_hud_denormalize(), minigame_hud_denormalize_size(), minigame_hud_fitsqare, minigame_hud_simpleboard(), minigame_next_team(), minigame_self, minigame_server_sendflags(), minigame_texture(), minigame_tile_pos(), NULL, owner, panel_fg_alpha, strcat(), strfree, string_null, ttt_move(), TTT_SF_SINGLEPLAYER, TTT_SPECTATOR_TEAM, TTT_TURN_TEAM1, ttt_valid_tile(), ttt_winning_piece(), vector(), and WriteByte().

111 {
112 #ifdef SVQC
113  // on multiplayer matches, wait for both players to agree
114  if ( minigame.minigame_flags & (TTT_TURN_WIN|TTT_TURN_DRAW) )
115  {
116  minigame.minigame_flags = TTT_TURN_NEXT | player.team;
117  minigame.SendFlags |= MINIG_SF_UPDATE;
118  }
119  else if ( (minigame.minigame_flags & TTT_TURN_NEXT) &&
120  !( minigame.minigame_flags & player.team ) )
121 #endif
122  {
123  minigame.minigame_flags = TTT_TURN_PLACE | minigame.ttt_nexteam;
125  minigame.ttt_npieces = 0;
126  entity e = NULL;
127  while ( ( e = findentity(e,owner,minigame) ) )
128  if ( e.classname == "minigame_board_piece" )
129  delete(e);
130  }
131 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
entity() spawn
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
entity owner
Definition: main.qh:73
const int TTT_TURN_DRAW
Definition: ttt.qc:6
#define NULL
Definition: post.qh:17
const int TTT_TURN_WIN
Definition: ttt.qc:5
const int TTT_TURN_NEXT
Definition: ttt.qc:7
const int TTT_TURN_PLACE
Definition: ttt.qc:4
+ Here is the call graph for this function:

◆ ttt_valid_tile()

bool ttt_valid_tile ( string  tile)

Definition at line 70 of file ttt.qc.

References minigame_tile_letter(), minigame_tile_number(), number, and TTT_LET_CNT.

Referenced by ttt_move(), and ttt_next_match().

71 {
72  if ( !tile )
73  return 0;
74  int number = minigame_tile_number(tile);
75  int letter = minigame_tile_letter(tile);
76  return 0 <= number && number < TTT_NUM_CNT && 0 <= letter && letter < TTT_LET_CNT;
77 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
const int TTT_NUM_CNT
Definition: ttt.qc:21
int minigame_tile_letter(string id)
Definition: minigames.qc:12
const int TTT_LET_CNT
Definition: ttt.qc:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ttt_winning_piece()

bool ttt_winning_piece ( entity  piece)

Definition at line 39 of file ttt.qc.

References minigame_tile_buildname(), minigame_tile_letter(), minigame_tile_number(), number, team, and ttt_find_piece().

Referenced by ttt_move(), and ttt_next_match().

40 {
41  int number = minigame_tile_number(piece.netname);
42  int letter = minigame_tile_letter(piece.netname);
43 
44  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(0,number)).team == piece.team )
45  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(1,number)).team == piece.team )
46  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(2,number)).team == piece.team )
47  return true;
48 
49  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(letter,0)).team == piece.team )
50  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(letter,1)).team == piece.team )
51  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(letter,2)).team == piece.team )
52  return true;
53 
54  if ( number == letter )
55  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(0,0)).team == piece.team )
56  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(1,1)).team == piece.team )
57  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(2,2)).team == piece.team )
58  return true;
59 
60  if ( number == 2-letter )
61  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(0,2)).team == piece.team )
62  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(1,1)).team == piece.team )
63  if ( ttt_find_piece(piece.owner,minigame_tile_buildname(2,0)).team == piece.team )
64  return true;
65 
66  return false;
67 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
int team
Definition: main.qh:157
entity ttt_find_piece(entity minig, string tile)
Definition: ttt.qc:29
int minigame_tile_letter(string id)
Definition: minigames.qc:12
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ ttt_ai

int ttt_ai

Definition at line 26 of file ttt.qc.

◆ TTT_LET_CNT

const int TTT_LET_CNT = 3

Definition at line 20 of file ttt.qc.

Referenced by ttt_valid_tile().

◆ ttt_nexteam

int ttt_nexteam

Definition at line 25 of file ttt.qc.

◆ ttt_npieces

int ttt_npieces

Definition at line 24 of file ttt.qc.

◆ TTT_NUM_CNT

const int TTT_NUM_CNT = 3

Definition at line 21 of file ttt.qc.

◆ TTT_SF_PLAYERSCORE

const int TTT_SF_PLAYERSCORE = MINIG_SF_CUSTOM

Definition at line 15 of file ttt.qc.

◆ TTT_SF_SINGLEPLAYER

const int TTT_SF_SINGLEPLAYER = MINIG_SF_CUSTOM<<1

Definition at line 16 of file ttt.qc.

Referenced by ttt_next_match().

◆ TTT_SPECTATOR_TEAM

const int TTT_SPECTATOR_TEAM = 255

Definition at line 18 of file ttt.qc.

Referenced by ttt_next_match().

◆ TTT_TILE_SIZE

const int TTT_TILE_SIZE = 3

Definition at line 22 of file ttt.qc.

◆ TTT_TURN_DRAW

const int TTT_TURN_DRAW = 0x0400

Definition at line 6 of file ttt.qc.

Referenced by ttt_move().

◆ TTT_TURN_NEXT

const int TTT_TURN_NEXT = 0x0800

Definition at line 7 of file ttt.qc.

◆ TTT_TURN_PLACE

const int TTT_TURN_PLACE = 0x0100

Definition at line 4 of file ttt.qc.

◆ TTT_TURN_TEAM

const int TTT_TURN_TEAM = 0x000f

Definition at line 12 of file ttt.qc.

◆ TTT_TURN_TEAM1

const int TTT_TURN_TEAM1 = 0x0001

Definition at line 10 of file ttt.qc.

Referenced by ttt_next_match().

◆ TTT_TURN_TEAM2

const int TTT_TURN_TEAM2 = 0x0002

Definition at line 11 of file ttt.qc.

◆ TTT_TURN_TYPE

const int TTT_TURN_TYPE = 0x0f00

Definition at line 8 of file ttt.qc.

◆ TTT_TURN_WIN

const int TTT_TURN_WIN = 0x0200

Definition at line 5 of file ttt.qc.