| 859 | } |
| 860 | |
| 861 | void AIGroup::SendTarget(Target* target, bool engage, bool fire, PackedBoolArray list, bool silent) |
| 862 | { |
| 863 | AIUnit* leader = Leader(); |
| 864 | if (!leader) |
| 865 | { |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | for (int i = 0; i < MAX_UNITS_PER_GROUP; i++) |
| 870 | { |
| 871 | if (!list.Get(i)) |
| 872 | { |
| 873 | continue; |
| 874 | } |
| 875 | AIUnit* unit = UnitWithID(i + 1); |
| 876 | if (!unit) |
| 877 | { |
| 878 | list.Set(i, false); |
| 879 | continue; |
| 880 | } |
| 881 | |
| 882 | if (target) |
| 883 | { |
| 884 | EntityAI* tgtAI = target->idExact; |
| 885 | if (tgtAI == unit->GetVehicleIn() || tgtAI == unit->GetPerson()) |
| 886 | { |
| 887 | // unit cannot target itself |
| 888 | list.Set(i, false); |
| 889 | continue; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | // check if unit is already doing what we tell it |
| 894 | if (TargetSent(unit) == target && (!fire || target == FireSent(unit)) && |
| 895 | (!engage || target == EngageSent(unit))) |
| 896 | { |
| 897 | list.Set(i, false); |
| 898 | continue; |
| 899 | } |
| 900 | if (unit == leader || silent) |
| 901 | { |
| 902 | // leader - direct processing |
| 903 | if (!target) |
| 904 | { |
| 905 | target = unit->GetTargetAssigned(); |
| 906 | } |
| 907 | else |
| 908 | { |
| 909 | unit->AssignTarget(target); |
| 910 | } |
| 911 | if (target) |
| 912 | { |
| 913 | if (fire) |
| 914 | { |
| 915 | unit->EnableFireTarget(target); |
| 916 | } |
| 917 | if (engage) |
| 918 | { |
no test coverage detected