From 509efb2d976ff9e2f8f6f475815533ce97899857 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 20 Sep 2024 20:03:40 +0000 Subject: [PATCH] Don't force all ammo values to 999 when spawning with infinite ammo --- qcsrc/common/weapons/weapon/arc.qc | 22 +++++++----- qcsrc/common/weapons/weapon/machinegun.qc | 20 ++++++----- qcsrc/common/weapons/weapon/minelayer.qc | 5 ++- qcsrc/common/weapons/weapon/shotgun.qc | 2 +- qcsrc/server/bot/default/havocbot/havocbot.qc | 6 ++-- qcsrc/server/bot/default/havocbot/roles.qc | 3 +- qcsrc/server/world.qc | 36 +++++++------------ 7 files changed, 48 insertions(+), 46 deletions(-) diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index 02199bb8d..af00e3f71 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -644,15 +644,19 @@ METHOD(Arc, wr_think, void(entity thiswep, entity actor, .entity weaponentity, i w_ready(thiswep, actor, weaponentity, fire); return; } - float ammo_available = GetResource(actor, thiswep.ammo_type); - // We don't want to shoot 3 rounds if there's 2 left in the mag, so we'll use a fraction. - // Also keep the fraction <= 1 otherwise we'd mag dump in one burst. - float burst_fraction = min(1, ammo_available / WEP_CVAR(WEP_ARC, bolt_ammo)); - int to_shoot = floor(WEP_CVAR(WEP_ARC, bolt_count) * burst_fraction); - - // We also don't want to use 3 rounds if there's only 2 left. - int to_use = min(WEP_CVAR(WEP_ARC, bolt_ammo), ammo_available); - W_DecreaseAmmo(thiswep, actor, to_use, weaponentity); + int to_shoot = WEP_CVAR(WEP_ARC, bolt_count); + if(!(actor.items & IT_UNLIMITED_AMMO)) + { + float ammo_available = GetResource(actor, thiswep.ammo_type); + // We don't want to shoot 3 rounds if there's 2 left in the mag, so we'll use a fraction. + // Also keep the fraction <= 1 otherwise we'd mag dump in one burst. + float burst_fraction = min(1, ammo_available / WEP_CVAR(WEP_ARC, bolt_ammo)); + to_shoot = floor(to_shoot * burst_fraction); + + // We also don't want to use 3 rounds if there's only 2 left. + int to_use = min(WEP_CVAR(WEP_ARC, bolt_ammo), ammo_available); + W_DecreaseAmmo(thiswep, actor, to_use, weaponentity); + } // Bursting counts up to 0 from a negative. actor.(weaponentity).misc_bulletcounter = -to_shoot; diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index db979d61a..b0517597f 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -209,14 +209,18 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen ammo_available = GetResource(actor, thiswep.ammo_type); } - // We don't want to shoot 3 rounds if there's 2 left in the mag, so we'll use a fraction. - // Also keep the fraction <= 1 otherwise we'd mag dump in one burst. - float burst_fraction = min(1, ammo_available / WEP_CVAR(WEP_MACHINEGUN, burst_ammo)); - int to_shoot = floor(WEP_CVAR(WEP_MACHINEGUN, burst) * burst_fraction); - - // We also don't want to use 3 rounds if there's only 2 left. - int to_use = min(WEP_CVAR(WEP_MACHINEGUN, burst_ammo), ammo_available); - W_DecreaseAmmo(thiswep, actor, to_use, weaponentity); + int to_shoot = WEP_CVAR(WEP_MACHINEGUN, burst); + if(!(actor.items & IT_UNLIMITED_AMMO)) + { + // We don't want to shoot 3 rounds if there's 2 left in the mag, so we'll use a fraction. + // Also keep the fraction <= 1 otherwise we'd mag dump in one burst. + float burst_fraction = min(1, ammo_available / WEP_CVAR(WEP_MACHINEGUN, burst_ammo)); + to_shoot = floor(to_shoot * burst_fraction); + + // We also don't want to use 3 rounds if there's only 2 left. + int to_use = min(WEP_CVAR(WEP_MACHINEGUN, burst_ammo), ammo_available); + W_DecreaseAmmo(thiswep, actor, to_use, weaponentity); + } // Bursting counts up to 0 from a negative. actor.(weaponentity).misc_bulletcounter = -to_shoot; diff --git a/qcsrc/common/weapons/weapon/minelayer.qc b/qcsrc/common/weapons/weapon/minelayer.qc index c272d4572..0a4a914dc 100644 --- a/qcsrc/common/weapons/weapon/minelayer.qc +++ b/qcsrc/common/weapons/weapon/minelayer.qc @@ -433,7 +433,10 @@ METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, .entity weaponent if(autocvar_g_balance_minelayer_reload_ammo && actor.(weaponentity).clip_load < WEP_CVAR(WEP_MINE_LAYER, ammo)) // forced reload { // not if we're holding the minelayer without enough ammo, but can detonate existing mines - if(!(W_MineLayer_PlacedMines(actor, weaponentity, false) && GetResource(actor, thiswep.ammo_type) < WEP_CVAR(WEP_MINE_LAYER, ammo))) { + bool enough_ammo = (GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(WEP_MINE_LAYER, ammo)); + if(actor.items & IT_UNLIMITED_AMMO) + enough_ammo = true; + if(!(W_MineLayer_PlacedMines(actor, weaponentity, false) && !enough_ammo)) { thiswep.wr_reload(thiswep, actor, weaponentity); } } diff --git a/qcsrc/common/weapons/weapon/shotgun.qc b/qcsrc/common/weapons/weapon/shotgun.qc index 49d36169c..723975770 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qc +++ b/qcsrc/common/weapons/weapon/shotgun.qc @@ -253,7 +253,7 @@ METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentit // force reload weapon when clip is empty or insufficent if(WEP_CVAR(WEP_SHOTGUN, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(WEP_SHOTGUN, ammo)) { - if(actor.(weaponentity).clip_load >= 0 && GetResource(actor, thiswep.ammo_type) > 0) + if(actor.(weaponentity).clip_load >= 0 && (GetResource(actor, thiswep.ammo_type) > 0 || (actor.items & IT_UNLIMITED_AMMO))) { thiswep.wr_reload(thiswep, actor, weaponentity); return; diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 51774e148..2aa283520 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -461,7 +461,7 @@ void havocbot_movetogoal(entity this) // Jetpack navigation if(this.navigation_jetpack_goal) if(this.goalcurrent==this.navigation_jetpack_goal) - if(GetResource(this, RES_FUEL)) + if(GetResource(this, RES_FUEL) > 0 || (this.items & IT_UNLIMITED_AMMO)) { if(autocvar_bot_debug_goalstack) { @@ -1469,7 +1469,7 @@ void havocbot_chooseenemy(entity this) this.havocbot_stickenemy_time = 0; } -float havocbot_chooseweapon_checkreload(entity this, .entity weaponentity, int new_weapon) +bool havocbot_chooseweapon_checkreload(entity this, .entity weaponentity, int new_weapon) { // bots under this skill cannot find unloaded weapons to reload idly when not in combat, // so skip this for them, or they'll never get to reload their weapons at all. @@ -1480,6 +1480,8 @@ float havocbot_chooseweapon_checkreload(entity this, .entity weaponentity, int n // if this weapon is scheduled for reloading, don't switch to it during combat if (this.(weaponentity).weapon_load[new_weapon] < 0) { + if(this.items & IT_UNLIMITED_AMMO) + return true; FOREACH(Weapons, it != WEP_Null, { if(it.wr_checkammo1(it, this, weaponentity) + it.wr_checkammo2(it, this, weaponentity)) return true; // other weapon available diff --git a/qcsrc/server/bot/default/havocbot/roles.qc b/qcsrc/server/bot/default/havocbot/roles.qc index 020d993be..9684c26a1 100644 --- a/qcsrc/server/bot/default/havocbot/roles.qc +++ b/qcsrc/server/bot/default/havocbot/roles.qc @@ -47,12 +47,13 @@ bool havocbot_goalrating_item_can_be_left_to_teammate(entity this, entity player if (GetResource(item, RES_HEALTH) && GetResource(player, RES_HEALTH) <= GetResource(this, RES_HEALTH)) {return true;} if (GetResource(item, RES_ARMOR) && GetResource(player, RES_ARMOR) <= GetResource(this, RES_ARMOR)) {return true;} if (STAT(WEAPONS, item) && !(STAT(WEAPONS, player) & STAT(WEAPONS, item))) {return true;} + if (item.itemdef.instanceOfPowerup) {return true;} + if (this.items & IT_UNLIMITED_AMMO) {return true;} if (GetResource(item, RES_SHELLS) && GetResource(player, RES_SHELLS) <= GetResource(this, RES_SHELLS)) {return true;} if (GetResource(item, RES_BULLETS) && GetResource(player, RES_BULLETS) <= GetResource(this, RES_BULLETS)) {return true;} if (GetResource(item, RES_ROCKETS) && GetResource(player, RES_ROCKETS) <= GetResource(this, RES_ROCKETS)) {return true;} if (GetResource(item, RES_CELLS) && GetResource(player, RES_CELLS) <= GetResource(this, RES_CELLS)) {return true;} if (GetResource(item, RES_PLASMA) && GetResource(player, RES_PLASMA) <= GetResource(this, RES_PLASMA)) {return true;} - if (item.itemdef.instanceOfPowerup) {return true;} return false; }; diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 3f38a933f..0fd0747da 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -2067,30 +2067,18 @@ void readplayerstartcvars() if(!cvar("g_use_ammunition")) start_items |= IT_UNLIMITED_AMMO; - if(start_items & IT_UNLIMITED_AMMO) - { - start_ammo_shells = 999; - start_ammo_nails = 999; - start_ammo_rockets = 999; - start_ammo_cells = 999; - start_ammo_plasma = 999; - start_ammo_fuel = 999; - } - else - { - start_ammo_shells = cvar("g_start_ammo_shells"); - start_ammo_nails = cvar("g_start_ammo_nails"); - start_ammo_rockets = cvar("g_start_ammo_rockets"); - start_ammo_cells = cvar("g_start_ammo_cells"); - start_ammo_plasma = cvar("g_start_ammo_plasma"); - start_ammo_fuel = cvar("g_start_ammo_fuel"); - random_start_weapons_count = cvar("g_random_start_weapons_count"); - SetResource(random_start_ammo, RES_SHELLS, cvar("g_random_start_shells")); - SetResource(random_start_ammo, RES_BULLETS, cvar("g_random_start_bullets")); - SetResource(random_start_ammo, RES_ROCKETS, cvar("g_random_start_rockets")); - SetResource(random_start_ammo, RES_CELLS, cvar("g_random_start_cells")); - SetResource(random_start_ammo, RES_PLASMA, cvar("g_random_start_plasma")); - } + start_ammo_shells = cvar("g_start_ammo_shells"); + start_ammo_nails = cvar("g_start_ammo_nails"); + start_ammo_rockets = cvar("g_start_ammo_rockets"); + start_ammo_cells = cvar("g_start_ammo_cells"); + start_ammo_plasma = cvar("g_start_ammo_plasma"); + start_ammo_fuel = cvar("g_start_ammo_fuel"); + random_start_weapons_count = cvar("g_random_start_weapons_count"); + SetResource(random_start_ammo, RES_SHELLS, cvar("g_random_start_shells")); + SetResource(random_start_ammo, RES_BULLETS, cvar("g_random_start_bullets")); + SetResource(random_start_ammo, RES_ROCKETS, cvar("g_random_start_rockets")); + SetResource(random_start_ammo, RES_CELLS, cvar("g_random_start_cells")); + SetResource(random_start_ammo, RES_PLASMA, cvar("g_random_start_plasma")); warmup_start_ammo_shells = start_ammo_shells; warmup_start_ammo_nails = start_ammo_nails; -- 2.39.2