Summary:
I am making a top-down turn-based game, and in the process of creating an "aiming" module which has to be pretty modular, depending on the kind of weapon being aimed. Overall, not too complicated - You move a "reticle" obj around, which is pointed to when you fire the weapon.
I ran into the issue when trying to highlight any tiles between you and the reticle (In a straight, single-tile path), AND highlight any tiles beyond the reticle that would be in the path of the projectile if it can penetrate your target. It would ideally show all possible tiles the projectile could path through extending out to the maximum range.
No problem in the cardinal directions, but when aiming at an intermediate angle, I can't figure out a good solution to keep a consistant line.
One method I tried was to keep "doubling" the difference in x&y between you and the reticle until it is outside the weapons range, then just do some pathing between you and that point - But this fails if you are too close to the edge of the map.
I've tried using using arctan to get a ratio between x-steps and y-steps, and then alternate, but continue to run into math issues.
Is there a simple solution to this kind of problem I am overlooking? Any ideas about the best way to come at the problem?
Code:
The aiming proc for weapons that can be manually aimed:
proc
GimbalAim(mob/M,,D,comp/C) // M: Player, D: The direction being passed, C: The weapon being used
if(M.reticle && M.aiming == C) //If you are already aiming this weapon using a reticle
step(M.reticle,D) //Move the reticle in the input direction
if(C.indirect == 0) //If the projectile paths straight to/through your reticle
ExtendPath(M,,D,C) //Draw the path extending from you to the reticle and beyond -- Currectly empty because I can't find a functional way of even doing this
else //Otherwise, just the reticle is fine (For "Mortar" style weapons)
return
else //Otherwise, create a reticle and set this weapon as being aimed
M.reticle = new/obj/reticle(M.loc)
M.aiming = C
It would look something like this: