# Worldgen Rewrite

**URL:** https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934
**Category:** The Drawing Board
**Created:** [February 17, 2015, 5:43am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934 "2015-02-17T05:43:36Z")
**Posts on this page:** 20
**Page:** 4

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 23, 2015, 9:44pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/61 "2015-02-23T21:44:20Z")

</div>

Alright, I figured out why I’m not getting native subways, ant-hills, or sewers, and in order to fix it I’m going to add a bitfield to oter\_t with flags for is\_asphalt, is\_sewer, is\_building, etc. Should I also go through and change all the existing bools on oter\_t to use said bitfield, or would you rather I left them be?

Also, I see no reference to std::bitfield. Did you mean std::bitfset?

---

<div class="post-metadata">

### Author: ![i2amroy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/i2amroy/32/909_2.png) [@i2amroy](https://discourse.cataclysmdda.org/u/i2amroy)
#### Post date: [February 23, 2015, 10:03pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/62 "2015-02-23T22:03:13Z")

</div>

std::bitset is what you would want, yeah (which implements a bitfield).

Important note, but document what the bitfield contains thoroughly; you might even want to make getter functions (like “get\_is\_sewer()”) instead of accessing the bitfield directly to ensure that clarity of what each spot is is maintained.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 23, 2015, 10:06pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/63 "2015-02-23T22:06:05Z")

</div>

That’s what I was planning, yes.

So it’s alright if I go and shove the booleans for Rotates, Is\_river, allows\_road, etc into the bitset as well? Also I’m planning on renaming Is\_road, because it has barely anything to do with roads.

---

<div class="post-metadata">

### Author: ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)
#### Post date: [February 24, 2015, 8:52am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/64 "2015-02-24T08:52:15Z")

</div>

> [@Angle](#):
>
> So it’s alright if I go and shove the booleans for Rotates, Is\_river, allows\_road, etc into the bitset as well?

Yeah, it would work well.  
Do create an enum for it, though. Look at how it is used in mtype.h and mtypedef.cpp. There’s an enum declared for the flags and the bitfield is only accessed through a getter: `has_flag( flag_enum_type_here )`  
That way it is all cleanly expressed as, for example, `m.has_flag(MF_SEES)` rather than `m.type->flagfield[4]`

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 24, 2015, 5:28pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/65 "2015-02-24T17:28:09Z")

</div>

I’s actually been making individually named functions for each bit, I.E. is\_asphalt(), set\_asphalt(), is\_ants(), set\_ants, etc. It might be easier to just use an enum, though.

In other news, I’m trying to come up with a way to implement an “Architect” system, for when you have multi-tile structures you want to be intelligently laid out, like labs, mansions, malls, skyscrapers, that bloody necropolis, etc. That way, instead of having 100 mall tiles, you can just have like one or two, and instead have the architect figure out what to put on each tile.

Also, does anyone know why it sometimes accesses an oter\_t from an oter\_id by using “oter\_id.t()” and sometimes by using “otermap[oterid]”? what’s the rationale behind that?

---

<div class="post-metadata">

### Author: ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)
#### Post date: [February 25, 2015, 3:30am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/66 "2015-02-25T03:30:30Z")

</div>

For the necropolis, I’d suggest leaving them alone for now, and considering converting them to dynamic generation as a seperate set of changes. The same applies for the mall and prison. It would be all too easy to get bogged down in making that just right and delaying the rest of the system.  
We will want to keep a system around that allows people to statically define structures anyway, some people can’t or don’t want to deal with dynamic generation, and just want to supply static layouts.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 25, 2015, 3:43am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/67 "2015-02-25T03:43:03Z")

</div>

Yeah, I’m thinking I’m going to make sure there’s an option for that in my Architect system, and port the generation of those into it. and that won’t come until much later, I’m about 90% done with part A, altering the tile code to support the multiple tile types. after that comes changing the mapgen to actually care about the multiple tile types, and then moving the map extras into tiles, and making some of them invisible.

After that, though, should I procede with D though G: Editing the worldgen code to make the placements of tiles make more sense, adding additional functionality for varying regions, adding many more tile types and the worldgen code to handle them, and adding an additional region type, Heavy Forest? or should I skip all that and work on the Architect system?

I should probably also point out that it might be easier to just go and implement the new Architect system than to go through and make the malls, prisons, and necropoli play nice with my new system on account of how many tiles they have. Like seriously, two thirds of the overmap\_terrain file is for those two.

