From f0e4f54c80eca5059be31e3ba5eb9586a9f6b960 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Mar 2017 18:38:09 +0100 Subject: [PATCH] - one more bit of scriptification. --- src/g_statusbar/sbar.h | 2 - src/g_statusbar/sbarinfo.cpp | 18 +++++++- src/g_statusbar/shared_sbar.cpp | 43 ------------------- wadsrc/static/zscript/statusbar/statusbar.txt | 34 ++++++++++++++- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index c41a0ef764..927617c0b1 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -387,8 +387,6 @@ public: void RefreshBackground () const; - void GetCurrentAmmo (AInventory *&ammo1, AInventory *&ammo2, int &ammocount1, int &ammocount2) const; - public: AInventory *ValidateInvFirst (int numVisible) const; void DrawCrosshair (); diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index c5d4c4a3e5..6548822fa2 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1068,8 +1068,24 @@ public: } } + if (CPlayer->ReadyWeapon != NULL) + { + ammo1 = CPlayer->ReadyWeapon->Ammo1; + ammo2 = CPlayer->ReadyWeapon->Ammo2; + if (ammo1 == NULL) + { + ammo1 = ammo2; + ammo2 = NULL; + } + } + else + { + ammo1 = ammo2 = NULL; + } + ammocount1 = ammo1 != NULL ? ammo1->Amount : 0; + ammocount2 = ammo2 != NULL ? ammo2->Amount : 0; + //prepare ammo counts - wrapper->GetCurrentAmmo(ammo1, ammo2, ammocount1, ammocount2); armor = CPlayer->mo->FindInventory(NAME_BasicArmor); if(state != HUD_AltHud) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index dab6e4e362..a88b0aac3a 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1377,49 +1377,6 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, ValidateInvFirst) } -//============================================================================ -// -// DBaseStatusBar :: GetCurrentAmmo -// -// Returns the types and amounts of ammo used by the current weapon. If the -// weapon only uses one type of ammo, it is always returned as ammo1. -// -//============================================================================ - -void DBaseStatusBar::GetCurrentAmmo (AInventory *&ammo1, AInventory *&ammo2, int &ammocount1, int &ammocount2) const -{ - if (CPlayer->ReadyWeapon != NULL) - { - ammo1 = CPlayer->ReadyWeapon->Ammo1; - ammo2 = CPlayer->ReadyWeapon->Ammo2; - if (ammo1 == NULL) - { - ammo1 = ammo2; - ammo2 = NULL; - } - } - else - { - ammo1 = ammo2 = NULL; - } - ammocount1 = ammo1 != NULL ? ammo1->Amount : 0; - ammocount2 = ammo2 != NULL ? ammo2->Amount : 0; -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetCurrentAmmo) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - AInventory *ammo1, *ammo2; - int ammocount1, ammocount2; - self->GetCurrentAmmo(ammo1, ammo2, ammocount1, ammocount2); - if (numret >= 1) ret[0].SetPointer(ammo1, ATAG_OBJECT); - if (numret >= 2) ret[1].SetPointer(ammo2, ATAG_OBJECT); - if (numret >= 3) ret[2].SetInt(ammocount1); - if (numret >= 4) ret[3].SetInt(ammocount2); - return MIN(numret, 4); -} - - //============================================================================ // // CCMD showpop diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index 9bdbb00e45..5d79de756d 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -79,6 +79,38 @@ class BaseStatusBar native ui virtual void SetMugShotState (String state_name, bool wait_till_done=false, bool reset=false) {} native void RefreshBackground () const; - native Inventory, Inventory, int, int GetCurrentAmmo () const; native Inventory ValidateInvFirst (int numVisible) const; + + //============================================================================ + // + // DBaseStatusBar :: GetCurrentAmmo + // + // Returns the types and amounts of ammo used by the current weapon. If the + // weapon only uses one type of ammo, it is always returned as ammo1. + // + //============================================================================ + + Inventory, Inventory, int, int GetCurrentAmmo () const + { + Ammo ammo1, ammo2; + if (CPlayer.ReadyWeapon != NULL) + { + ammo1 = CPlayer.ReadyWeapon.Ammo1; + ammo2 = CPlayer.ReadyWeapon.Ammo2; + if (ammo1 == NULL) + { + ammo1 = ammo2; + ammo2 = NULL; + } + } + else + { + ammo1 = ammo2 = NULL; + } + let ammocount1 = ammo1 != NULL ? ammo1.Amount : 0; + let ammocount2 = ammo2 != NULL ? ammo2.Amount : 0; + return ammo1, ammo2, ammocount1, ammocount2; + } + + }