]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
Merge branch 'master' into Lyberta/TeamplayFixes_
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / instagib / sv_instagib.qc
1 #include "sv_instagib.qh"
2
3 bool autocvar_g_instagib_damagedbycontents = true;
4 bool autocvar_g_instagib_blaster_keepdamage = false;
5 bool autocvar_g_instagib_blaster_keepforce = false;
6 bool autocvar_g_instagib_mirrordamage;
7 bool autocvar_g_instagib_friendlypush = true;
8 //int autocvar_g_instagib_ammo_drop;
9 bool autocvar_g_instagib_ammo_convert_cells;
10 bool autocvar_g_instagib_ammo_convert_rockets;
11 bool autocvar_g_instagib_ammo_convert_shells;
12 bool autocvar_g_instagib_ammo_convert_bullets;
13 int autocvar_g_instagib_extralives;
14 float autocvar_g_instagib_speed_highspeed;
15
16 #include <server/client.qh>
17
18 #include <common/items/_mod.qh>
19
20 REGISTER_MUTATOR(mutator_instagib, autocvar_g_instagib && !g_nexball);
21
22 spawnfunc(item_minst_cells)
23 {
24         if (!g_instagib) { delete(this); return; }
25         StartItem(this, ITEM_VaporizerCells);
26 }
27
28 void instagib_invisibility(entity this)
29 {
30         this.strength_finished = autocvar_g_balance_powerup_strength_time;
31         StartItem(this, ITEM_Invisibility);
32 }
33
34 void instagib_extralife(entity this)
35 {
36         StartItem(this, ITEM_ExtraLife);
37 }
38
39 void instagib_speed(entity this)
40 {
41         this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
42         StartItem(this, ITEM_Speed);
43 }
44
45 .float instagib_nextthink;
46 .float instagib_needammo;
47 void instagib_stop_countdown(entity e)
48 {
49         if (!e.instagib_needammo)
50                 return;
51         Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
52         e.instagib_needammo = false;
53 }
54 void instagib_ammocheck(entity this)
55 {
56         if(time < this.instagib_nextthink)
57                 return;
58         if(!IS_PLAYER(this))
59                 return; // not a player
60
61         if(IS_DEAD(this) || game_stopped)
62                 instagib_stop_countdown(this);
63         else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
64                 instagib_stop_countdown(this);
65         else if(autocvar_g_rm && autocvar_g_rm_laser)
66         {
67                 if(!this.instagib_needammo)
68                 {
69                         Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
70                         this.instagib_needammo = true;
71                 }
72         }
73         else
74         {
75                 float hp = GetResourceAmount(this, RESOURCE_HEALTH);
76                 this.instagib_needammo = true;
77                 if (hp <= 5)
78                 {
79                         Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
80                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
81                 }
82                 else if (hp <= 10)
83                 {
84                         Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
85                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
86                 }
87                 else if (hp <= 20)
88                 {
89                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
90                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
91                 }
92                 else if (hp <= 30)
93                 {
94                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
95                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
96                 }
97                 else if (hp <= 40)
98                 {
99                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
100                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
101                 }
102                 else if (hp <= 50)
103                 {
104                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
105                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
106                 }
107                 else if (hp <= 60)
108                 {
109                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
110                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
111                 }
112                 else if (hp <= 70)
113                 {
114                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
115                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
116                 }
117                 else if (hp <= 80)
118                 {
119                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
120                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
121                 }
122                 else if (hp <= 90)
123                 {
124                         Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
125                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
126                         Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
127                 }
128                 else
129                 {
130                         Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
131                         Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
132                 }
133         }
134         this.instagib_nextthink = time + 1;
135 }
136
137 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
138 {
139         FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
140 }
141
142 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
143 {
144         entity item = M_ARGV(1, entity);
145
146         item.monster_loot = ITEM_VaporizerCells;
147 }
148
149 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
150 {
151         entity mon = M_ARGV(0, entity);
152
153         // always refill ammo
154         if(mon.monsterid == MON_MAGE.monsterid)
155                 mon.skin = 1;
156 }
157
158 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
159 {
160         entity targ = M_ARGV(1, entity);
161
162         if (targ.items & ITEM_Invisibility.m_itemid)
163                 return true;
164 }
165
166 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
167 {
168         entity player = M_ARGV(0, entity);
169
170         instagib_stop_countdown(player);
171 }
172
173 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
174 {
175         entity player = M_ARGV(0, entity);
176
177         player.effects |= EF_FULLBRIGHT;
178 }
179
180 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
181 {
182         entity player = M_ARGV(0, entity);
183
184         instagib_ammocheck(player);
185 }
186
187 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
188 {
189         // no regeneration in instagib
190         return true;
191 }
192
193 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
194 {
195         entity player = M_ARGV(0, entity);
196
197         if (!(player.effects & EF_FULLBRIGHT))
198                 player.effects |= EF_FULLBRIGHT;
199
200         if (player.items & ITEM_Invisibility.m_itemid)
201         {
202                 play_countdown(player, player.strength_finished, SND_POWEROFF);
203                 if (time > player.strength_finished)
204                 {
205                         player.alpha = default_player_alpha;
206                         player.exteriorweaponentity.alpha = default_weapon_alpha;
207                         player.items &= ~ITEM_Invisibility.m_itemid;
208                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
209                 }
210         }
211         else
212         {
213                 if (time < player.strength_finished)
214                 {
215                         player.alpha = autocvar_g_instagib_invis_alpha;
216                         player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
217                         player.items |= ITEM_Invisibility.m_itemid;
218                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
219                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
220                 }
221         }
222
223         if (player.items & ITEM_Speed.m_itemid)
224         {
225                 play_countdown(player, player.invincible_finished, SND_POWEROFF);
226                 if (time > player.invincible_finished)
227                 {
228                         player.items &= ~ITEM_Speed.m_itemid;
229                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
230                 }
231         }
232         else
233         {
234                 if (time < player.invincible_finished)
235                 {
236                         player.items |= ITEM_Speed.m_itemid;
237                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
238                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
239                 }
240         }
241 }
242
243 .float stat_sv_maxspeed;
244
245 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
246 {
247         entity player = M_ARGV(0, entity);
248
249         if(player.items & ITEM_Speed.m_itemid)
250                 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
251 }
252
253 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
254 {
255         M_ARGV(4, float) = M_ARGV(7, float); // take = damage
256         M_ARGV(5, float) = 0; // save
257 }
258
259 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
260 {
261         // weapon dropping on death handled by FilterItem
262         return true;
263 }
264
265 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
266 {
267         entity frag_attacker = M_ARGV(1, entity);
268         entity frag_target = M_ARGV(2, entity);
269         float frag_deathtype = M_ARGV(3, float);
270         float frag_damage = M_ARGV(4, float);
271         float frag_mirrordamage = M_ARGV(5, float);
272         vector frag_force = M_ARGV(6, vector);
273
274         if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
275                 frag_damage = 0;
276
277         if(IS_PLAYER(frag_target))
278         {
279                 if(frag_deathtype == DEATH_FALL.m_id)
280                         frag_damage = 0; // never count fall damage
281
282                 if(!autocvar_g_instagib_damagedbycontents)
283                 switch(DEATH_ENT(frag_deathtype))
284                 {
285                         case DEATH_DROWN:
286                         case DEATH_SLIME:
287                         case DEATH_LAVA:
288                                 frag_damage = 0;
289                                 break;
290                 }
291
292                 if(IS_PLAYER(frag_attacker))
293                 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
294                 {
295                         if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
296                                 frag_force = '0 0 0';
297
298                         float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
299                         if(armor)
300                         {
301                                 armor -= 1;
302                                 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
303                                 frag_damage = 0;
304                                 frag_target.damage_dealt += 1;
305                                 frag_attacker.damage_dealt += 1;
306                                 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
307                         }
308                 }
309
310                 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
311                 {
312                         if(frag_deathtype & HITTYPE_SECONDARY)
313                         {
314                                 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
315                                 {
316                                         frag_damage = 0;
317                                         if(!autocvar_g_instagib_mirrordamage)
318                                                 frag_mirrordamage = 0; // never do mirror damage on enemies
319                                 }
320
321                                 if(frag_target != frag_attacker)
322                                 {
323                                         if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
324                                         if(!autocvar_g_instagib_blaster_keepforce)
325                                                 frag_force = '0 0 0';
326                                 }
327                         }
328                 }
329         }
330
331         if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
332         if(IS_PLAYER(frag_attacker))
333         if(frag_mirrordamage > 0)
334         {
335                 // just lose extra LIVES, don't kill the player for mirror damage
336                 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
337                 if(armor > 0)
338                 {
339                         armor -= 1;
340                         SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
341                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
342                         frag_attacker.damage_dealt += frag_mirrordamage;
343                 }
344                 frag_mirrordamage = 0;
345         }
346
347         if(frag_target.alpha && frag_target.alpha < 1)
348         if(IS_PLAYER(frag_target))
349                 yoda = 1;
350
351         M_ARGV(4, float) = frag_damage;
352         M_ARGV(5, float) = frag_mirrordamage;
353         M_ARGV(6, vector) = frag_force;
354 }
355
356 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
357 {
358         start_health       = warmup_start_health       = 100;
359         start_armorvalue   = warmup_start_armorvalue   = 0;
360
361         start_ammo_shells  = warmup_start_ammo_shells  = 0;
362         start_ammo_nails   = warmup_start_ammo_nails   = 0;
363         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_instagib_ammo_start");
364         start_ammo_plasma  = warmup_start_ammo_plasma  = 0;
365         start_ammo_rockets = warmup_start_ammo_rockets = 0;
366         //start_ammo_fuel    = warmup_start_ammo_fuel    = 0;
367
368         start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
369         start_items |= IT_UNLIMITED_SUPERWEAPONS;
370 }
371
372 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
373 {
374         // turn weapon arena off
375         M_ARGV(0, string) = "off";
376 }
377
378 void replace_with_insta_cells(entity item)
379 {
380         entity e = spawn();
381         setorigin(e, item.origin);
382         e.noalign = item.noalign;
383         e.cnt = item.cnt;
384         e.team = item.team;
385         e.spawnfunc_checked = true;
386         spawnfunc_item_minst_cells(e);
387 }
388
389 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
390 {
391         entity item = M_ARGV(0, entity);
392
393         if(item.classname == "item_cells")
394         {
395                 if(autocvar_g_instagib_ammo_convert_cells)
396                 {
397                         replace_with_insta_cells(item);
398                 }
399                 return true;
400         }
401         else if(item.classname == "item_rockets")
402         {
403                 if(autocvar_g_instagib_ammo_convert_rockets)
404                 {
405                         replace_with_insta_cells(item);
406                 }
407                 return true;
408         }
409         else if(item.classname == "item_shells")
410         {
411                 if(autocvar_g_instagib_ammo_convert_shells)
412                 {
413                         replace_with_insta_cells(item);
414                 }
415                 return true;
416         }
417         else if(item.classname == "item_bullets")
418         {
419                 if(autocvar_g_instagib_ammo_convert_bullets)
420                 {
421                         replace_with_insta_cells(item);
422                 }
423                 return true;
424         }
425
426         if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon")
427         {
428                 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
429                 return false;
430         }
431
432         if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
433         {
434                 replace_with_insta_cells(item);
435                 return true;
436         }
437
438         if(item.flags & FL_POWERUP)
439                 return false;
440
441         float cells = GetResourceAmount(item, RESOURCE_CELLS);
442         if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells")
443                 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
444
445         if(cells && !item.weapon)
446                 return false;
447
448         return true;
449 }
450
451 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
452 {
453         entity wp = M_ARGV(0, entity);
454         entity player = M_ARGV(1, entity);
455
456         entity e = WaypointSprite_getviewentity(player);
457
458         // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
459         // but only apply this to real players, not to spectators
460         if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
461         if(DIFF_TEAM(wp.owner, e))
462                 return true;
463 }
464
465 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
466 {
467         float frag_deathtype = M_ARGV(3, float);
468
469         if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
470                 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
471 }
472
473 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
474 {
475         entity item = M_ARGV(0, entity);
476         entity toucher = M_ARGV(1, entity);
477
478         if(GetResourceAmount(item, RESOURCE_CELLS))
479         {
480                 // play some cool sounds ;)
481                 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
482                 if (IS_CLIENT(toucher))
483                 {
484                         if(hp <= 5)
485                                 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
486                         else if(hp < 50)
487                                 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
488                 }
489
490                 if(hp < 100)
491                         SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
492
493                 return MUT_ITEMTOUCH_CONTINUE;
494         }
495
496         if(item.itemdef == ITEM_ExtraLife)
497         {
498                 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
499                 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
500                 return MUT_ITEMTOUCH_PICKUP;
501         }
502
503         return MUT_ITEMTOUCH_CONTINUE;
504 }
505
506 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
507 {
508         if (!autocvar_g_powerups) { return; }
509         entity ent = M_ARGV(0, entity);
510         // Can't use .itemdef here
511         if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
512                 return;
513
514         entity e = spawn();
515
516         float r = random();
517         if (r < 0.3)
518                 setthink(e, instagib_invisibility);
519         else if (r < 0.6)
520                 setthink(e, instagib_extralife);
521         else
522                 setthink(e, instagib_speed);
523
524         e.nextthink = time + 0.1;
525         e.spawnflags = ent.spawnflags;
526         e.noalign = ent.noalign;
527         setorigin(e, ent.origin);
528
529         return true;
530 }
531
532 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
533 {
534         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
535 }
536
537 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
538 {
539         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
540 }
541
542 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
543 {
544         M_ARGV(0, string) = "InstaGib";
545         return true;
546 }