---

<div class="post-metadata">

### Author: ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)
#### Post date: [February 25, 2015, 4:08am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/68 "2015-02-25T04:08:13Z")

</div>

I don’t follow, we WILL support specifying building layouts statically, that’s not negotiable, so if you’re overhauling everything you are going to have to implement support for buildings like that anyway. If you think you can improve on them by making them dynamic, great, but the ability to do large-scale static layout like that is a must.

---

<div class="post-metadata">

### Author: ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)
#### Post date: [February 25, 2015, 4:20am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/69 "2015-02-25T04:20:08Z")

</div>

> [@Angle](#):
>
> Also, does anyone know why it sometimes accesses an oter\_t from an oter\_id by using “oter\_id.t()” and sometimes by using “otermap[oterid]”? what’s the rationale behind that?

otermap[oterid] is used when oterid is a string. When you have oter\_id, use oter\_id.t() instead.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 25, 2015, 4:22am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/70 "2015-02-25T04:22:25Z")

</div>

My point is that it’d be easier to reprogram things so we have that without having a billion different overmap tiles. Instead, you’d just have a big blob of the same kind of mall tile, and then it’d load the information for the function that manages the layout from the JSON files. Th Architect would then go through and generate all of these tiles at once, using the information it loaded from the JSON to figure out where to add the individual details. I’ll have to add a new JSON detail, and translate the existing functions into it, but that shouldn’t be too much of a problem, and I was planning on doing it anyway.

---

<div class="post-metadata">

### Author: ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)
#### Post date: [February 25, 2015, 9:52pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/71 "2015-02-25T21:52:38Z")

</div>

Oh ok, so you just have one gigantic blob of layout that does the whole thing, and a second entry just for the shape of it on the overmap? if so yes that’s a massive improvement.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 25, 2015, 10:37pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/72 "2015-02-25T22:37:19Z")

</div>

Yup. Looking at things, the current code is so unwieldy, that doig the whole architect rewrite right now, before I progress any further is probably worthwhile. I mean, have you seen map::draw\_map in mapgen.cpp? Over 8000 lines for one function! Oh, the humanity!

So the way things’ll work now, is that you’ll have a class called Architect. The architect has a list of pointer, or references, to the tiles it works with. It also has a description of what it’s supposed to put on them, I.E. a list of possible rooms and hallways, and instructions on how to put those together. This will include capabilities to just specify static layouts, I.E. what I’ll do for the mall, necropolis, etc. For things that aren’t completely static, though, like mansions & labs, it’ll go through and decide how many of each room it’ll put in the whole building, figure out where the hallways should go, and match the two up. Then it goes and actually generates the terrain for the individual tiles, following it’s schematic.

---

<div class="post-metadata">

### Author: ![Frostwood](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/frostwood/32/112_2.png) [@Frostwood](https://discourse.cataclysmdda.org/u/Frostwood)
#### Post date: [February 26, 2015, 1:05am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/73 "2015-02-26T01:05:52Z")

</div>

[quote=“Angle, post:72, topic:8934”]Yup. Looking at things, the current code is so unwieldy, that doig the whole architect rewrite right now, before I progress any further is probably worthwhile. I mean, have you seen map::draw\_map in mapgen.cpp? Over 8000 lines for one function! Oh, the humanity!

So the way things’ll work now, is that you’ll have a class called Architect. The architect has a list of pointer, or references, to the tiles it works with. It also has a description of what it’s supposed to put on them, I.E. a list of possible rooms and hallways, and instructions on how to put those together. This will include capabilities to just specify static layouts, I.E. what I’ll do for the mall, necropolis, etc. For things that aren’t completely static, though, like mansions & labs, it’ll go through and decide how many of each room it’ll put in the whole building, figure out where the hallways should go, and match the two up. Then it goes and actually generates the terrain for the individual tiles, following it’s schematic.[/quote]  
So it will support both static and random generation?, sounds cool.  
The only thing I’m concerned is whether or not you are going to have to change the jsons to work with the new system, if so… that’s a lot of work.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 26, 2015, 2:21am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/74 "2015-02-26T02:21:30Z")

</div>

I’ve already had to edit the overmap\_terrain JSONs a bunch. I’m actually hoping that implementing this system will help me avoid having to edit the remaining two thirds of it too. Ad yes, I’ll probably have to add a another JSON file or two, but that’s manageable.

---

