Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Distance over z-levels  (Read 1014 times)

martinuzz

  • Bay Watcher
  • High dwarf
    • View Profile
Distance over z-levels
« on: July 29, 2014, 12:58:34 pm »

Is it still as it was before?
When a dwarf needs an item for a job, will it not take z-level distance into account?
In other words, does a dwarf still think that an item 2 tiles away on the same z-level is further away than an item 1 tile away but 100 z-levels down?
Logged
Friendly and polite reminder for optimists: Hope is a finite resource

We can ­disagree and still love each other, ­unless your disagreement is rooted in my oppression and denial of my humanity and right to exist - James Baldwin

http://www.bay12forums.com/smf/index.php?topic=73719.msg1830479#msg1830479

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Distance over z-levels
« Reply #1 on: July 29, 2014, 03:18:23 pm »

I'm pretty sure it's never been that way, and that the game always considered the X distance, Y distance, and Z distance as the mole digs, so a stone 5 Z-levels directly above the dwarf would be considered to be closer than a stone 6 tiles to the east.

The key is that job item selection is performed relative to the dwarf's current location, NOT the workshop itself, so if your dwarf is idling in his bedroom when he accepts a Masonry job, he will search for a boulder close to his bedroom, not close to the workshop.
« Last Edit: July 29, 2014, 03:20:22 pm by Quietust »
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

martinuzz

  • Bay Watcher
  • High dwarf
    • View Profile
Re: Distance over z-levels
« Reply #2 on: July 29, 2014, 04:20:45 pm »

I'm pretty sure it's never been that way, and that the game always considered the X distance, Y distance, and Z distance as the mole digs, so a stone 5 Z-levels directly above the dwarf would be considered to be closer than a stone 6 tiles to the east.
I'm quite sure that it has been like that. But maybe that was somewhere between 2007 and 2009, before you joined. I gets hard to recall / have read all game changes after being here for 7 years already (actually 8, I lurked and played about a year before registering on the forums). Dwarves did use to run down dozens of stairs to get a piece of rock for their next mason job on repeat, instead of the rock lying 5 tiles to the right, cause z-distance was not calculated.

The key is that job item selection is performed relative to the dwarf's current location, NOT the workshop itself, so if your dwarf is idling in his bedroom when he accepts a Masonry job, he will search for a boulder close to his bedroom, not close to the workshop.

I know that, that's another thing.
« Last Edit: July 29, 2014, 04:26:29 pm by martinuzz »
Logged
Friendly and polite reminder for optimists: Hope is a finite resource

We can ­disagree and still love each other, ­unless your disagreement is rooted in my oppression and denial of my humanity and right to exist - James Baldwin

http://www.bay12forums.com/smf/index.php?topic=73719.msg1830479#msg1830479

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: Distance over z-levels
« Reply #3 on: July 29, 2014, 04:36:27 pm »

AFAIK it's always counted z-levels as '1', though that certainly doesn't stop a dwarf from running up and down stairs to get the items they want! (Since they might go 30 squares over, 4 z-levels down and 30 squares back to grab a stone that would still be judged as "closer" to the workshop than one 5 squares away on the same level.)
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Distance over z-levels
« Reply #4 on: July 30, 2014, 08:17:55 am »

I've just done a test in version 0.28.181.40d, and I can confirm that Z-levels do count toward distance. My test setup as as follows:

1. A Mason's workshop on Z=149
2. Around the Mason's workshop, a 9x9 stone stockpile (with the center 3x3 occupied by the workshop itself, resulting in 3 concentric rings of distance 2, 3, and 4)
3. 3 Z-levels directly beneath the center of the workshop, a 3x3 stone stockpile
4. 15 Z-levels directly beneath the center of the workshop, a 3x3 stone stockpile
5. Mason's workshop set to Make Rock Blocks on repeat

The stones were used up in the following order:
1. A stone from the outer edge of the stockpile (because the mason was standing by the wagon)
2. The innermost ring around the workshop (distance 2)
3. The 9 stones 3 Z-levels beneath the workshop and the middle ring around the workshop (distance 3)
4. The outer ring around the workshop (distance 4)
5. The 9 stones 15 z-levels beneath the workshop (distance 15)

