Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Distance calculations ignore floors  (Read 922 times)

julius

  • Escaped Lunatic
    • View Profile
Distance calculations ignore floors
« on: November 25, 2007, 02:31:00 pm »

I have a forge complex almost directly underneath my trade depot and on the trade depot screen it lists the distance of all iron bars as '6' although they are clearly several dozen squares away by dwarf-travel -- i.e. move laterally to some stairs, go down, and move laterally back.

This would also explain why a mason working in a shop above a mined-out level will go to the lower level to get rocks directly under him instead of rocks 5 squares away.  (This bug was reported previously in a topic with the words "item distance" in it.)

Logged

Align

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #1 on: November 25, 2007, 03:45:00 pm »

If you knew it was reported before why did you post a new topic?
Logged
My stray dogs often chase fire imps back into the magma pipe and then continue fighting while burning and drowning in the lava. Truly their loyalty knows no bounds, but perhaps it should.

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: Distance calculations ignore floors
« Reply #2 on: November 25, 2007, 04:47:00 pm »

I do not see this as a bug at all.

It worked this way even in the old 2D version.

I see it as one of the fundamental constraints on fortress design.

(And, as a programmer, I know how terrible it would be to run an A* search between every object and the target square just to generate a list.)

0x517A5D

Logged

Align

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #3 on: November 25, 2007, 05:42:00 pm »

Would you (as a programmer) think the solution I suggested in http://www.bay12games.com/cgi-local/ultimatebb.cgi?ubb=get_topic&f=6&t=002126  is feasible?
 
quote:
Originally posted by Align:
<STRONG>One idea is to make it only check the nearest squares on the same z-level, unless it detects a staircase in which case it'll start checking the nearest squares on different z-levels.</STRONG>

[ November 25, 2007: Message edited by: Align ]

Logged
My stray dogs often chase fire imps back into the magma pipe and then continue fighting while burning and drowning in the lava. Truly their loyalty knows no bounds, but perhaps it should.

TotalPigeon

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #4 on: November 25, 2007, 06:18:00 pm »

I agree with Align, it isn't necessary to check the distance to every stone but it would be great if it could run that criteria - Perhaps only use stone on a different z-level if a staircase or ramp is nearer than the nearest stone on the same z-level? Perhaps a little addition: (distance to nearest staircase) + (distance to nearest stone) for different z-levels as opposed to (distance to nearest stone) for the current z-level. I can't see it slowing the game too much, it isn't like the search is constantly running, and that would cover most instances where someone would be searching for stone to use.
Logged

Zombie

  • Bay Watcher
  • Ǵ̨̕o͘d͝d̡͢e̡̕s̷͟s̵͢ ͝of̴ ͡G͘͠a̧mi̶n̛͝g̨
    • View Profile
Re: Distance calculations ignore floors
« Reply #5 on: November 25, 2007, 07:32:00 pm »

quote:
Originally posted by 0x517A5D:
<STRONG>I do not see this as a bug at all.

It worked this way even in the old 2D version.

I see it as one of the fundamental constraints on fortress design.

(And, as a programmer, I know how terrible it would be to run an A* search between every object and the target square just to generate a list.)

0x517A5D</STRONG>


I see it as a bug. It's a potential pathing bug. What if there isn't a stairway to get to an upper level? What if the stairway was destroyed or removed, and now that section is inaccessible. A dwarf could continually try to get there, resulting in a lot of "no path to object" or "misplaced object" job cancellations. The distance calculations need to be actual if you don't want to encounter bugs.

Also, how on earth was this issue EVER the same in the 2D version? The problem is with the distance calculations along the z-axis. Seeing as the z-axis didn't exist in the 2D version, I highly doubt there was any problem even remotely like this in it.

Logged
If I had a dollar for every dwarf whose feelings I didn't care about, I'd have seven dollars, with more coming in the fall.

Urist McSharpblade, Axe Sheriff cancels Justice: Needs more than an axe for this.

MULTI-THREADING - I'm talking about it!

Yourself

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #6 on: November 25, 2007, 08:36:00 pm »

quote:
(And, as a programmer, I know how terrible it would be to run an A* search between every object and the target square just to generate a list.)

That is true.  But in this case we don't really need a perfect solution.  An acceptable solution might be to simply compute the cost to reach each floor from the given workshop.  This has its own set of problems, though.  Dynamic things like drawbridges kind of throw a wrench into the whole process.

