3 #include <common/triggers/target/music.qh>
4 #include <common/gamemodes/_mod.qh>
6 .float buff_time = _STAT(BUFF_TIME);
7 void buffs_DelayedInit(entity this);
9 AUTOCVAR(g_buffs, int, -1, "Enable buffs, -1: enabled but no auto location or replacing powerups, 1: enabled and can replace them");
11 REGISTER_MUTATOR(buffs, autocvar_g_buffs)
15 if(autocvar_g_buffs > 0)
16 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
20 bool buffs_BuffModel_Customize(entity this, entity client)
22 entity player, myowner;
25 player = WaypointSprite_getviewentity(client);
27 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
29 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
32 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
35 if(player == myowner || (IS_SPEC(client) && client.enemy == myowner))
37 // somewhat hide the model, but keep the glow
43 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
49 void buffs_BuffModel_Spawn(entity player)
51 player.buff_model = spawn();
52 setmodel(player.buff_model, MDL_BUFF);
53 setsize(player.buff_model, '0 0 -40', '0 0 40');
54 setattachment(player.buff_model, player, "");
55 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
56 player.buff_model.owner = player;
57 player.buff_model.scale = 0.7;
58 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
59 player.buff_model.light_lev = 200;
60 setcefc(player.buff_model, buffs_BuffModel_Customize);
63 vector buff_GlowColor(entity buff)
65 //if(buff.team) { return Team_ColorRGB(buff.team); }
69 void buff_Effect(entity player, string eff)
71 if(!autocvar_g_buffs_effects) { return; }
73 if(time >= player.buff_effect_delay)
75 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
76 player.buff_effect_delay = time + 0.05; // prevent spam
81 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
83 if(!this.owner.buff_active && !this.owner.buff_activetime)
88 return view.cvar_cl_buffs_autoreplace == false || view.buffs != this.owner.buffs;
91 return WaypointSprite_visible_for_player(this, player, view);
94 void buff_Waypoint_Spawn(entity e)
96 entity buff = buff_FirstFromFlags(e.buffs);
97 entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, NULL, e.team, e, buff_waypoint, true, RADARICON_Buff);
98 wp.wp_extra = buff.m_id;
99 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
100 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
103 void buff_SetCooldown(entity this, float cd)
107 if(!this.buff_waypoint)
108 buff_Waypoint_Spawn(this);
110 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
111 this.buff_activetime = cd;
112 this.buff_active = !cd;
115 void buff_Respawn(entity this)
117 if(game_stopped) return;
119 vector oldbufforigin = this.origin;
120 this.velocity = '0 0 200';
122 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
123 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
125 entity spot = SelectSpawnPoint(this, true);
126 setorigin(this, spot.origin);
127 this.velocity = ((randomvec() * 100) + '0 0 200');
128 this.angles = spot.angles;
131 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
133 setorigin(this, trace_endpos); // attempt to unstick
135 set_movetype(this, MOVETYPE_TOSS);
137 makevectors(this.angles);
138 this.angles = '0 0 0';
139 if(autocvar_g_buffs_random_lifetime > 0)
140 this.lifetime = time + autocvar_g_buffs_random_lifetime;
142 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
143 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
145 WaypointSprite_Ping(this.buff_waypoint);
147 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
150 void buff_Touch(entity this, entity toucher)
152 if(game_stopped) return;
154 if(ITEM_TOUCH_NEEDKILL())
160 if((this.team && DIFF_TEAM(toucher, this))
161 || (STAT(FROZEN, toucher))
163 || (time < toucher.buff_shield)
164 || (!this.buff_active)
171 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
173 toucher = M_ARGV(1, entity);
175 if(!IS_PLAYER(toucher))
176 return; // incase mutator changed toucher
180 if (toucher.cvar_cl_buffs_autoreplace && toucher.buffs != this.buffs)
182 int buffid = buff_FirstFromFlags(toucher.buffs).m_id;
183 //Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, toucher.buffs);
184 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
187 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
189 else { return; } // do nothing
192 this.owner = toucher;
193 this.buff_active = false;
195 int buffid = buff_FirstFromFlags(this.buffs).m_id;
196 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, buffid);
197 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, buffid);
199 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
200 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
201 toucher.buffs |= (this.buffs);
204 float buff_Available(entity buff)
206 if (buff == BUFF_Null)
208 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
210 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
212 return cvar(strcat("g_buffs_", buff.m_name));
217 void buff_NewType(entity ent)
219 RandomSelection_Init();
220 FOREACH(Buffs, buff_Available(it),
222 // if it's already been chosen, give it a lower priority
223 RandomSelection_AddEnt(it, max(0.2, 1 / it.buff_seencount), 1);
225 entity newbuff = RandomSelection_chosen_ent;
226 newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
227 ent.buffs = newbuff.m_itemid;
230 void buff_Think(entity this)
232 if(this.buffs != this.oldbuffs)
234 entity buff = buff_FirstFromFlags(this.buffs);
235 this.color = buff.m_color;
236 this.glowmod = buff_GlowColor(buff);
237 this.skin = buff.m_skin;
239 setmodel(this, MDL_BUFF);
240 setsize(this, BUFF_MIN, BUFF_MAX);
242 if(this.buff_waypoint)
244 //WaypointSprite_Disown(this.buff_waypoint, 1);
245 WaypointSprite_Kill(this.buff_waypoint);
246 buff_Waypoint_Spawn(this);
247 if(this.buff_activetime)
248 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
251 this.oldbuffs = this.buffs;
255 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
256 if(!this.buff_activetime_updated)
258 buff_SetCooldown(this, this.buff_activetime);
259 this.buff_activetime_updated = true;
262 if(!this.buff_active && !this.buff_activetime)
263 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle || !(this.owner.buffs & this.buffs) || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway))
265 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
267 if(autocvar_g_buffs_randomize)
270 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
274 if(this.buff_activetime)
276 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
278 this.buff_activetime = max(0, this.buff_activetime - frametime);
280 if(!this.buff_activetime)
282 this.buff_active = true;
283 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
284 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
290 if(this.team && !this.buff_waypoint)
291 buff_Waypoint_Spawn(this);
294 if(time >= this.lifetime)
298 this.nextthink = time;
299 //this.angles_y = time * 110.1;
302 void buff_Waypoint_Reset(entity this)
304 WaypointSprite_Kill(this.buff_waypoint);
306 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
309 void buff_Reset(entity this)
311 if(autocvar_g_buffs_randomize)
314 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
315 buff_Waypoint_Reset(this);
316 this.buff_activetime_updated = false;
318 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
322 bool buff_Customize(entity this, entity client)
324 entity player = WaypointSprite_getviewentity(client);
325 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
328 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
334 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
335 this.light_lev = 220 + 36 * sin(time);
336 this.pflags = PFLAGS_FULLDYNAMIC;
341 void buff_Init(entity this)
343 if(!cvar("g_buffs")) { delete(this); return; }
345 if(!teamplay && this.team) { this.team = 0; }
347 entity buff = buff_FirstFromFlags(this.buffs);
349 if(!this.buffs || !buff_Available(buff))
352 this.classname = "item_buff";
353 this.solid = SOLID_TRIGGER;
354 this.flags = FL_ITEM;
355 this.bot_pickup = true;
356 this.bot_pickupevalfunc = generic_pickupevalfunc;
357 this.bot_pickupbasevalue = 1000;
358 IL_PUSH(g_items, this);
359 setthink(this, buff_Think);
360 settouch(this, buff_Touch);
361 this.reset = buff_Reset;
362 this.nextthink = time + 0.1;
364 set_movetype(this, MOVETYPE_TOSS);
366 this.skin = buff.m_skin;
367 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
368 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
369 setcefc(this, buff_Customize);
370 //this.gravity = 100;
371 this.color = buff.m_color;
372 this.glowmod = buff_GlowColor(this);
373 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
374 this.buff_active = !this.buff_activetime;
375 this.pflags = PFLAGS_FULLDYNAMIC;
377 if(this.spawnflags & 1)
381 set_movetype(this, MOVETYPE_NONE); // reset by random location
383 setmodel(this, MDL_BUFF);
384 setsize(this, BUFF_MIN, BUFF_MAX);
386 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
390 void buff_Init_Compat(entity ent, entity replacement)
392 if (ent.spawnflags & 2)
393 ent.team = NUM_TEAM_1;
394 else if (ent.spawnflags & 4)
395 ent.team = NUM_TEAM_2;
397 ent.buffs = replacement.m_itemid;
402 void buff_SpawnReplacement(entity ent, entity old)
404 setorigin(ent, old.origin);
405 ent.angles = old.angles;
406 ent.noalign = (old.noalign || (old.spawnflags & 1));
411 void buff_Vengeance_DelayedDamage(entity this)
414 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0');
420 // note: only really useful in teamplay
421 void buff_Medic_Heal(entity this)
423 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
425 if(SAME_TEAM(it, this))
426 if(it.health < autocvar_g_balance_health_regenstable)
428 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
429 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
434 float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
436 return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
440 MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
442 entity frag_attacker = M_ARGV(1, entity);
443 entity frag_target = M_ARGV(2, entity);
444 float frag_deathtype = M_ARGV(3, float);
445 float frag_damage = M_ARGV(4, float);
446 vector frag_force = M_ARGV(6, vector);
448 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
450 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
452 float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent;
453 frag_damage = bound(0, frag_damage - reduced, frag_damage);
456 if(frag_target.buffs & BUFF_SPEED.m_itemid)
457 if(frag_target != frag_attacker)
458 frag_damage *= autocvar_g_buffs_speed_damage_take;
460 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
461 if((frag_target.health - frag_damage) <= 0)
462 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
464 if(random() <= autocvar_g_buffs_medic_survive_chance)
465 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
467 if(frag_target.buffs & BUFF_JUMP.m_itemid)
468 if(frag_deathtype == DEATH_FALL.m_id)
471 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
473 if(frag_attacker != frag_target)
474 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
476 entity dmgent = spawn();
478 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
479 dmgent.enemy = frag_attacker;
480 dmgent.owner = frag_target;
481 setthink(dmgent, buff_Vengeance_DelayedDamage);
482 dmgent.nextthink = time + 0.1;
485 if(frag_target.buffs & BUFF_BASH.m_itemid)
486 if(frag_attacker != frag_target)
487 frag_force = '0 0 0';
489 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
491 if(frag_attacker == frag_target)
492 frag_force *= autocvar_g_buffs_bash_force_self;
494 frag_force *= autocvar_g_buffs_bash_force;
496 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
497 if(frag_target != frag_attacker)
498 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
500 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
502 if(frag_deathtype == DEATH_FIRE.m_id)
504 if(frag_deathtype == DEATH_LAVA.m_id)
505 frag_damage *= 0.5; // TODO: cvarize?
508 if(frag_attacker.buffs & BUFF_LUCK.m_itemid)
509 if(frag_attacker != frag_target)
510 if(autocvar_g_buffs_luck_damagemultiplier > 0)
511 if(random() <= autocvar_g_buffs_luck_chance)
512 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
514 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
515 if(frag_target != frag_attacker) {
516 float btime = buff_Inferno_CalculateTime(
519 autocvar_g_buffs_inferno_burntime_min_time,
520 autocvar_g_buffs_inferno_burntime_target_damage,
521 autocvar_g_buffs_inferno_burntime_target_time,
522 autocvar_g_buffs_inferno_burntime_factor
524 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
527 // this... is ridiculous (TODO: fix!)
528 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
529 if(!frag_target.vehicle)
530 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
531 if(!IS_DEAD(frag_target))
532 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
533 if(frag_attacker != frag_target)
534 if(!STAT(FROZEN, frag_target))
535 if(frag_target.takedamage)
536 if(DIFF_TEAM(frag_attacker, frag_target))
538 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);
539 if(frag_target.armorvalue)
540 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);
543 M_ARGV(4, float) = frag_damage;
544 M_ARGV(6, vector) = frag_force;
547 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
549 entity player = M_ARGV(0, entity);
552 player.buff_time = 0;
553 player.buff_shield = time + 0.5; // prevent picking up buffs immediately
554 // reset timers here to prevent them continuing after re-spawn
555 player.buff_disability_time = 0;
556 player.buff_disability_effect_time = 0;
559 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
561 entity player = M_ARGV(0, entity);
562 // these automatically reset, no need to worry
564 if(player.buffs & BUFF_SPEED.m_itemid)
565 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
567 if(time < player.buff_disability_time)
568 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
571 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
573 entity player = M_ARGV(0, entity);
574 // these automatically reset, no need to worry
576 if(player.buffs & BUFF_JUMP.m_itemid)
577 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
580 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
582 entity mon = M_ARGV(0, entity);
584 if(time < mon.buff_disability_time)
586 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
587 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
591 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
593 entity frag_target = M_ARGV(2, entity);
595 if(frag_target.buffs)
597 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
598 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
599 frag_target.buffs = 0;
601 if(frag_target.buff_model)
603 delete(frag_target.buff_model);
604 frag_target.buff_model = NULL;
609 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
611 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
613 entity player = M_ARGV(0, entity);
617 int buffid = buff_FirstFromFlags(player.buffs).m_id;
618 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
619 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
622 player.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
623 //player.buff_time = 0; // already notified
624 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
629 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
631 if(MUTATOR_RETURNVALUE || game_stopped) return;
632 entity player = M_ARGV(0, entity);
634 if(player.buffs & BUFF_SWAPPER.m_itemid)
636 float best_distance = autocvar_g_buffs_swapper_range;
637 entity closest = NULL;
638 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
639 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
640 if(DIFF_TEAM(it, player))
642 float test = vlen2(player.origin - it.origin);
643 if(test <= best_distance * best_distance)
645 best_distance = sqrt(test);
653 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
655 my_org = player.origin;
656 my_vel = player.velocity;
657 my_ang = player.angles;
658 their_org = closest.origin;
659 their_vel = closest.velocity;
660 their_ang = closest.angles;
662 Drop_Special_Items(closest);
664 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
666 setorigin(player, their_org);
667 setorigin(closest, my_org);
669 closest.velocity = my_vel;
670 closest.angles = my_ang;
671 closest.fixangle = true;
672 closest.oldorigin = my_org;
673 closest.oldvelocity = my_vel;
674 player.velocity = their_vel;
675 player.angles = their_ang;
676 player.fixangle = true;
677 player.oldorigin = their_org;
678 player.oldvelocity = their_vel;
680 // set pusher so player gets the kill if they fall into void
681 closest.pusher = player;
682 closest.pushltime = time + autocvar_g_maxpushtime;
683 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
685 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
686 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
688 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
689 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
691 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
698 bool buffs_RemovePlayer(entity player)
700 if(player.buff_model)
702 delete(player.buff_model);
703 player.buff_model = NULL;
706 // also reset timers here to prevent them continuing after spectating
707 player.buff_disability_time = 0;
708 player.buff_disability_effect_time = 0;
712 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
713 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
715 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
717 entity wp = M_ARGV(0, entity);
718 entity player = M_ARGV(1, entity);
720 entity e = WaypointSprite_getviewentity(player);
722 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
723 // but only apply this to real players, not to spectators
724 if((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player))
725 if(DIFF_TEAM(wp.owner, e))
729 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
731 if(autocvar_g_buffs < 0)
732 return; // no auto replacing of entities in this mode
734 entity ent = M_ARGV(0, entity);
736 if(autocvar_g_buffs_replace_powerups)
737 switch(ent.classname)
739 case "item_strength":
740 case "item_invincible":
743 buff_SpawnReplacement(e, ent);
749 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
751 entity player = M_ARGV(1, entity);
753 if(player.buffs & BUFF_SPEED.m_itemid)
754 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
756 if(time < player.buff_disability_time)
757 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
760 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
762 entity player = M_ARGV(1, entity);
764 if(player.buffs & BUFF_SPEED.m_itemid)
765 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
767 if(time < player.buff_disability_time)
768 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
771 .bool buff_flight_crouchheld;
773 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
775 entity player = M_ARGV(0, entity);
777 if(game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) return;
779 if(player.buffs & BUFF_FLIGHT.m_itemid)
781 if(!PHYS_INPUT_BUTTON_CROUCH(player))
782 player.buff_flight_crouchheld = false;
783 else if(!player.buff_flight_crouchheld)
785 player.buff_flight_crouchheld = true;
786 player.gravity *= -1;
790 if(time < player.buff_disability_time)
791 if(time >= player.buff_disability_effect_time)
793 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
794 player.buff_disability_effect_time = time + 0.5;
797 // handle buff lost status
798 // 1: notify everyone else
799 // 2: notify carrier as well
802 if(player.buff_time && player.buffs)
803 if(time >= player.buff_time)
805 player.buff_time = 0;
809 if(STAT(FROZEN, player)) { buff_lost = 1; }
815 int buffid = buff_FirstFromFlags(player.buffs).m_id;
818 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
819 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
822 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
824 player.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
828 if(player.buffs & BUFF_MAGNET.m_itemid)
831 IL_EACH(g_items, it.itemdef,
834 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
836 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
838 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
841 gettouch(it)(it, player);
846 if(player.buffs & BUFF_AMMO.m_itemid)
848 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
850 .entity weaponentity = weaponentities[slot];
851 if(player.(weaponentity).clip_size)
852 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
856 if((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
857 player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
859 if(player.buffs & BUFF_MEDIC.m_itemid)
860 if(time >= player.buff_medic_healtime)
862 buff_Medic_Heal(player);
863 player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
866 #define BUFF_ONADD(b) if ( (player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
867 #define BUFF_ONREM(b) if (!(player.buffs & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
869 if(player.buffs != player.oldbuffs)
871 entity buff = buff_FirstFromFlags(player.buffs);
872 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
873 player.buff_time = (bufftime) ? time + bufftime : 0;
875 BUFF_ONADD(BUFF_AMMO)
877 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO);
878 player.items |= IT_UNLIMITED_WEAPON_AMMO;
880 if(player.buffs & BUFF_AMMO.m_itemid)
882 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
884 .entity weaponentity = weaponentities[slot];
885 if(player.(weaponentity).clip_load)
886 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
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;
893 BUFF_ONREM(BUFF_AMMO)
895 if(player.buff_ammo_prev_infitems)
896 player.items |= IT_UNLIMITED_WEAPON_AMMO;
898 player.items &= ~IT_UNLIMITED_WEAPON_AMMO;
900 if(player.buffs & BUFF_AMMO.m_itemid)
902 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
904 .entity weaponentity = weaponentities[slot];
905 if(player.(weaponentity).buff_ammo_prev_clipload)
906 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
911 BUFF_ONADD(BUFF_INVISIBLE)
913 if(time < player.strength_finished && g_instagib)
914 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
916 player.buff_invisible_prev_alpha = player.alpha;
917 player.alpha = autocvar_g_buffs_invisible_alpha;
920 BUFF_ONREM(BUFF_INVISIBLE)
922 if(time < player.strength_finished && g_instagib)
923 player.alpha = autocvar_g_instagib_invis_alpha;
925 player.alpha = player.buff_invisible_prev_alpha;
928 BUFF_ONADD(BUFF_FLIGHT)
930 player.buff_flight_oldgravity = player.gravity;
935 BUFF_ONREM(BUFF_FLIGHT)
936 player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
938 player.oldbuffs = player.buffs;
941 if(!player.buff_model)
942 buffs_BuffModel_Spawn(player);
944 player.buff_model.color = buff.m_color;
945 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
946 player.buff_model.skin = buff.m_skin;
948 player.effects |= EF_NOSHADOW;
952 if(player.buff_model)
953 delete(player.buff_model);
954 player.buff_model = NULL;
956 player.effects &= ~(EF_NOSHADOW);
960 if(player.buff_model)
962 player.buff_model.effects = player.effects;
963 player.buff_model.effects |= EF_LOWPRECISION;
964 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
966 player.buff_model.alpha = player.alpha;
973 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
975 entity spectatee = M_ARGV(0, entity);
976 entity client = M_ARGV(1, entity);
978 client.buffs = spectatee.buffs;
979 client.buff_time = spectatee.buff_time;
982 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
984 entity player = M_ARGV(0, entity);
986 if(player.buffs & BUFF_MEDIC.m_itemid)
988 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
989 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
990 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
993 if(player.buffs & BUFF_SPEED.m_itemid)
994 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
997 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
999 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1001 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
1002 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1005 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1007 if(autocvar_g_buffs > 0)
1008 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1011 void buffs_DelayedInit(entity this)
1013 if(autocvar_g_buffs_spawn_count > 0)
1014 if(find(NULL, classname, "item_buff") == NULL)
1017 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1020 e.spawnflags |= 64; // always randomize
1021 e.velocity = randomvec() * 250; // this gets reset anyway if random location works