Merge branch 'master' into tls_wip

This commit is contained in:
loonycyborg 2021-05-12 21:39:21 +03:00
commit 56f9138de7
No known key found for this signature in database
GPG key ID: 6E8233FAB8F26D61
264 changed files with 4749 additions and 27694 deletions

View file

@ -295,40 +295,6 @@ jobs:
# in the case of needing to recompile the vcpkg-created Windows dependencies, increment the cache-name and key for both Release and Debug
# this will create a brand new cache and recompile the vcpkg dependencies from scratch
windows-release:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
# - name: Cache object files
# uses: actions/cache@v2
# env:
# cache-name: windows-release-cache-master
# with:
# path: D:/a/wesnoth/vcpkg
# key: windows-master-N003
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: DOS1
shell: cmd
run: |
git clone --shallow-since=2021-04-25 https://github.com/microsoft/vcpkg.git ../vcpkg
git -C ../vcpkg checkout a9b27ed5dffbf70b135eddb0c4729f3ca87f106c
%~dp0../wesnoth/vcpkg/bootstrap-vcpkg.bat
- name: DOS2
shell: cmd
run: |
%~dp0../wesnoth/vcpkg/vcpkg integrate install
%~dp0../wesnoth/vcpkg/vcpkg install sdl2:x64-windows sdl2-image:x64-windows sdl2-image[libjpeg-turbo]:x64-windows sdl2-mixer[libvorbis,dynamic-load]:x64-windows bzip2:x64-windows zlib:x64-windows pango:x64-windows cairo:x64-windows fontconfig:x64-windows libvorbis:x64-windows libogg:x64-windows boost-filesystem:x64-windows boost-iostreams:x64-windows boost-locale[icu]:x64-windows boost-random:x64-windows boost-regex[icu]:x64-windows boost-asio:x64-windows boost-program-options:x64-windows boost-system:x64-windows boost-bimap:x64-windows boost-multi-array:x64-windows boost-logic:x64-windows boost-format:x64-windows boost-scope-exit:x64-windows boost-circular-buffer:x64-windows boost-ptr-container:x64-windows
- name: DOS3
shell: cmd
run: |
MSBuild.exe projectfiles/VC16/wesnoth.sln -p:Configuration=Release -p:Platform=Win64
windows-debug:
runs-on: windows-2019
@ -337,38 +303,93 @@ jobs:
with:
submodules: "recursive"
# - name: Cache object files
# uses: actions/cache@v2
# env:
# cache-name: windows-debug-cache-master
# with:
# path: D:/a/wesnoth/vcpkg
# key: windows-master-N003
- name: Cache object files
id: windows-master-N007
uses: actions/cache@v2
with:
path: |
D:/a/wesnoth/vcpkg
D:/a/wesnoth/wesnoth/vcpkg_installed
key: windows-master-N007
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: DOS1
- name: Build vcpkg
shell: cmd
run: |
git clone --shallow-since=2021-04-25 https://github.com/microsoft/vcpkg.git ../vcpkg
git -C ../vcpkg checkout a9b27ed5dffbf70b135eddb0c4729f3ca87f106c
%~dp0../wesnoth/vcpkg/bootstrap-vcpkg.bat
- name: DOS2
git clone --depth=1 https://github.com/microsoft/vcpkg.git D:/a/wesnoth/vcpkg
D:/a/wesnoth/vcpkg/bootstrap-vcpkg.bat
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.8
- name: Use cmake
run: |
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_GAME=true -DENABLE_SERVER=true -DENABLE_CAMPAIGN_SERVER=true -DENABLE_TESTS=true -DENABLE_MYSQL=false -DENABLE_NLS=false -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_TOOLCHAIN_FILE=D:/a/wesnoth/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_GENERATOR_PLATFORM=x64 -G "Visual Studio 16 2019" .
# delete buildtrees directory to free up space after cmake invokes vcpkg to build the dependencies
# otherwise the job was failing when trying to write a .obj file
# building vcpkg on the more spacious C drive didn't work since for some reason vcpkg decides to not create the pango/cairo pkgconfig files there
- name: Build wesnoth
shell: cmd
run: |
%~dp0../wesnoth/vcpkg/vcpkg integrate install
%~dp0../wesnoth/vcpkg/vcpkg install sdl2:x64-windows sdl2-image:x64-windows sdl2-image[libjpeg-turbo]:x64-windows sdl2-mixer[libvorbis,dynamic-load]:x64-windows bzip2:x64-windows zlib:x64-windows pango:x64-windows cairo:x64-windows fontconfig:x64-windows libvorbis:x64-windows libogg:x64-windows boost-filesystem:x64-windows boost-iostreams:x64-windows boost-locale[icu]:x64-windows boost-random:x64-windows boost-regex[icu]:x64-windows boost-asio:x64-windows boost-program-options:x64-windows boost-system:x64-windows boost-thread:x64-windows boost-bimap:x64-windows boost-multi-array:x64-windows boost-logic:x64-windows boost-format:x64-windows boost-scope-exit:x64-windows boost-circular-buffer:x64-windows boost-ptr-container:x64-windows
- name: DOS3
shell: cmd
run: |
MSBuild.exe projectfiles/VC16/wesnoth.sln -p:Configuration=Debug -p:Platform=Win64
rmdir /s /q D:\a\wesnoth\vcpkg\buildtrees
MSBuild.exe wesnoth.sln -p:Configuration=Debug
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Windows-Debug
path: |
D:/a/wesnoth/wesnoth/wesnoth.exe
D:/a/wesnoth/wesnoth/wesnothd.exe
D:/a/wesnoth/wesnoth/wesnoth.pdb
D:/a/wesnoth/wesnoth/wesnothd.pdb
D:/a/wesnoth/wesnoth/Debug/wesnoth.exe
D:/a/wesnoth/wesnoth/Debug/wesnothd.exe
D:/a/wesnoth/wesnoth/Debug/wesnoth.pdb
D:/a/wesnoth/wesnoth/Debug/wesnothd.pdb
windows-release:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Cache object files
id: windows-master-N007
uses: actions/cache@v2
with:
path: |
D:/a/wesnoth/vcpkg
D:/a/wesnoth/wesnoth/vcpkg_installed
key: windows-master-N007
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Build vcpkg
shell: cmd
run: |
git clone --depth=1 https://github.com/microsoft/vcpkg.git D:/a/wesnoth/vcpkg
D:/a/wesnoth/vcpkg/bootstrap-vcpkg.bat
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.8
- name: Use cmake
run: |
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GAME=true -DENABLE_SERVER=true -DENABLE_CAMPAIGN_SERVER=true -DENABLE_TESTS=true -DENABLE_MYSQL=false -DENABLE_NLS=false -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_TOOLCHAIN_FILE=D:/a/wesnoth/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_GENERATOR_PLATFORM=x64 -G "Visual Studio 16 2019" .
# delete buildtrees directory to free up space after cmake invokes vcpkg to build the dependencies
# otherwise the job was failing when trying to write a .obj file
# building vcpkg on the more spacious C drive didn't work since for some reason vcpkg decides to not create the pango/cairo pkgconfig files there
- name: Build wesnoth
shell: cmd
run: |
rmdir /s /q D:\a\wesnoth\vcpkg\buildtrees
MSBuild.exe wesnoth.sln -p:Configuration=Release
- name: Run WML unit tests
shell: cmd
run: |
python run_wml_tests -v -g -c -t 20 -p D:/a/wesnoth/wesnoth/Release/wesnoth.exe

25
.gitignore vendored
View file

@ -49,25 +49,16 @@ projectfiles/**/*_build_log.html
projectfiles/**/*objs*
# Visual Studio
projectfiles/VC*
!projectfiles/VC16
projectfiles/VC*/.vs/
projectfiles/VC*/*.vc.*db
projectfiles/VC*/*.sdf
projectfiles/VC*/*.suo
projectfiles/VC*/*.aps
projectfiles/VC*/*.user
ALL_BUILD.vcproj
INSTALL.vcproj
PACKAGE.vcproj
ZERO_CHECK.vcproj
uninstall.vcproj
*.vcproj.*.user
src/**/*.vcproj
/WindowsTimeout.ilk
/WindowsTimeout.pdb
.vscode
/.vs
vcpkg_installed/
*.vcxproj
*.vcxproj.filters
doc/**/*.vcxproj
doc/**/*.vcxproj.filters
src/**/*.vcxproj
src/**/*.vcxproj.filters
vcpkg-manifest-install.log
# CLion
/.idea

View file

