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