patch to fix problem in fov code

Moderator: Moderator

Post Reply
Message
Author
tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

patch to fix problem in fov code

#1 Post by tiger_eye »

EDIT: Significant updated patch below. Many fixes to FoV and LoS.

$10 says the attached patch will make some people mad :D

But, well, the fov code is not working correctly, and it really ought to be fixed. Doing so, however, will generally decrease what a character can see. Check out the image below as an example.

A super-quick summary of what got changed. First, understand that fov is basically defined by two angles: start_slope and end_slope (and start_slope < end_slope). There were situations in which a blocked corner would decrease start_slope, thus allowing you to see more than you should. This is wrong and has been fixed. Similarly, there were situations in which end_slope would become larger and increase your fov, which is wrong and has been fixed. The final fix is to check if adjacent terrain blocks fov and adjust end_slope as necessary (start_slope already had this check). Enjoy! Mwahahaha!
better_fov.png
better_fov.png (80.89 KiB) Viewed 6222 times
Last edited by tiger_eye on Wed Mar 23, 2011 7:02 am, edited 2 times in total.

Canderel
Sher'Tul
Posts: 1252
Joined: Mon Nov 24, 2003 2:31 pm
Location: South Africa

Re: patch to fix problem in fov code

#2 Post by Canderel »

Can you do a before and after screenshot?

I've often wondered why I can see much more than I can target. Is this related? Though with bean trickery it becomes possilble.

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: patch to fix problem in fov code

#3 Post by tiger_eye »

For "Before", check out Zop's post here:
http://forums.te4.org/viewtopic.php?f=4 ... 0&start=15
which links to this image
http://img801.imageshack.us/i/twinc.png/

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: patch to fix problem in fov code

#4 Post by Graziel »

i think its still wrong - previously you could see target but not always make a line to the spot now its opposite( you cant see target but you can target spot )

IMHO - if you can target spot you should be able to see it(in terms of FOV) and opposite if you can see spot you should be able to target it.
You are likely to be eaten by a grue

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: patch to fix problem in fov code

#5 Post by tiger_eye »

Graziel wrote: i think its still wrong - previously you could see target but not always make a line to the spot now its opposite( you cant see target but you can target spot )
This should be confirmed by somebody who knows how this works in the code, but I think line target spotting does check if the target is in fov. Hence, if we change fov, then we change line targeting, and your above point is moot.

By the way, fov still uses the geometry documented in the code. I'll illustrate why you shouldn't be able to look past the following ("X" means you can't see the tile, and note targets "A" and "B" by the blocks):

Code: Select all

..XXX
.#..#
@....

expand 5x gives

+---++---++---++---++---+
|   ||   ||   ||   ||   |
|   ||   || X || X || X |
|   ||   ||   ||   ||   |
2---++---++---++---+B---+
+---+#####+---++---+#####
|   |#####|   ||   |#####
|   |#####|   ||   |#####
|   |#####|   ||   |#####
1---+#####A---++---+#####
+---++---++---++---++---+
|   ||   ||   ||   ||   |
| @ ||   ||   ||   ||   |
|   ||   ||   ||   ||   |
0---+1---+2---+3---+4---+
slope to A (lower-right of first block): 0.5/1.5 = 1/3 = 0.3333
slobe to B (upper-left of second block): 1.5/3.5 = 3/7 = 0.4286

Hence, the character can't see target 'B' because it is blocked by the first block.

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: patch to fix problem in fov code

#6 Post by yufra »

tiger_eye wrote:This should be confirmed by somebody who knows how this works in the code, but I think line target spotting does check if the target is in fov. Hence, if we change fov, then we change line targeting, and your above point is moot.
The line instance (created with line.new) is strictly geometric and has no knowledge of LOS, etc. Both the targeting and project(ion) code use the line instance and then iterate through it, checking the block_path function found in engine.Target.lua. The result is that only the tiles actually traversed by the line are checked, and the adjacent tiles have no bearing on it so you can shoot around corners if you get the angle right. It is possible to link targeting/projection to FOV checking by adding the "requires_knowledge" flag to the target specification, which is done automatically for targeting (see engine.Target:setActive). This is not exactly what you want because it requires you to be able to see the target within your limited light range, whereas you probably want an infinite light range and use the talent's range to determine distance.
<DarkGod> lets say it's intended

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: patch to fix problem in fov code

#7 Post by tiger_eye »

I'm glad you know the code, yufra :).

It should be pretty easy to add a few rules to line targeting to make it equivalent to fov (regardless of light distance and whether you can see the target). I can do this next week if nobody beats me to it. Gotta go!

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: patch to fix problem in fov code

#8 Post by tiger_eye »

Hopefully the attached patch ties up most the loose ends for the current FoV and LoS algorithms. Below is a list of changes:

(1) Blocked terrain no longer increases FoV (the issue reported in initial post)
(2) Correctly calculate slopes from angles via tangent function. Previously used 'tan(x) ~ x' approximation for x in range 0 to pi/4 radians (0 to 45 degrees)
(3) 'FOV_SHAPE_CIRCLE_PRECALCULATE' option now calculates height correctly
(4) Safely handle floating point precision issues in FoV
(5) Separated the "block" function and "apply" function for a couple 'fov.calc_{beam,circle}' calls
(6) Restrict LoS targeting to FoV. LoS still uses bresenham line drawing (i.e., 'line.new') to make a path from the center of the source tile to the center of the target tile
(7) Modified projectile code to handle the above changes
(8) Updated "Channel Staff" "block_path" function
(9) And a few other minor fixes

Please note that I probably haven't tested and verified all types of projectiles in all relevant situations, so if you wish to review my changes or keep an eye out for bugs, I would suggest starting with that. For example, the LoS logic in the following functions were very similar but structured slightly differently:
Target.lua:display()
ActorProject.lua:project()
ActorProject.lua:canProject()
Projectile.lua:act()
Attachments
los_fov_improvements.txt
(48.25 KiB) Downloaded 309 times

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: patch to fix problem in fov code

#9 Post by tiger_eye »

Oooooh, pretty angles :D
The following images use the same Lake of Nur example as done above. The green highlights represent the precise field of vision.

Here is the FoV for a point source (0% of tile width):
actor_width0.png
actor_width0.png (5.88 KiB) Viewed 6109 times
Here is the FoV for an actor 50% the width of the tile:
actor_width50.png
actor_width50.png (8.31 KiB) Viewed 6109 times
(Note: if the actor were any larger, it would begin to see past the obstructions to the right).

And here is the FoV for an actor 100% the width of the tile:
actor_width100.png
actor_width100.png (12.2 KiB) Viewed 6109 times
Ummm... uhhhhhh... you do not want to know how I made these images! :wink:

Canderel
Sher'Tul
Posts: 1252
Joined: Mon Nov 24, 2003 2:31 pm
Location: South Africa

Re: patch to fix problem in fov code

#10 Post by Canderel »

Lol, we probably do want to know (a new FOV patch?!)... but the guy at 100% have to have an eye on each corner of the square, and they are able to look crosseyed.

Personally I think the first one is best (most realistic)... Though targetting a dude in the L shape (two blocks down 1 to the side) in most board rpg terms would give you cover (half-cover at least).

Post Reply