* Get direction (0..8?) to get from starting point to destination point. * @param orgX X coordinate starting point. * @param orgY Y coordinate starting point. * @param desX X coordinate destination point. * @param desY Y coordinate destination point. * @return Direction to go in. * @todo Remove local magic constants and document the code. * @bug Has a condition that never holds. */
| 470 | * @bug Has a condition that never holds. |
| 471 | */ |
| 472 | short Micropolis::getDir(int orgX, int orgY, int desX, int desY) |
| 473 | { |
| 474 | static const short Gdtab[13] = { 0, 3, 2, 1, 3, 4, 5, 7, 6, 5, 7, 8, 1 }; |
| 475 | int dispX, dispY, z; |
| 476 | |
| 477 | dispX = desX - orgX; |
| 478 | dispY = desY - orgY; |
| 479 | |
| 480 | if (dispX < 0) { |
| 481 | if (dispY < 0) { |
| 482 | z = 11; |
| 483 | } else { |
| 484 | z = 8; |
| 485 | } |
| 486 | } else { |
| 487 | if (dispY < 0) { |
| 488 | z = 2; |
| 489 | } else { |
| 490 | z = 5; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | dispX = absoluteValue(dispX); |
| 495 | dispY = absoluteValue(dispY); |
| 496 | absDist = dispX + dispY; |
| 497 | |
| 498 | if (dispX * 2 < dispY) { |
| 499 | z++; |
| 500 | } else if (dispY * 2 < dispY) { // XXX This never holds!! |
| 501 | z--; |
| 502 | } |
| 503 | |
| 504 | if (z < 0 || z > 12) { |
| 505 | z = 0; |
| 506 | } |
| 507 | |
| 508 | return Gdtab[z]; |
| 509 | } |
| 510 | |
| 511 | |
| 512 | /** |
nothing calls this directly
no test coverage detected