X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fmutators%2Fmutator%2Fbuffs%2Fsv_buffs.qc;h=6fa6e8d054c50785a5971e02e685d6e98bacabcc;hb=579b98f2d87d5d2753618322ade31af1422d91ec;hp=83b471cd810e0c6ae992c9f115d70abc0cabff2a;hpb=b2108fdf144cd75a50be6fba1d68a642f41a1531;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc index 83b471cd8..6fa6e8d05 100644 --- a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc @@ -1,37 +1,22 @@ #include "sv_buffs.qh" #include +#include #include - -void buffs_DelayedInit(entity this); - -AUTOCVAR(g_buffs, int, -1, "Enable buffs, -1: enabled but no auto location or replacing powerups, 1: enabled and can replace them"); - -REGISTER_MUTATOR(buffs, autocvar_g_buffs) -{ - MUTATOR_ONADD - { - if(autocvar_g_buffs > 0) - InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET); - } -} +#include bool buffs_BuffModel_Customize(entity this, entity client) { - entity player, myowner; - bool same_team; - - player = WaypointSprite_getviewentity(client); - myowner = this.owner; - same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner)); + entity player = WaypointSprite_getviewentity(client); + entity myowner = this.owner; - if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0) + if(myowner.alpha <= 0.5 && DIFF_TEAM(player, myowner) && myowner.alpha != 0) return false; if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player)) return false; - if(player == myowner || (IS_SPEC(client) && client.enemy == myowner)) + if(player == myowner) { // somewhat hide the model, but keep the glow this.effects = 0; @@ -47,7 +32,7 @@ bool buffs_BuffModel_Customize(entity this, entity client) void buffs_BuffModel_Spawn(entity player) { - player.buff_model = spawn(); + player.buff_model = new(buff_model); setmodel(player.buff_model, MDL_BUFF); setsize(player.buff_model, '0 0 -40', '0 0 40'); setattachment(player.buff_model, player, ""); @@ -59,6 +44,13 @@ void buffs_BuffModel_Spawn(entity player) setcefc(player.buff_model, buffs_BuffModel_Customize); } +void buffs_BuffModel_Remove(entity player) +{ + if(player.buff_model) + delete(player.buff_model); + player.buff_model = NULL; +} + vector buff_GlowColor(entity buff) { //if(buff.team) { return Team_ColorRGB(buff.team); } @@ -84,7 +76,7 @@ bool buff_Waypoint_visible_for_player(entity this, entity player, entity view) if (STAT(BUFFS, view)) { - return CS(view).cvar_cl_buffs_autoreplace == false || STAT(BUFFS, view) != STAT(BUFFS, this.owner); + return CS_CVAR(view).cvar_cl_buffs_autoreplace == false || STAT(BUFFS, view) != STAT(BUFFS, this.owner); } return WaypointSprite_visible_for_player(this, player, view); @@ -92,6 +84,8 @@ bool buff_Waypoint_visible_for_player(entity this, entity player, entity view) void buff_Waypoint_Spawn(entity e) { + if(autocvar_g_buffs_waypoint_distance <= 0) return; + entity buff = buff_FirstFromFlags(STAT(BUFFS, e)); 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); wp.wp_extra = buff.m_id; @@ -106,7 +100,9 @@ void buff_SetCooldown(entity this, float cd) if(!this.buff_waypoint) buff_Waypoint_Spawn(this); - WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd); + if(this.buff_waypoint) + WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd); + this.buff_activetime = cd; this.buff_active = !cd; } @@ -178,7 +174,7 @@ void buff_Touch(entity this, entity toucher) if (STAT(BUFFS, toucher)) { - if (CS(toucher).cvar_cl_buffs_autoreplace && STAT(BUFFS, toucher) != STAT(BUFFS, this)) + if (CS_CVAR(toucher).cvar_cl_buffs_autoreplace && STAT(BUFFS, toucher) != STAT(BUFFS, this)) { // TODO: lost-gained notification for this case int buffid = buff_FirstFromFlags(STAT(BUFFS, toucher)).m_id; @@ -238,6 +234,9 @@ void buff_NewType(entity ent) void buff_Think(entity this) { + if(this.buff_waypoint && autocvar_g_buffs_waypoint_distance <= 0) + WaypointSprite_Kill(this.buff_waypoint); + if(STAT(BUFFS, this) != this.oldbuffs) { entity buff = buff_FirstFromFlags(STAT(BUFFS, this)); @@ -261,7 +260,7 @@ void buff_Think(entity this) } if(!game_stopped) - if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime) + if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime) if(!this.buff_activetime_updated) { buff_SetCooldown(this, this.buff_activetime); @@ -282,7 +281,7 @@ void buff_Think(entity this) if(this.buff_activetime) if(!game_stopped) - if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime) + if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime) { this.buff_activetime = max(0, this.buff_activetime - frametime); @@ -299,8 +298,7 @@ void buff_Think(entity this) if(this.team && !this.buff_waypoint) buff_Waypoint_Spawn(this); - if(this.lifetime) - if(time >= this.lifetime) + if(this.lifetime && time >= this.lifetime) buff_Respawn(this); } @@ -433,25 +431,6 @@ void buff_Vengeance_DelayedDamage(entity this) return; } -// note: only really useful in teamplay -void buff_Medic_Heal(entity this) -{ - FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range), - { - if (DIFF_TEAM(it, this)) - { - continue; - } - float hp = GetResource(it, RES_HEALTH); - if(hp >= autocvar_g_balance_health_regenstable) - { - continue; - } - Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1); - SetResource(it, RES_HEALTH, bound(0, hp + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable)); - }); -} - float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base) { return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base); @@ -494,7 +473,7 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate) if(frag_attacker != frag_target) if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) { - entity dmgent = spawn(); + entity dmgent = new_pure(dmgent); dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier; dmgent.enemy = frag_attacker; @@ -547,36 +526,33 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate) Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id); } - // this... is ridiculous (TODO: fix!) - if(STAT(BUFFS, frag_attacker) & BUFF_VAMPIRE.m_itemid) - if(!frag_target.vehicle) - if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) - if(!IS_DEAD(frag_target)) - if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target)) - if(frag_attacker != frag_target) - if(!STAT(FROZEN, frag_target)) - if(frag_target.takedamage) - if(DIFF_TEAM(frag_attacker, frag_target)) - { - float amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, - GetResource(frag_target, RES_HEALTH)); - GiveResourceWithLimit(frag_attacker, RES_HEALTH, amount, g_pickup_healthsmall_max); - if (GetResource(frag_target, RES_ARMOR)) - { - amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, - GetResource(frag_target, RES_ARMOR)); - GiveResourceWithLimit(frag_attacker, RES_ARMOR, amount, g_pickup_armorsmall_max); - } - } - M_ARGV(4, float) = frag_damage; M_ARGV(6, vector) = frag_force; } +MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor) +{ + entity frag_attacker = M_ARGV(1, entity); + entity frag_target = M_ARGV(2, entity); + if(!(STAT(BUFFS, frag_attacker) & BUFF_VAMPIRE.m_itemid)) + return; + float health_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH)); + + if(time >= frag_target.spawnshieldtime && + frag_target != frag_attacker && + IS_PLAYER(frag_attacker) && + !IS_DEAD(frag_target) && !STAT(FROZEN, frag_target)) + { + GiveResource(frag_attacker, RES_HEALTH, + autocvar_g_buffs_vampire_damage_steal * health_take); + } +} + MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn) { entity player = M_ARGV(0, entity); + buffs_BuffModel_Remove(player); player.oldbuffs = 0; // reset timers here to prevent them continuing after re-spawn player.buff_disability_time = 0; @@ -627,11 +603,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerDies) STAT(BUFFS, frag_target) = 0; STAT(BUFF_TIME, frag_target) = 0; - if(frag_target.buff_model) - { - delete(frag_target.buff_model); - frag_target.buff_model = NULL; - } + buffs_BuffModel_Remove(frag_target); } } @@ -737,11 +709,7 @@ MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon) bool buffs_RemovePlayer(entity player) { - if(player.buff_model) - { - delete(player.buff_model); - player.buff_model = NULL; - } + buffs_BuffModel_Remove(player); // also reset timers here to prevent them continuing after spectating player.buff_disability_time = 0; @@ -900,13 +868,6 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) if((STAT(BUFFS, player) & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid)) player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO) - if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid) - if(time >= player.buff_medic_healtime) - { - buff_Medic_Heal(player); - player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay; - } - #define BUFF_ONADD(b) if ( (STAT(BUFFS, player) & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid)) #define BUFF_ONREM(b) if (!(STAT(BUFFS, player) & (b).m_itemid) && (player.oldbuffs & (b).m_itemid)) @@ -955,7 +916,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) BUFF_ONADD(BUFF_INVISIBLE) { - if(time < player.strength_finished && MUTATOR_IS_ENABLED(mutator_instagib)) + if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib)) 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 else player.buff_invisible_prev_alpha = player.alpha; @@ -964,7 +925,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) BUFF_ONREM(BUFF_INVISIBLE) { - if(time < player.strength_finished && MUTATOR_IS_ENABLED(mutator_instagib)) + if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib)) player.alpha = autocvar_g_instagib_invis_alpha; else player.alpha = player.buff_invisible_prev_alpha; @@ -994,9 +955,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) } else { - if(player.buff_model) - delete(player.buff_model); - player.buff_model = NULL; + buffs_BuffModel_Remove(player); player.effects &= ~(EF_NOSHADOW); } @@ -1068,3 +1027,10 @@ void buffs_DelayedInit(entity this) } } } + +void buffs_Initialize() +{ + // if buffs are above 0, allow random spawning + if(autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0) + InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET); +}