Infinite Ammo Powerup should work as expected now
[k8zan.git] / progs / k8zan_server / EntityExZan.vc
blobeda061f0b06459e800732ef09a52e89477b2ba4f
1 //**************************************************************************
2 //**
3 //**  Copyright (C) 2021-2022 Ketmar Dark
4 //**
5 //**  This program is free software: you can redistribute it and/or modify
6 //**  it under the terms of the GNU General Public License as published by
7 //**  the Free Software Foundation, version 3 of the License ONLY.
8 //**
9 //**  This program is distributed in the hope that it will be useful,
10 //**  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //**  GNU General Public License for more details.
13 //**
14 //**  You should have received a copy of the GNU General Public License
15 //**  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 //**
17 //**************************************************************************
18 // this somewhat balances drops
19 class EntityExZanDCK : replaces(EntityEx, forceparents);
22 //==========================================================================
24 //  DropAllItems
26 //  called in `A_NoBlocking()`, to drop itemd from DropItemList
27 //  can be disabled with a flag in `A_NoBlocking()`
28 //  also, won't be called if `ShouldDropItems()` returned `false`
30 //==========================================================================
31 override void DropAllItems () {
32   bool hellClawSeen = false;
34   // check for monsters dropping things
35   float prb = GetCvarF('k8ZanMod_DropProbChaingun');
36   //printdebug("%C: DropAllItems! prb=%s", self, prb);
37   foreach (auto ref it; DropItemList) {
38     if (!it.Type) continue;
39     // replace most Chainguns with ammo
40     if (it.Type !isa Weapon) continue;
41     if ((it.Type isa 'Chaingun') || (GetClassReplacement(it.Type) isa 'Chaingun')) {
42       if (it.Amount > 1) it.Amount = 1;
43       // even if probability is zero, we still can have a VERY rare PainGun
44       if (FRandomFull() > prb) {
45         //printdebug("%C: replaced `%C` with `AmmoBelt`", self, it.Type);
46         int cnt = P_Random();
47         if (cnt >= 90) {
48           it.Type = AmmoBelt;
49         } else if (cnt/9 == 0) {
50           it.Type = none;
51         } else {
52           it.Type = AmmoBullet;
53           it.Amount = cnt/9;
54         }
55       }
56     } else if (!hellClawSeen && it.Type == Hellclaw) {
57       hellClawSeen = true;
58     }
59   }
61   // Barons will sometimes drop Hellclaw
62   if (!hellClawSeen) {
63     bool hb = ((self isa BaronOfHell) && !(self isa HellKnight));
64     // check for replacement too
65     if (!hb) {
66       auto rc = GetClassReplacee(self.Class);
67       //printdebug("%C: replacee is `%C`", self, rc);
68       if (rc && rc != self.Class) hb = ((rc isa BaronOfHell) && !(rc isa HellKnight));
69     }
70     if (hb) {
71       //printdebug("!!!");
72       prb = GetCvarF('k8ZanMod_DropProbBaronClaw');
73       if (FRandomFull() < prb) {
74         auto it = DropItemList.alloc();
75         it.Type = Hellclaw;
76         it.Amount = 1;
77         it.Chance = 1;
78       }
79     }
80   }
82   ::DropAllItems();