rendered paste bodystatic void
spawn_magic_missile (PELEMENT ElementPtr)
{
#define MAGIC_MISSILE_SPEED DISPLAY_TO_WORLD(40)
COUNT orig_facing;
SIZE delta_facing;
STARSHIPPTR StarShipPtr;
MISSILE_BLOCK MissileBlock;
HELEMENT hMissile;
COUNT real_angle;
GetElementStarShip (ElementPtr, &StarShipPtr);
MissileBlock.farray = missileGraphicsHack;
MissileBlock.face = orig_facing = StarShipPtr->ShipFacing;
if ((delta_facing = TrackShip (ElementPtr, &MissileBlock.face)) > 0)
{
if(ElementPtr->hTarget)
{
ELEMENTPTR EnemyPtr;
COUNT num_frames;
SIZE delta_x, delta_y;
LockElement (ElementPtr->hTarget, &EnemyPtr);
delta_x = EnemyPtr->next.location.x
- ElementPtr->next.location.x;
delta_x = WRAP_DELTA_X (delta_x);
delta_y = EnemyPtr->next.location.y
- ElementPtr->next.location.y;
delta_y = WRAP_DELTA_Y (delta_y);
num_frames = (square_root ((long)delta_x * delta_x
+ (long)delta_y * delta_y)) / MAGIC_MISSILE_SPEED;
if (num_frames == 0)
num_frames = 1;
GetNextVelocityComponents (&EnemyPtr->velocity,
&delta_x, &delta_y, num_frames);
delta_x = (EnemyPtr->next.location.x + (delta_x / 2))
- ElementPtr->next.location.x;
delta_y = (EnemyPtr->next.location.y + (delta_y / 2))
- ElementPtr->next.location.y;
real_angle = NORMALIZE_ANGLE(ARCTAN (delta_x, delta_y) + (((TFB_Random() & 3) + 1) / 2) - 1);
MissileBlock.face = MissileBlock.index = ANGLE_TO_FACING (real_angle);
UnlockElement(ElementPtr->hTarget);
}
else MissileBlock.face = MissileBlock.index = NORMALIZE_FACING (orig_facing + delta_facing);
}
MissileBlock.cx = ElementPtr->next.location.x;
MissileBlock.cy = ElementPtr->next.location.y;
MissileBlock.sender = (ElementPtr->state_flags & (GOOD_GUY | BAD_GUY))
| IGNORE_SIMILAR;
MissileBlock.pixoffs = ARILOU_OFFSET;
MissileBlock.preprocess_func = NULL_PTR;
MissileBlock.blast_offs = 4;
MissileBlock.speed = MAGIC_MISSILE_SPEED;
MissileBlock.hit_points = 2;
MissileBlock.damage = 2;
MissileBlock.life = 12;
hMissile = initialize_missile (&MissileBlock);
if (hMissile)
{
ELEMENTPTR MissilePtr;
LockElement(hMissile, &MissilePtr);
SetElementStarShip (MissilePtr, StarShipPtr);
if(ElementPtr->hTarget)
{
SetVelocityComponents(&MissilePtr->velocity,
COSINE(real_angle, WORLD_TO_VELOCITY(MAGIC_MISSILE_SPEED)),
SINE(real_angle, WORLD_TO_VELOCITY(MAGIC_MISSILE_SPEED)));
}
UnlockElement(hMissile);
PutElement(hMissile);
}
ElementPtr->hTarget = 0;
}