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

Method UpdateFormationPos

engine/Poseidon/AI/AISubgroup.cpp:2112–2208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2110 return minUnit;
2111}
2112
2113void AISubgroup::UpdateFormationPos()
2114{
2115 AI_ERROR(GetGroup());
2116 if (!GetGroup())
2117 {
2118 return;
2119 }
2120
2121 int nTanks = 0;
2122 for (int i = 0; i < NUnits(); i++)
2123 {
2124 AIUnit* unit = GetUnit(i);
2125 if (!unit)
2126 {
2127 continue;
2128 }
2129 Transport* veh = unit->GetVehicleIn();
2130 if (!veh)
2131 {
2132 continue;
2133 }
2134 if (!unit->IsUnit())
2135 {
2136 continue;
2137 }
2138 if (veh->GetType()->HasGunner())
2139 {
2140 nTanks++;
2141 }
2142 }
2143
2144 AIUnit* formUnits[MAX_UNITS_PER_GROUP];
2145 Vector3 formPos[MAX_UNITS_PER_GROUP];
2146 for (int i = 0; i < MAX_UNITS_PER_GROUP; i++)
2147 {
2148 formUnits[i] = nullptr;
2149 formPos[i] = VZero;
2150 }
2151
2152 for (int i = 0; i < MAX_UNITS_PER_GROUP; i++)
2153 {
2154 AIUnit* unit = GetGroup()->UnitWithID(i + 1);
2155
2156 int j = i; // formation index given by ID
2157 const FormInfo& info = formations[_formation][j];
2158 formUnits[j] = unit;
2159
2160 formPos[j].Init();
2161 if (info.base >= 0)
2162 {
2163 AIUnit* base = formUnits[info.base];
2164 float fXBase = 1, fZBase = 1;
2165 float fXUnit = 1, fZUnit = 1;
2166 if (base)
2167 {
2168 EntityAI* baseVehicle = base->IsUnit() ? base->GetVehicle() : base->GetPerson();
2169 fXBase = baseVehicle->GetFormationX();

Callers 2

BeginArcadeMethod · 0.80
JoinToSubgroupMethod · 0.80

Calls 13

GetGroupFunction · 0.85
GetUnitFunction · 0.85
GetVehicleInMethod · 0.80
IsUnitMethod · 0.80
UnitWithIDMethod · 0.80
GetPersonMethod · 0.80
HasGunnerMethod · 0.45
GetTypeMethod · 0.45
InitMethod · 0.45
GetVehicleMethod · 0.45
GetFormationXMethod · 0.45
GetFormationZMethod · 0.45

Tested by

no test coverage detected