Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 48 49 [50] 51 52 ... 72

Author Topic: The Roguelike Development Megathread  (Read 245574 times)

The Rookie

  • Escaped Lunatic
    • View Profile
    • The Rookie
Re: The Roguelike Development Megathread
« Reply #735 on: October 14, 2012, 05:20:36 pm »

EDIT: alexandertnt explained it much better in the post below.
« Last Edit: October 14, 2012, 05:32:26 pm by The Rookie »
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #736 on: October 14, 2012, 05:23:57 pm »

I am not familier with libtcod, but I can guess that...

Again, that's... kind of only useful if you know what it already is...
Code: [Select]
    # Create path.
    path = lib.path_new_using_map(fov_map, 1.41)
I only know that 1.41 is the cost of a diagonal move by the info on another page.

Im assuming this sets up the map nodes/edge list. Path would be something to store this information. If that is what this is, it is probably best to do this only once after the map has been created or whenever the map changes, and store the result.

Code: [Select]
    # Compute path.
    lib.path_compute(path, obj.x, obj.y, target.x, target.y)
I really have no idea what this actually does.  I mean, I can see that it's your starting position and your target position, but I don't know what it does and that would be really helpful if I want to use it reliably.

This probably does the actual path finding (A*, there is apparently a seperate function for Dijkstra's).

Code: [Select]
    testx, testy = lib.path_walk(path, False)
I really have no idea about this one at all.  Where did testx and testy come from?  What is this doing?  What is False?

This probably gets the next closest position (node) along the computed path. If you called this every update and set whatever-is-moving's X and Y to testx and testy, it would probably start moving along the path. The second argument is whether it should recalculate the path if needed. Im guessing if your map doesn't change, it is safe to leave this at false.

Code: [Select]
    # Make sure tile isn't blocked by any other objects.
    if not is_blocked(testx, testy):

        obj.x, obj.y = testx, testy
Same as above, I've gotten lost now.

testx and testy are the next position that the thing needs to move to. Im assuming that not_is_blocked is some function you have to provide to check that nothing is in it's way when it tries to move.

If the python version of libtcod is set up for it, you can try running help(lib.path_walk) in the interactive shell (and with other functions).

also this might help (The next 2 pages are also relevant).
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

The Rookie

  • Escaped Lunatic
    • View Profile
    • The Rookie
Re: The Roguelike Development Megathread
« Reply #737 on: October 14, 2012, 05:31:46 pm »

alexandertnt explained it much better than I did. Thanks!

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #738 on: October 14, 2012, 07:41:04 pm »

Ok, that makes some sense.  So, how would I like, keep the info?  In DF, a dwarf does pathing when it takes a job, and then follows the path.  It only recalculates the path if it's interrupted (by a mason building surprise walls).  How would that work?

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #739 on: October 14, 2012, 08:52:58 pm »

Ok, that makes some sense.  So, how would I like, keep the info?  In DF, a dwarf does pathing when it takes a job, and then follows the path.  It only recalculates the path if it's interrupted (by a mason building surprise walls).  How would that work?

When your is_blocked function returns true, you will probably need to recalculate the "path" variable, so the pathfinder is now aware of this blockage (path = lib.path_new_using_map(fov_map, 1.41)). Then, just do lib.path_compute(path, obj.x, obj.y, target.x, target.y) again.

something like:

Code: [Select]
   
if not is_blocked(testx, testy):
        obj.x, obj.y = testx, testy
else:
        # The route is blocked, recalculate path (So that path_compute will be aware of this blockage). This is a function defined by you.
        update_path_variable()
        # Using the new path, work out a route.
        lib.path_compute(path, obj.x, obj.y, target.x, target.y)

Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Biag

  • Bay Watcher
  • Huzzah!
    • View Profile
Re: The Roguelike Development Megathread
« Reply #740 on: October 15, 2012, 12:54:27 am »

Ok, that makes some sense.  So, how would I like, keep the info?  In DF, a dwarf does pathing when it takes a job, and then follows the path.  It only recalculates the path if it's interrupted (by a mason building surprise walls).  How would that work?

Are you asking how an actor "remembers" the path? I'm not sure if this is the most memory-efficient way of doing it, but I'd just have an instance variable in the AI to hold onto that path- MonsterBrain.currentPath or something.
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #741 on: October 15, 2012, 06:24:17 pm »

Ok, that makes some sense.  So, how would I like, keep the info?  In DF, a dwarf does pathing when it takes a job, and then follows the path.  It only recalculates the path if it's interrupted (by a mason building surprise walls).  How would that work?

Are you asking how an actor "remembers" the path? I'm not sure if this is the most memory-efficient way of doing it, but I'd just have an instance variable in the AI to hold onto that path- MonsterBrain.currentPath or something.

The ammount of memory it would take to store the path would be quite insignicant. The speed gained would easily outway the slight reduction in memory efficiency.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #742 on: October 15, 2012, 06:27:00 pm »

Yeah, the path should be just a list of x,y coordinates, right?  That's paltry.  Although my currently planned game should never have more than two dozen actors in the busiest scene, and many of them standing still fighting/farming/fishing/etc so it shouldn't be a huge issue anyways.

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #743 on: October 15, 2012, 07:21:43 pm »

DOUBLEPOST COMBO!
so this is my current (very basic) terrain generation:
Spoiler (click to show/hide)
How would I go about making this a bit more straightforward?  For instance, if I previously defined a tile (probably in another file so I could keep it orderly, and then import it) could I do this?
Spoiler (click to show/hide)

da dwarf lord

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #744 on: October 15, 2012, 07:41:26 pm »

DOUBLEPOST COMBO!
so this is my current (very basic) terrain generation:
Spoiler (click to show/hide)
How would I go about making this a bit more straightforward?  For instance, if I previously defined a tile (probably in another file so I could keep it orderly, and then import it) could I do this?
Spoiler (click to show/hide)

I'm not sure, seeing as I haven't used python in 6 months, but if you just defined a tile like that and then for some reason had to change the tile ( cutting the tree down etc.) I think that would affect all of the tree tiles because they all reference to one instance of tile.tree... so you would have to make a child class of the tile class used in map[][], and set the default values to the tree values. I hope this helps  :D
« Last Edit: October 15, 2012, 08:13:12 pm by da dwarf lord »
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #745 on: October 15, 2012, 07:47:19 pm »

Hmm, yes, Python has a tendency to change everything at once.  Well, I could make it slightly more modular, at least, right?
Code: [Select]
    for x in range(MAP_HEIGHT):
        for y in range(MAP_WIDTH):
            if libtcod.random_get_int(0,0,100) < 25:
                set_tile(x,y,tiletype.tree)
and then
Code: [Select]
def set_tile(x,y,tile):
  map[x][y].name=tile.name
  map[x][y].color=tile.color
  map[x][y].char=tile.char
  ...
That would be an easier way of transcribing data, at least.  And that way, when I need to cut down a tree, just set_tile(x,y,tile.stump) and it's smooth.

Any other good ways to handle this?

da dwarf lord

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #746 on: October 15, 2012, 08:22:55 pm »

Hmm, yes, Python has a tendency to change everything at once.  Well, I could make it slightly more modular, at least, right?
Code: [Select]
    for x in range(MAP_HEIGHT):
        for y in range(MAP_WIDTH):
            if libtcod.random_get_int(0,0,100) < 25:
                set_tile(x,y,tiletype.tree)
and then
Code: [Select]
def set_tile(x,y,tile):
  map[x][y].name=tile.name
  map[x][y].color=tile.color
  map[x][y].char=tile.char
  ...
That would be an easier way of transcribing data, at least.  And that way, when I need to cut down a tree, just set_tile(x,y,tile.stump) and it's smooth.

Any other good ways to handle this?

I would say that would be the best way to do it, plus you get to have the fun of dealing with pythons annoying importing system, consider it a learning experience :D
Logged

Neonivek

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #747 on: October 15, 2012, 08:28:44 pm »

Dang programming super geniuses!

I'll show you! I'll show you someday!
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #748 on: October 15, 2012, 08:41:21 pm »

Is all this encapsulated in a class? If it is you can inherit this class and override set_tile to make different maps easily.

something along the line of:

Code: [Select]
class A_Map(object):
    # Generates trees. __init__ will be called when A_Map instance is created.
    def __init__(self):
        for x in range(MAP_HEIGHT):
            for y in range(MAP_WIDTH):
                if libtcod.random_get_int(0,0,100) < 25:
                    self.set_tile(x,y)
    def set_tile(self, x, y):
         # Use map[x][y] to set up trees
         pass

And can be adapted to place something like rocks easily:

Code: [Select]
# Map that places rocks. __init__ is inherited from A_Map
class A_Rocky_Map(A_Map):
    def set_tile(self, x, y):
        # Use map[x][y] to set up rocks
        pass

Then create them like

Code: [Select]
A_Forest = A_Map()
A_Mountain = A_Rocky_Map()

You could also have a look at Perlin Noise to make more interesting and natural maps. A 2D Perlin Noise generator could help with generating stuff like biomes.


Dang programming super geniuses!

I'll show you! I'll show you someday!

Start now. Programming is hard to begin learning, but once you start to get the hang of it, it becomes pretty easy to continue to learn more advanced concepts. Its a massive motivator when you can actually see a creation of yours doing something interesting, but before you get there you have to start printing "Hello World" on the screen in different ways.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Neonivek

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #749 on: October 15, 2012, 08:42:38 pm »

The biggest barrier to learning many skills is simply that there is no starting point or spring board anyway.
Logged
Pages: 1 ... 48 49 [50] 51 52 ... 72