| 1386 | #define MAX_SAFESPAWN_ENTS 4 |
| 1387 | |
| 1388 | bool NPC_SafeSpawn( gentity_t *ent, float safeRadius ) |
| 1389 | { |
| 1390 | gentity_t *radiusEnts[ MAX_SAFESPAWN_ENTS ]; |
| 1391 | vec3_t safeMins, safeMaxs; |
| 1392 | float distance = 999999; |
| 1393 | int numEnts = 0; |
| 1394 | float safeRadiusSquared = safeRadius*safeRadius; |
| 1395 | int i; |
| 1396 | |
| 1397 | if (!ent) |
| 1398 | { |
| 1399 | return false; |
| 1400 | } |
| 1401 | |
| 1402 | //Setup the bbox to search in |
| 1403 | for ( i = 0; i < 3; i++ ) |
| 1404 | { |
| 1405 | safeMins[i] = ent->currentOrigin[i] - safeRadius; |
| 1406 | safeMaxs[i] = ent->currentOrigin[i] + safeRadius; |
| 1407 | } |
| 1408 | |
| 1409 | //Get a number of entities in a given space |
| 1410 | numEnts = gi.EntitiesInBox( safeMins, safeMaxs, radiusEnts, MAX_SAFESPAWN_ENTS ); |
| 1411 | |
| 1412 | for ( i = 0; i < numEnts; i++ ) |
| 1413 | { |
| 1414 | //Don't consider self |
| 1415 | if ( radiusEnts[i] == ent ) |
| 1416 | continue; |
| 1417 | |
| 1418 | if (radiusEnts[i]->NPC && (radiusEnts[i]->health == 0)) |
| 1419 | { |
| 1420 | // ignore dead guys |
| 1421 | continue; |
| 1422 | } |
| 1423 | |
| 1424 | distance = DistanceSquared( ent->currentOrigin, radiusEnts[i]->currentOrigin ); |
| 1425 | |
| 1426 | //Found one too close to us |
| 1427 | if ( distance < safeRadiusSquared ) |
| 1428 | { |
| 1429 | return false; |
| 1430 | } |
| 1431 | } |
| 1432 | return true; |
| 1433 | } |
| 1434 | |
| 1435 | |
| 1436 | /* |
no test coverage detected