Merge branch 'dev' into dev-cbot-factory

1164-fix
Fiftytwo 2020-06-16 20:07:03 +02:00
commit 5c0cfba8ae
653 changed files with 11026 additions and 4082 deletions

7
.gitignore vendored
View File

@ -38,3 +38,10 @@ CMakeLists.txt.user.*
# Ignore Visual Studio Code files
/.vscode
# Ignore CLion files
/.idea
# Ignore Visual Studio files
/CMakeSettings.json
/.vs

View File

@ -13,7 +13,7 @@ project(colobot C CXX)
set(COLOBOT_VERSION_CODENAME "Gold")
set(COLOBOT_VERSION_MAJOR 0)
set(COLOBOT_VERSION_MINOR 1)
set(COLOBOT_VERSION_REVISION 11)
set(COLOBOT_VERSION_REVISION 12)
# Used on official releases
#set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha")
@ -60,6 +60,7 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
set(PLATFORM_GNU 0)
set(PLATFORM_LINUX 0)
set(PLATFORM_MACOSX 0)
set(PLATFORM_FREEBSD 0)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
@ -71,6 +72,7 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(PLATFORM_LINUX 1)
set(PLATFORM_GNU 1)
set(PLATFORM_MACOSX 0)
set(PLATFORM_FREEBSD 0)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
@ -82,6 +84,7 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD" OR "${CMAKE_SYSTEM_NAME}" STREQ
set(PLATFORM_LINUX 0)
set(PLATFORM_GNU 1)
set(PLATFORM_MACOSX 0)
set(PLATFORM_FREEBSD 0)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
@ -94,18 +97,35 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(PLATFORM_GNU 0)
set(PLATFORM_MACOSX 1)
set(PLATFORM_OTHER 0)
set(PLATFORM_FREEBSD 0)
# Platform-dependent implementation of system.h
set(SYSTEM_CPP_MODULE "system_macosx.cpp")
set(SYSTEM_H_MODULE "system_macosx.h")
# To avoid CMake warning
set(CMAKE_MACOSX_RPATH 1)
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
message(STATUS "Build for FreeBSD system")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 0)
set(PLATFORM_GNU 0)
set(PLATFORM_MACOSX 0)
set(PLATFORM_FREEBSD 1)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
# On FreeBSD we can use *_other
set(SYSTEM_CPP_MODULE "system_other.cpp")
set(SYSTEM_H_MODULE "system_other.h")
# To avoid CMake warning
set(CMAKE_MACOSX_RPATH 1)
else()
message(STATUS "Build for other system")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 0)
set(PLATFORM_GNU 0)
set(PLATFORM_MACOSX 0)
set(PLATFORM_FREEBSD 0)
set(PLATFORM_OTHER 1)
# Platform-dependent implementation of system.h
@ -124,6 +144,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Include cmake directory with some additional scripts
set(CMAKE_MODULE_PATH "${colobot_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# MSVC needs different flags if linking statically
option(MSVC_STATIC "Link statically when using MSVC" OFF)
# Compiler detection
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
@ -132,8 +155,13 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(STATUS "Detected GCC version 4.7+")
set(NORMAL_CXX_FLAGS "-std=gnu++11 -Wall -Werror -Wold-style-cast -pedantic-errors")
set(NORMAL_CXX_FLAGS "-std=gnu++11 -Wall -Werror -Wold-style-cast -pedantic-errors -Wmissing-declarations")
set(NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -Wno-error=deprecated-declarations") # updated version of physfs is not available on some platforms so we keep using deprecated functions, see #958
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
set(NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -Wsuggest-override")
endif()
set(RELEASE_CXX_FLAGS "-O2")
set(DEBUG_CXX_FLAGS "-g -O0")
set(TEST_CXX_FLAGS "-pthread")
@ -145,7 +173,11 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Detected Clang version 3.1+")
set(NORMAL_CXX_FLAGS "-std=c++11 -Wall -Werror -Wold-style-cast -pedantic-errors")
if (${PLATFORM_FREEBSD})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=bfd")
endif()
set(NORMAL_CXX_FLAGS "-std=c++11 -Wall -Werror -Wold-style-cast -pedantic-errors -Wmissing-prototypes")
set(NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -Wno-error=deprecated-declarations") # updated version of physfs is not available on some platforms so we keep using deprecated functions, see #958
set(RELEASE_CXX_FLAGS "-O2")
set(DEBUG_CXX_FLAGS "-g -O0")
@ -155,14 +187,19 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(STATUS "Detected MSVC compiler")
set(NORMAL_CXX_FLAGS "/wd\"4244\" /wd\"4309\" /wd\"4800\" /wd\"4996\" /wd\"4351\" /EHsc") # disable some useless warnings
set(RELEASE_CXX_FLAGS "/MD")
set(DEBUG_CXX_FLAGS "/MDd /ZI")
if(MSVC_STATIC)
set(RELEASE_CXX_FLAGS "/MT /Ox")
set(DEBUG_CXX_FLAGS "/MTd /ZI")
else(MSVC_STATIC)
set(RELEASE_CXX_FLAGS "/MD /Ox")
set(DEBUG_CXX_FLAGS "/MDd /ZI")
endif()
set(TEST_CXX_FLAGS "")
add_definitions(-DNOEXCEPT= -DHAS_MSVC_EXCEPTION_BUG)
# Needed for Debug information (it's set to "No" by default for some reason)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:LIBCMT")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
else()
message(FATAL_ERROR "Your C++ compiler doesn't seem to be supported.")
endif()
@ -191,11 +228,17 @@ option(DEV_BUILD "Enable development build (enables some debugging tools, local
# Official build - changes text on the crash screen
# PLEASE DO NOT USE ON UNOFFICIAL BUILDS. Thanks.
option(OFFICIAL_BUILD "Official build (changes crash screen text)" OFF)
option(OFFICIAL_COLOBOT_BUILD "Official build (changes crash screen text)" OFF)
# Portable build - load all data from current directory
# Hardcode relative paths instead of absolute paths
option(USE_RELATIVE_PATHS "Generate relative paths from absolute paths" OFF)
# Portable build - load all data from the base directory
option(PORTABLE "Portable build" OFF)
# Portable saves - suitable for e.g. putting the whole game on external storage and moving your saves with it
option(PORTABLE_SAVES "Portable saves" OFF)
# Building tests can be enabled/disabled
option(TESTS "Build tests" OFF)
@ -307,6 +350,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CBOT_STATIC 1) # only this works for some reason
set(WINGETOPT 1) # use wingetopt library
# Hide console in release builds
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_WIN32_EXECUTABLE 1)
endif()
endif()
##
@ -345,21 +393,19 @@ endif()
##
# Installation paths defined before compiling sources
if(PLATFORM_WINDOWS)
if(MXE)
# We need to use STRING because PATH doesn't accept relative paths
set(COLOBOT_INSTALL_BIN_DIR ./ CACHE STRING "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ./ CACHE STRING "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ./data CACHE STRING "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ./lang CACHE STRING "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ./doc CACHE STRING "Colobot documentation directory")
else()
set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/data CACHE PATH "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/lang CACHE PATH "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc CACHE PATH "Colobot documentation directory")
endif()
if(PORTABLE OR (PLATFORM_WINDOWS AND MXE))
set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/data CACHE PATH "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/lang CACHE PATH "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc CACHE PATH "Colobot documentation directory")
set(USE_RELATIVE_PATHS ON)
elseif(PLATFORM_WINDOWS)
set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/data CACHE PATH "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/lang CACHE PATH "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc CACHE PATH "Colobot documentation directory")
elseif(PLATFORM_MACOSX)
set(COLOBOT_INSTALL_BIN_DIR ../MacOS CACHE STRING "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ../MacOS CACHE STRING "Colobot libraries directory")
@ -374,6 +420,18 @@ else()
set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/colobot CACHE PATH "Colobot documentation directory")
endif()
# Generate relative paths from absolute paths
if(USE_RELATIVE_PATHS)
message(STATUS "Generating relative paths")
file(RELATIVE_PATH COLOBOT_DATA_DIR ${COLOBOT_INSTALL_BIN_DIR} ${COLOBOT_INSTALL_DATA_DIR})
file(RELATIVE_PATH COLOBOT_I18N_DIR ${COLOBOT_INSTALL_BIN_DIR} ${COLOBOT_INSTALL_I18N_DIR})
add_definitions(-DUSE_RELATIVE_PATHS)
else()
set(COLOBOT_DATA_DIR ${COLOBOT_INSTALL_DATA_DIR})
set(COLOBOT_I18N_DIR ${COLOBOT_INSTALL_I18N_DIR})
endif()
# Subdirectory with sources
add_subdirectory(src)

View File

@ -71,7 +71,7 @@ You will need:
On Ubuntu (and probably any other Debian-based system), you can use the following command to install all required packages:
```
$ apt-get install build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools
$ apt-get install build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools
```
Make sure you install the packages along with header files (often distributed in separate *-dev packages). If you miss any requirements,

362
Jenkinsfile vendored
View File

