| 63 | |
| 64 | } |
| 65 | void 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 | |
| 118 | void TrainTest::stop() |
| 119 | { |
nothing calls this directly
no test coverage detected