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