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

183 lines
3.5 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 xsprite;
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-08-29 13:57:42 +00:00
DBloodActor* prevmarker; // needed by the nnext marker code. This originally hijacked targetX in XSPRITE
2021-11-19 20:19:18 +00:00
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 = {};
xsprite = {};
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; }
XSPRITE& x() { return xsprite; } // calling this does not validate the xsprite!
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-11-19 19:54:13 +00:00
x().target = own;
2020-12-03 17:00:07 +00:00
}
DBloodActor* GetTarget()
{
2021-11-19 19:54:13 +00:00
return x().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-11-28 12:35:35 +00:00
x().burnSource = own;
2020-12-03 19:30:30 +00:00
}
DBloodActor* GetBurnSource()
{
2021-11-28 12:35:35 +00:00
return x().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;
2020-12-02 23:30:19 +00:00
s().owner = kMaxSprites - 1;
}
bool GetSpecialOwner()
{
2021-11-19 20:19:18 +00:00
return ownerActor == nullptr && (s().owner == kMaxSprites - 1);
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;
switch (x().aiState->stateType)
{
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->s(), top, bottom);
}
END_BLD_NS