| 883 | void AIUnit::SendAnswer(Answer answer) |
| 884 | { |
| 885 | if (!IsLocal()) |
| 886 | { |
| 887 | return; |
| 888 | } |
| 889 | AISubgroup* subgrp = GetSubgroup(); |
| 890 | |
| 891 | if (!subgrp) |
| 892 | { |
| 893 | return; |
| 894 | } |
| 895 | AIGroup* grp = subgrp->GetGroup(); |
| 896 | if (!grp) |
| 897 | { |
| 898 | return; |
| 899 | } |
| 900 | if (!grp->IsLocal()) |
| 901 | { |
| 902 | // note: this should be player that wants to transmit some information |
| 903 | // all AI units should be local where group is local |
| 904 | AI_ERROR(IsAnyPlayer()); |
| 905 | if (IsAnyPlayer()) |
| 906 | { |
| 907 | // we need to transmit the message to the remote group |
| 908 | // do two things |
| 909 | // 1) transmit it on the radio |
| 910 | // 2) send answer accross network (done in Transmitted()) |
| 911 | grp->GetRadio().Transmit(new RadioMessageUnitAnswer(this, subgrp, answer), grp->GetCenter()->GetLanguage()); |
| 912 | } |
| 913 | return; // no simulation for remote groups |
| 914 | } |
| 915 | |
| 916 | if (answer == AI::UnitDestroyed) |
| 917 | { |
| 918 | // subgroup does not know it yet (until someone will report it) |
| 919 | // check: dead or deadinrespawn |
| 920 | if (GetLifeState() != LSDead) |
| 921 | { |
| 922 | SetLifeState(LSDead); |
| 923 | GetNetworkManager().UpdateObject(GetPerson()); |
| 924 | GetNetworkManager().UpdateObject(this); |
| 925 | if (grp->Leader() == this) |
| 926 | { |
| 927 | // if we are leader, units expect us to communicate |
| 928 | grp->SetReportBeforeTime(this, Glob.time + 30); |
| 929 | } |
| 930 | |
| 931 | RString identity = GetPerson()->GetInfo()._identityContext; |
| 932 | if (identity.GetLength() > 0) |
| 933 | { |
| 934 | // check if unit is from player group |
| 935 | Person* player = GWorld->GetRealPlayer(); |
| 936 | AIUnit* playerUnit = player ? player->Brain() : nullptr; |
| 937 | AIGroup* playerGroup = playerUnit ? playerUnit->GetGroup() : nullptr; |
| 938 | if (playerGroup == grp) |
| 939 | { |
| 940 | Poseidon::AddDeadIdentity(identity); |
| 941 | } |
| 942 | } |
no test coverage detected