Move a few mobj spawn defaults to its own function

This commit is contained in:
Jaime Ita Passos 2020-12-06 17:46:35 -03:00
parent 24ba782144
commit 6f9c48a305
3 changed files with 46 additions and 71 deletions

View file

@ -279,6 +279,7 @@ mobjtype_t P_GetMobjtype(UINT16 mthingtype);
void P_RespawnSpecials(void); void P_RespawnSpecials(void);
mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type); mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type);
void P_SetMobjSpawnDefaults(mobj_t *mobj);
void P_RecalcPrecipInSector(sector_t *sector); void P_RecalcPrecipInSector(sector_t *sector);
void P_PrecipitationEffects(void); void P_PrecipitationEffects(void);

View file

@ -10438,44 +10438,11 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
mobj->x = x; mobj->x = x;
mobj->y = y; mobj->y = y;
mobj->radius = info->radius;
mobj->height = info->height;
mobj->flags = info->flags;
mobj->health = (info->spawnhealth ? info->spawnhealth : 1);
mobj->reactiontime = info->reactiontime;
mobj->lastlook = -1; // stuff moved in P_enemy.P_LookForPlayer
// do not set the state with P_SetMobjState,
// because action routines can not be called yet
st = &states[info->spawnstate];
mobj->state = st;
mobj->tics = st->tics;
mobj->sprite = st->sprite;
mobj->frame = st->frame; // FF_FRAMEMASK for frame, and other bits..
P_SetupStateAnimation(mobj, st);
mobj->friction = ORIG_FRICTION;
mobj->movefactor = FRACUNIT;
// All mobjs are created at 100% scale.
mobj->scale = FRACUNIT;
mobj->destscale = mobj->scale;
mobj->scalespeed = FRACUNIT/12;
// TODO: Make this a special map header // TODO: Make this a special map header
if ((maptol & TOL_ERZ3) && !(mobj->type == MT_BLACKEGGMAN)) if ((maptol & TOL_ERZ3) && !(mobj->type == MT_BLACKEGGMAN))
mobj->destscale = FRACUNIT/2; mobj->destscale = FRACUNIT/2;
// Sprite rendering P_SetMobjSpawnDefaults(mobj);
mobj->blendmode = AST_TRANSLUCENT;
mobj->spritexscale = mobj->spriteyscale = mobj->scale;
mobj->spritexoffset = mobj->spriteyoffset = 0;
mobj->floorspriteslope = NULL;
// set subsector and/or block links // set subsector and/or block links
P_SetThingPosition(mobj); P_SetThingPosition(mobj);
@ -10785,6 +10752,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
mobj->frame &= ~FF_FRAMEMASK; mobj->frame &= ~FF_FRAMEMASK;
} }
st = &states[info->spawnstate];
// Call action functions when the state is set // Call action functions when the state is set
if (st->action.acp1 && (mobj->flags & MF_RUNSPAWNFUNC)) if (st->action.acp1 && (mobj->flags & MF_RUNSPAWNFUNC))
{ {
@ -10815,6 +10784,45 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
return mobj; return mobj;
} }
void P_SetMobjSpawnDefaults(mobj_t *mobj)
{
const mobjinfo_t *info = mobj->info;
state_t *st = &states[info->spawnstate];
mobj->radius = info->radius;
mobj->height = info->height;
mobj->flags = info->flags;
mobj->health = (info->spawnhealth ? info->spawnhealth : 1);
mobj->reactiontime = info->reactiontime;
mobj->lastlook = -1; // stuff moved in P_enemy.P_LookForPlayer
// do not set the state with P_SetMobjState,
// because action routines can not be called yet
mobj->state = st;
mobj->tics = st->tics;
mobj->sprite = st->sprite;
mobj->frame = st->frame; // FF_FRAMEMASK for frame, and other bits..
P_SetupStateAnimation(mobj, st);
mobj->friction = ORIG_FRICTION;
mobj->movefactor = FRACUNIT;
// All mobjs are created at 100% scale.
mobj->scale = FRACUNIT;
mobj->destscale = mobj->scale;
mobj->scalespeed = FRACUNIT/12;
// Sprite rendering
mobj->blendmode = AST_TRANSLUCENT;
mobj->spritexscale = mobj->spriteyscale = mobj->scale;
mobj->spritexoffset = mobj->spriteyoffset = 0;
mobj->floorspriteslope = NULL;
}
static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
{ {
state_t *st; state_t *st;

View file

@ -2692,7 +2692,10 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
} }
mobj->type = i; mobj->type = i;
} }
mobj->info = &mobjinfo[mobj->type]; mobj->info = &mobjinfo[mobj->type];
P_SetMobjSpawnDefaults(mobj);
if (diff & MD_POS) if (diff & MD_POS)
{ {
mobj->x = READFIXED(save_p); mobj->x = READFIXED(save_p);
@ -2718,35 +2721,21 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
if (diff & MD_RADIUS) if (diff & MD_RADIUS)
mobj->radius = READFIXED(save_p); mobj->radius = READFIXED(save_p);
else
mobj->radius = mobj->info->radius;
if (diff & MD_HEIGHT) if (diff & MD_HEIGHT)
mobj->height = READFIXED(save_p); mobj->height = READFIXED(save_p);
else
mobj->height = mobj->info->height;
if (diff & MD_FLAGS) if (diff & MD_FLAGS)
mobj->flags = READUINT32(save_p); mobj->flags = READUINT32(save_p);
else
mobj->flags = mobj->info->flags;
if (diff & MD_FLAGS2) if (diff & MD_FLAGS2)
mobj->flags2 = READUINT32(save_p); mobj->flags2 = READUINT32(save_p);
if (diff & MD_HEALTH) if (diff & MD_HEALTH)
mobj->health = READINT32(save_p); mobj->health = READINT32(save_p);
else
mobj->health = mobj->info->spawnhealth;
if (diff & MD_RTIME) if (diff & MD_RTIME)
mobj->reactiontime = READINT32(save_p); mobj->reactiontime = READINT32(save_p);
else
mobj->reactiontime = mobj->info->reactiontime;
if (diff & MD_STATE) if (diff & MD_STATE)
mobj->state = &states[READUINT16(save_p)]; mobj->state = &states[READUINT16(save_p)];
else
mobj->state = &states[mobj->info->spawnstate];
if (diff & MD_TICS) if (diff & MD_TICS)
mobj->tics = READINT32(save_p); mobj->tics = READINT32(save_p);
else
mobj->tics = mobj->state->tics;
if (diff & MD_SPRITE) { if (diff & MD_SPRITE) {
mobj->sprite = READUINT16(save_p); mobj->sprite = READUINT16(save_p);
if (mobj->sprite == SPR_PLAY) if (mobj->sprite == SPR_PLAY)
@ -2762,11 +2751,6 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->frame = READUINT32(save_p); mobj->frame = READUINT32(save_p);
mobj->anim_duration = READUINT16(save_p); mobj->anim_duration = READUINT16(save_p);
} }
else
{
mobj->frame = mobj->state->frame;
mobj->anim_duration = (UINT16)mobj->state->var2;
}
if (diff & MD_EFLAGS) if (diff & MD_EFLAGS)
mobj->eflags = READUINT16(save_p); mobj->eflags = READUINT16(save_p);
if (diff & MD_PLAYER) if (diff & MD_PLAYER)
@ -2783,20 +2767,14 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->threshold = READINT32(save_p); mobj->threshold = READINT32(save_p);
if (diff & MD_LASTLOOK) if (diff & MD_LASTLOOK)
mobj->lastlook = READINT32(save_p); mobj->lastlook = READINT32(save_p);
else
mobj->lastlook = -1;
if (diff & MD_TARGET) if (diff & MD_TARGET)
mobj->target = (mobj_t *)(size_t)READUINT32(save_p); mobj->target = (mobj_t *)(size_t)READUINT32(save_p);
if (diff & MD_TRACER) if (diff & MD_TRACER)
mobj->tracer = (mobj_t *)(size_t)READUINT32(save_p); mobj->tracer = (mobj_t *)(size_t)READUINT32(save_p);
if (diff & MD_FRICTION) if (diff & MD_FRICTION)
mobj->friction = READFIXED(save_p); mobj->friction = READFIXED(save_p);
else
mobj->friction = ORIG_FRICTION;
if (diff & MD_MOVEFACTOR) if (diff & MD_MOVEFACTOR)
mobj->movefactor = READFIXED(save_p); mobj->movefactor = READFIXED(save_p);
else
mobj->movefactor = FRACUNIT;
if (diff & MD_FUSE) if (diff & MD_FUSE)
mobj->fuse = READINT32(save_p); mobj->fuse = READINT32(save_p);
if (diff & MD_WATERTOP) if (diff & MD_WATERTOP)
@ -2805,16 +2783,10 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->waterbottom = READFIXED(save_p); mobj->waterbottom = READFIXED(save_p);
if (diff & MD_SCALE) if (diff & MD_SCALE)
mobj->scale = READFIXED(save_p); mobj->scale = READFIXED(save_p);
else
mobj->scale = FRACUNIT;
if (diff & MD_DSCALE) if (diff & MD_DSCALE)
mobj->destscale = READFIXED(save_p); mobj->destscale = READFIXED(save_p);
else
mobj->destscale = mobj->scale;
if (diff2 & MD2_SCALESPEED) if (diff2 & MD2_SCALESPEED)
mobj->scalespeed = READFIXED(save_p); mobj->scalespeed = READFIXED(save_p);
else
mobj->scalespeed = FRACUNIT/12;
if (diff2 & MD2_CUSVAL) if (diff2 & MD2_CUSVAL)
mobj->cusval = READINT32(save_p); mobj->cusval = READINT32(save_p);
if (diff2 & MD2_CVMEM) if (diff2 & MD2_CVMEM)
@ -2845,16 +2817,10 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->renderflags = READUINT32(save_p); mobj->renderflags = READUINT32(save_p);
if (diff2 & MD2_BLENDMODE) if (diff2 & MD2_BLENDMODE)
mobj->blendmode = READINT32(save_p); mobj->blendmode = READINT32(save_p);
else
mobj->blendmode = AST_TRANSLUCENT;
if (diff2 & MD2_SPRITEXSCALE) if (diff2 & MD2_SPRITEXSCALE)
mobj->spritexscale = READFIXED(save_p); mobj->spritexscale = READFIXED(save_p);
else
mobj->spritexscale = FRACUNIT;
if (diff2 & MD2_SPRITEYSCALE) if (diff2 & MD2_SPRITEYSCALE)
mobj->spriteyscale = READFIXED(save_p); mobj->spriteyscale = READFIXED(save_p);
else
mobj->spriteyscale = FRACUNIT;
if (diff2 & MD2_SPRITEXOFFSET) if (diff2 & MD2_SPRITEXOFFSET)
mobj->spritexoffset = READFIXED(save_p); mobj->spritexoffset = READFIXED(save_p);
if (diff2 & MD2_SPRITEYOFFSET) if (diff2 & MD2_SPRITEYOFFSET)