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

Go to the source code of this file.

Functions

entity c4_find_piece (entity minig, string tile)
 
string c4_get_lowest_tile (entity minigame, string s)
 
void c4_move (entity minigame, entity player, string pos)
 
bool c4_valid_tile (string tile)
 
bool c4_winning_piece (entity piece)
 
 REGISTER_MINIGAME (c4, _("Connect Four"))
 

Variables

const int C4_LET_CNT = 7
 
const int C4_MAX_TILES = 42
 
int c4_nexteam
 
int c4_npieces
 
const int C4_NUM_CNT = 6
 
const int C4_SPECTATOR_TEAM = 255
 
const int C4_TEAMS = 2
 
const int C4_TILE_SIZE = 8
 
const float C4_TURN_DRAW = 0x0400
 
const float C4_TURN_PLACE = 0x0100
 
const float C4_TURN_TEAM = 0x000f
 
const float C4_TURN_TEAM1 = 0x0001
 
const float C4_TURN_TEAM2 = 0x0002
 
const float C4_TURN_WIN = 0x0200
 
const int C4_WIN_CNT = 4
 

Function Documentation

◆ c4_find_piece()

entity c4_find_piece ( entity  minig,
string  tile 
)

Definition at line 27 of file c4.qc.

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

Referenced by c4_get_lowest_tile(), c4_move(), and c4_winning_piece().

28 {
29  entity e = NULL;
30  while ( ( e = findentity(e,owner,minig) ) )
31  if ( e.classname == "minigame_board_piece" && e.netname == tile )
32  return e;
33  return NULL;
34 }
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:

◆ c4_get_lowest_tile()

string c4_get_lowest_tile ( entity  minigame,
string  s 
)

Definition at line 140 of file c4.qc.

References c4_find_piece(), minigame_tile_buildname(), and minigame_tile_letter().

Referenced by c4_move().

141 {
142  int i;
143  int end = 0;
144  for(i = C4_NUM_CNT; i >= 0; --i)
145  {
148  {
149  end = i;
150  break;
151  }
152  }
154 }
const int C4_NUM_CNT
Definition: c4.qc:13
int minigame_tile_letter(string id)
Definition: minigames.qc:12
entity c4_find_piece(entity minig, string tile)
Definition: c4.qc:27
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:

◆ c4_move()

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

Definition at line 157 of file c4.qc.

References active_minigame, argv(), c4_find_piece(), c4_get_lowest_tile(), C4_SPECTATOR_TEAM, C4_TURN_DRAW, C4_TURN_TEAM1, c4_valid_tile(), c4_winning_piece(), DRAWFLAG_ADDITIVE, DRAWFLAG_NORMAL, drawpic(), entity(), eY, findentity(), FOREACH_MINIGAME_ENTITY, ftos(), hud_fontsize, MINIG_SF_ALL, MINIG_SF_UPDATE, minigame_count_players(), minigame_drawcolorcodedstring_wrapped(), minigame_drawpic_centered(), 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(), msle_spawn(), NULL, owner, panel_fg_alpha, strcat(), strfree, string_null, strzone(), and vector().

158 {
159  pos = c4_get_lowest_tile(minigame, pos);
160 
161  if ( minigame.minigame_flags & C4_TURN_PLACE )
162  if ( pos && player.team == (minigame.minigame_flags & C4_TURN_TEAM) )
163  {
164  if ( c4_valid_tile(pos) )
165  if ( !c4_find_piece(minigame,pos) )
166  {
167  entity piece = msle_spawn(minigame,new(minigame_board_piece));
168  piece.team = player.team;
169  piece.netname = strzone(pos);
172  minigame.c4_npieces++;
173  minigame.c4_nexteam = minigame_next_team(player.team,C4_TEAMS);
174  if ( c4_winning_piece(piece) )
175  {
176  minigame.minigame_flags = C4_TURN_WIN | player.team;
177  }
178  else if ( minigame.c4_npieces >= C4_MAX_TILES )
179  minigame.minigame_flags = C4_TURN_DRAW;
180  else
181  minigame.minigame_flags = C4_TURN_PLACE | minigame.c4_nexteam;
182  }
183  }
184 }
const float C4_TURN_DRAW
Definition: c4.qc:6
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
const int MINIG_SF_ALL
Definition: minigames.qh:112
bool c4_valid_tile(string tile)
Definition: c4.qc:131
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
bool c4_winning_piece(entity piece)
Definition: c4.qc:37
string c4_get_lowest_tile(entity minigame, string s)
Definition: c4.qc:140
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
const float C4_TURN_PLACE
Definition: c4.qc:4
const int C4_MAX_TILES
Definition: c4.qc:16
const int C4_TEAMS
Definition: c4.qc:20
entity c4_find_piece(entity minig, string tile)
Definition: c4.qc:27
const float C4_TURN_WIN
Definition: c4.qc:5
const float C4_TURN_TEAM
Definition: c4.qc:10
+ Here is the call graph for this function:

◆ c4_valid_tile()

bool c4_valid_tile ( string  tile)

Definition at line 131 of file c4.qc.

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

Referenced by c4_move().

