├── .gitignore ├── Include ├── BWAPI.h └── BWAPI │ ├── AIModule.h │ ├── ArithmaticFilter.h │ ├── BestFilter.h │ ├── Bullet.h │ ├── BulletType.h │ ├── Bulletset.h │ ├── Client.h │ ├── Client │ ├── BulletData.h │ ├── BulletImpl.h │ ├── Client.h │ ├── Command.h │ ├── CommandType.h │ ├── Event.h │ ├── ForceData.h │ ├── ForceImpl.h │ ├── GameData.h │ ├── GameImpl.h │ ├── GameTable.h │ ├── PlayerData.h │ ├── PlayerImpl.h │ ├── RegionData.h │ ├── RegionImpl.h │ ├── Shape.h │ ├── ShapeType.h │ ├── UnitCommand.h │ ├── UnitData.h │ └── UnitImpl.h │ ├── Color.h │ ├── ComparisonFilter.h │ ├── Constants.h │ ├── CoordinateType.h │ ├── DamageType.h │ ├── Error.h │ ├── Event.h │ ├── EventType.h │ ├── ExplosionType.h │ ├── Filters.h │ ├── Flag.h │ ├── Force.h │ ├── Forceset.h │ ├── Game.h │ ├── GameType.h │ ├── Input.h │ ├── Interface.h │ ├── InterfaceEvent.h │ ├── Latency.h │ ├── Order.h │ ├── Player.h │ ├── PlayerType.h │ ├── Playerset.h │ ├── Position.h │ ├── PositionUnit.h │ ├── Race.h │ ├── Region.h │ ├── Regionset.h │ ├── SetContainer.h │ ├── TechType.h │ ├── TournamentAction.h │ ├── Type.h │ ├── UnaryFilter.h │ ├── Unit.h │ ├── UnitCommand.h │ ├── UnitCommandType.h │ ├── UnitSizeType.h │ ├── UnitType.h │ ├── Unitset.h │ ├── UpgradeType.h │ ├── WeaponType.h │ └── WindowsTypes.h ├── Lib ├── Debug │ ├── BWAPIClientd.lib │ ├── BWAPIClientd.pdb │ ├── BWAPILibd.pdb │ ├── BWAPId.lib │ └── bwapid.pdb └── Release │ ├── BWAPI.lib │ ├── BWAPIClient.lib │ ├── BWAPIClient.pdb │ ├── BWAPILib.pdb │ └── VersionIs4.1.2.txt ├── README.md └── Src ├── BWAPI-CLI.sln ├── Broodwar ├── AiBase.cpp ├── AiBase.h ├── AssemblyInfo.cpp ├── BWAPI │ ├── Bullet.cpp │ ├── Bullet.h │ ├── Client │ │ ├── Client.cpp │ │ ├── Client.h │ │ ├── Command.cpp │ │ ├── Command.h │ │ ├── CommandType.h │ │ ├── UnitCommand.cpp │ │ └── UnitCommand.h │ ├── Enum │ │ ├── BulletType.h │ │ ├── CoordinateType.h │ │ ├── DamageType.h │ │ ├── ErrorType.h │ │ ├── EventType.h │ │ ├── ExplosionType.h │ │ ├── Flag.h │ │ ├── GameType.h │ │ ├── Key.h │ │ ├── Latency.h │ │ ├── MouseButton.h │ │ ├── OrderType.h │ │ ├── PlayerType.h │ │ ├── RaceType.h │ │ ├── Targets.h │ │ ├── TechType.h │ │ ├── TournamentAction.h │ │ ├── UnitCommandType.h │ │ ├── UnitSizeType.h │ │ ├── UnitType.h │ │ ├── UpgradeType.h │ │ └── WeaponType.h │ ├── Event.cpp │ ├── Event.h │ ├── Force.cpp │ ├── Force.h │ ├── Game.cpp │ ├── Game.h │ ├── IIdentifiedObject.h │ ├── Player.cpp │ ├── Player.h │ ├── Position.cpp │ ├── Position.h │ ├── Price.cpp │ ├── Price.h │ ├── Race.cpp │ ├── Race.h │ ├── Region.cpp │ ├── Region.h │ ├── Tech.cpp │ ├── Tech.h │ ├── TilePosition.cpp │ ├── TilePosition.h │ ├── Unit.cpp │ ├── Unit.h │ ├── UnitCommand.cpp │ ├── UnitCommand.h │ ├── UnitType.cpp │ ├── UnitType.h │ ├── Upgrade.cpp │ ├── Upgrade.h │ ├── WalkPosition.cpp │ ├── WalkPosition.h │ ├── Weapon.cpp │ └── Weapon.h ├── Broodwar.vcxproj ├── Broodwar.vcxproj.filters ├── EnumClassMap.h ├── EnumMapping.cpp ├── EnumMapping.h ├── TournamentBase.cpp ├── TournamentBase.h ├── Util.cpp └── Util.h ├── BroodwarFSharp ├── BroodwarFSharp.fsproj ├── Game.fs ├── Position.fs ├── Unit.fs └── UnitType.fs ├── BroodwarLoader ├── AIManaged.cpp ├── AIManaged.h ├── AIModule.cpp ├── AIModule.h ├── AssemblyInfo.cpp ├── BroodwarLoader.vcxproj ├── BroodwarLoader.vcxproj.filters ├── Dll.cpp └── app.config ├── BroodwarTournamentLoader ├── AIManaged.cpp ├── AIManaged.h ├── AIModule.cpp ├── AIModule.h ├── AssemblyInfo.cpp ├── BroodwarTournamentLoader.vcxproj ├── BroodwarTournamentLoader.vcxproj.filters ├── Dll.cpp ├── TournamentManaged.cpp ├── TournamentManaged.h ├── TournamentModule.cpp ├── TournamentModule.h └── app.config ├── Examples ├── ExampleAIModule │ ├── ExampleAIModule.csproj │ ├── ExampleAiModule.cs │ ├── Helper.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── ExampleAIModuleFSharp │ ├── Example.fs │ └── ExampleAIModuleFSharp.fsproj ├── ExampleAiClient │ ├── ExampleAiClient.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── app.config └── ExampleTournamentModule │ ├── AiModule.cs │ ├── CoolEvent.cs │ ├── Events.cs │ ├── ExampleTournamentModule.csproj │ ├── Properties │ └── AssemblyInfo.cs │ └── TournamentModule.cs └── bwapicli.snk /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # Martin's generated code 6 | *.gen.* 7 | *.txt4 8 | 9 | # Config logs 10 | *.log*.csv* 11 | 12 | # mstest test results 13 | TestResults 14 | 15 | ## Ignore Visual Studio temporary files, build results, and 16 | ## files generated by popular Visual Studio add-ons. 17 | 18 | # User-specific files 19 | *.suo 20 | *.user 21 | *.sln.docstates 22 | 23 | # Build results 24 | [Dd]ebug/ 25 | [Rr]elease/ 26 | x64/ 27 | *_i.c 28 | *_p.c 29 | *.ilk 30 | *.meta 31 | *.obj 32 | *.pch 33 | *.pdb 34 | *.pgc 35 | *.pgd 36 | *.rsp 37 | *.sbr 38 | *.tlb 39 | *.tli 40 | *.tlh 41 | *.tmp 42 | *.log 43 | *.vspscc 44 | *.vssscc 45 | .builds 46 | 47 | # Visual C++ cache files 48 | ipch/ 49 | *.aps 50 | *.ncb 51 | *.opensdf 52 | *.sdf 53 | 54 | # Visual Studio profiler 55 | *.psess 56 | *.vsp 57 | *.vspx 58 | 59 | # Guidance Automation Toolkit 60 | *.gpState 61 | 62 | # ReSharper is a .NET coding add-in 63 | _ReSharper* 64 | 65 | # NCrunch 66 | *.ncrunch* 67 | .*crunch*.local.xml 68 | 69 | # Installshield output folder 70 | [Ee]xpress 71 | 72 | # DocProject is a documentation generator add-in 73 | DocProject/buildhelp/ 74 | DocProject/Help/*.HxT 75 | DocProject/Help/*.HxC 76 | DocProject/Help/*.hhc 77 | DocProject/Help/*.hhk 78 | DocProject/Help/*.hhp 79 | DocProject/Help/Html2 80 | DocProject/Help/html 81 | 82 | # Click-Once directory 83 | publish 84 | 85 | # Publish Web Output 86 | *.Publish.xml 87 | 88 | # NuGet Packages Directory 89 | packages 90 | 91 | # Windows Azure Build Output 92 | csx 93 | *.build.csdef 94 | 95 | # Windows Store app package directory 96 | AppPackages/ 97 | 98 | # Others 99 | [Bb]in 100 | [Oo]bj 101 | sql 102 | TestResults 103 | [Tt]est[Rr]esult* 104 | *.Cache 105 | ClientBin 106 | [Ss]tyle[Cc]op.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | -------------------------------------------------------------------------------- /Include/BWAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef __BWAPI_H__ 3 | #define __BWAPI_H__ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | /// The primary namespace for the BWAPI interface. Everything that is BWAPI is 50 | /// contained within it. 51 | namespace BWAPI 52 | { 53 | /// Retrieves the revision of the BWAPILIB module currently being used. 54 | /// 55 | /// @returns 56 | /// An integer representing the revision number of the library. 57 | /// 58 | /// @threadsafe 59 | int BWAPI_getRevision(); 60 | 61 | /// Checks if the BWAPILIB module was compiled in DEBUG mode. 62 | /// 63 | /// @retval true if this is a DEBUG build 64 | /// @retval false if this is a RELEASE build 65 | /// 66 | /// @threadsafe 67 | bool BWAPI_isDebug(); 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /Include/BWAPI/ArithmaticFilter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Include/BWAPI/ArithmaticFilter.h -------------------------------------------------------------------------------- /Include/BWAPI/BestFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "ComparisonFilter.h" 4 | 5 | namespace BWAPI 6 | { 7 | /// The BestFilter is used to compare two objects with each other. Each 8 | /// function object compares two of the same object and returns the most desirable one. 9 | /// 10 | /// @note: A function object should return one of the two given parameters, never nullptr. Both 11 | /// parameters being given should never be nullptr. 12 | template 13 | class BestFilter 14 | { 15 | private: 16 | std::function<_PARAM(_PARAM,_PARAM)> pred; 17 | public: 18 | // Constructor 19 | template 20 | BestFilter(const _T &predicate) : pred(predicate) 21 | {}; 22 | 23 | // Assignment 24 | template 25 | BestFilter<_PARAM> &operator =(const _T &other) 26 | { 27 | this->pred = other; 28 | return *this; 29 | }; 30 | 31 | // Bitwise operators 32 | template 33 | inline BestFilter<_PARAM> operator &&(const _T &other) const 34 | { 35 | return [=](_PARAM p1, _PARAM p2)->_PARAM{ return other( (*this)(p1, p2) ); }; 36 | }; 37 | 38 | // call 39 | inline _PARAM operator()(const _PARAM &p1, const _PARAM &p2) const 40 | { 41 | return this->pred(p1, p2); 42 | }; 43 | 44 | }; 45 | 46 | template 47 | BestFilter<_PARAM> Lowest(const CompareFilter<_PARAM,int> &filter) 48 | { 49 | return [=](_PARAM p1, _PARAM p2)->_PARAM{ return filter(p2) < filter(p1) ? p2 : p1; }; 50 | }; 51 | template 52 | BestFilter<_PARAM> Highest(const CompareFilter<_PARAM,int> &filter) 53 | { 54 | return [=](_PARAM p1, _PARAM p2)->_PARAM{ return filter(p2) > filter(p1) ? p2 : p1; }; 55 | }; 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Include/BWAPI/Bulletset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SetContainer.h" 3 | 4 | namespace BWAPI 5 | { 6 | // Forward Declarations 7 | class BulletInterface; 8 | typedef BulletInterface *Bullet; 9 | 10 | /// A container for a set of Bullet objects. 11 | class Bulletset : public SetContainer> 12 | { 13 | public: 14 | }; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Include/BWAPI/Client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/BulletData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BWAPI 4 | { 5 | struct BulletData 6 | { 7 | int id; 8 | int player; 9 | int type; 10 | int source; 11 | int positionX; 12 | int positionY; 13 | double angle; 14 | double velocityX; 15 | double velocityY; 16 | int target; 17 | int targetPositionX; 18 | int targetPositionY; 19 | int removeTimer; 20 | bool exists; 21 | bool isVisible[9]; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/BulletImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "BulletData.h" 4 | #include 5 | 6 | namespace BWAPI 7 | { 8 | class PlayerInterface; 9 | typedef PlayerInterface *Player; 10 | 11 | class BulletImpl : public BulletInterface 12 | { 13 | private: 14 | const BulletData* self; 15 | int index; 16 | public: 17 | 18 | BulletImpl(int index); 19 | virtual int getID() const override; 20 | virtual bool exists() const override; 21 | virtual Player getPlayer() const override; 22 | virtual BulletType getType() const override; 23 | virtual Unit getSource() const override; 24 | virtual Position getPosition() const override; 25 | virtual double getAngle() const override; 26 | virtual double getVelocityX() const override; 27 | virtual double getVelocityY() const override; 28 | virtual Unit getTarget() const override; 29 | virtual Position getTargetPosition() const override; 30 | virtual int getRemoveTimer() const override; 31 | virtual bool isVisible(Player player = nullptr) const override; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/Client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GameData.h" 3 | #include "GameImpl.h" 4 | #include "ForceImpl.h" 5 | #include "PlayerImpl.h" 6 | #include "UnitImpl.h" 7 | #include "GameTable.h" 8 | 9 | #include "../WindowsTypes.h" 10 | 11 | 12 | namespace BWAPI 13 | { 14 | class Client 15 | { 16 | public: 17 | Client(); 18 | ~Client(); 19 | 20 | bool isConnected() const; 21 | bool connect(); 22 | void disconnect(); 23 | void update(); 24 | 25 | GameData* data = nullptr; 26 | private: 27 | HANDLE pipeObjectHandle; 28 | HANDLE mapFileHandle; 29 | HANDLE gameTableFileHandle; 30 | GameTable* gameTable = nullptr; 31 | 32 | bool connected = false; 33 | }; 34 | extern Client BWAPIClient; 35 | } 36 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/Command.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CommandType.h" 3 | 4 | namespace BWAPIC 5 | { 6 | struct Command 7 | { 8 | Command() 9 | : type( CommandType::None ) 10 | , value1( 0 ) 11 | , value2( 0 ) 12 | { } 13 | Command(CommandType::Enum _commandType, int _value1=0, int _value2=0) 14 | : type( _commandType ) 15 | , value1( _value1 ) 16 | , value2( _value2 ) 17 | { } 18 | 19 | CommandType::Enum type; 20 | int value1; 21 | int value2; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/CommandType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /** 3 | * Used in UnitCommand 4 | */ 5 | 6 | namespace BWAPIC 7 | { 8 | namespace CommandType 9 | { 10 | enum Enum 11 | { 12 | None, 13 | SetScreenPosition, 14 | PingMinimap, 15 | EnableFlag, 16 | Printf, 17 | SendText, 18 | PauseGame, 19 | ResumeGame, 20 | LeaveGame, 21 | RestartGame, 22 | SetLocalSpeed, 23 | SetLatCom, 24 | SetGui, 25 | SetFrameSkip, 26 | SetMap, 27 | SetAllies, 28 | SetVision, 29 | SetCommandOptimizerLevel, 30 | SetRevealAll 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /Include/BWAPI/Client/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace BWAPIC 7 | { 8 | struct Event 9 | { 10 | BWAPI::EventType::Enum type; 11 | int v1; 12 | int v2; 13 | }; 14 | } -------------------------------------------------------------------------------- /Include/BWAPI/Client/ForceData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BWAPI 4 | { 5 | struct ForceData 6 | { 7 | char name[32]; 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/ForceImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "ForceData.h" 4 | #include 5 | 6 | namespace BWAPI 7 | { 8 | class ForceImpl : public ForceInterface 9 | { 10 | private: 11 | const ForceData* self; 12 | int id; 13 | public: 14 | ForceImpl(int id); 15 | virtual int getID() const override; 16 | virtual std::string getName() const override; 17 | virtual Playerset getPlayers() const override; 18 | }; 19 | } -------------------------------------------------------------------------------- /Include/BWAPI/Client/GameData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "UnitCommand.h" 4 | #include "ForceData.h" 5 | #include "PlayerData.h" 6 | #include "RegionData.h" 7 | #include "UnitData.h" 8 | #include "BulletData.h" 9 | #include "Event.h" 10 | #include "Command.h" 11 | #include "Shape.h" 12 | namespace BWAPIC 13 | { 14 | struct Position 15 | { 16 | Position() {x=0;y=0;} 17 | int x; 18 | int y; 19 | }; 20 | } 21 | namespace BWAPI 22 | { 23 | struct unitFinder 24 | { 25 | int unitIndex; 26 | int searchValue; 27 | }; 28 | struct GameData 29 | { 30 | //revision and debug will stay at the top of struct so they don't move in memory from revision to revision. 31 | int revision; 32 | bool isDebug; 33 | 34 | int instanceID; 35 | int botAPM_noselects; 36 | int botAPM_selects; 37 | 38 | //forces 39 | int forceCount; 40 | ForceData forces[5]; 41 | 42 | //players 43 | int playerCount; 44 | PlayerData players[12]; 45 | 46 | //units 47 | int initialUnitCount; 48 | UnitData units[10000]; 49 | 50 | //unit table 51 | int unitArray[1700]; 52 | 53 | //bullets 54 | BulletData bullets[100]; 55 | 56 | // nuke dots 57 | int nukeDotCount; 58 | BWAPIC::Position nukeDots[200]; 59 | 60 | int gameType; 61 | int latency; 62 | int latencyFrames; 63 | int latencyTime; 64 | int remainingLatencyFrames; 65 | int remainingLatencyTime; 66 | bool hasLatCom; 67 | bool hasGUI; 68 | int replayFrameCount; 69 | int frameCount; 70 | int elapsedTime; 71 | int countdownTimer; 72 | int fps; 73 | double averageFPS; 74 | 75 | // user input 76 | int mouseX; 77 | int mouseY; 78 | bool mouseState[M_MAX]; 79 | bool keyState[K_MAX]; 80 | int screenX; 81 | int screenY; 82 | 83 | bool flags[BWAPI::Flag::Max]; 84 | 85 | // map 86 | int mapWidth; 87 | int mapHeight; 88 | char mapFileName[261]; //size based on broodwar memory 89 | char mapPathName[261]; //size based on broodwar memory 90 | char mapName[33]; //size based on broodwar memory 91 | char mapHash[41]; 92 | 93 | //tile data 94 | int getGroundHeight[256][256]; 95 | bool isWalkable[1024][1024]; 96 | bool isBuildable[256][256]; 97 | bool isVisible[256][256]; 98 | bool isExplored[256][256]; 99 | bool hasCreep[256][256]; 100 | bool isOccupied[256][256]; 101 | 102 | unsigned short mapTileRegionId[256][256]; 103 | unsigned short mapSplitTilesMiniTileMask[5000]; 104 | unsigned short mapSplitTilesRegion1[5000]; 105 | unsigned short mapSplitTilesRegion2[5000]; 106 | 107 | int regionCount; 108 | RegionData regions[5000]; 109 | 110 | // start locations 111 | int startLocationCount; 112 | BWAPIC::Position startLocations[8]; 113 | 114 | // match mode 115 | bool isInGame; 116 | bool isMultiplayer; 117 | bool isBattleNet; 118 | bool isPaused; 119 | bool isReplay; 120 | 121 | //selected units 122 | int selectedUnitCount; 123 | int selectedUnits[12]; 124 | 125 | // players 126 | int self; 127 | int enemy; 128 | int neutral; 129 | 130 | static const int MAX_EVENTS = 10000; 131 | static const int MAX_EVENT_STRINGS = 1000; 132 | static const int MAX_STRINGS = 20000; 133 | static const int MAX_SHAPES = 20000; 134 | static const int MAX_COMMANDS = 20000; 135 | static const int MAX_UNIT_COMMANDS = 20000; 136 | 137 | //events from server to client 138 | int eventCount; 139 | BWAPIC::Event events[MAX_EVENTS]; 140 | 141 | //strings used in events 142 | int eventStringCount; 143 | char eventStrings[MAX_EVENT_STRINGS][256]; 144 | 145 | //strings (used in shapes and commands) 146 | int stringCount; 147 | char strings[MAX_STRINGS][1024]; 148 | 149 | //shapes, commands, unitCommands, from client to server 150 | int shapeCount; 151 | BWAPIC::Shape shapes[MAX_SHAPES]; 152 | 153 | int commandCount; 154 | BWAPIC::Command commands[MAX_COMMANDS]; 155 | 156 | int unitCommandCount; 157 | BWAPIC::UnitCommand unitCommands[MAX_UNIT_COMMANDS]; 158 | 159 | int unitSearchSize; 160 | unitFinder xUnitSearch[1700*2]; 161 | unitFinder yUnitSearch[1700*2]; 162 | }; 163 | } 164 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/GameTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BWAPI 4 | { 5 | struct GameInstance 6 | { 7 | GameInstance() 8 | : serverProcessID(0) 9 | , isConnected(false) 10 | , lastKeepAliveTime(0) 11 | {}; 12 | GameInstance(unsigned int servID, bool connected, unsigned int lastAliveTime) 13 | : serverProcessID(servID) 14 | , isConnected(connected) 15 | , lastKeepAliveTime(lastAliveTime) 16 | {}; 17 | 18 | unsigned int serverProcessID; 19 | bool isConnected; 20 | //time_t lastKeepAliveTime; 21 | unsigned int lastKeepAliveTime; 22 | }; 23 | struct GameTable 24 | { 25 | GameTable() 26 | {} 27 | static const int MAX_GAME_INSTANCES = 8; 28 | GameInstance gameInstances[MAX_GAME_INSTANCES]; 29 | }; 30 | } -------------------------------------------------------------------------------- /Include/BWAPI/Client/PlayerData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace BWAPI 8 | { 9 | struct PlayerData 10 | { 11 | char name[25]; 12 | int race; 13 | int type; 14 | int force; 15 | bool isAlly[12]; 16 | bool isEnemy[12]; 17 | bool isNeutral; 18 | int startLocationX; 19 | int startLocationY; 20 | bool isVictorious; 21 | bool isDefeated; 22 | bool leftGame; 23 | bool isParticipating; 24 | 25 | int minerals; 26 | int gas; 27 | int gatheredMinerals; 28 | int gatheredGas; 29 | int repairedMinerals; 30 | int repairedGas; 31 | int refundedMinerals; 32 | int refundedGas; 33 | int supplyTotal[3]; 34 | int supplyUsed[3]; 35 | 36 | int allUnitCount[UnitTypes::Enum::MAX]; 37 | int visibleUnitCount[UnitTypes::Enum::MAX]; 38 | int completedUnitCount[UnitTypes::Enum::MAX]; 39 | int deadUnitCount[UnitTypes::Enum::MAX]; 40 | int killedUnitCount[UnitTypes::Enum::MAX]; 41 | 42 | int upgradeLevel[UpgradeTypes::Enum::MAX]; 43 | bool hasResearched[TechTypes::Enum::MAX]; 44 | bool isResearching[TechTypes::Enum::MAX]; 45 | bool isUpgrading[UpgradeTypes::Enum::MAX]; 46 | 47 | int color; 48 | 49 | int totalUnitScore; 50 | int totalKillScore; 51 | int totalBuildingScore; 52 | int totalRazingScore; 53 | int customScore; 54 | 55 | int maxUpgradeLevel[UpgradeTypes::Enum::MAX]; 56 | bool isResearchAvailable[TechTypes::Enum::MAX]; 57 | bool isUnitAvailable[UnitTypes::Enum::MAX]; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/PlayerImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "PlayerData.h" 4 | #include 5 | 6 | #include 7 | 8 | namespace BWAPI 9 | { 10 | class ForceInterface; 11 | typedef ForceInterface *Force; 12 | 13 | class PlayerImpl : public PlayerInterface 14 | { 15 | private: 16 | int id; 17 | public: 18 | PlayerData* self; 19 | Unitset units; 20 | void clear(); 21 | PlayerImpl(int id); 22 | virtual int getID() const override; 23 | virtual std::string getName() const override; 24 | virtual const Unitset &getUnits() const override; 25 | virtual Race getRace() const override; 26 | virtual PlayerType getType() const override; 27 | virtual Force getForce() const override; 28 | virtual bool isAlly(const Player player) const override; 29 | virtual bool isEnemy(const Player player) const override; 30 | virtual bool isNeutral() const override; 31 | virtual TilePosition getStartLocation() const override; 32 | virtual bool isVictorious() const override; 33 | virtual bool isDefeated() const override; 34 | virtual bool leftGame() const override; 35 | 36 | virtual int minerals() const override; 37 | virtual int gas() const override; 38 | virtual int gatheredMinerals() const override; 39 | virtual int gatheredGas() const override; 40 | virtual int repairedMinerals() const override; 41 | virtual int repairedGas() const override; 42 | virtual int refundedMinerals() const override; 43 | virtual int refundedGas() const override; 44 | virtual int spentMinerals() const override; 45 | virtual int spentGas() const override; 46 | 47 | virtual int supplyTotal(Race race = Races::None) const override; 48 | virtual int supplyUsed(Race race = Races::None) const override; 49 | 50 | virtual int allUnitCount(UnitType unit) const override; 51 | virtual int visibleUnitCount(UnitType unit) const override; 52 | virtual int completedUnitCount(UnitType unit) const override; 53 | virtual int deadUnitCount(UnitType unit) const override; 54 | virtual int killedUnitCount(UnitType unit) const override; 55 | 56 | virtual int getUpgradeLevel(UpgradeType upgrade) const override; 57 | virtual bool hasResearched(TechType tech) const override; 58 | virtual bool isResearching(TechType tech) const override; 59 | virtual bool isUpgrading(UpgradeType upgrade) const override; 60 | 61 | virtual BWAPI::Color getColor() const override; 62 | 63 | virtual int getUnitScore() const override; 64 | virtual int getKillScore() const override; 65 | virtual int getBuildingScore() const override; 66 | virtual int getRazingScore() const override; 67 | virtual int getCustomScore() const override; 68 | 69 | virtual bool isObserver() const override; 70 | 71 | virtual int getMaxUpgradeLevel(UpgradeType upgrade) const override; 72 | virtual bool isResearchAvailable(TechType tech) const override; 73 | virtual bool isUnitAvailable(UnitType unit) const override; 74 | }; 75 | }; 76 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/RegionData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BWAPI 4 | { 5 | struct RegionData 6 | { 7 | int id; 8 | int islandID; 9 | int center_x; 10 | int center_y; 11 | int priority; 12 | 13 | // region boundary 14 | int leftMost; 15 | int rightMost; 16 | int topMost; 17 | int bottomMost; 18 | 19 | int neighborCount; 20 | int neighbors[256]; 21 | 22 | bool isAccessible; 23 | bool isHigherGround; 24 | }; 25 | }; 26 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/RegionImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace BWAPI 9 | { 10 | class RegionImpl : public RegionInterface 11 | { 12 | private: 13 | RegionData* self; 14 | Regionset neighbors; 15 | BWAPI::Region closestAccessibleRgn = nullptr; 16 | BWAPI::Region closestInaccessibleRgn = nullptr; 17 | public: 18 | RegionImpl(int index); 19 | void setNeighbors(); 20 | virtual int getID() const override; 21 | virtual int getRegionGroupID() const override; 22 | virtual BWAPI::Position getCenter() const override; 23 | virtual bool isHigherGround() const override; 24 | virtual int getDefensePriority() const override; 25 | virtual bool isAccessible() const override; 26 | 27 | virtual const Regionset &getNeighbors() const override; 28 | 29 | virtual int getBoundsLeft() const override; 30 | virtual int getBoundsTop() const override; 31 | virtual int getBoundsRight() const override; 32 | virtual int getBoundsBottom() const override; 33 | 34 | virtual BWAPI::Region getClosestAccessibleRegion() const override; 35 | virtual BWAPI::Region getClosestInaccessibleRegion() const override; 36 | }; 37 | 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ShapeType.h" 3 | #include 4 | 5 | namespace BWAPIC 6 | { 7 | struct Shape 8 | { 9 | Shape() 10 | :type(ShapeType::None) 11 | ,ctype(BWAPI::CoordinateType::None) 12 | ,x1(0) 13 | ,y1(0) 14 | ,x2(0) 15 | ,y2(0) 16 | ,extra1(0) 17 | ,extra2(0) 18 | ,color(0) 19 | ,isSolid(false) 20 | { 21 | } 22 | 23 | Shape(ShapeType::Enum _shapeType, BWAPI::CoordinateType::Enum _ctype, int _x1, int _y1, int _x2, int _y2, int _extra1, int _extra2, int _color, bool _isSolid) 24 | :type(_shapeType) 25 | ,ctype(_ctype) 26 | ,x1(_x1) 27 | ,y1(_y1) 28 | ,x2(_x2) 29 | ,y2(_y2) 30 | ,extra1(_extra1) 31 | ,extra2(_extra2) 32 | ,color(_color) 33 | ,isSolid(_isSolid) 34 | { 35 | } 36 | 37 | ShapeType::Enum type; 38 | BWAPI::CoordinateType::Enum ctype; 39 | int x1; 40 | int y1; 41 | int x2; 42 | int y2; 43 | int extra1; 44 | int extra2; 45 | int color; 46 | bool isSolid; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /Include/BWAPI/Client/ShapeType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /** 3 | * Used in UnitCommand 4 | */ 5 | 6 | namespace BWAPIC 7 | { 8 | namespace ShapeType 9 | { 10 | enum Enum 11 | { 12 | None, 13 | Text, 14 | Box, 15 | Triangle, 16 | Circle, 17 | Ellipse, 18 | Dot, 19 | Line 20 | }; 21 | } 22 | } -------------------------------------------------------------------------------- /Include/BWAPI/Client/UnitCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /** 6 | * UnitOrder contains a single whole order 7 | */ 8 | 9 | namespace BWAPIC 10 | { 11 | struct UnitCommand 12 | { 13 | BWAPI::UnitCommandType type; 14 | int unitIndex; 15 | int targetIndex; 16 | int x; 17 | int y; 18 | int extra; 19 | }; 20 | } -------------------------------------------------------------------------------- /Include/BWAPI/Client/UnitData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BWAPI 4 | { 5 | struct UnitData 6 | { 7 | int clearanceLevel; 8 | int id; 9 | int player; 10 | int type; 11 | int positionX; 12 | int positionY; 13 | double angle; 14 | double velocityX; 15 | double velocityY; 16 | int hitPoints; 17 | int lastHitPoints; 18 | int shields; 19 | int energy; 20 | int resources; 21 | int resourceGroup; 22 | 23 | int killCount; 24 | int acidSporeCount; 25 | int scarabCount; 26 | int spiderMineCount; 27 | int groundWeaponCooldown; 28 | int airWeaponCooldown; 29 | int spellCooldown; 30 | int defenseMatrixPoints; 31 | 32 | int defenseMatrixTimer; 33 | int ensnareTimer; 34 | int irradiateTimer; 35 | int lockdownTimer; 36 | int maelstromTimer; 37 | int orderTimer; 38 | int plagueTimer; 39 | int removeTimer; 40 | int stasisTimer; 41 | int stimTimer; 42 | 43 | int buildType; 44 | int trainingQueueCount; 45 | int trainingQueue[5]; 46 | int tech; 47 | int upgrade; 48 | int remainingBuildTime; 49 | int remainingTrainTime; 50 | int remainingResearchTime; 51 | int remainingUpgradeTime; 52 | int buildUnit; 53 | 54 | int target; 55 | int targetPositionX; 56 | int targetPositionY; 57 | int order; 58 | int orderTarget; 59 | int orderTargetPositionX; 60 | int orderTargetPositionY; 61 | int secondaryOrder; 62 | int rallyPositionX; 63 | int rallyPositionY; 64 | int rallyUnit; 65 | int addon; 66 | int nydusExit; 67 | int powerUp; 68 | 69 | int transport; 70 | int carrier; 71 | int hatchery; 72 | 73 | bool exists; 74 | bool hasNuke; 75 | bool isAccelerating; 76 | bool isAttacking; 77 | bool isAttackFrame; 78 | bool isBeingGathered; 79 | bool isBlind; 80 | bool isBraking; 81 | bool isBurrowed; 82 | int carryResourceType; 83 | bool isCloaked; 84 | bool isCompleted; 85 | bool isConstructing; 86 | bool isDetected; 87 | bool isGathering; 88 | bool isHallucination; 89 | bool isIdle; 90 | bool isInterruptible; 91 | bool isInvincible; 92 | bool isLifted; 93 | bool isMorphing; 94 | bool isMoving; 95 | bool isParasited; 96 | bool isSelected; 97 | bool isStartingAttack; 98 | bool isStuck; 99 | bool isTraining; 100 | bool isUnderStorm; 101 | bool isUnderDarkSwarm; 102 | bool isUnderDWeb; 103 | bool isPowered; 104 | bool isVisible[9]; 105 | int buttonset; 106 | 107 | int lastAttackerPlayer; 108 | bool recentlyAttacked; 109 | int replayID; 110 | }; 111 | } 112 | -------------------------------------------------------------------------------- /Include/BWAPI/ComparisonFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // Prevent warnings if someone includes windows.h 3 | #ifdef max 4 | #undef max 5 | #endif 6 | 7 | #include 8 | #include 9 | 10 | #include "UnaryFilter.h" 11 | 12 | #define BWAPI_COMPARE_FILTER_OP(op) UnaryFilter operator op(const RType &cmp) const \ 13 | { return [=](PType v)->bool{ return (*this)(v) op cmp; }; } 14 | 15 | #define BWAPI_ARITHMATIC_FILTER_OP(op) template \ 16 | CompareFilter > operator op(const T &other) const \ 17 | { return [=](PType v)->int{ return (*this)(v) op other(v); }; } \ 18 | CompareFilter > operator op(RType other) const \ 19 | { return [=](PType v)->int{ return (*this)(v) op other; }; } 20 | 21 | namespace BWAPI 22 | { 23 | /// The CompareFilter is a container in which a stored function predicate returns a 24 | /// value. Arithmetic and bitwise operators will return a new CompareFilter that 25 | /// applies the operation to the result of the original functor. If any relational operators are 26 | /// used, then it creates a UnaryFilter that returns the result of the operation. 27 | /// 28 | /// @tparam PType 29 | /// The parameter type, which is the type passed into the functor. 30 | /// @tparam RType (optional) 31 | /// The functor's return type. It is int by default. 32 | /// @tparam Container (optional) 33 | /// Storage container for the function predicate. It is std::function by default. 34 | template < typename PType, typename RType=int, class Container = std::function > 35 | class CompareFilter 36 | { 37 | private: 38 | Container pred; 39 | public: 40 | // ctor 41 | template 42 | CompareFilter(const T &predicate) : pred(predicate) {} 43 | 44 | // Default copy/move ctor/assign and dtor 45 | 46 | // Comparison operators 47 | BWAPI_COMPARE_FILTER_OP(==); 48 | BWAPI_COMPARE_FILTER_OP(!=); 49 | BWAPI_COMPARE_FILTER_OP(<=); 50 | BWAPI_COMPARE_FILTER_OP(>=); 51 | BWAPI_COMPARE_FILTER_OP(<); 52 | BWAPI_COMPARE_FILTER_OP(>); 53 | 54 | // Arithmetic operators 55 | BWAPI_ARITHMATIC_FILTER_OP(+); 56 | BWAPI_ARITHMATIC_FILTER_OP(-); 57 | BWAPI_ARITHMATIC_FILTER_OP(|); 58 | BWAPI_ARITHMATIC_FILTER_OP(&); 59 | BWAPI_ARITHMATIC_FILTER_OP(*); 60 | BWAPI_ARITHMATIC_FILTER_OP(^); 61 | 62 | // Division 63 | template 64 | CompareFilter > operator /(const T &other) const 65 | { 66 | return [=](PType v)->int{ int rval = other(v); 67 | return rval == 0 ? std::numeric_limits::max() : (*this)(v) / rval; 68 | }; 69 | }; 70 | 71 | // Modulus 72 | template 73 | CompareFilter > operator %(const T &other) const 74 | { 75 | return [=](PType v)->int{ int rval = other(v); 76 | return rval == 0 ? 0 : (*this)(v) % rval; 77 | }; 78 | }; 79 | 80 | // call 81 | inline RType operator()(PType u) const 82 | { 83 | return pred(u); 84 | }; 85 | 86 | inline bool isValid() const 87 | { 88 | return (bool)pred; 89 | }; 90 | }; 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Include/BWAPI/Constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BWAPI 3 | { 4 | /** Used for converting between TilePosition coordinates and Position coordinates. */ 5 | #define TILE_SIZE 32 6 | } 7 | -------------------------------------------------------------------------------- /Include/BWAPI/CoordinateType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BWAPI 3 | { 4 | /// Contains the coordinate type enumeration for relative drawing positions. 5 | namespace CoordinateType 6 | { 7 | /// The coordinate type enumeration, used to indicate relative drawing positions. 8 | enum Enum 9 | { 10 | /// A default value for uninitialized coordinate types. 11 | None = 0, 12 | 13 | /// Positions::Origin (0,0) corresponds to the top left corner of the screen. 14 | Screen = 1, 15 | 16 | /// Positions::Origin (0,0) corresponds to the top left corner of the map. 17 | Map = 2, 18 | 19 | /// Positions::Origin (0,0) corresponds to the location of the mouse cursor. 20 | Mouse = 3, 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Include/BWAPI/DamageType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// Namespace containing damage types. 7 | /// 8 | /// @see DamageType 9 | /// 10 | /// [View on Liquipedia](http://wiki.teamliquid.net/starcraft/Damage_Type)
11 | /// [View on Starcraft Campendium (Official Website)](http://classic.battle.net/scc/gs/damage.shtml)
12 | /// [View on Starcraft Wikia](http://starcraft.wikia.com/wiki/Damage_types)
13 | namespace DamageTypes 14 | { 15 | /// Enumeration of damage types. 16 | /// @see DamageType 17 | namespace Enum 18 | { 19 | /// Enumeration of damage types. 20 | /// @see DamageType 21 | enum Enum 22 | { 23 | Independent, 24 | Explosive, 25 | Concussive, 26 | Normal, 27 | Ignore_Armor, 28 | None, 29 | Unknown, 30 | MAX 31 | }; 32 | } 33 | } 34 | /// Damage types are used in Broodwar to determine the amount of damage that will be 35 | /// done to a unit. This corresponds with UnitSizeType to determine the damage done to 36 | /// a unit. 37 | /// 38 | /// @see WeaponType, DamageTypes, UnitSizeType 39 | /// 40 | /// [View on Liquipedia](http://wiki.teamliquid.net/starcraft/Damage_Type)
41 | /// [View on Starcraft Campendium (Official Website)](http://classic.battle.net/scc/gs/damage.shtml)
42 | /// [View on Starcraft Wikia](http://starcraft.wikia.com/wiki/Damage_types)
43 | /// 44 | /// @ingroup TypeClasses 45 | class DamageType : public Type 46 | { 47 | public: 48 | /// @copydoc Type::Type(int) 49 | DamageType(int id = DamageTypes::Enum::None); 50 | }; 51 | 52 | /// @ingroup Types 53 | namespace DamageTypes 54 | { 55 | /// Retrieves the set of all the DamageTypes. 56 | /// 57 | /// @returns Set of DamageTypes. 58 | const DamageType::set& allDamageTypes(); 59 | 60 | extern const DamageType Independent; 61 | extern const DamageType Explosive; 62 | extern const DamageType Concussive; 63 | extern const DamageType Normal; 64 | extern const DamageType Ignore_Armor; 65 | extern const DamageType None; 66 | extern const DamageType Unknown; 67 | } 68 | 69 | static_assert(sizeof(DamageType) == sizeof(int), "Expected type to resolve to primitive size."); 70 | } 71 | -------------------------------------------------------------------------------- /Include/BWAPI/Error.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace BWAPI 6 | { 7 | class UnitType; 8 | 9 | /// Namespace containing error codes 10 | /// @see Error 11 | namespace Errors 12 | { 13 | /// Enumeration of Error types. 14 | /// @see Error 15 | namespace Enum 16 | { 17 | /// Enumeration of Error types. 18 | /// @see Error 19 | enum Enum 20 | { 21 | Unit_Does_Not_Exist, 22 | Unit_Not_Visible, 23 | Unit_Not_Owned, 24 | Unit_Busy, 25 | Incompatible_UnitType, 26 | Incompatible_TechType, 27 | Incompatible_State, 28 | Already_Researched, 29 | Fully_Upgraded, 30 | Currently_Researching, 31 | Currently_Upgrading, 32 | Insufficient_Minerals, 33 | Insufficient_Gas, 34 | Insufficient_Supply, 35 | Insufficient_Energy, 36 | Insufficient_Tech, 37 | Insufficient_Ammo, 38 | Insufficient_Space, 39 | Invalid_Tile_Position, 40 | Unbuildable_Location, 41 | Unreachable_Location, 42 | Out_Of_Range, 43 | Unable_To_Hit, 44 | Access_Denied, 45 | File_Not_Found, 46 | Invalid_Parameter, 47 | None, 48 | Unknown, 49 | MAX 50 | }; 51 | }; 52 | }; 53 | 54 | /// The Error object is generally used to determine why certain functions in BWAPI 55 | /// have failed. 56 | /// 57 | /// For example, you may not have enough resources to construct a unit. 58 | /// @see Game::getLastError, Game::setLastError, Errors 59 | /// @ingroup TypeClasses 60 | class Error : public Type 61 | { 62 | public: 63 | /// @copydoc Type::Type(int) 64 | Error(int id = Errors::Enum::None); 65 | }; 66 | 67 | /// @ingroup Types 68 | namespace Errors 69 | { 70 | /// Retrieves the set of all the error codes. 71 | /// 72 | /// @returns Set of error types. 73 | const Error::set& allErrors(); 74 | 75 | extern const Error Unit_Does_Not_Exist; 76 | extern const Error Unit_Not_Visible; 77 | extern const Error Unit_Not_Owned; 78 | extern const Error Unit_Busy; 79 | extern const Error Incompatible_UnitType; 80 | extern const Error Incompatible_TechType; 81 | extern const Error Incompatible_State; 82 | extern const Error Already_Researched; 83 | extern const Error Fully_Upgraded; 84 | extern const Error Currently_Researching; 85 | extern const Error Currently_Upgrading; 86 | extern const Error Insufficient_Minerals; 87 | extern const Error Insufficient_Gas; 88 | extern const Error Insufficient_Supply; 89 | extern const Error Insufficient_Energy; 90 | extern const Error Insufficient_Tech; 91 | extern const Error Insufficient_Ammo; 92 | extern const Error Insufficient_Space; 93 | extern const Error Invalid_Tile_Position; 94 | extern const Error Unbuildable_Location; 95 | extern const Error Unreachable_Location; 96 | extern const Error Out_Of_Range; 97 | extern const Error Unable_To_Hit; 98 | extern const Error Access_Denied; 99 | extern const Error File_Not_Found; 100 | extern const Error Invalid_Parameter; 101 | extern const Error None; 102 | extern const Error Unknown; 103 | } 104 | 105 | static_assert(sizeof(Error) == sizeof(int), "Expected type to resolve to primitive size."); 106 | } 107 | -------------------------------------------------------------------------------- /Include/BWAPI/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace BWAPI 9 | { 10 | // Forward Declarations 11 | class PlayerInterface; 12 | typedef PlayerInterface* Player; 13 | 14 | class Event 15 | { 16 | public: 17 | Event() = default; 18 | ~Event(); 19 | Event(const Event& other); 20 | Event(Event&& other); 21 | Event& operator=(const Event& other); 22 | Event& operator=(Event &&other); 23 | bool operator==(const Event& other) const; 24 | static Event MatchStart(); 25 | static Event MatchEnd(bool isWinner); 26 | static Event MatchFrame(); 27 | static Event MenuFrame(); 28 | static Event SendText(const char* text = nullptr); 29 | static Event ReceiveText(Player player, const char* text = nullptr); 30 | static Event PlayerLeft(Player player); 31 | static Event NukeDetect(Position target); 32 | static Event UnitDiscover(Unit unit); 33 | static Event UnitEvade(Unit unit); 34 | static Event UnitShow(Unit unit); 35 | static Event UnitHide(Unit unit); 36 | static Event UnitCreate(Unit unit); 37 | static Event UnitDestroy(Unit unit); 38 | static Event UnitMorph(Unit unit); 39 | static Event UnitRenegade(Unit unit); 40 | static Event SaveGame(const char* gameName = nullptr); 41 | static Event UnitComplete(Unit unit); 42 | EventType::Enum getType() const; 43 | Position getPosition() const; 44 | const std::string& getText() const; 45 | Unit getUnit() const; 46 | Player getPlayer() const; 47 | bool isWinner() const; 48 | 49 | Event& setType(EventType::Enum type); 50 | Event& setPosition(Position position); 51 | Event& setText(const char* text); 52 | Event& setUnit(Unit unit); 53 | Event& setPlayer(Player player); 54 | Event& setWinner(bool isWinner); 55 | //static Event TriggerAction(); 56 | private: 57 | Position position = Positions::None; 58 | std::string* text = nullptr; 59 | Unit unit = nullptr; 60 | Player player = nullptr; 61 | EventType::Enum type = EventType::None; 62 | bool winner = false; 63 | }; 64 | } -------------------------------------------------------------------------------- /Include/BWAPI/EventType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BWAPI 3 | { 4 | /// Contains a list of event types supported by BWAPI. 5 | namespace EventType 6 | { 7 | /// Enumeration of callback event types. 8 | enum Enum 9 | { 10 | MatchStart, 11 | MatchEnd, 12 | MatchFrame, 13 | MenuFrame, 14 | SendText, 15 | ReceiveText, 16 | PlayerLeft, 17 | NukeDetect, 18 | UnitDiscover, 19 | UnitEvade, 20 | UnitShow, 21 | UnitHide, 22 | UnitCreate, 23 | UnitDestroy, 24 | UnitMorph, 25 | UnitRenegade, 26 | SaveGame, 27 | UnitComplete, 28 | //TriggerAction, 29 | None 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Include/BWAPI/ExplosionType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// Namespace containing explosion types. 7 | /// @see ExplosionType 8 | namespace ExplosionTypes 9 | { 10 | /// Enumeration of explosion types. 11 | /// @see ExplosionType 12 | namespace Enum 13 | { 14 | /// Enumeration of explosion types. 15 | /// @see ExplosionType 16 | enum Enum 17 | { 18 | None = 0, 19 | Normal, 20 | Radial_Splash, 21 | Enemy_Splash, 22 | Lockdown, 23 | Nuclear_Missile, 24 | Parasite, 25 | Broodlings, 26 | EMP_Shockwave, 27 | Irradiate, 28 | Ensnare, 29 | Plague, 30 | Stasis_Field, 31 | Dark_Swarm, 32 | Consume, 33 | Yamato_Gun, 34 | Restoration, 35 | Disruption_Web, 36 | Corrosive_Acid, 37 | Mind_Control, 38 | Feedback, 39 | Optical_Flare, 40 | Maelstrom, 41 | Unused, 42 | Air_Splash, 43 | Unknown, 44 | MAX 45 | }; 46 | }; 47 | }; 48 | /// A representation of a weapon's explosion type. This indicates how the 49 | /// weapon behaves, such as if it deals splash damage or causes an effect to occur. 50 | /// 51 | /// @see ExplosionTypes 52 | /// @ingroup TypeClasses 53 | class ExplosionType : public Type 54 | { 55 | public: 56 | /// @copydoc Type::Type(int) 57 | ExplosionType(int id = ExplosionTypes::Enum::None); 58 | }; 59 | 60 | /// @ingroup Types 61 | namespace ExplosionTypes 62 | { 63 | /// Retrieves the set of all valid ExplosionTypes. 64 | /// 65 | /// @returns Set of ExplosionTypes. 66 | const ExplosionType::set& allExplosionTypes(); 67 | 68 | extern const ExplosionType None; 69 | extern const ExplosionType Normal; 70 | extern const ExplosionType Radial_Splash; 71 | extern const ExplosionType Enemy_Splash; 72 | extern const ExplosionType Lockdown; 73 | extern const ExplosionType Nuclear_Missile; 74 | extern const ExplosionType Parasite; 75 | extern const ExplosionType Broodlings; 76 | extern const ExplosionType EMP_Shockwave; 77 | extern const ExplosionType Irradiate; 78 | extern const ExplosionType Ensnare; 79 | extern const ExplosionType Plague; 80 | extern const ExplosionType Stasis_Field; 81 | extern const ExplosionType Dark_Swarm; 82 | extern const ExplosionType Consume; 83 | extern const ExplosionType Yamato_Gun; 84 | extern const ExplosionType Restoration; 85 | extern const ExplosionType Disruption_Web; 86 | extern const ExplosionType Corrosive_Acid; 87 | extern const ExplosionType Mind_Control; 88 | extern const ExplosionType Feedback; 89 | extern const ExplosionType Optical_Flare; 90 | extern const ExplosionType Maelstrom; 91 | extern const ExplosionType Air_Splash; 92 | extern const ExplosionType Unknown; 93 | } 94 | 95 | static_assert(sizeof(ExplosionType) == sizeof(int), "Expected type to resolve to primitive size."); 96 | } 97 | -------------------------------------------------------------------------------- /Include/BWAPI/Flag.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BWAPI 3 | { 4 | /// Contains flag enumerations for BWAPI. 5 | /// @see Game::enableFlag, Game::isFlagEnabled 6 | namespace Flag 7 | { 8 | /// Contains flag enumerations for BWAPI. 9 | /// @see Game::enableFlag, Game::isFlagEnabled 10 | enum Enum 11 | { 12 | /// Enable to get information about all units on the map, not just the visible units. 13 | CompleteMapInformation = 0, 14 | 15 | /// Enable to get information from the user (what units are selected, chat messages 16 | /// the user enters, etc) 17 | UserInput = 1, 18 | 19 | /// The maximum number of different flags available. 20 | Max 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Include/BWAPI/Force.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace BWAPI 6 | { 7 | // Forward Declarations 8 | class Playerset; 9 | 10 | class ForceInterface; 11 | typedef ForceInterface *Force; 12 | 13 | /// The Force class is used to get information about each force in a match. 14 | /// Normally this is considered a team. 15 | /// 16 | /// @note It is not called a team because players on the same force do not necessarily need 17 | /// to be allied at the beginning of a match. 18 | /// 19 | /// @ingroup Interface 20 | class ForceInterface : public Interface 21 | { 22 | protected: 23 | virtual ~ForceInterface() {}; 24 | public : 25 | /// Retrieves the unique ID that represents this Force. 26 | /// 27 | /// @returns 28 | /// An integer containing the ID for the Force. 29 | virtual int getID() const = 0; 30 | 31 | /// Retrieves the name of the Force. 32 | /// 33 | /// @returns 34 | /// A std::string object containing the name of the force. 35 | /// 36 | /// Example usage: 37 | /// @code 38 | /// BWAPI::Force myForce = BWAPI::Broodwar->self()->getForce(); 39 | /// if ( myForce->getName() == "Observers" ) 40 | /// BWAPI::Broodwar << "Looks like we're observing a match." << std::endl; 41 | /// @endcode 42 | /// 43 | /// @note Don't forget to use std::string::c_str() when passing this parameter to 44 | /// Game::sendText and other variadic functions. 45 | virtual std::string getName() const = 0; 46 | 47 | /// Retrieves the set of players that belong to this Force. 48 | /// 49 | /// @returns 50 | /// A Playerset object containing the players that are part of this Force. 51 | /// 52 | /// Example usage: 53 | /// @code 54 | /// // Get the enemy force, but make sure we have an enemy 55 | /// BWAPI::Force myEnemyForce = BWAPI::Broodwar->enemy() ? BWAPI::Broodwar->enemy()->getForce() : nullptr; 56 | /// if ( myEnemyForce != nullptr ) 57 | /// { 58 | /// Broodwar << "The allies of my enemy are..." << std::endl; 59 | /// for ( auto i = myEnemyForce.begin(); i != myEnemyForce.end(); ++i ) 60 | /// Broodwar << " - " << i->getName() << std::endl; 61 | /// } 62 | /// @endcode 63 | virtual Playerset getPlayers() const = 0; 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /Include/BWAPI/Forceset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SetContainer.h" 3 | 4 | namespace BWAPI 5 | { 6 | // Forward Declarations 7 | class ForceInterface; 8 | typedef ForceInterface *Force; 9 | class Playerset; 10 | 11 | /// A container that holds a group of Forces. 12 | /// 13 | /// @see BWAPI::Force 14 | class Forceset : public SetContainer> 15 | { 16 | public: 17 | 18 | /// @copydoc ForceInterface::getPlayers 19 | Playerset getPlayers() const; 20 | }; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Include/BWAPI/GameType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// Namespace containing game types. 7 | /// @see GameType 8 | namespace GameTypes 9 | { 10 | /// Enumeration of game types. 11 | /// @see GameType 12 | namespace Enum 13 | { 14 | /// Enumeration of game types. 15 | /// @see GameType 16 | enum Enum 17 | { 18 | None = 0, 19 | Custom, // Warcraft III 20 | Melee, 21 | Free_For_All, 22 | One_on_One, 23 | Capture_The_Flag, 24 | Greed, 25 | Slaughter, 26 | Sudden_Death, 27 | Ladder, 28 | Use_Map_Settings, 29 | Team_Melee, 30 | Team_Free_For_All, 31 | Team_Capture_The_Flag, 32 | Unknown_0x0E, 33 | Top_vs_Bottom, 34 | Iron_Man_Ladder, // Warcraft II 35 | 36 | Pro_Gamer_League = 32, // Not valid 37 | Unknown, 38 | MAX 39 | }; 40 | }; 41 | }; 42 | /// A class that represents game types in Broodwar. A game type is selected 43 | /// when creating a game. 44 | /// 45 | /// @see GameTypes 46 | /// @ingroup TypeClasses 47 | class GameType : public Type 48 | { 49 | public: 50 | /// @copydoc Type::Type(int) 51 | GameType(int id = GameTypes::Enum::None); 52 | }; 53 | 54 | /// @ingroup Types 55 | namespace GameTypes 56 | { 57 | /// Retrieves the set of all the valid GameTypes. 58 | /// 59 | /// @returns Set of available GameTypes. 60 | const GameType::set& allGameTypes(); 61 | 62 | extern const GameType Melee; 63 | extern const GameType Free_For_All; 64 | extern const GameType One_on_One; 65 | extern const GameType Capture_The_Flag; 66 | extern const GameType Greed; 67 | extern const GameType Slaughter; 68 | extern const GameType Sudden_Death; 69 | extern const GameType Ladder; 70 | extern const GameType Use_Map_Settings; 71 | extern const GameType Team_Melee; 72 | extern const GameType Team_Free_For_All; 73 | extern const GameType Team_Capture_The_Flag; 74 | extern const GameType Top_vs_Bottom; 75 | extern const GameType None; 76 | extern const GameType Unknown; 77 | } 78 | 79 | static_assert(sizeof(GameType) == sizeof(int), "Expected type to resolve to primitive size."); 80 | } 81 | -------------------------------------------------------------------------------- /Include/BWAPI/InterfaceEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// The interface event is an attachment to BWAPI interfaces which allows the user to 7 | /// register powerful conditional callbacks that can be executed a user-specified number of 8 | /// times. 9 | /// 10 | /// @tparam T 11 | /// The interface that this class is being used for. 12 | /// 13 | /// @see Interface::registerEvent 14 | template < typename T > 15 | class InterfaceEvent 16 | { 17 | public: 18 | InterfaceEvent() = default; 19 | 20 | /// This is the expected constructor for an interface event. 21 | /// 22 | /// 23 | /// An function callback that is run when all other conditions for this event are met. 24 | /// 25 | /// (optioinal) 26 | /// A function predicate that returns true if this event should be triggered. 27 | /// 28 | /// (optional) 29 | /// The number of times that the action is called before this event is discarded. A value 30 | /// of -1 means the event will never be discarded until the game has ended. 31 | /// 32 | /// (optional) 33 | /// The frequency that the event will check its condition at. A lower value indicates a 34 | /// higher frequency. A value of 0 means that the condition is checked every frame. 35 | /// A value of 10 means that the condition is checked once every 10 frames. 36 | /// 37 | InterfaceEvent(const std::function &action, const std::function &condition = nullptr, int timesToRun = -1, int framesToCheck = 0) 38 | : condProc( condition ) 39 | , execProc( action ) 40 | , runFreq( framesToCheck ) 41 | , runCount( timesToRun ) 42 | , step( framesToCheck ) 43 | {}; 44 | 45 | /// Checks if the event has finished its execution and is marked for removal. 46 | /// 47 | /// @returns true if the event has completed all runs and/or is marked for removal, otherwise 48 | /// it returns false if the event should continue execution. 49 | bool isFinished() const 50 | { 51 | return this->runCount == 0; 52 | }; 53 | 54 | /// Marks the event for removal. 55 | void removeEvent() 56 | { 57 | this->runCount = 0; 58 | }; 59 | 60 | protected: 61 | template < typename U > 62 | friend class Interface; 63 | 64 | // Function that runs the event, checkings its conditions and running its action, then 65 | // decrementing the run count. 66 | bool execute(T *instance) 67 | { 68 | // condition check 69 | if ( !this->isConditionMet(instance) ) 70 | return false; 71 | 72 | // There must be an exec proc! 73 | if ( !this->execProc ) 74 | return false; 75 | 76 | // execute 77 | this->execProc(instance); 78 | 79 | // Decrement run count (-1 being infinite) 80 | if ( this->runCount > 0 ) 81 | --this->runCount; 82 | return true; 83 | }; 84 | 85 | // Function to check if the condition associated with the event is true. Includes frame and 86 | // run count checking. 87 | bool isConditionMet(T *instance) 88 | { 89 | // Validity check 90 | if ( this->isFinished() ) 91 | return false; 92 | 93 | // Frame check 94 | --step; 95 | if ( step > 0 ) 96 | return false; 97 | this->step = this->runFreq; 98 | 99 | // Conditional check 100 | if ( this->condProc ) 101 | return this->condProc(instance); 102 | return true; // always run if there is no conditional function 103 | }; 104 | private: 105 | // Data members 106 | std::function condProc = nullptr; 107 | std::function execProc = nullptr; 108 | int runFreq = 0; // Frequency of runs, in frames (0 means every frame, 1 means every other frame) 109 | int runCount = 0; // Number of times that the action can occur (-1 being infinite) 110 | int step = 0; // Current step. Executes when reaches 0, then reset to runFreq. 111 | }; 112 | } 113 | -------------------------------------------------------------------------------- /Include/BWAPI/Latency.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BWAPI 3 | { 4 | /// Contains enumeration of known latency values. 5 | /// @see Game::getLatency 6 | namespace Latency 7 | { 8 | /// Contains enumeration of known latency values. 9 | /// @see Game::getLatency 10 | enum Enum 11 | { 12 | SinglePlayer = 2, 13 | LanLow = 5, 14 | LanMedium = 7, 15 | LanHigh = 9, 16 | BattlenetLow = 14, 17 | BattlenetMedium = 19, 18 | BattlenetHigh = 24 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Include/BWAPI/PlayerType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// Namespace containing player types (player controllers). 7 | /// @see PlayerType 8 | namespace PlayerTypes 9 | { 10 | /// Enumeration of player types (player controllers). 11 | /// @see PlayerType 12 | namespace Enum 13 | { 14 | /// Enumeration of player types (player controllers). 15 | /// @see PlayerType 16 | enum Enum 17 | { 18 | None = 0, 19 | Computer, 20 | Player, 21 | RescuePassive, 22 | RescueActive, 23 | EitherPreferComputer, 24 | EitherPreferHuman, 25 | Neutral, 26 | Closed, 27 | Observer, 28 | PlayerLeft, 29 | ComputerLeft, 30 | Unknown, 31 | MAX 32 | }; 33 | }; 34 | }; 35 | /// Represents the type of controller for the player slot (i.e. human, computer). 36 | /// 37 | /// @see PlayerTypes 38 | /// @ingroup TypeClasses 39 | class PlayerType : public Type 40 | { 41 | public: 42 | /// @copydoc Type::Type(int) 43 | PlayerType(int id = PlayerTypes::Enum::None); 44 | 45 | /// Identifies whether or not this type is used for the pre-game lobby. 46 | /// A type such as PlayerTypes::ComputerLeft would only appear in-game when a computer 47 | /// player is defeated. 48 | /// 49 | /// @returns true if this type can appear in the pre-game lobby, false otherwise. 50 | bool isLobbyType() const; 51 | 52 | /// Identifies whether or not this type is used in-game. A type such as 53 | /// PlayerTypes::Closed would not be a valid in-game type. 54 | /// 55 | /// @returns true if the type can appear in-game, false otherwise. 56 | /// @see isLobbyType 57 | bool isGameType() const; 58 | }; 59 | 60 | /// @ingroup Types 61 | namespace PlayerTypes 62 | { 63 | /// Retrieves the set of all the PlayerTypes. 64 | /// 65 | /// @returns Set consisting of all valid PlayerTypes. 66 | const PlayerType::set& allPlayerTypes(); 67 | 68 | extern const PlayerType None; 69 | extern const PlayerType Computer; 70 | extern const PlayerType Player; 71 | extern const PlayerType RescuePassive; 72 | extern const PlayerType EitherPreferComputer; 73 | extern const PlayerType EitherPreferHuman; 74 | extern const PlayerType Neutral; 75 | extern const PlayerType Closed; 76 | extern const PlayerType PlayerLeft; 77 | extern const PlayerType ComputerLeft; 78 | extern const PlayerType Unknown; 79 | } 80 | 81 | static_assert(sizeof(PlayerType) == sizeof(int), "Expected type to resolve to primitive size."); 82 | } 83 | -------------------------------------------------------------------------------- /Include/BWAPI/Playerset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SetContainer.h" 3 | 4 | #include 5 | #include 6 | 7 | namespace BWAPI 8 | { 9 | // Forward Declarations 10 | class PlayerInterface; 11 | typedef PlayerInterface *Player; 12 | class Unitset; 13 | 14 | /// A set containing Player objects. 15 | class Playerset : public SetContainer> 16 | { 17 | public: 18 | 19 | /// Returns the set of all units that every player in this set owns. 20 | /// 21 | /// @returns Unitset containing Playerset's units 22 | /// @see PlayerInterface::getUnits 23 | Unitset getUnits() const; 24 | 25 | /// Returns the list of races that each player in the set is. 26 | /// 27 | /// @returns Race::set containing Playerset's races 28 | /// @see PlayerInterface::getRace 29 | Race::set getRaces() const; 30 | 31 | /// Sets the alliance status with all players contained in the Playerset. 32 | /// 33 | /// 34 | /// Set to true to set the player to allied, or false for enemy. 35 | /// 36 | /// 37 | /// Set to true to turn on allied victory, or false to disable it. 38 | /// 39 | /// 40 | /// @see Game::setAlliance 41 | void setAlliance(bool allies = true, bool alliedVictory = true); 42 | 43 | }; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Include/BWAPI/PositionUnit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | class UnitInterface; 7 | typedef UnitInterface *Unit; 8 | 9 | /// PositionOrUnit is a class that is either a Position or a Unit. 10 | /// The purpose of this class is to reduce interface overhead by combining two commonly passed 11 | /// values into one, and to allow more function overloads with less effort. 12 | class PositionOrUnit 13 | { 14 | public: 15 | /// Unit constructor. Assigns this class to contain a unit. 16 | /// 17 | /// 18 | /// The unit to assign to this class. 19 | /// 20 | PositionOrUnit(Unit unit = nullptr); 21 | 22 | /// Position constructor. Assigns this class to contain a position. 23 | /// 24 | /// 25 | /// The position to assign to this class. 26 | /// 27 | PositionOrUnit(Position pos); 28 | 29 | /// Unit assignment operator. Assigns a unit to this class. 30 | PositionOrUnit &operator =(Unit pUnit); 31 | 32 | /// Position assignment operator. Assigns a position to this class. 33 | PositionOrUnit &operator =(Position pos); 34 | 35 | /// Indicates if a Unit is currently held in this class. 36 | /// 37 | /// @returns true if the value contained within this class is considered a unit, and false if 38 | /// it is a position. 39 | bool isUnit() const; 40 | 41 | /// Retrieves the Unit attached to this class, if there is one. 42 | /// 43 | /// @returns The Unit that was assigned to this class. 44 | /// @retval nullptr If this class does not contain a unit, or if nullptr was assigned to 45 | /// this class as a Unit. 46 | Unit getUnit() const; 47 | 48 | /// Indicates if a Position is currently held in this class. 49 | /// 50 | /// @returns true if the value contained within this class is considered a position, and false 51 | /// if it is a unit. 52 | bool isPosition() const; 53 | 54 | /// Retrieves the position if it was assigned to this class, otherwise it will 55 | /// retrieve the position of the unit contained within this class if there is one. 56 | /// 57 | /// @returns Position that was stored if there is one. If not, then the position of the unit 58 | /// will be used instead. 59 | /// @retval Positions::None if a nullptr Unit was assigned to this class. 60 | Position getPosition() const; 61 | 62 | private: 63 | /// @cond HIDDEN 64 | union 65 | { 66 | struct 67 | { 68 | int x, y; 69 | } position; 70 | struct 71 | { 72 | Unit pUnit; 73 | int y; 74 | } unit; 75 | }; 76 | /// @endcond 77 | }; 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Include/BWAPI/Race.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | class UnitType; 7 | 8 | /// Namespace containing all valid races. 9 | /// @see Race 10 | namespace Races 11 | { 12 | /// Enumeration of races. 13 | /// @see Race 14 | namespace Enum 15 | { 16 | /// Enumeration of races. 17 | /// @see Race 18 | enum Enum 19 | { 20 | Zerg = 0, 21 | Terran, 22 | Protoss, 23 | Other, 24 | Unused, 25 | Select, 26 | Random, 27 | None, 28 | Unknown, 29 | MAX 30 | }; 31 | }; 32 | } 33 | 34 | /// The Race object is used to get information about a particular race. For 35 | /// example, the default worker and supply provider UnitType. 36 | /// 37 | /// As you should already know, Starcraft has three races: @Terran , @Protoss , and @Zerg . 38 | /// @see UnitType::getRace, PlayerInterface::getRace, Races 39 | /// @ingroup TypeClasses 40 | class Race : public Type 41 | { 42 | public: 43 | /// @copydoc Type::Type(int) 44 | Race(int id = Races::Enum::None); 45 | 46 | /// Retrieves the default worker type for this Race. 47 | /// 48 | /// @note In Starcraft, workers are the units that are used to construct structures. 49 | /// 50 | /// @returns UnitType of the worker that this race uses. 51 | UnitType getWorker() const; 52 | 53 | /// Retrieves the default resource center UnitType that is used to create expansions for 54 | /// this Race. 55 | /// 56 | /// @note In Starcraft, the center is the very first structure of the Race's technology 57 | /// tree. Also known as its base of operations or resource depot. 58 | /// 59 | /// @returns UnitType of the center that this race uses. 60 | UnitType getCenter() const; 61 | 62 | /// Retrieves the default structure UnitType for this Race that is used to harvest gas from 63 | /// @Geysers. 64 | /// 65 | /// @note In Starcraft, you must first construct a structure over a @Geyser in order to 66 | /// begin harvesting Vespene Gas. 67 | /// 68 | /// @returns UnitType of the structure used to harvest gas. 69 | UnitType getRefinery() const; 70 | 71 | /// Retrieves the default transport UnitType for this race that is used to transport ground 72 | /// units across the map. 73 | /// 74 | /// @note In Starcraft, transports will allow you to carry ground units over unpassable 75 | /// terrain. 76 | /// 77 | /// @returns UnitType for transportation. 78 | UnitType getTransport() const; 79 | 80 | /// Retrieves the default supply provider UnitType for this race that is used to construct 81 | /// units. 82 | /// 83 | /// @note In Starcraft, training, morphing, or warping in units requires that the player 84 | /// has sufficient supply available for their Race. 85 | /// 86 | /// @returns UnitType that provides the player with supply. 87 | UnitType getSupplyProvider() const; 88 | }; 89 | 90 | /// @ingroup Types 91 | namespace Races 92 | { 93 | /// Retrieves the set of all valid races. 94 | /// 95 | /// @returns Race::set containing all the Race types. 96 | const Race::set& allRaces(); 97 | 98 | extern const Race Zerg; 99 | extern const Race Terran; 100 | extern const Race Protoss; 101 | extern const Race Random; 102 | extern const Race None; 103 | extern const Race Unknown; 104 | } 105 | 106 | static_assert(sizeof(Race) == sizeof(int), "Expected type to resolve to primitive size."); 107 | } 108 | -------------------------------------------------------------------------------- /Include/BWAPI/Regionset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SetContainer.h" 3 | #include 4 | #include 5 | 6 | namespace BWAPI 7 | { 8 | // Forward Declarations 9 | class RegionInterface; 10 | typedef RegionInterface *Region; 11 | 12 | class Unitset; 13 | 14 | /// A container that holds a set of Region objects. 15 | class Regionset : public SetContainer> 16 | { 17 | public: 18 | 19 | /// @copydoc RegionInterface::getCenter 20 | Position getCenter() const; 21 | 22 | /// @copydoc RegionInterface::getUnits 23 | Unitset getUnits(const UnitFilter &pred = __nullptr) const; 24 | }; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Include/BWAPI/SetContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace BWAPI 6 | { 7 | template 8 | using SetContainerUnderlyingT = std::unordered_set < T, HashT >; 9 | 10 | /// This container is used to wrap convenience functions for BWAPI and be used as a 11 | /// bridge with a built-in set type. 12 | /// 13 | /// @tparam T 14 | /// Type that this set contains. 15 | /// @tparam HashT 16 | /// Hash type. Defaults to integral hashing for BWAPI usage. 17 | template > 18 | class SetContainer : public SetContainerUnderlyingT < T, HashT > 19 | { 20 | public: 21 | SetContainer() : SetContainerUnderlyingT() {} 22 | SetContainer(SetContainer const &other) : SetContainerUnderlyingT(other) {} 23 | SetContainer(SetContainer &&other) : SetContainerUnderlyingT(std::forward(other)) {} 24 | SetContainer(std::initializer_list ilist) : SetContainerUnderlyingT(ilist) {} 25 | 26 | template 27 | SetContainer(IterT _begin, IterT _end) : SetContainerUnderlyingT(_begin, _end) {} 28 | 29 | /// Iterates the set and erases each element x where pred(x) returns true. 30 | /// 31 | /// 32 | /// Predicate for removing elements. 33 | /// 34 | /// @see std::erase_if 35 | template 36 | void erase_if(const Pred& pred) { 37 | auto it = this->begin(); 38 | while (it != this->end()) { 39 | if (pred(*it)) it = this->erase(it); 40 | else ++it; 41 | } 42 | }; 43 | 44 | /// Checks if this set contains a specific value. 45 | /// 46 | /// 47 | /// Value to search for. 48 | /// 49 | bool contains(T const &value) const 50 | { 51 | return count(value) != 0; 52 | } 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Include/BWAPI/TournamentAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BWAPI 4 | { 5 | /// Contains a list of interruptable actions that the tournament module can allow or deny. 6 | /// @see TournamentModule::onAction 7 | namespace Tournament 8 | { 9 | /// Contains a list of interruptable actions that the tournament module can allow or deny. 10 | /// @see TournamentModule::onAction 11 | enum ActionID 12 | { 13 | /// @see Game::enableFlag 14 | EnableFlag, 15 | 16 | /// @see Game::pauseGame 17 | PauseGame, 18 | 19 | /// @see Game::resumeGame 20 | ResumeGame, 21 | 22 | /// @see Game::leaveGame 23 | LeaveGame, 24 | 25 | /// @see Game::setLocalSpeed 26 | SetLocalSpeed, 27 | 28 | /// @see Game::setTextSize 29 | SetTextSize, 30 | 31 | /// @see Game::setLatCom 32 | SetLatCom, 33 | 34 | /// @see Game::setGUI 35 | SetGUI, 36 | 37 | /// @see Game::setMap 38 | SetMap, 39 | 40 | /// @see Game::setFrameSkip 41 | SetFrameSkip, 42 | 43 | /// @see Game::printf 44 | Printf, 45 | 46 | /// @see Game::sendText 47 | SendText, 48 | 49 | /// @see Game::setCommandOptimizationLevel 50 | SetCommandOptimizationLevel 51 | }; 52 | 53 | }; 54 | }; 55 | -------------------------------------------------------------------------------- /Include/BWAPI/UnaryFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// UnaryFilter allows for logical functor combinations. 7 | /// 8 | /// @code 9 | /// Unit myUnit; 10 | /// // The following two if statements are equivalent 11 | /// if ( myUnit->getType().isWorker() && myUnit->isCompleted() && myUnit->isIdle() ) 12 | /// {} 13 | /// 14 | /// if ( (IsWorker && IsCompleted && IsIdle)(myUnit) ) 15 | /// {} 16 | /// @endcode 17 | /// 18 | /// @tparam PType 19 | /// The type being passed into the predicate, which will be of type bool(PType). 20 | /// @tparam Container (optional) 21 | /// Storage container for the function predicate. It is std::function by default. 22 | template > 23 | class UnaryFilter 24 | { 25 | private: 26 | Container pred; 27 | public: 28 | // ctor 29 | template < typename T > 30 | UnaryFilter(const T &predicate) : pred(predicate) {} 31 | 32 | // Default copy/move ctor/assign and dtor 33 | 34 | // logical operators 35 | template 36 | inline UnaryFilter > operator &&(const T& other) const 37 | { 38 | return [=](PType v){ return (*this)(v) && other(v); }; 39 | }; 40 | 41 | template 42 | inline UnaryFilter > operator ||(const T& other) const 43 | { 44 | return [=](PType v){ return (*this)(v) || other(v); }; 45 | }; 46 | 47 | inline UnaryFilter > operator !() const 48 | { 49 | if ( !this->pred ) 50 | return nullptr; 51 | return [=](PType v){ return !(*this)(v); }; 52 | }; 53 | 54 | // call 55 | inline bool operator()(PType v) const 56 | { 57 | return pred(v); 58 | }; 59 | 60 | // operator bool 61 | inline bool isValid() const 62 | { 63 | return (bool)pred; 64 | }; 65 | 66 | }; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Include/BWAPI/UnitCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace BWAPI 6 | { 7 | // Forwards 8 | class UnitType; 9 | class TechType; 10 | class UpgradeType; 11 | class PositionOrUnit; 12 | class UnitInterface; 13 | typedef UnitInterface *Unit; 14 | 15 | class UnitCommand 16 | { 17 | public: 18 | UnitCommand() = default; 19 | UnitCommand(Unit _unit, UnitCommandType _type, Unit _target, int _x, int _y, int _extra); 20 | 21 | static UnitCommand attack(Unit unit, PositionOrUnit target, bool shiftQueueCommand = false); 22 | static UnitCommand build(Unit unit, TilePosition target, UnitType type); 23 | static UnitCommand buildAddon(Unit unit, UnitType type); 24 | static UnitCommand train(Unit unit, UnitType type); 25 | static UnitCommand morph(Unit unit, UnitType type); 26 | static UnitCommand research(Unit unit, TechType tech); 27 | static UnitCommand upgrade(Unit unit, UpgradeType upgrade); 28 | static UnitCommand setRallyPoint(Unit unit, PositionOrUnit target); 29 | static UnitCommand move(Unit unit, Position target, bool shiftQueueCommand = false); 30 | static UnitCommand patrol(Unit unit, Position target, bool shiftQueueCommand = false); 31 | static UnitCommand holdPosition(Unit unit, bool shiftQueueCommand = false); 32 | static UnitCommand stop(Unit unit, bool shiftQueueCommand = false); 33 | static UnitCommand follow(Unit unit, Unit target, bool shiftQueueCommand = false); 34 | static UnitCommand gather(Unit unit, Unit target, bool shiftQueueCommand = false); 35 | static UnitCommand returnCargo(Unit unit, bool shiftQueueCommand = false); 36 | static UnitCommand repair(Unit unit, Unit target, bool shiftQueueCommand = false); 37 | static UnitCommand burrow(Unit unit); 38 | static UnitCommand unburrow(Unit unit); 39 | static UnitCommand cloak(Unit unit); 40 | static UnitCommand decloak(Unit unit); 41 | static UnitCommand siege(Unit unit); 42 | static UnitCommand unsiege(Unit unit); 43 | static UnitCommand lift(Unit unit); 44 | static UnitCommand land(Unit unit, TilePosition target); 45 | static UnitCommand load(Unit unit, Unit target, bool shiftQueueCommand = false); 46 | static UnitCommand unload(Unit unit, Unit target); 47 | static UnitCommand unloadAll(Unit unit, bool shiftQueueCommand = false); 48 | static UnitCommand unloadAll(Unit unit, Position target, bool shiftQueueCommand = false); 49 | static UnitCommand rightClick(Unit unit, PositionOrUnit target, bool shiftQueueCommand = false); 50 | static UnitCommand haltConstruction(Unit unit); 51 | static UnitCommand cancelConstruction(Unit unit); 52 | static UnitCommand cancelAddon(Unit unit); 53 | static UnitCommand cancelTrain(Unit unit, int slot = -2); 54 | static UnitCommand cancelMorph(Unit unit); 55 | static UnitCommand cancelResearch(Unit unit); 56 | static UnitCommand cancelUpgrade(Unit unit); 57 | static UnitCommand useTech(Unit unit,TechType tech); 58 | static UnitCommand useTech(Unit unit,TechType tech, PositionOrUnit target); 59 | static UnitCommand placeCOP(Unit unit, TilePosition target); 60 | 61 | UnitCommandType getType() const; 62 | Unit getUnit() const; 63 | Unit getTarget() const; 64 | Position getTargetPosition() const; 65 | TilePosition getTargetTilePosition() const; 66 | UnitType getUnitType() const; 67 | TechType getTechType() const; 68 | UpgradeType getUpgradeType() const; 69 | int getSlot() const; 70 | bool isQueued() const; 71 | 72 | bool operator==(const UnitCommand& other) const; 73 | bool operator!=(const UnitCommand& other) const; 74 | 75 | Unit unit = nullptr; 76 | UnitCommandType type = UnitCommandTypes::None; 77 | Unit target = nullptr; 78 | int x = Positions::None.x; 79 | int y = Positions::None.y; 80 | int extra = 0; 81 | }; 82 | } -------------------------------------------------------------------------------- /Include/BWAPI/UnitSizeType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BWAPI 5 | { 6 | /// Namespace containing unit size types. 7 | /// 8 | /// @see UnitSizeType 9 | /// 10 | /// [View on Starcraft Campendium (Official Website)](http://classic.battle.net/scc/gs/damage.shtml)
11 | namespace UnitSizeTypes 12 | { 13 | /// Enumeration of unit size types. 14 | /// @see UnitSizeType 15 | namespace Enum 16 | { 17 | /// Enumeration of unit size types. 18 | /// @see UnitSizeType 19 | enum Enum 20 | { 21 | Independent = 0, 22 | Small, 23 | Medium, 24 | Large, 25 | None, 26 | Unknown, 27 | MAX 28 | }; 29 | }; 30 | }; 31 | 32 | /// Size types are used by unit types in Broodwar to determine how much damage will be 33 | /// applied. This corresponds with DamageType for several different damage reduction 34 | /// applications. 35 | /// 36 | /// @see DamageType, UnitType, UnitSizeTypes 37 | /// 38 | /// [View on Starcraft Campendium (Official Website)](http://classic.battle.net/scc/gs/damage.shtml)
39 | /// @ingroup TypeClasses 40 | class UnitSizeType : public Type 41 | { 42 | public: 43 | /// @copydoc Type::Type(int) 44 | UnitSizeType(int id = UnitSizeTypes::Enum::None); 45 | }; 46 | 47 | /// @ingroup Types 48 | namespace UnitSizeTypes 49 | { 50 | /// Retrieves the set of all valid UnitSizeTypes. 51 | /// 52 | /// @returns Set of all UnitSizeTypes. 53 | const UnitSizeType::set& allUnitSizeTypes(); 54 | 55 | extern const UnitSizeType Independent; 56 | extern const UnitSizeType Small; 57 | extern const UnitSizeType Medium; 58 | extern const UnitSizeType Large; 59 | extern const UnitSizeType None; 60 | extern const UnitSizeType Unknown; 61 | } 62 | 63 | static_assert(sizeof(UnitSizeType) == sizeof(int), "Expected type to resolve to primitive size."); 64 | } 65 | -------------------------------------------------------------------------------- /Include/BWAPI/WindowsTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef char CHAR; 4 | typedef short SHORT; 5 | typedef long LONG; 6 | typedef unsigned char BYTE; 7 | typedef unsigned short WORD; 8 | typedef unsigned long DWORD; 9 | typedef int BOOL; 10 | typedef void* HANDLE; 11 | typedef void* PVOID; 12 | typedef void* LPVOID; 13 | 14 | #ifndef WINAPI 15 | #define WINAPI __stdcall 16 | #endif 17 | 18 | #ifndef APIENTRY 19 | #define APIENTRY WINAPI 20 | #endif 21 | 22 | #ifndef DLL_PROCESS_ATTACH 23 | #define DLL_PROCESS_ATTACH 1 24 | #define DLL_THREAD_ATTACH 2 25 | #define DLL_THREAD_DETACH 3 26 | #define DLL_PROCESS_DETACH 0 27 | #endif 28 | 29 | #ifndef FALSE 30 | #define FALSE 0 31 | #endif 32 | #ifndef TRUE 33 | #define TRUE 1 34 | #endif 35 | -------------------------------------------------------------------------------- /Lib/Debug/BWAPIClientd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Debug/BWAPIClientd.lib -------------------------------------------------------------------------------- /Lib/Debug/BWAPIClientd.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Debug/BWAPIClientd.pdb -------------------------------------------------------------------------------- /Lib/Debug/BWAPILibd.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Debug/BWAPILibd.pdb -------------------------------------------------------------------------------- /Lib/Debug/BWAPId.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Debug/BWAPId.lib -------------------------------------------------------------------------------- /Lib/Debug/bwapid.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Debug/bwapid.pdb -------------------------------------------------------------------------------- /Lib/Release/BWAPI.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Release/BWAPI.lib -------------------------------------------------------------------------------- /Lib/Release/BWAPIClient.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Release/BWAPIClient.lib -------------------------------------------------------------------------------- /Lib/Release/BWAPIClient.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Release/BWAPIClient.pdb -------------------------------------------------------------------------------- /Lib/Release/BWAPILib.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Release/BWAPILib.pdb -------------------------------------------------------------------------------- /Lib/Release/VersionIs4.1.2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Lib/Release/VersionIs4.1.2.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BWAPI-CLI 2 | ## .NET wrapper for the Broodwar API (BWAPI) 3 | .NET wrapper for the Broodwar API (BWAPI) written in C++/CLI 4 | 5 | Currently wraps BWAPI 4.1.2 6 | 7 | This project is a C++/CLI wrapper for the Broodwar API. This project is also aimed to provide APIs that are higher level or more suited to F#/C# style than original BWAPI. 8 | 9 | WARNING: API will change during development. It is recommended that maintain your own copy be prepared to manually merge any changes you specifically desire. 10 | 11 | Project is in alpha stage, but library can run dll AI modules. Project is built with Visual Studio 2013, using BWAPI libraries directly. 12 | 13 | It is highly recommended that you have experience in setting up a BWAPI bot before dealing with this library. For now we do not provide any binaries so you'll have to build it by yourself. 14 | 15 | To use AI you have to place Broodwar.dll, BroodwarLoader.dll and BroodwarLoader.dll.config and your AI module into same folder. BWAPI config must point to BroodwarLoader.dll as AI module. Edit .config file. The Assembly key must point to your AI assembly (with extension), and the Module key must point to your class that implements AiBase. ExampleAIModule ported to C# and to F# is also provided. 16 | 17 | ## Original Version 18 | Previous BWAPI-CLI for version 3.7.3 was created by ZeroFusion at http://bwapicli.codeplex.com/ 19 | 20 | ## Issues 21 | This project a port from VS 2010 + BWAPI 3.7.3 to VS 2013 + BWAPI 4.1.2 of an Alpha project by someone with minimal C++ experience and no BWAPI experience. 22 | 23 | Everything appears to be working, though unit filter based functions has not been tested. These required changes to the supplied BWAPI headers to make the project compile. For example: 24 | 25 | // Does not compile - IntelliSense: argument of type "decltype(nullptr)" is incompatible with parameter of type "const decltype(nullptr) &" 26 | Unitset getUnitsOnTile(BWAPI::TilePosition tile, const UnitFilter &pred = nullptr) const; 27 | 28 | // Now compiles 29 | Unitset getUnitsOnTile(BWAPI::TilePosition tile, const UnitFilter &pred = __nullptr) const; 30 | -------------------------------------------------------------------------------- /Src/Broodwar/AiBase.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #pragma managed 6 | 7 | #include "AiBase.h" 8 | 9 | namespace BroodWar 10 | { 11 | void AiBase::OnStart() { } 12 | 13 | void AiBase::OnEnd(bool isWinner) { } 14 | 15 | void AiBase::OnFrame() { } 16 | 17 | void AiBase::OnSendText(String^ text) { } 18 | 19 | void AiBase::OnReceiveText(Api::Player^ player, String^ text) { } 20 | 21 | void AiBase::OnPlayerLeft(Api::Player^ player) { } 22 | 23 | void AiBase::OnNukeDetect(Api::Position^ target) { } 24 | 25 | void AiBase::OnUnitDiscover(Api::Unit^ unit) { } 26 | 27 | void AiBase::OnUnitEvade(Api::Unit^ unit) { } 28 | 29 | void AiBase::OnUnitShow(Api::Unit^ unit) { } 30 | 31 | void AiBase::OnUnitHide(Api::Unit^ unit) { } 32 | 33 | void AiBase::OnUnitCreate(Api::Unit^ unit) { } 34 | 35 | void AiBase::OnUnitDestroy(Api::Unit^ unit) { } 36 | 37 | void AiBase::OnUnitMorph(Api::Unit^ unit) { } 38 | 39 | void AiBase::OnUnitRenegade(Api::Unit^ unit) { } 40 | 41 | void AiBase::OnSaveGame(String^ gameName) { } 42 | 43 | void AiBase::OnUnitComplete(Api::Unit^ unit) { } 44 | 45 | void AiBase::OnPlayerDropped(Api::Player^ player) { } 46 | } 47 | -------------------------------------------------------------------------------- /Src/Broodwar/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | using namespace System; 2 | using namespace System::Reflection; 3 | 4 | [assembly: AssemblyKeyFile("..\\bwapicli.snk")]; 5 | [assembly: AssemblyDelaySign(false)]; 6 | 7 | [assembly: AssemblyVersion("0.0.9.0")]; 8 | [assembly: AssemblyFileVersion("0.0.9.0")]; 9 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Bullet.cpp: -------------------------------------------------------------------------------- 1 | #include "Bullet.h" 2 | #include "Player.h" 3 | #include "Position.h" 4 | #include "Unit.h" 5 | 6 | #include "..\EnumMapping.h" 7 | 8 | namespace BroodWar 9 | { 10 | namespace Api 11 | { 12 | Bullet^ ConvertBullet(BWAPI::Bullet bullet) 13 | { 14 | if(bullet == NULL) 15 | return nullptr; 16 | return gcnew Bullet(bullet); 17 | } 18 | 19 | Bullet::Bullet(BWAPI::Bullet type) 20 | { 21 | instance = type; 22 | } 23 | 24 | Api::Enum::BulletType Bullet::Type::get() 25 | { 26 | return EnumMapping::BulletType->Managed(instance->getType()); 27 | } 28 | 29 | int Bullet::Id::get() 30 | { 31 | return instance->getID(); 32 | } 33 | 34 | bool Bullet::TypeEquals(Api::Enum::BulletType type) 35 | { 36 | return Type == type; 37 | } 38 | 39 | Player^ Bullet::Player::get() 40 | { 41 | return ConvertPlayer(instance->getPlayer()); 42 | } 43 | 44 | Unit^ Bullet::Source::get() 45 | { 46 | return ConvertUnit(instance->getSource()); 47 | } 48 | 49 | Position^ Bullet::Position::get() 50 | { 51 | return ConvertPosition(instance->getPosition()); 52 | } 53 | 54 | double Bullet::Angle::get() 55 | { 56 | return instance->getAngle(); 57 | } 58 | 59 | double Bullet::VelocityX::get() 60 | { 61 | return instance->getVelocityX(); 62 | } 63 | 64 | double Bullet::VelocityY::get() 65 | { 66 | return instance->getVelocityY(); 67 | } 68 | 69 | Unit^ Bullet::Target::get() 70 | { 71 | return ConvertUnit(instance->getTarget()); 72 | } 73 | 74 | Position^ Bullet::TargetPosition::get() 75 | { 76 | return ConvertPosition(instance->getTargetPosition()); 77 | } 78 | 79 | int Bullet::RemoveTimer::get() 80 | { 81 | return instance->getRemoveTimer(); 82 | } 83 | 84 | bool Bullet::Exists::get() 85 | { 86 | return instance->exists(); 87 | } 88 | 89 | bool Bullet::IsVisible() 90 | { 91 | return instance->isVisible(); 92 | } 93 | 94 | bool Bullet::IsVisible(Api::Player^ player) 95 | { 96 | return instance->isVisible(ConvertPlayer(player)); 97 | } 98 | 99 | int Bullet::GetHashCode() 100 | { 101 | return instance->getID(); 102 | } 103 | 104 | bool Bullet::Equals(Object^ o) 105 | { 106 | Bullet^ other = dynamic_cast(o); 107 | return this->Equals(other); 108 | } 109 | 110 | bool Bullet::Equals(Bullet^ other) 111 | { 112 | if(ReferenceEquals(nullptr, other)) 113 | return false; 114 | if(ReferenceEquals(this, other)) 115 | return true; 116 | return this->instance->getID() == other->instance->getID(); 117 | } 118 | 119 | bool Bullet::operator == (Bullet^ first, Bullet^ second) 120 | { 121 | if(ReferenceEquals(first, second)) 122 | return true; 123 | if(ReferenceEquals(nullptr, first)) 124 | return false; 125 | return first->Equals(second); 126 | } 127 | 128 | bool Bullet::operator != (Bullet^ first, Bullet^ second) 129 | { 130 | return !(first == second); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Bullet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | #include "Enum\BulletType.h" 9 | #include "Position.h" 10 | #include "IIdentifiedObject.h" 11 | 12 | using namespace System; 13 | using namespace BroodWar; 14 | using namespace BroodWar::Api; 15 | using namespace BroodWar::Api::Enum; 16 | 17 | namespace BroodWar 18 | { 19 | namespace Api 20 | { 21 | ref class Player; 22 | ref class Unit; 23 | 24 | public ref class Bullet sealed : public IIdentifiedObject 25 | { 26 | internal: 27 | BWAPI::Bullet instance; 28 | 29 | Bullet(BWAPI::Bullet type); 30 | 31 | public: 32 | virtual property int Id { int get(); } 33 | 34 | property BulletType Type { BulletType get(); } 35 | bool TypeEquals(BulletType type); 36 | property Api::Player^ Player { Api::Player^ get(); } 37 | property Unit^ Source { Unit^ get(); } 38 | property Api::Position^ Position { Api::Position^ get(); } 39 | property double Angle { double get(); } 40 | property double VelocityX { double get(); } 41 | property double VelocityY { double get(); } 42 | property Unit^ Target { Unit^ get(); } 43 | property Api::Position^ TargetPosition { Api::Position^ get(); } 44 | property int RemoveTimer { int get(); } 45 | property bool Exists { bool get(); } 46 | bool IsVisible(); 47 | bool IsVisible(Api::Player^ player); 48 | 49 | virtual int GetHashCode() override; 50 | virtual bool Equals(Object^ o) override; 51 | bool Equals(Bullet^ other); 52 | 53 | static bool operator == (Bullet^ first, Bullet^ second); 54 | static bool operator != (Bullet^ first, Bullet^ second); 55 | }; 56 | 57 | Bullet^ ConvertBullet(BWAPI::Bullet bullet); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/Client.cpp: -------------------------------------------------------------------------------- 1 | #pragma warning(push) 2 | #pragma warning(disable:4005) 3 | #include "Client.h" 4 | #include "..\Game.h" 5 | #pragma warning(pop) 6 | 7 | extern BWAPI::Client BWAPI::BWAPIClient; 8 | 9 | namespace BroodWar 10 | { 11 | namespace Api 12 | { 13 | namespace Client 14 | { 15 | bool Client::IsConnected::get() 16 | { 17 | return BWAPI::BWAPIClient.isConnected(); 18 | } 19 | 20 | bool Client::Connect() 21 | { 22 | bool result = BWAPI::BWAPIClient.connect(); 23 | if(result) 24 | Api::Game::Rebind(); 25 | return result; 26 | } 27 | 28 | void Client::Disconnect() 29 | { 30 | BWAPI::BWAPIClient.disconnect(); 31 | } 32 | 33 | void Client::Update() 34 | { 35 | BWAPI::BWAPIClient.update(); 36 | } 37 | 38 | //GameData^ Client::Data::get() 39 | //{ 40 | // #pragma warning Implement 41 | // throw gcnew System::NotImplementedException(); 42 | //} 43 | 44 | //void Client::Data::set(GameData^ value) 45 | //{ 46 | // #pragma warning Implement 47 | // throw gcnew System::NotImplementedException(); 48 | //} 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/Client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | namespace BroodWar 9 | { 10 | namespace Api 11 | { 12 | namespace Client 13 | { 14 | //ref class GameData; 15 | 16 | public ref class Client abstract sealed 17 | { 18 | public: 19 | static property bool IsConnected { bool get(); } 20 | static bool Connect(); 21 | static void Disconnect(); 22 | static void Update(); 23 | //static property GameData^ Data 24 | //{ 25 | // GameData^ get(); 26 | // void set(GameData^ value); 27 | //} 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/Command.cpp: -------------------------------------------------------------------------------- 1 | #include "Command.h" 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Client 8 | { 9 | Command::Command(BWAPIC::Command command) 10 | { 11 | instance = new BWAPIC::Command(command); 12 | } 13 | 14 | Command::~Command() 15 | { 16 | delete instance; 17 | } 18 | 19 | Command::!Command() 20 | { 21 | delete instance; 22 | } 23 | 24 | Command::Command() 25 | { 26 | instance = new BWAPIC::Command(); 27 | } 28 | 29 | Command::Command(CommandType type, int value1, int value2) 30 | { 31 | instance = new BWAPIC::Command(static_cast(type), value1, value2); 32 | } 33 | 34 | CommandType Command::Type::get() 35 | { 36 | return static_cast(instance->type); 37 | } 38 | 39 | void Command::Type::set(CommandType type) 40 | { 41 | instance->type = static_cast(type); 42 | } 43 | 44 | int Command::Value1::get() 45 | { 46 | return instance->value1; 47 | } 48 | 49 | void Command::Value1::set(int value) 50 | { 51 | instance->value1 = value; 52 | } 53 | 54 | int Command::Value2::get() 55 | { 56 | return instance->value2; 57 | } 58 | 59 | void Command::Value2::set(int value) 60 | { 61 | instance->value2 = value; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/Command.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | #include "CommandType.h" 9 | 10 | namespace BroodWar 11 | { 12 | namespace Api 13 | { 14 | namespace Client 15 | { 16 | public ref class Command sealed 17 | { 18 | internal: 19 | BWAPIC::Command* instance; 20 | 21 | Command(BWAPIC::Command command); 22 | ~Command(); 23 | !Command(); 24 | public: 25 | Command(); 26 | Command(CommandType type, int value1, int value2); 27 | property CommandType Type 28 | { 29 | CommandType get(); 30 | void set(CommandType value); 31 | } 32 | property int Value1 33 | { 34 | int get(); 35 | void set(int value); 36 | } 37 | property int Value2 38 | { 39 | int get(); 40 | void set(int value); 41 | } 42 | }; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/CommandType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Client 8 | { 9 | public enum class CommandType 10 | { 11 | None, 12 | SetScreenPosition, 13 | PingMinimap, 14 | EnableFlag, 15 | Printf, 16 | SendText, 17 | ChangeRace, 18 | StartGame, 19 | PauseGame, 20 | ResumeGame, 21 | LeaveGame, 22 | RestartGame, 23 | SetLocalSpeed, 24 | SetLatCom, 25 | SetGui, 26 | SetFrameSkip, 27 | SetMap, 28 | SetAllies, 29 | SetVision, 30 | SetCommandOptimizerLevel, 31 | SetReplayVision, 32 | SetRevealAll, 33 | }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/UnitCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "UnitCommand.h" 2 | 3 | using namespace BroodWar::Api; 4 | 5 | namespace BroodWar 6 | { 7 | namespace Api 8 | { 9 | namespace Client 10 | { 11 | UnitCommand::UnitCommand(BWAPIC::UnitCommand command) 12 | { 13 | instance = new BWAPIC::UnitCommand(command); 14 | } 15 | 16 | UnitCommand::~UnitCommand() 17 | { 18 | delete instance; 19 | } 20 | 21 | UnitCommand::!UnitCommand() 22 | { 23 | delete instance; 24 | } 25 | 26 | UnitCommand::UnitCommand() 27 | { 28 | instance = new BWAPIC::UnitCommand(); 29 | } 30 | 31 | UnitCommandType UnitCommand::CommandType::get() 32 | { 33 | return EnumMapping::UnitCommandType->Managed(instance->type); 34 | } 35 | 36 | void UnitCommand::CommandType::set(UnitCommandType type) 37 | { 38 | instance->type = EnumMapping::UnitCommandType->Native(type); 39 | } 40 | 41 | int UnitCommand::UnitIndex::get() 42 | { 43 | return instance->unitIndex; 44 | } 45 | 46 | void UnitCommand::UnitIndex::set(int value) 47 | { 48 | instance->unitIndex = value; 49 | } 50 | 51 | int UnitCommand::TargetIndex::get() 52 | { 53 | return instance->targetIndex; 54 | } 55 | 56 | void UnitCommand::TargetIndex::set(int value) 57 | { 58 | instance->targetIndex = value; 59 | } 60 | 61 | int UnitCommand::X::get() 62 | { 63 | return instance->x; 64 | } 65 | 66 | void UnitCommand::X::set(int value) 67 | { 68 | instance->x = value; 69 | } 70 | 71 | int UnitCommand::Y::get() 72 | { 73 | return instance->y; 74 | } 75 | 76 | void UnitCommand::Y::set(int value) 77 | { 78 | instance->y = value; 79 | } 80 | 81 | int UnitCommand::Extra::get() 82 | { 83 | return instance->extra; 84 | } 85 | 86 | void UnitCommand::Extra::set(int value) 87 | { 88 | instance->extra = value; 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Client/UnitCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | #include "..\..\EnumMapping.h" 9 | 10 | using namespace BroodWar::Api::Enum; 11 | 12 | namespace BroodWar 13 | { 14 | namespace Api 15 | { 16 | namespace Client 17 | { 18 | public ref class UnitCommand sealed 19 | { 20 | internal: 21 | BWAPIC::UnitCommand* instance; 22 | 23 | UnitCommand(BWAPIC::UnitCommand command); 24 | ~UnitCommand(); 25 | !UnitCommand(); 26 | public: 27 | UnitCommand(); 28 | property UnitCommandType CommandType 29 | { 30 | UnitCommandType get(); 31 | void set(UnitCommandType value); 32 | } 33 | property int UnitIndex 34 | { 35 | int get(); 36 | void set(int value); 37 | } 38 | property int TargetIndex 39 | { 40 | int get(); 41 | void set(int value); 42 | } 43 | property int X 44 | { 45 | int get(); 46 | void set(int value); 47 | } 48 | property int Y 49 | { 50 | int get(); 51 | void set(int value); 52 | } 53 | property int Extra 54 | { 55 | int get(); 56 | void set(int value); 57 | } 58 | }; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/BulletType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class BulletType 10 | { 11 | Melee, 12 | FusionCutterHit, 13 | GaussRifleHit, 14 | C10CanisterRifleHit, 15 | GeminiMissiles, 16 | FragmentationGrenade, 17 | LongboltMissile, 18 | AtsAtaLaserBattery, 19 | BurstLasers, 20 | ArcliteShockCannonHit, 21 | EmpMissile, 22 | DualPhotonBlastersHit, 23 | ParticleBeamHit, 24 | AntiMatterMissile, 25 | PulseCannon, 26 | PsionicShockwaveHit, 27 | PsionicStorm, 28 | YamatoGun, 29 | PhaseDisruptor, 30 | StaStsCannonOverlay, 31 | SunkenColonyTentacle, 32 | AcidSpore, 33 | GlaveWurm, 34 | SeekerSpores, 35 | QueenSpellCarrier, 36 | PlagueCloud, 37 | Consume, 38 | Ensnare, 39 | NeedleSpineHit, 40 | Invisible, 41 | OpticalFlareGrenade, 42 | HaloRockets, 43 | SubterraneanSpines, 44 | CorrosiveAcidShot, 45 | NeutronFlare, 46 | None, 47 | Unknown 48 | }; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/CoordinateType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | // Conversion: 10 | // ShapeType managedST = static_cast(nativeST); 11 | // and vice versa 12 | public enum class CoordinateType 13 | { 14 | /// 15 | /// (0,0) corresponds to the top left corner of the screen 16 | /// 17 | Screen = 1, 18 | 19 | /// 20 | /// (0,0) corresponds to the top left corner of the map 21 | /// 22 | Map = 2, 23 | 24 | /// 25 | /// (0,0) corresponds to the tip of the mouse 26 | /// 27 | Mouse = 3 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/DamageType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class DamageType 10 | { 11 | Independent, 12 | Explosive, 13 | Concussive, 14 | Normal, 15 | IgnoreArmor, 16 | None, 17 | Unknown 18 | }; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/EventType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | //direct mapping 10 | public enum class EventType 11 | { 12 | MatchStart, 13 | MatchEnd, 14 | MatchFrame, 15 | MenuFrame, 16 | SendText, 17 | ReceiveText, 18 | PlayerLeft, 19 | NukeDetect, 20 | UnitDiscover, 21 | UnitEvade, 22 | UnitShow, 23 | UnitHide, 24 | UnitCreate, 25 | UnitDestroy, 26 | UnitMorph, 27 | UnitRenegade, 28 | SaveGame, 29 | UnitComplete, 30 | //TriggerAction, 31 | PlayerDropped, 32 | None 33 | }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/ExplosionType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class ExplosionType 10 | { 11 | None, 12 | Normal, 13 | RadialSplash, 14 | EnemySplash, 15 | Lockdown, 16 | NuclearMissile, 17 | Parasite, 18 | Broodlings, 19 | EmpShockwave, 20 | Irradiate, 21 | Ensnare, 22 | Plague, 23 | StasisField, 24 | DarkSwarm, 25 | Consume, 26 | YamatoGun, 27 | Restoration, 28 | DisruptionWeb, 29 | CorrosiveAcid, 30 | MindControl, 31 | Feedback, 32 | OpticalFlare, 33 | Maelstrom, 34 | AirSplash, 35 | Unknown, 36 | }; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/Flag.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | //direct mapping 10 | public enum class Flag 11 | { 12 | /// 13 | /// Enable to get information about all units on the map, not just the visible units 14 | /// 15 | CompleteMapInformation = 0, 16 | 17 | /// 18 | /// Enable to get information from the user (what units are selected, chat messages the user enters, etc) 19 | /// 20 | UserInput = 1, 21 | 22 | Max 23 | }; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/GameType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class GameType 10 | { 11 | Melee, 12 | FreeForAll, 13 | OneOnOne, 14 | CaptureTheFlag, 15 | Greed, 16 | Slaughter, 17 | SuddenDeath, 18 | Ladder, 19 | UseMapSettings, 20 | TeamMelee, 21 | TeamFreeForAll, 22 | TeamCaptureTheFlag, 23 | TopVsBottom, 24 | None, 25 | Unknown, 26 | }; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/Latency.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | //direct mapping 10 | public enum class Latency 11 | { 12 | SinglePlayer = 2, 13 | LanLow = 5, 14 | LanMedium = 7, 15 | LanHigh = 9, 16 | BattlenetLow = 14, 17 | BattlenetMedium = 19, 18 | BattlenetHigh = 24 19 | }; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/MouseButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class MouseButton 10 | { 11 | Left = 0, 12 | Right = 1, 13 | Middle = 2, 14 | Max 15 | }; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/OrderType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class OrderType 10 | { 11 | Die, 12 | Stop, 13 | Guard, 14 | PlayerGuard, 15 | TurretGuard, 16 | BunkerGuard, 17 | Move, 18 | AttackUnit, 19 | AttackTile, 20 | Hover, 21 | AttackMove, 22 | InfestedCommandCenter, 23 | UnusedNothing, 24 | UnusedPowerup, 25 | TowerGuard, 26 | VultureMine, 27 | Nothing, 28 | CastInfestation, 29 | InfestingCommandCenter, 30 | PlaceBuilding, 31 | CreateProtossBuilding, 32 | ConstructingBuilding, 33 | Repair, 34 | PlaceAddon, 35 | BuildAddon, 36 | Train, 37 | RallyPointUnit, 38 | RallyPointTile, 39 | ZergBirth, 40 | ZergUnitMorph, 41 | ZergBuildingMorph, 42 | IncompleteBuilding, 43 | BuildNydusExit, 44 | EnterNydusCanal, 45 | Follow, 46 | Carrier, 47 | ReaverCarrierMove, 48 | CarrierIgnore2, 49 | Reaver, 50 | TrainFighter, 51 | InterceptorAttack, 52 | ScarabAttack, 53 | RechargeShieldsUnit, 54 | RechargeShieldsBattery, 55 | ShieldBattery, 56 | InterceptorReturn, 57 | BuildingLand, 58 | BuildingLiftOff, 59 | DroneLiftOff, 60 | LiftingOff, 61 | ResearchTech, 62 | Upgrade, 63 | Larva, 64 | SpawningLarva, 65 | Harvest1, 66 | Harvest2, 67 | MoveToGas, 68 | WaitForGas, 69 | HarvestGas, 70 | ReturnGas, 71 | MoveToMinerals, 72 | WaitForMinerals, 73 | MiningMinerals, 74 | Harvest3, 75 | Harvest4, 76 | ReturnMinerals, 77 | Interrupted, 78 | EnterTransport, 79 | PickupIdle, 80 | PickupTransport, 81 | PickupBunker, 82 | Pickup4, 83 | PowerupIdle, 84 | Sieging, 85 | Unsieging, 86 | InitCreepGrowth, 87 | SpreadCreep, 88 | StoppingCreepGrowth, 89 | GuardianAspect, 90 | ArchonWarp, 91 | CompletingArchonSummon, 92 | HoldPosition, 93 | Cloak, 94 | Decloak, 95 | Unload, 96 | MoveUnload, 97 | FireYamatoGun, 98 | CastLockdown, 99 | Burrowing, 100 | Burrowed, 101 | Unburrowing, 102 | CastDarkSwarm, 103 | CastParasite, 104 | CastSpawnBroodlings, 105 | CastEmpShockwave, 106 | NukeWait, 107 | NukeTrain, 108 | NukeLaunch, 109 | NukePaint, 110 | NukeUnit, 111 | CastNuclearStrike, 112 | NukeTrack, 113 | CloakNearbyUnits, 114 | PlaceMine, 115 | RightClickAction, 116 | CastRecall, 117 | Teleport, 118 | CastScannerSweep, 119 | Scanner, 120 | CastDefensiveMatrix, 121 | CastPsionicStorm, 122 | CastIrradiate, 123 | CastPlague, 124 | CastConsume, 125 | CastEnsnare, 126 | CastStasisField, 127 | CastHallucination, 128 | Hallucination2, 129 | ResetCollision, 130 | Patrol, 131 | CtfcopInit, 132 | CtfcopStarted, 133 | Ctfcop2, 134 | ComputerAi, 135 | AtkMoveEp, 136 | HarassMove, 137 | AiPatrol, 138 | GuardPost, 139 | RescuePassive, 140 | Neutral, 141 | ComputerReturn, 142 | SelfDestructing, 143 | Critter, 144 | HiddenGun, 145 | OpenDoor, 146 | CloseDoor, 147 | HideTrap, 148 | RevealTrap, 149 | EnableDoodad, 150 | DisableDoodad, 151 | WarpIn, 152 | Medic, 153 | MedicHeal, 154 | HealMove, 155 | MedicHealToIdle, 156 | CastRestoration, 157 | CastDisruptionWeb, 158 | CastMindControl, 159 | DarkArchonMeld, 160 | CastFeedback, 161 | CastOpticalFlare, 162 | CastMaelstrom, 163 | JunkYardDog, 164 | Fatal, 165 | None, 166 | Unknown, 167 | }; 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/PlayerType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class PlayerType 10 | { 11 | None, 12 | Computer, 13 | Player, 14 | RescuePassive, 15 | EitherPreferComputer, 16 | EitherPreferHuman, 17 | Neutral, 18 | Closed, 19 | PlayerLeft, 20 | ComputerLeft, 21 | Unknown, 22 | }; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/RaceType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class RaceType 10 | { 11 | Zerg, 12 | Terran, 13 | Protoss, 14 | Random, 15 | None, 16 | Unknown, 17 | }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/Targets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | [System::Flags] 10 | public enum class Targets 11 | { 12 | None = 0x0, 13 | Air = 0x1, 14 | Ground = 0x2, 15 | Mechanical = 0x4, 16 | Organic = 0x8, 17 | NonBuilding = 0x10, 18 | NonRobotic = 0x20, 19 | Terrain = 0x40, 20 | OrgOrMech = 0x80, 21 | Own = 0x100 22 | }; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/TechType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class TechType 10 | { 11 | Stim_Packs, 12 | Lockdown, 13 | EMP_Shockwave, 14 | Spider_Mines, 15 | Scanner_Sweep, 16 | Tank_Siege_Mode, 17 | Defensive_Matrix, 18 | Irradiate, 19 | Yamato_Gun, 20 | Cloaking_Field, 21 | Personnel_Cloaking, 22 | Burrowing, 23 | Infestation, 24 | Spawn_Broodlings, 25 | Dark_Swarm, 26 | Plague, 27 | Consume, 28 | Ensnare, 29 | Parasite, 30 | Psionic_Storm, 31 | Hallucination, 32 | Recall, 33 | Stasis_Field, 34 | Archon_Warp, 35 | Restoration, 36 | Disruption_Web, 37 | Mind_Control, 38 | Dark_Archon_Meld, 39 | Feedback, 40 | Optical_Flare, 41 | Maelstrom, 42 | Lurker_Aspect, 43 | Healing, 44 | None, 45 | Unknown, 46 | Nuclear_Strike, 47 | }; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/TournamentAction.h: -------------------------------------------------------------------------------- 1 | namespace BroodWar 2 | { 3 | namespace Api 4 | { 5 | namespace Enum 6 | { 7 | public enum class TournamentAction 8 | { 9 | EnableFlag, 10 | ChangeRace, 11 | StartGame, 12 | PauseGame, 13 | ResumeGame, 14 | LeaveGame, 15 | RestartGame, 16 | SetLocalSpeed, 17 | SetTextSize, 18 | SetLatCom, 19 | SetGUI, 20 | SetMap, 21 | SetFrameSkip, 22 | Printf, 23 | SendText, 24 | SetCommandOptimizationLevel 25 | }; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/UnitCommandType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class UnitCommandType 10 | { 11 | AttackMove, 12 | AttackUnit, 13 | Build, 14 | BuildAddon, 15 | Train, 16 | Morph, 17 | Research, 18 | Upgrade, 19 | SetRallyPosition, 20 | SetRallyUnit, 21 | Move, 22 | Patrol, 23 | HoldPosition, 24 | Stop, 25 | Follow, 26 | Gather, 27 | ReturnCargo, 28 | Repair, 29 | Burrow, 30 | Unburrow, 31 | Cloak, 32 | Decloak, 33 | Siege, 34 | Unsiege, 35 | Lift, 36 | Land, 37 | Load, 38 | Unload, 39 | UnloadAll, 40 | UnloadAllPosition, 41 | RightClickPosition, 42 | RightClickUnit, 43 | HaltConstruction, 44 | CancelConstruction, 45 | CancelAddon, 46 | CancelTrain, 47 | CancelTrainSlot, 48 | CancelMorph, 49 | CancelResearch, 50 | CancelUpgrade, 51 | UseTech, 52 | UseTechPosition, 53 | UseTechUnit, 54 | PlaceCop, 55 | None, 56 | Unknown 57 | }; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/UnitSizeType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class UnitSizeType 10 | { 11 | Independent, 12 | Small, 13 | Medium, 14 | Large, 15 | None, 16 | Unknown, 17 | }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/UpgradeType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class UpgradeType 10 | { 11 | Terran_Infantry_Armor, 12 | Terran_Vehicle_Plating, 13 | Terran_Ship_Plating, 14 | Zerg_Carapace, 15 | Zerg_Flyer_Carapace, 16 | Protoss_Ground_Armor, 17 | Protoss_Air_Armor, 18 | Terran_Infantry_Weapons, 19 | Terran_Vehicle_Weapons, 20 | Terran_Ship_Weapons, 21 | Zerg_Melee_Attacks, 22 | Zerg_Missile_Attacks, 23 | Zerg_Flyer_Attacks, 24 | Protoss_Ground_Weapons, 25 | Protoss_Air_Weapons, 26 | Protoss_Plasma_Shields, 27 | U_238_Shells, 28 | Ion_Thrusters, 29 | Titan_Reactor, 30 | Ocular_Implants, 31 | Moebius_Reactor, 32 | Apollo_Reactor, 33 | Colossus_Reactor, 34 | Ventral_Sacs, 35 | Antennae, 36 | Pneumatized_Carapace, 37 | Metabolic_Boost, 38 | Adrenal_Glands, 39 | Muscular_Augments, 40 | Grooved_Spines, 41 | Gamete_Meiosis, 42 | Metasynaptic_Node, 43 | Singularity_Charge, 44 | Leg_Enhancements, 45 | Scarab_Damage, 46 | Reaver_Capacity, 47 | Gravitic_Drive, 48 | Sensor_Array, 49 | Gravitic_Boosters, 50 | Khaydarin_Amulet, 51 | Apial_Sensors, 52 | Gravitic_Thrusters, 53 | Carrier_Capacity, 54 | Khaydarin_Core, 55 | Argus_Jewel, 56 | Argus_Talisman, 57 | Caduceus_Reactor, 58 | Chitinous_Plating, 59 | Anabolic_Synthesis, 60 | Charon_Boosters, 61 | None, 62 | Unknown, 63 | }; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Enum/WeaponType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | namespace Enum 8 | { 9 | public enum class WeaponType 10 | { 11 | Gauss_Rifle, 12 | Gauss_Rifle_Jim_Raynor, 13 | C_10_Canister_Rifle, 14 | C_10_Canister_Rifle_Sarah_Kerrigan, 15 | C_10_Canister_Rifle_Samir_Duran, 16 | C_10_Canister_Rifle_Infested_Duran, 17 | C_10_Canister_Rifle_Alexei_Stukov, 18 | Fragmentation_Grenade, 19 | Fragmentation_Grenade_Jim_Raynor, 20 | Spider_Mines, 21 | Twin_Autocannons, 22 | Twin_Autocannons_Alan_Schezar, 23 | Hellfire_Missile_Pack, 24 | Hellfire_Missile_Pack_Alan_Schezar, 25 | Arclite_Cannon, 26 | Arclite_Cannon_Edmund_Duke, 27 | Fusion_Cutter, 28 | Gemini_Missiles, 29 | Gemini_Missiles_Tom_Kazansky, 30 | Burst_Lasers, 31 | Burst_Lasers_Tom_Kazansky, 32 | ATS_Laser_Battery, 33 | ATS_Laser_Battery_Hero, 34 | ATS_Laser_Battery_Hyperion, 35 | ATA_Laser_Battery, 36 | ATA_Laser_Battery_Hero, 37 | ATA_Laser_Battery_Hyperion, 38 | Flame_Thrower, 39 | Flame_Thrower_Gui_Montag, 40 | Arclite_Shock_Cannon, 41 | Arclite_Shock_Cannon_Edmund_Duke, 42 | Longbolt_Missile, 43 | Claws, 44 | Claws_Devouring_One, 45 | Claws_Infested_Kerrigan, 46 | Needle_Spines, 47 | Needle_Spines_Hunter_Killer, 48 | Kaiser_Blades, 49 | Kaiser_Blades_Torrasque, 50 | Toxic_Spores, 51 | Spines, 52 | Acid_Spore, 53 | Acid_Spore_Kukulza, 54 | Glave_Wurm, 55 | Glave_Wurm_Kukulza, 56 | Seeker_Spores, 57 | Subterranean_Tentacle, 58 | Suicide_Infested_Terran, 59 | Suicide_Scourge, 60 | Particle_Beam, 61 | Psi_Blades, 62 | Psi_Blades_Fenix, 63 | Phase_Disruptor, 64 | Phase_Disruptor_Fenix, 65 | Psi_Assault, 66 | Psionic_Shockwave, 67 | Psionic_Shockwave_TZ_Archon, 68 | Dual_Photon_Blasters, 69 | Dual_Photon_Blasters_Mojo, 70 | Dual_Photon_Blasters_Artanis, 71 | Anti_Matter_Missiles, 72 | Anti_Matter_Missiles_Mojo, 73 | Anti_Matter_Missiles_Artanis, 74 | Phase_Disruptor_Cannon, 75 | Phase_Disruptor_Cannon_Danimoth, 76 | Pulse_Cannon, 77 | STS_Photon_Cannon, 78 | STA_Photon_Cannon, 79 | Scarab, 80 | Neutron_Flare, 81 | Halo_Rockets, 82 | Corrosive_Acid, 83 | Subterranean_Spines, 84 | Warp_Blades, 85 | Warp_Blades_Hero, 86 | Warp_Blades_Zeratul, 87 | Independant_Laser_Battery, 88 | Twin_Autocannons_Floor_Trap, 89 | Hellfire_Missile_Pack_Wall_Trap, 90 | Flame_Thrower_Wall_Trap, 91 | Hellfire_Missile_Pack_Floor_Trap, 92 | 93 | Yamato_Gun, 94 | Nuclear_Strike, 95 | Lockdown, 96 | EMP_Shockwave, 97 | Irradiate, 98 | Parasite, 99 | Spawn_Broodlings, 100 | Ensnare, 101 | Dark_Swarm, 102 | Plague, 103 | Consume, 104 | Stasis_Field, 105 | Psionic_Storm, 106 | Disruption_Web, 107 | Restoration, 108 | Mind_Control, 109 | Feedback, 110 | Optical_Flare, 111 | Maelstrom, 112 | 113 | None, 114 | Unknown, 115 | }; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | #include "Enum\EventType.h" 9 | #include "Player.h" 10 | #include "Unit.h" 11 | #include "Position.h" 12 | 13 | using namespace System; 14 | 15 | namespace BroodWar 16 | { 17 | namespace Api 18 | { 19 | public ref class Event sealed 20 | { 21 | internal: 22 | BWAPI::Event* instance; 23 | bool dispose; 24 | 25 | Event(BWAPI::Event* ev); 26 | Event(BWAPI::Event ev); 27 | ~Event(); 28 | !Event(); 29 | 30 | public: 31 | Event(); 32 | Event(Event^ copy); 33 | 34 | property EventType Type 35 | { 36 | EventType get(); 37 | void set(EventType value); 38 | } 39 | property Api::Position^ Position 40 | { 41 | Api::Position^ get(); 42 | void set(Api::Position^ value); 43 | } 44 | property String^ Text 45 | { 46 | String^ get(); 47 | void set(String^ value); 48 | } 49 | property Api::Unit^ Unit 50 | { 51 | Api::Unit^ get(); 52 | void set(Api::Unit^ value); 53 | } 54 | property Api::Player^ Player 55 | { 56 | Api::Player^ get(); 57 | void set(Api::Player^ value); 58 | } 59 | property bool IsWinner 60 | { 61 | bool get(); 62 | void set(bool value); 63 | } 64 | 65 | static Event^ MatchStart(); 66 | static Event^ MatchEnd(bool isWinner); 67 | static Event^ MatchFrame(); 68 | static Event^ MenuFrame(); 69 | static Event^ SendText(String^ text); 70 | static Event^ ReceiveText(Api::Player^ player, String^ text); 71 | static Event^ PlayerLeft(Api::Player^ player); 72 | static Event^ NukeDetect(Api::Position^ target); 73 | static Event^ UnitDiscover(Api::Unit^ unit); 74 | static Event^ UnitEvade(Api::Unit^ unit); 75 | static Event^ UnitShow(Api::Unit^ unit); 76 | static Event^ UnitHide(Api::Unit^ unit); 77 | static Event^ UnitCreate(Api::Unit^ unit); 78 | static Event^ UnitDestroy(Api::Unit^ unit); 79 | static Event^ UnitMorph(Api::Unit^ unit); 80 | static Event^ UnitRenegade(Api::Unit^ unit); 81 | static Event^ SaveGame(String^ gameName); 82 | static Event^ UnitComplete(Api::Unit^ unit); 83 | 84 | static bool operator == (Api::Event^ first, Api::Event^ second); 85 | static bool operator != (Api::Event^ first, Api::Event^ second); 86 | }; 87 | 88 | Event^ ConvertEvent(BWAPI::Event ev); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Force.cpp: -------------------------------------------------------------------------------- 1 | #include "Force.h" 2 | #include "Player.h" 3 | #include "..\Util.h" 4 | 5 | using namespace BroodWar; 6 | 7 | namespace BroodWar 8 | { 9 | namespace Api 10 | { 11 | Force^ ConvertForce(BWAPI::Force force) 12 | { 13 | if(force == NULL) 14 | return nullptr; 15 | return gcnew Force(force); 16 | } 17 | 18 | Force::Force(BWAPI::Force force) 19 | { 20 | instance = force; 21 | } 22 | 23 | int Force::Id::get() 24 | { 25 | return instance->getID(); 26 | } 27 | 28 | String^ Force::Name::get() 29 | { 30 | return gcnew String(instance->getName().c_str()); 31 | } 32 | 33 | HashSet^ Force::Players::get() 34 | { 35 | return ToHashSet(instance->getPlayers(), &ConvertPlayer); 36 | } 37 | 38 | int Force::GetHashCode() 39 | { 40 | return instance->getID(); 41 | } 42 | 43 | bool Force::Equals(Object^ o) 44 | { 45 | Force^ other = dynamic_cast(o); 46 | return this->Equals(other); 47 | } 48 | 49 | bool Force::Equals(Api::Force^ other) 50 | { 51 | if(ReferenceEquals(nullptr, other)) 52 | return false; 53 | if(ReferenceEquals(this, other)) 54 | return true; 55 | return this->instance->getID() == other->instance->getID(); 56 | } 57 | 58 | bool Force::operator == (Api::Force^ first, Api::Force^ second) 59 | { 60 | if(ReferenceEquals(first, second)) 61 | return true; 62 | if(ReferenceEquals(nullptr, first)) 63 | return false; 64 | return first->Equals(second); 65 | } 66 | 67 | bool Force::operator != (Api::Force^ first, Api::Force^ second) 68 | { 69 | return !(first == second); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Force.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | #include 6 | 7 | #pragma managed 8 | 9 | #include "IIdentifiedObject.h" 10 | 11 | using namespace System; 12 | using namespace System::Collections::Generic; 13 | 14 | namespace BroodWar 15 | { 16 | namespace Api 17 | { 18 | ref class Player; 19 | 20 | public ref class Force sealed : public IIdentifiedObject 21 | { 22 | private: 23 | BWAPI::Force instance; 24 | 25 | internal: 26 | Force(BWAPI::Force force); 27 | 28 | public: 29 | virtual property int Id { int get(); } 30 | property String^ Name { String^ get(); } 31 | property HashSet^ Players { HashSet^ get(); } 32 | 33 | virtual int GetHashCode() override; 34 | virtual bool Equals(Object^ o) override; 35 | bool Equals(Api::Force^ other); 36 | 37 | static bool operator == (Api::Force^ first, Api::Force^ second); 38 | static bool operator != (Api::Force^ first, Api::Force^ second); 39 | }; 40 | 41 | Force^ ConvertForce(BWAPI::Force force); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/IIdentifiedObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma managed 4 | 5 | namespace BroodWar 6 | { 7 | namespace Api 8 | { 9 | public interface class IIdentifiedObject 10 | { 11 | property int Id { int get(); } 12 | }; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Position.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | //#pragma make_public(BWAPI::Point) 6 | 7 | #pragma managed 8 | 9 | namespace BroodWar 10 | { 11 | // Can't use templates, because they're hard to consume in C# 12 | // Can't use generics, because BWAPI::Point needs to be hidden away 13 | // Probably should codegen somehow, to keep the copies in sync 14 | namespace Api 15 | { 16 | ref class TilePosition; 17 | ref class WalkPosition; 18 | 19 | public ref class Position 20 | { 21 | internal: 22 | BWAPI::Position *instance; 23 | bool dispose; 24 | 25 | Position(BWAPI::Position *position, bool takeOwnership); 26 | Position(BWAPI::Position position); 27 | ~Position(); 28 | !Position(); 29 | 30 | public: 31 | Position(); 32 | Position(Position^ copy); 33 | Position(int x, int y); 34 | 35 | property int X { int get(); } 36 | property int Y { int get(); } 37 | property bool IsValid { bool get(); } 38 | double CalcDistance(Position^ position); 39 | int CalcApproximateDistance(Position^ position); 40 | double CalcLength(); 41 | void MakeValid(); 42 | property bool IsInvalid { bool get(); } 43 | property bool IsNone { bool get(); } 44 | property bool IsUnknown { bool get(); } 45 | 46 | virtual int GetHashCode() override; 47 | virtual bool Equals(Object^ o) override; 48 | bool Equals(Position^ other); 49 | 50 | static bool operator == (Position^ first, Position^ second); 51 | static bool operator != (Position^ first, Position^ second); 52 | static bool operator < (Position^ first, Position^ second); 53 | static Position^ operator + (Position^ first, Position^ second); 54 | static Position^ operator - (Position^ first, Position^ second); 55 | static Position^ operator * (Position^ first, int second); 56 | static Position^ operator / (Position^ first, int second); 57 | static Position^ operator += (Position^ first, Position^ second); 58 | static Position^ operator -= (Position^ first, Position^ second); 59 | static Position^ operator *= (Position^ first, int second); 60 | static Position^ operator /= (Position^ first, int second); 61 | 62 | static Position^ Rescale(TilePosition^ position); 63 | static Position^ Rescale(WalkPosition^ position); 64 | }; 65 | 66 | BWAPI::Position ConvertPosition(Position^ position); 67 | Position^ ConvertPosition(BWAPI::Position position); 68 | Position^ ConvertPosition(BWAPI::Position* position); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Price.cpp: -------------------------------------------------------------------------------- 1 | #include "Price.h" 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | Price::Price(int minerals, int gas, int timeFrames, int supply) 8 | { 9 | _minerals = minerals; 10 | _gas = gas; 11 | _timeFrames = timeFrames; 12 | _supply = supply; 13 | } 14 | 15 | int Price::Minerals::get() 16 | { 17 | return _minerals; 18 | } 19 | 20 | int Price::Gas::get() 21 | { 22 | return _gas; 23 | } 24 | 25 | int Price::TimeFrames::get() 26 | { 27 | return _timeFrames; 28 | } 29 | 30 | int Price::Supply::get() 31 | { 32 | return _supply; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Price.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Api 6 | { 7 | public ref class Price sealed 8 | { 9 | private: 10 | int _minerals, _gas, _timeFrames, _supply; 11 | public: 12 | Price(int minerals, int gas, int timeFrames, int supply); 13 | 14 | property int Minerals { int get(); } 15 | 16 | property int Gas { int get(); } 17 | 18 | property int TimeFrames { int get(); } 19 | 20 | property int Supply { int get(); } 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Race.cpp: -------------------------------------------------------------------------------- 1 | #include "Race.h" 2 | #include "UnitType.h" 3 | 4 | #include "..\EnumMapping.h" 5 | #include "..\Util.h" 6 | 7 | namespace BroodWar 8 | { 9 | namespace Api 10 | { 11 | Race^ ConvertRace(BWAPI::Race* race) 12 | { 13 | if(race == NULL) 14 | return nullptr; 15 | return gcnew Race(race); 16 | } 17 | 18 | Race^ ConvertRace(BWAPI::Race race) 19 | { 20 | return gcnew Race(race); 21 | } 22 | 23 | BWAPI::Race ConvertRace(Race^ race) 24 | { 25 | if(race == nullptr) 26 | return BWAPI::Race(); 27 | return BWAPI::Race(*(race->instance)); 28 | } 29 | 30 | Race::Race(Api::Enum::RaceType race) 31 | { 32 | instance = EnumMapping::RaceType->NativePointer(race); 33 | dispose = true; 34 | } 35 | 36 | Race::Race(BWAPI::Race* race) 37 | { 38 | instance = race; 39 | dispose = false; 40 | } 41 | 42 | Race::Race(BWAPI::Race race) 43 | { 44 | instance = new BWAPI::Race(race); 45 | dispose = true; 46 | } 47 | 48 | Race::~Race() 49 | { 50 | if(dispose) 51 | delete instance; 52 | } 53 | 54 | Race::!Race() 55 | { 56 | if(dispose) 57 | delete instance; 58 | } 59 | 60 | Race::Race() 61 | { 62 | instance = new BWAPI::Race(); 63 | dispose = true; 64 | } 65 | 66 | Race::Race(int id) 67 | { 68 | instance = new BWAPI::Race(id); 69 | dispose = true; 70 | } 71 | 72 | int Race::Id::get() 73 | { 74 | return instance->getID(); 75 | } 76 | 77 | System::String^ Race::ToString() 78 | { 79 | return gcnew System::String(instance->c_str()); 80 | } 81 | 82 | Api::Enum::RaceType Race::Type::get() 83 | { 84 | return EnumMapping::RaceType->Managed(instance); 85 | } 86 | 87 | bool Race::TypeEquals(Api::Enum::RaceType raceType) 88 | { 89 | return Type == raceType; 90 | } 91 | 92 | Api::UnitType^ Race::Worker::get() 93 | { 94 | return ConvertUnitType(instance->getWorker()); 95 | } 96 | 97 | Api::UnitType^ Race::Center::get() 98 | { 99 | return ConvertUnitType(instance->getCenter()); 100 | } 101 | 102 | Api::UnitType^ Race::Refinery::get() 103 | { 104 | return ConvertUnitType(instance->getRefinery()); 105 | } 106 | 107 | Api::UnitType^ Race::Transport::get() 108 | { 109 | return ConvertUnitType(instance->getTransport()); 110 | } 111 | 112 | Api::UnitType^ Race::SupplyProvider::get() 113 | { 114 | return ConvertUnitType(instance->getSupplyProvider()); 115 | } 116 | 117 | int Race::GetHashCode() 118 | { 119 | return instance->getID(); 120 | } 121 | 122 | bool Race::Equals(Object^ o) 123 | { 124 | Api::Race^ other = dynamic_cast(o); 125 | return this->Equals(other); 126 | } 127 | 128 | bool Race::Equals(Race^ other) 129 | { 130 | if(ReferenceEquals(nullptr, other)) 131 | return false; 132 | if(ReferenceEquals(this, other)) 133 | return true; 134 | return this->instance->getID() == other->instance->getID(); 135 | } 136 | 137 | List^ Race::AllRaces::get() 138 | { 139 | return ToList(BWAPI::Races::allRaces(), &ConvertRace); 140 | } 141 | 142 | bool Race::operator == (Race^ first, Race^ second) 143 | { 144 | if(ReferenceEquals(first, second)) 145 | return true; 146 | if(ReferenceEquals(nullptr, first)) 147 | return false; 148 | return first->Equals(second); 149 | } 150 | 151 | bool Race::operator != (Race^ first, Race^ second) 152 | { 153 | return !(first == second); 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Race.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | #include "IIdentifiedObject.h" 9 | #include "Enum\RaceType.h" 10 | 11 | using namespace System; 12 | using namespace System::Collections::Generic; 13 | using namespace BroodWar::Api::Enum; 14 | 15 | namespace BroodWar 16 | { 17 | namespace Api 18 | { 19 | ref class UnitType; 20 | 21 | public ref class Race : public IIdentifiedObject 22 | { 23 | internal: 24 | BWAPI::Race* instance; 25 | bool dispose; 26 | 27 | Race(RaceType race); 28 | Race(BWAPI::Race* race); 29 | Race(BWAPI::Race race); 30 | ~Race(); 31 | !Race(); 32 | 33 | public: 34 | Race(); 35 | 36 | Race(int id); 37 | 38 | virtual property int Id { int get(); } 39 | 40 | /// 41 | /// Returns the name of the race. For example Races::Terran.getName() will return a std::string object containing "Terran" 42 | /// 43 | virtual String^ ToString() override; 44 | 45 | property RaceType Type { RaceType get(); } 46 | 47 | bool TypeEquals(RaceType raceType); 48 | 49 | /// 50 | /// Returns the worker unit type for the given race. For example Races::Protoss.getWorker() will return a pointer to UnitTypes::Protoss_Probe 51 | /// 52 | property UnitType^ Worker { UnitType^ get(); } 53 | 54 | /// 55 | /// Returns the center unit type for the given race. For example Races::Terran.getCenter() will return a pointer to UnitTypes::Terran_Command_Center. 56 | /// While there are three center types for Zerg (Hatchery, Lair, and Hive), Races::Zerg.getCenter() will only return a pointer to UnitTypes::Zerg_Hatchery, 57 | /// since it is the unit type needed to make a new center 58 | /// 59 | property UnitType^ Center { UnitType^ get(); } 60 | 61 | /// 62 | /// Returns the refinery unit type for the given race. For example: Races::Zerg.getRefinery() will return a pointer to UnitTypes::Zerg_Extractor? 63 | /// 64 | property UnitType^ Refinery { UnitType^ get(); } 65 | 66 | /// 67 | /// Returns the transport unit type for the given race. For example: Races::Protoss.getTransport() will return a pointer to UnitTypes::Protoss_Shuttle 68 | /// 69 | property UnitType^ Transport { UnitType^ get(); } 70 | 71 | /// 72 | /// Returns the main supply provider unit type for the given race. For example: Races::Terran.getSupplyProvider() will return a pointer to 73 | /// UnitTypes::Terran_Supply_Depot? 74 | /// 75 | property UnitType^ SupplyProvider { UnitType^ get(); } 76 | 77 | virtual int GetHashCode() override; 78 | virtual bool Equals(Object^ o) override; 79 | bool Equals(Race^ other); 80 | 81 | static property List^ AllRaces { List^ get(); } 82 | 83 | static bool operator == (Race^ first, Race^ second); 84 | static bool operator != (Race^ first, Race^ second); 85 | }; 86 | 87 | Race^ ConvertRace(BWAPI::Race* race); 88 | Race^ ConvertRace(BWAPI::Race race); 89 | BWAPI::Race ConvertRace(Race^ race); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Region.cpp: -------------------------------------------------------------------------------- 1 | #include "Region.h" 2 | #include "..\Util.h" 3 | 4 | using namespace BroodWar; 5 | 6 | namespace BroodWar 7 | { 8 | namespace Api 9 | { 10 | Region^ ConvertRegion(BWAPI::Region region) 11 | { 12 | if(region == NULL) 13 | return nullptr; 14 | return gcnew Region(region); 15 | } 16 | 17 | Region::Region(BWAPI::Region region) 18 | { 19 | instance = region; 20 | } 21 | 22 | int Region::Id::get() 23 | { 24 | return instance->getID(); 25 | } 26 | 27 | int Region::RegionGroupId::get() 28 | { 29 | return instance->getRegionGroupID(); 30 | } 31 | 32 | Position^ Region::Center::get() 33 | { 34 | return ConvertPosition(instance->getCenter()); 35 | } 36 | 37 | bool Region::IsHigherGround::get() 38 | { 39 | return instance->isHigherGround(); 40 | } 41 | 42 | int Region::DefensePriority::get() 43 | { 44 | return instance->getDefensePriority(); 45 | } 46 | 47 | bool Region::IsAccessible::get() 48 | { 49 | return instance->isAccessible(); 50 | } 51 | 52 | HashSet^ Region::Neighbours::get() 53 | { 54 | return ToHashSet(instance->getNeighbors(), &ConvertRegion); 55 | } 56 | 57 | Rectangle Region::Bounds::get() 58 | { 59 | return System::Drawing::Rectangle( 60 | instance->getBoundsLeft(), 61 | instance->getBoundsTop(), 62 | instance->getBoundsRight() - instance->getBoundsLeft(), 63 | instance->getBoundsBottom() - instance->getBoundsTop()); 64 | } 65 | 66 | Region^ Region::ClosestAccessibleRegion::get() 67 | { 68 | return ConvertRegion(instance->getClosestAccessibleRegion()); 69 | } 70 | 71 | Region^ Region::ClosestInaccessibleRegion::get() 72 | { 73 | return ConvertRegion(instance->getClosestInaccessibleRegion()); 74 | } 75 | 76 | int Region::DistanceTo(Region^ region) 77 | { 78 | return instance->getDistance(region->instance); 79 | } 80 | 81 | int Region::GetHashCode() 82 | { 83 | return instance->getID(); 84 | } 85 | 86 | bool Region::Equals(Object^ o) 87 | { 88 | Region^ other = dynamic_cast(o); 89 | return this->Equals(other); 90 | } 91 | 92 | bool Region::Equals(Region^ other) 93 | { 94 | if(ReferenceEquals(nullptr, other)) 95 | return false; 96 | if(ReferenceEquals(this, other)) 97 | return true; 98 | return this->instance->getID() == other->instance->getID(); 99 | } 100 | 101 | bool Region::operator == (Region^ first, Region^ second) 102 | { 103 | if(ReferenceEquals(first, second)) 104 | return true; 105 | if(ReferenceEquals(nullptr, first)) 106 | return false; 107 | return first->Equals(second); 108 | } 109 | 110 | bool Region::operator != (Region^ first, Region^ second) 111 | { 112 | return !(first == second); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Region.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | #include 6 | 7 | #pragma managed 8 | 9 | #include "IIdentifiedObject.h" 10 | #include "Position.h" 11 | 12 | using namespace System::Collections::Generic; 13 | using namespace System::Drawing; 14 | 15 | namespace BroodWar 16 | { 17 | namespace Api 18 | { 19 | public ref class Region sealed : public IIdentifiedObject 20 | { 21 | internal: 22 | BWAPI::Region instance; 23 | 24 | Region(BWAPI::Region region); 25 | 26 | public: 27 | virtual property int Id { int get(); } 28 | property int RegionGroupId { int get(); } 29 | property Position^ Center { Position^ get(); } 30 | property bool IsHigherGround { bool get(); } 31 | property int DefensePriority { int get(); } 32 | property bool IsAccessible { bool get(); } 33 | property HashSet^ Neighbours { HashSet^ get(); } 34 | property System::Drawing::Rectangle Bounds { System::Drawing::Rectangle get(); } 35 | property Region^ ClosestAccessibleRegion { Region^ get(); } 36 | property Region^ ClosestInaccessibleRegion { Region^ get(); } 37 | int DistanceTo(Region^ region); 38 | 39 | virtual int GetHashCode() override; 40 | virtual bool Equals(Object^ o) override; 41 | bool Equals(Region^ other); 42 | 43 | static bool operator == (Region^ first, Region^ second); 44 | static bool operator != (Region^ first, Region^ second); 45 | }; 46 | 47 | Region^ ConvertRegion(BWAPI::Region region); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Tech.cpp: -------------------------------------------------------------------------------- 1 | #include "Tech.h" 2 | #include "Race.h" 3 | #include "Weapon.h" 4 | #include "UnitType.h" 5 | 6 | #include "..\EnumMapping.h" 7 | #include "..\Util.h" 8 | 9 | using namespace System::Collections::Generic; 10 | using namespace BroodWar; 11 | 12 | namespace BroodWar 13 | { 14 | namespace Api 15 | { 16 | Tech^ ConvertTech(BWAPI::TechType tech) 17 | { 18 | return gcnew Tech(tech); 19 | } 20 | 21 | BWAPI::TechType ConvertTech(Tech^ tech) 22 | { 23 | if(tech == nullptr) 24 | return BWAPI::TechType(); 25 | return BWAPI::TechType(*(tech->instance)); 26 | } 27 | 28 | BWAPI::TechType ConvertTech(TechType tech) 29 | { 30 | return EnumMapping::TechType->Native(tech); 31 | } 32 | 33 | Tech::Tech(Api::Enum::TechType type) 34 | { 35 | instance = EnumMapping::TechType->NativePointer(type); 36 | dispose = true; 37 | } 38 | 39 | Tech::Tech(BWAPI::TechType *type) 40 | { 41 | instance = type; 42 | dispose = false; 43 | } 44 | 45 | Tech::Tech(BWAPI::TechType type) 46 | { 47 | instance = new BWAPI::TechType(type); 48 | dispose = true; 49 | } 50 | 51 | Tech::~Tech() 52 | { 53 | if(dispose) 54 | delete instance; 55 | } 56 | 57 | Tech::!Tech() 58 | { 59 | if(dispose) 60 | delete instance; 61 | } 62 | 63 | Tech::Tech() 64 | { 65 | instance = new BWAPI::TechType(); 66 | dispose = true; 67 | } 68 | 69 | Tech::Tech(int id) 70 | { 71 | instance = new BWAPI::TechType(id); 72 | dispose = true; 73 | } 74 | 75 | int Tech::Id::get() 76 | { 77 | return instance->getID(); 78 | } 79 | 80 | Api::Enum::TechType Tech::Type::get() 81 | { 82 | return EnumMapping::TechType->Managed(instance); 83 | } 84 | 85 | bool Tech::TypeEquals(Api::Enum::TechType techType) 86 | { 87 | return Type == techType; 88 | } 89 | 90 | Api::Race^ Tech::Race::get() 91 | { 92 | return ConvertRace(instance->getRace()); 93 | } 94 | 95 | Api::Price^ Tech::Price::get() 96 | { 97 | return gcnew Api::Price(instance->mineralPrice(), instance->gasPrice(), instance->researchTime(), 0); 98 | } 99 | 100 | int Tech::EnergyCost::get() 101 | { 102 | return instance->energyCost(); 103 | } 104 | 105 | Api::UnitType^ Tech::WhatResearches::get() 106 | { 107 | return ConvertUnitType(instance->whatResearches()); 108 | } 109 | 110 | Api::Weapon^ Tech::Weapon::get() 111 | { 112 | return ConvertWeapon(instance->getWeapon()); 113 | } 114 | 115 | bool Tech::TargetsUnit::get() 116 | { 117 | return instance->targetsUnit(); 118 | } 119 | 120 | bool Tech::TargetsPosition::get() 121 | { 122 | return instance->targetsPosition(); 123 | } 124 | 125 | HashSet^ Tech::WhatUses::get() 126 | { 127 | return ToHashSet(instance->whatUses(), &ConvertUnitType); 128 | } 129 | 130 | Api::Enum::OrderType Tech::Order::get() 131 | { 132 | return EnumMapping::OrderType->Managed(instance->getOrder()); 133 | } 134 | 135 | int Tech::GetHashCode() 136 | { 137 | return instance->getID(); 138 | } 139 | 140 | bool Tech::Equals(Object^ o) 141 | { 142 | Tech^ other = dynamic_cast(o); 143 | return this->Equals(other); 144 | } 145 | 146 | bool Tech::Equals(Tech^ other) 147 | { 148 | if(ReferenceEquals(nullptr, other)) 149 | return false; 150 | if(ReferenceEquals(this, other)) 151 | return true; 152 | return this->instance->getID() == other->instance->getID(); 153 | } 154 | 155 | List^ Tech::AllTechs::get() 156 | { 157 | return ToList(BWAPI::TechTypes::allTechTypes(), &ConvertTech); 158 | } 159 | 160 | bool Tech::operator == (Tech^ first, Tech^ second) 161 | { 162 | if(ReferenceEquals(first, second)) 163 | return true; 164 | if(ReferenceEquals(nullptr, first)) 165 | return false; 166 | return first->Equals(second); 167 | } 168 | 169 | bool Tech::operator != (Tech^ first, Tech^ second) 170 | { 171 | return !(first == second); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Tech.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #pragma managed 9 | 10 | #include "Race.h" 11 | #include "Price.h" 12 | #include "IIdentifiedObject.h" 13 | #include "Enum\OrderType.h" 14 | #include "Enum\TechType.h" 15 | 16 | using namespace System::Collections::Generic; 17 | 18 | namespace BroodWar 19 | { 20 | namespace Api 21 | { 22 | ref class UnitType; 23 | ref class Weapon; 24 | 25 | public ref class Tech sealed 26 | { 27 | internal: 28 | BWAPI::TechType* instance; 29 | bool dispose; 30 | 31 | Tech(Api::Enum::TechType type); 32 | Tech(BWAPI::TechType *type); 33 | Tech(BWAPI::TechType type); 34 | ~Tech(); 35 | !Tech(); 36 | 37 | public: 38 | Tech(); 39 | Tech(int id); 40 | 41 | virtual property int Id { int get(); } 42 | 43 | property Api::Enum::TechType Type { Api::Enum::TechType get(); } 44 | 45 | bool TypeEquals(Api::Enum::TechType techType); 46 | 47 | /// 48 | /// Returns the race that uses the TechType. For example, TechTypes::Scanner_Sweep?.getRace() will return Races::Terran 49 | /// 50 | property Api::Race^ Race { Api::Race^ get(); } 51 | 52 | /// 53 | /// Tech price 54 | /// 55 | property Api::Price^ Price { Api::Price^ get(); } 56 | 57 | /// 58 | /// Returns the amount of energy used each time this tech type is used 59 | /// 60 | property int EnergyCost { int get(); } 61 | 62 | /// 63 | /// Returns the type of unit that researches this tech type. If this tech type is available for free (does not need to be researched), 64 | /// then this method will return UnitTypes::None 65 | /// 66 | property Api::UnitType^ WhatResearches { Api::UnitType^ get(); } 67 | 68 | /// 69 | /// Returns the corresponding weapon for this tech type, or TechTypes::None if no corresponding weapon exists. For example, TechTypes::Dark_Swarm.getWeapon() 70 | /// will return a pointer to WeaponTypes::Dark_Swarm 71 | /// 72 | property Api::Weapon^ Weapon { Api::Weapon^ get(); } 73 | 74 | /// 75 | /// Returns true if this tech type must be used on another unit (i.e. Irradiate) 76 | /// 77 | property bool TargetsUnit { bool get(); } 78 | 79 | /// 80 | /// Returns true if this tech type must be specified a position (i.e. Dark Swarm) 81 | /// 82 | property bool TargetsPosition { bool get(); } 83 | 84 | /// 85 | /// Returns the set of units that can use this tech type. Usually this will just be a set of one unit type, however in some cases, such as 86 | /// TechTypes::Burrowing, several unit types will be returned 87 | /// 88 | property HashSet^ WhatUses { HashSet^ get(); } 89 | 90 | /// 91 | /// Returns the order used to execute this tech type as an action 92 | /// 93 | property Api::Enum::OrderType Order { Api::Enum::OrderType get(); } 94 | 95 | virtual int GetHashCode() override; 96 | virtual bool Equals(Object^ o) override; 97 | bool Equals(Tech^ other); 98 | 99 | static property List^ AllTechs { List^ get(); } 100 | 101 | static bool operator == (Tech^ first, Tech^ second); 102 | static bool operator != (Tech^ first, Tech^ second); 103 | }; 104 | 105 | Tech^ ConvertTech(BWAPI::TechType tech); 106 | BWAPI::TechType ConvertTech(Tech^ tech); 107 | BWAPI::TechType ConvertTech(TechType tech); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/TilePosition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | //#pragma make_public(BWAPI::Point) 6 | 7 | #pragma managed 8 | 9 | namespace BroodWar 10 | { 11 | // Can't use templates, because they're hard to consume in C# 12 | // Can't use generics, because BWAPI::Point needs to be hidden away 13 | // Probably should codegen somehow, to keep the copies in sync 14 | namespace Api 15 | { 16 | ref class Position; 17 | ref class WalkPosition; 18 | 19 | public ref class TilePosition 20 | { 21 | internal: 22 | BWAPI::TilePosition *instance; 23 | bool dispose; 24 | 25 | TilePosition(BWAPI::TilePosition *position, bool takeOwnership); 26 | TilePosition(BWAPI::TilePosition position); 27 | ~TilePosition(); 28 | !TilePosition(); 29 | 30 | public: 31 | TilePosition(); 32 | TilePosition(TilePosition^ copy); 33 | TilePosition(int x, int y); 34 | 35 | property int X { int get(); } 36 | property int Y { int get(); } 37 | property bool IsValid { bool get(); } 38 | double CalcDistance(TilePosition^ position); 39 | int CalcApproximateDistance(TilePosition^ position); 40 | double CalcLength(); 41 | void MakeValid(); 42 | property bool IsInvalid { bool get(); } 43 | property bool IsNone { bool get(); } 44 | property bool IsUnknown { bool get(); } 45 | 46 | virtual int GetHashCode() override; 47 | virtual bool Equals(Object^ o) override; 48 | bool Equals(TilePosition^ other); 49 | 50 | static bool operator == (TilePosition^ first, TilePosition^ second); 51 | static bool operator != (TilePosition^ first, TilePosition^ second); 52 | static bool operator < (TilePosition^ first, TilePosition^ second); 53 | static TilePosition^ operator + (TilePosition^ first, TilePosition^ second); 54 | static TilePosition^ operator - (TilePosition^ first, TilePosition^ second); 55 | static TilePosition^ operator * (TilePosition^ first, int second); 56 | static TilePosition^ operator / (TilePosition^ first, int second); 57 | static TilePosition^ operator += (TilePosition^ first, TilePosition^ second); 58 | static TilePosition^ operator -= (TilePosition^ first, TilePosition^ second); 59 | static TilePosition^ operator *= (TilePosition^ first, int second); 60 | static TilePosition^ operator /= (TilePosition^ first, int second); 61 | 62 | static TilePosition^ Rescale(Position^ position); 63 | static TilePosition^ Rescale(WalkPosition^ position); 64 | }; 65 | 66 | BWAPI::TilePosition ConvertTilePosition(TilePosition^ position); 67 | TilePosition^ ConvertTilePosition(BWAPI::TilePosition position); 68 | TilePosition^ ConvertTilePosition(BWAPI::TilePosition* position); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/Upgrade.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | 6 | #pragma managed 7 | 8 | #include "Race.h" 9 | #include "IIdentifiedObject.h" 10 | #include "Enum\UpgradeType.h" 11 | 12 | using namespace System::Collections::Generic; 13 | 14 | namespace BroodWar 15 | { 16 | namespace Api 17 | { 18 | public ref class Upgrade : public IIdentifiedObject 19 | { 20 | internal: 21 | BWAPI::UpgradeType* instance; 22 | bool dispose; 23 | 24 | Upgrade(Api::Enum::UpgradeType type); 25 | Upgrade(BWAPI::UpgradeType* type); 26 | Upgrade(BWAPI::UpgradeType type); 27 | ~Upgrade(); 28 | !Upgrade(); 29 | 30 | public: 31 | Upgrade(); 32 | Upgrade(int id); 33 | 34 | virtual property int Id { int get(); } 35 | 36 | property UpgradeType Type { UpgradeType get(); } 37 | 38 | bool TypeEquals(UpgradeType type); 39 | 40 | /// 41 | /// Returns the race the upgrade is for. For example, UpgradeTypes::Terran_Infantry_Armor.getRace() will return Races::Terran 42 | /// 43 | property Api::Race^ Race { Api::Race^ get(); } 44 | 45 | /// 46 | /// Returns the mineral price for the first upgrade 47 | /// 48 | int MineralPrice(int level); 49 | 50 | /// 51 | /// Returns the amount that the mineral price increases for each additional upgrade 52 | /// 53 | property int MineralPriceFactor { int get(); } 54 | 55 | /// 56 | /// Returns the vespene gas price for the first upgrade 57 | /// 58 | int GasPrice(int level); 59 | 60 | /// 61 | /// Returns the amount that the vespene gas price increases for each additional upgrade 62 | /// 63 | property int GasPriceFactor { int get(); } 64 | 65 | /// 66 | /// Returns the number of frames needed to research the first upgrade 67 | /// 68 | int UpgradeTime(int level); 69 | 70 | /// 71 | /// Returns the number of frames that the upgrade time increases for each additional upgrade 72 | /// 73 | property int UpgradeTimeFactor { int get(); } 74 | 75 | /// 76 | /// Returns the maximum number of times the upgrade can be researched 77 | /// 78 | property int MaxRepeats { int get(); } 79 | 80 | /// 81 | /// Returns the type of unit that researches the upgrade 82 | /// 83 | property Api::UnitType^ WhatUpgrades { Api::UnitType^ get(); } 84 | 85 | /// 86 | /// Returns the type of unit that is additionally required for the upgrade 87 | /// 88 | Api::UnitType^ WhatsRequired(int level); 89 | 90 | /// 91 | /// Returns the set of units that are affected by this upgrade 92 | /// 93 | property HashSet^ WhatUses { HashSet^ get(); } 94 | 95 | virtual int GetHashCode() override; 96 | virtual bool Equals(Object^ o) override; 97 | bool Equals(Upgrade^ other); 98 | 99 | static property List^ AllUpgrades { List^ get(); } 100 | 101 | static bool operator == (Upgrade^ first, Upgrade^ second); 102 | static bool operator != (Upgrade^ first, Upgrade^ second); 103 | }; 104 | 105 | Upgrade^ ConvertUpgrade(BWAPI::UpgradeType upgrade); 106 | BWAPI::UpgradeType ConvertUpgrade(Upgrade^ upgrade); 107 | BWAPI::UpgradeType ConvertUpgrade(Enum::UpgradeType upgrade); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Src/Broodwar/BWAPI/WalkPosition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | //#pragma make_public(BWAPI::Point) 6 | 7 | #pragma managed 8 | 9 | namespace BroodWar 10 | { 11 | // Can't use templates, because they're hard to consume in C# 12 | // Can't use generics, because BWAPI::Point needs to be hidden away 13 | // Probably should codegen somehow, to keep the copies in sync 14 | namespace Api 15 | { 16 | ref class Position; 17 | ref class TilePosition; 18 | 19 | public ref class WalkPosition 20 | { 21 | internal: 22 | BWAPI::WalkPosition *instance; 23 | bool dispose; 24 | 25 | WalkPosition(BWAPI::WalkPosition *position, bool takeOwnership); 26 | WalkPosition(BWAPI::WalkPosition position); 27 | ~WalkPosition(); 28 | !WalkPosition(); 29 | 30 | public: 31 | WalkPosition(); 32 | WalkPosition(WalkPosition^ copy); 33 | WalkPosition(int x, int y); 34 | 35 | property int X { int get(); } 36 | property int Y { int get(); } 37 | property bool IsValid { bool get(); } 38 | double CalcDistance(WalkPosition^ position); 39 | int CalcApproximateDistance(WalkPosition^ position); 40 | double CalcLength(); 41 | void MakeValid(); 42 | property bool IsInvalid { bool get(); } 43 | property bool IsNone { bool get(); } 44 | property bool IsUnknown { bool get(); } 45 | 46 | virtual int GetHashCode() override; 47 | virtual bool Equals(Object^ o) override; 48 | bool Equals(WalkPosition^ other); 49 | 50 | static bool operator == (WalkPosition^ first, WalkPosition^ second); 51 | static bool operator != (WalkPosition^ first, WalkPosition^ second); 52 | static bool operator < (WalkPosition^ first, WalkPosition^ second); 53 | static WalkPosition^ operator + (WalkPosition^ first, WalkPosition^ second); 54 | static WalkPosition^ operator - (WalkPosition^ first, WalkPosition^ second); 55 | static WalkPosition^ operator * (WalkPosition^ first, int second); 56 | static WalkPosition^ operator / (WalkPosition^ first, int second); 57 | static WalkPosition^ operator += (WalkPosition^ first, WalkPosition^ second); 58 | static WalkPosition^ operator -= (WalkPosition^ first, WalkPosition^ second); 59 | static WalkPosition^ operator *= (WalkPosition^ first, int second); 60 | static WalkPosition^ operator /= (WalkPosition^ first, int second); 61 | 62 | static WalkPosition^ Rescale(Position^ position); 63 | static WalkPosition^ Rescale(TilePosition^ position); 64 | }; 65 | 66 | BWAPI::WalkPosition ConvertWalkPosition(WalkPosition^ position); 67 | WalkPosition^ ConvertWalkPosition(BWAPI::WalkPosition position); 68 | WalkPosition^ ConvertWalkPosition(BWAPI::WalkPosition* position); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Src/Broodwar/EnumClassMap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma unmanaged 4 | 5 | #include 6 | 7 | #pragma managed 8 | 9 | #include "Util.h" 10 | 11 | using namespace System; 12 | using namespace System::Collections::Generic; 13 | using namespace System::Runtime::InteropServices; 14 | 15 | namespace BroodWar 16 | { 17 | template 18 | private ref class EnumClassMap 19 | { 20 | private: 21 | Dictionary^ dictionaryForward; 22 | Dictionary^ dictionaryBackward; 23 | 24 | internal: 25 | EnumClassMap(int size) 26 | { 27 | dictionaryForward = gcnew Dictionary(size); 28 | dictionaryBackward = gcnew Dictionary(size); 29 | } 30 | 31 | void Add(const TNative* native, TManaged managed) 32 | { 33 | dictionaryForward->Add(native->getID(), managed); 34 | dictionaryBackward->Add(managed, native->getID()); 35 | } 36 | 37 | TManaged Managed(TNative native) 38 | { 39 | return dictionaryForward[native.getID()]; 40 | } 41 | 42 | TManaged Managed(const TNative* native) 43 | { 44 | return dictionaryForward[native->getID()]; 45 | } 46 | 47 | TNative Native(TManaged managed) 48 | { 49 | return TNative(dictionaryBackward[managed]); 50 | } 51 | 52 | TNative* NativePointer(TManaged managed) 53 | { 54 | return new TNative(dictionaryBackward[managed]); 55 | } 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /Src/Broodwar/EnumMapping.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma unmanaged 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #pragma managed 21 | 22 | #include "EnumClassMap.h" 23 | 24 | #include "BWAPI\Enum\BulletType.h" 25 | #include "BWAPI\Enum\DamageType.h" 26 | #include "BWAPI\Enum\ErrorType.h" 27 | #include "BWAPI\Enum\ExplosionType.h" 28 | #include "BWAPI\Enum\GameType.h" 29 | #include "BWAPI\Enum\OrderType.h" 30 | #include "BWAPI\Enum\PlayerType.h" 31 | #include "BWAPI\Enum\RaceType.h" 32 | #include "BWAPI\Enum\TechType.h" 33 | #include "BWAPI\Enum\TournamentAction.h" 34 | #include "BWAPI\Enum\UnitCommandType.h" 35 | #include "BWAPI\Enum\UnitSizeType.h" 36 | #include "BWAPI\Enum\UnitType.h" 37 | #include "BWAPI\Enum\UpgradeType.h" 38 | #include "BWAPI\Enum\WeaponType.h" 39 | 40 | using namespace BroodWar; 41 | 42 | namespace BroodWar 43 | { 44 | private ref class EnumMapping abstract sealed 45 | { 46 | public: 47 | static EnumClassMap^ UnitCommandType; 48 | static EnumClassMap^ DamageType; 49 | static EnumClassMap^ BulletType; 50 | static EnumClassMap^ ExplosionType; 51 | static EnumClassMap^ GameType; 52 | static EnumClassMap^ PlayerType; 53 | static EnumClassMap^ UnitSizeType; 54 | static EnumClassMap^ OrderType; 55 | static EnumClassMap^ ErrorType; 56 | static EnumClassMap^ RaceType; 57 | static EnumClassMap^ UnitType; 58 | static EnumClassMap^ TechType; 59 | static EnumClassMap^ UpgradeType; 60 | static EnumClassMap^ WeaponType; 61 | 62 | static EnumMapping(); 63 | 64 | static System::Drawing::Color ToNativeColor(BWAPI::Color color); 65 | 66 | static System::Drawing::Color ToNativeColor(BWAPI::Color *color); 67 | 68 | static BWAPI::Color* ToBwColorPointer(System::Drawing::Color^ color); 69 | 70 | static BWAPI::Color ToBwColor(System::Drawing::Color^ color); 71 | }; 72 | } -------------------------------------------------------------------------------- /Src/Broodwar/TournamentBase.cpp: -------------------------------------------------------------------------------- 1 | #pragma managed 2 | 3 | #include "TournamentBase.h" 4 | 5 | namespace BroodWar 6 | { 7 | bool TournamentBase::OnAction(TournamentAction action, IntPtr parameter) { return true; } 8 | 9 | void TournamentBase::OnFirstAdvertisement() { } 10 | } 11 | -------------------------------------------------------------------------------- /Src/Broodwar/TournamentBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma managed 4 | 5 | #include "BWAPI\Enum\TournamentAction.h" 6 | 7 | using namespace System; 8 | using namespace BroodWar::Api::Enum; 9 | 10 | namespace BroodWar 11 | { 12 | public ref class TournamentBase abstract 13 | { 14 | public: 15 | /// 16 | /// BWAPI calls this any time some Game-related functions are called. Return true to allow them, 17 | /// or false to disallow them. This includes functions like Game::pauseGame and Game::enableFlag 18 | /// 19 | virtual bool OnAction(TournamentAction action, IntPtr parameter); 20 | 21 | /// 22 | /// BWAPI calls this when this module was the first to send out its tournament advertisement. It 23 | /// can prevent both modules from performing the same task if it's necessary 24 | /// 25 | virtual void OnFirstAdvertisement(); 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /Src/Broodwar/Util.cpp: -------------------------------------------------------------------------------- 1 | #include "Util.h" 2 | #include 3 | #include "BWAPI\Player.h" 4 | 5 | using namespace System::IO; 6 | using namespace System::Runtime::InteropServices; 7 | 8 | extern BWAPI::GameWrapper BWAPI::Broodwar; 9 | 10 | namespace BroodWar 11 | { 12 | double DoubleToDouble(double d) 13 | { 14 | return d; 15 | } 16 | 17 | int IntToInt(int i) 18 | { 19 | return i; 20 | } 21 | 22 | BWAPI::Unitset ToUnitset(IEnumerable^ collection, BWAPI::Unit(*converter)(Unit^)) 23 | { 24 | BWAPI::Unitset result; 25 | BWAPI::Unit outelement; 26 | for each(Unit^ element in collection) 27 | { 28 | outelement = (BWAPI::Unit const)(converter(element)); 29 | result.insert(outelement); 30 | } 31 | return result; 32 | } 33 | 34 | void Util::Log(String^ string) 35 | { 36 | String^ fileName = Path::Combine( 37 | Environment::GetFolderPath(Environment::SpecialFolder::Personal), 38 | "text-from-lib.txt"); 39 | StreamWriter^ file = gcnew StreamWriter(fileName, true); 40 | file->WriteLine(string); 41 | file->Close(); 42 | 43 | IntPtr ptr = Marshal::StringToHGlobalAnsi(string); 44 | BWAPI::Broodwar->sendText((char*)ptr.ToPointer()); 45 | Marshal::FreeHGlobal(ptr); 46 | } 47 | 48 | void Util::LogException(String^ module, Exception^ ex) 49 | { 50 | Log(String::Format("Unexpected error occured during {0}: {1}{2}{3}", module, ex->Message, Environment::NewLine, ex->StackTrace)); 51 | while((ex = ex->InnerException) != nullptr) 52 | { 53 | Log(String::Format("Internal error is: {0}{1}{2}", ex->Message, Environment::NewLine, ex->StackTrace)); 54 | } 55 | } 56 | 57 | Api::Player^ Util::ConvertPlayer(void *player) 58 | { 59 | return Api::ConvertPlayer(static_cast(player)); 60 | } 61 | 62 | Api::Unit^ Util::ConvertUnit(void *unit) 63 | { 64 | return Api::ConvertUnit(static_cast(unit)); 65 | } 66 | 67 | Api::Position^ Util::ConvertPosition(void *position) 68 | { 69 | return Api::ConvertPosition(static_cast(position)); 70 | } 71 | 72 | void Util::LoadGameInstance(BWAPI::Game* game) 73 | { 74 | BWAPI::BroodwarPtr = game; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Src/BroodwarFSharp/BroodwarFSharp.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 115cddd6-3341-4864-a3fd-b11206883b15 9 | Library 10 | BroodwarFSharp 11 | BroodwarFSharp 12 | v4.0 13 | 4.3.1.0 14 | BroodwarFSharp 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | 3 25 | bin\Debug\BroodwarFSharp.XML 26 | 27 | 28 | pdbonly 29 | true 30 | true 31 | bin\Release\ 32 | TRACE 33 | 3 34 | bin\Release\BroodwarFSharp.XML 35 | x86 36 | 37 | 38 | 39 | 40 | True 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Broodwar 56 | {61e7ae8b-70bb-4266-90e1-926ebc9541fd} 57 | True 58 | 59 | 60 | 61 | 11 62 | 63 | 64 | 65 | 66 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 67 | 68 | 69 | 70 | 71 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 72 | 73 | 74 | 75 | 76 | 83 | -------------------------------------------------------------------------------- /Src/BroodwarFSharp/Position.fs: -------------------------------------------------------------------------------- 1 | namespace BroodwarFSharp 2 | 3 | [] type pixel 4 | [] type walk 5 | [] type tile 6 | [] type frame 7 | 8 | module Position = 9 | let (||~||) x y = 10 | let largeDist, smallDist = max x y, min x y 11 | if smallDist < (largeDist >>> 2) then largeDist 12 | else 13 | let smallCalc = (3*smallDist) >>> 3 14 | ((smallCalc >>> 5) + smallCalc + largeDist - (largeDist >>> 4) - (largeDist >>> 6)) 15 | 16 | type Position<[] 'u> = Pos of int<'u> * int<'u> with 17 | static member inline (+) (Pos (x1, y1), Pos (x2, y2)) = Pos (x1 + x2, y1 + y2) 18 | static member inline (-) (Pos (x1, y1), Pos (x2, y2)) = Pos (x1 - x2, y1 - y2) 19 | static member inline (*) (Pos (x, y), f) = Pos (x * f, y * f) 20 | static member inline (/) (Pos (x, y), d) = Pos (x / d, y / d) 21 | // getApproxDistance as per Starcraft: Broodwar 22 | static member (|~|) (Pos (x1:int<'u>, y1), Pos (x2, y2)) = (abs (x1 - x2) |> int) ||~|| (abs (y1 - y2) |> int) |> LanguagePrimitives.Int32WithMeasure<'u> 23 | // Precise length calc - may be slow 24 | static member inline (|-|) (Pos (x1, y1), Pos (x2, y2)) = 25 | pown (x1 - x2) 2 + pown (y1 - y2) 2 |> float |> sqrt 26 | 27 | // Approx distance between two rectangles 28 | let (|~~|) (Pos (l1:int<'u>, t1), Pos (r1, b1)) (Pos (l2, t2), Pos (r2, b2)) = 29 | let x1, x2 = l1 - r2, l2 - r1 30 | let y1, y2 = t1 - b2, t2 - b1 31 | ((max x1 x2 |> int) - 1 |> max 0) ||~|| ((max y1 y2 |> int) - 1 |> max 0) |> LanguagePrimitives.Int32WithMeasure<'u> 32 | // Test if two rectangles intersect 33 | let (|><|) (Pos (l1:int<'u>, t1), Pos (r1, b1)) (Pos (l2, t2), Pos (r2, b2)) = (l1 <= r2) && (l2 <= r1) && (t1 <= b2) && (t2 <= b1) 34 | 35 | let inline posx (Pos (_x, _)) = _x 36 | let inline posy (Pos (_, _y)) = _y 37 | 38 | let PixelPerWalk : int = 8 39 | let PixelPerTile : int = 32 40 | let WalkPerTile : int = 4 41 | 42 | let inline walkToPixel (pos:Position<_>) = pos * PixelPerWalk 43 | let inline tileToPixel (pos:Position<_>) = pos * PixelPerTile 44 | 45 | let inline pixelToWalk (pos:Position<_>) = pos / PixelPerWalk 46 | let inline tileToWalk (pos:Position<_>) = pos * WalkPerTile 47 | 48 | let inline pixelToTile (pos:Position<_>) = pos / PixelPerTile 49 | let inline walkToTile (pos:Position<_>) = pos / WalkPerTile 50 | 51 | let inline pixelToApi (Pos (x, y)) = new BroodWar.Api.Position(x * 1<1/pixel>, y * 1<1/pixel>) 52 | let inline walkToApi (Pos (x, y)) = new BroodWar.Api.WalkPosition(x * 1<1/walk>, y * 1<1/walk>) 53 | let inline tileToApi (Pos (x, y)) = new BroodWar.Api.TilePosition(x * 1<1/tile>, y * 1<1/tile>) 54 | 55 | let inline apiToPixel (pos:BroodWar.Api.Position) = Pos (pos.X * 1, pos.Y * 1) 56 | let inline apiToWalk (pos:BroodWar.Api.WalkPosition) = Pos (pos.X * 1, pos.Y * 1) 57 | let inline apiToTile (pos:BroodWar.Api.TilePosition) = Pos (pos.X * 1, pos.Y * 1) 58 | 59 | let invalidPixel = Pos (32000, 32000) 60 | let nonePixel = Pos (32000, 32032) 61 | let unknownPixel = Pos (32000, 32064) 62 | let invalidWalk = pixelToWalk invalidPixel 63 | let noneWalk = pixelToWalk nonePixel 64 | let unknownWalk = pixelToWalk unknownPixel 65 | let invalidTile = pixelToTile invalidPixel 66 | let noneTile = pixelToTile nonePixel 67 | let unknownTile = pixelToTile unknownPixel 68 | -------------------------------------------------------------------------------- /Src/BroodwarFSharp/UnitType.fs: -------------------------------------------------------------------------------- 1 | namespace BroodwarFSharp 2 | 3 | open Position 4 | 5 | type UnitType = BroodWar.Api.UnitType 6 | 7 | type UnitMark = { UnitId:int; Frame:int; Position:Position; UnitType:UnitType; Player:BroodWar.Api.Player } 8 | 9 | [] 10 | type UnitTypeExt = 11 | static member inline TileSize (unitType:UnitType) = Position.apiToTile unitType.TileSize 12 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/AIManaged.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Loader 6 | { 7 | private ref class AIManaged abstract sealed 8 | { 9 | private: 10 | static AiBase^ aiBase; 11 | internal: 12 | static AIManaged(); 13 | 14 | static void Start(); 15 | static void End(bool isWinner); 16 | static void Frame(); 17 | static void SendText(System::String^ text); 18 | static void ReceiveText(BWAPI::Player player, System::String^ text); 19 | static void PlayerLeft(BWAPI::Player player); 20 | static void NukeDetect(BWAPI::Position target); 21 | static void UnitDiscover(BWAPI::Unit unit); 22 | static void UnitEvade(BWAPI::Unit unit); 23 | static void UnitShow(BWAPI::Unit unit); 24 | static void UnitHide(BWAPI::Unit unit); 25 | static void UnitCreate(BWAPI::Unit unit); 26 | static void UnitDestroy(BWAPI::Unit unit); 27 | static void UnitMorph(BWAPI::Unit unit); 28 | static void UnitRenegade(BWAPI::Unit unit); 29 | static void SaveGame(System::String^ gameName); 30 | static void UnitComplete(BWAPI::Unit unit); 31 | static void PlayerDropped(BWAPI::Player player); 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/AIModule.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #pragma managed 6 | 7 | #include "AIManaged.h" 8 | #include "AIModule.h" 9 | 10 | using namespace System; 11 | using namespace System::IO; 12 | using namespace System::Reflection; 13 | using namespace BroodWar::Loader; 14 | 15 | Assembly^ ResolveAssembly(Object ^sender, ResolveEventArgs ^e); 16 | 17 | void Preload() 18 | { 19 | AppDomain::CurrentDomain->AssemblyResolve += gcnew ResolveEventHandler(&ResolveAssembly); 20 | } 21 | 22 | void LoadGameInstance(BWAPI::Game* game) 23 | { 24 | BroodWar::Util::LoadGameInstance(game); 25 | } 26 | 27 | void AIModule::onStart() 28 | { 29 | AIManaged::Start(); 30 | } 31 | 32 | void AIModule::onEnd(bool isWinner) 33 | { 34 | AIManaged::End(isWinner); 35 | } 36 | 37 | void AIModule::onFrame() 38 | { 39 | AIManaged::Frame(); 40 | } 41 | 42 | void AIModule::onSendText(std::string text) 43 | { 44 | AIManaged::SendText(gcnew System::String(text.c_str())); 45 | } 46 | 47 | void AIModule::onReceiveText(BWAPI::Player player, std::string text) 48 | { 49 | AIManaged::ReceiveText(player, gcnew System::String(text.c_str())); 50 | } 51 | 52 | void AIModule::onPlayerLeft(BWAPI::Player player) 53 | { 54 | AIManaged::PlayerLeft(player); 55 | } 56 | 57 | void AIModule::onNukeDetect(BWAPI::Position target) 58 | { 59 | AIManaged::NukeDetect(target); 60 | } 61 | 62 | void AIModule::onUnitDiscover(BWAPI::Unit unit) 63 | { 64 | AIManaged::UnitDiscover(unit); 65 | } 66 | 67 | void AIModule::onUnitEvade(BWAPI::Unit unit) 68 | { 69 | AIManaged::UnitEvade(unit); 70 | } 71 | 72 | void AIModule::onUnitShow(BWAPI::Unit unit) 73 | { 74 | AIManaged::UnitShow(unit); 75 | } 76 | 77 | void AIModule::onUnitHide(BWAPI::Unit unit) 78 | { 79 | AIManaged::UnitHide(unit); 80 | } 81 | 82 | void AIModule::onUnitCreate(BWAPI::Unit unit) 83 | { 84 | AIManaged::UnitCreate(unit); 85 | } 86 | 87 | void AIModule::onUnitDestroy(BWAPI::Unit unit) 88 | { 89 | AIManaged::UnitDestroy(unit); 90 | } 91 | 92 | void AIModule::onUnitMorph(BWAPI::Unit unit) 93 | { 94 | AIManaged::UnitMorph(unit); 95 | } 96 | 97 | void AIModule::onUnitRenegade(BWAPI::Unit unit) 98 | { 99 | AIManaged::UnitRenegade(unit); 100 | } 101 | 102 | void AIModule::onSaveGame(std::string gameName) 103 | { 104 | AIManaged::SaveGame(gcnew System::String(gameName.c_str())); 105 | } 106 | 107 | void AIModule::onUnitComplete(BWAPI::Unit unit) 108 | { 109 | AIManaged::UnitComplete(unit); 110 | } 111 | 112 | void AIModule::onPlayerDropped(BWAPI::Player player) 113 | { 114 | AIManaged::PlayerDropped(player); 115 | } 116 | 117 | Assembly^ ResolveAssembly(Object ^sender, ResolveEventArgs ^e) 118 | { 119 | String^ folder = Path::GetDirectoryName(Assembly::GetExecutingAssembly()->Location); 120 | AssemblyName^ assemblyName = gcnew AssemblyName(e->Name); 121 | for each (String^ extension in gcnew array { ".dll", ".exe" }) 122 | { 123 | String^ fileName = Path::Combine(folder, assemblyName->Name + extension); 124 | try 125 | { 126 | return Assembly::LoadFile(fileName); 127 | } 128 | catch (...) 129 | { 130 | } 131 | } 132 | return nullptr; 133 | } 134 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/AIModule.h: -------------------------------------------------------------------------------- 1 | void LoadGameInstance(BWAPI::Game* game); 2 | void Preload(); 3 | 4 | class AIModule : public BWAPI::AIModule 5 | { 6 | public: 7 | virtual void onStart(); 8 | virtual void onEnd(bool isWinner); 9 | virtual void onFrame(); 10 | virtual void onSendText(std::string text); 11 | virtual void onReceiveText(BWAPI::Player player, std::string text); 12 | virtual void onPlayerLeft(BWAPI::Player player); 13 | virtual void onNukeDetect(BWAPI::Position target); 14 | virtual void onUnitDiscover(BWAPI::Unit unit); 15 | virtual void onUnitEvade(BWAPI::Unit unit); 16 | virtual void onUnitShow(BWAPI::Unit unit); 17 | virtual void onUnitHide(BWAPI::Unit unit); 18 | virtual void onUnitCreate(BWAPI::Unit unit); 19 | virtual void onUnitDestroy(BWAPI::Unit unit); 20 | virtual void onUnitMorph(BWAPI::Unit unit); 21 | virtual void onUnitRenegade(BWAPI::Unit unit); 22 | virtual void onSaveGame(std::string gameName); 23 | virtual void onUnitComplete(BWAPI::Unit unit); 24 | virtual void onPlayerDropped(BWAPI::Player player); 25 | }; 26 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | using namespace System; 2 | using namespace System::Reflection; 3 | 4 | [assembly: AssemblyKeyFile("..\\bwapicli.snk")]; 5 | [assembly: AssemblyDelaySign(false)]; 6 | 7 | [assembly: AssemblyVersion("0.1.0.0")]; 8 | [assembly: AssemblyFileVersion("0.1.0.0")]; 9 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/BroodwarLoader.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Файлы исходного кода 20 | 21 | 22 | Файлы исходного кода 23 | 24 | 25 | Файлы исходного кода 26 | 27 | 28 | Файлы исходного кода 29 | 30 | 31 | 32 | 33 | Заголовочные файлы 34 | 35 | 36 | Заголовочные файлы 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/Dll.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #pragma managed 6 | 7 | #include "AIModule.h" 8 | 9 | #pragma unmanaged 10 | 11 | extern "C" __declspec(dllexport) void gameInit(BWAPI::Game* game) 12 | { 13 | //Hack to properly locate Broodwar.dll assembly 14 | Preload(); 15 | LoadGameInstance(game); 16 | } 17 | 18 | extern "C" __declspec(dllexport) BWAPI::AIModule* newAIModule() 19 | { 20 | return new AIModule(); 21 | } 22 | -------------------------------------------------------------------------------- /Src/BroodwarLoader/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/AIManaged.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Loader 6 | { 7 | private ref class AIManaged abstract sealed 8 | { 9 | private: 10 | static AiBase^ aiBase; 11 | internal: 12 | static AIManaged(); 13 | 14 | static void Start(); 15 | static void End(bool isWinner); 16 | static void Frame(); 17 | static void SendText(System::String^ text); 18 | static void ReceiveText(BWAPI::Player player, System::String^ text); 19 | static void PlayerLeft(BWAPI::Player player); 20 | static void NukeDetect(BWAPI::Position target); 21 | static void UnitDiscover(BWAPI::Unit unit); 22 | static void UnitEvade(BWAPI::Unit unit); 23 | static void UnitShow(BWAPI::Unit unit); 24 | static void UnitHide(BWAPI::Unit unit); 25 | static void UnitCreate(BWAPI::Unit unit); 26 | static void UnitDestroy(BWAPI::Unit unit); 27 | static void UnitMorph(BWAPI::Unit unit); 28 | static void UnitRenegade(BWAPI::Unit unit); 29 | static void SaveGame(System::String^ gameName); 30 | static void UnitComplete(BWAPI::Unit unit); 31 | static void PlayerDropped(BWAPI::Player player); 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/AIModule.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #pragma managed 6 | 7 | #include "AIManaged.h" 8 | #include "AIModule.h" 9 | 10 | using namespace System; 11 | using namespace System::IO; 12 | using namespace System::Reflection; 13 | using namespace BroodWar::Loader; 14 | 15 | Assembly^ ResolveAssembly(Object ^sender, ResolveEventArgs ^e); 16 | 17 | void Preload() 18 | { 19 | AppDomain::CurrentDomain->AssemblyResolve += gcnew ResolveEventHandler(&ResolveAssembly); 20 | } 21 | 22 | void LoadGameInstance(BWAPI::Game* game) 23 | { 24 | BroodWar::Util::LoadGameInstance(game); 25 | } 26 | 27 | void AIModule::onStart() 28 | { 29 | AIManaged::Start(); 30 | } 31 | 32 | void AIModule::onEnd(bool isWinner) 33 | { 34 | AIManaged::End(isWinner); 35 | } 36 | 37 | void AIModule::onFrame() 38 | { 39 | AIManaged::Frame(); 40 | } 41 | 42 | void AIModule::onSendText(std::string text) 43 | { 44 | AIManaged::SendText(gcnew System::String(text.c_str())); 45 | } 46 | 47 | void AIModule::onReceiveText(BWAPI::Player player, std::string text) 48 | { 49 | AIManaged::ReceiveText(player, gcnew System::String(text.c_str())); 50 | } 51 | 52 | void AIModule::onPlayerLeft(BWAPI::Player player) 53 | { 54 | AIManaged::PlayerLeft(player); 55 | } 56 | 57 | void AIModule::onNukeDetect(BWAPI::Position target) 58 | { 59 | AIManaged::NukeDetect(target); 60 | } 61 | 62 | void AIModule::onUnitDiscover(BWAPI::Unit unit) 63 | { 64 | AIManaged::UnitDiscover(unit); 65 | } 66 | 67 | void AIModule::onUnitEvade(BWAPI::Unit unit) 68 | { 69 | AIManaged::UnitEvade(unit); 70 | } 71 | 72 | void AIModule::onUnitShow(BWAPI::Unit unit) 73 | { 74 | AIManaged::UnitShow(unit); 75 | } 76 | 77 | void AIModule::onUnitHide(BWAPI::Unit unit) 78 | { 79 | AIManaged::UnitHide(unit); 80 | } 81 | 82 | void AIModule::onUnitCreate(BWAPI::Unit unit) 83 | { 84 | AIManaged::UnitCreate(unit); 85 | } 86 | 87 | void AIModule::onUnitDestroy(BWAPI::Unit unit) 88 | { 89 | AIManaged::UnitDestroy(unit); 90 | } 91 | 92 | void AIModule::onUnitMorph(BWAPI::Unit unit) 93 | { 94 | AIManaged::UnitMorph(unit); 95 | } 96 | 97 | void AIModule::onUnitRenegade(BWAPI::Unit unit) 98 | { 99 | AIManaged::UnitRenegade(unit); 100 | } 101 | 102 | void AIModule::onSaveGame(std::string gameName) 103 | { 104 | AIManaged::SaveGame(gcnew System::String(gameName.c_str())); 105 | } 106 | 107 | void AIModule::onUnitComplete(BWAPI::Unit unit) 108 | { 109 | AIManaged::UnitComplete(unit); 110 | } 111 | 112 | void AIModule::onPlayerDropped(BWAPI::Player player) 113 | { 114 | AIManaged::PlayerDropped(player); 115 | } 116 | 117 | Assembly^ ResolveAssembly(Object ^sender, ResolveEventArgs ^e) 118 | { 119 | String^ folder = Path::GetDirectoryName(Assembly::GetExecutingAssembly()->Location); 120 | AssemblyName^ assemblyName = gcnew AssemblyName(e->Name); 121 | for each (String^ extension in gcnew array { ".dll", ".exe" }) 122 | { 123 | String^ fileName = Path::Combine(folder, assemblyName->Name + extension); 124 | try 125 | { 126 | return Assembly::LoadFile(fileName); 127 | } 128 | catch (...) 129 | { 130 | } 131 | } 132 | return nullptr; 133 | } 134 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/AIModule.h: -------------------------------------------------------------------------------- 1 | void LoadGameInstance(BWAPI::Game* game); 2 | void Preload(); 3 | 4 | class AIModule : public BWAPI::AIModule 5 | { 6 | public: 7 | virtual void onStart(); 8 | virtual void onEnd(bool isWinner); 9 | virtual void onFrame(); 10 | virtual void onSendText(std::string text); 11 | virtual void onReceiveText(BWAPI::Player player, std::string text); 12 | virtual void onPlayerLeft(BWAPI::Player player); 13 | virtual void onNukeDetect(BWAPI::Position target); 14 | virtual void onUnitDiscover(BWAPI::Unit unit); 15 | virtual void onUnitEvade(BWAPI::Unit unit); 16 | virtual void onUnitShow(BWAPI::Unit unit); 17 | virtual void onUnitHide(BWAPI::Unit unit); 18 | virtual void onUnitCreate(BWAPI::Unit unit); 19 | virtual void onUnitDestroy(BWAPI::Unit unit); 20 | virtual void onUnitMorph(BWAPI::Unit unit); 21 | virtual void onUnitRenegade(BWAPI::Unit unit); 22 | virtual void onSaveGame(std::string gameName); 23 | virtual void onUnitComplete(BWAPI::Unit unit); 24 | virtual void onPlayerDropped(BWAPI::Player player); 25 | }; 26 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | using namespace System; 2 | using namespace System::Reflection; 3 | 4 | [assembly: AssemblyKeyFile("..\\bwapicli.snk")]; 5 | [assembly: AssemblyDelaySign(false)]; 6 | 7 | [assembly: AssemblyVersion("0.1.0.0")]; 8 | [assembly: AssemblyFileVersion("0.1.0.0")]; 9 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/BroodwarTournamentLoader.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Файлы исходного кода 23 | 24 | 25 | Файлы исходного кода 26 | 27 | 28 | Файлы исходного кода 29 | 30 | 31 | Файлы исходного кода 32 | 33 | 34 | Файлы исходного кода 35 | 36 | 37 | Файлы исходного кода 38 | 39 | 40 | 41 | 42 | Заголовочные файлы 43 | 44 | 45 | Заголовочные файлы 46 | 47 | 48 | Заголовочные файлы 49 | 50 | 51 | Заголовочные файлы 52 | 53 | 54 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/Dll.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #pragma managed 6 | 7 | #include "AIModule.h" 8 | #include "TournamentModule.h" 9 | 10 | #pragma unmanaged 11 | 12 | extern "C" __declspec(dllexport) void gameInit(BWAPI::Game* game) 13 | { 14 | //Hack to properly locate Broodwar.dll assembly 15 | Preload(); 16 | LoadGameInstance(game); 17 | } 18 | 19 | extern "C" __declspec(dllexport) 20 | BWAPI::AIModule* newAIModule(BWAPI::Game* game) 21 | { 22 | return new AIModule(); 23 | } 24 | 25 | extern "C" __declspec(dllexport) 26 | BWAPI::TournamentModule* newTournamentModule() 27 | { 28 | return new TournamentModule(); 29 | } 30 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/TournamentManaged.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #pragma managed 6 | 7 | #include "TournamentManaged.h" 8 | 9 | using namespace System; 10 | using namespace System::Configuration; 11 | using namespace System::IO; 12 | using namespace System::Reflection; 13 | using namespace System::Runtime::InteropServices; 14 | using namespace BroodWar::Api::Enum; 15 | 16 | namespace BroodWar 17 | { 18 | namespace Loader 19 | { 20 | static TournamentManaged::TournamentManaged() 21 | { 22 | try 23 | { 24 | String^ currentLocation = Assembly::GetExecutingAssembly()->Location; 25 | String^ configFile = String::Format("{0}.config", currentLocation); 26 | ExeConfigurationFileMap^ fileMap = gcnew ExeConfigurationFileMap(); 27 | fileMap->ExeConfigFilename = configFile; 28 | System::Configuration::Configuration^ config = ConfigurationManager::OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel::None); 29 | 30 | String^ path = config->AppSettings->Settings["Path"]->Value; 31 | String^ assemblyName = config->AppSettings->Settings["Assembly"]->Value; 32 | String^ type = config->AppSettings->Settings["Tournament"]->Value; 33 | 34 | if(!Path::IsPathRooted(path)) 35 | { 36 | path = Path::Combine(Path::GetDirectoryName(currentLocation), path); 37 | } 38 | 39 | Assembly^ assembly = Assembly::LoadFrom(Path::Combine(path, assemblyName)); 40 | if(assembly == nullptr) 41 | { 42 | Util::Log(String::Format("Could not load assembly {0} from path {1}", assemblyName, path)); 43 | return; 44 | } 45 | Type^ module = assembly->GetType(type); 46 | if(module == nullptr) 47 | { 48 | Util::Log(String::Format("Could not load type {0}", type)); 49 | return; 50 | } 51 | ConstructorInfo^ constructor = module->GetConstructor(gcnew array { }); 52 | if(constructor == nullptr) 53 | { 54 | Util::Log(String::Format("Could not find constructor for type {0}", type)); 55 | return; 56 | } 57 | tournamentBase = dynamic_cast(constructor->Invoke(gcnew array { })); 58 | if(tournamentBase == nullptr) 59 | { 60 | Util::Log(String::Format("Could not create instance of type {0}", type)); 61 | return; 62 | } 63 | 64 | Util::Log("Startup successful"); 65 | } 66 | catch(Exception^ ex) 67 | { 68 | Util::LogException("initialization", ex); 69 | } 70 | } 71 | 72 | bool TournamentManaged::Action(int action, void* parameter) 73 | { 74 | try 75 | { 76 | if(tournamentBase != nullptr) 77 | return tournamentBase->OnAction(static_cast(action), IntPtr(parameter)); 78 | return true; 79 | } 80 | catch(Exception^ ex) 81 | { 82 | Util::LogException("OnAction", ex); 83 | return false; 84 | } 85 | } 86 | 87 | void TournamentManaged::FirstAdvertisement() 88 | { 89 | try 90 | { 91 | if(tournamentBase != nullptr) 92 | tournamentBase->OnFirstAdvertisement(); 93 | } 94 | catch(Exception^ ex) 95 | { 96 | Util::LogException("OnFirstAdvertisement", ex); 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/TournamentManaged.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BroodWar 4 | { 5 | namespace Loader 6 | { 7 | private ref class TournamentManaged abstract sealed 8 | { 9 | private: 10 | static TournamentBase^ tournamentBase; 11 | internal: 12 | static TournamentManaged(); 13 | 14 | static bool Action(int action, void* parameter); 15 | 16 | static void FirstAdvertisement(); 17 | }; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/TournamentModule.cpp: -------------------------------------------------------------------------------- 1 | #pragma unmanaged 2 | 3 | #include 4 | 5 | #include "TournamentModule.h" 6 | 7 | #pragma managed 8 | 9 | #include "TournamentManaged.h" 10 | 11 | using namespace BroodWar::Loader; 12 | 13 | bool TournamentModule::onAction(int actionType, void* parameter) 14 | { 15 | return TournamentManaged::Action(actionType, parameter); 16 | } 17 | 18 | void TournamentModule::onFirstAdvertisement() 19 | { 20 | TournamentManaged::FirstAdvertisement(); 21 | } 22 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/TournamentModule.h: -------------------------------------------------------------------------------- 1 | class TournamentModule : public BWAPI::TournamentModule 2 | { 3 | virtual bool onAction(int actionType, void* parameter = NULL); 4 | virtual void onFirstAdvertisement(); 5 | }; 6 | -------------------------------------------------------------------------------- /Src/BroodwarTournamentLoader/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAIModule/ExampleAIModule.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {60ADD3FE-6C12-41D1-B469-D55A1BBD2C79} 9 | Library 10 | Properties 11 | ExampleAIModule 12 | ExampleAIModule 13 | v4.0 14 | 512 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | true 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | full 29 | x86 30 | prompt 31 | MinimumRecommendedRules.ruleset 32 | 33 | 34 | bin\x86\Release\ 35 | TRACE 36 | true 37 | pdbonly 38 | x86 39 | prompt 40 | MinimumRecommendedRules.ruleset 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | {61E7AE8B-70BB-4266-90E1-926EBC9541FD} 55 | Broodwar 56 | 57 | 58 | 59 | 66 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAIModule/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ExampleAIModule 5 | { 6 | public static class Helper 7 | { 8 | public static IEnumerable Project( 9 | this IEnumerable source, 10 | Func projection) 11 | { 12 | using (var iterator = source.GetEnumerator()) 13 | { 14 | if (!iterator.MoveNext()) 15 | { 16 | yield break; 17 | } 18 | var first = iterator.Current; 19 | var previous = iterator.Current; 20 | while (iterator.MoveNext()) 21 | { 22 | yield return projection(previous, iterator.Current); 23 | previous = iterator.Current; 24 | } 25 | yield return projection(previous, first); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAIModule/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ExampleAIModule")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ExampleAIModule")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("92fbc3ea-5f7a-41ae-954c-e158a7f5aca8")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAIModuleFSharp/ExampleAIModuleFSharp.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | e1ee437a-1e90-4a40-bb14-e80b4542353e 9 | Library 10 | ExampleAIModuleFSharp 11 | ExampleAIModuleFSharp 12 | v4.0 13 | 4.3.1.0 14 | ExampleAIModuleFSharp 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | 3 26 | bin\Debug\ExampleAIModuleFSharp.XML 27 | x86 28 | 29 | 30 | pdbonly 31 | true 32 | true 33 | bin\Release\ 34 | TRACE 35 | 3 36 | bin\Release\ExampleAIModuleFSharp.XML 37 | x86 38 | 39 | 40 | 41 | 42 | True 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Broodwar 55 | {61e7ae8b-70bb-4266-90e1-926ebc9541fd} 56 | True 57 | 58 | 59 | 60 | 11 61 | 62 | 63 | 64 | 65 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 66 | 67 | 68 | 69 | 70 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 71 | 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAiClient/ExampleAiClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {9105589D-441A-4103-BF60-91F8FF12AA42} 9 | Exe 10 | Properties 11 | ExampleAiClient 12 | ExampleAiClient 13 | v4.0 14 | 15 | 16 | 512 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | x86 28 | true 29 | full 30 | false 31 | bin\Debug\ 32 | DEBUG;TRACE 33 | prompt 34 | 4 35 | 36 | 37 | x86 38 | pdbonly 39 | true 40 | bin\Release\ 41 | TRACE 42 | prompt 43 | 4 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | {61E7AE8B-70BB-4266-90E1-926EBC9541FD} 61 | Broodwar 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAiClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ExampleAiClient")] 8 | [assembly: AssemblyProduct("ExampleAiClient")] 9 | 10 | // Setting ComVisible to false makes the types in this assembly not visible 11 | // to COM components. If you need to access a type in this assembly from 12 | // COM, set the ComVisible attribute to true on that type. 13 | [assembly: ComVisible(false)] 14 | 15 | // The following GUID is for the ID of the typelib if this project is exposed to COM 16 | [assembly: Guid("48230606-b2a4-4aa7-ba3e-46e07e28e4ac")] 17 | 18 | // Version information for an assembly consists of the following four values: 19 | // 20 | // Major Version 21 | // Minor Version 22 | // Build Number 23 | // Revision 24 | // 25 | // You can specify all the values or you can default the Build and Revision Numbers 26 | // by using the '*' as shown below: 27 | // [assembly: AssemblyVersion("1.0.*")] 28 | [assembly: AssemblyVersion("0.1.0.0")] 29 | [assembly: AssemblyFileVersion("0.1.0.0")] 30 | -------------------------------------------------------------------------------- /Src/Examples/ExampleAiClient/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Src/Examples/ExampleTournamentModule/CoolEvent.cs: -------------------------------------------------------------------------------- 1 | using BroodWar.Api; 2 | 3 | namespace ExampleTournamentModule 4 | { 5 | internal class CoolEvent 6 | { 7 | public Position Position { get; set; } 8 | public Unit Unit { get; set; } 9 | public int Priority { get; set; } 10 | public int Timer { get; set; } 11 | 12 | public bool IsNone 13 | { 14 | get { return Position == null && Unit == null; } 15 | } 16 | 17 | public override bool Equals(object obj) 18 | { 19 | var other = obj as CoolEvent; 20 | return Equals(other); 21 | } 22 | 23 | public static bool operator == (CoolEvent first, CoolEvent second) 24 | { 25 | if(ReferenceEquals(first, second)) 26 | return true; 27 | if(ReferenceEquals(first, null) || ReferenceEquals(second, null)) 28 | return false; 29 | return first.Position == second.Position 30 | && first.Unit == second.Unit 31 | && first.Priority == second.Priority 32 | && first.Timer == second.Timer; 33 | } 34 | 35 | public static bool operator !=(CoolEvent first, CoolEvent second) 36 | { 37 | return !(first == second); 38 | } 39 | 40 | public bool Equals(CoolEvent other) 41 | { 42 | if(ReferenceEquals(null, other)) 43 | { 44 | return false; 45 | } 46 | if(ReferenceEquals(this, other)) 47 | { 48 | return true; 49 | } 50 | return Equals(other.Position, Position) && Equals(other.Unit, Unit) && other.Priority == Priority && other.Timer == Timer; 51 | } 52 | 53 | public override int GetHashCode() 54 | { 55 | unchecked 56 | { 57 | int result = (Position != null ? Position.GetHashCode() : 0); 58 | result = (result * 397) ^ (Unit != null ? Unit.GetHashCode() : 0); 59 | result = (result * 397) ^ Priority; 60 | result = (result * 397) ^ Timer; 61 | return result; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Src/Examples/ExampleTournamentModule/ExampleTournamentModule.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {7C4F6DF3-9495-47F4-81CB-22DAE4493DED} 9 | Library 10 | Properties 11 | ExampleTournamentModule 12 | ExampleTournamentModule 13 | v4.0 14 | 512 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | true 26 | full 27 | false 28 | bin\Debug\ 29 | DEBUG;TRACE 30 | prompt 31 | 4 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | {61E7AE8B-70BB-4266-90E1-926EBC9541FD} 60 | Broodwar 61 | 62 | 63 | 64 | 71 | -------------------------------------------------------------------------------- /Src/Examples/ExampleTournamentModule/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ExampleTournamentModule")] 8 | [assembly: AssemblyProduct("ExampleTournamentModule")] 9 | [assembly: AssemblyCopyright("Copyright © 2015")] 10 | 11 | // Setting ComVisible to false makes the types in this assembly not visible 12 | // to COM components. If you need to access a type in this assembly from 13 | // COM, set the ComVisible attribute to true on that type. 14 | [assembly: ComVisible(false)] 15 | 16 | // The following GUID is for the ID of the typelib if this project is exposed to COM 17 | [assembly: Guid("7253817f-cfe9-4415-b5c0-6fafaaaddb86")] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("0.1.0.0")] 30 | [assembly: AssemblyFileVersion("0.1.0.0")] 31 | -------------------------------------------------------------------------------- /Src/Examples/ExampleTournamentModule/TournamentModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using BroodWar; 3 | using BroodWar.Api; 4 | using BroodWar.Api.Enum; 5 | 6 | namespace ExampleTournamentModule 7 | { 8 | public class TournamentModule : TournamentBase 9 | { 10 | public override bool OnAction(TournamentAction action, IntPtr parameter) 11 | { 12 | switch (action) 13 | { 14 | case TournamentAction.EnableFlag: 15 | switch ((Flag)parameter.ToInt32()) 16 | { 17 | case Flag.CompleteMapInformation: 18 | case Flag.UserInput: 19 | // Disallow these two flags 20 | return false; 21 | } 22 | // Allow other flags if we add more that don't affect gameplay specifically 23 | return true; 24 | case TournamentAction.PauseGame: 25 | case TournamentAction.RestartGame: 26 | case TournamentAction.ResumeGame: 27 | case TournamentAction.SetFrameSkip: 28 | case TournamentAction.SetGUI: 29 | case TournamentAction.SetLocalSpeed: 30 | case TournamentAction.SetMap: 31 | return false; // Disallow these actions 32 | case TournamentAction.LeaveGame: 33 | case TournamentAction.ChangeRace: 34 | case TournamentAction.SetLatCom: 35 | case TournamentAction.SetTextSize: 36 | case TournamentAction.SendText: 37 | case TournamentAction.Printf: 38 | return true; // Allow these actions 39 | case TournamentAction.SetCommandOptimizationLevel: 40 | return parameter.ToInt32() > Events.MinimumCommandOptimization; 41 | // Set a minimum command optimization level 42 | // to reduce APM with no action loss 43 | } 44 | return true; 45 | } 46 | 47 | public override void OnFirstAdvertisement() 48 | { 49 | Events.IsLeader = true; 50 | Game.SendText("Welcome to tournament!"); 51 | Game.SendText("Brought to you by ."); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Src/bwapicli.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lamarth/BWAPI-CLI/50e36076734dbe6327963b0816d48d275f670bd7/Src/bwapicli.snk --------------------------------------------------------------------------------