From 3b03b458e5739c2fabd010ac4dbf103d40a6b37a Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 9 Aug 2022 21:04:43 +0200 Subject: [PATCH 01/19] Load the game on double click on the loading menu --- source/glest_game/menu/main_menu.cpp | 10 ++++++++++ source/glest_game/menu/main_menu.h | 3 +++ source/glest_game/menu/menu_state_about.h | 1 + source/glest_game/menu/menu_state_connected_game.h | 1 + source/glest_game/menu/menu_state_custom_game.h | 1 + source/glest_game/menu/menu_state_graphic_info.h | 1 + source/glest_game/menu/menu_state_join_game.h | 1 + source/glest_game/menu/menu_state_keysetup.h | 1 + source/glest_game/menu/menu_state_load_game.cpp | 6 ++++++ source/glest_game/menu/menu_state_load_game.h | 1 + source/glest_game/menu/menu_state_masterserver.h | 1 + source/glest_game/menu/menu_state_mods.h | 1 + source/glest_game/menu/menu_state_new_game.h | 1 + source/glest_game/menu/menu_state_options.h | 1 + source/glest_game/menu/menu_state_options_graphics.h | 1 + source/glest_game/menu/menu_state_options_network.h | 1 + source/glest_game/menu/menu_state_options_sound.h | 1 + source/glest_game/menu/menu_state_root.h | 1 + source/glest_game/menu/menu_state_scenario.h | 1 + 19 files changed, 35 insertions(+) diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 1f28bc2f..e965b7e5 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -227,6 +227,16 @@ void MainMenu::mouseDownLeft(int x, int y){ state->mouseClick(x, y, mbLeft); } +void MainMenu::mouseDoubleClickLeft(int x, int y){ + if(GraphicComponent::getFade()<0.2f) return; + state->mouseDoubleClick(x, y, mbLeft); +} + +void MainMenu::mouseDoubleClickRight(int x, int y){ + if(GraphicComponent::getFade()<0.2f) return; + state->mouseDoubleClick(x, y, mbRight); +} + void MainMenu::mouseDownRight(int x, int y){ if(GraphicComponent::getFade()<0.2f) return; state->mouseClick(x, y, mbRight); diff --git a/source/glest_game/menu/main_menu.h b/source/glest_game/menu/main_menu.h index a98225bd..455ffb3c 100644 --- a/source/glest_game/menu/main_menu.h +++ b/source/glest_game/menu/main_menu.h @@ -74,6 +74,8 @@ public: virtual void mouseMove(int x, int y, const MouseState *mouseState); virtual void eventMouseWheel(int x, int y,int zDelta); virtual void mouseDownLeft(int x, int y); + virtual void mouseDoubleClickLeft(int x, int y); + virtual void mouseDoubleClickRight(int x, int y); virtual void mouseDownRight(int x, int y); virtual void mouseUpLeft(int x, int y); virtual bool textInput(std::string text); @@ -119,6 +121,7 @@ public: MenuState(Program *program, MainMenu *mainMenu, const string &stateName); virtual ~MenuState(); virtual void mouseClick(int x, int y, MouseButton mouseButton)=0; + virtual void mouseDoubleClick(int x, int y, MouseButton mouseButton)=0; virtual void mouseUp(int x, int y, const MouseButton mouseButton){}; virtual void mouseMove(int x, int y, const MouseState *mouseState)=0; virtual void eventMouseWheel(int x, int y, int zDelta){}; diff --git a/source/glest_game/menu/menu_state_about.h b/source/glest_game/menu/menu_state_about.h index efa6c0ef..5a8207b4 100644 --- a/source/glest_game/menu/menu_state_about.h +++ b/source/glest_game/menu/menu_state_about.h @@ -59,6 +59,7 @@ public: virtual ~MenuStateAbout(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); virtual void keyDown(SDL_KeyboardEvent key); diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index e1426c9e..f4971cf0 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -266,6 +266,7 @@ public: virtual ~MenuStateConnectedGame(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void eventMouseWheel(int x, int y,int zDelta); void render(); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 8e27dce0..5f67c5e9 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -245,6 +245,7 @@ public: virtual ~MenuStateCustomGame(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void eventMouseWheel(int x, int y,int zDelta); void render(); diff --git a/source/glest_game/menu/menu_state_graphic_info.h b/source/glest_game/menu/menu_state_graphic_info.h index 71ec9cb4..2d4b1e9f 100644 --- a/source/glest_game/menu/menu_state_graphic_info.h +++ b/source/glest_game/menu/menu_state_graphic_info.h @@ -38,6 +38,7 @@ public: MenuStateGraphicInfo(Program *program, MainMenu *mainMenu); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); virtual void keyDown(SDL_KeyboardEvent key); diff --git a/source/glest_game/menu/menu_state_join_game.h b/source/glest_game/menu/menu_state_join_game.h index c4cac3f8..85b1ff09 100644 --- a/source/glest_game/menu/menu_state_join_game.h +++ b/source/glest_game/menu/menu_state_join_game.h @@ -76,6 +76,7 @@ public: virtual ~MenuStateJoinGame(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); void update(); diff --git a/source/glest_game/menu/menu_state_keysetup.h b/source/glest_game/menu/menu_state_keysetup.h index add7352a..bd6a7167 100644 --- a/source/glest_game/menu/menu_state_keysetup.h +++ b/source/glest_game/menu/menu_state_keysetup.h @@ -70,6 +70,7 @@ public: virtual ~MenuStateKeysetup(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseUp(int x, int y, const MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); void update(); diff --git a/source/glest_game/menu/menu_state_load_game.cpp b/source/glest_game/menu/menu_state_load_game.cpp index 876c65e1..38c11b79 100644 --- a/source/glest_game/menu/menu_state_load_game.cpp +++ b/source/glest_game/menu/menu_state_load_game.cpp @@ -189,6 +189,12 @@ void MenuStateLoadGame::reloadUI() { GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); } +void MenuStateLoadGame::mouseDoubleClick(int x, int y, MouseButton mouseButton) { + if (mouseButton == mbLeft) { + slotsScrollBar.mouseDown(x, y); + mouseClick(loadButton.getX()+1, loadButton.getY()+1, mouseButton); + } +} void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){ CoreData &coreData= CoreData::getInstance(); diff --git a/source/glest_game/menu/menu_state_load_game.h b/source/glest_game/menu/menu_state_load_game.h index eeeb146e..ca344ce9 100644 --- a/source/glest_game/menu/menu_state_load_game.h +++ b/source/glest_game/menu/menu_state_load_game.h @@ -56,6 +56,7 @@ public: ~MenuStateLoadGame(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton); void mouseUp(int x, int y, const MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); void update(); diff --git a/source/glest_game/menu/menu_state_masterserver.h b/source/glest_game/menu/menu_state_masterserver.h index 55f2ac00..2b36f208 100644 --- a/source/glest_game/menu/menu_state_masterserver.h +++ b/source/glest_game/menu/menu_state_masterserver.h @@ -117,6 +117,7 @@ public: ~MenuStateMasterserver(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseUp(int x, int y, const MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); void update(); diff --git a/source/glest_game/menu/menu_state_mods.h b/source/glest_game/menu/menu_state_mods.h index 8ed70b05..74406eb3 100644 --- a/source/glest_game/menu/menu_state_mods.h +++ b/source/glest_game/menu/menu_state_mods.h @@ -188,6 +188,7 @@ public: virtual ~MenuStateMods(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseUp(int x, int y, const MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); void eventMouseWheel(int x, int y,int zDelta); diff --git a/source/glest_game/menu/menu_state_new_game.h b/source/glest_game/menu/menu_state_new_game.h index d8ac2d2e..d3066e5b 100644 --- a/source/glest_game/menu/menu_state_new_game.h +++ b/source/glest_game/menu/menu_state_new_game.h @@ -34,6 +34,7 @@ public: MenuStateNewGame(Program *program, MainMenu *mainMenu); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void update(); void render(); diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index ed6689b5..4dab996b 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -94,6 +94,7 @@ public: virtual ~MenuStateOptions(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); virtual bool textInput(std::string text); diff --git a/source/glest_game/menu/menu_state_options_graphics.h b/source/glest_game/menu/menu_state_options_graphics.h index 75203ac6..1b18469b 100644 --- a/source/glest_game/menu/menu_state_options_graphics.h +++ b/source/glest_game/menu/menu_state_options_graphics.h @@ -99,6 +99,7 @@ public: MenuStateOptionsGraphics(Program *program, MainMenu *mainMenu, ProgramState **parentUI=NULL); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); //virtual void keyDown(SDL_KeyboardEvent key); diff --git a/source/glest_game/menu/menu_state_options_network.h b/source/glest_game/menu/menu_state_options_network.h index 71a470fb..c518a756 100644 --- a/source/glest_game/menu/menu_state_options_network.h +++ b/source/glest_game/menu/menu_state_options_network.h @@ -70,6 +70,7 @@ public: MenuStateOptionsNetwork(Program *program, MainMenu *mainMenu, ProgramState **parentUI=NULL); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); //virtual void keyDown(SDL_KeyboardEvent key); diff --git a/source/glest_game/menu/menu_state_options_sound.h b/source/glest_game/menu/menu_state_options_sound.h index dc4cef95..05c2f3b9 100644 --- a/source/glest_game/menu/menu_state_options_sound.h +++ b/source/glest_game/menu/menu_state_options_sound.h @@ -54,6 +54,7 @@ public: MenuStateOptionsSound(Program *program, MainMenu *mainMenu, ProgramState **parentUI=NULL); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); //virtual void keyDown(SDL_KeyboardEvent key); diff --git a/source/glest_game/menu/menu_state_root.h b/source/glest_game/menu/menu_state_root.h index 29e5f2f0..9be5fbfd 100644 --- a/source/glest_game/menu/menu_state_root.h +++ b/source/glest_game/menu/menu_state_root.h @@ -62,6 +62,7 @@ public: virtual ~MenuStateRoot(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void render(); void update(); diff --git a/source/glest_game/menu/menu_state_scenario.h b/source/glest_game/menu/menu_state_scenario.h index f7889279..5a2a9244 100644 --- a/source/glest_game/menu/menu_state_scenario.h +++ b/source/glest_game/menu/menu_state_scenario.h @@ -56,6 +56,7 @@ public: virtual ~MenuStateScenario(); void mouseClick(int x, int y, MouseButton mouseButton); + void mouseDoubleClick(int x, int y, MouseButton mouseButton){}; void mouseMove(int x, int y, const MouseState *mouseState); void eventMouseWheel(int x, int y,int zDelta); void render(); From e63d8142dc84061dab98f887fcb6fe3fb0b3bba2 Mon Sep 17 00:00:00 2001 From: Andy Alt Date: Sun, 14 Aug 2022 16:41:35 -0500 Subject: [PATCH 02/19] .github/workflows/cmake.yml:cancel in progress jobs if newer job is started (#248) --- .github/workflows/cmake.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 1e8262c5..74eb4302 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,4 +1,7 @@ name: CMake +concurrency: + group: build-${{ github.ref }} + cancel-in-progress: true on: push: @@ -23,7 +26,7 @@ jobs: run: | sudo apt update sudo mk/linux/setupBuildDeps.sh - + - name: Bulid MegaGlest With GCC Compiler if: ${{ matrix.compiler == 'gcc' }} env: @@ -43,7 +46,7 @@ jobs: run: | cp mk/shared/*.ini mk/linux/ strip -g mk/linux/megaglest mk/linux/megaglest_editor mk/linux/megaglest_g3dviewer - + - name: Create Mega Glest Snapshot if: ${{ matrix.compiler == 'gcc' && matrix.os == 'ubuntu-latest' }} uses: actions/upload-artifact@v2 @@ -73,7 +76,7 @@ jobs: steps: - uses: actions/checkout@v2 - + - name: Cache Vcpkg Libs uses: actions/cache@v2 env: @@ -81,7 +84,7 @@ jobs: with: path: c:/vcpkg/installed key: vcpkg-deps - + - name: Install Dependencies run: | vcpkg integrate install @@ -121,7 +124,7 @@ jobs: - name: Build Mega Glest # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --config Release --target ALL_BUILD - + - name: Prepare Snapshot run: | cd mk/windoze @@ -129,7 +132,7 @@ jobs: $7zPath = $(Get-Command 7z).Source cp $7zPath . cd ../.. - + - name: Create Mega Glest Snapshot uses: actions/upload-artifact@v2 with: @@ -154,7 +157,7 @@ jobs: # - name: Get dependencies # run: | # brew install pkg-config cmake sdl2 lua jpeg libpng freetype ftgl libogg glew libvorbis cppunit fribidi miniupnpc curl wxmac xquartz zstd xml2 openldap - + # - name: Bulid MegaGlest With Clang Compiler # if: ${{ matrix.compiler == 'clang' }} # env: @@ -166,6 +169,6 @@ jobs: # mk/macos/build-mg.sh # - name: Test # working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. + # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail # run: ctest -C ${{env.BUILD_TYPE}} From 00fc8bcee38eef8f53127b98d4c9837af5cc152a Mon Sep 17 00:00:00 2001 From: Rampoina Date: Mon, 15 Aug 2022 01:44:37 +0200 Subject: [PATCH 03/19] Add missing check for the selected button --- source/glest_game/menu/menu_state_load_game.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/glest_game/menu/menu_state_load_game.cpp b/source/glest_game/menu/menu_state_load_game.cpp index 38c11b79..955c25bf 100644 --- a/source/glest_game/menu/menu_state_load_game.cpp +++ b/source/glest_game/menu/menu_state_load_game.cpp @@ -190,8 +190,7 @@ void MenuStateLoadGame::reloadUI() { } void MenuStateLoadGame::mouseDoubleClick(int x, int y, MouseButton mouseButton) { - if (mouseButton == mbLeft) { - slotsScrollBar.mouseDown(x, y); + if (mouseButton == mbLeft && selectedButton != NULL && selectedButton->mouseClick(x, y)) { mouseClick(loadButton.getX()+1, loadButton.getY()+1, mouseButton); } } From 77d696138ae7f165b2593da12c67abfbd3edc473 Mon Sep 17 00:00:00 2001 From: Andy Alt Date: Sat, 20 Aug 2022 17:29:38 -0500 Subject: [PATCH 04/19] workflows/cmake.yml:add tests for recent gcc versions;migrate to checkoutv3 (#250) * workflows/cmake.yml:test on Ubuntu Jammy (22.04);migrate to checkoutv3 This should also fix #247 * maybe fix ssh link error on Ubuntu Jammy gcc and clang build is failing on Jammy with the message: 'cannot find -lssh: No such file or directory' Basically I added libcurl-openssl-dev to the deps * remove libcurl4-gnutls-dev Trying to correct: The following packages have unmet dependencies: libcurl4-gnutls-dev : Conflicts: libcurl4-openssl-dev but 7.81.0-1ubuntu1.3 is to be installed libcurl4-openssl-dev : Conflicts: libcurl4-gnutls-dev but 7.81.0-1ubuntu1.3 is to be installed E: Unable to correct problems, you have held broken packages. An error occurred while installing build dependencies. * use cmake FindCURL module * for OpenSSL, use include instead of find_package * remove jammy, add gcc-10 and 11 test * revert now-unrelated changes * clean-up * add VERBOSE flag to make * Update .github/workflows/cmake.yml * Update .github/workflows/cmake.yml * use '-f' option from build script to force clang * force dynamic libs with '-d' fixes #251 * mk/linux/setupBuildDeps.sh:fix script so 22.04 is detected *remove vlc deps (not required for the CI) *remove ubuntu-18.04 from the build matrix, see https://github.blog/changelog/2022-08-09-github-actions-the-ubuntu-18-04-actions-runner-image-is-being-deprecated-and-will-be-removed-by-12-1-22/ * revert removal of commented macos jobs * run apt-get update and upgrade * cleanup Prep snapshot section --- .github/workflows/cmake.yml | 69 ++++++++++++++++------------------ .github/workflows/snapshot.yml | 39 +++++++++++++++++++ mk/linux/setupBuildDeps.sh | 14 +++---- 3 files changed, 77 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/snapshot.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 74eb4302..d616f2d5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -15,49 +15,46 @@ jobs: fail-fast: false matrix: arch: [x64] - os: [ubuntu-18.04, ubuntu-latest] + os: [ubuntu-20.04, ubuntu-22.04] compiler: [gcc, clang] runs-on: ${{ matrix.os }} - + env: + MATRIX_COMPILER: ${{matrix.compiler}} + MATRIX_OS: ${{matrix.os}} steps: - - uses: actions/checkout@v2 - + - uses: actions/checkout@v3 - name: Get dependencies run: | - sudo apt update + sudo apt-get update && sudo apt-get upgrade sudo mk/linux/setupBuildDeps.sh + - name: Build + run: | + if [ "${MATRIX_COMPILER}" = "clang" ]; then + EXTRA_OPTS="-f" + fi + mk/linux/build-mg.sh -m -d ${EXTRA_OPTS} + make -C mk/linux/build -j$(nproc) VERBOSE=1 - - name: Bulid MegaGlest With GCC Compiler - if: ${{ matrix.compiler == 'gcc' }} - env: - CC: gcc - CXX: g++ - run: mk/linux/build-mg.sh - - - name: Bulid MegaGlest With Clang Compiler - if: ${{ matrix.compiler == 'clang' }} - env: - CC: clang - CXX: clang++ - run: mk/linux/build-mg.sh - - - name: Prepare Snapshot - if: ${{ matrix.compiler == 'gcc' && matrix.os == 'ubuntu-latest' }} + build-linux-other: + strategy: + fail-fast: false + matrix: + compiler: [10, 12] # 11 is on 22.04 by default, tested above + runs-on: ubuntu-22.04 + env: + CC: gcc-${{matrix.compiler}} + CXX: g++-${{matrix.compiler}} + steps: + - uses: actions/checkout@v3 + - name: Get dependencies run: | - cp mk/shared/*.ini mk/linux/ - strip -g mk/linux/megaglest mk/linux/megaglest_editor mk/linux/megaglest_g3dviewer - - - name: Create Mega Glest Snapshot - if: ${{ matrix.compiler == 'gcc' && matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v2 - with: - name: megaglest-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.compiler }} - path: | - mk/linux/megaglest - mk/linux/megaglest_editor - mk/linux/megaglest_g3dviewer - mk/linux/*.ini - !mk/linux/glest-dev.ini + sudo apt-get update && sudo apt-get upgrade + sudo apt-get install -y $CXX + sudo mk/linux/setupBuildDeps.sh + - name: Build + run: | + mk/linux/build-mg.sh -d -m + make -C mk/linux/build -j$(nproc) VERBOSE=1 build-win64: # The CMake configure and build commands are platform agnostic and should work equally @@ -75,7 +72,7 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache Vcpkg Libs uses: actions/cache@v2 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 00000000..c1d66161 --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,39 @@ +name: Make Snapshot +concurrency: + group: build-${{ github.ref }} + cancel-in-progress: true +on: + push: + branches: [ develop ] + +# The artifact only runs on the same distro that it was built on. +# TODO: make AppImage instead +jobs: + make-snapshot: + strategy: + fail-fast: false + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Get dependencies + run: | + sudo apt-get update && sudo apt-get upgrade + sudo mk/linux/setupBuildDeps.sh + - name: Build + run: | + mk/linux/build-mg.sh -m + make -C mk/linux/build -j$(nproc) VERBOSE=1 + - name: Prepare Snapshot + run: | + cp mk/shared/*.ini mk/linux/ + strip -g mk/linux/megaglest mk/linux/megaglest_editor mk/linux/megaglest_g3dviewer + - name: Create Mega Glest Snapshot + uses: actions/upload-artifact@v2 + with: + name: megaglest-x64-ubuntu-20.04-gcc + path: | + mk/linux/megaglest + mk/linux/megaglest_editor + mk/linux/megaglest_g3dviewer + mk/linux/*.ini + !mk/linux/glest-dev.ini diff --git a/mk/linux/setupBuildDeps.sh b/mk/linux/setupBuildDeps.sh index ba3b5bb9..a127cd8b 100755 --- a/mk/linux/setupBuildDeps.sh +++ b/mk/linux/setupBuildDeps.sh @@ -159,13 +159,9 @@ case $distribution in #name > zesty, EoL January 2018 installcommand="apt-get install $APT_OPTIONS build-essential cmake libcurl4-gnutls-dev libsdl2-dev libopenal-dev liblua5.3-dev libjpeg-dev libpng-dev libfreetype6-dev libwxgtk3.0-dev libcppunit-dev libfribidi-dev libftgl-dev libglew-dev libogg-dev libvorbis-dev libminiupnpc-dev libircclient-dev libvlc-dev libvlccore-dev libxml2-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev librtmp-dev libkrb5-dev libldap2-dev libidn11-dev libgnutls28-dev libnghttp2-dev libssh2-1-dev libidn2-dev libpsl-dev" ;; - 18.04) - #name > bionic - installcommand="apt-get install $APT_OPTIONS build-essential cmake libcurl4-gnutls-dev libsdl2-dev libopenal-dev liblua5.3-dev libjpeg-dev libpng-dev libfreetype6-dev libwxgtk3.0-dev libcppunit-dev libfribidi-dev libftgl-dev libglew-dev libogg-dev libvorbis-dev libminiupnpc-dev libircclient-dev libvlc-dev libvlccore-dev libxml2-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev librtmp-dev libkrb5-dev libldap2-dev libidn11-dev libgnutls28-dev libnghttp2-dev libssh2-1-dev libidn2-dev libpsl-dev" - ;; - 20.04) - #name > Focal Fossa - installcommand="apt-get install $APT_OPTIONS build-essential cmake libcurl4-gnutls-dev libsdl2-dev libopenal-dev liblua5.3-dev libjpeg-dev libpng-dev libfreetype6-dev libwxgtk3.0-gtk3-dev libcppunit-dev libfribidi-dev libftgl-dev libglew-dev libogg-dev libvorbis-dev libminiupnpc-dev libircclient-dev libvlc-dev libvlccore-dev libxml2-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev librtmp-dev libkrb5-dev libldap2-dev libidn2-dev libpsl-dev libgnutls28-dev libnghttp2-dev libssh-dev libbrotli-dev" + "18.04"|"20.04"|"22.04") + #name > Bionic, Focal Fossa, Jammy Jellyfish + installcommand="apt-get install $APT_OPTIONS build-essential cmake libcurl4-gnutls-dev libsdl2-dev libopenal-dev liblua5.3-dev libjpeg-dev libpng-dev libfreetype6-dev libwxgtk3.0-gtk3-dev libcppunit-dev libfribidi-dev libftgl-dev libglew-dev libogg-dev libvorbis-dev libminiupnpc-dev libircclient-dev libxml2-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev librtmp-dev libkrb5-dev libldap2-dev libidn2-dev libpsl-dev libgnutls28-dev libnghttp2-dev libssh-dev libbrotli-dev" ;; *) installcommand="apt-get install $APT_OPTIONS $packages_for_next_debian_ubuntu_mint" @@ -177,7 +173,7 @@ case $distribution in case $release in 20.04) #name > Focal Fossa - installcommand="apt-get install $APT_OPTIONS build-essential cmake libcurl4-gnutls-dev libsdl2-dev libopenal-dev liblua5.3-dev libjpeg-dev libpng-dev libfreetype6-dev libwxgtk3.0-gtk3-dev libcppunit-dev libfribidi-dev libftgl-dev libglew-dev libogg-dev libvorbis-dev libminiupnpc-dev libircclient-dev libvlc-dev libvlccore-dev libxml2-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev librtmp-dev libkrb5-dev libldap2-dev libidn2-dev libpsl-dev libgnutls28-dev libnghttp2-dev libssh-dev libbrotli-dev" + installcommand="apt-get install $APT_OPTIONS build-essential cmake libcurl4-gnutls-dev libsdl2-dev libopenal-dev liblua5.3-dev libjpeg-dev libpng-dev libfreetype6-dev libwxgtk3.0-gtk3-dev libcppunit-dev libfribidi-dev libftgl-dev libglew-dev libogg-dev libvorbis-dev libminiupnpc-dev libircclient-dev libxml2-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev librtmp-dev libkrb5-dev libldap2-dev libidn2-dev libpsl-dev libgnutls28-dev libnghttp2-dev libssh-dev libbrotli-dev" ;; *) installcommand="apt-get install $APT_OPTIONS $packages_for_next_debian_ubuntu_mint" @@ -185,7 +181,7 @@ case $distribution in ;; esac ;; - + LinuxMint|Linuxmint) case $release in 2) From 332780950bb282693c5eeb87554a846ba89e14b1 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Wed, 10 Aug 2022 02:22:42 +0200 Subject: [PATCH 05/19] Fix unit/building progress not getting restored when loading a game --- source/glest_game/type_instances/unit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index d13d897e..dc81399c 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -5342,7 +5342,9 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * string skillTypeName = unitNode->getAttribute("currSkillName")->getValue(); SkillClass skillClass = static_cast(unitNode->getAttribute("currSkillClass")->getIntValue()); result->currSkill = ut->getSkillType(skillTypeName,skillClass); + int tempProgress2 = result->progress2; // setCurrSkill overwrites progress2 result->setCurrSkill(result->currSkill); + result->progress2 = tempProgress2; // restore it } // int lastModelIndexForCurrSkillType; From 35ff02052ce8b3293b575dc052170386c33a4c8a Mon Sep 17 00:00:00 2001 From: Banestorm Date: Sat, 16 Jul 2022 21:17:46 -0500 Subject: [PATCH 06/19] Remove command priority system This was resulting in non-intuitive and surprising behaviour when queuing commands. Removing this system results in Megaglest behaving more like other RTS games. For instance, the following are now possible and weren't previously: - Queuing multiple attack ground commands to move along a specific path attacking all enemies on the way. - Queuing attack ground followed by hold position, which is a sensible thing to do if you want a unit to guard a specific area. - Queuing a move command followed by a produce command, if you want to have your summoner summon a daemon at a specific location. The behaviour of queuing the stop command is unchanged, and commands that must be the last in the queue, such as morphing, are still properly replaced when something else is queued. --- source/glest_game/type_instances/command.cpp | 6 ----- source/glest_game/type_instances/command.h | 3 --- source/glest_game/type_instances/unit.cpp | 28 -------------------- source/glest_game/types/command_type.h | 6 +---- source/glest_game/world/unit_updater.cpp | 14 ---------- 5 files changed, 1 insertion(+), 56 deletions(-) diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index 56f45b50..c35af60a 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -76,12 +76,6 @@ Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitTy //} } -int Command::getPriority(){ - if(this->commandType->commandTypeClass==ccAttack && getUnit()==NULL){ - return 5; // attacks to the ground have low priority - } - return this->commandType->getTypePriority(); -} // =============== set =============== void Command::setCommandType(const CommandType *commandType) { diff --git a/source/glest_game/type_instances/command.h b/source/glest_game/type_instances/command.h index 8c04fea4..922ec9fc 100644 --- a/source/glest_game/type_instances/command.h +++ b/source/glest_game/type_instances/command.h @@ -71,9 +71,6 @@ public: inline const UnitType* getUnitType() const {return unitType;} inline CardinalDir getFacing() const {return facing;} - //Priority: commands of higher priority will cancel commands of lower priority - virtual int getPriority(); - //set void setCommandType(const CommandType *commandType); void setPos(const Vec2i &pos); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index dc81399c..429a2334 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1828,8 +1828,6 @@ std::pair Unit::giveCommand(Command *command, bool tryQueu throw megaglest_runtime_error("command->getCommandType() == NULL"); } - const int command_priority = command->getPriority(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); //printf("In [%s::%s] Line: %d unit [%d - %s] command [%s] tryQueue = %d command->getCommandType()->isQueuable(tryQueue) = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getId(),this->getType()->getName().c_str(), command->getCommandType()->getName().c_str(), tryQueue,command->getCommandType()->isQueuable(tryQueue)); @@ -1839,32 +1837,6 @@ std::pair Unit::giveCommand(Command *command, bool tryQueu if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Command is Queable\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - if(command->getCommandType()->isQueuable() == qAlways && tryQueue){ - // Its a produce or upgrade command called without queued key - // in this case we must NOT delete lower priority commands! - // we just queue it! - - } - else { - //Delete all lower-prioirty commands - for(list::iterator i= commands.begin(); i != commands.end();){ - if((*i)->getPriority() < command_priority){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) - SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Deleting lower priority command [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(*i)->toString(false).c_str()); - - static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); - MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId); - - deleteQueuedCommand(*i); - i= commands.erase(i); - - safeMutex.ReleaseLock(); - } - else { - ++i; - } - } - } if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); //cancel current command if it is not queuable diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index 913272c5..8808d27d 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -108,8 +108,6 @@ public: Queueability q = isQueuable(); return (q != qNever) && (q != qOnlyLast); } - //Priority: commands of higher priority will cancel commands of lower priority - virtual int getTypePriority() const {return 10;} virtual bool usesPathfinder() const= 0; //get @@ -139,7 +137,6 @@ public: virtual string getDesc(const TotalUpgrade *totalUpgrade, bool translatedValue) const; virtual string toString(bool translatedValue) const; virtual Queueability isQueuable() const {return qNever;} - virtual int getTypePriority() const {return 100000;} //get const StopSkillType *getStopSkillType() const {return stopSkillType;}; @@ -213,6 +210,7 @@ public: const TechTree *tt, const FactionType *ft, const UnitType &ut, std::map > > &loadedFileList, string parentLoader); virtual string getDesc(const TotalUpgrade *totalUpgrade, bool translatedValue) const; + virtual Queueability isQueuable() const {return qOnlyLast;} virtual string toString(bool translatedValue) const; //get @@ -369,7 +367,6 @@ public: virtual string toString(bool translatedValue) const; virtual const ProducibleType *getProduced() const; virtual Queueability isQueuable() const {return qAlways;} - virtual int getTypePriority() const {return 15;} //get const ProduceSkillType *getProduceSkillType() const {return produceSkillType;} @@ -399,7 +396,6 @@ public: virtual string getReqDesc(bool translatedValue) const; virtual const ProducibleType *getProduced() const; virtual Queueability isQueuable() const {return qAlways;} - virtual int getTypePriority() const {return 15;} //get const UpgradeSkillType *getUpgradeSkillType() const {return upgradeSkillType;} diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 88fa1dd3..15c4e2bc 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -720,20 +720,6 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - if( (command->getUnit() == NULL || !(command->getUnit()->isAlive()) ) && unit->getCommandSize() > 1) { - - if(frameIndex < 0) { - unit->finishCommand(); // all queued "ground attacks" are skipped if somthing else is queued after them. - - if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"[updateAttack]"); - unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); - } - } - return; - } - //if found //if(frameIndex < 0) { { From 0b1dcc70f5591bfbb715aea251dd9cd84ab35f15 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Sat, 27 Aug 2022 15:16:25 +0400 Subject: [PATCH 07/19] feat: allow queue after Morph commands --- source/glest_game/game/commander.cpp | 19 ++++-- source/glest_game/gui/gui.cpp | 6 +- source/glest_game/network/network_types.cpp | 67 ++++++++++++--------- source/glest_game/type_instances/unit.cpp | 12 ++++ source/glest_game/type_instances/unit.h | 1 + source/glest_game/types/command_type.h | 2 +- 6 files changed, 72 insertions(+), 35 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index a9f10b75..a6881800 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -263,8 +263,12 @@ std::pair Commander::tryGiveCommand(const Selection *selec int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= unit->getId(); Vec2i currPos= world->getMap()->computeDestPos(refPos, unit->getPosNotThreadSafe(), pos); + int unitTypeId= -1; + auto mct= unit->getCurrMorphCt(); + if(mct) unitTypeId= mct->getMorphUnit()->getId(); + NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, - commandType->getId(), currPos, -1, targetId, -1, tryQueue, + commandType->getId(), currPos, unitTypeId, targetId, -1, tryQueue, cst_None, -1, unitCommandGroupId); //every unit is ordered to a different position @@ -316,13 +320,16 @@ std::pair Commander::tryGiveCommand(const Selection *selec if(commandType != NULL) { int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= unit->getId(); + int unitTypeId= -1; + auto mct= unit->getCurrMorphCt(); + if(mct) unitTypeId= mct->getMorphUnit()->getId(); std::pair resultCur(crFailUndefined,""); bool canSubmitCommand=canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { NetworkCommand networkCommand(this->world,nctGiveCommand, - unitId, commandType->getId(), currPos, -1, targetId, + unitId, commandType->getId(), currPos, unitTypeId, targetId, -1, tryQueue, cst_None, -1, unitCommandGroupId); resultCur= pushNetworkCommand(&networkCommand); } @@ -950,7 +957,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const { throw megaglest_runtime_error(szBuf); } - ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId()); + ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId()); if(unit->getFaction()->getIndex() != networkCommand->getUnitFactionIndex()) { @@ -984,7 +991,11 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const { throw megaglest_runtime_error(sError); } - const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId()); + const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId()); + + if( networkCommand->getUnitTypeId() > -1 && networkCommand->getWantQueue()) { //Morph Queue + ct = unitType->findCommandTypeById(networkCommand->getCommandTypeId()); + } // debug test! //throw megaglest_runtime_error("Test missing command type!"); diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index ce6f79f6..a0ebeba9 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -552,7 +552,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) { else { result= commander->tryGiveCommand(&selection, activeCommandClass, targetPos, targetUnit,queueKeyDown); - } + } } else { //selecting building @@ -969,6 +969,10 @@ void Gui::computeDisplay(){ //uniform selection if(u->isBuilt()){ //printf("u->isBuilt()\n"); + auto mct = u->getCurrMorphCt(); + if(mct && isKeyDown(queueCommandKey)) {//Morph Queue + ut=mct->getMorphUnit(); + } int morphPos= 8; for(int i= 0; i < ut->getCommandTypeCount(); ++i){ diff --git a/source/glest_game/network/network_types.cpp b/source/glest_game/network/network_types.cpp index 62b73425..db2c4ac4 100644 --- a/source/glest_game/network/network_types.cpp +++ b/source/glest_game/network/network_types.cpp @@ -48,43 +48,52 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, this->targetId = targetId >= 0 ? targetId : facing; this->fromFactionIndex = world->getThisFactionIndex(); - if(this->networkCommandType == nctGiveCommand) { - const Unit *unit= world->findUnitById(this->unitId); + if(this->networkCommandType == nctGiveCommand) { + const Unit *unit= world->findUnitById(this->unitId); - //validate unit - if(unit != NULL) { - this->unitFactionIndex = unit->getFaction()->getIndex(); - this->unitFactionUnitCount = unit->getFaction()->getUnitCount(); + //validate unit + if(unit != NULL) { + this->unitFactionIndex = unit->getFaction()->getIndex(); + this->unitFactionUnitCount = unit->getFaction()->getUnitCount(); - //const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId); - const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId); - if(ct != NULL && ct->getClass() == ccBuild) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); - CardinalDir::assertDirValid(facing); - assert(targetId == -1); - } - } - } + const CommandType *ct= unit->getType()->findCommandTypeById(this->commandTypeId); + if(unitTypeId > -1) { + const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId); + ct= unitType->findCommandTypeById(this->commandTypeId); + } + + if(ct != NULL && ct->getClass() == ccBuild) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); + CardinalDir::assertDirValid(facing); + assert(targetId == -1); + } + } + } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Created NetworkCommand as follows:\n%s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Created NetworkCommand as follows:\n%s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); } void NetworkCommand::preprocessNetworkCommand(World *world) { - if(networkCommandType == nctGiveCommand) { - const Unit *unit= world->findUnitById(unitId); + if(networkCommandType == nctGiveCommand) { + const Unit *unit= world->findUnitById(unitId); - //validate unit - if(unit != NULL) { - //const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId); - const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId); - if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) { + //validate unit + if(unit != NULL) { + + const CommandType *ct= unit->getType()->findCommandTypeById(commandTypeId); + if(unitTypeId > -1) { + const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId); + ct= unitType->findCommandTypeById(this->commandTypeId); + } + + if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) { CardinalDir::assertDirValid(targetId); - } - } - else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] (unit == NULL) %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); - } - } + } + } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] (unit == NULL) %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); + } + } } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 429a2334..6f6788f6 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -745,6 +745,15 @@ void Unit::cleanupAllParticlesystems() { } +const MorphCommandType* Unit::getCurrMorphCt() const { + auto result = std::find_if(commands.rbegin(), commands.rend(),[](Command *i) + { return i->getCommandType()->getClass() == ccMorph? true: false; }); + if(result != commands.rend()) { + return static_cast((*result)->getCommandType()); + } + else return NULL; +} + ParticleSystem * Unit::getFire() const { if(this->fire != NULL && Renderer::getInstance().validateParticleSystemStillExists(this->fire,rsGame) == false) { @@ -3826,6 +3835,9 @@ std::pair Unit::checkCommand(Command *command) const { this->getType()->getFirstRepairCommand(this->getType()) != NULL) { } + else if(getCurrMorphCt()->getMorphUnit()->hasCommandType(command->getCommandType())) { + // Allow Current Morph Commands + } else { //printf("In [%s::%s Line: %d] command = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,command); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 1760f17e..80ac488f 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -653,6 +653,7 @@ public: } return NULL; } + const MorphCommandType* getCurrMorphCt() const; void replaceCurrCommand(Command *cmd); int getCountOfProducedUnitsPreExistence(const UnitType *ut) const; unsigned int getCommandSize() const; diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index 8808d27d..42dd6f01 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -425,7 +425,7 @@ public: virtual string toString(bool translatedValue) const; virtual string getReqDesc(bool translatedValue) const; virtual const ProducibleType *getProduced() const; - Queueability isQueuable() const {return qOnlyLast;} //After morph anything can happen + Queueability isQueuable() const {return qAlways;} //After morph anything can happen //get const MorphSkillType *getMorphSkillType() const {return morphSkillType;} From 37b6fbb12e9ec99732ef5551bb4302775fedffc3 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Sat, 27 Aug 2022 15:56:40 +0400 Subject: [PATCH 08/19] fix: checkCommand + TODO --- source/glest_game/gui/gui.cpp | 2 +- source/glest_game/type_instances/unit.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index a0ebeba9..8970e0c6 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -972,7 +972,7 @@ void Gui::computeDisplay(){ auto mct = u->getCurrMorphCt(); if(mct && isKeyDown(queueCommandKey)) {//Morph Queue ut=mct->getMorphUnit(); - } + }//TODO subscribe on queueCommandKey presed => resetState() and may remove stop cmd int morphPos= 8; for(int i= 0; i < ut->getCommandTypeCount(); ++i){ diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 6f6788f6..c32daa83 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -3829,13 +3829,14 @@ std::pair Unit::checkCommand(Command *command) const { (ignoreCheckCommand == false && this->getFaction()->reqsOk(command->getCommandType()) == false)) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] isOperative() = %d, command->getUnit() = %p, getType()->hasCommandType(command->getCommandType()) = %d, this->getFaction()->reqsOk(command->getCommandType()) = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__, __LINE__,isOperative(),command->getUnit(),getType()->hasCommandType(command->getCommandType()),this->getFaction()->reqsOk(command->getCommandType())); + auto mct = getCurrMorphCt(); // Allow self healing if able to heal own unit type if( command->getUnit() == this && command->getCommandType()->getClass() == ccRepair && this->getType()->getFirstRepairCommand(this->getType()) != NULL) { } - else if(getCurrMorphCt()->getMorphUnit()->hasCommandType(command->getCommandType())) { + else if(mct && mct->getMorphUnit()->hasCommandType(command->getCommandType())) { // Allow Current Morph Commands } else { From d2d691024ef32c5f5e472a3dbd104c8791b6ff9b Mon Sep 17 00:00:00 2001 From: pavanvo Date: Sat, 27 Aug 2022 16:19:54 +0400 Subject: [PATCH 09/19] fix: non-targed commands + TODO --- source/glest_game/gui/gui.cpp | 3 +++ source/glest_game/type_instances/unit.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 8970e0c6..608a4beb 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -707,6 +707,9 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { if (activeCommandClass == ccAttack) { ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass); } + auto mct= unit->getCurrMorphCt(); + if(mct) ct= mct->getMorphUnit()->getFirstCtOfClass(activeCommandClass); + if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){ assert(selection.isUniform()); selectingBuilding= true; diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index c32daa83..bb1d543c 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -747,7 +747,7 @@ void Unit::cleanupAllParticlesystems() { const MorphCommandType* Unit::getCurrMorphCt() const { auto result = std::find_if(commands.rbegin(), commands.rend(),[](Command *i) - { return i->getCommandType()->getClass() == ccMorph? true: false; }); + { return i->getCommandType()->getClass() == ccMorph; });//TODO set CurrMorphCt on push comands instead of looping if(result != commands.rend()) { return static_cast((*result)->getCommandType()); } From 35f755841d680cb864c7dbf5474c356ad662bf90 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Sun, 4 Sep 2022 13:09:32 +0400 Subject: [PATCH 10/19] feat: gui hotkey released --- source/glest_game/game/game.cpp | 3 +++ source/glest_game/gui/gui.cpp | 14 ++++++++++++-- source/glest_game/gui/gui.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 178f68b4..1768476d 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5005,7 +5005,10 @@ void Game::keyUp(SDL_KeyboardEvent key) { gameCamera.setMoveX(0); camRightButtonDown= false; calcCameraMoveX(); + } else { + gui.hotKeyReleased(key); } + } } catch(const exception &ex) { diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 608a4beb..1f9c80b3 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -447,6 +447,16 @@ void Gui::hotKey(SDL_KeyboardEvent key) { else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { clickCommonCommand(ccStop); } + + if(isKeyDown(queueCommandKey)) { + computeDisplay(); + } +} + +void Gui::hotKeyReleased(SDL_KeyboardEvent key) { + if(!isKeyDown(queueCommandKey)) { + computeDisplay(); + } } void Gui::switchToNextDisplayColor(){ @@ -975,7 +985,7 @@ void Gui::computeDisplay(){ auto mct = u->getCurrMorphCt(); if(mct && isKeyDown(queueCommandKey)) {//Morph Queue ut=mct->getMorphUnit(); - }//TODO subscribe on queueCommandKey presed => resetState() and may remove stop cmd + }//TODO on queueCommandKey presed disable stop cmd int morphPos= 8; for(int i= 0; i < ut->getCommandTypeCount(); ++i){ @@ -996,7 +1006,7 @@ void Gui::computeDisplay(){ display.setCommandType(displayPos, ct); display.setCommandClass(displayPos, ct->getClass()); bool reqOk=u->getFaction()->reqsOk(ct); - display.setDownLighted(displayPos,reqOk); + display.setDownLighted(displayPos, reqOk && !(!ct->isQueueAppendable() && isKeyDown(queueCommandKey))); if (reqOk && produced != NULL) { if (possibleAmount == 0) { diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index c9c8905c..fe8db1e3 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -196,6 +196,7 @@ public: void mouseDoubleClickLeftGraphics(int x, int y); void groupKey(int groupIndex); void hotKey(SDL_KeyboardEvent key); + void hotKeyReleased(SDL_KeyboardEvent key); //misc void switchToNextDisplayColor(); From c9c1adf8d092d17c10d484298c00918f04c56c63 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Mon, 5 Sep 2022 04:27:22 +0400 Subject: [PATCH 11/19] refactor: correct tabs --- source/glest_game/world/unit_updater.cpp | 530 +++++++++++------------ 1 file changed, 248 insertions(+), 282 deletions(-) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 15c4e2bc..a650ee25 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -720,153 +720,137 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - //if found - //if(frameIndex < 0) { - { - if(attackableOnRange(unit, &target, act->getAttackSkillType(),(frameIndex >= 0))) { - if(frameIndex < 0) { - if(unit->getEp() >= act->getAttackSkillType()->getEpCost()) { - unit->setCurrSkill(act->getAttackSkillType()); - unit->setTarget(target); - } - else { - unit->setCurrSkill(scStop); - } - + + if(attackableOnRange(unit, &target, act->getAttackSkillType(),(frameIndex >= 0))) { + if(frameIndex < 0) { + if(unit->getEp() >= act->getAttackSkillType()->getEpCost()) { + unit->setCurrSkill(act->getAttackSkillType()); + unit->setTarget(target); + } + else { + unit->setCurrSkill(scStop); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"[updateAttack]"); + unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); + } + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + } + else { + //compute target pos + Vec2i pos; + if(command->getUnit() != NULL) { + pos= command->getUnit()->getCenteredPos(); + } + else if(attackableOnSight(unit, &target, act->getAttackSkillType(), (frameIndex >= 0))) { + pos= target->getPos(); + } + else { + pos= command->getPos(); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"[updateAttack] pos [%s] unit->getPos() [%s]",pos.getString().c_str(),unit->getPos().getString().c_str()); + unit->logSynchData(__FILE__,__LINE__,szBuf); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + TravelState tsValue = tsImpossible; + //if(frameIndex < 0) { + { + //printf("In [%s::%s Line: %d] START pathfind for attacker [%d - %s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(), unit->getType()->getName().c_str()); + //fflush(stdout); + switch(this->game->getGameSettings()->getPathFinderType()) { + case pfBasic: + tsValue = pathFinder->findPath(unit, pos, NULL, frameIndex); + break; + default: + throw megaglest_runtime_error("detected unsupported pathfinder type!"); + } + //printf("In [%s::%s Line: %d] END pathfind for attacker [%d - %s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(), unit->getType()->getName().c_str()); + //fflush(stdout); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(frameIndex < 0) { + if(command->getUnit() != NULL && !command->getUnit()->isAlive() && unit->getCommandSize() > 1) { + // don't run over to dead body if there is still something to do in the queue + unit->finishCommand(); if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { char szBuf[8096]=""; snprintf(szBuf,8096,"[updateAttack]"); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); } - } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - } - else { - //compute target pos - Vec2i pos; - if(command->getUnit() != NULL) { - pos= command->getUnit()->getCenteredPos(); - } - else if(attackableOnSight(unit, &target, act->getAttackSkillType(), (frameIndex >= 0))) { - pos= target->getPos(); } else { - pos= command->getPos(); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"[updateAttack] pos [%s] unit->getPos() [%s]",pos.getString().c_str(),unit->getPos().getString().c_str()); - unit->logSynchData(__FILE__,__LINE__,szBuf); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - - TravelState tsValue = tsImpossible; - //if(frameIndex < 0) { - { - //printf("In [%s::%s Line: %d] START pathfind for attacker [%d - %s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(), unit->getType()->getName().c_str()); - //fflush(stdout); - switch(this->game->getGameSettings()->getPathFinderType()) { - case pfBasic: - tsValue = pathFinder->findPath(unit, pos, NULL, frameIndex); + //if unit arrives destPos order has ended + if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0 && + SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynchMax).enabled == true) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"#1 [updateAttack] tsValue = %d",tsValue); + unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); + } + switch (tsValue) { + case tsMoving: + unit->setCurrSkill(act->getMoveSkillType()); + break; + case tsBlocked: + if(unit->getPath()->isBlocked()) { + unit->finishCommand(); + } break; default: - throw megaglest_runtime_error("detected unsupported pathfinder type!"); - } - //printf("In [%s::%s Line: %d] END pathfind for attacker [%d - %s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(), unit->getType()->getName().c_str()); - //fflush(stdout); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - - if(frameIndex < 0) { - if(command->getUnit() != NULL && !command->getUnit()->isAlive() && unit->getCommandSize() > 1) { - // don't run over to dead body if there is still something to do in the queue - unit->finishCommand(); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"[updateAttack]"); - unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); + unit->finishCommand(); + break; } - } - else { - //if unit arrives destPos order has ended - if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0 && - SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynchMax).enabled == true) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"#1 [updateAttack] tsValue = %d",tsValue); - unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); - } - - switch (tsValue) { - case tsMoving: - unit->setCurrSkill(act->getMoveSkillType()); - break; - case tsBlocked: - if(unit->getPath()->isBlocked()) { - unit->finishCommand(); - } - break; - default: - unit->finishCommand(); - break; - } /* - case tsMoving: - unit->setCurrSkill(act->getMoveSkillType()); - - { - std::pair beingAttacked = unitBeingAttacked(unit); - if(beingAttacked.first == true) { - Unit *enemy = beingAttacked.second; - const AttackCommandType *act_forenemy = unit->getType()->getFirstAttackCommand(enemy->getCurrField()); - if(act_forenemy != NULL) { - if(unit->getEp() >= act_forenemy->getAttackSkillType()->getEpCost()) { - unit->setCurrSkill(act_forenemy->getAttackSkillType()); - unit->setTarget(enemy); - } - //aiInterface->giveCommand(i, act_forenemy, beingAttacked.second->getPos()); + case tsMoving: + unit->setCurrSkill(act->getMoveSkillType()); + { + std::pair beingAttacked = unitBeingAttacked(unit); + if(beingAttacked.first == true) { + Unit *enemy = beingAttacked.second; + const AttackCommandType *act_forenemy = unit->getType()->getFirstAttackCommand(enemy->getCurrField()); + if(act_forenemy != NULL) { + if(unit->getEp() >= act_forenemy->getAttackSkillType()->getEpCost()) { + unit->setCurrSkill(act_forenemy->getAttackSkillType()); + unit->setTarget(enemy); } - else { - const AttackStoppedCommandType *asct_forenemy = unit->getType()->getFirstAttackStoppedCommand(enemy->getCurrField()); - if(asct_forenemy != NULL) { - //aiInterface->giveCommand(i, asct_forenemy, beingAttacked.second->getCenteredPos()); - if(unit->getEp() >= asct_forenemy->getAttackSkillType()->getEpCost()) { - unit->setCurrSkill(asct_forenemy->getAttackSkillType()); - unit->setTarget(enemy); - } + //aiInterface->giveCommand(i, act_forenemy, beingAttacked.second->getPos()); + } + else { + const AttackStoppedCommandType *asct_forenemy = unit->getType()->getFirstAttackStoppedCommand(enemy->getCurrField()); + if(asct_forenemy != NULL) { + //aiInterface->giveCommand(i, asct_forenemy, beingAttacked.second->getCenteredPos()); + if(unit->getEp() >= asct_forenemy->getAttackSkillType()->getEpCost()) { + unit->setCurrSkill(asct_forenemy->getAttackSkillType()); + unit->setTarget(enemy); } } } } - - break; - - case tsBlocked: - if(unit->getPath()->isBlocked()){ - unit->finishCommand(); - } - break; - default: + } + break; + case tsBlocked: + if(unit->getPath()->isBlocked()){ unit->finishCommand(); - } + } + break; + default: + unit->finishCommand(); + } */ - - if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0 && - SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynchMax).enabled == true) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"#2 [updateAttack] tsValue = %d",tsValue); - unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); - } - + if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0 && + SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynchMax).enabled == true) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"#2 [updateAttack] tsValue = %d",tsValue); + unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf); } } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } - } + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -2904,97 +2888,86 @@ void UnitUpdater::findEnemiesForCell(const Vec2i pos, int size, int sightRange, //if the unit has any enemy on range bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, - const AttackSkillType *ast,bool evalMode) { + const AttackSkillType *ast,bool evalMode) { bool result=false; try { - vector enemies; - enemies.reserve(100); + vector enemies; + enemies.reserve(100); - //we check command target - const Unit *commandTarget = NULL; - if(unit->anyCommand() && unit->getCurrCommand() != NULL) { - commandTarget = static_cast(unit->getCurrCommand()->getUnit()); - } - if(commandTarget != NULL && commandTarget->isDead()) { - commandTarget = NULL; - } - //aux vars - int size = unit->getType()->getSize(); - Vec2i center = unit->getPos(); - Vec2f floatCenter = unit->getFloatCenteredPos(); + //we check command target + const Unit *commandTarget = NULL; + if(unit->anyCommand() && unit->getCurrCommand() != NULL) { + commandTarget = static_cast(unit->getCurrCommand()->getUnit()); + } + if(commandTarget != NULL && commandTarget->isDead()) { + commandTarget = NULL; + } + //aux vars + int size = unit->getType()->getSize(); + Vec2i center = unit->getPos(); + Vec2f floatCenter = unit->getFloatCenteredPos(); - //bool foundInCache = true; - if(findCachedCellsEnemies(center,range,size,enemies,ast, - unit,commandTarget) == false) { + //bool foundInCache = true; + if(findCachedCellsEnemies(center,range,size,enemies,ast, + unit,commandTarget) == false) { - //foundInCache = false; - //nearby cells - UnitRangeCellsLookupItem cacheItem; - for(int i = center.x - range; i < center.x + range + size; ++i) { - for(int j = center.y - range; j < center.y + range + size; ++j) { - //cells inside map and in range + //foundInCache = false; + //nearby cells + UnitRangeCellsLookupItem cacheItem; + for(int i = center.x - range; i < center.x + range + size; ++i) { + for(int j = center.y - range; j < center.y + range + size; ++j) { + //cells inside map and in range #ifdef USE_STREFLOP - if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2f((float)i, (float)j)))) <= (range+1)){ + if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2f((float)i, (float)j)))) <= (range+1)) #else - if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){ + if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)) #endif - Cell *cell = map->getCell(i,j); - findEnemiesForCell(ast,cell,unit,commandTarget,enemies); + { + Cell *cell = map->getCell(i,j); + findEnemiesForCell(ast,cell,unit,commandTarget,enemies); - cacheItem.rangeCellList.push_back(cell); + cacheItem.rangeCellList.push_back(cell); + } } } + + + // Ok update our caches with the latest info + if(cacheItem.rangeCellList.empty() == false) { + MutexSafeWrapper safeMutex(mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__)); + + UnitRangeCellsLookupItemCache[center][size][range] = cacheItem; + } } - - // Ok update our caches with the latest info - if(cacheItem.rangeCellList.empty() == false) { - MutexSafeWrapper safeMutex(mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__)); - - UnitRangeCellsLookupItemCache[center][size][range] = cacheItem; - } - } - - //attack enemies that can attack first - float distToUnit= -1; - Unit* enemySeen= NULL; - std::vector fightingEnemiesInRange; - std::vector damagedFightingEnemiesInRange; - Unit* myFightingEnemyInRange= NULL; - - float distToStandingUnit= -1; - Unit* attackingEnemySeen= NULL; - ControlType controlType= unit->getFaction()->getControlType(); - bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra; - bool isMega= controlType == ctCpuMega || controlType == ctNetworkCpuMega; - - - string randomInfoData = "enemies.size() = " + intToStr(enemies.size()); - - //printf("unit %d has control:%d\n",unit->getId(),controlType); - for(int i = 0; i< (int)enemies.size(); ++i) { - Unit *enemy = enemies[i]; - - - if(enemy != NULL && enemy->isAlive() == true) { - - // Here we default to first enemy if no attackers found - if(enemySeen == NULL) { - *rangedPtr = enemy; - enemySeen = enemy; - result = true; - } - - //randomInfoData += " i = " + intToStr(i) + " alive = true result = " + intToStr(result); - - // Attackers get first priority - if(enemy->getType()->hasSkillClass(scAttack) == true) { - - float currentDist = unit->getCenteredPos().dist(enemy->getCenteredPos()); - - //randomInfoData += " currentDist = " + floatToStr(currentDist); - + //attack enemies that can attack first + float distToUnit= -1; + Unit* enemySeen= NULL; + std::vector fightingEnemiesInRange; + std::vector damagedFightingEnemiesInRange; + Unit* myFightingEnemyInRange= NULL; + float distToStandingUnit= -1; + Unit* attackingEnemySeen= NULL; + ControlType controlType= unit->getFaction()->getControlType(); + bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra; + bool isMega= controlType == ctCpuMega || controlType == ctNetworkCpuMega; + string randomInfoData = "enemies.size() = " + intToStr(enemies.size()); + //printf("unit %d has control:%d\n",unit->getId(),controlType); + for(int i = 0; i< (int)enemies.size(); ++i) { + Unit *enemy = enemies[i]; + if(enemy != NULL && enemy->isAlive() == true) { + // Here we default to first enemy if no attackers found + if(enemySeen == NULL) { + *rangedPtr = enemy; + enemySeen = enemy; + result = true; + } + //randomInfoData += " i = " + intToStr(i) + " alive = true result = " + intToStr(result); + // Attackers get first priority + if(enemy->getType()->hasSkillClass(scAttack) == true) { + float currentDist = unit->getCenteredPos().dist(enemy->getCenteredPos()); + //randomInfoData += " currentDist = " + floatToStr(currentDist); // Select closest attacking unit if (distToUnit < 0 || currentDist < distToUnit) { distToUnit = currentDist; @@ -3027,10 +3000,9 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, } } } - - } - } - } + } + } + } if (evalMode == false) { bool doUltra = false; if (isMega) { @@ -3048,7 +3020,6 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, unitList = &damagedFightingEnemiesInRange; else unitList = &fightingEnemiesInRange; - //printf("Choosing new one\n"); int myChoice = unit->getRandom()->randRange(1, unitList->size(), extractFileFromDirectoryPath(__FILE__) + intToStr(__LINE__)); //printf("myChoice=%d\n", myChoice); @@ -3071,95 +3042,90 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, } - if(result == true) { + if(result == true) { - //const Unit* teamUnit = NULL; - const Unit* enemyUnit = NULL; - bool onlyEnemyUnits = true; + //const Unit* teamUnit = NULL; + const Unit* enemyUnit = NULL; + bool onlyEnemyUnits = true; - if(unit->getTeam() == world->getThisTeamIndex()) { - //teamUnit = unit; - enemyUnit = enemySeen; - onlyEnemyUnits = false; - } - else if(enemySeen->getTeam() == world->getThisTeamIndex()) { - //teamUnit = enemySeen; - enemyUnit = unit; - onlyEnemyUnits = false; - } + if(unit->getTeam() == world->getThisTeamIndex()) { + //teamUnit = unit; + enemyUnit = enemySeen; + onlyEnemyUnits = false; + } + else if(enemySeen->getTeam() == world->getThisTeamIndex()) { + //teamUnit = enemySeen; + enemyUnit = unit; + onlyEnemyUnits = false; + } - if(evalMode == false && onlyEnemyUnits == false && - enemyUnit->getTeam() != world->getThisTeamIndex()) { - - Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos(); - // find nearest Attack and cleanup old dates - AttackWarningData *nearest = NULL; - float currentDistance = 0.f; - float nearestDistance = 0.f; + if(evalMode == false && onlyEnemyUnits == false && + enemyUnit->getTeam() != world->getThisTeamIndex()) { + + Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos(); + // find nearest Attack and cleanup old dates + AttackWarningData *nearest = NULL; + float currentDistance = 0.f; + float nearestDistance = 0.f; - MutexSafeWrapper safeMutex(mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__)); - for(int i = (int)attackWarnings.size() - 1; i >= 0; --i) { - if(world->getFrameCount() - attackWarnings[i]->lastFrameCount > 200) { //after 200 frames attack break we warn again - AttackWarningData *toDelete =attackWarnings[i]; - attackWarnings.erase(attackWarnings.begin()+i); - delete toDelete; // old one - } - else { -#ifdef USE_STREFLOP - currentDistance = streflop::floor(static_cast(enemyFloatCenter.dist(attackWarnings[i]->attackPosition))); // no need for streflops here! -#else - currentDistance = floor(enemyFloatCenter.dist(attackWarnings[i]->attackPosition)); // no need for streflops here! -#endif - - if(nearest == NULL) { - nearest = attackWarnings[i]; - nearestDistance = currentDistance; + MutexSafeWrapper safeMutex(mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__)); + for(int i = (int)attackWarnings.size() - 1; i >= 0; --i) { + if(world->getFrameCount() - attackWarnings[i]->lastFrameCount > 200) { //after 200 frames attack break we warn again + AttackWarningData *toDelete =attackWarnings[i]; + attackWarnings.erase(attackWarnings.begin()+i); + delete toDelete; // old one } else { - if(currentDistance < nearestDistance) { +#ifdef USE_STREFLOP + currentDistance = streflop::floor(static_cast(enemyFloatCenter.dist(attackWarnings[i]->attackPosition))); // no need for streflops here! +#else + currentDistance = floor(enemyFloatCenter.dist(attackWarnings[i]->attackPosition)); // no need for streflops here! +#endif + + if(nearest == NULL) { nearest = attackWarnings[i]; nearestDistance = currentDistance; } + else { + if(currentDistance < nearestDistance) { + nearest = attackWarnings[i]; + nearestDistance = currentDistance; + } + } } } - } + if(nearest != NULL) { + // does it fit? + if(nearestDistance < attackWarnRange) { + // update entry with current values + nearest->lastFrameCount=world->getFrameCount(); + nearest->attackPosition.x=enemyFloatCenter.x; + nearest->attackPosition.y=enemyFloatCenter.y; + } + else { + //Must be a different Attack! + nearest=NULL; //set to null to force a new entry in next step + } + } + // add new attack + if(nearest == NULL) { + // no else! + AttackWarningData* awd= new AttackWarningData(); + awd->lastFrameCount=world->getFrameCount(); + awd->attackPosition.x=enemyFloatCenter.x; + awd->attackPosition.y=enemyFloatCenter.y; + MutexSafeWrapper safeMutex(mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__)); + attackWarnings.push_back(awd); - if(nearest != NULL) { - - // does it fit? - if(nearestDistance < attackWarnRange) { - // update entry with current values - nearest->lastFrameCount=world->getFrameCount(); - nearest->attackPosition.x=enemyFloatCenter.x; - nearest->attackPosition.y=enemyFloatCenter.y; - } - else { - //Must be a different Attack! - nearest=NULL; //set to null to force a new entry in next step - } - } - // add new attack - if(nearest == NULL) { - // no else! - AttackWarningData* awd= new AttackWarningData(); - awd->lastFrameCount=world->getFrameCount(); - awd->attackPosition.x=enemyFloatCenter.x; - awd->attackPosition.y=enemyFloatCenter.y; - - MutexSafeWrapper safeMutex(mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__)); - attackWarnings.push_back(awd); - - if(world->getAttackWarningsEnabled() == true) { - - SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound(),true); - world->addAttackEffects(enemyUnit); - } - } + if(world->getAttackWarningsEnabled() == true) { + SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound(),true); + world->addAttackEffects(enemyUnit); + } + } + } } } - - } catch(const exception &ex) { //setRunningStatus(false); From 22a2abd3f4a4fd4ed08aba608133f02065f90fcf Mon Sep 17 00:00:00 2001 From: pavanvo Date: Mon, 5 Sep 2022 18:13:50 +0400 Subject: [PATCH 12/19] fix: non-targed commands --- source/glest_game/gui/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 1f9c80b3..8bfae43e 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -718,7 +718,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass); } auto mct= unit->getCurrMorphCt(); - if(mct) ct= mct->getMorphUnit()->getFirstCtOfClass(activeCommandClass); + if(mct && isKeyDown(queueCommandKey)) ct= mct->getMorphUnit()->getFirstCtOfClass(activeCommandClass); if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){ assert(selection.isUniform()); From d2fbc3f857194e7d07e822ba6c3e3c8b0841156a Mon Sep 17 00:00:00 2001 From: pavanvo Date: Mon, 5 Sep 2022 18:17:19 +0400 Subject: [PATCH 13/19] fix: add check, if(unitType != NULL && ct->getClass() == ccBuild) --- source/glest_game/game/commander.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index a6881800..9ba5b7b4 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -1057,7 +1057,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const { //create command Command *command= NULL; if(isCancelPreMorphCommand == false) { - if(unitType != NULL) { + if(unitType != NULL && ct->getClass() == ccBuild) { command= new Command(ct, networkCommand->getPosition(), unitType, facing); } else if(target == NULL) { From 3e58c7d03d181e5ea6071e7a43e3783a85e39d35 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Mon, 5 Sep 2022 19:23:53 +0400 Subject: [PATCH 14/19] fix: Morph Queue --- source/glest_game/game/commander.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 9ba5b7b4..2650e572 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -994,7 +994,8 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const { const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId()); if( networkCommand->getUnitTypeId() > -1 && networkCommand->getWantQueue()) { //Morph Queue - ct = unitType->findCommandTypeById(networkCommand->getCommandTypeId()); + auto mct = unitType->findCommandTypeById(networkCommand->getCommandTypeId()); + if(mct) ct = mct; } // debug test! From 60d8bf7fd2a136aadcc4876c82e490c2bb1ee442 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 6 Sep 2022 00:56:21 +0400 Subject: [PATCH 15/19] feat: custom UnitType, for unit->computeCommandType --- source/glest_game/type_instances/unit.cpp | 20 ++++++++++---------- source/glest_game/type_instances/unit.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index bb1d543c..a4d5e12a 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -2164,8 +2164,9 @@ void Unit::resetHighlight(){ highlight= 1.f; } -const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *targetUnit) const{ +const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *targetUnit, const UnitType* unitType) const{ const CommandType *commandType= NULL; + unitType= unitType? unitType: type; if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) { throw megaglest_runtime_error("#6 Invalid path position = " + pos.getString()); @@ -2173,22 +2174,21 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(pos)); - if(type == NULL) { + if(unitType == NULL) { char szBuf[8096]=""; - snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->toString().c_str()); + snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: unitType == NULL, Unit = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->toString().c_str()); throw megaglest_runtime_error(szBuf); } - //printf("Line: %d Unit::computeCommandType pos [%s] targetUnit [%s]\n",__LINE__,pos.getString().c_str(),(targetUnit != NULL ? targetUnit->getType()->getName().c_str() : "(null)")); if(targetUnit != NULL) { //attack enemies if(isAlly(targetUnit) == false) { - commandType= type->getFirstAttackCommand(targetUnit->getCurrField()); + commandType= unitType->getFirstAttackCommand(targetUnit->getCurrField()); } //repair allies else { if(targetUnit->isBuilt() == false || targetUnit->isDamaged() == true) { - commandType= type->getFirstRepairCommand(targetUnit->getType()); + commandType= unitType->getFirstRepairCommand(targetUnit->getType()); } //printf("Line: %d Unit::computeCommandType pos [%s] targetUnit [%s] commandType [%p]\n",__LINE__,pos.getString().c_str(),(targetUnit != NULL ? targetUnit->getType()->getName().c_str() : "(null)"),commandType); @@ -2204,7 +2204,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target targetUnit->getType() != NULL && targetUnit->getType()->getStore(this->getLoadType()) > 0) { - commandType = type->getFirstHarvestEmergencyReturnCommand(); + commandType = unitType->getFirstHarvestEmergencyReturnCommand(); } } } @@ -2213,7 +2213,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target //check harvest command Resource *resource= sc->getResource(); if(resource != NULL) { - commandType= type->getFirstHarvestCommand(resource->getType(),this->getFaction()); + commandType= unitType->getFirstHarvestCommand(resource->getType(),this->getFaction()); } } @@ -2228,7 +2228,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target (targetUnit->isBuilt() == false || targetUnit->isDamaged() == true)) { const RepairCommandType *rct= this->getType()->getFirstRepairCommand(targetUnit->getType()); if(rct != NULL) { - commandType= type->getFirstRepairCommand(targetUnit->getType()); + commandType= unitType->getFirstRepairCommand(targetUnit->getType()); //printf("************ Unit will repair building built = %d, repair = %d\n",targetUnit->isBuilt(),targetUnit->isDamaged()); } } @@ -2238,7 +2238,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target //default command is move command if(commandType == NULL) { - commandType= type->getFirstCtOfClass(ccMove); + commandType= unitType->getFirstCtOfClass(ccMove); } return commandType; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 80ac488f..ccadf227 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -674,7 +674,7 @@ public: //other void resetHighlight(); - const CommandType *computeCommandType(const Vec2i &pos, const Unit *targetUnit= NULL) const; + const CommandType *computeCommandType(const Vec2i &pos, const Unit *targetUnit= NULL, const UnitType* unitType= NULL) const; string getDesc(bool translatedValue) const; string getDescExtension(bool translatedValue) const; bool computeEp(); From 8bc5abbfd3eb904829a4e2495038669de6ea220b Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 6 Sep 2022 00:58:26 +0400 Subject: [PATCH 16/19] fix: auto command for morph queue --- source/glest_game/game/commander.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 2650e572..66cb45bc 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -314,15 +314,15 @@ std::pair Commander::tryGiveCommand(const Selection *selec currPos= world->getMap()->computeDestPos(refPos, unit->getPosNotThreadSafe(), pos); //get command type - const CommandType *commandType= unit->computeCommandType(pos, targetUnit); + auto mct= unit->getCurrMorphCt(); + auto unitType= mct? mct->getMorphUnit(): NULL; + const CommandType *commandType= unit->computeCommandType(pos, targetUnit, unitType); //give commands if(commandType != NULL) { int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= unit->getId(); - int unitTypeId= -1; - auto mct= unit->getCurrMorphCt(); - if(mct) unitTypeId= mct->getMorphUnit()->getId(); + int unitTypeId= unitType? unitType->getId(): -1; std::pair resultCur(crFailUndefined,""); From 8d141ca57fc466c6bcda2e8c7ae268b22b63ae0c Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 6 Sep 2022 03:08:28 +0400 Subject: [PATCH 17/19] fix: add check --- source/glest_game/network/network_types.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/glest_game/network/network_types.cpp b/source/glest_game/network/network_types.cpp index db2c4ac4..3ba5f508 100644 --- a/source/glest_game/network/network_types.cpp +++ b/source/glest_game/network/network_types.cpp @@ -59,7 +59,8 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, const CommandType *ct= unit->getType()->findCommandTypeById(this->commandTypeId); if(unitTypeId > -1) { const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId); - ct= unitType->findCommandTypeById(this->commandTypeId); + auto mct= unitType->findCommandTypeById(this->commandTypeId); + if(mct) ct= mct; } if(ct != NULL && ct->getClass() == ccBuild) { @@ -83,7 +84,8 @@ void NetworkCommand::preprocessNetworkCommand(World *world) { const CommandType *ct= unit->getType()->findCommandTypeById(commandTypeId); if(unitTypeId > -1) { const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId); - ct= unitType->findCommandTypeById(this->commandTypeId); + auto mct= unitType->findCommandTypeById(this->commandTypeId); + if(mct) ct= mct; } if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) { From a1a93ae3d81a065a85871184097fcd2f23e9a16a Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 6 Sep 2022 17:43:54 +0400 Subject: [PATCH 18/19] fix: add param nextUnitTypeId to NetworkCommand class to prevent collision morph with build --- source/glest_game/network/network_types.cpp | 15 +++------------ source/glest_game/network/network_types.h | 4 ++++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/source/glest_game/network/network_types.cpp b/source/glest_game/network/network_types.cpp index 3ba5f508..b88c6c87 100644 --- a/source/glest_game/network/network_types.cpp +++ b/source/glest_game/network/network_types.cpp @@ -28,12 +28,13 @@ namespace Glest{ namespace Game{ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, int commandTypeId, const Vec2i &pos, int unitTypeId, - int targetId, int facing, bool wantQueue, + int nextUnitTypeId, int targetId, int facing, bool wantQueue, CommandStateType commandStateType, int commandStateValue, int unitCommandGroupId) : networkCommandType(networkCommandType) , unitId(unitId) , unitTypeId(unitTypeId) + , nextUnitTypeId(nextUnitTypeId) , commandTypeId(commandTypeId) , positionX(pos.x) , positionY(pos.y) @@ -57,11 +58,6 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, this->unitFactionUnitCount = unit->getFaction()->getUnitCount(); const CommandType *ct= unit->getType()->findCommandTypeById(this->commandTypeId); - if(unitTypeId > -1) { - const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId); - auto mct= unitType->findCommandTypeById(this->commandTypeId); - if(mct) ct= mct; - } if(ct != NULL && ct->getClass() == ccBuild) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); @@ -82,12 +78,7 @@ void NetworkCommand::preprocessNetworkCommand(World *world) { if(unit != NULL) { const CommandType *ct= unit->getType()->findCommandTypeById(commandTypeId); - if(unitTypeId > -1) { - const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId); - auto mct= unitType->findCommandTypeById(this->commandTypeId); - if(mct) ct= mct; - } - + if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) { CardinalDir::assertDirValid(targetId); } diff --git a/source/glest_game/network/network_types.h b/source/glest_game/network/network_types.h index 22493582..16435ca4 100644 --- a/source/glest_game/network/network_types.h +++ b/source/glest_game/network/network_types.h @@ -94,6 +94,7 @@ public: networkCommandType=0; unitId=0; unitTypeId=0; + nextUnitTypeId=0; commandTypeId=0; positionX=0; positionY=0; @@ -114,6 +115,7 @@ public: int commandTypeId= -1, const Vec2i &pos= Vec2i(0), int unitTypeId= -1, + int nextUnitTypeId= -1, int targetId= -1, int facing= -1, bool wantQueue = false, @@ -124,6 +126,7 @@ public: int16 networkCommandType; int32 unitId; int16 unitTypeId; + int16 nextUnitTypeId; int16 commandTypeId; int16 positionX; int16 positionY; @@ -141,6 +144,7 @@ public: int getCommandTypeId() const {return commandTypeId;} Vec2i getPosition() const {return Vec2i(positionX, positionY);} int getUnitTypeId() const {return unitTypeId;} + int getNextUnitTypeId() const {return nextUnitTypeId;} int getTargetId() const {return targetId;} int getWantQueue() const {return wantQueue;} int getFromFactionIndex() const {return fromFactionIndex;} From e7cf0a01deb4d4bc1db2cf109a610a0849ba3ee3 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 6 Sep 2022 17:46:45 +0400 Subject: [PATCH 19/19] fix: switch nextUnitTypeId from unitTypeId --- source/glest_game/game/commander.cpp | 38 ++++++++++++++---------- source/glest_game/world/unit_updater.cpp | 4 +-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 66cb45bc..326f3db9 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -120,9 +120,11 @@ std::pair Commander::tryGiveCommand(const Selection *selec } if(useCommandtype != NULL) { + auto mct= unit->getCurrMorphCt(); + int nextUnitTypeId= mct? mct->getMorphUnit()->getId(): -1; NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, - useCommandtype->getId(), usePos, unitType->getId(), - (targetUnit != NULL ? targetUnit->getId() : -1), + useCommandtype->getId(), usePos, unitType->getId(), nextUnitTypeId, + (targetUnit != NULL ? targetUnit->getId() : -1), facing, tryQueue, commandStateType,commandStateValue, unitCommandGroupId); @@ -162,8 +164,10 @@ std::pair Commander::tryGiveCommand(const Unit* unit, cons std::pair result(crFailUndefined,""); bool canSubmitCommand=canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { + auto mct= unit->getCurrMorphCt(); + int nextUnitTypeId= mct? mct->getMorphUnit()->getId(): -1; NetworkCommand networkCommand(this->world,nctGiveCommand, unit->getId(), - commandType->getId(), pos, unitType->getId(), + commandType->getId(), pos, unitType->getId(), nextUnitTypeId, (targetUnit != NULL ? targetUnit->getId() : -1), facing, tryQueue,cst_None,-1,unitGroupCommandId); @@ -210,8 +214,10 @@ std::pair Commander::tryGiveCommand(const Selection *selec int unitId= selection->getUnit(i)->getId(); Vec2i currPos= world->getMap()->computeDestPos(refPos, selection->getUnit(i)->getPosNotThreadSafe(), pos); + auto mct= unit->getCurrMorphCt(); + int nextUnitTypeId= mct? mct->getMorphUnit()->getId(): -1; NetworkCommand networkCommand(this->world,nctGiveCommand, - unitId, ct->getId(), currPos, -1, targetId, -1, + unitId, ct->getId(), currPos, -1, nextUnitTypeId, targetId, -1, tryQueue,cst_None,-1,unitCommandGroupId); //every unit is ordered to a different pos @@ -263,12 +269,11 @@ std::pair Commander::tryGiveCommand(const Selection *selec int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= unit->getId(); Vec2i currPos= world->getMap()->computeDestPos(refPos, unit->getPosNotThreadSafe(), pos); - int unitTypeId= -1; auto mct= unit->getCurrMorphCt(); - if(mct) unitTypeId= mct->getMorphUnit()->getId(); + int nextUnitTypeId= mct? mct->getMorphUnit()->getId(): -1; NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, - commandType->getId(), currPos, unitTypeId, targetId, -1, tryQueue, + commandType->getId(), currPos, -1, nextUnitTypeId, targetId, -1, tryQueue, cst_None, -1, unitCommandGroupId); //every unit is ordered to a different position @@ -315,21 +320,21 @@ std::pair Commander::tryGiveCommand(const Selection *selec //get command type auto mct= unit->getCurrMorphCt(); - auto unitType= mct? mct->getMorphUnit(): NULL; - const CommandType *commandType= unit->computeCommandType(pos, targetUnit, unitType); + auto nextUnitType= mct? mct->getMorphUnit(): NULL; + const CommandType *commandType= unit->computeCommandType(pos, targetUnit, nextUnitType); //give commands if(commandType != NULL) { int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= unit->getId(); - int unitTypeId= unitType? unitType->getId(): -1; + int nextUnitTypeId= nextUnitType? nextUnitType->getId(): -1; std::pair resultCur(crFailUndefined,""); bool canSubmitCommand=canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { NetworkCommand networkCommand(this->world,nctGiveCommand, - unitId, commandType->getId(), currPos, unitTypeId, targetId, + unitId, commandType->getId(), currPos, -1, nextUnitTypeId, targetId, -1, tryQueue, cst_None, -1, unitCommandGroupId); resultCur= pushNetworkCommand(&networkCommand); } @@ -337,7 +342,7 @@ std::pair Commander::tryGiveCommand(const Selection *selec } else if(unit->isMeetingPointSettable() == true) { NetworkCommand command(this->world,nctSetMeetingPoint, - unit->getId(), -1, currPos,-1,-1,-1,false, + unit->getId(), -1, currPos,-1,-1,-1,-1,false, cst_None,-1,unitCommandGroupId); std::pair resultCur= pushNetworkCommand(&command); @@ -365,7 +370,7 @@ CommandResult Commander::tryCancelCommand(const Selection *selection) const { for(int i = 0; i < selection->getCount(); ++i) { NetworkCommand command(this->world,nctCancelCommand, - selection->getUnit(i)->getId(),-1,Vec2i(0),-1,-1,-1,false, + selection->getUnit(i)->getId(),-1,Vec2i(0),-1,-1,-1,-1,false, cst_None,-1,unitCommandGroupId); pushNetworkCommand(&command); } @@ -993,8 +998,9 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const { const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId()); - if( networkCommand->getUnitTypeId() > -1 && networkCommand->getWantQueue()) { //Morph Queue - auto mct = unitType->findCommandTypeById(networkCommand->getCommandTypeId()); + if(networkCommand->getNextUnitTypeId() > -1 && networkCommand->getWantQueue()) { //Morph Queue + auto nextUnitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getNextUnitTypeId()); + auto mct = nextUnitType->findCommandTypeById(networkCommand->getCommandTypeId()); if(mct) ct = mct; } @@ -1058,7 +1064,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const { //create command Command *command= NULL; if(isCancelPreMorphCommand == false) { - if(unitType != NULL && ct->getClass() == ccBuild) { + if(unitType != NULL) { command= new Command(ct, networkCommand->getPosition(), unitType, facing); } else if(target == NULL) { diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index a650ee25..5a2bf0a9 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -1320,7 +1320,7 @@ void UnitUpdater::updateHarvestEmergencyReturn(Unit *unit, int frameIndex) { if(previousHarvestCmd != NULL) { //printf("\n\n#1a return harvested resources\n\n"); NetworkCommand networkCommand(this->world,nctGiveCommand, unit->getId(), previousHarvestCmd->getId(), unit->getLastHarvestedResourcePos(), - -1, Unit::invalidId, -1, false, cst_None, -1, -1); + -1, -1, Unit::invalidId, -1, false, cst_None, -1, -1); if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -2058,7 +2058,7 @@ void UnitUpdater::updateRepair(Unit *unit, int frameIndex) { const CommandType *ctbuild = unit->getType()->getFirstCtOfClass(ccBuild); NetworkCommand networkCommand(this->world,nctGiveCommand, unit->getId(), ctbuild->getId(), command->getPos(), - command->getUnitType()->getId(), -1, CardinalDir(CardinalDir::NORTH), true, command->getStateType(), + command->getUnitType()->getId(), -1, -1, CardinalDir(CardinalDir::NORTH), true, command->getStateType(), command->getStateValue()); if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);