Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 9 10 [11] 12 13 ... 72

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

Andir

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #150 on: January 29, 2009, 08:51:10 pm »

Spoiler: EPIC FAIL (click to show/hide)
This is going to take some time.
What is width?  Was width defined and declared as an unsigned int?
Logged
"Having faith" that the bridge will not fall, implies that the bridge itself isn't that trustworthy. It's not that different from "I pray that the bridge will hold my weight."

Fenrir

  • Bay Watcher
  • The Monstrous Wolf
    • View Profile
Re: The Roguelike Development Megathread
« Reply #151 on: January 29, 2009, 09:54:55 pm »

What is width?  Was width defined and declared as an unsigned int?
width is the width of the viewport. It's an int, but not unsigned. I don't think that's the problem, though. Attempting to access any element of the dynamic array "map" (an of integers) leads to a crash. I've no idea why.

It's initialized in the constructor:
Code: [Select]
Viewport::Viewport(int* map, int mapWidth, int mapHeight)
{
    this->mapWidth = mapWidth;
    this->mapHeight = mapHeight;
    this->map = new int[mapWidth * mapHeight];
}
Logged

Andir

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #152 on: January 30, 2009, 01:43:01 am »

You are accepting "int * map" as a pointer to the map, but you never use it?  That's fine for now if you don't use it yet, but be aware that right now you are creating that pointer in the Viewport constructor and it's being deleted automatically when the constructor is finished.  I'm assuming you will likely assign it to an instance variable later.

As far as accessing the map array (that is an array?  It looks like it how you are defining.) how are you going about it?  Can you paste the declaration for Viewport::map[]?
Logged
"Having faith" that the bridge will not fall, implies that the bridge itself isn't that trustworthy. It's not that different from "I pray that the bridge will hold my weight."

deadlycairn

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #153 on: January 30, 2009, 02:53:43 am »

How do you declare the prototype of a function within a class? Or will I have to waste yet more time turning one of my classes into a seperate page and adding a header for it?
Logged
Quote from: Ampersand
Also, Xom finds people that chug unidentified fluids pleasing.
Quote from: Servant Corps
Ignorance of magic does not give scientists the power to resist fireballs.

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Re: The Roguelike Development Megathread
« Reply #154 on: January 30, 2009, 08:06:22 am »

I think that classes are really handy for roguelikes.  Inheritance saves so much writing space.  Theres a nice tutorial of c++ ripped apart: http://www.bay12games.com/forum/index.php?topic=27973.msg357848#msg357848. that explains in simple terms how to do this.

  So you will have for example Entity Class (name, hp, and all general things) then monster class (type, attack, whatever) and player class (all that things that only you might have) descending from it.  The same with general objects and other things descending from it: potions (ingredients, etc), Weapons(type, etc).

  Remember that together with public and private there is also "protected" wich allows the "sons" of the class to access it's fathers protected variables... wich comes really handy.

There is also a link that come prove useful:
http://roguebasin.roguelikedevelopment.org/index.php?title=How_to_Write_a_Roguelike_in_15_Steps
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

Rhodan

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #155 on: January 30, 2009, 08:21:08 am »

Reading through those steps reminded me of my biggest nemesis in any game attempt ever: Saving.
I know how to make a file, and I know how to read from it, but I have no clue how I could ever  save the current state of all monsters and items in the game, especially if they're all pointing at each other and are in the middle of performing some action.
Do I write out every variable of the object in a little list and save that, recreating them all when loading?  With a proper Save() function on all objects this can be feasible, but what about the pointers?

If a dragon is chasing something, he probably uses a pointer to keep track of his prey.  But how do I save and load those?
Logged

Fenrir

  • Bay Watcher
  • The Monstrous Wolf
    • View Profile
Re: The Roguelike Development Megathread
« Reply #156 on: January 30, 2009, 08:50:09 am »

You are accepting "int * map" as a pointer to the map, but you never use it?
Haha! I totally forgot about that. That might be the problem.

EDIT:
I found the problem! I've been accessing my dynamic arrays incorrectly, so it was going out of bounds. Now I just need to determine the right way and I'll be in business.
« Last Edit: January 30, 2009, 09:03:44 am by Fenrir »
Logged

Granite26

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #157 on: January 30, 2009, 09:30:45 am »

Reading through those steps reminded me of my biggest nemesis in any game attempt ever: Saving.

I'm not sure how .net specific it is, but I'm using binary serialization, which recreates an exact copy of the object I serialize.  Since I have a 'game' class that stores the instances of every existant critter, when I serialize the game, everything gets saved.  Not pretty, not elegant, but a single function.