<div class="post-metadata">

### Author: ![Zireael](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zireael/32/956_2.png) [@Zireael](https://discourse.cataclysmdda.org/u/Zireael)
#### Post date: [February 26, 2015, 2:45pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/75 "2015-02-26T14:45:27Z")

</div>

Angle, that’s some amazing work you’re doing!

A hint from someone who pushed a few PRs: once you have the basic Architect framework working, PR it and do the next stages as separate PRs. This way, they get reviewed (and merged) faster!

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 26, 2015, 10:36pm UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/76 "2015-02-26T22:36:07Z")

</div>

Hmm, possibly. I want to make sure I have everything working at least as well as it was once I started. But yeah, I’ll PR before I start adding new content.

---

<div class="post-metadata">

### Author: ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)
#### Post date: [February 27, 2015, 2:42am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/77 "2015-02-27T02:42:59Z")

</div>

> [@Angle](#):
>
> So the way things’ll work now, is that you’ll have a class called Architect. The architect has a list of pointer, or references, to the tiles it works with. It also has a description of what it’s supposed to put on them, I.E. a list of possible rooms and hallways, and instructions on how to put those together. This will include capabilities to just specify static layouts, I.E. what I’ll do for the mall, necropolis, etc. For things that aren’t completely static, though, like mansions & labs, it’ll go through and decide how many of each room it’ll put in the whole building, figure out where the hallways should go, and match the two up. Then it goes and actually generates the terrain for the individual tiles, following it’s schematic.

The only thing that concerns me about this is that last step, at exactly what point in game execution is a tile populated? It sounds like if you get in range of a mall your game is going to stop for several seconds to sort the whole thing out, which if it isn’t obvious is a thing we don’t want.  
One very good thing about how the current system works is the separation of overmap and submap generation, we don’t want to lose that. You should however be able to make decisions about things at the higher level and bundle up some state for the lower level code to process further.

> [@Zireael](#):
>
> A hint from someone who pushed a few PRs: once you have the basic Architect framework working, PR it and do the next stages as separate PRs. This way, they get reviewed (and merged) faster!

> [@Angle](#):
>
> Hmm, possibly. I want to make sure I have everything working at least as well as it was once I started. But yeah, I’ll PR before I start adding new content.

Please rethink this, it sounds like you have a gigantic amount of changes already, and are about to embark on an even bigger set of changes, that is a bad idea. Please keep this in mind, if your PR becomes too big, it CAN get to the point where it will never be merged, simply because of its size.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 27, 2015, 3:36am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/78 "2015-02-27T03:36:26Z")

</div>

I was planning to have it generate the tiles for large things at world creation. It’ll slow things down a bit, But I think that’s acceptable. As for merging, the game is currently not in as good a state as it was when I started. I haven’t gone over the mall, necropolis, etc. yet, so they have roads and building dropped on top of them on a regular basis. Perhaps I could merge the changes that have happened to cataclysm since, into my repo?

---

<div class="post-metadata">

### Author: ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)
#### Post date: [February 27, 2015, 3:56am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/79 "2015-02-27T03:56:02Z")

</div>

Generating tiles of large things at world generation (actually overmapgen, there is no world gen) is not ok, that is an unbounded and unmanageable amount of computation to do up front, and worse overmapgen happens at unpredictable intervals as the player moves around. Doing all the work for large structures in one shot is simply not a workable solution, there is no point where it’s reasonable to do up to several hundred tiles of mapgen all in one go. Your solution _must_ break map generation into tiered pieces.

I’ve been insisting all along you need to break changes up into manageable pieces, if you don’t do that this isn’t going anywhere. Yes, you need to either merge the upstream repository into yours or rebase your changes on top of upstream on a regular basis, if you don’t it WILL become unmergeable. That doesn’t have a thing with making your changes manageable though, your changes need to be small enough to review and test in a reasonable amount of time. For context, 1000 lines of changes (not counting straightforward renames) is a very large PR.

---

<div class="post-metadata">

### Author: ![Angle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angle/32/957_2.png) [@Angle](https://discourse.cataclysmdda.org/u/Angle)
#### Post date: [February 27, 2015, 4:53am UTC](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934/80 "2015-02-27T04:53:37Z")

</div>

Hmm. Alright, I’ll work on both of those things.

[Previous page](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934.md?page=3)

[Next page](https://discourse.cataclysmdda.org/t/worldgen-rewrite/8934.md?page=5)
