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

195 lines
3.7 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;
int xvel, yvel, zvel;
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.
2021-09-04 10:23:36 +00:00
POINT3D 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;
DBloodActor& operator=(const DBloodActor& other) = default;
void ClearContent() override
{
dudeSlope = 0;
hit = {};
dudeExtra = {};
2021-09-01 19:53:33 +00:00
spriteMass = {};
genDudeExtra = {};
prevmarker = nullptr;
ownerActor = nullptr;
2021-09-04 10:23:36 +00:00
basePoint = {};
xspr = {};
hasx = false;
interpolated = false;
xvel = yvel = zvel = 0;
explosionhackflag = false;
interpolated = false;
condition[0] = {};
condition[1] = {};
cumulDamage = 0;
Super::ClearContent();
}
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;
s().owner = kMagicOwner;
2020-12-02 23:30:19 +00:00
}
bool GetSpecialOwner()
{
return ownerActor == nullptr && (s().owner == kMagicOwner);
2020-12-02 23:30:19 +00:00
}
bool IsPlayerActor()
{
return s().type >= kDudePlayer1 && s().type <= kDudePlayer8;
}
bool IsDudeActor()
{
return s().type >= kDudeBase && s().type < kDudeMax;
}
bool IsItemActor()
{
return s().type >= kItemBase && s().type < kItemMax;
}
bool IsWeaponActor()
{
return s().type >= kItemWeaponBase && s().type < kItemWeaponMax;
}
bool IsAmmoActor()
{
return s().type >= kItemAmmoBase && s().type < kItemAmmoMax;
}
2020-12-03 19:30:30 +00:00
bool isActive()
{
if (!hasX())
return false;
2021-12-23 14:55:27 +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)
{
return bits[act->spr.sectno()];
}
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