It doesn't have to be perfect, just better than what it is.  The problem came up when I was digging magma channels for my smelters.  I didn't want to dig staircases down to the channel from my main fortress, so I dug it starting at the vent.  As I got under my workshops, my dwarves started walking all the way out to the vent and down through the channel to collect stones to make their crafts.  I decided to just forbid everything down there, but it seems like an unnecessary step (since the craftsdwarves were ignoring the stone stockpiles near their workshops to walk down and grab stones 2 levels below them.

Logged

Aquillion

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #7 on: November 25, 2007, 11:10:00 pm »

quote:
Originally posted by 0x517A5D:
<STRONG>(And, as a programmer, I know how terrible it would be to run an A* search between every object and the target square just to generate a list.)</STRONG>
You don't need to run an A* search.  Instead:

Using our existing 'rough distance measurement' (ignoring walls), measure the distance from our starting point to each staircase.  This is extremely fast (just take their XY coordinates and do some math), so we can do it for all staircases and ramps, and, using this, produce a very rough estimate of how long it would take us to reach any given staircase/ramp on any given floor.

Then, on each floor, calculate the rough distance each item is from the floor's staircases, adding this to the rough distance from before.  Again, while this sounds like a lot of work, it is quick and easy, since we're not actually looking at walls or anything, just a few staircases.

The resulting map won't be perfect, but it will be as good as anything we had in the old version (better, in some ways), and it won't be fooled by the Z-axis.

If you want to be clever, you could create and store a map of the exact distances between all staircases and ramps using A* - those don't change much, so it'd be easy to do once and maintain, and we could then use it to produce very accurate distance measurements (since we'd only need to take a rough guess to the current floor's staircases, and from the staircases at our destination floor.)  Exact distances between the staircases a few other generally 'static' things, like the trade depot and various stockpiles, could be calculated and stored as well.  That way, we'd only need to approximate the occasional stray item, and only as close as the nearest staircase.

Logged
We don't want another cheap fantasy universe, we want a cheap fantasy universe generator. --Toady One

Zombie

  • Bay Watcher
  • Ǵ̨̕o͘d͝d̡͢e̡̕s̷͟s̵͢ ͝of̴ ͡G͘͠a̧mi̶n̛͝g̨
    • View Profile
Re: Distance calculations ignore floors
« Reply #8 on: November 26, 2007, 12:03:00 am »

It could update this map of staircases or whatever every time you build or demolish a staircase or ramp. That way it's somewhat accurate, and it only generates or modifies it when you create or destroy a staircase or ramp.
Logged
If I had a dollar for every dwarf whose feelings I didn't care about, I'd have seven dollars, with more coming in the fall.

Urist McSharpblade, Axe Sheriff cancels Justice: Needs more than an axe for this.

MULTI-THREADING - I'm talking about it!

Yourself

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #9 on: November 26, 2007, 01:07:00 am »

quote:
If you want to be clever, you could create and store a map of the exact distances between all staircases and ramps using A* - those don't change much, so it'd be easy to do once and maintain, and we could then use it to produce very accurate distance measurements (since we'd only need to take a rough guess to the current floor's staircases, and from the staircases at our destination floor.) Exact distances between the staircases a few other generally 'static' things, like the trade depot and various stockpiles, could be calculated and stored as well. That way, we'd only need to approximate the occasional stray item, and only as close as the nearest staircase.

You have to be careful with dynamic things in between those, though.  Someone could easily raise a drawbridge or lock a door and a path could be invalidated.  You could keep paths that don't cross things like this and it's probably unlikely that anyone's fortress would cause problems, but you never know.

Logged

Aquillion

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #10 on: November 26, 2007, 01:12:00 am »

Gah.  This is true.  It would probably be best for the whole detailed path thing to wait until barrows are in, then; those are where this would really work out.

But measuring 'general' distances to and from stairs using nothing but XY coordinates still works.

Logged
We don't want another cheap fantasy universe, we want a cheap fantasy universe generator. --Toady One

Keldor

  • Bay Watcher
  • Blood for the blood god!
    • View Profile
Re: Distance calculations ignore floors
« Reply #11 on: November 26, 2007, 07:31:00 am »

Just make the distance calculation multiply the Z distance by 15 or somesuch.  This not only compensates for typical fortresses not having easy access straight up and down, but will give the dwarves a natural aversion to dragging things up and down flights of stairs.
Logged
If ignorance is bliss, why are my dwarves all tantruming?

Buoyancy

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #12 on: November 26, 2007, 01:18:00 pm »

Multiplying the distance by 15 if it goes up or down a level is a terrible idea, since it ruins the ability to use the z-level to keep your fort organized and relatively efficient.  My typical forts have dozens of staircases since it allows for large stockpiles to be placed above or below the workshops without using up real estate.
Logged

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #13 on: November 26, 2007, 01:32:00 pm »

I think most complaints about this are due to an inability to use your z-axis to the utmost effect.

A stairway up or down is the same as one tile of movement.  Staircases should be as common as corridors.  Would you built long labyrinthine corridors?  No?  then why do you build long labyrithine z-axis corridors?

You could just as easily represent z-axis by rotation of planes by 90 degrees.  This would make things more clear for many players.  You do not go west to go north; do not, either, go west to go down.  You will end up going west, down, east, north, up, north, east.

I do not consider this a bug.  I would consider any pathing that artificially favored items on the same z-level to be a bug.  What if somebody posted, "Help!  My dwarves prefer items on the same y-line!  They won't go right or left to reach nearer items!"  That would be a bug, same as if dwarves preferred items on the same z-line.

Just build some more staircases.  They take up no more space than corridors.

Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.

Align

  • Bay Watcher
    • View Profile
Re: Distance calculations ignore floors
« Reply #14 on: November 26, 2007, 01:37:00 pm »

But we'd have to dig through engraved floors!
Logged
My stray dogs often chase fire imps back into the magma pipe and then continue fighting while burning and drowning in the lava. Truly their loyalty knows no bounds, but perhaps it should.
Pages: [1] 2