]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
Merge branch 'master' into Lyberta/RandomStartWeapons
[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 bool autocvar_g_overkill_filter_healthmega;
13 bool autocvar_g_overkill_filter_armormedium;
14 bool autocvar_g_overkill_filter_armorbig;
15 bool autocvar_g_overkill_filter_armormega;
16
17 .float ok_item;
18
19 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
20
21 void ok_Initialize();
22
23 REGISTER_MUTATOR(ok, expr_evaluate(autocvar_g_overkill) && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
24 {
25         MUTATOR_ONADD
26         {
27                 ok_Initialize();
28         }
29
30         MUTATOR_ONREMOVE
31         {
32                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
33                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
34         }
35 }
36
37 void W_Blaster_Attack(entity, .entity, float, float, float, float, float, float, float, float, float, float);
38 spawnfunc(weapon_hmg);
39 spawnfunc(weapon_rpc);
40
41 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
42 {
43         entity frag_attacker = M_ARGV(1, entity);
44         entity frag_target = M_ARGV(2, entity);
45         float frag_deathtype = M_ARGV(3, float);
46
47         if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
48         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
49         {
50                 if(frag_attacker != frag_target)
51                 if(!STAT(FROZEN, frag_target))
52                 if(!IS_DEAD(frag_target))
53                 {
54                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
55                         M_ARGV(6, vector) = '0 0 0'; // force
56                 }
57
58                 M_ARGV(4, float) = 0; // damage
59         }
60 }
61
62 void ok_DropItem(entity this, entity targ)
63 {
64         entity e = new(droppedweapon); // hax
65         e.ok_item = true;
66         e.noalign = true;
67         e.pickup_anyway = true;
68         e.spawnfunc_checked = true;
69         spawnfunc_item_armor_small(e);
70         if (!wasfreed(e)) { // might have been blocked by a mutator
71         set_movetype(e, MOVETYPE_TOSS);
72         e.gravity = 1;
73         e.reset = SUB_Remove;
74         setorigin(e, this.origin + '0 0 32');
75         e.velocity = '0 0 200' + normalize(targ.origin - this.origin) * 500;
76         SUB_SetFade(e, time + 5, 1);
77         }
78 }
79
80 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
81 {
82         entity frag_attacker = M_ARGV(1, entity);
83         entity frag_target = M_ARGV(2, entity);
84
85         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
86
87         ok_DropItem(frag_target, targ);
88
89         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
90         {
91                 .entity weaponentity = weaponentities[slot];
92
93                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
94         }
95 }
96
97 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
98 {
99         entity mon = M_ARGV(0, entity);
100         entity olditem = M_ARGV(1, entity);
101         entity frag_attacker = M_ARGV(2, entity);
102
103         delete(olditem);
104
105         M_ARGV(1, entity) = NULL;
106
107         ok_DropItem(mon, frag_attacker);
108 }
109
110 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
111 {
112         return true;
113 }
114
115 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
116 {
117         if(game_stopped)
118                 return;
119
120         entity player = M_ARGV(0, entity);
121
122         if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
123                 return;
124
125         if(PHYS_INPUT_BUTTON_ATCK2(player) && time >= player.jump_interval)
126         if( !forbidWeaponUse(player)
127                 || (round_handler_IsActive() && !round_handler_IsRoundStarted()) )
128         {
129                 player.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor(player);
130                 makevectors(player.v_angle);
131
132                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
133                 {
134                         .entity weaponentity = weaponentities[slot];
135
136                         if(player.(weaponentity).m_weapon == WEP_Null && slot != 0)
137                                 continue;
138
139                         Weapon oldwep = player.(weaponentity).m_weapon;
140                         player.(weaponentity).m_weapon = WEP_BLASTER;
141                         W_Blaster_Attack(
142                                 player,
143                                 weaponentity,
144                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
145                                 WEP_CVAR_SEC(vaporizer, shotangle),
146                                 WEP_CVAR_SEC(vaporizer, damage),
147                                 WEP_CVAR_SEC(vaporizer, edgedamage),
148                                 WEP_CVAR_SEC(vaporizer, radius),
149                                 WEP_CVAR_SEC(vaporizer, force),
150                                 WEP_CVAR_SEC(vaporizer, speed),
151                                 WEP_CVAR_SEC(vaporizer, spread),
152                                 WEP_CVAR_SEC(vaporizer, delay),
153                                 WEP_CVAR_SEC(vaporizer, lifetime)
154                         );
155                         player.(weaponentity).m_weapon = oldwep;
156                 }
157         }
158
159         PHYS_INPUT_BUTTON_ATCK2(player) = false;
160 }
161
162 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
163 {
164         entity player = M_ARGV(0, entity);
165
166         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
167         {
168                 .entity weaponentity = weaponentities[slot];
169                 entity thiswep = player.(weaponentity);
170
171                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
172                 {
173                         Weapon newwep = player.ok_lastwep[slot];
174                         if(player.ok_lastwep[slot] == WEP_HMG)
175                                 newwep = WEP_MACHINEGUN;
176                         if(player.ok_lastwep[slot] == WEP_RPC)
177                                 newwep = WEP_VORTEX;
178                         thiswep.m_switchweapon = newwep;
179                         player.ok_lastwep[slot] = WEP_Null;
180                 }
181         }
182 }
183
184 void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
185 void self_spawnfunc_weapon_rpc(entity this) { spawnfunc_weapon_rpc(this); }
186
187 MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpawn)
188 {
189         entity ent = M_ARGV(0, entity);
190
191         if(autocvar_g_powerups)
192         if(autocvar_g_overkill_powerups_replace)
193         {
194                 if(ent.classname == "item_strength")
195                 {
196                         entity wep = new(weapon_hmg);
197                         setorigin(wep, ent.origin);
198                         setmodel(wep, MDL_OK_HMG);
199                         wep.ok_item = true;
200                         wep.noalign = ent.noalign;
201                         wep.cnt = ent.cnt;
202                         wep.team = ent.team;
203                         wep.respawntime = g_pickup_respawntime_superweapon;
204                         wep.pickup_anyway = true;
205                         wep.spawnfunc_checked = true;
206                         setthink(wep, self_spawnfunc_weapon_hmg);
207                         wep.nextthink = time + 0.1;
208                         return true;
209                 }
210                 else if(ent.classname == "item_invincible")
211                 {
212                         entity wep = new(weapon_rpc);
213                         setorigin(wep, ent.origin);
214                         setmodel(wep, MDL_OK_RPC);
215                         wep.ok_item = true;
216                         wep.noalign = ent.noalign;
217                         wep.cnt = ent.cnt;
218                         wep.team = ent.team;
219                         wep.respawntime = g_pickup_respawntime_superweapon;
220                         wep.pickup_anyway = true;
221                         wep.spawnfunc_checked = true;
222                         setthink(wep, self_spawnfunc_weapon_rpc);
223                         wep.nextthink = time + 0.1;
224                         return true;
225                 }
226         }
227 }
228
229 bool ok_HandleItemWaypoints(entity e)
230 {
231         if(!autocvar_g_overkill_itemwaypoints)
232                 return false; // don't handle it
233
234         switch(e.itemdef)
235         {
236                 case ITEM_HealthMega: return true;
237                 case ITEM_ArmorMedium: return true;
238                 case ITEM_ArmorBig: return true;
239                 case ITEM_ArmorMega: return true;
240         }
241
242         return false;
243 }
244
245 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
246 {
247         entity item = M_ARGV(0, entity);
248         return ok_HandleItemWaypoints(item);
249 }
250
251 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
252 {
253         entity item = M_ARGV(0, entity);
254         return ok_HandleItemWaypoints(item);
255 }
256
257 MUTATOR_HOOKFUNCTION(ok, FilterItem)
258 {
259         entity item = M_ARGV(0, entity);
260
261         if(item.ok_item)
262                 return false;
263
264         switch(item.itemdef)
265         {
266                 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
267                 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
268                 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
269                 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
270         }
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 }
307
308 void ok_Initialize()
309 {
310         precache_all_playermodels("models/ok_player/*.dpm");
311
312         WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
313         WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
314
315         WEP_SHOTGUN.mdl = "ok_shotgun";
316         WEP_MACHINEGUN.mdl = "ok_mg";
317         WEP_VORTEX.mdl = "ok_sniper";
318 }