A_SpawnObjectRelative is an action which is used to spawn an Object of a type determined by Var2's lower 16 bits similarly to A_SpawnObjectAbsolute
, but with the location relative to the actor instead. The location's relative Z position to the actor is determined by Var2's upper 16 bits, its relative X position by Var1's upper 16 bits, and its relative Y position by Var1's lower 16 bits. The expressions for this are:
- Var1 = (X×65536)+Y
- Var2 = (Z×65536)+type
If the actor is in reverse gravity when this action is called, the Object spawned will have MF2_OBJECTFLIP
added to its secondary flags. The spawned Object's angle will be set to the actor's own angle.
Attributes |
Use
|
Var 1 |
Upper 16 bits: X position Lower 16 bits: Y position
|
Var 2 |
Upper 16 bits: Z position Lower 16 bits: Object type
|
Code – A_SpawnObjectRelative
|
|
// Function: A_SpawnObjectRelative
//
// Description: Spawns an object relative to the location of the actor
//
// var1:
// var1 >> 16 = x
// var1 & 65535 = y
// var2:
// var2 >> 16 = z
// var2 & 65535 = type
//
void A_SpawnObjectRelative(mobj_t *actor)
{
INT16 x, y, z; // Want to be sure we can use negative values
mobjtype_t type;
mobj_t *mo;
INT32 locvar1 = var1;
INT32 locvar2 = var2;
#ifdef HAVE_BLUA
if (LUA_CallAction("A_SpawnObjectRelative", actor))
return;
#endif
CONS_Debug(DBG_GAMELOGIC, "A_SpawnObjectRelative called from object type %d, var1: %d, var2: %d\n", actor->type, locvar1, locvar2);
x = (INT16)(locvar1>>16);
y = (INT16)(locvar1&65535);
z = (INT16)(locvar2>>16);
type = (mobjtype_t)(locvar2&65535);
// Spawn objects correctly in reverse gravity.
// NOTE: Doing actor->z + actor->height is the bottom of the object while the object has reverse gravity. - Flame
mo = P_SpawnMobj(actor->x + FixedMul(x<<FRACBITS, actor->scale),
actor->y + FixedMul(y<<FRACBITS, actor->scale),
(actor->eflags & MFE_VERTICALFLIP) ? ((actor->z + actor->height - mobjinfo[type].height) - FixedMul(z<<FRACBITS, actor->scale)) : (actor->z + FixedMul(z<<FRACBITS, actor->scale)), type);
// Spawn objects with an angle matching the spawner's, rather than spawning Eastwards - Monster Iestyn
mo->angle = actor->angle;
if (actor->eflags & MFE_VERTICALFLIP)
mo->flags2 |= MF2_OBJECTFLIP;
}
|
|