Jump to content

Автомаппер

From DDraceNetwork
Revision as of 15:08, 15 June 2025 by Кiлiбiк off (talk | contribs) (Created page with "Модификации тайла всегда находятся в той же строке, что и выбор.")

"Автомаппер" - это инструмент, облегчающий создание карт. Вместо того чтобы вручную расставлять круглые края фриза, вы можете сделать простое правило автомаппера, которое применяет правила ко всему слою тайлов. Каждое правило создается для определенного набора тайлов, и каждый набор тайлов может иметь несколько правил. Все правила находятся в teeworlds по адресу data/editor/automap/[1][2].


Файл правил

Для каждого набора тайлов, у которого есть автомаппер, существует текстовый файл tileset.rules. Каждый файл tileset.rules может содержать несколько автомапперов. Файл правил в общих чертах следует формату INI-файла. Внутри файла каждый автомаппер начинается с строки [automapper_name]. Например, в файле grass_main.rules есть автомаппер под названием Grass, который начинается со строки [Grass] в этом файле. Чтобы использовать его, нужно создать слой тайлов с набором тайлов grass_main в редакторе карт. Кликните правой кнопкой по слою и выберите "Auto map". Чтобы начать автомаппинг, нажмите "Grass".

Имя файла автомаппера должно соответствовать имени файла набора тайлов.

Автомаппер Grass[3]:

[Grass]
Index 1

#top
Index 16
Pos 0 -1 EMPTY
...

Обработка

Автомаппер будет считывать файл правил и сканировать каждую позицию слоя. Если для выбранного тайла выполняются все правила, тайл будет размещён в просканированной позиции автомаппера. Если совпадают несколько тайлов и их правила, применяется только последнее правило (так как оно перезапишет остальные). Если не отключено, автомаппер сначала поместит свои изменения в буфер, а затем применит их.

Обзор индексов набора тайлов

Индексы тайлов

Каждый набор тайлов содержит 16 строк и 16 столбцов, и каждый тайл можно адресовать по его индексу. Индекс тайла напрямую зависит от его позиции и может быть вычислен по формуле index = 16 * row + column, где значения row и column находятся в пределах от 0 до 15. Тайл с индексом 0 всегда считается EMPTY. Обычно эта часть не содержит текстур в наборах тайлов. Каждый другой тайл всегда считается FULL, даже если он не содержит текстур и полностью прозрачен.

Индекс используется для ключевого слова INDEX в автомаппере.

Синтаксис

Название вашего правила автомаппера:

Аналогично ini-файлам, вы можете создать свой собственный раздел для правила автомаппера:

[your-automapper-rule]

Несколько выборок индексов с последующими правилами могут входить в раздел.

Написание комментария:

#this is a comment

Выбор тайла, который вы хотите разместить:

INDEX 42

Это выбирает тайл 42 (то есть 3-я строка и 11-й столбец). Несколько индексов можно выбрать, добавляя между ними OR:

INDEX 42 OR 43

Изменение тайла:

Index 42 XFLIP YFLIP ROTATE

XFLIP зеркально отражает тайл по вертикали, а YFLIP — по горизонтали. ROTATE поворачивает тайл на 90° один раз.

Если вы хотите повернуть тайл на 180°, достаточно установить XFLIP и YFLIP, но не ROTATE.

Если вы хотите повернуть на 270°, нужно установить XFLIP, YFLIP и ROTATE.

Модификации тайла всегда находятся в той же строке, что и выбор.

If you want to select a tile without any rotations or flips, you can use NONE. Otherwise all tiles with the given INDEX will be selected.

Rule for placing the tile:

The selected tile gets placed if all following rules apply. A rule for placing the tile always starts with coordinates followed by a rule:

POS 0 -1 FULL

This rule selects the tile with X coordinate 0 and Y coordinate -1 relative to the scanning position of the automapper. If the tile above the scanning position is FULL, the selected tile will be placed (if all following rules apply). If it's EMPTY, it won't be placed.

Instead of using FULL or EMPTY, you can select another tile with the INDEX keyword:

POS 0 -1 INDEX 12

If the tile above the scanning position has index 12, it will be placed. Multiple indices can be selected by adding an OR between each index:

POS 0 -1 INDEX 12 OR 13

Similarly NOTINDEX can be used to exclude a tile.

Random rule:

You can make a selected tile randomly apply to rules by adding a random rule:

RANDOM 20%

The random rule expects a value between 0% and 100%. This value represents the probability, that a tile is placed[4].

If you put a value into it without a % symbol, the probability will not be parsed in terms of percentages, but with this formula:

percentage = 1.0 / value

This allows for rarer tile placements with probabilities between 0% and 1% and a value > 100.

For example RANDOM 150 will have a probability of 1.0 / 150 ≈ 0.67 (percent).

Modulo:

With the MODULO x_pattern y_pattern x_offset y_offset operator you can create a repeating pattern depending on the X and Y coordinate of a tile. For example MODULO 2 3 0 -1 uses modular arithmetic in order to set every second tile on the X-Axis (x_pattern) and every third tile on the Y-Axis (y_pattern). The third and fourth parameter can be used to offset the X (here 0) and Y (here -1) coordinate and move the pattern around. A tile will only be placed, if both the following rules are true:

(x + x_offset) % x_pattern == 0

(y + y_offset) % y_pattern == 0

Here % is the modulo operator.

Default condition rule:

By default the game assumes, that you want to apply each rule to a full tile, meaning that the following rule is always implied:

POS 0 0 FULL

You can deactivate this by adding the following line under the tile selection:

NoDefaultRule

NewRun:

Adding NewRun in a section will make the section run an additional time for each time this keyword gets added to the section. This can be used to set some basic tiles in the first run, and more complex ones in the second.

NoLayerCopy:

Adding NoLayerCopy in a section will cause it to run in-place. This can drastically improve performance, because the automapper doesn't copy it's changes into buffer memory before applying it. But it can cause unintended side effects!

Tools

Some tools in order to create automapper rules exist:

  • SimpleDDNetAutomapper - a small UI application, which tries a more user friendly approach for very basic rules and tilesets. It does not support randomness, or POS INDEX rules, but EMPTY and FULL.
  • Teeworlds Web Editor - Automapper edit and live-preview[5].
  • rpp - rules++ is a small experiment, aiming to make mappers utterly lazy, by unlocking the full potential of DDNet's rules. It is meant to be simple, readable and most importantly correct, everything else is irrelevant[6].

Resources