1 #ifndef MUTATOR_BUFFS_H
2 #define MUTATOR_BUFFS_H
4 #include "../instagib/module.inc"
6 bool autocvar_g_buffs_effects;
7 float autocvar_g_buffs_waypoint_distance;
8 bool autocvar_g_buffs_randomize;
9 float autocvar_g_buffs_random_lifetime;
10 bool autocvar_g_buffs_random_location;
11 int autocvar_g_buffs_random_location_attempts;
12 int autocvar_g_buffs_spawn_count;
13 bool autocvar_g_buffs_replace_powerups;
14 float autocvar_g_buffs_cooldown_activate;
15 float autocvar_g_buffs_cooldown_respawn;
16 float autocvar_g_buffs_resistance_blockpercent;
17 float autocvar_g_buffs_medic_survive_chance;
18 float autocvar_g_buffs_medic_survive_health;
19 float autocvar_g_buffs_medic_rot;
20 float autocvar_g_buffs_medic_max;
21 float autocvar_g_buffs_medic_regen;
22 float autocvar_g_buffs_medic_heal_amount = 15;
23 float autocvar_g_buffs_medic_heal_delay = 1;
24 float autocvar_g_buffs_medic_heal_range = 400;
25 float autocvar_g_buffs_vengeance_damage_multiplier;
26 float autocvar_g_buffs_bash_force;
27 float autocvar_g_buffs_bash_force_self;
28 float autocvar_g_buffs_disability_slowtime;
29 float autocvar_g_buffs_disability_speed;
30 float autocvar_g_buffs_disability_rate;
31 float autocvar_g_buffs_disability_weaponspeed;
32 float autocvar_g_buffs_speed_speed;
33 float autocvar_g_buffs_speed_rate;
34 float autocvar_g_buffs_speed_weaponspeed;
35 float autocvar_g_buffs_speed_damage_take;
36 float autocvar_g_buffs_speed_regen;
37 float autocvar_g_buffs_vampire_damage_steal;
38 float autocvar_g_buffs_invisible_alpha;
39 float autocvar_g_buffs_jump_height;
40 float autocvar_g_buffs_inferno_burntime_factor;
41 float autocvar_g_buffs_inferno_burntime_min_time;
42 float autocvar_g_buffs_inferno_burntime_target_damage;
43 float autocvar_g_buffs_inferno_burntime_target_time;
44 float autocvar_g_buffs_inferno_damagemultiplier;
45 float autocvar_g_buffs_swapper_range;
46 float autocvar_g_buffs_magnet_range_item;
47 float autocvar_g_buffs_magnet_range_buff = 200;
48 float autocvar_g_buffs_luck_chance = 0.15;
49 float autocvar_g_buffs_luck_damagemultiplier = 3;
52 .float buff_ammo_prev_infitems;
53 .int buff_ammo_prev_clipload;
55 .float buff_invisible_prev_alpha;
57 .float buff_medic_healtime;
59 .float buff_disability_time;
60 .float buff_disability_effect_time;
61 // common buff variables
62 .float buff_effect_delay;
66 .float buff_activetime;
67 .float buff_activetime_updated;
68 .entity buff_waypoint;
69 .int oldbuffs; // for updating effects
70 .entity buff_model; // controls effects (TODO: make csqc)
72 const vector BUFF_MIN = ('-16 -16 -20');
73 const vector BUFF_MAX = ('16 16 20');
75 // client side options
76 .float cvar_cl_buffs_autoreplace;
81 #include <common/triggers/target/music.qh>
82 #include <common/gamemodes/all.qh>
84 .float buff_time = _STAT(BUFF_TIME);
85 void buffs_DelayedInit(entity this);
87 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
91 InitializeEntity(world, buffs_DelayedInit, INITPRIO_FINDTARGET);
95 bool buffs_BuffModel_Customize()
97 entity player, myowner;
100 player = WaypointSprite_getviewentity(other);
101 myowner = self.owner;
102 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
104 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
107 if(MUTATOR_CALLHOOK(BuffModel_Customize, self, player))
110 if(player == myowner || (IS_SPEC(other) && other.enemy == myowner))
112 // somewhat hide the model, but keep the glow
118 self.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
124 void buffs_BuffModel_Spawn(entity player)
126 player.buff_model = spawn();
127 setmodel(player.buff_model, MDL_BUFF);
128 setsize(player.buff_model, '0 0 -40', '0 0 40');
129 setattachment(player.buff_model, player, "");
130 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
131 player.buff_model.owner = player;
132 player.buff_model.scale = 0.7;
133 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
134 player.buff_model.light_lev = 200;
135 player.buff_model.customizeentityforclient = buffs_BuffModel_Customize;
138 vector buff_GlowColor(entity buff)
140 //if(buff.team) { return Team_ColorRGB(buff.team); }
144 void buff_Effect(entity player, string eff)
146 if(!autocvar_g_buffs_effects) { return; }
148 if(time >= self.buff_effect_delay)
150 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
151 self.buff_effect_delay = time + 0.05; // prevent spam
156 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
158 if(!this.owner.buff_active && !this.owner.buff_activetime)
163 return view.cvar_cl_buffs_autoreplace == false || view.buffs != this.owner.buffs;
166 return WaypointSprite_visible_for_player(this, player, view);
169 void buff_Waypoint_Spawn(entity e)
171 entity buff = buff_FirstFromFlags(e.buffs);
172 entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, world, e.team, e, buff_waypoint, true, RADARICON_Buff);
173 wp.wp_extra = buff.m_id;
174 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
175 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
178 void buff_SetCooldown(entity this, float cd)
182 if(!this.buff_waypoint)
183 buff_Waypoint_Spawn(this);
185 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
186 this.buff_activetime = cd;
187 this.buff_active = !cd;
190 void buff_Respawn(entity this)
192 if(gameover) { return; }
194 vector oldbufforigin = this.origin;
195 this.velocity = '0 0 200';
197 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
198 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
200 entity spot = SelectSpawnPoint(this, true);
201 setorigin(this, spot.origin);
202 this.velocity = ((randomvec() * 100) + '0 0 200');
203 this.angles = spot.angles;
206 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
208 setorigin(this, trace_endpos); // attempt to unstick
210 this.movetype = MOVETYPE_TOSS;
212 makevectors(this.angles);
213 this.angles = '0 0 0';
214 if(autocvar_g_buffs_random_lifetime > 0)
215 this.lifetime = time + autocvar_g_buffs_random_lifetime;
217 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
218 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
220 WaypointSprite_Ping(this.buff_waypoint);
222 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
227 if(gameover) { return; }
229 if(ITEM_TOUCH_NEEDKILL())
235 if((self.team && DIFF_TEAM(other, self))
236 || (STAT(FROZEN, other))
238 || (!self.buff_active)
245 if(MUTATOR_CALLHOOK(BuffTouch, self, other))
248 if(!IS_PLAYER(other))
249 return; // incase mutator changed other
253 if (other.cvar_cl_buffs_autoreplace && other.buffs != self.buffs)
255 int buffid = buff_FirstFromFlags(other.buffs).m_id;
256 //Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_DROP, other.buffs);
257 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ITEM_BUFF_LOST, other.netname, buffid);
260 //sound(other, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
262 else { return; } // do nothing
266 self.buff_active = false;
268 int buffid = buff_FirstFromFlags(self.buffs).m_id;
269 Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_GOT, buffid);
270 Send_Notification(NOTIF_ALL_EXCEPT, other, MSG_INFO, INFO_ITEM_BUFF, other.netname, buffid);
272 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
273 sound(other, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
274 other.buffs |= (self.buffs);
277 float buff_Available(entity buff)
279 if (buff == BUFF_Null)
281 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
283 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
285 return cvar(strcat("g_buffs_", buff.m_name));
290 void buff_NewType(entity ent, float cb)
292 RandomSelection_Init();
293 FOREACH(Buffs, buff_Available(it), LAMBDA(
294 it.buff_seencount += 1;
295 // if it's already been chosen, give it a lower priority
296 RandomSelection_Add(world, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
298 ent.buffs = RandomSelection_chosen_float;
303 if(this.buffs != this.oldbuffs)
305 entity buff = buff_FirstFromFlags(this.buffs);
306 this.color = buff.m_color;
307 this.glowmod = buff_GlowColor(buff);
308 this.skin = buff.m_skin;
310 setmodel(this, MDL_BUFF);
312 if(this.buff_waypoint)
314 //WaypointSprite_Disown(this.buff_waypoint, 1);
315 WaypointSprite_Kill(this.buff_waypoint);
316 buff_Waypoint_Spawn(this);
317 if(this.buff_activetime)
318 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
321 this.oldbuffs = this.buffs;
325 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
326 if(!this.buff_activetime_updated)
328 buff_SetCooldown(this, this.buff_activetime);
329 this.buff_activetime_updated = true;
332 if(!this.buff_active && !this.buff_activetime)
333 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || !(this.owner.buffs & this.buffs))
335 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
337 if(autocvar_g_buffs_randomize)
338 buff_NewType(this, this.buffs);
340 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
344 if(this.buff_activetime)
346 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
348 this.buff_activetime = max(0, this.buff_activetime - frametime);
350 if(!this.buff_activetime)
352 this.buff_active = true;
353 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
354 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
360 if(this.team && !this.buff_waypoint)
361 buff_Waypoint_Spawn(this);
364 if(time >= this.lifetime)
368 this.nextthink = time;
369 //this.angles_y = time * 110.1;
372 void buff_Waypoint_Reset(entity this)
374 WaypointSprite_Kill(this.buff_waypoint);
376 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
379 void buff_Reset(entity this)
381 if(autocvar_g_buffs_randomize)
382 buff_NewType(this, this.buffs);
384 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
385 buff_Waypoint_Reset(this);
386 this.buff_activetime_updated = false;
388 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
392 float buff_Customize()
394 entity player = WaypointSprite_getviewentity(other);
395 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
398 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
404 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
405 this.light_lev = 220 + 36 * sin(time);
406 this.pflags = PFLAGS_FULLDYNAMIC;
411 void buff_Init(entity this)
413 if(!cvar("g_buffs")) { remove(this); return; }
415 if(!teamplay && this.team) { this.team = 0; }
417 entity buff = buff_FirstFromFlags(this.buffs);
419 if(!this.buffs || buff_Available(buff))
420 buff_NewType(this, 0);
422 this.classname = "item_buff";
423 this.solid = SOLID_TRIGGER;
424 this.flags = FL_ITEM;
425 setthink(this, buff_Think);
426 settouch(this, buff_Touch);
427 this.reset = buff_Reset;
428 this.nextthink = time + 0.1;
430 this.movetype = MOVETYPE_TOSS;
432 this.skin = buff.m_skin;
433 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
434 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
435 this.customizeentityforclient = buff_Customize;
436 //this.gravity = 100;
437 this.color = buff.m_color;
438 this.glowmod = buff_GlowColor(this);
439 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + game_starttime);
440 this.buff_active = !this.buff_activetime;
441 this.pflags = PFLAGS_FULLDYNAMIC;
443 if(this.spawnflags & 1)
447 this.movetype = MOVETYPE_NONE; // reset by random location
449 setmodel(this, MDL_BUFF);
450 setsize(this, BUFF_MIN, BUFF_MAX);
452 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
456 void buff_Init_Compat(entity ent, entity replacement)
458 if (ent.spawnflags & 2)
459 ent.team = NUM_TEAM_1;
460 else if (ent.spawnflags & 4)
461 ent.team = NUM_TEAM_2;
463 ent.buffs = replacement.m_itemid;
468 void buff_SpawnReplacement(entity ent, entity old)
470 setorigin(ent, old.origin);
471 ent.angles = old.angles;
472 ent.noalign = (old.noalign || (old.spawnflags & 1));
477 void buff_Vengeance_DelayedDamage()
480 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0');
486 // note: only really useful in teamplay
487 void buff_Medic_Heal(entity this)
489 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
491 if(SAME_TEAM(it, this))
492 if(it.health < autocvar_g_balance_health_regenstable)
494 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
495 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
500 float buff_Inferno_CalculateTime(float x, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
502 return offset_y + (intersect_y - offset_y) * logn(((x - offset_x) * ((base - 1) / intersect_x)) + 1, base);
506 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
508 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
510 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
512 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
520 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
522 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
524 if(frag_target.buffs & BUFF_SPEED.m_itemid)
525 if(frag_target != frag_attacker)
526 frag_damage *= autocvar_g_buffs_speed_damage_take;
528 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
529 if((frag_target.health - frag_damage) <= 0)
530 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
532 if(random() <= autocvar_g_buffs_medic_survive_chance)
533 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
535 if(frag_target.buffs & BUFF_JUMP.m_itemid)
536 if(frag_deathtype == DEATH_FALL.m_id)
539 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
541 if(frag_attacker != frag_target)
542 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
544 entity dmgent = spawn();
546 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
547 dmgent.enemy = frag_attacker;
548 dmgent.owner = frag_target;
549 setthink(dmgent, buff_Vengeance_DelayedDamage);
550 dmgent.nextthink = time + 0.1;
553 if(frag_target.buffs & BUFF_BASH.m_itemid)
554 if(frag_attacker != frag_target)
555 frag_force = '0 0 0';
557 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
559 if(frag_attacker == frag_target)
560 frag_force *= autocvar_g_buffs_bash_force_self;
562 frag_force *= autocvar_g_buffs_bash_force;
564 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
565 if(frag_target != frag_attacker)
566 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
568 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
570 if(frag_deathtype == DEATH_FIRE.m_id)
572 if(frag_deathtype == DEATH_LAVA.m_id)
573 frag_damage *= 0.5; // TODO: cvarize?
576 if(frag_attacker.buffs & BUFF_LUCK.m_itemid)
577 if(frag_attacker != frag_target)
578 if(autocvar_g_buffs_luck_damagemultiplier > 0)
579 if(random() <= autocvar_g_buffs_luck_chance)
580 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
582 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
583 if(frag_target != frag_attacker) {
584 float btime = buff_Inferno_CalculateTime(
587 autocvar_g_buffs_inferno_burntime_min_time,
588 autocvar_g_buffs_inferno_burntime_target_damage,
589 autocvar_g_buffs_inferno_burntime_target_time,
590 autocvar_g_buffs_inferno_burntime_factor
592 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
595 // this... is ridiculous (TODO: fix!)
596 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
597 if(!frag_target.vehicle)
598 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
599 if(!IS_DEAD(frag_target))
600 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
601 if(frag_attacker != frag_target)
602 if(!STAT(FROZEN, frag_target))
603 if(frag_target.takedamage)
604 if(DIFF_TEAM(frag_attacker, frag_target))
606 frag_attacker.health = bound(0, frag_attacker.health + bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, frag_target.health), g_pickup_healthsmall_max);
607 if(frag_target.armorvalue)
608 frag_attacker.armorvalue = bound(0, frag_attacker.armorvalue + bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, frag_target.armorvalue), g_pickup_armorsmall_max);
614 MUTATOR_HOOKFUNCTION(buffs,PlayerSpawn)
617 // reset timers here to prevent them continuing after re-spawn
618 self.buff_disability_time = 0;
619 self.buff_disability_effect_time = 0;
623 .float stat_sv_maxspeed;
624 .float stat_sv_airspeedlimit_nonqw;
625 .float stat_sv_jumpvelocity;
627 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
629 if(self.buffs & BUFF_SPEED.m_itemid)
631 self.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
632 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
635 if(time < self.buff_disability_time)
637 self.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
638 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
641 if(self.buffs & BUFF_JUMP.m_itemid)
643 // automatically reset, no need to worry
644 self.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
650 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
652 if(self.buffs & BUFF_JUMP.m_itemid)
653 player_jumpheight = autocvar_g_buffs_jump_height;
658 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
660 if(time < self.buff_disability_time)
662 monster_speed_walk *= autocvar_g_buffs_disability_speed;
663 monster_speed_run *= autocvar_g_buffs_disability_speed;
669 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
671 if(frag_target.buffs)
673 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
674 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
675 frag_target.buffs = 0;
677 if(frag_target.buff_model)
679 remove(frag_target.buff_model);
680 frag_target.buff_model = world;
686 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
688 if(MUTATOR_RETURNVALUE || gameover) { return false; }
691 int buffid = buff_FirstFromFlags(self.buffs).m_id;
692 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid);
693 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
696 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
702 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
704 if(MUTATOR_RETURNVALUE || gameover) { return false; }
706 if(self.buffs & BUFF_SWAPPER.m_itemid)
708 float best_distance = autocvar_g_buffs_swapper_range;
709 entity closest = world;
710 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
711 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
712 if(DIFF_TEAM(it, self))
714 float test = vlen2(self.origin - it.origin);
715 if(test <= best_distance * best_distance)
717 best_distance = sqrt(test);
725 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
727 my_org = self.origin;
728 my_vel = self.velocity;
729 my_ang = self.angles;
730 their_org = closest.origin;
731 their_vel = closest.velocity;
732 their_ang = closest.angles;
734 Drop_Special_Items(closest);
736 MUTATOR_CALLHOOK(PortalTeleport, self); // initiate flag dropper
738 setorigin(self, their_org);
739 setorigin(closest, my_org);
741 closest.velocity = my_vel;
742 closest.angles = my_ang;
743 closest.fixangle = true;
744 closest.oldorigin = my_org;
745 closest.oldvelocity = my_vel;
746 self.velocity = their_vel;
747 self.angles = their_ang;
748 self.fixangle = true;
749 self.oldorigin = their_org;
750 self.oldvelocity = their_vel;
752 // set pusher so self gets the kill if they fall into void
753 closest.pusher = self;
754 closest.pushltime = time + autocvar_g_maxpushtime;
755 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
757 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
758 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
760 sound(self, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
761 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
763 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
771 bool buffs_RemovePlayer(entity player)
773 if(player.buff_model)
775 remove(player.buff_model);
776 player.buff_model = world;
779 // also reset timers here to prevent them continuing after spectating
780 player.buff_disability_time = 0;
781 player.buff_disability_effect_time = 0;
785 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { SELFPARAM(); return buffs_RemovePlayer(self); }
786 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { SELFPARAM(); return buffs_RemovePlayer(self); }
788 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
790 entity e = WaypointSprite_getviewentity(other);
792 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
793 // but only apply this to real players, not to spectators
794 if((self.owner.flags & FL_CLIENT) && (self.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == other))
795 if(DIFF_TEAM(self.owner, e))
801 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
803 if(autocvar_g_buffs_replace_powerups)
804 switch(self.classname)
806 case "item_strength":
807 case "item_invincible":
810 buff_SpawnReplacement(e, self);
817 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
819 if(self.buffs & BUFF_SPEED.m_itemid)
820 weapon_rate *= autocvar_g_buffs_speed_rate;
822 if(time < self.buff_disability_time)
823 weapon_rate *= autocvar_g_buffs_disability_rate;
828 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
830 if(self.buffs & BUFF_SPEED.m_itemid)
831 ret_float *= autocvar_g_buffs_speed_weaponspeed;
833 if(time < self.buff_disability_time)
834 ret_float *= autocvar_g_buffs_disability_weaponspeed;
839 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
841 if(gameover || IS_DEAD(self)) { return false; }
843 if(time < self.buff_disability_time)
844 if(time >= self.buff_disability_effect_time)
846 Send_Effect(EFFECT_SMOKING, self.origin + ((self.mins + self.maxs) * 0.5), '0 0 0', 1);
847 self.buff_disability_effect_time = time + 0.5;
850 // handle buff lost status
851 // 1: notify everyone else
852 // 2: notify carrier as well
856 if(time >= self.buff_time)
859 if(STAT(FROZEN, self)) { buff_lost = 1; }
865 int buffid = buff_FirstFromFlags(self.buffs).m_id;
866 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
869 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
870 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
876 if(self.buffs & BUFF_MAGNET.m_itemid)
879 FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
882 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
884 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
886 if(boxesoverlap(self.absmin - pickup_size, self.absmax + pickup_size, it.absmin, it.absmax))
890 entity oldother = other;
892 WITHSELF(it, gettouch(it)());
899 if(self.buffs & BUFF_AMMO.m_itemid)
901 self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
903 if((self.buffs & BUFF_INVISIBLE.m_itemid) && (self.oldbuffs & BUFF_INVISIBLE.m_itemid))
904 if(self.alpha != autocvar_g_buffs_invisible_alpha)
905 self.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
907 if(self.buffs & BUFF_MEDIC.m_itemid)
908 if(time >= self.buff_medic_healtime)
910 buff_Medic_Heal(self);
911 self.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
914 #define BUFF_ONADD(b) if ( (self.buffs & (b).m_itemid) && !(self.oldbuffs & (b).m_itemid))
915 #define BUFF_ONREM(b) if (!(self.buffs & (b).m_itemid) && (self.oldbuffs & (b).m_itemid))
917 if(self.buffs != self.oldbuffs)
919 entity buff = buff_FirstFromFlags(self.buffs);
920 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
921 self.buff_time = (bufftime) ? time + bufftime : 0;
923 BUFF_ONADD(BUFF_AMMO)
925 self.buff_ammo_prev_infitems = (self.items & IT_UNLIMITED_WEAPON_AMMO);
926 self.items |= IT_UNLIMITED_WEAPON_AMMO;
929 self.buff_ammo_prev_clipload = self.clip_load;
930 self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
933 BUFF_ONREM(BUFF_AMMO)
935 if(self.buff_ammo_prev_infitems)
936 self.items |= IT_UNLIMITED_WEAPON_AMMO;
938 self.items &= ~IT_UNLIMITED_WEAPON_AMMO;
940 if(self.buff_ammo_prev_clipload)
941 self.clip_load = self.buff_ammo_prev_clipload;
944 BUFF_ONADD(BUFF_INVISIBLE)
946 if(time < self.strength_finished && g_instagib)
947 self.alpha = autocvar_g_instagib_invis_alpha;
949 self.alpha = self.buff_invisible_prev_alpha;
950 self.alpha = autocvar_g_buffs_invisible_alpha;
953 BUFF_ONREM(BUFF_INVISIBLE)
954 self.alpha = self.buff_invisible_prev_alpha;
956 self.oldbuffs = self.buffs;
960 buffs_BuffModel_Spawn(self);
962 self.buff_model.color = buff.m_color;
963 self.buff_model.glowmod = buff_GlowColor(self.buff_model);
964 self.buff_model.skin = buff.m_skin;
966 self.effects |= EF_NOSHADOW;
970 remove(self.buff_model);
971 self.buff_model = world;
973 self.effects &= ~(EF_NOSHADOW);
979 self.buff_model.effects = self.effects;
980 self.buff_model.effects |= EF_LOWPRECISION;
981 self.buff_model.effects = self.buff_model.effects & EFMASK_CHEAP; // eat performance
983 self.buff_model.alpha = self.alpha;
991 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
993 self.buffs = other.buffs;
997 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
999 vh_vehicle.buffs = vh_player.buffs;
1000 vh_player.buffs = 0;
1001 vh_vehicle.buff_time = max(0, vh_player.buff_time - time);
1002 vh_player.buff_time = 0;
1006 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
1008 vh_player.buffs = vh_player.oldbuffs = vh_vehicle.buffs;
1009 vh_vehicle.buffs = 0;
1010 vh_player.buff_time = time + vh_vehicle.buff_time;
1011 vh_vehicle.buff_time = 0;
1015 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
1017 if(self.buffs & BUFF_MEDIC.m_itemid)
1019 regen_mod_rot = autocvar_g_buffs_medic_rot;
1020 regen_mod_limit = regen_mod_max = autocvar_g_buffs_medic_max;
1021 regen_mod_regen = autocvar_g_buffs_medic_regen;
1024 if(self.buffs & BUFF_SPEED.m_itemid)
1025 regen_mod_regen = autocvar_g_buffs_speed_regen;
1030 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1032 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1034 ret_string = strcat(ret_string, ":Buffs");
1038 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1040 ret_string = strcat(ret_string, ", Buffs");
1044 void buffs_DelayedInit(entity this)
1046 if(autocvar_g_buffs_spawn_count > 0)
1047 if(find(world, classname, "item_buff") == world)
1050 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1053 e.spawnflags |= 64; // always randomize
1054 e.velocity = randomvec() * 250; // this gets reset anyway if random location works