MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / FindNearest

Method FindNearest

src/SB/Game/zNPCSupport.cpp:255–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253}
254
255S32 NPCTarget::FindNearest(S32 flg_consider, xBase* skipme, xVec3* from, F32 dst_max)
256{
257 S32 found = 0;
258 st_XORDEREDARRAY* npclist;
259 F32 ds2_best;
260 zNPCCommon *npc, *npc_best;
261 xVec3 vec = {};
262 F32 fv;
263 S32 i, ntyp;
264
265 npc_best = NULL;
266 ds2_best = (dst_max < 0.0f) ? HUGE : SQ(dst_max);
267
268 if (flg_consider & 0x1)
269 {
270 this->TargetSet(&globals.player.ent, 1);
271
272 if (from)
273 {
274 xVec3Sub(&vec, xEntGetPos(&globals.player.ent), from);
275 ds2_best = xVec3Length2(&vec);
276 }
277 }
278
279 if (from && (flg_consider & 0x1E))
280 {
281 npclist = zNPCMgr_GetNPCList();
282
283 for (i = 0; i < npclist->cnt; i++)
284 {
285 npc = (zNPCCommon*)npclist->list[i];
286 ntyp = npc->SelfType();
287
288 if (npc == skipme)
289 continue;
290
291 if (((ntyp & 0xFFFFFF00) != 'NTT\0' || (flg_consider & 0x4)) &&
292 ((ntyp & 0xFFFFFF00) != 'NTR\0' || (flg_consider & 0x2)) &&
293 ((ntyp & 0xFFFFFF00) != 'NTF\0' || (flg_consider & 0x8)) &&
294 ((ntyp & 0xFFFFFF00) != 'NTA\0' || (flg_consider & 0x10)))
295 {
296 if (npc->IsAlive())
297 {
298 xVec3Sub(&vec, xEntGetPos(npc), from);
299 if (flg_consider & 0x80)
300 {
301 vec.y = 0.0f;
302 }
303
304 fv = xVec3Length2(&vec);
305 if (fv > ds2_best)
306 continue;
307
308 ds2_best = fv;
309 npc_best = npc;
310 found = 1;
311 }
312 }

Callers 1

MonitorCoweringMethod · 0.80

Calls 7

TargetSetMethod · 0.95
xVec3SubFunction · 0.85
xEntGetPosFunction · 0.85
xVec3Length2Function · 0.85
zNPCMgr_GetNPCListFunction · 0.85
SelfTypeMethod · 0.80
IsAliveMethod · 0.45

Tested by

no test coverage detected