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