Commit Graph

60 Commits

Author SHA1 Message Date
Pasi Kallinen
16ed7e49c3 Separate level flags for premapped and sokoban 2023-10-29 12:35:32 +02:00
Pasi Kallinen
e407af4477 Allow defining random-teleport exclusion zones in lua
Adds a new lua command

  des.exclusion({ type = "teleport", region = { x1,y1, x2,y2 } });

which allows defining "exclusion zones" in the level, areas where
random teleports (or falling into the level) will never place the hero.
Does not prevent targeted teleportation into the area.

Breaks saves and bones.
2023-08-24 18:38:39 +03:00
copperwater
2ae5ce8ab3 Fix and guard against out-of-bounds writes in splev code
I traced a memory corruption bug in xNetHack to a themed room that
looked something like this:

    function()
       des.room({ type="themed", contents = function()
          des.feature({ type='sink' })
          ...
       end })
    end

Placing a feature at a random spot within a room or region is a
reasonable thing for the parser to handle, but the code was not equipped
to handle it, and so the unspecified x and y set as -1 got passed
directly to SP_COORD_PACK, ending up as coordinates way off the map.
Since sel_set_feature does not do an isok() check, this ended up writing
data to unrelated memory.

This commit does the following things:

- Enables des.feature() with no coordinates specified, both via a table
  with 'type' set, and as the single string argument. When no
  coordinates are specified, it will pick a random normal-floor spot
  within the enclosing room or region if there is one, or anywhere
  on the level if there isn't.
- Prevents sel_set_feature from corrupting memory outside
  g.level.locations. Additionally, if EXTRA_SANITY_CHECKS is defined and
  this gets attempted, it causes an impossible.
- Guards the existing "door coord not ok" Lua error with an immediate
  return from lspo_door.
- Adds similar "coord not ok" errors to all the other locations in
  sp_lev.c which did not already check for a unspecified/invalid
  coordinate and for which a random coordinate is nonsensical:
  des.terrain(), des.drawbridge(), and des.mazewalk().
2023-07-04 16:19:27 -07:00
Pasi Kallinen
12dd5323c8 Tutorial: eating food
Also document the lua timers a bit more.
2023-04-04 13:04:39 +03:00
Pasi Kallinen
ba60bfac25 Themeroom: buried zombies
- add a themeroom with random buried zombifying corpses
- disturbing buried zombies makes them revive much faster
- lua des.object() now returns the object it created
2023-04-01 14:05:18 +03:00
Pasi Kallinen
2a7be0b050 Tutorial: hunger and eating food
Reset hunger when exiting the tutorial.
Add an optional second parameter to lua pline, forcing a more-prompt.
2023-03-18 14:08:13 +02:00
Pasi Kallinen
aa83dadc1e Add stormy level flag
Which makes clouds create lightning bolts at random.
This flag is used on the plane of air.

Breaks saves and bones.
2023-03-17 20:13:32 +02:00
Pasi Kallinen
4799fc937a Add level flag for plane of fire fumaroles
Also reduce the size of the gas clouds.

Breaks saves and bones.
2023-03-17 19:36:00 +02:00
Pasi Kallinen
8e6cf385b1 Fix subroom doors
Doors weren't getting added to the correct subrooms in certain cases.

Also fix one of the themerooms, because doors have to be added
after subrooms; there was a possibility of no door to the subroom(s)
in that themeroom, because the subrooms overwrote the doors in
the parent room.

Test case for the subroom doors:

Large room, with a medium subroom, with a tiny subroom inside that.
The doors go from outermost room <-> tiny innermost room <-> middle room.

des.room({ type = "ordinary", x = 1, y = 1, w = 10, h = 10,
   contents = function()
      des.room({ type = "ordinary", w = 6, h = 6, x = 2, y = 2,
         contents = function()
            des.room({ type = "ordinary", w = 2, h = 2, x = 0, y = 0,
               contents = function()
                  des.door({ state="random", wall="south", pos = 1 });
               end
            });
            des.door({ state="random", wall="north", pos = 1 });
         end
      });
   end
});

Before this fix:

ROOM: ndoors:1, subrooms:1
  SUBROOM: ndoors:1, subrooms:1
    SUBROOM: ndoors:1, subrooms:0

after this fix:

ROOM: ndoors:1, subrooms:1
  SUBROOM: ndoors:1, subrooms:1
    SUBROOM: ndoors:2, subrooms:0
