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