- else if(mpiece % PIECES == KNIGHT) {
- GLfloat shine[1];
- GLfloat spec[4];
- GLfloat mult;
- glTranslatef(steps < 50 ? from[1] : to[1], 0.0,
- steps < 50 ? from[0] : to[0]);
-
- mult = steps < 10
- ? (1.0 - steps / 10.0) : 100 - steps < 10
- ? (1.0 - (100 - steps) / 10.0) : 0.0;
-
- shine[0] = mult*shininess[0];
- spec[0] = mult*specular[0];
- spec[1] = mult*specular[1];
- spec[2] = mult*specular[2];
- spec[3] = 1.0;
- glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shine);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
-
- glColor4f(shadow ? MaterialShadow[0] : colors[mpiece/7][0],
- shadow ? MaterialShadow[1] : colors[mpiece/7][1],
- shadow ? MaterialShadow[2] : colors[mpiece/7][2],
- fabs(49-steps)/49.0);
-
- glScalef(fabs(49-steps)/49.0, fabs(49-steps)/49.0, fabs(49-steps)/49.0);
+ else if(cs->mpiece % PIECES == KNIGHT) {
+ /* If there is nothing in the path of a knight, move it by sliding,
+ just like the other pieces. But if there are any pieces on the
+ middle two squares in its path, the knight would intersect them,
+ so in that case, move it in an airborne arc. */
+ GLfloat y;
+ int i, j;
+ Bool blocked_p = False;
+ int fromx = MIN(cs->from[1], cs->to[1]);
+ int fromy = MIN(cs->from[0], cs->to[0]);
+ int tox = MAX(cs->from[1], cs->to[1]);
+ int toy = MAX(cs->from[0], cs->to[0]);
+ if (fromx == tox-2) fromx = tox = fromx+1;
+ if (fromy == toy-2) fromy = toy = fromy+1;
+ for (i = fromy; i <= toy; i++) {
+ for (j = fromx; j <= tox; j++) {
+ if (cs->game.board[i][j]) {
+ blocked_p = True;
+ break;
+ }
+ }
+ }
+
+ if (!blocked_p)
+ goto SLIDE;
+
+ /* Move by hopping. */
+ y = 1.5 * sin (M_PI * cs->steps / 100.0);
+ glTranslatef(cs->from[1]+cs->steps*cs->dx, y,
+ cs->from[0]+cs->steps*cs->dz);
+
+ } else {
+ SLIDE:
+ /* Move by sliding. */
+ glTranslatef(cs->from[1]+cs->steps*cs->dx, 0.0, cs->from[0]+cs->steps*cs->dz);