#include "nmm.qh"
-#ifdef CSQC
-#include <client/miscfunctions.qh>
-#endif
-
REGISTER_MINIGAME(nmm, _("Nine Men's Morris"));
const int NMM_TURN_PLACE = 0x0100; // player has to place a piece on the board
const int NMM_PIECE_HOME = 0x1; // not yet placed
const int NMM_PIECE_BOARD = 0x2; // placed on the board
+const int NMM_SPECTATOR_TEAM = 255; // must be above max teams and equal to or below 255
+
.int nmm_tile_distance;
.entity nmm_tile_piece;
.string nmm_tile_hmill;
{
int letter = offset;
int number = offset;
- for ( int i = 0; i < 3; i++ )
+ for ( int i = 0; i < 3; ++i )
{
number = offset;
- for ( int j = 0; j < 3; j++ )
+ for ( int j = 0; j < 3; ++j )
{
if ( i != 1 || j != 1 )
nmm_spawn_tile(strzone(minigame_tile_buildname(letter,number)),minig, skip+1);
bool nmm_in_mill_string(entity tile, string s)
{
int argc = tokenize(s);
- for ( int i = 0; i < argc; i++ )
+ for ( int i = 0; i < argc; ++i )
{
entity e = nmm_find_tile(tile.owner,argv(i));
if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team )
minigame.minigame_flags = NMM_TURN_PLACE|NMM_TURN_TEAM1;
nmm_init_tiles(minigame);
entity e;
- for ( int i = 0; i < 7; i++ )
+ for ( int i = 0; i < 7; ++i )
{
- e = msle_spawn(minigame,"minigame_board_piece");
+ e = msle_spawn(minigame,new(minigame_board_piece));
e.team = 1;
e.minigame_flags = NMM_PIECE_HOME;
- e = msle_spawn(minigame,"minigame_board_piece");
+ e = msle_spawn(minigame,new(minigame_board_piece));
e.team = 2;
e.minigame_flags = NMM_PIECE_HOME;
}
for ( e = minigame.minigame_players; e; e = e.list_next )
n++;
if ( n >= 2 )
- return 0;
+ return NMM_SPECTATOR_TEAM;
if ( minigame.minigame_players && minigame.minigame_players.team == 1 )
return 2;
return 1;
sprintf(_("%s^7 won the game!"), pname),
winfs, 0, DRAWFLAG_NORMAL, 0.5);
- drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
+ drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
sprintf(_("%s^7 won the game!"), pname),
winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
}
+
+ minigame_show_allspecs(nmm_boardpos, nmm_boardsize);
}
// Required function, draw the game status panel
float piece_light = 1;
entity e = NULL;
- mypos = pos;
- if ( (active_minigame.minigame_flags&NMM_TURN_TEAM) == 2 )
- mypos_y += player_fontsize_y + ts_y;
- drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
- mypos_y += player_fontsize_y;
- drawfill(mypos,eX*mySize_x+eY*piece_sz_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
+ if(minigame_self.team != NMM_SPECTATOR_TEAM)
+ {
+ mypos = pos;
+ if ( (active_minigame.minigame_flags&NMM_TURN_TEAM) == 2 )
+ mypos_y += player_fontsize_y + ts_y;
+ drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
+ mypos_y += player_fontsize_y;
+ drawfill(mypos,eX*mySize_x+eY*piece_sz_y,'1 1 1',0.25*panel_fg_alpha,DRAWFLAG_ADDITIVE);
+ }
FOREACH_MINIGAME_ENTITY(e)
{
- if ( e.classname == "minigame_player" )
+ if ( e.classname == "minigame_player" && e.team != NMM_SPECTATOR_TEAM )
{
mypos = pos;
if ( e.team == 2 )
string nmm_turn_to_string(int turnflags)
{
+ if( minigame_self.team == NMM_SPECTATOR_TEAM )
+ return _("You are spectating");
+
if ( turnflags & NMM_TURN_WIN )
{
if ( (turnflags&NMM_TURN_TEAM) != minigame_self.team )
nmm_kill_tiles(minigame);
strfree(minigame.message);
}
- else if ( event == "key_pressed" && (minigame.minigame_flags&NMM_TURN_TEAM) == minigame_self.team )
+ else if ( (event == "key_pressed" || event == "key_released") )
{
- switch ( ...(0,int) )
+ bool event_blocked = ((event == "key_released")
+ || ((minigame.minigame_flags & NMM_TURN_TEAM) != minigame_self.team));
+ if (!(minigame.minigame_flags & NMM_TURN_WIN))
{
- case K_RIGHTARROW:
- case K_KP_RIGHTARROW:
- if ( ! nmm_currtile )
- nmm_currtile = nmm_find_tile(active_minigame,"a7");
- else
- {
- string tileid = nmm_currtile.netname;
- nmm_currtile = NULL;
- while ( !nmm_currtile )
+ switch ( ...(0,int) )
+ {
+ case K_RIGHTARROW:
+ case K_KP_RIGHTARROW:
+ if (event_blocked)
+ return true;
+ if ( ! nmm_currtile )
+ nmm_currtile = nmm_find_tile(active_minigame,"a7");
+ else
{
- tileid = minigame_relative_tile(tileid,1,0,7,7);
- nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ string tileid = nmm_currtile.netname;
+ nmm_currtile = NULL;
+ while ( !nmm_currtile )
+ {
+ tileid = minigame_relative_tile(tileid,1,0,7,7);
+ nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ }
}
- }
- return 1;
- case K_LEFTARROW:
- case K_KP_LEFTARROW:
- if ( ! nmm_currtile )
- nmm_currtile = nmm_find_tile(active_minigame,"g7");
- else
- {
- string tileid = nmm_currtile.netname;
- nmm_currtile = NULL;
- while ( !nmm_currtile )
+ return 1;
+ case K_LEFTARROW:
+ case K_KP_LEFTARROW:
+ if (event_blocked)
+ return true;
+ if ( ! nmm_currtile )
+ nmm_currtile = nmm_find_tile(active_minigame,"g7");
+ else
{
- tileid = minigame_relative_tile(tileid,-1,0,7,7);
- nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ string tileid = nmm_currtile.netname;
+ nmm_currtile = NULL;
+ while ( !nmm_currtile )
+ {
+ tileid = minigame_relative_tile(tileid,-1,0,7,7);
+ nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ }
}
- }
- return 1;
- case K_UPARROW:
- case K_KP_UPARROW:
- if ( ! nmm_currtile )
- nmm_currtile = nmm_find_tile(active_minigame,"a1");
- else
- {
- string tileid = nmm_currtile.netname;
- nmm_currtile = NULL;
- while ( !nmm_currtile )
+ return 1;
+ case K_UPARROW:
+ case K_KP_UPARROW:
+ if (event_blocked)
+ return true;
+ if ( ! nmm_currtile )
+ nmm_currtile = nmm_find_tile(active_minigame,"a1");
+ else
{
- tileid = minigame_relative_tile(tileid,0,1,7,7);
- nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ string tileid = nmm_currtile.netname;
+ nmm_currtile = NULL;
+ while ( !nmm_currtile )
+ {
+ tileid = minigame_relative_tile(tileid,0,1,7,7);
+ nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ }
}
- }
- return 1;
- case K_DOWNARROW:
- case K_KP_DOWNARROW:
- if ( ! nmm_currtile )
- nmm_currtile = nmm_find_tile(active_minigame,"a7");
- else
- {
- string tileid = nmm_currtile.netname;
- nmm_currtile = NULL;
- while ( !nmm_currtile )
+ return 1;
+ case K_DOWNARROW:
+ case K_KP_DOWNARROW:
+ if (event_blocked)
+ return true;
+ if ( ! nmm_currtile )
+ nmm_currtile = nmm_find_tile(active_minigame,"a7");
+ else
{
- tileid = minigame_relative_tile(tileid,0,-1,7,7);
- nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ string tileid = nmm_currtile.netname;
+ nmm_currtile = NULL;
+ while ( !nmm_currtile )
+ {
+ tileid = minigame_relative_tile(tileid,0,-1,7,7);
+ nmm_currtile = nmm_find_tile(active_minigame,tileid);
+ }
}
- }
- return 1;
- case K_ENTER:
- case K_KP_ENTER:
- case K_SPACE:
- nmm_make_move(minigame);
- return 1;
+ return 1;
+ case K_ENTER:
+ case K_KP_ENTER:
+ case K_SPACE:
+ if (event_blocked)
+ return true;
+ nmm_make_move(minigame);
+ return 1;
+ }
}
return 0;
}
else if ( event == "mouse_pressed" && ...(0,int) == K_MOUSE1 )
{
+ nmm_client_event(minigame, "mouse_moved");
nmm_make_move(minigame);
return 1;
}