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