* @brief Calculate the best fit direction between two points * @param x1 Tile coordinate * @param y1 Tile coordinate * @param x2 Tile coordinate * @param y2 Tile coordinate * @return A value from the direction enum */
| 856 | * @return A value from the direction enum |
| 857 | */ |
| 858 | int GetDirection(int x1, int y1, int x2, int y2) |
| 859 | { |
| 860 | int mx, my; |
| 861 | int md, ny; |
| 862 | |
| 863 | mx = x2 - x1; |
| 864 | my = y2 - y1; |
| 865 | |
| 866 | if (mx >= 0) { |
| 867 | if (my >= 0) { |
| 868 | md = DIR_S; |
| 869 | if (2 * mx < my) |
| 870 | md = DIR_SW; |
| 871 | } else { |
| 872 | my = -my; |
| 873 | md = DIR_E; |
| 874 | if (2 * mx < my) |
| 875 | md = DIR_NE; |
| 876 | } |
| 877 | if (2 * my < mx) |
| 878 | return DIR_SE; |
| 879 | } else { |
| 880 | if (my >= 0) { |
| 881 | ny = -mx; |
| 882 | md = DIR_W; |
| 883 | if (2 * ny < my) |
| 884 | md = DIR_SW; |
| 885 | } else { |
| 886 | ny = -mx; |
| 887 | my = -my; |
| 888 | md = DIR_N; |
| 889 | if (2 * ny < my) |
| 890 | md = DIR_NE; |
| 891 | } |
| 892 | if (2 * my < ny) |
| 893 | return DIR_NW; |
| 894 | } |
| 895 | |
| 896 | return md; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * @brief Set the RNG seed |
no outgoing calls
no test coverage detected