raze/source/games/duke/src/inlines.h

210 lines
4.2 KiB
C
Raw Normal View History

2020-07-06 20:23:18 +00:00
#pragma once
#include "mathutil.h"
#include "gamehud.h"
#include "global.h"
2020-07-06 20:23:18 +00:00
// all inline functions.
BEGIN_DUKE_NS
inline int rnd(int X)
{
2020-07-20 21:21:27 +00:00
return ((krand() >> 8) >= (255 - (X)));
}
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)
{
return ((gs.actorinfo[tileNum].flags & (SFLAG_INTERNAL_BADGUY | SFLAG_BADGUY)) != 0);
2020-07-06 20:23:18 +00:00
}
2020-10-19 16:32:13 +00:00
inline int badguy(spritetype const * const pSprite)
2020-07-06 20:23:18 +00:00
{
2020-10-19 16:32:13 +00:00
return badguypic(pSprite->picnum);
}
inline int bossguypic(int const tileNum)
{
return ((gs.actorinfo[tileNum].flags & (SFLAG_BOSS)) != 0);
}
2020-10-19 16:32:13 +00:00
inline int bossguy(spritetype const* const pSprite)
{
2020-10-19 16:32:13 +00:00
return bossguypic(pSprite->picnum);
2020-07-06 20:23:18 +00:00
}
inline int actorflag(DDukeActor * actor, int mask)
2020-07-06 16:08:31 +00:00
{
return (((gs.actorinfo[actor->s->picnum].flags) & mask) != 0);
2020-07-06 16:08:31 +00:00
}
inline int actorfella(DDukeActor* actor)
2020-07-06 16:08:31 +00:00
{
return actorflag(actor, 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)
{
gs.actorinfo[val].flags |= flag;
2020-07-20 21:21:27 +00:00
}
2020-07-06 16:08:31 +00:00
}
inline bool inventory(spritetype* S)
{
return !!(gs.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)
{
gs.tileinfo[val].flags |= flag;
2020-07-20 21:21:27 +00:00
}
2020-07-06 16:08:31 +00:00
}
2020-11-02 22:53:55 +00:00
inline bool wallswitchcheck(DDukeActor* s)
2020-07-06 16:08:31 +00:00
{
return !!(gs.tileinfo[s->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(ps[i].GetActor() && ps[i].GetActor()->s->sectnum == se ) return i;
2020-07-20 21:21:27 +00:00
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;
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.
inline bool PlayerInput(int pl, ESyncBits bit)
{
return (!!((ps[pl].sync.actions) & bit));
}
inline ESyncBits PlayerInputBits(int pl, ESyncBits bits)
{
return (ps[pl].sync.actions & bits);
}
inline void PlayerSetInput(int pl, ESyncBits bit)
{
ps[pl].sync.actions |= bit;
}
inline int PlayerNewWeapon(int pl)
{
return ps[pl].sync.getNewWeapon();
}
inline void PlayerSetItemUsed(int pl, int num)
{
ps[pl].sync.setItemUsed(num - 1);
}
inline bool PlayerUseItem(int pl, int num)
{
return ps[pl].sync.isItemUsed(num - 1);
}
2020-07-06 20:23:18 +00:00
inline int PlayerInputSideVel(int pl)
{
return ps[pl].sync.svel;
2020-07-06 20:23:18 +00:00
}
inline int PlayerInputForwardVel(int pl)
{
return ps[pl].sync.fvel;
2020-07-06 20:23:18 +00:00
}
inline float PlayerInputAngVel(int pl)
2020-07-06 20:23:18 +00:00
{
return ps[pl].sync.avel;
2020-07-06 20:23:18 +00:00
}
inline float GetPlayerHorizon(int pl)
{
return ps[pl].sync.horz;
}
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
}
inline void SetPlayerPal(player_struct* p, PalEntry pe)
{
2020-07-20 21:21:27 +00:00
p->pals = pe;
}
2020-07-06 19:10:20 +00:00
inline bool playrunning()
{
return (paused == 0 || (paused == 1 && (ud.recstat == 2 || ud.multimode > 1)));
}
inline void doslopetilting(player_struct* p, double const scaleAdjust = 1)
{
bool const canslopetilt = p->on_ground && sector[p->cursectnum].lotag != ST_2_UNDERWATER && (sector[p->cursectnum].floorstat & 2);
p->horizon.calcviewpitch(p->pos.vec2, p->angle.ang, p->aim_mode == 0, canslopetilt, p->cursectnum, scaleAdjust);
}
2020-07-07 21:01:34 +00:00
2020-07-06 20:23:18 +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;
hud_drawsprite(x, y, 65536, 0, tilenum, shade, p, 2 | orientation);
2020-07-06 20:23:18 +00:00
}
END_DUKE_NS