1 #ifndef MUTATOR_BUFFS_H
2 #define MUTATOR_BUFFS_H
5 .float buff_ammo_prev_infitems;
6 .int buff_ammo_prev_clipload;
8 .float buff_invisible_prev_alpha;
10 .float buff_flight_prev_gravity;
12 .float buff_disability_time;
13 .float buff_disability_effect_time;
14 // common buff variables
15 .float buff_effect_delay;
19 .float buff_activetime;
20 .float buff_activetime_updated;
21 .entity buff_waypoint;
22 .int oldbuffs; // for updating effects
23 .entity buff_model; // controls effects (TODO: make csqc)
25 const vector BUFF_MIN = ('-16 -16 -20');
26 const vector BUFF_MAX = ('16 16 20');
28 // client side options
29 .float cvar_cl_buffs_autoreplace;
34 #include "../../../common/triggers/target/music.qh"
35 #include "../../../common/gamemodes/all.qh"
36 #include "../../../common/buffs/all.qh"
39 void buffs_DelayedInit();
41 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
45 addstat(STAT_BUFFS, AS_INT, buffs);
46 addstat(STAT_BUFF_TIME, AS_FLOAT, buff_time);
48 InitializeEntity(world, buffs_DelayedInit, INITPRIO_FINDTARGET);
52 entity buff_FirstFromFlags(int _buffs)
56 FOREACH(Buffs, it.m_itemid & _buffs, LAMBDA(return it));
61 bool buffs_BuffModel_Customize()
63 entity player, myowner;
66 player = WaypointSprite_getviewentity(other);
68 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
70 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
73 if(MUTATOR_CALLHOOK(BuffModel_Customize, self, player))
76 if(player == myowner || (IS_SPEC(other) && other.enemy == myowner))
78 // somewhat hide the model, but keep the glow
84 self.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
90 void buffs_BuffModel_Spawn(entity player)
92 player.buff_model = spawn();
93 setmodel(player.buff_model, MDL_BUFF);
94 setsize(player.buff_model, '0 0 -40', '0 0 40');
95 setattachment(player.buff_model, player, "");
96 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
97 player.buff_model.owner = player;
98 player.buff_model.scale = 0.7;
99 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
100 player.buff_model.light_lev = 200;
101 player.buff_model.customizeentityforclient = buffs_BuffModel_Customize;
104 vector buff_GlowColor(entity buff)
106 //if(buff.team) { return Team_ColorRGB(buff.team); }
110 void buff_Effect(entity player, string eff)
112 if(!autocvar_g_buffs_effects) { return; }
114 if(time >= self.buff_effect_delay)
116 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
117 self.buff_effect_delay = time + 0.05; // prevent spam
122 float buff_Waypoint_visible_for_player(entity plr)
124 if(!self.owner.buff_active && !self.owner.buff_activetime)
129 return plr.cvar_cl_buffs_autoreplace == false || plr.buffs != self.owner.buffs;
132 return WaypointSprite_visible_for_player(plr);
135 void buff_Waypoint_Spawn(entity e)
137 entity buff = buff_FirstFromFlags(e.buffs);
138 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);
139 wp.wp_extra = buff.m_id;
140 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
141 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
144 void buff_SetCooldown(float cd)
148 if(!self.buff_waypoint)
149 buff_Waypoint_Spawn(self);
151 WaypointSprite_UpdateBuildFinished(self.buff_waypoint, time + cd);
152 self.buff_activetime = cd;
153 self.buff_active = !cd;
156 void buff_Respawn(entity ent)
158 if(gameover) { return; }
160 vector oldbufforigin = ent.origin;
162 if(!MoveToRandomMapLocation(ent, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
164 entity spot = SelectSpawnPoint(true);
165 setorigin(ent, ((spot.origin + '0 0 200') + (randomvec() * 300)));
166 ent.angles = spot.angles;
169 tracebox(ent.origin, ent.mins * 1.5, self.maxs * 1.5, ent.origin, MOVE_NOMONSTERS, ent);
171 setorigin(ent, trace_endpos); // attempt to unstick
173 ent.movetype = MOVETYPE_TOSS;
175 makevectors(ent.angles);
176 ent.velocity = '0 0 200';
177 ent.angles = '0 0 0';
178 if(autocvar_g_buffs_random_lifetime > 0)
179 ent.lifetime = time + autocvar_g_buffs_random_lifetime;
181 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((ent.mins + ent.maxs) * 0.5), '0 0 0', 1);
182 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(ent), '0 0 0', 1);
184 WaypointSprite_Ping(ent.buff_waypoint);
186 sound(ent, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
191 if(gameover) { return; }
193 if(ITEM_TOUCH_NEEDKILL())
199 if((self.team && DIFF_TEAM(other, self))
202 || (!self.buff_active)
209 if(MUTATOR_CALLHOOK(BuffTouch, self, other))
212 if(!IS_PLAYER(other))
213 return; // incase mutator changed other
217 if (other.cvar_cl_buffs_autoreplace && other.buffs != self.buffs)
219 int buffid = buff_FirstFromFlags(other.buffs).m_id;
220 //Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_DROP, other.buffs);
221 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ITEM_BUFF_LOST, other.netname, buffid);
224 //sound(other, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
226 else { return; } // do nothing
230 self.buff_active = false;
232 int buffid = buff_FirstFromFlags(self.buffs).m_id;
233 Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_BUFF_GOT, buffid);
234 Send_Notification(NOTIF_ALL_EXCEPT, other, MSG_INFO, INFO_ITEM_BUFF, other.netname, buffid);
236 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
237 sound(other, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
238 other.buffs |= (self.buffs);
241 float buff_Available(entity buff)
243 if (buff == BUFF_Null)
245 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
247 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
249 return cvar(strcat("g_buffs_", buff.m_name));
254 void buff_NewType(entity ent, float cb)
256 RandomSelection_Init();
257 FOREACH(Buffs, buff_Available(it), LAMBDA(
258 it.buff_seencount += 1;
259 // if it's already been chosen, give it a lower priority
260 RandomSelection_Add(world, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
262 ent.buffs = RandomSelection_chosen_float;
267 if(self.buffs != self.oldbuffs)
269 entity buff = buff_FirstFromFlags(self.buffs);
270 self.color = buff.m_color;
271 self.glowmod = buff_GlowColor(buff);
272 self.skin = buff.m_skin;
274 setmodel(self, MDL_BUFF);
276 if(self.buff_waypoint)
278 //WaypointSprite_Disown(self.buff_waypoint, 1);
279 WaypointSprite_Kill(self.buff_waypoint);
280 buff_Waypoint_Spawn(self);
281 if(self.buff_activetime)
282 WaypointSprite_UpdateBuildFinished(self.buff_waypoint, time + self.buff_activetime - frametime);
285 self.oldbuffs = self.buffs;
289 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
290 if(!self.buff_activetime_updated)
292 buff_SetCooldown(self.buff_activetime);
293 self.buff_activetime_updated = true;
296 if(!self.buff_active && !self.buff_activetime)
297 if(!self.owner || self.owner.frozen || self.owner.deadflag != DEAD_NO || !self.owner.iscreature || !(self.owner.buffs & self.buffs))
299 buff_SetCooldown(autocvar_g_buffs_cooldown_respawn + frametime);
301 if(autocvar_g_buffs_randomize)
302 buff_NewType(self, self.buffs);
304 if(autocvar_g_buffs_random_location || (self.spawnflags & 64))
308 if(self.buff_activetime)
310 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
312 self.buff_activetime = max(0, self.buff_activetime - frametime);
314 if(!self.buff_activetime)
316 self.buff_active = true;
317 sound(self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
318 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
324 if(self.team && !self.buff_waypoint)
325 buff_Waypoint_Spawn(self);
328 if(time >= self.lifetime)
332 self.nextthink = time;
333 //self.angles_y = time * 110.1;
336 void buff_Waypoint_Reset()
338 WaypointSprite_Kill(self.buff_waypoint);
340 if(self.buff_activetime) { buff_Waypoint_Spawn(self); }
345 if(autocvar_g_buffs_randomize)
346 buff_NewType(self, self.buffs);
348 buff_SetCooldown(autocvar_g_buffs_cooldown_activate);
349 buff_Waypoint_Reset();
350 self.buff_activetime_updated = false;
352 if(autocvar_g_buffs_random_location || (self.spawnflags & 64))
356 float buff_Customize()
358 entity player = WaypointSprite_getviewentity(other);
359 if(!self.buff_active || (self.team && DIFF_TEAM(player, self)))
362 if(self.effects & EF_FULLBRIGHT) { self.effects &= ~(EF_FULLBRIGHT); }
368 if(!(self.effects & EF_FULLBRIGHT)) { self.effects |= EF_FULLBRIGHT; }
369 self.light_lev = 220 + 36 * sin(time);
370 self.pflags = PFLAGS_FULLDYNAMIC;
375 void buff_Init(entity ent)
377 if(!cvar("g_buffs")) { remove(ent); return; }
379 if(!teamplay && ent.team) { ent.team = 0; }
381 entity buff = buff_FirstFromFlags(self.buffs);
384 if(!self.buffs || buff_Available(buff))
385 buff_NewType(self, 0);
387 self.classname = "item_buff";
388 self.solid = SOLID_TRIGGER;
389 self.flags = FL_ITEM;
390 self.think = buff_Think;
391 self.touch = buff_Touch;
392 self.reset = buff_Reset;
393 self.nextthink = time + 0.1;
395 self.movetype = MOVETYPE_TOSS;
397 self.skin = buff.m_skin;
398 self.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
399 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
400 self.customizeentityforclient = buff_Customize;
401 //self.gravity = 100;
402 self.color = buff.m_color;
403 self.glowmod = buff_GlowColor(self);
404 buff_SetCooldown(autocvar_g_buffs_cooldown_activate + game_starttime);
405 self.buff_active = !self.buff_activetime;
406 self.pflags = PFLAGS_FULLDYNAMIC;
408 if(self.spawnflags & 1)
412 self.movetype = MOVETYPE_NONE; // reset by random location
414 setmodel(self, MDL_BUFF);
415 setsize(self, BUFF_MIN, BUFF_MAX);
417 if(cvar("g_buffs_random_location") || (self.spawnflags & 64))
423 void buff_Init_Compat(entity ent, entity replacement)
425 if (ent.spawnflags & 2)
426 ent.team = NUM_TEAM_1;
427 else if (ent.spawnflags & 4)
428 ent.team = NUM_TEAM_2;
430 ent.buffs = replacement.m_itemid;
435 void buff_SpawnReplacement(entity ent, entity old)
437 setorigin(ent, old.origin);
438 ent.angles = old.angles;
439 ent.noalign = (old.noalign || (old.spawnflags & 1));
444 void buff_Vengeance_DelayedDamage()
447 Damage(self.enemy, self.owner, self.owner, self.dmg, DEATH_BUFF.m_id, self.enemy.origin, '0 0 0');
453 float buff_Inferno_CalculateTime(float x, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
455 return offset_y + (intersect_y - offset_y) * logn(((x - offset_x) * ((base - 1) / intersect_x)) + 1, base);
459 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
461 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
463 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
465 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
473 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
475 if(frag_deathtype == DEATH_BUFF.m_id) { return false; }
477 if(frag_target.buffs & BUFF_SPEED.m_itemid)
478 if(frag_target != frag_attacker)
479 frag_damage *= autocvar_g_buffs_speed_damage_take;
481 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
482 if((frag_target.health - frag_damage) <= 0)
483 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
485 if(random() <= autocvar_g_buffs_medic_survive_chance)
486 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
488 if(frag_target.buffs & BUFF_JUMP.m_itemid)
489 if(frag_deathtype == DEATH_FALL.m_id)
492 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
494 if(frag_attacker != frag_target)
495 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
497 entity dmgent = spawn();
499 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
500 dmgent.enemy = frag_attacker;
501 dmgent.owner = frag_target;
502 dmgent.think = buff_Vengeance_DelayedDamage;
503 dmgent.nextthink = time + 0.1;
506 if(frag_target.buffs & BUFF_BASH.m_itemid)
507 if(frag_attacker != frag_target)
509 frag_force = '0 0 0';
511 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
513 if(frag_attacker == frag_target)
514 frag_force *= autocvar_g_buffs_bash_force_self;
516 frag_force *= autocvar_g_buffs_bash_force;
518 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
519 if(frag_target != frag_attacker)
520 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
522 if(frag_attacker.buffs & BUFF_MEDIC.m_itemid)
523 if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC)
524 if(SAME_TEAM(frag_attacker, frag_target))
525 if(frag_attacker != frag_target)
527 frag_target.health = min(g_pickup_healthmega_max, frag_target.health + frag_damage);
531 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
532 if(frag_target != frag_attacker) {
533 float time = buff_Inferno_CalculateTime(
536 autocvar_g_buffs_inferno_burntime_min_time,
537 autocvar_g_buffs_inferno_burntime_target_damage,
538 autocvar_g_buffs_inferno_burntime_target_time,
539 autocvar_g_buffs_inferno_burntime_factor
541 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier) * time, time, DEATH_BUFF.m_id);
544 // this... is ridiculous (TODO: fix!)
545 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
546 if(!frag_target.vehicle)
547 if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC)
548 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
549 if(frag_target.deadflag == DEAD_NO)
550 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
551 if(frag_attacker != frag_target)
552 if(!frag_target.frozen)
553 if(frag_target.takedamage)
554 if(DIFF_TEAM(frag_attacker, frag_target))
556 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);
557 if(frag_target.armorvalue)
558 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);
564 MUTATOR_HOOKFUNCTION(buffs,PlayerSpawn)
567 // reset timers here to prevent them continuing after re-spawn
568 self.buff_disability_time = 0;
569 self.buff_disability_effect_time = 0;
573 .float stat_sv_maxspeed;
574 .float stat_sv_airspeedlimit_nonqw;
575 .float stat_sv_jumpvelocity;
577 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
579 if(self.buffs & BUFF_SPEED.m_itemid)
581 self.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
582 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
585 if(time < self.buff_disability_time)
587 self.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
588 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
591 if(self.buffs & BUFF_JUMP.m_itemid)
593 // automatically reset, no need to worry
594 self.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
600 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
602 if(self.buffs & BUFF_JUMP.m_itemid)
603 player_jumpheight = autocvar_g_buffs_jump_height;
608 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
610 if(time < self.buff_disability_time)
612 monster_speed_walk *= autocvar_g_buffs_disability_speed;
613 monster_speed_run *= autocvar_g_buffs_disability_speed;
619 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
623 int buffid = buff_FirstFromFlags(self.buffs).m_id;
624 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
629 remove(self.buff_model);
630 self.buff_model = world;
636 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
638 if(MUTATOR_RETURNVALUE || gameover) { return false; }
641 int buffid = buff_FirstFromFlags(self.buffs).m_id;
642 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid);
643 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
646 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
652 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
654 if(MUTATOR_RETURNVALUE || gameover) { return false; }
656 if(self.buffs & BUFF_SWAPPER.m_itemid)
658 float best_distance = autocvar_g_buffs_swapper_range;
659 entity closest = world;
661 FOR_EACH_PLAYER(player)
662 if(DIFF_TEAM(self, player))
663 if(player.deadflag == DEAD_NO && !player.frozen && !player.vehicle)
664 if(vlen(self.origin - player.origin) <= best_distance)
666 best_distance = vlen(self.origin - player.origin);
672 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
674 my_org = self.origin;
675 my_vel = self.velocity;
676 my_ang = self.angles;
677 their_org = closest.origin;
678 their_vel = closest.velocity;
679 their_ang = closest.angles;
681 Drop_Special_Items(closest);
683 MUTATOR_CALLHOOK(PortalTeleport, self); // initiate flag dropper
685 setorigin(self, their_org);
686 setorigin(closest, my_org);
688 closest.velocity = my_vel;
689 closest.angles = my_ang;
690 closest.fixangle = true;
691 closest.oldorigin = my_org;
692 closest.oldvelocity = my_vel;
693 self.velocity = their_vel;
694 self.angles = their_ang;
695 self.fixangle = true;
696 self.oldorigin = their_org;
697 self.oldvelocity = their_vel;
699 // set pusher so self gets the kill if they fall into void
700 closest.pusher = self;
701 closest.pushltime = time + autocvar_g_maxpushtime;
702 closest.istypefrag = closest.BUTTON_CHAT;
704 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
705 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
707 sound(self, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
708 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
710 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
718 bool buffs_RemovePlayer(entity player)
720 if(player.buff_model)
722 remove(player.buff_model);
723 player.buff_model = world;
726 // also reset timers here to prevent them continuing after spectating
727 player.buff_disability_time = 0;
728 player.buff_disability_effect_time = 0;
732 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { return buffs_RemovePlayer(self); }
733 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { return buffs_RemovePlayer(self); }
735 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
737 entity e = WaypointSprite_getviewentity(other);
739 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
740 // but only apply this to real players, not to spectators
741 if((self.owner.flags & FL_CLIENT) && (self.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == other))
742 if(DIFF_TEAM(self.owner, e))
748 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
750 if(autocvar_g_buffs_replace_powerups)
751 switch(self.classname)
753 case "item_strength":
754 case "item_invincible":
757 buff_SpawnReplacement(e, self);
764 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
766 if(self.buffs & BUFF_SPEED.m_itemid)
767 weapon_rate *= autocvar_g_buffs_speed_rate;
769 if(time < self.buff_disability_time)
770 weapon_rate *= autocvar_g_buffs_disability_rate;
775 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
777 if(self.buffs & BUFF_SPEED.m_itemid)
778 ret_float *= autocvar_g_buffs_speed_weaponspeed;
780 if(time < self.buff_disability_time)
781 ret_float *= autocvar_g_buffs_disability_weaponspeed;
786 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
788 if(gameover || self.deadflag != DEAD_NO) { return false; }
790 if(time < self.buff_disability_time)
791 if(time >= self.buff_disability_effect_time)
793 Send_Effect(EFFECT_SMOKING, self.origin + ((self.mins + self.maxs) * 0.5), '0 0 0', 1);
794 self.buff_disability_effect_time = time + 0.5;
797 // handle buff lost status
798 // 1: notify everyone else
799 // 2: notify carrier as well
803 if(time >= self.buff_time)
806 if(self.frozen) { buff_lost = 1; }
812 int buffid = buff_FirstFromFlags(self.buffs).m_id;
813 Send_Notification(NOTIF_ALL_EXCEPT, self, MSG_INFO, INFO_ITEM_BUFF_LOST, self.netname, buffid);
816 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
817 sound(self, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
823 if(self.buffs & BUFF_MAGNET.m_itemid)
825 vector pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
826 for(other = world; (other = findflags(other, flags, FL_ITEM)); )
827 if(boxesoverlap(self.absmin - pickup_size, self.absmax + pickup_size, other.absmin, other.absmax))
838 if(self.buffs & BUFF_AMMO.m_itemid)
840 self.clip_load = self.(weapon_load[self.switchweapon]) = self.clip_size;
842 if((self.buffs & BUFF_INVISIBLE.m_itemid) && (self.oldbuffs & BUFF_INVISIBLE.m_itemid))
843 if(self.alpha != autocvar_g_buffs_invisible_alpha)
844 self.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
846 #define BUFF_ONADD(b) if ( (self.buffs & (b).m_itemid) && !(self.oldbuffs & (b).m_itemid))
847 #define BUFF_ONREM(b) if (!(self.buffs & (b).m_itemid) && (self.oldbuffs & (b).m_itemid))
849 if(self.buffs != self.oldbuffs)
851 entity buff = buff_FirstFromFlags(self.buffs);
852 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
853 self.buff_time = (bufftime) ? time + bufftime : 0;
855 BUFF_ONADD(BUFF_AMMO)
857 self.buff_ammo_prev_infitems = (self.items & IT_UNLIMITED_WEAPON_AMMO);
858 self.items |= IT_UNLIMITED_WEAPON_AMMO;
861 self.buff_ammo_prev_clipload = self.clip_load;
862 self.clip_load = self.(weapon_load[self.switchweapon]) = self.clip_size;
865 BUFF_ONREM(BUFF_AMMO)
867 if(self.buff_ammo_prev_infitems)
868 self.items |= IT_UNLIMITED_WEAPON_AMMO;
870 self.items &= ~IT_UNLIMITED_WEAPON_AMMO;
872 if(self.buff_ammo_prev_clipload)
873 self.clip_load = self.buff_ammo_prev_clipload;
876 BUFF_ONADD(BUFF_INVISIBLE)
878 if(time < self.strength_finished && g_instagib)
879 self.alpha = autocvar_g_instagib_invis_alpha;
881 self.alpha = self.buff_invisible_prev_alpha;
882 self.alpha = autocvar_g_buffs_invisible_alpha;
885 BUFF_ONREM(BUFF_INVISIBLE)
886 self.alpha = self.buff_invisible_prev_alpha;
888 BUFF_ONADD(BUFF_FLIGHT)
890 self.buff_flight_prev_gravity = self.gravity;
891 self.gravity = autocvar_g_buffs_flight_gravity;
894 BUFF_ONREM(BUFF_FLIGHT)
895 self.gravity = self.buff_flight_prev_gravity;
897 self.oldbuffs = self.buffs;
901 buffs_BuffModel_Spawn(self);
903 self.buff_model.color = buff.m_color;
904 self.buff_model.glowmod = buff_GlowColor(self.buff_model);
905 self.buff_model.skin = buff.m_skin;
907 self.effects |= EF_NOSHADOW;
911 remove(self.buff_model);
912 self.buff_model = world;
914 self.effects &= ~(EF_NOSHADOW);
920 self.buff_model.effects = self.effects;
921 self.buff_model.effects |= EF_LOWPRECISION;
922 self.buff_model.effects = self.buff_model.effects & EFMASK_CHEAP; // eat performance
924 self.buff_model.alpha = self.alpha;
932 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
934 self.buffs = other.buffs;
938 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
940 vh_vehicle.buffs = vh_player.buffs;
942 vh_vehicle.buff_time = vh_player.buff_time - time;
943 vh_player.buff_time = 0;
947 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
949 vh_player.buffs = vh_player.oldbuffs = vh_vehicle.buffs;
950 vh_vehicle.buffs = 0;
951 vh_player.buff_time = time + vh_vehicle.buff_time;
952 vh_vehicle.buff_time = 0;
956 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
958 if(self.buffs & BUFF_MEDIC.m_itemid)
960 regen_mod_rot = autocvar_g_buffs_medic_rot;
961 regen_mod_limit = regen_mod_max = autocvar_g_buffs_medic_max;
962 regen_mod_regen = autocvar_g_buffs_medic_regen;
965 if(self.buffs & BUFF_SPEED.m_itemid)
966 regen_mod_regen = autocvar_g_buffs_speed_regen;
971 MUTATOR_HOOKFUNCTION(buffs, GetCvars)
973 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_buffs_autoreplace, "cl_buffs_autoreplace");
977 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
979 ret_string = strcat(ret_string, ":Buffs");
983 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
985 ret_string = strcat(ret_string, ", Buffs");
989 void buffs_DelayedInit()
991 if(autocvar_g_buffs_spawn_count > 0)
992 if(find(world, classname, "item_buff") == world)
995 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
998 e.spawnflags |= 64; // always randomize
999 e.velocity = randomvec() * 250; // this gets reset anyway if random location works