Thus, the material's effective distance is the maximum of the X-distance, the Y-distance, and the Z-distance, as if the "eligible item zone" was gradually expanding outward in a cube shape until it found something. It doesn't calculate actual linear distance, since that would require using multiplication and square roots (which are very expensive calculations when you're potentially doing them against tens of thousands of items per job).

You're welcome to repeat this test in version 0.40.05, though I'm willing to bet that the results will be the same.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Bki

  • Bay Watcher
    • View Profile
Re: Distance over z-levels
« Reply #5 on: July 30, 2014, 09:10:08 am »

It seems to be similar to the experience I had in 0.40. My masons would go find a rock a few z-level under the workshop, rather than the stones in the nearby stockpile (but farther away if you just calculate the distance).

I have not done formal test for that, though.

The obvious solution is to link the stockpiles to the workshop.
Logged

therahedwig

  • Bay Watcher
    • View Profile
    • wolthera.info
Re: Distance over z-levels
« Reply #6 on: July 30, 2014, 10:35:39 am »

Quiestus, Martinuz, you're both describing the same thing.

Though, back in the day, it was assumed z level had no cost added because no specific testing was done.

To avoid this kind of behaviour, outside of linking, item distance in z should also check distance to stair and add that to the total cost.

But for now, we only have linking.
Logged
Stonesense Grim Dark 0.2 Alternate detailed and darker tiles for stonesense. Now with all ores!

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Distance over z-levels
« Reply #7 on: July 30, 2014, 11:22:17 am »

item distance in z should also check distance to stair and add that to the total cost.
Doing that would require actual pathfinding checks to be done during job item selection, and that would very significantly slow down the game - pay attention to how long it takes in a large fortress to populate the item list for building a workshop (the actual delay between pressing the key and the menu showing up), and imagine that delay happening every time a workshop job starts.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Nahno

  • Bay Watcher
    • View Profile
Re: Distance over z-levels
« Reply #8 on: August 01, 2014, 04:06:34 am »

I'm pretty sure it's never been that way, and that the game always considered the X distance, Y distance, and Z distance as the mole digs, so a stone 5 Z-levels directly above the dwarf would be considered to be closer than a stone 6 tiles to the east.
I've just done a test in version 0.28.181.40d, and I can confirm that Z-levels do count toward distance.

I remember a mason going far down the central staircase for stone, ignoring the stone beside him, in one of my early forts. I also remember people talking about it on the forum. It annoyed some people a lot; messing up the effects of their intended infrastructure. I guess it was something Toady altered before the big DF2010-update.
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Distance over z-levels
« Reply #9 on: August 01, 2014, 06:18:05 am »

I guess it was something Toady altered before the big DF2010-update.
...except 0.28.181.40d was before the big DF2010-update. If it's absolutely necessary (and it looks like it is), I'll retest this in 0.27.169.32a (the first fully 3D release) and finally put this to rest.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Nahno

  • Bay Watcher
    • View Profile
Re: Distance over z-levels
« Reply #10 on: August 02, 2014, 08:23:29 am »

...except 0.28.181.40d was before the big DF2010-update.
Exactly my point.

If it's absolutely necessary (and it looks like it is), I'll retest this in 0.27.169.32a (the first fully 3D release) and finally put this to rest.
I don't think it is. The question was answered: the z-axis is included in the distance calculations on equal terms with x and y. If anyone decides to play an older version, they will probably choose the most updated version, like 40d, where you just confirmed that the z-axis is not ignored in distance calculations. Feel free to test it anyway, though.
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Distance over z-levels
« Reply #11 on: August 02, 2014, 09:27:26 am »

You seem to be under the impression that the behavior changed at some point - it hasn't. I just ran the exact same test against versions 0.27.169.32a (the first 3D release) and 0.40.05 (the latest version) and the results were exactly the same.

If anybody remembers it behaving differently, there are two possibilities:
1. Toady changed it at some point and then changed it back. For something as basic as item distance calculations, this is highly unlikely.
2. You're remembering incorrectly. This is almost definitely the case.
« Last Edit: August 02, 2014, 09:29:41 am by Quietust »
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

martinuzz

  • Bay Watcher
  • High dwarf
    • View Profile
Re: Distance over z-levels
« Reply #12 on: August 02, 2014, 10:48:53 am »

AFAIK it's always counted z-levels as '1', though that certainly doesn't stop a dwarf from running up and down stairs to get the items they want! (Since they might go 30 squares over, 4 z-levels down and 30 squares back to grab a stone that would still be judged as "closer" to the workshop than one 5 squares away on the same level.)

I believe this right here is what caused people, including me back then, to think that z levels weren't considered. It's because, like Quietust says, it's calculated 'as the mole digs', not taking actual pathing into account. Thanks for the research.
Logged
Friendly and polite reminder for optimists: Hope is a finite resource

We can ­disagree and still love each other, ­unless your disagreement is rooted in my oppression and denial of my humanity and right to exist - James Baldwin

http://www.bay12forums.com/smf/index.php?topic=73719.msg1830479#msg1830479