MCPcopy Create free account
hub / github.com/diasurgical/devilution / GetDirection

Function GetDirection

Source/engine.cpp:858–897  ·  view source on GitHub ↗

* @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 */

Source from the content-addressed store, hash-verified

856 * @return A value from the direction enum
857 */
858int 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

Callers 15

GetRotaryDistanceFunction · 0.85
Obj_TrapFunction · 0.85
OperateChestFunction · 0.85
M_GetDirFunction · 0.85
M_TryH2HHitFunction · 0.85
MAI_SkelSdFunction · 0.85
MAI_SnakeFunction · 0.85
MAI_BatFunction · 0.85
MAI_SneakFunction · 0.85
MAI_CleaverFunction · 0.85
MAI_RoundFunction · 0.85
MAI_RangedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected