diff --git a/src/g_game.cpp b/src/g_game.cpp index 1428fa5a9..13bd741ef 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -372,79 +372,43 @@ CCMD (weapprev) } } -static void DisplayNameTag(const char *tag) +static void DisplayNameTag(AActor *actor) { + auto tag = actor->GetTag(); if ((displaynametags & 1) && StatusBar && SmallFont) StatusBar->AttachMessage(Create(SmallFont, tag, 1.5f, 0.80f, 0, 0, (EColorRange)*nametagcolor, 2.f, 0.35f), MAKE_ID('S', 'I', 'N', 'V')); } +DEFINE_ACTION_FUNCTION_NATIVE(AActor, DisplayNameTag, DisplayNameTag) +{ + PARAM_SELF_PROLOGUE(AActor); + DisplayNameTag(self); + return 0; +} + CCMD (invnext) { - AInventory *next; - - if (who == NULL) - return; - - auto old = who->InvSel; - if (who->InvSel != NULL) + if (who != NULL) { - if ((next = who->InvSel->NextInv()) != NULL) + IFVM(PlayerPawn, InvNext) { - who->InvSel = next; + VMValue param = who; + VMCall(func, ¶m, 1, nullptr, 0); } - else - { - // Select the first item in the inventory - if (!(who->Inventory->ItemFlags & IF_INVBAR)) - { - who->InvSel = who->Inventory->NextInv(); - } - else - { - who->InvSel = who->Inventory; - } - } - if (who->InvSel) DisplayNameTag(who->InvSel->GetTag()); - } - who->player->inventorytics = 5*TICRATE; - if (old != who->InvSel) - { - S_Sound(CHAN_AUTO, "misc/invchange", 1.0, ATTN_NONE); } } -CCMD (invprev) +CCMD(invprev) { - AInventory *item, *newitem; - - if (who == NULL) - return; - - auto old = who->InvSel; - if (who->InvSel != NULL) + if (who != NULL) { - if ((item = who->InvSel->PrevInv()) != NULL) + IFVM(PlayerPawn, InvNext) { - who->InvSel = item; + VMValue param = who; + VMCall(func, ¶m, 1, nullptr, 0); } - else - { - // Select the last item in the inventory - item = who->InvSel; - while ((newitem = item->NextInv()) != NULL) - { - item = newitem; - } - who->InvSel = item; - } - if (who->InvSel) DisplayNameTag(who->InvSel->GetTag()); - } - who->player->inventorytics = 5*TICRATE; - if (old != who->InvSel) - { - S_Sound(CHAN_AUTO, "misc/invchange", 1.0, ATTN_NONE); } } diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 088ca2c53..b065fde6b 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -457,6 +457,7 @@ class Actor : Thinker native virtual native bool Slam(Actor victim); virtual native void Touch(Actor toucher); native void Substitute(Actor replacement); + native ui void DisplayNameTag(); // Called by PIT_CheckThing to check if two actors actually can collide. virtual bool CanCollideWith(Actor other, bool passive) @@ -998,7 +999,7 @@ class Actor : Thinker native deprecated("2.3") native void A_BulletAttack(); native void A_WolfAttack(int flags = 0, sound whattoplay = "weapons/pistol", double snipe = 1.0, int maxdamage = 64, int blocksize = 128, int pointblank = 2, int longrange = 4, double runspeed = 160.0, class pufftype = "BulletPuff"); - native void A_PlaySound(sound whattoplay = "weapons/pistol", int slot = CHAN_BODY, double volume = 1.0, bool looping = false, double attenuation = ATTN_NORM, bool local = false); + native clearscope void A_PlaySound(sound whattoplay = "weapons/pistol", int slot = CHAN_BODY, double volume = 1.0, bool looping = false, double attenuation = ATTN_NORM, bool local = false); native void A_SoundVolume(int slot, double volume); deprecated("2.3") void A_PlayWeaponSound(sound whattoplay) { A_PlaySound(whattoplay, CHAN_WEAPON); } native void A_StopSound(int slot = CHAN_VOICE); // Bad default but that's what is originally was... diff --git a/wadsrc/static/zscript/shared/player_inventory.txt b/wadsrc/static/zscript/shared/player_inventory.txt index 9ab6f1427..1f21e8314 100644 --- a/wadsrc/static/zscript/shared/player_inventory.txt +++ b/wadsrc/static/zscript/shared/player_inventory.txt @@ -1,5 +1,73 @@ extend class PlayerPawn { + + //=========================================================================== + // + // + // + //=========================================================================== + + ui void InvNext() + { + Inventory next; + + let old = InvSel; + if (InvSel != NULL) + { + if ((next = InvSel.NextInv()) != NULL) + { + InvSel = next; + } + else + { + // Select the first item in the inventory + InvSel = FirstInv(); + } + if (InvSel) InvSel.DisplayNameTag(); + } + player.inventorytics = 5*TICRATE; + if (old != InvSel) + { + A_PlaySound("misc/invchange", CHAN_AUTO, 1.0, false, ATTN_NONE); + } + } + + //=========================================================================== + // + // APlayerPawn :: AddInventory + // + //=========================================================================== + + ui void InvPrev() + { + Inventory item, newitem; + + let old = InvSel; + if (InvSel != NULL) + { + if ((item = InvSel.PrevInv()) != NULL) + { + InvSel = item; + } + else + { + // Select the last item in the inventory + item = InvSel; + while ((newitem = item.NextInv()) != NULL) + { + item = newitem; + } + InvSel = item; + } + if (InvSel) InvSel.DisplayNameTag(); + } + player.inventorytics = 5*TICRATE; + if (old != InvSel) + { + A_PlaySound("misc/invchange", CHAN_AUTO, 1.0, false, ATTN_NONE); + } + } + //=========================================================================== // // APlayerPawn :: AddInventory