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

Method onFrame

bwapi/TestAIModule/Source/MicroTest.cpp:10–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8 Broodwar->setCommandOptimizationLevel(4);
9}
10void MicroTest::onFrame()
11{
12 Position goal=Broodwar->getMousePosition()+Broodwar->getScreenPosition();
13 std::map<Unit , int> targetAdjustedHP;
14 std::map<Unit , Unitset > targetsInRange;
15 std::map<Unit , Unitset > targetGetAttackers;
16 for (Unit e : Broodwar->enemy()->getUnits())
17 {
18 targetAdjustedHP[e]=e->getHitPoints();
19 for (Unit s : Broodwar->self()->getUnits())
20 {
21 if (s->isInWeaponRange(e))
22 {
23 targetAdjustedHP[e]-=5;
24 targetsInRange[s].insert(e);
25 }
26 }
27 }
28 for (Unit s : Broodwar->self()->getUnits())
29 {
30 int minAdjHP=100000;
31 Unit localTarget = NULL;
32 for (Unit e : targetsInRange[s])
33 {
34 if (localTarget == NULL || targetAdjustedHP[e]<minAdjHP)
35 {
36 localTarget = e;
37 minAdjHP = targetAdjustedHP[e];
38 }
39 }
40 targetGetAttackers[localTarget].insert(s);
41 }
42 bool isAttackFrame = false;
43 int maxCoolDown = 0;
44 for (Unit s : Broodwar->self()->getUnits())
45 {
46 isAttackFrame = isAttackFrame || s->isAttackFrame();
47 if (s->getGroundWeaponCooldown() > maxCoolDown)
48 maxCoolDown = s->getGroundWeaponCooldown();
49 }
50 if (lastIsAttackFrame && !isAttackFrame)
51 {
52 Broodwar->issueCommand(Broodwar->self()->getUnits(),UnitCommand::rightClick(NULL,goal));
53 for (Unit s : Broodwar->self()->getUnits())
54 {
55 Broodwar->drawLineMap(s->getPosition(), goal, Colors::Green);
56 }
57 }
58 else
59 {
60 if (maxCoolDown == 0)
61 {
62 for (std::pair<Unit, Unitset> p : targetGetAttackers)
63 {
64 Unit e = p.first;
65 for (Unit s : p.second)
66 {
67 if (Broodwar->getFrameCount() - s->getLastCommandFrame() > 4)

Callers

nothing calls this directly

Calls 15

getHitPointsMethod · 0.80
isInWeaponRangeMethod · 0.80
isAttackFrameMethod · 0.80
drawLineMapMethod · 0.80
getLastCommandFrameMethod · 0.80
drawTextMapMethod · 0.80
getMousePositionMethod · 0.45
getScreenPositionMethod · 0.45
getUnitsMethod · 0.45
enemyMethod · 0.45
selfMethod · 0.45

Tested by

no test coverage detected