# HG changeset patch # User Stepan777 # Date 1339422970 -14400 # Node ID f484455dd05511b4ed5177b3e998e218307a2938 # Parent 5debd5fe526ed7b1e494add3f0db3b4652fc6929# Parent c3b4fc19fcd48bc99322b658d08cc7ed82264c90 merge diff -r 5debd5fe526e -r f484455dd055 CMakeLists.txt --- a/CMakeLists.txt Fri Jun 08 02:52:35 2012 +0400 +++ b/CMakeLists.txt Mon Jun 11 17:56:10 2012 +0400 @@ -4,9 +4,9 @@ #initialise cmake environment cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR) FOREACH(policy CMP0003 CMP0012) - IF(POLICY ${policy}) - CMAKE_POLICY(SET ${policy} NEW) - ENDIF() + IF(POLICY ${policy}) + CMAKE_POLICY(SET ${policy} NEW) + ENDIF() ENDFOREACH() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules) @@ -15,26 +15,26 @@ set(version_suffix "-dev") #UNSET THIS VARIABLE AT RELEASE TIME set(HGCHANGED "") IF(version_suffix MATCHES "-dev") - set(HW_DEV true) - IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.hg) - FIND_PROGRAM(HGCOMMAND hg) - IF(HGCOMMAND) - exec_program(${HGCOMMAND} - ARGS identify -in ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE version_suffix - ) - STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${version_suffix}) - STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) ([0-9]+)(.*)" "\\3-\\1" version_suffix ${version_suffix}) - IF (HGCHANGED) - MESSAGE(STATUS "Building revision ${version_suffix} (SOURCE CODE MODIFIED)") - ELSE() - MESSAGE(STATUS "Building revision ${version_suffix}") - ENDIF() - set(version_suffix "-${version_suffix}") - ENDIF() - ENDIF() + set(HW_DEV true) + IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.hg) + FIND_PROGRAM(HGCOMMAND hg) + IF(HGCOMMAND) + exec_program(${HGCOMMAND} + ARGS identify -in ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE version_suffix + ) + STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${version_suffix}) + STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) ([0-9]+)(.*)" "\\3-\\1" version_suffix ${version_suffix}) + IF (HGCHANGED) + MESSAGE(STATUS "Building revision ${version_suffix} (SOURCE CODE MODIFIED)") + ELSE() + MESSAGE(STATUS "Building revision ${version_suffix}") + ENDIF() + set(version_suffix "-${version_suffix}") + ENDIF() + ENDIF() ELSE() - set(HW_DEV false) + set(HW_DEV false) ENDIF() @@ -47,108 +47,105 @@ #set some safe values -IF(NOT WITH_SERVER) - SET(WITH_SERVER 0) -ENDIF(NOT WITH_SERVER) IF(NOT BUILD_ENGINE_LIBRARY) - SET(BUILD_ENGINE_LIBRARY 0) + SET(BUILD_ENGINE_LIBRARY 0) ENDIF(NOT BUILD_ENGINE_LIBRARY) set(target_dir "bin") #bundle .app setup if(APPLE) - set(CMAKE_FIND_FRAMEWORK "FIRST") + set(CMAKE_FIND_FRAMEWORK "FIRST") - #paths for creating the bundle - set(bundle_name Hedgewars.app) - set(frameworks_dir ${bundle_name}/Contents/Frameworks/) - set(CMAKE_INSTALL_PREFIX ${bundle_name}/Contents/MacOS/) - set(DATA_INSTALL_DIR "../Resources/") - set(target_dir ".") + #paths for creating the bundle + set(bundle_name Hedgewars.app) + set(frameworks_dir ${bundle_name}/Contents/Frameworks/) + set(CMAKE_INSTALL_PREFIX ${bundle_name}/Contents/MacOS/) + set(DATA_INSTALL_DIR "../Resources/") + set(target_dir ".") - #what system are we building for - set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET}) + #what system are we building for + set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET}) - #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version - find_program(sw_vers sw_vers) - if(sw_vers) - exec_program(${sw_vers} ARGS "-productVersion" OUTPUT_VARIABLE current_macosx_version) - string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version}) + #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version + find_program(sw_vers sw_vers) + if(sw_vers) + exec_program(${sw_vers} ARGS "-productVersion" OUTPUT_VARIABLE current_macosx_version) + string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version}) + else() + if(NOT minimum_macosx_version) + message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set") else() - if(NOT minimum_macosx_version) - message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set") - else() - set(current_macosx_version ${minimum_macosx_version}) - endif() - endif() + set(current_macosx_version ${minimum_macosx_version}) + endif() + endif() - #if nothing is set, we deploy only for the current system - if(NOT minimum_macosx_version) - set(minimum_macosx_version ${current_macosx_version}) - endif() + #if nothing is set, we deploy only for the current system + if(NOT minimum_macosx_version) + set(minimum_macosx_version ${current_macosx_version}) + endif() - #lower systems don't have enough processing power anyways - if (minimum_macosx_version LESS "10.4") - message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4") - endif() + #lower systems don't have enough processing power anyways + if (minimum_macosx_version LESS "10.4") + message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4") + endif() - #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2) - if(current_macosx_version MATCHES "10.4") - find_package(SDL_mixer REQUIRED) - set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg") - set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod") - set(pascal_flags "-k${DYLIB_SMPEG}" "-k${DYLIB_MIKMOD}" ${pascal_flags}) - set(CMAKE_C_FLAGS "${DYLIB_SMPEG}" "${DYLIB_MIKMOD}" ${CMAKE_C_FLAGS}) - endif() + #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2) + if(current_macosx_version MATCHES "10.4") + find_package(SDL_mixer REQUIRED) + set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg") + set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod") + set(pascal_flags "-k${DYLIB_SMPEG}" "-k${DYLIB_MIKMOD}" ${pascal_flags}) + set(CMAKE_C_FLAGS "${DYLIB_SMPEG}" "${DYLIB_MIKMOD}" ${CMAKE_C_FLAGS}) + endif() - #CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_SYSROOT need to be set for universal binary and correct linking - if(NOT CMAKE_OSX_ARCHITECTURES) - if(current_macosx_version LESS "10.6") - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*") - set(CMAKE_OSX_ARCHITECTURES "ppc7400") - else() - set(CMAKE_OSX_ARCHITECTURES "i386") - endif() - else() - set(CMAKE_OSX_ARCHITECTURES "x86_64") - endif() - endif() + #CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_SYSROOT need to be set for universal binary and correct linking + if(NOT CMAKE_OSX_ARCHITECTURES) + if(current_macosx_version LESS "10.6") + if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*") + set(CMAKE_OSX_ARCHITECTURES "ppc7400") + else() + set(CMAKE_OSX_ARCHITECTURES "i386") + endif() + else() + set(CMAKE_OSX_ARCHITECTURES "x86_64") + endif() + endif() - #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on - #we need to provide the correct one when host and target differ - if(NOT ${minimum_macosx_version} MATCHES ${current_macosx_version}) - if(minimum_macosx_version MATCHES "10.4") - set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/") - set(CMAKE_C_COMPILER "gcc-4.0") - set(CMAKE_CXX_COMPILER "g++-4.0") - else() - string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version}) - set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/") - endif() - endif() + #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on + #we need to provide the correct one when host and target differ + if(NOT ${minimum_macosx_version} MATCHES ${current_macosx_version}) + if(minimum_macosx_version MATCHES "10.4") + set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/") + set(CMAKE_C_COMPILER "gcc-4.0") + set(CMAKE_CXX_COMPILER "g++-4.0") + else() + string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version}) + set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/") + endif() + endif() - #add user framework directory, other paths can be passed via FPFLAGS - set(pascal_flags "-Ff~/Library/Frameworks" ${pascal_flags}) - #set deployment target - set(pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}" ${pascal_flags}) + #add user framework directory, other paths can be passed via FPFLAGS + set(pascal_flags "-Ff~/Library/Frameworks" ${pascal_flags}) + #set deployment target + set(pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}" ${pascal_flags}) - message(STATUS "Build system: Mac OS X ${current_macosx_version} with GCC:${CMAKE_C_COMPILER}") - message(STATUS "Target system: Mac OS X ${minimum_macosx_version} for architecture(s):${CMAKE_OSX_ARCHITECTURES}") + message(STATUS "Build system: Mac OS X ${current_macosx_version} with GCC:${CMAKE_C_COMPILER}") + message(STATUS "Target system: Mac OS X ${minimum_macosx_version} for architecture(s):${CMAKE_OSX_ARCHITECTURES}") endif(APPLE) #build Debug only when explicitally set if (NOT CMAKE_BUILD_TYPE) - set (CMAKE_BUILD_TYPE RELEASE CACHE STRING "Choose the type of build, options are: Debug Release." FORCE) + set (CMAKE_BUILD_TYPE RELEASE CACHE STRING "Choose the type of build, options are: Debug Release." FORCE) endif (NOT CMAKE_BUILD_TYPE) if(CMAKE_BUILD_TYPE MATCHES DEBUG OR CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "debug") - message(STATUS "Building Debug") - set(Optz false) + message(STATUS "Building Debug") + set(Optz false) else() - message(STATUS "Building Release") - set(Optz true) + message(STATUS "Building Release") + set(Optz true) endif() @@ -161,66 +158,72 @@ set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) separate_arguments(fpflags_full UNIX_COMMAND ${FPFLAGS}) -set(pascal_flags ${fpflags_full} "-B" "-FE../bin" "-Cs2000000" "-vewn" ${pascal_flags}) +set(pascal_flags ${fpflags_full} "-B" "-FE../bin" "-Cs2000000" "-vewn" "-dDEBUGFILE" ${pascal_flags}) separate_arguments(ghflags_full UNIX_COMMAND ${GHFLAGS}) set(haskell_flags "-O2" ${haskell_flags} ${ghflags_full}) if(Optz) -# set(pascal_flags "-O3" "-OpPENTIUM4" "-CfSSE3" "-Xs" "-Si" ${pascal_flags}) - set(pascal_flags "-Os" "-Ooregvar" "-Xs" "-Si" ${pascal_flags}) - set(haskell_flags "-w" "-fno-warn-unused-do-bind" ${haskell_flags}) +# set(pascal_flags "-O3" "-OpPENTIUM4" "-CfSSE3" "-Xs" "-Si" ${pascal_flags}) + set(pascal_flags "-Os" "-Ooregvar" "-Xs" "-Si" ${pascal_flags}) + set(haskell_flags "-w" "-fno-warn-unused-do-bind" ${haskell_flags}) else(Optz) - set(pascal_flags "-O-" "-g" "-gl" "-gv" "-Ct" "-dDEBUGFILE" ${pascal_flags}) - set(haskell_flags "-Wall" "-debug" "-dcore-lint" "-fno-warn-unused-do-bind" ${haskell_flags}) + set(pascal_flags "-O-" "-g" "-gl" "-gv" "-Ct" ${pascal_flags}) + set(haskell_flags "-Wall" "-debug" "-dcore-lint" "-fno-warn-unused-do-bind" ${haskell_flags}) endif(Optz) if(DEFINED DATA_INSTALL_DIR) - set(SHAREPATH ${DATA_INSTALL_DIR}/hedgewars/) + set(SHAREPATH ${DATA_INSTALL_DIR}/hedgewars/) else() - set(SHAREPATH share/hedgewars/) + set(SHAREPATH share/hedgewars/) endif() set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) -if(WITH_SERVER) - if(GHC) - set(ghc_executable ${GHC}) - else() - find_program(ghc_executable ghc) - endif() +if(NOT NOSERVER) + if(GHC) + set(ghc_executable ${GHC}) + else() + find_program(ghc_executable ghc) + endif() - if(ghc_executable) - set(HAVE_NETSERVER true) - add_subdirectory(gameServer) - else() - message(STATUS "No GHC executable found, server will *not* be built") - set(HAVE_NETSERVER false) - endif() -else(WITH_SERVER) - set(HAVE_NETSERVER false) -endif(WITH_SERVER) + if(ghc_executable) + set(HAVE_NETSERVER true) + add_subdirectory(gameServer) + else() + message(STATUS "No GHC executable found, server will not be built") + set(HAVE_NETSERVER false) + endif() +else() + message(STATUS "Server will not be built per user request") + set(HAVE_NETSERVER false) +endif() find_package(Lua) -if(NOT ${LUA_FOUND}) - message(STATUS "Lua library not found, building bundled dependency") - add_subdirectory(misc/liblua) - #link with liblua.a (which requires system readline) - set(pascal_flags "-k${CMAKE_BINARY_DIR}/bin/liblua.a" "-k-lreadline" ${pascal_flags}) +if(${LUA_FOUND}) + message(STATUS "Lua library is present on your system (${LUA_DEFAULT})") +else() + message(STATUS "Lua library not found, building bundled dependency") + add_subdirectory(misc/liblua) + #linking with liblua.a requires system readline -- this works everywhere, right? + set(pascal_flags "-k${CMAKE_BINARY_DIR}/bin/liblua.a" "-k-lreadline" ${pascal_flags}) endif() + add_subdirectory(hedgewars) + #run cmake -DANDROID=1 to enable this if(ANDROID) - add_subdirectory(project_files/Android-build) + add_subdirectory(project_files/Android-build) endif() + if(NOT (BUILD_ENGINE_LIBRARY OR ANDROID)) - add_subdirectory(bin) - add_subdirectory(misc/quazip) - add_subdirectory(QTfrontend) - add_subdirectory(share) - add_subdirectory(tools) + add_subdirectory(bin) + add_subdirectory(misc/quazip) + add_subdirectory(QTfrontend) + add_subdirectory(share) + add_subdirectory(tools) endif() @@ -235,74 +238,74 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "Hedgewars ${HEDGEWARS_VERSION}") if(WIN32 AND NOT UNIX) - set(CPACK_NSIS_DISPLAY_NAME "Hedgewars") - set(CPACK_NSIS_HELP_LINK "http://www.hedgewars.org/") - set(CPACK_NSIS_URL_INFO_ABOUT "http://www.hedgewars.org/") - set(CPACK_NSIS_CONTACT "unC0Rr@gmail.com") - set(CPACK_NSIS_MODIFY_PATH OFF) - set(CPACK_GENERATOR "ZIP;NSIS") - set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "hedgewars") + set(CPACK_NSIS_DISPLAY_NAME "Hedgewars") + set(CPACK_NSIS_HELP_LINK "http://www.hedgewars.org/") + set(CPACK_NSIS_URL_INFO_ABOUT "http://www.hedgewars.org/") + set(CPACK_NSIS_CONTACT "unC0Rr@gmail.com") + set(CPACK_NSIS_MODIFY_PATH OFF) + set(CPACK_GENERATOR "ZIP;NSIS") + set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "hedgewars") else(WIN32 AND NOT UNIX) - set(CPACK_STRIP_FILES "bin/hedgewars;bin/hwengine") + set(CPACK_STRIP_FILES "bin/hedgewars;bin/hwengine") endif(WIN32 AND NOT UNIX) set(CPACK_SOURCE_IGNORE_FILES - "~" - "\\\\.hg" - "\\\\.svn" - "\\\\.exe$" - "\\\\.a$" - "\\\\.dll$" - "\\\\.xcf$" - "\\\\.cxx$" - "\\\\.db$" - "\\\\.dof$" - "\\\\.layout$" - "\\\\.zip$" - "\\\\.gz$" - "\\\\.bz2$" - "\\\\.tmp$" - "\\\\.core$" - "\\\\.sh$" - "\\\\.sifz$" - "\\\\.svg$" - "\\\\.svgz$" - "\\\\.ppu$" - "\\\\.psd$" - "\\\\.o$" - "Makefile" - "Doxyfile" - "CMakeFiles" - "debug" - "release$" - "Debug$" - "Release$" - "proto\\\\.inc$" - "hwconsts\\\\.cpp$" - "playlist\\\\.inc$" - "CPack" - "cmake_install\\\\.cmake$" - "config\\\\.inc$" - "hwengine\\\\.desktop$" - "CMakeCache\\\\.txt$" -# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" -# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype" - "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" -# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor" - "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/HedgewarsMobile/" - "^${CMAKE_CURRENT_SOURCE_DIR}/bin/[a-z]" - "^${CMAKE_CURRENT_SOURCE_DIR}/tools/templates" - "^${CMAKE_CURRENT_SOURCE_DIR}/doc" - "^${CMAKE_CURRENT_SOURCE_DIR}/templates" - "^${CMAKE_CURRENT_SOURCE_DIR}/Graphics" - "^${CMAKE_CURRENT_SOURCE_DIR}/realtest" - "^${CMAKE_CURRENT_SOURCE_DIR}/tmp" - "^${CMAKE_CURRENT_SOURCE_DIR}/utils" - "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Maps/test" - "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Themes/ethereal" - "^${CMAKE_CURRENT_SOURCE_DIR}/install_manifest.txt" - "^${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" - "^${CMAKE_CURRENT_SOURCE_DIR}/hedgewars\\\\." + "~" + "\\\\.hg" + "\\\\.svn" + "\\\\.exe$" + "\\\\.a$" + "\\\\.dll$" + "\\\\.xcf$" + "\\\\.cxx$" + "\\\\.db$" + "\\\\.dof$" + "\\\\.layout$" + "\\\\.zip$" + "\\\\.gz$" + "\\\\.bz2$" + "\\\\.tmp$" + "\\\\.core$" + "\\\\.sh$" + "\\\\.sifz$" + "\\\\.svg$" + "\\\\.svgz$" + "\\\\.ppu$" + "\\\\.psd$" + "\\\\.o$" + "Makefile" + "Doxyfile" + "CMakeFiles" + "debug" + "release$" + "Debug$" + "Release$" + "proto\\\\.inc$" + "hwconsts\\\\.cpp$" + "playlist\\\\.inc$" + "CPack" + "cmake_install\\\\.cmake$" + "config\\\\.inc$" + "hwengine\\\\.desktop$" + "CMakeCache\\\\.txt$" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype" + "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor" + "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/HedgewarsMobile/" + "^${CMAKE_CURRENT_SOURCE_DIR}/bin/[a-z]" + "^${CMAKE_CURRENT_SOURCE_DIR}/tools/templates" + "^${CMAKE_CURRENT_SOURCE_DIR}/doc" + "^${CMAKE_CURRENT_SOURCE_DIR}/templates" + "^${CMAKE_CURRENT_SOURCE_DIR}/Graphics" + "^${CMAKE_CURRENT_SOURCE_DIR}/realtest" + "^${CMAKE_CURRENT_SOURCE_DIR}/tmp" + "^${CMAKE_CURRENT_SOURCE_DIR}/utils" + "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Maps/test" + "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Themes/ethereal" + "^${CMAKE_CURRENT_SOURCE_DIR}/install_manifest.txt" + "^${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" + "^${CMAKE_CURRENT_SOURCE_DIR}/hedgewars\\\\." ) include(CPack) diff -r 5debd5fe526e -r f484455dd055 QTfrontend/game.cpp --- a/QTfrontend/game.cpp Fri Jun 08 02:52:35 2012 +0400 +++ b/QTfrontend/game.cpp Mon Jun 11 17:56:10 2012 +0400 @@ -96,7 +96,7 @@ HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber))); HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber))); HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber))); - if(!gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore")); + if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore")); HWProto::addStringListToBuffer(buf, team.teamGameConfig(gamecfg->getInitHealth())); ; diff -r 5debd5fe526e -r f484455dd055 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/CMakeLists.txt Mon Jun 11 17:56:10 2012 +0400 @@ -172,13 +172,15 @@ if(${PNG_FOUND}) message(STATUS "PNG screenshots enabled (library found at ${PNG_LIBRARY})") set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags}) - if(APPLE) # need to explictly link with the static lib + if(APPLE) # need to explictly link with the static lib -- maybe windows too? string(REGEX REPLACE "(.*)libpng.*" "\\1" PNG_LIBDIR "${PNG_LIBRARY}") set(pascal_flags "-k${PNG_LIBDIR}/libpng.a" ${pascal_flags}) endif() else() message(STATUS "PNG library not found, switching to screenshots in BMP format") endif() +else() + message(STATUS "PNG screenshots disabled per user request, using BMP format") endif() set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project}) diff -r 5debd5fe526e -r f484455dd055 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/GSHandlers.inc Mon Jun 11 17:56:10 2012 +0400 @@ -1025,7 +1025,9 @@ else AmmoShove(Gear, Gear^.Timer, 20); CheckGearDrowning(Gear); - dec(i) until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0); + dec(i) + until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0); + if Gear^.Damage > 0 then begin DrawTunnel(oX, oY, Gear^.dX, Gear^.dY, 82 - i, 1); @@ -3438,7 +3440,7 @@ PlaySound(sndGun); end; - if (Gear^.Timer = 0) or (HHGear^.Damage <> 0) then + if (Gear^.Timer = 0) or ((HHGear^.State and gstHHDriven) = 0) then begin DeleteGear(Gear); AfterAttack diff -r 5debd5fe526e -r f484455dd055 hedgewars/VGSHandlers.inc --- a/hedgewars/VGSHandlers.inc Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/VGSHandlers.inc Mon Jun 11 17:56:10 2012 +0400 @@ -90,10 +90,16 @@ if round(X) > cRightScreenBorder then X:= X - cScreenSpace; // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards? - if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then - Y:= Y - (1024 + 300) // TODO - configure in theme (jellies for example could use limited range) - else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then - Y:= Y - (1024 + 25); + if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then + begin + X:= cLeftScreenBorder + random(cScreenSpace); + Y:= Y - (1024 + 250 + random(50)) // TODO - configure in theme (jellies for example could use limited range) + end + else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then + begin + X:= cLeftScreenBorder + random(cScreenSpace); + Y:= Y - (1024 + random(25)) + end; Timer:= 0; tdX:= 0; tdY:= 0 diff -r 5debd5fe526e -r f484455dd055 hedgewars/options.inc --- a/hedgewars/options.inc Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/options.inc Mon Jun 11 17:56:10 2012 +0400 @@ -16,61 +16,54 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA *) -{$IFDEF FPC} - {$WRITEABLECONST OFF} - {$IMPLICITEXCEPTIONS OFF} - {$VARSTRINGCHECKS ON} - {$MODE OBJFPC} -{$ELSE} - {$ERROR Only Free Pascal supported!} +{$IFNDEF FPC} + {$ERROR Only FreePascal Compiler is supported!} {$ENDIF} {$MACRO ON} +{$MODE OBJFPC} {$DEFINE GLunit:=GL} +{$WRITEABLECONST OFF} +{$IMPLICITEXCEPTIONS OFF} +{$VARSTRINGCHECKS ON} + +{$DEFINE USE_LUA_SCRIPT} + {$IFDEF ANDROID} + {$DEFINE MOBILE} + {$DEFINE USE_SDLTHREADS} + {$DEFINE USE_CONTEXT_RESTORE} + {$DEFINE Java_Prefix:= 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'} +{$ENDIF} + +{$IFDEF IPHONEOS} + {$DEFINE MOBILE} +{$ENDIF} + +{$IFDEF MOBILE} {$DEFINE SDL13} {$DEFINE HWLIBRARY} {$DEFINE S3D_DISABLED} {$DEFINE GLunit:=gles11} - {$DEFINE MOBILE} - {$DEFINE Java_Prefix:= 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'} - {$DEFINE USE_SDLTHREADS} - {$DEFINE USE_CONTEXT_RESTORE} {$DEFINE USE_LANDSCAPE_AMMOMENU} {$DEFINE USE_TOUCH_INTERFACE} +{$ELSE} + {$DEFINE USE_AM_NUMCOLUMN} {$ENDIF} -{$IFDEF IPHONEOS} - {$DEFINE SDL13} - {$DEFINE HWLIBRARY} - {$DEFINE S3D_DISABLED} - {$DEFINE GLunit:=gles11} - {$DEFINE MOBILE} - {$DEFINE USE_LANDSCAPE_AMMOMENU} - {$DEFINE USE_TOUCH_INTERFACE} -{$ENDIF} {$IFDEF WIN32} {$DEFINE USE_CONTEXT_RESTORE} {$ENDIF} -{$IFNDEF IPHONEOS} - {$IFDEF DARWIN} +{$IFDEF DARWIN} + {$IFNDEF IPHONEOS} {$DEFINE USE_CONTEXT_RESTORE} {$ENDIF} - // not needed on ios because DEBUGFILE is switched from command line - {$DEFINE DEBUGFILE} - //{$DEFINE TRACEAIACTIONS} - //{$DEFINE COUNTTICKS} {$ENDIF} -{$IFNDEF MOBILE} - {$DEFINE USE_AM_NUMCOLUMN} {$DEFINE USE_VIDEO_RECORDING} -{$ENDIF} - -{$DEFINE USE_LUA_SCRIPT} {$IFDEF PAS2C} {$DEFINE NOCONSOLE} @@ -79,3 +72,7 @@ {$DEFINE _S:=} {$DEFINE _P:=} + +//{$DEFINE TRACEAIACTIONS} +//{$DEFINE COUNTTICKS} + diff -r 5debd5fe526e -r f484455dd055 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uAI.pas Mon Jun 11 17:56:10 2012 +0400 @@ -111,7 +111,7 @@ procedure TestAmmos(var Actions: TActions; Me: PGear; isMoved: boolean); var BotLevel: Byte; ap: TAttackParams; - Score, i: LongInt; + Score, i, dAngle: LongInt; a, aa: TAmmoType; begin BotLevel:= Me^.Hedgehog^.BotLevel; @@ -153,29 +153,45 @@ if (ap.Time <> 0) then AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0); + if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then begin - ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle); - if ap.Angle > 0 then + dAngle:= LongInt(Me^.Angle) - Abs(ap.Angle); + if dAngle > 0 then begin AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0); - AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0) + AddAction(BestActions, aia_Up, aim_release, dAngle, 0, 0) end - else if ap.Angle < 0 then + else if dAngle < 0 then begin AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0); - AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0) + AddAction(BestActions, aia_Down, aim_release, -dAngle, 0, 0) end end; + if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then begin AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY) end; - if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then + + if (Ammoz[a].Ammo.Propz and ammoprop_OscAim) <> 0 then begin - AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); - AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); - end; + AddAction(BestActions, aia_attack, aim_push, 350 + random(200), 0, 0); + AddAction(BestActions, aia_attack, aim_release, 1, 0, 0); + + AddAction(BestActions, aia_Down, aim_push, 100 + random(150), 0, 0); + AddAction(BestActions, aia_Down, aim_release, 32, 0, 0); + + AddAction(BestActions, aia_waitAngle, ap.Angle, 250, 0, 0); + AddAction(BestActions, aia_attack, aim_push, 1, 0, 0); + AddAction(BestActions, aia_attack, aim_release, 1, 0, 0); + end else + if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then + begin + AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); + AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); + end; + if ap.ExplR > 0 then AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY); end @@ -218,81 +234,86 @@ BestRate:= RatePlace(Me); BaseRate:= Max(BestRate, 0); +// switch to 'skip' if we can't move because of mouse cursor being shown if (Ammoz[Me^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0 then AddAction(Actions, aia_Weapon, Longword(amSkip), 100 + random(200), 0, 0); - -tmp:= random(2) + 1; -Push(0, Actions, Me^, tmp); -Push(0, Actions, Me^, tmp xor 3); -while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do +if ((CurrentHedgehog^.MultiShootAttacks = 0) or ((Ammoz[Me^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoMoveAfter) = 0)) + and (GameFlags and gfArtillery = 0) then begin - Pop(ticks, Actions, Me^); + tmp:= random(2) + 1; + Push(0, Actions, Me^, tmp); + Push(0, Actions, Me^, tmp xor 3); + + while (Stack.Count > 0) and (not StopThinking) do + begin + Pop(ticks, Actions, Me^); - AddAction(Actions, Me^.Message, aim_push, 250, 0, 0); - if (Me^.Message and gmLeft) <> 0 then - AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0) - else - AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0); - - steps:= 0; + AddAction(Actions, Me^.Message, aim_push, 250, 0, 0); + if (Me^.Message and gmLeft) <> 0 then + AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0) + else + AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0); + + steps:= 0; - while (not StopThinking) do - begin -{$HINTS OFF} - CanGo:= HHGo(Me, @AltMe, GoInfo); -{$HINTS ON} - inc(ticks, GoInfo.Ticks); - if ticks > maxticks then - break; + while (not StopThinking) do + begin + {$HINTS OFF} + CanGo:= HHGo(Me, @AltMe, GoInfo); + {$HINTS ON} + inc(ticks, GoInfo.Ticks); + if ticks > maxticks then + break; - if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support - if Push(ticks, Actions, AltMe, Me^.Message) then - with Stack.States[Pred(Stack.Count)] do - begin - if Me^.dX.isNegative then - AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0) - else - AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0); + if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support + if Push(ticks, Actions, AltMe, Me^.Message) then + with Stack.States[Pred(Stack.Count)] do + begin + if Me^.dX.isNegative then + AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0) + else + AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0); + + AddAction(MadeActions, aia_HJump, 0, 305 + random(50), 0, 0); + AddAction(MadeActions, aia_HJump, 0, 350, 0, 0); - AddAction(MadeActions, aia_HJump, 0, 305 + random(50), 0, 0); - AddAction(MadeActions, aia_HJump, 0, 350, 0, 0); - - if Me^.dX.isNegative then - AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0) - else - AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0); - end; - if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support - if Push(ticks, Actions, AltMe, Me^.Message) then - with Stack.States[Pred(Stack.Count)] do - AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); + if Me^.dX.isNegative then + AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0) + else + AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0); + end; + if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support + if Push(ticks, Actions, AltMe, Me^.Message) then + with Stack.States[Pred(Stack.Count)] do + AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); - // 'not CanGO' means we can't go straight, possible jumps are checked above - if not CanGo then - break; - - inc(steps); - Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X); - Rate:= RatePlace(Me); - if Rate > BestRate then - begin - BestActions:= Actions; - BestActions.isWalkingToABetterPlace:= true; - BestRate:= Rate; - Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo - end - else if Rate < BestRate then - break; - if ((Me^.State and gstAttacked) = 0) and ((steps mod 4) = 0) then - TestAmmos(Actions, Me, true); - if GoInfo.FallPix >= FallPixForBranching then - Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right - end {while}; + // 'not CanGO' means we can't go straight, possible jumps are checked above + if not CanGo then + break; + + inc(steps); + Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X); + Rate:= RatePlace(Me); + if Rate > BestRate then + begin + BestActions:= Actions; + BestActions.isWalkingToABetterPlace:= true; + BestRate:= Rate; + Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo + end + else if Rate < BestRate then + break; + if ((Me^.State and gstAttacked) = 0) and ((steps mod 4) = 0) then + TestAmmos(Actions, Me, true); + if GoInfo.FallPix >= FallPixForBranching then + Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right + end {while}; - if BestRate > BaseRate then - exit + if BestRate > BaseRate then + exit end {while} + end {if} end; function Think(Me: Pointer): ptrint; @@ -414,6 +435,8 @@ AddFileLog('Thread started'); end; +//var scoreShown: boolean = false; + procedure ProcessBot; const cStopThinkTime = 40; begin @@ -430,16 +453,27 @@ StopMessages(Gear^.Message); TryDo((Gear^.Message and gmAllStoppable) = 0, 'Engine bug: AI may break demos playing', true); end; + if Gear^.Message <> 0 then exit; + + //scoreShown:= false; StartThink(Gear); StartTicks:= GameTicks - end else - ProcessAction(BestActions, Gear) + end else + begin + (* + if not scoreShown then + begin + if BestActions.Score > 0 then ParseCommand('/say Expected score = ' + inttostr(BestActions.Score div 1024), true); + scoreShown:= true + end;*) + ProcessAction(BestActions, Gear) + end else if ((GameTicks - StartTicks) > cMaxAIThinkTime) - or (TurnTimeLeft <= cStopThinkTime) then - StopThinking:= true + or (TurnTimeLeft <= cStopThinkTime) then + StopThinking:= true end; procedure initModule; diff -r 5debd5fe526e -r f484455dd055 hedgewars/uAIActions.pas --- a/hedgewars/uAIActions.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uAIActions.pas Mon Jun 11 17:56:10 2012 +0400 @@ -43,6 +43,7 @@ aia_Skip = $8008; aia_Wait = $8009; aia_Put = $800A; + aia_waitAngle = $800B; aim_push = $8000; aim_release = $8001; @@ -70,7 +71,7 @@ var PrevX: LongInt = 0; timedelta: Longword = 0; -const ActionIdToStr: array[0..7] of string[16] = ( +const ActionIdToStr: array[0..8] of string[16] = ( {aia_none} '', {aia_Left} 'left', {aia_Right} 'right', @@ -78,7 +79,8 @@ {aia_attack} 'attack', {aia_Up} 'up', {aia_Down} 'down', -{aia_Switch} 'switch' +{aia_Switch} 'switch', +{aia_waitAngle} 'waitAngle' ); {$IFDEF TRACEAIACTIONS} @@ -150,6 +152,7 @@ begin repeat if Actions.Pos >= Actions.Count then exit; + with Actions.actions[Actions.Pos] do begin if Time > GameTicks then @@ -160,74 +163,77 @@ if (Action and ai_specmask) <> 0 then case Action of aia_Weapon: - SetWeapon(TAmmoType(Param)); + SetWeapon(TAmmoType(Param)); aia_WaitXL: - if hwRound(Me^.X) = Param then - begin - Action:= aia_LookLeft; - Time:= GameTicks; - exit - end - else if hwRound(Me^.X) < Param then + if hwRound(Me^.X) = Param then begin - //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false); - FreeActionsList; + Action:= aia_LookLeft; + Time:= GameTicks; + exit + end + else if hwRound(Me^.X) < Param then + begin + //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false); + FreeActionsList; + exit + end + else + begin + CheckHang(Me); + exit + end; + + aia_WaitXR: + if hwRound(Me^.X) = Param then + begin + Action:= aia_LookRight; + Time:= GameTicks; + exit + end + else if hwRound(Me^.X) > Param then + begin + //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false); + FreeActionsList; + exit + end + else + begin + CheckHang(Me); + exit + end; + aia_LookLeft: + if not Me^.dX.isNegative then + begin + ParseCommand('+left', true); exit end else - begin - CheckHang(Me); - exit - end; - - aia_WaitXR: - if hwRound(Me^.X) = Param then - begin - Action:= aia_LookRight; - Time:= GameTicks; - exit - end - else if hwRound(Me^.X) > Param then + ParseCommand('-left', true); + aia_LookRight: + if Me^.dX.isNegative then begin - //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false); - FreeActionsList; + ParseCommand('+right', true); exit end - else - begin - CheckHang(Me); - exit - end; - aia_LookLeft: - if not Me^.dX.isNegative then - begin - ParseCommand('+left', true); - exit - end - else - ParseCommand('-left', true); - aia_LookRight: - if Me^.dX.isNegative then - begin - ParseCommand('+right', true); - exit - end - else ParseCommand('-right', true); + else ParseCommand('-right', true); aia_AwareExpl: - AwareOfExplosion(X, Y, Param); + AwareOfExplosion(X, Y, Param); aia_HJump: - ParseCommand('hjump', true); + ParseCommand('hjump', true); aia_LJump: - ParseCommand('ljump', true); + ParseCommand('ljump', true); aia_Skip: - ParseCommand('skip', true); + ParseCommand('skip', true); aia_Put: - doPut(X, Y, true); + doPut(X, Y, true); + + aia_waitAngle: + if Me^.Angle <> Abs(Param) then exit; end else begin diff -r 5debd5fe526e -r f484455dd055 hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uAIAmmoTests.pas Mon Jun 11 17:56:10 2012 +0400 @@ -43,6 +43,7 @@ function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; +function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; @@ -97,7 +98,7 @@ (proc: nil; flags: 0), // amExtraTime (proc: nil; flags: 0), // amLaserSight (proc: nil; flags: 0), // amVampiric - (proc: nil; flags: 0), // amSniperRifle + (proc: @TestSniperRifle; flags: 0), // amSniperRifle (proc: nil; flags: 0), // amJetpack (proc: @TestMolotov; flags: 0), // amMolotov (proc: nil; flags: 0), // amBirdy @@ -602,7 +603,56 @@ TestDesertEagle:= BadTurn; exit(BadTurn); end; -t:= 0.5 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y)); +t:= 2 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y)); +Vx:= (Targ.X - x) * t; +Vy:= (Targ.Y - y) * t; +ap.Angle:= DxDy2AttackAnglef(Vx, -Vy); +d:= 0; + +repeat + x:= x + vX; + y:= y + vY; + if ((trunc(x) and LAND_WIDTH_MASK) = 0)and((trunc(y) and LAND_HEIGHT_MASK) = 0) + and (Land[trunc(y), trunc(x)] <> 0) then + inc(d); +until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5) + or (x < 0) + or (y < 0) + or (trunc(x) > LAND_WIDTH) + or (trunc(y) > LAND_HEIGHT) + or (d > 50); + +if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5 then + begin + fallDmg:= TraceShoveFall(Targ.X, Targ.Y, vX * 0.00125 * 20, vY * 0.00125 * 20); + if fallDmg < 0 then + valueResult:= 204800 + else valueResult:= Max(0, (4 - d div 50) * trunc((7+fallDmg)*dmgMod) * 1024) + end +else + valueResult:= BadTurn; +TestDesertEagle:= valueResult +end; + + +function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; +var Vx, Vy, x, y, t, dmg, dmgMod: real; + d: Longword; + fallDmg, valueResult: LongInt; +begin +dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent; +Level:= Level; // avoid compiler hint +ap.ExplR:= 0; +ap.Time:= 0; +ap.Power:= 1; +x:= hwFloat2Float(Me^.X); +y:= hwFloat2Float(Me^.Y); +if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then + exit(BadTurn); + +dmg:= sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y)); +t:= 1.5 / dmg; +dmg:= dmg * 0.025; // div 40 Vx:= (Targ.X - x) * t; Vy:= (Targ.Y - y) * t; ap.Angle:= DxDy2AttackAnglef(Vx, -Vy); @@ -619,149 +669,172 @@ or (y < 0) or (trunc(x) > LAND_WIDTH) or (trunc(y) > LAND_HEIGHT) - or (d > 200); + or (d > 23); -if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 3 then +if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4 then begin - fallDmg:= TraceShoveFall(Me, Targ.X, Targ.Y, vX * 0.005 * 20, vY * 0.005 * 20); + fallDmg:= TraceShoveFall(Targ.X, Targ.Y, vX * 0.00166 * dmg, vY * 0.00166 * dmg); if fallDmg < 0 then - valueResult:= 204800 - else valueResult:= Max(0, (4 - d div 50) * trunc((7+fallDmg)*dmgMod) * 1024) + TestSniperRifle:= BadTurn + else + TestSniperRifle:= Max(0, trunc((dmg + fallDmg) * dmgMod) * 1024) end else - valueResult:= BadTurn; -TestDesertEagle:= valueResult + TestSniperRifle:= BadTurn end; + function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; -var valueResult: LongInt; - x, y: real; +var valueResult, a, v1, v2: LongInt; + x, y: LongInt; + dx, dy: real; begin -Level:= Level; // avoid compiler hint -TestBaseballBat:= BadTurn; -ap.ExplR:= 0; -x:= hwFloat2Float(Me^.X); -y:= hwFloat2Float(Me^.Y); -if (Level > 2) then - exit(BadTurn); + Level:= Level; // avoid compiler hint + ap.ExplR:= 0; + ap.Time:= 0; + ap.Power:= 1; + x:= hwRound(Me^.X); + y:= hwRound(Me^.Y); + + a:= 0; + valueResult:= 0; + + while a <= cMaxAngle div 2 do + begin + dx:= sin(a / cMaxAngle * pi) * 0.5; + dy:= cos(a / cMaxAngle * pi) * 0.5; -ap.Time:= 0; -ap.Power:= 1; -if (Targ.X) - trunc(x) >= 0 then - ap.Angle:= cMaxAngle div 4 -else - ap.Angle:= - cMaxAngle div 4; + v1:= RateShove(Me, x - 10, y + , 33, 30, 115 + , -dx, -dy, afTrackFall); + v2:= RateShove(Me, x + 10, y + , 33, 30, 115 + , dx, -dy, afTrackFall); + if (v1 > valueResult) or (v2 > valueResult) then + if (v2 > v1) + or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then + begin + ap.Angle:= a; + valueResult:= v2 + end + else + begin + ap.Angle:= -a; + valueResult:= v1 + end; -valueResult:= RateShove(Me, trunc(x) + LongWord(10*hwSignf(Targ.X - x)), trunc(y), 15, 30, 115, hwSign(Me^.dX)*0.353, -0.353, afTrackFall); -if valueResult <= 0 then - valueResult:= BadTurn -else - inc(valueResult); -TestBaseballBat:= valueResult; + a:= a + 15 + random(cMaxAngle div 16) + end; + + if valueResult <= 0 then + valueResult:= BadTurn; + + TestBaseballBat:= valueResult; end; function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; -var val1, val2, i, t: LongInt; - x, y: real; +var valueResult, v1, v2, i: LongInt; + x, y: LongInt; begin -Level:= Level; // avoid compiler hint -TestFirePunch:= BadTurn; -ap.ExplR:= 0; -ap.Time:= 0; -ap.Power:= 1; -ap.Angle:= hwSign(Me^.dX); -x:= hwFloat2Float(Me^.X); -y:= hwFloat2Float(Me^.Y); -{ -// this block is for digging with firepunch when blocked close to walls (notice TestColl check) -if (Abs(trunc(x) - Targ.X) > 25) - or (Abs(trunc(y) + 50 - Targ.Y) > 50) then - begin - if TestColl(trunc(x), trunc(y) - 16, 6) and - (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), - trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX)*0.45, -0.9, 1) >= 0) then - val1:= Succ(BadTurn) - else - val1:= BadTurn; - exit(val1); - end; - } -// and this is actual try to attack -val1:= 0; -for i:= 0 to 4 do - begin - t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, hwSign(Me^.dX)*0.45, -0.9, afTrackFall); - if (val1 < 0) or (t < 0) then val1:= BadTurn - else if t > 0 then val1:= t; - end; + Level:= Level; // avoid compiler hint + ap.ExplR:= 0; + ap.Time:= 0; + ap.Power:= 1; + x:= hwRound(Me^.X); + y:= hwRound(Me^.Y); + + v1:= 0; + for i:= 0 to 8 do + begin + v1:= v1 + RateShove(Me, x - 10, y - 10 * i + , 18, 30, 40 + , -0.45, -0.9, afTrackFall or afSetSkip); + end; + v1:= v1 + RateShove(Me, x - 10, y - 90 + , 18, 30, 40 + , -0.45, -0.9, afTrackFall); + -val2:= 0; -for i:= 0 to 4 do - begin - t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, -hwSign(Me^.dX)*0.45, -0.9, afTrackFall); - if (val2 < 0) or (t < 0) then val2:= BadTurn - else if t > 0 then val2:= t; - end; -if (val1 > val2) and (val1 > 0) then - TestFirePunch:= val1 -else if (val2 > val1) and (val2 > 0) then - begin - ap.Angle:= -hwSign(Me^.dX); - TestFirePunch:= val2 - end -else TestFirePunch:= BadTurn; + // now try opposite direction + v2:= 0; + for i:= 0 to 8 do + begin + v2:= v2 + RateShove(Me, x + 10, y - 10 * i + , 18, 30, 40 + , 0.45, -0.9, afTrackFall or afSetSkip); + end; + v2:= v2 + RateShove(Me, x + 10, y - 90 + , 18, 30, 40 + , 0.45, -0.9, afTrackFall); + + if (v2 > v1) + or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then + begin + ap.Angle:= 1; + valueResult:= v2 + end + else + begin + ap.Angle:= -1; + valueResult:= v1 + end; + + if valueResult <= 0 then + valueResult:= BadTurn; + + TestFirePunch:= valueResult; end; function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; var valueResult, v1, v2: LongInt; - x, y: real; + x, y: LongInt; begin -Level:= Level; // avoid compiler hint -ap.ExplR:= 0; -ap.Time:= 0; -ap.Power:= 1; -x:= hwFloat2Float(Me^.X); -y:= hwFloat2Float(Me^.Y); + Level:= Level; // avoid compiler hint + ap.ExplR:= 0; + ap.Time:= 0; + ap.Power:= 1; + x:= hwRound(Me^.X); + y:= hwRound(Me^.Y); -// check left direction -{first RateShove checks fartherest of two whip's AmmoShove attacks -to encourage distant attacks (damaged hog is excluded from view of second -RateShove call)} -v1:= RateShove(Me, trunc(x) - 15, trunc(y) - , 30, 30, 40 - , -1, -0.8, afTrackFall or afSetSkip); -v1:= v1 + - RateShove(Me, trunc(x), trunc(y) - , 30, 30, 40 - , -1, -0.8, afTrackFall); -// now try opposite direction -v2:= RateShove(Me, trunc(x) + 15, trunc(y) - , 30, 30, 40 - , 1, -0.8, afTrackFall or afSetSkip); -v2:= v2 + - RateShove(Me, trunc(x), trunc(y) - , 30, 30, 40 - , 1, -0.8, afTrackFall); + // check left direction + {first RateShove checks farthermost of two whip's AmmoShove attacks + to encourage distant attacks (damaged hog is excluded from view of second + RateShove call)} + v1:= RateShove(Me, x - 15, y + , 30, 30, 25 + , -1, -0.8, afTrackFall or afSetSkip); + v1:= v1 + + RateShove(Me, x, y + , 30, 30, 25 + , -1, -0.8, afTrackFall); + // now try opposite direction + v2:= RateShove(Me, x + 15, y + , 30, 30, 25 + , 1, -0.8, afTrackFall or afSetSkip); + v2:= v2 + + RateShove(Me, x, y + , 30, 30, 25 + , 1, -0.8, afTrackFall); -if (v2 > v1) - or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then - begin - ap.Angle:= 1; - valueResult:= v2 - end -else - begin - ap.Angle:= -1; - valueResult:= v1 - end; - -if valueResult <= 0 then - valueResult:= BadTurn -else - inc(valueResult); + if (v2 > v1) + or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then + begin + ap.Angle:= 1; + valueResult:= v2 + end + else + begin + ap.Angle:= -1; + valueResult:= v1 + end; + + if valueResult <= 0 then + valueResult:= BadTurn + else + inc(valueResult); -TestWhip:= valueResult; + TestWhip:= valueResult; end; function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; diff -r 5debd5fe526e -r f484455dd055 hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uAIMisc.pas Mon Jun 11 17:56:10 2012 +0400 @@ -59,8 +59,9 @@ function RatePlace(Gear: PGear): LongInt; function TestColl(x, y, r: LongInt): boolean; inline; +function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline; function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline; -function TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt; +function TraceShoveFall(x, y, dX, dY: Real): LongInt; function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline; function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt; @@ -80,7 +81,7 @@ end; implementation -uses uCollisions, uVariables, uUtils, uDebug; +uses uCollisions, uVariables, uUtils, uDebug, uLandTexture; const KillScore = 200; @@ -236,6 +237,28 @@ TestCollExcludingMe:= TestColl(x, y, r) end; +function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline; +var b: boolean; +begin + b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] and $FF00 <> 0); + if b then + exit(true); + + b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] and $FF00 <> 0); + if b then + exit(true); + + b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] and $FF00 <> 0); + if b then + exit(true); + + b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] and $FF00 <> 0); + if b then + exit(true); + + TestCollExcludingObjects:= false; +end; + function TestColl(x, y, r: LongInt): boolean; inline; var b: boolean; begin @@ -311,16 +334,25 @@ end; end; -function TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt; -var dmg: LongInt; +function TraceShoveFall(x, y, dX, dY: Real): LongInt; +var dmg, v: LongInt; begin +v:= random($FFFFFFFF); while true do begin x:= x + dX; y:= y + dY; dY:= dY + cGravityf; +(* + if ((trunc(y) and LAND_HEIGHT_MASK) = 0) and ((trunc(x) and LAND_WIDTH_MASK) = 0) then + begin + LandPixels[trunc(y), trunc(x)]:= v; + UpdateLandTexture(trunc(X), 1, trunc(Y), 1, true); + end; +*) + // consider adding dX/dY calc here for fall damage - if TestCollExcludingMe(Me, trunc(x), trunc(y), cHHRadius) then + if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then begin if 0.4 < dY then begin @@ -398,8 +430,8 @@ dX, dY, dmgMod: real; begin fallDmg:= 0; -dX:= gdX * 0.005 * kick; -dY:= gdY * 0.005 * kick; +dX:= gdX * 0.01 * kick; +dY:= gdY * 0.01 * kick; dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent; rate:= 0; for i:= 0 to Pred(Targets.Count) do @@ -410,15 +442,13 @@ begin dmg:= 0; if abs(Point.x - x) + abs(Point.y - y) < r then - begin dmg:= r - trunc(sqrt(sqr(Point.x - x)+sqr(Point.y - y))); - dmg:= trunc(dmg * dmgMod); - end; + if dmg > 0 then begin if (Flags and afSetSkip <> 0) then skip:= true; - if (Flags and afTrackFall <> 0) then - fallDmg:= trunc(TraceShoveFall(Me, Point.x, Point.y - 2, dX, dY) * dmgMod); + if (Flags and afTrackFall <> 0) and (Score > 0) then + fallDmg:= trunc(TraceShoveFall(Point.x, Point.y - 2, dX, dY) * dmgMod); if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI if Score > 0 then inc(rate, KillScore + Score div 10) // Add a bit of a bonus for bigger hog drownings diff -r 5debd5fe526e -r f484455dd055 hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uCommandHandlers.pas Mon Jun 11 17:56:10 2012 +0400 @@ -775,7 +775,8 @@ procedure chGameFlags(var s: shortstring); begin -GameFlags:= StrToInt(s) +GameFlags:= StrToInt(s); +if GameFlags and gfSharedAmmo <> 0 then GameFlags:= GameFlags and not gfPerHogAmmo end; procedure chHedgehogTurnTime(var s: shortstring); diff -r 5debd5fe526e -r f484455dd055 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uConsts.pas Mon Jun 11 17:56:10 2012 +0400 @@ -265,6 +265,8 @@ ammoprop_Effect = $00002000; ammoprop_SetBounce = $00004000; ammoprop_NeedUpDown = $00008000;//Used by TouchInterface to show or hide up/down widgets + ammoprop_OscAim = $00010000; + ammoprop_NoMoveAfter = $00020000; ammoprop_NoRoundEnd = $10000000; AMMO_INFINITE = 100; diff -r 5debd5fe526e -r f484455dd055 hedgewars/uInputHandler.pas --- a/hedgewars/uInputHandler.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uInputHandler.pas Mon Jun 11 17:56:10 2012 +0400 @@ -84,12 +84,12 @@ procedure MaskModifier(Modifier: shortstring; var code: LongInt); var mod_ : shortstring; ModifierCount, i: LongInt; - c : char; begin if Modifier = '' then exit; ModifierCount:= 0; -for c in Modifier do - if(c = ':') then inc(ModifierCount); + +for i:= 1 to Length(Modifier) do + if(Modifier[i] = ':') then inc(ModifierCount); SplitByChar(Modifier, mod_, ':');//remove the first mod: part Modifier:= mod_; @@ -156,7 +156,7 @@ var code: LongInt; begin code:= event.keysym.sym; - MaskModifier(code, event.keysym.modifier); + //MaskModifier(code, event.keysym.modifier); ProcessKey(code, event.type_ = SDL_KEYDOWN); end; diff -r 5debd5fe526e -r f484455dd055 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Fri Jun 08 02:52:35 2012 +0400 +++ b/hedgewars/uVariables.pas Mon Jun 11 17:56:10 2012 +0400 @@ -1840,7 +1840,9 @@ NameTex: nil; Probability: 20; NumberInCase: 2; - Ammo: (Propz: ammoprop_NeedUpDown; + Ammo: (Propz: ammoprop_NeedUpDown or + ammoprop_OscAim or + ammoprop_NoMoveAfter; Count: 2; NumPerTurn: 1; Timer: 0;