Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
ttt.qc
Go to the documentation of this file.
1#include "ttt.qh"
2REGISTER_MINIGAME(ttt, _("Tic Tac Toe"));
3
4const int TTT_TURN_PLACE = 0x0100; // player has to place a piece on the board
5const int TTT_TURN_WIN = 0x0200; // player has won
6const int TTT_TURN_DRAW = 0x0400; // no moves are possible
7const int TTT_TURN_NEXT = 0x0800; // a player wants to start a new match
8const int TTT_TURN_TYPE = 0x0f00; // turn type mask
9
10const int TTT_TURN_TEAM1 = 0x0001;
11const int TTT_TURN_TEAM2 = 0x0002;
12const int TTT_TURN_TEAM = 0x000f; // turn team mask
13
14// send flags
15const int TTT_SF_PLAYERSCORE = MINIG_SF_CUSTOM; // send minigame_player scores (won matches)
16const int TTT_SF_SINGLEPLAYER = MINIG_SF_CUSTOM<<1;// send minigame.ttt_ai
17
18const int TTT_SPECTATOR_TEAM = 255; // must be above max teams and equal to or below 255
19
20const int TTT_LET_CNT = 3;
21const int TTT_NUM_CNT = 3;
22const int TTT_TILE_SIZE = 3;
23
24.int ttt_npieces; // (minigame) number of pieces on the board (simplifies checking a draw)
25.int ttt_nexteam; // (minigame) next team (used to change the starting team on following matches)
26.int ttt_ai; // (minigame) when non-zero, singleplayer vs AI
27
28// find tic tac toe piece given its tile name
29entity ttt_find_piece(entity minig, string tile)
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}
37
38// Checks if the given piece completes a row
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}
68
69// check if the tile name is valid (3x3 grid)
70bool ttt_valid_tile(string tile)
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}
78
79// make a move
80void ttt_move(entity minigame, entity player, string pos )
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}
108
109// request a new match
110void ttt_next_match(entity minigame, entity player)
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}
132
133#ifdef SVQC
134
135
136// required function, handle server side events
137int ttt_server_event(entity minigame, string event, ...)
138{
139 switch(event)
140 {
141 case "start":
142 {
143 minigame.minigame_flags = (TTT_TURN_PLACE | TTT_TURN_TEAM1);
144 return true;
145 }
146 case "end":
147 {
148 entity e = NULL;
149 while( (e = findentity(e, owner, minigame)) )
150 if(e.classname == "minigame_board_piece")
151 {
152 strfree(e.netname);
153 delete(e);
154 }
155 return false;
156 }
157 case "join":
158 {
159 int pl_num = minigame_count_players(minigame);
160
161 // Don't allow joining a single player match
162 if ( (minigame.ttt_ai) && pl_num > 0 )
163 return false;
164
165 // Don't allow more than 2 players
166 if(pl_num >= 2) { return TTT_SPECTATOR_TEAM; }
167
168 // Get the right team
169 if(minigame.minigame_players)
170 return minigame_next_team(minigame.minigame_players.team, 2);
171
172 // Team 1 by default
173 return 1;
174 }
175 case "cmd":
176 {
177 entity player = ...(0,entity);
178 bool event_blocked = (player.team == TTT_SPECTATOR_TEAM);
179 switch(argv(0))
180 {
181 case "move":
182 if(event_blocked)
183 return true;
184 ttt_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null );
185 return true;
186 case "next":
187 if(event_blocked)
188 return true;
189 ttt_next_match(minigame,...(0,entity));
190 return true;
191 case "singleplayer":
192 if(event_blocked)
193 return true;
194 if ( minigame_count_players(minigame) == 1 )
195 {
196 minigame.ttt_ai = minigame_next_team(minigame.minigame_players.team, 2);
197 minigame.SendFlags = TTT_SF_SINGLEPLAYER;
198 }
199 return true;
200 }
201
202 return false;
203 }
204 case "network_send":
205 {
206 entity sent = ...(0,entity);
207 int sf = ...(1,int);
208 if ( sent.classname == "minigame_player" && (sf & TTT_SF_PLAYERSCORE ) )
209 {
210 WriteByte(MSG_ENTITY,sent.minigame_flags);
211 }
212 else if ( sent.classname == "minigame" && (sf & TTT_SF_SINGLEPLAYER) )
213 {
214 WriteByte(MSG_ENTITY,sent.ttt_ai);
215 }
216 return false;
217 }
218 }
219
220 return false;
221}
222
223
224#elif defined(CSQC)
225
226string ttt_curr_pos; // identifier of the tile under the mouse
227vector ttt_boardpos; // HUD board position
228vector ttt_boardsize;// HUD board size
229.int ttt_checkwin; // Used to optimize checks to display a win
230
231// Required function, draw the game board
232void ttt_hud_board(vector pos, vector mySize)
233{
234 minigame_hud_fitsqare(pos, mySize);
235 ttt_boardpos = pos;
236 ttt_boardsize = mySize;
237
238 minigame_hud_simpleboard(pos,mySize,minigame_texture("ttt/board"));
239
240 vector tile_size = minigame_hud_denormalize_size('1 1 0'/TTT_TILE_SIZE,pos,mySize);
241 vector tile_pos;
242
243 if ( (active_minigame.minigame_flags & TTT_TURN_TEAM) == minigame_self.team )
244 if ( ttt_valid_tile(ttt_curr_pos) )
245 {
246 tile_pos = minigame_tile_pos(ttt_curr_pos,TTT_LET_CNT,TTT_NUM_CNT);
247 tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
249 minigame_texture(strcat("ttt/piece",ftos(minigame_self.team))),
250 tile_size, '1 1 1', panel_fg_alpha/2, DRAWFLAG_NORMAL );
251 }
252
253 entity e;
255 {
256 if ( e.classname == "minigame_board_piece" )
257 {
258 tile_pos = minigame_tile_pos(e.netname,TTT_LET_CNT,TTT_NUM_CNT);
259 tile_pos = minigame_hud_denormalize(tile_pos,pos,mySize);
260
261 if ( active_minigame.minigame_flags & TTT_TURN_WIN )
262 if ( !e.ttt_checkwin )
263 e.ttt_checkwin = ttt_winning_piece(e) ? 1 : -1;
264
265 float icon_color = 1;
266 if ( e.ttt_checkwin == -1 )
267 icon_color = 0.4;
268 else if ( e.ttt_checkwin == 1 )
269 {
270 icon_color = 2;
271 minigame_drawpic_centered( tile_pos, minigame_texture("ttt/winglow"),
272 tile_size, '1 1 1', panel_fg_alpha, DRAWFLAG_ADDITIVE );
273 }
274
276 minigame_texture(strcat("ttt/piece",ftos(e.team))),
277 tile_size, '1 1 1'*icon_color, panel_fg_alpha, DRAWFLAG_NORMAL );
278 }
279 }
280
281 minigame_show_allspecs(ttt_boardpos, ttt_boardsize);
282}
283
284
285// Required function, draw the game status panel
286void ttt_hud_status(vector pos, vector mySize)
287{
289 vector ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
290 hud_fontsize * 2, '0.25 0.47 0.72', panel_fg_alpha, DRAWFLAG_NORMAL,0.5);
291
292 pos_y += ts_y;
293 mySize_y -= ts_y;
294
295 vector player_fontsize = hud_fontsize * 1.75;
296 ts_y = ( mySize_y - 2*player_fontsize_y ) / 2;
297 ts_x = mySize_x;
298 vector mypos;
299 vector tile_size = '48 48 0';
300
301 entity e;
303 {
304 if ( e.classname == "minigame_player" && e.team != TTT_SPECTATOR_TEAM )
305 {
306 mypos = pos;
307 if ( e.team == 2 )
308 mypos_y += player_fontsize_y + ts_y;
310 (e.minigame_playerslot ? entcs_GetName(e.minigame_playerslot-1) : _("AI")),
311 player_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
312
313 mypos_y += player_fontsize_y;
314 drawpic( mypos,
315 minigame_texture(strcat("ttt/piece",ftos(e.team))),
316 tile_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL );
317
318 mypos_x += tile_size_x;
319
320 drawstring(mypos,ftos(e.minigame_flags),tile_size,
321 '0.7 0.84 1', panel_fg_alpha, DRAWFLAG_NORMAL);
322 }
323 }
324}
325
326// Turn a set of flags into a help message
327string ttt_turn_to_string(int turnflags)
328{
330 return _("You are spectating");
331
332 if ( turnflags & TTT_TURN_DRAW )
333 return _("Draw");
334
335 if ( turnflags & TTT_TURN_WIN )
336 {
337 // translator-friendly messages composed of 2 existing messages
338 // TODO: proper "you win" banner instead of hijacking the help message
339 if ( (turnflags & TTT_TURN_TEAM) != minigame_self.team )
340 return strcat(_("You lost the game!"), "\n", _("Select \"^1Next Match^7\" on the menu for a rematch!"));
341 return strcat(_("You win!"), "\n", _("Select \"^1Next Match^7\" on the menu to start a new match!"));
342 }
343
344 if ( turnflags & TTT_TURN_NEXT )
345 {
346 if ( (turnflags & TTT_TURN_TEAM) != minigame_self.team )
347 return _("Select \"^1Next Match^7\" on the menu to start a new match!");
348 return _("Wait for your opponent to confirm the rematch");
349 }
350
351 if ( (turnflags & TTT_TURN_TEAM) != minigame_self.team )
352 return _("Wait for your opponent to make their move");
353
354 if ( turnflags & TTT_TURN_PLACE )
355 return _("Click on the game board to place your piece");
356
357 return "";
358}
359
360const int TTT_AI_POSFLAG_A1 = 0x0001;
361const int TTT_AI_POSFLAG_A2 = 0x0002;
362const int TTT_AI_POSFLAG_A3 = 0x0004;
363const int TTT_AI_POSFLAG_B1 = 0x0008;
364const int TTT_AI_POSFLAG_B2 = 0x0010;
365const int TTT_AI_POSFLAG_B3 = 0x0020;
366const int TTT_AI_POSFLAG_C1 = 0x0040;
367const int TTT_AI_POSFLAG_C2 = 0x0080;
368const int TTT_AI_POSFLAG_C3 = 0x0100;
369
370// convert a flag to a position
371string ttt_ai_piece_flag2pos(int pieceflag)
372{
373 switch(pieceflag)
374 {
375 case TTT_AI_POSFLAG_A1:
376 return "a1";
377 case TTT_AI_POSFLAG_A2:
378 return "a2";
379 case TTT_AI_POSFLAG_A3:
380 return "a3";
381
382 case TTT_AI_POSFLAG_B1:
383 return "b1";
384 case TTT_AI_POSFLAG_B2:
385 return "b2";
386 case TTT_AI_POSFLAG_B3:
387 return "b3";
388
389 case TTT_AI_POSFLAG_C1:
390 return "c1";
391 case TTT_AI_POSFLAG_C2:
392 return "c2";
393 case TTT_AI_POSFLAG_C3:
394 return "c3";
395
396 default:
397 return string_null;
398 }
399}
400
401bool ttt_ai_checkmask(int piecemask, int checkflags)
402{
403 return checkflags && (piecemask & checkflags) == checkflags;
404}
405
406// get the third flag if the mask matches two of them
407int ttt_ai_1of3(int piecemask, int flag1, int flag2, int flag3)
408{
409 if ( ttt_ai_checkmask(piecemask,flag1|flag2|flag3) )
410 return 0;
411
412 if ( ttt_ai_checkmask(piecemask,flag1|flag2) )
413 return flag3;
414
415 if ( ttt_ai_checkmask(piecemask,flag3|flag2) )
416 return flag1;
417
418 if ( ttt_ai_checkmask(piecemask,flag3|flag1) )
419 return flag2;
420
421 return 0;
422}
423
424// Select a random flag in the mask
425int ttt_ai_random(int piecemask)
426{
427 if ( !piecemask )
428 return 0;
429
430 int f = 1;
431
433
434 for ( int i = 0; i < 9; ++i )
435 {
436 if ( piecemask & f )
438 f <<= 1;
439 }
440
441 LOG_TRACE(sprintf("TTT AI: selected %x from %x",
442 RandomSelection_chosen_float, piecemask) );
444}
445
446// Block/complete a 3 i na row
447int ttt_ai_block3 ( int piecemask, int piecemask_free )
448{
449 int r = 0;
450
451 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A1,TTT_AI_POSFLAG_A2,TTT_AI_POSFLAG_A3);
452 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_B1,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_B3);
453 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_C1,TTT_AI_POSFLAG_C2,TTT_AI_POSFLAG_C3);
454 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A1,TTT_AI_POSFLAG_B1,TTT_AI_POSFLAG_C1);
455 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A2,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_C2);
456 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A3,TTT_AI_POSFLAG_B3,TTT_AI_POSFLAG_C3);
457 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A1,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_C3);
458 r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A3,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_C1);
459 LOG_TRACE(sprintf("TTT AI: possible 3 in a rows in %x: %x (%x)",piecemask,r, r&piecemask_free));
460 r &= piecemask_free;
461 return ttt_ai_random(r);
462}
463
464// Simple AI
465// 1) tries to win the game if possible
466// 2) tries to block the opponent if they have 2 in a row
467// 3) places a piece randomly
468string ttt_ai_choose_simple(int piecemask_self, int piecemask_opponent, int piecemask_free )
469{
470 int move = 0;
471
472 LOG_TRACE("TTT AI: checking winning move");
473 if (( move = ttt_ai_block3(piecemask_self,piecemask_free) ))
474 return ttt_ai_piece_flag2pos(move); // place winning move
475
476 LOG_TRACE("TTT AI: checking opponent's winning move");
477 if (( move = ttt_ai_block3(piecemask_opponent,piecemask_free) ))
478 return ttt_ai_piece_flag2pos(move); // block opponent
479
480 LOG_TRACE("TTT AI: random move");
481 return ttt_ai_piece_flag2pos(ttt_ai_random(piecemask_free));
482}
483
484// AI move (if it's AI's turn)
485void ttt_aimove(entity minigame)
486{
487 if ( minigame.minigame_flags == (TTT_TURN_PLACE|minigame.ttt_ai) )
488 {
489 entity aiplayer = NULL;
490 while ( ( aiplayer = findentity(aiplayer,owner,minigame) ) )
491 if ( aiplayer.classname == "minigame_player" && !aiplayer.minigame_playerslot )
492 break;
493
494 /*
495 * Build bit masks for the board pieces
496 * .---.---.---.
497 * | 4 | 32|256| 3
498 * |---+---+---|
499 * | 2 | 16|128| 2
500 * |---+---+---|
501 * | 1 | 8 | 64| 1
502 * '---'---'---'
503 * A B C
504 */
505 int piecemask_self = 0;
506 int piecemask_opponent = 0;
507 int piecemask_free = 0;
508 int pieceflag = 1;
509 string pos;
510 for ( int i = 0; i < 3; ++i )
511 {
512 for ( int j = 0; j < 3; ++j )
513 {
514 pos = minigame_tile_buildname(i,j);
515 entity piece = ttt_find_piece(minigame,pos);
516 if ( piece )
517 {
518 if ( piece.team == aiplayer.team )
519 piecemask_self |= pieceflag;
520 else
521 piecemask_opponent |= pieceflag;
522 }
523 else
524 piecemask_free |= pieceflag;
525 pieceflag <<= 1;
526 }
527 }
528
529 // TODO multiple AI difficulties
530 LOG_TRACE(sprintf("TTT AI: self: %x opponent: %x free: %x",
531 piecemask_self, piecemask_opponent, piecemask_free));
532 pos = ttt_ai_choose_simple(piecemask_self, piecemask_opponent, piecemask_free);
533 LOG_TRACE("TTT AI: chosen move: ", pos);
534 if ( !pos )
535 LOG_TRACE("Tic Tac Toe AI has derped!");
536 else
537 ttt_move(minigame,aiplayer,pos);
538 }
539 strcpy(minigame.message, ttt_turn_to_string(minigame.minigame_flags));
540}
541
542// Make the correct move
543void ttt_make_move(entity minigame)
544{
545 if ( minigame.minigame_flags == (TTT_TURN_PLACE|minigame_self.team) )
546 {
547 if ( minigame.ttt_ai )
548 {
549 ttt_move(minigame, minigame_self, ttt_curr_pos );
550 ttt_aimove(minigame);
551 }
552 else
553 minigame_cmd("move ",ttt_curr_pos);
554 }
555}
556
557void ttt_set_curr_pos(string s)
558{
559 strfree(ttt_curr_pos);
560 if ( s )
561 s = strzone(s);
562 ttt_curr_pos = s;
563}
564
565// Required function, handle client events
566int ttt_client_event(entity minigame, string event, ...)
567{
568 switch(event)
569 {
570 case "activate":
571 {
572 ttt_set_curr_pos("");
573 strcpy(minigame.message, ttt_turn_to_string(minigame.minigame_flags));
574 return false;
575 }
576 case "deactivate":
577 {
578 strfree(minigame.message);
579 return false;
580 }
581 case "key_pressed":
582 case "key_released":
583 {
584 bool event_blocked = ((event == "key_released")
585 || ((minigame.minigame_flags & TTT_TURN_TEAM) != minigame_self.team));
586 if (!(minigame.minigame_flags & (TTT_TURN_WIN | TTT_TURN_DRAW)))
587 {
588 switch ( ...(0,int) )
589 {
590 case K_RIGHTARROW:
591 case K_KP_RIGHTARROW:
592 if (event_blocked)
593 return true;
594 if ( ! ttt_curr_pos )
595 ttt_set_curr_pos("a3");
596 else
597 ttt_set_curr_pos(minigame_relative_tile(ttt_curr_pos,1,0,TTT_LET_CNT,TTT_NUM_CNT));
598 return true;
599 case K_LEFTARROW:
600 case K_KP_LEFTARROW:
601 if (event_blocked)
602 return true;
603 if ( ! ttt_curr_pos )
604 ttt_set_curr_pos("c3");
605 else
606 ttt_set_curr_pos(minigame_relative_tile(ttt_curr_pos,-1,0,TTT_LET_CNT,TTT_NUM_CNT));
607 return true;
608 case K_UPARROW:
609 case K_KP_UPARROW:
610 if (event_blocked)
611 return true;
612 if ( ! ttt_curr_pos )
613 ttt_set_curr_pos("a1");
614 else
615 ttt_set_curr_pos(minigame_relative_tile(ttt_curr_pos,0,1,TTT_LET_CNT,TTT_NUM_CNT));
616 return true;
617 case K_DOWNARROW:
618 case K_KP_DOWNARROW:
619 if (event_blocked)
620 return true;
621 if ( ! ttt_curr_pos )
622 ttt_set_curr_pos("a3");
623 else
624 ttt_set_curr_pos(minigame_relative_tile(ttt_curr_pos,0,-1,TTT_LET_CNT,TTT_NUM_CNT));
625 return true;
626 case K_ENTER:
627 case K_KP_ENTER:
628 case K_SPACE:
629 if (event_blocked)
630 return true;
631 ttt_make_move(minigame);
632 return true;
633 }
634 }
635
636 return false;
637 }
638 case "mouse_pressed":
639 {
640 if(...(0,int) == K_MOUSE1)
641 {
642 ttt_client_event(minigame, "mouse_moved");
643 ttt_make_move(minigame);
644 return true;
645 }
646
647 return false;
648 }
649 case "mouse_moved":
650 {
651 vector mouse_pos = minigame_hud_normalize(mousepos,ttt_boardpos,ttt_boardsize);
652 if ( minigame.minigame_flags == (TTT_TURN_PLACE|minigame_self.team) )
653 ttt_set_curr_pos(minigame_tile_name(mouse_pos,TTT_LET_CNT,TTT_NUM_CNT));
654 if ( ! ttt_valid_tile(ttt_curr_pos) )
655 ttt_set_curr_pos("");
656
657 return true;
658 }
659 case "network_receive":
660 {
661 entity sent = ...(0,entity);
662 int sf = ...(1,int);
663 if ( sent.classname == "minigame" )
664 {
665 if ( sf & MINIG_SF_UPDATE )
666 {
667 strcpy(sent.message, ttt_turn_to_string(sent.minigame_flags));
668 if ( sent.minigame_flags & minigame_self.team )
670 }
671
672 if ( (sf & TTT_SF_SINGLEPLAYER) )
673 {
674 int ai = ReadByte();
675 bool spawnai = ai && !sent.ttt_ai;
676 sent.ttt_ai = ai;
677
678 if ( spawnai )
679 {
680 entity aiplayer = new(minigame_player);
681 aiplayer.owner = minigame;
682 aiplayer.team = ai;
683 aiplayer.minigame_playerslot = 0;
684 aiplayer.minigame_autoclean = 1;
685 ttt_aimove(minigame);
686 }
687
688 }
689 }
690 else if ( sent.classname == "minigame_player" && (sf & TTT_SF_PLAYERSCORE ) )
691 {
692 sent.minigame_flags = ReadByte();
693 }
694
695 return false;
696 }
697 case "menu_show":
698 {
699 HUD_MinigameMenu_CustomEntry(...(0,entity),_("Next Match"),"next");
700 HUD_MinigameMenu_CustomEntry(...(0,entity),_("Single Player"),"singleplayer");
701 return false;
702 }
703 case "menu_click":
704 {
705 if(...(0,string) == "next")
706 {
707 if ( minigame.ttt_ai )
708 {
710 ttt_aimove(minigame);
711 }
712 else
713 minigame_cmd("next");
714 }
715 else if ( ...(0,string) == "singleplayer" && !minigame.ttt_ai )
716 {
717 if ( minigame_count_players(minigame) == 1 )
718 minigame_cmd("singleplayer");
719 }
720 return false;
721 }
722 }
723
724 return false;
725}
726
727#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text, vector fontsize, float theAlpha, int drawflags)
void minigame_show_allspecs(vector boardpos, vector boardsize)
void minigame_prompt()
vector minigame_drawstring_wrapped(float maxwidth, vector pos, string text, vector fontsize, vector color, float theAlpha, int drawflags, float align)
void minigame_hud_simpleboard(vector pos, vector mySize, string board_texture)
string minigame_texture(string name)
vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize)
vector minigame_hud_denormalize(vector v, vector pos, vector mySize)
vector minigame_hud_normalize(vector v, vector pos, vector mySize)
void minigame_drawpic_centered(vector pos, string texture, vector sz, vector color, float thealpha, int drawflags)
#define REGISTER_MINIGAME(name, nicename)
entity minigame_self
entity active_minigame
#define minigame_hud_fitsqare(pos, mySize)
#define minigame_cmd(...)
#define FOREACH_MINIGAME_ENTITY(entityvar)
void HUD_MinigameMenu_CustomEntry(entity parent, string menumessage, string event_arg)
#define drawstring(position, text, scale, rgb, alpha, flag)
Definition draw.qh:27
#define drawpic(position, pic, size, rgb, alpha, flag)
Definition draw.qh:21
vector hud_fontsize
Definition main.qh:77
entity owner
Definition main.qh:87
int team
Definition main.qh:188
const float DRAWFLAG_NORMAL
const float DRAWFLAG_ADDITIVE
string entcs_GetName(int i)
Definition ent_cs.qh:151
float panel_fg_alpha
Definition hud.qh:169
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector mousepos
Definition hud.qh:103
float K_KP_RIGHTARROW
Definition keycodes.qc:60
float K_UPARROW
Definition keycodes.qc:15
float K_DOWNARROW
Definition keycodes.qc:16
float K_MOUSE1
Definition keycodes.qc:129
float K_RIGHTARROW
Definition keycodes.qc:18
float K_KP_UPARROW
Definition keycodes.qc:64
float K_SPACE
Definition keycodes.qc:10
float K_KP_LEFTARROW
Definition keycodes.qc:57
float K_ENTER
Definition keycodes.qc:8
float K_KP_DOWNARROW
Definition keycodes.qc:53
float K_LEFTARROW
Definition keycodes.qc:17
float K_KP_ENTER
Definition keycodes.qc:74
#define int
Definition _all.inc:20
const int MSG_ENTITY
Definition net.qh:156
int ReadByte()
#define LOG_TRACE(...)
Definition log.qh:76
entity findentity(entity start,.entity field, entity match)
string ftos(float f)
void WriteByte(float data, float dest, float desto)
string strzone(string s)
string argv(float n)
entity msle_spawn(entity minigame_session, entity e)
Definition minigames.qc:87
string minigame_relative_tile(string start_id, int dx, int dy, int rows, int columns)
Definition minigames.qc:40
void minigame_server_sendflags(entity ent, int mgflags)
Definition minigames.qc:78
int minigame_count_players(entity minigame)
Definition minigames.qc:121
int minigame_next_team(int curr_team, int n_teams)
Definition minigames.qc:65
int minigame_tile_letter(string id)
Definition minigames.qc:12
string minigame_tile_name(vector pos, int rows, int columns)
Definition minigames.qc:54
vector minigame_tile_pos(string id, int rows, int columns)
Definition minigames.qc:27
string minigame_tile_buildname(int letter, int number)
Definition minigames.qc:34
int minigame_tile_number(string id)
Definition minigames.qc:21
const int MINIG_SF_UPDATE
Definition minigames.qh:109
const int MINIG_SF_ALL
Definition minigames.qh:112
const int MINIG_SF_CUSTOM
Definition minigames.qh:110
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
float RandomSelection_chosen_float
Definition random.qh:6
#define RandomSelection_AddFloat(f, weight, priority)
Definition random.qh:15
vector
Definition self.qh:92
int int number
Definition impulse.qc:89
#define strfree(this)
Definition string.qh:59
#define strcpy(this, s)
Definition string.qh:52
const int TTT_TURN_TEAM2
Definition ttt.qc:11
const int TTT_SF_SINGLEPLAYER
Definition ttt.qc:16
const int TTT_TURN_TYPE
Definition ttt.qc:8
const int TTT_TURN_PLACE
Definition ttt.qc:4
const int TTT_SF_PLAYERSCORE
Definition ttt.qc:15
const int TTT_TURN_TEAM1
Definition ttt.qc:10
bool ttt_winning_piece(entity piece)
Definition ttt.qc:39
void ttt_move(entity minigame, entity player, string pos)
Definition ttt.qc:80
const int TTT_LET_CNT
Definition ttt.qc:20
const int TTT_TURN_DRAW
Definition ttt.qc:6
int ttt_server_event(entity minigame, string event,...)
Definition ttt.qc:137
int ttt_nexteam
Definition ttt.qc:25
const int TTT_SPECTATOR_TEAM
Definition ttt.qc:18
int ttt_npieces
Definition ttt.qc:24
const int TTT_TURN_TEAM
Definition ttt.qc:12
const int TTT_NUM_CNT
Definition ttt.qc:21
const int TTT_TURN_NEXT
Definition ttt.qc:7
entity ttt_find_piece(entity minig, string tile)
Definition ttt.qc:29
int ttt_ai
Definition ttt.qc:26
bool ttt_valid_tile(string tile)
Definition ttt.qc:70
void ttt_next_match(entity minigame, entity player)
Definition ttt.qc:110
const int TTT_TURN_WIN
Definition ttt.qc:5
const int TTT_TILE_SIZE
Definition ttt.qc:22