| 13 | |
| 14 | |
| 15 | bool 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 |
no test coverage detected