コード例 #1
0
ファイル: makeflow_common.c プロジェクト: LyonsLab/cctools
void dag_parse_node_set_command(struct lexer_book *bk, struct dag_node *n, char *command)
{
	struct dag_lookup_set s = { bk->d, bk->category, n, NULL };
	char *local = dag_lookup_str("BATCH_LOCAL", &s);

	if(local) {
		if(string_istrue(local))
			n->local_job = 1;
		free(local);
	}

	n->original_command = xxstrdup(command);
	n->command = translate_command(n, command, n->local_job);
	debug(D_DEBUG, "node command=%s", n->command);
}
コード例 #2
0
ファイル: game_chess.c プロジェクト: Onirik79/bardmud
/*
 * Comando per gestire il gioco degli scacchi
 */
void do_chess( CHAR_DATA *ch, char *argument )
{
	CHESSBOARD_DATA *board;
	char			 arg[MIL];

	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "do_chess: ch è NULL" );
		return;
	}

	if ( IS_MOB(ch) )
	{
		send_to_char( ch, "I mob non possono giocare a scacchi.\r\n" );
		return;
	}

	board = get_chessboard( ch );

	if ( !VALID_STR(argument) || is_name(argument, "sintassi aiuto syntax help ?") )
	{
		char	*cmd;

		cmd = translate_command( ch, "chess" );
		ch_printf( ch, "&YSintassi gioco&w:  %s inizio|smetto|partecipo|forfeit\r\n", cmd );
		ch_printf( ch, "&YSintassi info&w:   %s pezzi\r\n", cmd );
		ch_printf( ch, "&YSintassi mosse&w:  %s muovo <sorgente> <destinazione> [comandi opzionali]\r\n", cmd );
		ch_printf( ch, "&YSintassi extra&w:  %s arrocco|promuovo\r\n", cmd );

		if ( !VALID_STR(argument) && board )
		{
			send_to_char( ch, "\r\n" );
			show_status( ch, board );
			send_to_char( ch, "\r\n" );
			show_board( ch, board );
		}

		return;
	}

	argument = one_argument( argument, arg );

	if ( is_name_prefix(arg, "inizio inizia comincio comincia cominciare start") )
	{
		CHESSBOARD_DATA *newboard;

		if ( board )
		{
			send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" );
			return;
		}

		CREATE( newboard, CHESSBOARD_DATA, 1 );
		init_board( newboard );
		newboard->player1	= ch;
		newboard->turn		= ch;

		LINK( newboard, first_chessboard, last_chessboard, next, prev );
		top_chessboard++;

		send_to_char( ch, "Inizio una nuova partita di scacchi.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "partecipa partecipo join") )
	{
		CHESSBOARD_DATA *vboard = NULL;
		CHAR_DATA		*vch;
		char			 arg2[MIL];

		if ( board )
		{
			send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" );
			return;
		}

		argument = one_argument( argument, arg2 );
		if ( !VALID_STR(arg2) )
		{
			send_to_char( ch, "Con chi devo partecipare ad una partita di scacchi?\r\n" );
			return;
		}

		vch = get_player_room( ch, arg2, TRUE );
		if ( !vch )
		{
			ch_printf( ch, "Non vedo nessun %s nella stanza.\r\n", arg2 );
			return;
		}

		vboard = get_chessboard( vch );
		if ( !vboard )
		{
			send_to_char( ch, "Non sta giocando a scacchi.\r\n" );
			return;
		}

		if ( vboard->player2 )
		{
			send_to_char( ch, "Questa scacchiera ha già due giocatori.\r\n" );
			return;
		}

		vboard->player2 = ch;
		vboard->turn	= vboard->player2;

		send_to_char( ch, "Mi unisco alla partita, è il mio turno.\r\n" );
		ch_printf( vboard->player1, "%s si unisce alla tua partita.\r\n", ch->name );
		return;
	}

	if ( is_name_prefix(arg, "pezzi pieces") )
	{
		int		x;	/* contatore dei colori */
		int		y;	/* contatore dei pezzi */

		for ( x = 0;  x < COLOR_NONE;  x++ )
		{
			if ( x == COLOR_BLACK )
				send_to_char( ch, "\r\n\r\nPezzi neri:\r\n" );
			else
				send_to_char( ch, "Pezzi bianchi:\r\n" );

			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				ch_printf( ch, "%-7s", table_pieces[y].name );

			send_to_char( ch, "\r\n" );
			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph1 : table_pieces[y].bgraph1 );

			send_to_char( ch, "\r\n" );
			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph2 : table_pieces[y].bgraph2 );
		}
		send_to_char( ch, "\r\n" );
		return;
	}

	if ( !board )
	{
		send_to_char( ch, "Non ho iniziato o non sto partecipando a nessuna partita di scacchi.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "smetto fermo stop") )
	{
		free_chessboard( board );
		return;
	}

	if ( is_name_prefix(arg, "forfeit") )
	{
		send_to_char( ch, "Dò forfeit così perdendo.\r\n" );
		free_chessboard( board );
		return;
	}

	if ( !board->player1 || !board->player2 )
	{
		send_to_char( ch, "C'è solo un giocatore.\r\n" );
		return;
	}

	if ( board->moves < 0 )
	{
		send_to_char( ch, "Il gioco non è ancora iniziato.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "promuovo promuovi promote") )
	{
		int		piece = board->piece[board->lastx][board->lasty];
		char	extra[MIL];

		if ( !((piece == PIECE_PAWN && board->player1 == ch)
		  ||   (piece == PIECE_PAWN && board->player2 == ch)) )
		{
			send_to_char( ch, "Non posso promuovere questo pezzo.\r\n" );
			return;
		}

		if ( (piece == PIECE_PAWN && board->lastx != 0)
		  || (piece == PIECE_PAWN && board->lastx != 7) )
		{
			send_to_char( ch, "Puoi promuovere solamente i pedoni che hanno raggiunto l'altro lato della scacchiera.\r\n" );
			return;
		}

		if ( !VALID_STR(argument) )
		{
			send_to_char( ch, "Vorrei promuovere il pedone in che cosa?\r\n" );
			return;
		}

		if		( is_name_prefix(argument, "regina queen"  ) )	piece = PIECE_QUEEN;
		else if ( is_name_prefix(argument, "alfiere bishop") )	piece = PIECE_BISHOP;
		else if ( is_name_prefix(argument, "cavallo knight") )	piece = PIECE_KNIGHT;
		else if ( is_name_prefix(argument, "torre rook"	   ) )	piece = PIECE_ROOK;
		else
		{
			ch_printf( ch, "Non posso promuoverlo a %s.\r\n", argument );
			return;
		}

		board->piece[board->lastx][board->lasty] = piece;
		sprintf( extra, "%s (%c%d)", table_pieces[piece].name, board->lastx+'a', board->lasty+1 );
		board_move_messages( ch, MOVE_PROMOTE, extra );
		return;
	}

	if ( board->turn != ch )
	{
		send_to_char( ch, "Non è il mio turno.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "arrocco") )
	{
		int 	myx;
		int 	rooky;
		int 	kdy;
		int		rdy;
		bool	fRookShort;

		if ( king_in_check(board, PIECE_KING, (board->player1 == ch) ? COLOR_BLACK : COLOR_WHITE) > 0 )
		{
			send_to_char( ch, "Non posso eseguire un arrocco mentre sono sotto scacco.\r\n" );
			return;
		}

		if ( (board->player1 == ch && HAS_BIT(board->flags1, CHESSFLAG_MOVEDKING))
		  || (board->player2 == ch && HAS_BIT(board->flags2, CHESSFLAG_MOVEDKING)) )
		{
			send_to_char( ch, "Non posso effettuare un arrocco quando ho già mosso il mio re.\r\n" );
			return;
		}
		myx = (board->player1 == ch) ? 7 : 0;

		if ( !VALID_STR(argument) )
		{
			ch_printf( ch, "Utilizzo: %s arrocco corto|lungo\r\n", translate_command(ch, "chess") );
			return;
		}

		if ( is_name_prefix(argument, "corto short") )
			fRookShort = TRUE;
		else if ( is_name_prefix(argument, "lungo long") )
			fRookShort = FALSE;
		else
		{
			send_command( ch, "chess arrocco", CO );
			return;
		}

		if ( (board->player1 == ch && HAS_BIT(board->flags1, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK))
		  || (board->player2 == ch && HAS_BIT(board->flags2, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK)) )
		{
			ch_printf( ch, "Non posso effettuare l'arrocco %s perchè ho già mosso la torre prima.\r\n",
				fRookShort ? "corto" : "lungo" );
			return;
		}
		rooky = fRookShort ? 7 : 0;

		if ( ( fRookShort && (board->piece[myx][6] != PIECE_NONE || board->piece[myx][5] != PIECE_NONE))
		  || (!fRookShort && (board->piece[myx][1] != PIECE_NONE || board->piece[myx][2] != PIECE_NONE || board->piece[myx][3] != PIECE_NONE)) )
		{
			send_to_char( ch, "L'arrocco è bloccato dalla presenza di pezzi tra il re e la torre.\r\n" );
			return;
		}

		/* castling succeeded */
		if ( fRookShort )
		{
			kdy = 6;
			rdy = 5;
		}
		else
		{
			kdy = 2;
			rdy = 3;
		}

/* (FF) (TT) (RR) (bb) ricordo che una qualsiasi delle caselle, in cui avveniva l'arrocco
 *	non dovevano essere sotto scacco, mi sa che qui non è così, o forse ricordo sbagliato */

		/* check for 'move across check' rule */
		board->piece[myx][rdy] = board->piece[myx][4];
		board->piece[myx][4] = PIECE_NONE;

		if ( king_in_check(board, board->piece[myx][rdy], board->color[myx][rdy]) > 0 )
		{
			send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" );

			board->piece[myx][4] = board->piece[myx][rdy];
			board->piece[myx][rdy] = PIECE_NONE;
			return;
		}

		board->piece[myx][kdy] = board->piece[myx][rdy];
		board->piece[myx][rdy] = board->piece[myx][rooky];
		board->piece[myx][rooky] = PIECE_NONE;

		/* check for 'check' after castled */
		if ( king_in_check(board, board->piece[myx][kdy], board->color[myx][kdy]) > 0 )
		{
			send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" );

			board->piece[myx][4] = board->piece[myx][kdy];
			board->piece[myx][kdy] = PIECE_NONE;
			board->piece[myx][rooky] = board->piece[myx][rdy];
			board->piece[myx][rdy] = PIECE_NONE;
			return;
		}

		/* Basta indicare che è stato mosso il re per evitare un altro arrocco */
		if ( board->player1 == ch )
			SET_BIT( board->flags1, CHESSFLAG_MOVEDKING );
		else
			SET_BIT( board->flags2, CHESSFLAG_MOVEDKING );

		board_move_stuff( board );
		board_move_messages( ch, MOVE_CASTLE, rooky == 7 ? "corto" : "lungo" );
	}

	if ( is_name_prefix(arg, "muovo move") )
	{
		char	coord1[MIL];
		char	coord2[MIL];
		char	extra[MIL];
		int		x, y, dx, dy;
		int		ret;

		if ( !VALID_STR(argument) )
		{
			ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") );
			return;
		}

		argument = one_argument( argument, coord1 );
		argument = one_argument( argument, coord2 );

		if ( !VALID_STR(coord1) || !VALID_STR(coord2) )
		{
			ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") );
			return;
		}

		get_coord( coord1, &x, &y );
		get_coord( coord2, &dx, &dy );

		if ( x < 0 || x >= 8 || dx < 0 || dx >= 8
		  || y < 0 || y >= 8 || dy < 0 || dy >= 8 )
		{
			send_to_char( ch, "Mossa non valida, utilizza a-h e 1-8 (esempio: a4 b4).\r\n" );
			return;
		}

		extra[0] = '\0';

		ret = is_valid_move( ch, board, x, y, dx, dy );
		if ( ret == MOVE_OK || ret == MOVE_TAKEN )
		{
			int	piece;
			int	color;
			int	destpiece;
			int	destcolor;

			piece	  = board->piece[x][y];
			color	  = board->color[x][y];
			destpiece = board->piece[dx][dy];
			destcolor = board->color[dx][dy];

			board->piece[dx][dy] = piece;
			board->color[dx][dy] = color;
			board->piece[x][y] = PIECE_NONE;
			board->color[x][y] = COLOR_NONE;

			if ( king_in_check(board, PIECE_KING, board->color[dx][dy]) > 0 )
			{
				board->piece[dx][dy] = destpiece;
				board->color[dx][dy] = destcolor;
				board->piece[x][y]	 = piece;
				board->color[x][y]	 = color;
				ret = MOVE_INCHECK;
			}
			else
			{
				if ( destpiece == PIECE_NONE )
					sprintf( extra, "%c%d (%s) alle coordinate %c%d", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1 );
				else
					sprintf( extra, "%c%d (%s) alle coordinate %c%d (%s)", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1, table_pieces[destpiece].name );

				board_move_stuff( board );
				board->lastx = dx;
				board->lasty = dy;

				/* Imposta le flag per evitare gli arrocchi */
				if ( piece == PIECE_ROOK )
				{
					if ( color == COLOR_WHITE )
					{
						if ( y == 0 && x == 0 )
							SET_BIT( board->flags1, CHESSFLAG_MOVEDKROOK );
						else if ( y == 0 && x == 7 )
							SET_BIT( board->flags1, CHESSFLAG_MOVEDQROOK );
					}
					else
					{
						if ( y == 7 && x == 0 )
							SET_BIT( board->flags2, CHESSFLAG_MOVEDKROOK );
						else if ( y == 7 && x == 7 )
							SET_BIT( board->flags2, CHESSFLAG_MOVEDQROOK );
					}
				}
				else if ( piece == PIECE_KING )
				{
					if ( color == COLOR_WHITE )
						SET_BIT( board->flags1, CHESSFLAG_MOVEDKING );
					else
						SET_BIT( board->flags2, CHESSFLAG_MOVEDKING );
				}
			}

			board_move_messages( ch, ret, extra );
		}

		/* Così qui gestisce i comandi opzionali, come il promote */
		if ( VALID_STR(argument) )
		{
			do_chess( ch, argument );
			return;
		}
		return;
	}

	send_command( ch, "chess aiuto", CO );
}