Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Auto Switch Weapon on Pickup" option #541

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andrikpowell
Copy link
Contributor

Took a stab at implementing an Auto Switch option asked for in (#511).

It's a rather simple casual only setting that's disabled in strict mode, demo recording/playing, netgame, and deathmatch.

Let me know if there's better precedent when it comes to netgame / deathmatch compat for options.

@@ -187,43 +190,47 @@ static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put if (!autoswitch) return true; before if (heretic) and remove these 2 conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great catch! Also simplifies this section much more nicely :)

@@ -2298,7 +2307,8 @@ dboolean Heretic_P_GiveWeapon(player_t * player, weapontype_t weapon)
player->bonuscount += BONUSADD;
player->weaponowned[weapon] = true;
P_GiveAmmo(player, wpnlev1info[weapon].ammo, GetWeaponAmmo[weapon]);
player->pendingweapon = weapon;
if (autoswitch)
player->pendingweapon = weapon;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition below is using brackets, so lets follow the style. Ik its not consistent at all, but its better if new code tries to match whats already there.

And maybe you should just extract this if into a new P_AutoSwitchWeapon

Copy link
Contributor Author

@andrikpowell andrikpowell Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm we could add a P_AutoSwitchWeapon, although not all of these cases are player->pendingweapon = weapon...

The player->pendingweapon is the same, but the result is variable. So doing a P_AutoSwitchWeapon() would require running a variable through, which at that point idk if it's worth the hassle.

That is unless you were thinking of replacing all autoswitch cases with a function... although the conditions around each autoswitch seem quite variable, so it doesn't seem like a major boon.

Actually regarding the brackets style, I'm fine with adding brackets. Although I usually tend to avoid using brackets for 1 line conditions, as I usually find it looks cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my thoughts on P_AutoSwitchWeapon... I changed my mind

@@ -108,6 +108,8 @@ static weapontype_t GetAmmoChange[] = {
wp_mace
};

#define autoswitch (allow_incompatibility && !deathmatch && !netgame ? dsda_IntConfig(dsda_config_switch_weapon_on_pickup) : true)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put () around allow_incompatibility && !deathmatch && !netgame. I wouldnt think the ternary captures all those conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in my test, this does actually work correctly. (i.e. I tested putting allow_incompatiblity at the end) and it still worked as intended.

Lol I will admit it is probably better practice to put () around the conditions though, so I'll do it anyway. :P

@andrikpowell
Copy link
Contributor Author

Implementing P_AutoSwitchWeapon has simplified the code significantly. Ready for another review :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants