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

Function GetDirection

Source/engine.cpp:25–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace devilution {
24
25Direction GetDirection(Point start, Point destination)
26{
27 Direction md;
28
29 int mx = destination.x - start.x;
30 int my = destination.y - start.y;
31 if (mx >= 0) {
32 if (my >= 0) {
33 if (5 * mx <= (my * 2)) // mx/my <= 0.4, approximation of tan(22.5)
34 return Direction::SouthWest;
35 md = Direction::South;
36 } else {
37 my = -my;
38 if (5 * mx <= (my * 2))
39 return Direction::NorthEast;
40 md = Direction::East;
41 }
42 if (5 * my <= (mx * 2)) // my/mx <= 0.4
43 md = Direction::SouthEast;
44 } else {
45 mx = -mx;
46 if (my >= 0) {
47 if (5 * mx <= (my * 2))
48 return Direction::SouthWest;
49 md = Direction::West;
50 } else {
51 my = -my;
52 if (5 * mx <= (my * 2))
53 return Direction::NorthEast;
54 md = Direction::North;
55 }
56 if (5 * my <= (mx * 2))
57 md = Direction::NorthWest;
58 }
59 return md;
60}
61
62int CalculateWidth2(int width)
63{

Callers 15

TESTFunction · 0.85
OperateChestFunction · 0.85
OperateTrapFunction · 0.85
OnPutItemFunction · 0.85
GetMonsterDirectionFunction · 0.85
StartDeathFromMonsterFunction · 0.85
MonsterAttackPlayerFunction · 0.85
AiAvoidanceFunction · 0.85
AiRangedFunction · 0.85
AiRangedAvoidanceFunction · 0.85
SkeletonAiFunction · 0.85
ScavengerAiFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68