@ -1,5 +1,5 @@
# set minimum version
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.5)
project(wesnoth)
@ -67,37 +67,33 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT APPLE)
find_package(Crypto 1.0 REQUIRED)
find_package(OpenSSL 1.0 REQUIRED)
else()
set(CRYPTO_LIBRARY "-framework Security")
set(OPENSSL_CRYPTO_LIBRARY "-framework Security")
endif()
find_package(OpenSSL REQUIRED)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS iostreams
program_options regex system thread random coroutine)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS iostreams program_options regex system thread random coroutine locale filesystem)
# no, gettext executables are not required when NLS is deactivated
find_package(Gettext)
find_package(X11)
# needed to get some SDL2 defines in... (as of rev31694 -D_GNU_SOURCE=1 is required!)
if(NOT MINGW)
set(SDL2_CONFIG "sdl2-config" CACHE STRING "Path to sdl2-config script")
exec_program(${SDL2_CONFIG} ARGS "--cflags" OUTPUT_VARIABLE SDL2_CFLAGS)
add_definitions(${SDL2_CFLAGS})
else()
# equivalent to sdl2-config --cflags --libs
# since cmake cannot execute sdl2-config in msys2 shell
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -I/mingw64/include/SDL2 -Dmain=SDL_main -L/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -mwindows)
# MinGW system libraries that should be linked to wesnoth
set(MINGW_SYSTEM_LIBS wsock32 ws2_32 shlwapi winmm)
endif()
if(NOT WIN32)
# Use the safer `mkstemp' instead of `tmpnam' on POSIX systems.
add_definitions(-DLUA_USE_POSIX)
# needed to get some SDL2 defines in... (as of rev31694 -D_GNU_SOURCE=1 is required!)
if(NOT MINGW)
set(SDL2_CONFIG "sdl2-config" CACHE STRING "Path to sdl2-config script")
exec_program(${SDL2_CONFIG} ARGS "--cflags" OUTPUT_VARIABLE SDL2_CFLAGS)
add_definitions(${SDL2_CFLAGS})
else()
# equivalent to sdl2-config --cflags --libs
# since cmake cannot execute sdl2-config in msys2 shell
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -I/mingw64/include/SDL2 -Dmain=SDL_main -L/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -mwindows)
endif()
# Use the safer `mkstemp' instead of `tmpnam' on POSIX systems.
add_definitions(-DLUA_USE_POSIX)
endif(NOT WIN32)
#check for some compiler/arch specific things and export defines accordingly...
@ -108,6 +104,7 @@ include(SearchForStuff)
# if nothing was selected
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release Profile RelWithDebInfo MinSizeRel." FORCE)
message("No build type specified, defaulting to Release")
endif(NOT CMAKE_BUILD_TYPE)
if(NOT DEFINED ENABLE_DISPLAY_REVISION)
@ -115,10 +112,7 @@ if(NOT DEFINED ENABLE_DISPLAY_REVISION)
# fail and should be disabled by default. If inside a repository enable
# the display of revision numbers by default.
execute_process(
COMMAND
${CMAKE_SOURCE_DIR}/utils/autorevision.sh
-t h
> ${CMAKE_CURRENT_BINARY_DIR}/revision.dummy
COMMAND ${CMAKE_SOURCE_DIR}/utils/autorevision.sh -t h > ${CMAKE_CURRENT_BINARY_DIR}/revision.dummy
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE
@ -144,14 +138,6 @@ option(
${DEFAULT_ENABLE_DISPLAY_REVISION}
)
# The use of shared libraries makes compilation debug versions faster but
# results in extra shared libraries. For installation this is not practical
# since the libraries need to be given SONAMES and kept in sync. Therefore
# installation is not supported for this option and will probably fail.
set(ENABLE_SHARED_LIBRARIES OFF CACHE BOOL "Enables shared libraries, this option is meant for development only, installation is *NOT* supported")
mark_as_advanced(on ENABLE_SHARED_LIBRARIES)
if(UNIX AND NOT APPLE AND NOT CYGWIN)
option(ENABLE_DESKTOP_ENTRY "enable installation of desktop entry files" ON)
endif(UNIX AND NOT APPLE AND NOT CYGWIN)
@ -182,297 +168,290 @@ set(BINARY_PREFIX "" CACHE STRING "Prefix in front of all binaries")
### Set the environment compiler flags.
if(CONFIGURED)
# The CONFIGURED flag was replaced when trunk `was' 1.11, before the release of 1.11.0
message("Builed files depending on 'CONFIGURED' found, please regenerate your build files.")
set(CXX_FLAGS_USER
"${CMAKE_CXX_FLAGS}"
CACHE
STRING
"The CXXFLAGS environment variable used for the initial generation."
FORCE
)
unset(CONFIGURED CACHE)
endif(CONFIGURED)
if(NOT WIN32)
if(NOT DEFINED CXX_FLAGS_USER)
if(NOT DEFINED CXX_FLAGS_USER)
MESSAGE(STATUS "Environment compiler flags set to »${CXX_FLAGS_USER}«")
set(CXX_FLAGS_USER
"$ENV{CXXFLAGS}"
CACHE
STRING
"The CXXFLAGS environment variable used for the initial generation."
FORCE
)
message(STATUS "Environment compiler flags set to »${CXX_FLAGS_USER}«")
set(CXX_FLAGS_USER
"$ENV{CXXFLAGS}"
CACHE
STRING
"The CXXFLAGS environment variable used for the initial generation."
FORCE
)
endif(NOT DEFINED CXX_FLAGS_USER)
endif(NOT DEFINED CXX_FLAGS_USER)
set(COMPILER_FLAGS "-Wall -Wextra -Werror=non-virtual-dtor -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wold-style-cast -Wtrampolines")
set(COMPILER_FLAGS "-Wall -Wextra -Werror=non-virtual-dtor -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wold-style-cast -Wtrampolines")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(COMPILER_FLAGS "${COMPILER_FLAGS} -Qunused-arguments -Wno-unknown-warning-option -Wmismatched-tags -Wno-conditional-uninitialized -Wno-unused-lambda-capture")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(COMPILER_FLAGS "${COMPILER_FLAGS} -Qunused-arguments -Wno-unknown-warning-option -Wmismatched-tags -Wno-conditional-uninitialized -Wno-unused-lambda-capture")
endif()
### Set strict compiler flags.
if(ENABLE_STRICT_COMPILATION)
set(COMPILER_FLAGS "${COMPILER_FLAGS} -Werror")
endif(ENABLE_STRICT_COMPILATION)
if(ENABLE_STRICT_COMPILATION)
set(COMPILER_FLAGS "${COMPILER_FLAGS} -Werror")
endif(ENABLE_STRICT_COMPILATION)
### Set pedantic compiler flags.
if(ENABLE_PEDANTIC_COMPILATION)
if(ENABLE_PEDANTIC_COMPILATION)
set(CXX_FLAGS_PEDANTIC_COMPILATION "-Wlogical-op -Wmissing-declarations -Wredundant-decls -Wctor-dtor-privacy -Wdouble-promotion -Wuseless-cast -Wnoexcept")
set(CXX_FLAGS_PEDANTIC_COMPILATION "-Wlogical-op -Wmissing-declarations -Wredundant-decls -Wctor-dtor-privacy -Wdouble-promotion -Wuseless-cast -Wnoexcept")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CXX_FLAGS_PEDANTIC_COMPILATION "${CXX_FLAGS_PEDANTIC_COMPILATION} -Wdocumentation -Wno-documentation-deprecated-sync")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CXX_FLAGS_PEDANTIC_COMPILATION "${CXX_FLAGS_PEDANTIC_COMPILATION} -Wdocumentation -Wno-documentation-deprecated-sync")
endif()
set(COMPILER_FLAGS "${COMPILER_FLAGS} ${CXX_FLAGS_PEDANTIC_COMPILATION}")
set(COMPILER_FLAGS "${COMPILER_FLAGS} ${CXX_FLAGS_PEDANTIC_COMPILATION}")
endif(ENABLE_PEDANTIC_COMPILATION)
endif(ENABLE_PEDANTIC_COMPILATION)
# check for sanitizer options
if(SANITIZE)
set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=${SANITIZE}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZE}")
# manually disable some optimizations to get better stacktraces if sanitizers are used
set(COMPILER_FLAGS "${COMPILER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
endif(SANITIZE)
if(SANITIZE)
set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=${SANITIZE}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZE}")
# manually disable some optimizations to get better stacktraces if sanitizers are used
set(COMPILER_FLAGS "${COMPILER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
endif(SANITIZE)
### Set the final compiler flags.
set(COMPILER_FLAGS "${COMPILER_FLAGS} ${CXX_FLAGS_USER}")
set(COMPILER_FLAGS "${COMPILER_FLAGS} ${CXX_FLAGS_USER}")
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${COMPILER_FLAGS}")
message(STATUS "CMake compiler flags set to »${COMPILER_FLAGS}«")
set(CMAKE_CXX_FLAGS
"${COMPILER_FLAGS}"
CACHE
STRING
"Global flags used by the CXX compiler during all builds."
FORCE
)
endif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${COMPILER_FLAGS}")
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${COMPILER_FLAGS}")
MESSAGE(STATUS "CMake compiler flags set to »${COMPILER_FLAGS}«")
set(CMAKE_CXX_FLAGS
"${COMPILER_FLAGS}"
CACHE
STRING
"Global flags used by the CXX compiler during all builds."
FORCE
)
endif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${COMPILER_FLAGS}")
# #
# Determine optimization level
# #
if(NOT OPT)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_RELEASE "-O3")
if(NOT OPT)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_C_FLAGS_DEBUG "-O0")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_C_FLAGS_DEBUG "-O0")
if(PROFILER STREQUAL "perf")
set(CMAKE_CXX_FLAGS_PROFILE "-Og")
set(CMAKE_C_FLAGS_PROFILE "-Og")
else(PROFILER STREQUAL "perf")
set(CMAKE_CXX_FLAGS_PROFILE "-O0")
set(CMAKE_C_FLAGS_PROFILE "-O0")
endif(PROFILER STREQUAL "perf")
else(NOT OPT)
set(CMAKE_CXX_FLAGS_RELEASE "${OPT}")
set(CMAKE_C_FLAGS_RELEASE "${OPT}")
if(PROFILER STREQUAL "perf")
set(CMAKE_CXX_FLAGS_PROFILE "-Og")
set(CMAKE_C_FLAGS_PROFILE "-Og")
else(PROFILER STREQUAL "perf")
set(CMAKE_CXX_FLAGS_PROFILE "-O0")
set(CMAKE_C_FLAGS_PROFILE "-O0")
endif(PROFILER STREQUAL "perf")
else(NOT OPT)
set(CMAKE_CXX_FLAGS_RELEASE "${OPT}")
set(CMAKE_C_FLAGS_RELEASE "${OPT}")
set(CMAKE_CXX_FLAGS_DEBUG "${OPT}")
set(CMAKE_C_FLAGS_DEBUG "${OPT}")
set(CMAKE_CXX_FLAGS_DEBUG "${OPT}")
set(CMAKE_C_FLAGS_DEBUG "${OPT}")
set(CMAKE_CXX_FLAGS_PROFILE "${OPT}")
set(CMAKE_C_FLAGS_PROFILE "${OPT}")
endif(NOT OPT)
set(CMAKE_CXX_FLAGS_PROFILE "${OPT}")
set(CMAKE_C_FLAGS_PROFILE "${OPT}")
endif(NOT OPT)
# check for hardening options
if(HARDEN AND NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -fstack-protector-strong")
if(HARDEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -fstack-protector-strong")
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -Wl,-pie")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie -Wl,-z,relro,-z,now")
endif()
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -Wl,-pie")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie -Wl,-z,relro,-z,now")
endif()
if(NOT CMAKE_CXX_FLAGS_DEBUG STREQUAL "-O0")
add_definitions(-D_FORTIFY_SOURCE=2)
endif()
endif(HARDEN AND NOT WIN32)
if(NOT CMAKE_CXX_FLAGS_DEBUG STREQUAL "-O0")
add_definitions(-D_FORTIFY_SOURCE=2)
endif()
endif(HARDEN)
if(UNIX AND NOT CMAKE_COMPILER_IS_GNUCXX)
# Assume the compiler is the clang compiler.
set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ -lm ${CMAKE_EXE_LINKER_FLAGS}")
endif(UNIX AND NOT CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ -lm ${CMAKE_EXE_LINKER_FLAGS}")
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT WIN32)
add_definitions(-DWESNOTH_PATH="${CMAKE_INSTALL_FULL_DATADIR}/${DATADIRNAME}")
endif(NOT WIN32)
if(X11_FOUND)
add_definitions(-D_X11)
endif(X11_FOUND)
if(X11_FOUND)
add_definitions(-D_X11)
endif(X11_FOUND)
add_definitions(-DLOCALEDIR="${LOCALEDIR}")
# -DNDEBUG is automatically added to all release build types, so manually remove this define from the related variables
RemoveFlag(CMAKE_CXX_FLAGS_RELWITHDEBINFO CACHE "-DNDEBUG" "Default C++ flags for RelWithDebInfo")
RemoveFlag(CMAKE_C_FLAGS_RELWITHDEBINFO CACHE "-DNDEBUG" "Default C flags for RelWithDebInfo")
RemoveFlag(CMAKE_CXX_FLAGS_MINSIZEREL CACHE "-DNDEBUG" "Default C++ flags for MinSizeRel")
RemoveFlag(CMAKE_C_FLAGS_MINSIZEREL CACHE "-DNDEBUG" "Default C flags for MinSizeRel")
add_definitions(-DLOCALEDIR="${LOCALEDIR}")
# -rdynamic is automatically added, but we don't need it, and it increases the executable size
RemoveFlag(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS SCRIPT "-rdynamic" "")
RemoveFlag(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS SCRIPT "-rdynamic" "")
RemoveFlag(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS SCRIPT "-rdynamic" "")
RemoveFlag(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS SCRIPT "-rdynamic" "")
# -DNDEBUG is automatically added to all release build types, so manually remove this define from the related variables
RemoveFlag(CMAKE_CXX_FLAGS_RELWITHDEBINFO CACHE "-DNDEBUG" "Default C++ flags for RelWithDebInfo")
RemoveFlag(CMAKE_C_FLAGS_RELWITHDEBINFO CACHE "-DNDEBUG" "Default C flags for RelWithDebInfo")
RemoveFlag(CMAKE_CXX_FLAGS_MINSIZEREL CACHE "-DNDEBUG" "Default C++ flags for MinSizeRel")
RemoveFlag(CMAKE_C_FLAGS_MINSIZEREL CACHE "-DNDEBUG" "Default C flags for MinSizeRel")
# #
# Start determining options for Release build
# #
# reset the base Release build option
MESSAGE("Replacing default flags used for Release build with ${OPT} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" CACHE STRING "Release build flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" CACHE STRING "Release build flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING "" FORCE)
MESSAGE("Replacing default flags used for Release build with ${OPT} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" CACHE STRING "Release build flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" CACHE STRING "Release build flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING "" FORCE)
# set the arch to use for Release build if provided
if(ARCH)
MESSAGE("adding -march=${ARCH} to Release build")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=${ARCH}" CACHE STRING "Release build flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=${ARCH}" CACHE STRING "Release build flags" FORCE)
endif(ARCH)
# add pentiumpro arch for windows builds with -O3 if no other arch provided, otherwise resulting executable may not work
if(WIN32 AND NOT ARCH)
MESSAGE("WIN32 and no arch provided, defaulting to pentiumpro")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=pentiumpro" CACHE STRING "Release build flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=pentiumpro" CACHE STRING "Release build flags" FORCE)
endif(WIN32 AND NOT ARCH)
if(ARCH)
MESSAGE("adding -march=${ARCH} to Release build")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=${ARCH}" CACHE STRING "Release build flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=${ARCH}" CACHE STRING "Release build flags" FORCE)
endif(ARCH)
# PGO and LTO for GCC
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(PGO_DATA STREQUAL "generate")
MESSAGE("Generating PGO data")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags generating PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags generating PGO data" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(PGO_DATA STREQUAL "generate")
MESSAGE("Generating PGO data")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags generating PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags generating PGO data" FORCE)
endif()
if(PGO_DATA STREQUAL "use")
MESSAGE("Using PGO data from previous runs")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-correction -fprofile-use=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags for using PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-correction -fprofile-use=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags for using PGO data" FORCE)
endif()
if(PGO_DATA STREQUAL "use")
MESSAGE("Using PGO data from previous runs")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-correction -fprofile-use=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags for using PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-correction -fprofile-use=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags for using PGO data" FORCE)
endif()
if(ENABLE_LTO)
if(NOT LTO_JOBS)
MESSAGE("LTO_JOBS not set, defaulting to 1")
set(LTO_JOBS "1" CACHE STRING "Number of threads to use for LTO with gcc" FORCE)
endif(NOT LTO_JOBS)
if(ENABLE_LTO)
if(NOT LTO_JOBS)
MESSAGE("LTO_JOBS not set, defaulting to 1")
set(LTO_JOBS "1" CACHE STRING "Number of threads to use for LTO with gcc" FORCE)
endif(NOT LTO_JOBS)
MESSAGE("added -flto=${LTO_JOBS} to Release build")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=${LTO_JOBS}" CACHE STRING "Release build flags with LTO" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=${LTO_JOBS}" CACHE STRING "Release build flags with LTO" FORCE)
MESSAGE("added -flto=${LTO_JOBS} to Release build")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=${LTO_JOBS}" CACHE STRING "Release build flags with LTO" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=${LTO_JOBS}" CACHE STRING "Release build flags with LTO" FORCE)
MESSAGE("Using GCC gold linker")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=gold -Wno-stringop-overflow" CACHE STRING "" FORCE)
endif(ENABLE_LTO)
endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
MESSAGE("Using GCC gold linker")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=gold -Wno-stringop-overflow" CACHE STRING "" FORCE)
endif(ENABLE_LTO)
endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# PGO and LTO for Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(PGO_DATA STREQUAL "generate")
MESSAGE("Generating PGO data")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth-%p.profraw" CACHE STRING "Release build flags generating PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth-%p.profraw" CACHE STRING "Release build flags generating PGO data" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(PGO_DATA STREQUAL "generate")
MESSAGE("Generating PGO data")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth-%p.profraw" CACHE STRING "Release build flags generating PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth-%p.profraw" CACHE STRING "Release build flags generating PGO data" FORCE)
endif()
if(PGO_DATA STREQUAL "use")
MESSAGE("Using PGO data from previous runs")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth.profdata" CACHE STRING "Release build flags for using PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth.profdata" CACHE STRING "Release build flags for using PGO data" FORCE)
endif()
if(PGO_DATA STREQUAL "use")
MESSAGE("Using PGO data from previous runs")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth.profdata" CACHE STRING "Release build flags for using PGO data" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth.profdata" CACHE STRING "Release build flags for using PGO data" FORCE)
endif()
if(ENABLE_LTO)
MESSAGE("added -flto=thin to Release build")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=thin" CACHE STRING "Release build flags with LTO" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=thin" CACHE STRING "Release build flags with LTO" FORCE)
if(ENABLE_LTO)
MESSAGE("added -flto=thin to Release build")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=thin" CACHE STRING "Release build flags with LTO" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=thin" CACHE STRING "Release build flags with LTO" FORCE)
MESSAGE("Using Clang LLD linker")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=lld" CACHE STRING "Linker flag for building with LTO and clang" FORCE)
endif(ENABLE_LTO)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
MESSAGE("Using Clang LLD linker")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=lld" CACHE STRING "Linker flag for building with LTO and clang" FORCE)
endif(ENABLE_LTO)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# set CMAKE_AR and CMAKE_RANLIB to use LTO-enabled variants if LTO is enabled
if(ENABLE_LTO)
MESSAGE("Using gcc-ar and gcc-ranlib")
find_program(LTO_AR NAMES gcc-ar)
find_program(LTO_RANLIB NAMES gcc-ranlib)
set(CMAKE_AR "${LTO_AR}" CACHE STRING "Supports LTO" FORCE)
set(CMAKE_RANLIB "${LTO_RANLIB}" CACHE STRING "Supports LTO" FORCE)
endif()
MARK_AS_ADVANCED(LTO_AR LTO_RANLIB NON_LTO_AR NON_LTO_RANLIB)
if(ENABLE_LTO)
MESSAGE("Using gcc-ar and gcc-ranlib")
find_program(LTO_AR NAMES gcc-ar)
find_program(LTO_RANLIB NAMES gcc-ranlib)
set(CMAKE_AR "${LTO_AR}" CACHE STRING "Supports LTO" FORCE)
set(CMAKE_RANLIB "${LTO_RANLIB}" CACHE STRING "Supports LTO" FORCE)
endif()
MARK_AS_ADVANCED(LTO_AR LTO_RANLIB NON_LTO_AR NON_LTO_RANLIB)
# add in extra flags
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_RELEASE}")
# clean the pgo data
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_SOURCE_DIR}/pgo_data/")
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_SOURCE_DIR}/pgo_data/")
# #
# End determining options for Release build
# Start setting options for Debug build
# #
# replace the default Debug flag of -g with -O0 -DDEBUG -ggdb3
# this matches the flags of scons' debug build
MESSAGE("Replacing flags used for Debug build ${OPT} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" CACHE STRING "change cmake's Debug flags to match scons' flags" FORCE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" CACHE STRING "change cmake's Debug flags to match scons' flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_DEBUG}" CACHE STRING "" FORCE)
# replace the default Debug flag of -g with -O0 -DDEBUG -ggdb3
# this matches the flags of scons' debug build
MESSAGE("Replacing flags used for Debug build ${OPT} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" CACHE STRING "change cmake's Debug flags to match scons' flags" FORCE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" CACHE STRING "change cmake's Debug flags to match scons' flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_DEBUG}" CACHE STRING "" FORCE)
# adds GLIBCXX_DEBUG definitions
if(GLIBCXX_DEBUG)
MESSAGE("Defining _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC")
add_definitions(-D_GLIBCXX_DEBUG)
add_definitions(-D_GLIBCXX_DEBUG_PEDANTIC)
endif(GLIBCXX_DEBUG)
if(GLIBCXX_DEBUG)
MESSAGE("Defining _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC")
add_definitions(-D_GLIBCXX_DEBUG)
add_definitions(-D_GLIBCXX_DEBUG_PEDANTIC)
endif(GLIBCXX_DEBUG)
# #
# End setting options for Debug build
# Start setting options for Profile build
# #
if(PROFILER STREQUAL "gprof" OR NOT PROFILER)
MESSAGE("Profiler is gprof")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} -pg ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gprof" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -pg ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gprof" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "gprof" OR NOT PROFILER)
MESSAGE("Profiler is gprof")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} -pg ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gprof" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -pg ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gprof" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "gcov")
MESSAGE("Profiler is gcov")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} -fprofile-arcs -ftest-coverage ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gcov" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -fprofile-arcs -ftest-coverage ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gcov" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "gcov")
MESSAGE("Profiler is gcov")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} -fprofile-arcs -ftest-coverage ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gcov" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -fprofile-arcs -ftest-coverage ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gcov" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "gperftools")
MESSAGE("Profiler is gperftools")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gperftools" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gperftools" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "-Wl,--no-as-needed,-lprofiler ${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "perf")
MESSAGE("Profiler is perf")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} -ggdb ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with perf" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -ggdb ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with perf" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "gperftools")
MESSAGE("Profiler is gperftools")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gperftools" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with gperftools" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "-Wl,--no-as-needed,-lprofiler ${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
if(PROFILER STREQUAL "perf")
MESSAGE("Profiler is perf")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} -ggdb ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with perf" FORCE)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -ggdb ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_PROFILE}" CACHE STRING "Flags for profiling with perf" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_PROFILE}" CACHE STRING "" FORCE)
endif()
# #
# End setting options for Profile build
# #
else()
set(CMAKE_CXX_FLAGS "/W3 /WX /wd4503 /wd4351 /wd4250 /wd4244 /wd4267 /we4239 /wd4275 /EHsc" CACHE STRING "Global flags used by the CXX compiler during all builds." FORCE)
add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_WIN7 -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -DNOMINMAX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG_LUA")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT")
# -DNDEBUG is automatically added to all release build types, so manually remove this define from the related variables
RemoveFlag(CMAKE_CXX_FLAGS_RELEASE CACHE "/DNDEBUG" "Default C++ flags for RELEASE")
RemoveFlag(CMAKE_C_FLAGS_RELEASE CACHE "/DNDEBUG" "Default C flags for RELEASE")
RemoveFlag(CMAKE_CXX_FLAGS_RELWITHDEBINFO CACHE "/DNDEBUG" "Default C++ flags for RelWithDebInfo")
RemoveFlag(CMAKE_C_FLAGS_RELWITHDEBINFO CACHE "/DNDEBUG" "Default C flags for RelWithDebInfo")
RemoveFlag(CMAKE_CXX_FLAGS_MINSIZEREL CACHE "/DNDEBUG" "Default C++ flags for MinSizeRel")
RemoveFlag(CMAKE_C_FLAGS_MINSIZEREL CACHE "/DNDEBUG" "Default C flags for MinSizeRel")
endif(NOT WIN32)
# When the path starts with a / on a Unix system it's an absolute path.
# This means that on Windows the path used is always relative.
@ -508,8 +487,7 @@ endif(ENABLE_DEBUG_WINDOW_LAYOUT)
#
if(ENABLE_GAME OR ENABLE_TESTS)
# find_package(OpenGL REQUIRED)
# find_package(GLEW REQUIRED)
# TODO: SDL2::SDL2 etc component target available with cmake 3.19+
find_package(SDL2 2.0.8 REQUIRED)
find_package(SDL2_image 2.0.2 REQUIRED)
find_package(SDL2_mixer 2.0.0 REQUIRED)
@ -517,8 +495,11 @@ if(ENABLE_GAME OR ENABLE_TESTS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CAIRO REQUIRED cairo>=1.10)
pkg_check_modules(PANGOCAIRO REQUIRED pangocairo>=1.22.0)
# TODO: can use find_package and Fontconfig::Fontconfig with cmake 3.14+
pkg_check_modules(FONTCONFIG REQUIRED fontconfig>=2.4.1)
pkg_check_modules(SYSTEMD systemd)
if(NOT WIN32)
pkg_check_modules(SYSTEMD systemd)
endif(NOT WIN32)
endif(ENABLE_GAME OR ENABLE_TESTS)
if(ENABLE_TESTS)
@ -545,9 +526,6 @@ if(ENABLE_GAME)
endif(ENABLE_HISTORY AND HISTORY_FOUND)
endif(ENABLE_GAME)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS filesystem)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS locale)
if(ENABLE_POT_UPDATE_TARGET)
find_package(TranslationTools REQUIRED)
endif(ENABLE_POT_UPDATE_TARGET)

