1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

What happened to map generators?

Discussion in 'Modding [KAG]' started by Frikman, Jul 9, 2016.

  1. Frikman

    Frikman Bison Rider

    Messages:
    162
    Hi, I've been testing and tweaking the Zombie Fortress mod dor the past few weeks, but I can't help but feel it lacks something really important: random dungeon-like maps.
    The current map generator is really basic compares to classic map generators, and if I try setting the same values classic gens have the results will be monstrosities of maps. Using the same files won't help that much either, since trees, water or caves won't be generated at all. The workaround I found was generating maps on kag classic first and then fix them, but it takes out the randomness of having a different map each round.
    Does anyone have an idea of how I could configure a .cfg file to generate caves, pasagges and simple structures or it's just deemed to fail because of engine limitations?
     
    Osmal and Sytoplasma like this.
  2. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Hey there. Can I be the first to say your work on modding recently has been nice to see.

    Map generation has been moved from the engine to scripts - meaning you can write your own completely custom map generator, including one based on either configs or images. In KAG we have kaggen configs which can be used for simple random terrain (and would be fairly easy to add more structures to for per-gamemode fun), and in trench run we have random cave patch generation.

    The reason for this is that the tile numbers changed quite a lot during the engine update, physics changed a lot and there were no more zombies to account for, so porting the old generator didn't make much sense.

    So, you'll have to write some code to accomplish this; @8x, @cameron1010 and maybe @makmoud98 are probably good people to hassle day-to-day about specifics as I think each of them have had some interaction with the map loading process or the current generator.
     
  3. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    test.kaggen.cfg is the sandbox map, it utilizes KAG's random map generator. (a lot of people don't know that the sandbox map is randomly generated) The script for the generator is GenerateFromKAGGen.as. Read through all the values that are in test.kaggen.cfg, you might find what you need. Otherwise, you can always just program more options into the script if you know how to code. I can help you out with some code most likely.
     
    PUNK123 and Sytoplasma like this.
  4. Frikman

    Frikman Bison Rider

    Messages:
    162
    That explains why the test.cfg file seemed so simple. So, after looking the GenerateFromKAGGen.as inside the mod folder I noticed it has a few changes for spawning portals, scrolls and other stuff, but it generates overlaped rectangles with tons of portals. While looking at the generator from classic I noticed this
    Code:
    # castle
    
    # area_generator = wang tiles grid; wang tile width; wang tile height;
    #                  area left corner x (% of map width); area upper corner y (%of map height);
    #                  area width (max); area height (max); randomization of size (0 none - 100 full); dungeon 0/1
    
    #area_generator =       Maps/randomgrid_castle_2.png;      Maps/randomgrid_castle_2.png;      Maps/randomgrid_cave_2.png;        Maps/randomgrid_cave_2.png;
    #area_generator_vars = 8; 8; 5; 5; 50; 50; 71; 0;         8; 8; 68; 5; 50; 50; 71; 0;        22; 10; 1; 90; 50; 100; 35; 1;     22; 10; 55; 50; 90; 100; 35; 1;
    
    # 100 100
    area_generator =       Maps/randomgrid_castle_2.png;         Maps/randomgrid_castle_2.png;           Maps/randomgrid_cave_2.png;            Maps/randomgrid_cave_2.png;            Maps/randomgrid_cave_2.png;
    area_generator_vars = 8; 8;  10; 30;  50; 33;  87; 0;      8; 8;  50; 36;  40; 33;  87; 0;          22; 10;  2; 46;  108; 35 ; 15; 1;        22; 10;  2; 63;  108; 35 ; 15; 1;    22; 10;  20; 78;  60; 42 ; 10; 1;
    The png files are still on the base game, but the KAGGen file doesn't reference them, so it won't create dungeons based on them. Any idea of how I could integrate the code from the classic generator on the .as file? I have little to none knowledge of programming so it's kinda hard for me :c
     

    Attached Files:

  5. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Unfortunately you'd have to code the generation code to stick those images together. The classic map generator is no longer available at all (the source was not in angelscript, it was in C++, and was very messy and not worth porting in our opinion).

    As that old config hints, you can look up "wang tiles" (no joke, that's just what they're called) if you want to find out how the previous castle generator worked but honestly imo there's better ways to generate caves and castles than wang tiles.

    The zombies modification to the generator is pretty rudimentary but probably forms a good starting point. Simply making the generated areas not overlap might get you the improvements you need - you'll want to basically generate a few areas to spawn portals randomly, and either check for an overlap and discard overlapping areas, or "collide" those areas (google for axis-aliegned box collision resolution) to separate them.

    You'll get better at coding the more you do it - it can be daunting but there are quite a few folks in IRC who'll be keen to help you out if you get stuck. The main thing is to keep trying.