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

Method update

bwapi/TestAIModule/Source/TrainTest.cpp:65–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64}
65void TrainTest::update()
66{
67 if (running == false) return;
68 if (fail)
69 {
70 running = false;
71 return;
72 }
73 int thisFrame = Broodwar->getFrameCount();
74 BWAssert(thisFrame==nextFrame);
75 BWAssertF(producer!=NULL,{fail=true;return;});
76 nextFrame++;
77 Broodwar->setScreenPosition(producer->getPosition() - Position(320,240));
78 int correctRemainingTrainTime = startFrame + Broodwar->getLatency() + unitType.buildTime()/10 - thisFrame + 1;
79 if (Broodwar->getLatency()==5)
80 correctRemainingTrainTime += 1;
81 if (correctRemainingTrainTime > unitType.buildTime()/10)
82 correctRemainingTrainTime = unitType.buildTime()/10;
83 if (correctRemainingTrainTime < 0)
84 correctRemainingTrainTime = 0;
85
86 // @TODO: Workaround
87 if ( thisFrame <= startFrame + Broodwar->getLatency() )
88 {
89 BWAssertF(producer->getRemainingTrainTime()/10 == correctRemainingTrainTime,{log("%d Error %d != %d",thisFrame-startFrame,producer->getRemainingTrainTime()/10, correctRemainingTrainTime);});
90 }
91 else
92 {
93 BWAssertF(producer->getRemainingTrainTime() == correctRemainingTrainTime,{log("%d Error %d != %d %s",thisFrame-startFrame,producer->getRemainingTrainTime(), correctRemainingTrainTime, producer->getType().c_str());});
94 }
95
96 int lastFrame = startFrame + Broodwar->getLatency() + unitType.buildTime()/10;
97 if (Broodwar->getLatency()==5)
98 lastFrame++;
99 if (unitType==UnitTypes::Terran_Nuclear_Missile)
100 lastFrame++;
101 if (thisFrame>lastFrame) //terminate condition
102 {
103 running = false;
104 return;
105 }
106 BWAssertF(producer->isTraining()==true,{log("%s: %s, %s", producer->getType().c_str(), producer->getOrder().c_str(), producer->getSecondaryOrder().c_str());Broodwar->printf("%d",thisFrame-startFrame);fail=true;return;});
107 BWAssertF(producer->isConstructing()==false,{fail=true;return;});
108 BWAssertF(producer->isIdle()==false,{fail=true;return;});
109 BWAssertF(producer->isLifted()==false,{fail=true;return;});
110 BWAssertF(producer->getTrainingQueue().size()==1,{log("%d tq size = %d",thisFrame-startFrame,producer->getTrainingQueue().size());fail=true;return;});
111 BWAssertF(producer->getTrainingQueue().front()==unitType,{fail=true;return;});
112 BWAssertF(Broodwar->self()->minerals() == correctMineralCount,{fail=true;return;});
113 BWAssertF(Broodwar->self()->gas() == correctGasCount,{fail=true;return;});
114 BWAssertF(Broodwar->self()->supplyUsed() == correctSupplyUsedCount,{Broodwar->printf("%d: %d!=%d",thisFrame-startFrame,Broodwar->self()->supplyUsed(),correctSupplyUsedCount);fail=true;return;});
115 BWAssertF(Broodwar->self()->completedUnitCount(unitType) == previousUnitCount,{fail=true;return;});
116}
117
118void TrainTest::stop()
119{

Callers

nothing calls this directly

Calls 15

logFunction · 0.85
buildTimeMethod · 0.80
getRemainingTrainTimeMethod · 0.80
c_strMethod · 0.80
isTrainingMethod · 0.80
getSecondaryOrderMethod · 0.80
printfMethod · 0.80
isConstructingMethod · 0.80
isIdleMethod · 0.80
isLiftedMethod · 0.80
getTrainingQueueMethod · 0.80
mineralsMethod · 0.80

Tested by

no test coverage detected