| 35 | { |
| 36 | |
| 37 | void AIGroup::IssueCommand(Command& cmd, PackedBoolArray list) |
| 38 | { |
| 39 | if (list.IsEmpty()) |
| 40 | { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | AIUnit* leader = Leader(); |
| 45 | // if leader is not alive, he should not be able to send commands |
| 46 | if (leader && leader->GetLifeState() != AIUnit::LSAlive) |
| 47 | { |
| 48 | // auto commands may be issued even without leader alive |
| 49 | if (cmd._context != Command::CtxAuto && cmd._context != Command::CtxAutoSilent) |
| 50 | { |
| 51 | LOG_DEBUG(AI, "IssueCommand: No command, leader {} is not alive", (const char*)leader->GetDebugName()); |
| 52 | return; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if (cmd._message == Command::GetOut) |
| 57 | { |
| 58 | // Get Out processed by units |
| 59 | int i; |
| 60 | for (i = 0; i < MAX_UNITS_PER_GROUP; i++) |
| 61 | { |
| 62 | if (!list[i]) |
| 63 | { |
| 64 | continue; |
| 65 | } |
| 66 | AIUnit* unit = UnitWithID(i + 1); |
| 67 | if (!unit) |
| 68 | { |
| 69 | continue; |
| 70 | } |
| 71 | |
| 72 | if (unit->IsFreeSoldier()) |
| 73 | { |
| 74 | continue; |
| 75 | } |
| 76 | |
| 77 | AISubgroup* subgrp = unit->GetSubgroup(); |
| 78 | AI_ERROR(subgrp); |
| 79 | if (subgrp != MainSubgroup() && subgrp->NUnits() == 1) |
| 80 | { |
| 81 | cmd._joinToSubgroup = nullptr; |
| 82 | subgrp->ReceiveCommand(cmd); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | if (cmd._context == Command::CtxAuto || cmd._context == Command::CtxAutoSilent) |
| 87 | { |
| 88 | cmd._joinToSubgroup = subgrp; |
| 89 | } |
| 90 | subgrp = new AISubgroup(); |
| 91 | AddSubgroup(subgrp); |
| 92 | subgrp->AddUnit(unit); |
| 93 | subgrp->SelectLeader(unit); |
| 94 | if (GWorld->GetMode() == GModeNetware) |
no test coverage detected