132 {
133  if ( !tile )
134  return false;
135  float number = minigame_tile_number(tile);
136  float letter = minigame_tile_letter(tile);
137  return 0 <= number && number < C4_NUM_CNT && 0 <= letter && letter < C4_LET_CNT;
138 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
const int C4_NUM_CNT
Definition: c4.qc:13
int minigame_tile_letter(string id)
Definition: minigames.qc:12
const int C4_LET_CNT
Definition: c4.qc:12
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ c4_winning_piece()

bool c4_winning_piece ( entity  piece)

Definition at line 37 of file c4.qc.

References c4_find_piece(), C4_NUM_CNT, entity(), minigame_tile_buildname(), minigame_tile_letter(), minigame_tile_number(), number, and team.

Referenced by c4_move().

38 {
39  int number = minigame_tile_number(piece.netname);
40  int letter = minigame_tile_letter(piece.netname);
41 
42  int i;
43  entity top = piece;
44  entity left = piece;
45  entity topleft = piece;
46  entity botleft = piece;
47  for(i = number; i < C4_NUM_CNT; ++i)
48  {
49  entity p = c4_find_piece(piece.owner,minigame_tile_buildname(letter, i));
50  if(p.team == piece.team)
51  top = p;
52  else break;
53  }
54 
55  for(i = letter; i >= 0; --i)
56  {
57  entity p = c4_find_piece(piece.owner,minigame_tile_buildname(i, number));
58  if(p.team == piece.team)
59  left = p;
60  else break;
61  }
62 
63  int j;
64  for(i = letter, j = number; i >= 0, j >= 0; --i, --j)
65  {
66  entity p = c4_find_piece(piece.owner,minigame_tile_buildname(i, j));
67  if(p.team == piece.team)
68  botleft = p;
69  else break;
70  }
71  for(i = letter, j = number; i >= 0, j < C4_NUM_CNT; --i, ++j)
72  {
73  entity p = c4_find_piece(piece.owner,minigame_tile_buildname(i, j));
74  if(p.team == piece.team)
75  topleft = p;
76  else break;
77  }
78 
79  // down
80  int found = 0;
81  for(i = minigame_tile_number(top.netname); i >= 0; --i)
82  {
83  if(c4_find_piece(piece.owner,minigame_tile_buildname(letter, i)).team == piece.team)
84  ++found;
85  else break;
86  }
87 
88  if(found >= C4_WIN_CNT)
89  return true;
90 
91  // right
92  found = 0;
93  for(i = minigame_tile_letter(left.netname); i < C4_LET_CNT; ++i)
94  {
95  if(c4_find_piece(piece.owner,minigame_tile_buildname(i, number)).team == piece.team)
96  ++found;
97  else break;
98  }
99 
100  if(found >= C4_WIN_CNT)
101  return true;
102 
103  // diagright down
104  found = 0;
105  for(i = minigame_tile_letter(topleft.netname), j = minigame_tile_number(topleft.netname); i < C4_LET_CNT, j >= 0; ++i, --j)
106  {
107  if(c4_find_piece(piece.owner,minigame_tile_buildname(i, j)).team == piece.team)
108  ++found;
109  else break;
110  }
111 
112  if(found >= C4_WIN_CNT)
113  return true;
114 
115  // diagright up
116  found = 0;
117  for(i = minigame_tile_letter(botleft.netname), j = minigame_tile_number(botleft.netname); i < C4_LET_CNT, j < C4_NUM_CNT; ++i, ++j)
118  {
119  if(c4_find_piece(piece.owner,minigame_tile_buildname(i, j)).team == piece.team)
120  ++found;
121  else break;
122  }
123 
124  if(found >= C4_WIN_CNT)
125  return true;
126 
127  return false;
128 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
int team
Definition: main.qh:157
entity() spawn
const int C4_NUM_CNT
Definition: c4.qc:13
int minigame_tile_letter(string id)
Definition: minigames.qc:12
entity c4_find_piece(entity minig, string tile)
Definition: c4.qc:27
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
const int C4_LET_CNT
Definition: c4.qc:12
const int C4_WIN_CNT
Definition: c4.qc:14
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REGISTER_MINIGAME()

REGISTER_MINIGAME ( c4  ,
_("Connect Four")   
)

Variable Documentation

◆ C4_LET_CNT

const int C4_LET_CNT = 7

Definition at line 12 of file c4.qc.

Referenced by c4_valid_tile().

◆ C4_MAX_TILES

const int C4_MAX_TILES = 42

Definition at line 16 of file c4.qc.

◆ c4_nexteam

int c4_nexteam

Definition at line 24 of file c4.qc.

◆ c4_npieces

int c4_npieces

Definition at line 23 of file c4.qc.

◆ C4_NUM_CNT

const int C4_NUM_CNT = 6

Definition at line 13 of file c4.qc.

Referenced by c4_winning_piece().

◆ C4_SPECTATOR_TEAM

const int C4_SPECTATOR_TEAM = 255

Definition at line 21 of file c4.qc.

Referenced by c4_move().

◆ C4_TEAMS

const int C4_TEAMS = 2

Definition at line 20 of file c4.qc.

◆ C4_TILE_SIZE

const int C4_TILE_SIZE = 8

Definition at line 18 of file c4.qc.

◆ C4_TURN_DRAW

const float C4_TURN_DRAW = 0x0400

Definition at line 6 of file c4.qc.

Referenced by c4_move().

◆ C4_TURN_PLACE

const float C4_TURN_PLACE = 0x0100

Definition at line 4 of file c4.qc.

◆ C4_TURN_TEAM

const float C4_TURN_TEAM = 0x000f

Definition at line 10 of file c4.qc.

◆ C4_TURN_TEAM1

const float C4_TURN_TEAM1 = 0x0001

Definition at line 8 of file c4.qc.

Referenced by c4_move().

◆ C4_TURN_TEAM2

const float C4_TURN_TEAM2 = 0x0002

Definition at line 9 of file c4.qc.

◆ C4_TURN_WIN

const float C4_TURN_WIN = 0x0200

Definition at line 5 of file c4.qc.

◆ C4_WIN_CNT

const int C4_WIN_CNT = 4

Definition at line 14 of file c4.qc.