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 entity frag_attacker = M_ARGV(1, entity);
567 entity frag_target = M_ARGV(2, entity);
568 if(!StatusEffects_active(BUFF_VAMPIRE, frag_attacker))
570 float health_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
572 if(time >= frag_target.spawnshieldtime &&
573 frag_target != frag_attacker &&
574 IS_PLAYER(frag_attacker) &&
575 !IS_DEAD(frag_target) && !STAT(FROZEN, frag_target))
577 GiveResource(frag_attacker, RES_HEALTH,
578 autocvar_g_buffs_vampire_damage_steal * health_take);
582 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
584 entity player = M_ARGV(0, entity);
586 buffs_BuffModel_Remove(player);
587 player.oldbuffs = NULL;
588 // reset timers here to prevent them continuing after re-spawn
589 player.buff_disability_time = 0;
590 player.buff_disability_effect_time = 0;
593 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
595 entity player = M_ARGV(0, entity);
596 // these automatically reset, no need to worry
598 if(StatusEffects_active(BUFF_SPEED, player))
599 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
601 if(time < player.buff_disability_time)
602 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
605 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
607 entity player = M_ARGV(0, entity);
608 // these automatically reset, no need to worry
610 if(StatusEffects_active(BUFF_JUMP, player))
611 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
614 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
616 entity mon = M_ARGV(0, entity);
618 if(time < mon.buff_disability_time)
620 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
621 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
625 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
627 entity frag_target = M_ARGV(2, entity);
629 entity heldbuff = buff_FirstFromFlags(frag_target);
632 int buffid = heldbuff.m_id;
633 if(!IS_INDEPENDENT_PLAYER(frag_target))
634 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
636 buffs_BuffModel_Remove(frag_target);
640 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
642 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
644 entity player = M_ARGV(0, entity);
646 entity heldbuff = buff_FirstFromFlags(player);
649 int buffid = heldbuff.m_id;
650 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
651 if(!IS_INDEPENDENT_PLAYER(player))
652 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
654 buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
655 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
656 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
661 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
663 if(MUTATOR_RETURNVALUE || game_stopped) return;
664 entity player = M_ARGV(0, entity);
666 if(StatusEffects_active(BUFF_SWAPPER, player))
668 float best_distance = autocvar_g_buffs_swapper_range;
669 entity closest = NULL;
670 FOREACH_CLIENT(IS_PLAYER(it), {
671 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
672 if(DIFF_TEAM(it, player))
674 float test = vlen2(player.origin - it.origin);
675 if(test <= best_distance * best_distance)
677 best_distance = sqrt(test);
685 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
687 my_org = player.origin;
688 my_vel = player.velocity;
689 my_ang = player.angles;
690 their_org = closest.origin;
691 their_vel = closest.velocity;
692 their_ang = closest.angles;
694 Drop_Special_Items(closest);
696 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
698 setorigin(player, their_org);
699 setorigin(closest, my_org);
701 closest.velocity = my_vel;
702 closest.angles = my_ang;
703 if (IS_BOT_CLIENT(closest))
705 closest.v_angle = closest.angles;
706 bot_aim_reset(closest);
708 closest.fixangle = true;
709 closest.oldorigin = my_org;
710 closest.oldvelocity = my_vel;
711 player.velocity = their_vel;
712 player.angles = their_ang;
713 if (IS_BOT_CLIENT(player))
715 player.v_angle = player.angles;
716 bot_aim_reset(player);
718 player.fixangle = true;
719 player.oldorigin = their_org;
720 player.oldvelocity = their_vel;
722 // set pusher so player gets the kill if they fall into void
723 closest.pusher = player;
724 closest.pushltime = time + autocvar_g_maxpushtime;
725 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
727 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
728 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
730 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
731 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
733 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
734 buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
740 bool buffs_RemovePlayer(entity player)
742 buffs_BuffModel_Remove(player);
744 // also reset timers here to prevent them continuing after spectating
745 player.buff_disability_time = 0;
746 player.buff_disability_effect_time = 0;
750 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
751 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
753 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
755 entity wp = M_ARGV(0, entity);
756 entity player = M_ARGV(1, entity);
758 entity e = WaypointSprite_getviewentity(player);
760 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
761 // but only apply this to real players, not to spectators
762 if((wp.owner.flags & FL_CLIENT) && (e == player) && StatusEffects_active(BUFF_INVISIBLE, wp.owner))
763 if(DIFF_TEAM(wp.owner, e))
767 MUTATOR_HOOKFUNCTION(buffs, FilterItem)
769 if(autocvar_g_buffs < 0)
770 return false; // no auto replacing of entities in this mode
772 entity item = M_ARGV(0, entity);
774 if(autocvar_g_buffs_replace_powerups)
776 switch(item.classname)
778 case "item_strength":
782 buff_SpawnReplacement(e, item);
791 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
793 entity player = M_ARGV(1, entity);
795 if(StatusEffects_active(BUFF_SPEED, player))
796 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
798 if(time < player.buff_disability_time)
799 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
802 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
804 entity player = M_ARGV(1, entity);
806 if(StatusEffects_active(BUFF_SPEED, player))
807 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
809 if(time < player.buff_disability_time)
810 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
813 .bool buff_flight_crouchheld;
815 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
817 entity player = M_ARGV(0, entity);
819 if(game_stopped || IS_DEAD(player) || !IS_PLAYER(player)) return;
821 if(StatusEffects_active(BUFF_FLIGHT, player))
823 if(!PHYS_INPUT_BUTTON_CROUCH(player))
824 player.buff_flight_crouchheld = false;
825 else if(!player.buff_flight_crouchheld)
827 player.buff_flight_crouchheld = true;
828 player.gravity *= -1;
832 if(time < player.buff_disability_time)
833 if(time >= player.buff_disability_effect_time)
835 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
836 player.buff_disability_effect_time = time + 0.5;
839 // handle buff lost status
840 // 1: notify everyone else
841 // 2: notify carrier as well
844 entity heldbuff = buff_FirstFromFlags(player);
845 float bufftime = StatusEffects_gettime(heldbuff, player);
846 if(heldbuff && bufftime && time >= bufftime)
849 if(STAT(FROZEN, player)) { buff_lost = 1; }
851 if(buff_lost && heldbuff)
853 int buffid = heldbuff.m_id;
856 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
857 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
859 else if(!IS_INDEPENDENT_PLAYER(player))
860 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
861 buff_RemoveAll(player, STATUSEFFECT_REMOVE_TIMEOUT); // TODO: remove only the currently active buff?
863 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
866 if(StatusEffects_active(BUFF_MAGNET, player))
869 IL_EACH(g_items, it.itemdef,
872 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
874 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
876 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
879 gettouch(it)(it, player);
884 if(StatusEffects_active(BUFF_AMMO, player))
886 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
888 .entity weaponentity = weaponentities[slot];
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;
894 if(!player.vehicle && StatusEffects_active(BUFF_INVISIBLE, player) && player.oldbuffs == BUFF_INVISIBLE)
895 player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
897 #define BUFF_ONADD(b) if ( (heldbuff == (b)) && (player.oldbuffs != (b)))
898 #define BUFF_ONREM(b) if ( (heldbuff != (b)) && (player.oldbuffs == (b)))
900 if(heldbuff != player.oldbuffs)
902 bufftime = heldbuff ? heldbuff.m_time(heldbuff) : 0;
903 if(StatusEffects_gettime(heldbuff, player) <= time) // if the player still has a buff countdown, don't reset it!
905 player.statuseffects.statuseffect_time[heldbuff.m_id] = (bufftime) ? time + bufftime : 0;
906 StatusEffects_update(player);
909 BUFF_ONADD(BUFF_AMMO)
911 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_AMMO);
912 player.items |= IT_UNLIMITED_AMMO;
914 if(StatusEffects_active(BUFF_AMMO, player))
916 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
918 .entity weaponentity = weaponentities[slot];
919 if(player.(weaponentity).clip_load)
920 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
921 if(player.(weaponentity).clip_size)
922 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
927 BUFF_ONREM(BUFF_AMMO)
929 if(player.buff_ammo_prev_infitems)
930 player.items |= IT_UNLIMITED_AMMO;
932 player.items &= ~IT_UNLIMITED_AMMO;
934 if(StatusEffects_active(BUFF_AMMO, player))
936 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
938 .entity weaponentity = weaponentities[slot];
939 if(player.(weaponentity).buff_ammo_prev_clipload)
940 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
945 BUFF_ONADD(BUFF_INVISIBLE)
947 if(StatusEffects_active(STATUSEFFECT_Strength, player) && MUTATOR_IS_ENABLED(mutator_instagib))
948 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
950 player.buff_invisible_prev_alpha = player.alpha;
952 player.alpha = autocvar_g_buffs_invisible_alpha;
955 BUFF_ONREM(BUFF_INVISIBLE)
959 if(StatusEffects_active(STATUSEFFECT_Strength, player) && MUTATOR_IS_ENABLED(mutator_instagib))
960 player.alpha = autocvar_g_instagib_invis_alpha;
962 player.alpha = player.buff_invisible_prev_alpha;
966 BUFF_ONADD(BUFF_FLIGHT)
968 player.buff_flight_oldgravity = player.gravity;
973 BUFF_ONREM(BUFF_FLIGHT)
974 player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
976 player.oldbuffs = heldbuff;
979 if(!player.buff_model)
980 buffs_BuffModel_Spawn(player);
982 player.buff_model.color = heldbuff.m_color;
983 player.buff_model.glowmod = buff_GlowColor(heldbuff);
984 player.buff_model.skin = heldbuff.m_skin;
986 player.effects |= EF_NOSHADOW;
990 buffs_BuffModel_Remove(player);
992 player.effects &= ~(EF_NOSHADOW);
996 if(player.buff_model)
998 player.buff_model.effects = player.effects;
999 player.buff_model.effects |= EF_LOWPRECISION;
1000 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
1002 player.buff_model.alpha = player.alpha;
1009 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
1011 entity player = M_ARGV(0, entity);
1013 if(StatusEffects_active(BUFF_MEDIC, player))
1015 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
1016 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
1017 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
1020 if(StatusEffects_active(BUFF_SPEED, player))
1021 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
1024 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1026 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1028 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
1029 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1032 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1034 if(autocvar_g_buffs > 0)
1035 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1038 void buffs_DelayedInit(entity this)
1040 if(autocvar_g_buffs_spawn_count > 0)
1041 if(find(NULL, classname, "item_buff") == NULL)
1044 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1047 e.spawnflags |= 64; // always randomize
1048 e.velocity = randomvec() * 250; // this gets reset anyway if random location works
1054 void buffs_Initialize()
1056 // if buffs are above 0, allow random spawning
1057 if(autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0)
1058 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);