2023-03-07 09:43:44 +02:00
copperwater
69d37be878 Fix: using a selection in a lit des.region modified it
The intuitive behavior when passing a selection to des.region, e.g.

    local foo = selection.area(07,02,10,24)
    des.region(foo, "lit")

is that foo will remain unmodified for further use. However, this wasn't
the case whenever making a lit region from it, because in order to light
walls adjacent to the lit area, the selection was having a grow
transformation applied as well. (This also seems like a problem - it
grows the selection even if what is being lit is not surrounded by
walls. I added a note in lua.adoc about this behavior.)

This fixes the selection mutation by cloning the passed-in selection and
growing the clone which leaves the original one unaffected.

This should not affect any special levels currently because the only
instance of des.region being used with a selection appears to be in
bigrm-2, which specifies *unlit* areas, which did not get grown.
2023-03-01 17:32:15 +02:00
Pasi Kallinen
fc7a32b86e Tutorial level
Add a tutorial level to teach commands to new players.
Very much a WIP.

Breaks save and bones compat.
2023-03-01 14:00:29 +02:00
Pasi Kallinen
00c756ba75 Lua: Traps without victims
Traps may get corpses generated on them on early dungeon levels,
to warn off fragile starting heroes. Allow creating traps in lua
without the corpse.
2023-02-25 18:05:09 +02:00
Pasi Kallinen
5d659cf1f6 Tips and option to disable them
Adds a more general way to handle gameplay tips, and adds
a boolean option "tips", which can be used to disable all
tips.  Adds a helpful longer message when the game goes
into the "farlook" mode.

Also adds a lua binding to easily show multi-line text
in a menu window.

Breaks save compat.
2023-02-19 15:56:18 +02:00
copperwater
9d0df0c9f0 Invert the behavior of selection.gradient
selection.gradient has some pretty unintuitive behavior, in that it
selects points that are NOT close to the defined center. I've used
gradient selections several times and so far all of them have had to be
negated, because I wanted to select points close to the center with a
decreasing probability further out.

This implements that behavior, and also fixes a bug in which the x,y
coordinates of the gradient center(s) were not converted properly when
used within a des.room or des.map. Also updated the lua documentation
for gradient.

I removed the "limited" argument, as it was previously used to control
whether the rest of the map outside the max given distance would be
included in the selection; now that the area beyond maxdist is naturally
never in the selection, it doesn't have much use. (And I can't think of
a reasonable use case for the inverse: wanting to select points close to
the center, with decreasing chance towards maxdist, but then select the
entire map beyond maxdist.)

Currently this does not affect any special levels or themed rooms
because none of them use selection.gradient.
2023-02-14 09:13:59 +02:00
Pasi Kallinen
7401b44fa1 Walls of lava
Add "walls of lava", basically lava which blocks vision and
require a bit more than just levitation or flight to move through.

No levels use this yet, as testing isn't thorough enough.
2023-02-06 19:23:42 +02:00
copperwater
50b18b1324 Fix: default lregion exclusion area occupied real space on the map
The intuitive behavior of des.levregion or des.teleport_region when
"exclude" is left unspecified is that there is no exclusion area.
However, this wasn't actually the case: since l_get_lregion defaulted
the exclusion area to (0,0,0,0) and exclude_islev to 0, this meant that
the 0,0 space on the map would always be excluded from regions. In cases
where a region was specified with its inclusion area constrained to the
0,0 space of the map, this would create a "Couldn't place lregion"
impossible message.

This fixes that issue by defaulting the exclusion area to (-1,-1,-1,-1),
and if the exclusion area is left unspecified, forces exclude_islev=1.
This means that the exclusion zone will be outside the walkable space of
the level where it can't cause any problems.

If a level designer puts negative coordinates in their inclusion or
exclusion parameters, this might not work correctly, but negative region
coordinates aren't currently used anywhere and probably shouldn't be
supported anyway.
2023-02-05 07:49:19 +02:00
Pasi Kallinen
744d64487b Helltweaks: improve lava river
The lava river will now draw another river, until a certain
amount of map locations have been turned into lava, so you don't
get a teensy "river" made out of 2 lava pools.

Add a lua selection method to count the number of locations
in the selection.
2023-01-30 17:10:39 +02:00
Pasi Kallinen
fd25cb177f Lua doc bits 2023-01-24 09:37:32 +02:00
Pasi Kallinen
bb8c144809 Level temperature
Allow setting a per-level "temperature": hot, cold, or temperate
via special level flags. Currently it only affects some messages
in Gehennom, but it could be expanded to ice melting, water freezing,
or monster generation, for example.

