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

Method FindRepairPosition

engine/Poseidon/AI/AIGroupImplHealth.cpp:186–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184#define REPAIR_FAR 500.0f
185
186const AITargetInfo* AIGroup::FindRepairPosition(AIUnit::ResourceState state) const
187{
188 if (state == AIUnit::RSNormal)
189 {
190 return nullptr;
191 }
192 AI_ERROR(Leader());
193
194 // find repair in close range
195 const AITargetInfo* depot = nullptr;
196 float dist2Depot = FLT_MAX;
197 const AITargetInfo* truck = nullptr;
198 float dist2Truck = FLT_MAX;
199
200 for (int i = 0; i < GetCenter()->NTargets(); i++)
201 {
202 const AITargetInfo& info = GetCenter()->GetTarget(i);
203 if (!info._type)
204 {
205 continue;
206 }
207 if (!(info._side == TCivilian) && !(GetCenter()->IsFriendly(info._side)))
208 {
209 continue;
210 }
211 if (info._type->GetMaxRepairCargo() <= 0)
212 {
213 continue;
214 }
215 VehicleSupply* veh = dyn_cast<VehicleSupply, Object>(info._idExact);
216 if (!veh)
217 {
218 continue;
219 }
220 if (veh->GetRepairCargo() <= 0)
221 {
222 continue;
223 }
224 if (GetCenter()->GetExposurePessimistic(info._realPos) > 0)
225 {
226 continue;
227 }
228 float dist2 = (Leader()->Position() - info._realPos).SquareSizeXZ();
229
230 if (info._type->IsKindOf(GLOB_WORLD->Preloaded(VTypeStatic)))
231 {
232 if (dist2 < dist2Depot)
233 {
234 dist2Depot = dist2;
235 depot = &info;
236 }
237 }
238 else
239 {
240 if (dist2 < dist2Truck)
241 {
242 dist2Truck = dist2;
243 truck = &info;

Callers 1

IssueCommandMethod · 0.80

Calls 12

GetCenterFunction · 0.85
NTargetsMethod · 0.80
IsFriendlyMethod · 0.80
GetRepairCargoMethod · 0.80
IsKindOfMethod · 0.80
SquareFunction · 0.50
GetTargetMethod · 0.45
GetMaxRepairCargoMethod · 0.45
SquareSizeXZMethod · 0.45
PositionMethod · 0.45
PreloadedMethod · 0.45

Tested by

no test coverage detected