mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-16 17:21:10 +00:00
Add Inventory::ModifyBob and Inventory::ModifyBob3D
This commit is contained in:
parent
e61ab4cbe2
commit
0e70e95fa4
3 changed files with 42 additions and 0 deletions
|
@ -830,4 +830,16 @@ unsigned GetVirtualIndex(PClass *cls, const char *funcname);
|
|||
VMFunction *func = clss->Virtuals.Size() > VIndex? clss->Virtuals[VIndex] : nullptr; \
|
||||
if (func != nullptr)
|
||||
|
||||
#define IFOVERRIDENVIRTUALPTRNAME(self, clsname, funcname) \
|
||||
static VMFunction *orig_func = nullptr; \
|
||||
static unsigned VIndex = ~0u; \
|
||||
if (VIndex == ~0u) { \
|
||||
PClass *cls = PClass::FindClass(clsname); \
|
||||
VIndex = GetVirtualIndex(cls, #funcname); \
|
||||
orig_func = cls->Virtuals.Size() > VIndex? cls->Virtuals[VIndex] : nullptr; \
|
||||
assert(VIndex != ~0u); \
|
||||
} \
|
||||
auto *clss = self->GetClass(); \
|
||||
VMFunction *func = clss->Virtuals.Size() > VIndex? clss->Virtuals[VIndex] : nullptr; \
|
||||
if (func && func != orig_func )
|
||||
#endif
|
||||
|
|
|
@ -641,6 +641,19 @@ void P_BobWeapon (player_t *player, float *x, float *y, double ticfrac)
|
|||
DVector2 result;
|
||||
VMReturn ret(&result);
|
||||
VMCall(func, param, 2, &ret, 1);
|
||||
|
||||
auto inv = player->mo->Inventory;
|
||||
while(inv != nullptr && !(inv->ObjectFlags & OF_EuthanizeMe)) // same loop as ModifyDamage, except it actually checks if it's overriden before calling
|
||||
{
|
||||
auto nextinv = inv->Inventory;
|
||||
IFOVERRIDENVIRTUALPTRNAME(inv, NAME_Inventory, ModifyBob)
|
||||
{
|
||||
VMValue param[] = { (DObject*)inv, result.X, result.Y, ticfrac };
|
||||
VMCall(func, param, 4, &ret, 1);
|
||||
}
|
||||
inv = nextinv;
|
||||
}
|
||||
|
||||
*x = (float)result.X;
|
||||
*y = (float)result.Y;
|
||||
return;
|
||||
|
@ -658,6 +671,19 @@ void P_BobWeapon3D (player_t *player, FVector3 *translation, FVector3 *rotation,
|
|||
returns[0].Vec3At(&t);
|
||||
returns[1].Vec3At(&r);
|
||||
VMCall(func, param, 2, returns, 2);
|
||||
|
||||
auto inv = player->mo->Inventory;
|
||||
while(inv != nullptr && !(inv->ObjectFlags & OF_EuthanizeMe))
|
||||
{
|
||||
auto nextinv = inv->Inventory;
|
||||
IFOVERRIDENVIRTUALPTRNAME(inv, NAME_Inventory, ModifyBob3D)
|
||||
{
|
||||
VMValue param[] = { (DObject*)inv, t.X, t.Y, t.Z, r.X, r.Y, r.Z, ticfrac };
|
||||
VMCall(func, param, 8, returns, 2);
|
||||
}
|
||||
inv = nextinv;
|
||||
}
|
||||
|
||||
translation->X = (float)t.X;
|
||||
translation->Y = (float)t.Y;
|
||||
translation->Z = (float)t.Z;
|
||||
|
|
|
@ -1021,6 +1021,10 @@ class Inventory : Actor
|
|||
//===========================================================================
|
||||
|
||||
virtual void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive, Actor inflictor = null, Actor source = null, int flags = 0) {}
|
||||
|
||||
virtual Vector2 ModifyBob(Vector2 Bob, double ticfrac) {return Bob;}
|
||||
|
||||
virtual Vector3, Vector3 ModifyBob3D(Vector3 Translation, Vector3 Rotation, double ticfrac) {return Translation, Rotation;}
|
||||
|
||||
|
||||
virtual bool Use (bool pickup) { return false; }
|
||||
|
|
Loading…
Reference in a new issue