void PAWN::promote(PIECETYPE promoteType) { switch (promoteType) { case TYPEQUEEN: promotePiece = new QUEEN(whatColor()); break; case TYPEROOK: promotePiece = new ROOK(whatColor()); break; case TYPEBISHOP: promotePiece = new BISHOP(whatColor()); break; case TYPEKNIGHT: promotePiece = new KNIGHT(whatColor()); break; } if (!promotePiece) OutOfMemory(); return; }
/* Display the map to the player */ void show_map( CHAR_DATA * ch, char *text ) { char buf[MAX_STRING_LENGTH * 2]; int x, y, pos; char *p; bool alldesc = FALSE; /* Has desc been fully displayed? */ if ( !text ) alldesc = TRUE; pos = 0; p = text; buf[0] = '\0'; /* * Show exits */ if ( xIS_SET( ch->act, PLR_AUTOEXIT ) ) snprintf( buf, MAX_STRING_LENGTH * 2, "%s%s", color_str( AT_EXITS, ch ), get_exits( ch ) ); else mudstrlcpy( buf, "", MAX_STRING_LENGTH * 2 ); /* * Top of map frame */ mudstrlcat( buf, "&z+-----------+&w ", MAX_STRING_LENGTH * 2 ); if ( !alldesc ) { pos = get_line( p, 63 ); if ( pos > 0 ) { mudstrlcat( buf, color_str( AT_RMDESC, ch ), MAX_STRING_LENGTH * 2 ); strncat( buf, p, pos ); p += pos; } else { mudstrlcat( buf, color_str( AT_RMDESC, ch ), MAX_STRING_LENGTH * 2 ); mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 ); alldesc = TRUE; } } mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 ); /* * Write out the main map area with text */ for ( y = 0; y <= MAPY; ++y ) { mudstrlcat( buf, "&z|&D", MAX_STRING_LENGTH * 2 ); for ( x = 0; x <= MAPX; ++x ) { switch ( dmap[x][y].tegn ) { case '-': case '|': case '\\': case '/': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&O%c&d", dmap[x][y].tegn ); break; case '@': // Character is standing here snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&R%c&d", dmap[x][y].tegn ); break; case 'O': // Indoors snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&w%c&d", dmap[x][y].tegn ); break; case '=': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&B%c&d", dmap[x][y].tegn ); break; case '~': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&C%c&d", dmap[x][y].tegn ); break; case '+': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&Y%c&d", dmap[x][y].tegn ); break; case '*': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&g%c&d", dmap[x][y].tegn ); break; case 'X': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&R%c&d", dmap[x][y].tegn ); break; case ':': snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&Y%c&d", dmap[x][y].tegn ); break; default: // Empty space snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "%c", dmap[x][y].tegn ); break; } } mudstrlcat( buf, "&z|&D ", MAX_STRING_LENGTH * 2 ); /* * Add the text, if necessary */ if ( !alldesc ) { pos = get_line( p, 63 ); char col[10], c[2]; strcpy( c, whatColor( text, p ) ); if ( c[0] == '\0' ) mudstrlcpy( col, color_str( AT_RMDESC, ch ), 10 ); else snprintf( col, 10, "%s", c ); if ( pos > 0 ) { mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 ); strncat( buf, p, pos ); p += pos; } else { mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 ); mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 ); alldesc = TRUE; } } mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 ); } /* * Finish off map area */ mudstrlcat( buf, "&z+-----------+&D ", MAX_STRING_LENGTH * 2 ); if ( !alldesc ) { char col[10], c[2]; pos = get_line( p, 63 ); strcpy( c, whatColor( text, p ) ); if ( c[0] == '\0' ) mudstrlcpy( col, color_str( AT_RMDESC, ch ), 10 ); else snprintf( col, 10, "%s", c ); if ( pos > 0 ) { mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 ); strncat( buf, p, pos ); p += pos; mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 ); } else { mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 ); mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 ); alldesc = TRUE; } } /* * Deal with any leftover text */ if ( !alldesc ) { char col[10], c[2]; do { /* * Note the number - no map to detract from width */ pos = get_line( p, 78 ); strcpy( c, whatColor( text, p ) ); if ( c[0] == '\0' ) mudstrlcpy( col, color_str( AT_RMDESC, ch ), 10 ); else snprintf( col, 10, "%s", c ); if ( pos > 0 ) { mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 ); strncat( buf, p, pos ); p += pos; mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 ); } else { mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 ); mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 ); alldesc = TRUE; } } while ( !alldesc ); } mudstrlcat( buf, "&D\r\n", MAX_STRING_LENGTH * 2 ); send_to_char( buf, ch ); }
void PAWN::legalMoves ( POSITION start, const BOARD &board, POSITIONLIST &moves ) const { int delta, limit; POSITION doubleMovedPawn; if (promotePiece) { promotePiece->legalMoves(start, board, moves); return; } if (whatColor() == WHITE) { delta = 1; limit = NUMCOLS; } else { delta = -1; limit = -1; } moves.nMoves = 0; // check if en passant capture possible if (board.lastMoveDoublePawn(doubleMovedPawn)) if ((start.col == doubleMovedPawn.col) && (whatColor() != board.whatPiece(doubleMovedPawn)->whatColor())) { if ((start.row - 1) == doubleMovedPawn.row) { moves.end[moves.nMoves].row = start.row - 1; moves.end[moves.nMoves++].col = start.col + delta; } else if ((start.row + 1) == doubleMovedPawn.row) { moves.end[moves.nMoves].row = start.row + 1; moves.end[moves.nMoves++].col = start.col + delta; } } start.col += delta; if (start.col == limit) return; // check for moves ahead if (!board.whatPiece(start)) { moves.end[moves.nMoves++] = start; // check if initial double move possible if (!hasBeenMoved()) if (!board.whatPiece(start.row, start.col + delta)) { moves.end[moves.nMoves].row = start.row; moves.end[moves.nMoves++].col = start.col + delta; } } // check for captures if (start.row > 0) if (board.whatPiece(start.row - 1, start.col)) if (board.whatPiece(start.row - 1, start.col)->whatColor() != whatColor()) { moves.end[moves.nMoves].row = start.row - 1; moves.end[moves.nMoves++].col = start.col; } if (start.row < (NUMROWS - 1)) if (board.whatPiece(start.row + 1, start.col)) if (board.whatPiece(start.row + 1, start.col)->whatColor() != whatColor()) { moves.end[moves.nMoves].row = start.row + 1; moves.end[moves.nMoves++].col = start.col; } return; }