-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (88 loc) · 2.45 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <BWAPI.h>
#include <iostream>
#include "Source\ExampleAIModule.h"
void reconnect(BWAPI::Client &BWAPIClient)
{
while (!BWAPIClient.connect())
{
std::this_thread::sleep_for(std::chrono::milliseconds{ 1000 });
}
}
int main(int argc, const char* argv[])
{
NiteKat bot;
std::cout << "Connecting..." << std::endl;
reconnect(bot.BWAPIClient);
while (true)
{
std::cout << "waiting to enter match" << std::endl;
while (!bot.Broodwar->isInGame())
{
while (!bot.BWAPIClient.isConnected())
{
std::cout << "Reconnecting..." << std::endl;
reconnect(bot.BWAPIClient);
}
bot.BWAPIClient.update(bot.Broodwar);
}
bot.onStart();
while (bot.Broodwar->isInGame())
{
for (auto &e : bot.Broodwar->getEvents())
{
switch (e.getType())
{
case BWAPI::EventType::MatchEnd:
bot.onEnd(e.isWinner());
break;
case BWAPI::EventType::SendText:
bot.onSendText(e.getText());
break;
case BWAPI::EventType::ReceiveText:
bot.onReceiveText(e.getPlayer(), e.getText());
break;
case BWAPI::EventType::PlayerLeft:
bot.onPlayerLeft(e.getPlayer());
break;
case BWAPI::EventType::NukeDetect:
bot.onNukeDetect(e.getPosition());
break;
case BWAPI::EventType::UnitDiscover:
bot.onUnitDiscover(e.getUnit());
break;
case BWAPI::EventType::UnitEvade:
bot.onUnitEvade(e.getUnit());
break;
case BWAPI::EventType::UnitShow:
bot.onUnitShow(e.getUnit());
break;
case BWAPI::EventType::UnitHide:
bot.onUnitHide(e.getUnit());
break;
case BWAPI::EventType::UnitCreate:
bot.onUnitCreate(e.getUnit());
break;
case BWAPI::EventType::UnitDestroy:
bot.onUnitDestroy(e.getUnit());
break;
case BWAPI::EventType::UnitMorph:
bot.onUnitMorph(e.getUnit());
break;
case BWAPI::EventType::UnitRenegade:
bot.onUnitRenegade(e.getUnit());
break;
case BWAPI::EventType::SaveGame:
bot.onSaveGame(e.getText());
break;
case BWAPI::EventType::UnitComplete:
bot.onUnitComplete(e.getUnit());
break;
}
}
bot.onFrame();
bot.BWAPIClient.update(bot.Broodwar);
}
bot.Broodwar.initGameData();
}
return 0;
}