32 if ( number == letter || number+letter == 6 )
34 int add = letter < 3 ? 1 : -1;
35 return strcat(tile.netname,
" ",
39 else if ( letter == 3 )
43 else if ( letter < 3 )
58 if ( letter == number || letter+number == 6 )
60 int add = number < 3 ? 1 : -1;
61 return strcat(tile.netname,
" ",
65 else if ( number == 3 )
69 else if ( number < 3 )
86 entity e =
new(minigame_nmm_tile);
91 e.nmm_tile_distance = distance;
104 for (
int i = 0; i < 3; i++ )
107 for (
int j = 0; j < 3; j++ )
109 if ( i != 1 || j != 1 )
125 if ( e.classname ==
"minigame_nmm_tile" )
145 if ( e.classname ==
"minigame_nmm_tile" && e.netname ==
id )
157 return ( dnumber == 0 && ( dletter == 1 || dletter == tile1.nmm_tile_distance ) ) ||
158 ( dletter == 0 && ( dnumber == 1 || dnumber == tile1.nmm_tile_distance ) );
166 if ( e.classname ==
"minigame_nmm_tile" && !e.nmm_tile_piece
178 for (
int i = 0; i < argc; i++ )
181 if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team )
190 return tile.nmm_tile_piece && (
202 if ( e.classname ==
"minigame_board_piece" &&
203 (e.minigame_flags & pieceflags) && e.team == teamn )
209 int nmm_count_pieces(
entity minigame,
int teamn,
int pieceflags)
213 while (( e = nmm_find_piece(e,minigame, teamn, pieceflags) ))
219 int nmm_server_event(
entity minigame,
string event, ...)
221 if ( event ==
"start" )
226 for (
int i = 0; i < 7; i++ )
228 e =
msle_spawn(minigame,
new(minigame_board_piece));
231 e =
msle_spawn(minigame,
new(minigame_board_piece));
238 else if ( event ==
"end" )
242 else if ( event ==
"join" )
246 for ( e = minigame.minigame_players; e; e = e.list_next )
250 if ( minigame.minigame_players && minigame.minigame_players.team == 1 )
254 else if ( event ==
"cmd" )
257 int argc = ...(1,
int);
260 bool move_ok =
false;
262 if ( e && argc >= 2 &&
argv(0) ==
"move" &&
270 else if ( minigame.minigame_flags & NMM_TURN_PLACE )
272 piece = nmm_find_piece(
NULL,minigame,e.team,NMM_PIECE_HOME);
273 if ( !tile.nmm_tile_piece && piece )
275 tile.nmm_tile_piece = piece;
277 piece.origin = tile.origin;
282 else if ( minigame.minigame_flags & NMM_TURN_MOVE )
284 if ( tile.nmm_tile_piece && tile.nmm_tile_piece.team == e.team )
286 piece = tile.nmm_tile_piece;
290 tile.nmm_tile_piece =
NULL;
291 tile2.nmm_tile_piece = piece;
292 piece.origin = tile2.origin;
300 else if ( minigame.minigame_flags & NMM_TURN_FLY )
302 if ( tile.nmm_tile_piece && tile.nmm_tile_piece.team == e.team )
304 piece = tile.nmm_tile_piece;
306 if ( tile2 && !tile2.nmm_tile_piece )
308 tile.nmm_tile_piece =
NULL;
309 tile2.nmm_tile_piece = piece;
310 piece.origin = tile2.origin;
318 else if ( minigame.minigame_flags & NMM_TURN_TAKE )
320 piece = tile.nmm_tile_piece;
321 if ( piece && piece.nmm_tile_piece.team != e.team )
323 tile.nmm_tile_piece =
NULL;
330 int nextteam = e.team % 2 + 1;
331 int npieces = nmm_count_pieces(minigame,nextteam,NMM_PIECE_HOME|NMM_PIECE_BOARD);
335 minigame.minigame_flags = NMM_TURN_WIN | e.team;
340 if ( !(minigame.minigame_flags & NMM_TURN_TAKE) &&
nmm_in_mill(tile) )
342 minigame.minigame_flags = NMM_TURN_TAKE|e.team;
346 if ( f.classname ==
"minigame_nmm_tile" && f.nmm_tile_piece &&
347 f.nmm_tile_piece.team == nextteam && !
nmm_in_mill(f) )
352 minigame.minigame_flags |= takemill;
356 if ( nmm_find_piece(
NULL,minigame,nextteam,NMM_PIECE_HOME) )
357 minigame.minigame_flags = NMM_TURN_PLACE|nextteam;
358 else if ( npieces == 3 )
359 minigame.minigame_flags = NMM_TURN_FLY|nextteam;
362 minigame.minigame_flags = NMM_TURN_WIN|e.team;
365 if ( f.classname ==
"minigame_nmm_tile" && f.nmm_tile_piece &&
368 minigame.minigame_flags = NMM_TURN_MOVE|nextteam;
376 LOG_TRACE(
"Invalid move: ", ...(2,
string));
392 bool nmm_valid_selection(
entity tile)
394 if ( ( tile.owner.minigame_flags & NMM_TURN_TEAM ) !=
minigame_self.team )
396 if ( tile.owner.minigame_flags & NMM_TURN_PLACE )
397 return !tile.nmm_tile_piece;
398 if ( tile.owner.minigame_flags & NMM_TURN_MOVE )
400 if ( tile.nmm_tile_piece && tile.nmm_tile_piece.team ==
minigame_self.team &&
407 if ( tile.owner.minigame_flags & NMM_TURN_FLY )
410 return !tile.nmm_tile_piece;
412 return tile.nmm_tile_piece && tile.nmm_tile_piece.team ==
minigame_self.team;
414 if ( tile.owner.minigame_flags & NMM_TURN_TAKE )
415 return tile.nmm_tile_piece && tile.nmm_tile_piece.team !=
minigame_self.team &&
421 bool nmm_draw_avaliable(
entity tile)
423 if ( ( tile.owner.minigame_flags & NMM_TURN_TEAM ) !=
minigame_self.team )
425 if ( (tile.owner.minigame_flags & NMM_TURN_TAKE) )
427 if ( (tile.owner.minigame_flags & (NMM_TURN_FLY|NMM_TURN_MOVE)) && nmm_fromtile )
428 return !tile.nmm_tile_piece;
437 nmm_boardsize = mySize;
445 if ( e.classname ==
"minigame_nmm_tile" )
449 if ( e == nmm_fromtile )
454 else if ( nmm_draw_avaliable(e) && nmm_valid_selection(e) )
460 if ( e == nmm_currtile )
466 if ( e.nmm_tile_piece )
482 if ( e.classname ==
"minigame_player" &&
484 pname = entcs_GetName(e.minigame_playerslot-1);
486 vector win_pos = pos+
eY*(mySize_y-winfs_y)/2;
489 sprintf(_(
"%s^7 won the game!"), pname),
495 sprintf(_(
"%s^7 won the game!"), pname),
511 ts_y = ( mySize_y - 2*player_fontsize_y ) / 2;
516 vector piece_sz =
'48 48 0';
517 float piece_space = piece_sz_x + ( ts_x - 7 * piece_sz_x ) / 6;
519 float piece_light = 1;
526 mypos_y += player_fontsize_y + ts_y;
528 mypos_y += player_fontsize_y;
534 if ( e.classname ==
"minigame_player" && e.team != NMM_SPECTATOR_TEAM )
538 mypos_y += player_fontsize_y + ts_y;
540 entcs_GetName(e.minigame_playerslot-1),
543 else if ( e.classname ==
"minigame_board_piece" )
546 mypos_y += player_fontsize_y;
550 player2x += piece_space;
551 mypos_y += player_fontsize_y + ts_y;
556 player1x += piece_space;
558 if ( e.minigame_flags == NMM_PIECE_HOME )
560 else if ( e.minigame_flags == NMM_PIECE_BOARD )
572 void nmm_make_move(
entity minigame)
576 if ( minigame.minigame_flags & (NMM_TURN_PLACE|NMM_TURN_TAKE) )
581 else if ( (minigame.minigame_flags & (NMM_TURN_MOVE|NMM_TURN_FLY)) )
583 if ( nmm_fromtile == nmm_currtile )
587 else if ( nmm_currtile.nmm_tile_piece && nmm_currtile.nmm_tile_piece.team ==
minigame_self.team )
589 nmm_fromtile = nmm_currtile;
591 else if ( nmm_fromtile )
593 minigame_cmd(
"move ",nmm_fromtile.netname,
" ",nmm_currtile.netname);
602 string nmm_turn_to_string(
int turnflags)
605 return _(
"You are spectating");
607 if ( turnflags & NMM_TURN_WIN )
610 return _(
"You lost the game!");
611 return _(
"You win!");
615 return _(
"Wait for your opponent to make their move");
616 if ( turnflags & NMM_TURN_PLACE )
617 return _(
"Click on the game board to place your piece");
618 if ( turnflags & NMM_TURN_MOVE )
619 return _(
"You can select one of your pieces to move it in one of the surrounding places");
620 if ( turnflags & NMM_TURN_FLY )
621 return _(
"You can select one of your pieces to move it anywhere on the board");
622 if ( turnflags & NMM_TURN_TAKE )
623 return _(
"You can take one of the opponent's pieces");
629 int nmm_client_event(
entity minigame,
string event, ...)
631 if ( event ==
"activate" )
635 strcpy(minigame.message, nmm_turn_to_string(minigame.minigame_flags));
637 else if ( event ==
"deactivate" )
643 else if ( (event ==
"key_pressed" || event ==
"key_released") )
645 bool event_blocked = ((
event ==
"key_released")
646 || ((minigame.minigame_flags & NMM_TURN_TEAM) !=
minigame_self.team));
647 if (!(minigame.minigame_flags & NMM_TURN_WIN))
649 switch ( ...(0,
int) )
655 if ( ! nmm_currtile )
659 string tileid = nmm_currtile.netname;
661 while ( !nmm_currtile )
672 if ( ! nmm_currtile )
676 string tileid = nmm_currtile.netname;
678 while ( !nmm_currtile )
689 if ( ! nmm_currtile )
693 string tileid = nmm_currtile.netname;
695 while ( !nmm_currtile )
706 if ( ! nmm_currtile )
710 string tileid = nmm_currtile.netname;
712 while ( !nmm_currtile )
724 nmm_make_move(minigame);
730 else if ( event ==
"mouse_pressed" && ...(0,
int) ==
K_MOUSE1 )
732 nmm_client_event(minigame,
"mouse_moved");
733 nmm_make_move(minigame);
736 else if ( event ==
"mouse_moved" )
744 if ( e.classname ==
"minigame_nmm_tile" )
756 else if ( event ==
"network_receive" )
760 if ( sent.classname ==
"minigame_board_piece" && ( ...(1,
int) &
MINIG_SF_UPDATE ) )
764 if ( sent.minigame_flags & NMM_PIECE_BOARD )
768 if ( e.classname ==
"minigame_nmm_tile" )
770 if ( e.nmm_tile_piece == sent )
771 e.nmm_tile_piece =
NULL;
772 if ( e.netname == tileid )
773 e.nmm_tile_piece = sent;
777 else if ( sent.classname ==
"minigame" && ( ...(1,
int) &
MINIG_SF_UPDATE ) )
779 strcpy(sent.message, nmm_turn_to_string(sent.minigame_flags));
REGISTER_MINIGAME(nmm, _("Nine Men's Morris"))
int minigame_tile_number(string id)
bool nmm_tile_canmove(entity tile)
string nmm_tile_build_hmill(entity tile)
void nmm_init_tiles(entity minig)
const int NMM_SPECTATOR_TEAM
#define FOREACH_MINIGAME_ENTITY(entityvar)
vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize)
#define minigame_hud_fitsqare(pos, mySize)
entity msle_spawn(entity minigame_session, entity e)
string nmm_tile_build_vmill(entity tile)
void nmm_spawn_tile_square(entity minig, int offset, int skip)
const int NMM_PIECE_BOARD
bool nmm_in_mill_string(entity tile, string s)
void nmm_kill_tiles(entity minig)
bool nmm_in_mill(entity tile)
const int MINIG_SF_UPDATE
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)
entity nmm_find_tile(entity minig, string id)
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"))
const float DRAWFLAG_NORMAL
int minigame_tile_letter(string id)
#define minigame_cmd(...)
string minigame_tile_buildname(int letter, int number)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
bool nmm_tile_adjacent(entity tile1, entity tile2)
string minigame_relative_tile(string start_id, int dx, int dy, int rows, int columns)
const int NMM_TURN_TAKEANY
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)
bool minigame_hud_mouse_in(vector pos, vector sz)
void nmm_spawn_tile(string id, entity minig, int distance)
vector minigame_drawstring_wrapped(float maxwidth, vector pos, string text, vector fontsize, vector color, float theAlpha, int drawflags, float align)