News: Celebrating over 10 years serving the creative community

Author Topic: Having more than 32 weapons in Half-Life mod?  (Read 101 times)

Napoleon

  • NS Project
  • Roach
  • *
  • Posts: 16
Having more than 32 weapons in Half-Life mod?
« on: July 06, 2019, 11:16:53 PM »
Hello All, I hope the old crew is doing good those days.

I know it's more than 20 year old engine, but still It never gets old if you know what I mean.
So I started again with one of my coding projects for Half-Life - it's arena mod with intended more than 32 weapons. The original idea was to have around 40 different weapons, unfortunately I guess I hit a roadblock...

I have the following issue:

Having more than 32 weapons in Half-Life mod.

For quite some time I was trying to incorporate more than 32 weapon in my Half-Life mod. I noticed there's a dependency between the number of "WEAPON_SUIT" and the number of allowed weapons on the mod.

For example by default the number of the suit is 31:

.\dlls\weapons.h
Code: [Select]
#define WEAPON_SUIT 31 // ?????
.\common\cdll_dll.h
Code: [Select]
#define WEAPON_SUIT 31
Note that I already have the Max_WEAPONS redefined as 64 defined (I know that the hard limit for max weapons in the engine is actually 64:

Code: [Select]
#define MAX_WEAPONS 64[/code]

The definition for all weapons is the following:

Code: [Select]
#define WEAPON_ALLWEAPONS (~(1<<WEAPON_SUIT))
So we're dependent on the number of the WEAPON_SUIT. If I try to add weapon with number above 32, I get the game to crash/freeze. I have double checked and it's not with the weapon code or with the definitions for that specific weapon (I obviously commented out another weapon and placed my code over that weapon's place and it all worked fine).
If I add weapon beyond 32, I don't get errors in the compiler and the "client" and "server" library compile well. So I started playing around with the definitions.

If I put WEAPON_SUIT to greater value than 31, (example 64, 128 or 256; I tested other values from 33 to 256 - the result is the same).
I can define more than 32 weapons for the mod, however there are other issues arising after that...

1. I get the following warnings when I compile:

Quote
1>d:\sdk_\dlls\player.cpp(761): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\items.cpp(188): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\healthkit.cpp(199): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\h_battery.cpp(121): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\bot.cpp(882): warning C4293: '<<' : shift count negative or too big, undefined behavior

Those warnings are related to lines containing
Code: [Select]
pev->weapons & (1<<WEAPON_SUIT) or
Code: [Select]
pev->weapons &= ~WEAPON_ALLWEAPONS;
So clearly changing the number of WEAPON_SUIT is the issue here.

2. When I start a game with the compiled libraries (with more than 32 weapons defined), I observe stage behaviors with the weapons above 32:

a) game crashing / freezing upon spawning / getting that weapon.
b) game working OK, however the gun has no animations, sprites and sounds.
c) game working, but with no sprites for the game in general.

So I guess the current definition does not support more than 32 (32-1).
I've searched everywhere for example on how to change the definitions properly to support more than 32 bytes (including based on warning C4293) and I'm unable to find a solution or workaround.

I know there are mods out there that have the functionality implemented - I've seen it in HL Weapon's Edition, XASH, Half-Life: Enhanced and few others; and I was wondering did anyone faced the same issue like me?
Have you been able to find a workaround for this one?

Any inside on this would be greatly appreciated.
« Last Edit: July 06, 2019, 11:18:43 PM by Napoleon »