* Turn. * @param p Present direction (1..8). * @param d Destination direction (1..8). * @return New direction. * @todo Remove local magic constants and document the code. */
| 389 | * @todo Remove local magic constants and document the code. |
| 390 | */ |
| 391 | short Micropolis::turnTo(int p, int d) |
| 392 | { |
| 393 | if (p == d) { |
| 394 | return p; |
| 395 | } |
| 396 | |
| 397 | if (p < d) { |
| 398 | if (d - p < 4) { |
| 399 | p++; |
| 400 | } else { |
| 401 | p--; |
| 402 | } |
| 403 | } else { |
| 404 | if (p - d < 4) { |
| 405 | p--; |
| 406 | } else { |
| 407 | p++; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | if (p > 8) { |
| 412 | p = 1; |
| 413 | } |
| 414 | |
| 415 | if (p < 1) { |
| 416 | p = 8; |
| 417 | } |
| 418 | |
| 419 | return p; |
| 420 | } |
| 421 | |
| 422 | /** ??? |
| 423 | * @todo Figure out what this function is doing. |
nothing calls this directly
no outgoing calls
no test coverage detected