]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
Merge branch 'martin-t/warns' into 'master'
[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, ForbidRandomStartWeapons)
182 {
183         return true;
184 }
185
186 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
187 {
188         entity player = M_ARGV(0, entity);
189
190         player.effects |= EF_FULLBRIGHT;
191 }
192
193 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
194 {
195         entity player = M_ARGV(0, entity);
196
197         instagib_ammocheck(player);
198 }
199
200 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
201 {
202         // no regeneration in instagib
203         return true;
204 }
205
206 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
207 {
208         entity player = M_ARGV(0, entity);
209
210         if (!(player.effects & EF_FULLBRIGHT))
211                 player.effects |= EF_FULLBRIGHT;
212
213         if (player.items & ITEM_Invisibility.m_itemid)
214         {
215                 play_countdown(player, player.strength_finished, SND_POWEROFF);
216                 if (time > player.strength_finished)
217                 {
218                         player.alpha = default_player_alpha;
219                         player.exteriorweaponentity.alpha = default_weapon_alpha;
220                         player.items &= ~ITEM_Invisibility.m_itemid;
221                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
222                 }
223         }
224         else
225         {
226                 if (time < player.strength_finished)
227                 {
228                         player.alpha = autocvar_g_instagib_invis_alpha;
229                         player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
230                         player.items |= ITEM_Invisibility.m_itemid;
231                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
232                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
233                 }
234         }
235
236         if (player.items & ITEM_Speed.m_itemid)
237         {
238                 play_countdown(player, player.invincible_finished, SND_POWEROFF);
239                 if (time > player.invincible_finished)
240                 {
241                         player.items &= ~ITEM_Speed.m_itemid;
242                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
243                 }
244         }
245         else
246         {
247                 if (time < player.invincible_finished)
248                 {
249                         player.items |= ITEM_Speed.m_itemid;
250                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
251                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
252                 }
253         }
254 }
255
256 .float stat_sv_maxspeed;
257
258 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
259 {
260         entity player = M_ARGV(0, entity);
261
262         if(player.items & ITEM_Speed.m_itemid)
263                 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
264 }
265
266 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
267 {
268         M_ARGV(4, float) = M_ARGV(7, float); // take = damage
269         M_ARGV(5, float) = 0; // save
270 }
271
272 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
273 {
274         // weapon dropping on death handled by FilterItem
275         return true;
276 }
277
278 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
279 {
280         entity frag_attacker = M_ARGV(1, entity);
281         entity frag_target = M_ARGV(2, entity);
282         float frag_deathtype = M_ARGV(3, float);
283         float frag_damage = M_ARGV(4, float);
284         float frag_mirrordamage = M_ARGV(5, float);
285         vector frag_force = M_ARGV(6, vector);
286
287         if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
288                 frag_damage = 0;
289
290         if(IS_PLAYER(frag_target))
291         {
292                 if(frag_deathtype == DEATH_FALL.m_id)
293                         frag_damage = 0; // never count fall damage
294
295                 if(!autocvar_g_instagib_damagedbycontents)
296                 switch(DEATH_ENT(frag_deathtype))
297                 {
298                         case DEATH_DROWN:
299                         case DEATH_SLIME:
300                         case DEATH_LAVA:
301                                 frag_damage = 0;
302                                 break;
303                 }
304
305                 if(IS_PLAYER(frag_attacker))
306                 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
307                 {
308                         if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
309                                 frag_force = '0 0 0';
310
311                         float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
312                         if(armor)
313                         {
314                                 armor -= 1;
315                                 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
316                                 frag_damage = 0;
317                                 frag_target.damage_dealt += 1;
318                                 frag_attacker.damage_dealt += 1;
319                                 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
320                         }
321                 }
322
323                 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
324                 {
325                         if(frag_deathtype & HITTYPE_SECONDARY)
326                         {
327                                 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
328                                 {
329                                         frag_damage = 0;
330                                         if(!autocvar_g_instagib_mirrordamage)
331                                                 frag_mirrordamage = 0; // never do mirror damage on enemies
332                                 }
333
334                                 if(frag_target != frag_attacker)
335                                 {
336                                         if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
337                                         if(!autocvar_g_instagib_blaster_keepforce)
338                                                 frag_force = '0 0 0';
339                                 }
340                         }
341                 }
342         }
343
344         if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
345         if(IS_PLAYER(frag_attacker))
346         if(frag_mirrordamage > 0)
347         {
348                 // just lose extra LIVES, don't kill the player for mirror damage
349                 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
350                 if(armor > 0)
351                 {
352                         armor -= 1;
353                         SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
354                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
355                         frag_attacker.damage_dealt += frag_mirrordamage;
356                 }
357                 frag_mirrordamage = 0;
358         }
359
360         if(frag_target.alpha && frag_target.alpha < 1)
361         if(IS_PLAYER(frag_target))
362                 yoda = 1;
363
364         M_ARGV(4, float) = frag_damage;
365         M_ARGV(5, float) = frag_mirrordamage;
366         M_ARGV(6, vector) = frag_force;
367 }
368
369 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
370 {
371         start_health       = warmup_start_health       = 100;
372         start_armorvalue   = warmup_start_armorvalue   = 0;
373
374         start_ammo_shells  = warmup_start_ammo_shells  = 0;
375         start_ammo_nails   = warmup_start_ammo_nails   = 0;
376         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_instagib_ammo_start");
377         start_ammo_plasma  = warmup_start_ammo_plasma  = 0;
378         start_ammo_rockets = warmup_start_ammo_rockets = 0;
379         //start_ammo_fuel    = warmup_start_ammo_fuel    = 0;
380
381         start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
382         start_items |= IT_UNLIMITED_SUPERWEAPONS;
383 }
384
385 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
386 {
387         // turn weapon arena off
388         M_ARGV(0, string) = "off";
389 }
390
391 void replace_with_insta_cells(entity item)
392 {
393         entity e = new(item_vaporizer_cells);
394         setorigin(e, item.origin);
395         e.noalign = Item_ShouldKeepPosition(item);
396         e.cnt = item.cnt;
397         e.team = item.team;
398         e.spawnfunc_checked = true;
399         spawnfunc_item_vaporizer_cells(e);
400 }
401
402 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
403 {
404         entity item = M_ARGV(0, entity);
405
406         if(item.classname == "item_cells")
407         {
408                 if(autocvar_g_instagib_ammo_convert_cells)
409                 {
410                         replace_with_insta_cells(item);
411                 }
412                 return true;
413         }
414         else if(item.classname == "item_rockets")
415         {
416                 if(autocvar_g_instagib_ammo_convert_rockets)
417                 {
418                         replace_with_insta_cells(item);
419                 }
420                 return true;
421         }
422         else if(item.classname == "item_shells")
423         {
424                 if(autocvar_g_instagib_ammo_convert_shells)
425                 {
426                         replace_with_insta_cells(item);
427                 }
428                 return true;
429         }
430         else if(item.classname == "item_bullets")
431         {
432                 if(autocvar_g_instagib_ammo_convert_bullets)
433                 {
434                         replace_with_insta_cells(item);
435                 }
436                 return true;
437         }
438
439         if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
440         {
441                 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
442                 return false;
443         }
444
445         if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
446         {
447                 replace_with_insta_cells(item);
448                 return true;
449         }
450
451         if(item.flags & FL_POWERUP)
452                 return false;
453
454         float cells = GetResourceAmount(item, RESOURCE_CELLS);
455         if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
456                 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
457
458         if(cells && !item.weapon)
459                 return false;
460
461         return true;
462 }
463
464 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
465 {
466         entity wp = M_ARGV(0, entity);
467         entity player = M_ARGV(1, entity);
468
469         entity e = WaypointSprite_getviewentity(player);
470
471         // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
472         // but only apply this to real players, not to spectators
473         if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
474         if(DIFF_TEAM(wp.owner, e))
475                 return true;
476 }
477
478 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
479 {
480         float frag_deathtype = M_ARGV(3, float);
481
482         if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
483                 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
484 }
485
486 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
487 {
488         entity item = M_ARGV(0, entity);
489         entity toucher = M_ARGV(1, entity);
490
491         if(GetResourceAmount(item, RESOURCE_CELLS))
492         {
493                 // play some cool sounds ;)
494                 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
495                 if (IS_CLIENT(toucher))
496                 {
497                         if(hp <= 5)
498                                 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
499                         else if(hp < 50)
500                                 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
501                 }
502
503                 if(hp < 100)
504                         SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
505
506                 return MUT_ITEMTOUCH_CONTINUE;
507         }
508
509         if(item.itemdef == ITEM_ExtraLife)
510         {
511                 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
512                 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
513                 return MUT_ITEMTOUCH_PICKUP;
514         }
515
516         return MUT_ITEMTOUCH_CONTINUE;
517 }
518
519 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
520 {
521         if (!autocvar_g_powerups) { return; }
522         entity ent = M_ARGV(0, entity);
523         // Can't use .itemdef here
524         if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_health_mega"))
525                 return;
526
527         entity e = spawn();
528
529         float r = random();
530         if (r < 0.3)
531         {
532                 e.classname = "item_invisibility";
533                 setthink(e, instagib_invisibility);
534         }
535         else if (r < 0.6)
536         {
537                 e.classname = "item_extralife";
538                 setthink(e, instagib_extralife);
539         }
540         else
541         {
542                 e.classname = "item_speed";
543                 setthink(e, instagib_speed);
544         }
545
546         e.nextthink = time + 0.1;
547         e.spawnflags = ent.spawnflags;
548         e.noalign = ent.noalign;
549         setorigin(e, ent.origin);
550
551         return true;
552 }
553
554 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
555 {
556         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
557 }
558
559 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
560 {
561         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
562 }
563
564 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
565 {
566         M_ARGV(0, string) = "InstaGib";
567         return true;
568 }