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_flight_gravity;
40 float autocvar_g_buffs_jump_height;
41 float autocvar_g_buffs_inferno_burntime_factor;
42 float autocvar_g_buffs_inferno_burntime_min_time;
43 float autocvar_g_buffs_inferno_burntime_target_damage;
44 float autocvar_g_buffs_inferno_burntime_target_time;
45 float autocvar_g_buffs_inferno_damagemultiplier;
46 float autocvar_g_buffs_swapper_range;
47 float autocvar_g_buffs_magnet_range_item;
48 float autocvar_g_buffs_magnet_range_buff = 200;
51 .float buff_ammo_prev_infitems;
52 .int buff_ammo_prev_clipload;
54 .float buff_invisible_prev_alpha;
56 .float buff_flight_prev_gravity;
58 .float buff_medic_healtime;
60 .float buff_disability_time;
61 .float buff_disability_effect_time;
62 // common buff variables
63 .float buff_effect_delay;
67 .float buff_activetime;
68 .float buff_activetime_updated;
69 .entity buff_waypoint;
70 .int oldbuffs; // for updating effects
71 .entity buff_model; // controls effects (TODO: make csqc)
73 const vector BUFF_MIN = ('-16 -16 -20');
74 const vector BUFF_MAX = ('16 16 20');
76 // client side options
77 .float cvar_cl_buffs_autoreplace;
82 #include <common/triggers/target/music.qh>
83 #include <common/gamemodes/all.qh>
85 .float buff_time = _STAT(BUFF_TIME);
86 void buffs_DelayedInit();
88 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
92 InitializeEntity(world, buffs_DelayedInit, INITPRIO_FINDTARGET);
96 entity buff_FirstFromFlags(int _buffs)
100 FOREACH(Buffs, it.m_itemid & _buffs, LAMBDA(return it));
105 bool buffs_BuffModel_Customize()
107 entity player, myowner;
110 player = WaypointSprite_getviewentity(other);
111 myowner = self.owner;
112 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
114 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
117 if(MUTATOR_CALLHOOK(BuffModel_Customize, self, player))
120 if(player == myowner || (IS_SPEC(other) && other.enemy == myowner))
122 // somewhat hide the model, but keep the glow
128 self.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
134 void buffs_BuffModel_Spawn(entity player)
136 player.buff_model = spawn();
137 setmodel(player.buff_model, MDL_BUFF);
138 setsize(player.buff_model, '0 0 -40', '0 0 40');
139 setattachment(player.buff_model, player, "");
140 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
141 player.buff_model.owner = player;
142 player.buff_model.scale = 0.7;
143 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
144 player.buff_model.light_lev = 200;
145 player.buff_model.customizeentityforclient = buffs_BuffModel_Customize;
148 vector buff_GlowColor(entity buff)
150 //if(buff.team) { return Team_ColorRGB(buff.team); }
154 void buff_Effect(entity player, string eff)
156 if(!autocvar_g_buffs_effects) { return; }
158 if(time >= self.buff_effect_delay)
160 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
161 self.buff_effect_delay = time + 0.05; // prevent spam
166 float buff_Waypoint_visible_for_player(entity plr)
168 if(!self.owner.buff_active && !self.owner.buff_activetime)
173 return plr.cvar_cl_buffs_autoreplace == false || plr.buffs != self.owner.buffs;
176 return WaypointSprite_visible_for_player(plr);
179 void buff_Waypoint_Spawn(entity e)
181 entity buff = buff_FirstFromFlags(e.buffs);
182 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);
183 wp.wp_extra = buff.m_id;
184 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
185 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
188 void buff_SetCooldown(float cd)
192 if(!self.buff_waypoint)
193 buff_Waypoint_Spawn(self);
195 WaypointSprite_UpdateBuildFinished(self.buff_waypoint, time + cd);
196 self.buff_activetime = cd;
197 self.buff_active = !cd;
200 void buff_Respawn(entity this)
202 if(gameover) { return; }
204 vector oldbufforigin = this.origin;
205 this.velocity = '0 0 200';
207 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
208 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
210 entity spot = SelectSpawnPoint(true);
211 setorigin(this, spot.origin);
212 this.velocity = ((randomvec() * 100) + '0 0 200');
213 this.angles = spot.angles;
216 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
218 setorigin(this, trace_endpos); // attempt to unstick
220 this.movetype = MOVETYPE_TOSS;
222 makevectors(this.angles);
223 this.angles = '0 0 0';
224 if(autocvar_g_buffs_random_lifetime > 0)
225 this.lifetime = time + autocvar_g_buffs_random_lifetime;
227 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
228 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
230 WaypointSprite_Ping(this.buff_waypoint);
232 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
237 if(gameover) { return; }
239 if(ITEM_TOUCH_NEEDKILL())
245 if((self.team && DIFF_TEAM(other, self))
246 || (STAT(FROZEN, other))
248 || (!self.buff_active)
255 if(MUTATOR_CALLHOOK(BuffTouch, self, other))
258 if(!IS_PLAYER(other))
259 return; // incase mutator changed other
263 if (other.cvar_cl_buffs_autoreplace && other.buffs != self.buffs)
265 int buffid = buff_FirstFromFlags(other.buffs).m_id;
266 //Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_DROP, other.buffs);
267 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ITEM_BUFF_LOST, other.netname, buffid);
270 //sound(other, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
272 else { return; } // do nothing
276 self.buff_active = false;
278 int buffid = buff_FirstFromFlags(self.buffs).m_id;
279 Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_GOT, buffid);
280 Send_Notification(NOTIF_ALL_EXCEPT, other, MSG_INFO, INFO_ITEM_BUFF, other.netname, buffid);
282 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
283 sound(other, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
284 other.buffs |= (self.buffs);
287 float buff_Available(entity buff)
289 if (buff == BUFF_Null)
291 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
293 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
295 return cvar(strcat("g_buffs_", buff.m_name));
300 void buff_NewType(entity ent, float cb)
302 RandomSelection_Init();
303 FOREACH(Buffs, buff_Available(it), LAMBDA(
304 it.buff_seencount += 1;
305 // if it's already been chosen, give it a lower priority
306 RandomSelection_Add(world, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
308 ent.buffs = RandomSelection_chosen_float;
313 if(self.buffs != self.oldbuffs)
315 entity buff = buff_FirstFromFlags(self.buffs);
316 self.color = buff.m_color;
317 self.glowmod = buff_GlowColor(buff);
318 self.skin = buff.m_skin;
320 setmodel(self, MDL_BUFF);
322 if(self.buff_waypoint)
324 //WaypointSprite_Disown(self.buff_waypoint, 1);
325 WaypointSprite_Kill(self.buff_waypoint);
326 buff_Waypoint_Spawn(self);
327 if(self.buff_activetime)
328 WaypointSprite_UpdateBuildFinished(self.buff_waypoint, time + self.buff_activetime - frametime);
331 self.oldbuffs = self.buffs;
335 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
336 if(!self.buff_activetime_updated)
338 buff_SetCooldown(self.buff_activetime);
339 self.buff_activetime_updated = true;
342 if(!self.buff_active && !self.buff_activetime)
343 if(!self.owner || STAT(FROZEN, self.owner) || IS_DEAD(self.owner) || !self.owner.iscreature || !(self.owner.buffs & self.buffs))
345 buff_SetCooldown(autocvar_g_buffs_cooldown_respawn + frametime);
347 if(autocvar_g_buffs_randomize)
348 buff_NewType(self, self.buffs);
350 if(autocvar_g_buffs_random_location || (self.spawnflags & 64))
354 if(self.buff_activetime)
356 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
358 self.buff_activetime = max(0, self.buff_activetime - frametime);
360 if(!self.buff_activetime)
362 self.buff_active = true;
363 sound(self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
364 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
370 if(self.team && !self.buff_waypoint)
371 buff_Waypoint_Spawn(self);
374 if(time >= self.lifetime)
378 self.nextthink = time;
379 //self.angles_y = time * 110.1;
382 void buff_Waypoint_Reset()
384 WaypointSprite_Kill(self.buff_waypoint);
386 if(self.buff_activetime) { buff_Waypoint_Spawn(self); }
389 void buff_Reset(entity this)
391 if(autocvar_g_buffs_randomize)
392 buff_NewType(this, this.buffs);
394 buff_SetCooldown(autocvar_g_buffs_cooldown_activate);
395 buff_Waypoint_Reset();
396 this.buff_activetime_updated = false;
398 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
402 float buff_Customize()
404 entity player = WaypointSprite_getviewentity(other);
405 if(!self.buff_active || (self.team && DIFF_TEAM(player, self)))
408 if(self.effects & EF_FULLBRIGHT) { self.effects &= ~(EF_FULLBRIGHT); }
414 if(!(self.effects & EF_FULLBRIGHT)) { self.effects |= EF_FULLBRIGHT; }
415 self.light_lev = 220 + 36 * sin(time);
416 self.pflags = PFLAGS_FULLDYNAMIC;
421 void buff_Init(entity ent)
423 if(!cvar("g_buffs")) { remove(ent); return; }
425 if(!teamplay && ent.team) { ent.team = 0; }
427 entity buff = buff_FirstFromFlags(self.buffs);
430 if(!self.buffs || buff_Available(buff))
431 buff_NewType(self, 0);
433 self.classname = "item_buff";
434 self.solid = SOLID_TRIGGER;
435 self.flags = FL_ITEM;
436 self.think = buff_Think;
437 self.touch = buff_Touch;
438 self.reset = buff_Reset;
439 self.nextthink = time + 0.1;
441 self.movetype = MOVETYPE_TOSS;
443 self.skin = buff.m_skin;
444 self.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
445 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
446 self.customizeentityforclient = buff_Customize;
447 //self.gravity = 100;
448 self.color = buff.m_color;
449 self.glowmod = buff_GlowColor(self);
450 buff_SetCooldown(autocvar_g_buffs_cooldown_activate + game_starttime);
451 self.buff_active = !self.buff_activetime;
452 self.pflags = PFLAGS_FULLDYNAMIC;
454 if(self.spawnflags & 1)
458 self.movetype = MOVETYPE_NONE; // reset by random location
460 setmodel(self, MDL_BUFF);
461 setsize(self, BUFF_MIN, BUFF_MAX);
463 if(cvar("g_buffs_random_location") || (self.spawnflags & 64))
469 void buff_Init_Compat(entity ent, entity replacement)
471 if (ent.spawnflags & 2)
472 ent.team = NUM_TEAM_1;
473 else if (ent.spawnflags & 4)
474 ent.team = NUM_TEAM_2;
476 ent.buffs = replacement.m_itemid;
481 void buff_SpawnReplacement(entity ent, entity old)
483 setorigin(ent, old.origin);
484 ent.angles = old.angles;
485 ent.noalign = (old.noalign || (old.spawnflags & 1));
490 void buff_Vengeance_DelayedDamage()
493 Damage(self.enemy, self.owner, self.owner, self.dmg, DEATH_BUFF.m_id, self.enemy.origin, '0 0 0');
499 // note: only really useful in teamplay
500 void buff_Medic_Heal(entity this)
502 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
504 if(SAME_TEAM(it, this))
505 if(it.health < autocvar_g_balance_health_regenstable)
507 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
508 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
513 float buff_Inferno_CalculateTime(float x, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
515 return offset_y + (intersect_y - offset_y) * logn(((x - offset_x) * ((base - 1) / intersect_x)) + 1, base);
519 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
521 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
523 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
525 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
533 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
535 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
537 if(frag_target.buffs & BUFF_SPEED.m_itemid)
538 if(frag_target != frag_attacker)
539 frag_damage *= autocvar_g_buffs_speed_damage_take;
541 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
542 if((frag_target.health - frag_damage) <= 0)
543 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
545 if(random() <= autocvar_g_buffs_medic_survive_chance)
546 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
548 if(frag_target.buffs & BUFF_JUMP.m_itemid)
549 if(frag_deathtype == DEATH_FALL.m_id)
552 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
554 if(frag_attacker != frag_target)
555 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
557 entity dmgent = spawn();
559 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
560 dmgent.enemy = frag_attacker;
561 dmgent.owner = frag_target;
562 dmgent.think = buff_Vengeance_DelayedDamage;
563 dmgent.nextthink = time + 0.1;
566 if(frag_target.buffs & BUFF_BASH.m_itemid)
567 if(frag_attacker != frag_target)
568 frag_force = '0 0 0';
570 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
572 if(frag_attacker == frag_target)
573 frag_force *= autocvar_g_buffs_bash_force_self;
575 frag_force *= autocvar_g_buffs_bash_force;
577 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
578 if(frag_target != frag_attacker)
579 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
581 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
583 if(frag_deathtype == DEATH_FIRE.m_id)
585 if(frag_deathtype == DEATH_LAVA.m_id)
586 frag_damage *= 0.5; // TODO: cvarize?
589 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
590 if(frag_target != frag_attacker) {
591 float btime = buff_Inferno_CalculateTime(
594 autocvar_g_buffs_inferno_burntime_min_time,
595 autocvar_g_buffs_inferno_burntime_target_damage,
596 autocvar_g_buffs_inferno_burntime_target_time,
597 autocvar_g_buffs_inferno_burntime_factor
599 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
602 // this... is ridiculous (TODO: fix!)
603 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
604 if(!frag_target.vehicle)
605 if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC)
606 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
607 if(!IS_DEAD(frag_target))
608 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
609 if(frag_attacker != frag_target)
610 if(!STAT(FROZEN, frag_target))
611 if(frag_target.takedamage)
612 if(DIFF_TEAM(frag_attacker, frag_target))
614 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);
615 if(frag_target.armorvalue)
616 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);
622 MUTATOR_HOOKFUNCTION(buffs,PlayerSpawn)
625 // reset timers here to prevent them continuing after re-spawn
626 self.buff_disability_time = 0;
627 self.buff_disability_effect_time = 0;
631 .float stat_sv_maxspeed;
632 .float stat_sv_airspeedlimit_nonqw;
633 .float stat_sv_jumpvelocity;
635 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
637 if(self.buffs & BUFF_SPEED.m_itemid)
639 self.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
640 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
643 if(time < self.buff_disability_time)
645 self.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
646 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
649 if(self.buffs & BUFF_JUMP.m_itemid)
651 // automatically reset, no need to worry
652 self.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
658 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
660 if(self.buffs & BUFF_JUMP.m_itemid)
661 player_jumpheight = autocvar_g_buffs_jump_height;
666 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
668 if(time < self.buff_disability_time)
670 monster_speed_walk *= autocvar_g_buffs_disability_speed;
671 monster_speed_run *= autocvar_g_buffs_disability_speed;
677 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
679 if(frag_target.buffs)
681 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
682 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
683 frag_target.buffs = 0;
685 if(frag_target.buff_model)
687 remove(frag_target.buff_model);
688 frag_target.buff_model = world;
694 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
696 if(MUTATOR_RETURNVALUE || gameover) { return false; }
699 int buffid = buff_FirstFromFlags(self.buffs).m_id;
700 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid);
701 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
704 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
710 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
712 if(MUTATOR_RETURNVALUE || gameover) { return false; }
714 if(self.buffs & BUFF_SWAPPER.m_itemid)
716 float best_distance = autocvar_g_buffs_swapper_range;
717 entity closest = world;
718 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
719 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
720 if(DIFF_TEAM(it, self))
722 float test = vlen2(self.origin - it.origin);
723 if(test <= best_distance * best_distance)
725 best_distance = sqrt(test);
733 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
735 my_org = self.origin;
736 my_vel = self.velocity;
737 my_ang = self.angles;
738 their_org = closest.origin;
739 their_vel = closest.velocity;
740 their_ang = closest.angles;
742 Drop_Special_Items(closest);
744 MUTATOR_CALLHOOK(PortalTeleport, self); // initiate flag dropper
746 setorigin(self, their_org);
747 setorigin(closest, my_org);
749 closest.velocity = my_vel;
750 closest.angles = my_ang;
751 closest.fixangle = true;
752 closest.oldorigin = my_org;
753 closest.oldvelocity = my_vel;
754 self.velocity = their_vel;
755 self.angles = their_ang;
756 self.fixangle = true;
757 self.oldorigin = their_org;
758 self.oldvelocity = their_vel;
760 // set pusher so self gets the kill if they fall into void
761 closest.pusher = self;
762 closest.pushltime = time + autocvar_g_maxpushtime;
763 closest.istypefrag = closest.BUTTON_CHAT;
765 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
766 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
768 sound(self, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
769 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
771 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
779 bool buffs_RemovePlayer(entity player)
781 if(player.buff_model)
783 remove(player.buff_model);
784 player.buff_model = world;
787 // also reset timers here to prevent them continuing after spectating
788 player.buff_disability_time = 0;
789 player.buff_disability_effect_time = 0;
793 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { return buffs_RemovePlayer(self); }
794 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { return buffs_RemovePlayer(self); }
796 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
798 entity e = WaypointSprite_getviewentity(other);
800 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
801 // but only apply this to real players, not to spectators
802 if((self.owner.flags & FL_CLIENT) && (self.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == other))
803 if(DIFF_TEAM(self.owner, e))
809 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
811 if (self.classname == "item_flight" && cvar("g_buffs") && cvar("g_buffs_flight"))
813 buff_Init_Compat(self, BUFF_FLIGHT);
816 if(autocvar_g_buffs_replace_powerups)
817 switch(self.classname)
819 case "item_strength":
820 case "item_invincible":
823 buff_SpawnReplacement(e, self);
830 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
832 if(self.buffs & BUFF_SPEED.m_itemid)
833 weapon_rate *= autocvar_g_buffs_speed_rate;
835 if(time < self.buff_disability_time)
836 weapon_rate *= autocvar_g_buffs_disability_rate;
841 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
843 if(self.buffs & BUFF_SPEED.m_itemid)
844 ret_float *= autocvar_g_buffs_speed_weaponspeed;
846 if(time < self.buff_disability_time)
847 ret_float *= autocvar_g_buffs_disability_weaponspeed;
852 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
854 if(gameover || IS_DEAD(self)) { return false; }
856 if(time < self.buff_disability_time)
857 if(time >= self.buff_disability_effect_time)
859 Send_Effect(EFFECT_SMOKING, self.origin + ((self.mins + self.maxs) * 0.5), '0 0 0', 1);
860 self.buff_disability_effect_time = time + 0.5;
863 // handle buff lost status
864 // 1: notify everyone else
865 // 2: notify carrier as well
869 if(time >= self.buff_time)
872 if(STAT(FROZEN, self)) { buff_lost = 1; }
878 int buffid = buff_FirstFromFlags(self.buffs).m_id;
879 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
882 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
883 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
889 if(self.buffs & BUFF_MAGNET.m_itemid)
892 FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
895 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
897 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
899 if(boxesoverlap(self.absmin - pickup_size, self.absmax + pickup_size, it.absmin, it.absmax))
903 entity oldother = other;
905 WITH(entity, self, it, it.touch());
913 if(self.buffs & BUFF_AMMO.m_itemid)
915 self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
917 if((self.buffs & BUFF_INVISIBLE.m_itemid) && (self.oldbuffs & BUFF_INVISIBLE.m_itemid))
918 if(self.alpha != autocvar_g_buffs_invisible_alpha)
919 self.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
921 if(self.buffs & BUFF_MEDIC.m_itemid)
922 if(time >= self.buff_medic_healtime)
924 buff_Medic_Heal(self);
925 self.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
928 #define BUFF_ONADD(b) if ( (self.buffs & (b).m_itemid) && !(self.oldbuffs & (b).m_itemid))
929 #define BUFF_ONREM(b) if (!(self.buffs & (b).m_itemid) && (self.oldbuffs & (b).m_itemid))
931 if(self.buffs != self.oldbuffs)
933 entity buff = buff_FirstFromFlags(self.buffs);
934 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
935 self.buff_time = (bufftime) ? time + bufftime : 0;
937 BUFF_ONADD(BUFF_AMMO)
939 self.buff_ammo_prev_infitems = (self.items & IT_UNLIMITED_WEAPON_AMMO);
940 self.items |= IT_UNLIMITED_WEAPON_AMMO;
943 self.buff_ammo_prev_clipload = self.clip_load;
944 self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
947 BUFF_ONREM(BUFF_AMMO)
949 if(self.buff_ammo_prev_infitems)
950 self.items |= IT_UNLIMITED_WEAPON_AMMO;
952 self.items &= ~IT_UNLIMITED_WEAPON_AMMO;
954 if(self.buff_ammo_prev_clipload)
955 self.clip_load = self.buff_ammo_prev_clipload;
958 BUFF_ONADD(BUFF_INVISIBLE)
960 if(time < self.strength_finished && g_instagib)
961 self.alpha = autocvar_g_instagib_invis_alpha;
963 self.alpha = self.buff_invisible_prev_alpha;
964 self.alpha = autocvar_g_buffs_invisible_alpha;
967 BUFF_ONREM(BUFF_INVISIBLE)
968 self.alpha = self.buff_invisible_prev_alpha;
970 BUFF_ONADD(BUFF_FLIGHT)
972 self.buff_flight_prev_gravity = self.gravity;
973 self.gravity = autocvar_g_buffs_flight_gravity;
976 BUFF_ONREM(BUFF_FLIGHT)
977 self.gravity = self.buff_flight_prev_gravity;
979 self.oldbuffs = self.buffs;
983 buffs_BuffModel_Spawn(self);
985 self.buff_model.color = buff.m_color;
986 self.buff_model.glowmod = buff_GlowColor(self.buff_model);
987 self.buff_model.skin = buff.m_skin;
989 self.effects |= EF_NOSHADOW;
993 remove(self.buff_model);
994 self.buff_model = world;
996 self.effects &= ~(EF_NOSHADOW);
1002 self.buff_model.effects = self.effects;
1003 self.buff_model.effects |= EF_LOWPRECISION;
1004 self.buff_model.effects = self.buff_model.effects & EFMASK_CHEAP; // eat performance
1006 self.buff_model.alpha = self.alpha;
1014 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
1016 self.buffs = other.buffs;
1020 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
1022 vh_vehicle.buffs = vh_player.buffs;
1023 vh_player.buffs = 0;
1024 vh_vehicle.buff_time = max(0, vh_player.buff_time - time);
1025 vh_player.buff_time = 0;
1029 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
1031 vh_player.buffs = vh_player.oldbuffs = vh_vehicle.buffs;
1032 vh_vehicle.buffs = 0;
1033 vh_player.buff_time = time + vh_vehicle.buff_time;
1034 vh_vehicle.buff_time = 0;
1038 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
1040 if(self.buffs & BUFF_MEDIC.m_itemid)
1042 regen_mod_rot = autocvar_g_buffs_medic_rot;
1043 regen_mod_limit = regen_mod_max = autocvar_g_buffs_medic_max;
1044 regen_mod_regen = autocvar_g_buffs_medic_regen;
1047 if(self.buffs & BUFF_SPEED.m_itemid)
1048 regen_mod_regen = autocvar_g_buffs_speed_regen;
1053 MUTATOR_HOOKFUNCTION(buffs, GetCvars)
1055 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_buffs_autoreplace, "cl_buffs_autoreplace");
1059 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1061 ret_string = strcat(ret_string, ":Buffs");
1065 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1067 ret_string = strcat(ret_string, ", Buffs");
1071 void buffs_DelayedInit()
1073 if(autocvar_g_buffs_spawn_count > 0)
1074 if(find(world, classname, "item_buff") == world)
1077 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1080 e.spawnflags |= 64; // always randomize
1081 e.velocity = randomvec() * 250; // this gets reset anyway if random location works