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