Rhodan

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #158 on: January 30, 2009, 09:58:32 am »

Hmmm, sounds interesting.  If I serialize monsters seperately, I doubt their pointers would still work though, so any system where only part of the game gets saved during play (visited dungeon levels) wouldn't work that well.
Unless I shove all entities in a waiting list, assign each a numeric ID and save their pointers as the ID of the thing they're pointing to, then reinstate those pointers upon load... I'm missing something here.
Logged

Granite26

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #159 on: January 30, 2009, 10:22:21 am »

Hmmm, sounds interesting.  If I serialize monsters seperately, I doubt their pointers would still work though, so any system where only part of the game gets saved during play (visited dungeon levels) wouldn't work that well.
Unless I shove all entities in a waiting list, assign each a numeric ID and save their pointers as the ID of the thing they're pointing to, then reinstate those pointers upon load... I'm missing something here.

when you leave a dungeon level, the monsters should forget who their chasing, unless you want to come back later and still have the cat chasing the mouse around the pillar.

Defining your own serialization should allow you to set all the pointers to 0, or even a 'prepare for sync' function.

Honestly, I wouldn't serialize the monsters seperately at all, just one big 'serializemap' function that hits everything it owns (which should be everything but the character).  In that case, all the pointers WILL come back (binary serialization is fun that way).  All you have to do is handle the case where the monster is pointing at something that doesn't belong to the level (like the PC or his allies).

I'm not sure I would let the characters on the map store a pointer to the actual character, though.  It seems more 'correct' for the map to point to a handler and the monster to know how to get what it needs through that.  (something to think about.)

In my case, it was just a case of marking all my classes as ISerializable. .net has made me lazy

Fenrir

  • Bay Watcher
  • The Monstrous Wolf
    • View Profile
Re: The Roguelike Development Megathread
« Reply #160 on: January 30, 2009, 10:43:29 am »

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHH!!!

That is all.
Logged

Rhodan

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #161 on: January 30, 2009, 11:05:38 am »

Dunno, if you want monsters to behave in ways more interesting than 'chase - run - chase', they should remember a few pointers to relevant objects, monsters and locations.  A dragon should, for example, have a hoard it likes to sit on.  When it detects enough treasure elsewhere, it should go get this treasure and bring it back to its hoard.  The delicious, albeit pointy snack that was carrying said treasure is a bonus.  It should also know about other dragons on the level, so it won't go stealing from their hoard unless the other dragon is weaker but richer.  Can't have the youngsters hoarding all the treasure.
Logged

Granite26

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #162 on: January 30, 2009, 11:27:46 am »

Dunno, if you want monsters to behave in ways more interesting than 'chase - run - chase', they should remember a few pointers to relevant objects, monsters and locations.  A dragon should, for example, have a hoard it likes to sit on.  When it detects enough treasure elsewhere, it should go get this treasure and bring it back to its hoard.  The delicious, albeit pointy snack that was carrying said treasure is a bonus.  It should also know about other dragons on the level, so it won't go stealing from their hoard unless the other dragon is weaker but richer.  Can't have the youngsters hoarding all the treasure.

All of which is a perfectly valid thing to store on the map.  Serialize the map and the dragon goes with it.  Also, there's no reason to store a pointer to the treasure when you can store it's location.

GUIDs are also your friend.  Smaug knows about Puff(GUID:XXXXYYYYXXYYY), not Puff(Pointer XXX).  Smaug accesses Puff through Map.Creatures(GUID) rather than a straight pointer to Puff.

(Map.Creatures can link to Game.Characters as well).

Fenrir

  • Bay Watcher
  • The Monstrous Wolf
    • View Profile
Re: The Roguelike Development Megathread
« Reply #163 on: January 30, 2009, 11:50:30 am »

VICTORY!!!

I got the Viewport working!



Note the gaping void that is Ginnungagap.
Logged

Rhodan

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #164 on: January 30, 2009, 12:15:59 pm »

But the dragon shouldn't just know where its hoard it, it should also know the hoard itself.  Imagine someone steals it?  Preferably, the dragon would store the last known location and a pointer.  If it can't find the hoard at the last known location, it should wander around looking for it.
Dragons should be Epic, not just a big 'D' you can stab, so they should have a more detailed AI so they pose a longer lasting threat to the player.  That's why at least some monsters should have persistent memories lasting over multiple levels.
I'm intrigued by this GUID thing, though.  What is it?

Fenrir, that looks neat so far!  You should try DF-style trees though, I keep thinking there's an army of green trolls there.
Logged
Pages: 1 ... 9 10 [11] 12 13 ... 72