From 5948abb4eb4167fd22210560b19d066392b2acfd Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Mon, 13 Jan 2025 11:53:53 +0800 Subject: [PATCH 1/2] Exported conversation behaviors --- src/playsim/p_map.cpp | 44 +++++++++++++++++++-------- wadsrc/static/zscript/actors/actor.zs | 4 ++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index ef5438afdff..65a319fe059 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -5702,6 +5702,35 @@ void R_OffsetView(FRenderViewpoint& viewPoint, const DVector3& dir, const double // //========================================================================== +static int CanTalk(AActor *self) +{ + return self->Conversation != nullptr; +} + +DEFINE_ACTION_FUNCTION_NATIVE(AActor, CanTalk, CanTalk) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_BOOL(CanTalk(self)); +} + +static int NativeStartConversation(AActor *self, AActor *player, bool faceTalker, bool saveAngle) +{ + if (self->health <= 0 || (self->flags4 & MF4_INCOMBAT) || self->Conversation == nullptr) + return false; + self->ConversationAnimation(0); + P_StartConversation(self, player, faceTalker, saveAngle); + return true; +} + +DEFINE_ACTION_FUNCTION_NATIVE(AActor, StartConversation, NativeStartConversation) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT(player, AActor); + PARAM_BOOL(faceTalker); + PARAM_BOOL(saveAngle); + ACTION_RETURN_BOOL(NativeStartConversation(self, player, faceTalker, saveAngle)); +} + bool P_TalkFacing(AActor *player) { static const double angleofs[] = { 0, 90./16, -90./16 }; @@ -5710,19 +5739,8 @@ bool P_TalkFacing(AActor *player) for (double angle : angleofs) { P_AimLineAttack(player, player->Angles.Yaw + DAngle::fromDeg(angle), TALKRANGE, &t, DAngle::fromDeg(35.), ALF_FORCENOSMART | ALF_CHECKCONVERSATION | ALF_PORTALRESTRICT); - if (t.linetarget != NULL) - { - if (t.linetarget->health > 0 && // Dead things can't talk. - !(t.linetarget->flags4 & MF4_INCOMBAT) && // Fighting things don't talk either. - t.linetarget->Conversation != NULL) - { - // Give the NPC a chance to play a brief animation - t.linetarget->ConversationAnimation(0); - P_StartConversation(t.linetarget, player, true, true); - return true; - } - return false; - } + if (t.linetarget != nullptr) + return NativeStartConversation(t.linetarget, player, true, true); } return false; } diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index e0633d599b8..49302c56d03 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -698,7 +698,9 @@ class Actor : Thinker native native clearscope int GetRenderStyle() const; native clearscope bool CheckKeys(int locknum, bool remote, bool quiet = false); protected native void CheckPortalTransition(bool linked = true); - + native clearscope bool CanTalk() const; + native bool StartConversation(Actor player, bool faceTalker = true, bool saveAngle = true); + native clearscope string GetTag(string defstr = "") const; native clearscope string GetCharacterName() const; native void SetTag(string defstr = ""); From 81ba080062b97e2d007ff37a2fd33e328da88fb8 Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Sat, 18 Jan 2025 00:26:41 +0800 Subject: [PATCH 2/2] Added HasConversation --- src/playsim/p_map.cpp | 16 ++++++++++++++-- wadsrc/static/zscript/actors/actor.zs | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index 65a319fe059..705ec395613 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -5704,7 +5704,7 @@ void R_OffsetView(FRenderViewpoint& viewPoint, const DVector3& dir, const double static int CanTalk(AActor *self) { - return self->Conversation != nullptr; + return self->Conversation != nullptr && self->health > 0 && !(self->flags4 & MF4_INCOMBAT); } DEFINE_ACTION_FUNCTION_NATIVE(AActor, CanTalk, CanTalk) @@ -5713,10 +5713,22 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, CanTalk, CanTalk) ACTION_RETURN_BOOL(CanTalk(self)); } +static int HasConversation(AActor *self) +{ + return self->Conversation != nullptr; +} + +DEFINE_ACTION_FUNCTION_NATIVE(AActor, HasConversation, HasConversation) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_BOOL(HasConversation(self)); +} + static int NativeStartConversation(AActor *self, AActor *player, bool faceTalker, bool saveAngle) { - if (self->health <= 0 || (self->flags4 & MF4_INCOMBAT) || self->Conversation == nullptr) + if (!CanTalk(self)) return false; + self->ConversationAnimation(0); P_StartConversation(self, player, faceTalker, saveAngle); return true; diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 49302c56d03..f480192622f 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -698,6 +698,7 @@ class Actor : Thinker native native clearscope int GetRenderStyle() const; native clearscope bool CheckKeys(int locknum, bool remote, bool quiet = false); protected native void CheckPortalTransition(bool linked = true); + native clearscope bool HasConversation() const; native clearscope bool CanTalk() const; native bool StartConversation(Actor player, bool faceTalker = true, bool saveAngle = true);