Invalidates saves and bones.
2023-01-17 20:11:45 +02:00
Pasi Kallinen
6abb12aee0 Lua: Persistent variables
Add a way for the lua scripts to set and retrieve variables
that are persistent - saved and restored with the game.

Invalidates saves.
2023-01-15 10:34:45 +02:00
Pasi Kallinen
9bf6d837ad More Gehennom filler level variance 2023-01-12 12:37:08 +02:00
Pasi Kallinen
4af086be73 More interesting Gehennom levels
Instead of just plain old boring mazes, spice up Gehennom by
occasionally adding lava, iron bars, or even mines-style levels
(with lava, of course).

Of the fixed Gehennom levels, only Asmodeus' lair has been changed
to add some random lava pools.

Also some lua fixes and changes:
- Fixed a selection negation bounding box being wrong.
- Fixed a selection negated and ORed returning wrong results.
- des.map now returns a selection of the map grids it touched.
- When using des.map contents-function the commands following the
  map are not relative to it.
2023-01-10 12:20:21 +02:00
Pasi Kallinen
bb3dc379bc Themerooms: Engraving hints the location of buried treasure
Add two new themeroom functions that are called when generating
the level: pre_themerooms_generate and post_themerooms_generate,
calles before and after themerooms_generate.

Allow the buried treasure -themeroom to put down an engraving
anywhere on the level, hinting at the location of the treasure.

des.object contents function now gets the generated object passed
to it as a parameter.
2022-09-18 12:45:16 +03:00
Pasi Kallinen
3605f18a8e Split themeroom shape from themeroom contents
Previously, the tetris-shaped rooms were always either
normal rooms, or turned into shops or other special rooms
in NetHack core. Now, the themed room lua code first picks
the themed room (which can be a themed or shaped), and some
of those will then pick a random filling (eg. ice floor,
traps, corpses, 3 altars).

Adds a new lua binding to create a selection picking locations
in current room.

The content-function in special level regions now get passed
the room data as a parameter.
2022-09-15 18:09:40 +03:00
copperwater
f71bff3285 Standardize all core and obj functions with relative coords
This is a large iteration on a previous implementation of making
nh.getmap() parse its coordinates as relative to the last defined map or
room rather than absolute to the entire level. Now, everything in the
nh.* and obj.* functions interprets coords as relative rather than
absolute. (By default; if no map or room has been defined, or if the lua
code is executing after level creation is done, they will interpret the
coordinates as absolute).

The general motivation is basically the same - routines that use
absolute coordinates are difficult to use in level creation routines,
because then the designer has to remember to convert the relative
coordinate to an absolute one (and that was impossible before
nh.abscoord was added, particularly in themed rooms). And once
nh.getmap() takes relative coordinates, it would be very strange to have
all the other functions (setting timers, burying objects, etc) remain
with absolute ones.

