2020-07-06 20:23:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mathutil.h"
|
2020-07-16 11:23:26 +00:00
|
|
|
#include "glbackend/glbackend.h"
|
2020-07-19 20:34:59 +00:00
|
|
|
#include "global.h"
|
2020-07-06 20:23:18 +00:00
|
|
|
|
|
|
|
// all inline functions.
|
|
|
|
BEGIN_DUKE_NS
|
|
|
|
|
2020-07-19 17:31:31 +00:00
|
|
|
inline int rnd(int X)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return ((krand() >> 8) >= (255 - (X)));
|
2020-07-19 17:31:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 16:08:31 +00:00
|
|
|
inline bool AFLAMABLE(int X)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return (X == TILE_BOX || X == TILE_TREE1 || X == TILE_TREE2 || X == TILE_TIRE || X == TILE_CONE);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
2020-07-06 20:23:18 +00:00
|
|
|
|
|
|
|
inline int badguypic(int const tileNum)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return ((actorinfo[tileNum].flags & (SFLAG_INTERNAL_BADGUY | SFLAG_BADGUY)) != 0);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int badguy(void const * const pSprite)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return badguypic(((uspritetype const *) pSprite)->picnum);
|
2020-09-07 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int bossguypic(int const tileNum)
|
|
|
|
{
|
|
|
|
return ((actorinfo[tileNum].flags & (SFLAG_BOSS)) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int bossguy(void const* const pSprite)
|
|
|
|
{
|
|
|
|
return badguypic(((uspritetype const*)pSprite)->picnum);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 16:08:31 +00:00
|
|
|
inline int actorflag(int spritenum, int mask)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return (((actorinfo[sprite[spritenum].picnum].flags/* ^ hittype[spritenum].flags*/) & mask) != 0);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int actorfella(int spnum)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return actorflag(spnum, SFLAG_KILLCOUNT);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void setflag(int flag, const std::initializer_list<short>& types)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
for (auto val : types)
|
|
|
|
{
|
|
|
|
actorinfo[val].flags |= flag;
|
|
|
|
}
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool inventory(spritetype* S)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return !!(actorinfo[S->picnum].flags & SFLAG_INVENTORY);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void settileflag(int flag, const std::initializer_list<short>& types)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
for (auto val : types)
|
|
|
|
{
|
|
|
|
tileinfo[val].flags |= flag;
|
|
|
|
}
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool wallswitchcheck(int s)
|
|
|
|
{
|
2020-07-25 08:54:46 +00:00
|
|
|
return !!(tileinfo[sprite[s].picnum].flags & TFLAG_WALLSWITCH);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:23:18 +00:00
|
|
|
inline int checkcursectnums(int se)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int i;
|
|
|
|
for(i=connecthead;i>=0;i=connectpoint2[i])
|
|
|
|
if((unsigned)ps[i].i < MAXSPRITES && sprite[ps[i].i].sectnum == se ) return i;
|
|
|
|
return -1;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// These are from duke's sector.c
|
|
|
|
inline int ldist(const spritetype* s1, const spritetype* s2)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int vx, vy;
|
|
|
|
vx = s1->x - s2->x;
|
|
|
|
vy = s1->y - s2->y;
|
|
|
|
return(FindDistance2D(vx, vy) + 1);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int dist(const spritetype* s1, const spritetype* s2)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int vx, vy, vz;
|
|
|
|
vx = s1->x - s2->x;
|
|
|
|
vy = s1->y - s2->y;
|
|
|
|
vz = s1->z - s2->z;
|
2020-08-18 21:49:44 +00:00
|
|
|
return(FindDistance3D(vx, vy, vz));
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isIn(int value, int first)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return value == first;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
bool isIn(int value, int first, Args... args)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
return value == first || isIn(value, args...);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isIn(int value, const std::initializer_list<int>& list)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
for (auto v : list) if (v == value) return true;
|
|
|
|
return false;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// these are mainly here to avoid directly accessing the input data so that it can be more easily refactored later.
|
2020-08-27 20:19:24 +00:00
|
|
|
inline bool PlayerInput(int pl, ESyncBits bit)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return (!!((ps[pl].sync.actions) & bit));
|
2020-08-27 20:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 21:02:55 +00:00
|
|
|
inline ESyncBits PlayerInputBits(int pl, ESyncBits bits)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return (ps[pl].sync.actions & bits);
|
2020-08-26 21:02:55 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 22:03:35 +00:00
|
|
|
inline void PlayerSetInput(int pl, ESyncBits bit)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
ps[pl].sync.actions |= bit;
|
2020-08-27 22:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-26 21:02:55 +00:00
|
|
|
inline int PlayerNewWeapon(int pl)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return ps[pl].sync.getNewWeapon();
|
2020-08-26 21:02:55 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 19:25:09 +00:00
|
|
|
inline void PlayerSetItemUsed(int pl, int num)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
ps[pl].sync.setItemUsed(num - 1);
|
2020-08-27 19:25:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool PlayerUseItem(int pl, int num)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return ps[pl].sync.isItemUsed(num - 1);
|
2020-08-27 19:25:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:23:18 +00:00
|
|
|
inline int PlayerInputSideVel(int pl)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return ps[pl].sync.svel;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int PlayerInputForwardVel(int pl)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return ps[pl].sync.fvel;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline fixed_t PlayerInputAngVel(int pl)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return ps[pl].sync.q16avel;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 11:04:07 +00:00
|
|
|
inline fixed_t PlayerHorizon(int pl)
|
|
|
|
{
|
2020-09-23 14:56:04 +00:00
|
|
|
return ps[pl].sync.q16horz;
|
2020-08-30 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 19:10:20 +00:00
|
|
|
inline void clearfriction()
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
for (int i = 0; i != -1; i = connectpoint2[i])
|
|
|
|
{
|
|
|
|
ps[i].fric.x = ps[i].fric.y = 0;
|
|
|
|
}
|
2020-07-06 19:10:20 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 21:24:35 +00:00
|
|
|
inline void SetPlayerPal(player_struct* p, PalEntry pe)
|
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
p->pals = pe;
|
2020-07-06 21:24:35 +00:00
|
|
|
}
|
2020-07-06 19:10:20 +00:00
|
|
|
|
2020-07-21 20:46:26 +00:00
|
|
|
inline bool playrunning()
|
|
|
|
{
|
|
|
|
return (paused == 0 || (paused == 1 && (ud.recstat == 2 || ud.multimode > 1)));
|
|
|
|
}
|
|
|
|
|
2020-07-29 22:24:27 +00:00
|
|
|
inline void backupplayer(player_struct* p)
|
|
|
|
{
|
|
|
|
backuppos(p);
|
|
|
|
backuplook(p);
|
2020-10-07 06:12:37 +00:00
|
|
|
p->horizon.backup();
|
2020-07-29 22:24:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 07:00:07 +00:00
|
|
|
// the weapon display code uses this.
|
2020-08-03 07:06:28 +00:00
|
|
|
inline double get16thOfHoriz(int snum, bool interpolate, double smoothratio)
|
|
|
|
{
|
|
|
|
struct player_struct *p = &ps[snum];
|
2020-10-07 06:12:37 +00:00
|
|
|
fixed_t ohorz = p->horizon.ohoriz.asq16() - p->horizon.ohorizoff.asq16();
|
|
|
|
fixed_t horz = p->horizon.horiz.asq16() - p->horizon.horizoff.asq16();
|
2020-08-03 07:06:28 +00:00
|
|
|
return (!interpolate ? horz : ohorz + fmulscale16(horz - ohorz, smoothratio)) * (0.0625 / FRACUNIT);
|
|
|
|
}
|
|
|
|
|
2020-07-07 21:01:34 +00:00
|
|
|
|
2020-07-06 20:23:18 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-07-16 11:23:26 +00:00
|
|
|
inline void hud_draw(double x, double y, int tilenum, int shade, int orientation)
|
2020-07-06 20:23:18 +00:00
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int p = sector[ps[screenpeek].cursectnum].floorpal;
|
2020-07-27 08:39:33 +00:00
|
|
|
hud_drawsprite(x, y, 65536, 0, tilenum, shade, p, 2 | orientation);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_DUKE_NS
|