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