]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Don't force all ammo values to 999 when spawning with infinite ammo
authorMario <mario.mario@y7mail.com>
Fri, 20 Sep 2024 20:03:40 +0000 (20:03 +0000)
committerterencehill <piuntn@gmail.com>
Fri, 20 Sep 2024 20:03:40 +0000 (20:03 +0000)
qcsrc/common/weapons/weapon/arc.qc
qcsrc/common/weapons/weapon/machinegun.qc
qcsrc/common/weapons/weapon/minelayer.qc
qcsrc/common/weapons/weapon/shotgun.qc
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/havocbot/roles.qc
qcsrc/server/world.qc

index 02199bb8dfb6b4149a159bc86494d77bdf7e4730..af00e3f71a056e3e0dc62c1287f629ac6715afab 100644 (file)
@@ -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;
index db979d61ad4fa62cadb41d8dbccdf08874e11a73..b0517597f4f6553b2e30d36e68657dcbe4ecb533 100644 (file)
@@ -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;
index c272d45728734081b6bdf7d2d030d5a44fa3b3ab..0a4a914dc215d24b8c21be33d987f39086d06a5c 100644 (file)
@@ -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);
                }
        }
index 49d36169ce7575f4dac3038eb471aec529f28c07..7239757700ba3784498aa860dcdf63bd7fb07adb 100644 (file)
@@ -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;
index 51774e14824fd4a369b6668cb2edfdc857633958..2aa283520111482a5c2bd4d36fe51bab1c4942fd 100644 (file)
@@ -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
index 020d993bed9fb03f133e630d3a9df5f771d90b6b..9684c26a1c9b2e532d79ddfec702efcd6f37d433 100644 (file)
@@ -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;
 };
index 3f38a933f9127df678e79d930d42931aae7167c5..0fd0747da5d676056b0893da04cec519abd19d73 100644 (file)
@@ -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;