diff --git a/.appveyor.yml b/.appveyor.yml index 3e1cca1027bea..b4432d1517bc4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -19,11 +19,7 @@ cache: - 'c:\tools\vcpkg\installed' install: # Install dependency packages - - cmd: vcpkg --triplet %PLATFORM%-windows-static install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext lua - # Add LUA binary folder to PATH - - cmd: set PATH=c:\tools\vcpkg\installed\%PLATFORM%-windows-static\tools\lua;%PATH% - # Report LUA binary version - - cmd: lua.exe -v + - cmd: vcpkg --triplet %PLATFORM%-windows-static install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext build: parallel: true project: /msvc-full-features/Cataclysm-vcpkg-static.sln diff --git a/.gitattributes b/.gitattributes index 90825d5011bff..5d97f0c5845d9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,7 +9,6 @@ *.cpp text *.h text *.json text -*.lua text *.md text *.py text *.rc text diff --git a/.gitignore b/.gitignore index 38383b7cc6159..6fa36e4b48e0e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,6 @@ /obj/ /objwin/ /save/ -/src/lua/catabindings.cpp /src/version.h /sound/ /templates/ diff --git a/.travis.yml b/.travis.yml index 770eddc46d01f..ad63bba223a33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,7 @@ jobs: sources: [*apt_sources, llvm-toolchain-trusty-6.0] # macOS Tiles - - env: CLANG=clang++ NATIVE=osx OSX_MIN=10.13 TILES=1 SOUND=1 LUA=1 + - env: CLANG=clang++ NATIVE=osx OSX_MIN=10.13 TILES=1 SOUND=1 os: osx osx_image: xcode10.1 compiler: clang diff --git a/CMakeLists.txt b/CMakeLists.txt index 4375a7b0d3bdd..c8f4ff70874cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ SET(CMAKE_MODULE_PATH ) # Build options -option(LUA "Lua support (required for some mods)." "OFF") option(TILES "Build graphical tileset version." "OFF") option(CURSES "Build curses version." "ON" ) option(SOUND "Support for in-game sounds & music." "OFF") @@ -18,9 +17,8 @@ option(USE_HOME_DIR "Use user's home directory for save files." "ON" ) option(LOCALIZE "Support for language localizations. Also enable UTF support." "ON" ) option(LANGUAGES "Compile localization files for specified languages." "" ) option(DYNAMIC_LINKING "Use dynamic linking. Or use static to remove MinGW dependency instead." "ON") -option(LUA_BINARY "Lua binary name or path. You can try to use luajit for extra speed." "") option(GIT_BINARY "Git binary name or path." "") -OPTION(PREFIX "Location of Data,GFX, & Lua directories" "") +OPTION(PREFIX "Location of Data & GFX directories" "") include(CTest) @@ -140,10 +138,6 @@ ENDIF (${CMAKE_SYSTEM_NAME} MATCHES Windows) MESSAGE(STATUS "${PROJECT_NAME} build options --\n") # Preset variables -IF (NOT LUA_BINARY) - SET (LUA_BINARY "lua") -ENDIF (NOT LUA_BINARY) - IF(NOT LANGUAGES) SET (LANGUAGES de es_AR es_ES fr it_IT ja ko pt_BR ru zh_CN zh_TW) ENDIF(NOT LANGUAGES) @@ -192,16 +186,12 @@ ELSE (CMAKE_BUILD_TYPE STREQUAL Debug) MESSAGE(STATUS "PIXMAPS_UNITY_ENTRY_PATH : ${PIXMAPS_UNITY_ENTRY_PATH}") MESSAGE(STATUS "MANPAGE_ENTRY_PATH : ${MANPAGE_ENTRY_PATH}\n") ADD_DEFINITIONS(-DRELEASE) - # Use PREFIX as storage of data,gfx,lua etc.. Usefull only on *nix OS. + # Use PREFIX as storage of data,gfx, etc.. Usefull only on *nix OS. IF (PREFIX AND NOT WIN32) ADD_DEFINITIONS(-DDATA_DIR_PREFIX) ENDIF (PREFIX AND NOT WIN32) ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug) - MESSAGE(STATUS "LUA : ${LUA}") -IF (LUA) - MESSAGE(STATUS "LUA_BINARY : ${LUA_BINARY}") -ENDIF (LUA) MESSAGE(STATUS "GIT_BINARY : ${GIT_EXECUTABLE}") MESSAGE(STATUS "DYNAMIC_LINKING : ${DYNAMIC_LINKING}") MESSAGE(STATUS "TILES : ${TILES}") @@ -309,16 +299,6 @@ IF(SOUND) ENDIF(NOT SDL2_MIXER_FOUND) ENDIF(SOUND) -IF(LUA) - FIND_PACKAGE(Lua) - IF(NOT LUA_FOUND) - MESSAGE(FATAL_ERROR - "You need the Lua development library to be able to compile with Lua support.\nSee INSTALL file for details and more info\n" - ) - ENDIF(NOT LUA_FOUND) - ADD_DEFINITIONS(-DLUA) -ENDIF(LUA) - IF(BACKTRACE) ADD_DEFINITIONS(-DBACKTRACE) ENDIF(BACKTRACE) @@ -347,11 +327,6 @@ IF(USE_HOME_DIR) ADD_DEFINITIONS(-DUSE_HOME_DIR) ENDIF(USE_HOME_DIR) -IF(LUA) - add_subdirectory(lua) - add_subdirectory(src/lua) -ENDIF(LUA) - add_subdirectory(src) add_subdirectory(data) if (NOT MSVC) diff --git a/CMakeModules/FindLua.cmake b/CMakeModules/FindLua.cmake deleted file mode 100644 index df88f130d80bf..0000000000000 --- a/CMakeModules/FindLua.cmake +++ /dev/null @@ -1,117 +0,0 @@ -# Locate Lua library -# This module defines -# LUA_EXECUTABLE, if found -# LUA_FOUND, if false, do not try to link to Lua -# LUA_LIBRARIES -# LUA_INCLUDE_DIR, where to find lua.h -# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) -# -# Note that the expected include convention is -# #include "lua.h" -# and not -# #include -# This is because, the lua location is not standardized and may exist -# in locations other than lua/ - -#============================================================================= -# Copyright 2007-2009 Kitware, Inc. -# Modified to support Lua 5.2 by LuaDist 2012 -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) -# -# The required version of Lua can be specified using the -# standard syntax, e.g. FIND_PACKAGE(Lua 5.1) -# Otherwise the module will search for any available Lua implementation - -# Always search for non-versioned lua first (recommended) -SET(_POSSIBLE_LUA_INCLUDE include include/lua) -SET(_POSSIBLE_LUA_EXECUTABLE lua) -SET(_POSSIBLE_LUA_LIBRARY lua) - -# Determine possible naming suffixes (there is no standard for this) -IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") -ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1") -ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - -# Set up possible search names and locations -FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) - LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}") - LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}") - LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") -ENDFOREACH(_SUFFIX) - -# Find the lua executable -FIND_PROGRAM(LUA_EXECUTABLE - NAMES ${_POSSIBLE_LUA_EXECUTABLE} -) - -# Find the lua header -FIND_PATH(LUA_INCLUDE_DIR lua.h - HINTS - $ENV{LUA_DIR} - PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE} - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt -) - -# Find the lua library -FIND_LIBRARY(LUA_LIBRARY - NAMES ${_POSSIBLE_LUA_LIBRARY} - HINTS - $ENV{LUA_DIR} - PATH_SUFFIXES lib64 lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw - /opt/local - /opt/csw - /opt -) - -IF(LUA_LIBRARY) - # include the math library for Unix - IF(UNIX AND NOT APPLE) - FIND_LIBRARY(LUA_MATH_LIBRARY m) - SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") - # For Windows and Mac, don't need to explicitly include the math library - ELSE(UNIX AND NOT APPLE) - SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") - ENDIF(UNIX AND NOT APPLE) -ENDIF(LUA_LIBRARY) - -# Determine Lua version -IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") - FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") - - STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") - UNSET(lua_version_str) -ENDIF() - -INCLUDE(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if -# all listed variables are TRUE -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua - REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR - VERSION_VAR LUA_VERSION_STRING) - -MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE) diff --git a/COMPILING-CMAKE.md b/COMPILING-CMAKE.md index 65433a008891b..ed65b15642589 100644 --- a/COMPILING-CMAKE.md +++ b/COMPILING-CMAKE.md @@ -31,7 +31,6 @@ order to build CataclysmDDA: * `zlib` * `bzip2` * Optional - * `lua51` * `gettext` * Curses * `ncurses` @@ -68,7 +67,6 @@ Obtain packages specified above with your system package manager. pacman -S mingw-w64-i686-toolchain msys/git \ mingw-w64-i686-cmake \ mingw-w64-i686-SDL2_{image,mixer,ttf} \ - mingw-w64-i686-lua51 \ ncurses-devel \ gettext-devel ``` @@ -82,7 +80,6 @@ Obtain packages specified above with your system package manager. pacman -S mingw-w64-x86_64-toolchain msys/git \ mingw-w64-x86_64-cmake \ mingw-w64-x86_64-SDL2_{image,mixer,ttf} \ - mingw-w64-x86_64-lua51 \ ncurses-devel \ gettext-devel ``` @@ -178,9 +175,6 @@ The above example creates a build directory inside the source directory, but tha * `libintl-8.dll` * `libiconv-2.dll` - * LUA deps: - * `lua51.dll` - * TILES deps: * `SDL2.dll` * `SDL2_ttf.dll` @@ -216,7 +210,7 @@ The above example creates a build directory inside the source directory, but tha CMake can generate `.sln` and `.vcxproj` files used either by Visual Studio itself or by MSBuild command line compiler (if you don't want a full fledged IDE) and have more "native" binaries than what MSYS/Cygwin can provide. -At the moment only a limited combination of options is supported (tiles only, no lua, no localizations, no backtrace). +At the moment only a limited combination of options is supported (tiles only, no localizations, no backtrace). Get the tools: * CMake from the official site - https://cmake.org/download/. @@ -229,7 +223,6 @@ Get the required libraries: * `SDL2_image` - https://www.libsdl.org/projects/SDL_image/ * `SDL2_mixer` (optional, for sound support) - https://www.libsdl.org/projects/SDL_mixer/ * Unsupported (and unused in the following instructions) optional libs: - * `Lua` - http://luabinaries.sourceforge.net/ * `gettext`/`libintl` - http://gnuwin32.sourceforge.net/packages/gettext.htm * `ncurses` - ??? @@ -315,11 +308,6 @@ Run the game. Should work. Support for in-game sounds & music. - * LUA=`` - - This enables Lua support. Needed only for full-fledged mods. - - * USE_HOME_DIR=`` Use user's home directory for save files. @@ -342,16 +330,11 @@ Run the game. Should work. -DLANGUAGES="cs;de;el;es_AR;es_ES" ``` - * LUA_BINARY=`` - - Override default Lua binary name or path. You can try to use `luajit` for extra speed. - - * GIT_BINARY=`` Override default Git binary name or path. - So a CMake command for building Cataclysm-DDA in release mode with tiles, sound and lua support will look as follows, provided it is run in build directory located in the project. + So a CMake command for building Cataclysm-DDA in release mode with tiles and sound support will look as follows, provided it is run in build directory located in the project. ``` -cmake ../ -DCMAKE_BUILD_TYPE=Release -DTILES=ON -DSOUND=ON -DLUA=ON +cmake ../ -DCMAKE_BUILD_TYPE=Release -DTILES=ON -DSOUND=ON ``` diff --git a/COMPILING-MSYS.md b/COMPILING-MSYS.md index fe523ae4ac620..4c68da1794d65 100644 --- a/COMPILING-MSYS.md +++ b/COMPILING-MSYS.md @@ -39,7 +39,7 @@ pacman -Su 4. Install packages required for compilation with: ```bash -pacman -S git git-extras-git make mingw-w64-x86_64-{astyle,ccache,gcc,libmad,libwebp,lua,ncurses,pkg-config,SDL2} mingw-w64-x86_64-SDL2_{image,mixer,ttf} +pacman -S git git-extras-git make mingw-w64-x86_64-{astyle,ccache,gcc,libmad,libwebp,ncurses,pkg-config,SDL2} mingw-w64-x86_64-SDL2_{image,mixer,ttf} ``` 5. Update paths in system-wide profile file (e.g. `C:\msys64\etc\profile`) as following: @@ -88,10 +88,10 @@ cd Cataclysm-DDA 2. Compile with following command line: ```bash -make CCACHE=1 RELEASE=1 MSYS2=1 DYNAMIC_LINKING=1 LUA=1 SDL=1 TILES=1 SOUND=1 LOCALIZE=1 LANGUAGES=all LINTJSON=0 ASTYLE=0 RUNTESTS=0 +make CCACHE=1 RELEASE=1 MSYS2=1 DYNAMIC_LINKING=1 SDL=1 TILES=1 SOUND=1 LOCALIZE=1 LANGUAGES=all LINTJSON=0 ASTYLE=0 RUNTESTS=0 ``` -**Note**: This will compile release version with Lua, Sound and Tiles support and all localization languages, skipping checks and tests and using ccache for faster build. You can use other switches, but `MSYS2=1`, `DYNAMIC_LINKING=1` and probably `RELEASE=1` are required to compile without issues. +**Note**: This will compile release version with Sound and Tiles support and all localization languages, skipping checks and tests and using ccache for faster build. You can use other switches, but `MSYS2=1`, `DYNAMIC_LINKING=1` and probably `RELEASE=1` are required to compile without issues. ## Running: diff --git a/COMPILING-VS-VCPKG.md b/COMPILING-VS-VCPKG.md index 6c38e84373c20..570edebb6b463 100644 --- a/COMPILING-VS-VCPKG.md +++ b/COMPILING-VS-VCPKG.md @@ -34,26 +34,26 @@ vcpkg integrate install #### install 64 bit dependencies: ```cmd -vcpkg --triplet x64-windows install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext lua +vcpkg --triplet x64-windows install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext ``` or (if you want to build statically linked executable) ```cmd -vcpkg --triplet x64-windows-static install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext lua +vcpkg --triplet x64-windows-static install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext ``` #### install32 bit dependencies: ```cmd -vcpkg --triplet x86-windows install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext lua +vcpkg --triplet x86-windows install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext ``` or (if you want to build statically linked executable) ```cmd -vcpkg --triplet x86-windows-static install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext lua +vcpkg --triplet x86-windows-static install sdl2 sdl2-image sdl2-mixer sdl2-ttf gettext ``` #### upgrade all dependencies: @@ -75,4 +75,4 @@ cd Cataclysm-DDA 2. Open one of provided solutions (`msvc-full-features\Cataclysm-vcpkg.sln` for dynamically linked executable or `msvc-full-features\Cataclysm-vcpkg-static.sln` for statically linked executable) in `Visual Studio`, select configuration (`Release` or `Debug`) an platform (`x64` or `x86`) and build it. -**Note**: This will compile release version with Lua, Sound, Tiles and Localization support (language files won't be automatically compiled). +**Note**: This will compile release version with Sound, Tiles and Localization support (language files won't be automatically compiled). diff --git a/COMPILING.md b/COMPILING.md index 85fd6d24cf0ad..3b99d96cb79bd 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -63,7 +63,7 @@ There are some general dependencies, optional dependencies and then specific dep Rough list based on building on Arch: * General: `gcc-libs`, `glibc`, `zlib`, `bzip2` - * Optional: `lua51`, `gettext` + * Optional: `gettext` * Curses: `ncurses` * Tiles: `sdl2`, `sdl2_image`, `sdl2_ttf`, `sdl2_mixer`, `freetype2` @@ -72,7 +72,6 @@ E.g. for curses build on Debian and derivatives you'll also need `libncurses5-de Note on optional dependencies: * `gettext` - for localization support; if you plan to only use English you can skip it - * `lua` - for full-fledged mods; you'll probably prefer to have it You should be able to figure out what you are missing by reading the compilation errors and/or the output of `ldd` for compiled binaries. @@ -86,7 +85,6 @@ Given you're building from source you have a number of choices to make: * `TILES=1` - with this you'll get the tiles version, without it the curses version * `SOUND=1` - if you want sound; this requires `TILES=1` * `LOCALIZE=0` - this disables localizations so `gettext` is not needed - * `LUA=1` - this enables Lua support; needed only for full-fledged mods * `CLANG=1` - use Clang instead of GCC * `CCACHE=1` - use ccache * `USE_LIBCXX=1` - use libc++ instead of libstdc++ with Clang (default on OS X) @@ -137,12 +135,11 @@ Dependencies: * SDL_ttf * freetype * build essentials - * lua5.2 and liblua5.2 - Only necessary if compiling with lua, which some mods like stats through skills use. Versions 5.1, 5.2 and 5.3 are supported. * libsdl2-mixer-dev - Used if compiling with sound support. Install: - sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libfreetype6-dev build-essential lua5.2 liblua5.2-dev + sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libfreetype6-dev build-essential ### Building @@ -152,9 +149,9 @@ A simple installation could be done by simply running: A more comprehensive alternative is: - make -j2 TILES=1 SOUND=1 RELEASE=1 LUA=1 USE_HOME_DIR=1 + make -j2 TILES=1 SOUND=1 RELEASE=1 USE_HOME_DIR=1 -The -j2 flag means it will compile with two parallel processes. It can be omitted or changed to -j4 in a more modern processor. If there is no desire to use lua, or have sound, those flags can also be omitted. The USE_HOME_DIR flag places the user files, like configurations and saves into the home folder, making It easier for backups, and can also be omitted. +The -j2 flag means it will compile with two parallel processes. It can be omitted or changed to -j4 in a more modern processor. If there is no desire to have sound, those flags can also be omitted. The USE_HOME_DIR flag places the user files, like configurations and saves into the home folder, making It easier for backups, and can also be omitted. @@ -192,7 +189,7 @@ Install: mkdir -p ~/src/mxe git clone https://github.com/mxe/mxe.git ~/src/mxe cd ~/src/mxe - make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' sdl2 sdl2_ttf sdl2_image sdl2_mixer gettext lua ncurses + make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' sdl2 sdl2_ttf sdl2_image sdl2_mixer gettext ncurses If you are not on a Debian derivative (Linux Mint, Ubuntu, etc), you will have to use a different command than apt-get to install [the MXE requirements](http://mxe.cc/#requirements). Building all these packages from MXE might take a while even on a fast computer. Be patient. If you are not planning on building for both 32-bit and 64-bit, you might want to adjust your MXE_TARGETS. @@ -201,21 +198,21 @@ If you are not on a Debian derivative (Linux Mint, Ubuntu, etc), you will have t Run: PLATFORM="i686-w64-mingw32.static" - make CROSS="~/src/mxe/usr/bin/${PLATFORM}-" TILES=1 SOUND=1 LUA=1 RELEASE=1 LOCALIZE=1 + make CROSS="~/src/mxe/usr/bin/${PLATFORM}-" TILES=1 SOUND=1 RELEASE=1 LOCALIZE=1 Change PLATFORM to x86_64-w64-mingw32.static for a 64-bit Windows build. To create nice zip file with all the required resources for a trouble free copy on Windows use the bindist target like this: PLATFORM="i686-w64-mingw32.static" - make CROSS="~/src/mxe/usr/bin/${PLATFORM}-" TILES=1 SOUND=1 LUA=1 RELEASE=1 LOCALIZE=1 bindist + make CROSS="~/src/mxe/usr/bin/${PLATFORM}-" TILES=1 SOUND=1 RELEASE=1 LOCALIZE=1 bindist ### Building (ncurses) Run: PLATFORM="i686-w64-mingw32.static" - make CROSS="~/src/mxe/usr/bin/${PLATFORM}-" LUA=1 RELEASE=1 LOCALIZE=1 + make CROSS="~/src/mxe/usr/bin/${PLATFORM}-" RELEASE=1 LOCALIZE=1 ## Cross-compile to Mac OS X from Linux @@ -252,34 +249,31 @@ Your directory tree should look like: ├── gettext │   ├── include │   └── lib - ├── lua - │   ├── include - │   └── lib └── ncurses ├── include └── lib Populated with respective frameworks, dylibs and headers. -Tested lib versions are libintl.8.dylib for gettext, liblua.5.2.4.dylib for lua, libncurses.5.4.dylib for ncurses. +Tested lib versions are libintl.8.dylib for gettext, libncurses.5.4.dylib for ncurses. These libs were obtained from `homebrew` binary distribution at OS X 10.11 Frameworks were obtained from SDL official website as described in the next [section](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/COMPILING.md#sdl) ### Building (SDL) -To build full feature tiles and sound enabled version with localizations and lua enabled: +To build full feature tiles and sound enabled version with localizations enabled: make dmgdist CROSS=x86_64-apple-darwin15- NATIVE=osx OSX_MIN=10.7 USE_HOME_DIR=1 CLANG=1 - RELEASE=1 LOCALIZE=1 LANGUAGES=all LUA=1 TILES=1 SOUND=1 FRAMEWORK=1 + RELEASE=1 LOCALIZE=1 LANGUAGES=all TILES=1 SOUND=1 FRAMEWORK=1 OSXCROSS=1 LIBSDIR=../libs FRAMEWORKSDIR=../Frameworks Make sure that `x86_64-apple-darwin15-clang++` is in `PATH` environment variable. ### Building (ncurses) -To build full curses version with localizations and lua enabled: +To build full curses version with localizations enabled: make dmgdist CROSS=x86_64-apple-darwin15- NATIVE=osx OSX_MIN=10.7 USE_HOME_DIR=1 CLANG=1 - RELEASE=1 LOCALIZE=1 LANGUAGES=all LUA=1 OSXCROSS=1 LIBSDIR=../libs FRAMEWORKSDIR=../Frameworks + RELEASE=1 LOCALIZE=1 LANGUAGES=all OSXCROSS=1 LIBSDIR=../libs FRAMEWORKSDIR=../Frameworks Make sure that `x86_64-apple-darwin15-clang++` is in `PATH` environment variable. @@ -287,7 +281,7 @@ Make sure that `x86_64-apple-darwin15-clang++` is in `PATH` environment variable The Android build uses [Gradle](https://gradle.org/) to compile the java and native C++ code, and is based heavily off SDL's [Android project template](https://hg.libsdl.org/SDL/file/f1084c419f33/android-project). See the official SDL documentation [README-android.md](https://hg.libsdl.org/SDL/file/f1084c419f33/docs/README-android.md) for further information. -The Gradle project lives in the repository under `android/`. You can build it via the command line or open it in [Android Studio](https://developer.android.com/studio/). For simplicity, it only builds the SDL version with all features enabled, including tiles, sound, localization and lua. +The Gradle project lives in the repository under `android/`. You can build it via the command line or open it in [Android Studio](https://developer.android.com/studio/). For simplicity, it only builds the SDL version with all features enabled, including tiles, sound and localization. ### Dependencies @@ -297,7 +291,6 @@ The Gradle project lives in the repository under `android/`. You can build it vi * SDL2_mixer (tested with 2.0.2) * SDL2_image (tested with 2.0.3) * libintl-lite (tested with a custom fork of libintl-lite 0.5) - * lua (tested with lua 5.1.5) The Gradle build process automatically installs dependencies from [deps.zip](android/app/deps.zip). @@ -305,7 +298,7 @@ The Gradle build process automatically installs dependencies from [deps.zip](and Install Linux dependencies. For a desktop Ubuntu installation: - sudo apt-get install lua5.2 openjdk-8-jdk-headless + sudo apt-get install openjdk-8-jdk-headless Install Android SDK and NDK: @@ -358,7 +351,7 @@ To build Cataclysm on Mac you'll need [Command Line Tools for Xcode](https://dev ## Simple build using Homebrew -Homebrew installation will come with tiles, sound and lua suooprt enabled by default. +Homebrew installation will come with tiles and sound support enabled by default. Once you have Homebrew installed, open Terminal and run one of the following commands. @@ -564,7 +557,7 @@ Open Terminal's preferences, turn on "Use bright colors for bold text" in "Prefe ## Visual Studio Guide -Visual Studio 2015 (or later) is required to build Cataclysm. If you use a later version of Visual Studio, you will need to [enable the Visual Studio 2015 (v140) platform toolset](https://developercommunity.visualstudio.com/content/problem/48806/cant-find-v140-in-visual-studio-2017.html). We created solution and project files in directory `msvc-full-features`. Because of the complexity and how troublesome defining every combination of build feature options are, in Visual Studio project we added all build features, including tiles, sound, localization and lua. +Visual Studio 2015 (or later) is required to build Cataclysm. If you use a later version of Visual Studio, you will need to [enable the Visual Studio 2015 (v140) platform toolset](https://developercommunity.visualstudio.com/content/problem/48806/cant-find-v140-in-visual-studio-2017.html). We created solution and project files in directory `msvc-full-features`. Because of the complexity and how troublesome defining every combination of build feature options are, in Visual Studio project we added all build features, including tiles, sound and localization. ### Dependencies @@ -572,12 +565,6 @@ We've prepared an archive containing all the headers and libraries required to b Extract the 'WinDepend' folder and put it in the root folder of Cataclysm project. Run the "copy_dll_to_bin" batch file and then move the dll files from the bin folder into the root folder the Cataclysm project. -### Lua - -The next thing you need to do is to install lua. Download the appropriate x86 or x64 lua from [http://lua-users.org/wiki/LuaBinaries](http://lua-users.org/wiki/LuaBinaries) or [http://dev.narc.ro/cataclysm/WinDepend-lua.zip](http://dev.narc.ro/cataclysm/WinDepend-lua.zip), and extract it to `C:\Windows\System32` or somewhere else on your path. - -Once you have it installed, go to the project directory, then go to `src/lua`, and run `lua53 generate_bindings.lua catabindings.cpp`. This will generate the `catabindings.cpp` file which is necessary for compilation. - ### Building Building Cataclysm with Visual Studio is very simple. Just build it like a normal Visual C++ project. The process may takes a long period of time, so you'd better prepare a cup of coffee and some books in front of your computer :) @@ -613,7 +600,7 @@ If we want to compile with Tiles (SDL) we have to download a few libraries. #### Bundled Libraries The following archives were pre-bundled for convenience and reduction of head-aches, simply download and extract directly to the root directory of the CDDA source: -* `64-bit SDL \ Tiles \ Sound \ Lua \ Localization` http://dev.narc.ro/cataclysm/cdda-win64-codeblocks.7z +* `64-bit SDL \ Tiles \ Sound \ Localization` http://dev.narc.ro/cataclysm/cdda-win64-codeblocks.7z #### Installing Tiles(SDL) libraries. For the first 3 (`SDL2`, `SDL_ttf` and `SDL_image`) you want to extract the include and lib folders from the `i686-w64-mingw32` folders into your MinGW installation folder. (Recommended `C:\MinGW`). And the `SDL2_image.dll` and `SDL2_ttf.dll` into your cataclysm root folder. @@ -644,7 +631,7 @@ If you dont want localization you can change `LOCALIZE` to 0. ## Rough guide to building with only MSYS2 -This is a tentative step-by-step guide to building your own CDDA with Tiles, Localization and Lua using only MSYS2. You may want to follow it if the MinGW guide above doesn't work for you or you just feel adventurous. Feedback is very much welcome in terms of issues and/or pull-requests. +This is a tentative step-by-step guide to building your own CDDA with Tiles and Localization using only MSYS2. You may want to follow it if the MinGW guide above doesn't work for you or you just feel adventurous. Feedback is very much welcome in terms of issues and/or pull-requests. This guide assumes you're building on a x86_64 build of Windows. If not adjust the invocations appropriately. It has been tested and proven to work on Windows XP, Windows 7 and Windows 10. Your mileage may vary. @@ -702,7 +689,6 @@ pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_image mingw-w64-x86_64-SDL pacman -S mingw-w64-x86_64-ncurses pacman -S mingw-w64-x86_64-pkg-config mingw-w64-x86_64-libwebp pacman -S git make -pacman -S mingw-w64-x86_64-lua ``` #### 8. Close MSYS2 terminal and open MinGW-w64 Win64 Shell from Start menu and run: @@ -717,11 +703,9 @@ cd Cataclysm-DDA #### 9. Compile your CDDA by running: ```bash -make MSYS2=1 RELEASE=1 TILES=1 LOCALIZE=1 SOUND=1 LUA=1 NATIVE=win64 +make MSYS2=1 RELEASE=1 TILES=1 LOCALIZE=1 SOUND=1 NATIVE=win64 ``` -Note: You cannot naively use `-jX` to speed up your building process with `LUA=1`. You must first run `cd src/lua/ && lua generate_bindings.lua && cd ../..` if you want to use `-jX`. X should be the number of threads/cores your processor has. - That's it. You should get a `cataclysm-tiles.exe` binary in the same folder you've found the `Makefile` in. The make flags are the same as the ones described above. For instance, if you do not want to build with sound support, you can remove `SOUND=1`. # BSDs diff --git a/Cataclysm-DDA.sublime-project b/Cataclysm-DDA.sublime-project index 60c82405510e5..377460e7a2428 100644 --- a/Cataclysm-DDA.sublime-project +++ b/Cataclysm-DDA.sublime-project @@ -8,11 +8,10 @@ "USE_HOME_DIR=1", "CLANG=1", "CCACHE=1", - "RELEASE=1", - "LUA=1" + "RELEASE=1" ], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", - "name": "make RELEASE LUA", + "name": "make RELEASE", "working_dir": "${folder:${project_path:${file_path}}}" }, { @@ -21,11 +20,10 @@ "make", "USE_HOME_DIR=1", "CLANG=1", - "CCACHE=1", - "LUA=1" + "CCACHE=1" ], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", - "name": "make LUA", + "name": "make", "working_dir": "${folder:${project_path:${file_path}}}" }, { @@ -35,11 +33,10 @@ "USE_HOME_DIR=1", "CLANG=1", "CCACHE=1", - "LUA=1", "TILES=1" ], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", - "name": "make TILES LUA", + "name": "make TILES", "working_dir": "${folder:${project_path:${file_path}}}" }, { @@ -49,12 +46,11 @@ "USE_HOME_DIR=1", "CLANG=1", "CCACHE=1", - "LUA=1", "TILES=1", "RELEASE=1" ], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", - "name": "make RELEASE TILES LUA", + "name": "make RELEASE TILES", "working_dir": "${folder:${project_path:${file_path}}}" } ], diff --git a/CataclysmWin.cbp b/CataclysmWin.cbp index 3cf5c59e9b323..7bba07d40e578 100644 --- a/CataclysmWin.cbp +++ b/CataclysmWin.cbp @@ -54,28 +54,6 @@ - - - + - - - + diff --git a/Makefile b/Makefile index 6d289fc703bf0..f17802127b78c 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,6 @@ # make AUTO_BUILD_PREFIX=1 # Install to system directories. # make install -# Enable lua support. Required only for full-fledged mods. -# make LUA=1 # Use user's XDG base directories for save files and configs. # make USE_XDG_DIR=1 # Use user's home directory for save files. @@ -134,10 +132,6 @@ CHKJSON_BIN = $(BUILD_PREFIX)chkjson BINDIST_DIR = $(BUILD_PREFIX)bindist BUILD_DIR = $(CURDIR) SRC_DIR = src -LUA_DIR = lua -LUASRC_DIR = $(SRC_DIR)/$(LUA_DIR) -# if you have LUAJIT installed, try make LUA_BINARY=luajit for extra speed -LUA_BINARY = lua LOCALIZE = 1 ASTYLE_BINARY = astyle @@ -178,7 +172,7 @@ W32ODIR = $(BUILD_PREFIX)objwin W32ODIRTILES = $(W32ODIR)/tiles ifdef AUTO_BUILD_PREFIX - BUILD_PREFIX = $(if $(RELEASE),release-)$(if $(DEBUG_SYMBOLS),symbol-)$(if $(TILES),tiles-)$(if $(SOUND),sound-)$(if $(LOCALIZE),local-)$(if $(BACKTRACE),back-)$(if $(SANITIZE),sanitize-)$(if $(MAPSIZE),map-$(MAPSIZE)-)$(if $(LUA),lua-)$(if $(USE_XDG_DIR),xdg-)$(if $(USE_HOME_DIR),home-)$(if $(DYNAMIC_LINKING),dynamic-)$(if $(MSYS2),msys2-) + BUILD_PREFIX = $(if $(RELEASE),release-)$(if $(DEBUG_SYMBOLS),symbol-)$(if $(TILES),tiles-)$(if $(SOUND),sound-)$(if $(LOCALIZE),local-)$(if $(BACKTRACE),back-)$(if $(SANITIZE),sanitize-)$(if $(MAPSIZE),map-$(MAPSIZE)-)$(if $(USE_XDG_DIR),xdg-)$(if $(USE_HOME_DIR),home-)$(if $(DYNAMIC_LINKING),dynamic-)$(if $(MSYS2),msys2-) export BUILD_PREFIX endif @@ -499,41 +493,6 @@ ifeq ($(SOUND), 1) CXXFLAGS += -DSDL_SOUND endif -ifdef LUA - ifeq ($(TARGETSYSTEM),WINDOWS) - ifeq ($(MSYS2),1) - LUA_USE_PKGCONFIG := 1 - else - # Windows expects to have lua unpacked at a specific location - LUA_LIBS := -llua - endif - else - LUA_USE_PKGCONFIG := 1 - endif - - ifdef OSXCROSS - LUA_LIBS = -L$(LIBSDIR)/lua/lib -llua -lm - LUA_CFLAGS = -I$(LIBSDIR)/lua/include - else - ifdef LUA_USE_PKGCONFIG - # On unix-like systems, use pkg-config to find lua - LUA_CANDIDATES = lua5.3 lua5.2 lua-5.3 lua-5.2 lua5.1 lua-5.1 lua $(LUA_BINARY) - LUA_FOUND = $(firstword $(foreach lua,$(LUA_CANDIDATES),\ - $(shell if $(PKG_CONFIG) --silence-errors --exists $(lua); then echo $(lua);fi))) - LUA_PKG = $(if $(LUA_FOUND),$(LUA_FOUND),$(error "Lua not found by $(PKG_CONFIG), install it or make without 'LUA=1'")) - LUA_LIBS := $(shell $(PKG_CONFIG) --silence-errors --libs $(LUA_PKG)) - LUA_CFLAGS := $(shell $(PKG_CONFIG) --silence-errors --cflags $(LUA_PKG)) - endif - endif - - LDFLAGS += $(LUA_LIBS) - CXXFLAGS += $(LUA_CFLAGS) - - CXXFLAGS += -DLUA - LUA_DEPENDENCIES = $(LUASRC_DIR)/catabindings.cpp - BINDIST_EXTRAS += $(LUA_DIR) -endif - ifdef SDL TILES = 1 endif @@ -794,15 +753,13 @@ endif $(BUILD_PREFIX)$(TARGET_NAME).a: $(OBJS) $(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS)) -.PHONY: version json-verify +.PHONY: version version: @( VERSION_STRING=$(VERSION) ; \ [ -e ".git" ] && GITVERSION=$$( git describe --tags --always --dirty --match "[0-9A-Z]*.[0-9A-Z]*" ) && VERSION_STRING=$$GITVERSION ; \ [ -e "$(SRC_DIR)/version.h" ] && OLDVERSION=$$(grep VERSION $(SRC_DIR)/version.h|cut -d '"' -f2) ; \ if [ "x$$VERSION_STRING" != "x$$OLDVERSION" ]; then echo "#define VERSION \"$$VERSION_STRING\"" | tee $(SRC_DIR)/version.h ; fi \ ) -json-verify: - $(LUA_BINARY) lua/json_verifier.lua # Unconditionally create the object dir on every invocation. $(shell mkdir -p $(ODIR)) @@ -817,11 +774,6 @@ src/version.h: version src/version.cpp: src/version.h -$(LUASRC_DIR)/catabindings.cpp: $(LUA_DIR)/class_definitions.lua $(LUASRC_DIR)/generate_bindings.lua - cd $(LUASRC_DIR) && $(LUA_BINARY) generate_bindings.lua - -$(SRC_DIR)/catalua.cpp: $(LUA_DEPENDENCIES) - localization: lang/compile_mo.sh $(LANGUAGES) @@ -836,7 +788,7 @@ clean: clean-tests rm -rf *$(TILES_TARGET_NAME).exe *$(TARGET_NAME).exe *$(TARGET_NAME).a rm -rf *obj *objwin rm -rf *$(BINDIST_DIR) *cataclysmdda-*.tar.gz *cataclysmdda-*.zip - rm -f $(SRC_DIR)/version.h $(LUASRC_DIR)/catabindings.cpp + rm -f $(SRC_DIR)/version.h rm -f $(CHKJSON_BIN) distclean: @@ -872,12 +824,6 @@ ifdef TILES endif ifdef SOUND cp -R --no-preserve=ownership data/sound $(DATA_PREFIX) -endif -ifdef LUA - mkdir -p $(DATA_PREFIX)/lua - install --mode=644 lua/autoexec.lua $(DATA_PREFIX)/lua - install --mode=644 lua/log.lua $(DATA_PREFIX)/lua - install --mode=644 lua/class_definitions.lua $(DATA_PREFIX)/lua endif install --mode=644 data/changelog.txt data/cataicon.ico data/fontdata.json \ LICENSE.txt -t $(DATA_PREFIX) @@ -909,12 +855,6 @@ ifdef TILES endif ifdef SOUND cp -R --no-preserve=ownership data/sound $(DATA_PREFIX) -endif -ifdef LUA - mkdir -p $(DATA_PREFIX)/lua - install --mode=644 lua/autoexec.lua $(DATA_PREFIX)/lua - install --mode=644 lua/log.lua $(DATA_PREFIX)/lua - install --mode=644 lua/class_definitions.lua $(DATA_PREFIX)/lua endif install --mode=644 data/changelog.txt data/cataicon.ico data/fontdata.json \ LICENSE.txt -t $(DATA_PREFIX) @@ -975,11 +915,6 @@ ifeq ($(LOCALIZE), 1) LIBINTL=$$($(CROSS)otool -L $(APPTARGET) | grep libintl | sed -n 's/\(.*\.dylib\).*/\1/p') && if [ -f $$LIBINTL ]; then cp $$LIBINTL $(APPRESOURCESDIR)/; fi; \ if [ ! -z "$$OSXCROSS" ]; then LIBINTL=$$(basename $$LIBINTL) && if [ ! -z "$$LIBINTL" ]; then cp $(LIBSDIR)/gettext/lib/$$LIBINTL $(APPRESOURCESDIR)/; fi; fi endif -ifdef LUA - cp -R lua $(APPRESOURCESDIR)/ - LIBLUA=$$($(CROSS)otool -L $(APPTARGET) | grep liblua | sed -n 's/\(.*\.dylib\).*/\1/p') && if [ -f $$LIBLUA ]; then cp $$LIBLUA $(APPRESOURCESDIR)/; fi; \ - if [ ! -z "$$OSXCROSS" ]; then LIBLUA=$$(basename $$LIBLUA) && if [ ! -z "$$LIBLUA" ]; then cp $(LIBSDIR)/lua/lib/$$LIBLUA $(APPRESOURCESDIR)/; fi; fi -endif # ifdef LUA ifdef TILES ifdef SOUND cp -R data/sound $(APPDATADIR) diff --git a/build-scripts/Dockerfile.debian-build b/build-scripts/Dockerfile.debian-build index 582c7249d54a8..9c7852fb940a3 100644 --- a/build-scripts/Dockerfile.debian-build +++ b/build-scripts/Dockerfile.debian-build @@ -33,7 +33,7 @@ RUN apt-fast -qq install --no-install-recommends gettext RUN apt-fast -qq install --no-install-recommends libncurses5-dev libncursesw5-dev # CDDA: libraries for tiles build -RUN apt-fast -qq install --no-install-recommends libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libfreetype6-dev lua5.2 liblua5.2-dev +RUN apt-fast -qq install --no-install-recommends libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libfreetype6-dev # general packages for a much nicer time inside the container (we install psmisc for `killall`) RUN apt-fast -qq install --no-install-recommends tree watch tmux fish colormake vim emacs git silversearcher-ag lsof psmisc dstat diff --git a/build-scripts/requirements.sh b/build-scripts/requirements.sh index 8e1d07c3fbaf3..41cab57cf7336 100644 --- a/build-scripts/requirements.sh +++ b/build-scripts/requirements.sh @@ -32,6 +32,6 @@ fi if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update - brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gettext ncurses lua + brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gettext ncurses brew link --force gettext ncurses fi diff --git a/data/mods/StatsThroughSkills/modinfo.json b/data/mods/StatsThroughSkills/modinfo.json index 640793aff13bd..103e2baf12022 100644 --- a/data/mods/StatsThroughSkills/modinfo.json +++ b/data/mods/StatsThroughSkills/modinfo.json @@ -4,7 +4,7 @@ "ident": "StatsThroughSkills", "name": "StatsThroughSkills", "authors": [ "Ryan \"DeNarr\" Saige", "Kevin Granade" ], - "description": "Allows stats to raise naturally via skill progression.", + "description": "Allows stats to raise via skill progression.", "category": "rebalance", "dependencies": [ "dda" ] }, diff --git a/doc/LUA_SUPPORT.md b/doc/LUA_SUPPORT.md deleted file mode 100644 index 7719e3d60debf..0000000000000 --- a/doc/LUA_SUPPORT.md +++ /dev/null @@ -1,194 +0,0 @@ -File Layout -=========== - -- `src/catalua.cpp` - Core of the lua mod, glueing lua to the cataclysm C++ engine. -- `src/catalua.h` - Export of some public lua-related functions, do not use these outside #ifdef LUA -- `lua/autoexec.lua` - Lua-side initialization of important data structures(metatables for classes etc.) -- `lua/class_definitions.lua` - Definitions of classes and functions that bindings will be generated from -- `lua/generate_bindings.lua` - Custom binding generator for cataclysm, can generate class and function bindings. -- `lua/catabindings.cpp` - Output of generate_bindings.lua -- `data/main.lua` - Script that will be called on cataclysm startup. You can define functions here and call them in the lua debug interpreter. - -Adding new functionality -======================== - -Generally, adding new functionality to lua is pretty straightforward. You have several options. - -Manually defining a new lua function in catalua.cpp ---------------------------------------------------- - -This is the most straightforward, and also most difficult method. You basically define a new C function that does all the lua stack handling etc. manually, then register it in the lua function table. More information on this can be found at: http://www.lua.org/manual/5.1/manual.html#3 - -An example of such a function would be: - -```c++ -// items = game.items_at(x, y) -static int game_items_at(lua_State *L) { - int x = lua_tointeger(L, 1); - int y = lua_tointeger(L, 2); - - std::vector& items = g->m.i_at(x, y); - - lua_createtable(L, items.size(), 0); // Preallocate enough space for all our items. - - // Iterate over the monster list and insert each monster into our returned table. - for(int i=0; i < items.size(); i++) { - // The stack will look like this: - // 1 - t, table containing item - // 2 - k, index at which the next item will be inserted - // 3 - v, next item to insert - // - // lua_rawset then does t[k] = v and pops v and k from the stack - - lua_pushnumber(L, i + 1); - item** item_userdata = (item**) lua_newuserdata(L, sizeof(item*)); - *item_userdata = &(items[i]); - luah_setmetatable(L, "item_metatable"); - lua_rawset(L, -3); - } - - return 1; // 1 return values -} - -static const struct luaL_Reg global_funcs [] = { - {"register_iuse", game_register_iuse}, - {"items_at", game_items_at}, // Don't forget to register your function in here! - {NULL, NULL} -}; -``` - -Defining a global function in catalua.cpp and registering it in lua/class_definitions.lua ---------------------------------------------------------------------------------------------- - -This method involves a bit more bureaucracy, but is much easier to pull off and less prone to errors. Unless you wish to do something that the binding generator can't handle, this method is recommended for functions. - -First, define your function however you like in catalua.cpp - -```c++ -// game.remove_item(x, y, item) -void game_remove_item(int x, int y, item *it) { - std::vector& items = g->m.i_at(x, y); - - for(int i=0; iadd_msg`(works because g is a global). `args` is simply a list of the argument types, most common C++ types should work, as well as any classes that are wrapped by lua. `rval` is similarly the type of the return value, and since C++ has no multi-return, rval is not a list. - -Of note is the special argument type `game`. If that type is found, the binding generator will not wrap that parameter, but instead always pass `g` to that argument. So say you have a function foo(game* g, int a), then you should set `args = {"game", "int"}`, and from lua you would simply call foo(5), the game parameter being implicitly set to `g`. - - -Wrapping class member variables -------------------------------- - -Wrapping member variables is simply a matter of adding the relevant entries to the class definition in lua/class_definitions.lua. - -```lua -classes = { - player = { - attributes = { - posx = { - type = "int", - writable = false - }, -``` - -`type` works the same as for global functions, `writable` specifies whether a setter should be generated for this attribute. - -Wrapping class member functions -------------------------------- - -This process is nearly identical to wrapping global functions. - -```lua -classes = { - player = { - [...] - functions = { - has_disease = { - args = { "string" }, - rval = "bool" - }, -``` - -As you can see, the way functions are defined here is identical to global functions. The only difference is that there's an implicit first argument that will always be present, `self`, which enables us to call `player:has_disease("foo")`. - - -Adding new classes ------------------- - -To add a new wrapped class, you have to do several things: -- Add a new entry to `classes` in lua/class_definitions.lua -- Add the relevant metatable to lua/autoexec.lua, e.g. `monster_metatable = generate_metatable("monster", classes.monster)` - -Eventually, the latter should be automated, but right now it's necessary. Note that the class name should be the exact same in lua as in C++, otherwise the binding generator will fail. That limitation might be removed at some point. - -Callbacks ---------- - -Following Lua-callbacks exist: - -*game-related*: - -- `on_savegame_loaded` runs when saved game is loaded; -- `on_weather_changed(weather_new, weather_old)` runs when weather is changed. - -*calendar-related*: - -- `on_turn_passed` runs once each turn (once per 6 seconds or 10 times per minute); -- `on_minute_passed` runs once per minute; -- `on_hour_passed` runs once per hour (at the beginning of the hour); -- `on_day_passed` runs once per day (at midnight); -- `on_year_passed` runs once per year (on first day of the year at midnight). - -*player-related*: - -- `on_player_skill_increased(player_id, source, skill_id, level)` runs whenever player skill is increased (previously known as `on_skill_increased`); -- `on_player_dodge(player_id, source, difficulty)` runs whenever player have dodged; -- `on_player_hit(player_id, source, body_part)` runs whenever player were hit; -- `on_player_hurt(player_id, source, disturb)` runs whenever player were hurt; -- `on_player_mutation_gain(player_id, mutation_id)` runs whenever player gains mutation; -- `on_player_mutation_loss(player_id, mutation_id)` runs whenever player loses mutation; -- `on_player_stat_change(player_id, stat_id, stat_value)` runs whenever player stats are changed; -- `on_player_effect_int_changes(player_id, effect_id, intensity, bodypart)` runs whenever intensity of effect on player has changed; -- `on_player_item_wear(player_id, item_id)` runs whenever player wears some clothes on; -- `on_player_item_takeoff(player_id, item_id)` runs whenever player takes some clothes off; -- `on_mission_assignment(player_id, mission_id)` runs whenever player is assigned to mission; -- `on_mission_finished(player_id, mission_id)` runs whenever player finishes the mission. - -*player activity-related*: - -- `on_activity_call_do_turn_started(act_id, player_id)` runs whenever player activity turn started; -- `on_activity_call_do_turn_finished(act_id, player_id)` runs whenever player activity turn ended; -- `on_activity_call_finish_started(act_id, player_id)` runs whenever player activity finish started; -- `on_activity_call_finish_finished(act_id, player_id)` runs whenever player activity finish ended. - -__Note for `player_id`:__ Value of -1 (when game is not started) or 1 (when game is started) are used for player character, values bigger than 1 are used for npcs. - -*mapgen-related*: - -- `on_mapgen_finished(mapgen_generator_type, mapgen_terrain_type_id, mapgen_terrain_coordinates)` runs whenever `builtin`, `json` or `lua` mapgen is finished generating. - -Some callbacks provide arguments which can be useful (see example mods). - -Example mods -============ - -See `/doc/sample_mods` folder. diff --git a/doc/MAPGEN.md b/doc/MAPGEN.md index 79b3586f106bf..832c578572177 100644 --- a/doc/MAPGEN.md +++ b/doc/MAPGEN.md @@ -45,30 +45,26 @@ * 2.4.0.1 "amount" * 2.4.0.2 "chance" * 2.4.0.3 "repeat" - * 2.5 "lua": - * 2.6 specials: - * 2.6.0 "fields" - * 2.6.1 "npcs" - * 2.6.2 "signs" - * 2.6.3 "vendingmachines" - * 2.6.4 "toilets" - * 2.6.5 "gaspumps" - * 2.6.6 "items" - * 2.6.7 "monsters" - * 2.6.8 "vehicles" - * 2.6.9 "item" - * 2.6.10 "traps" - * 2.6.11 "furniture" - * 2.6.12 "terrain" - * 2.6.13 "monster" - * 2.6.14 "rubble" - * 2.6.15 "place_liquids" - * 2.6.16 "loot" - * 2.6.17 "sealed_item" - * 2.7 "rotation" -* 3 Method: lua - * 3.0 Tested functions - * 3.1 Example script inside overmap_terrain entry + * 2.5 specials: + * 2.5.0 "fields" + * 2.5.1 "npcs" + * 2.5.2 "signs" + * 2.5.3 "vendingmachines" + * 2.5.4 "toilets" + * 2.5.5 "gaspumps" + * 2.5.6 "items" + * 2.5.7 "monsters" + * 2.5.8 "vehicles" + * 2.5.9 "item" + * 2.5.10 "traps" + * 2.5.11 "furniture" + * 2.5.12 "terrain" + * 2.5.13 "monster" + * 2.5.14 "rubble" + * 2.5.15 "place_liquids" + * 2.5.16 "loot" + * 2.5.17 "sealed_item" + * 2.6 "rotation" # 0 Intro Note: You may wish to read over JSON_INFO.md beforehand. @@ -89,8 +85,6 @@ One doesn't (and shouldn't) need to create a new overmap_terrain for a new varia While adding mapgen as a c++ function is one of the fastest (and the most versatile) ways to generate procedural terrain on the fly, this requires recompiling the game. For mods, one can instead define a mapgen function in: * JSON: A set of json arrays and objects for defining stuff and things. Pros: Fastest to apply, mostly complete, supported by one third party map editor so far. Cons: Not a programming language; no if statements or variables means instances of a particular json mapgen definition will all be similar. Support was added for randomizing things, however. -* LUA: The same scripting language used in Garry's Mod, S.T.A.L.K.E.R, CIV5, etc. Pros: Powerful; as a full scripting language it allows for endless variety and options in theory. Cons: In theory; lua needs bindings for internal game functions, and this is a work in progress. Also, it will apply to the map slower than c++ or json. - ## 1.1 Placement Mapgen definitions can be added in 2 places: ### 1.1.0 Embedded @@ -111,7 +105,7 @@ As "mapgen": { ... } objects inside an existing overmap_terrain object ( see "s_ ``` ### 1.1.1 Standalone -As standalone { "type": "mapgen", ... } objects in a .json inside data/json. Below is the same fast food restaurant, along with one written lua (as part of unhealthy_dining_expansion_mod.json) +As standalone { "type": "mapgen", ... } objects in a .json inside data/json. Below is the same fast food restaurant. ```C++ [ { @@ -122,15 +116,6 @@ As standalone { "type": "mapgen", ... } objects in a .json inside data/json. Bel "object": { (see below) } - }, - { - "type": "mapgen", - "om_terrain": "s_restaurant_fast", - "weight": 500, - "method": "lua", - "script": { - (see below) - } } ] ``` @@ -147,25 +132,6 @@ The above example only illustrate the mapgen entries, not the actual format for "object": { (more json here) } ``` --or- - -> * "lua" - requires - -``` -"script": "-- string of lua code\n -- for newline use \n -- and escape \"quote\"s" -``` - --or- - -> "lua" - requires - -``` -"script": [ - " -- array of lines ", - " -- etc ", -] -``` - ### 1.2.1 "om_terrain": **required for standalone** > Values: @@ -209,11 +175,10 @@ Default: 1000 ## 1.3 How "overmap_terrain" variables affect mapgen "id" is used to determine the required "om_terrain" id for standalone, -except- when the following variables are set in "overmap_terrain": * "extras" - applies rare, random scenes after mapgen; helicopter crashes, etc -* "mondensity" - determines the default 'density' value for *"place_groups": [ { "monster": ...* (json) or *map:place_monster(..)* (lua) +* "mondensity" - determines the default 'density' value for *"place_groups": [ { "monster": ...* (json) ## 1.4 Limitations / TODO * JSON: adding specific monster spawns are still WIP. -* lua: Just about *everything* is WIP; there are issues passing class pointers back and forth with the game that will be corrected eventually * The old mapgen.cpp system involved *The Biggest "if / else if / else if / .." Statement Known to Man*(tm), and is only halfway converted to the "builtin" mapgen class. This means that while custom mapgen functions are allowed, the game will cheerfully forget the default if one is added. * TODO: Add to this list. @@ -467,13 +432,7 @@ Example: "amount": [ 5, 15 ] Example: [ 1, 3 ] - apply 1-3 times -#### 2.5 "lua" -**optional** lua script to run after all of the above finishes. See below. -> Value: "string" - -Example: "lua": "if game.one_in(5000) then\n map:square_ter(\"t_lava\", 3, 3, 20, 20)\n game.add_msg(\"Oh noes micro volcano ;.;\")\n end" - -# 2.6 specials +# 2.5 specials **optional** Special map features that do more than just placing furniture / terrain. Specials can be defined either via a mapping like the terrain / furniture mapping using the "rows" entry above or through their exact location by its coordinates. @@ -567,46 +526,46 @@ Same as } ``` -### 2.6.0 "fields" +### 2.5.0 "fields" Places a field (see fields.h). Values: - "field": (required, string) the field type (e.g. "fd_blood") - "density": (optional, integer) field density. Defaults to 1. Possible values are 1, 2, or 3. - "age": (optional, integer) field age. Defaults to 0. -### 2.6.1 "npcs" +### 2.5.1 "npcs" Places a new NPC. Values: - "class": (required, string) the npc class id, see data/json/npcs/npc.json or define your own npc class. -### 2.6.2 "signs" +### 2.5.2 "signs" Places a sign (furniture f_sign) with a message written on it. Either "signage" or "snippet" must be defined. The message may include tags like \, \, and \ that will insert a randomly generated name, or \ that will insert the nearest city name. Values: - "signage": (optional, string) the message that should appear on the sign. - "snippet": (optional, string) a category of snippets that can appear on the sign. -### 2.6.3 "vendingmachines" +### 2.5.3 "vendingmachines" Places a vending machine (furniture) and fills it with items. The machine can sometimes spawn as broken one. Values: - "item_group": (optional, string) the item group that is used to create items inside the machine. It defaults to either "vending_food" or "vending_drink" (randomly chosen). -### 2.6.4 "toilets" +### 2.5.4 "toilets" Places a toilet (furniture) and adds water to it. Values: - "amount": (optional, integer or min/max array) the amount of water to be placed in the toilet. -### 2.6.5 "gaspumps" +### 2.5.5 "gaspumps" Places a gas pump with gasoline (or sometimes diesel) in it. Values: - "amount": (optional, integer or min/max array) the amount of fuel to be placed in the pump. - "fuel": (optional, string: "gasoline" or "diesel") the type of fuel to be placed in the pump. -### 2.6.6 "items" +### 2.5.6 "items" Places items from an item group. Values: - "item": (required, string) the item group to use. - "chance": (optional, integer or min/max array) x in 100 chance that a loop will continue to spawn items from the group (which itself may spawn multiple items or not depending on its type, see `ITEM_SPAWN.md`), unless the chance is 100, in which case it will trigger the item group spawn exactly 1 time (see `map::place_items`). -### 2.6.7 "monsters" +### 2.5.7 "monsters" Places a monster spawn point, the actual monsters are spawned when the map is loaded. Values: - "monster": (required, string) a monster group id, when the map is loaded, a random monsters from that group are spawned. - "density": (optional, float) if defined, it overrides the default monster density at the location (monster density is bigger towards the city centers) (see `map::place_spawns`). - "chance": (optional, integer or min/max array) one in x chance of spawn point being created (see `map::place_spawns`). -### 2.6.8 "vehicles" +### 2.5.8 "vehicles" Places a vehicle. Values: - "vehicle": (required, string) type of the vehicle or id of a vehicle group. - "chance": (optional, integer or min/max array) x in 100 chance of the vehicle spawning at all. The default is 1 (which means 1% probability that the vehicle spawns, you probably want something larger). @@ -614,7 +573,7 @@ Places a vehicle. Values: - "fuel": (optional, integer) the fuel status. Default is -1 which makes the tanks 1-7% full. Positive values are interpreted as percentage of the vehicles tanks to fill (e.g. 100 means completely full). - "status": (optional, integer) default is -1 (light damage), a value of 0 means perfect condition, 1 means heavily damaged. -### 2.6.9 "item" +### 2.5.9 "item" Places a specific item. Values: - "item": (required, string) the item type id of the new item. - "chance": (optional, integer or min/max array) one in x chance that the item will spawn. Default is 1, meaning it will always spawn. @@ -630,25 +589,25 @@ To use this type with explicit coordinates use the name "place_item" (this if fo ] ``` -### 2.6.10 "traps" +### 2.5.10 "traps" Places a trap. Values: - "trap": (required, string) type id of the trap (e.g. tr_beartrap). -### 2.6.11 "furniture" +### 2.5.11 "furniture" Places furniture. Values: - "furn": (required, string) type id of the furniture (e.g. f_chair). -### 2.6.12 "terrain" +### 2.5.12 "terrain" Places terrain. Values: - "ter": (required, string) type id of the terrain (e.g. t_floor). -### 2.6.13 "monster" +### 2.5.13 "monster" Places a specific monster. Values: - "monster": (required, string) type id of the monster (e.g. mon_zombie). - "friendly": (optional, bool) whether the monster is friendly, default is false. - "name": (optional, string) a name for that monster, optional, default is to create an unnamed monster. -### 2.6.14 "rubble" +### 2.5.14 "rubble" Creates rubble and bashes existing terrain (this step is applied last, after other things like furniture/terrain have been set). Creating rubble invokes the bashing function that can destroy terrain and cause structures to collapse. Values: - "rubble_type": (optional, furniture id, default: f_rubble) the type of the created rubble. @@ -663,7 +622,7 @@ To use this type with explicit coordinates use the name "place_rubble" (no plura ] ``` -### 2.6.15 "place_liquids" +### 2.5.15 "place_liquids" Creates a liquid item at the specified location. Liquids can't currently be picked up (except for gasoline in tanks or pumps), but can be used to add flavor to mapgen. Values: - "liquid": (required, item id) the item (a liquid) @@ -680,7 +639,7 @@ Example for dropping a default amount of gasoline (200 units) on the ground (eit ], ``` -### 2.6.16 "loot" +### 2.5.16 "loot" Places item(s) from an item group, or an individual item. An important distinction between this and `place_item` and `item`/`items` is that `loot` can spawn a single item from a distribution group (without looping). It can also spawn a matching magazine and ammo for guns. - Either `group` or `item` must be specified, but not both - "group": (string) the item group to use (see `ITEM_SPAWN.md` for notes on collection vs distribution groups) @@ -689,7 +648,7 @@ Places item(s) from an item group, or an individual item. An important distincti - "ammo": (optional, integer) x in 100 chance of item(s) spawning with the default amount of ammo. Defaults to 0. - "magazine": (optional, integer) x in 100 chance of item(s) spawning with the default magazine. Defaults to 0. -### 2.6.17 "sealed_item" +### 2.5.17 "sealed_item" Places an item or item group inside furniture that has special handling for items. This is intended for furniture such as `f_plant_harvest` with the `PLANT` flag, because placing items on such furniture via the other means will not work (since they have the `NOITEM` FLAG). @@ -716,49 +675,3 @@ Rotates the generated map after all the other mapgen stuff has been done. The va "rotation": [ 0, 3 ], ``` Values are 90° steps. - -## 3 Method: lua -Lua is very WIP but supports the following map class functions: -# 3.0 Tested functions -``` -ter_set(x, y, "ter_id") -furn_set(x, y, "furn_id") -line_ter("ter_id", x, y, x2, y2) -line_furn("furn_id", x, y, x2, y2) -fill_background("ter_id") -square_ter("ter_id", x, y, x2, y2) -square_furn("furn_id", x, y, x2, y2) -rough_circle("ter_id", x, y, radius) -place_items("itype", chance, x, y, x2, y2, bool ongrass, int chance) -``` -## 3.1 Example script inside overmap_terrain entry -``` -{ "method": "lua", "weight": 500, "comment": "Inlined, easier to edit", "script": [ - "-- tertype, turn = ...", - "function g_or_d_or_p()", - " if game.one_in(6) then", - " return \"t_water_sh\"", - " end", - " if game.rng(1,4) == 1 then", - " return \"t_grass\"", - " end", - " return \"t_dirt\"", - "end", - "x = 0", - "while x < 24 do", - " y = 0", - " while y < 24 do", - " map:ter_set(x, y, g_or_d_or_p())", - " y = y + 1", - " end", - " x = x + 1", - "end", - "map:place_items(\"field\", 60, 0, 0, 23, 23, 1, turn)", - "--map:square_furn(\"f_mutpoppy\", 10,10,13,13)", - "--map:line_ter(\"t_paper\", 1, 1, 22, 22)", - "game.add_msg(\"generated oter=\"..tertype..\" turn=\"..turn)" - ] -}, -``` -Ideally there will also be a way to load a .lua file directly from the same directory as its mapgen definition - diff --git a/doc/sample_mods/drinkable_milk/main.lua b/doc/sample_mods/drinkable_milk/main.lua deleted file mode 100644 index c9cb69ec80543..0000000000000 --- a/doc/sample_mods/drinkable_milk/main.lua +++ /dev/null @@ -1,17 +0,0 @@ -local milk = game.get_comestible_type("milk") - --- if milk spoils in less than a day, make it last at least a day -if milk.spoils_in < 24 then - milk.spoils_in = 24 -end - --- set the volume to half, just to test that inheritance really works -milk.volume = milk.volume / 2 - --- access a few other things to test the wrappers -local pipe_rifle = game.get_gun_type("rifle_22") -pipe_rifle.ammo = "battery" -- hell yeah - -local welder = game.get_tool_type("welder") -welder.max_charges = 1000 -- why not? -welder.def_charges = 500 diff --git a/doc/sample_mods/drinkable_milk/modinfo.json b/doc/sample_mods/drinkable_milk/modinfo.json deleted file mode 100644 index f02e0f377a6d1..0000000000000 --- a/doc/sample_mods/drinkable_milk/modinfo.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "MOD_INFO", - "mod-type": "SUPPLEMENTAL", - "ident": "DrinkableMilk", - "name": "Drinkable Milk", - "description": "Makes it so milk doesn't spoil instantly upon arriving in the cataclysm.", - "path": "" -} - diff --git a/doc/sample_mods/elf_mod/data.json b/doc/sample_mods/elf_mod/data.json deleted file mode 100644 index 145ffa026d21e..0000000000000 --- a/doc/sample_mods/elf_mod/data.json +++ /dev/null @@ -1,39 +0,0 @@ -[ - { - "type" : "MONSTER", - "id" : "mon_elf", - "name": "elf", - "species":"ZOMBIE", - "symbol":"E", - "color":"white", - "size":"MEDIUM", - "material":"flesh", - "diff":0, - "aggression":50, - "morale":100, - "speed":120, - "melee_skill":10, - "melee_dice":4, - "melee_dice_sides":6, - "melee_cut":12, - "dodge":10, - "armor_bash":2, - "armor_cut":2, - "item_chance":0, - "luminance":0, - "hp":50, - "special_freq":0, - "death_function":"NORMAL", - "special_attack":"NONE", - "description":"This is an elf. Nobody knows what an elf is doing in the cataclysm.", - "flags":["SEES", "HEARS", "SMELLS", "STUMBLES", "WARM", "BASHES", "VIS40"], - "anger_triggers":["PLAYER_CLOSE", "HURT"] - },{ - "type":"monstergroup", - "name" : "GROUP_ELF", - "default" : "mon_elf", - "monsters" : [ - { "monster" : "mon_elf", "freq" : 300, "cost_multiplier" : 0 } - ] - } -] diff --git a/doc/sample_mods/elf_mod/main.lua b/doc/sample_mods/elf_mod/main.lua deleted file mode 100644 index 1754e4b772bd4..0000000000000 --- a/doc/sample_mods/elf_mod/main.lua +++ /dev/null @@ -1,21 +0,0 @@ -local MOD = {} - -mods["ElfMod"] = MOD - -function MOD.on_day_passed() - game.add_msg("A day has passed! New elves are spawning!") - - -- spawn monster group in top left corner - local overmap = g:get_cur_om() - local newgroup = game.create_monster_group(overmap, "GROUP_ELF", 5, 5, 0, 10, 2000) - newgroup.horde = true - - -- Elves multiply - for _, mongroup in pairs(game.monstergroups(overmap)) do - if mongroup.type == "GROUP_ELF" then - mongroup.population = mongroup.population + 1 - game.add_msg("The elves multiply, oh noes! Current elf count: "..tostring(mongroup.population)) - end - end -end - diff --git a/doc/sample_mods/elf_mod/modinfo.json b/doc/sample_mods/elf_mod/modinfo.json deleted file mode 100644 index 1159aa3be3a3f..0000000000000 --- a/doc/sample_mods/elf_mod/modinfo.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "MOD_INFO", - "mod-type": "SUPPLEMENTAL", - "ident": "Elf", - "name": "Elf Mod", - "description": "Elves spawn randomly in the cataclysm.", - "path": "" -} - diff --git a/doc/sample_mods/lua_manhack_iuse/modinfo.json b/doc/sample_mods/lua_manhack_iuse/modinfo.json deleted file mode 100644 index 9bafb310b22d8..0000000000000 --- a/doc/sample_mods/lua_manhack_iuse/modinfo.json +++ /dev/null @@ -1,8 +0,0 @@ - { - "type": "MOD_INFO", - "mod-type": "SUPPLEMENTAL", - "ident": "Manhack_Lua", - "name": "Manhack Lua", - "description": "Manhack IUSE implemented in lua.", - "path": "" - } diff --git a/doc/sample_mods/lua_manhack_iuse/preload.lua b/doc/sample_mods/lua_manhack_iuse/preload.lua deleted file mode 100644 index f0214e2075949..0000000000000 --- a/doc/sample_mods/lua_manhack_iuse/preload.lua +++ /dev/null @@ -1,31 +0,0 @@ -function pick_from_list(list) - local rand = math.random(1, #list) - return list[rand] -end - -function iuse_manhack(item, active) - -- find a bunch of locations where we might spawn the manhack - local locs = {} - for delta_x = -1, 1 do - for delta_y = -1, 1 do - local point = player:pos() - point.x = point.x + delta_x - point.y = point.y + delta_y - if g:is_empty(point) then - table.insert(locs, point ) - end - end - end - - if #locs == 0 then - game.add_msg("You can't use this here!") - return 0 -- 0 charges used - end - - -- okay, we got a bunch of locations, pick one and spawn a manhack there - local loc = pick_from_list(locs) - local monster = game.create_monster(mtype_id("mon_manhack"), loc) - return 1 -- 1 charge used -end - -game.register_iuse("IUSE_LUA_MANHACK", iuse_manhack) diff --git a/doc/sample_mods/lua_manhack_iuse/tools.json b/doc/sample_mods/lua_manhack_iuse/tools.json deleted file mode 100644 index 682d1cdf67bdb..0000000000000 --- a/doc/sample_mods/lua_manhack_iuse/tools.json +++ /dev/null @@ -1,24 +0,0 @@ -[ - { - "id": "bot_manhack_lua", - "type": "TOOL", - "symbol": ",", - "color": "light_green", - "name": "inactive manhack(lua)", - "description": "This is an inactive manhack. Manhacks are fist-sized robots that fly through the air. They are covered with whirring blades and attack by throwing themselves against their target. Use this item to activate the manhack.", - "price": 60000, - "material": ["aluminum", "plastic"], - "weight": 300, - "volume": 1, - "bashing": 6, - "cutting": 6, - "to_hit": -3, - "max_charges": 0, - "initial_charges": 0, - "charges_per_use": 0, - "turns_per_charge": 0, - "ammo": "NULL", - "revert_to": "null", - "use_action": "IUSE_LUA_MANHACK" - } -] diff --git a/doc/sample_mods/lua_player_takeoff/items.json b/doc/sample_mods/lua_player_takeoff/items.json deleted file mode 100644 index 3f4199686791c..0000000000000 --- a/doc/sample_mods/lua_player_takeoff/items.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "id":"test_ptakeoff", - "type": "TOOL", - "symbol": "?", - "color": "white", - "name": "Test_Takeoff", - "category": "ZZZ", - "description": "Activate this to remove whatever item is just below your wielded item.", - "bashing": 1, - "price": 1, - "material": ["plastic"], - "weight": 1, - "volume": 1, - "use_action": ["PLAYERTAKEOFF"] - } -] diff --git a/doc/sample_mods/lua_player_takeoff/modinfo.json b/doc/sample_mods/lua_player_takeoff/modinfo.json deleted file mode 100644 index 14797bc965e9f..0000000000000 --- a/doc/sample_mods/lua_player_takeoff/modinfo.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "type": "MOD_INFO", - "mod-type": "SUPPLEMENTAL", - "ident": "LuaPlayerTakeoff", - "name": "Lua Test: Player:takeoff", - "description": "This makes an item named Test_Takeoff that calls player:takeoff(player:iat(-2)) and removes a single item just below the wielded weapon. Not using -1 because that is wielded weapon slot, and this won't work for that slot.", - "path": "" -} diff --git a/doc/sample_mods/lua_player_takeoff/preload.lua b/doc/sample_mods/lua_player_takeoff/preload.lua deleted file mode 100644 index 5ed665a0fcb41..0000000000000 --- a/doc/sample_mods/lua_player_takeoff/preload.lua +++ /dev/null @@ -1,14 +0,0 @@ -local MOD = {} - -mods["LUAPlayerTakeoff"] = MOD - -function playertakeoff() - if (player:i_at(-2):display_name() ~= "none") then - game.add_msg("Taking off: "..player:i_at(-2):display_name()) - player:takeoff(player:i_at(-2)) - else - game.add_msg("Nothing in that slot!") - end -end - -game.register_iuse("PLAYERTAKEOFF", playertakeoff) diff --git a/doc/sample_mods/lua_test_activity/main.lua b/doc/sample_mods/lua_test_activity/main.lua deleted file mode 100644 index e0308cd80cd03..0000000000000 --- a/doc/sample_mods/lua_test_activity/main.lua +++ /dev/null @@ -1,16 +0,0 @@ -local MOD = {} -mods["lua_test_activity"] = MOD - -function message(...) - local s = string.format(...) - game.add_msg(s) -end - -function MOD.on_minute_passed() - local act = player.activity - if not act:is_null() then - -- Show your current activity - message("activity_id: %s", act:id():str()) - message("moves_left: %d", act.moves_left) - end -end diff --git a/doc/sample_mods/lua_test_activity/modinfo.json b/doc/sample_mods/lua_test_activity/modinfo.json deleted file mode 100644 index e18e85f4db4fa..0000000000000 --- a/doc/sample_mods/lua_test_activity/modinfo.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "type": "MOD_INFO", - "ident": "lua_test_activity", - "name": "Lua sample code: Player activity", - "description": "Sample code of player activity.", - "category": "content", - "dependencies": ["dda"] - } -] diff --git a/doc/sample_mods/lua_test_bionics/actions.json b/doc/sample_mods/lua_test_bionics/actions.json deleted file mode 100644 index 6ebbf5c40d91d..0000000000000 --- a/doc/sample_mods/lua_test_bionics/actions.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "type": "item_action", - "id": "TEST_BIONICS_LIST", - "name": "Show your bionics" - } -] diff --git a/doc/sample_mods/lua_test_bionics/items.json b/doc/sample_mods/lua_test_bionics/items.json deleted file mode 100644 index 099d51f07418d..0000000000000 --- a/doc/sample_mods/lua_test_bionics/items.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "id": "test_bionics_list", - "type": "TOOL", - "symbol": "?", - "color": "white", - "name": "Bionics List(LUA)", - "description": "Show your bionics list.", - "material": ["plastic"], - "use_action": ["TEST_BIONICS_LIST"] - } -] diff --git a/doc/sample_mods/lua_test_bionics/modinfo.json b/doc/sample_mods/lua_test_bionics/modinfo.json deleted file mode 100644 index a35aba55eabd4..0000000000000 --- a/doc/sample_mods/lua_test_bionics/modinfo.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "type": "MOD_INFO", - "ident": "lua_test_bionics", - "name": "Lua sample code: Bionics", - "description": "Sample code of bionics related functions.", - "category": "content", - "dependencies": ["dda"] - } -] diff --git a/doc/sample_mods/lua_test_bionics/preload.lua b/doc/sample_mods/lua_test_bionics/preload.lua deleted file mode 100644 index 89dc85ac95367..0000000000000 --- a/doc/sample_mods/lua_test_bionics/preload.lua +++ /dev/null @@ -1,27 +0,0 @@ -function message(...) - local s = string.format(...) - game.add_msg(s) -end - -function iuse_test_bionics_list() - local num = player:num_bionics() - if num == 0 then - message("You installed no bionics.") - else - local i = 0 - while i < num do - -- Get bionic reference - local bio = player:bionic_at_index(i) - -- Get bionic_data reference (use obj() function of bionic_id class) - local bio_data = bio.id:obj() - local color = "white" - if bio_data.activated then - color = "green" - end - message("bionics[%d]: %s", i, color, bio_data.name) - i = i + 1 - end - end -end - -game.register_iuse("TEST_BIONICS_LIST", iuse_test_bionics_list) diff --git a/doc/sample_mods/lua_test_callback/main.lua b/doc/sample_mods/lua_test_callback/main.lua deleted file mode 100644 index e31ccd5126088..0000000000000 --- a/doc/sample_mods/lua_test_callback/main.lua +++ /dev/null @@ -1,142 +0,0 @@ -local MOD = { - id = "lua_test_callback", - version = "2019-01-06" -} -mods[MOD.id] = MOD - -MOD.MessageWithLog = function(s) - if log.message then - log.message(s) - end - if game.add_msg then - game.add_msg(s) - end -end - -MOD.on_game_loaded = function() - MOD.DisplayCallbackMessages("on_game_loaded") -end - -MOD.on_savegame_loaded = function() - MOD.DisplayCallbackMessages("on_savegame_loaded") -end - -MOD.on_new_player_created = function(player_id) - MOD.DisplayCallbackMessages("on_new_player_created", player_id) -end - -MOD.on_turn_passed = function() - MOD.DisplayCallbackMessages("on_turn_passed") -end - -MOD.on_second_passed = function() - MOD.DisplayCallbackMessages("on_second_passed") -end - -MOD.on_minute_passed = function() - MOD.DisplayCallbackMessages("on_minute_passed") -end - -MOD.on_hour_passed = function() - MOD.DisplayCallbackMessages("on_hour_passed") -end - -MOD.on_day_passed = function() - MOD.DisplayCallbackMessages("on_day_passed") -end - -MOD.on_year_passed = function() - MOD.DisplayCallbackMessages("on_year_passed") -end - -MOD.on_weather_changed = function(weather_new, weather_old) - MOD.DisplayCallbackMessages("on_weather_changed", weather_new, weather_old) -end - -MOD.on_player_skill_increased = function(player_id, source, skill_id, level) - MOD.DisplayCallbackMessages("on_player_skill_increased", player_id, source, skill_id, level) -end - -MOD.on_player_dodge = function(player_id, source, difficulty) - MOD.DisplayCallbackMessages("on_player_dodge", player_id, source, difficulty) -end - -MOD.on_player_hit = function(player_id, source, bodypart) --[[dealt_projectile_attack]]-- - MOD.DisplayCallbackMessages("on_player_hit", player_id, source, bodypart) -end - -MOD.on_player_hurt = function(player_id, source, disturb) - MOD.DisplayCallbackMessages("on_player_hurt", player_id, source, disturb) -end - -MOD.on_player_mutation_gain = function(player_id, mutation_id) - MOD.DisplayCallbackMessages("on_player_mutation_gain", player_id, mutation_id) -end - -MOD.on_player_mutation_loss = function(player_id, mutation_id) - MOD.DisplayCallbackMessages("on_player_mutation_loss", player_id, mutation_id) -end - -MOD.on_player_stat_change = function(player_id, stat_id, stat_value) - MOD.DisplayCallbackMessages("on_player_stat_change", player_id, stat_id, stat_value) -end - -MOD.on_player_item_wear = function(player_id, item_id) - MOD.DisplayCallbackMessages("on_player_item_wear", player_id, item_id) -end - -MOD.on_player_item_takeoff = function(player_id, item_id) - MOD.DisplayCallbackMessages("on_player_item_takeoff", player_id, item_id) -end - -MOD.on_player_effect_int_changes = function(player_id, effect_id, intensity, bodypart) - MOD.DisplayCallbackMessages("on_player_effect_int_change", player_id, effect_id, intensity, bodypart) -end - -MOD.on_player_mission_assignment = function(player_id, mission_id) - MOD.DisplayCallbackMessages("on_player_mission_assignment", player_id, mission_id) -end - -MOD.on_player_mission_finished = function(player_id, mission_id) - MOD.DisplayCallbackMessages("on_player_mission_finished", player_id, mission_id) -end - -MOD.on_activity_call_do_turn_started = function(act_id, player_id) - MOD.DisplayCallbackMessages("on_activity_call_do_turn_started", act_id, player_id) -end - -MOD.on_activity_call_do_turn_finished = function(act_id, player_id) - MOD.DisplayCallbackMessages("on_activity_call_do_turn_finished", act_id, player_id) -end - -MOD.on_activity_call_finish_started = function(act_id, player_id) - MOD.DisplayCallbackMessages("on_activity_call_finish_started", act_id, player_id) -end - -MOD.on_activity_call_finish_finished = function(act_id, player_id) - MOD.DisplayCallbackMessages("on_activity_call_finish_finished", act_id, player_id) -end - -MOD.on_mapgen_finished = function(mapgen_type, mapgen_id, mapgen_coord) - MOD.DisplayCallbackMessages("on_mapgen_finished", mapgen_type, mapgen_id, mapgen_coord) -end - -MOD.DisplayCallbackMessages = function(callback_name, ...) - - MOD.MessageWithLog ("Callback name is "..tostring(callback_name).."") - local callback_args = {...} - local callback_args_count = #callback_args - if callback_args_count > 0 then - MOD.MessageWithLog ("Callback data length is "..tostring(callback_args_count).."") - for i = 1, callback_args_count do - local callback_arg_name = "callback_arg_"..i - local callback_arg_data = callback_args[i] - local callback_arg_type = type(callback_arg_data) - MOD.MessageWithLog ("Callback arg "..tostring(callback_arg_name).." is "..tostring(callback_arg_data).." of type "..tostring(callback_arg_type).."") - end - else - MOD.MessageWithLog ("Callback args are empty") - end -end - -MOD.on_game_loaded() diff --git a/doc/sample_mods/lua_test_callback/modinfo.json b/doc/sample_mods/lua_test_callback/modinfo.json deleted file mode 100644 index 36cb49856e8b9..0000000000000 --- a/doc/sample_mods/lua_test_callback/modinfo.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "type": "MOD_INFO", - "ident": "lua_test_callback", - "name": "Dark Days Ahead: Lua Test: Callback", - "description": "Test of all callback Lua functions.", - "category": "content", - "dependencies": [ "dda" ], - "//": "Put mod into `./data/mods/lua_test_callback/` folder" - } -] diff --git a/doc/sample_mods/lua_test_callback/preload.lua b/doc/sample_mods/lua_test_callback/preload.lua deleted file mode 100644 index ad08096ea2b71..0000000000000 --- a/doc/sample_mods/lua_test_callback/preload.lua +++ /dev/null @@ -1,4 +0,0 @@ -local MOD = { - id = "lua_test_callback", - version = "2019-01-06" -} diff --git a/doc/sample_mods/lua_test_morale/actions.json b/doc/sample_mods/lua_test_morale/actions.json deleted file mode 100644 index 924aea388f142..0000000000000 --- a/doc/sample_mods/lua_test_morale/actions.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "type": "item_action", - "id": "TEST_GAIN_MORALE", - "name": "Gain morale! (+100)" - } -] diff --git a/doc/sample_mods/lua_test_morale/items.json b/doc/sample_mods/lua_test_morale/items.json deleted file mode 100644 index bdbd62bf7e7c7..0000000000000 --- a/doc/sample_mods/lua_test_morale/items.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "id": "test_gain_morale", - "type": "TOOL", - "symbol": "?", - "color": "white", - "name": "Gain morale(LUA)", - "description": "You gain big morale boost.", - "material": ["plastic"], - "use_action": ["TEST_GAIN_MORALE"] - } -] diff --git a/doc/sample_mods/lua_test_morale/modinfo.json b/doc/sample_mods/lua_test_morale/modinfo.json deleted file mode 100644 index 430c98c61b899..0000000000000 --- a/doc/sample_mods/lua_test_morale/modinfo.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "type": "MOD_INFO", - "ident": "lua_test_morale", - "name": "Lua sample code: Morale", - "description": "Sample code of morale related functions.", - "category": "content", - "dependencies": ["dda"] - } -] diff --git a/doc/sample_mods/lua_test_morale/morales.json b/doc/sample_mods/lua_test_morale/morales.json deleted file mode 100644 index 1cd382997f13b..0000000000000 --- a/doc/sample_mods/lua_test_morale/morales.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "id": "morale_test", - "type": "morale_type", - "text": "Gain big morale boost!" - } -] diff --git a/doc/sample_mods/lua_test_morale/preload.lua b/doc/sample_mods/lua_test_morale/preload.lua deleted file mode 100644 index aeeeaf09c7f30..0000000000000 --- a/doc/sample_mods/lua_test_morale/preload.lua +++ /dev/null @@ -1,34 +0,0 @@ -function message(...) - local s = string.format(...) - game.add_msg(s) -end - -function iuse_test_gain_morale() - -- Create select menu - local um = game.create_uimenu() - um.title = "Gain morale menu" - um:addentry("Gain morale") - um:addentry("Remove morale") - um:addentry("Cancel") - -- Wait for player selection - um:query(true) - - if um.selected == 0 then - -- "Gain morale" is selected - if player:has_morale(morale_type("morale_test")) == 0 then - -- Add morale boost (+100/10 min.) - player:add_morale(morale_type("morale_test"), 100, 100, MINUTES(10)) - message("You gained big morale boost!") - else - message("You already gained morale boost.") - end - elseif um.selected == 1 then - -- "Remove morale" is selected - player:rem_morale(morale_type("morale_test")) - message("Your morale boost is finished.") - end - - return 0 -end - -game.register_iuse("TEST_GAIN_MORALE", iuse_test_gain_morale) diff --git a/doc/sample_mods/lua_test_npc/actions.json b/doc/sample_mods/lua_test_npc/actions.json deleted file mode 100644 index 1cf1a9ee8b603..0000000000000 --- a/doc/sample_mods/lua_test_npc/actions.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "type": "item_action", - "id": "TEST_NPC", - "name": "Test NPC function" - } -] diff --git a/doc/sample_mods/lua_test_npc/items.json b/doc/sample_mods/lua_test_npc/items.json deleted file mode 100644 index d7493cf8eff8b..0000000000000 --- a/doc/sample_mods/lua_test_npc/items.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "id": "test_npc", - "type": "TOOL", - "symbol": "?", - "color": "white", - "name": "NPC test(LUA)", - "description": "You check NPC's opinion.", - "material": ["plastic"], - "use_action": ["TEST_NPC"] - } -] diff --git a/doc/sample_mods/lua_test_npc/modinfo.json b/doc/sample_mods/lua_test_npc/modinfo.json deleted file mode 100644 index 183659185377c..0000000000000 --- a/doc/sample_mods/lua_test_npc/modinfo.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "type": "MOD_INFO", - "ident": "lua_test_npc", - "name": "Lua sample code: NPC", - "authors": [ "LISP" ], - "maintainers": [ "LISP" ], - "description": "Sample code of NPC related functions.", - "category": "misc_additions", - "dependencies": [ "dda" ] - } -] diff --git a/doc/sample_mods/lua_test_npc/preload.lua b/doc/sample_mods/lua_test_npc/preload.lua deleted file mode 100644 index 733ad622884a7..0000000000000 --- a/doc/sample_mods/lua_test_npc/preload.lua +++ /dev/null @@ -1,76 +0,0 @@ -function message(...) - local s = string.format(...) - game.add_msg(s) -end - -function iuse_test_npc(item, active) - local um - local feature - - -- Create select menu - um = game.create_uimenu() - um.title = "What do you do?" - um:addentry("Check NPC's opinion") - um:addentry("Make NPC angry") - um:addentry("Make NPC your follower") - um:addentry("Cancel") - -- Wait for player selection - um:query(true) - - if um.selected == 3 then - -- Canceled - return 0 - end - feature = um.selected - - local p = player:pos() - local delta_x - local delta_y - local npc_num = 0 - local npcs = {} - local npc - - -- Create select menu - um = game.create_uimenu() - um.title = "Select NPC" - -- Search NPCs around you - for delta_x = -1, 1 do - for delta_y = -1, 1 do - local tp = tripoint(p.x + delta_x, p.y + delta_y, p.z) - npc = game.get_npc_at(tp) - if npc then - um:addentry(npc:get_name()) - table.insert(npcs, npc) - npc_num = npc_num + 1 - end - end - end - um:addentry("Cancel") - -- Wait for player selection - um:query(true) - - if um.selected == npc_num then - -- Canceled - return 0 - end - - local target = npcs[um.selected + 1] - if feature == 0 then - local opinion = target.op_of_u - message("Trust: %d", opinion.trust) - message("Fear: %d", opinion.fear) - message("Value: %d", opinion.value) - message("Anger: %d", opinion.anger) - message("Owed: %d", opinion.owed) - elseif feature == 1 then - target:make_angry() - message("%s gets angry!", target:disp_name()) - elseif feature == 2 then - target:set_attitude("NPCATT_FOLLOW") - message("%s is your follower now.", target:disp_name()) - end - - return 0 -end - -game.register_iuse("TEST_NPC", iuse_test_npc) diff --git a/doc/sample_mods/monster_special_attack/modinfo.json b/doc/sample_mods/monster_special_attack/modinfo.json deleted file mode 100644 index f9d7bcd185c31..0000000000000 --- a/doc/sample_mods/monster_special_attack/modinfo.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "type": "MOD_INFO", - "ident": "MonsterSpecialAttackTest", - "name": "Lua Test: Monster Special Attack", - "description": "This adds Lua-coded special attack. Zombies say hello.", - "path": "" - } -] diff --git a/doc/sample_mods/monster_special_attack/monster.json b/doc/sample_mods/monster_special_attack/monster.json deleted file mode 100644 index 39ad942978770..0000000000000 --- a/doc/sample_mods/monster_special_attack/monster.json +++ /dev/null @@ -1,45 +0,0 @@ -[ - { - "id": "mon_zombie_test", - "type": "MONSTER", - "name": "zombie(lua)", - "description": "A human body, swaying as it moves, an unstoppable rage is visible in its oily black eyes.", - "default_faction": "zombie", - "categories": [ "CLASSIC" ], - "species": [ "ZOMBIE", "HUMAN" ], - "diff": 3, - "size": "MEDIUM", - "hp": 80, - "speed": 70, - "material": [ "flesh" ], - "symbol": "Z", - "color": "light_green", - "aggression": 100, - "morale": 100, - "melee_skill": 4, - "melee_dice": 2, - "melee_dice_sides": 3, - "melee_cut": 0, - "vision_night": 3, - "special_attacks": [ [ "SAY_HELLO", 1 ] ], - "death_drops": "default_zombie_death_drops", - "death_function": [ "NORMAL" ], - "burn_into": "mon_zombie_scorched", - "upgrades": { "half_life": 28, "into_group": "GROUP_ZOMBIE_UPGRADE" }, - "flags": [ - "SEES", - "HEARS", - "SMELLS", - "STUMBLES", - "WARM", - "BASHES", - "GROUP_BASH", - "POISON", - "BLEED", - "NO_BREATHE", - "REVIVES", - "BONES", - "PUSH_MON" - ] - } -] diff --git a/doc/sample_mods/monster_special_attack/preload.lua b/doc/sample_mods/monster_special_attack/preload.lua deleted file mode 100644 index 4da13005f060c..0000000000000 --- a/doc/sample_mods/monster_special_attack/preload.lua +++ /dev/null @@ -1,10 +0,0 @@ -local MOD = {} - -mods["MonsterSpecialAttackTest"] = MOD - -function say_hello(monster) - game.add_msg(monster:disp_name()..": Hello!") - return true; -end - -game.register_monattack("SAY_HELLO", say_hello) diff --git a/doc/sample_mods/no_jam_spawn/main.lua b/doc/sample_mods/no_jam_spawn/main.lua deleted file mode 100644 index 048175350e505..0000000000000 --- a/doc/sample_mods/no_jam_spawn/main.lua +++ /dev/null @@ -1,15 +0,0 @@ -function blacklist_item_from_spawns(id) - local all_groups = game.get_item_groups() - for _, group_id in ipairs(all_groups) do - -- a chance of 0 removes the item - game.add_item_to_group(group_id, id, 0) - end -end - -blacklist_item_from_spawns("jam_strawberries") -blacklist_item_from_spawns("jam_blueberries") - --- also remove rocks from spawn, since it's rather hard to test whether --- jams spawn or not ;) rock recipes should still exist though, leading --- to hilarity -blacklist_item_from_spawns("rock") diff --git a/doc/sample_mods/no_jam_spawn/modinfo.json b/doc/sample_mods/no_jam_spawn/modinfo.json deleted file mode 100644 index 2163dbbe71850..0000000000000 --- a/doc/sample_mods/no_jam_spawn/modinfo.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "MOD_INFO", - "mod-type": "SUPPLEMENTAL", - "ident": "NoJamSpawn", - "name": "No Jam Spawn", - "description": "Prevents jam from spawning, but you can still make it.", - "path": "" -} - diff --git a/lua/CMakeLists.txt b/lua/CMakeLists.txt deleted file mode 100644 index 0252804704eab..0000000000000 --- a/lua/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# LUA files + test -cmake_minimum_required(VERSION 2.8.12) - -SET(CATACLYSM_DDA_LUA_SOURCES - ${CMAKE_SOURCE_DIR}/lua/class_definitions.lua - ${CMAKE_SOURCE_DIR}/lua/autoexec.lua -) - -# test chain -add_custom_target ( - check_lua - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -add_custom_command ( - TARGET check_lua - PRE_BUILD - COMMAND ${LUA_BINARY} lua/json_verifier.lua - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -IF(RELEASE) - install(FILES ${CATACLYSM_DDA_LUA_SOURCES} DESTINATION ${DATA_PREFIX}/lua) -ENDIF(RELEASE) diff --git a/lua/autoexec.lua b/lua/autoexec.lua deleted file mode 100644 index 6422a5c2681be..0000000000000 --- a/lua/autoexec.lua +++ /dev/null @@ -1,93 +0,0 @@ ---dofile("./class_definitions.lua") - -package.path = package.path .. ";./lua/?.lua" --Windows/Linux -package.path = package.path .. ";/usr/share/cataclysm-dda/lua/?.lua" --Linux(via make install) -package.path = package.path .. ";/storage/emulated/0/Android/data/com.cleverraven.cataclysmdda/files/lua/?.lua" --Android -package.path = package.path .. ";/storage/sdcard/Android/data/com.cleverraven.cataclysmdda/files/lua/?.lua" --Android (SD Card) -package.path = package.path .. ";/storage/sdcard0/Android/data/com.cleverraven.cataclysmdda/files/lua/?.lua" --Android (SD Card 0) -package.path = package.path .. ";/storage/sdcard1/Android/data/com.cleverraven.cataclysmdda/files/lua/?.lua" --Android (SD Card 1) - -log = require("log") -log.init("./config/lua-log.log") - -outdated_metatable = { - __index = function(userdata, key) - error("Attempt to access outdated gamedata.") - end, - - __newindex = function(table, key, value) - error("Attempt to access outdated gamedata.") - end -} - --- table containing our mods -mods = { } - -function mod_callback(callback_name, ...) - rval = nil - for modname, mod_instance in pairs(mods) do - if type(mod_instance[callback_name]) == "function" then - rval = mod_instance[callback_name](...) - end - end - return rval -end - -function resolve_name(name) - local a = _G - for key in string.gmatch(name, "([^%.]+)(%.?)") do - if a[key] then - a = a[key] - else - return nil - end - end - return a -end - -function function_exists(name) - return type(resolve_name(name)) == 'function' -end - -function table_length(name) - local length = 0 - if (name ~= nil) then - for _ in pairs(name) do - length = length + 1 - end - end - return length -end - --- Constructs `time_duration` with given `int` value (which is number of turns). -function TURNS(turns) - if( function_exists( "game.get_time_duration" ) ) then - return game.get_time_duration( turns ) - else - return nil - end -end - -function MINUTES(turns) - if( function_exists( "game.get_time_duration" ) ) then - return game.get_time_duration( turns * 10 ) - else - return nil - end -end - -function HOURS(turns) - if( function_exists( "game.get_time_duration" ) ) then - return game.get_time_duration( turns * 10 * 60 ) - else - return nil - end -end - -function DAYS(turns) - if( function_exists( "game.get_time_duration" ) ) then - return game.get_time_duration( turns * 10 * 60 * 24 ) - else - return nil - end -end diff --git a/lua/class_definitions.lua b/lua/class_definitions.lua deleted file mode 100644 index d78759fee1a94..0000000000000 --- a/lua/class_definitions.lua +++ /dev/null @@ -1,2449 +0,0 @@ ---[[ -Defines which attributes are exported by our C++ classes. The required C functions (used as -callbacks from Lua) are automatically generated by src/lua/generate_bindings.lua - -The classes table contains all classes that will be accessible in Lua. The key is the name -of the class in C++. Keep in mind that it has to be a valid Lua identifiers, you can add a -typedef in catalua.cpp, e.g. `using cppstring = std::string;`, than add a class with the name -`cppstring` here. It maps to a table with the following values: - -Each class requires at least the attributes and the functions table (they can be empty). -Optional values are: -- by_value (boolean, default: false): if true, copy the C++ object into memory managed by Lua - (the copy may outlive the source C++ object), otherwise only a pointer to the C++ object - is stored in Lua and it *needs* to stay valid in C++ until the Lua object is gone. -- by_value_and_reference (boolean, default: false): if true, the class is can be exported to Lua - as value (copy of the object, managed by Lua) *and* as reference (to an object managed by C++ - code). This flag implies "by_value", "by_value" should therefor not be specified explicitly. -- has_equal (boolean, default: false): If true, generate the __eq entry in the metatable which - will map to the C++ using the operator==. -- new (an array of parameter lists): defines the constructor of the object. This is only useful for - by_value objects, it allows to create an instance of it in Lua. The entry should be an array, - each element of it represents one overload of the constructor. Each element should be a list of - parameters to those overloads (same as the list of arguments to member functions). -- int_id (optional, a string): if the class has an associated int_id (e.g. ter_t has int_id, - which is typedefed to ter_id), this can be used to define that int_id (for ter_t is should be - "ter_id"). At the end of this file, this will be used to create an actual entry in the classes - table for the type name given here. - This is done because all the int_id objects have essentially the same functions. - -The attributes table contains the members of the C++ class. Each key is the name of the member, -it maps to a map with the following values: -- cpp_name (defaults to the name of the member): an alternatively name for the member, - used only in the C++ part of the wrapper. -- writable (boolean, default: false): if true, a wrapper to set the member is generated (otherwise - only the getter is generated and the member is effectively read-only). -- type (required): the type of the member (see below). - -The functions table contains the member functions of the C++ class. Each entry (no keys, it's an -array) should have the following values: -- name (required, string): the name of the function as it appears in Lua. -- cpp_name (defaults to the name of the function, string): an alternatively name for the function, - used only in the C++ part of the wrapper. -- args (an array of strings): the types (see below) of the parameters to the function (in order). -- rval (can be nil when the function returns void): the type (see below) that the function returns. - -The global_functions table is basically the same as the class functions table, but it has -(currently) the function name as key of the table (this disallows function overloading, and should -be considered a bug). TODO: fix it - -Types can be built in types: int, float, bool, string (std::string in C++), cstring (const char* in C++) -Or any class defined in the classes table. - -Regarding reference and the by_value setting: -Instances of the itype class are created by C++ (specifically by the Item_factory). They are -never created elsewhere and once created each instance will stay valid (and at the same address) -until the game has ended. Furthermore it's actually important that each item id maps to exactly -one instance of itype. Similar for mtype. -Therefor those objects are exported as pointer only (by_value is false). - -Other objects (e.g. tripoint) can be constructed as values in Lua (by_value is true). - -The return value of functions ("rval") behaves a bit special: -- If it ends with a '&', as in `rval = "item&"`, it is assumed the function returns a reference. - The by_value setting will determine whether to copy the referred object (to Lua memory), or - to store only a reference in Lua memory. - Using '&' on native Lua types is not allowed. -- If the return type is a class type (has an entry in classes), it is copied to Lua memory. This - will fail (when the generated bindings are compiled or when they get linked) if the type does not - support copying. One should either add `by_value = true` or `by_value_and_reference = true` to the type. -- Otherwise it should be a native Lua type, which will be copied. - -Example: (Creature::pos returns a const reference to tripoint, game::zombie returns a reference to monster) -`local m = game.zombie(0)` stores a pointer to the monster returned by `game::zombie(0)`. This reference -must not be used after the monster has been removed from the game (e.g. because it died). Calling -the function again will give the very same pointer: -`local n = game.zombie(0)` -`m.setpos(tripoint(10,0,0))` This also affects `n` because `m` and `n` are pointers to the very -same C++ object. -`local p = some_monster:pos()` stores a copy of the result of `some_monster.pos()` in `p`. This -variable can be used long after `some_monster` has been killed and removed from the game. It has -no connection at all to the monster. ---]] - -classes = { - gun_mode = { - string_id = "gun_mode_id", - attributes = { - }, - functions = { - } - }, - effect_type = { - string_id = "efftype_id", - attributes = { - }, - functions = { - } - }, - calendar = { - new = { - { "calendar" }, - { "int" }, - { "int", "int", "int", "season_type", "int" }, - }, - by_value_and_reference = true, - attributes = { - before_time_starts = { type = "time_point", writable = false }, - time_of_cataclysm = { type = "time_point", writable = false }, - }, - functions = { - { name = "eternal_season", rval = "bool", args = { } }, - { name = "year_length", rval = "time_duration", args = { } }, - { name = "season_length", rval = "time_duration", args = { } }, - { name = "season_ratio", rval = "float", args = { } }, - { name = "season_from_default_ratio", rval = "float", args = { } }, - { name = "name_season", rval = "string", args = { "season_type" } }, - { name = "day_of_year", rval = "int", args = { } }, - { name = "get_turn", rval = "int", cpp_name = "operator int", args = { } }, - { name = "increment", rval = nil, args = { } }, - { name = "is_night", rval = "bool", args = { } }, - { name = "sunlight", rval = "float", args = { } }, - { name = "years", rval = "int", args = { } }, - { name = "sunset", rval = "calendar", args = { } }, - { name = "sunrise", rval = "calendar", args = { } }, - } - }, - mutation_branch = { - string_id = "trait_id", - attributes = { - activated = { type = "bool", writable = true }, - bodytemp_max = { type = "int", writable = true }, - bodytemp_min = { type = "int", writable = true }, - bodytemp_sleep = { type = "int", writable = true }, - cooldown = { type = "int", writable = true }, - cost = { type = "int", writable = true }, - fatigue = { type = "bool", writable = true }, - hunger = { type = "bool", writable = true }, - mixed_effect = { type = "bool", writable = true }, - points = { type = "int", writable = true }, - profession = { type = "bool", writable = true }, - purifiable = { type = "bool", writable = true }, - startingtrait = { type = "bool", writable = true }, - thirst = { type = "bool", writable = true }, - threshold = { type = "bool", writable = true }, - ugliness = { type = "int", writable = true }, - valid = { type = "bool", writable = true }, - visibility = { type = "int", writable = true }, - }, - functions = { - { name = "name", rval = "string", args = { } }, - { name = "desc", rval = "string", args = { } }, - { name = "get_display_color", rval = "nc_color", args = { } }, - } - }, - Character = { - parent = "Creature", - attributes = { - dex_cur = { type = "int", writable = true }, - dex_max = { type = "int", writable = true }, - int_cur = { type = "int", writable = true }, - int_max = { type = "int", writable = true }, - per_cur = { type = "int", writable = true }, - per_max = { type = "int", writable = true }, - str_cur = { type = "int", writable = true }, - str_max = { type = "int", writable = true }, - male = { type = "bool", writable = true }, - name = { type = "string", writable = true }, - nv_cached = { type = "bool", writable = true }, - weapon = { type = "item", writable = true }, - }, - functions = { - { name = "add_traits", rval = nil, args = { } }, - { name = "aim_per_move", rval = "float", args = { "item", "float" } }, - { name = "bloodType", rval = "field_id", args = { } }, - { name = "can_pickVolume", rval = "bool", args = { "item" }, optional_args = { "bool" } }, - { name = "can_pickWeight", rval = "bool", args = { "item" }, optional_args = { "bool" } }, - { name = "can_use", rval = "bool", args = { "item" }, optional_args = { "item" } }, - { name = "die", rval = nil, args = { "Creature" } }, - { name = "empty_skills", rval = nil, args = { } }, - { name = "empty_traits", rval = nil, args = { } }, - { name = "get_dodge_base", rval = "float", args = { } }, - { name = "get_hit_base", rval = "float", args = { } }, - { name = "get_item_position", rval = "int", args = { "item" } }, - { name = "get_name", rval = "string", args = { } }, - { name = "get_time_died", rval = "time_point", args = { } }, - { name = "get_vision_threshold", rval = "float", args = { "int" } }, - { name = "gibType", rval = "field_id", args = { } }, - { name = "has_active_bionic", rval = "bool", args = { "bionic_id" } }, - { name = "has_active_item", rval = "bool", args = { "string" } }, - { name = "has_active_mutation", rval = "bool", args = { "trait_id" } }, - { name = "has_base_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_bionic", rval = "bool", args = { "bionic_id" } }, - { name = "has_nv", rval = "bool", args = { } }, - { name = "has_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_trait_flag", rval = "bool", args = { "string" } }, - { name = "i_add", rval = "item&", args = { "item" } }, - { name = "i_add_or_drop", rval = "bool", args = { "item" }, optional_args = { "int" } }, - { name = "i_at", rval = "item&", args = { "int" } }, - { name = "i_rem", rval = "item", args = { "int" } }, - { name = "i_rem", rval = "item", args = { "item" } }, - { name = "i_rem_keep_contents", rval = nil, args = { "int" } }, - { name = "is_warm", rval = "bool", args = { } }, - { name = "is_wearing", rval = "bool", args = { "string" } }, - { name = "is_wearing_on_bp", rval = "bool", args = { "string", "body_part" } }, - { name = "is_worn", rval = "bool", args = { "item" } }, - { name = "limb_color", rval = "nc_color", args = { "body_part", "bool", "bool", "bool" } }, - { name = "made_of", rval = "bool", args = { "material_id" } }, - { name = "mod_int_bonus", rval = nil, args = { "int" } }, - { name = "mod_stat", rval = nil, args = { "string", "int" } }, - { name = "move_effects", rval = "bool", args = { "bool" } }, - { name = "mutation_effect", rval = nil, args = { "trait_id" } }, - { name = "mutation_loss_effect", rval = nil, args = { "trait_id" } }, - { name = "normalize", rval = nil, args = { } }, - { name = "pick_name", rval = nil, args = { }, optional_args = { "bool" } }, - { name = "random_bad_trait", rval = "trait_id", args = { } }, - { name = "random_good_trait", rval = "trait_id", args = { } }, - { name = "ranged_dex_mod", rval = "int", args = { } }, - { name = "ranged_per_mod", rval = "int", args = { } }, - { name = "recalc_hp", rval = nil, args = { } }, - { name = "recalc_sight_limits", rval = nil, args = { } }, - { name = "remove_mission_items", rval = nil, args = { "int" } }, - { name = "remove_weapon", rval = "item", args = { } }, - { name = "reset", rval = nil, args = { } }, - { name = "reset_bonuses", rval = nil, args = { } }, - { name = "reset_stats", rval = nil, args = { } }, - { name = "set_time_died", rval = nil, args = { "time_point" } }, - { name = "symbol", rval = "string", args = { } }, - { name = "set_mutation", rval = nil, args = { "trait_id" } }, - { name = "symbol_color", rval = "nc_color", args = { } }, - { name = "unset_mutation", rval = nil, args = { "trait_id" } }, - { name = "toggle_trait", rval = nil, args = { "trait_id" } }, - { name = "trait_by_invlet", rval = "trait_id", args = { "int" } }, - { name = "volume_capacity", rval = "volume", args = { } }, - { name = "volume_carried", rval = "volume", args = { } }, - { name = "weight_capacity", rval = "mass", args = { } }, - { name = "weight_carried", rval = "mass", args = { } }, - { name = "worn_with_flag", rval = "bool", args = { "string" } }, - { name = "get_healthy", rval = "int", args = { } }, - { name = "get_healthy_mod", rval = "int", args = { } }, - { name = "get_str", rval = "int", args = { } }, - { name = "get_str_base", rval = "int", args = { } }, - { name = "get_str_bonus", rval = "int", args = { } }, - { name = "get_dex", rval = "int", args = { } }, - { name = "get_dex_base", rval = "int", args = { } }, - { name = "get_dex_bonus", rval = "int", args = { } }, - { name = "get_int", rval = "int", args = { } }, - { name = "get_int_base", rval = "int", args = { } }, - { name = "get_int_bonus", rval = "int", args = { } }, - { name = "get_per", rval = "int", args = { } }, - { name = "get_per_base", rval = "int", args = { } }, - { name = "get_per_bonus", rval = "int", args = { } }, - { name = "get_hunger", rval = "int", args = { } }, - { name = "get_thirst", rval = "int", args = { } }, - { name = "get_stomach_food", rval = "int", args = { } }, - { name = "get_stomach_water", rval = "int", args = { } }, - { name = "mod_fatigue", rval = nil, args = { "int" } }, - { name = "set_fatigue", rval = nil, args = { "int" } }, - { name = "get_fatigue", rval = "int", args = { } }, - { name = "set_dex_bonus", rval = nil, args = { "int" } }, - { name = "set_healthy", rval = nil, args = { "int" } }, - { name = "set_healthy_mod", rval = nil, args = { "int" } }, - { name = "set_int_bonus", rval = nil, args = { "int" } }, - { name = "set_per_bonus", rval = nil, args = { "int" } }, - { name = "set_str_bonus", rval = nil, args = { "int" } }, - { name = "set_hunger", rval = nil, args = { "int" } }, - { name = "set_thirst", rval = nil, args = { "int" } }, - { name = "set_stomach_food", rval = nil, args = { "int" } }, - { name = "set_stomach_water", rval = nil, args = { "int" } }, - { name = "mod_dex_bonus", rval = nil, args = { "int" } }, - { name = "mod_healthy", rval = nil, args = { "int" } }, - { name = "mod_healthy_mod", rval = nil, args = { "int", "int" } }, - { name = "mod_per_bonus", rval = nil, args = { "int" } }, - { name = "mod_str_bonus", rval = nil, args = { "int" } }, - { name = "mod_hunger", rval = nil, args = { "int" } }, - { name = "mod_thirst", rval = nil, args = { "int" } }, - { name = "mod_stomach_food", rval = nil, args = { "int" } }, - { name = "mod_stomach_water", rval = nil, args = { "int" } }, - { name = "update_health", rval = nil, args = { }, optional_args = { "int" } }, - { name = "mod_stat", rval = nil, args = { "string", "int" } } - } - }, - item_stack_iterator = { - by_value = true, - has_equal = true, - new = { - { "item_stack_iterator" }, - }, - attributes = { - }, - functions = { - { name = "elem", rval = "item&", cpp_name = "operator*"; args = { } }, - { name = "inc", rval = nil, cpp_name = "operator++", args = { } }, - } - }, - map_stack = { - by_value = true, - attributes = { - }, - functions = { - { name = "cppbegin", rval = "item_stack_iterator", cpp_name = "begin", args = { } }, - { name = "cppend", rval = "item_stack_iterator", cpp_name = "end", args = {} }, - { name = "empty", rval = "bool", args = { } }, - { name = "erase", rval = "item_stack_iterator", args = { "item_stack_iterator" } }, - { name = "push_back", rval = nil, args = { "item" } }, - { name = "size", rval = "int", args = { } }, - } - }, - game = { - attributes = { - lightning_active = { type = "bool", writable = true }, - }, - functions = { - { name = "add_zombie", rval = "bool", args = { "monster" } }, - { name = "add_zombie", rval = "bool", args = { "monster", "bool" } }, - { name = "assign_mission_id", rval = "int", args = { } }, - { name = "assign_npc_id", rval = "int", args = { } }, - { name = "cancel_activity", rval = nil, args = { } }, - { name = "clear_zombies", rval = nil, args = { } }, - { name = "critter_at", rval = "Creature&", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "critter_by_id", rval = "Creature&", args = { "int" } }, - { name = "do_blast", rval = nil, args = { "tripoint", "float", "float", "bool" } }, - { name = "draw", rval = nil, args = { } }, - { name = "draw_critter", rval = nil, args = { "Creature", "tripoint" } }, - { name = "draw_explosion", rval = nil, args = { "tripoint", "int", "nc_color" } }, - { name = "draw_hit_mon", rval = nil, args = { "tripoint", "monster" }, optional_args = { "bool" } }, - { name = "draw_hit_player", rval = nil, args = { "player", "int" } }, - { name = "draw_sct", rval = nil, args = { } }, - { name = "draw_ter", rval = nil, args = { "tripoint" }, optional_args = { "bool", "bool" } }, - { name = "draw_ter", rval = nil, args = { }, optional_args = { "bool" } }, - { name = "draw_trail_to_square", rval = nil, args = { "tripoint", "bool" } }, - { name = "emp_blast", rval = nil, args = { "tripoint" } }, - { name = "explosion", rval = nil, args = { "tripoint", "float" }, optional_args = { "float", "int", "bool" } }, - { name = "flashbang", rval = nil, args = { "tripoint" }, optional_args = { "bool" } }, - { name = "fling_creature", rval = nil, args = { "Creature", "int", "float" }, optional_args = { "bool" } }, - { name = "get_cur_om", rval = "overmap&", args = { } }, - { name = "get_levx", rval = "int", args = { } }, - { name = "get_levy", rval = "int", args = { } }, - { name = "get_levz", rval = "int", args = { } }, - { name = "get_temperature", rval = "int", args = { "tripoint" } }, - { name = "handle_liquid", rval = "bool", args = { "item" } }, - { name = "increase_kill_count", rval = nil, args = { "mtype_id" } }, - { name = "inv_for_all", rval = "int", args = { "string" } }, - { name = "inv_for_flag", rval = "int", args = { "string", "string" } }, - { name = "inventory_item_menu", rval = "int", args = { "int" }, optional_args = { "int", "int" } }, - { name = "is_empty", rval = "bool", args = { "tripoint" } }, - { name = "is_hostile_nearby", rval = "Creature&", args = { } }, - { name = "is_hostile_very_close", rval = "Creature&", args = { } }, - { name = "is_in_sunlight", rval = "bool", args = { "tripoint" } }, - { name = "is_sheltered", rval = "bool", args = { "tripoint" } }, - { name = "kill_count", rval = "int", args = { "mtype_id" } }, - { name = "knockback", rval = nil, args = { "tripoint", "tripoint", "int", "int", "int" } }, - { name = "light_level", rval = "int", args = { "int" } }, - { name = "look_around", rval = "tripoint", args = { } }, - { name = "natural_light_level", rval = "float", args = { "int" } }, - { name = "nuke", rval = nil, args = { "tripoint" } }, - { name = "num_creatures", rval = "int", args = { } }, - { name = "open_gate", rval = nil, args = { "tripoint" } }, - { name = "peek", rval = nil, args = { "tripoint" } }, - { name = "peek", rval = nil, args = { } }, - { name = "plfire", rval = nil, args = { } }, - { name = "plswim", rval = nil, args = { "tripoint" } }, - { name = "refresh_all", rval = nil, args = { } }, - { name = "remove_zombie", rval = nil, args = { "monster" } }, - { name = "resonance_cascade", rval = nil, args = { "tripoint" } }, - { name = "revive_corpse", rval = "bool", args = { "tripoint", "item" } }, - { name = "save", rval = "bool", args = { } }, - { name = "scrambler_blast", rval = nil, args = { "tripoint" } }, - { name = "shockwave", rval = nil, args = { "tripoint", "int", "int", "int", "int", "bool" } }, - { name = "spawn_hallucination", rval = "bool", args = { "tripoint" } }, - { name = "summon_mon", rval = "monster&", args = { "mtype_id", "tripoint" } }, - { name = "swap_critters", rval = "bool", args = { "Creature", "Creature" } }, - { name = "teleport", rval = nil, args = { }, optional_args = { "player", "bool" } }, - { name = "unload", rval = nil, args = { "item" } }, - { name = "unload", rval = nil, args = { }, optional_args = { "int" } }, - { name = "use_computer", rval = nil, args = { "tripoint" } }, - { name = "reload_npcs", rval = nil, args = { } }, - { name = "place_player", rval = nil, args = { "tripoint" } }, - { name = "place_player_overmap", rval = nil, args = { "tripoint" } }, - } - }, - -- TODO: activity_id is to be moved into activity_type.string_id. - -- Now: Visual Studio removes is_valid() function in optimisation, so compile will be filed. - activity_id = { - by_value = true, - has_equal = true, - new = { - { "activity_id" }, - { }, - { "string" } - }, - attributes = { - }, - functions = { - { name = "str", rval = "string", args = { } }, - { name = "obj", rval = "activity_type&", args = { } }, - } - }, - activity_type = { - attributes = { - }, - functions = { - { name = "id", rval = "activity_id&", args = { } }, - { name = "no_resume", rval = "bool", args = { } }, - { name = "rooted", rval = "bool", args = { } }, - { name = "suspendable", rval = "bool", args = { } }, - { name = "stop_phrase", rval = "string", args = { } }, - } - }, - player_activity = { - by_value_and_reference = true, - attributes = { - auto_resume = { type = "bool", writable = true }, - index = { type = "int", writable = true }, - moves_left = { type = "int", writable = true }, - moves_total = { type = "int", writable = true }, - name = { type = "string", writable = true }, - placement = { type = "tripoint", writable = true }, - position = { type = "int", writable = true }, - }, - new = { - { }, - { "activity_id", "int", "int", "int", "string" }, - { "player_activity" }, - }, - functions = { - { name = "is_null", rval = "bool", args = { } }, - { name = "set_to_null", rval = nil, args = { } }, - { name = "id", rval = "activity_id&", args = { } }, - { name = "rooted", rval = "bool", args = { } }, - { name = "is_suspendable", rval = "bool", args = { } }, - } - }, - bionic = { - attributes = { - charge = { type = "int", writable = true }, - id = { type = "bionic_id", writable = true }, - invlet = { type = "int", writable = true }, - powered = { type = "bool", writable = true }, - }, - functions = { - { name = "get_quality", rval = "int", args = { "quality_id" } }, - } - }, - bionic_data = { - string_id = "bionic_id", - attributes = { - activated = { type = "bool", writable = true }, - armor_interface = { type = "bool", writable = true }, - capacity = { type = "int", writable = true }, - charge_time = { type = "int", writable = true }, - description = { type = "string", writable = true }, - fake_item = { type = "string", writable = true }, - faulty = { type = "bool", writable = true }, - gun_bionic = { type = "bool", writable = true }, - name = { type = "string", writable = true }, - power_activate = { type = "int", writable = true }, - power_deactivate = { type = "int", writable = true }, - power_over_time = { type = "int", writable = true }, - power_source = { type = "bool", writable = true }, - toggled = { type = "bool", writable = true }, - upgraded_bionic = { type = "bionic_id", writable = true }, - weapon_bionic = { type = "bool", writable = true }, - }, - functions = { - { name = "is_included", rval = "bool", args = { "bionic_id" } }, - } - }, - morale_type_data = { - string_id = "morale_type", - attributes = { - id = { type = "morale_type", writable = true }, - }, - functions = { - { name = "describe", rval = "string", args = { }, optional_args = { "itype" } }, - { name = "is_permanent", rval = "bool", args = { } }, - } - }, - encumbrance_data = { - by_value = true, - new = { - { "encumbrance_data" }, - }, - attributes = { - encumbrance = { type = "int", writable = true }, - armor_encumbrance = { type = "int", writable = true }, - layer_penalty = { type = "int", writable = true }, - }, - functions = { - } - }, - stats = { - attributes = { - damage_healed = { type = "int", writable = true }, - damage_taken = { type = "int", writable = true }, - headshots = { type = "int", writable = true }, - squares_walked = { type = "int", writable = true }, - }, - functions = { - } - }, - player = { - parent = "Character", - attributes = { - activity = { type = "player_activity", writable = true }, - blocks_left = { type = "int", writable = true }, - cash = { type = "int", writable = true }, - controlling_vehicle = { type = "bool", writable = true }, - dodges_left = { type = "int", writable = true }, - focus_pool = { type = "int", writable = true }, - grab_point = { type = "tripoint", writable = true }, - in_vehicle = { type = "bool", writable = true }, - keep_hands_free = { type = "bool", writable = true }, - last_batch = { type = "int", writable = true }, - last_climate_control_ret = { type = "bool", writable = true }, - lastconsumed = { type = "string", writable = true }, - lastrecipe = { type = "recipe_id", writable = true }, - lifetime_stats = { type = "stats", writable = true }, - max_power_level = { type = "int", writable = true }, - move_mode = { type = "string", writable = true }, - movecounter = { type = "int", writable = true }, - next_climate_control_check = { type = "time_point", writable = true }, - oxygen = { type = "int", writable = true }, - power_level = { type = "int", writable = true }, - radiation = { type = "int", writable = true }, - reactor_plut = { type = "int", writable = true }, - recoil = { type = "int", writable = true }, - scent = { type = "int", writable = true }, - slow_rad = { type = "int", writable = true }, - stamina = { type = "int", writable = true }, - start_location = { type = "start_location_id", writable = true }, - stim = { type = "int", writable = true }, - style_selected = { type = "matype_id", writable = true }, - tank_plut = { type = "int", writable = true }, - view_offset = { type = "tripoint", writable = true }, - volume = { type = "int", writable = true }, - }, - functions = { - { name = "action_taken", rval = nil, args = { } }, - { name = "activate_bionic", rval = "bool", args = { "int" }, optional_args = { "bool" } }, - { name = "active_light", rval = "float", args = { } }, - { name = "add_addiction", rval = nil, args = { "add_type", "int" } }, - { name = "add_bionic", rval = nil, args = { "bionic_id" } }, - { name = "add_known_trap", rval = nil, args = { "tripoint", "trap" } }, - { name = "add_martialart", rval = nil, args = { "matype_id" } }, - { name = "add_morale", rval = nil, args = { "morale_type", "int" }, optional_args = { "int", "time_duration", "time_duration", "bool", "itype" } }, - { name = "add_pain_msg", rval = nil, args = { "int", "body_part" } }, - { name = "addiction_level", rval = "int", args = { "add_type" } }, - { name = "adjacent_tile", rval = "tripoint", args = { } }, - { name = "adjust_for_focus", rval = "int", args = { "int" } }, - { name = "allergy_type", rval = "morale_type", args = { "item" } }, - { name = "amount_of", rval = "int", args = { "string" } }, - { name = "amount_worn", rval = "int", args = { "string" } }, - { name = "apply_damage", rval = nil, args = { "Creature", "body_part", "int" } }, - { name = "apply_persistent_morale", rval = nil, args = { } }, - { name = "assign_activity", rval = nil, args = { "activity_id" }, optional_args = { "int", "int", "int", "string" } }, - { name = "assign_activity", rval = nil, args = { "player_activity" }, optional_args = { "bool" } }, - { name = "attack_speed", rval = "int", args = { "item" } }, - { name = "avoid_trap", rval = "bool", args = { "tripoint", "trap" } }, - { name = "best_shield", rval = "item&", args = { } }, - { name = "bonus_damage", rval = "float", args = { "bool" } }, - { name = "basic_symbol_color", rval = "nc_color", args = { } }, - { name = "bionic_at_index", rval = "bionic&", args = { "int" } }, - { name = "bionic_by_invlet", rval = "bionic&", args = { "int" } }, - { name = "blossoms", rval = nil, args = { } }, - { name = "bodytemp_color", rval = "nc_color", args = { "int" } }, - { name = "bonus_item_warmth", rval = "int", args = { "body_part" } }, - { name = "mod_skill_level", rval = nil, args = { "skill_id", "int" } }, - { name = "burn_move_stamina", rval = nil, args = { "int" } }, - { name = "calc_focus_equilibrium", rval = "int", args = { } }, - { name = "can_arm_block", rval = "bool", args = { } }, - { name = "can_hear", rval = "bool", args = { "tripoint", "int" } }, - { name = "can_leg_block", rval = "bool", args = { } }, - { name = "can_limb_block", rval = "bool", args = { } }, - { name = "can_melee", rval = "bool", args = { } }, - { name = "can_sleep", rval = "bool", args = { } }, - { name = "can_reload", rval = "bool", args = { "item" }, optional_args = { "string" } }, - { name = "cancel_activity", rval = nil, args = { } }, - { name = "change_side", rval = "bool", args = { "int" }, optional_args = { "bool" } }, - { name = "change_side", rval = "bool", args = { "item" }, optional_args = { "bool" } }, - { name = "charge_power", rval = nil, args = { "int" } }, - { name = "charges_of", rval = "int", args = { "string" } }, - { name = "clairvoyance", rval = "int", args = { } }, - { name = "clear_destination", rval = nil, args = { } }, - { name = "clear_miss_reasons", rval = nil, args = { } }, - { name = "climbing_cost", rval = "int", args = { "tripoint", "tripoint" } }, - { name = "complete_craft", rval = nil, args = { } }, - { name = "complete_disassemble", rval = nil, args = { } }, - { name = "consume", rval = "bool", args = { "int" } }, - { name = "consume_charges", rval = "bool", args = { "item", "int" } }, - { name = "consume_effects", rval = nil, args = { "item" } }, - { name = "consume_item", rval = "bool", args = { "item" } }, - { name = "cough", rval = nil, args = { }, optional_args = { "bool", "int" } }, - { name = "craft", rval = nil, args = { } }, - { name = "crit_chance", rval = "float", args = { "int", "int", "item" } }, - { name = "crossed_threshold", rval = "bool", args = { } }, - { name = "deactivate_bionic", rval = "bool", args = { "int" }, optional_args = { "bool" } }, - { name = "digging", rval = "bool", args = { } }, - { name = "disassemble", rval = "bool", args = { } }, - { name = "disassemble", rval = "bool", args = { "int" } }, - { name = "disassemble", rval = "bool", args = { "item", "int", "bool" }, optional_args = { "bool" } }, - { name = "disp_info", rval = nil, args = { } }, - { name = "disp_morale", rval = nil, args = { } }, - { name = "disp_name", rval = "string", args = { "bool" } }, - { name = "disp_name", rval = "string", args = { } }, - { name = "do_read", rval = nil, args = { "item" } }, - { name = "dodge_roll", rval = "float", args = { } }, - { name = "drench_mut_calc", rval = nil, args = { } }, - { name = "apply_wetness_morale", rval = nil, args = { "int" } }, - { name = "drink_from_hands", rval = "int", args = { "item" } }, - { name = "dump_memorial", rval = "string", args = { } }, - { name = "eat", rval = "bool", args = { "item" }, optional_args = { "bool" } }, - { name = "environmental_revert_effect", rval = nil, args = { } }, - { name = "fall_asleep", rval = nil, args = { "time_duration" } }, - { name = "fall_damage_mod", rval = "float", args = { } }, - { name = "fine_detail_vision_mod", rval = "float", args = { } }, - { name = "fire_gun", rval = "int", args = { "tripoint" }, optional_args = { "int" } }, - { name = "fire_gun", rval = "int", args = { "tripoint", "int", "item" } }, - { name = "fire_gun", rval = nil, args = { "tripoint", "bool" } }, - { name = "fire_gun", rval = nil, args = { "tripoint", "bool", "item" } }, - { name = "footwear_factor", rval = "float", args = { } }, - { name = "getID", rval = "int", args = { } }, - { name = "get_active_mission_target", rval = "tripoint", args = { } }, - { name = "get_armor_acid", rval = "int", args = { "body_part" } }, - { name = "get_armor_bash", rval = "int", args = { "body_part" } }, - { name = "get_armor_bash_base", rval = "int", args = { "body_part" } }, - { name = "get_armor_cut", rval = "int", args = { "body_part" } }, - { name = "get_armor_cut_base", rval = "int", args = { "body_part" } }, - { name = "get_armor_fire", rval = "int", args = { "body_part" } }, - { name = "get_category_dream", rval = "string", args = { "string", "int" } }, - { name = "get_combat_style", rval = "martialart&", args = { } }, - { name = "get_dodge", rval = "float", args = { } }, - { name = "get_dodge_base", rval = "float", args = { } }, - { name = "get_env_resist", rval = "int", args = { "body_part" } }, - { name = "get_highest_category", rval = "string", args = { } }, - { name = "get_hit_base", rval = "float", args = { } }, - { name = "get_hit_weapon", rval = "float", args = { "item" } }, - { name = "get_hp", rval = "int", args = { "hp_part" } }, - { name = "get_hp_max", rval = "int", args = { "hp_part" } }, - { name = "get_item_position", rval = "int", args = { "item" } }, - { name = "get_melee", rval = "float", args = { } }, - { name = "get_random_body_part", rval = "body_part", args = { "bool" } }, - { name = "get_sick", rval = nil, args = { } }, - { name = "get_size", rval = "m_size", args = { } }, - { name = "get_stamina_max", rval = "int", args = { } }, - { name = "get_wind_resistance", rval = "int", args = { "body_part" } }, - { name = "global_omt_location", rval = "tripoint", args = { } }, - { name = "global_sm_location", rval = "tripoint", args = { } }, - { name = "global_square_location", rval = "tripoint", args = { } }, - { name = "gun_value", rval = "float", args = { "item" }, optional_args = { "int" } }, - { name = "gunmod_add", rval = nil, args = { "item", "item" } }, - { name = "gunmod_remove", rval = "bool", args = { "item", "item" } }, - { name = "handle_melee_wear", rval = "bool", args = { "item" }, optional_args = { "float" } }, - { name = "has_active_optcloak", rval = "bool", args = { } }, - { name = "has_activity", rval = "bool", args = { "activity_id" } }, - { name = "has_addiction", rval = "bool", args = { "add_type" } }, - { name = "has_alarm_clock", rval = "bool", args = { } }, - { name = "has_amount", rval = "bool", args = { "string", "int" } }, - { name = "has_charges", rval = "bool", args = { "string", "int" } }, - { name = "has_child_flag", rval = "bool", args = { "trait_id" } }, - { name = "has_conflicting_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_destination", rval = "bool", args = { } }, - { name = "has_grab_break_tec", rval = "bool", args = { } }, - { name = "has_gun_for_ammo", rval = "bool", args = { "ammotype" } }, - { name = "has_higher_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_identified", rval = "bool", args = { "string" } }, - { name = "has_item", rval = "bool", args = { "item" } }, - { name = "has_item_with_flag", rval = "bool", args = { "string" } }, - { name = "has_lower_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_mabuff", rval = "bool", args = { "mabuff_id" } }, - { name = "has_martialart", rval = "bool", args = { "matype_id" } }, - { name = "has_miss_recovery_tec", rval = "bool", args = { "item" } }, - { name = "has_mission_item", rval = "bool", args = { "int" } }, - { name = "has_morale", rval = "int", args = { "morale_type" } }, - { name = "has_morale_to_craft", rval = "bool", args = { } }, - { name = "has_morale_to_read", rval = "bool", args = { } }, - { name = "has_opposite_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_technique", rval = "bool", args = { "matec_id", "item" } }, - { name = "has_two_arms", rval = "bool", args = { } }, - { name = "has_watch", rval = "bool", args = { } }, - { name = "has_weapon", rval = "bool", args = { } }, - { name = "heal", rval = nil, args = { "body_part", "int" } }, - { name = "heal", rval = nil, args = { "hp_part", "int" } }, - { name = "healall", rval = nil, args = { "int" } }, - { name = "hearing_ability", rval = "float", args = { } }, - { name = "hit_roll", rval = "float", args = { } }, - { name = "hitall", rval = "int", args = { "int", "int", "Creature" } }, - { name = "hp_percentage", rval = "int", args = { } }, - { name = "hurtall", rval = nil, args = { "int", "Creature" } }, - { name = "i_at", rval = "item&", args = { "int" } }, - { name = "impact", rval = "int", args = { "int", "tripoint" } }, - { name = "in_climate_control", rval = "bool", args = { } }, - { name = "install_bionics", rval = "bool", args = { "itype", "player" }, optional_args = { "bool", "int" } }, - { name = "intimidation", rval = "int", args = { } }, - { name = "invalidate_crafting_inventory", rval = nil, args = { } }, - { name = "invlet_to_position", rval = "int", args = { "int" } }, - { name = "invoke_item", rval = "bool", args = { "item" } }, - { name = "invoke_item", rval = "bool", args = { "item", "string" } }, - { name = "invoke_item", rval = "bool", args = { "item", "string", "tripoint" } }, - { name = "invoke_item", rval = "bool", args = { "item", "tripoint" } }, - { name = "is_armed", rval = "bool", args = { } }, - { name = "is_dead_state", rval = "bool", args = { } }, - { name = "is_deaf", rval = "bool", args = { } }, - { name = "is_elec_immune", rval = "bool", args = { } }, - { name = "is_hallucination", rval = "bool", args = { } }, - { name = "is_hibernating", rval = "bool", args = { } }, - { name = "is_immune_effect", rval = "bool", args = { "efftype_id" } }, - { name = "is_invisible", rval = "bool", args = { } }, - { name = "is_npc", rval = "bool", args = { } }, - { name = "is_on_ground", rval = "bool", args = { } }, - { name = "is_player", rval = "bool", args = { } }, - { name = "is_quiet", rval = "bool", args = { } }, - { name = "is_snuggling", rval = "string", args = { } }, - { name = "is_throw_immune", rval = "bool", args = { } }, - { name = "is_underwater", rval = "bool", args = { } }, - { name = "is_wearing_active_power_armor", rval = "bool", args = { } }, - { name = "is_wearing_power_armor", rval = "bool", args = { } }, - { name = "is_wearing_shoes", rval = "bool", args = { }, optional_args = { "side" } }, - { name = "item_handling_cost", rval = "int", args = { "item" }, optional_args = { "bool", "int" } }, - { name = "item_reload_cost", rval = "int", args = { "item", "item", "int" } }, - { name = "knock_back_from", rval = nil, args = { "tripoint" } }, - { name = "knows_trap", rval = "bool", args = { "tripoint" } }, - { name = "leak_level", rval = "int", args = { "string" } }, - { name = "load_info", rval = nil, args = { "string" } }, - { name = "long_craft", rval = nil, args = { } }, - { name = "ma_onattack_effects", rval = nil, args = { } }, - { name = "ma_onblock_effects", rval = nil, args = { } }, - { name = "ma_ondodge_effects", rval = nil, args = { } }, - { name = "ma_ongethit_effects", rval = nil, args = { } }, - { name = "ma_onhit_effects", rval = nil, args = { } }, - { name = "ma_onmove_effects", rval = nil, args = { } }, - { name = "ma_static_effects", rval = nil, args = { } }, - { name = "mabuff_block_bonus", rval = "int", args = { } }, - { name = "mabuff_dodge_bonus", rval = "int", args = { } }, - { name = "mabuff_speed_bonus", rval = "int", args = { } }, - { name = "mabuff_tohit_bonus", rval = "int", args = { } }, - { name = "make_all_craft", rval = nil, args = { "recipe_id", "int" } }, - { name = "make_craft", rval = nil, args = { "recipe_id", "int" } }, - { name = "make_craft_with_command", rval = nil, args = { "recipe_id", "int" }, optional_args = { "bool" } }, - { name = "making_would_work", rval = "bool", args = { "recipe_id", "int" } }, - { name = "max_quality", rval = "int", args = { "quality_id" } }, - { name = "melee_attack", rval = nil, args = { "Creature", "bool", "matec_id" } }, - { name = "melee_value", rval = "float", args = { "item" } }, - { name = "mend", rval = nil, args = { "int" } }, - { name = "metabolic_rate", rval = "float", args = { } }, - { name = "metabolic_rate_base", rval = "float", args = { } }, - { name = "mod_pain", rval = nil, args = { "int" } }, - { name = "set_pain", rval = nil, args = { "int" } }, - { name = "get_perceived_pain", rval = "int", args = { } }, - { name = "mod_painkiller", rval = nil, args = { "int" } }, - { name = "set_painkiller", rval = nil, args = { "int" } }, - { name = "get_painkiller", rval = "int", args = { } }, - { name = "mod_stat", rval = nil, args = { "string", "int" } }, - { name = "get_morale_level", rval = "int", args = { } }, - { name = "mutate", rval = nil, args = { } }, - { name = "mutate_category", rval = nil, args = { "string" } }, - { name = "mutate_towards", rval = "bool", args = { "trait_id" } }, - { name = "mutation_ok", rval = "bool", args = { "trait_id", "bool", "bool" } }, - { name = "natural_attack_restricted_on", rval = "bool", args = { "body_part" } }, - { name = "normalize", rval = nil, args = { } }, - { name = "num_bionics", rval = "int", args = { } }, - { name = "nutrition_for", rval = "int", args = { "item" } }, - { name = "on_dodge", rval = nil, args = { "Creature", "float" } }, - { name = "on_hit", rval = nil, args = { "Creature" } }, - { name = "on_hit", rval = nil, args = { "Creature", "body_part" } }, - { name = "on_hit", rval = nil, args = { "Creature", "body_part", "float" } }, - { name = "on_hurt", rval = nil, args = { "Creature" }, optional_args = { "bool" } }, - { name = "overmap_los", rval = "bool", args = { "tripoint", "int" } }, - { name = "overmap_sight_range", rval = "int", args = { "int" } }, - { name = "pause", rval = nil, args = { } }, - { name = "perform_special_attacks", rval = nil, args = { "Creature" } }, - { name = "pick_style", rval = "bool", args = { } }, - { name = "pick_technique", rval = "matec_id", args = { "Creature", "item", "bool", "bool", "bool" } }, - { name = "place_corpse", rval = nil, args = { } }, - { name = "pos", rval = "tripoint", args = { } }, - { name = "posx", rval = "int", args = { } }, - { name = "posy", rval = "int", args = { } }, - { name = "posz", rval = "int", args = { } }, - { name = "power_bionics", rval = nil, args = { } }, - { name = "power_mutations", rval = nil, args = { } }, - { name = "power_rating", rval = "float", args = { } }, - { name = "practice", rval = nil, args = { "skill_id", "int" }, optional_args = { "int" } }, - { name = "process_active_items", rval = nil, args = { } }, - { name = "process_bionic", rval = nil, args = { "int" } }, - { name = "process_effects", rval = nil, args = { } }, - { name = "process_turn", rval = nil, args = { } }, - { name = "purifiable", rval = "bool", args = { "trait_id" } }, - { name = "ranged_dex_mod", rval = "int", args = { } }, - { name = "ranged_per_mod", rval = "int", args = { } }, - { name = "reach_attack", rval = nil, args = { "tripoint" } }, - { name = "read", rval = "bool", args = { "int" } }, - { name = "read_speed", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "recalc_speed_bonus", rval = nil, args = { } }, - { name = "recraft", rval = nil, args = { } }, - { name = "reduce_charges", rval = "item", args = { "int", "int" } }, - { name = "reduce_charges", rval = "item", args = { "item", "int" } }, - { name = "regen", rval = nil, args = { "int" } }, - { name = "rem_addiction", rval = nil, args = { "add_type" } }, - { name = "rem_morale", rval = nil, args = { "morale_type" }, optional_args = { "itype" } }, - { name = "remove_bionic", rval = nil, args = { "bionic_id" } }, - { name = "remove_child_flag", rval = nil, args = { "trait_id" } }, - { name = "remove_mutation", rval = nil, args = { "trait_id" } }, - { name = "remove_random_bionic", rval = "bool", args = { } }, - { name = "reset_stats", rval = nil, args = { } }, - { name = "rooted", rval = nil, args = { } }, - { name = "rooted_message", rval = nil, args = { } }, - { name = "run_cost", rval = "int", args = { "int" }, optional_args = { "bool" } }, - { name = "rust_rate", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "save_info", rval = "string", args = { } }, - { name = "scored_crit", rval = "bool", args = { "float", "item" } }, - { name = "search_surroundings", rval = nil, args = { } }, - { name = "sees", rval = "bool", args = { "Creature" } }, - { name = "sees", rval = "bool", args = { "tripoint" } }, - { name = "sees", rval = "bool", args = { "tripoint", "bool" } }, - { name = "sees_with_infrared", rval = "bool", args = { "Creature" } }, - { name = "setID", rval = nil, args = { "int" } }, - { name = "set_highest_cat_level", rval = nil, args = { } }, - { name = "get_skill_level", rval = "int", args = { "skill_id" } }, - { name = "set_skill_level", rval = nil, args = { "skill_id", "int" } }, - { name = "set_underwater", rval = nil, args = { "bool" } }, - { name = "setpos", rval = nil, args = { "tripoint" } }, - { name = "setx", rval = nil, args = { "int" } }, - { name = "sety", rval = nil, args = { "int" } }, - { name = "setz", rval = nil, args = { "int" } }, - { name = "shift_destination", rval = nil, args = { "int", "int" } }, - { name = "shoe_type_count", rval = "int", args = { "string" } }, - { name = "shout", rval = nil, args = { }, optional_args = { "string" } }, - { name = "sight_impaired", rval = "bool", args = { } }, - { name = "sight_range", rval = "int", args = { "int" } }, - { name = "skin_name", rval = "string", args = { } }, - { name = "sleep_spot", rval = "int", args = { "tripoint" } }, - { name = "sort_armor", rval = nil, args = { } }, - { name = "speed_rating", rval = "float", args = { } }, - { name = "spores", rval = nil, args = { } }, - { name = "stability_roll", rval = "int", args = { } }, - { name = "stomach_capacity", rval = "int", args = { } }, - { name = "store", rval = nil, args = { "item", "item" }, optional_args = { "int", "bool" } }, - { name = "studied_all_recipes", rval = "bool", args = { "itype" } }, - { name = "suffer", rval = nil, args = { } }, - { name = "swim_speed", rval = "int", args = { } }, - { name = "takeoff", rval = bool, args = { "item" } }, - { name = "talk_skill", rval = "int", args = { } }, - { name = "temp_equalizer", rval = nil, args = { "body_part", "body_part" } }, - { name = "throw_range", rval = "int", args = { "item" } }, - { name = "toggle_move_mode", rval = nil, args = { } }, - { name = "try_to_sleep", rval = nil, args = { } }, - { name = "unarmed_attack", rval = "bool", args = { } }, - { name = "unarmed_value", rval = "float", args = { } }, - { name = "uncanny_dodge", rval = "bool", args = { } }, - { name = "unimpaired_range", rval = "int", args = { } }, - { name = "update_body_wetness", rval = nil, args = { "w_point" } }, - { name = "update_bodytemp", rval = nil, args = { } }, - { name = "update_health", rval = nil, args = { "int" } }, - { name = "update_health", rval = nil, args = { } }, - { name = "update_mental_focus", rval = nil, args = { } }, - { name = "update_morale", rval = nil, args = { } }, - { name = "update_needs", rval = nil, args = { "int" } }, - { name = "update_stamina", rval = nil, args = { "int" } }, - { name = "use", rval = nil, args = { "int" } }, - { name = "use_charges_if_avail", rval = "bool", args = { "string", "int" } }, - { name = "use_wielded", rval = nil, args = { } }, - { name = "visibility", rval = "int", args = { }, optional_args = { "bool", "int" } }, - { name = "vomit", rval = nil, args = { } }, - { name = "vomit_mod", rval = "float", args = { } }, - { name = "wake_up", rval = nil, args = { } }, - { name = "warmth", rval = "int", args = { "body_part" } }, - { name = "weapname", rval = "string", args = { } }, - { name = "weapon_value", rval = "float", args = { "item" }, optional_args = { "int" } }, - { name = "wear", rval = "bool", args = { "int" }, optional_args = { "bool" } }, - { name = "wear_item", rval = "bool", args = { "item" }, optional_args = { "bool" } }, - { name = "wearing_something_on", rval = "bool", args = { "body_part" } }, - { name = "wield", rval = "bool", args = { "item" } }, - { name = "wield_contents", rval = "bool", args = { "item" }, optional_args = { "int", "int", "bool" } }, - } - }, - npc_companion_mission = { - by_value = true, - attributes = { - mission_id = { type = "string", writable = true }, - position = { type = "tripoint", writable = true }, - role_id = { type = "string", writable = true }, - }, - functions = { - } - }, - npc_personality = { - by_value = true, - attributes = { - aggression = { type = "int", writable = true }, - altruism = { type = "int", writable = true }, - bravery = { type = "int", writable = true }, - collector = { type = "int", writable = true }, - }, - functions = { - } - }, - npc_opinion = { - by_value = true, - attributes = { - anger = { type = "int", writable = true }, - fear = { type = "int", writable = true }, - trust = { type = "int", writable = true }, - owed = { type = "int", writable = true }, - value = { type = "int", writable = true }, - }, - functions = { - } - }, - npc = { - parent = "player", - attributes = { - companion_mission_time = { type = "time_point", writable = true }, - guard_pos = { type = "tripoint", writable = true }, - op_of_u = { type = "npc_opinion", writable = true }, - personality = { type = "npc_personality", writable = true }, - patience = { type = "int", writable = true }, - restock = { type = "time_point", writable = true }, - wander_pos = { type = "tripoint", writable = true }, - wanted_item_pos = { type = "tripoint", writable = true }, - }, - functions = { - { name = "assigned_missions_value", rval = "int", args = { } }, - { name = "can_move_to", rval = "bool", args = { "tripoint", "bool" } }, - { name = "current_target", rval = "Creature&", args = { } }, - { name = "get_attitude", rval = "npc_attitude", args = { } }, - { name = "get_companion_mission", rval = "npc_companion_mission", args = { } }, - { name = "get_healing_item", rval = "item&", args = { "bool", "bool", "bool", "bool" } }, - { name = "guaranteed_hostile", rval = "bool", args = { } }, - { name = "has_companion_mission", rval = "bool", args = { } }, - { name = "hostile_anger_level", rval = "int", args = { } }, - { name = "is_active", rval = "bool", args = { } }, - { name = "is_dead", rval = "bool", args = { } }, - { name = "is_enemy", rval = "bool", args = { } }, - { name = "is_following", rval = "bool", args = { } }, - { name = "is_friend", rval = "bool", args = { } }, - { name = "is_guarding", rval = "bool", args = { } }, - { name = "is_leader", rval = "bool", args = { } }, - { name = "is_minion", rval = "bool", args = { } }, - { name = "make_angry", rval = nil, args = { } }, - { name = "reset_companion_mission", rval = nil, args = { } }, - { name = "say", rval = nil, args = { "string" } }, - { name = "set_attitude", rval = nil, args = { "npc_attitude" } }, - { name = "set_companion_mission", rval = nil, args = { "npc", "string" } }, - { name = "shop_restock", rval = nil, args = { } }, - { name = "spawn_at_precise", rval = nil, args = { "point", "tripoint" } }, - { name = "talk_to_u", rval = nil, args = { } }, - } - }, - item = { - new = { - { }, - { "item" }, - { "string", "int" }, - { "string", "int", "int" }, - { "itype", "int" }, - { "itype", "int", "int" }, - -- TODO: export constructor with default_charges_tag paremeter - }, - by_value_and_reference = true, - attributes = { - active = { type = "bool", writable = true }, - burnt = { type = "int", writable = true }, - charges = { type = "int", writable = true }, - frequency = { type = "int", writable = true }, - invlet = { type = "int", writable = true }, - irridation = { type = "int", writable = true }, - item_counter = { type = "int", writable = true }, - mission_id = { type = "int", writable = true }, - note = { type = "int", writable = true }, - player_id = { type = "int", writable = true }, - poison = { type = "int", writable = true }, - type = { type = "itype", writable = true }, - }, - functions = { - { name = "age", rval = "time_duration", args = { } }, - { name = "set_age", rval = nil, args = { "time_duration" } }, - { name = "birthday", rval = "time_point", args = { } }, - { name = "set_birthday", rval = nil, args = { "time_point" } }, - { name = "acid_resist", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "add_rain_to_container", rval = nil, args = { "bool" }, optional_args = { "int" } }, - { name = "add_technique", rval = nil, args = { "matec_id" } }, - { name = "already_used_by_player", rval = "bool", args = { "player" } }, - { name = "ammo_capacity", rval = "int", args = { } }, - { name = "ammo_current", rval = "string", args = { } }, - { name = "ammo_data", rval = "itype&", args = { } }, - { name = "ammo_remaining", rval = "int", args = { } }, - { name = "ammo_required", rval = "int", args = { } }, - { name = "ammo_type", rval = "ammotype", args = { }, optional_args = { "bool" } }, - { name = "amount_of", rval = "int", args = { "string", "bool" } }, - { name = "attack_time", rval = "int", args = { } }, - { name = "bash_resist", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "brewing_time", rval = "time_duration", args = { } }, - { name = "calc_rot", rval = nil, args = { "tripoint" } }, - { name = "can_holster", rval = "bool", args = { "item" }, optional_args = { "bool" } }, - { name = "can_revive", rval = "bool", args = { } }, - { name = "charges_of", rval = "int", args = { "string" } }, - { name = "chip_resistance", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "clear_vars", rval = nil, args = { } }, - { name = "color", rval = "nc_color", args = { } }, - { name = "color_in_inventory", rval = "nc_color", args = { } }, - { name = "components_to_string", rval = "string", args = { } }, - { name = "conductive", rval = "bool", args = { } }, - { name = "convert", rval = "item&", args = { "string" } }, - { name = "count_by_charges", rval = "bool", args = { } }, - { name = "covers", rval = "bool", args = { "body_part" } }, - { name = "craft_has_charges", rval = "bool", args = { } }, - { name = "cut_resist", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "damage", rval = "int", args = { } }, - { name = "destroyed_at_zero_charges", rval = "bool", args = { } }, - { name = "display_name", rval = "string", args = { }, optional_args = { "int" } }, - { name = "erase_var", rval = nil, args = { "string" } }, - { name = "fill_with", rval = nil, args = { "item" } }, - { name = "fire_resist", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "flammable", rval = "bool", args = { } }, - { name = "get_chapters", rval = "int", args = { } }, - { name = "get_coverage", rval = "int", args = { } }, - { name = "get_encumber", rval = "int", args = { "Character" } }, - { name = "get_env_resist", rval = "int", args = { } }, - { name = "get_free_mod_locations", rval = "int", args = { "string" } }, - { name = "get_gun_ups_drain", rval = "int", args = { } }, - { name = "get_layer", rval = "int", args = { } }, - { name = "get_mtype", rval = "mtype&", args = { } }, - { name = "get_plant_epoch", rval = "time_duration", args = { } }, - { name = "get_plant_name", rval = "string", args = { } }, - { name = "get_property_long", rval = "int", args = { "string" }, optional_args = { "int" } }, - { name = "get_property_string", rval = "string", args = { "string" }, optional_args = { "string" } }, - { name = "get_quality", rval = "int", args = { "quality_id" } }, - { name = "get_relative_rot", rval = "float", args = { } }, - { name = "get_remaining_capacity_for_liquid", rval = "int", args = { "item", "bool" } }, - { name = "get_remaining_chapters", rval = "int", args = { "player" } }, - { name = "get_rot", rval = "time_duration", args = { } }, - { name = "get_side", rval = "side", args = { } }, - { name = "get_storage", rval = "volume", args = { } }, - { name = "get_thickness", rval = "int", args = { } }, - { name = "get_usable_item", rval = "item&", args = { "string" } }, - { name = "get_var", rval = "float", args = { "string", "float" } }, - { name = "get_var", rval = "int", args = { "string", "int" } }, - { name = "get_var", rval = "int", args = { "string", "int" } }, - { name = "get_var", rval = "string", args = { "string" } }, - { name = "get_var", rval = "string", args = { "string", "string" } }, - { name = "get_warmth", rval = "int", args = { } }, - { name = "getlight_emit", rval = "int", args = { } }, - { name = "goes_bad", rval = "bool", args = { } }, - { name = "gun_cycle_mode", rval = nil, args = { } }, - { name = "gun_dispersion", rval = "int", args = { }, optional_args = { "bool", "bool" } }, - { name = "gun_get_mode_id", rval = "gun_mode_id", args = { } }, - { name = "gun_range", rval = "int", args = { "player" } }, - { name = "gun_range", rval = "int", args = { }, optional_args = { "bool" } }, - { name = "gun_recoil", rval = "int", args = { "player" }, optional_args = { "bool" } }, - { name = "gun_set_mode", rval = nil, args = { "gun_mode_id" } }, - { name = "gun_skill", rval = "skill_id", args = { } }, - { name = "gunmod_find", rval = "item&", args = { "string" } }, - { name = "has_flag", rval = "bool", args = { "string" } }, - { name = "has_label", rval = "bool", args = { } }, - { name = "has_property", rval = "bool", args = { "string" } }, - { name = "has_quality", rval = "bool", args = { "quality_id" }, optional_args = { "int", "int" } }, - { name = "has_rotten_away", rval = "bool", args = { } }, - { name = "has_technique", rval = "bool", args = { "matec_id" } }, - { name = "has_var", rval = "bool", args = { "string" } }, - { name = "in_its_container", rval = "item", args = { } }, - { name = "inc_damage", rval = "bool", args = { } }, - { name = "info", rval = "string", args = { }, optional_args = { "bool" } }, - { name = "is_ammo", rval = "bool", args = { } }, - { name = "is_ammo_container", rval = "bool", args = { } }, - { name = "is_armor", rval = "bool", args = { } }, - { name = "is_artifact", rval = "bool", args = { } }, - { name = "is_bionic", rval = "bool", args = { } }, - { name = "is_book", rval = "bool", args = { } }, - { name = "is_container", rval = "bool", args = { } }, - { name = "is_container_empty", rval = "bool", args = { } }, - { name = "is_container_full", rval = "bool", args = { } }, - { name = "is_corpse", rval = "bool", args = { } }, - { name = "is_dangerous", rval = "bool", args = { } }, - { name = "is_emissive", rval = "bool", args = { } }, - { name = "is_firearm", rval = "bool", args = { } }, - { name = "is_food", rval = "bool", args = { } }, - { name = "is_food_container", rval = "bool", args = { } }, - { name = "is_going_bad", rval = "bool", args = { } }, - { name = "is_gun", rval = "bool", args = { } }, - { name = "is_gunmod", rval = "bool", args = { } }, - { name = "is_magazine", rval = "bool", args = { } }, - { name = "is_null", rval = "bool", args = { } }, - { name = "is_power_armor", rval = "bool", args = { } }, - { name = "is_salvageable", rval = "bool", args = { } }, - { name = "is_non_resealable_container", rval = "bool", args = { } }, - { name = "is_seed", rval = "bool", args = { } }, - { name = "is_sided", rval = "bool", args = { } }, - { name = "is_silent", rval = "bool", args = { } }, - { name = "is_tool", rval = "bool", args = { } }, - { name = "is_tool_reversible", rval = "bool", args = { } }, - { name = "is_two_handed", rval = "bool", args = { "player" } }, - { name = "is_watertight_container", rval = "bool", args = { } }, - { name = "is_melee", rval = "bool", args = { } }, - { name = "label", rval = "string", args = { }, optional_args = { "int" } }, - { name = "charges_per_volume", rval = "int", args = { "volume" } }, - { name = "load_info", rval = nil, args = { "string" } }, - { name = "made_of", rval = "bool", args = { "phase_id" } }, - { name = "made_of", rval = "bool", args = { "material_id" } }, - { name = "magazine_current", rval = "item&", args = { } }, - { name = "magazine_default", rval = "string", args = { }, optional_args = { "bool" } }, - { name = "magazine_integral", rval = "bool", args = { } }, - { name = "make_corpse", rval = nil, args = { }, optional_args = { "mtype_id", "int", "string" } }, - { name = "mark_as_used_by_player", rval = nil, args = { "player" } }, - { name = "mark_chapter_as_read", rval = nil, args = { "player" } }, - { name = "max_damage", rval = "int", args = { } }, - { name = "merge_charges", rval = "bool", args = { "item" } }, - { name = "min_damage", rval = "int", args = { } }, - { name = "mod_damage", rval = "bool", args = { "int" } }, - { name = "needs_processing", rval = "bool", args = { } }, - { name = "on_pickup", rval = nil, args = { "Character" } }, - { name = "on_takeoff", rval = nil, args = { "player" } }, - { name = "on_wear", rval = nil, args = { "player" } }, - { name = "on_wield", rval = nil, args = { "player" } }, - { name = "price", rval = "int", args = { "bool" } }, - { name = "process", rval = "bool", args = { "player", "tripoint", "bool" } }, - { name = "process_artifact", rval = nil, args = { "player", "tripoint" } }, - { name = "processing_speed", rval = "int", args = { } }, - { name = "put_in", rval = nil, args = { "item" } }, - { name = "ready_to_revive", rval = "bool", args = { "tripoint" } }, - { name = "mod_charges", rval = nil, args = { "int" } }, - { name = "reset_cable", rval = nil, args = { "player" } }, - { name = "rotten", rval = "bool", args = { } }, - { name = "set_mtype", rval = nil, args = { "mtype" } }, - { name = "set_relative_rot", rval = nil, args = { "float" } }, - { name = "set_snippet", rval = nil, args = { "string" } }, - { name = "set_var", rval = nil, args = { "string", "float" } }, - { name = "set_var", rval = nil, args = { "string", "int" } }, - { name = "set_var", rval = nil, args = { "string", "int" } }, - { name = "set_var", rval = nil, args = { "string", "string" } }, - { name = "sight_dispersion", rval = "int", args = { } }, - { name = "stacks_with", rval = "bool", args = { "item" } }, - { name = "symbol", rval = "string", args = { } }, - { name = "tname", rval = "string", args = { }, optional_args = { "int", "bool" } }, - { name = "typeId", rval = "string", args = { } }, - { name = "type_name", rval = "string", args = { }, optional_args = { "int" } }, - { name = "volume", rval = "volume", args = { } }, - { name = "melee_skill", rval = "skill_id", args = { } }, - { name = "weight", rval = "mass", args = { } }, - } - }, - item_location = { - attributes = { - }, - by_value = true, - functions = { - { name = "describe", rval = "string", args = { }, optional_args = { "Character" } }, - { name = "get_item", rval = "item&", args = { } }, - { name = "obtain", rval = "int", args = { "Character" }, optional_args = { "int" } }, - { name = "obtain_cost", rval = "int", args = { "Character" }, optional_args = { "int" } }, - { name = "remove_item", rval = nil, args = { } }, - } - }, - point = { - by_value = true, - has_equal = true, - attributes = { - x = { - type = "int", - writable = true - }, - y = { - type = "int", - writable = true - } - }, - new = { - { "point" }, - { "int", "int" }, - }, - functions = { - } - }, - tripoint = { - by_value = true, - has_equal = true, - attributes = { - x = { - type = "int", - writable = true - }, - y = { - type = "int", - writable = true - }, - z = { - type = "int", - writable = true - } - }, - new = { - { "tripoint" }, - { "int", "int", "int" }, - }, - functions = { - } - }, - uilist = { - attributes = { - title = { - type = "string", - writable = true - }, - selected = { - type = "int", - writable = false - }, - ret = { - type = "int", - writable = false - } - }, - functions = { - { name = "show", rval = nil, args = { } }, - { name = "query", rval = nil, args = { "bool" } }, - { name = "addentry", rval = nil, args = { "string" } }, - } - }, - field_entry = { - attributes = { - }, - functions = { - { name = "getFieldAge", rval = "time_duration", args = { } }, - { name = "getFieldDensity", rval = "int", args = { } }, - { name = "getFieldType", rval = "field_id", args = { } }, - { name = "isAlive", rval = "bool", args = { } }, - { name = "is_dangerous", rval = "bool", args = { } }, - { name = "move_cost", rval = "int", args = { } }, - { name = "name", rval = "string", args = { } }, - { name = "setFieldAge", rval = "time_duration", args = { "time_duration" } }, - { name = "setFieldDensity", rval = "int", args = { "int" } }, - { name = "setFieldType", rval = "field_id", args = { "field_id" } }, - } - }, - field = { - attributes = { - }, - functions = { - { name = "addField", rval = "bool", args = { "field_id" }, optional_args = { "int", "time_duration" } }, - { name = "fieldCount", rval = "int", args = { } }, - { name = "fieldSymbol", rval = "field_id", args = { } }, - { name = "findField", rval = "field_entry&", args = { "field_id" } }, - { name = "findField", rval = "field_entry&", args = { "field_id" } }, - { name = "move_cost", rval = "int", args = { } }, - { name = "removeField", rval = "bool", args = { "field_id" } }, - } - }, - map = { - attributes = { - }, - functions = { - { name = "accessible_items", rval = "bool", args = { "tripoint" } }, - { name = "add_camp", rval = nil, args = { "tripoint", "string" } }, - { name = "add_corpse", rval = nil, args = { "tripoint" } }, - { name = "add_field", rval = "bool", args = { "tripoint", "field_id", "int", "time_duration" } }, - { name = "add_item", rval = "item&", args = { "tripoint", "item" } }, - { name = "add_item_or_charges", rval = "item&", args = { "tripoint", "item" }, optional_args = { "bool" } }, - { name = "add_spawn", rval = nil, args = { "mtype_id", "int", "int", "int" }, optional_args = { "bool", "int", "int", "string" } }, - { name = "adjust_field_age", rval = "time_duration", args = { "tripoint", "field_id", "time_duration" } }, - { name = "adjust_field_strength", rval = "int", args = { "tripoint", "field_id", "int" } }, - { name = "adjust_radiation", rval = nil, args = { "tripoint", "int" } }, - { name = "allow_camp", rval = "bool", args = { "tripoint", "int" } }, - { name = "ambient_light_at", rval = "float", args = { "tripoint" } }, - { name = "bash_rating", rval = "int", args = { "int", "tripoint" }, optional_args = { "bool" } }, - { name = "bash_resistance", rval = "int", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "bash_strength", rval = "int", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "board_vehicle", rval = nil, args = { "tripoint", "player" } }, - { name = "can_move_furniture", rval = "bool", args = { "tripoint" }, optional_args = { "player" } }, - { name = "can_put_items", rval = "bool", args = { "tripoint" } }, - { name = "clear_path", rval = "bool", args = { "tripoint", "tripoint", "int", "int", "int" } }, - { name = "clear_spawns", rval = nil, args = { } }, - { name = "clear_traps", rval = nil, args = { } }, - { name = "climb_difficulty", rval = "int", args = { "tripoint" } }, - { name = "close_door", rval = "bool", args = { "tripoint", "bool", "bool" } }, - { name = "collapse_at", rval = nil, args = { "tripoint", "bool" } }, - { name = "collapse_check", rval = "int", args = { "tripoint" } }, - { name = "combined_movecost", rval = "int", args = { "tripoint", "tripoint" } }, - { name = "could_see_items", rval = "bool", args = { "tripoint", "Creature" } }, - { name = "creature_in_field", rval = nil, args = { "Creature" } }, - { name = "creature_on_trap", rval = nil, args = { "Creature" }, optional_args = { "bool" } }, - { name = "crush", rval = nil, args = { "tripoint" } }, - { name = "decay_fields_and_scent", rval = nil, args = { "time_duration" } }, - { name = "delete_graffiti", rval = nil, args = { "tripoint" } }, - { name = "delete_signage", rval = nil, args = { "tripoint" } }, - { name = "destroy", rval = nil, args = { "tripoint" }, optional_args = { "bool" } }, - { name = "destroy_furn", rval = nil, args = { "tripoint" }, optional_args = { "bool" } }, - { name = "disarm_trap", rval = nil, args = { "tripoint" } }, - { name = "disp_name", rval = "string", args = { "tripoint" } }, - { name = "displace_vehicle", rval = nil, args = { "tripoint", "tripoint" } }, - { name = "displace_water", rval = "bool", args = { "tripoint" } }, - { name = "draw_circle_furn", rval = nil, args = { "furn_id", "int", "int", "int" } }, - { name = "draw_circle_furn", rval = nil, args = { "furn_str_id", "int", "int", "int" } }, - { name = "draw_circle_ter", rval = nil, args = { "ter_str_id", "int", "int", "int" } }, - { name = "draw_circle_ter", rval = nil, args = { "ter_id", "float", "float", "float" } }, - { name = "draw_circle_ter", rval = nil, args = { "ter_id", "int", "int", "int" } }, - { name = "draw_fill_background", rval = nil, args = { "ter_id" } }, - { name = "draw_fill_background", rval = nil, args = { "ter_str_id" } }, - { name = "draw_line_furn", rval = nil, args = { "furn_id", "int", "int", "int", "int" } }, - { name = "draw_line_furn", rval = nil, args = { "furn_str_id", "int", "int", "int", "int" } }, - { name = "draw_line_ter", rval = nil, args = { "ter_id", "int", "int", "int", "int" } }, - { name = "draw_line_ter", rval = nil, args = { "ter_str_id", "int", "int", "int", "int" } }, - { name = "draw_rough_circle_ter", rval = nil, args = { "ter_id", "int", "int", "int" } }, - { name = "draw_rough_circle_ter", rval = nil, args = { "ter_str_id", "int", "int", "int" } }, - { name = "draw_rough_circle_furn", rval = nil, args = { "furn_id", "int", "int", "int" } }, - { name = "draw_rough_circle_furn", rval = nil, args = { "furn_str_id", "int", "int", "int" } }, - { name = "draw_square_furn", rval = nil, args = { "furn_id", "int", "int", "int", "int" } }, - { name = "draw_square_furn", rval = nil, args = { "furn_str_id", "int", "int", "int", "int" } }, - { name = "draw_square_ter", rval = nil, args = { "ter_id", "int", "int", "int", "int" } }, - { name = "draw_square_ter", rval = nil, args = { "ter_str_id", "int", "int", "int", "int" } }, - { name = "features", rval = "string", args = { "tripoint" } }, - { name = "field_at", rval = "field&", args = { "tripoint" } }, - { name = "flammable_items_at", rval = "bool", args = { "tripoint" } }, - { name = "free_volume", rval = "volume", args = { "tripoint" } }, - { name = "furn", rval = "furn_id", args = { "tripoint" } }, - { name = "furn_set", rval = nil, args = { "tripoint", "furn_id" } }, - { name = "furn_set", rval = nil, args = { "tripoint", "furn_str_id" } }, - { name = "furnname", rval = "string", args = { "tripoint" } }, - { name = "get_abs_sub", rval = "tripoint", args = { } }, - { name = "get_field", rval = "field_entry&", args = { "tripoint", "field_id" } }, - { name = "get_field_age", rval = "time_duration", args = { "tripoint", "field_id" } }, - { name = "get_field_strength", rval = "int", args = { "tripoint", "field_id" } }, - { name = "get_radiation", rval = "int", args = { "tripoint" } }, - { name = "get_signage", rval = "string", args = { "tripoint" } }, - { name = "get_ter_transforms_into", rval = "ter_id", args = { "tripoint" } }, - { name = "getabs", rval = "tripoint", args = { "tripoint" } }, - { name = "getlocal", rval = "tripoint", args = { "tripoint" } }, - { name = "getmapsize", rval = "int", args = { } }, - { name = "graffiti_at", rval = "string", args = { "tripoint" } }, - { name = "has_adjacent_furniture", rval = "bool", args = { "tripoint" } }, - { name = "has_flag", rval = "bool", args = { "string", "tripoint" } }, - { name = "has_flag_furn", rval = "bool", args = { "string", "tripoint" } }, - { name = "has_flag_ter", rval = "bool", args = { "string", "tripoint" } }, - { name = "has_flag_ter_or_furn", rval = "bool", args = { "string", "tripoint" } }, - { name = "has_floor", rval = "bool", args = { "tripoint" } }, - { name = "has_floor_or_support", rval = "bool", args = { "tripoint" } }, - { name = "has_furn", rval = "bool", args = { "tripoint" } }, - { name = "has_graffiti_at", rval = "bool", args = { "tripoint" } }, - { name = "has_items", rval = "bool", args = { "tripoint" } }, - { name = "has_nearby_fire", rval = "bool", args = { "tripoint" }, optional_args = { "int" } }, - { name = "has_zlevels", rval = "bool", args = { } }, - { name = "hit_with_acid", rval = "bool", args = { "tripoint" } }, - { name = "hit_with_fire", rval = "bool", args = { "tripoint" } }, - { name = "i_at", rval = "map_stack", args = { "tripoint" } }, - { name = "i_clear", rval = nil, args = { "tripoint" } }, - { name = "i_rem", rval = "int", args = { "tripoint", "int" } }, - { name = "i_rem", rval = "item_stack_iterator", args = { "tripoint", "item_stack_iterator" } }, - { name = "i_rem", rval = nil, args = { "tripoint", "item" } }, - { name = "impassable", rval = "bool", args = { "tripoint" } }, - { name = "impassable_ter_furn", rval = "bool", args = { "tripoint" } }, - { name = "inbounds", rval = "bool", args = { "point" } }, - { name = "inbounds", rval = "bool", args = { "tripoint" } }, - { name = "is_bashable", rval = "bool", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "is_bashable_furn", rval = "bool", args = { "tripoint" } }, - { name = "is_bashable_ter", rval = "bool", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "is_bashable_ter_furn", rval = "bool", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "is_divable", rval = "bool", args = { "tripoint" } }, - { name = "is_outside", rval = "bool", args = { "tripoint" } }, - { name = "item_from", rval = "item&", args = { "tripoint", "int" } }, - { name = "light_transparency", rval = "float", args = { "tripoint" } }, - { name = "load", rval = nil, args = { "int", "int", "int", "bool" } }, - { name = "make_rubble", rval = nil, args = { "tripoint" } }, - { name = "make_rubble", rval = nil, args = { "tripoint", "furn_id", "bool" } }, - { name = "make_rubble", rval = nil, args = { "tripoint", "furn_id", "bool", "ter_id" }, optional_args = { "bool" } }, - { name = "max_volume", rval = "volume", args = { "tripoint" } }, - { name = "mop_spills", rval = nil, args = { "tripoint" } }, - { name = "move_cost", rval = "int", args = { "tripoint" } }, - { name = "move_cost_ter_furn", rval = "int", args = { "tripoint" } }, - { name = "name", rval = "string", args = { "tripoint" } }, - { name = "on_vehicle_moved", rval = nil, args = { "int" } }, - { name = "open_door", rval = "bool", args = { "tripoint", "bool" }, optional_args = { "bool" } }, - { name = "passable", rval = "bool", args = { "tripoint" } }, - { name = "passable_ter_furn", rval = "bool", args = { "tripoint" } }, - { name = "pl_sees", rval = "bool", args = { "tripoint", "int" } }, - { name = "place_gas_pump", rval = nil, args = { "int", "int", "int" } }, - { name = "place_gas_pump", rval = nil, args = { "int", "int", "int", "string" } }, - { name = "place_npc", rval = "int", args = { "int", "int", "npc_template_id" } }, - { name = "place_spawns", rval = nil, args = { "mongroup_id", "int", "int", "int", "int", "int", "float" } }, - { name = "place_toilet", rval = nil, args = { "int", "int" }, optional_args = { "int" } }, - { name = "place_vending", rval = nil, args = { "int", "int", "string" } }, - { name = "put_items_from_loc", rval = nil, args = { "string", "tripoint" }, optional_args = { "time_point" } }, - { name = "random_outdoor_tile", rval = "point", args = { } }, - { name = "remove_field", rval = nil, args = { "tripoint", "field_id" } }, - { name = "remove_trap", rval = nil, args = { "tripoint" } }, - { name = "save", rval = nil, args = { } }, - { name = "sees", rval = "bool", args = { "tripoint", "tripoint", "int" } }, - { name = "sees_some_items", rval = "bool", args = { "tripoint", "Creature" } }, - { name = "set_field_age", rval = "time_duration", args = { "tripoint", "field_id", "time_duration" }, optional_args = { "bool" } }, - { name = "set_field_strength", rval = "int", args = { "tripoint", "field_id", "int" }, optional_args = { "bool" } }, - { name = "set_graffiti", rval = nil, args = { "tripoint", "string" } }, - { name = "set_radiation", rval = nil, args = { "tripoint", "int" } }, - { name = "set_signage", rval = nil, args = { "tripoint", "string" } }, - { name = "set_temperature", rval = nil, args = { "tripoint", "int" } }, - { name = "smash_items", rval = nil, args = { "tripoint", "int" } }, - { name = "spawn_an_item", rval = "item&", args = { "tripoint", "item", "int", "int" } }, - { name = "spawn_artifact", rval = nil, args = { "tripoint" } }, - { name = "spawn_item", rval = nil, args = { "tripoint", "string" }, optional_args = { "int", "int", "time_point", "int" } }, - { name = "spawn_monsters", rval = nil, args = { "bool" } }, - { name = "stored_volume", rval = "volume", args = { "tripoint" } }, - { name = "supports_above", rval = "bool", args = { "tripoint" } }, - { name = "ter", rval = "ter_id", args = { "tripoint" } }, - { name = "ter_set", rval = nil, args = { "tripoint", "ter_id" } }, - { name = "ter_set", rval = nil, args = { "tripoint", "ter_str_id" } }, - { name = "tername", rval = "string", args = { "tripoint" } }, - { name = "tr_at", rval = "trap&", args = { "tripoint" } }, - { name = "trans", rval = "bool", args = { "tripoint" } }, - { name = "translate", rval = nil, args = { "ter_id", "ter_id" } }, - { name = "trap_set", rval = nil, args = { "tripoint", "trap_id" } }, - { name = "translate_radius", rval = nil, args = { "ter_id", "ter_id", "float", "tripoint" } }, - { name = "trigger_rc_items", rval = nil, args = { "string" } }, - { name = "unboard_vehicle", rval = nil, args = { "tripoint" } }, - { name = "valid_move", rval = "bool", args = { "tripoint", "tripoint" }, optional_args = { "bool", "bool" } }, - { name = "water_from", rval = "item", args = { "tripoint" } }, - } - }, - ter_t = { - int_id = "ter_id", - string_id = "ter_str_id", - - attributes = { - close = { type = "ter_str_id", writable = true }, - open = { type = "ter_str_id", writable = true }, - roof = { type = "ter_str_id", writable = true }, - transforms_into = { type = "ter_str_id", writable = true }, - trap = { type = "trap_id", writable = true }, - id = { type = "ter_str_id" }, - movecost = { type = "int", writable = true }, - }, - functions = { - { name = "color", rval = "nc_color", args = { } }, - { name = "name", rval = "string", args = { } }, - { name = "symbol", rval = "int", args = { } }, - } - }, - furn_t = { - int_id = "furn_id", - string_id = "furn_str_id", - - attributes = { - close = { type = "furn_str_id", writable = true }, - id = { type = "furn_str_id" }, - max_volume = { type = "volume", writable = true }, - movecost = { type = "int", writable = true }, - comfort = { type = "int", writable = true }, - floor_bedding_warmth = { type = "int", writable = true }, - bonus_fire_warmth_feet = { type = "int", writable = true }, - open = { type = "furn_str_id", writable = true }, - transparent = { type = "bool", writable = true }, - move_str_req = { type = "int", writable = true }, - }, - functions = { - { name = "color", rval = "nc_color", args = { } }, - { name = "name", rval = "string", args = { } }, - { name = "symbol", rval = "int", args = { } }, - } - }, - Creature = { - attributes = { - }, - functions = { - { name = "add_effect", rval = nil, args = { "efftype_id", "time_duration" }, optional_args = { "body_part", "bool", "int", "bool" } }, - { name = "add_env_effect", rval = "bool", args = { "efftype_id", "body_part", "int", "time_duration" }, optional_args = { "body_part", "bool", "int", "bool" } }, - { name = "apply_damage", rval = nil, args = { "Creature", "body_part", "int" } }, - { name = "avoid_trap", rval = "bool", args = { "tripoint", "trap" } }, - { name = "basic_symbol_color", rval = "nc_color", args = { } }, - { name = "bloodType", rval = "field_id", args = { } }, - { name = "check_dead_state", rval = nil, args = { } }, - { name = "clear_effects", rval = nil, args = { } }, - { name = "die", rval = nil, args = { "Creature" } }, - { name = "digging", rval = "bool", args = { } }, - { name = "disp_name", rval = "string", args = { }, optional_args = { "bool" } }, - { name = "dodge_roll", rval = "float", args = { } }, - { name = "fall_damage_mod", rval = "float", args = { } }, - { name = "get_armor_bash", rval = "int", args = { "body_part" } }, - { name = "get_armor_bash_base", rval = "int", args = { "body_part" } }, - { name = "get_armor_bash_bonus", rval = "int", args = { } }, - { name = "get_armor_cut", rval = "int", args = { "body_part" } }, - { name = "get_armor_cut_base", rval = "int", args = { "body_part" } }, - { name = "get_armor_cut_bonus", rval = "int", args = { } }, - { name = "get_bash_bonus", rval = "int", args = { } }, - { name = "get_bash_mult", rval = "float", args = { } }, - { name = "get_block_bonus", rval = "int", args = { } }, - { name = "get_cut_bonus", rval = "int", args = { } }, - { name = "get_cut_mult", rval = "float", args = { } }, - { name = "get_dodge", rval = "float", args = { } }, - { name = "get_dodge_base", rval = "float", args = { } }, - { name = "get_dodge_bonus", rval = "float", args = { } }, - { name = "get_effect_dur", rval = "time_duration", args = { "efftype_id" }, optional_args = { "body_part" } }, - { name = "get_effect_int", rval = "int", args = { "efftype_id" }, optional_args = { "body_part" } }, - { name = "get_env_resist", rval = "int", args = { "body_part" } }, - { name = "get_grab_resist", rval = "int", args = { } }, - { name = "get_hit", rval = "float", args = { } }, - { name = "get_hit_base", rval = "float", args = { } }, - { name = "get_hit_bonus", rval = "float", args = { } }, - { name = "get_hp", rval = "int", args = { "hp_part" } }, - { name = "get_hp", rval = "int", args = { } }, - { name = "get_hp_max", rval = "int", args = { "hp_part" } }, - { name = "get_hp_max", rval = "int", args = { } }, - { name = "get_killer", rval = "Creature&", args = { } }, - { name = "get_melee", rval = "int", args = { } }, - { name = "get_melee_quiet", rval = "bool", args = { } }, - { name = "get_name", rval = "string", args = { } }, - { name = "get_num_blocks", rval = "int", args = { } }, - { name = "get_num_blocks_bonus", rval = "int", args = { } }, - { name = "get_num_dodges", rval = "int", args = { } }, - { name = "get_num_dodges_bonus", rval = "int", args = { } }, - { name = "get_random_body_part", rval = "body_part", args = { }, optional_args = { "bool" } }, - { name = "get_size", rval = "m_size", args = { } }, - { name = "get_speed", rval = "int", args = { } }, - { name = "get_speed_base", rval = "int", args = { } }, - { name = "get_speed_bonus", rval = "int", args = { } }, - { name = "get_throw_resist", rval = "int", args = { } }, - { name = "get_value", rval = "string", args = { "string" } }, - { name = "gibType", rval = "field_id", args = { } }, - { name = "has_effect", rval = "bool", args = { "efftype_id" }, optional_args = { "body_part" } }, - { name = "has_grab_break_tec", rval = "bool", args = { } }, - { name = "has_trait", rval = "bool", args = { "trait_id" } }, - { name = "has_weapon", rval = "bool", args = { } }, - { name = "hit_roll", rval = "float", args = { } }, - { name = "hp_percentage", rval = "int", args = { } }, - { name = "impact", rval = "int", args = { "int", "tripoint" } }, - { name = "in_sleep_state", rval = "bool", args = { } }, - { name = "is_dead_state", rval = "bool", args = { } }, - { name = "is_elec_immune", rval = "bool", args = { } }, - { name = "is_fake", rval = "bool", args = { } }, - { name = "is_hallucination", rval = "bool", args = { } }, - { name = "is_immune_effect", rval = "bool", args = { "efftype_id" } }, - { name = "is_monster", rval = "bool", args = { } }, - { name = "is_npc", rval = "bool", args = { } }, - { name = "is_on_ground", rval = "bool", args = { } }, - { name = "is_player", rval = "bool", args = { } }, - { name = "is_symbol_highlighted", rval = "bool", args = { } }, - { name = "is_underwater", rval = "bool", args = { } }, - { name = "is_warm", rval = "bool", args = { } }, - { name = "knock_back_from", rval = nil, args = { "tripoint" } }, - { name = "mod_bash_bonus", rval = nil, args = { "int" } }, - { name = "mod_block_bonus", rval = nil, args = { "int" } }, - { name = "mod_cut_bonus", rval = nil, args = { "int" } }, - { name = "mod_dodge_bonus", rval = nil, args = { "float" } }, - { name = "mod_hit_bonus", rval = nil, args = { "float" } }, - { name = "mod_moves", rval = nil, args = { "int" } }, - { name = "mod_pain", rval = nil, args = { "int" } }, - { name = "mod_pain_noresist", rval = nil, args = { "int" } }, - { name = "set_pain", rval = nil, args = { "int" } }, - { name = "get_pain", rval = "int", args = { } }, - { name = "get_perceived_pain", rval = "int", args = { } }, - { name = "mod_speed_bonus", rval = nil, args = { "int" } }, - { name = "mod_stat", rval = nil, args = { "string", "int" } }, - { name = "move_effects", rval = "bool", args = { "bool" } }, - { name = "normalize", rval = nil, args = { } }, - { name = "on_dodge", rval = nil, args = { "Creature", "float" } }, - { name = "on_hit", rval = nil, args = { "Creature" }, optional_args = { "body_part", "float" } }, - { name = "pos", rval = "tripoint", args = { } }, - { name = "posx", rval = "int", args = { } }, - { name = "posy", rval = "int", args = { } }, - { name = "posz", rval = "int", args = { } }, - { name = "power_rating", rval = "float", args = { } }, - { name = "process_effects", rval = nil, args = { } }, - { name = "process_turn", rval = nil, args = { } }, - { name = "remove_effect", rval = "bool", args = { "efftype_id" }, optional_args = { "body_part" } }, - { name = "remove_value", rval = nil, args = { "string" } }, - { name = "reset", rval = nil, args = { } }, - { name = "reset_bonuses", rval = nil, args = { } }, - { name = "reset_stats", rval = nil, args = { } }, - { name = "sees", rval = "bool", args = { "Creature" } }, - { name = "sees", rval = "bool", args = { "tripoint" }, optional_args = { "bool" } }, - { name = "set_armor_bash_bonus", rval = nil, args = { "int" } }, - { name = "set_armor_cut_bonus", rval = nil, args = { "int" } }, - { name = "set_bash_bonus", rval = nil, args = { "int" } }, - { name = "set_bash_mult", rval = nil, args = { "float" } }, - { name = "set_block_bonus", rval = nil, args = { "int" } }, - { name = "set_cut_bonus", rval = nil, args = { "int" } }, - { name = "set_cut_mult", rval = nil, args = { "float" } }, - { name = "set_dodge_bonus", rval = nil, args = { "float" } }, - { name = "set_fake", rval = nil, args = { "bool" } }, - { name = "set_grab_resist", rval = nil, args = { "int" } }, - { name = "set_hit_bonus", rval = nil, args = { "float" } }, - { name = "set_melee_quiet", rval = nil, args = { "bool" } }, - { name = "set_moves", rval = nil, args = { "int" } }, - { name = "set_num_blocks_bonus", rval = nil, args = { "int" } }, - { name = "set_num_dodges_bonus", rval = nil, args = { "int" } }, - { name = "set_speed_base", rval = nil, args = { "int" } }, - { name = "set_speed_bonus", rval = nil, args = { "int" } }, - { name = "set_throw_resist", rval = nil, args = { "int" } }, - { name = "set_value", rval = nil, args = { "string", "string" } }, - { name = "setpos", rval = nil, args = { "tripoint" } }, - { name = "sight_range", rval = "int", args = { "int" } }, - { name = "skin_name", rval = "string", args = { } }, - { name = "speed_rating", rval = "float", args = { } }, - { name = "stability_roll", rval = "int", args = { } }, - { name = "symbol", rval = "string", args = { } }, - { name = "symbol_color", rval = "nc_color", args = { } }, - { name = "uncanny_dodge", rval = "bool", args = { } }, - { name = "weight_capacity", rval = "mass", args = { } }, - } - }, - monster = { - parent = "Creature", - attributes = { - anger = { type = "int", writable = true }, - friendly = { type = "int", writable = true }, - hallucination = { type = "bool", writable = true }, - ignoring = { type = "int", writable = true }, - last_updated = { type = "time_point", writable = true }, - made_footstep = { type = "bool", writable = true }, - mission_id = { type = "int", writable = true }, - morale = { type = "int", writable = true }, - no_corpse_quiet = { type = "bool", writable = true }, - no_extra_death_drops = { type = "bool", writable = true }, - staircount = { type = "int", writable = true }, - type = { type = "mtype" }, - unique_name = { type = "string", writable = true }, - wander_pos = { type = "tripoint", writable = true }, - wandf = { type = "int", writable = true }, - }, - functions = { - { name = "add_item", rval = nil, args = { "item" } }, - { name = "apply_damage", rval = nil, args = { "Creature", "body_part", "int" } }, - { name = "attack_at", rval = "bool", args = { "tripoint" } }, - { name = "attack_target", rval = "Creature&", args = { } }, - { name = "avoid_trap", rval = "bool", args = { "tripoint", "trap" } }, - { name = "bash_at", rval = "bool", args = { "tripoint" } }, - { name = "bash_estimate", rval = "int", args = { } }, - { name = "bash_skill", rval = "int", args = { } }, - { name = "basic_symbol_color", rval = "nc_color", args = { } }, - { name = "bloodType", rval = "field_id", args = { } }, - { name = "calc_climb_cost", rval = "int", args = { "tripoint", "tripoint" } }, - { name = "calc_movecost", rval = "int", args = { "tripoint", "tripoint" } }, - { name = "can_act", rval = "bool", args = { } }, - { name = "can_drown", rval = "bool", args = { } }, - { name = "can_hear", rval = "bool", args = { } }, - { name = "can_move_to", rval = "bool", args = { "tripoint" } }, - { name = "can_see", rval = "bool", args = { } }, - { name = "can_submerge", rval = "bool", args = { } }, - { name = "can_upgrade", rval = "bool", args = { } }, - { name = "color_with_effects", rval = "nc_color", args = { } }, - { name = "deal_melee_attack", rval = "int", args = { "Creature", "int" } }, - { name = "die", rval = nil, args = { "Creature" } }, - { name = "die_in_explosion", rval = nil, args = { "Creature" } }, - { name = "digging", rval = "bool", args = { } }, - { name = "disp_name", rval = "string", args = { "bool" } }, - { name = "disp_name", rval = "string", args = { } }, - { name = "dodge_roll", rval = "float", args = { } }, - { name = "drop_items_on_death", rval = nil, args = { } }, - { name = "explode", rval = nil, args = { } }, - { name = "fall_damage_mod", rval = "float", args = { } }, - { name = "footsteps", rval = nil, args = { "tripoint" } }, - { name = "get_armor_bash", rval = "int", args = { "body_part" } }, - { name = "get_armor_cut", rval = "int", args = { "body_part" } }, - { name = "get_dodge", rval = "float", args = { } }, - { name = "get_hp", rval = "int", args = { "hp_part" } }, - { name = "get_hp", rval = "int", args = { } }, - { name = "get_hp_max", rval = "int", args = { "hp_part" } }, - { name = "get_hp_max", rval = "int", args = { } }, - { name = "get_melee", rval = "float", args = { } }, - { name = "get_random_body_part", rval = "body_part", args = { "bool" } }, - { name = "get_size", rval = "m_size", args = { } }, - { name = "get_volume", rval = "volume", args = { } }, - { name = "get_weight", rval = "mass", args = { } }, - { name = "gibType", rval = "field_id", args = { } }, - { name = "group_bash_skill", rval = "int", args = { "tripoint" } }, - { name = "has_grab_break_tec", rval = "bool", args = { } }, - { name = "has_weapon", rval = "bool", args = { } }, - { name = "heal", rval = "int", args = { "int" }, optional_args = { "bool" } }, - { name = "hear_sound", rval = nil, args = { "tripoint", "int", "int" } }, - { name = "hit_roll", rval = "float", args = { } }, - { name = "hp_percentage", rval = "int", args = { } }, - { name = "impact", rval = "int", args = { "int", "tripoint" } }, - { name = "init_from_item", rval = nil, args = { "item" } }, - { name = "is_dead", rval = "bool", args = { } }, - { name = "is_dead_state", rval = "bool", args = { } }, - { name = "is_elec_immune", rval = "bool", args = { } }, - { name = "is_fleeing", rval = "bool", args = { "player" } }, - { name = "is_hallucination", rval = "bool", args = { } }, - { name = "is_immune_effect", rval = "bool", args = { "efftype_id" } }, - { name = "is_monster", rval = "bool", args = { } }, - { name = "is_on_ground", rval = "bool", args = { } }, - { name = "is_symbol_highlighted", rval = "bool", args = { } }, - { name = "is_underwater", rval = "bool", args = { } }, - { name = "is_warm", rval = "bool", args = { } }, - { name = "knock_back_from", rval = nil, args = { "tripoint" } }, - { name = "made_of", rval = "bool", args = { "phase_id" } }, - { name = "made_of", rval = "bool", args = { "material_id" } }, - { name = "make_ally", rval = nil, args = { "monster" } }, - { name = "make_friendly", rval = nil, args = { } }, - { name = "make_fungus", rval = "bool", args = { } }, - { name = "melee_attack", rval = nil, args = { "Creature", "float" } }, - { name = "move", rval = nil, args = { } }, - { name = "move_effects", rval = "bool", args = { "bool" } }, - { name = "move_target", rval = "tripoint", args = { } }, - { name = "move_to", rval = "bool", args = { "tripoint" }, optional_args = { "bool", "float" } }, - { name = "name", rval = "string", args = { }, optional_args = { "int" } }, - { name = "name_with_armor", rval = "string", args = { } }, - { name = "on_dodge", rval = nil, args = { "Creature", "float" } }, - { name = "on_hit", rval = nil, args = { "Creature" } }, - { name = "on_hit", rval = nil, args = { "Creature", "body_part" } }, - { name = "on_hit", rval = nil, args = { "Creature", "body_part", "float" } }, - { name = "on_load", rval = nil, args = { } }, - { name = "on_unload", rval = nil, args = { } }, - { name = "poly", rval = nil, args = { "mtype_id" } }, - { name = "pos", rval = "tripoint", args = { } }, - { name = "posx", rval = "int", args = { } }, - { name = "posy", rval = "int", args = { } }, - { name = "posz", rval = "int", args = { } }, - { name = "power_rating", rval = "float", args = { } }, - { name = "process_effects", rval = nil, args = { } }, - { name = "process_triggers", rval = nil, args = { } }, - { name = "push_to", rval = "bool", args = { "tripoint", "int", "int" } }, - { name = "rate_target", rval = "float", args = { "Creature", "float" }, optional_args = { "bool" } }, - { name = "reset_special", rval = nil, args = { "string" } }, - { name = "reset_special_rng", rval = nil, args = { "string" } }, - { name = "scent_move", rval = "tripoint", args = { } }, - { name = "set_dest", rval = nil, args = { "tripoint" } }, - { name = "set_hp", rval = nil, args = { "int" } }, - { name = "set_special", rval = nil, args = { "string", "int" } }, - { name = "disable_special", rval = nil, args = { "string" } }, - { name = "setpos", rval = nil, args = { "tripoint" } }, - { name = "shift", rval = nil, args = { "int", "int" } }, - { name = "sight_range", rval = "int", args = { "int" } }, - { name = "skin_name", rval = "string", args = { } }, - { name = "spawn", rval = nil, args = { "tripoint" } }, - { name = "speed_rating", rval = "float", args = { } }, - { name = "stability_roll", rval = "int", args = { } }, - { name = "stumble", rval = nil, args = { } }, - { name = "symbol", rval = "string", args = { } }, - { name = "symbol_color", rval = "nc_color", args = { } }, - { name = "to_item", rval = "item", args = { } }, - { name = "turns_to_reach", rval = "int", args = { "int", "int" } }, - { name = "try_upgrade", rval = nil, args = { "bool" } }, - { name = "hasten_upgrade", rval = nil, args = { } }, - { name = "unset_dest", rval = nil, args = { } }, - { name = "wander", rval = "bool", args = { } }, - { name = "wander_to", rval = nil, args = { "tripoint", "int" } }, - { name = "will_reach", rval = "bool", args = { "int", "int" } }, - } - }, - recipe = { - string_id = "recipe_id", - attributes = { - }, - functions = { - } - }, - martialart = { - string_id = "matype_id", - attributes = { - }, - functions = { - } - }, - material_type = { - string_id = "material_id", - attributes = { - }, - functions = { - } - }, - start_location = { - string_id = "start_location_id", - attributes = { - }, - functions = { - } - }, - ma_buff = { - string_id = "mabuff_id", - attributes = { - }, - functions = { - } - }, - ma_technique = { - string_id = "matec_id", - attributes = { - }, - functions = { - } - }, - Skill = { - string_id = "skill_id", - attributes = { - }, - functions = { - } - }, - quality = { - string_id = "quality_id", - attributes = { - name = { type = "string", writable = false } - }, - functions = { - } - }, - npc_template = { - string_id = "npc_template_id", - attributes = { - }, - functions = { - } - }, - species_type = { - string_id = "species_id", - attributes = { - }, - functions = { - } - }, - ammunition_type = { - string_id = "ammotype", - attributes = { - }, - functions = { - } - }, - MonsterGroup = { - string_id = "mongroup_id", - attributes = { - defaultMonster = { type = "mtype_id", writable = true }, - is_safe = { type = "bool", writable = true }, - monster_group_time = { type = "time_duration", writable = true }, - name = { type = "mongroup_id", writable = true }, - new_monster_group = { type = "mongroup_id", writable = true }, - replace_monster_group = { type = "bool", writable = true }, - }, - functions = { - { name = "IsMonsterInGroup", rval = "bool", args = { "mtype_id" } }, - } - }, - mtype = { - string_id = "mtype_id", - attributes = { - agro = { type = "int", writable = true }, - armor_acid = { type = "int", writable = true }, - armor_bash = { type = "int", writable = true }, - armor_cut = { type = "int", writable = true }, - armor_fire = { type = "int", writable = true }, - armor_stab = { type = "int", writable = true }, - attack_cost = { type = "int", writable = true }, - color = { type = "nc_color", writable = true }, - death_drops = { type = "string", writable = true }, - def_chance = { type = "int", writable = true }, - difficulty = { type = "int", writable = true }, - hp = { type = "int", writable = true }, - id = { type = "mtype_id" }, - luminance = { type = "float", writable = true }, - melee_dice = { type = "int", writable = true }, - melee_sides = { type = "int", writable = true }, - melee_skill = { type = "int", writable = true }, - morale = { type = "int", writable = true }, - phase = { type = "phase_id", writable = true }, - revert_to_itype = { type = "string", writable = true }, - size = { type = "m_size", writable = true }, - sk_dodge = { type = "int", writable = true }, - speed = { type = "int", writable = true }, - sym = { type = "string", writable = true }, - upgrade_group = { type = "mongroup_id", writable = true }, - upgrades = { type = "bool", writable = true }, - half_life = { type = "int", writable = true }, - upgrade_into = { type = "mtype_id", writable = true }, - vision_day = { type = "int", writable = true }, - vision_night = { type = "int", writable = true }, - }, - functions = { - { name = "bloodType", rval = "field_id", args = { } }, - { name = "get_meat_itype", rval = "string", args = { } }, - { name = "gibType", rval = "field_id", args = { } }, - { name = "has_flag", rval = "bool", args = { "string" } }, - { name = "made_of", rval = "bool", args = { "material_id" } }, - { name = "has_special_attack", rval = "bool", args = { "string" } }, - { name = "in_category", rval = "bool", args = { "string" } }, - { name = "in_species", rval = "bool", args = { "species_id" } }, - { name = "nname", rval = "string", args = { }, optional_args = { "int" } }, - { name = "same_species", rval = "bool", args = { "mtype" } }, - { name = "set_flag", rval = nil, args = { "string", "bool" } }, - } - }, - mongroup = { - attributes = { - pos = { type = "tripoint", writable = false }, - target = { type = "tripoint", writable = false }, - dying = { type = "bool", writable = true }, - horde = { type = "bool", writable = true }, - diffuse = { type = "bool", writable = true }, - radius = { type = "int", writable = true }, - population = { type = "int", writable = true } - }, - functions = { - { name = "set_target", rval = nil, args = { "int", "int" } }, - { name = "inc_interest", rval = nil, args = { "int" } }, - { name = "dec_interest", rval = nil, args = { "int" } }, - { name = "set_interest", rval = nil, args = { "int" } }, - } - }, - -- You can get reference to current overmap using `g:get_cur_om()` or return value of overmap with given coordinates using `overmap(x, y)`. - overmap = { - by_value_and_reference = true, - new = { - { "int", "int" }, - }, - attributes = { - }, - functions = { - { name = "pos", rval = "point", args = { } }, - { name = "find_random_omt", rval = "tripoint", args = { "string" } }, - { name = "is_explored", rval = "bool", args = { "int", "int", "int" } }, - { name = "has_note", rval = "bool", args = { "int", "int", "int" } }, - { name = "note", rval = "string", args = { "int", "int", "int" } }, - { name = "add_note", rval = nil, args = { "int", "int", "int", "string" } }, - { name = "delete_note", rval = nil, args = { "int", "int", "int" } }, - { name = "global_base_point", rval = "point", args = { } }, - { name = "clear_mon_groups", rval = nil, args = { } }, - } - }, - volume = { - by_value = true, - attributes = { - }, - functions = { - { name = "value", rval = "int", args = { } }, - }, - }, - mass = { - by_value = true, - attributes = { - }, - functions = { - { name = "value", rval = "int", args = { } }, - }, - }, - nc_color = { - by_value = true, - attributes = { - }, - functions = { - }, - }, - time_duration = { - by_value = true, - has_equal = true, - new = { - { "time_duration" }, - }, - attributes = { - }, - functions = { - }, - }, - time_point = { - by_value = true, - has_equal = true, - new = { - { "calendar" }, - { "int" }, - { "time_point" }, - }, - attributes = { - }, - functions = { - }, - }, - itype = { - attributes = { - color = { type = "nc_color", writable = true }, - description = { type = "string", writable = true }, - explode_in_fire = { type = "bool", writable = true }, - integral_volume = { type = "volume", writable = true }, - light_emission = { type = "int", writable = true }, - m_to_hit = { type = "int", writable = true }, - magazine_well = { type = "volume", writable = true }, - min_dex = { type = "int", writable = true }, - min_int = { type = "int", writable = true }, - min_per = { type = "int", writable = true }, - min_str = { type = "int", writable = true }, - phase = { type = "phase_id", writable = true }, - price = { type = "int", writable = true }, - price_post = { type = "int", writable = true }, - rigid = { type = "bool", writable = true }, - snippet_category = { type = "string", writable = true }, - stack_size = { type = "int", writable = true }, - sym = { type = "string", writable = true }, - volume = { type = "volume", writable = true }, - weight = { type = "mass", writable = true }, - }, - functions = { - { name = "can_use", args = { "string" } }, - { name = "charges_default", rval = "int", args = { } }, - { name = "charges_to_use", rval = "int", args = { } }, - { name = "count_by_charges", rval = "bool", args = { } }, - { name = "get_item_type_string", rval = "string", args = { } }, - { name = "has_use", rval = "bool", args = { } }, - { name = "invoke", rval = "int", args = { "player", "item", "tripoint" } }, - { name = "invoke", rval = "int", args = { "player", "item", "tripoint", "string" } }, - { name = "maximum_charges", rval = "int", args = { } }, - { name = "nname", rval = "string", args = { "int" } }, - { name = "tick", rval = "int", args = { "player", "item", "tripoint" } }, - } - }, - trap = { - int_id = "trap_id", - string_id = "trap_str_id", - attributes = { - id = { type = "trap_str_id" }, - loadid = { type = "trap_id" }, - color = { type = "nc_color" }, - sym = { type = "int" }, - }, - functions = { - { name = "can_see", rval = "bool", args = { "tripoint", "player" } }, - { name = "detect_trap", rval = "bool", args = { "tripoint", "player" } }, - { name = "funnel_turns_per_charge", rval = "float", args = { "float" } }, - { name = "get_avoidance", rval = "int", args = { } }, - { name = "get_difficulty", rval = "int", args = { } }, - { name = "get_visibility", rval = "int", args = { } }, - { name = "is_3x3_trap", rval = "bool", args = { } }, - { name = "is_benign", rval = "bool", args = { } }, - { name = "is_funnel", rval = "bool", args = { } }, - { name = "is_null", rval = "bool", args = { } }, - { name = "on_disarmed", rval = nil, args = { "map", "tripoint" } }, - { name = "trigger", rval = nil, args = { "tripoint", "Creature" } }, - { name = "triggered_by_item", rval = "bool", args = { "item" } }, - } - }, - w_point = { - attributes = { - temperature = { type = "float" }, - humidity = { type = "float" }, - pressure = { type = "float" }, - windpower = { type = "float" }, - acidic = { type = "bool" } - }, - functions = { - } - } -} - -enums = { - overmap_direction = { - "overmap_direction::invalid", - "overmap_direction::none", - "overmap_direction::north", - "overmap_direction::east", - "overmap_direction::south", - "overmap_direction::west", - }, - body_part = { - "bp_torso", - "bp_head", - "bp_eyes", - "bp_mouth", - "bp_arm_l", - "bp_arm_r", - "bp_hand_l", - "bp_hand_r", - "bp_leg_l", - "bp_leg_r", - "bp_foot_l", - "bp_foot_r", - "num_bp", - }, - hp_part = { - "hp_head", - "hp_torso", - "hp_arm_l", - "hp_arm_r", - "hp_leg_l", - "hp_leg_r", - "num_hp_parts", - }, - side = { - "side::BOTH", - "side::LEFT", - "side::RIGHT" - }, - phase_id = { - "PNULL", - "SOLID", - "LIQUID", - "GAS", - "PLASMA", - }, - m_size = { - "MS_TINY", - "MS_SMALL", - "MS_MEDIUM", - "MS_LARGE", - "MS_HUGE", - }, - npc_attitude = { - "NPCATT_NULL", - "NPCATT_TALK", - "NPCATT_LEGACY_1", - "NPCATT_FOLLOW", - "NPCATT_LEGACY_2", - "NPCATT_LEAD", - "NPCATT_WAIT", - "NPCATT_LEGACY_6", - "NPCATT_MUG", - "NPCATT_WAIT_FOR_LEAVE", - "NPCATT_KILL", - "NPCATT_FLEE", - "NPCATT_LEGACY_3", - "NPCATT_HEAL", - "NPCATT_LEGACY_4", - "NPCATT_LEGACY_5", - }, - game_message_type = { - "m_good", - "m_bad", - "m_mixed", - "m_warning", - "m_info", - "m_neutral", - "m_debug", - "m_headshot", - "m_critical", - "m_grazing", - }, - season_type = { - "SPRING", - "SUMMER", - "AUTUMN", - "WINTER", - }, - add_type = { - "ADD_NULL", - "ADD_CAFFEINE", - "ADD_ALCOHOL", - "ADD_SLEEP", - "ADD_PKILLER", - "ADD_SPEED", - "ADD_CIG", - "ADD_COKE", - "ADD_CRACK", - "ADD_MUTAGEN", - "ADD_DIAZEPAM", - "ADD_MARLOSS_R", - "ADD_MARLOSS_B", - "ADD_MARLOSS_Y", - }, - field_id = { - "fd_null", - "fd_blood", - "fd_bile", - "fd_gibs_flesh", - "fd_gibs_veggy", - "fd_web", - "fd_slime", - "fd_acid", - "fd_sap", - "fd_sludge", - "fd_fire", - "fd_rubble", - "fd_smoke", - "fd_toxic_gas", - "fd_tear_gas", - "fd_nuke_gas", - "fd_gas_vent", - "fd_fire_vent", - "fd_flame_burst", - "fd_electricity", - "fd_fatigue", - "fd_push_items", - "fd_shock_vent", - "fd_acid_vent", - "fd_plasma", - "fd_laser", - "fd_spotlight", - "fd_dazzling", - "fd_blood_veggy", - "fd_blood_insect", - "fd_blood_invertebrate", - "fd_gibs_insect", - "fd_gibs_invertebrate", - "fd_cigsmoke", - "fd_weedsmoke", - "fd_cracksmoke", - "fd_methsmoke", - "fd_bees", - "fd_incendiary", - "fd_relax_gas", - "fd_fungal_haze", - "fd_hot_air1", - "fd_hot_air2", - "fd_hot_air3", - "fd_hot_air4", - "fd_fungicidal_gas", - "num_fields", - } -} - -global_functions = { - add_msg = { - cpp_name = "add_msg_wrapper", - args = { "string" }, - argnames = { "message" }, - rval = nil, - desc = "Write a message to the game's standard message window." - }, - query_yn = { - cpp_name = "query_yn_wrapper", - args = { "string" }, - argnames = { "message" }, - rval = "bool" - }, - popup = { - cpp_name = "popup_wrapper", - args = { "string" }, - rval = nil - }, - string_input_popup = { - cpp_name = "string_input_popup_wrapper", - args = { "string", "int", "string" }, - rval = "string" - }, - create_uimenu = { - cpp_name = "create_uilist_no_cancel", - args = {}, - rval = "uilist&" - }, - create_uilist = { - cpp_name = "create_uilist", - args = {}, - rval = "uilist&" - }, - get_terrain_type = { - cpp_name = "get_terrain_type", - args = {"int"}, - rval = "ter_t&" - }, - rng = { - cpp_name = "rng", - args = {"int", "int"}, - rval = "int" - }, - one_in = { - cpp_name = "one_in", - args = {"int"}, - rval = "bool" - }, - distance = { - cpp_name = "rl_dist", - args = {"int", "int", "int", "int"}, - rval = "int" - }, - trig_dist = { - cpp_name = "trig_dist", - args = {"int", "int", "int", "int"}, - rval = "int" - }, - add_item_to_group = { - cpp_name = "item_controller->add_item_to_group", - args = { "string", "string", "int" }, - rval = "bool" - }, - get_monster_at = { - cpp_name = "get_monster_at", - args = { "tripoint" }, - rval = "monster&", - desc = "Returns a reference to monster at given tripoint, *or* nil if there is no monster." - }, - get_critter_at = { - cpp_name = "get_critter_at", - args = { "tripoint" }, - rval = "Creature&", - desc = "Returns a reference to creature at given tripoint, *or* nil if there is no creature." - }, - get_npc_at = { - cpp_name = "g->critter_at", - args = { "tripoint" }, - rval = "npc&", - desc = "Returns a reference to npc at given tripoint, *or* nil if there is no npc." - }, - create_monster = { - cpp_name = "create_monster", - args = { "mtype_id", "tripoint" }, - rval = "monster&", - desc = "Creates and spawns a new monster of given type. Returns a refernce to it, *or* nil if it could not be spawned." - }, - get_calendar_turn = { - cpp_name = "get_calendar_turn_wrapper", - args = {}, - rval = "calendar&" - }, - get_time_duration = { - cpp_name = "get_time_duration_wrapper", - args = { "int" }, - rval = "time_duration", - desc = "Constructs `time_duration` with given `int` value (which is number of turns). You can also use TURNS(n), MINUTES(n), HOURS(n) and DAYS(n) wrapper functions from `autoexec.lua`." - }, - -- Returns id of overmap terrain on given overmap with given tripoint in global overmap terrain coordinates. - -- Use `game.get_omt_id (g:get_cur_om(), player:global_omt_location())` to return id of overmap terrain of current player location. - get_omt_id = { - cpp_name = "get_omt_id", - args = { "overmap", "tripoint" }, - rval = "string" - }, - -- Returns enum, indicating direction of overmap terrain on given overmap with given tripoint in global overmap terrain coordinates. - -- Possible return values are in `overmap_direction` in `enums` section above. - -- Use `game.get_omt_dir (g:get_cur_om(), player:global_omt_location())` to return direction of overmap terrain of current player location. - get_omt_dir = { - cpp_name = "get_omt_dir", - args = { "overmap", "tripoint" }, - rval = "overmap_direction" - }, - omap_choose_point = { - cpp_name = "ui::omap::choose_point", - args = { "tripoint" }, - rval = "tripoint" - } -} - -function table_unpack_wrapper(args) - if args then - if table.unpack then - return table.unpack(args) - elseif unpack then - return unpack(args) - else - return nil - end - else - return nil - end -end - --- This extracts optional arguments. --- Example: --- { name = "add_effect", rval = nil, args = { "efftype_id", "time_duration" }, optional_args = { "body_part", "bool", "int", "bool" } }, --- As a result of previous definition is extracted, forrowing definitions is gained. --- { name = "add_effect", rval = nil, args = { "efftype_id", "time_duration", "body_part" } }, --- { name = "add_effect", rval = nil, args = { "efftype_id", "time_duration", "body_part", "bool" } }, --- { name = "add_effect", rval = nil, args = { "efftype_id", "time_duration", "body_part", "bool", "int" } }, --- { name = "add_effect", rval = nil, args = { "efftype_id", "time_duration", "body_part", "bool", "int", "bool" } }, -for class_name, value in pairs(classes) do - local new_functions = { } - for _, func in ipairs(value.functions) do - if func.optional_args then - local i = 0 - while i <= #func.optional_args do - local t = { - name = func.name, - rval = func.rval, - args = { table_unpack_wrapper(func.args) } -- copy args - } - local j = 1 - while j <= i do - table.insert(t.args, func.optional_args[j]) - j = j + 1 - end - table.insert(new_functions, t) - i = i + 1 - end - end - end - for _, new_func in ipairs(new_functions) do - table.insert(value.functions, new_func) - end -end - ---[[ -Currently, for each function in each class, the bindings generator creates a matching function in -each of the parent classes. For example is_player, which is defined in Creature and player. -Because it's in Creature and monster inherits it from there, the generator adds a wrapper to the -metatable of the monster class that calls is_player on a monster object. -However, it creates the same "wrapper" for the player class (same scenario: it inherits it from -Creature). -Now player::is_player is wrapped twice: once through the heritage from Creature and once on its own. - -The following snippet tries to correct this. It simply removes all the redundantly declared -functions in the subclasses. ---]] - -for class_name, value in pairs(classes) do - -- Collect all defined functions of the *parent* classes in this table - local existing = { }; - value = classes[value.parent] - while value do - for _, func in ipairs(value.functions) do - local n = func.name .. "_" .. table.concat(func.args, "|") - existing[n] = true - end - value = classes[value.parent] - end - -- Now back to the actual class, remove all the functions that are in the table - -- and therefor exist in at least on of the parent classes. - value = classes[class_name] - local i = 1 - while i <= #value.functions do - local func = value.functions[i] - local n = func.name .. "_" .. table.concat(func.args, "|") - if existing[n] then - table.remove(value.functions, i) - else - i = i + 1 - end - end -end - --- This adds the int_id wrappers from the class definition as real classes. --- All int_ids have the same interface, so we only need to add some mark to T, that this class --- T has an int_id of some name. --- In the class definition: add "int_id" = "XXX" (XXX is the typedef id that is used by C++). -new_classes = {} -for name, value in pairs(classes) do - if value.int_id then - -- This is the common int_id interface: - local t = { - by_value = true, - has_equal = true, - -- IDs *could* be constructed from int, but where does the Lua script get the int from? - -- The int is only exposed as int_id, so Lua should never know about it. - attributes = { }, - -- Copy and default constructor - new = { { value.int_id }, { } }, - functions = { - -- Use with care, only for displaying the value for debugging purpose! - { name = "to_i", rval = "int", args = { } }, - { name = "obj", rval = name .. "&", args = { } }, - } - } - if value.string_id then - -- Allow conversion from int_id to string_id - t[#t.functions] = { name = "id", rval = value.string_id, args = { } } - -- And creation of an int_id from a string_id - t.new = { { value.string_id }, { } } - end - new_classes[value.int_id] = t - end - -- Very similar to int_id above - if value.string_id then - local t = { - by_value = true, - has_equal = true, - -- Copy and default constructor and construct from plain string. - new = { { value.string_id }, { }, { "string" } }, - attributes = { }, - functions = { - { name = "str", rval = "string", args = { } }, - { name = "is_valid", rval = "bool", args = { } }, - { name = "obj", rval = name .. "&", args = { } }, - } - } - if value.int_id then - t.functions[#t.functions] = { name = "id", rval = value.int_id, args = { } } - end - new_classes[value.string_id] = t - end -end -for name, value in pairs(new_classes) do - classes[name] = value -end -new_classes = nil diff --git a/lua/dkjson.lua b/lua/dkjson.lua deleted file mode 100644 index b7475ba180ff8..0000000000000 --- a/lua/dkjson.lua +++ /dev/null @@ -1,843 +0,0 @@ - -- Module options: - local always_try_using_lpeg = true - local register_global_module_table = false - local global_module_name = 'json' - - --[==[ - -David Kolf's JSON module for Lua 5.1/5.2 -======================================== - -*Version 2.4* - -In the default configuration this module writes no global values, not even -the module table. Import it using - - json = require ("dkjson") - -In environments where `require` or a similiar function are not available -and you cannot receive the return value of the module, you can set the -option `register_global_module_table` to `true`. The module table will -then be saved in the global variable with the name given by the option -`global_module_name`. - -Exported functions and values: - -`json.encode (object [, state])` --------------------------------- - -Create a string representing the object. `Object` can be a table, -a string, a number, a boolean, `nil`, `json.null` or any object with -a function `__tojson` in its metatable. A table can only use strings -and numbers as keys and its values have to be valid objects as -well. It raises an error for any invalid data types or reference -cycles. - -`state` is an optional table with the following fields: - - - `indent` - When `indent` (a boolean) is set, the created string will contain - newlines and indentations. Otherwise it will be one long line. - - `keyorder` - `keyorder` is an array to specify the ordering of keys in the - encoded output. If an object has keys which are not in this array - they are written after the sorted keys. - - `level` - This is the initial level of indentation used when `indent` is - set. For each level two spaces are added. When absent it is set - to 0. - - `buffer` - `buffer` is an array to store the strings for the result so they - can be concatenated at once. When it isn't given, the encode - function will create it temporary and will return the - concatenated result. - - `bufferlen` - When `bufferlen` is set, it has to be the index of the last - element of `buffer`. - - `tables` - `tables` is a set to detect reference cycles. It is created - temporary when absent. Every table that is currently processed - is used as key, the value is `true`. - -When `state.buffer` was set, the return value will be `true` on -success. Without `state.buffer` the return value will be a string. - -`json.decode (string [, position [, null]])` --------------------------------------------- - -Decode `string` starting at `position` or at 1 if `position` was -omitted. - -`null` is an optional value to be returned for null values. The -default is `nil`, but you could set it to `json.null` or any other -value. - -The return values are the object or `nil`, the position of the next -character that doesn't belong to the object, and in case of errors -an error message. - -Two metatables are created. Every array or object that is decoded gets -a metatable with the `__jsontype` field set to either `array` or -`object`. If you want to provide your own metatables use the syntax - - json.decode (string, position, null, objectmeta, arraymeta) - -To prevent the assigning of metatables pass `nil`: - - json.decode (string, position, null, nil) - -`.__jsonorder` -------------------------- - -`__jsonorder` can overwrite the `keyorder` for a specific table. - -`.__jsontype` ------------------------- - -`__jsontype` can be either `"array"` or `"object"`. This value is only -checked for empty tables. (The default for empty tables is `"array"`). - -`.__tojson (self, state)` ------------------------------------- - -You can provide your own `__tojson` function in a metatable. In this -function you can either add directly to the buffer and return true, -or you can return a string. On errors nil and a message should be -returned. - -`json.null` ------------ - -You can use this value for setting explicit `null` values. - -`json.version` --------------- - -Set to `"dkjson 2.4"`. - -`json.quotestring (string)` ---------------------------- - -Quote a UTF-8 string and escape critical characters using JSON -escape sequences. This function is only necessary when you build -your own `__tojson` functions. - -`json.addnewline (state)` -------------------------- - -When `state.indent` is set, add a newline to `state.buffer` and spaces -according to `state.level`. - -LPeg support ------------- - -When the local configuration variable `always_try_using_lpeg` is set, -this module tries to load LPeg to replace the `decode` function. The -speed increase is significant. You can get the LPeg module at - . -When LPeg couldn't be loaded, the pure Lua functions stay active. - -In case you don't want this module to require LPeg on its own, -disable the option `always_try_using_lpeg` in the options section at -the top of the module. - -In this case you can later load LPeg support using - -### `json.use_lpeg ()` - -Require the LPeg module and replace the functions `quotestring` and -and `decode` with functions that use LPeg patterns. -This function returns the module table, so you can load the module -using: - - json = require "dkjson".use_lpeg() - -Alternatively you can use `pcall` so the JSON module still works when -LPeg isn't found. - - json = require "dkjson" - pcall (json.use_lpeg) - -### `json.using_lpeg` - -This variable is set to `true` when LPeg was loaded successfully. - ---------------------------------------------------------------------- - -Contact -------- - -You can contact the author by sending an e-mail to 'david' at the -domain 'dkolf.de'. - ---------------------------------------------------------------------- - -*Copyright (C) 2010-2013 David Heiko Kolf* - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - - - diff --git a/lua/generate_wikidocs.lua b/lua/generate_wikidocs.lua deleted file mode 100644 index 6750dce043fef..0000000000000 --- a/lua/generate_wikidocs.lua +++ /dev/null @@ -1,58 +0,0 @@ -dofile "class_definitions.lua" - -io.write("=== Global Functions ===\n") - -function write_function(name, func) - io.write("* ") - io.write("'''"..(func.rval or "void").."'''") - io.write(" ") - io.write(name) - io.write("(") - for key, arg in ipairs(func.args) do - io.write(arg) - if func.argnames then - io.write(" "..func.argnames[key]) - end - if next(func.args, key) then - io.write(", ") - end - end - io.write(")\n") - - if func.desc then - io.write("** "..func.desc.."\n") - end -end - -function write_attribute(name, attribute) - io.write("* ") - io.write("'''"..attribute.type.."'''") - io.write(" ") - io.write(name) - if not attribute.writable then - io.write(" ''read-only''") - end - io.write("\n") - - if attribute.desc then - io.write("** "..attribute.desc.."\n") - end -end - -for name, func in pairs(global_functions) do - write_function(name, func) -end - -for classname, class in pairs(classes) do - io.write("=== "..classname.." ===\n") - - io.write("==== Functions ====\n") - for name, func in pairs(class.functions) do - write_function(name, func) - end - - io.write("==== Attributes ====\n") - for name, attr in pairs(class.attributes) do - write_attribute(name, attr) - end -end diff --git a/lua/json_verifier.lua b/lua/json_verifier.lua deleted file mode 100644 index 59860198fb8a7..0000000000000 --- a/lua/json_verifier.lua +++ /dev/null @@ -1,175 +0,0 @@ --- script to verify CDDA JSON(verifies all mods) --- run this script with: lua lua/json_verifier.lua --- --- requires luafilesystem to scan for files, installation instructions: --- arch linux: pacman -S lua-filesystem --- debian linux: aptitude install liblua5.1-filesystem0 --- other linux distributions: search for "lua file system" in the --- package manager of your choice - -local json = require("lua/dkjson") -local lfs = require("lfs") - -local exit_code = 0 - --- function to read a file completely into a string -function read_file(filename) - local f = io.open(filename, "r") - local content = f:read("*all") - f:close() - return content -end - -decode_cache = {} - --- parse the JSON of an entire cataclysm file -function parse_cata_json(filename, handler) - local root, pos, err - if not decode_cache[filename] then - local content = read_file(filename) - - root, pos, err = json.decode(content, 1, nil) - decode_cache[filename] = root - else - root = decode_cache[filename] - end - - if err then - print("Error in ", filename ,":", err) - os.exit(1) - else - -- top level should be a json array - if type(root) ~= "table" then - print("Wrong root element to JSON file ", filename, " :", type(root)) - end - - for _, entry in ipairs(root) do - if not entry.type then - print("Invalid entry type in ", filename, ": ", entry.type) - end - if handler[entry.type] then - handler[entry.type](entry, filename) - end - end - end -end - -local definitions = {} -local material_definitions = {} -function load_item_definition(entry, filename) - -- store that this item was defined - definitions[entry.id] = true -end - --- define load_definition handlers -local load_definition = {} -local item_types = { "BOOK", "TOOL", "GUN", "GUNMOD", "TOOL_ARMOR", "ARMOR", "BIONIC_ITEM", "GENERIC", "AMMO", "CONTAINER", "COMESTIBLE", "VAR_VEH_PART" } -for _, item_type in ipairs(item_types) do - load_definition[item_type] = load_item_definition -end - --- load definition handler for materials -function load_material_definition(entry, filename) - -- store that this material was defined - material_definitions[entry.ident] = true -end -load_definition.material = load_material_definition - -local verify_handler = {} - -function ensure_definition(id, filename, parent_id) - if not definitions[id] then - -- signify that something went wrong - exit_code = 1 - - print("Trying to access non-existent item id ", id, " in ", filename, "(", parent_id, ")") - end -end - -function ensure_material_definition(id, filename, parent_id) - if not material_definitions[id] then - -- signify that something went wrong - exit_code = 1 - - print("Trying to access non-existent material id ", id, " in ", filename, "(", parent_id, ")") - end -end - -verify_handler.recipe = function(entry, filename) - ensure_definition(entry.result, filename, entry.result) - for _, alternatives in ipairs(entry.components) do - for _, item in ipairs(alternatives) do - ensure_definition(item[1], filename, entry.result) - end - end - if entry.tools then - for _, alternatives in ipairs(entry.tools) do - for _, item in ipairs(alternatives) do - ensure_definition(item[1], filename, entry.result) - end - end - end -end - -function verify_item_definition(entry, filename) - local materials - if not entry.material or entry.material == "" then - return - elseif type(entry.material) == "string" then - materials = { entry.material } - elseif type(entry.material == "table") then - materials = entry.material - else - exit_code = 1 - print("Invalid material for ", entry.id, " in ", filename) - end - - for _, material in ipairs(materials) do - ensure_material_definition(material, filename, entry.id) - end -end - -for _, item_type in ipairs(item_types) do - verify_handler[item_type] = verify_item_definition -end - - -function string.endswith(mystr, myend) - return myend=="" or string.sub(mystr,string.len(mystr)-string.len(myend)+1)==myend -end - - -function load_all_jsons_recursive(path, handler) - for file in lfs.dir(path) do - if file ~= "." and file ~= ".." then - local f = path..'/'..file - - local attr = lfs.attributes(f) - if attr.mode == "directory" then - load_all_jsons_recursive(f, handler) - elseif attr.mode == "file" and string.endswith(f, ".json") then - parse_cata_json(f, handler) - end - end - end -end - -function load_all_jsons(handler) - load_all_jsons_recursive("data/json", handler) - load_all_jsons_recursive("data/mods", handler) -end - --- first load all item definitions -load_all_jsons(load_definition) - --- some hardcoded item definitions -definitions["cvd_machine"] = true -definitions["corpse"] = true -definitions["apparatus"] = true -definitions["toolset"] = true -definitions["fire"] = true - --- then verify recipes -load_all_jsons(verify_handler) - -os.exit(exit_code) diff --git a/lua/log.lua b/lua/log.lua deleted file mode 100644 index 0bb896fdf9dc2..0000000000000 --- a/lua/log.lua +++ /dev/null @@ -1,43 +0,0 @@ -local log = { - - output_path = "./config/lua-log.log", - datetime_format= "%Y-%m-%d %H:%M:%S" - -} - -log.init = function(output_path) - - if (output_path ~= nil) then - log.output_path = output_path - end - return log - -end - -log.clear = function() - - local output_file = io.open (log.output_path, "w+") - io.close(output_file) - -end - -log.message = function(message_text, ...) - - local message_text_formatted = "" - - if (#{...} > 0) then - message_text_formatted = string.format(message_text, ...) - else - message_text_formatted = tostring(message_text) - end - - local output_text = os.date(log.datetime_format).."|"..message_text_formatted.."\n" - local output_file = io.open (log.output_path, "a") - - io.output(output_file) - io.write(output_text) - io.close(output_file) - -end - -return log diff --git a/msvc-full-features/Cataclysm-vcpkg-static.vcxproj b/msvc-full-features/Cataclysm-vcpkg-static.vcxproj index 5c1385bec301e..74f03efd1771e 100644 --- a/msvc-full-features/Cataclysm-vcpkg-static.vcxproj +++ b/msvc-full-features/Cataclysm-vcpkg-static.vcxproj @@ -102,7 +102,7 @@ Level1 Disabled true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) false false false @@ -132,7 +132,7 @@ MaxSpeed true true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) true false false @@ -162,7 +162,7 @@ Level1 Disabled true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) false false false @@ -192,7 +192,7 @@ MaxSpeed true true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) true false false diff --git a/msvc-full-features/Cataclysm-vcpkg.vcxproj b/msvc-full-features/Cataclysm-vcpkg.vcxproj index 47d1a9cd6b037..b92886148d27c 100644 --- a/msvc-full-features/Cataclysm-vcpkg.vcxproj +++ b/msvc-full-features/Cataclysm-vcpkg.vcxproj @@ -102,7 +102,7 @@ Level1 Disabled true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) false false false @@ -130,7 +130,7 @@ MaxSpeed true true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) true false false @@ -158,7 +158,7 @@ Level1 Disabled true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) false false false @@ -186,7 +186,7 @@ MaxSpeed true true - _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LUA;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;SDL_SOUND;TILES;LOCALIZE;USE_VCPKG;USE_WINMAIN;%(PreprocessorDefinitions) true false false diff --git a/msvc-full-features/Cataclysm.vcxproj b/msvc-full-features/Cataclysm.vcxproj index deb7615533511..1fcc93895971d 100755 --- a/msvc-full-features/Cataclysm.vcxproj +++ b/msvc-full-features/Cataclysm.vcxproj @@ -116,13 +116,13 @@ true Default /LTCG:OFF %(AdditionalOptions) - SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;%(AdditionalDependencies) prebuild.cmd - Get version string and generate lua bindings + Get version string true @@ -148,9 +148,9 @@ true Default /LTCG:OFF %(AdditionalOptions) - $(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + $(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) true - SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;%(AdditionalDependencies) @@ -187,13 +187,13 @@ true Default /LTCG:OFF %(AdditionalOptions) - SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;%(AdditionalDependencies) prebuild.cmd - Get version string and generate lua bindings + Get version string true @@ -222,9 +222,9 @@ true Default /LTCG:OFF %(AdditionalOptions) - $(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + $(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) true - SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;%(AdditionalDependencies) diff --git a/msvc-full-features/Cataclysm_lib.vcxproj b/msvc-full-features/Cataclysm_lib.vcxproj index 4abca8db661dd..5cd20ccbdf617 100755 --- a/msvc-full-features/Cataclysm_lib.vcxproj +++ b/msvc-full-features/Cataclysm_lib.vcxproj @@ -126,7 +126,7 @@ prebuild.cmd - Get version string and generate lua bindings + Get version string @@ -155,7 +155,7 @@ prebuild.cmd - Get version string and generate lua bindings + Get version string @@ -185,7 +185,7 @@ prebuild.cmd - Get version string and generate lua bindings + Get version string @@ -215,7 +215,7 @@ prebuild.cmd - Get version string and generate lua bindings + Get version string diff --git a/msvc-full-features/Tests.vcxproj b/msvc-full-features/Tests.vcxproj index 54750ea8ea8f3..796f3efcd62db 100755 --- a/msvc-full-features/Tests.vcxproj +++ b/msvc-full-features/Tests.vcxproj @@ -107,7 +107,7 @@ Use Level1 Disabled - $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;$(LUADIR)include;%(AdditionalIncludeDirectories) + $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;%(AdditionalIncludeDirectories) SDL_MAIN_HANDLED;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true true @@ -117,8 +117,8 @@ Console - $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) - libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + libiconv.lib;libintl.lib;%(AdditionalDependencies) true @@ -129,7 +129,7 @@ Use Level1 Disabled - $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;$(LUADIR)include;%(AdditionalIncludeDirectories) + $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;%(AdditionalIncludeDirectories) SDL_MAIN_HANDLED;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true false @@ -144,8 +144,8 @@ Console - $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) - libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + libiconv.lib;libintl.lib;%(AdditionalDependencies) true Default @@ -162,7 +162,7 @@ MaxSpeed true true - $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;$(LUADIR)include;%(AdditionalIncludeDirectories) + $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;%(AdditionalIncludeDirectories) SDL_MAIN_HANDLED;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true false @@ -174,8 +174,8 @@ Console true true - $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) - libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + libiconv.lib;libintl.lib;%(AdditionalDependencies) true @@ -188,7 +188,7 @@ MaxSpeed true true - $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;$(LUADIR)include;%(AdditionalIncludeDirectories) + $(VCInstallDir)UnitTest\include;..\src;$(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;%(AdditionalIncludeDirectories) SDL_MAIN_HANDLED;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true false @@ -204,8 +204,8 @@ Console true true - $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) - libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;$(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + libiconv.lib;libintl.lib;%(AdditionalDependencies) true Default diff --git a/msvc-full-features/WINDEPEND.props b/msvc-full-features/WINDEPEND.props index 4cb1fc0ce78bc..17c2ddb61290c 100644 --- a/msvc-full-features/WINDEPEND.props +++ b/msvc-full-features/WINDEPEND.props @@ -8,19 +8,18 @@ $(WINDEPEND)SDL2_mixer-2.0.4\ $(WINDEPEND)SDL2_image-2.0.4\ $(WINDEPEND)gettext\ - $(WINDEPEND)lua-5.3.3\ <_PropertySheetDisplayName>WINDEPEND - $(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;$(LUADIR)include;%(AdditionalIncludeDirectories) - SDL_SOUND;TILES;LUA;LOCALIZE;%(PreprocessorDefinitions) + $(SDL2ROOT)include;$(SDL2TTF)include;$(SDL2MIXER)include;$(SDL2IMAGE)include;$(GETTEXT)include;%(AdditionalIncludeDirectories) + SDL_SOUND;TILES;LOCALIZE;%(PreprocessorDefinitions) - $(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);$(LUADIR)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) - SDL2.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;Lua.lib;%(AdditionalDependencies) + $(SDL2ROOT)lib\$(PlatformTarget);$(SDL2TTF)lib\$(PlatformTarget);$(SDL2MIXER)lib\$(PlatformTarget);$(SDL2IMAGE)lib\$(PlatformTarget);$(GETTEXT)lib\$(PlatformTarget);%(AdditionalLibraryDirectories) + SDL2.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;libiconv.lib;libintl.lib;%(AdditionalDependencies) @@ -48,9 +47,5 @@ $(GETTEXT) true - - $(LUADIR) - true - \ No newline at end of file diff --git a/msvc-full-features/distribute.bat b/msvc-full-features/distribute.bat index 907105d4c4124..f446875564120 100644 --- a/msvc-full-features/distribute.bat +++ b/msvc-full-features/distribute.bat @@ -5,7 +5,6 @@ xcopy /s /e /i ..\data distribution\data xcopy /s /e /i ..\config distribution\config xcopy /s /e /i ..\gfx distribution\gfx xcopy /s /e /i ..\lang\mo distribution\lang\mo -xcopy /s /e /i ..\lua distribution\lua copy ..\Cataclysm.exe distribution\ echo Distribution files has been put into `distribution\' directory. pause diff --git a/msvc-full-features/prebuild.cmd b/msvc-full-features/prebuild.cmd index 9d1b421d11220..184e543fce402 100644 --- a/msvc-full-features/prebuild.cmd +++ b/msvc-full-features/prebuild.cmd @@ -1,9 +1,6 @@ @echo off SETLOCAL -cd ..\src\lua -echo Generating lua bindings -lua generate_bindings.lua cd ..\..\msvc-full-features echo Done diff --git a/snapcraft.yaml b/snapcraft.yaml index 369f12fed2976..f1d2ff64034aa 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -22,8 +22,7 @@ apps: parts: cataclysm: plugin: make - build-packages: [astyle, ccache, build-essential, libncurses5-dev, libncursesw5-dev, lua5.2, liblua5.2-dev, gettext] - stage-packages: [liblua5.2-0] - override-build: make NATIVE=linux64 RELEASE=1 LTO=1 LUA=1 LOCALIZE=1 CCACHE=1 USE_HOME_DIR=1 && mv * $SNAPCRAFT_PART_INSTALL - stage: [data, lua, cataclysm, cataclysm-launcher, usr] - prime: [data, lua, cataclysm, cataclysm-launcher, usr] + build-packages: [astyle, ccache, build-essential, libncurses5-dev, libncursesw5-dev, gettext] + override-build: make NATIVE=linux64 RELEASE=1 LTO=1 LOCALIZE=1 CCACHE=1 USE_HOME_DIR=1 && mv * $SNAPCRAFT_PART_INSTALL + stage: [data, cataclysm, cataclysm-launcher, usr] + prime: [data, cataclysm, cataclysm-launcher, usr] diff --git a/src/Android.mk b/src/Android.mk index 3fa5a998b1743..cffaed5930156 100644 --- a/src/Android.mk +++ b/src/Android.mk @@ -14,11 +14,11 @@ LOCAL_CPP_FEATURES := exceptions rtti FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) -LOCAL_SHARED_LIBRARIES := SDL2 SDL2_mixer SDL2_image SDL2_ttf lua libintl-lite mpg123 +LOCAL_SHARED_LIBRARIES := SDL2 SDL2_mixer SDL2_image SDL2_ttf libintl-lite mpg123 LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -LOCAL_CFLAGS += -DTILES=1 -DSDL_SOUND=1 -DLUA=1 -DCATA_NO_CPP11_STRING_CONVERSIONS=1 -DLOCALIZE=1 -Wextra -Wall -fsigned-char -ffast-math +LOCAL_CFLAGS += -DTILES=1 -DSDL_SOUND=1 -DCATA_NO_CPP11_STRING_CONVERSIONS=1 -DLOCALIZE=1 -Wextra -Wall -fsigned-char -ffast-math LOCAL_LDFLAGS += $(LOCAL_CFLAGS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6326532e6d372..ac398f1b0122e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,12 +54,6 @@ IF(TILES) target_link_libraries(cataclysm-tiles libcataclysm-tiles) target_compile_definitions(libcataclysm-tiles PUBLIC TILES ) - IF (LUA) - ADD_DEPENDENCIES(libcataclysm-tiles lua_bindings) - target_include_directories(libcataclysm-tiles PUBLIC ${LUA_INCLUDE_DIR}) - target_link_libraries(libcataclysm-tiles ${LUA_LIBRARIES}) - ENDIF(LUA) - IF (LOCALIZE) target_include_directories(libcataclysm-tiles PUBLIC ${LIBINTL_INCLUDE_DIR} @@ -162,12 +156,6 @@ IF(CURSES) target_link_libraries(cataclysm libcataclysm) - IF (LUA) - ADD_DEPENDENCIES(libcataclysm lua_bindings) - target_include_directories(libcataclysm PUBLIC ${LUA_INCLUDE_DIR}) - target_link_libraries(libcataclysm ${LUA_LIBRARIES}) - ENDIF(LUA) - IF (LOCALIZE) target_include_directories(libcataclysm PUBLIC ${LIBINTL_INCLUDE_DIR} @@ -224,11 +212,6 @@ IF(MINGW AND NOT RELEASE) ${RuntimeLib_STDC_PP_6} ${RuntimeLib_WINPTHREAD_1} ) - IF (LUA) - SET(RuntimeLib_LUA - ${LUA_LIBRARIES} - ) - ENDIF (LUA) IF (LOCALIZE) find_library(RuntimeLib_iconv "libiconv-2") find_library(RuntimeLib_intl "libintl-8") @@ -298,7 +281,6 @@ IF(MINGW AND NOT RELEASE) ENDIF (TILES) install(FILES ${RuntimeLib_GCC_ALL} ${RuntimeLib_LOCALIZE} - ${RuntimeLib_LUA} ${RuntimeLib_SDL} ${RuntimeLib_SDL_SOUND} DESTINATION ${BIN_PREFIX} diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index 91ce2ad293aa2..743c1cc12080e 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -5,7 +5,6 @@ #include "action.h" #include "advanced_inv.h" -#include "catalua.h" #include "clzones.h" #include "construction.h" #include "craft_command.h" @@ -1891,14 +1890,6 @@ void activity_handlers::train_finish( player_activity *act, player *p ) pgettext( "memorial_female", "Reached skill level %1$d in %2$s." ), new_skill_level, skill_name ); } - const std::string skill_increase_source = "training"; - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( p->getID() ); - lua_callback_args_info.emplace_back( skill_increase_source ); - lua_callback_args_info.emplace_back( sk.str() ); - lua_callback_args_info.emplace_back( new_skill_level ); - lua_callback( "on_player_skill_increased", lua_callback_args_info ); - lua_callback( "on_skill_increased" ); // Legacy callback act->set_to_null(); return; } diff --git a/src/activity_type.cpp b/src/activity_type.cpp index c4130f18aac82..1d4e53fc8ddd0 100644 --- a/src/activity_type.cpp +++ b/src/activity_type.cpp @@ -5,7 +5,6 @@ #include "activity_handlers.h" #include "assign.h" -#include "catalua.h" #include "debug.h" #include "json.h" #include "player.h" @@ -86,12 +85,7 @@ void activity_type::call_do_turn( player_activity *act, player *p ) const { const auto &pair = activity_handlers::do_turn_functions.find( id_ ); if( pair != activity_handlers::do_turn_functions.end() ) { - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( act->id().str() ); - lua_callback_args_info.emplace_back( p->getID() ); - lua_callback( "on_activity_call_do_turn_started", lua_callback_args_info ); pair->second( act, p ); - lua_callback( "on_activity_call_do_turn_finished", lua_callback_args_info ); } } @@ -99,12 +93,7 @@ bool activity_type::call_finish( player_activity *act, player *p ) const { const auto &pair = activity_handlers::finish_functions.find( id_ ); if( pair != activity_handlers::finish_functions.end() ) { - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( act->id().str() ); - lua_callback_args_info.emplace_back( p->getID() ); - lua_callback( "on_activity_call_finish_started", lua_callback_args_info ); pair->second( act, p ); - lua_callback( "on_activity_call_finish_finished", lua_callback_args_info ); return true; } return false; diff --git a/src/calendar.h b/src/calendar.h index db08f60a8bf66..7afd8ad3b5e77 100644 --- a/src/calendar.h +++ b/src/calendar.h @@ -153,7 +153,7 @@ class calendar /** * Accessor for current turn_number. * - * @returns Current turn number (`get_turn()` function for `calendar` class in Lua bindings.) + * @returns Current turn number. */ operator int() const; diff --git a/src/catalua.cpp b/src/catalua.cpp deleted file mode 100644 index a4af4b89bdd0a..0000000000000 --- a/src/catalua.cpp +++ /dev/null @@ -1,1435 +0,0 @@ -#include "catalua.h" - -#include - -#include "action.h" -#include "debug.h" -#include "game.h" -#include "item.h" -#include "item_factory.h" -#include "map.h" -#include "mapgen.h" -#include "mapgen_functions.h" -#include "messages.h" -#include "monstergenerator.h" -#include "omdata.h" -#include "output.h" -#include "overmap.h" -#include "path_info.h" -#include "player.h" -#include "pldata.h" -#include "requirements.h" -#include "string_formatter.h" -#include "translations.h" -#include "weather_gen.h" - -#ifdef LUA - -// Many pragmas here for headers which IWYU doesn't realise we need because -// they are used only inside src/lua/catabindings.cpp (the autogenerated file) - -#include "activity_type.h" // IWYU pragma: keep -#include "bionics.h" // IWYU pragma: keep -#include "field.h" // IWYU pragma: keep -#include "filesystem.h" -#include "gun_mode.h" -#include "itype.h" -#include "line.h" // IWYU pragma: keep -#include "mapdata.h" -#include "mongroup.h" -#include "morale_types.h" // IWYU pragma: keep -#include "mtype.h" -#include "mutation.h" // IWYU pragma: keep -#include "npc.h" // IWYU pragma: keep -#include "optional.h" -#include "overmap.h" -#include "overmap_ui.h" // IWYU pragma: keep -#include "requirements.h" // IWYU pragma: keep -#include "rng.h" // IWYU pragma: keep -#include "string_input_popup.h" -#include "trap.h" // IWYU pragma: keep -#include "ui.h" - -extern "C" { -#include -#include -#include -} - -#include - -#if LUA_VERSION_NUM < 502 -#define LUA_OK 0 -#endif - -using item_stack_iterator = std::list::iterator; -using volume = units::volume; -using mass = units::mass; -using npc_template_id = string_id; -using overmap_direction = om_direction::type; - -lua_State *lua_state = nullptr; - -// Keep track of the current mod from which we are executing, so that -// we know where to load files from. -std::string lua_file_path; - -std::stringstream lua_output_stream; -std::stringstream lua_error_stream; - -// Not used in the C++ code, but implicitly required by the Lua bindings. -// Gun modes need to be created via an actual item. -template<> -const gun_mode &string_id::obj() const -{ - static const gun_mode dummy{}; - return dummy; -} -template<> -bool string_id::is_valid() const -{ - return false; -} - -#if LUA_VERSION_NUM < 502 -// Compatibility, for before Lua 5.2, which does not have luaL_setfuncs -static void luaL_setfuncs( lua_State *const L, const luaL_Reg arrary[], const int nup ) -{ - for( ; arrary->name != nullptr; arrary++ ) { - lua_pushstring( L, arrary->name ); - // Need to copy the up-values because lua_pushcclosure removes them, they need - // to be set for each C-function. - for( int i = 0; i < nup; i++ ) { - lua_pushvalue( L, -( nup + 1 ) ); - } - lua_pushcclosure( L, arrary->func, nup ); - lua_settable( L, -( nup + 3 ) ); - } - // Remove up-values as per definition of luaL_setfuncs in 5.2 - lua_pop( L, nup ); -} -#endif - -void lua_dofile( lua_State *L, const char *path ); - -// Helper functions for making working with the lua API more straightforward. -// -------------------------------------------------------------------------- - -// Stores item at the given stack position into the registry. -int luah_store_in_registry( lua_State *L, int stackpos ) -{ - lua_pushvalue( L, stackpos ); - return luaL_ref( L, LUA_REGISTRYINDEX ); -} - -// Removes item from registry and pushes on the top of stack. -void luah_remove_from_registry( lua_State *L, int item_index ) -{ - lua_rawgeti( L, LUA_REGISTRYINDEX, item_index ); - luaL_unref( L, LUA_REGISTRYINDEX, item_index ); -} - -// Sets the metatable for the element on top of the stack. -void luah_setmetatable( lua_State *L, const char *metatable_name ) -{ - // Push the metatable on top of the stack. - lua_getglobal( L, metatable_name ); - - // The element we want to set the metatable for is now below the top. - lua_setmetatable( L, -2 ); -} - -void luah_setglobal( lua_State *L, const char *name, int index ) -{ - lua_pushvalue( L, index ); - lua_setglobal( L, name ); -} - -/** Safe wrapper to get a Lua string as std::string. Handles nullptr and binary data. */ -std::string lua_tostring_wrapper( lua_State *const L, const int stack_position ) -{ - size_t length = 0; - const char *const result = lua_tolstring( L, stack_position, &length ); - if( result == nullptr || length == 0 ) { - return std::string{}; - } - return std::string( result, length ); -} - -// Given a Lua return code and a file that it happened in, print a debugmsg with the error and path. -// Returns true if there was an error, false if there was no error at all. -bool lua_report_error( lua_State *L, int err, const char *path, bool simple = false ) -{ - if( err == LUA_OK || err == LUA_ERRRUN ) { - // No error or error message already shown via traceback function. - return err != LUA_OK; - } - const std::string error = lua_tostring_wrapper( L, -1 ); - switch( err ) { - case LUA_ERRSYNTAX: - if( !simple ) { - lua_error_stream << "Lua returned syntax error for " << path << std::endl; - } - lua_error_stream << error; - break; - case LUA_ERRMEM: - lua_error_stream << "Lua is out of memory"; - break; - case LUA_ERRFILE: - if( !simple ) { - lua_error_stream << "Lua returned file io error for " << path << std::endl; - } - lua_error_stream << error; - break; - default: - if( !simple ) { - lua_error_stream << string_format( "Lua returned unknown error %d for ", err ) << path << std::endl; - } - lua_error_stream << error; - break; - } - return true; -} - -/** - * Base interface for values, that are copied into Luas own memory (and thereby managed by Lua). - * The class creates a metatable for the wrapped objects, this is all set up via - * generate_bindings.lua. - * Usage: there are two main functions you might need: @ref push and @ref get. - * - @ref push copies the object into Luas memory and pushes a reference to it on the stack. - * It is like @ref lua_pushnumber, only it pushes a whole object. - * - @ref get reads a value from the stack and returns a reference to it (the memory of the object - * is managed by Lua and is kept until the garbage collector frees it). - * - * You can expect the following behavior: - * \code - * const Foo &myfoo = get_my_foo( ... ); - * LuaValue::push( L, myfoo ); // copies myfoo - * ... // give control back to Lua, wait for a callback from it, - * Foo &thefoo = LuaValue::get( L, 1 ); // get the first argument of the callback - * thefoo.something(); // do something with it, not that myfoo and thefoo are different objects - * \endcode - * - * @param T is the type of object that should be managed. It must be copy-constructible. - */ -template -class LuaValue -{ - private: - /** Defined by generate_bindings.lua in catabindings.cpp */ - static const char *const METATABLE_NAME; - /** Defined by generate_bindings.lua in catabindings.cpp */ - static const luaL_Reg FUNCTIONS[]; - /** Defined by generate_bindings.lua in catabindings.cpp */ - using MRMap = std::map; - static const MRMap READ_MEMBERS; - /** Defined by generate_bindings.lua in catabindings.cpp */ - using MWMap = std::map; - static const MWMap WRITE_MEMBERS; - - /*@{*/ - /** - * @name Dynamic type conversion for Lua, or so. - * - * (Disclaimer: don't feel bad for not understanding this, I don't either.) - * - * get_subclass is a generated function, it checks whether the value at stack_index - * is one of the direct subclasses of T (this check is recursive). - * If one type matches, it returns a pointer to the object. - * - * Normally the function would be defined as `T* get_subclass(...)`, but if T is - * already a pointer (e.g. Creature*), we end with `Creature** get_subclass`. - * The problem is that a `monster**` can not be converted to `Creature**` and thereby - * not be returned via this function (trust me, I tried, one may be able to use a - * reinterpret_cast, but that is evil). - * We need a simple pointer (not a pointer-to-pointer). - * - * We get the simple pointer by removing the pointer from T via the std thingy, which gives us - * @ref Type. A reference to that is returned by @ref get. - * - * Reading user data from Lua gives a T*, so it must be converted to Type&, which may either - * be just one dereferencing (if T*==Type*) or two (if T*==Type**). - * One dereferencing is always done int @ref get, the (conditional) second is done in @ref cast. - * The two overloads match either a Type* (which dereferences the parameter) or a Type& - * (which just returns the reference without any changes). - * - * Maybe an example will help: - * For T = monster* the function monster::die(Creature*) needs a Creature as parameter. - * Try this in Lua: `game.zombie(0):die(player)` - * Lua will check the parameter to be of type LuaValue, this means checking the - * metatable (whether it's the very same as the one generated by LuaValue::get_metatable) - * However, `player` has a different table (from LuaValue), so Lua would complain - * about the wrong of the argument. - * `LuaValue::get_subclass` is hard coded (via the code generator) to - * check whether the value is actually a `Character*`, or a `monster*` (direct subclasses). - * If so, a pointer the those objects (converted to `Creature*`) is returned. `cast()` will - * simply pass that pointer through and the caller can return the `Creature*`. - * - * Now assume T = point (and assume tripoint inherit from point, why not?) - * A function calls for a `point`, the input is a tripoint, so the metatables don't match. - * `get_subclass` is called and successfully extract a tripoint from the userdata. It - * returns a pointer to the tripoint (converted to `point*`). The caller needs a point (or - * a point reference), so the `point*` must be converted back to a reference. - * This is done by the first `cast()` overload. - */ - using Type = typename std::remove_pointer::type; - static Type *get_subclass( lua_State *S, int stack_index ); - template - static Type &cast( P *ptr ) { - return *ptr; - } - template - static Type &cast( P &ptr ) { - return ptr; - } - /*@}*/ - - static int gc( lua_State *const L ) { - T *object = static_cast( lua_touserdata( L, 1 ) ); - object->T::~T(); - lua_pop( L, 1 ); - return 0; - } - /** - * Wrapper for the Lua __index entry in the metatable of the userdata. - * It queries the actual metatable in case the call goes to a function (and does not request - * and actual class member) and returns that function (if found). - * If there is no function of the requested name, it looks up the name in @ref READ_MEMBERS, - * if it's there, it calls the function that the entry refers to (which acts as a getter). - * Finally it returns nil, which is what Lua would have used anyway. - */ - static int index( lua_State *const L ) { - // -2 is the userdata, -1 is the key (function to call) - const char *const key = lua_tostring( L, -1 ); - if( key == nullptr ) { - luaL_error( L, "Invalid input to __index: key is not a string." ); - } - if( luaL_getmetafield( L, -2, key ) != 0 ) { - // There is an entry of that name, return it. - lua_remove( L, -3 ); // remove userdata - lua_remove( L, -2 ); // remove key - // -1 is now the things we have gotten from luaL_getmetafield, return it. - return 1; - } - const auto iter = READ_MEMBERS.find( key ); - if( iter == READ_MEMBERS.end() ) { - // No such member or function - lua_pushnil( L ); - return 1; - } - lua_remove( L, -1 ); // remove key - // userdata is still there (now on -1, where it is expected by the getter) - return iter->second( L ); - } - /** - * Wrapper for the Lua __newindex entry in the metatable of the userdata. - * It looks up the name of the requested member in @ref WRITE_MEMBERS and (if found), - * calls the function that the entry refers to (which acts as a setter). - */ - static int newindex( lua_State *const L ) { - // -3 is the userdata, -2 is the key (name of the member), -1 is the value - const char *const key = lua_tostring( L, -2 ); - if( key == nullptr ) { - luaL_error( L, "Invalid input to __newindex: key is not a string." ); - } - const auto iter = WRITE_MEMBERS.find( key ); - if( iter == WRITE_MEMBERS.end() ) { - luaL_error( L, "Unknown attribute" ); - } - lua_remove( L, -2 ); // key, userdata is still there, but now on -2, and the value is on -1 - return iter->second( L ); - } - /** - * This loads the metatable (and adds the available functions) and pushes it on the stack. - */ - static void get_metatable( lua_State *const L ) { - // Create table (if it does not already exist), pushes it on the stack. - // If the table already exists, we have already filled it, so we can return - // without doing it again. - if( luaL_newmetatable( L, METATABLE_NAME ) == 0 ) { - return; - } - // Push the metatable itself, the stack now contains two pointers to the same metatable - lua_pushvalue( L, -1 ); - // Set the metatable of the new metatable (-2 on the stack) to be itself. Pretty meta, hu? - // It also pops one value from the stack. - lua_setmetatable( L, -2 ); - // Now set the actual functions of the metatable. - luaL_setfuncs( L, &FUNCTIONS[0], 0 ); - - // Push function pointer - lua_pushcfunction( L, &gc ); - // -1 would be the function pointer, -2 is the metatable, the function pointer is popped - lua_setfield( L, -2, "__gc" ); - lua_pushcfunction( L, &index ); - lua_setfield( L, -2, "__index" ); - lua_pushcfunction( L, &newindex ); - lua_setfield( L, -2, "__newindex" ); - } - /** - * Checks the metatable that of value at stack_index against the metatable of this - * object (matching type T). Returns the stack in the same state as it was when called. - */ - static bool has_matching_metatable( lua_State *const L, const int stack_index ) { - if( lua_getmetatable( L, stack_index ) == 0 ) { - // value does not have a metatable, can not be valid at all. - return false; - } - get_metatable( L ); - const bool is_correct_metatable = lua_rawequal( L, -1, -2 ); - lua_remove( L, -1 ); - lua_remove( L, -1 ); - return is_correct_metatable; - } - - public: - static void load_metatable( lua_State *const L, const char *const global_name ) { - // Create the metatable for the first time (or just retrieve it) - get_metatable( L ); - if( global_name == nullptr ) { - // remove the table from stack, setglobal does this in the other branch, - // make it here manually to leave the stack in the same state. - lua_remove( L, -1 ); - } else { - lua_setglobal( L, global_name ); - } - } - template - static void push( lua_State *const L, const cata::optional &value ) { - if( value ) { - push( L, *value ); - } else { - lua_pushnil( L ); - } - } - template::value, int>::type = 0 > - static void push( lua_State *const L, Args && ... args ) { - // Push user data, - T *value_in_lua = static_cast( lua_newuserdata( L, sizeof( T ) ) ); - // Push metatable, - get_metatable( L ); - // -1 is the metatable, -2 is the uservalue, the table is popped - lua_setmetatable( L, -2 ); - // This is where the copy happens: - new( value_in_lua ) T( std::forward( args )... ); - } - static int push_reg( lua_State *const L, const T &value ) { - push( L, value ); - return luah_store_in_registry( L, -1 ); - } - static Type &get( lua_State *const L, const int stack_index ) { - luaL_checktype( L, stack_index, LUA_TUSERDATA ); - T *user_data = static_cast( lua_touserdata( L, stack_index ) ); - if( user_data == nullptr ) { - // luaL_error does not return at all. - luaL_error( L, "First argument to function is not a class" ); - } - if( has_matching_metatable( L, stack_index ) ) { - return cast( *user_data ); - } - Type *const subobject = get_subclass( L, stack_index ); - if( subobject == nullptr ) { - // luaL_argerror does not return at all. - luaL_argerror( L, stack_index, METATABLE_NAME ); - } - return *subobject; - } - /** Checks whether the value at stack_index is of the type T. If so, @ref get can be used to get it. */ - static bool has( lua_State *const L, const int stack_index ) { - if( !lua_isuserdata( L, stack_index ) ) { - return false; - } - if( has_matching_metatable( L, stack_index ) ) { - return true; - } - return get_subclass( L, stack_index ) != nullptr; - } - /** Raises a Lua error if the type of the value at stack_index is not compatible with T. */ - static void check( lua_State *const L, const int stack_index ) { - luaL_checktype( L, stack_index, LUA_TUSERDATA ); - if( !has( L, stack_index ) ) { - // METATABLE_NAME is used here as the name of the type we expect. - luaL_argerror( L, stack_index, METATABLE_NAME ); - } - } -}; - -/** - * This is special wrapper (an extension) for references to objects which are not stored in Lua, - * but are kept in the memory managed by C++. This class only stores and retrieves the pointers, - * you have to make sure those pointers stay valid. - * - * Example (an @ref itype is loaded when a world is loaded and stays valid until the game ends): - * \code - * itype *it = type::find_type( "water" ); - * LuaReference::push( L, it ); // copies the pointer it - * ... // give control back to Lua, wait for a callback from it, - * itype &it = LuaValue::get( L, 1 ); // get the first argument of the callback - * assert(it.id == "water"); - * \endcode - * - * This class extends LuaValue by some pointer specific behavior: - * - @ref push is overloaded to accept a reference to T (which will be converted to a pointer - * and stored). Additionally, if the pointer passed to @ref push is nullptr, nil will be pushed - * (this obviously does not work for references). - * \code - * Foo *x = ...; - * LuaReference::push( L, x ); - * LuaReference::push( L, *x ); // both push calls do exactly the same. - * \endcode - * push is also overloaded to accept const and non-const references / pointers. The templated - * third parameter there makes sure that this is only done when T is not const. Otherwise we - * would end up with 2 identical push functions, both taking a const references. - * - @ref get returns a proxy object. It contains the pointer to T. It will automatically convert - * to a reference / a pointer to T: - * \code - * void f_ptr( itype* ); - * void f_ref( itype& ); - * auto proxy = LuaReference::get( L, 1 ); - * f_ptr( proxy ); // proxy converts to itype* - * f_ref( proxy ); // proxy converts to itype& - * itype *it = proxy; - * \endcode - * If you only need a reference (e.g. to call member functions or access members), use - * @ref LuaValue::get instead: - * \code - * itype &it = LuaValue::get( L, 1 ); - * std::string name = it.nname(); - * \endcode - */ -template -class LuaReference : private LuaValue -{ - public: - template - static void push( lua_State *const L, T *const value, - typename std::enable_if < !std::is_const::value >::value_type * = nullptr ) { - if( value == nullptr ) { - lua_pushnil( L ); - return; - } - LuaValue::push( L, value ); - } - template - static void push( lua_State *const L, const cata::optional &value ) { - if( value ) { - push( L, *value ); - } else { - lua_pushnil( L ); - } - } - // HACK: because Lua does not known what const is. - static void push( lua_State *const L, const T *const value ) { - if( value == nullptr ) { - lua_pushnil( L ); - return; - } - LuaValue::push( L, const_cast( value ) ); - } - template - static void push( lua_State *const L, T &value, - typename std::enable_if < !std::is_const::value >::value_type * = nullptr ) { - LuaValue::push( L, &value ); - } - // HACK: because Lua does not known what const is. - static void push( lua_State *const L, const T &value ) { - LuaValue::push( L, const_cast( &value ) ); - } - static int push_reg( lua_State *const L, T *const value ) { - push( L, value ); - return luah_store_in_registry( L, -1 ); - } - static int push_reg( lua_State *const L, T &value ) { - return LuaValue::push_reg( L, &value ); - } - /** A proxy object that allows to convert the reference to a pointer on-demand. The proxy object can - * be used as argument to functions that expect either a pointer and to functions expecting a - * reference. */ - struct proxy { - T *ref; - operator T *() { - return ref; - } - operator T &() { - return *ref; - } - T *operator &() { - return ref; - } - }; - /** Same as calling @ref get, but returns a @ref proxy containing the reference. */ - static proxy get( lua_State *const L, const int stack_position ) { - return proxy{ &LuaValue::get( L, stack_position ) }; - } - using LuaValue::has; - using LuaValue::check; -}; - -/** - * This is the basic type-checking interface for the Lua bindings generator. - * Instead of "if type is string, call lua_isstring, if it's int, call lua_isnumber, ...", the - * generator can just call "LuaType<"..type..">::has". - * The C++ classes do the actual separation based on the type through the template parameter. - * - * Each implementation contains function like the LuaValue has: - * - @ref has checks whether the object at given stack index is of the requested type. - * - @ref check calls @ref has and issues a Lua error if the types is not as requested. - * - @ref get returns the value at given stack_index. This is like @ref LuaValue::get. - * If you need to store the value, use \code auto && val = LuaType::get(...); \endcode - * - @ref push puts the value on the stack, like @ref LuaValue::push - */ -template -struct LuaType; - -template<> -struct LuaType { - static bool has( lua_State *const L, const int stack_index ) { - return lua_isnumber( L, stack_index ); - } - static void check( lua_State *const L, const int stack_index ) { - luaL_checktype( L, stack_index, LUA_TNUMBER ); - } - static int get( lua_State *const L, const int stack_index ) { - return lua_tonumber( L, stack_index ); - } - static void push( lua_State *const L, const int value ) { - lua_pushnumber( L, value ); - } -}; -template<> -struct LuaType { - static bool has( lua_State *const L, const int stack_index ) { - return lua_isboolean( L, stack_index ); - } - static void check( lua_State *const L, const int stack_index ) { - luaL_checktype( L, stack_index, LUA_TBOOLEAN ); - } - static bool get( lua_State *const L, const int stack_index ) { - return lua_toboolean( L, stack_index ); - } - static void push( lua_State *const L, const bool value ) { - lua_pushboolean( L, value ); - } - // It is helpful to be able to treat optionals as bools when passing to lua - template - static void push( lua_State *const L, const cata::optional &value ) { - push( L, !!value ); - } -}; -template<> -struct LuaType { - static bool has( lua_State *const L, const int stack_index ) { - return lua_isstring( L, stack_index ); - } - static void check( lua_State *const L, const int stack_index ) { - luaL_checktype( L, stack_index, LUA_TSTRING ); - } - static std::string get( lua_State *const L, const int stack_index ) { - return lua_tostring_wrapper( L, stack_index ); - } - static void push( lua_State *const L, const std::string &value ) { - lua_pushlstring( L, value.c_str(), value.length() ); - } - // For better performance: if the input is a c-string, forward it as such without wrapping - // it into a std::string first. - static void push( lua_State *const L, const char *value ) { - lua_pushstring( L, value ); - } -}; -template<> -struct LuaType : public LuaType { // inherit checking because it's all the same to Lua - static float get( lua_State *const L, const int stack_index ) { - return lua_tonumber( L, stack_index ); - } - static void push( lua_State *const L, const float value ) { - lua_pushnumber( L, value ); - } -}; -template -struct LuaType> : public LuaValue { -}; -template -struct LuaType> : public LuaReference { -}; - -/** This basically transforms a string (therefore inheriting from LuaType) into a C++ - * enumeration value. It simply contains a table of string-to-enum-values. */ -template -class LuaEnum : private LuaType -{ - private: - using Parent = LuaType; - /** Defined by generate_bindings.lua in catabindings.cpp */ - using EMap = std::map; - static const EMap BINDINGS; - static E from_string( const std::string &value ) { - const auto iter = BINDINGS.find( value ); - if( iter == BINDINGS.end() ) { - // This point shall not be reached. Always call this with valid input. - return BINDINGS.begin()->second; - } - return iter->second; - } - static const std::string &to_string( E const value ) { - for( auto &e : BINDINGS ) { - if( e.second == value ) { - return e.first; - } - } - // This point shall not be reached. Always call this with valid input. - return BINDINGS.begin()->first; - } - static bool has( const std::string &value ) { - return BINDINGS.count( value ) > 0; - } - static int index( lua_State *const L ) { - // -1 is the key (function to call) - const char *const key = lua_tostring( L, -1 ); - if( key == nullptr ) { - luaL_error( L, "Invalid input to __index: key is not a string." ); - } - const auto iter = BINDINGS.find( key ); - if( iter == BINDINGS.end() ) { - return luaL_error( L, "Invalid enum value." ); - } - lua_remove( L, -1 ); // remove key - // Push the enum as string, it will be converted back to the enum later. This way, it can - // be specified both ways in Lua code: either as string or via an entry here. - lua_pushlstring( L, iter->first.c_str(), iter->first.length() ); - return 1; - } - public: - static bool has( lua_State *const L, const int stack_index ) { - return Parent::has( L, stack_index ) && has( Parent::get( L, stack_index ) ); - } - static void check( lua_State *const L, const int stack_index ) { - Parent::check( L, stack_index ); - if( !has( Parent::get( L, stack_index ) ) ) { - luaL_argerror( L, stack_index, "invalid value for enum" ); - } - } - static E get( lua_State *const L, const int stack_index ) { - return from_string( Parent::get( L, stack_index ) ); - } - static void push( lua_State *const L, E const value ) { - Parent::push( L, to_string( value ) ); - } - /** Export the enum values as entries of a global metatable */ - static void export_global( lua_State *const L, const char *global_name ) { - lua_createtable( L, 0, 1 ); // +1 - lua_pushvalue( L, -1 ); // + 1 - // Set the new table to have itself as metatable - lua_setmetatable( L, -2 ); // -1 - // Setup the __index entry, which will translate the entry to a enum value - lua_pushcfunction( L, &index ); // +1 - lua_setfield( L, -2, "__index" ); // -1 - // And register as a global value - lua_setglobal( L, global_name ); // -1 - } -}; -template -struct LuaType> : public LuaEnum { -}; - -/** - * Wrapper class to access objects in Lua that are stored as either a pointer or a value. - * Technically, this class could inherit from both `LuaValue` and `LuaReference`, - * but that would basically the same code anyway. - * It behaves like a LuaValue if there is a value on the stack, and like LuaReference is there - * is a reference on the stack. Functions behave like the functions in a `LuaType`. - * Note that it does not have a push function because it can not know whether to push a reference - * or a value (copy). The caller must decide this and must use `LuaValue` or `LuaReference`. - */ -template -class LuaValueOrReference -{ - public: - using proxy = typename LuaReference::proxy; - static proxy get( lua_State *const L, const int stack_index ) { - if( LuaValue::has( L, stack_index ) ) { - return proxy{ &LuaValue::get( L, stack_index ) }; - } - return LuaReference::get( L, stack_index ); - } - static void check( lua_State *const L, const int stack_index ) { - if( LuaValue::has( L, stack_index ) ) { - return; - } - LuaValue::check( L, stack_index ); - } - static bool has( lua_State *const L, const int stack_index ) { - return LuaValue::has( L, stack_index ) || LuaValue::has( L, stack_index ); - } -}; - -void update_globals( lua_State *L ) -{ - LuaReference::push( L, g->u ); - luah_setglobal( L, "player", -1 ); - // luah_setglobal pushes an extra copy of the global data before storing it, - // but here the original value isn't needed once the global data has been - // saved. - lua_pop( L, 1 ); - - LuaReference::push( L, g->m ); - luah_setglobal( L, "map", -1 ); - lua_pop( L, 1 ); - - LuaReference::push( L, g.get() ); - luah_setglobal( L, "g", -1 ); - lua_pop( L, 1 ); -} - -class lua_iuse_wrapper : public iuse_actor -{ - private: - int lua_function; - public: - lua_iuse_wrapper( const int f, const std::string &type ) : iuse_actor( type ), lua_function( f ) {} - ~lua_iuse_wrapper() override = default; - long use( player &, item &it, bool a, const tripoint &pos ) const override { - // We'll be using lua_state a lot! - lua_State *const L = lua_state; - - // If it's a lua function, the arguments have to be wrapped in - // lua userdata's and passed on the lua stack. - // We will now call the function f(player, item, active) - - update_globals( L ); - - // Push the lua function on top of the stack - lua_rawgeti( L, LUA_REGISTRYINDEX, lua_function ); - - // TODO: also pass the player object, because of NPCs and all - // I guess - - // Push the item on top of the stack. - const int item_in_registry = LuaReference::push_reg( L, it ); - // Push the "active" parameter on top of the stack. - lua_pushboolean( L, a ); - // Push the location of the item. - const int tripoint_in_registry = LuaValue::push_reg( L, pos ); - - // Call the iuse function - int err = lua_pcall( L, 3, 1, 0 ); - lua_report_error( L, err, "iuse function" ); - - // Make sure the now outdated parameters we passed to lua aren't - // being used anymore by setting a metatable that will error on - // access. - luah_remove_from_registry( L, item_in_registry ); - luah_setmetatable( L, "outdated_metatable" ); - luah_remove_from_registry( L, tripoint_in_registry ); - luah_setmetatable( L, "outdated_metatable" ); - - return lua_tointeger( L, -1 ); - } - iuse_actor *clone() const override { - return new lua_iuse_wrapper( *this ); - } - - void load( JsonObject & ) override {} -}; - -// iuse abstraction to make iuse's both in lua and C++ possible -// ------------------------------------------------------------ -void Item_factory::register_iuse_lua( const std::string &name, int lua_function ) -{ - if( iuse_function_list.count( name ) > 0 ) { - DebugLog( D_INFO, D_MAIN ) << "lua iuse function " << name << " overrides existing iuse function"; - } - iuse_function_list[name] = use_function( new lua_iuse_wrapper( lua_function, name ) ); -} - -class lua_mattack_wrapper : public mattack_actor -{ - private: - int lua_function; - - public: - lua_mattack_wrapper( const mattack_id &id, const int f ) : - mattack_actor( id ), - lua_function( f ) {} - - ~lua_mattack_wrapper() override = default; - - bool call( monster &m ) const override { - lua_State *const L = lua_state; - // If it's a lua function, the arguments have to be wrapped in - // lua userdata's and passed on the lua stack. - // We will now call the function f(monster) - update_globals( L ); - // Push the lua function on top of the stack - lua_rawgeti( L, LUA_REGISTRYINDEX, lua_function ); - // Push the monster on top of the stack. - const int monster_in_registry = LuaReference::push_reg( L, m ); - // Call the iuse function - int err = lua_pcall( L, 1, 1, 0 ); - lua_report_error( L, err, "monattack function" ); - // Make sure the now outdated parameters we passed to lua aren't - // being used anymore by setting a metatable that will error on - // access. - luah_remove_from_registry( L, monster_in_registry ); - luah_setmetatable( L, "outdated_metatable" ); - return lua_toboolean( L, -1 ); - } - - mattack_actor *clone() const override { - return new lua_mattack_wrapper( *this ); - } - - void load_internal( JsonObject &, const std::string & ) override {} -}; - -void MonsterGenerator::register_monattack_lua( const std::string &name, int lua_function ) -{ - add_attack( mtype_special_attack( new lua_mattack_wrapper( name, lua_function ) ) ); -} - -// Call the given string directly, used in the lua debug command. -int call_lua( const std::string &tocall ) -{ - lua_State *L = lua_state; - - update_globals( L ); - int err = luaL_dostring( L, tocall.c_str() ); - lua_report_error( L, err, tocall.c_str(), true ); - return err; -} - -void CallbackArgument::Save() -{ - lua_State *const L = lua_state; - switch( type ) { - case CallbackArgumentType::Integer: - lua_pushinteger( L, value_integer ); - break; - case CallbackArgumentType::Number: - lua_pushnumber( L, value_number ); - break; - case CallbackArgumentType::Boolean: - lua_pushboolean( L, value_boolean ); - break; - case CallbackArgumentType::String: - lua_pushstring( L, value_string.c_str() ); - break; - case CallbackArgumentType::Tripoint: - LuaValue::push( L, value_tripoint ); - break; - case CallbackArgumentType::Item: - LuaValue::push( L, value_item ); - break; - case CallbackArgumentType::Reference_Creature: - LuaReference::push( L, value_creature ); - break; - case CallbackArgumentType::Enum_BodyPart: - LuaEnum::push( L, value_body_part ); - break; - default: - lua_pushnil( L ); - break; - } -} - -void lua_callback_helper( const char *callback_name, const CallbackArgumentContainer &callback_args, - int retsize = 0 ) -{ - if( lua_state == nullptr ) { - return; - } - lua_State *L = lua_state; - update_globals( L ); - lua_getglobal( L, "mod_callback" ); - lua_pushstring( L, callback_name ); - for( auto callback_arg : callback_args ) { - callback_arg.Save(); - } - int err = lua_pcall( L, callback_args.size() + 1, retsize, 0 ); - std::string err_function = "mod_callback(\"" + std::string( callback_name ) + "\")"; - lua_report_error( L, err, err_function.c_str(), true ); -} - -void lua_callback( const char *callback_name, const CallbackArgumentContainer &callback_args ) -{ - lua_callback_helper( callback_name, callback_args ); -} - -void lua_callback( const char *callback_name ) -{ - CallbackArgumentContainer callback_args; - lua_callback( callback_name, callback_args ); -} - -std::string lua_callback_getstring( const char *callback_name, - const CallbackArgumentContainer &callback_args ) -{ - lua_callback_helper( callback_name, callback_args, 1 ); - lua_State *L = lua_state; - size_t len; - const char *tmp = lua_tolstring( L, -1, &len ); - std::string retval = tmp ? tmp : ""; - return retval; -} - -// -int lua_mapgen( map *m, const oter_id &terrain_type, const mapgendata &, const time_point &t, float, - const std::string &scr ) -{ - if( lua_state == nullptr ) { - return 0; - } - lua_State *L = lua_state; - LuaReference::push( L, m ); - luah_setglobal( L, "map", -1 ); - - int err = luaL_loadstring( L, scr.c_str() ); - if( lua_report_error( L, err, scr.c_str() ) ) { - return err; - } - // int function_index = luaL_ref(L, LUA_REGISTRYINDEX); // @todo; make use of this - // lua_rawgeti(L, LUA_REGISTRYINDEX, function_index); - - lua_pushstring( L, terrain_type.id().c_str() ); - lua_setglobal( L, "tertype" ); - lua_pushinteger( L, to_turn( t ) ); - lua_setglobal( L, "turn" ); - - err = lua_pcall( L, 0, LUA_MULTRET, 0 ); - lua_report_error( L, err, scr.c_str() ); - - // luah_remove_from_registry(L, function_index); // @todo: make use of this - - return err; -} - -// Custom functions that are to be wrapped from lua. -// ------------------------------------------------- -static std::unique_ptr uilist_instance; -uilist *create_uilist() -{ - uilist_instance.reset( new uilist() ); - return uilist_instance.get(); -} - -// Simulate old create_uimenu() behavior -uilist *create_uilist_no_cancel() -{ - uilist_instance.reset( new uilist() ); - uilist_instance->allow_cancel = false; - return uilist_instance.get(); -} - -const ter_t &get_terrain_type( int id ) -{ - return ter_id( id ).obj(); -} - -static calendar &get_calendar_turn_wrapper() -{ - return calendar::turn; -} - -static time_duration get_time_duration_wrapper( const int t ) -{ - return time_duration::from_turns( t ); -} - -static std::string get_omt_id( const overmap &om, const tripoint &p ) -{ - return om.get_ter( p ).id().str(); -} - -static overmap_direction get_omt_dir( const overmap &om, const tripoint &p ) -{ - return om.get_ter( p ).obj().get_dir(); -} - -static std::string string_input_popup_wrapper( const std::string &title, int width, - const std::string &desc ) -{ - return string_input_popup().title( title ).width( width ).description( desc ).query_string(); -} - -/** Get reference to monster at given tripoint. */ -monster *get_monster_at( const tripoint &p ) -{ - return g->critter_at( p ); -} - -/** Get reference to Creature at given tripoint. */ -Creature *get_critter_at( const tripoint &p ) -{ - return g->critter_at( p ); -} - -/** Create a new monster of the given type. */ -monster *create_monster( const mtype_id &mon_type, const tripoint &p ) -{ - monster new_monster( mon_type, p ); - if( !g->add_zombie( new_monster ) ) { - return nullptr; - } else { - return g->critter_at( p ); - } -} - -// Manually implemented lua functions -// -// Most lua functions are generated by src/lua/generate_bindings.lua, -// these generated functions can be found in src/lua/catabindings.cpp - -static void popup_wrapper( const std::string &text ) -{ - popup( "%s", text.c_str() ); -} - -static void add_msg_wrapper( const std::string &text ) -{ - add_msg( text ); -} - -static bool query_yn_wrapper( const std::string &text ) -{ - return query_yn( text ); -} - -// items = game.items_at(x, y) -static int game_items_at( lua_State *L ) -{ - int x = lua_tointeger( L, 1 ); - int y = lua_tointeger( L, 2 ); - - auto items = g->m.i_at( x, y ); - lua_createtable( L, items.size(), 0 ); // Preallocate enough space for all our items. - - // Iterate over the monster list and insert each monster into our returned table. - int i = 0; - for( auto &an_item : items ) { - // The stack will look like this: - // 1 - t, table containing item - // 2 - k, index at which the next item will be inserted - // 3 - v, next item to insert - // - // lua_rawset then does t[k] = v and pops v and k from the stack - - lua_pushnumber( L, i++ + 1 ); - item **item_userdata = ( item ** ) lua_newuserdata( L, sizeof( item * ) ); - *item_userdata = &an_item; - // TODO: update using LuaReference - luah_setmetatable( L, "item_metatable" ); - lua_rawset( L, -3 ); - } - - return 1; // 1 return values -} - -// item_groups = game.get_item_groups() -static int game_get_item_groups( lua_State *L ) -{ - std::vector items = item_controller->get_all_group_names(); - - lua_createtable( L, items.size(), 0 ); // Preallocate enough space for all our items. - - // Iterate over the monster list and insert each monster into our returned table. - for( size_t i = 0; i < items.size(); ++i ) { - // The stack will look like this: - // 1 - t, table containing item - // 2 - k, index at which the next item will be inserted - // 3 - v, next item to insert - // - // lua_rawset then does t[k] = v and pops v and k from the stack - - lua_pushnumber( L, i + 1 ); - lua_pushstring( L, items[i].c_str() ); - lua_rawset( L, -3 ); - } - - return 1; // 1 return values -} - -// monster_types = game.get_monster_types() -static int game_get_monster_types( lua_State *L ) -{ - const auto mtypes = MonsterGenerator::generator().get_all_mtypes(); - - lua_createtable( L, mtypes.size(), 0 ); // Preallocate enough space for all our monster types. - - // Iterate over the monster list and insert each monster into our returned table. - for( size_t i = 0; i < mtypes.size(); ++i ) { - // The stack will look like this: - // 1 - t, table containing id - // 2 - k, index at which the next id will be inserted - // 3 - v, next id to insert - // - // lua_rawset then does t[k] = v and pops v and k from the stack - - lua_pushnumber( L, i + 1 ); - LuaValue::push( L, mtypes[i].id ); - lua_rawset( L, -3 ); - } - - return 1; // 1 return values -} - -// x, y = choose_adjacent(query_string, x, y) -static int game_choose_adjacent( lua_State *L ) -{ - const std::string parameter1 = lua_tostring_wrapper( L, 1 ); - const cata::optional pnt = choose_adjacent( parameter1 ); - if( pnt ) { - lua_pushnumber( L, pnt->x ); - lua_pushnumber( L, pnt->y ); - lua_pushnumber( L, pnt->z ); - return 3; // 3 return values - } else { - return 0; // 0 return values - } -} - -// game.register_iuse(string, function_object) -static int game_register_iuse( lua_State *L ) -{ - // Make sure the first argument is a string. - const char *name = luaL_checkstring( L, 1 ); - if( !name ) { - return luaL_error( L, "First argument to game.register_iuse is not a string." ); - } - - // Make sure the second argument is a function - luaL_checktype( L, 2, LUA_TFUNCTION ); - - // function_object is at the top of the stack, so we can just pop - // it with luaL_ref - int function_index = luaL_ref( L, LUA_REGISTRYINDEX ); - - // Now register function_object with our iuse's - item_controller->register_iuse_lua( name, function_index ); - - return 0; // 0 return values -} - -static int game_register_monattack( lua_State *L ) -{ - // Make sure the first argument is a string. - const char *name = luaL_checkstring( L, 1 ); - if( !name ) { - return luaL_error( L, "First argument to game.register_monattack is not a string." ); - } - // Make sure the second argument is a function - luaL_checktype( L, 2, LUA_TFUNCTION ); - // function_object is at the top of the stack, so we can just pop - // it with luaL_ref - int function_index = luaL_ref( L, LUA_REGISTRYINDEX ); - // Now register function_object with our monattack's - MonsterGenerator::generator().register_monattack_lua( name, function_index ); - return 0; // 0 return values -} - -#include "lua/catabindings.cpp" - -// Load the main file of a mod -void lua_loadmod( const std::string &base_path, const std::string &main_file_name ) -{ - std::string full_path = base_path + "/" + main_file_name; - if( file_exist( full_path ) ) { - lua_file_path = base_path; - lua_dofile( lua_state, full_path.c_str() ); - lua_file_path.clear(); - } - // debugmsg("Loading from %s", full_path.c_str()); -} - -// Custom error handler -static int traceback( lua_State *L ) -{ - // Get the error message - const std::string error = lua_tostring_wrapper( L, -1 ); - - // Get the lua stack trace -#if LUA_VERSION_NUM < 502 - lua_getfield( L, LUA_GLOBALSINDEX, "debug" ); - lua_getfield( L, -1, "traceback" ); -#else - lua_getglobal( L, "debug" ); - lua_getfield( L, -1, "traceback" ); - lua_remove( L, -2 ); -#endif - lua_pushvalue( L, 1 ); - lua_pushinteger( L, 2 ); - lua_call( L, 2, 1 ); - - const std::string stacktrace = lua_tostring_wrapper( L, -1 ); - - // Print a debug message. - debugmsg( "Error in lua module: %s", error.c_str() ); - - // Print the stack trace to our debug log. - DebugLog( D_ERROR, DC_ALL ) << stacktrace; - return 1; -} - -// Load an arbitrary lua file -void lua_dofile( lua_State *L, const char *path ) -{ - lua_pushcfunction( L, &traceback ); - int err = luaL_loadfile( L, path ); - if( lua_report_error( L, err, path ) ) { - return; - } - err = lua_pcall( L, 0, LUA_MULTRET, -2 ); - lua_report_error( L, err, path ); -} - -// game.dofile(file) -// -// Method to load files from lua, later should be made "safe" by -// ensuring it's being loaded from a valid path etc. -static int game_dofile( lua_State *L ) -{ - const char *path = luaL_checkstring( L, 1 ); - - std::string full_path = lua_file_path + "/" + path; - lua_dofile( L, full_path.c_str() ); - return 0; -} - -static int game_myPrint( lua_State *L ) -{ - int argc = lua_gettop( L ); - for( int i = argc; i > 0; i-- ) { - lua_output_stream << lua_tostring_wrapper( L, -i ); - } - lua_output_stream << std::endl; - return 0; -} - -// Registry containing all the game functions exported to lua. -// ----------------------------------------------------------- -static const struct luaL_Reg global_funcs [] = { - {"register_iuse", game_register_iuse}, - {"register_monattack", game_register_monattack}, - //{"get_monsters", game_get_monsters}, - {"items_at", game_items_at}, - {"choose_adjacent", game_choose_adjacent}, - {"dofile", game_dofile}, - {"get_monster_types", game_get_monster_types}, - {"get_item_groups", game_get_item_groups}, - {nullptr, nullptr} -}; - -// Lua initialization. -void game::init_lua() -{ - // This is called on each new-game, the old state (if any) is closed to dispose any data - // introduced by mods of the previously loaded world. - if( lua_state != nullptr ) { - lua_close( lua_state ); - } - lua_state = luaL_newstate(); - if( lua_state == nullptr ) { - debugmsg( "Failed to start Lua. Lua scripting won't be available." ); - return; - } - - luaL_openlibs( lua_state ); // Load standard lua libs - - // Load our custom "game" module -#if LUA_VERSION_NUM < 502 - luaL_register( lua_state, "game", gamelib ); - luaL_register( lua_state, "game", global_funcs ); -#else - std::vector lib_funcs; - for( auto x = gamelib; x->name != nullptr; ++x ) { - lib_funcs.push_back( *x ); - } - for( auto x = global_funcs; x->name != nullptr; ++x ) { - lib_funcs.push_back( *x ); - } - lib_funcs.push_back( luaL_Reg { nullptr, nullptr } ); - luaL_newmetatable( lua_state, "game" ); - lua_pushvalue( lua_state, -1 ); - luaL_setfuncs( lua_state, &lib_funcs.front(), 0 ); - lua_setglobal( lua_state, "game" ); -#endif - - load_metatables( lua_state ); - LuaEnum::export_global( lua_state, "body_part" ); - - // override default print to our version - lua_register( lua_state, "print", game_myPrint ); - - // Load lua-side metatables etc. - lua_dofile( lua_state, FILENAMES["class_defslua"].c_str() ); - lua_dofile( lua_state, FILENAMES["autoexeclua"].c_str() ); -} - -#endif // #ifdef LUA - -use_function::use_function( const use_function &other ) - : actor( other.actor ? other.actor->clone() : nullptr ) -{ -} - -use_function &use_function::operator=( iuse_actor *const f ) -{ - return operator=( use_function( f ) ); -} - -use_function &use_function::operator=( const use_function &other ) -{ - actor.reset( other.actor ? other.actor->clone() : nullptr ); - return *this; -} - -void use_function::dump_info( const item &it, std::vector &dump ) const -{ - if( actor != nullptr ) { - actor->info( it, dump ); - } -} - -ret_val use_function::can_call( const player &p, const item &it, bool t, - const tripoint &pos ) const -{ - if( actor == nullptr ) { - return ret_val::make_failure( _( "You can't do anything interesting with your %s." ), - it.tname().c_str() ); - } - - return actor->can_use( p, it, t, pos ); -} - -long use_function::call( player &p, item &it, bool active, const tripoint &pos ) const -{ - return actor->use( p, it, active, pos ); -} - -#ifndef LUA -/* Empty functions for builds without Lua: */ -int lua_monster_move( monster * ) -{ - return 0; -} -int call_lua( std::string ) -{ - popup( _( "This binary was not compiled with Lua support." ) ); - return 0; -} -// Implemented in mapgen.cpp: -// int lua_mapgen( map *, std::string, mapgendata, int, float, const std::string & ) -void lua_loadmod( const std::string &, const std::string & ) -{ -} -void game::init_lua() -{ -} - -void lua_callback( const char *, const CallbackArgumentContainer & ) -{ -} -void lua_callback( const char * ) -{ -} - -#endif diff --git a/src/catalua.h b/src/catalua.h deleted file mode 100644 index 1a55063e2bfcb..0000000000000 --- a/src/catalua.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once -#ifndef CATALUA_H -#define CATALUA_H - -#include -#include -#include - -#include "creature.h" -#include "enums.h" -#include "int_id.h" -#include "item.h" - -enum CallbackArgumentType : int { - Integer, - Number, - Double = Number, - Float = Number, - Boolean, - String, - Tripoint, - Item, - Reference_Creature, - Enum_BodyPart, -}; - -struct CallbackArgument { - CallbackArgumentType type; - - int value_integer; - float value_number; - bool value_boolean; - std::string value_string; - tripoint value_tripoint; - item value_item; - Creature *value_creature; - body_part value_body_part; - - CallbackArgument( int arg_value ) : - type( CallbackArgumentType::Integer ), value_integer( arg_value ) { - } - CallbackArgument( double arg_value ) : - type( CallbackArgumentType::Number ), value_number( arg_value ) { - } - CallbackArgument( float arg_value ) : - type( CallbackArgumentType::Number ), value_number( arg_value ) { - } - CallbackArgument( bool arg_value ) : - type( CallbackArgumentType::Boolean ), value_boolean( arg_value ) { - } - CallbackArgument( const std::string &arg_value ) : - type( CallbackArgumentType::String ), value_string( arg_value ) { - } - CallbackArgument( const tripoint &arg_value ) : - type( CallbackArgumentType::Tripoint ), value_tripoint( arg_value ) { - } - CallbackArgument( const item &arg_value ) : - type( CallbackArgumentType::Item ), value_item( arg_value ) { - } - CallbackArgument( Creature *&arg_value ) : - type( CallbackArgumentType::Reference_Creature ), value_creature( arg_value ) { - } - CallbackArgument( const body_part &arg_value ) : - type( CallbackArgumentType::Enum_BodyPart ), value_body_part( arg_value ) { - } -#ifdef LUA - void Save(); -#endif //LUA -}; - -typedef std::list CallbackArgumentContainer; - -class map; -class monster; -class time_point; -struct mapgendata; -struct oter_t; - -using oter_id = int_id; - -extern std::stringstream lua_output_stream; -extern std::stringstream lua_error_stream; - -/** If this returns 0, no lua function was defined to override behavior. - * If this returns 1, lua behavior was called and regular behavior should be omitted. - */ -int lua_monster_move( monster *m ); - -/** - * Call the given string as lua code, used for interactive debugging. - */ -int call_lua( const std::string &tocall ); -int lua_mapgen( map *m, const oter_id &terrain_type, const mapgendata &md, const time_point &t, - float d, const std::string &scr ); - -/** - * Execute a callback that can be overridden by all mods with optional accessible arguments. - */ -void lua_callback( const char *callback_name, const CallbackArgumentContainer &callback_args ); -void lua_callback( const char *callback_name ); - -std::string lua_callback_getstring( const char *callback_name, - const CallbackArgumentContainer &callback_args ); - -/** - * Load the main file of a lua mod. - * - * @param base_path The base path of the mod. - * @param main_file_name The file name of the lua file, usually "main.lua" - */ -void lua_loadmod( const std::string &base_path, const std::string &main_file_name ); - -#endif diff --git a/src/craft_command.cpp b/src/craft_command.cpp index 16a0f2d768ca5..3d5679edebc12 100644 --- a/src/craft_command.cpp +++ b/src/craft_command.cpp @@ -85,10 +85,6 @@ void craft_command::execute() crafter->assign_activity( activity ); - /* legacy support for lua bindings to last_batch and lastrecipe */ - crafter->last_batch = batch_size; - crafter->lastrecipe = rec->ident(); - const auto iter = std::find( uistate.recent_recipes.begin(), uistate.recent_recipes.end(), rec->ident() ); if( iter != uistate.recent_recipes.end() ) { diff --git a/src/game.cpp b/src/game.cpp index cb9748f3a966e..999db8b6473ac 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -23,7 +23,6 @@ #include "bodypart.h" #include "cata_utility.h" #include "catacharset.h" -#include "catalua.h" #include "clzones.h" #include "compatibility.h" #include "computer.h" @@ -57,7 +56,6 @@ #include "line.h" #include "live_view.h" #include "loading_ui.h" -#include "lua_console.h" #include "map.h" #include "map_item_stack.h" #include "map_iterator.h" @@ -358,22 +356,12 @@ void game::load_core_data( loading_ui &ui ) // anyway. DynamicDataLoader::get_instance().unload_data(); - init_lua(); load_data_from_dir( FILENAMES[ "jsondir" ], "core", ui ); } void game::load_data_from_dir( const std::string &path, const std::string &src, loading_ui &ui ) { - // Process a preload file before the .json files, - // so that custom IUSE's can be defined before - // the items that need them are parsed - lua_loadmod( path, "preload.lua" ); - DynamicDataLoader::get_instance().load_data_from_path( path, src, ui ); - - // main.lua will be executed after JSON, allowing to - // work with items defined by mod's JSON - lua_loadmod( path, "main.lua" ); } game::~game() @@ -970,10 +958,6 @@ bool game::start_game() u.add_memorial_log( pgettext( "memorial_male", "%s began their journey into the Cataclysm." ), pgettext( "memorial_female", "%s began their journey into the Cataclysm." ), u.name.c_str() ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( u.getID() ); - lua_callback( "on_new_player_created", lua_callback_args_info ); - return true; } @@ -1505,22 +1489,8 @@ bool game::do_turn() if( calendar::once_every( 1_days ) ) { overmap_buffer.process_mongroups(); - if( calendar::turn.day_of_year() == 0 ) { - lua_callback( "on_year_passed" ); - } - lua_callback( "on_day_passed" ); } - if( calendar::once_every( 1_hours ) ) { - lua_callback( "on_hour_passed" ); - } - - if( calendar::once_every( 1_minutes ) ) { - lua_callback( "on_minute_passed" ); - } - - lua_callback( "on_turn_passed" ); - // Move hordes every 2.5 min if( calendar::once_every( time_duration::from_minutes( 2.5 ) ) ) { overmap_buffer.move_hordes(); @@ -1852,12 +1822,6 @@ void game::update_weather() // Check weather every few turns, instead of every turn. //@todo: predict when the weather changes and use that time. nextweather = calendar::turn + 50_turns; - if( weather != old_weather ) { - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( weather_data( weather ).name ); - lua_callback_args_info.emplace_back( weather_data( old_weather ).name ); - lua_callback( "on_weather_changed", lua_callback_args_info ); - } if( weather != old_weather && weather_data( weather ).dangerous && get_levz() >= 0 && m.is_outside( u.pos() ) && !u.has_activity( activity_id( "ACT_WAIT_WEATHER" ) ) ) { @@ -2778,8 +2742,6 @@ void game::load( const save_t &name ) u.reset(); draw(); - - lua_callback( "on_savegame_loaded" ); } void game::load_world_modfiles( loading_ui &ui ) @@ -3049,20 +3011,19 @@ void game::debug() _( "Test Item Group" ), // 22 _( "Damage Self" ), // 23 _( "Show Sound Clustering" ), // 24 - _( "Lua Console" ), // 25 - _( "Display weather" ), // 26 - _( "Display overmap scents" ), // 27 - _( "Change time" ), // 28 - _( "Set automove route" ), // 29 - _( "Show mutation category levels" ), // 30 - _( "Overmap editor" ), // 31 - _( "Draw benchmark (X seconds)" ), // 32 - _( "Teleport - Adjacent overmap" ), // 33 - _( "Test trait group" ), // 34 - _( "Show debug message" ), // 35 - _( "Crash game (test crash handling)" ),// 36 - _( "Spawn Map Extra" ), // 37 - _( "Quit to Main Menu" ), // 38 + _( "Display weather" ), // 25 + _( "Display overmap scents" ), // 26 + _( "Change time" ), // 27 + _( "Set automove route" ), // 28 + _( "Show mutation category levels" ), // 29 + _( "Overmap editor" ), // 30 + _( "Draw benchmark (X seconds)" ), // 31 + _( "Teleport - Adjacent overmap" ), // 32 + _( "Test trait group" ), // 33 + _( "Show debug message" ), // 34 + _( "Crash game (test crash handling)" ),// 35 + _( "Spawn Map Extra" ), // 36 + _( "Quit to Main Menu" ), // 37 } ); refresh_all(); switch( action ) { @@ -3338,18 +3299,13 @@ void game::debug() } break; - case 25: { - lua_console console; - console.run(); - } - break; - case 26: + case 25: ui::omap::display_weather(); break; - case 27: + case 26: ui::omap::display_scents(); break; - case 28: { + case 27: { auto set_turn = [&]( const int initial, const int factor, const char *const msg ) { const auto text = string_input_popup() .title( msg ) @@ -3407,7 +3363,7 @@ void game::debug() } while( smenu.ret != UILIST_CANCEL ); } break; - case 29: { + case 28: { const cata::optional dest = look_around(); if( !dest || *dest == u.pos() ) { break; @@ -3421,17 +3377,17 @@ void game::debug() } } break; - case 30: + case 29: for( const auto &elem : u.mutation_category_level ) { add_msg( "%s: %d", elem.first.c_str(), elem.second ); } break; - case 31: + case 30: ui::omap::display_editor(); break; - case 32: { + case 31: { const int ms = string_input_popup() .title( _( "Enter benchmark length (in milliseconds):" ) ) .width( 20 ) @@ -3441,19 +3397,19 @@ void game::debug() } break; - case 33: + case 32: debug_menu::teleport_overmap(); break; - case 34: + case 33: trait_group::debug_spawn(); break; - case 35: + case 34: debugmsg( "Test debugmsg" ); break; - case 36: + case 35: std::raise( SIGSEGV ); break; - case 37: { + case 36: { oter_id terrain_type = overmap_buffer.ter( g->u.global_omt_location() ); map_extras ex = region_settings_map["default"].region_extras[terrain_type->get_extras()]; @@ -3478,7 +3434,7 @@ void game::debug() } break; } - case 38: + case 37: if( query_yn( _( "Quit without saving? This may cause issues such as duplicated or missing items and vehicles!" ) ) ) { u.moves = 0; diff --git a/src/game.h b/src/game.h index 60fe11227d528..a540b8f4fa2ad 100644 --- a/src/game.h +++ b/src/game.h @@ -915,7 +915,6 @@ class game #endif // Data Initialization void init_autosave(); // Initializes autosave parameters - void init_lua(); // Initializes lua interpreter. void create_starting_npcs(); // Creates NPCs that start near you // V Menu Functions and helpers: diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 5434192e17b38..9e48a9a47a2a2 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -2180,7 +2180,6 @@ void Item_factory::clear() categories.clear(); - // Also clear functions referring to lua iuse_function_list.clear(); m_templates.clear(); diff --git a/src/item_factory.h b/src/item_factory.h index 1200f54531a89..408f880a487b0 100644 --- a/src/item_factory.h +++ b/src/item_factory.h @@ -62,13 +62,6 @@ class Item_factory * This should be called once after all json data has been loaded. */ void check_definitions() const; - /** - * Registers a LUA based iuse function. - * @param name The name that is used in the json data to refer to the LUA function. - * It is stored in @ref iuse_function_list - * @param lua_function The LUA id of the LUA function. - */ - void register_iuse_lua( const std::string &name, int lua_function ); /** * @name Item groups @@ -123,12 +116,10 @@ class Item_factory Item_spawn_data *get_group( const Group_tag &id ); /** * Returns the idents of all item groups that are known. - * This is meant to be accessed at startup by lua to do mod-related modifications of groups. */ std::vector get_all_group_names(); /** * Sets the chance of the specified item in the group. - * This is meant to be accessed at startup by lua to do mod-related modifications of groups. * @param group_id Group to add item to * @param item_id Id of item to add to group * @param weight The relative weight of the item. A value of 0 removes the item from the diff --git a/src/iuse.cpp b/src/iuse.cpp index 11cc0d3322b29..1c57c75424c3b 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -7905,3 +7905,42 @@ int iuse::magic_8_ball( player *p, item *it, bool, const tripoint & ) p->add_msg_if_player( color, _( "The %s says: %s" ), it->tname().c_str(), _( tab[rn] ) ); return 0; } + +use_function::use_function( const use_function &other ) + : actor( other.actor ? other.actor->clone() : nullptr ) +{ +} + +use_function &use_function::operator=( iuse_actor *const f ) +{ + return operator=( use_function( f ) ); +} + +use_function &use_function::operator=( const use_function &other ) +{ + actor.reset( other.actor ? other.actor->clone() : nullptr ); + return *this; +} + +void use_function::dump_info( const item &it, std::vector &dump ) const +{ + if( actor != nullptr ) { + actor->info( it, dump ); + } +} + +ret_val use_function::can_call( const player &p, const item &it, bool t, + const tripoint &pos ) const +{ + if( actor == nullptr ) { + return ret_val::make_failure( _( "You can't do anything interesting with your %s." ), + it.tname().c_str() ); + } + + return actor->can_use( p, it, t, pos ); +} + +long use_function::call( player &p, item &it, bool active, const tripoint &pos ) const +{ + return actor->use( p, it, active, pos ); +} diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt deleted file mode 100644 index f05f01fdad4b2..0000000000000 --- a/src/lua/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# CataclysmDDA Lua bindings -cmake_minimum_required(VERSION 2.8.12) - -MESSAGE(STATUS "Searching for Lua library --\n") - -SET(CATACLYSM_DDA_LUA_BINDING_SOURCES - ${CMAKE_SOURCE_DIR}/lua/class_definitions.lua - ${CMAKE_SOURCE_DIR}/src/lua/generate_bindings.lua -) - -add_custom_target ( - lua_bindings - ALL - DEPENDS ${CMAKE_SOURCE_DIR}/src/lua/catabindings.cpp - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -) - -ADD_CUSTOM_COMMAND ( - OUTPUT ${CMAKE_SOURCE_DIR}/src/lua/catabindings.cpp - COMMAND ${LUA_BINARY} generate_bindings.lua - DEPENDS ${CATACLYSM_DDA_LUA_BINDING_SOURCES} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/lua -) diff --git a/src/lua/generate_bindings.lua b/src/lua/generate_bindings.lua deleted file mode 100644 index 73792ca7d48d7..0000000000000 --- a/src/lua/generate_bindings.lua +++ /dev/null @@ -1,656 +0,0 @@ --- Tool to automatically generate bindings for lua. --- The bindings are generated as C++ and lua files, which are --- then included into the cataclysm source. - --- Conventions: --- The variable holding the name of a class is named "class_name" --- The variable holding the data (declarations etc.) of a class is "class" --- Example code: for class_name, class in pairs(classes) do ... - --- The generated helper C++ functions use this naming system: --- Getter: "get_" .. class_name .. "_" .. member_name --- Setter: "set_" .. class_name .. "_" .. member_name --- Member function: "func_" .. class_name .. "_" .. member_name --- Operators: "op_" .. class_name .. "_" .. operator_id --- Constructors: "new_" .. class_name --- Global functions get a "global_" prefix. --- This allows a data member "foo", as well as a function member "get_foo(...)". --- They would get "get_class_foo", "set_class_foo" and "func_class_get_foo" wrappers. - -local br = "\n" -local tab = " " - --- Helper function for sorted iteration over tables -local function sorted_pairs(t) - local keys = {} - for key in pairs(t) do - table.insert(keys, key) - end - table.sort(keys) - - return function() - local key = table.remove(keys, 1) - return key, t[key] - end -end - --- Generic helpers to generate C++ source code chunks for use in our lua binding. ---------------------------------------------------------------------------------- - --- Convert a given type such as "string" to the corresponding C++ wrapper class, --- e.g. `LuaType`. The wrapper class has various static functions: --- `get` to get a value of that type from Lua stack. --- `push` to push a value of that type to Lua stack. --- `check` and `has` to check for a value of that type on the stack. --- See catalua.h for their implementation. -function member_type_to_cpp_type(member_type) - if member_type == "bool" then return "LuaType" - elseif member_type == "cstring" then return "LuaType" - elseif member_type == "string" then return "LuaType" - elseif member_type == "int" then return "LuaType" - elseif member_type == "float" then return "LuaType" - else - for class_name, class in pairs(classes) do - if class_name == member_type then - if class.by_value then - return "LuaValue<" .. member_type .. ">" - elseif class.by_value_and_reference then - return "LuaValueOrReference<" .. member_type .. ">" - else - return "LuaReference<" .. member_type .. ">" - end - end - end - for enum_name, _ in pairs(enums) do - if enum_name == member_type then - return "LuaEnum<" .. member_type .. ">" - end - end - - error("'"..member_type.."' is not a build-in type and is not defined in class_definitions.lua") - end -end - --- Loads an instance of class_name (which must be the first thing on the stack) into a local --- variable, named "instance". Only use for classes (not enums/primitives). -function load_instance(class_name) - if not classes[class_name] then - error("'"..class_name.."' is not defined in class_definitions.lua") - end - - return class_name .. "& instance = " .. retrieve_lua_value(class_name, 1) .. ";" -end - --- Returns a full statement that checks whether the given stack item has the given value. --- The statement does not return if the check fails (long jump back into the Lua error handling). -function check_lua_value(value_type, stack_position) - return member_type_to_cpp_type(value_type).."::check(L, " .. stack_position .. ");" -end - --- Returns an expression that evaluates to `true` if the stack has an object of the given type --- at the given position. -function has_lua_value(value_type, stack_position) - return member_type_to_cpp_type(value_type) .. "::has(L, " .. stack_position .. ")" -end - --- Returns code to retrieve a lua value from the stack and store it into --- a C++ variable -function retrieve_lua_value(value_type, stack_position) - return member_type_to_cpp_type(value_type) .. "::get(L, " .. stack_position .. ")" -end - --- Returns code to take a C++ variable of the given type and push a lua version --- of it onto the stack. -function push_lua_value(in_variable, value_type) - local wrapper - if value_type:sub(-1) == "&" then - -- A reference is to be pushed. Copying the referred to object may not be allowed (it may - -- be a reference to a global game object). - local t = value_type:sub(1, -2) - if classes[t] then - if classes[t].by_value_and_reference then - -- special case becaus member_type_to_cpp_type would return LuaValueOrReference, - -- which does not have a push function. - wrapper = "LuaReference<" .. t .. ">" - else - wrapper = member_type_to_cpp_type(t) - end - else - wrapper = member_type_to_cpp_type(t) - end - elseif classes[value_type] then - -- Not a native Lua type, but it's not a reference, so we *have* to copy it (the value would - -- go out of scope otherwise). Copy semantic means using LuaValue. - wrapper = "LuaValue<" .. value_type .. ">" - else - -- Either an undefined type or a native Lua type, both is handled in member_type_to_cpp_type - wrapper = member_type_to_cpp_type(value_type) - end - - return wrapper .. "::push(L, " .. in_variable .. ");" -end - --- Generates a getter function for a specific class and member variable. -function generate_getter(class_name, member_name, member_type, cpp_name) - local function_name = "get_" .. class_name .. "_" .. member_name - local text = "static int "..function_name.."(lua_State *L) {"..br - - text = text .. tab .. load_instance(class_name)..br - - -- adding the "&" to the type, so push_lua_value knows it's a reference. - text = text .. tab .. push_lua_value("instance."..cpp_name, member_type .. "&")..br - - text = text .. tab .. "return 1; // 1 return value"..br - text = text .. "}" .. br - - return text -end - --- Generates a setter function for a specific class and member variable. -function generate_setter(class_name, member_name, member_type, cpp_name) - local function_name = "set_" .. class_name .. "_" .. member_name - - local text = "static int "..function_name.."(lua_State *L) {"..br - - text = text .. tab .. load_instance(class_name)..br - - text = text .. tab .. check_lua_value(member_type, 2)..";"..br - text = text .. tab .. "instance."..cpp_name.." = " .. retrieve_lua_value(member_type, 2)..";"..br - - text = text .. tab .. "return 0; // 0 return values"..br - text = text .. "}" .. br - - return text -end - --- Generates a function wrapper for a global function. "function_to_call" can be any string --- that works as a "function", including expressions like "g->add_msg" -function generate_global_function_wrapper(function_name, function_to_call, args, rval) - local text = "static int global_"..function_name.."(lua_State *L) {"..br - - for i, arg in ipairs(args) do - text = text .. tab .. check_lua_value(arg, i)..br - -- Needs to be auto, can be a proxy object, a real reference, or a POD. - -- This will be resolved when the functin is called. The C++ compiler will convert - -- the auto to the expected parameter type. - text = text .. tab .. "auto && parameter"..i .. " = " .. retrieve_lua_value(arg, i)..";"..br - end - - local func_invoc = function_to_call .. "(" - for i, arg in ipairs(args) do - func_invoc = func_invoc .. "parameter"..i - if next(args, i) then func_invoc = func_invoc .. ", " end - end - func_invoc = func_invoc .. ")" - - if rval then - text = text .. tab .. push_lua_value(func_invoc, rval)..br - text = text .. tab .. "return 1; // 1 return values"..br - else - text = text .. tab .. func_invoc .. ";"..br - text = text .. tab .. "return 0; // 0 return values"..br - end - text = text .. "}"..br - - return text -end - ---[[ -To allow function overloading, we need to create a function that somehow detects the input -types and calls the matching C++ overload. -First step is to restructure the input: instead of -functions = { - { name = "f", ... }, - { name = "f", ... }, - { name = "f", ... }, -} -we want a decision tree. The leafs of the tree are the rval entries (they can be different for -each overload, but they do not affect the overload resolution). -Example: functions = { - r = { rval = "int", cpp_name = "f" } - "string" = { - r = { rval = "int", cpp_name = "f" } - }, - "int" = { - r = { rval = "bool", cpp_name = "f" } - "int" = { - r = { rval = "void", cpp_name = "f" } - }, - "string" = { - r = { rval = "int", cpp_name = "f" } - } - } -} -Means: `int f()` `int f(string)` `bool f(int)` void f(int, int)` `int f(int, string)` -Leafs are marked by the presence of rval entries. ---]] -function generate_overload_tree(classes) - for class_name, value in pairs(classes) do - local functions_by_name = {} - for _, func in ipairs(value.functions) do - if not func.name then - print("Every function of " .. class_name .. " needs a name, doesn't it?") - end - -- Create the table now. In the next loop below, we can simply assume it already exists - functions_by_name[func.name] = {} - end - -- This creates the mentioned tree: each entry has the key matching the parameter type, - -- and the final table (the leaf) has a `r` entry. - for _, func in ipairs(value.functions) do - local root = functions_by_name[func.name] - for _, arg in pairs(func.args) do - if not root[arg] then - root[arg] = {} - end - root = root[arg] - end - root.r = { rval = func.rval, cpp_name = func.cpp_name or func.name } - end - value.functions = functions_by_name - - if value.new then - local new_root = {} - for _, func in ipairs(value.new) do - local root = new_root - for _, arg in pairs(func) do - if not root[arg] then - root[arg] = {} - end - root = root[arg] - end - root.r = { rval = nil, cpp_name = class_name .. "::" .. class_name } - end - value.new = new_root - end - end -end - ---[[ -This (recursive) function handles function overloading: -- function_name: actual function name (only for showing an error message) -- args: tree of argument (see generate_overload_tree) -- indentation: level of indentation of the source code (only used for nice formatting) -- stack_index: index (1-based, because this is Lua) of the currently handled argument. -- cbc: callback that returns the C++ code that actually calls the C++ function. - Its parameters: - - indentation: level of indentation it should use - - stack_index: number of parameters it can use (C++ variables parameter1, parameter2 and so on) - - rval: type of the object the C++ function returns (can be nil) - - cpp_name: name of the C++ function to call. ---]] -function insert_overload_resolution(function_name, args, cbc, indentation, stack_index) - local ind = string.rep(" ", indentation) - local text = "" - -- Number of choices that can be made for function overloading - local count = 0 - for _ in pairs(args) do count = count + 1 end - local more = (count ~= 1) - -- If we can chose several overloads at this point (more=true), we have to add if statements - -- and have to increase the indentation inside of them. - -- Otherwise (no choices), we keep everything at the same indentation level. - -- (e.g. no overload at all, or this parameter is the same for all overloads). - local nsi = stack_index + 1 -- next stack_index - local ni = more and (indentation + 1) or indentation -- next indentation - local mind = more and (ind .. tab) or ind -- more indentation - local valid_types = "" -- list of acceptable types, for the error message - for arg_type, more_args in sorted_pairs(args) do - if arg_type == "r" then - -- handled outside this loop - else - if more then - -- Either check the type here (and continue when it's fine) - text = text..ind.."if("..has_lua_value(arg_type, nsi)..") {"..br - else - -- or check it here and let Lua bail out. - text = text..ind..check_lua_value(arg_type, nsi)..br - end - -- Needs to be auto, can be a proxy object, a real reference, or a POD. - -- This will be resolved when the functin is called. The C++ compiler will convert - -- the auto to the expected parameter type. - text = text..mind.."auto && parameter"..stack_index.." = "..retrieve_lua_value(arg_type, nsi)..";"..br - text = text..insert_overload_resolution(function_name, more_args, cbc, ni, nsi) - if more then - text = text..ind.."}"..br - end - valid_types = valid_types.." or "..arg_type - end - end - -- An overload can be called at this level, all required parameters are already extracted. - if args.r then - if more then - text = text .. ind .. "if(lua_gettop(L) == "..stack_index..") {"..br - end - -- If we're here, any further arguments will ignored, so raise an error if there are any left over - text = text..mind.."if(lua_gettop(L) > "..stack_index..") {"..br - text = text..mind..tab.."return luaL_error(L, \"Too many arguments to "..function_name..", expected only "..stack_index..", got %d\", lua_gettop(L));"..br - text = text..mind.."}"..br - text = text .. cbc(ni, stack_index - 1, args.r.rval, args.r.cpp_name) - if more then - text = text .. ind .. "}"..br - end - valid_types = valid_types .. " or nothing at all" - end - -- If more is false, there was no branching (no `if` statement) generated, but a return - -- statement had already been made, so this error would be unreachable code. - if more then - text = text .. ind .. "return luaL_argerror(L, "..stack_index..", \"Unexpected type, expected are "..valid_types:sub(5).."\");"..br - end - return text -end - --- Generate a wrapper around a class function(method) that allows us to call a method of a specific --- C++ instance by calling the method on the corresponding lua wrapper, e.g. --- monster:name() in lua translates to monster.name() in C++ -function generate_class_function_wrapper(class_name, function_name, func, cur_class_name) - local text = "static int func_" .. class_name .. "_" .. function_name .. "(lua_State *L) {"..br - - -- retrieve the object to call the function on from the stack. - text = text .. tab .. load_instance(class_name)..br - - local cbc = function(indentation, stack_index, rval, function_to_call) - local tab = string.rep(" ", indentation) - - local func_invoc - if cur_class_name == class_name then - func_invoc = "instance" - else - --[[ - If we call a function of the parent class, we need to call it through - a reference to the parent class, otherwise we get into trouble with default parameters: - Example: - class A { void f(int = 0); } - class B : A { void f(int); } - This won't work: B b; b.f(); - But this will: B b; static_cast(b).f() - --]] - func_invoc = "static_cast<"..cur_class_name.."&>(instance)" - end - func_invoc = func_invoc .. "."..function_to_call .. "(" - - for i = 1,stack_index do - func_invoc = func_invoc .. "parameter"..i - if i < stack_index then func_invoc = func_invoc .. ", " end - end - func_invoc = func_invoc .. ")" - - local text - if rval then - text = tab .. push_lua_value(func_invoc, rval)..br - text = text .. tab .. "return 1; // 1 return values"..br - else - text = tab .. func_invoc .. ";"..br - text = text .. tab .. "return 0; // 0 return values"..br - end - return text - end - - text = text .. insert_overload_resolution(function_name, func, cbc, 1, 1) - - text = text .. "}"..br - - return text -end - -function generate_constructor(class_name, args) - local text = "static int new_" .. class_name .. "(lua_State *L) {"..br - - local cbc = function(indentation, stack_index, rval, function_to_call) - local tab = string.rep(" ", indentation) - - -- Push is always done on a value, never on a pointer/reference, therefor don't use - -- `push_lua_value` (which uses member_type_to_cpp_type to get either LuaValue or LuaReference). - local text = tab .. "LuaValue<" .. class_name .. ">::push(L" - - for i = 1,stack_index do - text = text .. ", parameter"..i - end - - text = text .. ");"..br - text = text .. tab .. "return 1; // 1 return values"..br - return text - end - - text = text .. insert_overload_resolution(class_name .. "::" .. class_name, args, cbc, 1, 1) - - text = text .. "}"..br - - return text -end - -function generate_operator(class_name, operator_id, cppname) - local text = "static int op_" .. class_name .. "_" .. operator_id .. "(lua_State *L) {"..br - - text = text .. tab .. "const " .. class_name .. " &lhs = " .. retrieve_lua_value(class_name, 1) .. ";"..br - text = text .. tab .. "const " .. class_name .. " &rhs = " .. retrieve_lua_value(class_name, 2) .. ";"..br - - text = text .. tab .. "bool rval = " - - if classes[class_name].by_value then - text = text .. "lhs " .. cppname .. " rhs"; - else - -- Both objects are pointers, they need to point to the same object to be equal. - text = text .. "&lhs " .. cppname .. " &rhs"; - end - text = text .. ";"..br - - text = text .. tab .. push_lua_value("rval", "bool")..br - text = text .. tab .. "return 1; // 1 return values"..br - text = text .. "}"..br - - return text -end - --- Generate our C++ source file with all wrappers for accessing variables and functions from lua. -------------------------------------------------------------------------------------------------- -local cpp_output = "// This file was automatically generated by lua/generate_bindings.lua"..br - -local lua_output = "" - -dofile "../../lua/class_definitions.lua" - -generate_overload_tree(classes) - -function generate_accessors(class, class_name) - -- Generate getters and setters for our player attributes. - for key, attribute in sorted_pairs(class) do - cpp_output = cpp_output .. generate_getter(class_name, key, attribute.type, attribute.cpp_name or key) - if attribute.writable then - cpp_output = cpp_output .. generate_setter(class_name, key, attribute.type, attribute.cpp_name or key) - end - end -end - -function generate_class_function_wrappers(functions, class_name, cur_class_name) - for index, func in sorted_pairs(functions) do - cpp_output = cpp_output .. generate_class_function_wrapper(class_name, index, func, cur_class_name) - end -end - -for class_name, class in sorted_pairs(classes) do - while class do - generate_accessors(class.attributes, class_name) - class = classes[class.parent] - end -end - -for class_name, class in sorted_pairs(classes) do - local cur_class_name = class_name - while class do - generate_class_function_wrappers(class.functions, class_name, cur_class_name) - if class.new then - cpp_output = cpp_output .. generate_constructor(class_name, class.new) - end - if class.has_equal then - cpp_output = cpp_output .. generate_operator(class_name, "eq", "==") - end - cur_class_name = class.parent - class = classes[class.parent] - end -end - -for name, func in sorted_pairs(global_functions) do - cpp_output = cpp_output .. generate_global_function_wrapper(name, func.cpp_name, func.args, func.rval) -end - --- luaL_Reg is the name of the struct in C which this creates and returns. -function luaL_Reg(cpp_name, lua_name) - return tab .. '{"' .. lua_name .. '", ' .. cpp_name .. '},' .. br -end --- Creates the LuaValue::FUNCTIONS array, containing all the public functions of the class. -function generate_functions_static(cpp_type, class, class_name) - cpp_output = cpp_output .. "template<>" .. br - cpp_output = cpp_output .. "const luaL_Reg " .. cpp_type .. "::FUNCTIONS[] = {" .. br - while class do - for name, _ in sorted_pairs(class.functions) do - cpp_output = cpp_output .. luaL_Reg("func_" .. class_name .. "_" .. name, name) - end - if class.new then - cpp_output = cpp_output .. luaL_Reg("new_" .. class_name, "__call") - end - if class.has_equal then - cpp_output = cpp_output .. luaL_Reg("op_" .. class_name .. "_eq", "__eq") - end - class = classes[class.parent] - end - cpp_output = cpp_output .. tab .. "{NULL, NULL}" .. br -- sentinel to indicate end of array - cpp_output = cpp_output .. "};" .. br -end --- Creates the LuaValue::READ_MEMBERS map, containing the getters. Example: --- const LuaValue::MRMap LuaValue::READ_MEMBERS{ { "id", foo_get_id }, ... }; -function generate_read_members_static(cpp_type, class, class_name) - cpp_output = cpp_output .. "template<>" .. br - cpp_output = cpp_output .. "const " .. cpp_type .. "::MRMap " .. cpp_type .. "::READ_MEMBERS{" .. br - while class do - for key, attribute in sorted_pairs(class.attributes) do - local function_name = "get_" .. class_name .. "_" .. key - cpp_output = cpp_output .. tab .. "{\"" .. key .. "\", " .. function_name .. "}," .. br - end - class = classes[class.parent] - end - cpp_output = cpp_output .. "};" .. br -end --- Creates the LuaValue::READ_MEMBERS map, containing the setters. Example: --- const LuaValue::MWMap LuaValue::WRITE_MEMBERS{ { "id", foo_set_id }, ... }; -function generate_write_members_static(cpp_type, class, class_name) - cpp_output = cpp_output .. "template<>" .. br - cpp_output = cpp_output .. "const " .. cpp_type .. "::MWMap " .. cpp_type .. "::WRITE_MEMBERS{" .. br - while class do - for key, attribute in sorted_pairs(class.attributes) do - if attribute.writable then - local function_name = "set_" .. class_name .. "_" .. key - cpp_output = cpp_output .. tab .. "{\"" .. key .. "\", " .. function_name .. "}," .. br - end - end - class = classes[class.parent] - end - cpp_output = cpp_output .. "};" .. br -end - --- The static constant is always define in LuaValue (LuaReference gets it via inheritance) --- But LuaReference inherits from LuaValue! -function wrapper_base_class(class_name) - -- This must not be LuaReference because it is used for declaring/defining the static members - -- and those should onloy exist for LuaValue. - if classes[class_name].by_value then - return "LuaValue<" .. class_name .. ">" - else - return "LuaValue<" .. class_name .. "*>" - end -end - -function generate_LuaValue_constants(class_name, class, by_value_and_reference) - local cpp_name = "" - local metatable_name = "" - if by_value_and_reference then - -- A different metatable name, to allow the C++ wrappers to detect what the - -- object from Lua refers to. The wrappers can thereby be used by both types - -- at the same type. In other words: the created static functions `get_foo_member` - -- can be called on a value that was pushed to Lua via `Lua::push` (and is a value), - -- and values pushed via `LuaReference::push` (which is a pointer). - metatable_name = "value_of_" .. class_name .. "_metatable" - cpp_name = "LuaValue<" .. class_name .. ">" - else - metatable_name = class_name .. "_metatable" - cpp_name = wrapper_base_class(class_name) - end - cpp_output = cpp_output .. "template<>" .. br - cpp_output = cpp_output .. "const char * const " .. cpp_name .. "::METATABLE_NAME = \"" .. metatable_name .. "\";" .. br - cpp_output = cpp_output .. "template<>" .. br - cpp_output = cpp_output .. cpp_name.."::Type *"..cpp_name.."::get_subclass( lua_State* const S, const int i) {"..br - for child, class in sorted_pairs(classes) do - -- Note: while the function get_subclass resides in LuaValue, this calls into LuaValue or - -- LuaReference, that way we get a simple pointer. Unconditionally calling LuaValue::get, - -- would result in returning monster** (LuaValue::get returns a T&, applying `&` gives T*). - -- Now consider that T is already a pointer for LuaValue, so T* would be monster** - -- And that can not be converted to Creature**! - -- In the end, this function does not return T*. but std::remove_pointer::type* and that - -- is basically T* (if T is not a pointer) or T (if T is already a pointer). - local cpp_child_name = member_type_to_cpp_type(child); - if class.parent == class_name then - cpp_output = cpp_output .. tab .. "if("..cpp_child_name.."::has(S, i)) {" .. br - cpp_output = cpp_output .. tab .. tab .. "return &"..cpp_child_name.."::get( S, i );" .. br - cpp_output = cpp_output .. tab .. "}" .. br - end - end - cpp_output = cpp_output .. tab .. "(void)S; (void)i;" .. br -- just in case to prevent warnings - cpp_output = cpp_output .. tab .. "return nullptr;" .. br - cpp_output = cpp_output .. "}" .. br - generate_functions_static(cpp_name, class, class_name) - generate_read_members_static(cpp_name, class, class_name) - generate_write_members_static(cpp_name, class, class_name) -end - --- Create the static constant members of LuaValue -for class_name, class in sorted_pairs(classes) do - generate_LuaValue_constants(class_name, class, false) - if class.by_value_and_reference then - if class.by_value then - error("by_value_and_reference only works with classes that have `by_value = false`") - end - generate_LuaValue_constants(class_name, class, true) - end -end - --- Create a function that calls load_metatable on all the registered LuaValue's -cpp_output = cpp_output .. "static void load_metatables(lua_State* const L) {" .. br - -for class_name, class in sorted_pairs(classes) do - local cpp_name = wrapper_base_class(class_name) - -- If the class has a constructor, it should be exposed via a global name (which is the class name) - if class.new then - cpp_output = cpp_output .. tab .. cpp_name .. "::load_metatable( L, \"" .. class_name .. "\" );" .. br - else - cpp_output = cpp_output .. tab .. cpp_name .. "::load_metatable( L, nullptr );" .. br - end -end -cpp_output = cpp_output .. "}" .. br - --- Create bindings lists for enums -for enum_name, values in sorted_pairs(enums) do - local cpp_name = "LuaEnum<"..enum_name..">" - cpp_output = cpp_output .. "template<>" .. br - cpp_output = cpp_output .. "const "..cpp_name.."::EMap "..cpp_name.."::BINDINGS = {"..br - for _, name in ipairs(values) do - cpp_output = cpp_output .. tab.."{\""..name.."\", "..name.."},"..br - end - cpp_output = cpp_output .. "};" .. br -end - --- Create a lua registry with the global functions -cpp_output = cpp_output .. "static const struct luaL_Reg gamelib [] = {"..br - -for name, func in sorted_pairs(global_functions) do - cpp_output = cpp_output .. tab .. '{"'..name..'", global_'..name..'},'..br -end - -cpp_output = cpp_output .. tab .. "{NULL, NULL}"..br.."};"..br - --- We generated our binding, now write it to a .cpp file for inclusion in --- the main source code. -function writeFile(path,data) - local file = io.open(path,"wb") - file:write(data) - file:close() -end - -writeFile("catabindings.cpp", cpp_output) diff --git a/src/lua_console.cpp b/src/lua_console.cpp deleted file mode 100644 index 8579593fea96a..0000000000000 --- a/src/lua_console.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "lua_console.h" - -#include - -#include "catalua.h" -#include "input.h" -#include "string_input_popup.h" - -lua_console::lua_console() : cWin( catacurses::newwin( lines, width, 0, 0 ) ), - iWin( catacurses::newwin( 1, width, lines, 0 ) ) -{ -#ifndef LUA - text_stack.push_back( {_( "This build does not support Lua." ), c_red} ); -#else - text_stack.push_back( {_( "Welcome to the Lua console! Here you can enter Lua code." ), c_green} ); -#endif - text_stack.push_back( {_( "Press [Esc] to close the Lua console." ), c_blue} ); -} - -lua_console::~lua_console() = default; - -std::string lua_console::get_input() -{ - std::map> callbacks { - { - KEY_ESCAPE, [this]() - { - this->quit(); - return false; - } - }, - { - KEY_NPAGE, [this]() - { - this->scroll_up(); - return false; - } - }, - { - KEY_PPAGE, [this]() - { - this->scroll_down(); - return false; - } - } }; - string_input_popup popup; - popup.window( iWin, 0, 0, width ) - .max_length( width ) - .identifier( "LUA" ); - popup.callbacks = callbacks; - popup.query(); - return popup.text(); -} - -void lua_console::draw() -{ - werase( cWin ); - - // Some juggling to make sure text is aligned with the bottom of the console. - int stack_size = text_stack.size() - scroll; - for( int i = lines; i > lines - stack_size && i >= 0; i-- ) { - auto line = text_stack[stack_size - 1 - ( lines - i )]; - mvwprintz( cWin, i - 1, 0, line.second, line.first ); - } - - wrefresh( cWin ); -} - -void lua_console::quit() -{ - done = true; -} - -void lua_console::scroll_down() -{ - scroll = std::min( std::max( ( static_cast( text_stack.size() ) ) - lines, 0 ), scroll + 1 ); - draw(); -} - -void lua_console::scroll_up() -{ - scroll = std::max( 0, scroll - 1 ); - draw(); -} - -void lua_console::read_stream( std::stringstream &stream, nc_color text_color ) -{ - std::string line; - while( std::getline( stream, line ) ) { - for( auto str : foldstring( line, width ) ) { - text_stack.push_back( {str, text_color} ); - } - } - stream.str( std::string() ); // empty the buffer - stream.clear(); -} - -void lua_console::run() -{ - while( !done ) { - draw(); - - std::string input = get_input(); - -#ifdef LUA - call_lua( input ); - - read_stream( lua_output_stream, c_white ); - read_stream( lua_error_stream, c_red ); -#else - text_stack.push_back( {_( "This build does not support Lua." ), c_red} ); - text_stack.push_back( {_( "Press [Esc] to close the Lua console." ), c_blue} ); -#endif // LUA - } -} diff --git a/src/lua_console.h b/src/lua_console.h deleted file mode 100644 index 0f2bdf7158b4f..0000000000000 --- a/src/lua_console.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#ifndef LUA_CONSOLE_H -#define LUA_CONSOLE_H - -#include -#include -#include - -#include "cursesdef.h" -#include "output.h" - -class nc_color; - -class lua_console -{ - public: - lua_console(); - ~lua_console(); - void run(); - private: - const int width = TERMX; - const int lines = 10; - - catacurses::window cWin; - catacurses::window iWin; - - std::vector> text_stack; - std::string get_input(); - void draw(); - - bool done = false; - - int scroll = 0; - - void read_stream( std::stringstream &stream, nc_color text_color ); - - void quit(); - void scroll_up(); - void scroll_down(); -}; - -#endif // LUA_CONSOLE_H diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 7b37b1a37e4e7..dbb53c1d2be76 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -844,13 +844,8 @@ bool main_menu::load_character_tab() color1 = c_light_cyan; color2 = h_light_cyan; } else { - if( world_generator->world_need_lua_build( world_name ) ) { - color1 = c_dark_gray; - color2 = h_dark_gray; - } else { - color1 = c_white; - color2 = h_white; - } + color1 = c_white; + color2 = h_white; } mvwprintz( w_open, line, 15 + iMenuOffsetX + extra_w / 2, ( sel2 == i ? color2 : color1 ), "%s (%d)", @@ -898,12 +893,7 @@ bool main_menu::load_character_tab() mvwprintz( w_open, iMenuOffsetY - 2 - sel2, 15 + iMenuOffsetX + extra_w / 2, h_white, "%s", wn.c_str() ); - if( ( wn != "TUTORIAL" && wn != "DEFENSE" ) && world_generator->world_need_lua_build( wn ) ) { - savegames.clear(); - mvwprintz( w_open, iMenuOffsetY - 2 - sel2, 40 + iMenuOffsetX + extra_w / 2, - c_red, "%s", _( "This world requires the game to be compiled with Lua." ) ); - on_error(); - } else if( savegames.empty() ) { + if( savegames.empty() ) { mvwprintz( w_open, iMenuOffsetY - 2 - sel2, 40 + iMenuOffsetX + extra_w / 2, c_red, "%s", _( "No save games found!" ) ); on_error(); diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 886dbe2e69239..94d1aaba9bc27 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -8,7 +8,6 @@ #include #include "ammo.h" -#include "catalua.h" #include "computer.h" #include "coordinate_conversions.h" #include "coordinates.h" @@ -209,14 +208,6 @@ void mapgen_function_builtin::generate( map *m, const oter_id &terrain_type, con const time_point &t, float d ) { ( *fptr )( m, terrain_type, mgd, t, d ); - - const std::string mapgen_generator_type = "builtin"; - const tripoint terrain_tripoint = sm_to_omt_copy( m->get_abs_sub() ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( mapgen_generator_type ); - lua_callback_args_info.emplace_back( terrain_type.id().str() ); - lua_callback_args_info.emplace_back( terrain_tripoint ); - lua_callback( "on_mapgen_finished", lua_callback_args_info ); } ///////////////////////////////////////////////////////////////////////////////// @@ -322,29 +313,6 @@ load_mapgen_function( JsonObject &jio, const std::string &id_base, } else { debugmsg( "oter_t[%s]: Invalid mapgen function (missing \"name\" value).", id_base.c_str() ); } - } else if( mgtype == "lua" ) { // lua script - if( jio.has_string( "script" ) ) { // minified into one\nline - const std::string mgscript = jio.get_string( "script" ); - ret = std::make_shared( mgscript, mgweight ); - oter_mapgen[id_base].push_back( ret ); - } else if( jio.has_array( "script" ) ) { // or 1 line per entry array - std::string mgscript; - JsonArray jascr = jio.get_array( "script" ); - while( jascr.has_more() ) { - mgscript += jascr.next_string(); - mgscript += "\n"; - } - ret = std::make_shared( mgscript, mgweight ); - oter_mapgen[id_base].push_back( ret ); - // @todo: pass dirname current.json, because the latter two are icky - // } else if ( jio.has_string("file" ) { // or "same-dir-as-this/json/something.lua - } else { - debugmsg( "oter_t[%s]: Invalid mapgen function (missing \"script\" or \"file\" value).", - id_base.c_str() ); - } -#ifndef LUA - dbg( D_ERROR ) << "oter_t " << id_base << ": mapgen entry requires a build with LUA=1."; -#endif } else if( mgtype == "json" ) { if( jio.has_object( "object" ) ) { JsonObject jo = jio.get_object( "object" ); @@ -358,7 +326,7 @@ load_mapgen_function( JsonObject &jio, const std::string &id_base, debugmsg( "oter_t[%s]: Invalid mapgen function type: %s", id_base.c_str(), mgtype.c_str() ); } } else { - debugmsg( "oter_t[%s]: Invalid mapgen function (missing \"method\" value, must be \"builtin\", \"lua\", or \"json\").", + debugmsg( "oter_t[%s]: Invalid mapgen function (missing \"method\" value, must be \"builtin\" or \"json\").", id_base.c_str() ); } return ret; @@ -1908,17 +1876,6 @@ bool mapgen_function_json::setup_internal( JsonObject &jo ) fill_ter = ter_str_id( jo.get_string( "fill_ter" ) ).id(); } - if( jo.has_string( "lua" ) ) { // minified into one\nline - luascript = jo.get_string( "lua" ); - } else if( jo.has_array( "lua" ) ) { // or 1 line per entry array - luascript.clear(); - JsonArray jascr = jo.get_array( "lua" ); - while( jascr.has_more() ) { - luascript += jascr.next_string(); - luascript += "\n"; - } - } - if( jo.has_member( "rotation" ) ) { rotation = jmapgen_int( jo, "rotation" ); } @@ -2263,7 +2220,7 @@ void mapgen_function_json_base::formatted_set_incredibly_simple( map &m, int off * Apply mapgen as per a derived-from-json recipe; in theory fast, but not very versatile */ void mapgen_function_json::generate( map *m, const oter_id &terrain_type, const mapgendata &md, - const time_point &t, float d ) + const time_point &, float d ) { if( fill_ter != t_null ) { m->draw_fill_background( fill_ter ); @@ -2274,9 +2231,6 @@ void mapgen_function_json::generate( map *m, const oter_id &terrain_type, const for( auto &elem : setmap_points ) { elem.apply( md, 0, 0 ); } - if( ! luascript.empty() ) { - lua_mapgen( m, terrain_type, md, t, d, luascript ); - } place_stairs( m, terrain_type, md ); @@ -2287,14 +2241,6 @@ void mapgen_function_json::generate( map *m, const oter_id &terrain_type, const if( terrain_type->is_rotatable() ) { mapgen_rotate( m, terrain_type, false ); } - - const std::string mapgen_generator_type = "json"; - const tripoint terrain_tripoint = sm_to_omt_copy( m->get_abs_sub() ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( mapgen_generator_type ); - lua_callback_args_info.emplace_back( terrain_type.id().str() ); - lua_callback_args_info.emplace_back( terrain_tripoint ); - lua_callback( "on_mapgen_finished", lua_callback_args_info ); } void mapgen_function_json_nested::nest( const mapgendata &dat, int offset_x, int offset_y, @@ -2349,47 +2295,6 @@ void jmapgen_objects::apply( const mapgendata &dat, int offset_x, int offset_y, } } -///////////////////////////////////////////////////////////////////////////////// -///// lua mapgen functions -// wip: need more bindings. Basic stuff works - -#ifndef LUA -int lua_mapgen( map *m, const oter_id &terrain_type, const mapgendata &mgd, const time_point &t, - float d, const std::string & ) -{ - mapgen_crater( m, terrain_type, mgd, to_turn( t ), d ); - mapf::formatted_set_simple( m, 0, 6, - "\ - * * ***\n\ - ** * * *\n\ - * * * * *\n\ - * ** * *\n\ - * * ***\n\ -\n\ - * * * *\n\ - * * * * *\n\ - * * * ***\n\ - * * * * *\n\ - ***** *** * *\n\ -", mapf::ter_bind( "*", t_paper ), mapf::furn_bind( "*", f_null ) ); - return 0; -} -#endif - -void mapgen_function_lua::generate( map *m, const oter_id &terrain_type, const mapgendata &mgd, - const time_point &t, float d ) -{ - lua_mapgen( m, terrain_type, mgd, t, d, scr ); - - const std::string mapgen_generator_type = "lua"; - const tripoint terrain_tripoint = sm_to_omt_copy( m->get_abs_sub() ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( mapgen_generator_type ); - lua_callback_args_info.emplace_back( terrain_type.id().str() ); - lua_callback_args_info.emplace_back( terrain_tripoint ); - lua_callback( "on_mapgen_finished", lua_callback_args_info ); -} - ///////////// // TODO: clean up variable shadowing in this function // unfortunately, due to how absurdly long the function is (over 8000 lines!), it'll be hard to diff --git a/src/mapgen.h b/src/mapgen.h index cd22066e29c8c..e7dad1c68ac47 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -310,7 +310,6 @@ class mapgen_function_json : public mapgen_function_json_base, public virtual ma ~mapgen_function_json() override = default; ter_id fill_ter; - std::string luascript; protected: bool setup_internal( JsonObject &jo ) override; @@ -335,17 +334,6 @@ class mapgen_function_json_nested : public mapgen_function_json_base jmapgen_int rotation; }; -///////////////////////////////////////////////////////////////////////////////// -///// lua mapgen -class mapgen_function_lua : public virtual mapgen_function -{ - public: - const std::string scr; - mapgen_function_lua( std::string s, int w = 1000 ) : mapgen_function( w ), scr( s ) { - // scr = s; // @todo: if ( luaL_loadstring(L, scr.c_str() ) ) { error } - } - void generate( map *, const oter_id &, const mapgendata &, const time_point &, float ) override; -}; ///////////////////////////////////////////////////////// ///// global per-terrain mapgen function lists /* diff --git a/src/mod_manager.cpp b/src/mod_manager.cpp index 5dc60b56610d9..798b27c80ae0f 100644 --- a/src/mod_manager.cpp +++ b/src/mod_manager.cpp @@ -100,11 +100,6 @@ void mod_manager::load_replacement_mods( const std::string &path ) } ); } -bool MOD_INFORMATION::need_lua() const -{ - return file_exist( path + "/main.lua" ) || file_exist( path + "/preload.lua" ); -} - mod_manager::mod_manager() { load_replacement_mods( FILENAMES["mods-replacements"] ); diff --git a/src/mod_manager.h b/src/mod_manager.h index 14022ae4b1928..437105b386ebe 100644 --- a/src/mod_manager.h +++ b/src/mod_manager.h @@ -36,7 +36,7 @@ struct MOD_INFORMATION { mod_id ident; - /** Directory to load JSON and Lua from relative to directory containing modinfo.json */ + /** Directory to load JSON from relative to directory containing modinfo.json */ std::string path; /** If set load legacy migrations from this location dependent upon save version */ @@ -63,9 +63,6 @@ struct MOD_INFORMATION { /** Obsolete mods are loaded for legacy saves but cannot be used when starting new worlds */ bool obsolete = false; - /** Does this mod require Lua support? **/ - bool need_lua() const; - std::pair category = { -1, "" }; }; diff --git a/src/mod_manager_ui.cpp b/src/mod_manager_ui.cpp index 7417d9dfd26cd..4a9849e8402db 100644 --- a/src/mod_manager_ui.cpp +++ b/src/mod_manager_ui.cpp @@ -54,14 +54,6 @@ std::string mod_ui::get_information( const MOD_INFORMATION *mod ) info << _( mod->description.c_str() ) << "\n"; } - if( mod->need_lua() ) { -#ifdef LUA - info << _( "This mod requires Lua support" ) << "\n"; -#else - info << _( "This mod requires Lua support" ) << "\n"; -#endif - } - std::string note = !mm_tree.is_available( mod->ident ) ? mm_tree.get_node( mod->ident )->s_errors() : ""; if( !note.empty() ) { diff --git a/src/monstergenerator.h b/src/monstergenerator.h index deae39a232811..2b43a0fdb3c72 100644 --- a/src/monstergenerator.h +++ b/src/monstergenerator.h @@ -69,13 +69,6 @@ class MonsterGenerator const std::vector &get_all_mtypes() const; mtype_id get_valid_hallucination() const; - /** - * Registers a LUA based monster attack function. - * @param name The name that is used in the json data to refer to the LUA function. - * It is stored in @ref attack_map - * @param lua_function The LUA id of the LUA function. - */ - void register_monattack_lua( const std::string &name, int lua_function ); friend struct mtype; friend struct species_type; friend class mattack_actor; diff --git a/src/mutation.h b/src/mutation.h index 7074a5ed03844..94ec5320de601 100644 --- a/src/mutation.h +++ b/src/mutation.h @@ -325,7 +325,6 @@ struct mutation_branch { /** * Return the idents of all trait groups that are known. - * This is meant to be accessed at startup by lua to do mod-related modifications of groups. */ static std::vector get_all_group_names(); }; diff --git a/src/path_info.cpp b/src/path_info.cpp index 668c4012d46c6..5534b0667cba3 100644 --- a/src/path_info.cpp +++ b/src/path_info.cpp @@ -70,7 +70,6 @@ void PATH_INFO::update_datadir() { // Shared dirs update_pathname( "gfxdir", FILENAMES["datadir"] + "gfx/" ); - update_pathname( "luadir", FILENAMES["datadir"] + "lua/" ); update_pathname( "fontdir", FILENAMES["datadir"] + "font/" ); update_pathname( "rawdir", FILENAMES["datadir"] + "raw/" ); update_pathname( "jsondir", FILENAMES["datadir"] + "core/" ); @@ -84,8 +83,6 @@ void PATH_INFO::update_datadir() update_pathname( "helpdir", FILENAMES["datadir"] + "help/" ); // Shared files - update_pathname( "autoexeclua", FILENAMES["luadir"] + "autoexec.lua" ); - update_pathname( "class_defslua", FILENAMES["luadir"] + "class_definitions.lua" ); update_pathname( "title", FILENAMES["titledir"] + "en.title" ); update_pathname( "halloween", FILENAMES["titledir"] + "en.halloween" ); update_pathname( "motd", FILENAMES["motddir"] + "en.motd" ); @@ -121,26 +118,21 @@ void PATH_INFO::update_config_dir() void PATH_INFO::set_standard_filenames() { - // Special: data_dir lua_dir and gfx_dir + // Special: data_dir and gfx_dir if( !FILENAMES["base_path"].empty() ) { #ifdef DATA_DIR_PREFIX update_pathname( "datadir", FILENAMES["base_path"] + "share/cataclysm-dda/" ); update_pathname( "gfxdir", FILENAMES["datadir"] + "gfx/" ); - update_pathname( "luadir", FILENAMES["datadir"] + "lua/" ); #else update_pathname( "datadir", FILENAMES["base_path"] + "data/" ); update_pathname( "gfxdir", FILENAMES["base_path"] + "gfx/" ); - update_pathname( "luadir", FILENAMES["base_path"] + "lua/" ); #endif } else { update_pathname( "datadir", "data/" ); update_pathname( "gfxdir", "gfx/" ); - update_pathname( "luadir", "lua/" ); } // Shared dirs - update_pathname( "autoexeclua", FILENAMES["luadir"] + "autoexec.lua" ); - update_pathname( "class_defslua", FILENAMES["luadir"] + "class_definitions.lua" ); update_pathname( "fontdir", FILENAMES["datadir"] + "font/" ); update_pathname( "rawdir", FILENAMES["datadir"] + "raw/" ); update_pathname( "jsondir", FILENAMES["datadir"] + "core/" ); diff --git a/src/player.cpp b/src/player.cpp index 270a74e113c63..1144ca9643595 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -16,7 +16,6 @@ #include "bionics.h" #include "cata_utility.h" #include "catacharset.h" -#include "catalua.h" #include "coordinate_conversions.h" #include "craft_command.h" #include "cursesdef.h" @@ -3117,11 +3116,6 @@ void player::on_dodge( Creature *source, float difficulty ) melee_attack( *source, false, tec ); } } - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( source ); - lua_callback_args_info.emplace_back( difficulty ); - lua_callback( "on_player_dodge", lua_callback_args_info ); } void player::on_hit( Creature *source, body_part bp_hit, @@ -3198,12 +3192,6 @@ void player::on_hit( Creature *source, body_part bp_hit, source->add_effect( effect_blind, 2_turns ); } } - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( source ); - lua_callback_args_info.emplace_back( bp_hit ); - //lua_callback_args_info.emplace_back( proj ); - lua_callback( "on_player_hit", lua_callback_args_info ); } int player::get_lift_assist() const @@ -3247,11 +3235,6 @@ void player::on_hurt( Creature *source, bool disturb /*= true*/ ) if( is_dead_state() ) { set_killer( source ); } - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( source ); - lua_callback_args_info.emplace_back( disturb ); - lua_callback( "on_player_hurt", lua_callback_args_info ); } bool player::immune_to( body_part bp, damage_unit dam ) const @@ -9889,14 +9872,6 @@ void player::do_read( item &book ) pgettext( "memorial_female", "Reached skill level %1$d in %2$s." ), skill_level.level(), skill_name ); } - const std::string skill_increase_source = "book"; - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( skill_increase_source ); - lua_callback_args_info.emplace_back( skill.str() ); - lua_callback_args_info.emplace_back( originalSkillLevel + 1 ); - lua_callback( "on_player_skill_increased", lua_callback_args_info ); - lua_callback( "on_skill_increased" ); // Legacy callback } else { add_msg( m_good, _( "%s increases their %s level." ), learner->disp_name().c_str(), skill_name ); } @@ -11141,14 +11116,6 @@ void player::practice( const skill_id &id, int amount, int cap ) int newLevel = get_skill_level( id ); if( is_player() && newLevel > oldLevel ) { add_msg( m_good, _( "Your skill in %s has increased to %d!" ), skill_name, newLevel ); - const std::string skill_increase_source = "training"; - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( skill_increase_source ); - lua_callback_args_info.emplace_back( id.str() ); - lua_callback_args_info.emplace_back( newLevel ); - lua_callback( "on_player_skill_increased", lua_callback_args_info ); - lua_callback( "on_skill_increased" ); //Legacy callback } if( is_player() && newLevel > cap ) { //inform player immediately that the current recipe can't be used to train further @@ -12371,47 +12338,26 @@ bool player::has_item_with_flag( const std::string &flag, bool need_charges ) co void player::on_mutation_gain( const trait_id &mid ) { morale->on_mutation_gain( mid ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( mid.str() ); - lua_callback( "on_player_mutation_gain", lua_callback_args_info ); } void player::on_mutation_loss( const trait_id &mid ) { morale->on_mutation_loss( mid ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( mid.str() ); - lua_callback( "on_player_mutation_loss", lua_callback_args_info ); } void player::on_stat_change( const std::string &stat, int value ) { morale->on_stat_change( stat, value ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( stat ); - lua_callback_args_info.emplace_back( value ); - lua_callback( "on_player_stat_change", lua_callback_args_info ); } void player::on_item_wear( const item &it ) { morale->on_item_wear( it ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( it ); - lua_callback( "on_player_item_wear", lua_callback_args_info ); } void player::on_item_takeoff( const item &it ) { morale->on_item_takeoff( it ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( it ); - lua_callback( "on_player_item_takeoff", lua_callback_args_info ); } void player::on_worn_item_washed( const item &it ) @@ -12431,22 +12377,12 @@ void player::on_effect_int_change( const efftype_id &eid, int intensity, body_pa } morale->on_effect_int_change( eid, intensity, bp ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( eid.str() ); - lua_callback_args_info.emplace_back( intensity ); - lua_callback_args_info.emplace_back( bp ); - lua_callback( "on_player_effect_int_change", lua_callback_args_info ); } void player::on_mission_assignment( mission &new_mission ) { active_missions.push_back( &new_mission ); set_active_mission( new_mission ); - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( new_mission.get_id() ); - lua_callback( "on_player_mission_assignment", lua_callback_args_info ); } void player::on_mission_finished( mission &cur_mission ) @@ -12472,10 +12408,6 @@ void player::on_mission_finished( mission &cur_mission ) active_mission = active_missions.front(); } } - CallbackArgumentContainer lua_callback_args_info; - lua_callback_args_info.emplace_back( getID() ); - lua_callback_args_info.emplace_back( cur_mission.get_id() ); - lua_callback( "on_player_mission_finished", lua_callback_args_info ); } const targeting_data &player::get_targeting_data() diff --git a/src/worldfactory.cpp b/src/worldfactory.cpp index 5662d37941740..f209d0b18e8fc 100644 --- a/src/worldfactory.cpp +++ b/src/worldfactory.cpp @@ -157,19 +157,6 @@ WORLDPTR worldfactory::make_new_world( bool show_prompt, const std::string &worl if( curtab < 0 ) { return nullptr; } - } else { // 'Play NOW' -#ifndef LUA - // Silently remove all Lua mods set by default. - for( auto mod_it = retworld->active_mod_order.begin(); mod_it != retworld->active_mod_order.end(); - ) { - const MOD_INFORMATION &minfo = **mod_it; - if( minfo.need_lua() ) { - mod_it = retworld->active_mod_order.erase( mod_it ); - } else { - mod_it++; - } - } -#endif } return add_world( std::move( retworld ) ); @@ -347,8 +334,6 @@ WORLDPTR worldfactory::pick_world( bool show_prompt ) for( std::vector::iterator it = world_names.begin(); it != world_names.end(); ) { if( *it == "TUTORIAL" || *it == "DEFENSE" ) { it = world_names.erase( it ); - } else if( world_need_lua_build( *it ) ) { - it = world_names.erase( it ); } else { ++it; } @@ -462,11 +447,7 @@ WORLDPTR worldfactory::pick_world( bool show_prompt ) wprintz( w_worlds, c_yellow, " " ); } - if( world_need_lua_build( world_name ) ) { - wprintz( w_worlds, c_dark_gray, "%s (%lu)", world_name.c_str(), saves_num ); - } else { - wprintz( w_worlds, c_white, "%s (%lu)", world_name.c_str(), saves_num ); - } + wprintz( w_worlds, c_white, "%s (%lu)", world_name.c_str(), saves_num ); } //Draw Tabs @@ -522,12 +503,6 @@ WORLDPTR worldfactory::pick_world( bool show_prompt ) } } while( world_pages[selpage].empty() ); } else if( action == "CONFIRM" ) { - if( world_need_lua_build( world_pages[selpage][sel] ) ) { - popup( _( "Can't start in world [%s]. Some of mods require Lua support." ), - world_pages[selpage][sel].c_str() ); - continue; - } - werase( w_worlds ); werase( w_worlds_border ); werase( w_worlds_header ); @@ -652,15 +627,7 @@ void worldfactory::draw_mod_list( const catacurses::window &w, int &start, size_ } const MOD_INFORMATION &mod = **iter; -#ifndef LUA - if( mod.need_lua() ) { - trim_and_print( w, iNum - start, 4, wwidth, c_dark_gray, mod.name() ); - } else { - trim_and_print( w, iNum - start, 4, wwidth, c_white, mod.name() ); - } -#else trim_and_print( w, iNum - start, 4, wwidth, c_white, mod.name() ); -#endif if( w_shift ) { // get shift information for the active item @@ -974,15 +941,6 @@ int worldfactory::show_worldgen_tab_modselection( const catacurses::window &win, active_header = prev_header; } else if( action == "CONFIRM" ) { if( active_header == 0 && !current_tab_mods.empty() ) { -#ifndef LUA - if( current_tab_mods[cursel[0]]->need_lua() ) { - popup( _( "Can't add mod. This mod requires Lua support." ) ); - redraw_active = true; - draw_modselection_borders( win, ctxt ); - redraw_description = true; - continue; - } -#endif // try-add mman_ui->try_add( current_tab_mods[cursel[0]], active_mod_order ); redraw_active = true; @@ -1144,15 +1102,6 @@ to continue, or %s to go back and review your world." ), const std::string action = ctxt.handle_input(); if( action == "NEXT_TAB" ) { -#ifndef LUA - for( const mod_id &mod : world->active_mod_order ) { - const MOD_INFORMATION &temp = *mod; - if( temp.need_lua() ) { - popup( _( "Mod '%s' requires Lua support." ), temp.name() ); - return -2; // Move back to modselect tab. - } - } -#endif if( worldname.empty() ) { mvwprintz( w_confirmation, namebar_y, namebar_x, h_light_gray, _( "________NO NAME ENTERED!________" ) ); @@ -1322,25 +1271,6 @@ void worldfactory::draw_worldgen_tabs( const catacurses::window &w, size_t curre mvwputch( w, FULL_SCREEN_HEIGHT - 1, FULL_SCREEN_WIDTH - 1, BORDER_COLOR, LINE_XOOX ); // _| } -bool worldfactory::world_need_lua_build( std::string world_name ) -{ -#ifndef LUA - WORLDPTR world = get_world( world_name ); - - if( world == nullptr ) { - return false; - } - for( const mod_id &mod : world->active_mod_order ) { - if( mod.is_valid() && mod->need_lua() ) { - return true; - } - } -#endif - // Prevent unused var error when LUA and RELEASE enabled. - world_name.size(); - return false; -} - bool worldfactory::valid_worldname( const std::string &name, bool automated ) { std::string msg; diff --git a/src/worldfactory.h b/src/worldfactory.h index daafa8e4827fd..b7af537a8783f 100644 --- a/src/worldfactory.h +++ b/src/worldfactory.h @@ -112,12 +112,6 @@ class worldfactory void remove_world( const std::string &worldname ); bool valid_worldname( const std::string &name, bool automated = false ); - /** - * World need CDDA build with Lua support - * @param world_name World name to test - * @return True if world can't be loaded without Lua support. False otherwise. (When LUA is defined it's always false). - */ - bool world_need_lua_build( std::string world_name ); /** * @param delete_folder If true: delete all the files and directories of the given * world folder. Else just avoid deleting the config files and the directory diff --git a/tools/setuphgamelaunch.sh b/tools/setuphgamelaunch.sh index 882dfb0475052..fa467d7bfc849 100644 --- a/tools/setuphgamelaunch.sh +++ b/tools/setuphgamelaunch.sh @@ -62,7 +62,6 @@ mkdir -p $1/share/save mkdir -p $1/share/memorial cp -r ./data/. $1/share/cataclysm-dda cp -r ./gfx $1/share/cataclysm-dda -cp -r ./lua $1/share/cataclysm-dda cp -r ./lang $1/share/cataclysm-dda # Copying games.json