// Function: A_SnailerThink
//
// Description: Thinker function for Snailer
//
// var1 = unused
// var2 = unused
//
void A_SnailerThink(mobj_t *actor)
{
#ifdef HAVE_BLUA
if (LUA_CallAction("A_SnailerThink", actor))
return;
#endif
if (!actor->target || !(actor->target->flags & MF_SHOOTABLE))
{
// look for a new target
if (!P_LookForPlayers(actor, true, false, 0))
return;
}
// We now have a target. Oh bliss, rapture, and contentment!
if (actor->target->z + actor->target->height > actor->z - FixedMul(32*FRACUNIT, actor->scale)
&& actor->target->z < actor->z + actor->height + FixedMul(32*FRACUNIT, actor->scale)
&& !(leveltime % (TICRATE*2)))
{
angle_t an;
fixed_t z;
// Actor shouldn't face target, so we'll do things a bit differently here
an = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) - actor->angle;
z = actor->z + actor->height/2;
if (an > ANGLE_45 && an < ANGLE_315) // fire as close as you can to the target, even if too sharp an angle from your front
{
fixed_t dist;
fixed_t dx, dy;
dist = P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y);
if (an > ANGLE_45 && an <= ANGLE_90) // fire at 45 degrees to the left
{
dx = actor->x + P_ReturnThrustX(actor, actor->angle + ANGLE_45, dist);
dy = actor->y + P_ReturnThrustY(actor, actor->angle + ANGLE_45, dist);
}
else if (an >= ANGLE_270 && an < ANGLE_315) // fire at 45 degrees to the right
{
dx = actor->x + P_ReturnThrustX(actor, actor->angle - ANGLE_45, dist);
dy = actor->y + P_ReturnThrustY(actor, actor->angle - ANGLE_45, dist);
}
else // fire straight ahead
{
dx = actor->x + P_ReturnThrustX(actor, actor->angle, dist);
dy = actor->y + P_ReturnThrustY(actor, actor->angle, dist);
}
P_SpawnPointMissile(actor, dx, dy, actor->target->z, MT_ROCKET, actor->x, actor->y, z);
}
else
P_SpawnXYZMissile(actor, actor->target, MT_ROCKET, actor->x, actor->y, z);
}
if ((!(actor->eflags & MFE_VERTICALFLIP) && actor->target->z > actor->z)
|| (actor->eflags & MFE_VERTICALFLIP && (actor->target->z + actor->target->height) > (actor->z + actor->height)))
actor->momz += FixedMul(actor->info->speed, actor->scale);
else if ((!(actor->eflags & MFE_VERTICALFLIP) && actor->target->z < actor->z)
|| (actor->eflags & MFE_VERTICALFLIP && (actor->target->z + actor->target->height) < (actor->z + actor->height)))
actor->momz -= FixedMul(actor->info->speed, actor->scale);
actor->momz /= 2;
}