3 #include <common/triggers/target/music.qh>
4 #include <common/gamemodes/_mod.qh>
6 void buffs_DelayedInit(entity this);
8 AUTOCVAR(g_buffs, int, -1, "Enable buffs, -1: enabled but no auto location or replacing powerups, 1: enabled and can replace them");
10 REGISTER_MUTATOR(buffs, autocvar_g_buffs)
14 if(autocvar_g_buffs > 0)
15 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
19 bool buffs_BuffModel_Customize(entity this, entity client)
21 entity player, myowner;
24 player = WaypointSprite_getviewentity(client);
26 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
28 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
31 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
34 if(player == myowner || (IS_SPEC(client) && client.enemy == myowner))
36 // somewhat hide the model, but keep the glow
42 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
48 void buffs_BuffModel_Spawn(entity player)
50 player.buff_model = spawn();
51 setmodel(player.buff_model, MDL_BUFF);
52 setsize(player.buff_model, '0 0 -40', '0 0 40');
53 setattachment(player.buff_model, player, "");
54 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
55 player.buff_model.owner = player;
56 player.buff_model.scale = 0.7;
57 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
58 player.buff_model.light_lev = 200;
59 setcefc(player.buff_model, buffs_BuffModel_Customize);
62 vector buff_GlowColor(entity buff)
64 //if(buff.team) { return Team_ColorRGB(buff.team); }
68 void buff_Effect(entity player, string eff)
70 if(!autocvar_g_buffs_effects) { return; }
72 if(time >= player.buff_effect_delay)
74 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
75 player.buff_effect_delay = time + 0.05; // prevent spam
80 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
82 if(!this.owner.buff_active && !this.owner.buff_activetime)
85 if (STAT(BUFFS, view))
87 return CS(view).cvar_cl_buffs_autoreplace == false || STAT(BUFFS, view) != STAT(BUFFS, this.owner);
90 return WaypointSprite_visible_for_player(this, player, view);
93 void buff_Waypoint_Spawn(entity e)
95 entity buff = buff_FirstFromFlags(STAT(BUFFS, e));
96 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);
97 wp.wp_extra = buff.m_id;
98 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
99 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
102 void buff_SetCooldown(entity this, float cd)
106 if(!this.buff_waypoint)
107 buff_Waypoint_Spawn(this);
109 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
110 this.buff_activetime = cd;
111 this.buff_active = !cd;
114 void buff_Respawn(entity this)
116 if(game_stopped) return;
118 vector oldbufforigin = this.origin;
119 this.velocity = '0 0 200';
121 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
122 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
124 entity spot = SelectSpawnPoint(this, true);
125 setorigin(this, spot.origin);
126 this.velocity = ((randomvec() * 100) + '0 0 200');
127 this.angles = spot.angles;
130 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
132 setorigin(this, trace_endpos); // attempt to unstick
134 set_movetype(this, MOVETYPE_TOSS);
136 makevectors(this.angles);
137 this.angles = '0 0 0';
138 if(autocvar_g_buffs_random_lifetime > 0)
139 this.lifetime = time + autocvar_g_buffs_random_lifetime;
141 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
142 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
144 WaypointSprite_Ping(this.buff_waypoint);
146 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
149 void buff_Touch(entity this, entity toucher)
151 if(game_stopped) return;
153 if(ITEM_TOUCH_NEEDKILL())
159 if(!this.buff_active)
162 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
164 toucher = M_ARGV(1, entity);
166 if(!IS_PLAYER(toucher))
167 return; // incase mutator changed toucher
169 if((this.team && DIFF_TEAM(toucher, this))
170 || (STAT(FROZEN, toucher))
172 || (time < PS(toucher).buff_shield)
179 if (STAT(BUFFS, toucher))
181 if (CS(toucher).cvar_cl_buffs_autoreplace && STAT(BUFFS, toucher) != STAT(BUFFS, this))
183 int buffid = buff_FirstFromFlags(STAT(BUFFS, toucher)).m_id;
184 //Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, STAT(BUFFS, toucher));
185 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
187 STAT(BUFFS, toucher) = 0;
188 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
190 else { return; } // do nothing
193 this.owner = toucher;
194 this.buff_active = false;
196 int buffid = buff_FirstFromFlags(STAT(BUFFS, this)).m_id;
197 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, buffid);
198 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, buffid);
200 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
201 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
202 STAT(BUFFS, toucher) |= (STAT(BUFFS, this));
205 float buff_Available(entity buff)
207 if (buff == BUFF_Null)
209 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
211 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
213 return cvar(strcat("g_buffs_", buff.m_name));
218 void buff_NewType(entity ent)
220 RandomSelection_Init();
221 FOREACH(Buffs, buff_Available(it),
223 // if it's already been chosen, give it a lower priority
224 RandomSelection_AddEnt(it, max(0.2, 1 / it.buff_seencount), 1);
226 entity newbuff = RandomSelection_chosen_ent;
227 newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
228 STAT(BUFFS, ent) = newbuff.m_itemid;
231 void buff_Think(entity this)
233 if(STAT(BUFFS, this) != this.oldbuffs)
235 entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
236 this.color = buff.m_color;
237 this.glowmod = buff_GlowColor(buff);
238 this.skin = buff.m_skin;
240 setmodel(this, MDL_BUFF);
241 setsize(this, BUFF_MIN, BUFF_MAX);
243 if(this.buff_waypoint)
245 //WaypointSprite_Disown(this.buff_waypoint, 1);
246 WaypointSprite_Kill(this.buff_waypoint);
247 buff_Waypoint_Spawn(this);
248 if(this.buff_activetime)
249 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
252 this.oldbuffs = STAT(BUFFS, this);
256 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
257 if(!this.buff_activetime_updated)
259 buff_SetCooldown(this, this.buff_activetime);
260 this.buff_activetime_updated = true;
263 if(!this.buff_active && !this.buff_activetime)
264 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle || !(STAT(BUFFS, this.owner) & STAT(BUFFS, this)) || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway))
266 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
268 if(autocvar_g_buffs_randomize)
271 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
275 if(this.buff_activetime)
277 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
279 this.buff_activetime = max(0, this.buff_activetime - frametime);
281 if(!this.buff_activetime)
283 this.buff_active = true;
284 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
285 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
291 if(this.team && !this.buff_waypoint)
292 buff_Waypoint_Spawn(this);
295 if(time >= this.lifetime)
299 this.nextthink = time;
300 //this.angles_y = time * 110.1;
303 void buff_Waypoint_Reset(entity this)
305 WaypointSprite_Kill(this.buff_waypoint);
307 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
310 void buff_Reset(entity this)
312 if(autocvar_g_buffs_randomize)
315 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
316 buff_Waypoint_Reset(this);
317 this.buff_activetime_updated = false;
319 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
323 bool buff_Customize(entity this, entity client)
325 entity player = WaypointSprite_getviewentity(client);
326 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
329 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
335 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
336 this.light_lev = 220 + 36 * sin(time);
337 this.pflags = PFLAGS_FULLDYNAMIC;
342 void buff_Init(entity this)
344 if(!cvar("g_buffs")) { delete(this); return; }
346 if(!teamplay && this.team) { this.team = 0; }
348 entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
350 if(!STAT(BUFFS, this) || !buff_Available(buff))
353 this.classname = "item_buff";
354 this.solid = SOLID_TRIGGER;
355 this.flags = FL_ITEM;
356 this.bot_pickup = true;
357 this.bot_pickupevalfunc = generic_pickupevalfunc;
358 this.bot_pickupbasevalue = 1000;
359 IL_PUSH(g_items, this);
360 setthink(this, buff_Think);
361 settouch(this, buff_Touch);
362 this.reset = buff_Reset;
363 this.nextthink = time + 0.1;
365 set_movetype(this, MOVETYPE_TOSS);
367 this.skin = buff.m_skin;
368 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
369 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
370 setcefc(this, buff_Customize);
371 //this.gravity = 100;
372 this.color = buff.m_color;
373 this.glowmod = buff_GlowColor(this);
374 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
375 this.buff_active = !this.buff_activetime;
376 this.pflags = PFLAGS_FULLDYNAMIC;
378 if(this.spawnflags & 1)
382 set_movetype(this, MOVETYPE_NONE); // reset by random location
384 setmodel(this, MDL_BUFF);
385 setsize(this, BUFF_MIN, BUFF_MAX);
387 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
391 void buff_Init_Compat(entity ent, entity replacement)
393 if (ent.spawnflags & 2)
394 ent.team = NUM_TEAM_1;
395 else if (ent.spawnflags & 4)
396 ent.team = NUM_TEAM_2;
398 STAT(BUFFS, ent) = replacement.m_itemid;
403 void buff_SpawnReplacement(entity ent, entity old)
405 setorigin(ent, old.origin);
406 ent.angles = old.angles;
407 ent.noalign = Item_ShouldKeepPosition(old);
412 void buff_Vengeance_DelayedDamage(entity this)
415 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, DMG_NOWEP, this.enemy.origin, '0 0 0');
421 // note: only really useful in teamplay
422 void buff_Medic_Heal(entity this)
424 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
426 if (!SAME_TEAM(it, this))
430 float hp = GetResourceAmount(it, RESOURCE_HEALTH);
431 if(hp >= autocvar_g_balance_health_regenstable)
435 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
436 SetResourceAmount(it, RESOURCE_HEALTH, bound(0, hp + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable));
440 float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
442 return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
446 MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
448 entity frag_attacker = M_ARGV(1, entity);
449 entity frag_target = M_ARGV(2, entity);
450 float frag_deathtype = M_ARGV(3, float);
451 float frag_damage = M_ARGV(4, float);
452 vector frag_force = M_ARGV(6, vector);
454 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
456 if(STAT(BUFFS, frag_target) & BUFF_RESISTANCE.m_itemid)
458 float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent;
459 frag_damage = bound(0, frag_damage - reduced, frag_damage);
462 if(STAT(BUFFS, frag_target) & BUFF_SPEED.m_itemid)
463 if(frag_target != frag_attacker)
464 frag_damage *= autocvar_g_buffs_speed_damage_take;
466 if(STAT(BUFFS, frag_target) & BUFF_MEDIC.m_itemid)
467 if((GetResourceAmount(frag_target, RESOURCE_HEALTH) - frag_damage) <= 0)
468 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
470 if(random() <= autocvar_g_buffs_medic_survive_chance)
471 frag_damage = max(5, GetResourceAmount(frag_target, RESOURCE_HEALTH) - autocvar_g_buffs_medic_survive_health);
473 if(STAT(BUFFS, frag_target) & BUFF_JUMP.m_itemid)
474 if(frag_deathtype == DEATH_FALL.m_id)
477 if(STAT(BUFFS, frag_target) & BUFF_VENGEANCE.m_itemid)
479 if(frag_attacker != frag_target)
480 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
482 entity dmgent = spawn();
484 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
485 dmgent.enemy = frag_attacker;
486 dmgent.owner = frag_target;
487 setthink(dmgent, buff_Vengeance_DelayedDamage);
488 dmgent.nextthink = time + 0.1;
491 if(STAT(BUFFS, frag_target) & BUFF_BASH.m_itemid)
492 if(frag_attacker != frag_target)
493 frag_force = '0 0 0';
495 if(STAT(BUFFS, frag_attacker) & BUFF_BASH.m_itemid)
497 if(frag_attacker == frag_target)
498 frag_force *= autocvar_g_buffs_bash_force_self;
500 frag_force *= autocvar_g_buffs_bash_force;
502 if(STAT(BUFFS, frag_attacker) & BUFF_DISABILITY.m_itemid)
503 if(frag_target != frag_attacker)
504 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
506 if(STAT(BUFFS, frag_target) & BUFF_INFERNO.m_itemid)
508 if(frag_deathtype == DEATH_FIRE.m_id)
510 if(frag_deathtype == DEATH_LAVA.m_id)
511 frag_damage *= 0.5; // TODO: cvarize?
514 if(STAT(BUFFS, frag_attacker) & BUFF_LUCK.m_itemid)
515 if(frag_attacker != frag_target)
516 if(autocvar_g_buffs_luck_damagemultiplier > 0)
517 if(random() <= autocvar_g_buffs_luck_chance)
518 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
520 if(STAT(BUFFS, frag_attacker) & BUFF_INFERNO.m_itemid)
521 if(frag_target != frag_attacker) {
522 float btime = buff_Inferno_CalculateTime(
525 autocvar_g_buffs_inferno_burntime_min_time,
526 autocvar_g_buffs_inferno_burntime_target_damage,
527 autocvar_g_buffs_inferno_burntime_target_time,
528 autocvar_g_buffs_inferno_burntime_factor
530 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
533 // this... is ridiculous (TODO: fix!)
534 if(STAT(BUFFS, frag_attacker) & BUFF_VAMPIRE.m_itemid)
535 if(!frag_target.vehicle)
536 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
537 if(!IS_DEAD(frag_target))
538 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
539 if(frag_attacker != frag_target)
540 if(!STAT(FROZEN, frag_target))
541 if(frag_target.takedamage)
542 if(DIFF_TEAM(frag_attacker, frag_target))
544 float amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal,
545 GetResourceAmount(frag_target, RESOURCE_HEALTH));
546 GiveResourceWithLimit(frag_attacker, RESOURCE_HEALTH, amount, g_pickup_healthsmall_max);
547 if (frag_target.armorvalue)
549 amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal,
550 GetResourceAmount(frag_target, RESOURCE_ARMOR));
551 GiveResourceWithLimit(frag_attacker, RESOURCE_ARMOR, amount, g_pickup_armorsmall_max);
555 M_ARGV(4, float) = frag_damage;
556 M_ARGV(6, vector) = frag_force;
559 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
561 entity player = M_ARGV(0, entity);
563 STAT(BUFFS, player) = 0;
564 STAT(BUFF_TIME, player) = 0;
565 PS(player).buff_shield = time + 0.5; // prevent picking up buffs immediately
566 // reset timers here to prevent them continuing after re-spawn
567 player.buff_disability_time = 0;
568 player.buff_disability_effect_time = 0;
571 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
573 entity player = M_ARGV(0, entity);
574 // these automatically reset, no need to worry
576 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
577 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
579 if(time < player.buff_disability_time)
580 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
583 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
585 entity player = M_ARGV(0, entity);
586 // these automatically reset, no need to worry
588 if(STAT(BUFFS, player) & BUFF_JUMP.m_itemid)
589 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
592 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
594 entity mon = M_ARGV(0, entity);
596 if(time < mon.buff_disability_time)
598 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
599 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
603 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
605 entity frag_target = M_ARGV(2, entity);
607 if(STAT(BUFFS, frag_target))
609 int buffid = buff_FirstFromFlags(STAT(BUFFS, frag_target)).m_id;
610 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
611 STAT(BUFFS, frag_target) = 0;
613 if(frag_target.buff_model)
615 delete(frag_target.buff_model);
616 frag_target.buff_model = NULL;
621 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
623 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
625 entity player = M_ARGV(0, entity);
627 if(STAT(BUFFS, player))
629 int buffid = buff_FirstFromFlags(STAT(BUFFS, player)).m_id;
630 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
631 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
633 STAT(BUFFS, player) = 0;
634 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
635 //STAT(BUFF_TIME, player) = 0; // already notified
636 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
641 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
643 if(MUTATOR_RETURNVALUE || game_stopped) return;
644 entity player = M_ARGV(0, entity);
646 if(STAT(BUFFS, player) & BUFF_SWAPPER.m_itemid)
648 float best_distance = autocvar_g_buffs_swapper_range;
649 entity closest = NULL;
650 FOREACH_CLIENT(IS_PLAYER(it), {
651 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
652 if(DIFF_TEAM(it, player))
654 float test = vlen2(player.origin - it.origin);
655 if(test <= best_distance * best_distance)
657 best_distance = sqrt(test);
665 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
667 my_org = player.origin;
668 my_vel = player.velocity;
669 my_ang = player.angles;
670 their_org = closest.origin;
671 their_vel = closest.velocity;
672 their_ang = closest.angles;
674 Drop_Special_Items(closest);
676 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
678 setorigin(player, their_org);
679 setorigin(closest, my_org);
681 closest.velocity = my_vel;
682 closest.angles = my_ang;
683 closest.fixangle = true;
684 closest.oldorigin = my_org;
685 closest.oldvelocity = my_vel;
686 player.velocity = their_vel;
687 player.angles = their_ang;
688 player.fixangle = true;
689 player.oldorigin = their_org;
690 player.oldvelocity = their_vel;
692 // set pusher so player gets the kill if they fall into void
693 closest.pusher = player;
694 closest.pushltime = time + autocvar_g_maxpushtime;
695 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
697 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
698 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
700 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
701 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
703 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
704 STAT(BUFFS, player) = 0;
710 bool buffs_RemovePlayer(entity player)
712 if(player.buff_model)
714 delete(player.buff_model);
715 player.buff_model = NULL;
718 // also reset timers here to prevent them continuing after spectating
719 player.buff_disability_time = 0;
720 player.buff_disability_effect_time = 0;
724 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
725 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
727 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
729 entity wp = M_ARGV(0, entity);
730 entity player = M_ARGV(1, entity);
732 entity e = WaypointSprite_getviewentity(player);
734 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
735 // but only apply this to real players, not to spectators
736 if((wp.owner.flags & FL_CLIENT) && (STAT(BUFFS, wp.owner) & BUFF_INVISIBLE.m_itemid) && (e == player))
737 if(DIFF_TEAM(wp.owner, e))
741 MUTATOR_HOOKFUNCTION(buffs, FilterItem)
743 if(autocvar_g_buffs < 0)
744 return false; // no auto replacing of entities in this mode
746 entity item = M_ARGV(0, entity);
748 if(autocvar_g_buffs_replace_powerups)
750 switch(item.classname)
752 case "item_strength":
756 buff_SpawnReplacement(e, item);
765 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
767 entity player = M_ARGV(1, entity);
769 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
770 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
772 if(time < player.buff_disability_time)
773 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
776 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
778 entity player = M_ARGV(1, entity);
780 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
781 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
783 if(time < player.buff_disability_time)
784 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
787 .bool buff_flight_crouchheld;
789 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
791 entity player = M_ARGV(0, entity);
793 if(game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) return;
795 if(STAT(BUFFS, player) & BUFF_FLIGHT.m_itemid)
797 if(!PHYS_INPUT_BUTTON_CROUCH(player))
798 player.buff_flight_crouchheld = false;
799 else if(!player.buff_flight_crouchheld)
801 player.buff_flight_crouchheld = true;
802 player.gravity *= -1;
806 if(time < player.buff_disability_time)
807 if(time >= player.buff_disability_effect_time)
809 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
810 player.buff_disability_effect_time = time + 0.5;
813 // handle buff lost status
814 // 1: notify everyone else
815 // 2: notify carrier as well
818 if(STAT(BUFF_TIME, player) && STAT(BUFFS, player))
819 if(time >= STAT(BUFF_TIME, player))
821 STAT(BUFF_TIME, player) = 0;
825 if(STAT(FROZEN, player)) { buff_lost = 1; }
829 if(STAT(BUFFS, player))
831 int buffid = buff_FirstFromFlags(STAT(BUFFS, player)).m_id;
834 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
835 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
838 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
839 STAT(BUFFS, player) = 0;
840 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
844 if(STAT(BUFFS, player) & BUFF_MAGNET.m_itemid)
847 IL_EACH(g_items, it.itemdef,
850 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
852 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
854 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
857 gettouch(it)(it, player);
862 if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
864 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
866 .entity weaponentity = weaponentities[slot];
867 if(player.(weaponentity).clip_size)
868 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
872 if((STAT(BUFFS, player) & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
873 player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
875 if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid)
876 if(time >= player.buff_medic_healtime)
878 buff_Medic_Heal(player);
879 player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
882 #define BUFF_ONADD(b) if ( (STAT(BUFFS, player) & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
883 #define BUFF_ONREM(b) if (!(STAT(BUFFS, player) & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
885 if(STAT(BUFFS, player) != player.oldbuffs)
887 entity buff = buff_FirstFromFlags(STAT(BUFFS, player));
888 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
889 STAT(BUFF_TIME, player) = (bufftime) ? time + bufftime : 0;
891 BUFF_ONADD(BUFF_AMMO)
893 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO);
894 player.items |= IT_UNLIMITED_WEAPON_AMMO;
896 if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
898 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
900 .entity weaponentity = weaponentities[slot];
901 if(player.(weaponentity).clip_load)
902 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
903 if(player.(weaponentity).clip_size)
904 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
909 BUFF_ONREM(BUFF_AMMO)
911 if(player.buff_ammo_prev_infitems)
912 player.items |= IT_UNLIMITED_WEAPON_AMMO;
914 player.items &= ~IT_UNLIMITED_WEAPON_AMMO;
916 if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
918 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
920 .entity weaponentity = weaponentities[slot];
921 if(player.(weaponentity).buff_ammo_prev_clipload)
922 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
927 BUFF_ONADD(BUFF_INVISIBLE)
929 if(time < player.strength_finished && autocvar_g_instagib)
930 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
932 player.buff_invisible_prev_alpha = player.alpha;
933 player.alpha = autocvar_g_buffs_invisible_alpha;
936 BUFF_ONREM(BUFF_INVISIBLE)
938 if(time < player.strength_finished && autocvar_g_instagib)
939 player.alpha = autocvar_g_instagib_invis_alpha;
941 player.alpha = player.buff_invisible_prev_alpha;
944 BUFF_ONADD(BUFF_FLIGHT)
946 player.buff_flight_oldgravity = player.gravity;
951 BUFF_ONREM(BUFF_FLIGHT)
952 player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
954 player.oldbuffs = STAT(BUFFS, player);
955 if(STAT(BUFFS, player))
957 if(!player.buff_model)
958 buffs_BuffModel_Spawn(player);
960 player.buff_model.color = buff.m_color;
961 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
962 player.buff_model.skin = buff.m_skin;
964 player.effects |= EF_NOSHADOW;
968 if(player.buff_model)
969 delete(player.buff_model);
970 player.buff_model = NULL;
972 player.effects &= ~(EF_NOSHADOW);
976 if(player.buff_model)
978 player.buff_model.effects = player.effects;
979 player.buff_model.effects |= EF_LOWPRECISION;
980 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
982 player.buff_model.alpha = player.alpha;
989 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
991 entity spectatee = M_ARGV(0, entity);
992 entity client = M_ARGV(1, entity);
994 STAT(BUFFS, client) = STAT(BUFFS, spectatee);
995 STAT(BUFF_TIME, client) = STAT(BUFF_TIME, spectatee);
998 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
1000 entity player = M_ARGV(0, entity);
1002 if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid)
1004 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
1005 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
1006 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
1009 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
1010 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
1013 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1015 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1017 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
1018 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1021 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1023 if(autocvar_g_buffs > 0)
1024 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1027 void buffs_DelayedInit(entity this)
1029 if(autocvar_g_buffs_spawn_count > 0)
1030 if(find(NULL, classname, "item_buff") == NULL)
1033 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1036 e.spawnflags |= 64; // always randomize
1037 e.velocity = randomvec() * 250; // this gets reset anyway if random location works