Modular weapon status bar sequence?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Modular weapon status bar sequence?

Post by Matt »

So I've got a chunk of status bar code that looks like this:

Code: Select all

        if(w is "Lumberjack"){
            //draw chainsaw stuff
        }
        else if(w is "HDPistol"){
            //draw pistol stuff
        }
        else if(w is "HDSMG"){ 
...
        }
        else{
            //draw numbers for ammo and secondary ammo as appropriate
 
It looks a bit janky but does the job. However, this means that any time I try to add a new weapon, I have to go back to this function and add another if-then to it. I don't like this because:

1. this one file is going to get unmaintainably long if I include a lot of weapons (e.g., if I wanted to replace a bunch of weapons in another IWAD or TC)

2. it prevents anyone else from doing sub-mods without not only my approval but significant commitment on my part not just incorporating this but maintaining it in the future


Does anyone have a way for me to modularize this, so that basically this code can:

1. Look at the type of weapon that constitutes the readyweapon;
2. Look to that weapon definition to see what status bar function is tied to it; and
3. Execute that function?


Ideally I'd like to be able to do something like:

Code: Select all

extend class HDStatusBar{
 void ZorchCrossbow(){
  ...
 }
}

class ZorchCrossbow:HDWeapon{
 default{
  HDWeapon.SBarFunction "ZorchCrossbow";
  ...
 }
}
and have the original status bar function run ZorchCrossbow() if that is the player's readyweapon.


Or, even better, something like:

Code: Select all

class ZorchCrossbow:HDWeapon{
 override void StatusBarStuff(){
  ...
 }
}  
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Modular weapon status bar sequence?

Post by Matt »

Browsing the now-locked status bar questions thread I think I'm getting a general idea of the logic I want:


Status bar checks cplayer's Weapon.

If it's a regular weapon, print ammo reading.

If it's a weapon inheriting from "X" class, look for a property in "X"(cplayer.readyweapon) that points to a specific "Status Bar Element" class.

Draw the "Status Bar Element" of the class indicated.


...except I don't know what kind of thinker or class or whateverthingamabob this "Status Bar Element" would be or how to define or call it.


Hlp plzkthx?
Post Reply

Return to “Scripting”