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)
77 if (STAT(BUFFS, view))
79 return CS_CVAR(view).cvar_cl_buffs_autoreplace == false || STAT(BUFFS, view) != STAT(BUFFS, this.owner);
82 return WaypointSprite_visible_for_player(this, player, view);
85 void buff_Waypoint_Spawn(entity e)
87 if(autocvar_g_buffs_waypoint_distance <= 0) return;
89 entity buff = buff_FirstFromFlags(STAT(BUFFS, e));
90 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);
91 wp.wp_extra = buff.m_id;
92 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
93 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
96 void buff_SetCooldown(entity this, float cd)
100 if(!this.buff_waypoint)
101 buff_Waypoint_Spawn(this);
103 if(this.buff_waypoint)
104 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
106 this.buff_activetime = cd;
107 this.buff_active = !cd;
110 void buff_Respawn(entity this)
112 if(game_stopped) return;
114 vector oldbufforigin = this.origin;
115 this.velocity = '0 0 200';
117 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
118 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
120 entity spot = SelectSpawnPoint(this, true);
121 setorigin(this, spot.origin);
122 this.velocity = ((randomvec() * 100) + '0 0 200');
123 this.angles = spot.angles;
126 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
128 setorigin(this, trace_endpos); // attempt to unstick
130 set_movetype(this, MOVETYPE_TOSS);
132 makevectors(this.angles);
133 this.angles = '0 0 0';
134 if(autocvar_g_buffs_random_lifetime > 0)
135 this.lifetime = time + autocvar_g_buffs_random_lifetime;
137 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
138 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
140 WaypointSprite_Ping(this.buff_waypoint);
142 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
145 void buff_Touch(entity this, entity toucher)
147 if(game_stopped) return;
149 if(ITEM_TOUCH_NEEDKILL())
155 if(!this.buff_active)
158 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
160 toucher = M_ARGV(1, entity);
162 if(!IS_PLAYER(toucher))
163 return; // incase mutator changed toucher
165 if((this.team && DIFF_TEAM(toucher, this))
166 || (STAT(FROZEN, toucher))
168 || (time < PS(toucher).buff_shield)
175 if (STAT(BUFFS, toucher))
177 if (CS_CVAR(toucher).cvar_cl_buffs_autoreplace && STAT(BUFFS, toucher) != STAT(BUFFS, this))
179 // TODO: lost-gained notification for this case
180 int buffid = buff_FirstFromFlags(STAT(BUFFS, toucher)).m_id;
181 Send_Notification(NOTIF_ONE, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
182 if(!IS_INDEPENDENT_PLAYER(toucher))
183 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
185 STAT(BUFFS, toucher) = 0;
186 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
188 else { return; } // do nothing
191 this.owner = toucher;
192 this.buff_active = false;
194 entity thebuff = buff_FirstFromFlags(STAT(BUFFS, this));
195 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, thebuff.m_id);
196 if(!IS_INDEPENDENT_PLAYER(toucher))
197 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, thebuff.m_id);
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 STAT(BUFFS, toucher) |= (STAT(BUFFS, this));
202 STAT(LAST_PICKUP, toucher) = time;
203 float bufftime = ((this.count) ? this.count : thebuff.m_time(thebuff));
205 STAT(BUFF_TIME, toucher) = min(time + bufftime, max(STAT(BUFF_TIME, toucher), time) + bufftime);
208 float buff_Available(entity buff)
210 if (buff == BUFF_Null)
212 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_AMMO) || cvar("g_melee_only")))
214 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
216 return cvar(strcat("g_buffs_", buff.netname));
221 void buff_NewType(entity ent)
223 RandomSelection_Init();
224 FOREACH(Buffs, buff_Available(it),
226 // if it's already been chosen, give it a lower priority
227 float myseencount = (it.buff_seencount > 0) ? it.buff_seencount : 1; // no division by zero please!
228 RandomSelection_AddEnt(it, max(0.2, 1 / myseencount), 1);
230 entity newbuff = RandomSelection_chosen_ent;
231 newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
232 STAT(BUFFS, ent) = newbuff.m_itemid;
235 void buff_Think(entity this)
237 if(this.buff_waypoint && autocvar_g_buffs_waypoint_distance <= 0)
238 WaypointSprite_Kill(this.buff_waypoint);
240 if(STAT(BUFFS, this) != this.oldbuffs)
242 entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
243 this.color = buff.m_color;
244 this.glowmod = buff_GlowColor(buff);
245 this.skin = buff.m_skin;
247 setmodel(this, MDL_BUFF);
248 setsize(this, BUFF_MIN, BUFF_MAX);
250 if(this.buff_waypoint)
252 //WaypointSprite_Disown(this.buff_waypoint, 1);
253 WaypointSprite_Kill(this.buff_waypoint);
254 buff_Waypoint_Spawn(this);
255 if(this.buff_activetime)
256 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
259 this.oldbuffs = STAT(BUFFS, this);
263 if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
264 if(!this.buff_activetime_updated)
266 buff_SetCooldown(this, this.buff_activetime);
267 this.buff_activetime_updated = true;
270 if(!this.buff_active && !this.buff_activetime)
271 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))
273 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
275 if(autocvar_g_buffs_randomize && (!teamplay || autocvar_g_buffs_randomize_teamplay))
278 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
282 if(this.buff_activetime)
284 if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
286 this.buff_activetime = max(0, this.buff_activetime - frametime);
288 if(!this.buff_activetime)
290 this.buff_active = true;
291 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
292 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
298 if(this.team && !this.buff_waypoint)
299 buff_Waypoint_Spawn(this);
301 if(this.lifetime && time >= this.lifetime)
305 this.nextthink = time;
306 //this.angles_y = time * 110.1;
309 void buff_Waypoint_Reset(entity this)
311 WaypointSprite_Kill(this.buff_waypoint);
313 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
316 void buff_Reset(entity this)
318 if(autocvar_g_buffs_randomize && (!teamplay || autocvar_g_buffs_randomize_teamplay))
321 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
322 buff_Waypoint_Reset(this);
323 this.buff_activetime_updated = false;
325 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
329 bool buff_Customize(entity this, entity client)
331 entity player = WaypointSprite_getviewentity(client);
332 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
335 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
341 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
342 this.light_lev = 220 + 36 * sin(time);
343 this.pflags = PFLAGS_FULLDYNAMIC;
348 void buff_Delete(entity this)
350 WaypointSprite_Kill(this.buff_waypoint);
354 void buff_Init(entity this)
356 if(!cvar("g_buffs")) { delete(this); return; }
358 if(!teamplay && this.team) { this.team = 0; }
360 entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
362 if(!STAT(BUFFS, this) || !buff_Available(buff))
365 this.classname = "item_buff";
366 this.solid = SOLID_TRIGGER;
367 this.flags = FL_ITEM;
368 this.bot_pickup = true;
369 this.bot_pickupevalfunc = generic_pickupevalfunc;
370 this.bot_pickupbasevalue = 1000;
371 IL_PUSH(g_items, this);
372 setthink(this, buff_Think);
373 settouch(this, buff_Touch);
374 this.reset = buff_Reset;
375 this.nextthink = time + 0.1;
377 set_movetype(this, MOVETYPE_TOSS);
379 this.skin = buff.m_skin;
380 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
381 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
382 setcefc(this, buff_Customize);
383 //this.gravity = 100;
384 this.color = buff.m_color;
385 this.glowmod = buff_GlowColor(this);
386 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
387 this.buff_active = !this.buff_activetime;
388 this.pflags = PFLAGS_FULLDYNAMIC;
389 this.dtor = buff_Delete;
391 if(this.spawnflags & 1)
395 set_movetype(this, MOVETYPE_NONE); // reset by random location
397 setmodel(this, MDL_BUFF);
398 setsize(this, BUFF_MIN, BUFF_MAX);
400 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
404 void buff_Init_Compat(entity ent, entity replacement)
406 if (ent.spawnflags & 2)
407 ent.team = NUM_TEAM_1;
408 else if (ent.spawnflags & 4)
409 ent.team = NUM_TEAM_2;
411 STAT(BUFFS, ent) = replacement.m_itemid;
416 void buff_SpawnReplacement(entity ent, entity old)
418 setorigin(ent, old.origin);
419 ent.angles = old.angles;
420 ent.noalign = Item_ShouldKeepPosition(old);
425 void buff_Vengeance_DelayedDamage(entity this)
428 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, DMG_NOWEP, this.enemy.origin, '0 0 0');
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(STAT(BUFFS, frag_target) & 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(STAT(BUFFS, frag_target) & BUFF_SPEED.m_itemid)
457 if(frag_target != frag_attacker)
458 frag_damage *= autocvar_g_buffs_speed_damage_take;
460 if(STAT(BUFFS, frag_target) & BUFF_MEDIC.m_itemid)
461 if((GetResource(frag_target, RES_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, GetResource(frag_target, RES_HEALTH) - autocvar_g_buffs_medic_survive_health);
467 if(STAT(BUFFS, frag_target) & BUFF_JUMP.m_itemid)
468 if(frag_deathtype == DEATH_FALL.m_id)
471 if(STAT(BUFFS, frag_target) & BUFF_VENGEANCE.m_itemid)
473 if(frag_attacker != frag_target)
474 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
476 entity dmgent = new_pure(dmgent);
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(STAT(BUFFS, frag_target) & BUFF_BASH.m_itemid)
486 if(frag_attacker != frag_target)
487 frag_force = '0 0 0';
489 if(STAT(BUFFS, frag_attacker) & BUFF_BASH.m_itemid)
492 if(frag_attacker == frag_target)
493 frag_force *= autocvar_g_buffs_bash_force_self;
495 frag_force *= autocvar_g_buffs_bash_force;
498 if(STAT(BUFFS, frag_attacker) & BUFF_DISABILITY.m_itemid)
499 if(frag_target != frag_attacker)
500 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
502 if(STAT(BUFFS, frag_target) & BUFF_INFERNO.m_itemid)
504 if(frag_deathtype == DEATH_FIRE.m_id)
506 if(frag_deathtype == DEATH_LAVA.m_id)
507 frag_damage *= 0.5; // TODO: cvarize?
510 if(STAT(BUFFS, frag_attacker) & BUFF_LUCK.m_itemid)
511 if(frag_attacker != frag_target)
512 if(autocvar_g_buffs_luck_damagemultiplier > 0)
513 if(random() <= autocvar_g_buffs_luck_chance)
514 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
516 if(STAT(BUFFS, frag_attacker) & BUFF_INFERNO.m_itemid)
517 if(frag_target != frag_attacker) {
518 float btime = buff_Inferno_CalculateTime(
521 autocvar_g_buffs_inferno_burntime_min_time,
522 autocvar_g_buffs_inferno_burntime_target_damage,
523 autocvar_g_buffs_inferno_burntime_target_time,
524 autocvar_g_buffs_inferno_burntime_factor
526 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
529 M_ARGV(4, float) = frag_damage;
530 M_ARGV(6, vector) = frag_force;
533 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
535 // NOTE: vampire PlayerDamage_SplitHealthArmor code is similar
536 entity frag_attacker = M_ARGV(1, entity);
537 entity frag_target = M_ARGV(2, entity);
538 if(!(STAT(BUFFS, frag_attacker) & BUFF_VAMPIRE.m_itemid))
540 float health_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
542 if (time >= frag_target.spawnshieldtime && frag_target != frag_attacker
543 && IS_PLAYER(frag_attacker) && !IS_DEAD(frag_target) && !STAT(FROZEN, frag_target))
545 GiveResource(frag_attacker, RES_HEALTH, autocvar_g_buffs_vampire_damage_steal * health_take);
549 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
551 entity player = M_ARGV(0, entity);
553 buffs_BuffModel_Remove(player);
555 // reset timers here to prevent them continuing after re-spawn
556 player.buff_disability_time = 0;
557 player.buff_disability_effect_time = 0;
560 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
562 entity player = M_ARGV(0, entity);
563 // these automatically reset, no need to worry
565 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
566 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
568 if(time < player.buff_disability_time)
569 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
572 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
574 entity player = M_ARGV(0, entity);
575 // these automatically reset, no need to worry
577 if(STAT(BUFFS, player) & BUFF_JUMP.m_itemid)
578 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
581 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
583 entity mon = M_ARGV(0, entity);
585 if(time < mon.buff_disability_time)
587 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
588 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
592 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
594 entity frag_target = M_ARGV(2, entity);
596 if(STAT(BUFFS, frag_target))
598 int buffid = buff_FirstFromFlags(STAT(BUFFS, frag_target)).m_id;
599 if(!IS_INDEPENDENT_PLAYER(frag_target))
600 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
601 STAT(BUFFS, frag_target) = 0;
602 STAT(BUFF_TIME, frag_target) = 0;
604 buffs_BuffModel_Remove(frag_target);
608 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
610 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
612 entity player = M_ARGV(0, entity);
614 if(STAT(BUFFS, player))
616 int buffid = buff_FirstFromFlags(STAT(BUFFS, player)).m_id;
617 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
618 if(!IS_INDEPENDENT_PLAYER(player))
619 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
621 STAT(BUFFS, player) = 0;
622 STAT(BUFF_TIME, player) = 0;
623 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
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(STAT(BUFFS, player) & BUFF_SWAPPER.m_itemid)
636 float best_distance = autocvar_g_buffs_swapper_range;
637 entity closest = NULL;
638 FOREACH_CLIENT(IS_PLAYER(it), {
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 if (IS_BOT_CLIENT(closest))
673 closest.v_angle = closest.angles;
674 bot_aim_reset(closest);
676 closest.fixangle = true;
677 closest.oldorigin = my_org;
678 closest.oldvelocity = my_vel;
679 player.velocity = their_vel;
680 player.angles = their_ang;
681 if (IS_BOT_CLIENT(player))
683 player.v_angle = player.angles;
684 bot_aim_reset(player);
686 player.fixangle = true;
687 player.oldorigin = their_org;
688 player.oldvelocity = their_vel;
690 // set pusher so player gets the kill if they fall into void
691 closest.pusher = player;
692 closest.pushltime = time + autocvar_g_maxpushtime;
693 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
695 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
696 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
698 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
699 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
701 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
702 STAT(BUFFS, player) = 0;
708 bool buffs_RemovePlayer(entity player)
710 buffs_BuffModel_Remove(player);
712 // also reset timers here to prevent them continuing after spectating
713 player.buff_disability_time = 0;
714 player.buff_disability_effect_time = 0;
718 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
719 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
721 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
723 entity wp = M_ARGV(0, entity);
724 entity player = M_ARGV(1, entity);
726 entity e = WaypointSprite_getviewentity(player);
728 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
729 // but only apply this to real players, not to spectators
730 if((wp.owner.flags & FL_CLIENT) && (STAT(BUFFS, wp.owner) & BUFF_INVISIBLE.m_itemid) && (e == player))
731 if(DIFF_TEAM(wp.owner, e))
735 MUTATOR_HOOKFUNCTION(buffs, FilterItem)
737 if(autocvar_g_buffs < 0)
738 return false; // no auto replacing of entities in this mode
740 entity item = M_ARGV(0, entity);
742 if(autocvar_g_buffs_replace_powerups)
744 switch(item.classname)
746 case "item_strength":
750 buff_SpawnReplacement(e, item);
759 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
761 entity player = M_ARGV(1, entity);
763 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
764 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
766 if(time < player.buff_disability_time)
767 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
770 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
772 entity player = M_ARGV(1, entity);
774 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
775 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
777 if(time < player.buff_disability_time)
778 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
781 .bool buff_flight_crouchheld;
783 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
785 entity player = M_ARGV(0, entity);
787 if(game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) return;
789 if(STAT(BUFFS, player) & BUFF_FLIGHT.m_itemid)
791 if(!PHYS_INPUT_BUTTON_CROUCH(player))
792 player.buff_flight_crouchheld = false;
793 else if(!player.buff_flight_crouchheld)
795 player.buff_flight_crouchheld = true;
796 player.gravity *= -1;
800 if(time < player.buff_disability_time)
801 if(time >= player.buff_disability_effect_time)
803 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
804 player.buff_disability_effect_time = time + 0.5;
807 // handle buff lost status
808 // 1: notify everyone else
809 // 2: notify carrier as well
812 if(STAT(BUFF_TIME, player) && STAT(BUFFS, player))
813 if(time >= STAT(BUFF_TIME, player))
815 STAT(BUFF_TIME, player) = 0;
819 if(STAT(FROZEN, player)) { buff_lost = 1; }
823 if(STAT(BUFFS, player))
825 int buffid = buff_FirstFromFlags(STAT(BUFFS, player)).m_id;
828 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
829 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
831 else if(!IS_INDEPENDENT_PLAYER(player))
832 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
833 STAT(BUFFS, player) = 0;
834 PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
838 if(STAT(BUFFS, player) & BUFF_MAGNET.m_itemid)
841 IL_EACH(g_items, it.itemdef,
844 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
846 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
848 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
851 gettouch(it)(it, player);
856 if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
858 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
860 .entity weaponentity = weaponentities[slot];
861 if(player.(weaponentity).clip_size)
862 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
866 if((STAT(BUFFS, player) & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
867 player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
869 #define BUFF_ONADD(b) if ( (STAT(BUFFS, player) & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
870 #define BUFF_ONREM(b) if (!(STAT(BUFFS, player) & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
872 if(STAT(BUFFS, player) != player.oldbuffs)
874 entity buff = buff_FirstFromFlags(STAT(BUFFS, player));
875 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
876 if(STAT(BUFF_TIME, player) <= time) // if the player still has a buff countdown, don't reset it!
877 STAT(BUFF_TIME, player) = (bufftime) ? time + bufftime : 0;
879 BUFF_ONADD(BUFF_AMMO)
881 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_AMMO);
882 player.items |= IT_UNLIMITED_AMMO;
884 if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
886 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
888 .entity weaponentity = weaponentities[slot];
889 if(player.(weaponentity).clip_load)
890 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
891 if(player.(weaponentity).clip_size)
892 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
897 BUFF_ONREM(BUFF_AMMO)
899 if(player.buff_ammo_prev_infitems)
900 player.items |= IT_UNLIMITED_AMMO;
902 player.items &= ~IT_UNLIMITED_AMMO;
904 if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
906 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
908 .entity weaponentity = weaponentities[slot];
909 if(player.(weaponentity).buff_ammo_prev_clipload)
910 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
915 BUFF_ONADD(BUFF_INVISIBLE)
917 if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib))
918 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
920 player.buff_invisible_prev_alpha = player.alpha;
921 player.alpha = autocvar_g_buffs_invisible_alpha;
924 BUFF_ONREM(BUFF_INVISIBLE)
926 if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib))
927 player.alpha = autocvar_g_instagib_invis_alpha;
929 player.alpha = player.buff_invisible_prev_alpha;
932 BUFF_ONADD(BUFF_FLIGHT)
934 player.buff_flight_oldgravity = player.gravity;
939 BUFF_ONREM(BUFF_FLIGHT)
940 player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
942 player.oldbuffs = STAT(BUFFS, player);
943 if(STAT(BUFFS, player))
945 if(!player.buff_model)
946 buffs_BuffModel_Spawn(player);
948 player.buff_model.color = buff.m_color;
949 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
950 player.buff_model.skin = buff.m_skin;
952 player.effects |= EF_NOSHADOW;
956 buffs_BuffModel_Remove(player);
958 player.effects &= ~(EF_NOSHADOW);
962 if(player.buff_model)
964 player.buff_model.effects = player.effects;
965 player.buff_model.effects |= EF_LOWPRECISION;
966 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
968 player.buff_model.alpha = player.alpha;
975 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
977 entity spectatee = M_ARGV(0, entity);
978 entity client = M_ARGV(1, entity);
980 STAT(BUFFS, client) = STAT(BUFFS, spectatee);
981 STAT(BUFF_TIME, client) = STAT(BUFF_TIME, spectatee);
984 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
986 entity player = M_ARGV(0, entity);
988 if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid)
990 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
991 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
992 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
995 if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
996 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
999 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1001 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1003 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
1004 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1007 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1009 if(autocvar_g_buffs > 0)
1010 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1013 void buffs_DelayedInit(entity this)
1015 if(autocvar_g_buffs_spawn_count > 0)
1016 if(find(NULL, classname, "item_buff") == NULL)
1019 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1022 e.spawnflags |= 64; // always randomize
1023 e.velocity = randomvec() * 250; // this gets reset anyway if random location works
1029 void buffs_Initialize()
1031 // if buffs are above 0, allow random spawning
1032 if(autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0)
1033 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);