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