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 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
13 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
17 bool buffs_BuffModel_Customize(entity this, entity client)
19 entity player, myowner;
22 player = WaypointSprite_getviewentity(client);
24 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
26 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
29 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
32 if(player == myowner || (IS_SPEC(client) && client.enemy == myowner))
34 // somewhat hide the model, but keep the glow
40 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
46 void buffs_BuffModel_Spawn(entity player)
48 player.buff_model = spawn();
49 setmodel(player.buff_model, MDL_BUFF);
50 setsize(player.buff_model, '0 0 -40', '0 0 40');
51 setattachment(player.buff_model, player, "");
52 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
53 player.buff_model.owner = player;
54 player.buff_model.scale = 0.7;
55 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
56 player.buff_model.light_lev = 200;
57 setcefc(player.buff_model, buffs_BuffModel_Customize);
60 vector buff_GlowColor(entity buff)
62 //if(buff.team) { return Team_ColorRGB(buff.team); }
66 void buff_Effect(entity player, string eff)
68 if(!autocvar_g_buffs_effects) { return; }
70 if(time >= player.buff_effect_delay)
72 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
73 player.buff_effect_delay = time + 0.05; // prevent spam
78 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
80 if(!this.owner.buff_active && !this.owner.buff_activetime)
85 return view.cvar_cl_buffs_autoreplace == false || view.buffs != this.owner.buffs;
88 return WaypointSprite_visible_for_player(this, player, view);
91 void buff_Waypoint_Spawn(entity e)
93 entity buff = buff_FirstFromFlags(e.buffs);
94 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);
95 wp.wp_extra = buff.m_id;
96 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
97 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
100 void buff_SetCooldown(entity this, float cd)
104 if(!this.buff_waypoint)
105 buff_Waypoint_Spawn(this);
107 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
108 this.buff_activetime = cd;
109 this.buff_active = !cd;
112 void buff_Respawn(entity this)
114 if(gameover) { return; }
116 vector oldbufforigin = this.origin;
117 this.velocity = '0 0 200';
119 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
120 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
122 entity spot = SelectSpawnPoint(this, true);
123 setorigin(this, spot.origin);
124 this.velocity = ((randomvec() * 100) + '0 0 200');
125 this.angles = spot.angles;
128 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
130 setorigin(this, trace_endpos); // attempt to unstick
132 set_movetype(this, MOVETYPE_TOSS);
134 makevectors(this.angles);
135 this.angles = '0 0 0';
136 if(autocvar_g_buffs_random_lifetime > 0)
137 this.lifetime = time + autocvar_g_buffs_random_lifetime;
139 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
140 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
142 WaypointSprite_Ping(this.buff_waypoint);
144 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
147 void buff_Touch(entity this, entity toucher)
149 if(gameover) { return; }
151 if(ITEM_TOUCH_NEEDKILL())
157 if((this.team && DIFF_TEAM(toucher, this))
158 || (STAT(FROZEN, toucher))
160 || (!this.buff_active)
167 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
169 toucher = M_ARGV(1, entity);
171 if(!IS_PLAYER(toucher))
172 return; // incase mutator changed toucher
176 if (toucher.cvar_cl_buffs_autoreplace && toucher.buffs != this.buffs)
178 int buffid = buff_FirstFromFlags(toucher.buffs).m_id;
179 //Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, toucher.buffs);
180 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
183 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
185 else { return; } // do nothing
188 this.owner = toucher;
189 this.buff_active = false;
191 int buffid = buff_FirstFromFlags(this.buffs).m_id;
192 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, buffid);
193 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, buffid);
195 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
196 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
197 toucher.buffs |= (this.buffs);
200 float buff_Available(entity buff)
202 if (buff == BUFF_Null)
204 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
206 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
208 return cvar(strcat("g_buffs_", buff.m_name));
213 void buff_NewType(entity ent, float cb)
215 RandomSelection_Init();
216 FOREACH(Buffs, buff_Available(it), LAMBDA(
217 it.buff_seencount += 1;
218 // if it's already been chosen, give it a lower priority
219 RandomSelection_Add(NULL, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
221 ent.buffs = RandomSelection_chosen_float;
224 void buff_Think(entity this)
226 if(this.buffs != this.oldbuffs)
228 entity buff = buff_FirstFromFlags(this.buffs);
229 this.color = buff.m_color;
230 this.glowmod = buff_GlowColor(buff);
231 this.skin = buff.m_skin;
233 setmodel(this, MDL_BUFF);
235 if(this.buff_waypoint)
237 //WaypointSprite_Disown(this.buff_waypoint, 1);
238 WaypointSprite_Kill(this.buff_waypoint);
239 buff_Waypoint_Spawn(this);
240 if(this.buff_activetime)
241 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
244 this.oldbuffs = this.buffs;
248 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
249 if(!this.buff_activetime_updated)
251 buff_SetCooldown(this, this.buff_activetime);
252 this.buff_activetime_updated = true;
255 if(!this.buff_active && !this.buff_activetime)
256 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || !(this.owner.buffs & this.buffs))
258 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
260 if(autocvar_g_buffs_randomize)
261 buff_NewType(this, this.buffs);
263 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
267 if(this.buff_activetime)
269 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
271 this.buff_activetime = max(0, this.buff_activetime - frametime);
273 if(!this.buff_activetime)
275 this.buff_active = true;
276 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
277 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
283 if(this.team && !this.buff_waypoint)
284 buff_Waypoint_Spawn(this);
287 if(time >= this.lifetime)
291 this.nextthink = time;
292 //this.angles_y = time * 110.1;
295 void buff_Waypoint_Reset(entity this)
297 WaypointSprite_Kill(this.buff_waypoint);
299 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
302 void buff_Reset(entity this)
304 if(autocvar_g_buffs_randomize)
305 buff_NewType(this, this.buffs);
307 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
308 buff_Waypoint_Reset(this);
309 this.buff_activetime_updated = false;
311 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
315 bool buff_Customize(entity this, entity client)
317 entity player = WaypointSprite_getviewentity(client);
318 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
321 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
327 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
328 this.light_lev = 220 + 36 * sin(time);
329 this.pflags = PFLAGS_FULLDYNAMIC;
334 void buff_Init(entity this)
336 if(!cvar("g_buffs")) { delete(this); return; }
338 if(!teamplay && this.team) { this.team = 0; }
340 entity buff = buff_FirstFromFlags(this.buffs);
342 if(!this.buffs || buff_Available(buff))
343 buff_NewType(this, 0);
345 this.classname = "item_buff";
346 this.solid = SOLID_TRIGGER;
347 this.flags = FL_ITEM;
348 setthink(this, buff_Think);
349 settouch(this, buff_Touch);
350 this.reset = buff_Reset;
351 this.nextthink = time + 0.1;
353 set_movetype(this, MOVETYPE_TOSS);
355 this.skin = buff.m_skin;
356 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
357 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
358 setcefc(this, buff_Customize);
359 //this.gravity = 100;
360 this.color = buff.m_color;
361 this.glowmod = buff_GlowColor(this);
362 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + game_starttime);
363 this.buff_active = !this.buff_activetime;
364 this.pflags = PFLAGS_FULLDYNAMIC;
366 if(this.spawnflags & 1)
370 set_movetype(this, MOVETYPE_NONE); // reset by random location
372 setmodel(this, MDL_BUFF);
373 setsize(this, BUFF_MIN, BUFF_MAX);
375 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
379 void buff_Init_Compat(entity ent, entity replacement)
381 if (ent.spawnflags & 2)
382 ent.team = NUM_TEAM_1;
383 else if (ent.spawnflags & 4)
384 ent.team = NUM_TEAM_2;
386 ent.buffs = replacement.m_itemid;
391 void buff_SpawnReplacement(entity ent, entity old)
393 setorigin(ent, old.origin);
394 ent.angles = old.angles;
395 ent.noalign = (old.noalign || (old.spawnflags & 1));
400 void buff_Vengeance_DelayedDamage(entity this)
403 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0');
409 // note: only really useful in teamplay
410 void buff_Medic_Heal(entity this)
412 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
414 if(SAME_TEAM(it, this))
415 if(it.health < autocvar_g_balance_health_regenstable)
417 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
418 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
423 float buff_Inferno_CalculateTime(float x, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
425 return offset_y + (intersect_y - offset_y) * logn(((x - offset_x) * ((base - 1) / intersect_x)) + 1, base);
429 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
431 entity frag_target = M_ARGV(2, entity);
432 float frag_deathtype = M_ARGV(6, float);
433 float frag_damage = M_ARGV(7, float);
435 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
437 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
439 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
440 M_ARGV(4, float) = v.x; // take
441 M_ARGV(5, float) = v.y; // save
445 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
447 entity frag_attacker = M_ARGV(1, entity);
448 entity frag_target = M_ARGV(2, entity);
449 float frag_deathtype = M_ARGV(3, float);
450 float frag_damage = M_ARGV(4, float);
451 vector frag_force = M_ARGV(6, vector);
453 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
455 if(frag_target.buffs & BUFF_SPEED.m_itemid)
456 if(frag_target != frag_attacker)
457 frag_damage *= autocvar_g_buffs_speed_damage_take;
459 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
460 if((frag_target.health - frag_damage) <= 0)
461 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
463 if(random() <= autocvar_g_buffs_medic_survive_chance)
464 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
466 if(frag_target.buffs & BUFF_JUMP.m_itemid)
467 if(frag_deathtype == DEATH_FALL.m_id)
470 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
472 if(frag_attacker != frag_target)
473 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
475 entity dmgent = spawn();
477 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
478 dmgent.enemy = frag_attacker;
479 dmgent.owner = frag_target;
480 setthink(dmgent, buff_Vengeance_DelayedDamage);
481 dmgent.nextthink = time + 0.1;
484 if(frag_target.buffs & BUFF_BASH.m_itemid)
485 if(frag_attacker != frag_target)
486 frag_force = '0 0 0';
488 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
490 if(frag_attacker == frag_target)
491 frag_force *= autocvar_g_buffs_bash_force_self;
493 frag_force *= autocvar_g_buffs_bash_force;
495 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
496 if(frag_target != frag_attacker)
497 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
499 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
501 if(frag_deathtype == DEATH_FIRE.m_id)
503 if(frag_deathtype == DEATH_LAVA.m_id)
504 frag_damage *= 0.5; // TODO: cvarize?
507 if(frag_attacker.buffs & BUFF_LUCK.m_itemid)
508 if(frag_attacker != frag_target)
509 if(autocvar_g_buffs_luck_damagemultiplier > 0)
510 if(random() <= autocvar_g_buffs_luck_chance)
511 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
513 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
514 if(frag_target != frag_attacker) {
515 float btime = buff_Inferno_CalculateTime(
518 autocvar_g_buffs_inferno_burntime_min_time,
519 autocvar_g_buffs_inferno_burntime_target_damage,
520 autocvar_g_buffs_inferno_burntime_target_time,
521 autocvar_g_buffs_inferno_burntime_factor
523 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
526 // this... is ridiculous (TODO: fix!)
527 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
528 if(!frag_target.vehicle)
529 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
530 if(!IS_DEAD(frag_target))
531 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
532 if(frag_attacker != frag_target)
533 if(!STAT(FROZEN, frag_target))
534 if(frag_target.takedamage)
535 if(DIFF_TEAM(frag_attacker, frag_target))
537 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);
538 if(frag_target.armorvalue)
539 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);
542 M_ARGV(4, float) = frag_damage;
543 M_ARGV(6, vector) = frag_force;
546 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
548 entity player = M_ARGV(0, entity);
551 player.buff_time = 0;
552 // reset timers here to prevent them continuing after re-spawn
553 player.buff_disability_time = 0;
554 player.buff_disability_effect_time = 0;
557 .float stat_sv_maxspeed;
558 .float stat_sv_airspeedlimit_nonqw;
559 .float stat_sv_jumpvelocity;
561 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
563 entity player = M_ARGV(0, entity);
565 if(player.buffs & BUFF_SPEED.m_itemid)
567 player.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
568 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
571 if(time < player.buff_disability_time)
573 player.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
574 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
577 if(player.buffs & BUFF_JUMP.m_itemid)
579 // automatically reset, no need to worry
580 player.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
584 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
586 entity player = M_ARGV(0, entity);
588 if(player.buffs & BUFF_JUMP.m_itemid)
589 M_ARGV(1, float) = 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(frag_target.buffs)
609 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
610 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
611 frag_target.buffs = 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 || gameover) { return; }
625 entity player = M_ARGV(0, entity);
629 int buffid = buff_FirstFromFlags(player.buffs).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);
634 player.buff_time = 0; // already notified
635 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
640 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
642 if(MUTATOR_RETURNVALUE || gameover) { return; }
643 entity player = M_ARGV(0, entity);
645 if(player.buffs & BUFF_SWAPPER.m_itemid)
647 float best_distance = autocvar_g_buffs_swapper_range;
648 entity closest = NULL;
649 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
650 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
651 if(DIFF_TEAM(it, player))
653 float test = vlen2(player.origin - it.origin);
654 if(test <= best_distance * best_distance)
656 best_distance = sqrt(test);
664 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
666 my_org = player.origin;
667 my_vel = player.velocity;
668 my_ang = player.angles;
669 their_org = closest.origin;
670 their_vel = closest.velocity;
671 their_ang = closest.angles;
673 Drop_Special_Items(closest);
675 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
677 setorigin(player, their_org);
678 setorigin(closest, my_org);
680 closest.velocity = my_vel;
681 closest.angles = my_ang;
682 closest.fixangle = true;
683 closest.oldorigin = my_org;
684 closest.oldvelocity = my_vel;
685 player.velocity = their_vel;
686 player.angles = their_ang;
687 player.fixangle = true;
688 player.oldorigin = their_org;
689 player.oldvelocity = their_vel;
691 // set pusher so player gets the kill if they fall into void
692 closest.pusher = player;
693 closest.pushltime = time + autocvar_g_maxpushtime;
694 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
696 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
697 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
699 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
700 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
702 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
709 bool buffs_RemovePlayer(entity player)
711 if(player.buff_model)
713 delete(player.buff_model);
714 player.buff_model = NULL;
717 // also reset timers here to prevent them continuing after spectating
718 player.buff_disability_time = 0;
719 player.buff_disability_effect_time = 0;
723 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
724 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
726 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
728 entity wp = M_ARGV(0, entity);
729 entity player = M_ARGV(1, entity);
731 entity e = WaypointSprite_getviewentity(player);
733 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
734 // but only apply this to real players, not to spectators
735 if((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player))
736 if(DIFF_TEAM(wp.owner, e))
740 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
742 entity ent = M_ARGV(0, entity);
744 if(autocvar_g_buffs_replace_powerups)
745 switch(ent.classname)
747 case "item_strength":
748 case "item_invincible":
751 buff_SpawnReplacement(e, ent);
757 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
759 entity player = M_ARGV(1, entity);
761 if(player.buffs & BUFF_SPEED.m_itemid)
762 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
764 if(time < player.buff_disability_time)
765 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
768 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
770 entity player = M_ARGV(1, entity);
772 if(player.buffs & BUFF_SPEED.m_itemid)
773 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
775 if(time < player.buff_disability_time)
776 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
779 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
781 entity player = M_ARGV(0, entity);
783 if(gameover || IS_DEAD(player)) { return; }
785 if(time < player.buff_disability_time)
786 if(time >= player.buff_disability_effect_time)
788 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
789 player.buff_disability_effect_time = time + 0.5;
792 // handle buff lost status
793 // 1: notify everyone else
794 // 2: notify carrier as well
797 if(player.buff_time && player.buffs)
798 if(time >= player.buff_time)
800 player.buff_time = 0;
804 if(STAT(FROZEN, player)) { buff_lost = 1; }
810 int buffid = buff_FirstFromFlags(player.buffs).m_id;
813 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
814 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
817 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
822 if(player.buffs & BUFF_MAGNET.m_itemid)
825 FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
828 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
830 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
832 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
835 gettouch(it)(it, player);
840 if(player.buffs & BUFF_AMMO.m_itemid)
842 player.clip_load = player.(weapon_load[PS(player).m_switchweapon.m_id]) = player.clip_size;
844 if((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
845 if(player.alpha != autocvar_g_buffs_invisible_alpha)
846 player.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
848 if(player.buffs & BUFF_MEDIC.m_itemid)
849 if(time >= player.buff_medic_healtime)
851 buff_Medic_Heal(player);
852 player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
855 #define BUFF_ONADD(b) if ( (player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
856 #define BUFF_ONREM(b) if (!(player.buffs & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
858 if(player.buffs != player.oldbuffs)
860 entity buff = buff_FirstFromFlags(player.buffs);
861 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
862 player.buff_time = (bufftime) ? time + bufftime : 0;
864 BUFF_ONADD(BUFF_AMMO)
866 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO);
867 player.items |= IT_UNLIMITED_WEAPON_AMMO;
870 player.buff_ammo_prev_clipload = player.clip_load;
871 player.clip_load = player.(weapon_load[PS(player).m_switchweapon.m_id]) = player.clip_size;
874 BUFF_ONREM(BUFF_AMMO)
876 if(player.buff_ammo_prev_infitems)
877 player.items |= IT_UNLIMITED_WEAPON_AMMO;
879 player.items &= ~IT_UNLIMITED_WEAPON_AMMO;
881 if(player.buff_ammo_prev_clipload)
882 player.clip_load = player.buff_ammo_prev_clipload;
885 BUFF_ONADD(BUFF_INVISIBLE)
887 if(time < player.strength_finished && g_instagib)
888 player.alpha = autocvar_g_instagib_invis_alpha;
890 player.alpha = player.buff_invisible_prev_alpha;
891 player.alpha = autocvar_g_buffs_invisible_alpha;
894 BUFF_ONREM(BUFF_INVISIBLE)
895 player.alpha = player.buff_invisible_prev_alpha;
897 player.oldbuffs = player.buffs;
900 if(!player.buff_model)
901 buffs_BuffModel_Spawn(player);
903 player.buff_model.color = buff.m_color;
904 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
905 player.buff_model.skin = buff.m_skin;
907 player.effects |= EF_NOSHADOW;
911 delete(player.buff_model);
912 player.buff_model = NULL;
914 player.effects &= ~(EF_NOSHADOW);
918 if(player.buff_model)
920 player.buff_model.effects = player.effects;
921 player.buff_model.effects |= EF_LOWPRECISION;
922 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
924 player.buff_model.alpha = player.alpha;
931 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
933 entity spectatee = M_ARGV(0, entity);
934 entity client = M_ARGV(1, entity);
936 client.buffs = spectatee.buffs;
939 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
941 entity player = M_ARGV(0, entity);
942 entity veh = M_ARGV(1, entity);
944 veh.buffs = player.buffs;
946 veh.buff_time = max(0, player.buff_time - time);
947 player.buff_time = 0;
950 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
952 entity player = M_ARGV(0, entity);
953 entity veh = M_ARGV(1, entity);
955 player.buffs = player.oldbuffs = veh.buffs;
957 player.buff_time = time + veh.buff_time;
961 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
963 entity player = M_ARGV(0, entity);
965 if(player.buffs & BUFF_MEDIC.m_itemid)
967 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
968 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
969 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
972 if(player.buffs & BUFF_SPEED.m_itemid)
973 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
976 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
978 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
980 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
983 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
985 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
988 void buffs_DelayedInit(entity this)
990 if(autocvar_g_buffs_spawn_count > 0)
991 if(find(NULL, classname, "item_buff") == NULL)
994 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
997 e.spawnflags |= 64; // always randomize
998 e.velocity = randomvec() * 250; // this gets reset anyway if random location works