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

Method add

bwapi/BWAPI/Source/BWAPI/CommandOptimizer.cpp:15–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15bool CommandOptimizer::add(UnitCommand command)
16{
17 // ignore queued and invalid commands, or return if optimizer is disabled
18 if (level == 0 ||
19 command.isQueued() ||
20 command.getType() >= UnitCommandTypes::None)
21 return false;
22
23 // Store some commonly accessed variables
24 UnitCommandType uct = command.getType();
25 Unit utarg = command.getTarget();
26 UnitType targType = utarg ? utarg->getType() : UnitTypes::None;
27 Unit uthis = command.getUnit();
28 UnitType thisType = uthis ? uthis->getType() : UnitTypes::None;
29
30 // Exclude commands that cannot be optimized.
31 if (uct == UnitCommandTypes::Build_Addon ||
32 uct == UnitCommandTypes::Land ||
33 uct == UnitCommandTypes::Build ||
34 uct == UnitCommandTypes::Place_COP ||
35 uct == UnitCommandTypes::Research ||
36 uct == UnitCommandTypes::Upgrade ||
37 (level < 4 &&
38 uct == UnitCommandTypes::Use_Tech_Unit &&
39 (command.getTechType() == TechTypes::Archon_Warp ||
40 command.getTechType() == TechTypes::Dark_Archon_Meld)))
41 return false;
42
43
44 // Simplify some commands if possible to decrease their size
45 if (uct == UnitCommandTypes::Attack_Unit)
46 {
47 // Use Right Click for Attack Unit
48 if (thisType.canAttack() && utarg && Broodwar->self() && Broodwar->self()->isEnemy(utarg->getPlayer()))
49 command.type = UnitCommandTypes::Right_Click_Unit;
50 }
51 else if (uct == UnitCommandTypes::Move)
52 {
53 // Use Right Click for Move
54 command = UnitCommand::rightClick(uthis, command.getTargetPosition());
55 }
56 else if (uct == UnitCommandTypes::Gather)
57 {
58 // Use Right Click for gather
59 if (targType.isResourceContainer())
60 command = UnitCommand::rightClick(uthis, utarg);
61 }
62 else if (uct == UnitCommandTypes::Set_Rally_Position)
63 {
64 // Use Right Click for Set Rally
65 if (thisType.canProduce() &&
66 thisType != UnitTypes::Protoss_Carrier && thisType != UnitTypes::Hero_Gantrithor &&
67 thisType != UnitTypes::Protoss_Reaver && thisType != UnitTypes::Hero_Warbringer)
68 command = UnitCommand::rightClick(uthis, command.getTargetPosition());
69 }
70 else if (uct == UnitCommandTypes::Set_Rally_Unit)
71 {
72 // Use Right Click for Set Rally

Callers 3

prepareIssueCommandMethod · 0.80
naFunction · 0.80

Calls 15

isQueuedMethod · 0.80
getTechTypeMethod · 0.80
isResourceContainerMethod · 0.80
canProduceMethod · 0.80
isSiegedMethod · 0.80
isCloakedMethod · 0.80
isBurrowedMethod · 0.80
isBuildingMethod · 0.80
targetsPositionMethod · 0.80
UnitCommandClass · 0.50
getTypeMethod · 0.45

Tested by

no test coverage detected