diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 0669ab3d4..368184329 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -98,7 +98,7 @@ FRandom pr_cajump("CustomJump"); extern TArray actionParams; // this can use the same storage as CallAction -static bool CallStateChain (AActor *self, AActor *actor, FState *state) +static int CallStateChain (AActor *self, AActor *actor, FState *state) { INTBOOL result = false; int counter = 0; @@ -235,7 +235,7 @@ static bool CallStateChain (AActor *self, AActor *actor, FState *state) return !!result; } -DEFINE_ACTION_FUNCTION(ACustomInventory, CallStateChain) +DEFINE_ACTION_FUNCTION_NATIVE(ACustomInventory, CallStateChain, CallStateChain) { PARAM_SELF_PROLOGUE(AActor); PARAM_OBJECT(affectee, AActor); @@ -243,226 +243,6 @@ DEFINE_ACTION_FUNCTION(ACustomInventory, CallStateChain) ACTION_RETURN_BOOL(CallStateChain(self, affectee, state)); } -//========================================================================== -// -// CheckClass -// -// NON-ACTION function to check a pointer's class. -// -//========================================================================== - -DEFINE_ACTION_FUNCTION(AActor, CheckClass) -{ - if (numret > 0) - { - assert(ret != NULL); - PARAM_SELF_PROLOGUE(AActor); - PARAM_CLASS (checktype, AActor); - PARAM_INT (pick_pointer); - PARAM_BOOL (match_superclass); - - self = COPY_AAPTR(self, pick_pointer); - if (self == nullptr || checktype == nullptr) - { - ret->SetInt(false); - } - else if (match_superclass) - { - ret->SetInt(self->IsKindOf(checktype)); - } - else - { - ret->SetInt(self->GetClass() == checktype); - } - return 1; - } - return 0; -} - -//========================================================================== -// -// CheckClass -// -// NON-ACTION function to calculate missile damage for the given actor -// -//========================================================================== - -DEFINE_ACTION_FUNCTION(AActor, GetMissileDamage) -{ - if (numret > 0) - { - assert(ret != NULL); - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(mask); - PARAM_INT(add); - PARAM_INT(pick_pointer); - - self = COPY_AAPTR(self, pick_pointer); - if (self == NULL) - { - ret->SetInt(0); - } - else - { - ret->SetInt(self->GetMissileDamage(mask, add)); - } - return 1; - } - return 0; -} - -//========================================================================== -// -// GetDistance -// -// NON-ACTION function to get the distance in double. -// -//========================================================================== -DEFINE_ACTION_FUNCTION(AActor, GetDistance) -{ - if (numret > 0) - { - assert(ret != NULL); - PARAM_SELF_PROLOGUE(AActor); - PARAM_BOOL(checkz); - PARAM_INT(ptr); - - AActor *target = COPY_AAPTR(self, ptr); - - if (!target || target == self) - { - ret->SetFloat(0); - } - else - { - DVector3 diff = self->Vec3To(target); - if (checkz) - diff.Z += (target->Height - self->Height) / 2; - else - diff.Z = 0.; - - ret->SetFloat(diff.Length()); - } - return 1; - } - return 0; -} - -//========================================================================== -// -// GetAngle -// -// NON-ACTION function to get the angle in degrees (normalized to -180..180) -// -//========================================================================== -enum GAFlags -{ - GAF_RELATIVE = 1, - GAF_SWITCH = 1 << 1, -}; - -DEFINE_ACTION_FUNCTION(AActor, GetAngle) -{ - if (numret > 0) - { - assert(ret != NULL); - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(flags); - PARAM_INT(ptr) - - AActor *target = COPY_AAPTR(self, ptr); - - if (!target || target == self) - { - ret->SetFloat(0); - } - else - { - DVector3 diff = (flags & GAF_SWITCH) ? target->Vec3To(self) : self->Vec3To(target); - DAngle angto = diff.Angle(); - DAngle yaw = (flags & GAF_SWITCH) ? target->Angles.Yaw : self->Angles.Yaw; - if (flags & GAF_RELATIVE) angto = deltaangle(yaw, angto); - ret->SetFloat(angto.Degrees); - } - return 1; - } - return 0; -} - -//========================================================================== -// -// GetSpawnHealth -// -//========================================================================== -DEFINE_ACTION_FUNCTION(AActor, GetSpawnHealth) -{ - if (numret > 0) - { - PARAM_SELF_PROLOGUE(AActor); - ret->SetInt(self->SpawnHealth()); - return 1; - } - return 0; -} - -//========================================================================== -// -// GetSpriteAngle -// -// NON-ACTION function returns the sprite angle of a pointer. -//========================================================================== -DEFINE_ACTION_FUNCTION(AActor, GetSpriteAngle) -{ - if (numret > 0) - { - assert(ret != NULL); - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(ptr); - - AActor *target = COPY_AAPTR(self, ptr); - if (target == nullptr) - { - ret->SetFloat(0.0); - } - else - { - const double ang = target->SpriteAngle.Degrees; - ret->SetFloat(ang); - } - return 1; - } - return 0; -} - -//========================================================================== -// -// GetSpriteRotation -// -// NON-ACTION function returns the sprite rotation of a pointer. -//========================================================================== -DEFINE_ACTION_FUNCTION(AActor, GetSpriteRotation) -{ - if (numret > 0) - { - assert(ret != NULL); - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(ptr); - - AActor *target = COPY_AAPTR(self, ptr); - if (target == nullptr) - { - ret->SetFloat(0.0); - } - else - { - const double ang = target->SpriteRotation.Degrees; - ret->SetFloat(ang); - } - return 1; - } - return 0; -} - //========================================================================== // // GetZAt diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index de1349a12..0ed5240c2 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -267,7 +267,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetZ, SetZ) return 0; } -static void SetDamage(AActor *self, double dmg) +static void SetDamage(AActor *self, int dmg) { self->SetDamage(dmg); } @@ -698,6 +698,15 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SpawnHealth, SpawnHealth) ACTION_RETURN_INT(self->SpawnHealth()); } +// Why does this exist twice? +DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetSpawnHealth, SpawnHealth) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->SpawnHealth()); +} + + + void Revive(AActor *self) { self->Revive(); @@ -1061,7 +1070,7 @@ static AActor *ZS_LineAttack(AActor *self, double angle, double distance, double return P_LineAttack(self, angle, distance, pitch, damage, ENamedName(damageType), puffType, flags, victim, actualdamage, offsetz, offsetforward, offsetside); } -DEFINE_ACTION_FUNCTION_NATIVE(AActor, LineAttac, ZS_LineAttack) +DEFINE_ACTION_FUNCTION_NATIVE(AActor, LineAttack, ZS_LineAttack) { PARAM_SELF_PROLOGUE(AActor); PARAM_FLOAT(angle); @@ -1321,8 +1330,21 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, GiveSecret, GiveSecret) return 0; } +static int ZS_GetMissileDamage(AActor *self, int mask, int add, int pick_pointer) +{ + self = COPY_AAPTR(self, pick_pointer); + return self ? self->GetMissileDamage(mask, add) : 0; +} - +DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetMissileDamage, ZS_GetMissileDamage) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(mask); + PARAM_INT(add); + PARAM_INT(pick_pointer); + ACTION_RETURN_INT(ZS_GetMissileDamage(self, mask, add, pick_pointer)); +} + //===================================================================================== // // Inventory exports diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 01df3f1b0..86d916348 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -771,7 +771,6 @@ class Actor : Thinker native - native bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false); protected native void DestroyAllInventory(); // This is not supposed to be called by user code! native clearscope Inventory FindInventory(class itemtype, bool subclass = false) const; native Inventory GiveInventoryType(class itemtype); @@ -782,8 +781,6 @@ class Actor : Thinker native native bool Warp(Actor dest, double xofs = 0, double yofs = 0, double zofs = 0, double angle = 0, int flags = 0, double heightoffset = 0, double radiusoffset = 0, double pitch = 0); // DECORATE compatible functions - native double GetDistance(bool checkz, int ptr = AAPTR_TARGET) const; - native double GetAngle(int flags, int ptr = AAPTR_TARGET) const; native double GetZAt(double px = 0, double py = 0, double angle = 0, int flags = 0, int pick_pointer = AAPTR_DEFAULT); native clearscope int GetSpawnHealth() const; native double GetCrouchFactor(int ptr = AAPTR_PLAYER1); @@ -791,8 +788,6 @@ class Actor : Thinker native native double GetCVarString(string cvar); native int GetPlayerInput(int inputnum, int ptr = AAPTR_DEFAULT); native int CountProximity(class classname, double distance, int flags = 0, int ptr = AAPTR_DEFAULT); - native double GetSpriteAngle(int ptr = AAPTR_DEFAULT); - native double GetSpriteRotation(int ptr = AAPTR_DEFAULT); native int GetMissileDamage(int mask, int add, int ptr = AAPTR_DEFAULT); action native int OverlayID(); action native double OverlayX(int layer = 0); diff --git a/wadsrc/static/zscript/compatibility.txt b/wadsrc/static/zscript/compatibility.txt index 43280bdcc..90ba082b9 100644 --- a/wadsrc/static/zscript/compatibility.txt +++ b/wadsrc/static/zscript/compatibility.txt @@ -18,6 +18,116 @@ extend class Object extend class Actor { + //========================================================================== + // + // CheckClass + // + // NON-ACTION function to check a pointer's class. + // deprecated because functionality is directly accessible. + // + //========================================================================== + + deprecated("3.7") bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false) + { + let check = GetPointer(ptr_select); + if (check == null || checkclass == null) + { + return false; + } + else if (match_superclass) + { + return check is checkclass; + } + else + { + return check.GetClass() == checkclass; + } + } + + //========================================================================== + // + // GetDistance + // + // NON-ACTION function to get the distance in double. + // deprecated because it requires AAPTR to work. + // + //========================================================================== + deprecated("3.7") double GetDistance(bool checkz, int ptr = AAPTR_TARGET) const + { + let target = GetPointer(ptr); + + if (!target || target == self) + { + return 0; + } + else + { + let diff = Vec3To(target); + if (checkz) + diff.Z += (target.Height - self.Height) / 2; + else + diff.Z = 0.; + + return diff.Length(); + } + } + + //========================================================================== + // + // GetAngle + // + // NON-ACTION function to get the angle in degrees (normalized to -180..180) + // deprecated because it requires AAPTR to work. + // + //========================================================================== + + deprecated("3.7") double GetAngle(int flags, int ptr = AAPTR_TARGET) + { + let target = GetPointer(ptr); + + if (!target || target == self) + { + return 0; + } + else + { + let angto = (flags & GAF_SWITCH) ? target.AngleTo(self) : self.AngleTo(target); + let yaw = (flags & GAF_SWITCH) ? target.Angle : self.Angle; + if (flags & GAF_RELATIVE) angto = deltaangle(yaw, angto); + return angto; + } + } + + //========================================================================== + // + // GetSpriteAngle + // + // NON-ACTION function returns the sprite angle of a pointer. + // deprecated because direct access to the data is now possible. + // + //========================================================================== + + deprecated("3.7") double GetSpriteAngle(int ptr = AAPTR_DEFAULT) + { + let target = GetPointer(ptr); + return target? target.SpriteAngle : 0; + } + + //========================================================================== + // + // GetSpriteRotation + // + // NON-ACTION function returns the sprite rotation of a pointer. + // deprecated because direct access to the data is now possible. + // + //========================================================================== + + deprecated("3.7") double GetSpriteRotation(int ptr = AAPTR_DEFAULT) + { + let target = GetPointer(ptr); + return target? target.SpriteRotation : 0; + } + deprecated("2.3") void A_CustomMissile(class missiletype, double spawnheight = 32, double spawnofs_xy = 0, double angle = 0, int flags = 0, double pitch = 0, int ptr = AAPTR_TARGET) { A_SpawnProjectile(missiletype, spawnheight, spawnofs_xy, angle, flags|CMF_BADPITCH, pitch, ptr);