If you modify it to return the rounded distance as I suggested upthread, won't it return the same values as it used to for small cases, thus solving whatever problems your change introduced?
bug in head
Collapse
X
-
-
I am at work (East Coast, USA), so I didn't compile and check this code, but I think the problem is the above and below. Unless the exact distance is an whole number square root (1, 4, 9, etc...), sometimes it is going to round up the distance, and sometimes it is going to round down. It just depends on whether above or below gets to less than 1 of the unrounded distance first. For the case where a diaganol distance of 1 and dsq = 2, above gets there first, and it returns an undesired result.
I think you need to start from the below the distance and work your way up, checking each number one at a time until you get above dsq. I am assuming efficiency is important, and you will rarely be calculating distances greater than 25, so something like this:
/*
* Calculate distance between two points.
*/
int distance(int y1, int x1, int y2, int x2)
{
int dist = 0;
int dsq = abs(y2 - y1) + abs(x2 - x1);
/* For efficiency, help narrow in on the distance in increments of 5 */
if (dsq >= 400) dist = 20;
else if (dsq >= 225) dist = 15;
else if (dsq >= 100) dist = 10;
else if (dsq >= 25) dist = 5;
while (TRUE)
{
/*figure out if the next increment is greater than dsq*/
int dist_plus_squared = (dist +1) * (dist +1);
/*We have the distance, rounded down. We are done.*/
if (dist_plus_squared > dsq) return (dist);
/*try again*/
dist++;
}
}
That function returns a distance of 1 for all 8 directions around a player, and as the distance increases should return a relatively round circle for each distance.
Hope that helps.NPPAngband current home page: http://nppangband.bitshepherd.net/
Source code repository:
https://github.com/nppangband/NPPAngband_QT
Downloads:
https://app.box.com/s/1x7k65ghsmc31usmj329pb8415n1ux57Comment
-
For what it's worth, I modified the function to make sure it returned 1 for distance(0, 0, 1, 1) and still had the bug. I probably should have mentioned that. I can post the modified function along with a table of distances when I get a chance.
EDIT: I should ask... are you able to use your distance function in V and have it work? If so then obviously it's my mistake, but I would guess it still won't work. When I get home from work I will give it a try.Last edited by d_m; July 7, 2010, 15:27.Comment
-
That incredibly strange radius 3 light not covering a distance of \sqrt{2} probably means that something is getting doubled somewhere in addition to rounding up, so I don't think fixing just one value is likely to be enough. I remember checking that rounding works the same as the old distance in every point in the radius 3 ball, but I might have made a mistake.Comment
-
For what it's worth, I modified the function to make sure it returned 1 for distance(0, 0, 1, 1) and still had the bug. I probably should have mentioned that. I can post the modified function along with a table of distances when I get a chance.
EDIT: I should ask... are you able to use your distance function in V and have it work? If so then obviously it's my mistake, but I would guess it still won't work. When I get home from work I will give it a try.
I have a similar function in NPP that I think is used in update_view, all of the line-of-sight code and all of the project functions, but it is a bool that doesn't return the actual square root. It just uses pythagorean theorum to determine if the distance from one square to another is above or below a set distance.
How are you using that function?NPPAngband current home page: http://nppangband.bitshepherd.net/
Source code repository:
https://github.com/nppangband/NPPAngband_QT
Downloads:
https://app.box.com/s/1x7k65ghsmc31usmj329pb8415n1ux57Comment
-
I couldn't figure out how to get those to work. If I increase one, I have to increase the other. I fiddle around, and then I get an error that something is too small. I guess I'll have to try again when feeling more in tune with numerology.Comment
-
When I tried the suggested distance function though I think it ended up producing "too many" grids and/or slopes because I got a segfault.Comment
-
You can find the "correct" values by setting both of them to something too high (e.g. 1000) and then when you see a value in the error (e.g. 267 < 1000) use 267. You'll probably also have to set VINFO_BITS_3 to something like 0xFFFFFFFF.
When I tried the suggested distance function though I think it ended up producing "too many" grids and/or slopes because I got a segfault.
I even tossed in asserts to guarantee that my distance function returned the same values when dx <= 2 and dy <= 2, so somehow the visibility of the adjacent diagonal is getting screwed up by some change to a distance larger than 2. BTW my change suggested upthread doesn't work on distance 0, have to special case that.Comment
-
Found a couple small bugs.
Let's say you have something autoinscribed but change the inscription. Let's say you have -light autoinscribed @z1 but during the game you change the rod's inscription it to @z1 !k or something without changing the autoinscription. If you have full inventory and you pick up a rod of light it enters your pack but doesn't stack because of the different inscriptions. It then forces out whatever is last.
I got a message that 'Ariel crushes a xxxxx'. I could not see Ariel, she was not visible, and obviously was not detected by telepathy. I should have got a 'something crushes a xxxxx'
There needs to be quality squelch options for dragon armor. You need to have a 'squelch all non-artifact dragon armor' option. Admittedly, this has bothered me for a long time.Comment
-
If you don't mind abuse, squelch all DSMs through the menu. Artifacts are never squelched. You will see all artifact DSMs and no other DSMs. The abuse is that you can tell immediately whether they are artifacts at a distance.Comment
-
There was some talk of allowing dragon armors to have egos. I don't think it is worth worrying about fixing squelching until that is taken care of, since squelch code will have to change when DSMs have egos.
If you don't mind abuse, squelch all DSMs through the menu. Artifacts are never squelched. You will see all artifact DSMs and no other DSMs. The abuse is that you can tell immediately whether they are artifacts at a distance.Comment
-
If you play with the standard artifacts, you can squelch all but multihued and power and balance. I mind the abuse a little bit myself, but it is such a low probability event I just squelch each DSM flavor after picking one up if I don't want it, and ignore the abuse. I have not yet found artifact DSM after squelching the flavor so for me the abuse remains only theoretical so far.Comment
-
If you play with the standard artifacts, you can squelch all but multihued and power and balance. I mind the abuse a little bit myself, but it is such a low probability event I just squelch each DSM flavor after picking one up if I don't want it, and ignore the abuse. I have not yet found artifact DSM after squelching the flavor so for me the abuse remains only theoretical so far.Comment
Comment