2020-10-17 07:14:31 +00:00
|
|
|
#pragma once
|
|
|
|
#include "dobject.h"
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
BEGIN_DUKE_NS
|
|
|
|
|
|
|
|
|
|
|
|
// Iterator wrappers that return an actor pointer, not an index.
|
|
|
|
class DukeStatIterator : public StatIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DukeStatIterator(int stat) : StatIterator(stat)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DDukeActor *Next()
|
|
|
|
{
|
|
|
|
int n = NextIndex();
|
|
|
|
return n >= 0? &hittype[n] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDukeActor *Peek()
|
|
|
|
{
|
|
|
|
int n = PeekIndex();
|
|
|
|
return n >= 0? &hittype[n] : nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DukeSectIterator : public SectIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DukeSectIterator(int stat) : SectIterator(stat)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-15 21:44:16 +00:00
|
|
|
DukeSectIterator(sectortype* stat) : SectIterator(stat)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:14:31 +00:00
|
|
|
DDukeActor *Next()
|
|
|
|
{
|
|
|
|
int n = NextIndex();
|
|
|
|
return n >= 0? &hittype[n] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDukeActor *Peek()
|
|
|
|
{
|
|
|
|
int n = PeekIndex();
|
|
|
|
return n >= 0? &hittype[n] : nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-17 07:26:52 +00:00
|
|
|
// An interator to iterate over all sprites.
|
|
|
|
class DukeSpriteIterator
|
|
|
|
{
|
|
|
|
DukeStatIterator it;
|
|
|
|
int stat = STAT_DEFAULT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DukeSpriteIterator() : it(STAT_DEFAULT) {}
|
|
|
|
|
|
|
|
DDukeActor* Next()
|
|
|
|
{
|
|
|
|
while (stat < MAXSTATUS)
|
|
|
|
{
|
|
|
|
auto ac = it.Next();
|
|
|
|
if (ac) return ac;
|
|
|
|
stat++;
|
|
|
|
if (stat < MAXSTATUS) it.Reset(stat);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-27 06:15:03 +00:00
|
|
|
class DukeLinearSpriteIterator
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
public:
|
|
|
|
|
|
|
|
DDukeActor* Next()
|
|
|
|
{
|
|
|
|
while (index < MAXSPRITES)
|
|
|
|
{
|
|
|
|
auto p = &hittype[index++];
|
2021-04-15 17:21:43 +00:00
|
|
|
if (p->s->statnum != MAXSTATUS) return p;
|
2020-10-27 06:15:03 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-17 07:26:52 +00:00
|
|
|
inline DDukeActor* player_struct::GetActor()
|
|
|
|
{
|
|
|
|
return &hittype[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int player_struct::GetPlayerNum()
|
|
|
|
{
|
2021-04-15 17:21:43 +00:00
|
|
|
return GetActor()->s->yvel;
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Refactoring helpers/intermediates
|
2021-08-27 14:25:58 +00:00
|
|
|
inline void changeactorstat(DDukeActor* a, int newstat)
|
2020-10-17 07:26:52 +00:00
|
|
|
{
|
2021-10-24 07:22:35 +00:00
|
|
|
::changespritestat(a->GetSpriteIndex(), newstat);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:38:53 +00:00
|
|
|
inline void changeactorsect(DDukeActor* a, int newsect)
|
2020-10-17 07:26:52 +00:00
|
|
|
{
|
2021-10-24 07:22:35 +00:00
|
|
|
::changespritesect(a->GetSpriteIndex(), newsect);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 00:10:50 +00:00
|
|
|
inline void changeactorsect(DDukeActor* a, sectortype* newsect)
|
|
|
|
{
|
|
|
|
::changespritesect(a->GetSpriteIndex(), sectnum(newsect));
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:26:52 +00:00
|
|
|
inline int setsprite(DDukeActor* a, int x, int y, int z)
|
|
|
|
{
|
2021-10-24 07:22:35 +00:00
|
|
|
return ::setsprite(a->GetSpriteIndex(), x, y, z);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int setsprite(DDukeActor* a, const vec3_t& pos)
|
|
|
|
{
|
2021-10-24 07:22:35 +00:00
|
|
|
return ::setsprite(a->GetSpriteIndex(), pos.x, pos.y, pos.z);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see comment for changespritestat.
|
|
|
|
inline int setsprite(int i, int x, int y, int z)
|
|
|
|
{
|
|
|
|
return ::setsprite(i, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int ActorToScriptIndex(DDukeActor* a)
|
|
|
|
{
|
|
|
|
if (!a) return -1;
|
2021-10-24 07:22:35 +00:00
|
|
|
return a->GetSpriteIndex();
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline DDukeActor* ScriptIndexToActor(int index)
|
|
|
|
{
|
2020-10-17 08:30:11 +00:00
|
|
|
// only allow valid actors to get through here. Everything else gets null'ed.
|
2021-04-15 17:21:43 +00:00
|
|
|
if (index < 0 || index >= MAXSPRITES || hittype[index].s->statnum == MAXSTATUS) return nullptr;
|
2020-10-17 07:26:52 +00:00
|
|
|
return &hittype[index];
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:41:50 +00:00
|
|
|
DDukeActor* spawn(DDukeActor* spawner, int type);
|
2020-10-17 07:26:52 +00:00
|
|
|
|
|
|
|
inline int ldist(DDukeActor* s1, DDukeActor* s2)
|
|
|
|
{
|
2021-04-15 17:21:43 +00:00
|
|
|
return ldist(s1->s, s2->s);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int dist(DDukeActor* s1, DDukeActor* s2)
|
|
|
|
{
|
2021-04-15 17:21:43 +00:00
|
|
|
return dist(s1->s, s2->s);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int badguy(DDukeActor* pSprite)
|
|
|
|
{
|
2021-04-15 17:21:43 +00:00
|
|
|
return badguypic(pSprite->s->picnum);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int bossguy(DDukeActor* pSprite)
|
|
|
|
{
|
2021-04-15 17:21:43 +00:00
|
|
|
return bossguypic(pSprite->s->picnum);
|
2020-10-17 07:26:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 17:14:41 +00:00
|
|
|
// old interface versions of already changed functions
|
|
|
|
|
|
|
|
inline void deletesprite(int num)
|
|
|
|
{
|
|
|
|
deletesprite(&hittype[num]);
|
|
|
|
}
|
|
|
|
|
2020-10-24 07:31:15 +00:00
|
|
|
int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result);
|
|
|
|
int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result);
|
|
|
|
|
|
|
|
inline int movesprite_ex(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result)
|
|
|
|
{
|
|
|
|
auto f = isRR() ? movesprite_ex_r : movesprite_ex_d;
|
|
|
|
return f(actor, xchange, ychange, zchange, cliptype, result);
|
|
|
|
}
|
|
|
|
|
2021-11-07 17:46:28 +00:00
|
|
|
inline int clipmove_ex(vec3_t* pos, int* sect, int xv, int yv, int wal, int ceil, int flor, int ct, Collision& result)
|
2020-10-21 20:43:23 +00:00
|
|
|
{
|
2021-11-07 17:46:28 +00:00
|
|
|
int res = clipmove(pos, sect, xv, yv, wal, ceil, flor, ct);
|
2020-10-21 20:43:23 +00:00
|
|
|
return result.setFromEngine(res);
|
|
|
|
}
|
|
|
|
|
2021-11-07 11:37:58 +00:00
|
|
|
inline void getzrange_ex(int x, int y, int z, int sectnum, int32_t* ceilz, Collision& ceilhit, int32_t* florz, Collision& florhit, int32_t walldist, uint32_t cliptype)
|
2020-10-21 23:10:56 +00:00
|
|
|
{
|
|
|
|
int ch, fh;
|
|
|
|
getzrange(x, y, z, sectnum, ceilz, &ch, florz, &fh, walldist, cliptype);
|
|
|
|
ceilhit.setFromEngine(ch);
|
|
|
|
florhit.setFromEngine(fh);
|
|
|
|
}
|
|
|
|
|
2021-11-17 22:53:11 +00:00
|
|
|
inline int hitscan(int x, int y, int z, int sectnum, int32_t vx, int32_t vy, int32_t vz,
|
|
|
|
sectortype** hitsect, walltype** hitwall, DDukeActor** hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype)
|
|
|
|
{
|
|
|
|
short hitsprt, hitsct, hitwal;
|
|
|
|
int res = ::hitscan(x, y, z, sectnum, vx, vy, vz, &hitsct, &hitwal, &hitsprt, hitx, hity, hitz, cliptype);
|
|
|
|
if (hitspr) *hitspr = hitsprt == -1 ? nullptr : &hittype[hitsprt];
|
|
|
|
if (hitsect) *hitsect = hitsct >= 0? §or[hitsct] : nullptr;
|
|
|
|
if (hitwall) *hitwall = hitwal >= 0? &wall[hitwal] : nullptr;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-11-21 07:45:07 +00:00
|
|
|
inline int hitscan(int x, int y, int z, sectortype* sect, int32_t vx, int32_t vy, int32_t vz,
|
|
|
|
sectortype** hitsect, walltype** hitwall, DDukeActor** hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype)
|
|
|
|
{
|
|
|
|
short hitsprt, hitsct, hitwal;
|
|
|
|
int res = ::hitscan(x, y, z, sectnum(sect), vx, vy, vz, &hitsct, &hitwal, &hitsprt, hitx, hity, hitz, cliptype);
|
|
|
|
if (hitspr) *hitspr = hitsprt == -1 ? nullptr : &hittype[hitsprt];
|
|
|
|
if (hitsect) *hitsect = hitsct >= 0? §or[hitsct] : nullptr;
|
|
|
|
if (hitwall) *hitwall = hitwal >= 0? &wall[hitwal] : nullptr;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-11-07 11:43:00 +00:00
|
|
|
inline void neartag(int32_t xs, int32_t ys, int32_t zs, int sectnum, int ange,
|
2021-11-18 17:21:05 +00:00
|
|
|
sectortype** neartagsector, walltype** neartagwall, DDukeActor** neartagsprite,
|
2020-10-27 05:35:11 +00:00
|
|
|
int32_t* neartaghitdist, int32_t neartagrange, uint8_t tagsearch)
|
|
|
|
{
|
|
|
|
int16_t nts;
|
2021-11-07 09:10:00 +00:00
|
|
|
int16_t ntsec, ntwal;
|
|
|
|
::neartag(xs, ys, zs, sectnum, ange, &ntsec, &ntwal, &nts, neartaghitdist, neartagrange, tagsearch);
|
2020-10-27 05:35:11 +00:00
|
|
|
*neartagsprite = nts == -1 ? nullptr : &hittype[nts];
|
2021-11-18 17:21:05 +00:00
|
|
|
*neartagsector = ntsec == -1? nullptr : §or[ntsec];
|
|
|
|
*neartagwall = ntwal == -1? nullptr : &wall[ntwal];
|
2020-10-27 05:35:11 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:38:53 +00:00
|
|
|
|
2020-10-17 07:14:31 +00:00
|
|
|
END_DUKE_NS
|