1
\$\begingroup\$

I've been looking closely at how Animal Crossing (for GameCube) creates town maps, and as far as I can tell, it's something like this:

The town is made up of a 5x6 grid of acres. Each acre is 16x16 "tiles" in size.

That's the easier part. As for the actual map generation, it seems to use what I'll call "acre templates." That is, the acres seem to be selected somewhat randomly from a predefined list, with predefined layouts. So there are, for example 2 different layouts of what an acre containing the Museum will look like.

Or if an acre has a river running through it, top-to-bottom, there might be 3-4 different templates of how the river flows through that acre, with optional ponds nearby, etc.

The question is... What is a good suggestion or method for how to organize the data structure to handle all of this?

Another thing to keep in mind is that there's a "second layer" of objects on top of the basic terrain info, such as trees or rocks or inventory objects dropped/buried on/in the ground. How would I store that information in relation to the acre templates?

\$\endgroup\$
  • 1
    \$\begingroup\$ It seems like you just described how the data should be structured... If not, what exactly is "all of this" and what is involved in "handling" it? Are you looking for an algorithm for selecting acre templates without discontinuities at the borders? \$\endgroup\$ – bcrist Aug 3 '14 at 7:13
  • \$\begingroup\$ Are you asking how to structure the data in memory or how to best store it on disk or? \$\endgroup\$ – StarWeaver Aug 3 '14 at 10:14
  • \$\begingroup\$ @bcrist for style reason the theory is easy for me to grasp, but I'm having a hard time figuring out how to apply it to actual code. I suppose I'm looking for what StarWeaver included in his answer, but also yes, an algorithm for selecting the right template without discontinuities at the borders. \$\endgroup\$ – Deozaan Aug 4 '14 at 8:23
  • \$\begingroup\$ I can't seem to edit my comment. Autocorrect... For *some reason... \$\endgroup\$ – Deozaan Aug 4 '14 at 8:37
  • \$\begingroup\$ You can only edit comments within 5 minutes of posting them. Also, I would suggest asking another question about the procedural generation of maps, as it's not necessarily related to a specific map structure. \$\endgroup\$ – bcrist Aug 4 '14 at 9:12
4
\$\begingroup\$

Actually, after thinking about it for a bit, here's what my solution would be for both disk and memory storage; a mock-up in JSON:

{
"map_segments": [
    ["upper_left", "top",           "top",          "upper_right"],
    ["left",       "empty",         "town_center",  "right"],
    ["left",       "shopping_area", "player_house", "right"],
    ["left",       "npc_house",     "empty",        "right"]
]
"variants" : {
    "upper_right" : [
        {
            "tiles": [
                "xxxxxxxxxxxxxxxx",
                "  .  .   . .   x",
                "  .. .    ..   x",
                "  .    * . .   x",
                "     .   . .   x"
            ],
            "default_floor": "floors.grass",
            "legend": {
                "x": "walls.townwall",
                " ": "floors.dirt",
                ".": "floors.grass",
                "*": "objects.tumbleweed"
            }
        }
    ]
    "town_square": [
        {
            "tiles": [
                "xxx          xxx",
                "xx2  .   . .xx1x",
                "  .. .%   ..|==x",
                "xx2      . .xx=x",
                "xxx  .   . . xxx"
            ],
            "default_floor": "floors.grass",
            "legend": {
                "x": "walls.townwall",
                " ": "floors.dirt",
                ".": "floors.grass",
                "|": "objects.doorv",
                "=": "floors.wood",
                "1": ["floors.wood", "spawn.village_eelder"],
                "2": "objects.herostatue",
                "%": "objects.townwell"
            }
        },
        {
            "tiles": [
                "x!!        !!!= ",
                "!x3  . 1 . !=!! ",
                "  .. .%   .==== ",
                "!x2      . =!!! ",
                "x!x  .   . !!!= "
            ],
            "default_floor": "floors.grass",
            "legend": {
                "x": "walls.townwall",
                " ": "floors.dirt",
                ".": "floors.grass",
                "!": "walls.townwall_ruin",
                "=": "floors.wood_burned",
                "1": "spawn.village_elder",
                "2": "objects.herostatue",
                "3": "objects.herostatue_broken",
                "%": "objects.townwell"
            }
        }
    ]
}
}

Basically you have a lookup mapping for each type of map segment, which contains a list of variants for that segment which you can do a random pick from. This also includes a very simple hand-editable map format similar to that I've seen in several roguelikes or other randomized games in the past; handy if you don't want to build a in-depth map editor. (StarBound also does basically the same thing, except they use several bitmaps and a color lookup table instead of an ASCII lookup table.)

\$\endgroup\$
  • \$\begingroup\$ This is very helpful in giving me ideas for how to do this, thanks! I'll give it a little more time to see if anyone else has anything else to add, and then mark the most helpful answer as the accepted answer. But I just wanted you to know that I appreciate this and I do fund it helpful. \$\endgroup\$ – Deozaan Aug 4 '14 at 8:28
  • \$\begingroup\$ I do *find it helpful. Sorry... Autocorrect. Also, I added a little more detail to the question, if you could please address that as well that would be great. \$\endgroup\$ – Deozaan Aug 4 '14 at 8:40
  • \$\begingroup\$ +1. This is somewhat similar to a system I used for a small tower defense game a while back. \$\endgroup\$ – bcrist Aug 4 '14 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.