@@ -1574,53 +1574,39 @@ int WaypointAddOrigin(const Vector& vOrigin, const int iFlags, edict_t* pEntity,
15741574 if (pEnt->v .owner != nullptr )
15751575 continue ;
15761576
1577- Vector vEntOrigin = EntityOrigin (pEnt);
1577+ const Vector vEntOrigin = EntityOrigin (pEnt);
15781578
15791579 UTIL_TraceLine (vOrigin, vEntOrigin, ignore_monsters, pEntity, &tr);
15801580
1581- if (tr.flFraction >= 1 .0f || tr.pHit == pEnt)
1582- {
1583- const char * szClassname = STRING (pEnt->v .classname );
1581+ if (tr.flFraction < 1 .0f && tr.pHit != pEnt)
1582+ continue ; // Entity not visible, skip
15841583
1585- if (!szClassname)
1586- return 0 ; // Ensure szClassname is not null
1584+ const char * szClassname = STRING (pEnt->v .classname );
15871585
1588- if (std::strncmp (szClassname, " ammo_" , 5 ) == 0 )
1589- {
1590- new_waypoint->flags |= W_FL_AMMO;
1591- }
1592- else if (std::strncmp (szClassname, " weapon_" , 7 ) == 0 )
1593- {
1594- new_waypoint->flags |= W_FL_WEAPON;
1595- }
1596- else if (std::strncmp (szClassname, " item_health" , 11 ) == 0 ||
1597- std::strncmp (szClassname, " item_healthkit" , 14 ) == 0 ||
1598- std::strncmp (szClassname, " func_healthcharger" , 18 ) == 0 )
1599- {
1600- new_waypoint->flags |= W_FL_HEALTH;
1601- }
1602- else if (std::strncmp (szClassname, " item_armor" , 10 ) == 0 ||
1603- std::strncmp (szClassname, " item_battery" , 12 ) == 0 ||
1604- std::strncmp (szClassname, " func_recharge" , 13 ) == 0 )
1605- {
1606- new_waypoint->flags |= W_FL_ARMOR;
1607- }
1586+ if (!szClassname || !szClassname[0 ])
1587+ continue ; // Skip invalid classnames, don't abort
16081588
1609- return 1 ; // Return true to indicate success
1610- }
1611- }
1612-
1613- if (pEntity && bSound)
1614- {
1615- UTIL_PlaySound (pEntity, " weapons/xbow_hit1.wav" );
1616- // UTIL_PlaySound(pEntity,"weapons/xbow_hit1.wav");
1617- //
1589+ if (std::strncmp (szClassname, " ammo_" , 5 ) == 0 )
1590+ new_waypoint->flags |= W_FL_AMMO;
1591+ else if (std::strncmp (szClassname, " weapon_" , 7 ) == 0 )
1592+ new_waypoint->flags |= W_FL_WEAPON;
1593+ else if (std::strncmp (szClassname, " item_health" , 11 ) == 0 ||
1594+ std::strncmp (szClassname, " item_healthkit" , 14 ) == 0 ||
1595+ std::strncmp (szClassname, " func_healthcharger" , 18 ) == 0 )
1596+ new_waypoint->flags |= W_FL_HEALTH;
1597+ else if (std::strncmp (szClassname, " item_armor" , 10 ) == 0 ||
1598+ std::strncmp (szClassname, " item_battery" , 12 ) == 0 ||
1599+ std::strncmp (szClassname, " func_recharge" , 13 ) == 0 )
1600+ new_waypoint->flags |= W_FL_ARMOR;
16181601 }
16191602
16201603 // increment total number of waypoints if adding at end of array...
16211604 if (index == num_waypoints)
16221605 num_waypoints++;
16231606
1607+ if (pEntity && bSound)
1608+ UTIL_PlaySound (pEntity, " weapons/xbow_hit1.wav" );
1609+
16241610 if (gBotGlobals .m_bAutoPathWaypoint )
16251611 {
16261612 // calculate all the paths to this new waypoint
@@ -1636,27 +1622,22 @@ int WaypointAddOrigin(const Vector& vOrigin, const int iFlags, edict_t* pEntity,
16361622
16371623 UTIL_TraceLine (vOrigin, temp_waypoint->origin , ignore_monsters, ignore_glass, nullptr , &tr);
16381624
1639- WaypointVisibility.SetVisibilityFromTo (index, i, tr.flFraction >= 1 .0f );
1640- WaypointVisibility.SetVisibilityFromTo (i, index, tr.flFraction >= 1 .0f );
1625+ const bool bVisible = tr.flFraction >= 1 .0f ;
1626+ WaypointVisibility.SetVisibilityFromTo (index, i, bVisible);
1627+ WaypointVisibility.SetVisibilityFromTo (i, index, bVisible);
16411628
16421629 // check if the waypoint is reachable from the new one (one-way)
16431630 if (WaypointReachable (vOrigin, temp_waypoint->origin ))
1644- {
16451631 WaypointAddPath (static_cast <short >(index), static_cast <short >(i));
1646- }
16471632
16481633 // check if the new one is reachable from the waypoint (other way)
16491634 if (WaypointReachable (temp_waypoint->origin , vOrigin))
1650- {
16511635 WaypointAddPath (static_cast <short >(i), static_cast <short >(index));
1652- }
16531636 }
16541637 }
16551638
16561639 if (pEntity && bDraw)
1657- {
16581640 WaypointDrawIndex (pEntity, index);
1659- }
16601641
16611642 WaypointLocations.AddWptLocation (index, vOrigin);
16621643
@@ -2377,9 +2358,7 @@ Vector WaypointOrigin(const int iWaypointIndex)
23772358
23782359int WaypointFlags (const int iWaypointIndex)
23792360{
2380- // assert ( iWaypointIndex != -1 );
2381-
2382- if (iWaypointIndex < 0 || iWaypointIndex > MAX_WAYPOINTS)
2361+ if (iWaypointIndex < 0 || iWaypointIndex >= MAX_WAYPOINTS)
23832362 {
23842363 // BotMessage(NULL,0,"Caution: WaypointFlags() received invalid waypoint index!");
23852364 return 0 ;
0 commit comments