3 #include <common/triggers/target/music.qh>
4 #include <common/gamemodes/_mod.qh>
6 .float buff_time = _STAT(BUFF_TIME);
7 void buffs_DelayedInit(entity this);
9 AUTOCVAR(g_buffs, int, -1, "Enable buffs, -1: enabled but no auto location or replacing powerups, 1: enabled and can replace them");
11 REGISTER_MUTATOR(buffs, autocvar_g_buffs)
15 if(autocvar_g_buffs > 0)
16 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
20 bool buffs_BuffModel_Customize(entity this, entity client)
22 entity player, myowner;
25 player = WaypointSprite_getviewentity(client);
27 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
29 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
32 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
35 if(player == myowner || (IS_SPEC(client) && client.enemy == myowner))
37 // somewhat hide the model, but keep the glow
43 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
49 void buffs_BuffModel_Spawn(entity player)
51 player.buff_model = spawn();
52 setmodel(player.buff_model, MDL_BUFF);
53 setsize(player.buff_model, '0 0 -40', '0 0 40');
54 setattachment(player.buff_model, player, "");
55 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
56 player.buff_model.owner = player;
57 player.buff_model.scale = 0.7;
58 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
59 player.buff_model.light_lev = 200;
60 setcefc(player.buff_model, buffs_BuffModel_Customize);
63 vector buff_GlowColor(entity buff)
65 //if(buff.team) { return Team_ColorRGB(buff.team); }
69 void buff_Effect(entity player, string eff)
71 if(!autocvar_g_buffs_effects) { return; }
73 if(time >= player.buff_effect_delay)
75 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
76 player.buff_effect_delay = time + 0.05; // prevent spam
81 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
83 if(!this.owner.buff_active && !this.owner.buff_activetime)
88 return CS(view).cvar_cl_buffs_autoreplace == false || view.buffs != this.owner.buffs;
91 return WaypointSprite_visible_for_player(this, player, view);
94 void buff_Waypoint_Spawn(entity e)
96 entity buff = buff_FirstFromFlags(e.buffs);
97 entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, NULL, e.team, e, buff_waypoint, true, RADARICON_Buff);
98 wp.wp_extra = buff.m_id;
99 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
100 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
103 void buff_SetCooldown(entity this, float cd)
107 if(!this.buff_waypoint)
108 buff_Waypoint_Spawn(this);
110 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
111 this.buff_activetime = cd;
112 this.buff_active = !cd;
115 void buff_Respawn(entity this)
117 if(game_stopped) return;
119 vector oldbufforigin = this.origin;
120 this.velocity = '0 0 200';
122 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
123 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
125 entity spot = SelectSpawnPoint(this, true);
126 setorigin(this, spot.origin);
127 this.velocity = ((randomvec() * 100) + '0 0 200');
128 this.angles = spot.angles;
131 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
133 setorigin(this, trace_endpos); // attempt to unstick
135 set_movetype(this, MOVETYPE_TOSS);
137 makevectors(this.angles);
138 this.angles = '0 0 0';
139 if(autocvar_g_buffs_random_lifetime > 0)
140 this.lifetime = time + autocvar_g_buffs_random_lifetime;
142 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
143 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
145 WaypointSprite_Ping(this.buff_waypoint);
147 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
150 void buff_Touch(entity this, entity toucher)
152 if(game_stopped) return;
154 if(ITEM_TOUCH_NEEDKILL())
160 if(!this.buff_active)
163 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
165 toucher = M_ARGV(1, entity);
167 if(!IS_PLAYER(toucher))
168 return; // incase mutator changed toucher
170 if((this.team && DIFF_TEAM(toucher, this))
171 || (STAT(FROZEN, toucher))
173 || (time < PS(toucher).buff_shield)
182 if (CS(toucher).cvar_cl_buffs_autoreplace && toucher.buffs != this.buffs)
184 int buffid = buff_FirstFromFlags(toucher.buffs).m_id;
185 //Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, toucher.buffs);
186 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
189 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
191 else { return; } // do nothing
194 this.owner = toucher;
195 this.buff_active = false;
197 int buffid = buff_FirstFromFlags(this.buffs).m_id;
198 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, buffid);
199 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, buffid);
201 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
202 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
203 toucher.buffs |= (this.buffs);
206 float buff_Available(entity buff)
208 if (buff == BUFF_Null)
210 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
212 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
214 return cvar(strcat("g_buffs_", buff.m_name));
219 void buff_NewType(entity ent)
221 RandomSelection_Init();
222 FOREACH(Buffs, buff_Available(it),
224 // if it's already been chosen, give it a lower priority
225 RandomSelection_AddEnt(it, max(0.2, 1 / it.buff_seencount), 1);
227 entity newbuff = RandomSelection_chosen_ent;
228 newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
229 ent.buffs = newbuff.m_itemid;
232 void buff_Think(entity this)
234 if(this.buffs != this.oldbuffs)
236 entity buff = buff_FirstFromFlags(this.buffs);
237 this.color = buff.m_color;
238 this.glowmod = buff_GlowColor(buff);
239 this.skin = buff.m_skin;
241 setmodel(this, MDL_BUFF);
242 setsize(this, BUFF_MIN, BUFF_MAX);
244 if(this.buff_waypoint)
246 //WaypointSprite_Disown(this.buff_waypoint, 1);
247 WaypointSprite_Kill(this.buff_waypoint);
248 buff_Waypoint_Spawn(this);
249 if(this.buff_activetime)
250 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
253 this.oldbuffs = this.buffs;
257 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
258 if(!this.buff_activetime_updated)
260 buff_SetCooldown(this, this.buff_activetime);
261 this.buff_activetime_updated = true;
264 if(!this.buff_active && !this.buff_activetime)
265 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle || !(this.owner.buffs & this.buffs) || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway))
267 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
269 if(autocvar_g_buffs_randomize)
272 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
276 if(this.buff_activetime)
278 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
280 this.buff_activetime = max(0, this.buff_activetime - frametime);
282 if(!this.buff_activetime)
284 this.buff_active = true;
285 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
286 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
292 if(this.team && !this.buff_waypoint)
293 buff_Waypoint_Spawn(this);
296 if(time >= this.lifetime)
300 this.nextthink = time;
301 //this.angles_y = time * 110.1;
304 void buff_Waypoint_Reset(entity this)
306 WaypointSprite_Kill(this.buff_waypoint);
308 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
311 void buff_Reset(entity this)
313 if(autocvar_g_buffs_randomize)
316 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
317 buff_Waypoint_Reset(this);
318 this.buff_activetime_updated = false;
320 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
324 bool buff_Customize(entity this, entity client)
326 entity player = WaypointSprite_getviewentity(client);
327 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
330 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
336 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
337 this.light_lev = 220 + 36 * sin(time);
338 this.pflags = PFLAGS_FULLDYNAMIC;
343 void buff_Init(entity this)
345 if(!cvar("g_buffs")) { delete(this); return; }
347 if(!teamplay && this.team) { this.team = 0; }
349 entity buff = buff_FirstFromFlags(this.buffs);
351 if(!this.buffs || !buff_Available(buff))
354 this.classname = "item_buff";
355 this.solid = SOLID_TRIGGER;
356 this.flags = FL_ITEM;
357 this.bot_pickup = true;
358 this.bot_pickupevalfunc = generic_pickupevalfunc;
359 this.bot_pickupbasevalue = 1000;
360 IL_PUSH(g_items, this);
361 setthink(this, buff_Think);
362 settouch(this, buff_Touch);
363 this.reset = buff_Reset;
364 this.nextthink = time + 0.1;
366 set_movetype(this, MOVETYPE_TOSS);
368 this.skin = buff.m_skin;
369 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
370 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
371 setcefc(this, buff_Customize);
372 //this.gravity = 100;
373 this.color = buff.m_color;
374 this.glowmod = buff_GlowColor(this);
375 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
376 this.buff_active = !this.buff_activetime;
377 this.pflags = PFLAGS_FULLDYNAMIC;
379 if(this.spawnflags & 1)
383 set_movetype(this, MOVETYPE_NONE); // reset by random location
385 setmodel(this, MDL_BUFF);
386 setsize(this, BUFF_MIN, BUFF_MAX);
388 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
392 void buff_Init_Compat(entity ent, entity replacement)
394 if (ent.spawnflags & 2)
395 ent.team = NUM_TEAM_1;
396 else if (ent.spawnflags & 4)
397 ent.team = NUM_TEAM_2;
399 ent.buffs = replacement.m_itemid;
404 void buff_SpawnReplacement(entity ent, entity old)
406 setorigin(ent, old.origin);
407 ent.angles = old.angles;
408 ent.noalign = (old.noalign || (old.spawnflags & 1));
413 void buff_Vengeance_DelayedDamage(entity this)
416 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0');
422 // note: only really useful in teamplay
423 void buff_Medic_Heal(entity this)
425 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
427 if(SAME_TEAM(it, this))
428 if(it.health < autocvar_g_balance_health_regenstable)
430 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
431 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
436 float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
438 return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
442 MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
444 entity frag_attacker = M_ARGV(1, entity);
445 entity frag_target = M_ARGV(2, entity);
446 float frag_deathtype = M_ARGV(3, float);
447 float frag_damage = M_ARGV(4, float);
448 vector frag_force = M_ARGV(6, vector);
450 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
452 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
454 float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent;
455 frag_damage = bound(0, frag_damage - reduced, frag_damage);
458 if(frag_target.buffs & BUFF_SPEED.m_itemid)
459 if(frag_target != frag_attacker)
460 frag_damage *= autocvar_g_buffs_speed_damage_take;
462 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
463 if((frag_target.health - frag_damage) <= 0)
464 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
466 if(random() <= autocvar_g_buffs_medic_survive_chance)
467 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
469 if(frag_target.buffs & BUFF_JUMP.m_itemid)
470 if(frag_deathtype == DEATH_FALL.m_id)
473 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
475 if(frag_attacker != frag_target)
476 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
478 entity dmgent = spawn();
480 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
481 dmgent.enemy = frag_attacker;
482 dmgent.owner = frag_target;
483 setthink(dmgent, buff_Vengeance_DelayedDamage);
484 dmgent.nextthink = time + 0.1;
487 if(frag_target.buffs & BUFF_BASH.m_itemid)
488 if(frag_attacker != frag_target)
489 frag_force = '0 0 0';
491 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
493 if(frag_attacker == frag_target)
494 frag_force *= autocvar_g_buffs_bash_force_self;
496 frag_force *= autocvar_g_buffs_bash_force;
498 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
499 if(frag_target != frag_attacker)
500 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
502 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
504 if(frag_deathtype == DEATH_FIRE.m_id)
506 if(frag_deathtype == DEATH_LAVA.m_id)
507 frag_damage *= 0.5; // TODO: cvarize?
510 if(frag_attacker.buffs & BUFF_LUCK.m_itemid)
511 if(frag_attacker != frag_target)
512 if(autocvar_g_buffs_luck_damagemultiplier > 0)
513 if(random() <= autocvar_g_buffs_luck_chance)
514 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
516 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
517 if(frag_target != frag_attacker) {
518 float btime = buff_Inferno_CalculateTime(
521 autocvar_g_buffs_inferno_burntime_min_time,
522 autocvar_g_buffs_inferno_burntime_target_damage,
523 autocvar_g_buffs_inferno_burntime_target_time,
524 autocvar_g_buffs_inferno_burntime_factor
526 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
529 // this... is ridiculous (TODO: fix!)
530 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
531 if(!frag_target.vehicle)
532 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
533 if(!IS_DEAD(frag_target))
534 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
535 if(frag_attacker != frag_target)
536 if(!STAT(FROZEN, frag_target))
537 if(frag_target.takedamage)
538 if(DIFF_TEAM(frag_attacker, frag_target))
540 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);
541 if(frag_target.armorvalue)
542 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);
545 M_ARGV(4, float) = frag_damage;
546 M_ARGV(6, vector) = frag_force;
549 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
551 entity player = M_ARGV(0, entity);
554 player.buff_time = 0;
555 PS(player).buff_shield = time + 0.5; // prevent picking up buffs immediately
556 // reset timers here to prevent them continuing after re-spawn
557 player.buff_disability_time = 0;
558 player.buff_disability_effect_time = 0;
561 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
563 entity player = M_ARGV(0, entity);
564 // these automatically reset, no need to worry
566 if(player.buffs & BUFF_SPEED.m_itemid)
567 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
569 if(time < player.buff_disability_time)
570 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
573 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
575 entity player = M_ARGV(0, entity);
576 // these automatically reset, no need to worry
578 if(player.buffs & BUFF_JUMP.m_itemid)
579 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
582 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
584 entity mon = M_ARGV(0, entity);
586 if(time < mon.buff_disability_time)
588 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
589 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
593 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
595 entity frag_target = M_ARGV(2, entity);
597 if(frag_target.buffs)
599 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
600 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
601 frag_target.buffs = 0;
603 if(frag_target.buff_model)
605 delete(frag_target.buff_model);
606 frag_target.buff_model = NULL;
611 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
613 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
615 entity player = M_ARGV(0, entity);
619 int buffid = buff_FirstFromFlags(player.buffs).m_id;
620 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
621 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
624 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
625 //player.buff_time = 0; // already notified
626 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
631 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
633 if(MUTATOR_RETURNVALUE || game_stopped) return;
634 entity player = M_ARGV(0, entity);
636 if(player.buffs & BUFF_SWAPPER.m_itemid)
638 float best_distance = autocvar_g_buffs_swapper_range;
639 entity closest = NULL;
640 FOREACH_CLIENT(IS_PLAYER(it), {
641 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
642 if(DIFF_TEAM(it, player))
644 float test = vlen2(player.origin - it.origin);
645 if(test <= best_distance * best_distance)
647 best_distance = sqrt(test);
655 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
657 my_org = player.origin;
658 my_vel = player.velocity;
659 my_ang = player.angles;
660 their_org = closest.origin;
661 their_vel = closest.velocity;
662 their_ang = closest.angles;
664 Drop_Special_Items(closest);
666 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
668 setorigin(player, their_org);
669 setorigin(closest, my_org);
671 closest.velocity = my_vel;
672 closest.angles = my_ang;
673 closest.fixangle = true;
674 closest.oldorigin = my_org;
675 closest.oldvelocity = my_vel;
676 player.velocity = their_vel;
677 player.angles = their_ang;
678 player.fixangle = true;
679 player.oldorigin = their_org;
680 player.oldvelocity = their_vel;
682 // set pusher so player gets the kill if they fall into void
683 closest.pusher = player;
684 closest.pushltime = time + autocvar_g_maxpushtime;
685 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
687 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
688 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
690 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
691 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
693 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
700 bool buffs_RemovePlayer(entity player)
702 if(player.buff_model)
704 delete(player.buff_model);
705 player.buff_model = NULL;
708 // also reset timers here to prevent them continuing after spectating
709 player.buff_disability_time = 0;
710 player.buff_disability_effect_time = 0;
714 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
715 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
717 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
719 entity wp = M_ARGV(0, entity);
720 entity player = M_ARGV(1, entity);
722 entity e = WaypointSprite_getviewentity(player);
724 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
725 // but only apply this to real players, not to spectators
726 if((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player))
727 if(DIFF_TEAM(wp.owner, e))
731 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
733 if(autocvar_g_buffs < 0)
734 return; // no auto replacing of entities in this mode
736 entity ent = M_ARGV(0, entity);
738 if(autocvar_g_buffs_replace_powerups)
739 switch(ent.classname)
741 case "item_strength":
742 case "item_invincible":
745 buff_SpawnReplacement(e, ent);
751 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
753 entity player = M_ARGV(1, entity);
755 if(player.buffs & BUFF_SPEED.m_itemid)
756 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
758 if(time < player.buff_disability_time)
759 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
762 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
764 entity player = M_ARGV(1, entity);
766 if(player.buffs & BUFF_SPEED.m_itemid)
767 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
769 if(time < player.buff_disability_time)
770 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
773 .bool buff_flight_crouchheld;
775 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
777 entity player = M_ARGV(0, entity);
779 if(game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) return;
781 if(player.buffs & BUFF_FLIGHT.m_itemid)
783 if(!PHYS_INPUT_BUTTON_CROUCH(player))
784 player.buff_flight_crouchheld = false;
785 else if(!player.buff_flight_crouchheld)
787 player.buff_flight_crouchheld = true;
788 player.gravity *= -1;
792 if(time < player.buff_disability_time)
793 if(time >= player.buff_disability_effect_time)
795 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
796 player.buff_disability_effect_time = time + 0.5;
799 // handle buff lost status
800 // 1: notify everyone else
801 // 2: notify carrier as well
804 if(player.buff_time && player.buffs)
805 if(time >= player.buff_time)
807 player.buff_time = 0;
811 if(STAT(FROZEN, player)) { buff_lost = 1; }
817 int buffid = buff_FirstFromFlags(player.buffs).m_id;
820 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
821 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
824 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
826 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
830 if(player.buffs & BUFF_MAGNET.m_itemid)
833 IL_EACH(g_items, it.itemdef,
836 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
838 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
840 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
843 gettouch(it)(it, player);
848 if(player.buffs & BUFF_AMMO.m_itemid)
850 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
852 .entity weaponentity = weaponentities[slot];
853 if(player.(weaponentity).clip_size)
854 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
858 if((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
859 player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
861 if(player.buffs & BUFF_MEDIC.m_itemid)
862 if(time >= player.buff_medic_healtime)
864 buff_Medic_Heal(player);
865 player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
868 #define BUFF_ONADD(b) if ( (player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
869 #define BUFF_ONREM(b) if (!(player.buffs & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
871 if(player.buffs != player.oldbuffs)
873 entity buff = buff_FirstFromFlags(player.buffs);
874 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
875 player.buff_time = (bufftime) ? time + bufftime : 0;
877 BUFF_ONADD(BUFF_AMMO)
879 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO);
880 player.items |= IT_UNLIMITED_WEAPON_AMMO;
882 if(player.buffs & BUFF_AMMO.m_itemid)
884 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
886 .entity weaponentity = weaponentities[slot];
887 if(player.(weaponentity).clip_load)
888 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
889 if(player.(weaponentity).clip_size)
890 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
895 BUFF_ONREM(BUFF_AMMO)
897 if(player.buff_ammo_prev_infitems)
898 player.items |= IT_UNLIMITED_WEAPON_AMMO;
900 player.items &= ~IT_UNLIMITED_WEAPON_AMMO;
902 if(player.buffs & BUFF_AMMO.m_itemid)
904 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
906 .entity weaponentity = weaponentities[slot];
907 if(player.(weaponentity).buff_ammo_prev_clipload)
908 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
913 BUFF_ONADD(BUFF_INVISIBLE)
915 if(time < player.strength_finished && g_instagib)
916 player.buff_invisible_prev_alpha = default_player_alpha; // we don't want to save the powerup's alpha, as player may lose the powerup while holding the buff
918 player.buff_invisible_prev_alpha = player.alpha;
919 player.alpha = autocvar_g_buffs_invisible_alpha;
922 BUFF_ONREM(BUFF_INVISIBLE)
924 if(time < player.strength_finished && g_instagib)
925 player.alpha = autocvar_g_instagib_invis_alpha;
927 player.alpha = player.buff_invisible_prev_alpha;
930 BUFF_ONADD(BUFF_FLIGHT)
932 player.buff_flight_oldgravity = player.gravity;
937 BUFF_ONREM(BUFF_FLIGHT)
938 player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
940 player.oldbuffs = player.buffs;
943 if(!player.buff_model)
944 buffs_BuffModel_Spawn(player);
946 player.buff_model.color = buff.m_color;
947 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
948 player.buff_model.skin = buff.m_skin;
950 player.effects |= EF_NOSHADOW;
954 if(player.buff_model)
955 delete(player.buff_model);
956 player.buff_model = NULL;
958 player.effects &= ~(EF_NOSHADOW);
962 if(player.buff_model)
964 player.buff_model.effects = player.effects;
965 player.buff_model.effects |= EF_LOWPRECISION;
966 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
968 player.buff_model.alpha = player.alpha;
975 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
977 entity spectatee = M_ARGV(0, entity);
978 entity client = M_ARGV(1, entity);
980 client.buffs = spectatee.buffs;
981 client.buff_time = spectatee.buff_time;
984 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
986 entity player = M_ARGV(0, entity);
988 if(player.buffs & BUFF_MEDIC.m_itemid)
990 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
991 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
992 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
995 if(player.buffs & BUFF_SPEED.m_itemid)
996 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
999 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1001 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1003 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
1004 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1007 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1009 if(autocvar_g_buffs > 0)
1010 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1013 void buffs_DelayedInit(entity this)
1015 if(autocvar_g_buffs_spawn_count > 0)
1016 if(find(NULL, classname, "item_buff") == NULL)
1019 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1022 e.spawnflags |= 64; // always randomize
1023 e.velocity = randomvec() * 250; // this gets reset anyway if random location works