raze/source/games/blood/src/bloodactor.h

172 lines
3.3 KiB
C
Raw Normal View History

#pragma once
2021-11-25 20:42:49 +00:00
#include "coreactor.h"
BEGIN_BLD_NS
class DBloodActor;
struct SPRITEHIT
{
// These must use read barriers as they can live longer and need proper GC maintenance.
Collision hit, ceilhit, florhit;
};
2021-11-25 20:42:49 +00:00
class DBloodActor : public DCoreActor
{
DECLARE_CLASS(DBloodActor, DCoreActor)
HAS_OBJECT_POINTERS
public:
int dudeSlope;
vec3_t vel;
bool hasx;
XSPRITE xspr;
2021-08-29 17:09:29 +00:00
SPRITEHIT hit;
DUDEEXTRA dudeExtra;
2021-09-01 19:53:33 +00:00
SPRITEMASS spriteMass;
GENDUDEEXTRA genDudeExtra;
2021-12-05 22:56:35 +00:00
TObjPtr<DBloodActor*> prevmarker; // needed by the nnext marker code. This originally hijacked targetX in XSPRITE
TObjPtr<DBloodActor*> ownerActor; // was previously stored in the sprite's owner field.
2022-08-10 22:13:36 +00:00
DVector3 basePoint;
EventObject condition[2];
bool explosionhackflag; // this originally hijacked the target field which is not safe when working with pointers.
2021-09-01 19:53:33 +00:00
// transient data (not written to savegame)
int cumulDamage;
bool interpolated;
DBloodActor() = default;
void Serialize(FSerializer& arc) override;
size_t PropagateMark() override;
bool hasX() { return hasx; }
void addX() { hasx = true; }
void SetOwner(DBloodActor* own)
{
2021-11-19 20:19:18 +00:00
ownerActor = own;
}
DBloodActor* GetOwner()
{
2021-11-19 20:19:18 +00:00
return ownerActor;
}
2020-12-03 17:00:07 +00:00
void SetTarget(DBloodActor* own)
{
2021-12-23 14:55:27 +00:00
xspr.target = own;
2020-12-03 17:00:07 +00:00
}
DBloodActor* GetTarget()
{
2021-12-23 14:55:27 +00:00
return xspr.target;
2020-12-03 17:00:07 +00:00
}
bool ValidateTarget(const char* func)
{
if (GetTarget() == nullptr)
{
Printf(PRINT_HIGH | PRINT_NOTIFY, "%s: invalid target in calling actor\n", func);
return false;
}
return true;
}
2020-12-03 19:30:30 +00:00
void SetBurnSource(DBloodActor* own)
{
2021-12-23 14:55:27 +00:00
xspr.burnSource = own;
2020-12-03 19:30:30 +00:00
}
DBloodActor* GetBurnSource()
{
2021-12-23 14:55:27 +00:00
return xspr.burnSource;
2020-12-03 19:30:30 +00:00
}
2020-12-02 23:30:19 +00:00
void SetSpecialOwner() // nnext hackery
{
2021-11-19 20:19:18 +00:00
ownerActor = nullptr;
spr.intowner = kMagicOwner;
2020-12-02 23:30:19 +00:00
}
bool GetSpecialOwner()
{
return ownerActor == nullptr && (spr.intowner == kMagicOwner);
2020-12-02 23:30:19 +00:00
}
bool IsPlayerActor()
{
return spr.type >= kDudePlayer1 && spr.type <= kDudePlayer8;
}
bool IsDudeActor()
{
return spr.type >= kDudeBase && spr.type < kDudeMax;
}
bool IsItemActor()
{
return spr.type >= kItemBase && spr.type < kItemMax;
}
bool IsWeaponActor()
{
return spr.type >= kItemWeaponBase && spr.type < kItemWeaponMax;
}
bool IsAmmoActor()
{
return spr.type >= kItemAmmoBase && spr.type < kItemAmmoMax;
}
2021-12-29 19:03:42 +00:00
bool isActive()
2020-12-03 19:30:30 +00:00
{
if (!hasX())
return false;
2021-12-29 19:03:42 +00:00
switch (xspr.aiState->stateType)
2020-12-03 19:30:30 +00:00
{
case kAiStateIdle:
case kAiStateGenIdle:
case kAiStateSearch:
case kAiStateMove:
case kAiStateOther:
return false;
default:
return true;
}
}
};
// subclassed to add a game specific actor() method
extern HitInfo gHitInfo;
// Iterator wrappers that return an actor pointer, not an index.
using BloodStatIterator = TStatIterator<DBloodActor>;
using BloodSectIterator = TSectIterator<DBloodActor>;
using BloodSpriteIterator = TSpriteIterator<DBloodActor>;
2020-12-02 22:39:38 +00:00
inline void GetActorExtents(DBloodActor* actor, int* top, int* bottom)
{
GetSpriteExtents(&actor->spr, top, bottom);
2020-12-02 22:39:38 +00:00
}
2021-12-22 14:40:15 +00:00
inline bool CheckSector(const BitArray& bits, DBloodActor* act)
{
2021-12-30 15:39:43 +00:00
return bits[act->sectno()];
2021-12-22 14:40:15 +00:00
}
inline bool IsTargetTeammate(DBloodActor* pSource, DBloodActor* pTarget)
{
if (!pSource->IsPlayerActor())
return false;
PLAYER* pSourcePlayer = &gPlayer[pSource->spr.type - kDudePlayer1];
return IsTargetTeammate(pSourcePlayer, pTarget);
}
END_BLD_NS