The Selfish Gene wrote:In Maj'Eyal, lines sort of avoid obstacles to some extent
Only sort of?! It doesn't avoid obstacles that the user can't see or doesn't know about, but it should do a good job otherwise! Heh, although it may try to shoot through tiles such as friendly units. Do you have examples where this doesn't perform as expected?
The Selfish Gene wrote:Is it a feature of Maj'Eyal or of the TE4 Engine?
The engine. In C.
The Selfish Gene wrote:I'd like to know where to find the code for this feature or the broad logic behind it. It would be really helpful.
Heh, I wouldn't assume the code will be helpful. It is not for the feint of heart. Do you want to use this feature, understand it, reproduce the behavior elsewhere, or what?
The bulk of the code is here:
http://git.net-core.org/tome/t-engine4/ ... /fov/fov.c
The following code is used to determine the line start and end positions, angle, etc. There is different code that is run, for example, when a projectile is actually flying along the specified path.
Consider yourself warned, but I will try to step you through the relevant parts. Let me know if you have any questions. I wrote this code (sorry gentle readers!).
This block uses functions defined by macros and creates the line in a given octant. It is a reasonable place to start:
http://git.net-core.org/tome/t-engine4/ ... L2543-2578
The functions are defined by the macros here:
http://git.net-core.org/tome/t-engine4/ ... L2207-2214
This is the main macro:
http://git.net-core.org/tome/t-engine4/ ... ov.c#L2011
The code that runs when the line finishes is here. It has special logic if the line is blocked or not:
http://git.net-core.org/tome/t-engine4/ ... ov.c#L1877
The macros use this macro, which determines the optimal boundary of vision:
http://git.net-core.org/tome/t-engine4/ ... fov.c#L598
Hmm, the definition of the fov line struct may also be useful:
http://git.net-core.org/tome/t-engine4/ ... h#L133-173
There are similar functions/macros that do this for hexagonal maps too.
Good luck!