MCPcopy Create free account
hub / github.com/bwapi/bwapi / onStart

Method onStart

bwapi/ExampleAIModule/Source/ExampleAIModule.cpp:7–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace Filter;
6
7void ExampleAIModule::onStart()
8{
9 // Hello World!
10 Broodwar->sendText("Hello world!");
11
12 // Print the map name.
13 // BWAPI returns std::string when retrieving a string, don't forget to add .c_str() when printing!
14 Broodwar << "The map is " << Broodwar->mapName() << "!" << std::endl;
15
16 // Enable the UserInput flag, which allows us to control the bot and type messages.
17 Broodwar->enableFlag(Flag::UserInput);
18
19 // Uncomment the following line and the bot will know about everything through the fog of war (cheat).
20 //Broodwar->enableFlag(Flag::CompleteMapInformation);
21
22 // Set the command optimization level so that common commands can be grouped
23 // and reduce the bot's APM (Actions Per Minute).
24 Broodwar->setCommandOptimizationLevel(2);
25
26 // Check if this is a replay
27 if ( Broodwar->isReplay() )
28 {
29
30 // Announce the players in the replay
31 Broodwar << "The following players are in this replay:" << std::endl;
32
33 // Iterate all the players in the game using a std:: iterator
34 Playerset players = Broodwar->getPlayers();
35 for(auto p : players)
36 {
37 // Only print the player if they are not an observer
38 if ( !p->isObserver() )
39 Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
40 }
41
42 }
43 else // if this is not a replay
44 {
45 // Retrieve you and your enemy's races. enemy() will just return the first enemy.
46 // If you wish to deal with multiple enemies then you must use enemies().
47 if ( Broodwar->enemy() ) // First make sure there is an enemy
48 Broodwar << "The matchup is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;
49 }
50
51}
52
53void ExampleAIModule::onEnd(bool isWinner)
54{

Callers

nothing calls this directly

Calls 11

sendTextMethod · 0.80
isObserverMethod · 0.80
mapNameMethod · 0.45
enableFlagMethod · 0.45
isReplayMethod · 0.45
getPlayersMethod · 0.45
getNameMethod · 0.45
getRaceMethod · 0.45
enemyMethod · 0.45
selfMethod · 0.45

Tested by

no test coverage detected