| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | void AISubgroup::JoinToSubgroup(AISubgroup* subgrp) |
| 1421 | { |
| 1422 | AI_ERROR(subgrp); |
| 1423 | AI_ERROR(subgrp != this); |
| 1424 | if (subgrp == this) |
| 1425 | { |
| 1426 | Fail("Join with themselves."); |
| 1427 | return; |
| 1428 | } |
| 1429 | AI_ERROR(subgrp->GetGroup() == GetGroup()); |
| 1430 | if (subgrp->GetGroup() != GetGroup()) |
| 1431 | { |
| 1432 | Fail("Join to another group"); |
| 1433 | return; |
| 1434 | } |
| 1435 | AI_ERROR(this != GetGroup()->MainSubgroup()); |
| 1436 | |
| 1437 | PoseidonAssert(AssertValid()); |
| 1438 | |
| 1439 | ClearAllCommands(); |
| 1440 | |
| 1441 | while (_units.Size() > 0) |
| 1442 | { |
| 1443 | Ref<AIUnit> unit = _units[0]; |
| 1444 | _units.Delete(0); |
| 1445 | if (!unit) |
| 1446 | { |
| 1447 | Fail("No unit"); |
| 1448 | continue; |
| 1449 | } |
| 1450 | if (unit->GetSubgroup() != this) |
| 1451 | { |
| 1452 | Fail("Bad structure"); |
| 1453 | } |
| 1454 | // remove explicitly - avoid refresh of destroyed subgroup |
| 1455 | unit->_subgroup = nullptr; |
| 1456 | subgrp->AddUnit(unit); |
| 1457 | } |
| 1458 | RemoveFromGroup(); |
| 1459 | |
| 1460 | subgrp->SelectLeader(); |
| 1461 | subgrp->RefreshPlan(); |
| 1462 | subgrp->UpdateFormationPos(); |
| 1463 | |
| 1464 | PoseidonAssert(subgrp->AssertValid()); |
| 1465 | } |
| 1466 | |
| 1467 | // Mind |
no test coverage detected