In a couple places, code is changed to account for coordinates that are
relative to a *room* (which uses g.coder->croom->[lx,ly] as an offset,
instead of relative to a *map*, which uses [xstart,ystart].
Specifically, selection.iterate did not account for this, and without
this the ice themed room timer was not being started in the proper
place.

All tests are updated to respect the new behavior. Most of the modified
functions are not actually used anywhere in level files; the one
exception is starting a timer in a themed room, and that has been
adjusted.

Documentation updated as well to clarify when various things are tossing
around relative and absolute coordinates, both in comments and in
lua.adoc.
2022-08-31 18:26:05 +03:00
Pasi Kallinen
723ee6d1f6 Expose selection bounds to lua 2022-08-26 13:07:52 +03:00
Pasi Kallinen
f45e79e1a0 Fix medusa levels
My recent commit broke medusa-3 and medusa-4, so fix those.

Make des.stair and des.ladder also accept hash-coordinate:
  des.stair("up", {8, 10});
2022-04-01 08:53:15 +03:00
Pasi Kallinen
6eadff01b8 Lua: selection get and rndcoord changes 2022-03-22 10:45:20 +02:00
Pasi Kallinen
27898340b9 Lua: coordinate tweaking
Make selection rndcoord return a table with x and y keys.
Allow (most) coordinate parameters accept such a table.
Fix selection and des lua tests broken by the above changes and
an earlier change, because selections tried to set terrain
at column 0, and it now causes a complaint.
2022-03-22 09:16:19 +02:00
Pasi Kallinen
811299edaf Lua: allow calling impossible 2022-03-16 16:58:42 +02:00
Pasi Kallinen
38924002e0 Lua: ice theme room and melting ice
Allow the ice theme room to occasionally have melting ice.
Add nh.abscoord() to convert room-relative to map-absolute coords.
2022-03-15 22:05:36 +02:00
Pasi Kallinen
bdc81ab389 Lua: allow obj chain iteration 2022-03-15 18:24:49 +02:00
Pasi Kallinen
e33dd11e99 Document the lua object class 2022-03-15 14:17:46 +02:00
Pasi Kallinen
957c0fbee0 Lua: location-specific timers
Expose map-location specific timers to lua scripts. For example:

  nh.start_timer_at(x,y, "melt-ice", 10);

Currently only available timer type is "melt-ice".
2022-03-15 13:46:56 +02:00
copperwater
b4a460f81b Implement selection addition and difference
Selection difference is something I have found myself wanting a lot when
working on levels, and have had to defer to a clunkier xor-then-and
approach. This commit implements the TODO-ed addition and subtraction
operators on two sets.

I don't see how the addition operator would be any different from
logical or, so it just calls l_selection_or rather than implement a new
function.
2022-03-14 18:42:28 +02:00
Pasi Kallinen
4be6fb0df9 Rolling boulder launch coordinates
Allow defining rolling boulder launching location in special level
lua scripts:

 des.trap({ type="rolling boulder", coord={7, 5}, launchfrom={-2, -2} });

launchfrom is relative to the trap coord.
2022-03-12 18:34:44 +02:00
Pasi Kallinen
c434236f1e Allow creating unhidden traps in special levels
des.trap({ type = "rust", seen = true });
2022-02-19 12:38:28 +02:00
Pasi Kallinen
a6816824c7 Lua: Pass more data to room contents function 2022-01-23 13:27:00 +02:00
Pasi Kallinen
07451ca32c Update lua api docs 2022-01-04 21:29:06 +02:00
Pasi Kallinen
f43bfc3f71 Lua: diagonals for selection floodfill 2021-08-15 13:50:28 +03:00
Pasi Kallinen
7f39d53ad3 Lua: improve level testing
Add des.finalize_level() used for testing in conjunction with
des.reset_level().
Add nhc.DLB to return 0 or 1 if DLB was defined at compile-time.
Change the test_lev.lua to give more informative messages instead of
just lua error when required file doesn't exist.
Add bigrm-11 to the level tests.
2021-07-24 10:49:06 +03:00
Pasi Kallinen
932b6d03c9 Lua: Make des.monster use boolean params 2021-07-22 11:05:40 +03:00
Pasi Kallinen
1e7b75eb8b Expose stairway data to lua 2021-06-24 18:55:20 +03:00
Pasi Kallinen
3ddb2a91c7 Allow some makemon flags in lua monster creation
Also document the des.monster hash parameter values.
2021-06-24 14:38:12 +03:00
Pasi Kallinen
29868036f1 Lua: nhcore script with function callbacks
Adds possible callbacks for "start_new_game", "restore_old_game",
"moveloop_turn", and "game_exit" which when defined, will be called
from core code at the appropriate time.

Adds lua hooks for dump_fmtstr (only if DUMPLOG), dnum_name, u.moves,
u.uhave_amulet, and u.depth.
2021-05-21 21:24:59 +03:00
copperwater
18dc88505d Convert room 'joined' and 'needjoining' into booleans
des.region() accepted booleans for the joined field, whereas des.room
accepted xchars. These were only being used as truth values, so this
converts the room ones into booleans for consistency. I don't think
accidentally using an int or a boolean wrongly would actually crash the
level generator, but consistency is good.

This converts an schar field in struct mkroom into a boolean; on most
systems these are probably 1-byte types and save files won't be broken,
but it might be best to treat this as a save breaker anyway.
2021-02-19 17:09:41 +02:00
Pasi Kallinen
da92e0349b Fix lua doc copypaste error 2021-02-10 22:06:36 +02:00
Pasi Kallinen
cc25f40d69 Add lua tests for config file parsing
Bare-bones for now, more tests needed.
2021-02-10 19:22:16 +02:00
Pasi Kallinen
d817564a6a Lua: set and get config options
Still needs more work, especially the error handling.
2021-02-06 19:02:25 +02:00
Pasi Kallinen
476990b303 Fixes and lua doc 2020-09-29 17:35:16 +03:00