2020-07-06 20:23:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mathutil.h"
|
2021-04-11 06:40:18 +00:00
|
|
|
#include "gamehud.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-11-29 12:54:58 +00:00
|
|
|
return ((gs.actorinfo[tileNum].flags & (SFLAG_INTERNAL_BADGUY | SFLAG_BADGUY)) != 0);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 19:38:17 +00:00
|
|
|
inline int bossguypic(int const tileNum)
|
|
|
|
{
|
2020-11-29 12:54:58 +00:00
|
|
|
return ((gs.actorinfo[tileNum].flags & (SFLAG_BOSS)) != 0);
|
2020-09-07 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 09:17:44 +00:00
|
|
|
inline int actorflag(DDukeActor * actor, EDukeFlags1 mask)
|
2020-07-06 16:08:31 +00:00
|
|
|
{
|
2021-12-21 17:19:45 +00:00
|
|
|
return (((gs.actorinfo[actor->spr.picnum].flags) & mask) != 0);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 09:17:44 +00:00
|
|
|
inline int actorflag(DDukeActor* actor, EDukeFlags2 mask)
|
|
|
|
{
|
|
|
|
return (((gs.actorinfo[actor->spr.picnum].flags2) & mask) != 0);
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:41:33 +00:00
|
|
|
inline int attackerflag(DDukeActor* actor, EDukeFlags1 mask)
|
|
|
|
{
|
|
|
|
return (((gs.actorinfo[actor->attackertype].flags) & mask) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int attackerflag(DDukeActor* actor, EDukeFlags2 mask)
|
|
|
|
{
|
|
|
|
return (((gs.actorinfo[actor->attackertype].flags2) & mask) != 0);
|
|
|
|
}
|
|
|
|
|
2020-10-23 17:02:58 +00:00
|
|
|
inline int actorfella(DDukeActor* actor)
|
2020-07-06 16:08:31 +00:00
|
|
|
{
|
2020-10-23 17:02:58 +00:00
|
|
|
return actorflag(actor, SFLAG_KILLCOUNT);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 09:17:44 +00:00
|
|
|
inline void setflag(EDukeFlags1 flag, const std::initializer_list<short>& types)
|
2020-07-06 16:08:31 +00:00
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
for (auto val : types)
|
|
|
|
{
|
2020-11-29 12:54:58 +00:00
|
|
|
gs.actorinfo[val].flags |= flag;
|
2020-07-20 21:21:27 +00:00
|
|
|
}
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 09:17:44 +00:00
|
|
|
inline void setflag(EDukeFlags2 flag, const std::initializer_list<short>& types)
|
|
|
|
{
|
|
|
|
for (auto val : types)
|
|
|
|
{
|
|
|
|
gs.actorinfo[val].flags2 |= flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-21 21:31:25 +00:00
|
|
|
inline bool inventory(DDukeActor* S)
|
2020-07-06 16:08:31 +00:00
|
|
|
{
|
2022-01-17 23:54:10 +00:00
|
|
|
return actorflag(S, 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)
|
|
|
|
{
|
2020-11-29 12:54:58 +00:00
|
|
|
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
|
|
|
{
|
2021-12-21 17:19:45 +00:00
|
|
|
return !!(gs.tileinfo[s->spr.picnum].flags & TFLAG_WALLSWITCH);
|
2020-07-06 16:08:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 20:02:59 +00:00
|
|
|
inline int checkcursectnums(sectortype* se)
|
2020-07-06 20:23:18 +00:00
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int i;
|
|
|
|
for(i=connecthead;i>=0;i=connectpoint2[i])
|
2021-12-30 15:51:56 +00:00
|
|
|
if(ps[i].GetActor() && ps[i].GetActor()->sector() == se ) return i;
|
2020-07-20 21:21:27 +00:00
|
|
|
return -1;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 21:28:13 +00:00
|
|
|
inline int ldist(DDukeActor* s1, DDukeActor* s2)
|
2020-07-06 20:23:18 +00:00
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int vx, vy;
|
2022-01-31 18:21:49 +00:00
|
|
|
vx = s1->int_pos().X - s2->int_pos().X;
|
|
|
|
vy = s1->int_pos().Y - s2->int_pos().Y;
|
2020-07-20 21:21:27 +00:00
|
|
|
return(FindDistance2D(vx, vy) + 1);
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 21:28:13 +00:00
|
|
|
inline int ldist(const DDukeActor* s1, const tspritetype* s2)
|
2021-12-04 18:08:50 +00:00
|
|
|
{
|
|
|
|
int vx, vy;
|
2022-02-02 18:49:57 +00:00
|
|
|
vx = s1->int_pos().X - s2->int_pos().X;
|
|
|
|
vy = s1->int_pos().Y - s2->int_pos().Y;
|
2021-12-04 18:08:50 +00:00
|
|
|
return(FindDistance2D(vx, vy) + 1);
|
|
|
|
}
|
2021-12-21 21:28:13 +00:00
|
|
|
inline int dist(DDukeActor* s1, DDukeActor* s2)
|
2020-07-06 20:23:18 +00:00
|
|
|
{
|
2020-07-20 21:21:27 +00:00
|
|
|
int vx, vy, vz;
|
2022-01-31 18:21:49 +00:00
|
|
|
vx = s1->int_pos().X - s2->int_pos().X;
|
|
|
|
vy = s1->int_pos().Y - s2->int_pos().Y;
|
|
|
|
vz = s1->int_pos().Z - s2->int_pos().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)
|
|
|
|
{
|
2021-07-17 12:42:58 +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
|
|
|
}
|
|
|
|
|
2020-10-08 03:47:30 +00:00
|
|
|
inline float PlayerInputAngVel(int pl)
|
2020-07-06 20:23:18 +00:00
|
|
|
{
|
2020-10-08 03:47:30 +00:00
|
|
|
return ps[pl].sync.avel;
|
2020-07-06 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 19:56:31 +00:00
|
|
|
inline float GetPlayerHorizon(int pl)
|
2020-08-30 11:04:07 +00:00
|
|
|
{
|
2020-10-07 07:22:07 +00:00
|
|
|
return ps[pl].sync.horz;
|
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])
|
|
|
|
{
|
2021-12-22 09:28:51 +00:00
|
|
|
ps[i].fric.X = ps[i].fric.Y = 0;
|
2020-07-20 21:21:27 +00:00
|
|
|
}
|
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)));
|
|
|
|
}
|
|
|
|
|
2021-01-01 22:32:19 +00:00
|
|
|
inline void doslopetilting(player_struct* p, double const scaleAdjust = 1)
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-12-18 12:14:56 +00:00
|
|
|
bool const canslopetilt = p->on_ground && p->insector() && p->cursector->lotag != ST_2_UNDERWATER && (p->cursector->floorstat & CSTAT_SECTOR_SLOPE);
|
2022-08-27 13:09:22 +00:00
|
|
|
p->horizon.calcviewpitch(p->pos.XY(), p->angle.ang, p->aim_mode == 0, canslopetilt, p->cursector, scaleAdjust);
|
2021-01-01 13:30:01 +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
|
|
|
{
|
2021-11-21 07:56:39 +00:00
|
|
|
int p = ps[screenpeek].cursector->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
|
|
|
}
|
|
|
|
|
2022-06-06 01:04:51 +00:00
|
|
|
inline void animateshrunken(player_struct* p, double weapon_xoffset, double looking_arc, double look_anghalf, int tilenum, int8_t shade, int o, double smoothratio)
|
|
|
|
{
|
2022-08-29 01:18:54 +00:00
|
|
|
const double fistsign = bsinf(interpolatedvaluef(p->ofistsign, p->fistsign, smoothratio), -10);
|
2022-06-06 01:04:51 +00:00
|
|
|
if (p->jetpack_on == 0) looking_arc += 32 - (p->GetActor()->spr.xvel >> 1);
|
|
|
|
hud_draw(weapon_xoffset + fistsign + 250 - look_anghalf, looking_arc + 258 - fabs(fistsign * 4), tilenum, shade, o);
|
|
|
|
hud_draw(weapon_xoffset - fistsign + 40 - look_anghalf, looking_arc + 200 + fabs(fistsign * 4), tilenum, shade, o | 4);
|
|
|
|
}
|
|
|
|
|
2021-12-18 17:07:41 +00:00
|
|
|
inline ESpriteFlags randomFlip()
|
|
|
|
{
|
|
|
|
int r = krand() & 12;
|
|
|
|
if (r == 0) return 0;
|
|
|
|
if (r == 4) return CSTAT_SPRITE_XFLIP;
|
|
|
|
if (r == 8) return CSTAT_SPRITE_YFLIP;
|
|
|
|
return CSTAT_SPRITE_XFLIP | CSTAT_SPRITE_YFLIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ESpriteFlags randomXFlip()
|
|
|
|
{
|
|
|
|
int r = krand() & 4;
|
|
|
|
if (r == 0) return 0;
|
|
|
|
return CSTAT_SPRITE_XFLIP;
|
|
|
|
}
|
2021-11-18 17:35:59 +00:00
|
|
|
|
2020-07-06 20:23:18 +00:00
|
|
|
END_DUKE_NS
|