diff --git a/.gitignore b/.gitignore index 38b541b29..db1166e94 100755 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.sdf *.opensdf */svnrev.h +*/include/svnrev.h *.suo *.log *.ncb @@ -9,6 +10,8 @@ Debug Release Release_Pipeline Debug_Pipeline +Release_NoCopy +Debug_NoCopy *.swp *.bak cppcheck.xml @@ -39,3 +42,5 @@ apps/cygwin/ apps/http* BWAPI.7z + +build diff --git a/CMakeLists.txt b/CMakeLists.txt index deef29b09..b203adf4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(BWAPI) set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") diff --git a/Documentation/Doxyfile b/Documentation/Doxyfile index a093d6a27..19fb50e4b 100755 --- a/Documentation/Doxyfile +++ b/Documentation/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = BWAPI # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 4.2.0 +PROJECT_NUMBER = 4.4.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/Documentation/post-processing/htmlcompressor-1.5.3.jar b/Documentation/post-processing/htmlcompressor-1.5.3.jar new file mode 100755 index 000000000..2a6196fc4 Binary files /dev/null and b/Documentation/post-processing/htmlcompressor-1.5.3.jar differ diff --git a/Documentation/post-processing/phantomjs/LICENSE.BSD b/Documentation/post-processing/phantomjs/LICENSE.BSD new file mode 100755 index 000000000..d5dfdd1f6 --- /dev/null +++ b/Documentation/post-processing/phantomjs/LICENSE.BSD @@ -0,0 +1,22 @@ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Documentation/post-processing/phantomjs/phantomjs.exe b/Documentation/post-processing/phantomjs/phantomjs.exe new file mode 100755 index 000000000..6046b2a6a Binary files /dev/null and b/Documentation/post-processing/phantomjs/phantomjs.exe differ diff --git a/Documentation/post-processing/phantomjs/third-party.txt b/Documentation/post-processing/phantomjs/third-party.txt new file mode 100755 index 000000000..1d0f439b5 --- /dev/null +++ b/Documentation/post-processing/phantomjs/third-party.txt @@ -0,0 +1,40 @@ +This document contains the list of Third Party Software included with +PhantomJS, along with the license information. + +Third Party Software may impose additional restrictions and it is the +user's responsibility to ensure that they have met the licensing +requirements of PhantomJS and the relevant license of the Third Party +Software they are using. + +Qt - http://qt-project.org/ +License: GNU Lesser General Public License (LGPL) version 2.1. +Reference: http://qt-project.org/doc/qt-4.8/lgpl.html. + +WebKit - http://www.webkit.org/ +License: GNU Lesser General Public License (LGPL) version 2.1 and BSD. +Reference: http://www.webkit.org/coding/lgpl-license.html and +http://www.webkit.org/coding/bsd-license.html. + +Mongoose - https://github.com/cesanta/mongoose +License: MIT +Reference: https://github.com/cesanta/mongoose/commit/abbf27338ef554cce0281ac157aa71a9c1b82a55 + +Breakpad - http://code.google.com/p/google-breakpad/ +License: BSD. +Reference: http://code.google.com/p/google-breakpad/source/browse/trunk/COPYING. + +OpenSSL - http://www.openssl.org/ +License: OpenSSL License, SSLeay License. +Reference: http://www.openssl.org/source/license.html. + +Linenoise - https://github.com/tadmarshall/linenoise +License: BSD. +Reference: https://github.com/tadmarshall/linenoise/blob/master/linenoise.h. + +QCommandLine - http://xf.iksaif.net/dev/qcommandline.html +License: GNU Lesser General Public License (LGPL) version 2.1. +Reference: http://dev.iksaif.net/projects/qcommandline/repository/revisions/master/entry/COPYING + +wkhtmlpdf - http://code.google.com/p/wkhtmltopdf/ +License: GNU Lesser General Public License (LGPL) +Reference: http://code.google.com/p/wkhtmltopdf/ diff --git a/Documentation/post-processing/yuicompressor-2.4.8.jar b/Documentation/post-processing/yuicompressor-2.4.8.jar new file mode 100755 index 000000000..a1cf0a092 Binary files /dev/null and b/Documentation/post-processing/yuicompressor-2.4.8.jar differ diff --git a/README.md b/README.md index cc4469b5e..b24a715fa 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # BWAPI for OpenBW This is a fork of BWAPI which allows the use of OpenBW as a backend for BWAPI. -The BWAPI version is 4.2.0. +The BWAPI version is 4.4.0. This fork has significant changes and it no longer works with regular StarCraft: Brood War. Support for OpenBW should eventually be merged into the official BWAPI, but this fork will exist until then. @@ -43,6 +43,7 @@ If you installed, BWAPI.h (and the rest) will be in the include folder, otherwis On Windows, you should link to BWAPILIB.lib (not BWAPI.lib, this is different from regular BWAPI). On Linux, you don't really need to link to anything, but you can -lBWAPILIB if you want. +* **SSCAIT Discord:** https://discord.gg/DqvHsq9 ### Running diff --git a/bwapi/AIModuleLoader/AIModuleLoader.vcxproj b/bwapi/AIModuleLoader/AIModuleLoader.vcxproj index 0c8c9763f..b453be01c 100755 --- a/bwapi/AIModuleLoader/AIModuleLoader.vcxproj +++ b/bwapi/AIModuleLoader/AIModuleLoader.vcxproj @@ -19,12 +19,12 @@ Application true - v141 + v141_xp Application Unicode - v141 + v141_xp @@ -45,7 +45,7 @@ Disabled ../include;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -53,13 +53,13 @@ Level3 true + /Zc:threadSafeInit- %(AdditionalOptions) true Console MachineX86 - ../lib/BWAPId.lib;../lib/BWAPIClientd.lib;%(AdditionalDependencies) @@ -67,7 +67,7 @@ MaxSpeed true ../include;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -79,6 +79,7 @@ true true true + /Zc:threadSafeInit- %(AdditionalOptions) @@ -87,12 +88,19 @@ true true MachineX86 - ../lib/BWAPI.lib;../lib/BWAPIClient.lib;%(AdditionalDependencies) + + + {c99abf61-6716-4fc0-aa77-9a136ea61680} + + + {843656fd-9bfd-47bf-8460-7bfe9710ea2c} + + diff --git a/bwapi/Archive/Archive.vcxproj b/bwapi/Archive/Archive.vcxproj old mode 100644 new mode 100755 index a57c91c1b..d44eb6990 --- a/bwapi/Archive/Archive.vcxproj +++ b/bwapi/Archive/Archive.vcxproj @@ -15,13 +15,12 @@ {7C035A16-F016-4F21-88EB-8DD3B9539219} MakeFileProj InstallerArchive - 8.1 Makefile false - v141 + v141_xp @@ -42,7 +41,7 @@ IF %ERRORLEVEL% NEQ 0 ( ) cd $(SolutionDir)/../ -7z a -r -mx=9 -myx=9 BWAPI.7z Release_Binary +7z a -r BWAPI.7z Release_Binary cd $(SolutionDir) diff --git a/bwapi/BWAPI/Source/BW/OrderTypes.cpp b/bwapi/BWAPI/Source/BW/OrderTypes.cpp index cdbfeaa25..fd242d71a 100755 --- a/bwapi/BWAPI/Source/BW/OrderTypes.cpp +++ b/bwapi/BWAPI/Source/BW/OrderTypes.cpp @@ -5,7 +5,7 @@ #include #include -#include "../../../Debug.h" +#include namespace BW { namespace Orders diff --git a/bwapi/BWAPI/Source/BW/PositionUnitTarget.cpp b/bwapi/BWAPI/Source/BW/PositionUnitTarget.cpp index acad728f7..23ad6fde1 100755 --- a/bwapi/BWAPI/Source/BW/PositionUnitTarget.cpp +++ b/bwapi/BWAPI/Source/BW/PositionUnitTarget.cpp @@ -1,6 +1,6 @@ #include "PositionUnitTarget.h" -#include "../../../Debug.h" +#include #include diff --git a/bwapi/BWAPI/Source/BW/UnitTarget.cpp b/bwapi/BWAPI/Source/BW/UnitTarget.cpp index 3d879233f..fe0901afe 100755 --- a/bwapi/BWAPI/Source/BW/UnitTarget.cpp +++ b/bwapi/BWAPI/Source/BW/UnitTarget.cpp @@ -3,7 +3,7 @@ #include #include -#include "../../../Debug.h" +#include namespace BW { diff --git a/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.cpp b/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.cpp index f7f7fba50..8d9c3b46c 100755 --- a/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.cpp +++ b/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.cpp @@ -3,6 +3,7 @@ //#include "../DLLMain.h" #include +#include #include //#include #include @@ -14,6 +15,11 @@ using namespace BWAPI; +namespace +{ + std::mt19937 mt{static_cast(std::chrono::system_clock::now().time_since_epoch().count())}; +} + AutoMenuManager::AutoMenuManager(BW::Game bwgame) : bwgame(bwgame) { this->reloadConfig(); @@ -149,19 +155,18 @@ void AutoMenuManager::chooseNewRandomMap() { if (!this->autoMapPool.empty()) { - int chosenEntry = 0; + std::string chosen; if (this->autoMapIteration == "RANDOM") { // Obtain a random map file - chosenEntry = rand() % this->autoMapPool.size(); + std::sample(autoMapPool.begin(), autoMapPool.end(), &chosen, 1, mt); } else if (this->autoMapIteration == "SEQUENCE") { if (this->lastAutoMapEntry >= this->autoMapPool.size()) this->lastAutoMapEntry = 0; - chosenEntry = this->lastAutoMapEntry++; + chosen = this->autoMapPool[this->lastAutoMapEntry++]; } - std::string chosen = this->autoMapPool[chosenEntry]; this->lastMapGen = this->autoMenuMapPath + chosen; } } diff --git a/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.h b/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.h index 4f1c33761..662f2e5d2 100755 --- a/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.h +++ b/bwapi/BWAPI/Source/BWAPI/AutoMenuManager.h @@ -46,7 +46,7 @@ namespace BWAPI std::string lastMapGen; std::vector autoMapPool; std::string autoMenuMapPath; - std::string autoMapIteration; + std::string autoMapIteration = "RANDOM"; std::string autoMenuRace; std::array autoMenuEnemyRace; diff --git a/bwapi/BWAPI/Source/BWAPI/BWtoBWAPI.cpp b/bwapi/BWAPI/Source/BWAPI/BWtoBWAPI.cpp index d686422df..6a1df6275 100755 --- a/bwapi/BWAPI/Source/BWAPI/BWtoBWAPI.cpp +++ b/bwapi/BWAPI/Source/BWAPI/BWtoBWAPI.cpp @@ -1,6 +1,6 @@ #include "BWtoBWAPI.h" -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/BulletImpl.cpp b/bwapi/BWAPI/Source/BWAPI/BulletImpl.cpp index c9fcca08b..7cc406fc7 100755 --- a/bwapi/BWAPI/Source/BWAPI/BulletImpl.cpp +++ b/bwapi/BWAPI/Source/BWAPI/BulletImpl.cpp @@ -8,7 +8,7 @@ #include "PlayerImpl.h" #include "UnitImpl.h" -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/Command.h b/bwapi/BWAPI/Source/BWAPI/Command.h index 73903d54f..0275ee8c5 100755 --- a/bwapi/BWAPI/Source/BWAPI/Command.h +++ b/bwapi/BWAPI/Source/BWAPI/Command.h @@ -1,13 +1,10 @@ #pragma once -#include "CommandTemp.h" +class Command; +#include #include "UnitImpl.h" #include "PlayerImpl.h" namespace BWAPI { - class Command : public CommandTemp - { - public: - Command(const UnitCommand& command) : CommandTemp(command) {} - }; + using Command = CommandTemp; } \ No newline at end of file diff --git a/bwapi/BWAPI/Source/BWAPI/CommandTemp.h b/bwapi/BWAPI/Source/BWAPI/CommandTemp.h deleted file mode 100755 index baf98583f..000000000 --- a/bwapi/BWAPI/Source/BWAPI/CommandTemp.h +++ /dev/null @@ -1,723 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include - -namespace BWAPI -{ - template - class CommandTemp - { - public : - CommandTemp(const UnitCommand& command); - void execute(int frame); - protected: - virtual ~CommandTemp() {}; - private : - static int getUnitID(Unit unit); - UnitCommand command; - int savedExtra = -1; - int savedExtra2 = -1; - PlayerImpl* player = nullptr; - }; - template - CommandTemp::CommandTemp(const UnitCommand& command) : command(command) - {} - template - int CommandTemp::getUnitID(Unit unit) - { - if ( !unit ) - return -1; - return unit->getID(); - } - template - void CommandTemp::execute(int frame) - { - // Immediately return if latency compensation is disabled or if the command was queued - if ( !Broodwar->isLatComEnabled() || command.isQueued() ) return; - UnitImpl* unit = static_cast(command.unit); - UnitImpl* target = static_cast(command.target); - - Position position(command.x,command.y); - TilePosition tileposition(command.x,command.y); - UnitType unitType(command.extra); - UpgradeType upgradeType(command.extra); - TechType techType(command.extra); - - // Get the player (usually the unit's owner) - if ( !player ) - player = static_cast(unit ? unit->getPlayer() : Broodwar->self()); - - // Latency test - if (frame > Broodwar->getLatency() && - command.type != UnitCommandTypes::Cancel_Construction && - command.type != UnitCommandTypes::Cancel_Train_Slot && - command.type != UnitCommandTypes::Cancel_Morph && - command.type != UnitCommandTypes::Train && - command.type != UnitCommandTypes::Gather && - command.type != UnitCommandTypes::Stop && - command.type != UnitCommandTypes::Return_Cargo && - command.type != UnitCommandTypes::Right_Click_Position && - command.type != UnitCommandTypes::Morph) - return; - - // Existence test - switch ( command.type.getID() ) - { - case UnitCommandTypes::Enum::Cancel_Construction: - case UnitCommandTypes::Enum::Cancel_Research: - case UnitCommandTypes::Enum::Cancel_Upgrade: - break; - default: - if ( !unit->self->exists ) - return; - break; - } - - // Move test - switch ( command.type.getID() ) - { - case UnitCommandTypes::Enum::Follow: - case UnitCommandTypes::Enum::Hold_Position: - case UnitCommandTypes::Enum::Move: - case UnitCommandTypes::Enum::Patrol: - case UnitCommandTypes::Enum::Right_Click_Position: - case UnitCommandTypes::Enum::Attack_Move: - if (!unit->getType().canMove()) - return; - break; - } - - // Apply command changes - if (command.type == UnitCommandTypes::Attack_Move) - { - unit->self->order = Orders::AttackMove; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - } - else if (command.type == UnitCommandTypes::Attack_Unit) - { - if ( !target || !target->self->exists) - return; - if (!unit->getType().canAttack()) - return; - unit->self->order = Orders::AttackUnit; - unit->self->target = getUnitID(target); - } - else if (command.type == UnitCommandTypes::Build) - { - unit->self->order = Orders::PlaceBuilding; - unit->self->isConstructing = true; - unit->self->isIdle = false; - unit->self->buildType = command.extra; - } - else if (command.type == UnitCommandTypes::Build_Addon) - { - unit->self->secondaryOrder = Orders::BuildAddon; - unit->self->isConstructing = true; - unit->self->isIdle = false; - unit->self->buildType = command.extra; - } - else if (command.type == UnitCommandTypes::Burrow) - { - unit->self->order = Orders::Burrowing; - } - else if (command.type == UnitCommandTypes::Cancel_Addon) - { - if (savedExtra == -1) - savedExtra = unit->self->buildType; - unitType = UnitType(savedExtra); - if (frame < Broodwar->getLatency()) - { - player->self->minerals += (int)(unitType.mineralPrice() * 0.75); - player->self->gas += (int)(unitType.gasPrice() * 0.75); - } - unit->self->remainingBuildTime = 0; - unit->self->isConstructing = false; - unit->self->order = Orders::Nothing; - unit->self->isIdle = true; - unit->self->buildType = UnitTypes::None; - unit->self->buildUnit = -1; - } - else if (command.type == UnitCommandTypes::Cancel_Construction) - { - if (savedExtra == -1) - savedExtra = unit->self->type; - if (savedExtra2 == -1) - savedExtra2 = unit->self->buildUnit; - unitType = UnitType(savedExtra); - if ((frame > Broodwar->getLatency() + 1 && Broodwar->getLatency() == 2) || - (frame > Broodwar->getLatency() + 2 && Broodwar->getLatency() > 2)) - return; - if (unitType.getRace() == Races::Terran) - { - UnitImpl* builder = static_cast( Broodwar->getUnit(savedExtra2) ); - if ( builder && builder->exists()) - { - builder->self->buildUnit = -1; - builder->self->buildType = UnitTypes::None; - builder->self->isConstructing = false; - builder->self->order = Orders::ResetCollision; - } - } - if (frame > Broodwar->getLatency()) - return; - if (!unit->self->exists) - return; - unit->self->buildUnit = -1; - if ((frame < Broodwar->getLatency() && Broodwar->getLatency()==2) || - (frame <=Broodwar->getLatency() && Broodwar->getLatency()>2)) - { - player->self->minerals += (int)(unitType.mineralPrice() * 0.75); - player->self->gas += (int)(unitType.gasPrice() * 0.75); - } - unit->self->remainingBuildTime = 0; - unit->self->isConstructing = false; - if (unitType.getRace() == Races::Zerg) - { - unit->self->type = unitType.whatBuilds().first; - unit->self->buildType = UnitTypes::None; - unit->self->isMorphing = false; - unit->self->isIdle = true; - - UnitType whatBuilds = unitType.whatBuilds().first; - if (frame < Broodwar->getLatency()) - player->self->supplyUsed[unitType.getRace()] += whatBuilds.supplyRequired(); - - if (whatBuilds.isBuilding()) - { - unit->self->order = Orders::Nothing; - } - else - { - unit->self->order = Orders::ResetCollision; - } - } - else - { - unit->self->order = Orders::Die; - unit->self->isCompleted = false; - unit->self->isIdle = false; - } - } - else if (command.type == UnitCommandTypes::Cancel_Morph) - { - if (savedExtra == -1) - savedExtra = unit->self->buildType; - unitType = UnitType(savedExtra); - if (frame > Broodwar->getLatency() + 12) - return; - if (frame < Broodwar->getLatency()) - { - if (unitType.whatBuilds().first.isBuilding()) - { - player->self->minerals += (int)(unitType.mineralPrice()*0.75); - player->self->gas += (int)(unitType.gasPrice()*0.75); - } - else - { - player->self->minerals += unitType.mineralPrice(); - player->self->gas += unitType.gasPrice(); - } - } - if (frame<=Broodwar->getLatency()) - { - if (unitType.isTwoUnitsInOneEgg()) - player->self->supplyUsed[Races::Zerg] -= unitType.supplyRequired() * 2 - unitType.whatBuilds().first.supplyRequired(); - else - player->self->supplyUsed[Races::Zerg] -= unitType.supplyRequired() - unitType.whatBuilds().first.supplyRequired(); - } - unit->self->buildType = UnitTypes::None; - unit->self->remainingBuildTime = 0; - unit->self->isMorphing = false; - unit->self->isConstructing = false; - unit->self->isCompleted = true; - unit->self->isIdle = true; - unit->self->type = unitType.whatBuilds().first; - if (unitType.whatBuilds().first.isBuilding()) - unit->self->order = Orders::Nothing; - else - unit->self->order = Orders::PlayerGuard; - } - else if (command.type == UnitCommandTypes::Cancel_Research) - { - if (savedExtra == -1) - savedExtra = unit->self->tech; - techType = TechType(savedExtra); - - if (!unit->self->exists) - return; - unit->self->order = Orders::Nothing; - unit->self->tech = TechTypes::None; - unit->self->isIdle = true; - unit->self->remainingResearchTime = 0; - if (frame < Broodwar->getLatency()) - { - player->self->minerals += techType.mineralPrice(); - player->self->gas += techType.gasPrice(); - } - } - else if (command.type == UnitCommandTypes::Cancel_Train) - { - if (savedExtra == -1) - savedExtra = unit->self->trainingQueue[unit->self->trainingQueueCount - 1]; - if (savedExtra2 == -1) - savedExtra2 = unit->self->buildUnit; - if ((frame < Broodwar->getLatency() && Broodwar->getLatency() == 2) || - (frame <= Broodwar->getLatency()+1 && Broodwar->getLatency() > 2)) - { - unit->self->trainingQueueCount--; - if (unit->self->trainingQueueCount < 0) - unit->self->trainingQueueCount = 0; - player->self->minerals += UnitType(savedExtra).mineralPrice(); - player->self->gas += UnitType(savedExtra).gasPrice(); - } - if (unit->self->trainingQueueCount == 0) - { - unit->self->buildUnit = -1; - unit->self->isTraining = false; - unit->self->remainingTrainTime = 0; - unit->self->isIdle = true; - player->self->supplyUsed[unit->getType().getRace()] -= UnitType(savedExtra).supplyRequired(); - } - } - else if (command.type == UnitCommandTypes::Cancel_Train_Slot) - { - if (frame > Broodwar->getLatency() + 2) - return; - if (savedExtra == -1) - savedExtra = unit->self->trainingQueue[command.extra]; - if ((frame < Broodwar->getLatency() && Broodwar->getLatency() == 2) || - (frame <= Broodwar->getLatency()+1 && Broodwar->getLatency() > 2)) - { - for(int i = command.extra; i < 4; ++i) - unit->self->trainingQueue[i] = unit->self->trainingQueue[i+1]; - unit->self->trainingQueueCount--; - if (unit->self->trainingQueueCount < 0) - unit->self->trainingQueueCount = 0; - player->self->minerals += UnitType(savedExtra).mineralPrice(); - player->self->gas += UnitType(savedExtra).gasPrice(); - } - if (command.extra == 0) - { - unit->self->buildUnit = -1; - if ((frame < Broodwar->getLatency() && Broodwar->getLatency() == 2) || - (frame <= Broodwar->getLatency()-1 && Broodwar->getLatency() > 2)) - { - player->self->supplyUsed[unit->getType().getRace()] -= UnitType(savedExtra).supplyRequired(); - } - - if (unit->self->trainingQueueCount == 0) - { - unit->self->isTraining = false; - unit->self->isIdle = true; - } - else - { - unit->self->remainingTrainTime = UnitType(unit->self->trainingQueue[0]).buildTime(); // @TODO: fix to real build time - player->self->supplyUsed[unit->getType().getRace()] += UnitType(unit->self->trainingQueue[0]).supplyRequired(); - if ((frame == Broodwar->getLatency() && Broodwar->getLatency() == 2) || - (frame == Broodwar->getLatency()+1 && Broodwar->getLatency() > 2) ) - { - player->self->supplyUsed[unit->getType().getRace()] -= UnitType(savedExtra).supplyRequired(); - } - } - } - } - else if (command.type == UnitCommandTypes::Cancel_Upgrade) - { - if (savedExtra == -1) - savedExtra = unit->self->upgrade; - upgradeType = UpgradeType(savedExtra); - - if (!unit->self->exists) - return; - - unit->self->order = Orders::Nothing; - int level = unit->getPlayer()->getUpgradeLevel(upgradeType); - unit->self->upgrade = UpgradeTypes::None; - unit->self->isIdle = true; - unit->self->remainingUpgradeTime = 0; - - if (frame < Broodwar->getLatency()) - { - player->self->minerals += upgradeType.mineralPrice(level+1); - player->self->gas += upgradeType.gasPrice(level+1); - } - } - else if (command.type == UnitCommandTypes::Cloak) - { - unit->self->order = Orders::Cloak; - if (frame < Broodwar->getLatency()) - unit->self->energy -= unit->getType().cloakingTech().energyCost(); - } - else if (command.type == UnitCommandTypes::Decloak) - { - unit->self->order = Orders::Decloak; - } - else if (command.type == UnitCommandTypes::Follow) - { - unit->self->order = Orders::Follow; - unit->self->target = getUnitID(target); - unit->self->isIdle = false; - unit->self->isMoving = true; - } - else if (command.type == UnitCommandTypes::Gather) - { - if ((frame<=Broodwar->getLatency() && Broodwar->getLatency()==2) || - (frame<=Broodwar->getLatency()+1 && Broodwar->getLatency()>2)) - { - unit->self->target = getUnitID(target); - unit->self->isIdle = false; - unit->self->isMoving = true; - unit->self->isGathering = true; - if ( target->getType().isMineralField() ) - unit->self->order = Orders::MoveToMinerals; - else if ( target->getType().isRefinery() ) - unit->self->order = Orders::MoveToGas; - } - } - else if (command.type == UnitCommandTypes::Halt_Construction) - { - if (savedExtra == -1) - savedExtra = unit->self->buildUnit; - if (frame > Broodwar->getLatency()) - return; - UnitImpl* buildUnit = static_cast( Broodwar->getUnit(savedExtra) ); - if ( buildUnit ) - buildUnit->self->buildUnit = -1; - - unit->self->buildUnit = -1; - unit->self->buildType = UnitTypes::None; - unit->self->order = Orders::ResetCollision; - unit->self->isConstructing = false; - } - else if (command.type == UnitCommandTypes::Hold_Position) - { - unit->self->isMoving = false; - unit->self->isIdle = false; - unit->self->order = Orders::HoldPosition; - } - else if (command.type == UnitCommandTypes::Land) - { - unit->self->order = Orders::BuildingLand; - unit->self->isIdle = false; - } - else if (command.type == UnitCommandTypes::Lift) - { - unit->self->order = Orders::BuildingLiftOff; - unit->self->isIdle = false; - } - else if (command.type == UnitCommandTypes::Load) - { - if (unit->getType() == UnitTypes::Terran_Bunker) - { - unit->self->order = Orders::PickupBunker; - unit->self->target = getUnitID(target); - } - else if ( unit->getType().spaceProvided() ) - { - unit->self->order = Orders::PickupTransport; - unit->self->target = getUnitID(target); - } - else if ( target->getType().spaceProvided() ) - { - unit->self->order = Orders::EnterTransport; - unit->self->target = getUnitID(target); - } - unit->self->isIdle = false; - } - else if (command.type == UnitCommandTypes::Morph) - { - if (frame > Broodwar->getLatency()+1) - return; - unit->self->isMorphing = true; - unit->self->isConstructing = true; - unit->self->isCompleted = false; - unit->self->isIdle = false; - unit->self->buildType = unitType; - if (unit->self->remainingBuildTime < 50) - unit->self->remainingBuildTime = unitType.buildTime(); // @TODO: Fix to real build time - if (frame > Broodwar->getLatency()) - return; - if (unitType.isBuilding()) - { - unit->self->order = Orders::ZergBuildingMorph; - player->self->minerals -= unitType.mineralPrice(); - player->self->gas -= unitType.gasPrice(); - unit->self->type = unitType; - } - else - { - unit->self->order = Orders::ZergUnitMorph; - if (frame < Broodwar->getLatency()) - { - player->self->minerals -= unitType.mineralPrice(); - player->self->gas -= unitType.gasPrice(); - } - if (unitType.isTwoUnitsInOneEgg()) - player->self->supplyUsed[Races::Zerg] += unitType.supplyRequired()*2-unitType.whatBuilds().first.supplyRequired(); - else - player->self->supplyUsed[Races::Zerg] += unitType.supplyRequired()-unitType.whatBuilds().first.supplyRequired(); - - if (unitType == UnitTypes::Zerg_Lurker) - unit->self->type = UnitTypes::Zerg_Lurker_Egg; - else if (unitType == UnitTypes::Zerg_Devourer || - unitType == UnitTypes::Zerg_Guardian) - unit->self->type = UnitTypes::Zerg_Cocoon; - else - unit->self->type = UnitTypes::Zerg_Egg; - } - } - else if (command.type == UnitCommandTypes::Move) - { - unit->self->order = Orders::Move; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - unit->self->isMoving = true; - unit->self->isIdle = false; - } - else if (command.type == UnitCommandTypes::Patrol) - { - unit->self->order = Orders::Patrol; - unit->self->isIdle = false; - unit->self->isMoving = true; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - } - else if (command.type == UnitCommandTypes::Repair) - { - if (unit->getType() != UnitTypes::Terran_SCV) - return; - unit->self->order = Orders::Repair; - unit->self->target = getUnitID(target); - unit->self->isIdle = false; - } - else if (command.type == UnitCommandTypes::Research) - { - unit->self->order = Orders::ResearchTech; - unit->self->tech = techType; - unit->self->isIdle = false; - unit->self->remainingResearchTime = techType.researchTime(); // @TODO: Fix to real time - if (frame < Broodwar->getLatency()) - { - player->self->minerals -= techType.mineralPrice(); - player->self->gas -= techType.gasPrice(); - } - player->self->isResearching[techType] = true; - } - else if (command.type == UnitCommandTypes::Return_Cargo) - { - if (unit->self->carryResourceType == 0) - return; - if ((frame<=Broodwar->getLatency() && Broodwar->getLatency()==2) || - (frame<=Broodwar->getLatency()+1 && Broodwar->getLatency()>2)) - { - if (unit->isCarryingGas()) - unit->self->order = Orders::ReturnGas; - else - unit->self->order = Orders::ReturnMinerals; - unit->self->isGathering = true; - unit->self->isIdle = false; - } - } - else if (command.type == UnitCommandTypes::Right_Click_Position) - { - if ((frame<=Broodwar->getLatency() && Broodwar->getLatency()==2) || - (frame<=Broodwar->getLatency()+1 && Broodwar->getLatency()>2)) - { - unit->self->order = Orders::Move; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - unit->self->isMoving = true; - unit->self->isIdle = false; - } - } - else if (command.type == UnitCommandTypes::Right_Click_Unit) - { - unit->self->target = getUnitID(target); - unit->self->isIdle = false; - unit->self->isMoving = true; - if (unit->getType().isWorker() && target->getType().isMineralField() ) - { - unit->self->isGathering = true; - unit->self->order = Orders::MoveToMinerals; - } - else if (unit->getType().isWorker() && target->getType().isRefinery() ) - { - unit->self->isGathering = true; - unit->self->order = Orders::MoveToGas; - } - else if (unit->getType().isWorker() && - target->getType().getRace() == Races::Terran && - target->getType().whatBuilds().first == unit->getType() && - !target->isCompleted()) - { - unit->self->order = Orders::ConstructingBuilding; - unit->self->buildUnit = getUnitID(target); - target->self->buildUnit = getUnitID(unit); - unit->self->isConstructing = true; - target->self->isConstructing = true; - } - else if ( unit->getType().canAttack() && target->getPlayer() != unit->getPlayer() && !target->getType().isNeutral() ) - { - unit->self->order = Orders::AttackUnit; - } - else if ( unit->getType().canMove() ) - { - unit->self->order = Orders::Follow; - } - } - else if (command.type == UnitCommandTypes::Set_Rally_Position) - { - if (!unit->getType().canProduce()) - return; - unit->self->order = Orders::RallyPointTile; - unit->self->rallyPositionX = position.x; - unit->self->rallyPositionY = position.y; - unit->self->rallyUnit = -1; - } - else if (command.type == UnitCommandTypes::Set_Rally_Unit) - { - if (!unit->getType().canProduce()) - return; - if ( !target || !target->self->exists ) - return; - unit->self->order = Orders::RallyPointUnit; - unit->self->rallyUnit = getUnitID(target); - } - else if (command.type == UnitCommandTypes::Siege) - { - unit->self->order = Orders::Sieging; - } - else if (command.type == UnitCommandTypes::Stop) - { - if ((frame<=Broodwar->getLatency() && Broodwar->getLatency()==2) || - (frame<=Broodwar->getLatency()+1 && Broodwar->getLatency()>2)) - { - unit->self->order = Orders::Stop; - unit->self->isIdle = true; - } - } - else if (command.type == UnitCommandTypes::Train) - { - if (savedExtra == -1) - savedExtra = unit->self->trainingQueueCount; - if ((frame < Broodwar->getLatency() && Broodwar->getLatency() == 2) || - (frame <= Broodwar->getLatency() && Broodwar->getLatency() > 2)) - { - unit->self->trainingQueue[unit->self->trainingQueueCount++] = unitType; - player->self->minerals -= unitType.mineralPrice(); - player->self->gas -= unitType.gasPrice(); - } - if ((frame <= Broodwar->getLatency() && Broodwar->getLatency() == 2) || - (frame <= Broodwar->getLatency()+1 && Broodwar->getLatency() > 2)) - { - if (savedExtra == 0) - { - unit->self->remainingTrainTime = unitType.buildTime(); // @TODO: fix to real build time - player->self->supplyUsed[unitType.getRace()] += unitType.supplyRequired(); - } - } - if (frame <= Broodwar->getLatency()) - { - unit->self->isTraining = true; - unit->self->isIdle = false; - if ( unitType == UnitTypes::Terran_Nuclear_Missile ) - unit->self->secondaryOrder = Orders::Train; - } - } - else if (command.type == UnitCommandTypes::Unburrow) - { - unit->self->order = Orders::Unburrowing; - } - else if (command.type == UnitCommandTypes::Unload) - { - unit->self->order = Orders::Unload; - unit->self->target = getUnitID(target); - } - else if (command.type == UnitCommandTypes::Unload_All) - { - if (unit->getType() == UnitTypes::Terran_Bunker) - { - unit->self->order = Orders::Unload; - } - else - { - unit->self->order = Orders::MoveUnload; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - } - } - else if (command.type == UnitCommandTypes::Unload_All_Position) - { - unit->self->order = Orders::MoveUnload; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - } - else if (command.type == UnitCommandTypes::Unsiege) - { - unit->self->order = Orders::Unsieging; - } - else if (command.type == UnitCommandTypes::Upgrade) - { - unit->self->order = Orders::Upgrade; - unit->self->upgrade = upgradeType; - unit->self->isIdle = false; - int level = unit->getPlayer()->getUpgradeLevel(upgradeType); - unit->self->remainingUpgradeTime = upgradeType.upgradeTime(level+1); // @TODO: Fix to real time - if (frame < Broodwar->getLatency()) - { - player->self->minerals -= upgradeType.mineralPrice(level+1); - player->self->gas -= upgradeType.gasPrice(level+1); - } - player->self->isUpgrading[upgradeType] = true; - } - else if (command.type == UnitCommandTypes::Use_Tech) - { - if ( techType == TechTypes::Stim_Packs && unit->self->hitPoints > 10 ) - { - unit->self->hitPoints -= 10; - unit->self->stimTimer = 17; - } - } - else if (command.type == UnitCommandTypes::Use_Tech_Position) - { - if ( !techType.targetsPosition() ) - return; - unit->self->order = techType.getOrder();; - unit->self->targetPositionX = position.x; - unit->self->targetPositionY = position.y; - unit->self->orderTargetPositionX = position.x; - unit->self->orderTargetPositionY = position.y; - } - else if (command.type == UnitCommandTypes::Use_Tech_Unit) - { - if ( !techType.targetsUnit() ) - return; - unit->self->order = techType.getOrder(); - unit->self->orderTarget = getUnitID(target); - unit->self->targetPositionX = target->getPosition().x; - unit->self->targetPositionY = target->getPosition().y; - unit->self->orderTargetPositionX = target->getPosition().x; - unit->self->orderTargetPositionY = target->getPosition().y; - } - } - -}; diff --git a/bwapi/BWAPI/Source/BWAPI/ForceImpl.cpp b/bwapi/BWAPI/Source/BWAPI/ForceImpl.cpp index d8caa216b..37e08addb 100755 --- a/bwapi/BWAPI/Source/BWAPI/ForceImpl.cpp +++ b/bwapi/BWAPI/Source/BWAPI/ForceImpl.cpp @@ -1,7 +1,7 @@ #include "ForceImpl.h" #include "GameImpl.h" -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/GameBullets.cpp b/bwapi/BWAPI/Source/BWAPI/GameBullets.cpp index 3d4af0416..d177f976c 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameBullets.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameBullets.cpp @@ -4,7 +4,7 @@ #include -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/GameCommands.cpp b/bwapi/BWAPI/Source/BWAPI/GameCommands.cpp index eb919fc15..8f14b5c6b 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameCommands.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameCommands.cpp @@ -6,31 +6,44 @@ #include -#include "../../../Debug.h" +#include namespace BWAPI { //----------------------------------------- ADD TO COMMAND BUFFER ------------------------------------------ - void GameImpl::addToCommandBuffer(Command* command) + void GameImpl::addToCommandBuffer(Command command) { - //executes latency compensation code and added it to the buffer - command->execute(0); - this->commandBuffer[this->commandBuffer.size() - 1].push_back(command); + std::move(command).insertIntoCommandBuffer(this->commandBuffer); } //----------------------------------------- APPLY LATENCY COMPENSATION void GameImpl::applyLatencyCompensation() { - //apply latency compensation - while ((int)(this->commandBuffer.size()) > this->getLatency()+15) + // Remove the current frame from the buffer and execute the current frame + // (only some actions execute on the current frame, like resource reserving) + if (!this->commandBuffer.empty()) { - for (unsigned int i = 0; i < this->commandBuffer.front().size(); ++i) - delete this->commandBuffer.front()[i]; - this->commandBuffer.erase(this->commandBuffer.begin()); + for (auto &command : this->commandBuffer.front()) + { + command.execute(true); + } + this->commandBuffer.erase(std::begin(this->commandBuffer)); + } + + // Apply latency compensation + for (auto buf = 0; buf < getRemainingLatencyFrames() + && buf < static_cast(this->commandBuffer.size()); ++buf) + { + for (auto &command : this->commandBuffer[buf]) + { + command.execute(); + } + } + + // Prepare buffer space for new commands + if (this->commandBuffer.size() < static_cast(getRemainingLatencyFrames() + 15)) + { + this->commandBuffer.resize(getRemainingLatencyFrames() + 15); } - this->commandBuffer.push_back(std::vector()); - for (unsigned int i = 0; i < this->commandBuffer.size(); ++i) - for (unsigned int j = 0; j < this->commandBuffer[i].size(); ++j) - this->commandBuffer[i][j]->execute(this->commandBuffer.size()-1-i); } //--------------------------------------------- EXECUTE COMMAND -------------------------------------------- diff --git a/bwapi/BWAPI/Source/BWAPI/GameDrawing.cpp b/bwapi/BWAPI/Source/BWAPI/GameDrawing.cpp index 1bb6f6222..6851e0175 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameDrawing.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameDrawing.cpp @@ -5,7 +5,7 @@ #include #include -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/GameEvents.cpp b/bwapi/BWAPI/Source/BWAPI/GameEvents.cpp index 9acd89191..085ea47f4 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameEvents.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameEvents.cpp @@ -8,8 +8,7 @@ #include #include -#include "../../../svnrev.h" -#include "../../../Debug.h" +#include #include #include @@ -31,6 +30,9 @@ namespace BWAPI // This function is called at the start of every match this->initializeData(); + // Set the speed override + this->setLocalSpeedDirect(this->speedOverride); + // initialize the variables //this->frameCount = 0; this->onStartCalled = true; @@ -265,14 +267,14 @@ namespace BWAPI { if ( text.empty() ) return; - if ( !parseText(text) && isFlagEnabled(BWAPI::Flag::UserInput) ) + if ( !parseText(text) ) { if ( externalModuleConnected ) { events.push_back(Event::SendText()); events.back().setText(text.c_str()); } - else + else if( isFlagEnabled(BWAPI::Flag::UserInput) ) sendText("%s", text.c_str()); } } diff --git a/bwapi/BWAPI/Source/BWAPI/GameImpl.cpp b/bwapi/BWAPI/Source/BWAPI/GameImpl.cpp index 1d2b90370..d8f062779 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameImpl.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameImpl.cpp @@ -1,4 +1,4 @@ -#include "../../../svnrev.h" +#include "../../svnrev.h" #include "GameImpl.h" #include @@ -31,7 +31,7 @@ #include "../Config.h" #include "BWtoBWAPI.h" -#include "../../../Debug.h" +#include namespace BWAPI { @@ -883,6 +883,10 @@ namespace BWAPI { return this->lastEventTime; } + void GameImpl::setLastEventTime(int lastEventTime) + { + this->lastEventTime = lastEventTime; + } bool GameImpl::setRevealAll(bool reveal) { if ( !isReplay() ) @@ -1211,9 +1215,6 @@ namespace BWAPI frameCount = s.frameCount; flags = s.flags; - for(unsigned int j = 0; j < this->commandBuffer.size(); ++j) - for (unsigned int i = 0; i < this->commandBuffer[j].size(); ++i) - delete this->commandBuffer[j][i]; this->commandBuffer.clear(); this->commandBuffer.reserve(16); diff --git a/bwapi/BWAPI/Source/BWAPI/GameImpl.h b/bwapi/BWAPI/Source/BWAPI/GameImpl.h index a2014696d..7f31f2b25 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameImpl.h +++ b/bwapi/BWAPI/Source/BWAPI/GameImpl.h @@ -18,6 +18,7 @@ #include #include "CommandOptimizer.h" +#include "Command.h" #include "APMCounter.h" #include "FPSCounter.h" #include "AutoMenuManager.h" @@ -44,7 +45,6 @@ namespace BWAPI { // forwards class AIModule; - class Command; class BulletImpl; class Bulletset; @@ -209,6 +209,7 @@ namespace BWAPI virtual BWAPI::Region getRegionAt(int x, int y) const override; virtual int getLastEventTime() const override; + void setLastEventTime(int lastEventTime); virtual bool setRevealAll(bool reveal = true) override; @@ -256,7 +257,7 @@ namespace BWAPI static void mouseDown(int x, int y); static void mouseUp(int x, int y); - void addToCommandBuffer(Command* command); + void addToCommandBuffer(Command command); void onGameStart(); void onGameEnd(); static int stormIdToPlayerId(int dwStormId); @@ -380,7 +381,7 @@ namespace BWAPI std::unordered_map regionMap; std::array bulletArray; - std::vector< std::vector > commandBuffer; + std::vector> commandBuffer; void updateUnits(); void updateBullets(); diff --git a/bwapi/BWAPI/Source/BWAPI/GameInternals.cpp b/bwapi/BWAPI/Source/BWAPI/GameInternals.cpp index c329ab3df..470551c3d 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameInternals.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameInternals.cpp @@ -11,7 +11,7 @@ #include #include "Command.h" -#include "../../../Debug.h" +#include #include "BW/BWData.h" @@ -379,9 +379,6 @@ namespace BWAPI flags.fill(false); // Clear the latency buffer - for(unsigned int j = 0; j < this->commandBuffer.size(); ++j) - for (unsigned int i = 0; i < this->commandBuffer[j].size(); ++i) - delete this->commandBuffer[j][i]; this->commandBuffer.clear(); this->commandBuffer.reserve(16); @@ -399,7 +396,7 @@ namespace BWAPI this->regionMap.clear(); // Reset game speeds and text size - this->setLocalSpeedDirect(this->speedOverride); + this->setLocalSpeedDirect(std::numeric_limits::min()); this->setFrameSkip(1); this->setTextSize(); this->setGUI(true); diff --git a/bwapi/BWAPI/Source/BWAPI/GameMenu.cpp b/bwapi/BWAPI/Source/BWAPI/GameMenu.cpp index f86cbfe31..b7583a0fe 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameMenu.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameMenu.cpp @@ -7,7 +7,7 @@ #include -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/GameUnits.cpp b/bwapi/BWAPI/Source/BWAPI/GameUnits.cpp index f0d96d651..49fed6c53 100755 --- a/bwapi/BWAPI/Source/BWAPI/GameUnits.cpp +++ b/bwapi/BWAPI/Source/BWAPI/GameUnits.cpp @@ -6,7 +6,7 @@ #include #include -#include "../../../Debug.h" +#include namespace BWAPI { @@ -264,6 +264,7 @@ namespace BWAPI { UnitImpl *u = static_cast(ui); UnitImpl* orderTargetUnit = getUnitFromBWUnit(u->bwunit.orderTarget_pUnit()); + UnitImpl *buildUnit = getUnitFromBWUnit(u->bwunit.currentBuildUnit()); if ( orderTargetUnit && orderTargetUnit->exists() && u->getOrder() == Orders::ConstructingBuilding ) { UnitImpl* j = orderTargetUnit; @@ -288,6 +289,15 @@ namespace BWAPI j->self->isIdle = false; j->self->buildType = j->self->type; } + else if ( buildUnit && buildUnit->exists() && u->isTraining() ) + { + // Apply buildUnit symmetry + UnitImpl* j = buildUnit; + j->self->buildUnit = server.getUnitID(u); + j->self->isConstructing = true; + j->self->isIdle = false; + j->self->buildType = j->self->type; + } if (u->getTransport()) { static_cast(u->getTransport())->loadedUnits.insert(u); diff --git a/bwapi/BWAPI/Source/BWAPI/Map.cpp b/bwapi/BWAPI/Source/BWAPI/Map.cpp index 93ae1a396..6d96f68e0 100755 --- a/bwapi/BWAPI/Source/BWAPI/Map.cpp +++ b/bwapi/BWAPI/Source/BWAPI/Map.cpp @@ -10,7 +10,7 @@ #include "GameImpl.h" #include "PlayerImpl.h" -#include "../../../Debug.h" +#include using namespace std; namespace BWAPI diff --git a/bwapi/BWAPI/Source/BWAPI/PlayerImpl.cpp b/bwapi/BWAPI/Source/BWAPI/PlayerImpl.cpp index 7d6dd56e9..602fd572f 100755 --- a/bwapi/BWAPI/Source/BWAPI/PlayerImpl.cpp +++ b/bwapi/BWAPI/Source/BWAPI/PlayerImpl.cpp @@ -9,7 +9,7 @@ #include -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/RegionImpl.cpp b/bwapi/BWAPI/Source/BWAPI/RegionImpl.cpp index 97ae0f47a..0a83ce166 100755 --- a/bwapi/BWAPI/Source/BWAPI/RegionImpl.cpp +++ b/bwapi/BWAPI/Source/BWAPI/RegionImpl.cpp @@ -4,7 +4,7 @@ #include -#include "../../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPI/Source/BWAPI/Server.cpp b/bwapi/BWAPI/Source/BWAPI/Server.cpp index b0b024d11..f20953674 100755 --- a/bwapi/BWAPI/Source/BWAPI/Server.cpp +++ b/bwapi/BWAPI/Source/BWAPI/Server.cpp @@ -17,9 +17,9 @@ #include #include "../Config.h" -#include "../../../svnrev.h" +#include "../../svnrev.h" -#include "../../../Debug.h" +#include namespace BWAPI { @@ -72,7 +72,9 @@ namespace BWAPI { // Update BWAPI Client updateSharedMemory(); + // auto const onFrameStart = GetTickCount(); callOnFrame(); + // BroodwarImpl.setLastEventTime(GetTickCount() - onFrameStart); processCommands(); } else @@ -263,6 +265,7 @@ namespace BWAPI p->type = i->getType(); p->force = getForceID(i->getForce()); p->color = p2->color; + p->isParticipating = p2->isParticipating; for(int j = 0; j < 12; ++j) { diff --git a/bwapi/BWAPI/Source/BWAPI/UnitImpl.cpp b/bwapi/BWAPI/Source/BWAPI/UnitImpl.cpp index feadeb510..bb14750c3 100755 --- a/bwapi/BWAPI/Source/BWAPI/UnitImpl.cpp +++ b/bwapi/BWAPI/Source/BWAPI/UnitImpl.cpp @@ -13,7 +13,7 @@ #include #include -#include "../../../Debug.h" +#include namespace BWAPI { @@ -78,7 +78,7 @@ namespace BWAPI } // Add to command optimizer if possible, as well as the latency compensation buffer - BroodwarImpl.addToCommandBuffer(new Command(command)); + BroodwarImpl.addToCommandBuffer(Command{ command }); return BroodwarImpl.commandOptimizer.add(command); } bool UnitImpl::issueCommand(UnitCommand command) diff --git a/bwapi/BWAPI/Source/BWAPI/UnitUpdate.cpp b/bwapi/BWAPI/Source/BWAPI/UnitUpdate.cpp index e6ae08cf0..87c769d73 100755 --- a/bwapi/BWAPI/Source/BWAPI/UnitUpdate.cpp +++ b/bwapi/BWAPI/Source/BWAPI/UnitUpdate.cpp @@ -21,7 +21,7 @@ #include "Server.h" #include "BWtoBWAPI.h" -#include "../../../Debug.h" +#include namespace BWAPI { @@ -311,7 +311,6 @@ namespace BWAPI self->lastHitPoints = wasAccessible ? self->hitPoints : _getHitPoints; //getHitPoints self->hitPoints = _getHitPoints; //getHitPoints self->shields = _getType.maxShields() > 0 ? (int)std::ceil(o.shieldPoints()/256.0) : 0; //getShields - self->energy = _getType.isSpellcaster() ? (int)std::ceil(o.energy()/256.0) : 0; //getEnergy self->resources = _getResources; //getResources //self->resourceGroup = _getType.isResourceContainer() ? o.resourceGroup() : 0; //getResourceGroup self->resourceGroup = 0; //getResourceGroup @@ -485,7 +484,6 @@ namespace BWAPI self->lastHitPoints = 0; //getHitPoints self->hitPoints = 0; //getHitPoints self->shields = 0; //getShields - self->energy = 0; //getEnergy //self->resources = 0; //getResources self->resourceGroup = 0; //getResourceGroup self->killCount = 0; //getKillCount @@ -559,6 +557,10 @@ namespace BWAPI self->remainingUpgradeTime = 0; self->remainingBuildTime = 0; self->rallyUnit = -1; + + //------------------------------------------------------------------------------------------------------ + // getEnergy + self->energy = _getType.isSpellcaster() ? (int)std::ceil(o.energy() / 256.0) : 0; //------------------------------------------------------------------------------------------------------ // getTrainingQueue @@ -666,6 +668,7 @@ namespace BWAPI } else { + self->energy = 0; //getEnergy self->buildType = UnitTypes::None; //getBuildType self->trainingQueueCount = 0; //getTrainingQueue self->tech = TechTypes::None; //getTech diff --git a/bwapi/BWAPI/Source/GameUpdate.cpp b/bwapi/BWAPI/Source/GameUpdate.cpp index ca6bf5f26..c942fb7e4 100755 --- a/bwapi/BWAPI/Source/GameUpdate.cpp +++ b/bwapi/BWAPI/Source/GameUpdate.cpp @@ -9,8 +9,8 @@ #include #include -#include "../../../svnrev.h" -#include "../../../Debug.h" +#include "../../svnrev.h" +#include #ifdef _WIN32 #include diff --git a/bwapi/BWAPIClient/Source/Command.h b/bwapi/BWAPIClient/Source/Command.h index 8cfd474fb..382a65d3c 100755 --- a/bwapi/BWAPIClient/Source/Command.h +++ b/bwapi/BWAPIClient/Source/Command.h @@ -1,8 +1,7 @@ #pragma once #include #include - -#include "../../BWAPI/Source/BWAPI/CommandTemp.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPIClient/Source/UnitImpl.cpp b/bwapi/BWAPIClient/Source/UnitImpl.cpp index 1640baf7c..a0f2b3787 100755 --- a/bwapi/BWAPIClient/Source/UnitImpl.cpp +++ b/bwapi/BWAPIClient/Source/UnitImpl.cpp @@ -55,7 +55,7 @@ namespace BWAPI c.x = command.x; c.y = command.y; c.extra = command.extra; - Command(command).execute(0); + Command{ command }.execute(); static_cast(BroodwarPtr)->addUnitCommand(c); lastCommandFrame = Broodwar->getFrameCount(); lastCommand = command; diff --git a/bwapi/BWAPILIB/Source/AIModule.cpp b/bwapi/BWAPILIB/Source/AIModule.cpp index 8358a6833..be05d9e28 100755 --- a/bwapi/BWAPILIB/Source/AIModule.cpp +++ b/bwapi/BWAPILIB/Source/AIModule.cpp @@ -1,6 +1,6 @@ #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/BWAPI.cpp b/bwapi/BWAPILIB/Source/BWAPI.cpp index 9e94f72ee..a28c60769 100755 --- a/bwapi/BWAPILIB/Source/BWAPI.cpp +++ b/bwapi/BWAPILIB/Source/BWAPI.cpp @@ -1,7 +1,7 @@ #include #include "../../svnrev.h" -#include "../../Debug.h" +#include int BWAPI::BWAPI_getRevision() { diff --git a/bwapi/BWAPILIB/Source/BulletType.cpp b/bwapi/BWAPILIB/Source/BulletType.cpp index 47cbdffe6..396c391a4 100755 --- a/bwapi/BWAPILIB/Source/BulletType.cpp +++ b/bwapi/BWAPILIB/Source/BulletType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Color.cpp b/bwapi/BWAPILIB/Source/Color.cpp index 083e7b00a..a86e8b339 100755 --- a/bwapi/BWAPILIB/Source/Color.cpp +++ b/bwapi/BWAPILIB/Source/Color.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include typedef unsigned char BYTE; typedef struct tagRGBQUAD { diff --git a/bwapi/BWAPILIB/Source/DamageType.cpp b/bwapi/BWAPILIB/Source/DamageType.cpp index 68c69aeb8..7aaf23720 100755 --- a/bwapi/BWAPILIB/Source/DamageType.cpp +++ b/bwapi/BWAPILIB/Source/DamageType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Error.cpp b/bwapi/BWAPILIB/Source/Error.cpp index 541f09840..484cc11e6 100755 --- a/bwapi/BWAPILIB/Source/Error.cpp +++ b/bwapi/BWAPILIB/Source/Error.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Event.cpp b/bwapi/BWAPILIB/Source/Event.cpp index b0c114de1..33ecbab59 100755 --- a/bwapi/BWAPILIB/Source/Event.cpp +++ b/bwapi/BWAPILIB/Source/Event.cpp @@ -2,7 +2,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/ExplosionType.cpp b/bwapi/BWAPILIB/Source/ExplosionType.cpp index 20f3bbe67..61d5ff5df 100755 --- a/bwapi/BWAPILIB/Source/ExplosionType.cpp +++ b/bwapi/BWAPILIB/Source/ExplosionType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/GameType.cpp b/bwapi/BWAPILIB/Source/GameType.cpp index 47c2374bb..72dd218ea 100755 --- a/bwapi/BWAPILIB/Source/GameType.cpp +++ b/bwapi/BWAPILIB/Source/GameType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Order.cpp b/bwapi/BWAPILIB/Source/Order.cpp index 3994cf51c..cf4f5498b 100755 --- a/bwapi/BWAPILIB/Source/Order.cpp +++ b/bwapi/BWAPILIB/Source/Order.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Player.cpp b/bwapi/BWAPILIB/Source/Player.cpp index 33c3e9f2c..0603a17f2 100755 --- a/bwapi/BWAPILIB/Source/Player.cpp +++ b/bwapi/BWAPILIB/Source/Player.cpp @@ -115,23 +115,23 @@ char PlayerInterface::getTextColor() const { switch ( this->getColor() ) { - case 111: // red + case Colors::Red: return Text::BrightRed; - case 165: // blue + case Colors::Blue: return Text::Blue; - case 159: // teal + case Colors::Teal: return Text::Teal; - case 164: // purp + case Colors::Purple: return Text::Purple; - case 179: // oj + case Colors::Orange: return Text::Orange; - case 19: // brown + case Colors::Brown: return Text::Brown; - case 84: // white + case Colors::White: return Text::PlayerWhite; - case 135: // yellow + case Colors::Yellow: return Text::PlayerYellow; - case 185: // green p9 + case Colors::Green: return Text::DarkGreen; case 136: // p10 return Text::LightYellow; diff --git a/bwapi/BWAPILIB/Source/PlayerType.cpp b/bwapi/BWAPILIB/Source/PlayerType.cpp index cf5f114aa..edfcd6e2f 100755 --- a/bwapi/BWAPILIB/Source/PlayerType.cpp +++ b/bwapi/BWAPILIB/Source/PlayerType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Race.cpp b/bwapi/BWAPILIB/Source/Race.cpp index 6e36ffc15..c1d94b680 100755 --- a/bwapi/BWAPILIB/Source/Race.cpp +++ b/bwapi/BWAPILIB/Source/Race.cpp @@ -2,7 +2,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/TechType.cpp b/bwapi/BWAPILIB/Source/TechType.cpp index 67ecd1b8c..8b7d55832 100755 --- a/bwapi/BWAPILIB/Source/TechType.cpp +++ b/bwapi/BWAPILIB/Source/TechType.cpp @@ -5,7 +5,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/Unit.cpp b/bwapi/BWAPILIB/Source/Unit.cpp index ab3fe1ecc..30b49c6b5 100755 --- a/bwapi/BWAPILIB/Source/Unit.cpp +++ b/bwapi/BWAPILIB/Source/Unit.cpp @@ -94,27 +94,20 @@ namespace BWAPI return std::numeric_limits::max(); /////// Compute distance - - // retrieve left/top/right/bottom values for calculations - int left = target.x - 1; - int top = target.y - 1; - int right = target.x + 1; - int bottom = target.y + 1; - // compute x distance - int xDist = this->getLeft() - right; + int xDist = this->getLeft() - target.x; if (xDist < 0) { - xDist = left - this->getRight(); + xDist = target.x - (this->getRight() + 1); if (xDist < 0) xDist = 0; } // compute y distance - int yDist = this->getTop() - bottom; + int yDist = this->getTop() - target.y; if (yDist < 0) { - yDist = top - this->getBottom(); + yDist = target.y - (this->getBottom() + 1); if (yDist < 0) yDist = 0; } diff --git a/bwapi/BWAPILIB/Source/UnitCommandType.cpp b/bwapi/BWAPILIB/Source/UnitCommandType.cpp index 034e909cd..d2c15eaba 100755 --- a/bwapi/BWAPILIB/Source/UnitCommandType.cpp +++ b/bwapi/BWAPILIB/Source/UnitCommandType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/UnitSizeType.cpp b/bwapi/BWAPILIB/Source/UnitSizeType.cpp index d16a2d39b..ea5cc9722 100755 --- a/bwapi/BWAPILIB/Source/UnitSizeType.cpp +++ b/bwapi/BWAPILIB/Source/UnitSizeType.cpp @@ -1,7 +1,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/UnitType.cpp b/bwapi/BWAPILIB/Source/UnitType.cpp index 06483cf20..9c9a5a730 100755 --- a/bwapi/BWAPILIB/Source/UnitType.cpp +++ b/bwapi/BWAPILIB/Source/UnitType.cpp @@ -10,7 +10,7 @@ #include #include -#include "../../Debug.h" +#include template class std::allocator; diff --git a/bwapi/BWAPILIB/Source/UpgradeType.cpp b/bwapi/BWAPILIB/Source/UpgradeType.cpp index 33b899e65..5a4926709 100755 --- a/bwapi/BWAPILIB/Source/UpgradeType.cpp +++ b/bwapi/BWAPILIB/Source/UpgradeType.cpp @@ -3,7 +3,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/Source/WeaponType.cpp b/bwapi/BWAPILIB/Source/WeaponType.cpp index 33eae793c..aaa2e0407 100755 --- a/bwapi/BWAPILIB/Source/WeaponType.cpp +++ b/bwapi/BWAPILIB/Source/WeaponType.cpp @@ -6,7 +6,7 @@ #include #include -#include "../../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIB/UnitCommand.cpp b/bwapi/BWAPILIB/UnitCommand.cpp index 8a767ebc6..038e8c0bb 100755 --- a/bwapi/BWAPILIB/UnitCommand.cpp +++ b/bwapi/BWAPILIB/UnitCommand.cpp @@ -4,7 +4,7 @@ #include #include -#include "../Debug.h" +#include namespace BWAPI { diff --git a/bwapi/BWAPILIBTest/BWAPILIBTest.vcxproj b/bwapi/BWAPILIBTest/BWAPILIBTest.vcxproj index 81e17caa2..f77b11781 100755 --- a/bwapi/BWAPILIBTest/BWAPILIBTest.vcxproj +++ b/bwapi/BWAPILIBTest/BWAPILIBTest.vcxproj @@ -19,14 +19,14 @@ DynamicLibrary true - v141 + v141_xp Unicode false DynamicLibrary false - v141 + v141_xp true Unicode false @@ -53,11 +53,12 @@ Level4 Disabled $(VCInstallDir)UnitTest\include;../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;%(PreprocessorDefinitions) + WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;%(PreprocessorDefinitions) true 4505 true false + /Zc:threadSafeInit- %(AdditionalOptions) Windows @@ -75,10 +76,11 @@ true true $(VCInstallDir)UnitTest\include;../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;%(PreprocessorDefinitions) + WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;%(PreprocessorDefinitions) true 4505 true + /Zc:threadSafeInit- %(AdditionalOptions) Windows diff --git a/bwapi/BWAPI_PluginInjector/BWAPI_PluginInjector.vcxproj b/bwapi/BWAPI_PluginInjector/BWAPI_PluginInjector.vcxproj index d313c01e3..ed4c95e6e 100755 --- a/bwapi/BWAPI_PluginInjector/BWAPI_PluginInjector.vcxproj +++ b/bwapi/BWAPI_PluginInjector/BWAPI_PluginInjector.vcxproj @@ -1,10 +1,18 @@  + + Debug_NoCopy + Win32 + Debug Win32 + + Release_NoCopy + Win32 + Release Win32 @@ -19,13 +27,24 @@ DynamicLibrary - v141 + v141_xp + Unicode + + + DynamicLibrary + v141_xp Unicode DynamicLibrary true - v141 + v141_xp + Unicode + + + DynamicLibrary + true + v141_xp Unicode @@ -34,13 +53,20 @@ + + + + + + <_ProjectFileVersion>10.0.30319.1 false + false @@ -48,7 +74,7 @@ MaxSpeed Speed true - NOMINMAX;WIN32;NDEBUG;_WINDOWS;_USRDLL;CREATETHREADREMOTETEST_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;CREATETHREADREMOTETEST_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreaded false @@ -61,6 +87,7 @@ true true true + /Zc:threadSafeInit- %(AdditionalOptions) Creating ChaosLauncherInjector readme @@ -83,17 +110,63 @@ COPY /Y "$(OutDir)$(TargetName)$(TargetExt)" "$(SolutionDir)..\Release_Binary\MPQDraft\$(ProjectName).qdp" + + + + MaxSpeed + Speed + true + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;CREATETHREADREMOTETEST_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + true + MultiThreaded + false + false + Level4 + + + %(AdditionalIncludeDirectories) + AnySuitable + true + true + true + /Zc:threadSafeInit- %(AdditionalOptions) + + + + + + + + + + + Windows + true + true + MachineX86 + Advapi32.lib;User32.lib;Shell32.lib + false + QDPlugin.def + + + + + + + + Disabled - NOMINMAX;WIN32;_DEBUG;_WINDOWS;_USRDLL;CREATETHREADREMOTETEST_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;CREATETHREADREMOTETEST_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDebug Level4 ProgramDatabase %(AdditionalIncludeDirectories) true + /Zc:threadSafeInit- %(AdditionalOptions) Creating ChaosLauncherInjector readme @@ -114,6 +187,41 @@ COPY /Y "$(OutDir)$(TargetName)$(TargetExt)" "$(SolutionDir)..\Release_Binary\MP COPY /Y "$(OutDir)$(TargetName)$(TargetExt)" "$(SolutionDir)..\Release_Binary\MPQDraft\$(ProjectName)d.qdp" + + + + Disabled + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;CREATETHREADREMOTETEST_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + true + MultiThreadedDebug + Level4 + ProgramDatabase + %(AdditionalIncludeDirectories) + true + /Zc:threadSafeInit- %(AdditionalOptions) + + + + + + + + + false + + + Windows + MachineX86 + Advapi32.lib;User32.lib;Shell32.lib + QDPlugin.def + + + + + + + + diff --git a/bwapi/BWAPI_PluginInjector/common.h b/bwapi/BWAPI_PluginInjector/common.h index 1794dad90..335272cdd 100755 --- a/bwapi/BWAPI_PluginInjector/common.h +++ b/bwapi/BWAPI_PluginInjector/common.h @@ -1,6 +1,6 @@ #include -#include "../svnrev.h" +#include "../include/svnrev.h" #ifdef _DEBUG #define MODULE "BWAPId.dll" diff --git a/bwapi/BWScriptEmulator/BWScriptEmulator.vcxproj b/bwapi/BWScriptEmulator/BWScriptEmulator.vcxproj index 5fbd440af..b85e18247 100755 --- a/bwapi/BWScriptEmulator/BWScriptEmulator.vcxproj +++ b/bwapi/BWScriptEmulator/BWScriptEmulator.vcxproj @@ -19,12 +19,12 @@ DynamicLibrary true - v141 + v141_xp DynamicLibrary Unicode - v141 + v141_xp @@ -45,13 +45,14 @@ Disabled ../include;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;_DEBUG;_WINDOWS;_USRDLL;BWSCRIPTEMULATOR_EXPORTS;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;BWSCRIPTEMULATOR_EXPORTS;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL Level3 ProgramDatabase true + /Zc:threadSafeInit- %(AdditionalOptions) true @@ -65,12 +66,13 @@ MaxSpeed true ../include;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;NDEBUG;_WINDOWS;_USRDLL;BWSCRIPTEMULATOR;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;BWSCRIPTEMULATOR;%(PreprocessorDefinitions) MultiThreadedDLL true Level3 ProgramDatabase true + /Zc:threadSafeInit- %(AdditionalOptions) true diff --git a/bwapi/CopyProjects/CopyProjects.vcxproj b/bwapi/CopyProjects/CopyProjects.vcxproj new file mode 100755 index 000000000..4d417701b --- /dev/null +++ b/bwapi/CopyProjects/CopyProjects.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {D571C4C8-3978-41A9-8DBB-C4B5B84B0E6B} + CopyProjects + + + + Utility + true + v141 + + + Utility + false + v141 + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + XCOPY "$(SolutionDir)include\*.h" "$(SolutionDir)..\Release_Binary\include" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.vcxproj" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.h" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.cpp" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.vcxproj" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.cpp" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.h" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.vcxproj" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.cpp" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.h" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.vcxproj" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.cpp" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.h" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.vcxproj" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.cpp" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.h" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.vcxproj" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.cpp" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.h" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)Shared\*.cpp" "$(SolutionDir)..\Release_Binary\Shared" /S /C /I /R /Y +XCOPY "$(SolutionDir)Shared\*.h" "$(SolutionDir)..\Release_Binary\Shared" /S /C /I /R /Y + + Copying include files, BWAPILIB project, and example projects to final release + + + + + Level3 + Disabled + true + true + + + + + + + XCOPY "$(SolutionDir)include\*.h" "$(SolutionDir)..\Release_Binary\include" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.vcxproj" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.h" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIModule\*.cpp" "$(SolutionDir)..\Release_Binary\ExampleAIModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.vcxproj" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.cpp" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleAIClient\*.h" "$(SolutionDir)..\Release_Binary\ExampleAIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.vcxproj" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.cpp" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)ExampleTournamentModule\*.h" "$(SolutionDir)..\Release_Binary\ExampleTournamentModule" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.vcxproj" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.cpp" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)AIModuleLoader\*.h" "$(SolutionDir)..\Release_Binary\AIModuleLoader" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.vcxproj" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.cpp" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPILIB\*.h" "$(SolutionDir)..\Release_Binary\BWAPILIB" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.vcxproj" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.vcxproj.filters" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.cpp" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)BWAPIClient\*.h" "$(SolutionDir)..\Release_Binary\BWAPIClient" /S /C /I /R /Y +XCOPY "$(SolutionDir)Shared\*.cpp" "$(SolutionDir)..\Release_Binary\Shared" /S /C /I /R /Y +XCOPY "$(SolutionDir)Shared\*.h" "$(SolutionDir)..\Release_Binary\Shared" /S /C /I /R /Y + + Copying include files, BWAPILIB project, and example projects to final release + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + \ No newline at end of file diff --git a/bwapi/CopyProjects/CopyProjects.vcxproj.filters b/bwapi/CopyProjects/CopyProjects.vcxproj.filters new file mode 100755 index 000000000..a69f7463c --- /dev/null +++ b/bwapi/CopyProjects/CopyProjects.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + \ No newline at end of file diff --git a/bwapi/DevAIModule/DevAIModule.vcxproj b/bwapi/DevAIModule/DevAIModule.vcxproj index b06d7673f..f5c14b9af 100755 --- a/bwapi/DevAIModule/DevAIModule.vcxproj +++ b/bwapi/DevAIModule/DevAIModule.vcxproj @@ -19,12 +19,12 @@ DynamicLibrary true - v141 + v141_xp DynamicLibrary Unicode - v141 + v141_xp @@ -45,7 +45,7 @@ Disabled ../include;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;_DEBUG;_WINDOWS;_USRDLL;DEVAIMODULE_EXPORTS;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;DEVAIMODULE_EXPORTS;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -53,6 +53,7 @@ ProgramDatabase 4996 true + /Zc:threadSafeInit- %(AdditionalOptions) true @@ -66,7 +67,7 @@ MaxSpeed true ../include;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;NDEBUG;_WINDOWS;_USRDLL;DEVAIMODULE_EXPORTS;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;DEVAIMODULE_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL true Level3 @@ -77,6 +78,7 @@ true true true + /Zc:threadSafeInit- %(AdditionalOptions) true diff --git a/bwapi/DevAIModule/Source/DevAIModule.cpp b/bwapi/DevAIModule/Source/DevAIModule.cpp old mode 100644 new mode 100755 diff --git a/bwapi/Documentation/Documentation.vcxproj b/bwapi/Documentation/Documentation.vcxproj index 837083963..cb9f33d09 100755 --- a/bwapi/Documentation/Documentation.vcxproj +++ b/bwapi/Documentation/Documentation.vcxproj @@ -9,13 +9,12 @@ {2BED9E24-4DAE-43A1-8D7F-A4EC05E53DAE} Documentation - 8.1 Makefile false - v141 + v141_xp diff --git a/bwapi/DocumentationGen/DocumentationGen.vcxproj b/bwapi/DocumentationGen/DocumentationGen.vcxproj index ec72e410b..c9ba023d8 100755 --- a/bwapi/DocumentationGen/DocumentationGen.vcxproj +++ b/bwapi/DocumentationGen/DocumentationGen.vcxproj @@ -18,13 +18,13 @@ Application true - v141 + v141_xp MultiByte Application false - v141 + v141_xp true @@ -43,13 +43,14 @@ Level3 Disabled ../include/;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true false + /Zc:threadSafeInit- %(AdditionalOptions) true - ../lib/BWAPId.lib;%(AdditionalDependencies) + Console @@ -59,14 +60,15 @@ true true ../include/;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + /Zc:threadSafeInit- %(AdditionalOptions) true true true - ../lib/BWAPI.lib;%(AdditionalDependencies) + Console @@ -93,6 +95,11 @@ + + + {843656fd-9bfd-47bf-8460-7bfe9710ea2c} + + diff --git a/bwapi/Installer/Installer.vcxproj b/bwapi/Installer/Installer.vcxproj index fc19cdbf0..ba3f834d3 100755 --- a/bwapi/Installer/Installer.vcxproj +++ b/bwapi/Installer/Installer.vcxproj @@ -14,13 +14,12 @@ {D5928E29-F115-474E-BA42-9AB710B0E892} Installer - 8.1 Makefile false - v141 + v141_xp true diff --git a/bwapi/SNP_DirectIP/SNP_DirectIP.vcxproj b/bwapi/SNP_DirectIP/SNP_DirectIP.vcxproj index 8b2af562c..214f63012 100755 --- a/bwapi/SNP_DirectIP/SNP_DirectIP.vcxproj +++ b/bwapi/SNP_DirectIP/SNP_DirectIP.vcxproj @@ -1,10 +1,18 @@  + + Debug_NoCopy + Win32 + Debug Win32 + + Release_NoCopy + Win32 + Release Win32 @@ -19,12 +27,22 @@ DynamicLibrary true - v141 + v141_xp + + + DynamicLibrary + true + v141_xp DynamicLibrary Unicode - v141 + v141_xp + + + DynamicLibrary + Unicode + v141_xp @@ -32,19 +50,27 @@ + + + + + + <_ProjectFileVersion>10.0.40219.1 true + true false + false Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;SNP_DIRECTIP_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;SNP_DIRECTIP_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -54,6 +80,7 @@ ../Util/Source;../Storm;%(AdditionalIncludeDirectories) true true + /Zc:threadSafeInit- %(AdditionalOptions) ws2_32.lib;%(AdditionalDependencies) @@ -66,11 +93,38 @@ copy /Y /B "$(OutDir)$(TargetName)$(TargetExt)" + "SNP\caps.mpq" "$(OutDir)$(TargetName).snp" + + + Disabled + WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;SNP_DIRECTIP_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + ../Util/Source;../Storm;%(AdditionalIncludeDirectories) + true + true + /Zc:threadSafeInit- %(AdditionalOptions) + + + ws2_32.lib;%(AdditionalDependencies) + SNP/SNPModule.def + true + Windows + MachineX86 + + + + + + MaxSpeed true - WIN32;NDEBUG;_WINDOWS;_USRDLL;SNP_DIRECTIP_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;SNP_DIRECTIP_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -80,6 +134,7 @@ ../Util/Source;../Storm;%(AdditionalIncludeDirectories) true true + /Zc:threadSafeInit- %(AdditionalOptions) ws2_32.lib;%(AdditionalDependencies) @@ -94,6 +149,36 @@ copy /Y /B "$(OutDir)$(TargetName)$(TargetExt)" + "SNP\caps.mpq" "$(SolutionDir)..\Release_Binary\Starcraft\$(TargetName).snp" + + + MaxSpeed + true + WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;SNP_DIRECTIP_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + ../Util/Source;../Storm;%(AdditionalIncludeDirectories) + true + true + /Zc:threadSafeInit- %(AdditionalOptions) + + + ws2_32.lib;%(AdditionalDependencies) + SNP/SNPModule.def + true + Windows + true + true + MachineX86 + + + + + + diff --git a/bwapi/SVNRevGen/SVNRevGen.vcxproj b/bwapi/SVNRevGen/SVNRevGen.vcxproj index 75208ca81..05c8e9e1b 100755 --- a/bwapi/SVNRevGen/SVNRevGen.vcxproj +++ b/bwapi/SVNRevGen/SVNRevGen.vcxproj @@ -18,13 +18,13 @@ Utility true - v141 + v141_xp MultiByte Utility false - v141 + v141_xp true MultiByte @@ -50,8 +50,8 @@ - pushd "$(SolutionDir)" -cscript "./revisionUpdate.vbs" + pushd ".." +cscript "./revisionUpdate.vbs" popd @@ -75,8 +75,8 @@ popd - pushd "$(SolutionDir)" -cscript "./revisionUpdate.vbs" + pushd ".." +cscript "./revisionUpdate.vbs" popd diff --git a/bwapi/Shared/Templates.h b/bwapi/Shared/Templates.h index bfe64cd55..55133bc51 100755 --- a/bwapi/Shared/Templates.h +++ b/bwapi/Shared/Templates.h @@ -252,7 +252,7 @@ namespace BWAPI for (BWAPI::Unit m : Broodwar->getStaticMinerals()) { TilePosition tp = m->getInitialTilePosition(); - if ( (Broodwar->isVisible(tp) || Broodwar->isVisible(tp.x + 1, tp.y)) && !m->isVisible() ) + if ( (Broodwar->isVisible(tp) || Broodwar->isVisible(tp.x + 1, tp.y)) && !m->exists() ) continue; // tile position is visible, but mineral is not => mineral does not exist if (tp.x > lt.x - 5 && tp.y > lt.y - 4 && @@ -466,6 +466,8 @@ namespace BWAPI { if ( !targetUnit || !targetUnit->exists() ) return Broodwar->setLastError(Errors::Unit_Does_Not_Exist); + if ( !targetUnit->isVisible() && !Broodwar->isFlagEnabled(Flag::CompleteMapInformation) ) + return false; if ( !targetUnit->isCompleted() && !targetUnit->getType().isBuilding() && !targetUnit->isMorphing() && diff --git a/bwapi/Storm/Storm.vcxproj b/bwapi/Storm/Storm.vcxproj index 856db6070..36d66033d 100755 --- a/bwapi/Storm/Storm.vcxproj +++ b/bwapi/Storm/Storm.vcxproj @@ -14,7 +14,7 @@ DynamicLibrary - v141 + v141_xp Unicode @@ -31,8 +31,7 @@ MaxSpeed - true - NOMINMAX;WIN32;NDEBUG;_WINDOWS;_USRDLL;STORM_EXPORTS;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;STORM_EXPORTS;%(PreprocessorDefinitions) Sync 1Byte false @@ -46,6 +45,7 @@ true true true + /Zc:threadSafeInit- %(AdditionalOptions) storm.def diff --git a/bwapi/TestAIModule/TestAIModule.vcxproj b/bwapi/TestAIModule/TestAIModule.vcxproj index 8db4aadcd..c218147d8 100755 --- a/bwapi/TestAIModule/TestAIModule.vcxproj +++ b/bwapi/TestAIModule/TestAIModule.vcxproj @@ -19,12 +19,12 @@ DynamicLibrary true - v141 + v141_xp DynamicLibrary Unicode - v141 + v141_xp @@ -45,7 +45,7 @@ Disabled ../include; ../Util/Source/Util;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;_DEBUG;_WINDOWS;_USRDLL;EXAMPLEAIMODULE_EXPORTS;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;EXAMPLEAIMODULE_EXPORTS;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -54,6 +54,7 @@ Level3 ProgramDatabase true + /Zc:threadSafeInit- %(AdditionalOptions) true @@ -67,7 +68,7 @@ MaxSpeed true ../include;../Util/Source/Util;%(AdditionalIncludeDirectories) - NOMINMAX;WIN32;NDEBUG;_WINDOWS;_USRDLL;EXAMPLEAIMODULE_EXPORTS;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;EXAMPLEAIMODULE_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -79,6 +80,7 @@ true true true + /Zc:threadSafeInit- %(AdditionalOptions) true diff --git a/bwapi/include/BWAPI.h b/bwapi/include/BWAPI.h index 4e2f718ff..a5827e229 100755 --- a/bwapi/include/BWAPI.h +++ b/bwapi/include/BWAPI.h @@ -73,7 +73,7 @@ namespace BWAPI /// /// @note This value is purposely high to avoid collisions with revision values. /// @since 4.2.0 - const int CLIENT_VERSION = 10002; + const int CLIENT_VERSION = 10003; } #endif diff --git a/bwapi/include/BWAPI/Client/CommandTemp.h b/bwapi/include/BWAPI/Client/CommandTemp.h new file mode 100755 index 000000000..9929a811a --- /dev/null +++ b/bwapi/include/BWAPI/Client/CommandTemp.h @@ -0,0 +1,1004 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +namespace BWAPI +{ + template + class CommandTemp + { + public: + CommandTemp(const UnitCommand& command) : command(command) { } + + void execute(); + void execute(bool isCurrentFrame); + + void insertIntoCommandBuffer(std::vector>> &buf) && { + const auto addToBuffer = [&buf](auto &&command, int frames) + { + command.execute(frames == 0); + + if (static_cast(buf.size()) < frames) + { + buf.resize(frames); // Will probably never trigger, since we resize + // the buffer in applyLatencyCompensation() + // but it's better to be safe. + } + + if(frames > 0) + buf[frames - 1].push_back(std::forward(command)); // Forward rvalue ref + }; + + auto orderEvent = makeEvent(EventType::Order); + auto finishEvent = makeEvent(EventType::Finish); + + switch ((UnitCommandType) command.type) { + // RLF: Resource event + // RLF + 1: Order event + // RLF + 2: Finish event + case UnitCommandTypes::Cancel_Construction: + addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames()); + addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1); + addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 2); + break; + + // RLF: Resource event + // RLF + 1: Order event + case UnitCommandTypes::Build_Addon: + case UnitCommandTypes::Cancel_Addon: + case UnitCommandTypes::Cancel_Research: + case UnitCommandTypes::Cancel_Upgrade: + case UnitCommandTypes::Morph: + addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames()); + addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1); + break; + + // RLF: Resource event + // RLF + 1: Order event (only for building -> building morphs) + // RLF + 13: Finish event (only for unit -> unit morphs) + // RLF + 15: Finish event (only for building -> building morphs) + case UnitCommandTypes::Cancel_Morph: + addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames()); + + if (auto unit = reinterpret_cast(command.unit); + unit && unit->getType().isBuilding()) + { + addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1); + addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 15); + } + else + { + addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 13); + } + break; + + // RLF: Resource event + // RLF + 1: Order event + // RLF + 3: Finish event + case UnitCommandTypes::Cancel_Train: + case UnitCommandTypes::Cancel_Train_Slot: + addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames()); + addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1); + addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 3); + break; + + // RLF: Order event + // RLF + 1: Finish event + case UnitCommandTypes::Halt_Construction: + eventType = EventType::Order; + addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames()); + addToBuffer(finishEvent, Broodwar->getRemainingLatencyFrames() + 1); + break; + + default: + addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames()); + break; + } + + } + + private: + enum struct EventType { Order, Resource, Finish }; + CommandTemp makeEvent(EventType type) + { + CommandTemp other{ command }; + other.eventType = type; + return other; + } + + static int getUnitID(Unit unit); + UnitCommand command; + EventType eventType = EventType::Resource; + int savedExtra = -1; + int savedExtra2 = -1; + + PlayerImpl* player = nullptr; + }; + + template + int CommandTemp::getUnitID(Unit unit) + { + if ( !unit ) + return -1; + return unit->getID(); + } + + template + void CommandTemp::execute() + { + switch((UnitCommandType) command.type) + { + case UnitCommandTypes::Halt_Construction: + eventType = EventType::Order; + [[fallthrough]]; + default: + execute(Broodwar->getRemainingLatencyFrames() == 0); + break; + } + } + + template + void CommandTemp::execute(const bool isCurrentFrame) + { + // Immediately return if latency compensation is disabled or if the command was queued + if (!Broodwar->isLatComEnabled() || command.isQueued()) return; + UnitImpl *unit = reinterpret_cast(command.unit); + UnitImpl *target = reinterpret_cast(command.target); + + if (isCurrentFrame) { + switch ((UnitCommandType) command.type) // Commands which do things during the current frame + { + case UnitCommandTypes::Morph: // Morph, Build_Addon and Train orders may reserve resources or supply that + case UnitCommandTypes::Build_Addon: // SC does not take until the next frame to protect bots from overspending. + case UnitCommandTypes::Train: + if(eventType == EventType::Resource) + break; + return; + default: + return; + } + } + + // Get the player (usually the unit's owner) + if (!player) + player = static_cast(unit ? unit->getPlayer() : Broodwar->self()); + + // Existence test + if (!unit->self->exists) + return; + + // Move test + switch ((UnitCommandType) command.type) + { + case UnitCommandTypes::Follow: + case UnitCommandTypes::Hold_Position: + case UnitCommandTypes::Move: + case UnitCommandTypes::Patrol: + case UnitCommandTypes::Right_Click_Position: + case UnitCommandTypes::Attack_Move: + if (!unit->getType().canMove()) + return; + break; + default: + break; + } + + // Apply command changes + switch((UnitCommandType) command.type) + { + // RLF + case UnitCommandTypes::Attack_Move: + unit->self->order = Orders::AttackMove; + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + break; + + // RLF + case UnitCommandTypes::Attack_Unit: + if (!target || !target->self->exists || !unit->getType().canAttack()) + return; + unit->self->order = Orders::AttackUnit; + unit->self->target = getUnitID(target); + break; + + // RLF + case UnitCommandTypes::Build: + unit->self->order = Orders::PlaceBuilding; + unit->self->isConstructing = true; + unit->self->isIdle = false; + unit->self->buildType = command.extra; + break; + + // For building addons, SC takes minerals on RLF + 1. + // Latcom will do as with building->building morph and reserve these resources. + // RLF: Resource event + // RLF + 1: Order event + case UnitCommandTypes::Build_Addon: { + UnitType addonType{ command.extra }; + switch (eventType) + { + case EventType::Resource: + player->self->minerals -= static_cast(addonType.mineralPrice()); + player->self->gas -= static_cast(addonType.gasPrice()); + + if (!isCurrentFrame) // We will pretend the building is busy building, this doesn't + { + unit->self->isIdle = false; + unit->self->order = Orders::PlaceAddon; + } + break; + + case EventType::Order: + unit->self->isConstructing = true; + unit->self->order = Orders::Nothing; + unit->self->secondaryOrder = Orders::BuildAddon; + unit->self->buildType = command.extra; + break; + } + } + break; + + // RLF + case UnitCommandTypes::Burrow: + unit->self->order = Orders::Burrowing; + break; + + // RLF: Resource event + // RLF + 1: Order event + case UnitCommandTypes::Cancel_Addon: + switch(eventType) + { + case EventType::Resource: { + UnitType addonType{ unit->self->buildType }; + player->self->minerals += static_cast(addonType.mineralPrice() * 0.75); + player->self->gas += static_cast(addonType.gasPrice() * 0.75); + unit->self->buildType = UnitTypes::None; + } + break; + case EventType::Order: + unit->self->remainingBuildTime = 0; + unit->self->isConstructing = false; + unit->self->order = Orders::Nothing; + unit->self->isIdle = true; + unit->self->buildUnit = -1; + break; + } + + break; + + // RLF: Resource event + // RLF + 1: Order event + // RLF + 2: Finish event + case UnitCommandTypes::Cancel_Construction: + { + if (unit->getType().getRace() == Races::Terran) + { + if (auto builder = static_cast(Broodwar->getUnit(unit->self->buildUnit)); + builder && builder->exists()) + { + switch (eventType) + { + case EventType::Resource: + builder->self->buildType = UnitTypes::None; + break; + case EventType::Order: + builder->self->isConstructing = false; + builder->self->order = Orders::ResetCollision; + break; + case EventType::Finish: + builder->self->order = Orders::PlayerGuard; + break; + } + } + } + + if (eventType == EventType::Resource) + { + unit->self->buildUnit = -1; + player->self->minerals += static_cast(unit->getType().mineralPrice() * 0.75); + player->self->gas += static_cast(unit->getType().gasPrice() * 0.75); + unit->self->remainingBuildTime = 0; + } + + if (unit->getType().getRace() == Races::Zerg) + { + switch (eventType) + { + case EventType::Resource: + unit->self->type = unit->getType().whatBuilds().first; + unit->self->buildType = UnitTypes::None; + unit->self->isMorphing = false; + unit->self->order = Orders::ResetCollision; + unit->self->isConstructing = false; + + player->self->supplyUsed[unit->getType().getRace()] += unit->getType().supplyRequired(); + break; + + case EventType::Order: + unit->self->order = Orders::PlayerGuard; + unit->self->isIdle = true; + break; + } + } + + break; + } + + + // RLF: Resource event + // RLF + 1: Order event (only for builing -> building morphs) + // RLF + 13: Finish event (only for unit -> unit morphs) + // RLF + 15: Finish event (only for building -> building morphs) + case UnitCommandTypes::Cancel_Morph: + switch(eventType) + { + case EventType::Resource: + { + UnitType builtType{ unit->self->buildType }; + UnitType newType{ builtType.whatBuilds().first }; + + if (newType.isBuilding()) + { + player->self->minerals += static_cast(builtType.mineralPrice() * 0.75); + player->self->gas += static_cast(builtType.gasPrice() * 0.75); + } + else + { + player->self->minerals += builtType.mineralPrice(); + player->self->gas += builtType.gasPrice(); + } + + if (newType.isBuilding() && newType.producesCreep()) + { + unit->self->order = Orders::InitCreepGrowth; + } + + if (unit->self->type != UnitTypes::Zerg_Egg) { // Issue #781 + // https://github.com/bwapi/bwapi/issues/781 + unit->self->type = newType; + } + + unit->self->buildType = UnitTypes::None; + unit->self->isConstructing = false; + unit->self->isMorphing = false; + unit->self->isCompleted = true; + unit->self->remainingBuildTime = 0; + } + + break; + + case EventType::Order: + if (unit->getType().isBuilding()) // This event would hopefully not have been created + { // if this wasn't true (see event note above) + unit->self->isIdle = true; + unit->self->order = Orders::Nothing; + if(unit->self->type == UnitTypes::Zerg_Hatchery || unit->self->type == UnitTypes::Zerg_Lair) + { // Type should have updated during last event to the cancelled type + unit->self->secondaryOrder = Orders::SpreadCreep; + } + } + else + { + player->self->supplyUsed[unit->getType().getRace()] -= + unit->getType().supplyRequired() * (1 + static_cast(unit->getType().isTwoUnitsInOneEgg())); + + player->self->supplyUsed[unit->getType().getRace()] += // Could these races be different? Probably not. + // Should we handle it? Definetely. + unit->getType().whatBuilds().first.supplyRequired() * unit->getType().whatBuilds().second; + // Note: unit->getType().whatBuilds().second is always 1 but we + // might as well handle the general case, in case Blizzard + // all of a sudden allows you to cancel archon morphs + } + + break; + + case EventType::Finish: + if(unit->self->type == UnitTypes::Zerg_Hatchery || unit->self->type == UnitTypes::Zerg_Lair) + { + unit->self->secondaryOrder = Orders::SpawningLarva; + } + else if(!unit->getType().isBuilding()) + { + unit->self->order = Orders::PlayerGuard; + unit->self->isCompleted = true; + unit->self->isConstructing = false; + unit->self->isIdle = true; + unit->self->isMorphing = false; + } + break; + } + + break; + + // RLF: Resource event + // RLF + 1: Order update + case UnitCommandTypes::Cancel_Research: + { + switch(eventType) + { + case EventType::Resource: + { + TechType techType{ unit->self->tech }; + player->self->minerals += techType.mineralPrice(); + player->self->gas += techType.gasPrice(); + unit->self->remainingResearchTime = 0; + unit->self->tech = TechTypes::None; + } + break; + + case EventType::Order: + unit->self->order = Orders::Nothing; + unit->self->isIdle = true; + break; + } + } + + break; + + // RLF: Resource event + // RLF + 1: Order event + // RLF + 3: Finish event + case UnitCommandTypes::Cancel_Train_Slot: + if (command.extra != 0) + { + if (eventType == EventType::Resource) + { + UnitType unitType{ unit->self->trainingQueue[command.extra] }; + player->self->minerals += unitType.mineralPrice(); + player->self->gas += unitType.gasPrice(); + + // Shift training queue back one slot after the cancelled unit + for (int i = command.extra; i < 4; ++i) + { + unit->self->trainingQueue[i] = unit->self->trainingQueue[i + 1]; + } + + --unit->self->trainingQueueCount; + } + break; + } + + // If we're cancelling slot 0, we fall through to Cancel_Train. + [[fallthrough]]; + + // RLF: Resource event + // RLF + 1: Order event + // RLF + 3: Finish event + case UnitCommandTypes::Cancel_Train: { + switch(eventType) + { + case EventType::Resource: + { + UnitType unitType{ unit->self->trainingQueue[unit->self->trainingQueueCount - 1] }; + player->self->minerals += unitType.mineralPrice(); + player->self->gas += unitType.gasPrice(); + + unit->self->buildUnit = -1; + + if (unit->self->trainingQueueCount == 1) + { + unit->self->isIdle = false; + unit->self->isTraining = false; + } + break; + } + + case EventType::Order: + { + UnitType unitType{ unit->self->trainingQueue[--unit->self->trainingQueueCount] }; + player->self->supplyUsed[unitType.getRace()] -= unitType.supplyRequired(); + + if (unit->self->trainingQueueCount == 0) + { + unit->self->buildType = UnitTypes::None; + } + else + { + // Actual time decreases, but we'll let it be the buildTime until latency catches up. + unit->self->remainingTrainTime = + static_cast(unit->self->trainingQueue[unit->self->trainingQueueCount - 1]).buildTime(); + unit->self->buildType = unit->self->trainingQueue[unit->self->trainingQueueCount - 1]; + } + } + + break; + + case EventType::Finish: + if (unit->self->buildType == UnitTypes::None) + { + unit->self->order = Orders::Nothing; + } + break; + } + break; + } + + // RLF: Resource event + // RLF + 1: Order event + case UnitCommandTypes::Cancel_Upgrade: + switch(eventType) + { + case EventType::Resource: + { + UpgradeType upgradeType = unit->self->upgrade; + const int nextLevel = unit->getPlayer()->getUpgradeLevel(upgradeType) + 1; + + player->self->minerals += upgradeType.mineralPrice(nextLevel); + player->self->gas += upgradeType.gasPrice(nextLevel); + + unit->self->upgrade = UpgradeTypes::None; + unit->self->remainingUpgradeTime = 0; + } + break; + + case EventType::Order: + unit->self->order = Orders::Nothing; + unit->self->isIdle = true; + break; + } + + break; + + // RLF + case UnitCommandTypes::Cloak: + unit->self->order = Orders::Cloak; + unit->self->energy -= unit->getType().cloakingTech().energyCost(); + break; + + // RLF + case UnitCommandTypes::Decloak: + unit->self->order = Orders::Decloak; + break; + + // RLF + case UnitCommandTypes::Follow: + unit->self->order = Orders::Follow; + unit->self->target = getUnitID(target); + unit->self->isIdle = false; + unit->self->isMoving = true; + break; + + // RLF + case UnitCommandTypes::Gather: + unit->self->target = getUnitID(target); + unit->self->isIdle = false; + unit->self->isMoving = true; + unit->self->isGathering = true; + + // @TODO: Fully time and test this order + if (target->getType().isMineralField()) + unit->self->order = Orders::MoveToMinerals; + else if (target->getType().isRefinery()) + unit->self->order = Orders::MoveToGas; + + break; + + // RLF: Order event + // RLF + 1: Finish event + case UnitCommandTypes::Halt_Construction: + switch(eventType) + { + case EventType::Order: + if (auto building = reinterpret_cast(Broodwar->getUnit(unit->self->buildUnit)); + building) + { + building->self->buildUnit = -1; + } + unit->self->buildUnit = -1; + unit->self->order = Orders::ResetCollision; + unit->self->isConstructing = false; + unit->self->buildType = UnitTypes::None; + break; + + case EventType::Finish: + unit->self->order = Orders::PlayerGuard; + unit->self->isIdle = true; + break; + } + + break; + + // RLF + case UnitCommandTypes::Hold_Position: + unit->self->isMoving = false; + unit->self->isIdle = false; + unit->self->order = Orders::HoldPosition; + break; + + // RLF + case UnitCommandTypes::Land: + unit->self->order = Orders::BuildingLand; + unit->self->isIdle = false; + break; + + // RLF + case UnitCommandTypes::Lift: + unit->self->order = Orders::BuildingLiftOff; + unit->self->isIdle = false; + break; + + // RLF + case UnitCommandTypes::Load: + if (unit->getType() == UnitTypes::Terran_Bunker) + { + unit->self->order = Orders::PickupBunker; + unit->self->target = getUnitID(target); + } + else if (unit->getType().spaceProvided()) + { + unit->self->order = Orders::PickupTransport; + unit->self->target = getUnitID(target); + } + else if (target->getType().spaceProvided()) + { + unit->self->order = Orders::EnterTransport; + unit->self->target = getUnitID(target); + } + unit->self->isIdle = false; + + break; + + // For morph, SC takes minerals on RLF + 1 if morphing building->building. + // Latcom will do as with addons and reserve these resources. + // RLF: Resource event + // RLF + 1: Order event + case UnitCommandTypes::Morph: + { + UnitType morphType{ command.extra }; + + switch (eventType) + { + case EventType::Resource: + if(!isCurrentFrame) + { + unit->self->isCompleted = false; + unit->self->isIdle = false; + unit->self->isConstructing = true; + unit->self->isMorphing = true; + unit->self->buildType = morphType; + } + + if (unit->getType().isBuilding()) + { + if (!isCurrentFrame) + { // Actions that don't happen when we're reserving resources + unit->self->order = Orders::ZergBuildingMorph; + unit->self->type = morphType; + } + player->self->minerals -= morphType.mineralPrice(); + player->self->gas -= morphType.gasPrice(); + } + else + { + player->self->supplyUsed[morphType.getRace()] += morphType.supplyRequired() * + (1 + static_cast(morphType.isTwoUnitsInOneEgg())) - unit->getType().supplyRequired(); + + if(!isCurrentFrame) + { + unit->self->order = Orders::ZergUnitMorph; + + player->self->minerals -= morphType.mineralPrice(); + player->self->gas -= morphType.gasPrice(); + + switch(morphType) + { + case UnitTypes::Zerg_Lurker_Egg: + unit->self->type = UnitTypes::Zerg_Lurker_Egg; + break; + + case UnitTypes::Zerg_Devourer: + case UnitTypes::Zerg_Guardian: + unit->self->type = UnitTypes::Zerg_Cocoon; + break; + + default: + unit->self->type = UnitTypes::Zerg_Egg; + break; + } + + unit->self->trainingQueue[unit->self->trainingQueueCount++] = morphType; + } + } + break; + case EventType::Order: + if (unit->getType().isBuilding()) + { + unit->self->order = Orders::IncompleteBuilding; + } + break; + } + } + + break; + + // RLF + case UnitCommandTypes::Move: + unit->self->order = Orders::Move; + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + unit->self->isMoving = true; + unit->self->isIdle = false; + break; + + // RLF + case UnitCommandTypes::Patrol: + unit->self->order = Orders::Patrol; + unit->self->isIdle = false; + unit->self->isMoving = true; + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + break; + + // RLF + case UnitCommandTypes::Repair: + if (unit->getType() != UnitTypes::Terran_SCV) + { + return; + } + unit->self->order = Orders::Repair; + unit->self->target = getUnitID(target); + unit->self->isIdle = false; + break; + + // RLF + case UnitCommandTypes::Research: + { + TechType techType{ command.extra }; + unit->self->order = Orders::ResearchTech; + unit->self->tech = techType; + unit->self->isIdle = false; + unit->self->remainingResearchTime = techType.researchTime(); + + player->self->minerals -= techType.mineralPrice(); + player->self->gas -= techType.gasPrice(); + player->self->isResearching[techType] = true; + } + break; + + // RLF + case UnitCommandTypes::Return_Cargo: + if (!unit->self->carryResourceType) + return; + + unit->self->order = (unit->isCarryingGas() ? Orders::ReturnGas : Orders::ReturnMinerals); + unit->self->isGathering = true; + unit->self->isIdle = false; + + break; + + // RLF + case UnitCommandTypes::Right_Click_Position: + unit->self->order = Orders::Move; + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + unit->self->isMoving = true; + unit->self->isIdle = false; + break; + + // RLF + case UnitCommandTypes::Right_Click_Unit: + unit->self->target = getUnitID(target); + unit->self->isIdle = false; + unit->self->isMoving = true; + + if (unit->getType().isWorker() && target->getType().isMineralField()) + { + unit->self->isGathering = true; + unit->self->order = Orders::MoveToMinerals; + } + else if (unit->getType().isWorker() && target->getType().isRefinery()) + { + unit->self->isGathering = true; + unit->self->order = Orders::MoveToGas; + } + else if (unit->getType().isWorker() && + target->getType().getRace() == Races::Terran && + target->getType().whatBuilds().first == unit->getType() && + !target->isCompleted()) + { + unit->self->order = Orders::ConstructingBuilding; + unit->self->buildUnit = getUnitID(target); + target->self->buildUnit = getUnitID(unit); + unit->self->isConstructing = true; + target->self->isConstructing = true; + } + else if (unit->getType().canAttack() && target->getPlayer() != unit->getPlayer() && !target->getType().isNeutral()) + { + unit->self->order = Orders::AttackUnit; + } + else if(unit->getType().canMove()) + { + unit->self->order = Orders::Follow; + } + + break; + + // RLF + case UnitCommandTypes::Set_Rally_Position: + if (!unit->getType().canProduce()) + return; + + unit->self->order = Orders::RallyPointTile; + unit->self->rallyPositionX = command.x; + unit->self->rallyPositionY = command.y; + unit->self->rallyUnit = -1; + + break; + + // RLF + case UnitCommandTypes::Set_Rally_Unit: + if (!unit->getType().canProduce()) + return; + if (!target || !target->self->exists) + return; + + unit->self->order = Orders::RallyPointUnit; + unit->self->rallyUnit = getUnitID(target); + + break; + + // RLF + case UnitCommandTypes::Siege: + unit->self->order = Orders::Sieging; + break; + + // RLF + case UnitCommandTypes::Stop: + unit->self->order = Orders::Stop; + unit->self->isIdle = true; + break; + + // With train, the game does not take the supply until RLF + 1. + // We just pretend that it happens on RLF. + case UnitCommandTypes::Train: + { + UnitType unitType = command.extra; + + if (!isCurrentFrame) + { + // Happens on RLF, we don't want to duplicate this. + player->self->minerals -= unitType.mineralPrice(); + player->self->gas -= unitType.gasPrice(); + } + + // Happens on RLF + 1, we want to pretend this happens on RLF. + unit->self->trainingQueue[unit->self->trainingQueueCount++] = unitType; + player->self->supplyUsed[unitType.getRace()] += unitType.supplyRequired(); + + // Happens on RLF or RLF + 1, doesn't matter if we do twice + unit->self->isTraining = true; + unit->self->isIdle = false; + unit->self->remainingTrainTime = unitType.buildTime(); + + if (unitType == UnitTypes::Terran_Nuclear_Missile) + { + unit->self->secondaryOrder = Orders::Train; + } + } + + break; + + // RLF + case UnitCommandTypes::Unburrow: + unit->self->order = Orders::Unburrowing; + break; + + // RLF + case UnitCommandTypes::Unload: + unit->self->order = Orders::Unload; + unit->self->target = getUnitID(target); + break; + + // RLF + case UnitCommandTypes::Unload_All: + if (unit->getType() == UnitTypes::Terran_Bunker) + { + unit->self->order = Orders::Unload; + } + else + { + unit->self->order = Orders::MoveUnload; + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + } + + break; + + // RLF + case UnitCommandTypes::Unload_All_Position: + unit->self->order = Orders::MoveUnload; + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + break; + + // RLF + case UnitCommandTypes::Unsiege: + unit->self->order = Orders::Unsieging; + break; + + // RLF + case UnitCommandTypes::Upgrade: + { + UpgradeType upgradeType { command.extra }; + + unit->self->order = Orders::Upgrade; + unit->self->upgrade = upgradeType; + unit->self->isIdle = false; + + const int level = unit->getPlayer()->getUpgradeLevel(upgradeType); + unit->self->remainingUpgradeTime = upgradeType.upgradeTime(level + 1); + + player->self->minerals -= upgradeType.mineralPrice(level + 1); + player->self->gas -= upgradeType.gasPrice(level + 1); + + player->self->isUpgrading[upgradeType] = true; + } + break; + + // RLF + case UnitCommandTypes::Use_Tech: + if (static_cast(command.extra) == TechTypes::Stim_Packs + && unit->self->hitPoints > 10) + { + unit->self->hitPoints -= 10; + unit->self->stimTimer = 17; + } + break; + + // RLF + case UnitCommandTypes::Use_Tech_Position: + { + TechType techType{ command.extra }; + + if (!techType.targetsPosition()) + return; + + unit->self->order = techType.getOrder(); + unit->self->targetPositionX = command.x; + unit->self->targetPositionY = command.y; + unit->self->orderTargetPositionX = command.x; + unit->self->orderTargetPositionY = command.y; + } + + break; + + // RLF + case UnitCommandTypes::Use_Tech_Unit: + { + TechType techType{ command.extra }; + + if (!techType.targetsUnit()) + return; + + unit->self->order = techType.getOrder(); + unit->self->orderTarget = getUnitID(target); + + Position const targetPosition = target->getPosition(); + + unit->self->targetPositionX = targetPosition.x; + unit->self->targetPositionY = targetPosition.y; + unit->self->orderTargetPositionX = targetPosition.x; + unit->self->orderTargetPositionY = targetPosition.y; + + break; + } + } + } +}; diff --git a/bwapi/include/BWAPI/Color.h b/bwapi/include/BWAPI/Color.h index cbd249d6a..4e4e4ac4c 100755 --- a/bwapi/include/BWAPI/Color.h +++ b/bwapi/include/BWAPI/Color.h @@ -71,7 +71,7 @@ namespace BWAPI constexpr Color Purple{ 164 }; /// The default color for Player 5. - constexpr Color Orange{ 179 }; + constexpr Color Orange{ 156 }; /// The default color for Player 6. constexpr Color Brown{ 19 }; diff --git a/bwapi/include/BWAPI/Player.h b/bwapi/include/BWAPI/Player.h old mode 100644 new mode 100755 index 94dfbdec3..912a12613 --- a/bwapi/include/BWAPI/Player.h +++ b/bwapi/include/BWAPI/Player.h @@ -521,14 +521,14 @@ namespace BWAPI /// @returns Sight range of the provided unit type for this player. int sightRange(UnitType unit) const; - /// Retrieves the weapon cooldown of a unit type, taking the player's attack speed - /// upgrades into consideration. + /// Retrieves the ground weapon cooldown of a unit type, taking the player's attack + /// speed upgrades into consideration. /// /// - /// The UnitType to retrieve the damage cooldown for. + /// The UnitType to retrieve the ground damage cooldown for. /// /// - /// @returns Weapon cooldown of the provided unit type for this player. + /// @returns Ground weapon cooldown of the provided unit type for this player. int weaponDamageCooldown(UnitType unit) const; /// Calculates the armor that a given unit type will have, including upgrades. diff --git a/bwapi/include/BWAPI/Position.h b/bwapi/include/BWAPI/Position.h index f5f5366bc..ec720a1c6 100755 --- a/bwapi/include/BWAPI/Position.h +++ b/bwapi/include/BWAPI/Position.h @@ -90,8 +90,8 @@ namespace BWAPI explicit operator bool() const { return this->isValid(); }; bool operator == (const Point &pos) const - { - return std::tie(this->x, this->y) == std::tie(pos.x, pos.y); + { + return this->x == pos.x && this->y == pos.y; }; bool operator != (const Point &pos) const { @@ -102,7 +102,9 @@ namespace BWAPI /// Compares lexicographically the x position, followed by the y position. bool operator < (const Point &position) const { - return std::tie(this->x, this->y) < std::tie(position.x, position.y); + if(this->x == position.x) + return this->y < position.y; + return this->x < position.x; }; inline Point &operator += (const Point &p) @@ -305,12 +307,12 @@ namespace BWAPI /// @see getDistance int getApproxDistance(const Point &position) const { - unsigned int min = abs((int)(this->x - position.x)); - unsigned int max = abs((int)(this->y - position.y)); + unsigned int max = abs((int)(this->x - position.x)); + unsigned int min = abs((int)(this->y - position.y)); if ( max < min ) std::swap(min, max); - if ( min < (max >> 2) ) + if ( min <= (max >> 2) ) return max; unsigned int minCalc = (3*min) >> 3; diff --git a/bwapi/include/BWAPI/Unit.h b/bwapi/include/BWAPI/Unit.h old mode 100644 new mode 100755 index 4efb57f1d..0d2a18636 --- a/bwapi/include/BWAPI/Unit.h +++ b/bwapi/include/BWAPI/Unit.h @@ -161,8 +161,7 @@ namespace BWAPI /// /// Example /// @code - /// Unitset myUnits = Broodwar->self()->getUnits(); - /// for ( auto u = myUnits.begin(); u != myUnits.end(); ++u ) + /// for ( auto u : Broodwar->self()->getUnits() ) /// { /// if ( u->isFlying() && u->isUnderAttack() ) // implies exists and isCompleted /// { diff --git a/bwapi/include/BWAPI/UnitType.h b/bwapi/include/BWAPI/UnitType.h index 2c90c1246..5cdf727f4 100755 --- a/bwapi/include/BWAPI/UnitType.h +++ b/bwapi/include/BWAPI/UnitType.h @@ -534,25 +534,23 @@ namespace BWAPI /// Retrieves the unit's acceleration amount. /// - /// @returns How fast the unit can accelerate to its top speed. - /// - /// @todo Figure out the units this quantity is measured in. + /// @returns If the value is 1: The unit has fixed or patterned velocity (for example, a + /// hopping Zergling). Otherwise, returns the unit's acceleration measured in N/256 pixels + /// per frame per frame. So a unit with 64 acceleration would take 4 frames to reach 1 + /// pixel per frame. int acceleration() const; - /// Retrieves the unit's halting distance. This determines how fast a unit - /// can stop moving. - /// - /// @returns A halting distance value. + /// Retrieves the unit's halting distance. This is the distance from + /// the unit's destination at which point the unit starts decelerating. /// - /// @todo Figure out the units this quantity is measured in. + /// @returns The unit's halting distance, in 1/256ths of a pixel. int haltDistance() const; - /// Retrieves a unit's turning radius. This determines how fast a unit can - /// turn. - /// - /// @returns A turn radius value. - /// - /// @todo Figure out the units this quantity is measured in. + /// Retrieves a unit's turning rate. This determines how far a unit can + /// rotate in one frame. + /// + /// @returns The units are N/256ths of a circle per frame. So a unit with a turnRadius of 64 + /// can turn a full circle in 4 frames. int turnRadius() const; /// Determines if a unit can train other units. For example, diff --git a/bwapi/include/BWAPI/WeaponType.h b/bwapi/include/BWAPI/WeaponType.h index c81e60a60..1202ad6a4 100755 --- a/bwapi/include/BWAPI/WeaponType.h +++ b/bwapi/include/BWAPI/WeaponType.h @@ -226,25 +226,22 @@ namespace BWAPI /// @returns Maximum attack range, in pixels. int maxRange() const; - /// Retrieves the inner radius used for splash damage calculations, in pixels. + /// Retrieves the inner radius used for splash damage calculations, in pixels. + /// Units in this area take 100% damage. /// /// @returns Radius of the inner splash area, in pixels. - /// - /// @todo Add damage calculation. int innerSplashRadius() const; - /// Retrieves the middle radius used for splash damage calculations, in pixels. + /// Retrieves the middle radius used for splash damage calculations, in pixels. + /// Units in this area take 50% damage. /// /// @returns Radius of the middle splash area, in pixels. - /// - /// @todo Add damage calculation. int medianSplashRadius() const; /// Retrieves the outer radius used for splash damage calculations, in pixels. + /// Units in this area take 25% damage. /// /// @returns Radius of the outer splash area, in pixels. - /// - /// @todo Add damage calculation. int outerSplashRadius() const; /// Checks if this weapon type can target air units. diff --git a/bwapi/Debug.h b/bwapi/include/Debug.h similarity index 88% rename from bwapi/Debug.h rename to bwapi/include/Debug.h index 2168d656e..8053bb4a0 100755 --- a/bwapi/Debug.h +++ b/bwapi/include/Debug.h @@ -1,3 +1,4 @@ +#pragma once #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC #include diff --git a/bwapi/starcraftver.h b/bwapi/include/starcraftver.h similarity index 90% rename from bwapi/starcraftver.h rename to bwapi/include/starcraftver.h index 66494ac52..3879a0be7 100755 --- a/bwapi/starcraftver.h +++ b/bwapi/include/starcraftver.h @@ -16,6 +16,6 @@ #define BUILD_DEBUG 0 #endif -#define BWAPI_VER "4.2.0" +#define BWAPI_VER "4.4.0" #define BWAPI_HOME_URL "http://bwapi.github.io/" #endif diff --git a/bwapi/lib/.gitignore b/bwapi/lib/.gitignore deleted file mode 100755 index f59ec20aa..000000000 --- a/bwapi/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* \ No newline at end of file