31 if ( e.classname ==
"minigame_board_piece" && e.netname == tile )
50 if(p.team == piece.team)
55 for(i = letter; i >= 0; --i)
58 if(p.team == piece.team)
64 for(i = letter, j = number; i >= 0, j >= 0; --i, --j)
67 if(p.team == piece.team)
71 for(i = letter, j = number; i >= 0, j <
C4_NUM_CNT; --i, ++j)
74 if(p.team == piece.team)
88 if(found >= C4_WIN_CNT)
100 if(found >= C4_WIN_CNT)
112 if(found >= C4_WIN_CNT)
124 if(found >= C4_WIN_CNT)
137 return 0 <= number && number < C4_NUM_CNT && 0 <= letter && letter <
C4_LET_CNT;
144 for(i = C4_NUM_CNT; i >= 0; --i)
161 if ( minigame.minigame_flags & C4_TURN_PLACE )
162 if ( pos && player.team == (minigame.minigame_flags & C4_TURN_TEAM) )
168 piece.team = player.team;
172 minigame.c4_npieces++;
176 minigame.minigame_flags = C4_TURN_WIN | player.team;
178 else if ( minigame.c4_npieces >= C4_MAX_TILES )
181 minigame.minigame_flags = C4_TURN_PLACE | minigame.c4_nexteam;
190 int c4_server_event(
entity minigame,
string event, ...)
203 if(e.classname ==
"minigame_board_piece")
218 if(minigame.minigame_players)
257 c4_boardsize = mySize;
279 if ( e.classname ==
"minigame_board_piece" )
285 if ( !e.c4_checkwin )
288 float icon_color = 1;
289 if ( e.c4_checkwin == -1 )
291 else if ( e.c4_checkwin == 1 )
309 if ( e.classname ==
"minigame_player" &&
311 pname = entcs_GetName(e.minigame_playerslot-1);
313 vector win_pos = pos+
eY*(mySize_y-winfs_y)/2;
316 sprintf(_(
"%s^7 won the game!"), pname),
322 sprintf(_(
"%s^7 won the game!"), pname),
340 ts_y = ( mySize_y - 2*player_fontsize_y ) / 2;
343 vector tile_size =
'48 48 0';
349 mypos_y += player_fontsize_y + ts_y;
351 mypos_y += player_fontsize_y;
358 if ( e.classname ==
"minigame_player" && e.team != C4_SPECTATOR_TEAM )
362 mypos_y += player_fontsize_y + ts_y;
364 entcs_GetName(e.minigame_playerslot-1),
367 mypos_y += player_fontsize_y;
372 mypos_x += tile_size_x;
378 string c4_turn_to_string(
int turnflags)
381 return _(
"You are spectating");
383 if ( turnflags & C4_TURN_DRAW )
386 if ( turnflags & C4_TURN_WIN )
389 return _(
"You lost the game!");
390 return _(
"You win!");
394 return _(
"Wait for your opponent to make their move");
396 if ( turnflags & C4_TURN_PLACE )
397 return _(
"Click on the game board to place your piece");
403 void c4_make_move(
entity minigame)
405 if ( minigame.minigame_flags == (C4_TURN_PLACE|
minigame_self.team) )
411 void c4_set_curr_pos(
string s)
420 int c4_client_event(
entity minigame,
string event, ...)
427 strcpy(minigame.message, c4_turn_to_string(minigame.minigame_flags));
438 bool event_blocked = ((
event ==
"key_released")
439 || ((minigame.minigame_flags & C4_TURN_TEAM) !=
minigame_self.team));
440 if (!(minigame.minigame_flags & C4_TURN_WIN) && !(minigame.minigame_flags &
C4_TURN_DRAW))
442 switch ( ...(0,
int) )
490 c4_make_move(minigame);
497 case "mouse_pressed":
501 c4_client_event(minigame,
"mouse_moved");
502 c4_make_move(minigame);
511 if ( minigame.minigame_flags == (C4_TURN_PLACE|
minigame_self.team) )
520 case "network_receive":
524 if ( sent.classname ==
"minigame" )
528 strcpy(sent.message, c4_turn_to_string(sent.minigame_flags));
int minigame_tile_number(string id)
void minigame_server_sendflags(entity ent, int mgflags)
bool c4_valid_tile(string tile)
#define FOREACH_MINIGAME_ENTITY(entityvar)
vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize)
const float C4_TURN_TEAM2
#define minigame_hud_fitsqare(pos, mySize)
entity msle_spawn(entity minigame_session, entity e)
int minigame_next_team(int curr_team, int n_teams)
vector minigame_hud_normalize(vector v, vector pos, vector mySize)
bool c4_winning_piece(entity piece)
string c4_get_lowest_tile(entity minigame, string s)
const int MINIG_SF_UPDATE
const float C4_TURN_PLACE
const float C4_TURN_TEAM1
string minigame_tile_name(vector pos, int rows, int columns)
const float DRAWFLAG_ADDITIVE
#define HUD_Panel_DrawBg()
void minigame_drawpic_centered(vector pos, string texture, vector sz, vector color, float thealpha, int drawflags)
string minigame_texture(string name)
vector minigame_tile_pos(string id, int rows, int columns)
vector minigame_drawcolorcodedstring_wrapped(float maxwidth, vector pos, string text, vector fontsize, float theAlpha, int drawflags, float align)
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
REGISTER_MINIGAME(c4, _("Connect Four"))
const float DRAWFLAG_NORMAL
int minigame_tile_letter(string id)
entity c4_find_piece(entity minig, string tile)
#define minigame_cmd(...)
string minigame_tile_buildname(int letter, int number)
void c4_move(entity minigame, entity player, string pos)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
string minigame_relative_tile(string start_id, int dx, int dy, int rows, int columns)
int minigame_count_players(entity minigame)
const int C4_SPECTATOR_TEAM
vector minigame_hud_denormalize(vector v, vector pos, vector mySize)
void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text, vector fontsize, float theAlpha, int drawflags)
void minigame_hud_simpleboard(vector pos, vector mySize, string board_texture)
vector minigame_drawstring_wrapped(float maxwidth, vector pos, string text, vector fontsize, vector color, float theAlpha, int drawflags, float align)