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

Method start

bwapi/TestAIModule/Source/TrainTest.cpp:20–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 BWAssertF(producerType!=UnitTypes::Unknown,{fail=true;return;});
19}
20void TrainTest::start()
21{
22 if (fail) return;
23 running = true;
24
25 int producerCount = Broodwar->self()->completedUnitCount(producerType);
26 BWAssertF(producerCount>=1,{fail=true;return;});
27 for (Unit u : Broodwar->self()->getUnits())
28 {
29 if (u->getType()==producerType)
30 {
31 producer = u;
32 break;
33 }
34 }
35 BWAssertF(producer!=NULL,{fail=true;return;});
36
37 BWAssertF(producer->isTraining()==false,{fail=true;return;});
38 BWAssertF(producer->isConstructing()==false,{fail=true;return;});
39 BWAssertF(producer->isIdle()==true,{fail=true;return;});
40 BWAssertF(producer->isLifted()==false,{fail=true;return;});
41 BWAssertF(producer->getTrainingQueue().empty()==true,{log("%s", producer->getTrainingQueue().front().c_str());fail=true;return;});
42 BWAssertF(producer->getRemainingTrainTime() == 0,{fail=true;return;});
43 correctMineralCount = Broodwar->self()->minerals() - unitType.mineralPrice();
44 correctGasCount = Broodwar->self()->gas() - unitType.gasPrice();
45 correctSupplyUsedCount = Broodwar->self()->supplyUsed() + unitType.supplyRequired();
46
47 producer->train(unitType);
48
49 BWAssertF(producer->isTraining()==true,{fail=true;return;});
50 BWAssertF(producer->isConstructing()==false,{fail=true;return;});
51 BWAssertF(producer->isIdle()==false,{fail=true;return;});
52 BWAssertF(producer->isLifted()==false,{fail=true;return;});
53 BWAssertF(producer->getTrainingQueue().size()==1,{fail=true;return;});
54 BWAssertF(*producer->getTrainingQueue().begin()==unitType,{fail=true;return;});
55 BWAssertF(producer->getRemainingTrainTime() == unitType.buildTime(),{fail=true; log("%d == %d (%s)", producer->getRemainingTrainTime(), unitType.buildTime()/10, unitType.c_str()); return;});
56 BWAssertF(Broodwar->self()->minerals() == correctMineralCount,{fail=true;return;});
57 BWAssertF(Broodwar->self()->gas() == correctGasCount,{fail=true;return;});
58 BWAssertF(Broodwar->self()->supplyUsed() == correctSupplyUsedCount,{fail=true;return;});
59
60 startFrame = Broodwar->getFrameCount();
61 nextFrame = startFrame;
62 previousUnitCount = Broodwar->self()->completedUnitCount(unitType);
63
64}
65void TrainTest::update()
66{
67 if (running == false) return;

Callers

nothing calls this directly

Calls 15

logFunction · 0.85
completedUnitCountMethod · 0.80
isTrainingMethod · 0.80
isConstructingMethod · 0.80
isIdleMethod · 0.80
isLiftedMethod · 0.80
getTrainingQueueMethod · 0.80
c_strMethod · 0.80
getRemainingTrainTimeMethod · 0.80
mineralsMethod · 0.80
gasMethod · 0.80
supplyUsedMethod · 0.80

Tested by

no test coverage detected