@ -1,71 +1,297 @@
#!/usr/bin/env groovy
if (env.BRANCH_NAME.startsWith('PR-')) {
properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactNumToKeepStr: '1']]])
} else {
properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '30', artifactNumToKeepStr: '20']]])
pipeline {
agent none
options {
buildDiscarder(logRotator(artifactDaysToKeepStr: '30', artifactNumToKeepStr: '20'))
}
stages {
stage('Check pull request target') {
when { changeRequest() }
steps {
script {
if (env.CHANGE_TARGET == 'master') {
throw "This pull request targets the wrong branch. Please reopen the pull request targetting the dev branch."
}
}
}
}
stage('Build') {
parallel {
stage('Build Windows') {
agent {
docker { image 'krzysh/colobot-build:latest' }
}
steps {
sh 'mkdir -p build/windows'
dir('build/windows') {
sh '''
# FIXME: without -lsetupapi linking sdl2 fails
rm -rf *
/opt/mxe/usr/bin/i686-w64-mingw32.static-cmake \
-DCMAKE_CXX_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lsetupapi" \
-DCMAKE_INSTALL_PREFIX=/install \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 ../..
make
rm -rf install
DESTDIR=. make install
'''
}
}
post {
success {
sh 'rm -f windows-debug.zip'
zip zipFile: 'windows-debug.zip', archive: true, dir: 'build/windows/install'
}
}
}
stage('Build Linux') {
agent {
docker { image 'krzysh/colobot-build:latest' }
}
steps {
sh 'mkdir -p build/linux'
dir('build/linux') {
sh '''
rm -rf *
cmake \
-DCMAKE_INSTALL_PREFIX=/install -DCMAKE_SKIP_INSTALL_RPATH=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=1 ../..
make
rm -rf install
DESTDIR=. make install
patchelf --set-rpath '.' install/colobot
'''
}
}
post {
success {
sh 'rm -f linux-debug.zip'
dir('build/linux') {
sh '''
# Clean up
rm -rf squashfs-root
rm -rf colobot.AppDir
rm -rf appimage
rm -f Colobot-x86_64.AppImage
# Download app image tool
wget -N https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage
./linuxdeploy-x86_64.AppImage --appimage-extract
# Create AppImage
NO_STRIP=1 ./squashfs-root/AppRun -e colobot --output appimage --appdir colobot.AppDir -d desktop/colobot.desktop -i ../../desktop/colobot.svg
#rename AppImage file to avoid "No such file or directory" errors
find . -maxdepth 1 -type f -name '*AppImage' -name 'Colobot*' -exec sh -c 'x="{}"; mv "$x" "Colobot-x86_64.AppImage"' \\;
chmod +x Colobot-x86_64.AppImage
# Prepare folder for zip
mkdir -p appimage
cp -rp install/data appimage/data
cp -rp install/lang appimage/lang
cp -p Colobot-x86_64.AppImage appimage/colobot
'''
}
zip zipFile: 'linux-debug.zip', archive: true, dir: 'build/linux/appimage'
}
}
}
}
}
stage('Generate docs') {
agent {
docker { image 'krzysh/colobot-build:latest' }
}
steps {
dir('build/linux') {
sh 'make doc'
}
}
post {
success {
publishHTML([reportName: 'Doxygen', reportDir: 'build/linux/doc/html', reportFiles: 'index.html', reportTitles: '', allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false])
}
}
}
stage('Run tests') {
agent {
docker { image 'krzysh/colobot-build:latest' }
}
steps {
dir('build/linux') {
sh './colobot_ut --gtest_output=xml:gtestresults.xml || true'
}
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '0'], [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']], tools: [[$class: 'GoogleTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'build/linux/gtestresults.xml', skipNoTestFiles: false, stopProcessingIfError: true]]])
}
// TODO: Maybe run Windows tests using wine as well?
}
stage('Run colobot-lint') {
agent {
label 'colobot-build'
}
environment {
CC = '/usr/lib/llvm-3.6/bin/clang'
CXX = '/usr/lib/llvm-3.6/bin/clang++'
CLANG_PREFIX = '/usr/lib/llvm-3.6'
}
steps {
copyArtifacts filter: 'build/colobot-lint,build/html_report.tar.gz,Tools/count_errors.py', fingerprintArtifacts: true, projectName: 'colobot/colobot-lint/master', selector: lastSuccessful(), target: 'colobot-lint'
sh 'chmod +x colobot-lint/Tools/count_errors.py' // TODO: ???
sh 'mkdir -p build/lint'
dir('build/lint') {
// The cd is required here because /var/lib/jenkins is a symlink and colobot-lint breaks otherwise...
sh 'cd $WORKSPACE/build/lint; cmake -DCOLOBOT_LINT_BUILD=1 -DTESTS=1 -DTOOLS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $WORKSPACE'
sh '''#!/bin/bash
set -e +x
# Run colobot-lint
COLOBOT_DIR="$WORKSPACE"
COLOBOT_BUILD_DIR="$WORKSPACE/build/lint"
COLOBOT_LINT_BUILD_DIR="$WORKSPACE/colobot-lint/build"
COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml"
# CLANG_PREFIX="/usr/lib/llvm-3.6" # Set in top-level environment block
cd "$COLOBOT_LINT_BUILD_DIR"
chmod +x ./colobot-lint
# Workaround for Clang not finding system headers
rm -rf bin/
mkdir -p bin
mv ./colobot-lint ./bin/
rm -f ./lib
ln -s ${CLANG_PREFIX}/lib ./lib
echo "Running colobot-lint"
find "$WORKSPACE" \\( -wholename "$COLOBOT_DIR/src/*.cpp" \
-or -wholename "$COLOBOT_DIR/test/unit/*.cpp" \
-or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/src/*.cpp" \
-or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/test/unit/*.cpp" \\) \
-exec ./bin/colobot-lint \
-verbose \
-output-format xml \
-output-file "$COLOBOT_LINT_REPORT_FILE" \
-p "$COLOBOT_BUILD_DIR" \
-project-local-include-path "$COLOBOT_DIR/src" -project-local-include-path "$COLOBOT_BUILD_DIR/src" \
-license-template-file "$COLOBOT_DIR/LICENSE-HEADER.txt" \
{} +
'''
sh '''#!/bin/bash
set -e +x
# Generate HTML report
COLOBOT_LINT_BUILD_DIR="$WORKSPACE/colobot-lint/build"
COLBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml"
HTML_REPORT_DIR="$WORKSPACE/build/lint/html_report"
echo "Generating HTML report"
cd "$COLOBOT_LINT_BUILD_DIR"
rm -rf HtmlReport/
tar -zxf html_report.tar.gz
HtmlReport/generate.py --xml-report "$COLBOT_LINT_REPORT_FILE" --output-dir "$HTML_REPORT_DIR"
'''
script {
retcode = sh script: '''#!/bin/bash
set -e +x
# Update stable/unstable build status
ret=0
COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml"
COLOBOT_LINT_DIR="$WORKSPACE/colobot-lint"
OVERALL_STABLE_RULES=(
"class naming"
"code block placement"
"compile error"
# "compile warning"
# "enum naming"
# "function naming"
"header file not self-contained"
# "implicit bool cast"
# "include style"
# "inconsistent declaration parameter name"
"license header"
# "naked delete"
# "naked new"
# "old style function"
"old-style null pointer"
# "possible forward declaration"
"undefined function"
# "uninitialized field"
# "uninitialized local variable"
# "unused forward declaration"
# "variable naming"
"whitespace"
)
echo "Checking rule stability (overall)"
for ((i = 0; i < ${#OVERALL_STABLE_RULES[@]}; i++)); do
rule="${OVERALL_STABLE_RULES[$i]}"
count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")"
if [ "$count" != "0" ]; then
echo "UNSTABLE RULE: $rule ($count occurences)"
ret=1
fi
done
STABLE_RULES_WITHOUT_CBOT=(
"class naming"
"code block placement"
"compile error"
"compile warning"
# "enum naming"
# "function naming"
"header file not self-contained"
# "implicit bool cast"
"include style"
"inconsistent declaration parameter name"
"license header"
"naked delete"
"naked new"
# "old style function"
"old-style null pointer"
# "possible forward declaration"
"undefined function"
"uninitialized field"
# "uninitialized local variable"
"unused forward declaration"
# "variable naming"
"whitespace"
)
echo "Checking rule stability (without CBOT)"
for ((i = 0; i < ${#STABLE_RULES_WITHOUT_CBOT[@]}; i++)); do
rule="${STABLE_RULES_WITHOUT_CBOT[$i]}"
count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --file-filter="-.*CBot.*" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")"
if [ "$count" != "0" ]; then
echo "UNSTABLE RULE: $rule (without CBOT, $count occurences)"
ret=1
fi
done
exit $ret
''', returnStatus: true
if (retcode != 0) {
currentBuild.result = 'UNSTABLE'
}
}
}
publishCppcheck pattern: 'build/lint/colobot_lint_report.xml'
publishHTML([reportName: 'Colobot-lint HTML report', reportDir: 'build/lint/html_report', reportFiles: 'index.html', reportTitles: '', allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true])
}
}
}
}
if (env.CHANGE_TARGET == 'master') {
error("This pull request targets the wrong branch. Please reopen the pull request targetting the dev branch.")
}
node('master') {
stage('Pull changes') {
checkout scm
}
stage('Build Windows') {
sh 'mkdir -p build/windows'
dir('build/windows') {
sh '''
cmake \
-DCMAKE_INSTALL_PREFIX=/install \
-DCMAKE_TOOLCHAIN_FILE=/opt/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 ../..
make
rm -rf install
DESTDIR=. make install
'''
}
sh 'rm -f windows-debug.zip'
zip zipFile: 'windows-debug.zip', archive: true, dir: 'build/windows/install'
}
stage('Build Linux') {
sh 'mkdir -p build/linux'
dir('build/linux') {
sh '''
cmake \
-DCMAKE_INSTALL_PREFIX=/install -DCOLOBOT_INSTALL_BIN_DIR=/install -DCOLOBOT_INSTALL_LIB_DIR=/install -DCOLOBOT_INSTALL_DATA_DIR=/install/data -DCOLOBOT_INSTALL_I18N_DIR=/install/lang -DCMAKE_SKIP_INSTALL_RPATH=ON \
-DBOOST_STATIC=ON -DGLEW_STATIC=ON -DGLEW_LIBRARY=/usr/lib64/libGLEW.a \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=0 ../..
make
rm -rf install
DESTDIR=. make install
patchelf --set-rpath '.' install/colobot
'''
}
sh 'rm -f linux-debug.zip'
zip zipFile: 'linux-debug.zip', archive: true, dir: 'build/linux/install'
}
stage('Doxygen') {
dir('build/linux') {
sh 'make doc'
}
publishHTML target: [$class: 'HtmlPublisherTarget', reportName: 'Doxygen', reportDir: 'build/linux/doc/html', reportFiles: 'index.html']
}
stage('Run tests') {
dir('build/linux') {
sh './colobot_ut --gtest_output=xml:gtestresults.xml || true'
}
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '0'], [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']], tools: [[$class: 'GoogleTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'build/linux/gtestresults.xml', skipNoTestFiles: false, stopProcessingIfError: true]]])
}
// Clean workspace after building pull requests
// to save disk space on the Jenkins host
if (env.BRANCH_NAME.startsWith('PR-')) {
cleanWs()
}
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -30,6 +30,7 @@ On some Linux distributions there are also distribution packages available:
* Debian Sid (unstable): http://packages.debian.org/sid/colobot
* Arch Linux (AUR): https://aur.archlinux.org/packages/colobot-gold
* openSUSE: http://software.opensuse.org/download.html?project=games&package=colobot
* Fedora: https://src.fedoraproject.org/rpms/colobot
## Compiling and running the game

View File

@ -5,7 +5,7 @@
FIND_PATH(LIBSNDFILE_INCLUDE_DIR sndfile.h)
SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile)
SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile libsndfile-1)
FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES} PATH)
IF(LIBSNDFILE_INCLUDE_DIR AND LIBSNDFILE_LIBRARY)

View File

@ -7,7 +7,7 @@ IF (WIN32)
FIND_PATH( PHYSFS_INCLUDE_PATH physfs.h
DOC "The directory where physfs.h resides")
FIND_LIBRARY( PHYSFS_LIBRARY
NAMES physfs
NAMES physfs physfs-static
PATHS /mingw/lib
DOC "The PhysFS library")
ELSE (WIN32)

2
data

@ -1 +1 @@
Subproject commit bab2d994d3602f70774257d5b2125b41e6aca926
Subproject commit d1c52c9cdb763ed127e89e51b0c921f85d8760b6

View File

