MCPcopy Create free account
hub / github.com/DFHack/dfhack / ProjectilePath

Class ProjectilePath

plugins/siege-engine.cpp:795–845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793 */
794
795struct ProjectilePath {
796 static const int DEFAULT_FUDGE = 31;
797
798 df::coord origin, goal, target, fudge_delta;
799 int divisor, fudge_factor;
800 df::coord speed, direction;
801
802 ProjectilePath(df::coord origin, df::coord goal) :
803 origin(origin), goal(goal), fudge_factor(1)
804 {
805 fudge_delta = df::coord(0,0,0);
806 calc_line();
807 }
808
809 ProjectilePath(df::coord origin, df::coord goal, df::coord delta, int factor) :
810 origin(origin), goal(goal), fudge_delta(delta), fudge_factor(factor)
811 {
812 calc_line();
813 }
814
815 ProjectilePath(df::coord origin, df::coord goal, float zdelta, int factor = DEFAULT_FUDGE) :
816 origin(origin), goal(goal), fudge_factor(factor)
817 {
818 fudge_delta = df::coord(0,0,int(factor * zdelta));
819 calc_line();
820 }
821
822 void calc_line()
823 {
824 speed = goal - origin;
825 speed.x *= fudge_factor;
826 speed.y *= fudge_factor;
827 speed.z *= fudge_factor;
828 speed = speed + fudge_delta;
829 target = origin + speed;
830 divisor = point_distance(speed);
831 if (divisor <= 0) divisor = 1;
832 direction = df::coord(speed.x>=0?1:-1,speed.y>=0?1:-1,speed.z>=0?1:-1);
833 }
834
835 df::coord operator[] (int i) const
836 {
837 int div2 = divisor * 2;
838 int bias = divisor-1;
839 return origin + df::coord(
840 (2*speed.x*i + direction.x*bias)/div2,
841 (2*speed.y*i + direction.y*bias)/div2,
842 (2*speed.z*i + direction.z*bias)/div2
843 );
844 }
845};
846
847static ProjectilePath decode_path(lua_State *L, int idx, df::coord origin)
848{

Callers 3

decode_pathFunction · 0.85
aimAtPointMethod · 0.85
aimAtAreaMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected