From 814af66864f78d2f55b4b7599885de9abcbb5afa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 24 Nov 2018 18:33:42 +0100 Subject: [PATCH] - exported one FraggleScript function for testing. --- src/fragglescript/t_func.cpp | 43 +---------------- .../static/zscript/scriptutil/scriptutil.txt | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index be6c18520..c16896f31 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -2588,50 +2588,11 @@ void FParser::SF_PlayerAmmo(void) void FParser::SF_MaxPlayerAmmo() { - int playernum, amount; - PClassActor * ammotype; - if (CheckArgs(2)) { - playernum=T_GetPlayerNum(t_argv[0]); - if (playernum==-1) return; - - ammotype=T_GetAmmo(t_argv[1]); - if (!ammotype) return; - - if(t_argc == 2) - { - } - else if(t_argc >= 3) - { - auto iammo = players[playernum].mo->FindInventory(ammotype); - amount = intvalue(t_argv[2]); - if(amount < 0) amount = 0; - if (!iammo) - { - players[playernum].mo->GiveAmmo(ammotype, 1); - iammo = players[playernum].mo->FindInventory(ammotype); - iammo->Amount = 0; - } - iammo->MaxAmount = amount; - - - for (AInventory *item = players[playernum].mo->Inventory; item != NULL; item = item->Inventory) - { - if (item->IsKindOf(NAME_BackpackItem)) - { - if (t_argc>=4) amount = intvalue(t_argv[3]); - else amount*=2; - break; - } - } - iammo->IntVar("BackpackMaxAmount") = amount; - } - t_return.type = svt_int; - AInventory * iammo = players[playernum].mo->FindInventory(ammotype); - if (iammo) t_return.value.i = iammo->MaxAmount; - else t_return.value.i = ((AInventory*)GetDefaultByType(ammotype))->MaxAmount; + t_return.value.i = ScriptUtil::Exec("MaxPlayerAmmo", ScriptUtil::Pointer, T_GetPlayerActor(t_argv[0]), ScriptUtil::Class, T_ClassType(t_argv[1]), + ScriptUtil::Int, t_argc >= 3? intvalue(t_argv[2]) : INT_MIN, ScriptUtil::Int, t_argc >= 4 ? intvalue(t_argv[3]) : INT_MIN, ScriptUtil::End); } } diff --git a/wadsrc/static/zscript/scriptutil/scriptutil.txt b/wadsrc/static/zscript/scriptutil/scriptutil.txt index a47f79486..d29fb3f34 100644 --- a/wadsrc/static/zscript/scriptutil/scriptutil.txt +++ b/wadsrc/static/zscript/scriptutil/scriptutil.txt @@ -102,4 +102,50 @@ class ScriptUtil play } } + + //========================================================================== + // + // + // + //========================================================================== + + static int PlayerMaxAmmo(Actor activator, class type, int newmaxamount = int.min, int newbpmaxamount = int.min) + { + if (activator == null) return 0; + let ammotype = (class)(type); + if (ammotype == null) return 0; + + if (newmaxamount != int.min) + { + let iammo = Ammo(activator.FindInventory(ammotype)); + if(newmaxamount < 0) newmaxamount = 0; + if (!iammo) + { + activator.GiveAmmo(ammotype, 1); + iammo = Ammo(activator.FindInventory(ammotype)); + if (iammo) + iammo.Amount = 0; + } + + for (Inventory item = activator.Inv; item != NULL; item = item.Inv) + { + if (item is 'BackpackItem') + { + if (newbpmaxamount == int.min) newbpmaxamount = newmaxamount * 2; + break; + } + } + if (iammo) + { + iammo.MaxAmount = newmaxamount; + iammo.BackpackMaxAmount = newbpmaxamount; + } + } + + let rammo = activator.FindInventory(ammotype); + if (rammo) return rammo.maxamount; + else return GetDefaultByType(ammotype).MaxAmount; + } + + }