MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getDirectionTo

Method getDirectionTo

src/Battlescape/TileEngine.cpp:2747–2789  ·  view source on GitHub ↗

* Returns the direction from origin to target. * @param origin The origin point of the action. * @param target The target point of the action. * @return direction. */

Source from the content-addressed store, hash-verified

2745 * @return direction.
2746 */
2747int TileEngine::getDirectionTo(const Position &origin, const Position &target) const
2748{
2749 double ox = target.x - origin.x;
2750 double oy = target.y - origin.y;
2751 double angle = atan2(ox, -oy);
2752 // divide the pie in 4 angles each at 1/8th before each quarter
2753 double pie[4] = {(M_PI_4 * 4.0) - M_PI_4 / 2.0, (M_PI_4 * 3.0) - M_PI_4 / 2.0, (M_PI_4 * 2.0) - M_PI_4 / 2.0, (M_PI_4 * 1.0) - M_PI_4 / 2.0};
2754 int dir = 0;
2755
2756 if (angle > pie[0] || angle < -pie[0])
2757 {
2758 dir = 4;
2759 }
2760 else if (angle > pie[1])
2761 {
2762 dir = 3;
2763 }
2764 else if (angle > pie[2])
2765 {
2766 dir = 2;
2767 }
2768 else if (angle > pie[3])
2769 {
2770 dir = 1;
2771 }
2772 else if (angle < -pie[1])
2773 {
2774 dir = 5;
2775 }
2776 else if (angle < -pie[2])
2777 {
2778 dir = 6;
2779 }
2780 else if (angle < -pie[3])
2781 {
2782 dir = 7;
2783 }
2784 else if (angle < pie[0])
2785 {
2786 dir = 0;
2787 }
2788 return dir;
2789}
2790
2791/**
2792 * Gets the origin voxel of a certain action.

Callers 6

setupAmbushMethod · 0.80
selectNearestTargetMethod · 0.80
selectPointNearTargetMethod · 0.80
findFirePointMethod · 0.80
meleeActionMethod · 0.80
postPathProceduresMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected