Beispiel #1
0
static bool CanSeeAPlayer(const TActor *a)
{
    const Vec2i realPos = Vec2iFull2Real(a->Pos);
    CA_FOREACH(const PlayerData, p, gPlayerDatas)
    if (!IsPlayerAlive(p))
    {
        continue;
    }
    const TActor *player = ActorGetByUID(p->ActorUID);
    const Vec2i playerRealPos = Vec2iFull2Real(player->Pos);
    // Can see player if:
    // - Clear line of sight, and
    // - If they are close, or if facing and they are not too far
    if (!AIHasClearShot(realPos, playerRealPos))
    {
        continue;
    }
    const int distance = CHEBYSHEV_DISTANCE(
                             realPos.x, realPos.y, playerRealPos.x, playerRealPos.y);
    const bool isClose = distance < 16 * 4;
    const bool isNotTooFar = distance < 16 * 30;
    if (isClose ||
            (isNotTooFar && AIIsFacing(a, player->Pos, a->direction)))
    {
        return true;
    }
    CA_FOREACH_END()
    return false;
}
Beispiel #2
0
static bool CanSeeAPlayer(const TActor *a)
{
	const Vec2i realPos = Vec2iFull2Real(a->Pos);
	for (int i = 0; i < MAX_PLAYERS; i++)
	{
		if (!IsPlayerAlive(i))
		{
			continue;
		}
		const TActor *player = CArrayGet(&gActors, gPlayerIds[i]);
		const Vec2i playerRealPos = Vec2iFull2Real(player->Pos);
		// Can see player if:
		// - Clear line of sight, and
		// - If they are close, or if facing and they are not too far
		if (!AIHasClearShot(realPos, playerRealPos))
		{
			continue;
		}
		const int distance = CHEBYSHEV_DISTANCE(
			realPos.x, realPos.y, playerRealPos.x, playerRealPos.y);
		const bool isClose = distance < 16 * 4;
		const bool isNotTooFar = distance < 16 * 30;
		if (isClose ||
			(isNotTooFar && IsFacing(realPos, playerRealPos, a->direction)))
		{
			return true;
		}
	}
	return false;
}