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