|
|
Line 33: |
Line 33: |
| |OnCompletedCheck|{{modarg|function}}| | | |OnCompletedCheck|{{modarg|function}}| |
| |OnNuked |{{modarg|function}}| | | |OnNuked |{{modarg|function}}| |
− | |}}
| |
− | }}
| |
− | === Flags ===
| |
− | {{drltable|Level Flags|2|{{Table2Col
| |
− | |es=background: #333;
| |
− | |c1=font-family:monospace; text-align:right; vertical-align:top; padding:0px 2px;
| |
− | |c2=padding:0px 2px;
| |
− | |LF_NOHOMING|Causes homing phase devices to act like normal phase devices.
| |
− | |LF_UNIQUEITEM|Used by the level generation code to keep track of whether a unique item has dropped on the current level (in order to prevent multiple uniques from dropping on one level). This flag also causes a level feeling to occur indicating that a unique item is present.
| |
− | |LF_BONUS|This flag is automatically set for so-called special levels like [[Halls of Carnage]]. (It is not set for those special levels like [[Hellgate]] that replace normal levels, only by those reached from red stairs.)
| |
− | |LF_RESPAWN|Causes monsters to randomly respawn as when playing the game on Nightmare!
| |
− | |LF_NORESPAWN|Prevents the Nightmare! respawn feature.
| |
− | |LF_NUKED|This flag is automatically set when the level is nuked.
| |
− | |LF_NONUKE|Causes the thermonuclear bomb to have no effect when it is used. It is not respected by other nuke effects.
| |
− | |LF_ITEMSVISIBLE|Allows the player to see all items on the level (as with a [[Computer Map]]).
| |
− | |LF_BEINGSVISIBLE|Allows the player to see all beings on the level (as with a [[Tracking Map]]).
| |
| |}} | | |}} |
| }} | | }} |
| | | |
| == Engine Hooks == | | == Engine Hooks == |
− |
| |
| {{drltable|Level Hooks|2|{{Table2Col | | {{drltable|Level Hooks|2|{{Table2Col |
| |es=background: #333; | | |es=background: #333; |
Line 80: |
Line 63: |
| |}} | | |}} |
| }} | | }} |
− |
| |
| | | |
| {{Anchor|level_create}} | | {{Anchor|level_create}} |
Line 158: |
Line 140: |
| ;OnNuked() | | ;OnNuked() |
| :Triggered when a nuke is detonated. | | :Triggered when a nuke is detonated. |
− |
| |
− | == Properties ==
| |
− | These are properties of the global Level variable. They are changed by the engine as the player moves from level to level. For some of the read-only properties, rawset can be used to create a lua property that shadows the pascal property, tricking APIs that are implemented in lua. This is particularly useful for tricking the generator API into using a custom style.
| |
− | {|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
| |
− | ! colspan="3" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Level'''
| |
− | {{Table3Col
| |
− | |es=background: #333;
| |
− | |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px;
| |
− | |c2=vertical-align:top; padding:0px 2px;
| |
− | |c3=padding:0px 2px;
| |
− | |Word|status|This is for use by level designers. It is preferred to access it through Level.result.
| |
− | |string|name|This is the level name as displayed on the HUD.
| |
− | |Byte|name_number|This controls the "LevX" part of the level name. If zero, it won't be displayed.
| |
− | |Byte|danger_level|Level generation parameter that corresponds to depth.
| |
− | |Byte|style|The style (tile set) used by the level generation functions. This property is read-only.
| |
− | |string|special_exit|The sid of the level that red stairs lead to on the current level number. This property is read-only.
| |
− | |string|special_name|The sid of the current level prototype or the empty string for random levels. This property is read-only.
| |
− | |DWord|item_array_size|Length of the sparse array that stores all the items on the level. This property is read-only.
| |
− | |DWord|being_array_size|Length of the sparse array that stores all the beings on the level. This property is read-only.
| |
− | }}
| |
− | |}
| |
− |
| |
− | == API ==
| |
− | {{drltable|Level Interface|2|{{Table2Col
| |
− | |es=background: #333;
| |
− | |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px;
| |
− | |c2=padding:0px 2px;
| |
− | |{{modarg|value}}|{{moddef|list|property_get|dot||string|property}}
| |
− | |{{modarg|void}}|{{moddef|list|property_set|dot|string|property|value|value}}
| |
− | |{{modarg|boolean}}|{{moddef|list|flag_get|dot||Level Flag|flag}}
| |
− | |{{modarg|void}}|{{moddef|list|flag_set|dot||Level Flag|flag|boolean|value}}
| |
− | |{{modarg|value}}|{{moddef|list|roll_weight|dot||list|list|integer|sum}}
| |
− | |{{modarg|integer}}|{{moddef|list|weight_list_sum|dot||list|list}}
| |
− | |{{modarg|void}}|{{moddef|list|place_tile|dot||table|translation|string|tile|integer|x|integer|y}}
| |
− | |{{modarg|void}}|{{moddef|list|player|dot||integer|x|integer|y}}
| |
− | |{{modarg|integer}}|{{moddef|list|result|dot||integer|value}}
| |
− | |{{modarg|boolean}}|{{moddef|list|eye_contact|dot||Coord|c1|Coord|c2}}
| |
− | |{{modarg|boolean}}|{{moddef|list|is_visible|dot||Coord|position}}
| |
− | |{{modarg|void}}|{{moddef|list|nuke|dot}}
| |
− | |{{modarg|void}}|{{moddef|list|explosion|dot||Coord|position|integer|radius|integer|delay|integer|damage_dice|integer|damage_sides|Color|color|Sound ID|sound|DamageType|damagetype|ExplosionFlag List|flags|Cell ID|content}}
| |
− | ||'''Cell-specific functions'''
| |
− | |{{modarg|boolean}}|{{moddef|list|light_flag_get|dot||Coord|position|LightFlag|flag}}
| |
− | |{{modarg|void}}|{{moddef|list|light_flag_set|dot||Coord|position|LightFlag|flag|boolean|value}}
| |
− | |{{modarg|integer}}|{{moddef|list|hp_get|dot||Coord|position}}
| |
− | |{{modarg|void}}|{{moddef|list|hp_set|dot||Coord|position|integer|value}}
| |
− | |{{modarg|boolean}}|{{moddef|list|is_corpse|dot||Coord|position}}
| |
− | |{{modarg|boolean}}|{{moddef|list|scan|dot||Area|scan_area|Cell ID|good}}
| |
− | |{{modarg|void}}|{{moddef|list|fill|dot||Cell ID|cell|Area|fill_area}}
| |
− | |{{modarg|void}}|{{moddef|list|flood|dot||Cell ID|tile|Area|flood_area}}
| |
− | |{{modarg|void}}|{{moddef|list|scatter|dot||Area|scatter_area|Cell ID|good|Cell ID|fill|integer|count}}
| |
− | |{{modarg|void}}|{{moddef|list|scatter_put|dot||Area|scatter_area|table|translation|string|tile|Cell ID|good|integer|count}}
| |
− | |{{modarg|boolean}}|{{moddef|list|push_cell|dot||Coord|c|Coord|target|boolean|quiet}}
| |
− | ||'''Being-specific functions'''
| |
− | |{{modarg|Being}}|{{moddef|list|get_being|dot||integer|index}}
| |
− | |{{modarg|Being}}|{{moddef|list|get_being_by_uid|dot||integer|uid}}
| |
− | |{{modarg|Being}}|{{moddef|list|drop_being|dot||Being ID|bid|Coord|position}}
| |
− | |{{modarg|void}}|{{moddef|list|drop_being_ext|dot||table|being|Coord|position}}
| |
− | |{{modarg|Being}}|{{moddef|list|summon|dot||Being ID|bid|integer|count}}
| |
− | |{{modarg|Being}}|{{moddef|list|area_summon|dot||Area|where|Being ID|bid|integer|count}}
| |
− | |{{modarg|void}}|{{moddef|list|clear_being|dot||Coord|position}}
| |
− | |{{modarg|list}}, {{modarg|integer}}|{{moddef|list|get_being_list|dot}}
| |
− | |[[Modding:Being|Being ID]]|{{moddef|list|random_being|dot}}
| |
− | |{{modarg|void}}|{{moddef|list|flood_monster|dot||Being ID|bid|integer|amount}}
| |
− | |{{modarg|void}}|{{moddef|list|flood_monsters|dot||integer|amount}}
| |
− | |{{modarg|Being iterator}}|{{moddef|list|beings|dot}}
| |
− | |{{modarg|Being iterator}}|{{moddef|list|beings_in_range|dot||Coord|position|integer|range}}
| |
− | ||'''Item-specific functions'''
| |
− | |{{modarg|Item}}|{{moddef|list|get_item|dot||integer|index}}
| |
− | |{{modarg|Item}}|{{moddef|list|get_item_by_uid|dot||integer|uid}}
| |
− | |{{modarg|Item}}|{{moddef|list|drop_item|dot||Item ID|iid|Coord|position}}
| |
− | |{{modarg|void}}|{{moddef|list|drop_item_ext|dot||table|item|Coord|position}}
| |
− | |{{modarg|Item}}|{{moddef|list|drop|dot||Item ID|iid|integer|count}}
| |
− | |{{modarg|Item}}|{{moddef|list|area_drop|dot||Area|where|Item ID|iid|integer|count}}
| |
− | |{{modarg|void}}|{{moddef|list|try_destroy_item|dot||Coord|c}}
| |
− | |{{modarg|list}}, {{modarg|integer}}|{{moddef|list|get_item_list|dot||integer|max_level|integer|unique_mult}}
| |
− | |[[Modding:Item|Item ID]]|{{moddef|list|roll_item_type|dot||ItemType list|itypes|integer|max_level|integer|unique_mod}}
| |
− | |[[Modding:Item|Item ID]]|{{moddef|list|roll_item|dot||integer|max_level|integer|unique_mod}}
| |
− | |{{modarg|void}}|{{moddef|list|flood_items|dot||integer|amount|}}
| |
− | |{{modarg|Item iterator}}|{{moddef|list|items|dot}}
| |
− | |{{modarg|Item iterator}}|{{moddef|list|items_in_range|dot||Coord|position|integer|range}}
| |
− | }}
| |
− | }}
| |
− |
| |
− | {{moddef|desc|property_get|dot|value|string|property}}
| |
− | :Gets the value of the given level property. It is preferred to use the Lua dot indexing syntax instead.
| |
− | ----
| |
− | {{moddef|desc|property_set|dot|string|property|value|value}}
| |
− | :Sets the given level property to the given value. It is preferred to use the Lua dot indexing syntax instead.
| |
− | ----
| |
− | {{moddef|desc|flag_get|dot|boolean|Level Flag|flag}}
| |
− | ;Level.flags[[[Modding:Constants#Level Flags|Level Flag]] flag] → '''boolean'''
| |
− | :Determines the current state of the given level flag.
| |
− | ----
| |
− | {{moddef|desc|flag_set|dot||Level Flag|flag|boolean|value}}
| |
− | ;Level.flags[[[Modding:Constants#Level Flags|Level Flag]] flag] = '''boolean''' value
| |
− | :Sets the given level flag to the given value.
| |
− | ----
| |
− | {{moddef|desc|roll_weight|dot|value|list|list|integer|sum}}
| |
− | :Randomly chooses an item from the list according to the weight property of the list items. Sum must be the sum of the weights of all the list items.
| |
− | ----
| |
− | {{moddef|desc|weight_list_sum|dot|integer|list|list}}
| |
− | :Returns the sum of the weight properties of all the items in the list.
| |
− | ----
| |
− | {{moddef|desc|place_tile|dot||table|translation|string|tile|integer|x|integer|y}}
| |
− | :Places the map tile given by ''translation'' and ''tile'' on the map at the position given by ''x'' and ''y''. ''translation'' should be a table that maps single character strings to either cell ids, or to tables. These tables have their first array element be a cell id, but they may also contain a being and''or'' item key that is mapped to a being or item id respectively. Level.drop_being_ext and Level.drop_item_ext syntax is allowed. ''tile'' should be a string of characters that are defined in ''translation''. Line breaks correspond to line breaks on the map.
| |
− | ----
| |
− | {{moddef|desc|player|dot||integer|x|integer|y}}
| |
− | :Sets the initial position of the player for a special or scripted level. This should be called in the Create hook; after that it has no meaningful effect.
| |
− | ----
| |
− | {{moddef|desc|result|dot|integer|integer|value}}
| |
− | :If ''value'' is given, updates the level's status and returns nil. If ''value'' is omitted, returns the current status.
| |
− | ----
| |
− | {{moddef|desc|eye_contact|dot|boolean|Coord|c1|Coord|c2}}
| |
− | :Determines whether or not there is a line-of-sight path between '''c1''' and '''c2'''. This calculation ignores light flags (such that two beings can have eye contact even if they aren't visible to each other).
| |
− | ----
| |
− | {{moddef|desc|is_visible|dot|boolean|Coord|position}}
| |
− | :Determines if the given position is visible to the player.
| |
− | ----
| |
− | {{moddef|desc|nuke|dot}}
| |
− | :Triggers an immediate nuclear explosion as from a [[thermonuclear bomb]].
| |
− | ----
| |
− | {{moddef|desc|explosion|dot||Coord|position|integer|radius|integer|delay|integer|damage_dice|integer|damage_sides|Color|color|Sound ID|sound|DamageType|damagetype|ExplosionFlag List|flags|Cell ID|content}}
| |
− | :Creates an [[explosions|explosion]] centered at the given position with the given parameters. ''radius'' is the size of the explosion. ''delay'' is the delay in milliseconds between animation frames (typically this is around 40). ''damage_dice'' and ''damage_sides'' determine the damage roll for the explosion. For a no-damage explosion, both should be 0. The default damage type is fire. ''content'' determines the cell that is randomly created wherever the explosion does enough damage. By default, there are no flags and there is no content. Only some colors are supported, and these are automatically translated into 3 color combinations used by the explosion animation. The supported colors are LIGHTBLUE, BLUE, MAGENTA, GREEN, LIGHTRED, YELLOW, and the default RED.
| |
− | ----
| |
− | {{moddef|desc|light_flag_get|dot|boolean|Coord|position|LightFlag|flag}}
| |
− | ;Level.light[[[Modding:Coord|Coord]] position][[[Modding:Constants#LightFlag|LightFlag]] flag] → '''boolean'''
| |
− | :Gets the value of the given light flag at the given position.
| |
− | ----
| |
− | {{moddef|desc|light_flag_set|dot||Coord|position|LightFlag|flag|boolean|value}}
| |
− | ;Level.light[[[Modding:Coord|Coord]] position][[[Modding:Constants#LightFlag|LightFlag]] flag] = '''boolean''' value
| |
− | ;Level.light[[[Modding:Constants#LightFlag|LightFlag]] flag] = '''boolean''' value
| |
− | :Sets the value of the given light flag at the given position. For the syntax without a position, the light flag will be set at every position on the map.
| |
− | ----
| |
− | {{moddef|desc|hp_get|dot|integer|Coord|position}}
| |
− | ;Level.hp[[[Modding:Coord|Coord]] position] → '''integer'''
| |
− | :Gets the current hp of the cell at the given position.
| |
− | ----
| |
− | {{moddef|desc|hp_set|dot||Coord|position|integer|value}}
| |
− | ;Level.hp[[[Modding:Coord|Coord]] position] = '''integer''' value
| |
− | :Sets the current hp of the cell at the given position. Setting hp to 0 won't destroy a cell.
| |
− | ----
| |
− | {{moddef|desc|is_corpse|dot|boolean|Coord|position}}
| |
− | :Determines whether the given position has a corpse in it. This counts the cell with id "corpse" as a corpse even though it otherwise isn't a corpse as far as the engine is concerned.
| |
− | ----
| |
− | {{moddef|desc|scan|dot|boolean|Area|scan_area|Cell ID|good}}
| |
− | :Determines if every cell in ''scan_area'' is ''good''.
| |
− | ----
| |
− | {{moddef|desc|fill|dot||Cell ID|cell|Area|fill_area}}
| |
− | :Sets every cell in the given area to the area. ''fill_area'' is optional; it defaults to the full map.
| |
− | ----
| |
− | {{moddef|desc|flood|dot||Cell ID|tile|Area|flood_area}}
| |
− | :Changes CELLSET_FLOORS and CF_LIQUID tiles in the area to ''tile''. If ''tile'' has CF_HAZARD, then it will destroy items.
| |
− | ----
| |
− | {{moddef|desc|scatter|dot||Area|scatter_area|Cell ID|good|Cell ID|fill|integer|count}}
| |
− | :Chooses ''count'' random tiles in ''scatter_area'' (possibly with duplicates) and sets any chosen cells that are ''good'' to ''fill''.
| |
− | ----
| |
− | {{moddef|desc|scatter_put|dot||Area|scatter_area|table|translation|string|tile|Cell ID|good|integer|count}}
| |
− | :Chooses ''count'' random subareas with upper-left corner in ''scatter_area'' of the size appropriate of ''tile'' (using the first line length and number of lines to define a rectangular area). There may be duplicates or overlaps. For each subarea, if the area is already filled with ''good'', then it is replaced with ''tile'' (according to ''translation''). See Level.place_tile for the semantics of ''translation'' and ''tile''.
| |
− | ----
| |
− | {{moddef|desc|push_cell|dot|boolean|Coord|c|Coord|target|boolean|quiet}}
| |
− | :Swaps the content of the cells located in '''c''' and '''target''': this will only occur successfully if '''target''' is a part of CELLSET_FLOORS. If '''target''' has the CF_HAZARD flag, the cell on '''c''' activates its OnDestroy hook. '''quiet''', when set to true, includes messages (mostly specific to barrels, the only object pushed in the base game).
| |
− | ----
| |
− | {{moddef|desc|get_being|dot|Being|integer|index}}
| |
− | :Returns the being at the given index in the sparse being array. A being's index won't change as long as it is in the array.
| |
− | ----
| |
− | {{moddef|desc|get_being_by_uid|dot|Being|integer|uid}}
| |
− | :Returns the being with the given uid, or nil if that being doesn't exist or has been removed from the map.
| |
− | ----
| |
− | {{moddef|desc|drop_being|dot|Being|Being ID|bid|Coord|position}}
| |
− | :Drops a newly created being in the given position. ''bid'' can also be an actual being object, although this should not be used for beings that are already on the map. If the position is occupied, the being will be dropped nearby. The dropped being is returned. If the function fails, nil is returned.
| |
− | ----
| |
− | {{moddef|desc|drop_being_ext|dot||table|being|Coord|position}}
| |
− | :As Level.drop_being, except additional values are accetable for ''being'' as Level.drop_item_ext.
| |
− | ----
| |
− | {{moddef|desc|summon|dot|Being|Being ID|bid|integer|count}}
| |
− | :Creates new beings of the type given by ''bid'' and amount given by ''count'' and scatters them around the map. The last dropped being (if any) is returned. ''count'' is optional and defaults to 1.
| |
− | ----
| |
− | {{moddef|desc|area_summon|dot|Being|Area|where|Being ID|bid|integer|count}}
| |
− | :As Level.summon, but all the summoned beings are randomly placed in ''where'' rather than scattered across the whole map.
| |
− | ----
| |
− | {{moddef|desc|clear_being|dot||Coord|position}}
| |
− | {{moddef|desc|clear_being|dot||integer|index}}
| |
− | :Removes an item from the map at the given position, or from the given index in the item array.
| |
− | ----
| |
− | {{moddef|desc|get_being_list|dot|list,integer}}
| |
− | :Returns the list and sum (ready to be used with [[#level_roll_weight|Level.roll_weight]]) for beings and beings groups according to Level.danger_level and DIFFICULTY. The result is cached.
| |
− | ----
| |
− | {{moddef|desc|random_being|dot|Being ID}}
| |
− | :Returns a random being chosen according to weights from the current level's list. This will never choose a group. The returned id is always a string id.
| |
− | ----
| |
− | {{moddef|desc|flood_monster|dot||Being ID|bid|integer|amount}}
| |
− | :Add the given monster type to the level in an amount specified by the total danger value ''amount'' (so it scales appropriately with Level.flood_monsters).
| |
− | ----
| |
− | {{moddef|desc|flood_monsters|dot||integer|amount}}
| |
− | :Adds monsters to the level using the normal algorithm for random levels. The ''amount'' is a total danger value such as a value returned by Generator.being_weight.
| |
− | ----
| |
− | {{moddef|desc|beings|dot|Being iterator}}
| |
− | :Gives an iterator over all beings in the level.
| |
− | ----
| |
− | {{moddef|desc|beings_in_range|dot|Being iterator|Coord|position|integer|range}}
| |
− | :Gives an iterator over all beings within '''range''' units of [[distance]] from '''position''' in the level.
| |
− | ----
| |
− | {{moddef|desc|get_item|dot|Item|integer|index}}
| |
− | :Returns the item at the given index in the sparse item array. An item's index won't change as long as it is in the array.
| |
− | ----
| |
− | {{moddef|desc|get_item_by_uid|dot|Item|integer|uid}}
| |
− | :Returns the item with the given uid, or nil if that item doesn't exist or has been removed from the map.
| |
− | ----
| |
− | {{moddef|desc|drop_item|dot|Item|Item ID|iid|Coord|position}}
| |
− | :Drops a newly created item in the given position. ''iid'' can also be an actual item object, although this should not be used for items that are already on the map. If the position is occupied, the item will be dropped nearby. The dropped item is returned. If the function fails, nil is returned.
| |
− | ----
| |
− | {{moddef|desc|drop_item_ext|dot||table|item|Coord|position}}
| |
− | :As Level.drop_item, except additional values are acceptable for ''item''. If ''item'' is a table, the first list element is passed used to determine which item to drop. For other key-value pairs in the table, the property of the dropped item that corresponds to the key will be set to the value.
| |
− | ----
| |
− | {{moddef|desc|drop|dot|Item|Item ID|iid|integer|count}}
| |
− | :Creates new items of the type given by ''iid'' and amount given by ''count'' and scatters them around the map. The last dropped item (if any) is returned. ''count'' is optional and defaults to 1.
| |
− | ----
| |
− | {{moddef|desc|area_drop|dot|Item|Area|where|Item ID|iid|integer|count}}
| |
− | :As Level.drop, but all dropped items are randomly placed in ''where'' rather than scattered across the whole map.
| |
− | ----
| |
− | {{moddef|desc|try_destroy_item|dot||Coord|c}}
| |
− | :Destroys an item at '''position''', if there is one to be found.
| |
− | ----
| |
− | {{moddef|desc|get_item_list|dot|list,integer|integer|max_level|integer|unique_mult}}
| |
− | :Returns the list and sum (ready to be used with [[#level_roll_weight|Level.roll_weight]]) for items according to ''max_level'', and ''unique_mult''. ''max_level'' defaults to Level.danger_level, and is used to determine which items fall in the proper level range. Unique items' weights are multiplied by ''unique_mult'' (which defaults to 1). The result is cached.
| |
− | ----
| |
− | {{moddef|desc|roll_item_type|dot|Item ID|ItemType list|itypes|integer|max_level|integer|unique_mod}}
| |
− | :Returns a random item chosen from among the given item types according to weights from the list specified by ''max_level'' and ''unique_mod''. The returned id is always a string id.
| |
− | ----
| |
− | {{moddef|desc|roll_item|dot|Item ID|integer|max_level|integer|unique_mod}}
| |
− | :As Level.roll_item_type, but the item type of the result isn't restricted.
| |
− | ----
| |
− | {{moddef|desc|flood_items|dot||integer|amount|}}
| |
− | :Adds items to the level according to the normal algorithm for random levels (not counting special features). The number of items is given by ''amount''.
| |
− | ----
| |
− | {{moddef|desc|items|dot|Item iterator}}
| |
− | :Gives an iterator over all items in the level.
| |
− | ----
| |
− | {{moddef|desc|items_in_range|dot|Item iterator|Coord|position|integer|range}}
| |
− | :Gives an iterator over all items within '''range''' units of [[distance]] from '''position''' in the level.
| |