@ -70,26 +70,18 @@ if(PLATFORM_GNU)
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications/
)
# Install appdata
install(
FILES info.colobot.Colobot.appdata.xml
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/metainfo/
)
# Install Icon
install(
FILES ${COLOBOT_ICON_FILE}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps/
)
# Translate translatable material
find_program(PO4A po4a)
if(NOT PO4A)
message(WARNING "po4a not found; desktop and manpage files will not be translated")
endif()
if(PO4A)
add_custom_target(desktop_po4a
COMMAND ${PO4A} po4a.cfg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(desktopfile desktop_po4a)
endif()
# Create manpage from pod-formatted file
find_program(POD2MAN pod2man)
if(NOT POD2MAN)
@ -127,11 +119,30 @@ if(PLATFORM_GNU)
# Create the english manpage
podman(PODFILE colobot.pod)
# Translate translatable material
find_program(PO4A po4a)
if(NOT PO4A)
message(WARNING "po4a not found; desktop and manpage files will not be translated")
endif()
if(PO4A)
# Translate the manpage to other languages
add_dependencies(man desktop_po4a)
file(GLOB LINGUAS_PO RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po/ ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po)
string(REGEX REPLACE ".po$" "" LINGUAS ${LINGUAS_PO})
set(PO4A_OUTPUTS)
foreach(LOCALE ${LINGUAS})
list(APPEND PO4A_OUTPUTS ${CMAKE_CURRENT_SOURCE_DIR}/lang/${LOCALE}/colobot.pod)
endforeach()
add_custom_command(
OUTPUT ${PO4A_OUTPUTS}
COMMAND ${PO4A} po4a.cfg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(desktop_po4a DEPENDS ${PO4A_OUTPUTS})
add_dependencies(man desktop_po4a)
add_dependencies(desktopfile desktop_po4a)
foreach(LOCALE ${LINGUAS})
podman(PODFILE lang/${LOCALE}/colobot.pod LOCALE ${LOCALE})
add_dependencies(man${PM_LOCALE} desktop_po4a)
@ -145,7 +156,12 @@ if(PLATFORM_MACOSX)
endif(PLATFORM_MACOSX)
if(PLATFORM_WINDOWS)
set(COLOBOT_VERSION_4COMMAS "${COLOBOT_VERSION_MAJOR},${COLOBOT_VERSION_MINOR},${COLOBOT_VERSION_REVISION},0")
if(COLOBOT_VERSION_REVISION MATCHES "([0-9]+)\\.([0-9]+)")
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1,\\2" COLOBOT_VERSION_REVISION_COMMA "${COLOBOT_VERSION_REVISION}")
set(COLOBOT_VERSION_4COMMAS "${COLOBOT_VERSION_MAJOR},${COLOBOT_VERSION_MINOR},${COLOBOT_VERSION_REVISION_COMMA}")
else()
set(COLOBOT_VERSION_4COMMAS "${COLOBOT_VERSION_MAJOR},${COLOBOT_VERSION_MINOR},${COLOBOT_VERSION_REVISION},0")
endif()
configure_file(colobot.rc.cmake ${CMAKE_CURRENT_BINARY_DIR}/colobot.rc)
endif(PLATFORM_WINDOWS)

View File

@ -1,4 +1,4 @@
Name="Colobot"
GenericName="Game to learn programming"
Comment="Colonize with bots"
Keywords="robots;3d;space;astronaut;java;c++"
Keywords="robots;3d;space;astronaut;java;c++;"

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<component>
<id>info.colobot.Colobot</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0</project_license>
<developer_name>TerranovaTeam</developer_name>
<update_contact>contact@colobot.info</update_contact>
<name>Colobot</name>
<summary>Colonize with bots</summary>
<description>
<p>Colobot (Colonize with Bots) is an educational game aiming to teach programming through entertainment. You are playing as an astronaut on a journey with robot helpers to find a planet for colonization. It features 3D real-time graphics and a C++ and Java-like, object-oriented language, CBOT, which can be used to program the robots available in the game.</p>
</description>
<launchable type="desktop-id">colobot.desktop</launchable>
<screenshots>
<screenshot type="default">
<caption>Alpha 0.1.5</caption>
<image type="source" height="600" width="800">https://colobot.info/wordpress/wp-content/uploads/alpha-0.1.5.png</image>
</screenshot>
</screenshots>
<url type="homepage">https://colobot.info/</url>
<url type="bugtracker">https://github.com/colobot/colobot/issues</url>
<url type="help">http://colobot.info/forum/</url>
<url type="donation">https://colobot.info/donate/</url>
<content_rating type="oars-1.1">
<content_attribute id="violence-cartoon">moderate</content_attribute>
<content_attribute id="violence-fantasy">moderate</content_attribute>
<content_attribute id="violence-bloodshed">mild</content_attribute>
</content_rating>
<releases>
<release date="2018-04-10" version="0.1.11.1"/>
</releases>
</component>

View File

@ -37,7 +37,7 @@ msgstr ""
#. type: Keywords=
#: colobot.ini:4
#, no-wrap
msgid "robots;3d;space;astronaut;java;c++"
msgid "robots;3d;space;astronaut;java;c++;"
msgstr ""
#. type: =head1

View File

@ -3,18 +3,20 @@
# This file is distributed under the same license as the Colobot package.
#
# Didier Raboud <odyx@debian.org>, 2012, 2016.
# B-CE <.>, 2019.
msgid ""
msgstr ""
"Project-Id-Version: colobot 0.1.7\n"
"Project-Id-Version: colobot 0.1.12\n"
"POT-Creation-Date: 2016-03-30 13:45+0200\n"
"PO-Revision-Date: 2016-03-30 13:49+0100\n"
"Last-Translator: Didier Raboud <odyx@debian.org>\n"
"PO-Revision-Date: 2019-06-01 09:43+0200\n"
"Last-Translator: BCE <.>\n"
"Language-Team: French <kde-i18n-doc@kde.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Lokalize 2.0\n"
"X-Generator: Lokalize 18.12.3\n"
#. type: Name=
#: colobot.ini:1
@ -32,13 +34,13 @@ msgstr "Apprentissage de la programmation par le jeu"
#: colobot.ini:3
#, no-wrap
msgid "Colonize with bots"
msgstr "Colonise avec des roBots"
msgstr "COlonise avec des roBOTs"
#. type: Keywords=
#: colobot.ini:4
#, no-wrap
msgid "robots;3d;space;astronaut;java;c++"
msgstr "robots;3d;espace;astronaute;cosmonaute;java;c++"
msgid "robots;3d;space;astronaut;java;c++;"
msgstr "robots;3d;espace;astronaute;cosmonaute;java;c++;programmation;jeux"
#. type: =head1
#: colobot.pod:3
@ -74,12 +76,12 @@ msgid ""
"real-time graphics and a C++ and Java-like, object-oriented language, CBOT, "
"which can be used to program the robots available in the game."
msgstr ""
"Colobot (Colonise avec des roBots) est un jeu éducatif visant à "
"l'enseignement de la programmation par le jeu. Vous jouez un astronaute en "
"Colobot (Colonise avec des roBots) est un jeu éducatif visant "
"à l'enseignement de la programmation par le jeu. Vous jouez un astronaute en "
"voyage avec des robots à la recherche d'une planète à coloniser. Son "
"interface est en trois-dimensions et en temps réel; le language utilisé "
"(CBOT) ressemble au C++ et à Java et peut être utilisé pour programmer les "
"robots disponibles dans le jeu."
"interface est en trois-dimensions et en temps réel. Le langage utilisé "
"(CBOT), orienté objet , ressemble au C++ et à Java. Il peut être utilisé "
"pour programmer les robots disponibles dans le jeu."
#. type: =head1
#: colobot.pod:19
@ -208,9 +210,9 @@ msgid ""
"Enable debug mode (more info printed in logs). Possible values are as "
"follows, as well as any comma-separated combination"
msgstr ""
"Active le mode de I<debug> (plus d'informations dans les logs). Les valeurs"
" possibles sont les suivantes, ainsi que toute combinaison séparée par des"
" virgules"
"Active le mode de I<debug> (plus d'informations dans les logs). "
"Les valeurs possibles sont les suivantes, "
"ainsi que toute combinaison séparée par des virgules"
#. type: =item
#: colobot.pod:81
@ -260,7 +262,7 @@ msgstr "models"
#. type: textblock
#: colobot.pod:99
msgid "Models-related debugging"
msgstr "Debug pour les modèles"
msgstr "Débug pour les modèles"
#. type: =item
#: colobot.pod:101
@ -270,7 +272,7 @@ msgstr "all"
#. type: textblock
#: colobot.pod:103
msgid "All above debugging statements"
msgstr "Tout les messages de debug ci-dessus"
msgstr "Tous les messages de debug ci-dessus"
#. type: =item
#: colobot.pod:107
@ -280,9 +282,7 @@ msgstr "B<-headless>"
#. type: textblock
#: colobot.pod:109
msgid "Run in headless mode - disables graphics, sound and user interaction"
msgstr ""
"Lance en mode I<headless> - désactive les graphiques, sons et interactions"
" utilisateurs"
msgstr "Lance en mode I<headless> - désactive les graphiques, sons et interactions utilisateurs"
#. type: =item
#: colobot.pod:111
@ -292,7 +292,7 @@ msgstr "B<-runscene> I<scenecodename>"
#. type: textblock
#: colobot.pod:113
msgid "Run given scene on start (skip menus)"
msgstr "Lance une scène donnée au lancement (saute les menus)"
msgstr "Démarre directement une scène (saute les menus)"
#. type: =item
#: colobot.pod:115
@ -317,7 +317,7 @@ msgstr "LC_MESSAGES"
#. type: textblock
#: colobot.pod:127
msgid "Used to determine the runtime language."
msgstr "Utilisé pour déterminer la langue au lancement"
msgstr "Utilisé pour déterminer la langue au lancement."
#. type: =head1
#: colobot.pod:131

View File

@ -266,6 +266,10 @@ msgstr ""
msgid "The battle has ended"
msgstr ""
#, c-format
msgid "Time: %s"
msgstr ""
#, c-format
msgid "%s: %d pts"
msgstr ""
@ -447,6 +451,9 @@ msgstr ""
msgid "Shadow resolution\\Higher means better range and quality, but slower"
msgstr ""
msgid "Vertical Synchronization\\Limits the number of frames per second to display frequency"
msgstr ""
msgid "Standard controls\\Standard key functions"
msgstr ""
@ -810,6 +817,18 @@ msgstr ""
msgid "Build a legged sniffer"
msgstr ""
msgid "Build a winged builder"
msgstr ""
msgid "Build a tracked builder"
msgstr ""
msgid "Build a wheeled builder"
msgstr ""
msgid "Build a legged builder"
msgstr ""
msgid "Build a thumper"
msgstr ""
@ -825,6 +844,9 @@ msgstr ""
msgid "Build a subber"
msgstr ""
msgid "Build a target bot"
msgstr ""
msgid "Run research program for tracked bots"
msgstr ""
@ -855,6 +877,12 @@ msgstr ""
msgid "Run research program for orga shooter"
msgstr ""
msgid "Run research program for builder"
msgstr ""
msgid "Run research program for target bot"
msgstr ""
msgid "Return to start"
msgstr ""
@ -870,6 +898,9 @@ msgstr ""
msgid "Explode (\\key action;)"
msgstr ""
msgid "Build (\\key action;)"
msgstr ""
msgid "Recycle (\\key action;)"
msgstr ""
@ -1248,6 +1279,18 @@ msgstr ""
msgid "Legged grabber"
msgstr ""
msgid "Winged builder"
msgstr ""
msgid "Tracked builder"
msgstr ""
msgid "Wheeled builder"
msgstr ""
msgid "Legged builder"
msgstr ""
msgid "Winged shooter"
msgstr ""
@ -1464,7 +1507,7 @@ msgstr ""
msgid "Nothing to analyze"
msgstr ""
msgid "Analyzes only organic matter"
msgid "Inappropriate sample"
msgstr ""
msgid "Analysis already performed"
@ -1563,6 +1606,9 @@ msgstr ""
msgid "Plans for nuclear power plant available"
msgstr ""
msgid "Plans for builder available"
msgstr ""
msgid "New bot available"
msgstr ""
@ -1788,6 +1834,12 @@ msgstr ""
msgid "Invalid universal character name"
msgstr ""
msgid "Empty character constant"
msgstr ""
msgid "Duplicate label in switch"
msgstr ""
msgid "Dividing by zero"
msgstr ""

1872
po/cs.po Normal file

File diff suppressed because it is too large Load Diff

View File

@ -490,6 +490,9 @@ msgstr "Sinkt (\\key gdown;)"
msgid "Drawer bot"
msgstr "Zeichner"
msgid "Duplicate label in switch"
msgstr ""
msgid "Dust\\Dust and dirt on bots and buildings"
msgstr "Schmutz\\Schmutz auf Robotern und Bauten"
@ -508,6 +511,9 @@ msgstr "Gewähltes Programm bearbeiten"
msgid "Egg"
msgstr "Ei"
msgid "Empty character constant"
msgstr ""
msgid "End of block missing"
msgstr "Es fehlt eine geschlossene geschweifte Klammer \"}\" (Ende des Blocks)"
@ -1563,6 +1569,10 @@ msgstr "Stampfen (\\key action;)"
msgid "Thumper"
msgstr "Stampfer"
#, c-format
msgid "Time: %s"
msgstr ""
msgid "Titanium"
msgstr "Titan"
@ -1677,6 +1687,9 @@ msgstr "Der Wert dieser Variable wurde nicht definiert"
msgid "Vault"
msgstr "Bunker"
msgid "Vertical Synchronization\\Limits the number of frames per second to display frequency"
msgstr ""
msgid "Violet flag"
msgstr "Violette Fahne"

400
po/fr.po

File diff suppressed because it is too large Load Diff

View File

@ -365,7 +365,7 @@ msgid "Checkpoint"
msgstr "Punkt kontrolny"
msgid "Class name expected"
msgstr ""
msgstr "Oczekiwano nazwy klasy"
msgid "Climb\\Increases the power of the jet"
msgstr "W górę\\Zwiększa moc silnika"
@ -488,6 +488,9 @@ msgstr "Dół (\\key gdown;)"
msgid "Drawer bot"
msgstr "Robot rysownik"
msgid "Duplicate label in switch"
msgstr ""
msgid "Dust\\Dust and dirt on bots and buildings"
msgstr "Kurz\\Kurz i bród na robotach i budynkach"
@ -506,6 +509,9 @@ msgstr "Edytuj zaznaczony program"
msgid "Egg"
msgstr "Jajo"
msgid "Empty character constant"
msgstr ""
msgid "End of block missing"
msgstr "Brak końca bloku"
@ -628,7 +634,7 @@ msgid "Function name missing"
msgstr "Brakująca nazwa funkcji"
msgid "Function needs return type \"void\""
msgstr ""
msgstr "Funkcja potrzebuje typu zwracanego \"void\""
msgid "Game speed"
msgstr "Prędkość gry"
@ -679,7 +685,7 @@ msgid "Help balloons\\Explain the function of the buttons"
msgstr "Dymki pomocy\\Wyjaśnia funkcje przycisków"
msgid "Hex value out of range"
msgstr ""
msgstr "Wartość heksadecymalna poza zakresem"
msgid "Higher speed\\Doubles speed"
msgstr "Zwiększ prędkość\\Podwaja prędkość"
@ -859,10 +865,10 @@ msgid "Mipmap level\\Mipmap level"
msgstr "Poziom mipmap\\Poziom mipmap"
msgid "Missing end quote"
msgstr ""
msgstr "Brak cudzysłowu zamykającego"
msgid "Missing hex digits after escape sequence"
msgstr ""
msgstr "Brak cyfr heksadecymalnych po znaku ucieczki"
msgid "Mission name"
msgstr "Nazwa misji"
@ -964,7 +970,7 @@ msgid "No userlevels installed!"
msgstr "Brak zainstalowanych poziomów użytkownika!"
msgid "Non-void function needs \"return;\""
msgstr ""
msgstr "Funkcja zwracająca typ inny, niż \"void\", wymaga \"return;\""
msgid "Normal size"
msgstr "Normalna wielkość"
@ -1027,7 +1033,7 @@ msgid "Object too close"
msgstr "Obiekt za blisko"
msgid "Octal value out of range"
msgstr ""
msgstr "Wartość ósemkowa poza zakresem"
msgid "One step"
msgstr "Jeden krok"
@ -1072,7 +1078,7 @@ msgid "Paste (Ctrl+V)"
msgstr "Wklej (Ctrl+V)"
msgid "Pause blur\\Blur the background on the pause screen"
msgstr ""
msgstr "Rozmyta pauza\\Rozmyj tło na ekranie pauzy"
msgid "Pause in background\\Pause the game when the window is unfocused"
msgstr "Wstrzymaj w tle\\Wstrzymaj grę gdy okno stanie się nieaktywne"
@ -1534,7 +1540,7 @@ msgid "This object is not a member of a class"
msgstr "Ten obiekt nie jest członkiem klasy"
msgid "This parameter needs a default value"
msgstr ""
msgstr "Ten parametr wymaga podania domyślnej wartości"
msgid "This program is read-only, clone it to edit"
msgstr "Ten program jest tylko do odczytu, skopiuj go, aby edytować"
@ -1545,6 +1551,10 @@ msgstr "Uderz (\\key action;)"
msgid "Thumper"
msgstr "Uderzacz"
#, c-format
msgid "Time: %s"
msgstr "Czas: %s"
msgid "Titanium"
msgstr "Tytan"
@ -1659,6 +1669,9 @@ msgstr "Zmienna nie została zainicjalizowana"
msgid "Vault"
msgstr "Skrytka"
msgid "Vertical Synchronization\\Limits the number of frames per second to display frequency"
msgstr "Synchronizacja pionowa\\Ogranicza ilość klatek na sekundę do wartości odświeżania ekranu"
msgid "Violet flag"
msgstr "Fioletowa flaga"

2055
po/pt.po Normal file

File diff suppressed because it is too large Load Diff

View File

@ -496,6 +496,9 @@ msgstr "Вниз (\\key gdown;)"
msgid "Drawer bot"
msgstr "Рисовальщик"
msgid "Duplicate label in switch"
msgstr ""
msgid "Dust\\Dust and dirt on bots and buildings"
msgstr "Пыль\\Пыль и грязь на ботах и зданиях"
@ -514,6 +517,9 @@ msgstr "Изменить выбранную программу"
msgid "Egg"
msgstr "Яйцо"
msgid "Empty character constant"
msgstr ""
msgid "End of block missing"
msgstr "Отсутствует конец блока"
@ -1576,6 +1582,10 @@ msgstr "Удар (\\key action;)"
msgid "Thumper"
msgstr "Ударник"
#, c-format
msgid "Time: %s"
msgstr ""
msgid "Titanium"
msgstr "Титан"
@ -1690,6 +1700,9 @@ msgstr "Переменная не инициализирована"
msgid "Vault"
msgstr "Хранилище"
msgid "Vertical Synchronization\\Limits the number of frames per second to display frequency"
msgstr ""
msgid "Violet flag"
msgstr "Фиолетовый флаг"

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -36,7 +36,6 @@
#include "CBot/CBotCStack.h"
#include "CBot/CBotDefParam.h"
#include "CBot/CBotUtils.h"
#include "CBot/CBotFileUtils.h"
#include <algorithm>
@ -192,7 +191,7 @@ bool CBotClass::AddItem(CBotVar* pVar)
}
////////////////////////////////////////////////////////////////////////////////
std::string CBotClass::GetName()
const std::string& CBotClass::GetName()
{
return m_name;
}
@ -364,69 +363,70 @@ void CBotClass::RestoreMethode(long& nIdent,
}
////////////////////////////////////////////////////////////////////////////////
bool CBotClass::SaveStaticState(FILE* pf)
bool CBotClass::SaveStaticState(std::ostream &ostr)
{
if (!WriteWord( pf, CBOTVERSION*2)) return false;
if (!WriteLong(ostr, CBOTVERSION*2)) return false;
// saves the state of static variables in classes
for (CBotClass* p : m_publicClasses)
{
if (!WriteWord( pf, 1 )) return false;
if (!WriteWord(ostr, 1)) return false;
// save the name of the class
if (!WriteString( pf, p->GetName() )) return false;
if (!WriteString(ostr, p->GetName())) return false;
CBotVar* pv = p->GetVar();
while( pv != nullptr )
{
if ( pv->IsStatic() )
{
if (!WriteWord( pf, 1 )) return false;
if (!WriteString( pf, pv->GetName() )) return false;
if (!WriteWord(ostr, 1)) return false;
if (!WriteString(ostr, pv->GetName())) return false;
if ( !pv->Save0State(pf) ) return false; // common header
if ( !pv->Save1State(pf) ) return false; // saves as the child class
if ( !WriteWord( pf, 0 ) ) return false;
if (!pv->Save0State(ostr)) return false; // common header
if (!pv->Save1State(ostr)) return false; // saves as the child class
if (!WriteWord(ostr, 0)) return false;
}
pv = pv->GetNext();
}
if (!WriteWord( pf, 0 )) return false;
if (!WriteWord(ostr, 0)) return false;
}
if (!WriteWord( pf, 0 )) return false;
if (!WriteWord(ostr, 0)) return false;
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool CBotClass::RestoreStaticState(FILE* pf)
bool CBotClass::RestoreStaticState(std::istream &istr)
{
std::string ClassName, VarName;
CBotClass* pClass;
unsigned short w;
if (!ReadWord( pf, w )) return false;
if ( w != CBOTVERSION*2 ) return false;
long version;
if (!ReadLong(istr, version)) return false;
if (version != CBOTVERSION*2) return false;
while (true)
{
if (!ReadWord( pf, w )) return false;
if (!ReadWord(istr, w)) return false;
if ( w == 0 ) return true;
if (!ReadString( pf, ClassName )) return false;
if (!ReadString(istr, ClassName)) return false;
pClass = Find(ClassName);
while (true)
{
if (!ReadWord( pf, w )) return false;
if (!ReadWord(istr, w)) return false;
if ( w == 0 ) break;
CBotVar* pVar = nullptr;
CBotVar* pv = nullptr;
if (!ReadString( pf, VarName )) return false;
if (!ReadString(istr, VarName)) return false;
if ( pClass != nullptr ) pVar = pClass->GetItem(VarName);
if (!CBotVar::RestoreState(pf, pv)) return false; // the temp variable
if (!CBotVar::RestoreState(istr, pv)) return false; // the temp variable
if ( pVar != nullptr ) pVar->Copy(pv);
delete pv;

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -173,7 +173,7 @@ public:
* \brief GetName Gives the name of the class.
* \return
*/
std::string GetName();
const std::string& GetName();
/*!
* \brief GetParent Gives the parent class (or nullptr).
@ -331,18 +331,18 @@ public:
static void ClearPublic();
/*!
* \brief SaveStaticState
* \param pf
* \return
* \brief Save all static variables from each public class
* \param ostr Output stream
* \return true on success
*/
static bool SaveStaticState(FILE* pf);
static bool SaveStaticState(std::ostream &ostr);
/*!
* \brief RestoreStaticState
* \param pf
* \return
* \brief Restore all static variables in each public class
* \param istr Input stream
* \return true on success
*/
static bool RestoreStaticState(FILE* pf);
static bool RestoreStaticState(std::istream &istr);
/**
* \brief Request a lock on this class (for "synchronized" keyword)

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -23,6 +23,7 @@
#include "CBot/CBotInstr/CBotFunction.h"
#include "CBot/CBotInstr/CBotInstrCall.h"
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -173,14 +173,34 @@ bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj)
{
switch (p->m_type.GetType())
{
case CBotTypByte:
newvar->SetValByte(pVar->GetValByte());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypShort:
newvar->SetValShort(pVar->GetValShort());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypChar:
newvar->SetValChar(pVar->GetValChar());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypInt:
newvar->SetValInt(pVar->GetValInt());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypLong:
newvar->SetValLong(pVar->GetValLong());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypFloat:
newvar->SetValFloat(pVar->GetValFloat());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypDouble:
newvar->SetValDouble(pVar->GetValDouble());
newvar->SetInit(pVar->GetInit()); // copy nan
break;
case CBotTypString:
newvar->SetValString(pVar->GetValString());
break;

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -35,13 +35,13 @@ namespace CBot
enum CBotType
{
CBotTypVoid = 0, //!< void
CBotTypByte = 1, //!< byte (NOT IMPLEMENTED)
CBotTypShort = 2, //!< short (NOT IMPLEMENTED)
CBotTypChar = 3, //!< char (NOT IMPLEMENTED)
CBotTypByte = 1, //!< byte
CBotTypShort = 2, //!< short
CBotTypChar = 3, //!< char
CBotTypInt = 4, //!< int
CBotTypLong = 5, //!< long (NOT IMPLEMENTED)
CBotTypLong = 5, //!< long
CBotTypFloat = 6, //!< float
CBotTypDouble = 7, //!< double (NOT IMPLEMENTED)
CBotTypDouble = 7, //!< double
CBotTypBoolean = 8, //!< bool
CBotTypString = 9, //!< string
@ -106,6 +106,11 @@ enum TokenId
ID_STRING,
ID_VOID,
ID_BOOL,
ID_BYTE,
ID_SHORT,
ID_CHAR,
ID_LONG,
ID_DOUBLE,
TokenKeyVal = 2200, //!< keywords that represent values (true, false, null, nan)
ID_TRUE = 2200,
@ -177,7 +182,8 @@ enum TokenType
TokenTypNum = 2, //!< number
TokenTypString = 3, //!< string
TokenTypVar = 4, //!< a variable name
TokenTypDef = 5 //!< value according DefineNum
TokenTypDef = 5, //!< value according DefineNum
TokenTypChar = 6, //!< character literal
};
/**
@ -247,6 +253,8 @@ enum CBotError : int
CBotErrHexDigits = 5052, //!< missing hex digits after escape sequence
CBotErrHexRange = 5053, //!< hex value out of range
CBotErrUnicodeName = 5054, //!< invalid universal character name
CBotErrCharEmpty = 5055, //!< empty character constant
CBotErrRedefCase = 5056, //!< duplicate label in switch
// Runtime errors
CBotErrZeroDiv = 6000, //!< division by zero

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -21,129 +21,285 @@
#include "CBot/CBotClass.h"
#include "CBot/CBotEnums.h"
#include "CBot/CBotUtils.h"
namespace CBot
{
// file management
// necessary because it is not possible to do the fopen in the main program
// fwrite and fread in a dll or using the FILE * returned.
////////////////////////////////////////////////////////////////////////////////
FILE* fOpen(const char* name, const char* mode)
template<typename T>
static bool WriteBinary(std::ostream &ostr, T value, unsigned padTo = 0)
{
return fopen(name, mode);
}
////////////////////////////////////////////////////////////////////////////////
int fClose(FILE* filehandle)
{
return fclose(filehandle);
}
////////////////////////////////////////////////////////////////////////////////
std::size_t fWrite(const void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle)
{
return fwrite(buffer, elemsize, length, filehandle);
}
////////////////////////////////////////////////////////////////////////////////
std::size_t fRead(void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle)
{
return fread(buffer, elemsize, length, filehandle);
}
////////////////////////////////////////////////////////////////////////////////
bool ReadWord(FILE* pf, unsigned short& w)
{
size_t lg;
lg = fread(&w, sizeof( unsigned short ), 1, pf );
return (lg == 1);
}
////////////////////////////////////////////////////////////////////////////////
bool ReadFloat(FILE* pf, float& w)
{
size_t lg;
lg = fread(&w, sizeof( float ), 1, pf );
return (lg == 1);
}
////////////////////////////////////////////////////////////////////////////////
bool WriteLong(FILE* pf, long w)
{
size_t lg;
lg = fwrite(&w, sizeof( long ), 1, pf );
return (lg == 1);
}
////////////////////////////////////////////////////////////////////////////////
bool ReadLong(FILE* pf, long& w)
{
size_t lg;
lg = fread(&w, sizeof( long ), 1, pf );
return (lg == 1);
}
////////////////////////////////////////////////////////////////////////////////
bool ReadString(FILE* pf, std::string& s)
{
unsigned short w;
char buf[1000];
size_t lg1, lg2;
if (!ReadWord(pf, w)) return false;
lg1 = w;
lg2 = fread(buf, 1, lg1, pf );
buf[lg2] = 0;
s = buf;
return (lg1 == lg2);
}
////////////////////////////////////////////////////////////////////////////////
bool WriteType(FILE* pf, const CBotTypResult &type)
{
int typ = type.GetType();
if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
if ( !WriteWord(pf, typ) ) return false;
if ( typ == CBotTypClass )
unsigned char chr;
unsigned count = 1;
while (value > 127) // unsigned LEB128
{
CBotClass* p = type.GetClass();
if ( !WriteString(pf, p->GetName()) ) return false;
++count;
chr = (value & 0x7F) | 0x80;
if (!ostr.write(reinterpret_cast<char*>(&chr), 1)) return false;
value >>= 7;
}
if ( type.Eq( CBotTypArrayBody ) ||
type.Eq( CBotTypArrayPointer ) )
chr = value & 0x7F;
if (count < padTo) chr |= 0x80;
if (!ostr.write(reinterpret_cast<char*>(&chr), 1)) return false;
if (count < padTo)
{
if ( !WriteWord(pf, type.GetLimite()) ) return false;
if ( !WriteType(pf, type.GetTypElem()) ) return false;
while (++count < padTo)
if (!(ostr << '\x80')) return false;
if (!(ostr << '\x00')) return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool ReadType(FILE* pf, CBotTypResult &type)
template<typename T>
static bool ReadBinary(std::istream &istr, T &value)
{
value = 0;
unsigned char chr;
unsigned shift = 0;
while (true) // unsigned LEB128
{
if (!istr.read(reinterpret_cast<char*>(&chr), 1)) return false;
if (shift < sizeof(T) * 8 - 1)
value |= static_cast<T>(chr & 0x7F) << shift;
shift += 7;
if ((chr & 0x80) == 0) break;
}
return true;
}
template<typename T>
static bool WriteSignedBinary(std::ostream &ostr, T value, unsigned padTo = 0)
{
signed char sign = value >> (8 * sizeof(T) - 1);
unsigned count = 0;
while (true) // signed LEB128
{
++count;
unsigned char chr = value & 0x7F;
value >>= 7;
if (!(value != sign || ((chr ^ sign) & 0x40) != 0))
{
if (count < padTo) chr |= 0x80;
if (!ostr.write(reinterpret_cast<char*>(&chr), 1)) return false;
break;
}
chr |= 0x80;
if (!ostr.put(chr)) return false;
}
if (count < padTo)
{
char chr = (sign < 0) ? 0x7F : 0x00;
while (++count < padTo)
if (!ostr.put(chr | 0x80)) return false;
if (!ostr.put(chr)) return false;
}
return true;
}
template<typename T>
static bool ReadSignedBinary(std::istream &istr, T &value)
{
value = 0;
unsigned char chr;
unsigned shift = 0;
while (true) // signed LEB128
{
if (!istr.read(reinterpret_cast<char*>(&chr), 1)) return false;
if (shift < sizeof(T) * 8 - 1)
value |= (static_cast<T>(chr & 0x7F) << shift);
shift += 7;
if ((chr & 0x80) == 0) break;
}
if (shift >= 8 * sizeof(T) - 1) shift = 8 * sizeof(T) - 1;
if ((chr & 0x40) != 0)
value |= static_cast<T>(-1) << shift;
return true;
}
bool WriteWord(std::ostream &ostr, unsigned short w)
{
return WriteBinary<unsigned short>(ostr, w);
}
bool ReadWord(std::istream &istr, unsigned short &w)
{
return ReadBinary<unsigned short>(istr, w);
}
bool WriteByte(std::ostream &ostr, char c)
{
if (!ostr.put(c)) return false;
return true;
}
bool ReadByte(std::istream &istr, char& c)
{
if (!istr.get(c)) return false;
return true;
}
bool WriteShort(std::ostream &ostr, short s)
{
return WriteSignedBinary<short>(ostr, s);
}
bool ReadShort(std::istream &istr, short &s)
{
return ReadSignedBinary<short>(istr, s);
}
bool WriteUInt32(std::ostream &ostr, uint32_t i)
{
return WriteBinary<uint32_t>(ostr, i);
}
bool ReadUInt32(std::istream &istr, uint32_t &i)
{
return ReadBinary<uint32_t>(istr, i);
}
bool WriteInt(std::ostream &ostr, int i)
{
return WriteSignedBinary<int>(ostr, i);
}
bool ReadInt(std::istream &istr, int &i)
{
return ReadSignedBinary<int>(istr, i);
}
bool WriteLong(std::ostream &ostr, long l, unsigned padTo)
{
return WriteSignedBinary<long>(ostr, l, padTo);
}
bool ReadLong(std::istream &istr, long &l)
{
return ReadSignedBinary<long>(istr, l);
}
bool WriteFloat(std::ostream &ostr, float f)
{
union TypeConverter
{
float fValue;
unsigned int iValue;
};
TypeConverter u;
u.fValue = 0.0f;
u.iValue = 0;
u.fValue = f;
return WriteBinary<unsigned int>(ostr, u.iValue);
}
bool ReadFloat(std::istream &istr, float &f)
{
union TypeConverter
{
float fValue;
unsigned int iValue;
};
TypeConverter u;
u.fValue = 0.0f;
u.iValue = 0;
if (!ReadBinary<unsigned int>(istr, u.iValue)) return false;
f = u.fValue;
return true;
}
bool WriteDouble(std::ostream &ostr, double d)
{
union TypeConverter
{
double dValue;
unsigned long iValue;
};
TypeConverter u;
u.dValue = 0.0;
u.iValue = 0;
u.dValue = d;
return WriteBinary<unsigned long>(ostr, u.iValue);
}
bool ReadDouble(std::istream &istr, double &d)
{
union TypeConverter
{
double dValue;
unsigned long iValue;
};
TypeConverter u;
u.dValue = 0.0;
u.iValue = 0;
if (!ReadBinary<unsigned long>(istr, u.iValue)) return false;
d = u.dValue;
return true;
}
bool WriteString(std::ostream &ostr, const std::string &s)
{
if (!WriteBinary<size_t>(ostr, s.size())) return false;
if (!ostr.write(&(s[0]), s.size())) return false;
return true;
}
bool ReadString(std::istream &istr, std::string &s)
{
size_t length = 0;
if (!ReadBinary<size_t>(istr, length)) return false;
s.resize(length);
if (length != 0)
{
if (!istr.read(&(s[0]), length)) return false;
}
return true;
}
bool WriteType(std::ostream &ostr, const CBotTypResult &type)
{
int typ = type.GetType();
if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
if ( !WriteWord(ostr, typ) ) return false;
if ( typ == CBotTypClass )
{
CBotClass* p = type.GetClass();
if (!WriteString(ostr, p->GetName())) return false;
}
if ( type.Eq( CBotTypArrayBody ) ||
type.Eq( CBotTypArrayPointer ) )
{
if (!WriteWord(ostr, type.GetLimite())) return false;
if (!WriteType(ostr, type.GetTypElem())) return false;
}
if ( type.Eq(CBotTypPointer) )
{
if (type.GetClass() != nullptr)
{
if (!WriteString(ostr, type.GetClass()->GetName())) return false;
}
else if (!WriteString(ostr, "")) return false;
}
return true;
}
bool ReadType(std::istream &istr, CBotTypResult &type)
{
unsigned short w, ww;
if ( !ReadWord(pf, w) ) return false;
if (!ReadWord(istr, w)) return false;
type.SetType(w);
if ( type.Eq( CBotTypIntrinsic ) )
@ -154,7 +310,7 @@ bool ReadType(FILE* pf, CBotTypResult &type)
if ( type.Eq( CBotTypClass ) )
{
std::string s;
if ( !ReadString(pf, s) ) return false;
if (!ReadString(istr, s)) return false;
type = CBotTypResult( w, s );
}
@ -162,11 +318,45 @@ bool ReadType(FILE* pf, CBotTypResult &type)
type.Eq( CBotTypArrayBody ) )
{
CBotTypResult r;
if ( !ReadWord(pf, ww) ) return false;
if ( !ReadType(pf, r) ) return false;
if (!ReadWord(istr, ww)) return false;
if (!ReadType(istr, r)) return false;
type = CBotTypResult( w, r );
type.SetLimite(static_cast<short>(ww));
}
if ( type.Eq(CBotTypPointer) )
{
std::string className;
if (!ReadString(istr, className)) return false;
type = CBotTypResult(w, className);
}
return true;
}
bool WriteStream(std::ostream &ostr, std::istream& istr)
{
if (!istr.seekg(0, istr.end)) return false;
auto size = istr.tellg();
if (size == 0) return WriteLong(ostr, 0);
if (!WriteLong(ostr, size)) return false;
if (!istr.seekg(0, istr.beg)) return false;
if (!(ostr << istr.rdbuf())) return false;
return true;
}
bool ReadStream(std::istream& istr, std::ostream &ostr)
{
long length;
if (!ReadLong(istr, length)) return false;
if (length == 0) return true;
while (length-- > 0)
{
if (!(ostr << istr.get())) return false;
}
return true;
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -19,7 +19,7 @@
#pragma once
#include <cstdio>
#include <iostream>
#include <string>
namespace CBot
@ -28,128 +28,189 @@ namespace CBot
class CBotVar;
class CBotTypResult;
///////////////////////////////////////////////////////////////////////////////
// routines for file management (* FILE)
/*!
* \brief fOpen
* \param name
* \param mode
* \return
* \brief Save a linked list if variables
* \param ostr Output stream
* \param pVar First variable in the list
* \return true on success
*/
FILE* fOpen(const char* name, const char* mode);
/*!
* \brief fClose
* \param filehandle
* \return
*/
int fClose(FILE* filehandle);
/*!
* \brief fWrite
* \param buffer
* \param elemsize
* \param length
* \param filehandle
* \return
*/
std::size_t fWrite(const void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle);
/*!
* \brief fRead
* \param buffer
* \param elemsize
* \param length
* \param filehandle
* \return
*/
std::size_t fRead(void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle);
/*!
* \brief SaveVars
* \param pf
* \param pVar
* \return
*/
bool SaveVars(FILE* pf, CBotVar* pVar);
bool SaveVars(std::ostream &ostr, CBotVar* pVar);
/*!
* \brief WriteWord
* \param pf
* \param ostr Output stream
* \param w
* \return
* \return true on success
*/
bool WriteWord(FILE* pf, unsigned short w);
bool WriteWord(std::ostream &ostr, unsigned short w);
/*!
* \brief ReadWord
* \param pf
* \param w
* \return
* \param istr Input stream
* \param[out] w
* \return true on success
*/
bool ReadWord(FILE* pf, unsigned short& w);
bool ReadWord(std::istream &istr, unsigned short &w);
/*!
* \brief ReadLong
* \param pf
* \param w
* \return
* \brief WriteByte
* \param ostr Output stream
* \param c
* \return true on success
*/
bool ReadLong(FILE* pf, long& w);
bool WriteByte(std::ostream &ostr, char c);
/*!
* \brief WriteFloat
* \param pf
* \param w
* \return
* \brief ReadByte
* \param istr Input stream
* \param[out] c
* \return true on success
*/
bool WriteFloat(FILE* pf, float w);
bool ReadByte(std::istream &istr, char& c);
/*!
* \brief WriteShort
* \param ostr Output stream
* \param s
* \return true on success
*/
bool WriteShort(std::ostream &ostr, short s);
/*!
* \brief ReadShort
* \param istr Input stream
* \param[out] s
* \return true on success
*/
bool ReadShort(std::istream &istr, short &s);
/*!
* \brief WriteUInt32
* \param ostr Output stream
* \param i
* \return true on success
*/
bool WriteUInt32(std::ostream &ostr, uint32_t i);
/*!
* \brief ReadUInt32
* \param istr Input stream
* \param[out] i
* \return true on success
*/
bool ReadUInt32(std::istream &istr, uint32_t &i);
/*!
* \brief WriteInt
* \param ostr Output stream
* \param i
* \return true on success
*/
bool WriteInt(std::ostream &ostr, int i);
/*!
* \brief ReadInt
* \param istr Input stream
* \param[out] i
* \return true on success
*/
bool ReadInt(std::istream &istr, int &i);
/*!
* \brief WriteLong
* \param pf
* \param w
* \return
* \param ostr Output stream
* \param l
* \param padTo minimum number of bytes to write
* \return true on success
*/
bool WriteLong(FILE* pf, long w);
bool WriteLong(std::ostream &ostr, long l, unsigned padTo = 0);
/*!
* \brief ReadLong
* \param istr Input stream
* \param[out] l
* \return true on success
*/
bool ReadLong(std::istream &istr, long &l);
/*!
* \brief WriteFloat
* \param ostr Output stream
* \param f
* \return true on success
*/
bool WriteFloat(std::ostream &ostr, float f);
/*!
* \brief ReadFloat
* \param pf
* \param w
* \return
* \param istr Input stream
* \param[out] f
* \return true on success
*/
bool ReadFloat(FILE* pf, float& w);
bool ReadFloat(std::istream &istr, float &f);
/*!
* \brief WriteDouble
* \param ostr Output stream
* \param d
* \return true on success
*/
bool WriteDouble(std::ostream &ostr, double d);
/*!
* \brief ReadDouble
* \param istr Input stream
* \param[out] d
* \return true on success
*/
bool ReadDouble(std::istream &istr, double &d);
/*!
* \brief WriteString
* \param ostr Output stream
* \param s
* \return true on success
*/
bool WriteString(std::ostream &ostr, const std::string &s);
/*!
* \brief ReadString
* \param pf
* \param s
* \return
* \param istr Input stream
* \param[out] s
* \return true on success
*/
bool ReadString(FILE* pf, std::string& s);
bool ReadString(std::istream &istr, std::string &s);
/*!
* \brief WriteType
* \param pf
* \param ostr Output stream
* \param type
* \return
* \return true on success
*/
bool WriteType(FILE* pf, const CBotTypResult &type);
bool WriteType(std::ostream &ostr, const CBotTypResult &type);
/*!
* \brief ReadType
* \param pf
* \param type
* \return
* \param istr Input stream
* \param[out] type
* \return true on success
*/
bool ReadType(FILE* pf, CBotTypResult &type);
bool ReadType(std::istream &istr, CBotTypResult &type);
/*!
* \brief WriteStream
* \param ostr Output stream
* \param istr Input stream
* \return true on success
*/
bool WriteStream(std::ostream &ostr, std::istream& istr);
/*!
* \brief ReadStream
* \param istr Input stream
* \param ostr Output stream
* \return true on success
*/
bool ReadStream(std::istream& istr, std::ostream &ostr);
} // namespace CBot

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -19,7 +19,7 @@
#include "CBot/CBotInstr/CBotCase.h"
#include "CBot/CBotInstr/CBotExprLitNum.h"
#include "CBot/CBotInstr/CBotTwoOpExpr.h"
#include "CBot/CBotStack.h"
#include "CBot/CBotCStack.h"
@ -30,69 +30,107 @@ namespace CBot
////////////////////////////////////////////////////////////////////////////////
CBotCase::CBotCase()
{
m_value = nullptr;
m_instr = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
CBotCase::~CBotCase()
{
delete m_value;
delete m_instr;
}
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack, std::unordered_map<long, CBotInstr*>& labels)
{
CBotCase* inst = new CBotCase(); // creates the object
CBotToken* pp = p; // preserves at the ^ token (starting position)
inst->SetToken(p);
if (!IsOfType(p, ID_CASE, ID_DEFAULT)) return nullptr; // should never happen
pStack->SetStartError(pp->GetStart());
if ( pp->GetType() == ID_CASE )
long labelValue = 0;
if (pp->GetType() == ID_CASE)
{
pp = p;
inst->m_value = CBotExprLitNum::Compile(p, pStack);
if (inst->m_value == nullptr )
CBotInstr* i = nullptr;
if (nullptr != (i = CBotTwoOpExpr::Compile(p, pStack, nullptr, true)))
{
pStack->SetError( CBotErrBadNum, pp );
delete inst;
return nullptr;
if (pStack->GetType() <= CBotTypLong)
{
CBotStack* pile = CBotStack::AllocateStack();
while ( !i->Execute(pile) );
labelValue = pile->GetVar()->GetValLong();
pile->Delete();
if (labels.count(labelValue) > 0)
{
pStack->SetError(CBotErrRedefCase, p->GetStart());
}
}
else
pStack->SetError(CBotErrBadNum, p->GetStart());
delete i;
}
}
if ( !IsOfType( p, ID_DOTS ))
{
pStack->SetError( CBotErrNoDoubleDots, p->GetStart() );
delete inst;
return nullptr;
else
pStack->SetError(CBotErrBadNum, p->GetStart());
}
return inst;
if (pStack->IsOk() && IsOfType(p, ID_DOTS))
{
CBotCase* newCase = new CBotCase();
newCase->SetToken(pp);
if (pp->GetType() == ID_CASE)
labels[labelValue] = newCase;
return newCase;
}
pStack->SetError(CBotErrNoDoubleDots, p->GetStart());
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
bool CBotCase::Execute(CBotStack* &pj)
{
return true; // the "case" statement does nothing!
if (m_instr == nullptr) return true;
CBotStack* pile = pj->AddStack(this, CBotStack::BlockVisibilityType::BLOCK);
int state = pile->GetState();
CBotInstr* p = m_instr;
while (state-- > 0) p = p->GetNext();
while (p != nullptr)
{
if (!p->Execute(pile)) return false;
pile->IncState();
p = p->GetNext();
}
pile->Delete();
return pj->IsOk();
}
////////////////////////////////////////////////////////////////////////////////
void CBotCase::RestoreState(CBotStack* &pj, bool bMain)
{
}
if (!bMain) return;
////////////////////////////////////////////////////////////////////////////////
bool CBotCase::CompCase(CBotStack* &pile, int val)
{
if (m_value == nullptr ) return true; // "default" case
CBotStack* pile = pj->RestoreStack(this);
if (pile == nullptr) return;
while (!m_value->Execute(pile)); // puts the value on the correspondent stack (without interruption)
return (pile->GetVal() == val); // compared with the given value
CBotInstr* p = m_instr;
int state = pile->GetState();
while (p != nullptr && state-- > 0)
{
p->RestoreState(pile, bMain);
p = p->GetNext();
}
if (p != nullptr) p->RestoreState(pile, bMain);
}
std::map<std::string, CBotInstr*> CBotCase::GetDebugLinks()
{
auto links = CBotInstr::GetDebugLinks();
links["m_value"] = m_value;
links["m_instr"] = m_instr;
return links;
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -21,6 +21,8 @@
#include "CBot/CBotInstr/CBotInstr.h"
#include <unordered_map>
namespace CBot
{
@ -42,7 +44,7 @@ public:
* \param pStack
* \return
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, std::unordered_map<long, CBotInstr*>& labels);
/*!
* \brief Execute Execution of instruction "case".
@ -58,22 +60,15 @@ public:
*/
void RestoreState(CBotStack* &pj, bool bMain) override;
/*!
* \brief CompCase Routine to find the entry point of "case" corresponding
* to the value seen.
* \param pj
* \param val
* \return
*/
bool CompCase(CBotStack* &pj, int val) override;
protected:
virtual const std::string GetDebugName() override { return "CBotCase"; }
virtual std::map<std::string, CBotInstr*> GetDebugLinks() override;
private:
//! Value to compare.
CBotInstr* m_value;
//! List of instructions after case label
CBotInstr* m_instr;
friend class CBotSwitch;
};
} // namespace CBot

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -140,7 +140,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
if (typ == CBotErrUndefCall)
{
// si le constructeur n'existe pas
// if the ctor don't exist
if (inst->m_parameters != nullptr) // with parameters
{
pStk->SetError(CBotErrNoConstruct, vartoken);

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -46,13 +46,22 @@ CBotDefFloat::~CBotDefFloat()
}
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip, CBotTypResult vartype)
{
CBotToken* pp = cont ? nullptr : p;
if (!cont && !IsOfType(p, ID_FLOAT)) return nullptr;
if (!cont)
{
switch (p->GetType())
{
case ID_FLOAT: vartype.SetType(CBotTypFloat ); break;
case ID_DOUBLE: vartype.SetType(CBotTypDouble); break;
default: return nullptr;
}
p = p->GetNext();
}
CBotDefFloat* inst = static_cast<CBotDefFloat*>(CompileArray(p, pStack, CBotTypFloat));
CBotDefFloat* inst = static_cast<CBotDefFloat*>(CompileArray(p, pStack, vartype));
if (inst != nullptr || !pStack->IsOk()) return inst;
CBotCStack* pStk = pStack->TokenStack(pp);
@ -67,7 +76,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
{
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypFloat;
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = vartype;
if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable
{
pStk->SetStartError(vartoken->GetStart());
@ -79,7 +88,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
{
delete inst;
p = vartoken;
inst = static_cast<CBotDefFloat*>(CBotDefArray::Compile(p, pStk, CBotTypFloat));
inst = static_cast<CBotDefFloat*>(CBotDefArray::Compile(p, pStk, vartype));
goto suite; // no assignment, variable already created
}
@ -103,7 +112,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
}
}
var = CBotVar::Create(*vartoken, CBotTypFloat);
var = CBotVar::Create(*vartoken, vartype);
var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF);
var->SetUniqNum(
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
@ -111,7 +120,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
suite:
if (pStk->IsOk() && IsOfType(p, ID_COMMA))
{
if (nullptr != ( inst->m_next2b = CBotDefFloat::Compile(p, pStk, true, noskip)))
if (nullptr != ( inst->m_next2b = CBotDefFloat::Compile(p, pStk, true, noskip, vartype)))
{
return pStack->Return(inst, pStk);
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -41,7 +41,7 @@ public:
* \param noskip
* \return
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false, CBotTypResult vartype = CBotTypFloat);
/*!
* \brief Execute Executes the definition of a real variable.

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -47,13 +47,25 @@ CBotDefInt::~CBotDefInt()
}
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip, CBotTypResult vartype)
{
CBotToken* pp = cont ? nullptr : p; // no repetition of the token "int"
if (!cont && !IsOfType(p, ID_INT)) return nullptr;
if (!cont)
{
switch (p->GetType())
{
case ID_BYTE: vartype.SetType(CBotTypByte ); break;
case ID_SHORT: vartype.SetType(CBotTypShort); break;
case ID_CHAR: vartype.SetType(CBotTypChar ); break;
case ID_INT: vartype.SetType(CBotTypInt ); break;
case ID_LONG: vartype.SetType(CBotTypLong ); break;
default: return nullptr;
}
p = p->GetNext();
}
CBotDefInt* inst = static_cast<CBotDefInt*>(CompileArray(p, pStack, CBotTypInt));
CBotDefInt* inst = static_cast<CBotDefInt*>(CompileArray(p, pStack, vartype));
if (inst != nullptr || !pStack->IsOk()) return inst;
CBotCStack* pStk = pStack->TokenStack(pp);
@ -68,7 +80,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
// determines the expression is valid for the item on the left side
if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
{
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypInt;
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = vartype;
if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable
{
pStk->SetError(CBotErrRedefVar, vartoken);
@ -82,7 +94,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
// compiles an array declaration
CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, CBotTypInt);
CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, vartype);
inst = static_cast<CBotDefInt*>(inst2);
goto suite; // no assignment, variable already created
@ -108,7 +120,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
}
{
CBotVar* var = CBotVar::Create(*vartoken, CBotTypInt);// create the variable (evaluated after the assignment)
CBotVar* var = CBotVar::Create(*vartoken, vartype); // create the variable (evaluated after the assignment)
var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); // if initialized with assignment
var->SetUniqNum( //set it with a unique number
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
@ -117,7 +129,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
suite:
if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // chained several definitions
{
if (nullptr != ( inst->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile next one
if (nullptr != ( inst->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip, vartype))) // compile next one
{
return pStack->Return(inst, pStk);
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -41,7 +41,7 @@ public:
* \param noskip
* \return
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false);
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false, CBotTypResult vartype = CBotTypInt);
/*!
* \brief Execute Execute the definition of the integer variable.

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -57,7 +57,7 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
inst->SetToken(p);
if (!IsOfType(p, ID_DO)) return nullptr; // should never happen
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
CBotCStack* pStk = pStack->TokenStack(pp); // some space for a stack, plz
// looking for a statement block after the do

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -0,0 +1,151 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "CBot/CBotInstr/CBotExprLitChar.h"
#include "CBot/CBotStack.h"
#include "CBot/CBotCStack.h"
#include "CBot/CBotVar/CBotVar.h"
namespace CBot
{
CBotExprLitChar::CBotExprLitChar()
{
}
CBotExprLitChar::~CBotExprLitChar()
{
}
CBotInstr* CBotExprLitChar::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->TokenStack();
const auto& s = p->GetString();
auto it = s.cbegin();
if (++it != s.cend())
{
if (*it != '\'') // not empty quotes ?
{
uint32_t valchar = 0;
int pos = p->GetStart() + 1;
if (*it != '\\') valchar = *(it++); // not escape sequence ?
else if (++it != s.cend())
{
pStk->SetStartError(pos++);
unsigned char c = *(it++);
if (c == '\"' || c == '\'' || c == '\\') valchar = c;
else if (c == 'a') valchar = '\a'; // alert bell
else if (c == 'b') valchar = '\b'; // backspace
else if (c == 'f') valchar = '\f'; // form feed
else if (c == 'n') valchar = '\n'; // new line
else if (c == 'r') valchar = '\r'; // carriage return
else if (c == 't') valchar = '\t'; // horizontal tab
else if (c == 'v') valchar = '\v'; // vertical tab
else if (c == 'u' || c == 'U') // unicode escape
{
if (it != s.cend())
{
std::string hex = "";
size_t maxlen = (c == 'u') ? 4 : 8;
for (size_t i = 0; i < maxlen; i++)
{
if (!CharInList(*it, "0123456789ABCDEFabcdef")) break;
++pos;
hex += *it;
if (++it == s.cend()) break;
}
if (maxlen == hex.length()) // unicode character
{
try
{
valchar = std::stoi(hex, nullptr, 16);
if (0x10FFFF < valchar || (0xD7FF < valchar && valchar < 0xE000))
pStk->SetError(CBotErrUnicodeName, pos + 1);
}
catch (const std::out_of_range& e)
{
pStk->SetError(CBotErrHexRange, pos + 1);
}
}
else
pStk->SetError(CBotErrHexDigits, pos + 1);
}
else
pStk->SetError(CBotErrHexDigits, pos + 1);
}
else
pStk->SetError(CBotErrBadEscape, pos + 1);
}
if (it == s.cend() || *it != '\'')
pStk->SetError(CBotErrEndQuote, p);
if (pStk->IsOk())
{
CBotExprLitChar* inst = new CBotExprLitChar();
inst->m_valchar = valchar;
inst->SetToken(p);
p = p->GetNext();
CBotVar* var = CBotVar::Create("", CBotTypChar);
pStk->SetVar(var);
return pStack->Return(inst, pStk);
}
}
pStk->SetError(CBotErrCharEmpty, p);
}
pStk->SetError(CBotErrEndQuote, p);
return pStack->Return(nullptr, pStk);
}
bool CBotExprLitChar::Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this);
if (pile->IfStep()) return false;
CBotVar* var = CBotVar::Create("", CBotTypChar);
var->SetValChar(m_valchar);
pile->SetVar(var);
return pj->Return(pile);
}
void CBotExprLitChar::RestoreState(CBotStack* &pj, bool bMain)
{
if (bMain) pj->RestoreStack(this);
}
std::string CBotExprLitChar::GetDebugData()
{
return m_token.GetString();
}
} // namespace CBot

View File

@ -0,0 +1,60 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "CBot/CBotInstr/CBotInstr.h"
namespace CBot
{
/**
* \brief A character literal
* \verbatim 'a', '\n', '\t', '\uFFFD', '\U0000FFFD', etc. \endverbatim
*/
class CBotExprLitChar : public CBotInstr
{
public:
CBotExprLitChar();
~CBotExprLitChar();
/*!
* \brief Compile a character literal
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
/*!
* \brief Execute, returns the corresponding char.
*/
bool Execute(CBotStack* &pj) override;
/*!
* \brief RestoreState
*/
void RestoreState(CBotStack* &pj, bool bMain) override;
protected:
virtual const std::string GetDebugName() override { return "CBotExprLitChar"; }
virtual std::string GetDebugData() override;
private:
uint32_t m_valchar = 0;
};
} // namespace CBot

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -25,52 +25,85 @@
#include "CBot/CBotUtils.h"
#include <limits>
#include <sstream>
namespace CBot
{
////////////////////////////////////////////////////////////////////////////////
CBotExprLitNum::CBotExprLitNum()
template <>
CBotExprLitNum<int>::CBotExprLitNum(int val) : m_numtype(CBotTypInt), m_value(val)
{
}
////////////////////////////////////////////////////////////////////////////////
CBotExprLitNum::~CBotExprLitNum()
template <>
CBotExprLitNum<long>::CBotExprLitNum(long val) : m_numtype(CBotTypLong), m_value(val)
{
}
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotExprLitNum::Compile(CBotToken* &p, CBotCStack* pStack)
template <>
CBotExprLitNum<float>::CBotExprLitNum(float val) : m_numtype(CBotTypFloat), m_value(val)
{
}
template <>
CBotExprLitNum<double>::CBotExprLitNum(double val) : m_numtype(CBotTypDouble), m_value(val)
{
}
template <typename T>
CBotExprLitNum<T>::~CBotExprLitNum()
{
}
CBotInstr* CompileExprLitNum(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->TokenStack();
CBotExprLitNum* inst = new CBotExprLitNum();
const auto& s = p->GetString();
inst->SetToken(p);
std::string s = p->GetString();
CBotInstr* inst = nullptr;
CBotType numtype = CBotTypInt;
inst->m_numtype = CBotTypInt;
if (p->GetType() == TokenTypDef)
{
inst->m_valint = p->GetKeywordId();
inst = new CBotExprLitNum<int>(static_cast<int>(p->GetKeywordId()));
}
else
{
if (s.find('.') != std::string::npos || ( s.find('x') == std::string::npos && ( s.find_first_of("eE") != std::string::npos ) ))
{
inst->m_numtype = CBotTypFloat;
inst->m_valfloat = GetNumFloat(s);
double val = GetNumFloat(s);
if (val > static_cast<double>(std::numeric_limits<float>::max()))
{
numtype = CBotTypDouble;
inst = new CBotExprLitNum<double>(val);
}
else
{
numtype = CBotTypFloat;
inst = new CBotExprLitNum<float>(static_cast<float>(val));
}
}
else
{
inst->m_valint = GetNumInt(s);
long val = GetNumInt(s);
if (val > std::numeric_limits<int>::max())
{
numtype = CBotTypLong;
inst = new CBotExprLitNum<long>(val);
}
else
{
inst = new CBotExprLitNum<int>(static_cast<int>(val));
}
}
}
inst->SetToken(p);
if (pStk->NextToken(p))
{
CBotVar* var = CBotVar::Create("", inst->m_numtype);
CBotVar* var = CBotVar::Create("", numtype);
pStk->SetVar(var);
return pStack->Return(inst, pStk);
@ -79,8 +112,48 @@ CBotInstr* CBotExprLitNum::Compile(CBotToken* &p, CBotCStack* pStack)
return pStack->Return(nullptr, pStk);
}
////////////////////////////////////////////////////////////////////////////////
bool CBotExprLitNum::Execute(CBotStack* &pj)
CBotInstr* CompileSizeOf(CBotToken* &p, CBotCStack* pStack)
{
CBotToken* pp = p;
if (!IsOfType(p, TokenTypVar)) return nullptr;
if (pp->GetString() == "sizeof" && IsOfType(p, ID_OPENPAR))
{
CBotCStack* pStk = pStack->TokenStack();
int value;
if (IsOfType(p, ID_BYTE)) value = sizeof(signed char);
else if (IsOfType(p, ID_SHORT)) value = sizeof(short);
else if (IsOfType(p, ID_CHAR)) value = sizeof(uint32_t);
else if (IsOfType(p, ID_INT)) value = sizeof(int);
else if (IsOfType(p, ID_LONG)) value = sizeof(long);
else if (IsOfType(p, ID_FLOAT)) value = sizeof(float);
else if (IsOfType(p, ID_DOUBLE)) value = sizeof(double);
else
{
p = pp;
return pStack->Return(nullptr, pStk);
}
if (IsOfType(p, ID_CLOSEPAR))
{
auto inst = new CBotExprLitNum<int>(value);
inst->SetToken(pp);
CBotVar* var = CBotVar::Create("", CBotTypInt);
pStk->SetVar(var);
return pStack->Return(inst, pStk);
}
pStk->SetError(CBotErrClosePar, p->GetStart());
return pStack->Return(nullptr, pStk);
}
p = pp;
return nullptr;
}
template <typename T>
bool CBotExprLitNum<T>::Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this);
@ -88,39 +161,38 @@ bool CBotExprLitNum::Execute(CBotStack* &pj)
CBotVar* var = CBotVar::Create("", m_numtype);
std::string nombre ;
if (m_token.GetType() == TokenTypDef)
{
nombre = m_token.GetString();
var->SetValInt(m_value, m_token.GetString());
}
switch (m_numtype)
else
{
case CBotTypShort:
case CBotTypInt:
var->SetValInt(m_valint, nombre);
break;
case CBotTypFloat:
var->SetValFloat(m_valfloat);
break;
default:
assert(false);
*var = m_value;
}
pile->SetVar(var); // place on the stack
return pj->Return(pile); // it's ok
}
////////////////////////////////////////////////////////////////////////////////
void CBotExprLitNum::RestoreState(CBotStack* &pj, bool bMain)
template <typename T>
void CBotExprLitNum<T>::RestoreState(CBotStack* &pj, bool bMain)
{
if (bMain) pj->RestoreStack(this);
}
std::string CBotExprLitNum::GetDebugData()
template <typename T>
std::string CBotExprLitNum<T>::GetDebugData()
{
std::stringstream ss;
ss << "(" << (m_numtype == CBotTypFloat ? "float" : "int") << ") " << (m_numtype == CBotTypFloat ? m_valfloat : m_valint);
switch (m_numtype)
{
case CBotTypInt : ss << "(int) "; break;
case CBotTypLong : ss << "(long) "; break;
case CBotTypFloat : ss << "(float) "; break;
case CBotTypDouble: ss << "(double) "; break;
default: assert(false);
}
ss << m_value;
return ss.str();
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -24,25 +24,24 @@
namespace CBot
{
CBotInstr* CompileExprLitNum(CBotToken* &p, CBotCStack* pStack);
CBotInstr* CompileSizeOf(CBotToken* &p, CBotCStack* pStack);
/**
* \brief A number literal - 5, 1, 2.5, 3.75, etc. or a predefined numerical constant (see CBotToken::DefineNum())
*
* Can be of type ::CBotTypInt or ::CBotTypFloat
* Can be of type ::CBotTypInt, ::CBotTypLong, ::CBotTypFloat, or ::CBotTypDouble
*/
template <typename T>
class CBotExprLitNum : public CBotInstr
{
public:
CBotExprLitNum();
~CBotExprLitNum();
// To keep linter happy, instead of = delete (see https://stackoverflow.com/a/37593094)
CBotExprLitNum(T val) { static_assert(sizeof(T) == 0, "Only specializations of CBotExprLitNum can be used"); };
/*!
* \brief Compile
* \param p
* \param pStack
* \return
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
~CBotExprLitNum();
/*!
* \brief Execute Execute, returns the corresponding number.
@ -65,10 +64,8 @@ protected:
private:
//! The type of number.
CBotType m_numtype;
//! Value for an int.
long m_valint;
//! Value for a float.
float m_valfloat;
//! Value
T m_value;
};

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -24,6 +24,8 @@
#include "CBot/CBotVar/CBotVar.h"
#include <stdexcept>
namespace CBot
{
@ -42,7 +44,7 @@ CBotInstr* CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->TokenStack();
std::string s = p->GetString();
const auto& s = p->GetString();
auto it = s.cbegin();
if (++it != s.cend())
@ -51,7 +53,7 @@ CBotInstr* CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
std::string valstring = "";
while (it != s.cend() && *it != '\"')
{
pStk->SetStartError(++pos);
++pos;
if (*it != '\\') // not escape sequence ?
{
valstring += *(it++);
@ -59,6 +61,7 @@ CBotInstr* CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
}
if (++it == s.cend()) break;
pStk->SetStartError(pos);
if (CharInList(*it, "01234567")) // octal
{

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -40,8 +40,7 @@ CBotExprUnaire::~CBotExprUnaire()
delete m_expr;
}
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral)
CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral, bool bConstExpr)
{
int op = p->GetType();
CBotToken* pp = p;
@ -52,8 +51,10 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLite
CBotExprUnaire* inst = new CBotExprUnaire();
inst->SetToken(pp);
if (!bLiteral) inst->m_expr = CBotParExpr::Compile(p, pStk);
else inst->m_expr = CBotParExpr::CompileLitExpr(p, pStk);
if (bConstExpr || !bLiteral)
inst->m_expr = CBotParExpr::Compile(p, pStk, bConstExpr);
else
inst->m_expr = CBotParExpr::CompileLitExpr(p, pStk);
if (inst->m_expr != nullptr)
{

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -40,7 +40,7 @@ public:
* \param bLiteral If true, compiles only literal expressions Ex: ~11, -4.0, !false, not true
* \return The compiled instruction or nullptr
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral = false);
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral = false, bool bConstExpr = false);
/*!
* \brief Execute

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -67,7 +67,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
return nullptr;
}
CBotCStack* pStk = pStack->TokenStack(pp, true); // un petit bout de pile svp
CBotCStack* pStk = pStack->TokenStack(pp, true); // some size for a stack, plz
// compiles instructions for initialization
inst->m_init = CBotListExpression::Compile(p, pStk );

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -169,7 +169,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
func->m_token = d;
}
// un nom de fonction est-il là ?
// is there a function name here ?
if (IsOfType(p, TokenTypVar))
{
if ( IsOfType( p, ID_DBLDOTS ) ) // method for a class
@ -284,7 +284,7 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas
func->m_token = d;
}
// un nom de fonction est-il là ?
// is there a function name here ?
if (IsOfType(p, TokenTypVar))
{
if ( IsOfType( p, ID_DBLDOTS ) ) // method for a class
@ -584,7 +584,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(const std::list<CBotFunction*>& lo
{
int i = 0;
int alpha = 0; // signature of parameters
// parameters sont-ils compatibles ?
// are parameters compatible ?
CBotDefParam* pv = pt->m_param; // list of expected parameters
CBotVar* pw = ppVars[i++]; // list of provided parameters
while ( pv != nullptr && (pw != nullptr || pv->HasDefault()) )
@ -996,7 +996,7 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam)
}
////////////////////////////////////////////////////////////////////////////////
std::string CBotFunction::GetName()
const std::string& CBotFunction::GetName()
{
return m_token.GetString();
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -207,7 +207,7 @@ public:
* \brief GetName
* \return
*/
std::string GetName();
const std::string& GetName();
/*!
* \brief GetParams

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -208,10 +208,15 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
case ID_THROW:
return CBotThrow::Compile(p, pStack);
case ID_BYTE:
case ID_SHORT:
case ID_CHAR:
case ID_INT:
case ID_LONG:
return CBotDefInt::Compile(p, pStack);
case ID_FLOAT:
case ID_DOUBLE:
return CBotDefFloat::Compile(p, pStack);
case ID_STRING:
@ -312,13 +317,6 @@ void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain)
assert(0); // dad do not know, see the girls
}
////////////////////////////////////////////////////////////////////////////////
bool CBotInstr::CompCase(CBotStack* &pj, int val)
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first)
{
if (IsOfType(p, ID_OPBRK))

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
@ -191,17 +191,6 @@ public:
virtual void RestoreStateVar(CBotStack* &pile,
bool bMain);
/**
* \brief CompCase This routine is defined only for the subclass CBotCase
* this allows to make the call on all instructions CompCase to see if it's
* a case to the desired value..
* \param pj
* \param val
* \return
*/
virtual bool CompCase(CBotStack* &pj,
int val);
/**
* \brief SetToken Set the token corresponding to the instruction.
* \param p

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,6 +1,6 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify

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