Author Topic: Multiple stairs  (Read 13751 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Multiple stairs
« on: September 17, 2010, 06:25:07 AM »
It's easy to know where stairs lead if there are just one stairs in the destination level, but how to implement multiple stairs? By giving stairs an id they could be connected to proper destination stairs. The problem is that levels are created when player enters them, then the stairs id is not yet known! How to solve this?

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Multiple stairs
« Reply #1 on: September 17, 2010, 06:55:34 AM »
I have 'level id generator'.
When level is generated, id for next level is taken from generator.
Stairs are assigned with this id.
When player is trying to use stairs, if there is no
existing level with this id, new level is generated.
Like this.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Multiple stairs
« Reply #2 on: September 17, 2010, 09:03:51 AM »
Level ids are created in world structure (before levels are made), that's not the problem. I need individual stairs ids to connect two stairs. But I can't since the destination level (and stairs for that) is not created and if I wanted to do that I could as well create all levels at once, because some levels have several entrances to other levels.

Joonas

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Multiple stairs
« Reply #3 on: September 17, 2010, 12:05:39 PM »
I had this problem as well. I solved it simply like this:

When the world is created, I initialize a portal list with following properties:

- source site, source level
- source x, y
- portal type (normal stairs, teleporter, one-way teleporter, hole in the ground etc.)
- destination site, destination level
- destination x, y

All portals are in that list. Only one level is generated at a time. When I create a level, the list is checked for needed portals, they're created on the map and the missing properties (x,y mainly) is filled. When the player uses a portal, the list is again checked for destination site and level. Then the destination level is created, needed portals are added on the map and x,y information is filled.


Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: Multiple stairs
« Reply #4 on: September 17, 2010, 10:30:51 PM »
I'd suggest using level names. Each stair contains the name of the level it transports you to. When you use a staircase, it find the destination map, then finds the stairs that lead to the previous map. It then changes the player's location to these stairs. A lot of levels can have generic names like "Dungeon Level 2", so that they can be accessed through things like "Dungeon Level %d".
« Last Edit: September 17, 2010, 10:42:16 PM by Elig »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Multiple stairs
« Reply #5 on: September 20, 2010, 08:18:04 AM »
I'd suggest using level names. Each stair contains the name of the level it transports you to.

What is the difference to level id? I think you don't understand the problem. Hell, even I don't understand it. I just have to try and see what happens and what works the best.

purestrain

  • Rogueliker
  • ***
  • Posts: 172
  • Karma: +0/-0
    • View Profile
Re: Multiple stairs
« Reply #6 on: September 20, 2010, 08:32:40 AM »
Hell, even I don't understand it. I just have to try and see what happens and what works the best.

Thats what i thought.... i don't see any problems with multiple stairs

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Multiple stairs
« Reply #7 on: September 20, 2010, 11:16:03 AM »
I have an idea but I have to remake some level themes to try it in action. First I have level connections that are created for each level before the actual level is made. Connections are "abstract", they don't know the exact location of stairs. The destination id for node is simply taken from next node id.. so, both nodes are cross-linked to each other's ids (this also means that only source stairs need to be made, the "counterpart" is automatic). Also, when there are more than one level in theme the location can be from top/bottom/random level from that set.

The problem that remains is how to link static (some stairs are in non-random place) locations to these nodes? I think it could be done by stair creation routine with stair type and the location as parameter. When node list has that type of stairs it's created. The remaining stairs are made randomly.
« Last Edit: September 20, 2010, 11:18:36 AM by Krice »

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: Multiple stairs
« Reply #8 on: September 21, 2010, 03:51:20 AM »
I'd suggest using level names. Each stair contains the name of the level it transports you to.

What is the difference to level id? I think you don't understand the problem.
It's not a big difference, either way would work. You don't need to know the coordinates of the stairs being linked to before the player actually uses the stairs, that's the thing.  When the player uses the stairs, just look up the map via ID or name, and then find the stairs on that level which link back to the first. Move the player to the location of those stairs. You're over thinking this, you don't need to know anything in advance except the floor that the stairs link to. Everything else can be found out when the player actually uses the stairs.

If you want to use multiple stairs to and from the same levels, just have an index variable that decides which stairs on the new floor to link to. Start the index at 0, and for every staircase added to the map, increase by 1. Store this index number in the stairs themselves (as in, each staircase has it's own unique number). Just make sure that you have the same number of stairs on each map. For example, 4 stairs on the first map would have index numbers 0-3, then when the map being linked to is generated, it would generate 4 stairs going to the previous map which would have index numbers 0-3. Then, when the player uses the stairs, find the new map, then search for the stairs linking to the previous map that have the same index number as the stairs that the player just used.
« Last Edit: September 21, 2010, 04:03:24 AM by Elig »

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Multiple stairs
« Reply #9 on: September 21, 2010, 04:13:05 AM »
Example.
There is level with id 1 and two stairs from this level to (not yet existing) level with id 2.
Both stairs have lvlId=2 as destination, but unassigned destination positions.
When player tries to use either staircase on lvl1, game checks that
level with lvlId=2 is not generated yet, and starts generation,
passing lvlId1 as source level.
When new level is generated, it asks source level for a list of stairs.
The same amount of incoming stairs is generated on new level,
and both sets are randomly connected.

But in my case levels are strictly linear with possible dead end branches.

If you need proper cross-level stairs (portals?) than you need global
stairs/portals repository with indexes by source and destination.

Hm. I think I see the problem...
It looks like in general case you need to construct complete levels connection graph beforehand.
When generating specific level you need to know for sure how much stairs/portals
have destination point at this level.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Multiple stairs
« Reply #10 on: September 21, 2010, 07:10:42 AM »
The first step is complete, but I still need to add automatic connections to set of levels in the theme.

Code: [Select]
//create connections to other levels
int *ptr;
int node_id=0;
for (int t=0; t<Amt_Of_Level_Themes; t++)
{
T_Level_Theme th(t);
ptr=th.Get_Connections();
int p=0;
while (ptr[p]!=-1)
{
//get source level id
int sid=Get_Level_ID(t, ptr[p+lnd::source_node_type]);
//get destination level id
int did=Get_Level_ID(ptr[p+lnd::dest_level_theme], ptr[p+lnd::dest_node_type]);

//make source stairs
T_Level_Node sn(node_id, ptr[p+lnd::stairs_type], node_id+1, did);
level_list[sid]->Add_Level_Node(sn);

//create a pair for it in destination level
T_Level_Theme dth(ptr[p+lnd::dest_level_theme]);
int st;
//try to figure out the destination entrance type
if (dth.Can_Exit_From_Border()) st=stBorder_Exit;
else
{
st=stStairs_Up;
}
//use reverse node ids to link back to source node
T_Level_Node dn(node_id+1, st, node_id, sid);
level_list[did]->Add_Level_Node(dn);

p+=lnd::size_of_data_block; //next data block
node_id+=2; //new node ids for the next pair
}
}

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Multiple stairs
« Reply #11 on: September 21, 2010, 11:05:50 AM »
The code for connecting levels of a set, it actually seems to work!

Code: [Select]
//create internal stairs between levels of a theme when more than one level in the set
for (int t=0; t<Amt_Of_Level_Themes; t++)
{
vector<int> set_levels;
int a=Count_Levels_Of_Theme(t, set_levels);
if (a>1)
{
int down_st;
int up_st;
T_Level_Theme th(t);
if (th.Get_Generation_Direction()==D_Down) { down_st=stStairs_Down; up_st=stStairs_Up; }
else { down_st=stStairs_Up; up_st=stStairs_Down; }
for (int r=0; r<a-1; r++)
{
int slv=set_levels[r];
int dlv=set_levels[r+1];
//source stairs
T_Level_Node sn(node_id, down_st, node_id+1, level_list[dlv]->Get_ID());
level_list[slv]->Add_Level_Node(sn);
//destination stairs
T_Level_Node dn(node_id+1, up_st, node_id, level_list[slv]->Get_ID());
level_list[dlv]->Add_Level_Node(dn);

node_id+=2;
}
}
}

Edit: Actually T_Level_Node is not needed if I change Stairs class to contain that data and fill in the missing location just like Joonas suggested.. well..
« Last Edit: September 21, 2010, 11:21:10 AM by Krice »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Multiple stairs
« Reply #12 on: September 26, 2010, 08:19:55 AM »
I used the same code in Kaduria, but instead of theme-divided I used 'nodes' that are one or collection of levels (areas of dungeon) which then are connected with same kind of data for stairs. Also, I had to store the connection tree separately to World class, because there is only one level at a time in Kaduria. Other than that it worked great! I'm happy that I went through this and created somewhat flexible system for this thing.