Added CGameRules::MaxItemPerSlot to let gamemodes/rules allow how many

items we allow per inventory/HUD slot. CS's is 1 in multiplayer.
This commit is contained in:
Marco Cawthorne 2020-04-23 21:02:38 +02:00
parent b95f7c37eb
commit 7c0315d56f
11 changed files with 83 additions and 6 deletions

View File

@ -1,6 +1,7 @@
r_part effect
{
texture ball
texture "particles/fteparticlefont.tga"
tcoords 97 97 191 191 256
count 1
scale 512
scalefactor 1

View File

@ -75,6 +75,25 @@ CSEv_BuyWeapon_f(float fWeapon)
}
if ((pl.money - g_cstrikeWeaponPrice[iWeapon]) >= 0) {
/* let's check if we've got a limit */
int maxit;
maxit = rules.MaxItemPerSlot();
if (maxit > 0) {
int wantslot = g_weapons[iWeapon].slot;
int c;
for (int i = 0; i < g_weapons.length; i++) {
if (pl.g_items & g_weapons[i].id && g_weapons[i].slot == wantslot) {
c++;
/* we're over the slot limit. */
if (c >= maxit) {
pl.activeweapon = i;
CSEv_DropWeapon();
}
}
}
}
Weapons_AddItem(pl, iWeapon);
Money_AddMoney(pl, -g_cstrikeWeaponPrice[iWeapon]);
Sound_Play(pl, CHAN_ITEM, "buy.weapon");

View File

@ -220,4 +220,4 @@ void
CSGameRules::PlayerKill(player pl)
{
Damage_Apply(pl, pl, pl.health, WEAPON_NONE, DMG_SKIP_ARMOR);
}
}

View File

@ -74,4 +74,5 @@ class CSMultiplayerRules:CSGameRules
virtual void(player) PlayerMakeSpectator;
virtual void(player, int) PlayerRespawn;
virtual entity(float) PlayerFindSpawn;
virtual int(void) MaxItemPerSlot;
};

View File

@ -788,6 +788,12 @@ CSMultiplayerRules::PlayerSpawn(player pl)
forceinfokey(pl, "*team", "0");
}
int
CSMultiplayerRules::MaxItemPerSlot(void)
{
return 1;
}
void
CSMultiplayerRules::CSMultiplayerRules(void)
{

View File

@ -104,6 +104,12 @@ CGameRules::SpectatorThink(player pl)
//print("SpectatorThink!\n");
}*/
int
CGameRules::MaxItemPerSlot(void)
{
return -1;
}
void
CGameRules::CGameRules(void)
{

View File

@ -38,6 +38,8 @@ class CGameRules
virtual void(void) LevelNewParms;
virtual void(player) LevelChangeParms;
virtual int(void) MaxItemPerSlot;
/* spectator */
/*virtual void(player) SpectatorConnect;
virtual void(player) SpectatorDisconnect;

View File

@ -17,6 +17,8 @@
/* PICKUP ITEMS */
class item_pickup:CBaseTrigger
{
int m_iClip;
int m_iWasDropped;
int id;
void(void) item_pickup;
@ -72,7 +74,10 @@ void item_pickup::Respawn(void)
think = __NULL__;
nextthink = -1;
sound(this, CHAN_ITEM, "items/suitchargeok1.wav", 1, ATTN_NORM, 150);
if (!m_iWasDropped)
sound(this, CHAN_ITEM, "items/suitchargeok1.wav", 1, ATTN_NORM, 150);
droptofloor();
}

View File

@ -16,6 +16,7 @@
#ifdef CLIENT
var int FX_EXPLOSION_MAIN;
var int FX_EXPLOSION_BS;
void
FX_Explosion_Init(void)
@ -25,6 +26,7 @@ FX_Explosion_Init(void)
precache_sound("weapons/explode5.wav");
precache_model("sprites/fexplo.spr");
FX_EXPLOSION_MAIN = particleeffectnum("fx_explosion.main");
FX_EXPLOSION_BS = particleeffectnum("fx_explosion.blacksmoke");
}
#endif
@ -56,6 +58,7 @@ FX_Explosion(vector vecPos)
eExplosion.nextthink = time + 0.05f;
pointparticles(FX_EXPLOSION_MAIN, vecPos, [0,0,0], 1);
pointparticles(FX_EXPLOSION_BS, vecPos, [0,0,0], 1);
#endif
}

View File

@ -284,6 +284,25 @@ int Weapons_AddItem(player pl, int w)
entity oldself = self;
self = pl;
/* let's check if we've got a limit */
int maxit;
CGameRules rules = (CGameRules)g_grMode;
maxit = rules.MaxItemPerSlot();
if (maxit > 0) {
int wantslot = g_weapons[w].slot;
int c;
for (int i = 0; i < g_weapons.length; i++) {
if (pl.g_items & g_weapons[i].id && g_weapons[i].slot == wantslot) {
c++;
/* we're over the slot limit. */
if (c >= maxit) {
return FALSE;
}
}
}
}
/* in case programmer decided not to add a pickup callback */
if (g_weapons[w].pickup == __NULL__) {
if (pl.g_items & g_weapons[w].id) {
@ -384,7 +403,7 @@ void CSEv_DropWeapon(void)
if (!pl.activeweapon)
return;
item_pickup drop = spawn(item_pickup);
item_pickup drop = spawn(item_pickup, m_iWasDropped: TRUE, m_iClip: pl.a_ammo1);
drop.setitem(pl.activeweapon);
setorigin(drop, pl.origin);
drop.solid = SOLID_NOT;

View File

@ -9,7 +9,7 @@ r_part ember
scalefactor 1
friction 8
gravity 50
die 1
die 1.5
blend add
randomvel 5
veladd 1
@ -51,4 +51,19 @@ r_part main
friction 1
blend add
assoc expgib
}
}
r_part blacksmoke
{
texture "particles/fteparticlefont.tga"
tcoords 97 97 191 191 256
count 1
scale 324
scalefactor 1
die 3
alpha 1
rgb 0 0 0
spawnmode ball
gravity -25
veladd -20
}