-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
62 lines (57 loc) · 1.44 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
55
56
57
58
59
60
61
62
#include <BWAPI.h>
#include <BWAPI/Client.h>
#include <iostream>
#include <thread>
#include <chrono>
#include <memory>
#include "Source/CampaignBot.h"
void reconnect()
{
while (!BWAPI::BWAPIClient.connect())
{
std::this_thread::sleep_for(std::chrono::milliseconds{ 1000 });
}
}
int main()
{
std::cout << "Connecting..." << std::endl;
reconnect();
while (true)
{
//std::unique_ptr<CampaignBot> bot;
std::cout << "waiting to enter match" << std::endl;
while (!BWAPI::Broodwar->isInGame())
{
BWAPI::BWAPIClient.update();
if (!BWAPI::BWAPIClient.isConnected())
{
std::cout << "Reconnecting..." << std::endl;
reconnect();
}
}
std::cout << "starting match!" << std::endl;
std::cout << "Map: " << BWAPI::Broodwar->mapName() << std::endl;
BWAPI::Broodwar->enableFlag(BWAPI::Flag::UserInput);
while (BWAPI::Broodwar->isInGame())
{
for (auto& e : BWAPI::Broodwar->getEvents())
{
switch (e.getType())
{
case BWAPI::EventType::MatchStart:
bot = std::make_unique<CampaignBot>();
break;
case BWAPI::EventType::SendText:
BWAPI::Broodwar->sendText(e.getText().c_str());
break;
default:
break;
}
}
auto& allUnits = BWAPI::Broodwar->getAllUnits();
if (BWAPI::Broodwar->getFrameCount() > 0)
bot->onFrame();
BWAPI::BWAPIClient.update();
}
}
}