Skip to content

Commit

Permalink
- consolidated movesprite_ex functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Mar 27, 2023
1 parent 0c7e265 commit 3cf2a49
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 162 deletions.
85 changes: 85 additions & 0 deletions source/games/duke/src/actors.cpp
Expand Up @@ -983,6 +983,91 @@ void hitradius(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int hp4
}
}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------


int movesprite_ex(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result)
{
int bg = badguy(actor);

if (actor->spr.statnum == STAT_MISC || (bg && actor->spr.scale.X < 0.0625))
{
actor->spr.pos += change;
if (bg)
SetActor(actor, actor->spr.pos);
return result.setNone();
}

auto dasectp = actor->sector();

auto ppos = actor->spr.pos;

auto tex = TexMan.GetGameTexture(actor->spr.spritetexture());
ppos.Z -= tex->GetDisplayHeight() * actor->spr.scale.Y * 0.5;

if (bg)
{
if (actor->spr.scale.X > 0.9375)
clipmove(ppos, &dasectp, change * 0.5, 64., 4., 4., cliptype, result);
else
{
// todo: move this mess to the actor definitions once we have them all available.
double clipdist = actor->FloatVar(NAME_moveclipdist);
if (clipdist == 0)
{
if ((actor->flags1 & SFLAG_BADGUY) && !isRR())
clipdist = actor->clipdist;
else
clipdist = 12;
}

clipmove(ppos, &dasectp, change * 0.5, clipdist, 4., 4., cliptype, result);
}

// conditional code from hell...
if (dasectp == nullptr || (dasectp != nullptr &&
((actor->actorstayput != nullptr && actor->actorstayput != dasectp) ||
((actor->flags3 & SFLAG3_ST3CONFINED) && actor->spr.pal == 0 && dasectp->lotag != ST_3_BOSS2) ||
((actor->flags3 & SFLAG3_DONTENTERWATER) && dasectp->lotag == ST_1_ABOVE_WATER) ||
((actor->flags3 & SFLAG3_DONTENTERWATERONGROUND) && actor->vel.Z == 0 && dasectp->lotag == ST_1_ABOVE_WATER))
)
)
{
if (dasectp && dasectp->lotag == ST_1_ABOVE_WATER && (actor->flags3 & SFLAG3_RANDOMANGLEONWATER))
actor->spr.Angles.Yaw = randomAngle();
else if ((actor->counter & 3) == 1 && !(actor->flags3 & SFLAG3_NORANDOMANGLEWHENBLOCKED))
actor->spr.Angles.Yaw = randomAngle();
SetActor(actor, actor->spr.pos);
if (dasectp == nullptr) dasectp = &sector[0];
return result.setSector(dasectp);
}
if ((result.type == kHitWall || result.type == kHitSprite) && (actor->cgg == 0)) actor->spr.Angles.Yaw += DAngle90 + DAngle45;
}
else
{
if (actor->spr.statnum == STAT_PROJECTILE)
clipmove(ppos, &dasectp, change * 0.5, 0.5, 4., 4., cliptype, result);
else
clipmove(ppos, &dasectp, change * 0.5, actor->clipdist, 4., 4., cliptype, result);
}
actor->spr.pos.XY() = ppos.XY();

if (dasectp != nullptr && dasectp != actor->sector())
ChangeActorSect(actor, dasectp);

double daz = actor->spr.pos.Z + change.Z * 0.5;
if (daz > actor->ceilingz && daz <= actor->floorz)
actor->spr.pos.Z = daz;
else if (result.type == kHitNone)
return result.setSector(dasectp);

return result.type;
}

//---------------------------------------------------------------------------
//
// Rotating sector
Expand Down
84 changes: 0 additions & 84 deletions source/games/duke/src/actors_d.cpp
Expand Up @@ -141,90 +141,6 @@ int ifsquished(DDukeActor* actor, int p)
return false;
}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------


