Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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)
int c4_server_event (entity minigame, string event,...)
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.

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}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
entity owner
Definition main.qh:87
entity findentity(entity start,.entity field, entity match)
#define NULL
Definition post.qh:14

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

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

◆ c4_get_lowest_tile()

string c4_get_lowest_tile ( entity minigame,
string s )

Definition at line 140 of file c4.qc.

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}
entity c4_find_piece(entity minig, string tile)
Definition c4.qc:27
const int C4_NUM_CNT
Definition c4.qc:13
int minigame_tile_letter(string id)
Definition minigames.qc:12
string minigame_tile_buildname(int letter, int number)
Definition minigames.qc:34

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

Referenced by c4_move().

◆ c4_move()

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

Definition at line 157 of file c4.qc.

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_TEAM
Definition c4.qc:10
const float C4_TURN_PLACE
Definition c4.qc:4
const int C4_TEAMS
Definition c4.qc:20
bool c4_valid_tile(string tile)
Definition c4.qc:131
bool c4_winning_piece(entity piece)
Definition c4.qc:37
const float C4_TURN_WIN
Definition c4.qc:5
const int C4_MAX_TILES
Definition c4.qc:16
const float C4_TURN_DRAW
Definition c4.qc:6
string c4_get_lowest_tile(entity minigame, string s)
Definition c4.qc:140
string strzone(string s)
entity msle_spawn(entity minigame_session, entity e)
Definition minigames.qc:87
void minigame_server_sendflags(entity ent, int mgflags)
Definition minigames.qc:78
int minigame_next_team(int curr_team, int n_teams)
Definition minigames.qc:65
const int MINIG_SF_UPDATE
Definition minigames.qh:109
const int MINIG_SF_ALL
Definition minigames.qh:112

References c4_find_piece(), c4_get_lowest_tile(), C4_MAX_TILES, C4_TEAMS, C4_TURN_DRAW, C4_TURN_PLACE, C4_TURN_TEAM, C4_TURN_WIN, c4_valid_tile(), c4_winning_piece(), entity(), MINIG_SF_ALL, MINIG_SF_UPDATE, minigame_next_team(), minigame_server_sendflags(), msle_spawn(), and strzone().

Referenced by c4_server_event().

◆ c4_server_event()

int c4_server_event ( entity minigame,
string event,
... )

Definition at line 190 of file c4.qc.

191{
192 switch(event)
193 {
194 case "start":
195 {
196 minigame.minigame_flags = (C4_TURN_PLACE | C4_TURN_TEAM1);
197 return true;
198 }
199 case "end":
200 {
201 entity e = NULL;
202 while( (e = findentity(e, owner, minigame)) )
203 if(e.classname == "minigame_board_piece")
204 {
205 strfree(e.netname);
206 delete(e);
207 }
208 return false;
209 }
210 case "join":
211 {
212 int pl_num = minigame_count_players(minigame);
213
214 // Don't allow more than 2 players
215 if(pl_num >= C4_TEAMS) { return C4_SPECTATOR_TEAM; }
216
217 // Get the right team
218 if(minigame.minigame_players)
219 return minigame_next_team(minigame.minigame_players.team, C4_TEAMS);
220
221 // Team 1 by default
222 return 1;
223 }
224 case "cmd":
225 {
226 entity player = ...(0,entity);
227 bool event_blocked = (player.team == C4_SPECTATOR_TEAM);
228 switch(argv(0))
229 {
230 case "move":
231 if(event_blocked)
232 return true;
233 c4_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null );
234 return true;
235 }
236
237 return false;
238 }
239 }
240
241 return false;
242}
const int C4_SPECTATOR_TEAM
Definition c4.qc:21
void c4_move(entity minigame, entity player, string pos)
Definition c4.qc:157
const float C4_TURN_TEAM1
Definition c4.qc:8
string argv(float n)
int minigame_count_players(entity minigame)
Definition minigames.qc:121
string string_null
Definition nil.qh:9
#define strfree(this)
Definition string.qh:59

References argv(), c4_move(), C4_SPECTATOR_TEAM, C4_TEAMS, C4_TURN_PLACE, C4_TURN_TEAM1, entity(), findentity(), minigame_count_players(), minigame_next_team(), NULL, owner, strfree, and string_null.

◆ c4_valid_tile()

bool c4_valid_tile ( string tile)

Definition at line 131 of file c4.qc.

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}
const int C4_LET_CNT
Definition c4.qc:12
int minigame_tile_number(string id)
Definition minigames.qc:21
int int number
Definition impulse.qc:89

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

Referenced by c4_move().

◆ c4_winning_piece()

bool c4_winning_piece ( entity piece)

Definition at line 37 of file c4.qc.

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 {
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}
const int C4_WIN_CNT
Definition c4.qc:14
int team
Definition main.qh:188

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

Referenced by c4_move().

◆ 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(), and c4_winning_piece().

◆ C4_MAX_TILES

const int C4_MAX_TILES = 42

Definition at line 16 of file c4.qc.

Referenced by c4_move().

◆ 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_get_lowest_tile(), c4_valid_tile(), and c4_winning_piece().

◆ C4_SPECTATOR_TEAM

const int C4_SPECTATOR_TEAM = 255

Definition at line 21 of file c4.qc.

Referenced by c4_server_event(), and minigame_show_allspecs().

◆ C4_TEAMS

const int C4_TEAMS = 2

Definition at line 20 of file c4.qc.

Referenced by c4_move(), and c4_server_event().

◆ 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.

Referenced by c4_move(), and c4_server_event().

◆ C4_TURN_TEAM

const float C4_TURN_TEAM = 0x000f

Definition at line 10 of file c4.qc.

Referenced by c4_move().

◆ C4_TURN_TEAM1

const float C4_TURN_TEAM1 = 0x0001

Definition at line 8 of file c4.qc.

Referenced by c4_server_event().

◆ 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.

Referenced by c4_move().

◆ C4_WIN_CNT

const int C4_WIN_CNT = 4

Definition at line 14 of file c4.qc.

Referenced by c4_winning_piece().