From 1f8d425a1edf9cbd54c4b77413f48f2a70b248dc Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Thu, 4 Feb 2016 21:45:31 -0600 Subject: [PATCH] - Added CountInv(itemtype, [ptr_select]). - Returns an inventory item count. --- src/namedef.h | 1 + src/thingdef/thingdef_codeptr.cpp | 33 +++++++++++++++++++++++++++++++ wadsrc/static/actors/actor.txt | 1 + 3 files changed, 35 insertions(+) diff --git a/src/namedef.h b/src/namedef.h index d06ca9ccc..2f312d6a0 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -306,6 +306,7 @@ xx(CallACS) xx(Sqrt) xx(CheckClass) xx(IsPointerEqual) +xx(CountInv) xx(Pick) xx(Mass) xx(VelX) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index ba5bc7f47..3f2300ece 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -217,6 +217,39 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, IsPointerEqual) return 0; } +//========================================================================== +// +// CountInv +// +// NON-ACTION function to return the inventory count of an item. +// +//========================================================================== + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, CountInv) +{ + if (numret > 0) + { + assert(ret != NULL); + PARAM_PROLOGUE; + PARAM_OBJECT(self, AActor); + PARAM_CLASS(itemtype, AInventory); + PARAM_INT_OPT(pick_pointer) { pick_pointer = AAPTR_DEFAULT; } + + self = COPY_AAPTR(self, pick_pointer); + if (self == NULL || itemtype == NULL) + { + ret->SetInt(false); + } + else + { + AInventory *item = self->FindInventory(itemtype); + ret->SetInt(item ? item->Amount : 0); + return 1; + } + } + return 0; +} + //========================================================================== // // A_RearrangePointers diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 1f7efd895..0d0e98261 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -35,6 +35,7 @@ ACTOR Actor native //: Thinker // Functions native bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false); native bool IsPointerEqual(int ptr_select1, int ptr_select2); + native int CountInv(class itemtype, int ptr_select = AAPTR_DEFAULT); // Action functions