int movesprite_ex_d(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision &result)
{
int bg = badguy(actor);

if (actor->spr.statnum == STAT_MISC || (bg && actor->spr.scale.X < 0.0625))
{
actor->spr.pos += change;
if (bg)
SetActor(actor, actor->spr.pos);
return result.setNone();
}

auto dasectp = actor->sector();

auto ppos = actor->spr.pos;

auto tex = TexMan.GetGameTexture(actor->spr.spritetexture());
ppos.Z -= tex->GetDisplayHeight() * actor->spr.scale.Y * 0.5;

if (bg)
{
if (actor->spr.scale.X > 0.9375 )
clipmove(ppos, &dasectp, change * 0.5, 64., 4., 4., cliptype, result);
else
{
// todo: move this mess to the actor definitions once we have them all available.
double clipdist = actor->FloatVar(NAME_moveclipdist);
if (clipdist == 0)
{
if ((actor->flags1 & SFLAG_BADGUY) && !isRR())
clipdist = actor->clipdist;
else
clipdist = 12;
}

clipmove(ppos, &dasectp, change * 0.5, clipdist, 4., 4., cliptype, result);
}

// conditional code from hell...
if (dasectp == nullptr || (dasectp != nullptr &&
((actor->actorstayput != nullptr && actor->actorstayput != dasectp) ||
((actor->flags3 & SFLAG3_ST3CONFINED) && actor->spr.pal == 0 && dasectp->lotag != ST_3_BOSS2) ||
((actor->flags3 & SFLAG3_DONTENTERWATER) && dasectp->lotag == ST_1_ABOVE_WATER) ||
((actor->flags3 & SFLAG3_DONTENTERWATERONGROUND) && actor->vel.Z == 0 && dasectp->lotag == ST_1_ABOVE_WATER))
)
)
{
if (dasectp && dasectp->lotag == ST_1_ABOVE_WATER && (actor->flags3 & SFLAG3_RANDOMANGLEONWATER))
actor->spr.Angles.Yaw = randomAngle();
else if ((actor->counter&3) == 1 && !(actor->flags3 & SFLAG3_NORANDOMANGLEWHENBLOCKED))
actor->spr.Angles.Yaw = randomAngle();
SetActor(actor,actor->spr.pos);
if (dasectp == nullptr) dasectp = &sector[0];
return result.setSector(dasectp);
}
if ((result.type == kHitWall || result.type == kHitSprite) && (actor->cgg == 0)) actor->spr.Angles.Yaw += DAngle90 + DAngle45;
}
else
{
if (actor->spr.statnum == STAT_PROJECTILE)
clipmove(ppos, &dasectp, change * 0.5, 0.5, 4., 4., cliptype, result);
else
clipmove(ppos, &dasectp, change * 0.5, actor->clipdist, 4., 4., cliptype, result);
}
actor->spr.pos.XY() = ppos.XY();

if (dasectp != nullptr && dasectp != actor->sector())
ChangeActorSect(actor, dasectp);

double daz = actor->spr.pos.Z + change.Z * 0.5;
if (daz > actor->ceilingz && daz <= actor->floorz)
actor->spr.pos.Z = daz;
else if (result.type == kHitNone)
return result.setSector(dasectp);

return result.type;
}
//---------------------------------------------------------------------------
//
//
Expand Down
66 changes: 0 additions & 66 deletions source/games/duke/src/actors_r.cpp
Expand Up @@ -140,72 +140,6 @@ void addweapon_r(player_struct* p, int weapon, bool wswitch)
}
}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

int movesprite_ex_r(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision &result)
{
int bg = badguy(actor);

if (actor->spr.statnum == 5 || (bg && actor->spr.scale.X < 0.0625))
{
actor->spr.pos += change;
if (bg)
SetActor(actor, actor->spr.pos);
return result.setNone();
}

auto dasectp = actor->sector();

auto ppos = actor->spr.pos;
auto tex = TexMan.GetGameTexture(actor->spr.spritetexture());
ppos.Z -= tex->GetDisplayHeight() * actor->spr.scale.Y * 0.5;

if (bg)
{
if (actor->spr.scale.X > 0.9375 )
clipmove(ppos, &dasectp, change * 0.5, 64., 4., 4., cliptype, result);
else
{
clipmove(ppos, &dasectp, change * 0.5, 12., 4., 4., cliptype, result);
}

if (dasectp == nullptr || (dasectp != nullptr && actor->actorstayput != nullptr && actor->actorstayput != dasectp))
{
if (dasectp && dasectp->lotag == ST_1_ABOVE_WATER)
actor->spr.Angles.Yaw = randomAngle();
else if ((actor->counter & 3) == 1)
actor->spr.Angles.Yaw = randomAngle();
SetActor(actor, actor->spr.pos);
if (dasectp == nullptr) dasectp = &sector[0];
return result.setSector(dasectp);
}
if ((result.type == kHitWall || result.type == kHitSprite) && (actor->cgg == 0)) actor->spr.Angles.Yaw += DAngle45 + DAngle90;
}
else
{
if (actor->spr.statnum == STAT_PROJECTILE)
clipmove(ppos, &dasectp, change * 0.5, 0.5, 4., 4., cliptype, result);
else
clipmove(ppos, &dasectp, change * 0.5, actor->clipdist, 4., 4., cliptype, result);
}
actor->spr.pos.XY() = ppos.XY();

if (dasectp)
if ((dasectp != actor->sector()))
ChangeActorSect(actor, dasectp);
double daz = actor->spr.pos.Z + change.Z * 0.5;
if (daz > actor->ceilingz && daz <= actor->floorz)
actor->spr.pos.Z = daz;
else if (result.type == kHitNone)
return result.setSector(dasectp);

return result.type;
}

//---------------------------------------------------------------------------
//
//
Expand Down
12 changes: 0 additions & 12 deletions source/games/duke/src/dukeactor.h
Expand Up @@ -32,16 +32,4 @@ inline int bossguy(DDukeActor* pSprite)
return pSprite->flags1 & SFLAG_BOSS;
}

// old interface versions of already changed functions

int movesprite_ex_d(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result);
int movesprite_ex_r(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result);

inline int movesprite_ex(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result)
{
auto f = isRR() ? movesprite_ex_r : movesprite_ex_d;
return f(actor, change, cliptype, result);
}


END_DUKE_NS
1 change: 1 addition & 0 deletions source/games/duke/src/funct.h
Expand Up @@ -41,6 +41,7 @@ void clearcameras(player_struct* p);
void RANDOMSCRAP(DDukeActor* i);
void detonate(DDukeActor* i, PClassActor* explosion);
void hitradius(DDukeActor* i, int r, int hp1, int hp2, int hp3, int hp4);
int movesprite_ex(DDukeActor* actor, const DVector3& change, unsigned int cliptype, Collision& result);
void lotsofstuff(DDukeActor* s, int n, PClassActor* spawntype);
void watersplash2(DDukeActor* i);
bool money(DDukeActor* i, int BLOODPOOL);
Expand Down

0 comments on commit 3cf2a49

Please sign in to comment.