Commit Graph

31 Commits

Author SHA1 Message Date
Pasi Kallinen
deb730d9b5 More hypothetical type mismatches 2020-11-15 13:51:47 +02:00
Pasi Kallinen
289c8d654d Futureproofing hypothetical type mismatches
If we ever want huge maps with COLNO or ROWNO larger than signed char,
this will at least allow the game to compile and start when typedef'ing
xchar to int. Trying to use huge maps exposes more bugs.
2020-11-14 13:53:09 +02:00
Pasi Kallinen
47fb7e5ee5 Fix double free 2020-04-12 16:55:00 +03:00
copperwater
0befdbfd02 Re-implement gradient selections
Uncomments and makes available selection.gradient in Lua. (The backend C
code for this still existed, it just wasn't used.)

The only valid way to specify a gradient is with a table. I considered
adding non-table versions, but decided that there are too many
independent variables that can be optional. A non-table version, without
named parameters, would be confusing to read, especially since most of
the arguments are ints.

Also adds an impossible in the (possibly unreachable) case that
selection_do_gradient gets called with a bad gradient type.
2020-04-06 18:54:39 +03:00
Pasi Kallinen
e215f09ddb Fix even more warnings 2020-04-06 13:34:07 +03:00
Pasi Kallinen
ac2b34654f Fix lua selection error
There was a rare selection bug where selection was freed by the gc
but it was still in use. Don't remove the selections from the stack
while we're handling them.
2020-03-31 19:11:49 +03:00
nhmall
7902bacf70 build fix for vs2019
src\nhlsel.c(604) : error C4703: potentially uninitialized local pointer variable 'mf' used
2020-03-03 18:34:27 -05:00
Pasi Kallinen
c9b21e36a7 Add lua selection match method
Also improve the replace_terrain command parameters.
2020-03-02 16:17:53 +02:00
Pasi Kallinen
7a54edf91f Implement lua selection iteration
... and showcase it by dehardcoding the Fort Ludios treasury.
2020-02-26 17:25:28 +02:00
PatR
19df82971d fix nhlsel.c warning
A recent change has resulted in complaints about 'sel' not being
used in
  struct selectionvar *sel = l_selection_check(L, 1);
  struct selectionvar *ret;
  int p = (int) luaL_checkinteger(L, 2);

  lua_pop(L, 1);
  (void) l_selection_clone(L);
  ret = l_selection_check(L, 1);
  selection_filter_percent(ret, p);

This preserves the semantics of that code while getting rid of the
warning, but I have no idea whether it makes any sense.
2020-02-25 16:04:41 -08:00
Pasi Kallinen
dc70132da8 Change lua selection floodfill and add some tests 2020-02-22 18:35:41 +02:00
Pasi Kallinen
fe3dae85d5 Make lua selection filter_mapchar create a new selection 2020-02-22 17:51:29 +02:00
Pasi Kallinen
50eaf95c27 Make lua selection grow create a new selection 2020-02-22 16:58:45 +02:00
Pasi Kallinen
6648ecfe04 Make lua selection randline create a new selection 2020-02-22 16:34:50 +02:00
Pasi Kallinen
b3f337bdf6 Make lua selection rect and fillrect create a new selection 2020-02-22 15:23:30 +02:00
Pasi Kallinen
44f7d44e94 Make lua selection line create a new selection
... instead of modifying the one given as a parameter.

Also add some tests for it.
2020-02-22 14:23:36 +02:00
Pasi Kallinen
00a32c6039 Make lua selection percent filter create a new selection
... instead of modifying the one given as a parameter.

Also add some tests for it.
2020-02-22 13:31:47 +02:00
Pasi Kallinen
42a05e9595 Make lua selection boolean opers create a new selection
... instead of modifying one of the given selections.

Also add tests for the operations.
2020-02-22 12:17:03 +02:00
Pasi Kallinen
e8ee044468 Make lua selection negate return a new selection
... instead of modifying the one given as a parameter.

Also add tests for it.
2020-02-22 12:17:03 +02:00
Pasi Kallinen
5885962efd Alloc sizeof struct instead of pointer-to-struct 2020-02-13 22:06:50 +02:00
PatR
75e9055b89 plug a couple of memory leaks in sp_lev.c, take II
[...]
| Change selection_free(foo) to also free(foo) after freeing foo's
| fields.  Every use was already
|   selection_free(foo);
|   free(foo);
| except for the two instances of memory leak.

And except for the three which aren't in sp_lev.c, one of which was
dealing with memory managed by Lua.  This time it seems to be working
as intended.
2020-02-12 18:56:41 -08:00
PatR
e09bfeb8af remove another unused variable 2020-02-09 12:28:19 -08:00
Pasi Kallinen
39032d2fac Fix the selection param unify 2020-02-09 14:47:41 +02:00
Pasi Kallinen
ced327fdf5 Unify some exported lua script params 2020-02-09 13:44:04 +02:00
nhmall
5e5217aceb more versioning bits 2019-12-01 19:38:47 -05:00
PatR
8f5cca8e3d 3.7 build cleanup
Unix Makefile.utl wasn't aware of the dependency of makedefs.o on
src/mdlib.c so didn't rebuild makedefs when it should have.

Eliminate several warnings:
mdlib.c  - #if inside the arguments to macro Sprintf();
nhlua.c  - nhl_error() ends with a call to lua_error() which doesn't
           return, but neither of them were declared that way;
nhlsel.c - because of the previous, the 'else error' case of
           l_selection_ellipse() led to complaints about uninitialized
	   variables;
sp_lev.c - missing 'const'.

I did minimal testing which went ok, but revisiting a couple of levels
gave me un-freed memory allocated by restore.c line 1337.  (I haven't
looked at that at all.)
2019-11-24 17:56:01 -08:00
Pasi Kallinen
791657f4e6 Fix memory leaks in lua integration 2019-11-20 20:09:16 +02:00
nhmall
29d378116e fix unplanned perm change 2019-11-15 22:22:19 -05:00
nhmall
298af2294f quiet some macosx warnings 2019-11-15 21:20:38 -05:00
nhmall
223c31af0c some build fix-ups 2019-11-06 13:43:27 -05:00
Pasi Kallinen
fd55d9118e Use lua for special level files
Game is playable, and should compile on linux and Windows.
Assumes you have a lua 5.3 library available.

Removes level compiler and associated files.
Replaces special level des-files with lua scripts.
Exposes some NetHack internals to lua:
 - des-table with commands to create special levels
 - nh-table with NetHack core commands
 - nhc-table with some constants
 - u-table with some player-specific data (u-struct)
 - selection userdata

Adds some rudimentary tests.

Adds new extended command #wizloadlua to run a specific script,
and #wizloaddes to run a specific level-creation script.

nhlib.lua is loaded for every lua script.

Download and untar lua:
  mkdir lib
  cd lib
  curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
  tar zxf lua-5.3.5.tar.gz

Then make nethack normally.
2019-11-06 18:43:20 +02:00