View file

@ -68,7 +68,7 @@ rebuild Wesnoth frequently (i.e. for development and testing).
See [here](https://github.com/wesnoth/wesnoth/blob/master/projectfiles/Xcode/README.md) for instructions on using Xcode.
### Windows
See [here](https://github.com/wesnoth/wesnoth/blob/master/projectfiles/VC16/README.md) for instructions on using Visual Studio 2019.
Wesnoth uses CMake for project configuration and vcpkg for installing dependencies. See [here](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio) for information on using Visual Studio with cmake. The first time it's run, vcpkg will build all the required dependencies which may take over an hour, however it will only need to be done once.
## SCons Build

View file

@ -6,23 +6,33 @@
### Multiplayer
### Lua API
* Added `pango_color` to the `wesnoth.colors` table, for easy use in formatted text.
* Add new function `filesystem.resolve_asset` to convert `[binary_path]` relative paths to data-relative paths.
* Add new function `filesystem.have_asset` which can determine if an image or sound exists.
* `wesnoth.have_file`, `wesnoth.read_file`, `wesnoth.image_size` moved to new `filesystem` library
* Add a more advanced way of manipulating version strings via `wesnoth.version` constructor function.
* Add a `wesnoth.scenario` data module that consolidates everything there is to know about the current scenario. Much of this information was previously available through `wesnoth.game_config`, but there are some new details too.
### Packaging
* Increased minimum required version of SDL to 2.0.8 (PR #5736).
### Terrain
### Translations
* Updated translations: British English, Dutch, Italian.
* Updated translations: British English, Czech, Dutch, Italian, Russian.
### Units
* Horses added
* Seahorse added
* Zombie horse variation added
* Update piglet/boar graphics
### User interface
* The multiplayer "turns over" dialog now uses each team's colors when showing teams' names.
### WML Engine
* Modify implementation of overwrite_specials attribute for replace yes/no parameter by none/one_side/both_sides and select abilities used like weapons and specials who must be overwrited(owned by fighter where special applied or both)
* Add a 'ability_id_active' attribute to [filter]
* Add a `ability_id_active` attribute to `[filter]`
* `[terrain_mask]` now accepts `mask_file` as an alternative to an inline mask. The file is loaded from the same place as `map_file` in the `[scenario]` tag (ie, a maps/ subdirectory of your binary path). Anyone who prefers to keep masks separate from regular maps is free to make a subdirectory for their masks (or just keep all their masks inline).
### Miscellaneous and Bug Fixes
* More optimizations in the UI drawing code, these shouldn't have visible effects (PR #5681).
* More optimization in the UI drawing code, fixes the crash displaying the full credits (issue #5043).
* Made GUI.pyw compatible with Python 3.9 (issue #5719).
* Removed workarounds for bugs affecting older SDL 2.0 versions, including an extra copy of the game screen made during gamemap scrolling (PR #5736).
* FPS values calculated when the :fps or :benchmark are now written to a file which can then be used to track FPS values over time.
* Removed old image optimisation scripts, as there's a rewrite in Python.
## Version 1.15.12
### Add-ons client

View file

@ -1,69 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindGLEW
# --------
#
# Find the OpenGL Extension Wrangler Library (GLEW)
#
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the :prop_tgt:`IMPORTED` target ``GLEW::GLEW``,
# if GLEW has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ::
#
# GLEW_INCLUDE_DIRS - include directories for GLEW
# GLEW_LIBRARIES - libraries to link against GLEW
# GLEW_FOUND - true if GLEW has been found and can be used
find_path(GLEW_INCLUDE_DIR GL/glew.h)
if(NOT GLEW_LIBRARY)
find_library(GLEW_LIBRARY_RELEASE NAMES GLEW glew32 glew glew32s PATH_SUFFIXES lib64 libx32)
find_library(GLEW_LIBRARY_DEBUG NAMES GLEWd glew32d glewd PATH_SUFFIXES lib64)
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(GLEW)
endif ()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(GLEW
REQUIRED_VARS GLEW_INCLUDE_DIR GLEW_LIBRARY)
if(GLEW_FOUND)
set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
if(NOT GLEW_LIBRARIES)
set(GLEW_LIBRARIES ${GLEW_LIBRARY})
endif()
if (NOT TARGET GLEW::GLEW)
add_library(GLEW::GLEW UNKNOWN IMPORTED)
set_target_properties(GLEW::GLEW PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
if(GLEW_LIBRARY_RELEASE)
set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(GLEW::GLEW PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_LIBRARY_RELEASE}")
endif()
if(GLEW_LIBRARY_DEBUG)
set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(GLEW::GLEW PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_LIBRARY_DEBUG}")
endif()
if(NOT GLEW_LIBRARY_RELEASE AND NOT GLEW_LIBRARY_DEBUG)
set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_LOCATION "${GLEW_LIBRARY}")
endif()
endif()
endif()
mark_as_advanced(GLEW_INCLUDE_DIR)

View file

@ -1,517 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindOpenGL
# ----------
#
# FindModule for OpenGL and GLU.
#
# Optional COMPONENTS
# ^^^^^^^^^^^^^^^^^^^
#
# This module respects several optional COMPONENTS: ``EGL``, ``GLX``, and
# ``OpenGL``. There are corresponding import targets for each of these flags.
#
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the :prop_tgt:`IMPORTED` targets:
#
# ``OpenGL::GL``
# Defined to the platform-specific OpenGL libraries if the system has OpenGL.
# ``OpenGL::OpenGL``
# Defined to libOpenGL if the system is GLVND-based.
# ``OpenGL::GL``
# ``OpenGL::GLU``
# Defined if the system has GLU.
# ``OpenGL::GLX``
# Defined if the system has GLX.
# ``OpenGL::EGL``
# Defined if the system has EGL.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module sets the following variables:
#
# ``OPENGL_FOUND``
# True, if the system has OpenGL and all components are found.
# ``OPENGL_XMESA_FOUND``
# True, if the system has XMESA.
# ``OPENGL_GLU_FOUND``
# True, if the system has GLU.
# ``OpenGL_OpenGL_FOUND``
# True, if the system has an OpenGL library.
# ``OpenGL_GLX_FOUND``
# True, if the system has GLX.
# ``OpenGL_EGL_FOUND``
# True, if the system has EGL.
# ``OPENGL_INCLUDE_DIR``
# Path to the OpenGL include directory.
# ``OPENGL_EGL_INCLUDE_DIRS``
# Path to the EGL include directory.
# ``OPENGL_LIBRARIES``
# Paths to the OpenGL library, windowing system libraries, and GLU libraries.
# On Linux, this assumes GLX and is never correct for EGL-based targets.
# Clients are encouraged to use the ``OpenGL::*`` import targets instead.
#
# Cache variables
# ^^^^^^^^^^^^^^^
#
# The following cache variables may also be set:
#
# ``OPENGL_egl_LIBRARY``
# Path to the EGL library.
# ``OPENGL_glu_LIBRARY``
# Path to the GLU library.
# ``OPENGL_glx_LIBRARY``
# Path to the GLVND 'GLX' library.
# ``OPENGL_opengl_LIBRARY``
# Path to the GLVND 'OpenGL' library
# ``OPENGL_gl_LIBRARY``
# Path to the OpenGL library. New code should prefer the ``OpenGL::*`` import
# targets.
#
# Linux-specific
# ^^^^^^^^^^^^^^
#
# Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates
# context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and
# contexts are defined in "libGLX" or "libEGL". GLVND is currently the only way
# to get OpenGL 3+ functionality via EGL in a manner portable across vendors.
# Projects may use GLVND explicitly with target ``OpenGL::OpenGL`` and either
# ``OpenGL::GLX`` or ``OpenGL::EGL``.
#
# Projects may use the ``OpenGL::GL`` target (or ``OPENGL_LIBRARIES`` variable)
# to use legacy GL interfaces. These will use the legacy GL library located
# by ``OPENGL_gl_LIBRARY``, if available. If ``OPENGL_gl_LIBRARY`` is empty or
# not found and GLVND is available, the ``OpenGL::GL`` target will use GLVND
# ``OpenGL::OpenGL`` and ``OpenGL::GLX`` (and the ``OPENGL_LIBRARIES``
# variable will use the corresponding libraries). Thus, for non-EGL-based
# Linux targets, the ``OpenGL::GL`` target is most portable.
#
# A ``OpenGL_GL_PREFERENCE`` variable may be set to specify the preferred way
# to provide legacy GL interfaces in case multiple choices are available.
# The value may be one of:
#
# ``GLVND``
# If the GLVND OpenGL and GLX libraries are available, prefer them.
# This forces ``OPENGL_gl_LIBRARY`` to be empty.
# This is the default if components were requested (since components
# correspond to GLVND libraries).
#
# ``LEGACY``
# Prefer to use the legacy libGL library, if available.
# This is the default if no components were requested.
#
# For EGL targets the client must rely on GLVND support on the user's system.
# Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets. Using GLES*
# libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this
# module does not currently support that; contributions welcome.
#
# ``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of
# GLVND. For non-GLVND Linux and other systems these are left undefined.
#
# macOS-Specific
# ^^^^^^^^^^^^^^
#
# On OSX FindOpenGL defaults to using the framework version of OpenGL. People
# will have to change the cache values of OPENGL_glu_LIBRARY and
# OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX.
set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
# Provide OPENGL_USE_<C> variables for each component.
foreach(component ${OpenGL_FIND_COMPONENTS})
string(TOUPPER ${component} _COMPONENT)
set(OPENGL_USE_${_COMPONENT} 1)
endforeach()
if (CYGWIN)
find_path(OPENGL_INCLUDE_DIR GL/gl.h )
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
find_library(OPENGL_gl_LIBRARY opengl32 )
find_library(OPENGL_glu_LIBRARY glu32 )
elseif (WIN32)
if(BORLAND)
set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
else()
set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
endif()
elseif (APPLE)
# The OpenGL.framework provides both gl and glu
find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X")
find_library(OPENGL_glu_LIBRARY OpenGL DOC
"GLU library for OS X (usually same as OpenGL library)")
find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X")
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
else()
if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
# Handle HP-UX cases where we only want to find OpenGL in either hpux64
# or hpux32 depending on if we're doing a 64 bit build.
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(_OPENGL_LIB_PATH
/opt/graphics/OpenGL/lib/hpux32/)
else()
set(_OPENGL_LIB_PATH
/opt/graphics/OpenGL/lib/hpux64/
/opt/graphics/OpenGL/lib/pa20_64)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku)
set(_OPENGL_LIB_PATH
/boot/develop/lib/x86)
set(_OPENGL_INCLUDE_PATH
/boot/develop/headers/os/opengl)
endif()
# The first line below is to make sure that the proper headers
# are used on a Linux machine with the NVidia drivers installed.
# They replace Mesa with NVidia's own library but normally do not
# install headers and that causes the linking to
# fail since the compiler finds the Mesa headers but NVidia's library.
# Make sure the NVIDIA directory comes BEFORE the others.
# - Atanas Georgiev <atanas@cs.columbia.edu>
find_path(OPENGL_INCLUDE_DIR GL/gl.h
/usr/share/doc/NVIDIA_GLX-1.0/include
/usr/openwin/share/include
/opt/graphics/OpenGL/include /usr/X11R6/include
${_OPENGL_INCLUDE_PATH}
)
find_path(OPENGL_GLX_INCLUDE_DIR GL/glx.h ${_OPENGL_INCLUDE_PATH})
find_path(OPENGL_EGL_INCLUDE_DIR EGL/egl.h ${_OPENGL_INCLUDE_PATH})
find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
/usr/share/doc/NVIDIA_GLX-1.0/include
/usr/openwin/share/include
/opt/graphics/OpenGL/include /usr/X11R6/include
)
# Search for the GLVND libraries. We do this regardless of COMPONENTS; we'll
# take into account the COMPONENTS logic later.
find_library(OPENGL_opengl_LIBRARY
NAMES OpenGL
PATHS /usr/X11R6/lib
${_OPENGL_LIB_PATH}
)
find_library(OPENGL_glx_LIBRARY
NAMES GLX
PATHS /usr/X11R6/lib
${_OPENGL_LIB_PATH}
)
find_library(OPENGL_egl_LIBRARY
NAMES EGL
PATHS ${_OPENGL_LIB_PATH}
)
find_library(OPENGL_glu_LIBRARY
NAMES GLU MesaGLU
PATHS ${OPENGL_gl_LIBRARY}
/opt/graphics/OpenGL/lib
/usr/openwin/lib
/usr/shlib /usr/X11R6/lib
)
if(NOT DEFINED OpenGL_GL_PREFERENCE)
set(OpenGL_GL_PREFERENCE "")
endif()
if(NOT OpenGL_GL_PREFERENCE STREQUAL "")
# A preference has been explicitly specified.
if(NOT OpenGL_GL_PREFERENCE MATCHES "^(GLVND|LEGACY)$")
message(FATAL_ERROR
"OpenGL_GL_PREFERENCE value '${OpenGL_GL_PREFERENCE}' not recognized. "
"Allowed values are 'GLVND' and 'LEGACY'."
)
endif()
elseif(OpenGL_FIND_COMPONENTS)
# No preference was explicitly specified, but the caller did request
# at least one GLVND component. Prefer GLVND for legacy GL.
set(OpenGL_GL_PREFERENCE "GLVND")
else()
# No preference was explicitly specified and no GLVND components were
# requested. Prefer libGL for legacy GL.
set(OpenGL_GL_PREFERENCE "LEGACY")
endif()
if("x${OpenGL_GL_PREFERENCE}x" STREQUAL "xGLVNDx" AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY)
# We can provide legacy GL using GLVND libraries.
# Do not use any legacy GL library.
set(OPENGL_gl_LIBRARY "")
else()
# We cannot provide legacy GL using GLVND libraries.
# Search for the legacy GL library.
find_library(OPENGL_gl_LIBRARY
NAMES GL MesaGL
PATHS /opt/graphics/OpenGL/lib
/usr/openwin/lib
/usr/shlib /usr/X11R6/lib
${_OPENGL_LIB_PATH}
)
endif()
# FPHSA cannot handle "this OR that is required", so we conditionally set what
# it must look for. First clear any previous config we might have done:
set(_OpenGL_REQUIRED_VARS)
# now we append the libraries as appropriate. The complicated logic
# basically comes down to "use libOpenGL when we can, and add in specific
# context mechanisms when requested, or we need them to preserve the previous
# default where glx is always available."
if((NOT OPENGL_USE_EGL AND
NOT OPENGL_opengl_LIBRARY AND
OPENGL_glx_LIBRARY AND
NOT OPENGL_gl_LIBRARY) OR
(NOT OPENGL_USE_EGL AND
NOT OPENGL_glx_LIBRARY AND
NOT OPENGL_gl_LIBRARY) OR
(NOT OPENGL_USE_EGL AND
OPENGL_opengl_LIBRARY AND
OPENGL_glx_LIBRARY) OR
( OPENGL_USE_EGL))
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY)
endif()
# GLVND GLX library. Preferred when available.
if((NOT OPENGL_USE_OPENGL AND
NOT OPENGL_USE_GLX AND
NOT OPENGL_USE_EGL AND
NOT OPENGL_glx_LIBRARY AND
NOT OPENGL_gl_LIBRARY) OR
( OPENGL_USE_GLX AND
NOT OPENGL_USE_EGL AND
NOT OPENGL_glx_LIBRARY AND
NOT OPENGL_gl_LIBRARY) OR
(NOT OPENGL_USE_EGL AND
OPENGL_opengl_LIBRARY AND
OPENGL_glx_LIBRARY) OR
(OPENGL_USE_GLX AND OPENGL_USE_EGL))
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_glx_LIBRARY)
endif()
# GLVND EGL library.
if(OPENGL_USE_EGL)
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_egl_LIBRARY)
endif()
# Old-style "libGL" library: used as a fallback when GLVND isn't available.
if((NOT OPENGL_USE_EGL AND
NOT OPENGL_opengl_LIBRARY AND
OPENGL_glx_LIBRARY AND
OPENGL_gl_LIBRARY) OR
(NOT OPENGL_USE_EGL AND
NOT OPENGL_glx_LIBRARY AND
OPENGL_gl_LIBRARY))
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
endif()
# We always need the 'gl.h' include dir.
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
unset(_OPENGL_INCLUDE_PATH)
unset(_OPENGL_LIB_PATH)
find_library(OPENGL_glu_LIBRARY
NAMES GLU MesaGLU
PATHS ${OPENGL_gl_LIBRARY}
/opt/graphics/OpenGL/lib
/usr/openwin/lib
/usr/shlib /usr/X11R6/lib
)
endif ()
if(OPENGL_xmesa_INCLUDE_DIR)
set( OPENGL_XMESA_FOUND "YES" )
else()
set( OPENGL_XMESA_FOUND "NO" )
endif()
if(OPENGL_glu_LIBRARY)
set( OPENGL_GLU_FOUND "YES" )
else()
set( OPENGL_GLU_FOUND "NO" )
endif()
# OpenGL_OpenGL_FOUND is a bit unique in that it is okay if /either/ libOpenGL
# or libGL is found.
# Using libGL with libEGL is never okay, though; we handle that case later.
if(NOT OPENGL_opengl_LIBRARY AND NOT OPENGL_gl_LIBRARY)
set(OpenGL_OpenGL_FOUND FALSE)
else()
set(OpenGL_OpenGL_FOUND TRUE)
endif()
if(OPENGL_glx_LIBRARY AND OPENGL_GLX_INCLUDE_DIR)
set(OpenGL_GLX_FOUND TRUE)
else()
set(OpenGL_GLX_FOUND FALSE)
endif()
if(OPENGL_egl_LIBRARY AND OPENGL_EGL_INCLUDE_DIR)
set(OpenGL_EGL_FOUND TRUE)
else()
set(OpenGL_EGL_FOUND FALSE)
endif()
# User-visible names should be plural.
if(OPENGL_EGL_INCLUDE_DIR)
set(OPENGL_EGL_INCLUDE_DIRS ${OPENGL_EGL_INCLUDE_DIR})
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS}
HANDLE_COMPONENTS)
unset(_OpenGL_REQUIRED_VARS)
# OpenGL:: targets
if(OPENGL_FOUND)
# ::OpenGL is a GLVND library, and thus Linux-only: we don't bother checking
# for a framework version of this library.
if(OPENGL_opengl_LIBRARY AND NOT TARGET OpenGL::OpenGL)
if(IS_ABSOLUTE "${OPENGL_opengl_LIBRARY}")
add_library(OpenGL::OpenGL UNKNOWN IMPORTED)
set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LOCATION
"${OPENGL_opengl_LIBRARY}")
else()
add_library(OpenGL::OpenGL INTERFACE IMPORTED)
set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LIBNAME
"${OPENGL_opengl_LIBRARY}")
endif()
set_target_properties(OpenGL::OpenGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${OPENGL_INCLUDE_DIR}")
endif()
# ::GLX is a GLVND library, and thus Linux-only: we don't bother checking
# for a framework version of this library.
if(OpenGL_GLX_FOUND AND NOT TARGET OpenGL::GLX)
if(IS_ABSOLUTE "${OPENGL_glx_LIBRARY}")
add_library(OpenGL::GLX UNKNOWN IMPORTED)
set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LOCATION
"${OPENGL_glx_LIBRARY}")
else()
add_library(OpenGL::GLX INTERFACE IMPORTED)
set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LIBNAME
"${OPENGL_glx_LIBRARY}")
endif()
set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_LINK_LIBRARIES
OpenGL::OpenGL)
set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${OPENGL_GLX_INCLUDE_DIR}")
endif()
if(OPENGL_gl_LIBRARY AND NOT TARGET OpenGL::GL)
# A legacy GL library is available, so use it for the legacy GL target.
if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}")
add_library(OpenGL::GL UNKNOWN IMPORTED)
if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$")
set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}")
if(EXISTS "${_gl_fw}.tbd")
string(APPEND _gl_fw ".tbd")
endif()
set_target_properties(OpenGL::GL PROPERTIES
IMPORTED_LOCATION "${_gl_fw}")
else()
set_target_properties(OpenGL::GL PROPERTIES
IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}")
endif()
else()
add_library(OpenGL::GL INTERFACE IMPORTED)
set_target_properties(OpenGL::GL PROPERTIES
IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}")
endif()
set_target_properties(OpenGL::GL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}")
elseif(NOT TARGET OpenGL::GL AND TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX)
# A legacy GL library is not available, but we can provide the legacy GL
# target using GLVND OpenGL+GLX.
add_library(OpenGL::GL INTERFACE IMPORTED)
set_target_properties(OpenGL::GL PROPERTIES INTERFACE_LINK_LIBRARIES
OpenGL::OpenGL)
set_property(TARGET OpenGL::GL APPEND PROPERTY INTERFACE_LINK_LIBRARIES
OpenGL::GLX)
set_target_properties(OpenGL::GL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${OPENGL_INCLUDE_DIR}")
endif()
# ::EGL is a GLVND library, and thus Linux-only: we don't bother checking
# for a framework version of this library.
# Note we test for OpenGL::OpenGL as a target. When this module is updated to
# support GLES, we would additionally want to check for the hypothetical GLES
# target and enable EGL if either ::GLES or ::OpenGL is created.
if(TARGET OpenGL::OpenGL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL)
if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}")
add_library(OpenGL::EGL UNKNOWN IMPORTED)
set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION
"${OPENGL_egl_LIBRARY}")
else()
add_library(OpenGL::EGL INTERFACE IMPORTED)
set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LIBNAME
"${OPENGL_egl_LIBRARY}")
endif()
set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES
OpenGL::OpenGL)
# Note that EGL's include directory is different from OpenGL/GLX's!
set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${OPENGL_EGL_INCLUDE_DIR}")
endif()
if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU)
if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}")
add_library(OpenGL::GLU UNKNOWN IMPORTED)
if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$")
set(_glu_fw "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}")
if(EXISTS "${_glu_fw}.tbd")
string(APPEND _glu_fw ".tbd")
endif()
set_target_properties(OpenGL::GLU PROPERTIES
IMPORTED_LOCATION "${_glu_fw}")
else()
set_target_properties(OpenGL::GLU PROPERTIES
IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}")
endif()
else()
add_library(OpenGL::GLU INTERFACE IMPORTED)
set_target_properties(OpenGL::GLU PROPERTIES
IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}")
endif()
set_target_properties(OpenGL::GLU PROPERTIES
INTERFACE_LINK_LIBRARIES OpenGL::GL)
endif()
# OPENGL_LIBRARIES mirrors OpenGL::GL's logic ...
if(OPENGL_gl_LIBRARY)
set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY})
elseif(TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX)
set(OPENGL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY})
else()
set(OPENGL_LIBRARIES "")
endif()
# ... and also includes GLU, if available.
if(TARGET OpenGL::GLU)
list(APPEND OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY})
endif()
endif()
# This deprecated setting is for backward compatibility with CMake1.4
set(OPENGL_LIBRARY ${OPENGL_LIBRARIES})
# This deprecated setting is for backward compatibility with CMake1.4
set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
mark_as_advanced(
OPENGL_INCLUDE_DIR
OPENGL_xmesa_INCLUDE_DIR
OPENGL_egl_LIBRARY
OPENGL_glu_LIBRARY
OPENGL_glx_LIBRARY
OPENGL_gl_LIBRARY
OPENGL_opengl_LIBRARY
OPENGL_EGL_INCLUDE_DIR
OPENGL_GLX_INCLUDE_DIR
)

