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_vengeance_damage_multiplier;
23 float autocvar_g_buffs_bash_force;
24 float autocvar_g_buffs_bash_force_self;
25 float autocvar_g_buffs_disability_slowtime;
26 float autocvar_g_buffs_disability_speed;
27 float autocvar_g_buffs_disability_rate;
28 float autocvar_g_buffs_disability_weaponspeed;
29 float autocvar_g_buffs_speed_speed;
30 float autocvar_g_buffs_speed_rate;
31 float autocvar_g_buffs_speed_weaponspeed;
32 float autocvar_g_buffs_speed_damage_take;
33 float autocvar_g_buffs_speed_regen;
34 float autocvar_g_buffs_vampire_damage_steal;
35 float autocvar_g_buffs_invisible_alpha;
36 float autocvar_g_buffs_flight_gravity;
37 float autocvar_g_buffs_jump_height;
38 float autocvar_g_buffs_inferno_burntime_factor;
39 float autocvar_g_buffs_inferno_burntime_min_time;
40 float autocvar_g_buffs_inferno_burntime_target_damage;
41 float autocvar_g_buffs_inferno_burntime_target_time;
42 float autocvar_g_buffs_inferno_damagemultiplier;
43 float autocvar_g_buffs_swapper_range;
44 float autocvar_g_buffs_magnet_range_item;
47 .float buff_ammo_prev_infitems;
48 .int buff_ammo_prev_clipload;
50 .float buff_invisible_prev_alpha;
52 .float buff_flight_prev_gravity;
54 .float buff_disability_time;
55 .float buff_disability_effect_time;
56 // common buff variables
57 .float buff_effect_delay;
61 .float buff_activetime;
62 .float buff_activetime_updated;
63 .entity buff_waypoint;
64 .int oldbuffs; // for updating effects
65 .entity buff_model; // controls effects (TODO: make csqc)
67 const vector BUFF_MIN = ('-16 -16 -20');
68 const vector BUFF_MAX = ('16 16 20');
70 // client side options
71 .float cvar_cl_buffs_autoreplace;
76 #include <common/triggers/target/music.qh>
77 #include <common/gamemodes/all.qh>
79 .float buff_time = _STAT(BUFF_TIME);
80 void buffs_DelayedInit();
82 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
86 InitializeEntity(world, buffs_DelayedInit, INITPRIO_FINDTARGET);
90 entity buff_FirstFromFlags(int _buffs)
94 FOREACH(Buffs, it.m_itemid & _buffs, LAMBDA(return it));
99 bool buffs_BuffModel_Customize()
101 entity player, myowner;
104 player = WaypointSprite_getviewentity(other);
105 myowner = self.owner;
106 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
108 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
111 if(MUTATOR_CALLHOOK(BuffModel_Customize, self, player))
114 if(player == myowner || (IS_SPEC(other) && other.enemy == myowner))
116 // somewhat hide the model, but keep the glow
122 self.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
128 void buffs_BuffModel_Spawn(entity player)
130 player.buff_model = spawn();
131 setmodel(player.buff_model, MDL_BUFF);
132 setsize(player.buff_model, '0 0 -40', '0 0 40');
133 setattachment(player.buff_model, player, "");
134 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
135 player.buff_model.owner = player;
136 player.buff_model.scale = 0.7;
137 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
138 player.buff_model.light_lev = 200;
139 player.buff_model.customizeentityforclient = buffs_BuffModel_Customize;
142 vector buff_GlowColor(entity buff)
144 //if(buff.team) { return Team_ColorRGB(buff.team); }
148 void buff_Effect(entity player, string eff)
150 if(!autocvar_g_buffs_effects) { return; }
152 if(time >= self.buff_effect_delay)
154 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
155 self.buff_effect_delay = time + 0.05; // prevent spam
160 float buff_Waypoint_visible_for_player(entity plr)
162 if(!self.owner.buff_active && !self.owner.buff_activetime)
167 return plr.cvar_cl_buffs_autoreplace == false || plr.buffs != self.owner.buffs;
170 return WaypointSprite_visible_for_player(plr);
173 void buff_Waypoint_Spawn(entity e)
175 entity buff = buff_FirstFromFlags(e.buffs);
176 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);
177 wp.wp_extra = buff.m_id;
178 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
179 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
182 void buff_SetCooldown(float cd)
186 if(!self.buff_waypoint)
187 buff_Waypoint_Spawn(self);
189 WaypointSprite_UpdateBuildFinished(self.buff_waypoint, time + cd);
190 self.buff_activetime = cd;
191 self.buff_active = !cd;
194 void buff_Respawn(entity this)
196 if(gameover) { return; }
198 vector oldbufforigin = this.origin;
199 this.velocity = '0 0 200';
201 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
202 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
204 entity spot = SelectSpawnPoint(true);
205 setorigin(this, spot.origin);
206 this.velocity = ((randomvec() * 100) + '0 0 200');
207 this.angles = spot.angles;
210 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
212 setorigin(this, trace_endpos); // attempt to unstick
214 this.movetype = MOVETYPE_TOSS;
216 makevectors(this.angles);
217 this.angles = '0 0 0';
218 if(autocvar_g_buffs_random_lifetime > 0)
219 this.lifetime = time + autocvar_g_buffs_random_lifetime;
221 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
222 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
224 WaypointSprite_Ping(this.buff_waypoint);
226 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
231 if(gameover) { return; }
233 if(ITEM_TOUCH_NEEDKILL())
239 if((self.team && DIFF_TEAM(other, self))
240 || (STAT(FROZEN, other))
242 || (!self.buff_active)
249 if(MUTATOR_CALLHOOK(BuffTouch, self, other))
252 if(!IS_PLAYER(other))
253 return; // incase mutator changed other
257 if (other.cvar_cl_buffs_autoreplace && other.buffs != self.buffs)
259 int buffid = buff_FirstFromFlags(other.buffs).m_id;
260 //Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_DROP, other.buffs);
261 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ITEM_BUFF_LOST, other.netname, buffid);
264 //sound(other, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
266 else { return; } // do nothing
270 self.buff_active = false;
272 int buffid = buff_FirstFromFlags(self.buffs).m_id;
273 Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_GOT, buffid);
274 Send_Notification(NOTIF_ALL_EXCEPT, other, MSG_INFO, INFO_ITEM_BUFF, other.netname, buffid);
276 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
277 sound(other, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
278 other.buffs |= (self.buffs);
281 float buff_Available(entity buff)
283 if (buff == BUFF_Null)
285 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
287 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
289 return cvar(strcat("g_buffs_", buff.m_name));
294 void buff_NewType(entity ent, float cb)
296 RandomSelection_Init();
297 FOREACH(Buffs, buff_Available(it), LAMBDA(
298 it.buff_seencount += 1;
299 // if it's already been chosen, give it a lower priority
300 RandomSelection_Add(world, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
302 ent.buffs = RandomSelection_chosen_float;
307 if(self.buffs != self.oldbuffs)
309 entity buff = buff_FirstFromFlags(self.buffs);
310 self.color = buff.m_color;
311 self.glowmod = buff_GlowColor(buff);
312 self.skin = buff.m_skin;
314 setmodel(self, MDL_BUFF);
316 if(self.buff_waypoint)
318 //WaypointSprite_Disown(self.buff_waypoint, 1);
319 WaypointSprite_Kill(self.buff_waypoint);
320 buff_Waypoint_Spawn(self);
321 if(self.buff_activetime)
322 WaypointSprite_UpdateBuildFinished(self.buff_waypoint, time + self.buff_activetime - frametime);
325 self.oldbuffs = self.buffs;
329 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
330 if(!self.buff_activetime_updated)
332 buff_SetCooldown(self.buff_activetime);
333 self.buff_activetime_updated = true;
336 if(!self.buff_active && !self.buff_activetime)
337 if(!self.owner || STAT(FROZEN, self.owner) || IS_DEAD(self.owner) || !self.owner.iscreature || !(self.owner.buffs & self.buffs))
339 buff_SetCooldown(autocvar_g_buffs_cooldown_respawn + frametime);
341 if(autocvar_g_buffs_randomize)
342 buff_NewType(self, self.buffs);
344 if(autocvar_g_buffs_random_location || (self.spawnflags & 64))
348 if(self.buff_activetime)
350 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
352 self.buff_activetime = max(0, self.buff_activetime - frametime);
354 if(!self.buff_activetime)
356 self.buff_active = true;
357 sound(self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
358 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
364 if(self.team && !self.buff_waypoint)
365 buff_Waypoint_Spawn(self);
368 if(time >= self.lifetime)
372 self.nextthink = time;
373 //self.angles_y = time * 110.1;
376 void buff_Waypoint_Reset()
378 WaypointSprite_Kill(self.buff_waypoint);
380 if(self.buff_activetime) { buff_Waypoint_Spawn(self); }
383 void buff_Reset(entity this)
385 if(autocvar_g_buffs_randomize)
386 buff_NewType(this, this.buffs);
388 buff_SetCooldown(autocvar_g_buffs_cooldown_activate);
389 buff_Waypoint_Reset();
390 this.buff_activetime_updated = false;
392 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
396 float buff_Customize()
398 entity player = WaypointSprite_getviewentity(other);
399 if(!self.buff_active || (self.team && DIFF_TEAM(player, self)))
402 if(self.effects & EF_FULLBRIGHT) { self.effects &= ~(EF_FULLBRIGHT); }
408 if(!(self.effects & EF_FULLBRIGHT)) { self.effects |= EF_FULLBRIGHT; }
409 self.light_lev = 220 + 36 * sin(time);
410 self.pflags = PFLAGS_FULLDYNAMIC;
415 void buff_Init(entity ent)
417 if(!cvar("g_buffs")) { remove(ent); return; }
419 if(!teamplay && ent.team) { ent.team = 0; }
421 entity buff = buff_FirstFromFlags(self.buffs);
424 if(!self.buffs || buff_Available(buff))
425 buff_NewType(self, 0);
427 self.classname = "item_buff";
428 self.solid = SOLID_TRIGGER;
429 self.flags = FL_ITEM;
430 self.think = buff_Think;
431 self.touch = buff_Touch;
432 self.reset = buff_Reset;
433 self.nextthink = time + 0.1;
435 self.movetype = MOVETYPE_TOSS;
437 self.skin = buff.m_skin;
438 self.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
439 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
440 self.customizeentityforclient = buff_Customize;
441 //self.gravity = 100;
442 self.color = buff.m_color;
443 self.glowmod = buff_GlowColor(self);
444 buff_SetCooldown(autocvar_g_buffs_cooldown_activate + game_starttime);
445 self.buff_active = !self.buff_activetime;
446 self.pflags = PFLAGS_FULLDYNAMIC;
448 if(self.spawnflags & 1)
452 self.movetype = MOVETYPE_NONE; // reset by random location
454 setmodel(self, MDL_BUFF);
455 setsize(self, BUFF_MIN, BUFF_MAX);
457 if(cvar("g_buffs_random_location") || (self.spawnflags & 64))
463 void buff_Init_Compat(entity ent, entity replacement)
465 if (ent.spawnflags & 2)
466 ent.team = NUM_TEAM_1;
467 else if (ent.spawnflags & 4)
468 ent.team = NUM_TEAM_2;
470 ent.buffs = replacement.m_itemid;
475 void buff_SpawnReplacement(entity ent, entity old)
477 setorigin(ent, old.origin);
478 ent.angles = old.angles;
479 ent.noalign = (old.noalign || (old.spawnflags & 1));
484 void buff_Vengeance_DelayedDamage()
487 Damage(self.enemy, self.owner, self.owner, self.dmg, DEATH_BUFF.m_id, self.enemy.origin, '0 0 0');
493 float buff_Inferno_CalculateTime(float x, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
495 return offset_y + (intersect_y - offset_y) * logn(((x - offset_x) * ((base - 1) / intersect_x)) + 1, base);
499 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
501 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
503 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
505 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
513 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
515 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
517 if(frag_target.buffs & BUFF_SPEED.m_itemid)
518 if(frag_target != frag_attacker)
519 frag_damage *= autocvar_g_buffs_speed_damage_take;
521 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
522 if((frag_target.health - frag_damage) <= 0)
523 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
525 if(random() <= autocvar_g_buffs_medic_survive_chance)
526 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
528 if(frag_target.buffs & BUFF_JUMP.m_itemid)
529 if(frag_deathtype == DEATH_FALL.m_id)
532 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
534 if(frag_attacker != frag_target)
535 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
537 entity dmgent = spawn();
539 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
540 dmgent.enemy = frag_attacker;
541 dmgent.owner = frag_target;
542 dmgent.think = buff_Vengeance_DelayedDamage;
543 dmgent.nextthink = time + 0.1;
546 if(frag_target.buffs & BUFF_BASH.m_itemid)
547 if(frag_attacker != frag_target)
548 frag_force = '0 0 0';
550 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
552 if(frag_attacker == frag_target)
553 frag_force *= autocvar_g_buffs_bash_force_self;
555 frag_force *= autocvar_g_buffs_bash_force;
557 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
558 if(frag_target != frag_attacker)
559 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
561 if(frag_attacker.buffs & BUFF_MEDIC.m_itemid)
562 if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC)
563 if(SAME_TEAM(frag_attacker, frag_target))
564 if(frag_attacker != frag_target)
566 frag_target.health = min(g_pickup_healthmega_max, frag_target.health + frag_damage);
570 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
571 if(frag_target != frag_attacker) {
572 float time = buff_Inferno_CalculateTime(
575 autocvar_g_buffs_inferno_burntime_min_time,
576 autocvar_g_buffs_inferno_burntime_target_damage,
577 autocvar_g_buffs_inferno_burntime_target_time,
578 autocvar_g_buffs_inferno_burntime_factor
580 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier) * time, time, DEATH_BUFF.m_id);
583 // this... is ridiculous (TODO: fix!)
584 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
585 if(!frag_target.vehicle)
586 if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC)
587 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
588 if(!IS_DEAD(frag_target))
589 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
590 if(frag_attacker != frag_target)
591 if(!STAT(FROZEN, frag_target))
592 if(frag_target.takedamage)
593 if(DIFF_TEAM(frag_attacker, frag_target))
595 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);
596 if(frag_target.armorvalue)
597 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);
603 MUTATOR_HOOKFUNCTION(buffs,PlayerSpawn)
606 // reset timers here to prevent them continuing after re-spawn
607 self.buff_disability_time = 0;
608 self.buff_disability_effect_time = 0;
612 .float stat_sv_maxspeed;
613 .float stat_sv_airspeedlimit_nonqw;
614 .float stat_sv_jumpvelocity;
616 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
618 if(self.buffs & BUFF_SPEED.m_itemid)
620 self.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
621 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
624 if(time < self.buff_disability_time)
626 self.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
627 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
630 if(self.buffs & BUFF_JUMP.m_itemid)
632 // automatically reset, no need to worry
633 self.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
639 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
641 if(self.buffs & BUFF_JUMP.m_itemid)
642 player_jumpheight = autocvar_g_buffs_jump_height;
647 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
649 if(time < self.buff_disability_time)
651 monster_speed_walk *= autocvar_g_buffs_disability_speed;
652 monster_speed_run *= autocvar_g_buffs_disability_speed;
658 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
662 int buffid = buff_FirstFromFlags(self.buffs).m_id;
663 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
668 remove(self.buff_model);
669 self.buff_model = world;
675 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
677 if(MUTATOR_RETURNVALUE || gameover) { return false; }
680 int buffid = buff_FirstFromFlags(self.buffs).m_id;
681 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid);
682 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
685 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
691 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
693 if(MUTATOR_RETURNVALUE || gameover) { return false; }
695 if(self.buffs & BUFF_SWAPPER.m_itemid)
697 float best_distance = autocvar_g_buffs_swapper_range;
698 entity closest = world;
699 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
700 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
701 if(DIFF_TEAM(it, self))
703 float test = vlen2(self.origin - it.origin);
704 if(test <= best_distance * best_distance)
706 best_distance = sqrt(test);
714 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
716 my_org = self.origin;
717 my_vel = self.velocity;
718 my_ang = self.angles;
719 their_org = closest.origin;
720 their_vel = closest.velocity;
721 their_ang = closest.angles;
723 Drop_Special_Items(closest);
725 MUTATOR_CALLHOOK(PortalTeleport, self); // initiate flag dropper
727 setorigin(self, their_org);
728 setorigin(closest, my_org);
730 closest.velocity = my_vel;
731 closest.angles = my_ang;
732 closest.fixangle = true;
733 closest.oldorigin = my_org;
734 closest.oldvelocity = my_vel;
735 self.velocity = their_vel;
736 self.angles = their_ang;
737 self.fixangle = true;
738 self.oldorigin = their_org;
739 self.oldvelocity = their_vel;
741 // set pusher so self gets the kill if they fall into void
742 closest.pusher = self;
743 closest.pushltime = time + autocvar_g_maxpushtime;
744 closest.istypefrag = closest.BUTTON_CHAT;
746 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
747 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
749 sound(self, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
750 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
752 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
760 bool buffs_RemovePlayer(entity player)
762 if(player.buff_model)
764 remove(player.buff_model);
765 player.buff_model = world;
768 // also reset timers here to prevent them continuing after spectating
769 player.buff_disability_time = 0;
770 player.buff_disability_effect_time = 0;
774 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { return buffs_RemovePlayer(self); }
775 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { return buffs_RemovePlayer(self); }
777 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
779 entity e = WaypointSprite_getviewentity(other);
781 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
782 // but only apply this to real players, not to spectators
783 if((self.owner.flags & FL_CLIENT) && (self.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == other))
784 if(DIFF_TEAM(self.owner, e))
790 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
792 if (self.classname == "item_flight" && cvar("g_buffs") && cvar("g_buffs_flight"))
794 buff_Init_Compat(self, BUFF_FLIGHT);
797 if(autocvar_g_buffs_replace_powerups)
798 switch(self.classname)
800 case "item_strength":
801 case "item_invincible":
804 buff_SpawnReplacement(e, self);
811 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
813 if(self.buffs & BUFF_SPEED.m_itemid)
814 weapon_rate *= autocvar_g_buffs_speed_rate;
816 if(time < self.buff_disability_time)
817 weapon_rate *= autocvar_g_buffs_disability_rate;
822 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
824 if(self.buffs & BUFF_SPEED.m_itemid)
825 ret_float *= autocvar_g_buffs_speed_weaponspeed;
827 if(time < self.buff_disability_time)
828 ret_float *= autocvar_g_buffs_disability_weaponspeed;
833 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
835 if(gameover || IS_DEAD(self)) { return false; }
837 if(time < self.buff_disability_time)
838 if(time >= self.buff_disability_effect_time)
840 Send_Effect(EFFECT_SMOKING, self.origin + ((self.mins + self.maxs) * 0.5), '0 0 0', 1);
841 self.buff_disability_effect_time = time + 0.5;
844 // handle buff lost status
845 // 1: notify everyone else
846 // 2: notify carrier as well
850 if(time >= self.buff_time)
853 if(STAT(FROZEN, self)) { buff_lost = 1; }
859 int buffid = buff_FirstFromFlags(self.buffs).m_id;
860 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
863 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
864 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
870 if(self.buffs & BUFF_MAGNET.m_itemid)
872 vector pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
873 for(other = world; (other = findflags(other, flags, FL_ITEM)); )
874 if(boxesoverlap(self.absmin - pickup_size, self.absmax + pickup_size, other.absmin, other.absmax))
885 if(self.buffs & BUFF_AMMO.m_itemid)
887 self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
889 if((self.buffs & BUFF_INVISIBLE.m_itemid) && (self.oldbuffs & BUFF_INVISIBLE.m_itemid))
890 if(self.alpha != autocvar_g_buffs_invisible_alpha)
891 self.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
893 #define BUFF_ONADD(b) if ( (self.buffs & (b).m_itemid) && !(self.oldbuffs & (b).m_itemid))
894 #define BUFF_ONREM(b) if (!(self.buffs & (b).m_itemid) && (self.oldbuffs & (b).m_itemid))
896 if(self.buffs != self.oldbuffs)
898 entity buff = buff_FirstFromFlags(self.buffs);
899 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
900 self.buff_time = (bufftime) ? time + bufftime : 0;
902 BUFF_ONADD(BUFF_AMMO)
904 self.buff_ammo_prev_infitems = (self.items & IT_UNLIMITED_WEAPON_AMMO);
905 self.items |= IT_UNLIMITED_WEAPON_AMMO;
908 self.buff_ammo_prev_clipload = self.clip_load;
909 self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
912 BUFF_ONREM(BUFF_AMMO)
914 if(self.buff_ammo_prev_infitems)
915 self.items |= IT_UNLIMITED_WEAPON_AMMO;
917 self.items &= ~IT_UNLIMITED_WEAPON_AMMO;
919 if(self.buff_ammo_prev_clipload)
920 self.clip_load = self.buff_ammo_prev_clipload;
923 BUFF_ONADD(BUFF_INVISIBLE)
925 if(time < self.strength_finished && g_instagib)
926 self.alpha = autocvar_g_instagib_invis_alpha;
928 self.alpha = self.buff_invisible_prev_alpha;
929 self.alpha = autocvar_g_buffs_invisible_alpha;
932 BUFF_ONREM(BUFF_INVISIBLE)
933 self.alpha = self.buff_invisible_prev_alpha;
935 BUFF_ONADD(BUFF_FLIGHT)
937 self.buff_flight_prev_gravity = self.gravity;
938 self.gravity = autocvar_g_buffs_flight_gravity;
941 BUFF_ONREM(BUFF_FLIGHT)
942 self.gravity = self.buff_flight_prev_gravity;
944 self.oldbuffs = self.buffs;
948 buffs_BuffModel_Spawn(self);
950 self.buff_model.color = buff.m_color;
951 self.buff_model.glowmod = buff_GlowColor(self.buff_model);
952 self.buff_model.skin = buff.m_skin;
954 self.effects |= EF_NOSHADOW;
958 remove(self.buff_model);
959 self.buff_model = world;
961 self.effects &= ~(EF_NOSHADOW);
967 self.buff_model.effects = self.effects;
968 self.buff_model.effects |= EF_LOWPRECISION;
969 self.buff_model.effects = self.buff_model.effects & EFMASK_CHEAP; // eat performance
971 self.buff_model.alpha = self.alpha;
979 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
981 self.buffs = other.buffs;
985 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
987 vh_vehicle.buffs = vh_player.buffs;
989 vh_vehicle.buff_time = max(0, time - vh_player.buff_time);
990 vh_player.buff_time = 0;
994 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
996 vh_player.buffs = vh_player.oldbuffs = vh_vehicle.buffs;
997 vh_vehicle.buffs = 0;
998 vh_player.buff_time = time + vh_vehicle.buff_time;
999 vh_vehicle.buff_time = 0;
1003 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
1005 if(self.buffs & BUFF_MEDIC.m_itemid)
1007 regen_mod_rot = autocvar_g_buffs_medic_rot;
1008 regen_mod_limit = regen_mod_max = autocvar_g_buffs_medic_max;
1009 regen_mod_regen = autocvar_g_buffs_medic_regen;
1012 if(self.buffs & BUFF_SPEED.m_itemid)
1013 regen_mod_regen = autocvar_g_buffs_speed_regen;
1018 MUTATOR_HOOKFUNCTION(buffs, GetCvars)
1020 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_buffs_autoreplace, "cl_buffs_autoreplace");
1024 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1026 ret_string = strcat(ret_string, ":Buffs");
1030 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1032 ret_string = strcat(ret_string, ", Buffs");
1036 void buffs_DelayedInit()
1038 if(autocvar_g_buffs_spawn_count > 0)
1039 if(find(world, classname, "item_buff") == world)
1042 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1045 e.spawnflags |= 64; // always randomize
1046 e.velocity = randomvec() * 250; // this gets reset anyway if random location works