MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / GetFormationRelative

Method GetFormationRelative

engine/Poseidon/AI/AIUnit.cpp:1541–1590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1539// check size of formation
1540
1541static float FormSize(AISubgroup* subgrp)
1542{
1543 return 0.0f;
1544}
1545
1546Vector3 AIUnit::GetFormationRelative() const
1547{
1548 // most common case
1549 // no need to calculate formation size
1550 if (_formPos == AI::PosInFormation)
1551 {
1552 return _formationPos;
1553 }
1554 // relative to leader
1555 // consider formation position (advance etc...)
1556 Vector3 offset = VZero;
1557 // calculate formation size
1558 float sizeX = 0;
1559 float sizeZ = 0;
1560 AISubgroup* subgrp = GetSubgroup();
1561 for (int i = 0; i < subgrp->NUnits(); i++)
1562 {
1563 AIUnit* unit = subgrp->GetUnit(i);
1564 if (!unit)
1565 {
1566 continue;
1567 }
1568 EntityAI* veh = unit->GetVehicle();
1569 sizeX += veh->GetFormationX();
1570 sizeZ += veh->GetFormationZ();
1571 }
1572 if (subgrp->NUnits() < 8)
1573 {
1574 float nCoef = 8.0 / subgrp->NUnits();
1575 sizeX *= nCoef;
1576 sizeZ *= nCoef;
1577 }
1578 float coef = _formPosCoef;
1579 switch (_formPos)
1580 {
1581 case AI::PosAdvance:
1582 offset[2] += sizeZ * coef;
1583 break;
1584 case AI::PosStayBack:
1585 offset[2] -= sizeZ * coef;
1586 break;
1587 case AI::PosFlankLeft:
1588 offset[0] -= sizeX * coef;
1589 break;
1590 case AI::PosFlankRight:
1591 offset[0] += sizeX * coef;
1592 break;
1593 }

Callers 6

AIPilotMethod · 0.80
AIPilotMethod · 0.80
GetFormationAbsoluteMethod · 0.80
DrawDiagsMethod · 0.80
FormationPilotMethod · 0.80
DrawTargetInfoMethod · 0.80

Calls 5

GetUnitMethod · 0.80
NUnitsMethod · 0.45
GetVehicleMethod · 0.45
GetFormationXMethod · 0.45
GetFormationZMethod · 0.45

Tested by

no test coverage detected