I have just found that the op4ctf flag owner problem isn't fixed correctly. actually there're quite a lot of places checking pent->v.owner and all of them need to check pent->v.origin as well:
(actually I think this is a bug of OP4. the "owner" field is just not nulled out when someone lost the flag and we have to use a "hack" like this to "fix" it)
Code:
else if ((mod_id == GEARBOX_DLL) && (pent_info_ctfdetect != NULL))
{
pent = NULL;
while ((pent = UTIL_FindEntityByClassname( pent, "item_ctfflag" )) != NULL)
{
// is this bot carrying the item? (after capture bug fix by Whistler)
if ((pent->v.owner == pEdict) && (pent->v.origin == pEdict->v.origin))
{
// we are carrying the flag
bot_has_flag = TRUE;
break; // break out of while loop
}
else if (FInViewCone( &pent->v.origin, pEdict ) &&
FVisible( pent->v.origin, pEdict))
{
// the bot can see it, check what type of model it is...
skin = pent->v.skin;
if (skin == 0) // Opposing Force team (these are BACKASSWARDS!)
skin = 1;
else if (skin == 1) // Black Mesa team
skin = 0;
// see if the flag matches the bot's team...
if (skin == team)
{
// is and enemy carrying our flag/card?
if (pent->v.owner != NULL)
{
+ if (pent->v.origin == pent->v.owner->v.origin)
+ {
// kill the man with the flag/card!
pBot->pBotEnemy = pent->v.owner;
pBot->waypoint_goal = -1; // forget the goal (if there is one)
return TRUE;
+ }
}
}
else // flag/card is for another team!
{
// check if someone is NOT carrying the flag/card...
+ bool bIsCarrying = FALSE;
+ if (!FNullEnt(pent->v.owner))
+ {
+ if (pent->v.origin == pent->v.owner->v.origin)
+ bIsCarrying = TRUE;
+ }
- if (pent->v.owner == NULL)
+ if (bIsCarrying)
{
// find the nearest waypoint to the flag/card...
index = WaypointFindNearest(pent->v.origin, pEdict, 500, team);
if (index == -1)
{
// no waypoint is close enough, just head straight towards the flag/card
Vector v_flag = pent->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
else
{
waypoint_distance = (waypoints[index].origin - pent->v.origin).Length();
distance = (pent->v.origin - pEdict->v.origin).Length();
// is the bot closer to the flag/card than the waypoint is?
if (distance < waypoint_distance)
{
// just head towards the flag/card
Vector v_flag = pent->v.origin - pEdict->v.origin;
Vector bot_angles = UTIL_VecToAngles( v_flag );
pEdict->v.ideal_yaw = bot_angles.y;
BotFixIdealYaw(pEdict);
return TRUE;
}
else
{
// head towards this waypoint
pBot->waypoint_goal = index;
// remember where the flag/card is located...
pBot->waypoint_near_flag = TRUE;
pBot->waypoint_flag_origin = pent->v.origin;
}
}
}
}
}
}
}