Whitelist overkill's health/armor items again
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / sv_overkill.qc
1 #include "sv_overkill.qh"
2
3 #include "hmg.qh"
4 #include "rpc.qh"
5
6 string autocvar_g_overkill;
7
8 bool autocvar_g_overkill_powerups_replace;
9
10 bool autocvar_g_overkill_itemwaypoints = true;
11
12 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
13
14 REGISTER_MUTATOR(ok, expr_evaluate(autocvar_g_overkill) && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
15 {
16         MUTATOR_ONADD
17         {
18                 precache_all_playermodels("models/ok_player/*.dpm");
19
20                 if (autocvar_g_overkill_filter_healthmega)
21                 {
22                         ITEM_HealthMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
23                 }
24                 if (autocvar_g_overkill_filter_armormedium)
25                 {
26                         ITEM_ArmorMedium.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
27                 }
28                 if (autocvar_g_overkill_filter_armorbig)
29                 {
30                         ITEM_ArmorBig.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
31                 }
32                 if (autocvar_g_overkill_filter_armormega)
33                 {
34                         ITEM_ArmorMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
35                 }
36
37                 WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
38                 WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
39
40                 WEP_SHOTGUN.mdl = "ok_shotgun";
41                 WEP_MACHINEGUN.mdl = "ok_mg";
42                 WEP_VORTEX.mdl = "ok_sniper";
43         }
44
45         MUTATOR_ONREMOVE
46         {
47                 ITEM_HealthMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
48                 ITEM_ArmorMedium.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
49                 ITEM_ArmorBig.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
50                 ITEM_ArmorMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
51
52                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
53                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
54         }
55 }
56
57 void W_Blaster_Attack(entity, .entity, float, float, float, float, float, float, float, float, float, float);
58
59 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
60 {
61         entity frag_attacker = M_ARGV(1, entity);
62         entity frag_target = M_ARGV(2, entity);
63         float frag_deathtype = M_ARGV(3, float);
64
65         if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
66         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
67         {
68                 if(frag_attacker != frag_target)
69                 if(!STAT(FROZEN, frag_target))
70                 if(!IS_DEAD(frag_target))
71                 {
72                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
73                         M_ARGV(6, vector) = '0 0 0'; // force
74                 }
75
76                 M_ARGV(4, float) = 0; // damage
77         }
78 }
79
80 void ok_DropItem(entity this, entity targ)
81 {
82         entity e = spawn();
83         e.ok_item = true;
84         Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
85                 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
86 }
87
88 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
89 {
90         entity frag_attacker = M_ARGV(1, entity);
91         entity frag_target = M_ARGV(2, entity);
92
93         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
94
95         ok_DropItem(frag_target, targ);
96
97         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
98         {
99                 .entity weaponentity = weaponentities[slot];
100
101                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
102         }
103 }
104
105 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
106 {
107         entity mon = M_ARGV(0, entity);
108         entity olditem = M_ARGV(1, entity);
109         entity frag_attacker = M_ARGV(2, entity);
110
111         delete(olditem);
112
113         M_ARGV(1, entity) = NULL;
114
115         ok_DropItem(mon, frag_attacker);
116 }
117
118 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
119 {
120         return true;
121 }
122
123 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
124 {
125         if(game_stopped)
126                 return;
127
128         entity player = M_ARGV(0, entity);
129
130         if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
131                 return;
132
133         if(PHYS_INPUT_BUTTON_ATCK2(player) && time >= player.jump_interval)
134         if( !forbidWeaponUse(player)
135                 || (round_handler_IsActive() && !round_handler_IsRoundStarted()) )
136         {
137                 player.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor(player);
138                 makevectors(player.v_angle);
139
140                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
141                 {
142                         .entity weaponentity = weaponentities[slot];
143
144                         if(player.(weaponentity).m_weapon == WEP_Null && slot != 0)
145                                 continue;
146
147                         Weapon oldwep = player.(weaponentity).m_weapon;
148                         player.(weaponentity).m_weapon = WEP_BLASTER;
149                         W_Blaster_Attack(
150                                 player,
151                                 weaponentity,
152                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
153                                 WEP_CVAR_SEC(vaporizer, shotangle),
154                                 WEP_CVAR_SEC(vaporizer, damage),
155                                 WEP_CVAR_SEC(vaporizer, edgedamage),
156                                 WEP_CVAR_SEC(vaporizer, radius),
157                                 WEP_CVAR_SEC(vaporizer, force),
158                                 WEP_CVAR_SEC(vaporizer, speed),
159                                 WEP_CVAR_SEC(vaporizer, spread),
160                                 WEP_CVAR_SEC(vaporizer, delay),
161                                 WEP_CVAR_SEC(vaporizer, lifetime)
162                         );
163                         player.(weaponentity).m_weapon = oldwep;
164                 }
165         }
166
167         PHYS_INPUT_BUTTON_ATCK2(player) = false;
168 }
169
170 MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
171 {
172         return true;
173 }
174
175 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
176 {
177         entity player = M_ARGV(0, entity);
178
179         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
180         {
181                 .entity weaponentity = weaponentities[slot];
182                 entity thiswep = player.(weaponentity);
183
184                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
185                 {
186                         Weapon newwep = player.ok_lastwep[slot];
187                         if(player.ok_lastwep[slot] == WEP_HMG)
188                                 newwep = WEP_MACHINEGUN;
189                         if(player.ok_lastwep[slot] == WEP_RPC)
190                                 newwep = WEP_VORTEX;
191                         thiswep.m_switchweapon = newwep;
192                         player.ok_lastwep[slot] = WEP_Null;
193                 }
194         }
195 }
196
197 bool ok_HandleItemWaypoints(entity e)
198 {
199         if(!autocvar_g_overkill_itemwaypoints)
200                 return false; // don't handle it
201
202         switch(e.itemdef)
203         {
204                 case ITEM_HealthMega: return true;
205                 case ITEM_ArmorMedium: return true;
206                 case ITEM_ArmorBig: return true;
207                 case ITEM_ArmorMega: return true;
208         }
209
210         return false;
211 }
212
213 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
214 {
215         entity item = M_ARGV(0, entity);
216         return ok_HandleItemWaypoints(item);
217 }
218
219 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
220 {
221         entity item = M_ARGV(0, entity);
222         return ok_HandleItemWaypoints(item);
223 }
224
225 MUTATOR_HOOKFUNCTION(ok, FilterItem)
226 {
227         entity item = M_ARGV(0, entity);
228
229         if (item.ok_item)
230         {
231                 return false;
232         }
233         switch(item.itemdef)
234         {
235                 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
236                 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
237                 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
238                 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
239         }
240         if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
241         {
242                 return true;
243         }
244         if (item.classname == "item_strength")
245         {
246                 entity wep = new(weapon_hmg);
247                 setorigin(wep, item.origin);
248                 wep.ok_item = true;
249                 wep.noalign = Item_ShouldKeepPosition(item);
250                 wep.cnt = item.cnt;
251                 wep.team = item.team;
252                 wep.respawntime = g_pickup_respawntime_superweapon;
253                 wep.pickup_anyway = true;
254                 wep.spawnfunc_checked = true;
255                 Item_Initialize(wep, "weapon_hmg");
256                 return true;
257         }
258         else if (item.classname == "item_shield")
259         {
260                 entity wep = new(weapon_rpc);
261                 setorigin(wep, item.origin);
262                 wep.ok_item = true;
263                 wep.noalign = Item_ShouldKeepPosition(item);
264                 wep.cnt = item.cnt;
265                 wep.team = item.team;
266                 wep.respawntime = g_pickup_respawntime_superweapon;
267                 wep.pickup_anyway = true;
268                 wep.spawnfunc_checked = true;
269                 Item_Initialize(wep, "weapon_rpc");
270                 return true;
271         }
272         return true;
273 }
274
275 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
276 {
277         WepSet ok_start_items = (WEPSET(MACHINEGUN) | WEPSET(VORTEX) | WEPSET(SHOTGUN));
278
279         if(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET(RPC); }
280         if(WEP_HMG.weaponstart > 0) { ok_start_items |= WEPSET(HMG); }
281
282         start_items |= IT_UNLIMITED_WEAPON_AMMO;
283         start_weapons = warmup_start_weapons = ok_start_items;
284 }
285
286 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
287 {
288         // turn weapon arena off
289         M_ARGV(0, string) = "off";
290 }
291
292 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
293 {
294         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
295 }
296
297 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
298 {
299         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
300 }
301
302 MUTATOR_HOOKFUNCTION(ok, SetModname)
303 {
304         M_ARGV(0, string) = "Overkill";
305         return true;
306 }