View file

@ -61,7 +61,7 @@ end
function ai_helper.done_eval_messages(start_time, ca_name)
ca_name = ca_name or 'unknown'
local dt = wesnoth.get_time_stamp() / 1000. - start_time
local dt = wesnoth.ms_since_init() / 1000. - start_time
if ai_helper.print_eval() then
ai_helper.print_ts_delta(start_time, ' - Done evaluating ' .. ca_name .. ':')
end
@ -119,7 +119,7 @@ function ai_helper.print_ts(...)
-- Print arguments preceded by a time stamp in seconds
-- Also return that time stamp
local ts = wesnoth.get_time_stamp() / 1000.
local ts = wesnoth.ms_since_init() / 1000.
local arg = { ... }
arg[#arg+1] = string.format('[ t = %.3f ]', ts)
@ -130,13 +130,13 @@ function ai_helper.print_ts(...)
end
function ai_helper.print_ts_delta(start_time, ...)
-- @start_time: time stamp in seconds as returned by wesnoth.get_time_stamp / 1000.
-- @start_time: time stamp in seconds as returned by wesnoth.ms_since_init / 1000.
-- Same as ai_helper.print_ts(), but also adds time elapsed since
-- the time given in the first argument (in seconds)
-- Returns time stamp as well as time elapsed
local ts = wesnoth.get_time_stamp() / 1000.
local ts = wesnoth.ms_since_init() / 1000.
local delta = ts - start_time
local arg = { ... }
@ -655,7 +655,7 @@ function ai_helper.get_named_loc_xy(param_core, cfg, required_for)
if (param_core ~= '') then param_loc = param_core .. '_loc' end
local loc_id = cfg[param_loc]
if loc_id then
local loc = wesnoth.special_locations[loc_id]
local loc = wesnoth.current.map.special_locations[loc_id]
if loc then
return loc
else
@ -1840,7 +1840,7 @@ function ai_helper.custom_cost_with_avoid(x, y, prev_cost, unit, avoid_map, ally
-- in most cases this will simply add to the cost, rather than change the path itself.
local defense = unit:defense_on(terrain)
-- We need this to be multiples of 10 for the penalty identification to work
defense = H.round(defense / 10) * 10
defense = mathx.round(defense / 10) * 10
if (defense > 90) then defense = 90 end
if (defense < 10) then defense = 10 end
move_cost_int = move_cost_int + (100 - defense)

View file

@ -143,16 +143,16 @@ function battle_calcs.strike_damage(attacker, defender, att_weapon, def_weapon,
-- Rounding of .5 values is done differently depending on whether the
-- multiplier is greater or smaller than 1
if (att_multiplier > 1) then
att_damage = H.round(att_damage * att_multiplier - 0.001)
att_damage = mathx.round(att_damage * att_multiplier - 0.001)
else
att_damage = H.round(att_damage * att_multiplier + 0.001)
att_damage = mathx.round(att_damage * att_multiplier + 0.001)
end
if (def_weapon ~= 0) then
if (def_multiplier > 1) then
def_damage = H.round(def_damage * def_multiplier - 0.001)
def_damage = mathx.round(def_damage * def_multiplier - 0.001)
else
def_damage = H.round(def_damage * def_multiplier + 0.001)
def_damage = mathx.round(def_damage * def_multiplier + 0.001)
end
end
@ -1380,7 +1380,7 @@ function battle_calcs.get_attack_combos_subset(units, enemy, cfg)
local function add_attack(attacks, reachable_hexes, n_reach, attack_combos, combos_str, current_combo, hexes_used, cfg)
local time_up = false
if cfg.max_time and (wesnoth.get_time_stamp() / 1000. - cfg.start_time >= cfg.max_time) then
if cfg.max_time and (wesnoth.ms_since_init() / 1000. - cfg.start_time >= cfg.max_time) then
time_up = true
end
@ -1583,7 +1583,7 @@ function battle_calcs.get_attack_combos_subset(units, enemy, cfg)
-- If cfg.max_time is set, record the start time
-- For convenience, we store this in cfg
if cfg.max_time then
cfg.start_time = wesnoth.get_time_stamp() / 1000.
cfg.start_time = wesnoth.ms_since_init() / 1000.
end

View file

@ -62,7 +62,7 @@ function ca_castle_switch:evaluation(cfg, data, filter_own, recruiting_leader)
-- @recruiting_leader is passed from the recuit_rushers CA for the leader_takes_village()
-- evaluation. If it is set, we do the castle switch evaluation only for that leader
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'castle_switch'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'castle_switch'
if AH.print_eval() then AH.print_ts(' - Evaluating castle_switch CA:') end
if ai.aspects.passive_leader then

View file

@ -10,7 +10,7 @@ local GV_unit, GV_village
local ca_grab_villages = {}
function ca_grab_villages:evaluation(cfg, data, filter_own)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'grab_villages'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'grab_villages'
if AH.print_eval() then AH.print_ts(' - Evaluating grab_villages CA:') end
-- Check if there are units with moves left

View file

@ -11,7 +11,7 @@ local MTAE_unit, MTAE_destination
local ca_move_to_any_enemy = {}
function ca_move_to_any_enemy:evaluation(cfg, data, filter_own)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'move_to_any_enemy'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'move_to_any_enemy'
if AH.print_eval() then AH.print_ts(' - Evaluating move_to_any_enemy CA:') end
local units = AH.get_units_with_moves({

View file

@ -6,7 +6,7 @@ local HS = wesnoth.require "ai/micro_ais/cas/ca_healer_move.lua"
local ca_place_healers = {}
function ca_place_healers:evaluation(cfg, data, filter_own)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'place_healers'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'place_healers'
if AH.print_eval() then AH.print_ts(' - Evaluating place_healers CA:') end
if HS:evaluation({ { 'filter', filter_own } }, data) > 0 then

View file

@ -9,7 +9,7 @@ local retreat_unit, retreat_loc
local ca_retreat_injured = {}
function ca_retreat_injured:evaluation(cfg, data, filter_own)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'retreat_injured'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'retreat_injured'
if AH.print_eval() then AH.print_ts(' - Evaluating retreat_injured CA:') end
if (ai.aspects.retreat_factor <= 0) then

View file

@ -9,7 +9,7 @@ local SP_attack
local ca_spread_poison = {}
function ca_spread_poison:evaluation(cfg, data, filter_own)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'spread_poison'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'spread_poison'
if AH.print_eval() then AH.print_ts(' - Evaluating spread_poison CA:') end
local attacks_aspect = ai.aspects.attacks

View file

@ -11,7 +11,7 @@ local VH_unit, VH_dst = {}, {}
local ca_village_hunt = {}
function ca_village_hunt:evaluation(cfg, data, filter_own)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'village_hunt'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'village_hunt'
if AH.print_eval() then AH.print_ts(' - Evaluating village_hunt CA:') end
local avoid_map = LS.of_pairs(ai.aspects.avoid)

View file

@ -448,7 +448,7 @@ return {
end
function ai_cas:recruit_rushers_eval()
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'recruit_rushers'
local start_time, ca_name = wesnoth.ms_since_init() / 1000., 'recruit_rushers'
if AH.print_eval() then AH.print_ts(' - Evaluating recruit_rushers CA:') end
local score = recruit_lib.do_recruit_eval(recruit_data)
@ -684,7 +684,7 @@ return {
local enemy_sides = wesnoth.sides.find({ { "enemy_of", {side = wesnoth.current.side} } })
local min_dist = math.huge
for _, side in ipairs(enemy_sides) do
local enemy_start_hex = wesnoth.special_locations[side.side]
local enemy_start_hex = wesnoth.current.map.special_locations[side.side]
if enemy_start_hex then
local dist = wesnoth.map.distance_between(reference_hex[1], reference_hex[2], enemy_start_hex[1], enemy_start_hex[2])
if dist < min_dist then
@ -756,7 +756,7 @@ return {
local lawful_bonus = 0
local eta_turn = wesnoth.current.turn + eta
if eta_turn <= wesnoth.game_config.last_turn then
if eta_turn <= wesnoth.scenario.turns then
lawful_bonus = wesnoth.get_time_of_day(wesnoth.current.turn + eta).lawful_bonus / eta^2
end
local damage_bonus = AH.get_unit_time_of_day_bonus(recruit_unit.alignment, lawful_bonus)

View file

@ -21,7 +21,7 @@ function ca_hang_out:evaluation(cfg, data)
-- Otherwise check if any of the mobilize conditions are now met
local mobilize_condition = wml.get_child(cfg, "mobilize_condition")
if (mobilize_condition and wesnoth.eval_conditional(mobilize_condition))
if (mobilize_condition and wml.eval_conditional(mobilize_condition))
or (cfg.mobilize_on_gold_less_than and (wesnoth.sides[wesnoth.current.side].gold < cfg.mobilize_on_gold_less_than))
then
MAISD.insert_mai_self_data(data, cfg.ai_id, { mobilize_units = true })

View file

@ -535,14 +535,14 @@
for i = 1, #units do
-- pick an advancement randomly, and remove others so advance() doesn't show the dialog
if units[i].advances_to[1] ~= nil then
local r = wesnoth.random ( 1, #units[i].advances_to )
local r = mathx.random ( 1, #units[i].advances_to )
local t = { }; t[1] = units[i].advances_to[r]
units[i].advances_to = t
end
-- level the unit and give it a random amount of experience up to half of max
units[i].experience = units[i].max_experience
units[i]:advance( )
units[i].experience = wesnoth.random ( 0, helper.round( units[i].max_experience / 2 ) )
units[i].experience = mathx.random ( 0, helper.round( units[i].max_experience / 2 ) )
end
>>
[/lua]

View file

@ -184,7 +184,7 @@ local convert = {
local loopCounter
for loopCounter = 1, snowNeeded do
local locationsIndex = wesnoth.random(#locations)
local locationsIndex = mathx.random(#locations)
local coordinate = locations[locationsIndex]
local terrainCode = wesnoth.current.map[coordinate]
wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode)

View file

@ -25,7 +25,7 @@ function wml_actions.spread_bandit_villages(cfg)
local village_i
for i = 0, (count - 1) do
village_i = helper.rand("1.."..#villages)
village_i = mathx.random_choice("1.."..#villages)
vars[string.format("bandit_villages[%d].x", i)] = villages[village_i][1]
vars[string.format("bandit_villages[%d].y", i)] = villages[village_i][2]
@ -38,8 +38,8 @@ local function bandits_found(x,y)
local bandit_villages = wml.array_variables["bandit_villages"]
local boss_found = vars.boss_found
local visited = vars.villages_visited
local rand1 = helper.rand("3,4")
local rand2 = helper.rand("2.."..rand1)
local rand1 = mathx.random_choice("3,4")
local rand2 = mathx.random_choice("2.."..rand1)
for i=1,rand2 do
local radius = 1
@ -49,8 +49,8 @@ local function bandits_found(x,y)
radius = radius + 1
until locs[1]
local bandit = helper.rand(bandit_types)
local loc_i = helper.rand("1.."..#locs)
local bandit = mathx.random_choice(bandit_types)
local loc_i = mathx.random_choice("1.."..#locs)
wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]), y = string.format("%d,%d", y, locs[loc_i][2]), type = bandit, side = "4"})
wesnoth.units.to_map({ type = bandit, side = "4", random_traits = "yes", generate_name = "yes", upkeep = "loyal" }, locs[loc_i][1], locs[loc_i][2])
@ -58,7 +58,7 @@ local function bandits_found(x,y)
if not boss_found and visited > 2 then
local boss_chance = (100 / #bandit_villages)
local rand3 = helper.rand("1..100")
local rand3 = mathx.random_choice("1..100")
if rand3 <= boss_chance or #bandit_villages < 3 then
vars.boss_found = true
@ -80,12 +80,12 @@ function wml_actions.bandit_village_capture(cfg)
local visited = vars.villages_visited
vars.villages_visited = visited + 1
wesnoth.fire("message" , { x = x , y = y , message = _"They're here!"})
wml.fire("message" , { x = x , y = y , message = _"They're here!"})
bandits_found(x,y)
return
end
end
wesnoth.fire("message" , { x = x , y = y , message = _"No outlaws in this village."})
wml.fire("message" , { x = x , y = y , message = _"No outlaws in this village."})
end

View file

@ -204,7 +204,7 @@ local convert = {
local loopCounter
for loopCounter = 1, snowNeeded do
local locationsIndex = wesnoth.random(#locations)
local locationsIndex = mathx.random(#locations)
local coordinate = locations[locationsIndex]
local terrainCode = wesnoth.current.map[coordinate]
wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode)

View file

@ -7,7 +7,7 @@ function wesnoth.wml_actions.find_respawn_point(cfg)
local respawn_point
local radius = 1
if not wesnoth.eval_conditional { T.have_unit { id = respawn_near} } then
if not wml.eval_conditional { T.have_unit { id = respawn_near} } then
respawn_near = "Tallin"
end

View file

@ -200,8 +200,6 @@
#define ENABLE_AI_COMMAND_CA_TRANSPORT_S6
[lua]
code = <<
local helper = wesnoth.require "helper"
function wesnoth.custom_synced_commands.ship_unload(cfg)
local unit = wesnoth.units.get(cfg.x, cfg.y)
@ -211,12 +209,12 @@ function wesnoth.custom_synced_commands.ship_unload(cfg)
local locs = wml.child_array(cfg, "dst")
local l2_type = helper.rand('Swordsman,Javelineer,Pikeman')
local l2_type = mathx.random_choice('Swordsman,Javelineer,Pikeman')
wesnoth.units.to_map({ side = wesnoth.current.side, type = l2_type, moves = 2 }, locs[1].x, locs[1].y)
wesnoth.add_known_unit(l2_type)
for i = 2, #locs do
local l1_type = helper.rand('Fencer,Mage,Cavalryman,Bowman,Spearman')
local l1_type = mathx.random_choice('Fencer,Mage,Cavalryman,Bowman,Spearman')
wesnoth.units.to_map({ side = wesnoth.current.side, type = l1_type, moves = 2 }, locs[i].x, locs[i].y)
wesnoth.add_known_unit(l1_type)
end

View file

@ -20,8 +20,8 @@ function wml_actions.spawn_units(cfg)
done = done + 1
local unit_type = helper.rand(types)
local loc_i = helper.rand("1.."..#locs)
local unit_type = mathx.random_choice(types)
local loc_i = mathx.random_choice("1.."..#locs)
wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]) , y = string.format("%d,%d", y, locs[loc_i][2]) , type = unit_type , side = side})
wesnoth.units.to_map({ type = unit_type , side = side, random_traits = "yes", generate_name = "yes" , upkeep = "loyal" }, locs[loc_i][1], locs[loc_i][2])

View file

@ -401,8 +401,8 @@
radius = radius + 1
until locs[1]
local orc = helper.rand(orc_types)
local loc_i = helper.rand("1.."..#locs)
local orc = mathx.random_choice(orc_types)
local loc_i = mathx.random_choice("1.."..#locs)
wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]), y = string.format("%d,%d", y, locs[loc_i][2]), type = orc, side = "4"})
wesnoth.units.to_map({ type = orc, side = "4", random_traits = "yes", generate_name = "yes", upkeep = "loyal" }, locs[loc_i][1], locs[loc_i][2])

View file

@ -1,5 +1,4 @@
local on_event = wesnoth.require("on_event")
local helper = wesnoth.require("helper")
local enemy = {}
@ -38,7 +37,7 @@ function enemy.pick_suitable_enemy_item(unit)
if #possible_artifacts == 0 then
return
end
local i = possible_artifacts[wesnoth.random(#possible_artifacts)]
local i = possible_artifacts[mathx.random(#possible_artifacts)]
local artifact_id = tonumber(enemy_items[i])
table.remove(enemy_items, i)
wml.variables["wc2_enemy_army.artifacts"] = table.concat(enemy_items, ",")
@ -77,7 +76,7 @@ function enemy.do_commander(cfg, group_id, loc)
local scenario = wc2_scenario.scenario_num()
--wesnoth.message("do_commander", wml.variables[("wc2_enemy_army.group[%d].allies_available"):format(group_id)])
local ally_i = wc2_utils.pick_random(("wc2_enemy_army.group[%d].allies_available"):format(group_id)) - 1
local leader_index = wesnoth.random(wml.variables[("wc2_enemy_army.group[%d].leader.length"):format(ally_i)]) - 1
local leader_index = mathx.random(wml.variables[("wc2_enemy_army.group[%d].leader.length"):format(ally_i)]) - 1
local new_recruits = wml.variables[("wc2_enemy_army.group[%d].leader[%d].recruit"):format(ally_i, leader_index)]
wesnoth.wml_actions.allow_recruit {
side = cfg.side,
@ -87,7 +86,7 @@ function enemy.do_commander(cfg, group_id, loc)
wesnoth.wml_actions.unit {
x = loc[1],
y = loc[2],
type = helper.rand(commander_options),
type = mathx.random_choice(commander_options),
side = cfg.side,
generate_name = true,
role = "commander",
@ -144,7 +143,7 @@ on_event("recruit", function(ec)
wml.tag.filter {}
}
}
helper.shuffle(candidates)
mathx.shuffle(candidates)
while #candidates > 0 and #to_recall > 0 do
enemy.fake_recall(side_num, to_recall[1], candidates[1])
table.remove(to_recall, 1)
@ -169,7 +168,7 @@ function enemy.do_recall(cfg, group_id, loc)
get_advanced_units(level, stringx.split(group.recruit or ""), types)
end
for i = 1, amount do
table.insert(to_recall, types[wesnoth.random(#types)])
table.insert(to_recall, types[mathx.random(#types)])
end
end
recall_level(2)
@ -255,7 +254,7 @@ function wesnoth.wml_actions.wc2_enemy(cfg)
--should't happen, added for robustness.
local n_groups = wml.variables["wc2_enemy_army.group.length"]
if n_groups > 0 then
enemy_type_id = wesnoth.random(n_groups) - 1
enemy_type_id = mathx.random(n_groups) - 1
else
error("no enemy groups defined")
end

View file

@ -8,7 +8,7 @@ local strings = {
-- which means in paticular changing the castle of the enemy accorign to the unit type of that
-- enemy, and giving him an extra unit.
local function wct_map_enemy_themed(race, pet, castle, village, chance)
if wesnoth.random(100) > chance then
if mathx.random(100) > chance then
return
end
local boss = wesnoth.units.find_on_map {
@ -56,7 +56,7 @@ local function wct_map_enemy_themed(race, pet, castle, village, chance)
}
-- extra tweak with trees to elvish castle
for i, tile in ipairs(elvish_castle) do
if wesnoth.random(10) <= 4 then
if mathx.random(10) <= 4 then
wesnoth.current.map[tile] = "Cv^Fet"
end
end

View file

@ -46,7 +46,7 @@ function wesnoth.wml_actions.wc2_store_carryover(cfg)
local human_sides = wesnoth.sides.find(wml.get_child(cfg, "sides"))
--use an the average amount of villages for this scenario to stay independent of map generator results.
local nvillages = cfg.nvillages
local turns_left = math.max(wesnoth.game_config.last_turn - wesnoth.current.turn, 0)
local turns_left = math.max(wesnoth.scenario.turns - wesnoth.current.turn, 0)
local player_gold = 0
for side_num, side in ipairs(human_sides) do
@ -77,7 +77,7 @@ on_event("enemies defeated", function(cx)
if wml.variables.wc2_scenario > 4 then
return
end
wesnoth.play_sound("ambient/ship.ogg")
wesnoth.audio.play("ambient/ship.ogg")
wesnoth.wml_actions.endlevel {
result = "victory",
carryover_percentage = 0,

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require("helper")
local on_event = wesnoth.require("on_event")
local _ = wesnoth.textdomain 'wesnoth-wc'
@ -74,7 +73,7 @@ local function init_side(side_num)
for v in wml.child_range(faction, "pair") do
i = i + 1
local p = stringx.split(v.types or "")
if wesnoth.random(1,2) == 2 then
if mathx.random(1,2) == 2 then
p[1],p[2] = p[2],p[1]
end
wesnoth.wml_actions.allow_recruit {
@ -86,7 +85,7 @@ local function init_side(side_num)
end
if not faction and #wc2_era.factions_wml > 0 then
faction = wc2_era.factions_wml[wesnoth.random(#wc2_era.factions_wml)]
faction = wc2_era.factions_wml[mathx.random(#wc2_era.factions_wml)]
end
if not faction then
@ -97,9 +96,9 @@ local function init_side(side_num)
local deserters = wc2_era.expand_hero_types(faction.deserters)
local commanders = wc2_era.expand_hero_types(faction.commanders)
helper.shuffle(heroes)
helper.shuffle(deserters)
helper.shuffle(commanders)
mathx.shuffle(heroes)
mathx.shuffle(deserters)
mathx.shuffle(commanders)
side.variables["wc2.heroes"] = table.concat(heroes, ",")
side.variables["wc2.deserters"] = table.concat(deserters, ",")
@ -116,13 +115,13 @@ end
local function add_known_spawn_filter(spawn_filter)
local types = stringx.map_split(spawn_filter.types or "")
local filter_location = wml.get_child(spawn_filter, "filter_location") or helper.wml_error("missing [filter_location] in [hero_spawn_filter]")
local filter_location = wml.get_child(spawn_filter, "filter_location") or wml.error("missing [filter_location] in [hero_spawn_filter]")
table.insert(wc2_era.spawn_filters, { types = types, filter_location = filter_location} )
end
local function add_known_trait_extra(trait_extra)
local types = stringx.map_split(trait_extra.types or "")
local trait = wml.get_child(trait_extra, "trait") or helper.wml_error("missing [trait] in [trait_extra]")
local trait = wml.get_child(trait_extra, "trait") or wml.error("missing [trait] in [trait_extra]")
table.insert(wc2_era.hero_traits, { types = types, trait = trait} )
end
-- in case that a [multiplayer_side] has not [world_conquest_data] we generate it randomly.
@ -132,11 +131,11 @@ function wc2_era.create_random_faction(id)
local heroes_set = {}
local commanders_set = {}
local i_deserters1 = wesnoth.random(#wc2_era.standard_factions)
local i_deserters2 = wesnoth.random(#wc2_era.standard_factions)
local i_heroes1 = wesnoth.random(#wc2_era.standard_factions)
local i_heroes2 = wesnoth.random(#wc2_era.standard_factions)
local i_commanders = wesnoth.random(#wc2_era.standard_factions)
local i_deserters1 = mathx.random(#wc2_era.standard_factions)
local i_deserters2 = mathx.random(#wc2_era.standard_factions)
local i_heroes1 = mathx.random(#wc2_era.standard_factions)
local i_heroes2 = mathx.random(#wc2_era.standard_factions)
local i_commanders = mathx.random(#wc2_era.standard_factions)
deserters_set = stringx.map_split(wc2_era.standard_factions[i_deserters1].recruits .. ',' .. wc2_era.standard_factions[i_deserters2].recruits)
heroes_set = stringx.map_split(wc2_era.standard_factions[i_heroes1].recruits .. ',' .. wc2_era.standard_factions[i_heroes2].recruits)
@ -174,7 +173,7 @@ function wc2_era.read_era_tag(era_wml)
end
function wc2_era.init_era_default()
wc2_era.read_era_tag(wesnoth.game_config.era)
wc2_era.read_era_tag(wesnoth.scenario.era)
wc2_era.init_data()
end

View file

@ -17,12 +17,12 @@ function wesnoth.wml_actions.wc2_place_bonus(cfg)
local image = c_scenery.image or scenery
bonus.place_item(x, y, image)
-- Note: although the numbrs of options passed to helper.rand might depend on the langauge
-- the number of thimes random is called does not (random is called even if there is
-- Note: although the numbers of options passed to mathx.random_choice might depend on the langauge
-- the number of times random is called does not (random is called even if there is
-- only one option), so this doesn't cause OOS.
local name1 = wc2_random_names()
local name_options = c_scenery.names or { _"place" }
local name2 = tostring(name_options[wesnoth.random(#name_options)])
local name2 = tostring(name_options[mathx.random(#name_options)])
local function span_font_family(str, fam)
return string.format("<span font-family='%s'>%s</span>", fam, str)
@ -100,7 +100,7 @@ on_event("wc2_drop_pickup", function(ec)
local training_chance = wml.variables.wc2_config_training_chance or 1
local hero_chance = wml.variables.wc2_config_hero_chance or 1
local item_chance = wml.variables.wc2_config_item_chance or 1
local r = wesnoth.random(training_chance + hero_chance + item_chance)
local r = mathx.random(training_chance + hero_chance + item_chance)
if r <= training_chance then
bonus_type = 1
elseif r <= training_chance + item_chance then
@ -112,7 +112,7 @@ on_event("wc2_drop_pickup", function(ec)
local bonus_subtype = item.wc2_subtype
if bonus_type == 1 then
if not bonus.found_training(wesnoth.current.side, bonus_subtype, ec) then
bonus_type = wesnoth.random(2,3)
bonus_type = mathx.random(2,3)
bonus_subtype = nil
end
end

View file

@ -10,7 +10,7 @@ wc2_heroes.dialogues = {}
wc2_heroes.trait_heroic = nil
wc2_heroes.trait_expert = nil
if wesnoth.have_file("./unittypedata.lua") then
if filesystem.have_file("./unittypedata.lua") then
local data = wesnoth.require("./unittypedata.lua")
for v,k in pairs(data) do
wc2_heroes.dialogues[v] = k

View file

@ -8,7 +8,7 @@ function wc2_invest.add_items(side_num, num_items)
local items_left = stringx.split(side.variables["wc2.items_left"] or "")
local items_available = stringx.split(side.variables["wc2.items"] or "")
for j = 1, num_items do
local i = wesnoth.random(#items_left)
local i = mathx.random(#items_left)
table.insert(items_available, items_left[i])
table.remove(items_left, i)
end
@ -72,7 +72,7 @@ function wc2_invest.do_hero(t, is_local)
local x,y = leaders[1].x, leaders[1].y
if t == "wc2_commander" then
local commanders = stringx.split(side.variables["wc2.commanders"] or "")
local i = wesnoth.random(#commanders)
local i = mathx.random(#commanders)
t = commanders[i]
table.remove(commanders, i)
side.variables["wc2.commanders"] = table.concat(commanders, ",")
@ -85,7 +85,7 @@ function wc2_invest.do_hero(t, is_local)
wesnoth.sides[side_num].gold = wesnoth.sides[side_num].gold + 15
local deserters = stringx.split(side.variables["wc2.deserters"] or "")
local i = wesnoth.random(#deserters)
local i = mathx.random(#deserters)
t = deserters[i]
table.remove(deserters, i)
side.variables["wc2.deserters"] = table.concat(deserters, ",")
@ -171,7 +171,7 @@ end
function wesnoth.wml_actions.wc2_invest(cfg)
--disallow undoing.
wesnoth.random(100)
mathx.random(100)
wc2_invest.invest()
end

View file

@ -102,7 +102,7 @@ function training.find_available(side_num, among, amount)
if #possible_traintypes == 0 then
return
else
return possible_traintypes[wesnoth.random(#possible_traintypes)]
return possible_traintypes[mathx.random(#possible_traintypes)]
end
end
@ -184,7 +184,7 @@ end
function training.bonus_calculate_amount(side_num)
local amount = 1
local advanced_chance = 4 * training.get_level_sum(side_num)
if wc2_scenario.scenario_num() > 3 or wesnoth.random(100) <= advanced_chance then
if wc2_scenario.scenario_num() > 3 or mathx.random(100) <= advanced_chance then
amount = 2
end
return amount
@ -226,7 +226,7 @@ function training.apply(u)
local vchance = wml.tovconfig(chance)
local filter = wml.get_child(vchance, "filter")
local matches_filter = (not filter) or u:matches(filter)
if wesnoth.random(100) <= vchance.value and matches_filter then
if mathx.random(100) <= vchance.value and matches_filter then
--wesnoth.wml_actions.message { message = "Got it" }
table.insert(descriptions, wc2_utils.get_fstring(chance, "info"))
for effect in wml.child_range(vchance, "effect") do

View file

@ -32,7 +32,7 @@ function wc2_utils.pick_random(str, generator)
if #array == 0 and generator then
array = generator()
end
local index = wesnoth.random(#array)
local index = mathx.random(#array)
local res = array[index]
table.remove(array, index)
wml.variables[str] = table.concat(array, ",")
@ -50,7 +50,7 @@ local function filtered_from_array(array, filter)
if #possible_indicies == 0 then
return nil
end
local index = possible_indicies[wesnoth.random(#possible_indicies)]
local index = possible_indicies[mathx.random(#possible_indicies)]
return index
end
@ -79,7 +79,7 @@ end
function wc2_utils.pick_random_t(str)
local size = wml.variables[str .. ".length"]
if size ~= 0 then
local index = wesnoth.random(size) - 1
local index = mathx.random(size) - 1
local res = wml.variables[str .. "[" .. index .. "]"]
wml.variables[str .. "[" .. index .. "]"] = nil
return res
@ -121,43 +121,7 @@ function wc2_utils.has_no_advances(u)
return #u.advances_to == 0
end
local global_vars = setmetatable({}, {
__index = function(self, namespace)
return setmetatable({}, {
__index = function(self, name)
wml.variables.lua_global_variable = nil
wesnoth.unsynced(function()
wesnoth.wml_actions.get_global_variable {
namespace = namespace,
to_local = "lua_global_variable",
from_global = name,
immediate = true,
}
end)
local res = wml.variables.lua_global_variable
wml.variables.lua_global_variable = nil
if res == "" then
return nil
end
return res
end,
__newindex = function(self, name, val)
wml.variables.lua_global_variable = val
wesnoth.unsynced(function()
wesnoth.wml_actions.set_global_variable {
namespace = namespace,
from_local = "lua_global_variable",
to_global = name,
immediate = true,
}
end)
wml.variables.lua_global_variable = nil
end,
})
end
})
wc2_utils.global_vars = global_vars.wc2
wc2_utils.global_vars = wesnoth.experimental.wml.global_vars.wc2
if rawget(_G, "wc2_menu_filters") == nil then
wc2_menu_filters = {}
@ -207,18 +171,17 @@ function wc2_utils.load_wc2_data()
if wc2_utils.world_conquest_data == nil then
local data_dict = {}
local ignore_list = {}
for i,res_id in ipairs(wesnoth.game_config.active_resources) do
local ressource = wesnoth.get_resource(res_id)
local world_conquest_data = wml.get_child(ressource, "world_conquest_data")
for i,resource in ipairs(wesnoth.scenario.resources) do
local world_conquest_data = wml.get_child(resource, "world_conquest_data")
if world_conquest_data then
for ignore in wml.child_range(world_conquest_data, "ignore") do
ignore_list[ignore.id] = true
end
table.insert(data_dict, {id=res_id, data = world_conquest_data})
table.insert(data_dict, {id=resource.id, data = world_conquest_data})
end
end
table.insert(data_dict, {id="era", data = wesnoth.game_config.era})
table.insert(data_dict, {id="era", data = wesnoth.scenario.era})
-- make sure the result does not depend on the order in which these addons are loaded.

View file

@ -119,7 +119,7 @@ function wesnoth.wml_actions.wc2_show_wocopedia(cfg)
end
end
---- add general factions topic ----
local era_wml = wesnoth.game_config.era
local era_wml = wesnoth.scenario.era
local node, page = root_node:add_help_page {
title = str_cat_era

View file

@ -245,13 +245,13 @@ function default_generate_map(data)
end
for i = 1, 20 do
local status, map = pcall(function()
cfg.seed = wesnoth.random(5000) + 7
cfg.seed = mathx.random(5000) + 7
return wesnoth.map.generate(w, h, cfg)
end)
if status then
return map
end
end
cfg.seed = wesnoth.random(5000) + 7
cfg.seed = mathx.random(5000) + 7
return wesnoth.map.generate(w, h, cfg)
end

View file

@ -28,7 +28,7 @@ local function get_map_generator(scenario_data)
globals.settings.island
)
else
return scenario_data.generators[wesnoth.random(#scenario_data.generators)]
return scenario_data.generators[mathx.random(#scenario_data.generators)]
end
end
@ -37,9 +37,9 @@ function wc_ii_generate_scenario(nplayers, gen_args)
nplayers = settings.nplayers or nplayers
local id_suffix = gen_args.id_suffix or ""
local scenario_extra = wml.get_child(gen_args, "scenario")
local scenario_num = settings.scenario_num or wesnoth.get_variable("wc2_scenario") or 1
local scenario_num = settings.scenario_num or wml.variables.wc2_scenario or 1
--todo: does this work properly in the first scenario?
local enemy_stength = wesnoth.get_variable("wc2_difficulty.enemy_power") or 6
local enemy_stength = wml.variables["wc2_difficulty.enemy_power"] or 6
local scenario_data = wesnoth.dofile(string.format("./scenarios/WC_II_%dp_scenario%d.lua", nplayers, scenario_num))
local prestart_event = { name = "prestart" }

View file

@ -48,9 +48,9 @@ function world_conquest_tek_map_decoration_1()
}
-- tweak roads
if wesnoth.random(20) ~= 1 then
local rad = wesnoth.random(5, 9)
local ter = helper.rand("Ch*^*,Kh*^*,Ch*^*,Kh*^*")
if mathx.random(20) ~= 1 then
local rad = mathx.random(5, 9)
local ter = mathx.random_choice("Ch*^*,Kh*^*,Ch*^*,Kh*^*")
set_terrain { "Rb",
f.all(
f.terrain("Re"),
@ -63,13 +63,13 @@ function world_conquest_tek_map_decoration_1()
-- chances of fords
local terrain_to_change = wct_store_possible_encampment_ford();
while #terrain_to_change > 0 and wesnoth.random(2) == 1 do
local i = wesnoth.random(#terrain_to_change)
while #terrain_to_change > 0 and mathx.random(2) == 1 do
local i = mathx.random(#terrain_to_change)
map[terrain_to_change[i]] = "Wwf"
terrain_to_change = wct_store_possible_encampment_ford()
end
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
wct_change_map_water("g")
end
-- randomize a few forest
@ -87,7 +87,7 @@ function world_conquest_tek_map_decoration_1()
),
}
if wesnoth.random(8) ~= 1 then
if mathx.random(8) ~= 1 then
set_terrain { "Mm^Xm",
f.all(
f.terrain("Xu"),
@ -122,7 +122,7 @@ end
function wct_map_1_post_castle_expansion_fix()
wct_map_reduce_castle_expanding_recruit("Ce", "Wwf")
local r = helper.rand("Ch,Ch,Ch,Chw,Chw,Chs,Ce,Wwf")
local r = mathx.random_choice("Ch,Ch,Ch,Chw,Chw,Chs,Ce,Wwf")
set_terrain { r,
f.all(
f.terrain("Ce"),

View file

@ -19,28 +19,28 @@ function world_conquest_tek_map_decoration_2a()
}
-- chances of tropical palm forest near caves
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("Hh*^F*"),
f.adjacent(f.terrain("Xu,U*^*,Mv,Ql,Qxu"))
))
if #terrain_to_change > 3 then
local r = wesnoth.random(0, #terrain_to_change - 3)
local r = mathx.random(0, #terrain_to_change - 3)
for i = 1, r do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Hh^Ftp"
end
end
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("G*^F*"),
f.adjacent(f.terrain("Xu,U*^*,Mv,Ql,Qxu"))
))
if #terrain_to_change > 3 then
local r = wesnoth.random(0, #terrain_to_change - 3)
local r = mathx.random(0, #terrain_to_change - 3)
for i = 1, r do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Gs^Ftp"
end
end
@ -139,7 +139,7 @@ function world_conquest_tek_map_decoration_2a()
-- fords
local r = wesnoth.random(0, 4)
local r = mathx.random(0, 4)
for i = 1, r do
set_terrain { "Wwf",
f.all(
@ -152,8 +152,8 @@ function world_conquest_tek_map_decoration_2a()
end
-- chances flowers
local terrain_to_change = wct_store_possible_flowers("G*^Fet")
while #terrain_to_change > 0 and wesnoth.random(10) ~= 1 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
while #terrain_to_change > 0 and mathx.random(10) ~= 1 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "^Efm"
local terrain_to_change = wct_store_possible_flowers("G*^Fet")
end
@ -167,7 +167,7 @@ function world_conquest_tek_map_decoration_2a()
}
wct_map_reduce_castle_expanding_recruit("Ce", "Re")
if wesnoth.random(5) ~= 1 then
if mathx.random(5) ~= 1 then
wct_map_decorative_docks()
end
end

View file

@ -1,21 +1,21 @@
-- Lakes
local function world_conquest_tek_map_repaint_2b()
-- Add snow and ice
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("!,Ss,D*^*,Hd,W*^*,Mm^Xm,Xu,Mv,Q*^*,U*^*"),
f.radius(2, f.terrain("M*^*"))
))
-- base amount in map surface
local r = helper.rand(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 330))
local r = mathx.random_choice(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 330))
wct_storm(terrain_to_change, r)
end
wct_expand_snow()
set_terrain { "Ai",
f.all(
f.terrain("Wwt,Wot"),
f.adjacent(f.terrain("A*^*,Ms^*,Ha^*,Kha,Cha"), nil, wesnoth.random(3, 5))
f.adjacent(f.terrain("A*^*,Ms^*,Ha^*,Kha,Cha"), nil, mathx.random(3, 5))
),
}
-- randomize snowed forests
@ -58,14 +58,14 @@ local function world_conquest_tek_map_repaint_2b()
fraction = 2,
}
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
set_terrain { "Gg",
f.terrain("Gs^*"),
layer = "base",
}
end
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
set_terrain { "Gg^Gvs",
f.all(
f.terrain("Gg"),
@ -88,13 +88,13 @@ local function world_conquest_tek_map_repaint_2b()
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
wct_dirt_beachs("9..11")
-- chance of different lakes water
-- todo: does this syntax really work?
local terrain_mod = helper.rand("g,,,,,,,,,,,,,,,,,,t")
local terrain_mod = mathx.random_choice("g,,,,,,,,,,,,,,,,,,t")
set_terrain { "Ww" .. terrain_mod,
f.terrain("Wwt^*"),
layer = "base",
@ -104,7 +104,7 @@ local function world_conquest_tek_map_repaint_2b()
}
-- chance of frozen lakes
if wesnoth.random(9) == 1 then
if mathx.random(9) == 1 then
set_terrain { "Ai",
f.all(
f.terrain("Ww,Wwg,Wo,Wog"),
@ -144,7 +144,7 @@ local function world_conquest_tek_map_repaint_2b()
local terrain_to_change = map:find(f.terrain("A*^*,Ha*^*,Ms^*"))
local chance = 2000 * #terrain_to_change // total_tiles
if wesnoth.random(0, 99 ) > chance then
if mathx.random(0, 99 ) > chance then
set_terrain { "*^Ftd",
f.terrain("*^Ft"),
layer = "overlay",
@ -231,7 +231,7 @@ function world_conquest_tek_map_constructor_lakes()
fraction_rand = "11..13",
}
local r = helper.rand(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 285))
local r = mathx.random_choice(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 285))
set_terrain { "Hh^Uf",
f.all(

View file

@ -141,9 +141,9 @@ function world_conquest_tek_map_decoration_2c()
f.terrain("Wo"),
f.adjacent(f.terrain("!,Wo"), nil, 0)
))
helper.shuffle(terrain_to_change)
mathx.shuffle(terrain_to_change)
-- base amount in map surface
local r = helper.rand(tostring(total_tiles // 285) .. ".." .. tostring(total_tiles // 150))
local r = mathx.random_choice(tostring(total_tiles // 285) .. ".." .. tostring(total_tiles // 150))
for i = 1, math.min(r, #terrain_to_change) do
map[terrain_to_change[i]] = "Ai"
end
@ -152,8 +152,8 @@ function world_conquest_tek_map_decoration_2c()
f.terrain("Wo"),
f.adjacent(f.terrain("!,Wo,Ai"), nil, 0)
))
helper.shuffle(icepack_candiates)
local r = helper.rand(tostring(total_tiles // 250) .. ".." .. tostring(total_tiles // 150))
mathx.shuffle(icepack_candiates)
local r = mathx.random_choice(tostring(total_tiles // 250) .. ".." .. tostring(total_tiles // 150))
for i = 1, math.min(r, #icepack_candiates) do
local loc = icepack_candiates[i]
@ -170,20 +170,20 @@ function world_conquest_tek_map_decoration_2c()
fraction = 15,
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Wwf",
f.terrain("Gd"),
fraction_rand = "2..6",
}
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Gs",
f.terrain("Gd"),
fraction_rand = "1..5",
}
end
if wesnoth.random(8) == 1 then
if mathx.random(8) == 1 then
set_terrain { "Aa,Aa,Aa,Ai",
f.terrain("Gd"),
fraction_rand = "1..4",

View file

@ -15,7 +15,7 @@ end
function wct_provinces_castle(terrain_to_change, terrain)
if #terrain_to_change > 0 then
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = terrain
end
end

View file

@ -10,7 +10,7 @@ function wct_map_2e_post_bunus_decoration()
end
function world_conquest_tek_map_repaint_2e()
world_conquest_tek_map_noise_proxy(1, wesnoth.random(1,2), "!,W*^*,Ds*^*,X*,M*^Xm,R*^*,Ch*,K*,U*^*,Ql^B*")
world_conquest_tek_map_noise_proxy(1, mathx.random(1,2), "!,W*^*,Ds*^*,X*,M*^Xm,R*^*,Ch*,K*,U*^*,Ql^B*")
-- create citadel castles
wct_map_reduce_castle_expanding_recruit("Xos", "Rr^Fet")
@ -57,12 +57,12 @@ function world_conquest_tek_map_repaint_2e()
-- create villages in empty citadels
local terrain_to_change = wct_store_empty_citadel()
while #terrain_to_change > 0 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Rr^Vhc"
terrain_to_change = wct_store_empty_citadel()
end
-- improve roads quality
local r = wesnoth.random(2,4)
local r = mathx.random(2,4)
set_terrain { "Rr",
f.all(
f.terrain("Re"),
@ -86,11 +86,11 @@ function world_conquest_tek_map_repaint_2e()
}
local max_yards = map.height * map.width // 300
local nyards = tonumber(helper.rand("1,0.." .. max_yards))
local nyards = tonumber(mathx.random_choice("1,0.." .. max_yards))
for i = 1, nyards do
local yard_dir = "n,nw,ne"
local yard_cdir = "s,sw,se"
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
yard_dir, yard_cdir = yard_cdir, yard_dir
end
wct_map_yard(yard_dir, yard_cdir)
@ -98,7 +98,7 @@ function world_conquest_tek_map_repaint_2e()
-- chance of farms replacing yards
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "Rb^Gvs,Rb^Gvs,Rb^Gvs,Gg",
f.terrain("*^Eff"),
}
@ -136,7 +136,7 @@ function wct_map_yard(directions, counter_directions)
))
if #terrain_to_change > 0 then
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Gg^Eff"
set_terrain { "Gg^Eff",
f.adjacent( f.is_loc(loc), counter_directions, nil)
@ -202,7 +202,7 @@ function wct_map_decoration_3e_leantos()
)
))
for i, v in ipairs(terrain_to_change) do
if wesnoth.random(3) == 1 then
if mathx.random(3) == 1 then
map[v] = "Rrc"
table.insert(prestart_event, wml.tag.item {

View file

@ -9,7 +9,7 @@ end
function world_conquest_tek_map_decoration_3a()
-- chances of some dessert over swamp
if wesnoth.random(4) ~= 1 then
if mathx.random(4) ~= 1 then
set_terrain { "Dd^Edp,Dd^Do,Dd,Dd,Dd,Dd,Dd,Dd",
f.all(
f.terrain("Ss"),
@ -139,7 +139,7 @@ function world_conquest_tek_map_decoration_3a()
f.terrain("Xu"),
}
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
wct_change_map_water("t")
end
set_terrain { "Gs^Ft",

View file

@ -378,7 +378,7 @@ function world_conquest_tek_map_decoration_3c()
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
wct_change_map_water("t")
end
end

View file

@ -10,8 +10,8 @@ function world_conquest_tek_map_repaint_3f()
-- soft rough terrain generated
local terrain_to_change = wct_store_cave_passages_candidates()
while #terrain_to_change > 0 do
-- the oriignal code also did not randomize this.
-- todo: but maybe we should? (use wesnoth.random(#terrain_to_change[) instead of 1 here)
-- the original code also did not randomize this.
-- todo: but maybe we should? (use mathx.random(#terrain_to_change) instead of 1 here)
map[terrain_to_change[1]] = "Mm"
terrain_to_change = wct_store_cave_passages_candidates()
end
@ -145,7 +145,7 @@ function wct_map_3f_post_bunus_decoration(bonus_points)
fraction = 4,
}
if wesnoth.random(7) == 1 then
if mathx.random(7) == 1 then
set_terrain { "Wwf",
f.all(
f.terrain("G*"),
@ -160,7 +160,7 @@ function wct_map_3f_post_bunus_decoration(bonus_points)
}
end
if wesnoth.random(7) == 1 then
if mathx.random(7) == 1 then
set_terrain { "Wwf",
f.all(
f.terrain("G*"),

View file

@ -101,7 +101,7 @@ function world_conquest_tek_map_decoration_4a()
}
-- better road near castle
local rad = helper.rand("1,2,3,3,3,3,4,4")
local rad = mathx.random_choice("1,2,3,3,3,3,4,4")
set_terrain { "Rr",
f.all(
f.terrain("Re"),
@ -150,8 +150,8 @@ function world_conquest_tek_map_decoration_4a()
-- chances flowers
local terrain_to_change = wct_store_possible_flowers("Rr^Vhc")
while #terrain_to_change > 0 and wesnoth.random(10) > 5 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
while #terrain_to_change > 0 and mathx.random(10) > 5 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "^Efm"
terrain_to_change = wct_store_possible_flowers("Rr^Vhc")
end
@ -162,30 +162,30 @@ function world_conquest_tek_map_decoration_4a()
layer = "overlay",
}
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "*^Ftr",
f.terrain("G*^Fds"),
layer = "overlay",
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "*^Ftr",
f.terrain("G*^Fms"),
fraction = 3,
layer = "overlay",
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "*^Ftr",
f.terrain("G*^Fp"),
fraction = 5,
layer = "overlay",
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_change_map_water("g")
end
end

View file

@ -91,21 +91,21 @@ function world_conquest_tek_map_repaint_4b()
fraction = 3,
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Ur^Vd",
f.terrain("Ur^Vu"),
fraction_rand = "2..3",
}
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Rd^Vd",
f.terrain("Rd^Vhh"),
fraction_rand = "2..3",
}
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Ds^Vd",
f.terrain("D*^V*"),
fraction_rand = "3..4",
@ -193,7 +193,7 @@ function world_conquest_tek_map_repaint_4b()
f.adjacent(f.terrain("K*^*,C*^*,*^V"), "se,s,sw", 0)
))
if #terrain_to_change > 0 then
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
set_terrain { "Md^Xm",
f.all(
f.none(f.terrain("M*^*")),
@ -277,8 +277,8 @@ function world_conquest_tek_map_repaint_4b()
-- mushrooms, base amount in map surface
local terrain_to_change = map:find(f.terrain("Hhd,Hhd^F^*"))
helper.shuffle(terrain_to_change)
local r = helper.rand(tostring(total_tiles // 600) .. ".." .. tostring(total_tiles // 300))
mathx.shuffle(terrain_to_change)
local r = mathx.random_choice(tostring(total_tiles // 600) .. ".." .. tostring(total_tiles // 300))
for mush_i = 1, math.min(r, #terrain_to_change) do
map[terrain_to_change[mush_i]] = "Hhd^Uf"
@ -321,8 +321,8 @@ function world_conquest_tek_map_repaint_4b()
f.adjacent(f.terrain("Uue"))
))
helper.shuffle(whirlpool_candidats)
for i = 1, #whirlpool_candidats // wesnoth.random(4, 15) do
mathx.shuffle(whirlpool_candidats)
for i = 1, #whirlpool_candidats // mathx.random(4, 15) do
local loc = whirlpool_candidats[i]
table.insert(prestart_event, wml.tag.item {
@ -354,11 +354,11 @@ function world_conquest_tek_map_repaint_4b()
-- very dirt coast
local terrain_to_change = map:find(f.terrain("Ds"))
helper.shuffle(terrain_to_change)
for i = 1, #terrain_to_change // wesnoth.random(3, 4) do
mathx.shuffle(terrain_to_change)
for i = 1, #terrain_to_change // mathx.random(3, 4) do
map[terrain_to_change[i]] = "Ds^Esd"
end
helper.shuffle(terrain_to_change)
mathx.shuffle(terrain_to_change)
for i = 1, #terrain_to_change // 6 do
map[terrain_to_change[i]] = "Ds^Es"
end
@ -401,7 +401,7 @@ function world_conquest_tek_map_repaint_4b()
}
local r = wesnoth.random(20)
local r = mathx.random(20)
if r == 1 then
wct_change_map_water("g")
elseif r == 2 then

View file

@ -230,7 +230,7 @@ function world_conquest_tek_map_decoration_4c()
layer = "overlay",
}
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_change_map_water("t")
end
end
@ -262,7 +262,7 @@ function wct_map_4c_post_bunus_decoration()
))
for forge_i, v in ipairs(terrain_to_change) do
local r = wesnoth.random(6)
local r = mathx.random(6)
if r == 1 then
map[v] = "Cud"
elseif r == 2 then

View file

@ -1,7 +1,7 @@
-- Podzol
local function world_conquest_tek_map_repaint_4d()
local rad = helper.rand("1,2,2")
local rad = mathx.random_choice("1,2,2")
world_conquest_tek_map_noise_proxy(rad, 2 , "!,W*^*,Ai,Ds*^*,Xu,M*^Xm,R*^*,Ch*,Cud,K*,U*^*,Ql^B*")
wct_reduce_wall_clusters("Uu,Uu,Uu,Uu,Uh,Uh,Ai")
@ -102,7 +102,7 @@ local function world_conquest_tek_map_repaint_4d()
f.terrain("Ww"),
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Ai",
f.all(
f.terrain("Wwg"),

View file

@ -364,7 +364,7 @@ function world_conquest_tek_map_repaint_4e()
}
local r = "Gs^Fp,Gs^Fms,Gs^Fds,Gs^Ft,Gs^Ft,Gs^Ftp,Gs^Ftr,Gs^Ftd,Gs^Fet"
r = helper.rand(r)
r = mathx.random_choice(r)
set_terrain { r,
f.all(
f_west_half,
@ -376,7 +376,7 @@ function world_conquest_tek_map_repaint_4e()
}
local r = "Gs^Fp,Gs^Fms,Gs^Fds,Gs^Ftp,Gs^Ft,Gs^Ftp,Gs^Ftr,Gs^Ftd,Gs^Fet,Gs^Fts,Gs^Fts,Gs^Ft,Gs^Ft,Gs^Ftd,Gs^Fp"
r = helper.rand(r)
r = mathx.random_choice(r)
set_terrain { r,
f.all(
f.terrain("Gs^F*,Hh^F*"),
@ -587,7 +587,7 @@ function wct_map_4e_post_bunus_decoration()
f_north_half
)
),
fraction = wesnoth.random(10,30),
fraction = mathx.random(10,30),
}
-- small mushrooms northeast
@ -601,7 +601,7 @@ function wct_map_4e_post_bunus_decoration()
f_west_half
)
),
fraction = wesnoth.random(2,3),
fraction = mathx.random(2,3),
}
-- slighty soft dessert southwest

View file

@ -70,7 +70,7 @@ function repaint(map_data)
exact = false,
}
if wesnoth.random(4) == 1 then
if mathx.random(4) == 1 then
set_terrain { "Ww",
f.terrain("Wwg^*"),
layer = "base",
@ -238,7 +238,7 @@ function wild_zones_replace(heights)
for i_temp, temp in ipairs(height) do
handle_single_zone(temp.all_locs, temp[1].default)
for zone_i, zone in ipairs(temp.zones) do
local wild_dice = wesnoth.random(100)
local wild_dice = mathx.random(100)
for chance_i, chance in ipairs(temp[1].chances) do
if wild_dice <= chance.value then
handle_single_zone(zone, chance.command)

View file

@ -67,7 +67,7 @@ local function world_conquest_tek_map_decoration_6a()
}
-- stone roads, better ones near castle
local rad = wesnoth.random(4, 6)
local rad = mathx.random(4, 6)
set_terrain { "Rrc",
f.all(
f.terrain("Re"),
@ -175,7 +175,7 @@ local function world_conquest_tek_map_decoration_6a()
))
))
local r = helper.rand(tostring(total_tiles // 930) .. ".." .. tostring(total_tiles // 210))
local r = mathx.random_choice(tostring(total_tiles // 930) .. ".." .. tostring(total_tiles // 210))
wct_storm(terrain_to_change, r + 2)
wct_expand_snow()
@ -269,14 +269,14 @@ local function world_conquest_tek_map_decoration_6a()
-- chances of few dwarven castles
local terrain_to_change = wct_store_possible_dwarven_castle()
while #terrain_to_change > 0 and wesnoth.random(2) == 1 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
while #terrain_to_change > 0 and mathx.random(2) == 1 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Cud"
terrain_to_change = wct_store_possible_dwarven_castle()
end
-- decorative farmlands in base to log villages
local terrain_to_change = map:find(f.terrain("Gs^Vl"))
for i = 1, wesnoth.random(0, 2 * #terrain_to_change) do
for i = 1, mathx.random(0, 2 * #terrain_to_change) do
set_terrain { "Gg^Gvs",
f.all(
f.terrain("Gs,Gg"),
@ -319,7 +319,7 @@ local function world_conquest_tek_map_decoration_6a()
}
-- chance of fences near farmlands
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("Gs,Gg,Gll,Aa,Ai"),
f.adjacent(f.terrain("Gg^Gvs")),
@ -333,7 +333,7 @@ local function world_conquest_tek_map_decoration_6a()
end
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Gs^Eff",
f.any(
f.all(
@ -350,7 +350,7 @@ local function world_conquest_tek_map_decoration_6a()
end
-- chances of stone walls and dark roads near darven castls
local rad = wesnoth.random(1, 4)
local rad = mathx.random(1, 4)
set_terrain { "Xos",
f.all(
f.terrain("Xu"),
@ -359,7 +359,7 @@ local function world_conquest_tek_map_decoration_6a()
}
wct_map_cave_path_to("Re")
local r = helper.rand("Ur,Urb")
local r = mathx.random_choice("Ur,Urb")
set_terrain { r,
f.all(
f.terrain("Re"),
@ -367,7 +367,7 @@ local function world_conquest_tek_map_decoration_6a()
),
}
if wesnoth.random(3) == 0 then
if mathx.random(3) == 0 then
set_terrain { "Xuc",
f.all(
f.terrain("Xu"),
@ -382,10 +382,10 @@ local function world_conquest_tek_map_decoration_6a()
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_change_map_water("g")
end
wct_noise_snow_to("Wwf")

View file

@ -42,8 +42,8 @@ function wct_maritime_bridges()
local pb = get_possible_maritime_bridge()
while #pb[1].locs > 0 or #pb[2].locs > 0 or #pb[3].locs > 0 do
pb = functional.filter(pb, function(t) return #t.locs >0 end)
local sel = pb[wesnoth.random(#pb)]
local loc = sel.locs[wesnoth.random(#sel.locs)]
local sel = pb[mathx.random(#pb)]
local loc = sel.locs[mathx.random(#sel.locs)]
map[loc] = "Ww^" .. sel.type
pb = get_possible_maritime_bridge()
end
@ -190,7 +190,7 @@ function world_conquest_tek_map_decoration_6b()
f.adjacent(f.terrain("W*^*"), nil, "2-5"),
f.adjacent(f.terrain("Wog,Wwg"))
))
loc = locs[wesnoth.random(#locs)];
loc = locs[mathx.random(#locs)];
map[loc] = "Iwr^Vl"
end
@ -238,7 +238,7 @@ function world_conquest_tek_map_decoration_6b()
}
local locs = map:find(f.terrain("Iwr"))
for ship_i, ship_loc in ipairs(locs) do
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
table.insert(prestart_event, wml.tag.item {
x = ship_loc[1],
y = ship_loc[2],
@ -368,7 +368,7 @@ function world_conquest_tek_map_decoration_6b()
}
-- chance of expand rivers into sea
local r = tonumber(helper.rand("0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3"))
local r = tonumber(mathx.random_choice("0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3"))
for i = 1 , r do
local terrain_to_change = map:find(f.all(
f.terrain("Wog,Wwg,Wwrg"),

View file

@ -103,8 +103,8 @@ local function wct_dirty_deltas()
local terrain_to_change = wct_store_possible_dirty_delta()
while #terrain_to_change > 0 do
local loc = 1 -- todo: maybe use terrain_to_change[wesnoth.random(#terrain_to_change)]
local ter = helper.rand("Gs,Hh^Uf,Cud,Gs^Uf,Gs,Hh,Ds^Edt,Ds,Hh^Fmf,Gs,Gs^Fmf")
local loc = 1 -- todo: maybe use terrain_to_change[mathx.random(#terrain_to_change)]
local ter = mathx.random_choice("Gs,Hh^Uf,Cud,Gs^Uf,Gs,Hh,Ds^Edt,Ds,Hh^Fmf,Gs,Gs^Fmf")
map[loc] = ter
terrain_to_change = wct_store_possible_dirty_delta()
end
@ -122,8 +122,8 @@ local function wct_ford_deltas()
local terrain_to_change = wct_store_possible_ford_delta()
while #terrain_to_change > 0 do
local loc = terrain_to_change[1]-- todo: maybe use errain_to_change[wesnoth.random(#terrain_to_change)]
local ter = helper.rand("Gg,Gg^Efm,Mm,Gg^Fet,Gg,Mm,Gg")
local loc = terrain_to_change[1]-- todo: maybe use errain_to_change[mathx.random(#terrain_to_change)]
local ter = mathx.random_choice("Gg,Gg^Efm,Mm,Gg^Fet,Gg,Mm,Gg")
map[loc] = ter
terrain_to_change = wct_store_possible_ford_delta()
end
@ -385,7 +385,7 @@ local function world_conquest_tek_map_decoration_6c()
))
for swamp_i, swamp_loc in ipairs(terrain_to_change) do
local r = wesnoth.random(3, map.width // 4)
local r = mathx.random(3, map.width // 4)
set_terrain { "Sm",
f.all(
f.terrain("Ww^*"),
@ -402,7 +402,7 @@ local function world_conquest_tek_map_decoration_6c()
))
for water_i, water_loc in ipairs(terrain_to_change) do
local r = wesnoth.random(4, map.width // 6)
local r = mathx.random(4, map.width // 6)
set_terrain { "Wwg",
f.all(
f.terrain("Ww^*"),
@ -413,7 +413,7 @@ local function world_conquest_tek_map_decoration_6c()
}
end
-- fords
local r = wesnoth.random(4, map.width // 10)
local r = mathx.random(4, map.width // 10)
set_terrain { "Wwf",
f.all(
f.terrain("Ww^*"),

View file

@ -453,7 +453,7 @@ local function world_conquest_tek_map_repaint_6d()
fraction_rand = "24..240",
}
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
-- beachs sand and stones

View file

@ -63,12 +63,12 @@ function set_terrain_impl(data)
if d.exact then
num_tiles = math.ceil(num_tiles * chance / 1000)
chance = 1000
helper.shuffle(locs[i])
mathx.shuffle(locs[i])
end
for j = 1, num_tiles do
local loc = locs[i][j]
if chance >= 1000 or chance >= wesnoth.random(1000) then
map[loc] = wesnoth.map['replace_' .. layer](helper.rand(terrains))
if chance >= 1000 or chance >= mathx.random(1000) then
map[loc] = wesnoth.map['replace_' .. layer](mathx.random_choice(terrains))
nlocs_changed = nlocs_changed + 1
end
end
@ -95,7 +95,7 @@ function set_terrain_simul(cfg)
elseif r.fraction then
r_new.per_thousand = math.ceil(1000 / r.fraction);
elseif r.fraction_rand then
r_new.per_thousand = math.ceil(1000 / helper.rand(r.fraction_rand));
r_new.per_thousand = math.ceil(1000 / mathx.random_choice(r.fraction_rand));
end
table.insert(data, r_new)
end

View file

@ -146,7 +146,7 @@ function wct_castle_expansion_side(side_num)
wesnoth.log("warn", "Too few tiles in castle expansion for side " .. side_num .. ", wanted: " .. n_tiles_wanted .. " but we got only " .. #candidates)
n_tiles_wanted = #candidates
end
helper.shuffle(candidates)
mathx.shuffle(candidates)
for i = 1, n_tiles_wanted do
map[candidates[i]] = "Ch"
end

View file

@ -1,7 +1,7 @@
function world_conquest_tek_map_noise_proxy(radius, fraction, terrain)
local terrain_to_change = map:find(f.terrain(terrain))
local nop_filter = wesnoth.map.filter(f.all())
helper.shuffle(terrain_to_change)
mathx.shuffle(terrain_to_change)
for terrain_i = 1, math.ceil(#terrain_to_change / fraction) do
local loc_a = terrain_to_change[terrain_i]
local terrain_to_swap_b = map:find_in_radius({loc_a}, radius, nop_filter)
@ -12,7 +12,7 @@ function world_conquest_tek_map_noise_proxy(radius, fraction, terrain)
), terrain_to_swap_b)
if #terrain_to_swap_b > 0 then
local loc_b = terrain_to_swap_b[wesnoth.random(#terrain_to_swap_b)]
local loc_b = terrain_to_swap_b[mathx.random(#terrain_to_swap_b)]
local terrain_a, terrain_b = map[loc_a], map[loc_b]
map[loc_a] = terrain_b
map[loc_b] = terrain_a

View file

@ -128,8 +128,8 @@ function wct_expand_snow()
),
}
-- chances of expand ice
if wesnoth.random(20) == 1 then
local r = wesnoth.random(3)
if mathx.random(20) == 1 then
local r = mathx.random(3)
set_terrain { "Ai",
f.all(
f.terrain("Ww,Wo"),
@ -138,8 +138,8 @@ function wct_expand_snow()
}
end
if wesnoth.random(20) == 1 then
local r = wesnoth.random(4, 5)
if mathx.random(20) == 1 then
local r = mathx.random(4, 5)
set_terrain { "Ai",
f.all(
f.terrain("Aa"),
@ -156,7 +156,7 @@ function wct_storm(terrain_to_change, snow)
return
end
for show_i = 1, snow do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
set_terrain { "Ai",
f.terrain("Aa"),
locs = { loc },

View file

@ -47,7 +47,7 @@ function world_conquest_tek_map_rebuild(cave, reef)
-- replace hills for mushrooms
-- base amount in map surface
local r = helper.rand(tostring(total_tiles // 500) .. ".." .. tostring(total_tiles // 250))
local r = mathx.random_choice(tostring(total_tiles // 500) .. ".." .. tostring(total_tiles // 250))
-- just to be sure.
r = tonumber(r)
set_terrain { "Hh^Uf",
@ -190,8 +190,8 @@ end
function wct_possible_map4_castle(terrain, value)
local terrain_to_change = wct_store_possible_map4_castle(value)
while #terrain_to_change > 0 and wesnoth.random(value + 1) == 1 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
while #terrain_to_change > 0 and mathx.random(value + 1) == 1 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = terrain
terrain_to_change = wct_store_possible_map4_castle(value)
end
@ -220,7 +220,7 @@ function wct_road_to_village(road, village)
-- build roads of 1 hex to conect villages
local terrain_to_change = wct_store_possible_roads(village)
while #terrain_to_change > 0 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = road
terrain_to_change = wct_store_possible_roads(village)
end
@ -233,7 +233,7 @@ function wct_iterate_roads_to(get_next, radius, terrain)
for r = radius, 1, -1 do
local locs = get_next(r)
while #locs > 0 do
local loc = locs[wesnoth.random(#locs)]
local loc = locs[mathx.random(#locs)]
map[loc] = terrain
locs = get_next(r)
end
@ -287,7 +287,7 @@ function wct_iterate_roads_to_2(f_validpath, f_src, f_dest, terrain_road, radius
goto path_found
end
end
path[#path + 1] = next_locs[wesnoth.random(#next_locs)]
path[#path + 1] = next_locs[mathx.random(#next_locs)]
loc = path[#path]
dist = distmap:get(loc)
end
@ -309,8 +309,8 @@ function wct_break_walls(wall, terrain)
local terrain_to_change = wct_store_broken_wall_candidates(wall)
while #terrain_to_change > 0 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
map[loc] = helper.rand(terrain)
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = mathx.random_choice(terrain)
terrain_to_change = wct_store_broken_wall_candidates(wall)
end
end

View file

@ -10,7 +10,7 @@ local function wild_volcano_for_lava_zone(terrain_to_change)
), { terrain_to_change = terrain_to_change })
if #possible_volcano > 0 then
local loc = possible_volcano[wesnoth.random(#possible_volcano)]
local loc = possible_volcano[mathx.random(#possible_volcano)]
set_terrain { "Md^Xm",
f.adjacent(f.is_loc(loc), "ne,n,nw")
}

View file

@ -20,7 +20,7 @@ function random_placement(locs, num_items, min_distance, command)
helper.wml_error("[random_placement] failed to place items. only " .. i .. " items were placed")
end
end
local index = wesnoth.random(size)
local index = mathx.random(size)
local point = locs[index]
command(point, i)
@ -65,7 +65,7 @@ function random_placement(locs, num_items, min_distance, command)
end
function get_f_wct_bonus_location_filter(map)
local scenario_num = wesnoth.get_variable("wc2_scenario") or 1
local scenario_num = wml.variables.wc2_scenario or 1
return f.all(
f.terrain("G*,Hh,Uu,Uh,Dd,Ds,R*,Mm,Md,Ss,Hd,Hhd,Ww,Wwt,Wwg,Ds^Esd,Ur"),
--no adjacent to village, deep water, chasm or walls
@ -391,7 +391,7 @@ function wct_bonus_chose_scenery(loc, theme, filter_extra)
end
::final_pick::
-- pick random scenery value from our list
local res = helper.rand(scenery)
local res = mathx.random_choice(scenery)
wesnoth.log("debug", "scenery:" .. res .. " from " .. scenery)
return res
end
@ -399,7 +399,7 @@ end
function world_conquest_tek_bonus_points(theme)
local res = {}
local scenario_num = wesnoth.get_variable("wc2_scenario") or 1
local scenario_num = wml.variables.wc2_scenario or 1
oceanic = get_oceanic()
f_wct_bonus_location_filter = wesnoth.map.filter(get_f_wct_bonus_location_filter(map), { oceanic = oceanic })
local possible_locs = map:find(f_wct_bonus_location_filter)

View file

@ -43,7 +43,7 @@ function add_plot(scenario, scenario_num, nplayers)
end_message("1,2,3", true, _ "Victory is ours! Let us set sail in search of new lands to conquer!")
elseif scenario_num == 2 then
local r = wesnoth.random(nplayers)
local r = mathx.random(nplayers)
start_message(r, true, _ "Ahhh. Just look at these fertile lands, ripe for conquest!")
start_message("4", true, _ "Whats this?! Foreign invaders have set foot upon our shores!")
start_message("5", true, _ "Well send them back to where they came from quick enough. All troops, to me!")
@ -57,7 +57,7 @@ function add_plot(scenario, scenario_num, nplayers)
end_message("1,2,3", true, _ "Victory is ours! Let us set sail in search of new lands to conquer!")
elseif scenario_num == 4 then
local r = wesnoth.random(nplayers)
local r = mathx.random(nplayers)
start_message("5", true, _ "Ready yourselves, men! The conquering hordes are upon us!")
start_message("4", true, _ "Word has come to our island of your victories. Your army is impressive, but it will avail you not.")
start_message("6", true, _ "Indeed. You come this far, and no farther!")
@ -69,7 +69,7 @@ function add_plot(scenario, scenario_num, nplayers)
end_message("1,2,3", false, _ "We have travelled great oceans and brought low mighty empires. Should we not wait until our forces regain their strength?")
end_message("1,2,3", true, _ "One last effort! We better finish our campaign when we hold initiative, before Winter arrives.")
else
local r = wesnoth.random(nplayers)
local r = mathx.random(nplayers)
start_message(r, true, _ "Finally we come to the shores of the last continent. Here at the edge of the world our empire shall be made complete.")
start_message("4", true, _ "Never! Your mad quest ends here, tyrant.")

View file

@ -5,7 +5,7 @@ local _ = wesnoth.textdomain 'wesnoth-wc'
function get_defaults(nplayer, nscenario)
if wesnoth.have_file(string.format("./../scenarios/WC_II_%dp_scenario%d.lua", nplayer, nscenario)) then
if filesystem.have_file(string.format("./../scenarios/WC_II_%dp_scenario%d.lua", nplayer, nscenario)) then
local old_wct_map_generator = _G.wct_map_generator
_G.wct_map_generator = function(default_id, postgen_id, length, villages, castle, iterations, hill_size, players, island)
return {

View file

@ -179,7 +179,7 @@ function print_set_terrain(filter, terrain, extra)
end
function convert_filter()
local cfg = wml.parse(wesnoth.read_file("./filterdata.cfg"))
local cfg = wml.parse(filesystem.read_file("./filterdata.cfg"))
std_print("")
for i, v in ipairs(cfg) do
local tag = v[1]

View file

@ -1,6 +1,4 @@
local helper = wesnoth.require("helper")
globals = {}
setmetatable(globals, {
["__index"] = function(t, k)
@ -37,7 +35,7 @@ function shuffle_special_locations(map, loc_ids)
locs[i] = map.special_locations[tostring(v)]
end
assert(#locs == #loc_ids)
helper.shuffle(locs)
mathx.shuffle(locs)
for i , v in ipairs(loc_ids) do
map.special_locations[tostring(v)] = locs[i]
end

View file

@ -10,7 +10,7 @@ Distmap = wesnoth.dofile("./distmap.lua")
wesnoth.dofile("./postgeneration_utils/engine.lua")
local postgenerators = {}
for i, v in ipairs(wesnoth.read_file("./postgeneration")) do
for i, v in ipairs(filesystem.read_file("./postgeneration")) do
local code = string.match(v, "^(%d%a).*")
if code then
postgenerators[string.lower(code)] = v
@ -32,7 +32,7 @@ local function run_postgeneration(map_data, id, scenario_content, nplayers, nhum
for i = 1, nplayers do--nhumanplayer
player_list[i] = i
end
local postgen_starttime = wesnoth.get_time_stamp()
local postgen_starttime = wesnoth.ms_since_init()
wesnoth.dofile("./postgeneration_utils/utilities.lua")
wesnoth.dofile("./postgeneration_utils/events.lua")
wesnoth.dofile("./postgeneration_utils/snow.lua")
@ -48,7 +48,7 @@ local function run_postgeneration(map_data, id, scenario_content, nplayers, nhum
_G.total_tiles = _G.map.width * _G.map.height
_G.prestart_event = scenario_content.event[1]
_G.print_time = function(msg)
wesnoth.log("info", msg .. " time: " .. (wesnoth.get_time_stamp() - postgen_starttime))
wesnoth.log("info", msg .. " time: " .. (wesnoth.ms_since_init() - postgen_starttime))
end
--the only reason why we do this here an not in mian.lua is that it needs a map object.
shuffle_special_locations(map, player_list)

View file

@ -76,12 +76,12 @@ on_event("die", function(cx)
map[loc] = "^Fetd"
elseif loc:matches{terrain = "Aa"} then
item(snow[wesnoth.random(#snow)])
item(snow[mathx.random(#snow)])
elseif loc:matches{terrain = "Ai"} then
item(ice[wesnoth.random(#ice)])
item(ice[mathx.random(#ice)])
elseif loc:matches{terrain = "Ww^Bsb|,Ww^Bsb/,Ww^Bsb\\,Wwt^Bsb|,Wwt^Bsb/,Wwt^Bsb\\,Wwg^Bsb|,Wwg^Bsb/,Wwg^Bsb\\"} then
map[loc] = "Wwf^Edt"
wesnoth.play_sound("water-blast.wav")
wesnoth.audio.play("water-blast.wav")
item("scenery/castle-ruins.png")
elseif loc:matches{terrain = "Rrc"} then
if wml.variables["bonus.theme"] == "paradise" then

View file

@ -706,9 +706,6 @@ sort=yes
# no strings committed so far
[about]
title = _"Friulian Translation" # wmllint: no spellcheck
[entry]
name = ""
[/entry]
[/about]
[about]

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 836 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,000 B

Some files were not shown because too many files have changed in this diff Show more