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

Method update

bwapi/TestAIModule/Source/UpgradeTest.cpp:69–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67
68}
69void UpgradeTest::update()
70{
71 if (running == false) return;
72 if (fail)
73 {
74 running = false;
75 return;
76 }
77 int thisFrame = Broodwar->getFrameCount();
78 BWAssert(thisFrame==nextUpdateFrame);
79 BWAssertF(upgrader!=NULL,{fail=true;LOGTYPE;return;});
80 nextUpdateFrame++;
81 Broodwar->setScreenPosition(upgrader->getPosition() - Position(320,240));
82
83 // NOTE: /15*15 is to account for the editor not displaying the real times
84 int expectedUpgradeTime = (upgradeType.upgradeTime()/15/10*15) + (upgradeType.upgradeTimeFactor()/15/10*15) * (std::max(0,previousUpgradeLevel+1-1));
85
86 int correctRemainingUpgradeTime = startUpgradeFrame + Broodwar->getLatency() + expectedUpgradeTime - thisFrame;
87 if (correctRemainingUpgradeTime > expectedUpgradeTime)
88 correctRemainingUpgradeTime = expectedUpgradeTime;
89 if (correctRemainingUpgradeTime < 0)
90 correctRemainingUpgradeTime = 0;
91
92 // @TODO: Workaround
93 if ( thisFrame <= startUpgradeFrame + Broodwar->getLatency() )
94 {
95 BWAssertF(upgrader->getRemainingUpgradeTime() == upgradeType.upgradeTime(previousUpgradeLevel+1),{log("%d %d",upgrader->getRemainingUpgradeTime(), upgradeType.upgradeTime(previousUpgradeLevel+1));});
96 }
97 else
98 {
99 BWAssertF(upgrader->getRemainingUpgradeTime() == correctRemainingUpgradeTime,{log("%d %d",upgrader->getRemainingUpgradeTime(), correctRemainingUpgradeTime);});
100 }
101
102 int lastFrame = startUpgradeFrame+Broodwar->getLatency() + expectedUpgradeTime;
103 if (thisFrame>lastFrame) //terminate condition
104 {
105 running = false;
106 return;
107 }
108 BWAssertF(upgrader->getOrder()==Orders::Upgrade,{fail=true;LOGTYPE;return;});
109 BWAssertF(upgrader->isIdle()==false,{fail=true;LOGTYPE;return;});
110 BWAssertF(upgrader->isLifted()==false,{fail=true;LOGTYPE;return;});
111 BWAssertF(upgrader->isResearching()==false,{fail=true;LOGTYPE;return;});
112 BWAssertF(upgrader->isUpgrading()==true,{fail=true;LOGTYPE;return;});
113 BWAssertF(upgrader->getTech()==TechTypes::None,{fail=true;LOGTYPE;return;});
114 BWAssertF(upgrader->getUpgrade()==upgradeType,{fail=true;LOGTYPE;return;});
115 BWAssertF(upgrader->getRemainingResearchTime()==0,{fail=true;LOGTYPE;return;});
116 BWAssertF(Broodwar->self()->getUpgradeLevel(upgradeType)==previousUpgradeLevel,{fail=true;LOGTYPE;return;});
117 BWAssertF(Broodwar->self()->minerals() == correctMineralCount,{fail=true;LOGTYPE;return;});
118 BWAssertF(Broodwar->self()->gas() == correctGasCount,{fail=true;LOGTYPE;return;});
119}
120
121void UpgradeTest::stop()
122{

Callers

nothing calls this directly

Calls 15

logFunction · 0.85
upgradeTimeMethod · 0.80
upgradeTimeFactorMethod · 0.80
isIdleMethod · 0.80
isLiftedMethod · 0.80
getUpgradeMethod · 0.80
getUpgradeLevelMethod · 0.80
mineralsMethod · 0.80
gasMethod · 0.80
PositionClass · 0.50

Tested by

no test coverage detected