Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ExampleAIClient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,27 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Source\CameraControl.cpp" />
<ClCompile Include="Source\ChatControl.cpp" />
<ClCompile Include="Source\ExampleAIClient.cpp" />
<ClCompile Include="Source\IRCClient.cpp" />
<ClCompile Include="Source\IRCHandler.cpp" />
<ClCompile Include="Source\IRCSocket.cpp" />
<ClCompile Include="Source\Mutex.cpp" />
<ClCompile Include="Source\StringOperations.cpp" />
<ClCompile Include="Source\Thread.cpp" />
<ClCompile Include="Source\WorkerControl.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\CameraControl.h" />
<ClInclude Include="Source\ChatControl.h" />
<ClInclude Include="Source\IRCClient.h" />
<ClInclude Include="Source\IRCHandler.h" />
<ClInclude Include="Source\IRCSocket.h" />
<ClInclude Include="Source\Mutex.h" />
<ClInclude Include="Source\StringOperations.h" />
<ClInclude Include="Source\Thread.h" />
<ClInclude Include="Source\WorkerControl.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
24 changes: 24 additions & 0 deletions ExampleAIClient.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
<ClCompile Include="Source\Mutex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\StringOperations.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\WorkerControl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\CameraControl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\ChatControl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\IRCClient.h">
Expand All @@ -50,5 +62,17 @@
<ClInclude Include="Source\Mutex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\StringOperations.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\WorkerControl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\CameraControl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\ChatControl.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Source/CameraControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "CameraControl.h"

#include <BWAPI.h>

using BWAPI::Broodwar;
using BWAPI::Position;
using BWAPI::Unit;

void centerCameraOnPoint(Position p) {
if(p == BWAPI::Positions::Unknown) {
return;
}
Broodwar->setScreenPosition(p - Position(300, 200)); //experimental testing
}

void centerCameraOnUnit(Unit unit) {
if(!unit) {
return;
}
Position p = unit->getPosition();
if(p == BWAPI::Positions::Unknown) {
return;
}
centerCameraOnPoint(p);
}
9 changes: 9 additions & 0 deletions Source/CameraControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CAMERA_CONTROL_H
#define CAMERA_CONTROL_H

#include <BWAPI.h>

void centerCameraOnPoint(BWAPI::Position p);
void centerCameraOnUnit(BWAPI::Unit unit);

#endif
105 changes: 105 additions & 0 deletions Source/ChatControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#define _WINSOCKAPI_ // stops windows.h including winsock.h
#define NOMINMAX

#include "ChatControl.h"

#include <BWAPI.h>

#include "IRCClient.h"
#include "CameraControl.h"
#include "WorkerControl.h"
#include "Mutex.h"

using namespace BWAPI;

ChatControl::ChatControl(Mutex& gameMutex) : gameMutex(gameMutex) {

}

ChatControl::ChatControl(ChatControl& other) : gameMutex(other.gameMutex) {

}

ChatControl::ChatControl(ChatControl&& control) : gameMutex(control.gameMutex) {

}

ChatControl::~ChatControl() {

}

void ChatControl::operator()(const IRCMessage& message, IRCClient& client) {
std::string text = message.parameters.at(message.parameters.size() - 1);
LockGuard guard(gameMutex);
if(text == "build worker") {
Unitset units = Broodwar->self()->getUnits();
units.remove_if([](Unit i) { return !i->getType().isResourceDepot(); });
if(units.size() > 0) {
Unit u = units.rand();
u->train(Broodwar->self()->getRace().getWorker());
centerCameraOnUnit(u);
}
} else if(text == "send idle workers to mine") {
Unitset units = Broodwar->self()->getUnits();
for(auto it = units.begin(); it != units.end(); it++) {
if(it->getType().isWorker() && it->isIdle()) {
it->gather(it->getClosestUnit(BWAPI::Filter::IsMineralField));
centerCameraOnUnit(*it);
}
}
} else if(text == "build supply depot") {
Unitset units = Broodwar->self()->getUnits();
// Get all our workers
units.remove_if([](Unit i) { return !i->getType().isWorker(); });
units.remove_if([](Unit i) { return !i->canBuild(); });
units.remove_if([](Unit i) { return !i->canBuild(UnitTypes::Terran_Supply_Depot); });
if(units.size() > 0) {
// Choose a random one
Unit worker = units.rand();
//Find the closest place to build one
buildAtClosestLocation(worker, UnitTypes::Terran_Supply_Depot);
centerCameraOnUnit(worker);
}
} else if(text == "build barracks") {
Unitset units = Broodwar->self()->getUnits();
// Get all our workers
units.remove_if([](Unit i) { return !i->getType().isWorker(); });
units.remove_if([](Unit i) { return !i->canBuild(); });
units.remove_if([](Unit i) { return !i->canBuild(UnitTypes::Terran_Barracks); });
if(units.size() > 0) {
// Choose a random one
Unit worker = units.rand();
//Find the closest place to build one
buildAtClosestLocation(worker, UnitTypes::Terran_Barracks);
centerCameraOnUnit(worker);
}
} else if(text == "build marine") {
Unitset units = Broodwar->self()->getUnits();
units.remove_if([](Unit i) { return i->getType().getID() != UnitTypes::Terran_Barracks; });
if(units.size() > 0) {
Unit barracks = units.rand();
if(barracks->train(UnitTypes::Terran_Marine)) {
centerCameraOnUnit(barracks);
}
}
} else if(text == "yolo marines") {
Unitset units = Broodwar->self()->getUnits();
units.remove_if([](Unit i) { return i->getType().getID() != UnitTypes::Terran_Marine; });

Unitset enemyUnits = Broodwar->enemies()[0]->getUnits();
enemyUnits.remove_if([](Unit i) { return !i->getType().isResourceDepot(); });
if(enemyUnits.size() > 0) {

for(auto it = units.begin(); it != units.end(); it++) {
if(!it->attack(PositionOrUnit(enemyUnits.getPosition()))) {
std::cout << "unit failed to attack" << std::endl;
} else {
std::cout << "successful attack!" << std::endl;
}
centerCameraOnUnit(*it);
}
} else {
std::cout << "nothing to attack" << std::endl;
}
}
}
21 changes: 21 additions & 0 deletions Source/ChatControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CHAT_CONTROL
#define CHAT_CONTROL

#include "Mutex.h"
#include "IRCClient.h"

class ChatControl {
private:
Mutex& gameMutex;

ChatControl& operator=(const ChatControl&) {} //deleted
public:
ChatControl(Mutex& gameMutex);
ChatControl(ChatControl& o);
ChatControl(ChatControl&&);
~ChatControl();

void operator()(const IRCMessage& message, IRCClient& client);
};

#endif
Loading