3 #include <common/mapobjects/target/music.qh>
4 #include <common/mutators/mutator/instagib/_mod.qh>
5 #include <common/gamemodes/_mod.qh>
6 #include <server/items/items.qh>
8 bool buffs_BuffModel_Customize(entity this, entity client)
10 entity player = WaypointSprite_getviewentity(client);
11 entity myowner = this.owner;
13 if(myowner.alpha <= 0.5 && DIFF_TEAM(player, myowner) && myowner.alpha != 0)
16 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
21 // somewhat hide the model, but keep the glow
27 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
33 void buffs_BuffModel_Spawn(entity player)
35 player.buff_model = new(buff_model);
36 setmodel(player.buff_model, MDL_BUFF);
37 setsize(player.buff_model, '0 0 -40', '0 0 40');
38 setattachment(player.buff_model, player, "");
39 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
40 player.buff_model.owner = player;
41 player.buff_model.scale = 0.7;
42 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
43 player.buff_model.light_lev = 200;
44 setcefc(player.buff_model, buffs_BuffModel_Customize);
47 void buffs_BuffModel_Remove(entity player)
50 delete(player.buff_model);
51 player.buff_model = NULL;
54 vector buff_GlowColor(entity buff)
56 //if(buff.team) { return Team_ColorRGB(buff.team); }
60 void buff_Effect(entity player, string eff)
62 if(!autocvar_g_buffs_effects) { return; }
64 if(time >= player.buff_effect_delay)
66 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
67 player.buff_effect_delay = time + 0.05; // prevent spam
72 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
74 if(!this.owner.buff_active && !this.owner.buff_activetime || !this.owner.buffdef)
77 entity heldbuff = buff_FirstFromFlags(view); // TODO: cache this information so it isn't performing a loop every frame
80 return CS_CVAR(view).cvar_cl_buffs_autoreplace == false || heldbuff != this.owner.buffdef;
83 return WaypointSprite_visible_for_player(this, player, view);
86 void buff_Waypoint_Spawn(entity e)
88 if(autocvar_g_buffs_waypoint_distance <= 0) return;
90 entity buff = e.buffdef;
91 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);
92 wp.wp_extra = buff.m_id;
93 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
94 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
97 void buff_SetCooldown(entity this, float cd)
101 if(!this.buff_waypoint)
102 buff_Waypoint_Spawn(this);
104 if(this.buff_waypoint)
105 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
107 this.buff_activetime = cd;
108 this.buff_active = !cd;
111 void buff_Respawn(entity this)
113 if(game_stopped) return;
115 vector oldbufforigin = this.origin;
116 this.velocity = '0 0 200';
118 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
119 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
121 entity spot = SelectSpawnPoint(this, true);
122 setorigin(this, spot.origin);
123 this.velocity = ((randomvec() * 100) + '0 0 200');
124 this.angles = spot.angles;
127 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
129 setorigin(this, trace_endpos); // attempt to unstick
131 set_movetype(this, MOVETYPE_TOSS);
133 makevectors(this.angles);
134 this.angles = '0 0 0';
135 if(autocvar_g_buffs_random_lifetime > 0)
136 this.lifetime = time + autocvar_g_buffs_random_lifetime;
138 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
139 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
141 WaypointSprite_Ping(this.buff_waypoint);
143 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
146 void buff_Touch(entity this, entity toucher)
148 if(game_stopped) return;
150 if(ITEM_TOUCH_NEEDKILL())
156 if(!this.buff_active)
159 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
161 toucher = M_ARGV(1, entity);
163 if(!IS_PLAYER(toucher))
164 return; // incase mutator changed toucher
166 if((this.team && DIFF_TEAM(toucher, this))
167 || (STAT(FROZEN, toucher))
169 || (!this.buffdef) // TODO: error out or maybe reset type if this occurs?
170 || (time < PS(toucher).buff_shield)
177 entity heldbuff = buff_FirstFromFlags(toucher);
178 entity thebuff = this.buffdef;
182 if (CS_CVAR(toucher).cvar_cl_buffs_autoreplace && heldbuff != thebuff)
184 // TODO: lost-gained notification for this case
185 int buffid = heldbuff.m_id;
186 Send_Notification(NOTIF_ONE, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
187 if(!IS_INDEPENDENT_PLAYER(toucher))
188 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
190 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
192 else { return; } // do nothing
195 this.owner = toucher;
196 this.buff_active = false;
198 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, thebuff.m_id);
199 if(!IS_INDEPENDENT_PLAYER(toucher))
200 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, thebuff.m_id);
202 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
203 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
204 float oldtime = StatusEffects_gettime(thebuff, toucher);
205 float bufftime = ((this.buffs_finished) ? this.buffs_finished : thebuff.m_time(thebuff));
207 buff_RemoveAll(toucher, STATUSEFFECT_REMOVE_NORMAL); // remove previous buffs so that a new one may be added
209 StatusEffects_apply(thebuff, toucher, min(time + bufftime, max(oldtime, time) + bufftime), 0);
211 StatusEffects_apply(thebuff, toucher, time + 999, 0); // HACK: zero timer means "infinite"!
213 STAT(LAST_PICKUP, toucher) = time;
216 float buff_Available(entity buff)
220 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_AMMO) || cvar("g_melee_only")))
222 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
224 return cvar(strcat("g_buffs_", buff.netname));
229 void buff_NewType(entity ent)
231 RandomSelection_Init();
232 FOREACH(StatusEffect, it.instanceOfBuff && buff_Available(it),
234 // if it's already been chosen, give it a lower priority
235 float myseencount = (it.buff_seencount > 0) ? it.buff_seencount : 1; // no division by zero please!
236 RandomSelection_AddEnt(it, max(0.2, 1 / myseencount), 1);
238 entity newbuff = RandomSelection_chosen_ent;
241 newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
242 ent.buffdef = newbuff;
245 void buff_RemoveAll(entity actor, int removal_type)
247 if(!actor.statuseffects)
249 FOREACH(StatusEffect, it.instanceOfBuff,
251 it.m_remove(it, actor, removal_type);
255 entity buff_FirstFromFlags(entity actor)
257 if(!actor.statuseffects)
259 FOREACH(StatusEffect, it.instanceOfBuff && it.m_active(it, actor), { return it; });
263 void buff_Think(entity this)
265 if(this.buff_waypoint && autocvar_g_buffs_waypoint_distance <= 0)
266 WaypointSprite_Kill(this.buff_waypoint);
268 if(this.buffdef != this.oldbuffs)
270 entity buff = this.buffdef;
271 this.color = buff.m_color;
272 this.glowmod = buff_GlowColor(buff);
273 this.skin = buff.m_skin;
275 setmodel(this, MDL_BUFF);
276 setsize(this, BUFF_MIN, BUFF_MAX);
278 if(this.buff_waypoint)
280 //WaypointSprite_Disown(this.buff_waypoint, 1);
281 WaypointSprite_Kill(this.buff_waypoint);
282 buff_Waypoint_Spawn(this);
283 if(this.buff_activetime)
284 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
287 this.oldbuffs = this.buffdef;
291 if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
292 if(!this.buff_activetime_updated)
294 buff_SetCooldown(this, this.buff_activetime);
295 this.buff_activetime_updated = true;
298 if(!this.buff_active && !this.buff_activetime)
299 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle
300 || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway) || this.buffdef != buff_FirstFromFlags(this.owner))
302 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
304 if(autocvar_g_buffs_randomize && (!teamplay || autocvar_g_buffs_randomize_teamplay))
307 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
311 if(this.buff_activetime)
313 if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
315 this.buff_activetime = max(0, this.buff_activetime - frametime);
317 if(!this.buff_activetime)
319 this.buff_active = true;
320 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
321 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
327 if(this.team && !this.buff_waypoint)
328 buff_Waypoint_Spawn(this);
330 if(this.lifetime && time >= this.lifetime)
334 this.nextthink = time;
335 //this.angles_y = time * 110.1;
338 void buff_Waypoint_Reset(entity this)
340 WaypointSprite_Kill(this.buff_waypoint);
342 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
345 void buff_Reset(entity this)
347 if(autocvar_g_buffs_randomize && (!teamplay || autocvar_g_buffs_randomize_teamplay))
350 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
351 buff_Waypoint_Reset(this);
352 this.buff_activetime_updated = false;
354 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
358 bool buff_Customize(entity this, entity client)
360 entity player = WaypointSprite_getviewentity(client);
361 if((!this.buff_active || !this.buffdef) || (this.team && DIFF_TEAM(player, this)))
364 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
370 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
371 this.light_lev = 220 + 36 * sin(time);
372 this.pflags = PFLAGS_FULLDYNAMIC;
377 void buff_Delete(entity this)
379 WaypointSprite_Kill(this.buff_waypoint);
383 void buff_Init(entity this)
385 if(!cvar("g_buffs")) { delete(this); return; }
387 if(!teamplay && this.team) { this.team = 0; }
389 entity buff = this.buffdef;
391 if(!buff || !buff_Available(buff))
394 this.classname = "item_buff";
395 this.solid = SOLID_TRIGGER;
396 this.flags = FL_ITEM;
397 this.bot_pickup = true;
398 this.bot_pickupevalfunc = generic_pickupevalfunc;
399 this.bot_pickupbasevalue = 1000;
400 IL_PUSH(g_items, this);
401 setthink(this, buff_Think);
402 settouch(this, buff_Touch);
403 setmodel(this, MDL_BUFF);
404 setsize(this, BUFF_MIN, BUFF_MAX);
405 this.reset = buff_Reset;
406 this.nextthink = time + 0.1;
408 set_movetype(this, MOVETYPE_TOSS);
410 this.skin = buff.m_skin;
411 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
412 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
413 setcefc(this, buff_Customize);
414 //this.gravity = 100;
415 this.color = buff.m_color;
416 this.glowmod = buff_GlowColor(this);
417 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
418 this.buff_active = !this.buff_activetime;
419 this.pflags = PFLAGS_FULLDYNAMIC;
420 this.dtor = buff_Delete;
422 if(!this.buffs_finished)
423 this.buffs_finished = this.count; // legacy support
425 if(this.spawnflags & 1)
429 set_movetype(this, MOVETYPE_NONE); // reset by random location
431 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
435 void buff_Init_Compat(entity ent, entity replacement)
437 if (ent.spawnflags & 2)
438 ent.team = NUM_TEAM_1;
439 else if (ent.spawnflags & 4)
440 ent.team = NUM_TEAM_2;
442 ent.buffdef = replacement;
447 void buff_SpawnReplacement(entity ent, entity old)
449 setorigin(ent, old.origin);
450 ent.angles = old.angles;
451 ent.noalign = Item_ShouldKeepPosition(old);
456 void buff_Vengeance_DelayedDamage(entity this)
459 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, DMG_NOWEP, this.enemy.origin, '0 0 0');
465 float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
467 return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
471 MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
473 entity frag_attacker = M_ARGV(1, entity);
474 entity frag_target = M_ARGV(2, entity);
475 float frag_deathtype = M_ARGV(3, float);
476 float frag_damage = M_ARGV(4, float);
477 vector frag_force = M_ARGV(6, vector);
479 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
481 if(StatusEffects_active(BUFF_RESISTANCE, frag_target))
483 float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent;
484 frag_damage = bound(0, frag_damage - reduced, frag_damage);
487 if(StatusEffects_active(BUFF_SPEED, frag_target))
488 if(frag_target != frag_attacker)
489 frag_damage *= autocvar_g_buffs_speed_damage_take;
491 if(StatusEffects_active(BUFF_MEDIC, frag_target))
492 if((GetResource(frag_target, RES_HEALTH) - frag_damage) <= 0)
493 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
495 if(random() <= autocvar_g_buffs_medic_survive_chance)
496 frag_damage = max(5, GetResource(frag_target, RES_HEALTH) - autocvar_g_buffs_medic_survive_health);
498 if(StatusEffects_active(BUFF_JUMP, frag_target))
499 if(frag_deathtype == DEATH_FALL.m_id)
502 if(StatusEffects_active(BUFF_VENGEANCE, frag_target))
504 if(frag_attacker != frag_target)
505 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
507 entity dmgent = new_pure(dmgent);
509 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
510 dmgent.enemy = frag_attacker;
511 dmgent.owner = frag_target;
512 setthink(dmgent, buff_Vengeance_DelayedDamage);
513 dmgent.nextthink = time + 0.1;
516 if(StatusEffects_active(BUFF_BASH, frag_target))
517 if(frag_attacker != frag_target)
518 frag_force = '0 0 0';
520 if(StatusEffects_active(BUFF_BASH, frag_attacker))
523 if(frag_attacker == frag_target)
524 frag_force *= autocvar_g_buffs_bash_force_self;
526 frag_force *= autocvar_g_buffs_bash_force;
529 if(StatusEffects_active(BUFF_DISABILITY, frag_attacker))
530 if(frag_target != frag_attacker)
531 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
533 if(StatusEffects_active(BUFF_INFERNO, frag_target))
535 if(frag_deathtype == DEATH_FIRE.m_id)
537 if(frag_deathtype == DEATH_LAVA.m_id)
538 frag_damage *= 0.5; // TODO: cvarize?
541 if(StatusEffects_active(BUFF_LUCK, frag_attacker))
542 if(frag_attacker != frag_target)
543 if(autocvar_g_buffs_luck_damagemultiplier > 0)
544 if(random() <= autocvar_g_buffs_luck_chance)
545 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
547 if(StatusEffects_active(BUFF_INFERNO, frag_attacker))
548 if(frag_target != frag_attacker) {
549 float btime = buff_Inferno_CalculateTime(
552 autocvar_g_buffs_inferno_burntime_min_time,
553 autocvar_g_buffs_inferno_burntime_target_damage,
554 autocvar_g_buffs_inferno_burntime_target_time,
555 autocvar_g_buffs_inferno_burntime_factor
557 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
560 M_ARGV(4, float) = frag_damage;
561 M_ARGV(6, vector) = frag_force;
564 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
566 // NOTE: vampire PlayerDamage_SplitHealthArmor code is similar
567 entity frag_attacker = M_ARGV(1, entity);
568 entity frag_target = M_ARGV(2, entity);
569 if(!StatusEffects_active(BUFF_VAMPIRE, frag_attacker))
571 float health_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
573 if (time >= frag_target.spawnshieldtime && frag_target != frag_attacker
574 && IS_PLAYER(frag_attacker) && !IS_DEAD(frag_target) && !STAT(FROZEN, frag_target))
576 GiveResource(frag_attacker, RES_HEALTH, autocvar_g_buffs_vampire_damage_steal * health_take);
580 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
582 entity player = M_ARGV(0, entity);
584 buffs_BuffModel_Remove(player);
585 player.oldbuffs = NULL;
586 // reset timers here to prevent them continuing after re-spawn
587 player.buff_disability_time = 0;
588 player.buff_disability_effect_time = 0;
591 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
593 entity player = M_ARGV(0, entity);
594 // these automatically reset, no need to worry
596 if(StatusEffects_active(BUFF_SPEED, player))
597 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
599 if(time < player.buff_disability_time)
600 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
603 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
605 entity player = M_ARGV(0, entity);
606 // these automatically reset, no need to worry
608 if(StatusEffects_active(BUFF_JUMP, player))
609 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
612 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
614 entity mon = M_ARGV(0, entity);
616 if(time < mon.buff_disability_time)
618 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
619 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
623 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
625 entity frag_target = M_ARGV(2, entity);
627 entity heldbuff = buff_FirstFromFlags(frag_target);
630 int buffid = heldbuff.m_id;
631 if(!IS_INDEPENDENT_PLAYER(frag_target))
632 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
634 buffs_BuffModel_Remove(frag_target);
638 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
640 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
642 entity player = M_ARGV(0, entity);
644 entity heldbuff = buff_FirstFromFlags(player);
647 int buffid = heldbuff.m_id;
648 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
649 if(!IS_INDEPENDENT_PLAYER(player))
650 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
652 buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
653 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
654 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
659 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
661 if(MUTATOR_RETURNVALUE || game_stopped) return;
662 entity player = M_ARGV(0, entity);
664 if(StatusEffects_active(BUFF_SWAPPER, player))
666 float best_distance = autocvar_g_buffs_swapper_range;
667 entity closest = NULL;
668 FOREACH_CLIENT(IS_PLAYER(it), {
669 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
670 if(DIFF_TEAM(it, player))
672 float test = vlen2(player.origin - it.origin);
673 if(test <= best_distance * best_distance)
675 best_distance = sqrt(test);
683 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
685 my_org = player.origin;
686 my_vel = player.velocity;
687 my_ang = player.angles;
688 their_org = closest.origin;
689 their_vel = closest.velocity;
690 their_ang = closest.angles;
692 Drop_Special_Items(closest);
694 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
696 setorigin(player, their_org);
697 setorigin(closest, my_org);
699 closest.velocity = my_vel;
700 closest.angles = my_ang;
701 if (IS_BOT_CLIENT(closest))
703 closest.v_angle = closest.angles;
704 bot_aim_reset(closest);
706 closest.fixangle = true;
707 closest.oldorigin = my_org;
708 closest.oldvelocity = my_vel;
709 player.velocity = their_vel;
710 player.angles = their_ang;
711 if (IS_BOT_CLIENT(player))
713 player.v_angle = player.angles;
714 bot_aim_reset(player);
716 player.fixangle = true;
717 player.oldorigin = their_org;
718 player.oldvelocity = their_vel;
720 // set pusher so player gets the kill if they fall into void
721 closest.pusher = player;
722 closest.pushltime = time + autocvar_g_maxpushtime;
723 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
725 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
726 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
728 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
729 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
731 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
732 buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
738 bool buffs_RemovePlayer(entity player)
740 buffs_BuffModel_Remove(player);
742 // also reset timers here to prevent them continuing after spectating
743 player.buff_disability_time = 0;
744 player.buff_disability_effect_time = 0;
748 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
749 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
751 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
753 entity wp = M_ARGV(0, entity);
754 entity player = M_ARGV(1, entity);
756 entity e = WaypointSprite_getviewentity(player);
758 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
759 // but only apply this to real players, not to spectators
760 if((wp.owner.flags & FL_CLIENT) && (e == player) && StatusEffects_active(BUFF_INVISIBLE, wp.owner))
761 if(DIFF_TEAM(wp.owner, e))
765 MUTATOR_HOOKFUNCTION(buffs, FilterItem)
767 if(autocvar_g_buffs < 0)
768 return false; // no auto replacing of entities in this mode
770 entity item = M_ARGV(0, entity);
772 if(autocvar_g_buffs_replace_powerups)
774 switch(item.classname)
776 case "item_strength":
780 buff_SpawnReplacement(e, item);
789 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
791 entity player = M_ARGV(1, entity);
793 if(StatusEffects_active(BUFF_SPEED, player))
794 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
796 if(time < player.buff_disability_time)
797 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
800 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
802 entity player = M_ARGV(1, entity);
804 if(StatusEffects_active(BUFF_SPEED, player))
805 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
807 if(time < player.buff_disability_time)
808 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
811 .bool buff_flight_crouchheld;
813 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
815 entity player = M_ARGV(0, entity);
817 if(game_stopped || IS_DEAD(player) || !IS_PLAYER(player)) return;
819 if(StatusEffects_active(BUFF_FLIGHT, player))
821 if(!PHYS_INPUT_BUTTON_CROUCH(player))
822 player.buff_flight_crouchheld = false;
823 else if(!player.buff_flight_crouchheld)
825 player.buff_flight_crouchheld = true;
826 player.gravity *= -1;
830 if(time < player.buff_disability_time)
831 if(time >= player.buff_disability_effect_time)
833 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
834 player.buff_disability_effect_time = time + 0.5;
837 // handle buff lost status
838 // 1: notify everyone else
839 // 2: notify carrier as well
842 entity heldbuff = buff_FirstFromFlags(player);
843 float bufftime = StatusEffects_gettime(heldbuff, player);
844 if(heldbuff && bufftime && time >= bufftime)
847 if(STAT(FROZEN, player)) { buff_lost = 1; }
849 if(buff_lost && heldbuff)
851 int buffid = heldbuff.m_id;
854 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
855 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
857 else if(!IS_INDEPENDENT_PLAYER(player))
858 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
859 buff_RemoveAll(player, STATUSEFFECT_REMOVE_TIMEOUT); // TODO: remove only the currently active buff?
861 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
864 if(StatusEffects_active(BUFF_MAGNET, player))
867 IL_EACH(g_items, it.itemdef,
870 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
872 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
874 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
877 gettouch(it)(it, player);
882 if(StatusEffects_active(BUFF_AMMO, player))
884 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
886 .entity weaponentity = weaponentities[slot];
887 if(player.(weaponentity).clip_size)
888 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
892 if(!player.vehicle && StatusEffects_active(BUFF_INVISIBLE, player) && player.oldbuffs == BUFF_INVISIBLE)
893 player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
895 #define BUFF_ONADD(b) if ( (heldbuff == (b)) && (player.oldbuffs != (b)))
896 #define BUFF_ONREM(b) if ( (heldbuff != (b)) && (player.oldbuffs == (b)))
898 if(heldbuff != player.oldbuffs)
900 bufftime = heldbuff ? heldbuff.m_time(heldbuff) : 0;
901 if(StatusEffects_gettime(heldbuff, player) <= time) // if the player still has a buff countdown, don't reset it!
903 player.statuseffects.statuseffect_time[heldbuff.m_id] = (bufftime) ? time + bufftime : 0;
904 StatusEffects_update(player);
907 BUFF_ONADD(BUFF_AMMO)
909 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_AMMO);
910 player.items |= IT_UNLIMITED_AMMO;
912 if(StatusEffects_active(BUFF_AMMO, player))
914 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
916 .entity weaponentity = weaponentities[slot];
917 if(player.(weaponentity).clip_load)
918 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
919 if(player.(weaponentity).clip_size)
920 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
925 BUFF_ONREM(BUFF_AMMO)
927 if(player.buff_ammo_prev_infitems)
928 player.items |= IT_UNLIMITED_AMMO;
930 player.items &= ~IT_UNLIMITED_AMMO;
932 if(StatusEffects_active(BUFF_AMMO, player))
934 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
936 .entity weaponentity = weaponentities[slot];
937 if(player.(weaponentity).buff_ammo_prev_clipload)
938 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
943 BUFF_ONADD(BUFF_INVISIBLE)
945 if(StatusEffects_active(STATUSEFFECT_Strength, player) && MUTATOR_IS_ENABLED(mutator_instagib))
946 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
948 player.buff_invisible_prev_alpha = player.alpha;
950 player.alpha = autocvar_g_buffs_invisible_alpha;
953 BUFF_ONREM(BUFF_INVISIBLE)
957 if(StatusEffects_active(STATUSEFFECT_Strength, player) && MUTATOR_IS_ENABLED(mutator_instagib))
958 player.alpha = autocvar_g_instagib_invis_alpha;
960 player.alpha = player.buff_invisible_prev_alpha;
964 BUFF_ONADD(BUFF_FLIGHT)
966 player.buff_flight_oldgravity = player.gravity;
971 BUFF_ONREM(BUFF_FLIGHT)
972 player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
974 player.oldbuffs = heldbuff;
977 if(!player.buff_model)
978 buffs_BuffModel_Spawn(player);
980 player.buff_model.color = heldbuff.m_color;
981 player.buff_model.glowmod = buff_GlowColor(heldbuff);
982 player.buff_model.skin = heldbuff.m_skin;
984 player.effects |= EF_NOSHADOW;
988 buffs_BuffModel_Remove(player);
990 player.effects &= ~(EF_NOSHADOW);
994 if(player.buff_model)
996 player.buff_model.effects = player.effects;
997 player.buff_model.effects |= EF_LOWPRECISION;
998 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
1000 player.buff_model.alpha = player.alpha;
1007 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
1009 entity player = M_ARGV(0, entity);
1011 if(StatusEffects_active(BUFF_MEDIC, player))
1013 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
1014 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
1015 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
1018 if(StatusEffects_active(BUFF_SPEED, player))
1019 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
1022 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1024 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1026 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
1027 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1030 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1032 if(autocvar_g_buffs > 0)
1033 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1036 void buffs_DelayedInit(entity this)
1038 if(autocvar_g_buffs_spawn_count > 0)
1039 if(find(NULL, classname, "item_buff") == NULL)
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
1052 void buffs_Initialize()
1054 // if buffs are above 0, allow random spawning
1055 if(autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0)
1056 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);