From 44e43c48b5144215b8531970aca1eb20786cf05f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 4 Dec 2018 17:31:25 +0100 Subject: [PATCH] - scriptified A_SelectWeapon --- src/p_actionfunctions.cpp | 49 +-------------- wadsrc/static/zscript/actor.txt | 2 +- wadsrc/static/zscript/actor_inventory.txt | 73 +++++++++++++++++------ 3 files changed, 58 insertions(+), 66 deletions(-) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 48e85c6b0..e3d46fd6a 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -1529,54 +1529,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Recoil) } -//=========================================================================== -// -// A_SelectWeapon -// -//=========================================================================== -enum SW_Flags -{ - SWF_SELECTPRIORITY = 1, -}; -DEFINE_ACTION_FUNCTION(AActor, A_SelectWeapon) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_CLASS(cls, AActor); - PARAM_INT(flags); - - bool selectPriority = !!(flags & SWF_SELECTPRIORITY); - - if ((!selectPriority && cls == NULL) || self->player == NULL) - { - ACTION_RETURN_BOOL(false); - } - - auto weaponitem = self->FindInventory(cls); - - if (weaponitem != NULL && weaponitem->IsKindOf(NAME_Weapon)) - { - if (self->player->ReadyWeapon != weaponitem) - { - self->player->PendingWeapon = weaponitem; - } - ACTION_RETURN_BOOL(true); - } - else if (selectPriority) - { - // [XA] if the named weapon cannot be found (or is a dummy like 'None'), - // select the next highest priority weapon. This is basically - // the same as A_CheckReload minus the ammo check. Handy. - self->player->mo->PickNewWeapon(NULL); - ACTION_RETURN_BOOL(true); - } - else - { - ACTION_RETURN_BOOL(false); - } -} - - -//=========================================================================== +///=========================================================================== // // A_Print // diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 70f0e0983..00671c802 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -1067,7 +1067,7 @@ class Actor : Thinker native native void A_QueueCorpse(); native void A_DeQueueCorpse(); native void A_ClearLastHeard(); - native bool A_SelectWeapon(class whichweapon, int flags = 0); + native void A_ClassBossHealth(); native void A_SetAngle(double angle = 0, int flags = 0, int ptr = AAPTR_DEFAULT); native void A_SetPitch(double pitch, int flags = 0, int ptr = AAPTR_DEFAULT); diff --git a/wadsrc/static/zscript/actor_inventory.txt b/wadsrc/static/zscript/actor_inventory.txt index dd69da5b4..f62ae6d03 100644 --- a/wadsrc/static/zscript/actor_inventory.txt +++ b/wadsrc/static/zscript/actor_inventory.txt @@ -58,7 +58,7 @@ extend class Actor // AActor :: GiveInventory // //============================================================================ - + bool GiveInventory(Class type, int amount, bool givecheat = false) { bool result = true; @@ -193,7 +193,7 @@ extend class Actor if (item != null) { - // A_SetInventory sets the absolute amount. + // A_SetInventory sets the absolute amount. // Subtract or set the appropriate amount as necessary. if (amount == item.Amount) @@ -264,12 +264,12 @@ extend class Actor return false; } - if (!item.Use(false)) + if (!item.Use(false)) { return false; } - if (sv_infiniteinventory) + if (sv_infiniteinventory) { return true; } @@ -355,7 +355,7 @@ extend class Actor } } - + //============================================================================ // // AActor :: GiveAmmo @@ -413,7 +413,7 @@ extend class Actor { amount = 1; } - if (mi) + if (mi) { let item = Inventory(Spawn(mi)); if (item == NULL) @@ -446,7 +446,7 @@ extend class Actor bool A_GiveInventory(class itemtype, int amount = 0, int giveto = AAPTR_DEFAULT) { return DoGiveInventory(self, false, itemtype, amount, giveto); - } + } bool A_GiveToTarget(class itemtype, int amount = 0, int giveto = AAPTR_DEFAULT) { @@ -497,7 +497,7 @@ extend class Actor bool DoTakeInventory(Actor receiver, bool orresult, class itemtype, int amount, int flags, int setreceiver = AAPTR_DEFAULT) { int paramnum = 0; - + if (itemtype == NULL) { return false; @@ -517,12 +517,12 @@ extend class Actor bool A_TakeInventory(class itemtype, int amount = 0, int flags = 0, int giveto = AAPTR_DEFAULT) { return DoTakeInventory(self, false, itemtype, amount, flags, giveto); - } + } bool A_TakeFromTarget(class itemtype, int amount = 0, int flags = 0, int giveto = AAPTR_DEFAULT) { return DoTakeInventory(target, false, itemtype, amount, flags, giveto); - } + } int A_TakeFromChildren(class itemtype, int amount = 0) { @@ -564,7 +564,7 @@ extend class Actor // A_SetInventory // //=========================================================================== - + bool A_SetInventory(class itemtype, int amount, int ptr = AAPTR_DEFAULT, bool beyondMax = false) { bool res = false; @@ -600,7 +600,7 @@ extend class Actor { int style = sv_dropstyle; if (style==0) style = gameinfo.defaultdropstyle; - + if (style==2) { Vel.X += random2[DropItem](7); @@ -614,7 +614,7 @@ extend class Actor } } - + //--------------------------------------------------------------------------- // // PROC A_DropItem @@ -730,8 +730,47 @@ extend class Actor return false; } - - - -} + //=========================================================================== + // + // A_SelectWeapon + // + //=========================================================================== + bool A_SelectWeapon(class whichweapon, int flags = 0) + { + bool selectPriority = !!(flags & SWF_SELECTPRIORITY); + let player = self.player; + + if ((!selectPriority && whichweapon == NULL) || player == NULL) + { + return false; + } + + let weaponitem = Weapon(FindInventory(whichweapon)); + + if (weaponitem != NULL) + { + if (player.ReadyWeapon != weaponitem) + { + player.PendingWeapon = weaponitem; + } + return true; + } + else if (selectPriority) + { + // [XA] if the named weapon cannot be found (or is a dummy like 'None'), + // select the next highest priority weapon. This is basically + // the same as A_CheckReload minus the ammo check. Handy. + player.mo.PickNewWeapon(NULL); + return true; + } + else + { + return false; + } + } + + + + +}