Modular level generator¶
Now that we are aware how level generation works in general, we can have
a look at more modular approach.
pyherc.generators.level.new_level_generator()
is a high order function
used to construct new modular level generator functions.
(defn new-level-generator [model partitioners room-generators decorators
portal-adders item-adders creature-adders
trap-generator rng name description]
...)
Calling this function will return a function that can be used to generate level as configured. It has simple interface:
(fn [portal]
...)
Overview of level generator¶
Instead of performing all the steps by itself, level generator delegates most of its tasks to sub components.
First new level is created and sent to a partitioner. This component will divide level into sections and link them to each other randomly. Partitioners are required to ensure that all sections are reachable.
A room is generated within each section and corridors are used to link rooms to neighbouring sections. Linking is done according to links set up in the previous phase. This in turn ensures that each room is reachable.
Adding of creatures is done by creature adders. These contains information of the type of creatures to add and their placement.
Items are added in the same way as the portals, but item adders are used.
Portals are added by portal adders. These portals will lead deeper in the dungeon and cause new levels generated when player walks down to them. One special portal is also created, that links generated level to the higher level.
In decoration step details are added into the level. Walls are built where empty space meets solid ground and floors are detailed.
Partitioners¶
pyherc.generators.level.partitioners.grid.grid_partitioning()
creates
a basic partitioner, which knows how to divide level into a grid with equal
sized sections.
All partitioners have same interface:
(fn [level]
...)
Calling the function will partition level to sections, link sections to each other and return them in a list.
pyherc.generators.level.partitioners.section.Section
is used to represent
section. It defines a rectangular area in level, links to neighbouring areas and
information how they should connect to each other. It also defines connections
for rooms.
Room generators¶
Room generators are used to create rooms inside of sections created by partitioner. Each section has information how they link together and these connection points must be linked together by room generator.
Room generator is instantiated with
pyherc.generators.level.room.new_room_generator()
function. It will create a
generator function with following signature:
(fn [section trap-generator]
...)
Calling this function should create a room inside section and connect all connection points together.
Decorators¶
Decorators can be used to add theme to level. Simple ones can be used to change appearance of the floor to something different than what was generated by room generator. More complex usage is to detect where walls are located and change their appearance.
Decorators have simple interface:
(fn [level]
...)
Portal adders¶
(fn [level]
...)
Creature adder¶
(fn [level]
...)
Item adder¶
(fn [level]
...)
Defining levels¶
Levels are defined in configuration scripts that are fed to
pyherc.config.config.Configuration
during system startup.